Merge branch 'master' of git+ssh://michal@git.freedesktop.org/git/mesa/mesa into...
[mesa.git] / src / mesa / pipe / softpipe / sp_quad_output.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /* Vertices are just an array of floats, with all the attributes
26 * packed. We currently assume a layout like:
27 *
28 * attr[0][0..3] - window position
29 * attr[1..n][0..3] - remaining attributes.
30 *
31 * Attributes are assumed to be 4 floats wide but are packed so that
32 * all the enabled attributes run contiguously.
33 */
34
35 #include "glheader.h"
36 #include "imports.h"
37 #include "sp_context.h"
38 #include "sp_headers.h"
39 #include "sp_surface.h"
40 #include "sp_quad.h"
41
42
43 static void mask_copy( GLfloat (*dest)[4],
44 GLfloat (*src)[4],
45 GLuint mask )
46 {
47 GLuint i, j;
48
49 for (i = 0; i < 4; i++) {
50 if (mask & (1<<i)) {
51 for (j = 0; j < 4; j++) {
52 dest[j][i] = src[j][i];
53 }
54 }
55 }
56 }
57
58
59 /**
60 * Write quad to framebuffer, taking mask into account.
61 *
62 * Note that surfaces support only full quad reads and writes.
63 */
64 static void
65 output_quad(struct quad_stage *qs, struct quad_header *quad)
66 {
67 struct softpipe_context *softpipe = qs->softpipe;
68 GLuint i;
69
70 for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) {
71 struct softpipe_surface *sps
72 = softpipe_surface(softpipe->framebuffer.cbufs[i]);
73
74 if (quad->mask != MASK_ALL) {
75 GLfloat tmp[4][QUAD_SIZE];
76
77 /* Yes, we'll probably have a masked write as well, but this is
78 * how blend will be done at least.
79 */
80
81 sps->read_quad_f_swz(sps, quad->x0, quad->y0, tmp);
82
83 mask_copy( tmp, quad->outputs.color, quad->mask );
84
85 sps->write_quad_f_swz(sps, quad->x0, quad->y0, tmp);
86 }
87 else {
88 sps->write_quad_f_swz(sps, quad->x0, quad->y0, quad->outputs.color);
89 }
90 }
91 }
92
93
94 struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe )
95 {
96 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
97
98 stage->softpipe = softpipe;
99 stage->run = output_quad;
100
101 return stage;
102 }
103