mesa: use _mesa_base_format_has_channel() in fbobject.c queries
authorBrian Paul <brianp@vmware.com>
Wed, 23 Nov 2011 22:33:45 +0000 (15:33 -0700)
committerBrian Paul <brianp@vmware.com>
Mon, 28 Nov 2011 15:07:09 +0000 (08:07 -0700)
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/main/fbobject.c
src/mesa/main/texparam.c
src/mesa/main/texparam.h

index f63a8e7..2b4c70a 100644 (file)
@@ -46,6 +46,7 @@
 #include "state.h"
 #include "teximage.h"
 #include "texobj.h"
+#include "texparam.h"
 
 
 /** Set this to 1 to help debug FBO incompleteness problems */
@@ -1477,48 +1478,10 @@ _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
 static GLint
 get_component_bits(GLenum pname, GLenum baseFormat, gl_format format)
 {
-   switch (pname) {
-   case GL_RENDERBUFFER_RED_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
-      if (baseFormat == GL_RGB || baseFormat == GL_RGBA ||
-         baseFormat == GL_RG || baseFormat == GL_RED)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_GREEN_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
-      if (baseFormat == GL_RGB || baseFormat == GL_RGBA || baseFormat == GL_RG)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_BLUE_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
-      if (baseFormat == GL_RGB || baseFormat == GL_RGBA)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
-      if (baseFormat == GL_RGBA || baseFormat == GL_ALPHA ||
-         baseFormat == GL_LUMINANCE_ALPHA)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
-      if (baseFormat == GL_DEPTH_COMPONENT || baseFormat == GL_DEPTH_STENCIL)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
-   case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
-      if (baseFormat == GL_STENCIL_INDEX || baseFormat == GL_DEPTH_STENCIL)
-         return _mesa_get_format_bits(format, pname);
-      else
-         return 0;
-   default:
+   if (_mesa_base_format_has_channel(baseFormat, pname))
+      return _mesa_get_format_bits(format, pname);
+   else
       return 0;
-   }
 }
 
 
index 0081c3b..4c30a36 100644 (file)
@@ -884,12 +884,14 @@ _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params)
 }
 
 
-static GLboolean
-base_format_has_channel(GLenum base_format, GLenum 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 ||
@@ -899,6 +901,8 @@ base_format_has_channel(GLenum base_format, GLenum pname)
       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) {
@@ -907,6 +911,8 @@ base_format_has_channel(GLenum base_format, GLenum pname)
       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;
@@ -914,6 +920,8 @@ base_format_has_channel(GLenum base_format, GLenum pname)
       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) {
@@ -935,11 +943,20 @@ base_format_has_channel(GLenum base_format, GLenum pname)
       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);
@@ -1048,7 +1065,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
       case GL_TEXTURE_GREEN_SIZE:
       case GL_TEXTURE_BLUE_SIZE:
       case GL_TEXTURE_ALPHA_SIZE:
-         if (base_format_has_channel(img->_BaseFormat, pname))
+         if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
             *params = _mesa_get_format_bits(texFormat, pname);
          else
             *params = 0;
@@ -1122,7 +1139,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
       case GL_TEXTURE_DEPTH_TYPE_ARB:
          if (!ctx->Extensions.ARB_texture_float)
             goto invalid_pname;
-        if (base_format_has_channel(img->_BaseFormat, pname))
+        if (_mesa_base_format_has_channel(img->_BaseFormat, pname))
            *params = _mesa_get_format_datatype(texFormat);
         else
            *params = GL_NONE;
index 19b4116..6c6b7fa 100644 (file)
@@ -30,6 +30,9 @@
 #include "main/glheader.h"
 
 
+extern GLboolean
+_mesa_base_format_has_channel(GLenum base_format, GLenum pname);
+
 extern void GLAPIENTRY
 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
                               GLenum pname, GLfloat *params );