new debugging code
[mesa.git] / src / mesa / swrast / s_lines.c
1 /* $Id: s_lines.c,v 1.20 2001/08/20 16:41:47 brianp 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 GLuint count;
552 PB_SET_COLOR( PB, color[0], color[1], color[2], color[3] );
553
554 if (ctx->Line.StippleFlag) {
555 /* stippled */
556 #define INTERP_XY 1
557 #define INTERP_Z 1
558 #define INTERP_FOG 1
559 #define WIDE 1
560 #define STIPPLE 1
561 #define PLOT(X,Y) \
562 PB_WRITE_PIXEL(PB, X, Y, Z, fog0); \
563 count = PB->count; \
564 CHECK_FULL(count);
565 #include "s_linetemp.h"
566 }
567 else {
568 /* unstippled */
569 if (ctx->Line.Width==2.0F) {
570 /* special case: unstippled and width=2 */
571 #define INTERP_XY 1
572 #define INTERP_Z 1
573 #define INTERP_FOG 1
574 #define XMAJOR_PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, Z, fog0); \
575 PB_WRITE_PIXEL(PB, X, Y+1, Z, fog0);
576 #define YMAJOR_PLOT(X,Y) PB_WRITE_PIXEL(PB, X, Y, Z, fog0); \
577 PB_WRITE_PIXEL(PB, X+1, Y, Z, fog0);
578 #include "s_linetemp.h"
579 }
580 else {
581 /* unstippled, any width */
582 #define INTERP_XY 1
583 #define INTERP_Z 1
584 #define INTERP_FOG 1
585 #define WIDE 1
586 #define PLOT(X,Y) \
587 PB_WRITE_PIXEL(PB, X, Y, Z, fog0); \
588 count = PB->count; \
589 CHECK_FULL(count);
590 #include "s_linetemp.h"
591 }
592 }
593
594 _mesa_flush_pb(ctx);
595 }
596
597
598 /* Flat-shaded, textured, any width, maybe stippled */
599 static void flat_textured_line( GLcontext *ctx,
600 const SWvertex *vert0,
601 const SWvertex *vert1 )
602 {
603 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
604 GLint count;
605 GLint *pbx = PB->x;
606 GLint *pby = PB->y;
607 GLdepth *pbz = PB->z;
608 GLfloat *pbfog = PB->fog;
609 GLfloat *pbs = PB->s[0];
610 GLfloat *pbt = PB->t[0];
611 GLfloat *pbu = PB->u[0];
612 GLchan *color = (GLchan*) vert1->color;
613 PB_SET_COLOR( PB, color[0], color[1], color[2], color[3] );
614 count = PB->count;
615
616 if (ctx->Line.StippleFlag) {
617 /* stippled */
618 #define INTERP_XY 1
619 #define INTERP_Z 1
620 #define INTERP_FOG 1
621 #define INTERP_TEX 1
622 #define WIDE 1
623 #define STIPPLE 1
624 #define PLOT(X,Y) \
625 { \
626 pbx[count] = X; \
627 pby[count] = Y; \
628 pbz[count] = Z; \
629 pbfog[count] = fog0; \
630 pbs[count] = fragTexcoord[0];\
631 pbt[count] = fragTexcoord[1];\
632 pbu[count] = fragTexcoord[2];\
633 count++; \
634 CHECK_FULL(count); \
635 }
636 #include "s_linetemp.h"
637 }
638 else {
639 /* unstippled */
640 #define INTERP_XY 1
641 #define INTERP_Z 1
642 #define INTERP_FOG 1
643 #define INTERP_TEX 1
644 #define WIDE 1
645 #define PLOT(X,Y) \
646 { \
647 pbx[count] = X; \
648 pby[count] = Y; \
649 pbz[count] = Z; \
650 pbfog[count] = fog0; \
651 pbs[count] = fragTexcoord[0];\
652 pbt[count] = fragTexcoord[1];\
653 pbu[count] = fragTexcoord[2];\
654 count++; \
655 CHECK_FULL(count); \
656 }
657 #include "s_linetemp.h"
658 }
659
660 PB->count = count;
661 _mesa_flush_pb(ctx);
662 }
663
664
665
666 /* Smooth-shaded, textured, any width, maybe stippled */
667 static void smooth_textured_line( GLcontext *ctx,
668 const SWvertex *vert0,
669 const SWvertex *vert1 )
670 {
671 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
672 GLint count = PB->count;
673 GLint *pbx = PB->x;
674 GLint *pby = PB->y;
675 GLdepth *pbz = PB->z;
676 GLfloat *pbfog = PB->fog;
677 GLfloat *pbs = PB->s[0];
678 GLfloat *pbt = PB->t[0];
679 GLfloat *pbu = PB->u[0];
680 GLchan (*pbrgba)[4] = PB->rgba;
681
682 PB->mono = GL_FALSE;
683
684 if (ctx->Line.StippleFlag) {
685 /* stippled */
686 #define INTERP_XY 1
687 #define INTERP_Z 1
688 #define INTERP_FOG 1
689 #define INTERP_RGB 1
690 #define INTERP_ALPHA 1
691 #define INTERP_TEX 1
692 #define WIDE 1
693 #define STIPPLE 1
694 #define PLOT(X,Y) \
695 { \
696 pbx[count] = X; \
697 pby[count] = Y; \
698 pbz[count] = Z; \
699 pbfog[count] = fog0; \
700 pbs[count] = fragTexcoord[0]; \
701 pbt[count] = fragTexcoord[1]; \
702 pbu[count] = fragTexcoord[2]; \
703 pbrgba[count][RCOMP] = FixedToInt(r0); \
704 pbrgba[count][GCOMP] = FixedToInt(g0); \
705 pbrgba[count][BCOMP] = FixedToInt(b0); \
706 pbrgba[count][ACOMP] = FixedToInt(a0); \
707 count++; \
708 CHECK_FULL(count); \
709 }
710 #include "s_linetemp.h"
711 }
712 else {
713 /* unstippled */
714 #define INTERP_XY 1
715 #define INTERP_Z 1
716 #define INTERP_FOG 1
717 #define INTERP_RGB 1
718 #define INTERP_ALPHA 1
719 #define INTERP_TEX 1
720 #define WIDE 1
721 #define PLOT(X,Y) \
722 { \
723 pbx[count] = X; \
724 pby[count] = Y; \
725 pbz[count] = Z; \
726 pbfog[count] = fog0; \
727 pbs[count] = fragTexcoord[0]; \
728 pbt[count] = fragTexcoord[1]; \
729 pbu[count] = fragTexcoord[2]; \
730 pbrgba[count][RCOMP] = FixedToInt(r0); \
731 pbrgba[count][GCOMP] = FixedToInt(g0); \
732 pbrgba[count][BCOMP] = FixedToInt(b0); \
733 pbrgba[count][ACOMP] = FixedToInt(a0); \
734 count++; \
735 CHECK_FULL(count); \
736 }
737 #include "s_linetemp.h"
738 }
739
740 PB->count = count;
741 _mesa_flush_pb(ctx);
742 }
743
744
745 /* Smooth-shaded, multitextured, any width, maybe stippled, separate specular
746 * color interpolation.
747 */
748 static void smooth_multitextured_line( GLcontext *ctx,
749 const SWvertex *vert0,
750 const SWvertex *vert1 )
751 {
752 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
753 GLint count = PB->count;
754 GLint *pbx = PB->x;
755 GLint *pby = PB->y;
756 GLdepth *pbz = PB->z;
757 GLfloat *pbfog = PB->fog;
758 GLchan (*pbrgba)[4] = PB->rgba;
759 GLchan (*pbspec)[3] = PB->spec;
760
761 PB->mono = GL_FALSE;
762
763 if (ctx->Line.StippleFlag) {
764 /* stippled */
765 #define INTERP_XY 1
766 #define INTERP_Z 1
767 #define INTERP_FOG 1
768 #define INTERP_RGB 1
769 #define INTERP_SPEC 1
770 #define INTERP_ALPHA 1
771 #define INTERP_MULTITEX 1
772 #define WIDE 1
773 #define STIPPLE 1
774 #define PLOT(X,Y) \
775 { \
776 GLuint u; \
777 pbx[count] = X; \
778 pby[count] = Y; \
779 pbz[count] = Z; \
780 pbfog[count] = fog0; \
781 pbrgba[count][RCOMP] = FixedToInt(r0); \
782 pbrgba[count][GCOMP] = FixedToInt(g0); \
783 pbrgba[count][BCOMP] = FixedToInt(b0); \
784 pbrgba[count][ACOMP] = FixedToInt(a0); \
785 pbspec[count][RCOMP] = FixedToInt(sr0); \
786 pbspec[count][GCOMP] = FixedToInt(sg0); \
787 pbspec[count][BCOMP] = FixedToInt(sb0); \
788 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
789 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
790 PB->s[u][count] = fragTexcoord[u][0]; \
791 PB->t[u][count] = fragTexcoord[u][1]; \
792 PB->u[u][count] = fragTexcoord[u][2]; \
793 } \
794 } \
795 count++; \
796 CHECK_FULL(count); \
797 }
798 #include "s_linetemp.h"
799 }
800 else {
801 /* unstippled */
802 #define INTERP_XY 1
803 #define INTERP_Z 1
804 #define INTERP_FOG 1
805 #define INTERP_RGB 1
806 #define INTERP_SPEC 1
807 #define INTERP_ALPHA 1
808 #define INTERP_MULTITEX 1
809 #define WIDE 1
810 #define PLOT(X,Y) \
811 { \
812 GLuint u; \
813 pbx[count] = X; \
814 pby[count] = Y; \
815 pbz[count] = Z; \
816 pbfog[count] = fog0; \
817 pbrgba[count][RCOMP] = FixedToInt(r0); \
818 pbrgba[count][GCOMP] = FixedToInt(g0); \
819 pbrgba[count][BCOMP] = FixedToInt(b0); \
820 pbrgba[count][ACOMP] = FixedToInt(a0); \
821 pbspec[count][RCOMP] = FixedToInt(sr0); \
822 pbspec[count][GCOMP] = FixedToInt(sg0); \
823 pbspec[count][BCOMP] = FixedToInt(sb0); \
824 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
825 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
826 PB->s[u][count] = fragTexcoord[u][0]; \
827 PB->t[u][count] = fragTexcoord[u][1]; \
828 PB->u[u][count] = fragTexcoord[u][2]; \
829 } \
830 } \
831 count++; \
832 CHECK_FULL(count); \
833 }
834 #include "s_linetemp.h"
835 }
836
837 PB->count = count;
838 _mesa_flush_pb(ctx);
839 }
840
841
842 /* Flat-shaded, multitextured, any width, maybe stippled, separate specular
843 * color interpolation.
844 */
845 static void flat_multitextured_line( GLcontext *ctx,
846 const SWvertex *vert0,
847 const SWvertex *vert1 )
848 {
849 struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
850 GLint count = PB->count;
851 GLint *pbx = PB->x;
852 GLint *pby = PB->y;
853 GLdepth *pbz = PB->z;
854 GLfloat *pbfog = PB->fog;
855 GLchan (*pbrgba)[4] = PB->rgba;
856 GLchan (*pbspec)[3] = PB->spec;
857 GLchan *color = (GLchan*) vert1->color;
858 GLchan sRed = vert1->specular[0];
859 GLchan sGreen = vert1->specular[1];
860 GLchan sBlue = vert1->specular[2];
861
862 PB->mono = GL_FALSE;
863
864 if (ctx->Line.StippleFlag) {
865 /* stippled */
866 #define INTERP_XY 1
867 #define INTERP_Z 1
868 #define INTERP_FOG 1
869 #define INTERP_ALPHA 1
870 #define INTERP_MULTITEX 1
871 #define WIDE 1
872 #define STIPPLE 1
873 #define PLOT(X,Y) \
874 { \
875 GLuint u; \
876 pbx[count] = X; \
877 pby[count] = Y; \
878 pbz[count] = Z; \
879 pbfog[count] = fog0; \
880 pbrgba[count][RCOMP] = color[0]; \
881 pbrgba[count][GCOMP] = color[1]; \
882 pbrgba[count][BCOMP] = color[2]; \
883 pbrgba[count][ACOMP] = color[3]; \
884 pbspec[count][RCOMP] = sRed; \
885 pbspec[count][GCOMP] = sGreen; \
886 pbspec[count][BCOMP] = sBlue; \
887 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
888 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
889 PB->s[u][count] = fragTexcoord[u][0]; \
890 PB->t[u][count] = fragTexcoord[u][1]; \
891 PB->u[u][count] = fragTexcoord[u][2]; \
892 } \
893 } \
894 count++; \
895 CHECK_FULL(count); \
896 }
897 #include "s_linetemp.h"
898 }
899 else {
900 /* unstippled */
901 #define INTERP_XY 1
902 #define INTERP_Z 1
903 #define INTERP_FOG 1
904 #define INTERP_ALPHA 1
905 #define INTERP_MULTITEX 1
906 #define WIDE 1
907 #define PLOT(X,Y) \
908 { \
909 GLuint u; \
910 pbx[count] = X; \
911 pby[count] = Y; \
912 pbz[count] = Z; \
913 pbfog[count] = fog0; \
914 pbrgba[count][RCOMP] = color[0]; \
915 pbrgba[count][GCOMP] = color[1]; \
916 pbrgba[count][BCOMP] = color[2]; \
917 pbrgba[count][ACOMP] = color[3]; \
918 pbspec[count][RCOMP] = sRed; \
919 pbspec[count][GCOMP] = sGreen; \
920 pbspec[count][BCOMP] = sBlue; \
921 for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \
922 if (ctx->Texture.Unit[u]._ReallyEnabled) { \
923 PB->s[u][count] = fragTexcoord[u][0]; \
924 PB->t[u][count] = fragTexcoord[u][1]; \
925 PB->u[u][count] = fragTexcoord[u][2]; \
926 } \
927 } \
928 count++; \
929 CHECK_FULL(count); \
930 }
931 #include "s_linetemp.h"
932 }
933
934 PB->count = count;
935 _mesa_flush_pb(ctx);
936 }
937
938
939 void _swrast_add_spec_terms_line( GLcontext *ctx,
940 const SWvertex *v0,
941 const SWvertex *v1 )
942 {
943 SWvertex *ncv0 = (SWvertex *)v0;
944 SWvertex *ncv1 = (SWvertex *)v1;
945 GLchan c[2][4];
946 COPY_CHAN4( c[0], ncv0->color );
947 COPY_CHAN4( c[1], ncv1->color );
948 ACC_3V( ncv0->color, ncv0->specular );
949 ACC_3V( ncv1->color, ncv1->specular );
950 SWRAST_CONTEXT(ctx)->SpecLine( ctx, ncv0, ncv1 );
951 COPY_CHAN4( ncv0->color, c[0] );
952 COPY_CHAN4( ncv1->color, c[1] );
953 }
954
955
956 #ifdef DEBUG
957 extern void
958 _mesa_print_line_function(GLcontext *ctx); /* silence compiler warning */
959 void
960 _mesa_print_line_function(GLcontext *ctx)
961 {
962 SWcontext *swrast = SWRAST_CONTEXT(ctx);
963
964 printf("Line Func == ");
965 if (swrast->Line == flat_ci_line)
966 printf("flat_ci_line\n");
967 else if (swrast->Line == flat_ci_z_line)
968 printf("flat_ci_z_line\n");
969 else if (swrast->Line == flat_rgba_line)
970 printf("flat_rgba_line\n");
971 else if (swrast->Line == flat_rgba_z_line)
972 printf("flat_rgba_z_line\n");
973 else if (swrast->Line == smooth_ci_line)
974 printf("smooth_ci_line\n");
975 else if (swrast->Line == smooth_ci_z_line)
976 printf("smooth_ci_z_line\n");
977 else if (swrast->Line == smooth_rgba_line)
978 printf("smooth_rgba_line\n");
979 else if (swrast->Line == smooth_rgba_z_line)
980 printf("smooth_rgba_z_line\n");
981 else if (swrast->Line == general_smooth_ci_line)
982 printf("general_smooth_ci_line\n");
983 else if (swrast->Line == general_flat_ci_line)
984 printf("general_flat_ci_line\n");
985 else if (swrast->Line == general_smooth_rgba_line)
986 printf("general_smooth_rgba_line\n");
987 else if (swrast->Line == general_flat_rgba_line)
988 printf("general_flat_rgba_line\n");
989 else if (swrast->Line == flat_textured_line)
990 printf("flat_textured_line\n");
991 else if (swrast->Line == smooth_textured_line)
992 printf("smooth_textured_line\n");
993 else if (swrast->Line == smooth_multitextured_line)
994 printf("smooth_multitextured_line\n");
995 else if (swrast->Line == flat_multitextured_line)
996 printf("flat_multitextured_line\n");
997 else
998 printf("Driver func %p\n", swrast->Line);
999 }
1000 #endif
1001
1002
1003
1004 #ifdef DEBUG
1005
1006 /* record the current line function name */
1007 static const char *lineFuncName = NULL;
1008
1009 #define USE(lineFunc) \
1010 do { \
1011 lineFuncName = #lineFunc; \
1012 /*printf("%s\n", lineFuncName);*/ \
1013 swrast->Line = lineFunc; \
1014 } while (0)
1015
1016 #else
1017
1018 #define USE(lineFunc) swrast->Line = lineFunc;
1019
1020 #endif
1021
1022
1023
1024 /*
1025 * Determine which line drawing function to use given the current
1026 * rendering context.
1027 *
1028 * Please update the summary flag _SWRAST_NEW_LINE if you add or remove
1029 * tests to this code.
1030 */
1031 void
1032 _swrast_choose_line( GLcontext *ctx )
1033 {
1034 SWcontext *swrast = SWRAST_CONTEXT(ctx);
1035 const GLboolean rgbmode = ctx->Visual.rgbMode;
1036
1037 if (ctx->RenderMode==GL_RENDER) {
1038 if (ctx->Line.SmoothFlag) {
1039 /* antialiased lines */
1040 _swrast_choose_aa_line_function(ctx);
1041 ASSERT(swrast->Triangle);
1042 }
1043 else if (ctx->Texture._ReallyEnabled) {
1044 if (ctx->Texture._ReallyEnabled > TEXTURE0_ANY ||
1045 (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)) {
1046 /* multi-texture and/or separate specular color */
1047 if (ctx->Light.ShadeModel==GL_SMOOTH)
1048 USE(smooth_multitextured_line);
1049 else
1050 USE(flat_multitextured_line);
1051 }
1052 else {
1053 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1054 USE(smooth_textured_line);
1055 }
1056 else {
1057 USE(flat_textured_line);
1058 }
1059 }
1060 }
1061 else if (ctx->Line.Width!=1.0 || ctx->Line.StippleFlag) {
1062 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1063 if (rgbmode)
1064 USE(general_smooth_rgba_line);
1065 else
1066 USE(general_smooth_ci_line);
1067 }
1068 else {
1069 if (rgbmode)
1070 USE(general_flat_rgba_line);
1071 else
1072 USE(general_flat_ci_line);
1073 }
1074 }
1075 else {
1076 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1077 /* Width==1, non-stippled, smooth-shaded */
1078 if (ctx->Depth.Test || ctx->Fog.Enabled) {
1079 if (rgbmode)
1080 USE(smooth_rgba_z_line);
1081 else
1082 USE(smooth_ci_z_line);
1083 }
1084 else {
1085 if (rgbmode)
1086 USE(smooth_rgba_line);
1087 else
1088 USE(smooth_ci_line);
1089 }
1090 }
1091 else {
1092 /* Width==1, non-stippled, flat-shaded */
1093 if (ctx->Depth.Test || ctx->Fog.Enabled) {
1094 if (rgbmode)
1095 USE(flat_rgba_z_line);
1096 else
1097 USE(flat_ci_z_line);
1098 }
1099 else {
1100 if (rgbmode)
1101 USE(flat_rgba_line);
1102 else
1103 USE(flat_ci_line);
1104 }
1105 }
1106 }
1107 }
1108 else if (ctx->RenderMode==GL_FEEDBACK) {
1109 USE(_mesa_feedback_line);
1110 }
1111 else {
1112 /* GL_SELECT mode */
1113 USE(_mesa_select_line);
1114 }
1115
1116 /*_mesa_print_line_function(ctx);*/
1117 }