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
31class SoPBuffer;
32class SoGLRenderAction;
33class SoGLFramebufferObject;
34class SoGLTexture;
35class SoGLRenderbuffer;
36
37ML_START_NAMESPACE
38
43{
45 ML_MODULE_CLASS_HEADER(OffscreenRenderer)
46
47public:
48
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,
67 };
68
74
76 static const char *ImageTypeStrings[NUM_IMAGE_TYPES];
77
80
83
85 OffscreenRenderer(ImageType imgType = IMG_RGB, const Vector2 &size = Vector2(64.,64.), int numInputImages=0, int numOutputImages=1);
86
89
90
92 void handleNotification(Field *) override;
93
95 void calculateOutputImageProperties(int outputIndex, PagedImage* outputImage) override;
96
98 void calculateOutputSubImage(SubImage *outSubImg, int outIndex, SubImage *inSubImgs) override;
99
101 void activateAttachments() override;
102
105
106protected:
108
110 BoolField* _supportedFld;
112 SoNodeField* _sceneGraphFld;
114 EnumField* _imageTypeFld;
118 EnumField* _bufferTypeFld;
120 // (we should use an integer type here, but we have no corresponding field type)
121 Vector2Field* _sizeFld;
124 FloatField* _pixelScaleFld;
126 ColorField* _bgColorFld;
130 NotifyField* _updateFld;
134 IntField* _multiSampling;
135
136
137protected:
139
142
144 SoGLRenderAction* _glRenderAction;
145
148 SoRef<SoOffscreenViewerProxyNode> _root;
149
152
154 SoPBuffer* _pBuffer;
156 int _mode;
159
161 SoGLFramebufferObject* _fbo;
165 SoGLRenderbuffer* _depthRenderBuffer;
171
172 SoGLFramebufferObject* _msaaFbo;
173 SoGLRenderbuffer* _msaaColorBuffer;
174
176 unsigned char *_memImage;
178 unsigned int _memImgBytes;
179
182
183protected:
185 void _setMode();
186
188
190 bool _createPBuffer(const SbVec2s&);
191
193 bool _createFBO(const SbVec2s&);
194
196
199
201 bool _renderToOutImage(bool& hasSceneAndUpdatedBuffer);
202
205 bool _render(bool& hasSceneAndUpdatedBuffer);
206
208};
209
210
211ML_END_NAMESPACE
212
213#endif // of __OFFSCREENRENDER_H
214
215
216
217
218
#define MLOFFSCREENRENDER_EXPORT
This class implements access to the state of the SoOffscreenRenderer viewer.
int _mode
The mode of the pBuffer.
SoRef< SoOffscreenViewerProxyNode > _root
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)
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.
static const char * BufferTypeStrings[NUM_BUFFER_TYPES]
Define strings for all image types. These can be used for enum fields.
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.
void * takeMemoryImage()
Returns the current memory image and creates a new one. The ownership is passed to the caller.
bool _bufferUpToDate
Member variables.
static const char * TransparencyTypeStrings[NUM_TRANSPARENCY_TYPES]
Define strings for all transparency types. These can be used for enum fields.
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.
static const char * ImageTypeStrings[NUM_IMAGE_TYPES]
Define strings for all image types. These can be used for enum fields.
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.