summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2011-10-23 10:44:47 -0600
committerBrian Paul <[email protected]>2011-10-23 10:44:47 -0600
commit68da4b50e9b6aa72a9b155f650952620063e1b94 (patch)
tree369f3d98b315e6a000f3d45ad96b006aebc310e0 /src/mesa/swrast
parent66681b4c8cb1ef16f42c1591298cb30c83bca09b (diff)
mesa: add swrast_texture_image::Buffer
In the past, swrast_texture_image::Data has been overloaded. It could either point to malloc'd memory storing texture data, or it could point to a current mapping of GPU memory. Now, Buffer always points to malloc'd memory (if we're not using GPU memory) and Data always points to mapped memory. The next step would be to rename Data -> Map. This change also involves adding swrast functions for mapping textures and renderbuffers prior to rendering to setup the Data pointer. Plus, corresponding functions to unmap texures and renderbuffers. This is very much like similar code in the dri drivers.
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r--src/mesa/swrast/s_context.c24
-rw-r--r--src/mesa/swrast/s_context.h28
-rw-r--r--src/mesa/swrast/s_texrender.c31
-rw-r--r--src/mesa/swrast/s_texture.c151
4 files changed, 211 insertions, 23 deletions
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 5287671d780..9112cf30d81 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -747,6 +747,12 @@ _swrast_CreateContext( struct gl_context *ctx )
swrast->AllowVertexFog = GL_TRUE;
swrast->AllowPixelFog = GL_TRUE;
+ swrast->Driver.SpanRenderStart = _swrast_span_render_start;
+ swrast->Driver.SpanRenderFinish = _swrast_span_render_finish;
+
+ ctx->Driver.MapTexture = _swrast_map_texture;
+ ctx->Driver.UnmapTexture = _swrast_unmap_texture;
+
/* Optimized Accum buffer */
swrast->_IntegerAccumMode = GL_FALSE;
swrast->_IntegerAccumScaler = 0.0;
@@ -837,6 +843,24 @@ _swrast_render_primitive( struct gl_context *ctx, GLenum prim )
}
+/** called via swrast->Driver.SpanRenderStart() */
+void
+_swrast_span_render_start(struct gl_context *ctx)
+{
+ _swrast_map_textures(ctx);
+ _swrast_map_renderbuffers(ctx);
+}
+
+
+/** called via swrast->Driver.SpanRenderFinish() */
+void
+_swrast_span_render_finish(struct gl_context *ctx)
+{
+ _swrast_unmap_textures(ctx);
+ _swrast_unmap_renderbuffers(ctx);
+}
+
+
void
_swrast_render_start( struct gl_context *ctx )
{
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 55f7c31ce51..a83ac614560 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -144,6 +144,9 @@ struct swrast_texture_image
each 2D slice in 'Data', in texels */
GLubyte *Data; /**< Image data, accessed via FetchTexel() */
+ /** Malloc'd texure memory */
+ GLubyte *Buffer;
+
FetchTexelFunc FetchTexel;
StoreTexelFunc Store;
};
@@ -333,6 +336,31 @@ swrast_render_finish(struct gl_context *ctx)
}
+extern void
+_swrast_span_render_start(struct gl_context *ctx);
+
+extern void
+_swrast_span_render_finish(struct gl_context *ctx);
+
+extern void
+_swrast_map_textures(struct gl_context *ctx);
+
+extern void
+_swrast_unmap_textures(struct gl_context *ctx);
+
+extern void
+_swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj);
+
+extern void
+_swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj);
+
+
+extern void
+_swrast_map_renderbuffers(struct gl_context *ctx);
+
+extern void
+_swrast_unmap_renderbuffers(struct gl_context *ctx);
+
/**
* Size of an RGBA pixel, in bytes, for given datatype.
diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index caa17f983e3..e2b921512f2 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -31,6 +31,15 @@ struct texture_renderbuffer
};
+/** cast wrapper */
+static inline struct texture_renderbuffer *
+texture_renderbuffer(struct gl_renderbuffer *rb)
+{
+ return (struct texture_renderbuffer *) rb;
+}
+
+
+
/**
* Get row of values from the renderbuffer that wraps a texture image.
*/
@@ -38,8 +47,7 @@ static void
texture_get_row(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, void *values)
{
- const struct texture_renderbuffer *trb
- = (const struct texture_renderbuffer *) rb;
+ struct texture_renderbuffer *trb = texture_renderbuffer(rb);
const GLint z = trb->Zoffset;
GLuint i;
@@ -107,8 +115,7 @@ static void
texture_get_values(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
const GLint x[], const GLint y[], void *values)
{
- const struct texture_renderbuffer *trb
- = (const struct texture_renderbuffer *) rb;
+ struct texture_renderbuffer *trb = texture_renderbuffer(rb);
const GLint z = trb->Zoffset;
GLuint i;
@@ -174,8 +181,7 @@ static void
texture_put_row(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, const void *values, const GLubyte *mask)
{
- const struct texture_renderbuffer *trb
- = (const struct texture_renderbuffer *) rb;
+ struct texture_renderbuffer *trb = texture_renderbuffer(rb);
const GLint z = trb->Zoffset;
GLuint i;
@@ -236,8 +242,7 @@ static void
texture_put_row_rgb(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, const void *values, const GLubyte *mask)
{
- const struct texture_renderbuffer *trb
- = (const struct texture_renderbuffer *) rb;
+ struct texture_renderbuffer *trb = texture_renderbuffer(rb);
const GLint z = trb->Zoffset;
GLuint i;
@@ -296,8 +301,7 @@ static void
texture_put_mono_row(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint count,
GLint x, GLint y, const void *value, const GLubyte *mask)
{
- const struct texture_renderbuffer *trb
- = (const struct texture_renderbuffer *) rb;
+ struct texture_renderbuffer *trb = texture_renderbuffer(rb);
const GLint z = trb->Zoffset;
GLuint i;
@@ -356,8 +360,7 @@ texture_put_values(struct gl_context *ctx, struct gl_renderbuffer *rb, GLuint co
const GLint x[], const GLint y[], const void *values,
const GLubyte *mask)
{
- const struct texture_renderbuffer *trb
- = (const struct texture_renderbuffer *) rb;
+ struct texture_renderbuffer *trb = texture_renderbuffer(rb);
const GLint z = trb->Zoffset;
GLuint i;
@@ -415,8 +418,7 @@ texture_put_mono_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
GLuint count, const GLint x[], const GLint y[],
const void *value, const GLubyte *mask)
{
- const struct texture_renderbuffer *trb
- = (const struct texture_renderbuffer *) rb;
+ struct texture_renderbuffer *trb = texture_renderbuffer(rb);
const GLint z = trb->Zoffset;
GLuint i;
@@ -610,7 +612,6 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
trb->Base.DataType = CHAN_TYPE;
trb->Base._BaseFormat = GL_RGBA;
}
- trb->Base.Data = trb->TexImage->Data;
}
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index df371c30e3c..80c3070c941 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -76,9 +76,9 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
assert(texImage->Height == height);
assert(texImage->Depth == depth);
- assert(!swImg->Data);
- swImg->Data = _mesa_align_malloc(bytes, 512);
- if (!swImg->Data)
+ assert(!swImg->Buffer);
+ swImg->Buffer = _mesa_align_malloc(bytes, 512);
+ if (!swImg->Buffer)
return GL_FALSE;
/* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
@@ -128,9 +128,9 @@ _swrast_free_texture_image_buffer(struct gl_context *ctx,
struct gl_texture_image *texImage)
{
struct swrast_texture_image *swImage = swrast_texture_image(texImage);
- if (swImage->Data) {
- _mesa_align_free(swImage->Data);
- swImage->Data = NULL;
+ if (swImage->Buffer) {
+ _mesa_align_free(swImage->Buffer);
+ swImage->Buffer = NULL;
}
if (swImage->ImageOffsets) {
@@ -189,9 +189,9 @@ _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->Data);
+ assert(swImage->Buffer);
- map = swImage->Data;
+ map = swImage->Buffer;
if (texImage->TexObject->Target == GL_TEXTURE_3D ||
texImage->TexObject->Target == GL_TEXTURE_2D_ARRAY) {
@@ -224,3 +224,138 @@ _swrast_unmap_teximage(struct gl_context *ctx,
{
/* nop */
}
+
+
+void
+_swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
+{
+ const GLuint faces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+ GLuint face, level;
+
+ for (face = 0; face < faces; face++) {
+ for (level = texObj->BaseLevel; level < MAX_TEXTURE_LEVELS; level++) {
+ struct gl_texture_image *texImage = texObj->Image[face][level];
+ if (texImage) {
+ struct swrast_texture_image *swImage =
+ swrast_texture_image(texImage);
+
+ /* XXX we'll eventually call _swrast_map_teximage() here */
+ swImage->Data = swImage->Buffer;
+ assert(swImage->Buffer);
+ }
+ }
+ }
+}
+
+
+void
+_swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
+{
+ const GLuint faces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
+ GLuint face, level;
+
+ for (face = 0; face < faces; face++) {
+ for (level = texObj->BaseLevel; level < MAX_TEXTURE_LEVELS; level++) {
+ struct gl_texture_image *texImage = texObj->Image[face][level];
+ if (texImage) {
+ struct swrast_texture_image *swImage
+ = swrast_texture_image(texImage);
+
+ /* XXX we'll eventually call _swrast_unmap_teximage() here */
+ swImage->Data = NULL;
+ }
+ }
+ }
+}
+
+
+/**
+ * Map all textures for reading prior to software rendering.
+ */
+void
+_swrast_map_textures(struct gl_context *ctx)
+{
+ GLbitfield enabledUnits = ctx->Texture._EnabledUnits;
+
+ /* loop over enabled texture units */
+ while (enabledUnits) {
+ GLuint unit = ffs(enabledUnits) - 1;
+ struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
+
+ _swrast_map_texture(ctx, texObj);
+
+ enabledUnits &= ~(1 << unit);
+ }
+}
+
+
+/**
+ * Unmap all textures for reading prior to software rendering.
+ */
+void
+_swrast_unmap_textures(struct gl_context *ctx)
+{
+ GLbitfield enabledUnits = ctx->Texture._EnabledUnits;
+
+ /* loop over enabled texture units */
+ while (enabledUnits) {
+ GLuint unit = ffs(enabledUnits) - 1;
+ struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current;
+
+ _swrast_unmap_texture(ctx, texObj);
+
+ enabledUnits &= ~(1 << unit);
+ }
+}
+
+
+/**
+ * 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);
+}