ReactOS  0.4.14-dev-376-gaedba84
matrix.h File Reference
#include "types.h"
Include dependency graph for matrix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void gl_analyze_modelview_matrix (GLcontext *ctx)
 
void gl_analyze_projection_matrix (GLcontext *ctx)
 
void gl_analyze_texture_matrix (GLcontext *ctx)
 
void gl_rotation_matrix (GLfloat angle, GLfloat x, GLfloat y, GLfloat z, GLfloat m[])
 
void gl_Frustum (GLcontext *ctx, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
 
void gl_Ortho (GLcontext *ctx, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
 
void gl_PushMatrix (GLcontext *ctx)
 
void gl_PopMatrix (GLcontext *ctx)
 
void gl_LoadIdentity (GLcontext *ctx)
 
void gl_LoadMatrixf (GLcontext *ctx, const GLfloat *m)
 
void gl_MatrixMode (GLcontext *ctx, GLenum mode)
 
void gl_MultMatrixf (GLcontext *ctx, const GLfloat *m)
 
void gl_Viewport (GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height)
 
void gl_Rotatef (GLcontext *ctx, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
 
void gl_Scalef (GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z)
 
void gl_Translatef (GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z)
 

Function Documentation

◆ gl_analyze_modelview_matrix()

void gl_analyze_modelview_matrix ( GLcontext ctx)

Definition at line 420 of file matrix.c.

421 {
422  const GLfloat *m = ctx->ModelViewMatrix;
423  if (is_identity(m)) {
425  }
426  else if ( m[4]==0.0F && m[ 8]==0.0F
427  && m[1]==0.0F && m[ 9]==0.0F
428  && m[2]==0.0F && m[6]==0.0F && m[10]==1.0F && m[14]==0.0F
429  && m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
431  }
432  else if ( m[ 8]==0.0F
433  && m[ 9]==0.0F
434  && m[2]==0.0F && m[6]==0.0F && m[10]==1.0F && m[14]==0.0F
435  && m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
437  }
438  else if (m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
440  }
441  else {
443  }
444 
447 }
#define MATRIX_GENERAL
Definition: types.h:1242
GLfloat ModelViewMatrix[16]
Definition: types.h:1284
#define GL_FALSE
Definition: gl.h:173
static GLboolean is_identity(const GLfloat m[16])
Definition: matrix.c:402
#define MATRIX_3D
Definition: types.h:1248
GLboolean NewModelViewMatrix
Definition: types.h:1282
GLuint ModelViewMatrixType
Definition: types.h:1283
const GLfloat * m
Definition: glext.h:10848
#define MATRIX_2D
Definition: types.h:1246
#define MATRIX_2D_NO_ROT
Definition: types.h:1247
GLfloat ModelViewInv[16]
Definition: types.h:1285
float GLfloat
Definition: gl.h:161
static void invert_matrix(const GLfloat *m, GLfloat *out)
Definition: matrix.c:290
#define F(x, y, z)
Definition: md5.c:51
#define MATRIX_IDENTITY
Definition: types.h:1243

Referenced by gl_Begin(), gl_ClipPlane(), gl_Lightfv(), gl_RasterPos4f(), gl_TexGenfv(), and gl_windowpos().

◆ gl_analyze_projection_matrix()

void gl_analyze_projection_matrix ( GLcontext ctx)

Definition at line 455 of file matrix.c.

456 {
457  /* look for common-case ortho and perspective matrices */
458  const GLfloat *m = ctx->ProjectionMatrix;
459  if (is_identity(m)) {
461  }
462  else if ( m[4]==0.0F && m[8] ==0.0F
463  && m[1]==0.0F && m[9] ==0.0F
464  && m[2]==0.0F && m[6]==0.0F
465  && m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
467  }
468  else if ( m[4]==0.0F && m[12]==0.0F
469  && m[1]==0.0F && m[13]==0.0F
470  && m[2]==0.0F && m[6]==0.0F
471  && m[3]==0.0F && m[7]==0.0F && m[11]==-1.0F && m[15]==0.0F) {
473  }
474  else {
476  }
477 
479 }
#define MATRIX_GENERAL
Definition: types.h:1242
#define GL_FALSE
Definition: gl.h:173
static GLboolean is_identity(const GLfloat m[16])
Definition: matrix.c:402
GLboolean NewProjectionMatrix
Definition: types.h:1290
GLuint ProjectionMatrixType
Definition: types.h:1291
const GLfloat * m
Definition: glext.h:10848
#define MATRIX_PERSPECTIVE
Definition: types.h:1245
#define MATRIX_ORTHO
Definition: types.h:1244
float GLfloat
Definition: gl.h:161
GLfloat ProjectionMatrix[16]
Definition: types.h:1292
#define F(x, y, z)
Definition: md5.c:51
#define MATRIX_IDENTITY
Definition: types.h:1243

Referenced by gl_Begin(), and gl_RasterPos4f().

◆ gl_analyze_texture_matrix()

void gl_analyze_texture_matrix ( GLcontext ctx)

Definition at line 487 of file matrix.c.

488 {
489  const GLfloat *m = ctx->TextureMatrix;
490  if (is_identity(m)) {
492  }
493  else if ( m[ 8]==0.0F
494  && m[ 9]==0.0F
495  && m[2]==0.0F && m[6]==0.0F && m[10]==1.0F && m[14]==0.0F
496  && m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
498  }
499  else if (m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
501  }
502  else {
504  }
505 
506  ctx->NewTextureMatrix = GL_FALSE;
507 }
#define MATRIX_GENERAL
Definition: types.h:1242
#define GL_FALSE
Definition: gl.h:173
GLfloat TextureMatrix[16]
Definition: types.h:1300
static GLboolean is_identity(const GLfloat m[16])
Definition: matrix.c:402
#define MATRIX_3D
Definition: types.h:1248
GLuint TextureMatrixType
Definition: types.h:1299
const GLfloat * m
Definition: glext.h:10848
#define MATRIX_2D
Definition: types.h:1246
GLboolean NewTextureMatrix
Definition: types.h:1298
float GLfloat
Definition: gl.h:161
#define F(x, y, z)
Definition: md5.c:51
#define MATRIX_IDENTITY
Definition: types.h:1243

Referenced by gl_RasterPos4f(), and gl_transform_vb_part2().

◆ gl_Frustum()

void gl_Frustum ( GLcontext ctx,
GLdouble  left,
GLdouble  right,
GLdouble  bottom,
GLdouble  top,
GLdouble  nearval,
GLdouble  farval 
)

Definition at line 511 of file matrix.c.

515 {
516  GLfloat x, y, a, b, c, d;
517  GLfloat m[16];
518 
519  if (nearval<=0.0 || farval<=0.0) {
520  gl_error( ctx, GL_INVALID_VALUE, "glFrustum(near or far)" );
521  }
522 
523  x = (2.0*nearval) / (right-left);
524  y = (2.0*nearval) / (top-bottom);
525  a = (right+left) / (right-left);
526  b = (top+bottom) / (top-bottom);
527  c = -(farval+nearval) / ( farval-nearval);
528  d = -(2.0*farval*nearval) / (farval-nearval); /* error? */
529 
530 #define M(row,col) m[col*4+row]
531  M(0,0) = x; M(0,1) = 0.0F; M(0,2) = a; M(0,3) = 0.0F;
532  M(1,0) = 0.0F; M(1,1) = y; M(1,2) = b; M(1,3) = 0.0F;
533  M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = c; M(2,3) = d;
534  M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = -1.0F; M(3,3) = 0.0F;
535 #undef M
536 
537  gl_MultMatrixf( ctx, m );
538 
539 
540  /* Need to keep a stack of near/far values in case the user push/pops
541  * the projection matrix stack so that we can call Driver.NearFar()
542  * after a pop.
543  */
544  ctx->NearFarStack[ctx->ProjectionStackDepth][0] = nearval;
545  ctx->NearFarStack[ctx->ProjectionStackDepth][1] = farval;
546 
547  if (ctx->Driver.NearFar) {
548  (*ctx->Driver.NearFar)( ctx, nearval, farval );
549  }
550 }
#define M(row, col)
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLfloat * m
Definition: glext.h:10848
struct dd_function_table Driver
Definition: types.h:1276
GLfloat NearFarStack[MAX_PROJECTION_STACK_DEPTH][2]
Definition: types.h:1295
#define a
Definition: ke_i.h:78
GLint GLint bottom
Definition: glext.h:7726
#define b
Definition: ke_i.h:79
GLuint ProjectionStackDepth
Definition: types.h:1293
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define d
Definition: ke_i.h:81
const GLubyte * c
Definition: glext.h:8905
void gl_MultMatrixf(GLcontext *ctx, const GLfloat *m)
Definition: matrix.c:785
GLint left
Definition: glext.h:7726
GLdouble GLdouble right
Definition: glext.h:10859
#define GL_INVALID_VALUE
Definition: gl.h:695
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
float GLfloat
Definition: gl.h:161
#define c
Definition: ke_i.h:80
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by execute_list(), and init_exec_pointers().

◆ gl_LoadIdentity()

void gl_LoadIdentity ( GLcontext ctx)

Definition at line 709 of file matrix.c.

710 {
711  if (INSIDE_BEGIN_END(ctx)) {
712  gl_error( ctx, GL_INVALID_OPERATION, "glLoadIdentity" );
713  return;
714  }
715  switch (ctx->Transform.MatrixMode) {
716  case GL_MODELVIEW:
717  MEMCPY( ctx->ModelViewMatrix, Identity, 16*sizeof(GLfloat) );
718  MEMCPY( ctx->ModelViewInv, Identity, 16*sizeof(GLfloat) );
721  break;
722  case GL_PROJECTION:
723  MEMCPY( ctx->ProjectionMatrix, Identity, 16*sizeof(GLfloat) );
726  break;
727  case GL_TEXTURE:
728  MEMCPY( ctx->TextureMatrix, Identity, 16*sizeof(GLfloat) );
730  ctx->NewTextureMatrix = GL_FALSE;
731  break;
732  default:
733  gl_problem(ctx, "Bad matrix mode in gl_LoadIdentity");
734  }
735 }
GLfloat ModelViewMatrix[16]
Definition: types.h:1284
#define GL_FALSE
Definition: gl.h:173
GLfloat TextureMatrix[16]
Definition: types.h:1300
static GLfloat Identity[16]
Definition: matrix.c:127
GLboolean NewProjectionMatrix
Definition: types.h:1290
GLboolean NewModelViewMatrix
Definition: types.h:1282
GLuint ModelViewMatrixType
Definition: types.h:1283
GLuint TextureMatrixType
Definition: types.h:1299
GLuint ProjectionMatrixType
Definition: types.h:1291
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
GLboolean NewTextureMatrix
Definition: types.h:1298
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
GLfloat ModelViewInv[16]
Definition: types.h:1285
struct gl_transform_attrib Transform
Definition: types.h:1335
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_PROJECTION
Definition: gl.h:246
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define GL_MODELVIEW
Definition: gl.h:245
float GLfloat
Definition: gl.h:161
GLfloat ProjectionMatrix[16]
Definition: types.h:1292
#define GL_TEXTURE
Definition: gl.h:247
#define MATRIX_IDENTITY
Definition: types.h:1243

Referenced by execute_list(), and init_exec_pointers().

◆ gl_LoadMatrixf()

void gl_LoadMatrixf ( GLcontext ctx,
const GLfloat m 
)

Definition at line 738 of file matrix.c.

739 {
740  if (INSIDE_BEGIN_END(ctx)) {
741  gl_error( ctx, GL_INVALID_OPERATION, "glLoadMatrix" );
742  return;
743  }
744  switch (ctx->Transform.MatrixMode) {
745  case GL_MODELVIEW:
746  MEMCPY( ctx->ModelViewMatrix, m, 16*sizeof(GLfloat) );
748  break;
749  case GL_PROJECTION:
750  MEMCPY( ctx->ProjectionMatrix, m, 16*sizeof(GLfloat) );
752  {
753  float n,f,c,d;
754 
755 #define M(row,col) m[col*4+row]
756  c = M(2,2);
757  d = M(2,3);
758 #undef M
759  n = d / (c-1);
760  f = d / (c+1);
761 
762  /* Need to keep a stack of near/far values in case the user
763  * push/pops the projection matrix stack so that we can call
764  * Driver.NearFar() after a pop.
765  */
766  ctx->NearFarStack[ctx->ProjectionStackDepth][0] = n;
767  ctx->NearFarStack[ctx->ProjectionStackDepth][1] = f;
768 
769  if (ctx->Driver.NearFar) {
770  (*ctx->Driver.NearFar)( ctx, n, f );
771  }
772  }
773  break;
774  case GL_TEXTURE:
775  MEMCPY( ctx->TextureMatrix, m, 16*sizeof(GLfloat) );
776  ctx->NewTextureMatrix = GL_TRUE;
777  break;
778  default:
779  gl_problem(ctx, "Bad matrix mode in gl_LoadMatrixf");
780  }
781 }
GLfloat ModelViewMatrix[16]
Definition: types.h:1284
#define M(row, col)
GLfloat TextureMatrix[16]
Definition: types.h:1300
GLdouble n
Definition: glext.h:7729
GLboolean NewProjectionMatrix
Definition: types.h:1290
GLboolean NewModelViewMatrix
Definition: types.h:1282
const GLfloat * m
Definition: glext.h:10848
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
struct dd_function_table Driver
Definition: types.h:1276
GLfloat NearFarStack[MAX_PROJECTION_STACK_DEPTH][2]
Definition: types.h:1295
GLuint ProjectionStackDepth
Definition: types.h:1293
GLfloat f
Definition: glext.h:7540
#define d
Definition: ke_i.h:81
GLboolean NewTextureMatrix
Definition: types.h:1298
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
const GLubyte * c
Definition: glext.h:8905
struct gl_transform_attrib Transform
Definition: types.h:1335
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_PROJECTION
Definition: gl.h:246
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define f
Definition: ke_i.h:83
#define GL_TRUE
Definition: gl.h:174
#define GL_MODELVIEW
Definition: gl.h:245
float GLfloat
Definition: gl.h:161
GLfloat ProjectionMatrix[16]
Definition: types.h:1292
#define c
Definition: ke_i.h:80
#define GL_TEXTURE
Definition: gl.h:247

Referenced by execute_list(), and init_exec_pointers().

◆ gl_MatrixMode()

void gl_MatrixMode ( GLcontext ctx,
GLenum  mode 
)

Definition at line 584 of file matrix.c.

585 {
586  if (INSIDE_BEGIN_END(ctx)) {
587  gl_error( ctx, GL_INVALID_OPERATION, "glMatrixMode" );
588  return;
589  }
590  switch (mode) {
591  case GL_MODELVIEW:
592  case GL_PROJECTION:
593  case GL_TEXTURE:
594  ctx->Transform.MatrixMode = mode;
595  break;
596  default:
597  gl_error( ctx, GL_INVALID_ENUM, "glMatrixMode" );
598  }
599 }
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
struct gl_transform_attrib Transform
Definition: types.h:1335
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_PROJECTION
Definition: gl.h:246
GLenum mode
Definition: glext.h:6217
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define GL_INVALID_ENUM
Definition: gl.h:694
#define GL_MODELVIEW
Definition: gl.h:245
#define GL_TEXTURE
Definition: gl.h:247

Referenced by execute_list(), and init_exec_pointers().

◆ gl_MultMatrixf()

void gl_MultMatrixf ( GLcontext ctx,
const GLfloat m 
)

Definition at line 785 of file matrix.c.

786 {
787  if (INSIDE_BEGIN_END(ctx)) {
788  gl_error( ctx, GL_INVALID_OPERATION, "glMultMatrix" );
789  return;
790  }
791  switch (ctx->Transform.MatrixMode) {
792  case GL_MODELVIEW:
793  matmul( ctx->ModelViewMatrix, ctx->ModelViewMatrix, m );
795  break;
796  case GL_PROJECTION:
797  matmul( ctx->ProjectionMatrix, ctx->ProjectionMatrix, m );
799  break;
800  case GL_TEXTURE:
801  matmul( ctx->TextureMatrix, ctx->TextureMatrix, m );
802  ctx->NewTextureMatrix = GL_TRUE;
803  break;
804  default:
805  gl_problem(ctx, "Bad matrix mode in gl_MultMatrixf");
806  }
807 }
GLfloat ModelViewMatrix[16]
Definition: types.h:1284
GLfloat TextureMatrix[16]
Definition: types.h:1300
static void matmul(GLfloat *product, const GLfloat *a, const GLfloat *b)
Definition: matrix.c:154
GLboolean NewProjectionMatrix
Definition: types.h:1290
GLboolean NewModelViewMatrix
Definition: types.h:1282
const GLfloat * m
Definition: glext.h:10848
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
GLboolean NewTextureMatrix
Definition: types.h:1298
struct gl_transform_attrib Transform
Definition: types.h:1335
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_PROJECTION
Definition: gl.h:246
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define GL_TRUE
Definition: gl.h:174
#define GL_MODELVIEW
Definition: gl.h:245
GLfloat ProjectionMatrix[16]
Definition: types.h:1292
#define GL_TEXTURE
Definition: gl.h:247

Referenced by execute_list(), gl_Frustum(), gl_Ortho(), gl_Rotatef(), and init_exec_pointers().

◆ gl_Ortho()

void gl_Ortho ( GLcontext ctx,
GLdouble  left,
GLdouble  right,
GLdouble  bottom,
GLdouble  top,
GLdouble  nearval,
GLdouble  farval 
)

Definition at line 553 of file matrix.c.

557 {
558  GLfloat x, y, z;
559  GLfloat tx, ty, tz;
560  GLfloat m[16];
561 
562  x = 2.0 / (right-left);
563  y = 2.0 / (top-bottom);
564  z = -2.0 / (farval-nearval);
565  tx = -(right+left) / (right-left);
566  ty = -(top+bottom) / (top-bottom);
567  tz = -(farval+nearval) / (farval-nearval);
568 
569 #define M(row,col) m[col*4+row]
570  M(0,0) = x; M(0,1) = 0.0F; M(0,2) = 0.0F; M(0,3) = tx;
571  M(1,0) = 0.0F; M(1,1) = y; M(1,2) = 0.0F; M(1,3) = ty;
572  M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = z; M(2,3) = tz;
573  M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = 0.0F; M(3,3) = 1.0F;
574 #undef M
575 
576  gl_MultMatrixf( ctx, m );
577 
578  if (ctx->Driver.NearFar) {
579  (*ctx->Driver.NearFar)( ctx, nearval, farval );
580  }
581 }
#define M(row, col)
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLfloat * m
Definition: glext.h:10848
struct dd_function_table Driver
Definition: types.h:1276
GLdouble GLdouble z
Definition: glext.h:5874
GLint GLint bottom
Definition: glext.h:7726
GLbyte ty
Definition: glext.h:8756
void gl_MultMatrixf(GLcontext *ctx, const GLfloat *m)
Definition: matrix.c:785
GLint left
Definition: glext.h:7726
GLdouble GLdouble right
Definition: glext.h:10859
GLbyte GLbyte tz
Definition: glext.h:8756
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
float GLfloat
Definition: gl.h:161
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859

Referenced by execute_list(), and init_exec_pointers().

◆ gl_PopMatrix()

void gl_PopMatrix ( GLcontext ctx)

Definition at line 653 of file matrix.c.

654 {
655  if (INSIDE_BEGIN_END(ctx)) {
656  gl_error( ctx, GL_INVALID_OPERATION, "glPopMatrix" );
657  return;
658  }
659  switch (ctx->Transform.MatrixMode) {
660  case GL_MODELVIEW:
661  if (ctx->ModelViewStackDepth==0) {
662  gl_error( ctx, GL_STACK_UNDERFLOW, "glPopMatrix");
663  return;
664  }
665  ctx->ModelViewStackDepth--;
666  MEMCPY( ctx->ModelViewMatrix,
668  16*sizeof(GLfloat) );
670  break;
671  case GL_PROJECTION:
672  if (ctx->ProjectionStackDepth==0) {
673  gl_error( ctx, GL_STACK_UNDERFLOW, "glPopMatrix");
674  return;
675  }
676  ctx->ProjectionStackDepth--;
677  MEMCPY( ctx->ProjectionMatrix,
679  16*sizeof(GLfloat) );
681 
682  /* Device driver near/far values */
683  {
684  GLfloat nearVal = ctx->NearFarStack[ctx->ProjectionStackDepth][0];
685  GLfloat farVal = ctx->NearFarStack[ctx->ProjectionStackDepth][1];
686  if (ctx->Driver.NearFar) {
687  (*ctx->Driver.NearFar)( ctx, nearVal, farVal );
688  }
689  }
690  break;
691  case GL_TEXTURE:
692  if (ctx->TextureStackDepth==0) {
693  gl_error( ctx, GL_STACK_UNDERFLOW, "glPopMatrix");
694  return;
695  }
696  ctx->TextureStackDepth--;
697  MEMCPY( ctx->TextureMatrix,
698  ctx->TextureStack[ctx->TextureStackDepth],
699  16*sizeof(GLfloat) );
700  ctx->NewTextureMatrix = GL_TRUE;
701  break;
702  default:
703  gl_problem(ctx, "Bad matrix mode in gl_PopMatrix");
704  }
705 }
GLfloat ModelViewStack[MAX_MODELVIEW_STACK_DEPTH][16]
Definition: types.h:1287
GLfloat ModelViewMatrix[16]
Definition: types.h:1284
GLfloat TextureMatrix[16]
Definition: types.h:1300
GLboolean NewProjectionMatrix
Definition: types.h:1290
GLboolean NewModelViewMatrix
Definition: types.h:1282
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
struct dd_function_table Driver
Definition: types.h:1276
GLfloat NearFarStack[MAX_PROJECTION_STACK_DEPTH][2]
Definition: types.h:1295
GLfloat ProjectionStack[MAX_PROJECTION_STACK_DEPTH][16]
Definition: types.h:1294
GLuint ProjectionStackDepth
Definition: types.h:1293
GLboolean NewTextureMatrix
Definition: types.h:1298
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
struct gl_transform_attrib Transform
Definition: types.h:1335
#define GL_INVALID_OPERATION
Definition: gl.h:696
GLfloat TextureStack[MAX_TEXTURE_STACK_DEPTH][16]
Definition: types.h:1302
#define GL_PROJECTION
Definition: gl.h:246
GLuint ModelViewStackDepth
Definition: types.h:1286
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define GL_TRUE
Definition: gl.h:174
#define GL_MODELVIEW
Definition: gl.h:245
float GLfloat
Definition: gl.h:161
GLuint TextureStackDepth
Definition: types.h:1301
GLfloat ProjectionMatrix[16]
Definition: types.h:1292
#define GL_TEXTURE
Definition: gl.h:247
#define GL_STACK_UNDERFLOW
Definition: gl.h:698

Referenced by execute_list(), and init_exec_pointers().

◆ gl_PushMatrix()

void gl_PushMatrix ( GLcontext ctx)

Definition at line 603 of file matrix.c.

604 {
605  if (INSIDE_BEGIN_END(ctx)) {
606  gl_error( ctx, GL_INVALID_OPERATION, "glPushMatrix" );
607  return;
608  }
609  switch (ctx->Transform.MatrixMode) {
610  case GL_MODELVIEW:
612  gl_error( ctx, GL_STACK_OVERFLOW, "glPushMatrix");
613  return;
614  }
616  ctx->ModelViewMatrix,
617  16*sizeof(GLfloat) );
618  ctx->ModelViewStackDepth++;
619  break;
620  case GL_PROJECTION:
622  gl_error( ctx, GL_STACK_OVERFLOW, "glPushMatrix");
623  return;
624  }
626  ctx->ProjectionMatrix,
627  16*sizeof(GLfloat) );
628  ctx->ProjectionStackDepth++;
629 
630  /* Save near and far projection values */
631  ctx->NearFarStack[ctx->ProjectionStackDepth][0]
632  = ctx->NearFarStack[ctx->ProjectionStackDepth-1][0];
633  ctx->NearFarStack[ctx->ProjectionStackDepth][1]
634  = ctx->NearFarStack[ctx->ProjectionStackDepth-1][1];
635  break;
636  case GL_TEXTURE:
638  gl_error( ctx, GL_STACK_OVERFLOW, "glPushMatrix");
639  return;
640  }
642  ctx->TextureMatrix,
643  16*sizeof(GLfloat) );
644  ctx->TextureStackDepth++;
645  break;
646  default:
647  gl_problem(ctx, "Bad matrix mode in gl_PushMatrix");
648  }
649 }
GLfloat ModelViewStack[MAX_MODELVIEW_STACK_DEPTH][16]
Definition: types.h:1287
GLfloat ModelViewMatrix[16]
Definition: types.h:1284
GLfloat TextureMatrix[16]
Definition: types.h:1300
#define MAX_PROJECTION_STACK_DEPTH
Definition: config.h:69
#define MAX_TEXTURE_STACK_DEPTH
Definition: config.h:72
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
GLfloat NearFarStack[MAX_PROJECTION_STACK_DEPTH][2]
Definition: types.h:1295
GLfloat ProjectionStack[MAX_PROJECTION_STACK_DEPTH][16]
Definition: types.h:1294
GLuint ProjectionStackDepth
Definition: types.h:1293
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
struct gl_transform_attrib Transform
Definition: types.h:1335
#define GL_INVALID_OPERATION
Definition: gl.h:696
GLfloat TextureStack[MAX_TEXTURE_STACK_DEPTH][16]
Definition: types.h:1302
#define GL_PROJECTION
Definition: gl.h:246
GLuint ModelViewStackDepth
Definition: types.h:1286
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define GL_MODELVIEW
Definition: gl.h:245
float GLfloat
Definition: gl.h:161
GLuint TextureStackDepth
Definition: types.h:1301
#define GL_STACK_OVERFLOW
Definition: gl.h:697
GLfloat ProjectionMatrix[16]
Definition: types.h:1292
#define GL_TEXTURE
Definition: gl.h:247
#define MAX_MODELVIEW_STACK_DEPTH
Definition: config.h:66

Referenced by execute_list(), and init_exec_pointers().

◆ gl_Rotatef()

void gl_Rotatef ( GLcontext ctx,
GLfloat  angle,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Definition at line 927 of file matrix.c.

929 {
930  GLfloat m[16];
931  gl_rotation_matrix( angle, x, y, z, m );
932  gl_MultMatrixf( ctx, m );
933 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLfloat angle
Definition: glext.h:10853
const GLfloat * m
Definition: glext.h:10848
GLdouble GLdouble z
Definition: glext.h:5874
void gl_MultMatrixf(GLcontext *ctx, const GLfloat *m)
Definition: matrix.c:785
void gl_rotation_matrix(GLfloat angle, GLfloat x, GLfloat y, GLfloat z, GLfloat m[])
Definition: matrix.c:814
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
float GLfloat
Definition: gl.h:161

Referenced by init_exec_pointers().

◆ gl_rotation_matrix()

void gl_rotation_matrix ( GLfloat  angle,
GLfloat  x,
GLfloat  y,
GLfloat  z,
GLfloat  m[] 
)

Definition at line 814 of file matrix.c.

816 {
817  /* This function contributed by Erich Boleyn (erich@uruk.org) */
818  GLfloat mag, s, c;
819  GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;
820 
821  s = sin( angle * DEG2RAD );
822  c = cos( angle * DEG2RAD );
823 
824  mag = GL_SQRT( x*x + y*y + z*z );
825 
826  if (mag == 0.0) {
827  /* generate an identity matrix and return */
828  MEMCPY(m, Identity, sizeof(GLfloat)*16);
829  return;
830  }
831 
832  x /= mag;
833  y /= mag;
834  z /= mag;
835 
836 #define M(row,col) m[col*4+row]
837 
838  /*
839  * Arbitrary axis rotation matrix.
840  *
841  * This is composed of 5 matrices, Rz, Ry, T, Ry', Rz', multiplied
842  * like so: Rz * Ry * T * Ry' * Rz'. T is the final rotation
843  * (which is about the X-axis), and the two composite transforms
844  * Ry' * Rz' and Rz * Ry are (respectively) the rotations necessary
845  * from the arbitrary axis to the X-axis then back. They are
846  * all elementary rotations.
847  *
848  * Rz' is a rotation about the Z-axis, to bring the axis vector
849  * into the x-z plane. Then Ry' is applied, rotating about the
850  * Y-axis to bring the axis vector parallel with the X-axis. The
851  * rotation about the X-axis is then performed. Ry and Rz are
852  * simply the respective inverse transforms to bring the arbitrary
853  * axis back to it's original orientation. The first transforms
854  * Rz' and Ry' are considered inverses, since the data from the
855  * arbitrary axis gives you info on how to get to it, not how
856  * to get away from it, and an inverse must be applied.
857  *
858  * The basic calculation used is to recognize that the arbitrary
859  * axis vector (x, y, z), since it is of unit length, actually
860  * represents the sines and cosines of the angles to rotate the
861  * X-axis to the same orientation, with theta being the angle about
862  * Z and phi the angle about Y (in the order described above)
863  * as follows:
864  *
865  * cos ( theta ) = x / sqrt ( 1 - z^2 )
866  * sin ( theta ) = y / sqrt ( 1 - z^2 )
867  *
868  * cos ( phi ) = sqrt ( 1 - z^2 )
869  * sin ( phi ) = z
870  *
871  * Note that cos ( phi ) can further be inserted to the above
872  * formulas:
873  *
874  * cos ( theta ) = x / cos ( phi )
875  * sin ( theta ) = y / sin ( phi )
876  *
877  * ...etc. Because of those relations and the standard trigonometric
878  * relations, it is pssible to reduce the transforms down to what
879  * is used below. It may be that any primary axis chosen will give the
880  * same results (modulo a sign convention) using thie method.
881  *
882  * Particularly nice is to notice that all divisions that might
883  * have caused trouble when parallel to certain planes or
884  * axis go away with care paid to reducing the expressions.
885  * After checking, it does perform correctly under all cases, since
886  * in all the cases of division where the denominator would have
887  * been zero, the numerator would have been zero as well, giving
888  * the expected result.
889  */
890 
891  xx = x * x;
892  yy = y * y;
893  zz = z * z;
894  xy = x * y;
895  yz = y * z;
896  zx = z * x;
897  xs = x * s;
898  ys = y * s;
899  zs = z * s;
900  one_c = 1.0F - c;
901 
902  M(0,0) = (one_c * xx) + c;
903  M(0,1) = (one_c * xy) - zs;
904  M(0,2) = (one_c * zx) + ys;
905  M(0,3) = 0.0F;
906 
907  M(1,0) = (one_c * xy) + zs;
908  M(1,1) = (one_c * yy) + c;
909  M(1,2) = (one_c * yz) - xs;
910  M(1,3) = 0.0F;
911 
912  M(2,0) = (one_c * zx) - ys;
913  M(2,1) = (one_c * yz) + xs;
914  M(2,2) = (one_c * zz) + c;
915  M(2,3) = 0.0F;
916 
917  M(3,0) = 0.0F;
918  M(3,1) = 0.0F;
919  M(3,2) = 0.0F;
920  M(3,3) = 1.0F;
921 
922 #undef M
923 }
#define M(row, col)
static GLfloat Identity[16]
Definition: matrix.c:127
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLfloat angle
Definition: glext.h:10853
const GLfloat * m
Definition: glext.h:10848
GLdouble GLdouble z
Definition: glext.h:5874
_STLP_DECLSPEC complex< float > _STLP_CALL cos(const complex< float > &)
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
const GLubyte * c
Definition: glext.h:8905
#define GL_SQRT(X)
Definition: mmath.h:63
int xx
Definition: npserver.c:29
#define DEG2RAD
Definition: macros.h:268
GLdouble s
Definition: gl.h:2039
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
float GLfloat
Definition: gl.h:161
#define c
Definition: ke_i.h:80
_STLP_DECLSPEC complex< float > _STLP_CALL sin(const complex< float > &)

Referenced by gl_Rotatef(), and gl_save_Rotatef().

◆ gl_Scalef()

void gl_Scalef ( GLcontext ctx,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Definition at line 940 of file matrix.c.

941 {
942  GLfloat *m;
943 
944  if (INSIDE_BEGIN_END(ctx)) {
945  gl_error( ctx, GL_INVALID_OPERATION, "glScale" );
946  return;
947  }
948  switch (ctx->Transform.MatrixMode) {
949  case GL_MODELVIEW:
950  m = ctx->ModelViewMatrix;
952  break;
953  case GL_PROJECTION:
954  m = ctx->ProjectionMatrix;
956  break;
957  case GL_TEXTURE:
958  m = ctx->TextureMatrix;
959  ctx->NewTextureMatrix = GL_TRUE;
960  break;
961  default:
962  gl_problem(ctx, "Bad matrix mode in gl_Scalef");
963  return;
964  }
965  m[0] *= x; m[4] *= y; m[8] *= z;
966  m[1] *= x; m[5] *= y; m[9] *= z;
967  m[2] *= x; m[6] *= y; m[10] *= z;
968  m[3] *= x; m[7] *= y; m[11] *= z;
969 }
GLfloat ModelViewMatrix[16]
Definition: types.h:1284
GLfloat TextureMatrix[16]
Definition: types.h:1300
GLboolean NewProjectionMatrix
Definition: types.h:1290
GLboolean NewModelViewMatrix
Definition: types.h:1282
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLfloat * m
Definition: glext.h:10848
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
GLdouble GLdouble z
Definition: glext.h:5874
GLboolean NewTextureMatrix
Definition: types.h:1298
struct gl_transform_attrib Transform
Definition: types.h:1335
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_PROJECTION
Definition: gl.h:246
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define GL_TRUE
Definition: gl.h:174
#define GL_MODELVIEW
Definition: gl.h:245
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
float GLfloat
Definition: gl.h:161
GLfloat ProjectionMatrix[16]
Definition: types.h:1292
#define GL_TEXTURE
Definition: gl.h:247

Referenced by execute_list(), and init_exec_pointers().

◆ gl_Translatef()

void gl_Translatef ( GLcontext ctx,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Definition at line 976 of file matrix.c.

977 {
978  GLfloat *m;
979  if (INSIDE_BEGIN_END(ctx)) {
980  gl_error( ctx, GL_INVALID_OPERATION, "glTranslate" );
981  return;
982  }
983  switch (ctx->Transform.MatrixMode) {
984  case GL_MODELVIEW:
985  m = ctx->ModelViewMatrix;
987  break;
988  case GL_PROJECTION:
989  m = ctx->ProjectionMatrix;
991  break;
992  case GL_TEXTURE:
993  m = ctx->TextureMatrix;
994  ctx->NewTextureMatrix = GL_TRUE;
995  break;
996  default:
997  gl_problem(ctx, "Bad matrix mode in gl_Translatef");
998  return;
999  }
1000 
1001  m[12] = m[0] * x + m[4] * y + m[8] * z + m[12];
1002  m[13] = m[1] * x + m[5] * y + m[9] * z + m[13];
1003  m[14] = m[2] * x + m[6] * y + m[10] * z + m[14];
1004  m[15] = m[3] * x + m[7] * y + m[11] * z + m[15];
1005 }
GLfloat ModelViewMatrix[16]
Definition: types.h:1284
GLfloat TextureMatrix[16]
Definition: types.h:1300
GLboolean NewProjectionMatrix
Definition: types.h:1290
GLboolean NewModelViewMatrix
Definition: types.h:1282
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLfloat * m
Definition: glext.h:10848
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
GLdouble GLdouble z
Definition: glext.h:5874
GLboolean NewTextureMatrix
Definition: types.h:1298
struct gl_transform_attrib Transform
Definition: types.h:1335
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_PROJECTION
Definition: gl.h:246
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define GL_TRUE
Definition: gl.h:174
#define GL_MODELVIEW
Definition: gl.h:245
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
float GLfloat
Definition: gl.h:161
GLfloat ProjectionMatrix[16]
Definition: types.h:1292
#define GL_TEXTURE
Definition: gl.h:247

Referenced by execute_list(), and init_exec_pointers().

◆ gl_Viewport()

void gl_Viewport ( GLcontext ctx,
GLint  x,
GLint  y,
GLsizei  width,
GLsizei  height 
)

Definition at line 1014 of file matrix.c.

1016 {
1017  if (width<0 || height<0) {
1018  gl_error( ctx, GL_INVALID_VALUE, "glViewport" );
1019  return;
1020  }
1021  if (INSIDE_BEGIN_END(ctx)) {
1022  gl_error( ctx, GL_INVALID_OPERATION, "glViewport" );
1023  return;
1024  }
1025 
1026  /* clamp width, and height to implementation dependent range */
1027  width = CLAMP( width, 1, MAX_WIDTH );
1028  height = CLAMP( height, 1, MAX_HEIGHT );
1029 
1030  /* Save viewport */
1031  ctx->Viewport.X = x;
1032  ctx->Viewport.Width = width;
1033  ctx->Viewport.Y = y;
1034  ctx->Viewport.Height = height;
1035 
1036  /* compute scale and bias values */
1037  ctx->Viewport.Sx = (GLfloat) width / 2.0F;
1038  ctx->Viewport.Tx = ctx->Viewport.Sx + x;
1039  ctx->Viewport.Sy = (GLfloat) height / 2.0F;
1040  ctx->Viewport.Ty = ctx->Viewport.Sy + y;
1041 
1042  ctx->NewState |= NEW_ALL; /* just to be safe */
1043 
1044  /* Check if window/buffer has been resized and if so, reallocate the
1045  * ancillary buffers.
1046  */
1047  gl_ResizeBuffersMESA(ctx);
1048 }
GLint GLint GLsizei width
Definition: gl.h:1546
GLuint NewState
Definition: types.h:1355
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
#define CLAMP(f, min, max)
Definition: tif_color.c:177
#define NEW_ALL
Definition: types.h:1236
#define MAX_HEIGHT
Definition: config.h:131
#define MAX_WIDTH
Definition: config.h:130
#define GL_INVALID_VALUE
Definition: gl.h:695
#define GL_INVALID_OPERATION
Definition: gl.h:696
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
struct gl_viewport_attrib Viewport
Definition: types.h:1336
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
void gl_ResizeBuffersMESA(GLcontext *ctx)
Definition: context.c:1497
float GLfloat
Definition: gl.h:161
#define F(x, y, z)
Definition: md5.c:51

Referenced by execute_list(), init_exec_pointers(), and sw_SetContext().