Merge remote branch 'origin/master' into radeon-rewrite
[mesa.git] / src / mesa / state_tracker / st_atom_framebuffer.c
index d46c3ee16c5d8af9b6f6f3851f1114d18c9d0859..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"
@@ -59,7 +60,7 @@ update_renderbuffer_surface(struct st_context *st,
        strb->surface->texture != texture ||
        strb->surface->width != rtt_width ||
        strb->surface->height != rtt_height) {
-      int level;
+      GLuint level;
       /* find matching mipmap level size */
       for (level = 0; level <= texture->last_level; level++) {
          if (texture->width[level] == rtt_width &&
@@ -95,7 +96,7 @@ update_framebuffer_state( struct st_context *st )
    struct pipe_framebuffer_state *framebuffer = &st->state.framebuffer;
    struct gl_framebuffer *fb = st->ctx->DrawBuffer;
    struct st_renderbuffer *strb;
-   GLuint i, j;
+   GLuint i;
 
    memset(framebuffer, 0, sizeof(*framebuffer));
 
@@ -107,20 +108,19 @@ 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;
-   for (j = 0; j < MAX_DRAW_BUFFERS; j++) {
-      for (i = 0; i < fb->_NumColorDrawBuffers[j]; i++) {
-         strb = st_renderbuffer(fb->_ColorDrawBuffers[j][i]);
-
-         /*printf("--------- framebuffer surface rtt %p\n", strb->rtt);*/
-         if (strb->rtt) {
-            /* rendering to a GL texture, may have to update surface */
-            update_renderbuffer_surface(st, strb);
-         }
+   framebuffer->nr_cbufs = 0;
+   for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
+      strb = st_renderbuffer(fb->_ColorDrawBuffers[i]);
 
-         assert(strb->surface);
-         framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface;
-         framebuffer->num_cbufs++;
+      /*printf("--------- framebuffer surface rtt %p\n", strb->rtt);*/
+      if (strb->rtt) {
+         /* rendering to a GL texture, may have to update surface */
+         update_renderbuffer_surface(st, strb);
+      }
+
+      if (strb->surface) {
+         framebuffer->cbufs[framebuffer->nr_cbufs] = strb->surface;
+         framebuffer->nr_cbufs++;
       }
    }
 
@@ -132,7 +132,6 @@ update_framebuffer_state( struct st_context *st )
          update_renderbuffer_surface(st, strb);
       }
 
-      assert(strb->surface);
       framebuffer->zsbuf = strb->surface;
    }
    else {
@@ -146,9 +145,19 @@ update_framebuffer_state( struct st_context *st )
 
    cso_set_framebuffer(st->cso_context, framebuffer);
 
-   if (fb->_ColorDrawBufferMask[0] & BUFFER_BIT_FRONT_LEFT) {
+   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;