[MESA]
[reactos.git] / reactos / dll / opengl / mesa / src / mesa / main / matrix.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.5
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR 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 "mfeatures.h"
44 #include "matrix.h"
45 #include "mtypes.h"
46 #include "math/m_matrix.h"
47
48
49 /**
50 * Apply a perspective projection matrix.
51 *
52 * \param left left clipping plane coordinate.
53 * \param right right clipping plane coordinate.
54 * \param bottom bottom clipping plane coordinate.
55 * \param top top clipping plane coordinate.
56 * \param nearval distance to the near clipping plane.
57 * \param farval distance to the far clipping plane.
58 *
59 * \sa glFrustum().
60 *
61 * Flushes vertices and validates parameters. Calls _math_matrix_frustum() with
62 * the top matrix of the current matrix stack and sets
63 * __struct gl_contextRec::NewState.
64 */
65 void GLAPIENTRY
66 _mesa_Frustum( GLdouble left, GLdouble right,
67 GLdouble bottom, GLdouble top,
68 GLdouble nearval, GLdouble farval )
69 {
70 GET_CURRENT_CONTEXT(ctx);
71 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
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 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
114
115 if (MESA_VERBOSE & VERBOSE_API)
116 _mesa_debug(ctx, "glOrtho(%f, %f, %f, %f, %f, %f)\n",
117 left, right, bottom, top, nearval, farval);
118
119 if (left == right ||
120 bottom == top ||
121 nearval == farval)
122 {
123 _mesa_error( ctx, GL_INVALID_VALUE, "glOrtho" );
124 return;
125 }
126
127 _math_matrix_ortho( ctx->CurrentStack->Top,
128 (GLfloat) left, (GLfloat) right,
129 (GLfloat) bottom, (GLfloat) top,
130 (GLfloat) nearval, (GLfloat) farval );
131 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
132 }
133
134
135 /**
136 * Set the current matrix stack.
137 *
138 * \param mode matrix stack.
139 *
140 * \sa glMatrixMode().
141 *
142 * Flushes the vertices, validates the parameter and updates
143 * __struct gl_contextRec::CurrentStack and gl_transform_attrib::MatrixMode
144 * with the specified matrix stack.
145 */
146 void GLAPIENTRY
147 _mesa_MatrixMode( GLenum mode )
148 {
149 GET_CURRENT_CONTEXT(ctx);
150 ASSERT_OUTSIDE_BEGIN_END(ctx);
151
152 if (ctx->Transform.MatrixMode == mode && mode != GL_TEXTURE)
153 return;
154 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
155
156 switch (mode) {
157 case GL_MODELVIEW:
158 ctx->CurrentStack = &ctx->ModelviewMatrixStack;
159 break;
160 case GL_PROJECTION:
161 ctx->CurrentStack = &ctx->ProjectionMatrixStack;
162 break;
163 case GL_TEXTURE:
164 ctx->CurrentStack = &ctx->TextureMatrixStack;
165 break;
166 default:
167 _mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode(mode)" );
168 return;
169 }
170
171 ctx->Transform.MatrixMode = mode;
172 }
173
174
175 /**
176 * Push the current matrix stack.
177 *
178 * \sa glPushMatrix().
179 *
180 * Verifies the current matrix stack is not full, and duplicates the top-most
181 * matrix in the stack.
182 * Marks __struct gl_contextRec::NewState with the stack dirty flag.
183 */
184 void GLAPIENTRY
185 _mesa_PushMatrix( void )
186 {
187 GET_CURRENT_CONTEXT(ctx);
188 struct gl_matrix_stack *stack = ctx->CurrentStack;
189 ASSERT_OUTSIDE_BEGIN_END(ctx);
190
191 if (MESA_VERBOSE&VERBOSE_API)
192 _mesa_debug(ctx, "glPushMatrix %s\n",
193 _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode));
194
195 if (stack->Depth + 1 >= stack->MaxDepth) {
196 if (ctx->Transform.MatrixMode == GL_TEXTURE) {
197 _mesa_error(ctx, GL_STACK_OVERFLOW,
198 "glPushMatrix(mode=GL_TEXTURE)");
199 }
200 else {
201 _mesa_error(ctx, GL_STACK_OVERFLOW, "glPushMatrix(mode=%s)",
202 _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode));
203 }
204 return;
205 }
206 _math_matrix_copy( &stack->Stack[stack->Depth + 1],
207 &stack->Stack[stack->Depth] );
208 stack->Depth++;
209 stack->Top = &(stack->Stack[stack->Depth]);
210 ctx->NewState |= stack->DirtyFlag;
211 }
212
213
214 /**
215 * Pop the current matrix stack.
216 *
217 * \sa glPopMatrix().
218 *
219 * Flushes the vertices, verifies the current matrix stack is not empty, and
220 * moves the stack head down.
221 * Marks __struct gl_contextRec::NewState with the dirty stack flag.
222 */
223 void GLAPIENTRY
224 _mesa_PopMatrix( void )
225 {
226 GET_CURRENT_CONTEXT(ctx);
227 struct gl_matrix_stack *stack = ctx->CurrentStack;
228 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
229
230 if (MESA_VERBOSE&VERBOSE_API)
231 _mesa_debug(ctx, "glPopMatrix %s\n",
232 _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode));
233
234 if (stack->Depth == 0) {
235 if (ctx->Transform.MatrixMode == GL_TEXTURE) {
236 _mesa_error(ctx, GL_STACK_UNDERFLOW,
237 "glPopMatrix(mode=GL_TEXTURE)");
238 }
239 else {
240 _mesa_error(ctx, GL_STACK_UNDERFLOW, "glPopMatrix(mode=%s)",
241 _mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode));
242 }
243 return;
244 }
245 stack->Depth--;
246 stack->Top = &(stack->Stack[stack->Depth]);
247 ctx->NewState |= stack->DirtyFlag;
248 }
249
250
251 /**
252 * Replace the current matrix with the identity matrix.
253 *
254 * \sa glLoadIdentity().
255 *
256 * Flushes the vertices and calls _math_matrix_set_identity() with the
257 * top-most matrix in the current stack.
258 * Marks __struct gl_contextRec::NewState with the stack dirty flag.
259 */
260 void GLAPIENTRY
261 _mesa_LoadIdentity( void )
262 {
263 GET_CURRENT_CONTEXT(ctx);
264 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
265
266 if (MESA_VERBOSE & VERBOSE_API)
267 _mesa_debug(ctx, "glLoadIdentity()\n");
268
269 _math_matrix_set_identity( ctx->CurrentStack->Top );
270 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
271 }
272
273
274 /**
275 * Replace the current matrix with a given matrix.
276 *
277 * \param m matrix.
278 *
279 * \sa glLoadMatrixf().
280 *
281 * Flushes the vertices and calls _math_matrix_loadf() with the top-most
282 * matrix in the current stack and the given matrix.
283 * Marks __struct gl_contextRec::NewState with the dirty stack flag.
284 */
285 void GLAPIENTRY
286 _mesa_LoadMatrixf( const GLfloat *m )
287 {
288 GET_CURRENT_CONTEXT(ctx);
289 if (!m) return;
290 if (MESA_VERBOSE & VERBOSE_API)
291 _mesa_debug(ctx,
292 "glLoadMatrix(%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f\n",
293 m[0], m[4], m[8], m[12],
294 m[1], m[5], m[9], m[13],
295 m[2], m[6], m[10], m[14],
296 m[3], m[7], m[11], m[15]);
297
298 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
299 _math_matrix_loadf( ctx->CurrentStack->Top, m );
300 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
301 }
302
303
304 /**
305 * Multiply the current matrix with a given matrix.
306 *
307 * \param m matrix.
308 *
309 * \sa glMultMatrixf().
310 *
311 * Flushes the vertices and calls _math_matrix_mul_floats() with the top-most
312 * matrix in the current stack and the given matrix. Marks
313 * __struct gl_contextRec::NewState with the dirty stack flag.
314 */
315 void GLAPIENTRY
316 _mesa_MultMatrixf( const GLfloat *m )
317 {
318 GET_CURRENT_CONTEXT(ctx);
319 if (!m) return;
320 if (MESA_VERBOSE & VERBOSE_API)
321 _mesa_debug(ctx,
322 "glMultMatrix(%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f\n",
323 m[0], m[4], m[8], m[12],
324 m[1], m[5], m[9], m[13],
325 m[2], m[6], m[10], m[14],
326 m[3], m[7], m[11], m[15]);
327 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
328 _math_matrix_mul_floats( ctx->CurrentStack->Top, m );
329 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
330 }
331
332
333 /**
334 * Multiply the current matrix with a rotation matrix.
335 *
336 * \param angle angle of rotation, in degrees.
337 * \param x rotation vector x coordinate.
338 * \param y rotation vector y coordinate.
339 * \param z rotation vector z coordinate.
340 *
341 * \sa glRotatef().
342 *
343 * Flushes the vertices and calls _math_matrix_rotate() with the top-most
344 * matrix in the current stack and the given parameters. Marks
345 * __struct gl_contextRec::NewState with the dirty stack flag.
346 */
347 void GLAPIENTRY
348 _mesa_Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
349 {
350 GET_CURRENT_CONTEXT(ctx);
351 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
352 if (angle != 0.0F) {
353 _math_matrix_rotate( ctx->CurrentStack->Top, angle, x, y, z);
354 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
355 }
356 }
357
358
359 /**
360 * Multiply the current matrix with a general scaling matrix.
361 *
362 * \param x x axis scale factor.
363 * \param y y axis scale factor.
364 * \param z z axis scale factor.
365 *
366 * \sa glScalef().
367 *
368 * Flushes the vertices and calls _math_matrix_scale() with the top-most
369 * matrix in the current stack and the given parameters. Marks
370 * __struct gl_contextRec::NewState with the dirty stack flag.
371 */
372 void GLAPIENTRY
373 _mesa_Scalef( GLfloat x, GLfloat y, GLfloat z )
374 {
375 GET_CURRENT_CONTEXT(ctx);
376 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
377 _math_matrix_scale( ctx->CurrentStack->Top, x, y, z);
378 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
379 }
380
381
382 /**
383 * Multiply the current matrix with a translation matrix.
384 *
385 * \param x translation vector x coordinate.
386 * \param y translation vector y coordinate.
387 * \param z translation vector z coordinate.
388 *
389 * \sa glTranslatef().
390 *
391 * Flushes the vertices and calls _math_matrix_translate() with the top-most
392 * matrix in the current stack and the given parameters. Marks
393 * __struct gl_contextRec::NewState with the dirty stack flag.
394 */
395 void GLAPIENTRY
396 _mesa_Translatef( GLfloat x, GLfloat y, GLfloat z )
397 {
398 GET_CURRENT_CONTEXT(ctx);
399 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
400 _math_matrix_translate( ctx->CurrentStack->Top, x, y, z);
401 ctx->NewState |= ctx->CurrentStack->DirtyFlag;
402 }
403
404
405 #if _HAVE_FULL_GL
406 void GLAPIENTRY
407 _mesa_LoadMatrixd( const GLdouble *m )
408 {
409 GLint i;
410 GLfloat f[16];
411 if (!m) return;
412 for (i = 0; i < 16; i++)
413 f[i] = (GLfloat) m[i];
414 _mesa_LoadMatrixf(f);
415 }
416
417 void GLAPIENTRY
418 _mesa_MultMatrixd( const GLdouble *m )
419 {
420 GLint i;
421 GLfloat f[16];
422 if (!m) return;
423 for (i = 0; i < 16; i++)
424 f[i] = (GLfloat) m[i];
425 _mesa_MultMatrixf( f );
426 }
427
428
429 void GLAPIENTRY
430 _mesa_Rotated( GLdouble angle, GLdouble x, GLdouble y, GLdouble z )
431 {
432 _mesa_Rotatef((GLfloat) angle, (GLfloat) x, (GLfloat) y, (GLfloat) z);
433 }
434
435
436 void GLAPIENTRY
437 _mesa_Scaled( GLdouble x, GLdouble y, GLdouble z )
438 {
439 _mesa_Scalef((GLfloat) x, (GLfloat) y, (GLfloat) z);
440 }
441
442
443 void GLAPIENTRY
444 _mesa_Translated( GLdouble x, GLdouble y, GLdouble z )
445 {
446 _mesa_Translatef((GLfloat) x, (GLfloat) y, (GLfloat) z);
447 }
448 #endif
449
450
451 #if _HAVE_FULL_GL
452 void GLAPIENTRY
453 _mesa_LoadTransposeMatrixfARB( const GLfloat *m )
454 {
455 GLfloat tm[16];
456 if (!m) return;
457 _math_transposef(tm, m);
458 _mesa_LoadMatrixf(tm);
459 }
460
461
462 void GLAPIENTRY
463 _mesa_LoadTransposeMatrixdARB( const GLdouble *m )
464 {
465 GLfloat tm[16];
466 if (!m) return;
467 _math_transposefd(tm, m);
468 _mesa_LoadMatrixf(tm);
469 }
470
471
472 void GLAPIENTRY
473 _mesa_MultTransposeMatrixfARB( const GLfloat *m )
474 {
475 GLfloat tm[16];
476 if (!m) return;
477 _math_transposef(tm, m);
478 _mesa_MultMatrixf(tm);
479 }
480
481
482 void GLAPIENTRY
483 _mesa_MultTransposeMatrixdARB( const GLdouble *m )
484 {
485 GLfloat tm[16];
486 if (!m) return;
487 _math_transposefd(tm, m);
488 _mesa_MultMatrixf(tm);
489 }
490 #endif
491
492
493
494 /**********************************************************************/
495 /** \name State management */
496 /*@{*/
497
498
499 /**
500 * Update the projection matrix stack.
501 *
502 * \param ctx GL context.
503 *
504 * Calls _math_matrix_analyse() with the top-matrix of the projection matrix
505 * stack, and recomputes user clip positions if necessary.
506 *
507 * \note This routine references __struct gl_contextRec::Tranform attribute
508 * values to compute userclip positions in clip space, but is only called on
509 * _NEW_PROJECTION. The _mesa_ClipPlane() function keeps these values up to
510 * date across changes to the __struct gl_contextRec::Transform attributes.
511 */
512 static void
513 update_projection( struct gl_context *ctx )
514 {
515 _math_matrix_analyse( ctx->ProjectionMatrixStack.Top );
516
517 #if FEATURE_userclip
518 /* Recompute clip plane positions in clipspace. This is also done
519 * in _mesa_ClipPlane().
520 */
521 if (ctx->Transform.ClipPlanesEnabled) {
522 GLuint p;
523 for (p = 0; p < ctx->Const.MaxClipPlanes; p++) {
524 if (ctx->Transform.ClipPlanesEnabled & (1 << p)) {
525 _mesa_transform_vector( ctx->Transform._ClipUserPlane[p],
526 ctx->Transform.EyeUserPlane[p],
527 ctx->ProjectionMatrixStack.Top->inv );
528 }
529 }
530 }
531 #endif
532 }
533
534
535 /**
536 * Calculate the combined modelview-projection matrix.
537 *
538 * \param ctx GL context.
539 *
540 * Multiplies the top matrices of the projection and model view stacks into
541 * __struct gl_contextRec::_ModelProjectMatrix via _math_matrix_mul_matrix()
542 * and analyzes the resulting matrix via _math_matrix_analyse().
543 */
544 static void
545 calculate_model_project_matrix( struct gl_context *ctx )
546 {
547 _math_matrix_mul_matrix( &ctx->_ModelProjectMatrix,
548 ctx->ProjectionMatrixStack.Top,
549 ctx->ModelviewMatrixStack.Top );
550
551 _math_matrix_analyse( &ctx->_ModelProjectMatrix );
552 }
553
554
555 /**
556 * Updates the combined modelview-projection matrix.
557 *
558 * \param ctx GL context.
559 * \param new_state new state bit mask.
560 *
561 * If there is a new model view matrix then analyzes it. If there is a new
562 * projection matrix, updates it. Finally calls
563 * calculate_model_project_matrix() to recalculate the modelview-projection
564 * matrix.
565 */
566 void _mesa_update_modelview_project( struct gl_context *ctx, GLuint new_state )
567 {
568 if (new_state & _NEW_MODELVIEW) {
569 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
570
571 /* Bring cull position up to date.
572 */
573 TRANSFORM_POINT3( ctx->Transform.CullObjPos,
574 ctx->ModelviewMatrixStack.Top->inv,
575 ctx->Transform.CullEyePos );
576 }
577
578
579 if (new_state & _NEW_PROJECTION)
580 update_projection( ctx );
581
582 /* Keep ModelviewProject up to date always to allow tnl
583 * implementations that go model->clip even when eye is required.
584 */
585 calculate_model_project_matrix(ctx);
586 }
587
588 /*@}*/
589
590
591 /**********************************************************************/
592 /** Matrix stack initialization */
593 /*@{*/
594
595
596 /**
597 * Initialize a matrix stack.
598 *
599 * \param stack matrix stack.
600 * \param maxDepth maximum stack depth.
601 * \param dirtyFlag dirty flag.
602 *
603 * Allocates an array of \p maxDepth elements for the matrix stack and calls
604 * _math_matrix_ctr() and _math_matrix_alloc_inv() for each element to
605 * initialize it.
606 */
607 static void
608 init_matrix_stack( struct gl_matrix_stack *stack,
609 GLuint maxDepth, GLuint dirtyFlag )
610 {
611 GLuint i;
612
613 stack->Depth = 0;
614 stack->MaxDepth = maxDepth;
615 stack->DirtyFlag = dirtyFlag;
616 /* The stack */
617 stack->Stack = (GLmatrix *) CALLOC(maxDepth * sizeof(GLmatrix));
618 for (i = 0; i < maxDepth; i++) {
619 _math_matrix_ctr(&stack->Stack[i]);
620 _math_matrix_alloc_inv(&stack->Stack[i]);
621 }
622 stack->Top = stack->Stack;
623 }
624
625 /**
626 * Free matrix stack.
627 *
628 * \param stack matrix stack.
629 *
630 * Calls _math_matrix_dtr() for each element of the matrix stack and
631 * frees the array.
632 */
633 static void
634 free_matrix_stack( struct gl_matrix_stack *stack )
635 {
636 GLuint i;
637 for (i = 0; i < stack->MaxDepth; i++) {
638 _math_matrix_dtr(&stack->Stack[i]);
639 }
640 FREE(stack->Stack);
641 stack->Stack = stack->Top = NULL;
642 }
643
644 /*@}*/
645
646
647 /**********************************************************************/
648 /** \name Initialization */
649 /*@{*/
650
651
652 /**
653 * Initialize the context matrix data.
654 *
655 * \param ctx GL context.
656 *
657 * Initializes each of the matrix stacks and the combined modelview-projection
658 * matrix.
659 */
660 void _mesa_init_matrix( struct gl_context * ctx )
661 {
662 /* Initialize matrix stacks */
663 init_matrix_stack(&ctx->ModelviewMatrixStack, MAX_MODELVIEW_STACK_DEPTH,
664 _NEW_MODELVIEW);
665 init_matrix_stack(&ctx->ProjectionMatrixStack, MAX_PROJECTION_STACK_DEPTH,
666 _NEW_PROJECTION);
667 init_matrix_stack(&ctx->TextureMatrixStack, MAX_TEXTURE_STACK_DEPTH,
668 _NEW_TEXTURE_MATRIX);
669 ctx->CurrentStack = &ctx->ModelviewMatrixStack;
670
671 /* Init combined Modelview*Projection matrix */
672 _math_matrix_ctr( &ctx->_ModelProjectMatrix );
673 }
674
675
676 /**
677 * Free the context matrix data.
678 *
679 * \param ctx GL context.
680 *
681 * Frees each of the matrix stacks and the combined modelview-projection
682 * matrix.
683 */
684 void _mesa_free_matrix_data( struct gl_context *ctx )
685 {
686 free_matrix_stack(&ctx->ModelviewMatrixStack);
687 free_matrix_stack(&ctx->ProjectionMatrixStack);
688 free_matrix_stack(&ctx->TextureMatrixStack);
689 /* combined Modelview*Projection matrix */
690 _math_matrix_dtr( &ctx->_ModelProjectMatrix );
691
692 }
693
694
695 /**
696 * Initialize the context transform attribute group.
697 *
698 * \param ctx GL context.
699 *
700 * \todo Move this to a new file with other 'transform' routines.
701 */
702 void _mesa_init_transform( struct gl_context *ctx )
703 {
704 GLint i;
705
706 /* Transformation group */
707 ctx->Transform.MatrixMode = GL_MODELVIEW;
708 ctx->Transform.Normalize = GL_FALSE;
709 ctx->Transform.RescaleNormals = GL_FALSE;
710 ctx->Transform.RasterPositionUnclipped = GL_FALSE;
711 for (i=0;i<ctx->Const.MaxClipPlanes;i++) {
712 ASSIGN_4V( ctx->Transform.EyeUserPlane[i], 0.0, 0.0, 0.0, 0.0 );
713 }
714 ctx->Transform.ClipPlanesEnabled = 0;
715
716 ASSIGN_4V( ctx->Transform.CullObjPos, 0.0, 0.0, 1.0, 0.0 );
717 ASSIGN_4V( ctx->Transform.CullEyePos, 0.0, 0.0, 1.0, 0.0 );
718 }
719
720
721 /*@}*/