opengl: Set GL_UNPACK_ROW_LENGTH in GLTexture::upload()
The image stride can be other than "width * bpp". In order to properly handle such a case, we need to set GL_UNPACK_ROW_LENGTH to skip the right amount of pixels between consecutive rows. Co-authored-by: Gabriel Souza Franco <gabrielfrancosouza@gmail.com>
This commit is contained in:
parent
31adedba3a
commit
f3406a033c
1 changed files with 2 additions and 0 deletions
|
@ -587,6 +587,7 @@ std::unique_ptr<GLTexture> GLTexture::upload(const QImage &image)
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, im.bytesPerLine() / (im.depth() / 8));
|
||||||
if (!context->isOpenGLES()) {
|
if (!context->isOpenGLES()) {
|
||||||
if (context->supportsTextureStorage()) {
|
if (context->supportsTextureStorage()) {
|
||||||
glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, im.width(), im.height());
|
glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, im.width(), im.height());
|
||||||
|
@ -598,6 +599,7 @@ std::unique_ptr<GLTexture> GLTexture::upload(const QImage &image)
|
||||||
} else {
|
} else {
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
return std::unique_ptr<GLTexture>(new GLTexture(GL_TEXTURE_2D, texture, internalFormat, image.size(), 1, true, OutputTransform::FlipY));
|
return std::unique_ptr<GLTexture>(new GLTexture(GL_TEXTURE_2D, texture, internalFormat, image.size(), 1, true, OutputTransform::FlipY));
|
||||||
|
|
Loading…
Reference in a new issue