MeVisLab Resolution Independence API
mlOffscreenRender.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_OFFSCREEN_RENDER_H
14 #define ML_OFFSCREEN_RENDER_H
15 
16 // Include specific settings.
18 
19 // Include most ml specific things.
20 #include "mlModuleIncludes.h"
21 
22 
23 #include <GL/glew.h>
24 
25 // inventor include goes here
26 #include <Inventor/actions/SoGLRenderAction.h>
27 
28 // Forward declaration
31 class SoPBuffer;
32 class SoGLRenderAction;
33 class SoGLFramebufferObject;
34 class SoGLTexture;
35 class SoGLRenderbuffer;
36 
37 ML_START_NAMESPACE
38 
43 {
45  ML_MODULE_CLASS_HEADER(OffscreenRenderer)
46 
47 public:
48 
50  enum ImageType {
51  IMG_RGB = 0,
54  NUM_IMAGE_TYPES
55  };
56 
57  // Various levels of transparency rendering quality
59  SCREEN_DOOR = SoGLRenderAction::SCREEN_DOOR,
60  ADD = SoGLRenderAction::ADD,
61  DELAYED_ADD = SoGLRenderAction::DELAYED_ADD,
62  SORTED_OBJECT_ADD = SoGLRenderAction::SORTED_OBJECT_ADD,
63  BLEND = SoGLRenderAction::BLEND,
64  DELAYED_BLEND = SoGLRenderAction::DELAYED_BLEND,
65  SORTED_OBJECT_BLEND = SoGLRenderAction::SORTED_OBJECT_BLEND,
66  NUM_TRANSPARENCY_TYPES
67  };
68 
69  enum BufferType {
72  NUM_BUFFER_TYPES
73  };
74 
76  static const char *ImageTypeStrings[NUM_IMAGE_TYPES];
77 
79  static const char *TransparencyTypeStrings[NUM_TRANSPARENCY_TYPES];
80 
82  static const char *BufferTypeStrings[NUM_BUFFER_TYPES];
83 
85  OffscreenRenderer(ImageType imgType = IMG_RGB, const Vector2 &size = Vector2(64.,64.), int numInputImages=0, int numOutputImages=1);
86 
88  ~OffscreenRenderer() override;
89 
90 
92  void handleNotification(Field *) override;
93 #if ML_DEPRECATED_SINCE(3,6,0)
94  using Module::calculateOutputImageProperties;
95 #endif
97  void calculateOutputImageProperties(int outputIndex, PagedImage* outputImage) override;
98 
100  void calculateOutputSubImage(SubImage *outSubImg, int outIndex, SubImage *inSubImgs) override;
101 
103  void activateAttachments() override;
104 
107 
108 protected:
110 
112  BoolField* _supportedFld;
114  SoNodeField* _sceneGraphFld;
116  EnumField* _imageTypeFld;
120  EnumField* _bufferTypeFld;
122  // (we should use an integer type here, but we have no corresponding field type)
123  Vector2Field* _sizeFld;
126  FloatField* _pixelScaleFld;
128  ColorField* _bgColorFld;
132  NotifyField* _updateFld;
136  IntField* _multiSampling;
137 
138 
139 protected:
141 
143  bool _useFBO;
144 
146  SoGLRenderAction* _glRenderAction;
147 
150  SoRef<SoOffscreenViewerProxyNode> _root;
151 
154 
156  SoPBuffer* _pBuffer;
158  int _mode;
161 
163  SoGLFramebufferObject* _fbo;
165  SoGLTexture* _colorTextureBuffer;
167  SoGLRenderbuffer* _depthRenderBuffer;
172  GLenum _colorFormat;
173 
174  SoGLFramebufferObject* _msaaFbo;
175  SoGLRenderbuffer* _msaaColorBuffer;
176 
178  unsigned char *_memImage;
180  unsigned int _memImgBytes;
181 
184 
185 protected:
187  void _setMode();
188 
190 
192  bool _createPBuffer(const SbVec2s&);
193 
195  bool _createFBO(const SbVec2s&);
196 
198 
201 
203  bool _renderToOutImage(bool& hasSceneAndUpdatedBuffer);
204 
207  bool _render(bool& hasSceneAndUpdatedBuffer);
208 
210 };
211 
212 
213 ML_END_NAMESPACE
214 
215 #endif // of __OFFSCREENRENDER_H
216 
217 
218 
219 
220 
#define MLOFFSCREENRENDER_EXPORT
Defines macro needed for Windows (export of classes from this DLL)
SoOffscreenViewerProxyNode will put a SoViewerElement with the given SoOffscreenViewerProxy into the ...
This class implements access to the state of the SoOffscreenRenderer viewer.
OpenInventor Scenes can be rendered to the OffscreenRender who outputs an MLImage.
int _mode
The mode of the pBuffer.
SoRef< SoOffscreenViewerProxyNode > _root
SoSeparator node to use as root of the scene, so that the render state is reset after each rendering.
SoGLTexture * _colorTextureBuffer
Pointer to the color buffer.
NotifyField * _updateFld
Triggers update.
ImageType
Macro for declaring methods for the runtime system, defined in mlRuntimeSubClass.h.
OffscreenRenderer(ImageType imgType=IMG_RGB, const Vector2 &size=Vector2(64., 64.), int numInputImages=0, int numOutputImages=1)
Constructor.
void _setMode()
Sets the mode of the pixel buffer according to _curImgType.
bool _createFBO(const SbVec2s &)
Creates the FBO.
EnumField * _transparencyTypeFld
Specifies the image type of the output image.
EnumField * _imageTypeFld
Specifies the image type of the output image.
SoGLFramebufferObject * _msaaFbo
SoOffscreenViewerProxy * _offscreenProxy
Proxy node that can be queried during traversal.
unsigned char * _memImage
Pointer to memory allocated to hold the content of the offscreen buffer.
bool _render(bool &hasSceneAndUpdatedBuffer)
Calls _renderToOutImage().
void calculateOutputSubImage(SubImage *outSubImg, int outIndex, SubImage *inSubImgs) override
Called when a page is calculated.
void calculateOutputImageProperties(int outputIndex, PagedImage *outputImage) override
Determine properties of output image.
SoGLRenderbuffer * _msaaColorBuffer
BoolField * _createStencilBufferFld
Specifies whether to create a stencil buffer.
ColorField * _bgColorFld
Background color.
~OffscreenRenderer() override
Destructor:
unsigned int _memImgBytes
Number of bytes of the _memImage.
BoolField * _supportedFld
Field variables.
bool _bufferUpToDate
Member variables.
SoGLRenderbuffer * _depthRenderBuffer
Pointer to the depth buffer.
void _deactivateOffscreenBuffer()
bool _frameBufferCompletionTested
Flag that indicates that the current color/depth/stencil buffer configuration has been checked and wo...
void handleNotification(Field *) override
Called when input changes.
bool _renderToOutImage(bool &hasSceneAndUpdatedBuffer)
Render the scene and write it to a main memory buffer. Returns true on success, false otherwise.
bool _createPBuffer(const SbVec2s &)
Creates the pixel buffer.
SoNodeField * _sceneGraphFld
Root node of scene graph to be rendered offscreen.
void activateAttachments() override
Initialize buffer type.
SoPBuffer * _pBuffer
The pBuffer object.
SoGLFramebufferObject * _fbo
The frame buffer object, is used instead of the pBuffer if available.
GLuint _depthComponent
The depth component actually used. May differ from requested, cause gfx card does not support it.
EnumField * _bufferTypeFld
Specifies the buffer type.
IntField * _multiSampling
Sets number of samples.
Vector2Field * _sizeFld
Size of the output image.
void * takeMemoryImage()
Returns the current memory image and creates a new one. The ownership is passed to the caller.
BoolField * _enableMultiSampling
Enables multi sampling.
ImageType _curImgType
The image type of the pBuffer. This is not necessarily identical to the value of _imageTypeFld!
SoGLRenderAction * _glRenderAction
The GL render action needed to traverse the scene attached to this module.
FloatField * _pixelScaleFld
Scale factor for pixel size.