2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 * -# 4x4 transformation matrices are stored in memory in column major order.
32 * -# Points/vertices are to be thought of as column vectors.
33 * -# Transformation of a point p by a matrix M is: p' = M * p
44 #include "math/m_matrix.h"
48 * Apply a perspective projection matrix.
50 * \param left left clipping plane coordinate.
51 * \param right right clipping plane coordinate.
52 * \param bottom bottom clipping plane coordinate.
53 * \param top top clipping plane coordinate.
54 * \param nearval distance to the near clipping plane.
55 * \param farval distance to the far clipping plane.
59 * Flushes vertices and validates parameters. Calls _math_matrix_frustum() with
60 * the top matrix of the current matrix stack and sets
61 * __GLcontextRec::NewState.
64 _mesa_Frustum( GLdouble left
, GLdouble right
,
65 GLdouble bottom
, GLdouble top
,
66 GLdouble nearval
, GLdouble farval
)
68 GET_CURRENT_CONTEXT(ctx
);
69 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
77 _mesa_error( ctx
, GL_INVALID_VALUE
, "glFrustum" );
81 _math_matrix_frustum( ctx
->CurrentStack
->Top
,
82 (GLfloat
) left
, (GLfloat
) right
,
83 (GLfloat
) bottom
, (GLfloat
) top
,
84 (GLfloat
) nearval
, (GLfloat
) farval
);
85 ctx
->NewState
|= ctx
->CurrentStack
->DirtyFlag
;
90 * Apply an orthographic projection matrix.
92 * \param left left clipping plane coordinate.
93 * \param right right clipping plane coordinate.
94 * \param bottom bottom clipping plane coordinate.
95 * \param top top clipping plane coordinate.
96 * \param nearval distance to the near clipping plane.
97 * \param farval distance to the far clipping plane.
101 * Flushes vertices and validates parameters. Calls _math_matrix_ortho() with
102 * the top matrix of the current matrix stack and sets
103 * __GLcontextRec::NewState.
106 _mesa_Ortho( GLdouble left
, GLdouble right
,
107 GLdouble bottom
, GLdouble top
,
108 GLdouble nearval
, GLdouble farval
)
110 GET_CURRENT_CONTEXT(ctx
);
111 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
113 if (MESA_VERBOSE
& VERBOSE_API
)
114 _mesa_debug(ctx
, "glOrtho(%f, %f, %f, %f, %f, %f)\n",
115 left
, right
, bottom
, top
, nearval
, farval
);
121 _mesa_error( ctx
, GL_INVALID_VALUE
, "glOrtho" );
125 _math_matrix_ortho( ctx
->CurrentStack
->Top
,
126 (GLfloat
) left
, (GLfloat
) right
,
127 (GLfloat
) bottom
, (GLfloat
) top
,
128 (GLfloat
) nearval
, (GLfloat
) farval
);
129 ctx
->NewState
|= ctx
->CurrentStack
->DirtyFlag
;
134 * Set the current matrix stack.
136 * \param mode matrix stack.
138 * \sa glMatrixMode().
140 * Flushes the vertices, validates the parameter and updates
141 * __GLcontextRec::CurrentStack and gl_transform_attrib::MatrixMode with the
142 * specified matrix stack.
145 _mesa_MatrixMode( GLenum mode
)
147 GET_CURRENT_CONTEXT(ctx
);
148 ASSERT_OUTSIDE_BEGIN_END(ctx
);
150 if (ctx
->Transform
.MatrixMode
== mode
&& mode
!= GL_TEXTURE
)
152 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
156 ctx
->CurrentStack
= &ctx
->ModelviewMatrixStack
;
159 ctx
->CurrentStack
= &ctx
->ProjectionMatrixStack
;
162 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
163 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glMatrixMode(texcoord unit)");
166 ctx
->CurrentStack
= &ctx
->TextureMatrixStack
[ctx
->Texture
.CurrentUnit
];
169 ctx
->CurrentStack
= &ctx
->ColorMatrixStack
;
179 if (ctx
->Extensions
.NV_vertex_program
) {
180 ctx
->CurrentStack
= &ctx
->ProgramMatrixStack
[mode
- GL_MATRIX0_NV
];
183 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMatrixMode(mode)" );
195 if (ctx
->Extensions
.ARB_vertex_program
||
196 ctx
->Extensions
.ARB_fragment_program
) {
197 const GLuint m
= mode
- GL_MATRIX0_ARB
;
198 if (m
> ctx
->Const
.MaxProgramMatrices
) {
199 _mesa_error(ctx
, GL_INVALID_ENUM
,
200 "glMatrixMode(GL_MATRIX%d_ARB)", m
);
203 ctx
->CurrentStack
= &ctx
->ProgramMatrixStack
[m
];
206 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMatrixMode(mode)" );
211 _mesa_error( ctx
, GL_INVALID_ENUM
, "glMatrixMode(mode)" );
215 ctx
->Transform
.MatrixMode
= mode
;
220 * Push the current matrix stack.
222 * \sa glPushMatrix().
224 * Verifies the current matrix stack is not full, and duplicates the top-most
225 * matrix in the stack. Marks __GLcontextRec::NewState with the stack dirty
229 _mesa_PushMatrix( void )
231 GET_CURRENT_CONTEXT(ctx
);
232 struct gl_matrix_stack
*stack
= ctx
->CurrentStack
;
233 ASSERT_OUTSIDE_BEGIN_END(ctx
);
235 if (MESA_VERBOSE
&VERBOSE_API
)
236 _mesa_debug(ctx
, "glPushMatrix %s\n",
237 _mesa_lookup_enum_by_nr(ctx
->Transform
.MatrixMode
));
239 if (stack
->Depth
+ 1 >= stack
->MaxDepth
) {
240 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
241 _mesa_error(ctx
, GL_STACK_OVERFLOW
,
242 "glPushMatrix(mode=GL_TEXTURE, unit=%d)",
243 ctx
->Texture
.CurrentUnit
);
246 _mesa_error(ctx
, GL_STACK_OVERFLOW
, "glPushMatrix(mode=%s)",
247 _mesa_lookup_enum_by_nr(ctx
->Transform
.MatrixMode
));
251 _math_matrix_copy( &stack
->Stack
[stack
->Depth
+ 1],
252 &stack
->Stack
[stack
->Depth
] );
254 stack
->Top
= &(stack
->Stack
[stack
->Depth
]);
255 ctx
->NewState
|= stack
->DirtyFlag
;
260 * Pop the current matrix stack.
264 * Flushes the vertices, verifies the current matrix stack is not empty, and
265 * moves the stack head down. Marks __GLcontextRec::NewState with the dirty
269 _mesa_PopMatrix( void )
271 GET_CURRENT_CONTEXT(ctx
);
272 struct gl_matrix_stack
*stack
= ctx
->CurrentStack
;
273 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
275 if (MESA_VERBOSE
&VERBOSE_API
)
276 _mesa_debug(ctx
, "glPopMatrix %s\n",
277 _mesa_lookup_enum_by_nr(ctx
->Transform
.MatrixMode
));
279 if (stack
->Depth
== 0) {
280 if (ctx
->Transform
.MatrixMode
== GL_TEXTURE
) {
281 _mesa_error(ctx
, GL_STACK_UNDERFLOW
,
282 "glPopMatrix(mode=GL_TEXTURE, unit=%d)",
283 ctx
->Texture
.CurrentUnit
);
286 _mesa_error(ctx
, GL_STACK_UNDERFLOW
, "glPopMatrix(mode=%s)",
287 _mesa_lookup_enum_by_nr(ctx
->Transform
.MatrixMode
));
292 stack
->Top
= &(stack
->Stack
[stack
->Depth
]);
293 ctx
->NewState
|= stack
->DirtyFlag
;
298 * Replace the current matrix with the identity matrix.
300 * \sa glLoadIdentity().
302 * Flushes the vertices and calls _math_matrix_set_identity() with the top-most
303 * matrix in the current stack. Marks __GLcontextRec::NewState with the stack
307 _mesa_LoadIdentity( void )
309 GET_CURRENT_CONTEXT(ctx
);
310 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
312 if (MESA_VERBOSE
& VERBOSE_API
)
313 _mesa_debug(ctx
, "glLoadIdentity()");
315 _math_matrix_set_identity( ctx
->CurrentStack
->Top
);
316 ctx
->NewState
|= ctx
->CurrentStack
->DirtyFlag
;
321 * Replace the current matrix with a given matrix.
325 * \sa glLoadMatrixf().
327 * Flushes the vertices and calls _math_matrix_loadf() with the top-most matrix
328 * in the current stack and the given matrix. Marks __GLcontextRec::NewState
329 * with the dirty stack flag.
332 _mesa_LoadMatrixf( const GLfloat
*m
)
334 GET_CURRENT_CONTEXT(ctx
);
336 if (MESA_VERBOSE
& VERBOSE_API
)
338 "glLoadMatrix(%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f\n",
339 m
[0], m
[4], m
[8], m
[12],
340 m
[1], m
[5], m
[9], m
[13],
341 m
[2], m
[6], m
[10], m
[14],
342 m
[3], m
[7], m
[11], m
[15]);
344 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
345 _math_matrix_loadf( ctx
->CurrentStack
->Top
, m
);
346 ctx
->NewState
|= ctx
->CurrentStack
->DirtyFlag
;
351 * Multiply the current matrix with a given matrix.
355 * \sa glMultMatrixf().
357 * Flushes the vertices and calls _math_matrix_mul_floats() with the top-most
358 * matrix in the current stack and the given matrix. Marks
359 * __GLcontextRec::NewState with the dirty stack flag.
362 _mesa_MultMatrixf( const GLfloat
*m
)
364 GET_CURRENT_CONTEXT(ctx
);
366 if (MESA_VERBOSE
& VERBOSE_API
)
368 "glMultMatrix(%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f\n",
369 m
[0], m
[4], m
[8], m
[12],
370 m
[1], m
[5], m
[9], m
[13],
371 m
[2], m
[6], m
[10], m
[14],
372 m
[3], m
[7], m
[11], m
[15]);
373 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
374 _math_matrix_mul_floats( ctx
->CurrentStack
->Top
, m
);
375 ctx
->NewState
|= ctx
->CurrentStack
->DirtyFlag
;
380 * Multiply the current matrix with a rotation matrix.
382 * \param angle angle of rotation, in degrees.
383 * \param x rotation vector x coordinate.
384 * \param y rotation vector y coordinate.
385 * \param z rotation vector z coordinate.
389 * Flushes the vertices and calls _math_matrix_rotate() with the top-most
390 * matrix in the current stack and the given parameters. Marks
391 * __GLcontextRec::NewState with the dirty stack flag.
394 _mesa_Rotatef( GLfloat angle
, GLfloat x
, GLfloat y
, GLfloat z
)
396 GET_CURRENT_CONTEXT(ctx
);
397 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
399 _math_matrix_rotate( ctx
->CurrentStack
->Top
, angle
, x
, y
, z
);
400 ctx
->NewState
|= ctx
->CurrentStack
->DirtyFlag
;
406 * Multiply the current matrix with a general scaling matrix.
408 * \param x x axis scale factor.
409 * \param y y axis scale factor.
410 * \param z z axis scale factor.
414 * Flushes the vertices and calls _math_matrix_scale() with the top-most
415 * matrix in the current stack and the given parameters. Marks
416 * __GLcontextRec::NewState with the dirty stack flag.
419 _mesa_Scalef( GLfloat x
, GLfloat y
, GLfloat z
)
421 GET_CURRENT_CONTEXT(ctx
);
422 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
423 _math_matrix_scale( ctx
->CurrentStack
->Top
, x
, y
, z
);
424 ctx
->NewState
|= ctx
->CurrentStack
->DirtyFlag
;
429 * Multiply the current matrix with a translation matrix.
431 * \param x translation vector x coordinate.
432 * \param y translation vector y coordinate.
433 * \param z translation vector z coordinate.
435 * \sa glTranslatef().
437 * Flushes the vertices and calls _math_matrix_translate() with the top-most
438 * matrix in the current stack and the given parameters. Marks
439 * __GLcontextRec::NewState with the dirty stack flag.
442 _mesa_Translatef( GLfloat x
, GLfloat y
, GLfloat z
)
444 GET_CURRENT_CONTEXT(ctx
);
445 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
446 _math_matrix_translate( ctx
->CurrentStack
->Top
, x
, y
, z
);
447 ctx
->NewState
|= ctx
->CurrentStack
->DirtyFlag
;
453 _mesa_LoadMatrixd( const GLdouble
*m
)
458 for (i
= 0; i
< 16; i
++)
459 f
[i
] = (GLfloat
) m
[i
];
460 _mesa_LoadMatrixf(f
);
464 _mesa_MultMatrixd( const GLdouble
*m
)
469 for (i
= 0; i
< 16; i
++)
470 f
[i
] = (GLfloat
) m
[i
];
471 _mesa_MultMatrixf( f
);
476 _mesa_Rotated( GLdouble angle
, GLdouble x
, GLdouble y
, GLdouble z
)
478 _mesa_Rotatef((GLfloat
) angle
, (GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
);
483 _mesa_Scaled( GLdouble x
, GLdouble y
, GLdouble z
)
485 _mesa_Scalef((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
);
490 _mesa_Translated( GLdouble x
, GLdouble y
, GLdouble z
)
492 _mesa_Translatef((GLfloat
) x
, (GLfloat
) y
, (GLfloat
) z
);
499 _mesa_LoadTransposeMatrixfARB( const GLfloat
*m
)
503 _math_transposef(tm
, m
);
504 _mesa_LoadMatrixf(tm
);
509 _mesa_LoadTransposeMatrixdARB( const GLdouble
*m
)
513 _math_transposefd(tm
, m
);
514 _mesa_LoadMatrixf(tm
);
519 _mesa_MultTransposeMatrixfARB( const GLfloat
*m
)
523 _math_transposef(tm
, m
);
524 _mesa_MultMatrixf(tm
);
529 _mesa_MultTransposeMatrixdARB( const GLdouble
*m
)
533 _math_transposefd(tm
, m
);
534 _mesa_MultMatrixf(tm
);
541 * \param x, y coordinates of the lower-left corner of the viewport rectangle.
542 * \param width width of the viewport rectangle.
543 * \param height height of the viewport rectangle.
545 * \sa Called via glViewport() or display list execution.
547 * Flushes the vertices and calls _mesa_set_viewport() with the given
551 _mesa_Viewport( GLint x
, GLint y
, GLsizei width
, GLsizei height
)
553 GET_CURRENT_CONTEXT(ctx
);
554 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
555 _mesa_set_viewport(ctx
, x
, y
, width
, height
);
560 * Set new viewport parameters and update derived state (the _WindowMap
561 * matrix). Usually called from _mesa_Viewport().
563 * \param ctx GL context.
564 * \param x, y coordinates of the lower left corner of the viewport rectangle.
565 * \param width width of the viewport rectangle.
566 * \param height height of the viewport rectangle.
569 _mesa_set_viewport( GLcontext
*ctx
, GLint x
, GLint y
,
570 GLsizei width
, GLsizei height
)
572 if (MESA_VERBOSE
& VERBOSE_API
)
573 _mesa_debug(ctx
, "glViewport %d %d %d %d\n", x
, y
, width
, height
);
575 if (width
< 0 || height
< 0) {
576 _mesa_error( ctx
, GL_INVALID_VALUE
,
577 "glViewport(%d, %d, %d, %d)", x
, y
, width
, height
);
581 /* clamp width and height to the implementation dependent range */
582 width
= CLAMP(width
, 1, (GLsizei
) ctx
->Const
.MaxViewportWidth
);
583 height
= CLAMP(height
, 1, (GLsizei
) ctx
->Const
.MaxViewportHeight
);
586 ctx
->Viewport
.Width
= width
;
588 ctx
->Viewport
.Height
= height
;
589 ctx
->NewState
|= _NEW_VIEWPORT
;
592 /* XXX remove this someday. Currently the DRI drivers rely on
593 * the WindowMap matrix being up to date in the driver's Viewport
594 * and DepthRange functions.
596 _math_matrix_viewport(&ctx
->Viewport
._WindowMap
,
597 ctx
->Viewport
.X
, ctx
->Viewport
.Y
,
598 ctx
->Viewport
.Width
, ctx
->Viewport
.Height
,
599 ctx
->Viewport
.Near
, ctx
->Viewport
.Far
,
600 ctx
->DrawBuffer
->_DepthMaxF
);
603 if (ctx
->Driver
.Viewport
) {
604 /* Many drivers will use this call to check for window size changes
605 * and reallocate the z/stencil/accum/etc buffers if needed.
607 (*ctx
->Driver
.Viewport
)( ctx
, x
, y
, width
, height
);
614 * Called by glDepthRange
616 * \param nearval specifies the Z buffer value which should correspond to
617 * the near clip plane
618 * \param farval specifies the Z buffer value which should correspond to
622 _mesa_DepthRange( GLclampd nearval
, GLclampd farval
)
624 GET_CURRENT_CONTEXT(ctx
);
625 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
627 if (MESA_VERBOSE
&VERBOSE_API
)
628 _mesa_debug(ctx
, "glDepthRange %f %f\n", nearval
, farval
);
630 ctx
->Viewport
.Near
= (GLfloat
) CLAMP( nearval
, 0.0, 1.0 );
631 ctx
->Viewport
.Far
= (GLfloat
) CLAMP( farval
, 0.0, 1.0 );
632 ctx
->NewState
|= _NEW_VIEWPORT
;
635 /* XXX remove this someday. Currently the DRI drivers rely on
636 * the WindowMap matrix being up to date in the driver's Viewport
637 * and DepthRange functions.
639 _math_matrix_viewport(&ctx
->Viewport
._WindowMap
,
640 ctx
->Viewport
.X
, ctx
->Viewport
.Y
,
641 ctx
->Viewport
.Width
, ctx
->Viewport
.Height
,
642 ctx
->Viewport
.Near
, ctx
->Viewport
.Far
,
643 ctx
->DrawBuffer
->_DepthMaxF
);
646 if (ctx
->Driver
.DepthRange
) {
647 (*ctx
->Driver
.DepthRange
)( ctx
, nearval
, farval
);
654 /**********************************************************************/
655 /** \name State management */
660 * Update the projection matrix stack.
662 * \param ctx GL context.
664 * Calls _math_matrix_analyse() with the top-matrix of the projection matrix
665 * stack, and recomputes user clip positions if necessary.
667 * \note This routine references __GLcontextRec::Tranform attribute values to
668 * compute userclip positions in clip space, but is only called on
669 * _NEW_PROJECTION. The _mesa_ClipPlane() function keeps these values up to
670 * date across changes to the __GLcontextRec::Transform attributes.
673 update_projection( GLcontext
*ctx
)
675 _math_matrix_analyse( ctx
->ProjectionMatrixStack
.Top
);
678 /* Recompute clip plane positions in clipspace. This is also done
679 * in _mesa_ClipPlane().
681 if (ctx
->Transform
.ClipPlanesEnabled
) {
683 for (p
= 0; p
< ctx
->Const
.MaxClipPlanes
; p
++) {
684 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
685 _mesa_transform_vector( ctx
->Transform
._ClipUserPlane
[p
],
686 ctx
->Transform
.EyeUserPlane
[p
],
687 ctx
->ProjectionMatrixStack
.Top
->inv
);
696 * Calculate the combined modelview-projection matrix.
698 * \param ctx GL context.
700 * Multiplies the top matrices of the projection and model view stacks into
701 * __GLcontextRec::_ModelProjectMatrix via _math_matrix_mul_matrix() and
702 * analyzes the resulting matrix via _math_matrix_analyse().
705 calculate_model_project_matrix( GLcontext
*ctx
)
707 _math_matrix_mul_matrix( &ctx
->_ModelProjectMatrix
,
708 ctx
->ProjectionMatrixStack
.Top
,
709 ctx
->ModelviewMatrixStack
.Top
);
711 _math_matrix_analyse( &ctx
->_ModelProjectMatrix
);
716 * Updates the combined modelview-projection matrix.
718 * \param ctx GL context.
719 * \param new_state new state bit mask.
721 * If there is a new model view matrix then analyzes it. If there is a new
722 * projection matrix, updates it. Finally calls
723 * calculate_model_project_matrix() to recalculate the modelview-projection
726 void _mesa_update_modelview_project( GLcontext
*ctx
, GLuint new_state
)
728 if (new_state
& _NEW_MODELVIEW
) {
729 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
731 /* Bring cull position uptodate.
733 TRANSFORM_POINT3( ctx
->Transform
.CullObjPos
,
734 ctx
->ModelviewMatrixStack
.Top
->inv
,
735 ctx
->Transform
.CullEyePos
);
739 if (new_state
& _NEW_PROJECTION
)
740 update_projection( ctx
);
742 /* Keep ModelviewProject uptodate always to allow tnl
743 * implementations that go model->clip even when eye is required.
745 calculate_model_project_matrix(ctx
);
751 /**********************************************************************/
752 /** Matrix stack initialization */
757 * Initialize a matrix stack.
759 * \param stack matrix stack.
760 * \param maxDepth maximum stack depth.
761 * \param dirtyFlag dirty flag.
763 * Allocates an array of \p maxDepth elements for the matrix stack and calls
764 * _math_matrix_ctr() and _math_matrix_alloc_inv() for each element to
768 init_matrix_stack( struct gl_matrix_stack
*stack
,
769 GLuint maxDepth
, GLuint dirtyFlag
)
774 stack
->MaxDepth
= maxDepth
;
775 stack
->DirtyFlag
= dirtyFlag
;
777 stack
->Stack
= (GLmatrix
*) CALLOC(maxDepth
* sizeof(GLmatrix
));
778 for (i
= 0; i
< maxDepth
; i
++) {
779 _math_matrix_ctr(&stack
->Stack
[i
]);
780 _math_matrix_alloc_inv(&stack
->Stack
[i
]);
782 stack
->Top
= stack
->Stack
;
788 * \param stack matrix stack.
790 * Calls _math_matrix_dtr() for each element of the matrix stack and
794 free_matrix_stack( struct gl_matrix_stack
*stack
)
797 for (i
= 0; i
< stack
->MaxDepth
; i
++) {
798 _math_matrix_dtr(&stack
->Stack
[i
]);
801 stack
->Stack
= stack
->Top
= NULL
;
807 /**********************************************************************/
808 /** \name Initialization */
813 * Initialize the context matrix data.
815 * \param ctx GL context.
817 * Initializes each of the matrix stacks and the combined modelview-projection
820 void _mesa_init_matrix( GLcontext
* ctx
)
824 /* Initialize matrix stacks */
825 init_matrix_stack(&ctx
->ModelviewMatrixStack
, MAX_MODELVIEW_STACK_DEPTH
,
827 init_matrix_stack(&ctx
->ProjectionMatrixStack
, MAX_PROJECTION_STACK_DEPTH
,
829 init_matrix_stack(&ctx
->ColorMatrixStack
, MAX_COLOR_STACK_DEPTH
,
831 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++)
832 init_matrix_stack(&ctx
->TextureMatrixStack
[i
], MAX_TEXTURE_STACK_DEPTH
,
833 _NEW_TEXTURE_MATRIX
);
834 for (i
= 0; i
< MAX_PROGRAM_MATRICES
; i
++)
835 init_matrix_stack(&ctx
->ProgramMatrixStack
[i
],
836 MAX_PROGRAM_MATRIX_STACK_DEPTH
, _NEW_TRACK_MATRIX
);
837 ctx
->CurrentStack
= &ctx
->ModelviewMatrixStack
;
839 /* Init combined Modelview*Projection matrix */
840 _math_matrix_ctr( &ctx
->_ModelProjectMatrix
);
845 * Free the context matrix data.
847 * \param ctx GL context.
849 * Frees each of the matrix stacks and the combined modelview-projection
852 void _mesa_free_matrix_data( GLcontext
*ctx
)
856 free_matrix_stack(&ctx
->ModelviewMatrixStack
);
857 free_matrix_stack(&ctx
->ProjectionMatrixStack
);
858 free_matrix_stack(&ctx
->ColorMatrixStack
);
859 for (i
= 0; i
< MAX_TEXTURE_UNITS
; i
++)
860 free_matrix_stack(&ctx
->TextureMatrixStack
[i
]);
861 for (i
= 0; i
< MAX_PROGRAM_MATRICES
; i
++)
862 free_matrix_stack(&ctx
->ProgramMatrixStack
[i
]);
863 /* combined Modelview*Projection matrix */
864 _math_matrix_dtr( &ctx
->_ModelProjectMatrix
);
870 * Initialize the context transform attribute group.
872 * \param ctx GL context.
874 * \todo Move this to a new file with other 'transform' routines.
876 void _mesa_init_transform( GLcontext
*ctx
)
880 /* Transformation group */
881 ctx
->Transform
.MatrixMode
= GL_MODELVIEW
;
882 ctx
->Transform
.Normalize
= GL_FALSE
;
883 ctx
->Transform
.RescaleNormals
= GL_FALSE
;
884 ctx
->Transform
.RasterPositionUnclipped
= GL_FALSE
;
885 for (i
=0;i
<MAX_CLIP_PLANES
;i
++) {
886 ASSIGN_4V( ctx
->Transform
.EyeUserPlane
[i
], 0.0, 0.0, 0.0, 0.0 );
888 ctx
->Transform
.ClipPlanesEnabled
= 0;
890 ASSIGN_4V( ctx
->Transform
.CullObjPos
, 0.0, 0.0, 1.0, 0.0 );
891 ASSIGN_4V( ctx
->Transform
.CullEyePos
, 0.0, 0.0, 1.0, 0.0 );
896 * Initialize the context viewport attribute group.
898 * \param ctx GL context.
900 * \todo Move this to a new file with other 'viewport' routines.
902 void _mesa_init_viewport( GLcontext
*ctx
)
904 GLfloat depthMax
= 65535.0F
; /* sorf of arbitrary */
909 ctx
->Viewport
.Width
= 0;
910 ctx
->Viewport
.Height
= 0;
911 ctx
->Viewport
.Near
= 0.0;
912 ctx
->Viewport
.Far
= 1.0;
913 _math_matrix_ctr(&ctx
->Viewport
._WindowMap
);
915 _math_matrix_viewport(&ctx
->Viewport
._WindowMap
, 0, 0, 0, 0,
916 0.0F
, 1.0F
, depthMax
);
921 * Free the context viewport attribute group data.
923 * \param ctx GL context.
925 * \todo Move this to a new file with other 'viewport' routines.
927 void _mesa_free_viewport_data( GLcontext
*ctx
)
929 _math_matrix_dtr(&ctx
->Viewport
._WindowMap
);