source: trunk/src/opengl/mesa/lines.c@ 3830

Last change on this file since 3830 was 3598, checked in by jeroen, 25 years ago

* empty log message *

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