Major rework of tnl module
[mesa.git] / src / mesa / main / attrib.c
index b6c5174def79a6e5d892fb20815d85042d395e34..6158a64869cb41a888b4b33d78399433d4a4d1b3 100644 (file)
@@ -1,21 +1,21 @@
-/* $Id: attrib.c,v 1.34 2000/11/16 21:05:34 keithw Exp $ */
+/* $Id: attrib.c,v 1.39 2000/12/26 05:09:27 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * 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
@@ -38,7 +38,7 @@
 #include "mem.h"
 #include "simple_list.h"
 #include "texstate.h"
-#include "types.h"
+#include "mtypes.h"
 #endif
 
 
@@ -85,8 +85,8 @@ 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->_MaxLevel = src->_MaxLevel;
+   dest->_MaxLambda = src->_MaxLambda;
    dest->Palette = src->Palette;
    dest->Complete = src->Complete;
 }
@@ -100,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);
@@ -136,9 +136,7 @@ _mesa_PushAttrib(GLbitfield mask)
 
    if (mask & GL_CURRENT_BIT) {
       struct gl_current_attrib *attr;
-
-      FLUSH_TNL( ctx, FLUSH_UPDATE_CURRENT );
-
+      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 );
@@ -257,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 );
@@ -350,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 );
@@ -545,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" );
@@ -615,7 +613,7 @@ _mesa_PopAttrib(void)
             }
             break;
          case GL_CURRENT_BIT:
-           FLUSH_TNL( ctx, FLUSH_UPDATE_CURRENT );
+           FLUSH_CURRENT( ctx, 0 );
             MEMCPY( &ctx->Current, attr->data,
                    sizeof(struct gl_current_attrib) );
             break;
@@ -705,7 +703,7 @@ _mesa_PopAttrib(void)
             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))
+           if (ctx->Light.Enabled)
               ctx->_Enabled |= ENABLE_LIGHT;
             break;
          case GL_LINE_BIT:
@@ -760,7 +758,7 @@ _mesa_PopAttrib(void)
         case GL_POLYGON_STIPPLE_BIT:
            MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
            ctx->NewState |= _NEW_POLYGONSTIPPLE;
-           if (ctx->Driver.PolygonStipple) 
+           if (ctx->Driver.PolygonStipple)
               ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
            break;
          case GL_SCISSOR_BIT:
@@ -811,35 +809,35 @@ _mesa_PopAttrib(void)
             {
                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;
@@ -871,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" );
@@ -922,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" );
@@ -937,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");
@@ -957,7 +958,6 @@ _mesa_PopClientAttrib(void)
       attr = next;
    }
 
-   ctx->NewState = _NEW_ARRAY;
 }