dispatch: Make all API functions non-static.
[mesa.git] / src / mesa / main / format_pack.c
index e20e361c842a3f64d82fc0d83f021761c6c350d8..051fb40b90ea36fe470027799686d5e08ddc9289 100644 (file)
 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
 
 
+/** Helper struct for MESA_FORMAT_Z32_FLOAT_X24S8 */
+struct z32f_x24s8
+{
+   float z;
+   uint32_t x24s8;
+};
+
+
 typedef void (*pack_ubyte_rgba_row_func)(GLuint n,
                                          const GLubyte src[][4], void *dst);
 
@@ -997,6 +1005,32 @@ pack_float_ARGB2101010(const GLfloat src[4], void *dst)
 }
 
 
+/* MESA_FORMAT_ABGR2101010_UINT */
+
+static void
+pack_ubyte_ABGR2101010_UINT(const GLubyte src[4], void *dst)
+{
+   GLuint *d = ((GLuint *) dst);
+   GLushort r = UBYTE_TO_USHORT(src[RCOMP]);
+   GLushort g = UBYTE_TO_USHORT(src[GCOMP]);
+   GLushort b = UBYTE_TO_USHORT(src[BCOMP]);
+   GLushort a = UBYTE_TO_USHORT(src[ACOMP]);
+   *d = PACK_COLOR_2101010_US(a, b, g, r);
+}
+
+static void
+pack_float_ABGR2101010_UINT(const GLfloat src[4], void *dst)
+{
+   GLuint *d = ((GLuint *) dst);
+   GLushort r, g, b, a;
+   UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
+   UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
+   UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
+   UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]);
+   *d = PACK_COLOR_2101010_US(a, b, g, r);
+}
+
+
 /* MESA_FORMAT_SRGB8 */
 
 static void
@@ -1688,6 +1722,7 @@ _mesa_get_pack_ubyte_rgba_function(gl_format format)
       table[MESA_FORMAT_RG1616] = pack_ubyte_RG1616;
       table[MESA_FORMAT_RG1616_REV] = pack_ubyte_RG1616_REV;
       table[MESA_FORMAT_ARGB2101010] = pack_ubyte_ARGB2101010;
+      table[MESA_FORMAT_ABGR2101010_UINT] = pack_ubyte_ABGR2101010_UINT;
 
       /* should never convert RGBA to these formats */
       table[MESA_FORMAT_Z24_S8] = NULL;
@@ -1833,6 +1868,7 @@ _mesa_get_pack_float_rgba_function(gl_format format)
       table[MESA_FORMAT_RG1616] = pack_float_RG1616;
       table[MESA_FORMAT_RG1616_REV] = pack_float_RG1616_REV;
       table[MESA_FORMAT_ARGB2101010] = pack_float_ARGB2101010;
+      table[MESA_FORMAT_ABGR2101010_UINT] = pack_float_ABGR2101010_UINT;
 
       /* should never convert RGBA to these formats */
       table[MESA_FORMAT_Z24_S8] = NULL;
@@ -2212,7 +2248,7 @@ pack_uint_z_Z32_FLOAT(const GLuint *src, void *dst)
 {
    GLuint *d = ((GLuint *) dst);
    const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
-   *d = *src * scale;
+   *d = (GLuint) (*src * scale);
    assert(*d >= 0.0f);
    assert(*d <= 1.0f);
 }
@@ -2222,7 +2258,7 @@ pack_uint_z_Z32_FLOAT_X24S8(const GLuint *src, void *dst)
 {
    GLfloat *d = ((GLfloat *) dst);
    const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
-   *d = *src * scale;
+   *d = (GLfloat) (*src * scale);
    assert(*d >= 0.0f);
    assert(*d <= 1.0f);
 }
@@ -2372,10 +2408,10 @@ _mesa_pack_float_z_row(gl_format format, GLuint n,
       break;
    case MESA_FORMAT_Z32_FLOAT_X24S8:
       {
-         GLfloat *d = ((GLfloat *) dst);
+         struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
          GLuint i;
          for (i = 0; i < n; i++) {
-            d[i * 2] = src[i];
+            d[i].z = src[i];
          }
       }
       break;
@@ -2437,7 +2473,7 @@ _mesa_pack_uint_z_row(gl_format format, GLuint n,
          const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
          GLuint i;
          for (i = 0; i < n; i++) {
-            d[i] = src[i] * scale;
+            d[i] = (GLuint) (src[i] * scale);
             assert(d[i] >= 0.0f);
             assert(d[i] <= 1.0f);
          }
@@ -2445,13 +2481,13 @@ _mesa_pack_uint_z_row(gl_format format, GLuint n,
       break;
    case MESA_FORMAT_Z32_FLOAT_X24S8:
       {
-         GLfloat *d = ((GLfloat *) dst);
+         struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
          const GLdouble scale = 1.0 / (GLdouble) 0xffffffff;
          GLuint i;
          for (i = 0; i < n; i++) {
-            d[i * 2] = src[i] * scale;
-            assert(d[i * 2] >= 0.0f);
-            assert(d[i * 2] <= 1.0f);
+            d[i].z = (GLfloat) (src[i] * scale);
+            assert(d[i].z >= 0.0f);
+            assert(d[i].z <= 1.0f);
          }
       }
       break;
@@ -2495,10 +2531,10 @@ _mesa_pack_ubyte_stencil_row(gl_format format, GLuint n,
       break;
    case MESA_FORMAT_Z32_FLOAT_X24S8:
       {
-         GLuint *d = dst;
+         struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
          GLuint i;
          for (i = 0; i < n; i++) {
-            d[i * 2 + 1] = src[i];
+            d[i].x24s8 = src[i];
          }
       }
       break;
@@ -2533,13 +2569,12 @@ _mesa_pack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
    case MESA_FORMAT_Z32_FLOAT_X24S8:
       {
          const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
-         GLuint *destu = (GLuint *) dst;
-         GLfloat *destf = (GLfloat *) dst;
-         GLint i;
+         struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
+         GLuint i;
          for (i = 0; i < n; i++) {
-            GLfloat z = (src[i] >> 8) * scale;
-            destf[i * 2 + 0] = z;
-            destu[i * 2 + 1] = src[i] & 0xff;
+            GLfloat z = (GLfloat) ((src[i] >> 8) * scale);
+            d[i].z = z;
+            d[i].x24s8 = src[i];
          }
       }
       break;
@@ -2564,10 +2599,10 @@ _mesa_pack_colormask(gl_format format, const GLubyte colorMask[4], void *dst)
    switch (_mesa_get_format_datatype(format)) {
    case GL_UNSIGNED_NORMALIZED:
       /* simple: 1.0 will convert to ~0 in the right bit positions */
-      maskColor[0] = colorMask[0] ? 1.0 : 0.0;
-      maskColor[1] = colorMask[1] ? 1.0 : 0.0;
-      maskColor[2] = colorMask[2] ? 1.0 : 0.0;
-      maskColor[3] = colorMask[3] ? 1.0 : 0.0;
+      maskColor[0] = colorMask[0] ? 1.0f : 0.0f;
+      maskColor[1] = colorMask[1] ? 1.0f : 0.0f;
+      maskColor[2] = colorMask[2] ? 1.0f : 0.0f;
+      maskColor[3] = colorMask[3] ? 1.0f : 0.0f;
       _mesa_pack_float_rgba_row(format, 1,
                                 (const GLfloat (*)[4]) maskColor, dst);
       break;
@@ -2598,7 +2633,7 @@ _mesa_pack_colormask(gl_format format, const GLubyte colorMask[4], void *dst)
          if (bits == 8) {
             GLubyte *d = (GLubyte *) dst;
             for (i = 0; i < bytes; i++) {
-               d[i] = d[i] ? 0xffff : 0x0;
+               d[i] = d[i] ? 0xff : 0x0;
             }
          }
          else if (bits == 16) {