diff --git a/examples/osgcamera/osgcamera.cpp b/examples/osgcamera/osgcamera.cpp index d67f1938c..8149325ba 100644 --- a/examples/osgcamera/osgcamera.cpp +++ b/examples/osgcamera/osgcamera.cpp @@ -40,7 +40,7 @@ void singleWindowMultipleCameras(osgViewer::Viewer& viewer) osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); if (gw) { - osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height ); } @@ -80,17 +80,18 @@ void multipleWindowMultipleCameras(osgViewer::Viewer& viewer) wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); - unsigned int numCameras = 2; + unsigned int numCameras = 4; double aspectRatioScale = (double)numCameras; double translate_x = double(numCameras)-1; for(unsigned int i=0; i traits = new osg::GraphicsContext::Traits; + traits->screenNum = i / 2; traits->x = (i*width)/numCameras; traits->y = 0; traits->width = width/numCameras-1; traits->height = height; - #if 1 + #if 0 traits->windowDecoration = false; #else traits->windowDecoration = true; @@ -103,7 +104,7 @@ void multipleWindowMultipleCameras(osgViewer::Viewer& viewer) osgViewer::GraphicsWindow* gw = dynamic_cast(gc.get()); if (gw) { - osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, traits->width, traits->height ); } @@ -149,7 +150,7 @@ int main( int argc, char **argv ) } } - osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts(2); + // osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts(4); osg::Referenced::setThreadSafeReferenceCounting(true); // load the scene. @@ -171,7 +172,7 @@ int main( int argc, char **argv ) if (apm.valid()) viewer.setCameraManipulator(apm.get()); else viewer.setCameraManipulator( new osgGA::TrackballManipulator() ); -#if 0 +#if 1 // singleWindowMultipleCameras(viewer); @@ -182,7 +183,10 @@ int main( int argc, char **argv ) viewer.setUpViewAcrossAllScreens(); -#endif +#endif + + loadedModel->resizeGLObjectBuffers(osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts()); + viewer.realize(); diff --git a/include/osg/Camera b/include/osg/Camera index afc87437f..8beab8149 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -352,6 +352,9 @@ class OSG_EXPORT Camera : public Transform, public CullSettings OpenThreads::Mutex* getDataChangeMutex() const { return &_dataChangeMutex; } + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** If State is non-zero, this function releases any associated OpenGL objects for * the specified graphics context. Otherwise, releases OpenGL objexts * for all graphics contexts. */ diff --git a/include/osg/Drawable b/include/osg/Drawable index c224907a8..88fdbceeb 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -278,6 +278,9 @@ class OSG_EXPORT Drawable : public Object */ virtual void compileGLObjects(RenderInfo& renderInfo) const; + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** If State is non-zero, this function releases OpenGL objects for * the specified graphics context. Otherwise, releases OpenGL objexts * for all graphics contexts. */ diff --git a/include/osg/FragmentProgram b/include/osg/FragmentProgram index 44d861473..cd59b64da 100644 --- a/include/osg/FragmentProgram +++ b/include/osg/FragmentProgram @@ -220,6 +220,9 @@ class OSG_EXPORT FragmentProgram : public StateAttribute virtual void compileGLObjects(State& state) const { apply(state); } + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** release an OpenGL objects in specified graphics context if State object is passed, otherwise release OpenGL objexts for all graphics context if State object pointer == NULL.*/ diff --git a/include/osg/Geode b/include/osg/Geode index 4d258c64d..31597ac9a 100644 --- a/include/osg/Geode +++ b/include/osg/Geode @@ -138,6 +138,9 @@ class OSG_EXPORT Geode : public Node virtual BoundingSphere computeBound() const; + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** If State is non-zero, this function releases any associated OpenGL objects for * the specified graphics context. Otherwise, releases OpenGL objexts * for all graphics contexts. */ diff --git a/include/osg/Group b/include/osg/Group index f5c0db1d3..41f01d905 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -142,6 +142,9 @@ class OSG_EXPORT Group : public Node return _children.size(); // node not found. } + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** If State is non-zero, this function releases any associated OpenGL objects for * the specified graphics context. Otherwise, releases OpenGL objexts * for all graphics contexts. */ diff --git a/include/osg/Node b/include/osg/Node index 803a1c8ec..1e1d5e277 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -299,6 +299,8 @@ class OSG_EXPORT Node : public Object /** Get the const compute bound callback.*/ const ComputeBoundingSphereCallback* getComputeBoundingSphereCallback() const { return _computeBoundCallback.get(); } + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/); /** If State is non-zero, this function releases any associated OpenGL objects for * the specified graphics context. Otherwise, releases OpenGL objexts diff --git a/include/osg/Object b/include/osg/Object index 48b4223ba..1111237ff 100644 --- a/include/osg/Object +++ b/include/osg/Object @@ -118,6 +118,8 @@ class OSG_EXPORT Object : public Referenced /** Get const user data.*/ inline const Referenced* getUserData() const { return _userData.get(); } + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {} /** If State is non-zero, this function releases any associated OpenGL objects for * the specified graphics context. Otherwise, releases OpenGL objexts diff --git a/include/osg/PrimitiveSet b/include/osg/PrimitiveSet index 835b93092..66655f4a2 100644 --- a/include/osg/PrimitiveSet +++ b/include/osg/PrimitiveSet @@ -242,6 +242,9 @@ class OSG_EXPORT PrimitiveSet : public Object /** Get modified count value.*/ inline unsigned int getModifiedCount() const { return _modifiedCount; } + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {} + /** If State is non-zero, this function releases OpenGL objects for * the specified graphics context. Otherwise, releases OpenGL objexts * for all graphics contexts. */ @@ -437,6 +440,9 @@ class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorGLubyte virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } virtual void offsetIndices(int offset); + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + virtual void releaseGLObjects(State* state=0) const; virtual void computeRange() const @@ -517,6 +523,9 @@ class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorGLushort virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } virtual void offsetIndices(int offset); + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + virtual void releaseGLObjects(State* state=0) const; virtual void computeRange() const @@ -595,6 +604,9 @@ class OSG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorGLuint virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } virtual void offsetIndices(int offset); + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + virtual void releaseGLObjects(State* state=0) const; virtual void computeRange() const diff --git a/include/osg/Program b/include/osg/Program index 6bed61aec..f0e8b9e02 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -63,6 +63,9 @@ class OSG_EXPORT Program : public osg::StateAttribute virtual void compileGLObjects(osg::State& state) const; + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** release OpenGL objects in specified graphics context if State object is passed, otherwise release OpenGL objects for all graphics context if State object pointer NULL.*/ diff --git a/include/osg/Shader b/include/osg/Shader index 828523f27..223145245 100644 --- a/include/osg/Shader +++ b/include/osg/Shader @@ -81,6 +81,9 @@ class OSG_EXPORT Shader : public osg::Object /** Get the Shader type as a descriptive string. */ const char* getTypename() const; + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** release OpenGL objects in specified graphics context if State object is passed, otherwise release OpenGL objects for all graphics context if State object pointer NULL.*/ diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 2260292e2..f15461291 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -312,10 +312,13 @@ class OSG_EXPORT StateAttribute : public Object */ virtual void apply(State&) const {} - /** default to nothing to compile - all state is applied immediately. */ + /** Default to nothing to compile - all state is applied immediately. */ virtual void compileGLObjects(State&) const {} - /** release OpenGL objects in specified graphics context if State + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {} + + /** Release OpenGL objects in specified graphics context if State object is passed, otherwise release OpenGL objexts for all graphics context if State object pointer NULL.*/ virtual void releaseGLObjects(State* =0) const {} diff --git a/include/osg/StateSet b/include/osg/StateSet index 1fac5e1cc..cb8ffb206 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -417,6 +417,9 @@ class OSG_EXPORT StateSet : public Object /** call compile on all StateAttributes contained within this StateSet.*/ void compileGLObjects(State& state) const; + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** call release on all StateAttributes contained within this StateSet.*/ virtual void releaseGLObjects(State* state=0) const; diff --git a/include/osg/Texture b/include/osg/Texture index 6b641ca0d..6c83e369b 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -451,6 +451,9 @@ class OSG_EXPORT Texture : public osg::StateAttribute /** Calls apply(state) to compile the texture. */ virtual void compileGLObjects(State& state) const; + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** If State is non-zero, this function releases OpenGL objects for * the specified graphics context. Otherwise, releases OpenGL objexts * for all graphics contexts. */ diff --git a/include/osg/VertexProgram b/include/osg/VertexProgram index 989a1159a..ee6ebd846 100644 --- a/include/osg/VertexProgram +++ b/include/osg/VertexProgram @@ -221,6 +221,9 @@ class OSG_EXPORT VertexProgram : public StateAttribute virtual void compileGLObjects(State& state) const { apply(state); } + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + /** Release any OpenGL objects in specified graphics context if State * object is passed, otherwise release OpenGL objexts for all graphics contexts if * State object pointer is NULL. diff --git a/include/osg/buffered_value b/include/osg/buffered_value index aad79b45b..d2714685d 100644 --- a/include/osg/buffered_value +++ b/include/osg/buffered_value @@ -48,6 +48,8 @@ class buffered_value inline bool empty() const { return _array.empty(); } inline unsigned int size() const { return _array.size(); } + + inline void resize(unsigned int newSize) { _array.resize(newSize,0); } inline T& operator[] (unsigned int pos) { @@ -99,6 +101,8 @@ class buffered_object inline unsigned int size() const { return _array.size(); } + inline void resize(unsigned int newSize) { _array.resize(newSize); } + inline T& operator[] (unsigned int pos) { // automatically resize array. diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index 26317cbb9..27fc8ea5e 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -241,6 +241,13 @@ void Camera::detach(BufferComponent buffer) _bufferAttachmentMap.erase(buffer); } +void Camera::resizeGLObjectBuffers(unsigned int maxSize) +{ + _renderingCache.resize(maxSize); + + Transform::resizeGLObjectBuffers(maxSize); +} + void Camera::releaseGLObjects(osg::State* state) const { if (state) const_cast(this)->_renderingCache[state->getContextID()] = 0; diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 6f6171b02..71a9126f1 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -479,6 +479,14 @@ void Drawable::compileGLObjects(RenderInfo& renderInfo) const } +void Drawable::resizeGLObjectBuffers(unsigned int maxSize) +{ + if (_stateset.valid()) _stateset->resizeGLObjectBuffers(maxSize); + if (_drawCallback.valid()) _drawCallback->resizeGLObjectBuffers(maxSize); + + _globjList.resize(maxSize); +} + void Drawable::releaseGLObjects(State* state) const { if (_stateset.valid()) _stateset->releaseGLObjects(state); diff --git a/src/osg/FragmentProgram.cpp b/src/osg/FragmentProgram.cpp index 04f946c3e..8db673e09 100644 --- a/src/osg/FragmentProgram.cpp +++ b/src/osg/FragmentProgram.cpp @@ -183,6 +183,11 @@ void FragmentProgram::apply(State& state) const } } +void FragmentProgram::resizeGLObjectBuffers(unsigned int maxSize) +{ + _fragmentProgramIDList.resize(maxSize); +} + void FragmentProgram::releaseGLObjects(State* state) const { if (!state) const_cast(this)->dirtyFragmentProgramObject(); diff --git a/src/osg/Geode.cpp b/src/osg/Geode.cpp index c2b2fafc1..bad02d8aa 100644 --- a/src/osg/Geode.cpp +++ b/src/osg/Geode.cpp @@ -209,6 +209,18 @@ void Geode::compileDrawables(RenderInfo& renderInfo) } } +void Geode::resizeGLObjectBuffers(unsigned int maxSize) +{ + Node::resizeGLObjectBuffers(maxSize); + + for(DrawableList::const_iterator itr=_drawables.begin(); + itr!=_drawables.end(); + ++itr) + { + (*itr)->resizeGLObjectBuffers(maxSize); + } +} + void Geode::releaseGLObjects(osg::State* state) const { Node::releaseGLObjects(state); diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index f33845057..d9735ccf9 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -379,6 +379,18 @@ BoundingSphere Group::computeBound() const return bsphere; } +void Group::resizeGLObjectBuffers(unsigned int maxSize) +{ + Node::resizeGLObjectBuffers(maxSize); + + for(NodeList::const_iterator itr=_children.begin(); + itr!=_children.end(); + ++itr) + { + (*itr)->resizeGLObjectBuffers(maxSize); + } +} + void Group::releaseGLObjects(osg::State* state) const { Node::releaseGLObjects(state); diff --git a/src/osg/Node.cpp b/src/osg/Node.cpp index e73cd827e..26d691053 100644 --- a/src/osg/Node.cpp +++ b/src/osg/Node.cpp @@ -491,6 +491,14 @@ void Node::dirtyBound() } } +void Node::resizeGLObjectBuffers(unsigned int maxSize) +{ + if (_stateset.valid()) _stateset->resizeGLObjectBuffers(maxSize); + if (_updateCallback.valid()) _updateCallback->resizeGLObjectBuffers(maxSize); + if (_eventCallback.valid()) _eventCallback->resizeGLObjectBuffers(maxSize); + if (_cullCallback.valid()) _cullCallback->resizeGLObjectBuffers(maxSize); +} + void Node::releaseGLObjects(osg::State* state) const { if (_stateset.valid()) _stateset->releaseGLObjects(state); diff --git a/src/osg/PrimitiveSet.cpp b/src/osg/PrimitiveSet.cpp index f4d2b12a0..18aa2154b 100644 --- a/src/osg/PrimitiveSet.cpp +++ b/src/osg/PrimitiveSet.cpp @@ -121,6 +121,11 @@ DrawElementsUByte::~DrawElementsUByte() releaseGLObjects(); } +void DrawElementsUByte::resizeGLObjectBuffers(unsigned int maxSize) +{ + _vboList.resize(maxSize); +} + void DrawElementsUByte::releaseGLObjects(State* state) const { if (state) @@ -209,6 +214,11 @@ DrawElementsUShort::~DrawElementsUShort() releaseGLObjects(); } +void DrawElementsUShort::resizeGLObjectBuffers(unsigned int maxSize) +{ + _vboList.resize(maxSize); +} + void DrawElementsUShort::releaseGLObjects(State* state) const { if (state) @@ -298,6 +308,11 @@ DrawElementsUInt::~DrawElementsUInt() releaseGLObjects(); } +void DrawElementsUInt::resizeGLObjectBuffers(unsigned int maxSize) +{ + _vboList.resize(maxSize); +} + void DrawElementsUInt::releaseGLObjects(State* state) const { if (state) diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index bb8893827..30f302404 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -1994,6 +1994,16 @@ void Program::dirtyProgram() } +void Program::resizeGLObjectBuffers(unsigned int maxSize) +{ + for( unsigned int i=0; i < _shaderList.size(); ++i ) + { + if (_shaderList[i].valid()) _shaderList[i]->resizeGLObjectBuffers(maxSize); + } + + _pcpList.resize(maxSize); +} + void Program::releaseGLObjects(osg::State* state) const { for( unsigned int i=0; i < _shaderList.size(); ++i ) diff --git a/src/osg/Shader.cpp b/src/osg/Shader.cpp index 93f29ead6..29be20acf 100644 --- a/src/osg/Shader.cpp +++ b/src/osg/Shader.cpp @@ -196,6 +196,10 @@ Shader::Type Shader::getTypeId( const std::string& tname ) return UNDEFINED; } +void Shader::resizeGLObjectBuffers(unsigned int maxSize) +{ + _pcsList.resize(maxSize); +} void Shader::releaseGLObjects(osg::State* state) const { diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 0b5457ca5..d619eab39 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -1202,6 +1202,28 @@ void StateSet::compileGLObjects(State& state) const } } +void StateSet::resizeGLObjectBuffers(unsigned int maxSize) +{ + for(AttributeList::const_iterator itr = _attributeList.begin(); + itr!=_attributeList.end(); + ++itr) + { + itr->second.first->resizeGLObjectBuffers(maxSize); + } + + for(TextureAttributeList::const_iterator taitr=_textureAttributeList.begin(); + taitr!=_textureAttributeList.end(); + ++taitr) + { + for(AttributeList::const_iterator itr = taitr->begin(); + itr!=taitr->end(); + ++itr) + { + itr->second.first->resizeGLObjectBuffers(maxSize); + } + } +} + void StateSet::releaseGLObjects(State* state) const { for(AttributeList::const_iterator itr = _attributeList.begin(); diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 72808cbcd..e47b6da96 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -1295,6 +1295,11 @@ void Texture::compileGLObjects(State& state) const apply(state); } +void Texture::resizeGLObjectBuffers(unsigned int maxSize) +{ + _textureObjectBuffer.resize(maxSize); +} + void Texture::releaseGLObjects(State* state) const { if (!state) const_cast(this)->dirtyTextureObject(); diff --git a/src/osg/VertexProgram.cpp b/src/osg/VertexProgram.cpp index 0323d0f88..e4cb45f1b 100644 --- a/src/osg/VertexProgram.cpp +++ b/src/osg/VertexProgram.cpp @@ -183,6 +183,11 @@ void VertexProgram::apply(State& state) const } } +void VertexProgram::resizeGLObjectBuffers(unsigned int maxSize) +{ + _vertexProgramIDList.resize(maxSize); +} + void VertexProgram::releaseGLObjects(State* state) const { if (!state) const_cast(this)->dirtyVertexProgramObject();