Fix order of decomposition of quad.
[mesa.git] / src / mesa / swrast / s_lines.c
1 /* $Id: s_lines.c,v 1.17 2001/05/17 09:32:17 keithw 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 #include "glheader.h"
29 #include "colormac.h"
30 #include "macros.h"
31 #include "mmath.h"
32 #include "s_aaline.h"
33 #include "s_pb.h"
34 #include "s_context.h"
35 #include "s_depth.h"
36 #include "s_lines.h"
37 #include "s_feedback.h"
38
39
40
41 /**********************************************************************/
42 /***** Rasterization *****/
43 /**********************************************************************/
44
45
46 /*
47 * There are 4 pairs (RGBA, CI) of line drawing functions:
48 * 1. simple: width=1 and no special rasterization functions (fastest)
49 * 2. flat: width=1, non-stippled, flat-shaded, any raster operations
50 * 3. smooth: width=1, non-stippled, smooth-shaded, any raster operations
51 * 4. general: any other kind of line (slowest)
52 */
53
54
55 /* Flat, color index line */
56 static void flat_ci_line( GLcontext *ctx,
57 const SWvertex *vert0,
58 const SWvertex *vert1 )
59 {
60 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
61
62 PB_SET_INDEX( PB, vert0->index );
63
64 #define INTERP_XY 1
65 #define PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, 0, 0);
66
67 #include "s_linetemp.h"
68
69 _mesa_flush_pb(ctx);
70 }
71
72
73
74 /* Flat, color index line with Z interpolation/testing */
75 static void flat_ci_z_line( GLcontext *ctx,
76 const SWvertex *vert0,
77 const SWvertex *vert1 )
78 {
79 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
80 PB_SET_INDEX( PB, vert0->index );
81
82 #define INTERP_XY 1
83 #define INTERP_Z 1
84 #define INTERP_FOG 1
85 #define PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, Z, fog0);
86
87 #include "s_linetemp.h"
88
89 _mesa_flush_pb(ctx);
90 }
91
92
93
94 /* Flat-shaded, RGBA line */
95 static void flat_rgba_line( GLcontext *ctx,
96 const SWvertex *vert0,
97 const SWvertex *vert1 )
98 {
99 const GLchan *color = vert1->color;
100 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
101 PB_SET_COLOR( PB, color[0], color[1], color[2], color[3] );
102
103 #define INTERP_XY 1
104 #define PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, 0, 0);
105
106 #include "s_linetemp.h"
107
108 _mesa_flush_pb(ctx);
109 }
110
111
112
113 /* Flat-shaded, RGBA line with Z interpolation/testing */
114 static void flat_rgba_z_line( GLcontext *ctx,
115 const SWvertex *vert0,
116 const SWvertex *vert1 )
117 {
118 const GLchan *color = vert1->color;
119 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
120 PB_SET_COLOR( PB, color[0], color[1], color[2], color[3] );
121
122 #define INTERP_XY 1
123 #define INTERP_Z 1
124 #define INTERP_FOG 1
125 #define PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, Z, fog0);
126
127 #include "s_linetemp.h"
128
129 _mesa_flush_pb(ctx);
130 }
131
132
133
134 /* Smooth shaded, color index line */
135 static void smooth_ci_line( GLcontext *ctx,
136 const SWvertex *vert0,
137 const SWvertex *vert1 )
138 {
139 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
140 GLint count = PB->count;
141 GLint *pbx = PB->x;
142 GLint *pby = PB->y;
143 GLuint *pbi = PB->index;
144
145 PB->mono = GL_FALSE;
146
147 #define INTERP_XY 1
148 #define INTERP_INDEX 1
149
150 #define PLOT(X,Y) \
151 pbx[count] = X; \
152 pby[count] = Y; \
153 pbi[count] = I; \
154 count++;
155
156 #include "s_linetemp.h"
157
158 PB->count = count;
159 _mesa_flush_pb(ctx);
160 }
161
162
163
164 /* Smooth shaded, color index line with Z interpolation/testing */
165 static void smooth_ci_z_line( GLcontext *ctx,
166 const SWvertex *vert0,
167 const SWvertex *vert1 )
168 {
169 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
170 GLint count = PB->count;
171 GLint *pbx = PB->x;
172 GLint *pby = PB->y;
173 GLdepth *pbz = PB->z;
174 GLuint *pbi = PB->index;
175
176 PB->mono = GL_FALSE;
177
178 #define INTERP_XY 1
179 #define INTERP_Z 1
180 #define INTERP_FOG 1
181 #define INTERP_INDEX 1
182
183 #define PLOT(X,Y) \
184 pbx[count] = X; \
185 pby[count] = Y; \
186 pbz[count] = Z; \
187 pbi[count] = I; \
188 count++;
189
190 #include "s_linetemp.h"
191
192 PB->count = count;
193 _mesa_flush_pb(ctx);
194 }
195
196
197
198 /* Smooth-shaded, RGBA line */
199 static void smooth_rgba_line( GLcontext *ctx,
200 const SWvertex *vert0,
201 const SWvertex *vert1 )
202 {
203 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
204 GLint count = PB->count;
205 GLint *pbx = PB->x;
206 GLint *pby = PB->y;
207 GLchan (*pbrgba)[4] = PB->rgba;
208
209 PB->mono = GL_FALSE;
210
211 #define INTERP_XY 1
212 #define INTERP_RGB 1
213 #define INTERP_ALPHA 1
214
215 #define PLOT(X,Y) \
216 pbx[count] = X; \
217 pby[count] = Y; \
218 pbrgba[count][RCOMP] = FixedToInt(r0); \
219 pbrgba[count][GCOMP] = FixedToInt(g0); \
220 pbrgba[count][BCOMP] = FixedToInt(b0); \
221 pbrgba[count][ACOMP] = FixedToInt(a0); \
222 count++;
223
224 #include "s_linetemp.h"
225
226 PB->count = count;
227 _mesa_flush_pb(ctx);
228 }
229
230
231
232 /* Smooth-shaded, RGBA line with Z interpolation/testing */
233 static void smooth_rgba_z_line( GLcontext *ctx,
234 const SWvertex *vert0,
235 const SWvertex *vert1 )
236 {
237 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
238 GLint count = PB->count;
239 GLint *pbx = PB->x;
240 GLint *pby = PB->y;
241 GLdepth *pbz = PB->z;
242 GLfloat *pbfog = PB->fog;
243 GLchan (*pbrgba)[4] = PB->rgba;
244
245
246 PB->mono = GL_FALSE;
247
248 #define INTERP_XY 1
249 #define INTERP_Z 1
250 #define INTERP_FOG 1
251 #define INTERP_RGB 1
252 #define INTERP_ALPHA 1
253
254 #define PLOT(X,Y) \
255 pbx[count] = X; \
256 pby[count] = Y; \
257 pbz[count] = Z; \
258 pbfog[count] = fog0; \
259 pbrgba[count][RCOMP] = FixedToInt(r0); \
260 pbrgba[count][GCOMP] = FixedToInt(g0); \
261 pbrgba[count][BCOMP] = FixedToInt(b0); \
262 pbrgba[count][ACOMP] = FixedToInt(a0); \
263 count++;
264
265 #include "s_linetemp.h"
266
267 PB->count = count;
268 _mesa_flush_pb(ctx);
269 }
270
271
272 #define CHECK_FULL(count) \
273 if (count >= PB_SIZE-MAX_WIDTH) { \
274 PB->count = count; \
275 _mesa_flush_pb(ctx); \
276 count = PB->count; \
277 }
278
279
280
281 /* Smooth shaded, color index, any width, maybe stippled */
282 static void general_smooth_ci_line( GLcontext *ctx,
283 const SWvertex *vert0,
284 const SWvertex *vert1 )
285 {
286 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
287 GLint count = PB->count;
288 GLint *pbx = PB->x;
289 GLint *pby = PB->y;
290 GLdepth *pbz = PB->z;
291 GLfloat *pbfog = PB->fog;
292 GLuint *pbi = PB->index;
293
294 PB->mono = GL_FALSE;
295
296 if (ctx->Line.StippleFlag) {
297 /* stippled */
298 #define INTERP_XY 1
299 #define INTERP_Z 1
300 #define INTERP_FOG 1
301 #define INTERP_INDEX 1
302 #define WIDE 1
303 #define STIPPLE 1
304 #define PLOT(X,Y) \
305 pbx[count] = X; \
306 pby[count] = Y; \
307 pbz[count] = Z; \
308 pbfog[count] = fog0; \
309 pbi[count] = I; \
310 count++; \
311 CHECK_FULL(count);
312 #include "s_linetemp.h"
313 }
314 else {
315 /* unstippled */
316 if (ctx->Line.Width==2.0F) {
317 /* special case: unstippled and width=2 */
318 #define INTERP_XY 1
319 #define INTERP_Z 1
320 #define INTERP_FOG 1
321 #define INTERP_INDEX 1
322 #define XMAJOR_PLOT(X,Y) \
323 pbx[count] = X; pbx[count+1] = X; \
324 pby[count] = Y; pby[count+1] = Y+1; \
325 pbz[count] = Z; pbz[count+1] = Z; \
326 pbfog[count] = fog0; pbfog[count+1] = fog0; \
327 pbi[count] = I; pbi[count+1] = I; \
328 count += 2; \
329 CHECK_FULL(count);
330 #define YMAJOR_PLOT(X,Y) \
331 pbx[count] = X; pbx[count+1] = X+1; \
332 pby[count] = Y; pby[count+1] = Y; \
333 pbz[count] = Z; pbz[count+1] = Z; \
334 pbfog[count] = fog0; pbfog[count+1] = fog0; \
335 pbi[count] = I; pbi[count+1] = I; \
336 count += 2; \
337 CHECK_FULL(count);
338 #include "s_linetemp.h"
339 }
340 else {
341 /* unstippled, any width */
342 #define INTERP_XY 1
343 #define INTERP_Z 1
344 #define INTERP_FOG 1
345 #define INTERP_INDEX 1
346 #define WIDE 1
347 #define PLOT(X,Y) \
348 pbx[count] = X; \
349 pby[count] = Y; \
350 pbz[count] = Z; \
351 pbi[count] = I; \
352 pbfog[count] = fog0; \
353 count++; \
354 CHECK_FULL(count);
355 #include "s_linetemp.h"
356 }
357 }
358
359 PB->count = count;
360 _mesa_flush_pb(ctx);
361 }
362
363
364 /* Flat shaded, color index, any width, maybe stippled */
365 static void general_flat_ci_line( GLcontext *ctx,
366 const SWvertex *vert0,
367 const SWvertex *vert1 )
368 {
369 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
370 GLint count;
371 GLint *pbx = PB->x;
372 GLint *pby = PB->y;
373 GLdepth *pbz = PB->z;
374 GLfloat *pbfog = PB->fog;
375 PB_SET_INDEX( PB, vert0->index );
376 count = PB->count;
377
378 if (ctx->Line.StippleFlag) {
379 /* stippled, any width */
380 #define INTERP_XY 1
381 #define INTERP_Z 1
382 #define INTERP_FOG 1
383 #define WIDE 1
384 #define STIPPLE 1
385 #define PLOT(X,Y) \
386 pbx[count] = X; \
387 pby[count] = Y; \
388 pbz[count] = Z; \
389 pbfog[count] = fog0; \
390 count++; \
391 CHECK_FULL(count);
392 #include "s_linetemp.h"
393 }
394 else {
395 /* unstippled */
396 if (ctx->Line.Width==2.0F) {
397 /* special case: unstippled and width=2 */
398 #define INTERP_XY 1
399 #define INTERP_Z 1
400 #define INTERP_FOG 1
401 #define XMAJOR_PLOT(X,Y) \
402 pbx[count] = X; pbx[count+1] = X; \
403 pby[count] = Y; pby[count+1] = Y+1; \
404 pbz[count] = Z; pbz[count+1] = Z; \
405 pbfog[count] = fog0; pbfog[count+1] = fog0; \
406 count += 2; \
407 CHECK_FULL(count);
408 #define YMAJOR_PLOT(X,Y) \
409 pbx[count] = X; pbx[count+1] = X+1; \
410 pby[count] = Y; pby[count+1] = Y; \
411 pbz[count] = Z; pbz[count+1] = Z; \
412 pbfog[count] = fog0; pbfog[count+1] = fog0; \
413 count += 2; \
414 CHECK_FULL(count);
415 #include "s_linetemp.h"
416 }
417 else {
418 /* unstippled, any width */
419 #define INTERP_XY 1
420 #define INTERP_Z 1
421 #define INTERP_FOG 1
422 #define WIDE 1
423 #define PLOT(X,Y) \
424 pbx[count] = X; \
425 pby[count] = Y; \
426 pbz[count] = Z; \
427 pbfog[count] = fog0; \
428 count++; \
429 CHECK_FULL(count);
430 #include "s_linetemp.h"
431 }
432 }
433
434 PB->count = count;
435 _mesa_flush_pb(ctx);
436 }
437
438
439
440 static void general_smooth_rgba_line( GLcontext *ctx,
441 const SWvertex *vert0,
442 const SWvertex *vert1 )
443 {
444 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
445 GLint count = PB->count;
446 GLint *pbx = PB->x;
447 GLint *pby = PB->y;
448 GLdepth *pbz = PB->z;
449 GLfloat *pbfog = PB->fog;
450 GLchan (*pbrgba)[4] = PB->rgba;
451
452 PB->mono = GL_FALSE;
453
454 if (ctx->Line.StippleFlag) {
455 /* stippled */
456 #define INTERP_XY 1
457 #define INTERP_Z 1
458 #define INTERP_FOG 1
459 #define INTERP_RGB 1
460 #define INTERP_ALPHA 1
461 #define WIDE 1
462 #define STIPPLE 1
463 #define PLOT(X,Y) \
464 pbx[count] = X; \
465 pby[count] = Y; \
466 pbz[count] = Z; \
467 pbfog[count] = fog0; \
468 pbrgba[count][RCOMP] = FixedToInt(r0); \
469 pbrgba[count][GCOMP] = FixedToInt(g0); \
470 pbrgba[count][BCOMP] = FixedToInt(b0); \
471 pbrgba[count][ACOMP] = FixedToInt(a0); \
472 count++; \
473 CHECK_FULL(count);
474 #include "s_linetemp.h"
475 }
476 else {
477 /* unstippled */
478 if (ctx->Line.Width==2.0F) {
479 /* special case: unstippled and width=2 */
480 #define INTERP_XY 1
481 #define INTERP_Z 1
482 #define INTERP_FOG 1
483 #define INTERP_RGB 1
484 #define INTERP_ALPHA 1
485 #define XMAJOR_PLOT(X,Y) \
486 pbx[count] = X; pbx[count+1] = X; \
487 pby[count] = Y; pby[count+1] = Y+1; \
488 pbz[count] = Z; pbz[count+1] = Z; \
489 pbfog[count] = fog0; pbfog[count+1] = fog0; \
490 pbrgba[count][RCOMP] = FixedToInt(r0); \
491 pbrgba[count][GCOMP] = FixedToInt(g0); \
492 pbrgba[count][BCOMP] = FixedToInt(b0); \
493 pbrgba[count][ACOMP] = FixedToInt(a0); \
494 pbrgba[count+1][RCOMP] = FixedToInt(r0); \
495 pbrgba[count+1][GCOMP] = FixedToInt(g0); \
496 pbrgba[count+1][BCOMP] = FixedToInt(b0); \
497 pbrgba[count+1][ACOMP] = FixedToInt(a0); \
498 count += 2; \
499 CHECK_FULL(count);
500 #define YMAJOR_PLOT(X,Y) \
501 pbx[count] = X; pbx[count+1] = X+1; \
502 pby[count] = Y; pby[count+1] = Y; \
503 pbz[count] = Z; pbz[count+1] = Z; \
504 pbfog[count] = fog0; pbfog[count+1] = fog0; \
505 pbrgba[count][RCOMP] = FixedToInt(r0); \
506 pbrgba[count][GCOMP] = FixedToInt(g0); \
507 pbrgba[count][BCOMP] = FixedToInt(b0); \
508 pbrgba[count][ACOMP] = FixedToInt(a0); \
509 pbrgba[count+1][RCOMP] = FixedToInt(r0); \
510 pbrgba[count+1][GCOMP] = FixedToInt(g0); \
511 pbrgba[count+1][BCOMP] = FixedToInt(b0); \
512 pbrgba[count+1][ACOMP] = FixedToInt(a0); \
513 count += 2; \
514 CHECK_FULL(count);
515 #include "s_linetemp.h"
516 }
517 else {
518 /* unstippled, any width */
519 #define INTERP_XY 1
520 #define INTERP_Z 1
521 #define INTERP_FOG 1
522 #define INTERP_RGB 1
523 #define INTERP_ALPHA 1
524 #define WIDE 1
525 #define PLOT(X,Y) \
526 pbx[count] = X; \
527 pby[count] = Y; \
528 pbz[count] = Z; \
529 pbfog[count] = fog0; \
530 pbrgba[count][RCOMP] = FixedToInt(r0); \
531 pbrgba[count][GCOMP] = FixedToInt(g0); \
532 pbrgba[count][BCOMP] = FixedToInt(b0); \
533 pbrgba[count][ACOMP] = FixedToInt(a0); \
534 count++; \
535 CHECK_FULL(count);
536 #include "s_linetemp.h"
537 }
538 }
539
540 PB->count = count;
541 _mesa_flush_pb(ctx);
542 }
543
544
545 static void general_flat_rgba_line( GLcontext *ctx,
546 const SWvertex *vert0,
547 const SWvertex *vert1 )
548 {
549 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
550 const GLchan *color = vert1->color;
551 PB_SET_COLOR( PB, color[0], color[1], color[2], color[3] );
552
553 if (ctx->Line.StippleFlag) {
554 /* stippled */
555 #define INTERP_XY 1
556 #define INTERP_Z 1
557 #define INTERP_FOG 1
558 #define WIDE 1
559 #define STIPPLE 1
560 #define PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, Z, fog0);
561 #include "s_linetemp.h"
562 }
563 else {
564 /* unstippled */
565 if (ctx->Line.Width==2.0F) {
566 /* special case: unstippled and width=2 */
567 #define INTERP_XY 1
568 #define INTERP_Z 1
569 #define INTERP_FOG 1
570 #define XMAJOR_PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, Z, fog0); \
571 PB_WRITE_PIXEL(PB, X, Y+1, Z, fog0);
572 #define YMAJOR_PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, Z, fog0); \
573 PB_WRITE_PIXEL(PB, X+1, Y, Z, fog0);
574 #include "s_linetemp.h"
575 }
576 else {
577 /* unstippled, any width */
578 #define INTERP_XY 1
579 #define INTERP_Z 1
580 #define INTERP_FOG 1
581 #define WIDE 1
582 #define PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, Z, fog0);
583 #include "s_linetemp.h"
584 }
585 }
586
587 _mesa_flush_pb(ctx);
588 }
589
590
591 /* Flat-shaded, textured, any width, maybe stippled */
592 static void flat_textured_line( GLcontext *ctx,
593 const SWvertex *vert0,
594 const SWvertex *vert1 )
595 {
596 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
597 GLint count;
598 GLint *pbx = PB->x;
599 GLint *pby = PB->y;
600 GLdepth *pbz = PB->z;
601 GLfloat *pbfog = PB->fog;
602 GLfloat *pbs = PB->s[0];
603 GLfloat *pbt = PB->t[0];
604 GLfloat *pbu = PB->u[0];
605 GLchan *color = (GLchan*) vert1->color;
606 PB_SET_COLOR( PB, color[0], color[1], color[2], color[3] );
607 count = PB->count;
608
609 if (ctx->Line.StippleFlag) {
610 /* stippled */
611 #define INTERP_XY 1
612 #define INTERP_Z 1
613 #define INTERP_FOG 1
614 #define INTERP_TEX 1
615 #define WIDE 1
616 #define STIPPLE 1
617 #define PLOT(X,Y) \
618 { \
619 pbx[count] = X; \
620 pby[count] = Y; \
621 pbz[count] = Z; \
622 pbfog[count] = fog0; \
623 pbs[count] = fragTexcoord[0];\
624 pbt[count] = fragTexcoord[1];\
625 pbu[count] = fragTexcoord[2];\
626 count++; \
627 CHECK_FULL(count); \
628 }
629 #include "s_linetemp.h"
630 }
631 else {
632 /* unstippled */
633 #define INTERP_XY 1
634 #define INTERP_Z 1
635 #define INTERP_FOG 1
636 #define INTERP_TEX 1
637 #define WIDE 1
638 #define PLOT(X,Y) \
639 { \
640 pbx[count] = X; \
641 pby[count] = Y; \
642 pbz[count] = Z; \
643 pbfog[count] = fog0; \
644 pbs[count] = fragTexcoord[0];\
645 pbt[count] = fragTexcoord[1];\
646 pbu[count] = fragTexcoord[2];\
647 count++; \
648 CHECK_FULL(count); \
649 }
650 #include "s_linetemp.h"
651 }
652
653 PB->count = count;
654 _mesa_flush_pb(ctx);
655 }
656
657
658
659 /* Smooth-shaded, textured, any width, maybe stippled */
660 static void smooth_textured_line( GLcontext *ctx,
661 const SWvertex *vert0,
662 const SWvertex *vert1 )
663 {
664 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
665 GLint count = PB->count;
666 GLint *pbx = PB->x;
667 GLint *pby = PB->y;
668 GLdepth *pbz = PB->z;
669 GLfloat *pbfog = PB->fog;
670 GLfloat *pbs = PB->s[0];
671 GLfloat *pbt = PB->t[0];
672 GLfloat *pbu = PB->u[0];
673 GLchan (*pbrgba)[4] = PB->rgba;
674
675 PB->mono = GL_FALSE;
676
677 if (ctx->Line.StippleFlag) {
678 /* stippled */
679 #define INTERP_XY 1
680 #define INTERP_Z 1
681 #define INTERP_FOG 1
682 #define INTERP_RGB 1
683 #define INTERP_ALPHA 1
684 #define INTERP_TEX 1
685 #define WIDE 1
686 #define STIPPLE 1
687 #define PLOT(X,Y) \
688 { \
689 pbx[count] = X; \
690 pby[count] = Y; \
691 pbz[count] = Z; \
692 pbfog[count] = fog0; \
693 pbs[count] = fragTexcoord[0]; \
694 pbt[count] = fragTexcoord[1]; \
695 pbu[count] = fragTexcoord[2]; \
696 pbrgba[count][RCOMP] = FixedToInt(r0); \
697 pbrgba[count][GCOMP] = FixedToInt(g0); \
698 pbrgba[count][BCOMP] = FixedToInt(b0); \
699 pbrgba[count][ACOMP] = FixedToInt(a0); \
700 count++; \
701 CHECK_FULL(count); \
702 }
703 #include "s_linetemp.h"
704 }
705 else {
706 /* unstippled */
707 #define INTERP_XY 1
708 #define INTERP_Z 1
709 #define INTERP_FOG 1
710 #define INTERP_RGB 1
711 #define INTERP_ALPHA 1
712 #define INTERP_TEX 1
713 #define WIDE 1
714 #define PLOT(X,Y) \
715 { \
716 pbx[count] = X; \
717 pby[count] = Y; \
718 pbz[count] = Z; \
719 pbfog[count] = fog0; \
720 pbs[count] = fragTexcoord[0]; \
721 pbt[count] = fragTexcoord[1]; \
722 pbu[count] = fragTexcoord[2]; \
723 pbrgba[count][RCOMP] = FixedToInt(r0); \
724 pbrgba[count][GCOMP] = FixedToInt(g0); \
725 pbrgba[count][BCOMP] = FixedToInt(b0); \
726 pbrgba[count][ACOMP] = FixedToInt(a0); \
727 count++; \
728 CHECK_FULL(count); \
729 }
730 #include "s_linetemp.h"
731 }
732
733 PB->count = count;
734 _mesa_flush_pb(ctx);
735 }
736
737
738 /* Smooth-shaded, multitextured, any width, maybe stippled, separate specular
739 * color interpolation.
740 */
741 static void smooth_multitextured_line( GLcontext *ctx,
742 const SWvertex *vert0,
743 const SWvertex *vert1 )
744 {
745 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
746 GLint count = PB->count;
747 GLint *pbx = PB->x;
748 GLint *pby = PB->y;
749 GLdepth *pbz = PB->z;
750 GLfloat *pbfog = PB->fog;
751 GLchan (*pbrgba)[4] = PB->rgba;
752 GLchan (*pbspec)[3] = PB->spec;
753
754 PB->mono = GL_FALSE;
755
756 if (ctx->Line.StippleFlag) {
757 /* stippled */
758 #define INTERP_XY 1
759 #define INTERP_Z 1
760 #define INTERP_FOG 1
761 #define INTERP_RGB 1
762 #define INTERP_SPEC 1
763 #define INTERP_ALPHA 1
764 #define INTERP_MULTITEX 1
765 #define WIDE 1
766 #define STIPPLE 1
767 #define PLOT(X,Y) \
768 { \
769 GLuint u; \
770 pbx[count] = X; \
771 pby[count] = Y; \
772 pbz[count] = Z; \
773 pbfog[count] = fog0; \
774 pbrgba[count][RCOMP] = FixedToInt(r0); \
775 pbrgba[count][GCOMP] = FixedToInt(g0); \
776 pbrgba[count][BCOMP] = FixedToInt(b0); \
777 pbrgba[count][ACOMP] = FixedToInt(a0); \
778 pbspec[count][RCOMP] = FixedToInt(sr0); \
779 pbspec[count][GCOMP] = FixedToInt(sg0); \
780 pbspec[count][BCOMP] = FixedToInt(sb0); \
781 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
782 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
783 PB->s[u][0] = fragTexcoord[u][0]; \
784 PB->s[u][1] = fragTexcoord[u][1]; \
785 PB->s[u][2] = fragTexcoord[u][2]; \
786 PB->s[u][3] = fragTexcoord[u][3]; \
787 } \
788 } \
789 count++; \
790 CHECK_FULL(count); \
791 }
792 #include "s_linetemp.h"
793 }
794 else {
795 /* unstippled */
796 #define INTERP_XY 1
797 #define INTERP_Z 1
798 #define INTERP_FOG 1
799 #define INTERP_RGB 1
800 #define INTERP_SPEC 1
801 #define INTERP_ALPHA 1
802 #define INTERP_MULTITEX 1
803 #define WIDE 1
804 #define PLOT(X,Y) \
805 { \
806 GLuint u; \
807 pbx[count] = X; \
808 pby[count] = Y; \
809 pbz[count] = Z; \
810 pbfog[count] = fog0; \
811 pbrgba[count][RCOMP] = FixedToInt(r0); \
812 pbrgba[count][GCOMP] = FixedToInt(g0); \
813 pbrgba[count][BCOMP] = FixedToInt(b0); \
814 pbrgba[count][ACOMP] = FixedToInt(a0); \
815 pbspec[count][RCOMP] = FixedToInt(sr0); \
816 pbspec[count][GCOMP] = FixedToInt(sg0); \
817 pbspec[count][BCOMP] = FixedToInt(sb0); \
818 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
819 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
820 PB->s[u][0] = fragTexcoord[u][0]; \
821 PB->s[u][1] = fragTexcoord[u][1]; \
822 PB->s[u][2] = fragTexcoord[u][2]; \
823 PB->s[u][3] = fragTexcoord[u][3]; \
824 } \
825 } \
826 count++; \
827 CHECK_FULL(count); \
828 }
829 #include "s_linetemp.h"
830 }
831
832 PB->count = count;
833 _mesa_flush_pb(ctx);
834 }
835
836
837 /* Flat-shaded, multitextured, any width, maybe stippled, separate specular
838 * color interpolation.
839 */
840 static void flat_multitextured_line( GLcontext *ctx,
841 const SWvertex *vert0,
842 const SWvertex *vert1 )
843 {
844 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
845 GLint count = PB->count;
846 GLint *pbx = PB->x;
847 GLint *pby = PB->y;
848 GLdepth *pbz = PB->z;
849 GLfloat *pbfog = PB->fog;
850 GLchan (*pbrgba)[4] = PB->rgba;
851 GLchan (*pbspec)[3] = PB->spec;
852 GLchan *color = (GLchan*) vert1->color;
853 GLchan sRed = vert1->specular[0];
854 GLchan sGreen = vert1->specular[1];
855 GLchan sBlue = vert1->specular[2];
856
857 PB->mono = GL_FALSE;
858
859 if (ctx->Line.StippleFlag) {
860 /* stippled */
861 #define INTERP_XY 1
862 #define INTERP_Z 1
863 #define INTERP_FOG 1
864 #define INTERP_ALPHA 1
865 #define INTERP_MULTITEX 1
866 #define WIDE 1
867 #define STIPPLE 1
868 #define PLOT(X,Y) \
869 { \
870 GLuint u; \
871 pbx[count] = X; \
872 pby[count] = Y; \
873 pbz[count] = Z; \
874 pbfog[count] = fog0; \
875 pbrgba[count][RCOMP] = color[0]; \
876 pbrgba[count][GCOMP] = color[1]; \
877 pbrgba[count][BCOMP] = color[2]; \
878 pbrgba[count][ACOMP] = color[3]; \
879 pbspec[count][RCOMP] = sRed; \
880 pbspec[count][GCOMP] = sGreen; \
881 pbspec[count][BCOMP] = sBlue; \
882 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
883 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
884 PB->s[u][0] = fragTexcoord[u][0]; \
885 PB->s[u][1] = fragTexcoord[u][1]; \
886 PB->s[u][2] = fragTexcoord[u][2]; \
887 PB->s[u][3] = fragTexcoord[u][3]; \
888 } \
889 } \
890 count++; \
891 CHECK_FULL(count); \
892 }
893 #include "s_linetemp.h"
894 }
895 else {
896 /* unstippled */
897 #define INTERP_XY 1
898 #define INTERP_Z 1
899 #define INTERP_FOG 1
900 #define INTERP_ALPHA 1
901 #define INTERP_MULTITEX 1
902 #define WIDE 1
903 #define PLOT(X,Y) \
904 { \
905 GLuint u; \
906 pbx[count] = X; \
907 pby[count] = Y; \
908 pbz[count] = Z; \
909 pbfog[count] = fog0; \
910 pbrgba[count][RCOMP] = color[0]; \
911 pbrgba[count][GCOMP] = color[1]; \
912 pbrgba[count][BCOMP] = color[2]; \
913 pbrgba[count][ACOMP] = color[3]; \
914 pbspec[count][RCOMP] = sRed; \
915 pbspec[count][GCOMP] = sGreen; \
916 pbspec[count][BCOMP] = sBlue; \
917 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
918 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
919 PB->s[u][0] = fragTexcoord[u][0]; \
920 PB->s[u][1] = fragTexcoord[u][1]; \
921 PB->s[u][2] = fragTexcoord[u][2]; \
922 PB->s[u][3] = fragTexcoord[u][3]; \
923 } \
924 } \
925 count++; \
926 CHECK_FULL(count); \
927 }
928 #include "s_linetemp.h"
929 }
930
931 PB->count = count;
932 _mesa_flush_pb(ctx);
933 }
934
935
936 void _swrast_add_spec_terms_line( GLcontext *ctx,
937 const SWvertex *v0,
938 const SWvertex *v1 )
939 {
940 SWvertex *ncv0 = (SWvertex *)v0;
941 SWvertex *ncv1 = (SWvertex *)v1;
942 GLchan c[2][4];
943 COPY_CHAN4( c[0], ncv0->color );
944 COPY_CHAN4( c[1], ncv1->color );
945 ACC_3V( ncv0->color, ncv0->specular );
946 ACC_3V( ncv1->color, ncv1->specular );
947 SWRAST_CONTEXT(ctx)->SpecLine( ctx, ncv0, ncv1 );
948 COPY_CHAN4( ncv0->color, c[0] );
949 COPY_CHAN4( ncv1->color, c[1] );
950 }
951
952
953 #ifdef DEBUG
954 extern void
955 _mesa_print_line_function(GLcontext *ctx); /* silence compiler warning */
956 void
957 _mesa_print_line_function(GLcontext *ctx)
958 {
959 SWcontext *swrast = SWRAST_CONTEXT(ctx);
960
961 printf("Line Func == ");
962 if (swrast->Line == flat_ci_line)
963 printf("flat_ci_line\n");
964 else if (swrast->Line == flat_ci_z_line)
965 printf("flat_ci_z_line\n");
966 else if (swrast->Line == flat_rgba_line)
967 printf("flat_rgba_line\n");
968 else if (swrast->Line == flat_rgba_z_line)
969 printf("flat_rgba_z_line\n");
970 else if (swrast->Line == smooth_ci_line)
971 printf("smooth_ci_line\n");
972 else if (swrast->Line == smooth_ci_z_line)
973 printf("smooth_ci_z_line\n");
974 else if (swrast->Line == smooth_rgba_line)
975 printf("smooth_rgba_line\n");
976 else if (swrast->Line == smooth_rgba_z_line)
977 printf("smooth_rgba_z_line\n");
978 else if (swrast->Line == general_smooth_ci_line)
979 printf("general_smooth_ci_line\n");
980 else if (swrast->Line == general_flat_ci_line)
981 printf("general_flat_ci_line\n");
982 else if (swrast->Line == general_smooth_rgba_line)
983 printf("general_smooth_rgba_line\n");
984 else if (swrast->Line == general_flat_rgba_line)
985 printf("general_flat_rgba_line\n");
986 else if (swrast->Line == flat_textured_line)
987 printf("flat_textured_line\n");
988 else if (swrast->Line == smooth_textured_line)
989 printf("smooth_textured_line\n");
990 else if (swrast->Line == smooth_multitextured_line)
991 printf("smooth_multitextured_line\n");
992 else if (swrast->Line == flat_multitextured_line)
993 printf("flat_multitextured_line\n");
994 else
995 printf("Driver func %p\n", swrast->Line);
996 }
997 #endif
998
999
1000
1001 /*
1002 * Determine which line drawing function to use given the current
1003 * rendering context.
1004 *
1005 * Please update the summary flag _SWRAST_NEW_LINE if you add or remove
1006 * tests to this code.
1007 */
1008 void
1009 _swrast_choose_line( GLcontext *ctx )
1010 {
1011 SWcontext *swrast = SWRAST_CONTEXT(ctx);
1012 const GLboolean rgbmode = ctx->Visual.rgbMode;
1013
1014 if (ctx->RenderMode==GL_RENDER) {
1015 if (ctx->Line.SmoothFlag) {
1016 /* antialiased lines */
1017 _swrast_choose_aa_line_function(ctx);
1018 ASSERT(swrast->Triangle);
1019 }
1020 else if (ctx->Texture._ReallyEnabled) {
1021 if (ctx->Texture._ReallyEnabled > TEXTURE0_ANY ||
1022 (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)) {
1023 /* multi-texture and/or separate specular color */
1024 if (ctx->Light.ShadeModel==GL_SMOOTH)
1025 swrast->Line = smooth_multitextured_line;
1026 else
1027 swrast->Line = flat_multitextured_line;
1028 }
1029 else {
1030 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1031 swrast->Line = smooth_textured_line;
1032 }
1033 else {
1034 swrast->Line = flat_textured_line;
1035 }
1036 }
1037 }
1038 else if (ctx->Line.Width!=1.0 || ctx->Line.StippleFlag) {
1039 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1040 if (rgbmode)
1041 swrast->Line = general_smooth_rgba_line;
1042 else
1043 swrast->Line = general_smooth_ci_line;
1044 }
1045 else {
1046 if (rgbmode)
1047 swrast->Line = general_flat_rgba_line;
1048 else
1049 swrast->Line = general_flat_ci_line;
1050 }
1051 }
1052 else {
1053 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1054 /* Width==1, non-stippled, smooth-shaded */
1055 if (ctx->Depth.Test || ctx->Fog.Enabled) {
1056 if (rgbmode)
1057 swrast->Line = smooth_rgba_z_line;
1058 else
1059 swrast->Line = smooth_ci_z_line;
1060 }
1061 else {
1062 if (rgbmode)
1063 swrast->Line = smooth_rgba_line;
1064 else
1065 swrast->Line = smooth_ci_line;
1066 }
1067 }
1068 else {
1069 /* Width==1, non-stippled, flat-shaded */
1070 if (ctx->Depth.Test || ctx->Fog.Enabled) {
1071 if (rgbmode)
1072 swrast->Line = flat_rgba_z_line;
1073 else
1074 swrast->Line = flat_ci_z_line;
1075 }
1076 else {
1077 if (rgbmode)
1078 swrast->Line = flat_rgba_line;
1079 else
1080 swrast->Line = flat_ci_line;
1081 }
1082 }
1083 }
1084 }
1085 else if (ctx->RenderMode==GL_FEEDBACK) {
1086 swrast->Line = _mesa_feedback_line;
1087 }
1088 else {
1089 /* GL_SELECT mode */
1090 swrast->Line = _mesa_select_line;
1091 }
1092
1093 /*_mesa_print_line_function(ctx);*/
1094 }