glapi / teximage: implement EGLImageTargetTexStorageEXT
[mesa.git] / src / mesa / main / pack.c
index d1f368c79fde664c45c98b708bf0b7abbcd0de4a..64ad115f8b5a25d6c9427e4279d81695aae2dff0 100644 (file)
@@ -42,8 +42,8 @@
 #endif
 
 
+#include "errors.h"
 #include "glheader.h"
-#include "colormac.h"
 #include "enums.h"
 #include "image.h"
 #include "imports.h"
@@ -155,7 +155,7 @@ _mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source,
    if (!source)
       return;
 
-   width_in_bytes = CEILING( width, 8 );
+   width_in_bytes = DIV_ROUND_UP( width, 8 );
    src = source;
    for (row = 0; row < height; row++) {
       GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, dest,
@@ -257,9 +257,9 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
                      GLenum srcFormat, GLenum srcType, const GLvoid *src,
                      const struct gl_pixelstore_attrib *unpack )
 {
-   ASSERT(srcFormat == GL_COLOR_INDEX || srcFormat == GL_STENCIL_INDEX);
+   assert(srcFormat == GL_COLOR_INDEX || srcFormat == GL_STENCIL_INDEX);
 
-   ASSERT(srcType == GL_BITMAP ||
+   assert(srcType == GL_BITMAP ||
           srcType == GL_UNSIGNED_BYTE ||
           srcType == GL_BYTE ||
           srcType == GL_UNSIGNED_SHORT ||
@@ -268,6 +268,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
           srcType == GL_INT ||
           srcType == GL_UNSIGNED_INT_24_8_EXT ||
           srcType == GL_HALF_FLOAT_ARB ||
+          srcType == GL_HALF_FLOAT_OES ||
           srcType == GL_FLOAT ||
           srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
 
@@ -407,6 +408,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
          }
          break;
       case GL_HALF_FLOAT_ARB:
+      case GL_HALF_FLOAT_OES:
          {
             GLuint i;
             const GLhalfARB *s = (const GLhalfARB *) src;
@@ -459,27 +461,11 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
          break;
 
       default:
-         _mesa_problem(NULL, "bad srcType in extract_uint_indexes");
-         return;
+         unreachable("bad srcType in extract_uint_indexes");
    }
 }
 
 
-static inline GLuint
-clamp_float_to_uint(GLfloat f)
-{
-   return f < 0.0F ? 0 : F_TO_I(f);
-}
-
-
-static inline GLuint
-clamp_half_to_uint(GLhalfARB h)
-{
-   GLfloat f = _mesa_half_to_float(h);
-   return f < 0.0F ? 0 : F_TO_I(f);
-}
-
-
 /*
  * Unpack a row of stencil data from a client buffer according to
  * the pixel unpacking parameters.
@@ -501,7 +487,7 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
                            const struct gl_pixelstore_attrib *srcPacking,
                            GLbitfield transferOps )
 {
-   ASSERT(srcType == GL_BITMAP ||
+   assert(srcType == GL_BITMAP ||
           srcType == GL_UNSIGNED_BYTE ||
           srcType == GL_BYTE ||
           srcType == GL_UNSIGNED_SHORT ||
@@ -510,10 +496,11 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
           srcType == GL_INT ||
           srcType == GL_UNSIGNED_INT_24_8_EXT ||
           srcType == GL_HALF_FLOAT_ARB ||
+          srcType == GL_HALF_FLOAT_OES ||
           srcType == GL_FLOAT ||
           srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
 
-   ASSERT(dstType == GL_UNSIGNED_BYTE ||
+   assert(dstType == GL_UNSIGNED_BYTE ||
           dstType == GL_UNSIGNED_SHORT ||
           dstType == GL_UNSIGNED_INT ||
           dstType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
@@ -598,7 +585,7 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
             }
             break;
          default:
-            _mesa_problem(ctx, "bad dstType in _mesa_unpack_stencil_span");
+            unreachable("bad dstType in _mesa_unpack_stencil_span");
       }
 
       free(indexes);
@@ -700,6 +687,7 @@ _mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
       }
       break;
    case GL_HALF_FLOAT_ARB:
+   case GL_HALF_FLOAT_OES:
       {
          GLhalfARB *dst = (GLhalfARB *) dest;
          GLuint i;
@@ -744,7 +732,7 @@ _mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
       }
       break;
    default:
-      _mesa_problem(ctx, "bad type in _mesa_pack_index_span");
+      unreachable("bad type in _mesa_pack_index_span");
    }
 
    free(stencil);
@@ -792,7 +780,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
     * back to an int type can introduce errors that will show up as
     * artifacts in things like depth peeling which uses glCopyTexImage.
     */
-   if (ctx->Pixel.DepthScale == 1.0 && ctx->Pixel.DepthBias == 0.0) {
+   if (ctx->Pixel.DepthScale == 1.0F && ctx->Pixel.DepthBias == 0.0F) {
       if (srcType == GL_UNSIGNED_INT && dstType == GL_UNSIGNED_SHORT) {
          const GLuint *src = (const GLuint *) source;
          GLushort *dst = (GLushort *) dest;
@@ -870,8 +858,8 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
       case GL_UNSIGNED_INT_24_8_EXT: /* GL_EXT_packed_depth_stencil */
          if (dstType == GL_UNSIGNED_INT_24_8_EXT &&
              depthMax == 0xffffff &&
-             ctx->Pixel.DepthScale == 1.0 &&
-             ctx->Pixel.DepthBias == 0.0) {
+             ctx->Pixel.DepthScale == 1.0F &&
+             ctx->Pixel.DepthBias == 0.0F) {
             const GLuint *src = (const GLuint *) source;
             GLuint *zValues = (GLuint *) dest;
             GLuint i;
@@ -917,6 +905,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
          needClamp = GL_TRUE;
          break;
       case GL_HALF_FLOAT_ARB:
+      case GL_HALF_FLOAT_OES:
          {
             GLuint i;
             const GLhalfARB *src = (const GLhalfARB *) source;
@@ -940,7 +929,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
    {
       const GLfloat scale = ctx->Pixel.DepthScale;
       const GLfloat bias = ctx->Pixel.DepthBias;
-      if (scale != 1.0 || bias != 0.0) {
+      if (scale != 1.0F || bias != 0.0F) {
          GLuint i;
          for (i = 0; i < n; i++) {
             depthValues[i] = depthValues[i] * scale + bias;
@@ -953,7 +942,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
    if (needClamp) {
       GLuint i;
       for (i = 0; i < n; i++) {
-         depthValues[i] = (GLfloat)CLAMP(depthValues[i], 0.0, 1.0);
+         depthValues[i] = CLAMP(depthValues[i], 0.0F, 1.0F);
       }
    }
 
@@ -983,7 +972,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
    else if (dstType == GL_UNSIGNED_SHORT) {
       GLushort *zValues = (GLushort *) dest;
       GLuint i;
-      ASSERT(depthMax <= 0xffff);
+      assert(depthMax <= 0xffff);
       for (i = 0; i < n; i++) {
          zValues[i] = (GLushort) (depthValues[i] * (GLfloat) depthMax);
       }
@@ -999,7 +988,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
       }
    }
    else {
-      ASSERT(0);
+      assert(0);
    }
 
    free(depthTemp);
@@ -1020,7 +1009,7 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
       return;
    }
 
-   if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
+   if (ctx->Pixel.DepthScale != 1.0F || ctx->Pixel.DepthBias != 0.0F) {
       memcpy(depthCopy, depthSpan, n * sizeof(GLfloat));
       _mesa_scale_and_bias_depth(ctx, n, depthCopy);
       depthSpan = depthCopy;
@@ -1069,6 +1058,21 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
          }
       }
       break;
+   case GL_UNSIGNED_INT_24_8:
+      {
+         const GLdouble scale = (GLdouble) 0xffffff;
+         GLuint *dst = (GLuint *) dest;
+         GLuint i;
+         for (i = 0; i < n; i++) {
+            GLuint z = (GLuint) (depthSpan[i] * scale);
+            assert(z <= 0xffffff);
+            dst[i] = (z << 8);
+         }
+         if (dstPacking->SwapBytes) {
+            _mesa_swap4( (GLuint *) dst, n );
+         }
+         break;
+      }
    case GL_UNSIGNED_INT:
       {
          GLuint *dst = (GLuint *) dest;
@@ -1106,6 +1110,7 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
       }
       break;
    case GL_HALF_FLOAT_ARB:
+   case GL_HALF_FLOAT_OES:
       {
          GLhalfARB *dst = (GLhalfARB *) dest;
          GLuint i;
@@ -1118,7 +1123,7 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
       }
       break;
    default:
-      _mesa_problem(ctx, "bad type in _mesa_pack_depth_span");
+      unreachable("bad type in _mesa_pack_depth_span()");
    }
 
    free(depthCopy);
@@ -1147,7 +1152,7 @@ _mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n,
       return;
    }
 
-   if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
+   if (ctx->Pixel.DepthScale != 1.0F || ctx->Pixel.DepthBias != 0.0F) {
       memcpy(depthCopy, depthVals, n * sizeof(GLfloat));
       _mesa_scale_and_bias_depth(ctx, n, depthCopy);
       depthVals = depthCopy;
@@ -1481,20 +1486,20 @@ _mesa_pack_luminance_from_rgba_integer(GLuint n,
          case GL_UNSIGNED_BYTE: {
             GLbyte *dst = (GLbyte *) dstAddr;
             dst[i] = lum32;
+            break;
          }
-         break;
          case GL_SHORT:
          case GL_UNSIGNED_SHORT: {
             GLshort *dst = (GLshort *) dstAddr;
             dst[i] = lum32;
+            break;
          }
-         break;
          case GL_INT:
          case GL_UNSIGNED_INT: {
             GLint *dst = (GLint *) dstAddr;
             dst[i] = lum32;
+            break;
          }
-         break;
          }
       }
       return;
@@ -1519,21 +1524,22 @@ _mesa_pack_luminance_from_rgba_integer(GLuint n,
             GLbyte *dst = (GLbyte *) dstAddr;
             dst[2*i] = lum32;
             dst[2*i+1] = alpha;
+            break;
          }
          case GL_SHORT:
          case GL_UNSIGNED_SHORT: {
             GLshort *dst = (GLshort *) dstAddr;
             dst[i] = lum32;
             dst[2*i+1] = alpha;
+            break;
          }
-         break;
          case GL_INT:
          case GL_UNSIGNED_INT: {
             GLint *dst = (GLint *) dstAddr;
             dst[i] = lum32;
             dst[2*i+1] = alpha;
+            break;
          }
-         break;
          }
       }
       return;