Merge remote branch 'origin/master' into radeon-rewrite
[mesa.git] / src / mesa / state_tracker / st_atom_framebuffer.c
index b4f42c6f93f6a4182e759667d8a9f09462345401..625efdd66b5d94552dd142d2cad262863a48b40a 100644 (file)
@@ -34,6 +34,7 @@
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_cb_fbo.h"
+#include "st_public.h"
 #include "st_texture.h"
 #include "pipe/p_context.h"
 #include "pipe/p_inlines.h"
@@ -107,7 +108,7 @@ update_framebuffer_state( struct st_context *st )
    /* Examine Mesa's ctx->DrawBuffer->_ColorDrawBuffers state
     * to determine which surfaces to draw to
     */
-   framebuffer->num_cbufs = 0;
+   framebuffer->nr_cbufs = 0;
    for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
       strb = st_renderbuffer(fb->_ColorDrawBuffers[i]);
 
@@ -116,10 +117,11 @@ update_framebuffer_state( struct st_context *st )
          /* rendering to a GL texture, may have to update surface */
          update_renderbuffer_surface(st, strb);
       }
-      
-      assert(strb->surface);
-      framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface;
-      framebuffer->num_cbufs++;
+
+      if (strb->surface) {
+         framebuffer->cbufs[framebuffer->nr_cbufs] = strb->surface;
+         framebuffer->nr_cbufs++;
+      }
    }
 
    strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
@@ -130,7 +132,6 @@ update_framebuffer_state( struct st_context *st )
          update_renderbuffer_surface(st, strb);
       }
 
-      assert(strb->surface);
       framebuffer->zsbuf = strb->surface;
    }
    else {
@@ -146,7 +147,17 @@ update_framebuffer_state( struct st_context *st )
 
    if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) {
       if (st->frontbuffer_status == FRONT_STATUS_COPY_OF_BACK) {
-         /* XXX copy back buf to front? */
+         /* copy back color buffer to front color buffer */
+         struct st_framebuffer *stfb = (struct st_framebuffer *) fb;
+        struct pipe_surface *surf_front, *surf_back;
+         (void) st_get_framebuffer_surface(stfb, ST_SURFACE_FRONT_LEFT, &surf_front);
+         (void) st_get_framebuffer_surface(stfb, ST_SURFACE_BACK_LEFT, &surf_back);
+
+         st->pipe->surface_copy(st->pipe,
+                                FALSE,
+                                surf_front, 0, 0,  /* dest */
+                                surf_back, 0, 0,   /* src */
+                                fb->Width, fb->Height);
       }
       /* we're assuming we'll really draw to the front buffer */
       st->frontbuffer_status = FRONT_STATUS_DIRTY;