Skip to content

Commit

Permalink
From Fabien Lavignotte, "I use Texture2D::copyTexImage2D to generate …
Browse files Browse the repository at this point in the history
…some textures at each frame on a PagedLOD databases.

There was some performance problems after a long run, because textures created with copyTexImage2D were not reused.
After investigation, there is a problem with the Texture Pool when a texture object is created with an empty profile, and then move after creation to TextureObjectSet with good profile using setAllocated method.
I have just changed a little bit the code of Texture2D::copyTexImage2D, to generate the texture object with the good profile at the start."
  • Loading branch information
robertosfield committed Dec 1, 2010
1 parent 9c0e56d commit 78b15f8
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/osg/Texture2D.cpp
Expand Up @@ -337,13 +337,7 @@ void Texture2D::copyTexImage2D(State& state, int x, int y, int width, int height

// switch off mip-mapping.
//
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_2D);

textureObject->bind();

applyTexParameters(GL_TEXTURE_2D,state);



bool needHardwareMipMap = (_min_filter != LINEAR && _min_filter != NEAREST);
bool hardwareMipMapOn = false;
if (needHardwareMipMap)
Expand All @@ -357,12 +351,6 @@ void Texture2D::copyTexImage2D(State& state, int x, int y, int width, int height
_min_filter = LINEAR;
}
}

GenerateMipmapMode mipmapResult = mipmapBeforeTexImage(state, hardwareMipMapOn);

glCopyTexImage2D( GL_TEXTURE_2D, 0, _internalFormat, x, y, width, height, 0 );

mipmapAfterTexImage(state, mipmapResult);

_textureWidth = width;
_textureHeight = height;
Expand All @@ -373,7 +361,20 @@ void Texture2D::copyTexImage2D(State& state, int x, int y, int width, int height
for(int s=1; s<width || s<height; s <<= 1, ++_numMipmapLevels) {}
}

textureObject->setAllocated(_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(this, contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);

textureObject->bind();

applyTexParameters(GL_TEXTURE_2D,state);


GenerateMipmapMode mipmapResult = mipmapBeforeTexImage(state, hardwareMipMapOn);

glCopyTexImage2D( GL_TEXTURE_2D, 0, _internalFormat, x, y, width, height, 0 );

mipmapAfterTexImage(state, mipmapResult);

textureObject->setAllocated(true);

// inform state that this texture is the current one bound.
state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this);
Expand Down

0 comments on commit 78b15f8

Please sign in to comment.