mesa: added unsigned 16-bit/channel tex format
authorBrian Paul <brianp@vmware.com>
Mon, 10 May 2010 01:28:10 +0000 (19:28 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 10 May 2010 03:19:42 +0000 (21:19 -0600)
src/mesa/main/formats.c
src/mesa/main/formats.h
src/mesa/main/texfetch.c
src/mesa/main/texfetch_tmp.h
src/mesa/main/texformat.c
src/mesa/main/texstore.c

index 7f57fc05d59926e268c2a33237fc62cb181c58af..3671140e85900234f246e366781d1f89a8d56073 100644 (file)
@@ -721,6 +721,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       16, 16, 16, 16,
       0, 0, 0, 0, 0,
       1, 1, 8
+   },
+   {
+      MESA_FORMAT_RGBA_16,
+      "MESA_FORMAT_RGBA_16",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      16, 16, 16, 16,
+      0, 0, 0, 0, 0,
+      1, 1, 8
    }
 };
 
index bfd4f20337e5f5a106b1a1da08ea7d46ea4871fb..c744688122f1fb010d105c813a1b4738f8312fde 100644 (file)
@@ -146,6 +146,7 @@ typedef enum
    MESA_FORMAT_SIGNED_RG_16,      /* ushort[0]=R, ushort[1]=G */
    MESA_FORMAT_SIGNED_RGB_16,     /* ushort[0]=R, ushort[1]=G, ushort[2]=B */
    MESA_FORMAT_SIGNED_RGBA_16,    /* ... */
+   MESA_FORMAT_RGBA_16,           /* ... */
    /*@}*/
 
    MESA_FORMAT_COUNT
index 48a22c194552d7d17446f0af56423e1d9d6a4b3e..3169f3b3f568dc0817f2b58d603c717bf9c6d2ef 100644 (file)
@@ -622,6 +622,13 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       fetch_texel_3d_signed_rgba_16,
       store_texel_signed_rgba_16
    },
+   {
+      MESA_FORMAT_RGBA_16,
+      fetch_texel_1d_rgba_16,
+      fetch_texel_2d_rgba_16,
+      fetch_texel_3d_rgba_16,
+      store_texel_rgba_16
+   }
 };
 
 
index 4df2b19181a458a780504d4a4b13f77d439ef107..280c8d9400d504179c91586170a473f7fcdc3b6e 100644 (file)
@@ -1374,7 +1374,7 @@ store_texel_signed_rg_16(struct gl_texture_image *texImage,
 #endif
 
 
-/* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
+/* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
 
 static void 
 FETCH(signed_rgb_16)(const struct gl_texture_image *texImage,
@@ -1430,6 +1430,35 @@ store_texel_signed_rgba_16(struct gl_texture_image *texImage,
 
 
 
+/* MESA_FORMAT_RGBA_16 ***********************************************/
+
+static void
+FETCH(rgba_16)(const struct gl_texture_image *texImage,
+               GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
+   texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
+   texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
+   texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
+   texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
+}
+
+#if DIM == 3
+static void
+store_texel_rgba_16(struct gl_texture_image *texImage,
+                    GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLushort *rgba = (const GLushort *) texel;
+   GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
+   dst[0] = rgba[RCOMP];
+   dst[1] = rgba[GCOMP];
+   dst[2] = rgba[BCOMP];
+   dst[3] = rgba[ACOMP];
+}
+#endif
+
+
+
 /* MESA_FORMAT_YCBCR *********************************************************/
 
 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
index 06e6fd92fca9cec593f03fcd9eb70659c41031f9..d235485721a69507e414d55880bdbf706706c24b 100644 (file)
@@ -61,12 +61,9 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
    (void) type;
 
    switch (internalFormat) {
-      /* RGBA formats */
+      /* shallow RGBA formats */
       case 4:
       case GL_RGBA:
-      case GL_RGB10_A2:
-      case GL_RGBA12:
-      case GL_RGBA16:
       case GL_RGBA8:
          return MESA_FORMAT_RGBA8888;
       case GL_RGB5_A1:
@@ -76,12 +73,15 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
       case GL_RGBA4:
          return MESA_FORMAT_ARGB4444;
 
-      /* RGB formats */
+      /* deep RGBA formats */
+      case GL_RGB10_A2:
+      case GL_RGBA12:
+      case GL_RGBA16:
+         return MESA_FORMAT_RGBA_16;
+
+      /* shallow RGB formats */
       case 3:
       case GL_RGB:
-      case GL_RGB10:
-      case GL_RGB12:
-      case GL_RGB16:
       case GL_RGB8:
          return MESA_FORMAT_RGB888;
       case GL_R3_G3_B2:
@@ -91,6 +91,12 @@ _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
       case GL_RGB5:
          return MESA_FORMAT_RGB565;
 
+      /* deep RGB formats */
+      case GL_RGB10:
+      case GL_RGB12:
+      case GL_RGB16:
+         return MESA_FORMAT_RGBA_16;
+
       /* Alpha formats */
       case GL_ALPHA:
       case GL_ALPHA4:
index 2356b24f4afb82a8b4bdbd1776257ce78f5aa32b..ce05652c935f3c7e44cfd7f8f77fa6e6e71a0c4c 100644 (file)
@@ -2224,6 +2224,70 @@ _mesa_texstore_al1616(TEXSTORE_PARAMS)
 }
 
 
+static GLboolean
+_mesa_texstore_rgba_16(TEXSTORE_PARAMS)
+{
+   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+   ASSERT(dstFormat == MESA_FORMAT_RGBA_16);
+   ASSERT(texelBytes == 8);
+
+   if (!ctx->_ImageTransferState &&
+       !srcPacking->SwapBytes &&
+       baseInternalFormat == GL_RGBA &&
+       srcFormat == GL_RGBA &&
+       srcType == GL_UNSIGNED_SHORT) {
+      /* simple memcpy path */
+      memcpy_texture(ctx, dims,
+                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+                     dstRowStride,
+                     dstImageOffsets,
+                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+                     srcAddr, srcPacking);
+   }
+   else {
+      /* general path */
+      const GLfloat *tempImage = make_temp_float_image(ctx, dims,
+                                                 baseInternalFormat,
+                                                 baseFormat,
+                                                 srcWidth, srcHeight, srcDepth,
+                                                 srcFormat, srcType, srcAddr,
+                                                 srcPacking);
+      const GLfloat *src = tempImage;
+      GLint img, row, col;
+      if (!tempImage)
+         return GL_FALSE;
+      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * texelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * texelBytes;
+         for (row = 0; row < srcHeight; row++) {
+            GLushort *dstUS = (GLushort *) dstRow;
+            for (col = 0; col < srcWidth; col++) {
+               GLushort r, g, b, a;
+
+               UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
+               UNCLAMPED_FLOAT_TO_USHORT(g, src[1]);
+               UNCLAMPED_FLOAT_TO_USHORT(b, src[2]);
+               UNCLAMPED_FLOAT_TO_USHORT(a, src[3]);
+               dstUS[col*4+0] = r;
+               dstUS[col*4+1] = g;
+               dstUS[col*4+2] = b;
+               dstUS[col*4+3] = a;
+               src += 4;
+            }
+            dstRow += dstRowStride;
+         }
+      }
+      free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
+
 static GLboolean
 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS)
 {
@@ -3420,7 +3484,8 @@ texstore_funcs[MESA_FORMAT_COUNT] =
    { MESA_FORMAT_SIGNED_R_16, _mesa_texstore_signed_rgba_16 },
    { MESA_FORMAT_SIGNED_RG_16, _mesa_texstore_signed_rgba_16 },
    { MESA_FORMAT_SIGNED_RGB_16, _mesa_texstore_signed_rgba_16 },
-   { MESA_FORMAT_SIGNED_RGBA_16, _mesa_texstore_signed_rgba_16 }
+   { MESA_FORMAT_SIGNED_RGBA_16, _mesa_texstore_signed_rgba_16 },
+   { MESA_FORMAT_RGBA_16, _mesa_texstore_rgba_16 }
 };