diff options
author | Brian Paul <[email protected]> | 2011-12-10 11:44:43 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2011-12-13 06:45:37 -0700 |
commit | c0a55cf68aa80cacbc709b25205705eee2e3bbdb (patch) | |
tree | 71a54112c58ea1aa7ebd5155a3c1c907d51b72da /src/mesa/main/depthstencil.c | |
parent | 2750809b2e9a7d24d83d01f0a1d5bb5dce027b4c (diff) |
mesa: move update_depth/stencil_buffer() functions
These functions update the gl_framebuffer::_DepthBuffer and _StencilBuffer
fields, possibly creating renderbuffer wrappers that make a shared
depth+stencil accessible as depth-only or stencil only.
This stuff is only used by swrast now and will be moved there next.
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/mesa/main/depthstencil.c')
-rw-r--r-- | src/mesa/main/depthstencil.c | 90 |
1 files changed, 82 insertions, 8 deletions
diff --git a/src/mesa/main/depthstencil.c b/src/mesa/main/depthstencil.c index af5c12f67fc..18f2705a479 100644 --- a/src/mesa/main/depthstencil.c +++ b/src/mesa/main/depthstencil.c @@ -349,9 +349,9 @@ put_mono_values_z24(struct gl_context *ctx, struct gl_renderbuffer *z24rb, * a depth renderbuffer. * \return new depth renderbuffer */ -struct gl_renderbuffer * -_mesa_new_z24_renderbuffer_wrapper(struct gl_context *ctx, - struct gl_renderbuffer *dsrb) +static struct gl_renderbuffer * +new_z24_renderbuffer_wrapper(struct gl_context *ctx, + struct gl_renderbuffer *dsrb) { struct gl_renderbuffer *z24rb; @@ -563,9 +563,9 @@ put_mono_values_z32f(struct gl_context *ctx, struct gl_renderbuffer *z32frb, * a depth renderbuffer. * \return new depth renderbuffer */ -struct gl_renderbuffer * -_mesa_new_z32f_renderbuffer_wrapper(struct gl_context *ctx, - struct gl_renderbuffer *dsrb) +static struct gl_renderbuffer * +new_z32f_renderbuffer_wrapper(struct gl_context *ctx, + struct gl_renderbuffer *dsrb) { struct gl_renderbuffer *z32frb; @@ -915,8 +915,8 @@ put_mono_values_s8(struct gl_context *ctx, struct gl_renderbuffer *s8rb, GLuint * a stencil renderbuffer. * \return new stencil renderbuffer */ -struct gl_renderbuffer * -_mesa_new_s8_renderbuffer_wrapper(struct gl_context *ctx, struct gl_renderbuffer *dsrb) +static struct gl_renderbuffer * +new_s8_renderbuffer_wrapper(struct gl_context *ctx, struct gl_renderbuffer *dsrb) { struct gl_renderbuffer *s8rb; @@ -957,3 +957,77 @@ _mesa_new_s8_renderbuffer_wrapper(struct gl_context *ctx, struct gl_renderbuffer return s8rb; } + + +/** + * Update the framebuffer's _DepthBuffer field using the renderbuffer + * found at the given attachment index. + * + * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer, + * create and install a depth wrapper/adaptor. + * + * \param fb the framebuffer whose _DepthBuffer field to update + */ +void +_mesa_update_depth_buffer(struct gl_context *ctx, struct gl_framebuffer *fb) +{ + struct gl_renderbuffer *depthRb = + fb->Attachment[BUFFER_DEPTH].Renderbuffer; + + if (depthRb && _mesa_is_format_packed_depth_stencil(depthRb->Format)) { + /* The attached depth buffer is a GL_DEPTH_STENCIL renderbuffer */ + if (!fb->_DepthBuffer + || fb->_DepthBuffer->Wrapped != depthRb + || _mesa_get_format_base_format(fb->_DepthBuffer->Format) != GL_DEPTH_COMPONENT) { + /* need to update wrapper */ + struct gl_renderbuffer *wrapper; + + if (depthRb->Format == MESA_FORMAT_Z32_FLOAT_X24S8) { + wrapper = new_z32f_renderbuffer_wrapper(ctx, depthRb); + } + else { + wrapper = new_z24_renderbuffer_wrapper(ctx, depthRb); + } + _mesa_reference_renderbuffer(&fb->_DepthBuffer, wrapper); + ASSERT(fb->_DepthBuffer->Wrapped == depthRb); + } + } + else { + /* depthRb may be null */ + _mesa_reference_renderbuffer(&fb->_DepthBuffer, depthRb); + } +} + + +/** + * Update the framebuffer's _StencilBuffer field using the renderbuffer + * found at the given attachment index. + * + * If that attachment points to a combined GL_DEPTH_STENCIL renderbuffer, + * create and install a stencil wrapper/adaptor. + * + * \param fb the framebuffer whose _StencilBuffer field to update + */ +void +_mesa_update_stencil_buffer(struct gl_context *ctx, struct gl_framebuffer *fb) +{ + struct gl_renderbuffer *stencilRb = + fb->Attachment[BUFFER_STENCIL].Renderbuffer; + + if (stencilRb && _mesa_is_format_packed_depth_stencil(stencilRb->Format)) { + /* The attached stencil buffer is a GL_DEPTH_STENCIL renderbuffer */ + if (!fb->_StencilBuffer + || fb->_StencilBuffer->Wrapped != stencilRb + || _mesa_get_format_base_format(fb->_StencilBuffer->Format) != GL_STENCIL_INDEX) { + /* need to update wrapper */ + struct gl_renderbuffer *wrapper + = new_s8_renderbuffer_wrapper(ctx, stencilRb); + _mesa_reference_renderbuffer(&fb->_StencilBuffer, wrapper); + ASSERT(fb->_StencilBuffer->Wrapped == stencilRb); + } + } + else { + /* stencilRb may be null */ + _mesa_reference_renderbuffer(&fb->_StencilBuffer, stencilRb); + } +} |