2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
36 * Bitflags used for interpMask and arrayMask fields below to indicate
37 * which interpolant values and fragment arrays are in use, respectively.
40 #define SPAN_RGBA 0x001
41 #define SPAN_SPEC 0x002
42 #define SPAN_INDEX 0x004
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? */
52 #define SPAN_MASK 0x1000
53 #define SPAN_VARYING 0x2000
58 /* alternate arrangement for code below */
61 GLubyte sz1
[MAX_WIDTH
][4]; /* primary color */
62 GLushort sz2
[MAX_WIDTH
][4];
65 GLubyte sz1
[MAX_WIDTH
][4]; /* specular color and temp storage */
66 GLushort sz2
[MAX_WIDTH
][4];
75 * \brief Arrays of fragment values.
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.
81 typedef struct sw_span_arrays
83 /** Per-fragment attributes (indexed by FRAG_ATTRIB_* tokens) */
84 /* XXX someday look at transposing first two indexes for better memory
87 GLfloat attribs
[FRAG_ATTRIB_MAX
][MAX_WIDTH
][4];
89 /** This mask indicates which fragments are alive or culled */
90 GLubyte mask
[MAX_WIDTH
];
92 GLenum ChanType
; /**< Color channel type, GL_UNSIGNED_BYTE, GL_FLOAT */
95 GLubyte rgba
[MAX_WIDTH
][4]; /**< primary color */
96 GLubyte spec
[MAX_WIDTH
][4]; /**< specular color and temp storage */
99 GLushort rgba
[MAX_WIDTH
][4];
100 GLushort spec
[MAX_WIDTH
][4];
103 /** XXX these are temporary fields, pointing into above color arrays */
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 */
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.
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.
128 typedef struct sw_span
130 /** Coord of first fragment in horizontal span/run */
133 /** Number of fragments in the span */
136 /** This flag indicates that mask[] array is effectively filled with ones */
139 /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
142 /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */
146 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
147 * which of the attrStart/StepX/StepY variables are relevant.
149 GLbitfield interpMask
;
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 */
156 /* XXX the rest of these will go away eventually... */
158 /* For horizontal spans, step is the partial derivative wrt X.
159 * For lines, step is the delta from one fragment to the next.
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
;
178 GLfixed index
, indexStep
;
179 GLfixed z
, zStep
; /* XXX z should probably be GLuint */
180 GLfixed intTex
[2], intTexStep
[2]; /* s, t only */
183 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
184 * which of the fragment arrays in the span_arrays struct are relevant.
186 GLbitfield arrayMask
;
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.
199 #define INIT_SPAN(S, PRIMITIVE, END, INTERP_MASK, ARRAY_MASK) \
201 (S).primitive = (PRIMITIVE); \
202 (S).interpMask = (INTERP_MASK); \
203 (S).arrayMask = (ARRAY_MASK); \
206 (S).array = SWRAST_CONTEXT(ctx)->SpanArrays; \
212 _swrast_span_default_z( GLcontext
*ctx
, SWspan
*span
);
215 _swrast_span_interpolate_z( const GLcontext
*ctx
, SWspan
*span
);
218 _swrast_span_default_fog( GLcontext
*ctx
, SWspan
*span
);
221 _swrast_span_default_color( GLcontext
*ctx
, SWspan
*span
);
224 _swrast_span_default_texcoords( GLcontext
*ctx
, SWspan
*span
);
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
);
232 _swrast_write_index_span( GLcontext
*ctx
, SWspan
*span
);
236 _swrast_write_rgba_span( GLcontext
*ctx
, SWspan
*span
);
240 _swrast_read_rgba_span(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
241 GLuint n
, GLint x
, GLint y
, GLenum type
, GLvoid
*rgba
);
244 _swrast_read_index_span( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
245 GLuint n
, GLint x
, GLint y
, GLuint indx
[] );
248 _swrast_get_values(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
249 GLuint count
, const GLint x
[], const GLint y
[],
250 void *values
, GLuint valueSize
);
253 _swrast_put_row(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
254 GLuint count
, GLint x
, GLint y
,
255 const GLvoid
*values
, GLuint valueSize
);
258 _swrast_get_row(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
259 GLuint count
, GLint x
, GLint y
,
260 GLvoid
*values
, GLuint valueSize
);
264 _swrast_get_dest_rgba(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,