1 #include "sgcf.h"
2 #if defined(HAVE_X11)
3
4 /* $Id: xmesa3.c,v 1.4 2000/12/31 16:32:59 mholst Exp $ */
5
6 /*
7 * Mesa 3-D graphics library
8 * Version: 2.0
9 * Copyright (C) 1995-1996 Brian Paul
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26 /*
27 * Mesa/X11 interface, part 3.
28 *
29 * This file contains "accelerated" point, line, and triangle functions.
30 * It should be fairly easy to write new special-purpose point, line or
31 * triangle functions and hook them into this module.
32 */
33
34
35
36 #include <sys/time.h>
37 #include <assert.h>
38
39
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <X11/Xlib.h>
43 #include "bresenhm.h"
44 #include "depth.h"
45 #include "interp.h"
46 #include "macros.h"
47 #include "vb.h"
48 #include "types.h"
49 #include "xmesaP.h"
50
51
52 /*
53 * Like PACK_8A8B8G8R() but don't use alpha. This is usually an acceptable
54 * shortcut.
55 */
56 #define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) )
57
58
59
60
61 /**********************************************************************/
62 /*** Point rendering ***/
63 /**********************************************************************/
64
65
66 /*
67 * Render an array of points into a pixmap, any pixel format.
68 */
draw_points_ANY_pixmap(GLcontext * ctx,GLuint first,GLuint last)69 static void draw_points_ANY_pixmap( GLcontext *ctx, GLuint first, GLuint last )
70 {
71 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
72 Display *dpy = xmesa->xm_visual->display;
73 Drawable buffer = xmesa->xm_buffer->buffer;
74 GC gc = xmesa->xm_buffer->gc2;
75 struct vertex_buffer *VB = ctx->VB;
76 register GLuint i;
77
78 if (VB->MonoColor) {
79 /* all same color */
80 XPoint p[VB_SIZE];
81 int n = 0;
82 for (i=first;i<=last;i++) {
83 if (VB->Unclipped[i]) {
84 p[n].x = (GLint) VB->Win[i][0];
85 p[n].y = FLIP( (GLint) VB->Win[i][1] );
86 n++;
87 }
88 }
89 XDrawPoints( dpy, buffer, xmesa->xm_buffer->gc1, p, n, CoordModeOrigin );
90 }
91 else {
92 /* all different colors */
93 int shift = ctx->ColorShift;
94 if (xmesa->xm_visual->gl_visual->RGBAflag) {
95 /* RGB mode */
96 for (i=first;i<=last;i++) {
97 if (VB->Unclipped[i]) {
98 register int x, y;
99 unsigned long pixel = xmesa_color_to_pixel( xmesa,
100 VB->Color[i][0] >> shift,
101 VB->Color[i][1] >> shift,
102 VB->Color[i][2] >> shift,
103 VB->Color[i][3] >> shift );
104 XSetForeground( dpy, gc, pixel );
105 x = (GLint) VB->Win[i][0];
106 y = FLIP( (GLint) VB->Win[i][1] );
107 XDrawPoint( dpy, buffer, gc, x, y);
108 }
109 }
110 }
111 else {
112 /* Color index mode */
113 for (i=first;i<=last;i++) {
114 if (VB->Unclipped[i]) {
115 register int x, y;
116 XSetForeground( dpy, gc, VB->Index[i] >> shift );
117 x = (GLint) VB->Win[i][0];
118 y = FLIP( (GLint) VB->Win[i][1] );
119 XDrawPoint( dpy, buffer, gc, x, y);
120 }
121 }
122 }
123 }
124 }
125
126
127
128 /*
129 * Analyze context state to see if we can provide a fast points drawing
130 * function, like those in points.c. Otherwise, return NULL.
131 */
xmesa_get_points_func(GLcontext * ctx)132 points_func xmesa_get_points_func( GLcontext *ctx )
133 {
134 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
135
136 if (ctx->Point.Size==1.0F && !ctx->Point.SmoothFlag && ctx->RasterMask==0
137 && !ctx->Texture.Enabled) {
138 if (xmesa->xm_buffer->buffer==XIMAGE) {
139 return NULL; /*draw_points_ximage;*/
140 }
141 else {
142 return draw_points_ANY_pixmap;
143 }
144 }
145 else {
146 return NULL;
147 }
148 }
149
150
151
152 /**********************************************************************/
153 /*** Line rendering ***/
154 /**********************************************************************/
155
156 /*
157 * Render a line into a pixmap, any pixel format.
158 */
flat_pixmap_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)159 static void flat_pixmap_line( GLcontext *ctx, GLuint v0, GLuint v1, GLuint pv )
160 {
161 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
162 struct vertex_buffer *VB = ctx->VB;
163 register int x0, y0, x1, y1;
164 GC gc;
165 if (VB->MonoColor) {
166 gc = xmesa->xm_buffer->gc1; /* use current color */
167 }
168 else {
169 unsigned long pixel;
170 if (xmesa->xm_visual->gl_visual->RGBAflag) {
171 pixel = xmesa_color_to_pixel( xmesa,
172 VB->Color[pv][0], VB->Color[pv][1],
173 VB->Color[pv][2], VB->Color[pv][3] );
174 }
175 else {
176 pixel = VB->Index[pv];
177 }
178 gc = xmesa->xm_buffer->gc2;
179 XSetForeground( xmesa->display, gc, pixel );
180 }
181 x0 = (GLint) VB->Win[v0][0];
182 y0 = FLIP( (GLint) VB->Win[v0][1] );
183 x1 = (GLint) VB->Win[v1][0];
184 y1 = FLIP( (GLint) VB->Win[v1][1] );
185 XDrawLine( xmesa->display, xmesa->xm_buffer->buffer, gc, x0, y0, x1, y1 );
186 }
187
188
189 /*
190 * Despite being clipped to the view volume, the line's window coordinates
191 * may just lie outside the window bounds. That is, if the legal window
192 * coordinates are [0,W-1][0,H-1], it's possible for x==W and/or y==H.
193 * These quick and dirty macros take care of that possibility.
194 */
195 #define WINCLIP_X(X1,X2) \
196 { \
197 GLint w = ctx->Buffer->Width; \
198 if ((X1==w) | (X2==w)) { \
199 if ((X1==w) & (X2==w)) return;\
200 X1 -= (X1==w); X2 -= (X2==w);\
201 } \
202 }
203
204 #define WINCLIP_Y(Y1,Y2) \
205 { \
206 GLint h = ctx->Buffer->Height; \
207 if ((Y1==h) | (Y2==h)) { \
208 if ((Y1==h) & (Y2==h)) return;\
209 Y1 -= (Y1==h); Y2 -= (Y2==h);\
210 } \
211 }
212
213
214 /*
215 * Draw a flat-shaded, PF_8A8B8G8R line into an XImage.
216 */
flat_8A8B8G8R_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)217 static void flat_8A8B8G8R_line( GLcontext *ctx,
218 GLuint v0, GLuint v1, GLuint pv )
219 {
220 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
221 struct vertex_buffer *VB = ctx->VB;
222 GLint x1 = (GLint) VB->Win[v0][0], y1 = (GLint) VB->Win[v0][1];
223 GLint x2 = (GLint) VB->Win[v1][0], y2 = (GLint) VB->Win[v1][1];
224 GLuint pixel;
225 WINCLIP_X(x1,x2);
226 WINCLIP_Y(y1,y2);
227 pixel = PACK_8B8G8R( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2] );
228
229 #define BRESENHAM_PLOT(X,Y) \
230 { \
231 GLuint *ptr = PIXELADDR4(X,Y); \
232 *ptr = pixel; \
233 }
234
235 BRESENHAM( x1, y1, x2, y2 );
236
237 #undef BRESENHAM_PLOT
238 }
239
240
241 /*
242 * Draw a flat-shaded, PF_8R8G8B line into an XImage.
243 */
flat_8R8G8B_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)244 static void flat_8R8G8B_line( GLcontext *ctx,
245 GLuint v0, GLuint v1, GLuint pv )
246 {
247 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
248 struct vertex_buffer *VB = ctx->VB;
249 GLint x1 = (GLint) VB->Win[v0][0], y1 = (GLint) VB->Win[v0][1];
250 GLint x2 = (GLint) VB->Win[v1][0], y2 = (GLint) VB->Win[v1][1];
251 GLuint pixel;
252 WINCLIP_X(x1,x2);
253 WINCLIP_Y(y1,y2);
254 pixel = PACK_8R8G8B( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2] );
255
256 #define BRESENHAM_PLOT(X,Y) \
257 { \
258 GLuint *ptr = PIXELADDR4(X,Y); \
259 *ptr = pixel; \
260 }
261
262 BRESENHAM( x1, y1, x2, y2 );
263
264 #undef BRESENHAM_PLOT
265 }
266
267
268 /*
269 * Draw a flat-shaded, PF_5R6G5B line into an XImage.
270 */
flat_5R6G5B_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)271 static void flat_5R6G5B_line( GLcontext *ctx,
272 GLuint v0, GLuint v1, GLuint pv )
273 {
274 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
275 struct vertex_buffer *VB = ctx->VB;
276 GLint x1 = (GLint) VB->Win[v0][0], y1 = (GLint) VB->Win[v0][1];
277 GLint x2 = (GLint) VB->Win[v1][0], y2 = (GLint) VB->Win[v1][1];
278 GLushort pixel;
279 WINCLIP_X(x1,x2);
280 WINCLIP_Y(y1,y2);
281 pixel = PACK_5R6G5B( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2] );
282
283 #define BRESENHAM_PLOT(X,Y) \
284 { \
285 GLushort *ptr = PIXELADDR2(X,Y); \
286 *ptr = pixel; \
287 }
288
289 BRESENHAM( x1, y1, x2, y2 );
290
291 #undef BRESENHAM_PLOT
292 }
293
294
295
296 /*
297 * Draw a flat-shaded, PF_TRUECOLOR line into an XImage.
298 */
flat_TRUECOLOR_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)299 static void flat_TRUECOLOR_line( GLcontext *ctx,
300 GLuint v0, GLuint v1, GLuint pv )
301 {
302 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
303 struct vertex_buffer *VB = ctx->VB;
304 XImage *img = xmesa->xm_buffer->backimage;
305 GLint x1 = (GLint) VB->Win[v0][0], y1 = (GLint) VB->Win[v0][1];
306 GLint x2 = (GLint) VB->Win[v1][0], y2 = (GLint) VB->Win[v1][1];
307 unsigned long pixel = PACK_RGB( VB->Color[pv][0], VB->Color[pv][1],
308 VB->Color[pv][2] );
309 WINCLIP_X(x1,x2);
310 WINCLIP_Y(y1,y2);
311
312 #define BRESENHAM_PLOT(X,Y) \
313 XPutPixel( img, X, FLIP(Y), pixel );
314
315 BRESENHAM( x1, y1, x2, y2 );
316
317 #undef BRESENHAM_PLOT
318 }
319
320
321 /*
322 * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage.
323 */
flat_DITHER8_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)324 static void flat_DITHER8_line( GLcontext *ctx,
325 GLuint v0, GLuint v1, GLuint pv )
326 {
327 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
328 struct vertex_buffer *VB = ctx->VB;
329 GLint x1 = (GLint) VB->Win[v0][0], y1 = (GLint) VB->Win[v0][1];
330 GLint x2 = (GLint) VB->Win[v1][0], y2 = (GLint) VB->Win[v1][1];
331 GLint r = VB->Color[pv][0], g = VB->Color[pv][1], b = VB->Color[pv][2];
332 DITHER_SETUP;
333
334 WINCLIP_X(x1,x2);
335 WINCLIP_Y(y1,y2);
336
337 #define BRESENHAM_PLOT(X,Y) \
338 GLubyte *ptr = PIXELADDR1(X,Y); \
339 *ptr = DITHER( X, Y, r, g, b);
340
341 BRESENHAM( x1, y1, x2, y2 );
342
343 #undef BRESENHAM_PLOT
344 }
345
346
347 /*
348 * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage.
349 */
flat_LOOKUP8_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)350 static void flat_LOOKUP8_line( GLcontext *ctx,
351 GLuint v0, GLuint v1, GLuint pv )
352 {
353 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
354 struct vertex_buffer *VB = ctx->VB;
355 GLint x1 = (GLint) VB->Win[v0][0], y1 = (GLint) VB->Win[v0][1];
356 GLint x2 = (GLint) VB->Win[v1][0], y2 = (GLint) VB->Win[v1][1];
357 LOOKUP_SETUP;
358 GLubyte pixel = LOOKUP( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2] );
359
360 WINCLIP_X(x1,x2);
361 WINCLIP_Y(y1,y2);
362
363 #define BRESENHAM_PLOT(X,Y) \
364 GLubyte *ptr = PIXELADDR1(X,Y); \
365 *ptr = pixel;
366
367 BRESENHAM( x1, y1, x2, y2 );
368
369 #undef BRESENHAM_PLOT
370 }
371
372
373 /*
374 * Draw a flat-shaded, PF_HPCR line into an XImage.
375 */
flat_HPCR_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)376 static void flat_HPCR_line( GLcontext *ctx,
377 GLuint v0, GLuint v1, GLuint pv )
378 {
379 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
380 struct vertex_buffer *VB = ctx->VB;
381 GLint x1 = (GLint) VB->Win[v0][0], y1 = (GLint) VB->Win[v0][1];
382 GLint x2 = (GLint) VB->Win[v1][0], y2 = (GLint) VB->Win[v1][1];
383 GLint r = VB->Color[pv][0], g = VB->Color[pv][1], b = VB->Color[pv][2];
384
385 WINCLIP_X(x1,x2);
386 WINCLIP_Y(y1,y2);
387
388 #define BRESENHAM_PLOT(X,Y) \
389 GLubyte *ptr = PIXELADDR1(X,Y); \
390 *ptr = DITHER_HPCR( X, Y, r, g, b);
391
392 BRESENHAM( x1, y1, x2, y2 );
393
394 #undef BRESENHAM_PLOT
395 }
396
397
398
399 /*
400 * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage.
401 */
flat_TRUECOLOR_z_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)402 static void flat_TRUECOLOR_z_line( GLcontext *ctx,
403 GLuint v0, GLuint v1, GLuint pv )
404 {
405 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
406 XImage *img = xmesa->xm_buffer->backimage;
407 struct vertex_buffer *VB = ctx->VB;
408 GLint x1 = (GLint) VB->Win[v0][0], x2 = (GLint) VB->Win[v1][0];
409 GLint y1 = (GLint) VB->Win[v0][1], y2 = (GLint) VB->Win[v1][1];
410 GLint z1 = (GLint) (VB->Win[v0][2] + ctx->LineZoffset);
411 GLint z2 = (GLint) (VB->Win[v1][2] + ctx->LineZoffset);
412 unsigned long pixel = PACK_RGB( VB->Color[pv][0], VB->Color[pv][1],
413 VB->Color[pv][2] );
414
415 WINCLIP_X(x1,x2);
416 WINCLIP_Y(y1,y2);
417
418 #define BRESENHAM_PLOT(X,Y,Z,ZBUF) \
419 if (Z < *ZBUF) { \
420 XPutPixel( img, X, FLIP(Y), pixel ); \
421 *ZBUF = Z; \
422 }
423
424 BRESENHAM_Z( ctx, x1, y1, z1, x2, y2, z2 );
425
426 #undef BRESENHAM_PLOT
427 }
428
429
430 /*
431 * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage.
432 */
flat_8A8B8G8R_z_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)433 static void flat_8A8B8G8R_z_line( GLcontext *ctx,
434 GLuint v0, GLuint v1, GLuint pv )
435 {
436 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
437 struct vertex_buffer *VB = ctx->VB;
438 GLint x1 = (GLint) VB->Win[v0][0], x2 = (GLint) VB->Win[v1][0];
439 GLint y1 = (GLint) VB->Win[v0][1], y2 = (GLint) VB->Win[v1][1];
440 GLint z1 = (GLint) (VB->Win[v0][2] + ctx->LineZoffset);
441 GLint z2 = (GLint) (VB->Win[v1][2] + ctx->LineZoffset);
442 GLuint pixel = PACK_8B8G8R( VB->Color[pv][0], VB->Color[pv][1],
443 VB->Color[pv][2] );
444
445 WINCLIP_X(x1,x2);
446 WINCLIP_Y(y1,y2);
447
448 #define BRESENHAM_PLOT(X,Y,Z,ZBUF) \
449 if (Z < *ZBUF) { \
450 GLuint *ptr = PIXELADDR4(X,Y); \
451 *ptr = pixel; \
452 *ZBUF = Z; \
453 }
454
455 BRESENHAM_Z( ctx, x1, y1, z1, x2, y2, z2 );
456
457 #undef BRESENHAM_PLOT
458 }
459
460
461 /*
462 * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage.
463 */
flat_8R8G8B_z_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)464 static void flat_8R8G8B_z_line( GLcontext *ctx,
465 GLuint v0, GLuint v1, GLuint pv )
466 {
467 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
468 struct vertex_buffer *VB = ctx->VB;
469 GLint x1 = (GLint) VB->Win[v0][0], x2 = (GLint) VB->Win[v1][0];
470 GLint y1 = (GLint) VB->Win[v0][1], y2 = (GLint) VB->Win[v1][1];
471 GLint z1 = (GLint) (VB->Win[v0][2] + ctx->LineZoffset);
472 GLint z2 = (GLint) (VB->Win[v1][2] + ctx->LineZoffset);
473 GLuint pixel = PACK_8R8G8B( VB->Color[pv][0], VB->Color[pv][1],
474 VB->Color[pv][2] );
475
476 WINCLIP_X(x1,x2);
477 WINCLIP_Y(y1,y2);
478
479 #define BRESENHAM_PLOT(X,Y,Z,ZBUF) \
480 if (Z < *ZBUF) { \
481 GLuint *ptr = PIXELADDR4(X,Y); \
482 *ptr = pixel; \
483 *ZBUF = Z; \
484 }
485
486 BRESENHAM_Z( ctx, x1, y1, z1, x2, y2, z2 );
487
488 #undef BRESENHAM_PLOT
489 }
490
491
492 /*
493 * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage.
494 */
flat_5R6G5B_z_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)495 static void flat_5R6G5B_z_line( GLcontext *ctx,
496 GLuint v0, GLuint v1, GLuint pv )
497 {
498 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
499 struct vertex_buffer *VB = ctx->VB;
500 GLint x1 = (GLint) VB->Win[v0][0], x2 = (GLint) VB->Win[v1][0];
501 GLint y1 = (GLint) VB->Win[v0][1], y2 = (GLint) VB->Win[v1][1];
502 GLint z1 = (GLint) (VB->Win[v0][2] + ctx->LineZoffset);
503 GLint z2 = (GLint) (VB->Win[v1][2] + ctx->LineZoffset);
504 GLuint pixel = PACK_5R6G5B( VB->Color[pv][0], VB->Color[pv][1],
505 VB->Color[pv][2] );
506
507 WINCLIP_X(x1,x2);
508 WINCLIP_Y(y1,y2);
509
510 #define BRESENHAM_PLOT(X,Y,Z,ZBUF) \
511 if (Z < *ZBUF) { \
512 GLushort *ptr = PIXELADDR2(X,Y); \
513 *ptr = pixel; \
514 *ZBUF = Z; \
515 }
516
517 BRESENHAM_Z( ctx, x1, y1, z1, x2, y2, z2 );
518
519 #undef BRESENHAM_PLOT
520 }
521
522
523 /*
524 * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage.
525 */
flat_DITHER8_z_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)526 static void flat_DITHER8_z_line( GLcontext *ctx,
527 GLuint v0, GLuint v1, GLuint pv )
528 {
529 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
530 struct vertex_buffer *VB = ctx->VB;
531 GLint x1 = (GLint) VB->Win[v0][0], x2 = (GLint) VB->Win[v1][0];
532 GLint y1 = (GLint) VB->Win[v0][1], y2 = (GLint) VB->Win[v1][1];
533 GLint z1 = (GLint) (VB->Win[v0][2] + ctx->LineZoffset);
534 GLint z2 = (GLint) (VB->Win[v1][2] + ctx->LineZoffset);
535 GLint r = VB->Color[pv][0], g = VB->Color[pv][1], b = VB->Color[pv][2];
536 DITHER_SETUP;
537
538 WINCLIP_X(x1,x2);
539 WINCLIP_Y(y1,y2);
540
541 #define BRESENHAM_PLOT(X,Y,Z,ZBUF) \
542 if (Z < *ZBUF) { \
543 GLubyte *ptr = PIXELADDR1(X,Y); \
544 *ptr = DITHER( X, Y, r, g, b); \
545 *ZBUF = Z; \
546 }
547
548 BRESENHAM_Z( ctx, x1, y1, z1, x2, y2, z2 );
549
550 #undef BRESENHAM_PLOT
551 }
552
553
554 /*
555 * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage.
556 */
flat_LOOKUP8_z_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)557 static void flat_LOOKUP8_z_line( GLcontext *ctx,
558 GLuint v0, GLuint v1, GLuint pv )
559 {
560 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
561 struct vertex_buffer *VB = ctx->VB;
562 GLint x1 = (GLint) VB->Win[v0][0], x2 = (GLint) VB->Win[v1][0];
563 GLint y1 = (GLint) VB->Win[v0][1], y2 = (GLint) VB->Win[v1][1];
564 GLint z1 = (GLint) (VB->Win[v0][2] + ctx->LineZoffset);
565 GLint z2 = (GLint) (VB->Win[v1][2] + ctx->LineZoffset);
566 LOOKUP_SETUP;
567 GLubyte pixel = LOOKUP( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2] );
568
569 WINCLIP_X(x1,x2);
570 WINCLIP_Y(y1,y2);
571
572 #define BRESENHAM_PLOT(X,Y,Z,ZBUF) \
573 if (Z < *ZBUF) { \
574 GLubyte *ptr = PIXELADDR1(X,Y); \
575 *ptr = pixel; \
576 *ZBUF = Z; \
577 }
578
579 BRESENHAM_Z( ctx, x1, y1, z1, x2, y2, z2 );
580
581 #undef BRESENHAM_PLOT
582 }
583
584
585 /*
586 * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage.
587 */
flat_HPCR_z_line(GLcontext * ctx,GLuint v0,GLuint v1,GLuint pv)588 static void flat_HPCR_z_line( GLcontext *ctx,
589 GLuint v0, GLuint v1, GLuint pv )
590 {
591 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
592 struct vertex_buffer *VB = ctx->VB;
593 GLint x1 = (GLint) VB->Win[v0][0], x2 = (GLint) VB->Win[v1][0];
594 GLint y1 = (GLint) VB->Win[v0][1], y2 = (GLint) VB->Win[v1][1];
595 GLint z1 = (GLint) (VB->Win[v0][2] + ctx->LineZoffset);
596 GLint z2 = (GLint) (VB->Win[v1][2] + ctx->LineZoffset);
597 GLint r = VB->Color[pv][0], g = VB->Color[pv][1], b = VB->Color[pv][2];
598
599 WINCLIP_X(x1,x2);
600 WINCLIP_Y(y1,y2);
601
602 #define BRESENHAM_PLOT(X,Y,Z,ZBUF) \
603 if (Z < *ZBUF) { \
604 GLubyte *ptr = PIXELADDR1(X,Y); \
605 *ptr = DITHER_HPCR( X, Y, r, g, b); \
606 *ZBUF = Z; \
607 }
608
609 BRESENHAM_Z( ctx, x1, y1, z1, x2, y2, z2 );
610
611 #undef BRESENHAM_PLOT
612 }
613
614
615
616 /*
617 * Examine ctx->Line attributes and set xmesa->xm_buffer->gc1
618 * and xmesa->xm_buffer->gc2 appropriately.
619 */
setup_x_line_options(GLcontext * ctx)620 static void setup_x_line_options( GLcontext *ctx )
621 {
622 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
623 int i, state, state0, new_state, len, offs;
624 int tbit;
625 char *dptr;
626 int n_segments = 0;
627 char dashes[20];
628 int line_width, line_style;
629
630 /*** Line Stipple ***/
631 if (ctx->Line.StippleFlag) {
632 const int pattern = ctx->Line.StipplePattern;
633
634 dptr = dashes;
635 state0 = state = ((pattern & 1) != 0);
636
637 /* Decompose the pattern */
638 for (i=1,tbit=2,len=1;i<16;++i,tbit=(tbit<<1))
639 {
640 new_state = ((tbit & pattern) != 0);
641 if (state != new_state)
642 {
643 *dptr++ = ctx->Line.StippleFactor * len;
644 len = 1;
645 state = new_state;
646 }
647 else
648 ++len;
649 }
650 *dptr = ctx->Line.StippleFactor * len;
651 n_segments = 1 + (dptr - dashes);
652
653 /* ensure an even no. of segments, or X may toggle on/off for consecutive patterns */
654 /* if (n_segments & 1) dashes [n_segments++] = 0; value of 0 not allowed in dash list */
655
656 /* Handle case where line style starts OFF */
657 if (state0 == 0)
658 offs = dashes[0];
659 else
660 offs = 0;
661
662 #if 0
663 fprintf (stderr, "input pattern: 0x%04x, offset %d, %d segments:", pattern, offs, n_segments);
664 for (i = 0; i < n_segments; i++)
665 fprintf (stderr, " %d", dashes[i]);
666 fprintf (stderr, "\n");
667 #endif
668
669 XSetDashes( xmesa->display, xmesa->xm_buffer->gc1, offs, dashes, n_segments );
670 XSetDashes( xmesa->display, xmesa->xm_buffer->gc2, offs, dashes, n_segments );
671
672 line_style = LineOnOffDash;
673 }
674 else {
675 line_style = LineSolid;
676 }
677
678 /*** Line Width ***/
679 line_width = (int) (ctx->Line.Width+0.5F);
680 if (line_width < 2) {
681 /* Use fast lines when possible */
682 line_width = 0;
683 }
684
685 /*** Set GC attributes ***/
686 XSetLineAttributes( xmesa->display, xmesa->xm_buffer->gc1,
687 line_width, line_style, CapButt, JoinBevel);
688 XSetLineAttributes( xmesa->display, xmesa->xm_buffer->gc2,
689 line_width, line_style, CapButt, JoinBevel);
690 XSetFillStyle( xmesa->display, xmesa->xm_buffer->gc1, FillSolid );
691 XSetFillStyle( xmesa->display, xmesa->xm_buffer->gc2, FillSolid );
692 }
693
694
695
696 /*
697 * Analyze context state to see if we can provide a fast line drawing
698 * function, like those in lines.c. Otherwise, return NULL.
699 */
xmesa_get_line_func(GLcontext * ctx)700 line_func xmesa_get_line_func( GLcontext *ctx )
701 {
702 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
703 int depth = xmesa->xm_visual->visinfo->depth;
704
705 if (ctx->Line.SmoothFlag) return NULL;
706 if (ctx->Texture.Enabled) return NULL;
707 if (ctx->Light.ShadeModel!=GL_FLAT) return NULL;
708
709 if (xmesa->xm_buffer->buffer==XIMAGE
710 && ctx->RasterMask==DEPTH_BIT
711 && ctx->Depth.Func==GL_LESS
712 && ctx->Depth.Mask==GL_TRUE
713 && ctx->Line.Width==1.0F
714 && ctx->Line.StippleFlag==GL_FALSE) {
715 switch (xmesa->pixelformat) {
716 case PF_TRUECOLOR:
717 return flat_TRUECOLOR_z_line;
718 case PF_8A8B8G8R:
719 return flat_8A8B8G8R_z_line;
720 case PF_8R8G8B:
721 return flat_8R8G8B_z_line;
722 case PF_5R6G5B:
723 return flat_5R6G5B_z_line;
724 case PF_DITHER:
725 return (depth==8) ? flat_DITHER8_z_line : NULL;
726 case PF_LOOKUP:
727 return (depth==8) ? flat_LOOKUP8_z_line : NULL;
728 case PF_HPCR:
729 return flat_HPCR_z_line;
730 default:
731 return NULL;
732 }
733 }
734 if (xmesa->xm_buffer->buffer==XIMAGE
735 && ctx->RasterMask==0
736 && ctx->Line.Width==1.0F
737 && ctx->Line.StippleFlag==GL_FALSE) {
738 switch (xmesa->pixelformat) {
739 case PF_TRUECOLOR:
740 return flat_TRUECOLOR_line;
741 case PF_8A8B8G8R:
742 return flat_8A8B8G8R_line;
743 case PF_8R8G8B:
744 return flat_8R8G8B_line;
745 case PF_5R6G5B:
746 return flat_5R6G5B_line;
747 case PF_DITHER:
748 return (depth==8) ? flat_DITHER8_line : NULL;
749 case PF_LOOKUP:
750 return (depth==8) ? flat_LOOKUP8_line : NULL;
751 case PF_HPCR:
752 return flat_HPCR_line;
753 default:
754 return NULL;
755 }
756 }
757 if (xmesa->xm_buffer->buffer!=XIMAGE && ctx->RasterMask==0) {
758 setup_x_line_options( ctx );
759 return flat_pixmap_line;
760 }
761 return NULL;
762 }
763
764
765
766
767 /**********************************************************************/
768 /*** Triangle rendering ***/
769 /**********************************************************************/
770
771 /*
772 * Render a triangle into a pixmap, any pixel format, flat shaded and
773 * no raster ops.
774 */
flat_pixmap_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)775 void flat_pixmap_triangle( GLcontext *ctx,
776 GLuint v0, GLuint v1, GLuint v2, GLuint pv )
777 {
778 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
779 struct vertex_buffer *VB = ctx->VB;
780 XPoint p[3];
781 GC gc;
782 if (VB->MonoColor) {
783 gc = xmesa->xm_buffer->gc1; /* use current color */
784 }
785 else {
786 unsigned long pixel;
787 if (xmesa->xm_visual->gl_visual->RGBAflag) {
788 pixel = xmesa_color_to_pixel( xmesa,
789 VB->Color[pv][0], VB->Color[pv][1],
790 VB->Color[pv][2], VB->Color[pv][3] );
791 }
792 else {
793 pixel = VB->Index[pv];
794 }
795 gc = xmesa->xm_buffer->gc2;
796 XSetForeground( xmesa->display, gc, pixel );
797 }
798 p[0].x = (GLint) (VB->Win[v0][0] + 0.5f);
799 p[0].y = FLIP( (GLint) (VB->Win[v0][1] - 0.5f) );
800 p[1].x = (GLint) (VB->Win[v1][0] + 0.5f);
801 p[1].y = FLIP( (GLint) (VB->Win[v1][1] - 0.5f) );
802 p[2].x = (GLint) (VB->Win[v2][0] + 0.5f);
803 p[2].y = FLIP( (GLint) (VB->Win[v2][1] - 0.5f) );
804 XFillPolygon( xmesa->display, xmesa->xm_buffer->buffer, gc,
805 p, 3, Convex, CoordModeOrigin );
806 }
807
808
809
810 /*
811 * XImage, smooth, depth-buffered, PF_TRUECOLOR triangle.
812 */
smooth_TRUECOLOR_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)813 static void smooth_TRUECOLOR_z_triangle( GLcontext *ctx,
814 GLuint v0, GLuint v1, GLuint v2,
815 GLuint pv )
816 {
817 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
818 XImage *img = xmesa->xm_buffer->backimage;
819 #define INTERP_Z 1
820 #define INTERP_RGB 1
821 #define INNER_LOOP( LEFT, RIGHT, Y ) \
822 { \
823 GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
824 for (i=0;i<len;i++,xx++) { \
825 GLdepth z = FixedToDepth(ffz); \
826 if (z < zRow[i]) { \
827 unsigned long p = PACK_RGB( FixedToInt(ffr), FixedToInt(ffg), \
828 FixedToInt(ffb) ); \
829 XPutPixel( img, xx, yy, p ); \
830 zRow[i] = z; \
831 } \
832 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
833 ffz += fdzdx; \
834 } \
835 }
836 #include "tritemp.h"
837 }
838
839
840
841 /*
842 * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
843 */
smooth_8A8B8G8R_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)844 static void smooth_8A8B8G8R_z_triangle( GLcontext *ctx,
845 GLuint v0, GLuint v1, GLuint v2,
846 GLuint pv )
847 {
848 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
849 #define INTERP_Z 1
850 #define INTERP_RGB 1
851 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
852 #define PIXEL_TYPE GLuint
853 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
854 #define INNER_LOOP( LEFT, RIGHT, Y ) \
855 { \
856 GLint i, len = RIGHT-LEFT; \
857 for (i=0;i<len;i++) { \
858 GLdepth z = FixedToDepth(ffz); \
859 if (z < zRow[i]) { \
860 pRow[i] = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
861 FixedToInt(ffb) ); \
862 zRow[i] = z; \
863 } \
864 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
865 ffz += fdzdx; \
866 } \
867 }
868 #include "tritemp.h"
869 }
870
871
872 /*
873 * XImage, smooth, depth-buffered, PF_8R8G8B triangle.
874 */
smooth_8R8G8B_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)875 static void smooth_8R8G8B_z_triangle( GLcontext *ctx,
876 GLuint v0, GLuint v1, GLuint v2,
877 GLuint pv )
878 {
879 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
880 #define INTERP_Z 1
881 #define INTERP_RGB 1
882 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
883 #define PIXEL_TYPE GLuint
884 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
885 #define INNER_LOOP( LEFT, RIGHT, Y ) \
886 { \
887 GLint i, len = RIGHT-LEFT; \
888 for (i=0;i<len;i++) { \
889 GLdepth z = FixedToDepth(ffz); \
890 if (z < zRow[i]) { \
891 pRow[i] = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
892 FixedToInt(ffb) ); \
893 zRow[i] = z; \
894 } \
895 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
896 ffz += fdzdx; \
897 } \
898 }
899 #include "tritemp.h"
900 }
901
902
903
904 /*
905 * XImage, smooth, depth-buffered, PF_5R6G5B triangle.
906 */
smooth_5R6G5B_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)907 static void smooth_5R6G5B_z_triangle( GLcontext *ctx,
908 GLuint v0, GLuint v1, GLuint v2,
909 GLuint pv )
910 {
911 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
912 #define INTERP_Z 1
913 #define INTERP_RGB 1
914 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
915 #define PIXEL_TYPE GLushort
916 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
917 #define INNER_LOOP( LEFT, RIGHT, Y ) \
918 { \
919 GLint i, len = RIGHT-LEFT; \
920 for (i=0;i<len;i++) { \
921 GLdepth z = FixedToDepth(ffz); \
922 if (z < zRow[i]) { \
923 pRow[i] = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
924 FixedToInt(ffb) ); \
925 zRow[i] = z; \
926 } \
927 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
928 ffz += fdzdx; \
929 } \
930 }
931 #include "tritemp.h"
932 }
933
934
935 /*
936 * XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle.
937 */
smooth_DITHER8_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)938 static void smooth_DITHER8_z_triangle( GLcontext *ctx,
939 GLuint v0, GLuint v1, GLuint v2,
940 GLuint pv )
941 {
942 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
943 #define INTERP_Z 1
944 #define INTERP_RGB 1
945 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
946 #define PIXEL_TYPE GLubyte
947 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
948 #define INNER_LOOP( LEFT, RIGHT, Y ) \
949 { \
950 GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
951 XDITHER_SETUP(yy); \
952 for (i=0;i<len;i++,xx++) { \
953 GLdepth z = FixedToDepth(ffz); \
954 if (z < zRow[i]) { \
955 pRow[i] = XDITHER( xx, FixedToInt(ffr), FixedToInt(ffg), \
956 FixedToInt(ffb) ); \
957 zRow[i] = z; \
958 } \
959 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
960 ffz += fdzdx; \
961 } \
962 }
963 #include "tritemp.h"
964 }
965
966
967
968 /*
969 * XImage, smooth, depth-buffered, PF_DITHER triangle.
970 */
smooth_DITHER_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)971 static void smooth_DITHER_z_triangle( GLcontext *ctx,
972 GLuint v0, GLuint v1, GLuint v2,
973 GLuint pv )
974 {
975 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
976 XImage *img = xmesa->xm_buffer->backimage;
977 #define INTERP_Z 1
978 #define INTERP_RGB 1
979 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
980 #define PIXEL_TYPE GLubyte
981 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
982 #define INNER_LOOP( LEFT, RIGHT, Y ) \
983 { \
984 GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
985 XDITHER_SETUP(yy); \
986 for (i=0;i<len;i++,xx++) { \
987 GLdepth z = FixedToDepth(ffz); \
988 if (z < zRow[i]) { \
989 unsigned long p = XDITHER( xx, FixedToInt(ffr), \
990 FixedToInt(ffg), FixedToInt(ffb) ); \
991 XPutPixel( img, xx, yy, p ); \
992 zRow[i] = z; \
993 } \
994 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
995 ffz += fdzdx; \
996 } \
997 }
998 #include "tritemp.h"
999 }
1000
1001
1002 /*
1003 * XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle.
1004 */
smooth_LOOKUP8_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1005 static void smooth_LOOKUP8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1006 GLuint v2, GLuint pv )
1007 {
1008 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1009 #define INTERP_Z 1
1010 #define INTERP_RGB 1
1011 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1012 #define PIXEL_TYPE GLubyte
1013 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1014 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1015 { \
1016 GLint i, len = RIGHT-LEFT; \
1017 LOOKUP_SETUP; \
1018 for (i=0;i<len;i++) { \
1019 GLdepth z = FixedToDepth(ffz); \
1020 if (z < zRow[i]) { \
1021 pRow[i] = LOOKUP( FixedToInt(ffr), FixedToInt(ffg), \
1022 FixedToInt(ffb) ); \
1023 zRow[i] = z; \
1024 } \
1025 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1026 ffz += fdzdx; \
1027 } \
1028 }
1029 #include "tritemp.h"
1030 }
1031
1032
1033
1034 /*
1035 * XImage, smooth, depth-buffered, 8-bit PF_HPCR triangle.
1036 */
smooth_HPCR_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1037 static void smooth_HPCR_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1038 GLuint v2, GLuint pv )
1039 {
1040 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1041 #define INTERP_Z 1
1042 #define INTERP_RGB 1
1043 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1044 #define PIXEL_TYPE GLubyte
1045 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1046 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1047 { \
1048 GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
1049 for (i=0;i<len;i++,xx++) { \
1050 GLdepth z = FixedToDepth(ffz); \
1051 if (z < zRow[i]) { \
1052 pRow[i] = DITHER_HPCR( xx, yy, FixedToInt(ffr), \
1053 FixedToInt(ffg), FixedToInt(ffb) ); \
1054 zRow[i] = z; \
1055 } \
1056 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1057 ffz += fdzdx; \
1058 } \
1059 }
1060 #include "tritemp.h"
1061 }
1062
1063
1064
1065 /*
1066 * XImage, flat, depth-buffered, PF_TRUECOLOR triangle.
1067 */
flat_TRUECOLOR_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1068 static void flat_TRUECOLOR_z_triangle( GLcontext *ctx,
1069 GLuint v0, GLuint v1, GLuint v2,
1070 GLuint pv )
1071 {
1072 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1073 XImage *img = xmesa->xm_buffer->backimage;
1074 #define INTERP_Z 1
1075 #define SETUP_CODE \
1076 unsigned long pixel = PACK_RGB( VB->Color[pv][0], \
1077 VB->Color[pv][1], VB->Color[pv][2] );
1078
1079 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1080 { \
1081 GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
1082 for (i=0;i<len;i++,xx++) { \
1083 GLdepth z = FixedToDepth(ffz); \
1084 if (z < zRow[i]) { \
1085 XPutPixel( img, xx, yy, pixel ); \
1086 zRow[i] = z; \
1087 } \
1088 ffz += fdzdx; \
1089 } \
1090 }
1091 #include "tritemp.h"
1092 }
1093
1094
1095 /*
1096 * XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
1097 */
flat_8A8B8G8R_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1098 static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, GLuint v0,
1099 GLuint v1, GLuint v2, GLuint pv )
1100 {
1101 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1102 #define INTERP_Z 1
1103 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
1104 #define PIXEL_TYPE GLuint
1105 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1106 #define SETUP_CODE \
1107 unsigned long p = PACK_8B8G8R( VB->Color[pv][0], \
1108 VB->Color[pv][1], VB->Color[pv][2] );
1109 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1110 { \
1111 GLint i, len = RIGHT-LEFT; \
1112 for (i=0;i<len;i++) { \
1113 GLdepth z = FixedToDepth(ffz); \
1114 if (z < zRow[i]) { \
1115 pRow[i] = p; \
1116 zRow[i] = z; \
1117 } \
1118 ffz += fdzdx; \
1119 } \
1120 }
1121 #include "tritemp.h"
1122 }
1123
1124
1125 /*
1126 * XImage, flat, depth-buffered, PF_8R8G8B triangle.
1127 */
flat_8R8G8B_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1128 static void flat_8R8G8B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1129 GLuint v2, GLuint pv )
1130 {
1131 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1132 #define INTERP_Z 1
1133 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
1134 #define PIXEL_TYPE GLuint
1135 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1136 #define SETUP_CODE \
1137 unsigned long p = PACK_8R8G8B( VB->Color[pv][0], \
1138 VB->Color[pv][1], VB->Color[pv][2] );
1139 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1140 { \
1141 GLint i, len = RIGHT-LEFT; \
1142 for (i=0;i<len;i++) { \
1143 GLdepth z = FixedToDepth(ffz); \
1144 if (z < zRow[i]) { \
1145 pRow[i] = p; \
1146 zRow[i] = z; \
1147 } \
1148 ffz += fdzdx; \
1149 } \
1150 }
1151 #include "tritemp.h"
1152 }
1153
1154
1155 /*
1156 * XImage, flat, depth-buffered, PF_5R6G5B triangle.
1157 */
flat_5R6G5B_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1158 static void flat_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1159 GLuint v2, GLuint pv )
1160 {
1161 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1162 #define INTERP_Z 1
1163 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
1164 #define PIXEL_TYPE GLushort
1165 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1166 #define SETUP_CODE \
1167 unsigned long p = PACK_5R6G5B( VB->Color[pv][0], \
1168 VB->Color[pv][1], VB->Color[pv][2] );
1169 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1170 { \
1171 GLint i, len = RIGHT-LEFT; \
1172 for (i=0;i<len;i++) { \
1173 GLdepth z = FixedToDepth(ffz); \
1174 if (z < zRow[i]) { \
1175 pRow[i] = p; \
1176 zRow[i] = z; \
1177 } \
1178 ffz += fdzdx; \
1179 } \
1180 }
1181 #include "tritemp.h"
1182 }
1183
1184
1185 /*
1186 * XImage, flat, depth-buffered, 8-bit PF_DITHER triangle.
1187 */
flat_DITHER8_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1188 static void flat_DITHER8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1189 GLuint v2, GLuint pv )
1190 {
1191 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1192 #define INTERP_Z 1
1193 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1194 #define PIXEL_TYPE GLubyte
1195 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1196 #define SETUP_CODE \
1197 FLAT_DITHER_SETUP( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2] );
1198
1199 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1200 { \
1201 GLint i, xx = LEFT, len = RIGHT-LEFT; \
1202 FLAT_DITHER_ROW_SETUP(FLIP(Y)); \
1203 for (i=0;i<len;i++,xx++) { \
1204 GLdepth z = FixedToDepth(ffz); \
1205 if (z < zRow[i]) { \
1206 pRow[i] = FLAT_DITHER(xx); \
1207 zRow[i] = z; \
1208 } \
1209 ffz += fdzdx; \
1210 } \
1211 }
1212 #include "tritemp.h"
1213 }
1214
1215
1216 /*
1217 * XImage, flat, depth-buffered, PF_DITHER triangle.
1218 */
flat_DITHER_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1219 static void flat_DITHER_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1220 GLuint v2, GLuint pv )
1221 {
1222 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1223 XImage *img = xmesa->xm_buffer->backimage;
1224 #define INTERP_Z 1
1225 #define SETUP_CODE \
1226 FLAT_DITHER_SETUP( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2] );
1227
1228 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1229 { \
1230 GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
1231 FLAT_DITHER_ROW_SETUP(yy); \
1232 for (i=0;i<len;i++,xx++) { \
1233 GLdepth z = FixedToDepth(ffz); \
1234 if (z < zRow[i]) { \
1235 unsigned long p = FLAT_DITHER(xx); \
1236 XPutPixel( img, xx, yy, p ); \
1237 zRow[i] = z; \
1238 } \
1239 ffz += fdzdx; \
1240 } \
1241 }
1242 #include "tritemp.h"
1243 }
1244
1245
1246 /*
1247 * XImage, flat, depth-buffered, 8-bit PF_HPCR triangle.
1248 */
flat_HPCR_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1249 static void flat_HPCR_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1250 GLuint v2, GLuint pv )
1251 {
1252 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1253 #define INTERP_Z 1
1254 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1255 #define PIXEL_TYPE GLubyte
1256 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1257 #define SETUP_CODE \
1258 GLubyte r = VB->Color[pv][0]; \
1259 GLubyte g = VB->Color[pv][1]; \
1260 GLubyte b = VB->Color[pv][2];
1261 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1262 { \
1263 GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
1264 for (i=0;i<len;i++,xx++) { \
1265 GLdepth z = FixedToDepth(ffz); \
1266 if (z < zRow[i]) { \
1267 pRow[i] = DITHER_HPCR( xx, yy, r, g, b ); \
1268 zRow[i] = z; \
1269 } \
1270 ffz += fdzdx; \
1271 } \
1272 }
1273 #include "tritemp.h"
1274 }
1275
1276
1277
1278 /*
1279 * XImage, flat, depth-buffered, 8-bit PF_LOOKUP triangle.
1280 */
flat_LOOKUP8_z_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1281 static void flat_LOOKUP8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1282 GLuint v2, GLuint pv )
1283 {
1284 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1285 #define INTERP_Z 1
1286 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1287 #define PIXEL_TYPE GLubyte
1288 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1289 #define SETUP_CODE \
1290 LOOKUP_SETUP; \
1291 GLubyte r = VB->Color[pv][0]; \
1292 GLubyte g = VB->Color[pv][1]; \
1293 GLubyte b = VB->Color[pv][2]; \
1294 GLubyte p = LOOKUP(r,g,b);
1295 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1296 { \
1297 GLint i, len = RIGHT-LEFT; \
1298 for (i=0;i<len;i++) { \
1299 GLdepth z = FixedToDepth(ffz); \
1300 if (z < zRow[i]) { \
1301 pRow[i] = p; \
1302 zRow[i] = z; \
1303 } \
1304 ffz += fdzdx; \
1305 } \
1306 }
1307 #include "tritemp.h"
1308 }
1309
1310
1311
1312 /*
1313 * XImage, smooth, NON-depth-buffered, PF_TRUECOLOR triangle.
1314 */
smooth_TRUECOLOR_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1315 static void smooth_TRUECOLOR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1316 GLuint v2, GLuint pv )
1317 {
1318 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1319 XImage *img = xmesa->xm_buffer->backimage;
1320 #define INTERP_RGB 1
1321 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1322 { \
1323 GLint xx, yy = FLIP(Y); \
1324 for (xx=LEFT;xx<RIGHT;xx++) { \
1325 unsigned long p = PACK_RGB( FixedToInt(ffr), FixedToInt(ffg), \
1326 FixedToInt(ffb) ); \
1327 XPutPixel( img, xx, yy, p ); \
1328 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1329 } \
1330 }
1331 #include "tritemp.h"
1332 }
1333
1334
1335 /*
1336 * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
1337 */
smooth_8A8B8G8R_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1338 static void smooth_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1339 GLuint v2, GLuint pv )
1340 {
1341 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1342 #define INTERP_RGB 1
1343 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
1344 #define PIXEL_TYPE GLuint
1345 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1346 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1347 { \
1348 GLint xx; \
1349 PIXEL_TYPE *pixel = pRow; \
1350 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1351 *pixel = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
1352 FixedToInt(ffb) ); \
1353 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1354 } \
1355 }
1356 #include "tritemp.h"
1357 }
1358
1359
1360 /*
1361 * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
1362 */
smooth_8R8G8B_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1363 static void smooth_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1364 GLuint v2, GLuint pv )
1365 {
1366 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1367 #define INTERP_RGB 1
1368 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
1369 #define PIXEL_TYPE GLuint
1370 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1371 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1372 { \
1373 GLint xx; \
1374 PIXEL_TYPE *pixel = pRow; \
1375 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1376 *pixel = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
1377 FixedToInt(ffb) ); \
1378 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1379 } \
1380 }
1381 #include "tritemp.h"
1382 }
1383
1384
1385 /*
1386 * XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
1387 */
smooth_5R6G5B_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1388 static void smooth_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1389 GLuint v2, GLuint pv )
1390 {
1391 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1392 #define INTERP_RGB 1
1393 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
1394 #define PIXEL_TYPE GLushort
1395 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1396 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1397 { \
1398 GLint xx; \
1399 PIXEL_TYPE *pixel = pRow; \
1400 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1401 *pixel = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
1402 FixedToInt(ffb) ); \
1403 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1404 } \
1405 }
1406 #include "tritemp.h"
1407 }
1408
1409
1410 /*
1411 * XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER triangle.
1412 */
smooth_DITHER8_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1413 static void smooth_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1414 GLuint v2, GLuint pv )
1415 {
1416 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1417 #define INTERP_RGB 1
1418 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1419 #define PIXEL_TYPE GLubyte
1420 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1421 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1422 { \
1423 GLint xx, yy = FLIP(Y); \
1424 PIXEL_TYPE *pixel = pRow; \
1425 XDITHER_SETUP(yy); \
1426 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1427 *pixel = XDITHER( xx, FixedToInt(ffr), FixedToInt(ffg), \
1428 FixedToInt(ffb) ); \
1429 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1430 } \
1431 }
1432 #include "tritemp.h"
1433 }
1434
1435
1436 /*
1437 * XImage, smooth, NON-depth-buffered, PF_DITHER triangle.
1438 */
smooth_DITHER_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1439 static void smooth_DITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1440 GLuint v2, GLuint pv )
1441 {
1442 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1443 XImage *img = xmesa->xm_buffer->backimage;
1444 #define INTERP_RGB 1
1445 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1446 { \
1447 GLint xx, yy = FLIP(Y); \
1448 XDITHER_SETUP(yy); \
1449 for (xx=LEFT;xx<RIGHT;xx++) { \
1450 unsigned long p = XDITHER( xx, FixedToInt(ffr), \
1451 FixedToInt(ffg), FixedToInt(ffb) ); \
1452 XPutPixel( img, xx, yy, p ); \
1453 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1454 } \
1455 }
1456 #include "tritemp.h"
1457 }
1458
1459
1460 /*
1461 * XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
1462 */
smooth_LOOKUP8_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1463 static void smooth_LOOKUP8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1464 GLuint v2, GLuint pv )
1465 {
1466 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1467 #define INTERP_RGB 1
1468 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1469 #define PIXEL_TYPE GLubyte
1470 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1471 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1472 { \
1473 GLint xx; \
1474 PIXEL_TYPE *pixel = pRow; \
1475 LOOKUP_SETUP; \
1476 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1477 *pixel = LOOKUP( FixedToInt(ffr), FixedToInt(ffg), \
1478 FixedToInt(ffb) ); \
1479 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1480 } \
1481 }
1482 #include "tritemp.h"
1483 }
1484
1485
1486
1487 /*
1488 * XImage, smooth, NON-depth-buffered, 8-bit PF_HPCR triangle.
1489 */
smooth_HPCR_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1490 static void smooth_HPCR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1491 GLuint v2, GLuint pv )
1492 {
1493 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1494 #define INTERP_RGB 1
1495 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1496 #define PIXEL_TYPE GLubyte
1497 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1498 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1499 { \
1500 GLint xx, yy = FLIP(Y); \
1501 PIXEL_TYPE *pixel = pRow; \
1502 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1503 *pixel = DITHER_HPCR( xx, yy, FixedToInt(ffr), \
1504 FixedToInt(ffg), FixedToInt(ffb) ); \
1505 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
1506 } \
1507 }
1508 #include "tritemp.h"
1509 }
1510
1511
1512 /*
1513 * XImage, flat, NON-depth-buffered, PF_TRUECOLOR triangle.
1514 */
flat_TRUECOLOR_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1515 static void flat_TRUECOLOR_triangle( GLcontext *ctx, GLuint v0,
1516 GLuint v1, GLuint v2, GLuint pv )
1517 {
1518 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1519 XImage *img = xmesa->xm_buffer->backimage;
1520 #define SETUP_CODE \
1521 unsigned long pixel = PACK_RGB( VB->Color[pv][0], \
1522 VB->Color[pv][1], VB->Color[pv][2] );
1523 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1524 { \
1525 GLint xx, yy = FLIP(Y); \
1526 for (xx=LEFT;xx<RIGHT;xx++) { \
1527 XPutPixel( img, xx, yy, pixel ); \
1528 } \
1529 }
1530 #include "tritemp.h"
1531 }
1532
1533
1534 /*
1535 * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
1536 */
flat_8A8B8G8R_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1537 static void flat_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0,
1538 GLuint v1, GLuint v2, GLuint pv )
1539 {
1540 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1541 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
1542 #define PIXEL_TYPE GLuint
1543 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1544 #define SETUP_CODE \
1545 unsigned long p = PACK_8B8G8R( VB->Color[pv][0], \
1546 VB->Color[pv][1], VB->Color[pv][2] );
1547 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1548 { \
1549 GLint xx; \
1550 PIXEL_TYPE *pixel = pRow; \
1551 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1552 *pixel = p; \
1553 } \
1554 }
1555 #include "tritemp.h"
1556 }
1557
1558
1559 /*
1560 * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
1561 */
flat_8R8G8B_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1562 static void flat_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1563 GLuint v2, GLuint pv )
1564 {
1565 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1566 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
1567 #define PIXEL_TYPE GLuint
1568 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1569 #define SETUP_CODE \
1570 unsigned long p = PACK_8R8G8B( VB->Color[pv][0], \
1571 VB->Color[pv][1], VB->Color[pv][2] );
1572 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1573 { \
1574 GLint xx; \
1575 PIXEL_TYPE *pixel = pRow; \
1576 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1577 *pixel = p; \
1578 } \
1579 }
1580 #include "tritemp.h"
1581 }
1582
1583
1584 /*
1585 * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
1586 */
flat_5R6G5B_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1587 static void flat_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1588 GLuint v2, GLuint pv )
1589 {
1590 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1591 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
1592 #define PIXEL_TYPE GLushort
1593 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1594 #define SETUP_CODE \
1595 unsigned long p = PACK_5R6G5B( VB->Color[pv][0], \
1596 VB->Color[pv][1], VB->Color[pv][2] );
1597 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1598 { \
1599 GLint xx; \
1600 PIXEL_TYPE *pixel = pRow; \
1601 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1602 *pixel = p; \
1603 } \
1604 }
1605 #include "tritemp.h"
1606 }
1607
1608
1609 /*
1610 * XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
1611 */
flat_DITHER8_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1612 static void flat_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1613 GLuint v2, GLuint pv )
1614 {
1615 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1616 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1617 #define PIXEL_TYPE GLubyte
1618 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1619 #define SETUP_CODE \
1620 FLAT_DITHER_SETUP( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2] );
1621
1622 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1623 { \
1624 GLint xx; \
1625 PIXEL_TYPE *pixel = pRow; \
1626 FLAT_DITHER_ROW_SETUP(FLIP(Y)); \
1627 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1628 *pixel = FLAT_DITHER(xx); \
1629 } \
1630 }
1631 #include "tritemp.h"
1632 }
1633
1634
1635 /*
1636 * XImage, flat, NON-depth-buffered, PF_DITHER triangle.
1637 */
flat_DITHER_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1638 static void flat_DITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1639 GLuint v2, GLuint pv )
1640 {
1641 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1642 XImage *img = xmesa->xm_buffer->backimage;
1643 #define SETUP_CODE \
1644 FLAT_DITHER_SETUP( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2] );
1645
1646 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1647 { \
1648 GLint xx, yy = FLIP(Y); \
1649 FLAT_DITHER_ROW_SETUP(yy); \
1650 for (xx=LEFT;xx<RIGHT;xx++) { \
1651 unsigned long p = FLAT_DITHER(xx); \
1652 XPutPixel( img, xx, yy, p ); \
1653 } \
1654 }
1655 #include "tritemp.h"
1656 }
1657
1658
1659 /*
1660 * XImage, flat, NON-depth-buffered, 8-bit PF_HPCR triangle.
1661 */
flat_HPCR_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1662 static void flat_HPCR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1663 GLuint v2, GLuint pv )
1664 {
1665 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1666 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1667 #define PIXEL_TYPE GLubyte
1668 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1669 #define SETUP_CODE \
1670 GLubyte r = VB->Color[pv][0]; \
1671 GLubyte g = VB->Color[pv][1]; \
1672 GLubyte b = VB->Color[pv][2];
1673 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1674 { \
1675 GLint xx, yy = FLIP(Y); \
1676 PIXEL_TYPE *pixel = pRow; \
1677 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1678 *pixel = DITHER_HPCR( xx, yy, r, g, b ); \
1679 } \
1680 }
1681 #include "tritemp.h"
1682 }
1683
1684
1685 /*
1686 * XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
1687 */
flat_LOOKUP8_triangle(GLcontext * ctx,GLuint v0,GLuint v1,GLuint v2,GLuint pv)1688 static void flat_LOOKUP8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
1689 GLuint v2, GLuint pv )
1690 {
1691 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1692 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
1693 #define PIXEL_TYPE GLubyte
1694 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
1695 #define SETUP_CODE \
1696 LOOKUP_SETUP; \
1697 GLubyte r = VB->Color[pv][0]; \
1698 GLubyte g = VB->Color[pv][1]; \
1699 GLubyte b = VB->Color[pv][2]; \
1700 GLubyte p = LOOKUP(r,g,b);
1701 #define INNER_LOOP( LEFT, RIGHT, Y ) \
1702 { \
1703 GLint xx; \
1704 PIXEL_TYPE *pixel = pRow; \
1705 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
1706 *pixel = p; \
1707 } \
1708 }
1709 #include "tritemp.h"
1710 }
1711
1712
1713
1714
1715 /*
1716 * This function is called if we're about to render triangles into an
1717 * X window/pixmap. It sets the polygon stipple pattern if enabled.
1718 */
setup_x_polygon_options(GLcontext * ctx)1719 static void setup_x_polygon_options( GLcontext *ctx )
1720 {
1721 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1722 int fill_type;
1723
1724 if (ctx->Polygon.StippleFlag) {
1725 /*
1726 * Allocate polygon stippling stuff once for this context.
1727 */
1728 if (xmesa->xm_buffer->stipple_pixmap == 0) {
1729 XGCValues values;
1730 XMesaBuffer b = xmesa->xm_buffer;
1731 b->stipple_pixmap = XCreatePixmap( xmesa->display,
1732 b->buffer, 32, 32, 1 );
1733 values.function = GXcopy;
1734 values.foreground = 1;
1735 values.background = 0;
1736 b->stipple_gc = XCreateGC( xmesa->display, b->stipple_pixmap,
1737 (GCFunction|GCForeground|GCBackground),
1738 &values );
1739 b->stipple_ximage = XCreateImage( xmesa->display,
1740 xmesa->xm_visual->visinfo->visual,
1741 1, ZPixmap, 0,
1742 (char *)ctx->PolygonStipple,
1743 32, 32, 8, 0 );
1744 b->stipple_ximage->byte_order = LSBFirst;
1745 b->stipple_ximage->bitmap_bit_order = LSBFirst;
1746 b->stipple_ximage->bitmap_unit = 32;
1747 }
1748
1749 /*
1750 * NOTE: We don't handle the following here!
1751 * GL_UNPACK_SWAP_BYTES
1752 * GL_UNPACK_LSB_FIRST
1753 */
1754 XPutImage( xmesa->display,
1755 xmesa->xm_buffer->stipple_pixmap,
1756 xmesa->xm_buffer->stipple_gc,
1757 xmesa->xm_buffer->stipple_ximage, 0, 0, 0, 0, 32, 32 );
1758 XSetStipple( xmesa->display, xmesa->xm_buffer->gc1,
1759 xmesa->xm_buffer->stipple_pixmap );
1760 XSetStipple( xmesa->display, xmesa->xm_buffer->gc2,
1761 xmesa->xm_buffer->stipple_pixmap );
1762 fill_type = FillStippled;
1763 }
1764 else {
1765 fill_type = FillSolid;
1766 }
1767
1768 XSetFillStyle( xmesa->display, xmesa->xm_buffer->gc1, fill_type );
1769 XSetFillStyle( xmesa->display, xmesa->xm_buffer->gc2, fill_type );
1770 }
1771
1772
1773
xmesa_get_triangle_func(GLcontext * ctx)1774 triangle_func xmesa_get_triangle_func( GLcontext *ctx )
1775 {
1776 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
1777 int depth = xmesa->xm_visual->visinfo->depth;
1778
1779 if (ctx->Polygon.SmoothFlag) return NULL;
1780 if (ctx->Texture.Enabled) return NULL;
1781
1782 if (xmesa->xm_buffer->buffer==XIMAGE) {
1783 if ( ctx->Light.ShadeModel==GL_SMOOTH
1784 && ctx->RasterMask==DEPTH_BIT
1785 && ctx->Depth.Func==GL_LESS
1786 && ctx->Depth.Mask==GL_TRUE
1787 && ctx->Polygon.StippleFlag==GL_FALSE) {
1788 switch (xmesa->pixelformat) {
1789 case PF_TRUECOLOR:
1790 return smooth_TRUECOLOR_z_triangle;
1791 case PF_8A8B8G8R:
1792 return smooth_8A8B8G8R_z_triangle;
1793 case PF_8R8G8B:
1794 return smooth_8R8G8B_z_triangle;
1795 case PF_5R6G5B:
1796 return smooth_5R6G5B_z_triangle;
1797 case PF_HPCR:
1798 return smooth_HPCR_z_triangle;
1799 case PF_DITHER:
1800 return (depth==8) ? smooth_DITHER8_z_triangle
1801 : smooth_DITHER_z_triangle;
1802 case PF_LOOKUP:
1803 return (depth==8) ? smooth_LOOKUP8_z_triangle : NULL;
1804 default:
1805 return NULL;
1806 }
1807 }
1808 if ( ctx->Light.ShadeModel==GL_FLAT
1809 && ctx->RasterMask==DEPTH_BIT
1810 && ctx->Depth.Func==GL_LESS
1811 && ctx->Depth.Mask==GL_TRUE
1812 && ctx->Polygon.StippleFlag==GL_FALSE) {
1813 switch (xmesa->pixelformat) {
1814 case PF_TRUECOLOR:
1815 return flat_TRUECOLOR_z_triangle;
1816 case PF_8A8B8G8R:
1817 return flat_8A8B8G8R_z_triangle;
1818 case PF_8R8G8B:
1819 return flat_8R8G8B_z_triangle;
1820 case PF_5R6G5B:
1821 return flat_5R6G5B_z_triangle;
1822 case PF_HPCR:
1823 return flat_HPCR_z_triangle;
1824 case PF_DITHER:
1825 return (depth==8) ? flat_DITHER8_z_triangle
1826 : flat_DITHER_z_triangle;
1827 case PF_LOOKUP:
1828 return (depth==8) ? flat_LOOKUP8_z_triangle : NULL;
1829 default:
1830 return NULL;
1831 }
1832 }
1833 if ( ctx->RasterMask==0 /* no depth test */
1834 && ctx->Light.ShadeModel==GL_SMOOTH
1835 && ctx->Polygon.StippleFlag==GL_FALSE) {
1836 switch (xmesa->pixelformat) {
1837 case PF_TRUECOLOR:
1838 return smooth_TRUECOLOR_triangle;
1839 case PF_8A8B8G8R:
1840 return smooth_8A8B8G8R_triangle;
1841 case PF_8R8G8B:
1842 return smooth_8R8G8B_triangle;
1843 case PF_5R6G5B:
1844 return smooth_5R6G5B_triangle;
1845 case PF_HPCR:
1846 return smooth_HPCR_triangle;
1847 case PF_DITHER:
1848 return (depth==8) ? smooth_DITHER8_triangle
1849 : smooth_DITHER_triangle;
1850 case PF_LOOKUP:
1851 return (depth==8) ? smooth_LOOKUP8_triangle : NULL;
1852 default:
1853 return NULL;
1854 }
1855 }
1856
1857 if ( ctx->RasterMask==0 /* no depth test */
1858 && ctx->Light.ShadeModel==GL_FLAT
1859 && ctx->Polygon.StippleFlag==GL_FALSE) {
1860 switch (xmesa->pixelformat) {
1861 case PF_TRUECOLOR:
1862 return flat_TRUECOLOR_triangle;
1863 case PF_8A8B8G8R:
1864 return flat_8A8B8G8R_triangle;
1865 case PF_8R8G8B:
1866 return flat_8R8G8B_triangle;
1867 case PF_5R6G5B:
1868 return flat_5R6G5B_triangle;
1869 case PF_HPCR:
1870 return flat_HPCR_triangle;
1871 case PF_DITHER:
1872 return (depth==8) ? flat_DITHER8_triangle
1873 : flat_DITHER_triangle;
1874 case PF_LOOKUP:
1875 return (depth==8) ? flat_LOOKUP8_triangle : NULL;
1876 default:
1877 return NULL;
1878 }
1879 }
1880
1881 return NULL;
1882 }
1883 else {
1884 /* pixmap */
1885 if (ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0) {
1886 setup_x_polygon_options( ctx );
1887 return flat_pixmap_triangle;
1888 }
1889 return NULL;
1890 }
1891 }
1892
1893 #endif
1894