Merge branch 'i915tex_privbuffers' into softpipe_0_1_branch
[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 struct softpipe_surface *sps = softpipe_surface(softpipe->cbuf);
69
70 if (quad->mask != MASK_ALL) {
71 GLfloat tmp[4][QUAD_SIZE];
72
73 /* XXX probably add a masked-write function someday */
74
75 sps->read_quad_f_swz(sps, quad->x0, quad->y0, tmp);
76
77 mask_copy( tmp, quad->outputs.color, quad->mask );
78
79 sps->write_quad_f_swz(sps, quad->x0, quad->y0, tmp);
80 }
81 else if (quad->mask) {
82 sps->write_quad_f_swz(sps, quad->x0, quad->y0, quad->outputs.color);
83 }
84 }
85
86
87 struct quad_stage *sp_quad_output_stage( struct softpipe_context *softpipe )
88 {
89 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
90
91 stage->softpipe = softpipe;
92 stage->run = output_quad;
93
94 return stage;
95 }