softpipe: rename sp_headers.h to sp_quad.h
[mesa.git] / src / gallium / drivers / softpipe / sp_quad_bufloop.c
1
2 #include "util/u_memory.h"
3 #include "sp_context.h"
4 #include "sp_quad.h"
5 #include "sp_surface.h"
6 #include "sp_quad_pipe.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[PIPE_MAX_COLOR_BUFS][4][QUAD_SIZE];
17 unsigned i;
18
19 assert(sizeof(quad->outputs.color) == sizeof(tmp));
20 assert(softpipe->framebuffer.nr_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.nr_cbufs; i++) {
32 /* set current cbuffer */
33 #if 0 /* obsolete & going away */
34 softpipe->current_cbuf = i;
35 #endif
36
37 /* pass blended quad to next stage */
38 qs->next->run(qs->next, quad);
39
40 /* restore quad's colors for next buffer */
41 memcpy(quad->outputs.color, tmp, sizeof(tmp));
42 }
43 }
44
45
46 static void cbuf_loop_begin(struct quad_stage *qs)
47 {
48 qs->next->begin(qs->next);
49 }
50
51
52 static void cbuf_loop_destroy(struct quad_stage *qs)
53 {
54 FREE( qs );
55 }
56
57
58 /**
59 * Create the colorbuffer loop stage.
60 * This is used to implement multiple render targets and GL_FRONT_AND_BACK
61 * rendering.
62 */
63 struct quad_stage *sp_quad_bufloop_stage( struct softpipe_context *softpipe )
64 {
65 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
66
67 stage->softpipe = softpipe;
68 stage->begin = cbuf_loop_begin;
69 stage->run = cbuf_loop_quad;
70 stage->destroy = cbuf_loop_destroy;
71
72 return stage;
73 }
74