mesa: consolidate framebuffer target lookup code
authorBrian Paul <brianp@vmware.com>
Tue, 1 Mar 2011 01:24:25 +0000 (18:24 -0700)
committerBrian Paul <brianp@vmware.com>
Tue, 1 Mar 2011 01:24:25 +0000 (18:24 -0700)
src/mesa/main/fbobject.c

index 5da6a6cd16a4dcaec7c1dd8327418326467fa126..c242e568d08037e238fd8fbd9c48ff1b1d84d8f2 100644 (file)
@@ -159,6 +159,29 @@ invalidate_framebuffer(struct gl_framebuffer *fb)
 }
 
 
+/**
+ * Return the gl_framebuffer object which corresponds to the given
+ * framebuffer target, such as GL_DRAW_FRAMEBUFFER.
+ * Check support for GL_EXT_framebuffer_blit to determine if certain
+ * targets are legal.
+ * \return gl_framebuffer pointer or NULL if target is illegal
+ */
+static struct gl_framebuffer *
+get_framebuffer_target(struct gl_context *ctx, GLenum target)
+{
+   switch (target) {
+   case GL_DRAW_FRAMEBUFFER:
+      return ctx->Extensions.EXT_framebuffer_blit ? ctx->DrawBuffer : NULL;
+   case GL_READ_FRAMEBUFFER:
+      return ctx->Extensions.EXT_framebuffer_blit ? ctx->ReadBuffer : NULL;
+   case GL_FRAMEBUFFER_EXT:
+      return ctx->DrawBuffer;
+   default:
+      return NULL;
+   }
+}
+
+
 /**
  * Given a GL_*_ATTACHMENTn token, return a pointer to the corresponding
  * gl_renderbuffer_attachment object.
@@ -1677,29 +1700,10 @@ _mesa_CheckFramebufferStatusEXT(GLenum target)
 
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, 0);
 
-   switch (target) {
-#if FEATURE_EXT_framebuffer_blit
-   case GL_DRAW_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
-         return 0;
-      }
-      buffer = ctx->DrawBuffer;
-      break;
-   case GL_READ_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
-         return 0;
-      }
-      buffer = ctx->ReadBuffer;
-      break;
-#endif
-   case GL_FRAMEBUFFER_EXT:
-      buffer = ctx->DrawBuffer;
-      break;
-   default:
+   buffer = get_framebuffer_target(ctx, target);
+   if (!buffer) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glCheckFramebufferStatus(target)");
-      return 0; /* formerly GL_FRAMEBUFFER_STATUS_ERROR_EXT */
+      return 0;
    }
 
    if (buffer->Name == 0) {
@@ -1729,33 +1733,16 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
    struct gl_renderbuffer_attachment *att;
    struct gl_texture_object *texObj = NULL;
    struct gl_framebuffer *fb;
-   GLboolean error = GL_FALSE;
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   switch (target) {
-   case GL_READ_FRAMEBUFFER_EXT:
-      error = !ctx->Extensions.EXT_framebuffer_blit;
-      fb = ctx->ReadBuffer;
-      break;
-   case GL_DRAW_FRAMEBUFFER_EXT:
-      error = !ctx->Extensions.EXT_framebuffer_blit;
-      /* fall-through */
-   case GL_FRAMEBUFFER_EXT:
-      fb = ctx->DrawBuffer;
-      break;
-   default:
-      error = GL_TRUE;
-   }
-
-   if (error) {
+   fb = get_framebuffer_target(ctx, target);
+   if (!fb) {
       _mesa_error(ctx, GL_INVALID_ENUM,
                   "glFramebufferTexture%sEXT(target=0x%x)", caller, target);
       return;
    }
 
-   ASSERT(fb);
-
    /* check framebuffer binding */
    if (fb->Name == 0) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -1936,31 +1923,9 @@ _mesa_FramebufferRenderbufferEXT(GLenum target, GLenum attachment,
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   switch (target) {
-#if FEATURE_EXT_framebuffer_blit
-   case GL_DRAW_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glFramebufferRenderbufferEXT(target)");
-         return;
-      }
-      fb = ctx->DrawBuffer;
-      break;
-   case GL_READ_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glFramebufferRenderbufferEXT(target)");
-         return;
-      }
-      fb = ctx->ReadBuffer;
-      break;
-#endif
-   case GL_FRAMEBUFFER_EXT:
-      fb = ctx->DrawBuffer;
-      break;
-   default:
-      _mesa_error(ctx, GL_INVALID_ENUM,
-                  "glFramebufferRenderbufferEXT(target)");
+   fb = get_framebuffer_target(ctx, target);
+   if (!fb) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glFramebufferRenderbufferEXT(target)");
       return;
    }
 
@@ -2040,29 +2005,8 @@ _mesa_GetFramebufferAttachmentParameterivEXT(GLenum target, GLenum attachment,
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   switch (target) {
-#if FEATURE_EXT_framebuffer_blit
-   case GL_DRAW_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glGetFramebufferAttachmentParameterivEXT(target)");
-         return;
-      }
-      buffer = ctx->DrawBuffer;
-      break;
-   case GL_READ_FRAMEBUFFER_EXT:
-      if (!ctx->Extensions.EXT_framebuffer_blit) {
-         _mesa_error(ctx, GL_INVALID_ENUM,
-                     "glGetFramebufferAttachmentParameterivEXT(target)");
-         return;
-      }
-      buffer = ctx->ReadBuffer;
-      break;
-#endif
-   case GL_FRAMEBUFFER_EXT:
-      buffer = ctx->DrawBuffer;
-      break;
-   default:
+   buffer = get_framebuffer_target(ctx, target);
+   if (!buffer) {
       _mesa_error(ctx, GL_INVALID_ENUM,
                   "glGetFramebufferAttachmentParameterivEXT(target)");
       return;