draw: corrections to allow for different cliptest cases
[mesa.git] / src / mesa / swrast / s_spantemp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.1
4 *
5 * Copyright (C) 1999-2006 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
26 /*
27 * Templates for the span/pixel-array write/read functions called via
28 * the gl_renderbuffer's GetRow, GetValues, PutRow, PutMonoRow, PutValues
29 * and PutMonoValues functions.
30 *
31 * Define the following macros before including this file:
32 * NAME(BASE) to generate the function name (i.e. add prefix or suffix)
33 * RB_TYPE the renderbuffer DataType
34 * SPAN_VARS to declare any local variables
35 * INIT_PIXEL_PTR(P, X, Y) to initialize a pointer to a pixel
36 * INC_PIXEL_PTR(P) to increment a pixel pointer by one pixel
37 * STORE_PIXEL(DST, X, Y, VALUE) to store pixel values in buffer
38 * FETCH_PIXEL(DST, SRC) to fetch pixel values from buffer
39 *
40 * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
41 * for the pixels to be stored. This is useful when dithering and probably
42 * ignored otherwise.
43 */
44
45 #include "main/macros.h"
46
47
48 #if !defined(RB_COMPONENTS)
49 #define RB_COMPONENTS 4
50 #endif
51
52
53 static void
54 NAME(get_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
55 GLuint count, GLint x, GLint y, void *values )
56 {
57 #ifdef SPAN_VARS
58 SPAN_VARS
59 #endif
60 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
61 GLuint i;
62 INIT_PIXEL_PTR(pixel, x, y);
63 for (i = 0; i < count; i++) {
64 FETCH_PIXEL(dest[i], pixel);
65 INC_PIXEL_PTR(pixel);
66 }
67 (void) rb;
68 }
69
70
71 static void
72 NAME(get_values)( GLcontext *ctx, struct gl_renderbuffer *rb,
73 GLuint count, const GLint x[], const GLint y[], void *values )
74 {
75 #ifdef SPAN_VARS
76 SPAN_VARS
77 #endif
78 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
79 GLuint i;
80 for (i = 0; i < count; i++) {
81 INIT_PIXEL_PTR(pixel, x[i], y[i]);
82 FETCH_PIXEL(dest[i], pixel);
83 }
84 (void) rb;
85 }
86
87
88 static void
89 NAME(put_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
90 GLuint count, GLint x, GLint y,
91 const void *values, const GLubyte mask[] )
92 {
93 #ifdef SPAN_VARS
94 SPAN_VARS
95 #endif
96 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
97 GLuint i;
98 INIT_PIXEL_PTR(pixel, x, y);
99 if (mask) {
100 for (i = 0; i < count; i++) {
101 if (mask[i]) {
102 STORE_PIXEL(pixel, x + i, y, src[i]);
103 }
104 INC_PIXEL_PTR(pixel);
105 }
106 }
107 else {
108 for (i = 0; i < count; i++) {
109 STORE_PIXEL(pixel, x + i, y, src[i]);
110 INC_PIXEL_PTR(pixel);
111 }
112 }
113 (void) rb;
114 }
115
116
117 static void
118 NAME(put_row_rgb)( GLcontext *ctx, struct gl_renderbuffer *rb,
119 GLuint count, GLint x, GLint y,
120 const void *values, const GLubyte mask[] )
121 {
122 #ifdef SPAN_VARS
123 SPAN_VARS
124 #endif
125 const RB_TYPE (*src)[3] = (const RB_TYPE (*)[3]) values;
126 GLuint i;
127 INIT_PIXEL_PTR(pixel, x, y);
128 for (i = 0; i < count; i++) {
129 if (!mask || mask[i]) {
130 #ifdef STORE_PIXEL_RGB
131 STORE_PIXEL_RGB(pixel, x + i, y, src[i]);
132 #else
133 STORE_PIXEL(pixel, x + i, y, src[i]);
134 #endif
135 }
136 INC_PIXEL_PTR(pixel);
137 }
138 (void) rb;
139 }
140
141
142 static void
143 NAME(put_mono_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
144 GLuint count, GLint x, GLint y,
145 const void *value, const GLubyte mask[] )
146 {
147 #ifdef SPAN_VARS
148 SPAN_VARS
149 #endif
150 const RB_TYPE *src = (const RB_TYPE *) value;
151 GLuint i;
152 INIT_PIXEL_PTR(pixel, x, y);
153 if (mask) {
154 for (i = 0; i < count; i++) {
155 if (mask[i]) {
156 STORE_PIXEL(pixel, x + i, y, src);
157 }
158 INC_PIXEL_PTR(pixel);
159 }
160 }
161 else {
162 for (i = 0; i < count; i++) {
163 STORE_PIXEL(pixel, x + i, y, src);
164 INC_PIXEL_PTR(pixel);
165 }
166 }
167 (void) rb;
168 }
169
170
171 static void
172 NAME(put_values)( GLcontext *ctx, struct gl_renderbuffer *rb,
173 GLuint count, const GLint x[], const GLint y[],
174 const void *values, const GLubyte mask[] )
175 {
176 #ifdef SPAN_VARS
177 SPAN_VARS
178 #endif
179 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
180 GLuint i;
181 ASSERT(mask);
182 for (i = 0; i < count; i++) {
183 if (mask[i]) {
184 INIT_PIXEL_PTR(pixel, x[i], y[i]);
185 STORE_PIXEL(pixel, x[i], y[i], src[i]);
186 }
187 }
188 (void) rb;
189 }
190
191
192 static void
193 NAME(put_mono_values)( GLcontext *ctx, struct gl_renderbuffer *rb,
194 GLuint count, const GLint x[], const GLint y[],
195 const void *value, const GLubyte mask[] )
196 {
197 #ifdef SPAN_VARS
198 SPAN_VARS
199 #endif
200 const RB_TYPE *src = (const RB_TYPE *) value;
201 GLuint i;
202 ASSERT(mask);
203 for (i = 0; i < count; i++) {
204 if (mask[i]) {
205 INIT_PIXEL_PTR(pixel, x[i], y[i]);
206 STORE_PIXEL(pixel, x[i], y[i], src);
207 }
208 }
209 (void) rb;
210 }
211
212
213 #undef NAME
214 #undef RB_TYPE
215 #undef RB_COMPONENTS
216 #undef SPAN_VARS
217 #undef INIT_PIXEL_PTR
218 #undef INC_PIXEL_PTR
219 #undef STORE_PIXEL
220 #undef STORE_PIXEL_RGB
221 #undef FETCH_PIXEL