Added Object::resizeGLObjectBuffers(uint) method to help improve the ability
to change the number of active graphics contexts on the fly during an applications life.
This commit is contained in:
@@ -40,7 +40,7 @@ void singleWindowMultipleCameras(osgViewer::Viewer& viewer)
|
||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
||||
if (gw)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
||||
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
||||
|
||||
gw->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<numCameras;++i, translate_x -= 2.0)
|
||||
{
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> 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<osgViewer::GraphicsWindow*>(gc.get());
|
||||
if (gw)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
||||
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
||||
|
||||
gw->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();
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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.*/
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.*/
|
||||
|
||||
@@ -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.*/
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<Camera*>(this)->_renderingCache[state->getContextID()] = 0;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<FragmentProgram*>(this)->dirtyFragmentProgramObject();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Texture*>(this)->dirtyTextureObject();
|
||||
|
||||
@@ -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<VertexProgram*>(this)->dirtyVertexProgramObject();
|
||||
|
||||
Reference in New Issue
Block a user