softpipe: rename PRIM_x to QUAD_PRIM_x
[mesa.git] / src / gallium / drivers / softpipe / sp_quad_output.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "util/u_memory.h"
29 #include "sp_context.h"
30 #include "sp_quad.h"
31 #include "sp_surface.h"
32 #include "sp_quad_pipe.h"
33 #include "sp_tile_cache.h"
34
35
36 /**
37 * Last step of quad processing: write quad colors to the framebuffer,
38 * taking mask into account.
39 */
40 static void
41 output_quad(struct quad_stage *qs, struct quad_header *quad)
42 {
43 /* in-tile pos: */
44 const int itx = quad->input.x0 % TILE_SIZE;
45 const int ity = quad->input.y0 % TILE_SIZE;
46
47 struct softpipe_context *softpipe = qs->softpipe;
48 uint cbuf;
49
50 /* loop over colorbuffer outputs */
51 for (cbuf = 0; cbuf < softpipe->framebuffer.nr_cbufs; cbuf++) {
52 struct softpipe_cached_tile *tile
53 = sp_get_cached_tile(softpipe,
54 softpipe->cbuf_cache[cbuf],
55 quad->input.x0, quad->input.y0);
56 float (*quadColor)[4] = quad->output.color[cbuf];
57 int i, j;
58
59 /* get/swizzle dest colors */
60 for (j = 0; j < QUAD_SIZE; j++) {
61 if (quad->inout.mask & (1 << j)) {
62 int x = itx + (j & 1);
63 int y = ity + (j >> 1);
64 for (i = 0; i < 4; i++) { /* loop over color chans */
65 tile->data.color[y][x][i] = quadColor[i][j];
66 }
67 if (0) {
68 debug_printf("sp write pixel %d,%d: %g, %g, %g\n",
69 quad->input.x0 + x,
70 quad->input.y0 + y,
71 quadColor[0][j],
72 quadColor[1][j],
73 quadColor[2][j]);
74 }
75 }
76 }
77 }
78 }
79
80
81 static void output_begin(struct quad_stage *qs)
82 {
83 assert(qs->next == NULL);
84 }
85
86
87 static void output_destroy(struct quad_stage *qs)
88 {
89 FREE( qs );
90 }
91
92
93 struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe )
94 {
95 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
96
97 stage->softpipe = softpipe;
98 stage->begin = output_begin;
99 stage->run = output_quad;
100 stage->destroy = output_destroy;
101
102 return stage;
103 }