Skip to content
Browse files

changed: improved gles performance by avoiding bgra->rgba convert for…

… textures

Previously, bgra textures were uploaded as rgba then converted back in
shaders. Instead, check for the existance of BGRA extensions and convert
on upload instead. If no extension is found, convert in software before
uploading.

This allows us to remove the swizzle in our shaders, which amounts to a
significant performance gain.
  • Loading branch information...
1 parent 972791b commit bef5be15420f5f5e2c3a7de6fa54d4d9d69c7e08 theuni committed Jul 9, 2011
View
2 system/shaders/guishader_frag_multi.glsl
@@ -28,5 +28,5 @@ varying vec4 m_cord1;
// SM_MULTI shader
void main ()
{
- gl_FragColor.rgba = (texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy)).bgra;
+ gl_FragColor.rgba = (texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy)).rgba;
}
View
2 system/shaders/guishader_frag_multi_blendcolor.glsl
@@ -29,5 +29,5 @@ varying lowp vec4 m_colour;
// SM_MULTI shader
void main ()
{
- gl_FragColor.rgba = (texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy)).bgra * m_colour;
+ gl_FragColor.rgba = (texture2D(m_samp0, m_cord0.xy) * texture2D(m_samp1, m_cord1.xy)).rgba * m_colour;
}
View
2 system/shaders/guishader_frag_texture.glsl
@@ -27,5 +27,5 @@ varying lowp vec4 m_colour;
// SM_TEXTURE shader
void main ()
{
- gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).bgra * m_colour);
+ gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba * m_colour);
}
View
2 system/shaders/guishader_frag_texture_noblend.glsl
@@ -26,5 +26,5 @@ varying vec4 m_cord0;
// SM_TEXTURE_NOBLEND shader
void main ()
{
- gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).bgra);
+ gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba);
}
View
32 xbmc/guilib/TextureGL.cpp
@@ -60,7 +60,6 @@ void CGLTexture::LoadToGPU()
// nothing to load - probably same image (no change)
return;
}
-
if (m_texture == 0)
{
// Have OpenGL generate a texture object handle for us
@@ -128,13 +127,30 @@ void CGLTexture::LoadToGPU()
m_textureWidth = maxSize;
}
-#if HAS_GLES == 1
- glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, m_textureWidth, m_textureHeight, 0,
- GL_BGRA_EXT, GL_UNSIGNED_BYTE, m_pixels);
-#elif HAS_GLES == 2
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_textureWidth, m_textureHeight, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, m_pixels);
-#endif
+ // All incoming textures are BGRA, which GLES does not necessarily support.
+ // Some (most?) hardware supports BGRA textures via an extension.
+ // If not, we convert to RGBA first to avoid having to swizzle in shaders.
+ GLint internalformat;
+ GLenum pixelformat;
+ if (g_Windowing.SupportsBGRA())
+ {
+ internalformat = pixelformat = GL_BGRA_EXT;
+ }
+ else if (g_Windowing.SupportsBGRAApple())
+ {
+ // Apple's implementation does not conform to spec. Instead, they require
+ // differing format/internalformat, more like GL.
+ internalformat = GL_RGBA;
+ pixelformat = GL_BGRA_EXT;
+ }
+ else
+ {
+ SwapBlueRed(m_pixels, m_textureHeight, GetPitch());
+ internalformat = pixelformat = GL_RGBA;
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, 0, internalformat, m_textureWidth, m_textureHeight, 0,
+ pixelformat, GL_UNSIGNED_BYTE, m_pixels);
#endif
VerifyGLState();

0 comments on commit bef5be1

Please sign in to comment.
Something went wrong with that request. Please try again.