mesa: implement new texture format L16
[mesa.git] / src / mesa / main / formats.c
index a82aa9c6a0ea198aea3c8844422329fbc05ffa4c..81d907f7a0e259807384904065386f5d80fcd07d 100644 (file)
@@ -221,6 +221,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
       1, 1, 2                      /* BlockWidth/Height,Bytes */
    },
+   {
+      MESA_FORMAT_AL44,            /* Name */
+      "MESA_FORMAT_AL44",          /* StrName */
+      GL_LUMINANCE_ALPHA,          /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      0, 0, 0, 4,                  /* Red/Green/Blue/AlphaBits */
+      4, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 1                      /* BlockWidth/Height,Bytes */
+   },
    {
       MESA_FORMAT_AL88,            /* Name */
       "MESA_FORMAT_AL88",          /* StrName */
@@ -275,6 +284,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
       1, 1, 1                      /* BlockWidth/Height,Bytes */
    },
+   {
+      MESA_FORMAT_A16,             /* Name */
+      "MESA_FORMAT_A16",           /* StrName */
+      GL_ALPHA,                    /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      0, 0, 0, 16,                 /* Red/Green/Blue/AlphaBits */
+      0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 2                      /* BlockWidth/Height,Bytes */
+   },
    {
       MESA_FORMAT_L8,              /* Name */
       "MESA_FORMAT_L8",            /* StrName */
@@ -284,6 +302,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       8, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
       1, 1, 1                      /* BlockWidth/Height,Bytes */
    },
+   {
+      MESA_FORMAT_L16,             /* Name */
+      "MESA_FORMAT_L16",           /* StrName */
+      GL_LUMINANCE,                /* BaseFormat */
+      GL_UNSIGNED_NORMALIZED,      /* DataType */
+      0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
+      16, 0, 0, 0, 0,              /* Lum/Int/Index/Depth/StencilBits */
+      1, 1, 2                      /* BlockWidth/Height,Bytes */
+   },
    {
       MESA_FORMAT_I8,              /* Name */
       "MESA_FORMAT_I8",            /* StrName */
@@ -374,6 +401,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       0, 0, 0, 0, 0,
       1, 1, 4
    },
+   {
+      MESA_FORMAT_ARGB2101010,
+      "MESA_FORMAT_ARGB2101010",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      10, 10, 10, 2,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
    {
       MESA_FORMAT_Z24_S8,          /* Name */
       "MESA_FORMAT_Z24_S8",        /* StrName */
@@ -863,7 +899,6 @@ const char *
 _mesa_get_format_name(gl_format format)
 {
    const struct gl_format_info *info = _mesa_get_format_info(format);
-   ASSERT(info->BytesPerBlock);
    return info->StrName;
 }
 
@@ -945,6 +980,7 @@ _mesa_get_format_bits(gl_format format, GLenum pname)
  *    GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
  *    GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
  *    GL_UNSIGNED_INT = an ordinary unsigned integer
+ *    GL_INT = an ordinary signed integer
  *    GL_FLOAT = an ordinary float
  */
 GLenum
@@ -1006,6 +1042,20 @@ _mesa_is_format_packed_depth_stencil(gl_format format)
 }
 
 
+/**
+ * Is the given format a signed/unsigned integer color format?
+ */
+GLboolean
+_mesa_is_format_integer_color(gl_format format)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) &&
+      info->BaseFormat != GL_DEPTH_COMPONENT &&
+      info->BaseFormat != GL_DEPTH_STENCIL &&
+      info->BaseFormat != GL_STENCIL_INDEX;
+}
+
+
 /**
  * Return color encoding for given format.
  * \return GL_LINEAR or GL_SRGB
@@ -1042,11 +1092,12 @@ _mesa_format_image_size(gl_format format, GLsizei width,
    const struct gl_format_info *info = _mesa_get_format_info(format);
    /* Strictly speaking, a conditional isn't needed here */
    if (info->BlockWidth > 1 || info->BlockHeight > 1) {
-      /* compressed format */
+      /* compressed format (2D only for now) */
       const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
       const GLuint wblocks = (width + bw - 1) / bw;
       const GLuint hblocks = (height + bh - 1) / bh;
       const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
+      assert(depth == 1);
       return sz;
    }
    else {
@@ -1057,6 +1108,36 @@ _mesa_format_image_size(gl_format format, GLsizei width,
 }
 
 
+/**
+ * Same as _mesa_format_image_size() but returns a 64-bit value to
+ * accomodate very large textures.
+ */
+uint64_t
+_mesa_format_image_size64(gl_format format, GLsizei width,
+                          GLsizei height, GLsizei depth)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   /* Strictly speaking, a conditional isn't needed here */
+   if (info->BlockWidth > 1 || info->BlockHeight > 1) {
+      /* compressed format (2D only for now) */
+      const uint64_t bw = info->BlockWidth, bh = info->BlockHeight;
+      const uint64_t wblocks = (width + bw - 1) / bw;
+      const uint64_t hblocks = (height + bh - 1) / bh;
+      const uint64_t sz = wblocks * hblocks * info->BytesPerBlock;
+      assert(depth == 1);
+      return sz;
+   }
+   else {
+      /* non-compressed */
+      const uint64_t sz = ((uint64_t) width *
+                           (uint64_t) height *
+                           (uint64_t) depth *
+                           info->BytesPerBlock);
+      return sz;
+   }
+}
+
+
 
 GLint
 _mesa_format_row_stride(gl_format format, GLsizei width)
@@ -1179,6 +1260,7 @@ _mesa_format_to_type_and_comps(gl_format format,
    case MESA_FORMAT_ARGB8888:
    case MESA_FORMAT_ARGB8888_REV:
    case MESA_FORMAT_XRGB8888:
+   case MESA_FORMAT_XRGB8888_REV:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 4;
       return;
@@ -1205,6 +1287,17 @@ _mesa_format_to_type_and_comps(gl_format format,
       *comps = 4;
       return;
 
+   case MESA_FORMAT_ARGB2101010:
+      *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_RGBA5551:
+      *datatype = GL_UNSIGNED_SHORT_5_5_5_1;
+      *comps = 4;
+      return;
+
+   case MESA_FORMAT_AL44: /* XXX this isn't plain GL_UNSIGNED_BYTE */
    case MESA_FORMAT_AL88:
    case MESA_FORMAT_AL88_REV:
    case MESA_FORMAT_RG88:
@@ -1222,6 +1315,8 @@ _mesa_format_to_type_and_comps(gl_format format,
       return;
 
    case MESA_FORMAT_R16:
+   case MESA_FORMAT_A16:
+   case MESA_FORMAT_L16:
       *datatype = GL_UNSIGNED_SHORT;
       *comps = 1;
       return;
@@ -1236,6 +1331,7 @@ _mesa_format_to_type_and_comps(gl_format format,
    case MESA_FORMAT_I8:
    case MESA_FORMAT_CI8:
    case MESA_FORMAT_R8:
+   case MESA_FORMAT_S8:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 1;
       return;
@@ -1281,12 +1377,26 @@ _mesa_format_to_type_and_comps(gl_format format,
       *comps = 2;
       return;
 
+   case MESA_FORMAT_SIGNED_R8:
+      *datatype = GL_BYTE;
+      *comps = 1;
+      return;
+   case MESA_FORMAT_SIGNED_RG88:
+      *datatype = GL_BYTE;
+      *comps = 2;
+      return;
    case MESA_FORMAT_SIGNED_RGBA8888:
    case MESA_FORMAT_SIGNED_RGBA8888_REV:
+   case MESA_FORMAT_SIGNED_RGBX8888:
       *datatype = GL_BYTE;
       *comps = 4;
       return;
 
+   case MESA_FORMAT_RGBA_16:
+      *datatype = GL_UNSIGNED_SHORT;
+      *comps = 4;
+      return;
+
    case MESA_FORMAT_SIGNED_R_16:
       *datatype = GL_SHORT;
       *comps = 1;
@@ -1338,12 +1448,12 @@ _mesa_format_to_type_and_comps(gl_format format,
    case MESA_FORMAT_SRGBA_DXT1:
    case MESA_FORMAT_SRGBA_DXT3:
    case MESA_FORMAT_SRGBA_DXT5:
+#endif
 #endif
       /* XXX generate error instead? */
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 0;
       return;
-#endif
 
    case MESA_FORMAT_RGBA_FLOAT32:
       *datatype = GL_FLOAT;
@@ -1411,9 +1521,14 @@ _mesa_format_to_type_and_comps(gl_format format,
       *comps = 4;
       return;
 
-
+   case MESA_FORMAT_NONE:
+   case MESA_FORMAT_COUNT:
+   /* For debug builds, warn if any formats are not handled */
+#ifndef DEBUG
    default:
-      _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps");
+#endif
+      _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps",
+                    _mesa_get_format_name(format));
       *datatype = 0;
       *comps = 1;
    }