mesa/st: Generates TGSI that always recognizes INSTANCEID/VERTEXID as integers.
[mesa.git] / src / mesa / swrast / s_texture.c
index 80c3070c941c0656b4b35513db57bfa792fefc5d..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,8 +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;
-            assert(swImage->Buffer);
+            swImage->Map = swImage->Buffer;
          }
       }
    }
@@ -262,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;
          }
       }
    }
@@ -310,52 +333,31 @@ _swrast_unmap_textures(struct gl_context *ctx)
 
 
 /**
- * Map or unmap any textures that we may be rendering to as renderbuffers.
+ * Called via ctx->Driver.AllocTextureStorage()
+ * Just have to allocate memory for the texture images.
  */
-static void
-map_unmap_renderbuffers(struct gl_context *ctx,
-                        struct gl_framebuffer *fb,
-                        GLboolean map)
+GLboolean
+_swrast_AllocTextureStorage(struct gl_context *ctx,
+                            struct gl_texture_object *texObj,
+                            GLsizei levels, GLsizei width,
+                            GLsizei height, GLsizei depth)
 {
-   GLuint i;
+   const GLint numFaces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   GLint face, level;
 
-   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;
+   for (face = 0; face < numFaces; face++) {
+      for (level = 0; level < levels; level++) {
          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;
-            }
+         if (!_swrast_alloc_texture_image_buffer(ctx, texImage,
+                                                 texImage->TexFormat,
+                                                 texImage->Width,
+                                                 texImage->Height,
+                                                 texImage->Depth)) {
+            return GL_FALSE;
          }
       }
    }
-}
 
-
-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);
+   return 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);
-}