meta: Always restore the framebuffers and current renderbuffer.
authorEric Anholt <eric@anholt.net>
Mon, 3 Mar 2014 19:14:42 +0000 (11:14 -0800)
committerEric Anholt <eric@anholt.net>
Tue, 11 Mar 2014 19:47:46 +0000 (12:47 -0700)
The few paths that were playing with framebuffers and renderbuffer were
saving and restoring them.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/common/meta.c
src/mesa/drivers/common/meta.h
src/mesa/drivers/common/meta_generate_mipmap.c

index fe353ec2a06b236adcf629a5757dde41553472b7..76cbb41a9d056c03b019ba7d27f1b841ad1b23e3 100644 (file)
@@ -733,6 +733,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);
    }
 }
 
@@ -1079,6 +1084,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;
@@ -2652,7 +2667,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.
@@ -2786,8 +2800,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;
@@ -2821,11 +2833,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 ?
@@ -2974,16 +2981,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);
 }
 
 
index 6029a775cd54afb15e7e0cee4d2e453e9d348977..e2ccb939e8cb35442107c020cfb56747d6589ca9 100644 (file)
@@ -177,6 +177,8 @@ struct save_state
    GLboolean Lighting;
    GLboolean RasterDiscard;
    GLboolean TransformFeedbackNeedsResume;
+
+   GLuint DrawBufferName, ReadBufferName, RenderbufferName;
 };
 
 /**
index 3db073ab16e273efaa7a81ffb24c7d9d4455e52b..d62819c4c2243842a2a6b493d32b84ed8b411b5e 100644 (file)
@@ -194,7 +194,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;
@@ -378,6 +377,4 @@ _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);
 }