diff options
author | Brian Paul <[email protected]> | 2012-01-16 10:55:25 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2012-01-24 14:12:14 -0700 |
commit | 7d1ddec92168e9b6ead0da80b18364a75f9a85e6 (patch) | |
tree | b6ea2d9bad4e6401f9dda0b205484a4759bdabb4 /src/mesa/swrast | |
parent | 14da67d9b9b9e30740ef1687c3952a0b5e8b0a54 (diff) |
mesa: use gl_renderbuffer::Map for all depth/stencil accesses
Instead of using the obsolete gl_renderbuffer::Data field.
Color buffer are still accessed through GetRow/PutRow().
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r-- | src/mesa/swrast/s_context.h | 6 | ||||
-rw-r--r-- | src/mesa/swrast/s_texture.c | 141 |
2 files changed, 110 insertions, 37 deletions
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index 36ab86a5e84..7f1e4c78ee4 100644 --- a/src/mesa/swrast/s_context.h +++ b/src/mesa/swrast/s_context.h @@ -429,7 +429,7 @@ static inline GLubyte * _swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y) { const GLint bpp = _mesa_get_format_bytes(rb->Format); - const GLint rowStride = rb->RowStride * bpp; + const GLint rowStride = rb->RowStrideBytes; assert(x >= 0); assert(y >= 0); /* NOTE: using <= only because of s_tritemp.h which gets a pixel @@ -437,8 +437,8 @@ _swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y) */ assert(x <= (GLint) rb->Width); assert(y <= (GLint) rb->Height); - assert(rb->Data); - return (GLubyte *) rb->Data + y * rowStride + x * bpp; + assert(rb->Map); + return (GLubyte *) rb->Map + y * rowStride + x * bpp; } diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index a50018dfd4b..f945a6b0fa8 100644 --- a/src/mesa/swrast/s_texture.c +++ b/src/mesa/swrast/s_texture.c @@ -315,57 +315,130 @@ _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) +map_attachment(struct gl_context *ctx, + struct gl_framebuffer *fb, + gl_buffer_index buffer) { - 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->Map = swImage->Buffer; - } - else { - /* XXX we'll eventually call _swrast_unmap_teximage() here */ - swImage->Map = NULL; - } + struct gl_texture_object *texObj = fb->Attachment[buffer].Texture; + struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer; + + if (texObj) { + const GLuint level = fb->Attachment[buffer].TextureLevel; + const GLuint face = fb->Attachment[buffer].CubeMapFace; + 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->Map = swImage->Buffer; + if (rb) { + rb->Map = swImage->Buffer; + rb->RowStrideBytes = swImage->RowStride * + _mesa_get_format_bytes(swImage->Base.TexFormat); } } } + else if (rb) { + /* Map ordinary renderbuffer */ + /* XXX don't map color buffers yet */ + if (buffer == BUFFER_DEPTH || buffer == BUFFER_STENCIL) { + ctx->Driver.MapRenderbuffer(ctx, rb, + 0, 0, rb->Width, rb->Height, + GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, + &rb->Map, &rb->RowStrideBytes); + assert(rb->Map); + } + } } + +static void +unmap_attachment(struct gl_context *ctx, + struct gl_framebuffer *fb, + gl_buffer_index buffer) +{ + struct gl_texture_object *texObj = fb->Attachment[buffer].Texture; + struct gl_renderbuffer *rb = fb->Attachment[buffer].Renderbuffer; + + if (texObj) { + const GLuint level = fb->Attachment[buffer].TextureLevel; + const GLuint face = fb->Attachment[buffer].CubeMapFace; + struct gl_texture_image *texImage = texObj->Image[face][level]; + if (texImage) { + + /* XXX we'll eventually call _swrast_unmap_teximage() here */ + } + } + else if (rb) { + /* unmap ordinary renderbuffer */ + /* XXX don't map color buffers yet */ + if (buffer == BUFFER_DEPTH || buffer == BUFFER_STENCIL) { + ctx->Driver.UnmapRenderbuffer(ctx, rb); + } + } + rb->Map = NULL; + rb->RowStrideBytes = 0; +} + + +/** + * Map the renderbuffers we'll use for tri/line/point rendering. + */ 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); -} + struct gl_framebuffer *fb = ctx->DrawBuffer; + struct gl_renderbuffer *depthRb, *stencilRb; + GLuint buf; + + depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; + if (depthRb) { + /* map depth buffer */ + map_attachment(ctx, fb, BUFFER_DEPTH); + } + stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; + if (stencilRb && stencilRb != depthRb) { + /* map stencil buffer */ + map_attachment(ctx, fb, BUFFER_STENCIL); + } + for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) { + map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]); + } +} + + +/** + * Unmap renderbuffers after rendering. + */ 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); -} + struct gl_framebuffer *fb = ctx->DrawBuffer; + struct gl_renderbuffer *depthRb, *stencilRb; + GLuint buf; + + depthRb = fb->Attachment[BUFFER_DEPTH].Renderbuffer; + if (depthRb) { + /* map depth buffer */ + unmap_attachment(ctx, fb, BUFFER_DEPTH); + } + stencilRb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; + if (stencilRb && stencilRb != depthRb) { + /* map stencil buffer */ + unmap_attachment(ctx, fb, BUFFER_STENCIL); + } + + for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) { + unmap_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]); + } +} + /** |