mesa: Change many Type A MESA_FORMATs to meet naming standard
[mesa.git] / src / mesa / main / formats.c
index 0d4af7c169c41138b86de82f63062744730a96b9..99d1e189d8dbcf3e6d5b232b1559dbff84476c08 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.7
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  * Copyright (c) 2008-2009  VMware, Inc.
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 #include "imports.h"
 #include "formats.h"
-#include "mfeatures.h"
+#include "macros.h"
+#include "glformats.h"
 
 
 /**
@@ -34,7 +35,7 @@
  */
 struct gl_format_info
 {
-   gl_format Name;
+   mesa_format Name;
 
    /** text name for debugging */
    const char *StrName;
@@ -87,8 +88,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       0, 0, 0                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_RGBA8888,        /* Name */
-      "MESA_FORMAT_RGBA8888",      /* StrName */
+      MESA_FORMAT_A8B8G8R8_UNORM,        /* Name */
+      "MESA_FORMAT_A8B8G8R8_UNORM",      /* StrName */
       GL_RGBA,                     /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
@@ -96,8 +97,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_RGBA8888_REV,    /* Name */
-      "MESA_FORMAT_RGBA8888_REV",  /* StrName */
+      MESA_FORMAT_R8G8B8A8_UNORM,    /* Name */
+      "MESA_FORMAT_R8G8B8A8_UNORM",  /* StrName */
       GL_RGBA,                     /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
@@ -105,8 +106,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_ARGB8888,        /* Name */
-      "MESA_FORMAT_ARGB8888",      /* StrName */
+      MESA_FORMAT_B8G8R8A8_UNORM,        /* Name */
+      "MESA_FORMAT_B8G8R8A8_UNORM",      /* StrName */
       GL_RGBA,                     /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
@@ -114,8 +115,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_ARGB8888_REV,    /* Name */
-      "MESA_FORMAT_ARGB8888_REV",  /* StrName */
+      MESA_FORMAT_A8R8G8B8_UNORM,    /* Name */
+      "MESA_FORMAT_A8R8G8B8_UNORM",  /* StrName */
       GL_RGBA,                     /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
@@ -123,8 +124,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_RGBX8888,        /* Name */
-      "MESA_FORMAT_RGBX8888",      /* StrName */
+      MESA_FORMAT_X8B8G8R8_UNORM,        /* Name */
+      "MESA_FORMAT_X8B8G8R8_UNORM",      /* StrName */
       GL_RGB,                      /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -132,8 +133,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_RGBX8888_REV,    /* Name */
-      "MESA_FORMAT_RGBX8888_REV",  /* StrName */
+      MESA_FORMAT_R8G8B8X8_UNORM,    /* Name */
+      "MESA_FORMAT_R8G8B8X8_UNORM",  /* StrName */
       GL_RGB,                      /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -141,8 +142,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_XRGB8888,        /* Name */
-      "MESA_FORMAT_XRGB8888",      /* StrName */
+      MESA_FORMAT_B8G8R8X8_UNORM,        /* Name */
+      "MESA_FORMAT_B8G8R8X8_UNORM",      /* StrName */
       GL_RGB,                      /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -150,8 +151,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_XRGB8888_REV,    /* Name */
-      "MESA_FORMAT_XRGB8888_REV",  /* StrName */
+      MESA_FORMAT_X8R8G8B8_UNORM,    /* Name */
+      "MESA_FORMAT_X8R8G8B8_UNORM",  /* StrName */
       GL_RGB,                      /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -159,8 +160,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_RGB888,          /* Name */
-      "MESA_FORMAT_RGB888",        /* StrName */
+      MESA_FORMAT_BGR_UNORM8,          /* Name */
+      "MESA_FORMAT_BGR_UNORM8",        /* StrName */
       GL_RGB,                      /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -168,8 +169,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 3                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_BGR888,          /* Name */
-      "MESA_FORMAT_BGR888",        /* StrName */
+      MESA_FORMAT_RGB_UNORM8,          /* Name */
+      "MESA_FORMAT_RGB_UNORM8",        /* StrName */
       GL_RGB,                      /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -294,8 +295,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 1                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_A8,              /* Name */
-      "MESA_FORMAT_A8",            /* StrName */
+      MESA_FORMAT_A_UNORM8,              /* Name */
+      "MESA_FORMAT_A_UNORM8",            /* StrName */
       GL_ALPHA,                    /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       0, 0, 0, 8,                  /* Red/Green/Blue/AlphaBits */
@@ -303,8 +304,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 1                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_A16,             /* Name */
-      "MESA_FORMAT_A16",           /* StrName */
+      MESA_FORMAT_A_UNORM16,             /* Name */
+      "MESA_FORMAT_A_UNORM16",           /* StrName */
       GL_ALPHA,                    /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       0, 0, 0, 16,                 /* Red/Green/Blue/AlphaBits */
@@ -312,8 +313,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 2                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_L8,              /* Name */
-      "MESA_FORMAT_L8",            /* StrName */
+      MESA_FORMAT_L_UNORM8,              /* Name */
+      "MESA_FORMAT_L_UNORM8",            /* StrName */
       GL_LUMINANCE,                /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -321,8 +322,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 1                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_L16,             /* Name */
-      "MESA_FORMAT_L16",           /* StrName */
+      MESA_FORMAT_L_UNORM16,             /* Name */
+      "MESA_FORMAT_L_UNORM16",           /* StrName */
       GL_LUMINANCE,                /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -330,8 +331,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 2                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_I8,              /* Name */
-      "MESA_FORMAT_I8",            /* StrName */
+      MESA_FORMAT_I_UNORM8,              /* Name */
+      "MESA_FORMAT_I_UNORM8",            /* StrName */
       GL_INTENSITY,                /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -339,8 +340,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 1                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_I16,             /* Name */
-      "MESA_FORMAT_I16",           /* StrName */
+      MESA_FORMAT_I_UNORM16,             /* Name */
+      "MESA_FORMAT_I_UNORM16",           /* StrName */
       GL_INTENSITY,                /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -366,8 +367,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 2                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_R8,
-      "MESA_FORMAT_R8",
+      MESA_FORMAT_R_UNORM8,
+      "MESA_FORMAT_R_UNORM8",
       GL_RED,
       GL_UNSIGNED_NORMALIZED,
       8, 0, 0, 0,
@@ -384,8 +385,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 2
    },
    {
-      MESA_FORMAT_RG88_REV,
-      "MESA_FORMAT_RG88_REV",
+      MESA_FORMAT_RG88,
+      "MESA_FORMAT_RG88",
       GL_RG,
       GL_UNSIGNED_NORMALIZED,
       8, 8, 0, 0,
@@ -393,8 +394,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 2
    },
    {
-      MESA_FORMAT_R16,
-      "MESA_FORMAT_R16",
+      MESA_FORMAT_R_UNORM16,
+      "MESA_FORMAT_R_UNORM16",
       GL_RED,
       GL_UNSIGNED_NORMALIZED,
       16, 0, 0, 0,
@@ -402,8 +403,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 2
    },
    {
-      MESA_FORMAT_RG1616,
-      "MESA_FORMAT_RG1616",
+      MESA_FORMAT_GR1616,
+      "MESA_FORMAT_GR1616",
       GL_RG,
       GL_UNSIGNED_NORMALIZED,
       16, 16, 0, 0,
@@ -411,8 +412,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4
    },
    {
-      MESA_FORMAT_RG1616_REV,
-      "MESA_FORMAT_RG1616_REV",
+      MESA_FORMAT_RG1616,
+      "MESA_FORMAT_RG1616",
       GL_RG,
       GL_UNSIGNED_NORMALIZED,
       16, 16, 0, 0,
@@ -447,8 +448,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_Z16,             /* Name */
-      "MESA_FORMAT_Z16",           /* StrName */
+      MESA_FORMAT_Z_UNORM16,             /* Name */
+      "MESA_FORMAT_Z_UNORM16",           /* StrName */
       GL_DEPTH_COMPONENT,          /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -474,8 +475,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_Z32,             /* Name */
-      "MESA_FORMAT_Z32",           /* StrName */
+      MESA_FORMAT_Z_UNORM32,             /* Name */
+      "MESA_FORMAT_Z_UNORM32",           /* StrName */
       GL_DEPTH_COMPONENT,          /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,      /* DataType */
       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -483,8 +484,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_S8,              /* Name */
-      "MESA_FORMAT_S8",            /* StrName */
+      MESA_FORMAT_S_UINT8,              /* Name */
+      "MESA_FORMAT_S_UINT8",            /* StrName */
       GL_STENCIL_INDEX,            /* BaseFormat */
       GL_UNSIGNED_INT,             /* DataType */
       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -492,8 +493,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 1                      /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_SRGB8,
-      "MESA_FORMAT_SRGB8",
+      MESA_FORMAT_BGR_SRGB8,
+      "MESA_FORMAT_BGR_SRGB8",
       GL_RGB,
       GL_UNSIGNED_NORMALIZED,
       8, 8, 8, 0,
@@ -519,8 +520,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4
    },
    {
-      MESA_FORMAT_SL8,
-      "MESA_FORMAT_SL8",
+      MESA_FORMAT_L_SRGB8,
+      "MESA_FORMAT_L_SRGB8",
       GL_LUMINANCE,
       GL_UNSIGNED_NORMALIZED,    
       0, 0, 0, 0,
@@ -1305,8 +1306,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 8
    },
    {
-      MESA_FORMAT_RGBA_16,
-      "MESA_FORMAT_RGBA_16",
+      MESA_FORMAT_RGBA_UNORM16,
+      "MESA_FORMAT_RGBA_UNORM16",
       GL_RGBA,
       GL_UNSIGNED_NORMALIZED,
       16, 16, 16, 16,
@@ -1318,7 +1319,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
      "MESA_FORMAT_RED_RGTC1",
      GL_RED,
      GL_UNSIGNED_NORMALIZED,
-     4, 0, 0, 0,
+     8, 0, 0, 0,
      0, 0, 0, 0, 0,
      4, 4, 8                     /* 8 bytes per 4x4 block */
    },
@@ -1327,7 +1328,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
      "MESA_FORMAT_SIGNED_RED_RGTC1",
      GL_RED,
      GL_SIGNED_NORMALIZED,
-     4, 0, 0, 0,
+     8, 0, 0, 0,
      0, 0, 0, 0, 0,
      4, 4, 8                     /* 8 bytes per 4x4 block */
    },
@@ -1336,7 +1337,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
      "MESA_FORMAT_RG_RGTC2",
      GL_RG,
      GL_UNSIGNED_NORMALIZED,
-     4, 4, 0, 0,
+     8, 8, 0, 0,
      0, 0, 0, 0, 0,
      4, 4, 16                     /* 16 bytes per 4x4 block */
    },
@@ -1345,7 +1346,7 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
      "MESA_FORMAT_SIGNED_RG_RGTC2",
      GL_RG,
      GL_SIGNED_NORMALIZED,
-     4, 4, 0, 0,
+     8, 8, 0, 0,
      0, 0, 0, 0, 0,
      4, 4, 16                     /* 16 bytes per 4x4 block */
    },
@@ -1396,6 +1397,106 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       4, 4, 8                     /* 8 bytes per 4x4 block */
    },
 
+   {
+      MESA_FORMAT_ETC2_RGB8,
+      "MESA_FORMAT_ETC2_RGB8",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      8, 8, 8, 0,
+      0, 0, 0, 0, 0,
+      4, 4, 8                     /* 8 bytes per 4x4 block */
+   },
+
+   {
+      MESA_FORMAT_ETC2_SRGB8,
+      "MESA_FORMAT_ETC2_SRGB8",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      8, 8, 8, 0,
+      0, 0, 0, 0, 0,
+      4, 4, 8                     /* 8 bytes per 4x4 block */
+   },
+
+   {
+      MESA_FORMAT_ETC2_RGBA8_EAC,
+      "MESA_FORMAT_ETC2_RGBA8_EAC",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      8, 8, 8, 8,
+      0, 0, 0, 0, 0,
+      4, 4, 16                    /* 16 bytes per 4x4 block */
+   },
+
+   {
+      MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC,
+      "MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      8, 8, 8, 8,
+      0, 0, 0, 0, 0,
+      4, 4, 16                    /* 16 bytes per 4x4 block */
+   },
+
+   {
+      MESA_FORMAT_ETC2_R11_EAC,
+      "MESA_FORMAT_ETC2_R11_EAC",
+      GL_RED,
+      GL_UNSIGNED_NORMALIZED,
+      11, 0, 0, 0,
+      0, 0, 0, 0, 0,
+      4, 4, 8                    /* 8 bytes per 4x4 block */
+   },
+
+   {
+      MESA_FORMAT_ETC2_RG11_EAC,
+      "MESA_FORMAT_ETC2_RG11_EAC",
+      GL_RG,
+      GL_UNSIGNED_NORMALIZED,
+      11, 11, 0, 0,
+      0, 0, 0, 0, 0,
+      4, 4, 16                    /* 16 bytes per 4x4 block */
+   },
+
+   {
+      MESA_FORMAT_ETC2_SIGNED_R11_EAC,
+      "MESA_FORMAT_ETC2_SIGNED_R11_EAC",
+      GL_RED,
+      GL_SIGNED_NORMALIZED,
+      11, 0, 0, 0,
+      0, 0, 0, 0, 0,
+      4, 4, 8                    /* 8 bytes per 4x4 block */
+   },
+
+   {
+      MESA_FORMAT_ETC2_SIGNED_RG11_EAC,
+      "MESA_FORMAT_ETC2_SIGNED_RG11_EAC",
+      GL_RG,
+      GL_SIGNED_NORMALIZED,
+      11, 11, 0, 0,
+      0, 0, 0, 0, 0,
+      4, 4, 16                    /* 16 bytes per 4x4 block */
+   },
+
+   {
+      MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1,
+      "MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      8, 8, 8, 1,
+      0, 0, 0, 0, 0,
+      4, 4, 8                     /* 8 bytes per 4x4 block */
+   },
+
+   {
+      MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1,
+      "MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      8, 8, 8, 1,
+      0, 0, 0, 0, 0,
+      4, 4, 8                     /* 8 bytes per 4x4 block */
+   },
+
    /* Signed formats from EXT_texture_snorm that are not in GL3.1 */
    {
       MESA_FORMAT_SIGNED_A8,
@@ -1489,8 +1590,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
    },
    /* ARB_depth_buffer_float */
    {
-      MESA_FORMAT_Z32_FLOAT,       /* Name */
-      "MESA_FORMAT_Z32_FLOAT",     /* StrName */
+      MESA_FORMAT_Z_FLOAT32,       /* Name */
+      "MESA_FORMAT_Z_FLOAT32",     /* StrName */
       GL_DEPTH_COMPONENT,          /* BaseFormat */
       GL_FLOAT,                    /* DataType */
       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
@@ -1518,12 +1619,183 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       0, 0, 0, 0, 0,
       1, 1, 4
    },
+   {
+      MESA_FORMAT_ABGR2101010_UINT,
+      "MESA_FORMAT_ABGR2101010_UINT",
+      GL_RGBA,
+      GL_UNSIGNED_INT,
+      10, 10, 10, 2,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_XRGB4444_UNORM,
+      "MESA_FORMAT_XRGB4444_UNORM",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      4, 4, 4, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 2
+   },
+   {
+      MESA_FORMAT_XRGB1555_UNORM,
+      "MESA_FORMAT_XRGB1555_UNORM",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      5, 5, 5, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 2
+   },
+   {
+      MESA_FORMAT_XBGR8888_SNORM,
+      "MESA_FORMAT_XBGR8888_SNORM",
+      GL_RGB,
+      GL_SIGNED_NORMALIZED,
+      8, 8, 8, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_XBGR8888_SRGB,
+      "MESA_FORMAT_XBGR8888_SRGB",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      8, 8, 8, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_RGBX_UINT8,
+      "MESA_FORMAT_RGBX_UINT8",
+      GL_RGB,
+      GL_UNSIGNED_INT,
+      8, 8, 8, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_RGBX_SINT8,
+      "MESA_FORMAT_RGBX_SINT8",
+      GL_RGB,
+      GL_INT,
+      8, 8, 8, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_XRGB2101010_UNORM,
+      "MESA_FORMAT_XRGB2101010_UNORM",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      10, 10, 10, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      MESA_FORMAT_RGBX_UNORM16,
+      "MESA_FORMAT_RGBX_UNORM16",
+      GL_RGB,
+      GL_UNSIGNED_NORMALIZED,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_RGBX_SNORM16,
+      "MESA_FORMAT_RGBX_SNORM16",
+      GL_RGB,
+      GL_SIGNED_NORMALIZED,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_RGBX_FLOAT16,
+      "MESA_FORMAT_RGBX_FLOAT16",
+      GL_RGB,
+      GL_FLOAT,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_RGBX_UINT16,
+      "MESA_FORMAT_RGBX_UINT16",
+      GL_RGB,
+      GL_UNSIGNED_INT,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_RGBX_SINT16,
+      "MESA_FORMAT_RGBX_SINT16",
+      GL_RGB,
+      GL_INT,
+      16, 16, 16, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 8
+   },
+   {
+      MESA_FORMAT_RGBX_FLOAT32,
+      "MESA_FORMAT_RGBX_FLOAT32",
+      GL_RGB,
+      GL_FLOAT,
+      32, 32, 32, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 16
+   },
+   {
+      MESA_FORMAT_RGBX_UINT32,
+      "MESA_FORMAT_RGBX_UINT32",
+      GL_RGB,
+      GL_UNSIGNED_INT,
+      32, 32, 32, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 16
+   },
+   {
+      MESA_FORMAT_RGBX_SINT32,
+      "MESA_FORMAT_RGBX_SINT32",
+      GL_RGB,
+      GL_INT,
+      32, 32, 32, 0,
+      0, 0, 0, 0, 0,
+      1, 1, 16
+   },
+   {
+      MESA_FORMAT_ABGR2101010,
+      "MESA_FORMAT_ABGR2101010",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      10, 10, 10, 2,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
+      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
+   },
 };
 
 
 
 static const struct gl_format_info *
-_mesa_get_format_info(gl_format format)
+_mesa_get_format_info(mesa_format format)
 {
    const struct gl_format_info *info = &format_info[format];
    assert(info->Name == format);
@@ -1533,7 +1805,7 @@ _mesa_get_format_info(gl_format format)
 
 /** Return string name of format (for debugging) */
 const char *
-_mesa_get_format_name(gl_format format)
+_mesa_get_format_name(mesa_format format)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
    return info->StrName;
@@ -1549,10 +1821,12 @@ _mesa_get_format_name(gl_format format)
  * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
  */
 GLint
-_mesa_get_format_bytes(gl_format format)
+_mesa_get_format_bytes(mesa_format format)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
    ASSERT(info->BytesPerBlock);
+   ASSERT(info->BytesPerBlock <= MAX_PIXEL_BYTES ||
+          _mesa_is_format_compressed(format));
    return info->BytesPerBlock;
 }
 
@@ -1563,7 +1837,7 @@ _mesa_get_format_bytes(gl_format format)
  * \param pname  the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
  */
 GLint
-_mesa_get_format_bits(gl_format format, GLenum pname)
+_mesa_get_format_bits(mesa_format format, GLenum pname)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
 
@@ -1611,6 +1885,21 @@ _mesa_get_format_bits(gl_format format, GLenum pname)
 }
 
 
+GLuint
+_mesa_get_format_max_bits(mesa_format format)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   GLuint max = MAX2(info->RedBits, info->GreenBits);
+   max = MAX2(max, info->BlueBits);
+   max = MAX2(max, info->AlphaBits);
+   max = MAX2(max, info->LuminanceBits);
+   max = MAX2(max, info->IntensityBits);
+   max = MAX2(max, info->DepthBits);
+   max = MAX2(max, info->StencilBits);
+   return max;
+}
+
+
 /**
  * Return the data type (or more specifically, the data representation)
  * for the given format.
@@ -1622,7 +1911,7 @@ _mesa_get_format_bits(gl_format format, GLenum pname)
  *    GL_FLOAT = an ordinary float
  */
 GLenum
-_mesa_get_format_datatype(gl_format format)
+_mesa_get_format_datatype(mesa_format format)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
    return info->DataType;
@@ -1635,7 +1924,7 @@ _mesa_get_format_datatype(gl_format format)
  * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
  */
 GLenum
-_mesa_get_format_base_format(gl_format format)
+_mesa_get_format_base_format(mesa_format format)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
    return info->BaseFormat;
@@ -1650,7 +1939,7 @@ _mesa_get_format_base_format(gl_format format)
  * \param bh  returns block height in pixels
  */
 void
-_mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
+_mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
    *bw = info->BlockWidth;
@@ -1660,7 +1949,7 @@ _mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
 
 /** Is the given format a compressed format? */
 GLboolean
-_mesa_is_format_compressed(gl_format format)
+_mesa_is_format_compressed(mesa_format format)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
    return info->BlockWidth > 1 || info->BlockHeight > 1;
@@ -1671,7 +1960,7 @@ _mesa_is_format_compressed(gl_format format)
  * Determine if the given format represents a packed depth/stencil buffer.
  */
 GLboolean
-_mesa_is_format_packed_depth_stencil(gl_format format)
+_mesa_is_format_packed_depth_stencil(mesa_format format)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
 
@@ -1683,7 +1972,7 @@ _mesa_is_format_packed_depth_stencil(gl_format format)
  * Is the given format a signed/unsigned integer color format?
  */
 GLboolean
-_mesa_is_format_integer_color(gl_format format)
+_mesa_is_format_integer_color(mesa_format format)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
    return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) &&
@@ -1693,24 +1982,59 @@ _mesa_is_format_integer_color(gl_format format)
 }
 
 
+/**
+ * Is the given format an unsigned integer format?
+ */
+GLboolean
+_mesa_is_format_unsigned(mesa_format format)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   return _mesa_is_type_unsigned(info->DataType);
+}
+
+
+/**
+ * Does the given format store signed values?
+ */
+GLboolean
+_mesa_is_format_signed(mesa_format format)
+{
+   if (format == MESA_FORMAT_R11_G11_B10_FLOAT || 
+       format == MESA_FORMAT_RGB9_E5_FLOAT) {
+      /* these packed float formats only store unsigned values */
+      return GL_FALSE;
+   }
+   else {
+      const struct gl_format_info *info = _mesa_get_format_info(format);
+      return (info->DataType == GL_SIGNED_NORMALIZED ||
+              info->DataType == GL_INT ||
+              info->DataType == GL_FLOAT);
+   }
+}
+
+
 /**
  * Return color encoding for given format.
  * \return GL_LINEAR or GL_SRGB
  */
 GLenum
-_mesa_get_format_color_encoding(gl_format format)
+_mesa_get_format_color_encoding(mesa_format format)
 {
    /* XXX this info should be encoded in gl_format_info */
    switch (format) {
-   case MESA_FORMAT_SRGB8:
+   case MESA_FORMAT_BGR_SRGB8:
    case MESA_FORMAT_SRGBA8:
    case MESA_FORMAT_SARGB8:
-   case MESA_FORMAT_SL8:
+   case MESA_FORMAT_L_SRGB8:
    case MESA_FORMAT_SLA8:
    case MESA_FORMAT_SRGB_DXT1:
    case MESA_FORMAT_SRGBA_DXT1:
    case MESA_FORMAT_SRGBA_DXT3:
    case MESA_FORMAT_SRGBA_DXT5:
+   case MESA_FORMAT_XBGR8888_SRGB:
+   case MESA_FORMAT_ETC2_SRGB8:
+   case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
+   case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
       return GL_SRGB;
    default:
       return GL_LINEAR;
@@ -1722,21 +2046,21 @@ _mesa_get_format_color_encoding(gl_format format)
  * For an sRGB format, return the corresponding linear color space format.
  * For non-sRGB formats, return the format as-is.
  */
-gl_format
-_mesa_get_srgb_format_linear(gl_format format)
+mesa_format
+_mesa_get_srgb_format_linear(mesa_format format)
 {
    switch (format) {
-   case MESA_FORMAT_SRGB8:
-      format = MESA_FORMAT_RGB888;
+   case MESA_FORMAT_BGR_SRGB8:
+      format = MESA_FORMAT_BGR_UNORM8;
       break;
    case MESA_FORMAT_SRGBA8:
-      format = MESA_FORMAT_RGBA8888;
+      format = MESA_FORMAT_A8B8G8R8_UNORM;
       break;
    case MESA_FORMAT_SARGB8:
-      format = MESA_FORMAT_ARGB8888;
+      format = MESA_FORMAT_B8G8R8A8_UNORM;
       break;
-   case MESA_FORMAT_SL8:
-      format = MESA_FORMAT_L8;
+   case MESA_FORMAT_L_SRGB8:
+      format = MESA_FORMAT_L_UNORM8;
       break;
    case MESA_FORMAT_SLA8:
       format = MESA_FORMAT_AL88;
@@ -1753,6 +2077,18 @@ _mesa_get_srgb_format_linear(gl_format format)
    case MESA_FORMAT_SRGBA_DXT5:
       format = MESA_FORMAT_RGBA_DXT5;
       break;
+   case MESA_FORMAT_XBGR8888_SRGB:
+      format = MESA_FORMAT_R8G8B8X8_UNORM;
+      break;
+   case MESA_FORMAT_ETC2_SRGB8:
+      format = MESA_FORMAT_ETC2_RGB8;
+      break;
+   case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
+      format = MESA_FORMAT_ETC2_RGBA8_EAC;
+      break;
+   case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
+      format = MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
+      break;
    default:
       break;
    }
@@ -1764,28 +2100,28 @@ _mesa_get_srgb_format_linear(gl_format format)
  * If the given format is a compressed format, return a corresponding
  * uncompressed format.
  */
-gl_format
-_mesa_get_uncompressed_format(gl_format format)
+mesa_format
+_mesa_get_uncompressed_format(mesa_format format)
 {
    switch (format) {
    case MESA_FORMAT_RGB_FXT1:
-      return MESA_FORMAT_RGB888;
+      return MESA_FORMAT_BGR_UNORM8;
    case MESA_FORMAT_RGBA_FXT1:
-      return MESA_FORMAT_RGBA8888;
+      return MESA_FORMAT_A8B8G8R8_UNORM;
    case MESA_FORMAT_RGB_DXT1:
    case MESA_FORMAT_SRGB_DXT1:
-      return MESA_FORMAT_RGB888;
+      return MESA_FORMAT_BGR_UNORM8;
    case MESA_FORMAT_RGBA_DXT1:
    case MESA_FORMAT_SRGBA_DXT1:
-      return MESA_FORMAT_RGBA8888;
+      return MESA_FORMAT_A8B8G8R8_UNORM;
    case MESA_FORMAT_RGBA_DXT3:
    case MESA_FORMAT_SRGBA_DXT3:
-      return MESA_FORMAT_RGBA8888;
+      return MESA_FORMAT_A8B8G8R8_UNORM;
    case MESA_FORMAT_RGBA_DXT5:
    case MESA_FORMAT_SRGBA_DXT5:
-      return MESA_FORMAT_RGBA8888;
+      return MESA_FORMAT_A8B8G8R8_UNORM;
    case MESA_FORMAT_RED_RGTC1:
-      return MESA_FORMAT_R8;
+      return MESA_FORMAT_R_UNORM8;
    case MESA_FORMAT_SIGNED_RED_RGTC1:
       return MESA_FORMAT_SIGNED_R8;
    case MESA_FORMAT_RG_RGTC2:
@@ -1793,7 +2129,7 @@ _mesa_get_uncompressed_format(gl_format format)
    case MESA_FORMAT_SIGNED_RG_RGTC2:
       return MESA_FORMAT_SIGNED_RG88_REV;
    case MESA_FORMAT_L_LATC1:
-      return MESA_FORMAT_L8;
+      return MESA_FORMAT_L_UNORM8;
    case MESA_FORMAT_SIGNED_L_LATC1:
       return MESA_FORMAT_SIGNED_L8;
    case MESA_FORMAT_LA_LATC2:
@@ -1801,7 +2137,20 @@ _mesa_get_uncompressed_format(gl_format format)
    case MESA_FORMAT_SIGNED_LA_LATC2:
       return MESA_FORMAT_SIGNED_AL88;
    case MESA_FORMAT_ETC1_RGB8:
-      return MESA_FORMAT_RGB888;
+   case MESA_FORMAT_ETC2_RGB8:
+   case MESA_FORMAT_ETC2_SRGB8:
+      return MESA_FORMAT_BGR_UNORM8;
+   case MESA_FORMAT_ETC2_RGBA8_EAC:
+   case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
+   case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
+   case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
+      return MESA_FORMAT_A8B8G8R8_UNORM;
+   case MESA_FORMAT_ETC2_R11_EAC:
+   case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
+      return MESA_FORMAT_R_UNORM16;
+   case MESA_FORMAT_ETC2_RG11_EAC:
+   case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
+      return MESA_FORMAT_GR1616;
    default:
 #ifdef DEBUG
       assert(!_mesa_is_format_compressed(format));
@@ -1812,7 +2161,7 @@ _mesa_get_uncompressed_format(gl_format format)
 
 
 GLuint
-_mesa_format_num_components(gl_format format)
+_mesa_format_num_components(mesa_format format)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
    return ((info->RedBits > 0) +
@@ -1831,7 +2180,7 @@ _mesa_format_num_components(gl_format format)
  * in the given format.
  */
 GLuint
-_mesa_format_image_size(gl_format format, GLsizei width,
+_mesa_format_image_size(mesa_format format, GLsizei width,
                         GLsizei height, GLsizei depth)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
@@ -1842,8 +2191,7 @@ _mesa_format_image_size(gl_format format, GLsizei width,
       const GLuint wblocks = (width + bw - 1) / bw;
       const GLuint hblocks = (height + bh - 1) / bh;
       const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
-      assert(depth == 1);
-      return sz;
+      return sz * depth;
    }
    else {
       /* non-compressed */
@@ -1858,7 +2206,7 @@ _mesa_format_image_size(gl_format format, GLsizei width,
  * accomodate very large textures.
  */
 uint64_t
-_mesa_format_image_size64(gl_format format, GLsizei width,
+_mesa_format_image_size64(mesa_format format, GLsizei width,
                           GLsizei height, GLsizei depth)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
@@ -1869,8 +2217,7 @@ _mesa_format_image_size64(gl_format format, GLsizei width,
       const uint64_t wblocks = (width + bw - 1) / bw;
       const uint64_t hblocks = (height + bh - 1) / bh;
       const uint64_t sz = wblocks * hblocks * info->BytesPerBlock;
-      assert(depth == 1);
-      return sz;
+      return sz * depth;
    }
    else {
       /* non-compressed */
@@ -1885,7 +2232,7 @@ _mesa_format_image_size64(gl_format format, GLsizei width,
 
 
 GLint
-_mesa_format_row_stride(gl_format format, GLsizei width)
+_mesa_format_row_stride(mesa_format format, GLsizei width)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
    /* Strictly speaking, a conditional isn't needed here */
@@ -1912,7 +2259,7 @@ _mesa_format_row_stride(gl_format format, GLsizei width)
 static void
 check_format_to_type_and_comps(void)
 {
-   gl_format f;
+   mesa_format f;
 
    for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) {
       GLenum datatype = 0;
@@ -1933,7 +2280,7 @@ _mesa_test_formats(void)
 {
    GLuint i;
 
-   assert(Elements(format_info) == MESA_FORMAT_COUNT);
+   STATIC_ASSERT(Elements(format_info) == MESA_FORMAT_COUNT);
 
    for (i = 0; i < MESA_FORMAT_COUNT; i++) {
       const struct gl_format_info *info = _mesa_get_format_info(i);
@@ -2017,27 +2364,27 @@ _mesa_test_formats(void)
 
 
 /**
- * Return datatype and number of components per texel for the given gl_format.
+ * Return datatype and number of components per texel for the given mesa_format.
  * Only used for mipmap generation code.
  */
 void
-_mesa_format_to_type_and_comps(gl_format format,
+_mesa_format_to_type_and_comps(mesa_format format,
                                GLenum *datatype, GLuint *comps)
 {
    switch (format) {
-   case MESA_FORMAT_RGBA8888:
-   case MESA_FORMAT_RGBA8888_REV:
-   case MESA_FORMAT_ARGB8888:
-   case MESA_FORMAT_ARGB8888_REV:
-   case MESA_FORMAT_RGBX8888:
-   case MESA_FORMAT_RGBX8888_REV:
-   case MESA_FORMAT_XRGB8888:
-   case MESA_FORMAT_XRGB8888_REV:
+   case MESA_FORMAT_A8B8G8R8_UNORM:
+   case MESA_FORMAT_R8G8B8A8_UNORM:
+   case MESA_FORMAT_B8G8R8A8_UNORM:
+   case MESA_FORMAT_A8R8G8B8_UNORM:
+   case MESA_FORMAT_X8B8G8R8_UNORM:
+   case MESA_FORMAT_R8G8B8X8_UNORM:
+   case MESA_FORMAT_B8G8R8X8_UNORM:
+   case MESA_FORMAT_X8R8G8B8_UNORM:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 4;
       return;
-   case MESA_FORMAT_RGB888:
-   case MESA_FORMAT_BGR888:
+   case MESA_FORMAT_BGR_UNORM8:
+   case MESA_FORMAT_RGB_UNORM8:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 3;
       return;
@@ -2049,12 +2396,14 @@ _mesa_format_to_type_and_comps(gl_format format,
 
    case MESA_FORMAT_ARGB4444:
    case MESA_FORMAT_ARGB4444_REV:
+   case MESA_FORMAT_XRGB4444_UNORM:
       *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
       *comps = 4;
       return;
 
    case MESA_FORMAT_ARGB1555:
    case MESA_FORMAT_ARGB1555_REV:
+   case MESA_FORMAT_XRGB1555_UNORM:
       *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
       *comps = 4;
       return;
@@ -2077,23 +2426,23 @@ _mesa_format_to_type_and_comps(gl_format format,
    case MESA_FORMAT_AL88:
    case MESA_FORMAT_AL88_REV:
    case MESA_FORMAT_GR88:
-   case MESA_FORMAT_RG88_REV:
+   case MESA_FORMAT_RG88:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 2;
       return;
 
    case MESA_FORMAT_AL1616:
    case MESA_FORMAT_AL1616_REV:
+   case MESA_FORMAT_GR1616:
    case MESA_FORMAT_RG1616:
-   case MESA_FORMAT_RG1616_REV:
       *datatype = GL_UNSIGNED_SHORT;
       *comps = 2;
       return;
 
-   case MESA_FORMAT_R16:
-   case MESA_FORMAT_A16:
-   case MESA_FORMAT_L16:
-   case MESA_FORMAT_I16:
+   case MESA_FORMAT_R_UNORM16:
+   case MESA_FORMAT_A_UNORM16:
+   case MESA_FORMAT_L_UNORM16:
+   case MESA_FORMAT_I_UNORM16:
       *datatype = GL_UNSIGNED_SHORT;
       *comps = 1;
       return;
@@ -2103,11 +2452,11 @@ _mesa_format_to_type_and_comps(gl_format format,
       *comps = 3;
       return;
 
-   case MESA_FORMAT_A8:
-   case MESA_FORMAT_L8:
-   case MESA_FORMAT_I8:
-   case MESA_FORMAT_R8:
-   case MESA_FORMAT_S8:
+   case MESA_FORMAT_A_UNORM8:
+   case MESA_FORMAT_L_UNORM8:
+   case MESA_FORMAT_I_UNORM8:
+   case MESA_FORMAT_R_UNORM8:
+   case MESA_FORMAT_S_UINT8:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 1;
       return;
@@ -2128,7 +2477,7 @@ _mesa_format_to_type_and_comps(gl_format format,
       *comps = 2;
       return;
 
-   case MESA_FORMAT_Z16:
+   case MESA_FORMAT_Z_UNORM16:
       *datatype = GL_UNSIGNED_SHORT;
       *comps = 1;
       return;
@@ -2143,12 +2492,12 @@ _mesa_format_to_type_and_comps(gl_format format,
       *comps = 1;
       return;
 
-   case MESA_FORMAT_Z32:
+   case MESA_FORMAT_Z_UNORM32:
       *datatype = GL_UNSIGNED_INT;
       *comps = 1;
       return;
 
-   case MESA_FORMAT_Z32_FLOAT:
+   case MESA_FORMAT_Z_FLOAT32:
       *datatype = GL_FLOAT;
       *comps = 1;
       return;
@@ -2182,7 +2531,7 @@ _mesa_format_to_type_and_comps(gl_format format,
       *comps = 4;
       return;
 
-   case MESA_FORMAT_RGBA_16:
+   case MESA_FORMAT_RGBA_UNORM16:
       *datatype = GL_UNSIGNED_SHORT;
       *comps = 4;
       return;
@@ -2208,8 +2557,7 @@ _mesa_format_to_type_and_comps(gl_format format,
       *comps = 4;
       return;
 
-#if FEATURE_EXT_texture_sRGB
-   case MESA_FORMAT_SRGB8:
+   case MESA_FORMAT_BGR_SRGB8:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 3;
       return;
@@ -2218,7 +2566,7 @@ _mesa_format_to_type_and_comps(gl_format format,
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 4;
       return;
-   case MESA_FORMAT_SL8:
+   case MESA_FORMAT_L_SRGB8:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 1;
       return;
@@ -2226,24 +2574,17 @@ _mesa_format_to_type_and_comps(gl_format format,
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 2;
       return;
-#endif
 
-#if FEATURE_texture_fxt1
    case MESA_FORMAT_RGB_FXT1:
    case MESA_FORMAT_RGBA_FXT1:
-#endif
-#if FEATURE_texture_s3tc
    case MESA_FORMAT_RGB_DXT1:
    case MESA_FORMAT_RGBA_DXT1:
    case MESA_FORMAT_RGBA_DXT3:
    case MESA_FORMAT_RGBA_DXT5:
-#if FEATURE_EXT_texture_sRGB
    case MESA_FORMAT_SRGB_DXT1:
    case MESA_FORMAT_SRGBA_DXT1:
    case MESA_FORMAT_SRGBA_DXT3:
    case MESA_FORMAT_SRGBA_DXT5:
-#endif
-#endif
    case MESA_FORMAT_RED_RGTC1:
    case MESA_FORMAT_SIGNED_RED_RGTC1:
    case MESA_FORMAT_RG_RGTC2:
@@ -2253,6 +2594,16 @@ _mesa_format_to_type_and_comps(gl_format format,
    case MESA_FORMAT_LA_LATC2:
    case MESA_FORMAT_SIGNED_LA_LATC2:
    case MESA_FORMAT_ETC1_RGB8:
+   case MESA_FORMAT_ETC2_RGB8:
+   case MESA_FORMAT_ETC2_SRGB8:
+   case MESA_FORMAT_ETC2_RGBA8_EAC:
+   case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
+   case MESA_FORMAT_ETC2_R11_EAC:
+   case MESA_FORMAT_ETC2_RG11_EAC:
+   case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
+   case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
+   case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
+   case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
       /* XXX generate error instead? */
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 0;
@@ -2475,10 +2826,75 @@ _mesa_format_to_type_and_comps(gl_format format,
       return;
 
    case MESA_FORMAT_ARGB2101010_UINT:
+   case MESA_FORMAT_ABGR2101010_UINT:
+      *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_XBGR8888_SRGB:
+   case MESA_FORMAT_RGBX_UINT8:
+      *datatype = GL_UNSIGNED_BYTE;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_XBGR8888_SNORM:
+   case MESA_FORMAT_RGBX_SINT8:
+      *datatype = GL_BYTE;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_XRGB2101010_UNORM:
+      *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_RGBX_UNORM16:
+   case MESA_FORMAT_RGBX_UINT16:
+      *datatype = GL_UNSIGNED_SHORT;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_RGBX_SNORM16:
+   case MESA_FORMAT_RGBX_SINT16:
+      *datatype = GL_SHORT;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_RGBX_FLOAT16:
+      *datatype = GL_HALF_FLOAT;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_RGBX_FLOAT32:
+      *datatype = GL_FLOAT;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_RGBX_UINT32:
+      *datatype = GL_UNSIGNED_INT;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_RGBX_SINT32:
+      *datatype = GL_INT;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_ABGR2101010:
       *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
       *comps = 4;
       return;
 
+   case MESA_FORMAT_SIGNED_RG88:
+      *datatype = GL_BYTE;
+      *comps = 2;
+      return;
+
+   case MESA_FORMAT_SIGNED_RG1616:
+      *datatype = GL_SHORT;
+      *comps = 2;
+      return;
+
    case MESA_FORMAT_COUNT:
       assert(0);
       return;
@@ -2496,16 +2912,18 @@ _mesa_format_to_type_and_comps(gl_format format,
 }
 
 /**
- * Check if a gl_format exactly matches a GL formaat/type combination
+ * Check if a mesa_format exactly matches a GL format/type combination
  * such that we can use memcpy() from one to the other.
- *
- * Note: this matching assumes that GL_PACK/UNPACK_SWAP_BYTES is unset.
- *
+ * \param mesa_format  a MESA_FORMAT_x value
+ * \param format  the user-specified image format
+ * \param type  the user-specified image datatype
+ * \param swapBytes  typically the current pixel pack/unpack byteswap state
  * \return GL_TRUE if the formats match, GL_FALSE otherwise.
  */
 GLboolean
-_mesa_format_matches_format_and_type(gl_format gl_format,
-                                    GLenum format, GLenum type)
+_mesa_format_matches_format_and_type(mesa_format mesa_format,
+                                    GLenum format, GLenum type,
+                                     GLboolean swapBytes)
 {
    const GLboolean littleEndian = _mesa_little_endian();
 
@@ -2518,45 +2936,105 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
     * enums in formats.h.
     */
 
-   switch (gl_format) {
+   switch (mesa_format) {
 
    case MESA_FORMAT_NONE:
    case MESA_FORMAT_COUNT:
       return GL_FALSE;
 
-   case MESA_FORMAT_RGBA8888:
-      return ((format == GL_RGBA && (type == GL_UNSIGNED_INT_8_8_8_8 ||
-                                    (type == GL_UNSIGNED_BYTE && !littleEndian))) ||
-             (format == GL_ABGR_EXT && (type == GL_UNSIGNED_INT_8_8_8_8_REV ||
-                                        (type == GL_UNSIGNED_BYTE && littleEndian))));
+   case MESA_FORMAT_A8B8G8R8_UNORM:
+   case MESA_FORMAT_SRGBA8:
+      if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8 && !swapBytes)
+         return GL_TRUE;
 
-   case MESA_FORMAT_RGBA8888_REV:
-      return ((format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV));
+      if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV && swapBytes)
+         return GL_TRUE;
 
-   case MESA_FORMAT_ARGB8888:
-      return ((format == GL_BGRA && (type == GL_UNSIGNED_INT_8_8_8_8_REV ||
-                                    (type == GL_UNSIGNED_BYTE && littleEndian))));
+      if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !littleEndian)
+         return GL_TRUE;
 
-   case MESA_FORMAT_ARGB8888_REV:
-      return ((format == GL_BGRA && (type == GL_UNSIGNED_INT_8_8_8_8 ||
-                                    (type == GL_UNSIGNED_BYTE && !littleEndian))));
+      if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8_REV
+          && !swapBytes)
+         return GL_TRUE;
+
+      if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8
+          && swapBytes)
+         return GL_TRUE;
+
+      if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && littleEndian)
+         return GL_TRUE;
 
-   case MESA_FORMAT_RGBX8888:
-   case MESA_FORMAT_RGBX8888_REV:
       return GL_FALSE;
 
-   case MESA_FORMAT_XRGB8888:
-   case MESA_FORMAT_XRGB8888_REV:
+   case MESA_FORMAT_R8G8B8A8_UNORM:
+      if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
+          !swapBytes)
+         return GL_TRUE;
+
+      if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
+         return GL_TRUE;
+
+      if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && littleEndian)
+         return GL_TRUE;
+
+      if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8 &&
+          !swapBytes)
+         return GL_TRUE;
+
+      if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
+          swapBytes)
+         return GL_TRUE;
+
+      if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && !littleEndian)
+         return GL_TRUE;
+
       return GL_FALSE;
 
-   case MESA_FORMAT_RGB888:
-      return format == GL_RGB && type == GL_UNSIGNED_BYTE && littleEndian;
+   case MESA_FORMAT_B8G8R8A8_UNORM:
+   case MESA_FORMAT_SARGB8:
+      if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
+          !swapBytes)
+         return GL_TRUE;
+
+      if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
+         return GL_TRUE;
+
+      if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && littleEndian)
+         return GL_TRUE;
+
+      return GL_FALSE;
+
+   case MESA_FORMAT_A8R8G8B8_UNORM:
+      if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8 && !swapBytes)
+         return GL_TRUE;
 
-   case MESA_FORMAT_BGR888:
+      if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
+          swapBytes)
+         return GL_TRUE;
+
+      if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && !littleEndian)
+         return GL_TRUE;
+
+      return GL_FALSE;
+
+   case MESA_FORMAT_X8B8G8R8_UNORM:
+   case MESA_FORMAT_R8G8B8X8_UNORM:
+      return GL_FALSE;
+
+   case MESA_FORMAT_B8G8R8X8_UNORM:
+   case MESA_FORMAT_X8R8G8B8_UNORM:
       return GL_FALSE;
 
+   case MESA_FORMAT_BGR_UNORM8:
+   case MESA_FORMAT_BGR_SRGB8:
+      return format == GL_BGR && type == GL_UNSIGNED_BYTE && littleEndian;
+
+   case MESA_FORMAT_RGB_UNORM8:
+      return format == GL_RGB && type == GL_UNSIGNED_BYTE && littleEndian;
+
    case MESA_FORMAT_RGB565:
-      return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5;
+      return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 && !swapBytes;
+
    case MESA_FORMAT_RGB565_REV:
       /* Some of the 16-bit MESA_FORMATs that would seem to correspond to
        * GL_UNSIGNED_SHORT_* are byte-swapped instead of channel-reversed,
@@ -2565,90 +3043,103 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return GL_FALSE;
 
    case MESA_FORMAT_ARGB4444:
-      return format == GL_BGRA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV;
+      return format == GL_BGRA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV &&
+         !swapBytes;
+
    case MESA_FORMAT_ARGB4444_REV:
       return GL_FALSE;
 
    case MESA_FORMAT_RGBA5551:
-      return format == GL_RGBA && type == GL_UNSIGNED_SHORT_5_5_5_1;
+      return format == GL_RGBA && type == GL_UNSIGNED_SHORT_5_5_5_1 &&
+         !swapBytes;
 
    case MESA_FORMAT_ARGB1555:
-      return format == GL_BGRA && type == GL_UNSIGNED_SHORT_1_5_5_5_REV;
+      return format == GL_BGRA && type == GL_UNSIGNED_SHORT_1_5_5_5_REV &&
+         !swapBytes;
+
    case MESA_FORMAT_ARGB1555_REV:
       return GL_FALSE;
 
    case MESA_FORMAT_AL44:
       return GL_FALSE;
    case MESA_FORMAT_AL88:
+   case MESA_FORMAT_SLA8:
       return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE && littleEndian;
    case MESA_FORMAT_AL88_REV:
       return GL_FALSE;
 
    case MESA_FORMAT_AL1616:
-      return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_SHORT && littleEndian;
+      return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_SHORT && littleEndian && !swapBytes;
    case MESA_FORMAT_AL1616_REV:
       return GL_FALSE;
 
    case MESA_FORMAT_RGB332:
       return format == GL_RGB && type == GL_UNSIGNED_BYTE_3_3_2;
 
-   case MESA_FORMAT_A8:
+   case MESA_FORMAT_A_UNORM8:
       return format == GL_ALPHA && type == GL_UNSIGNED_BYTE;
-   case MESA_FORMAT_A16:
-      return format == GL_ALPHA && type == GL_UNSIGNED_SHORT && littleEndian;
-   case MESA_FORMAT_L8:
+   case MESA_FORMAT_A_UNORM16:
+      return format == GL_ALPHA && type == GL_UNSIGNED_SHORT && !swapBytes;
+   case MESA_FORMAT_L_UNORM8:
+   case MESA_FORMAT_L_SRGB8:
       return format == GL_LUMINANCE && type == GL_UNSIGNED_BYTE;
-   case MESA_FORMAT_L16:
-      return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT && littleEndian;
-   case MESA_FORMAT_I8:
+   case MESA_FORMAT_L_UNORM16:
+      return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT && !swapBytes;
+   case MESA_FORMAT_I_UNORM8:
       return format == GL_INTENSITY && type == GL_UNSIGNED_BYTE;
-   case MESA_FORMAT_I16:
-      return format == GL_INTENSITY && type == GL_UNSIGNED_SHORT && littleEndian;
+   case MESA_FORMAT_I_UNORM16:
+      return format == GL_INTENSITY && type == GL_UNSIGNED_SHORT && !swapBytes;
 
    case MESA_FORMAT_YCBCR:
+      return format == GL_YCBCR_MESA &&
+             ((type == GL_UNSIGNED_SHORT_8_8_MESA && littleEndian != swapBytes) ||
+              (type == GL_UNSIGNED_SHORT_8_8_REV_MESA && littleEndian == swapBytes));
    case MESA_FORMAT_YCBCR_REV:
-      return GL_FALSE;
+      return format == GL_YCBCR_MESA &&
+             ((type == GL_UNSIGNED_SHORT_8_8_MESA && littleEndian == swapBytes) ||
+              (type == GL_UNSIGNED_SHORT_8_8_REV_MESA && littleEndian != swapBytes));
 
-   case MESA_FORMAT_R8:
+   case MESA_FORMAT_R_UNORM8:
       return format == GL_RED && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_GR88:
       return format == GL_RG && type == GL_UNSIGNED_BYTE && littleEndian;
-   case MESA_FORMAT_RG88_REV:
+   case MESA_FORMAT_RG88:
       return GL_FALSE;
 
-   case MESA_FORMAT_R16:
-      return format == GL_RED && type == GL_UNSIGNED_SHORT && littleEndian;
+   case MESA_FORMAT_R_UNORM16:
+      return format == GL_RED && type == GL_UNSIGNED_SHORT &&
+         !swapBytes;
+   case MESA_FORMAT_GR1616:
+      return format == GL_RG && type == GL_UNSIGNED_SHORT && littleEndian &&
+         !swapBytes;
    case MESA_FORMAT_RG1616:
-      return format == GL_RG && type == GL_UNSIGNED_SHORT && littleEndian;
-   case MESA_FORMAT_RG1616_REV:
       return GL_FALSE;
 
    case MESA_FORMAT_ARGB2101010:
-      return format == GL_BGRA && type == GL_UNSIGNED_INT_2_10_10_10_REV;
+      return format == GL_BGRA && type == GL_UNSIGNED_INT_2_10_10_10_REV &&
+         !swapBytes;
 
    case MESA_FORMAT_Z24_S8:
-      return format == GL_DEPTH_STENCIL && type == GL_UNSIGNED_INT_24_8;
+      return format == GL_DEPTH_STENCIL && type == GL_UNSIGNED_INT_24_8 &&
+         !swapBytes;
    case MESA_FORMAT_Z24_X8:
    case MESA_FORMAT_S8_Z24:
       return GL_FALSE;
 
-   case MESA_FORMAT_Z16:
-      return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_SHORT;
+   case MESA_FORMAT_Z_UNORM16:
+      return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_SHORT &&
+         !swapBytes;
 
    case MESA_FORMAT_X8_Z24:
       return GL_FALSE;
 
-   case MESA_FORMAT_Z32:
-      return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_INT;
+   case MESA_FORMAT_Z_UNORM32:
+      return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_INT &&
+         !swapBytes;
 
-   case MESA_FORMAT_S8:
-      return GL_FALSE;
+   case MESA_FORMAT_S_UINT8:
+      return format == GL_STENCIL_INDEX && type == GL_UNSIGNED_BYTE;
 
-   case MESA_FORMAT_SRGB8:
-   case MESA_FORMAT_SRGBA8:
-   case MESA_FORMAT_SARGB8:
-   case MESA_FORMAT_SL8:
-   case MESA_FORMAT_SLA8:
    case MESA_FORMAT_SRGB_DXT1:
    case MESA_FORMAT_SRGBA_DXT1:
    case MESA_FORMAT_SRGBA_DXT3:
@@ -2664,53 +3155,59 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return GL_FALSE;
 
    case MESA_FORMAT_RGBA_FLOAT32:
-      return format == GL_RGBA && type == GL_FLOAT;
+      return format == GL_RGBA && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_RGBA_FLOAT16:
-      return format == GL_RGBA && type == GL_HALF_FLOAT;
+      return format == GL_RGBA && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_RGB_FLOAT32:
-      return format == GL_RGB && type == GL_FLOAT;
+      return format == GL_RGB && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_RGB_FLOAT16:
-      return format == GL_RGB && type == GL_HALF_FLOAT;
+      return format == GL_RGB && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_ALPHA_FLOAT32:
-      return format == GL_ALPHA && type == GL_FLOAT;
+      return format == GL_ALPHA && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_ALPHA_FLOAT16:
-      return format == GL_ALPHA && type == GL_HALF_FLOAT;
+      return format == GL_ALPHA && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_LUMINANCE_FLOAT32:
-      return format == GL_LUMINANCE && type == GL_FLOAT;
+      return format == GL_LUMINANCE && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_LUMINANCE_FLOAT16:
-      return format == GL_LUMINANCE && type == GL_HALF_FLOAT;
+      return format == GL_LUMINANCE && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
-      return format == GL_LUMINANCE_ALPHA && type == GL_FLOAT;
+      return format == GL_LUMINANCE_ALPHA && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
-      return format == GL_LUMINANCE_ALPHA && type == GL_HALF_FLOAT;
+      return format == GL_LUMINANCE_ALPHA && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_INTENSITY_FLOAT32:
-      return format == GL_INTENSITY && type == GL_FLOAT;
+      return format == GL_INTENSITY && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_INTENSITY_FLOAT16:
-      return format == GL_INTENSITY && type == GL_HALF_FLOAT;
+      return format == GL_INTENSITY && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_R_FLOAT32:
-      return format == GL_RED && type == GL_FLOAT;
+      return format == GL_RED && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_R_FLOAT16:
-      return format == GL_RED && type == GL_HALF_FLOAT;
+      return format == GL_RED && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_RG_FLOAT32:
-      return format == GL_RG && type == GL_FLOAT;
+      return format == GL_RG && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_RG_FLOAT16:
-      return format == GL_RG && type == GL_HALF_FLOAT;
+      return format == GL_RG && type == GL_HALF_FLOAT && !swapBytes;
 
-      /* FINISHME: What do we want to do for GL_EXT_texture_integer? */
    case MESA_FORMAT_ALPHA_UINT8:
+      return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_ALPHA_UINT16:
+      return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_SHORT &&
+             !swapBytes;
    case MESA_FORMAT_ALPHA_UINT32:
+      return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_INT &&
+             !swapBytes;
    case MESA_FORMAT_ALPHA_INT8:
+      return format == GL_ALPHA_INTEGER && type == GL_BYTE;
    case MESA_FORMAT_ALPHA_INT16:
+      return format == GL_ALPHA_INTEGER && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_ALPHA_INT32:
-      return GL_FALSE;
+      return format == GL_ALPHA_INTEGER && type == GL_INT && !swapBytes;
 
    case MESA_FORMAT_INTENSITY_UINT8:
    case MESA_FORMAT_INTENSITY_UINT16:
@@ -2718,65 +3215,140 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
    case MESA_FORMAT_INTENSITY_INT8:
    case MESA_FORMAT_INTENSITY_INT16:
    case MESA_FORMAT_INTENSITY_INT32:
+      /* GL_INTENSITY_INTEGER_EXT doesn't exist. */
       return GL_FALSE;
 
    case MESA_FORMAT_LUMINANCE_UINT8:
+      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_LUMINANCE_UINT16:
+      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_SHORT &&
+             !swapBytes;
    case MESA_FORMAT_LUMINANCE_UINT32:
+      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_INT &&
+             !swapBytes;
    case MESA_FORMAT_LUMINANCE_INT8:
+      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_BYTE;
    case MESA_FORMAT_LUMINANCE_INT16:
+      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_SHORT &&
+             !swapBytes;
    case MESA_FORMAT_LUMINANCE_INT32:
-      return GL_FALSE;
+      return format == GL_LUMINANCE_INTEGER_EXT && type == GL_INT && !swapBytes;
 
    case MESA_FORMAT_LUMINANCE_ALPHA_UINT8:
+      return format == GL_LUMINANCE_ALPHA_INTEGER_EXT &&
+             type == GL_UNSIGNED_BYTE && !swapBytes;
    case MESA_FORMAT_LUMINANCE_ALPHA_UINT16:
+      return format == GL_LUMINANCE_ALPHA_INTEGER_EXT &&
+             type == GL_UNSIGNED_SHORT && !swapBytes;
    case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
+      return format == GL_LUMINANCE_ALPHA_INTEGER_EXT &&
+             type == GL_UNSIGNED_INT && !swapBytes;
    case MESA_FORMAT_LUMINANCE_ALPHA_INT8:
+      return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && type == GL_BYTE &&
+             !swapBytes;
    case MESA_FORMAT_LUMINANCE_ALPHA_INT16:
+      return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && type == GL_SHORT &&
+             !swapBytes;
    case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
-      return GL_FALSE;
+      return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && type == GL_INT &&
+             !swapBytes;
 
    case MESA_FORMAT_R_INT8:
+      return format == GL_RED_INTEGER && type == GL_BYTE;
    case MESA_FORMAT_RG_INT8:
+      return format == GL_RG_INTEGER && type == GL_BYTE && !swapBytes;
    case MESA_FORMAT_RGB_INT8:
+      return format == GL_RGB_INTEGER && type == GL_BYTE && !swapBytes;
    case MESA_FORMAT_RGBA_INT8:
+      return format == GL_RGBA_INTEGER && type == GL_BYTE && !swapBytes;
    case MESA_FORMAT_R_INT16:
+      return format == GL_RED_INTEGER && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_RG_INT16:
+      return format == GL_RG_INTEGER && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_RGB_INT16:
+      return format == GL_RGB_INTEGER && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_RGBA_INT16:
+      return format == GL_RGBA_INTEGER && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_R_INT32:
+      return format == GL_RED_INTEGER && type == GL_INT && !swapBytes;
    case MESA_FORMAT_RG_INT32:
+      return format == GL_RG_INTEGER && type == GL_INT && !swapBytes;
    case MESA_FORMAT_RGB_INT32:
+      return format == GL_RGB_INTEGER && type == GL_INT && !swapBytes;
    case MESA_FORMAT_RGBA_INT32:
-      return GL_FALSE;
+      return format == GL_RGBA_INTEGER && type == GL_INT && !swapBytes;
 
    case MESA_FORMAT_R_UINT8:
+      return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_RG_UINT8:
+      return format == GL_RG_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes;
    case MESA_FORMAT_RGB_UINT8:
+      return format == GL_RGB_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes;
    case MESA_FORMAT_RGBA_UINT8:
+      return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_BYTE &&
+             !swapBytes;
    case MESA_FORMAT_R_UINT16:
+      return format == GL_RED_INTEGER && type == GL_UNSIGNED_SHORT &&
+             !swapBytes;
    case MESA_FORMAT_RG_UINT16:
+      return format == GL_RG_INTEGER && type == GL_UNSIGNED_SHORT && !swapBytes;
    case MESA_FORMAT_RGB_UINT16:
+      return format == GL_RGB_INTEGER && type == GL_UNSIGNED_SHORT &&
+             !swapBytes;
    case MESA_FORMAT_RGBA_UINT16:
+      return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_SHORT &&
+             !swapBytes;
    case MESA_FORMAT_R_UINT32:
+      return format == GL_RED_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
    case MESA_FORMAT_RG_UINT32:
+      return format == GL_RG_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
    case MESA_FORMAT_RGB_UINT32:
+      return format == GL_RGB_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
    case MESA_FORMAT_RGBA_UINT32:
-      return GL_FALSE;
+      return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
 
    case MESA_FORMAT_DUDV8:
+      return (format == GL_DU8DV8_ATI || format == GL_DUDV_ATI) &&
+             type == GL_BYTE && littleEndian && !swapBytes;
+
    case MESA_FORMAT_SIGNED_R8:
+      return format == GL_RED && type == GL_BYTE;
    case MESA_FORMAT_SIGNED_RG88_REV:
+      return format == GL_RG && type == GL_BYTE && littleEndian &&
+             !swapBytes;
    case MESA_FORMAT_SIGNED_RGBX8888:
+      return GL_FALSE;
+
    case MESA_FORMAT_SIGNED_RGBA8888:
+      if (format == GL_RGBA && type == GL_BYTE && !littleEndian)
+         return GL_TRUE;
+
+      if (format == GL_ABGR_EXT && type == GL_BYTE && littleEndian)
+         return GL_TRUE;
+
+      return GL_FALSE;
+
    case MESA_FORMAT_SIGNED_RGBA8888_REV:
+      if (format == GL_RGBA && type == GL_BYTE && littleEndian)
+         return GL_TRUE;
+
+      if (format == GL_ABGR_EXT && type == GL_BYTE && !littleEndian)
+         return GL_TRUE;
+
+      return GL_FALSE;
+
    case MESA_FORMAT_SIGNED_R16:
+      return format == GL_RED && type == GL_SHORT &&
+             !swapBytes;
    case MESA_FORMAT_SIGNED_GR1616:
+      return format == GL_RG && type == GL_SHORT && littleEndian && !swapBytes;
    case MESA_FORMAT_SIGNED_RGB_16:
+      return format == GL_RGB && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_SIGNED_RGBA_16:
-   case MESA_FORMAT_RGBA_16:
-      /* FINISHME: SNORM */
-      return GL_FALSE;
+      return format == GL_RGBA && type == GL_SHORT && !swapBytes;
+   case MESA_FORMAT_RGBA_UNORM16:
+      return format == GL_RGBA && type == GL_UNSIGNED_SHORT &&
+             !swapBytes;
 
    case MESA_FORMAT_RED_RGTC1:
    case MESA_FORMAT_SIGNED_RED_RGTC1:
@@ -2791,33 +3363,93 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
       return GL_FALSE;
 
    case MESA_FORMAT_ETC1_RGB8:
+   case MESA_FORMAT_ETC2_RGB8:
+   case MESA_FORMAT_ETC2_SRGB8:
+   case MESA_FORMAT_ETC2_RGBA8_EAC:
+   case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
+   case MESA_FORMAT_ETC2_R11_EAC:
+   case MESA_FORMAT_ETC2_RG11_EAC:
+   case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
+   case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
+   case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
+   case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
       return GL_FALSE;
 
    case MESA_FORMAT_SIGNED_A8:
+      return format == GL_ALPHA && type == GL_BYTE;
    case MESA_FORMAT_SIGNED_L8:
+      return format == GL_LUMINANCE && type == GL_BYTE;
    case MESA_FORMAT_SIGNED_AL88:
+      return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
+             littleEndian && !swapBytes;
    case MESA_FORMAT_SIGNED_I8:
+      return format == GL_INTENSITY && type == GL_BYTE;
    case MESA_FORMAT_SIGNED_A16:
+      return format == GL_ALPHA && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_SIGNED_L16:
+      return format == GL_LUMINANCE && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_SIGNED_AL1616:
+      return format == GL_LUMINANCE_ALPHA && type == GL_SHORT &&
+             littleEndian && !swapBytes;
    case MESA_FORMAT_SIGNED_I16:
-      /* FINISHME: SNORM */
-      return GL_FALSE;
+      return format == GL_INTENSITY && type == GL_SHORT && littleEndian &&
+             !swapBytes;
 
    case MESA_FORMAT_ARGB2101010_UINT:
-      return GL_FALSE;
+      return (format == GL_BGRA_INTEGER_EXT &&
+              type == GL_UNSIGNED_INT_2_10_10_10_REV &&
+              !swapBytes);
+
+   case MESA_FORMAT_ABGR2101010_UINT:
+      return (format == GL_RGBA_INTEGER_EXT &&
+              type == GL_UNSIGNED_INT_2_10_10_10_REV &&
+              !swapBytes);
 
    case MESA_FORMAT_RGB9_E5_FLOAT:
-      return format == GL_RGB && type == GL_UNSIGNED_INT_5_9_9_9_REV;
+      return format == GL_RGB && type == GL_UNSIGNED_INT_5_9_9_9_REV &&
+         !swapBytes;
+
    case MESA_FORMAT_R11_G11_B10_FLOAT:
-      return format == GL_RGB && type == GL_UNSIGNED_INT_10F_11F_11F_REV;
+      return format == GL_RGB && type == GL_UNSIGNED_INT_10F_11F_11F_REV &&
+         !swapBytes;
 
-   case MESA_FORMAT_Z32_FLOAT:
-      return format == GL_DEPTH_COMPONENT && type == GL_FLOAT;
+   case MESA_FORMAT_Z_FLOAT32:
+      return format == GL_DEPTH_COMPONENT && type == GL_FLOAT && !swapBytes;
 
    case MESA_FORMAT_Z32_FLOAT_X24S8:
+      return format == GL_DEPTH_STENCIL &&
+             type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV && !swapBytes;
+
+   case MESA_FORMAT_XRGB4444_UNORM:
+   case MESA_FORMAT_XRGB1555_UNORM:
+   case MESA_FORMAT_XBGR8888_SNORM:
+   case MESA_FORMAT_XBGR8888_SRGB:
+   case MESA_FORMAT_RGBX_UINT8:
+   case MESA_FORMAT_RGBX_SINT8:
+   case MESA_FORMAT_XRGB2101010_UNORM:
+   case MESA_FORMAT_RGBX_UNORM16:
+   case MESA_FORMAT_RGBX_SNORM16:
+   case MESA_FORMAT_RGBX_FLOAT16:
+   case MESA_FORMAT_RGBX_UINT16:
+   case MESA_FORMAT_RGBX_SINT16:
+   case MESA_FORMAT_RGBX_FLOAT32:
+   case MESA_FORMAT_RGBX_UINT32:
+   case MESA_FORMAT_RGBX_SINT32:
       return GL_FALSE;
+
+   case MESA_FORMAT_ABGR2101010:
+      return format == GL_RGBA && type == GL_UNSIGNED_INT_2_10_10_10_REV &&
+         !swapBytes;
+
+   case MESA_FORMAT_SIGNED_RG88:
+      return format == GL_RG && type == GL_BYTE && !littleEndian &&
+         !swapBytes;
+
+   case MESA_FORMAT_SIGNED_RG1616:
+      return format == GL_RG && type == GL_SHORT && !littleEndian &&
+         !swapBytes;
    }
 
    return GL_FALSE;
 }
+