Merge branch 'origin' into glsl-compiler-1
[mesa.git] / src / mesa / swrast / s_span.h
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
26 #ifndef S_SPAN_H
27 #define S_SPAN_H
28
29
30 #include "mtypes.h"
31 #include "swrast.h"
32
33
34 /**
35 * \defgroup SpanFlags
36 * Bitflags used for interpMask and arrayMask fields below to indicate
37 * which interpolant values and fragment arrays are in use, respectively.
38 */
39 /*@{*/
40 #define SPAN_RGBA 0x001
41 #define SPAN_SPEC 0x002
42 #define SPAN_INDEX 0x004
43 #define SPAN_Z 0x008
44 #define SPAN_W 0x010
45 #define SPAN_FOG 0x020
46 #define SPAN_TEXTURE 0x040
47 #define SPAN_INT_TEXTURE 0x080
48 #define SPAN_LAMBDA 0x100
49 #define SPAN_COVERAGE 0x200
50 #define SPAN_FLAT 0x400 /**< flat shading? */
51 #define SPAN_XY 0x800
52 #define SPAN_MASK 0x1000
53 #define SPAN_VARYING 0x2000
54 /*@}*/
55
56
57 #if 0
58 /* alternate arrangement for code below */
59 struct arrays2 {
60 union {
61 GLubyte sz1[MAX_WIDTH][4]; /* primary color */
62 GLushort sz2[MAX_WIDTH][4];
63 } rgba;
64 union {
65 GLubyte sz1[MAX_WIDTH][4]; /* specular color and temp storage */
66 GLushort sz2[MAX_WIDTH][4];
67 } spec;
68 };
69 #endif
70
71
72
73 /**
74 * \sw_span_arrays
75 * \brief Arrays of fragment values.
76 *
77 * These will either be computed from the span x/xStep values or
78 * filled in by glDraw/CopyPixels, etc.
79 * These arrays are separated out of sw_span to conserve memory.
80 */
81 typedef struct sw_span_arrays
82 {
83 /** Per-fragment attributes (indexed by FRAG_ATTRIB_* tokens) */
84 /* XXX someday look at transposing first two indexes for better memory
85 * access pattern.
86 */
87 GLfloat attribs[FRAG_ATTRIB_MAX][MAX_WIDTH][4];
88
89 /** This mask indicates which fragments are alive or culled */
90 GLubyte mask[MAX_WIDTH];
91
92 GLenum ChanType; /**< Color channel type, GL_UNSIGNED_BYTE, GL_FLOAT */
93 union {
94 struct {
95 GLubyte rgba[MAX_WIDTH][4]; /**< primary color */
96 GLubyte spec[MAX_WIDTH][4]; /**< specular color and temp storage */
97 } sz1;
98 struct {
99 GLushort rgba[MAX_WIDTH][4];
100 GLushort spec[MAX_WIDTH][4];
101 } sz2;
102 } color;
103 /** XXX these are temporary fields, pointing into above color arrays */
104 GLchan (*rgba)[4];
105 GLchan (*spec)[4];
106
107 GLint x[MAX_WIDTH]; /**< fragment X coords */
108 GLint y[MAX_WIDTH]; /**< fragment Y coords */
109 GLuint z[MAX_WIDTH]; /**< fragment Z coords */
110 GLuint index[MAX_WIDTH]; /**< Color indexes */
111 GLfloat lambda[MAX_TEXTURE_COORD_UNITS][MAX_WIDTH]; /**< Texture LOD */
112 GLfloat coverage[MAX_WIDTH]; /**< Fragment coverage for AA/smoothing */
113 } SWspanarrays;
114
115
116 /**
117 * The SWspan structure describes the colors, Z, fogcoord, texcoords,
118 * etc for either a horizontal run or an array of independent pixels.
119 * We can either specify a base/step to indicate interpolated values, or
120 * fill in explicit arrays of values. The interpMask and arrayMask bitfields
121 * indicate which attributes are active interpolants or arrays, respectively.
122 *
123 * It would be interesting to experiment with multiprocessor rasterization
124 * with this structure. The triangle rasterizer could simply emit a
125 * stream of these structures which would be consumed by one or more
126 * span-processing threads which could run in parallel.
127 */
128 typedef struct sw_span
129 {
130 /** Coord of first fragment in horizontal span/run */
131 GLint x, y;
132
133 /** Number of fragments in the span */
134 GLuint end;
135
136 /** This flag indicates that mask[] array is effectively filled with ones */
137 GLboolean writeAll;
138
139 /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
140 GLenum primitive;
141
142 /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */
143 GLuint facing;
144
145 /**
146 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
147 * which of the attrStart/StepX/StepY variables are relevant.
148 */
149 GLbitfield interpMask;
150
151 /** Fragment attribute interpolants */
152 GLfloat attrStart[FRAG_ATTRIB_MAX][4]; /**< initial value */
153 GLfloat attrStepX[FRAG_ATTRIB_MAX][4]; /**< dvalue/dx */
154 GLfloat attrStepY[FRAG_ATTRIB_MAX][4]; /**< dvalue/dy */
155
156 /* XXX the rest of these will go away eventually... */
157
158 /* For horizontal spans, step is the partial derivative wrt X.
159 * For lines, step is the delta from one fragment to the next.
160 */
161 #if CHAN_TYPE == GL_FLOAT
162 GLfloat red, redStep;
163 GLfloat green, greenStep;
164 GLfloat blue, blueStep;
165 GLfloat alpha, alphaStep;
166 GLfloat specRed, specRedStep;
167 GLfloat specGreen, specGreenStep;
168 GLfloat specBlue, specBlueStep;
169 #else /* CHAN_TYPE == GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT */
170 GLfixed red, redStep;
171 GLfixed green, greenStep;
172 GLfixed blue, blueStep;
173 GLfixed alpha, alphaStep;
174 GLfixed specRed, specRedStep;
175 GLfixed specGreen, specGreenStep;
176 GLfixed specBlue, specBlueStep;
177 #endif
178 GLfixed index, indexStep;
179 GLfixed z, zStep; /* XXX z should probably be GLuint */
180 GLfixed intTex[2], intTexStep[2]; /* s, t only */
181
182 /**
183 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
184 * which of the fragment arrays in the span_arrays struct are relevant.
185 */
186 GLbitfield arrayMask;
187
188 /**
189 * We store the arrays of fragment values in a separate struct so
190 * that we can allocate sw_span structs on the stack without using
191 * a lot of memory. The span_arrays struct is about 1.4MB while the
192 * sw_span struct is only about 512 bytes.
193 */
194 SWspanarrays *array;
195 } SWspan;
196
197
198
199 #define INIT_SPAN(S, PRIMITIVE, END, INTERP_MASK, ARRAY_MASK) \
200 do { \
201 (S).primitive = (PRIMITIVE); \
202 (S).interpMask = (INTERP_MASK); \
203 (S).arrayMask = (ARRAY_MASK); \
204 (S).end = (END); \
205 (S).facing = 0; \
206 (S).array = SWRAST_CONTEXT(ctx)->SpanArrays; \
207 } while (0)
208
209
210
211 extern void
212 _swrast_span_default_z( GLcontext *ctx, SWspan *span );
213
214 extern void
215 _swrast_span_interpolate_z( const GLcontext *ctx, SWspan *span );
216
217 extern void
218 _swrast_span_default_fog( GLcontext *ctx, SWspan *span );
219
220 extern void
221 _swrast_span_default_color( GLcontext *ctx, SWspan *span );
222
223 extern void
224 _swrast_span_default_texcoords( GLcontext *ctx, SWspan *span );
225
226 extern GLfloat
227 _swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy,
228 GLfloat dqdx, GLfloat dqdy, GLfloat texW, GLfloat texH,
229 GLfloat s, GLfloat t, GLfloat q, GLfloat invQ);
230
231 extern void
232 _swrast_write_index_span( GLcontext *ctx, SWspan *span);
233
234
235 extern void
236 _swrast_write_rgba_span( GLcontext *ctx, SWspan *span);
237
238
239 extern void
240 _swrast_read_rgba_span(GLcontext *ctx, struct gl_renderbuffer *rb,
241 GLuint n, GLint x, GLint y, GLenum type, GLvoid *rgba);
242
243 extern void
244 _swrast_read_index_span( GLcontext *ctx, struct gl_renderbuffer *rb,
245 GLuint n, GLint x, GLint y, GLuint indx[] );
246
247 extern void
248 _swrast_get_values(GLcontext *ctx, struct gl_renderbuffer *rb,
249 GLuint count, const GLint x[], const GLint y[],
250 void *values, GLuint valueSize);
251
252 extern void
253 _swrast_put_row(GLcontext *ctx, struct gl_renderbuffer *rb,
254 GLuint count, GLint x, GLint y,
255 const GLvoid *values, GLuint valueSize);
256
257 extern void
258 _swrast_get_row(GLcontext *ctx, struct gl_renderbuffer *rb,
259 GLuint count, GLint x, GLint y,
260 GLvoid *values, GLuint valueSize);
261
262
263 extern void *
264 _swrast_get_dest_rgba(GLcontext *ctx, struct gl_renderbuffer *rb,
265 SWspan *span);
266
267 #endif