home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / src / xmesa3.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  45KB  |  1,735 lines

  1. /* $Id: xmesa3.c,v 1.25 1996/04/09 19:05:55 billh Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995-1996  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Log: xmesa3.c,v $
  26.  * Revision 1.25  1996/04/09  19:05:55  billh
  27.  * added a cast to line drawing functions to stop warning on Sun's compiler
  28.  *
  29.  * Revision 1.24  1996/03/22  20:56:03  brianp
  30.  * removed CC.ClipSpans stuff
  31.  *
  32.  * Revision 1.23  1996/03/05  19:52:37  brianp
  33.  * Set GC line width to 0, not 1, for best performance
  34.  *
  35.  * Revision 1.22  1996/03/02  21:41:05  brianp
  36.  * added PF_8R8G8B pixel format
  37.  *
  38.  * Revision 1.21  1996/03/01  20:07:27  brianp
  39.  * added optimized polygon rasterizers for non-depth-buffered rendering
  40.  *
  41.  * Revision 1.20  1996/02/26  16:23:09  brianp
  42.  * added PF_5R6G5B pixel format from Joerg Hessdoerfer
  43.  *
  44.  * Revision 1.19  1996/02/23  17:13:54  brianp
  45.  * cleaned up inner loops of polygon drawing functions
  46.  *
  47.  * Revision 1.18  1996/02/16  16:39:35  brianp
  48.  * let wide lines be drawn by XDrawLine, suggested by Michael Pichler
  49.  *
  50.  * Revision 1.17  1996/02/06  03:25:22  brianp
  51.  * removed #include "gamma.h"
  52.  *
  53.  * Revision 1.16  1996/01/26  20:32:25  brianp
  54.  * use CC.ColorShift in encode_color()
  55.  *
  56.  * Revision 1.16  1996/01/26  20:32:25  brianp
  57.  * use CC.ColorShift in encode_color()
  58.  *
  59.  * Revision 1.15  1996/01/12  22:31:43  brianp
  60.  * added simple window clipping to line drawing functions
  61.  *
  62.  * Revision 1.14  1996/01/11  22:53:29  brianp
  63.  * added more flat-shaded line drawing functions
  64.  *
  65.  * Revision 1.13  1996/01/10  22:36:25  brianp
  66.  * made back XImage one pixel wider and higher than window
  67.  * added more line drawing functions
  68.  *
  69.  * Revision 1.12  1996/01/05  01:16:52  brianp
  70.  * added flat_LOOKUP8_z_polygon
  71.  *
  72.  * Revision 1.11  1996/01/02  22:12:40  brianp
  73.  * added flat TRUECOLOR and HPCR polygon functions
  74.  * removed old fixed-point macros
  75.  *
  76.  * Revision 1.10  1995/12/30  01:06:09  brianp
  77.  * use fixed point vertex colors instead of floating point
  78.  * added several flat-shaded polygon functions
  79.  * use renamed DITHER macro
  80.  *
  81.  * Revision 1.8  1995/12/07  17:05:06  brianp
  82.  * faster color interpolation by removing some bit shifting
  83.  *
  84.  * Revision 1.7  1995/11/30  00:21:36  brianp
  85.  * added PF_GRAYSCALE support
  86.  *
  87.  * Revision 1.6  1995/11/14  21:49:09  brianp
  88.  * optimized polygon rendering setup
  89.  *
  90.  * Revision 1.5  1995/11/08  22:08:22  brianp
  91.  * fixed OFFSET4/1 bug in smooth_rgba_z_polygon_ximage()
  92.  *
  93.  * Revision 1.4  1995/11/04  20:09:32  brianp
  94.  * added F suffix to floating point constants
  95.  * replaced incorrect 0.05F with 0.5F
  96.  *
  97.  * Revision 1.3  1995/11/03  17:41:48  brianp
  98.  * removed unused vars, fixed code for C++ compilation
  99.  *
  100.  * Revision 1.2  1995/10/30  15:50:41  brianp
  101.  * make sure CC.ClipSpans is FALSE before using smooth_rgba_z_polygon_ximage
  102.  *
  103.  * Revision 1.1  1995/10/30  15:15:15  brianp
  104.  * Initial revision
  105.  *
  106.  */
  107.  
  108.  
  109. /*
  110.  * Mesa/X11 interface, part 3.
  111.  *
  112.  * This file contains "accelerated" point, line, and polygon functions.
  113.  * It should be fairly easy to write new special-purpose point, line or
  114.  * polygon functions and hook them into this module.
  115.  */
  116.  
  117.  
  118.  
  119. #include <sys/time.h>
  120. #include <assert.h>
  121.  
  122.  
  123. #include <stdlib.h>
  124. #include <stdio.h>
  125. #include "X11/Xlib.h"
  126. #include "bresenhm.h"
  127. #include "context.h"
  128. #include "depth.h"
  129. #include "dd.h"
  130. #include "interp.h"
  131. #include "macros.h"
  132. #include "polygons.h"
  133. #include "vb.h"
  134. #include "xmesaP.h"
  135.  
  136.  
  137. /*
  138.  * Like PACK_8A8B8G8R() but don't use alpha.  This is usually an acceptable
  139.  * shortcut.  If alpha is needed the MESA_ALPHA environment variable
  140.  * should be defined as would be needed for any other visual type.
  141.  */
  142. #define PACK_8B8G8R( R, G, B )   ( ((B) << 16) | ((G) << 8) | (R) )
  143.  
  144.  
  145.  
  146. /*
  147.  * Given a vertex number return the X pixel value for that vertex's color.
  148.  * Note that if smooth shading is enabled we have to convert the vertex
  149.  * colors from fixed point to integers by shifting by CC.ColorShift bits.
  150.  */
  151. static unsigned long encode_color( GLuint i )
  152. {
  153.    switch (XMesa->pixelformat) {
  154.       case PF_INDEX:
  155.          return (unsigned long) VB.Index[i];
  156.       case PF_TRUECOLOR:
  157.          {
  158.             register int r, g, b;
  159.             int shift = CC.ColorShift;
  160.             r = VB.Color[i][0] >> shift;
  161.             g = VB.Color[i][1] >> shift;
  162.             b = VB.Color[i][2] >> shift;
  163.             return PACK_RGB( r, g, b );
  164.          }
  165.       case PF_8A8B8G8R:
  166.          {
  167.             register int r, g, b, a;
  168.             int shift = CC.ColorShift;
  169.             r = VB.Color[i][0] >> shift;
  170.             g = VB.Color[i][1] >> shift;
  171.             b = VB.Color[i][2] >> shift;
  172.             a = VB.Color[i][3] >> shift;
  173.             return PACK_8A8B8G8R( r, g, b, a );
  174.          }
  175.       case PF_8R8G8B:
  176.          {
  177.             register int r, g, b;
  178.             int shift = CC.ColorShift;
  179.             r = VB.Color[i][0] >> shift;
  180.             g = VB.Color[i][1] >> shift;
  181.             b = VB.Color[i][2] >> shift;
  182.             return PACK_8R8G8B( r, g, b );
  183.          }
  184.       case PF_5R6G5B:
  185.          {
  186.             register int r, g, b;
  187.             int shift = CC.ColorShift;
  188.             r = VB.Color[i][0] >> shift;
  189.             g = VB.Color[i][1] >> shift;
  190.             b = VB.Color[i][2] >> shift;
  191.             return PACK_5R6G5B( r, g, b );
  192.          }
  193.       case PF_DITHER:
  194.          {
  195.             register int r, g, b;
  196.             int shift = CC.ColorShift;
  197.             r = VB.Color[i][0] >> shift;
  198.             g = VB.Color[i][1] >> shift;
  199.             b = VB.Color[i][2] >> shift;
  200.             return DITHER( 0, 0, r, g, b );
  201.          }
  202.       case PF_LOOKUP:
  203.          {
  204.             register int r, g, b;
  205.             int shift = CC.ColorShift;
  206.             r = VB.Color[i][0] >> shift;
  207.             g = VB.Color[i][1] >> shift;
  208.             b = VB.Color[i][2] >> shift;
  209.             return LOOKUP( r, g, b );
  210.          }
  211.       case PF_HPCR:
  212.          {
  213.             register int r, g, b;
  214.             int shift = CC.ColorShift;
  215.             r = VB.Color[i][0] >> shift;
  216.             g = VB.Color[i][1] >> shift;
  217.             b = VB.Color[i][2] >> shift;
  218.             return DITHER_HPCR( 1, 1, r, g, b );
  219.          }
  220.       case PF_1BIT:
  221.          {
  222.             register int r, g, b;
  223.             int shift = CC.ColorShift;
  224.             r = VB.Color[i][0] >> shift;
  225.             g = VB.Color[i][1] >> shift;
  226.             b = VB.Color[i][2] >> shift;
  227.             return (r+g+b) > 382;
  228.          }
  229.       case PF_GRAYSCALE:
  230.          {
  231.             register int r, g, b;
  232.             int shift = CC.ColorShift;
  233.             r = VB.Color[i][0] >> shift;
  234.             g = VB.Color[i][1] >> shift;
  235.             b = VB.Color[i][2] >> shift;
  236.             return GRAY_RGB( r, g, b );
  237.          }
  238.       default:
  239.          abort();
  240.    }
  241.    return 0;
  242. }
  243.  
  244.  
  245.  
  246. /**********************************************************************/
  247. /***                    Point rendering                             ***/
  248. /**********************************************************************/
  249.  
  250.  
  251. /*
  252.  * Render an array of points into a pixmap, any pixel format.
  253.  */
  254. static void draw_points_ANY_pixmap( GLuint first, GLuint last )
  255. {
  256.    register GLuint i;
  257.    if (VB.MonoColor) {
  258.       /* all same color */
  259.       XPoint p[VB_SIZE];
  260.       int n = 0;
  261.       for (i=first;i<=last;i++) {
  262.          if (VB.Unclipped[i]) {
  263.             p[n].x =       (GLint) VB.Win[i][0];
  264.             p[n].y = FLIP( (GLint) VB.Win[i][1] );
  265.             n++;
  266.          }
  267.       }
  268.       XDrawPoints( XMesa->display, XMesa->buffer, XMesa->gc1, p, n,
  269.                    CoordModeOrigin );
  270.    }
  271.    else {
  272.       /* all different colors */
  273.       for (i=first;i<=last;i++) {
  274.          if (VB.Unclipped[i]) {
  275.             register int x, y;
  276.             XSetForeground( XMesa->display, XMesa->gc2, encode_color(i) );
  277.             x =       (GLint) VB.Win[i][0];
  278.             y = FLIP( (GLint) VB.Win[i][1] );
  279.             XDrawPoint( XMesa->display, XMesa->buffer, XMesa->gc2, x, y);
  280.          }
  281.       }
  282.    }
  283. }
  284.  
  285.  
  286.  
  287. /*
  288.  * Analyze current CC state to see if we can provide a fast points drawing
  289.  * function, like those in points.c.  Otherwise, return NULL.
  290.  */
  291. points_func xmesa_get_points_func( void )
  292. {
  293.    if (CC.Point.Size==1.0F && !CC.Point.SmoothFlag && CC.RasterMask==0
  294.        && !CC.Texture.Enabled) {
  295.       if (XMesa->buffer==XIMAGE) {
  296.          return NULL; /*draw_points_ximage;*/
  297.       }
  298.       else {
  299.          return draw_points_ANY_pixmap;
  300.       }
  301.    }
  302.    else {
  303.       return NULL;
  304.    }
  305. }
  306.  
  307.  
  308.  
  309. /**********************************************************************/
  310. /***                      Line rendering                            ***/
  311. /**********************************************************************/
  312.  
  313. /*
  314.  * Render a line into a pixmap, any pixel format.
  315.  */
  316. static void flat_line_pixmap( GLuint v0, GLuint v1, GLuint pv )
  317. {
  318.    register int x0, y0, x1, y1;
  319.    GC gc;
  320.    if (VB.MonoColor) {
  321.       gc = XMesa->gc1;  /* use current color */
  322.    }
  323.    else {
  324.       gc = XMesa->gc2;
  325.       XSetForeground( XMesa->display, XMesa->gc2, encode_color(pv) );
  326.    }
  327.    x0 =       (GLint) VB.Win[v0][0];
  328.    y0 = FLIP( (GLint) VB.Win[v0][1] );
  329.    x1 =       (GLint) VB.Win[v1][0];
  330.    y1 = FLIP( (GLint) VB.Win[v1][1] );
  331.    XDrawLine( XMesa->display, XMesa->buffer, gc, x0, y0, x1, y1 );
  332. }
  333.  
  334.  
  335. /*
  336.  * Despite being clipped to the view volume, the line's window coordinates
  337.  * may just lie outside the window bounds.  That is, if the legal window
  338.  * coordinates are [0,W-1][0,H-1], it's possible for x==W and/or y==H.
  339.  * These quick and dirty macros take care of that possibility.
  340.  */
  341. #define WINCLIP_X(X1,X2)        \
  342.    {                    \
  343.       GLint w = CC.BufferWidth;        \
  344.       if (X1==w | X2==w) {        \
  345.          if (X1==w & X2==w)  return;    \
  346.          X1 -= X1==w;   X2 -= X2==w;    \
  347.       }                    \
  348.    }
  349.  
  350. #define WINCLIP_Y(Y1,Y2)        \
  351.    {                    \
  352.       GLint h = CC.BufferHeight;    \
  353.       if (Y1==h | Y2==h) {        \
  354.          if (Y1==h & Y2==h)  return;    \
  355.          Y1 -= Y1==h;   Y2 -= Y2==h;    \
  356.       }                    \
  357.    }
  358.  
  359.  
  360. /*
  361.  * Draw a flat-shaded, PF_8A8B8G8R line into an XImage.
  362.  */
  363. static void flat_8A8B8G8R_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  364. {
  365.    GLint x1 = (GLint) VB.Win[v0][0],  y1 = (GLint) VB.Win[v0][1];
  366.    GLint x2 = (GLint) VB.Win[v1][0],  y2 = (GLint) VB.Win[v1][1];
  367.    GLuint pixel;
  368.    WINCLIP_X(x1,x2);
  369.    WINCLIP_Y(y1,y2);
  370.    pixel = PACK_8B8G8R( VB.Color[pv][0], VB.Color[pv][1], VB.Color[pv][2] );
  371.  
  372. #define BRESENHAM_PLOT(X,Y)            \
  373.     {                    \
  374.        GLuint *ptr = PIXELADDR4(X,Y);    \
  375.        *ptr = pixel;            \
  376.     }
  377.  
  378.    BRESENHAM( x1, y1, x2, y2 );
  379.  
  380. #undef BRESENHAM_PLOT
  381. }
  382.  
  383.  
  384. /*
  385.  * Draw a flat-shaded, PF_8R8G8B line into an XImage.
  386.  */
  387. static void flat_8R8G8B_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  388. {
  389.    GLint x1 = (GLint) VB.Win[v0][0],  y1 = (GLint) VB.Win[v0][1];
  390.    GLint x2 = (GLint) VB.Win[v1][0],  y2 = (GLint) VB.Win[v1][1];
  391.    GLuint pixel;
  392.    WINCLIP_X(x1,x2);
  393.    WINCLIP_Y(y1,y2);
  394.    pixel = PACK_8R8G8B( VB.Color[pv][0], VB.Color[pv][1], VB.Color[pv][2] );
  395.  
  396. #define BRESENHAM_PLOT(X,Y)            \
  397.     {                    \
  398.        GLuint *ptr = PIXELADDR4(X,Y);    \
  399.        *ptr = pixel;            \
  400.     }
  401.  
  402.    BRESENHAM( x1, y1, x2, y2 );
  403.  
  404. #undef BRESENHAM_PLOT
  405. }
  406.  
  407.  
  408. /*
  409.  * Draw a flat-shaded, PF_5R6G5B line into an XImage.
  410.  */
  411. static void flat_5R6G5B_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  412. {
  413.    GLint x1 = (GLint) VB.Win[v0][0],  y1 = (GLint) VB.Win[v0][1];
  414.    GLint x2 = (GLint) VB.Win[v1][0],  y2 = (GLint) VB.Win[v1][1];
  415.    GLushort pixel;
  416.    WINCLIP_X(x1,x2);
  417.    WINCLIP_Y(y1,y2);
  418.    pixel = PACK_5R6G5B( VB.Color[pv][0], VB.Color[pv][1], VB.Color[pv][2] );
  419.  
  420. #define BRESENHAM_PLOT(X,Y)            \
  421.     {                    \
  422.        GLushort *ptr = PIXELADDR2(X,Y);    \
  423.        *ptr = pixel;            \
  424.     }
  425.  
  426.    BRESENHAM( x1, y1, x2, y2 );
  427.  
  428. #undef BRESENHAM_PLOT
  429. }
  430.  
  431.  
  432.  
  433. /*
  434.  * Draw a flat-shaded, PF_TRUECOLOR line into an XImage.
  435.  */
  436. static void flat_TRUECOLOR_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  437. {
  438.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  439.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  440.    unsigned long pixel = PACK_RGB( VB.Color[pv][0], VB.Color[pv][1],
  441.                                    VB.Color[pv][2] );
  442.    WINCLIP_X(x1,x2);
  443.    WINCLIP_Y(y1,y2);
  444.  
  445. #define BRESENHAM_PLOT(X,Y)                    \
  446.         XPutPixel( XMesa->backimage, X, FLIP(Y), pixel );
  447.  
  448.    BRESENHAM( x1, y1, x2, y2 );
  449.  
  450. #undef BRESENHAM_PLOT
  451. }
  452.  
  453.  
  454. /*
  455.  * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage.
  456.  */
  457. static void flat_DITHER8_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  458. {
  459.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  460.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  461.    GLint r = VB.Color[pv][0], g = VB.Color[pv][1], b = VB.Color[pv][2];
  462.  
  463.    WINCLIP_X(x1,x2);
  464.    WINCLIP_Y(y1,y2);
  465.  
  466. #define BRESENHAM_PLOT(X,Y)               \
  467.     GLubyte *ptr = PIXELADDR1(X,Y);    \
  468.     *ptr = DITHER( X, Y, r, g, b);
  469.  
  470.    BRESENHAM( x1, y1, x2, y2 );
  471.  
  472. #undef BRESENHAM_PLOT
  473. }
  474.  
  475.  
  476. /*
  477.  * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage.
  478.  */
  479. static void flat_LOOKUP8_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  480. {
  481.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  482.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  483.    GLubyte pixel = LOOKUP( VB.Color[pv][0], VB.Color[pv][1], VB.Color[pv][2] );
  484.  
  485.    WINCLIP_X(x1,x2);
  486.    WINCLIP_Y(y1,y2);
  487.  
  488. #define BRESENHAM_PLOT(X,Y)               \
  489.     GLubyte *ptr = PIXELADDR1(X,Y);    \
  490.     *ptr = pixel;
  491.  
  492.    BRESENHAM( x1, y1, x2, y2 );
  493.  
  494. #undef BRESENHAM_PLOT
  495. }
  496.  
  497.  
  498. /*
  499.  * Draw a flat-shaded, PF_HPCR line into an XImage.
  500.  */
  501. static void flat_HPCR_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  502. {
  503.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  504.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  505.    GLint r = VB.Color[pv][0], g = VB.Color[pv][1], b = VB.Color[pv][2];
  506.  
  507.    WINCLIP_X(x1,x2);
  508.    WINCLIP_Y(y1,y2);
  509.  
  510. #define BRESENHAM_PLOT(X,Y)            \
  511.     GLubyte *ptr = PIXELADDR1(X,Y);        \
  512.     *ptr = DITHER_HPCR( X, Y, r, g, b);
  513.  
  514.    BRESENHAM( x1, y1, x2, y2 );
  515.  
  516. #undef BRESENHAM_PLOT
  517. }
  518.  
  519.  
  520.  
  521. /*
  522.  * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage.
  523.  */
  524. static void flat_TRUECOLOR_z_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  525. {
  526.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  527.    GLint z1 = (GLint) (VB.Win[v0][2] * DEPTH_SCALE);
  528.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  529.    GLint z2 = (GLint) (VB.Win[v1][2] * DEPTH_SCALE);
  530.    unsigned long pixel = PACK_RGB( VB.Color[pv][0], VB.Color[pv][1],
  531.                                    VB.Color[pv][2] );
  532.    GLdepth *zptr;
  533.  
  534.    WINCLIP_X(x1,x2);
  535.    WINCLIP_Y(y1,y2);
  536.  
  537. #define BRESENHAM_PLOT(X,Y,Z)                    \
  538.     zptr = Z_ADDRESS(X,Y);                    \
  539.     if ((GLdepth)(Z) < *zptr) {                \
  540.            XPutPixel( XMesa->backimage, X, FLIP(Y), pixel );    \
  541.        *zptr = (Z);                        \
  542.     }
  543.  
  544.    BRESENHAM_Z( x1, y1, z1, x2, y2, z2 );
  545.  
  546. #undef BRESENHAM_PLOT
  547. }
  548.  
  549.  
  550. /*
  551.  * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage.
  552.  */
  553. static void flat_8A8B8G8R_z_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  554. {
  555.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  556.    GLint z1 = (GLint) (VB.Win[v0][2] * DEPTH_SCALE);
  557.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  558.    GLint z2 = (GLint) (VB.Win[v1][2] * DEPTH_SCALE);
  559.    GLuint pixel = PACK_8B8G8R( VB.Color[pv][0], VB.Color[pv][1],
  560.                                VB.Color[pv][2] );
  561.    GLdepth *zptr;
  562.  
  563.    WINCLIP_X(x1,x2);
  564.    WINCLIP_Y(y1,y2);
  565.  
  566. #define BRESENHAM_PLOT(X,Y,Z)            \
  567.     zptr = Z_ADDRESS(X,Y);            \
  568.     if ((GLdepth)(Z) < *zptr) {        \
  569.        GLuint *ptr = PIXELADDR4(X,Y);    \
  570.        *ptr = pixel;            \
  571.        *zptr = (Z);                \
  572.     }
  573.  
  574.    BRESENHAM_Z( x1, y1, z1, x2, y2, z2 );
  575.  
  576. #undef BRESENHAM_PLOT
  577. }
  578.  
  579.  
  580. /*
  581.  * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage.
  582.  */
  583. static void flat_8R8G8B_z_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  584. {
  585.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  586.    GLint z1 = (GLint) (VB.Win[v0][2] * DEPTH_SCALE);
  587.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  588.    GLint z2 = (GLint) (VB.Win[v1][2] * DEPTH_SCALE);
  589.    GLuint pixel = PACK_8R8G8B( VB.Color[pv][0], VB.Color[pv][1],
  590.                                VB.Color[pv][2] );
  591.    GLdepth *zptr;
  592.  
  593.    WINCLIP_X(x1,x2);
  594.    WINCLIP_Y(y1,y2);
  595.  
  596. #define BRESENHAM_PLOT(X,Y,Z)            \
  597.     zptr = Z_ADDRESS(X,Y);            \
  598.     if ((GLdepth)(Z) < *zptr) {        \
  599.        GLuint *ptr = PIXELADDR4(X,Y);    \
  600.        *ptr = pixel;            \
  601.        *zptr = (Z);                \
  602.     }
  603.  
  604.    BRESENHAM_Z( x1, y1, z1, x2, y2, z2 );
  605.  
  606. #undef BRESENHAM_PLOT
  607. }
  608.  
  609.  
  610. /*
  611.  * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage.
  612.  */
  613. static void flat_5R6G5B_z_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  614. {
  615.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  616.    GLint z1 = (GLint) (VB.Win[v0][2] * DEPTH_SCALE);
  617.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  618.    GLint z2 = (GLint) (VB.Win[v1][2] * DEPTH_SCALE);
  619.    GLuint pixel = PACK_5R6G5B( VB.Color[pv][0], VB.Color[pv][1],
  620.                                VB.Color[pv][2] );
  621.    GLdepth *zptr;
  622.  
  623.    WINCLIP_X(x1,x2);
  624.    WINCLIP_Y(y1,y2);
  625.  
  626. #define BRESENHAM_PLOT(X,Y,Z)            \
  627.     zptr = Z_ADDRESS(X,Y);            \
  628.     if ((GLdepth)(Z) < *zptr) {        \
  629.        GLushort *ptr = PIXELADDR2(X,Y);    \
  630.        *ptr = pixel;            \
  631.        *zptr = (Z);                \
  632.     }
  633.  
  634.    BRESENHAM_Z( x1, y1, z1, x2, y2, z2 );
  635.  
  636. #undef BRESENHAM_PLOT
  637. }
  638.  
  639.  
  640. /*
  641.  * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage.
  642.  */
  643. static void flat_DITHER8_z_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  644. {
  645.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  646.    GLint z1 = (GLint) (VB.Win[v0][2] * DEPTH_SCALE);
  647.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  648.    GLint z2 = (GLint) (VB.Win[v1][2] * DEPTH_SCALE);
  649.    GLint r = VB.Color[pv][0], g = VB.Color[pv][1], b = VB.Color[pv][2];
  650.    GLdepth *zptr;
  651.  
  652.    WINCLIP_X(x1,x2);
  653.    WINCLIP_Y(y1,y2);
  654.  
  655. #define BRESENHAM_PLOT(X,Y,Z)            \
  656.     zptr = Z_ADDRESS(X,Y);            \
  657.     if ((GLdepth)(Z) < *zptr) {        \
  658.        GLubyte *ptr = PIXELADDR1(X,Y);    \
  659.        *ptr = DITHER( X, Y, r, g, b);    \
  660.        *zptr = (Z);                \
  661.     }
  662.  
  663.    BRESENHAM_Z( x1, y1, z1, x2, y2, z2 );
  664.  
  665. #undef BRESENHAM_PLOT
  666. }
  667.  
  668.  
  669. /*
  670.  * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage.
  671.  */
  672. static void flat_LOOKUP8_z_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  673. {
  674.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  675.    GLint z1 = (GLint) (VB.Win[v0][2] * DEPTH_SCALE);
  676.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  677.    GLint z2 = (GLint) (VB.Win[v1][2] * DEPTH_SCALE);
  678.    GLubyte pixel = LOOKUP( VB.Color[pv][0], VB.Color[pv][1], VB.Color[pv][2] );
  679.    GLdepth *zptr;
  680.  
  681.    WINCLIP_X(x1,x2);
  682.    WINCLIP_Y(y1,y2);
  683.  
  684. #define BRESENHAM_PLOT(X,Y,Z)            \
  685.     zptr = Z_ADDRESS(X,Y);            \
  686.     if ((GLdepth)(Z) < *zptr) {        \
  687.        GLubyte *ptr = PIXELADDR1(X,Y);    \
  688.        *ptr = pixel;            \
  689.        *zptr = (Z);                \
  690.     }
  691.  
  692.    BRESENHAM_Z( x1, y1, z1, x2, y2, z2 );
  693.  
  694. #undef BRESENHAM_PLOT
  695. }
  696.  
  697.  
  698. /*
  699.  * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage.
  700.  */
  701. static void flat_HPCR_z_line_ximage( GLuint v0, GLuint v1, GLuint pv )
  702. {
  703.    GLint x1 = (GLint) VB.Win[v0][0], y1 = (GLint) VB.Win[v0][1];
  704.    GLint z1 = (GLint) (VB.Win[v0][2] * DEPTH_SCALE);
  705.    GLint x2 = (GLint) VB.Win[v1][0], y2 = (GLint) VB.Win[v1][1];
  706.    GLint z2 = (GLint) (VB.Win[v1][2] * DEPTH_SCALE);
  707.    GLint r = VB.Color[pv][0], g = VB.Color[pv][1], b = VB.Color[pv][2];
  708.    GLdepth *zptr;
  709.  
  710.    WINCLIP_X(x1,x2);
  711.    WINCLIP_Y(y1,y2);
  712.  
  713. #define BRESENHAM_PLOT(X,Y,Z)            \
  714.     zptr = Z_ADDRESS(X,Y);            \
  715.     if ((GLdepth)(Z) < *zptr) {        \
  716.        GLubyte *ptr = PIXELADDR1(X,Y);    \
  717.        *ptr = DITHER_HPCR( X, Y, r, g, b);    \
  718.        *zptr = (Z);                \
  719.     }
  720.  
  721.    BRESENHAM_Z( x1, y1, z1, x2, y2, z2 );
  722.  
  723. #undef BRESENHAM_PLOT
  724. }
  725.  
  726.  
  727.  
  728. /*
  729.  * Analyze current state to see if we can provide a fast line drawing
  730.  * function, like those in lines.c.  Otherwise, return NULL.
  731.  */
  732. line_func xmesa_get_line_func( void )
  733. {
  734.    if (CC.Line.SmoothFlag)              return NULL;
  735.    if (CC.Line.StippleFlag)             return NULL;
  736.    if (CC.Texture.Enabled)              return NULL;
  737.    if (CC.Light.ShadeModel!=GL_FLAT)    return NULL;
  738.  
  739.    if (XMesa->buffer==XIMAGE && CC.RasterMask==DEPTH_BIT
  740.        && CC.Depth.Func==GL_LESS && CC.Depth.Mask==GL_TRUE
  741.        && CC.Line.Width==1.0F) {
  742.       switch (XMesa->pixelformat) {
  743.          case PF_TRUECOLOR:
  744.             return flat_TRUECOLOR_z_line_ximage;
  745.          case PF_8A8B8G8R:
  746.             return flat_8A8B8G8R_z_line_ximage;
  747.          case PF_8R8G8B:
  748.             return flat_8R8G8B_z_line_ximage;
  749.          case PF_5R6G5B:
  750.             return flat_5R6G5B_z_line_ximage;
  751.          case PF_DITHER:
  752.             return (XMesa->depth==8) ? flat_DITHER8_z_line_ximage : NULL;
  753.          case PF_LOOKUP:
  754.             return (XMesa->depth==8) ? flat_LOOKUP8_z_line_ximage : NULL;
  755.          case PF_HPCR:
  756.             return flat_HPCR_z_line_ximage;
  757.          default:
  758.             return NULL;
  759.       }
  760.    }
  761.    if (XMesa->buffer==XIMAGE && CC.RasterMask==0 && CC.Line.Width==1.0F) {
  762.       switch (XMesa->pixelformat) {
  763.          case PF_TRUECOLOR:
  764.             return flat_TRUECOLOR_line_ximage;
  765.          case PF_8A8B8G8R:
  766.             return flat_8A8B8G8R_line_ximage;
  767.          case PF_8R8G8B:
  768.             return flat_8R8G8B_line_ximage;
  769.          case PF_5R6G5B:
  770.             return flat_5R6G5B_line_ximage;
  771.          case PF_DITHER:
  772.             return (XMesa->depth==8) ? flat_DITHER8_line_ximage : NULL;
  773.          case PF_LOOKUP:
  774.             return (XMesa->depth==8) ? flat_LOOKUP8_line_ximage : NULL;
  775.          case PF_HPCR:
  776.             return flat_HPCR_line_ximage;
  777.      default:
  778.         return NULL;
  779.       }
  780.    }
  781.    if (XMesa->buffer!=XIMAGE && CC.RasterMask==0) {
  782.       XGCValues gcvals;
  783.       gcvals.line_width = (int) CC.Line.Width;
  784.       if (gcvals.line_width<2) {
  785.          /* width=1 can be slow, width=0 is fastest */
  786.          gcvals.line_width = 0;
  787.       }
  788.       XChangeGC( XMesa->display, XMesa->gc1, GCLineWidth, &gcvals );
  789.       XChangeGC( XMesa->display, XMesa->gc2, GCLineWidth, &gcvals );
  790.       return flat_line_pixmap;
  791.    }
  792.    return NULL;
  793. }
  794.  
  795.  
  796.  
  797.  
  798. /**********************************************************************/
  799. /***                   Polygon rendering                            ***/
  800. /**********************************************************************/
  801.  
  802. /*
  803.  * Render a polygon into a pixmap, any pixel format.
  804.  */
  805. void draw_polygon_ANY_pixmap( GLuint n, GLuint vlist[], GLuint pv )
  806. {
  807.    GLuint i;
  808.    XPoint p[VB_SIZE];
  809.    GC gc;
  810.    if (VB.MonoColor) {
  811.       gc = XMesa->gc1;  /* use current color */
  812.    }
  813.    else {
  814.       gc = XMesa->gc2;
  815.       XSetForeground( XMesa->display, XMesa->gc2, encode_color(pv) );
  816.    }
  817.    for (i=0;i<n;i++) {
  818.       GLuint j = vlist[i];
  819.       /* The +1 offset is tricky, involves the CC.RasterOffset and X's */
  820.       /* sampling policy. */
  821.       p[i].x =       (GLint) VB.Win[j][0] + 1;
  822.       p[i].y = FLIP( (GLint) (VB.Win[j][1]+1.0f) - 1 );
  823.    }
  824.    XFillPolygon( XMesa->display, XMesa->buffer, gc,
  825.          p, n, Convex, CoordModeOrigin );
  826. }
  827.  
  828.  
  829.  
  830. static GLint lx[MAX_HEIGHT], rx[MAX_HEIGHT];    /* X bounds */
  831. static GLfixed lz[MAX_HEIGHT], rz[MAX_HEIGHT];    /* Z values */
  832. static GLfixed lr[MAX_HEIGHT], rr[MAX_HEIGHT];    /* Red */
  833. static GLfixed lg[MAX_HEIGHT], rg[MAX_HEIGHT];    /* Green */
  834. static GLfixed lb[MAX_HEIGHT], rb[MAX_HEIGHT];    /* Blue */
  835. static GLfixed la[MAX_HEIGHT], ra[MAX_HEIGHT];    /* Alpha */
  836.  
  837.  
  838.  
  839.  
  840.  
  841. /*
  842.  * XImage, smooth, depth-buffered, PF_TRUECOLOR polygon.
  843.  */
  844. static void smooth_TRUECOLOR_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  845. {
  846. #define INTERP_COLOR
  847. #define INTERP_Z
  848.  
  849. #define INNER_CODE                    \
  850.    GLint i, yy = FLIP(y);                \
  851.    for (i=0;i<len;i++,xmin++) {                \
  852.       if (FixedToUns(fz) < zptr[i]) {            \
  853.          unsigned long p;                \
  854.          zptr[i] = FixedToUns(fz);            \
  855.          p = PACK_RGB( FixedToInt(fr), FixedToInt(fg),    \
  856.                FixedToInt(fb) );        \
  857.          XPutPixel( XMesa->backimage, xmin, yy, p );    \
  858.       }                            \
  859.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;        \
  860.       fz += fdzdx;                    \
  861.    }
  862.  
  863. #include "polytemp.h"
  864. }
  865.  
  866.  
  867. /*
  868.  * XImage, smooth, depth-buffered, PF_8A8B8G8R polygon.
  869.  */
  870. static void smooth_8A8B8G8R_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  871. {
  872. #define INTERP_COLOR
  873. #define INTERP_Z
  874.  
  875. #define INNER_CODE                        \
  876.    GLuint *img = PIXELADDR4(xmin,y);                \
  877.    GLint i;                            \
  878.    for (i=0;i<len;i++) {                    \
  879.       if (FixedToUns(fz) < zptr[i]) {                \
  880.          zptr[i] = FixedToUns(fz);                \
  881.          img[i] = PACK_8B8G8R( FixedToInt(fr), FixedToInt(fg),    \
  882.                                FixedToInt(fb) );        \
  883.       }                                \
  884.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;             \
  885.       fz += fdzdx;                        \
  886.    }
  887.  
  888. #include "polytemp.h"
  889. }
  890.  
  891.  
  892. /*
  893.  * XImage, smooth, depth-buffered, PF_8R8G8B polygon.
  894.  */
  895. static void smooth_8R8G8B_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  896. {
  897. #define INTERP_COLOR
  898. #define INTERP_Z
  899.  
  900. #define INNER_CODE                        \
  901.    GLuint *img = PIXELADDR4(xmin,y);                \
  902.    GLint i;                            \
  903.    for (i=0;i<len;i++) {                    \
  904.       if (FixedToUns(fz) < zptr[i]) {                \
  905.          zptr[i] = FixedToUns(fz);                \
  906.          img[i] = PACK_8R8G8B( FixedToInt(fr), FixedToInt(fg),    \
  907.                                FixedToInt(fb) );        \
  908.       }                                \
  909.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;             \
  910.       fz += fdzdx;                        \
  911.    }
  912.  
  913. #include "polytemp.h"
  914. }
  915.  
  916.  
  917. /*
  918.  * XImage, smooth, depth-buffered, PF_5R6G5B polygon.
  919.  */
  920. static void smooth_5R6G5B_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  921. {
  922. #define INTERP_COLOR
  923. #define INTERP_Z
  924.  
  925. #define INNER_CODE                        \
  926.    GLushort *img = PIXELADDR2(xmin,y);                \
  927.    GLint i;                            \
  928.    for (i=0;i<len;i++) {                    \
  929.       if (FixedToUns(fz) < zptr[i]) {                \
  930.          zptr[i] = FixedToUns(fz);                \
  931.          img[i] = PACK_5R6G5B( FixedToInt(fr), FixedToInt(fg),    \
  932.                                FixedToInt(fb) );        \
  933.       }                                \
  934.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;            \
  935.       fz += fdzdx;                        \
  936.    }
  937.  
  938. #include "polytemp.h"
  939. }
  940.  
  941.  
  942. /*
  943.  * XImage, smooth, depth-buffered, 8-bit PF_DITHER polygon.
  944.  */
  945. static void smooth_DITHER8_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  946. {
  947. #define INTERP_COLOR
  948. #define INTERP_Z
  949.  
  950. #define INNER_CODE                        \
  951.    GLubyte *img = PIXELADDR1(xmin,y);                \
  952.    GLint i;                            \
  953.    for (i=0;i<len;i++,xmin++) {                    \
  954.       if (FixedToUns(fz) < zptr[i]) {                \
  955.          zptr[i] = FixedToUns(fz);                \
  956.          img[i] = DITHER( xmin, y, FixedToInt(fr),        \
  957.                           FixedToInt(fg), FixedToInt(fb) );    \
  958.       }                                \
  959.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;            \
  960.       fz += fdzdx;                        \
  961.    }
  962.  
  963. #include "polytemp.h"
  964. }
  965.  
  966.  
  967.  
  968. /*
  969.  * XImage, smooth, depth-buffered, PF_DITHER polygon.
  970.  */
  971. static void smooth_DITHER_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  972. {
  973. #define INTERP_COLOR
  974. #define INTERP_Z
  975.  
  976. #define INNER_CODE                    \
  977.    GLint i, yy = FLIP(y);                \
  978.    for (i=0;i<len;i++,xmin++) {                \
  979.       if (FixedToUns(fz) < zptr[i]) {            \
  980.      unsigned long p;                \
  981.          zptr[i] = FixedToUns(fz);            \
  982.      p = DITHER( xmin, y, FixedToInt(fr),        \
  983.                      FixedToInt(fg), FixedToInt(fb) );    \
  984.      XPutPixel( XMesa->backimage, xmin, yy, p );    \
  985.       }                            \
  986.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;        \
  987.       fz += fdzdx;                    \
  988.    }
  989.  
  990. #include "polytemp.h"
  991. }
  992.  
  993.  
  994.  
  995. /*
  996.  * XImage, smooth, depth-buffered, 8-bit PF_LOOKUP polygon.
  997.  */
  998. static void smooth_LOOKUP8_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  999. {
  1000. #define INTERP_COLOR
  1001. #define INTERP_Z
  1002.  
  1003. #define INNER_CODE                        \
  1004.    GLubyte *img = PIXELADDR1(xmin,y);                \
  1005.    GLint i;                            \
  1006.    for (i=0;i<len;i++) {                    \
  1007.       if (FixedToUns(fz) < zptr[i]) {                \
  1008.          zptr[i] = FixedToUns(fz);                \
  1009.          img[i] = LOOKUP( FixedToInt(fr),            \
  1010.                           FixedToInt(fg), FixedToInt(fb) );    \
  1011.       }                                \
  1012.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;            \
  1013.       fz += fdzdx;                        \
  1014.    }
  1015.  
  1016. #include "polytemp.h"
  1017. }
  1018.  
  1019.  
  1020.  
  1021.  
  1022. /*
  1023.  * XImage, smooth, depth-buffered, 8-bit PF_HPCR polygon.
  1024.  */
  1025. static void smooth_HPCR_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1026. {
  1027. #define INTERP_COLOR
  1028. #define INTERP_Z
  1029.  
  1030. #define INNER_CODE                        \
  1031.    GLubyte *img = PIXELADDR1(xmin,y);                \
  1032.    GLint i;                            \
  1033.    for (i=0;i<len;i++,xmin++) {                    \
  1034.       if (FixedToUns(fz) < zptr[i]) {                \
  1035.          zptr[i] = FixedToUns(fz);                \
  1036.          img[i] = DITHER_HPCR( xmin, y, FixedToInt(fr),        \
  1037.                               FixedToInt(fg), FixedToInt(fb) );    \
  1038.       }                                \
  1039.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;            \
  1040.       fz += fdzdx;                        \
  1041.    }
  1042.  
  1043. #include "polytemp.h"
  1044. }
  1045.  
  1046.  
  1047.  
  1048. /*
  1049.  * XImage, flat, depth-buffered, PF_TRUECOLOR polygon.
  1050.  */
  1051. static void flat_TRUECOLOR_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1052. {
  1053. #define INTERP_Z
  1054.  
  1055. #define SETUP_CODE                    \
  1056.    unsigned long pixel = PACK_RGB( VB.Color[pv][0],    \
  1057.          VB.Color[pv][1], VB.Color[pv][2] );
  1058.  
  1059. #define INNER_CODE                        \
  1060.    GLint i, yy = FLIP(y);                    \
  1061.    for (i=0;i<len;i++,xmin++) {                    \
  1062.       if (FixedToUns(fz) < zptr[i]) {                \
  1063.          zptr[i] = FixedToUns(fz);                \
  1064.          XPutPixel( XMesa->backimage, xmin, yy, pixel );    \
  1065.       }                                \
  1066.       fz += fdzdx;                        \
  1067.    }
  1068.  
  1069. #include "polytemp.h"
  1070. }
  1071.  
  1072.  
  1073.  
  1074. /*
  1075.  * XImage, flat, depth-buffered, PF_8A8B8G8R polygon.
  1076.  */
  1077. static void flat_8A8B8G8R_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1078. {
  1079. #define INTERP_Z
  1080.  
  1081. #define SETUP_CODE                \
  1082.    GLuint pixel = PACK_8B8G8R( VB.Color[pv][0],    \
  1083.          VB.Color[pv][1], VB.Color[pv][2] );
  1084.  
  1085. #define INNER_CODE            \
  1086.    GLuint *img = PIXELADDR4(xmin,y);    \
  1087.    GLint i;                \
  1088.    for (i=0;i<len;i++) {        \
  1089.       if (FixedToUns(fz) < zptr[i]) {    \
  1090.          zptr[i] = FixedToUns(fz);    \
  1091.          img[i] = pixel;        \
  1092.       }                    \
  1093.       fz += fdzdx;            \
  1094.    }
  1095.  
  1096. #include "polytemp.h"
  1097. }
  1098.  
  1099.  
  1100.  
  1101. /*
  1102.  * XImage, flat, depth-buffered, PF_8R8G8B polygon.
  1103.  */
  1104. static void flat_8R8G8B_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1105. {
  1106. #define INTERP_Z
  1107.  
  1108. #define SETUP_CODE                \
  1109.    GLuint pixel = PACK_8R8G8B( VB.Color[pv][0],    \
  1110.          VB.Color[pv][1], VB.Color[pv][2] );
  1111.  
  1112. #define INNER_CODE            \
  1113.    GLuint *img = PIXELADDR4(xmin,y);    \
  1114.    GLint i;                \
  1115.    for (i=0;i<len;i++) {        \
  1116.       if (FixedToUns(fz) < zptr[i]) {    \
  1117.          zptr[i] = FixedToUns(fz);    \
  1118.          img[i] = pixel;        \
  1119.       }                    \
  1120.       fz += fdzdx;            \
  1121.    }
  1122.  
  1123. #include "polytemp.h"
  1124. }
  1125.  
  1126.  
  1127.  
  1128. /*
  1129.  * XImage, flat, depth-buffered, PF_5R6G5B polygon.
  1130.  */
  1131. static void flat_5R6G5B_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1132. {
  1133. #define INTERP_Z
  1134.  
  1135. #define SETUP_CODE                    \
  1136.    GLushort pixel = PACK_5R6G5B( VB.Color[pv][0],    \
  1137.          VB.Color[pv][1], VB.Color[pv][2] );
  1138.  
  1139. #define INNER_CODE            \
  1140.    GLushort *img = PIXELADDR2(xmin,y);    \
  1141.    GLint i;                \
  1142.    for (i=0;i<len;i++) {        \
  1143.       if (FixedToUns(fz) < zptr[i]) {    \
  1144.          zptr[i] = FixedToUns(fz);    \
  1145.          img[i] = pixel;        \
  1146.       }                    \
  1147.       fz += fdzdx;            \
  1148.    }
  1149.  
  1150. #include "polytemp.h"
  1151. }
  1152.  
  1153.  
  1154.  
  1155. /*
  1156.  * XImage, flat, depth-buffered, 8-bit PF_DITHER polygon.
  1157.  */
  1158. static void flat_DITHER8_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1159. {
  1160. #define INTERP_Z
  1161.  
  1162. #define SETUP_CODE                \
  1163.    GLubyte r = VB.Color[pv][0];            \
  1164.    GLubyte g = VB.Color[pv][1];            \
  1165.    GLubyte b = VB.Color[pv][2];
  1166.  
  1167. #define INNER_CODE                \
  1168.    GLubyte *img = PIXELADDR1(xmin,y);        \
  1169.    GLint i;                    \
  1170.    for (i=0;i<len;i++,xmin++) {            \
  1171.       if (FixedToUns(fz) < zptr[i]) {        \
  1172.          zptr[i] = FixedToUns(fz);        \
  1173.          img[i] = DITHER( xmin, y, r, g, b );    \
  1174.       }                        \
  1175.       fz += fdzdx;                \
  1176.    }
  1177.  
  1178. #include "polytemp.h"
  1179. }
  1180.  
  1181.  
  1182.  
  1183. /*
  1184.  * XImage, flat, depth-buffered, PF_DITHER polygon.
  1185.  */
  1186. static void flat_DITHER_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1187. {
  1188. #define INTERP_Z
  1189.  
  1190. #define SETUP_CODE                \
  1191.    GLubyte r = VB.Color[pv][0];            \
  1192.    GLubyte g = VB.Color[pv][1];            \
  1193.    GLubyte b = VB.Color[pv][2];
  1194.  
  1195. #define INNER_CODE                    \
  1196.    GLint i, yy = FLIP(y);                \
  1197.    for (i=0;i<len;i++,xmin++) {                \
  1198.       if (FixedToUns(fz) < zptr[i]) {            \
  1199.      unsigned long p;                \
  1200.          zptr[i] = FixedToUns(fz);            \
  1201.          p = DITHER( xmin, yy, r, g, b );        \
  1202.          XPutPixel( XMesa->backimage, xmin, yy, p );    \
  1203.       }                            \
  1204.       fz += fdzdx;                    \
  1205.    }
  1206.  
  1207. #include "polytemp.h"
  1208. }
  1209.  
  1210.  
  1211.  
  1212. /*
  1213.  * XImage, flat, depth-buffered, 8-bit PF_HPCR polygon.
  1214.  */
  1215. static void flat_HPCR_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1216. {
  1217. #define INTERP_Z
  1218.  
  1219. #define SETUP_CODE                \
  1220.    GLubyte r = VB.Color[pv][0];            \
  1221.    GLubyte g = VB.Color[pv][1];            \
  1222.    GLubyte b = VB.Color[pv][2];
  1223.  
  1224. #define INNER_CODE                    \
  1225.    GLubyte *img = PIXELADDR1(xmin,y);            \
  1226.    GLint i;                        \
  1227.    for (i=0;i<len;i++,xmin++) {                \
  1228.       if (FixedToUns(fz) < zptr[i]) {            \
  1229.          zptr[i] = FixedToUns(fz);            \
  1230.          img[i] = DITHER_HPCR( xmin, y, r, g, b );    \
  1231.       }                            \
  1232.       fz += fdzdx;                    \
  1233.    }
  1234.  
  1235. #include "polytemp.h"
  1236. }
  1237.  
  1238.  
  1239.  
  1240.  
  1241. /*
  1242.  * XImage, flat, depth-buffered, 8-bit PF_LOOKUP polygon.
  1243.  */
  1244. static void flat_LOOKUP8_z_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1245. {
  1246. #define INTERP_Z
  1247.  
  1248. #define SETUP_CODE                \
  1249.    GLubyte r = VB.Color[pv][0];            \
  1250.    GLubyte g = VB.Color[pv][1];            \
  1251.    GLubyte b = VB.Color[pv][2];            \
  1252.    GLubyte pixel = LOOKUP(r,g,b);
  1253.  
  1254. #define INNER_CODE                \
  1255.    GLubyte *img = PIXELADDR1(xmin,y);        \
  1256.    GLint i;                    \
  1257.    for (i=0;i<len;i++) {            \
  1258.       if (FixedToUns(fz) < zptr[i]) {        \
  1259.          zptr[i] = FixedToUns(fz);        \
  1260.          img[i] = pixel;            \
  1261.       }                        \
  1262.       fz += fdzdx;                \
  1263.    }
  1264.  
  1265. #include "polytemp.h"
  1266. }
  1267.  
  1268.  
  1269.  
  1270.  
  1271. /*
  1272.  * XImage, smooth, NON-depth-buffered, PF_TRUECOLOR polygon.
  1273.  */
  1274. static void smooth_TRUECOLOR_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1275. {
  1276. #define INTERP_COLOR
  1277.  
  1278. #define INNER_CODE                            \
  1279.    GLint i, yy = FLIP(y);                        \
  1280.    for (i=0;i<len;i++,xmin++) {                        \
  1281.       unsigned long p;                            \
  1282.       p = PACK_RGB( FixedToInt(fr), FixedToInt(fg), FixedToInt(fb) );    \
  1283.       XPutPixel( XMesa->backimage, xmin, yy, p );            \
  1284.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;                \
  1285.    }
  1286.  
  1287. #include "polytemp.h"
  1288. }
  1289.  
  1290.  
  1291. /*
  1292.  * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R polygon.
  1293.  */
  1294. static void smooth_8A8B8G8R_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1295. {
  1296. #define INTERP_COLOR
  1297.  
  1298. #define INNER_CODE                        \
  1299.    GLuint *img = PIXELADDR4(xmin,y);                \
  1300.    GLint i;                            \
  1301.    for (i=0;i<len;i++) {                    \
  1302.       img[i] = PACK_8B8G8R( FixedToInt(fr), FixedToInt(fg),    \
  1303.                 FixedToInt(fb) );            \
  1304.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;             \
  1305.    }
  1306.  
  1307. #include "polytemp.h"
  1308. }
  1309.  
  1310.  
  1311. /*
  1312.  * XImage, smooth, NON-depth-buffered, PF_8R8G8B polygon.
  1313.  */
  1314. static void smooth_8R8G8B_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1315. {
  1316. #define INTERP_COLOR
  1317.  
  1318. #define INNER_CODE                        \
  1319.    GLuint *img = PIXELADDR4(xmin,y);                \
  1320.    GLint i;                            \
  1321.    for (i=0;i<len;i++) {                    \
  1322.       img[i] = PACK_8R8G8B( FixedToInt(fr), FixedToInt(fg),    \
  1323.                 FixedToInt(fb) );            \
  1324.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;             \
  1325.    }
  1326.  
  1327. #include "polytemp.h"
  1328. }
  1329.  
  1330.  
  1331. /*
  1332.  * XImage, smooth, NON-depth-buffered, PF_5R6G5B polygon.
  1333.  */
  1334. static void smooth_5R6G5B_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1335. {
  1336. #define INTERP_COLOR
  1337.  
  1338. #define INNER_CODE                        \
  1339.    GLushort *img = PIXELADDR2(xmin,y);                \
  1340.    GLint i;                            \
  1341.    for (i=0;i<len;i++) {                    \
  1342.       img[i] = PACK_5R6G5B( FixedToInt(fr), FixedToInt(fg),    \
  1343.                             FixedToInt(fb) );            \
  1344.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;            \
  1345.    }
  1346.  
  1347. #include "polytemp.h"
  1348. }
  1349.  
  1350.  
  1351. /*
  1352.  * XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER polygon.
  1353.  */
  1354. static void smooth_DITHER8_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1355. {
  1356. #define INTERP_COLOR
  1357.  
  1358. #define INNER_CODE                        \
  1359.    GLubyte *img = PIXELADDR1(xmin,y);                \
  1360.    GLint i;                            \
  1361.    for (i=0;i<len;i++,xmin++) {                    \
  1362.       img[i] = DITHER( xmin, y, FixedToInt(fr),            \
  1363.                FixedToInt(fg), FixedToInt(fb) );    \
  1364.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;            \
  1365.    }
  1366.  
  1367. #include "polytemp.h"
  1368. }
  1369.  
  1370.  
  1371.  
  1372. /*
  1373.  * XImage, smooth, NON-depth-buffered, PF_DITHER polygon.
  1374.  */
  1375. static void smooth_DITHER_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1376. {
  1377. #define INTERP_COLOR
  1378.  
  1379. #define INNER_CODE                    \
  1380.    GLint i, yy = FLIP(y);                \
  1381.    for (i=0;i<len;i++,xmin++) {                \
  1382.       unsigned long p;                    \
  1383.       p = DITHER( xmin, y, FixedToInt(fr),        \
  1384.                   FixedToInt(fg), FixedToInt(fb) );    \
  1385.       XPutPixel( XMesa->backimage, xmin, yy, p );    \
  1386.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;        \
  1387.    }
  1388.  
  1389. #include "polytemp.h"
  1390. }
  1391.  
  1392.  
  1393.  
  1394. /*
  1395.  * XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP polygon.
  1396.  */
  1397. static void smooth_LOOKUP8_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1398. {
  1399. #define INTERP_COLOR
  1400.  
  1401. #define INNER_CODE                        \
  1402.    GLubyte *img = PIXELADDR1(xmin,y);                \
  1403.    GLint i;                            \
  1404.    for (i=0;i<len;i++) {                    \
  1405.       img[i] = LOOKUP( FixedToInt(fr),                \
  1406.                FixedToInt(fg), FixedToInt(fb) );    \
  1407.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;            \
  1408.    }
  1409.  
  1410. #include "polytemp.h"
  1411. }
  1412.  
  1413.  
  1414.  
  1415. /*
  1416.  * XImage, smooth, NON-depth-buffered, 8-bit PF_HPCR polygon.
  1417.  */
  1418. static void smooth_HPCR_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1419. {
  1420. #define INTERP_COLOR
  1421.  
  1422. #define INNER_CODE                        \
  1423.    GLubyte *img = PIXELADDR1(xmin,y);                \
  1424.    GLint i;                            \
  1425.    for (i=0;i<len;i++,xmin++) {                    \
  1426.       img[i] = DITHER_HPCR( xmin, y, FixedToInt(fr),        \
  1427.                             FixedToInt(fg), FixedToInt(fb) );    \
  1428.       fr += fdrdx;  fg += fdgdx;  fb += fdbdx;            \
  1429.    }
  1430.  
  1431. #include "polytemp.h"
  1432. }
  1433.  
  1434.  
  1435.  
  1436. /*
  1437.  * XImage, flat, NON-depth-buffered, PF_TRUECOLOR polygon.
  1438.  */
  1439. static void flat_TRUECOLOR_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1440. {
  1441. #define SETUP_CODE                    \
  1442.    unsigned long pixel = PACK_RGB( VB.Color[pv][0],    \
  1443.          VB.Color[pv][1], VB.Color[pv][2] );
  1444.  
  1445. #define INNER_CODE                    \
  1446.    GLint i, yy = FLIP(y);                \
  1447.    for (i=0;i<len;i++,xmin++) {                \
  1448.       XPutPixel( XMesa->backimage, xmin, yy, pixel );    \
  1449.    }
  1450.  
  1451. #include "polytemp.h"
  1452. }
  1453.  
  1454.  
  1455.  
  1456. /*
  1457.  * XImage, flat, NON-depth-buffered, PF_8A8B8G8R polygon.
  1458.  */
  1459. static void flat_8A8B8G8R_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1460. {
  1461. #define SETUP_CODE                    \
  1462.    GLuint pixel = PACK_8B8G8R( VB.Color[pv][0],        \
  1463.             VB.Color[pv][1], VB.Color[pv][2] );
  1464.  
  1465. #define INNER_CODE            \
  1466.    GLuint *img = PIXELADDR4(xmin,y);    \
  1467.    GLint i;                \
  1468.    for (i=0;i<len;i++) {        \
  1469.       img[i] = pixel;            \
  1470.    }
  1471.  
  1472. #include "polytemp.h"
  1473. }
  1474.  
  1475.  
  1476.  
  1477. /*
  1478.  * XImage, flat, NON-depth-buffered, PF_8R8G8B polygon.
  1479.  */
  1480. static void flat_8R8G8B_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1481. {
  1482. #define SETUP_CODE                    \
  1483.    GLuint pixel = PACK_8R8G8B( VB.Color[pv][0],        \
  1484.             VB.Color[pv][1], VB.Color[pv][2] );
  1485.  
  1486. #define INNER_CODE            \
  1487.    GLuint *img = PIXELADDR4(xmin,y);    \
  1488.    GLint i;                \
  1489.    for (i=0;i<len;i++) {        \
  1490.       img[i] = pixel;            \
  1491.    }
  1492.  
  1493. #include "polytemp.h"
  1494. }
  1495.  
  1496.  
  1497.  
  1498. /*
  1499.  * XImage, flat, NON-depth-buffered, PF_5R6G5B polygon.
  1500.  */
  1501. static void flat_5R6G5B_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1502. {
  1503. #define SETUP_CODE                    \
  1504.    GLushort pixel = PACK_5R6G5B( VB.Color[pv][0],    \
  1505.          VB.Color[pv][1], VB.Color[pv][2] );
  1506.  
  1507. #define INNER_CODE            \
  1508.    GLushort *img = PIXELADDR2(xmin,y);    \
  1509.    GLint i;                \
  1510.    for (i=0;i<len;i++) {        \
  1511.       img[i] = pixel;            \
  1512.    }
  1513.  
  1514. #include "polytemp.h"
  1515. }
  1516.  
  1517.  
  1518.  
  1519. /*
  1520.  * XImage, flat, NON-depth-buffered, 8-bit PF_DITHER polygon.
  1521.  */
  1522. static void flat_DITHER8_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1523. {
  1524. #define SETUP_CODE                \
  1525.    GLubyte r = VB.Color[pv][0];            \
  1526.    GLubyte g = VB.Color[pv][1];            \
  1527.    GLubyte b = VB.Color[pv][2];
  1528.  
  1529. #define INNER_CODE                \
  1530.    GLubyte *img = PIXELADDR1(xmin,y);        \
  1531.    GLint i;                    \
  1532.    for (i=0;i<len;i++,xmin++) {            \
  1533.       img[i] = DITHER( xmin, y, r, g, b );    \
  1534.    }
  1535.  
  1536. #include "polytemp.h"
  1537. }
  1538.  
  1539.  
  1540.  
  1541. /*
  1542.  * XImage, flat, NON-depth-buffered, PF_DITHER polygon.
  1543.  */
  1544. static void flat_DITHER_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1545. {
  1546. #define SETUP_CODE                \
  1547.    GLubyte r = VB.Color[pv][0];            \
  1548.    GLubyte g = VB.Color[pv][1];            \
  1549.    GLubyte b = VB.Color[pv][2];
  1550.  
  1551. #define INNER_CODE                    \
  1552.    GLint i, yy = FLIP(y);                \
  1553.    for (i=0;i<len;i++,xmin++) {                \
  1554.       unsigned long p = DITHER( xmin, yy, r, g, b );    \
  1555.       XPutPixel( XMesa->backimage, xmin, yy, p );    \
  1556.    }
  1557.  
  1558. #include "polytemp.h"
  1559. }
  1560.  
  1561.  
  1562.  
  1563. /*
  1564.  * XImage, flat, NON-depth-buffered, 8-bit PF_HPCR polygon.
  1565.  */
  1566. static void flat_HPCR_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1567. {
  1568. #define SETUP_CODE                \
  1569.    GLubyte r = VB.Color[pv][0];            \
  1570.    GLubyte g = VB.Color[pv][1];            \
  1571.    GLubyte b = VB.Color[pv][2];
  1572.  
  1573. #define INNER_CODE                \
  1574.    GLubyte *img = PIXELADDR1(xmin,y);        \
  1575.    GLint i;                    \
  1576.    for (i=0;i<len;i++,xmin++) {            \
  1577.       img[i] = DITHER_HPCR( xmin, y, r, g, b );    \
  1578.    }
  1579.  
  1580. #include "polytemp.h"
  1581. }
  1582.  
  1583.  
  1584.  
  1585.  
  1586. /*
  1587.  * XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP polygon.
  1588.  */
  1589. static void flat_LOOKUP8_polygon( GLuint n, GLuint vlist[], GLuint pv )
  1590. {
  1591. #define SETUP_CODE                \
  1592.    GLubyte r = VB.Color[pv][0];            \
  1593.    GLubyte g = VB.Color[pv][1];            \
  1594.    GLubyte b = VB.Color[pv][2];            \
  1595.    GLubyte pixel = LOOKUP(r,g,b);
  1596.  
  1597. #define INNER_CODE            \
  1598.    GLubyte *img = PIXELADDR1(xmin,y);    \
  1599.    GLint i;                \
  1600.    for (i=0;i<len;i++) {        \
  1601.       img[i] = pixel;            \
  1602.    }
  1603.  
  1604. #include "polytemp.h"
  1605. }
  1606.  
  1607.  
  1608.  
  1609.  
  1610. /*
  1611.  * Analyze current CC and device driver state to see if we can provide a
  1612.  * fast polygon drawing function, like those in polygons.c.  Otherwise,
  1613.  * return NULL.
  1614.  */
  1615. polygon_func xmesa_get_polygon_func( void )
  1616. {
  1617.    static int first_time=1;
  1618.    if (first_time) {
  1619.       int i;
  1620.       for (i=0;i<MAX_HEIGHT;i++) {
  1621.          lx[i] = MAX_WIDTH;
  1622.          rx[i] = -1;
  1623.       }
  1624.       first_time=0;
  1625.    }
  1626.  
  1627.    if (CC.Polygon.SmoothFlag)     return NULL;
  1628.    if (CC.Polygon.StippleFlag)    return NULL;
  1629.    if (CC.Texture.Enabled)        return NULL;
  1630.  
  1631.    if (XMesa->buffer==XIMAGE) {
  1632.       if (   CC.Light.ShadeModel==GL_SMOOTH
  1633.           && CC.RasterMask==DEPTH_BIT
  1634.           && CC.Depth.Func==GL_LESS
  1635.           && CC.Depth.Mask==GL_TRUE) {
  1636.          switch (XMesa->pixelformat) {
  1637.             case PF_TRUECOLOR:
  1638.            return smooth_TRUECOLOR_z_polygon;
  1639.             case PF_8A8B8G8R:
  1640.                return smooth_8A8B8G8R_z_polygon;
  1641.             case PF_8R8G8B:
  1642.                return smooth_8R8G8B_z_polygon;
  1643.             case PF_5R6G5B:
  1644.                return smooth_5R6G5B_z_polygon;
  1645.             case PF_HPCR:
  1646.            return smooth_HPCR_z_polygon;
  1647.             case PF_DITHER:
  1648.                return (XMesa->depth==8) ? smooth_DITHER8_z_polygon
  1649.                                         : smooth_DITHER_z_polygon;
  1650.             case PF_LOOKUP:
  1651.                return (XMesa->depth==8) ? smooth_LOOKUP8_z_polygon : NULL;
  1652.             default:
  1653.                return NULL;
  1654.          }
  1655.       }
  1656.       if (   CC.Light.ShadeModel==GL_FLAT
  1657.           && CC.RasterMask==DEPTH_BIT
  1658.           && CC.Depth.Func==GL_LESS
  1659.           && CC.Depth.Mask==GL_TRUE) {
  1660.          switch (XMesa->pixelformat) {
  1661.             case PF_TRUECOLOR:
  1662.            return flat_TRUECOLOR_z_polygon;
  1663.             case PF_8A8B8G8R:
  1664.                return flat_8A8B8G8R_z_polygon;
  1665.             case PF_8R8G8B:
  1666.                return flat_8R8G8B_z_polygon;
  1667.             case PF_5R6G5B:
  1668.                return flat_5R6G5B_z_polygon;
  1669.             case PF_HPCR:
  1670.            return flat_HPCR_z_polygon;
  1671.             case PF_DITHER:
  1672.                return (XMesa->depth==8) ? flat_DITHER8_z_polygon
  1673.                                         : flat_DITHER_z_polygon;
  1674.             case PF_LOOKUP:
  1675.                return (XMesa->depth==8) ? flat_LOOKUP8_z_polygon : NULL;
  1676.             default:
  1677.                return NULL;
  1678.          }
  1679.       }
  1680.       if (   CC.RasterMask==0   /* no depth test */
  1681.           && CC.Light.ShadeModel==GL_SMOOTH) {
  1682.          switch (XMesa->pixelformat) {
  1683.             case PF_TRUECOLOR:
  1684.            return smooth_TRUECOLOR_polygon;
  1685.             case PF_8A8B8G8R:
  1686.                return smooth_8A8B8G8R_polygon;
  1687.             case PF_8R8G8B:
  1688.                return smooth_8R8G8B_polygon;
  1689.             case PF_5R6G5B:
  1690.                return smooth_5R6G5B_polygon;
  1691.             case PF_HPCR:
  1692.            return smooth_HPCR_polygon;
  1693.             case PF_DITHER:
  1694.                return (XMesa->depth==8) ? smooth_DITHER8_polygon
  1695.                                         : smooth_DITHER_polygon;
  1696.             case PF_LOOKUP:
  1697.                return (XMesa->depth==8) ? smooth_LOOKUP8_polygon : NULL;
  1698.             default:
  1699.                return NULL;
  1700.          }
  1701.       }
  1702.       if (   CC.RasterMask==0   /* no depth test */
  1703.           && CC.Light.ShadeModel==GL_FLAT) {
  1704.          switch (XMesa->pixelformat) {
  1705.             case PF_TRUECOLOR:
  1706.            return flat_TRUECOLOR_polygon;
  1707.             case PF_8A8B8G8R:
  1708.                return flat_8A8B8G8R_polygon;
  1709.             case PF_8R8G8B:
  1710.                return flat_8R8G8B_polygon;
  1711.             case PF_5R6G5B:
  1712.                return flat_5R6G5B_polygon;
  1713.             case PF_HPCR:
  1714.            return flat_HPCR_polygon;
  1715.             case PF_DITHER:
  1716.                return (XMesa->depth==8) ? flat_DITHER8_polygon
  1717.                                         : flat_DITHER_polygon;
  1718.             case PF_LOOKUP:
  1719.                return (XMesa->depth==8) ? flat_LOOKUP8_polygon : NULL;
  1720.             default:
  1721.                return NULL;
  1722.          }
  1723.       }
  1724.       return NULL;
  1725.    }
  1726.    else {
  1727.       /* pixmap */
  1728.       if (CC.Light.ShadeModel==GL_FLAT && CC.RasterMask==0) {
  1729.          return draw_polygon_ANY_pixmap;
  1730.       }
  1731.       return NULL;
  1732.    }
  1733. }
  1734.  
  1735.