OpenSceneGraph 3.6.5
RenderStage
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUTIL_RENDERSTAGE
15#define OSGUTIL_RENDERSTAGE 1
16
17#include <osg/ColorMask>
18#include <osg/Viewport>
19#include <osg/Texture>
20#include <osg/FrameBufferObject>
21#include <osg/Camera>
22
23#include <osgUtil/RenderBin>
25
26namespace osgUtil {
27
38{
39 public:
40
41 typedef std::pair< int , osg::ref_ptr<RenderStage> > RenderStageOrderPair;
42 typedef std::list< RenderStageOrderPair > RenderStageList;
43
46
48
49 virtual osg::Object* cloneType() const { return new RenderStage(); }
50 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new RenderStage(*this,copyop); } // note only implements a clone of type.
51 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const RenderStage*>(obj)!=0L; }
52 virtual const char* className() const { return "RenderStage"; }
53
54 virtual void reset();
55
56
58 void setDrawBuffer(GLenum buffer, bool applyMask = true ) { _drawBuffer = buffer; setDrawBufferApplyMask( applyMask ); }
59
61 GLenum getDrawBuffer() const { return _drawBuffer; }
62
65
67 void setDrawBufferApplyMask( bool applyMask ) { _drawBufferApplyMask = applyMask; }
68
69
70
72 void setReadBuffer(GLenum buffer, bool applyMask = true) { _readBuffer = buffer; setReadBufferApplyMask( applyMask ); }
73
75 GLenum getReadBuffer() const { return _readBuffer; }
76
79
81 void setReadBufferApplyMask( bool applyMask ) { _readBufferApplyMask = applyMask; }
82
83
85 void setViewport(osg::Viewport* viewport) { _viewport = viewport; }
86
88 const osg::Viewport* getViewport() const { return _viewport.get(); }
89
91 osg::Viewport* getViewport() { return _viewport.get(); }
92
94 void setInitialViewMatrix(const osg::RefMatrix* matrix) { _initialViewMatrix = matrix; }
95
98
101 void setClearMask(GLbitfield mask) { _clearMask = mask; }
102
104 GLbitfield getClearMask() const { return _clearMask; }
105
106
109 const osg::ColorMask* getColorMask() const { return _colorMask.get(); }
110
111
114 void setClearColor(const osg::Vec4& color) { _clearColor=color; }
115
117 const osg::Vec4& getClearColor() const { return _clearColor; }
118
121 void setClearAccum(const osg::Vec4& color) { _clearAccum=color; }
122
124 const osg::Vec4& getClearAccum() const { return _clearAccum; }
125
128 void setClearDepth(double depth) { _clearDepth=depth; }
129
131 double getClearDepth() const { return _clearDepth; }
132
135 void setClearStencil(int stencil) { _clearStencil=stencil; }
136
138 int getClearStencil() const { return _clearStencil; }
139
140
141 void setCamera(osg::Camera* camera) { if (_camera!=camera) { _camera = camera; _cameraRequiresSetUp = true; } }
142 osg::Camera* getCamera() { return _camera.get(); }
143 const osg::Camera* getCamera() const { return _camera.get(); }
144
147
150
151
154
155 void setTexture(osg::Texture* texture, unsigned int level = 0, unsigned int face=0) { _texture = texture; _level = level; _face = face; }
156 osg::Texture* getTexture() { return _texture.get(); }
157
158 void setImage(osg::Image* image) { _image = image; }
159 osg::Image* getImage() { return _image.get(); }
160
161 void setImageReadPixelFormat(GLenum format) { _imageReadPixelFormat = format; }
163
166
172 const osg::FrameBufferObject* getFrameBufferObject() const { return _fbo.get(); }
173
182
186 void setDisableFboAfterRender(bool disable) {_disableFboAfterRender = disable;}
188
192
193
194
195
198
201
203
209
211 {
212 getPositionalStateContainer()->addPositionedAttribute(matrix,attr);
213 }
214
215 virtual void addPositionedTextureAttribute(unsigned int textureUnit, osg::RefMatrix* matrix,const osg::StateAttribute* attr)
216 {
217 getPositionalStateContainer()->addPositionedTextureAttribute(textureUnit, matrix,attr);
218 }
219
220 void copyTexture(osg::RenderInfo& renderInfo);
221
222 virtual void sort();
223
224 virtual void drawPreRenderStages(osg::RenderInfo& renderInfo,RenderLeaf*& previous);
225
226 virtual void draw(osg::RenderInfo& renderInfo,RenderLeaf*& previous);
227
228 virtual void drawInner(osg::RenderInfo& renderInfo,RenderLeaf*& previous, bool& doCopyTexture);
229
230 virtual void drawPostRenderStages(osg::RenderInfo& renderInfo,RenderLeaf*& previous);
231
232 virtual void drawImplementation(osg::RenderInfo& renderInfo,RenderLeaf*& previous);
233
234
236
237 void addPreRenderStage(RenderStage* rs, int order = 0);
238
239 void addPostRenderStage(RenderStage* rs, int order = 0);
240
243
246
248 bool getStats(Statistics& stats) const;
249
251 virtual unsigned int computeNumberOfDynamicRenderLeaves() const;
252
259
261
264
267
271 virtual void releaseGLObjects(osg::State* state= 0) const;
272
273protected:
274
275 virtual ~RenderStage();
276
277 typedef std::vector< osg::ref_ptr<osg::Camera> > Cameras;
278
282
284
285 // viewport x,y,width,height.
288
293 GLbitfield _clearMask;
299
303
305 unsigned int _level;
306 unsigned int _face;
307
311
312 std::map< osg::Camera::BufferComponent, Attachment> _bufferAttachmentMap;
313
318
322
323
324};
325
326}
327
328#endif
329
Matrixd Matrix
Definition Matrix:27
Vec4f Vec4
Definition Vec4:21
RefMatrixd RefMatrix
Definition Matrix:28
The osgUtil library provides general purpose utility classes such as update, cull and draw traverses,...
Definition NodeVisitor:25
Camera - is a subclass of Transform which represents encapsulates the settings of a Camera.
Definition Camera:45
BufferComponent
Definition Camera:326
Encapsulates OpenGL glColorMaskFunc/Op/Mask functions.
Definition ColorMask:25
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Definition FrameBufferObject:321
Base class for providing Windowing API agnostic access to creating and managing graphics context.
Definition GraphicsContext:30
Image class for encapsulating the storage texture image data.
Definition Image:179
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Smart pointer for observed objects, that automatically set pointers to them to null when they are del...
Definition observer_ptr:39
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Definition RenderInfo:28
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Base class for state attributes.
Definition StateAttribute:77
Texture pure virtual base class that encapsulates OpenGL texture functionality common to the various ...
Definition Texture:422
Encapsulate OpenGL glViewport.
Definition Viewport:24
PositionalStateContainer base class.
Definition PositionalStateContainer:30
SortMode
Definition RenderBin:42
Container class for all data required for rendering of drawables.
Definition RenderLeaf:34
bool _cameraRequiresSetUp
Definition RenderStage:300
void setMultisampleResolveFramebufferObject(osg::FrameBufferObject *fbo)
Sets the destination framebuffer object for glBlitFramebufferEXT to resolve a multisampled framebuffe...
virtual void drawPostRenderStages(osg::RenderInfo &renderInfo, RenderLeaf *&previous)
void setCamera(osg::Camera *camera)
Definition RenderStage:141
virtual void reset()
virtual void addPositionedAttribute(osg::RefMatrix *matrix, const osg::StateAttribute *attr)
Definition RenderStage:210
std::pair< int, osg::ref_ptr< RenderStage > > RenderStageOrderPair
Definition RenderStage:41
osg::ref_ptr< PositionalStateContainer > _renderStageLighting
Definition RenderStage:321
unsigned int _cameraAttachmentMapModifiedCount
Definition RenderStage:301
const RenderStageList & getPostRenderList() const
Definition RenderStage:244
osg::GraphicsContext * getGraphicsContext()
Definition RenderStage:190
osg::Vec4 _clearAccum
Definition RenderStage:296
void addPostRenderStage(RenderStage *rs, int order=0)
const osg::FrameBufferObject * getFrameBufferObject() const
Definition RenderStage:172
bool getDisableFboAfterRender() const
Definition RenderStage:187
GLenum getImageReadPixelFormat() const
Definition RenderStage:162
virtual unsigned int computeNumberOfDynamicRenderLeaves() const
Compute the number of dynamic RenderLeaves.
bool getStats(Statistics &stats) const
Extract stats for current draw list.
const osg::GraphicsContext * getGraphicsContext() const
Definition RenderStage:191
GLenum getDrawBuffer() const
Get the draw buffer used at the start of each frame draw.
Definition RenderStage:61
std::vector< osg::ref_ptr< osg::Camera > > Cameras
Definition RenderStage:277
void copyTexture(osg::RenderInfo &renderInfo)
GLenum getImageReadPixelDataType() const
Definition RenderStage:165
virtual void sort()
bool _drawBufferApplyMask
Definition RenderStage:290
bool _readBufferApplyMask
Definition RenderStage:292
RenderStageList & getPostRenderList()
Definition RenderStage:245
void setInheritedPositionalStateContainerMatrix(const osg::Matrix &matrix)
Definition RenderStage:196
virtual void drawPreRenderStages(osg::RenderInfo &renderInfo, RenderLeaf *&previous)
void addPreRenderStage(RenderStage *rs, int order=0)
const osg::Matrix & getInheritedPositionalStateContainerMatrix() const
Definition RenderStage:197
const osg::Camera * getCamera() const
Definition RenderStage:143
void setCameraRequiresSetUp(bool flag)
Definition RenderStage:145
void setTexture(osg::Texture *texture, unsigned int level=0, unsigned int face=0)
Definition RenderStage:155
void setImageReadPixelFormat(GLenum format)
Definition RenderStage:161
virtual void releaseGLObjects(osg::State *state=0) const
If State is non-zero, this function releases any associated OpenGL objects for the specified graphics...
bool getCameraRequiresSetUp() const
Definition RenderStage:146
void setDrawBuffer(GLenum buffer, bool applyMask=true)
Set the draw buffer used at the start of each frame draw.
Definition RenderStage:58
void setCameraAttachmentMapCount(unsigned int v)
Definition RenderStage:148
osg::Image * getImage()
Definition RenderStage:159
osg::ref_ptr< const osg::RefMatrix > _initialViewMatrix
Definition RenderStage:287
RenderStageList & getPreRenderList()
Definition RenderStage:242
double getClearDepth() const
Get the clear depth.
Definition RenderStage:131
bool _stageDrawnThisFrame
Definition RenderStage:279
void addToDependencyList(RenderStage *rs)
Definition RenderStage:235
osg::ref_ptr< osg::Texture > _texture
Definition RenderStage:304
osg::ref_ptr< osg::GraphicsContext > _graphicsContext
Definition RenderStage:316
int _clearStencil
Definition RenderStage:298
virtual void drawImplementation(osg::RenderInfo &renderInfo, RenderLeaf *&previous)
virtual osg::Object * clone(const osg::CopyOp &copyop) const
Clone an object, with Object* return type.
Definition RenderStage:50
void setInitialViewMatrix(const osg::RefMatrix *matrix)
Set the initial view matrix.
Definition RenderStage:94
void setInheritedPositionalStateContainer(PositionalStateContainer *rsl)
Definition RenderStage:199
virtual void drawInner(osg::RenderInfo &renderInfo, RenderLeaf *&previous, bool &doCopyTexture)
osg::FrameBufferObject * getFrameBufferObject()
Definition RenderStage:171
int getClearStencil() const
Get the clear color.
Definition RenderStage:138
bool getReadBufferApplyMask() const
Get the apply mask defining whether glReadBuffer is called at each frame draw.
Definition RenderStage:78
GLenum getReadBuffer() const
Get the read buffer for any required copy operations to use.
Definition RenderStage:75
RenderStageList _postRenderList
Definition RenderStage:281
osg::Texture * getTexture()
Definition RenderStage:156
void setGraphicsContext(osg::GraphicsContext *context)
Definition RenderStage:189
void attach(osg::Camera::BufferComponent buffer, osg::Image *image)
osg::ref_ptr< osg::Viewport > _viewport
Definition RenderStage:286
void setFrameBufferObject(osg::FrameBufferObject *fbo)
Set a framebuffer object to render into.
Definition RenderStage:170
osg::ref_ptr< osg::Image > _image
Definition RenderStage:308
std::map< osg::Camera::BufferComponent, Attachment > _bufferAttachmentMap
Definition RenderStage:312
void setViewport(osg::Viewport *viewport)
Set the viewport.
Definition RenderStage:85
void clearReferencesToDependentCameras()
clear the references to any dependent cameras.
void runCameraSetUp(osg::RenderInfo &renderInfo)
Attempt the set the RenderStage from the Camera settings.
virtual bool isSameKindAs(const osg::Object *obj) const
Definition RenderStage:51
void setClearMask(GLbitfield mask)
Set the clear mask used in glClear(..).
Definition RenderStage:101
Cameras _dependentCameras
Definition RenderStage:283
virtual osg::Object * cloneType() const
Clone the type of an object, with Object* return type.
Definition RenderStage:49
void setDrawBufferApplyMask(bool applyMask)
Set the apply mask defining whether glDrawBuffer is called at each frame draw.
Definition RenderStage:67
bool _disableFboAfterRender
Definition RenderStage:317
osg::observer_ptr< osg::Camera > _camera
Definition RenderStage:302
osg::Camera * getCamera()
Definition RenderStage:142
const osg::RefMatrix * getInitialViewMatrix()
Get the initial view matrix.
Definition RenderStage:97
const osg::ColorMask * getColorMask() const
Definition RenderStage:109
virtual const char * className() const
return the name of the object's class type.
Definition RenderStage:52
const osg::FrameBufferObject * getMultisampleResolveFramebufferObject() const
Definition RenderStage:181
const osg::Vec4 & getClearAccum() const
Get the clear accum.
Definition RenderStage:124
RenderStage(SortMode mode)
const osg::Vec4 & getClearColor() const
Get the clear color.
Definition RenderStage:117
osg::ref_ptr< osg::FrameBufferObject > _resolveFbo
Definition RenderStage:315
osg::ref_ptr< PositionalStateContainer > _inheritedPositionalStateContainer
Definition RenderStage:320
osg::ref_ptr< osg::ColorMask > _colorMask
Definition RenderStage:294
const RenderStageList & getPreRenderList() const
Definition RenderStage:241
GLbitfield _clearMask
Definition RenderStage:293
osg::Matrix _inheritedPositionalStateContainerMatrix
Definition RenderStage:319
osg::Vec4 _clearColor
Definition RenderStage:295
void setClearColor(const osg::Vec4 &color)
Set the clear color used in glClearColor(..).
Definition RenderStage:114
osg::ColorMask * getColorMask()
Definition RenderStage:108
void setColorMask(osg::ColorMask *cm)
Definition RenderStage:107
void setPositionalStateContainer(PositionalStateContainer *rsl)
Definition RenderStage:202
osg::FrameBufferObject * getMultisampleResolveFramebufferObject()
Definition RenderStage:180
unsigned int _face
Definition RenderStage:306
bool getDrawBufferApplyMask() const
Get the apply mask defining whether glDrawBuffer is called at each frame draw.
Definition RenderStage:64
const osg::Viewport * getViewport() const
Get the const viewport.
Definition RenderStage:88
PositionalStateContainer * getInheritedPositionalStateContainer()
Definition RenderStage:200
GLbitfield getClearMask() const
Get the clear mask.
Definition RenderStage:104
void setClearStencil(int stencil)
Set the clear stencil value used in glClearStencil().
Definition RenderStage:135
GLenum _imageReadPixelDataType
Definition RenderStage:310
osg::ref_ptr< osg::FrameBufferObject > _fbo
Definition RenderStage:314
void setClearDepth(double depth)
Set the clear depth used in glClearDepth(..).
Definition RenderStage:128
RenderStage(const RenderStage &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
void setReadBuffer(GLenum buffer, bool applyMask=true)
Set the read buffer for any required copy operations to use.
Definition RenderStage:72
RenderStageList _preRenderList
Definition RenderStage:280
unsigned int getCameraAttachmentMapCount()
Definition RenderStage:149
void setImageReadPixelDataType(GLenum type)
Definition RenderStage:164
virtual void draw(osg::RenderInfo &renderInfo, RenderLeaf *&previous)
void setReadBufferApplyMask(bool applyMask)
Set the apply mask defining whether glReadBuffer is called at each frame draw.
Definition RenderStage:81
GLenum _drawBuffer
Definition RenderStage:289
unsigned int _level
Definition RenderStage:305
GLenum _imageReadPixelFormat
Definition RenderStage:309
void setDisableFboAfterRender(bool disable)
Set whether the framebuffer object should be unbound after rendering.
Definition RenderStage:186
void collateReferencesToDependentCameras()
search through any pre and post RenderStage that reference a Camera, and take a reference to each of ...
void setImage(osg::Image *image)
Definition RenderStage:158
PositionalStateContainer * getPositionalStateContainer() const
Definition RenderStage:204
double _clearDepth
Definition RenderStage:297
void setClearAccum(const osg::Vec4 &color)
Set the clear accum used in glClearAccum(..).
Definition RenderStage:121
std::list< RenderStageOrderPair > RenderStageList
Definition RenderStage:42
virtual void addPositionedTextureAttribute(unsigned int textureUnit, osg::RefMatrix *matrix, const osg::StateAttribute *attr)
Definition RenderStage:215
osg::Viewport * getViewport()
Get the viewport.
Definition RenderStage:91
GLenum _readBuffer
Definition RenderStage:291
Definition RenderStage:254
osg::ref_ptr< osg::Image > _image
Definition RenderStage:255
GLenum _imageReadPixelDataType
Definition RenderStage:257
GLenum _imageReadPixelFormat
Definition RenderStage:256
Statistics base class.
Definition Statistics:48
#define OSGUTIL_EXPORT
Definition Export:40

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.