From 98a676ef653fc956b375712bc7765e622a6dd2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Jul 2017 00:27:02 +0200 Subject: [PATCH] Internal format should be equal to format on ES2 for tex storage fallback. Fixes a case where passing TextureFormat::RGBA8 to Texture::setStorage() on a platform w/o EXT_texture_storage would emit an error. Now it passes GL_RGBA to both format and internalFormat fields. --- src/Magnum/AbstractTexture.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Magnum/AbstractTexture.cpp b/src/Magnum/AbstractTexture.cpp index 93feeed46..44f4c4f23 100644 --- a/src/Magnum/AbstractTexture.cpp +++ b/src/Magnum/AbstractTexture.cpp @@ -1229,6 +1229,15 @@ void AbstractTexture::storageImplementationFallback(const GLsizei levels, const const PixelFormat format = pixelFormatForInternalFormat(internalFormat); const PixelType type = pixelTypeForInternalFormat(internalFormat); + /* If EXT_texture_storage is not available on ES2, passing e.g. + TextureFormat::RGBA8 would cause an error. On ES2 it's required to have + internalFormat equal to format, so we do exactly that. */ + #ifndef MAGNUM_TARGET_GLES2 + const TextureFormat finalInternalFormat = internalFormat; + #else + const TextureFormat finalInternalFormat = TextureFormat(GLenum(format)); + #endif + /* Common code for classic types */ #ifndef MAGNUM_TARGET_GLES if(_target == GL_TEXTURE_2D || _target == GL_TEXTURE_RECTANGLE) @@ -1237,7 +1246,7 @@ void AbstractTexture::storageImplementationFallback(const GLsizei levels, const #endif { for(GLsizei level = 0; level != levels; ++level) - DataHelper<2>::setImage(*this, level, internalFormat, + DataHelper<2>::setImage(*this, level, finalInternalFormat, ImageView2D{format, type, Math::max(Vector2i(1), size >> level)}); /* Cube map additionally needs to specify all faces */ @@ -1249,7 +1258,7 @@ void AbstractTexture::storageImplementationFallback(const GLsizei levels, const GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}) - DataHelper<2>::setImage(*this, face, level, internalFormat, + DataHelper<2>::setImage(*this, face, level, finalInternalFormat, ImageView2D{format, type, Math::max(Vector2i(1), size >> level)}); } @@ -1298,6 +1307,15 @@ void AbstractTexture::storageImplementationFallback(GLsizei levels, TextureForma const PixelFormat format = pixelFormatForInternalFormat(internalFormat); const PixelType type = pixelTypeForInternalFormat(internalFormat); + /* If EXT_texture_storage is not available on ES2, passing e.g. + TextureFormat::RGBA8 would cause an error. On ES2 it's required to have + internalFormat equal to format, so we do exactly that. */ + #ifndef MAGNUM_TARGET_GLES2 + const TextureFormat finalInternalFormat = internalFormat; + #else + const TextureFormat finalInternalFormat = TextureFormat(GLenum(format)); + #endif + /* Common code for classic type */ #ifndef MAGNUM_TARGET_GLES2 if(_target == GL_TEXTURE_3D) @@ -1305,7 +1323,7 @@ void AbstractTexture::storageImplementationFallback(GLsizei levels, TextureForma if(_target == GL_TEXTURE_3D_OES) #endif for(GLsizei level = 0; level != levels; ++level) - DataHelper<3>::setImage(*this, level, internalFormat, + DataHelper<3>::setImage(*this, level, finalInternalFormat, ImageView3D{format, type, Math::max(Vector3i(1), size >> level)}); #ifndef MAGNUM_TARGET_GLES2