home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / types.h < prev    next >
C/C++ Source or Header  |  2000-01-07  |  70KB  |  2,186 lines

  1. /* -*- mode: C; tab-width:8; c-basic-offset:8 -*- */
  2. /* $Id: types.h,v 1.18.2.6 1999/12/21 17:22:40 keithw Exp $ */
  3.  
  4. /*
  5.  * Mesa 3-D graphics library
  6.  * Version:  3.1
  7.  * 
  8.  * Copyright (C) 1999  Brian Paul   All Rights Reserved.
  9.  * 
  10.  * Permission is hereby granted, free of charge, to any person obtaining a
  11.  * copy of this software and associated documentation files (the "Software"),
  12.  * to deal in the Software without restriction, including without limitation
  13.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14.  * and/or sell copies of the Software, and to permit persons to whom the
  15.  * Software is furnished to do so, subject to the following conditions:
  16.  * 
  17.  * The above copyright notice and this permission notice shall be included
  18.  * in all copies or substantial portions of the Software.
  19.  * 
  20.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  23.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  24.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  25.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26.  */
  27.  
  28.  
  29.  
  30.  
  31.  
  32. #ifndef TYPES_H
  33. #define TYPES_H
  34.  
  35.  
  36. #include "GL/gl.h"
  37. #ifdef HAVE_CONFIG_H
  38. #include "conf.h"
  39. #endif
  40. #include "config.h"
  41. #include "macros.h"
  42. #include "fixed.h"
  43. #include "extensions.h"
  44. #include "vector.h"
  45. #include "matrix.h"
  46. #include "vb.h"
  47.  
  48. /*
  49. #if !defined(MESA_MINOR_VERSION) || !defined(MESA_MAJOR_VERSION)
  50. #error "Compiling with non-Mesa GL.h"
  51. #endif
  52.  
  53. #if (MESA_MINOR_VERSION != 1) || (MESA_MAJOR_VERSION != 3)
  54. #error "Compiling with GL.h from a different Mesa version"
  55. #endif
  56. */
  57.  
  58. /* This should rev. quite quickly - perhaps every time this file is
  59.  * committed, to allow dependent projects to track changes to mesa's
  60.  * internals.
  61.  */
  62. #define MESA_BRANCH 0
  63. #define MESA_TINY_VERSION 2
  64. #define MESA_VERSION MESA_VER(MESA_MAJOR_VERSION, \
  65.                               MESA_MINOR_VERSION, \
  66.                               MESA_BRANCH, \
  67.                               MESA_TINY_VERSION)
  68.  
  69. #define MESA_VER(x,y,z,w) ((x<<24)+(y<<16)+(z<<10)+w)
  70.  
  71.  
  72. #define GL_MAX_TEXTURES GL_MAX_TEXTURES_SGIS
  73.  
  74.  
  75. /*
  76.  * Color channel data type:
  77.  */
  78. #if CHAN_BITS==8
  79.    typedef GLubyte GLchan;
  80. #elif CHAN_BITS==16
  81.    typedef GLushort GLchan;
  82. #else
  83.    illegal number of color channel bits
  84. #endif
  85.  
  86.  
  87. /*
  88.  * Accumulation buffer data type:
  89.  */
  90. #if ACCUM_BITS==8
  91.    typedef GLbyte GLaccum;
  92. #elif ACCUM_BITS==16
  93.    typedef GLshort GLaccum;
  94. #else
  95. #  error "illegal number of accumulation bits"
  96. #endif
  97.  
  98.  
  99. /*
  100.  * Stencil buffer data type:
  101.  */
  102. #if STENCIL_BITS==8
  103.    typedef GLubyte GLstencil;
  104. #  define STENCIL_MAX 0xff
  105. #elif STENCIL_BITS==16
  106.    typedef GLushort GLstencil
  107. #  define STENCIL_MAX 0xffff
  108. #else
  109. #  error "illegal number of stencil bits"
  110. #endif
  111.  
  112.  
  113.  
  114. /*
  115.  * Depth buffer data type:
  116.  */
  117. #if DEPTH_BITS==16
  118.    typedef GLushort GLdepth;
  119. #elif DEPTH_BITS==32
  120.    typedef GLint GLdepth;
  121. #else
  122. #  error "illegal number of depth bits"
  123. #endif
  124.  
  125.  
  126.  
  127. /*
  128.  * Some forward type declarations
  129.  */
  130. struct HashTable;
  131.  
  132. typedef struct gl_visual GLvisual;
  133.  
  134. typedef struct gl_frame_buffer GLframebuffer;
  135.  
  136. struct gl_pixelstore_attrib;
  137.  
  138.  
  139. /*
  140.  * Functions for transformation of normals in the VB.
  141.  */
  142. typedef void (*normal_func)( const GLmatrix *mat,
  143.                  GLfloat scale,
  144.                  const GLvector3f *in,
  145.                  const GLfloat lengths[],
  146.                  const GLubyte mask[],
  147.                  GLvector3f *dest );
  148.  
  149.  
  150.  
  151. /*
  152.  * Point, line, triangle, quadrilateral and rectangle rasterizer functions:
  153.  */
  154. typedef void (*points_func)( GLcontext *ctx, GLuint first, GLuint last );
  155.  
  156. typedef void (*line_func)( GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv );
  157.  
  158. typedef void (*triangle_func)( GLcontext *ctx,
  159.                                GLuint v1, GLuint v2, GLuint v3, GLuint pv );
  160.  
  161. typedef void (*quad_func)( GLcontext *ctx, GLuint v1, GLuint v2,
  162.                            GLuint v3, GLuint v4, GLuint pv );
  163.  
  164. typedef void (*rect_func)( GLcontext *ctx, GLint x, GLint y,
  165.                            GLint width, GLint height );
  166.  
  167.  
  168.  
  169. /*
  170.  * The auxiliary interpolation function for clipping - now always in 
  171.  * clip space.
  172.  */
  173. typedef void (*clip_interp_func)( struct vertex_buffer *VB, GLuint dst,
  174.                                   GLfloat t, GLuint in, GLuint out );
  175.  
  176.  
  177. /*
  178.  * Renders vertices in vertex buffer
  179.  */
  180. typedef void (*render_vb_func)( GLcontext *ctx );
  181.  
  182.  
  183. /*
  184.  * Blending function
  185.  */
  186. typedef void (*blend_func)( GLcontext *ctx, GLuint n, const GLubyte mask[],
  187.                             GLubyte src[][4], CONST GLubyte dst[][4] );
  188.  
  189.  
  190.  
  191. /*
  192.  * For texture sampling:
  193.  */
  194. struct gl_texture_object;
  195.  
  196. typedef void (*TextureSampleFunc)( const struct gl_texture_object *tObj,
  197.                                    GLuint n,
  198.                                    const GLfloat s[], const GLfloat t[],
  199.                                    const GLfloat u[], const GLfloat lambda[],
  200.                                    GLubyte rgba[][4] );
  201.  
  202.  
  203.  
  204. /* Generic internal image format */
  205. struct gl_image {
  206.     GLint Width;
  207.     GLint Height;
  208.     GLint Depth;        /* for 3-D texturing */
  209.     GLint Components;    /* 1, 2, 3 or 4 */
  210.         GLenum Format;        /* GL_COLOR_INDEX, GL_RED, GL_RGB, etc */
  211.     GLenum Type;        /* GL_UNSIGNED_BYTE or GL_FLOAT or GL_BITMAP */
  212.     GLvoid *Data;
  213.     GLboolean ErrorFlag;
  214.     GLint RefCount;
  215. };
  216.  
  217.  
  218.  
  219. /* Texture image record */
  220. struct gl_texture_image {
  221.     GLenum Format;        /* GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
  222.                  * GL_INTENSITY, GL_RGB, GL_RGBA, or
  223.                  * GL_COLOR_INDEX only
  224.                  */
  225.     GLenum IntFormat;    /* Internal format as given by the user */
  226.         GLubyte RedBits;    /* Bits per texel component              */
  227.         GLubyte GreenBits;    /*   These are initialized by Mesa but   */
  228.         GLubyte BlueBits;    /*   may be reassigned by the device     */
  229.         GLubyte AlphaBits;    /*   driver to indicate the true texture */
  230.         GLubyte IntensityBits;    /*   color resolution.                   */
  231.         GLubyte LuminanceBits;
  232.         GLubyte IndexBits;
  233.     GLuint Border;        /* 0 or 1 */
  234.     GLuint Width;        /* = 2^WidthLog2 + 2*Border */
  235.     GLuint Height;        /* = 2^HeightLog2 + 2*Border */
  236.     GLuint Depth;        /* = 2^DepthLog2 + 2*Border */
  237.     GLuint Width2;        /* = Width - 2*Border */
  238.     GLuint Height2;        /* = Height - 2*Border */
  239.     GLuint Depth2;        /* = Depth - 2*Border */
  240.     GLuint WidthLog2;    /* = log2(Width2) */
  241.     GLuint HeightLog2;    /* = log2(Height2) */
  242.     GLuint DepthLog2;    /* = log2(Depth2) */
  243.     GLuint MaxLog2;        /* = MAX(WidthLog2, HeightLog2) */
  244.     GLubyte *Data;        /* Image data as unsigned bytes */
  245.  
  246.     /* For device driver: */
  247.     void *DriverData;    /* Arbitrary device driver data */
  248. };
  249.  
  250.  
  251. /*
  252.  * All gl* API functions in api*.c jump through pointers in this struct.
  253.  */
  254. struct gl_api_table {
  255.    void (*Accum)( GLcontext *, GLenum, GLfloat );
  256.    void (*AlphaFunc)( GLcontext *, GLenum, GLclampf );
  257.    GLboolean (*AreTexturesResident)( GLcontext *, GLsizei,
  258.                                      const GLuint *, GLboolean * );
  259.    void (*BindTexture)( GLcontext *, GLenum, GLuint );
  260.    void (*Bitmap)( GLcontext *, GLsizei, GLsizei, GLfloat, GLfloat,
  261.                    GLfloat, GLfloat, const GLubyte *,
  262.                    const struct gl_pixelstore_attrib *packing );
  263.    void (*BlendColor)( GLcontext *, GLclampf, GLclampf, GLclampf, GLclampf);
  264.    void (*BlendEquation)( GLcontext *, GLenum );
  265.    void (*BlendFunc)( GLcontext *, GLenum, GLenum );
  266.    void (*BlendFuncSeparate)( GLcontext *, GLenum, GLenum, GLenum, GLenum );
  267.    void (*CallList)( GLcontext *, GLuint list );
  268.    void (*CallLists)( GLcontext *, GLsizei, GLenum, const GLvoid * );
  269.    void (*Clear)( GLcontext *, GLbitfield );
  270.    void (*ClearAccum)( GLcontext *, GLfloat, GLfloat, GLfloat, GLfloat );
  271.    void (*ClearColor)( GLcontext *, GLclampf, GLclampf, GLclampf, GLclampf );
  272.    void (*ClearDepth)( GLcontext *, GLclampd );
  273.    void (*ClearIndex)( GLcontext *, GLfloat );
  274.    void (*ClearStencil)( GLcontext *, GLint );
  275.    void (*ClipPlane)( GLcontext *, GLenum, const GLfloat * );
  276.    void (*ColorMask)( GLcontext *,
  277.             GLboolean, GLboolean, GLboolean, GLboolean );
  278.    void (*ColorMaterial)( GLcontext *, GLenum, GLenum );
  279.    void (*ColorTable)( GLcontext *, GLenum, GLenum, struct gl_image * );
  280.    void (*ColorSubTable)( GLcontext *, GLenum, GLsizei, struct gl_image * );
  281.    void (*CopyPixels)( GLcontext *, GLint, GLint, GLsizei, GLsizei, GLenum );
  282.    void (*CopyTexImage1D)( GLcontext *, GLenum, GLint, GLenum,
  283.                            GLint, GLint, GLsizei, GLint );
  284.    void (*CopyTexImage2D)( GLcontext *, GLenum, GLint, GLenum,
  285.                            GLint, GLint, GLsizei, GLsizei, GLint );
  286.    void (*CopyTexSubImage1D)( GLcontext *, GLenum, GLint, GLint,
  287.                               GLint, GLint, GLsizei );
  288.    void (*CopyTexSubImage2D)( GLcontext *, GLenum, GLint, GLint, GLint,
  289.                               GLint, GLint, GLsizei, GLsizei );
  290.    void (*CopyTexSubImage3D)(GLcontext *, GLenum, GLint, GLint, GLint, GLint,
  291.                              GLint, GLint, GLsizei, GLsizei  );
  292.    void (*CullFace)( GLcontext *, GLenum );
  293.    void (*DeleteLists)( GLcontext *, GLuint, GLsizei );
  294.    void (*DeleteTextures)( GLcontext *, GLsizei, const GLuint *);
  295.    void (*DepthFunc)( GLcontext *, GLenum );
  296.    void (*DepthMask)( GLcontext *, GLboolean );
  297.    void (*DepthRange)( GLcontext *, GLclampd, GLclampd );
  298.    void (*Disable)( GLcontext *, GLenum );
  299.    void (*DisableClientState)( GLcontext *, GLenum );
  300.    void (*DrawBuffer)( GLcontext *, GLenum );
  301.    void (*DrawPixels)( GLcontext *, struct gl_image *image );
  302.    void (*Enable)( GLcontext *, GLenum );
  303.    void (*Error)( GLcontext *, GLenum, const char * );
  304.    void (*EnableClientState)( GLcontext *, GLenum );
  305.    void (*EndList)( GLcontext * );
  306.    void (*EvalMesh1)( GLcontext *, GLenum, GLint, GLint );
  307.    void (*EvalMesh2)( GLcontext *, GLenum, GLint, GLint, GLint, GLint );
  308.    void (*FeedbackBuffer)( GLcontext *, GLsizei, GLenum, GLfloat * );
  309.    void (*Finish)( GLcontext * );
  310.    void (*Flush)( GLcontext * );
  311.    void (*Fogfv)( GLcontext *, GLenum, const GLfloat * );
  312.    void (*FrontFace)( GLcontext *, GLenum );
  313.    void (*Frustum)( GLcontext *, GLdouble, GLdouble, GLdouble, GLdouble,
  314.                     GLdouble, GLdouble );
  315.    GLuint (*GenLists)( GLcontext *, GLsizei );
  316.    void (*GenTextures)( GLcontext *, GLsizei, GLuint * );
  317.    void (*GetBooleanv)( GLcontext *, GLenum, GLboolean * );
  318.    void (*GetClipPlane)( GLcontext *, GLenum, GLdouble * );
  319.    void (*GetColorTable)( GLcontext *, GLenum, GLenum, GLenum, GLvoid *);
  320.    void (*GetColorTableParameteriv)( GLcontext *, GLenum, GLenum, GLint *);
  321.    void (*GetDoublev)( GLcontext *, GLenum, GLdouble * );
  322.    GLenum (*GetError)( GLcontext * );
  323.    void (*GetFloatv)( GLcontext *, GLenum, GLfloat * );
  324.    void (*GetIntegerv)( GLcontext *, GLenum, GLint * );
  325.    const GLubyte* (*GetString)( GLcontext *, GLenum name );
  326.    void (*GetLightfv)( GLcontext *, GLenum light, GLenum, GLfloat * );
  327.    void (*GetLightiv)( GLcontext *, GLenum light, GLenum, GLint * );
  328.    void (*GetMapdv)( GLcontext *, GLenum, GLenum, GLdouble * );
  329.    void (*GetMapfv)( GLcontext *, GLenum, GLenum, GLfloat * );
  330.    void (*GetMapiv)( GLcontext *, GLenum, GLenum, GLint * );
  331.    void (*GetMaterialfv)( GLcontext *, GLenum, GLenum, GLfloat * );
  332.    void (*GetMaterialiv)( GLcontext *, GLenum, GLenum, GLint * );
  333.    void (*GetPixelMapfv)( GLcontext *, GLenum, GLfloat * );
  334.    void (*GetPixelMapuiv)( GLcontext *, GLenum, GLuint * );
  335.    void (*GetPixelMapusv)( GLcontext *, GLenum, GLushort * );
  336.    void (*GetPointerv)( GLcontext *, GLenum, GLvoid ** );
  337.    void (*GetPolygonStipple)( GLcontext *, GLubyte * );
  338.    void (*PrioritizeTextures)( GLcontext *, GLsizei, const GLuint *,
  339.                                const GLclampf * );
  340.    void (*GetTexEnvfv)( GLcontext *, GLenum, GLenum, GLfloat * );
  341.    void (*GetTexEnviv)( GLcontext *, GLenum, GLenum, GLint * );
  342.    void (*GetTexGendv)( GLcontext *, GLenum coord, GLenum, GLdouble * );
  343.    void (*GetTexGenfv)( GLcontext *, GLenum coord, GLenum, GLfloat * );
  344.    void (*GetTexGeniv)( GLcontext *, GLenum coord, GLenum, GLint * );
  345.    void (*GetTexImage)( GLcontext *, GLenum, GLint level, GLenum, GLenum,
  346.                         GLvoid * );
  347.    void (*GetTexLevelParameterfv)( GLcontext *,
  348.                      GLenum, GLint, GLenum, GLfloat * );
  349.    void (*GetTexLevelParameteriv)( GLcontext *,
  350.                      GLenum, GLint, GLenum, GLint * );
  351.    void (*GetTexParameterfv)( GLcontext *, GLenum, GLenum, GLfloat *);
  352.    void (*GetTexParameteriv)( GLcontext *, GLenum, GLenum, GLint * );
  353.    GLboolean (*Hint)( GLcontext *, GLenum, GLenum );
  354.    void (*IndexMask)( GLcontext *, GLuint );
  355.    void (*InitNames)( GLcontext * );
  356.    GLboolean (*IsEnabled)( GLcontext *, GLenum );
  357.    GLboolean (*IsList)( GLcontext *, GLuint );
  358.    GLboolean (*IsTexture)( GLcontext *, GLuint );
  359.    void (*LightModelfv)( GLcontext *, GLenum, const GLfloat * );
  360.    void (*Lightfv)( GLcontext *, GLenum light, GLenum, const GLfloat *, GLint);
  361.    void (*LineStipple)( GLcontext *, GLint factor, GLushort );
  362.    void (*LineWidth)( GLcontext *, GLfloat );
  363.    void (*ListBase)( GLcontext *, GLuint );
  364.    void (*LoadIdentity)( GLcontext * );
  365.    /* LoadMatrixd implemented with glLoadMatrixf */
  366.    void (*LoadMatrixf)( GLcontext *, const GLfloat * );
  367.    void (*LoadName)( GLcontext *, GLuint );
  368.    void (*LogicOp)( GLcontext *, GLenum );
  369.    void (*Map1f)( GLcontext *, GLenum, GLfloat, GLfloat, GLint, GLint,
  370.           const GLfloat *, GLboolean );
  371.    void (*Map2f)( GLcontext *, GLenum, GLfloat, GLfloat, GLint, GLint,
  372.           GLfloat, GLfloat, GLint, GLint, const GLfloat *,
  373.           GLboolean );
  374.    void (*MapGrid1f)( GLcontext *, GLint, GLfloat, GLfloat );
  375.    void (*MapGrid2f)( GLcontext *, GLint, GLfloat, GLfloat,
  376.             GLint, GLfloat, GLfloat );
  377.    void (*MatrixMode)( GLcontext *, GLenum );
  378.    /* MultMatrixd implemented with glMultMatrixf */
  379.    void (*MultMatrixf)( GLcontext *, const GLfloat * );
  380.    void (*NewList)( GLcontext *, GLuint list, GLenum );
  381.    void (*Ortho)( GLcontext *, GLdouble, GLdouble, GLdouble, GLdouble,
  382.                   GLdouble, GLdouble );
  383.    void (*PassThrough)( GLcontext *, GLfloat );
  384.    void (*PixelMapfv)( GLcontext *, GLenum, GLint, const GLfloat * );
  385.    void (*PixelStorei)( GLcontext *, GLenum, GLint );
  386.    void (*PixelTransferf)( GLcontext *, GLenum, GLfloat );
  387.    void (*PixelZoom)( GLcontext *, GLfloat, GLfloat );
  388.    void (*PointParameterfvEXT)( GLcontext *, GLenum, const GLfloat * );
  389.    void (*PointSize)( GLcontext *, GLfloat );
  390.    void (*PolygonMode)( GLcontext *, GLenum, GLenum );
  391.    void (*PolygonOffset)( GLcontext *, GLfloat, GLfloat );
  392.    void (*PolygonStipple)( GLcontext *, const GLuint * );
  393.    void (*PopAttrib)( GLcontext * );
  394.    void (*PopClientAttrib)( GLcontext * );
  395.    void (*PopMatrix)( GLcontext * );
  396.    void (*PopName)( GLcontext * );
  397.    void (*PushAttrib)( GLcontext *, GLbitfield );
  398.    void (*PushClientAttrib)( GLcontext *, GLbitfield );
  399.    void (*PushMatrix)( GLcontext * );
  400.    void (*PushName)( GLcontext *, GLuint );
  401.    void (*RasterPos4f)( GLcontext *,
  402.                         GLfloat x, GLfloat y, GLfloat z, GLfloat w );
  403.    void (*ReadBuffer)( GLcontext *, GLenum );
  404.    void (*ReadPixels)( GLcontext *, GLint, GLint, GLsizei, GLsizei, GLenum,
  405.              GLenum, GLvoid * );
  406.    void (*Rectf)( GLcontext *, GLfloat, GLfloat, GLfloat, GLfloat );
  407.    GLint (*RenderMode)( GLcontext *, GLenum );
  408.    void (*Rotatef)( GLcontext *, GLfloat, GLfloat, GLfloat, GLfloat );
  409.    void (*Scalef)( GLcontext *, GLfloat, GLfloat, GLfloat );
  410.    void (*Scissor)( GLcontext *, GLint, GLint, GLsizei, GLsizei);
  411.    void (*SelectBuffer)( GLcontext *, GLsizei, GLuint * );
  412.    void (*ShadeModel)( GLcontext *, GLenum );
  413.    void (*StencilFunc)( GLcontext *, GLenum, GLint, GLuint );
  414.    void (*StencilMask)( GLcontext *, GLuint );
  415.    void (*StencilOp)( GLcontext *, GLenum, GLenum, GLenum );
  416.  
  417.    void (*TexEnvfv)( GLcontext *, GLenum, GLenum, const GLfloat * );
  418.    void (*TexGenfv)( GLcontext *, GLenum coord, GLenum, const GLfloat * );
  419.    void (*TexImage1D)( GLcontext *, GLenum, GLint, GLint, GLsizei,
  420.                        GLint, GLenum, GLenum, const GLvoid * );
  421.    void (*TexImage2D)( GLcontext *, GLenum, GLint, GLint, GLsizei, GLsizei,
  422.                        GLint, GLenum, GLenum, const GLvoid *);
  423.    void (*TexSubImage1D)( GLcontext *, GLenum, GLint, GLint, GLsizei,
  424.                           GLenum, GLenum, const GLvoid * );
  425.    void (*TexSubImage2D)( GLcontext *, GLenum, GLint, GLint, GLint,
  426.                           GLsizei, GLsizei, GLenum, GLenum, const GLvoid *);
  427.    void (*TexImage3D)(GLcontext *, GLenum, GLint, GLint, GLsizei, GLsizei,
  428.                       GLsizei, GLint, GLenum, GLenum, const GLvoid *);
  429.    void (*TexSubImage3D)(GLcontext *, GLenum, GLint, GLint, GLint, GLint,
  430.                          GLsizei, GLsizei, GLsizei, GLenum, GLenum,
  431.                          const GLvoid *);
  432.    void (*TexParameterfv)( GLcontext *, GLenum, GLenum, const GLfloat * );
  433.    /* Translated implemented by Translatef */
  434.    void (*Translatef)( GLcontext *, GLfloat, GLfloat, GLfloat );
  435.  
  436.    void (*Viewport)( GLcontext *, GLint, GLint, GLsizei, GLsizei );
  437.  
  438.    /* GL_MESA_window_pos extension */
  439.    void (*WindowPos4fMESA)( GLcontext *, GLfloat, GLfloat, GLfloat, GLfloat );
  440.  
  441.    /* GL_MESA_resize_buffers extension */
  442.    void (*ResizeBuffersMESA)( GLcontext * );
  443.  
  444.    /* GL_ARB_multitexture */
  445.    void (*ActiveTexture)( GLcontext *, GLenum );
  446.    void (*ClientActiveTexture)( GLcontext *, GLenum );
  447. };
  448.  
  449.  
  450.  
  451. typedef void (*render_func)( struct vertex_buffer *VB, 
  452.                  GLuint start,
  453.                  GLuint count,
  454.                  GLuint parity );
  455.  
  456.  
  457.  
  458.  
  459.  
  460. /* This has to included here. */
  461. #include "dd.h"
  462.  
  463.  
  464. /*
  465.  * Bit flags used for updating material values.
  466.  */
  467. #define FRONT_AMBIENT_BIT     0x1
  468. #define BACK_AMBIENT_BIT      0x2
  469. #define FRONT_DIFFUSE_BIT     0x4
  470. #define BACK_DIFFUSE_BIT      0x8
  471. #define FRONT_SPECULAR_BIT   0x10
  472. #define BACK_SPECULAR_BIT    0x20
  473. #define FRONT_EMISSION_BIT   0x40
  474. #define BACK_EMISSION_BIT    0x80
  475. #define FRONT_SHININESS_BIT 0x100
  476. #define BACK_SHININESS_BIT  0x200
  477. #define FRONT_INDEXES_BIT   0x400
  478. #define BACK_INDEXES_BIT    0x800
  479.  
  480. #define FRONT_MATERIAL_BITS    (FRONT_EMISSION_BIT | FRONT_AMBIENT_BIT | \
  481.                  FRONT_DIFFUSE_BIT | FRONT_SPECULAR_BIT | \
  482.                  FRONT_SHININESS_BIT | FRONT_INDEXES_BIT)
  483.  
  484. #define BACK_MATERIAL_BITS    (BACK_EMISSION_BIT | BACK_AMBIENT_BIT | \
  485.                  BACK_DIFFUSE_BIT | BACK_SPECULAR_BIT | \
  486.                  BACK_SHININESS_BIT | BACK_INDEXES_BIT)
  487.  
  488. #define ALL_MATERIAL_BITS    (FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
  489.  
  490.  
  491.  
  492. /*
  493.  * Specular exponent and material shininess lookup table sizes:
  494.  */
  495. #define EXP_TABLE_SIZE 512
  496. #define SHINE_TABLE_SIZE 256
  497.  
  498. struct gl_light {
  499.         struct gl_light *next;            /* double linked list with sentinel */
  500.         struct gl_light *prev;
  501.  
  502.     GLfloat Ambient[4];        /* ambient color */
  503.     GLfloat Diffuse[4];        /* diffuse color */
  504.     GLfloat Specular[4];        /* specular color */
  505.     GLfloat EyePosition[4];        /* position in eye coordinates */
  506.     GLfloat EyeDirection[4];    /* spotlight dir in eye coordinates */
  507.     GLfloat SpotExponent;
  508.     GLfloat SpotCutoff;        /* in degress */
  509.         GLfloat CosCutoff;        /* = MAX(0, cos(SpotCutoff)) */
  510.     GLfloat ConstantAttenuation;
  511.     GLfloat LinearAttenuation;
  512.     GLfloat QuadraticAttenuation;
  513.     GLboolean Enabled;        /* On/off flag */
  514.  
  515.     /* Derived fields */
  516.         GLuint Flags;        /* State */
  517.  
  518.     GLfloat Position[4];        /* position in eye/obj coordinates */
  519.     GLfloat VP_inf_norm[3];        /* Norm direction to infinite light */
  520.     GLfloat h_inf_norm[3];        /* Norm( VP_inf_norm + <0,0,1> ) */
  521.         GLfloat NormDirection[4];    /* normalized spotlight direction */
  522.         GLfloat VP_inf_spot_attenuation; 
  523.  
  524.         GLfloat SpotExpTable[EXP_TABLE_SIZE][2];  /* to replace a pow() call */
  525.     GLfloat MatAmbient[2][3];    /* material ambient * light ambient */
  526.     GLfloat MatDiffuse[2][3];    /* material diffuse * light diffuse */
  527.     GLfloat MatSpecular[2][3];    /* material spec * light specular */
  528.     GLfloat dli;            /* CI diffuse light intensity */
  529.     GLfloat sli;            /* CI specular light intensity */
  530.         GLboolean IsMatSpecular[2];
  531. };
  532.  
  533.  
  534. struct gl_lightmodel {
  535.     GLfloat Ambient[4];        /* ambient color */
  536.     GLboolean LocalViewer;        /* Local (or infinite) view point? */
  537.     GLboolean TwoSide;        /* Two (or one) sided lighting? */
  538.     GLenum ColorControl;        /* either GL_SINGLE_COLOR */
  539.                     /* or GL_SEPARATE_SPECULAR_COLOR */
  540. };
  541.  
  542.  
  543. /*
  544.  * Attribute structures:
  545.  *    We define a struct for each attribute group to make pushing and
  546.  *    popping attributes easy.  Also it's a good organization.
  547.  */
  548.  
  549.  
  550. struct gl_accum_attrib {
  551.     GLfloat ClearColor[4];    /* Accumulation buffer clear color */
  552. };
  553.  
  554.  
  555. /*
  556.  * Used in DrawDestMask below
  557.  */
  558. #define FRONT_LEFT_BIT  1
  559. #define FRONT_RIGHT_BIT 2
  560. #define BACK_LEFT_BIT   4
  561. #define BACK_RIGHT_BIT  8
  562.  
  563.  
  564. struct gl_colorbuffer_attrib {
  565.     GLuint ClearIndex;        /* Index to use for glClear */
  566.     GLfloat ClearColor[4];        /* Color to use for glClear */
  567.  
  568.     GLuint IndexMask;        /* Color index write mask */
  569.     GLubyte ColorMask[4];        /* Each flag is 0xff or 0x0 */
  570.         GLboolean SWmasking;        /* Do color/CI masking in software? */
  571.  
  572.     GLenum DrawBuffer;        /* Which buffer to draw into */
  573.     GLenum DriverDrawBuffer;    /* Current device driver dest buffer */
  574.     GLboolean MultiDrawBuffer;    /* Drawing to mutliple buffers? */
  575.         GLubyte DrawDestMask;        /* bitwise-OR of bitflags above */
  576.  
  577.     /* alpha testing */
  578.     GLboolean AlphaEnabled;        /* Alpha test enabled flag */
  579.     GLenum AlphaFunc;        /* Alpha test function */
  580.     GLubyte AlphaRef;        /* Alpha ref value in range [0,255] */
  581.  
  582.     /* blending */
  583.     GLboolean BlendEnabled;        /* Blending enabled flag */
  584.     GLenum BlendSrcRGB;        /* Blending source operator */
  585.     GLenum BlendDstRGB;        /* Blending destination operator */
  586.     GLenum BlendSrcA;        /* GL_INGR_blend_func_separate */
  587.     GLenum BlendDstA;        /* GL_INGR_blend_func_separate */
  588.     GLenum BlendEquation;
  589.     GLfloat BlendColor[4];
  590.     blend_func BlendFunc;        /* Points to C blending function */
  591.  
  592.     /* logic op */
  593.     GLenum LogicOp;            /* Logic operator */
  594.     GLboolean IndexLogicOpEnabled;    /* Color index logic op enabled flag */
  595.     GLboolean ColorLogicOpEnabled;    /* RGBA logic op enabled flag */
  596.     GLboolean SWLogicOpEnabled;    /* Do logic ops in software? */
  597.  
  598.     GLboolean DitherFlag;        /* Dither enable flag */
  599. };
  600.  
  601.  
  602. struct gl_current_attrib {
  603.  
  604.     /* KW: These values valid only when the VB is flushed.  
  605.      */
  606.     GLuint Flag;                        /* Contains size information */
  607.     GLfloat Normal[3];
  608.     GLubyte ByteColor[4];            /* Current RGBA color */
  609.     GLuint Index;                /* Current color index */
  610.     GLboolean EdgeFlag;            /* Current edge flag */
  611.     GLfloat Texcoord[MAX_TEXTURE_UNITS][4];    /* Current texture coords */
  612.     GLenum Primitive;                    /* Prim or GL_POLYGON+1 */
  613.     
  614.     /* KW: No change to these values.
  615.      */
  616.     GLfloat RasterPos[4];            /* Current raster position */
  617.     GLfloat RasterDistance;            /* Current raster distance */
  618.     GLfloat RasterColor[4];            /* Current raster color */
  619.     GLuint  RasterIndex;            /* Current raster index */
  620.     GLfloat *RasterTexCoord;        /* Current raster texcoord*/
  621.     GLfloat RasterMultiTexCoord[MAX_TEXTURE_UNITS][4];
  622.     GLboolean RasterPosValid;        /* Raster po valid flag */
  623. };
  624.  
  625.  
  626. struct gl_depthbuffer_attrib {
  627.     GLenum Func;        /* Function for depth buffer compare */
  628.     GLfloat Clear;        /* Value to clear depth buffer to */
  629.     GLboolean Test;        /* Depth buffering enabled flag */
  630.     GLboolean Mask;        /* Depth buffer writable? */
  631. };
  632.  
  633.  
  634. struct gl_enable_attrib {
  635.     GLboolean AlphaTest;
  636.     GLboolean AutoNormal;
  637.     GLboolean Blend;
  638.     GLboolean ClipPlane[MAX_CLIP_PLANES];
  639.     GLboolean ColorMaterial;
  640.     GLboolean CullFace;
  641.     GLboolean DepthTest;
  642.     GLboolean Dither;
  643.     GLboolean Fog;
  644.     GLboolean Light[MAX_LIGHTS];
  645.     GLboolean Lighting;
  646.     GLboolean LineSmooth;
  647.     GLboolean LineStipple;
  648.     GLboolean IndexLogicOp;
  649.     GLboolean ColorLogicOp;
  650.     GLboolean Map1Color4;
  651.     GLboolean Map1Index;
  652.     GLboolean Map1Normal;
  653.     GLboolean Map1TextureCoord1;
  654.     GLboolean Map1TextureCoord2;
  655.     GLboolean Map1TextureCoord3;
  656.     GLboolean Map1TextureCoord4;
  657.     GLboolean Map1Vertex3;
  658.     GLboolean Map1Vertex4;
  659.     GLboolean Map2Color4;
  660.     GLboolean Map2Index;
  661.     GLboolean Map2Normal;
  662.     GLboolean Map2TextureCoord1;
  663.     GLboolean Map2TextureCoord2;
  664.     GLboolean Map2TextureCoord3;
  665.     GLboolean Map2TextureCoord4;
  666.     GLboolean Map2Vertex3;
  667.     GLboolean Map2Vertex4;
  668.     GLboolean Normalize;
  669.     GLboolean PointSmooth;
  670.     GLboolean PolygonOffsetPoint;
  671.     GLboolean PolygonOffsetLine;
  672.     GLboolean PolygonOffsetFill;
  673.     GLboolean PolygonSmooth;
  674.     GLboolean PolygonStipple;
  675.     GLboolean RescaleNormals;
  676.     GLboolean Scissor;
  677.     GLboolean Stencil;
  678.     GLuint Texture;
  679.     GLuint TexGen[MAX_TEXTURE_UNITS];
  680. };
  681.  
  682.  
  683. struct gl_eval_attrib {
  684.     /* Enable bits */
  685.     GLboolean Map1Color4;
  686.     GLboolean Map1Index;
  687.     GLboolean Map1Normal;
  688.     GLboolean Map1TextureCoord1;
  689.     GLboolean Map1TextureCoord2;
  690.     GLboolean Map1TextureCoord3;
  691.     GLboolean Map1TextureCoord4;
  692.     GLboolean Map1Vertex3;
  693.     GLboolean Map1Vertex4;
  694.     GLboolean Map2Color4;
  695.     GLboolean Map2Index;
  696.     GLboolean Map2Normal;
  697.     GLboolean Map2TextureCoord1;
  698.     GLboolean Map2TextureCoord2;
  699.     GLboolean Map2TextureCoord3;
  700.     GLboolean Map2TextureCoord4;
  701.     GLboolean Map2Vertex3;
  702.     GLboolean Map2Vertex4;
  703.     GLboolean AutoNormal;
  704.     /* Map Grid endpoints and divisions and calculated du values */
  705.     GLint MapGrid1un;
  706.     GLfloat MapGrid1u1, MapGrid1u2, MapGrid1du;
  707.     GLint MapGrid2un, MapGrid2vn;
  708.     GLfloat MapGrid2u1, MapGrid2u2, MapGrid2du;
  709.     GLfloat MapGrid2v1, MapGrid2v2, MapGrid2dv;
  710. };
  711.  
  712.  
  713. struct gl_fog_attrib {
  714.     GLboolean Enabled;        /* Fog enabled flag */
  715.     GLfloat Color[4];        /* Fog color */
  716.     GLfloat Density;        /* Density >= 0.0 */
  717.     GLfloat Start;            /* Start distance in eye coords */
  718.     GLfloat End;            /* End distance in eye coords */
  719.     GLfloat Index;            /* Fog index */
  720.     GLenum Mode;            /* Fog mode */
  721. };
  722.  
  723.  
  724. struct gl_hint_attrib {
  725.     /* always one of GL_FASTEST, GL_NICEST, or GL_DONT_CARE */
  726.     GLenum PerspectiveCorrection;
  727.     GLenum PointSmooth;
  728.     GLenum LineSmooth;
  729.     GLenum PolygonSmooth;
  730.     GLenum Fog;
  731.  
  732.     /* GL_PGI_misc_hints */
  733.     GLenum AllowDrawWin;
  734.     GLenum AllowDrawSpn;
  735.     GLenum AllowDrawMem;
  736.     GLenum StrictLighting;
  737.  
  738.     /* GL_EXT_clip_volume_hint */
  739.     GLenum ClipVolumeClipping;
  740. };
  741.  
  742.  
  743. struct gl_light_attrib {
  744.    struct gl_light Light[MAX_LIGHTS];    /* Array of lights */
  745.    struct gl_lightmodel Model;        /* Lighting model */
  746.    struct gl_material Material[2];    /* Material 0=front, 1=back */
  747.    GLboolean Enabled;            /* Lighting enabled flag */
  748.    GLenum ShadeModel;            /* GL_FLAT or GL_SMOOTH */
  749.    GLenum ColorMaterialFace;        /* GL_FRONT, BACK or FRONT_AND_BACK */
  750.    GLenum ColorMaterialMode;        /* GL_AMBIENT, GL_DIFFUSE, etc */
  751.    GLuint ColorMaterialBitmask;        /* bitmask formed from Face and Mode */
  752.    GLboolean ColorMaterialEnabled;
  753.  
  754.    struct gl_light EnabledList;         /* List sentinel */
  755.  
  756.    /* Derived for optimizations: */
  757.    GLboolean NeedVertices;        /* Use fast shader? */
  758.    GLuint  Flags;                /* State, see below */
  759.    GLfloat BaseColor[2][3];
  760.    GLubyte BaseAlpha[2];
  761. };
  762.  
  763.  
  764. #define LIGHT_POSITIONAL   0x4
  765. #define LIGHT_SPECULAR     0x8
  766. #define LIGHT_SPOT         0x10
  767. #define LIGHT_LOCAL_VIEWER 0x20
  768. #define LIGHT_TWO_SIDE     0x40
  769.  
  770. #define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
  771.  
  772. struct gl_line_attrib {
  773.     GLboolean SmoothFlag;        /* GL_LINE_SMOOTH enabled? */
  774.     GLboolean StippleFlag;        /* GL_LINE_STIPPLE enabled? */
  775.     GLushort StipplePattern;    /* Stipple pattern */
  776.     GLint StippleFactor;        /* Stipple repeat factor */
  777.     GLfloat Width;            /* Line width */
  778. };
  779.  
  780.  
  781. struct gl_list_attrib {
  782.     GLuint ListBase;
  783. };
  784.  
  785.  
  786. struct gl_pixel_attrib {
  787.     GLenum ReadBuffer;        /* src buffer for glRead/CopyPixels */
  788.     GLenum DriverReadBuffer;    /* Driver's current source buffer */
  789.     GLfloat RedBias, RedScale;
  790.     GLfloat GreenBias, GreenScale;
  791.     GLfloat BlueBias, BlueScale;
  792.     GLfloat AlphaBias, AlphaScale;
  793.     GLboolean ScaleOrBiasRGBA;
  794.     GLfloat DepthBias, DepthScale;
  795.     GLint IndexShift, IndexOffset;
  796.     GLboolean MapColorFlag;
  797.     GLboolean MapStencilFlag;
  798.     GLfloat ZoomX;            /* Pixel zoom X factor */
  799.     GLfloat ZoomY;            /* Pixel zoom Y factor */
  800.     GLint MapStoSsize;        /* Size of each pixel map */
  801.     GLint MapItoIsize;
  802.     GLint MapItoRsize;
  803.     GLint MapItoGsize;
  804.     GLint MapItoBsize;
  805.     GLint MapItoAsize;
  806.     GLint MapRtoRsize;
  807.     GLint MapGtoGsize;
  808.     GLint MapBtoBsize;
  809.     GLint MapAtoAsize;
  810.     GLint MapStoS[MAX_PIXEL_MAP_TABLE];    /* Pixel map tables */
  811.     GLint MapItoI[MAX_PIXEL_MAP_TABLE];
  812.     GLfloat MapItoR[MAX_PIXEL_MAP_TABLE];
  813.     GLfloat MapItoG[MAX_PIXEL_MAP_TABLE];
  814.     GLfloat MapItoB[MAX_PIXEL_MAP_TABLE];
  815.     GLfloat MapItoA[MAX_PIXEL_MAP_TABLE];
  816.     GLubyte MapItoR8[MAX_PIXEL_MAP_TABLE];  /* converted to 8-bit color */
  817.     GLubyte MapItoG8[MAX_PIXEL_MAP_TABLE];
  818.     GLubyte MapItoB8[MAX_PIXEL_MAP_TABLE];
  819.     GLubyte MapItoA8[MAX_PIXEL_MAP_TABLE];
  820.     GLfloat MapRtoR[MAX_PIXEL_MAP_TABLE];
  821.     GLfloat MapGtoG[MAX_PIXEL_MAP_TABLE];
  822.     GLfloat MapBtoB[MAX_PIXEL_MAP_TABLE];
  823.     GLfloat MapAtoA[MAX_PIXEL_MAP_TABLE];
  824. };
  825.  
  826.  
  827. struct gl_point_attrib {
  828.     GLboolean SmoothFlag;    /* True if GL_POINT_SMOOTH is enabled */
  829.     GLfloat Size;        /* Point size */
  830.     GLfloat Params[3];    /* Point Parameters EXT distance atenuation 
  831.                    factors by default = {1,0,0} */ 
  832.     GLfloat MinSize;    /* Default 0.0 always >=0 */
  833.     GLfloat MaxSize;    /* Default MAX_POINT_SIZE */
  834.     GLfloat Threshold;    /* Default 1.0 */ 
  835.     GLboolean Attenuated;
  836. };
  837.  
  838.  
  839. struct gl_polygon_attrib {
  840.     GLenum FrontFace;    /* Either GL_CW or GL_CCW */
  841.     GLenum FrontMode;    /* Either GL_POINT, GL_LINE or GL_FILL */
  842.     GLenum BackMode;    /* Either GL_POINT, GL_LINE or GL_FILL */
  843.     GLboolean FrontBit;    /*  */
  844.     GLboolean Unfilled;    /* True if back or front mode is not GL_FILL */
  845.     GLboolean CullFlag;    /* Culling on/off flag */
  846.         GLubyte CullBits;    /* Used for cull testing */
  847.     GLboolean SmoothFlag;    /* True if GL_POLYGON_SMOOTH is enabled */
  848.     GLboolean StippleFlag;    /* True if GL_POLYGON_STIPPLE is enabled */
  849.     GLenum CullFaceMode;    /* Culling mode GL_FRONT or GL_BACK */
  850.         GLfloat OffsetFactor;    /* Polygon offset factor */
  851.         GLfloat OffsetUnits;    /* Polygon offset units */
  852.         GLboolean OffsetPoint;    /* Offset in GL_POINT mode? */
  853.         GLboolean OffsetLine;    /* Offset in GL_LINE mode? */
  854.         GLboolean OffsetFill;    /* Offset in GL_FILL mode? */
  855.  
  856. };
  857.  
  858.  
  859. struct gl_scissor_attrib {
  860.     GLboolean Enabled;        /* Scissor test enabled? */
  861.     GLint X, Y;            /* Lower left corner of box */
  862.     GLsizei Width, Height;        /* Size of box */
  863. };
  864.  
  865.  
  866. struct gl_stencil_attrib {
  867.     GLboolean Enabled;        /* Enabled flag */
  868.     GLenum Function;        /* Stencil function */
  869.     GLenum FailFunc;        /* Fail function */
  870.     GLenum ZPassFunc;        /* Depth buffer pass function */
  871.     GLenum ZFailFunc;        /* Depth buffer fail function */
  872.     GLstencil Ref;            /* Reference value */
  873.     GLstencil ValueMask;        /* Value mask */
  874.     GLstencil Clear;        /* Clear value */
  875.     GLstencil WriteMask;        /* Write mask */
  876. };
  877.  
  878.  
  879. /* TexGenEnabled flags */
  880. #define S_BIT 1
  881. #define T_BIT 2
  882. #define R_BIT 4
  883. #define Q_BIT 8
  884.  
  885. /* Texture Enabled flags */
  886. #define TEXTURE0_1D S_BIT     /* Texture unit 0 (default) */
  887. #define TEXTURE0_2D T_BIT
  888. #define TEXTURE0_3D R_BIT
  889. #define TEXTURE0_ANY (TEXTURE0_1D | TEXTURE0_2D | TEXTURE0_3D)
  890. #define TEXTURE1_1D (S_BIT<<4)    /* Texture unit 1 */
  891. #define TEXTURE1_2D (T_BIT<<4)
  892. #define TEXTURE1_3D (R_BIT<<4)
  893. #define TEXTURE1_ANY (TEXTURE1_1D | TEXTURE1_2D | TEXTURE1_3D)
  894.  
  895. /* Bitmap versions of the GL_ constants.
  896.  */
  897. #define TEXGEN_SPHERE_MAP        0x1
  898. #define TEXGEN_OBJ_LINEAR        0x2
  899. #define TEXGEN_EYE_LINEAR        0x4
  900. #define TEXGEN_REFLECTION_MAP_NV 0x8
  901. #define TEXGEN_NORMAL_MAP_NV     0x10
  902.  
  903. #define TEXGEN_NEED_M            (TEXGEN_SPHERE_MAP)
  904. #define TEXGEN_NEED_F            (TEXGEN_SPHERE_MAP        | \
  905.                   TEXGEN_REFLECTION_MAP_NV)
  906. #define TEXGEN_NEED_NORMALS      (TEXGEN_SPHERE_MAP        | \
  907.                   TEXGEN_REFLECTION_MAP_NV | \
  908.                   TEXGEN_NORMAL_MAP_NV)
  909. #define TEXGEN_NEED_VERTICES     (TEXGEN_OBJ_LINEAR |         \
  910.                   TEXGEN_EYE_LINEAR |        \
  911.                   TEXGEN_REFLECTION_MAP_NV |    \
  912.                   TEXGEN_SPHERE_MAP )
  913. #define TEXGEN_NEED_EYE_COORD    (TEXGEN_SPHERE_MAP        | \
  914.                   TEXGEN_REFLECTION_MAP_NV | \
  915.                   TEXGEN_NORMAL_MAP_NV     | \
  916.                   TEXGEN_EYE_LINEAR)
  917.  
  918.  
  919. /* A selection of state flags to make choosing optimized pipelines easier.
  920.  */
  921. #define ENABLE_TEX0         0xf    /* TEXTURE0_ANY */
  922. #define ENABLE_TEX1         0xf0   /* TEXTURE1_ANY */
  923. #define ENABLE_LIGHT        0x100
  924. #define ENABLE_FOG          0x200
  925. #define ENABLE_USERCLIP     0x400
  926. #define ENABLE_TEXGEN0      0x800
  927. #define ENABLE_TEXGEN1      0x1000
  928. #define ENABLE_TEXMAT0      0x2000    /* Ie. not the identity matrix */
  929. #define ENABLE_TEXMAT1      0x4000
  930. #define ENABLE_VIEWCLIP     0x8000
  931. #define ENABLE_NORMALIZE    0x10000
  932. #define ENABLE_RESCALE      0x20000
  933. #define ENABLE_POINT_ATTEN  0x40000
  934.  
  935.  
  936. #define ENABLE_TEX_ANY  (ENABLE_TEX0 | ENABLE_TEX1)
  937.  
  938.  
  939. typedef void (*texgen_func)( struct vertex_buffer *VB, 
  940.                  GLuint textureSet);
  941.  
  942.  
  943. /* Texture object record */
  944. struct gl_texture_object {
  945.     GLint RefCount;            /* reference count */
  946.     GLuint Name;            /* an unsigned integer */
  947.     GLuint Dimensions;        /* 1 or 2 or 3 */
  948.     GLfloat Priority;        /* in [0,1] */
  949.     GLubyte BorderColor[4];        /* as integers in [0,255] */
  950.     GLenum WrapS;            /* GL_CLAMP, REPEAT or CLAMP_TO_EDGE */
  951.     GLenum WrapT;            /* GL_CLAMP, REPEAT or CLAMP_TO_EDGE */
  952.     GLenum WrapR;            /* GL_CLAMP, REPEAT or CLAMP_TO_EDGE */
  953.     GLenum MinFilter;        /* minification filter */
  954.     GLenum MagFilter;        /* magnification filter */
  955.     GLfloat MinLod;            /* OpenGL 1.2 */
  956.     GLfloat MaxLod;            /* OpenGL 1.2 */
  957.     GLint BaseLevel;        /* OpenGL 1.2 */
  958.     GLint MaxLevel;            /* OpenGL 1.2 */
  959.     GLint P;            /* Highest mipmap level */
  960.     GLfloat M;            /* = MIN(MaxLevel, P) - BaseLevel */
  961.     GLfloat MinMagThresh;        /* min/mag threshold */
  962.     struct gl_texture_image *Image[MAX_TEXTURE_LEVELS];
  963.  
  964.     /* GL_EXT_paletted_texture */
  965.     GLubyte Palette[MAX_TEXTURE_PALETTE_SIZE*4];
  966.     GLuint PaletteSize;
  967.     GLenum PaletteIntFormat;
  968.     GLenum PaletteFormat;
  969.  
  970.     /* For device driver: */
  971.     GLboolean Dirty;    /* Is this texture object in dirty list? */
  972.     void *DriverData;    /* Arbitrary device driver data */
  973.  
  974.     GLboolean Complete;        /* Complete set of images? */
  975.     TextureSampleFunc SampleFunc;    /* The texel sampling function */
  976.     struct gl_texture_object *Next;        /* Next in linked list */
  977.     struct gl_texture_object *NextDirty;    /* Next in dirty linked list */
  978. };
  979.  
  980.  
  981.  
  982. /*
  983.  * Texture units are new with the multitexture extension.
  984.  */
  985. struct gl_texture_unit {
  986.     GLuint Enabled;
  987.     GLuint ReallyEnabled;
  988.  
  989.     GLenum EnvMode;        /* GL_MODULATE, GL_DECAL, GL_BLEND */
  990.     GLenum LastEnvMode;
  991.  
  992.     GLfloat EnvColor[4];
  993.     GLuint TexGenEnabled;    /* Bitwise-OR of [STRQ]_BIT values */
  994.     GLenum GenModeS;    /* Tex coord generation mode, either */
  995.     GLenum GenModeT;    /*    GL_OBJECT_LINEAR, or */
  996.     GLenum GenModeR;    /*    GL_EYE_LINEAR, or    */
  997.     GLenum GenModeQ;    /*      GL_SPHERE_MAP        */
  998.     GLuint GenBitS;
  999.     GLuint GenBitT;
  1000.     GLuint GenBitR;
  1001.     GLuint GenBitQ;
  1002.     GLuint GenFlags;    /* bitwise or of GenBit[STRQ] */
  1003.     GLfloat ObjectPlaneS[4];
  1004.     GLfloat ObjectPlaneT[4];
  1005.     GLfloat ObjectPlaneR[4];
  1006.     GLfloat ObjectPlaneQ[4];
  1007.     GLfloat EyePlaneS[4];
  1008.     GLfloat EyePlaneT[4];
  1009.     GLfloat EyePlaneR[4];
  1010.     GLfloat EyePlaneQ[4];
  1011.     texgen_func *func;    /* points to array of func pointers */
  1012.     GLubyte Holes;        /* elements not generated by texgen */
  1013.     GLuint  TexgenSize;    /* size of element generated */
  1014.     GLboolean AnyTransform;    /* texgen or non-identity matrix */
  1015.  
  1016.     struct gl_texture_object *CurrentD[4];
  1017.     struct gl_texture_object *Current;
  1018.     GLuint CurrentDimension;
  1019.  
  1020.     struct gl_texture_object Saved1D;  /* only used by glPush/PopAttrib */
  1021.     struct gl_texture_object Saved2D;
  1022.     struct gl_texture_object Saved3D;
  1023. };
  1024.  
  1025.  
  1026. struct gl_texture_attrib {
  1027.     /* multitexture */
  1028.     GLuint CurrentUnit;            /* Current texture unit */
  1029.     GLuint CurrentTransformUnit;        /* Current texture xform unit */
  1030.  
  1031.     /* Bitwise-OR of TEXTURE_XD values */
  1032.     GLuint Enabled;        /* Enabled by the user */
  1033.     GLuint ReallyEnabled;    /* Really enabled (w.r.t. completeness, etc) */
  1034.     
  1035.     GLuint LastEnabled;    /* Decide whether enabled has really changed */
  1036.  
  1037.     GLboolean NeedNormals;
  1038.     GLboolean NeedEyeCoords;
  1039.  
  1040.     struct gl_texture_unit Unit[MAX_TEXTURE_UNITS];
  1041.     
  1042.     struct gl_texture_object *Proxy1D;
  1043.     struct gl_texture_object *Proxy2D;
  1044.     struct gl_texture_object *Proxy3D;
  1045.  
  1046.     /* GL_EXT_shared_texture_palette */
  1047.     GLboolean SharedPalette;
  1048.     GLubyte Palette[MAX_TEXTURE_PALETTE_SIZE*4];
  1049.     GLuint PaletteSize;
  1050.     GLenum PaletteIntFormat;
  1051.     GLenum PaletteFormat;
  1052.  
  1053.     /* GL_EXT_texture_env_add */
  1054.     GLboolean ExtAddEnv;    /* is the extension enabled? */
  1055. };
  1056.  
  1057.  
  1058.  
  1059. /* KW: Renamed ClipEquation to avoid having 'ClipClipEquation'
  1060.  */
  1061. struct gl_transform_attrib {
  1062.     GLenum MatrixMode;            /* Matrix mode */
  1063.     GLfloat EyeUserPlane[MAX_CLIP_PLANES][4];
  1064.     GLfloat ClipUserPlane[MAX_CLIP_PLANES][4]; /* derived */
  1065.     GLboolean ClipEnabled[MAX_CLIP_PLANES];
  1066.     GLubyte   AnyClip;            /* How many ClipEnabled? */
  1067.     GLboolean Normalize;            /* Normalize all normals? */
  1068.     GLboolean RescaleNormals;        /* GL_EXT_rescale_normal */
  1069. };
  1070.  
  1071.  
  1072. struct gl_viewport_attrib {
  1073.     GLint X, Y;        /* position */
  1074.     GLsizei Width, Height;    /* size */
  1075.     GLfloat Near, Far;    /* Depth buffer range */
  1076.         GLmatrix WindowMap;    /* Mapping transformation as a matrix. */
  1077. };
  1078.  
  1079.  
  1080. /* For the attribute stack: */
  1081. struct gl_attrib_node {
  1082.     GLbitfield kind;
  1083.     void *data;
  1084.     struct gl_attrib_node *next;
  1085. };
  1086.  
  1087.  
  1088.  
  1089. /*
  1090.  * Client pixel packing/unpacking attributes
  1091.  */
  1092. struct gl_pixelstore_attrib {
  1093.     GLint Alignment;
  1094.     GLint RowLength;
  1095.     GLint SkipPixels;
  1096.     GLint SkipRows;
  1097.     GLint ImageHeight;     /* for GL_EXT_texture3D */
  1098.     GLint SkipImages;      /* for GL_EXT_texture3D */
  1099.     GLboolean SwapBytes;
  1100.     GLboolean LsbFirst;
  1101. };
  1102.  
  1103.  
  1104. /*
  1105.  * Client vertex array attributes
  1106.  */
  1107. struct gl_client_array {
  1108.    GLint Size;
  1109.    GLenum Type;
  1110.    GLsizei Stride;        /* user-specified stride */
  1111.    GLsizei StrideB;        /* actual stride in bytes */
  1112.    void *Ptr;
  1113.    GLboolean Enabled;
  1114. };
  1115.  
  1116.  
  1117. /* KW:  New functions to populate a vector from data of a different type.
  1118.  *      Used in the array interface.  Flags & match only used in the
  1119.  *      specialized array-element case.
  1120.  */
  1121. typedef void (*trans_1ui_func)(GLuint *to,
  1122.                    const struct gl_client_array *from,
  1123.                    GLuint start, 
  1124.                    GLuint n );
  1125.  
  1126. typedef void (*trans_1ub_func)(GLubyte *to,
  1127.                    const struct gl_client_array *from,
  1128.                    GLuint start,
  1129.                    GLuint n );
  1130.  
  1131. typedef void (*trans_4ub_func)(GLubyte (*to)[4],
  1132.                    const struct gl_client_array *from,
  1133.                    GLuint start,
  1134.                    GLuint n );
  1135.  
  1136. typedef void (*trans_4f_func)(GLfloat (*to)[4],
  1137.                   const struct gl_client_array *from,
  1138.                   GLuint start, 
  1139.                   GLuint n );
  1140.  
  1141. typedef void (*trans_3f_func)(GLfloat (*to)[3],
  1142.                   const struct gl_client_array *from,
  1143.                   GLuint start, 
  1144.                   GLuint n );
  1145.  
  1146.  
  1147.  
  1148. typedef void (*trans_elt_1ui_func)(GLuint *to,
  1149.                    const struct gl_client_array *from,
  1150.                    GLuint *flags, 
  1151.                    GLuint *elts, 
  1152.                    GLuint match,
  1153.                    GLuint start,
  1154.                    GLuint n );
  1155.  
  1156. typedef void (*trans_elt_1ub_func)(GLubyte *to,
  1157.                    const struct gl_client_array *from,
  1158.                    GLuint *flags, 
  1159.                    GLuint *elts, 
  1160.                    GLuint match,
  1161.                    GLuint start,
  1162.                    GLuint n );
  1163.  
  1164. typedef void (*trans_elt_4ub_func)(GLubyte (*to)[4],
  1165.                    const struct gl_client_array *from,
  1166.                    GLuint *flags, 
  1167.                    GLuint *elts, 
  1168.                    GLuint match,
  1169.                    GLuint start,
  1170.                    GLuint n );
  1171.  
  1172. typedef void (*trans_elt_4f_func)(GLfloat (*to)[4],
  1173.                   const struct gl_client_array *from,
  1174.                   GLuint *flags, 
  1175.                   GLuint *elts, 
  1176.                   GLuint match,
  1177.                   GLuint start,
  1178.                   GLuint n );
  1179.  
  1180. typedef void (*trans_elt_3f_func)(GLfloat (*to)[3],
  1181.                   const struct gl_client_array *from,
  1182.                   GLuint *flags, 
  1183.                   GLuint *elts, 
  1184.                   GLuint match,
  1185.                   GLuint start,
  1186.                   GLuint n );
  1187.  
  1188.  
  1189.  
  1190. struct gl_array_attrib {
  1191.     struct gl_client_array Vertex;         /* client data descriptors */
  1192.     struct gl_client_array Normal;
  1193.     struct gl_client_array Color;
  1194.     struct gl_client_array Index;
  1195.     struct gl_client_array TexCoord[MAX_TEXTURE_UNITS];
  1196.     struct gl_client_array EdgeFlag;
  1197.  
  1198.     trans_4f_func  VertexFunc;       /* conversion functions */
  1199.     trans_3f_func  NormalFunc;  
  1200.     trans_4ub_func ColorFunc;   
  1201.     trans_1ui_func IndexFunc;
  1202.     trans_4f_func  TexCoordFunc[MAX_TEXTURE_UNITS];
  1203.     trans_1ub_func EdgeFlagFunc;
  1204.  
  1205.     trans_elt_4f_func  VertexEltFunc; /* array elt conversion functions */
  1206.     trans_elt_3f_func  NormalEltFunc;  
  1207.     trans_elt_4ub_func ColorEltFunc;   
  1208.     trans_elt_1ui_func IndexEltFunc;
  1209.     trans_elt_4f_func  TexCoordEltFunc[MAX_TEXTURE_UNITS];
  1210.     trans_elt_1ub_func EdgeFlagEltFunc;
  1211.  
  1212.     GLint TexCoordInterleaveFactor;
  1213.     GLint ActiveTexture;        /* Client Active Texture */
  1214.  
  1215.     GLuint LockFirst;
  1216.     GLuint LockCount;
  1217.     
  1218.     GLuint Flag[VB_SIZE];    /* crock */
  1219.           GLuint Flags;
  1220.     GLuint Summary;        /* Like flags, but no size information */
  1221.     GLuint NewArrayState;    /* Tracks which arrays have been changed. */
  1222. };
  1223.  
  1224.  
  1225. /* These are used to make the ctx->Current values look like
  1226.  * arrays (with zero StrideB).
  1227.  */
  1228. struct gl_fallback_arrays {
  1229.     struct gl_client_array Normal;
  1230.     struct gl_client_array Color;
  1231.     struct gl_client_array Index;
  1232.     struct gl_client_array TexCoord[MAX_TEXTURE_UNITS];
  1233.     struct gl_client_array EdgeFlag;
  1234. };
  1235.  
  1236. #define MAX_PIPELINE_STAGES     30
  1237.  
  1238. #define PIPE_IMMEDIATE          0x1
  1239. #define PIPE_PRECALC            0x2
  1240.  
  1241. #define PIPE_OP_VERT_XFORM      0x1
  1242. #define PIPE_OP_NORM_XFORM      0x2
  1243. #define PIPE_OP_LIGHT           0x4
  1244. #define PIPE_OP_FOG             0x8
  1245. #define PIPE_OP_TEX0            0x10
  1246. #define PIPE_OP_TEX1            0x20
  1247. #define PIPE_OP_RAST_SETUP_0    0x40
  1248. #define PIPE_OP_RAST_SETUP_1    0x80
  1249. #define PIPE_OP_RENDER          0x100
  1250. #define PIPE_OP_CVA_PREPARE     0x200
  1251.  
  1252.  
  1253. /* Nodes in a state machine to drive rendering of the various
  1254.  * point/line/tri primitives.
  1255.  */
  1256. struct gl_prim_state {
  1257.     GLuint v0, v1;
  1258.     GLboolean draw;
  1259.     GLboolean finish_loop;    /* not used... */
  1260.     struct gl_prim_state *next;
  1261. };
  1262.  
  1263.  
  1264. typedef void (*vb_func)( struct vertex_buffer *VB );
  1265. typedef void (*ctx_func)( GLcontext * );
  1266.  
  1267. struct gl_pipeline_stage {
  1268.     const char *name;
  1269.     GLuint ops;             /* PIPE_OP flags */
  1270.     GLuint type;             /* PIPE flags */
  1271.     GLuint special;             /* PIPE flags - force update_inputs() */
  1272.     GLuint state_change;         /* state flags - trigger update_inputs() */
  1273.     GLuint cva_state_change;     /* state flags - recalc cva buffer */
  1274.     GLuint elt_forbidden_inputs; /* VERT flags - force a pipeline recalc */
  1275.     GLuint pre_forbidden_inputs; /* VERT flags - force a pipeline recalc */
  1276.     GLuint active;             /* PIPE flags */
  1277.     GLuint inputs;             /* VERT flags */
  1278.     GLuint outputs;             /* VERT flags */
  1279.     void (*check)( GLcontext *ctx, struct gl_pipeline_stage * );
  1280.     void (*run)( struct vertex_buffer *VB );
  1281. };
  1282.  
  1283.  
  1284. struct gl_pipeline {
  1285.     GLuint state_change;     /* state changes which require recalc */
  1286.     GLuint cva_state_change; /* ... which require re-run */
  1287.     GLuint forbidden_inputs; /* inputs which require recalc */
  1288.     GLuint ops;         /* what gets done in this pipe */
  1289.     GLuint changed_ops;
  1290.     GLuint inputs;
  1291.     GLuint outputs;
  1292.     GLuint new_inputs;
  1293.     GLuint new_outputs;
  1294.     GLuint fallback;
  1295.     GLuint type;
  1296.     GLuint pipeline_valid:1;
  1297.     GLuint data_valid:1;
  1298.     GLuint copy_transformed_data:1;
  1299.     GLuint replay_copied_vertices:1;
  1300.     GLuint new_state;     /* state changes since last recalc */
  1301.     struct gl_pipeline_stage *stages[MAX_PIPELINE_STAGES];
  1302. };
  1303.  
  1304.  
  1305. struct gl_cva {
  1306.     struct gl_pipeline pre;
  1307.     struct gl_pipeline elt;
  1308.     
  1309.     struct gl_client_array Elt;
  1310.     trans_1ui_func EltFunc;
  1311.  
  1312.     struct vertex_buffer *VB;
  1313.     struct vertex_arrays v;
  1314.     struct vertex_data store;
  1315.  
  1316.     GLuint elt_count;
  1317.     GLenum elt_mode;
  1318.     GLuint elt_size;
  1319.  
  1320.     GLuint forbidden_inputs;
  1321.     GLuint orflag;
  1322.     GLuint merge;
  1323.  
  1324.     GLuint lock_changed;
  1325.     GLuint last_orflag;
  1326.     GLuint last_array_flags;
  1327.     GLuint last_array_new_state;
  1328. };
  1329.  
  1330.  
  1331. struct gl_feedback {
  1332.     GLenum Type;
  1333.     GLuint Mask;
  1334.     GLfloat *Buffer;
  1335.     GLuint BufferSize;
  1336.     GLuint Count;
  1337. };
  1338.  
  1339.  
  1340.  
  1341. struct gl_selection {
  1342.     GLuint *Buffer;
  1343.     GLuint BufferSize;    /* size of SelectBuffer */
  1344.     GLuint BufferCount;    /* number of values in SelectBuffer */
  1345.     GLuint Hits;        /* number of records in SelectBuffer */
  1346.     GLuint NameStackDepth;
  1347.     GLuint NameStack[MAX_NAME_STACK_DEPTH];
  1348.     GLboolean HitFlag;
  1349.     GLfloat HitMinZ, HitMaxZ;
  1350. };
  1351.  
  1352.  
  1353.  
  1354. /*
  1355.  * 1-D Evaluator control points
  1356.  */
  1357. struct gl_1d_map {
  1358.     GLuint Order;        /* Number of control points */
  1359.     GLfloat u1, u2, du;    /* u1, u2, 1.0/(u2-u1) */
  1360.     GLfloat *Points;    /* Points to contiguous control points */
  1361.     GLboolean Retain;    /* Reference counter */
  1362. };
  1363.     
  1364.  
  1365. /*
  1366.  * 2-D Evaluator control points
  1367.  */
  1368. struct gl_2d_map {
  1369.     GLuint Uorder;        /* Number of control points in U dimension */
  1370.     GLuint Vorder;        /* Number of control points in V dimension */
  1371.     GLfloat u1, u2, du;
  1372.     GLfloat v1, v2, dv;
  1373.     GLfloat *Points;    /* Points to contiguous control points */
  1374.     GLboolean Retain;    /* Reference counter */
  1375. };
  1376.  
  1377.  
  1378. /*
  1379.  * All evalutator control points
  1380.  */
  1381. struct gl_evaluators {
  1382.     /* 1-D maps */
  1383.     struct gl_1d_map Map1Vertex3;
  1384.     struct gl_1d_map Map1Vertex4;
  1385.     struct gl_1d_map Map1Index;
  1386.     struct gl_1d_map Map1Color4;
  1387.     struct gl_1d_map Map1Normal;
  1388.     struct gl_1d_map Map1Texture1;
  1389.     struct gl_1d_map Map1Texture2;
  1390.     struct gl_1d_map Map1Texture3;
  1391.     struct gl_1d_map Map1Texture4;
  1392.  
  1393.     /* 2-D maps */
  1394.     struct gl_2d_map Map2Vertex3;
  1395.     struct gl_2d_map Map2Vertex4;
  1396.     struct gl_2d_map Map2Index;
  1397.     struct gl_2d_map Map2Color4;
  1398.     struct gl_2d_map Map2Normal;
  1399.     struct gl_2d_map Map2Texture1;
  1400.     struct gl_2d_map Map2Texture2;
  1401.     struct gl_2d_map Map2Texture3;
  1402.     struct gl_2d_map Map2Texture4;
  1403. };
  1404.  
  1405.  
  1406.  
  1407. /*
  1408.  * State which can be shared by multiple contexts:
  1409.  */
  1410. struct gl_shared_state {
  1411.    GLint RefCount;               /* Reference count */
  1412.    struct HashTable *DisplayList;       /* Display lists hash table */
  1413.    struct HashTable *TexObjects;       /* Texture objects hash table */
  1414.    struct gl_texture_object *TexObjectList;/* Linked list of texture objects */
  1415.    struct gl_texture_object *DirtyTexObjList; /* List of dirty tex objects */
  1416.  
  1417.    /* Default texture objects (shared by all multi-texture units) */
  1418.    struct gl_texture_object *DefaultD[4];
  1419. };
  1420.  
  1421.  
  1422.  
  1423. /*
  1424.  * Describes the color, depth, stencil and accum buffer parameters.
  1425.  * In C++ terms, think of this as a base class from which device drivers
  1426.  * will make derived classes.
  1427.  */
  1428. struct gl_visual {
  1429.     GLboolean RGBAflag;    /* Is frame buffer in RGBA mode, not CI? */
  1430.     GLboolean DBflag;    /* Is color buffer double buffered? */
  1431.     GLboolean StereoFlag;    /* stereo buffer? */
  1432.  
  1433.     GLint RedBits;        /* Bits per color component */
  1434.     GLint GreenBits;
  1435.     GLint BlueBits;
  1436.     GLint AlphaBits;
  1437.  
  1438.     GLint IndexBits;    /* Bits/pixel if in color index mode */
  1439.  
  1440.     GLint AccumBits;    /* Number of bits per color channel, or 0 */
  1441.     GLint DepthBits;    /* Number of bits in depth buffer, or 0 */
  1442.     GLint StencilBits;    /* Number of bits in stencil buffer, or 0 */
  1443.  
  1444.     GLboolean SoftwareAlpha;/* Implement software alpha buffer? */
  1445. };
  1446.  
  1447.  
  1448.  
  1449. /*
  1450.  * A "frame buffer" is a color buffer and its optional ancillary buffers:
  1451.  * depth, accum, stencil, and software-simulated alpha buffers.
  1452.  * In C++ terms, think of this as a base class from which device drivers
  1453.  * will make derived classes.
  1454.  */
  1455. struct gl_frame_buffer {
  1456.     GLvisual *Visual;    /* The corresponding visual */
  1457.  
  1458.     GLint Width;        /* Width of frame buffer in pixels */
  1459.     GLint Height;        /* Height of frame buffer in pixels */
  1460.  
  1461.     GLdepth *Depth;        /* array [Width*Height] of GLdepth values */
  1462.  
  1463.     /* Stencil buffer */
  1464.     GLstencil *Stencil;    /* array [Width*Height] of GLstencil values */
  1465.  
  1466.     /* Accumulation buffer */
  1467.     GLaccum *Accum;        /* array [4*Width*Height] of GLaccum values */
  1468.  
  1469.     /* Software alpha planes: */
  1470.     GLubyte *FrontLeftAlpha;  /* array [Width*Height] of GLubyte */
  1471.     GLubyte *BackLeftAlpha;   /* array [Width*Height] of GLubyte */
  1472.     GLubyte *FrontRightAlpha; /* array [Width*Height] of GLubyte */
  1473.     GLubyte *BackRightAlpha;  /* array [Width*Height] of GLubyte */
  1474.     GLubyte *Alpha;           /* Points to current alpha buffer */
  1475.  
  1476.     /* Drawing bounds: intersection of window size and scissor box */
  1477.     GLint Xmin, Xmax, Ymin, Ymax;
  1478. };
  1479.  
  1480.  
  1481. /*
  1482.  * Constants which may be overriden by device driver.
  1483.  */
  1484. struct gl_constants {
  1485.    GLint MaxTextureSize;
  1486.    GLint MaxTextureLevels;
  1487.    GLuint MaxTextureUnits;
  1488.    GLuint MaxArrayLockSize;
  1489. };
  1490.  
  1491.  
  1492. /*
  1493.  * List of extensions.
  1494.  */
  1495. struct extension;
  1496. struct gl_extensions {
  1497.    char *ext_string;
  1498.    struct extension *ext_list;
  1499. };
  1500.  
  1501.  
  1502. /*
  1503.  * Bitmasks to indicate which rasterization options are enabled (RasterMask)
  1504.  */
  1505. #define ALPHATEST_BIT        0x001    /* Alpha-test pixels */
  1506. #define BLEND_BIT        0x002    /* Blend pixels */
  1507. #define DEPTH_BIT        0x004    /* Depth-test pixels */
  1508. #define FOG_BIT            0x008    /* Per-pixel fog */
  1509. #define LOGIC_OP_BIT        0x010    /* Apply logic op in software */
  1510. #define SCISSOR_BIT        0x020    /* Scissor pixels */
  1511. #define STENCIL_BIT        0x040    /* Stencil pixels */
  1512. #define MASKING_BIT        0x080    /* Do glColorMask or glIndexMask */
  1513. #define ALPHABUF_BIT        0x100    /* Using software alpha buffer */
  1514. #define WINCLIP_BIT        0x200    /* Clip pixels/primitives to window */
  1515. #define MULTI_DRAW_BIT        0x400    /* Write to more than one color- */
  1516.                                         /* buffer or no buffers. */
  1517.  
  1518. /*
  1519.  * Bits to indicate what state has to be updated (NewState)
  1520.  */
  1521. #define NEW_LIGHTING            0x1
  1522. #define NEW_RASTER_OPS            0x2
  1523. #define NEW_TEXTURING            0x4
  1524. #define NEW_POLYGON            0x8
  1525. #define NEW_DRVSTATE0            0x10 /* Reserved for drivers */
  1526. #define NEW_DRVSTATE1            0x20 /* Reserved for drivers */
  1527. #define NEW_DRVSTATE2            0x40 /* Reserved for drivers */
  1528. #define NEW_DRVSTATE3            0x80 /* Reserved for drivers */
  1529. #define NEW_MODELVIEW            0x100
  1530. #define NEW_PROJECTION            0x200
  1531. #define NEW_TEXTURE_MATRIX    0x400
  1532. #define NEW_USER_CLIP            0x800
  1533. #define NEW_TEXTURE_ENV         0x1000
  1534. #define NEW_CLIENT_STATE        0x2000
  1535. #define NEW_FOG                 0x4000
  1536. #define NEW_NORMAL_TRANSFORM    0x8000
  1537. #define NEW_VIEWPORT            0x10000
  1538. #define NEW_TEXTURE_ENABLE      0x20000
  1539. #define NEW_ALL                ~0
  1540.  
  1541.  
  1542. #define NEW_DRIVER_STATE (NEW_DRVSTATE0 | NEW_DRVSTATE1 |    \
  1543.                           NEW_DRVSTATE2 | NEW_DRVSTATE3) 
  1544.  
  1545. /* What can the driver do, what requires us to call render_triangle or
  1546.  * a non-driver rasterize function?
  1547.  */
  1548. #define DD_FEEDBACK                 0x1
  1549. #define DD_SELECT                   0x2
  1550. #define DD_FLATSHADE                0x4
  1551. #define DD_MULTIDRAW                0x8
  1552. #define DD_SEPERATE_SPECULAR        0x10
  1553. #define DD_TRI_LIGHT_TWOSIDE        0x20
  1554. #define DD_TRI_UNFILLED             0x40
  1555. #define DD_TRI_SMOOTH               0x80
  1556. #define DD_TRI_STIPPLE              0x100
  1557. #define DD_TRI_OFFSET               0x200
  1558. #define DD_TRI_CULL                 0x400
  1559. #define DD_LINE_SMOOTH              0x800
  1560. #define DD_LINE_STIPPLE             0x1000
  1561. #define DD_LINE_WIDTH               0x2000
  1562. #define DD_POINT_SMOOTH             0x4000
  1563. #define DD_POINT_SIZE               0x8000
  1564. #define DD_POINT_ATTEN              0x10000
  1565. #define DD_LIGHTING_CULL            0x20000 /* never set by driver */
  1566. #define DD_POINT_SW_RASTERIZE       0x40000 
  1567. #define DD_LINE_SW_RASTERIZE        0x80000 
  1568. #define DD_TRI_SW_RASTERIZE         0x100000 
  1569. #define DD_QUAD_SW_RASTERIZE        0x200000 
  1570. #define DD_TRI_CULL_FRONT_BACK      0x400000 /* not supported by most drivers */
  1571. #define DD_Z_NEVER                  0x800000 
  1572. #define DD_STENCIL                  0x1000000 
  1573. #define DD_CLIP_FOG_COORD           0x2000000
  1574.  
  1575. #define DD_SW_SETUP           (DD_TRI_CULL|        \
  1576.                                DD_TRI_CULL_FRONT_BACK|    \
  1577.                                DD_TRI_OFFSET|        \
  1578.                    DD_TRI_LIGHT_TWOSIDE|    \
  1579.                                DD_TRI_UNFILLED)
  1580.  
  1581. #define DD_ANY_CULL           (DD_TRI_CULL_FRONT_BACK|    \
  1582.                                DD_TRI_CULL|        \
  1583.                                DD_LIGHTING_CULL)
  1584.  
  1585. #define DD_SW_RASTERIZE       (DD_POINT_SW_RASTERIZE|    \
  1586.                                DD_LINE_SW_RASTERIZE|    \
  1587.                                DD_TRI_SW_RASTERIZE|    \
  1588.                                DD_QUAD_SW_RASTERIZE)
  1589.  
  1590.  
  1591. /* Vertex buffer clipping flags 
  1592.  */
  1593. #define CLIP_RIGHT_SHIFT     0
  1594. #define CLIP_LEFT_SHIFT     1
  1595. #define CLIP_TOP_SHIFT      2
  1596. #define CLIP_BOTTOM_SHIFT       3
  1597. #define CLIP_NEAR_SHIFT      4
  1598. #define CLIP_FAR_SHIFT      5
  1599.  
  1600. #define CLIP_RIGHT_BIT   0x01
  1601. #define CLIP_LEFT_BIT    0x02
  1602. #define CLIP_TOP_BIT     0x04
  1603. #define CLIP_BOTTOM_BIT  0x08
  1604. #define CLIP_NEAR_BIT    0x10
  1605. #define CLIP_FAR_BIT     0x20
  1606. #define CLIP_USER_BIT    0x40
  1607. #define CLIP_CULLED_BIT  0x80    /* Vertex has been culled */
  1608. #define CLIP_ALL_BITS    0x3f
  1609.  
  1610.  
  1611. /*
  1612.  * Bits to indicate which faces a vertex participates in,
  1613.  * what facing the primitive provoked by that vertex has,
  1614.  * and some misc. flags.
  1615.  */
  1616. #define VERT_FACE_FRONT       0x1    /* is in a front-color primitive */
  1617. #define VERT_FACE_REAR        0x2    /* is in a rear-color primitive */
  1618. #define PRIM_FACE_FRONT       0x4    /* use front color */
  1619. #define PRIM_FACE_REAR        0x8    /* use rear color */
  1620. #define PRIM_CLIPPED          0x10    /* needs clipping */
  1621. #define PRIM_USER_CLIPPED     CLIP_USER_BIT    /* 0x40 */
  1622.  
  1623.  
  1624. #define PRIM_FLAG_SHIFT  2
  1625. #define PRIM_FACE_FLAGS  (PRIM_FACE_FRONT|PRIM_FACE_REAR)
  1626. #define VERT_FACE_FLAGS  (VERT_FACE_FRONT|VERT_FACE_REAR)
  1627.  
  1628. #define PRIM_ANY_CLIP    (PRIM_CLIPPED|PRIM_USER_CLIPPED)
  1629. #define PRIM_NOT_CULLED  (PRIM_ANY_CLIP|PRIM_FACE_FLAGS)
  1630.  
  1631. /* Flags for ctx->VB->CullMode.
  1632.  */
  1633. #define CULL_MASK_ACTIVE  0x1
  1634. #define COMPACTED_NORMALS 0x2
  1635. #define CLIP_MASK_ACTIVE  0x4
  1636.  
  1637. /* Flags for selecting a shading function.  The first two bits are
  1638.  * shared with the cull mode (ie. cull_mask_active and
  1639.  * compacted_normals.)
  1640.  */
  1641. #define SHADE_RGBA_VERTICES     0x4
  1642. #define SHADE_RGBA_NORMALS      0x8
  1643. #define SHADE_RGBA_SPEC         0xc /* note - not a seperate bit */
  1644. #define SHADE_TWOSIDE           0x10
  1645.  
  1646. /* Flags for selecting a normal transformation function. 
  1647.  */
  1648. #define NORM_RESCALE   0x1    /* apply the scale factor */
  1649. #define NORM_NORMALIZE 0x2    /* normalize */
  1650. #define NORM_TRANSFORM 0x4    /* apply the transformation matrix */
  1651. #define NORM_TRANSFORM_NO_ROT 0x8    /* apply the transformation matrix */
  1652.  
  1653.  
  1654. /*
  1655.  * Different kinds of 4x4 transformation matrices:
  1656.  */
  1657. #define MATRIX_GENERAL        0    /* general 4x4 matrix */
  1658. #define MATRIX_IDENTITY        1    /* identity matrix */
  1659. #define MATRIX_3D_NO_ROT    2    /* ortho projection and others... */
  1660. #define MATRIX_PERSPECTIVE    3    /* perspective projection matrix */
  1661. #define MATRIX_2D        4    /* 2-D transformation */
  1662. #define MATRIX_2D_NO_ROT    5    /* 2-D scale & translate only */
  1663. #define MATRIX_3D        6    /* 3-D transformation */
  1664.  
  1665. #define MAT_FLAG_IDENTITY        0
  1666. #define MAT_FLAG_GENERAL        0x1
  1667. #define MAT_FLAG_ROTATION       0x2
  1668. #define MAT_FLAG_TRANSLATION    0x4
  1669. #define MAT_FLAG_UNIFORM_SCALE  0x8
  1670. #define MAT_FLAG_GENERAL_SCALE  0x10
  1671. #define MAT_FLAG_GENERAL_3D     0x20
  1672. #define MAT_FLAG_PERSPECTIVE    0x40
  1673. #define MAT_DIRTY_TYPE          0x80
  1674. #define MAT_DIRTY_FLAGS         0x100
  1675. #define MAT_DIRTY_INVERSE       0x200
  1676. #define MAT_DIRTY_DEPENDENTS    0x400
  1677.  
  1678.  
  1679. /* Give symbolic names to some of the entries in the matrix to help
  1680.  * out with the rework of the viewport_map as a matrix transform.
  1681.  */
  1682. #define MAT_SX 0
  1683. #define MAT_SY 5
  1684. #define MAT_SZ 10
  1685. #define MAT_TX 12
  1686. #define MAT_TY 13
  1687. #define MAT_TZ 14
  1688.  
  1689.  
  1690. #define MAT_FLAGS_ANGLE_PRESERVING (MAT_FLAG_ROTATION | \
  1691.                     MAT_FLAG_TRANSLATION | \
  1692.                     MAT_FLAG_UNIFORM_SCALE)
  1693.  
  1694. #define MAT_FLAGS_LENGTH_PRESERVING (MAT_FLAG_ROTATION | \
  1695.                      MAT_FLAG_TRANSLATION)
  1696.  
  1697. #define MAT_FLAGS_3D (MAT_FLAG_ROTATION | \
  1698.               MAT_FLAG_TRANSLATION | \
  1699.               MAT_FLAG_UNIFORM_SCALE | \
  1700.               MAT_FLAG_GENERAL_SCALE | \
  1701.               MAT_FLAG_GENERAL_3D)
  1702.  
  1703. #define MAT_FLAGS_GEOMETRY (MAT_FLAG_GENERAL | \
  1704.                 MAT_FLAG_ROTATION | \
  1705.                 MAT_FLAG_TRANSLATION | \
  1706.                 MAT_FLAG_UNIFORM_SCALE | \
  1707.                 MAT_FLAG_GENERAL_SCALE | \
  1708.                 MAT_FLAG_GENERAL_3D | \
  1709.                 MAT_FLAG_PERSPECTIVE)
  1710.  
  1711. #define MAT_DIRTY_ALL_OVER (MAT_DIRTY_TYPE | \
  1712.                 MAT_DIRTY_DEPENDENTS | \
  1713.                 MAT_DIRTY_FLAGS | \
  1714.                 MAT_DIRTY_INVERSE)
  1715.  
  1716. #define TEST_MAT_FLAGS(mat, a)  ((MAT_FLAGS_GEOMETRY&(~(a))&((mat)->flags))==0)
  1717.  
  1718.  
  1719. /*
  1720.  * FogMode values:
  1721.  */
  1722. #define FOG_NONE    0    /* no fog */
  1723. #define FOG_VERTEX    1    /* apply per vertex */
  1724. #define FOG_FRAGMENT    2    /* apply per fragment */
  1725.  
  1726.  
  1727.  
  1728. typedef void (*gl_shade_func)( struct vertex_buffer *VB );
  1729.  
  1730.  
  1731.  
  1732. /*
  1733.  * Forward declaration of display list datatypes:
  1734.  */
  1735. union node;
  1736. typedef union node Node;
  1737.  
  1738.  
  1739.  
  1740.  
  1741. /* KW: Flags that describe the current vertex state, and the contents
  1742.  * of a vertex in a vertex-cassette.  
  1743.  *
  1744.  * For really major expansion, consider a 'VERT_ADDITIONAL_FLAGS' flag,
  1745.  * which means there is data in another flags array (eg, extra_flags[]).
  1746.  */
  1747.  
  1748. #define VERT_OBJ_2           0x1    /* glVertex2 */
  1749. #define VERT_OBJ_3           0x2        /* glVertex3 */
  1750. #define VERT_OBJ_4           0x4        /* glVertex4 */
  1751. #define VERT_BEGIN           0x8    /* glBegin */
  1752. #define VERT_END             0x10    /* glEnd */
  1753. #define VERT_ELT             0x20    /* glArrayElement */
  1754. #define VERT_RGBA            0x40    /* glColor */
  1755. #define VERT_NORM            0x80    /* glNormal */
  1756. #define VERT_INDEX           0x100    /* glIndex */
  1757. #define VERT_EDGE            0x200    /* glEdgeFlag */
  1758. #define VERT_MATERIAL        0x400    /* glMaterial */
  1759. #define VERT_TEX0_1          0x800       
  1760. #define VERT_TEX0_2          0x1000
  1761. #define VERT_TEX0_3          0x2000
  1762. #define VERT_TEX0_4          0x4000
  1763. #define VERT_TEX1_1          0x8000
  1764. #define VERT_TEX1_2          0x10000
  1765. #define VERT_TEX1_3          0x20000
  1766. #define VERT_TEX1_4          0x40000
  1767. #define VERT_TEX2_1          0x80000    /* 3rd texunit - reserved but unused */
  1768. #define VERT_TEX2_2          0x100000
  1769. #define VERT_TEX2_3          0x200000
  1770. #define VERT_TEX2_4          0x400000
  1771. #define VERT_END_VB          0x800000   /* end vb marker */
  1772. #define VERT_EVAL_C1         0x1000000  /* could reuse OBJ bits for this? */
  1773. #define VERT_EVAL_C2         0x2000000  /*    - or just use 3 bits */
  1774. #define VERT_EVAL_P1         0x4000000  /*  */
  1775. #define VERT_EVAL_P2         0x8000000  /*  */
  1776. #define VERT_FLOAT_RGBA      0x10000000    /* allow partial support for this */
  1777. #define VERT_FOG_COORD       0x20000000    /* internal use only, currently */
  1778.  
  1779. #define VERT_EYE             VERT_BEGIN /* for pipeline management & cva */
  1780. #define VERT_WIN             VERT_END   /* some overlaps can be tolerated */
  1781. #define VERT_SETUP_FULL      0x4000000
  1782. #define VERT_SETUP_PART      0x8000000
  1783. #define VERT_PRECALC_DATA    VERT_END_VB /* overlap! */
  1784.  
  1785. /* Shorthands.
  1786.  */
  1787. #define VERT_TEX0_SHIFT 11
  1788.  
  1789. #define VERT_EVAL_ANY      (VERT_EVAL_C1|VERT_EVAL_P1|    \
  1790.                             VERT_EVAL_C2|VERT_EVAL_P2)
  1791.  
  1792. #define VERT_OBJ_23       (VERT_OBJ_3|VERT_OBJ_2)
  1793. #define VERT_OBJ_234      (VERT_OBJ_4|VERT_OBJ_23)
  1794. #define VERT_OBJ_ANY      VERT_OBJ_2
  1795.  
  1796. #define VERT_TEX0_12      (VERT_TEX0_2|VERT_TEX0_1)
  1797. #define VERT_TEX0_123     (VERT_TEX0_3|VERT_TEX0_12)
  1798. #define VERT_TEX0_1234    (VERT_TEX0_4|VERT_TEX0_123)
  1799. #define VERT_TEX0_ANY     VERT_TEX0_1
  1800.  
  1801. #define VERT_TEX1_12      (VERT_TEX1_2|VERT_TEX1_1)
  1802. #define VERT_TEX1_123     (VERT_TEX1_3|VERT_TEX1_12)
  1803. #define VERT_TEX1_1234    (VERT_TEX1_4|VERT_TEX1_123)
  1804. #define VERT_TEX1_ANY     VERT_TEX1_1
  1805.  
  1806. /* not used */
  1807. #define VERT_TEX2_12      (VERT_TEX2_2|VERT_TEX2_1)
  1808. #define VERT_TEX2_123     (VERT_TEX2_3|VERT_TEX2_12)
  1809. #define VERT_TEX2_1234    (VERT_TEX2_4|VERT_TEX2_123)
  1810. #define VERT_TEX2_ANY     VERT_TEX2_1
  1811.  
  1812. /* not used 
  1813. #define VERT_TEX3_12      (VERT_TEX3_2|VERT_TEX3_1)
  1814. #define VERT_TEX3_123     (VERT_TEX3_3|VERT_TEX3_12)
  1815. #define VERT_TEX3_1234    (VERT_TEX3_4|VERT_TEX3_123)
  1816. #define VERT_TEX3_ANY     VERT_TEX3_1
  1817. */
  1818.  
  1819. #define NR_TEXSIZE_BITS   4
  1820. #define VERT_TEX_ANY(i)   (VERT_TEX0_ANY<<(i*NR_TEXSIZE_BITS))
  1821.  
  1822. #define VERT_FIXUP         (VERT_TEX0_ANY|VERT_TEX1_ANY|VERT_RGBA| \
  1823.                 VERT_INDEX|VERT_EDGE|VERT_NORM)
  1824.  
  1825. #define VERT_DATA          (VERT_TEX0_ANY|VERT_TEX1_ANY|VERT_RGBA| \
  1826.                 VERT_INDEX|VERT_EDGE|VERT_NORM| \
  1827.                         VERT_OBJ_ANY|VERT_MATERIAL|VERT_ELT| \
  1828.                         VERT_EVAL_ANY|VERT_FOG_COORD)
  1829.  
  1830.  
  1831. #define VERT_TO_PIPE      (~VERT_END_VB)
  1832. #define VERT_FLAGS_TO_PIPE_FLAGS(x) (x & VERT_TO_PIPE)
  1833. #define PIPE_FLAGS_TO_VERT_FLAGS(x) (x & VERT_TO_PIPE)
  1834. #define PIPE_TEX(i)       VERT_TEX_ANY(i)
  1835.  
  1836.  
  1837.  
  1838. /* For beginstate
  1839.  */
  1840. #define VERT_BEGIN_0    0x1       /* glBegin (if initially inside beg/end) */
  1841. #define VERT_BEGIN_1    0x2       /* glBegin (if initially outside beg/end) */
  1842. #define VERT_ERROR_0    0x4       /* invalid_operation in initial state 0 */
  1843. #define VERT_ERROR_1    0x8        /* invalid_operation in initial state 1 */
  1844.  
  1845.  
  1846.  
  1847.  
  1848. typedef void (*vb_transform_func)( GLcontext *ctx );
  1849.  
  1850.  
  1851. typedef GLuint (*clip_line_func)( struct vertex_buffer *VB, 
  1852.                   GLuint *i, GLuint *j,
  1853.                   GLubyte mask);
  1854. typedef GLuint (*clip_poly_func)( struct vertex_buffer *VB,
  1855.                   GLuint n, GLuint vlist[],
  1856.                   GLubyte mask );
  1857.  
  1858. /*
  1859.  * The library context: 
  1860.  */
  1861.  
  1862. struct gl_context {
  1863.     /* State possibly shared with other contexts in the address space */
  1864.     struct gl_shared_state *Shared;
  1865.  
  1866.     /* API function pointer tables */
  1867.     struct gl_api_table API;        /* For api.c */
  1868.     struct gl_api_table Save;        /* Display list save funcs */
  1869.     struct gl_api_table Exec;        /* Execute funcs */
  1870.  
  1871.         GLvisual *Visual;
  1872.         GLframebuffer *Buffer;
  1873.  
  1874.     /* Driver function pointer table */
  1875.     struct dd_function_table Driver;
  1876.     
  1877.         triangle_func TriangleFunc; /* driver or indirect triangle func */
  1878.         quad_func     QuadFunc;
  1879.         triangle_func ClippedTriangleFunc;
  1880.     clip_poly_func *poly_clip_tab;
  1881.     clip_line_func *line_clip_tab;
  1882.  
  1883.     void *DriverCtx;    /* Points to device driver context/state */
  1884.     void *DriverMgrCtx;    /* Points to device driver manager (optional)*/
  1885.  
  1886.     /* Core/Driver constants */
  1887.     struct gl_constants Const;
  1888.  
  1889.     /* Modelview matrix and stack */
  1890.     GLmatrix ModelView;    
  1891.     GLuint ModelViewStackDepth;
  1892.     GLmatrix ModelViewStack[MAX_MODELVIEW_STACK_DEPTH];
  1893.  
  1894.     /* Projection matrix and stack */
  1895.     GLmatrix ProjectionMatrix;
  1896.     GLuint ProjectionStackDepth;
  1897.     GLmatrix ProjectionStack[MAX_PROJECTION_STACK_DEPTH];
  1898.     GLfloat NearFarStack[MAX_PROJECTION_STACK_DEPTH][2];
  1899.  
  1900.         /* Combined modelview and projection matrix */
  1901.         GLmatrix ModelProjectMatrix;
  1902.  
  1903.         /* Combined modelview, projection and window matrix */
  1904.         GLmatrix ModelProjectWinMatrix;
  1905.         GLboolean ModelProjectWinMatrixUptodate;
  1906.  
  1907.     /* Texture matrix and stack */
  1908.     GLmatrix TextureMatrix[MAX_TEXTURE_UNITS];
  1909.     GLuint TextureStackDepth[MAX_TEXTURE_UNITS];
  1910.     GLmatrix TextureStack[MAX_TEXTURE_UNITS][MAX_TEXTURE_STACK_DEPTH];
  1911.  
  1912.     /* Display lists */
  1913.     GLuint CallDepth;    /* Current recursion calling depth */
  1914.     GLboolean ExecuteFlag;    /* Execute GL commands? */
  1915.     GLboolean CompileFlag;    /* Compile GL commands into display list? */
  1916.     GLboolean CompileCVAFlag;
  1917.     Node *CurrentListPtr;    /* Head of list being compiled */
  1918.     GLuint CurrentListNum;    /* Number of the list being compiled */
  1919.     Node *CurrentBlock;    /* Pointer to current block of nodes */
  1920.     GLuint CurrentPos;    /* Index into current block of nodes */
  1921.  
  1922.     /* Extensions */
  1923.     struct gl_extensions Extensions;
  1924.  
  1925.  
  1926.     /* Pipeline stages - shared between the two pipelines,
  1927.      * which live in CVA.
  1928.      */
  1929.     struct gl_pipeline_stage PipelineStage[MAX_PIPELINE_STAGES];
  1930.     GLuint NrPipelineStages;
  1931.  
  1932.     /* Cva */
  1933.     struct gl_cva CVA;
  1934.  
  1935.     /* Renderer attribute stack */
  1936.     GLuint AttribStackDepth;
  1937.     struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
  1938.  
  1939.     /* Renderer attribute groups */
  1940.     struct gl_accum_attrib        Accum;
  1941.     struct gl_colorbuffer_attrib    Color;
  1942.     struct gl_current_attrib    Current;
  1943.     struct gl_depthbuffer_attrib    Depth;
  1944.     struct gl_eval_attrib        Eval;
  1945.     struct gl_fog_attrib        Fog;
  1946.     struct gl_hint_attrib        Hint;
  1947.     struct gl_light_attrib        Light;
  1948.     struct gl_line_attrib        Line;
  1949.     struct gl_list_attrib        List;
  1950.     struct gl_pixel_attrib        Pixel;
  1951.     struct gl_point_attrib        Point;
  1952.     struct gl_polygon_attrib    Polygon;
  1953.     GLuint PolygonStipple[32];
  1954.     struct gl_scissor_attrib    Scissor;
  1955.     struct gl_stencil_attrib    Stencil;
  1956.     struct gl_texture_attrib    Texture;
  1957.     struct gl_transform_attrib    Transform;
  1958.     struct gl_viewport_attrib    Viewport;
  1959.  
  1960.     /* Client attribute stack */
  1961.     GLuint ClientAttribStackDepth;
  1962.     struct gl_attrib_node *ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
  1963.  
  1964.     /* Client attribute groups */
  1965.     struct gl_array_attrib        Array;    /* Vertex arrays */
  1966.     struct gl_pixelstore_attrib    Pack;    /* Pixel packing */
  1967.     struct gl_pixelstore_attrib    Unpack;    /* Pixel unpacking */
  1968.  
  1969.     struct gl_evaluators EvalMap;    /* All evaluators */
  1970.     struct gl_feedback Feedback;    /* Feedback */
  1971.     struct gl_selection Select;    /* Selection */
  1972.  
  1973.     /* Optimized Accumulation buffer info */
  1974.     GLboolean IntegerAccumMode;    /* Storing unscaled integers? */
  1975.     GLfloat IntegerAccumScaler;    /* Implicit scale factor */
  1976.  
  1977.  
  1978.     struct gl_fallback_arrays Fallback; 
  1979.  
  1980.     GLenum ErrorValue;        /* Last error code */
  1981.  
  1982.     /* Miscellaneous */
  1983.         GLuint NewState;        /* bitwise OR of NEW_* flags */
  1984.     GLuint Enabled;         /* bitwise or of ENABLE_* flags */
  1985.     GLenum RenderMode;    /* either GL_RENDER, GL_SELECT, GL_FEEDBACK */
  1986.     GLuint StippleCounter;    /* Line stipple counter */
  1987.     GLuint RasterMask;    /* OR of rasterization flags */
  1988.     GLuint TriangleCaps;      /* OR of DD_* flags */
  1989.     GLuint IndirectTriangles; /* TriangleCaps not handled by the driver */
  1990.     GLfloat PolygonZoffset;    /* Z offset for GL_FILL polygons */
  1991.     GLfloat LineZoffset;    /* Z offset for GL_LINE polygons */
  1992.     GLfloat PointZoffset;    /* Z offset for GL_POINT polygons */
  1993.     GLboolean NeedNormals;    /* Are vertex normal vectors needed? */
  1994.         GLboolean MutablePixels;/* Can rasterization change pixel's color? */
  1995.         GLboolean MonoPixels;   /* Are all pixels likely to be same color? */
  1996.     GLuint FogMode;         /* FOG_OFF, FOG_VERTEX or FOG_FRAGMENT */
  1997.  
  1998.     GLboolean DoViewportMapping;
  1999.  
  2000.  
  2001.         GLuint RenderFlags;    /* Active inputs to render stage */
  2002.  
  2003.     GLuint RequireWriteableFlags; /* What can the driver/clipping tolerate? */
  2004.  
  2005.     /* Points to function which interpolates colors, etc when clipping */
  2006.     clip_interp_func ClipInterpFunc;
  2007.     GLuint ClipTabMask;
  2008.  
  2009.         normal_func *NormalTransform; 
  2010.  
  2011.     /* Current shading function */
  2012.         GLuint shade_func_flags;
  2013.  
  2014.         GLfloat EyeZDir[3];
  2015.         GLfloat rescale_factor;
  2016.  
  2017.     GLfloat vb_rescale_factor;
  2018.     GLmatrix *vb_proj_matrix;
  2019.  
  2020.     GLubyte   AllowVertexCull; /* To be set by the geometry driver */
  2021.         GLboolean NeedEyeCoords;
  2022.         GLboolean NeedEyeNormals;
  2023.         GLboolean NeedClipCoords;
  2024.  
  2025.     GLfloat backface_sign;
  2026.  
  2027.         /* Destination of immediate mode commands */
  2028.         struct immediate *input;
  2029.  
  2030.  
  2031.     /* Cache of unused immediate structs
  2032.      */
  2033.     struct immediate *freed_im_queue;
  2034.     GLuint nr_im_queued;
  2035.  
  2036.         /* The vertex buffer being used by this context.
  2037.      */
  2038.         struct vertex_buffer *VB;
  2039.    
  2040.         /* The pixel buffer being used by this context */
  2041.         struct pixel_buffer* PB;
  2042.  
  2043.         struct gl_shine_tab *ShineTable[4];  /* Active shine tables */
  2044.         struct gl_shine_tab *ShineTabList;   /* Mru list of inactive shine tables */
  2045.  
  2046.  
  2047. #ifdef PROFILE
  2048.         /* Performance measurements */
  2049.         GLuint BeginEndCount;    /* number of glBegin/glEnd pairs */
  2050.         GLdouble BeginEndTime;    /* seconds spent between glBegin/glEnd */
  2051.         GLuint VertexCount;    /* number of vertices processed */
  2052.         GLdouble VertexTime;    /* total time in seconds */
  2053.         GLuint PointCount;    /* number of points rendered */
  2054.         GLdouble PointTime;    /* total time in seconds */
  2055.         GLuint LineCount;    /* number of lines rendered */
  2056.         GLdouble LineTime;    /* total time in seconds */
  2057.         GLuint PolygonCount;    /* number of polygons rendered */
  2058.         GLdouble PolygonTime;    /* total time in seconds */
  2059.         GLuint ClearCount;    /* number of glClear calls */
  2060.         GLdouble ClearTime;    /* seconds spent in glClear */
  2061.         GLuint SwapCount;    /* number of swap-buffer calls */
  2062.         GLdouble SwapTime;    /* seconds spent in swap-buffers */
  2063. #endif
  2064.  
  2065.         /* Should 3Dfx Glide driver catch signals? */
  2066.         GLboolean CatchSignals;
  2067.         
  2068.         /* For debugging/development only */
  2069.         GLboolean NoRaster;
  2070.         GLboolean FirstTimeCurrent;
  2071.  
  2072.         /* Dither disable via MESA_NO_DITHER env var */
  2073.         GLboolean NoDither;
  2074. };
  2075.  
  2076.  
  2077. #ifndef MESA_DEBUG
  2078. # define MESA_VERBOSE 0
  2079. # define MESA_DEBUG_FLAGS 0
  2080. # ifndef NDEBUG
  2081. #  define NDEBUG
  2082. # endif
  2083. #else
  2084. extern int MESA_VERBOSE; 
  2085. extern int MESA_DEBUG_FLAGS;
  2086. #endif
  2087.  
  2088. enum _verbose {
  2089.     VERBOSE_VARRAY          = 0x1,
  2090.     VERBOSE_TEXTURE         = 0x2,
  2091.     VERBOSE_IMMEDIATE       = 0x4,
  2092.     VERBOSE_PIPELINE        = 0x8,
  2093.     VERBOSE_DRIVER          = 0x10,
  2094.     VERBOSE_STATE           = 0x20,
  2095.     VERBOSE_API             = 0x40,
  2096.     VERBOSE_TRIANGLE_CHECKS = 0x80,
  2097.     VERBOSE_CULL            = 0x100,
  2098.     VERBOSE_DISPLAY_LIST    = 0x200,
  2099.     VERBOSE_LIGHTING        = 0x400,
  2100.     VERBOSE_EXTENSIONS      = 0x800,
  2101. }; 
  2102.  
  2103.  
  2104. enum _debug {
  2105.     DEBUG_ALWAYS_FLUSH          = 0x1
  2106. }; 
  2107.  
  2108.  
  2109. extern void gl_flush_vb( GLcontext *ctx, const char *where );
  2110.  
  2111. extern void RESET_IMMEDIATE( GLcontext *ctx );
  2112.  
  2113. #define FLUSH_VB( ctx, where )            \
  2114. do {                        \
  2115.     struct immediate *IM = ctx->input;    \
  2116.     if (IM->Flag[IM->Start])        \
  2117.         gl_flush_vb( ctx, where );    \
  2118. } while (0)
  2119.  
  2120.  
  2121.  
  2122.  
  2123. /* Test if we're inside a glBegin / glEnd pair: 
  2124. */
  2125. #define ASSERT_OUTSIDE_BEGIN_END( ctx, where )                \
  2126. do {                                    \
  2127.     struct immediate *IM = ctx->input;                \
  2128.     GLuint flag = IM->Flag[IM->Count];                \
  2129.     if ((flag & (VERT_BEGIN|VERT_END)) != VERT_END) {        \
  2130.                 FLUSH_VB(ctx, where);                    \
  2131.         if (ctx->Current.Primitive != GL_POLYGON+1) {        \
  2132.             gl_error( ctx, GL_INVALID_OPERATION, where );    \
  2133.             return;                        \
  2134.         }                            \
  2135.     }                                \
  2136. } while (0)
  2137.  
  2138. #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL( ctx, where, what )    \
  2139. do {                                    \
  2140.     struct immediate *IM = ctx->input;                \
  2141.     GLuint flag = IM->Flag[IM->Count];                \
  2142.     if ((flag & (VERT_BEGIN|VERT_END)) != VERT_END) {        \
  2143.                 FLUSH_VB(ctx, where);                    \
  2144.         if (ctx->Current.Primitive != GL_POLYGON+1) {        \
  2145.             gl_error( ctx, GL_INVALID_OPERATION, where );    \
  2146.             return what;                    \
  2147.         }                            \
  2148.     }                                \
  2149. } while (0)
  2150.  
  2151.  
  2152. #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx, where )    \
  2153. do {                                \
  2154.     FLUSH_VB( ctx, where );                    \
  2155.     if (ctx->Current.Primitive != GL_POLYGON+1) {        \
  2156.         gl_error( ctx, GL_INVALID_OPERATION, where );    \
  2157.         return;                        \
  2158.     }                            \
  2159. } while (0)
  2160.  
  2161.  
  2162. #define ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL( ctx, where, what )  \
  2163. do {                                \
  2164.     FLUSH_VB( ctx, where );                                \
  2165.     if (ctx->Current.Primitive != GL_POLYGON+1) {        \
  2166.         gl_error( ctx, GL_INVALID_OPERATION, where );    \
  2167.         return what;                    \
  2168.     }                            \
  2169. } while (0)
  2170.  
  2171. #if 0
  2172. #undef ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL
  2173. #define ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL
  2174.  
  2175. #undef ASSERT_OUTSIDE_BEGIN_END
  2176. #define ASSERT_OUTSIDE_BEGIN_END ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH
  2177. #endif
  2178.  
  2179.  
  2180. #define Elements(x) sizeof(x)/sizeof(*(x))
  2181.  
  2182. #endif
  2183.  
  2184.  
  2185.  
  2186.