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)))
swImg->HeightScale = (GLfloat) texImage->Height;
swImg->DepthScale = (GLfloat) texImage->Depth;
}
-
- return GL_TRUE;
}
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 ||
swrast_texture_image(texImage);
/* XXX we'll eventually call _swrast_map_teximage() here */
- swImage->Data = swImage->Buffer;
- assert(swImage->Buffer);
+ swImage->Map = swImage->Buffer;
}
}
}
= swrast_texture_image(texImage);
/* XXX we'll eventually call _swrast_unmap_teximage() here */
- swImage->Data = NULL;
+ swImage->Map = NULL;
}
}
}
/**
- * 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);
-}