r600g: pad the DMA CS to a multiple of 8 dwords
[mesa.git] / src / mesa / main / mipmap.c
index 867506c9fc70b1a66a5f5687a656d532cd0e1a5b..a2f3767a327177d3d8ac02d19e6f95661797b0c7 100644 (file)
 
 #include "imports.h"
 #include "formats.h"
+#include "glformats.h"
 #include "mipmap.h"
 #include "mtypes.h"
 #include "teximage.h"
+#include "texobj.h"
 #include "texstore.h"
 #include "image.h"
 #include "macros.h"
@@ -476,7 +478,7 @@ do_row(GLenum datatype, GLuint comps, GLint srcWidth,
       GLuint *dst = (GLuint *) dstRow;
       for (i = j = 0, k = k0; i < (GLuint) dstWidth;
            i++, j += colStride, k += colStride) {
-         dst[i] = (GLfloat)(rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4);
+         dst[i] = rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4;
       }
    }
 
@@ -991,7 +993,7 @@ do_row_3D(GLenum datatype, GLuint comps, GLint srcWidth,
       }
    }
    else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 3)) {
-      DECLARE_ROW_POINTERS(GLhalfARB, 4);
+      DECLARE_ROW_POINTERS(GLhalfARB, 3);
 
       for (i = j = 0, k = k0; i < (GLuint) dstWidth;
            i++, j += colStride, k += colStride) {
@@ -1001,7 +1003,7 @@ do_row_3D(GLenum datatype, GLuint comps, GLint srcWidth,
       }
    }
    else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 2)) {
-      DECLARE_ROW_POINTERS(GLhalfARB, 4);
+      DECLARE_ROW_POINTERS(GLhalfARB, 2);
 
       for (i = j = 0, k = k0; i < (GLuint) dstWidth;
            i++, j += colStride, k += colStride) {
@@ -1010,7 +1012,7 @@ do_row_3D(GLenum datatype, GLuint comps, GLint srcWidth,
       }
    }
    else if ((datatype == GL_HALF_FLOAT_ARB) && (comps == 1)) {
-      DECLARE_ROW_POINTERS(GLhalfARB, 4);
+      DECLARE_ROW_POINTERS(GLhalfARB, 1);
 
       for (i = j = 0, k = k0; i < (GLuint) dstWidth;
            i++, j += colStride, k += colStride) {
@@ -1816,7 +1818,7 @@ _mesa_prepare_mipmap_level(struct gl_context *ctx,
                            GLsizei width, GLsizei height, GLsizei depth,
                            GLsizei border, GLenum intFormat, gl_format format)
 {
-   const GLuint numFaces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+   const GLuint numFaces = _mesa_num_tex_faces(texObj->Target);
    GLuint face;
 
    if (texObj->Immutable) {
@@ -1864,8 +1866,7 @@ _mesa_prepare_mipmap_level(struct gl_context *ctx,
                                     width, height, depth,
                                     border, intFormat, format);
 
-         ctx->Driver.AllocTextureImageBuffer(ctx, dstImage,
-                                             format, width, height, depth);
+         ctx->Driver.AllocTextureImageBuffer(ctx, dstImage);
 
          /* in case the mipmap level is part of an FBO: */
          _mesa_update_fbo_texture(ctx, texObj, face, level);
@@ -1938,7 +1939,7 @@ generate_mipmap_uncompressed(struct gl_context *ctx, GLenum target,
       }
 
       /* Map src texture image slices */
-      srcMaps = (GLubyte **) calloc(srcDepth, sizeof(GLubyte *));
+      srcMaps = calloc(srcDepth, sizeof(GLubyte *));
       if (srcMaps) {
          for (slice = 0; slice < srcDepth; slice++) {
             ctx->Driver.MapTextureImage(ctx, srcImage, slice,
@@ -1956,7 +1957,7 @@ generate_mipmap_uncompressed(struct gl_context *ctx, GLenum target,
       }
 
       /* Map dst texture image slices */
-      dstMaps = (GLubyte **) calloc(dstDepth, sizeof(GLubyte *));
+      dstMaps = calloc(dstDepth, sizeof(GLubyte *));
       if (dstMaps) {
          for (slice = 0; slice < dstDepth; slice++) {
             ctx->Driver.MapTextureImage(ctx, dstImage, slice,
@@ -2052,7 +2053,7 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
    /* allocate storage for the temporary, uncompressed image */
    /* 20 extra bytes, just be safe when calling last FetchTexel */
    temp_src_stride = _mesa_format_row_stride(temp_format, srcImage->Width);
-   temp_src = (GLubyte *) malloc(temp_src_stride * srcImage->Height + 20);
+   temp_src = malloc(temp_src_stride * srcImage->Height + 20);
    if (!temp_src) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
       return;
@@ -2101,7 +2102,7 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
 
       temp_dst_stride = _mesa_format_row_stride(temp_format, dstWidth);
       if (!temp_dst) {
-        temp_dst = (GLubyte *) malloc(temp_dst_stride * dstHeight);
+        temp_dst = malloc(temp_dst_stride * dstHeight);
         if (!temp_dst) {
            _mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
            break;
@@ -2128,14 +2129,15 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
                                       dstWidth, dstHeight, dstDepth,
                                       border, srcImage->InternalFormat,
                                       srcImage->TexFormat)) {
+         free(temp_dst);
          return;
       }
 
       /* The image space was allocated above so use glTexSubImage now */
-      ctx->Driver.TexSubImage2D(ctx, dstImage,
-                                0, 0, dstWidth, dstHeight,
-                                temp_base_format, temp_datatype,
-                                temp_dst, &ctx->DefaultPacking);
+      ctx->Driver.TexSubImage(ctx, 2, dstImage,
+                              0, 0, 0, dstWidth, dstHeight, 1,
+                              temp_base_format, temp_datatype,
+                              temp_dst, &ctx->DefaultPacking);
 
       /* swap src and dest pointers */
       {