Merge branch 'radeon-texrewrite-clean' into mesa_7_7_branch
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_copy.c
index 99cd818417d8149394ddc10e5f1893736ce72b90..4b5fe7be9f5c22dd5b02e5011353802dd45a2aa4 100644 (file)
@@ -29,6 +29,7 @@
 #include "main/enums.h"
 #include "main/image.h"
 #include "main/teximage.h"
+#include "main/texstate.h"
 #include "main/mipmap.h"
 
 #include "drivers/common/meta.h"
@@ -92,8 +93,7 @@ do_copy_texsubimage(struct intel_context *intel,
                     GLint x, GLint y, GLsizei width, GLsizei height)
 {
    GLcontext *ctx = &intel->ctx;
-   const struct intel_region *src =
-      get_teximage_source(intel, internalFormat);
+   const struct intel_region *src = get_teximage_source(intel, internalFormat);
 
    if (!intelImage->mt || !src) {
       if (INTEL_DEBUG & DEBUG_FALLBACKS)
@@ -109,26 +109,29 @@ do_copy_texsubimage(struct intel_context *intel,
       return GL_FALSE;
    }
 
-   intelFlush(ctx);
+   //   intelFlush(ctx);
    LOCK_HARDWARE(intel);
    {
       drm_intel_bo *dst_bo = intel_region_buffer(intel,
                                                 intelImage->mt->region,
                                                 INTEL_WRITE_PART);
-      GLuint image_offset = intel_miptree_image_offset(intelImage->mt,
-                                                       intelImage->face,
-                                                       intelImage->level, 0);
       const GLint orig_x = x;
       const GLint orig_y = y;
+      GLuint image_x, image_y;
       GLshort src_pitch;
 
+      /* get dest x/y in destination texture */
+      intel_miptree_get_image_offset(intelImage->mt,
+                                    intelImage->level,
+                                    intelImage->face,
+                                    0,
+                                    &image_x, &image_y);
       /* Update dst for clipped src.  Need to also clip the source rect. */
       dstx += x - orig_x;
       dsty += y - orig_y;
 
       /* Can't blit to tiled buffers with non-tile-aligned offset. */
-      if (intelImage->mt->region->tiling != I915_TILING_NONE &&
-         (image_offset & 4095) != 0) {
+      if (intelImage->mt->region->tiling == I915_TILING_Y) {
         UNLOCK_HARDWARE(intel);
         return GL_FALSE;
       }
@@ -152,17 +155,19 @@ do_copy_texsubimage(struct intel_context *intel,
         src_pitch = src->pitch;
       }
 
+      /* blit from src buffer to texture */
       if (!intelEmitCopyBlit(intel,
                             intelImage->mt->cpp,
                             src_pitch,
                             src->buffer,
-                            0,
+                            src->draw_offset,
                             src->tiling,
                             intelImage->mt->pitch,
                             dst_bo,
-                            image_offset,
+                            0,
                             intelImage->mt->region->tiling,
-                            x, y, dstx, dsty, width, height,
+                            x, y, image_x + dstx, image_y + dsty,
+                            width, height,
                             GL_COPY)) {
         UNLOCK_HARDWARE(intel);
         return GL_FALSE;
@@ -180,8 +185,7 @@ intelCopyTexImage1D(GLcontext * ctx, GLenum target, GLint level,
                     GLenum internalFormat,
                     GLint x, GLint y, GLsizei width, GLint border)
 {
-   struct gl_texture_unit *texUnit =
-      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
    struct gl_texture_object *texObj =
       _mesa_select_tex_object(ctx, texUnit, target);
    struct gl_texture_image *texImage =
@@ -228,8 +232,7 @@ intelCopyTexImage2D(GLcontext * ctx, GLenum target, GLint level,
                     GLint x, GLint y, GLsizei width, GLsizei height,
                     GLint border)
 {
-   struct gl_texture_unit *texUnit =
-      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
    struct gl_texture_object *texObj =
       _mesa_select_tex_object(ctx, texUnit, target);
    struct gl_texture_image *texImage =
@@ -244,7 +247,7 @@ intelCopyTexImage2D(GLcontext * ctx, GLenum target, GLint level,
     */
    ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
                           width, height, border,
-                          GL_RGBA, CHAN_TYPE, NULL,
+                          GL_RGBA, GL_UNSIGNED_BYTE, NULL,
                           &ctx->DefaultPacking, texObj, texImage);
 
    srcx = x;
@@ -274,8 +277,7 @@ static void
 intelCopyTexSubImage1D(GLcontext * ctx, GLenum target, GLint level,
                        GLint xoffset, GLint x, GLint y, GLsizei width)
 {
-   struct gl_texture_unit *texUnit =
-      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
    struct gl_texture_object *texObj =
       _mesa_select_tex_object(ctx, texUnit, target);
    struct gl_texture_image *texImage =
@@ -300,8 +302,7 @@ intelCopyTexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
                        GLint xoffset, GLint yoffset,
                        GLint x, GLint y, GLsizei width, GLsizei height)
 {
-   struct gl_texture_unit *texUnit =
-      &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+   struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
    struct gl_texture_object *texObj =
       _mesa_select_tex_object(ctx, texUnit, target);
    struct gl_texture_image *texImage =