Squashed commit of the following:
[mesa.git] / src / mesa / state_tracker / st_cb_blit.c
index c741940bcf45a4c4ff2f8c2fa95206b0a9684356..0498080ccfc5ff3adf47e6405ecda1ee29806876 100644 (file)
 #include "main/imports.h"
 #include "main/image.h"
 #include "main/macros.h"
-#include "main/texformat.h"
 #include "shader/program.h"
-#include "shader/prog_parameter.h"
-#include "shader/prog_print.h"
 
 #include "st_context.h"
-#include "st_program.h"
+#include "st_texture.h"
 #include "st_cb_blit.h"
 #include "st_cb_fbo.h"
 
 #include "util/u_blit.h"
-
-#include "cso_cache/cso_context.h"
+#include "util/u_inlines.h"
 
 
 void
@@ -63,6 +59,7 @@ st_destroy_blit(struct st_context *st)
 }
 
 
+#if FEATURE_EXT_framebuffer_blit
 static void
 st_BlitFramebuffer(GLcontext *ctx,
                    GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
@@ -72,6 +69,7 @@ st_BlitFramebuffer(GLcontext *ctx,
    const GLbitfield depthStencil = (GL_DEPTH_BUFFER_BIT |
                                     GL_STENCIL_BUFFER_BIT);
    struct st_context *st = ctx->st;
+   struct pipe_context *pipe = st->pipe;
    const uint pFilter = ((filter == GL_NEAREST)
                          ? PIPE_TEX_MIPFILTER_NEAREST
                          : PIPE_TEX_MIPFILTER_LINEAR);
@@ -110,17 +108,52 @@ 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 = pipe->screen;
+         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_BIND_BLIT_SOURCE);
+         if(!srcSurf)
+            return;
+
+         util_blit_pixels(st->blit,
+                          srcSurf, st_get_stobj_sampler_view(srcObj),
+                          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_sampler_view *srcView = st_renderbuffer_get_sampler_view(srcRb, pipe);
+         struct pipe_surface *dstSurf = dstRb->surface;
+
+         util_blit_pixels(st->blit,
+                          srcSurf, srcView, srcX0, srcY0, srcX1, srcY1,
+                          dstSurf, dstX0, dstY0, dstX1, dstY1,
+                          0.0, pFilter);
+      }
    }
 
    if (mask & depthStencil) {
@@ -149,11 +182,13 @@ st_BlitFramebuffer(GLcontext *ctx,
       if ((mask & depthStencil) == depthStencil &&
           srcDepthSurf == srcStencilSurf &&
           dstDepthSurf == dstStencilSurf) {
+         struct pipe_sampler_view *srcView = st_renderbuffer_get_sampler_view(srcDepthRb, pipe);
+
          /* Blitting depth and stencil values between combined
           * depth/stencil buffers.  This is the ideal case for such buffers.
           */
          util_blit_pixels(st->blit,
-                          srcDepthSurf, srcX0, srcY0, srcX1, srcY1,
+                          srcDepthSurf, srcView, srcX0, srcY0, srcX1, srcY1,
                           dstDepthSurf, dstX0, dstY0, dstX1, dstY1,
                           0.0, pFilter);
       }
@@ -172,6 +207,7 @@ st_BlitFramebuffer(GLcontext *ctx,
       }
    }
 }
+#endif /* FEATURE_EXT_framebuffer_blit */