Mesa (master): st: when creating an on-demand front color buffer, init to back buffer image

Brian Paul brianp at kemper.freedesktop.org
Fri May 1 22:44:58 UTC 2009


Module: Mesa
Branch: master
Commit: 3f52a853f795d7432b181de81da6f0c4cf1cc202
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3f52a853f795d7432b181de81da6f0c4cf1cc202

Author: Brian Paul <brianp at vmware.com>
Date:   Fri May  1 12:48:46 2009 -0600

st: when creating an on-demand front color buffer, init to back buffer image

When we create a new front color buffer (user called glDrawBuffer(GL_FRONT))
initialize it to the contents of the back buffer.  Any previous call to
SwapBuffers() would have done that in effect, so make it reality.

---

 src/mesa/state_tracker/st_cb_fbo.c |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index fe9befa..9ae4208 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -455,6 +455,31 @@ st_validate_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb)
 
 
 /**
+ * Copy back color buffer to front color buffer.
+ */
+static void
+copy_back_to_front(struct st_context *st,
+                   struct gl_framebuffer *fb,
+                   gl_buffer_index frontIndex,
+                   gl_buffer_index backIndex)
+
+{
+   struct st_framebuffer *stfb = (struct st_framebuffer *) fb;
+   struct pipe_surface *surf_front, *surf_back;
+
+   (void) st_get_framebuffer_surface(stfb, frontIndex, &surf_front);
+   (void) st_get_framebuffer_surface(stfb, backIndex, &surf_back);
+
+   if (surf_front && surf_back) {
+      st->pipe->surface_copy(st->pipe,
+                             surf_front, 0, 0,  /* dest */
+                             surf_back, 0, 0,   /* src */
+                             fb->Width, fb->Height);
+   }
+}
+
+
+/**
  * Check if we're drawing into, or read from, a front color buffer.  If the
  * front buffer is missing, create it now.
  *
@@ -493,7 +518,7 @@ check_create_front_buffer(GLcontext *ctx, struct gl_framebuffer *fb,
          uint samples;
 
          if (0)
-            _mesa_debug(ctx, "Allocate new front buffer");
+            _mesa_debug(ctx, "Allocate new front buffer\n");
 
          /* get back renderbuffer info */
          back = st_renderbuffer(fb->Attachment[backIndex].Renderbuffer);
@@ -507,6 +532,11 @@ check_create_front_buffer(GLcontext *ctx, struct gl_framebuffer *fb,
          /* alloc texture/surface for new front buffer */
          front->AllocStorage(ctx, front, front->InternalFormat,
                              fb->Width, fb->Height);
+
+         /* initialize the front color buffer contents by copying
+          * the back buffer.
+          */
+         copy_back_to_front(ctx->st, fb, frontIndex, backIndex);
       }
    }
 }




More information about the mesa-commit mailing list