opengl: Re-arrange code in GLTexture::upload()
Re-arrange the code so it's easier to set GL_UNPACK_ROW_LENGTH.
This commit is contained in:
parent
def0bde5e9
commit
31adedba3a
1 changed files with 32 additions and 26 deletions
|
@ -547,53 +547,59 @@ std::unique_ptr<GLTexture> GLTexture::upload(const QImage &image)
|
|||
qCWarning(KWIN_OPENGL, "generating OpenGL texture handle failed");
|
||||
return nullptr;
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
const auto context = OpenGlContext::currentContext();
|
||||
GLenum internalFormat;
|
||||
if (!context->isOpenGLES()) {
|
||||
QImage im;
|
||||
GLenum format;
|
||||
GLenum type;
|
||||
|
||||
QImage::Format uploadFormat;
|
||||
if (!context->isOpenGLES()) {
|
||||
const QImage::Format index = image.format();
|
||||
|
||||
if (index < sizeof(formatTable) / sizeof(formatTable[0]) && formatTable[index].internalFormat
|
||||
&& !(formatTable[index].type == GL_UNSIGNED_SHORT && !context->supports16BitTextures())) {
|
||||
internalFormat = formatTable[index].internalFormat;
|
||||
format = formatTable[index].format;
|
||||
type = formatTable[index].type;
|
||||
im = image;
|
||||
uploadFormat = index;
|
||||
} else {
|
||||
im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
internalFormat = GL_RGBA8;
|
||||
format = GL_BGRA;
|
||||
type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
||||
uploadFormat = QImage::Format_ARGB32_Premultiplied;
|
||||
}
|
||||
} else {
|
||||
if (context->supportsARGB32Textures()) {
|
||||
internalFormat = GL_BGRA_EXT;
|
||||
format = GL_BGRA_EXT;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
uploadFormat = QImage::Format_ARGB32_Premultiplied;
|
||||
} else {
|
||||
internalFormat = GL_RGBA;
|
||||
format = GL_RGBA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
uploadFormat = QImage::Format_RGBA8888_Premultiplied;
|
||||
}
|
||||
}
|
||||
|
||||
QImage im = image;
|
||||
if (im.format() != uploadFormat) {
|
||||
im.convertTo(uploadFormat);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
if (!context->isOpenGLES()) {
|
||||
if (context->supportsTextureStorage()) {
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, im.width(), im.height());
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, im.width(), im.height(),
|
||||
format, type, im.constBits());
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, im.width(), im.height(), format, type, im.constBits());
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, im.width(), im.height(), 0,
|
||||
format, type, im.constBits());
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, im.width(), im.height(), 0, format, type, im.constBits());
|
||||
}
|
||||
} else {
|
||||
internalFormat = GL_RGBA8;
|
||||
|
||||
if (context->supportsARGB32Textures()) {
|
||||
const QImage im = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, im.width(), im.height(),
|
||||
0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, im.constBits());
|
||||
} else {
|
||||
const QImage im = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, im.width(), im.height(),
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, im.constBits());
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, im.width(), im.height(), 0, format, type, im.constBits());
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
return std::unique_ptr<GLTexture>(new GLTexture(GL_TEXTURE_2D, texture, internalFormat, image.size(), 1, true, OutputTransform::FlipY));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue