home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / vbfill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  35.6 KB  |  1,336 lines

  1. /* $Id: vbfill.c,v 1.17 1997/11/14 03:02:53 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.5
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: vbfill.c,v $
  26.  * Revision 1.17  1997/11/14 03:02:53  brianp
  27.  * clamp floating point color components to [0,1] before int conversion
  28.  *
  29.  * Revision 1.16  1997/08/13 01:31:11  brianp
  30.  * LightTwoSide is now a GLboolean
  31.  *
  32.  * Revision 1.15  1997/07/24 01:25:27  brianp
  33.  * changed precompiled header symbol from PCH to PC_HEADER
  34.  *
  35.  * Revision 1.14  1997/06/20 02:47:41  brianp
  36.  * added Color4ubv API pointer
  37.  *
  38.  * Revision 1.13  1997/06/20 02:46:49  brianp
  39.  * changed color components from GLfixed to GLubyte
  40.  *
  41.  * Revision 1.12  1997/05/28 03:26:49  brianp
  42.  * added precompiled header (PCH) support
  43.  *
  44.  * Revision 1.11  1997/05/27 03:13:41  brianp
  45.  * removed some debugging code
  46.  *
  47.  * Revision 1.10  1997/04/28 02:05:44  brianp
  48.  * renamed some vertex functions, also save color with texcoords
  49.  *
  50.  * Revision 1.9  1997/04/24 01:50:53  brianp
  51.  * optimized glColor3f, glColor3fv, glColor4fv
  52.  *
  53.  * Revision 1.8  1997/04/24 00:30:17  brianp
  54.  * optimized glTexCoord2() code
  55.  *
  56.  * Revision 1.7  1997/04/20 15:59:30  brianp
  57.  * removed VERTEX2_BIT stuff
  58.  *
  59.  * Revision 1.6  1997/04/16 23:55:33  brianp
  60.  * added optimized glTexCoord2f code
  61.  *
  62.  * Revision 1.5  1997/04/14 22:18:23  brianp
  63.  * added optimized glVertex3fv code
  64.  *
  65.  * Revision 1.4  1997/04/12 16:21:54  brianp
  66.  * added ctx->Exec.Vertex2f = vertex2_feedback; statement
  67.  *
  68.  * Revision 1.3  1997/04/12 12:23:26  brianp
  69.  * fixed 3 bugs in gl_eval_vertex
  70.  *
  71.  * Revision 1.2  1997/04/07 03:01:11  brianp
  72.  * optimized vertex[234] code
  73.  *
  74.  * Revision 1.1  1997/04/02 03:13:56  brianp
  75.  * Initial revision
  76.  *
  77.  */
  78.  
  79.  
  80. /*
  81.  * This file implements the functions for filling the vertex buffer:
  82.  *   glVertex, glNormal, glColor, glIndex, glEdgeFlag, glTexCoord,
  83.  */
  84.  
  85.  
  86. #ifdef PC_HEADER
  87. #include "all.h"
  88. #else
  89. #include <assert.h>
  90. #include <stdio.h>
  91. #include "context.h"
  92. #include "light.h"
  93. #include "clip.h"
  94. #include "dlist.h"
  95. #include "feedback.h"
  96. #include "macros.h"
  97. #include "matrix.h"
  98. #include "pb.h"
  99. #include "types.h"
  100. #include "vb.h"
  101. #include "vbfill.h"
  102. #include "vbxform.h"
  103. #include "xform.h"
  104. #endif
  105.  
  106.  
  107.  
  108. /**********************************************************************/
  109. /******                    glNormal functions                     *****/
  110. /**********************************************************************/
  111.  
  112. /*
  113.  * Caller:  context->API.Normal3f pointer.
  114.  */
  115. void gl_Normal3f( GLcontext *ctx, GLfloat nx, GLfloat ny, GLfloat nz )
  116. {
  117.    ctx->Current.Normal[0] = nx;
  118.    ctx->Current.Normal[1] = ny;
  119.    ctx->Current.Normal[2] = nz;
  120.    ctx->VB->MonoNormal = GL_FALSE;
  121. }
  122.  
  123.  
  124. /*
  125.  * Caller:  context->API.Normal3fv pointer.
  126.  */
  127. void gl_Normal3fv( GLcontext *ctx, const GLfloat *n )
  128. {
  129.    ctx->Current.Normal[0] = n[0];
  130.    ctx->Current.Normal[1] = n[1];
  131.    ctx->Current.Normal[2] = n[2];
  132.    ctx->VB->MonoNormal = GL_FALSE;
  133. }
  134.  
  135.  
  136.  
  137. /**********************************************************************/
  138. /******                    glIndex functions                      *****/
  139. /**********************************************************************/
  140.  
  141. /*
  142.  * Caller:  context->API.Indexf pointer.
  143.  */
  144. void gl_Indexf( GLcontext *ctx, GLfloat c )
  145. {
  146.    ctx->Current.Index = (GLuint) (GLint) c;
  147.    ctx->VB->MonoColor = GL_FALSE;
  148. }
  149.  
  150.  
  151. /*
  152.  * Caller:  context->API.Indexi pointer.
  153.  */
  154. void gl_Indexi( GLcontext *ctx, GLint c )
  155. {
  156.    ctx->Current.Index = (GLuint) c;
  157.    ctx->VB->MonoColor = GL_FALSE;
  158. }
  159.  
  160.  
  161.  
  162. /**********************************************************************/
  163. /******                     glColor functions                     *****/
  164. /**********************************************************************/
  165.  
  166. /*
  167.  * Caller:  context->API.Color3f pointer.
  168.  */
  169. void gl_Color3f( GLcontext *ctx, GLfloat red, GLfloat green, GLfloat blue )
  170. {
  171.    ctx->Current.ByteColor[0] = CLAMP(red  , 0.0F, 1.0F) * ctx->Visual->RedScale;
  172.    ctx->Current.ByteColor[1] = CLAMP(green, 0.0F, 1.0F) * ctx->Visual->GreenScale;
  173.    ctx->Current.ByteColor[2] = CLAMP(blue , 0.0F, 1.0F) * ctx->Visual->BlueScale;
  174.    ctx->Current.ByteColor[3] = ctx->Visual->AlphaScale;
  175.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  176.    ctx->VB->MonoColor = GL_FALSE;
  177. }
  178.  
  179.  
  180. /*
  181.  * Caller:  context->API.Color3fv pointer.
  182.  */
  183. void gl_Color3fv( GLcontext *ctx, const GLfloat *c )
  184. {
  185.    ctx->Current.ByteColor[0] = CLAMP(c[0], 0.0F, 1.0F) * ctx->Visual->RedScale;
  186.    ctx->Current.ByteColor[1] = CLAMP(c[1], 0.0F, 1.0F) * ctx->Visual->GreenScale;
  187.    ctx->Current.ByteColor[2] = CLAMP(c[2], 0.0F, 1.0F) * ctx->Visual->BlueScale;
  188.    ctx->Current.ByteColor[3] = ctx->Visual->AlphaScale;
  189.  
  190.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  191.    ctx->VB->MonoColor = GL_FALSE;
  192. }
  193.  
  194.  
  195. /*
  196.  * Caller:  context->API.Color4f pointer.
  197.  */
  198. void gl_Color4f( GLcontext *ctx,
  199.          GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
  200. {
  201.    ctx->Current.ByteColor[0] = CLAMP(red  , 0.0F, 1.0F) * ctx->Visual->RedScale;
  202.    ctx->Current.ByteColor[1] = CLAMP(green, 0.0F, 1.0F) * ctx->Visual->GreenScale;
  203.    ctx->Current.ByteColor[2] = CLAMP(blue , 0.0F, 1.0F) * ctx->Visual->BlueScale;
  204.    ctx->Current.ByteColor[3] = CLAMP(alpha, 0.0F, 1.0F) * ctx->Visual->AlphaScale;
  205.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  206.    ctx->VB->MonoColor = GL_FALSE;
  207. }
  208.  
  209.  
  210. /*
  211.  * Caller:  context->API.Color4fv pointer.
  212.  */
  213. void gl_Color4fv( GLcontext *ctx, const GLfloat *c )
  214. {
  215.    ctx->Current.ByteColor[0] = CLAMP(c[0], 0.0F, 1.0F) * ctx->Visual->RedScale;
  216.    ctx->Current.ByteColor[1] = CLAMP(c[1], 0.0F, 1.0F) * ctx->Visual->GreenScale;
  217.    ctx->Current.ByteColor[2] = CLAMP(c[2], 0.0F, 1.0F) * ctx->Visual->BlueScale;
  218.    ctx->Current.ByteColor[3] = CLAMP(c[3], 0.0F, 1.0F) * ctx->Visual->AlphaScale;
  219.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  220.    ctx->VB->MonoColor = GL_FALSE;
  221. }
  222.  
  223.  
  224. /*
  225.  * Used when colors are not scaled to [0,255]
  226.  * Caller:  context->API.Color4ub pointer.
  227.  */
  228. void gl_Color4ub( GLcontext *ctx,
  229.           GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
  230. {
  231.    ctx->Current.ByteColor[0] = red   * ctx->Visual->RedScale   * (1.0F/255.0F);
  232.    ctx->Current.ByteColor[1] = green * ctx->Visual->GreenScale * (1.0F/255.0F);
  233.    ctx->Current.ByteColor[2] = blue  * ctx->Visual->BlueScale  * (1.0F/255.0F);
  234.    ctx->Current.ByteColor[3] = alpha * ctx->Visual->AlphaScale * (1.0F/255.0F);
  235.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  236.    ctx->VB->MonoColor = GL_FALSE;
  237. }
  238.  
  239.  
  240. /*
  241.  * Used when colors are scaled to [0,255].
  242.  * Caller:  context->API.Color4ub pointer.
  243.  */
  244. void gl_Color4ub8bit( GLcontext *ctx,
  245.               GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
  246. {
  247.    ASSIGN_4V( ctx->Current.ByteColor, red, green, blue, alpha );
  248.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  249.    ctx->VB->MonoColor = GL_FALSE;
  250. }
  251.  
  252.  
  253. /*
  254.  * Used when colors are not scaled to [0,255]
  255.  * Caller:  context->API.Color4ub pointer.
  256.  */
  257. void gl_Color4ubv( GLcontext *ctx, const GLubyte *c )
  258. {
  259.    ctx->Current.ByteColor[0] = c[0] * ctx->Visual->RedScale   * (1.0F/255.0F);
  260.    ctx->Current.ByteColor[1] = c[1] * ctx->Visual->GreenScale * (1.0F/255.0F);
  261.    ctx->Current.ByteColor[2] = c[2] * ctx->Visual->BlueScale  * (1.0F/255.0F);
  262.    ctx->Current.ByteColor[3] = c[3] * ctx->Visual->AlphaScale * (1.0F/255.0F);
  263.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  264.    ctx->VB->MonoColor = GL_FALSE;
  265. }
  266.  
  267.  
  268. /*
  269.  * Used when colors are scaled to [0,255].
  270.  * Caller:  context->API.Color4ub pointer.
  271.  */
  272. void gl_Color4ubv8bit( GLcontext *ctx, const GLubyte *c )
  273. {
  274.    COPY_4UBV( ctx->Current.ByteColor, c );
  275.    ASSERT( !ctx->Light.ColorMaterialEnabled );
  276.    ctx->VB->MonoColor = GL_FALSE;
  277. }
  278.  
  279.  
  280. /*
  281.  * glColor() which modifies material(s).
  282.  * Caller:  context->API.Color3f pointer.
  283.  */
  284. void gl_ColorMat3f( GLcontext *ctx, GLfloat red, GLfloat green, GLfloat blue )
  285. {
  286.    GLfloat color[4];
  287.    ctx->Current.ByteColor[0] = CLAMP(red  , 0.0F, 1.0F) * ctx->Visual->RedScale;
  288.    ctx->Current.ByteColor[1] = CLAMP(green, 0.0F, 1.0F) * ctx->Visual->GreenScale;
  289.    ctx->Current.ByteColor[2] = CLAMP(blue , 0.0F, 1.0F) * ctx->Visual->BlueScale;
  290.    ctx->Current.ByteColor[3] = ctx->Visual->AlphaScale;
  291.    /* update material */
  292.    ASSERT( ctx->Light.ColorMaterialEnabled );
  293.    ASSIGN_4V( color, red, green, blue, 1.0F );
  294.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  295.    ctx->VB->MonoColor = GL_FALSE;
  296. }
  297.  
  298.  
  299. /*
  300.  * glColor() which modifies material(s).
  301.  * Caller:  context->API.Color3fv pointer.
  302.  */
  303. void gl_ColorMat3fv( GLcontext *ctx, const GLfloat *c )
  304. {
  305.    GLfloat color[4];
  306.    ctx->Current.ByteColor[0] = CLAMP(c[0], 0.0F, 1.0F) * ctx->Visual->RedScale;
  307.    ctx->Current.ByteColor[1] = CLAMP(c[1], 0.0F, 1.0F) * ctx->Visual->GreenScale;
  308.    ctx->Current.ByteColor[2] = CLAMP(c[2], 0.0F, 1.0F) * ctx->Visual->BlueScale;
  309.    ctx->Current.ByteColor[3] = ctx->Visual->AlphaScale;
  310.    /* update material */
  311.    ASSERT( ctx->Light.ColorMaterialEnabled );
  312.    ASSIGN_4V( color, c[0], c[1], c[2], 1.0F );
  313.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  314.    ctx->VB->MonoColor = GL_FALSE;
  315. }
  316.  
  317.  
  318. /*
  319.  * glColor() which modifies material(s).
  320.  * Caller:  context->API.Color4f pointer.
  321.  */
  322. void gl_ColorMat4f( GLcontext *ctx,
  323.             GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha )
  324. {
  325.    GLfloat color[4];
  326.    ctx->Current.ByteColor[0] = CLAMP(red  , 0.0F, 1.0F) * ctx->Visual->RedScale;
  327.    ctx->Current.ByteColor[1] = CLAMP(green, 0.0F, 1.0F) * ctx->Visual->GreenScale;
  328.    ctx->Current.ByteColor[2] = CLAMP(blue , 0.0F, 1.0F) * ctx->Visual->BlueScale;
  329.    ctx->Current.ByteColor[3] = CLAMP(alpha, 0.0F, 1.0F) * ctx->Visual->AlphaScale;
  330.    /* update material */
  331.    ASSERT( ctx->Light.ColorMaterialEnabled );
  332.    ASSIGN_4V( color, red, green, blue, alpha );
  333.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  334.    ctx->VB->MonoColor = GL_FALSE;
  335. }
  336.  
  337.  
  338. /*
  339.  * glColor() which modifies material(s).
  340.  * Caller:  context->API.Color4fv pointer.
  341.  */
  342. void gl_ColorMat4fv( GLcontext *ctx, const GLfloat *c )
  343. {
  344.    GLfloat color[4];
  345.    ctx->Current.ByteColor[0] = CLAMP(c[0], 0.0F, 1.0F) * ctx->Visual->RedScale;
  346.    ctx->Current.ByteColor[1] = CLAMP(c[1], 0.0F, 1.0F) * ctx->Visual->GreenScale;
  347.    ctx->Current.ByteColor[2] = CLAMP(c[2], 0.0F, 1.0F) * ctx->Visual->BlueScale;
  348.    ctx->Current.ByteColor[3] = CLAMP(c[3], 0.0F, 1.0F) * ctx->Visual->AlphaScale;
  349.    /* update material */
  350.    ASSERT( ctx->Light.ColorMaterialEnabled );
  351.    ASSIGN_4V( color, c[0], c[1], c[2], c[3] );
  352.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  353.    ctx->VB->MonoColor = GL_FALSE;
  354. }
  355.  
  356.  
  357. /*
  358.  * glColor which modifies material(s).
  359.  * Caller:  context->API.Color4ub pointer.
  360.  */
  361. void gl_ColorMat4ub( GLcontext *ctx,
  362.              GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha )
  363. {
  364.    GLfloat color[4];
  365.    if (ctx->Visual->EightBitColor) {
  366.       ASSIGN_4V( ctx->Current.ByteColor, red, green, blue, alpha );
  367.    }
  368.    else {
  369.       ctx->Current.ByteColor[0] = red   * ctx->Visual->RedScale   * (1.0F/255.0F);
  370.       ctx->Current.ByteColor[1] = green * ctx->Visual->GreenScale * (1.0F/255.0F);
  371.       ctx->Current.ByteColor[2] = blue  * ctx->Visual->BlueScale  * (1.0F/255.0F);
  372.       ctx->Current.ByteColor[3] = alpha * ctx->Visual->AlphaScale * (1.0F/255.0F);
  373.    }
  374.    /* update material */
  375.    ASSERT( ctx->Light.ColorMaterialEnabled );
  376.    color[0] = red   * (1.0F/255.0F);
  377.    color[1] = green * (1.0F/255.0F);
  378.    color[2] = blue  * (1.0F/255.0F);
  379.    color[3] = alpha * (1.0F/255.0F);
  380.    gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, color );
  381.    ctx->VB->MonoColor = GL_FALSE;
  382. }
  383.  
  384.  
  385. /*
  386.  * glColor which modifies material(s).
  387.  * Caller:  context->API.Color4ub pointer.
  388.  */
  389. void gl_ColorMat4ubv( GLcontext *ctx, const GLubyte *c )
  390. {
  391.    gl_ColorMat4ub( ctx, c[0], c[1], c[2], c[3] );
  392. }
  393.  
  394.  
  395.  
  396. /**********************************************************************/
  397. /******                  glEdgeFlag functions                     *****/
  398. /**********************************************************************/
  399.  
  400. /*
  401.  * Caller:  context->API.EdgeFlag pointer.
  402.  */
  403. void gl_EdgeFlag( GLcontext *ctx, GLboolean flag )
  404. {
  405.    ctx->Current.EdgeFlag = flag;
  406. }
  407.  
  408.  
  409.  
  410. /**********************************************************************/
  411. /*****                    glVertex functions                      *****/
  412. /**********************************************************************/
  413.  
  414. /*
  415.  * Used when in feedback mode.
  416.  * Caller:  context->API.Vertex4f pointer.
  417.  */
  418. static void vertex4f_feedback( GLcontext *ctx,
  419.                    GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  420. {
  421.    struct vertex_buffer *VB = ctx->VB;
  422.    GLuint count = VB->Count;
  423.  
  424.    /* vertex */
  425.    ASSIGN_4V( VB->Obj[count], x, y, z, w );
  426.  
  427.    /* color */
  428.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  429.  
  430.    /* index */
  431.    VB->Findex[count] = ctx->Current.Index;
  432.  
  433.    /* normal */
  434.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  435.  
  436.    /* texcoord */
  437.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  438.  
  439.    /* edgeflag */
  440.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  441.  
  442.    count++;
  443.    VB->Count = count;
  444.    if (count==VB_MAX) {
  445.       gl_transform_vb_part1( ctx, GL_FALSE );
  446.    }
  447. }
  448.  
  449.  
  450. static void vertex3f_feedback( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  451. {
  452.    vertex4f_feedback(ctx, x, y, z, 1.0F);
  453. }
  454.  
  455.  
  456. static void vertex2f_feedback( GLcontext *ctx, GLfloat x, GLfloat y )
  457. {
  458.    vertex4f_feedback(ctx, x, y, 0.0F, 1.0F);
  459. }
  460.  
  461.  
  462. static void vertex3fv_feedback( GLcontext *ctx, const GLfloat v[3] )
  463. {
  464.    vertex4f_feedback(ctx, v[0], v[1], v[2], 1.0F);
  465. }
  466.  
  467.  
  468.  
  469. /*
  470.  * Only one glVertex4 function since it's not too popular.
  471.  * Caller:  context->API.Vertex4f pointer.
  472.  */
  473. static void vertex4( GLcontext *ctx,
  474.              GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  475. {
  476.    struct vertex_buffer *VB = ctx->VB;
  477.    GLuint count = VB->Count;
  478.  
  479.    ASSIGN_4V( VB->Obj[count], x, y, z, w );
  480.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  481.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  482.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  483.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  484.    VB->VertexSizeMask = VERTEX4_BIT;
  485.  
  486.    count++;
  487.    VB->Count = count;
  488.    if (count==VB_MAX) {
  489.       gl_transform_vb_part1( ctx, GL_FALSE );
  490.    }
  491. }
  492.  
  493.  
  494.  
  495. /*
  496.  * XYZ vertex, RGB color, normal, ST texture coords.
  497.  * Caller:  context->API.Vertex3f pointer.
  498.  */
  499. static void vertex3f_normal_color_tex2( GLcontext *ctx,
  500.                     GLfloat x, GLfloat y, GLfloat z )
  501. {
  502.    struct vertex_buffer *VB = ctx->VB;
  503.    GLuint count = VB->Count;
  504.  
  505.    ASSIGN_3V( VB->Obj[count], x, y, z );
  506.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  507.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  508.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  509.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  510.  
  511.    count++;
  512.    VB->Count = count;
  513.    if (count==VB_MAX) {
  514.       gl_transform_vb_part1( ctx, GL_FALSE );
  515.    }
  516. }
  517.  
  518.  
  519. /*
  520.  * XYZ vertex, RGB color, normal, STRQ texture coords.
  521.  * Caller:  context->API.Vertex3f pointer.
  522.  */
  523. static void vertex3f_normal_color_tex4( GLcontext *ctx,
  524.                     GLfloat x, GLfloat y, GLfloat z )
  525. {
  526.    struct vertex_buffer *VB = ctx->VB;
  527.    GLuint count = VB->Count;
  528.  
  529.    ASSIGN_3V( VB->Obj[count], x, y, z );
  530.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  531.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  532.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  533.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  534.  
  535.    count++;
  536.    VB->Count = count;
  537.    if (count==VB_MAX) {
  538.       gl_transform_vb_part1( ctx, GL_FALSE );
  539.    }
  540. }
  541.  
  542.  
  543. /*
  544.  * XYZ vertex, normal.
  545.  * Caller:  context->API.Vertex3f pointer.
  546.  */
  547. static void vertex3f_normal( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  548. {
  549.    struct vertex_buffer *VB = ctx->VB;
  550.    GLuint count = VB->Count;
  551.  
  552.    ASSIGN_3V( VB->Obj[count], x, y, z );
  553.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  554.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  555.  
  556.    count++;
  557.    VB->Count = count;
  558.    if (count==VB_MAX) {
  559.       gl_transform_vb_part1( ctx, GL_FALSE );
  560.    }
  561. }
  562.  
  563.  
  564. /*
  565.  * XYZ vertex, ST texture coords.
  566.  * Caller:  context->API.Vertex3f pointer.
  567.  */
  568. static void vertex3f_color_tex2( GLcontext *ctx,
  569.                  GLfloat x, GLfloat y, GLfloat z )
  570. {
  571.    struct vertex_buffer *VB = ctx->VB;
  572.    GLuint count = VB->Count;
  573.  
  574.    ASSIGN_3V( VB->Obj[count], x, y, z );
  575.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  576.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  577.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  578.  
  579.    count++;
  580.    VB->Count = count;
  581.    if (count==VB_MAX) {
  582.       gl_transform_vb_part1( ctx, GL_FALSE );
  583.    }
  584. }
  585.  
  586.  
  587. /*
  588.  * XYZ vertex, STRQ texture coords.
  589.  * Caller:  context->API.Vertex3f pointer.
  590.  */
  591. static void vertex3f_color_tex4( GLcontext *ctx,
  592.                  GLfloat x, GLfloat y, GLfloat z )
  593. {
  594.    struct vertex_buffer *VB = ctx->VB;
  595.    GLuint count = VB->Count;
  596.  
  597.    ASSIGN_3V( VB->Obj[count], x, y, z );
  598.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  599.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  600.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  601.  
  602.    count++;
  603.    VB->Count = count;
  604.    if (count==VB_MAX) {
  605.       gl_transform_vb_part1( ctx, GL_FALSE );
  606.    }
  607. }
  608.  
  609.  
  610. /*
  611.  * XYZ vertex, RGB color.
  612.  * Caller:  context->API.Vertex3f pointer.
  613.  */
  614. static void vertex3f_color( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  615. {
  616.    struct vertex_buffer *VB = ctx->VB;
  617.    GLuint count = VB->Count;
  618.  
  619.    ASSIGN_3V( VB->Obj[count], x, y, z );
  620.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  621.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  622.  
  623.    count++;
  624.    VB->Count = count;
  625.    if (count==VB_MAX) {
  626.       gl_transform_vb_part1( ctx, GL_FALSE );
  627.    }
  628. }
  629.  
  630.  
  631. /*
  632.  * XYZ vertex, color index.
  633.  * Caller:  context->API.Vertex3f pointer.
  634.  */
  635. static void vertex3f_index( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  636. {
  637.    struct vertex_buffer *VB = ctx->VB;
  638.    GLuint count = VB->Count;
  639.  
  640.    ASSIGN_3V( VB->Obj[count], x, y, z );
  641.    VB->Findex[count] = ctx->Current.Index;
  642.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  643.  
  644.    count++;
  645.    VB->Count = count;
  646.    if (count==VB_MAX) {
  647.       gl_transform_vb_part1( ctx, GL_FALSE );
  648.    }
  649. }
  650.  
  651.  
  652.  
  653. /*
  654.  * XY vertex, RGB color, normal, ST texture coords.
  655.  * Caller:  context->API.Vertex2f pointer.
  656.  */
  657. static void vertex2f_normal_color_tex2( GLcontext *ctx, GLfloat x, GLfloat y )
  658. {
  659.    struct vertex_buffer *VB = ctx->VB;
  660.    GLuint count = VB->Count;
  661.  
  662.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  663.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  664.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  665.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  666.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  667.  
  668.    count++;
  669.    VB->Count = count;
  670.    if (count==VB_MAX) {
  671.       gl_transform_vb_part1( ctx, GL_FALSE );
  672.    }
  673. }
  674.  
  675.  
  676. /*
  677.  * XY vertex, RGB color, normal, STRQ texture coords.
  678.  * Caller:  context->API.Vertex2f pointer.
  679.  */
  680. static void vertex2f_normal_color_tex4( GLcontext *ctx, GLfloat x, GLfloat y )
  681. {
  682.    struct vertex_buffer *VB = ctx->VB;
  683.    GLuint count = VB->Count;
  684.  
  685.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  686.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  687.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  688.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  689.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  690.  
  691.    count++;
  692.    VB->Count = count;
  693.    if (count==VB_MAX) {
  694.       gl_transform_vb_part1( ctx, GL_FALSE );
  695.    }
  696. }
  697.  
  698.  
  699. /*
  700.  * XY vertex, normal.
  701.  * Caller:  context->API.Vertex2f pointer.
  702.  */
  703. static void vertex2f_normal( GLcontext *ctx, GLfloat x, GLfloat y )
  704. {
  705.    struct vertex_buffer *VB = ctx->VB;
  706.    GLuint count = VB->Count;
  707.  
  708.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  709.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  710.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  711.  
  712.    count++;
  713.    VB->Count = count;
  714.    if (count==VB_MAX) {
  715.       gl_transform_vb_part1( ctx, GL_FALSE );
  716.    }
  717. }
  718.  
  719.  
  720. /*
  721.  * XY vertex, ST texture coords.
  722.  * Caller:  context->API.Vertex2f pointer.
  723.  */
  724. static void vertex2f_color_tex2( GLcontext *ctx, GLfloat x, GLfloat y )
  725. {
  726.    struct vertex_buffer *VB = ctx->VB;
  727.    GLuint count = VB->Count;
  728.  
  729.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  730.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  731.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  732.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  733.  
  734.    count++;
  735.    VB->Count = count;
  736.    if (count==VB_MAX) {
  737.       gl_transform_vb_part1( ctx, GL_FALSE );
  738.    }
  739. }
  740.  
  741.  
  742. /*
  743.  * XY vertex, STRQ texture coords.
  744.  * Caller:  context->API.Vertex2f pointer.
  745.  */
  746. static void vertex2f_color_tex4( GLcontext *ctx, GLfloat x, GLfloat y )
  747. {
  748.    struct vertex_buffer *VB = ctx->VB;
  749.    GLuint count = VB->Count;
  750.  
  751.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  752.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  753.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  754.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  755.  
  756.    count++;
  757.    VB->Count = count;
  758.    if (count==VB_MAX) {
  759.       gl_transform_vb_part1( ctx, GL_FALSE );
  760.    }
  761. }
  762.  
  763.  
  764. /*
  765.  * XY vertex, RGB color.
  766.  * Caller:  context->API.Vertex2f pointer.
  767.  */
  768. static void vertex2f_color( GLcontext *ctx, GLfloat x, GLfloat y )
  769. {
  770.    struct vertex_buffer *VB = ctx->VB;
  771.    GLuint count = VB->Count;
  772.  
  773.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  774.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  775.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  776.  
  777.    count++;
  778.    VB->Count = count;
  779.    if (count==VB_MAX) {
  780.       gl_transform_vb_part1( ctx, GL_FALSE );
  781.    }
  782. }
  783.  
  784.  
  785. /*
  786.  * XY vertex, color index.
  787.  * Caller:  context->API.Vertex3f pointer.
  788.  */
  789. static void vertex2f_index( GLcontext *ctx, GLfloat x, GLfloat y )
  790. {
  791.    struct vertex_buffer *VB = ctx->VB;
  792.    GLuint count = VB->Count;
  793.  
  794.    ASSIGN_3V( VB->Obj[count], x, y, 0.0F );
  795.    VB->Findex[count] = ctx->Current.Index;
  796.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  797.  
  798.    count++;
  799.    VB->Count = count;
  800.    if (count==VB_MAX) {
  801.       gl_transform_vb_part1( ctx, GL_FALSE );
  802.    }
  803. }
  804.  
  805.  
  806.  
  807.  
  808. /*
  809.  * XYZ vertex, RGB color, normal, ST texture coords.
  810.  * Caller:  context->API.Vertex3f pointer.
  811.  */
  812. static void vertex3fv_normal_color_tex2( GLcontext *ctx, const GLfloat v[3] )
  813. {
  814.    struct vertex_buffer *VB = ctx->VB;
  815.    GLuint count = VB->Count;
  816.  
  817.    COPY_3V( VB->Obj[count], v );
  818.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  819.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  820.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  821.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  822.  
  823.    count++;
  824.    VB->Count = count;
  825.    if (count==VB_MAX) {
  826.       gl_transform_vb_part1( ctx, GL_FALSE );
  827.    }
  828. }
  829.  
  830.  
  831. /*
  832.  * XYZ vertex, RGB color, normal, STRQ texture coords.
  833.  * Caller:  context->API.Vertex3f pointer.
  834.  */
  835. static void vertex3fv_normal_color_tex4( GLcontext *ctx, const GLfloat v[3] )
  836. {
  837.    struct vertex_buffer *VB = ctx->VB;
  838.    GLuint count = VB->Count;
  839.  
  840.    COPY_3V( VB->Obj[count], v );
  841.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  842.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  843.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  844.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  845.  
  846.    count++;
  847.    VB->Count = count;
  848.    if (count==VB_MAX) {
  849.       gl_transform_vb_part1( ctx, GL_FALSE );
  850.    }
  851. }
  852.  
  853.  
  854. /*
  855.  * XYZ vertex, normal.
  856.  * Caller:  context->API.Vertex3f pointer.
  857.  */
  858. static void vertex3fv_normal( GLcontext *ctx, const GLfloat v[3] )
  859. {
  860.    struct vertex_buffer *VB = ctx->VB;
  861.    GLuint count = VB->Count;
  862.  
  863.    COPY_3V( VB->Obj[count], v );
  864.    COPY_3V( VB->Normal[count], ctx->Current.Normal );
  865.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  866.  
  867.    count++;
  868.    VB->Count = count;
  869.    if (count==VB_MAX) {
  870.       gl_transform_vb_part1( ctx, GL_FALSE );
  871.    }
  872. }
  873.  
  874.  
  875. /*
  876.  * XYZ vertex, ST texture coords.
  877.  * Caller:  context->API.Vertex3f pointer.
  878.  */
  879. static void vertex3fv_color_tex2( GLcontext *ctx, const GLfloat v[3] )
  880. {
  881.    struct vertex_buffer *VB = ctx->VB;
  882.    GLuint count = VB->Count;
  883.  
  884.    COPY_3V( VB->Obj[count], v );
  885.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  886.    COPY_2V( VB->TexCoord[count], ctx->Current.TexCoord );
  887.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  888.  
  889.    count++;
  890.    VB->Count = count;
  891.    if (count==VB_MAX) {
  892.       gl_transform_vb_part1( ctx, GL_FALSE );
  893.    }
  894. }
  895.  
  896.  
  897. /*
  898.  * XYZ vertex, STRQ texture coords.
  899.  * Caller:  context->API.Vertex3f pointer.
  900.  */
  901. static void vertex3fv_color_tex4( GLcontext *ctx, const GLfloat v[3] )
  902. {
  903.    struct vertex_buffer *VB = ctx->VB;
  904.    GLuint count = VB->Count;
  905.  
  906.    COPY_3V( VB->Obj[count], v );
  907.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  908.    COPY_4V( VB->TexCoord[count], ctx->Current.TexCoord );
  909.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  910.  
  911.    count++;
  912.    VB->Count = count;
  913.    if (count==VB_MAX) {
  914.       gl_transform_vb_part1( ctx, GL_FALSE );
  915.    }
  916. }
  917.  
  918.  
  919. /*
  920.  * XYZ vertex, RGB color.
  921.  * Caller:  context->API.Vertex3f pointer.
  922.  */
  923. static void vertex3fv_color( GLcontext *ctx, const GLfloat v[3] )
  924. {
  925.    struct vertex_buffer *VB = ctx->VB;
  926.    GLuint count = VB->Count;
  927.  
  928.    COPY_3V( VB->Obj[count], v );
  929.    COPY_4UBV( VB->Fcolor[count], ctx->Current.ByteColor );
  930.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  931.  
  932.    count++;
  933.    VB->Count = count;
  934.    if (count==VB_MAX) {
  935.       gl_transform_vb_part1( ctx, GL_FALSE );
  936.    }
  937. }
  938.  
  939.  
  940. /*
  941.  * XYZ vertex, Color index
  942.  * Caller:  context->API.Vertex3f pointer.
  943.  */
  944. static void vertex3fv_index( GLcontext *ctx, const GLfloat v[3] )
  945. {
  946.    struct vertex_buffer *VB = ctx->VB;
  947.    GLuint count = VB->Count;
  948.  
  949.    COPY_3V( VB->Obj[count], v );
  950.    VB->Findex[count] = ctx->Current.Index;
  951.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  952.  
  953.    count++;
  954.    VB->Count = count;
  955.    if (count==VB_MAX) {
  956.       gl_transform_vb_part1( ctx, GL_FALSE );
  957.    }
  958. }
  959.  
  960.  
  961.  
  962. /*
  963.  * Called when outside glBegin/glEnd, raises an error.
  964.  * Caller:  context->API.Vertex4f pointer.
  965.  */
  966. void gl_vertex4f_nop( GLcontext *ctx,
  967.               GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  968. {
  969.    gl_error( ctx, GL_INVALID_OPERATION, "glVertex4" );
  970. }
  971.  
  972. void gl_vertex3f_nop( GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z )
  973. {
  974.    gl_error( ctx, GL_INVALID_OPERATION, "glVertex3" );
  975. }
  976.  
  977. void gl_vertex2f_nop( GLcontext *ctx, GLfloat x, GLfloat y )
  978. {
  979.    gl_error( ctx, GL_INVALID_OPERATION, "glVertex2" );
  980. }
  981.  
  982. void gl_vertex3fv_nop( GLcontext *ctx, const GLfloat v[3] )
  983. {
  984.    gl_error( ctx, GL_INVALID_OPERATION, "glVertex3v" );
  985. }
  986.  
  987.  
  988.  
  989.  
  990. /**********************************************************************/
  991. /******                   glTexCoord functions                    *****/
  992. /**********************************************************************/
  993.  
  994. /*
  995.  * Caller:  context->API.TexCoord2f pointer.
  996.  */
  997. void gl_TexCoord2f( GLcontext *ctx, GLfloat s, GLfloat t )
  998. {
  999.    ctx->Current.TexCoord[0] = s;
  1000.    ctx->Current.TexCoord[1] = t;
  1001. }
  1002.  
  1003.  
  1004. /*
  1005.  * Caller:  context->API.TexCoord2f pointer.
  1006.  * This version of glTexCoord2 is called if glTexCoord[34] was a predecessor.
  1007.  */
  1008. void gl_TexCoord2f4( GLcontext *ctx, GLfloat s, GLfloat t )
  1009. {
  1010.    ctx->Current.TexCoord[0] = s;
  1011.    ctx->Current.TexCoord[1] = t;
  1012.    ctx->Current.TexCoord[2] = 0.0F;
  1013.    ctx->Current.TexCoord[3] = 1.0F;
  1014. }
  1015.  
  1016.  
  1017. /*
  1018.  * Caller:  context->API.TexCoord4f pointer.
  1019.  */
  1020. void gl_TexCoord4f( GLcontext *ctx, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
  1021. {
  1022.    ctx->Current.TexCoord[0] = s;
  1023.    ctx->Current.TexCoord[1] = t;
  1024.    ctx->Current.TexCoord[2] = r;
  1025.    ctx->Current.TexCoord[3] = q;
  1026.    if (ctx->VB->TexCoordSize==2) {
  1027.       /* Have to switch to 4-component texture mode now */
  1028.       ctx->VB->TexCoordSize = 4;
  1029.       gl_set_vertex_function( ctx );
  1030.       ctx->Exec.TexCoord2f = ctx->API.TexCoord2f = gl_TexCoord2f4;
  1031.    }
  1032. }
  1033.  
  1034.  
  1035.  
  1036.  
  1037. /*
  1038.  * This function examines the current GL state and sets the
  1039.  * ctx->Exec.Vertex[34]f pointers to point at the appropriate vertex
  1040.  * processing functions.
  1041.  */
  1042. void gl_set_vertex_function( GLcontext *ctx )
  1043. {
  1044.    if (ctx->RenderMode==GL_FEEDBACK) {
  1045.       ctx->Exec.Vertex4f = vertex4f_feedback;
  1046.       ctx->Exec.Vertex3f = vertex3f_feedback;
  1047.       ctx->Exec.Vertex2f = vertex2f_feedback;
  1048.       ctx->Exec.Vertex3fv = vertex3fv_feedback;
  1049.    }
  1050.    else {
  1051.       ctx->Exec.Vertex4f = vertex4;
  1052.       if (ctx->Visual->RGBAflag) {
  1053.      if (ctx->NeedNormals) {
  1054.         /* lighting enabled, need normal vectors */
  1055.         if (ctx->Texture.Enabled) {
  1056.            if (ctx->VB->TexCoordSize==2) {
  1057.           ctx->Exec.Vertex2f = vertex2f_normal_color_tex2;
  1058.           ctx->Exec.Vertex3f = vertex3f_normal_color_tex2;
  1059.           ctx->Exec.Vertex3fv = vertex3fv_normal_color_tex2;
  1060.            }
  1061.            else {
  1062.           ctx->Exec.Vertex2f = vertex2f_normal_color_tex4;
  1063.           ctx->Exec.Vertex3f = vertex3f_normal_color_tex4;
  1064.           ctx->Exec.Vertex3fv = vertex3fv_normal_color_tex4;
  1065.            }
  1066.         }
  1067.         else {
  1068.            ctx->Exec.Vertex2f = vertex2f_normal;
  1069.            ctx->Exec.Vertex3f = vertex3f_normal;
  1070.            ctx->Exec.Vertex3fv = vertex3fv_normal;
  1071.         }
  1072.      }
  1073.      else {
  1074.         /* not lighting, need vertex color */
  1075.         if (ctx->Texture.Enabled) {
  1076.            if (ctx->VB->TexCoordSize==2) {
  1077.           ctx->Exec.Vertex2f = vertex2f_color_tex2;
  1078.           ctx->Exec.Vertex3f = vertex3f_color_tex2;
  1079.           ctx->Exec.Vertex3fv = vertex3fv_color_tex2;
  1080.            }
  1081.            else {
  1082.           ctx->Exec.Vertex2f = vertex2f_color_tex4;
  1083.           ctx->Exec.Vertex3f = vertex3f_color_tex4;
  1084.           ctx->Exec.Vertex3fv = vertex3fv_color_tex4;
  1085.            }
  1086.         }
  1087.         else {
  1088.            ctx->Exec.Vertex2f = vertex2f_color;
  1089.            ctx->Exec.Vertex3f = vertex3f_color;
  1090.            ctx->Exec.Vertex3fv = vertex3fv_color;
  1091.         }
  1092.      }
  1093.       }
  1094.       else {
  1095.      /* color index mode */
  1096.      if (ctx->Light.Enabled) {
  1097.         ctx->Exec.Vertex2f = vertex2f_normal;
  1098.         ctx->Exec.Vertex3f = vertex3f_normal;
  1099.         ctx->Exec.Vertex3fv = vertex3fv_normal;
  1100.      }
  1101.      else {
  1102.         ctx->Exec.Vertex2f = vertex2f_index;
  1103.         ctx->Exec.Vertex3f = vertex3f_index;
  1104.         ctx->Exec.Vertex3fv = vertex3fv_index;
  1105.      }
  1106.       }
  1107.    }
  1108.  
  1109.    if (!ctx->CompileFlag) {
  1110.       ctx->API.Vertex2f = ctx->Exec.Vertex2f;
  1111.       ctx->API.Vertex3f = ctx->Exec.Vertex3f;
  1112.       ctx->API.Vertex4f = ctx->Exec.Vertex4f;
  1113.       ctx->API.Vertex3fv = ctx->Exec.Vertex3fv;
  1114.    }
  1115. }
  1116.  
  1117.  
  1118.  
  1119. /*
  1120.  * This function examines the current GL state and sets the
  1121.  * ctx->Exec.Color[34]* pointers to point at the appropriate vertex
  1122.  * processing functions.
  1123.  */
  1124. void gl_set_color_function( GLcontext *ctx )
  1125. {
  1126.    ASSERT( !INSIDE_BEGIN_END(ctx) );
  1127.  
  1128.    if (ctx->Light.ColorMaterialEnabled) {
  1129.       ctx->Exec.Color3f = gl_ColorMat3f;
  1130.       ctx->Exec.Color3fv = gl_ColorMat3fv;
  1131.       ctx->Exec.Color4f = gl_ColorMat4f;
  1132.       ctx->Exec.Color4fv = gl_ColorMat4fv;
  1133.       ctx->Exec.Color4ub = gl_ColorMat4ub;
  1134.       ctx->Exec.Color4ubv = gl_ColorMat4ubv;
  1135.    }
  1136.    else {
  1137.       ctx->Exec.Color3f = gl_Color3f;
  1138.       ctx->Exec.Color3fv = gl_Color3fv;
  1139.       ctx->Exec.Color4f = gl_Color4f;
  1140.       ctx->Exec.Color4fv = gl_Color4fv;
  1141.       ctx->Exec.Color4ub
  1142.      = ctx->Visual->EightBitColor ? (void(*)(GLcontext *,GLubyte, GLubyte, GLubyte, GLubyte))gl_Color4ub8bit : (void(*)(GLcontext *,GLubyte, GLubyte, GLubyte, GLubyte))gl_Color4ub;
  1143.       ctx->Exec.Color4ubv
  1144.      = ctx->Visual->EightBitColor ? (void(*)(GLcontext *, const GLubyte *))gl_Color4ubv8bit : (void(*)(GLcontext *, const GLubyte *))gl_Color4ubv;
  1145.    }
  1146.    if (!ctx->CompileFlag) {
  1147.       ctx->API.Color3f = ctx->Exec.Color3f;
  1148.       ctx->API.Color3fv = ctx->Exec.Color3fv;
  1149.       ctx->API.Color4f = ctx->Exec.Color4f;
  1150.       ctx->API.Color4fv = ctx->Exec.Color4fv;
  1151.       ctx->API.Color4ub = ctx->Exec.Color4ub;
  1152.       ctx->API.Color4ubv = ctx->Exec.Color4ubv;
  1153.    }
  1154. }
  1155.  
  1156.  
  1157.  
  1158. /**********************************************************************/
  1159. /*****                    Evaluator vertices                      *****/
  1160. /**********************************************************************/
  1161.  
  1162.  
  1163. /*
  1164.  * Process a vertex produced by an evaluator.
  1165.  * Caller:  eval.c
  1166.  * Input:  vertex - the X,Y,Z,W vertex
  1167.  *         normal - normal vector
  1168.  *         color - 4 integer color components
  1169.  *         index - color index
  1170.  *         texcoord - texture coordinate
  1171.  */
  1172. void gl_eval_vertex( GLcontext *ctx,
  1173.              const GLfloat vertex[4], const GLfloat normal[3],
  1174.              const GLubyte color[4],
  1175.              GLuint index,
  1176.              const GLfloat texcoord[4] )
  1177. {
  1178.    struct vertex_buffer *VB = ctx->VB;
  1179.    GLuint count = VB->Count;  /* copy to local var to encourage optimization */
  1180.  
  1181.    VB->VertexSizeMask = VERTEX4_BIT;
  1182.    VB->MonoNormal = GL_FALSE;
  1183.    COPY_4V( VB->Obj[count], vertex );
  1184.    COPY_3V( VB->Normal[count], normal );
  1185.    COPY_4UBV( VB->Fcolor[count], color );
  1186.    
  1187. #ifdef GL_VERSION_1_1
  1188.    if (ctx->Light.ColorMaterialEnabled
  1189.        && (ctx->Eval.Map1Color4 || ctx->Eval.Map2Color4)) {
  1190.       GLfloat fcolor[4];
  1191.       fcolor[0] = color[0] * ctx->Visual->InvRedScale;
  1192.       fcolor[1] = color[1] * ctx->Visual->InvGreenScale;
  1193.       fcolor[2] = color[2] * ctx->Visual->InvBlueScale;
  1194.       fcolor[3] = color[3] * ctx->Visual->InvAlphaScale;
  1195.       gl_set_material( ctx, ctx->Light.ColorMaterialBitmask, fcolor );
  1196.    }
  1197. #endif
  1198.    VB->Findex[count] = index;
  1199.    COPY_4V( VB->TexCoord[count], texcoord );
  1200.    VB->Edgeflag[count] = ctx->Current.EdgeFlag;
  1201.  
  1202.    count++;
  1203.    VB->Count = count;
  1204.    if (count==VB_MAX) {
  1205.       gl_transform_vb_part1( ctx, GL_FALSE );
  1206.    }
  1207. }
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213. /**********************************************************************/
  1214. /*****                    glBegin / glEnd                         *****/
  1215. /**********************************************************************/
  1216.  
  1217.  
  1218. #ifdef PROFILE
  1219. static GLdouble begin_time;
  1220. #endif
  1221.  
  1222.  
  1223. void gl_Begin( GLcontext *ctx, GLenum p )
  1224. {
  1225.    struct vertex_buffer *VB = ctx->VB;
  1226.    struct pixel_buffer *PB = ctx->PB;
  1227. #ifdef PROFILE
  1228.    begin_time = gl_time();
  1229. #endif
  1230.  
  1231.    if (INSIDE_BEGIN_END(ctx)) {
  1232.       gl_error( ctx, GL_INVALID_OPERATION, "glBegin" );
  1233.       return;
  1234.    }
  1235.    if (ctx->NewModelViewMatrix) {
  1236.       gl_analyze_modelview_matrix(ctx);
  1237.    }
  1238.    if (ctx->NewProjectionMatrix) {
  1239.       gl_analyze_projection_matrix(ctx);
  1240.    }
  1241.    if (ctx->NewState) {
  1242.       gl_update_state(ctx);
  1243.    }
  1244.    else if (ctx->Exec.Vertex4f==(void (*)( GLcontext *, GLfloat, GLfloat, GLfloat, GLfloat ))gl_vertex3f_nop) {
  1245.       gl_set_vertex_function(ctx);
  1246.    }
  1247.  
  1248.    if (ctx->Driver.Begin) {
  1249.       (*ctx->Driver.Begin)( ctx, p );
  1250.    }
  1251.  
  1252.    ctx->Primitive = p;
  1253.    VB->Start = VB->Count = 0;
  1254.  
  1255.    VB->MonoColor = ctx->MonoPixels;
  1256.    VB->MonoNormal = GL_TRUE;
  1257.    if (VB->MonoColor) {
  1258.       /* All pixels generated are likely to be the same color so have
  1259.        * the device driver set the "monocolor" now.
  1260.        */
  1261.       if (ctx->Visual->RGBAflag) {
  1262.      GLubyte r = ctx->Current.ByteColor[0];
  1263.      GLubyte g = ctx->Current.ByteColor[1];
  1264.      GLubyte b = ctx->Current.ByteColor[2];
  1265.      GLubyte a = ctx->Current.ByteColor[3];
  1266.      (*ctx->Driver.Color)( ctx, r, g, b, a );
  1267.       }
  1268.       else {
  1269.      (*ctx->Driver.Index)( ctx, ctx->Current.Index );
  1270.       }
  1271.    }
  1272.  
  1273.    /* By default use front color/index.  Two-sided lighting may override. */
  1274.    VB->Color = VB->Fcolor;
  1275.    VB->Index = VB->Findex;
  1276.  
  1277.    switch (ctx->Primitive) {
  1278.       case GL_POINTS:
  1279.      ctx->LightTwoSide = GL_FALSE;
  1280.      PB_INIT( PB, GL_POINT );
  1281.      break;
  1282.       case GL_LINES:
  1283.       case GL_LINE_STRIP:
  1284.       case GL_LINE_LOOP:
  1285.      ctx->LightTwoSide = GL_FALSE;
  1286.      ctx->StippleCounter = 0;
  1287.      PB_INIT( PB, GL_LINE );
  1288.      break;
  1289.       case GL_TRIANGLES:
  1290.       case GL_TRIANGLE_STRIP:
  1291.       case GL_TRIANGLE_FAN:
  1292.       case GL_QUADS:
  1293.       case GL_QUAD_STRIP:
  1294.       case GL_POLYGON:
  1295.      ctx->LightTwoSide = ctx->Light.Enabled && ctx->Light.Model.TwoSide;
  1296.      PB_INIT( PB, GL_POLYGON );
  1297.      break;
  1298.       default:
  1299.      gl_error( ctx, GL_INVALID_ENUM, "glBegin" );
  1300.      ctx->Primitive = GL_BITMAP;
  1301.    }
  1302. }
  1303.  
  1304.  
  1305.  
  1306. void gl_End( GLcontext *ctx )
  1307. {
  1308.    struct pixel_buffer *PB = ctx->PB;
  1309.    struct vertex_buffer *VB = ctx->VB;
  1310.  
  1311.    if (ctx->Primitive==GL_BITMAP) {
  1312.       /* glEnd without glBegin */
  1313.       gl_error( ctx, GL_INVALID_OPERATION, "glEnd" );
  1314.       return;
  1315.    }
  1316.  
  1317.    if (VB->Count > VB->Start) {
  1318.       gl_transform_vb_part1( ctx, GL_TRUE );
  1319.    }
  1320.    if (PB->count>0) {
  1321.       gl_flush_pb(ctx);
  1322.    }
  1323.  
  1324.    if (ctx->Driver.End) {
  1325.       (*ctx->Driver.End)(ctx);
  1326.    }
  1327.  
  1328.    PB->primitive = ctx->Primitive = GL_BITMAP;  /* Default mode */
  1329.  
  1330. #ifdef PROFILE
  1331.    ctx->BeginEndTime += gl_time() - begin_time;
  1332.    ctx->BeginEndCount++;
  1333. #endif
  1334. }
  1335.  
  1336.