From 1c09bcfdda4083636a3ac27d804a34ef87875ce7 Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 11 Mar 2007 17:00:39 -0600 Subject: Implement support for GL_ARB_draw_buffers with GL_MAX_DRAW_BUFFERS > 1. GL_MAX_DRAW_BUFFERS is currently 4. Added gl_FragData[] output for fragment programs. In _swrast_write_rgba_span() loop over the color outputs/renderbuffers. --- src/mesa/swrast/s_fragprog.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/mesa/swrast/s_fragprog.c') diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index dbfc1b8c0c..7260759306 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -139,7 +139,9 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, static void run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end) { + SWcontext *swrast = SWRAST_CONTEXT(ctx); const struct gl_fragment_program *program = ctx->FragmentProgram._Current; + const GLbitfield outputsWritten = program->Base.OutputsWritten; struct gl_program_machine machine; GLuint i; @@ -148,12 +150,28 @@ run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end) init_machine(ctx, &machine, program, span, i); if (_mesa_execute_program(ctx, &program->Base, &machine)) { + /* Store result color */ - COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0][i], - machine.Outputs[FRAG_RESULT_COLR]); + if (outputsWritten & (1 << FRAG_RESULT_COLR)) { + COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0][i], + machine.Outputs[FRAG_RESULT_COLR]); + } + else { + /* Multiple drawbuffers / render targets + * Note that colors beyond 0 and 1 will overwrite other + * attributes, such as FOGC, TEX0, TEX1, etc. That's OK. + */ + GLuint output; + for (output = 0; output < swrast->_NumColorOutputs; output++) { + if (outputsWritten & (1 << (FRAG_RESULT_DATA0 + output))) { + COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0+output][i], + machine.Outputs[FRAG_RESULT_DATA0 + output]); + } + } + } /* Store result depth/z */ - if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) { + if (outputsWritten & (1 << FRAG_RESULT_DEPR)) { const GLfloat depth = machine.Outputs[FRAG_RESULT_DEPR][2]; if (depth <= 0.0) span->array->z[i] = 0; -- cgit v1.2.3