StelQGLTextureBackend.cpp   StelQGLTextureBackend.cpp 
skipping to change at line 116 skipping to change at line 116
} }
if (loader != NULL) if (loader != NULL)
{ {
loader->abort(); loader->abort();
// Don't forget that the loader has no parent. // Don't forget that the loader has no parent.
loader->deleteLater(); loader->deleteLater();
loader = NULL; loader = NULL;
} }
} }
// Texture creation requires a texture bind.
//
// If the user has bound a StelTextureNew _and_ tries to create a new textu
re,
// the new texture is bound during creation and we must rebind the "officia
lly"
// bound texture so the user can continue to use their bound texture.
//
// During texture creation, we bind the texture to texture unit 0, so we on
ly need
// to keep track of the texture currently bound to this texture unit.
static GLuint textureBoundToTextureUnit0_ = 0;
void StelQGLTextureBackend::bind(const int textureUnit) void StelQGLTextureBackend::bind(const int textureUnit)
{ {
invariant(); invariant();
Q_ASSERT_X(textureUnit >= 0, Q_FUNC_INFO, Q_ASSERT_X(textureUnit >= 0, Q_FUNC_INFO,
"Trying to bind to a texture unit with negative index"); "Trying to bind to a texture unit with negative index");
renderer->makeGLContextCurrent(); renderer->makeGLContextCurrent();
QGLFunctions& gl = renderer->getGLFunctions(); QGLFunctions& gl = renderer->getGLFunctions();
gl.glActiveTexture(GL_TEXTURE0 + textureUnit); gl.glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_2D, glTextureID); glBindTexture(GL_TEXTURE_2D, glTextureID);
if(textureUnit == 0)
{
textureBoundToTextureUnit0_ = glTextureID;
}
invariant(); invariant();
} }
void StelQGLTextureBackend::startAsynchronousLoading() void StelQGLTextureBackend::startAsynchronousLoading()
{ {
invariant(); invariant();
startedLoading(); startedLoading();
bool http = path.startsWith("http://"); bool http = path.startsWith("http://");
bool pvr = path.endsWith(".pvr"); bool pvr = path.endsWith(".pvr");
skipping to change at line 323 skipping to change at line 337
"backend only supports power-of-two dime nsions"); "backend only supports power-of-two dime nsions");
return result; return result;
} }
result->prepareContextForLoading(); result->prepareContextForLoading();
// Create the GL texture object. // Create the GL texture object.
GLuint glTextureID; GLuint glTextureID;
// According to GL docs, this always succeeds. // According to GL docs, this always succeeds.
glGenTextures(1, &glTextureID); glGenTextures(1, &glTextureID);
// Creating textures always on texture unit 0.
QGLFunctions& gl = renderer->getGLFunctions();
gl.glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, glTextureID); glBindTexture(GL_TEXTURE_2D, glTextureID);
// Set texture parameters. // Set texture parameters.
switch(params.filteringMode) switch(params.filteringMode)
{ {
case TextureFiltering_Nearest: case TextureFiltering_Nearest:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_NEAREST);
break; break;
case TextureFiltering_Linear: case TextureFiltering_Linear:
skipping to change at line 376 skipping to change at line 393
checkGLErrors("fromRawData() before texture data upload"); checkGLErrors("fromRawData() before texture data upload");
// Upload the texture // Upload the texture
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, size.width(), size.he ight(), 0, glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, size.width(), size.he ight(), 0,
loadFormat, type, data); loadFormat, type, data);
// Check for errors during upload. // Check for errors during upload.
const GLenum glError = glGetError(); const GLenum glError = glGetError();
if(glError == GL_INVALID_VALUE) if(glError == GL_INVALID_VALUE)
{ {
glDeleteTextures(1, &glTextureID); glDeleteTextures(1, &glTextureID);
glBindTexture(GL_TEXTURE_2D, textureBoundToTextureUnit0_);
result->errorOccured("fromRawData(): Failed with GL_INVALID_ VALUE, " result->errorOccured("fromRawData(): Failed with GL_INVALID_ VALUE, "
"maybe the texture is too big?"); "maybe the texture is too big?");
return result; return result;
} }
if(glError != GL_NO_ERROR) if(glError != GL_NO_ERROR)
{ {
glDeleteTextures(1, &glTextureID); glDeleteTextures(1, &glTextureID);
glBindTexture(GL_TEXTURE_2D, textureBoundToTextureUnit0_);
result->errorOccured("fromRawData(): Failed with an unknown error. " result->errorOccured("fromRawData(): Failed with an unknown error. "
"NOTE: THIS IS EITHER A BUG IN CODE (FO RMAT MISMATCH?) " "NOTE: THIS IS EITHER A BUG IN CODE (FO RMAT MISMATCH?) "
"THAT NEEDS TO BE FIXED OR A NEW ERROR CONDITION THAT " "THAT NEEDS TO BE FIXED OR A NEW ERROR CONDITION THAT "
"NEEDS AN APPROPRIATE ERROR MESSAGE"); "NEEDS AN APPROPRIATE ERROR MESSAGE");
return result; return result;
} }
renderer->getStatistics()[ESTIMATED_TEXTURE_MEMORY] renderer->getStatistics()[ESTIMATED_TEXTURE_MEMORY]
+= size.width() * size.height() * result->pixelBytes; += size.width() * size.height() * result->pixelBytes;
// Finish constructing the texture. // Finish constructing the texture.
result->setTextureWrapping(); result->setTextureWrapping();
result->glTextureID = glTextureID; result->glTextureID = glTextureID;
result->deleteManually = true; result->deleteManually = true;
result->finishedLoading(size); result->finishedLoading(size);
glBindTexture(GL_TEXTURE_2D, textureBoundToTextureUnit0_);
return result; return result;
} }
void StelQGLTextureBackend::onImageLoaded(QImage image) void StelQGLTextureBackend::onImageLoaded(QImage image)
{ {
invariant(); invariant();
Q_ASSERT_X(!image.isNull(), Q_FUNC_INFO, Q_ASSERT_X(!image.isNull(), Q_FUNC_INFO,
"onImageLoaded slot was called even though the image fail ed to load"); "onImageLoaded slot was called even though the image fail ed to load");
 End of changes. 6 change blocks. 
0 lines changed or deleted 23 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/