From: Brian Paul Date: Mon, 16 Jan 2012 17:55:25 +0000 (-0700) Subject: mesa: use gl_renderbuffer::Map for all depth/stencil accesses X-Git-Tag: 062012170305~1952 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d1ddec92168e9b6ead0da80b18364a75f9a85e6;p=profile%2Fivi%2Fmesa.git 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(). --- diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c index d4d3bf9..506c295 100644 --- a/src/mesa/drivers/dri/intel/intel_span.c +++ b/src/mesa/drivers/dri/intel/intel_span.c @@ -60,8 +60,8 @@ intel_set_span_functions(struct intel_context *intel, int minx = 0, miny = 0; \ int maxx = rb->Width; \ int maxy = rb->Height; \ - int pitch = rb->RowStride * irb->mt->region->cpp; \ - void *buf = rb->Data; \ + int pitch = rb->RowStrideBytes; \ + void *buf = rb->Map; \ GLuint p; \ (void) p; @@ -189,7 +189,7 @@ intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb) if (!irb) return; - if (rb->Data) { + if (rb->Map) { /* Renderbuffer is already mapped. This usually happens when a single * buffer is attached to the framebuffer's depth and stencil attachment * points. @@ -200,8 +200,9 @@ intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb) ctx->Driver.MapRenderbuffer(ctx, rb, 0, 0, rb->Width, rb->Height, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, &map, &stride); - rb->Data = map; + rb->Map = map; rb->RowStride = stride / _mesa_get_format_bytes(rb->Format); + rb->RowStrideBytes = stride; intel_set_span_functions(intel, rb); } @@ -216,7 +217,7 @@ intel_renderbuffer_unmap(struct intel_context *intel, if (!irb) return; - if (!rb->Data) { + if (!rb->Map) { /* Renderbuffer is already unmapped. This usually happens when a single * buffer is attached to the framebuffer's depth and stencil attachment * points. @@ -228,8 +229,9 @@ intel_renderbuffer_unmap(struct intel_context *intel, rb->GetRow = NULL; rb->PutRow = NULL; - rb->Data = NULL; + rb->Map = NULL; rb->RowStride = 0; + rb->RowStrideBytes = 0; } static void diff --git a/src/mesa/drivers/dri/radeon/radeon_span.c b/src/mesa/drivers/dri/radeon/radeon_span.c index e3bdc36..569aca9 100644 --- a/src/mesa/drivers/dri/radeon/radeon_span.c +++ b/src/mesa/drivers/dri/radeon/radeon_span.c @@ -74,8 +74,8 @@ static void radeonSetSpanFunctions(struct radeon_renderbuffer *rrb); int minx = 0, miny = 0; \ int maxx = rb->Width; \ int maxy = rb->Height; \ - void *buf = rb->Data; \ - int pitch = rb->RowStride * rrb->cpp; \ + void *buf = rb->Map; \ + int pitch = rb->RowStrideBytes; \ GLuint p; \ (void)p; @@ -178,8 +178,9 @@ radeon_renderbuffer_map(struct gl_context *ctx, struct gl_renderbuffer *rb) GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, &map, &stride); - rb->Data = map; + rb->Map = map; rb->RowStride = stride / _mesa_get_format_bytes(rb->Format); + rb->RowStrideBytes = stride; radeonSetSpanFunctions(rrb); } @@ -195,8 +196,9 @@ radeon_renderbuffer_unmap(struct gl_context *ctx, struct gl_renderbuffer *rb) rb->GetRow = NULL; rb->PutRow = NULL; - rb->Data = NULL; + rb->Map = NULL; rb->RowStride = 0; + rb->RowStrideBytes = 0; } static void diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index 36ab86a..7f1e4c7 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 a50018d..f945a6b 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]); + } +} + /**