Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / gallium / drivers / softpipe / sp_quad_bufloop.c
1
2 #include "pipe/p_util.h"
3 #include "sp_context.h"
4 #include "sp_headers.h"
5 #include "sp_surface.h"
6 #include "sp_quad.h"
7
8
9 /**
10 * Loop over colorbuffers, passing quad to next stage each time.
11 */
12 static void
13 cbuf_loop_quad(struct quad_stage *qs, struct quad_header *quad)
14 {
15 struct softpipe_context *softpipe = qs->softpipe;
16 float tmp[4][QUAD_SIZE];
17 unsigned i;
18
19 assert(sizeof(quad->outputs.color) == sizeof(tmp));
20 assert(softpipe->framebuffer.num_cbufs <= PIPE_MAX_COLOR_BUFS);
21
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.
28 */
29 memcpy(tmp, quad->outputs.color, sizeof(tmp));
30
31 for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) {
32 /* set current cbuffer */
33 softpipe->current_cbuf = i;
34
35 /* pass blended quad to next stage */
36 qs->next->run(qs->next, quad);
37
38 /* restore quad's colors for next buffer */
39 memcpy(quad->outputs.color, tmp, sizeof(tmp));
40 }
41 }
42
43
44 static void cbuf_loop_begin(struct quad_stage *qs)
45 {
46 qs->next->begin(qs->next);
47 }
48
49
50 static void cbuf_loop_destroy(struct quad_stage *qs)
51 {
52 FREE( qs );
53 }
54
55
56 /**
57 * Create the colorbuffer loop stage.
58 * This is used to implement multiple render targets and GL_FRONT_AND_BACK
59 * rendering.
60 */
61 struct quad_stage *sp_quad_bufloop_stage( struct softpipe_context *softpipe )
62 {
63 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
64
65 stage->softpipe = softpipe;
66 stage->begin = cbuf_loop_begin;
67 stage->run = cbuf_loop_quad;
68 stage->destroy = cbuf_loop_destroy;
69
70 return stage;
71 }
72