mesa: rename logging functions to reflect that they format strings
[mesa.git] / src / mesa / main / format_utils.c
index 30c7044e2f23c489d3867d498dc2eadd50294ffb..6959bf062a1210b0b0dba66425b73bd31daa6b2f 100644 (file)
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include "errors.h"
 #include "format_utils.h"
 #include "glformats.h"
 #include "format_pack.h"
 #include "format_unpack.h"
 
-const mesa_array_format RGBA8888_FLOAT =
+const mesa_array_format RGBA32_FLOAT =
    MESA_ARRAY_FORMAT(4, 1, 1, 1, 4, 0, 1, 2, 3);
 
-const mesa_array_format RGBA8888_UBYTE =
+const mesa_array_format RGBA8_UBYTE =
    MESA_ARRAY_FORMAT(1, 0, 0, 1, 4, 0, 1, 2, 3);
 
-const mesa_array_format RGBA8888_UINT =
+const mesa_array_format RGBA32_UINT =
    MESA_ARRAY_FORMAT(4, 0, 0, 0, 4, 0, 1, 2, 3);
 
-const mesa_array_format RGBA8888_INT =
+const mesa_array_format RGBA32_INT =
    MESA_ARRAY_FORMAT(4, 1, 0, 0, 4, 0, 1, 2, 3);
 
 static void
@@ -55,32 +56,6 @@ invert_swizzle(uint8_t dst[4], const uint8_t src[4])
             dst[i] = j;
 }
 
-static GLenum
-gl_type_for_array_format_datatype(enum mesa_array_format_datatype type)
-{
-   switch (type) {
-   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
-      return GL_UNSIGNED_BYTE;
-   case MESA_ARRAY_FORMAT_TYPE_USHORT:
-      return GL_UNSIGNED_SHORT;
-   case MESA_ARRAY_FORMAT_TYPE_UINT:
-      return GL_UNSIGNED_INT;
-   case MESA_ARRAY_FORMAT_TYPE_BYTE:
-      return GL_BYTE;
-   case MESA_ARRAY_FORMAT_TYPE_SHORT:
-      return GL_SHORT;
-   case MESA_ARRAY_FORMAT_TYPE_INT:
-      return GL_INT;
-   case MESA_ARRAY_FORMAT_TYPE_HALF:
-      return GL_HALF_FLOAT;
-   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
-      return GL_FLOAT;
-   default:
-      assert(!"Invalid datatype");
-      return GL_NONE;
-   }
-}
-
 /* Takes a src to RGBA swizzle and applies a rebase swizzle to it. This
  * is used when we need to rebase a format to match a different
  * base internal format.
@@ -201,10 +176,67 @@ _mesa_compute_rgba2base2rgba_component_mapping(GLenum baseFormat, uint8_t *map)
          return needRebase;
       }
    default:
-      assert(!"Unexpected base format");
+      unreachable("Unexpected base format");
    }
 }
 
+
+/**
+ * Special case conversion function to swap r/b channels from the source
+ * image to the dest image.
+ */
+static void
+convert_ubyte_rgba_to_bgra(size_t width, size_t height,
+                           const uint8_t *src, size_t src_stride,
+                           uint8_t *dst, size_t dst_stride)
+{
+   int row;
+
+   if (sizeof(void *) == 8 &&
+       src_stride % 8 == 0 &&
+       dst_stride % 8 == 0 &&
+       (GLsizeiptr) src % 8 == 0 &&
+       (GLsizeiptr) dst % 8 == 0) {
+      /* use 64-bit word to swizzle two 32-bit pixels.  We need 8-byte
+       * alignment for src/dst addresses and strides.
+       */
+      for (row = 0; row < height; row++) {
+         const GLuint64 *s = (const GLuint64 *) src;
+         GLuint64 *d = (GLuint64 *) dst;
+         int i;
+         for (i = 0; i < width/2; i++) {
+            d[i] = ( (s[i] & 0xff00ff00ff00ff00) |
+                    ((s[i] &       0xff000000ff) << 16) |
+                    ((s[i] &   0xff000000ff0000) >> 16));
+         }
+         if (width & 1) {
+            /* handle the case of odd widths */
+            const GLuint s = ((const GLuint *) src)[width - 1];
+            GLuint *d = (GLuint *) dst + width - 1;
+            *d = ( (s & 0xff00ff00) |
+                  ((s &       0xff) << 16) |
+                  ((s &   0xff0000) >> 16));
+         }
+         src += src_stride;
+         dst += dst_stride;
+      }
+   } else {
+      for (row = 0; row < height; row++) {
+         const GLuint *s = (const GLuint *) src;
+         GLuint *d = (GLuint *) dst;
+         int i;
+         for (i = 0; i < width; i++) {
+            d[i] = ( (s[i] & 0xff00ff00) |
+                    ((s[i] &       0xff) << 16) |
+                    ((s[i] &   0xff0000) >> 16));
+         }
+         src += src_stride;
+         dst += dst_stride;
+      }
+   }
+}
+
+
 /**
  * This can be used to convert between most color formats.
  *
@@ -243,7 +275,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
    bool src_format_is_mesa_array_format, dst_format_is_mesa_array_format;
    uint8_t src2dst[4], src2rgba[4], rgba2dst[4], dst2rgba[4];
    uint8_t rebased_src2rgba[4];
-   GLenum src_gl_type, dst_gl_type, common_gl_type;
+   enum mesa_array_format_datatype src_type = 0, dst_type = 0, common_type;
    bool normalized, dst_integer, src_integer, is_signed;
    int src_num_channels = 0, dst_num_channels = 0;
    uint8_t (*tmp_ubyte)[4];
@@ -281,9 +313,23 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
     * enable it for specific combinations that are known to work.
     */
    if (!rebase_swizzle) {
+      /* Do a direct memcpy where possible */
+      if ((dst_format_is_mesa_array_format &&
+           src_format_is_mesa_array_format &&
+           src_array_format == dst_array_format) ||
+          src_format == dst_format) {
+         int format_size = _mesa_get_format_bytes(src_format);
+         for (row = 0; row < height; row++) {
+            memcpy(dst, src, width * format_size);
+            src += src_stride;
+            dst += dst_stride;
+         }
+         return;
+      }
+
       /* Handle the cases where we can directly unpack */
       if (!src_format_is_mesa_array_format) {
-         if (dst_array_format == RGBA8888_FLOAT) {
+         if (dst_array_format == RGBA32_FLOAT) {
             for (row = 0; row < height; ++row) {
                _mesa_unpack_rgba_row(src_format, width,
                                      src, (float (*)[4])dst);
@@ -291,7 +337,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
                dst += dst_stride;
             }
             return;
-         } else if (dst_array_format == RGBA8888_UBYTE) {
+         } else if (dst_array_format == RGBA8_UBYTE) {
             assert(!_mesa_is_format_integer_color(src_format));
             for (row = 0; row < height; ++row) {
                _mesa_unpack_ubyte_rgba_row(src_format, width,
@@ -300,7 +346,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
                dst += dst_stride;
             }
             return;
-         } else if (dst_array_format == RGBA8888_UINT &&
+         } else if (dst_array_format == RGBA32_UINT &&
                     _mesa_is_format_unsigned(src_format)) {
             assert(_mesa_is_format_integer_color(src_format));
             for (row = 0; row < height; ++row) {
@@ -315,7 +361,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
 
       /* Handle the cases where we can directly pack */
       if (!dst_format_is_mesa_array_format) {
-         if (src_array_format == RGBA8888_FLOAT) {
+         if (src_array_format == RGBA32_FLOAT) {
             for (row = 0; row < height; ++row) {
                _mesa_pack_float_rgba_row(dst_format, width,
                                          (const float (*)[4])src, dst);
@@ -323,16 +369,23 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
                dst += dst_stride;
             }
             return;
-         } else if (src_array_format == RGBA8888_UBYTE) {
+         } else if (src_array_format == RGBA8_UBYTE) {
             assert(!_mesa_is_format_integer_color(dst_format));
-            for (row = 0; row < height; ++row) {
-               _mesa_pack_ubyte_rgba_row(dst_format, width,
-                                         (const uint8_t (*)[4])src, dst);
-               src += src_stride;
-               dst += dst_stride;
+
+            if (dst_format == MESA_FORMAT_B8G8R8A8_UNORM) {
+               convert_ubyte_rgba_to_bgra(width, height, src, src_stride,
+                                          dst, dst_stride);
+            }
+            else {
+               for (row = 0; row < height; ++row) {
+                  _mesa_pack_ubyte_rgba_row(dst_format, width,
+                                            (const uint8_t (*)[4])src, dst);
+                  src += src_stride;
+                  dst += dst_stride;
+               }
             }
             return;
-         } else if (src_array_format == RGBA8888_UINT &&
+         } else if (src_array_format == RGBA32_UINT &&
                     _mesa_is_format_unsigned(dst_format)) {
             assert(_mesa_is_format_integer_color(dst_format));
             for (row = 0; row < height; ++row) {
@@ -349,9 +402,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
    /* Handle conversions between array formats */
    normalized = false;
    if (src_array_format) {
-      enum mesa_array_format_datatype datatype =
-         _mesa_array_format_get_datatype(src_array_format);
-      src_gl_type = gl_type_for_array_format_datatype(datatype);
+      src_type = _mesa_array_format_get_datatype(src_array_format);
 
       src_num_channels = _mesa_array_format_get_num_channels(src_array_format);
 
@@ -361,9 +412,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
    }
 
    if (dst_array_format) {
-      enum mesa_array_format_datatype datatype =
-         _mesa_array_format_get_datatype(dst_array_format);
-      dst_gl_type = gl_type_for_array_format_datatype(datatype);
+      dst_type = _mesa_array_format_get_datatype(dst_array_format);
 
       dst_num_channels = _mesa_array_format_get_num_channels(dst_array_format);
 
@@ -381,8 +430,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
                                         src2dst);
 
       for (row = 0; row < height; ++row) {
-         _mesa_swizzle_and_convert(dst, dst_gl_type, dst_num_channels,
-                                   src, src_gl_type, src_num_channels,
+         _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
+                                   src, src_type, src_num_channels,
                                    src2dst, normalized, width);
          src += src_stride;
          dst += dst_stride;
@@ -464,13 +513,14 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
        * _mesa_swizzle_and_convert for signed formats, which is aware of the
        * truncation problem.
        */
-      common_gl_type = is_signed ? GL_INT : GL_UNSIGNED_INT;
+      common_type = is_signed ? MESA_ARRAY_FORMAT_TYPE_INT :
+                                MESA_ARRAY_FORMAT_TYPE_UINT;
       if (src_array_format) {
          compute_rebased_rgba_component_mapping(src2rgba, rebase_swizzle,
                                                 rebased_src2rgba);
          for (row = 0; row < height; ++row) {
-            _mesa_swizzle_and_convert(tmp_uint + row * width, common_gl_type, 4,
-                                      src, src_gl_type, src_num_channels,
+            _mesa_swizzle_and_convert(tmp_uint + row * width, common_type, 4,
+                                      src, src_type, src_num_channels,
                                       rebased_src2rgba, normalized, width);
             src += src_stride;
          }
@@ -479,8 +529,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
             _mesa_unpack_uint_rgba_row(src_format, width,
                                        src, tmp_uint + row * width);
             if (rebase_swizzle)
-               _mesa_swizzle_and_convert(tmp_uint + row * width, common_gl_type, 4,
-                                         tmp_uint + row * width, common_gl_type, 4,
+               _mesa_swizzle_and_convert(tmp_uint + row * width, common_type, 4,
+                                         tmp_uint + row * width, common_type, 4,
                                          rebase_swizzle, false, width);
             src += src_stride;
          }
@@ -492,8 +542,8 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
        */
       if (dst_format_is_mesa_array_format) {
          for (row = 0; row < height; ++row) {
-            _mesa_swizzle_and_convert(dst, dst_gl_type, dst_num_channels,
-                                      tmp_uint + row * width, common_gl_type, 4,
+            _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
+                                      tmp_uint + row * width, common_type, 4,
                                       rgba2dst, normalized, width);
             dst += dst_stride;
          }
@@ -513,8 +563,9 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
          compute_rebased_rgba_component_mapping(src2rgba, rebase_swizzle,
                                                 rebased_src2rgba);
          for (row = 0; row < height; ++row) {
-            _mesa_swizzle_and_convert(tmp_float + row * width, GL_FLOAT, 4,
-                                      src, src_gl_type, src_num_channels,
+            _mesa_swizzle_and_convert(tmp_float + row * width,
+                                      MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
+                                      src, src_type, src_num_channels,
                                       rebased_src2rgba, normalized, width);
             src += src_stride;
          }
@@ -523,17 +574,20 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
             _mesa_unpack_rgba_row(src_format, width,
                                   src, tmp_float + row * width);
             if (rebase_swizzle)
-               _mesa_swizzle_and_convert(tmp_float + row * width, GL_FLOAT, 4,
-                                         tmp_float + row * width, GL_FLOAT, 4,
-                                         rebase_swizzle, false, width);
+               _mesa_swizzle_and_convert(tmp_float + row * width,
+                                         MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
+                                         tmp_float + row * width,
+                                         MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
+                                         rebase_swizzle, normalized, width);
             src += src_stride;
          }
       }
 
       if (dst_format_is_mesa_array_format) {
          for (row = 0; row < height; ++row) {
-            _mesa_swizzle_and_convert(dst, dst_gl_type, dst_num_channels,
-                                      tmp_float + row * width, GL_FLOAT, 4,
+            _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
+                                      tmp_float + row * width,
+                                      MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
                                       rgba2dst, normalized, width);
             dst += dst_stride;
          }
@@ -553,8 +607,9 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
          compute_rebased_rgba_component_mapping(src2rgba, rebase_swizzle,
                                                 rebased_src2rgba);
          for (row = 0; row < height; ++row) {
-            _mesa_swizzle_and_convert(tmp_ubyte + row * width, GL_UNSIGNED_BYTE, 4,
-                                      src, src_gl_type, src_num_channels,
+            _mesa_swizzle_and_convert(tmp_ubyte + row * width,
+                                      MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
+                                      src, src_type, src_num_channels,
                                       rebased_src2rgba, normalized, width);
             src += src_stride;
          }
@@ -563,17 +618,20 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
             _mesa_unpack_ubyte_rgba_row(src_format, width,
                                         src, tmp_ubyte + row * width);
             if (rebase_swizzle)
-               _mesa_swizzle_and_convert(tmp_ubyte + row * width, GL_UNSIGNED_BYTE, 4,
-                                         tmp_ubyte + row * width, GL_UNSIGNED_BYTE, 4,
-                                         rebase_swizzle, false, width);
+               _mesa_swizzle_and_convert(tmp_ubyte + row * width,
+                                         MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
+                                         tmp_ubyte + row * width,
+                                         MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
+                                         rebase_swizzle, normalized, width);
             src += src_stride;
          }
       }
 
       if (dst_format_is_mesa_array_format) {
          for (row = 0; row < height; ++row) {
-            _mesa_swizzle_and_convert(dst, dst_gl_type, dst_num_channels,
-                                      tmp_ubyte + row * width, GL_UNSIGNED_BYTE, 4,
+            _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
+                                      tmp_ubyte + row * width,
+                                      MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
                                       rgba2dst, normalized, width);
             dst += dst_stride;
          }
@@ -623,7 +681,7 @@ _mesa_format_to_array(mesa_format format, GLenum *type, int *num_components,
 
    *normalized = !_mesa_is_format_integer(format);
 
-   _mesa_format_to_type_and_comps(format, type, &format_components);
+   _mesa_uncompressed_format_to_type_and_comps(format, type, &format_components);
 
    switch (_mesa_get_format_layout(format)) {
    case MESA_FORMAT_LAYOUT_ARRAY:
@@ -709,8 +767,12 @@ _mesa_format_to_array(mesa_format format, GLenum *type, int *num_components,
  *          operation with memcpy, false otherwise
  */
 static bool
-swizzle_convert_try_memcpy(void *dst, GLenum dst_type, int num_dst_channels,
-                           const void *src, GLenum src_type, int num_src_channels,
+swizzle_convert_try_memcpy(void *dst,
+                           enum mesa_array_format_datatype dst_type,
+                           int num_dst_channels,
+                           const void *src,
+                           enum mesa_array_format_datatype src_type,
+                           int num_src_channels,
                            const uint8_t swizzle[4], bool normalized, int count)
 {
    int i;
@@ -724,7 +786,8 @@ swizzle_convert_try_memcpy(void *dst, GLenum dst_type, int num_dst_channels,
       if (swizzle[i] != i && swizzle[i] != MESA_FORMAT_SWIZZLE_NONE)
          return false;
 
-   memcpy(dst, src, count * num_src_channels * _mesa_sizeof_type(src_type));
+   memcpy(dst, src, count * num_src_channels *
+          _mesa_array_format_datatype_get_size(src_type));
 
    return true;
 }
@@ -880,48 +943,48 @@ convert_float(void *void_dst, int num_dst_channels,
    const float one = 1.0f;
 
    switch (src_type) {
-   case GL_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
       SWIZZLE_CONVERT(float, float, src);
       break;
-   case GL_HALF_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
       SWIZZLE_CONVERT(float, uint16_t, _mesa_half_to_float(src));
       break;
-   case GL_UNSIGNED_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
       if (normalized) {
          SWIZZLE_CONVERT(float, uint8_t, _mesa_unorm_to_float(src, 8));
       } else {
          SWIZZLE_CONVERT(float, uint8_t, src);
       }
       break;
-   case GL_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
       if (normalized) {
          SWIZZLE_CONVERT(float, int8_t, _mesa_snorm_to_float(src, 8));
       } else {
          SWIZZLE_CONVERT(float, int8_t, src);
       }
       break;
-   case GL_UNSIGNED_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
       if (normalized) {
          SWIZZLE_CONVERT(float, uint16_t, _mesa_unorm_to_float(src, 16));
       } else {
          SWIZZLE_CONVERT(float, uint16_t, src);
       }
       break;
-   case GL_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
       if (normalized) {
          SWIZZLE_CONVERT(float, int16_t, _mesa_snorm_to_float(src, 16));
       } else {
          SWIZZLE_CONVERT(float, int16_t, src);
       }
       break;
-   case GL_UNSIGNED_INT:
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
       if (normalized) {
          SWIZZLE_CONVERT(float, uint32_t, _mesa_unorm_to_float(src, 32));
       } else {
          SWIZZLE_CONVERT(float, uint32_t, src);
       }
       break;
-   case GL_INT:
+   case MESA_ARRAY_FORMAT_TYPE_INT:
       if (normalized) {
          SWIZZLE_CONVERT(float, int32_t, _mesa_snorm_to_float(src, 32));
       } else {
@@ -942,48 +1005,48 @@ convert_half_float(void *void_dst, int num_dst_channels,
    const uint16_t one = _mesa_float_to_half(1.0f);
 
    switch (src_type) {
-   case GL_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
       SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_half(src));
       break;
-   case GL_HALF_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
       SWIZZLE_CONVERT(uint16_t, uint16_t, src);
       break;
-   case GL_UNSIGNED_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, uint8_t, _mesa_unorm_to_half(src, 8));
       } else {
          SWIZZLE_CONVERT(uint16_t, uint8_t, _mesa_float_to_half(src));
       }
       break;
-   case GL_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_snorm_to_half(src, 8));
       } else {
          SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_float_to_half(src));
       }
       break;
-   case GL_UNSIGNED_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_unorm_to_half(src, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_float_to_half(src));
       }
       break;
-   case GL_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_snorm_to_half(src, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_float_to_half(src));
       }
       break;
-   case GL_UNSIGNED_INT:
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_unorm_to_half(src, 32));
       } else {
          SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_float_to_half(src));
       }
       break;
-   case GL_INT:
+   case MESA_ARRAY_FORMAT_TYPE_INT:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, int32_t, _mesa_snorm_to_half(src, 32));
       } else {
@@ -1003,52 +1066,52 @@ convert_ubyte(void *void_dst, int num_dst_channels,
    const uint8_t one = normalized ? UINT8_MAX : 1;
 
    switch (src_type) {
-   case GL_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
       if (normalized) {
          SWIZZLE_CONVERT(uint8_t, float, _mesa_float_to_unorm(src, 8));
       } else {
          SWIZZLE_CONVERT(uint8_t, float, _mesa_float_to_unsigned(src, 8));
       }
       break;
-   case GL_HALF_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
       if (normalized) {
          SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_half_to_unorm(src, 8));
       } else {
          SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_half_to_unsigned(src, 8));
       }
       break;
-   case GL_UNSIGNED_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
       SWIZZLE_CONVERT(uint8_t, uint8_t, src);
       break;
-   case GL_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
       if (normalized) {
          SWIZZLE_CONVERT(uint8_t, int8_t, _mesa_snorm_to_unorm(src, 8, 8));
       } else {
          SWIZZLE_CONVERT(uint8_t, int8_t, _mesa_signed_to_unsigned(src, 8));
       }
       break;
-   case GL_UNSIGNED_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
       if (normalized) {
          SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_unorm_to_unorm(src, 16, 8));
       } else {
          SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_unsigned_to_unsigned(src, 8));
       }
       break;
-   case GL_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
       if (normalized) {
          SWIZZLE_CONVERT(uint8_t, int16_t, _mesa_snorm_to_unorm(src, 16, 8));
       } else {
          SWIZZLE_CONVERT(uint8_t, int16_t, _mesa_signed_to_unsigned(src, 8));
       }
       break;
-   case GL_UNSIGNED_INT:
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
       if (normalized) {
          SWIZZLE_CONVERT(uint8_t, uint32_t, _mesa_unorm_to_unorm(src, 32, 8));
       } else {
          SWIZZLE_CONVERT(uint8_t, uint32_t, _mesa_unsigned_to_unsigned(src, 8));
       }
       break;
-   case GL_INT:
+   case MESA_ARRAY_FORMAT_TYPE_INT:
       if (normalized) {
          SWIZZLE_CONVERT(uint8_t, int32_t, _mesa_snorm_to_unorm(src, 32, 8));
       } else {
@@ -1069,52 +1132,52 @@ convert_byte(void *void_dst, int num_dst_channels,
    const int8_t one = normalized ? INT8_MAX : 1;
 
    switch (src_type) {
-   case GL_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
       if (normalized) {
          SWIZZLE_CONVERT(uint8_t, float, _mesa_float_to_snorm(src, 8));
       } else {
          SWIZZLE_CONVERT(uint8_t, float, _mesa_float_to_signed(src, 8));
       }
       break;
-   case GL_HALF_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
       if (normalized) {
          SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_half_to_snorm(src, 8));
       } else {
          SWIZZLE_CONVERT(uint8_t, uint16_t, _mesa_half_to_signed(src, 8));
       }
       break;
-   case GL_UNSIGNED_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
       if (normalized) {
          SWIZZLE_CONVERT(int8_t, uint8_t, _mesa_unorm_to_snorm(src, 8, 8));
       } else {
          SWIZZLE_CONVERT(int8_t, uint8_t, _mesa_unsigned_to_signed(src, 8));
       }
       break;
-   case GL_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
       SWIZZLE_CONVERT(int8_t, int8_t, src);
       break;
-   case GL_UNSIGNED_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
       if (normalized) {
          SWIZZLE_CONVERT(int8_t, uint16_t, _mesa_unorm_to_snorm(src, 16, 8));
       } else {
          SWIZZLE_CONVERT(int8_t, uint16_t, _mesa_unsigned_to_signed(src, 8));
       }
       break;
-   case GL_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
       if (normalized) {
          SWIZZLE_CONVERT(int8_t, int16_t, _mesa_snorm_to_snorm(src, 16, 8));
       } else {
          SWIZZLE_CONVERT(int8_t, int16_t, _mesa_signed_to_signed(src, 8));
       }
       break;
-   case GL_UNSIGNED_INT:
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
       if (normalized) {
          SWIZZLE_CONVERT(int8_t, uint32_t, _mesa_unorm_to_snorm(src, 32, 8));
       } else {
          SWIZZLE_CONVERT(int8_t, uint32_t, _mesa_unsigned_to_signed(src, 8));
       }
       break;
-   case GL_INT:
+   case MESA_ARRAY_FORMAT_TYPE_INT:
       if (normalized) {
          SWIZZLE_CONVERT(int8_t, int32_t, _mesa_snorm_to_snorm(src, 32, 8));
       } else {
@@ -1135,52 +1198,52 @@ convert_ushort(void *void_dst, int num_dst_channels,
    const uint16_t one = normalized ? UINT16_MAX : 1;
    
    switch (src_type) {
-   case GL_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_unorm(src, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_unsigned(src, 16));
       }
       break;
-   case GL_HALF_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_half_to_unorm(src, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_half_to_unsigned(src, 16));
       }
       break;
-   case GL_UNSIGNED_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, uint8_t, _mesa_unorm_to_unorm(src, 8, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, uint8_t, src);
       }
       break;
-   case GL_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_snorm_to_unorm(src, 8, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, int8_t, _mesa_signed_to_unsigned(src, 16));
       }
       break;
-   case GL_UNSIGNED_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
       SWIZZLE_CONVERT(uint16_t, uint16_t, src);
       break;
-   case GL_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_snorm_to_unorm(src, 16, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, int16_t, _mesa_signed_to_unsigned(src, 16));
       }
       break;
-   case GL_UNSIGNED_INT:
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_unorm_to_unorm(src, 32, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, uint32_t, _mesa_unsigned_to_unsigned(src, 16));
       }
       break;
-   case GL_INT:
+   case MESA_ARRAY_FORMAT_TYPE_INT:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, int32_t, _mesa_snorm_to_unorm(src, 32, 16));
       } else {
@@ -1201,52 +1264,52 @@ convert_short(void *void_dst, int num_dst_channels,
    const int16_t one = normalized ? INT16_MAX : 1;
 
    switch (src_type) {
-   case GL_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_snorm(src, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, float, _mesa_float_to_signed(src, 16));
       }
       break;
-   case GL_HALF_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
       if (normalized) {
          SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_half_to_snorm(src, 16));
       } else {
          SWIZZLE_CONVERT(uint16_t, uint16_t, _mesa_half_to_signed(src, 16));
       }
       break;
-   case GL_UNSIGNED_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
       if (normalized) {
          SWIZZLE_CONVERT(int16_t, uint8_t, _mesa_unorm_to_snorm(src, 8, 16));
       } else {
          SWIZZLE_CONVERT(int16_t, uint8_t, src);
       }
       break;
-   case GL_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
       if (normalized) {
          SWIZZLE_CONVERT(int16_t, int8_t, _mesa_snorm_to_snorm(src, 8, 16));
       } else {
          SWIZZLE_CONVERT(int16_t, int8_t, src);
       }
       break;
-   case GL_UNSIGNED_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
       if (normalized) {
          SWIZZLE_CONVERT(int16_t, uint16_t, _mesa_unorm_to_snorm(src, 16, 16));
       } else {
          SWIZZLE_CONVERT(int16_t, uint16_t, _mesa_unsigned_to_signed(src, 16));
       }
       break;
-   case GL_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
       SWIZZLE_CONVERT(int16_t, int16_t, src);
       break;
-   case GL_UNSIGNED_INT:
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
       if (normalized) {
          SWIZZLE_CONVERT(int16_t, uint32_t, _mesa_unorm_to_snorm(src, 32, 16));
       } else {
          SWIZZLE_CONVERT(int16_t, uint32_t, _mesa_unsigned_to_signed(src, 16));
       }
       break;
-   case GL_INT:
+   case MESA_ARRAY_FORMAT_TYPE_INT:
       if (normalized) {
          SWIZZLE_CONVERT(int16_t, int32_t, _mesa_snorm_to_snorm(src, 32, 16));
       } else {
@@ -1266,52 +1329,52 @@ convert_uint(void *void_dst, int num_dst_channels,
    const uint32_t one = normalized ? UINT32_MAX : 1;
 
    switch (src_type) {
-   case GL_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
       if (normalized) {
          SWIZZLE_CONVERT(uint32_t, float, _mesa_float_to_unorm(src, 32));
       } else {
          SWIZZLE_CONVERT(uint32_t, float, _mesa_float_to_unsigned(src, 32));
       }
       break;
-   case GL_HALF_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
       if (normalized) {
          SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_half_to_unorm(src, 32));
       } else {
          SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_half_to_unsigned(src, 32));
       }
       break;
-   case GL_UNSIGNED_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
       if (normalized) {
          SWIZZLE_CONVERT(uint32_t, uint8_t, _mesa_unorm_to_unorm(src, 8, 32));
       } else {
          SWIZZLE_CONVERT(uint32_t, uint8_t, src);
       }
       break;
-   case GL_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
       if (normalized) {
          SWIZZLE_CONVERT(uint32_t, int8_t, _mesa_snorm_to_unorm(src, 8, 32));
       } else {
          SWIZZLE_CONVERT(uint32_t, int8_t, _mesa_signed_to_unsigned(src, 32));
       }
       break;
-   case GL_UNSIGNED_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
       if (normalized) {
          SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_unorm_to_unorm(src, 16, 32));
       } else {
          SWIZZLE_CONVERT(uint32_t, uint16_t, src);
       }
       break;
-   case GL_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
       if (normalized) {
          SWIZZLE_CONVERT(uint32_t, int16_t, _mesa_snorm_to_unorm(src, 16, 32));
       } else {
          SWIZZLE_CONVERT(uint32_t, int16_t, _mesa_signed_to_unsigned(src, 32));
       }
       break;
-   case GL_UNSIGNED_INT:
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
       SWIZZLE_CONVERT(uint32_t, uint32_t, src);
       break;
-   case GL_INT:
+   case MESA_ARRAY_FORMAT_TYPE_INT:
       if (normalized) {
          SWIZZLE_CONVERT(uint32_t, int32_t, _mesa_snorm_to_unorm(src, 32, 32));
       } else {
@@ -1332,56 +1395,56 @@ convert_int(void *void_dst, int num_dst_channels,
    const int32_t one = normalized ? INT32_MAX : 1;
 
    switch (src_type) {
-   case GL_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
       if (normalized) {
          SWIZZLE_CONVERT(uint32_t, float, _mesa_float_to_snorm(src, 32));
       } else {
          SWIZZLE_CONVERT(uint32_t, float, _mesa_float_to_signed(src, 32));
       }
       break;
-   case GL_HALF_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
       if (normalized) {
          SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_half_to_snorm(src, 32));
       } else {
          SWIZZLE_CONVERT(uint32_t, uint16_t, _mesa_half_to_signed(src, 32));
       }
       break;
-   case GL_UNSIGNED_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
       if (normalized) {
          SWIZZLE_CONVERT(int32_t, uint8_t, _mesa_unorm_to_snorm(src, 8, 32));
       } else {
          SWIZZLE_CONVERT(int32_t, uint8_t, src);
       }
       break;
-   case GL_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
       if (normalized) {
          SWIZZLE_CONVERT(int32_t, int8_t, _mesa_snorm_to_snorm(src, 8, 32));
       } else {
          SWIZZLE_CONVERT(int32_t, int8_t, src);
       }
       break;
-   case GL_UNSIGNED_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
       if (normalized) {
          SWIZZLE_CONVERT(int32_t, uint16_t, _mesa_unorm_to_snorm(src, 16, 32));
       } else {
          SWIZZLE_CONVERT(int32_t, uint16_t, src);
       }
       break;
-   case GL_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
       if (normalized) {
          SWIZZLE_CONVERT(int32_t, int16_t, _mesa_snorm_to_snorm(src, 16, 32));
       } else {
          SWIZZLE_CONVERT(int32_t, int16_t, src);
       }
       break;
-   case GL_UNSIGNED_INT:
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
       if (normalized) {
          SWIZZLE_CONVERT(int32_t, uint32_t, _mesa_unorm_to_snorm(src, 32, 32));
       } else {
          SWIZZLE_CONVERT(int32_t, uint32_t, _mesa_unsigned_to_signed(src, 32));
       }
       break;
-   case GL_INT:
+   case MESA_ARRAY_FORMAT_TYPE_INT:
       SWIZZLE_CONVERT(int32_t, int32_t, src);
       break;
    default:
@@ -1439,8 +1502,8 @@ convert_int(void *void_dst, int num_dst_channels,
  * \param[in]  count             the number of pixels to convert
  */
 void
-_mesa_swizzle_and_convert(void *void_dst, GLenum dst_type, int num_dst_channels,
-                          const void *void_src, GLenum src_type, int num_src_channels,
+_mesa_swizzle_and_convert(void *void_dst, enum mesa_array_format_datatype dst_type, int num_dst_channels,
+                          const void *void_src, enum mesa_array_format_datatype src_type, int num_src_channels,
                           const uint8_t swizzle[4], bool normalized, int count)
 {
    if (swizzle_convert_try_memcpy(void_dst, dst_type, num_dst_channels,
@@ -1449,35 +1512,35 @@ _mesa_swizzle_and_convert(void *void_dst, GLenum dst_type, int num_dst_channels,
       return;
 
    switch (dst_type) {
-   case GL_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
       convert_float(void_dst, num_dst_channels, void_src, src_type,
                     num_src_channels, swizzle, normalized, count);
       break;
-   case GL_HALF_FLOAT:
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
       convert_half_float(void_dst, num_dst_channels, void_src, src_type,
                     num_src_channels, swizzle, normalized, count);
       break;
-   case GL_UNSIGNED_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
       convert_ubyte(void_dst, num_dst_channels, void_src, src_type,
                     num_src_channels, swizzle, normalized, count);
       break;
-   case GL_BYTE:
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
       convert_byte(void_dst, num_dst_channels, void_src, src_type,
                    num_src_channels, swizzle, normalized, count);
       break;
-   case GL_UNSIGNED_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
       convert_ushort(void_dst, num_dst_channels, void_src, src_type,
                      num_src_channels, swizzle, normalized, count);
       break;
-   case GL_SHORT:
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
       convert_short(void_dst, num_dst_channels, void_src, src_type,
                     num_src_channels, swizzle, normalized, count);
       break;
-   case GL_UNSIGNED_INT:
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
       convert_uint(void_dst, num_dst_channels, void_src, src_type,
                    num_src_channels, swizzle, normalized, count);
       break;
-   case GL_INT:
+   case MESA_ARRAY_FORMAT_TYPE_INT:
       convert_int(void_dst, num_dst_channels, void_src, src_type,
                   num_src_channels, swizzle, normalized, count);
       break;