mesa: Allow BlitFramebuffer from a texture.
authorJosé Fonseca <jfonseca@vmware.com>
Sat, 19 Sep 2009 13:33:35 +0000 (14:33 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 19 Sep 2009 13:33:35 +0000 (14:33 +0100)
Although GL_EXT_framebuffer_blit does not mention textures, it doesn't
forbid them either, and some thirdparty driver appear to support this.

src/mesa/state_tracker/st_cb_blit.c

index c741940bcf45a4c4ff2f8c2fa95206b0a9684356..5626e25323e89d0ace01e80eda92e328687374ae 100644 (file)
@@ -39,6 +39,7 @@
 #include "shader/prog_print.h"
 
 #include "st_context.h"
+#include "st_texture.h"
 #include "st_program.h"
 #include "st_cb_blit.h"
 #include "st_cb_fbo.h"
@@ -110,17 +111,50 @@ st_BlitFramebuffer(GLcontext *ctx,
    }
 
    if (mask & GL_COLOR_BUFFER_BIT) {
-      struct st_renderbuffer *srcRb = 
-         st_renderbuffer(readFB->_ColorReadBuffer);
-      struct st_renderbuffer *dstRb = 
-         st_renderbuffer(drawFB->_ColorDrawBuffers[0]);
-      struct pipe_surface *srcSurf = srcRb->surface;
-      struct pipe_surface *dstSurf = dstRb->surface;
-
-      util_blit_pixels(st->blit,
-                       srcSurf, srcX0, srcY0, srcX1, srcY1,
-                       dstSurf, dstX0, dstY0, dstX1, dstY1,
-                       0.0, pFilter);
+      struct gl_renderbuffer_attachment *srcAtt =
+         &readFB->Attachment[readFB->_ColorReadBufferIndex];
+
+      if(srcAtt->Type == GL_TEXTURE) {
+         struct pipe_screen *screen = ctx->st->pipe->screen;
+         const struct st_texture_object *srcObj =
+            st_texture_object(srcAtt->Texture);
+         struct st_renderbuffer *dstRb =
+            st_renderbuffer(drawFB->_ColorDrawBuffers[0]);
+         struct pipe_surface *srcSurf;
+         struct pipe_surface *dstSurf = dstRb->surface;
+
+         if (!srcObj->pt)
+            return;
+
+         srcSurf = screen->get_tex_surface(screen,
+                                           srcObj->pt,
+                                           srcAtt->CubeMapFace,
+                                           srcAtt->TextureLevel,
+                                           srcAtt->Zoffset,
+                                           PIPE_BUFFER_USAGE_GPU_READ);
+         if(!srcSurf)
+            return;
+
+         util_blit_pixels(st->blit,
+                          srcSurf, srcX0, srcY0, srcX1, srcY1,
+                          dstSurf, dstX0, dstY0, dstX1, dstY1,
+                          0.0, pFilter);
+
+         pipe_surface_reference(&srcSurf, NULL);
+      }
+      else {
+         struct st_renderbuffer *srcRb =
+            st_renderbuffer(readFB->_ColorReadBuffer);
+         struct st_renderbuffer *dstRb =
+            st_renderbuffer(drawFB->_ColorDrawBuffers[0]);
+         struct pipe_surface *srcSurf = srcRb->surface;
+         struct pipe_surface *dstSurf = dstRb->surface;
+
+         util_blit_pixels(st->blit,
+                          srcSurf, srcX0, srcY0, srcX1, srcY1,
+                          dstSurf, dstX0, dstY0, dstX1, dstY1,
+                          0.0, pFilter);
+      }
    }
 
    if (mask & depthStencil) {