[Mesa-dev] [PATCH 04/10] meta: Always restore the framebuffers and current renderbuffer.

Eric Anholt eric at anholt.net
Tue Mar 4 14:17:38 PST 2014


The few paths that were playing with framebuffers and renderbuffer were
saving and restoring them, but I was writing another path doing so in this
series, and forgot to.
---
 src/mesa/drivers/common/meta.c | 36 +++++++++++++++---------------------
 src/mesa/drivers/common/meta.h |  2 ++
 2 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index cde34f9..24eb0a3 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -734,6 +734,11 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
       save->RasterDiscard = ctx->RasterDiscard;
       if (ctx->RasterDiscard)
          _mesa_set_enable(ctx, GL_RASTERIZER_DISCARD, GL_FALSE);
+
+      save->DrawBufferName = ctx->DrawBuffer->Name;
+      save->ReadBufferName = ctx->ReadBuffer->Name;
+      save->RenderbufferName = (ctx->CurrentRenderbuffer ?
+                                ctx->CurrentRenderbuffer->Name : 0);
    }
 }
 
@@ -1080,6 +1085,16 @@ _mesa_meta_end(struct gl_context *ctx)
    if (save->TransformFeedbackNeedsResume)
       _mesa_ResumeTransformFeedback();
 
+   if (ctx->DrawBuffer->Name != save->DrawBufferName)
+      _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, save->DrawBufferName);
+
+   if (ctx->ReadBuffer->Name != save->ReadBufferName)
+      _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, save->ReadBufferName);
+
+   if (!ctx->CurrentRenderbuffer ||
+       ctx->CurrentRenderbuffer->Name != save->RenderbufferName)
+      _mesa_BindRenderbuffer(GL_RENDERBUFFER, save->RenderbufferName);
+
    ctx->Meta->SaveStackDepth--;
 
    ctx->API = save->API;
@@ -2727,7 +2742,6 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
    const GLuint maxLevel = texObj->MaxLevel;
    const GLint maxLevelSave = texObj->MaxLevel;
    const GLboolean genMipmapSave = texObj->GenerateMipmap;
-   const GLuint fboSave = ctx->DrawBuffer->Name;
    const GLuint currentTexUnitSave = ctx->Texture.CurrentUnit;
    const GLboolean use_glsl_version = ctx->Extensions.ARB_vertex_shader &&
                                       ctx->Extensions.ARB_fragment_shader;
@@ -2932,8 +2946,6 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
    _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
    if (genMipmapSave)
       _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, genMipmapSave);
-
-   _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT, fboSave);
 }
 
 
@@ -2988,7 +3000,6 @@ get_temp_image_type(struct gl_context *ctx, mesa_format format)
    }
 }
 
-
 /**
  * Helper for _mesa_meta_CopyTexSubImage1/2/3D() functions.
  * Have to be careful with locking and meta state for pixel transfer.
@@ -3122,8 +3133,6 @@ decompress_texture_image(struct gl_context *ctx,
    const GLenum target = texObj->Target;
    GLenum faceTarget;
    struct vertex verts[4];
-   GLuint fboDrawSave, fboReadSave;
-   GLuint rbSave;
    GLuint samplerSave;
    const bool use_glsl_version = ctx->Extensions.ARB_vertex_shader &&
                                       ctx->Extensions.ARB_fragment_shader;
@@ -3157,11 +3166,6 @@ decompress_texture_image(struct gl_context *ctx,
       break;
    }
 
-   /* save fbo bindings (not saved by _mesa_meta_begin()) */
-   fboDrawSave = ctx->DrawBuffer->Name;
-   fboReadSave = ctx->ReadBuffer->Name;
-   rbSave = ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
-
    _mesa_meta_begin(ctx, MESA_META_ALL & ~MESA_META_PIXEL_STORE);
 
    samplerSave = ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler ?
@@ -3310,16 +3314,6 @@ decompress_texture_image(struct gl_context *ctx,
    _mesa_BindSampler(ctx->Texture.CurrentUnit, samplerSave);
 
    _mesa_meta_end(ctx);
-
-   /* restore fbo bindings */
-   if (fboDrawSave == fboReadSave) {
-      _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT, fboDrawSave);
-   }
-   else {
-      _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, fboDrawSave);
-      _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER_EXT, fboReadSave);
-   }
-   _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT, rbSave);
 }
 
 
diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
index fcf45c4..104849a 100644
--- a/src/mesa/drivers/common/meta.h
+++ b/src/mesa/drivers/common/meta.h
@@ -177,6 +177,8 @@ struct save_state
    GLboolean Lighting;
    GLboolean RasterDiscard;
    GLboolean TransformFeedbackNeedsResume;
+
+   GLuint DrawBufferName, ReadBufferName, RenderbufferName;
 };
 
 /**
-- 
1.9.rc1



More information about the mesa-dev mailing list