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.
39 * XXX We should replace these flags with the FRAG_BIT_ values someday...
42 #define SPAN_RGBA 0x001
43 #define SPAN_SPEC 0x002
44 #define SPAN_INDEX 0x004
47 #define SPAN_FOG 0x020
48 #define SPAN_TEXTURE 0x040
49 #define SPAN_INT_TEXTURE 0x080
50 #define SPAN_LAMBDA 0x100
51 #define SPAN_COVERAGE 0x200
52 #define SPAN_FLAT 0x400 /**< flat shading? */
54 #define SPAN_MASK 0x1000
55 #define SPAN_VARYING 0x2000
60 /* alternate arrangement for code below */
63 GLubyte sz1
[MAX_WIDTH
][4]; /* primary color */
64 GLushort sz2
[MAX_WIDTH
][4];
67 GLubyte sz1
[MAX_WIDTH
][4]; /* specular color and temp storage */
68 GLushort sz2
[MAX_WIDTH
][4];
77 * \brief Arrays of fragment values.
79 * These will either be computed from the span x/xStep values or
80 * filled in by glDraw/CopyPixels, etc.
81 * These arrays are separated out of sw_span to conserve memory.
83 typedef struct sw_span_arrays
85 /** Per-fragment attributes (indexed by FRAG_ATTRIB_* tokens) */
86 /* XXX someday look at transposing first two indexes for better memory
89 GLfloat attribs
[FRAG_ATTRIB_MAX
][MAX_WIDTH
][4];
91 /** This mask indicates which fragments are alive or culled */
92 GLubyte mask
[MAX_WIDTH
];
94 GLenum ChanType
; /**< Color channel type, GL_UNSIGNED_BYTE, GL_FLOAT */
97 GLubyte rgba
[MAX_WIDTH
][4]; /**< primary color */
98 GLubyte spec
[MAX_WIDTH
][4]; /**< specular color and temp storage */
101 GLushort rgba
[MAX_WIDTH
][4];
102 GLushort spec
[MAX_WIDTH
][4];
105 /** XXX these are temporary fields, pointing into above color arrays */
109 GLint x
[MAX_WIDTH
]; /**< fragment X coords */
110 GLint y
[MAX_WIDTH
]; /**< fragment Y coords */
111 GLuint z
[MAX_WIDTH
]; /**< fragment Z coords */
112 GLuint index
[MAX_WIDTH
]; /**< Color indexes */
113 GLfloat lambda
[MAX_TEXTURE_COORD_UNITS
][MAX_WIDTH
]; /**< Texture LOD */
114 GLfloat coverage
[MAX_WIDTH
]; /**< Fragment coverage for AA/smoothing */
119 * The SWspan structure describes the colors, Z, fogcoord, texcoords,
120 * etc for either a horizontal run or an array of independent pixels.
121 * We can either specify a base/step to indicate interpolated values, or
122 * fill in explicit arrays of values. The interpMask and arrayMask bitfields
123 * indicate which attributes are active interpolants or arrays, respectively.
125 * It would be interesting to experiment with multiprocessor rasterization
126 * with this structure. The triangle rasterizer could simply emit a
127 * stream of these structures which would be consumed by one or more
128 * span-processing threads which could run in parallel.
130 typedef struct sw_span
132 /** Coord of first fragment in horizontal span/run */
135 /** Number of fragments in the span */
138 /** This flag indicates that mask[] array is effectively filled with ones */
141 /** either GL_POLYGON, GL_LINE, GL_POLYGON, GL_BITMAP */
144 /** 0 = front-facing span, 1 = back-facing span (for two-sided stencil) */
148 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
149 * which of the attrStart/StepX/StepY variables are relevant.
151 GLbitfield interpMask
;
153 /** Fragment attribute interpolants */
154 GLfloat attrStart
[FRAG_ATTRIB_MAX
][4]; /**< initial value */
155 GLfloat attrStepX
[FRAG_ATTRIB_MAX
][4]; /**< dvalue/dx */
156 GLfloat attrStepY
[FRAG_ATTRIB_MAX
][4]; /**< dvalue/dy */
158 /* XXX the rest of these will go away eventually... */
160 /* For horizontal spans, step is the partial derivative wrt X.
161 * For lines, step is the delta from one fragment to the next.
163 #if CHAN_TYPE == GL_FLOAT
164 GLfloat red
, redStep
;
165 GLfloat green
, greenStep
;
166 GLfloat blue
, blueStep
;
167 GLfloat alpha
, alphaStep
;
168 GLfloat specRed
, specRedStep
;
169 GLfloat specGreen
, specGreenStep
;
170 GLfloat specBlue
, specBlueStep
;
171 #else /* CHAN_TYPE == GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT */
172 GLfixed red
, redStep
;
173 GLfixed green
, greenStep
;
174 GLfixed blue
, blueStep
;
175 GLfixed alpha
, alphaStep
;
176 GLfixed specRed
, specRedStep
;
177 GLfixed specGreen
, specGreenStep
;
178 GLfixed specBlue
, specBlueStep
;
180 GLfixed index
, indexStep
;
181 GLfixed z
, zStep
; /* XXX z should probably be GLuint */
182 GLfixed intTex
[2], intTexStep
[2]; /* s, t only */
185 * This bitmask (of \link SpanFlags SPAN_* flags\endlink) indicates
186 * which of the fragment arrays in the span_arrays struct are relevant.
188 GLbitfield arrayMask
;
191 * We store the arrays of fragment values in a separate struct so
192 * that we can allocate sw_span structs on the stack without using
193 * a lot of memory. The span_arrays struct is about 1.4MB while the
194 * sw_span struct is only about 512 bytes.
201 #define INIT_SPAN(S, PRIMITIVE, END, INTERP_MASK, ARRAY_MASK) \
203 (S).primitive = (PRIMITIVE); \
204 (S).interpMask = (INTERP_MASK); \
205 (S).arrayMask = (ARRAY_MASK); \
208 (S).array = SWRAST_CONTEXT(ctx)->SpanArrays; \
214 _swrast_span_default_z( GLcontext
*ctx
, SWspan
*span
);
217 _swrast_span_interpolate_z( const GLcontext
*ctx
, SWspan
*span
);
220 _swrast_span_default_fog( GLcontext
*ctx
, SWspan
*span
);
223 _swrast_span_default_color( GLcontext
*ctx
, SWspan
*span
);
226 _swrast_span_default_secondary_color(GLcontext
*ctx
, SWspan
*span
);
229 _swrast_span_default_texcoords( GLcontext
*ctx
, SWspan
*span
);
232 _swrast_compute_lambda(GLfloat dsdx
, GLfloat dsdy
, GLfloat dtdx
, GLfloat dtdy
,
233 GLfloat dqdx
, GLfloat dqdy
, GLfloat texW
, GLfloat texH
,
234 GLfloat s
, GLfloat t
, GLfloat q
, GLfloat invQ
);
237 _swrast_write_index_span( GLcontext
*ctx
, SWspan
*span
);
241 _swrast_write_rgba_span( GLcontext
*ctx
, SWspan
*span
);
245 _swrast_read_rgba_span(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
246 GLuint n
, GLint x
, GLint y
, GLenum type
, GLvoid
*rgba
);
249 _swrast_read_index_span( GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
250 GLuint n
, GLint x
, GLint y
, GLuint indx
[] );
253 _swrast_get_values(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
254 GLuint count
, const GLint x
[], const GLint y
[],
255 void *values
, GLuint valueSize
);
258 _swrast_put_row(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
259 GLuint count
, GLint x
, GLint y
,
260 const GLvoid
*values
, GLuint valueSize
);
263 _swrast_get_row(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
264 GLuint count
, GLint x
, GLint y
,
265 GLvoid
*values
, GLuint valueSize
);
269 _swrast_get_dest_rgba(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,