diff --git a/src/graphics/central_settings.cpp b/src/graphics/central_settings.cpp index 13c743d28..3712cf008 100644 --- a/src/graphics/central_settings.cpp +++ b/src/graphics/central_settings.cpp @@ -49,6 +49,10 @@ void CentralVideoSettings::init() hasUBO = false; hasExplicitAttribLocation = false; hasGS = false; + +#if defined(USE_GLES2) + hasBGRA = false; +#endif m_GI_has_artifact = false; m_need_rh_workaround = false; @@ -218,6 +222,15 @@ void CentralVideoSettings::init() hasAtomics = true; hasSSBO = true; } + + if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_TEXTURE_FORMAT_BGRA8888) && + (hasGLExtension("GL_IMG_texture_format_BGRA8888") || + hasGLExtension("GL_EXT_texture_format_BGRA8888"))) + { + hasBGRA = true; + Log::info("GLDriver", "EXT texture format BGRA8888 Present"); + } + #endif } } @@ -337,6 +350,13 @@ bool CentralVideoSettings::isARBMultiDrawIndirectUsable() const return hasMultiDrawIndirect; } +#if defined(USE_GLES2) +bool CentralVideoSettings::isEXTTextureFormatBGRA8888Usable() const +{ + return hasBGRA; +} +#endif + bool CentralVideoSettings::supportsShadows() const { return isARBGeometryShadersUsable() && isARBUniformBufferObjectUsable() && isARBExplicitAttribLocationUsable(); diff --git a/src/graphics/central_settings.hpp b/src/graphics/central_settings.hpp index 059840ebf..3553d7775 100644 --- a/src/graphics/central_settings.hpp +++ b/src/graphics/central_settings.hpp @@ -42,6 +42,10 @@ private: bool hasSSBO; bool hasImageLoadStore; bool hasMultiDrawIndirect; + +#if defined(USE_GLES2) + bool hasBGRA; +#endif bool m_need_rh_workaround; bool m_need_srgb_workaround; @@ -75,6 +79,10 @@ public: bool isARBImageLoadStoreUsable() const; bool isARBMultiDrawIndirectUsable() const; bool isARBExplicitAttribLocationUsable() const; + +#if defined(USE_GLES2) + bool isEXTTextureFormatBGRA8888Usable() const; +#endif // Are all required extensions available for feature support diff --git a/src/graphics/graphics_restrictions.cpp b/src/graphics/graphics_restrictions.cpp index cf624eafd..d660748b5 100644 --- a/src/graphics/graphics_restrictions.cpp +++ b/src/graphics/graphics_restrictions.cpp @@ -57,6 +57,9 @@ namespace GraphicsRestrictions "TextureCompressionS3TC", "AMDVertexShaderLayer", "ExplicitAttribLocation", +#if defined(USE_GLES2) + "TextureFormatBGRA8888", +#endif "DriverRecentEnough", "HighDefinitionTextures", "AdvancedPipeline", diff --git a/src/graphics/graphics_restrictions.hpp b/src/graphics/graphics_restrictions.hpp index 0f0038459..c17acf466 100644 --- a/src/graphics/graphics_restrictions.hpp +++ b/src/graphics/graphics_restrictions.hpp @@ -51,6 +51,9 @@ namespace GraphicsRestrictions GR_EXT_TEXTURE_COMPRESSION_S3TC, GR_AMD_VERTEX_SHADER_LAYER, GR_EXPLICIT_ATTRIB_LOCATION, +#if defined(USE_GLES2) + GR_TEXTURE_FORMAT_BGRA8888, +#endif GR_DRIVER_RECENT_ENOUGH, GR_HIGHDEFINITION_TEXTURES, GR_ADVANCED_PIPELINE, diff --git a/src/graphics/texture_manager.cpp b/src/graphics/texture_manager.cpp index 4ddc71cf2..2fed716c1 100644 --- a/src/graphics/texture_manager.cpp +++ b/src/graphics/texture_manager.cpp @@ -87,10 +87,20 @@ void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha) memcpy(data, tex->lock(), w * h * 4); tex->unlock(); unsigned internalFormat, Format; - if (tex->hasAlpha()) - Format = GL_BGRA; - else - Format = GL_BGR; + Format = tex->hasAlpha() ? GL_BGRA : GL_BGR; +#if defined(USE_GLES2) + if (!CVS->isEXTTextureFormatBGRA8888Usable()) + { + Format = tex->hasAlpha() ? GL_RGBA : GL_RGB; + + for (unsigned int i = 0; i < w * h; i++) + { + char tmp_val = data[i*4]; + data[i*4] = data[i*4 + 2]; + data[i*4 + 2] = tmp_val; + } + } +#endif if (premul_alpha) {