st/mesa: Prefer alpha-less formats for RGB textures.
authorMichel Dänzer <daenzer@vmware.com>
Sat, 5 Dec 2009 16:42:50 +0000 (17:42 +0100)
committerMichel Dänzer <michel@daenzer.net>
Sat, 5 Dec 2009 16:59:49 +0000 (17:59 +0100)
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

index 02f80057c29faa7bf205e67255e7ae34c889484b..93125afe9e1c3bb5aa39e2290bd6e6d90efd8653 100644 (file)
@@ -388,6 +388,33 @@ default_rgba_format(struct pipe_screen *screen,
    return PIPE_FORMAT_NONE;
 }
 
+/**
+ * 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.
  */
@@ -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: