openscenegraph
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
64 bool getDrawBufferApplyMask() const { return _drawBufferApplyMask; }
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
78 bool getReadBufferApplyMask() const { return _readBufferApplyMask; }
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
97 const osg::RefMatrix* getInitialViewMatrix() { return _initialViewMatrix.get(); }
98
101 void setClearMask(GLbitfield mask) { _clearMask = mask; }
102
104 GLbitfield getClearMask() const { return _clearMask; }
105
106
107 void setColorMask(osg::ColorMask* cm) { _colorMask = cm; }
108 osg::ColorMask* getColorMask() { return _colorMask.get(); }
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
145 void setCameraRequiresSetUp(bool flag) { _cameraRequiresSetUp = flag; }
146 bool getCameraRequiresSetUp() const { return _cameraRequiresSetUp; }
147
148 void setCameraAttachmentMapCount(unsigned int v) { _cameraAttachmentMapModifiedCount = v; }
149 unsigned int getCameraAttachmentMapCount() { return _cameraAttachmentMapModifiedCount; }
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; }
162 GLenum getImageReadPixelFormat() const { return _imageReadPixelFormat; }
163
164 void setImageReadPixelDataType(GLenum type) { _imageReadPixelDataType = type; }
165 GLenum getImageReadPixelDataType() const { return _imageReadPixelDataType; }
166
172 const osg::FrameBufferObject* getFrameBufferObject() const { return _fbo.get(); }
173
181 const osg::FrameBufferObject* getMultisampleResolveFramebufferObject() const { return _resolveFbo.get(); }
182
186 void setDisableFboAfterRender(bool disable) {_disableFboAfterRender = disable;}
187 bool getDisableFboAfterRender() const {return _disableFboAfterRender;}
188
189 void setGraphicsContext(osg::GraphicsContext* context) { _graphicsContext = context; }
190 osg::GraphicsContext* getGraphicsContext() { return _graphicsContext.get(); }
191 const osg::GraphicsContext* getGraphicsContext() const { return _graphicsContext.get(); }
192
193
194
195
196 void setInheritedPositionalStateContainerMatrix(const osg::Matrix& matrix) { _inheritedPositionalStateContainerMatrix = matrix; }
197 const osg::Matrix& getInheritedPositionalStateContainerMatrix() const { return _inheritedPositionalStateContainerMatrix; }
198
199 void setInheritedPositionalStateContainer(PositionalStateContainer* rsl) { _inheritedPositionalStateContainer = rsl; }
200 PositionalStateContainer* getInheritedPositionalStateContainer() { return _inheritedPositionalStateContainer.get(); }
201
202 void setPositionalStateContainer(PositionalStateContainer* rsl) { _renderStageLighting = rsl; }
203
205 {
206 if (!_renderStageLighting.valid()) _renderStageLighting = new PositionalStateContainer;
207 return _renderStageLighting.get();
208 }
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
235 void addToDependencyList(RenderStage* rs) { addPreRenderStage(rs); }
236
237 void addPreRenderStage(RenderStage* rs, int order = 0);
238
239 void addPostRenderStage(RenderStage* rs, int order = 0);
240
241 const RenderStageList& getPreRenderList() const { return _preRenderList; }
242 RenderStageList& getPreRenderList() { return _preRenderList; }
243
244 const RenderStageList& getPostRenderList() const { return _postRenderList; }
245 RenderStageList& getPostRenderList() { return _postRenderList; }
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
Definition PositionalStateContainer:30
Definition RenderBin:34
SortMode
Definition RenderBin:42
Definition RenderLeaf:34
Definition RenderStage:38
bool _cameraRequiresSetUp
Definition RenderStage:300
void setMultisampleResolveFramebufferObject(osg::FrameBufferObject *fbo)
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
bool getStats(Statistics &stats) const
const osg::GraphicsContext * getGraphicsContext() const
Definition RenderStage:191
GLenum getDrawBuffer() const
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
bool getCameraRequiresSetUp() const
Definition RenderStage:146
void setDrawBuffer(GLenum buffer, bool applyMask=true)
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
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
Definition RenderStage:50
void setInitialViewMatrix(const osg::RefMatrix *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
Definition RenderStage:138
bool getReadBufferApplyMask() const
Definition RenderStage:78
GLenum getReadBuffer() const
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)
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)
Definition RenderStage:85
void clearReferencesToDependentCameras()
void runCameraSetUp(osg::RenderInfo &renderInfo)
virtual bool isSameKindAs(const osg::Object *obj) const
Definition RenderStage:51
void setClearMask(GLbitfield mask)
Definition RenderStage:101
Cameras _dependentCameras
Definition RenderStage:283
virtual osg::Object * cloneType() const
Definition RenderStage:49
void setDrawBufferApplyMask(bool applyMask)
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()
Definition RenderStage:97
const osg::ColorMask * getColorMask() const
Definition RenderStage:109
virtual const char * className() const
Definition RenderStage:52
const osg::FrameBufferObject * getMultisampleResolveFramebufferObject() const
Definition RenderStage:181
const osg::Vec4 & getClearAccum() const
Definition RenderStage:124
RenderStage(SortMode mode)
const osg::Vec4 & getClearColor() const
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)
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
Definition RenderStage:64
const osg::Viewport * getViewport() const
Definition RenderStage:88
PositionalStateContainer * getInheritedPositionalStateContainer()
Definition RenderStage:200
GLbitfield getClearMask() const
Definition RenderStage:104
void setClearStencil(int stencil)
Definition RenderStage:135
GLenum _imageReadPixelDataType
Definition RenderStage:310
osg::ref_ptr< osg::FrameBufferObject > _fbo
Definition RenderStage:314
void setClearDepth(double depth)
Definition RenderStage:128
RenderStage(const RenderStage &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
void setReadBuffer(GLenum buffer, bool applyMask=true)
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)
Definition RenderStage:81
GLenum _drawBuffer
Definition RenderStage:289
unsigned int _level
Definition RenderStage:305
GLenum _imageReadPixelFormat
Definition RenderStage:309
void setDisableFboAfterRender(bool disable)
Definition RenderStage:186
void collateReferencesToDependentCameras()
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)
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()
Definition RenderStage:91
GLenum _readBuffer
Definition RenderStage:291
Definition Statistics:48
Definition Camera:45
BufferComponent
Definition Camera:326
Definition ColorMask:25
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Definition FrameBufferObject:321
Definition GraphicsContext:30
Definition Image:179
Definition Matrixd:27
Definition Object:61
Definition Matrixd:412
Definition RenderInfo:28
Definition StateAttribute:77
Definition State:80
Definition Texture:422
Definition Vec4f:28
Definition Viewport:24
Definition observer_ptr:39
Definition ref_ptr:32
Shader generator framework.
Definition NodeVisitor:25
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
Definition RenderStage:254
osg::ref_ptr< osg::Image > _image
Definition RenderStage:255
GLenum _imageReadPixelDataType
Definition RenderStage:257
GLenum _imageReadPixelFormat
Definition RenderStage:256