1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Expand workarounds for format inconsistency with BGRA8888 extension on GLES

fixes #16011
This commit is contained in:
sfan5 2025-04-13 17:20:41 +02:00
parent 37d2bc8a5f
commit cf07b56235
2 changed files with 17 additions and 9 deletions

View file

@ -165,9 +165,8 @@ public:
} }
#ifndef IRR_COMPILE_GL_COMMON #ifndef IRR_COMPILE_GL_COMMON
// On GLES 3.0 we must use sized internal formats for textures in certain // On GLES 3.0 we must use sized internal formats for textures when calling
// cases (e.g. with ETT_2D_MS). However ECF_A8R8G8B8 is mapped to GL_BGRA // glTexStorage. But ECF_A8R8G8B8 might be mapped to GL_BGRA (an unsized format).
// (an unsized format).
// Since we don't upload to RTT we can safely pick a different combo that works. // Since we don't upload to RTT we can safely pick a different combo that works.
if (InternalFormat == GL_BGRA && Driver->Version.Major >= 3) { if (InternalFormat == GL_BGRA && Driver->Version.Major >= 3) {
InternalFormat = GL_RGBA8; InternalFormat = GL_RGBA8;
@ -271,7 +270,7 @@ public:
// For OpenGL an array texture is basically just a 3D texture internally. // For OpenGL an array texture is basically just a 3D texture internally.
// So if we call glGetTexImage() we would download the entire array, // So if we call glGetTexImage() we would download the entire array,
// except the caller only wants a single layer. // except the caller only wants a single layer.
// To do this properly we could have to use glGetTextureSubImage() [4.5] // To do this properly we could use glGetTextureSubImage() [4.5]
// or some trickery with glTextureView() [4.3]. // or some trickery with glTextureView() [4.3].
// Also neither of those will work on GLES. // Also neither of those will work on GLES.
@ -522,10 +521,18 @@ protected:
} }
// reference: <https://www.khronos.org/opengl/wiki/Texture_Storage> // reference: <https://www.khronos.org/opengl/wiki/Texture_Storage>
bool use_tex_storage = Driver->getFeature().TexStorage;
#ifndef IRR_COMPILE_GL_COMMON
// On GLES 3.0 if we don't have a sized format suitable for glTexStorage,
// just avoid using it. Only affects the extension that provides BGRA.
if (InternalFormat == GL_BGRA && Driver->Version.Major >= 3)
use_tex_storage = false;
#endif
switch (Type) { switch (Type) {
case ETT_2D: case ETT_2D:
if (Driver->getFeature().TexStorage) { if (use_tex_storage) {
GL.TexStorage2D(TextureType, levels, InternalFormat, GL.TexStorage2D(TextureType, levels, InternalFormat,
Size.Width, Size.Height); Size.Width, Size.Height);
} else { } else {
@ -541,6 +548,7 @@ protected:
// glTexImage2DMultisample is supported by OpenGL 3.2+ // glTexImage2DMultisample is supported by OpenGL 3.2+
// glTexStorage2DMultisample is supported by OpenGL 4.3+ and OpenGL ES 3.1+ // glTexStorage2DMultisample is supported by OpenGL 4.3+ and OpenGL ES 3.1+
// so pick the most compatible one
#ifdef IRR_COMPILE_GL_COMMON // legacy driver #ifdef IRR_COMPILE_GL_COMMON // legacy driver
constexpr bool use_gl_impl = true; constexpr bool use_gl_impl = true;
#else #else
@ -557,7 +565,7 @@ protected:
case ETT_CUBEMAP: case ETT_CUBEMAP:
for (u32 i = 0; i < 6; i++) { for (u32 i = 0; i < 6; i++) {
GLenum target = getTextureTarget(i); GLenum target = getTextureTarget(i);
if (Driver->getFeature().TexStorage) { if (use_tex_storage) {
GL.TexStorage2D(target, levels, InternalFormat, GL.TexStorage2D(target, levels, InternalFormat,
Size.Width, Size.Height); Size.Width, Size.Height);
} else { } else {
@ -568,7 +576,7 @@ protected:
} }
break; break;
case ETT_2D_ARRAY: case ETT_2D_ARRAY:
if (Driver->getFeature().TexStorage) { if (use_tex_storage) {
GL.TexStorage3D(TextureType, levels, InternalFormat, GL.TexStorage3D(TextureType, levels, InternalFormat,
Size.Width, Size.Height, layers); Size.Width, Size.Height, layers);
} else { } else {

View file

@ -63,8 +63,8 @@ void COpenGLES2Driver::initFeatures()
TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}; TextureFormats[ECF_D24S8] = {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8};
// NOTE a recent (2024) revision of EXT_texture_format_BGRA8888 also // NOTE a recent (2024) revision of EXT_texture_format_BGRA8888 also
// adds a sized format GL_BGRA8_EXT. We have a workaround in place to // adds a sized format GL_BGRA8_EXT. Because we can't rely on that we
// fix up the InternalFormat in case of render targets. // have stupid workarounds in place on texture creation...
if (FeatureAvailable[IRR_GL_EXT_texture_format_BGRA8888] || FeatureAvailable[IRR_GL_APPLE_texture_format_BGRA8888]) if (FeatureAvailable[IRR_GL_EXT_texture_format_BGRA8888] || FeatureAvailable[IRR_GL_APPLE_texture_format_BGRA8888])
TextureFormats[ECF_A8R8G8B8] = {GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE}; TextureFormats[ECF_A8R8G8B8] = {GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE};