diff --git a/include/osg/Texture b/include/osg/Texture index b34c5aff2..12d1932a3 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include @@ -418,7 +418,7 @@ class TextureObjectManager; /** Texture pure virtual base class that encapsulates OpenGL texture * functionality common to the various types of OSG textures. */ -class OSG_EXPORT Texture : public osg::StateAttribute +class OSG_EXPORT Texture : public osg::TextureAttribute { public : @@ -1052,7 +1052,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute } - void bind(); + void bind(osg::State& state); inline GLenum id() const { return _id; } inline GLenum target() const { return _profile._target; } diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 03cd3bdbc..38727eaa6 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -245,10 +245,12 @@ Texture::TextureObject::~TextureObject() // OSG_NOTICE<<"Texture::TextureObject::~TextureObject() "<moveToBack(this); + + if (state.getUseStateAttributeShaders()) state.setCurrentTextureFormat(_profile._internalFormat); } void Texture::TextureObject::release() @@ -1248,7 +1250,7 @@ Texture::Texture(): } Texture::Texture(const Texture& text,const CopyOp& copyop): - StateAttribute(text,copyop), + TextureAttribute(text,copyop), _wrap_s(text._wrap_s), _wrap_t(text._wrap_t), _wrap_r(text._wrap_r), @@ -2768,7 +2770,7 @@ void Texture::generateMipmap(State& state) const // FrameBufferObjects are required for glGenerateMipmap if (ext->isFrameBufferObjectSupported && ext->glGenerateMipmap) { - textureObject->bind(); + textureObject->bind(state); ext->glGenerateMipmap(textureObject->target()); // inform state that this texture is the current one bound. diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index 4fe3fda46..c46daff07 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -158,7 +158,7 @@ void Texture1D::apply(State& state) const if (textureObject) { - textureObject->bind(); + textureObject->bind(state); if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_1D,state); @@ -181,7 +181,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 = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_1D,state); @@ -202,7 +202,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 = generateAndAssignTextureObject(contextID,GL_TEXTURE_1D); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_1D,state); @@ -227,7 +227,7 @@ void Texture1D::apply(State& state) const { textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D,_numMipmapLevels,_internalFormat,_textureWidth,1,1,0); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_1D,state); @@ -415,7 +415,7 @@ void Texture1D::copyTexImage1D(State& state, int x, int y, int width) textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_1D,state); @@ -444,7 +444,7 @@ void Texture1D::copyTexSubImage1D(State& state, int xoffset, int x, int y, int w if (textureObject != 0) { - textureObject->bind(); + textureObject->bind(state); // we have a valid image applyTexParameters(GL_TEXTURE_1D,state); @@ -476,7 +476,7 @@ void Texture1D::allocateMipmap(State& state) const if (textureObject && _textureWidth != 0) { // bind texture - textureObject->bind(); + textureObject->bind(state); // compute number of mipmap levels int width = _textureWidth; diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp index d73cebc37..7bf1aa848 100644 --- a/src/osg/Texture2D.cpp +++ b/src/osg/Texture2D.cpp @@ -159,7 +159,6 @@ bool Texture2D::textureObjectValid(State& state) const void Texture2D::apply(State& state) const { - //state.setReportGLErrors(true); // get the contextID (user defined ID of 0 upwards) for the @@ -191,7 +190,7 @@ void Texture2D::apply(State& state) const if (textureObject) { - textureObject->bind(); + textureObject->bind(state); if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_2D,state); @@ -220,7 +219,7 @@ void Texture2D::apply(State& state) const _textureObjectBuffer[contextID] = _subloadCallback->generateTextureObject(*this, state); textureObject = _textureObjectBuffer[contextID].get(); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_2D,state); @@ -251,7 +250,7 @@ void Texture2D::apply(State& state) const textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_2D,state); @@ -291,7 +290,7 @@ void Texture2D::apply(State& state) const { textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_2D,state); @@ -388,7 +387,7 @@ void Texture2D::copyTexImage2D(State& state, int x, int y, int width, int height textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_2D,state); @@ -417,7 +416,7 @@ void Texture2D::copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, if (textureObject) { // we have a valid image - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_2D,state); @@ -463,7 +462,7 @@ void Texture2D::allocateMipmap(State& state) const if (textureObject && _textureWidth != 0 && _textureHeight != 0) { // bind texture - textureObject->bind(); + textureObject->bind(state); // compute number of mipmap levels int width = _textureWidth; diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index 6c34d2a70..8012aacbb 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -275,7 +275,7 @@ void Texture2DArray::apply(State& state) const if (textureObject) { // bind texture object - textureObject->bind(); + textureObject->bind(state); // if texture parameters changed, then reset them if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_2D_ARRAY,state); @@ -312,7 +312,7 @@ void Texture2DArray::apply(State& state) const { // generate texture (i.e. glGenTexture) and apply parameters textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_2D_ARRAY, state); _subloadCallback->load(*this,state); } @@ -333,7 +333,7 @@ void Texture2DArray::apply(State& state) const contextID, GL_TEXTURE_2D_ARRAY,_numMipmapLevels, _internalFormat, _textureWidth, _textureHeight, textureDepth,0); // bind texture - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_2D_ARRAY, state); // First we need to allocate the texture memory @@ -422,7 +422,7 @@ void Texture2DArray::apply(State& state) const textureObject = generateAndAssignTextureObject( contextID, GL_TEXTURE_2D_ARRAY,_numMipmapLevels,_internalFormat, _textureWidth, _textureHeight, _textureDepth,0); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_2D_ARRAY,state); extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat, @@ -614,7 +614,7 @@ void Texture2DArray::copyTexSubImage2DArray(State& state, int xoffset, int yoffs // if texture object is valid if (textureObject != 0) { - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_2D_ARRAY,state); extensions->glCopyTexSubImage3D( GL_TEXTURE_2D_ARRAY, 0, xoffset,yoffset,zoffset, x, y, width, height); @@ -653,7 +653,7 @@ void Texture2DArray::allocateMipmap(State& state) const } // bind texture - textureObject->bind(); + textureObject->bind(state); // compute number of mipmap levels int width = _textureWidth; diff --git a/src/osg/Texture2DMultisample.cpp b/src/osg/Texture2DMultisample.cpp index c723da906..43d013dc6 100644 --- a/src/osg/Texture2DMultisample.cpp +++ b/src/osg/Texture2DMultisample.cpp @@ -98,7 +98,7 @@ void Texture2DMultisample::apply(State& state) const if (textureObject) { - textureObject->bind(); + textureObject->bind(state); } else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_numSamples!=0) ) { @@ -112,7 +112,7 @@ void Texture2DMultisample::apply(State& state) const 1, _borderWidth); - textureObject->bind(); + textureObject->bind(state); extensions->glTexImage2DMultisample( getTextureTarget(), _numSamples, diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 68e42fe42..097df9c66 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -239,7 +239,7 @@ void Texture3D::apply(State& state) const if (textureObject) { // we have a valid image - textureObject->bind(); + textureObject->bind(state); if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_3D,state); @@ -263,7 +263,7 @@ void Texture3D::apply(State& state) const textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_3D); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_3D,state); @@ -289,7 +289,7 @@ void Texture3D::apply(State& state) const textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_3D); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_3D,state); @@ -314,7 +314,7 @@ void Texture3D::apply(State& state) const textureObject = generateAndAssignTextureObject( contextID,GL_TEXTURE_3D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_3D,state); @@ -487,7 +487,7 @@ void Texture3D::copyTexSubImage3D(State& state, int xoffset, int yoffset, int zo if (textureObject != 0) { - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_3D,state); extensions->glCopyTexSubImage3D( GL_TEXTURE_3D, 0, xoffset,yoffset,zoffset, x, y, width, height); @@ -517,7 +517,7 @@ void Texture3D::allocateMipmap(State& state) const const GLExtensions* extensions = state.get(); // bind texture - textureObject->bind(); + textureObject->bind(state); // compute number of mipmap levels int width = _textureWidth; diff --git a/src/osg/TextureBuffer.cpp b/src/osg/TextureBuffer.cpp index 0201cfe5e..896c73b85 100644 --- a/src/osg/TextureBuffer.cpp +++ b/src/osg/TextureBuffer.cpp @@ -176,7 +176,7 @@ void TextureBuffer::apply(State& state) const _modifiedCount[contextID]=_bufferData->getModifiedCount() ; } - textureObject->bind(); + textureObject->bind(state); if( getTextureParameterDirty(contextID) ) { @@ -200,7 +200,7 @@ void TextureBuffer::apply(State& state) const textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_BUFFER); textureObject->_profile._internalFormat=_internalFormat; - textureObject->bind(); + textureObject->bind(state); if ( extensions->isBindImageTextureSupported() && _imageAttachment.access!=0 ) { @@ -219,7 +219,7 @@ void TextureBuffer::apply(State& state) const textureObject->setAllocated(true); extensions->glBindBuffer(_bufferData->getBufferObject()->getTarget(),0); - textureObject->bind(); + textureObject->bind(state); extensions->glTexBuffer(GL_TEXTURE_BUFFER, _internalFormat, glBufferObject->getGLObjectID()); _modifiedCount[contextID] = _bufferData->getModifiedCount(); } diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp index 6e447e2e8..2571591d0 100644 --- a/src/osg/TextureCubeMap.cpp +++ b/src/osg/TextureCubeMap.cpp @@ -231,7 +231,7 @@ void TextureCubeMap::apply(State& state) const if (textureObject) { - textureObject->bind(); + textureObject->bind(state); if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_CUBE_MAP,state); @@ -257,7 +257,7 @@ void TextureCubeMap::apply(State& state) const { textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_CUBE_MAP); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_CUBE_MAP,state); @@ -288,7 +288,7 @@ void TextureCubeMap::apply(State& state) const textureObject = generateAndAssignTextureObject( contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_CUBE_MAP,state); @@ -330,7 +330,7 @@ void TextureCubeMap::apply(State& state) const textureObject = generateAndAssignTextureObject( contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_CUBE_MAP,state); @@ -395,7 +395,7 @@ void TextureCubeMap::copyTexSubImageCubeMap(State& state, int face, int xoffset, if (textureObject) { // we have a valid image - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_CUBE_MAP, state); @@ -435,7 +435,7 @@ void TextureCubeMap::allocateMipmap(State& state) const if (textureObject && _textureWidth != 0 && _textureHeight != 0) { // bind texture - textureObject->bind(); + textureObject->bind(state); // compute number of mipmap levels int width = _textureWidth; diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index 87dbf6f9c..7a4190c2a 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -193,7 +193,7 @@ void TextureRectangle::apply(State& state) const if (textureObject) { - textureObject->bind(); + textureObject->bind(state); if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_RECTANGLE, state); @@ -215,7 +215,7 @@ void TextureRectangle::apply(State& state) const // we don't have a applyTexImage1D_subload yet so can't reuse.. so just generate a new texture object. textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_RECTANGLE); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_RECTANGLE, state); @@ -245,7 +245,7 @@ void TextureRectangle::apply(State& state) const textureObject = generateAndAssignTextureObject( contextID,GL_TEXTURE_RECTANGLE,1,_internalFormat,_textureWidth,_textureHeight,1,0); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_RECTANGLE, state); @@ -271,7 +271,7 @@ void TextureRectangle::apply(State& state) const textureObject = generateAndAssignTextureObject( contextID,GL_TEXTURE_RECTANGLE,0,_internalFormat,_textureWidth,_textureHeight,1,0); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_RECTANGLE,state); @@ -490,7 +490,7 @@ void TextureRectangle::copyTexImage2D(State& state, int x, int y, int width, int // textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_RECTANGLE); - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_RECTANGLE,state); @@ -524,7 +524,7 @@ void TextureRectangle::copyTexSubImage2D(State& state, int xoffset, int yoffset, if (textureObject) { // we have a valid image - textureObject->bind(); + textureObject->bind(state); applyTexParameters(GL_TEXTURE_RECTANGLE,state);