Added support for multiple graphics contexts to osg::Texture and its

subclasses.
This commit is contained in:
Robert Osfield 2002-09-04 08:14:04 +00:00
parent d5f87e919d
commit 6ff24b338f
6 changed files with 41 additions and 22 deletions

View File

@ -109,7 +109,7 @@ class SG_EXPORT Texture : public osg::StateAttribute
/** Sets the border color for this texture. Makes difference only if
* wrap mode is CLAMP_TO_BORDER */
void setBorderColor(const Vec4& color) { _borderColor = color; _texParametersDirty = true; }
void setBorderColor(const Vec4& color) { _borderColor = color; dirtyTextureParameters(); }
const Vec4& getBorderColor() const { return _borderColor; }
@ -181,7 +181,7 @@ class SG_EXPORT Texture : public osg::StateAttribute
/** Get the handle to the texture object for the current context.*/
/** return the OpenGL texture object for specified context.*/
inline GLuint& getTextureObject(const uint contextID) const
inline GLuint& getTextureObject(uint contextID) const
{
// pad out handle list if required.
if (_handleList.size()<=contextID)
@ -191,7 +191,7 @@ class SG_EXPORT Texture : public osg::StateAttribute
return _handleList[contextID];
}
inline uint& getModifiedTag(const uint contextID) const
inline uint& getModifiedTag(uint contextID) const
{
// pad out handle list if required.
if (_modifiedTag.size()<=contextID)
@ -201,9 +201,21 @@ class SG_EXPORT Texture : public osg::StateAttribute
return _modifiedTag[contextID];
}
inline uint& getTextureParameterDity(uint contextID) const
{
// pad out handle list if required.
if (_texParametersDirtyList.size()<=contextID)
_texParametersDirtyList.resize(contextID+1,0);
// get the dirty flag for the current contextID.
return _texParametersDirtyList[contextID];
}
/** Force a recompile on next apply() of associated OpenGL texture objects.*/
void dirtyTextureObject();
/** Force a resetting on next apply() of associated OpenGL texture parameters.*/
void dirtyTextureParameters();
/** use deleteTextureObject instead of glDeleteTextures to allow
@ -253,6 +265,8 @@ class SG_EXPORT Texture : public osg::StateAttribute
typedef std::vector<uint> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag;
typedef std::vector<uint> TexParameterDirtyList;
mutable TexParameterDirtyList _texParametersDirtyList;
WrapMode _wrap_s;
WrapMode _wrap_t;
@ -264,10 +278,6 @@ class SG_EXPORT Texture : public osg::StateAttribute
Vec4 _borderColor;
// true if apply tex parameters required.
mutable bool _texParametersDirty;
InternalFormatMode _internalFormatMode;
mutable GLint _internalFormat;

View File

@ -20,12 +20,12 @@ Texture::Texture():
_mag_filter(LINEAR),
_maxAnisotropy(1.0f),
_borderColor(0.0, 0.0, 0.0, 0.0),
_texParametersDirty(true),
_internalFormatMode(USE_IMAGE_DATA_FORMAT),
_internalFormat(0)
{
_handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
_modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
_texParametersDirtyList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),true);
}
Texture::Texture(const Texture& text,const CopyOp& copyop):
@ -37,12 +37,12 @@ Texture::Texture(const Texture& text,const CopyOp& copyop):
_mag_filter(text._mag_filter),
_maxAnisotropy(text._maxAnisotropy),
_borderColor(text._borderColor),
_texParametersDirty(false),
_internalFormatMode(text._internalFormatMode),
_internalFormat(text._internalFormat)
{
_handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
_modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
_texParametersDirtyList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),true);
}
Texture::~Texture()
@ -70,9 +70,9 @@ void Texture::setWrap(WrapParameter which, WrapMode wrap)
{
switch( which )
{
case WRAP_S : _wrap_s = wrap; _texParametersDirty = true; break;
case WRAP_T : _wrap_t = wrap; _texParametersDirty = true; break;
case WRAP_R : _wrap_r = wrap; _texParametersDirty = true; break;
case WRAP_S : _wrap_s = wrap; dirtyTextureParameters(); break;
case WRAP_T : _wrap_t = wrap; dirtyTextureParameters(); break;
case WRAP_R : _wrap_r = wrap; dirtyTextureParameters(); break;
default : notify(WARN)<<"Error: invalid 'which' passed Texture::setWrap("<<(unsigned int)which<<","<<(unsigned int)wrap<<")"<<std::endl; break;
}
@ -95,8 +95,8 @@ void Texture::setFilter(FilterParameter which, FilterMode filter)
{
switch( which )
{
case MIN_FILTER : _min_filter = filter; _texParametersDirty = true; break;
case MAG_FILTER : _mag_filter = filter; _texParametersDirty = true; break;
case MIN_FILTER : _min_filter = filter; dirtyTextureParameters(); break;
case MAG_FILTER : _mag_filter = filter; dirtyTextureParameters(); break;
default : notify(WARN)<<"Error: invalid 'which' passed Texture::setFilter("<<(unsigned int)which<<","<<(unsigned int)filter<<")"<<std::endl; break;
}
}
@ -117,7 +117,7 @@ void Texture::setMaxAnisotropy(float anis)
if (_maxAnisotropy!=anis)
{
_maxAnisotropy = anis;
_texParametersDirty = true;
dirtyTextureParameters();
}
}
@ -134,6 +134,16 @@ void Texture::dirtyTextureObject()
}
}
void Texture::dirtyTextureParameters()
{
for(TexParameterDirtyList::iterator itr=_texParametersDirtyList.begin();
itr!=_texParametersDirtyList.end();
++itr)
{
*itr = true;
}
}
void Texture::computeInternalFormatWithImage(osg::Image& image) const
{
static bool s_ARB_Compression = isGLExtensionSupported("GL_ARB_texture_compression");
@ -240,7 +250,7 @@ bool Texture::isCompressedInternalFormat(GLint internalFormat) const
}
}
void Texture::applyTexParameters(GLenum target, State&) const
void Texture::applyTexParameters(GLenum target, State& state) const
{
WrapMode ws = _wrap_s, wt = _wrap_t;
@ -301,8 +311,7 @@ void Texture::applyTexParameters(GLenum target, State&) const
glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, _borderColor.ptr());
}
_texParametersDirty=false;
getTextureParameterDity(state.getContextID()) = false;
}

View File

@ -96,7 +96,7 @@ void Texture1D::apply(State& state) const
{
glBindTexture( GL_TEXTURE_1D, handle );
if (_texParametersDirty) applyTexParameters(GL_TEXTURE_1D,state);
if (getTextureParameterDity(state.getContextID())) applyTexParameters(GL_TEXTURE_1D,state);
if (_subloadCallback.valid())
{

View File

@ -99,7 +99,7 @@ void Texture2D::apply(State& state) const
{
glBindTexture( GL_TEXTURE_2D, handle );
if (_texParametersDirty) applyTexParameters(GL_TEXTURE_2D,state);
if (getTextureParameterDity(state.getContextID())) applyTexParameters(GL_TEXTURE_2D,state);
if (_subloadCallback.valid())
{

View File

@ -117,7 +117,7 @@ void Texture3D::apply(State& state) const
{
glBindTexture( GL_TEXTURE_3D, handle );
if (_texParametersDirty) applyTexParameters(GL_TEXTURE_3D,state);
if (getTextureParameterDity(state.getContextID())) applyTexParameters(GL_TEXTURE_3D,state);
if (_subloadCallback.valid())
{

View File

@ -209,7 +209,7 @@ void TextureCubeMap::apply(State& state) const
if (handle != 0)
{
glBindTexture( GL_TEXTURE_CUBE_MAP, handle );
if (_texParametersDirty) applyTexParameters(GL_TEXTURE_CUBE_MAP,state);
if (getTextureParameterDity(state.getContextID())) applyTexParameters(GL_TEXTURE_CUBE_MAP,state);
if (_subloadCallback.valid())
{