2 #include "pipe/p_util.h"
3 #include "sp_context.h"
4 #include "sp_headers.h"
5 #include "sp_surface.h"
10 * Loop over colorbuffers, passing quad to next stage each time.
13 cbuf_loop_quad(struct quad_stage
*qs
, struct quad_header
*quad
)
15 struct softpipe_context
*softpipe
= qs
->softpipe
;
16 float tmp
[4][QUAD_SIZE
];
19 assert(sizeof(quad
->outputs
.color
) == sizeof(tmp
));
20 assert(softpipe
->framebuffer
.num_cbufs
<= PIPE_MAX_COLOR_BUFS
);
22 /* make copy of original colors since they can get modified
23 * by blending and masking.
24 * XXX we won't have to do this if the fragment program actually emits
25 * N separate colors and we're drawing to N color buffers (MRT).
26 * But if we emitted one color and glDrawBuffer(GL_FRONT_AND_BACK) is
27 * in effect, we need to save/restore colors like this.
29 memcpy(tmp
, quad
->outputs
.color
, sizeof(tmp
));
31 for (i
= 0; i
< softpipe
->framebuffer
.num_cbufs
; i
++) {
32 /* set current cbuffer */
33 softpipe
->cbuf
= softpipe
->framebuffer
.cbufs
[i
];
35 /* pass blended quad to next stage */
36 qs
->next
->run(qs
->next
, quad
);
38 /* restore quad's colors for next buffer */
39 memcpy(quad
->outputs
.color
, tmp
, sizeof(tmp
));
42 softpipe
->cbuf
= NULL
; /* prevent accidental use */
46 static void cbuf_loop_begin(struct quad_stage
*qs
)
49 qs
->next
->begin(qs
->next
);
54 * Create the colorbuffer loop stage.
55 * This is used to implement multiple render targets and GL_FRONT_AND_BACK
58 struct quad_stage
*sp_quad_bufloop_stage( struct softpipe_context
*softpipe
)
60 struct quad_stage
*stage
= CALLOC_STRUCT(quad_stage
);
62 stage
->softpipe
= softpipe
;
63 stage
->begin
= cbuf_loop_begin
;
64 stage
->run
= cbuf_loop_quad
;