Added set/getUnrefImageOnApply() methods and associated flag and
code in Texture::apply() to set the _image to 0 on apply. Note, this will only work when you have a single graphics context, as with multiple graphics contexts one can't delete the image after the first apply, as there will be more than one texture object to update.
This commit is contained in:
@@ -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> _image;
|
||||
|
||||
bool _unrefImageAfterApply;
|
||||
|
||||
GLenum _target; // defaults to GL_TEXTURE_2D
|
||||
|
||||
WrapMode _wrap_s;
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user