head	3.65;
access;
symbols
	merge-1:3.45.2.7
	autoconf:3.46.0.2
	experimental-1:3.45.0.2
	mesa-3-1-with-kw3:3.36
	mesa-3-1-prior-to-kw3:3.35;
locks; strict;
comment	@ * @;


3.65
date	99.08.03.21.21.02;	author keithw;	state Exp;
branches;
next	3.64;

3.64
date	99.08.01.16.39.06;	author brianp;	state Exp;
branches;
next	3.63;

3.63
date	99.07.31.23.59.01;	author brianp;	state Exp;
branches;
next	3.62;

3.62
date	99.07.31.19.15.18;	author miklos;	state Exp;
branches;
next	3.61;

3.61
date	99.07.30.18.48.01;	author brianp;	state Exp;
branches;
next	3.60;

3.60
date	99.07.16.03.33.15;	author tjump;	state Exp;
branches;
next	3.59;

3.59
date	99.07.15.20.24.51;	author keithw;	state Exp;
branches;
next	3.58;

3.58
date	99.07.15.12.35.26;	author tjump;	state Exp;
branches;
next	3.57;

3.57
date	99.07.15.02.47.12;	author brianp;	state Exp;
branches;
next	3.56;

3.56
date	99.07.14.21.08.36;	author brianp;	state Exp;
branches;
next	3.55;

3.55
date	99.07.14.01.28.25;	author brianp;	state Exp;
branches;
next	3.54;

3.54
date	99.07.12.12.05.23;	author keithw;	state Exp;
branches;
next	3.53;

3.53
date	99.07.06.01.09.35;	author brianp;	state Exp;
branches;
next	3.52;

3.52
date	99.06.25.01.51.24;	author brianp;	state Exp;
branches;
next	3.51;

3.51
date	99.06.18.20.04.35;	author brianp;	state Exp;
branches;
next	3.50;

3.50
date	99.06.18.14.22.02;	author brianp;	state Exp;
branches;
next	3.49;

3.49
date	99.06.11.01.49.55;	author brianp;	state Exp;
branches;
next	3.48;

3.48
date	99.06.07.14.04.50;	author brianp;	state Exp;
branches;
next	3.47;

3.47
date	99.06.02.12.55.35;	author keithw;	state Exp;
branches;
next	3.46;

3.46
date	99.05.26.15.22.00;	author keithw;	state Exp;
branches;
next	3.45;

3.45
date	99.05.18.00.12.05;	author keithw;	state Exp;
branches
	3.45.2.1;
next	3.44;

3.44
date	99.05.11.17.43.00;	author keithw;	state Exp;
branches;
next	3.43;

3.43
date	99.05.02.00.59.24;	author keithw;	state Exp;
branches;
next	3.42;

3.42
date	99.04.22.02.18.30;	author brianp;	state Exp;
branches;
next	3.41;

3.41
date	99.04.07.22.16.55;	author brianp;	state Exp;
branches;
next	3.40;

3.40
date	99.03.31.20.18.38;	author keithw;	state Exp;
branches;
next	3.39;

3.39
date	99.03.30.02.44.36;	author brianp;	state Exp;
branches;
next	3.38;

3.38
date	99.03.28.20.56.15;	author brianp;	state Exp;
branches;
next	3.37;

3.37
date	99.03.16.00.04.46;	author keithw;	state Exp;
branches;
next	3.36;

3.36
date	99.02.25.14.12.30;	author keithw;	state Exp;
branches;
next	3.35;

3.35
date	99.02.24.22.48.05;	author jens;	state Exp;
branches;
next	3.34;

3.34
date	99.02.17.02.12.43;	author brianp;	state Exp;
branches;
next	3.33;

3.33
date	99.02.14.03.46.34;	author brianp;	state Exp;
branches;
next	3.32;

3.32
date	99.02.05.03.23.56;	author brianp;	state Exp;
branches;
next	3.31;

3.31
date	99.01.30.04.29.16;	author brianp;	state Exp;
branches;
next	3.30;

3.30
date	98.11.17.01.52.47;	author brianp;	state Exp;
branches;
next	3.29;

3.29
date	98.11.08.22.36.00;	author brianp;	state Exp;
branches;
next	3.28;

3.28
date	98.11.07.14.22.17;	author brianp;	state Exp;
branches;
next	3.27;

3.27
date	98.11.07.02.27.27;	author brianp;	state Exp;
branches;
next	3.26;

3.26
date	98.11.07.02.13.33;	author brianp;	state Exp;
branches;
next	3.25;

3.25
date	98.11.03.01.16.57;	author brianp;	state Exp;
branches;
next	3.24;

3.24
date	98.10.31.17.06.15;	author brianp;	state Exp;
branches;
next	3.23;

3.23
date	98.10.29.02.33.49;	author brianp;	state Exp;
branches;
next	3.22;

3.22
date	98.10.05.00.40.15;	author brianp;	state Exp;
branches;
next	3.21;

3.21
date	98.08.23.22.19.30;	author brianp;	state Exp;
branches;
next	3.20;

3.20
date	98.08.21.01.49.46;	author brianp;	state Exp;
branches;
next	3.19;

3.19
date	98.07.17.03.23.32;	author brianp;	state Exp;
branches;
next	3.18;

3.18
date	98.06.21.02.00.55;	author brianp;	state Exp;
branches;
next	3.17;

3.17
date	98.06.19.03.13.10;	author brianp;	state Exp;
branches;
next	3.16;

3.16
date	98.06.07.22.18.52;	author brianp;	state Exp;
branches;
next	3.15;

3.15
date	98.04.01.02.58.28;	author brianp;	state Exp;
branches;
next	3.14;

3.14
date	98.03.27.03.30.36;	author brianp;	state Exp;
branches;
next	3.13;

3.13
date	98.03.22.16.42.22;	author brianp;	state Exp;
branches;
next	3.12;

3.12
date	98.03.15.17.55.54;	author brianp;	state Exp;
branches;
next	3.11;

3.11
date	98.03.05.02.49.48;	author brianp;	state Exp;
branches;
next	3.10;

3.10
date	98.03.01.20.17.03;	author brianp;	state Exp;
branches;
next	3.9;

3.9
date	98.02.20.04.50.09;	author brianp;	state Exp;
branches;
next	3.8;

3.8
date	98.02.13.04.38.05;	author brianp;	state Exp;
branches;
next	3.7;

3.7
date	98.02.13.03.23.04;	author brianp;	state Exp;
branches;
next	3.6;

3.6
date	98.02.13.03.17.02;	author brianp;	state Exp;
branches;
next	3.5;

3.5
date	98.02.08.20.20.34;	author brianp;	state Exp;
branches;
next	3.4;

3.4
date	98.02.05.01.10.25;	author brianp;	state Exp;
branches;
next	3.3;

3.3
date	98.02.02.03.09.34;	author brianp;	state Exp;
branches;
next	3.2;

3.2
date	98.02.01.16.37.19;	author brianp;	state Exp;
branches;
next	3.1;

3.1
date	98.01.31.23.56.55;	author brianp;	state Exp;
branches;
next	3.0;

3.0
date	98.01.31.20.49.07;	author brianp;	state Exp;
branches;
next	;

3.45.2.1
date	99.05.21.21.29.25;	author keithw;	state Exp;
branches;
next	3.45.2.2;

3.45.2.2
date	99.05.22.19.14.39;	author keithw;	state Exp;
branches;
next	3.45.2.3;

3.45.2.3
date	99.05.27.20.52.32;	author keithw;	state Exp;
branches;
next	3.45.2.4;

3.45.2.4
date	99.05.30.13.30.34;	author keithw;	state Exp;
branches;
next	3.45.2.5;

3.45.2.5
date	99.06.01.00.45.21;	author keithw;	state Exp;
branches;
next	3.45.2.6;

3.45.2.6
date	99.06.06.22.35.53;	author keithw;	state Exp;
branches;
next	3.45.2.7;

3.45.2.7
date	99.06.19.15.04.13;	author keithw;	state Exp;
branches;
next	;


desc
@context management
@


3.65
log
@reverted to old, less buggy, glGetError
@
text
@/* $Id: context.c,v 3.64 1999/08/01 16:39:06 brianp Exp $ */

/*
 * Mesa 3-D graphics library
 * Version:  3.1
 *
 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


/*
 * If multi-threading is enabled (-DTHREADS) then each thread has it's
 * own rendering context.  A thread obtains the pointer to its GLcontext
 * with the gl_get_thread_context() function.  Otherwise, the global
 * pointer, CC, points to the current context used by all threads in
 * the address space.
 */



#ifdef PC_HEADER
#include "all.h"
#else
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "accum.h"
#include "alphabuf.h"
#include "api.h"
#include "clip.h"
#include "context.h"
#include "cva.h"
#include "depth.h"
#include "dlist.h"
#include "eval.h"
#include "enums.h"
#include "fog.h"
#include "hash.h"
#include "light.h"
#include "lines.h"
#include "dlist.h"
#include "macros.h"
#include "matrix.h"
#include "mmath.h"
#include "pb.h"
#include "pipeline.h"
#include "points.h"
#include "pointers.h"
#include "quads.h"
#include "shade.h"
#include "simple_list.h"
#include "stencil.h"
#include "stages.h"
#include "triangle.h"
#include "translate.h"
#include "teximage.h"
#include "texobj.h"
#include "texstate.h"
#include "texture.h"
#include "types.h"
#include "varray.h"
#include "vb.h"
#include "vbcull.h"
#include "vbfill.h"
#include "vbrender.h"
#include "vbxform.h"
#include "xform.h"
#ifdef XFree86Server
#include "GL/xf86glx.h"
#endif
#endif



/**********************************************************************/
/*****                  Context and Thread management             *****/
/**********************************************************************/


#ifdef THREADS

#include "mthreads.h" /* Mesa platform independent threads interface */

static MesaTSD mesa_ctx_tsd;

static void mesa_ctx_thread_init() {
  MesaInitTSD(&mesa_ctx_tsd);
}

GLcontext *gl_get_thread_context( void ) {
  return (GLcontext *) MesaGetTSD(&mesa_ctx_tsd);
}

static void set_thread_context( GLcontext *ctx ) {
  MesaSetTSD(&mesa_ctx_tsd, ctx, mesa_ctx_thread_init);
}


#else

/* One Current Context pointer for all threads in the address space */
GLcontext *CC = NULL;
struct immediate *CURRENT_INPUT = NULL;

#endif /*THREADS*/




/**********************************************************************/
/*****                   Profiling functions                      *****/
/**********************************************************************/

#ifdef PROFILE

#include <sys/times.h>
#include <sys/param.h>


/*
 * Return system time in seconds.
 * NOTE:  this implementation may not be very portable!
 */
GLdouble gl_time( void )
{
   static GLdouble prev_time = 0.0;
   static GLdouble time;
   struct tms tm;
   clock_t clk;

   clk = times(&tm);

#ifdef CLK_TCK
   time = (double)clk / (double)CLK_TCK;
#else
   time = (double)clk / (double)HZ;
#endif

   if (time>prev_time) {
      prev_time = time;
      return time;
   }
   else {
      return prev_time;
   }
}

/*
 * Reset the timing/profiling counters
 */
static void init_timings( GLcontext *ctx )
{
   ctx->BeginEndCount = 0;
   ctx->BeginEndTime = 0.0;
   ctx->VertexCount = 0;
   ctx->VertexTime = 0.0;
   ctx->PointCount = 0;
   ctx->PointTime = 0.0;
   ctx->LineCount = 0;
   ctx->LineTime = 0.0;
   ctx->PolygonCount = 0;
   ctx->PolygonTime = 0.0;
   ctx->ClearCount = 0;
   ctx->ClearTime = 0.0;
   ctx->SwapCount = 0;
   ctx->SwapTime = 0.0;
}


/*
 * Print the accumulated timing/profiling data.
 */
static void print_timings( GLcontext *ctx )
{
   GLdouble beginendrate;
   GLdouble vertexrate;
   GLdouble pointrate;
   GLdouble linerate;
   GLdouble polygonrate;
   GLdouble overhead;
   GLdouble clearrate;
   GLdouble swaprate;
   GLdouble avgvertices;

   if (ctx->BeginEndTime>0.0) {
      beginendrate = ctx->BeginEndCount / ctx->BeginEndTime;
   }
   else {
      beginendrate = 0.0;
   }
   if (ctx->VertexTime>0.0) {
      vertexrate = ctx->VertexCount / ctx->VertexTime;
   }
   else {
      vertexrate = 0.0;
   }
   if (ctx->PointTime>0.0) {
      pointrate = ctx->PointCount / ctx->PointTime;
   }
   else {
      pointrate = 0.0;
   }
   if (ctx->LineTime>0.0) {
      linerate = ctx->LineCount / ctx->LineTime;
   }
   else {
      linerate = 0.0;
   }
   if (ctx->PolygonTime>0.0) {
      polygonrate = ctx->PolygonCount / ctx->PolygonTime;
   }
   else {
      polygonrate = 0.0;
   }
   if (ctx->ClearTime>0.0) {
      clearrate = ctx->ClearCount / ctx->ClearTime;
   }
   else {
      clearrate = 0.0;
   }
   if (ctx->SwapTime>0.0) {
      swaprate = ctx->SwapCount / ctx->SwapTime;
   }
   else {
      swaprate = 0.0;
   }

   if (ctx->BeginEndCount>0) {
      avgvertices = (GLdouble) ctx->VertexCount / (GLdouble) ctx->BeginEndCount;
   }
   else {
      avgvertices = 0.0;
   }

   overhead = ctx->BeginEndTime - ctx->VertexTime - ctx->PointTime
              - ctx->LineTime - ctx->PolygonTime;


   printf("                          Count   Time (s)    Rate (/s) \n");
   printf("--------------------------------------------------------\n");
   printf("glBegin/glEnd           %7d  %8.3f   %10.3f\n",
          ctx->BeginEndCount, ctx->BeginEndTime, beginendrate);
   printf("  vertexes transformed  %7d  %8.3f   %10.3f\n",
          ctx->VertexCount, ctx->VertexTime, vertexrate );
   printf("  points rasterized     %7d  %8.3f   %10.3f\n",
          ctx->PointCount, ctx->PointTime, pointrate );
   printf("  lines rasterized      %7d  %8.3f   %10.3f\n",
          ctx->LineCount, ctx->LineTime, linerate );
   printf("  polygons rasterized   %7d  %8.3f   %10.3f\n",
          ctx->PolygonCount, ctx->PolygonTime, polygonrate );
   printf("  overhead                       %8.3f\n", overhead );
   printf("glClear                 %7d  %8.3f   %10.3f\n",
          ctx->ClearCount, ctx->ClearTime, clearrate );
   printf("SwapBuffers             %7d  %8.3f   %10.3f\n",
          ctx->SwapCount, ctx->SwapTime, swaprate );
   printf("\n");

   printf("Average number of vertices per begin/end: %8.3f\n", avgvertices );
}
#endif





/**********************************************************************/
/*****       Context allocation, initialization, destroying       *****/
/**********************************************************************/


/*
 * This function just calls all the various one-time-init functions in Mesa.
 */
static void one_time_init( void )
{
   static GLboolean alreadyCalled = GL_FALSE;
   if (!alreadyCalled) {
      gl_init_clip();
      gl_init_eval();
      gl_init_fog();
      gl_init_math();
      gl_init_lists();
      gl_init_shade();
      gl_init_texture();
      gl_init_transformation();
      gl_init_translate();
      gl_init_vbrender();
      gl_init_vbxform();
      alreadyCalled = GL_TRUE;
   }
#if defined(DEBUG) && defined(__DATE__) && defined(__TIME__)
   fprintf(stderr, "Mesa DEBUG build %s %s\n", __DATE__, __TIME__);
#endif
}


/*
 * Allocate and initialize a shared context state structure.
 */
static struct gl_shared_state *alloc_shared_state( void )
{
   GLuint i;
   struct gl_shared_state *ss;
   GLboolean outOfMemory;

   ss = (struct gl_shared_state*) calloc( 1, sizeof(struct gl_shared_state) );
   if (!ss)
      return NULL;

   ss->DisplayList = NewHashTable();

   ss->TexObjects = NewHashTable();

   /* Default Texture objects */
   outOfMemory = GL_FALSE;
   for (i=0;i<MAX_TEXTURE_UNITS;i++) {
      GLuint d;
      for (d = 1 ; d <= 3 ; d++) {
	 ss->DefaultD[d][i] = gl_alloc_texture_object(ss, 0, d);
	 if (!ss->DefaultD[d][i]) {
	    outOfMemory = GL_TRUE;
	    break;
	 }
	 ss->DefaultD[d][i]->RefCount++; /* don't free if not in use */
      }
   }

   if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
      /* Ran out of memory at some point.  Free everything and return NULL */
      if (ss->DisplayList)
         DeleteHashTable(ss->DisplayList);
      if (ss->TexObjects)
         DeleteHashTable(ss->TexObjects);
      for (i=0;i<MAX_TEXTURE_UNITS;i++) {
         if (ss->DefaultD[1][i])
            gl_free_texture_object(ss, ss->DefaultD[1][i]);
         if (ss->DefaultD[2][i])
            gl_free_texture_object(ss, ss->DefaultD[2][i]);
         if (ss->DefaultD[3][i])
            gl_free_texture_object(ss, ss->DefaultD[3][i]);
      }
      free(ss);
      return NULL;
   }
   else {
      return ss;
   }
}


/*
 * Deallocate a shared state context and all children structures.
 */
static void free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
{
   /* Free display lists */
   while (1) {
      GLuint list = HashFirstEntry(ss->DisplayList);
      if (list) {
         gl_destroy_list(ctx, list);
      }
      else {
         break;
      }
   }
   DeleteHashTable(ss->DisplayList);

   /* Free texture objects */
   while (ss->TexObjectList)
   {
      if (ctx->Driver.DeleteTexture)
         (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList );
      /* this function removes from linked list too! */
      gl_free_texture_object(ss, ss->TexObjectList);
   }
   DeleteHashTable(ss->TexObjects);

   free(ss);
}






/*
 * Initialize the nth light.  Note that the defaults for light 0 are
 * different than the other lights.
 */
static void init_light( struct gl_light *l, GLuint n )
{
   make_empty_list( l );

   ASSIGN_4V( l->Ambient, 0.0, 0.0, 0.0, 1.0 );
   if (n==0) {
      ASSIGN_4V( l->Diffuse, 1.0, 1.0, 1.0, 1.0 );
      ASSIGN_4V( l->Specular, 1.0, 1.0, 1.0, 1.0 );
   }
   else {
      ASSIGN_4V( l->Diffuse, 0.0, 0.0, 0.0, 1.0 );
      ASSIGN_4V( l->Specular, 0.0, 0.0, 0.0, 1.0 );
   }
   ASSIGN_4V( l->EyePosition, 0.0, 0.0, 1.0, 0.0 );
   ASSIGN_3V( l->EyeDirection, 0.0, 0.0, -1.0 );
   l->SpotExponent = 0.0;
   gl_compute_spot_exp_table( l );
   l->SpotCutoff = 180.0;
   l->CosCutoff = 0.0;		/* KW: -ve values not admitted */
   l->ConstantAttenuation = 1.0;
   l->LinearAttenuation = 0.0;
   l->QuadraticAttenuation = 0.0;
   l->Enabled = GL_FALSE;
}



static void init_lightmodel( struct gl_lightmodel *lm )
{
   ASSIGN_4V( lm->Ambient, 0.2, 0.2, 0.2, 1.0 );
   lm->LocalViewer = GL_FALSE;
   lm->TwoSide = GL_FALSE;
   lm->ColorControl = GL_SINGLE_COLOR;
}


static void init_material( struct gl_material *m )
{
   ASSIGN_4V( m->Ambient,  0.2, 0.2, 0.2, 1.0 );
   ASSIGN_4V( m->Diffuse,  0.8, 0.8, 0.8, 1.0 );
   ASSIGN_4V( m->Specular, 0.0, 0.0, 0.0, 1.0 );
   ASSIGN_4V( m->Emission, 0.0, 0.0, 0.0, 1.0 );
   m->Shininess = 0.0;
   m->AmbientIndex = 0;
   m->DiffuseIndex = 1;
   m->SpecularIndex = 1;
}



static void init_texture_unit( GLcontext *ctx, GLuint unit )
{
   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];

   texUnit->EnvMode = GL_MODULATE;
   ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
   texUnit->TexGenEnabled = 0;
   texUnit->GenModeS = GL_EYE_LINEAR;
   texUnit->GenModeT = GL_EYE_LINEAR;
   texUnit->GenModeR = GL_EYE_LINEAR;
   texUnit->GenModeQ = GL_EYE_LINEAR;
   /* Yes, these plane coefficients are correct! */
   ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
   ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
   ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );

   texUnit->CurrentD[1] = ctx->Shared->DefaultD[1][unit];
   texUnit->CurrentD[2] = ctx->Shared->DefaultD[2][unit];
   texUnit->CurrentD[3] = ctx->Shared->DefaultD[3][unit];
}


static void init_fallback_arrays( GLcontext *ctx )
{
   struct gl_client_array *cl;
   GLuint i;

   cl = &ctx->Fallback.Normal;
   cl->Size = 3;
   cl->Type = GL_FLOAT;
   cl->Stride = 0;
   cl->StrideB = 0;
   cl->Ptr = (void *) ctx->Current.Normal;
   cl->Enabled = 1;

   cl = &ctx->Fallback.Color;
   cl->Size = 4;
   cl->Type = GL_UNSIGNED_BYTE;
   cl->Stride = 0;
   cl->StrideB = 0;
   cl->Ptr = (void *) ctx->Current.ByteColor;
   cl->Enabled = 1;

   cl = &ctx->Fallback.Index;
   cl->Size = 1;
   cl->Type = GL_UNSIGNED_INT;
   cl->Stride = 0;
   cl->StrideB = 0;
   cl->Ptr = (void *) &ctx->Current.Index;
   cl->Enabled = 1;

   for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
      cl = &ctx->Fallback.TexCoord[i];
      cl->Size = 4;
      cl->Type = GL_FLOAT;
      cl->Stride = 0;
      cl->StrideB = 0;
      cl->Ptr = (void *) ctx->Current.Texcoord[i];
      cl->Enabled = 1;
   }

   cl = &ctx->Fallback.EdgeFlag;
   cl->Size = 1;
   cl->Type = GL_UNSIGNED_BYTE;
   cl->Stride = 0;
   cl->StrideB = 0;
   cl->Ptr = (void *) &ctx->Current.EdgeFlag;
   cl->Enabled = 1;
}

/* Initialize a 1-D evaluator map */
static void init_1d_map( struct gl_1d_map *map, int n, const float *initial )
{
   map->Order = 1;
   map->u1 = 0.0;
   map->u2 = 1.0;
   map->Points = (GLfloat *) malloc(n * sizeof(GLfloat));
   if (map->Points) {
      GLint i;
      for (i=0;i<n;i++)
         map->Points[i] = initial[i];
   }
   map->Retain = GL_FALSE;
}


/* Initialize a 2-D evaluator map */
static void init_2d_map( struct gl_2d_map *map, int n, const float *initial )
{
   map->Uorder = 1;
   map->Vorder = 1;
   map->u1 = 0.0;
   map->u2 = 1.0;
   map->v1 = 0.0;
   map->v2 = 1.0;
   map->Points = (GLfloat *) malloc(n * sizeof(GLfloat));
   if (map->Points) {
      GLint i;
      for (i=0;i<n;i++)
         map->Points[i] = initial[i];
   }
   map->Retain = GL_FALSE;
}



/*
 * Initialize a gl_context structure to default values.
 */
static void initialize_context( GLcontext *ctx )
{
   GLuint i, j;

   if (ctx) {
      /* Constants, may be overriden by device driver */
      ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
      ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
      ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
      ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;


      /* Modelview matrix */
      gl_matrix_ctr( &ctx->ModelView );
      gl_matrix_alloc_inv( &ctx->ModelView );

      ctx->ModelViewStackDepth = 0;
      for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
	 gl_matrix_ctr( &ctx->ModelViewStack[i] );
	 gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
      }

      /* Projection matrix - need inv for user clipping in clip space*/
      gl_matrix_ctr( &ctx->ProjectionMatrix );
      gl_matrix_alloc_inv( &ctx->ProjectionMatrix );

      gl_matrix_ctr( &ctx->ModelProjectMatrix );
      gl_matrix_ctr( &ctx->ModelProjectWinMatrix );
      ctx->ModelProjectWinMatrixUptodate = GL_FALSE;

      ctx->ProjectionStackDepth = 0;
      ctx->NearFarStack[0][0] = 1.0; /* These values seem weird by make */
      ctx->NearFarStack[0][1] = 0.0; /* sense mathematically. */

      for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) {
	 gl_matrix_ctr( &ctx->ProjectionStack[i] );
	 gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
      }

      /* Texture matrix */
      for (i=0; i<MAX_TEXTURE_UNITS; i++) {
	 gl_matrix_ctr( &ctx->TextureMatrix[i] );
	 ctx->TextureStackDepth[i] = 0;
	 for (j = 0 ; j < MAX_TEXTURE_STACK_DEPTH ; j++) {
	    ctx->TextureStack[i][j].inv = 0;
	 }
      }

      /* Accumulate buffer group */
      ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );

      /* Color buffer group */
      ctx->Color.IndexMask = 0xffffffff;
      ctx->Color.ColorMask[0] = 0xff;
      ctx->Color.ColorMask[1] = 0xff;
      ctx->Color.ColorMask[2] = 0xff;
      ctx->Color.ColorMask[3] = 0xff;
      ctx->Color.SWmasking = GL_FALSE;
      ctx->Color.ClearIndex = 0;
      ASSIGN_4V( ctx->Color.ClearColor, 0.0, 0.0, 0.0, 0.0 );
      ctx->Color.DrawBuffer = GL_FRONT;
      ctx->Color.AlphaEnabled = GL_FALSE;
      ctx->Color.AlphaFunc = GL_ALWAYS;
      ctx->Color.AlphaRef = 0;
      ctx->Color.BlendEnabled = GL_FALSE;
      ctx->Color.BlendSrcRGB = GL_ONE;
      ctx->Color.BlendDstRGB = GL_ZERO;
      ctx->Color.BlendSrcA = GL_ONE;
      ctx->Color.BlendDstA = GL_ZERO;
      ctx->Color.BlendEquation = GL_FUNC_ADD_EXT;
      ctx->Color.BlendFunc = NULL;  /* this pointer set only when needed */
      ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
      ctx->Color.IndexLogicOpEnabled = GL_FALSE;
      ctx->Color.ColorLogicOpEnabled = GL_FALSE;
      ctx->Color.SWLogicOpEnabled = GL_FALSE;
      ctx->Color.LogicOp = GL_COPY;
      ctx->Color.DitherFlag = GL_TRUE;
      ctx->Color.MultiDrawBuffer = GL_FALSE;

      /* Current group */
      ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255);
      ctx->Current.Index = 1;
      for (i=0; i<MAX_TEXTURE_UNITS; i++)
         ASSIGN_4V( ctx->Current.Texcoord[i], 0.0, 0.0, 0.0, 1.0 );
      ASSIGN_4V( ctx->Current.RasterPos, 0.0, 0.0, 0.0, 1.0 );
      ctx->Current.RasterDistance = 0.0;
      ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
      ctx->Current.RasterIndex = 1;
      for (i=0; i<MAX_TEXTURE_UNITS; i++)
         ASSIGN_4V( ctx->Current.RasterMultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
      ctx->Current.RasterTexCoord = ctx->Current.RasterMultiTexCoord[0];
      ctx->Current.RasterPosValid = GL_TRUE;
      ctx->Current.EdgeFlag = GL_TRUE;
      ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
      ctx->Current.Primitive = (GLenum) (GL_POLYGON + 1);

      ctx->Current.Flag = (VERT_NORM|VERT_INDEX|VERT_RGBA|VERT_EDGE|
			   VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);

      init_fallback_arrays( ctx );

      /* Depth buffer group */
      ctx->Depth.Test = GL_FALSE;
      ctx->Depth.Clear = 1.0;
      ctx->Depth.Func = GL_LESS;
      ctx->Depth.Mask = GL_TRUE;

      /* Evaluators group */
      ctx->Eval.Map1Color4 = GL_FALSE;
      ctx->Eval.Map1Index = GL_FALSE;
      ctx->Eval.Map1Normal = GL_FALSE;
      ctx->Eval.Map1TextureCoord1 = GL_FALSE;
      ctx->Eval.Map1TextureCoord2 = GL_FALSE;
      ctx->Eval.Map1TextureCoord3 = GL_FALSE;
      ctx->Eval.Map1TextureCoord4 = GL_FALSE;
      ctx->Eval.Map1Vertex3 = GL_FALSE;
      ctx->Eval.Map1Vertex4 = GL_FALSE;
      ctx->Eval.Map2Color4 = GL_FALSE;
      ctx->Eval.Map2Index = GL_FALSE;
      ctx->Eval.Map2Normal = GL_FALSE;
      ctx->Eval.Map2TextureCoord1 = GL_FALSE;
      ctx->Eval.Map2TextureCoord2 = GL_FALSE;
      ctx->Eval.Map2TextureCoord3 = GL_FALSE;
      ctx->Eval.Map2TextureCoord4 = GL_FALSE;
      ctx->Eval.Map2Vertex3 = GL_FALSE;
      ctx->Eval.Map2Vertex4 = GL_FALSE;
      ctx->Eval.AutoNormal = GL_FALSE;
      ctx->Eval.MapGrid1un = 1;
      ctx->Eval.MapGrid1u1 = 0.0;
      ctx->Eval.MapGrid1u2 = 1.0;
      ctx->Eval.MapGrid2un = 1;
      ctx->Eval.MapGrid2vn = 1;
      ctx->Eval.MapGrid2u1 = 0.0;
      ctx->Eval.MapGrid2u2 = 1.0;
      ctx->Eval.MapGrid2v1 = 0.0;
      ctx->Eval.MapGrid2v2 = 1.0;

      /* Evaluator data */
      {
         static GLfloat vertex[4] = { 0.0, 0.0, 0.0, 1.0 };
         static GLfloat normal[3] = { 0.0, 0.0, 1.0 };
         static GLfloat index[1] = { 1.0 };
         static GLfloat color[4] = { 1.0, 1.0, 1.0, 1.0 };
         static GLfloat texcoord[4] = { 0.0, 0.0, 0.0, 1.0 };

         init_1d_map( &ctx->EvalMap.Map1Vertex3, 3, vertex );
         init_1d_map( &ctx->EvalMap.Map1Vertex4, 4, vertex );
         init_1d_map( &ctx->EvalMap.Map1Index, 1, index );
         init_1d_map( &ctx->EvalMap.Map1Color4, 4, color );
         init_1d_map( &ctx->EvalMap.Map1Normal, 3, normal );
         init_1d_map( &ctx->EvalMap.Map1Texture1, 1, texcoord );
         init_1d_map( &ctx->EvalMap.Map1Texture2, 2, texcoord );
         init_1d_map( &ctx->EvalMap.Map1Texture3, 3, texcoord );
         init_1d_map( &ctx->EvalMap.Map1Texture4, 4, texcoord );

         init_2d_map( &ctx->EvalMap.Map2Vertex3, 3, vertex );
         init_2d_map( &ctx->EvalMap.Map2Vertex4, 4, vertex );
         init_2d_map( &ctx->EvalMap.Map2Index, 1, index );
         init_2d_map( &ctx->EvalMap.Map2Color4, 4, color );
         init_2d_map( &ctx->EvalMap.Map2Normal, 3, normal );
         init_2d_map( &ctx->EvalMap.Map2Texture1, 1, texcoord );
         init_2d_map( &ctx->EvalMap.Map2Texture2, 2, texcoord );
         init_2d_map( &ctx->EvalMap.Map2Texture3, 3, texcoord );
         init_2d_map( &ctx->EvalMap.Map2Texture4, 4, texcoord );
      }

      /* Fog group */
      ctx->Fog.Enabled = GL_FALSE;
      ctx->Fog.Mode = GL_EXP;
      ASSIGN_4V( ctx->Fog.Color, 0.0, 0.0, 0.0, 0.0 );
      ctx->Fog.Index = 0.0;
      ctx->Fog.Density = 1.0;
      ctx->Fog.Start = 0.0;
      ctx->Fog.End = 1.0;

      /* Hint group */
      ctx->Hint.PerspectiveCorrection = GL_DONT_CARE;
      ctx->Hint.PointSmooth = GL_DONT_CARE;
      ctx->Hint.LineSmooth = GL_DONT_CARE;
      ctx->Hint.PolygonSmooth = GL_DONT_CARE;
      ctx->Hint.Fog = GL_DONT_CARE;

      ctx->Hint.AllowDrawWin = GL_TRUE;
      ctx->Hint.AllowDrawSpn = GL_TRUE;
      ctx->Hint.AllowDrawMem = GL_TRUE;
      ctx->Hint.StrictLighting = GL_TRUE;

      /* Pipeline */
      gl_pipeline_init( ctx );
      gl_cva_init( ctx );

      /* Extensions */
      gl_extensions_ctr( ctx );

      ctx->AllowVertexCull = 0;

      /* Lighting group */
      for (i=0;i<MAX_LIGHTS;i++) {
	 init_light( &ctx->Light.Light[i], i );
      }
      make_empty_list( &ctx->Light.EnabledList );

      init_lightmodel( &ctx->Light.Model );
      init_material( &ctx->Light.Material[0] );
      init_material( &ctx->Light.Material[1] );
      ctx->Light.ShadeModel = GL_SMOOTH;
      ctx->Light.Enabled = GL_FALSE;
      ctx->Light.ColorMaterialFace = GL_FRONT_AND_BACK;
      ctx->Light.ColorMaterialMode = GL_AMBIENT_AND_DIFFUSE;
      ctx->Light.ColorMaterialBitmask
         = gl_material_bitmask( ctx,
				GL_FRONT_AND_BACK,
				GL_AMBIENT_AND_DIFFUSE, ~0, 0 );

      ctx->Light.ColorMaterialEnabled = GL_FALSE;

      /* Line group */
      ctx->Line.SmoothFlag = GL_FALSE;
      ctx->Line.StippleFlag = GL_FALSE;
      ctx->Line.Width = 1.0;
      ctx->Line.StipplePattern = 0xffff;
      ctx->Line.StippleFactor = 1;

      /* Display List group */
      ctx->List.ListBase = 0;

      /* Pixel group */
      ctx->Pixel.RedBias = 0.0;
      ctx->Pixel.RedScale = 1.0;
      ctx->Pixel.GreenBias = 0.0;
      ctx->Pixel.GreenScale = 1.0;
      ctx->Pixel.BlueBias = 0.0;
      ctx->Pixel.BlueScale = 1.0;
      ctx->Pixel.AlphaBias = 0.0;
      ctx->Pixel.AlphaScale = 1.0;
      ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE;
      ctx->Pixel.DepthBias = 0.0;
      ctx->Pixel.DepthScale = 1.0;
      ctx->Pixel.IndexOffset = 0;
      ctx->Pixel.IndexShift = 0;
      ctx->Pixel.ZoomX = 1.0;
      ctx->Pixel.ZoomY = 1.0;
      ctx->Pixel.MapColorFlag = GL_FALSE;
      ctx->Pixel.MapStencilFlag = GL_FALSE;
      ctx->Pixel.MapStoSsize = 1;
      ctx->Pixel.MapItoIsize = 1;
      ctx->Pixel.MapItoRsize = 1;
      ctx->Pixel.MapItoGsize = 1;
      ctx->Pixel.MapItoBsize = 1;
      ctx->Pixel.MapItoAsize = 1;
      ctx->Pixel.MapRtoRsize = 1;
      ctx->Pixel.MapGtoGsize = 1;
      ctx->Pixel.MapBtoBsize = 1;
      ctx->Pixel.MapAtoAsize = 1;
      ctx->Pixel.MapStoS[0] = 0;
      ctx->Pixel.MapItoI[0] = 0;
      ctx->Pixel.MapItoR[0] = 0.0;
      ctx->Pixel.MapItoG[0] = 0.0;
      ctx->Pixel.MapItoB[0] = 0.0;
      ctx->Pixel.MapItoA[0] = 0.0;
      ctx->Pixel.MapItoR8[0] = 0;
      ctx->Pixel.MapItoG8[0] = 0;
      ctx->Pixel.MapItoB8[0] = 0;
      ctx->Pixel.MapItoA8[0] = 0;
      ctx->Pixel.MapRtoR[0] = 0.0;
      ctx->Pixel.MapGtoG[0] = 0.0;
      ctx->Pixel.MapBtoB[0] = 0.0;
      ctx->Pixel.MapAtoA[0] = 0.0;

      /* Point group */
      ctx->Point.SmoothFlag = GL_FALSE;
      ctx->Point.Size = 1.0;
      ctx->Point.Params[0] = 1.0;
      ctx->Point.Params[1] = 0.0;
      ctx->Point.Params[2] = 0.0;
      ctx->Point.Attenuated = GL_FALSE;
      ctx->Point.MinSize = 0.0;
      ctx->Point.MaxSize = (GLfloat) MAX_POINT_SIZE;
      ctx->Point.Threshold = 1.0;

      /* Polygon group */
      ctx->Polygon.CullFlag = GL_FALSE;
      ctx->Polygon.CullFaceMode = GL_BACK;
      ctx->Polygon.FrontFace = GL_CCW;
      ctx->Polygon.FrontBit = 0;
      ctx->Polygon.FrontMode = GL_FILL;
      ctx->Polygon.BackMode = GL_FILL;
      ctx->Polygon.Unfilled = GL_FALSE;
      ctx->Polygon.SmoothFlag = GL_FALSE;
      ctx->Polygon.StippleFlag = GL_FALSE;
      ctx->Polygon.OffsetFactor = 0.0F;
      ctx->Polygon.OffsetUnits = 0.0F;
      ctx->Polygon.OffsetPoint = GL_FALSE;
      ctx->Polygon.OffsetLine = GL_FALSE;
      ctx->Polygon.OffsetFill = GL_FALSE;

      /* Polygon Stipple group */
      MEMSET( ctx->PolygonStipple, 0xff, 32*sizeof(GLuint) );

      /* Scissor group */
      ctx->Scissor.Enabled = GL_FALSE;
      ctx->Scissor.X = 0;
      ctx->Scissor.Y = 0;
      ctx->Scissor.Width = 0;
      ctx->Scissor.Height = 0;

      /* Stencil group */
      ctx->Stencil.Enabled = GL_FALSE;
      ctx->Stencil.Function = GL_ALWAYS;
      ctx->Stencil.FailFunc = GL_KEEP;
      ctx->Stencil.ZPassFunc = GL_KEEP;
      ctx->Stencil.ZFailFunc = GL_KEEP;
      ctx->Stencil.Ref = 0;
      ctx->Stencil.ValueMask = 0xff;
      ctx->Stencil.Clear = 0;
      ctx->Stencil.WriteMask = 0xff;

      /* Texture group */
      ctx->Texture.CurrentUnit = 0;      /* multitexture */
      ctx->Texture.CurrentTransformUnit = 0; /* multitexture */
      ctx->Texture.Enabled = 0;

      for (i=0; i<MAX_TEXTURE_UNITS; i++)
         init_texture_unit( ctx, i );

      ctx->Texture.SharedPalette = GL_FALSE;
      ctx->Texture.Palette[0] = 255;
      ctx->Texture.Palette[1] = 255;
      ctx->Texture.Palette[2] = 255;
      ctx->Texture.Palette[3] = 255;
      ctx->Texture.PaletteSize = 1;
      ctx->Texture.PaletteIntFormat = GL_RGBA;
      ctx->Texture.PaletteFormat = GL_RGBA;

      /* Transformation group */
      ctx->Transform.MatrixMode = GL_MODELVIEW;
      ctx->Transform.Normalize = GL_FALSE;
      ctx->Transform.RescaleNormals = GL_FALSE;
      for (i=0;i<MAX_CLIP_PLANES;i++) {
	 ctx->Transform.ClipEnabled[i] = GL_FALSE;
         ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
      }
      ctx->Transform.AnyClip = GL_FALSE;

      /* Viewport group */
      ctx->Viewport.X = 0;
      ctx->Viewport.Y = 0;
      ctx->Viewport.Width = 0;
      ctx->Viewport.Height = 0;
      ctx->Viewport.Near = 0.0;
      ctx->Viewport.Far = 1.0;
      gl_matrix_ctr(&ctx->Viewport.WindowMap);

#define Sz 10
#define Tz 14
      ctx->Viewport.WindowMap.m[Sz] = 0.5 * DEPTH_SCALE;
      ctx->Viewport.WindowMap.m[Tz] = 0.5 * DEPTH_SCALE;
#undef Sz
#undef Tz

      ctx->Viewport.WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
      ctx->Viewport.WindowMap.type = MATRIX_3D_NO_ROT;

      /* Vertex arrays */
      ctx->Array.Vertex.Size = 4;
      ctx->Array.Vertex.Type = GL_FLOAT;
      ctx->Array.Vertex.Stride = 0;
      ctx->Array.Vertex.StrideB = 0;
      ctx->Array.Vertex.Ptr = NULL;
      ctx->Array.Vertex.Enabled = GL_FALSE;
      ctx->Array.Normal.Type = GL_FLOAT;
      ctx->Array.Normal.Stride = 0;
      ctx->Array.Normal.StrideB = 0;
      ctx->Array.Normal.Ptr = NULL;
      ctx->Array.Normal.Enabled = GL_FALSE;
      ctx->Array.Color.Size = 4;
      ctx->Array.Color.Type = GL_FLOAT;
      ctx->Array.Color.Stride = 0;
      ctx->Array.Color.StrideB = 0;
      ctx->Array.Color.Ptr = NULL;
      ctx->Array.Color.Enabled = GL_FALSE;
      ctx->Array.Index.Type = GL_FLOAT;
      ctx->Array.Index.Stride = 0;
      ctx->Array.Index.StrideB = 0;
      ctx->Array.Index.Ptr = NULL;
      ctx->Array.Index.Enabled = GL_FALSE;
      for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
         ctx->Array.TexCoord[i].Size = 4;
         ctx->Array.TexCoord[i].Type = GL_FLOAT;
         ctx->Array.TexCoord[i].Stride = 0;
         ctx->Array.TexCoord[i].StrideB = 0;
         ctx->Array.TexCoord[i].Ptr = NULL;
         ctx->Array.TexCoord[i].Enabled = GL_FALSE;
      }
      ctx->Array.TexCoordInterleaveFactor = 1;
      ctx->Array.EdgeFlag.Stride = 0;
      ctx->Array.EdgeFlag.StrideB = 0;
      ctx->Array.EdgeFlag.Ptr = NULL;
      ctx->Array.EdgeFlag.Enabled = GL_FALSE;
      ctx->Array.ActiveTexture = 0;   /* GL_ARB_multitexture */

      /* Pixel transfer */
      ctx->Pack.Alignment = 4;
      ctx->Pack.RowLength = 0;
      ctx->Pack.SkipPixels = 0;
      ctx->Pack.SkipRows = 0;
      ctx->Pack.SwapBytes = GL_FALSE;
      ctx->Pack.LsbFirst = GL_FALSE;
      ctx->Unpack.Alignment = 4;
      ctx->Unpack.RowLength = 0;
      ctx->Unpack.SkipPixels = 0;
      ctx->Unpack.SkipRows = 0;
      ctx->Unpack.SwapBytes = GL_FALSE;
      ctx->Unpack.LsbFirst = GL_FALSE;

      /* Feedback */
      ctx->Feedback.Type = GL_2D;   /* TODO: verify */
      ctx->Feedback.Buffer = NULL;
      ctx->Feedback.BufferSize = 0;
      ctx->Feedback.Count = 0;

      /* Selection/picking */
      ctx->Select.Buffer = NULL;
      ctx->Select.BufferSize = 0;
      ctx->Select.BufferCount = 0;
      ctx->Select.Hits = 0;
      ctx->Select.NameStackDepth = 0;

      /* Optimized Accum buffer */
      ctx->IntegerAccumMode = GL_TRUE;
      ctx->IntegerAccumScaler = 0.0;

      /* multitexture */
      ctx->TexCoordUnit = 0;

      /* Renderer and client attribute stacks */
      ctx->AttribStackDepth = 0;
      ctx->ClientAttribStackDepth = 0;

      /*** Miscellaneous ***/
      ctx->NewState = NEW_ALL;
      ctx->RenderMode = GL_RENDER;
      ctx->StippleCounter = 0;
      ctx->NeedNormals = GL_FALSE;
      ctx->DoViewportMapping = GL_TRUE;

      ctx->NeedEyeCoords = GL_FALSE;
      ctx->NeedEyeNormals = GL_FALSE;
      ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;

      /* Display list */
      ctx->CallDepth = 0;
      ctx->ExecuteFlag = GL_TRUE;
      ctx->CompileFlag = GL_FALSE;
      ctx->CurrentListPtr = NULL;
      ctx->CurrentBlock = NULL;
      ctx->CurrentListNum = 0;
      ctx->CurrentPos = 0;

      ctx->ErrorValue = (GLenum) GL_NO_ERROR;

      ctx->CatchSignals = GL_TRUE;

      /* For debug/development only */
      ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;

      /* Dither disable */
      ctx->NoDither = getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
      if (ctx->NoDither) {
         if (getenv("MESA_DEBUG")) {
            fprintf(stderr, "MESA_NO_DITHER set - dithering disabled\n");
         }
         ctx->Color.DitherFlag = GL_FALSE;
      }
   }
}



/*
 * Allocate a new GLvisual object.
 * Input:  rgbFlag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
 *         alphaFlag - alloc software alpha buffers?
 *         dbFlag - double buffering?
 *         stereoFlag - stereo buffer?
 *         depthFits - requested minimum bits per depth buffer value
 *         stencilFits - requested minimum bits per stencil buffer value
 *         accumFits - requested minimum bits per accum buffer component
 *         indexFits - number of bits per pixel if rgbFlag==GL_FALSE
 *         red/green/blue/alphaFits - number of bits per color component
 *                                     in frame buffer for RGB(A) mode.
 * Return:  pointer to new GLvisual or NULL if requested parameters can't
 *          be met.
 */
GLvisual *gl_create_visual( GLboolean rgbFlag,
                            GLboolean alphaFlag,
                            GLboolean dbFlag,
                            GLboolean stereoFlag,
                            GLint depthBits,
                            GLint stencilBits,
                            GLint accumBits,
                            GLint indexBits,
                            GLint redBits,
                            GLint greenBits,
                            GLint blueBits,
                            GLint alphaBits )
{
   GLvisual *vis;

   if (depthBits > (GLint) (8*sizeof(GLdepth))) {
      /* can't meet depth buffer requirements */
      return NULL;
   }
   if (stencilBits > (GLint) (8*sizeof(GLstencil))) {
      /* can't meet stencil buffer requirements */
      return NULL;
   }
   if (accumBits > (GLint) (8*sizeof(GLaccum))) {
      /* can't meet accum buffer requirements */
      return NULL;
   }

   vis = (GLvisual *) calloc( 1, sizeof(GLvisual) );
   if (!vis) {
      return NULL;
   }

   vis->RGBAflag   = rgbFlag;
   vis->DBflag     = dbFlag;
   vis->StereoFlag = stereoFlag;
   vis->RedBits    = redBits;
   vis->GreenBits  = greenBits;
   vis->BlueBits   = blueBits;
   vis->AlphaBits  = alphaFlag ? 8*sizeof(GLubyte) : alphaBits;

   vis->IndexBits   = indexBits;
   vis->DepthBits   = (depthBits>0) ? 8*sizeof(GLdepth) : 0;
   vis->AccumBits   = (accumBits>0) ? 8*sizeof(GLaccum) : 0;
   vis->StencilBits = (stencilBits>0) ? 8*sizeof(GLstencil) : 0;

   vis->SoftwareAlpha = alphaFlag;

   return vis;
}



void gl_destroy_visual( GLvisual *vis )
{
   free( vis );
}



/*
 * Allocate the proxy textures.  If we run out of memory part way through
 * the allocations clean up and return GL_FALSE.
 * Return:  GL_TRUE=success, GL_FALSE=failure
 */
static GLboolean alloc_proxy_textures( GLcontext *ctx )
{
   GLboolean out_of_memory;
   GLint i;

   ctx->Texture.Proxy1D = gl_alloc_texture_object(NULL, 0, 1);
   if (!ctx->Texture.Proxy1D) {
      return GL_FALSE;
   }

   ctx->Texture.Proxy2D = gl_alloc_texture_object(NULL, 0, 2);
   if (!ctx->Texture.Proxy2D) {
      gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
      return GL_FALSE;
   }

   ctx->Texture.Proxy3D = gl_alloc_texture_object(NULL, 0, 3);
   if (!ctx->Texture.Proxy3D) {
      gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
      gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
      return GL_FALSE;
   }

   out_of_memory = GL_FALSE;
   for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
      ctx->Texture.Proxy1D->Image[i] = gl_alloc_texture_image();
      ctx->Texture.Proxy2D->Image[i] = gl_alloc_texture_image();
      ctx->Texture.Proxy3D->Image[i] = gl_alloc_texture_image();
      if (!ctx->Texture.Proxy1D->Image[i]
          || !ctx->Texture.Proxy2D->Image[i]
          || !ctx->Texture.Proxy3D->Image[i]) {
         out_of_memory = GL_TRUE;
      }
   }
   if (out_of_memory) {
      for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
         if (ctx->Texture.Proxy1D->Image[i]) {
            gl_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
         }
         if (ctx->Texture.Proxy2D->Image[i]) {
            gl_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
         }
         if (ctx->Texture.Proxy3D->Image[i]) {
            gl_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
         }
      }
      gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
      gl_free_texture_object(NULL, ctx->Texture.Proxy2D);
      gl_free_texture_object(NULL, ctx->Texture.Proxy3D);
      return GL_FALSE;
   }
   else {
      return GL_TRUE;
   }
}



#define MALLOC_STRUCT(T)  (struct T *) malloc( sizeof(struct T) )

/*
 * Allocate and initialize a GLcontext structure.
 * Input:  visual - a GLvisual pointer
 *         sharelist - another context to share display lists with or NULL
 *         driver_ctx - pointer to device driver's context state struct
 * Return:  pointer to a new gl_context struct or NULL if error.
 */
GLcontext *gl_create_context( GLvisual *visual,
                              GLcontext *share_list,
                              void *driver_ctx,
                              GLboolean direct )
{
   GLcontext *ctx;
   GLuint i;

   (void) direct;  /* not used */

   /* do some implementation tests */
   assert( sizeof(GLbyte) == 1 );
   assert( sizeof(GLshort) >= 2 );
   assert( sizeof(GLint) >= 4 );
   assert( sizeof(GLubyte) == 1 );
   assert( sizeof(GLushort) >= 2 );
   assert( sizeof(GLuint) >= 4 );

   /* misc one-time initializations */
   one_time_init();

   ctx = (GLcontext *) calloc( 1, sizeof(GLcontext) );
   if (!ctx) {
      return NULL;
   }

   ctx->DriverCtx = driver_ctx;
   ctx->Visual = visual;
   ctx->Buffer = NULL;

   ctx->VB = gl_vb_create_for_immediate( ctx );
   if (!ctx->VB) {
      free( ctx );
      return NULL;
   }
   ctx->input = ctx->VB->IM;

   ctx->PB = gl_alloc_pb();
   if (!ctx->PB) {
      free( ctx->VB );
      free( ctx );
      return NULL;
   }

   if (share_list) {
      /* share the group of display lists of another context */
      ctx->Shared = share_list->Shared;
   }
   else {
      /* allocate new group of display lists */
      ctx->Shared = alloc_shared_state();
      if (!ctx->Shared) {
         free(ctx->VB);
         free(ctx->PB);
         free(ctx);
         return NULL;
      }
   }
   ctx->Shared->RefCount++;

   initialize_context( ctx );
   gl_reset_vb( ctx->VB );
   gl_reset_input( ctx );


   ctx->ShineTabList = MALLOC_STRUCT( gl_shine_tab );
   make_empty_list( ctx->ShineTabList );

   for (i = 0 ; i < 10 ; i++) {
      struct gl_shine_tab *s = MALLOC_STRUCT( gl_shine_tab );
      s->shininess = -1;
      s->refcount = 0;
      insert_at_tail( ctx->ShineTabList, s );
   }

   for (i = 0 ; i < 4 ; i++) {
      ctx->ShineTable[i] = ctx->ShineTabList->prev;
      ctx->ShineTable[i]->refcount++;
   }

   if (visual->DBflag) {
      ctx->Color.DrawBuffer = GL_BACK;
      ctx->Color.DriverDrawBuffer = GL_BACK_LEFT;
      ctx->Color.DrawDestMask = BACK_LEFT_BIT;
      ctx->Pixel.ReadBuffer = GL_BACK;
      ctx->Pixel.DriverReadBuffer = GL_BACK_LEFT;
   }
   else {
      ctx->Color.DrawBuffer = GL_FRONT;
      ctx->Color.DriverDrawBuffer = GL_FRONT_LEFT;
      ctx->Color.DrawDestMask = FRONT_LEFT_BIT;
      ctx->Pixel.ReadBuffer = GL_FRONT;
      ctx->Pixel.DriverReadBuffer = GL_FRONT_LEFT;
   }

#ifdef PROFILE
   init_timings( ctx );
#endif

#ifdef GL_VERSION_1_1
   if (!alloc_proxy_textures(ctx)) {
      free_shared_state(ctx, ctx->Shared);
      free(ctx->VB);
      free(ctx->PB);
      free(ctx);
      return NULL;
   }
#endif

   gl_init_api_function_pointers( ctx );
   ctx->API = ctx->Exec;   /* GL_EXECUTE is default */

   return ctx;
}

/* Just reads the config files...
 */
void gl_context_initialize( GLcontext *ctx )
{
   gl_read_config_file( ctx );
}




/*
 * Destroy a gl_context structure.
 */
void gl_destroy_context( GLcontext *ctx )
{
   if (ctx) {

      GLuint i;
      struct gl_shine_tab *s, *tmps;

#ifdef PROFILE
      if (getenv("MESA_PROFILE")) {
         print_timings( ctx );
      }
#endif

      gl_matrix_dtr( &ctx->ModelView );
      for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
	 gl_matrix_dtr( &ctx->ModelViewStack[i] );
      }


      free( ctx->PB );
      free( ctx->VB );

      ctx->Shared->RefCount--;
      assert(ctx->Shared->RefCount>=0);
      if (ctx->Shared->RefCount==0) {
	 /* free shared state */
	 free_shared_state( ctx, ctx->Shared );
      }

      foreach_s( s, tmps, ctx->ShineTabList ) {
	 free( s );
      }
      free( ctx->ShineTabList );

      /* Free proxy texture objects */
      gl_free_texture_object( NULL, ctx->Texture.Proxy1D );
      gl_free_texture_object( NULL, ctx->Texture.Proxy2D );
      gl_free_texture_object( NULL, ctx->Texture.Proxy3D );

      /* Free evaluator data */
      if (ctx->EvalMap.Map1Vertex3.Points)
         free( ctx->EvalMap.Map1Vertex3.Points );
      if (ctx->EvalMap.Map1Vertex4.Points)
         free( ctx->EvalMap.Map1Vertex4.Points );
      if (ctx->EvalMap.Map1Index.Points)
         free( ctx->EvalMap.Map1Index.Points );
      if (ctx->EvalMap.Map1Color4.Points)
         free( ctx->EvalMap.Map1Color4.Points );
      if (ctx->EvalMap.Map1Normal.Points)
         free( ctx->EvalMap.Map1Normal.Points );
      if (ctx->EvalMap.Map1Texture1.Points)
         free( ctx->EvalMap.Map1Texture1.Points );
      if (ctx->EvalMap.Map1Texture2.Points)
         free( ctx->EvalMap.Map1Texture2.Points );
      if (ctx->EvalMap.Map1Texture3.Points)
         free( ctx->EvalMap.Map1Texture3.Points );
      if (ctx->EvalMap.Map1Texture4.Points)
         free( ctx->EvalMap.Map1Texture4.Points );

      if (ctx->EvalMap.Map2Vertex3.Points)
         free( ctx->EvalMap.Map2Vertex3.Points );
      if (ctx->EvalMap.Map2Vertex4.Points)
         free( ctx->EvalMap.Map2Vertex4.Points );
      if (ctx->EvalMap.Map2Index.Points)
         free( ctx->EvalMap.Map2Index.Points );
      if (ctx->EvalMap.Map2Color4.Points)
         free( ctx->EvalMap.Map2Color4.Points );
      if (ctx->EvalMap.Map2Normal.Points)
         free( ctx->EvalMap.Map2Normal.Points );
      if (ctx->EvalMap.Map2Texture1.Points)
         free( ctx->EvalMap.Map2Texture1.Points );
      if (ctx->EvalMap.Map2Texture2.Points)
         free( ctx->EvalMap.Map2Texture2.Points );
      if (ctx->EvalMap.Map2Texture3.Points)
         free( ctx->EvalMap.Map2Texture3.Points );
      if (ctx->EvalMap.Map2Texture4.Points)
         free( ctx->EvalMap.Map2Texture4.Points );

      free( (void *) ctx );

#ifndef THREADS
      if (ctx==CC) {
         CC = NULL;
	 CURRENT_INPUT = NULL;
      }
#endif

   }
}



/*
 * Create a new framebuffer.  A GLframebuffer is a struct which
 * encapsulates the depth, stencil and accum buffers and related
 * parameters.
 * Input:  visual - a GLvisual pointer
 * Return:  pointer to new GLframebuffer struct or NULL if error.
 */
GLframebuffer *gl_create_framebuffer( GLvisual *visual )
{
   GLframebuffer *buffer;

   buffer = (GLframebuffer *) calloc( 1, sizeof(GLframebuffer) );
   if (!buffer) {
      return NULL;
   }

   buffer->Visual = visual;

   return buffer;
}



/*
 * Free a framebuffer struct and its buffers.
 */
void gl_destroy_framebuffer( GLframebuffer *buffer )
{
   if (buffer) {
      if (buffer->Depth) {
         free( buffer->Depth );
      }
      if (buffer->Accum) {
         free( buffer->Accum );
      }
      if (buffer->Stencil) {
         free( buffer->Stencil );
      }
      if (buffer->FrontLeftAlpha) {
         free( buffer->FrontLeftAlpha );
      }
      if (buffer->BackLeftAlpha) {
         free( buffer->BackLeftAlpha );
      }
      if (buffer->FrontRightAlpha) {
         free( buffer->FrontRightAlpha );
      }
      if (buffer->BackRightAlpha) {
         free( buffer->BackRightAlpha );
      }
      free(buffer);
   }
}



/*
 * Set the current context, binding the given frame buffer to the context.
 */
void gl_make_current( GLcontext *ctx, GLframebuffer *buffer )
{
   GET_CONTEXT;

   /* Flush the old context
    */
   if (CC) {
      ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(CC, "gl_make_current");
   }

#ifdef THREADS
   /* TODO: unbind old buffer from context? */
   set_thread_context( ctx );
#else
   if (CC && CC->Buffer) {
      /* unbind frame buffer from context */
      CC->Buffer = NULL;
   }
   CC = ctx;
   if (ctx) {
      SET_IMMEDIATE(ctx, ctx->input);
   }
#endif

   if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");

   if (ctx && buffer) {
      /* TODO: check if ctx and buffer's visual match??? */
      ctx->Buffer = buffer;      /* Bind the frame buffer to the context */
      ctx->NewState = NEW_ALL;   /* just to be safe */
      gl_update_state( ctx );
   }
}


/*
 * Return current context handle.
 */
GLcontext *gl_get_current_context( void )
{
#ifdef THREADS
   return gl_get_thread_context();
#else
   return CC;
#endif
}



/*
 * Copy attribute groups from one context to another.
 * Input:  src - source context
 *         dst - destination context
 *         mask - bitwise OR of GL_*_BIT flags
 */
void gl_copy_context( const GLcontext *src, GLcontext *dst, GLuint mask )
{
   if (mask & GL_ACCUM_BUFFER_BIT) {
      MEMCPY( &dst->Accum, &src->Accum, sizeof(struct gl_accum_attrib) );
   }
   if (mask & GL_COLOR_BUFFER_BIT) {
      MEMCPY( &dst->Color, &src->Color, sizeof(struct gl_colorbuffer_attrib) );
   }
   if (mask & GL_CURRENT_BIT) {
      MEMCPY( &dst->Current, &src->Current, sizeof(struct gl_current_attrib) );
   }
   if (mask & GL_DEPTH_BUFFER_BIT) {
      MEMCPY( &dst->Depth, &src->Depth, sizeof(struct gl_depthbuffer_attrib) );
   }
   if (mask & GL_ENABLE_BIT) {
      /* no op */
   }
   if (mask & GL_EVAL_BIT) {
      MEMCPY( &dst->Eval, &src->Eval, sizeof(struct gl_eval_attrib) );
   }
   if (mask & GL_FOG_BIT) {
      MEMCPY( &dst->Fog, &src->Fog, sizeof(struct gl_fog_attrib) );
   }
   if (mask & GL_HINT_BIT) {
      MEMCPY( &dst->Hint, &src->Hint, sizeof(struct gl_hint_attrib) );
   }
   if (mask & GL_LIGHTING_BIT) {
      MEMCPY( &dst->Light, &src->Light, sizeof(struct gl_light_attrib) );
/*       gl_reinit_light_attrib( &dst->Light ); */
   }
   if (mask & GL_LINE_BIT) {
      MEMCPY( &dst->Line, &src->Line, sizeof(struct gl_line_attrib) );
   }
   if (mask & GL_LIST_BIT) {
      MEMCPY( &dst->List, &src->List, sizeof(struct gl_list_attrib) );
   }
   if (mask & GL_PIXEL_MODE_BIT) {
      MEMCPY( &dst->Pixel, &src->Pixel, sizeof(struct gl_pixel_attrib) );
   }
   if (mask & GL_POINT_BIT) {
      MEMCPY( &dst->Point, &src->Point, sizeof(struct gl_point_attrib) );
   }
   if (mask & GL_POLYGON_BIT) {
      MEMCPY( &dst->Polygon, &src->Polygon, sizeof(struct gl_polygon_attrib) );
   }
   if (mask & GL_POLYGON_STIPPLE_BIT) {
      /* Use loop instead of MEMCPY due to problem with Portland Group's
       * C compiler.  Reported by John Stone.
       */
      int i;
      for (i=0;i<32;i++) {
         dst->PolygonStipple[i] = src->PolygonStipple[i];
      }
   }
   if (mask & GL_SCISSOR_BIT) {
      MEMCPY( &dst->Scissor, &src->Scissor, sizeof(struct gl_scissor_attrib) );
   }
   if (mask & GL_STENCIL_BUFFER_BIT) {
      MEMCPY( &dst->Stencil, &src->Stencil, sizeof(struct gl_stencil_attrib) );
   }
   if (mask & GL_TEXTURE_BIT) {
      MEMCPY( &dst->Texture, &src->Texture, sizeof(struct gl_texture_attrib) );
   }
   if (mask & GL_TRANSFORM_BIT) {
      MEMCPY( &dst->Transform, &src->Transform, sizeof(struct gl_transform_attrib) );
   }
   if (mask & GL_VIEWPORT_BIT) {
      MEMCPY( &dst->Viewport, &src->Viewport, sizeof(struct gl_viewport_attrib) );
   }
}



/*
 * Someday a GLS library or OpenGL-like debugger may call this function
 * to register it's own set of API entry points.
 * Input: ctx - the context to set API pointers for
 *        api - if NULL, restore original API pointers
 *              else, set API function table to this table.
 */
void gl_set_api_table( GLcontext *ctx, const struct gl_api_table *api )
{
   if (api) {
      MEMCPY( &ctx->API, api, sizeof(struct gl_api_table) );
   }
   else {
      MEMCPY( &ctx->API, &ctx->Exec, sizeof(struct gl_api_table) );
   }
}




/**********************************************************************/
/*****                Miscellaneous functions                     *****/
/**********************************************************************/


/*
 * This function is called when the Mesa user has stumbled into a code
 * path which may not be implemented fully or correctly.
 */
void gl_problem( const GLcontext *ctx, const char *s )
{
   fprintf( stderr, "Mesa implementation error: %s\n", s );
   fprintf( stderr, "Report to mesa-bugs@@mesa3d.org\n" );
   (void) ctx;
}



/*
 * This is called to inform the user that he or she has tried to do
 * something illogical or if there's likely a bug in their program
 * (like enabled depth testing without a depth buffer).
 */
void gl_warning( const GLcontext *ctx, const char *s )
{
   GLboolean debug;
#ifdef DEBUG
   debug = GL_TRUE;
#else
   if (getenv("MESA_DEBUG")) {
      debug = GL_TRUE;
   }
   else {
      debug = GL_FALSE;
   }
#endif
   if (debug) {
      fprintf( stderr, "Mesa warning: %s\n", s );
   }
   (void) ctx;
}



void gl_compile_error( GLcontext *ctx, GLenum error, const char *s )
{
   if (ctx->CompileFlag)
      gl_save_error( ctx, error, s );

   if (ctx->ExecuteFlag)
      gl_error( ctx, error, s );
}


/*
 * This is Mesa's error handler.  Normally, all that's done is the updating
 * of the current error value.  If Mesa is compiled with -DDEBUG or if the
 * environment variable "MESA_DEBUG" is defined then a real error message
 * is printed to stderr.
 * Input:  error - the error value
 *         s - a diagnostic string
 */
void gl_error( GLcontext *ctx, GLenum error, const char *s )
{
   GLboolean debug;

#ifdef DEBUG
   debug = GL_TRUE;
#else
   if (getenv("MESA_DEBUG")) {
      debug = GL_TRUE;
   }
   else {
      debug = GL_FALSE;
   }
#endif

   if (debug) {
      char errstr[1000];

      switch (error) {
	 case GL_NO_ERROR:
	    strcpy( errstr, "GL_NO_ERROR" );
	    break;
	 case GL_INVALID_VALUE:
	    strcpy( errstr, "GL_INVALID_VALUE" );
	    break;
	 case GL_INVALID_ENUM:
	    strcpy( errstr, "GL_INVALID_ENUM" );
	    break;
	 case GL_INVALID_OPERATION:
	    strcpy( errstr, "GL_INVALID_OPERATION" );
	    break;
	 case GL_STACK_OVERFLOW:
	    strcpy( errstr, "GL_STACK_OVERFLOW" );
	    break;
	 case GL_STACK_UNDERFLOW:
	    strcpy( errstr, "GL_STACK_UNDERFLOW" );
	    break;
	 case GL_OUT_OF_MEMORY:
	    strcpy( errstr, "GL_OUT_OF_MEMORY" );
	    break;
	 default:
	    strcpy( errstr, "unknown" );
	    break;
      }
      fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s );
   }

   if (ctx->ErrorValue==GL_NO_ERROR) {
      ctx->ErrorValue = error;
   }

   /* Call device driver's error handler, if any.  This is used on the Mac. */
   if (ctx->Driver.Error) {
      (*ctx->Driver.Error)( ctx );
   }
}



/*
 * Execute a glGetError command
 */
GLenum gl_GetError( GLcontext *ctx )
{
   GLenum e = ctx->ErrorValue;

   ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL( ctx, "glGetError", 0);

   if (MESA_VERBOSE & VERBOSE_API)
      fprintf(stderr, "glGetError <-- %s\n", gl_lookup_enum_by_nr(e));

   ctx->ErrorValue = (GLenum) GL_NO_ERROR;
   return e;
}



void gl_ResizeBuffersMESA( GLcontext *ctx )
{
   GLuint buf_width, buf_height;

   if (MESA_VERBOSE & VERBOSE_API)
      fprintf(stderr, "glResizeBuffersMESA\n");

   /* ask device driver for size of output buffer */
   (*ctx->Driver.GetBufferSize)( ctx, &buf_width, &buf_height );

   /* see if size of device driver's color buffer (window) has changed */
   if (ctx->Buffer->Width == (GLint) buf_width &&
       ctx->Buffer->Height == (GLint) buf_height)
      return;

   ctx->NewState |= NEW_RASTER_OPS;  /* to update scissor / window bounds */

   /* save buffer size */
   ctx->Buffer->Width = buf_width;
   ctx->Buffer->Height = buf_height;

   /* Reallocate other buffers if needed. */
   if (ctx->Visual->DepthBits>0) {
      /* reallocate depth buffer */
      (*ctx->Driver.AllocDepthBuffer)( ctx );
   }
   if (ctx->Visual->StencilBits>0) {
      /* reallocate stencil buffer */
      gl_alloc_stencil_buffer( ctx );
   }
   if (ctx->Visual->AccumBits>0) {
      /* reallocate accum buffer */
      gl_alloc_accum_buffer( ctx );
   }
   if (ctx->Visual->SoftwareAlpha) {
      gl_alloc_alpha_buffers( ctx );
   }
}




/**********************************************************************/
/*****                   State update logic                       *****/
/**********************************************************************/


/*
 * Since the device driver may or may not support pixel logic ops we
 * have to make some extensive tests to determine whether or not
 * software-implemented logic operations have to be used.
 */
static void update_pixel_logic( GLcontext *ctx )
{
   if (ctx->Visual->RGBAflag) {
      /* RGBA mode blending w/ Logic Op */
      if (ctx->Color.ColorLogicOpEnabled) {
	 if (ctx->Driver.LogicOp
             && (*ctx->Driver.LogicOp)( ctx, ctx->Color.LogicOp )) {
	    /* Device driver can do logic, don't have to do it in software */
	    ctx->Color.SWLogicOpEnabled = GL_FALSE;
	 }
	 else {
	    /* Device driver can't do logic op so we do it in software */
	    ctx->Color.SWLogicOpEnabled = GL_TRUE;
	 }
      }
      else {
	 /* no logic op */
	 if (ctx->Driver.LogicOp) {
            (void) (*ctx->Driver.LogicOp)( ctx, GL_COPY );
         }
	 ctx->Color.SWLogicOpEnabled = GL_FALSE;
      }
   }
   else {
      /* CI mode Logic Op */
      if (ctx->Color.IndexLogicOpEnabled) {
	 if (ctx->Driver.LogicOp
             && (*ctx->Driver.LogicOp)( ctx, ctx->Color.LogicOp )) {
	    /* Device driver can do logic, don't have to do it in software */
	    ctx->Color.SWLogicOpEnabled = GL_FALSE;
	 }
	 else {
	    /* Device driver can't do logic op so we do it in software */
	    ctx->Color.SWLogicOpEnabled = GL_TRUE;
	 }
      }
      else {
	 /* no logic op */
	 if (ctx->Driver.LogicOp) {
            (void) (*ctx->Driver.LogicOp)( ctx, GL_COPY );
         }
	 ctx->Color.SWLogicOpEnabled = GL_FALSE;
      }
   }
}



/*
 * Check if software implemented RGBA or Color Index masking is needed.
 */
static void update_pixel_masking( GLcontext *ctx )
{
   if (ctx->Visual->RGBAflag) {
      GLuint *colorMask = (GLuint *) ctx->Color.ColorMask;
      if (*colorMask == 0xffffffff) {
         /* disable masking */
         if (ctx->Driver.ColorMask) {
            (void) (*ctx->Driver.ColorMask)( ctx, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
         }
         ctx->Color.SWmasking = GL_FALSE;
      }
      else {
         /* Ask driver to do color masking, if it can't then
          * do it in software
          */
         GLboolean red   = ctx->Color.ColorMask[RCOMP] ? GL_TRUE : GL_FALSE;
         GLboolean green = ctx->Color.ColorMask[GCOMP] ? GL_TRUE : GL_FALSE;
         GLboolean blue  = ctx->Color.ColorMask[BCOMP] ? GL_TRUE : GL_FALSE;
         GLboolean alpha = ctx->Color.ColorMask[ACOMP] ? GL_TRUE : GL_FALSE;
         if (ctx->Driver.ColorMask
             && (*ctx->Driver.ColorMask)( ctx, red, green, blue, alpha )) {
            ctx->Color.SWmasking = GL_FALSE;
         }
         else {
            ctx->Color.SWmasking = GL_TRUE;
         }
      }
   }
   else {
      if (ctx->Color.IndexMask==0xffffffff) {
         /* disable masking */
         if (ctx->Driver.IndexMask) {
            (void) (*ctx->Driver.IndexMask)( ctx, 0xffffffff );
         }
         ctx->Color.SWmasking = GL_FALSE;
      }
      else {
         /* Ask driver to do index masking, if it can't then
          * do it in software
          */
         if (ctx->Driver.IndexMask
             && (*ctx->Driver.IndexMask)( ctx, ctx->Color.IndexMask )) {
            ctx->Color.SWmasking = GL_FALSE;
         }
         else {
            ctx->Color.SWmasking = GL_TRUE;
         }
      }
   }
}


static void update_fog_mode( GLcontext *ctx )
{
   if (ctx->Fog.Enabled) {
      if (ctx->Texture.Enabled)
         ctx->FogMode = FOG_FRAGMENT;
      else if (ctx->Hint.Fog == GL_NICEST)
         ctx->FogMode = FOG_FRAGMENT;
      else
         ctx->FogMode = FOG_VERTEX;

      if (ctx->Driver.GetParameteri)
         if ((ctx->Driver.GetParameteri)( ctx, DD_HAVE_HARDWARE_FOG ))
            ctx->FogMode = FOG_FRAGMENT;
   }
   else {
      ctx->FogMode = FOG_NONE;
   }
}


/*
 * Recompute the value of ctx->RasterMask, etc. according to
 * the current context.
 */
static void update_rasterflags( GLcontext *ctx )
{
   ctx->RasterMask = 0;

   if (ctx->Color.AlphaEnabled)		ctx->RasterMask |= ALPHATEST_BIT;
   if (ctx->Color.BlendEnabled)		ctx->RasterMask |= BLEND_BIT;
   if (ctx->Depth.Test)			ctx->RasterMask |= DEPTH_BIT;
   if (ctx->FogMode==FOG_FRAGMENT)	ctx->RasterMask |= FOG_BIT;
   if (ctx->Color.SWLogicOpEnabled)	ctx->RasterMask |= LOGIC_OP_BIT;
   if (ctx->Scissor.Enabled)		ctx->RasterMask |= SCISSOR_BIT;
   if (ctx->Stencil.Enabled)		ctx->RasterMask |= STENCIL_BIT;
   if (ctx->Color.SWmasking)		ctx->RasterMask |= MASKING_BIT;

   if (ctx->Visual->SoftwareAlpha && ctx->Color.ColorMask[ACOMP]
       && ctx->Color.DrawBuffer != GL_NONE)
      ctx->RasterMask |= ALPHABUF_BIT;

   if (   ctx->Viewport.X<0
       || ctx->Viewport.X + ctx->Viewport.Width > ctx->Buffer->Width
       || ctx->Viewport.Y<0
       || ctx->Viewport.Y + ctx->Viewport.Height > ctx->Buffer->Height) {
      ctx->RasterMask |= WINCLIP_BIT;
   }

   /* If we're not drawing to exactly one color buffer set the
    * MULTI_DRAW_BIT flag.  Also set it if we're drawing to no
    * buffers or the RGBA or CI mask disables all writes.
    */

   ctx->TriangleCaps &= ~DD_MULTIDRAW;

   if (ctx->Color.MultiDrawBuffer) {
      ctx->RasterMask |= MULTI_DRAW_BIT;
      ctx->TriangleCaps |= DD_MULTIDRAW;
   }
   else if (ctx->Color.DrawBuffer==GL_NONE) {
      ctx->RasterMask |= MULTI_DRAW_BIT;
      ctx->TriangleCaps |= DD_MULTIDRAW;
   }
   else if (ctx->Visual->RGBAflag && ctx->Color.ColorMask==0) {
      /* all RGBA channels disabled */
      ctx->RasterMask |= MULTI_DRAW_BIT;
      ctx->TriangleCaps |= DD_MULTIDRAW;
      ctx->Color.DrawDestMask = 0;
   }
   else if (!ctx->Visual->RGBAflag && ctx->Color.IndexMask==0) {
      /* all color index bits disabled */
      ctx->RasterMask |= MULTI_DRAW_BIT;
      ctx->TriangleCaps |= DD_MULTIDRAW;
      ctx->Color.DrawDestMask = 0;
   }
}


void gl_print_state( const char *msg, GLuint state )
{
   fprintf(stderr,
	   "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
	   msg,
	   state,
	   (state & NEW_LIGHTING)         ? "lighting, " : "",
	   (state & NEW_RASTER_OPS)       ? "raster-ops, " : "",
	   (state & NEW_TEXTURING)        ? "texturing, " : "",
	   (state & NEW_POLYGON)          ? "polygon, " : "",
	   (state & NEW_DRVSTATE0)        ? "driver-0, " : "",
	   (state & NEW_DRVSTATE1)        ? "driver-1, " : "",
	   (state & NEW_DRVSTATE2)        ? "driver-2, " : "",
	   (state & NEW_DRVSTATE3)        ? "driver-3, " : "",
	   (state & NEW_MODELVIEW)        ? "modelview, " : "",
	   (state & NEW_PROJECTION)       ? "projection, " : "",
	   (state & NEW_TEXTURE_MATRIX)   ? "texture-matrix, " : "",
	   (state & NEW_USER_CLIP)        ? "user-clip, " : "",
	   (state & NEW_TEXTURE_ENV)      ? "texture-env, " : "",
	   (state & NEW_CLIENT_STATE)     ? "client-state, " : "",
	   (state & NEW_FOG)              ? "fog, " : "",
	   (state & NEW_NORMAL_TRANSFORM) ? "normal-transform, " : "",
	   (state & NEW_VIEWPORT)         ? "viewport, " : "",
	   (state & NEW_TEXTURE_ENABLE)   ? "texture-enable, " : "");
}

void gl_print_enable_flags( const char *msg, GLuint flags )
{
   fprintf(stderr,
	   "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s\n",
	   msg,
	   flags,
	   (flags & ENABLE_TEX0)       ? "tex-0, " : "",
	   (flags & ENABLE_TEX1)       ? "tex-1, " : "",
	   (flags & ENABLE_LIGHT)      ? "light, " : "",
	   (flags & ENABLE_FOG)        ? "fog, " : "",
	   (flags & ENABLE_USERCLIP)   ? "userclip, " : "",
	   (flags & ENABLE_TEXGEN0)    ? "tex-gen-0, " : "",
	   (flags & ENABLE_TEXGEN1)    ? "tex-gen-1, " : "",
	   (flags & ENABLE_TEXMAT0)    ? "tex-mat-0, " : "",
	   (flags & ENABLE_TEXMAT1)    ? "tex-mat-1, " : "",
	   (flags & ENABLE_NORMALIZE)  ? "normalize, " : "",
	   (flags & ENABLE_RESCALE)    ? "rescale, " : "");
}


/*
 * If ctx->NewState is non-zero then this function MUST be called before
 * rendering any primitive.  Basically, function pointers and miscellaneous
 * flags are updated to reflect the current state of the state machine.
 */
void gl_update_state( GLcontext *ctx )
{
   GLuint i;

   if (MESA_VERBOSE & VERBOSE_STATE)
      gl_print_state("", ctx->NewState);

   if (ctx->NewState & NEW_CLIENT_STATE)
      gl_update_client_state( ctx );

   if ((ctx->NewState & NEW_TEXTURE_ENABLE) &&
       (ctx->Enabled & ENABLE_TEX_ANY) != ctx->Texture.Enabled)
      ctx->NewState |= NEW_TEXTURING | NEW_RASTER_OPS;

   if (ctx->NewState & NEW_TEXTURE_ENV) {
      if (ctx->Texture.Unit[0].EnvMode == ctx->Texture.Unit[0].LastEnvMode &&
	  ctx->Texture.Unit[1].EnvMode == ctx->Texture.Unit[1].LastEnvMode)
	 ctx->NewState &= ~NEW_TEXTURE_ENV;
      ctx->Texture.Unit[0].LastEnvMode = ctx->Texture.Unit[0].EnvMode;
      ctx->Texture.Unit[1].LastEnvMode = ctx->Texture.Unit[1].EnvMode;
   }

   if ((ctx->NewState & ~(NEW_CLIENT_STATE|NEW_TEXTURE_ENABLE)) == 0)
      goto finished;

   if (ctx->NewState & NEW_TEXTURE_MATRIX) {
      ctx->Enabled &= ~(ENABLE_TEXMAT0|ENABLE_TEXMAT1);

      for (i=0; i < MAX_TEXTURE_UNITS; i++) {
	 if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER)
	 {
	    gl_matrix_analyze( &ctx->TextureMatrix[i] );
	    ctx->TextureMatrix[i].flags &= ~MAT_DIRTY_DEPENDENTS;

	    if (ctx->Texture.Unit[i].Enabled &&
		ctx->TextureMatrix[i].type != MATRIX_IDENTITY)
	       ctx->Enabled |= ENABLE_TEXMAT0 << i;
	 }
      }
   }

   if (ctx->NewState & NEW_TEXTURING) {
      ctx->Texture.NeedNormals = GL_FALSE;
      gl_update_dirty_texobjs(ctx);
      ctx->Enabled &= ~(ENABLE_TEXGEN0|ENABLE_TEXGEN1);
      ctx->Texture.ReallyEnabled = 0;

      for (i=0; i < MAX_TEXTURE_UNITS; i++) {
	 if (ctx->Texture.Unit[i].Enabled) {
	    gl_update_texture_unit( ctx, &ctx->Texture.Unit[i] );

	    ctx->Texture.ReallyEnabled |=
	       ctx->Texture.Unit[i].ReallyEnabled<<(i*4);

	    if (ctx->Texture.Unit[i].GenFlags != 0) {
	       ctx->Enabled |= ENABLE_TEXGEN0 << i;

	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_NORMALS)
	       {
		  ctx->Texture.NeedNormals = GL_TRUE;
		  ctx->Texture.NeedEyeCoords = GL_TRUE;
	       }

	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_EYE_COORD)
	       {
		  ctx->Texture.NeedEyeCoords = GL_TRUE;
	       }
	    }
	 }
      }

      ctx->Texture.Enabled = ctx->Enabled & ENABLE_TEX_ANY;
      ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
   }

   if (ctx->NewState & (NEW_RASTER_OPS | NEW_LIGHTING)) {
      if (ctx->NewState & NEW_RASTER_OPS) {
	 update_pixel_logic(ctx);
	 update_pixel_masking(ctx);
	 update_fog_mode(ctx);
	 update_rasterflags(ctx);
	 if (ctx->Driver.Dither) {
	    (*ctx->Driver.Dither)( ctx, ctx->Color.DitherFlag );
	 }

	 /* Check if incoming colors can be modified during rasterization */
	 if (ctx->Fog.Enabled ||
	     ctx->Texture.Enabled ||
	     ctx->Color.BlendEnabled ||
	     ctx->Color.SWmasking ||
	     ctx->Color.SWLogicOpEnabled) {
	    ctx->MutablePixels = GL_TRUE;
	 }
	 else {
	    ctx->MutablePixels = GL_FALSE;
	 }

	 /* update scissor region */

	 ctx->Buffer->Xmin = 0;
	 ctx->Buffer->Ymin = 0;
	 ctx->Buffer->Xmax = ctx->Buffer->Width-1;
	 ctx->Buffer->Ymax = ctx->Buffer->Height-1;
	 if (ctx->Scissor.Enabled) {
	    if (ctx->Scissor.X > ctx->Buffer->Xmin) {
	       ctx->Buffer->Xmin = ctx->Scissor.X;
	    }
	    if (ctx->Scissor.Y > ctx->Buffer->Ymin) {
	       ctx->Buffer->Ymin = ctx->Scissor.Y;
	    }
	    if (ctx->Scissor.X + ctx->Scissor.Width - 1 < ctx->Buffer->Xmax) {
	       ctx->Buffer->Xmax = ctx->Scissor.X + ctx->Scissor.Width - 1;
	    }
	    if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < ctx->Buffer->Ymax) {
	       ctx->Buffer->Ymax = ctx->Scissor.Y + ctx->Scissor.Height - 1;
	    }
	 }

	 /*
	  * Update Device Driver interface
	  */
	 ctx->Driver.AllocDepthBuffer = gl_alloc_depth_buffer;
	 if (ctx->Depth.Mask) {
	    switch (ctx->Depth.Func) {
	    case GL_LESS:
	       ctx->Driver.DepthTestSpan = gl_depth_test_span_less;
	       ctx->Driver.DepthTestPixels = gl_depth_test_pixels_less;
	       break;
	    case GL_GREATER:
	       ctx->Driver.DepthTestSpan = gl_depth_test_span_greater;
	       ctx->Driver.DepthTestPixels = gl_depth_test_pixels_greater;
	       break;
	    default:
	       ctx->Driver.DepthTestSpan = gl_depth_test_span_generic;
	       ctx->Driver.DepthTestPixels = gl_depth_test_pixels_generic;
	    }
	 }
	 else {
	    ctx->Driver.DepthTestSpan = gl_depth_test_span_generic;
	    ctx->Driver.DepthTestPixels = gl_depth_test_pixels_generic;
	 }
	 ctx->Driver.ReadDepthSpanFloat = gl_read_depth_span_float;
	 ctx->Driver.ReadDepthSpanInt = gl_read_depth_span_int;
      }

      if (ctx->NewState & NEW_LIGHTING) {
	 ctx->TriangleCaps &= ~(DD_TRI_LIGHT_TWOSIDE|DD_EARLY_CULL);
	 if (ctx->Light.Enabled) {
	    if (ctx->Light.Model.TwoSide)
	       ctx->TriangleCaps |= (DD_TRI_LIGHT_TWOSIDE|DD_EARLY_CULL);
	    gl_update_lighting(ctx);
	 }
      }
   }

   if (ctx->NewState & (NEW_POLYGON | NEW_LIGHTING)) {


      if (ctx->NewState & NEW_POLYGON) {
	 /* Setup CullBits bitmask */
	 if (ctx->Polygon.CullFlag) {
	    switch(ctx->Polygon.CullFaceMode) {
	    case GL_FRONT:
	       ctx->Polygon.CullBits = 2;
	       break;
	    case GL_BACK:
	       ctx->Polygon.CullBits = 1;
	       break;
	    default:
	    case GL_FRONT_AND_BACK:
	       ctx->Polygon.CullBits = 3;
	       break;
	    }
	 }
	 else
	    ctx->Polygon.CullBits = 3;

	 /* Any Polygon offsets enabled? */
	 ctx->TriangleCaps &= ~DD_TRI_OFFSET;

	 if (ctx->Polygon.OffsetPoint ||
	     ctx->Polygon.OffsetLine ||
	     ctx->Polygon.OffsetFill)
	    ctx->TriangleCaps |= DD_TRI_OFFSET;

	 /* reset Z offsets now */
	 ctx->PointZoffset   = 0.0;
	 ctx->LineZoffset    = 0.0;
	 ctx->PolygonZoffset = 0.0;
      }
   }

   if (ctx->NewState & ~(NEW_CLIENT_STATE|NEW_TEXTURE_ENABLE|
			 NEW_DRIVER_STATE|NEW_USER_CLIP|
			 NEW_POLYGON))
      gl_update_clipmask(ctx);

   if (ctx->NewState & (NEW_LIGHTING|
			NEW_RASTER_OPS|
			NEW_TEXTURING|
			NEW_TEXTURE_ENV|
			NEW_POLYGON|
			NEW_DRVSTATE0|
			NEW_DRVSTATE1|
			NEW_DRVSTATE2|
			NEW_DRVSTATE3|
			NEW_USER_CLIP))
   {
      ctx->IndirectTriangles = ctx->TriangleCaps & ~ctx->Driver.TriangleCaps;
      ctx->IndirectTriangles |= DD_SW_RASTERIZE;

      ctx->Driver.PointsFunc = NULL;
      ctx->Driver.LineFunc = NULL;
      ctx->Driver.TriangleFunc = NULL;
      ctx->Driver.QuadFunc = NULL;
      ctx->Driver.RectFunc = NULL;
      ctx->Driver.RenderVBClippedTab = NULL;
      ctx->Driver.RenderVBCulledTab = NULL;
      ctx->Driver.RenderVBRawTab = NULL;

      /*
       * Here the driver sets up all the ctx->Driver function pointers to
       * it's specific, private functions.
       */
      ctx->Driver.UpdateState(ctx);

      /*
       * In case the driver didn't hook in an optimized point, line or
       * triangle function we'll now select "core/fallback" point, line
       * and triangle functions.
       */
      if (ctx->IndirectTriangles & DD_SW_RASTERIZE) {
	 gl_set_point_function(ctx);
	 gl_set_line_function(ctx);
	 gl_set_triangle_function(ctx);
	 gl_set_quad_function(ctx);
      }

      gl_set_render_vb_function(ctx);
   }

   /* Should only be calc'd when !need_eye_coords and not culling.
    */
   if (ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION)) {
      if (ctx->NewState & NEW_MODELVIEW) {
	 gl_matrix_analyze( &ctx->ModelView );
	 ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;
      }

      if (ctx->NewState & NEW_PROJECTION) {
	 gl_matrix_analyze( &ctx->ProjectionMatrix );
	 ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;

	 if (ctx->Transform.AnyClip) {
	    gl_update_userclip( ctx );
	 }
      }

      gl_calculate_model_project_matrix( ctx );
      ctx->ModelProjectWinMatrixUptodate = 0;
   }

   /* Figure out whether we can light in object space or not.  If we
    * can, find the current positions of the lights in object space
    */
   if ((ctx->Enabled & (ENABLE_POINT_ATTEN | ENABLE_LIGHT | 
			ENABLE_TEXGEN0 | ENABLE_TEXGEN1)) &&
       (ctx->NewState & (NEW_LIGHTING | 
			 NEW_MODELVIEW | 
			 NEW_PROJECTION |
			 NEW_TEXTURING |
			 NEW_RASTER_OPS |
			 NEW_USER_CLIP)))
   {
      GLboolean oldcoord, oldnorm;

      oldcoord = ctx->NeedEyeCoords;
      oldnorm = ctx->NeedEyeNormals;

      ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
      ctx->NeedEyeCoords = ((ctx->Fog.Enabled && ctx->Hint.Fog != GL_NICEST) ||
			    ctx->Point.Attenuated);
      ctx->NeedEyeNormals = GL_FALSE;

      if (ctx->Light.Enabled) {
	 if (ctx->Light.Flags & LIGHT_POSITIONAL) {
	    /* Need length for attenuation */
	    if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING))
	       ctx->NeedEyeCoords = GL_TRUE;
	 } else if (ctx->Light.NeedVertices) {
	    /* Need angle for spot calculations */
	    if (!TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_ANGLE_PRESERVING))
	       ctx->NeedEyeCoords = GL_TRUE;
	 }
	 ctx->NeedEyeNormals = ctx->NeedEyeCoords;
      }
      if (ctx->Texture.Enabled || ctx->RenderMode==GL_FEEDBACK) {
	 if (ctx->Texture.NeedEyeCoords) ctx->NeedEyeCoords = GL_TRUE;
	 if (ctx->Texture.NeedNormals)
	    ctx->NeedNormals = ctx->NeedEyeNormals = GL_TRUE;
      }

      ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;

      if (ctx->NeedEyeCoords)
	 ctx->vb_proj_matrix = &ctx->ProjectionMatrix;

      if (ctx->Light.Enabled) {
	 gl_update_lighting_function(ctx);

	 if ( (ctx->NewState & NEW_LIGHTING) ||
	      ((ctx->NewState & (NEW_MODELVIEW| NEW_PROJECTION)) &&
	       !ctx->NeedEyeCoords) ||
	      oldcoord != ctx->NeedEyeCoords ||
	      oldnorm != ctx->NeedEyeNormals) {
	    gl_compute_light_positions(ctx);
	 }

	 ctx->rescale_factor = 1.0F;

	 if (ctx->ModelView.flags & (MAT_FLAG_UNIFORM_SCALE |
				     MAT_FLAG_GENERAL_SCALE |
				     MAT_FLAG_GENERAL_3D |
				     MAT_FLAG_GENERAL) )

	 {
	    GLfloat *m = ctx->ModelView.inv;
	    GLfloat f = m[2]*m[2] + m[6]*m[6] + m[10]*m[10];
	    if (f > 1e-12 && (f-1)*(f-1) > 1e-12)
	       ctx->rescale_factor = 1.0/GL_SQRT(f);
	 }
      }

      gl_update_normal_transform( ctx );
   }

 finished:
   gl_update_pipelines(ctx);
   ctx->NewState = 0;
}
@


3.64
log
@minor change to glGetError()
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.63 1999/07/31 23:59:01 brianp Exp $ */
d1732 1
a1732 2
/*       fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s ); */
      printf("Mesa user error: %s in %s\n", errstr, s ); fflush(stdout);
d1754 1
a1754 8
   /* special case- flush VB after checking if inside begin/end */

   if (ctx->Current.Primitive != GL_POLYGON+1) {
      gl_error( ctx, GL_INVALID_OPERATION, "glGetError" );
      return (GLenum) 0;
   }

   FLUSH_VB( ctx, "glGetError" );
@


3.63
log
@bug fix: scissor region wasn't updated upon window resize
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.62 1999/07/31 19:15:18 miklos Exp $ */
d70 1
d72 1
a72 1
#include "simple_list.h"
d282 3
d286 1
a286 1
/*****           One-time initializations                         *****/
d290 3
a315 6

/**********************************************************************/
/*****       Context allocation, initialization, destroying       *****/
/**********************************************************************/


d1748 3
a1750 1

d1755 9
a1763 1
   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glGetError", (GLenum) 0);
@


3.62
log
@added vb_init_xform code.
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.61 1999/07/30 18:48:01 brianp Exp $ */
d1777 1
a1777 1
/*        ctx->NewState |= NEW_BUFFERS_SIZE; */
@


3.61
log
@optimized glAccum for common cases
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.60 1999/07/16 03:33:15 tjump Exp $ */
d300 1
@


3.60
log
@Revived previous code for texstate.c/h, get.c, enable.c, updated Win32 project files
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.59 1999/07/15 20:24:51 keithw Exp $ */
d998 4
@


3.59
log
@fix for points attenuation
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.58 1999/07/15 12:35:26 tjump Exp $ */
d2084 1
a2084 1
      gl_update_texture_state(ctx);
@


3.58
log
@more Win32 build cleanups
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.56 1999/07/14 21:08:36 brianp Exp $ */
a2300 3

/*        if (!(ctx->Enabled & (ENABLE_LIGHT | ENABLE_TEXGEN0 | ENABLE_TEXGEN1))) */
/*  	 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix; */
d2306 4
a2309 3
   if ((ctx->Enabled & (ENABLE_LIGHT | ENABLE_TEXGEN0 | ENABLE_TEXGEN1)) &&
       (ctx->NewState & (NEW_LIGHTING |
			 NEW_MODELVIEW |
@


3.57
log
@renamed gl_update_state() to gl_update_dirty_texobjs()
@
text
@d6 1
a6 1
 * 
d8 1
a8 1
 * 
d15 1
a15 1
 * 
d18 1
a18 1
 * 
d400 3
d529 1
a529 1
   cl->Enabled = 1;   
d752 1
a752 1
      
d757 1
a757 1
      
d781 2
a782 2
         = gl_material_bitmask( ctx, 
				GL_FRONT_AND_BACK, 
d919 1
a919 1
      ctx->Viewport.Height = 0;   
d1317 1
d1352 1
a1352 1
      }      
a1663 4
/*
 * When an error is detected during display list compilation we call
 * this function to process it.
 */
d1666 1
a1666 1
   if (ctx->CompileFlag) 
d1668 1
a1668 1
   
a1673 1

d1992 1
a1992 1
   fprintf(stderr, 
d2008 2
a2009 2
	   (state & NEW_TEXTURE_ENV)      ? "texture-env, " : "", 
	   (state & NEW_CLIENT_STATE)     ? "client-state, " : "", 
d2013 1
a2013 1
	   (state & NEW_TEXTURE_ENABLE)   ? "texture-enable, " : "");   
d2018 1
a2018 1
   fprintf(stderr, 
d2052 1
a2052 1
       (ctx->Enabled & ENABLE_TEX_ANY) != ctx->Texture.Enabled) 
d2063 1
a2063 1
   if ((ctx->NewState & ~(NEW_CLIENT_STATE|NEW_TEXTURE_ENABLE)) == 0) 
d2070 2
a2071 1
	 if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER) {
d2075 1
a2075 1
	    if (ctx->Texture.Unit[i].Enabled && 
d2084 1
a2084 1
      gl_update_dirty_texobjs(ctx);
d2090 1
a2090 1
	    gl_update_texture_unit( ctx, &ctx->Texture.Unit[i] );	    
d2092 1
a2092 1
	    ctx->Texture.ReallyEnabled |= 
d2094 1
a2094 1
	    	    
d2097 3
a2099 2
	    	    
	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_NORMALS) {
d2103 3
a2105 2
 
	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_EYE_COORD) {
d2107 3
a2109 3
	       }	   
	    } 
	 }	 
d2111 1
a2111 1
      
d2158 1
a2158 1
	 
d2189 1
a2189 1
	    if (ctx->Light.Model.TwoSide) 
d2198 1
d2217 1
a2217 1
	 
d2249 1
a2249 1
      ctx->IndirectTriangles = ctx->TriangleCaps & ~ctx->Driver.TriangleCaps;  
d2251 1
a2251 1
      
d2293 1
a2293 1
	 
d2307 1
a2307 1
    * can, find the current positions of the lights in object space 
d2310 2
a2311 2
       (ctx->NewState & (NEW_LIGHTING | 
			 NEW_MODELVIEW | 
d2313 1
a2313 1
			 NEW_TEXTURING | 
d2322 1
a2322 1
      ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals); 
d2326 1
a2326 1
      
d2336 1
a2336 1
	 } 
d2340 2
a2341 2
	 if (ctx->Texture.NeedEyeCoords) ctx->NeedEyeCoords = GL_TRUE;	 
	 if (ctx->Texture.NeedNormals) 
d2347 1
a2347 1
      if (ctx->NeedEyeCoords) 
d2352 1
a2352 1
	 
d2356 1
a2356 1
	      oldcoord != ctx->NeedEyeCoords || 
d2361 1
a2361 1
	 ctx->rescale_factor = 1.0F;	 
d2363 1
a2363 1
	 if (ctx->ModelView.flags & (MAT_FLAG_UNIFORM_SCALE | 
d2366 2
a2367 2
				     MAT_FLAG_GENERAL) ) 
	       
d2371 1
a2371 1
	    if (f > 1e-12 && (f-1)*(f-1) > 1e-12) 
d2379 1
a2379 1
 finished:   
d2381 1
a2381 1
   ctx->NewState = 0; 
a2382 1

@


3.56
log
@changed print string in gl_problem()
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.55 1999/07/14 01:28:25 brianp Exp $ */
a399 3



a1313 1

d1660 4
d1674 1
d2071 1
a2071 2
	 if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER) 
	 {
d2084 1
a2084 1
      gl_update_texture_state(ctx);
d2098 1
a2098 2
	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_NORMALS) 
	       {
d2103 1
a2103 2
	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_EYE_COORD)
	       {
a2195 1
   
@


3.55
log
@print DEBUG build date and time
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.54 1999/07/12 12:05:23 keithw Exp $ */
d1632 1
a1632 1
   fprintf( stderr, "Report to Mesa author.\n" );
@


3.54
log
@merge from experimental branch upto merge-1 tag
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.53 1999/07/06 01:09:35 brianp Exp $ */
d302 3
a2114 1

@


3.53
log
@don't call SET_IMMEDIATE() in gl_create_context
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.52 1999/06/25 01:51:24 brianp Exp $ */
d55 1
d331 8
a338 6
      ss->Default1D[i] = gl_alloc_texture_object(ss, 0, 1);
      ss->Default2D[i] = gl_alloc_texture_object(ss, 0, 2);
      ss->Default3D[i] = gl_alloc_texture_object(ss, 0, 3);
      if (!ss->Default1D[i] || !ss->Default2D[i] || !ss->Default3D[i]) {
         outOfMemory = GL_TRUE;
         break;
d349 6
a354 6
         if (ss->Default1D[i])
            gl_free_texture_object(ss, ss->Default1D[i]);
         if (ss->Default2D[i])
            gl_free_texture_object(ss, ss->Default2D[i]);
         if (ss->Default3D[i])
            gl_free_texture_object(ss, ss->Default3D[i]);
d475 3
a477 3
   texUnit->Current1D = ctx->Shared->Default1D[unit];
   texUnit->Current2D = ctx->Shared->Default2D[unit];
   texUnit->Current3D = ctx->Shared->Default3D[unit];
d481 48
a651 1
      ctx->Current.TexSet = 0;
d665 3
a667 1
			   VERT_TEX0_1|VERT_TEX1_1);
d757 1
d762 2
a862 1
      ctx->Polygon.OffsetAny = GL_FALSE;
d1012 1
d1476 1
a1476 1
      ASSERT_OUTSIDE_BEGIN_END(CC, "gl_make_current");
d1493 2
d1742 1
a1742 1
   GLenum e;
d1745 2
a1747 1
   e = ctx->ErrorValue;
a1755 1
   GLint newsize;
a1756 2
   
   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glResizeBuffersMESA");
d1758 2
a1759 1
   ctx->NewState |= NEW_ALL;   /* just to be safe */
d1765 5
a1769 2
   newsize = ctx->Buffer->Width != (GLint) buf_width
          || ctx->Buffer->Height != (GLint) buf_height;
d1776 1
a1776 1
   if (newsize && ctx->Visual->DepthBits>0) {
d1780 1
a1780 1
   if (newsize && ctx->Visual->StencilBits>0) {
d1784 1
a1784 1
   if (newsize && ctx->Visual->AccumBits>0) {
d1788 1
a1788 1
   if (newsize && ctx->Visual->SoftwareAlpha) {
d1961 3
d1966 1
d1970 1
d1975 1
d1981 1
d1987 1
a1987 5
/*
 * Recompute the value of ctx->ClipMask according to the current context.
 * ClipMask depends on Texturing and Lighting.
 */
static void update_clipmask(GLcontext *ctx)
d1989 41
a2029 43
   /* Recompute ClipMask (what has to be interpolated when clipping) */
   ctx->ClipMask = 0;
   if (ctx->Texture.ReallyEnabled) {
      ctx->ClipMask |= CLIP_TEXTURE_BIT;
   }
   if (ctx->Light.ShadeModel==GL_SMOOTH) {
      if (ctx->Visual->RGBAflag) {
	 ctx->ClipMask |= CLIP_FCOLOR_BIT;
	 if (ctx->LightTwoSide) {
	    ctx->ClipMask |= CLIP_BCOLOR_BIT;
	 }
      }
      else {
	 ctx->ClipMask |= CLIP_FINDEX_BIT;
	 if (ctx->LightTwoSide) {
	    ctx->ClipMask |= CLIP_BINDEX_BIT;
	 }
      }
   }
 
   if (ctx->Texture.ReallyEnabled >= TEXTURE1_1D) {
      /* Multi texture coords */
      ctx->ClipInterpFunc = gl_clip_interp_all;
   }
   else {
      switch(ctx->ClipMask) {
         case CLIP_FCOLOR_BIT | CLIP_TEXTURE_BIT:
            ctx->ClipInterpFunc = gl_clip_interp_color_tex;
            break;
         case CLIP_TEXTURE_BIT:
            ctx->ClipInterpFunc = gl_clip_interp_color_tex;
            /*            ctx->ClipInterpFunc = gl_clip_interp_tex;*/
            break;
         case CLIP_FCOLOR_BIT:
            ctx->ClipInterpFunc = gl_clip_interp_color;
            break;
         case 0:
            ctx->ClipInterpFunc = gl_clip_interp_none;
            break;
         default:
            ctx->ClipInterpFunc = gl_clip_interp_all;
      }
   }
a2032 1

d2041 3
a2043 3
   
/*     static int counter; */
/*     extern void fxsignals(); */
d2048 14
a2061 3
/*     if ((++counter & 0xff) == 0) */
/*        fxsignals(); */
   
d2063 2
a2064 5
   if (ctx->NewState & (NEW_TEXTURING|NEW_TEXTURE_MATRIX)) {
      ctx->Texture.NeedNormals = GL_FALSE;
      gl_update_texture_state(ctx);
      ctx->Texture.Enabled = 0;
      ctx->Texture.ReallyEnabled = 0;
d2067 2
a2068 1
	 if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER) {
d2071 4
d2076 2
a2077 3
	    
	 ctx->Texture.Unit[i].AnyTransform = 0;
	    
d2079 7
d2087 1
a2087 5

	    if (ctx->NewState & NEW_TEXTURING)
	       gl_update_texture_unit( ctx, &ctx->Texture.Unit[i] );

	    ctx->Texture.Enabled |= ctx->Texture.Unit[i].Enabled<<(i*4);
d2091 14
a2104 9
	    
	    ctx->Texture.Unit[i].AnyTransform = (
	       ctx->TextureMatrix[i].type != MATRIX_IDENTITY ||
	       ctx->Texture.Unit[i].GenFlags != 0);
	    
	    if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_NORMALS) 
	    {
	       ctx->Texture.NeedNormals = GL_TRUE;
	       ctx->Texture.NeedEyeCoords = GL_TRUE;
a2105 4
	    else if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_EYE_COORD)
	    {
	       ctx->Texture.NeedEyeCoords = GL_TRUE;
	    }	    
d2108 3
a2110 3

      ctx->NeedNormals = (ctx->Light.Enabled || 
			  ctx->Texture.NeedNormals);
d2185 6
a2190 2
	 ctx->LightTwoSide = ctx->Light.Enabled && ctx->Light.Model.TwoSide;
	 if (ctx->Light.Enabled) gl_update_lighting(ctx);
a2191 1

a2192 1
      update_clipmask(ctx);
d2217 7
a2223 3
	 ctx->Polygon.OffsetAny = (ctx->Polygon.OffsetPoint ||
				   ctx->Polygon.OffsetLine ||
				   ctx->Polygon.OffsetFill);
a2228 12
   
      ctx->NeedCull = (ctx->LightTwoSide || ctx->Polygon.CullBits != 3);

      /* Determine if we can directly call the triangle rasterizer */
      ctx->IndirectTriangles = 0;
      
      if (ctx->Polygon.Unfilled)  ctx->IndirectTriangles |= DD_TRI_UNFILLED;
      if (ctx->Polygon.OffsetAny) ctx->IndirectTriangles |= DD_TRI_OFFSET;
      if (ctx->Polygon.CullFlag)  ctx->IndirectTriangles |= DD_TRI_CULL;
      if (ctx->LightTwoSide)      ctx->IndirectTriangles |= DD_TRI_LIGHT_TWOSIDE;

      ctx->IndirectTriangles &= ~ctx->Driver.TriangleCaps;
d2231 4
d2239 1
d2245 1
a2245 2
			NEW_USER_CLIP|
			NEW_FRONT_FACE))
d2247 3
d2255 1
a2255 1

a2259 6
       * The ctx->Driver.UpdateState pointer _MUST_ be valid at this point
       * in order for any impending rendering to succeed.
       */
      assert(ctx->Driver.UpdateState);

      /*
d2263 1
a2263 1
      (*ctx->Driver.UpdateState)(ctx);
d2270 7
a2276 4
      gl_set_point_function(ctx);
      gl_set_line_function(ctx);
      gl_set_triangle_function(ctx);
      gl_set_quad_function(ctx);
d2280 1
a2280 2
   /* Figure out whether we can light in object space or not.  If we
    * can, find the current positions of the lights in object space 
d2282 1
a2282 9
   if (ctx->NewState & (NEW_LIGHTING | 
			NEW_MODELVIEW | 
			NEW_PROJECTION |
			NEW_TEXTURING | 
			NEW_RASTER_OPS |
			NEW_USER_CLIP))
   {
      GLboolean oldcoord, oldnorm;

d2291 1
a2291 1

d2297 20
d2338 1
a2338 1
	 if (ctx->Texture.NeedEyeCoords) ctx->NeedEyeCoords = GL_TRUE;
d2343 1
a2343 6
      /* Should only be calc'd when !need_eye_coords and not culling.
       */
      if (ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION)) {
	 gl_calculate_model_project_matrix( ctx );
	 ctx->ModelProjectWinMatrixUptodate = 0;
      }
d2345 1
a2345 1
      if (ctx->NeedEyeCoords) {
a2346 3
      } else {
	 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
      }
a2375 3
   
   if (1)
      gl_update_pipelines(ctx);
d2377 2
@


3.52
log
@implemented linked list for dirty texture objects
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.51 1999/06/18 20:04:35 brianp Exp $ */
d1170 1
a1170 1
   SET_IMMEDIATE(ctx, ctx->VB->IM);
@


3.51
log
@minor changes for THREADS mode
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.50 1999/06/18 14:22:02 brianp Exp $ */
a835 1
      ctx->Texture.AnyDirty = GL_FALSE;
@


3.50
log
@no real change - cvs commit test
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.49 1999/06/11 01:49:55 brianp Exp $ */
d1417 2
@


3.49
log
@removed DirectContext variable
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.48 1999/06/07 14:04:50 brianp Exp $ */
d37 1
d1700 2
@


3.48
log
@test for NULL ctx in gl_make_current()
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.47 1999/06/02 12:55:35 keithw Exp $ */
d1143 2
a1213 3


   ctx->DirectContext = direct;
@


3.47
log
@multiple window bug fix
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.46 1999/05/26 15:22:00 keithw Exp $ */
d1432 3
a1434 1
   SET_IMMEDIATE(ctx, ctx->input);
@


3.46
log
@bugfix for light + scale + dlists
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.45 1999/05/18 00:12:05 keithw Exp $ */
d1347 1
d1417 6
d1432 1
@


3.45
log
@texture clipping bugfix
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.44 1999/05/11 17:43:00 keithw Exp $ */
d2272 5
a2276 2
	 if (!ctx->Transform.Normalize &&
	     (!ctx->NeedEyeNormals == !ctx->Transform.RescaleNormals))
d2278 4
a2281 11
	    if (ctx->ModelView.flags & (MAT_FLAG_UNIFORM_SCALE | 
					MAT_FLAG_GENERAL_SCALE |
					MAT_FLAG_GENERAL_3D |
					MAT_FLAG_GENERAL) ) 
	       
	    {
	       GLfloat *m = ctx->ModelView.inv;
	       GLfloat f = m[2]*m[2] + m[6]*m[6] + m[10]*m[10];
	       if (f > 1e-12 && (f-1)*(f-1) > 1e-12) 
		  ctx->rescale_factor = 1.0/GL_SQRT(f);
	    }
@


3.45.2.1
log
@Quake3 inspired optimizations
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.45 1999/05/18 00:12:05 keithw Exp $ */
a476 48
static void init_fallback_arrays( GLcontext *ctx )
{
   struct gl_client_array *cl;
   GLuint i;

   cl = &ctx->Fallback.Normal;
   cl->Size = 3;
   cl->Type = GL_FLOAT;
   cl->Stride = 0;
   cl->StrideB = 0;
   cl->Ptr = (void *) ctx->Current.Normal;
   cl->Enabled = 1;

   cl = &ctx->Fallback.Color;
   cl->Size = 4;
   cl->Type = GL_UNSIGNED_BYTE;
   cl->Stride = 0;
   cl->StrideB = 0;
   cl->Ptr = (void *) ctx->Current.ByteColor;
   cl->Enabled = 1;

   cl = &ctx->Fallback.Index;
   cl->Size = 1;
   cl->Type = GL_UNSIGNED_INT;
   cl->Stride = 0;
   cl->StrideB = 0;
   cl->Ptr = (void *) &ctx->Current.Index;
   cl->Enabled = 1;

   for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) {
      cl = &ctx->Fallback.TexCoord[i];
      cl->Size = 4;
      cl->Type = GL_FLOAT;
      cl->Stride = 0;
      cl->StrideB = 0;
      cl->Ptr = (void *) ctx->Current.Texcoord[i];
      cl->Enabled = 1;
   }

   cl = &ctx->Fallback.EdgeFlag;
   cl->Size = 1;
   cl->Type = GL_UNSIGNED_BYTE;
   cl->Stride = 0;
   cl->StrideB = 0;
   cl->Ptr = (void *) &ctx->Current.EdgeFlag;
   cl->Enabled = 1;   
}

d614 1
a614 3
			   VERT_TEX0_1|VERT_TEX1_1|VERT_MATERIAL);

      init_fallback_arrays( ctx );
a703 1
      gl_cva_init( ctx );
a707 2
      ctx->AllowVertexCull = 0;

a1426 2
   if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n");

d1687 1
d1689 2
a1690 3

   if (MESA_VERBOSE & VERBOSE_API)
      fprintf(stderr, "glResizeBuffersMESA\n");
d1696 2
a1697 5
   if (ctx->Buffer->Width == (GLint) buf_width &&
       ctx->Buffer->Height == (GLint) buf_height)
      return;

/*        ctx->NewState |= NEW_BUFFERS_SIZE; */
d1704 1
a1704 1
   if (ctx->Visual->DepthBits>0) {
d1708 1
a1708 1
   if (ctx->Visual->StencilBits>0) {
d1712 1
a1712 1
   if (ctx->Visual->AccumBits>0) {
d1716 1
a1716 1
   if (ctx->Visual->SoftwareAlpha) {
d1908 5
a1912 1
void gl_print_state( const char *msg, GLuint state )
d1914 43
a1956 22
   fprintf(stderr, 
	   "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
	   msg,
	   state,
	   (state & NEW_LIGHTING)         ? "lighting, " : "",
	   (state & NEW_RASTER_OPS)       ? "raster-ops, " : "",
	   (state & NEW_TEXTURING)        ? "texturing, " : "",
	   (state & NEW_POLYGON)          ? "polygon, " : "",
	   (state & NEW_DRVSTATE0)        ? "driver-0, " : "",
	   (state & NEW_DRVSTATE1)        ? "driver-1, " : "",
	   (state & NEW_DRVSTATE2)        ? "driver-2, " : "",
	   (state & NEW_DRVSTATE3)        ? "driver-3, " : "",
	   (state & NEW_MODELVIEW)        ? "modelview, " : "",
	   (state & NEW_PROJECTION)       ? "projection, " : "",
	   (state & NEW_TEXTURE_MATRIX)   ? "texture-matrix, " : "",
	   (state & NEW_USER_CLIP)        ? "user-clip, " : "",
	   (state & NEW_FRONT_FACE)       ? "front-face, " : "",
	   (state & NEW_CLIENT_STATE)     ? "client-state, " : "", 
	   (state & NEW_FOG)              ? "fog, " : "",
	   (state & NEW_NORMAL_TRANSFORM) ? "normal-transform, " : "",
	   (state & NEW_VIEWPORT)         ? "viewport, " : "",
	   (state & NEW_TEXTURE_ENABLE)   ? "texture-enable, " : "");   
d1960 1
d1969 3
a1971 3

   if (MESA_VERBOSE /*& VERBOSE_STATE*/)
      gl_print_state("", ctx->NewState);
d1976 3
a1978 7
   if ((ctx->NewState & NEW_TEXTURE_ENABLE) && ctx->Texture.EnabledStateChange) 
      ctx->NewState |= NEW_TEXTURING | NEW_RASTER_OPS;

   ctx->Texture.EnabledStateChange = 0;

   if ((ctx->NewState & ~(NEW_CLIENT_STATE|NEW_TEXTURE_ENABLE)) == 0) 
      goto finished;
d2100 1
d2102 1
a2148 4
   if (ctx->NewState & ~(NEW_CLIENT_STATE|NEW_TEXTURE_ENABLE|
			 NEW_DRIVER_STATE|NEW_USER_CLIP|NEW_FRONT_FACE|
			 NEW_POLYGON))
      gl_update_clipmask(ctx);
a2160 1
      ctx->IndirectTriangles |= DD_SW_RASTERIZE;
d2166 1
a2166 1
      ctx->Driver.RenderVBClippedTab = NULL;
d2187 4
a2190 7
      if (ctx->IndirectTriangles & DD_SW_RASTERIZE) {
	 gl_set_point_function(ctx);
	 gl_set_line_function(ctx);
	 gl_set_triangle_function(ctx);
	 gl_set_quad_function(ctx);
      }

a2205 3

      /* If we don't need eye coords, don't analyze that much?
       */
d2291 3
a2294 2
 finished:   
   gl_update_pipelines(ctx);
@


3.45.2.2
log
@q2, q3 bugfixes
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.45.2.1 1999/05/21 21:29:25 keithw Exp $ */
d1729 1
a1729 1
   GLenum e = ctx->ErrorValue;
a1731 2
   if (MESA_VERBOSE & VERBOSE_API)
      fprintf(stderr, "glGetError <-- %s\n", gl_lookup_enum_by_nr(e));
d1733 1
d1969 1
a1969 1
	   "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
d2030 1
d2033 1
a2033 1
	    if (ctx->NewState & NEW_TEXTURING) {
a2034 1
	    }
d2040 1
a2040 1
	    	    
d2170 1
a2180 3

      ctx->NeedCull = (ctx->LightTwoSide || 
		       (ctx->IndirectTriangles & DD_TRI_CULL));
d2286 1
a2286 1
	 if (ctx->Texture.NeedEyeCoords) ctx->NeedEyeCoords = GL_TRUE;	 
@


3.45.2.3
log
@Faux multitexturing for voodoo-1
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.45.2.2 1999/05/22 19:14:39 keithw Exp $ */
a53 1
#include "enums.h"
@


3.45.2.4
log
@Broadened FX fast path, added support for multipass multitexture.
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.45.2.3 1999/05/27 20:52:32 keithw Exp $ */
d1971 1
a1971 1
	   "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
d1986 1
a1993 19
void gl_print_enable_flags( const char *msg, GLuint flags )
{
   fprintf(stderr, 
	   "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s\n",
	   msg,
	   flags,
	   (flags & ENABLE_TEX0)       ? "tex-0, " : "",
	   (flags & ENABLE_TEX1)       ? "tex-1, " : "",
	   (flags & ENABLE_LIGHT)      ? "light, " : "",
	   (flags & ENABLE_FOG)        ? "fog, " : "",
	   (flags & ENABLE_USERCLIP)   ? "userclip, " : "",
	   (flags & ENABLE_TEXGEN0)    ? "tex-gen-0, " : "",
	   (flags & ENABLE_TEXGEN1)    ? "tex-gen-1, " : "",
	   (flags & ENABLE_TEXMAT0)    ? "tex-mat-0, " : "",
	   (flags & ENABLE_TEXMAT1)    ? "tex-mat-1, " : "",
	   (flags & ENABLE_NORMALIZE)  ? "normalize, " : "",
	   (flags & ENABLE_RESCALE)    ? "rescale, " : "");
}

d2004 1
a2004 1
   if (MESA_VERBOSE & VERBOSE_STATE)
d2021 1
a2021 3
      ctx->Enabled &= ~(ENABLE_TEX0|ENABLE_TEX1|
			ENABLE_TEXGEN0|ENABLE_TEXGEN1|
			ENABLE_TEXMAT0|ENABLE_TEXMAT1);
d2030 2
a2032 2
	    if (ctx->NewState & NEW_TEXTURING) 
	       gl_update_texture_unit( ctx, &ctx->Texture.Unit[i] );	    
d2034 5
a2038 1
	    ctx->Enabled |= ctx->Texture.Unit[i].Enabled<<(i*4);
d2043 8
a2050 16
	    if (ctx->TextureMatrix[i].type != MATRIX_IDENTITY)
	       ctx->Enabled |= ENABLE_TEXMAT0 << i;

	    if (ctx->Texture.Unit[i].GenFlags != 0) {
	       ctx->Enabled |= ENABLE_TEXGEN0 << i;
	    	    
	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_NORMALS) 
	       {
		  ctx->Texture.NeedNormals = GL_TRUE;
		  ctx->Texture.NeedEyeCoords = GL_TRUE;
	       }
 
	       if (ctx->Texture.Unit[i].GenFlags & TEXGEN_NEED_EYE_COORD)
	       {
		  ctx->Texture.NeedEyeCoords = GL_TRUE;
	       }	   
d2052 4
a2057 2
      
      ctx->Texture.Enabled = ctx->Enabled & ENABLE_TEX_ANY;
d2188 1
a2188 1
			 NEW_DRIVER_STATE|NEW_USER_CLIP|
d2200 2
a2201 1
			NEW_USER_CLIP))
@


3.45.2.5
log
@When texture.unit[0].envmode is GL_REPLACE, don't need VERT_RGBA as an input to rendering stages.

Rearranged fxfastpath.c without improving its performance.
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.45.2.4 1999/05/30 13:30:34 keithw Exp $ */
a2216 1
			NEW_TEXTURE_ENV|
d2233 6
@


3.45.2.6
log
@some trial assembly, made newer code active by default
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.45.2.5 1999/06/01 00:45:21 keithw Exp $ */
d330 6
a335 8
      GLuint d;
      for (d = 1 ; d <= 3 ; d++) {
	 ss->DefaultD[d][i] = gl_alloc_texture_object(ss, 0, d);
	 if (!ss->DefaultD[d][i]) {
	    outOfMemory = GL_TRUE;
	    break;
	 }
	 ss->DefaultD[d][i]->RefCount++; /* don't free if not in use */
d346 6
a351 6
         if (ss->DefaultD[1][i])
            gl_free_texture_object(ss, ss->DefaultD[1][i]);
         if (ss->DefaultD[2][i])
            gl_free_texture_object(ss, ss->DefaultD[2][i]);
         if (ss->DefaultD[3][i])
            gl_free_texture_object(ss, ss->DefaultD[3][i]);
d472 3
a474 3
   texUnit->CurrentD[1] = ctx->Shared->DefaultD[1][unit];
   texUnit->CurrentD[2] = ctx->Shared->DefaultD[2][unit];
   texUnit->CurrentD[3] = ctx->Shared->DefaultD[3][unit];
d1971 1
a1971 1
	   "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
a1985 1
	   (state & NEW_TEXTURE_ENV)      ? "texture-env, " : "", 
d2028 1
a2028 2
   if ((ctx->NewState & NEW_TEXTURE_ENABLE) &&
       (ctx->Enabled & ENABLE_TEX_ANY) != ctx->Texture.Enabled) 
d2031 1
a2031 7
   if (ctx->NewState & NEW_TEXTURE_ENV) {
      if (ctx->Texture.Unit[0].EnvMode == ctx->Texture.Unit[0].LastEnvMode &&
	  ctx->Texture.Unit[1].EnvMode == ctx->Texture.Unit[1].LastEnvMode)
	 ctx->NewState &= ~NEW_TEXTURE_ENV;
      ctx->Texture.Unit[0].LastEnvMode = ctx->Texture.Unit[0].EnvMode;
      ctx->Texture.Unit[1].LastEnvMode = ctx->Texture.Unit[1].EnvMode;
   }
d2036 7
a2042 2
   if (ctx->NewState & NEW_TEXTURE_MATRIX) {
      ctx->Enabled &= ~(ENABLE_TEXMAT0|ENABLE_TEXMAT1);
d2045 1
a2045 2
	 if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER) 
	 {
a2047 4

	    if (ctx->Texture.Unit[i].Enabled && 
		ctx->TextureMatrix[i].type != MATRIX_IDENTITY)
	       ctx->Enabled |= ENABLE_TEXMAT0 << i;
d2049 4
a2052 2
      }
   }
d2054 1
a2054 9
   if (ctx->NewState & NEW_TEXTURING) {
      ctx->Texture.NeedNormals = GL_FALSE;
      gl_update_texture_state(ctx);
      ctx->Enabled &= ~(ENABLE_TEXGEN0|ENABLE_TEXGEN1);
      ctx->Texture.ReallyEnabled = 0;

      for (i=0; i < MAX_TEXTURE_UNITS; i++) {
	 if (ctx->Texture.Unit[i].Enabled) {
	    gl_update_texture_unit( ctx, &ctx->Texture.Unit[i] );	    
d2059 3
d2080 3
a2082 1
      ctx->NeedNormals = (ctx->Light.Enabled || ctx->Texture.NeedNormals);
d2239 1
a2239 1
      ctx->Driver.UpdateState(ctx);
d2256 2
a2257 1
   /* Should only be calc'd when !need_eye_coords and not culling.
d2259 12
a2270 1
   if (ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION)) {
d2279 1
a2279 1
	 
a2284 20
      gl_calculate_model_project_matrix( ctx );
      ctx->ModelProjectWinMatrixUptodate = 0;

      if (!(ctx->Enabled & (ENABLE_LIGHT | ENABLE_TEXGEN0 | ENABLE_TEXGEN1)))
	 ctx->vb_proj_matrix = &ctx->ModelProjectMatrix;
   }

   /* Figure out whether we can light in object space or not.  If we
    * can, find the current positions of the lights in object space 
    */
   if ((ctx->Enabled & (ENABLE_LIGHT | ENABLE_TEXGEN0 | ENABLE_TEXGEN1)) &&
       (ctx->NewState & (NEW_LIGHTING | 
			 NEW_MODELVIEW | 
			 NEW_PROJECTION |
			 NEW_TEXTURING | 
			 NEW_RASTER_OPS |
			 NEW_USER_CLIP)))
   {
      GLboolean oldcoord, oldnorm;

d2309 7
@


3.45.2.7
log
@Removed SGIS multitexture, added FX/X86 assm directory
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.45.2.6 1999/06/06 22:35:53 keithw Exp $ */
d863 1
a1950 3

   ctx->TriangleCaps &= ~DD_MULTIDRAW;

a1952 1
      ctx->TriangleCaps |= DD_MULTIDRAW;
a1955 1
      ctx->TriangleCaps |= DD_MULTIDRAW;
a1959 1
      ctx->TriangleCaps |= DD_MULTIDRAW;
a1964 1
      ctx->TriangleCaps |= DD_MULTIDRAW;
d2168 2
a2169 6
	 ctx->TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
	 if (ctx->Light.Enabled) {
	    if (ctx->Light.Model.TwoSide) 
	       ctx->TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
	    gl_update_lighting(ctx);
	 }
d2196 3
a2198 7
	 ctx->TriangleCaps &= ~DD_TRI_OFFSET;

	 if (ctx->Polygon.OffsetPoint ||
	     ctx->Polygon.OffsetLine ||
	     ctx->Polygon.OffsetFill)
	    ctx->TriangleCaps |= DD_TRI_OFFSET;

d2204 14
a2235 1
      ctx->IndirectTriangles = ctx->TriangleCaps & ~ctx->Driver.TriangleCaps;  
a2236 1
      
@


3.44
log
@miscellaneous bug fixes
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.43 1999/05/02 00:59:24 keithw Exp $ */
d2101 1
a2102 1
   }
@


3.43
log
@FX polygon offset and debugging changes
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.42 1999/04/22 02:18:30 brianp Exp $ */
a185 1

d1970 2
a1971 2
   static int counter;
   extern void fxsignals();
@


3.42
log
@added fx-catch-signals config option
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.41 1999/04/07 22:16:55 brianp Exp $ */
d797 1
d1970 3
d1977 3
@


3.41
log
@fixed int/enum cast warning
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.40 1999/03/31 20:18:38 keithw Exp $ */
d969 2
@


3.40
log
@Compiled vertex arrays
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.39 1999/03/30 02:44:36 brianp Exp $ */
d612 1
a612 1
      ctx->Current.Primitive = GL_POLYGON+1;
@


3.39
log
@another change for multi-buffer drawing
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.38 1999/03/28 20:56:15 brianp Exp $ */
d50 1
d63 1
d526 2
d614 3
d697 11
d788 1
d1161 1
a1161 1
   ctx->VB = gl_alloc_vb( ctx );
d1166 1
a1166 1
   SET_IMMEDIATE(ctx, &ctx->VB->store);
d1192 1
a1192 1
   gl_reset_vb( ctx, &ctx->VB->store );
d1249 8
d1975 2
d1978 8
a1985 2
      if (ctx->Texture.Enabled) {
	 GLuint tex_enabled[2] = { 0x7, 0x70 };
d1987 1
a1987 11
	 for (i=0; i < MAX_TEXTURE_UNITS; i++) 
	 {
	    if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER) {
	       gl_matrix_analyze( &ctx->TextureMatrix[i] );
	       ctx->TextureMatrix[i].flags &= ~MAT_DIRTY_DEPENDENTS;
	    }
	    
	    if (!(ctx->Texture.Enabled & tex_enabled[i])) {
	       ctx->Texture.Unit[i].AnyTransform = 0;
	       continue;
	    }
d1992 5
d2000 1
a2000 1

d2010 1
a2010 1
         }
d2041 1
d2131 8
a2138 10
      if (   ctx->Polygon.Unfilled
	     || ctx->Polygon.OffsetAny
	     || ctx->Polygon.CullFlag
	     || ctx->LightTwoSide
	     || ctx->RenderMode!=GL_RENDER) {
	 ctx->DirectTriangles = GL_FALSE;
      }
      else {
	 ctx->DirectTriangles = GL_TRUE;
      }
a2158 1
      ctx->Driver.RenderVBIndirectTab = NULL;
a2182 1
      gl_set_vertex_function(ctx);
a2215 1

d2217 1
a2217 6
			    ctx->Point.Params[0]!=1.0 ||
			    ctx->Point.Params[1]!=0.0 || 
			    ctx->Point.Params[2]!=0.0); 
				 

      
d2246 1
a2246 1
	 ctx->VB->ProjMatrix = &ctx->ProjectionMatrix;
d2248 1
a2248 1
	 ctx->VB->ProjMatrix = &ctx->ModelProjectMatrix;
d2281 1
a2281 1
      gl_update_shade_context( ctx );
d2284 3
@


3.38
log
@better handling of multi draw buffers, software alpha buffers
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.37 1999/03/16 00:04:46 keithw Exp $ */
d1198 1
d1205 1
@


3.37
log
@Eero's lighting fix
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.36 1999/02/25 14:12:30 keithw Exp $ */
d590 1
d1028 1
a1028 7
   /* software alpha buffers */
   if (alphaFlag) {
      vis->FrontAlphaEnabled = GL_TRUE;
      if (dbFlag) {
         vis->BackAlphaEnabled = GL_TRUE;
      }
   }
d1197 1
d1199 1
d1203 1
d1205 1
d1362 5
a1366 2
      if (buffer->FrontAlpha) {
         free( buffer->FrontAlpha );
d1368 5
a1372 2
      if (buffer->BackAlpha) {
         free( buffer->BackAlpha );
d1645 1
a1645 1
   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glGetError", 0);
d1685 1
a1685 2
   if (newsize
       && (ctx->Visual->FrontAlphaEnabled || ctx->Visual->BackAlphaEnabled)) {
d1842 4
a1845 2
   if (ctx->Visual->FrontAlphaEnabled)	ctx->RasterMask |= ALPHABUF_BIT;
   if (ctx->Visual->BackAlphaEnabled)	ctx->RasterMask |= ALPHABUF_BIT;
d1854 6
a1859 3
   /* check if drawing to front and back buffers */
   if (ctx->Color.DrawBuffer==GL_FRONT_AND_BACK) {
      ctx->RasterMask |= FRONT_AND_BACK_BIT;
d1861 2
a1862 4

   /* check if writing to color buffer(s) is disabled */
   if (ctx->Color.DrawBuffer==GL_NONE) {
      ctx->RasterMask |= NO_DRAW_BIT;
d1865 3
a1867 1
      ctx->RasterMask |= NO_DRAW_BIT;
d1870 3
a1872 1
      ctx->RasterMask |= NO_DRAW_BIT;
@


3.36
log
@Merged in kw3 patch
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.35 1999/02/24 22:48:05 jens Exp $ */
d2220 2
a2221 1
	 if ( ((ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION)) &&
@


3.35
log
@Added header file to get XMesa to compile standalone and inside XFree86
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.34 1999/02/17 02:12:43 brianp Exp $ */
a28 110
 * $Log: context.c,v $
 * Revision 3.34  1999/02/17 02:12:43  brianp
 * fixed memory deallocation bugs in alloc_shared_state() (davem@@twiddle.net)
 *
 * Revision 3.33  1999/02/14 03:46:34  brianp
 * new copyright
 *
 * Revision 3.32  1999/02/05 03:23:56  brianp
 * fixed a few BeOS compiler warnings
 *
 * Revision 3.31  1999/01/30 04:29:16  brianp
 * stereo updates (KendallB@@scitechsoft.com)
 *
 * Revision 3.30  1998/11/17 01:52:47  brianp
 * implemented GL_NV_texgen_reflection extension (MJK)
 *
 * Revision 3.29  1998/11/08 22:36:00  brianp
 * renamed texture sets to texture units
 *
 * Revision 3.28  1998/11/07 14:22:17  brianp
 * call gl_init_transformation() in one_time_init()
 *
 * Revision 3.27  1998/11/07 02:27:27  brianp
 * removed TexCoordSet from struct gl_texture_set (GL_EXT_multitexture)
 *
 * Revision 3.26  1998/11/07 02:13:33  brianp
 * added one_time_init(), fixed a NeedEyeNormals bug
 *
 * Revision 3.25  1998/11/03 01:16:57  brianp
 * added Texture.ReallyEnabled to simply testing for enabled textures
 *
 * Revision 3.24  1998/10/31 17:06:15  brianp
 * variety of multi-texture changes
 *
 * Revision 3.23  1998/10/29 02:33:49  brianp
 * incorporated Keith Whitwell's transformation optimizations
 *
 * Revision 3.22  1998/10/05 00:40:15  brianp
 * added GL_INGR_blend_func_separate extension
 *
 * Revision 3.21  1998/08/23 22:19:30  brianp
 * added DoViewportMapping to context struct
 *
 * Revision 3.20  1998/08/21 01:49:46  brianp
 * initialize vertex array state
 *
 * Revision 3.19  1998/07/17 03:23:32  brianp
 * added Pixel.ScaleOrBiasRGBA field
 *
 * Revision 3.18  1998/06/21 02:00:55  brianp
 * cleaned up clip interpolation function code
 *
 * Revision 3.17  1998/06/19 03:13:10  brianp
 * evaluator state wasn't fully initialized
 *
 * Revision 3.16  1998/06/07 22:18:52  brianp
 * implemented GL_EXT_multitexture extension
 *
 * Revision 3.15  1998/04/01 02:58:28  brianp
 * updated for v0.24 of 3Dfx/Glide driver
 *
 * Revision 3.14  1998/03/27 03:30:36  brianp
 * fixed G++ warnings
 *
 * Revision 3.13  1998/03/22 16:42:22  brianp
 * added 8-bit CI->RGBA pixel mapping tables
 *
 * Revision 3.12  1998/03/15 17:55:54  brianp
 * added FogMode to context struct
 *
 * Revision 3.11  1998/03/05 02:49:48  brianp
 * added an assertion and added better comments in gl_update_state()
 *
 * Revision 3.10  1998/03/01 20:17:03  brianp
 * removed dead code
 *
 * Revision 3.9  1998/02/20 04:50:09  brianp
 * implemented GL_SGIS_multitexture
 *
 * Revision 3.8  1998/02/13 04:38:05  brianp
 * optimized blending functions called via BlendFunc function pointer
 *
 * Revision 3.7  1998/02/13 03:23:04  brianp
 * AlphaRef is now a GLubyte
 *
 * Revision 3.6  1998/02/13 03:17:02  brianp
 * added basic stereo support
 *
 * Revision 3.5  1998/02/08 20:20:34  brianp
 * ColorMask is now GLubyte[4] instead of GLuint
 *
 * Revision 3.4  1998/02/05 01:10:25  brianp
 * added John Stone's thread modifications
 *
 * Revision 3.3  1998/02/02 03:09:34  brianp
 * added GL_LIGHT_MODEL_COLOR_CONTROL (separate specular color interpolation)
 *
 * Revision 3.2  1998/02/01 16:37:19  brianp
 * added GL_EXT_rescale_normal extension
 *
 * Revision 3.1  1998/01/31 23:56:55  brianp
 * removed Driver.ClearDepthBuffer function
 *
 * Revision 3.0  1998/01/31 20:49:07  brianp
 * initial rev
 *
 */


/*
d47 1
d51 1
d53 1
d67 1
d69 1
d73 1
d75 1
d77 1
d79 2
d117 1
d287 3
d292 2
a293 1
      gl_init_eval();
d295 2
a391 17
/*
 * Init for optimized shader context
 */
static void init_shade_context( GLcontext *ctx, struct gl_shade_context *sc )
{
   sc->vertices = (GLfloat *) ctx->VB->Obj;
   sc->vertex_stride = 4;
   sc->normals = (GLfloat *) ctx->VB->Normal;
   sc->normal_stride = 3;

   sc->Fcolor = ctx->VB->Fcolor;
   sc->Bcolor = ctx->VB->Bcolor;
   sc->Fspec = ctx->VB->Fspec;
   sc->Bspec = ctx->VB->Bspec;
   sc->Findex = ctx->VB->Findex;
   sc->Bindex = ctx->VB->Bindex;
}
d401 2
d417 1
a417 1
   l->CosCutoff = -1.0;
a444 1
   gl_compute_material_shine_table( m );
d535 1
a535 1
      /* Projection matrix */
d537 6
d548 2
a549 1
	 ctx->ProjectionStack[i].inv = 0;
d592 1
a592 1
      ASSIGN_4V( ctx->Current.ByteColor, 255, 255, 255, 255 );
a593 1
      ASSIGN_3V( ctx->Current.Normal, 0.0, 0.0, 1.0 );
d595 2
a596 2
         ASSIGN_4V( ctx->Current.MultiTexCoord[i], 0.0, 0.0, 0.0, 1.0 );
      ctx->Current.TexCoord = ctx->Current.MultiTexCoord[0];
d606 2
d694 2
d704 3
a706 1
         = gl_material_bitmask( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
d834 1
a834 1
         ASSIGN_4V( ctx->Transform.ClipEquation[i], 0.0, 0.0, 0.0, 0.0 );
d845 11
a855 6
      ctx->Viewport.Sx = 0.0;  /* Sx, Tx, Sy, Ty are computed later */
      ctx->Viewport.Tx = 0.0;
      ctx->Viewport.Sy = 0.0;
      ctx->Viewport.Ty = 0.0;
      ctx->Viewport.Sz = 0.5 * DEPTH_SCALE;
      ctx->Viewport.Tz = 0.5 * DEPTH_SCALE;
d858 22
a879 22
      ctx->Array.VertexSize = 4;
      ctx->Array.VertexType = GL_FLOAT;
      ctx->Array.VertexStride = 0;
      ctx->Array.VertexStrideB = 0;
      ctx->Array.VertexPtr = NULL;
      ctx->Array.VertexEnabled = GL_FALSE;
      ctx->Array.NormalType = GL_FLOAT;
      ctx->Array.NormalStride = 0;
      ctx->Array.NormalStrideB = 0;
      ctx->Array.NormalPtr = NULL;
      ctx->Array.NormalEnabled = GL_FALSE;
      ctx->Array.ColorSize = 4;
      ctx->Array.ColorType = GL_FLOAT;
      ctx->Array.ColorStride = 0;
      ctx->Array.ColorStrideB = 0;
      ctx->Array.ColorPtr = NULL;
      ctx->Array.ColorEnabled = GL_FALSE;
      ctx->Array.IndexType = GL_FLOAT;
      ctx->Array.IndexStride = 0;
      ctx->Array.IndexStrideB = 0;
      ctx->Array.IndexPtr = NULL;
      ctx->Array.IndexEnabled = GL_FALSE;
d881 6
a886 6
         ctx->Array.TexCoordSize[i] = 4;
         ctx->Array.TexCoordType[i] = GL_FLOAT;
         ctx->Array.TexCoordStride[i] = 0;
         ctx->Array.TexCoordStrideB[i] = 0;
         ctx->Array.TexCoordPtr[i] = NULL;
         ctx->Array.TexCoordEnabled[i] = GL_FALSE;
d889 4
a892 4
      ctx->Array.EdgeFlagStride = 0;
      ctx->Array.EdgeFlagStrideB = 0;
      ctx->Array.EdgeFlagPtr = NULL;
      ctx->Array.EdgeFlagEnabled = GL_FALSE;
a931 1
      ctx->Primitive = GL_BITMAP;
a938 2
      init_shade_context( ctx, &ctx->shade_context );

d1110 2
d1125 1
d1147 1
a1147 1
   ctx->VB = gl_alloc_vb();
d1152 1
d1178 19
d1239 1
d1263 5
d1448 1
d1557 10
d1619 2
a1620 1
      fprintf( stderr, "Mesa user error: %s in %s\n", errstr, s );
d1640 1
a1640 4
   if (INSIDE_BEGIN_END(ctx)) {
      gl_error( ctx, GL_INVALID_OPERATION, "glGetError" );
      return GL_INVALID_OPERATION;
   }
d1880 1
a1880 1
	 if (ctx->Light.Model.TwoSide) {
d1886 1
a1886 1
	 if (ctx->Light.Model.TwoSide) {
d1908 3
d1928 7
a1934 4
   if (ctx->NewState & NEW_MODELVIEW) {
      gl_matrix_analyze( &ctx->ModelView );
      ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;
   }
d1936 2
a1937 13
   if (ctx->NewState & NEW_PROJECTION) {
      gl_matrix_analyze( &ctx->ProjectionMatrix );
      ctx->ProjectionMatrix.flags &= ~MAT_DIRTY_DEPENDENTS;
   }
  
   if (ctx->Texture.Enabled || ctx->RenderMode==GL_FEEDBACK)
   {
      for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++)
	 if (ctx->TextureMatrix[i].flags & MAT_DIRTY_ALL_OVER) {
	    gl_matrix_analyze( &ctx->TextureMatrix[i] );
	    ctx->TextureMatrix[i].flags &= ~MAT_DIRTY_DEPENDENTS;
	 }
   }
d1939 29
a1967 7
   if (ctx->NewState & NEW_RASTER_OPS) {
      update_pixel_logic(ctx);
      update_pixel_masking(ctx);
      update_fog_mode(ctx);
      update_rasterflags(ctx);
      if (ctx->Driver.Dither) {
         (*ctx->Driver.Dither)( ctx, ctx->Color.DitherFlag );
a1968 1
   }
d1970 2
a1971 3
   if (ctx->NewState & NEW_LIGHTING) {
      gl_update_lighting(ctx);
      gl_set_color_function(ctx);
a1973 3
   if (ctx->NewState & NEW_TEXTURING) {
      gl_update_texture_state(ctx);
   }
d1976 20
a1995 2
      update_clipmask(ctx);
   }
d1997 45
a2041 26
   if (ctx->NewState & (NEW_LIGHTING | NEW_TEXTURING)) {
      /* Check if normal vectors are needed */
      GLboolean sphereGen = GL_FALSE;
      if (ctx->Texture.Enabled) {
         GLuint u;
         for (u=0; u<MAX_TEXTURE_UNITS; u++) {
            if ((ctx->Texture.Unit[u].GenModeS==GL_SPHERE_MAP
                 && (ctx->Texture.Unit[u].TexGenEnabled & S_BIT))
                || (ctx->Texture.Unit[u].GenModeT==GL_SPHERE_MAP
                    && (ctx->Texture.Unit[u].TexGenEnabled & T_BIT)))
               sphereGen = GL_TRUE;
            else if ((ctx->Texture.Unit[u].GenModeS==GL_REFLECTION_MAP_NV
                 && (ctx->Texture.Unit[u].TexGenEnabled & S_BIT))
                || (ctx->Texture.Unit[u].GenModeT==GL_REFLECTION_MAP_NV
                    && (ctx->Texture.Unit[u].TexGenEnabled & T_BIT))
                || (ctx->Texture.Unit[u].GenModeR==GL_REFLECTION_MAP_NV
                    && (ctx->Texture.Unit[u].TexGenEnabled & R_BIT)))
               sphereGen = GL_TRUE;
            else if ((ctx->Texture.Unit[u].GenModeS==GL_NORMAL_MAP_NV
                 && (ctx->Texture.Unit[u].TexGenEnabled & S_BIT))
                || (ctx->Texture.Unit[u].GenModeT==GL_NORMAL_MAP_NV
                    && (ctx->Texture.Unit[u].TexGenEnabled & T_BIT))
                || (ctx->Texture.Unit[u].GenModeR==GL_NORMAL_MAP_NV
                    && (ctx->Texture.Unit[u].TexGenEnabled & R_BIT)))
               sphereGen = GL_TRUE;
         }
d2043 4
a2046 2
      if (ctx->Light.Enabled || sphereGen) {
         ctx->NeedNormals = GL_TRUE;
a2047 4
      else {
         ctx->NeedNormals = GL_FALSE;
      }
   }
d2049 1
a2049 12
   if (ctx->NewState & NEW_RASTER_OPS) {
      /* Check if incoming colors can be modified during rasterization */
      if (ctx->Fog.Enabled ||
          ctx->Texture.Enabled ||
          ctx->Color.BlendEnabled ||
          ctx->Color.SWmasking ||
          ctx->Color.SWLogicOpEnabled) {
         ctx->MutablePixels = GL_TRUE;
      }
      else {
         ctx->MutablePixels = GL_FALSE;
      }
d2052 1
a2052 18
   if (ctx->NewState & (NEW_RASTER_OPS | NEW_LIGHTING)) {
      /* Check if all pixels generated are likely to be the same color */
      if (ctx->Light.ShadeModel==GL_SMOOTH ||
          ctx->Light.Enabled ||
          ctx->Fog.Enabled ||
          ctx->Texture.Enabled ||
          ctx->Color.BlendEnabled ||
          ctx->Color.SWmasking ||
          ctx->Color.SWLogicOpEnabled) {
         ctx->MonoPixels = GL_FALSE;       /* pixels probably multicolored */
      }
      else {
         /* pixels will all be same color,
          * only glColor() can invalidate this.
          */
         ctx->MonoPixels = GL_TRUE;
      }
   }
d2054 28
a2081 12
   if (ctx->NewState & NEW_POLYGON) {
      /* Setup CullBits bitmask */
      ctx->Polygon.CullBits = 0;
      if (ctx->Polygon.CullFlag) {
         if (ctx->Polygon.CullFaceMode==GL_FRONT ||
             ctx->Polygon.CullFaceMode==GL_FRONT_AND_BACK) {
            ctx->Polygon.CullBits |= 1;
         }
         if (ctx->Polygon.CullFaceMode==GL_BACK ||
             ctx->Polygon.CullFaceMode==GL_FRONT_AND_BACK) {
            ctx->Polygon.CullBits |= 2;
         }
d2083 2
a2084 9
      /* Any Polygon offsets enabled? */
      ctx->Polygon.OffsetAny = ctx->Polygon.OffsetPoint ||
                               ctx->Polygon.OffsetLine ||
                               ctx->Polygon.OffsetFill;
      /* reset Z offsets now */
      ctx->PointZoffset   = 0.0;
      ctx->LineZoffset    = 0.0;
      ctx->PolygonZoffset = 0.0;
   }
a2085 1
   if (ctx->NewState & (NEW_POLYGON | NEW_LIGHTING)) {
d2088 5
a2092 5
          || ctx->Polygon.OffsetAny
          || ctx->Polygon.CullFlag
          || ctx->Light.Model.TwoSide
          || ctx->RenderMode!=GL_RENDER) {
         ctx->DirectTriangles = GL_FALSE;
d2095 1
a2095 1
         ctx->DirectTriangles = GL_TRUE;
a2098 19
   /* update scissor region */
   ctx->Buffer->Xmin = 0;
   ctx->Buffer->Ymin = 0;
   ctx->Buffer->Xmax = ctx->Buffer->Width-1;
   ctx->Buffer->Ymax = ctx->Buffer->Height-1;
   if (ctx->Scissor.Enabled) {
      if (ctx->Scissor.X > ctx->Buffer->Xmin) {
         ctx->Buffer->Xmin = ctx->Scissor.X;
      }
      if (ctx->Scissor.Y > ctx->Buffer->Ymin) {
         ctx->Buffer->Ymin = ctx->Scissor.Y;
      }
      if (ctx->Scissor.X + ctx->Scissor.Width - 1 < ctx->Buffer->Xmax) {
         ctx->Buffer->Xmax = ctx->Scissor.X + ctx->Scissor.Width - 1;
      }
      if (ctx->Scissor.Y + ctx->Scissor.Height - 1 < ctx->Buffer->Ymax) {
         ctx->Buffer->Ymax = ctx->Scissor.Y + ctx->Scissor.Height - 1;
      }
   }
d2100 26
a2125 27
   /*
    * Update Device Driver interface
    */
   if (ctx->NewState & NEW_RASTER_OPS) {
      ctx->Driver.AllocDepthBuffer = gl_alloc_depth_buffer;
      if (ctx->Depth.Mask) {
         switch (ctx->Depth.Func) {
            case GL_LESS:
               ctx->Driver.DepthTestSpan = gl_depth_test_span_less;
               ctx->Driver.DepthTestPixels = gl_depth_test_pixels_less;
               break;
            case GL_GREATER:
               ctx->Driver.DepthTestSpan = gl_depth_test_span_greater;
               ctx->Driver.DepthTestPixels = gl_depth_test_pixels_greater;
               break;
            default:
               ctx->Driver.DepthTestSpan = gl_depth_test_span_generic;
               ctx->Driver.DepthTestPixels = gl_depth_test_pixels_generic;
         }
      }
      else {
         ctx->Driver.DepthTestSpan = gl_depth_test_span_generic;
         ctx->Driver.DepthTestPixels = gl_depth_test_pixels_generic;
      }
      ctx->Driver.ReadDepthSpanFloat = gl_read_depth_span_float;
      ctx->Driver.ReadDepthSpanInt = gl_read_depth_span_int;
   }
d2127 5
a2131 11
   ctx->Driver.PointsFunc = NULL;
   ctx->Driver.LineFunc = NULL;
   ctx->Driver.TriangleFunc = NULL;
   ctx->Driver.QuadFunc = NULL;
   ctx->Driver.RectFunc = NULL;

   /*
    * The ctx->Driver.UpdateState pointer _MUST_ be valid at this point
    * in order for any impending rendering to succeed.
    */
   assert(ctx->Driver.UpdateState);
d2133 12
a2144 16
   /*
    * Here the driver sets up all the ctx->Driver function pointers to
    * it's specific, private functions.
    */
   (*ctx->Driver.UpdateState)(ctx);

   /*
    * In case the driver didn't hook in an optimized point, line or
    * triangle function we'll now select "core/fallback" point, line
    * and triangle functions.
    */
   gl_set_point_function(ctx);
   gl_set_line_function(ctx);
   gl_set_triangle_function(ctx);
   gl_set_quad_function(ctx);
   gl_set_vertex_function(ctx);
d2154 17
a2170 3
			NEW_USER_CLIP)) {
      GLboolean oldcoord = ctx->NeedEyeCoords;
      GLboolean oldnorm = ctx->NeedEyeNormals;
d2172 2
a2173 2
      ctx->NeedEyeCoords = (ctx->Transform.AnyClip || 
			    (ctx->Fog.Enabled && ctx->Hint.Fog != GL_NICEST));
d2175 9
d2185 1
a2185 1

d2187 10
a2196 5
         if (ctx->Light.NeedVertices &&
             !TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING)) {
            ctx->NeedEyeCoords = GL_TRUE;
         } 
         ctx->NeedEyeNormals = ctx->NeedEyeCoords;
d2199 3
a2201 3
	 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++)
	    if (ctx->Texture.Unit[i].TexGenEnabled) 
	       ctx->NeedEyeCoords = ctx->NeedEyeNormals = GL_TRUE;
d2204 3
a2206 2
      if ((ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION) &&
	   !ctx->NeedEyeCoords))
d2208 8
d2219 2
a2220 2

	 if ( (ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION) &&
d2222 2
a2223 2
	     oldcoord != ctx->NeedEyeCoords || 
	     oldnorm != ctx->NeedEyeNormals) {
d2226 18
d2245 2
d2248 1
a2248 1

d2251 1
@


3.34
log
@fixed memory deallocation bugs in alloc_shared_state() (davem@@twiddle.net)
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.33 1999/02/14 03:46:34 brianp Exp brianp $ */
d30 3
d182 3
@


3.33
log
@new copyright
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.32 1999/02/05 03:23:56 brianp Exp brianp $ */
d30 3
d426 1
a426 1
      if (!ss->DisplayList)
d428 1
a428 1
      if (!ss->TexObjects)
d431 1
a431 1
         if (!ss->Default1D[i])
d433 1
a433 1
         if (!ss->Default2D[i])
d435 1
a435 1
         if (!ss->Default3D[i])
@


3.32
log
@fixed a few BeOS compiler warnings
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.31 1999/01/30 04:29:16 brianp Exp brianp $ */
d6 19
a24 15
 * Copyright (C) 1995-1999  Brian Paul
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
d30 3
@


3.31
log
@stereo updates (KendallB@@scitechsoft.com)
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.30 1998/11/17 01:52:47 brianp Exp brianp $ */
d26 3
d575 1
a575 1
   map->Points = malloc(n * sizeof(GLfloat));
d594 1
a594 1
   map->Points = malloc(n * sizeof(GLfloat));
@


3.30
log
@implemented GL_NV_texgen_reflection extension (MJK)
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.29 1998/11/08 22:36:00 brianp Exp brianp $ */
d6 1
a6 1
 * Copyright (C) 1995-1998  Brian Paul
d26 3
a1070 5

   if (stereoFlag) {
      gl_warning(NULL, "stereo not supported");
      return NULL;   /* Stereo isn't supported yet! */
   }
@


3.29
log
@renamed texture sets to texture units
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.28 1998/11/07 14:22:17 brianp Exp brianp $ */
d26 3
d2017 14
@


3.28
log
@call gl_init_transformation() in one_time_init()
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.27 1998/11/07 02:27:27 brianp Exp brianp $ */
d26 3
d144 1
d150 1
d159 1
a159 2
#include "matrix.h"
#include "shade.h"
d533 1
a533 1
static void init_texture_set( GLcontext *ctx, GLuint setNum )
d535 1
a535 1
   struct gl_texture_set *s = &ctx->Texture.Set[setNum];
d537 7
a543 7
   s->EnvMode = GL_MODULATE;
   ASSIGN_4V( s->EnvColor, 0.0, 0.0, 0.0, 0.0 );
   s->TexGenEnabled = 0;
   s->GenModeS = GL_EYE_LINEAR;
   s->GenModeT = GL_EYE_LINEAR;
   s->GenModeR = GL_EYE_LINEAR;
   s->GenModeQ = GL_EYE_LINEAR;
d545 12
a556 12
   ASSIGN_4V( s->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( s->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
   ASSIGN_4V( s->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( s->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( s->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( s->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
   ASSIGN_4V( s->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
   ASSIGN_4V( s->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );

   s->Current1D = ctx->Shared->Default1D[setNum];
   s->Current2D = ctx->Shared->Default2D[setNum];
   s->Current3D = ctx->Shared->Default3D[setNum];
d883 2
a884 2
      ctx->Texture.CurrentSet = 0;      /* multitexture */
      ctx->Texture.CurrentTransformSet = 0; /* multitexture */
d889 1
a889 1
         init_texture_set( ctx, i );
d990 1
a990 1
      ctx->TexCoordSet = 0;
d2008 6
a2013 6
         GLuint texSet;
         for (texSet=0; texSet<MAX_TEXTURE_UNITS; texSet++) {
            if ((ctx->Texture.Set[texSet].GenModeS==GL_SPHERE_MAP
                 && (ctx->Texture.Set[texSet].TexGenEnabled & S_BIT))
                || (ctx->Texture.Set[texSet].GenModeT==GL_SPHERE_MAP
                    && (ctx->Texture.Set[texSet].TexGenEnabled & T_BIT)))
d2198 1
a2198 1
	    if (ctx->Texture.Set[i].TexGenEnabled) 
@


3.27
log
@removed TexCoordSet from struct gl_texture_set (GL_EXT_multitexture)
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.26 1998/11/07 02:13:33 brianp Exp brianp $ */
d26 3
d360 1
a360 1
      /* gl_3dnow_test(); XXX ToDo */
@


3.26
log
@added one_time_init(), fixed a NeedEyeNormals bug
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.25 1998/11/03 01:16:57 brianp Exp brianp $ */
d26 3
a549 2

   s->TexCoordSet = setNum;   /* multitexture */
@


3.25
log
@added Texture.ReallyEnabled to simply testing for enabled textures
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.24 1998/10/31 17:06:15 brianp Exp brianp $ */
d26 3
d342 16
d448 5
a465 1

a469 1

a1106 1

d1200 1
a1200 3
   gl_init_math();
   gl_init_lists();
   gl_init_eval();
d2172 1
a2172 2
			NEW_USER_CLIP))
   {
d2181 6
a2186 8
      if (ctx->Light.Enabled)
      {
	  if (ctx->Light.NeedVertices && 
	      !TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING)) 
	  {
	      ctx->NeedEyeCoords = GL_TRUE;
	  } 
	  ctx->NeedEyeNormals = ctx->NeedEyeCoords;
d2188 2
a2189 3
      else if (ctx->Texture.Enabled || ctx->RenderMode==GL_FEEDBACK) 
      {
	 for (i = 0 ; i < MAX_TEXTURE_UNITS ; i++) 
d2192 1
a2192 1
      }    
d2194 1
a2194 1
      if ((ctx->NewState & (NEW_MODELVIEW|NEW_PROJECTION) && 
d2198 1
a2198 2
      if (ctx->Light.Enabled) 
      {
d2202 1
a2202 1
	       !ctx->NeedEyeCoords) || 
d2204 1
a2204 2
	     oldnorm != ctx->NeedEyeNormals)
	 {
d2208 1
a2208 1
   }			    
a2211 1

@


3.24
log
@variety of multi-texture changes
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.23 1998/10/29 02:33:49 brianp Exp brianp $ */
d26 3
d1884 1
a1884 1
   if (ctx->Texture.Enabled) {
d1902 1
a1902 1
   if (ctx->Texture.Enabled >= TEXTURE1_1D) {
d1912 2
a1913 1
            ctx->ClipInterpFunc = gl_clip_interp_tex;
a1963 4
   if (ctx->NewState & (NEW_RASTER_OPS | NEW_LIGHTING)) {
      update_clipmask(ctx);
   }

d1971 4
@


3.23
log
@incorporated Keith Whitwell's transformation optimizations
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.22 1998/10/05 00:40:15 brianp Exp $ */
d26 3
d363 1
a363 1
   for (i=0;i<MAX_TEX_SETS;i++) {
d379 1
a379 1
      for (i=0;i<MAX_TEX_SETS;i++) {
d571 5
a579 1

a585 1

d597 1
a597 1
      for (i=0; i<MAX_TEX_SETS; i++) {
d639 1
a639 1
      for (i=0; i<MAX_TEX_SETS; i++)
d646 1
a646 1
      for (i=0; i<MAX_TEX_SETS; i++)
d855 1
a855 1
      for (i=0; i<MAX_TEX_SETS; i++)
d914 1
a914 1
      for (i = 0; i < MAX_TEX_COORD_SETS; i++) {
d927 1
d1943 1
a1943 1
      for (i = 0 ; i < MAX_TEX_SETS ; i++)
d1978 1
a1978 1
         for (texSet=0; texSet<MAX_TEX_SETS; texSet++) {
d2170 1
a2170 1
	 for (i = 0 ; i < MAX_TEX_SETS ; i++) 
@


3.22
log
@added GL_INGR_blend_func_separate extension
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.21 1998/08/23 22:19:30 brianp Exp brianp $ */
d26 3
d139 2
a216 2


d413 2
d423 16
d457 2
a458 2
   ASSIGN_4V( l->Position, 0.0, 0.0, 1.0, 0.0 );
   ASSIGN_3V( l->Direction, 0.0, 0.0, -1.0 );
d494 1
d520 1
a520 1
   s->TexCoordSet = setNum;   /* GL_EXT_multitexture */
d565 1
a565 7
   static GLfloat identity[16] = {
	1.0, 0.0, 0.0, 0.0,
	0.0, 1.0, 0.0, 0.0,
	0.0, 0.0, 1.0, 0.0,
	0.0, 0.0, 0.0, 1.0
   };
   GLuint i;
d569 4
a572 4
      ctx->NewModelViewMatrix = GL_FALSE;
      ctx->ModelViewMatrixType = MATRIX_IDENTITY;
      MEMCPY( ctx->ModelViewMatrix, identity, 16*sizeof(GLfloat) );
      MEMCPY( ctx->ModelViewInv, identity, 16*sizeof(GLfloat) );
d574 5
d581 1
a581 3
      ctx->NewProjectionMatrix = GL_FALSE;
      ctx->ProjectionMatrixType = MATRIX_IDENTITY;
      MEMCPY( ctx->ProjectionMatrix, identity, 16*sizeof(GLfloat) );
d586 4
d592 5
a596 4
         ctx->NewTextureMatrix = GL_FALSE;
         ctx->TextureMatrixType[i] = MATRIX_IDENTITY;
         MEMCPY( ctx->TextureMatrix[i], identity, 16*sizeof(GLfloat) );
         ctx->TextureStackDepth[i] = 0;
d844 2
a845 2
      ctx->Texture.CurrentSet = 0;      /* GL_SGIS_multitexture */
      ctx->Texture.CurrentTransformSet = 0; /* GL_EXT_multitexture */
d949 1
a949 1
      /* GL_EXT_multitexture */
d964 5
d1253 2
d1261 6
d1922 21
d2132 14
d2147 38
a2184 1
   gl_set_vertex_function(ctx);
d2186 1
a2186 1
   ctx->NewState = 0;
@


3.21
log
@added DoViewportMapping to context struct
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.20 1998/08/21 01:49:46 brianp Exp brianp $ */
d5 1
a5 1
 * Version:  3.0
d26 3
d592 4
a595 2
      ctx->Color.BlendSrc = GL_ONE;
      ctx->Color.BlendDst = GL_ZERO;
@


3.20
log
@initialize vertex array state
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.19 1998/07/17 03:23:32 brianp Exp brianp $ */
d26 3
a930 1

d933 1
@


3.19
log
@added Pixel.ScaleOrBiasRGBA field
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.18 1998/06/21 02:00:55 brianp Exp brianp $ */
d26 3
d852 37
@


3.18
log
@cleaned up clip interpolation function code
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.17 1998/06/19 03:13:10 brianp Exp brianp $ */
d26 3
d727 1
@


3.17
log
@evaluator state wasn't fully initialized
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.16 1998/06/07 22:18:52 brianp Exp brianp $ */
d26 3
d1805 1
a1805 1
      ctx->ClipInterpAuxFunc = interpolate_aux;
d1809 2
a1810 5
         case CLIP_FCOLOR_BIT|CLIP_TEXTURE_BIT:
            if(ctx->VB->TexCoordSize==2)
               ctx->ClipInterpAuxFunc = interpolate_aux_color_tex2;
            else
               ctx->ClipInterpAuxFunc = interpolate_aux;
d1813 1
a1813 4
            if(ctx->VB->TexCoordSize==2)
               ctx->ClipInterpAuxFunc = interpolate_aux_tex2;
            else
               ctx->ClipInterpAuxFunc = interpolate_aux;
d1816 1
a1816 1
            ctx->ClipInterpAuxFunc = interpolate_aux_color;
d1819 1
a1819 1
            ctx->ClipInterpAuxFunc = interpolate_aux;
@


3.16
log
@implemented GL_EXT_multitexture extension
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.15 1998/04/01 02:58:28 brianp Exp brianp $ */
d26 3
d487 36
d641 29
d1189 39
@


3.15
log
@updated for v0.24 of 3Dfx/Glide driver
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.14 1998/03/27 03:30:36 brianp Exp brianp $ */
d26 3
d479 2
d735 1
a735 1
      ctx->Texture.CurrentCoordSet = 0; /* GL_SGIS_multitexture */
d801 3
@


3.14
log
@fixed G++ warnings
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.13 1998/03/22 16:42:22 brianp Exp brianp $ */
d26 3
d1604 4
@


3.13
log
@added 8-bit CI->RGBA pixel mapping tables
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.12 1998/03/15 17:55:54 brianp Exp brianp $ */
d26 3
d815 1
a815 1
      ctx->ErrorValue = GL_NO_ERROR;
d868 1
a868 1
   if (depthBits > 8*sizeof(GLdepth)) {
d872 1
a872 1
   if (stencilBits > 8*sizeof(GLstencil)) {
d876 1
a876 1
   if (accumBits > 8*sizeof(GLaccum)) {
d1324 1
d1350 1
d1433 1
a1433 1
   ctx->ErrorValue = GL_NO_ERROR;
d1450 2
a1451 1
   newsize = ctx->Buffer->Width!=buf_width || ctx->Buffer->Height!=buf_height;
@


3.12
log
@added FogMode to context struct
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.11 1998/03/05 02:49:48 brianp Exp brianp $ */
d26 3
d666 4
@


3.11
log
@added an assertion and added better comments in gl_update_state()
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.10 1998/03/01 20:17:03 brianp Exp brianp $ */
d26 3
d1579 15
d1606 1
a1606 1
   if (ctx->Fog.Enabled)		ctx->RasterMask |= FOG_BIT;
d1704 1
@


3.10
log
@removed dead code
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.9 1998/02/20 04:50:09 brianp Exp brianp $ */
d26 3
d1850 11
a1860 3
   if (ctx->Driver.UpdateState) {
      (*ctx->Driver.UpdateState)(ctx);
   }
d1862 5
@


3.9
log
@implemented GL_SGIS_multitexture
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.8 1998/02/13 04:38:05 brianp Exp brianp $ */
d26 3
a713 22
#if 0
      ctx->Texture.EnvMode = GL_MODULATE;
      ASSIGN_4V( ctx->Texture.EnvColor, 0.0, 0.0, 0.0, 0.0 );
      ctx->Texture.TexGenEnabled = 0;
      ctx->Texture.GenModeS = GL_EYE_LINEAR;
      ctx->Texture.GenModeT = GL_EYE_LINEAR;
      ctx->Texture.GenModeR = GL_EYE_LINEAR;
      ctx->Texture.GenModeQ = GL_EYE_LINEAR;
      ASSIGN_4V( ctx->Texture.ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
      ASSIGN_4V( ctx->Texture.ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
      ASSIGN_4V( ctx->Texture.ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
      ASSIGN_4V( ctx->Texture.ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
      ASSIGN_4V( ctx->Texture.EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
      ASSIGN_4V( ctx->Texture.EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
      ASSIGN_4V( ctx->Texture.EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
      ASSIGN_4V( ctx->Texture.EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );

      ctx->Texture.Current1D = ctx->Shared->Default1D;
      ctx->Texture.Current2D = ctx->Shared->Default2D;
      ctx->Texture.Current3D = ctx->Shared->Default3D;

#endif
a788 6

#if JUNK
      ctx->PointsFunc = NULL;
      ctx->LineFunc = NULL;
      ctx->TriangleFunc = NULL;
#endif
@


3.8
log
@optimized blending functions called via BlendFunc function pointer
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.7 1998/02/13 03:23:04 brianp Exp brianp $ */
d26 3
d304 1
d306 1
d317 10
a326 3
   ss->Default1D = gl_alloc_texture_object(ss, 0, 1);
   ss->Default2D = gl_alloc_texture_object(ss, 0, 2);
   ss->Default3D = gl_alloc_texture_object(ss, 0, 3);
d328 1
a328 2
   if (!ss->DisplayList || !ss->TexObjects
       || !ss->Default1D || !ss->Default2D || !ss->Default3D) {
d334 8
a341 6
      if (!ss->Default1D)
         gl_free_texture_object(ss, ss->Default1D);
      if (!ss->Default2D)
         gl_free_texture_object(ss, ss->Default2D);
      if (!ss->Default3D)
         gl_free_texture_object(ss, ss->Default3D);
d434 26
d475 1
a475 1
      /* Modelview matrix stuff */
d482 1
a482 1
      /* Projection matrix stuff */
d490 7
a496 5
      /* Texture matrix stuff */
      ctx->NewTextureMatrix = GL_FALSE;
      ctx->TextureMatrixType = MATRIX_IDENTITY;
      MEMCPY( ctx->TextureMatrix, identity, 16*sizeof(GLfloat) );
      ctx->TextureStackDepth = 0;
d527 1
d530 3
a532 4
      ctx->Current.ByteColor[0] = 255;
      ctx->Current.ByteColor[1] = 255;
      ctx->Current.ByteColor[2] = 255;
      ctx->Current.ByteColor[3] = 255;
d534 6
a540 3
      ctx->Current.RasterIndex = 1;
      ASSIGN_4V( ctx->Current.TexCoord, 0.0, 0.0, 0.0, 1.0 );
      ASSIGN_4V( ctx->Current.RasterColor, 1.0, 1.0, 1.0, 1.0 );
d707 2
d710 2
d732 1
d734 2
d1669 22
a1690 5
   switch(ctx->ClipMask) {
      case CLIP_FCOLOR_BIT|CLIP_TEXTURE_BIT:
         if(ctx->VB->TexCoordSize==2)
            ctx->ClipInterpAuxFunc = interpolate_aux_color_tex2;
         else
d1692 1
a1692 12
         break;
      case CLIP_TEXTURE_BIT:
         if(ctx->VB->TexCoordSize==2)
            ctx->ClipInterpAuxFunc = interpolate_aux_tex2;
         else
            ctx->ClipInterpAuxFunc = interpolate_aux;
         break;
      case CLIP_FCOLOR_BIT:
         ctx->ClipInterpAuxFunc = interpolate_aux_color;
         break;
      default:
         ctx->ClipInterpAuxFunc = interpolate_aux;
d1729 11
a1739 5
      GLboolean sphereGen = ctx->Texture.Enabled
         && ((ctx->Texture.GenModeS==GL_SPHERE_MAP
              && (ctx->Texture.TexGenEnabled & S_BIT))
             || (ctx->Texture.GenModeT==GL_SPHERE_MAP
                 && (ctx->Texture.TexGenEnabled & T_BIT)));
@


3.7
log
@AlphaRef is now a GLubyte
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.6 1998/02/13 03:17:02 brianp Exp brianp $ */
d26 3
d477 1
@


3.6
log
@added basic stereo support
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.5 1998/02/08 20:20:34 brianp Exp brianp $ */
d26 3
d469 1
a469 2
      ctx->Color.AlphaRef = 0.0;
      ctx->Color.AlphaRefUbyte = 0;
@


3.5
log
@ColorMask is now GLubyte[4] instead of GLuint
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.4 1998/02/05 01:10:25 brianp Exp brianp $ */
d26 3
d787 9
a795 8
 * Input:  rgb_flag - GL_TRUE=RGB(A) mode, GL_FALSE=Color Index mode
 *         alpha_flag - alloc software alpha buffers?
 *         db_flag - double buffering?
 *         depth_bits - requested minimum bits per depth buffer value
 *         stencil_bits - requested minimum bits per stencil buffer value
 *         accum_bits - requested minimum bits per accum buffer component
 *         index_bits - number of bits per pixel if rgb_flag==GL_FALSE
 *         red/green/blue/alpha_bits - number of bits per color component
d800 12
a811 11
GLvisual *gl_create_visual( GLboolean rgb_flag,
                            GLboolean alpha_flag,
                            GLboolean db_flag,
                            GLint depth_bits,
                            GLint stencil_bits,
                            GLint accum_bits,
                            GLint index_bits,
                            GLint red_bits,
                            GLint green_bits,
                            GLint blue_bits,
                            GLint alpha_bits )
d815 6
a820 1
   if (depth_bits > 8*sizeof(GLdepth)) {
d824 1
a824 1
   if (stencil_bits > 8*sizeof(GLstencil)) {
d828 1
a828 1
   if (accum_bits > 8*sizeof(GLaccum)) {
d838 12
a849 12
   vis->RGBAflag      = rgb_flag;
   vis->DBflag        = db_flag;

   vis->RedBits   = red_bits;
   vis->GreenBits = green_bits;
   vis->BlueBits  = blue_bits;
   vis->AlphaBits = alpha_flag ? 8*sizeof(GLubyte) : alpha_bits;

   vis->IndexBits   = index_bits;
   vis->DepthBits   = (depth_bits>0) ? 8*sizeof(GLdepth) : 0;
   vis->AccumBits   = (accum_bits>0) ? 8*sizeof(GLaccum) : 0;
   vis->StencilBits = (stencil_bits>0) ? 8*sizeof(GLstencil) : 0;
d852 1
a852 1
   if (alpha_flag) {
d854 1
a854 1
      if (db_flag) {
@


3.4
log
@added John Stone's thread modifications
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.3 1998/02/02 03:09:34 brianp Exp brianp $ */
d26 3
d453 4
a456 1
      ctx->Color.ColorMask = 0xf;
d1482 2
a1483 1
      if (ctx->Color.ColorMask==0xf) {
d1494 4
a1497 4
         GLboolean red   = (ctx->Color.ColorMask & 8) ? GL_TRUE : GL_FALSE;
         GLboolean green = (ctx->Color.ColorMask & 4) ? GL_TRUE : GL_FALSE;
         GLboolean blue  = (ctx->Color.ColorMask & 2) ? GL_TRUE : GL_FALSE;
         GLboolean alpha = (ctx->Color.ColorMask & 1) ? GL_TRUE : GL_FALSE;
@


3.3
log
@added GL_LIGHT_MODEL_COLOR_CONTROL (separate specular color interpolation)
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.2 1998/02/01 16:37:19 brianp Exp brianp $ */
d26 3
d93 1
a93 1
/* A different context may be bound to each thread */
d95 1
a95 2
#include <sys/types.h>
#include <unistd.h>
d97 3
a99 17
#define MAX_THREADS 20
static pid_t ThreadID[MAX_THREADS];
static GLcontext *ThreadContext[MAX_THREADS];
static int NumThreads = 0;

GLcontext *gl_get_thread_context( void )
{
   pid_t id;
   int i;

   id = getpid();

   for (i=0;i<MAX_THREADS;i++) {
      if (ThreadID[i]==id) {
         return ThreadContext[i];
      }
   }
d101 2
a102 2
   /* No context for this thread */
   return NULL;
d105 2
a106 16
static void set_thread_context( GLcontext *ctx )
{
   pid_t id = getpid();
   int i;

   for (i=0;i<NumThreads;i++) {
      if (ThreadID[i]==id) {
         ThreadContext[i] = c;
         return;
      }
   }
   if (i<MAX_THREADS) {
      ThreadID[i] = getpid();
      ThreadContext[i] = c;
      NumThreads++;
   }
d108 1
@


3.2
log
@added GL_EXT_rescale_normal extension
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.1 1998/01/31 23:56:55 brianp Exp brianp $ */
d26 3
d416 1
@


3.1
log
@removed Driver.ClearDepthBuffer function
@
text
@d1 1
a1 1
/* $Id: context.c,v 3.0 1998/01/31 20:49:07 brianp Exp brianp $ */
d26 3
d704 1
@


3.0
log
@initial rev
@
text
@d1 1
a1 1
/* $Id$ */
d25 4
a28 1
 * $Log$
a1410 2
      /*** if scissoring enabled then clearing can cause a problem ***/
      /***(*ctx->Driver.ClearDepthBuffer)( ctx );***/
a1773 1
      ctx->Driver.ClearDepthBuffer = gl_clear_depth_buffer;
@
