diff --git a/include/osg/Texture b/include/osg/Texture index cf872452b..253e943dd 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -82,6 +82,7 @@ class SG_EXPORT Texture : public StateAttribute _handleList(), _modifiedTag(), _image(copyop(text._image.get())), + _unrefImageAfterApply(text._unrefImageAfterApply), _target(text._target), _wrap_s(text._wrap_s), _wrap_t(text._wrap_t), @@ -120,6 +121,10 @@ class SG_EXPORT Texture : public StateAttribute /** Get the const texture image. */ inline const Image* getImage() const { return _image.get(); } + + void setUnrefImageAfterApply(bool unrefImage) { _unrefImageAfterApply = unrefImage; } + + bool getUnrefImageAfterApply() const { return _unrefImageAfterApply; } /** Copy pixels into a 2D texture image.As per glCopyTexImage2D. * Creates an OpenGL texture object from the current OpenGL background @@ -273,7 +278,7 @@ class SG_EXPORT Texture : public StateAttribute { // pad out handle list if required. if (_modifiedTag.size()<=contextID) - _modifiedTag.resize(contextID,0); + _modifiedTag.resize(contextID+1,0); // get the modified tag for the current contextID. return _modifiedTag[contextID]; @@ -329,6 +334,8 @@ class SG_EXPORT Texture : public StateAttribute // which is const... mutable ref_ptr _image; + bool _unrefImageAfterApply; + GLenum _target; // defaults to GL_TEXTURE_2D WrapMode _wrap_s; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 82e417ff3..53641074a 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -20,6 +20,7 @@ Texture::DeletedTextureObjectCache Texture::s_deletedTextureObjectCache; Texture::Texture(): _target(GL_TEXTURE_2D), + _unrefImageAfterApply(true), _wrap_s(CLAMP), _wrap_t(CLAMP), _wrap_r(CLAMP), @@ -223,6 +224,9 @@ void Texture::apply(State& state) const // unless a second bind is called?!! // perhaps it is the first glBind which is not required... glBindTexture( _target, handle ); + + if (_unrefImageAfterApply) + _image = 0; } }