Mesa (map-texture-image-v4): swrast: map/ unmap textures bound to framebuffer attachments
Brian Paul
brianp at kemper.freedesktop.org
Thu Jul 28 04:23:22 UTC 2011
Module: Mesa
Branch: map-texture-image-v4
Commit: 08692dbe2dee936c8d14ec9deaaa57808aba8167
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=08692dbe2dee936c8d14ec9deaaa57808aba8167
Author: Brian Paul <brianp at vmware.com>
Date: Wed Jul 27 22:23:07 2011 -0600
swrast: map/unmap textures bound to framebuffer attachments
---
src/mesa/swrast/s_context.c | 14 +++--
src/mesa/swrast/s_context.h | 6 ++
src/mesa/swrast/s_texrender.c | 38 +-------------
src/mesa/swrast/s_texture.c | 115 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 131 insertions(+), 42 deletions(-)
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 174f326..eaa6a67 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -758,6 +758,9 @@ _swrast_CreateContext( struct gl_context *ctx )
ctx->swrast_context = swrast;
+ swrast->Driver.SpanRenderStart = _swrast_render_start;
+ swrast->Driver.SpanRenderFinish = _swrast_render_finish;
+
return GL_TRUE;
}
@@ -809,24 +812,23 @@ _swrast_render_primitive( struct gl_context *ctx, GLenum prim )
}
+/** Called via swrast->Driver.SpanRenderStart() */
void
_swrast_render_start( struct gl_context *ctx )
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
_swrast_map_textures(ctx);
- if (swrast->Driver.SpanRenderStart)
- swrast->Driver.SpanRenderStart( ctx );
+ _swrast_map_renderbuffers(ctx);
swrast->PointSpan.end = 0;
}
+/** Called via swrast->Driver.SpanRenderFinish() */
void
_swrast_render_finish( struct gl_context *ctx )
{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- if (swrast->Driver.SpanRenderFinish)
- swrast->Driver.SpanRenderFinish( ctx );
- _swrast_unmap_textures(ctx);
_swrast_flush(ctx);
+ _swrast_unmap_renderbuffers(ctx);
+ _swrast_unmap_textures(ctx);
}
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 4949beb..aafc8b1 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -319,6 +319,12 @@ _swrast_map_textures( struct gl_context *ctx );
extern void
_swrast_unmap_textures( struct gl_context *ctx );
+extern void
+_swrast_map_renderbuffers(struct gl_context *ctx);
+
+extern void
+_swrast_unmap_renderbuffers(struct gl_context *ctx);
+
/**
* Called prior to framebuffer reading/writing.
diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index 02cae26..fbef71f 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -647,35 +647,7 @@ _swrast_render_texture(struct gl_context *ctx,
{
struct swrast_texture_image *swImg =
swrast_texture_image(_mesa_get_attachment_teximage(att));
- const GLenum target = swImg->Base.TexObject->Target;
- gl_format format;
- GLuint slice;
-
- if (!swImg->SliceMaps) {
- swImg->SliceMaps =
- (GLubyte **) calloc(swImg->Base.Depth, sizeof(GLubyte *));
- if (!swImg->SliceMaps) {
- return; /* XXX error */
- }
- }
- assert(swImg->SliceMaps);
-
- /* We don't use the Zoffset for 1D array textures */
- if (target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY)
- slice = att->Zoffset;
- else
- slice = 0;
-
- ctx->Driver.MapTextureImage(ctx,
- &swImg->Base,
- slice,
- 0, 0,
- swImg->Base.Width, swImg->Base.Height,
- GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
- &swImg->SliceMaps[slice],
- &swImg->RowStride);
-
- format = swImg->Base.TexFormat;
+ gl_format format = swImg->Base.TexFormat;
swImg->TexelSize = _mesa_get_format_bytes(format);
swImg->Fetch = _swrast_get_texel_fetch_func(format);
swImg->Store = _swrast_get_texel_store_func(format);
@@ -691,11 +663,5 @@ void
_swrast_finish_render_texture(struct gl_context *ctx,
struct gl_renderbuffer_attachment *att)
{
- struct gl_texture_image *texImage = _mesa_get_attachment_teximage(att);
-
- struct swrast_texture_image *swImg = swrast_texture_image(texImage);
-
- /* just unmap the texture image buffer */
- ctx->Driver.UnmapTextureImage(ctx, texImage, att->Zoffset);
- swImg->SliceMaps[0] = NULL;
+ /* nothing */
}
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 6e935ac..ebc2f88 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -27,6 +27,7 @@
#include "main/context.h"
+#include "main/fbobject.h"
#include "swrast/swrast.h"
#include "swrast/s_context.h"
@@ -338,6 +339,120 @@ _swrast_unmap_textures(struct gl_context *ctx)
}
+static void
+map_renderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer_attachment *att)
+{
+ struct swrast_texture_image *swImg =
+ swrast_texture_image(_mesa_get_attachment_teximage(att));
+ const GLenum target = att->Texture->Target;
+ GLuint slice;
+
+ if (!swImg->SliceMaps) {
+ swImg->SliceMaps =
+ (GLubyte **) calloc(swImg->Base.Depth, sizeof(GLubyte *));
+ if (!swImg->SliceMaps) {
+ return; /* XXX error */
+ }
+ }
+ assert(swImg->SliceMaps);
+
+ /* We don't use the Zoffset for 1D array textures */
+ if (target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY)
+ slice = att->Zoffset;
+ else
+ slice = 0;
+
+ ctx->Driver.MapTextureImage(ctx,
+ &swImg->Base,
+ slice,
+ 0, 0,
+ swImg->Base.Width, swImg->Base.Height,
+ GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
+ &swImg->SliceMaps[slice],
+ &swImg->RowStride);
+}
+
+
+static void
+unmap_renderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer_attachment *att)
+{
+ const GLenum target = att->Texture->Target;
+ struct gl_texture_image *texImage = _mesa_get_attachment_teximage(att);
+ struct swrast_texture_image *swImg = swrast_texture_image(texImage);
+ GLuint slice;
+
+ /* We don't use the Zoffset for 1D array textures */
+ if (target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY)
+ slice = att->Zoffset;
+ else
+ slice = 0;
+
+ /* just unmap the texture image buffer */
+ ctx->Driver.UnmapTextureImage(ctx, texImage, slice);
+ swImg->SliceMaps[slice] = NULL;
+}
+
+
+static void
+map_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ GLuint buf;
+
+ for (buf = 0; buf < Elements(fb->Attachment); buf++) {
+ struct gl_renderbuffer_attachment *att = &fb->Attachment[buf];
+ if (att->Texture) {
+ map_renderbuffer(ctx, att);
+ }
+ }
+}
+
+
+static void
+unmap_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb)
+{
+ GLuint buf;
+
+ for (buf = 0; buf < Elements(fb->Attachment); buf++) {
+ struct gl_renderbuffer_attachment *att = &fb->Attachment[buf];
+ if (att->Texture) {
+ unmap_renderbuffer(ctx, att);
+ }
+ }
+}
+
+
+/**
+ * Map all the renderbuffers (or the textures they point at) prior
+ * to software rendering.
+ */
+void
+_swrast_map_renderbuffers(struct gl_context *ctx)
+{
+ map_renderbuffers(ctx, ctx->DrawBuffer);
+
+ if (ctx->ReadBuffer != ctx->DrawBuffer) {
+ map_renderbuffers(ctx, ctx->ReadBuffer);
+ }
+}
+
+
+/**
+ * Unmap all the renderbuffers (or the textures they point at) after
+ * software rendering.
+ */
+void
+_swrast_unmap_renderbuffers(struct gl_context *ctx)
+{
+ unmap_renderbuffers(ctx, ctx->DrawBuffer);
+
+ if (ctx->ReadBuffer != ctx->DrawBuffer) {
+ unmap_renderbuffers(ctx, ctx->ReadBuffer);
+ }
+}
+
+
/**
* Allocate a new swrast_texture_image (a subclass of gl_texture_image).
More information about the mesa-commit
mailing list