diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 4397b9217..6b655e793 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -199,6 +199,16 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced void setApplication(const std::string& application) { _application = application; } const std::string& getApplication() { return _application; } + + void setMaxTexturePoolSize(unsigned int size) { _maxTexturePoolSize = size; } + unsigned int getMaxTexturePoolSize() const { return _maxTexturePoolSize; } + + void setMaxVBOPoolSize(unsigned int size) { _maxVBOPoolSize = size; } + unsigned int getMaxVBOPoolSize() const { return _maxVBOPoolSize; } + + void setMaxFBOPoolSize(unsigned int size) { _maxFBOPoolSize = size; } + unsigned int getMaxFBOPoolSize() const { return _maxFBOPoolSize; } + protected: virtual ~DisplaySettings(); @@ -240,6 +250,9 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced std::string _application; + unsigned int _maxTexturePoolSize; + unsigned int _maxVBOPoolSize; + unsigned int _maxFBOPoolSize; }; } diff --git a/include/osg/State b/include/osg/State index 7b294e468..0438c5403 100644 --- a/include/osg/State +++ b/include/osg/State @@ -39,7 +39,7 @@ #ifdef GL_FOG_COORDINATE_ARRAY_EXT #define GL_FOG_COORDINATE_ARRAY GL_FOG_COORDINATE_ARRAY_EXT #else - #define GL_FOG_COORDINATE_ARRAY 0x8457 + #define GL_FOG_COORDINATE_ARRAY 0x8457 #endif #endif @@ -47,14 +47,14 @@ #ifdef GL_SECONDARY_COLOR_ARRAY_EXT #define GL_SECONDARY_COLOR_ARRAY GL_SECONDARY_COLOR_ARRAY_EXT #else - #define GL_SECONDARY_COLOR_ARRAY 0x845E + #define GL_SECONDARY_COLOR_ARRAY 0x845E #endif #endif namespace osg { /** macro for use with osg::StateAttribute::apply methods for detecting and - * reporting OpenGL error messages.*/ +* reporting OpenGL error messages.*/ #define OSG_GL_DEBUG(message) \ if (state.getFineGrainedErrorDetection()) \ { \ @@ -70,37 +70,37 @@ namespace osg { class GraphicsContext; /** Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings, - * implements lazy state updating and provides accessors for querying the current state. - * The venerable Red Book says that "OpenGL is a state machine", and this class - * represents the OpenGL state in OSG. Furthermore, \c State also has other - * important features: - * - It works as a stack of states (see \c pushStateSet() and - * \c popStateSet()). Manipulating this stack of OpenGL states manually is - * seldom needed, since OSG does this in the most common situations. - * - It implements lazy state updating. This means that, if one requests a - * state change and that particular state is already in the requested state, - * no OpenGL call will be made. This ensures that the OpenGL pipeline is not - * stalled by unnecessary state changes. - * - It allows to query the current OpenGL state without calls to \c glGet*(), - * which typically stall the graphics pipeline (see, for instance, - * \c captureCurrentState() and \c getModelViewMatrix()). - */ +* implements lazy state updating and provides accessors for querying the current state. +* The venerable Red Book says that "OpenGL is a state machine", and this class +* represents the OpenGL state in OSG. Furthermore, \c State also has other +* important features: +* - It works as a stack of states (see \c pushStateSet() and +* \c popStateSet()). Manipulating this stack of OpenGL states manually is +* seldom needed, since OSG does this in the most common situations. +* - It implements lazy state updating. This means that, if one requests a +* state change and that particular state is already in the requested state, +* no OpenGL call will be made. This ensures that the OpenGL pipeline is not +* stalled by unnecessary state changes. +* - It allows to query the current OpenGL state without calls to \c glGet*(), +* which typically stall the graphics pipeline (see, for instance, +* \c captureCurrentState() and \c getModelViewMatrix()). +*/ class OSG_EXPORT State : public Referenced, public Observer { public : State(); - - /** Set the graphics context associated with that owns this State object.*/ + + /** Set the graphics context associated with that owns this State object.*/ void setGraphicsContext(GraphicsContext* context) { _graphicsContext = context; } - /** Get the graphics context associated with that owns this State object.*/ + /** Get the graphics context associated with that owns this State object.*/ GraphicsContext* getGraphicsContext() { return _graphicsContext; } - /** Get the const graphics context associated with that owns this State object.*/ + /** Get the const graphics context associated with that owns this State object.*/ const GraphicsContext* getGraphicsContext() const { return _graphicsContext; } - + /** Set the current OpenGL context uniqueID. Note, it is the application developers responsibility to @@ -122,9 +122,9 @@ class OSG_EXPORT State : public Referenced, public Observer /** Pop stateset off state stack.*/ void popStateSet(); - + /** pop all statesets off state stack, ensuring it is empty ready for the next frame. - * Note, to return OpenGL to default state, one should do any state.popAllStatSets(); state.apply().*/ + * Note, to return OpenGL to default state, one should do any state.popAllStatSets(); state.apply().*/ void popAllStateSets(); /** Insert stateset onto state stack.*/ @@ -132,10 +132,10 @@ class OSG_EXPORT State : public Referenced, public Observer /** Pop stateset off state stack.*/ void removeStateSet(unsigned int pos); - + /** Get the number of StateSet's on the StateSet stack.*/ unsigned int getStateSetStackSize() { return static_cast(_stateStateStack.size()); } - + /** Pop StateSet's for the StateSet stack till its size equals the specified size.*/ void popStateSetStackToSize(unsigned int size) { while (_stateStateStack.size()>size) popStateSet(); } @@ -143,7 +143,7 @@ class OSG_EXPORT State : public Referenced, public Observer /** Get the StateSet stack.*/ StateSetStack& getStateSetStack() { return _stateStateStack; } - + /** Copy the modes and attributes which capture the current state.*/ void captureCurrentState(StateSet& stateset) const; @@ -216,14 +216,14 @@ class OSG_EXPORT State : public Referenced, public Observer void apply(const StateSet* dstate); /** Updates the OpenGL state so that it matches the \c StateSet at the - * top of the stack of StateSets maintained internally by a - * \c State. - */ + * top of the stack of StateSets maintained internally by a + * \c State. + */ void apply(); /** Set whether a particular OpenGL mode is valid in the current graphics context. - * Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/ + * Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/ inline void setModeValidity(StateAttribute::GLMode mode,bool valid) { ModeStack& ms = _modeMap[mode]; @@ -231,7 +231,7 @@ class OSG_EXPORT State : public Referenced, public Observer } /** Get whether a particular OpenGL mode is valid in the current graphics context. - * Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/ + * Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/ inline bool getModeValidity(StateAttribute::GLMode mode) { ModeStack& ms = _modeMap[mode]; @@ -251,13 +251,13 @@ class OSG_EXPORT State : public Referenced, public Observer /** Apply an OpenGL mode if required. This is a wrapper around - * \c glEnable() and \c glDisable(), that just actually calls these - * functions if the \c enabled flag is different than the current - * state. - * @return \c true if the state was actually changed. \c false - * otherwise. Notice that a \c false return does not indicate - * an error, it just means that the mode was already set to the - * same value as the \c enabled parameter. + * \c glEnable() and \c glDisable(), that just actually calls these + * functions if the \c enabled flag is different than the current + * state. + * @return \c true if the state was actually changed. \c false + * otherwise. Notice that a \c false return does not indicate + * an error, it just means that the mode was already set to the + * same value as the \c enabled parameter. */ inline bool applyMode(StateAttribute::GLMode mode,bool enabled) { @@ -345,44 +345,44 @@ class OSG_EXPORT State : public Referenced, public Observer void haveAppliedMode(StateAttribute::GLMode mode,StateAttribute::GLModeValue value); /** Mode has been set externally, therefore dirty the associated mode in osg::State - * so it is applied on next call to osg::State::apply(..)*/ + * so it is applied on next call to osg::State::apply(..)*/ void haveAppliedMode(StateAttribute::GLMode mode); /** Attribute has been applied externally, update state to reflect this setting.*/ void haveAppliedAttribute(const StateAttribute* attribute); - /** Attribute has been applied externally, - * and therefore this attribute type has been dirtied - * and will need to be re-applied on next osg::State.apply(..). - * note, if you have an osg::StateAttribute which you have applied externally - * then use the have_applied(attribute) method as this will cause the osg::State to - * track the current state more accurately and enable lazy state updating such - * that only changed state will be applied.*/ + /** Attribute has been applied externally, + * and therefore this attribute type has been dirtied + * and will need to be re-applied on next osg::State.apply(..). + * note, if you have an osg::StateAttribute which you have applied externally + * then use the have_applied(attribute) method as this will cause the osg::State to + * track the current state more accurately and enable lazy state updating such + * that only changed state will be applied.*/ void haveAppliedAttribute(StateAttribute::Type type, unsigned int member=0); - /** Get whether the current specified mode is enabled (true) or disabled (false).*/ + /** Get whether the current specified mode is enabled (true) or disabled (false).*/ bool getLastAppliedMode(StateAttribute::GLMode mode) const; - /** Get the current specified attribute, return NULL if one has not yet been applied.*/ + /** Get the current specified attribute, return NULL if one has not yet been applied.*/ const StateAttribute* getLastAppliedAttribute(StateAttribute::Type type, unsigned int member=0) const; /** texture Mode has been set externally, update state to reflect this setting.*/ void haveAppliedTextureMode(unsigned int unit, StateAttribute::GLMode mode,StateAttribute::GLModeValue value); /** texture Mode has been set externally, therefore dirty the associated mode in osg::State - * so it is applied on next call to osg::State::apply(..)*/ + * so it is applied on next call to osg::State::apply(..)*/ void haveAppliedTextureMode(unsigned int unit, StateAttribute::GLMode mode); /** texture Attribute has been applied externally, update state to reflect this setting.*/ void haveAppliedTextureAttribute(unsigned int unit, const StateAttribute* attribute); /** texture Attribute has been applied externally, - * and therefore this attribute type has been dirtied - * and will need to be re-applied on next osg::State.apply(..). - * note, if you have an osg::StateAttribute which you have applied externally - * then use the have_applied(attribute) method as this will the osg::State to - * track the current state more accurately and enable lazy state updating such - * that only changed state will be applied.*/ + * and therefore this attribute type has been dirtied + * and will need to be re-applied on next osg::State.apply(..). + * note, if you have an osg::StateAttribute which you have applied externally + * then use the have_applied(attribute) method as this will the osg::State to + * track the current state more accurately and enable lazy state updating such + * that only changed state will be applied.*/ void haveAppliedTextureAttribute(unsigned int unit, StateAttribute::Type type, unsigned int member=0); /** Get whether the current specified texture mode is enabled (true) or disabled (false).*/ @@ -456,18 +456,18 @@ class OSG_EXPORT State : public Referenced, public Observer inline void unbindPixelBufferObject() { if (!_currentPBO) return; - + _glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB,0); _currentPBO = 0; } - - + + inline void glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount) { if (primcount>=1 && _glDrawArraysInstanced!=0) _glDrawArraysInstanced(mode, first, count, primcount); else glDrawArrays(mode, first, count); } - + inline void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount ) { if (primcount>=1 && _glDrawElementsInstanced!=0) _glDrawElementsInstanced(mode, count, type, indices, primcount); @@ -476,8 +476,8 @@ class OSG_EXPORT State : public Referenced, public Observer /** Wrapper around glInterleavedArrays(..). - * also resets the internal array points and modes within osg::State to keep the other - * vertex array operations consistent. */ + * also resets the internal array points and modes within osg::State to keep the other + * vertex array operations consistent. */ void setInterleavedArrays( GLenum format, GLsizei stride, const GLvoid* pointer); /** Set the vertex pointer using an osg::Array, and manage any VBO that are required.*/ @@ -487,7 +487,7 @@ class OSG_EXPORT State : public Referenced, public Observer { const VertexBufferObject* vbo = array->getVertexBufferObject(); if (vbo) - { + { bindVertexBufferObject(vbo); setVertexPointer(array->getDataSize(),array->getDataType(),0,array->getVertexBufferObjectOffset()); } @@ -501,9 +501,9 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer(..); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void setVertexPointer( GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr ) + GLsizei stride, const GLvoid *ptr ) { if (!_vertexArray._enabled || _vertexArray._dirty) { @@ -519,7 +519,7 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glDisableClientState(GL_VERTEX_ARRAY). - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void disableVertexPointer() { if (_vertexArray._enabled || _vertexArray._dirty) @@ -544,9 +544,9 @@ class OSG_EXPORT State : public Referenced, public Observer { const VertexBufferObject* vbo = array->getVertexBufferObject(); if (vbo) - { + { bindVertexBufferObject(vbo); - setNormalPointer(array->getDataType(),0,array->getVertexBufferObjectOffset()); + setNormalPointer(array->getDataType(),0,array->getVertexBufferObjectOffset()); } else { @@ -558,9 +558,9 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glEnableClientState(GL_NORMAL_ARRAY);glNormalPointer(..); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void setNormalPointer( GLenum type, GLsizei stride, - const GLvoid *ptr ) + const GLvoid *ptr ) { if (!_normalArray._enabled || _normalArray._dirty) { @@ -576,7 +576,7 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glDisableClientState(GL_NORMAL_ARRAY); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void disableNormalPointer() { if (_normalArray._enabled || _normalArray._dirty) @@ -600,7 +600,7 @@ class OSG_EXPORT State : public Referenced, public Observer { const VertexBufferObject* vbo = array->getVertexBufferObject(); if (vbo) - { + { bindVertexBufferObject(vbo); setColorPointer(array->getDataSize(),array->getDataType(),0,array->getVertexBufferObjectOffset()); } @@ -615,9 +615,9 @@ class OSG_EXPORT State : public Referenced, public Observer /** wrapper around glEnableClientState(GL_COLOR_ARRAY);glColorPointer(..); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void setColorPointer( GLint size, GLenum type, - GLsizei stride, const GLvoid *ptr ) + GLsizei stride, const GLvoid *ptr ) { if (!_colorArray._enabled || _colorArray._dirty) { @@ -633,7 +633,7 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glDisableClientState(GL_COLOR_ARRAY); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void disableColorPointer() { if (_colorArray._enabled || _colorArray._dirty) @@ -661,9 +661,9 @@ class OSG_EXPORT State : public Referenced, public Observer { const VertexBufferObject* vbo = array->getVertexBufferObject(); if (vbo) - { + { bindVertexBufferObject(vbo); -#if 0 +#if 0 setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,vbo->getOffset(array->getVertexBufferObjectIndex())); #else setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,array->getVertexBufferObjectOffset()); @@ -679,11 +679,11 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glEnableClientState(GL_SECONDARY_COLOR_ARRAY);glSecondayColorPointer(..); - * note, only updates values that change.*/ + * note, only updates values that change.*/ void setSecondaryColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr ); /** wrapper around glDisableClientState(GL_SECONDARY_COLOR_ARRAY); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void disableSecondaryColorPointer() { if (_secondaryColorArray._enabled || _secondaryColorArray._dirty) @@ -701,9 +701,9 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glEnableClientState(GL_INDEX_ARRAY);glIndexPointer(..); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void setIndexPointer( GLenum type, GLsizei stride, - const GLvoid *ptr ) + const GLvoid *ptr ) { if (!_indexArray._enabled || _indexArray._dirty) { @@ -719,7 +719,7 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glDisableClientState(GL_INDEX_ARRAY); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void disableIndexPointer() { if (_indexArray._enabled || _indexArray._dirty) @@ -747,7 +747,7 @@ class OSG_EXPORT State : public Referenced, public Observer { const VertexBufferObject* vbo = array->getVertexBufferObject(); if (vbo) - { + { bindVertexBufferObject(vbo); #if 0 setFogCoordPointer(array->getDataType(),0,vbo->getOffset(array->getVertexBufferObjectIndex())); @@ -766,11 +766,11 @@ class OSG_EXPORT State : public Referenced, public Observer /** wrapper around glEnableClientState(GL_FOG_COORDINATE_ARRAY);glFogCoordPointer(..); - * note, only updates values that change.*/ + * note, only updates values that change.*/ void setFogCoordPointer( GLenum type, GLsizei stride, const GLvoid *ptr ); /** wrapper around glDisableClientState(GL_FOG_COORDINATE_ARRAY); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void disableFogCoordPointer() { if (_fogArray._enabled || _fogArray._dirty) @@ -796,7 +796,7 @@ class OSG_EXPORT State : public Referenced, public Observer { const VertexBufferObject* vbo = array->getVertexBufferObject(); if (vbo) - { + { bindVertexBufferObject(vbo); #if 0 setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0,vbo->getOffset(array->getVertexBufferObjectIndex())); @@ -814,7 +814,7 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glEnableClientState(GL_TEXTURE_COORD_ARRAY);glTexCoordPointer(..); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void setTexCoordPointer( unsigned int unit, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr ) @@ -839,7 +839,7 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glDisableClientState(GL_TEXTURE_COORD_ARRAY); - * note, only updates values that change.*/ + * note, only updates values that change.*/ inline void disableTexCoordPointer( unsigned int unit ) { if (setClientActiveTextureUnit(unit)) @@ -896,16 +896,16 @@ class OSG_EXPORT State : public Referenced, public Observer /** Set the current texture unit, return true if selected, - * false if selection failed such as when multi texturing is not supported. - * note, only updates values that change.*/ + * false if selection failed such as when multi texturing is not supported. + * note, only updates values that change.*/ bool setActiveTextureUnit( unsigned int unit ); - + /** Get the current texture unit.*/ unsigned int getActiveTextureUnit() const { return _currentActiveTextureUnit; } /** Set the current tex coord array texture unit, return true if selected, - * false if selection failed such as when multi texturing is not supported. - * note, only updates values that change.*/ + * false if selection failed such as when multi texturing is not supported. + * note, only updates values that change.*/ bool setClientActiveTextureUnit( unsigned int unit ); /** Get the current tex coord array texture unit.*/ @@ -918,9 +918,9 @@ class OSG_EXPORT State : public Referenced, public Observer { const VertexBufferObject* vbo = array->getVertexBufferObject(); if (vbo) - { + { bindVertexBufferObject(vbo); -#if 0 +#if 0 setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),normalized,0,vbo->getOffset(array->getVertexBufferObjectIndex())); #else setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),normalized,0,array->getVertexBufferObjectOffset()); @@ -936,13 +936,13 @@ class OSG_EXPORT State : public Referenced, public Observer } /** wrapper around glEnableVertexAttribArrayARB(index);glVertexAttribPointerARB(..); - * note, only updates values that change.*/ + * note, only updates values that change.*/ void setVertexAttribPointer( unsigned int index, - GLint size, GLenum type, GLboolean normalized, - GLsizei stride, const GLvoid *ptr ); + GLint size, GLenum type, GLboolean normalized, + GLsizei stride, const GLvoid *ptr ); /** wrapper around DisableVertexAttribArrayARB(index); - * note, only updates values that change.*/ + * note, only updates values that change.*/ void disableVertexAttribPointer( unsigned int index ); void disableVertexAttribPointersAboveAndIncluding( unsigned int index ); @@ -965,10 +965,10 @@ class OSG_EXPORT State : public Referenced, public Observer { if (_lastAppliedProgramObject!=program) { - _lastAppliedProgramObject = program; + _lastAppliedProgramObject = program; if (program && _appliedProgramObjectSet.count(program)==0) { - _appliedProgramObjectSet.insert(program); + _appliedProgramObjectSet.insert(program); program->addObserver(this); } } @@ -998,8 +998,8 @@ class OSG_EXPORT State : public Referenced, public Observer /** Set the DisplaySettings. Note, nothing is applied, the visual settings are just - * used in the State object to pass the current visual settings to Drawables - * during rendering. */ + * used in the State object to pass the current visual settings to Drawables + * during rendering. */ inline void setDisplaySettings(DisplaySettings* vs) { _displaySettings = vs; } /** Get the DisplaySettings */ @@ -1011,7 +1011,7 @@ class OSG_EXPORT State : public Referenced, public Observer void setAbortRenderingPtr(bool* abortPtr) { _abortRenderingPtr = abortPtr; } /** Get flag for early termination of the draw traversal, - * if true steps should be taken to complete rendering early.*/ + * if true steps should be taken to complete rendering early.*/ bool getAbortRendering() const { return _abortRenderingPtr!=0?(*_abortRenderingPtr):false; } @@ -1019,13 +1019,13 @@ class OSG_EXPORT State : public Referenced, public Observer { virtual void completed(osg::State*) = 0; }; - + /** Set the callback to be called when the dynamic object count hits 0.*/ void setDynamicObjectRenderingCompletedCallback(DynamicObjectRenderingCompletedCallback* cb){ _completeDynamicObjectRenderingCallback = cb; } - + /** Get the callback to be called when the dynamic object count hits 0.*/ DynamicObjectRenderingCompletedCallback* getDynamicObjectRenderingCompletedCallback() { return _completeDynamicObjectRenderingCallback.get(); } - + /** Set the number of dynamic objects that will be rendered in this graphics context this frame.*/ void setDynamicObjectCount(unsigned int count, bool callCallbackOnZero = false) { @@ -1041,9 +1041,9 @@ class OSG_EXPORT State : public Referenced, public Observer /** Get the number of dynamic objects that will be rendered in this graphics context this frame.*/ unsigned int getDynamicObjectCount() const { return _dynamicObjectCount; } - - /** Decrement the number of dynamic objects left to render this frame, and once the count goes to zero call the - * DynamicObjectRenderingCompletedCallback to inform of completion.*/ + + /** Decrement the number of dynamic objects left to render this frame, and once the count goes to zero call the + * DynamicObjectRenderingCompletedCallback to inform of completion.*/ inline void decrementDynamicObjectCount() { --_dynamicObjectCount; @@ -1051,13 +1051,22 @@ class OSG_EXPORT State : public Referenced, public Observer { _completeDynamicObjectRenderingCallback->completed(this); } - } + } + + void setMaxTexturePoolSize(unsigned int size); + unsigned int getMaxTexturePoolSize() const { return _maxTexturePoolSize; } + + void setMaxVBOPoolSize(unsigned int size); + unsigned int getMaxVBOPoolSize() const { return _maxVBOPoolSize; } + + void setMaxFBOPoolSize(unsigned int size); + unsigned int getMaxFBOPoolSize() const { return _maxFBOPoolSize; } enum CheckForGLErrors { - /** NEVER_CHECK_GL_ERRORS hints that OpenGL need not be checked for, this + /** NEVER_CHECK_GL_ERRORS hints that OpenGL need not be checked for, this is the fastest option since checking for errors does incurr a small overhead.*/ NEVER_CHECK_GL_ERRORS, /** ONCE_PER_FRAME means that OpenGl errors will be checked for once per @@ -1154,13 +1163,13 @@ class OSG_EXPORT State : public Referenced, public Observer /** Apply an OpenGL mode if required, passing in mode, enable flag and - * appropriate mode stack. This is a wrapper around \c glEnable() and - * \c glDisable(), that just actually calls these functions if the - * \c enabled flag is different than the current state. - * @return \c true if the state was actually changed. \c false - * otherwise. Notice that a \c false return does not indicate - * an error, it just means that the mode was already set to the - * same value as the \c enabled parameter. + * appropriate mode stack. This is a wrapper around \c glEnable() and + * \c glDisable(), that just actually calls these functions if the + * \c enabled flag is different than the current state. + * @return \c true if the state was actually changed. \c false + * otherwise. Notice that a \c false return does not indicate + * an error, it just means that the mode was already set to the + * same value as the \c enabled parameter. */ inline bool applyMode(StateAttribute::GLMode mode,bool enabled,ModeStack& ms) { @@ -1224,7 +1233,7 @@ class OSG_EXPORT State : public Referenced, public Observer typedef std::map UniformMap; typedef std::vector > MatrixStack; - + typedef std::set AppliedProgramObjectSet; ModeMap _modeMap; @@ -1239,6 +1248,11 @@ class OSG_EXPORT State : public Referenced, public Observer StateSetStack _stateStateStack; + unsigned int _maxTexturePoolSize; + unsigned int _maxVBOPoolSize; + unsigned int _maxFBOPoolSize; + + struct EnabledArrayPair { EnabledArrayPair():_dirty(true),_enabled(false),_normalized(0),_pointer(0) {} @@ -1326,7 +1340,7 @@ class OSG_EXPORT State : public Referenced, public Observer typedef void (APIENTRY * EnableVertexAttribProc) (unsigned int); typedef void (APIENTRY * DisableVertexAttribProc) (unsigned int); typedef void (APIENTRY * BindBufferProc) (GLenum target, GLuint buffer); - + typedef void (APIENTRY * DrawArraysInstancedProc)( GLenum mode, GLint first, GLsizei count, GLsizei primcount ); typedef void (APIENTRY * DrawElementsInstancedProc)( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount ); @@ -1346,7 +1360,7 @@ class OSG_EXPORT State : public Referenced, public Observer unsigned int _dynamicObjectCount; osg::ref_ptr _completeDynamicObjectRenderingCallback; - + }; inline void State::pushModeList(ModeMap& modeMap,const StateSet::ModeList& modeList) diff --git a/include/osg/Texture b/include/osg/Texture index 78c103027..a9503ef02 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -470,12 +470,17 @@ class OSG_EXPORT Texture : public osg::StateAttribute class TextureObject; - /** Returns a pointer to the texture object for the current context. */ + /** Returns a pointer to the TextureBbject for the current context. */ inline TextureObject* getTextureObject(unsigned int contextID) const { return _textureObjectBuffer[contextID].get(); } + inline void setTextureObject(unsigned int contextID, TextureObject* to) + { + _textureObjectBuffer[contextID] = to; + } + /** Forces a recompile on next apply() of associated OpenGL texture * objects. */ void dirtyTextureObject(); @@ -759,7 +764,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute /** Allocate mipmap levels of the texture by subsequent calling of glTexImage* function. */ virtual void allocateMipmap(State& state) const = 0; - + /** Returns -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */ int compareTexture(const Texture& rhs) const; @@ -769,7 +774,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute typedef buffered_value TexParameterDirtyList; mutable TexParameterDirtyList _texParametersDirtyList; mutable TexParameterDirtyList _texMipmapGenerationDirtyList; - + WrapMode _wrap_s; WrapMode _wrap_t; WrapMode _wrap_r; @@ -790,31 +795,137 @@ class OSG_EXPORT Texture : public osg::StateAttribute mutable GLint _internalFormat; mutable GLenum _sourceFormat; mutable GLenum _sourceType; - + bool _use_shadow_comparison; ShadowCompareFunc _shadow_compare_func; ShadowTextureMode _shadow_texture_mode; float _shadow_ambient; public: - - class TextureObject : public osg::Referenced + + struct TextureProfile { - public: - - inline TextureObject(GLuint id,GLenum target): - _id(id), + inline TextureProfile(GLenum target): _target(target), _numMipmapLevels(0), _internalFormat(0), _width(0), _height(0), _depth(0), - _border(0), + _border(0) {} + + inline TextureProfile(GLenum target, + GLint numMipmapLevels, + GLenum internalFormat, + GLsizei width, + GLsizei height, + GLsizei depth, + GLint border): + _target(target), + _numMipmapLevels(numMipmapLevels), + _internalFormat(internalFormat), + _width(width), + _height(height), + _depth(depth), + _border(border) {} + + + #define LESSTHAN(A,B) if (A > TextureObjectList; - typedef osg::buffered_object TextureObjectListMap; - /** Takes the active texture objects from the Texture and places them - * in the specified TextureObjectListMap. */ - void takeTextureObjects(TextureObjectListMap& toblm); - - - static TextureObject* generateTextureObject(unsigned int contextID,GLenum target); + class TextureObjectSet : public Referenced + { + public: + TextureObjectSet(TextureObjectManager* parent, const TextureProfile& profile); - static TextureObject* generateTextureObject(unsigned int contextID, + void handlePendingOrphandedTextureObjects(); + void flushAllDeletedTextureObjects(); + void discardAllDeletedTextureObjects(); + void flushDeletedTextureObjects(double currentTime, double& availableTime); + + TextureObject* takeOrGenerate(Texture* texture); + void moveToBack(TextureObject* to); + void addToBack(TextureObject* to); + void orphan(TextureObject* to); + unsigned int size() const; + + bool checkConsistency() const; + + protected: + + virtual ~TextureObjectSet(); + + OpenThreads::Mutex _mutex; + + TextureObjectManager* _parent; + unsigned int _contextID; + TextureProfile _profile; + unsigned int _numOfTextureObjects; + TextureObjectList _orphanedTextureObjects; + TextureObjectList _pendingOrphanedTextureObjects; + + TextureObject* _head; + TextureObject* _tail; + + }; + + class TextureObjectManager : public osg::Referenced + { + public: + TextureObjectManager(unsigned int contextID); + + unsigned int getContextID() const { return _contextID; } + + void setTexturePoolSize(unsigned int size); + unsigned int getTexturePoolSize() const { return _texturePoolSize; } + + TextureObject* generateTextureObject(const Texture* texture, GLenum target); + TextureObject* generateTextureObject(const Texture* texture, + GLenum target, + GLint numMipmapLevels, + GLenum internalFormat, + GLsizei width, + GLsizei height, + GLsizei depth, + GLint border); + void handlePendingOrphandedTextureObjects(); + void flushAllDeletedTextureObjects(); + void discardAllDeletedTextureObjects(); + void flushDeletedTextureObjects(double currentTime, double& availableTime); + void releaseTextureObject(TextureObject* to); + + protected: + + typedef std::map< TextureProfile, osg::ref_ptr > TextureSetMap; + unsigned int _contextID; + unsigned int _texturePoolSize; + TextureSetMap _textureSetMap; + }; + + static osg::ref_ptr& getTextureObjectManager(unsigned int contextID); + + static TextureObject* generateTextureObject(const Texture* texture, unsigned int contextID,GLenum target); + + static TextureObject* generateTextureObject(const Texture* texture, + unsigned int contextID, GLenum target, GLint numMipmapLevels, GLenum internalFormat, @@ -922,9 +1088,10 @@ class OSG_EXPORT Texture : public osg::StateAttribute static void flushAllDeletedTextureObjects(unsigned int contextID); static void discardAllDeletedTextureObjects(unsigned int contextID); - + static void flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availableTime); + static void releaseTextureObject(unsigned int contextID, TextureObject* to); protected: diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index b3c3af803..d8f433ffb 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -80,6 +80,10 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs) _numHttpDatabaseThreadsHint = vs._numHttpDatabaseThreadsHint; _application = vs._application; + + _maxTexturePoolSize = vs._maxTexturePoolSize; + _maxVBOPoolSize = vs._maxVBOPoolSize; + _maxFBOPoolSize = vs._maxFBOPoolSize; } void DisplaySettings::merge(const DisplaySettings& vs) @@ -103,6 +107,10 @@ void DisplaySettings::merge(const DisplaySettings& vs) if (vs._numHttpDatabaseThreadsHint>_numHttpDatabaseThreadsHint) _numHttpDatabaseThreadsHint = vs._numHttpDatabaseThreadsHint; if (_application.empty()) _application = vs._application; + + if (vs._maxTexturePoolSize>_maxTexturePoolSize) _maxTexturePoolSize = vs._maxTexturePoolSize; + if (vs._maxVBOPoolSize>_maxVBOPoolSize) _maxVBOPoolSize = vs._maxVBOPoolSize; + if (vs._maxFBOPoolSize>_maxFBOPoolSize) _maxFBOPoolSize = vs._maxFBOPoolSize; } void DisplaySettings::setDefaults() @@ -147,6 +155,10 @@ void DisplaySettings::setDefaults() _numDatabaseThreadsHint = 2; _numHttpDatabaseThreadsHint = 1; + + _maxTexturePoolSize = 0; + _maxVBOPoolSize = 0; + _maxFBOPoolSize = 0; } void DisplaySettings::setMaxNumberOfGraphicsContexts(unsigned int num) @@ -186,6 +198,9 @@ static ApplicationUsageProxy DisplaySetting_e14(ApplicationUsage::ENVIRONMENTAL_ static ApplicationUsageProxy DisplaySetting_e15(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_NUM_DATABASE_THREADS ","Set the hint for the total number of threads to set up in the DatabasePager."); static ApplicationUsageProxy DisplaySetting_e16(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_NUM_HTTP_DATABASE_THREADS ","Set the hint for the total number of threads dedicated to http requests to set up in the DatabasePager."); static ApplicationUsageProxy DisplaySetting_e17(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MULTI_SAMPLES ","Set the hint for the number of samples to use when multi-sampling."); +static ApplicationUsageProxy DisplaySetting_e18(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_TEXTURE_POOL_SIZE ","Set the hint size of texture pool to manage."); +static ApplicationUsageProxy DisplaySetting_e19(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_VBO_POOL_SIZE ","Set the hint size of vertex buffer object pool to manage."); +static ApplicationUsageProxy DisplaySetting_e20(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_FBO_POOL_SIZE ","Set the hint size of frame buffer object pool to manage."); void DisplaySettings::readEnvironmentalVariables() { @@ -382,6 +397,21 @@ void DisplaySettings::readEnvironmentalVariables() { _numMultiSamples = atoi(ptr); } + + if( (ptr = getenv("OSG_TEXTURE_POOL_SIZE")) != 0) + { + _maxTexturePoolSize = atoi(ptr); + } + + if( (ptr = getenv("OSG_VBO_POOL_SIZE")) != 0) + { + _maxVBOPoolSize = atoi(ptr); + } + + if( (ptr = getenv("OSG_FBO_POOL_SIZE")) != 0) + { + _maxFBOPoolSize = atoi(ptr); + } } void DisplaySettings::readCommandLine(ArgumentParser& arguments) @@ -468,4 +498,12 @@ void DisplaySettings::readCommandLine(ArgumentParser& arguments) while(arguments.read("--num-db-threads",_numDatabaseThreadsHint)) {} while(arguments.read("--num-http-threads",_numHttpDatabaseThreadsHint)) {} + + while(arguments.read("--texture-pool-size",_maxTexturePoolSize)) {} + while(arguments.read("--vbo-pool-size",_maxVBOPoolSize)) {} + while(arguments.read("--fbo-pool-size",_maxFBOPoolSize)) {} + } + + + diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index b240f0c96..cabbc5031 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -496,12 +496,12 @@ void FrameBufferAttachment::createRequiredTexturesAndApplyGenerateMipMap(State & if (_ximpl->textureTarget.valid()) { tobj = _ximpl->textureTarget->getTextureObject(contextID); - if (!tobj || tobj->_id == 0) + if (!tobj || tobj->id() == 0) { _ximpl->textureTarget->compileGLObjects(state); tobj = _ximpl->textureTarget->getTextureObject(contextID); } - if (!tobj || tobj->_id == 0) + if (!tobj || tobj->id() == 0) return; Texture::FilterMode minFilter = _ximpl->textureTarget->getFilter(Texture::MIN_FILTER); @@ -526,13 +526,13 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen if (_ximpl->textureTarget.valid()) { tobj = _ximpl->textureTarget->getTextureObject(contextID); - if (!tobj || tobj->_id == 0) + if (!tobj || tobj->id() == 0) { _ximpl->textureTarget->compileGLObjects(state); tobj = _ximpl->textureTarget->getTextureObject(contextID); } - if (!tobj || tobj->_id == 0) + if (!tobj || tobj->id() == 0) return; } @@ -543,22 +543,22 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen ext->glFramebufferRenderbufferEXT(target, attachment_point, GL_RENDERBUFFER_EXT, _ximpl->renderbufferTarget->getObjectID(contextID, ext)); break; case Pimpl::TEXTURE1D: - ext->glFramebufferTexture1DEXT(target, attachment_point, GL_TEXTURE_1D, tobj->_id, _ximpl->level); + ext->glFramebufferTexture1DEXT(target, attachment_point, GL_TEXTURE_1D, tobj->id(), _ximpl->level); break; case Pimpl::TEXTURE2D: - ext->glFramebufferTexture2DEXT(target, attachment_point, GL_TEXTURE_2D, tobj->_id, _ximpl->level); + ext->glFramebufferTexture2DEXT(target, attachment_point, GL_TEXTURE_2D, tobj->id(), _ximpl->level); break; case Pimpl::TEXTURE3D: - ext->glFramebufferTexture3DEXT(target, attachment_point, GL_TEXTURE_3D, tobj->_id, _ximpl->level, _ximpl->zoffset); + ext->glFramebufferTexture3DEXT(target, attachment_point, GL_TEXTURE_3D, tobj->id(), _ximpl->level, _ximpl->zoffset); break; case Pimpl::TEXTURE2DARRAY: - ext->glFramebufferTextureLayerEXT(target, attachment_point, tobj->_id, _ximpl->level, _ximpl->zoffset); + ext->glFramebufferTextureLayerEXT(target, attachment_point, tobj->id(), _ximpl->level, _ximpl->zoffset); break; case Pimpl::TEXTURERECT: - ext->glFramebufferTexture2DEXT(target, attachment_point, GL_TEXTURE_RECTANGLE, tobj->_id, 0); + ext->glFramebufferTexture2DEXT(target, attachment_point, GL_TEXTURE_RECTANGLE, tobj->id(), 0); break; case Pimpl::TEXTURECUBE: - ext->glFramebufferTexture2DEXT(target, attachment_point, GL_TEXTURE_CUBE_MAP_POSITIVE_X + _ximpl->cubeMapFace, tobj->_id, _ximpl->level); + ext->glFramebufferTexture2DEXT(target, attachment_point, GL_TEXTURE_CUBE_MAP_POSITIVE_X + _ximpl->cubeMapFace, tobj->id(), _ximpl->level); break; } } diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 6188a80f1..f98eab98e 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -86,6 +86,10 @@ State::State(): _glMaxTextureCoords = 1; _glMaxTextureUnits = 1; + + _maxTexturePoolSize = 0; + _maxVBOPoolSize = 0; + _maxFBOPoolSize = 0; } State::~State() @@ -220,6 +224,24 @@ void State::setInitialViewMatrix(const osg::RefMatrix* matrix) _initialInverseViewMatrix.invert(*_initialViewMatrix); } +void State::setMaxTexturePoolSize(unsigned int size) +{ + _maxTexturePoolSize = size; + osg::notify(osg::NOTICE)<<"_maxTexturePoolSize="<<_maxTexturePoolSize< > BufferedExtensions; +static BufferedExtensions s_extensions; + +unsigned int s_minimumNumberOfTextureObjectsToRetainInCache = 0; + +void Texture::setMinimumNumberOfTextureObjectsToRetainInCache(unsigned int minimum) +{ + s_minimumNumberOfTextureObjectsToRetainInCache = minimum; +} + +unsigned int Texture::getMinimumNumberOfTextureObjectsToRetainInCache() +{ + return s_minimumNumberOfTextureObjectsToRetainInCache; +} + + +#define USE_NEW_TEXTURE_POOL 0 + +void Texture::TextureObject::bind() +{ + glBindTexture( _profile._target, _id); + if (_set) _set->moveToBack(this); +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// New texture object manager +// +Texture::TextureObjectSet::TextureObjectSet(TextureObjectManager* parent, const TextureProfile& profile): + _parent(parent), + _contextID(parent->getContextID()), + _profile(profile), + _numOfTextureObjects(0), + _head(0), + _tail(0) +{ +} + +Texture::TextureObjectSet::~TextureObjectSet() +{ +#if 0 + osg::notify(osg::NOTICE)<<"TextureObjectSet::~TextureObjectSet(), _numOfTextureObjects="<<_numOfTextureObjects<_next) + { + if ((to->_next)->_previous != to) + { + osg::notify(osg::NOTICE)<<"Error (to->_next)->_previous != to "<_next)->_previous != to "; + } + } + else + { + if (_tail != to) + { + osg::notify(osg::NOTICE)<<"Error _trail != to"<_next; + } + + unsigned int totalNumber = numInList + _orphanedTextureObjects.size(); + if (totalNumber != _numOfTextureObjects) + { + osg::notify(osg::NOTICE)<<"Error numInList + _orphanedTextureObjects.size() != _numOfTextureObjects"<get(); + + _orphanedTextureObjects.push_back(to); + + if (to->_previous!=0) + { + (to->_previous)->_next = to->_next; + } + else + { + // 'to' was head so assign _head to the next in list + _head = to->_next; + } + + if (to->_next!=0) + { + (to->_next)->_previous = to->_previous; + } + else + { + // 'to' was tail so assing tail to the previous in list + _tail = to->_previous; + } + + // reset the 'to' list pointers as it's no longer in the active list. + to->_next = 0; + to->_previous = 0; + +#if 0 + osg::notify(osg::NOTICE)<<" HPOTO after _head = "<<_head<_previous = "<_previous<_next = "<_next< lock(_mutex); + handlePendingOrphandedTextureObjects(); + } + + return; + + for(TextureObjectList::iterator itr = _orphanedTextureObjects.begin(); + itr != _orphanedTextureObjects.end(); + ++itr) + { + + GLuint id = (*itr)->id(); + + osg::notify(osg::NOTICE)<<"Deleting textureobject id="< lock(_mutex); + + if (!_pendingOrphanedTextureObjects.empty()) handlePendingOrphandedTextureObjects(); + + // see if we can recyle TextureObject from the orphane list + if (!_orphanedTextureObjects.empty()) + { + // take front of orphaned list. + ref_ptr to = _orphanedTextureObjects.front(); + + // remove from orphan list. + _orphanedTextureObjects.pop_front(); + + // assign to new texture + to->setTexture(texture); + + // place at back of active list + addToBack(to.get()); + + osg::notify(osg::NOTICE)<<"Reusing orhpahned TextureObject, _numOfTextureObjects="<<_numOfTextureObjects<getTexturePoolSize()!=0) && + (_numOfTextureObjects > _parent->getTexturePoolSize()) && + (_numOfTextureObjects>1) && + (_head != 0)) + { + ref_ptr to = _head; + + ref_ptr original_texture = to->getTexture(); + + if (original_texture.valid()) + { + original_texture->setTextureObject(_contextID,0); + osg::notify(osg::NOTICE)<<"Reusing an active TextureObject "<setTexture(texture); + + return to.release(); + + } + + + // + // no TextureObjects available to recyle so have to create one from scratch + // + GLuint id; + glGenTextures( 1L, &id ); + + TextureObject* to = new Texture::TextureObject(const_cast(texture),id,_profile); + to->_set = this; + ++_numOfTextureObjects; + + addToBack(to); + + osg::notify(osg::NOTICE)<<"Created new TextureObject, _numOfTextureObjects "<<_numOfTextureObjects<_previous = "<_previous<_next = "<_next<_next==0) + { + osg::notify(osg::NOTICE)<<"Error ***************** Should not get here either !!!!!!!!!"<_previous) + { + (to->_previous)->_next = to->_next; + } + else + { + // 'to' is the head, so moving it to the back will mean we need a new head + if (to->_next) + { + _head = to->_next; + } + } + + (to->_next)->_previous = to->_previous; + + _tail->_next = to; + + to->_previous = _tail; + to->_next = 0; + + _tail = to; + +#if 0 + osg::notify(osg::NOTICE)<<" m2B after _head = "<<_head<_previous = "<_previous<_next = "<_next<_previous = "<_previous<_next = "<_next<_previous !=0 || to->_next !=0) + { + moveToBack(to); + } + else + { + if (_tail) _tail->_next = to; + to->_previous = _tail; + + if (!_head) _head = to; + _tail = to; + } +#if 0 + osg::notify(osg::NOTICE)<<" a2B after _head = "<<_head<_previous = "<_previous<_next = "<_next< lock(_mutex); + + // disconnect from original texture + to->setTexture(0); + + // add orphan 'to' to the pending list of orphans, these will then be + // handled in the handlePendingOrphandedTextureObjects() where the TO's + // will be removed from the active list, and then placed in the orhpanTextureObject + // list. This double buffered approach to handling orphaned TO's is used + // to avoid having to mutex the process of appling active TO's. + _pendingOrphanedTextureObjects.push_back(to); + +#if 0 + osg::notify(osg::NOTICE)<<"TextureObjectSet::orphan("<& tos = _textureSetMap[profile]; + if (!tos) tos = new Texture::TextureObjectSet(this, profile); + return tos->takeOrGenerate(const_cast(texture)); +} + +void Texture::TextureObjectManager::handlePendingOrphandedTextureObjects() +{ + for(TextureSetMap::iterator itr = _textureSetMap.begin(); + itr != _textureSetMap.end(); + ++itr) + { + (*itr).second->handlePendingOrphandedTextureObjects(); + } +} + +void Texture::TextureObjectManager::flushAllDeletedTextureObjects() +{ + for(TextureSetMap::iterator itr = _textureSetMap.begin(); + itr != _textureSetMap.end(); + ++itr) + { + (*itr).second->flushAllDeletedTextureObjects(); + } +} + +void Texture::TextureObjectManager::discardAllDeletedTextureObjects() +{ + for(TextureSetMap::iterator itr = _textureSetMap.begin(); + itr != _textureSetMap.end(); + ++itr) + { + (*itr).second->discardAllDeletedTextureObjects(); + } +} + +void Texture::TextureObjectManager::flushDeletedTextureObjects(double currentTime, double& availableTime) +{ + for(TextureSetMap::iterator itr = _textureSetMap.begin(); + (itr != _textureSetMap.end()) && (availableTime > 0.0); + ++itr) + { + (*itr).second->flushDeletedTextureObjects(currentTime, availableTime); + } +} + +void Texture::TextureObjectManager::releaseTextureObject(Texture::TextureObject* to) +{ + if (to->_set) to->_set->orphan(to); + else osg::notify(osg::NOTICE)<<"TextureObjectManager::releaseTextureObject(Texture::TextureObject* to) Not implemented yet"<& Texture::getTextureObjectManager(unsigned int contextID) +{ + typedef osg::buffered_object< ref_ptr > TextureObjectManagerBuffer; + static TextureObjectManagerBuffer s_TextureObjectManager; + if (!s_TextureObjectManager[contextID]) s_TextureObjectManager[contextID] = new Texture::TextureObjectManager(contextID); + return s_TextureObjectManager[contextID]; +} + + +#if USE_NEW_TEXTURE_POOL + +Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, unsigned int contextID, GLenum target) +{ + return getTextureObjectManager(contextID)->generateTextureObject(texture, target); +} + +Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, unsigned int contextID, + GLenum target, + GLint numMipmapLevels, + GLenum internalFormat, + GLsizei width, + GLsizei height, + GLsizei depth, + GLint border) +{ + return getTextureObjectManager(contextID)->generateTextureObject(texture,target,numMipmapLevels,internalFormat,width,height,depth,border); +} + +void Texture::flushAllDeletedTextureObjects(unsigned int contextID) +{ + getTextureObjectManager(contextID)->flushAllDeletedTextureObjects(); +} + +void Texture::discardAllDeletedTextureObjects(unsigned int contextID) +{ + getTextureObjectManager(contextID)->discardAllDeletedTextureObjects(); +} + +void Texture::flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availbleTime) +{ + getTextureObjectManager(contextID)->flushDeletedTextureObjects(currentTime, availbleTime); +} + +void Texture::releaseTextureObject(unsigned int contextID, Texture::TextureObject* to) +{ + getTextureObjectManager(contextID)->releaseTextureObject(to); +} + +#else + +/////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Original texture object manager +// +class OriginalTextureObjectManager : public osg::Referenced { public: - TextureObjectManager(): + OriginalTextureObjectManager(): _expiryDelay(0.0) { - // printf("Constructing TextureObjectManager\n"); + // printf("Constructing OriginalTextureObjectManager\n"); } - ~TextureObjectManager() + ~OriginalTextureObjectManager() { - // printf("Destructing TextureObjectManager\n"); + // printf("Destructing OriginalTextureObjectManager\n"); } - virtual Texture::TextureObject* generateTextureObject(unsigned int contextID,GLenum target); + virtual Texture::TextureObject* generateTextureObject(Texture* texture, unsigned int contextID,GLenum target); - virtual Texture::TextureObject* generateTextureObject(unsigned int contextID, + virtual Texture::TextureObject* generateTextureObject(Texture* texture, unsigned int contextID, GLenum target, GLint numMipmapLevels, GLenum internalFormat, @@ -80,7 +592,7 @@ public: GLsizei depth, GLint border); - virtual Texture::TextureObject* reuseTextureObject(unsigned int contextID, + virtual Texture::TextureObject* reuseTextureObject(Texture* texture, unsigned int contextID, GLenum target, GLint numMipmapLevels, GLenum internalFormat, @@ -89,7 +601,7 @@ public: GLsizei depth, GLint border); - inline Texture::TextureObject* reuseOrGenerateTextureObject(unsigned int contextID, + inline Texture::TextureObject* reuseOrGenerateTextureObject(Texture* texture, unsigned int contextID, GLenum target, GLint numMipmapLevels, GLenum internalFormat, @@ -98,15 +610,11 @@ public: GLsizei depth, GLint border) { - Texture::TextureObject* to = reuseTextureObject(contextID,target,numMipmapLevels,internalFormat,width,height,depth,border); + Texture::TextureObject* to = reuseTextureObject(texture, contextID,target,numMipmapLevels,internalFormat,width,height,depth,border); if (to) return to; - else return generateTextureObject(contextID,target,numMipmapLevels,internalFormat,width,height,depth,border); + else return generateTextureObject(texture, contextID,target,numMipmapLevels,internalFormat,width,height,depth,border); } - void addTextureObjects(Texture::TextureObjectListMap& toblm); - - void addTextureObjectsFrom(Texture& texture); - void flushAllTextureObjects(unsigned int contextID); void discardAllTextureObjects(unsigned int contextID); @@ -120,46 +628,32 @@ public: /** How long to keep unused texture objects before deletion. */ double _expiryDelay; - Texture::TextureObjectListMap _textureObjectListMap; + typedef osg::buffered_object TextureObjectListMap; + TextureObjectListMap _textureObjectListMap; // mutex to keep access serialized. OpenThreads::Mutex _mutex; }; -} - unsigned int Texture::s_numberTextureReusedLastInLastFrame = 0; unsigned int Texture::s_numberNewTextureInLastFrame = 0; unsigned int Texture::s_numberDeletedTextureInLastFrame = 0; -unsigned int s_minimumNumberOfTextureObjectsToRetainInCache = 0; -typedef buffered_value< ref_ptr > BufferedExtensions; -static BufferedExtensions s_extensions; +static ref_ptr s_textureObjectManager = new OriginalTextureObjectManager; -static ref_ptr s_textureObjectManager = new TextureObjectManager; -void Texture::setMinimumNumberOfTextureObjectsToRetainInCache(unsigned int minimum) -{ - s_minimumNumberOfTextureObjectsToRetainInCache = minimum; -} - -unsigned int Texture::getMinimumNumberOfTextureObjectsToRetainInCache() -{ - return s_minimumNumberOfTextureObjectsToRetainInCache; -} - -Texture::TextureObject* TextureObjectManager::generateTextureObject(unsigned int /*contextID*/,GLenum target) +Texture::TextureObject* OriginalTextureObjectManager::generateTextureObject(Texture* texture, unsigned int /*contextID*/,GLenum target) { GLuint id; glGenTextures( 1L, &id ); - return new Texture::TextureObject(id,target); + return new Texture::TextureObject(texture, id,target); } static int s_number = 0; -Texture::TextureObject* TextureObjectManager::generateTextureObject(unsigned int /*contextID*/, +Texture::TextureObject* OriginalTextureObjectManager::generateTextureObject(Texture* texture, unsigned int /*contextID*/, GLenum target, GLint numMipmapLevels, GLenum internalFormat, @@ -176,10 +670,10 @@ Texture::TextureObject* TextureObjectManager::generateTextureObject(unsigned int GLuint id; glGenTextures( 1L, &id ); - return new Texture::TextureObject(id,target,numMipmapLevels,internalFormat,width,height,depth,border); + return new Texture::TextureObject(texture, id,target,numMipmapLevels,internalFormat,width,height,depth,border); } -Texture::TextureObject* TextureObjectManager::reuseTextureObject(unsigned int contextID, +Texture::TextureObject* OriginalTextureObjectManager::reuseTextureObject(Texture* texture, unsigned int contextID, GLenum target, GLint numMipmapLevels, GLenum internalFormat, @@ -205,6 +699,8 @@ Texture::TextureObject* TextureObjectManager::reuseTextureObject(unsigned int co ++Texture::s_numberTextureReusedLastInLastFrame; + textureObject->setTexture(texture); + return textureObject; } } @@ -212,27 +708,7 @@ Texture::TextureObject* TextureObjectManager::reuseTextureObject(unsigned int co return 0; } - - -void TextureObjectManager::addTextureObjects(Texture::TextureObjectListMap& toblm) -{ - OpenThreads::ScopedLock lock(_mutex); - - for(unsigned int i=0; i< toblm.size(); ++i) - { - Texture::TextureObjectList& tol = _textureObjectListMap[i]; - tol.insert(tol.end(),toblm[i].begin(),toblm[i].end()); - } -} - -void TextureObjectManager::addTextureObjectsFrom(Texture& texture) -{ - OpenThreads::ScopedLock lock(_mutex); - - texture.takeTextureObjects(_textureObjectListMap); -} - -void TextureObjectManager::flushAllTextureObjects(unsigned int contextID) +void OriginalTextureObjectManager::flushAllTextureObjects(unsigned int contextID) { OpenThreads::ScopedLock lock(_mutex); @@ -245,12 +721,13 @@ void TextureObjectManager::flushAllTextureObjects(unsigned int contextID) ++itr) { // osg::notify(osg::NOTICE)<<" deleting texture object "<<(*itr)->_id<_id)); + GLuint id = (*itr)->id(); + glDeleteTextures( 1L, &id); } tol.clear(); } -void TextureObjectManager::discardAllTextureObjects(unsigned int contextID) +void OriginalTextureObjectManager::discardAllTextureObjects(unsigned int contextID) { OpenThreads::ScopedLock lock(_mutex); @@ -258,7 +735,7 @@ void TextureObjectManager::discardAllTextureObjects(unsigned int contextID) tol.clear(); } -void TextureObjectManager::flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime) +void OriginalTextureObjectManager::flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime) { // if no time available don't try to flush objects. if (availableTime<=0.0) return; @@ -282,7 +759,7 @@ void TextureObjectManager::flushTextureObjects(unsigned int contextID,double cur itr!=tol.end(); ++itr) { - if ((*itr)->_timeStamp==0.0) (*itr)->_timeStamp=currentTime; + if ((*itr)->getTimeStamp()==0.0) (*itr)->setTimeStamp(currentTime); } double expiryTime = currentTime-_expiryDelay; @@ -291,12 +768,13 @@ void TextureObjectManager::flushTextureObjects(unsigned int contextID,double cur itr!=tol.end() && elapsedTimes_minimumNumberOfTextureObjectsToRetainInCache && numObjectsDeleted_timeStamp<=expiryTime) + if ((*itr)->getTimeStamp()<=expiryTime) { --s_number; ++Texture::s_numberDeletedTextureInLastFrame; - glDeleteTextures( 1L, &((*itr)->_id)); + GLuint id = (*itr)->id(); + glDeleteTextures( 1L, &id); itr = tol.erase(itr); ++numTexturesDeleted; ++numObjectsDeleted; @@ -315,19 +793,19 @@ void TextureObjectManager::flushTextureObjects(unsigned int contextID,double cur } -static TextureObjectManager* getTextureObjectManager() +static OriginalTextureObjectManager* getOriginalTextureObjectManager() { return s_textureObjectManager.get(); } -Texture::TextureObject* Texture::generateTextureObject(unsigned int contextID,GLenum target) +Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, unsigned int contextID,GLenum target) { - if (getTextureObjectManager()) return getTextureObjectManager()->generateTextureObject(contextID,target); + if (getOriginalTextureObjectManager()) return getOriginalTextureObjectManager()->generateTextureObject(const_cast(texture),contextID,target); else return 0; } -Texture::TextureObject* Texture::generateTextureObject(unsigned int contextID, +Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, unsigned int contextID, GLenum target, GLint numMipmapLevels, GLenum internalFormat, @@ -336,8 +814,9 @@ Texture::TextureObject* Texture::generateTextureObject(unsigned int contextID, GLsizei depth, GLint border) { - if (getTextureObjectManager()) - return getTextureObjectManager()->reuseOrGenerateTextureObject(contextID, + if (getOriginalTextureObjectManager()) + return getOriginalTextureObjectManager()->reuseOrGenerateTextureObject(const_cast(texture), + contextID, target, numMipmapLevels, internalFormat, @@ -351,19 +830,32 @@ Texture::TextureObject* Texture::generateTextureObject(unsigned int contextID, void Texture::flushAllDeletedTextureObjects(unsigned int contextID) { - if (getTextureObjectManager()) getTextureObjectManager()->flushAllTextureObjects(contextID); + if (getOriginalTextureObjectManager()) getOriginalTextureObjectManager()->flushAllTextureObjects(contextID); } void Texture::discardAllDeletedTextureObjects(unsigned int contextID) { - if (getTextureObjectManager()) getTextureObjectManager()->discardAllTextureObjects(contextID); + if (getOriginalTextureObjectManager()) getOriginalTextureObjectManager()->discardAllTextureObjects(contextID); } void Texture::flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availbleTime) { - if (getTextureObjectManager()) getTextureObjectManager()->flushTextureObjects(contextID, currentTime, availbleTime); + if (getOriginalTextureObjectManager()) getOriginalTextureObjectManager()->flushTextureObjects(contextID, currentTime, availbleTime); } +void Texture::releaseTextureObject(unsigned int contextID, Texture::TextureObject* to) +{ + if (getOriginalTextureObjectManager()) + { + OpenThreads::ScopedLock lock(getOriginalTextureObjectManager()->_mutex); + getOriginalTextureObjectManager()->_textureObjectListMap[contextID].push_back(to); + } +} + +#endif + + + Texture::Texture(): _wrap_s(CLAMP), _wrap_t(CLAMP), @@ -526,20 +1018,14 @@ void Texture::setMaxAnisotropy(float anis) /** Force a recompile on next apply() of associated OpenGL texture objects.*/ void Texture::dirtyTextureObject() { - if (getTextureObjectManager()) getTextureObjectManager()->addTextureObjectsFrom(*this); -} - -void Texture::takeTextureObjects(Texture::TextureObjectListMap& toblm) -{ - for(unsigned int i = 0; i<_textureObjectBuffer.size();++i) + for(unsigned int i=0; i<_textureObjectBuffer.size();++i) { - if (_textureObjectBuffer[i].valid()) + if (_textureObjectBuffer[i].valid()) { - //notify(INFO) << "releasing texture "<glGenerateMipmapEXT(textureObject->_target); + fbo_ext->glGenerateMipmapEXT(textureObject->target()); } } break; @@ -1520,7 +2006,7 @@ void Texture::generateMipmap(State& state) const if (fbo_ext->glGenerateMipmapEXT) { textureObject->bind(); - fbo_ext->glGenerateMipmapEXT(textureObject->_target); + fbo_ext->glGenerateMipmapEXT(textureObject->target()); // inform state that this texture is the current one bound. state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this); @@ -1533,14 +2019,6 @@ void Texture::generateMipmap(State& state) const } - -/////////////////////////////////////////////////////////////////////////////////////////////// -// Static map to manage the deletion of texture objects are the right time. -////////////////////////////////////////////////////////////////////////////////////////////// -#include -#include - - void Texture::compileGLObjects(State& state) const { apply(state); @@ -1560,11 +2038,10 @@ void Texture::releaseGLObjects(State* state) const else { unsigned int contextID = state->getContextID(); - if (_textureObjectBuffer[contextID].valid() && getTextureObjectManager()) + if (_textureObjectBuffer[contextID].valid()) { - OpenThreads::ScopedLock lock(getTextureObjectManager()->_mutex); - - getTextureObjectManager()->_textureObjectListMap[contextID].push_back(_textureObjectBuffer[contextID]); + Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get()); + _textureObjectBuffer[contextID] = 0; } } @@ -1800,3 +2277,4 @@ void Texture::Extensions::glGetCompressedTexImage(GLenum target, GLint level, GL } } +} \ No newline at end of file diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index fd5172f7f..0d6796ce9 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -150,7 +150,7 @@ void Texture1D::apply(State& state) const { // we don't have a applyTexImage1D_subload yet so can't reuse.. so just generate a new texture object. - _textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID,GL_TEXTURE_1D); + _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID, GL_TEXTURE_1D); textureObject->bind(); @@ -171,7 +171,7 @@ void Texture1D::apply(State& state) const { // we don't have a applyTexImage1D_subload yet so can't reuse.. so just generate a new texture object. - textureObject = generateTextureObject(contextID,GL_TEXTURE_1D); + textureObject = generateTextureObject(this, contextID,GL_TEXTURE_1D); textureObject->bind(); @@ -196,7 +196,7 @@ void Texture1D::apply(State& state) const else if ( (_textureWidth!=0) && (_internalFormat!=0) ) { _textureObjectBuffer[contextID] = textureObject = generateTextureObject( - contextID,GL_TEXTURE_1D,_numMipmapLevels,_internalFormat,_textureWidth,1,1,0); + this,contextID,GL_TEXTURE_1D,_numMipmapLevels,_internalFormat,_textureWidth,1,1,0); textureObject->bind(); @@ -378,7 +378,7 @@ void Texture1D::copyTexImage1D(State& state, int x, int y, int width) _min_filter = LINEAR; _mag_filter = LINEAR; - _textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID,GL_TEXTURE_1D); + _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_1D); textureObject->bind(); diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp index b8ebe846c..cbd9ea4f4 100644 --- a/src/osg/Texture2D.cpp +++ b/src/osg/Texture2D.cpp @@ -169,7 +169,7 @@ void Texture2D::apply(State& state) const else if (_subloadCallback.valid()) { - _textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID,GL_TEXTURE_2D); + _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_2D); textureObject->bind(); @@ -199,7 +199,7 @@ void Texture2D::apply(State& state) const computeRequiredTextureDimensions(state,*image,_textureWidth, _textureHeight, _numMipmapLevels); _textureObjectBuffer[contextID] = textureObject = generateTextureObject( - contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); + this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); textureObject->bind(); @@ -223,7 +223,10 @@ void Texture2D::apply(State& state) const // update the modified tag to show that it is upto date. getModifiedCount(contextID) = image->getModifiedCount(); - if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && image->getDataVariance()==STATIC) + if (state.getMaxTexturePoolSize()==0 && + _unrefImageDataAfterApply && + areAllTextureObjectsLoaded() && + image->getDataVariance()==STATIC) { Texture2D* non_const_this = const_cast(this); non_const_this->_image = 0; @@ -239,7 +242,7 @@ void Texture2D::apply(State& state) const else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) ) { _textureObjectBuffer[contextID] = textureObject = generateTextureObject( - contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); + this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); textureObject->bind(); @@ -312,7 +315,7 @@ void Texture2D::copyTexImage2D(State& state, int x, int y, int width, int height // switch off mip-mapping. // - _textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID,GL_TEXTURE_2D); + _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_2D); textureObject->bind(); diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index 0b65eb922..fad8e58fb 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -256,7 +256,7 @@ void Texture2DArray::apply(State& state) const else if (_subloadCallback.valid()) { // generate texture (i.e. glGenTexture) and apply parameters - _textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID, GL_TEXTURE_2D_ARRAY_EXT); + _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID, GL_TEXTURE_2D_ARRAY_EXT); textureObject->bind(); applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT, state); _subloadCallback->load(*this,state); @@ -275,7 +275,7 @@ void Texture2DArray::apply(State& state) const // create texture object textureObject = generateTextureObject( - contextID,GL_TEXTURE_2D_ARRAY_EXT,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0); + this, contextID,GL_TEXTURE_2D_ARRAY_EXT,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0); // bind texture textureObject->bind(); @@ -325,7 +325,7 @@ void Texture2DArray::apply(State& state) const { // generate texture _textureObjectBuffer[contextID] = textureObject = generateTextureObject( - contextID, GL_TEXTURE_2D_ARRAY_EXT,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0); + this, contextID, GL_TEXTURE_2D_ARRAY_EXT,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0); textureObject->bind(); applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state); diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 1a0ff6ace..3cab25ed2 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -232,7 +232,7 @@ void Texture3D::apply(State& state) const else if (_subloadCallback.valid()) { - _textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID,GL_TEXTURE_3D); + _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_3D); textureObject->bind(); @@ -258,7 +258,7 @@ void Texture3D::apply(State& state) const // compute the dimensions of the texture. computeRequiredTextureDimensions(state,*_image,_textureWidth, _textureHeight, _textureDepth,_numMipmapLevels); - textureObject = generateTextureObject(contextID,GL_TEXTURE_3D); + textureObject = generateTextureObject(this, contextID,GL_TEXTURE_3D); textureObject->bind(); @@ -284,7 +284,7 @@ void Texture3D::apply(State& state) const else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_textureDepth!=0) && (_internalFormat!=0) ) { _textureObjectBuffer[contextID] = textureObject = generateTextureObject( - contextID,GL_TEXTURE_3D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0); + this, contextID,GL_TEXTURE_3D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0); textureObject->bind(); diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp index d21cce242..548ca4f0a 100644 --- a/src/osg/TextureCubeMap.cpp +++ b/src/osg/TextureCubeMap.cpp @@ -230,7 +230,7 @@ void TextureCubeMap::apply(State& state) const } else if (_subloadCallback.valid()) { - _textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID,GL_TEXTURE_CUBE_MAP); + _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_CUBE_MAP); textureObject->bind(); @@ -261,7 +261,7 @@ void TextureCubeMap::apply(State& state) const } textureObject = generateTextureObject( - contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); + this, contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); textureObject->bind(); @@ -304,7 +304,7 @@ void TextureCubeMap::apply(State& state) const else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) ) { _textureObjectBuffer[contextID] = textureObject = generateTextureObject( - contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); + this, contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); textureObject->bind(); diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index 67410a1d4..dc791c87d 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -190,7 +190,7 @@ void TextureRectangle::apply(State& state) const else if (_subloadCallback.valid()) { // we don't have a applyTexImage1D_subload yet so can't reuse.. so just generate a new texture object. - _textureObjectBuffer[contextID] = textureObject = generateTextureObject(contextID,GL_TEXTURE_RECTANGLE); + _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_RECTANGLE); textureObject->bind(); @@ -212,7 +212,7 @@ void TextureRectangle::apply(State& state) const OpenThreads::ScopedLock lock(s_mutex); // we don't have a applyTexImage1D_subload yet so can't reuse.. so just generate a new texture object. - textureObject = generateTextureObject(contextID,GL_TEXTURE_RECTANGLE); + textureObject = generateTextureObject(this, contextID,GL_TEXTURE_RECTANGLE); textureObject->bind(); @@ -235,7 +235,7 @@ void TextureRectangle::apply(State& state) const else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) ) { _textureObjectBuffer[contextID] = textureObject = generateTextureObject( - contextID,GL_TEXTURE_RECTANGLE,0,_internalFormat,_textureWidth,_textureHeight,1,0); + this, contextID,GL_TEXTURE_RECTANGLE,0,_internalFormat,_textureWidth,_textureHeight,1,0); textureObject->bind(); @@ -460,8 +460,7 @@ void TextureRectangle::copyTexImage2D(State& state, int x, int y, int width, int // switch off mip-mapping. // - _textureObjectBuffer[contextID] = textureObject = - generateTextureObject(contextID,GL_TEXTURE_RECTANGLE); + _textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_RECTANGLE); textureObject->bind(); diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 8e9ae4b3d..f841933fe 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -590,7 +590,7 @@ void Font::GlyphTexture::apply(osg::State& state) const // being bound for the first time, need to allocate the texture _textureObjectBuffer[contextID] = textureObject = osg::Texture::generateTextureObject( - contextID,GL_TEXTURE_2D,1,GL_ALPHA,getTextureWidth(), getTextureHeight(),1,0); + this, contextID,GL_TEXTURE_2D,1,GL_ALPHA,getTextureWidth(), getTextureHeight(),1,0); textureObject->bind(); diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index b492f06ed..5499177e0 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -834,7 +834,8 @@ void SceneView::cull() } } - + + } bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage, osg::Viewport *viewport) @@ -845,6 +846,12 @@ bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod osg::ref_ptr proj = new osg::RefMatrix(projection); osg::ref_ptr mv = new osg::RefMatrix(modelview); + osg::State* state = _renderInfo.getState(); + if (state->getMaxTexturePoolSize()!=0) + { + osg::Texture::getTextureObjectManager(state->getContextID())->setTexturePoolSize(state->getMaxTexturePoolSize()); + } + // collect any occluder in the view frustum. if (_camera->containsOccluderNodes()) diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index 5d3db92fd..33dfb6c38 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -1,13 +1,13 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ @@ -84,10 +84,10 @@ void CompositeViewer::constructorInit() _frameStamp->setFrameNumber(0); _frameStamp->setReferenceTime(0); _frameStamp->setSimulationTime(0); - + _eventVisitor = new osgGA::EventVisitor; _eventVisitor->setFrameStamp(_frameStamp.get()); - + _updateVisitor = new osgUtil::UpdateVisitor; _updateVisitor->setFrameStamp(_frameStamp.get()); @@ -99,10 +99,10 @@ CompositeViewer::~CompositeViewer() osg::notify(osg::INFO)<<"CompositeViewer::~CompositeViewer()"<_viewerBase = this; - + if (view->getSceneData()) - { + { // make sure that existing scene graph objects are allocated with thread safe ref/unref - if (getThreadingModel()!=ViewerBase::SingleThreaded) + if (getThreadingModel()!=ViewerBase::SingleThreaded) { view->getSceneData()->setThreadSafeRefUnref(true); } - + // update the scene graph so that it has enough GL object buffer memory for the graphics contexts that will be using it. view->getSceneData()->resizeGLObjectBuffers(osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts()); } view->setFrameStamp(_frameStamp.get()); - + if (alreadyRealized) { Contexts contexts; @@ -196,7 +196,7 @@ void CompositeViewer::addView(osgViewer::View* view) } } - + if (threadsWereRunning) startThreading(); } @@ -236,7 +236,7 @@ bool CompositeViewer::isRealized() const { if ((*citr)->isRealized()) ++numRealizedWindows; } - + return numRealizedWindows > 0; } @@ -280,7 +280,7 @@ int CompositeViewer::run() view->setCameraManipulator(new osgGA::TrackballManipulator()); } } - + setReleaseContextAtEndOfFrameHint(false); return ViewerBase::run(); @@ -289,14 +289,14 @@ int CompositeViewer::run() void CompositeViewer::setStartTick(osg::Timer_t tick) { _startTick = tick; - + for(RefViews::iterator vitr = _views.begin(); vitr != _views.end(); ++vitr) { (*vitr)->setStartTick(tick); } - + Contexts contexts; getContexts(contexts,false); @@ -380,14 +380,14 @@ void CompositeViewer::getContexts(Contexts& contexts, bool onlyValid) void CompositeViewer::getCameras(Cameras& cameras, bool onlyActive) { cameras.clear(); - + for(RefViews::iterator vitr = _views.begin(); vitr != _views.end(); ++vitr) { View* view = vitr->get(); - if (view->getCamera() && + if (view->getCamera() && (!onlyActive || (view->getCamera()->getGraphicsContext() && view->getCamera()->getGraphicsContext()->valid())) ) cameras.push_back(view->getCamera()); for(View::Slaves::iterator itr = view->_slaves.begin(); @@ -399,7 +399,7 @@ void CompositeViewer::getCameras(Cameras& cameras, bool onlyActive) } } } - + void CompositeViewer::getScenes(Scenes& scenes, bool onlyValid) { scenes.clear(); @@ -441,7 +441,7 @@ void CompositeViewer::getAllThreads(Threads& threads, bool onlyActive) OperationThreads operationThreads; getOperationThreads(operationThreads); - + for(OperationThreads::iterator itr = operationThreads.begin(); itr != operationThreads.end(); ++itr) @@ -451,7 +451,7 @@ void CompositeViewer::getAllThreads(Threads& threads, bool onlyActive) Scenes scenes; getScenes(scenes); - + for(Scenes::iterator sitr = scenes.begin(); sitr != scenes.end(); ++sitr) @@ -476,7 +476,7 @@ void CompositeViewer::getAllThreads(Threads& threads, bool onlyActive) void CompositeViewer::getOperationThreads(OperationThreads& threads, bool onlyActive) { threads.clear(); - + Contexts contexts; getContexts(contexts); for(Contexts::iterator gcitr = contexts.begin(); @@ -484,13 +484,13 @@ void CompositeViewer::getOperationThreads(OperationThreads& threads, bool onlyAc ++gcitr) { osg::GraphicsContext* gc = *gcitr; - if (gc->getGraphicsThread() && + if (gc->getGraphicsThread() && (!onlyActive || gc->getGraphicsThread()->isRunning()) ) { threads.push_back(gc->getGraphicsThread()); } } - + Cameras cameras; getCameras(cameras); for(Cameras::iterator citr = cameras.begin(); @@ -498,19 +498,19 @@ void CompositeViewer::getOperationThreads(OperationThreads& threads, bool onlyAc ++citr) { osg::Camera* camera = *citr; - if (camera->getCameraThread() && + if (camera->getCameraThread() && (!onlyActive || camera->getCameraThread()->isRunning()) ) { threads.push_back(camera->getCameraThread()); } } - + } void CompositeViewer::realize() { //osg::notify(osg::INFO)<<"CompositeViewer::realize()"<setUpViewAcrossAllScreens(); - + getContexts(contexts); } @@ -539,24 +539,34 @@ void CompositeViewer::realize() _done = true; return; } - + + unsigned int maxTexturePoolSize = osg::DisplaySettings::instance()->getMaxTexturePoolSize(); + unsigned int maxVBOPoolSize = osg::DisplaySettings::instance()->getMaxVBOPoolSize(); + unsigned int maxFBOPoolSize = osg::DisplaySettings::instance()->getMaxFBOPoolSize(); + for(Contexts::iterator citr = contexts.begin(); citr != contexts.end(); ++citr) { osg::GraphicsContext* gc = *citr; + + // set the pool sizes, 0 the default will result in no GL object pools. + gc->getState()->setMaxTexturePoolSize(maxTexturePoolSize); + gc->getState()->setMaxVBOPoolSize(maxVBOPoolSize); + gc->getState()->setMaxFBOPoolSize(maxFBOPoolSize); + gc->realize(); - - if (_realizeOperation.valid() && gc->valid()) + + if (_realizeOperation.valid() && gc->valid()) { gc->makeCurrent(); - + (*_realizeOperation)(gc); - + gc->releaseContext(); } } - + // attach contexts to _incrementalCompileOperation if attached. if (_incrementalCompileOperation) _incrementalCompileOperation->assignContexts(contexts); @@ -571,12 +581,12 @@ void CompositeViewer::realize() osgViewer::GraphicsWindow* gw = dynamic_cast(*citr); if (gw) { - gw->grabFocusIfPointerInWindow(); + gw->grabFocusIfPointerInWindow(); } } } - - + + startThreading(); // initialize the global timer to be relative to the current time. @@ -599,7 +609,7 @@ void CompositeViewer::realize() gc->createGraphicsThread(); gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors); gc->getGraphicsThread()->startThread(); - + ++processNum; } } @@ -610,7 +620,7 @@ void CompositeViewer::realize() void CompositeViewer::advance(double simulationTime) { if (_done) return; - + double prevousReferenceTime = _frameStamp->getReferenceTime(); int previousFrameNumber = _frameStamp->getFrameNumber(); @@ -627,7 +637,7 @@ void CompositeViewer::advance(double simulationTime) { _frameStamp->setSimulationTime(simulationTime); } - + if (getViewerStats() && getViewerStats()->collectStats("frame_rate")) { // update previous frame stats @@ -652,7 +662,7 @@ void CompositeViewer::setCameraWithFocus(osg::Camera* camera) ++vitr) { View* view = vitr->get(); - if (view->containsCamera(camera)) + if (view->containsCamera(camera)) { _viewWithFocus = view; return; @@ -666,18 +676,18 @@ void CompositeViewer::setCameraWithFocus(osg::Camera* camera) void CompositeViewer::eventTraversal() { if (_done) return; - + if (_views.empty()) return; - + double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); // osg::notify(osg::NOTICE)<<"CompositeViewer::frameEventTraversal()."< ViewEventsMap; ViewEventsMap viewEventsMap; - + Contexts contexts; getContexts(contexts); @@ -685,11 +695,11 @@ void CompositeViewer::eventTraversal() getScenes(scenes); osgViewer::View* masterView = getViewWithFocus() ? getViewWithFocus() : _views[0].get(); - + osg::Camera* masterCamera = masterView->getCamera(); - osgGA::GUIEventAdapter* eventState = masterView->getEventQueue()->getCurrentEventState(); + osgGA::GUIEventAdapter* eventState = masterView->getEventQueue()->getCurrentEventState(); osg::Matrix masterCameraVPW = masterCamera->getViewMatrix() * masterCamera->getProjectionMatrix(); - if (masterCamera->getViewport()) + if (masterCamera->getViewport()) { osg::Viewport* viewport = masterCamera->getViewport(); masterCameraVPW *= viewport->computeWindowMatrix(); @@ -703,27 +713,27 @@ void CompositeViewer::eventTraversal() if (gw) { gw->checkEvents(); - + osgGA::EventQueue::Events gw_events; gw->getEventQueue()->takeEvents(gw_events); - + osgGA::EventQueue::Events::iterator itr; for(itr = gw_events.begin(); itr != gw_events.end(); ++itr) { osgGA::GUIEventAdapter* event = itr->get(); - + //osg::notify(osg::NOTICE)<<"event->getGraphicsContext()="<getGraphicsContext()<getX(); float y = event->getY(); - + bool invert_y = event->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS; if (invert_y && gw->getTraits()) y = gw->getTraits()->height - y; - + switch(event->getEventType()) { case(osgGA::GUIEventAdapter::RESIZE): @@ -735,7 +745,7 @@ void CompositeViewer::eventTraversal() case(osgGA::GUIEventAdapter::MOVE): { pointerEvent = true; - + if (event->getEventType()!=osgGA::GUIEventAdapter::DRAG || !getCameraWithFocus()) { osg::GraphicsContext::Cameras& cameras = gw->getCameras(); @@ -744,12 +754,12 @@ void CompositeViewer::eventTraversal() ++citr) { osg::Camera* camera = *citr; - if (camera->getView() && + if (camera->getView() && camera->getAllowEventFocus() && camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER) { osg::Viewport* viewport = camera ? camera->getViewport() : 0; - if (viewport && + if (viewport && x >= viewport->x() && y >= viewport->y() && x <= (viewport->x()+viewport->width()) && y <= (viewport->y()+viewport->height()) ) { @@ -759,9 +769,9 @@ void CompositeViewer::eventTraversal() if (camera->getView()->getCamera() == camera) { eventState->setGraphicsContext(gw); - eventState->setInputRange( viewport->x(), viewport->y(), - viewport->x()+viewport->width(), - viewport->y()+viewport->height()); + eventState->setInputRange( viewport->x(), viewport->y(), + viewport->x()+viewport->width(), + viewport->y()+viewport->height()); } else @@ -774,10 +784,10 @@ void CompositeViewer::eventTraversal() // need to reset the masterView masterView = getViewWithFocus(); masterCamera = masterView->getCamera(); - eventState = masterView->getEventQueue()->getCurrentEventState(); + eventState = masterView->getEventQueue()->getCurrentEventState(); masterCameraVPW = masterCamera->getViewMatrix() * masterCamera->getProjectionMatrix(); - if (masterCamera->getViewport()) + if (masterCamera->getViewport()) { osg::Viewport* viewport = masterCamera->getViewport(); masterCameraVPW *= viewport->computeWindowMatrix(); @@ -788,9 +798,9 @@ void CompositeViewer::eventTraversal() if (camera->getView()->getCamera() == camera) { eventState->setGraphicsContext(gw); - eventState->setInputRange( viewport->x(), viewport->y(), - viewport->x()+viewport->width(), - viewport->y()+viewport->height()); + eventState->setInputRange( viewport->x(), viewport->y(), + viewport->x()+viewport->width(), + viewport->y()+viewport->height()); } else @@ -801,13 +811,13 @@ void CompositeViewer::eventTraversal() } } } - + break; } default: break; } - + if (pointerEvent) { if (getCameraWithFocus()) @@ -821,7 +831,7 @@ void CompositeViewer::eventTraversal() osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix; x = new_coord.x(); - y = new_coord.y(); + y = new_coord.y(); event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax()); event->setX(x); @@ -829,7 +839,7 @@ void CompositeViewer::eventTraversal() event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS); } - // pass along the new pointer events details to the eventState of the viewer + // pass along the new pointer events details to the eventState of the viewer eventState->setX(x); eventState->setY(y); eventState->setButtonMask(event->getButtonMask()); @@ -857,7 +867,7 @@ void CompositeViewer::eventTraversal() { bool wasThreading = areThreadsRunning(); if (wasThreading) stopThreading(); - + gw->close(); if (wasThreading) startThreading(); @@ -873,7 +883,7 @@ void CompositeViewer::eventTraversal() } } - + // osg::notify(osg::NOTICE)<<"mouseEventState Xmin = "<getXmin()<<" Ymin="<getYmin()<<" xMax="<getXmax()<<" Ymax="<getYmax()<getEventQueue()->frame( getFrameStamp()->getReferenceTime() ); view->getEventQueue()->takeEvents(viewEventsMap[view]); } - + // osg::notify(osg::NOTICE)<<"Events "<first; _eventVisitor->setActionAdapter(view); - + if (view->getSceneData()) - { + { for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); itr != veitr->second.end(); ++itr) @@ -963,7 +973,7 @@ void CompositeViewer::eventTraversal() } } } - + } for(ViewEventsMap::iterator veitr = viewEventsMap.begin(); @@ -971,7 +981,7 @@ void CompositeViewer::eventTraversal() ++veitr) { View* view = veitr->first; - + for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); itr != veitr->second.end(); ++itr) @@ -992,7 +1002,7 @@ void CompositeViewer::eventTraversal() ++veitr) { View* view = veitr->first; - + for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin(); itr != veitr->second.end(); ++itr) @@ -1006,7 +1016,7 @@ void CompositeViewer::eventTraversal() } } - + if (getViewerStats() && getViewerStats()->collectStats("event")) { @@ -1023,7 +1033,7 @@ void CompositeViewer::eventTraversal() void CompositeViewer::updateTraversal() { if (_done) return; - + double beginUpdateTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); _updateVisitor->reset(); @@ -1084,17 +1094,17 @@ void CompositeViewer::updateTraversal() } - if (view->getCameraManipulator()) + if (view->getCameraManipulator()) { view->setFusionDistance( view->getCameraManipulator()->getFusionDistanceMode(), - view->getCameraManipulator()->getFusionDistanceValue() ); - + view->getCameraManipulator()->getFusionDistanceValue() ); + view->getCamera()->setViewMatrix( view->getCameraManipulator()->getInverseMatrix()); } view->updateSlaves(); } - + if (getViewerStats() && getViewerStats()->collectStats("update")) { double endUpdateTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); diff --git a/src/osgViewer/Renderer.cpp b/src/osgViewer/Renderer.cpp index 9240e4335..417f6a0cc 100644 --- a/src/osgViewer/Renderer.cpp +++ b/src/osgViewer/Renderer.cpp @@ -1,13 +1,13 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ @@ -100,7 +100,7 @@ void OpenGLQuerySupport::beginQuery(int frameNumber) { GLuint query = createQueryObject(); _extensions->glBeginQuery(GL_TIME_ELAPSED, query); - _queryFrameNumberList.push_back(QueryFrameNumberPair(query, frameNumber)); + _queryFrameNumberList.push_back(QueryFrameNumberPair(query, frameNumber)); } void OpenGLQuerySupport::endQuery() @@ -143,7 +143,7 @@ osgUtil::SceneView* Renderer::ThreadSafeQueue::takeFront() _queue.pop_front(); if (_queue.empty()) _block.set(false); - + return front; } @@ -199,7 +199,7 @@ Renderer::Renderer(osg::Camera* camera): _sceneView[0]->setGlobalStateSet(stateset); _sceneView[1]->setGlobalStateSet(stateset); - + _sceneView[0]->setDefaults(sceneViewOptions); _sceneView[1]->setDefaults(sceneViewOptions); @@ -213,7 +213,7 @@ Renderer::Renderer(osg::Camera* camera): // prevent the draw traversal from reading from it before the cull traversal has been completed. _availableQueue.add(_sceneView[0].get()); _availableQueue.add(_sceneView[1].get()); - + DEBUG_MESSAGE<<"_availableQueue.size()="<<_availableQueue._queue.size()<setGlobalStateSet(stateset); } - + osg::GraphicsContext* context = _camera->getGraphicsContext(); osg::State* state = context ? context->getState() : 0; - if (sceneView->getState()!=state) + if (sceneView->getState()!=state) { sceneView->setState(state); } @@ -255,11 +255,11 @@ void Renderer::updateSceneView(osgUtil::SceneView* sceneView) osgDB::ImagePager* imagePager = view ? view->getImagePager() : 0; sceneView->getCullVisitor()->setImageRequestHandler(imagePager); - + sceneView->setFrameStamp(view ? view->getFrameStamp() : state->getFrameStamp()); - + if (databasePager) databasePager->setCompileGLObjectsForContextID(state->getContextID(), true); - + osg::DisplaySettings* ds = _camera->getDisplaySettings() ? _camera->getDisplaySettings() : ((view &&view->getDisplaySettings()) ? view->getDisplaySettings() : osg::DisplaySettings::instance()); @@ -273,11 +273,11 @@ void Renderer::compile() DEBUG_MESSAGE<<"Renderer::compile()"<getSceneData()) + if (sceneView->getSceneData()) { osgUtil::GLObjectsVisitor glov; glov.setState(sceneView->getState()); @@ -329,7 +329,7 @@ void Renderer::cull() if (stats && stats->collectStats("rendering")) { DEBUG_MESSAGE<<"Collecting rendering stats"<setAttribute(frameNumber, "Cull traversal begin time", osg::Timer::instance()->delta_s(_startTick, beforeCullTick)); stats->setAttribute(frameNumber, "Cull traversal end time", osg::Timer::instance()->delta_s(_startTick, afterCullTick)); stats->setAttribute(frameNumber, "Cull traversal time taken", osg::Timer::instance()->delta_s(beforeCullTick, afterCullTick)); @@ -339,7 +339,7 @@ void Renderer::cull() { osgUtil::Statistics sceneStats; sceneView->getStats(sceneStats); - + stats->setAttribute(frameNumber, "Visible vertex count", static_cast(sceneStats._vertexCount)); stats->setAttribute(frameNumber, "Visible number of drawables", static_cast(sceneStats.numDrawables)); stats->setAttribute(frameNumber, "Visible number of lights", static_cast(sceneStats.nlights)); @@ -359,7 +359,7 @@ void Renderer::cull() stats->setAttribute(frameNumber, "Visible number of GL_QUADS", static_cast(pcm[GL_QUADS])); stats->setAttribute(frameNumber, "Visible number of GL_QUAD_STRIP", static_cast(pcm[GL_QUAD_STRIP])); stats->setAttribute(frameNumber, "Visible number of GL_POLYGON", static_cast(pcm[GL_POLYGON])); - + } _drawQueue.add(sceneView); @@ -393,7 +393,7 @@ void Renderer::draw() { compile(); } - + osgViewer::View* view = dynamic_cast(_camera->getView()); osgDB::DatabasePager* databasePager = view ? view->getDatabasePager() : 0; @@ -432,24 +432,24 @@ void Renderer::draw() bool acquireGPUStats = stats && _timerQuerySupported && stats->collectStats("gpu"); - if (acquireGPUStats) + if (acquireGPUStats) { checkQuery(stats); } // do draw traversal - if (acquireGPUStats) + if (acquireGPUStats) { checkQuery(stats); beginQuery(frameNumber); } osg::Timer_t beforeDrawTick; - - + + bool serializeDraw = sceneView->getDisplaySettings()->getSerializeDrawDispatch(); - if (serializeDraw) + if (serializeDraw) { OpenThreads::ScopedLock lock(s_drawSerializerMutex); beforeDrawTick = osg::Timer::instance()->tick(); @@ -469,7 +469,7 @@ void Renderer::draw() // now flush delete OpenGL objects and compile any objects as required by the DatabasePager flushAndCompile(dispatchTime, sceneView, databasePager, compileThread); - + if (acquireGPUStats) { endQuery(); @@ -477,7 +477,7 @@ void Renderer::draw() } //glFlush(); - + osg::Timer_t afterDrawTick = osg::Timer::instance()->tick(); // osg::notify(osg::NOTICE)<<"Time wait for draw = "<delta_m(startDrawTick, beforeDrawTick)<collectStats("gpu"); - if (acquireGPUStats) + if (acquireGPUStats) { checkQuery(stats); } @@ -576,7 +576,7 @@ void Renderer::cull_draw() // do draw traversal - if (acquireGPUStats) + if (acquireGPUStats) { checkQuery(stats); beginQuery(frameNumber); @@ -586,10 +586,10 @@ void Renderer::cull_draw() bool serializeDraw = sceneView->getDisplaySettings()->getSerializeDrawDispatch(); - if (serializeDraw) + if (serializeDraw) { OpenThreads::ScopedLock lock(s_drawSerializerMutex); - + beforeDrawTick = osg::Timer::instance()->tick(); sceneView->draw(); } @@ -633,7 +633,7 @@ void Renderer::cull_draw() void Renderer::flushAndCompile(double currentElapsedFrameTime, osgUtil::SceneView* sceneView, osgDB::DatabasePager* databasePager, osg::GraphicsThread* compileThread) { - + double targetFrameRate = _targetFrameRate; double minimumTimeAvailableForGLCompileAndDeletePerFrame = _minimumTimeAvailableForGLCompileAndDeletePerFrame; @@ -642,7 +642,7 @@ void Renderer::flushAndCompile(double currentElapsedFrameTime, osgUtil::SceneVie targetFrameRate = std::min(targetFrameRate, databasePager->getTargetFrameRate()); minimumTimeAvailableForGLCompileAndDeletePerFrame = std::min(minimumTimeAvailableForGLCompileAndDeletePerFrame, databasePager->getMinimumTimeAvailableForGLCompileAndDeletePerFrame()); } - + double targetFrameTime = 1.0/targetFrameRate; double availableTime = std::max((targetFrameTime - currentElapsedFrameTime)*_conservativeTimeRatio, @@ -666,7 +666,7 @@ void Renderer::flushAndCompile(double currentElapsedFrameTime, osgUtil::SceneVie sceneView->flushDeletedGLObjects(flushTime); } - // if any time left over from flush add this to compile time. + // if any time left over from flush add this to compile time. if (flushTime>0.0) compileTime += flushTime; #if 0 diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 5a5cb1292..580ea3361 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -1,13 +1,13 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ @@ -65,7 +65,7 @@ Viewer::Viewer(osg::ArgumentParser& arguments) //arguments.getApplicationUsage()->addCommandLineOption("--radius",""); //arguments.getApplicationUsage()->addCommandLineOption("--collar",""); //arguments.getApplicationUsage()->addCommandLineOption("--im",""); - + std::string filename; bool readConfig = false; while (arguments.read("-c",filename)) @@ -139,9 +139,9 @@ Viewer::Viewer(osg::ArgumentParser& arguments) while (arguments.read("--wow-vz",wow_vz)) {} while (arguments.read("--wow-M",wow_M)) {} while (arguments.read("--wow-C",wow_C)) {} - + if (screenNum<0) screenNum = 0; - + setUpViewForWoWVxDisplay( screenNum, wow_content, wow_factor, wow_offset, wow_Zd, wow_vz, wow_M, wow_C ); } else if ((ss3d=arguments.read("--3d-sd")) || arguments.read("--panoramic-sd")) @@ -174,7 +174,7 @@ Viewer::Viewer(osg::ArgumentParser& arguments) { if (screenNum>=0) setUpViewInWindow(x, y, width, height, screenNum); else setUpViewInWindow(x,y,width,height); - + } else if (screenNum>=0) { @@ -194,7 +194,7 @@ void Viewer::constructorInit() _eventVisitor = new osgGA::EventVisitor; _eventVisitor->setActionAdapter(this); _eventVisitor->setFrameStamp(_frameStamp.get()); - + _updateVisitor = new osgUtil::UpdateVisitor; _updateVisitor->setFrameStamp(_frameStamp.get()); @@ -213,7 +213,7 @@ Viewer::~Viewer() stopThreading(); - + if (_scene.valid() && _scene->getDatabasePager()) { _scene->getDatabasePager()->cancel(); @@ -230,9 +230,9 @@ Viewer::~Viewer() { (*citr)->close(); } - + //osg::notify(osg::NOTICE)<<"finish Viewer::~Viewer()"< object = osgDB::readObjectFile(filename); - if (!object) + if (!object) { //osg::notify(osg::NOTICE)<<"Error: Unable to load configuration file \""<(object.get()); if (compositeViewer) { osg::notify(osg::NOTICE)<<"Error: Config file \""<(object.get()); if (view) { @@ -306,7 +306,7 @@ bool Viewer::readConfiguration(const std::string& filename) return true; } else - { + { osg::notify(osg::NOTICE)<<"Error: Config file \""<isRealized()) ++numRealizedWindows; } - + return numRealizedWindows > 0; } @@ -419,18 +419,18 @@ GraphicsWindowEmbedded* Viewer::setUpViewerAsEmbeddedInWindow(int x, int y, int void Viewer::realize() { //osg::notify(osg::INFO)<<"Viewer::realize()"<getMaxTexturePoolSize(); + if (_camera->getDisplaySettings()) maxTexturePoolSize = std::max(maxTexturePoolSize, _camera->getDisplaySettings()->getMaxTexturePoolSize()); + if (_displaySettings.valid()) maxTexturePoolSize = std::max(maxTexturePoolSize, _displaySettings->getMaxTexturePoolSize()); + + unsigned int maxVBOPoolSize = osg::DisplaySettings::instance()->getMaxVBOPoolSize(); + if (_displaySettings.valid()) maxVBOPoolSize = std::max(maxVBOPoolSize, _displaySettings->getMaxVBOPoolSize()); + if (_camera->getDisplaySettings()) maxVBOPoolSize = std::max(maxVBOPoolSize, _camera->getDisplaySettings()->getMaxVBOPoolSize()); + + unsigned int maxFBOPoolSize = osg::DisplaySettings::instance()->getMaxFBOPoolSize(); + if (_displaySettings.valid()) maxFBOPoolSize = std::max(maxFBOPoolSize, _displaySettings->getMaxFBOPoolSize()); + if (_camera->getDisplaySettings()) maxFBOPoolSize = std::max(maxFBOPoolSize, _camera->getDisplaySettings()->getMaxFBOPoolSize()); + for(Contexts::iterator citr = contexts.begin(); citr != contexts.end(); ++citr) { osg::GraphicsContext* gc = *citr; + + // set the pool sizes, 0 the default will result in no GL object pools. + gc->getState()->setMaxTexturePoolSize(maxTexturePoolSize); + gc->getState()->setMaxVBOPoolSize(maxVBOPoolSize); + gc->getState()->setMaxFBOPoolSize(maxFBOPoolSize); + gc->realize(); - + if (_realizeOperation.valid() && gc->valid()) { gc->makeCurrent(); - + (*_realizeOperation)(gc); - + gc->releaseContext(); } } @@ -507,11 +525,11 @@ void Viewer::realize() osgViewer::GraphicsWindow* gw = dynamic_cast(*citr); if (gw) { - gw->grabFocusIfPointerInWindow(); + gw->grabFocusIfPointerInWindow(); } } } - + // initialize the global timer to be relative to the current time. osg::Timer::instance()->setStartTick(); @@ -519,7 +537,7 @@ void Viewer::realize() setStartTick(osg::Timer::instance()->getStartTick()); setUpThreading(); - + if (osg::DisplaySettings::instance()->getCompileContextsHint()) { int numProcessors = OpenThreads::GetNumberOfProcessors(); @@ -534,12 +552,12 @@ void Viewer::realize() gc->createGraphicsThread(); gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors); gc->getGraphicsThread()->startThread(); - + ++processNum; } } } - + } @@ -563,7 +581,7 @@ void Viewer::advance(double simulationTime) { _frameStamp->setSimulationTime(simulationTime); } - + if (getViewerStats() && getViewerStats()->collectStats("frame_rate")) { // update previous frame stats @@ -590,16 +608,16 @@ void Viewer::eventTraversal() double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); // osg::notify(osg::NOTICE)<<"Viewer::frameEventTraversal()."<getCurrentEventState(); + osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix(); - if (getCamera()->getViewport()) + if (getCamera()->getViewport()) { osg::Viewport* viewport = getCamera()->getViewport(); masterCameraVPW *= viewport->computeWindowMatrix(); @@ -619,25 +637,25 @@ void Viewer::eventTraversal() if (gw) { gw->checkEvents(); - + osgGA::EventQueue::Events gw_events; gw->getEventQueue()->takeEvents(gw_events); - + osgGA::EventQueue::Events::iterator itr; for(itr = gw_events.begin(); itr != gw_events.end(); ++itr) { osgGA::GUIEventAdapter* event = itr->get(); - + bool pointerEvent = false; float x = event->getX(); float y = event->getY(); - + bool invert_y = event->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS; if (invert_y && gw->getTraits()) y = gw->getTraits()->height - y; - + switch(event->getEventType()) { case(osgGA::GUIEventAdapter::PUSH): @@ -646,7 +664,7 @@ void Viewer::eventTraversal() case(osgGA::GUIEventAdapter::MOVE): { pointerEvent = true; - + if (event->getEventType()!=osgGA::GUIEventAdapter::DRAG || !getCameraWithFocus()) { osg::GraphicsContext::Cameras& cameras = gw->getCameras(); @@ -655,12 +673,12 @@ void Viewer::eventTraversal() ++citr) { osg::Camera* camera = *citr; - if (camera->getView()==this && + if (camera->getView()==this && camera->getAllowEventFocus() && camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER) { osg::Viewport* viewport = camera ? camera->getViewport() : 0; - if (viewport && + if (viewport && x >= viewport->x() && y >= viewport->y() && x <= (viewport->x()+viewport->width()) && y <= (viewport->y()+viewport->height()) ) { @@ -670,13 +688,13 @@ void Viewer::eventTraversal() } } } - + break; } default: break; } - + if (pointerEvent) { if (getCameraWithFocus()) @@ -690,7 +708,7 @@ void Viewer::eventTraversal() osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix; x = new_coord.x(); - y = new_coord.y(); + y = new_coord.y(); // osg::notify(osg::NOTICE)<<"pointer event new_coord.x()="<getKey()==_keyEventSetsDone) _done = true; break; - + case(osgGA::GUIEventAdapter::QUIT_APPLICATION): if (_quitEventSetsDone) _done = true; break; - + default: break; } } } - + if (_done) return; if (_eventVisitor.valid() && getSceneData()) @@ -888,7 +906,7 @@ void Viewer::eventTraversal() { (*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this, 0, 0); } - + } for(osgGA::EventQueue::Events::iterator itr = events.begin(); @@ -901,7 +919,7 @@ void Viewer::eventTraversal() _cameraManipulator->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *this); } } - + if (getViewerStats() && getViewerStats()->collectStats("event")) { double endEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); @@ -1003,14 +1021,14 @@ void Viewer::getAllThreads(Threads& threads, bool onlyActive) OperationThreads operationThreads; getOperationThreads(operationThreads); - + for(OperationThreads::iterator itr = operationThreads.begin(); itr != operationThreads.end(); ++itr) { threads.push_back(*itr); } - + if (_scene.valid()) { @@ -1033,7 +1051,7 @@ void Viewer::getAllThreads(Threads& threads, bool onlyActive) void Viewer::getOperationThreads(OperationThreads& threads, bool onlyActive) { threads.clear(); - + Contexts contexts; getContexts(contexts); for(Contexts::iterator gcitr = contexts.begin(); @@ -1041,13 +1059,13 @@ void Viewer::getOperationThreads(OperationThreads& threads, bool onlyActive) ++gcitr) { osg::GraphicsContext* gc = *gcitr; - if (gc->getGraphicsThread() && + if (gc->getGraphicsThread() && (!onlyActive || gc->getGraphicsThread()->isRunning()) ) { threads.push_back(gc->getGraphicsThread()); } } - + Cameras cameras; getCameras(cameras); for(Cameras::iterator citr = cameras.begin(); @@ -1055,13 +1073,13 @@ void Viewer::getOperationThreads(OperationThreads& threads, bool onlyActive) ++citr) { osg::Camera* camera = *citr; - if (camera->getCameraThread() && + if (camera->getCameraThread() && (!onlyActive || camera->getCameraThread()->isRunning()) ) { threads.push_back(camera->getCameraThread()); } } - + } void Viewer::getContexts(Contexts& contexts, bool onlyValid) @@ -1071,14 +1089,14 @@ void Viewer::getContexts(Contexts& contexts, bool onlyValid) contexts.clear(); - if (_camera.valid() && - _camera->getGraphicsContext() && + if (_camera.valid() && + _camera->getGraphicsContext() && (_camera->getGraphicsContext()->valid() || !onlyValid)) { contextSet.insert(_camera->getGraphicsContext()); contexts.push_back(_camera->getGraphicsContext()); } - + for(unsigned int i=0; igetGraphicsContext() && _camera->getGraphicsContext()->valid())) ) cameras.push_back(_camera.get()); for(Slaves::iterator itr = _slaves.begin(); diff --git a/src/osgWrappers/osg/DisplaySettings.cpp b/src/osgWrappers/osg/DisplaySettings.cpp index e856d6ecc..c11b71080 100644 --- a/src/osgWrappers/osg/DisplaySettings.cpp +++ b/src/osgWrappers/osg/DisplaySettings.cpp @@ -384,6 +384,36 @@ BEGIN_OBJECT_REFLECTOR(osg::DisplaySettings) __C5_std_string_R1__getApplication, "", ""); + I_Method1(void, setMaxTexturePoolSize, IN, unsigned int, size, + Properties::NON_VIRTUAL, + __void__setMaxTexturePoolSize__unsigned_int, + "", + ""); + I_Method0(unsigned int, getMaxTexturePoolSize, + Properties::NON_VIRTUAL, + __unsigned_int__getMaxTexturePoolSize, + "", + ""); + I_Method1(void, setMaxVBOPoolSize, IN, unsigned int, size, + Properties::NON_VIRTUAL, + __void__setMaxVBOPoolSize__unsigned_int, + "", + ""); + I_Method0(unsigned int, getMaxVBOPoolSize, + Properties::NON_VIRTUAL, + __unsigned_int__getMaxVBOPoolSize, + "", + ""); + I_Method1(void, setMaxFBOPoolSize, IN, unsigned int, size, + Properties::NON_VIRTUAL, + __void__setMaxFBOPoolSize__unsigned_int, + "", + ""); + I_Method0(unsigned int, getMaxFBOPoolSize, + Properties::NON_VIRTUAL, + __unsigned_int__getMaxFBOPoolSize, + "", + ""); I_SimpleProperty(bool, AccumBuffer, __bool__getAccumBuffer, 0); @@ -411,9 +441,18 @@ BEGIN_OBJECT_REFLECTOR(osg::DisplaySettings) I_SimpleProperty(float, EyeSeparation, __float__getEyeSeparation, __void__setEyeSeparation__float); + I_SimpleProperty(unsigned int, MaxFBOPoolSize, + __unsigned_int__getMaxFBOPoolSize, + __void__setMaxFBOPoolSize__unsigned_int); I_SimpleProperty(unsigned int, MaxNumberOfGraphicsContexts, __unsigned_int__getMaxNumberOfGraphicsContexts, __void__setMaxNumberOfGraphicsContexts__unsigned_int); + I_SimpleProperty(unsigned int, MaxTexturePoolSize, + __unsigned_int__getMaxTexturePoolSize, + __void__setMaxTexturePoolSize__unsigned_int); + I_SimpleProperty(unsigned int, MaxVBOPoolSize, + __unsigned_int__getMaxVBOPoolSize, + __void__setMaxVBOPoolSize__unsigned_int); I_SimpleProperty(unsigned int, MinimumNumAccumAlphaBits, __unsigned_int__getMinimumNumAccumAlphaBits, 0); diff --git a/src/osgWrappers/osg/State.cpp b/src/osgWrappers/osg/State.cpp index cf4c94469..f6d2a703b 100644 --- a/src/osgWrappers/osg/State.cpp +++ b/src/osgWrappers/osg/State.cpp @@ -696,6 +696,36 @@ BEGIN_OBJECT_REFLECTOR(osg::State) __void__decrementDynamicObjectCount, "Decrement the number of dynamic objects left to render this frame, and once the count goes to zero call the DynamicObjectRenderingCompletedCallback to inform of completion. ", ""); + I_Method1(void, setMaxTexturePoolSize, IN, unsigned int, size, + Properties::NON_VIRTUAL, + __void__setMaxTexturePoolSize__unsigned_int, + "", + ""); + I_Method0(unsigned int, getMaxTexturePoolSize, + Properties::NON_VIRTUAL, + __unsigned_int__getMaxTexturePoolSize, + "", + ""); + I_Method1(void, setMaxVBOPoolSize, IN, unsigned int, size, + Properties::NON_VIRTUAL, + __void__setMaxVBOPoolSize__unsigned_int, + "", + ""); + I_Method0(unsigned int, getMaxVBOPoolSize, + Properties::NON_VIRTUAL, + __unsigned_int__getMaxVBOPoolSize, + "", + ""); + I_Method1(void, setMaxFBOPoolSize, IN, unsigned int, size, + Properties::NON_VIRTUAL, + __void__setMaxFBOPoolSize__unsigned_int, + "", + ""); + I_Method0(unsigned int, getMaxFBOPoolSize, + Properties::NON_VIRTUAL, + __unsigned_int__getMaxFBOPoolSize, + "", + ""); I_Method1(void, setCheckForGLErrors, IN, osg::State::CheckForGLErrors, check, Properties::NON_VIRTUAL, __void__setCheckForGLErrors__CheckForGLErrors, @@ -850,6 +880,15 @@ BEGIN_OBJECT_REFLECTOR(osg::State) I_SimpleProperty(const osg::Program::PerContextProgram *, LastAppliedProgramObject, __C5_Program_PerContextProgram_P1__getLastAppliedProgramObject, __void__setLastAppliedProgramObject__C5_Program_PerContextProgram_P1); + I_SimpleProperty(unsigned int, MaxFBOPoolSize, + __unsigned_int__getMaxFBOPoolSize, + __void__setMaxFBOPoolSize__unsigned_int); + I_SimpleProperty(unsigned int, MaxTexturePoolSize, + __unsigned_int__getMaxTexturePoolSize, + __void__setMaxTexturePoolSize__unsigned_int); + I_SimpleProperty(unsigned int, MaxVBOPoolSize, + __unsigned_int__getMaxVBOPoolSize, + __void__setMaxVBOPoolSize__unsigned_int); I_IndexedProperty(bool, ModeValidity, __bool__getModeValidity__StateAttribute_GLMode, __void__setModeValidity__StateAttribute_GLMode__bool, diff --git a/src/osgWrappers/osg/Texture.cpp b/src/osgWrappers/osg/Texture.cpp index 02852a25d..493d5dc33 100644 --- a/src/osgWrappers/osg/Texture.cpp +++ b/src/osgWrappers/osg/Texture.cpp @@ -105,8 +105,6 @@ END_REFLECTOR TYPE_NAME_ALIAS(std::list< osg::ref_ptr< osg::Texture::TextureObject > >, osg::Texture::TextureObjectList) -TYPE_NAME_ALIAS(osg::buffered_object< osg::Texture::TextureObjectList >, osg::Texture::TextureObjectListMap) - BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture) I_DeclaringFile("osg/Texture"); I_BaseType(osg::StateAttribute); @@ -330,7 +328,12 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture) I_Method1(osg::Texture::TextureObject *, getTextureObject, IN, unsigned int, contextID, Properties::NON_VIRTUAL, __TextureObject_P1__getTextureObject__unsigned_int, - "Returns a pointer to the texture object for the current context. ", + "Returns a pointer to the TextureBbject for the current context. ", + ""); + I_Method2(void, setTextureObject, IN, unsigned int, contextID, IN, osg::Texture::TextureObject *, to, + Properties::NON_VIRTUAL, + __void__setTextureObject__unsigned_int__TextureObject_P1, + "", ""); I_Method0(void, dirtyTextureObject, Properties::NON_VIRTUAL, @@ -457,11 +460,6 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture) __void__applyTexImage2D_subload__State_R1__GLenum__C5_Image_P1__GLsizei__GLsizei__GLint__GLsizei, "Helper method. ", "Subloads images into the texture, but doesn't set or use a texture binding. Note: Don't call this method directly unless you're implementing a subload callback. "); - I_Method1(void, takeTextureObjects, IN, osg::Texture::TextureObjectListMap &, toblm, - Properties::NON_VIRTUAL, - __void__takeTextureObjects__TextureObjectListMap_R1, - "Takes the active texture objects from the Texture and places them in the specified TextureObjectListMap. ", - ""); I_StaticMethod2(osg::Texture::Extensions *, getExtensions, IN, unsigned int, contextID, IN, bool, createIfNotInitalized, __Extensions_P1__getExtensions__unsigned_int__bool_S, "Gets the extension for the specified context. ", @@ -478,12 +476,16 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture) __void__getCompressedSize__GLenum__GLint__GLint__GLint__GLint_R1__GLint_R1_S, "Determine the size of a compressed image, given the internalFormat, the width, the height, and the depth of the image. ", "The block size and the size are output parameters. "); - I_StaticMethod2(osg::Texture::TextureObject *, generateTextureObject, IN, unsigned int, contextID, IN, GLenum, target, - __TextureObject_P1__generateTextureObject__unsigned_int__GLenum_S, + I_StaticMethod1(osg::ref_ptr< osg::Texture::TextureObjectManager > &, getTextureObjectManager, IN, unsigned int, contextID, + __osg_ref_ptrT1_Texture_TextureObjectManager__R1__getTextureObjectManager__unsigned_int_S, "", ""); - I_StaticMethod8(osg::Texture::TextureObject *, generateTextureObject, IN, unsigned int, contextID, IN, GLenum, target, IN, GLint, numMipmapLevels, IN, GLenum, internalFormat, IN, GLsizei, width, IN, GLsizei, height, IN, GLsizei, depth, IN, GLint, border, - __TextureObject_P1__generateTextureObject__unsigned_int__GLenum__GLint__GLenum__GLsizei__GLsizei__GLsizei__GLint_S, + I_StaticMethod3(osg::Texture::TextureObject *, generateTextureObject, IN, const osg::Texture *, texture, IN, unsigned int, contextID, IN, GLenum, target, + __TextureObject_P1__generateTextureObject__C5_Texture_P1__unsigned_int__GLenum_S, + "", + ""); + I_StaticMethod9(osg::Texture::TextureObject *, generateTextureObject, IN, const osg::Texture *, texture, IN, unsigned int, contextID, IN, GLenum, target, IN, GLint, numMipmapLevels, IN, GLenum, internalFormat, IN, GLsizei, width, IN, GLsizei, height, IN, GLsizei, depth, IN, GLint, border, + __TextureObject_P1__generateTextureObject__C5_Texture_P1__unsigned_int__GLenum__GLint__GLenum__GLsizei__GLsizei__GLsizei__GLint_S, "", ""); I_StaticMethod1(void, setMinimumNumberOfTextureObjectsToRetainInCache, IN, unsigned int, minimum, @@ -506,6 +508,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture) __void__flushDeletedTextureObjects__unsigned_int__double__double_R1_S, "", ""); + I_StaticMethod2(void, releaseTextureObject, IN, unsigned int, contextID, IN, osg::Texture::TextureObject *, to, + __void__releaseTextureObject__unsigned_int__TextureObject_P1_S, + "", + ""); I_ProtectedMethod0(void, computeInternalFormat, Properties::PURE_VIRTUAL, Properties::CONST, @@ -640,6 +646,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Texture) I_SimpleProperty(int, TextureHeight, __int__getTextureHeight, 0); + I_IndexedProperty(osg::Texture::TextureObject *, TextureObject, + __TextureObject_P1__getTextureObject__unsigned_int, + __void__setTextureObject__unsigned_int__TextureObject_P1, + 0); I_SimpleProperty(GLenum, TextureTarget, __GLenum__getTextureTarget, 0); @@ -664,12 +674,16 @@ END_REFLECTOR BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObject) I_DeclaringFile("osg/Texture"); I_BaseType(osg::Referenced); - I_Constructor2(IN, GLuint, id, IN, GLenum, target, - ____TextureObject__GLuint__GLenum, + I_Constructor3(IN, osg::Texture *, texture, IN, GLuint, id, IN, GLenum, target, + ____TextureObject__Texture_P1__GLuint__GLenum, "", ""); - I_Constructor8(IN, GLuint, id, IN, GLenum, target, IN, GLint, numMipmapLevels, IN, GLenum, internalFormat, IN, GLsizei, width, IN, GLsizei, height, IN, GLsizei, depth, IN, GLint, border, - ____TextureObject__GLuint__GLenum__GLint__GLenum__GLsizei__GLsizei__GLsizei__GLint, + I_Constructor3(IN, osg::Texture *, texture, IN, GLuint, id, IN, const osg::Texture::TextureProfile &, profile, + ____TextureObject__Texture_P1__GLuint__C5_TextureProfile_R1, + "", + ""); + I_Constructor9(IN, osg::Texture *, texture, IN, GLuint, id, IN, GLenum, target, IN, GLint, numMipmapLevels, IN, GLenum, internalFormat, IN, GLsizei, width, IN, GLsizei, height, IN, GLsizei, depth, IN, GLint, border, + ____TextureObject__Texture_P1__GLuint__GLenum__GLint__GLenum__GLsizei__GLsizei__GLsizei__GLint, "", ""); I_Method7(bool, match, IN, GLenum, target, IN, GLint, numMipmapLevels, IN, GLenum, internalFormat, IN, GLsizei, width, IN, GLsizei, height, IN, GLsizei, depth, IN, GLint, border, @@ -682,6 +696,36 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObject) __void__bind, "", ""); + I_Method0(GLenum, id, + Properties::NON_VIRTUAL, + __GLenum__id, + "", + ""); + I_Method0(GLenum, target, + Properties::NON_VIRTUAL, + __GLenum__target, + "", + ""); + I_Method1(void, setTexture, IN, osg::Texture *, texture, + Properties::NON_VIRTUAL, + __void__setTexture__Texture_P1, + "", + ""); + I_Method0(osg::Texture *, getTexture, + Properties::NON_VIRTUAL, + __Texture_P1__getTexture, + "", + ""); + I_Method1(void, setTimeStamp, IN, double, timestamp, + Properties::NON_VIRTUAL, + __void__setTimeStamp__double, + "", + ""); + I_Method0(double, getTimeStamp, + Properties::NON_VIRTUAL, + __double__getTimeStamp, + "", + ""); I_MethodWithDefaults1(void, setAllocated, IN, bool, allocated, true, Properties::NON_VIRTUAL, __void__setAllocated__bool, @@ -705,41 +749,133 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObject) I_SimpleProperty(bool, Allocated, 0, __void__setAllocated__bool); + I_SimpleProperty(osg::Texture *, Texture, + __Texture_P1__getTexture, + __void__setTexture__Texture_P1); + I_SimpleProperty(double, TimeStamp, + __double__getTimeStamp, + __void__setTimeStamp__double); I_PublicMemberProperty(GLuint, _id); - I_PublicMemberProperty(GLenum, _target); - I_PublicMemberProperty(GLint, _numMipmapLevels); - I_PublicMemberProperty(GLenum, _internalFormat); - I_PublicMemberProperty(GLsizei, _width); - I_PublicMemberProperty(GLsizei, _height); - I_PublicMemberProperty(GLsizei, _depth); - I_PublicMemberProperty(GLint, _border); + I_PublicMemberProperty(osg::Texture::TextureProfile, _profile); + I_PublicMemberProperty(osg::Texture::TextureObjectSet *, _set); + I_PublicMemberProperty(osg::Texture::TextureObject *, _previous); + I_PublicMemberProperty(osg::Texture::TextureObject *, _next); + I_PublicMemberProperty(osg::Texture *, _texture); I_PublicMemberProperty(bool, _allocated); I_PublicMemberProperty(double, _timeStamp); END_REFLECTOR -BEGIN_VALUE_REFLECTOR(osg::buffered_object< osg::Texture::TextureObjectList >) - I_DeclaringFile("osg/buffered_value"); - I_Constructor0(____buffered_object, - "", - ""); - I_Constructor1(IN, unsigned int, size, +BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObjectManager) + I_DeclaringFile("osg/Texture"); + I_BaseType(osg::Referenced); + I_Constructor1(IN, unsigned int, contextID, Properties::NON_EXPLICIT, - ____buffered_object__unsigned_int, + ____TextureObjectManager__unsigned_int, "", ""); - I_Method1(void, setAllElementsTo, IN, const osg::Texture::TextureObjectList &, t, + I_Method0(unsigned int, getContextID, Properties::NON_VIRTUAL, - __void__setAllElementsTo__C5_T_R1, + __unsigned_int__getContextID, "", ""); - I_Method0(void, clear, + I_Method1(void, setTexturePoolSize, IN, unsigned int, size, Properties::NON_VIRTUAL, - __void__clear, + __void__setTexturePoolSize__unsigned_int, "", ""); - I_Method0(bool, empty, + I_Method0(unsigned int, getTexturePoolSize, Properties::NON_VIRTUAL, - __bool__empty, + __unsigned_int__getTexturePoolSize, + "", + ""); + I_Method2(osg::Texture::TextureObject *, generateTextureObject, IN, const osg::Texture *, texture, IN, GLenum, target, + Properties::NON_VIRTUAL, + __TextureObject_P1__generateTextureObject__C5_Texture_P1__GLenum, + "", + ""); + I_Method8(osg::Texture::TextureObject *, generateTextureObject, IN, const osg::Texture *, texture, IN, GLenum, target, IN, GLint, numMipmapLevels, IN, GLenum, internalFormat, IN, GLsizei, width, IN, GLsizei, height, IN, GLsizei, depth, IN, GLint, border, + Properties::NON_VIRTUAL, + __TextureObject_P1__generateTextureObject__C5_Texture_P1__GLenum__GLint__GLenum__GLsizei__GLsizei__GLsizei__GLint, + "", + ""); + I_Method0(void, handlePendingOrphandedTextureObjects, + Properties::NON_VIRTUAL, + __void__handlePendingOrphandedTextureObjects, + "", + ""); + I_Method0(void, flushAllDeletedTextureObjects, + Properties::NON_VIRTUAL, + __void__flushAllDeletedTextureObjects, + "", + ""); + I_Method0(void, discardAllDeletedTextureObjects, + Properties::NON_VIRTUAL, + __void__discardAllDeletedTextureObjects, + "", + ""); + I_Method2(void, flushDeletedTextureObjects, IN, double, currentTime, IN, double &, availableTime, + Properties::NON_VIRTUAL, + __void__flushDeletedTextureObjects__double__double_R1, + "", + ""); + I_Method1(void, releaseTextureObject, IN, osg::Texture::TextureObject *, to, + Properties::NON_VIRTUAL, + __void__releaseTextureObject__TextureObject_P1, + "", + ""); + I_SimpleProperty(unsigned int, ContextID, + __unsigned_int__getContextID, + 0); + I_SimpleProperty(unsigned int, TexturePoolSize, + __unsigned_int__getTexturePoolSize, + __void__setTexturePoolSize__unsigned_int); +END_REFLECTOR + +BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObjectSet) + I_DeclaringFile("osg/Texture"); + I_BaseType(osg::Referenced); + I_Constructor2(IN, osg::Texture::TextureObjectManager *, parent, IN, const osg::Texture::TextureProfile &, profile, + ____TextureObjectSet__TextureObjectManager_P1__C5_TextureProfile_R1, + "", + ""); + I_Method0(void, handlePendingOrphandedTextureObjects, + Properties::NON_VIRTUAL, + __void__handlePendingOrphandedTextureObjects, + "", + ""); + I_Method0(void, flushAllDeletedTextureObjects, + Properties::NON_VIRTUAL, + __void__flushAllDeletedTextureObjects, + "", + ""); + I_Method0(void, discardAllDeletedTextureObjects, + Properties::NON_VIRTUAL, + __void__discardAllDeletedTextureObjects, + "", + ""); + I_Method2(void, flushDeletedTextureObjects, IN, double, currentTime, IN, double &, availableTime, + Properties::NON_VIRTUAL, + __void__flushDeletedTextureObjects__double__double_R1, + "", + ""); + I_Method1(osg::Texture::TextureObject *, takeOrGenerate, IN, osg::Texture *, texture, + Properties::NON_VIRTUAL, + __TextureObject_P1__takeOrGenerate__Texture_P1, + "", + ""); + I_Method1(void, moveToBack, IN, osg::Texture::TextureObject *, to, + Properties::NON_VIRTUAL, + __void__moveToBack__TextureObject_P1, + "", + ""); + I_Method1(void, addToBack, IN, osg::Texture::TextureObject *, to, + Properties::NON_VIRTUAL, + __void__addToBack__TextureObject_P1, + "", + ""); + I_Method1(void, orphan, IN, osg::Texture::TextureObject *, to, + Properties::NON_VIRTUAL, + __void__orphan__TextureObject_P1, "", ""); I_Method0(unsigned int, size, @@ -747,14 +883,41 @@ BEGIN_VALUE_REFLECTOR(osg::buffered_object< osg::Texture::TextureObjectList >) __unsigned_int__size, "", ""); - I_Method1(void, resize, IN, unsigned int, newSize, + I_Method0(bool, checkConsistency, Properties::NON_VIRTUAL, - __void__resize__unsigned_int, + __bool__checkConsistency, "", ""); - I_SimpleProperty(const osg::Texture::TextureObjectList &, AllElementsTo, - 0, - __void__setAllElementsTo__C5_T_R1); +END_REFLECTOR + +BEGIN_VALUE_REFLECTOR(osg::Texture::TextureProfile) + I_DeclaringFile("osg/Texture"); + I_Constructor1(IN, GLenum, target, + Properties::NON_EXPLICIT, + ____TextureProfile__GLenum, + "", + ""); + I_Constructor7(IN, GLenum, target, IN, GLint, numMipmapLevels, IN, GLenum, internalFormat, IN, GLsizei, width, IN, GLsizei, height, IN, GLsizei, depth, IN, GLint, border, + ____TextureProfile__GLenum__GLint__GLenum__GLsizei__GLsizei__GLsizei__GLint, + "", + ""); + I_Method6(void, set, IN, GLint, numMipmapLevels, IN, GLenum, internalFormat, IN, GLsizei, width, IN, GLsizei, height, IN, GLsizei, depth, IN, GLint, border, + Properties::NON_VIRTUAL, + __void__set__GLint__GLenum__GLsizei__GLsizei__GLsizei__GLint, + "", + ""); + I_Method7(bool, match, IN, GLenum, target, IN, GLint, numMipmapLevels, IN, GLenum, internalFormat, IN, GLsizei, width, IN, GLsizei, height, IN, GLsizei, depth, IN, GLint, border, + Properties::NON_VIRTUAL, + __bool__match__GLenum__GLint__GLenum__GLsizei__GLsizei__GLsizei__GLint, + "", + ""); + I_PublicMemberProperty(GLenum, _target); + I_PublicMemberProperty(GLint, _numMipmapLevels); + I_PublicMemberProperty(GLenum, _internalFormat); + I_PublicMemberProperty(GLsizei, _width); + I_PublicMemberProperty(GLsizei, _height); + I_PublicMemberProperty(GLsizei, _depth); + I_PublicMemberProperty(GLint, _border); END_REFLECTOR BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osg::Texture::TextureObject >) @@ -797,5 +960,45 @@ BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osg::Texture::TextureObject >) 0); END_REFLECTOR +BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osg::Texture::TextureObjectManager >) + I_DeclaringFile("osg/ref_ptr"); + I_Constructor0(____ref_ptr, + "", + ""); + I_Constructor1(IN, osg::Texture::TextureObjectManager *, ptr, + Properties::NON_EXPLICIT, + ____ref_ptr__T_P1, + "", + ""); + I_Constructor1(IN, const osg::ref_ptr< osg::Texture::TextureObjectManager > &, rp, + Properties::NON_EXPLICIT, + ____ref_ptr__C5_ref_ptr_R1, + "", + ""); + I_Method0(osg::Texture::TextureObjectManager *, get, + Properties::NON_VIRTUAL, + __T_P1__get, + "", + ""); + I_Method0(bool, valid, + Properties::NON_VIRTUAL, + __bool__valid, + "", + ""); + I_Method0(osg::Texture::TextureObjectManager *, release, + Properties::NON_VIRTUAL, + __T_P1__release, + "", + ""); + I_Method1(void, swap, IN, osg::ref_ptr< osg::Texture::TextureObjectManager > &, rp, + Properties::NON_VIRTUAL, + __void__swap__ref_ptr_R1, + "", + ""); + I_SimpleProperty(osg::Texture::TextureObjectManager *, , + __T_P1__get, + 0); +END_REFLECTOR + STD_LIST_REFLECTOR(std::list< osg::ref_ptr< osg::Texture::TextureObject > >)