silence compiler warnings (last batch for src)
[mesa.git] / src / mesa / swrast / s_aalinetemp.h
1 /* $Id: s_aalinetemp.h,v 1.14 2001/09/19 20:30:44 kschultz Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 /*
29 * Antialiased line template.
30 */
31
32
33 /*
34 * Function to render each fragment in the AA line.
35 */
36 static void
37 NAME(plot)(GLcontext *ctx, const struct LineInfo *line,
38 struct pixel_buffer *pb, int ix, int iy)
39 {
40 const GLfloat fx = (GLfloat) ix;
41 const GLfloat fy = (GLfloat) iy;
42 const GLfloat coverage = compute_coveragef(line, ix, iy);
43 GLdepth z;
44 GLfloat fog;
45 #ifdef DO_RGBA
46 GLchan red, green, blue, alpha;
47 #else
48 GLint index;
49 #endif
50 GLchan specRed, specGreen, specBlue;
51 GLfloat tex[MAX_TEXTURE_UNITS][4], lambda[MAX_TEXTURE_UNITS];
52
53 if (coverage == 0.0)
54 return;
55
56 /*
57 * Compute Z, color, texture coords, fog for the fragment by
58 * solving the plane equations at (ix,iy).
59 */
60 #ifdef DO_Z
61 z = (GLdepth) solve_plane(fx, fy, line->zPlane);
62 #else
63 z = 0.0;
64 #endif
65 #ifdef DO_FOG
66 fog = solve_plane(fx, fy, line->fPlane);
67 #else
68 fog = 0.0;
69 #endif
70 #ifdef DO_RGBA
71 red = solve_plane_chan(fx, fy, line->rPlane);
72 green = solve_plane_chan(fx, fy, line->gPlane);
73 blue = solve_plane_chan(fx, fy, line->bPlane);
74 alpha = solve_plane_chan(fx, fy, line->aPlane);
75 #endif
76 #ifdef DO_INDEX
77 index = (GLint) solve_plane(fx, fy, line->iPlane);
78 #endif
79 #ifdef DO_SPEC
80 specRed = solve_plane_chan(fx, fy, line->srPlane);
81 specGreen = solve_plane_chan(fx, fy, line->sgPlane);
82 specBlue = solve_plane_chan(fx, fy, line->sbPlane);
83 #else
84 (void) specRed;
85 (void) specGreen;
86 (void) specBlue;
87 #endif
88 #ifdef DO_TEX
89 {
90 GLfloat invQ = solve_plane_recip(fx, fy, line->vPlane[0]);
91 tex[0][0] = solve_plane(fx, fy, line->sPlane[0]) * invQ;
92 tex[0][1] = solve_plane(fx, fy, line->tPlane[0]) * invQ;
93 tex[0][2] = solve_plane(fx, fy, line->uPlane[0]) * invQ;
94 lambda[0] = compute_lambda(line->sPlane[0], line->tPlane[0], invQ,
95 line->texWidth[0], line->texHeight[0]);
96 }
97 #elif defined(DO_MULTITEX)
98 {
99 GLuint unit;
100 for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
101 if (ctx->Texture.Unit[unit]._ReallyEnabled) {
102 GLfloat invQ = solve_plane_recip(fx, fy, line->vPlane[unit]);
103 tex[unit][0] = solve_plane(fx, fy, line->sPlane[unit]) * invQ;
104 tex[unit][1] = solve_plane(fx, fy, line->tPlane[unit]) * invQ;
105 tex[unit][2] = solve_plane(fx, fy, line->uPlane[unit]) * invQ;
106 lambda[unit] = compute_lambda(line->sPlane[unit],
107 line->tPlane[unit], invQ,
108 line->texWidth[unit], line->texHeight[unit]);
109 }
110 }
111 }
112 #else
113 (void) tex[0][0];
114 (void) lambda[0];
115 #endif
116
117
118 PB_COVERAGE(pb, coverage);
119
120 #if defined(DO_MULTITEX)
121 #if defined(DO_SPEC)
122 PB_WRITE_MULTITEX_SPEC_PIXEL(pb, ix, iy, z, fog, red, green, blue, alpha,
123 specRed, specGreen, specBlue, tex);
124 #else
125 PB_WRITE_MULTITEX_PIXEL(pb, ix, iy, z, fog, red, green, blue, alpha, tex);
126 #endif
127 #elif defined(DO_TEX)
128 PB_WRITE_TEX_PIXEL(pb, ix, iy, z, fog, red, green, blue, alpha,
129 tex[0][0], tex[0][1], tex[0][2]);
130 #elif defined(DO_RGBA)
131 PB_WRITE_RGBA_PIXEL(pb, ix, iy, z, fog, red, green, blue, alpha);
132 #elif defined(DO_INDEX)
133 PB_WRITE_CI_PIXEL(pb, ix, iy, z, fog, index);
134 #endif
135
136 pb->haveCoverage = GL_TRUE;
137 PB_CHECK_FLUSH(ctx, pb);
138 }
139
140
141
142 /*
143 * Line setup
144 */
145 static void
146 NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1)
147 {
148 SWcontext *swrast = SWRAST_CONTEXT(ctx);
149 struct pixel_buffer *pb = SWRAST_CONTEXT(ctx)->PB;
150 GLfloat tStart, tEnd; /* segment start, end along line length */
151 GLboolean inSegment;
152 GLint iLen, i;
153
154 /* Init the LineInfo struct */
155 struct LineInfo line;
156 line.x0 = v0->win[0];
157 line.y0 = v0->win[1];
158 line.x1 = v1->win[0];
159 line.y1 = v1->win[1];
160 line.dx = line.x1 - line.x0;
161 line.dy = line.y1 - line.y0;
162 line.len = (GLfloat) sqrt(line.dx * line.dx + line.dy * line.dy);
163 line.halfWidth = 0.5F * ctx->Line.Width;
164
165 if (line.len == 0.0)
166 return;
167
168 line.xAdj = line.dx / line.len * line.halfWidth;
169 line.yAdj = line.dy / line.len * line.halfWidth;
170
171 #ifdef DO_Z
172 compute_plane(line.x0, line.y0, line.x1, line.y1,
173 v0->win[2], v1->win[2], line.zPlane);
174 #endif
175 #ifdef DO_FOG
176 compute_plane(line.x0, line.y0, line.x1, line.y1,
177 v0->fog, v1->fog, line.fPlane);
178 #endif
179 #ifdef DO_RGBA
180 if (ctx->Light.ShadeModel == GL_SMOOTH) {
181 compute_plane(line.x0, line.y0, line.x1, line.y1,
182 v0->color[RCOMP], v1->color[RCOMP], line.rPlane);
183 compute_plane(line.x0, line.y0, line.x1, line.y1,
184 v0->color[GCOMP], v1->color[GCOMP], line.gPlane);
185 compute_plane(line.x0, line.y0, line.x1, line.y1,
186 v0->color[BCOMP], v1->color[BCOMP], line.bPlane);
187 compute_plane(line.x0, line.y0, line.x1, line.y1,
188 v0->color[ACOMP], v1->color[ACOMP], line.aPlane);
189 }
190 else {
191 constant_plane(v1->color[RCOMP], line.rPlane);
192 constant_plane(v1->color[GCOMP], line.gPlane);
193 constant_plane(v1->color[BCOMP], line.bPlane);
194 constant_plane(v1->color[ACOMP], line.aPlane);
195 }
196 #endif
197 #ifdef DO_SPEC
198 if (ctx->Light.ShadeModel == GL_SMOOTH) {
199 compute_plane(line.x0, line.y0, line.x1, line.y1,
200 v0->specular[RCOMP], v1->specular[RCOMP], line.srPlane);
201 compute_plane(line.x0, line.y0, line.x1, line.y1,
202 v0->specular[GCOMP], v1->specular[GCOMP], line.sgPlane);
203 compute_plane(line.x0, line.y0, line.x1, line.y1,
204 v0->specular[BCOMP], v1->specular[BCOMP], line.sbPlane);
205 }
206 else {
207 constant_plane(v1->specular[RCOMP], line.srPlane);
208 constant_plane(v1->specular[GCOMP], line.sgPlane);
209 constant_plane(v1->specular[BCOMP], line.sbPlane);
210 }
211 #endif
212 #ifdef DO_INDEX
213 if (ctx->Light.ShadeModel == GL_SMOOTH) {
214 compute_plane(line.x0, line.y0, line.x1, line.y1,
215 (GLfloat) v0->index, (GLfloat) v1->index, line.iPlane);
216 }
217 else {
218 constant_plane((GLfloat) v1->index, line.iPlane);
219 }
220 #endif
221 #ifdef DO_TEX
222 {
223 const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current;
224 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];
225 const GLfloat invW0 = v0->win[3];
226 const GLfloat invW1 = v1->win[3];
227 const GLfloat s0 = v0->texcoord[0][0] * invW0;
228 const GLfloat s1 = v1->texcoord[0][0] * invW1;
229 const GLfloat t0 = v0->texcoord[0][1] * invW0;
230 const GLfloat t1 = v1->texcoord[0][1] * invW0;
231 const GLfloat r0 = v0->texcoord[0][2] * invW0;
232 const GLfloat r1 = v1->texcoord[0][2] * invW0;
233 const GLfloat q0 = v0->texcoord[0][3] * invW0;
234 const GLfloat q1 = v1->texcoord[0][3] * invW0;
235 compute_plane(line.x0, line.y0, line.x1, line.y1, s0, s1, line.sPlane[0]);
236 compute_plane(line.x0, line.y0, line.x1, line.y1, t0, t1, line.tPlane[0]);
237 compute_plane(line.x0, line.y0, line.x1, line.y1, r0, r1, line.uPlane[0]);
238 compute_plane(line.x0, line.y0, line.x1, line.y1, q0, q1, line.vPlane[0]);
239 line.texWidth[0] = (GLfloat) texImage->Width;
240 line.texHeight[0] = (GLfloat) texImage->Height;
241 }
242 #elif defined(DO_MULTITEX)
243 {
244 GLuint u;
245 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
246 if (ctx->Texture.Unit[u]._ReallyEnabled) {
247 const struct gl_texture_object *obj = ctx->Texture.Unit[u]._Current;
248 const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];
249 const GLfloat invW0 = v0->win[3];
250 const GLfloat invW1 = v1->win[3];
251 const GLfloat s0 = v0->texcoord[u][0] * invW0;
252 const GLfloat s1 = v1->texcoord[u][0] * invW1;
253 const GLfloat t0 = v0->texcoord[u][1] * invW0;
254 const GLfloat t1 = v1->texcoord[u][1] * invW0;
255 const GLfloat r0 = v0->texcoord[u][2] * invW0;
256 const GLfloat r1 = v1->texcoord[u][2] * invW0;
257 const GLfloat q0 = v0->texcoord[u][3] * invW0;
258 const GLfloat q1 = v1->texcoord[u][3] * invW0;
259 compute_plane(line.x0, line.y0, line.x1, line.y1, s0, s1, line.sPlane[u]);
260 compute_plane(line.x0, line.y0, line.x1, line.y1, t0, t1, line.tPlane[u]);
261 compute_plane(line.x0, line.y0, line.x1, line.y1, r0, r1, line.uPlane[u]);
262 compute_plane(line.x0, line.y0, line.x1, line.y1, q0, q1, line.vPlane[u]);
263 line.texWidth[u] = (GLfloat) texImage->Width;
264 line.texHeight[u] = (GLfloat) texImage->Height;
265 }
266 }
267 }
268 #endif
269
270 tStart = tEnd = 0.0;
271 inSegment = GL_FALSE;
272 iLen = (GLint) line.len;
273
274 if (ctx->Line.StippleFlag) {
275 for (i = 0; i < iLen; i++) {
276 const GLuint bit = (swrast->StippleCounter / ctx->Line.StippleFactor) & 0xf;
277 if ((1 << bit) & ctx->Line.StipplePattern) {
278 /* stipple bit is on */
279 const GLfloat t = (GLfloat) i / (GLfloat) line.len;
280 if (!inSegment) {
281 /* start new segment */
282 inSegment = GL_TRUE;
283 tStart = t;
284 }
285 else {
286 /* still in the segment, extend it */
287 tEnd = t;
288 }
289 }
290 else {
291 /* stipple bit is off */
292 if (inSegment && (tEnd > tStart)) {
293 /* draw the segment */
294 segment(ctx, &line, NAME(plot), pb, tStart, tEnd);
295 inSegment = GL_FALSE;
296 }
297 else {
298 /* still between segments, do nothing */
299 }
300 }
301 swrast->StippleCounter++;
302 }
303
304 if (inSegment) {
305 /* draw the final segment of the line */
306 segment(ctx, &line, NAME(plot), pb, tStart, 1.0F);
307 }
308 }
309 else {
310 /* non-stippled */
311 segment(ctx, &line, NAME(plot), pb, 0.0, 1.0);
312 }
313 }
314
315
316
317
318 #undef DO_Z
319 #undef DO_FOG
320 #undef DO_RGBA
321 #undef DO_INDEX
322 #undef DO_SPEC
323 #undef DO_TEX
324 #undef DO_MULTITEX
325 #undef NAME