fix softpipe_clear() to handle ps->offset!=0 (such as when rendering to texture and...
[mesa.git] / src / mesa / pipe / 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->cbuf = softpipe->framebuffer.cbufs[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 softpipe->cbuf = NULL; /* prevent accidental use */
43 }
44
45
46 static void cbuf_loop_begin(struct quad_stage *qs)
47 {
48 if (qs->next)
49 qs->next->begin(qs->next);
50 }
51
52
53 /**
54 * Create the colorbuffer loop stage.
55 * This is used to implement multiple render targets and GL_FRONT_AND_BACK
56 * rendering.
57 */
58 struct quad_stage *sp_quad_bufloop_stage( struct softpipe_context *softpipe )
59 {
60 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
61
62 stage->softpipe = softpipe;
63 stage->begin = cbuf_loop_begin;
64 stage->run = cbuf_loop_quad;
65
66 return stage;
67 }
68