mesa: s/primcount/numInstances/
[mesa.git] / src / mesa / main / formats.c
index 514fe7aa7d0c052df343f985e0ffa0a8aea14412..b8fed182570a573ed03504457149064d6cbad8f7 100644 (file)
@@ -1091,6 +1091,48 @@ _mesa_get_format_color_encoding(gl_format format)
 }
 
 
+/**
+ * For an sRGB format, return the corresponding linear color space format.
+ * For non-sRGB formats, return the format as-is.
+ */
+gl_format
+_mesa_get_srgb_format_linear(gl_format format)
+{
+   switch (format) {
+   case MESA_FORMAT_SRGB8:
+      format = MESA_FORMAT_RGB888;
+      break;
+   case MESA_FORMAT_SRGBA8:
+      format = MESA_FORMAT_RGBA8888;
+      break;
+   case MESA_FORMAT_SARGB8:
+      format = MESA_FORMAT_ARGB8888;
+      break;
+   case MESA_FORMAT_SL8:
+      format = MESA_FORMAT_L8;
+      break;
+   case MESA_FORMAT_SLA8:
+      format = MESA_FORMAT_AL88;
+      break;
+   case MESA_FORMAT_SRGB_DXT1:
+      format = MESA_FORMAT_RGB_DXT1;
+      break;
+   case MESA_FORMAT_SRGBA_DXT1:
+      format = MESA_FORMAT_RGBA_DXT1;
+      break;
+   case MESA_FORMAT_SRGBA_DXT3:
+      format = MESA_FORMAT_RGBA_DXT3;
+      break;
+   case MESA_FORMAT_SRGBA_DXT5:
+      format = MESA_FORMAT_RGBA_DXT5;
+      break;
+   default:
+      break;
+   }
+   return format;
+}
+
+
 /**
  * Return number of bytes needed to store an image of the given size
  * in the given format.
@@ -1168,6 +1210,27 @@ _mesa_format_row_stride(gl_format format, GLsizei width)
 }
 
 
+/**
+ * Debug/test: check that all formats are handled in the
+ * _mesa_format_to_type_and_comps() function.  When new pixel formats
+ * are added to Mesa, that function needs to be updated.
+ * This is a no-op after the first call.
+ */
+static void
+check_format_to_type_and_comps(void)
+{
+   gl_format f;
+
+   for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) {
+      GLenum datatype = 0;
+      GLuint comps = 0;
+      /* This function will emit a problem/warning if the format is
+       * not handled.
+       */
+      _mesa_format_to_type_and_comps(f, &datatype, &comps);
+   }
+}
+
 
 /**
  * Do sanity checking of the format info table.
@@ -1251,8 +1314,9 @@ _mesa_test_formats(void)
          assert(info->LuminanceBits == 0);
          assert(info->IntensityBits > 0);
       }
-
    }
+
+   check_format_to_type_and_comps();
 }