mesa/st: Generates TGSI that always recognizes INSTANCEID/VERTEXID as integers.
[mesa.git] / src / mesa / swrast / s_texture.c
index 76a31eeae73cd79a3fcb2e4b1259a74bcc6bd9b9..9718367a8df13a086eaf597ffcb61166bae34e93 100644 (file)
@@ -96,6 +96,25 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
       swImg->ImageOffsets[i] = i * width * height;
    }
 
+   _swrast_init_texture_image(texImage, width, height, depth);
+
+   return GL_TRUE;
+}
+
+
+/**
+ * Code that overrides ctx->Driver.AllocTextureImageBuffer may use this to
+ * initialize the fields of swrast_texture_image without allocating the image
+ * buffer or initializing ImageOffsets or RowStride.
+ *
+ * Returns GL_TRUE on success, GL_FALSE on memory allocation failure.
+ */
+void
+_swrast_init_texture_image(struct gl_texture_image *texImage, GLsizei width,
+                           GLsizei height, GLsizei depth)
+{
+   struct swrast_texture_image *swImg = swrast_texture_image(texImage);
+
    if ((width == 1 || _mesa_is_pow_two(texImage->Width2)) &&
        (height == 1 || _mesa_is_pow_two(texImage->Height2)) &&
        (depth == 1 || _mesa_is_pow_two(texImage->Depth2)))
@@ -115,8 +134,6 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
       swImg->HeightScale = (GLfloat) texImage->Height;
       swImg->DepthScale = (GLfloat) texImage->Depth;
    }
-
-   return GL_TRUE;
 }
 
 
@@ -189,8 +206,15 @@ _swrast_map_teximage(struct gl_context *ctx,
    stride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width);
    _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
 
-   assert(swImage->Buffer);
+   assert(x % bw == 0);
+   assert(y % bh == 0);
 
+   if (!swImage->Buffer) {
+      /* probably ran out of memory when allocating tex mem */
+      *mapOut = NULL;
+      return;
+   }
+      
    map = swImage->Buffer;
 
    if (texImage->TexObject->Target == GL_TEXTURE_3D ||
@@ -240,7 +264,7 @@ _swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
                swrast_texture_image(texImage);
 
             /* XXX we'll eventually call _swrast_map_teximage() here */
-            swImage->Data = swImage->Buffer;
+            swImage->Map = swImage->Buffer;
          }
       }
    }
@@ -261,7 +285,7 @@ _swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
                = swrast_texture_image(texImage);
 
             /* XXX we'll eventually call _swrast_unmap_teximage() here */
-            swImage->Data = NULL;
+            swImage->Map = NULL;
          }
       }
    }
@@ -278,7 +302,7 @@ _swrast_map_textures(struct gl_context *ctx)
 
    /* loop over enabled texture units */
    while (enabledUnits) {
-      GLuint unit = _mesa_ffs(enabledUnits) - 1;
+      GLuint unit = ffs(enabledUnits) - 1;
       struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
       
       _swrast_map_texture(ctx, texObj);
@@ -298,7 +322,7 @@ _swrast_unmap_textures(struct gl_context *ctx)
 
    /* loop over enabled texture units */
    while (enabledUnits) {
-      GLuint unit = _mesa_ffs(enabledUnits) - 1;
+      GLuint unit = ffs(enabledUnits) - 1;
       struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
       
       _swrast_unmap_texture(ctx, texObj);
@@ -308,59 +332,6 @@ _swrast_unmap_textures(struct gl_context *ctx)
 }
 
 
-/**
- * Map or unmap any textures that we may be rendering to as renderbuffers.
- */
-static void
-map_unmap_renderbuffers(struct gl_context *ctx,
-                        struct gl_framebuffer *fb,
-                        GLboolean map)
-{
-   GLuint i;
-
-   for (i = 0; i < Elements(fb->Attachment); i++) {
-      struct gl_texture_object *texObj = fb->Attachment[i].Texture;
-      if (texObj) {
-         const GLuint level = fb->Attachment[i].TextureLevel;
-         const GLuint face = fb->Attachment[i].CubeMapFace;
-         struct gl_texture_image *texImage = texObj->Image[face][level];
-         if (texImage) {
-            struct swrast_texture_image *swImage
-               = swrast_texture_image(texImage);
-
-            if (map) {
-               /* XXX we'll eventually call _swrast_map_teximage() here */
-               swImage->Data = swImage->Buffer;
-            }
-            else {
-               /* XXX we'll eventually call _swrast_unmap_teximage() here */
-               swImage->Data = NULL;
-            }
-         }
-      }
-   }
-}
-
-
-void
-_swrast_map_renderbuffers(struct gl_context *ctx)
-{
-   map_unmap_renderbuffers(ctx, ctx->DrawBuffer, GL_TRUE);
-   if (ctx->ReadBuffer != ctx->DrawBuffer)
-      map_unmap_renderbuffers(ctx, ctx->ReadBuffer, GL_TRUE);
-}
-
-
-void
-_swrast_unmap_renderbuffers(struct gl_context *ctx)
-{
-   map_unmap_renderbuffers(ctx, ctx->DrawBuffer, GL_FALSE);
-   if (ctx->ReadBuffer != ctx->DrawBuffer)
-      map_unmap_renderbuffers(ctx, ctx->ReadBuffer, GL_FALSE);
-}
-
-
-
 /**
  * Called via ctx->Driver.AllocTextureStorage()
  * Just have to allocate memory for the texture images.