st: added st_renderbuffer::defined flag
authorBrian Paul <brianp@vmware.com>
Fri, 1 May 2009 18:25:42 +0000 (12:25 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 1 May 2009 18:25:42 +0000 (12:25 -0600)
Indicates whether there's defined image contents, or garbage/don't care.
This is set when we draw into a renderbuffer and cleared when we resize/
reallocate a renderbuffer or do a buffer swap (back buffer becomes undefined).

We use this to determine whether the front color buffer has been drawn to,
and whether to display its contents upon glFlush/Finish(), when the new
st_swapbuffers() function is used.

src/mesa/state_tracker/st_atom_framebuffer.c
src/mesa/state_tracker/st_cb_fbo.c
src/mesa/state_tracker/st_cb_fbo.h
src/mesa/state_tracker/st_cb_flush.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_framebuffer.c

index df0f093..f23186c 100644 (file)
@@ -123,6 +123,7 @@ update_framebuffer_state( struct st_context *st )
             framebuffer->cbufs[framebuffer->nr_cbufs] = strb->surface;
             framebuffer->nr_cbufs++;
          }
+         strb->defined = GL_TRUE; /* we'll be drawing something */
       }
    }
 
index 0b88d9b..fe9befa 100644 (file)
@@ -125,6 +125,8 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
    strb->Base.Height = height;
    init_renderbuffer_bits(strb, template.format);
 
+   strb->defined = GL_FALSE;  /* undefined contents now */
+
    /* Probably need dedicated flags for surface usage too: 
     */
    surface_usage = (PIPE_BUFFER_USAGE_GPU_READ |
index 44fa9fe..fd77d0a 100644 (file)
@@ -44,6 +44,7 @@ struct st_renderbuffer
    struct pipe_texture *texture;
    struct pipe_surface *surface; /* temporary view into texture */
    enum pipe_format format;  /** preferred format, or PIPE_FORMAT_NONE */
+   GLboolean defined;        /**< defined contents? */
 
    struct st_texture_object *rtt;  /**< GL render to texture's texture */
    int rtt_level, rtt_face, rtt_slice;
index fbaffd1..8ceeeab 100644 (file)
 #include "util/u_blit.h"
 
 
+/** Check if we have a front color buffer and if it's been drawn to. */
 static INLINE GLboolean
 is_front_buffer_dirty(struct st_context *st)
 {
-   return st->frontbuffer_status == FRONT_STATUS_DIRTY;
+   if (st->frontbuffer_status == FRONT_STATUS_DIRTY) {
+      return GL_TRUE;
+   }
+   else {
+      GLframebuffer *fb = st->ctx->DrawBuffer;
+      struct st_renderbuffer *strb
+         = st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
+      return strb && strb->defined;
+   }
 }
 
 
index 6ffed56..18adb35 100644 (file)
@@ -45,6 +45,7 @@ struct blit_state;
 struct bitmap_cache;
 
 
+/** XXX we'd like to get rid of these */
 #define FRONT_STATUS_UNDEFINED    0
 #define FRONT_STATUS_DIRTY        1
 #define FRONT_STATUS_COPY_OF_BACK 2
@@ -111,7 +112,7 @@ struct st_context
       struct gl_fragment_program *fragment_program;
    } cb;
 
-   GLuint frontbuffer_status;  /**< one of FRONT_STATUS_ */
+   GLuint frontbuffer_status;  /**< one of FRONT_STATUS_ (XXX to be removed) */
 
    char vendor[100];
    char renderer[100];
index 07ccaa6..639373f 100644 (file)
@@ -331,6 +331,12 @@ st_swapbuffers(struct st_framebuffer *stfb,
             st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
          *front_left = strb->surface;
       }
+      /* mark back buffer contents as undefined */
+      {
+         struct st_renderbuffer *back =
+            st_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer);
+         back->defined = GL_FALSE;
+      }
    }
    else {
       /* no front buffer, display the back buffer */
@@ -354,6 +360,12 @@ st_swapbuffers(struct st_framebuffer *stfb,
             st_renderbuffer(fb->Attachment[BUFFER_FRONT_RIGHT].Renderbuffer);
          *front_right = strb->surface;
       }
+      /* mark back buffer contents as undefined */
+      {
+         struct st_renderbuffer *back =
+            st_renderbuffer(fb->Attachment[BUFFER_BACK_RIGHT].Renderbuffer);
+         back->defined = GL_FALSE;
+      }
    }
    else {
       /* no front right buffer, display back right buffer (if exists) */