intel / DRI2: When available, use DRI2GetBuffersWithFormat
[mesa.git] / src / mesa / state_tracker / st_atom_framebuffer.c
index d07fd2517a7804ef17ba7ee590a3c5b76e74d35b..df0f0931eab38f7a5ab264616927e648731df7e2 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,19 +108,22 @@ 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]);
 
-      /*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) {
+         /*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++;
+         }
       }
-      
-      assert(strb->surface);
-      framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface;
-      framebuffer->num_cbufs++;
    }
 
    strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
@@ -130,7 +134,6 @@ update_framebuffer_state( struct st_context *st )
          update_renderbuffer_surface(st, strb);
       }
 
-      assert(strb->surface);
       framebuffer->zsbuf = strb->surface;
    }
    else {
@@ -144,20 +147,22 @@ update_framebuffer_state( struct st_context *st )
 
    cso_set_framebuffer(st->cso_context, framebuffer);
 
-#if 0
-   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,
+                                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;
    }
-#else
-#if !defined(PIPE_OS_WINDOWS)
-#warning "fix me"
-#endif
-   st->frontbuffer_status = FRONT_STATUS_DIRTY;
-#endif
 }