diff options
Diffstat (limited to 'src/mesa/main/framebuffer.c')
-rw-r--r-- | src/mesa/main/framebuffer.c | 165 |
1 files changed, 109 insertions, 56 deletions
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index 494743f134..af78363ad3 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -32,6 +32,7 @@ #include "glheader.h" #include "imports.h" +#include "buffers.h" #include "context.h" #include "depthstencil.h" #include "mtypes.h" @@ -108,8 +109,9 @@ _mesa_new_framebuffer(GLcontext *ctx, GLuint name) if (fb) { fb->Name = name; fb->RefCount = 1; + fb->_NumColorDrawBuffers = 1; fb->ColorDrawBuffer[0] = GL_COLOR_ATTACHMENT0_EXT; - fb->_ColorDrawBufferMask[0] = BUFFER_BIT_COLOR0; + fb->_ColorDrawBufferIndexes[0] = BUFFER_COLOR0; fb->ColorReadBuffer = GL_COLOR_ATTACHMENT0_EXT; fb->_ColorReadBufferIndex = BUFFER_COLOR0; fb->Delete = _mesa_destroy_framebuffer; @@ -138,16 +140,18 @@ _mesa_initialize_framebuffer(struct gl_framebuffer *fb, const GLvisual *visual) /* save the visual */ fb->Visual = *visual; - /* Init glRead/DrawBuffer state */ + /* Init read/draw renderbuffer state */ if (visual->doubleBufferMode) { + fb->_NumColorDrawBuffers = 1; fb->ColorDrawBuffer[0] = GL_BACK; - fb->_ColorDrawBufferMask[0] = BUFFER_BIT_BACK_LEFT; + fb->_ColorDrawBufferIndexes[0] = BUFFER_BACK_LEFT; fb->ColorReadBuffer = GL_BACK; fb->_ColorReadBufferIndex = BUFFER_BACK_LEFT; } else { + fb->_NumColorDrawBuffers = 1; fb->ColorDrawBuffer[0] = GL_FRONT; - fb->_ColorDrawBufferMask[0] = BUFFER_BIT_FRONT_LEFT; + fb->_ColorDrawBufferIndexes[0] = BUFFER_FRONT_LEFT; fb->ColorReadBuffer = GL_FRONT; fb->_ColorReadBufferIndex = BUFFER_FRONT_LEFT; } @@ -660,8 +664,53 @@ _mesa_update_stencil_buffer(GLcontext *ctx, } +/* + * Example DrawBuffers scenarios: + * + * 1. glDrawBuffer(GL_FRONT_AND_BACK), fixed-func or shader writes to + * "gl_FragColor" or program writes to the "result.color" register: + * + * fragment color output renderbuffer + * --------------------- --------------- + * color[0] Front, Back + * + * + * 2. glDrawBuffers(3, [GL_FRONT, GL_AUX0, GL_AUX1]), shader writes to + * gl_FragData[i] or program writes to result.color[i] registers: + * + * fragment color output renderbuffer + * --------------------- --------------- + * color[0] Front + * color[1] Aux0 + * color[3] Aux1 + * + * + * 3. glDrawBuffers(3, [GL_FRONT, GL_AUX0, GL_AUX1]) and shader writes to + * gl_FragColor, or fixed function: + * + * fragment color output renderbuffer + * --------------------- --------------- + * color[0] Front, Aux0, Aux1 + * + * + * In either case, the list of renderbuffers is stored in the + * framebuffer->_ColorDrawBuffers[] array and + * framebuffer->_NumColorDrawBuffers indicates the number of buffers. + * The renderer (like swrast) has to look at the current fragment shader + * to see if it writes to gl_FragColor vs. gl_FragData[i] to determine + * how to map color outputs to renderbuffers. + * + * Note that these two calls are equivalent (for fixed function fragment + * shading anyway): + * a) glDrawBuffer(GL_FRONT_AND_BACK); (assuming non-stereo framebuffer) + * b) glDrawBuffers(2, [GL_FRONT_LEFT, GL_BACK_LEFT]); + */ + + + + /** - * Update the list of color drawing renderbuffer pointers. + * Update the (derived) list of color drawing renderbuffer pointers. * Later, when we're rendering we'll loop from 0 to _NumColorDrawBuffers * writing colors. */ @@ -670,42 +719,23 @@ update_color_draw_buffers(GLcontext *ctx, struct gl_framebuffer *fb) { GLuint output; - /* - * Fragment programs can write to multiple colorbuffers with - * the GL_ARB_draw_buffers extension. - */ - for (output = 0; output < ctx->Const.MaxDrawBuffers; output++) { - GLbitfield bufferMask = fb->_ColorDrawBufferMask[output]; - GLuint count = 0; - GLuint i; - if (!fb->DeletePending) { - /* We need the inner loop here because glDrawBuffer(GL_FRONT_AND_BACK) - * can specify writing to two or four color buffers (for example). - */ - for (i = 0; bufferMask && i < BUFFER_COUNT; i++) { - const GLuint bufferBit = 1 << i; - if (bufferBit & bufferMask) { - struct gl_renderbuffer *rb = fb->Attachment[i].Renderbuffer; - if (rb && rb->Width > 0 && rb->Height > 0) { - fb->_ColorDrawBuffers[output][count] = rb; - count++; - } - else { - /* - _mesa_warning(ctx, "DrawBuffer names a missing buffer!\n"); - */ - } - bufferMask &= ~bufferBit; - } - } + /* set 0th buffer to NULL now in case _NumColorDrawBuffers is zero */ + fb->_ColorDrawBuffers[0] = NULL; + + for (output = 0; output < fb->_NumColorDrawBuffers; output++) { + GLint buf = fb->_ColorDrawBufferIndexes[output]; + if (buf >= 0) { + fb->_ColorDrawBuffers[output] = fb->Attachment[buf].Renderbuffer; + } + else { + fb->_ColorDrawBuffers[output] = NULL; } - fb->_NumColorDrawBuffers[output] = count; } } /** - * Update the color read renderbuffer pointer. + * Update the (derived) color read renderbuffer pointer. * Unlike the DrawBuffer, we can only read from one (or zero) color buffers. */ static void @@ -727,19 +757,51 @@ update_color_read_buffer(GLcontext *ctx, struct gl_framebuffer *fb) } +/** + * Update a gl_framebuffer's derived state. + * + * Specifically, update these framebuffer fields: + * _ColorDrawBuffers + * _NumColorDrawBuffers + * _ColorReadBuffer + * _DepthBuffer + * _StencilBuffer + * + * If the framebuffer is user-created, make sure it's complete. + * + * The following functions (at least) can effect framebuffer state: + * glReadBuffer, glDrawBuffer, glDrawBuffersARB, glFramebufferRenderbufferEXT, + * glRenderbufferStorageEXT. + */ static void update_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb) { - /* Completeness only matters for user-created framebuffers */ - if (fb->Name != 0) { - /* XXX: EXT_framebuffer_blit: - framebuffer must still be complete wrt read/draw? */ + if (fb->Name == 0) { + /* This is a window-system framebuffer */ + /* Need to update the FB's GL_DRAW_BUFFER state to match the + * context state (GL_READ_BUFFER too). + */ + if (fb->ColorDrawBuffer[0] != ctx->Color.DrawBuffer[0]) { + _mesa_drawbuffers(ctx, ctx->Const.MaxDrawBuffers, + ctx->Color.DrawBuffer, NULL); + } + if (fb->ColorReadBuffer != ctx->Pixel.ReadBuffer) { + + } + } + else { + /* This is a user-created framebuffer. + * Completeness only matters for user-created framebuffers. + */ _mesa_test_framebuffer_completeness(ctx, fb); _mesa_update_framebuffer_visual(fb); } - /* update_color_draw/read_buffers not needed for - read/draw only fb, but shouldn't hurt ??? */ + /* Strictly speaking, we don't need to update the draw-state + * if this FB is bound as ctx->ReadBuffer (and conversely, the + * read-state if this FB is bound as ctx->DrawBuffer), but no + * harm. + */ update_color_draw_buffers(ctx, fb); update_color_read_buffer(ctx, fb); _mesa_update_depth_buffer(ctx, fb, BUFFER_DEPTH); @@ -748,28 +810,19 @@ update_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb) compute_depth_max(fb); } + /** * Update state related to the current draw/read framebuffers. - * Specifically, update these framebuffer fields: - * _ColorDrawBuffers - * _NumColorDrawBuffers - * _ColorReadBuffer - * _DepthBuffer - * _StencilBuffer - * If the current framebuffer is user-created, make sure it's complete. - * The following functions can effect this state: glReadBuffer, - * glDrawBuffer, glDrawBuffersARB, glFramebufferRenderbufferEXT, - * glRenderbufferStorageEXT. */ void _mesa_update_framebuffer(GLcontext *ctx) { - struct gl_framebuffer *fb = ctx->DrawBuffer; - struct gl_framebuffer *fbread = ctx->ReadBuffer; + struct gl_framebuffer *drawFb = ctx->DrawBuffer; + struct gl_framebuffer *readFb = ctx->ReadBuffer; - update_framebuffer(ctx, fb); - if (fbread != fb) - update_framebuffer(ctx, fbread); + update_framebuffer(ctx, drawFb); + if (readFb != drawFb) + update_framebuffer(ctx, readFb); } |