Skip to content

Commit

Permalink
changed: improved gles performance by avoiding bgra->rgba convert for…
Browse files Browse the repository at this point in the history
… 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
theuni committed Jul 9, 2011
1 parent 972791b commit bef5be1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion system/shaders/guishader_frag_multi.glsl
Expand Up @@ -28,5 +28,5 @@ varying vec4 m_cord1;
// SM_MULTI shader // SM_MULTI shader
void main () 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;
} }
2 changes: 1 addition & 1 deletion system/shaders/guishader_frag_multi_blendcolor.glsl
Expand Up @@ -29,5 +29,5 @@ varying lowp vec4 m_colour;
// SM_MULTI shader // SM_MULTI shader
void main () 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;
} }
2 changes: 1 addition & 1 deletion system/shaders/guishader_frag_texture.glsl
Expand Up @@ -27,5 +27,5 @@ varying lowp vec4 m_colour;
// SM_TEXTURE shader // SM_TEXTURE shader
void main () 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);
} }
2 changes: 1 addition & 1 deletion system/shaders/guishader_frag_texture_noblend.glsl
Expand Up @@ -26,5 +26,5 @@ varying vec4 m_cord0;
// SM_TEXTURE_NOBLEND shader // SM_TEXTURE_NOBLEND shader
void main () void main ()
{ {
gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).bgra); gl_FragColor.rgba = vec4(texture2D(m_samp0, m_cord0.xy).rgba);
} }
32 changes: 24 additions & 8 deletions xbmc/guilib/TextureGL.cpp
Expand Up @@ -60,7 +60,6 @@ void CGLTexture::LoadToGPU()
// nothing to load - probably same image (no change) // nothing to load - probably same image (no change)
return; return;
} }

if (m_texture == 0) if (m_texture == 0)
{ {
// Have OpenGL generate a texture object handle for us // Have OpenGL generate a texture object handle for us
Expand Down Expand Up @@ -128,13 +127,30 @@ void CGLTexture::LoadToGPU()
m_textureWidth = maxSize; m_textureWidth = maxSize;
} }


#if HAS_GLES == 1 // All incoming textures are BGRA, which GLES does not necessarily support.
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, m_textureWidth, m_textureHeight, 0, // Some (most?) hardware supports BGRA textures via an extension.
GL_BGRA_EXT, GL_UNSIGNED_BYTE, m_pixels); // If not, we convert to RGBA first to avoid having to swizzle in shaders.
#elif HAS_GLES == 2 GLint internalformat;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_textureWidth, m_textureHeight, 0, GLenum pixelformat;
GL_RGBA, GL_UNSIGNED_BYTE, m_pixels); if (g_Windowing.SupportsBGRA())
#endif {
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 #endif
VerifyGLState(); VerifyGLState();
Expand Down

0 comments on commit bef5be1

Please sign in to comment.