source: trunk/src/opengl/mesa/lnaatemp.h@ 3100

Last change on this file since 3100 was 2938, checked in by sandervl, 25 years ago

created

File size: 14.3 KB
Line 
1/* $Id: lnaatemp.h,v 1.1 2000-02-29 00:48:32 sandervl Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.1
6 *
7 * Copyright (C) 1999 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 Rasterizer Template
30 *
31 * This file is #include'd to generate custom line rasterizers.
32 *
33 * The following macros may be defined to indicate what auxillary information
34 * must be interplated along the line:
35 * INTERP_RGBA - if defined, interpolate RGBA values
36 * INTERP_SPEC - if defined, interpolate specular RGB values
37 * INTERP_INDEX - if defined, interpolate color index values
38 * INTERP_STUV0 - if defined, interpolate unit 0 STU texcoords with
39 * perspective correction
40 * NOTE: OpenGL STRQ = Mesa STUV (R was taken for red)
41 * INTERP_STUV1 - if defined, interpolate unit 1 STU texcoords
42 *
43 * Optionally, one may provide one-time setup code
44 * SETUP_CODE - code which is to be executed once per line
45 *
46 * To actually "plot" each pixel the PLOT macro must be defined.
47 *
48 * This code was designed for the origin to be in the lower-left corner.
49 */
50
51/* void aa_line( GLcontext *ctx, GLuint vert0, GLuint vert1, GLuint pvert ) */
52{
53 const struct vertex_buffer *VB = ctx->VB;
54 struct pixel_buffer *pb = ctx->PB;
55 GLfloat halfWidth = 0.5F * ctx->Line.Width; /* 0.5 is a bit of a hack */
56 GLboolean solid = !ctx->Line.StippleFlag;
57 GLint x0 = (GLint) VB->Win.data[vert0][0];
58 GLint x1 = (GLint) VB->Win.data[vert1][0];
59 GLint y0 = (GLint) VB->Win.data[vert0][1];
60 GLint y1 = (GLint) VB->Win.data[vert1][1];
61 GLint dx = x1 - x0;
62 GLint dy = y1 - y0;
63 GLint xStep, yStep;
64 GLint z0, z1;
65#if INTERP_RGBA
66 GLfixed fr, fg, fb, fa; /* fixed-pt RGBA */
67 GLfixed dfr, dfg, dfb, dfa; /* fixed-pt RGBA deltas */
68#endif
69#if INTERP_SPEC
70 GLfixed fsr, fsg, fsb; /* fixed-pt specular RGBA */
71 GLfixed dfsr, dfsg, dfsb; /* fixed-pt specular RGBA deltas */
72#endif
73#if INTERP_INDEX
74 GLfixed fi, dfi;
75#endif
76#if INTERP_STUV0 || INTERP_STUV1
77 GLfloat invw0 = VB->Win.data[vert0][3];
78 GLfloat invw1 = VB->Win.data[vert1][3];
79#endif
80#if INTERP_STUV0
81 /* h denotes hyperbolic */
82 GLfloat hs0 = invw0 * VB->TexCoordPtr[0]->data[vert0][0];
83 GLfloat dhs = invw1 * VB->TexCoordPtr[0]->data[vert1][0] - hs0;
84 GLfloat ht0 = invw0 * VB->TexCoordPtr[0]->data[vert0][1];
85 GLfloat dht = invw1 * VB->TexCoordPtr[0]->data[vert1][1] - ht0;
86 GLfloat hu0 = 0, dhu = 0;
87 GLfloat hv0 = invw0, dhv = invw1 - invw0;
88#endif
89#if INTERP_STUV1
90 GLfloat hs01 = invw0 * VB->TexCoordPtr[1]->data[vert0][0];
91 GLfloat dhs1 = invw1 * VB->TexCoordPtr[1]->data[vert1][0] - hs01;
92 GLfloat ht01 = invw0 * VB->TexCoordPtr[1]->data[vert0][1];
93 GLfloat dht1 = invw1 * VB->TexCoordPtr[1]->data[vert1][1] - ht01;
94 GLfloat hu01 = 0, dhu1 = 0;
95 GLfloat hv01 = invw0, dhv1 = invw1 - invw0;
96#endif
97
98 if (dx == 0 && dy == 0)
99 return;
100
101#if DEPTH_BITS==16
102 z0 = FloatToFixed(VB->Win.data[vert0][2]);
103 z1 = FloatToFixed(VB->Win.data[vert1][2]);
104#else
105 z0 = (int) VB->Win.data[vert0][2];
106 z1 = (int) VB->Win.data[vert1][2];
107#endif
108
109#if INTERP_STUV0
110 if (VB->TexCoordPtr[0]->size > 2) {
111 hu0 = invw0 * VB->TexCoordPtr[0]->data[vert0][2];
112 dhu = invw1 * VB->TexCoordPtr[0]->data[vert1][2] - hu0;
113 if (VB->TexCoordPtr[0]->size > 3) {
114 hv0 = invw0 * VB->TexCoordPtr[0]->data[vert0][3];
115 dhv = invw1 * VB->TexCoordPtr[0]->data[vert1][3] - hv0;
116 }
117 }
118#endif
119
120#if INTERP_STUV1
121 if (VB->TexCoordPtr[1]->size > 2) {
122 hu01 = invw0 * VB->TexCoordPtr[1]->data[vert0][2];
123 dhu1 = invw1 * VB->TexCoordPtr[1]->data[vert1][2] - hu01;
124 if (VB->TexCoordPtr[1]->size > 3) {
125 hv01 = invw0 * VB->TexCoordPtr[1]->data[vert0][3];
126 dhv1 = invw1 * VB->TexCoordPtr[1]->data[vert1][3] - hv01;
127 }
128 }
129#endif
130
131#if INTERP_RGBA
132 if (ctx->Light.ShadeModel == GL_SMOOTH) {
133 fr = IntToFixed(VB->ColorPtr->data[vert0][0]);
134 fg = IntToFixed(VB->ColorPtr->data[vert0][1]);
135 fb = IntToFixed(VB->ColorPtr->data[vert0][2]);
136 fa = IntToFixed(VB->ColorPtr->data[vert0][3]);
137 }
138 else {
139 fr = IntToFixed(VB->ColorPtr->data[pvert][0]);
140 fg = IntToFixed(VB->ColorPtr->data[pvert][1]);
141 fb = IntToFixed(VB->ColorPtr->data[pvert][2]);
142 fa = IntToFixed(VB->ColorPtr->data[pvert][3]);
143 dfr = dfg = dfb = dfa = 0;
144 }
145#endif
146#if INTERP_SPEC
147 if (ctx->Light.ShadeModel == GL_SMOOTH) {
148 fsr = IntToFixed(VB->Specular[vert0][0]);
149 fsg = IntToFixed(VB->Specular[vert0][1]);
150 fsb = IntToFixed(VB->Specular[vert0][2]);
151 }
152 else {
153 fsr = IntToFixed(VB->Specular[pvert][0]);
154 fsg = IntToFixed(VB->Specular[pvert][1]);
155 fsb = IntToFixed(VB->Specular[pvert][2]);
156 dfsr = dfsg = dfsb = 0;
157 }
158#endif
159#if INTERP_INDEX
160 if (ctx->Light.ShadeModel == GL_SMOOTH) {
161 fi = IntToFixed(VB->IndexPtr->data[vert0]);
162 }
163 else {
164 fi = IntToFixed(VB->IndexPtr->data[pvert]);
165 dfi = 0;
166 }
167#endif
168
169 /*
170 * Setup
171 */
172#ifdef SETUP_CODE
173 SETUP_CODE
174#endif
175
176 if (dx < 0) {
177 xStep = -1;
178 dx = -dx;
179 }
180 else {
181 xStep = 1;
182 }
183
184 if (dy < 0) {
185 yStep = -1;
186 dy = -dy;
187 }
188 else {
189 yStep = 1;
190 }
191
192 if (dx > dy) {
193 /*** X-major line ***/
194 GLint i;
195 GLint x = x0;
196 GLfloat y = VB->Win.data[vert0][1];
197 GLfloat yStep = (VB->Win.data[vert1][1] - y) / (GLfloat) dx;
198 GLint dz = (z1 - z0) / dx;
199 GLfloat invDx = 1.0F / dx;
200 (void) invDx;
201#if INTERP_RGBA
202 if (ctx->Light.ShadeModel == GL_SMOOTH) {
203 dfr = (IntToFixed(VB->ColorPtr->data[vert1][0]) - fr) * invDx;
204 dfg = (IntToFixed(VB->ColorPtr->data[vert1][1]) - fg) * invDx;
205 dfb = (IntToFixed(VB->ColorPtr->data[vert1][2]) - fb) * invDx;
206 dfa = (IntToFixed(VB->ColorPtr->data[vert1][3]) - fa) * invDx;
207 }
208#endif
209#if INTERP_SPEC
210 if (ctx->Light.ShadeModel == GL_SMOOTH) {
211 dfsr = (IntToFixed(VB->Specular[vert1][0]) - fsr) * invDx;
212 dfsg = (IntToFixed(VB->Specular[vert1][1]) - fsg) * invDx;
213 dfsb = (IntToFixed(VB->Specular[vert1][2]) - fsb) * invDx;
214 }
215#endif
216#if INTERP_STUV0
217 dhs *= invDx;
218 dht *= invDx;
219 dhu *= invDx;
220 dhv *= invDx;
221#endif
222#if INTERP_STUV1
223 dhs1 *= invDx;
224 dht1 *= invDx;
225 dhu1 *= invDx;
226 dhv1 *= invDx;
227#endif
228 for (i = 0; i < dx; i++) {
229 if (solid || (ctx->Line.StipplePattern & (1 << ((ctx->StippleCounter/ctx->Line.StippleFactor) & 0xf)))) {
230
231 GLfloat yTop = y + halfWidth;
232 GLfloat yBot = y - halfWidth;
233 GLint yTopi = (GLint) yTop;
234 GLint yBoti = (GLint) yBot;
235 GLint iy;
236#if INTERP_RGBA
237 GLubyte red = FixedToInt(fr);
238 GLubyte green = FixedToInt(fg);
239 GLubyte blue = FixedToInt(fb);
240 GLubyte alpha = FixedToInt(fa);
241 GLint coverage;
242#endif
243#if INTERP_SPEC
244 GLubyte specRed = FixedToInt(fsr);
245 GLubyte specGreen = FixedToInt(fsg);
246 GLubyte specBlue = FixedToInt(fsb);
247#endif
248#if INTERP_INDEX
249 GLuint index = FixedToInt(fi) & 0xfffffff0;
250 GLuint coverage;
251#endif
252#if DEPTH_BITS==16
253 GLdepth z = FixedToInt(z0);
254#else
255 GLdepth z = z0;
256#endif
257 ASSERT(yBoti <= yTopi);
258
259 {
260#if INTERP_STUV0
261 GLfloat invQ = 1.0F / hv0;
262 GLfloat s = hs0 * invQ;
263 GLfloat t = ht0 * invQ;
264 GLfloat u = hu0 * invQ;
265#endif
266#if INTERP_STUV1
267 GLfloat invQ1 = 1.0F / hv01;
268 GLfloat s1 = hs01 * invQ1;
269 GLfloat t1 = ht01 * invQ1;
270 GLfloat u1 = hu01 * invQ1;
271#endif
272
273 /* bottom pixel of swipe */
274#if INTERP_RGBA
275 coverage = (GLint) (alpha * (1.0F - (yBot - yBoti)));
276#endif
277#if INTERP_INDEX
278 coverage = (GLuint) (15.0F * (1.0F - (yBot - yBoti)));
279#endif
280 PLOT(x, yBoti);
281 yBoti++;
282
283 /* top pixel of swipe */
284#if INTERP_RGBA
285 coverage = (GLint) (alpha * (yTop - yTopi));
286#endif
287#if INTERP_INDEX
288 coverage = (GLuint) (15.0F * (yTop - yTopi));
289#endif
290 PLOT(x, yTopi);
291 yTopi--;
292
293 /* pixels between top and bottom with 100% coverage */
294#if INTERP_RGBA
295 coverage = alpha;
296#endif
297#if INTERP_INDEX
298 coverage = 15;
299#endif
300 for (iy = yBoti; iy <= yTopi; iy++) {
301 PLOT(x, iy);
302 }
303 }
304 PB_CHECK_FLUSH( ctx, pb );
305
306 } /* if stippling */
307
308 x += xStep;
309 y += yStep;
310 z0 += dz;
311#if INTERP_RGBA
312 fr += dfr;
313 fg += dfg;
314 fb += dfb;
315 fa += dfa;
316#endif
317#if INTERP_SPEC
318 fsr += dfsr;
319 fsg += dfsg;
320 fsb += dfsb;
321#endif
322#if INTERP_STUV0
323 hs0 += dhs;
324 ht0 += dht;
325 hu0 += dhu;
326 hv0 += dhv;
327#endif
328#if INTERP_STUV1
329 hs01 += dhs1;
330 ht01 += dht1;
331 hu01 += dhu1;
332 hv01 += dhv1;
333#endif
334#if INTERP_INDEX
335 fi += dfi;
336#endif
337
338 if (!solid)
339 ctx->StippleCounter++;
340 }
341 }
342 else {
343 /*** Y-major line ***/
344 GLint i;
345 GLint y = y0;
346 GLfloat x = VB->Win.data[vert0][0];
347 GLfloat xStep = (VB->Win.data[vert1][0] - x) / (GLfloat) dy;
348 GLint dz = (z1 - z0) / dy;
349 GLfloat invDy = 1.0F / dy;
350 (void) invDy;
351#if INTERP_RGBA
352 if (ctx->Light.ShadeModel == GL_SMOOTH) {
353 dfr = (IntToFixed(VB->ColorPtr->data[vert1][0]) - fr) * invDy;
354 dfg = (IntToFixed(VB->ColorPtr->data[vert1][1]) - fg) * invDy;
355 dfb = (IntToFixed(VB->ColorPtr->data[vert1][2]) - fb) * invDy;
356 dfa = (IntToFixed(VB->ColorPtr->data[vert1][3]) - fa) * invDy;
357 }
358#endif
359#if INTERP_SPEC
360 if (ctx->Light.ShadeModel == GL_SMOOTH) {
361 dfsr = (IntToFixed(VB->Specular[vert1][0]) - fsr) * invDy;
362 dfsg = (IntToFixed(VB->Specular[vert1][1]) - fsg) * invDy;
363 dfsb = (IntToFixed(VB->Specular[vert1][2]) - fsb) * invDy;
364 }
365#endif
366#if INTERP_STUV0
367 dhs *= invDy;
368 dht *= invDy;
369 dhu *= invDy;
370 dhv *= invDy;
371#endif
372#if INTERP_STUV1
373 dhs1 *= invDy;
374 dht1 *= invDy;
375 dhu1 *= invDy;
376 dhv1 *= invDy;
377#endif
378#if INTERP_INDEX
379 if (ctx->Light.ShadeModel == GL_SMOOTH) {
380 dfi = (IntToFixed(VB->IndexPtr->data[vert1]) - fi) / dy;
381 }
382#endif
383 for (i = 0; i < dy; i++) {
384 if (solid || (ctx->Line.StipplePattern & (1 << ((ctx->StippleCounter/ctx->Line.StippleFactor) & 0xf)))) {
385 GLfloat xRight = x + halfWidth;
386 GLfloat xLeft = x - halfWidth;
387 GLint xRighti = (GLint) xRight;
388 GLint xLefti = (GLint) xLeft;
389 GLint ix;
390#if INTERP_RGBA
391 GLubyte red = FixedToInt(fr);
392 GLubyte green = FixedToInt(fg);
393 GLubyte blue = FixedToInt(fb);
394 GLubyte alpha = FixedToInt(fa);
395 GLint coverage;
396#endif
397#if INTERP_SPEC
398 GLubyte specRed = FixedToInt(fsr);
399 GLubyte specGreen = FixedToInt(fsg);
400 GLubyte specBlue = FixedToInt(fsb);
401#endif
402#if INTERP_INDEX
403 GLuint index = FixedToInt(fi) & 0xfffffff0;
404 GLuint coverage;
405#endif
406#if DEPTH_BITS==16
407 GLdepth z = FixedToInt(z0);
408#else
409 GLdepth z = z0;
410#endif
411
412 ASSERT(xLefti < xRight);
413
414 {
415#if INTERP_STUV0
416 GLfloat invQ = 1.0F / hv0;
417 GLfloat s = hs0 * invQ;
418 GLfloat t = ht0 * invQ;
419 GLfloat u = hu0 * invQ;
420#endif
421#if INTERP_STUV1
422 GLfloat invQ1 = 1.0F / hv01;
423 GLfloat s1 = hs01 * invQ1;
424 GLfloat t1 = ht01 * invQ1;
425 GLfloat u1 = hu01 * invQ1;
426#endif
427
428 /* left pixel of swipe */
429#if INTERP_RGBA
430 coverage = (GLint) (alpha * (1.0F - (xLeft - xLefti)));
431#endif
432#if INTERP_INDEX
433 coverage = (GLuint) (15.0F * (1.0F - (xLeft - xLefti)));
434#endif
435 PLOT(xLefti, y);
436 xLefti++;
437
438 /* right pixel of swipe */
439#if INTERP_RGBA
440 coverage = (GLint) (alpha * (xRight - xRighti));
441#endif
442#if INTERP_INDEX
443 coverage = (GLuint) (15.0F * (xRight - xRighti));
444#endif
445 PLOT(xRighti, y)
446 xRighti--;
447
448 /* pixels between top and bottom with 100% coverage */
449#if INTERP_RGBA
450 coverage = alpha;
451#endif
452#if INTERP_INDEX
453 coverage = 15;
454#endif
455 for (ix = xLefti; ix <= xRighti; ix++) {
456 PLOT(ix, y);
457 }
458 }
459 PB_CHECK_FLUSH( ctx, pb );
460 }
461
462 x += xStep;
463 y += yStep;
464 z0 += dz;
465#if INTERP_RGBA
466 fr += dfr;
467 fg += dfg;
468 fb += dfb;
469 fa += dfa;
470#endif
471#if INTERP_SPEC
472 fsr += dfsr;
473 fsg += dfsg;
474 fsb += dfsb;
475#endif
476#if INTERP_STUV0
477 hs0 += dhs;
478 ht0 += dht;
479 hu0 += dhu;
480 hv0 += dhv;
481#endif
482#if INTERP_STUV1
483 hs01 += dhs1;
484 ht01 += dht1;
485 hu01 += dhu1;
486 hv01 += dhv1;
487#endif
488#if INTERP_INDEX
489 fi += dfi;
490#endif
491 if (!solid)
492 ctx->StippleCounter++;
493 }
494 }
495}
496
497#undef INTERP_RGBA
498#undef INTERP_SPEC
499#undef INTERP_STUV0
500#undef INTERP_STUV1
501#undef INTERP_INDEX
502#undef PLOT
Note: See TracBrowser for help on using the repository browser.