replace malloc macros in imports.h with u_memory.h versions
[mesa.git] / src / mesa / swrast / s_texture.c
index a735e69c2eeacd13c2dcf82cd33ecd5e08c2ce21..88b4e87c62af3b2f88f524d00700cb897612cba9 100644 (file)
@@ -31,6 +31,7 @@
 #include "main/fbobject.h"
 #include "main/teximage.h"
 #include "main/texobj.h"
+#include "util/u_memory.h"
 #include "swrast/swrast.h"
 #include "swrast/s_context.h"
 
@@ -60,7 +61,7 @@ _swrast_delete_texture_image(struct gl_context *ctx,
 }
 
 static unsigned int
-texture_slices(struct gl_texture_image *texImage)
+texture_slices(const struct gl_texture_image *texImage)
 {
    if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY)
       return texImage->Height;
@@ -127,9 +128,9 @@ _swrast_init_texture_image(struct gl_texture_image *texImage)
 {
    struct swrast_texture_image *swImg = swrast_texture_image(texImage);
 
-   if ((texImage->Width == 1 || _mesa_is_pow_two(texImage->Width2)) &&
-       (texImage->Height == 1 || _mesa_is_pow_two(texImage->Height2)) &&
-       (texImage->Depth == 1 || _mesa_is_pow_two(texImage->Depth2)))
+   if ((texImage->Width == 1 || util_is_power_of_two_or_zero(texImage->Width2)) &&
+       (texImage->Height == 1 || util_is_power_of_two_or_zero(texImage->Height2)) &&
+       (texImage->Depth == 1 || util_is_power_of_two_or_zero(texImage->Depth2)))
       swImg->_IsPowerOfTwo = GL_TRUE;
    else
       swImg->_IsPowerOfTwo = GL_FALSE;
@@ -188,6 +189,7 @@ check_map_teximage(const struct gl_texture_image *texImage,
    assert(y < texImage->Height || texImage->Height == 0);
    assert(x + w <= texImage->Width);
    assert(y + h <= texImage->Height);
+   assert(slice < texture_slices(texImage));
 }
 
 /**
@@ -240,7 +242,6 @@ _swrast_map_teximage(struct gl_context *ctx,
    assert(swImage->Buffer);
    assert(swImage->Buffer == swImage->ImageSlices[0]);
 
-   assert(slice < texture_slices(texImage));
    map = swImage->ImageSlices[slice];
 
    /* apply x/y offset to map address */
@@ -362,11 +363,10 @@ _swrast_map_textures(struct gl_context *ctx)
    int unit;
 
    for (unit = 0; unit <= ctx->Texture._MaxEnabledTexImageUnit; unit++) {
-      if (ctx->Texture.Unit[unit]._ReallyEnabled) {
-         struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
+      struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
 
+      if (texObj)
          _swrast_map_texture(ctx, texObj);
-      }
    }
 }
 
@@ -379,10 +379,9 @@ _swrast_unmap_textures(struct gl_context *ctx)
 {
    int unit;
    for (unit = 0; unit <= ctx->Texture._MaxEnabledTexImageUnit; unit++) {
-      if (ctx->Texture.Unit[unit]._ReallyEnabled) {
-         struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
+      struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
 
+      if (texObj)
          _swrast_unmap_texture(ctx, texObj);
-      }
    }
 }