mesa: add ARB_clear_texture.xml to file list, remove duplicate decls
[mesa.git] / src / mesa / main / formats.c
index a61064b901fa4f5970950609f156e31decb7ca33..1f20a9a6ad1f17c12965771b6a316949e97834c0 100644 (file)
@@ -43,7 +43,7 @@ struct gl_format_info
    /**
     * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
     * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
-    * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL, GL_DUDV_ATI.
+    * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
     */
    GLenum BaseFormat;
 
@@ -368,8 +368,8 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4                          /* BlockWidth/Height,Bytes */
    },
    {
-      MESA_FORMAT_X8Z24_UNORM,         /* Name */
-      "MESA_FORMAT_X8Z24_UNORM",       /* StrName */
+      MESA_FORMAT_X8_UINT_Z24_UNORM,   /* Name */
+      "MESA_FORMAT_X8_UINT_Z24_UNORM", /* StrName */
       GL_DEPTH_COMPONENT,              /* BaseFormat */
       GL_UNSIGNED_NORMALIZED,          /* DataType */
       0, 0, 0, 0,                      /* Red/Green/Blue/AlphaBits */
@@ -414,15 +414,6 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
    },
 
    /* Array unorm formats */
-   {
-      MESA_FORMAT_DUDV8,
-      "MESA_FORMAT_DUDV8",
-      GL_DUDV_ATI,
-      GL_SIGNED_NORMALIZED,
-      0, 0, 0, 0,
-      0, 0, 0, 0, 0,
-      1, 1, 2
-   },
    {
       MESA_FORMAT_A_UNORM8,        /* Name */
       "MESA_FORMAT_A_UNORM8",      /* StrName */
@@ -2035,6 +2026,15 @@ _mesa_is_format_signed(mesa_format format)
    }
 }
 
+/**
+ * Is the given format an integer format?
+ */
+GLboolean
+_mesa_is_format_integer(mesa_format format)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT);
+}
 
 /**
  * Return color encoding for given format.
@@ -2206,6 +2206,35 @@ _mesa_format_num_components(mesa_format format)
 }
 
 
+/**
+ * Returns true if a color format has data stored in the R/G/B/A channels,
+ * given an index from 0 to 3.
+ */
+bool
+_mesa_format_has_color_component(mesa_format format, int component)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+
+   assert(info->BaseFormat != GL_DEPTH_COMPONENT &&
+          info->BaseFormat != GL_DEPTH_STENCIL &&
+          info->BaseFormat != GL_STENCIL_INDEX);
+
+   switch (component) {
+   case 0:
+      return (info->RedBits + info->IntensityBits + info->LuminanceBits) > 0;
+   case 1:
+      return (info->GreenBits + info->IntensityBits + info->LuminanceBits) > 0;
+   case 2:
+      return (info->BlueBits + info->IntensityBits + info->LuminanceBits) > 0;
+   case 3:
+      return (info->AlphaBits + info->IntensityBits) > 0;
+   default:
+      assert(!"Invalid color component: must be 0..3");
+      return false;
+   }
+}
+
+
 /**
  * Return number of bytes needed to store an image of the given size
  * in the given format.
@@ -2518,7 +2547,7 @@ _mesa_format_to_type_and_comps(mesa_format format,
       *comps = 1;
       return;
 
-   case MESA_FORMAT_X8Z24_UNORM:
+   case MESA_FORMAT_X8_UINT_Z24_UNORM:
       *datatype = GL_UNSIGNED_INT;
       *comps = 1;
       return;
@@ -2538,11 +2567,6 @@ _mesa_format_to_type_and_comps(mesa_format format,
       *comps = 1;
       return;
 
-   case MESA_FORMAT_DUDV8:
-      *datatype = GL_BYTE;
-      *comps = 2;
-      return;
-
    case MESA_FORMAT_R_SNORM8:
    case MESA_FORMAT_A_SNORM8:
    case MESA_FORMAT_L_SNORM8:
@@ -3124,9 +3148,9 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
    case MESA_FORMAT_L_UNORM16:
       return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT && !swapBytes;
    case MESA_FORMAT_I_UNORM8:
-      return format == GL_INTENSITY && type == GL_UNSIGNED_BYTE;
+      return format == GL_RED && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_I_UNORM16:
-      return format == GL_INTENSITY && type == GL_UNSIGNED_SHORT && !swapBytes;
+      return format == GL_RED && type == GL_UNSIGNED_SHORT && !swapBytes;
 
    case MESA_FORMAT_YCBCR:
       return format == GL_YCBCR_MESA &&
@@ -3160,7 +3184,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
    case MESA_FORMAT_S8_UINT_Z24_UNORM:
       return format == GL_DEPTH_STENCIL && type == GL_UNSIGNED_INT_24_8 &&
          !swapBytes;
-   case MESA_FORMAT_X8Z24_UNORM:
+   case MESA_FORMAT_X8_UINT_Z24_UNORM:
    case MESA_FORMAT_Z24_UNORM_S8_UINT:
       return GL_FALSE;
 
@@ -3218,9 +3242,9 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
       return format == GL_LUMINANCE_ALPHA && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_I_FLOAT32:
-      return format == GL_INTENSITY && type == GL_FLOAT && !swapBytes;
+      return format == GL_RED && type == GL_FLOAT && !swapBytes;
    case MESA_FORMAT_I_FLOAT16:
-      return format == GL_INTENSITY && type == GL_HALF_FLOAT && !swapBytes;
+      return format == GL_RED && type == GL_HALF_FLOAT && !swapBytes;
 
    case MESA_FORMAT_R_FLOAT32:
       return format == GL_RED && type == GL_FLOAT && !swapBytes;
@@ -3248,13 +3272,17 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
       return format == GL_ALPHA_INTEGER && type == GL_INT && !swapBytes;
 
    case MESA_FORMAT_I_UINT8:
+      return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE;
    case MESA_FORMAT_I_UINT16:
+      return format == GL_RED_INTEGER && type == GL_UNSIGNED_SHORT && !swapBytes;
    case MESA_FORMAT_I_UINT32:
+      return format == GL_RED_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
    case MESA_FORMAT_I_SINT8:
+      return format == GL_RED_INTEGER && type == GL_BYTE;
    case MESA_FORMAT_I_SINT16:
+      return format == GL_RED_INTEGER && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_I_SINT32:
-      /* GL_INTENSITY_INTEGER_EXT doesn't exist. */
-      return GL_FALSE;
+      return format == GL_RED_INTEGER && type == GL_INT && !swapBytes;
 
    case MESA_FORMAT_L_UINT8:
       return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_BYTE;
@@ -3345,10 +3373,6 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
    case MESA_FORMAT_RGBA_UINT32:
       return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
 
-   case MESA_FORMAT_DUDV8:
-      return (format == GL_DU8DV8_ATI || format == GL_DUDV_ATI) &&
-             type == GL_BYTE && littleEndian && !swapBytes;
-
    case MESA_FORMAT_R_SNORM8:
       return format == GL_RED && type == GL_BYTE;
    case MESA_FORMAT_R8G8_SNORM:
@@ -3421,7 +3445,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
       return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
              littleEndian && !swapBytes;
    case MESA_FORMAT_I_SNORM8:
-      return format == GL_INTENSITY && type == GL_BYTE;
+      return format == GL_RED && type == GL_BYTE;
    case MESA_FORMAT_A_SNORM16:
       return format == GL_ALPHA && type == GL_SHORT && !swapBytes;
    case MESA_FORMAT_L_SNORM16:
@@ -3430,7 +3454,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
       return format == GL_LUMINANCE_ALPHA && type == GL_SHORT &&
              littleEndian && !swapBytes;
    case MESA_FORMAT_I_SNORM16:
-      return format == GL_INTENSITY && type == GL_SHORT && littleEndian &&
+      return format == GL_RED && type == GL_SHORT && littleEndian &&
              !swapBytes;
 
    case MESA_FORMAT_B10G10R10A2_UINT: