changed: improved gles performance by avoiding bgra->rgba convert for textures
authortheuni <theuni-nospam-@xbmc.org>
Sat, 9 Jul 2011 16:00:55 +0000 (12:00 -0400)
committertheuni <theuni-nospam-@xbmc.org>
Sun, 10 Jul 2011 05:58:29 +0000 (01:58 -0400)
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.

system/shaders/guishader_frag_multi.glsl
system/shaders/guishader_frag_multi_blendcolor.glsl
system/shaders/guishader_frag_texture.glsl
system/shaders/guishader_frag_texture_noblend.glsl
xbmc/guilib/TextureGL.cpp

index c712e3c..a5a97b5 100644 (file)
@@ -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;
 }
index e012a6b..b311350 100644 (file)
@@ -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;
 }
index 826369f..16bb84e 100644 (file)
@@ -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);
 }
index 16438a3..ed050fa 100644 (file)
@@ -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);
 }
index 2f20c0e..520af9e 100644 (file)
@@ -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();