[Mesa-dev] [PATCH 1/2] mesa: Add gl_formats to cover all GLUser provided format/type combinations

Mark Mueller markkmueller at gmail.com
Thu Nov 14 15:53:27 PST 2013


This and the subsequent patch are the first steps in adding support to load textures
via GPU instead of CPU. This patch expands Mesa's gl_formats such that all GLUser
format/type combinations are represented and thus can be communicated to lower levels
within dri drivers. The new formats are source only thus they require no associated
Texstore functions or render targets, therefore they are added _privately_ at the end
of the gl_formats list.

Signed-off-by: Mark Mueller <MarkKMueller at gmail.com>
---
 src/mesa/main/formats.c   | 441 +++++++++++++++++++++++++++++++++++++++++++++-
 src/mesa/main/formats.h   |  70 +++++++-
 src/mesa/main/texformat.c | 271 ++++++++++++++++++++++++++++
 src/mesa/main/texformat.h |  11 ++
 4 files changed, 789 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 07d2a72..2c32bba 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -76,7 +76,7 @@ struct gl_format_info
  * These must be in the same order as the MESA_FORMAT_* enums so that
  * we can do lookups without searching.
  */
-static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
+static struct gl_format_info format_info[MESA_PRIVATE_FORMAT_COUNT] =
 {
    {
       MESA_FORMAT_NONE,            /* Name */
@@ -1572,7 +1572,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
    },
    {
       MESA_FORMAT_RGB9_E5_FLOAT,
-      "MESA_FORMAT_RGB9_E5",
+      "MESA_FORMAT_RGB9_E5_FLOAT",
       GL_RGB,
       GL_FLOAT,
       9, 9, 9, 0,
@@ -1763,6 +1763,440 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       0, 0, 0, 0, 0,
       1, 1, 16
    },
+
+   /*
+    * Formats to exactly represent format/type combinations for OGLUser provided
+    * textures. These formats are required only for caching of an unaltered copy of
+    * the application texture prior to passing them to the GPU, where they are
+    * processed to the final internalFormat and miptree location. Texstore functions
+    * do not apply and these are not intended to be used as render targets.
+    * Listing is based on the order presented in the glTexImage2D spec.
+    */
+   /* Red Solo - !cup */
+   {
+      MESA_FORMAT_R32,
+      "MESA_FORMAT_R32",
+      GL_RED,
+      GL_UNSIGNED_NORMALIZED,
+      16, 0, 0, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 2
+   },
+   {
+      MESA_FORMAT_SIGNED_R32,
+      "MESA_FORMAT_SIGNED_R32",
+      GL_RED,
+      GL_SIGNED_NORMALIZED,
+      32, 0, 0, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+
+   /* Red Green - !show */
+   {
+      MESA_FORMAT_SIGNED_RG88,
+      "MESA_FORMAT_SIGNED_RG88",
+      GL_RG,
+      GL_SIGNED_NORMALIZED,
+      8, 8, 0, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 2
+   },
+   {
+      MESA_FORMAT_SIGNED_RG1616,
+      "MESA_FORMAT_SIGNED_RG1616",
+      GL_RG,
+      GL_SIGNED_NORMALIZED,
+      16, 16, 0, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_RG3232,
+      "MESA_FORMAT_RG3232",
+      GL_RG,
+      GL_UNSIGNED_NORMALIZED,
+      32, 32, 0, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_SIGNED_RG3232,
+      "MESA_FORMAT_SIGNED_RG3232",
+      GL_RG,
+      GL_SIGNED_NORMALIZED,
+      32, 32, 0, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+
+   /* Red Green Blue */
+   {
+      MESA_FORMAT_SIGNED_RGB888,
+      "MESA_FORMAT_SIGNED_RGB888",
+      GL_RGB,
+      GL_SIGNED_NORMALIZED,
+      8, 8, 8, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 3
+   },
+   {
+      MESA_FORMAT_RGB161616,
+      "MESA_FORMAT_RG161616",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 6
+   },
+   {
+      MESA_FORMAT_SIGNED_RGB161616,
+      "MESA_FORMAT_SIGNED_RGB161616",
+      GL_RGB,
+      GL_SIGNED_NORMALIZED,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 6
+   },
+   {
+      MESA_FORMAT_RGB323232,
+      "MESA_FORMAT_RGB323232",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      32, 32, 32, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 12
+   },
+   {
+      MESA_FORMAT_SIGNED_RGB323232,
+      "MESA_FORMAT_SIGNED_RGB323232",
+      GL_RGB,
+      GL_SIGNED_NORMALIZED,
+      32, 32, 32, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 12
+   },
+   {
+      MESA_FORMAT_RGB233_REV,
+      "MESA_FORMAT_RGB233_REV",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      3, 3, 2, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 1
+   },
+   {
+      MESA_FORMAT_RGB101111_REV,
+      "MESA_FORMAT_RGB101111_REV",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      11, 11, 10, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+
+   /* Blue Green Red */
+   {
+       MESA_FORMAT_SIGNED_BGR888,
+       "MESA_FORMAT_SIGNED_BGR888",
+       GL_RGB,
+       GL_SIGNED_NORMALIZED,
+       8, 8, 8, 0,
+       0, 0, 0, 0, 0,
+       1, 1, 3
+   },
+   {
+      MESA_FORMAT_BGR161616,
+      "MESA_FORMAT_BGR161616",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 6
+   },
+   {
+      MESA_FORMAT_SIGNED_BGR161616,
+      "MESA_FORMAT_SIGNED_BGR161616",
+      GL_RGB,
+      GL_SIGNED_NORMALIZED,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 6
+   },
+   {
+      MESA_FORMAT_BGR_FLOAT16,
+      "MESA_FORMAT_BGR_FLOAT16",
+      GL_RGB,
+      GL_FLOAT,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 6
+   },
+   {
+      MESA_FORMAT_BGR323232,
+      "MESA_FORMAT_BGR323232",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      32, 32, 32, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 12
+   },
+   {
+      MESA_FORMAT_SIGNED_BGR323232,
+      "MESA_FORMAT_SIGNED_BGR323232",
+      GL_RGB,
+      GL_SIGNED_NORMALIZED,
+      32, 32, 32, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 12
+   },
+   {
+      MESA_FORMAT_BGR_FLOAT32,
+      "MESA_FORMAT_BGR_FLOAT32",
+      GL_RGB,
+      GL_FLOAT,
+      32, 32, 32, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 12
+   },
+
+   /* Red Green Blue Alpha */
+   {
+      MESA_FORMAT_RGBA16161616,
+      "MESA_FORMAT_RGBA161616",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      16, 16, 16, 16,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_SIGNED_RGBA16161616,
+      "MESA_FORMAT_SIGNED_RGBA161616",
+      GL_RGBA,
+      GL_SIGNED_NORMALIZED,
+      16, 16, 16, 16,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_RGBA32323232,
+      "MESA_FORMAT_RGBA323232",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      32, 32, 32, 32,
+      0, 0, 0, 0, 0,
+      1, 1, 16
+   },
+   {
+      MESA_FORMAT_SIGNED_RGBA32323232,
+      "MESA_FORMAT_SIGNED_RGBA323232",
+      GL_RGBA,
+      GL_SIGNED_NORMALIZED,
+      32, 32, 32, 32,
+      0, 0, 0, 0, 0,
+      1, 1, 16
+   },
+   {
+      MESA_FORMAT_RGBA1010102,
+      "MESA_FORMAT_RGBA1010102",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      10, 10, 10, 2,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_RGBA2101010_REV,
+      "MESA_FORMAT_RGBA2101010_REV",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      10, 10, 10, 2,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_RGBA5999_REV,
+      "MESA_FORMAT_RGBA5999_REV",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      9, 9, 9, 5,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_RGBA4444,        /* Name */
+      "MESA_FORMAT_RGBA4444",      /* StrName */
+      GL_RGBA,                     /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      4, 4, 4, 4,                  /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 2                      /* BlockWidth/Height,Bytes */
+   },
+   {
+      MESA_FORMAT_RGBA4444_REV,    /* Name */
+      "MESA_FORMAT_RGBA4444_REV",  /* StrName */
+      GL_RGBA,                     /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      4, 4, 4, 4,                  /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 2                      /* BlockWidth/Height,Bytes */
+   },
+   {
+      MESA_FORMAT_RGBA1555_REV,    /* Name */
+      "MESA_FORMAT_RGBA1555_REV",  /* StrName */
+      GL_RGBA,                     /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      5, 5, 5, 1,                  /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 2                      /* BlockWidth/Height,Bytes */
+   },
+
+   /* Blue Green Red Alpha */
+   {
+      MESA_FORMAT_BGRA8888,        /* Name */
+      "MESA_FORMAT_BGRA8888",      /* StrName */
+      GL_RGBA,                     /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 4                      /* BlockWidth/Height,Bytes */
+   },
+   {
+      MESA_FORMAT_BGRA8888_REV,    /* Name */
+      "MESA_FORMAT_BGRA8888",      /* StrName */
+      GL_RGBA,                     /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 4                      /* BlockWidth/Height,Bytes */
+   },
+   {
+      MESA_FORMAT_SIGNED_BGRA8888,
+      "MESA_FORMAT_SIGNED_BGRA8888",
+      GL_RGBA,
+      GL_SIGNED_NORMALIZED,
+      8, 8, 8, 8,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_BGRA16161616,
+      "MESA_FORMAT_BGRA16161616",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      16, 16, 16, 16,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_SIGNED_BGRA16161616,
+      "MESA_FORMAT_SIGNED_BGRA16161616",
+      GL_RGBA,
+      GL_SIGNED_NORMALIZED,
+      16, 16, 16, 16,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_BGRA_FLOAT16,
+      "MESA_FORMAT_BGRA_FLOAT16",
+      GL_RGBA,
+      GL_FLOAT,
+      16, 16, 16, 16,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_BGRA32323232,
+      "MESA_FORMAT_BGRA32323232",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      32, 32, 32, 32,
+      0, 0, 0, 0, 0,
+      1, 1, 16
+   },
+   {
+      MESA_FORMAT_SIGNED_BGRA32323232,
+      "MESA_FORMAT_SIGNED_BGRA32323232",
+      GL_RGBA,
+      GL_SIGNED_NORMALIZED,
+      32, 32, 32, 32,
+      0, 0, 0, 0, 0,
+      1, 1, 16
+   },
+   {
+      MESA_FORMAT_BGRA_FLOAT32,
+      "MESA_FORMAT_BGRA_FLOAT32",
+      GL_RGBA,
+      GL_FLOAT,
+      32, 32, 32, 32,
+      0, 0, 0, 0, 0,
+      1, 1, 16
+   },
+   {
+      MESA_FORMAT_BGRA4444,        /* Name */
+      "MESA_FORMAT_BGRA4444",      /* StrName */
+      GL_RGBA,                     /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      4, 4, 4, 4,                  /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 2                      /* BlockWidth/Height,Bytes */
+   },
+   {
+      MESA_FORMAT_BGRA4444_REV,    /* Name */
+      "MESA_FORMAT_BGRA4444_REV",  /* StrName */
+      GL_RGBA,                     /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      4, 4, 4, 4,                  /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 2                      /* BlockWidth/Height,Bytes */
+   },
+   {
+      MESA_FORMAT_BGRA5551,        /* Name */
+      "MESA_FORMAT_BGRA5551",      /* StrName */
+      GL_RGBA,                     /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      5, 5, 5, 1,                  /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 2                      /* BlockWidth/Height,Bytes */
+   },
+   {
+      MESA_FORMAT_BGRA1555_REV,    /* Name */
+      "MESA_FORMAT_BGRA1555_REV",  /* StrName */
+      GL_RGBA,                     /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      5, 5, 5, 1,                  /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 2                      /* BlockWidth/Height,Bytes */
+   },
+   {
+      MESA_FORMAT_BGRA1010102,
+      "MESA_FORMAT_BGRA1010102",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      10, 10, 10, 2,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_BGRA2101010_REV,
+      "MESA_FORMAT_BGRA2101010_REV",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      10, 10, 10, 2,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_BGRA5999_REV,
+      "MESA_FORMAT_BGRA5999_REV",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      9, 9, 9, 5,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
 };
 
 
@@ -2221,7 +2655,7 @@ _mesa_test_formats(void)
 {
    GLuint i;
 
-   STATIC_ASSERT(Elements(format_info) == MESA_FORMAT_COUNT);
+   STATIC_ASSERT(Elements(format_info) == MESA_PRIVATE_FORMAT_COUNT);
 
    for (i = 0; i < MESA_FORMAT_COUNT; i++) {
       const struct gl_format_info *info = _mesa_get_format_info(i);
@@ -3361,6 +3795,7 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
    case MESA_FORMAT_XBGR32323232_FLOAT:
    case MESA_FORMAT_XBGR32323232_UINT:
    case MESA_FORMAT_XBGR32323232_SINT:
+   default:
       return GL_FALSE;
    }
 
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 64b4b9a..687b525 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -304,7 +304,75 @@ typedef enum
    MESA_FORMAT_XBGR32323232_UINT, /* ... */
    MESA_FORMAT_XBGR32323232_SINT, /* ... */
 
-   MESA_FORMAT_COUNT
+   MESA_FORMAT_COUNT,
+
+   /*
+    * Formats to exactly represent format/type combinations for OGLUser provided
+    * textures. These formats are required only for caching of an unaltered copy of
+    * the application texture prior to passing them to the GPU, where they are
+    * processed to the final internalFormat and miptree location. Texstore functions
+    * do not apply and these are not intended to be used as render targets.
+    * Listing is based on the order presented in the glTexImage2D spec.
+    */
+   /* Red Solo - !cup */
+   MESA_FORMAT_R32 = MESA_FORMAT_COUNT,
+   MESA_FORMAT_SIGNED_R32,
+
+   /* Red Green - !show */
+   MESA_FORMAT_SIGNED_RG88,
+   MESA_FORMAT_SIGNED_RG1616,
+   MESA_FORMAT_RG3232,
+   MESA_FORMAT_SIGNED_RG3232,
+
+   /* Red Green Blue */
+   MESA_FORMAT_SIGNED_RGB888,
+   MESA_FORMAT_RGB161616,
+   MESA_FORMAT_SIGNED_RGB161616,
+   MESA_FORMAT_RGB323232,
+   MESA_FORMAT_SIGNED_RGB323232,
+   MESA_FORMAT_RGB233_REV,
+   MESA_FORMAT_RGB101111_REV,
+
+   /* Blue Green Red */
+   MESA_FORMAT_SIGNED_BGR888,
+   MESA_FORMAT_BGR161616,
+   MESA_FORMAT_SIGNED_BGR161616,
+   MESA_FORMAT_BGR_FLOAT16,
+   MESA_FORMAT_BGR323232,
+   MESA_FORMAT_SIGNED_BGR323232,
+   MESA_FORMAT_BGR_FLOAT32,
+
+   /* Red Green Blue Alpha */
+   MESA_FORMAT_RGBA16161616,
+   MESA_FORMAT_SIGNED_RGBA16161616,
+   MESA_FORMAT_RGBA32323232,
+   MESA_FORMAT_SIGNED_RGBA32323232,
+   MESA_FORMAT_RGBA1010102,
+   MESA_FORMAT_RGBA2101010_REV,
+   MESA_FORMAT_RGBA5999_REV,
+   MESA_FORMAT_RGBA4444,
+   MESA_FORMAT_RGBA4444_REV,
+   MESA_FORMAT_RGBA1555_REV,
+
+   /* Blue Green Red Alpha */
+   MESA_FORMAT_BGRA8888,
+   MESA_FORMAT_BGRA8888_REV,
+   MESA_FORMAT_SIGNED_BGRA8888,
+   MESA_FORMAT_BGRA16161616,
+   MESA_FORMAT_SIGNED_BGRA16161616,
+   MESA_FORMAT_BGRA_FLOAT16,
+   MESA_FORMAT_BGRA32323232,
+   MESA_FORMAT_SIGNED_BGRA32323232,
+   MESA_FORMAT_BGRA_FLOAT32,
+   MESA_FORMAT_BGRA4444,
+   MESA_FORMAT_BGRA4444_REV,
+   MESA_FORMAT_BGRA5551,
+   MESA_FORMAT_BGRA1555_REV,
+   MESA_FORMAT_BGRA1010102,
+   MESA_FORMAT_BGRA2101010_REV,
+   MESA_FORMAT_BGRA5999_REV,
+
+   MESA_PRIVATE_FORMAT_COUNT
 } gl_format;
 
 
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index d3aa477..713fdf2 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -831,3 +831,274 @@ _mesa_tex_target_is_array(GLenum target)
       return GL_FALSE;
    }
 }
+
+/**
+ * Choose a texture format that exaclty matches the application texture
+ * given the format, and type Format parameters passed to glTexImage().
+ *
+ * \param ctx  the GL context.
+ * \param format  incoming image pixel format.
+ * \param type  incoming image data type.
+ *
+ * \return a matching gl_format for the given format/type arguments
+ *
+ */
+gl_format
+_mesa_choose_cached_tex_format(struct gl_context *ctx, GLenum format, GLenum type)
+{
+   switch (format) {
+   case GL_RED:
+      switch (type) {
+      case GL_BYTE:
+         return MESA_FORMAT_SIGNED_R8;
+      case GL_UNSIGNED_BYTE:
+         return MESA_FORMAT_R8;
+      case GL_SHORT:
+         return MESA_FORMAT_SIGNED_R16;
+      case GL_UNSIGNED_SHORT:
+         return MESA_FORMAT_R16;
+      case GL_INT:
+         return MESA_FORMAT_SIGNED_R32;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_R32;
+      case GL_FLOAT:
+         return MESA_FORMAT_R_FLOAT32;
+      case GL_HALF_FLOAT:
+         return MESA_FORMAT_R_FLOAT16;
+      }
+      break;
+
+   case GL_RG:
+      switch (type) {
+      case GL_BYTE:
+         return MESA_FORMAT_SIGNED_RG88;
+      case GL_UNSIGNED_BYTE:
+         return MESA_FORMAT_RG88;
+      case GL_SHORT:
+         return MESA_FORMAT_SIGNED_RG1616;
+      case GL_UNSIGNED_SHORT:
+         return MESA_FORMAT_RG1616;
+      case GL_INT:
+         return MESA_FORMAT_SIGNED_RG3232;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_RG3232;
+      case GL_FLOAT:
+         return MESA_FORMAT_RG_FLOAT32;
+      case GL_HALF_FLOAT:
+         return MESA_FORMAT_RG_FLOAT16;
+      }
+      break;
+
+   case GL_RGB:
+      switch (type) {
+      case GL_BYTE:
+         return MESA_FORMAT_SIGNED_RGB888;
+      case GL_UNSIGNED_BYTE:
+         return MESA_FORMAT_RGB888;
+      case GL_SHORT:
+         return MESA_FORMAT_SIGNED_RGB161616;
+      case GL_UNSIGNED_SHORT:
+         return MESA_FORMAT_RGB161616;
+      case GL_INT:
+         return MESA_FORMAT_SIGNED_RGB323232;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_RGB323232;
+      case GL_FLOAT:
+         return MESA_FORMAT_RGB_FLOAT32;
+      case GL_HALF_FLOAT:
+         return MESA_FORMAT_RGB_FLOAT16;
+      case GL_UNSIGNED_BYTE_3_3_2:
+         return MESA_FORMAT_RGB332;
+      case GL_UNSIGNED_BYTE_2_3_3_REV:
+         return MESA_FORMAT_RGB233_REV;
+      case GL_UNSIGNED_SHORT_5_6_5:
+         return MESA_FORMAT_RGB565;
+      case GL_UNSIGNED_SHORT_5_6_5_REV:
+         return MESA_FORMAT_RGB565_REV;
+      case GL_UNSIGNED_INT_10F_11F_11F_REV:
+         return MESA_FORMAT_RGB101111_REV;
+      }
+      break;
+
+   case GL_BGR:
+      switch (type) {
+      case GL_BYTE:
+         return MESA_FORMAT_SIGNED_BGR888;
+      case GL_UNSIGNED_BYTE:
+         return MESA_FORMAT_BGR888;
+      case GL_SHORT:
+         return MESA_FORMAT_SIGNED_BGR161616;
+      case GL_UNSIGNED_SHORT:
+         return MESA_FORMAT_BGR161616;
+      case GL_INT:
+         return MESA_FORMAT_SIGNED_BGR323232;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_BGR323232;
+      case GL_FLOAT:
+         return MESA_FORMAT_BGR_FLOAT32;
+      case GL_HALF_FLOAT:
+         return MESA_FORMAT_BGR_FLOAT16;
+      }
+      break;
+
+   case GL_RGBA:
+      switch (type) {
+      case GL_BYTE:
+         return MESA_FORMAT_SIGNED_RGBA8888;
+      case GL_UNSIGNED_BYTE:
+         return MESA_FORMAT_RGBA8888;
+      case GL_SHORT:
+         return MESA_FORMAT_SIGNED_RGBA16161616;
+      case GL_UNSIGNED_SHORT:
+         return MESA_FORMAT_RGBA16161616;
+      case GL_INT:
+         return MESA_FORMAT_SIGNED_RGBA32323232;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_RGBA32323232;
+      case GL_FLOAT:
+         return MESA_FORMAT_RGBA_FLOAT32;
+      case GL_HALF_FLOAT:
+         return MESA_FORMAT_RGBA_FLOAT16;
+      case GL_UNSIGNED_SHORT_4_4_4_4:
+         return MESA_FORMAT_RGBA4444;
+      case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+         return MESA_FORMAT_RGBA4444_REV;
+      case GL_UNSIGNED_SHORT_5_5_5_1:
+         return MESA_FORMAT_RGBA5551;
+      case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+         return MESA_FORMAT_RGBA1555_REV;
+      case GL_UNSIGNED_INT_8_8_8_8:
+         return MESA_FORMAT_RGBA32323232;
+      case GL_UNSIGNED_INT_8_8_8_8_REV:
+         return MESA_FORMAT_RGBA8888_REV;
+      case GL_UNSIGNED_INT_10_10_10_2:
+         return MESA_FORMAT_RGBA1010102;
+      case GL_UNSIGNED_INT_2_10_10_10_REV:
+         return MESA_FORMAT_RGBA2101010_REV;
+      case GL_UNSIGNED_INT_5_9_9_9_REV:
+         return MESA_FORMAT_RGBA5999_REV;
+      }
+      break;
+
+   case GL_BGRA:
+      switch (type) {
+      case GL_BYTE:
+         return MESA_FORMAT_SIGNED_BGRA8888;
+      case GL_UNSIGNED_BYTE:
+         return MESA_FORMAT_BGRA8888;
+      case GL_SHORT:
+         return MESA_FORMAT_SIGNED_BGRA16161616;
+      case GL_UNSIGNED_SHORT:
+         return MESA_FORMAT_BGRA16161616;
+      case GL_INT:
+         return MESA_FORMAT_BGRA32323232;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_SIGNED_BGRA32323232;
+      case GL_FLOAT:
+         return MESA_FORMAT_BGRA_FLOAT32;
+      case GL_HALF_FLOAT:
+         return MESA_FORMAT_BGRA_FLOAT16;
+      case GL_UNSIGNED_SHORT_4_4_4_4:
+         return MESA_FORMAT_BGRA4444;
+      case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+         return MESA_FORMAT_BGRA4444_REV;
+      case GL_UNSIGNED_SHORT_5_5_5_1:
+         return MESA_FORMAT_BGRA5551;
+      case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+         return MESA_FORMAT_BGRA1555_REV;
+      case GL_UNSIGNED_INT_8_8_8_8:
+         return MESA_FORMAT_BGRA8888;
+      case GL_UNSIGNED_INT_8_8_8_8_REV:
+         return MESA_FORMAT_BGRA8888_REV;
+      case GL_UNSIGNED_INT_10_10_10_2:
+         return MESA_FORMAT_BGRA1010102;
+      case GL_UNSIGNED_INT_2_10_10_10_REV:
+         return MESA_FORMAT_BGRA2101010_REV;
+      case GL_UNSIGNED_INT_5_9_9_9_REV:
+         return MESA_FORMAT_BGRA5999_REV;
+      }
+      break;
+
+   case GL_LUMINANCE:
+      switch (type) {
+      case GL_BYTE:
+         return MESA_FORMAT_LUMINANCE_INT8;
+      case GL_UNSIGNED_BYTE:
+         return MESA_FORMAT_LUMINANCE_UINT8;
+      case GL_SHORT:
+         return MESA_FORMAT_LUMINANCE_INT16;
+      case GL_UNSIGNED_SHORT:
+         return MESA_FORMAT_LUMINANCE_UINT16;
+      case GL_INT:
+         return MESA_FORMAT_LUMINANCE_INT32;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_LUMINANCE_UINT32;
+      case GL_FLOAT:
+         return MESA_FORMAT_LUMINANCE_FLOAT32;
+      case GL_HALF_FLOAT:
+         return MESA_FORMAT_LUMINANCE_FLOAT16;
+      }
+      break;
+
+   case GL_LUMINANCE_ALPHA:
+      switch (type) {
+      case GL_BYTE:
+         return MESA_FORMAT_LUMINANCE_ALPHA_INT8;
+      case GL_UNSIGNED_BYTE:
+         return MESA_FORMAT_LUMINANCE_ALPHA_UINT8;
+      case GL_SHORT:
+         return MESA_FORMAT_LUMINANCE_ALPHA_INT16;
+      case GL_UNSIGNED_SHORT:
+         return MESA_FORMAT_LUMINANCE_ALPHA_UINT16;
+      case GL_INT:
+         return MESA_FORMAT_LUMINANCE_ALPHA_INT32;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_LUMINANCE_ALPHA_UINT32;
+      case GL_FLOAT:
+         return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32;
+      case GL_HALF_FLOAT:
+         return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16;
+      }
+      break;
+
+   case GL_DEPTH_COMPONENT:
+      switch (type) {
+      case GL_INT:
+         return MESA_FORMAT_Z32;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_Z32;
+      case GL_FLOAT:
+         return MESA_FORMAT_Z32_FLOAT;
+      }
+      break;
+
+   case GL_STENCIL_INDEX:
+      switch (type) {
+      case GL_BYTE:
+      case GL_UNSIGNED_BYTE:
+         return MESA_FORMAT_S8;
+      }
+      break;
+
+   case GL_DEPTH_STENCIL:
+      switch (type) {
+      case GL_UNSIGNED_SHORT:
+         return MESA_FORMAT_Z24_S8;
+      case GL_INT:
+         return MESA_FORMAT_Z32;
+      case GL_UNSIGNED_INT:
+         return MESA_FORMAT_Z32;
+      case GL_FLOAT:
+         return MESA_FORMAT_Z32_FLOAT_X24S8;
+      case GL_UNSIGNED_INT_24_8_EXT: /* GL_EXT_packed_depth_stencil */
+         return MESA_FORMAT_Z24_S8;
+      case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
+         return MESA_FORMAT_S8_Z24;
+      }
+      break;
+   }
+
+   _mesa_problem(ctx, "%s(): unexpected format %s and type %s\n",
+                 __FUNCTION__, _mesa_lookup_enum_by_nr(format), _mesa_lookup_enum_by_nr(type));
+   return MESA_FORMAT_NONE;
+}
diff --git a/src/mesa/main/texformat.h b/src/mesa/main/texformat.h
index 88ad4d1..66d50b3 100644
--- a/src/mesa/main/texformat.h
+++ b/src/mesa/main/texformat.h
@@ -29,13 +29,24 @@
 
 #include "formats.h"
 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct gl_context;
 
 extern gl_format
+_mesa_choose_cached_tex_format(struct gl_context *ctx, GLenum format, GLenum type);
+extern gl_format
 _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
                         GLint internalFormat, GLenum format, GLenum type);
 
 extern GLboolean
 _mesa_tex_target_is_array(GLenum target);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
-- 
1.8.3.1



More information about the mesa-dev mailing list