mesa: add infra for ARB_shader_clock
[mesa.git] / src / mesa / main / matrix.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * \file matrix.c
29 * Matrix operations.
30 *
31 * \note
32 * -# 4x4 transformation matrices are stored in memory in column major order.
33 * -# Points/vertices are to be thought of as column vectors.
34 * -# Transformation of a point p by a matrix M is: p' = M * p
35 */
36
37
38 #include "glheader.h"
39 #include "imports.h"
40 #include "context.h"
41 #include "enums.h"
42 #include "macros.h"
43 #include "matrix.h"
44 #include "mtypes.h"
45 #include "math/m_matrix.h"
46
47
48 /**
49 * Apply a perspective projection matrix.
50 *
51 * \param left left clipping plane coordinate.
52 * \param right right clipping plane coordinate.
53 * \param bottom bottom clipping plane coordinate.
54 * \param top top clipping plane coordinate.
55 * \param nearval distance to the near clipping plane.
56 * \param farval distance to the far clipping plane.
57 *
58 * \sa glFrustum().
59 *
60 * Flushes vertices and validates parameters. Calls _math_matrix_frustum() with
61 * the top matrix of the current matrix stack and sets
62 * __struct gl_contextRec::NewState.
63 */
64 void GLAPIENTRY
65 _mesa_Frustum( GLdouble left, GLdouble right,
66 GLdouble bottom, GLdouble top,
67 GLdouble nearval, GLdouble farval )
68 {
69 GET_CURRENT_CONTEXT(ctx);
70
71 FLUSH_VERTICES(ctx, 0);
72
73 if (nearval <= 0.0 ||
74 farval <= 0.0 ||
75 nearval == farval ||
76 left == right ||
77 top == bottom)
78 {
79 _mesa_error( ctx, GL_INVALID_VALUE, "glFrustum" );
80 return;
81 }
82
83 _math_matrix_frustum( ctx->CurrentStack->Top,
84 (GLfloat) left, (GLfloat) right,
85 (GLfloat) bottom, (GLfloat) top,
86 (GLfloat) nearval, (GLfloat) farval );
87 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
88 }
89
90
91 /**
92 * Apply an orthographic projection matrix.
93 *
94 * \param left left clipping plane coordinate.
95 * \param right right clipping plane coordinate.
96 * \param bottom bottom clipping plane coordinate.
97 * \param top top clipping plane coordinate.
98 * \param nearval distance to the near clipping plane.
99 * \param farval distance to the far clipping plane.
100 *
101 * \sa glOrtho().
102 *
103 * Flushes vertices and validates parameters. Calls _math_matrix_ortho() with
104 * the top matrix of the current matrix stack and sets
105 * __struct gl_contextRec::NewState.
106 */
107 void GLAPIENTRY
108 _mesa_Ortho( GLdouble left, GLdouble right,
109 GLdouble bottom, GLdouble top,
110 GLdouble nearval, GLdouble farval )
111 {
112 GET_CURRENT_CONTEXT(ctx);
113
114 FLUSH_VERTICES(ctx, 0);
115
116 if (MESA_VERBOSE & VERBOSE_API)
117 _mesa_debug(ctx, "glOrtho(%f, %f, %f, %f, %f, %f)\n",
118 left, right, bottom, top, nearval, farval);
119
120 if (left == right ||
121 bottom == top ||
122 nearval == farval)
123 {
124 _mesa_error( ctx, GL_INVALID_VALUE, "glOrtho" );
125 return;
126 }
127
128 _math_matrix_ortho( ctx->CurrentStack->Top,
129 (GLfloat) left, (GLfloat) right,
130 (GLfloat) bottom, (GLfloat) top,
131 (GLfloat) nearval, (GLfloat) farval );
132 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
133 }
134
135
136 /**
137 * Set the current matrix stack.
138 *
139 * \param mode matrix stack.
140 *
141 * \sa glMatrixMode().
142 *
143 * Flushes the vertices, validates the parameter and updates
144 * __struct gl_contextRec::CurrentStack and gl_transform_attrib::MatrixMode
145 * with the specified matrix stack.
146 */
147 void GLAPIENTRY
148 _mesa_MatrixMode( GLenum mode )
149 {
150 GET_CURRENT_CONTEXT(ctx);
151
152 if (ctx->Transform.MatrixMode == mode && mode != GL_TEXTURE)
153 return;
154
155 switch (mode) {
156 case GL_MODELVIEW:
157 ctx->CurrentStack = &ctx->ModelviewMatrixStack;
158 break;
159 case GL_PROJECTION:
160 ctx->CurrentStack = &ctx->ProjectionMatrixStack;
161 break;
162 case GL_TEXTURE:
163 /* This error check is disabled because if we're called from
164 * glPopAttrib() when the active texture unit is >= MaxTextureCoordUnits
165 * we'll generate an unexpected error.
166 * From the GL_ARB_vertex_shader spec it sounds like we should instead
167 * do error checking in other places when we actually try to access
168 * texture matrices beyond MaxTextureCoordUnits.
169 */
170 #if 0
171 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
172 _mesa_error(ctx, GL_INVALID_OPERATION,
173 "glMatrixMode(invalid tex unit %d)",
174 ctx->Texture.CurrentUnit);
175 return;
176 }
177 #endif
178 assert(ctx->Texture.CurrentUnit < ARRAY_SIZE(ctx->TextureMatrixStack));
179 ctx->CurrentStack = &ctx->TextureMatrixStack[ctx->Texture.CurrentUnit];
180 break;
181 case GL_MATRIX0_ARB:
182 case GL_MATRIX1_ARB:
183 case GL_MATRIX2_ARB:
184 case GL_MATRIX3_ARB:
185 case GL_MATRIX4_ARB:
186 case GL_MATRIX5_ARB:
187 case GL_MATRIX6_ARB:
188 case GL_MATRIX7_ARB:
189 if (ctx->API == API_OPENGL_COMPAT
190 && (ctx->Extensions.ARB_vertex_program ||
191 ctx->Extensions.ARB_fragment_program)) {
192 const GLuint m = mode - GL_MATRIX0_ARB;
193 if (m > ctx->Const.MaxProgramMatrices) {
194 _mesa_error(ctx, GL_INVALID_ENUM,
195 "glMatrixMode(GL_MATRIX%d_ARB)", m);
196 return;
197 }
198 ctx->CurrentStack = &ctx->ProgramMatrixStack[m];
199 }
200 else {
201 _mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode(mode)" );
202 return;
203 }
204 break;
205 default:
206 _mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode(mode)" );
207 return;
208 }
209
210 ctx->Transform.MatrixMode = mode;
211 }
212
213
214 /**
215 * Push the current matrix stack.
216 *
217 * \sa glPushMatrix().
218 *
219 * Verifies the current matrix stack is not full, and duplicates the top-most
220 * matrix in the stack.
221 * Marks __struct gl_contextRec::NewState with the stack dirty flag.
222 */
223 void GLAPIENTRY
224 _mesa_PushMatrix( void )
225 {
226 GET_CURRENT_CONTEXT(ctx);
227 struct gl_matrix_stack *stack = ctx->CurrentStack;
228
229 if (MESA_VERBOSE&VERBOSE_API)
230 _mesa_debug(ctx, "glPushMatrix %s\n",
231 _mesa_enum_to_string(ctx->Transform.MatrixMode));
232
233 if (stack->Depth + 1 >= stack->MaxDepth) {
234 if (ctx->Transform.MatrixMode == GL_TEXTURE) {
235 _mesa_error(ctx, GL_STACK_OVERFLOW,
236 "glPushMatrix(mode=GL_TEXTURE, unit=%d)",
237 ctx->Texture.CurrentUnit);
238 }
239 else {
240 _mesa_error(ctx, GL_STACK_OVERFLOW, "glPushMatrix(mode=%s)",
241 _mesa_enum_to_string(ctx->Transform.MatrixMode));
242 }
243 return;
244 }
245 _math_matrix_copy( &stack->Stack[stack->Depth + 1],
246 &stack->Stack[stack->Depth] );
247 stack->Depth++;
248 stack->Top = &(stack->Stack[stack->Depth]);
249 ctx->NewState |= stack->DirtyFlag;
250 }
251
252
253 /**
254 * Pop the current matrix stack.
255 *
256 * \sa glPopMatrix().
257 *
258 * Flushes the vertices, verifies the current matrix stack is not empty, and
259 * moves the stack head down.
260 * Marks __struct gl_contextRec::NewState with the dirty stack flag.
261 */
262 void GLAPIENTRY
263 _mesa_PopMatrix( void )
264 {
265 GET_CURRENT_CONTEXT(ctx);
266 struct gl_matrix_stack *stack = ctx->CurrentStack;
267
268 FLUSH_VERTICES(ctx, 0);
269
270 if (MESA_VERBOSE&VERBOSE_API)
271 _mesa_debug(ctx, "glPopMatrix %s\n",
272 _mesa_enum_to_string(ctx->Transform.MatrixMode));
273
274 if (stack->Depth == 0) {
275 if (ctx->Transform.MatrixMode == GL_TEXTURE) {
276 _mesa_error(ctx, GL_STACK_UNDERFLOW,
277 "glPopMatrix(mode=GL_TEXTURE, unit=%d)",
278 ctx->Texture.CurrentUnit);
279 }
280 else {
281 _mesa_error(ctx, GL_STACK_UNDERFLOW, "glPopMatrix(mode=%s)",
282 _mesa_enum_to_string(ctx->Transform.MatrixMode));
283 }
284 return;
285 }
286 stack->Depth--;
287 stack->Top = &(stack->Stack[stack->Depth]);
288 ctx->NewState |= stack->DirtyFlag;
289 }
290
291
292 /**
293 * Replace the current matrix with the identity matrix.
294 *
295 * \sa glLoadIdentity().
296 *
297 * Flushes the vertices and calls _math_matrix_set_identity() with the
298 * top-most matrix in the current stack.
299 * Marks __struct gl_contextRec::NewState with the stack dirty flag.
300 */
301 void GLAPIENTRY
302 _mesa_LoadIdentity( void )
303 {
304 GET_CURRENT_CONTEXT(ctx);
305
306 FLUSH_VERTICES(ctx, 0);
307
308 if (MESA_VERBOSE & VERBOSE_API)
309 _mesa_debug(ctx, "glLoadIdentity()\n");
310
311 _math_matrix_set_identity( ctx->CurrentStack->Top );
312 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
313 }
314
315
316 /**
317 * Replace the current matrix with a given matrix.
318 *
319 * \param m matrix.
320 *
321 * \sa glLoadMatrixf().
322 *
323 * Flushes the vertices and calls _math_matrix_loadf() with the top-most
324 * matrix in the current stack and the given matrix.
325 * Marks __struct gl_contextRec::NewState with the dirty stack flag.
326 */
327 void GLAPIENTRY
328 _mesa_LoadMatrixf( const GLfloat *m )
329 {
330 GET_CURRENT_CONTEXT(ctx);
331 if (!m) return;
332 if (MESA_VERBOSE & VERBOSE_API)
333 _mesa_debug(ctx,
334 "glLoadMatrix(%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f\n",
335 m[0], m[4], m[8], m[12],
336 m[1], m[5], m[9], m[13],
337 m[2], m[6], m[10], m[14],
338 m[3], m[7], m[11], m[15]);
339
340 FLUSH_VERTICES(ctx, 0);
341 _math_matrix_loadf( ctx->CurrentStack->Top, m );
342 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
343 }
344
345
346 /**
347 * Multiply the current matrix with a given matrix.
348 *
349 * \param m matrix.
350 *
351 * \sa glMultMatrixf().
352 *
353 * Flushes the vertices and calls _math_matrix_mul_floats() with the top-most
354 * matrix in the current stack and the given matrix. Marks
355 * __struct gl_contextRec::NewState with the dirty stack flag.
356 */
357 void GLAPIENTRY
358 _mesa_MultMatrixf( const GLfloat *m )
359 {
360 GET_CURRENT_CONTEXT(ctx);
361 if (!m) return;
362 if (MESA_VERBOSE & VERBOSE_API)
363 _mesa_debug(ctx,
364 "glMultMatrix(%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f\n",
365 m[0], m[4], m[8], m[12],
366 m[1], m[5], m[9], m[13],
367 m[2], m[6], m[10], m[14],
368 m[3], m[7], m[11], m[15]);
369
370 FLUSH_VERTICES(ctx, 0);
371 _math_matrix_mul_floats( ctx->CurrentStack->Top, m );
372 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
373 }
374
375
376 /**
377 * Multiply the current matrix with a rotation matrix.
378 *
379 * \param angle angle of rotation, in degrees.
380 * \param x rotation vector x coordinate.
381 * \param y rotation vector y coordinate.
382 * \param z rotation vector z coordinate.
383 *
384 * \sa glRotatef().
385 *
386 * Flushes the vertices and calls _math_matrix_rotate() with the top-most
387 * matrix in the current stack and the given parameters. Marks
388 * __struct gl_contextRec::NewState with the dirty stack flag.
389 */
390 void GLAPIENTRY
391 _mesa_Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
392 {
393 GET_CURRENT_CONTEXT(ctx);
394
395 FLUSH_VERTICES(ctx, 0);
396 if (angle != 0.0F) {
397 _math_matrix_rotate( ctx->CurrentStack->Top, angle, x, y, z);
398 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
399 }
400 }
401
402
403 /**
404 * Multiply the current matrix with a general scaling matrix.
405 *
406 * \param x x axis scale factor.
407 * \param y y axis scale factor.
408 * \param z z axis scale factor.
409 *
410 * \sa glScalef().
411 *
412 * Flushes the vertices and calls _math_matrix_scale() with the top-most
413 * matrix in the current stack and the given parameters. Marks
414 * __struct gl_contextRec::NewState with the dirty stack flag.
415 */
416 void GLAPIENTRY
417 _mesa_Scalef( GLfloat x, GLfloat y, GLfloat z )
418 {
419 GET_CURRENT_CONTEXT(ctx);
420
421 FLUSH_VERTICES(ctx, 0);
422 _math_matrix_scale( ctx->CurrentStack->Top, x, y, z);
423 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
424 }
425
426
427 /**
428 * Multiply the current matrix with a translation matrix.
429 *
430 * \param x translation vector x coordinate.
431 * \param y translation vector y coordinate.
432 * \param z translation vector z coordinate.
433 *
434 * \sa glTranslatef().
435 *
436 * Flushes the vertices and calls _math_matrix_translate() with the top-most
437 * matrix in the current stack and the given parameters. Marks
438 * __struct gl_contextRec::NewState with the dirty stack flag.
439 */
440 void GLAPIENTRY
441 _mesa_Translatef( GLfloat x, GLfloat y, GLfloat z )
442 {
443 GET_CURRENT_CONTEXT(ctx);
444
445 FLUSH_VERTICES(ctx, 0);
446 _math_matrix_translate( ctx->CurrentStack->Top, x, y, z);
447 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
448 }
449
450
451 void GLAPIENTRY
452 _mesa_LoadMatrixd( const GLdouble *m )
453 {
454 GLint i;
455 GLfloat f[16];
456 if (!m) return;
457 for (i = 0; i < 16; i++)
458 f[i] = (GLfloat) m[i];
459 _mesa_LoadMatrixf(f);
460 }
461
462 void GLAPIENTRY
463 _mesa_MultMatrixd( const GLdouble *m )
464 {
465 GLint i;
466 GLfloat f[16];
467 if (!m) return;
468 for (i = 0; i < 16; i++)
469 f[i] = (GLfloat) m[i];
470 _mesa_MultMatrixf( f );
471 }
472
473
474 void GLAPIENTRY
475 _mesa_Rotated( GLdouble angle, GLdouble x, GLdouble y, GLdouble z )
476 {
477 _mesa_Rotatef((GLfloat) angle, (GLfloat) x, (GLfloat) y, (GLfloat) z);
478 }
479
480
481 void GLAPIENTRY
482 _mesa_Scaled( GLdouble x, GLdouble y, GLdouble z )
483 {
484 _mesa_Scalef((GLfloat) x, (GLfloat) y, (GLfloat) z);
485 }
486
487
488 void GLAPIENTRY
489 _mesa_Translated( GLdouble x, GLdouble y, GLdouble z )
490 {
491 _mesa_Translatef((GLfloat) x, (GLfloat) y, (GLfloat) z);
492 }
493
494
495 void GLAPIENTRY
496 _mesa_LoadTransposeMatrixf( const GLfloat *m )
497 {
498 GLfloat tm[16];
499 if (!m) return;
500 _math_transposef(tm, m);
501 _mesa_LoadMatrixf(tm);
502 }
503
504
505 void GLAPIENTRY
506 _mesa_LoadTransposeMatrixd( const GLdouble *m )
507 {
508 GLfloat tm[16];
509 if (!m) return;
510 _math_transposefd(tm, m);
511 _mesa_LoadMatrixf(tm);
512 }
513
514
515 void GLAPIENTRY
516 _mesa_MultTransposeMatrixf( const GLfloat *m )
517 {
518 GLfloat tm[16];
519 if (!m) return;
520 _math_transposef(tm, m);
521 _mesa_MultMatrixf(tm);
522 }
523
524
525 void GLAPIENTRY
526 _mesa_MultTransposeMatrixd( const GLdouble *m )
527 {
528 GLfloat tm[16];
529 if (!m) return;
530 _math_transposefd(tm, m);
531 _mesa_MultMatrixf(tm);
532 }
533
534
535
536 /**********************************************************************/
537 /** \name State management */
538 /*@{*/
539
540
541 /**
542 * Update the projection matrix stack.
543 *
544 * \param ctx GL context.
545 *
546 * Calls _math_matrix_analyse() with the top-matrix of the projection matrix
547 * stack, and recomputes user clip positions if necessary.
548 *
549 * \note This routine references __struct gl_contextRec::Tranform attribute
550 * values to compute userclip positions in clip space, but is only called on
551 * _NEW_PROJECTION. The _mesa_ClipPlane() function keeps these values up to
552 * date across changes to the __struct gl_contextRec::Transform attributes.
553 */
554 static void
555 update_projection( struct gl_context *ctx )
556 {
557 _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
558
559 /* Recompute clip plane positions in clipspace. This is also done
560 * in _mesa_ClipPlane().
561 */
562 if (ctx->Transform.ClipPlanesEnabled) {
563 GLuint p;
564 for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
565 if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
566 _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
567 ctx->Transform.EyeUserPlane[p],
568 ctx->ProjectionMatrixStack.Top->inv );
569 }
570 }
571 }
572 }
573
574
575 /**
576 * Calculate the combined modelview-projection matrix.
577 *
578 * \param ctx GL context.
579 *
580 * Multiplies the top matrices of the projection and model view stacks into
581 * __struct gl_contextRec::_ModelProjectMatrix via _math_matrix_mul_matrix()
582 * and analyzes the resulting matrix via _math_matrix_analyse().
583 */
584 static void
585 calculate_model_project_matrix( struct gl_context *ctx )
586 {
587 _math_matrix_mul_matrix( &ctx->_ModelProjectMatrix,
588 ctx->ProjectionMatrixStack.Top,
589 ctx->ModelviewMatrixStack.Top );
590
591 _math_matrix_analyse( &ctx->_ModelProjectMatrix );
592 }
593
594
595 /**
596 * Updates the combined modelview-projection matrix.
597 *
598 * \param ctx GL context.
599 * \param new_state new state bit mask.
600 *
601 * If there is a new model view matrix then analyzes it. If there is a new
602 * projection matrix, updates it. Finally calls
603 * calculate_model_project_matrix() to recalculate the modelview-projection
604 * matrix.
605 */
606 void _mesa_update_modelview_project( struct gl_context *ctx, GLuint new_state )
607 {
608 if (new_state & _NEW_MODELVIEW)
609 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
610
611 if (new_state & _NEW_PROJECTION)
612 update_projection( ctx );
613
614 /* Keep ModelviewProject up to date always to allow tnl
615 * implementations that go model->clip even when eye is required.
616 */
617 calculate_model_project_matrix(ctx);
618 }
619
620 /*@}*/
621
622
623 /**********************************************************************/
624 /** Matrix stack initialization */
625 /*@{*/
626
627
628 /**
629 * Initialize a matrix stack.
630 *
631 * \param stack matrix stack.
632 * \param maxDepth maximum stack depth.
633 * \param dirtyFlag dirty flag.
634 *
635 * Allocates an array of \p maxDepth elements for the matrix stack and calls
636 * _math_matrix_ctr() for each element to initialize it.
637 */
638 static void
639 init_matrix_stack( struct gl_matrix_stack *stack,
640 GLuint maxDepth, GLuint dirtyFlag )
641 {
642 GLuint i;
643
644 stack->Depth = 0;
645 stack->MaxDepth = maxDepth;
646 stack->DirtyFlag = dirtyFlag;
647 /* The stack */
648 stack->Stack = calloc(maxDepth, sizeof(GLmatrix));
649 for (i = 0; i < maxDepth; i++) {
650 _math_matrix_ctr(&stack->Stack[i]);
651 }
652 stack->Top = stack->Stack;
653 }
654
655 /**
656 * Free matrix stack.
657 *
658 * \param stack matrix stack.
659 *
660 * Calls _math_matrix_dtr() for each element of the matrix stack and
661 * frees the array.
662 */
663 static void
664 free_matrix_stack( struct gl_matrix_stack *stack )
665 {
666 GLuint i;
667 for (i = 0; i < stack->MaxDepth; i++) {
668 _math_matrix_dtr(&stack->Stack[i]);
669 }
670 free(stack->Stack);
671 stack->Stack = stack->Top = NULL;
672 }
673
674 /*@}*/
675
676
677 /**********************************************************************/
678 /** \name Initialization */
679 /*@{*/
680
681
682 /**
683 * Initialize the context matrix data.
684 *
685 * \param ctx GL context.
686 *
687 * Initializes each of the matrix stacks and the combined modelview-projection
688 * matrix.
689 */
690 void _mesa_init_matrix( struct gl_context * ctx )
691 {
692 GLuint i;
693
694 /* Initialize matrix stacks */
695 init_matrix_stack(&ctx->ModelviewMatrixStack, MAX_MODELVIEW_STACK_DEPTH,
696 _NEW_MODELVIEW);
697 init_matrix_stack(&ctx->ProjectionMatrixStack, MAX_PROJECTION_STACK_DEPTH,
698 _NEW_PROJECTION);
699 for (i = 0; i < ARRAY_SIZE(ctx->TextureMatrixStack); i++)
700 init_matrix_stack(&ctx->TextureMatrixStack[i], MAX_TEXTURE_STACK_DEPTH,
701 _NEW_TEXTURE_MATRIX);
702 for (i = 0; i < ARRAY_SIZE(ctx->ProgramMatrixStack); i++)
703 init_matrix_stack(&ctx->ProgramMatrixStack[i],
704 MAX_PROGRAM_MATRIX_STACK_DEPTH, _NEW_TRACK_MATRIX);
705 ctx->CurrentStack = &ctx->ModelviewMatrixStack;
706
707 /* Init combined Modelview*Projection matrix */
708 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
709 }
710
711
712 /**
713 * Free the context matrix data.
714 *
715 * \param ctx GL context.
716 *
717 * Frees each of the matrix stacks and the combined modelview-projection
718 * matrix.
719 */
720 void _mesa_free_matrix_data( struct gl_context *ctx )
721 {
722 GLuint i;
723
724 free_matrix_stack(&ctx->ModelviewMatrixStack);
725 free_matrix_stack(&ctx->ProjectionMatrixStack);
726 for (i = 0; i < ARRAY_SIZE(ctx->TextureMatrixStack); i++)
727 free_matrix_stack(&ctx->TextureMatrixStack[i]);
728 for (i = 0; i < ARRAY_SIZE(ctx->ProgramMatrixStack); i++)
729 free_matrix_stack(&ctx->ProgramMatrixStack[i]);
730 /* combined Modelview*Projection matrix */
731 _math_matrix_dtr( &ctx->_ModelProjectMatrix );
732
733 }
734
735
736 /**
737 * Initialize the context transform attribute group.
738 *
739 * \param ctx GL context.
740 *
741 * \todo Move this to a new file with other 'transform' routines.
742 */
743 void _mesa_init_transform( struct gl_context *ctx )
744 {
745 GLuint i;
746
747 /* Transformation group */
748 ctx->Transform.MatrixMode = GL_MODELVIEW;
749 ctx->Transform.Normalize = GL_FALSE;
750 ctx->Transform.RescaleNormals = GL_FALSE;
751 ctx->Transform.RasterPositionUnclipped = GL_FALSE;
752 for (i=0;i<ctx->Const.MaxClipPlanes;i++) {
753 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
754 }
755 ctx->Transform.ClipPlanesEnabled = 0;
756 }
757
758
759 /*@}*/