From Ulrich Hertlein, "not sure how severe this is but I believe there's a bug in

Texture.cpp:applyTexImage2D_subload:

<code>
unsigned char* data = = (unsigned char*)image->data();
if (needImageRescale) {
 // allocates rescale buffer
 data = new unsigned char[newTotalSize];

 // calls gluScaleImage into the data buffer
}

const unsigned char* dataPtr = image->data();
// subloads 'dataPtr'

// deletes 'data'
</code>

In effect, the scaled data would never be used.

I've also replaced bits of duplicate code in Texture1D/2D/2DArray/3D/Cubemap/Rectangle
that checks if the texture image can/should be unref'd with common functionality in
Texture.cpp.

"
This commit is contained in:
Robert Osfield
2010-09-14 13:19:55 +00:00
parent d55ada3790
commit 551d2b6479
9 changed files with 34 additions and 54 deletions

View File

@@ -1656,7 +1656,8 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
glPixelStorei(GL_PACK_ALIGNMENT,image->getPacking());
gluScaleImage(image->getPixelFormat(),
image->s(),image->t(),image->getDataType(),image->data(),
inwidth,inheight,image->getDataType(),dataPtr);
inwidth,inheight,image->getDataType(),
dataPtr);
#else
OSG_NOTICE<<"Warning: gluScaleImage(..) not supported, cannot subload image."<<std::endl;
return;
@@ -1868,8 +1869,7 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking());
unsigned char* data = (unsigned char*)image->data();
unsigned char* dataPtr = (unsigned char*)image->data();
bool needImageRescale = inwidth!=image->s() || inheight!=image->t();
if (needImageRescale)
@@ -1888,9 +1888,9 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
}
unsigned int newTotalSize = osg::Image::computeRowWidthInBytes(inwidth,image->getPixelFormat(),image->getDataType(),image->getPacking())*inheight;
data = new unsigned char [newTotalSize];
dataPtr = new unsigned char [newTotalSize];
if (!data)
if (!dataPtr)
{
OSG_WARN<<"Warning:: Not enough memory to resize image, cannot apply to texture."<<std::endl;
return;
@@ -1903,7 +1903,8 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
glPixelStorei(GL_PACK_ALIGNMENT,image->getPacking());
gluScaleImage(image->getPixelFormat(),
image->s(),image->t(),image->getDataType(),image->data(),
inwidth,inheight,image->getDataType(),data);
inwidth,inheight,image->getDataType(),
dataPtr);
#else
OSG_NOTICE<<"Warning: gluScaleImage(..) not supported, cannot subload image."<<std::endl;
return;
@@ -1915,7 +1916,6 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
bool useHardwareMipMapGeneration = mipmappingRequired && (!image->isMipmap() && isHardwareMipmapGenerationEnabled(state));
bool useGluBuildMipMaps = mipmappingRequired && (!useHardwareMipMapGeneration && !image->isMipmap());
const unsigned char* dataPtr = image->data();
GLBufferObject* pbo = image->getOrCreateGLBufferObject(contextID);
if (pbo && !needImageRescale && !useGluBuildMipMaps)
{
@@ -2037,7 +2037,7 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
if (needImageRescale)
{
// clean up the resized image.
delete [] data;
delete [] dataPtr;
}
}