Added shader pipeline support to various Texture subclasses

This commit is contained in:
Robert Osfield 2016-11-22 15:12:56 +00:00
parent 3821f77c35
commit d5e9a2c447
10 changed files with 51 additions and 50 deletions

View File

@ -16,7 +16,7 @@
#include <osg/GL>
#include <osg/Image>
#include <osg/StateAttribute>
#include <osg/TextureAttribute>
#include <osg/GraphicsContext>
#include <osg/ref_ptr>
#include <osg/Vec4>
@ -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; }

View File

@ -245,10 +245,12 @@ Texture::TextureObject::~TextureObject()
// OSG_NOTICE<<"Texture::TextureObject::~TextureObject() "<<this<<std::endl;
}
void Texture::TextureObject::bind()
void Texture::TextureObject::bind(osg::State& state)
{
glBindTexture( _profile._target, _id);
if (_set) _set->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.

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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<GLExtensions>();
// bind texture
textureObject->bind();
textureObject->bind(state);
// compute number of mipmap levels
int width = _textureWidth;

View File

@ -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();
}

View File

@ -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;

View File

@ -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);