mesa: fix some minor texstore comments
[mesa.git] / src / mesa / main / image.c
index 37127dcb7a24da89044669284330077d76c9cd37..b266e26c6795a21e917ea0abad2b38aa5622580c 100644 (file)
 #include "mtypes.h"
 
 
-/**
- * NOTE:
- * Normally, BYTE_TO_FLOAT(0) returns 0.00392  That causes problems when
- * we later convert the float to a packed integer value (such as for
- * GL_RGB5_A1) because we'll wind up with a non-zero value.
- *
- * We redefine the macros here so zero is handled correctly.
- */
-#undef BYTE_TO_FLOAT
-#define BYTE_TO_FLOAT(B)    ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
-
-#undef SHORT_TO_FLOAT
-#define SHORT_TO_FLOAT(S)   ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
-
-
-
-/** Compute ceiling of integer quotient of A divided by B. */
-#define CEILING( A, B )  ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
-
 
 /**
  * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
@@ -195,38 +176,24 @@ _mesa_sizeof_packed_type( GLenum type )
       case GL_FLOAT:
         return sizeof(GLfloat);
       case GL_UNSIGNED_BYTE_3_3_2:
-         return sizeof(GLubyte);
       case GL_UNSIGNED_BYTE_2_3_3_REV:
-         return sizeof(GLubyte);
       case MESA_UNSIGNED_BYTE_4_4:
          return sizeof(GLubyte);
       case GL_UNSIGNED_SHORT_5_6_5:
-         return sizeof(GLushort);
       case GL_UNSIGNED_SHORT_5_6_5_REV:
-         return sizeof(GLushort);
       case GL_UNSIGNED_SHORT_4_4_4_4:
-         return sizeof(GLushort);
       case GL_UNSIGNED_SHORT_4_4_4_4_REV:
-         return sizeof(GLushort);
       case GL_UNSIGNED_SHORT_5_5_5_1:
-         return sizeof(GLushort);
       case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+      case GL_UNSIGNED_SHORT_8_8_MESA:
+      case GL_UNSIGNED_SHORT_8_8_REV_MESA:
          return sizeof(GLushort);
       case GL_UNSIGNED_INT_8_8_8_8:
-         return sizeof(GLuint);
       case GL_UNSIGNED_INT_8_8_8_8_REV:
-         return sizeof(GLuint);
       case GL_UNSIGNED_INT_10_10_10_2:
-         return sizeof(GLuint);
       case GL_UNSIGNED_INT_2_10_10_10_REV:
-         return sizeof(GLuint);
-      case GL_UNSIGNED_SHORT_8_8_MESA:
-      case GL_UNSIGNED_SHORT_8_8_REV_MESA:
-         return sizeof(GLushort);      
       case GL_UNSIGNED_INT_24_8_EXT:
-         return sizeof(GLuint);
       case GL_UNSIGNED_INT_5_9_9_9_REV:
-         return sizeof(GLuint);
       case GL_UNSIGNED_INT_10F_11F_11F_REV:
          return sizeof(GLuint);
       case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
@@ -249,12 +216,6 @@ _mesa_components_in_format( GLenum format )
 {
    switch (format) {
       case GL_COLOR_INDEX:
-      case GL_COLOR_INDEX1_EXT:
-      case GL_COLOR_INDEX2_EXT:
-      case GL_COLOR_INDEX4_EXT:
-      case GL_COLOR_INDEX8_EXT:
-      case GL_COLOR_INDEX12_EXT:
-      case GL_COLOR_INDEX16_EXT:
       case GL_STENCIL_INDEX:
       case GL_DEPTH_COMPONENT:
       case GL_RED:
@@ -269,29 +230,29 @@ _mesa_components_in_format( GLenum format )
       case GL_LUMINANCE_INTEGER_EXT:
       case GL_INTENSITY:
          return 1;
+
       case GL_LUMINANCE_ALPHA:
       case GL_LUMINANCE_ALPHA_INTEGER_EXT:
       case GL_RG:
+      case GL_YCBCR_MESA:
+      case GL_DEPTH_STENCIL_EXT:
+      case GL_DUDV_ATI:
+      case GL_DU8DV8_ATI:
         return 2;
+
       case GL_RGB:
+      case GL_BGR:
       case GL_RGB_INTEGER_EXT:
+      case GL_BGR_INTEGER_EXT:
         return 3;
+
       case GL_RGBA:
-      case GL_RGBA_INTEGER_EXT:
-        return 4;
-      case GL_BGR:
-        return 3;
       case GL_BGRA:
-        return 4;
       case GL_ABGR_EXT:
+      case GL_RGBA_INTEGER_EXT:
+      case GL_BGRA_INTEGER_EXT:
          return 4;
-      case GL_YCBCR_MESA:
-         return 2;
-      case GL_DEPTH_STENCIL_EXT:
-         return 2;
-      case GL_DUDV_ATI:
-      case GL_DU8DV8_ATI:
-         return 2;
+
       default:
          return -1;
    }
@@ -586,11 +547,12 @@ _mesa_is_legal_format_and_type(const struct gl_context *ctx,
             case GL_UNSIGNED_SHORT:
             case GL_INT:
             case GL_UNSIGNED_INT:
+               return ctx->Extensions.EXT_texture_integer;
             case GL_UNSIGNED_BYTE_3_3_2:
             case GL_UNSIGNED_BYTE_2_3_3_REV:
             case GL_UNSIGNED_SHORT_5_6_5:
             case GL_UNSIGNED_SHORT_5_6_5_REV:
-               return ctx->Extensions.EXT_texture_integer;
+               return ctx->Extensions.ARB_texture_rgb10_a2ui;
             default:
                return GL_FALSE;
          }
@@ -618,6 +580,7 @@ _mesa_is_legal_format_and_type(const struct gl_context *ctx,
             case GL_UNSIGNED_SHORT:
             case GL_INT:
             case GL_UNSIGNED_INT:
+               return ctx->Extensions.EXT_texture_integer;
             case GL_UNSIGNED_SHORT_4_4_4_4:
             case GL_UNSIGNED_SHORT_4_4_4_4_REV:
             case GL_UNSIGNED_SHORT_5_5_5_1:
@@ -626,7 +589,7 @@ _mesa_is_legal_format_and_type(const struct gl_context *ctx,
             case GL_UNSIGNED_INT_8_8_8_8_REV:
             case GL_UNSIGNED_INT_10_10_10_2:
             case GL_UNSIGNED_INT_2_10_10_10_REV:
-               return ctx->Extensions.EXT_texture_integer;
+               return ctx->Extensions.ARB_texture_rgb10_a2ui;
             default:
                return GL_FALSE;
          }
@@ -778,6 +741,7 @@ _mesa_is_color_format(GLenum format)
       case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
       case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
       case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
+      case GL_ETC1_RGB8_OES:
       /* generic integer formats */
       case GL_RED_INTEGER_EXT:
       case GL_GREEN_INTEGER_EXT:
@@ -853,6 +817,7 @@ _mesa_is_color_format(GLenum format)
       case GL_INTENSITY16_SNORM:
       case GL_RGB9_E5:
       case GL_R11F_G11F_B10F:
+      case GL_RGB10_A2UI:
          return GL_TRUE;
       case GL_YCBCR_MESA:  /* not considered to be RGB */
          /* fall-through */
@@ -862,27 +827,6 @@ _mesa_is_color_format(GLenum format)
 }
 
 
-/**
- * Test if the given image format is a color index format.
- */
-GLboolean
-_mesa_is_index_format(GLenum format)
-{
-   switch (format) {
-      case GL_COLOR_INDEX:
-      case GL_COLOR_INDEX1_EXT:
-      case GL_COLOR_INDEX2_EXT:
-      case GL_COLOR_INDEX4_EXT:
-      case GL_COLOR_INDEX8_EXT:
-      case GL_COLOR_INDEX12_EXT:
-      case GL_COLOR_INDEX16_EXT:
-         return GL_TRUE;
-      default:
-         return GL_FALSE;
-   }
-}
-
-
 /**
  * Test if the given image format is a depth component format.
  */
@@ -910,7 +854,6 @@ _mesa_is_stencil_format(GLenum format)
 {
    switch (format) {
       case GL_STENCIL_INDEX:
-      case GL_DEPTH_STENCIL:
          return GL_TRUE;
       default:
          return GL_FALSE;
@@ -1014,40 +957,53 @@ _mesa_is_integer_format(GLenum format)
    /* specific integer formats */
    case GL_RGBA32UI_EXT:
    case GL_RGB32UI_EXT:
+   case GL_RG32UI:
+   case GL_R32UI:
    case GL_ALPHA32UI_EXT:
    case GL_INTENSITY32UI_EXT:
    case GL_LUMINANCE32UI_EXT:
    case GL_LUMINANCE_ALPHA32UI_EXT:
    case GL_RGBA16UI_EXT:
    case GL_RGB16UI_EXT:
+   case GL_RG16UI:
+   case GL_R16UI:
    case GL_ALPHA16UI_EXT:
    case GL_INTENSITY16UI_EXT:
    case GL_LUMINANCE16UI_EXT:
    case GL_LUMINANCE_ALPHA16UI_EXT:
    case GL_RGBA8UI_EXT:
    case GL_RGB8UI_EXT:
+   case GL_RG8UI:
+   case GL_R8UI:
    case GL_ALPHA8UI_EXT:
    case GL_INTENSITY8UI_EXT:
    case GL_LUMINANCE8UI_EXT:
    case GL_LUMINANCE_ALPHA8UI_EXT:
    case GL_RGBA32I_EXT:
    case GL_RGB32I_EXT:
+   case GL_RG32I:
+   case GL_R32I:
    case GL_ALPHA32I_EXT:
    case GL_INTENSITY32I_EXT:
    case GL_LUMINANCE32I_EXT:
    case GL_LUMINANCE_ALPHA32I_EXT:
    case GL_RGBA16I_EXT:
    case GL_RGB16I_EXT:
+   case GL_RG16I:
+   case GL_R16I:
    case GL_ALPHA16I_EXT:
    case GL_INTENSITY16I_EXT:
    case GL_LUMINANCE16I_EXT:
    case GL_LUMINANCE_ALPHA16I_EXT:
    case GL_RGBA8I_EXT:
    case GL_RGB8I_EXT:
+   case GL_RG8I:
+   case GL_R8I:
    case GL_ALPHA8I_EXT:
    case GL_INTENSITY8I_EXT:
    case GL_LUMINANCE8I_EXT:
    case GL_LUMINANCE_ALPHA8I_EXT:
+   case GL_RGB10_A2UI:
       return GL_TRUE;
    default:
       return GL_FALSE;
@@ -1095,9 +1051,111 @@ _mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
       return ctx->Extensions.EXT_texture_compression_latc;
    case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
       return ctx->Extensions.ATI_texture_compression_3dc;
+   case GL_ETC1_RGB8_OES:
+      return ctx->Extensions.OES_compressed_ETC1_RGB8_texture;
+#if FEATURE_ES
+   case GL_PALETTE4_RGB8_OES:
+   case GL_PALETTE4_RGBA8_OES:
+   case GL_PALETTE4_R5_G6_B5_OES:
+   case GL_PALETTE4_RGBA4_OES:
+   case GL_PALETTE4_RGB5_A1_OES:
+   case GL_PALETTE8_RGB8_OES:
+   case GL_PALETTE8_RGBA8_OES:
+   case GL_PALETTE8_R5_G6_B5_OES:
+   case GL_PALETTE8_RGBA4_OES:
+   case GL_PALETTE8_RGB5_A1_OES:
+      return ctx->API == API_OPENGLES;
+#endif
+   default:
+      return GL_FALSE;
+   }
+}
+
+
+/**
+ * Does the given base texture/renderbuffer format have the channel
+ * named by 'pname'?
+ */
+GLboolean
+_mesa_base_format_has_channel(GLenum base_format, GLenum pname)
+{
+   switch (pname) {
+   case GL_TEXTURE_RED_SIZE:
+   case GL_TEXTURE_RED_TYPE:
+   case GL_RENDERBUFFER_RED_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
+      if (base_format == GL_RED ||
+         base_format == GL_RG ||
+         base_format == GL_RGB ||
+         base_format == GL_RGBA) {
+        return GL_TRUE;
+      }
+      return GL_FALSE;
+   case GL_TEXTURE_GREEN_SIZE:
+   case GL_TEXTURE_GREEN_TYPE:
+   case GL_RENDERBUFFER_GREEN_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
+      if (base_format == GL_RG ||
+         base_format == GL_RGB ||
+         base_format == GL_RGBA) {
+        return GL_TRUE;
+      }
+      return GL_FALSE;
+   case GL_TEXTURE_BLUE_SIZE:
+   case GL_TEXTURE_BLUE_TYPE:
+   case GL_RENDERBUFFER_BLUE_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
+      if (base_format == GL_RGB ||
+         base_format == GL_RGBA) {
+        return GL_TRUE;
+      }
+      return GL_FALSE;
+   case GL_TEXTURE_ALPHA_SIZE:
+   case GL_TEXTURE_ALPHA_TYPE:
+   case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
+      if (base_format == GL_RGBA ||
+         base_format == GL_ALPHA ||
+         base_format == GL_LUMINANCE_ALPHA) {
+        return GL_TRUE;
+      }
+      return GL_FALSE;
+   case GL_TEXTURE_LUMINANCE_SIZE:
+   case GL_TEXTURE_LUMINANCE_TYPE:
+      if (base_format == GL_LUMINANCE ||
+         base_format == GL_LUMINANCE_ALPHA) {
+        return GL_TRUE;
+      }
+      return GL_FALSE;
+   case GL_TEXTURE_INTENSITY_SIZE:
+   case GL_TEXTURE_INTENSITY_TYPE:
+      if (base_format == GL_INTENSITY) {
+        return GL_TRUE;
+      }
+      return GL_FALSE;
+   case GL_TEXTURE_DEPTH_SIZE:
+   case GL_TEXTURE_DEPTH_TYPE:
+   case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
+      if (base_format == GL_DEPTH_STENCIL ||
+         base_format == GL_DEPTH_COMPONENT) {
+        return GL_TRUE;
+      }
+      return GL_FALSE;
+   case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
+   case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
+      if (base_format == GL_DEPTH_STENCIL ||
+         base_format == GL_STENCIL_INDEX) {
+        return GL_TRUE;
+      }
+      return GL_FALSE;
    default:
+      _mesa_warning(NULL, "%s: Unexpected channel token 0x%x\n",
+                   __FUNCTION__, pname);
       return GL_FALSE;
    }
+
+   return GL_FALSE;
 }
 
 
@@ -1540,12 +1598,8 @@ _mesa_convert_colors(GLenum srcType, const GLvoid *src,
          GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
          GLuint i;
          for (i = 0; i < count; i++) {
-            if (!mask || mask[i]) {
-               UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][RCOMP], src4[i][RCOMP]);
-               UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][GCOMP], src4[i][GCOMP]);
-               UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][BCOMP], src4[i][BCOMP]);
-               UNCLAMPED_FLOAT_TO_UBYTE(dst1[i][ACOMP], src4[i][ACOMP]);
-            }
+            if (!mask || mask[i])
+               _mesa_unclamped_float_rgba_to_ubyte(dst1[i], src4[i]);
          }
          if (useTemp)
             memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));
@@ -1774,7 +1828,7 @@ _mesa_clip_to_region(GLint xmin, GLint ymin,
 /**
  * Clip dst coords against Xmax (or Ymax).
  */
-static INLINE void
+static inline void
 clip_right_or_top(GLint *srcX0, GLint *srcX1,
                   GLint *dstX0, GLint *dstX1,
                   GLint maxValue)
@@ -1807,7 +1861,7 @@ clip_right_or_top(GLint *srcX0, GLint *srcX1,
 /**
  * Clip dst coords against Xmin (or Ymin).
  */
-static INLINE void
+static inline void
 clip_left_or_bottom(GLint *srcX0, GLint *srcX1,
                     GLint *dstX0, GLint *dstX1,
                     GLint minValue)