From cf07b56235dfd14148f614bf535838023dbef143 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 13 Apr 2025 17:20:41 +0200 Subject: [PATCH] Expand workarounds for format inconsistency with BGRA8888 extension on GLES fixes #16011 --- irr/src/COpenGLCoreTexture.h | 22 +++++++++++++++------- irr/src/OpenGLES2/Driver.cpp | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/irr/src/COpenGLCoreTexture.h b/irr/src/COpenGLCoreTexture.h index 51b122075..ba9ad89c3 100644 --- a/irr/src/COpenGLCoreTexture.h +++ b/irr/src/COpenGLCoreTexture.h @@ -165,9 +165,8 @@ public: } #ifndef IRR_COMPILE_GL_COMMON - // On GLES 3.0 we must use sized internal formats for textures in certain - // cases (e.g. with ETT_2D_MS). However ECF_A8R8G8B8 is mapped to GL_BGRA - // (an unsized format). + // On GLES 3.0 we must use sized internal formats for textures when calling + // glTexStorage. But ECF_A8R8G8B8 might be mapped to GL_BGRA (an unsized format). // Since we don't upload to RTT we can safely pick a different combo that works. if (InternalFormat == GL_BGRA && Driver->Version.Major >= 3) { InternalFormat = GL_RGBA8; @@ -271,7 +270,7 @@ public: // For OpenGL an array texture is basically just a 3D texture internally. // So if we call glGetTexImage() we would download the entire array, // 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]. // Also neither of those will work on GLES. @@ -522,10 +521,18 @@ protected: } // reference: + 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) { case ETT_2D: - if (Driver->getFeature().TexStorage) { + if (use_tex_storage) { GL.TexStorage2D(TextureType, levels, InternalFormat, Size.Width, Size.Height); } else { @@ -541,6 +548,7 @@ protected: // glTexImage2DMultisample is supported by OpenGL 3.2+ // 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 constexpr bool use_gl_impl = true; #else @@ -557,7 +565,7 @@ protected: case ETT_CUBEMAP: for (u32 i = 0; i < 6; i++) { GLenum target = getTextureTarget(i); - if (Driver->getFeature().TexStorage) { + if (use_tex_storage) { GL.TexStorage2D(target, levels, InternalFormat, Size.Width, Size.Height); } else { @@ -568,7 +576,7 @@ protected: } break; case ETT_2D_ARRAY: - if (Driver->getFeature().TexStorage) { + if (use_tex_storage) { GL.TexStorage3D(TextureType, levels, InternalFormat, Size.Width, Size.Height, layers); } else { diff --git a/irr/src/OpenGLES2/Driver.cpp b/irr/src/OpenGLES2/Driver.cpp index 2db021088..84e702a8f 100644 --- a/irr/src/OpenGLES2/Driver.cpp +++ b/irr/src/OpenGLES2/Driver.cpp @@ -63,8 +63,8 @@ void COpenGLES2Driver::initFeatures() 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 - // adds a sized format GL_BGRA8_EXT. We have a workaround in place to - // fix up the InternalFormat in case of render targets. + // adds a sized format GL_BGRA8_EXT. Because we can't rely on that we + // have stupid workarounds in place on texture creation... 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};