From Jannik Heller, "I have added new functions Texture::generateAndAssignTextureObject mirroring the Texture::generateTextureObject functions.

I have left the Texture::generateTextureObject functions intact as I'm not sure if/how it's used outside the core OSG. If you feel that compatibility isn't important in that area feel free to drop it.

While testing the build with OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION=OFF I found a compile error in GlyphGeometry.cpp that was entirely unrelated to the changes I've made. The fix is included in the patch.

There is one thing left to fix and that is Texture2D::SubloadCallback:

        class OSG_EXPORT SubloadCallback : public Referenced
        {
            public:
                ....
                virtual TextureObject* generateTextureObject(const Texture2D& texture, State& state) const
                {
                    return osg::Texture::generateTextureObject(&texture, state.getContextID(), GL_TEXTURE_2D);
                }
                ...
         }"
         


git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14879 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2015-06-01 10:50:44 +00:00
parent 44c406e167
commit 78a01ce2a5
12 changed files with 79 additions and 59 deletions

View File

@@ -1101,8 +1101,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute
void discardAllDeletedTextureObjects();
void flushDeletedTextureObjects(double currentTime, double& availableTime);
TextureObject* takeFromOrphans(Texture* texture);
TextureObject* takeOrGenerate(Texture* texture);
osg::ref_ptr<TextureObject> takeFromOrphans(Texture* texture);
osg::ref_ptr<TextureObject> takeOrGenerate(Texture* texture);
void moveToBack(TextureObject* to);
void addToBack(TextureObject* to);
void orphan(TextureObject* to);
@@ -1167,8 +1167,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute
bool hasSpace(unsigned int size) const { return (_currTexturePoolSize+size)<=_maxTexturePoolSize; }
bool makeSpace(unsigned int size);
TextureObject* generateTextureObject(const Texture* texture, GLenum target);
TextureObject* generateTextureObject(const Texture* texture,
osg::ref_ptr<TextureObject> generateTextureObject(const Texture* texture, GLenum target);
osg::ref_ptr<TextureObject> generateTextureObject(const Texture* texture,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,
@@ -1231,9 +1231,9 @@ class OSG_EXPORT Texture : public osg::StateAttribute
static osg::ref_ptr<Texture::TextureObjectManager>& getTextureObjectManager(unsigned int contextID);
static TextureObject* generateTextureObject(const Texture* texture, unsigned int contextID,GLenum target);
static osg::ref_ptr<TextureObject> generateTextureObject(const Texture* texture, unsigned int contextID,GLenum target);
static TextureObject* generateTextureObject(const Texture* texture,
static osg::ref_ptr<TextureObject> generateTextureObject(const Texture* texture,
unsigned int contextID,
GLenum target,
GLint numMipmapLevels,
@@ -1243,6 +1243,17 @@ class OSG_EXPORT Texture : public osg::StateAttribute
GLsizei depth,
GLint border);
TextureObject* generateAndAssignTextureObject(unsigned int contextID, GLenum target) const;
TextureObject* generateAndAssignTextureObject(unsigned int contextID,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border) const;
static void deleteAllTextureObjects(unsigned int contextID);
static void discardAllTextureObjects(unsigned int contextID);
static void flushAllDeletedTextureObjects(unsigned int contextID);

View File

@@ -95,7 +95,7 @@ class OSG_EXPORT Texture2D : public Texture
virtual TextureObject* generateTextureObject(const Texture2D& texture, State& state) const
{
return osg::Texture::generateTextureObject(&texture, state.getContextID(), GL_TEXTURE_2D);
return osg::Texture::generateTextureObject(&texture, state.getContextID(), GL_TEXTURE_2D).release();
}
virtual void load(const Texture2D& texture,State& state) const = 0;

View File

@@ -680,7 +680,7 @@ bool Texture::TextureObjectSet::makeSpace(unsigned int& size)
return size==0;
}
Texture::TextureObject* Texture::TextureObjectSet::takeFromOrphans(Texture* texture)
osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectSet::takeFromOrphans(Texture* texture)
{
// take front of orphaned list.
ref_ptr<TextureObject> to = _orphanedTextureObjects.front();
@@ -700,11 +700,11 @@ Texture::TextureObject* Texture::TextureObjectSet::takeFromOrphans(Texture* text
OSG_INFO<<"Reusing orphaned TextureObject, _numOfTextureObjects="<<_numOfTextureObjects<<std::endl;
return to.release();
return to;
}
Texture::TextureObject* Texture::TextureObjectSet::takeOrGenerate(Texture* texture)
osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectSet::takeOrGenerate(Texture* texture)
{
// see if we can recyle TextureObject from the orphan list
{
@@ -752,7 +752,7 @@ Texture::TextureObject* Texture::TextureObjectSet::takeOrGenerate(Texture* textu
// assign to new texture
to->setTexture(texture);
return to.release();
return to;
}
//
@@ -761,7 +761,7 @@ Texture::TextureObject* Texture::TextureObjectSet::takeOrGenerate(Texture* textu
GLuint id;
glGenTextures( 1L, &id );
TextureObject* to = new Texture::TextureObject(const_cast<Texture*>(texture),id,_profile);
osg::ref_ptr<TextureObject> to = new Texture::TextureObject(const_cast<Texture*>(texture),id,_profile);
to->_set = this;
++_numOfTextureObjects;
@@ -769,7 +769,7 @@ Texture::TextureObject* Texture::TextureObjectSet::takeOrGenerate(Texture* textu
_parent->getCurrTexturePoolSize() += _profile._size;
_parent->getNumberActiveTextureObjects() += 1;
addToBack(to);
addToBack(to.get());
OSG_INFO<<"Created new " << this << " TextureObject, _numOfTextureObjects "<<_numOfTextureObjects<<std::endl;
@@ -990,12 +990,12 @@ bool Texture::TextureObjectManager::makeSpace(unsigned int size)
}
Texture::TextureObject* Texture::TextureObjectManager::generateTextureObject(const Texture* texture, GLenum target)
osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectManager::generateTextureObject(const Texture* texture, GLenum target)
{
return generateTextureObject(texture, target, 0, 0, 0, 0, 0, 0);
}
Texture::TextureObject* Texture::TextureObjectManager::generateTextureObject(const Texture* texture,
osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectManager::generateTextureObject(const Texture* texture,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,
@@ -1012,6 +1012,26 @@ Texture::TextureObject* Texture::TextureObjectManager::generateTextureObject(con
return tos->takeOrGenerate(const_cast<Texture*>(texture));
}
Texture::TextureObject* Texture::generateAndAssignTextureObject(unsigned int contextID, GLenum target) const
{
_textureObjectBuffer[contextID] = generateTextureObject(this, contextID, target);
return _textureObjectBuffer[contextID].get();
}
Texture::TextureObject* Texture::generateAndAssignTextureObject(
unsigned int contextID,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border) const
{
_textureObjectBuffer[contextID] = generateTextureObject(this, contextID, target, numMipmapLevels, internalFormat, width, height, depth, border);
return _textureObjectBuffer[contextID].get();
}
Texture::TextureObjectSet* Texture::TextureObjectManager::getTextureObjectSet(const TextureProfile& profile)
{
osg::ref_ptr<Texture::TextureObjectSet>& tos = _textureSetMap[profile];
@@ -1203,12 +1223,12 @@ osg::ref_ptr<Texture::TextureObjectManager>& Texture::getTextureObjectManager(un
}
Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, unsigned int contextID, GLenum target)
osg::ref_ptr<Texture::TextureObject> Texture::generateTextureObject(const Texture* texture, unsigned int contextID, GLenum target)
{
return getTextureObjectManager(contextID)->generateTextureObject(texture, target);
}
Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, unsigned int contextID,
osg::ref_ptr<Texture::TextureObject> Texture::generateTextureObject(const Texture* texture, unsigned int contextID,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,

View File

@@ -183,7 +183,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.
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID, GL_TEXTURE_1D);
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D);
textureObject->bind();
@@ -204,7 +204,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 = generateTextureObject(this, contextID,GL_TEXTURE_1D);
textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_1D);
textureObject->bind();
@@ -229,8 +229,7 @@ void Texture1D::apply(State& state) const
}
else if ( (_textureWidth!=0) && (_internalFormat!=0) )
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
this,contextID,GL_TEXTURE_1D,_numMipmapLevels,_internalFormat,_textureWidth,1,1,0);
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D,_numMipmapLevels,_internalFormat,_textureWidth,1,1,0);
textureObject->bind();
@@ -418,7 +417,7 @@ void Texture1D::copyTexImage1D(State& state, int x, int y, int width)
_min_filter = LINEAR;
_mag_filter = LINEAR;
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_1D);
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D);
textureObject->bind();

View File

@@ -251,8 +251,7 @@ void Texture2D::apply(State& state) const
// compute the dimensions of the texture.
computeRequiredTextureDimensions(state,*image,_textureWidth, _textureHeight, _numMipmapLevels);
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth);
textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth);
textureObject->bind();
@@ -292,8 +291,7 @@ void Texture2D::apply(State& state) const
}
else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) )
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth);
textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth);
textureObject->bind();
@@ -390,7 +388,7 @@ void Texture2D::copyTexImage2D(State& state, int x, int y, int width, int height
for(int s=1; s<width || s<height; s <<= 1, ++_numMipmapLevels) {}
}
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject->bind();

View File

@@ -315,7 +315,7 @@ void Texture2DArray::apply(State& state) const
else if (_subloadCallback.valid())
{
// generate texture (i.e. glGenTexture) and apply parameters
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID, GL_TEXTURE_2D_ARRAY_EXT);
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D_ARRAY_EXT);
textureObject->bind();
applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT, state);
_subloadCallback->load(*this,state);
@@ -333,15 +333,13 @@ void Texture2DArray::apply(State& state) const
computeRequiredTextureDimensions(state,*_images[0],_textureWidth, _textureHeight, _numMipmapLevels);
// create texture object
textureObject = generateTextureObject(
this, contextID, GL_TEXTURE_2D_ARRAY_EXT,_numMipmapLevels, _internalFormat, _textureWidth, _textureHeight, textureDepth,0);
textureObject = generateAndAssignTextureObject(
contextID, GL_TEXTURE_2D_ARRAY_EXT,_numMipmapLevels, _internalFormat, _textureWidth, _textureHeight, textureDepth,0);
// bind texture
textureObject->bind();
applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT, state);
_textureObjectBuffer[contextID] = textureObject;
// First we need to allocate the texture memory
int sourceFormat = _sourceFormat ? _sourceFormat : _internalFormat;
@@ -426,8 +424,8 @@ void Texture2DArray::apply(State& state) const
else if ( (_textureWidth > 0) && (_textureHeight > 0) && (_textureDepth > 0) && (_internalFormat!=0) )
{
// generate texture
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
this, contextID, GL_TEXTURE_2D_ARRAY_EXT,_numMipmapLevels,_internalFormat, _textureWidth, _textureHeight, _textureDepth,0);
textureObject = generateAndAssignTextureObject(
contextID, GL_TEXTURE_2D_ARRAY_EXT,_numMipmapLevels,_internalFormat, _textureWidth, _textureHeight, _textureDepth,0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state);

View File

@@ -106,8 +106,7 @@ void Texture2DMultisample::apply(State& state) const
}
else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_numSamples!=0) )
{
_textureObjectBuffer[contextID] = textureObject =
generateTextureObject( this,
textureObject = generateAndAssignTextureObject(
contextID,
getTextureTarget(),
1,

View File

@@ -265,7 +265,7 @@ void Texture3D::apply(State& state) const
else if (_subloadCallback.valid())
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_3D);
textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_3D);
textureObject->bind();
@@ -291,7 +291,7 @@ void Texture3D::apply(State& state) const
// compute the dimensions of the texture.
computeRequiredTextureDimensions(state,*_image,_textureWidth, _textureHeight, _textureDepth,_numMipmapLevels);
textureObject = generateTextureObject(this, contextID,GL_TEXTURE_3D);
textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_3D);
textureObject->bind();
@@ -305,8 +305,6 @@ void Texture3D::apply(State& state) const
// update the modified count to show that it is upto date.
getModifiedCount(contextID) = _image->getModifiedCount();
_textureObjectBuffer[contextID] = textureObject;
// unref image data?
if (isSafeToUnrefImageData(state) && _image->getDataVariance()==STATIC)
{
@@ -317,8 +315,8 @@ void Texture3D::apply(State& state) const
}
else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_textureDepth!=0) && (_internalFormat!=0) )
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
this, contextID,GL_TEXTURE_3D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0);
textureObject = generateAndAssignTextureObject(
contextID,GL_TEXTURE_3D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0);
textureObject->bind();

View File

@@ -135,8 +135,7 @@ void TextureBuffer::apply(State& state) const
}
else if (_image.valid() && _image->data())
{
textureObject = generateTextureObject(this, contextID, GL_TEXTURE_BUFFER);
_textureObjectBuffer[contextID] = textureObject;
textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_BUFFER);
textureObject->bind();
textureBufferObject = new TextureBufferObject(contextID,_usageHint);

View File

@@ -259,7 +259,7 @@ void TextureCubeMap::apply(State& state) const
}
else if (_subloadCallback.valid())
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_CUBE_MAP);
textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_CUBE_MAP);
textureObject->bind();
@@ -289,8 +289,8 @@ void TextureCubeMap::apply(State& state) const
_textureWidth = _textureHeight = minimum( _textureWidth , _textureHeight );
}
textureObject = generateTextureObject(
this, contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject = generateAndAssignTextureObject(
contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject->bind();
@@ -315,8 +315,6 @@ void TextureCubeMap::apply(State& state) const
}
_textureObjectBuffer[contextID] = textureObject;
// unref image data?
if (isSafeToUnrefImageData(state))
{
@@ -333,8 +331,8 @@ void TextureCubeMap::apply(State& state) const
}
else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) )
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
this, contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject = generateAndAssignTextureObject(
contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject->bind();

View File

@@ -218,7 +218,7 @@ void TextureRectangle::apply(State& state) const
else if (_subloadCallback.valid())
{
// we don't have a applyTexImage1D_subload yet so can't reuse.. so just generate a new texture object.
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_RECTANGLE);
textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_RECTANGLE);
textureObject->bind();
@@ -247,8 +247,8 @@ void TextureRectangle::apply(State& state) const
_textureWidth = image->s();
_textureHeight = image->t();
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
this, contextID,GL_TEXTURE_RECTANGLE,1,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject = generateAndAssignTextureObject(
contextID,GL_TEXTURE_RECTANGLE,1,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject->bind();
@@ -273,8 +273,8 @@ void TextureRectangle::apply(State& state) const
}
else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) )
{
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
this, contextID,GL_TEXTURE_RECTANGLE,0,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject = generateAndAssignTextureObject(
contextID,GL_TEXTURE_RECTANGLE,0,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject->bind();
@@ -493,7 +493,7 @@ void TextureRectangle::copyTexImage2D(State& state, int x, int y, int width, int
// switch off mip-mapping.
//
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_RECTANGLE);
textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_RECTANGLE);
textureObject->bind();

View File

@@ -186,8 +186,8 @@ void GlyphTexture::apply(osg::State& state) const
// being bound for the first time, need to allocate the texture
_textureObjectBuffer[contextID] = textureObject = osg::Texture::generateTextureObject(
this, contextID, GL_TEXTURE_2D, 1, OSGTEXT_GLYPH_INTERNALFORMAT, getTextureWidth(), getTextureHeight(), 1, 0);
textureObject = osg::Texture::generateAndAssignTextureObject(
contextID, GL_TEXTURE_2D, 1, OSGTEXT_GLYPH_INTERNALFORMAT, getTextureWidth(), getTextureHeight(), 1, 0);
textureObject->bind();