Mesa (master): st/mesa: Prefer alpha-less formats for RGB textures.

Michel Dänzer daenzer at kemper.freedesktop.org
Sat Dec 5 09:11:11 PST 2009


Module: Mesa
Branch: master
Commit: 01537a84dfe65cd1512d6fbf71e975fad5639432
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=01537a84dfe65cd1512d6fbf71e975fad5639432

Author: Michel Dänzer <daenzer at vmware.com>
Date:   Sat Dec  5 17:42:50 2009 +0100

st/mesa: Prefer alpha-less formats for RGB textures.

This can e.g. increase the chance of being able to accelerate
glCopyTex(Sub)Image from an alpha-less renderbuffer.

---

 src/mesa/state_tracker/st_format.c |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 02f8005..93125af 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -389,6 +389,33 @@ default_rgba_format(struct pipe_screen *screen,
 }
 
 /**
+ * Find an RGB format supported by the context/winsys.
+ */
+static enum pipe_format
+default_rgb_format(struct pipe_screen *screen, 
+                   enum pipe_texture_target target,
+                   unsigned tex_usage, 
+                   unsigned geom_flags)
+{
+   static const enum pipe_format colorFormats[] = {
+      PIPE_FORMAT_X8R8G8B8_UNORM,
+      PIPE_FORMAT_B8G8R8X8_UNORM,
+      PIPE_FORMAT_R8G8B8X8_UNORM,
+      PIPE_FORMAT_A8R8G8B8_UNORM,
+      PIPE_FORMAT_B8G8R8A8_UNORM,
+      PIPE_FORMAT_R8G8B8A8_UNORM,
+      PIPE_FORMAT_R5G6B5_UNORM
+   };
+   uint i;
+   for (i = 0; i < Elements(colorFormats); i++) {
+      if (screen->is_format_supported( screen, colorFormats[i], target, tex_usage, geom_flags )) {
+         return colorFormats[i];
+      }
+   }
+   return PIPE_FORMAT_NONE;
+}
+
+/**
  * Find an sRGBA format supported by the context/winsys.
  */
 static enum pipe_format
@@ -472,13 +499,14 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
    case 4:
    case GL_RGBA:
    case GL_COMPRESSED_RGBA:
-   case 3:
-   case GL_RGB:
-   case GL_COMPRESSED_RGB:
    case GL_RGBA8:
    case GL_RGB10_A2:
    case GL_RGBA12:
       return default_rgba_format( screen, target, tex_usage, geom_flags );
+   case 3:
+   case GL_RGB:
+   case GL_COMPRESSED_RGB:
+      return default_rgb_format( screen, target, tex_usage, geom_flags );
    case GL_RGBA16:
       if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET)
          return default_deep_rgba_format( screen, target, tex_usage, geom_flags );
@@ -500,7 +528,7 @@ st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
    case GL_RGB10:
    case GL_RGB12:
    case GL_RGB16:
-      return default_rgba_format( screen, target, tex_usage, geom_flags );
+      return default_rgb_format( screen, target, tex_usage, geom_flags );
 
    case GL_RGB5:
    case GL_RGB4:



More information about the mesa-commit mailing list