Check if drivers support BGRA texture format and fallback to RGBA

This commit is contained in:
Deve 2016-09-11 22:32:27 +02:00
parent fb1c049906
commit b0c0af8c46
5 changed files with 48 additions and 4 deletions

View File

@ -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();

View File

@ -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

View File

@ -57,6 +57,9 @@ namespace GraphicsRestrictions
"TextureCompressionS3TC",
"AMDVertexShaderLayer",
"ExplicitAttribLocation",
#if defined(USE_GLES2)
"TextureFormatBGRA8888",
#endif
"DriverRecentEnough",
"HighDefinitionTextures",
"AdvancedPipeline",

View File

@ -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,

View File

@ -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)
{