mesa: remove duplicate dispatch sanity tests
[mesa.git] / src / mesa / main / matrix.c
index 293d50c33595b06e077e541646162a6ae24340ef..8065a83705c4d601ce306a93e5bcc5bfb8961614 100644 (file)
@@ -243,6 +243,24 @@ _mesa_PushMatrix( void )
       }
       return;
    }
+   if (stack->Depth + 1 >= stack->StackSize) {
+      unsigned new_stack_size = stack->StackSize * 2;
+      unsigned i;
+      GLmatrix *new_stack = realloc(stack->Stack,
+                                    sizeof(*new_stack) * new_stack_size);
+
+      if (!new_stack) {
+         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushMatrix()");
+         return;
+      }
+
+      for (i = stack->StackSize; i < new_stack_size; i++)
+         _math_matrix_ctr(&new_stack[i]);
+
+      stack->Stack = new_stack;
+      stack->StackSize = new_stack_size;
+   }
+
    _math_matrix_copy( &stack->Stack[stack->Depth + 1],
                       &stack->Stack[stack->Depth] );
    stack->Depth++;
@@ -338,9 +356,11 @@ _mesa_LoadMatrixf( const GLfloat *m )
           m[2], m[6], m[10], m[14],
           m[3], m[7], m[11], m[15]);
 
-   FLUSH_VERTICES(ctx, 0);
-   _math_matrix_loadf( ctx->CurrentStack->Top, m );
-   ctx->NewState |= ctx->CurrentStack->DirtyFlag;
+   if (memcmp(m, ctx->CurrentStack->Top->m, 16 * sizeof(GLfloat)) != 0) {
+      FLUSH_VERTICES(ctx, 0);
+      _math_matrix_loadf( ctx->CurrentStack->Top, m );
+      ctx->NewState |= ctx->CurrentStack->DirtyFlag;
+   }
 }
 
 
@@ -637,19 +657,16 @@ void _mesa_update_modelview_project( struct gl_context *ctx, GLuint new_state )
  * _math_matrix_ctr() for each element to initialize it.
  */
 static void
-init_matrix_stack( struct gl_matrix_stack *stack,
-                   GLuint maxDepth, GLuint dirtyFlag )
+init_matrix_stack(struct gl_matrix_stack *stack,
+                  GLuint maxDepth, GLuint dirtyFlag)
 {
-   GLuint i;
-
    stack->Depth = 0;
    stack->MaxDepth = maxDepth;
    stack->DirtyFlag = dirtyFlag;
-   /* The stack */
-   stack->Stack = calloc(maxDepth, sizeof(GLmatrix));
-   for (i = 0; i < maxDepth; i++) {
-      _math_matrix_ctr(&stack->Stack[i]);
-   }
+   /* The stack will be dynamically resized at glPushMatrix() time */
+   stack->Stack = calloc(1, sizeof(GLmatrix));
+   stack->StackSize = 1;
+   _math_matrix_ctr(&stack->Stack[0]);
    stack->Top = stack->Stack;
 }
 
@@ -665,11 +682,12 @@ static void
 free_matrix_stack( struct gl_matrix_stack *stack )
 {
    GLuint i;
-   for (i = 0; i < stack->MaxDepth; i++) {
+   for (i = 0; i < stack->StackSize; i++) {
       _math_matrix_dtr(&stack->Stack[i]);
    }
    free(stack->Stack);
    stack->Stack = stack->Top = NULL;
+   stack->StackSize = 0;
 }
 
 /*@}*/