meta: Refactor code for binding a texture image to the FBO.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 6 Mar 2014 03:19:32 +0000 (19:19 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Sat, 8 Mar 2014 06:45:14 +0000 (22:45 -0800)
Almost the exact same code appeared twice, and it needs to expand to
handle additional texture targets.  Refactor it to tidy up the code and
avoid duplicating more work in the future.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/common/meta_generate_mipmap.c

index 9bce97d6561861cd50f71e67fceaa6ca0bd456e2..5bdf1270bcac53e57d2b058034f7ae8494649e08 100644 (file)
 #include "main/viewport.h"
 #include "drivers/common/meta.h"
 
+/**
+ * Bind a particular texture level/layer to mipmap->FBO's GL_COLOR_ATTACHMENT0.
+ */
+static void
+bind_fbo_image(struct gl_texture_object *texObj, GLenum target, GLuint level)
+{
+   switch (target) {
+   case GL_TEXTURE_1D:
+      _mesa_FramebufferTexture1D(GL_FRAMEBUFFER,
+                                 GL_COLOR_ATTACHMENT0,
+                                 target,
+                                 texObj->Name,
+                                 level);
+      break;
+   case GL_TEXTURE_3D:
+      _mesa_FramebufferTexture3D(GL_FRAMEBUFFER,
+                                 GL_COLOR_ATTACHMENT0,
+                                 target,
+                                 texObj->Name,
+                                 level,
+                                 0); /* XXX: Unfinished */
+      break;
+   default: /* 2D / cube */
+      _mesa_FramebufferTexture2D(GL_FRAMEBUFFER,
+                                 GL_COLOR_ATTACHMENT0,
+                                 target,
+                                 texObj->Name,
+                                 level);
+   }
+}
+
 /**
  * Check if the call to _mesa_meta_GenerateMipmap() will require a
  * software fallback.  The fallback path will require that the texture
@@ -104,26 +135,7 @@ fallback_required(struct gl_context *ctx, GLenum target,
       _mesa_GenFramebuffers(1, &mipmap->FBO);
    _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT, mipmap->FBO);
 
-   if (target == GL_TEXTURE_1D) {
-      _mesa_FramebufferTexture1D(GL_FRAMEBUFFER_EXT,
-                                    GL_COLOR_ATTACHMENT0_EXT,
-                                    target, texObj->Name, srcLevel);
-   }
-#if 0
-   /* other work is needed to enable 3D mipmap generation */
-   else if (target == GL_TEXTURE_3D) {
-      GLint zoffset = 0;
-      _mesa_FramebufferTexture3D(GL_FRAMEBUFFER_EXT,
-                                    GL_COLOR_ATTACHMENT0_EXT,
-                                    target, texObj->Name, srcLevel, zoffset);
-   }
-#endif
-   else {
-      /* 2D / cube */
-      _mesa_FramebufferTexture2D(GL_FRAMEBUFFER_EXT,
-                                    GL_COLOR_ATTACHMENT0_EXT,
-                                    target, texObj->Name, srcLevel);
-   }
+   bind_fbo_image(texObj, target, srcLevel);
 
    status = _mesa_CheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
 
@@ -271,7 +283,6 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
       const GLuint srcLevel = dstLevel - 1;
       GLsizei srcWidth, srcHeight, srcDepth;
       GLsizei dstWidth, dstHeight, dstDepth;
-      GLenum status;
 
       srcImage = _mesa_select_tex_image(ctx, texObj, faceTarget, srcLevel);
       assert(srcImage->Border == 0);
@@ -312,35 +323,13 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
       /* limit minification to src level */
       _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel);
 
-      /* Set to draw into the current dstLevel */
-      if (target == GL_TEXTURE_1D) {
-         _mesa_FramebufferTexture1D(GL_FRAMEBUFFER_EXT,
-                                       GL_COLOR_ATTACHMENT0_EXT,
-                                       target,
-                                       texObj->Name,
-                                       dstLevel);
-      }
-      else if (target == GL_TEXTURE_3D) {
-         GLint zoffset = 0; /* XXX unfinished */
-         _mesa_FramebufferTexture3D(GL_FRAMEBUFFER_EXT,
-                                       GL_COLOR_ATTACHMENT0_EXT,
-                                       target,
-                                       texObj->Name,
-                                       dstLevel, zoffset);
-      } else {
-         /* 2D / cube */
-         _mesa_FramebufferTexture2D(GL_FRAMEBUFFER_EXT,
-                                       GL_COLOR_ATTACHMENT0_EXT,
-                                       faceTarget,
-                                       texObj->Name,
-                                       dstLevel);
-      }
+      bind_fbo_image(texObj, faceTarget, dstLevel);
 
       _mesa_DrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
 
       /* sanity check */
-      status = _mesa_CheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
-      if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+      if (_mesa_CheckFramebufferStatus(GL_FRAMEBUFFER) !=
+          GL_FRAMEBUFFER_COMPLETE) {
          _mesa_problem(ctx, "Unexpected incomplete framebuffer in "
                        "_mesa_meta_GenerateMipmap()");
          break;