Merge branch 'master' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / unichrome / via_tex.c
index 126a26c345151806b6ab152f77eaccccc4abe2b7..d2010f090741286fd7b4fc3d00e1ff431086b7f8 100644 (file)
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "glheader.h"
-#include "macros.h"
-#include "mtypes.h"
-#include "enums.h"
-#include "colortab.h"
-#include "convolve.h"
-#include "context.h"
-#include "simple_list.h"
-#include "texcompress.h"
-#include "texformat.h"
-#include "texobj.h"
-#include "texstore.h"
-
-#include "mm.h"
+#include "main/glheader.h"
+#include "main/macros.h"
+#include "main/mtypes.h"
+#include "main/enums.h"
+#include "main/colortab.h"
+#include "main/convolve.h"
+#include "main/context.h"
+#include "main/mipmap.h"
+#include "main/simple_list.h"
+#include "main/texcompress.h"
+#include "main/texformat.h"
+#include "main/texobj.h"
+#include "main/texstore.h"
+
+#include "main/mm.h"
 #include "via_context.h"
 #include "via_fb.h"
 #include "via_tex.h"
@@ -512,6 +513,13 @@ static GLboolean viaSetTexImages(GLcontext *ctx,
 
    numLevels = lastLevel - firstLevel + 1;
 
+   /* The hardware supports only 10 mipmap levels; ignore higher levels.
+    */
+   if ((numLevels > 10) && (ctx->Const.MaxTextureLevels > 10)) {
+       lastLevel -= numLevels - 10;
+       numLevels = 10;
+   }
+
    /* save these values, check if they effect the residency of the
     * texture:
     */
@@ -691,6 +699,14 @@ static void viaTexImage(GLcontext *ctx,
    }
    texelBytes = texImage->TexFormat->TexelBytes;
 
+   if (texelBytes == 0) {
+      /* compressed format */
+      texImage->IsCompressed = GL_TRUE;
+      texImage->CompressedSize =
+         ctx->Driver.CompressedTextureSize(ctx, texImage->Width,
+                                           texImage->Height, texImage->Depth,
+                                           texImage->TexFormat->MesaFormat);
+   }
 
    /* Minimum pitch of 32 bytes */
    if (postConvWidth * texelBytes < 32) {
@@ -779,10 +795,10 @@ static void viaTexImage(GLcontext *ctx,
       return;
    }
    else {
-      GLint dstRowStride, dstImageStride = 0;
+      GLint dstRowStride;
       GLboolean success;
       if (texImage->IsCompressed) {
-         dstRowStride = _mesa_compressed_row_stride(texImage->InternalFormat,width);
+         dstRowStride = _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, width);
       }
       else {
          dstRowStride = postConvWidth * texImage->TexFormat->TexelBytes;
@@ -793,7 +809,8 @@ static void viaTexImage(GLcontext *ctx,
                                                 texImage->TexFormat,
                                                 texImage->Data,
                                                 0, 0, 0,  /* dstX/Y/Zoffset */
-                                                dstRowStride, dstImageStride,
+                                                dstRowStride,
+                                                texImage->ImageOffsets,
                                                 width, height, 1,
                                                 format, type, pixels, packing);
       if (!success) {
@@ -803,9 +820,7 @@ static void viaTexImage(GLcontext *ctx,
 
    /* GL_SGIS_generate_mipmap */
    if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-      _mesa_generate_mipmap(ctx, target,
-                            &ctx->Texture.Unit[ctx->Texture.CurrentUnit],
-                            texObj);
+      _mesa_generate_mipmap(ctx, target, texObj);
    }
 
    _mesa_unmap_teximage_pbo(ctx, packing);
@@ -839,7 +854,7 @@ static void viaTexSubImage2D(GLcontext *ctx,
 {
    struct via_context *vmesa = VIA_CONTEXT(ctx);
   
-   VIA_FLUSH_DMA(vmesa);
+   viaWaitIdle(vmesa, GL_TRUE);
    vmesa->clearTexCache = 1;
 
    _mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width,
@@ -875,7 +890,7 @@ static void viaTexSubImage1D(GLcontext *ctx,
 {
    struct via_context *vmesa = VIA_CONTEXT(ctx);
 
-   VIA_FLUSH_DMA(vmesa);
+   viaWaitIdle(vmesa, GL_TRUE); 
    vmesa->clearTexCache = 1;
 
    _mesa_store_texsubimage1d(ctx, target, level, xoffset, width,