summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/softpipe/sp_quad_bufloop.c
blob: 47ae7c9d6c6e7efb74d9c5639c4e2bc5d011aaab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

#include "util/u_memory.h"
#include "sp_context.h"
#include "sp_headers.h"
#include "sp_surface.h"
#include "sp_quad_pipe.h"


/**
 * Loop over colorbuffers, passing quad to next stage each time.
 */
static void
cbuf_loop_quad(struct quad_stage *qs, struct quad_header *quad)
{
   struct softpipe_context *softpipe = qs->softpipe;
   float tmp[PIPE_MAX_COLOR_BUFS][4][QUAD_SIZE];
   unsigned i;

   assert(sizeof(quad->outputs.color) == sizeof(tmp));
   assert(softpipe->framebuffer.nr_cbufs <= PIPE_MAX_COLOR_BUFS);

   /* make copy of original colors since they can get modified
    * by blending and masking.
    * XXX we won't have to do this if the fragment program actually emits
    * N separate colors and we're drawing to N color buffers (MRT).
    * But if we emitted one color and glDrawBuffer(GL_FRONT_AND_BACK) is
    * in effect, we need to save/restore colors like this.
    */
   memcpy(tmp, quad->outputs.color, sizeof(tmp));

   for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) {
      /* set current cbuffer */
#if 0 /* obsolete & going away */
      softpipe->current_cbuf = i;
#endif

      /* pass blended quad to next stage */
      qs->next->run(qs->next, quad);

      /* restore quad's colors for next buffer */
      memcpy(quad->outputs.color, tmp, sizeof(tmp));
   }
}


static void cbuf_loop_begin(struct quad_stage *qs)
{
   qs->next->begin(qs->next);
}


static void cbuf_loop_destroy(struct quad_stage *qs)
{
   FREE( qs );
}


/**
 * Create the colorbuffer loop stage.
 * This is used to implement multiple render targets and GL_FRONT_AND_BACK
 * rendering.
 */
struct quad_stage *sp_quad_bufloop_stage( struct softpipe_context *softpipe )
{
   struct quad_stage *stage = CALLOC_STRUCT(quad_stage);

   stage->softpipe = softpipe;
   stage->begin = cbuf_loop_begin;
   stage->run = cbuf_loop_quad;
   stage->destroy = cbuf_loop_destroy;

   return stage;
}