Merge branch 'crestline-qa', adding support for the 965GM chipset.
[mesa.git] / src / mesa / swrast / s_aalinetemp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
5 * Copyright (C) 1999-2007 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 * Antialiased line template.
28 */
29
30
31 /*
32 * Function to render each fragment in the AA line.
33 * \param ix - integer fragment window X coordiante
34 * \param iy - integer fragment window Y coordiante
35 */
36 static void
37 NAME(plot)(GLcontext *ctx, struct LineInfo *line, int ix, int iy)
38 {
39 const SWcontext *swrast = SWRAST_CONTEXT(ctx);
40 const GLfloat fx = (GLfloat) ix;
41 const GLfloat fy = (GLfloat) iy;
42 #ifdef DO_INDEX
43 const GLfloat coverage = compute_coveragei(line, ix, iy);
44 #else
45 const GLfloat coverage = compute_coveragef(line, ix, iy);
46 #endif
47 const GLuint i = line->span.end;
48
49 (void) swrast;
50
51 if (coverage == 0.0)
52 return;
53
54 line->span.end++;
55 line->span.array->coverage[i] = coverage;
56 line->span.array->x[i] = ix;
57 line->span.array->y[i] = iy;
58
59 /*
60 * Compute Z, color, texture coords, fog for the fragment by
61 * solving the plane equations at (ix,iy).
62 */
63 #ifdef DO_Z
64 line->span.array->z[i] = (GLuint) solve_plane(fx, fy, line->zPlane);
65 #endif
66 #ifdef DO_FOG
67 line->span.array->attribs[FRAG_ATTRIB_FOGC][i][0] = solve_plane(fx, fy, line->fPlane);
68 #endif
69 #ifdef DO_RGBA
70 line->span.array->rgba[i][RCOMP] = solve_plane_chan(fx, fy, line->rPlane);
71 line->span.array->rgba[i][GCOMP] = solve_plane_chan(fx, fy, line->gPlane);
72 line->span.array->rgba[i][BCOMP] = solve_plane_chan(fx, fy, line->bPlane);
73 line->span.array->rgba[i][ACOMP] = solve_plane_chan(fx, fy, line->aPlane);
74 #endif
75 #ifdef DO_INDEX
76 line->span.array->index[i] = (GLint) solve_plane(fx, fy, line->iPlane);
77 #endif
78 #ifdef DO_SPEC
79 line->span.array->spec[i][RCOMP] = solve_plane_chan(fx, fy, line->srPlane);
80 line->span.array->spec[i][GCOMP] = solve_plane_chan(fx, fy, line->sgPlane);
81 line->span.array->spec[i][BCOMP] = solve_plane_chan(fx, fy, line->sbPlane);
82 #endif
83 #if defined(DO_TEXVAR)
84 {
85 GLuint attr;
86 for (attr = swrast->_MinFragmentAttrib; attr < swrast->_MaxFragmentAttrib; attr++) {
87 if (swrast->_FragmentAttribs & (1 << attr)) {
88 GLfloat (*attribArray)[4] = line->span.array->attribs[attr];
89 GLfloat invQ;
90 if (ctx->FragmentProgram._Active) {
91 invQ = 1.0F;
92 }
93 else {
94 invQ = solve_plane_recip(fx, fy, line->vPlane[attr]);
95 }
96 attribArray[i][0] = solve_plane(fx, fy, line->sPlane[attr]) * invQ;
97 attribArray[i][1] = solve_plane(fx, fy, line->tPlane[attr]) * invQ;
98 attribArray[i][2] = solve_plane(fx, fy, line->uPlane[attr]) * invQ;
99 if (attr < FRAG_ATTRIB_VAR0) {
100 const GLuint unit = attr - FRAG_ATTRIB_TEX0;
101 line->span.array->lambda[unit][i]
102 = compute_lambda(line->sPlane[attr],
103 line->tPlane[attr], invQ,
104 line->texWidth[attr], line->texHeight[attr]);
105 }
106 }
107 }
108 }
109 #endif
110
111 if (line->span.end == MAX_WIDTH) {
112 #if defined(DO_RGBA)
113 _swrast_write_rgba_span(ctx, &(line->span));
114 #else
115 _swrast_write_index_span(ctx, &(line->span));
116 #endif
117 line->span.end = 0; /* reset counter */
118 }
119 }
120
121
122
123 /*
124 * Line setup
125 */
126 static void
127 NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1)
128 {
129 SWcontext *swrast = SWRAST_CONTEXT(ctx);
130 GLfloat tStart, tEnd; /* segment start, end along line length */
131 GLboolean inSegment;
132 GLint iLen, i;
133
134 /* Init the LineInfo struct */
135 struct LineInfo line;
136 line.x0 = v0->win[0];
137 line.y0 = v0->win[1];
138 line.x1 = v1->win[0];
139 line.y1 = v1->win[1];
140 line.dx = line.x1 - line.x0;
141 line.dy = line.y1 - line.y0;
142 line.len = SQRTF(line.dx * line.dx + line.dy * line.dy);
143 line.halfWidth = 0.5F * ctx->Line._Width;
144
145 if (line.len == 0.0 || IS_INF_OR_NAN(line.len))
146 return;
147
148 INIT_SPAN(line.span, GL_LINE, 0, 0, SPAN_XY | SPAN_COVERAGE);
149
150 line.xAdj = line.dx / line.len * line.halfWidth;
151 line.yAdj = line.dy / line.len * line.halfWidth;
152
153 #ifdef DO_Z
154 line.span.arrayMask |= SPAN_Z;
155 compute_plane(line.x0, line.y0, line.x1, line.y1,
156 v0->win[2], v1->win[2], line.zPlane);
157 #endif
158 #ifdef DO_FOG
159 line.span.arrayMask |= SPAN_FOG;
160 compute_plane(line.x0, line.y0, line.x1, line.y1,
161 v0->fog, v1->fog, line.fPlane);
162 #endif
163 #ifdef DO_RGBA
164 line.span.arrayMask |= SPAN_RGBA;
165 if (ctx->Light.ShadeModel == GL_SMOOTH) {
166 compute_plane(line.x0, line.y0, line.x1, line.y1,
167 v0->color[RCOMP], v1->color[RCOMP], line.rPlane);
168 compute_plane(line.x0, line.y0, line.x1, line.y1,
169 v0->color[GCOMP], v1->color[GCOMP], line.gPlane);
170 compute_plane(line.x0, line.y0, line.x1, line.y1,
171 v0->color[BCOMP], v1->color[BCOMP], line.bPlane);
172 compute_plane(line.x0, line.y0, line.x1, line.y1,
173 v0->color[ACOMP], v1->color[ACOMP], line.aPlane);
174 }
175 else {
176 constant_plane(v1->color[RCOMP], line.rPlane);
177 constant_plane(v1->color[GCOMP], line.gPlane);
178 constant_plane(v1->color[BCOMP], line.bPlane);
179 constant_plane(v1->color[ACOMP], line.aPlane);
180 }
181 #endif
182 #ifdef DO_SPEC
183 line.span.arrayMask |= SPAN_SPEC;
184 if (ctx->Light.ShadeModel == GL_SMOOTH) {
185 compute_plane(line.x0, line.y0, line.x1, line.y1,
186 v0->specular[RCOMP], v1->specular[RCOMP], line.srPlane);
187 compute_plane(line.x0, line.y0, line.x1, line.y1,
188 v0->specular[GCOMP], v1->specular[GCOMP], line.sgPlane);
189 compute_plane(line.x0, line.y0, line.x1, line.y1,
190 v0->specular[BCOMP], v1->specular[BCOMP], line.sbPlane);
191 }
192 else {
193 constant_plane(v1->specular[RCOMP], line.srPlane);
194 constant_plane(v1->specular[GCOMP], line.sgPlane);
195 constant_plane(v1->specular[BCOMP], line.sbPlane);
196 }
197 #endif
198 #ifdef DO_INDEX
199 line.span.arrayMask |= SPAN_INDEX;
200 if (ctx->Light.ShadeModel == GL_SMOOTH) {
201 compute_plane(line.x0, line.y0, line.x1, line.y1,
202 v0->index, v1->index, line.iPlane);
203 }
204 else {
205 constant_plane(v1->index, line.iPlane);
206 }
207 #endif
208 #if defined(DO_TEXVAR)
209 {
210 GLuint attr;
211 const GLfloat invW0 = v0->win[3];
212 const GLfloat invW1 = v1->win[3];
213 line.span.arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA | SPAN_VARYING);
214 for (attr = swrast->_MinFragmentAttrib; attr < swrast->_MaxFragmentAttrib; attr++) {
215 if (swrast->_FragmentAttribs & (1 << attr)) {
216 const GLfloat s0 = v0->attrib[attr][0] * invW0;
217 const GLfloat s1 = v1->attrib[attr][0] * invW1;
218 const GLfloat t0 = v0->attrib[attr][1] * invW0;
219 const GLfloat t1 = v1->attrib[attr][1] * invW1;
220 const GLfloat r0 = v0->attrib[attr][2] * invW0;
221 const GLfloat r1 = v1->attrib[attr][2] * invW1;
222 const GLfloat q0 = v0->attrib[attr][3] * invW0;
223 const GLfloat q1 = v1->attrib[attr][3] * invW1;
224 compute_plane(line.x0, line.y0, line.x1, line.y1, s0, s1, line.sPlane[attr]);
225 compute_plane(line.x0, line.y0, line.x1, line.y1, t0, t1, line.tPlane[attr]);
226 compute_plane(line.x0, line.y0, line.x1, line.y1, r0, r1, line.uPlane[attr]);
227 compute_plane(line.x0, line.y0, line.x1, line.y1, q0, q1, line.vPlane[attr]);
228 if (attr < FRAG_ATTRIB_VAR0) {
229 const GLuint u = attr - FRAG_ATTRIB_TEX0;
230 const struct gl_texture_object *obj = ctx->Texture.Unit[u]._Current;
231 const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel];
232 line.texWidth[attr] = (GLfloat) texImage->Width;
233 line.texHeight[attr] = (GLfloat) texImage->Height;
234 }
235 }
236 }
237 }
238 #endif
239
240 tStart = tEnd = 0.0;
241 inSegment = GL_FALSE;
242 iLen = (GLint) line.len;
243
244 if (ctx->Line.StippleFlag) {
245 for (i = 0; i < iLen; i++) {
246 const GLuint bit = (swrast->StippleCounter / ctx->Line.StippleFactor) & 0xf;
247 if ((1 << bit) & ctx->Line.StipplePattern) {
248 /* stipple bit is on */
249 const GLfloat t = (GLfloat) i / (GLfloat) line.len;
250 if (!inSegment) {
251 /* start new segment */
252 inSegment = GL_TRUE;
253 tStart = t;
254 }
255 else {
256 /* still in the segment, extend it */
257 tEnd = t;
258 }
259 }
260 else {
261 /* stipple bit is off */
262 if (inSegment && (tEnd > tStart)) {
263 /* draw the segment */
264 segment(ctx, &line, NAME(plot), tStart, tEnd);
265 inSegment = GL_FALSE;
266 }
267 else {
268 /* still between segments, do nothing */
269 }
270 }
271 swrast->StippleCounter++;
272 }
273
274 if (inSegment) {
275 /* draw the final segment of the line */
276 segment(ctx, &line, NAME(plot), tStart, 1.0F);
277 }
278 }
279 else {
280 /* non-stippled */
281 segment(ctx, &line, NAME(plot), 0.0, 1.0);
282 }
283
284 #if defined(DO_RGBA)
285 _swrast_write_rgba_span(ctx, &(line.span));
286 #else
287 _swrast_write_index_span(ctx, &(line.span));
288 #endif
289 }
290
291
292
293
294 #undef DO_Z
295 #undef DO_FOG
296 #undef DO_RGBA
297 #undef DO_INDEX
298 #undef DO_SPEC
299 #undef DO_TEXVAR
300 #undef NAME