st: st_equal_formats() function to compare gallium/GL pixel formats
authorBrian Paul <brianp@vmware.com>
Wed, 15 Apr 2009 15:51:38 +0000 (09:51 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 15 Apr 2009 15:51:38 +0000 (09:51 -0600)
src/mesa/state_tracker/st_format.c
src/mesa/state_tracker/st_format.h

index 9e2d60c92691f6886cf43be41cda98956a606786..d507e3e58dd5b46a0e0f91d501347fed8af31e47 100644 (file)
@@ -716,3 +716,23 @@ st_ChooseTextureFormat(GLcontext *ctx, GLint internalFormat,
 
    return translate_gallium_format_to_mesa_format(pFormat);
 }
+
+
+/**
+ * Test if a gallium format is equivalent to a GL format/type.
+ */
+GLboolean
+st_equal_formats(enum pipe_format pFormat, GLenum format, GLenum type)
+{
+   switch (pFormat) {
+   case PIPE_FORMAT_R8G8B8A8_UNORM:
+      return format == GL_RGBA && type == GL_UNSIGNED_BYTE;
+   case PIPE_FORMAT_B8G8R8A8_UNORM:
+      return format == GL_BGRA && type == GL_UNSIGNED_BYTE;
+   case PIPE_FORMAT_R5G6B5_UNORM:
+      return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5;
+   /* XXX more combos... */
+   default:
+      return GL_FALSE;
+   }
+}
index 3f5ac3201b1b2c35e73f245f2964592615df021b..7bbbe2d57044ae34a7dcf723a95535645debc06c 100644 (file)
@@ -76,4 +76,8 @@ st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
                        GLenum format, GLenum type);
 
 
+extern GLboolean
+st_equal_formats(enum pipe_format pFormat, GLenum format, GLenum type);
+
+
 #endif /* ST_CB_TEXIMAGE_H */