From a2952315ac2c97311c0a967bf1c337a6c0b82a2f Mon Sep 17 00:00:00 2001 From: Topi Pohjolainen Date: Mon, 5 May 2014 17:37:40 +0300 Subject: [PATCH] meta: Refactor binding of renderbuffer as texture image Cc: "10.2" Signed-off-by: Topi Pohjolainen Reviewed-by: Kenneth Graunke --- src/mesa/drivers/common/meta.h | 7 +++ src/mesa/drivers/common/meta_blit.c | 70 ++++++++++++++++------------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h index fdd8714a7a9..70b87a1d631 100644 --- a/src/mesa/drivers/common/meta.h +++ b/src/mesa/drivers/common/meta.h @@ -395,6 +395,13 @@ _mesa_meta_end(struct gl_context *ctx); extern GLboolean _mesa_meta_in_progress(struct gl_context *ctx); +extern GLboolean +_mesa_meta_bind_rb_as_tex_image(struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint *tex, + struct gl_texture_object **texObj, + GLenum *target); + extern void _mesa_meta_BlitFramebuffer(struct gl_context *ctx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, diff --git a/src/mesa/drivers/common/meta_blit.c b/src/mesa/drivers/common/meta_blit.c index 14ecf8f11ed..9c8231bf02d 100644 --- a/src/mesa/drivers/common/meta_blit.c +++ b/src/mesa/drivers/common/meta_blit.c @@ -392,38 +392,16 @@ blitframebuffer_texture(struct gl_context *ctx, texObj = readAtt->Texture; target = texObj->Target; } else if (!readAtt->Texture && ctx->Driver.BindRenderbufferTexImage) { - /* Otherwise, we need the driver to be able to bind a renderbuffer as - * a texture image. - */ - struct gl_texture_image *texImage; - - if (rb->NumSamples > 1) - target = GL_TEXTURE_2D_MULTISAMPLE; - else - target = GL_TEXTURE_2D; - - _mesa_GenTextures(1, &tempTex); - _mesa_BindTexture(target, tempTex); - srcLevel = 0; - texObj = _mesa_lookup_texture(ctx, tempTex); - texImage = _mesa_get_tex_image(ctx, texObj, target, srcLevel); - - if (!ctx->Driver.BindRenderbufferTexImage(ctx, rb, texImage)) { - _mesa_DeleteTextures(1, &tempTex); + if (!_mesa_meta_bind_rb_as_tex_image(ctx, rb, + &tempTex, &texObj, &target)) return false; - } else { - if (ctx->Driver.FinishRenderTexture && - !rb->NeedsFinishRenderTexture) { - rb->NeedsFinishRenderTexture = true; - ctx->Driver.FinishRenderTexture(ctx, rb); - } - if (_mesa_is_winsys_fbo(readFb)) { - GLint temp = srcY0; - srcY0 = rb->Height - srcY1; - srcY1 = rb->Height - temp; - flipY = -flipY; - } + srcLevel = 0; + if (_mesa_is_winsys_fbo(readFb)) { + GLint temp = srcY0; + srcY0 = rb->Height - srcY1; + srcY1 = rb->Height - temp; + flipY = -flipY; } } else { GLenum tex_base_format; @@ -603,6 +581,38 @@ blitframebuffer_texture(struct gl_context *ctx, return true; } +GLboolean +_mesa_meta_bind_rb_as_tex_image(struct gl_context *ctx, + struct gl_renderbuffer *rb, + GLuint *tex, + struct gl_texture_object **texObj, + GLenum *target) +{ + struct gl_texture_image *texImage; + + if (rb->NumSamples > 1) + *target = GL_TEXTURE_2D_MULTISAMPLE; + else + *target = GL_TEXTURE_2D; + + _mesa_GenTextures(1, tex); + _mesa_BindTexture(*target, *tex); + *texObj = _mesa_lookup_texture(ctx, *tex); + texImage = _mesa_get_tex_image(ctx, *texObj, *target, 0); + + if (!ctx->Driver.BindRenderbufferTexImage(ctx, rb, texImage)) { + _mesa_DeleteTextures(1, tex); + return false; + } + + if (ctx->Driver.FinishRenderTexture && !rb->NeedsFinishRenderTexture) { + rb->NeedsFinishRenderTexture = true; + ctx->Driver.FinishRenderTexture(ctx, rb); + } + + return true; +} + /** * Meta implementation of ctx->Driver.BlitFramebuffer() in terms * of texture mapping and polygon rendering. -- 2.30.2