diff options
author | Kenneth Graunke <[email protected]> | 2014-03-05 19:19:32 -0800 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2014-03-07 22:45:14 -0800 |
commit | be84d53d445419062173216ffc7e5e111fe23353 (patch) | |
tree | c1cefd0dbfc90055450107a4efc1656f04e6947f /src | |
parent | 45ee1b30d76cae79b5040bda72ecd87d7d39f1e3 (diff) |
meta: Refactor code for binding a texture image to the FBO.
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 <[email protected]>
Reviewed-by: Matt Turner <[email protected]>
Reviewed-by: Anuj Phogat <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/drivers/common/meta_generate_mipmap.c | 81 |
1 files changed, 35 insertions, 46 deletions
diff --git a/src/mesa/drivers/common/meta_generate_mipmap.c b/src/mesa/drivers/common/meta_generate_mipmap.c index 9bce97d6561..5bdf1270bca 100644 --- a/src/mesa/drivers/common/meta_generate_mipmap.c +++ b/src/mesa/drivers/common/meta_generate_mipmap.c @@ -45,6 +45,37 @@ #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 * images are mapped. @@ -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; |