matrix.c revision 7117f1b4
17117f1b4Smrg/* 27117f1b4Smrg * Mesa 3-D graphics library 37117f1b4Smrg * Version: 6.5.3 47117f1b4Smrg * 57117f1b4Smrg * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 67117f1b4Smrg * 77117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 87117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 97117f1b4Smrg * to deal in the Software without restriction, including without limitation 107117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 117117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 127117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 137117f1b4Smrg * 147117f1b4Smrg * The above copyright notice and this permission notice shall be included 157117f1b4Smrg * in all copies or substantial portions of the Software. 167117f1b4Smrg * 177117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 187117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 197117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 207117f1b4Smrg * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 217117f1b4Smrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 227117f1b4Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 237117f1b4Smrg */ 247117f1b4Smrg 257117f1b4Smrg 267117f1b4Smrg/** 277117f1b4Smrg * \file matrix.c 287117f1b4Smrg * Matrix operations. 297117f1b4Smrg * 307117f1b4Smrg * \note 317117f1b4Smrg * -# 4x4 transformation matrices are stored in memory in column major order. 327117f1b4Smrg * -# Points/vertices are to be thought of as column vectors. 337117f1b4Smrg * -# Transformation of a point p by a matrix M is: p' = M * p 347117f1b4Smrg */ 357117f1b4Smrg 367117f1b4Smrg 377117f1b4Smrg#include "glheader.h" 387117f1b4Smrg#include "imports.h" 397117f1b4Smrg#include "context.h" 407117f1b4Smrg#include "enums.h" 417117f1b4Smrg#include "macros.h" 427117f1b4Smrg#include "matrix.h" 437117f1b4Smrg#include "mtypes.h" 447117f1b4Smrg#include "math/m_matrix.h" 457117f1b4Smrg#include "math/m_xform.h" 467117f1b4Smrg 477117f1b4Smrg 487117f1b4Smrg/** 497117f1b4Smrg * Apply a perspective projection matrix. 507117f1b4Smrg * 517117f1b4Smrg * \param left left clipping plane coordinate. 527117f1b4Smrg * \param right right clipping plane coordinate. 537117f1b4Smrg * \param bottom bottom clipping plane coordinate. 547117f1b4Smrg * \param top top clipping plane coordinate. 557117f1b4Smrg * \param nearval distance to the near clipping plane. 567117f1b4Smrg * \param farval distance to the far clipping plane. 577117f1b4Smrg * 587117f1b4Smrg * \sa glFrustum(). 597117f1b4Smrg * 607117f1b4Smrg * Flushes vertices and validates parameters. Calls _math_matrix_frustum() with 617117f1b4Smrg * the top matrix of the current matrix stack and sets 627117f1b4Smrg * __GLcontextRec::NewState. 637117f1b4Smrg */ 647117f1b4Smrgvoid GLAPIENTRY 657117f1b4Smrg_mesa_Frustum( GLdouble left, GLdouble right, 667117f1b4Smrg GLdouble bottom, GLdouble top, 677117f1b4Smrg GLdouble nearval, GLdouble farval ) 687117f1b4Smrg{ 697117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 707117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 717117f1b4Smrg 727117f1b4Smrg if (nearval <= 0.0 || 737117f1b4Smrg farval <= 0.0 || 747117f1b4Smrg nearval == farval || 757117f1b4Smrg left == right || 767117f1b4Smrg top == bottom) 777117f1b4Smrg { 787117f1b4Smrg _mesa_error( ctx, GL_INVALID_VALUE, "glFrustum" ); 797117f1b4Smrg return; 807117f1b4Smrg } 817117f1b4Smrg 827117f1b4Smrg _math_matrix_frustum( ctx->CurrentStack->Top, 837117f1b4Smrg (GLfloat) left, (GLfloat) right, 847117f1b4Smrg (GLfloat) bottom, (GLfloat) top, 857117f1b4Smrg (GLfloat) nearval, (GLfloat) farval ); 867117f1b4Smrg ctx->NewState |= ctx->CurrentStack->DirtyFlag; 877117f1b4Smrg} 887117f1b4Smrg 897117f1b4Smrg 907117f1b4Smrg/** 917117f1b4Smrg * Apply an orthographic projection matrix. 927117f1b4Smrg * 937117f1b4Smrg * \param left left clipping plane coordinate. 947117f1b4Smrg * \param right right clipping plane coordinate. 957117f1b4Smrg * \param bottom bottom clipping plane coordinate. 967117f1b4Smrg * \param top top clipping plane coordinate. 977117f1b4Smrg * \param nearval distance to the near clipping plane. 987117f1b4Smrg * \param farval distance to the far clipping plane. 997117f1b4Smrg * 1007117f1b4Smrg * \sa glOrtho(). 1017117f1b4Smrg * 1027117f1b4Smrg * Flushes vertices and validates parameters. Calls _math_matrix_ortho() with 1037117f1b4Smrg * the top matrix of the current matrix stack and sets 1047117f1b4Smrg * __GLcontextRec::NewState. 1057117f1b4Smrg */ 1067117f1b4Smrgvoid GLAPIENTRY 1077117f1b4Smrg_mesa_Ortho( GLdouble left, GLdouble right, 1087117f1b4Smrg GLdouble bottom, GLdouble top, 1097117f1b4Smrg GLdouble nearval, GLdouble farval ) 1107117f1b4Smrg{ 1117117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 1127117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1137117f1b4Smrg 1147117f1b4Smrg if (MESA_VERBOSE & VERBOSE_API) 1157117f1b4Smrg _mesa_debug(ctx, "glOrtho(%f, %f, %f, %f, %f, %f)\n", 1167117f1b4Smrg left, right, bottom, top, nearval, farval); 1177117f1b4Smrg 1187117f1b4Smrg if (left == right || 1197117f1b4Smrg bottom == top || 1207117f1b4Smrg nearval == farval) 1217117f1b4Smrg { 1227117f1b4Smrg _mesa_error( ctx, GL_INVALID_VALUE, "glOrtho" ); 1237117f1b4Smrg return; 1247117f1b4Smrg } 1257117f1b4Smrg 1267117f1b4Smrg _math_matrix_ortho( ctx->CurrentStack->Top, 1277117f1b4Smrg (GLfloat) left, (GLfloat) right, 1287117f1b4Smrg (GLfloat) bottom, (GLfloat) top, 1297117f1b4Smrg (GLfloat) nearval, (GLfloat) farval ); 1307117f1b4Smrg ctx->NewState |= ctx->CurrentStack->DirtyFlag; 1317117f1b4Smrg} 1327117f1b4Smrg 1337117f1b4Smrg 1347117f1b4Smrg/** 1357117f1b4Smrg * Set the current matrix stack. 1367117f1b4Smrg * 1377117f1b4Smrg * \param mode matrix stack. 1387117f1b4Smrg * 1397117f1b4Smrg * \sa glMatrixMode(). 1407117f1b4Smrg * 1417117f1b4Smrg * Flushes the vertices, validates the parameter and updates 1427117f1b4Smrg * __GLcontextRec::CurrentStack and gl_transform_attrib::MatrixMode with the 1437117f1b4Smrg * specified matrix stack. 1447117f1b4Smrg */ 1457117f1b4Smrgvoid GLAPIENTRY 1467117f1b4Smrg_mesa_MatrixMode( GLenum mode ) 1477117f1b4Smrg{ 1487117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 1497117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END(ctx); 1507117f1b4Smrg 1517117f1b4Smrg if (ctx->Transform.MatrixMode == mode && mode != GL_TEXTURE) 1527117f1b4Smrg return; 1537117f1b4Smrg FLUSH_VERTICES(ctx, _NEW_TRANSFORM); 1547117f1b4Smrg 1557117f1b4Smrg switch (mode) { 1567117f1b4Smrg case GL_MODELVIEW: 1577117f1b4Smrg ctx->CurrentStack = &ctx->ModelviewMatrixStack; 1587117f1b4Smrg break; 1597117f1b4Smrg case GL_PROJECTION: 1607117f1b4Smrg ctx->CurrentStack = &ctx->ProjectionMatrixStack; 1617117f1b4Smrg break; 1627117f1b4Smrg case GL_TEXTURE: 1637117f1b4Smrg if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) { 1647117f1b4Smrg _mesa_error(ctx, GL_INVALID_OPERATION, "glMatrixMode(texcoord unit)"); 1657117f1b4Smrg return; 1667117f1b4Smrg } 1677117f1b4Smrg ctx->CurrentStack = &ctx->TextureMatrixStack[ctx->Texture.CurrentUnit]; 1687117f1b4Smrg break; 1697117f1b4Smrg case GL_COLOR: 1707117f1b4Smrg ctx->CurrentStack = &ctx->ColorMatrixStack; 1717117f1b4Smrg break; 1727117f1b4Smrg case GL_MATRIX0_NV: 1737117f1b4Smrg case GL_MATRIX1_NV: 1747117f1b4Smrg case GL_MATRIX2_NV: 1757117f1b4Smrg case GL_MATRIX3_NV: 1767117f1b4Smrg case GL_MATRIX4_NV: 1777117f1b4Smrg case GL_MATRIX5_NV: 1787117f1b4Smrg case GL_MATRIX6_NV: 1797117f1b4Smrg case GL_MATRIX7_NV: 1807117f1b4Smrg if (ctx->Extensions.NV_vertex_program) { 1817117f1b4Smrg ctx->CurrentStack = &ctx->ProgramMatrixStack[mode - GL_MATRIX0_NV]; 1827117f1b4Smrg } 1837117f1b4Smrg else { 1847117f1b4Smrg _mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode(mode)" ); 1857117f1b4Smrg return; 1867117f1b4Smrg } 1877117f1b4Smrg break; 1887117f1b4Smrg case GL_MATRIX0_ARB: 1897117f1b4Smrg case GL_MATRIX1_ARB: 1907117f1b4Smrg case GL_MATRIX2_ARB: 1917117f1b4Smrg case GL_MATRIX3_ARB: 1927117f1b4Smrg case GL_MATRIX4_ARB: 1937117f1b4Smrg case GL_MATRIX5_ARB: 1947117f1b4Smrg case GL_MATRIX6_ARB: 1957117f1b4Smrg case GL_MATRIX7_ARB: 1967117f1b4Smrg if (ctx->Extensions.ARB_vertex_program || 1977117f1b4Smrg ctx->Extensions.ARB_fragment_program) { 1987117f1b4Smrg const GLuint m = mode - GL_MATRIX0_ARB; 1997117f1b4Smrg if (m > ctx->Const.MaxProgramMatrices) { 2007117f1b4Smrg _mesa_error(ctx, GL_INVALID_ENUM, 2017117f1b4Smrg "glMatrixMode(GL_MATRIX%d_ARB)", m); 2027117f1b4Smrg return; 2037117f1b4Smrg } 2047117f1b4Smrg ctx->CurrentStack = &ctx->ProgramMatrixStack[m]; 2057117f1b4Smrg } 2067117f1b4Smrg else { 2077117f1b4Smrg _mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode(mode)" ); 2087117f1b4Smrg return; 2097117f1b4Smrg } 2107117f1b4Smrg break; 2117117f1b4Smrg default: 2127117f1b4Smrg _mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode(mode)" ); 2137117f1b4Smrg return; 2147117f1b4Smrg } 2157117f1b4Smrg 2167117f1b4Smrg ctx->Transform.MatrixMode = mode; 2177117f1b4Smrg} 2187117f1b4Smrg 2197117f1b4Smrg 2207117f1b4Smrg/** 2217117f1b4Smrg * Push the current matrix stack. 2227117f1b4Smrg * 2237117f1b4Smrg * \sa glPushMatrix(). 2247117f1b4Smrg * 2257117f1b4Smrg * Verifies the current matrix stack is not full, and duplicates the top-most 2267117f1b4Smrg * matrix in the stack. Marks __GLcontextRec::NewState with the stack dirty 2277117f1b4Smrg * flag. 2287117f1b4Smrg */ 2297117f1b4Smrgvoid GLAPIENTRY 2307117f1b4Smrg_mesa_PushMatrix( void ) 2317117f1b4Smrg{ 2327117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 2337117f1b4Smrg struct gl_matrix_stack *stack = ctx->CurrentStack; 2347117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END(ctx); 2357117f1b4Smrg 2367117f1b4Smrg if (MESA_VERBOSE&VERBOSE_API) 2377117f1b4Smrg _mesa_debug(ctx, "glPushMatrix %s\n", 2387117f1b4Smrg _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode)); 2397117f1b4Smrg 2407117f1b4Smrg if (stack->Depth + 1 >= stack->MaxDepth) { 2417117f1b4Smrg if (ctx->Transform.MatrixMode == GL_TEXTURE) { 2427117f1b4Smrg _mesa_error(ctx, GL_STACK_OVERFLOW, 2437117f1b4Smrg "glPushMatrix(mode=GL_TEXTURE, unit=%d)", 2447117f1b4Smrg ctx->Texture.CurrentUnit); 2457117f1b4Smrg } 2467117f1b4Smrg else { 2477117f1b4Smrg _mesa_error(ctx, GL_STACK_OVERFLOW, "glPushMatrix(mode=%s)", 2487117f1b4Smrg _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode)); 2497117f1b4Smrg } 2507117f1b4Smrg return; 2517117f1b4Smrg } 2527117f1b4Smrg _math_matrix_copy( &stack->Stack[stack->Depth + 1], 2537117f1b4Smrg &stack->Stack[stack->Depth] ); 2547117f1b4Smrg stack->Depth++; 2557117f1b4Smrg stack->Top = &(stack->Stack[stack->Depth]); 2567117f1b4Smrg ctx->NewState |= stack->DirtyFlag; 2577117f1b4Smrg} 2587117f1b4Smrg 2597117f1b4Smrg 2607117f1b4Smrg/** 2617117f1b4Smrg * Pop the current matrix stack. 2627117f1b4Smrg * 2637117f1b4Smrg * \sa glPopMatrix(). 2647117f1b4Smrg * 2657117f1b4Smrg * Flushes the vertices, verifies the current matrix stack is not empty, and 2667117f1b4Smrg * moves the stack head down. Marks __GLcontextRec::NewState with the dirty 2677117f1b4Smrg * stack flag. 2687117f1b4Smrg */ 2697117f1b4Smrgvoid GLAPIENTRY 2707117f1b4Smrg_mesa_PopMatrix( void ) 2717117f1b4Smrg{ 2727117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 2737117f1b4Smrg struct gl_matrix_stack *stack = ctx->CurrentStack; 2747117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 2757117f1b4Smrg 2767117f1b4Smrg if (MESA_VERBOSE&VERBOSE_API) 2777117f1b4Smrg _mesa_debug(ctx, "glPopMatrix %s\n", 2787117f1b4Smrg _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode)); 2797117f1b4Smrg 2807117f1b4Smrg if (stack->Depth == 0) { 2817117f1b4Smrg if (ctx->Transform.MatrixMode == GL_TEXTURE) { 2827117f1b4Smrg _mesa_error(ctx, GL_STACK_UNDERFLOW, 2837117f1b4Smrg "glPopMatrix(mode=GL_TEXTURE, unit=%d)", 2847117f1b4Smrg ctx->Texture.CurrentUnit); 2857117f1b4Smrg } 2867117f1b4Smrg else { 2877117f1b4Smrg _mesa_error(ctx, GL_STACK_UNDERFLOW, "glPopMatrix(mode=%s)", 2887117f1b4Smrg _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode)); 2897117f1b4Smrg } 2907117f1b4Smrg return; 2917117f1b4Smrg } 2927117f1b4Smrg stack->Depth--; 2937117f1b4Smrg stack->Top = &(stack->Stack[stack->Depth]); 2947117f1b4Smrg ctx->NewState |= stack->DirtyFlag; 2957117f1b4Smrg} 2967117f1b4Smrg 2977117f1b4Smrg 2987117f1b4Smrg/** 2997117f1b4Smrg * Replace the current matrix with the identity matrix. 3007117f1b4Smrg * 3017117f1b4Smrg * \sa glLoadIdentity(). 3027117f1b4Smrg * 3037117f1b4Smrg * Flushes the vertices and calls _math_matrix_set_identity() with the top-most 3047117f1b4Smrg * matrix in the current stack. Marks __GLcontextRec::NewState with the stack 3057117f1b4Smrg * dirty flag. 3067117f1b4Smrg */ 3077117f1b4Smrgvoid GLAPIENTRY 3087117f1b4Smrg_mesa_LoadIdentity( void ) 3097117f1b4Smrg{ 3107117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 3117117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3127117f1b4Smrg 3137117f1b4Smrg if (MESA_VERBOSE & VERBOSE_API) 3147117f1b4Smrg _mesa_debug(ctx, "glLoadIdentity()"); 3157117f1b4Smrg 3167117f1b4Smrg _math_matrix_set_identity( ctx->CurrentStack->Top ); 3177117f1b4Smrg ctx->NewState |= ctx->CurrentStack->DirtyFlag; 3187117f1b4Smrg} 3197117f1b4Smrg 3207117f1b4Smrg 3217117f1b4Smrg/** 3227117f1b4Smrg * Replace the current matrix with a given matrix. 3237117f1b4Smrg * 3247117f1b4Smrg * \param m matrix. 3257117f1b4Smrg * 3267117f1b4Smrg * \sa glLoadMatrixf(). 3277117f1b4Smrg * 3287117f1b4Smrg * Flushes the vertices and calls _math_matrix_loadf() with the top-most matrix 3297117f1b4Smrg * in the current stack and the given matrix. Marks __GLcontextRec::NewState 3307117f1b4Smrg * with the dirty stack flag. 3317117f1b4Smrg */ 3327117f1b4Smrgvoid GLAPIENTRY 3337117f1b4Smrg_mesa_LoadMatrixf( const GLfloat *m ) 3347117f1b4Smrg{ 3357117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 3367117f1b4Smrg if (!m) return; 3377117f1b4Smrg if (MESA_VERBOSE & VERBOSE_API) 3387117f1b4Smrg _mesa_debug(ctx, 3397117f1b4Smrg "glLoadMatrix(%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f\n", 3407117f1b4Smrg m[0], m[4], m[8], m[12], 3417117f1b4Smrg m[1], m[5], m[9], m[13], 3427117f1b4Smrg m[2], m[6], m[10], m[14], 3437117f1b4Smrg m[3], m[7], m[11], m[15]); 3447117f1b4Smrg 3457117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3467117f1b4Smrg _math_matrix_loadf( ctx->CurrentStack->Top, m ); 3477117f1b4Smrg ctx->NewState |= ctx->CurrentStack->DirtyFlag; 3487117f1b4Smrg} 3497117f1b4Smrg 3507117f1b4Smrg 3517117f1b4Smrg/** 3527117f1b4Smrg * Multiply the current matrix with a given matrix. 3537117f1b4Smrg * 3547117f1b4Smrg * \param m matrix. 3557117f1b4Smrg * 3567117f1b4Smrg * \sa glMultMatrixf(). 3577117f1b4Smrg * 3587117f1b4Smrg * Flushes the vertices and calls _math_matrix_mul_floats() with the top-most 3597117f1b4Smrg * matrix in the current stack and the given matrix. Marks 3607117f1b4Smrg * __GLcontextRec::NewState with the dirty stack flag. 3617117f1b4Smrg */ 3627117f1b4Smrgvoid GLAPIENTRY 3637117f1b4Smrg_mesa_MultMatrixf( const GLfloat *m ) 3647117f1b4Smrg{ 3657117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 3667117f1b4Smrg if (!m) return; 3677117f1b4Smrg if (MESA_VERBOSE & VERBOSE_API) 3687117f1b4Smrg _mesa_debug(ctx, 3697117f1b4Smrg "glMultMatrix(%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f\n", 3707117f1b4Smrg m[0], m[4], m[8], m[12], 3717117f1b4Smrg m[1], m[5], m[9], m[13], 3727117f1b4Smrg m[2], m[6], m[10], m[14], 3737117f1b4Smrg m[3], m[7], m[11], m[15]); 3747117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3757117f1b4Smrg _math_matrix_mul_floats( ctx->CurrentStack->Top, m ); 3767117f1b4Smrg ctx->NewState |= ctx->CurrentStack->DirtyFlag; 3777117f1b4Smrg} 3787117f1b4Smrg 3797117f1b4Smrg 3807117f1b4Smrg/** 3817117f1b4Smrg * Multiply the current matrix with a rotation matrix. 3827117f1b4Smrg * 3837117f1b4Smrg * \param angle angle of rotation, in degrees. 3847117f1b4Smrg * \param x rotation vector x coordinate. 3857117f1b4Smrg * \param y rotation vector y coordinate. 3867117f1b4Smrg * \param z rotation vector z coordinate. 3877117f1b4Smrg * 3887117f1b4Smrg * \sa glRotatef(). 3897117f1b4Smrg * 3907117f1b4Smrg * Flushes the vertices and calls _math_matrix_rotate() with the top-most 3917117f1b4Smrg * matrix in the current stack and the given parameters. Marks 3927117f1b4Smrg * __GLcontextRec::NewState with the dirty stack flag. 3937117f1b4Smrg */ 3947117f1b4Smrgvoid GLAPIENTRY 3957117f1b4Smrg_mesa_Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) 3967117f1b4Smrg{ 3977117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 3987117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 3997117f1b4Smrg if (angle != 0.0F) { 4007117f1b4Smrg _math_matrix_rotate( ctx->CurrentStack->Top, angle, x, y, z); 4017117f1b4Smrg ctx->NewState |= ctx->CurrentStack->DirtyFlag; 4027117f1b4Smrg } 4037117f1b4Smrg} 4047117f1b4Smrg 4057117f1b4Smrg 4067117f1b4Smrg/** 4077117f1b4Smrg * Multiply the current matrix with a general scaling matrix. 4087117f1b4Smrg * 4097117f1b4Smrg * \param x x axis scale factor. 4107117f1b4Smrg * \param y y axis scale factor. 4117117f1b4Smrg * \param z z axis scale factor. 4127117f1b4Smrg * 4137117f1b4Smrg * \sa glScalef(). 4147117f1b4Smrg * 4157117f1b4Smrg * Flushes the vertices and calls _math_matrix_scale() with the top-most 4167117f1b4Smrg * matrix in the current stack and the given parameters. Marks 4177117f1b4Smrg * __GLcontextRec::NewState with the dirty stack flag. 4187117f1b4Smrg */ 4197117f1b4Smrgvoid GLAPIENTRY 4207117f1b4Smrg_mesa_Scalef( GLfloat x, GLfloat y, GLfloat z ) 4217117f1b4Smrg{ 4227117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 4237117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 4247117f1b4Smrg _math_matrix_scale( ctx->CurrentStack->Top, x, y, z); 4257117f1b4Smrg ctx->NewState |= ctx->CurrentStack->DirtyFlag; 4267117f1b4Smrg} 4277117f1b4Smrg 4287117f1b4Smrg 4297117f1b4Smrg/** 4307117f1b4Smrg * Multiply the current matrix with a translation matrix. 4317117f1b4Smrg * 4327117f1b4Smrg * \param x translation vector x coordinate. 4337117f1b4Smrg * \param y translation vector y coordinate. 4347117f1b4Smrg * \param z translation vector z coordinate. 4357117f1b4Smrg * 4367117f1b4Smrg * \sa glTranslatef(). 4377117f1b4Smrg * 4387117f1b4Smrg * Flushes the vertices and calls _math_matrix_translate() with the top-most 4397117f1b4Smrg * matrix in the current stack and the given parameters. Marks 4407117f1b4Smrg * __GLcontextRec::NewState with the dirty stack flag. 4417117f1b4Smrg */ 4427117f1b4Smrgvoid GLAPIENTRY 4437117f1b4Smrg_mesa_Translatef( GLfloat x, GLfloat y, GLfloat z ) 4447117f1b4Smrg{ 4457117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 4467117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 4477117f1b4Smrg _math_matrix_translate( ctx->CurrentStack->Top, x, y, z); 4487117f1b4Smrg ctx->NewState |= ctx->CurrentStack->DirtyFlag; 4497117f1b4Smrg} 4507117f1b4Smrg 4517117f1b4Smrg 4527117f1b4Smrg#if _HAVE_FULL_GL 4537117f1b4Smrgvoid GLAPIENTRY 4547117f1b4Smrg_mesa_LoadMatrixd( const GLdouble *m ) 4557117f1b4Smrg{ 4567117f1b4Smrg GLint i; 4577117f1b4Smrg GLfloat f[16]; 4587117f1b4Smrg if (!m) return; 4597117f1b4Smrg for (i = 0; i < 16; i++) 4607117f1b4Smrg f[i] = (GLfloat) m[i]; 4617117f1b4Smrg _mesa_LoadMatrixf(f); 4627117f1b4Smrg} 4637117f1b4Smrg 4647117f1b4Smrgvoid GLAPIENTRY 4657117f1b4Smrg_mesa_MultMatrixd( const GLdouble *m ) 4667117f1b4Smrg{ 4677117f1b4Smrg GLint i; 4687117f1b4Smrg GLfloat f[16]; 4697117f1b4Smrg if (!m) return; 4707117f1b4Smrg for (i = 0; i < 16; i++) 4717117f1b4Smrg f[i] = (GLfloat) m[i]; 4727117f1b4Smrg _mesa_MultMatrixf( f ); 4737117f1b4Smrg} 4747117f1b4Smrg 4757117f1b4Smrg 4767117f1b4Smrgvoid GLAPIENTRY 4777117f1b4Smrg_mesa_Rotated( GLdouble angle, GLdouble x, GLdouble y, GLdouble z ) 4787117f1b4Smrg{ 4797117f1b4Smrg _mesa_Rotatef((GLfloat) angle, (GLfloat) x, (GLfloat) y, (GLfloat) z); 4807117f1b4Smrg} 4817117f1b4Smrg 4827117f1b4Smrg 4837117f1b4Smrgvoid GLAPIENTRY 4847117f1b4Smrg_mesa_Scaled( GLdouble x, GLdouble y, GLdouble z ) 4857117f1b4Smrg{ 4867117f1b4Smrg _mesa_Scalef((GLfloat) x, (GLfloat) y, (GLfloat) z); 4877117f1b4Smrg} 4887117f1b4Smrg 4897117f1b4Smrg 4907117f1b4Smrgvoid GLAPIENTRY 4917117f1b4Smrg_mesa_Translated( GLdouble x, GLdouble y, GLdouble z ) 4927117f1b4Smrg{ 4937117f1b4Smrg _mesa_Translatef((GLfloat) x, (GLfloat) y, (GLfloat) z); 4947117f1b4Smrg} 4957117f1b4Smrg#endif 4967117f1b4Smrg 4977117f1b4Smrg 4987117f1b4Smrg#if _HAVE_FULL_GL 4997117f1b4Smrgvoid GLAPIENTRY 5007117f1b4Smrg_mesa_LoadTransposeMatrixfARB( const GLfloat *m ) 5017117f1b4Smrg{ 5027117f1b4Smrg GLfloat tm[16]; 5037117f1b4Smrg if (!m) return; 5047117f1b4Smrg _math_transposef(tm, m); 5057117f1b4Smrg _mesa_LoadMatrixf(tm); 5067117f1b4Smrg} 5077117f1b4Smrg 5087117f1b4Smrg 5097117f1b4Smrgvoid GLAPIENTRY 5107117f1b4Smrg_mesa_LoadTransposeMatrixdARB( const GLdouble *m ) 5117117f1b4Smrg{ 5127117f1b4Smrg GLfloat tm[16]; 5137117f1b4Smrg if (!m) return; 5147117f1b4Smrg _math_transposefd(tm, m); 5157117f1b4Smrg _mesa_LoadMatrixf(tm); 5167117f1b4Smrg} 5177117f1b4Smrg 5187117f1b4Smrg 5197117f1b4Smrgvoid GLAPIENTRY 5207117f1b4Smrg_mesa_MultTransposeMatrixfARB( const GLfloat *m ) 5217117f1b4Smrg{ 5227117f1b4Smrg GLfloat tm[16]; 5237117f1b4Smrg if (!m) return; 5247117f1b4Smrg _math_transposef(tm, m); 5257117f1b4Smrg _mesa_MultMatrixf(tm); 5267117f1b4Smrg} 5277117f1b4Smrg 5287117f1b4Smrg 5297117f1b4Smrgvoid GLAPIENTRY 5307117f1b4Smrg_mesa_MultTransposeMatrixdARB( const GLdouble *m ) 5317117f1b4Smrg{ 5327117f1b4Smrg GLfloat tm[16]; 5337117f1b4Smrg if (!m) return; 5347117f1b4Smrg _math_transposefd(tm, m); 5357117f1b4Smrg _mesa_MultMatrixf(tm); 5367117f1b4Smrg} 5377117f1b4Smrg#endif 5387117f1b4Smrg 5397117f1b4Smrg/** 5407117f1b4Smrg * Set the viewport. 5417117f1b4Smrg * 5427117f1b4Smrg * \param x, y coordinates of the lower-left corner of the viewport rectangle. 5437117f1b4Smrg * \param width width of the viewport rectangle. 5447117f1b4Smrg * \param height height of the viewport rectangle. 5457117f1b4Smrg * 5467117f1b4Smrg * \sa Called via glViewport() or display list execution. 5477117f1b4Smrg * 5487117f1b4Smrg * Flushes the vertices and calls _mesa_set_viewport() with the given 5497117f1b4Smrg * parameters. 5507117f1b4Smrg */ 5517117f1b4Smrgvoid GLAPIENTRY 5527117f1b4Smrg_mesa_Viewport( GLint x, GLint y, GLsizei width, GLsizei height ) 5537117f1b4Smrg{ 5547117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 5557117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 5567117f1b4Smrg _mesa_set_viewport(ctx, x, y, width, height); 5577117f1b4Smrg} 5587117f1b4Smrg 5597117f1b4Smrg 5607117f1b4Smrg/** 5617117f1b4Smrg * Set new viewport parameters and update derived state (the _WindowMap 5627117f1b4Smrg * matrix). Usually called from _mesa_Viewport(). 5637117f1b4Smrg * 5647117f1b4Smrg * \param ctx GL context. 5657117f1b4Smrg * \param x, y coordinates of the lower left corner of the viewport rectangle. 5667117f1b4Smrg * \param width width of the viewport rectangle. 5677117f1b4Smrg * \param height height of the viewport rectangle. 5687117f1b4Smrg */ 5697117f1b4Smrgvoid 5707117f1b4Smrg_mesa_set_viewport( GLcontext *ctx, GLint x, GLint y, 5717117f1b4Smrg GLsizei width, GLsizei height ) 5727117f1b4Smrg{ 5737117f1b4Smrg if (MESA_VERBOSE & VERBOSE_API) 5747117f1b4Smrg _mesa_debug(ctx, "glViewport %d %d %d %d\n", x, y, width, height); 5757117f1b4Smrg 5767117f1b4Smrg if (width < 0 || height < 0) { 5777117f1b4Smrg _mesa_error( ctx, GL_INVALID_VALUE, 5787117f1b4Smrg "glViewport(%d, %d, %d, %d)", x, y, width, height ); 5797117f1b4Smrg return; 5807117f1b4Smrg } 5817117f1b4Smrg 5827117f1b4Smrg /* clamp width and height to the implementation dependent range */ 5837117f1b4Smrg width = CLAMP(width, 1, (GLsizei) ctx->Const.MaxViewportWidth); 5847117f1b4Smrg height = CLAMP(height, 1, (GLsizei) ctx->Const.MaxViewportHeight); 5857117f1b4Smrg 5867117f1b4Smrg ctx->Viewport.X = x; 5877117f1b4Smrg ctx->Viewport.Width = width; 5887117f1b4Smrg ctx->Viewport.Y = y; 5897117f1b4Smrg ctx->Viewport.Height = height; 5907117f1b4Smrg ctx->NewState |= _NEW_VIEWPORT; 5917117f1b4Smrg 5927117f1b4Smrg#if 1 5937117f1b4Smrg /* XXX remove this someday. Currently the DRI drivers rely on 5947117f1b4Smrg * the WindowMap matrix being up to date in the driver's Viewport 5957117f1b4Smrg * and DepthRange functions. 5967117f1b4Smrg */ 5977117f1b4Smrg _math_matrix_viewport(&ctx->Viewport._WindowMap, 5987117f1b4Smrg ctx->Viewport.X, ctx->Viewport.Y, 5997117f1b4Smrg ctx->Viewport.Width, ctx->Viewport.Height, 6007117f1b4Smrg ctx->Viewport.Near, ctx->Viewport.Far, 6017117f1b4Smrg ctx->DrawBuffer->_DepthMaxF); 6027117f1b4Smrg#endif 6037117f1b4Smrg 6047117f1b4Smrg if (ctx->Driver.Viewport) { 6057117f1b4Smrg /* Many drivers will use this call to check for window size changes 6067117f1b4Smrg * and reallocate the z/stencil/accum/etc buffers if needed. 6077117f1b4Smrg */ 6087117f1b4Smrg (*ctx->Driver.Viewport)( ctx, x, y, width, height ); 6097117f1b4Smrg } 6107117f1b4Smrg} 6117117f1b4Smrg 6127117f1b4Smrg 6137117f1b4Smrg#if _HAVE_FULL_GL 6147117f1b4Smrg/** 6157117f1b4Smrg * Called by glDepthRange 6167117f1b4Smrg * 6177117f1b4Smrg * \param nearval specifies the Z buffer value which should correspond to 6187117f1b4Smrg * the near clip plane 6197117f1b4Smrg * \param farval specifies the Z buffer value which should correspond to 6207117f1b4Smrg * the far clip plane 6217117f1b4Smrg */ 6227117f1b4Smrgvoid GLAPIENTRY 6237117f1b4Smrg_mesa_DepthRange( GLclampd nearval, GLclampd farval ) 6247117f1b4Smrg{ 6257117f1b4Smrg GET_CURRENT_CONTEXT(ctx); 6267117f1b4Smrg ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 6277117f1b4Smrg 6287117f1b4Smrg if (MESA_VERBOSE&VERBOSE_API) 6297117f1b4Smrg _mesa_debug(ctx, "glDepthRange %f %f\n", nearval, farval); 6307117f1b4Smrg 6317117f1b4Smrg ctx->Viewport.Near = (GLfloat) CLAMP( nearval, 0.0, 1.0 ); 6327117f1b4Smrg ctx->Viewport.Far = (GLfloat) CLAMP( farval, 0.0, 1.0 ); 6337117f1b4Smrg ctx->NewState |= _NEW_VIEWPORT; 6347117f1b4Smrg 6357117f1b4Smrg#if 1 6367117f1b4Smrg /* XXX remove this someday. Currently the DRI drivers rely on 6377117f1b4Smrg * the WindowMap matrix being up to date in the driver's Viewport 6387117f1b4Smrg * and DepthRange functions. 6397117f1b4Smrg */ 6407117f1b4Smrg _math_matrix_viewport(&ctx->Viewport._WindowMap, 6417117f1b4Smrg ctx->Viewport.X, ctx->Viewport.Y, 6427117f1b4Smrg ctx->Viewport.Width, ctx->Viewport.Height, 6437117f1b4Smrg ctx->Viewport.Near, ctx->Viewport.Far, 6447117f1b4Smrg ctx->DrawBuffer->_DepthMaxF); 6457117f1b4Smrg#endif 6467117f1b4Smrg 6477117f1b4Smrg if (ctx->Driver.DepthRange) { 6487117f1b4Smrg (*ctx->Driver.DepthRange)( ctx, nearval, farval ); 6497117f1b4Smrg } 6507117f1b4Smrg} 6517117f1b4Smrg#endif 6527117f1b4Smrg 6537117f1b4Smrg 6547117f1b4Smrg 6557117f1b4Smrg/**********************************************************************/ 6567117f1b4Smrg/** \name State management */ 6577117f1b4Smrg/*@{*/ 6587117f1b4Smrg 6597117f1b4Smrg 6607117f1b4Smrg/** 6617117f1b4Smrg * Update the projection matrix stack. 6627117f1b4Smrg * 6637117f1b4Smrg * \param ctx GL context. 6647117f1b4Smrg * 6657117f1b4Smrg * Calls _math_matrix_analyse() with the top-matrix of the projection matrix 6667117f1b4Smrg * stack, and recomputes user clip positions if necessary. 6677117f1b4Smrg * 6687117f1b4Smrg * \note This routine references __GLcontextRec::Tranform attribute values to 6697117f1b4Smrg * compute userclip positions in clip space, but is only called on 6707117f1b4Smrg * _NEW_PROJECTION. The _mesa_ClipPlane() function keeps these values up to 6717117f1b4Smrg * date across changes to the __GLcontextRec::Transform attributes. 6727117f1b4Smrg */ 6737117f1b4Smrgstatic void 6747117f1b4Smrgupdate_projection( GLcontext *ctx ) 6757117f1b4Smrg{ 6767117f1b4Smrg _math_matrix_analyse( ctx->ProjectionMatrixStack.Top ); 6777117f1b4Smrg 6787117f1b4Smrg#if FEATURE_userclip 6797117f1b4Smrg /* Recompute clip plane positions in clipspace. This is also done 6807117f1b4Smrg * in _mesa_ClipPlane(). 6817117f1b4Smrg */ 6827117f1b4Smrg if (ctx->Transform.ClipPlanesEnabled) { 6837117f1b4Smrg GLuint p; 6847117f1b4Smrg for (p = 0; p < ctx->Const.MaxClipPlanes; p++) { 6857117f1b4Smrg if (ctx->Transform.ClipPlanesEnabled & (1 << p)) { 6867117f1b4Smrg _mesa_transform_vector( ctx->Transform._ClipUserPlane[p], 6877117f1b4Smrg ctx->Transform.EyeUserPlane[p], 6887117f1b4Smrg ctx->ProjectionMatrixStack.Top->inv ); 6897117f1b4Smrg } 6907117f1b4Smrg } 6917117f1b4Smrg } 6927117f1b4Smrg#endif 6937117f1b4Smrg} 6947117f1b4Smrg 6957117f1b4Smrg 6967117f1b4Smrg/** 6977117f1b4Smrg * Calculate the combined modelview-projection matrix. 6987117f1b4Smrg * 6997117f1b4Smrg * \param ctx GL context. 7007117f1b4Smrg * 7017117f1b4Smrg * Multiplies the top matrices of the projection and model view stacks into 7027117f1b4Smrg * __GLcontextRec::_ModelProjectMatrix via _math_matrix_mul_matrix() and 7037117f1b4Smrg * analyzes the resulting matrix via _math_matrix_analyse(). 7047117f1b4Smrg */ 7057117f1b4Smrgstatic void 7067117f1b4Smrgcalculate_model_project_matrix( GLcontext *ctx ) 7077117f1b4Smrg{ 7087117f1b4Smrg _math_matrix_mul_matrix( &ctx->_ModelProjectMatrix, 7097117f1b4Smrg ctx->ProjectionMatrixStack.Top, 7107117f1b4Smrg ctx->ModelviewMatrixStack.Top ); 7117117f1b4Smrg 7127117f1b4Smrg _math_matrix_analyse( &ctx->_ModelProjectMatrix ); 7137117f1b4Smrg} 7147117f1b4Smrg 7157117f1b4Smrg 7167117f1b4Smrg/** 7177117f1b4Smrg * Updates the combined modelview-projection matrix. 7187117f1b4Smrg * 7197117f1b4Smrg * \param ctx GL context. 7207117f1b4Smrg * \param new_state new state bit mask. 7217117f1b4Smrg * 7227117f1b4Smrg * If there is a new model view matrix then analyzes it. If there is a new 7237117f1b4Smrg * projection matrix, updates it. Finally calls 7247117f1b4Smrg * calculate_model_project_matrix() to recalculate the modelview-projection 7257117f1b4Smrg * matrix. 7267117f1b4Smrg */ 7277117f1b4Smrgvoid _mesa_update_modelview_project( GLcontext *ctx, GLuint new_state ) 7287117f1b4Smrg{ 7297117f1b4Smrg if (new_state & _NEW_MODELVIEW) { 7307117f1b4Smrg _math_matrix_analyse( ctx->ModelviewMatrixStack.Top ); 7317117f1b4Smrg 7327117f1b4Smrg /* Bring cull position uptodate. 7337117f1b4Smrg */ 7347117f1b4Smrg TRANSFORM_POINT3( ctx->Transform.CullObjPos, 7357117f1b4Smrg ctx->ModelviewMatrixStack.Top->inv, 7367117f1b4Smrg ctx->Transform.CullEyePos ); 7377117f1b4Smrg } 7387117f1b4Smrg 7397117f1b4Smrg 7407117f1b4Smrg if (new_state & _NEW_PROJECTION) 7417117f1b4Smrg update_projection( ctx ); 7427117f1b4Smrg 7437117f1b4Smrg /* Keep ModelviewProject uptodate always to allow tnl 7447117f1b4Smrg * implementations that go model->clip even when eye is required. 7457117f1b4Smrg */ 7467117f1b4Smrg calculate_model_project_matrix(ctx); 7477117f1b4Smrg} 7487117f1b4Smrg 7497117f1b4Smrg/*@}*/ 7507117f1b4Smrg 7517117f1b4Smrg 7527117f1b4Smrg/**********************************************************************/ 7537117f1b4Smrg/** Matrix stack initialization */ 7547117f1b4Smrg/*@{*/ 7557117f1b4Smrg 7567117f1b4Smrg 7577117f1b4Smrg/** 7587117f1b4Smrg * Initialize a matrix stack. 7597117f1b4Smrg * 7607117f1b4Smrg * \param stack matrix stack. 7617117f1b4Smrg * \param maxDepth maximum stack depth. 7627117f1b4Smrg * \param dirtyFlag dirty flag. 7637117f1b4Smrg * 7647117f1b4Smrg * Allocates an array of \p maxDepth elements for the matrix stack and calls 7657117f1b4Smrg * _math_matrix_ctr() and _math_matrix_alloc_inv() for each element to 7667117f1b4Smrg * initialize it. 7677117f1b4Smrg */ 7687117f1b4Smrgstatic void 7697117f1b4Smrginit_matrix_stack( struct gl_matrix_stack *stack, 7707117f1b4Smrg GLuint maxDepth, GLuint dirtyFlag ) 7717117f1b4Smrg{ 7727117f1b4Smrg GLuint i; 7737117f1b4Smrg 7747117f1b4Smrg stack->Depth = 0; 7757117f1b4Smrg stack->MaxDepth = maxDepth; 7767117f1b4Smrg stack->DirtyFlag = dirtyFlag; 7777117f1b4Smrg /* The stack */ 7787117f1b4Smrg stack->Stack = (GLmatrix *) CALLOC(maxDepth * sizeof(GLmatrix)); 7797117f1b4Smrg for (i = 0; i < maxDepth; i++) { 7807117f1b4Smrg _math_matrix_ctr(&stack->Stack[i]); 7817117f1b4Smrg _math_matrix_alloc_inv(&stack->Stack[i]); 7827117f1b4Smrg } 7837117f1b4Smrg stack->Top = stack->Stack; 7847117f1b4Smrg} 7857117f1b4Smrg 7867117f1b4Smrg/** 7877117f1b4Smrg * Free matrix stack. 7887117f1b4Smrg * 7897117f1b4Smrg * \param stack matrix stack. 7907117f1b4Smrg * 7917117f1b4Smrg * Calls _math_matrix_dtr() for each element of the matrix stack and 7927117f1b4Smrg * frees the array. 7937117f1b4Smrg */ 7947117f1b4Smrgstatic void 7957117f1b4Smrgfree_matrix_stack( struct gl_matrix_stack *stack ) 7967117f1b4Smrg{ 7977117f1b4Smrg GLuint i; 7987117f1b4Smrg for (i = 0; i < stack->MaxDepth; i++) { 7997117f1b4Smrg _math_matrix_dtr(&stack->Stack[i]); 8007117f1b4Smrg } 8017117f1b4Smrg FREE(stack->Stack); 8027117f1b4Smrg stack->Stack = stack->Top = NULL; 8037117f1b4Smrg} 8047117f1b4Smrg 8057117f1b4Smrg/*@}*/ 8067117f1b4Smrg 8077117f1b4Smrg 8087117f1b4Smrg/**********************************************************************/ 8097117f1b4Smrg/** \name Initialization */ 8107117f1b4Smrg/*@{*/ 8117117f1b4Smrg 8127117f1b4Smrg 8137117f1b4Smrg/** 8147117f1b4Smrg * Initialize the context matrix data. 8157117f1b4Smrg * 8167117f1b4Smrg * \param ctx GL context. 8177117f1b4Smrg * 8187117f1b4Smrg * Initializes each of the matrix stacks and the combined modelview-projection 8197117f1b4Smrg * matrix. 8207117f1b4Smrg */ 8217117f1b4Smrgvoid _mesa_init_matrix( GLcontext * ctx ) 8227117f1b4Smrg{ 8237117f1b4Smrg GLint i; 8247117f1b4Smrg 8257117f1b4Smrg /* Initialize matrix stacks */ 8267117f1b4Smrg init_matrix_stack(&ctx->ModelviewMatrixStack, MAX_MODELVIEW_STACK_DEPTH, 8277117f1b4Smrg _NEW_MODELVIEW); 8287117f1b4Smrg init_matrix_stack(&ctx->ProjectionMatrixStack, MAX_PROJECTION_STACK_DEPTH, 8297117f1b4Smrg _NEW_PROJECTION); 8307117f1b4Smrg init_matrix_stack(&ctx->ColorMatrixStack, MAX_COLOR_STACK_DEPTH, 8317117f1b4Smrg _NEW_COLOR_MATRIX); 8327117f1b4Smrg for (i = 0; i < MAX_TEXTURE_UNITS; i++) 8337117f1b4Smrg init_matrix_stack(&ctx->TextureMatrixStack[i], MAX_TEXTURE_STACK_DEPTH, 8347117f1b4Smrg _NEW_TEXTURE_MATRIX); 8357117f1b4Smrg for (i = 0; i < MAX_PROGRAM_MATRICES; i++) 8367117f1b4Smrg init_matrix_stack(&ctx->ProgramMatrixStack[i], 8377117f1b4Smrg MAX_PROGRAM_MATRIX_STACK_DEPTH, _NEW_TRACK_MATRIX); 8387117f1b4Smrg ctx->CurrentStack = &ctx->ModelviewMatrixStack; 8397117f1b4Smrg 8407117f1b4Smrg /* Init combined Modelview*Projection matrix */ 8417117f1b4Smrg _math_matrix_ctr( &ctx->_ModelProjectMatrix ); 8427117f1b4Smrg} 8437117f1b4Smrg 8447117f1b4Smrg 8457117f1b4Smrg/** 8467117f1b4Smrg * Free the context matrix data. 8477117f1b4Smrg * 8487117f1b4Smrg * \param ctx GL context. 8497117f1b4Smrg * 8507117f1b4Smrg * Frees each of the matrix stacks and the combined modelview-projection 8517117f1b4Smrg * matrix. 8527117f1b4Smrg */ 8537117f1b4Smrgvoid _mesa_free_matrix_data( GLcontext *ctx ) 8547117f1b4Smrg{ 8557117f1b4Smrg GLint i; 8567117f1b4Smrg 8577117f1b4Smrg free_matrix_stack(&ctx->ModelviewMatrixStack); 8587117f1b4Smrg free_matrix_stack(&ctx->ProjectionMatrixStack); 8597117f1b4Smrg free_matrix_stack(&ctx->ColorMatrixStack); 8607117f1b4Smrg for (i = 0; i < MAX_TEXTURE_UNITS; i++) 8617117f1b4Smrg free_matrix_stack(&ctx->TextureMatrixStack[i]); 8627117f1b4Smrg for (i = 0; i < MAX_PROGRAM_MATRICES; i++) 8637117f1b4Smrg free_matrix_stack(&ctx->ProgramMatrixStack[i]); 8647117f1b4Smrg /* combined Modelview*Projection matrix */ 8657117f1b4Smrg _math_matrix_dtr( &ctx->_ModelProjectMatrix ); 8667117f1b4Smrg 8677117f1b4Smrg} 8687117f1b4Smrg 8697117f1b4Smrg 8707117f1b4Smrg/** 8717117f1b4Smrg * Initialize the context transform attribute group. 8727117f1b4Smrg * 8737117f1b4Smrg * \param ctx GL context. 8747117f1b4Smrg * 8757117f1b4Smrg * \todo Move this to a new file with other 'transform' routines. 8767117f1b4Smrg */ 8777117f1b4Smrgvoid _mesa_init_transform( GLcontext *ctx ) 8787117f1b4Smrg{ 8797117f1b4Smrg GLint i; 8807117f1b4Smrg 8817117f1b4Smrg /* Transformation group */ 8827117f1b4Smrg ctx->Transform.MatrixMode = GL_MODELVIEW; 8837117f1b4Smrg ctx->Transform.Normalize = GL_FALSE; 8847117f1b4Smrg ctx->Transform.RescaleNormals = GL_FALSE; 8857117f1b4Smrg ctx->Transform.RasterPositionUnclipped = GL_FALSE; 8867117f1b4Smrg for (i=0;i<MAX_CLIP_PLANES;i++) { 8877117f1b4Smrg ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 ); 8887117f1b4Smrg } 8897117f1b4Smrg ctx->Transform.ClipPlanesEnabled = 0; 8907117f1b4Smrg 8917117f1b4Smrg ASSIGN_4V( ctx->Transform.CullObjPos, 0.0, 0.0, 1.0, 0.0 ); 8927117f1b4Smrg ASSIGN_4V( ctx->Transform.CullEyePos, 0.0, 0.0, 1.0, 0.0 ); 8937117f1b4Smrg} 8947117f1b4Smrg 8957117f1b4Smrg 8967117f1b4Smrg/** 8977117f1b4Smrg * Initialize the context viewport attribute group. 8987117f1b4Smrg * 8997117f1b4Smrg * \param ctx GL context. 9007117f1b4Smrg * 9017117f1b4Smrg * \todo Move this to a new file with other 'viewport' routines. 9027117f1b4Smrg */ 9037117f1b4Smrgvoid _mesa_init_viewport( GLcontext *ctx ) 9047117f1b4Smrg{ 9057117f1b4Smrg GLfloat depthMax = 65535.0F; /* sorf of arbitrary */ 9067117f1b4Smrg 9077117f1b4Smrg /* Viewport group */ 9087117f1b4Smrg ctx->Viewport.X = 0; 9097117f1b4Smrg ctx->Viewport.Y = 0; 9107117f1b4Smrg ctx->Viewport.Width = 0; 9117117f1b4Smrg ctx->Viewport.Height = 0; 9127117f1b4Smrg ctx->Viewport.Near = 0.0; 9137117f1b4Smrg ctx->Viewport.Far = 1.0; 9147117f1b4Smrg _math_matrix_ctr(&ctx->Viewport._WindowMap); 9157117f1b4Smrg 9167117f1b4Smrg _math_matrix_viewport(&ctx->Viewport._WindowMap, 0, 0, 0, 0, 9177117f1b4Smrg 0.0F, 1.0F, depthMax); 9187117f1b4Smrg} 9197117f1b4Smrg 9207117f1b4Smrg 9217117f1b4Smrg/** 9227117f1b4Smrg * Free the context viewport attribute group data. 9237117f1b4Smrg * 9247117f1b4Smrg * \param ctx GL context. 9257117f1b4Smrg * 9267117f1b4Smrg * \todo Move this to a new file with other 'viewport' routines. 9277117f1b4Smrg */ 9287117f1b4Smrgvoid _mesa_free_viewport_data( GLcontext *ctx ) 9297117f1b4Smrg{ 9307117f1b4Smrg _math_matrix_dtr(&ctx->Viewport._WindowMap); 9317117f1b4Smrg} 9327117f1b4Smrg 9337117f1b4Smrg/*@}*/ 934