Comment out __FUNCTION__ usage.
[mesa.git] / src / mesa / main / matrix.c
index 227f54b73d5efb173fd98bcc1ad134d8ca0d0ae5..a2b7af02ba2500c23345cdd7d39cf9d417ff407d 100644 (file)
@@ -1,21 +1,21 @@
-/* $Id: matrix.c,v 1.26 2000/11/16 21:05:35 keithw Exp $ */
+/* $Id: matrix.c,v 1.34 2001/03/19 22:45:52 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Version:  3.5
- * 
- * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
- * 
+ *
+ * Copyright (C) 1999-2001  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
@@ -46,7 +46,7 @@
 #include "matrix.h"
 #include "mem.h"
 #include "mmath.h"
-#include "types.h"
+#include "mtypes.h"
 
 #include "math/m_matrix.h"
 #endif
 /**********************************************************************/
 
 
-#define GET_ACTIVE_MATRIX(ctx, mat, flags, where)                      \
+#define GET_ACTIVE_MATRIX(ctx, mat, flags, where)              \
 do {                                                                   \
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, where);                      \
-   if (MESA_VERBOSE&VERBOSE_API) fprintf(stderr, "%s\n", where);        \
+   if (MESA_VERBOSE&VERBOSE_API) fprintf(stderr, "%s\n", where);       \
    switch (ctx->Transform.MatrixMode) {                                        \
       case GL_MODELVIEW:                                               \
         mat = &ctx->ModelView;                                         \
@@ -79,7 +78,7 @@ do {                                                                  \
         flags |= _NEW_COLOR_MATRIX;                                    \
         break;                                                         \
       default:                                                         \
-         gl_problem(ctx, where);                                       \
+         _mesa_problem(ctx, where);                                    \
    }                                                                   \
 } while (0)
 
@@ -91,20 +90,21 @@ _mesa_Frustum( GLdouble left, GLdouble right,
 {
    GET_CURRENT_CONTEXT(ctx);
    GLmatrix *mat = 0;
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    GET_ACTIVE_MATRIX( ctx,  mat, ctx->NewState, "glFrustrum" );
 
    if (nearval <= 0.0 ||
-       farval <= 0.0 || 
-       nearval == farval || 
-       left == right || 
-       top == bottom) 
+       farval <= 0.0 ||
+       nearval == farval ||
+       left == right ||
+       top == bottom)
    {
-      gl_error( ctx,  GL_INVALID_VALUE, "glFrustum" );
+      _mesa_error( ctx,  GL_INVALID_VALUE, "glFrustum" );
       return;
    }
-   
-   _math_matrix_frustrum( mat, left, right, bottom, top, nearval, farval );
+
+   _math_matrix_frustum( mat, left, right, bottom, top, nearval, farval );
 }
 
 
@@ -115,14 +115,15 @@ _mesa_Ortho( GLdouble left, GLdouble right,
 {
    GET_CURRENT_CONTEXT(ctx);
    GLmatrix *mat = 0;
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    GET_ACTIVE_MATRIX( ctx,  mat, ctx->NewState, "glOrtho" );
-   
-   if (left == right || 
-       bottom == top || 
-       nearval == farval) 
+
+   if (left == right ||
+       bottom == top ||
+       nearval == farval)
    {
-      gl_error( ctx,  GL_INVALID_VALUE, "gl_Ortho" );
+      _mesa_error( ctx,  GL_INVALID_VALUE, "glOrtho" );
       return;
    }
 
@@ -134,16 +135,20 @@ void
 _mesa_MatrixMode( GLenum mode )
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glMatrixMode");
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
    switch (mode) {
       case GL_MODELVIEW:
       case GL_PROJECTION:
       case GL_TEXTURE:
       case GL_COLOR:
+        if (ctx->Transform.MatrixMode == mode)
+           return;
          ctx->Transform.MatrixMode = mode;
+        FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
          break;
       default:
-         gl_error( ctx,  GL_INVALID_ENUM, "glMatrixMode" );
+         _mesa_error( ctx,  GL_INVALID_ENUM, "glMatrixMode" );
    }
 }
 
@@ -153,16 +158,16 @@ void
 _mesa_PushMatrix( void )
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushMatrix");
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE&VERBOSE_API)
-      fprintf(stderr, "glPushMatrix %s\n", 
-             gl_lookup_enum_by_nr(ctx->Transform.MatrixMode));
+      fprintf(stderr, "glPushMatrix %s\n",
+             _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode));
 
    switch (ctx->Transform.MatrixMode) {
       case GL_MODELVIEW:
          if (ctx->ModelViewStackDepth >= MAX_MODELVIEW_STACK_DEPTH - 1) {
-            gl_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
+            _mesa_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
             return;
          }
          _math_matrix_copy( &ctx->ModelViewStack[ctx->ModelViewStackDepth++],
@@ -170,7 +175,7 @@ _mesa_PushMatrix( void )
          break;
       case GL_PROJECTION:
          if (ctx->ProjectionStackDepth >= MAX_PROJECTION_STACK_DEPTH - 1) {
-            gl_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
+            _mesa_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
             return;
          }
          _math_matrix_copy( &ctx->ProjectionStack[ctx->ProjectionStackDepth++],
@@ -180,7 +185,7 @@ _mesa_PushMatrix( void )
          {
             GLuint t = ctx->Texture.CurrentTransformUnit;
             if (ctx->TextureStackDepth[t] >= MAX_TEXTURE_STACK_DEPTH - 1) {
-               gl_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
+               _mesa_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
                return;
             }
            _math_matrix_copy( &ctx->TextureStack[t][ctx->TextureStackDepth[t]++],
@@ -189,14 +194,14 @@ _mesa_PushMatrix( void )
          break;
       case GL_COLOR:
          if (ctx->ColorStackDepth >= MAX_COLOR_STACK_DEPTH - 1) {
-            gl_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
+            _mesa_error( ctx,  GL_STACK_OVERFLOW, "glPushMatrix");
             return;
          }
          _math_matrix_copy( &ctx->ColorStack[ctx->ColorStackDepth++],
                       &ctx->ColorMatrix );
          break;
       default:
-         gl_problem(ctx, "Bad matrix mode in gl_PushMatrix");
+         _mesa_problem(ctx, "Bad matrix mode in _mesa_PushMatrix");
    }
 }
 
@@ -206,16 +211,16 @@ void
 _mesa_PopMatrix( void )
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopMatrix");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (MESA_VERBOSE&VERBOSE_API)
-      fprintf(stderr, "glPopMatrix %s\n", 
-             gl_lookup_enum_by_nr(ctx->Transform.MatrixMode));
+      fprintf(stderr, "glPopMatrix %s\n",
+             _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode));
 
    switch (ctx->Transform.MatrixMode) {
       case GL_MODELVIEW:
          if (ctx->ModelViewStackDepth==0) {
-            gl_error( ctx,  GL_STACK_UNDERFLOW, "glPopMatrix");
+            _mesa_error( ctx,  GL_STACK_UNDERFLOW, "glPopMatrix");
             return;
          }
          _math_matrix_copy( &ctx->ModelView,
@@ -224,7 +229,7 @@ _mesa_PopMatrix( void )
          break;
       case GL_PROJECTION:
          if (ctx->ProjectionStackDepth==0) {
-            gl_error( ctx,  GL_STACK_UNDERFLOW, "glPopMatrix");
+            _mesa_error( ctx,  GL_STACK_UNDERFLOW, "glPopMatrix");
             return;
          }
 
@@ -236,7 +241,7 @@ _mesa_PopMatrix( void )
          {
             GLuint t = ctx->Texture.CurrentTransformUnit;
             if (ctx->TextureStackDepth[t]==0) {
-               gl_error( ctx,  GL_STACK_UNDERFLOW, "glPopMatrix");
+               _mesa_error( ctx,  GL_STACK_UNDERFLOW, "glPopMatrix");
                return;
             }
            _math_matrix_copy(&ctx->TextureMatrix[t],
@@ -246,7 +251,7 @@ _mesa_PopMatrix( void )
          break;
       case GL_COLOR:
          if (ctx->ColorStackDepth==0) {
-            gl_error( ctx,  GL_STACK_UNDERFLOW, "glPopMatrix");
+            _mesa_error( ctx,  GL_STACK_UNDERFLOW, "glPopMatrix");
             return;
          }
          _math_matrix_copy(&ctx->ColorMatrix,
@@ -254,7 +259,7 @@ _mesa_PopMatrix( void )
         ctx->NewState |= _NEW_COLOR_MATRIX;
          break;
       default:
-         gl_problem(ctx, "Bad matrix mode in gl_PopMatrix");
+         _mesa_problem(ctx, "Bad matrix mode in _mesa_PopMatrix");
    }
 }
 
@@ -265,6 +270,7 @@ _mesa_LoadIdentity( void )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLmatrix *mat = 0;
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
    GET_ACTIVE_MATRIX(ctx, mat, ctx->NewState, "glLoadIdentity");
    _math_matrix_set_identity( mat );
 }
@@ -275,6 +281,7 @@ _mesa_LoadMatrixf( const GLfloat *m )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLmatrix *mat = 0;
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
    GET_ACTIVE_MATRIX(ctx, mat, ctx->NewState, "glLoadMatrix");
    _math_matrix_loadf( mat, m );
 }
@@ -300,13 +307,14 @@ _mesa_MultMatrixf( const GLfloat *m )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLmatrix *mat = 0;
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
    GET_ACTIVE_MATRIX( ctx,  mat, ctx->NewState, "glMultMatrix" );
    _math_matrix_mul_floats( mat, m );
 }
 
 
 /*
- * Multiply the active matrix by an arbitary matrix.  
+ * Multiply the active matrix by an arbitary matrix.
  */
 void
 _mesa_MultMatrixd( const GLdouble *m )
@@ -328,6 +336,7 @@ void
 _mesa_Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
 {
    GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
    if (angle != 0.0F) {
       GLmatrix *mat = 0;
       GET_ACTIVE_MATRIX( ctx,  mat, ctx->NewState, "glRotate" );
@@ -350,6 +359,7 @@ _mesa_Scalef( GLfloat x, GLfloat y, GLfloat z )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLmatrix *mat = 0;
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
    GET_ACTIVE_MATRIX(ctx, mat, ctx->NewState, "glScale");
    _math_matrix_scale( mat, x, y, z );
 }
@@ -370,6 +380,7 @@ _mesa_Translatef( GLfloat x, GLfloat y, GLfloat z )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLmatrix *mat = 0;
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
    GET_ACTIVE_MATRIX(ctx, mat, ctx->NewState, "glTranslate");
    _math_matrix_translate( mat, x, y, z );
 }
@@ -425,32 +436,30 @@ void
 _mesa_Viewport( GLint x, GLint y, GLsizei width, GLsizei height )
 {
    GET_CURRENT_CONTEXT(ctx);
-   gl_Viewport(ctx, x, y, width, height);
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+   _mesa_set_viewport(ctx, x, y, width, height);
 }
 
 
-
 /*
  * Define a new viewport and reallocate auxillary buffers if the size of
  * the window (color buffer) has changed.
- *
- * XXX This is directly called by device drivers, BUT this function
- * may be renamed _mesa_Viewport (without ctx arg) in the future so
- * use of _mesa_Viewport is encouraged.
  */
 void
-gl_Viewport( GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height )
+_mesa_set_viewport( GLcontext *ctx, GLint x, GLint y,
+                    GLsizei width, GLsizei height )
 {
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glViewport");
+   const GLfloat n = ctx->Viewport.Near;
+   const GLfloat f = ctx->Viewport.Far;
 
-   if (width<0 || height<0) {
-      gl_error( ctx,  GL_INVALID_VALUE, "glViewport" );
+   if (width < 0 || height < 0) {
+      _mesa_error( ctx,  GL_INVALID_VALUE, "glViewport" );
       return;
    }
 
    if (MESA_VERBOSE & VERBOSE_API)
       fprintf(stderr, "glViewport %d %d %d %d\n", x, y, width, height);
-   
+
    /* clamp width, and height to implementation dependent range */
    width  = CLAMP( width,  1, MAX_WIDTH );
    height = CLAMP( height, 1, MAX_HEIGHT );
@@ -461,13 +470,15 @@ gl_Viewport( GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height )
    ctx->Viewport.Y = y;
    ctx->Viewport.Height = height;
 
-   /* compute scale and bias values */
+   /* compute scale and bias values :: This is really driver-specific
+    * and should be maintained elsewhere if at all.
+    */
    ctx->Viewport._WindowMap.m[MAT_SX] = (GLfloat) width / 2.0F;
    ctx->Viewport._WindowMap.m[MAT_TX] = ctx->Viewport._WindowMap.m[MAT_SX] + x;
    ctx->Viewport._WindowMap.m[MAT_SY] = (GLfloat) height / 2.0F;
    ctx->Viewport._WindowMap.m[MAT_TY] = ctx->Viewport._WindowMap.m[MAT_SY] + y;
-   ctx->Viewport._WindowMap.m[MAT_SZ] = 0.5 * ctx->Visual.DepthMaxF;
-   ctx->Viewport._WindowMap.m[MAT_TZ] = 0.5 * ctx->Visual.DepthMaxF;
+   ctx->Viewport._WindowMap.m[MAT_SZ] = ctx->DepthMaxF * ((f - n) / 2.0);
+   ctx->Viewport._WindowMap.m[MAT_TZ] = ctx->DepthMaxF * ((f - n) / 2.0 + n);
    ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
    ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
    ctx->NewState |= _NEW_VIEWPORT;
@@ -500,18 +511,18 @@ _mesa_DepthRange( GLclampd nearval, GLclampd farval )
     */
    GLfloat n, f;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDepthRange");
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (MESA_VERBOSE&VERBOSE_API)
-      fprintf(stderr, "glDepthRange %f %f\n", nearval, farval); 
+      fprintf(stderr, "glDepthRange %f %f\n", nearval, farval);
 
    n = (GLfloat) CLAMP( nearval, 0.0, 1.0 );
    f = (GLfloat) CLAMP( farval, 0.0, 1.0 );
 
    ctx->Viewport.Near = n;
    ctx->Viewport.Far = f;
-   ctx->Viewport._WindowMap.m[MAT_SZ] = ctx->Visual.DepthMaxF * ((f - n) / 2.0);
-   ctx->Viewport._WindowMap.m[MAT_TZ] = ctx->Visual.DepthMaxF * ((f - n) / 2.0 + n);
+   ctx->Viewport._WindowMap.m[MAT_SZ] = ctx->DepthMaxF * ((f - n) / 2.0);
+   ctx->Viewport._WindowMap.m[MAT_TZ] = ctx->DepthMaxF * ((f - n) / 2.0 + n);
    ctx->NewState |= _NEW_VIEWPORT;
 
    if (ctx->Driver.DepthRange) {