core | glapi | vbo | math | shader | swrast | swrast_setup | tnl | tnl_dd

matrix.c File Reference


Detailed Description

Matrix operations.

Note:
  1. 4x4 transformation matrices are stored in memory in column major order.
  2. Points/vertices are to be thought of as column vectors.
  3. Transformation of a point p by a matrix M is: p' = M * p

#include "glheader.h"
#include "imports.h"
#include "context.h"
#include "enums.h"
#include "macros.h"
#include "matrix.h"
#include "mtypes.h"
#include "math/m_matrix.h"

Functions

void GLAPIENTRY _mesa_Frustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
 Apply a perspective projection matrix.
void GLAPIENTRY _mesa_Ortho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
 Apply an orthographic projection matrix.
void GLAPIENTRY _mesa_MatrixMode (GLenum mode)
 Set the current matrix stack.
void GLAPIENTRY _mesa_PushMatrix (void)
 Push the current matrix stack.
void GLAPIENTRY _mesa_PopMatrix (void)
 Pop the current matrix stack.
void GLAPIENTRY _mesa_LoadIdentity (void)
 Replace the current matrix with the identity matrix.
void GLAPIENTRY _mesa_LoadMatrixf (const GLfloat *m)
 Replace the current matrix with a given matrix.
void GLAPIENTRY _mesa_MultMatrixf (const GLfloat *m)
 Multiply the current matrix with a given matrix.
void GLAPIENTRY _mesa_Rotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
 Multiply the current matrix with a rotation matrix.
void GLAPIENTRY _mesa_Scalef (GLfloat x, GLfloat y, GLfloat z)
 Multiply the current matrix with a general scaling matrix.
void GLAPIENTRY _mesa_Translatef (GLfloat x, GLfloat y, GLfloat z)
 Multiply the current matrix with a translation matrix.
void GLAPIENTRY _mesa_LoadMatrixd (const GLdouble *m)
void GLAPIENTRY _mesa_MultMatrixd (const GLdouble *m)
void GLAPIENTRY _mesa_Rotated (GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
void GLAPIENTRY _mesa_Scaled (GLdouble x, GLdouble y, GLdouble z)
void GLAPIENTRY _mesa_Translated (GLdouble x, GLdouble y, GLdouble z)
void GLAPIENTRY _mesa_LoadTransposeMatrixfARB (const GLfloat *m)
void GLAPIENTRY _mesa_LoadTransposeMatrixdARB (const GLdouble *m)
void GLAPIENTRY _mesa_MultTransposeMatrixfARB (const GLfloat *m)
void GLAPIENTRY _mesa_MultTransposeMatrixdARB (const GLdouble *m)
State management
static void update_projection (GLcontext *ctx)
 Update the projection matrix stack.
static void calculate_model_project_matrix (GLcontext *ctx)
 Calculate the combined modelview-projection matrix.
void _mesa_update_modelview_project (GLcontext *ctx, GLuint new_state)
 Updates the combined modelview-projection matrix.
static void init_matrix_stack (struct gl_matrix_stack *stack, GLuint maxDepth, GLuint dirtyFlag)
 Matrix stack initialization.
static void free_matrix_stack (struct gl_matrix_stack *stack)
 Free matrix stack.
Initialization
void _mesa_init_matrix (GLcontext *ctx)
 Initialize the context matrix data.
void _mesa_free_matrix_data (GLcontext *ctx)
 Free the context matrix data.
void _mesa_init_transform (GLcontext *ctx)
 Initialize the context transform attribute group.


Function Documentation

void _mesa_free_matrix_data ( GLcontext ctx  ) 

Free the context matrix data.

Parameters:
ctx GL context.
Frees each of the matrix stacks and the combined modelview-projection matrix.

void GLAPIENTRY _mesa_Frustum ( GLdouble  left,
GLdouble  right,
GLdouble  bottom,
GLdouble  top,
GLdouble  nearval,
GLdouble  farval 
)

Apply a perspective projection matrix.

Parameters:
left left clipping plane coordinate.
right right clipping plane coordinate.
bottom bottom clipping plane coordinate.
top top clipping plane coordinate.
nearval distance to the near clipping plane.
farval distance to the far clipping plane.
See also:
glFrustum().
Flushes vertices and validates parameters. Calls _math_matrix_frustum() with the top matrix of the current matrix stack and sets __GLcontextRec::NewState.

void _mesa_init_matrix ( GLcontext ctx  ) 

Initialize the context matrix data.

Parameters:
ctx GL context.
Initializes each of the matrix stacks and the combined modelview-projection matrix.

void _mesa_init_transform ( GLcontext ctx  ) 

Initialize the context transform attribute group.

Parameters:
ctx GL context.
Todo:
Move this to a new file with other 'transform' routines.

void GLAPIENTRY _mesa_LoadIdentity ( void   ) 

Replace the current matrix with the identity matrix.

See also:
glLoadIdentity().
Flushes the vertices and calls _math_matrix_set_identity() with the top-most matrix in the current stack. Marks __GLcontextRec::NewState with the stack dirty flag.

void GLAPIENTRY _mesa_LoadMatrixd ( const GLdouble *  m  ) 

void GLAPIENTRY _mesa_LoadMatrixf ( const GLfloat *  m  ) 

Replace the current matrix with a given matrix.

Parameters:
m matrix.
See also:
glLoadMatrixf().
Flushes the vertices and calls _math_matrix_loadf() with the top-most matrix in the current stack and the given matrix. Marks __GLcontextRec::NewState with the dirty stack flag.

void GLAPIENTRY _mesa_LoadTransposeMatrixdARB ( const GLdouble *  m  ) 

void GLAPIENTRY _mesa_LoadTransposeMatrixfARB ( const GLfloat *  m  ) 

void GLAPIENTRY _mesa_MatrixMode ( GLenum  mode  ) 

Set the current matrix stack.

Parameters:
mode matrix stack.
See also:
glMatrixMode().
Flushes the vertices, validates the parameter and updates __GLcontextRec::CurrentStack and gl_transform_attrib::MatrixMode with the specified matrix stack.

void GLAPIENTRY _mesa_MultMatrixd ( const GLdouble *  m  ) 

void GLAPIENTRY _mesa_MultMatrixf ( const GLfloat *  m  ) 

Multiply the current matrix with a given matrix.

Parameters:
m matrix.
See also:
glMultMatrixf().
Flushes the vertices and calls _math_matrix_mul_floats() with the top-most matrix in the current stack and the given matrix. Marks __GLcontextRec::NewState with the dirty stack flag.

void GLAPIENTRY _mesa_MultTransposeMatrixdARB ( const GLdouble *  m  ) 

void GLAPIENTRY _mesa_MultTransposeMatrixfARB ( const GLfloat *  m  ) 

void GLAPIENTRY _mesa_Ortho ( GLdouble  left,
GLdouble  right,
GLdouble  bottom,
GLdouble  top,
GLdouble  nearval,
GLdouble  farval 
)

Apply an orthographic projection matrix.

Parameters:
left left clipping plane coordinate.
right right clipping plane coordinate.
bottom bottom clipping plane coordinate.
top top clipping plane coordinate.
nearval distance to the near clipping plane.
farval distance to the far clipping plane.
See also:
glOrtho().
Flushes vertices and validates parameters. Calls _math_matrix_ortho() with the top matrix of the current matrix stack and sets __GLcontextRec::NewState.

void GLAPIENTRY _mesa_PopMatrix ( void   ) 

Pop the current matrix stack.

See also:
glPopMatrix().
Flushes the vertices, verifies the current matrix stack is not empty, and moves the stack head down. Marks __GLcontextRec::NewState with the dirty stack flag.

void GLAPIENTRY _mesa_PushMatrix ( void   ) 

Push the current matrix stack.

See also:
glPushMatrix().
Verifies the current matrix stack is not full, and duplicates the top-most matrix in the stack. Marks __GLcontextRec::NewState with the stack dirty flag.

void GLAPIENTRY _mesa_Rotated ( GLdouble  angle,
GLdouble  x,
GLdouble  y,
GLdouble  z 
)

void GLAPIENTRY _mesa_Rotatef ( GLfloat  angle,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Multiply the current matrix with a rotation matrix.

Parameters:
angle angle of rotation, in degrees.
x rotation vector x coordinate.
y rotation vector y coordinate.
z rotation vector z coordinate.
See also:
glRotatef().
Flushes the vertices and calls _math_matrix_rotate() with the top-most matrix in the current stack and the given parameters. Marks __GLcontextRec::NewState with the dirty stack flag.

void GLAPIENTRY _mesa_Scaled ( GLdouble  x,
GLdouble  y,
GLdouble  z 
)

void GLAPIENTRY _mesa_Scalef ( GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Multiply the current matrix with a general scaling matrix.

Parameters:
x x axis scale factor.
y y axis scale factor.
z z axis scale factor.
See also:
glScalef().
Flushes the vertices and calls _math_matrix_scale() with the top-most matrix in the current stack and the given parameters. Marks __GLcontextRec::NewState with the dirty stack flag.

void GLAPIENTRY _mesa_Translated ( GLdouble  x,
GLdouble  y,
GLdouble  z 
)

void GLAPIENTRY _mesa_Translatef ( GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Multiply the current matrix with a translation matrix.

Parameters:
x translation vector x coordinate.
y translation vector y coordinate.
z translation vector z coordinate.
See also:
glTranslatef().
Flushes the vertices and calls _math_matrix_translate() with the top-most matrix in the current stack and the given parameters. Marks __GLcontextRec::NewState with the dirty stack flag.

void _mesa_update_modelview_project ( GLcontext ctx,
GLuint  new_state 
)

Updates the combined modelview-projection matrix.

Parameters:
ctx GL context.
new_state new state bit mask.
If there is a new model view matrix then analyzes it. If there is a new projection matrix, updates it. Finally calls calculate_model_project_matrix() to recalculate the modelview-projection matrix.

static void calculate_model_project_matrix ( GLcontext ctx  )  [static]

Calculate the combined modelview-projection matrix.

Parameters:
ctx GL context.
Multiplies the top matrices of the projection and model view stacks into __GLcontextRec::_ModelProjectMatrix via _math_matrix_mul_matrix() and analyzes the resulting matrix via _math_matrix_analyse().

static void free_matrix_stack ( struct gl_matrix_stack stack  )  [static]

Free matrix stack.

Parameters:
stack matrix stack.
Calls _math_matrix_dtr() for each element of the matrix stack and frees the array.

static void init_matrix_stack ( struct gl_matrix_stack stack,
GLuint  maxDepth,
GLuint  dirtyFlag 
) [static]

Matrix stack initialization.

Initialize a matrix stack.

Parameters:
stack matrix stack.
maxDepth maximum stack depth.
dirtyFlag dirty flag.
Allocates an array of maxDepth elements for the matrix stack and calls _math_matrix_ctr() and _math_matrix_alloc_inv() for each element to initialize it.

static void update_projection ( GLcontext ctx  )  [static]

Update the projection matrix stack.

Parameters:
ctx GL context.
Calls _math_matrix_analyse() with the top-matrix of the projection matrix stack, and recomputes user clip positions if necessary.

Note:
This routine references __GLcontextRec::Tranform attribute values to compute userclip positions in clip space, but is only called on _NEW_PROJECTION. The _mesa_ClipPlane() function keeps these values up to date across changes to the __GLcontextRec::Transform attributes.


Generated on Sun Sep 27 06:47:46 2009 for Mesa Main by  doxygen 1.5.4