Major rework of tnl module
[mesa.git] / src / mesa / main / attrib.c
index 9cf1d3c5099932fe0c6edd27811bccb98972b497..6158a64869cb41a888b4b33d78399433d4a4d1b3 100644 (file)
@@ -1,21 +1,21 @@
-/* $Id: attrib.c,v 1.28 2000/09/28 22:44:30 brianp Exp $ */
+/* $Id: attrib.c,v 1.39 2000/12/26 05:09:27 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.3
- * 
+ * Version:  3.5
+ *
  * Copyright (C) 1999-2000  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
 #include "context.h"
 #include "enable.h"
 #include "enums.h"
+#include "matrix.h"
 #include "mem.h"
 #include "simple_list.h"
 #include "texstate.h"
-#include "types.h"
+#include "mtypes.h"
 #endif
 
 
@@ -84,12 +85,10 @@ copy_texobj_state( struct gl_texture_object *dest,
    dest->MaxLod = src->MaxLod;
    dest->BaseLevel = src->BaseLevel;
    dest->MaxLevel = src->MaxLevel;
-   dest->P = src->P;
-   dest->M = src->M;
-   dest->MinMagThresh = src->MinMagThresh;
+   dest->_MaxLevel = src->_MaxLevel;
+   dest->_MaxLambda = src->_MaxLambda;
    dest->Palette = src->Palette;
    dest->Complete = src->Complete;
-   dest->SampleFunc = src->SampleFunc;
 }
 
 
@@ -101,7 +100,7 @@ _mesa_PushAttrib(GLbitfield mask)
    struct gl_attrib_node *head;
 
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushAttrib");
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE&VERBOSE_API)
       fprintf(stderr, "glPushAttrib %x\n", (int)mask);
@@ -137,6 +136,7 @@ _mesa_PushAttrib(GLbitfield mask)
 
    if (mask & GL_CURRENT_BIT) {
       struct gl_current_attrib *attr;
+      FLUSH_CURRENT( ctx, 0 );
       attr = MALLOC_STRUCT( gl_current_attrib );
       MEMCPY( attr, &ctx->Current, sizeof(struct gl_current_attrib) );
       newnode = new_attrib_node( GL_CURRENT_BIT );
@@ -255,6 +255,7 @@ _mesa_PushAttrib(GLbitfield mask)
 
    if (mask & GL_LIGHTING_BIT) {
       struct gl_light_attrib *attr;
+      FLUSH_CURRENT(ctx, 0);   /* flush material changes */
       attr = MALLOC_STRUCT( gl_light_attrib );
       MEMCPY( attr, &ctx->Light, sizeof(struct gl_light_attrib) );
       newnode = new_attrib_node( GL_LIGHTING_BIT );
@@ -348,17 +349,18 @@ _mesa_PushAttrib(GLbitfield mask)
       GLuint u;
       /* Take care of texture object reference counters */
       for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-        ctx->Texture.Unit[u].CurrentD[1]->RefCount++;
-        ctx->Texture.Unit[u].CurrentD[2]->RefCount++;
-        ctx->Texture.Unit[u].CurrentD[3]->RefCount++;
+        ctx->Texture.Unit[u].Current1D->RefCount++;
+        ctx->Texture.Unit[u].Current2D->RefCount++;
+        ctx->Texture.Unit[u].Current3D->RefCount++;
+        ctx->Texture.Unit[u].CurrentCubeMap->RefCount++;
       }
       attr = MALLOC_STRUCT( gl_texture_attrib );
       MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) );
       /* copy state of the currently bound texture objects */
       for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-         copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].CurrentD[1]);
-         copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].CurrentD[2]);
-         copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].CurrentD[3]);
+         copy_texobj_state(&attr->Unit[u].Saved1D, attr->Unit[u].Current1D);
+         copy_texobj_state(&attr->Unit[u].Saved2D, attr->Unit[u].Current2D);
+         copy_texobj_state(&attr->Unit[u].Saved3D, attr->Unit[u].Current3D);
          copy_texobj_state(&attr->Unit[u].SavedCubeMap, attr->Unit[u].CurrentCubeMap);
       }
       newnode = new_attrib_node( GL_TEXTURE_BIT );
@@ -543,9 +545,7 @@ _mesa_PopAttrib(void)
 {
    struct gl_attrib_node *attr, *next;
    GET_CURRENT_CONTEXT(ctx);
-
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopAttrib");
-
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (ctx->AttribStackDepth==0) {
       gl_error( ctx, GL_STACK_UNDERFLOW, "glPopAttrib" );
@@ -563,17 +563,19 @@ _mesa_PopAttrib(void)
       switch (attr->kind) {
          case GL_ACCUM_BUFFER_BIT:
             MEMCPY( &ctx->Accum, attr->data, sizeof(struct gl_accum_attrib) );
+           ctx->NewState |= _NEW_ACCUM;
             break;
          case GL_COLOR_BUFFER_BIT:
             {
                GLenum oldDrawBuffer = ctx->Color.DrawBuffer;
                GLenum oldAlphaFunc = ctx->Color.AlphaFunc;
-               GLubyte oldAlphaRef = ctx->Color.AlphaRef;
+               GLchan oldAlphaRef = ctx->Color.AlphaRef;
                GLenum oldBlendSrc = ctx->Color.BlendSrcRGB;
                GLenum oldBlendDst = ctx->Color.BlendDstRGB;
               GLenum oldLogicOp = ctx->Color.LogicOp;
                MEMCPY( &ctx->Color, attr->data,
                        sizeof(struct gl_colorbuffer_attrib) );
+              ctx->NewState |= _NEW_COLOR;
                if (ctx->Color.DrawBuffer != oldDrawBuffer) {
                   _mesa_DrawBuffer( ctx->Color.DrawBuffer);
                }
@@ -587,16 +589,16 @@ _mesa_PopAttrib(void)
                  ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
                }
                if (ctx->Visual.RGBAflag) {
-                  GLubyte r = (GLint) (ctx->Color.ClearColor[0] * 255.0F);
-                  GLubyte g = (GLint) (ctx->Color.ClearColor[1] * 255.0F);
-                  GLubyte b = (GLint) (ctx->Color.ClearColor[2] * 255.0F);
-                  GLubyte a = (GLint) (ctx->Color.ClearColor[3] * 255.0F);
+                  GLchan r = (GLint) (ctx->Color.ClearColor[0] * CHAN_MAXF);
+                  GLchan g = (GLint) (ctx->Color.ClearColor[1] * CHAN_MAXF);
+                  GLchan b = (GLint) (ctx->Color.ClearColor[2] * CHAN_MAXF);
+                  GLchan a = (GLint) (ctx->Color.ClearColor[3] * CHAN_MAXF);
                   (*ctx->Driver.ClearColor)( ctx, r, g, b, a );
                   if ((ctx->Color.AlphaFunc != oldAlphaFunc ||
                        ctx->Color.AlphaRef != oldAlphaRef) &&
                       ctx->Driver.AlphaFunc)
                      (*ctx->Driver.AlphaFunc)( ctx, ctx->Color.AlphaFunc,
-                                               ctx->Color.AlphaRef / 255.0F);
+                                              ctx->Color.AlphaRef / CHAN_MAXF);
                   if (ctx->Driver.ColorMask) {
                      (*ctx->Driver.ColorMask)(ctx,
                                               ctx->Color.ColorMask[0],
@@ -611,6 +613,7 @@ _mesa_PopAttrib(void)
             }
             break;
          case GL_CURRENT_BIT:
+           FLUSH_CURRENT( ctx, 0 );
             MEMCPY( &ctx->Current, attr->data,
                    sizeof(struct gl_current_attrib) );
             break;
@@ -622,6 +625,7 @@ _mesa_PopAttrib(void)
                GLfloat oldDepthClear = ctx->Depth.Clear;
                MEMCPY( &ctx->Depth, attr->data,
                        sizeof(struct gl_depthbuffer_attrib) );
+              ctx->NewState |= _NEW_DEPTH;
                if (ctx->Depth.Test != oldDepthTest && ctx->Driver.Enable)
                   (*ctx->Driver.Enable)( ctx, GL_DEPTH_TEST, ctx->Depth.Test);
                if (ctx->Depth.Func != oldDepthFunc && ctx->Driver.DepthFunc)
@@ -637,15 +641,18 @@ _mesa_PopAttrib(void)
                const struct gl_enable_attrib *enable;
                enable = (const struct gl_enable_attrib *) attr->data;
                pop_enable_group(ctx, enable);
+              ctx->NewState |= _NEW_ALL;
             }
             break;
          case GL_EVAL_BIT:
             MEMCPY( &ctx->Eval, attr->data, sizeof(struct gl_eval_attrib) );
+           ctx->NewState |= _NEW_EVAL;
             break;
          case GL_FOG_BIT:
             {
                GLboolean anyChange = (GLboolean) (memcmp( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) ) != 0);
                MEMCPY( &ctx->Fog, attr->data, sizeof(struct gl_fog_attrib) );
+              ctx->NewState |= _NEW_FOG;
                if (anyChange && ctx->Driver.Fogfv) {
                   const GLfloat mode = (GLfloat) ctx->Fog.Mode;
                   const GLfloat density = ctx->Fog.Density;
@@ -659,12 +666,13 @@ _mesa_PopAttrib(void)
                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_INDEX, &index );
                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_COLOR, ctx->Fog.Color );
                }
-              ctx->Enabled &= ~ENABLE_FOG;
-              if (ctx->Fog.Enabled) ctx->Enabled |= ENABLE_FOG;
+              ctx->_Enabled &= ~ENABLE_FOG;
+              if (ctx->Fog.Enabled) ctx->_Enabled |= ENABLE_FOG;
             }
             break;
          case GL_HINT_BIT:
             MEMCPY( &ctx->Hint, attr->data, sizeof(struct gl_hint_attrib) );
+           ctx->NewState |= _NEW_HINT;
             if (ctx->Driver.Hint) {
                (*ctx->Driver.Hint)( ctx, GL_PERSPECTIVE_CORRECTION_HINT,
                                     ctx->Hint.PerspectiveCorrection );
@@ -679,6 +687,7 @@ _mesa_PopAttrib(void)
             break;
          case GL_LIGHTING_BIT:
             MEMCPY( &ctx->Light, attr->data, sizeof(struct gl_light_attrib) );
+           ctx->NewState |= _NEW_LIGHT;
             if (ctx->Driver.Enable) {
                GLuint i;
                for (i = 0; i < MAX_LIGHTS; i++) {
@@ -688,17 +697,18 @@ _mesa_PopAttrib(void)
                (*ctx->Driver.Enable)( ctx, GL_LIGHTING, ctx->Light.Enabled );
             }
             if (ctx->Light.ShadeModel == GL_FLAT)
-               ctx->TriangleCaps |= DD_FLATSHADE;
+               ctx->_TriangleCaps |= DD_FLATSHADE;
             else
-               ctx->TriangleCaps &= ~DD_FLATSHADE;
+               ctx->_TriangleCaps &= ~DD_FLATSHADE;
             if (ctx->Driver.ShadeModel)
                (*ctx->Driver.ShadeModel)(ctx, ctx->Light.ShadeModel);
-           ctx->Enabled &= ~ENABLE_LIGHT;
-           if (ctx->Light.Enabled && !is_empty_list(&ctx->Light.EnabledList))
-              ctx->Enabled |= ENABLE_LIGHT;
+           ctx->_Enabled &= ~ENABLE_LIGHT;
+           if (ctx->Light.Enabled)
+              ctx->_Enabled |= ENABLE_LIGHT;
             break;
          case GL_LINE_BIT:
             MEMCPY( &ctx->Line, attr->data, sizeof(struct gl_line_attrib) );
+           ctx->NewState |= _NEW_LINE;
             if (ctx->Driver.Enable) {
                (*ctx->Driver.Enable)( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
                (*ctx->Driver.Enable)( ctx, GL_LINE_STIPPLE, ctx->Line.StippleFlag );
@@ -714,9 +724,11 @@ _mesa_PopAttrib(void)
             break;
          case GL_PIXEL_MODE_BIT:
             MEMCPY( &ctx->Pixel, attr->data, sizeof(struct gl_pixel_attrib) );
+           ctx->NewState |= _NEW_PIXEL;
             break;
          case GL_POINT_BIT:
             MEMCPY( &ctx->Point, attr->data, sizeof(struct gl_point_attrib) );
+           ctx->NewState |= _NEW_POINT;
             if (ctx->Driver.Enable)
                (*ctx->Driver.Enable)( ctx, GL_POINT_SMOOTH, ctx->Point.SmoothFlag );
             break;
@@ -726,6 +738,7 @@ _mesa_PopAttrib(void)
                GLenum oldBackMode = ctx->Polygon.BackMode;
                MEMCPY( &ctx->Polygon, attr->data,
                        sizeof(struct gl_polygon_attrib) );
+              ctx->NewState |= _NEW_POLYGON;
                if ((ctx->Polygon.FrontMode != oldFrontMode ||
                     ctx->Polygon.BackMode != oldBackMode) &&
                    ctx->Driver.PolygonMode) {
@@ -744,12 +757,14 @@ _mesa_PopAttrib(void)
             break;
         case GL_POLYGON_STIPPLE_BIT:
            MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
-           if (ctx->Driver.PolygonStipple) 
+           ctx->NewState |= _NEW_POLYGONSTIPPLE;
+           if (ctx->Driver.PolygonStipple)
               ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
            break;
          case GL_SCISSOR_BIT:
             MEMCPY( &ctx->Scissor, attr->data,
                    sizeof(struct gl_scissor_attrib) );
+           ctx->NewState |= _NEW_SCISSOR;
             if (ctx->Driver.Enable)
                (*ctx->Driver.Enable)( ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled );
            if (ctx->Driver.Scissor)
@@ -759,6 +774,7 @@ _mesa_PopAttrib(void)
          case GL_STENCIL_BUFFER_BIT:
             MEMCPY( &ctx->Stencil, attr->data,
                    sizeof(struct gl_stencil_attrib) );
+           ctx->NewState |= _NEW_STENCIL;
             if (ctx->Driver.StencilFunc)
                (*ctx->Driver.StencilFunc)( ctx, ctx->Stencil.Function,
                                    ctx->Stencil.Ref, ctx->Stencil.ValueMask);
@@ -771,57 +787,60 @@ _mesa_PopAttrib(void)
                (*ctx->Driver.ClearStencil)( ctx, ctx->Stencil.Clear );
             if (ctx->Driver.Enable)
                (*ctx->Driver.Enable)( ctx, GL_STENCIL_TEST, ctx->Stencil.Enabled );
-           ctx->TriangleCaps &= ~DD_STENCIL;
+           ctx->_TriangleCaps &= ~DD_STENCIL;
            if (ctx->Stencil.Enabled)
-              ctx->TriangleCaps |= DD_STENCIL;
+              ctx->_TriangleCaps |= DD_STENCIL;
 
             break;
          case GL_TRANSFORM_BIT:
             MEMCPY( &ctx->Transform, attr->data,
                    sizeof(struct gl_transform_attrib) );
+           ctx->NewState |= _NEW_TRANSFORM;
             if (ctx->Driver.Enable) {
                (*ctx->Driver.Enable)( ctx, GL_NORMALIZE, ctx->Transform.Normalize );
                (*ctx->Driver.Enable)( ctx, GL_RESCALE_NORMAL_EXT, ctx->Transform.RescaleNormals );
             }
-           ctx->Enabled &= ~(ENABLE_NORMALIZE|ENABLE_RESCALE);
-           if (ctx->Transform.Normalize) ctx->Enabled |= ENABLE_NORMALIZE;
-           if (ctx->Transform.RescaleNormals) ctx->Enabled |= ENABLE_RESCALE;
+           ctx->_Enabled &= ~(ENABLE_NORMALIZE|ENABLE_RESCALE);
+           if (ctx->Transform.Normalize) ctx->_Enabled |= ENABLE_NORMALIZE;
+           if (ctx->Transform.RescaleNormals) ctx->_Enabled |= ENABLE_RESCALE;
             break;
          case GL_TEXTURE_BIT:
             /* Take care of texture object reference counters */
             {
                GLuint u;
                for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-                 ctx->Texture.Unit[u].CurrentD[1]->RefCount--;
-                 ctx->Texture.Unit[u].CurrentD[2]->RefCount--;
-                 ctx->Texture.Unit[u].CurrentD[3]->RefCount--;
+                 ctx->Texture.Unit[u].Current1D->RefCount--;
+                 ctx->Texture.Unit[u].Current2D->RefCount--;
+                 ctx->Texture.Unit[u].Current3D->RefCount--;
+                 ctx->Texture.Unit[u].CurrentCubeMap->RefCount--;
                }
                MEMCPY( &ctx->Texture, attr->data,
                        sizeof(struct gl_texture_attrib) );
+              ctx->NewState |= _NEW_TEXTURE;
                /* restore state of the currently bound texture objects */
                for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-                  copy_texobj_state( ctx->Texture.Unit[u].CurrentD[1],
+                  copy_texobj_state( ctx->Texture.Unit[u].Current1D,
                                      &(ctx->Texture.Unit[u].Saved1D) );
-                  copy_texobj_state( ctx->Texture.Unit[u].CurrentD[2],
+                  copy_texobj_state( ctx->Texture.Unit[u].Current2D,
                                      &(ctx->Texture.Unit[u].Saved2D) );
-                  copy_texobj_state( ctx->Texture.Unit[u].CurrentD[3],
+                  copy_texobj_state( ctx->Texture.Unit[u].Current3D,
                                      &(ctx->Texture.Unit[u].Saved3D) );
                   copy_texobj_state( ctx->Texture.Unit[u].CurrentCubeMap,
                                      &(ctx->Texture.Unit[u].SavedCubeMap) );
 
-                  gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[1] );
-                  gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[2] );
-                  gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentD[3] );
-                  gl_put_texobj_on_dirty_list( ctx, ctx->Texture.Unit[u].CurrentCubeMap );
-
+                  ctx->Texture.Unit[u].Current1D->Complete = GL_FALSE;
+                  ctx->Texture.Unit[u].Current2D->Complete = GL_FALSE;
+                  ctx->Texture.Unit[u].Current3D->Complete = GL_FALSE;
+                  ctx->Texture.Unit[u].CurrentCubeMap->Complete = GL_FALSE;
                }
             }
             break;
-         case GL_VIEWPORT_BIT: 
+         case GL_VIEWPORT_BIT:
         {
-           struct gl_viewport_attrib *v = 
+           struct gl_viewport_attrib *v =
               (struct gl_viewport_attrib *)attr->data;
-           
+
+           ctx->NewState |= _NEW_VIEWPORT;
            _mesa_Viewport( v->X, v->Y, v->Width, v->Height );
            _mesa_DepthRange( v->Near, v->Far );
            break;
@@ -836,9 +855,6 @@ _mesa_PopAttrib(void)
       FREE( attr );
       attr = next;
    }
-
-   ctx->NewState = NEW_ALL;
-   ctx->ImageTransferState = UPDATE_IMAGE_TRANSFER_STATE;
 }
 
 
@@ -853,7 +869,7 @@ _mesa_PushClientAttrib(GLbitfield mask)
    struct gl_attrib_node *head;
 
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushClientAttrib");
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (ctx->ClientAttribStackDepth>=MAX_CLIENT_ATTRIB_STACK_DEPTH) {
       gl_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
@@ -904,7 +920,7 @@ _mesa_PopClientAttrib(void)
    struct gl_attrib_node *attr, *next;
 
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopClientAttrib");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (ctx->ClientAttribStackDepth==0) {
       gl_error( ctx, GL_STACK_UNDERFLOW, "glPopClientAttrib" );
@@ -919,14 +935,17 @@ _mesa_PopClientAttrib(void)
          case GL_CLIENT_PACK_BIT:
             MEMCPY( &ctx->Pack, attr->data,
                     sizeof(struct gl_pixelstore_attrib) );
+           ctx->NewState = _NEW_PACKUNPACK;
             break;
          case GL_CLIENT_UNPACK_BIT:
             MEMCPY( &ctx->Unpack, attr->data,
                     sizeof(struct gl_pixelstore_attrib) );
+           ctx->NewState = _NEW_PACKUNPACK;
             break;
          case GL_CLIENT_VERTEX_ARRAY_BIT:
             MEMCPY( &ctx->Array, attr->data,
                    sizeof(struct gl_array_attrib) );
+           ctx->NewState = _NEW_ARRAY;
             break;
          default:
             gl_problem( ctx, "Bad attrib flag in PopClientAttrib");
@@ -939,7 +958,6 @@ _mesa_PopClientAttrib(void)
       attr = next;
    }
 
-   ctx->NewState = NEW_ALL;
 }