work on GL_SGI_color_table
[mesa.git] / src / mesa / main / context.c
index eb3b7a8121b5dc452ac5dfef9333b01dc6790a1a..9ff18aca609b5ae3ec156d15521d6152c732d94a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: context.c,v 1.44 2000/03/03 17:47:39 brianp Exp $ */
+/* $Id: context.c,v 1.59 2000/04/12 00:27:37 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -267,18 +267,23 @@ static void print_timings( GLcontext *ctx )
  * 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 *
+_mesa_create_visual( GLboolean rgbFlag,
+                     GLboolean alphaFlag,
+                     GLboolean dbFlag,
+                     GLboolean stereoFlag,
+                     GLint redBits,
+                     GLint greenBits,
+                     GLint blueBits,
+                     GLint alphaBits,
+                     GLint indexBits,
+                     GLint depthBits,
+                     GLint stencilBits,
+                     GLint accumRedBits,
+                     GLint accumGreenBits,
+                     GLint accumBlueBits,
+                     GLint accumAlphaBits,
+                     GLint numSamples )
 {
    GLvisual *vis;
 
@@ -294,7 +299,16 @@ GLvisual *gl_create_visual( GLboolean rgbFlag,
    if (stencilBits < 0 || stencilBits > (GLint) (8 * sizeof(GLstencil))) {
       return NULL;
    }
-   if (accumBits < 0 || accumBits > (GLint) (8 * sizeof(GLaccum))) {
+   if (accumRedBits < 0 || accumRedBits > (GLint) (8 * sizeof(GLaccum))) {
+      return NULL;
+   }
+   if (accumGreenBits < 0 || accumGreenBits > (GLint) (8 * sizeof(GLaccum))) {
+      return NULL;
+   }
+   if (accumBlueBits < 0 || accumBlueBits > (GLint) (8 * sizeof(GLaccum))) {
+      return NULL;
+   }
+   if (accumAlphaBits < 0 || accumAlphaBits > (GLint) (8 * sizeof(GLaccum))) {
       return NULL;
    }
 
@@ -311,10 +325,13 @@ GLvisual *gl_create_visual( GLboolean rgbFlag,
    vis->BlueBits   = blueBits;
    vis->AlphaBits  = alphaFlag ? (8 * sizeof(GLubyte)) : alphaBits;
 
-   vis->IndexBits   = indexBits;
-   vis->DepthBits   = depthBits;
-   vis->AccumBits   = (accumBits > 0) ? (8 * sizeof(GLaccum)) : 0;
-   vis->StencilBits = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
+   vis->IndexBits      = indexBits;
+   vis->DepthBits      = depthBits;
+   vis->AccumRedBits   = (accumRedBits > 0) ? (8 * sizeof(GLaccum)) : 0;
+   vis->AccumGreenBits = (accumGreenBits > 0) ? (8 * sizeof(GLaccum)) : 0;
+   vis->AccumBlueBits  = (accumBlueBits > 0) ? (8 * sizeof(GLaccum)) : 0;
+   vis->AccumAlphaBits = (accumAlphaBits > 0) ? (8 * sizeof(GLaccum)) : 0;
+   vis->StencilBits    = (stencilBits > 0) ? (8 * sizeof(GLstencil)) : 0;
 
    vis->SoftwareAlpha = alphaFlag;
 
@@ -334,10 +351,38 @@ GLvisual *gl_create_visual( GLboolean rgbFlag,
 }
 
 
+/* This function should no longer be used. Use _mesa_create_visual() instead */
+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 )
+{
+   return _mesa_create_visual(rgbFlag, alphaFlag, dbFlag, stereoFlag,
+                              redBits, greenBits, blueBits, alphaBits,
+                              indexBits, depthBits, stencilBits,
+                              accumBits, accumBits, accumBits, accumBits, 0);
+}
+
 
+void
+_mesa_destroy_visual( GLvisual *vis )
+{
+   FREE(vis);
+}
+
+
+/* obsolete */
 void gl_destroy_visual( GLvisual *vis )
 {
-   FREE( vis );
+   _mesa_destroy_visual(vis);
 }
 
 
@@ -381,7 +426,9 @@ GLframebuffer *gl_create_framebuffer( GLvisual *visual,
    }
    if (softwareAccum) {
       assert(visual->RGBAflag);
-      assert(visual->AccumBits > 0);
+      assert(visual->AccumRedBits > 0);
+      assert(visual->AccumGreenBits > 0);
+      assert(visual->AccumBlueBits > 0);
    }
    if (softwareAlpha) {
       assert(visual->RGBAflag);
@@ -405,8 +452,8 @@ GLframebuffer *gl_create_framebuffer( GLvisual *visual,
 void gl_destroy_framebuffer( GLframebuffer *buffer )
 {
    if (buffer) {
-      if (buffer->Depth) {
-         FREE( buffer->Depth );
+      if (buffer->DepthBuffer) {
+         FREE( buffer->DepthBuffer );
       }
       if (buffer->Accum) {
          FREE( buffer->Accum );
@@ -459,7 +506,7 @@ static void one_time_init( void )
       gl_init_clip();
       gl_init_eval();
       _mesa_init_fog();
-      gl_init_math();
+      _mesa_init_math();
       gl_init_lists();
       gl_init_shade();
       gl_init_texture();
@@ -740,6 +787,12 @@ static void init_color_table( struct gl_color_table *p )
    p->Size = 1;
    p->IntFormat = GL_RGBA;
    p->Format = GL_RGBA;
+   p->RedSize = 8;
+   p->GreenSize = 8;
+   p->BlueSize = 8;
+   p->AlphaSize = 8;
+   p->IntensitySize = 0;
+   p->LuminanceSize = 0;
 }
 
 
@@ -775,7 +828,7 @@ static void init_attrib_groups( GLcontext *ctx )
    gl_matrix_alloc_inv( &ctx->ModelView );
 
    ctx->ModelViewStackDepth = 0;
-   for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
+   for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
       gl_matrix_ctr( &ctx->ModelViewStack[i] );
       gl_matrix_alloc_inv( &ctx->ModelViewStack[i] );
    }
@@ -792,7 +845,7 @@ static void init_attrib_groups( GLcontext *ctx )
    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++) {
+   for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
       gl_matrix_ctr( &ctx->ProjectionStack[i] );
       gl_matrix_alloc_inv( &ctx->ProjectionStack[i] );
    }
@@ -801,11 +854,18 @@ static void init_attrib_groups( GLcontext *ctx )
    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++) {
+      for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
          ctx->TextureStack[i][j].inv = 0;
       }
    }
 
+   /* Color matrix */
+   gl_matrix_ctr(&ctx->ColorMatrix);
+   ctx->ColorStackDepth = 0;
+   for (j = 0; j < MAX_COLOR_STACK_DEPTH - 1; j++) {
+      gl_matrix_ctr(&ctx->ColorStack[j]);
+   }
+
    /* Accumulate buffer group */
    ASSIGN_4V( ctx->Accum.ClearColor, 0.0, 0.0, 0.0, 0.0 );
 
@@ -864,6 +924,7 @@ static void init_attrib_groups( GLcontext *ctx )
    ctx->Depth.Clear = 1.0;
    ctx->Depth.Func = GL_LESS;
    ctx->Depth.Mask = GL_TRUE;
+   ctx->Depth.OcclusionTest = GL_FALSE;
 
    /* Evaluators group */
    ctx->Eval.Map1Color4 = GL_FALSE;
@@ -941,10 +1002,36 @@ static void init_attrib_groups( GLcontext *ctx )
    ctx->Hint.Fog = GL_DONT_CARE;
 
    ctx->Hint.AllowDrawWin = GL_TRUE;
-   ctx->Hint.AllowDrawSpn = GL_TRUE;
+   ctx->Hint.AllowDrawFrg = GL_TRUE;
    ctx->Hint.AllowDrawMem = GL_TRUE;
    ctx->Hint.StrictLighting = GL_TRUE;
 
+   /* Histogram group */
+   ctx->Histogram.Width = 0;
+   ctx->Histogram.Format = GL_RGBA;
+   ctx->Histogram.Sink = GL_FALSE;
+   ctx->Histogram.RedSize       = 0xffffffff;
+   ctx->Histogram.GreenSize     = 0xffffffff;
+   ctx->Histogram.BlueSize      = 0xffffffff;
+   ctx->Histogram.AlphaSize     = 0xffffffff;
+   ctx->Histogram.LuminanceSize = 0xffffffff;
+   for (i = 0; i < HISTOGRAM_TABLE_SIZE; i++) {
+      ctx->Histogram.Count[i][0] = 0;
+      ctx->Histogram.Count[i][1] = 0;
+      ctx->Histogram.Count[i][2] = 0;
+      ctx->Histogram.Count[i][3] = 0;
+   }
+
+   /* Min/Max group */
+   ctx->MinMax.Format = GL_RGBA;
+   ctx->MinMax.Sink = GL_FALSE;
+   ctx->MinMax.Min[RCOMP] = 1000;    ctx->MinMax.Max[RCOMP] = -1000;
+   ctx->MinMax.Min[GCOMP] = 1000;    ctx->MinMax.Max[GCOMP] = -1000;
+   ctx->MinMax.Min[BCOMP] = 1000;    ctx->MinMax.Max[BCOMP] = -1000;
+   ctx->MinMax.Min[ACOMP] = 1000;    ctx->MinMax.Max[ACOMP] = -1000;
+
+
+
    /* Pipeline */
    gl_pipeline_init( ctx );
    gl_cva_init( ctx );
@@ -1041,6 +1128,30 @@ static void init_attrib_groups( GLcontext *ctx )
    ctx->Pixel.MapGtoG[0] = 0.0;
    ctx->Pixel.MapBtoB[0] = 0.0;
    ctx->Pixel.MapAtoA[0] = 0.0;
+   ctx->Pixel.HistogramEnabled = GL_FALSE;
+   ctx->Pixel.MinMaxEnabled = GL_FALSE;
+   ctx->Pixel.PixelTextureEnabled = GL_FALSE;
+   ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
+   ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
+   ctx->Pixel.PostColorMatrixRedBias = 0.0;
+   ctx->Pixel.PostColorMatrixRedScale = 1.0;
+   ctx->Pixel.PostColorMatrixGreenBias = 0.0;
+   ctx->Pixel.PostColorMatrixGreenScale = 1.0;
+   ctx->Pixel.PostColorMatrixBlueBias = 0.0;
+   ctx->Pixel.PostColorMatrixBlueScale = 1.0;
+   ctx->Pixel.PostColorMatrixAlphaBias = 0.0;
+   ctx->Pixel.PostColorMatrixAlphaScale = 1.0;
+   ctx->Pixel.ColorTableScale[0] = 1.0F;
+   ctx->Pixel.ColorTableScale[1] = 1.0F;
+   ctx->Pixel.ColorTableScale[2] = 1.0F;
+   ctx->Pixel.ColorTableScale[3] = 1.0F;
+   ctx->Pixel.ColorTableBias[0] = 0.0F;
+   ctx->Pixel.ColorTableBias[1] = 0.0F;
+   ctx->Pixel.ColorTableBias[2] = 0.0F;
+   ctx->Pixel.ColorTableBias[3] = 0.0F;
+   ctx->Pixel.ColorTableEnabled = GL_FALSE;
+   ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
+   ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
 
    /* Point group */
    ctx->Point.SmoothFlag = GL_FALSE;
@@ -1204,6 +1315,23 @@ static void init_attrib_groups( GLcontext *ctx )
    ctx->AttribStackDepth = 0;
    ctx->ClientAttribStackDepth = 0;
 
+   /* 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;
+
+   /* Color tables */
+   init_color_table(&ctx->ColorTable);
+   init_color_table(&ctx->ProxyColorTable);
+   init_color_table(&ctx->PostConvolutionColorTable);
+   init_color_table(&ctx->ProxyPostConvolutionColorTable);
+   init_color_table(&ctx->PostColorMatrixColorTable);
+   init_color_table(&ctx->ProxyPostColorMatrixColorTable);
+
    /* Miscellaneous */
    ctx->NewState = NEW_ALL;
    ctx->RenderMode = GL_RENDER;
@@ -1215,18 +1343,11 @@ static void init_attrib_groups( GLcontext *ctx )
    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;
+   ctx->OcclusionResult = GL_FALSE;
+   ctx->OcclusionResultSaved = GL_FALSE;
 
    /* For debug/development only */
    ctx->NoRaster = getenv("MESA_NO_RASTER") ? GL_TRUE : GL_FALSE;
@@ -1275,9 +1396,9 @@ static GLboolean alloc_proxy_textures( GLcontext *ctx )
 
    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();
+      ctx->Texture.Proxy1D->Image[i] = _mesa_alloc_texture_image();
+      ctx->Texture.Proxy2D->Image[i] = _mesa_alloc_texture_image();
+      ctx->Texture.Proxy3D->Image[i] = _mesa_alloc_texture_image();
       if (!ctx->Texture.Proxy1D->Image[i]
           || !ctx->Texture.Proxy2D->Image[i]
           || !ctx->Texture.Proxy3D->Image[i]) {
@@ -1287,13 +1408,13 @@ static GLboolean alloc_proxy_textures( GLcontext *ctx )
    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]);
+            _mesa_free_texture_image(ctx->Texture.Proxy1D->Image[i]);
          }
          if (ctx->Texture.Proxy2D->Image[i]) {
-            gl_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
+            _mesa_free_texture_image(ctx->Texture.Proxy2D->Image[i]);
          }
          if (ctx->Texture.Proxy3D->Image[i]) {
-            gl_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
+            _mesa_free_texture_image(ctx->Texture.Proxy3D->Image[i]);
          }
       }
       gl_free_texture_object(NULL, ctx->Texture.Proxy1D);
@@ -1392,8 +1513,8 @@ GLboolean gl_initialize_context_data( GLcontext *ctx,
    }
 
    /* setup API dispatch tables */
-   ctx->Exec = CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
-   ctx->Save = CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
+   ctx->Exec = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
+   ctx->Save = (struct _glapi_table *) CALLOC(_glapi_get_dispatch_table_size() * sizeof(void *));
    if (!ctx->Exec || !ctx->Save) {
       free_shared_state(ctx, ctx->Shared);
       FREE(ctx->VB);
@@ -1446,8 +1567,8 @@ GLcontext *gl_create_context( GLvisual *visual,
  */
 void gl_free_context_data( GLcontext *ctx )
 {
-   GLuint i;
    struct gl_shine_tab *s, *tmps;
+   GLuint i, j;
 
    /* if we're destroying the current context, unbind it first */
    if (ctx == gl_get_current_context()) {
@@ -1461,13 +1582,19 @@ void gl_free_context_data( GLcontext *ctx )
 #endif
 
    gl_matrix_dtr( &ctx->ModelView );
-   for (i = 0 ; i < MAX_MODELVIEW_STACK_DEPTH ; i++) {
+   for (i = 0; i < MAX_MODELVIEW_STACK_DEPTH - 1; i++) {
       gl_matrix_dtr( &ctx->ModelViewStack[i] );
    }
    gl_matrix_dtr( &ctx->ProjectionMatrix );
-   for (i = 0 ; i < MAX_PROJECTION_STACK_DEPTH ; i++) {
+   for (i = 0; i < MAX_PROJECTION_STACK_DEPTH - 1; i++) {
       gl_matrix_dtr( &ctx->ProjectionStack[i] );
    }
+   for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
+      gl_matrix_dtr( &ctx->TextureMatrix[i] );
+      for (j = 0; j < MAX_TEXTURE_STACK_DEPTH - 1; j++) {
+         gl_matrix_dtr( &ctx->TextureStack[i][j] );
+      }
+   }
 
    FREE( ctx->PB );