2001-12-18 04:06:44 +00:00
|
|
|
/* $Id: matrix.c,v 1.38 2001/12/18 04:06:45 brianp Exp $ */
|
1999-08-19 00:55:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mesa 3-D graphics library
|
2001-12-18 04:06:44 +00:00
|
|
|
* Version: 4.1
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
2001-01-23 23:39:36 +00:00
|
|
|
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
1999-08-19 00:55:39 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
1999-08-19 00:55:39 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
1999-08-19 00:55:39 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Matrix operations
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef PC_HEADER
|
|
|
|
#include "all.h"
|
|
|
|
#else
|
1999-11-11 01:22:25 +00:00
|
|
|
#include "glheader.h"
|
2000-02-02 19:28:27 +00:00
|
|
|
#include "buffers.h"
|
1999-08-19 00:55:39 +00:00
|
|
|
#include "context.h"
|
|
|
|
#include "enums.h"
|
2000-10-29 18:23:16 +00:00
|
|
|
#include "macros.h"
|
1999-08-19 00:55:39 +00:00
|
|
|
#include "matrix.h"
|
1999-11-11 01:22:25 +00:00
|
|
|
#include "mem.h"
|
1999-08-19 00:55:39 +00:00
|
|
|
#include "mmath.h"
|
2000-11-22 07:32:16 +00:00
|
|
|
#include "mtypes.h"
|
2000-09-17 21:56:07 +00:00
|
|
|
|
2000-11-16 21:05:34 +00:00
|
|
|
#include "math/m_matrix.h"
|
|
|
|
#endif
|
2000-09-17 21:56:07 +00:00
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_Frustum( GLdouble left, GLdouble right,
|
|
|
|
GLdouble bottom, GLdouble top,
|
|
|
|
GLdouble nearval, GLdouble farval )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
1999-08-19 00:55:39 +00:00
|
|
|
|
2000-11-16 21:05:34 +00:00
|
|
|
if (nearval <= 0.0 ||
|
2000-11-22 07:32:16 +00:00
|
|
|
farval <= 0.0 ||
|
|
|
|
nearval == farval ||
|
|
|
|
left == right ||
|
|
|
|
top == bottom)
|
2000-11-16 21:05:34 +00:00
|
|
|
{
|
2001-03-03 20:33:27 +00:00
|
|
|
_mesa_error( ctx, GL_INVALID_VALUE, "glFrustum" );
|
1999-09-09 18:49:36 +00:00
|
|
|
return;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
2000-11-22 07:32:16 +00:00
|
|
|
|
2001-12-18 04:06:44 +00:00
|
|
|
_math_matrix_frustum( ctx->CurrentStack->Top,
|
|
|
|
(GLfloat) left, (GLfloat) right,
|
2001-09-18 16:16:21 +00:00
|
|
|
(GLfloat) bottom, (GLfloat) top,
|
|
|
|
(GLfloat) nearval, (GLfloat) farval );
|
2001-12-18 04:06:44 +00:00
|
|
|
ctx->NewState |= ctx->CurrentStack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_Ortho( GLdouble left, GLdouble right,
|
|
|
|
GLdouble bottom, GLdouble top,
|
|
|
|
GLdouble nearval, GLdouble farval )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
1999-08-19 00:55:39 +00:00
|
|
|
|
2000-11-22 07:32:16 +00:00
|
|
|
if (left == right ||
|
|
|
|
bottom == top ||
|
|
|
|
nearval == farval)
|
2000-11-16 21:05:34 +00:00
|
|
|
{
|
2001-03-03 20:33:27 +00:00
|
|
|
_mesa_error( ctx, GL_INVALID_VALUE, "glOrtho" );
|
1999-09-09 18:49:36 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-08-19 00:55:39 +00:00
|
|
|
|
2001-12-18 04:06:44 +00:00
|
|
|
_math_matrix_ortho( ctx->CurrentStack->Top,
|
|
|
|
(GLfloat) left, (GLfloat) right,
|
2001-09-18 16:16:21 +00:00
|
|
|
(GLfloat) bottom, (GLfloat) top,
|
|
|
|
(GLfloat) nearval, (GLfloat) farval );
|
2001-12-18 04:06:44 +00:00
|
|
|
ctx->NewState |= ctx->CurrentStack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_MatrixMode( GLenum mode )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END(ctx);
|
|
|
|
|
2001-12-18 04:06:44 +00:00
|
|
|
if (ctx->Transform.MatrixMode == mode)
|
|
|
|
return;
|
|
|
|
FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
|
|
|
|
|
1999-08-19 00:55:39 +00:00
|
|
|
switch (mode) {
|
2001-12-18 04:06:44 +00:00
|
|
|
case GL_MODELVIEW:
|
|
|
|
ctx->CurrentStack = &ctx->ModelviewMatrixStack;
|
|
|
|
break;
|
|
|
|
case GL_PROJECTION:
|
|
|
|
ctx->CurrentStack = &ctx->ProjectionMatrixStack;
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE:
|
|
|
|
ctx->CurrentStack = &ctx->TextureMatrixStack[ctx->Texture.CurrentUnit];
|
|
|
|
break;
|
|
|
|
case GL_COLOR:
|
|
|
|
ctx->CurrentStack = &ctx->ColorMatrixStack;
|
|
|
|
break;
|
|
|
|
case GL_MATRIX0_NV:
|
|
|
|
case GL_MATRIX1_NV:
|
|
|
|
case GL_MATRIX2_NV:
|
|
|
|
case GL_MATRIX3_NV:
|
|
|
|
case GL_MATRIX4_NV:
|
|
|
|
case GL_MATRIX5_NV:
|
|
|
|
case GL_MATRIX6_NV:
|
|
|
|
case GL_MATRIX7_NV:
|
|
|
|
if (!ctx->Extensions.NV_vertex_program) {
|
2001-03-03 20:33:27 +00:00
|
|
|
_mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode" );
|
2001-12-18 04:06:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ctx->CurrentStack = &ctx->ProgramMatrixStack[mode - GL_MATRIX0_NV];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_mesa_error( ctx, GL_INVALID_ENUM, "glMatrixMode" );
|
|
|
|
return;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
2001-12-18 04:06:44 +00:00
|
|
|
|
|
|
|
ctx->Transform.MatrixMode = mode;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_PushMatrix( void )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2001-12-18 04:06:44 +00:00
|
|
|
struct matrix_stack *stack = ctx->CurrentStack;
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END(ctx);
|
1999-08-19 00:55:39 +00:00
|
|
|
|
|
|
|
if (MESA_VERBOSE&VERBOSE_API)
|
2000-11-22 07:32:16 +00:00
|
|
|
fprintf(stderr, "glPushMatrix %s\n",
|
2001-03-03 20:33:27 +00:00
|
|
|
_mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode));
|
1999-08-19 00:55:39 +00:00
|
|
|
|
2001-12-18 04:06:44 +00:00
|
|
|
if (stack->Depth + 1 >= stack->MaxDepth) {
|
|
|
|
_mesa_error( ctx, GL_STACK_OVERFLOW, "glPushMatrix" );
|
|
|
|
return;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
2001-12-18 04:06:44 +00:00
|
|
|
_math_matrix_copy( &stack->Stack[stack->Depth + 1],
|
|
|
|
&stack->Stack[stack->Depth] );
|
|
|
|
stack->Depth++;
|
|
|
|
stack->Top = &(stack->Stack[stack->Depth]);
|
|
|
|
ctx->NewState |= stack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_PopMatrix( void )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2001-12-18 04:06:44 +00:00
|
|
|
struct matrix_stack *stack = ctx->CurrentStack;
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
1999-08-19 00:55:39 +00:00
|
|
|
|
|
|
|
if (MESA_VERBOSE&VERBOSE_API)
|
2000-11-22 07:32:16 +00:00
|
|
|
fprintf(stderr, "glPopMatrix %s\n",
|
2001-03-03 20:33:27 +00:00
|
|
|
_mesa_lookup_enum_by_nr(ctx->Transform.MatrixMode));
|
1999-08-19 00:55:39 +00:00
|
|
|
|
2001-12-18 04:06:44 +00:00
|
|
|
if (stack->Depth == 0) {
|
|
|
|
_mesa_error( ctx, GL_STACK_UNDERFLOW, "glPopMatrix" );
|
|
|
|
return;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
2001-12-18 04:06:44 +00:00
|
|
|
stack->Depth--;
|
|
|
|
stack->Top = &(stack->Stack[stack->Depth]);
|
|
|
|
ctx->NewState |= stack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_LoadIdentity( void )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
2001-12-18 04:06:44 +00:00
|
|
|
_math_matrix_set_identity( ctx->CurrentStack->Top );
|
|
|
|
ctx->NewState |= ctx->CurrentStack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_LoadMatrixf( const GLfloat *m )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
2001-12-18 04:06:44 +00:00
|
|
|
_math_matrix_loadf( ctx->CurrentStack->Top, m );
|
|
|
|
ctx->NewState |= ctx->CurrentStack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_LoadMatrixd( const GLdouble *m )
|
|
|
|
{
|
|
|
|
GLint i;
|
2000-11-16 21:05:34 +00:00
|
|
|
GLfloat f[16];
|
1999-11-11 01:22:25 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
2001-09-18 16:16:21 +00:00
|
|
|
f[i] = (GLfloat) m[i];
|
1999-11-11 01:22:25 +00:00
|
|
|
_mesa_LoadMatrixf(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-19 00:55:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Multiply the active matrix by an arbitary matrix.
|
|
|
|
*/
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_MultMatrixf( const GLfloat *m )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
2001-12-18 04:06:44 +00:00
|
|
|
_math_matrix_mul_floats( ctx->CurrentStack->Top, m );
|
|
|
|
ctx->NewState |= ctx->CurrentStack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-11-22 07:32:16 +00:00
|
|
|
* Multiply the active matrix by an arbitary matrix.
|
1999-08-19 00:55:39 +00:00
|
|
|
*/
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_MultMatrixd( const GLdouble *m )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
2000-11-16 21:05:34 +00:00
|
|
|
GLint i;
|
|
|
|
GLfloat f[16];
|
|
|
|
for (i = 0; i < 16; i++)
|
2001-09-18 16:16:21 +00:00
|
|
|
f[i] = (GLfloat) m[i];
|
2000-11-16 21:05:34 +00:00
|
|
|
_mesa_MultMatrixf( f );
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Execute a glRotate call
|
|
|
|
*/
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
1999-08-19 00:55:39 +00:00
|
|
|
if (angle != 0.0F) {
|
2001-12-18 04:06:44 +00:00
|
|
|
_math_matrix_rotate( ctx->CurrentStack->Top, angle, x, y, z);
|
|
|
|
ctx->NewState |= ctx->CurrentStack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_Rotated( GLdouble angle, GLdouble x, GLdouble y, GLdouble z )
|
|
|
|
{
|
2001-09-18 16:16:21 +00:00
|
|
|
_mesa_Rotatef((GLfloat) angle, (GLfloat) x, (GLfloat) y, (GLfloat) z);
|
1999-11-11 01:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-19 00:55:39 +00:00
|
|
|
/*
|
|
|
|
* Execute a glScale call
|
|
|
|
*/
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_Scalef( GLfloat x, GLfloat y, GLfloat z )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
2001-12-18 04:06:44 +00:00
|
|
|
_math_matrix_scale( ctx->CurrentStack->Top, x, y, z);
|
|
|
|
ctx->NewState |= ctx->CurrentStack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_mesa_Scaled( GLdouble x, GLdouble y, GLdouble z )
|
|
|
|
{
|
2001-09-18 16:16:21 +00:00
|
|
|
_mesa_Scalef((GLfloat) x, (GLfloat) y, (GLfloat) z);
|
1999-11-11 01:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-19 00:55:39 +00:00
|
|
|
/*
|
|
|
|
* Execute a glTranslate call
|
|
|
|
*/
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_Translatef( GLfloat x, GLfloat y, GLfloat z )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
2001-12-18 04:06:44 +00:00
|
|
|
_math_matrix_translate( ctx->CurrentStack->Top, x, y, z);
|
|
|
|
ctx->NewState |= ctx->CurrentStack->DirtyFlag;
|
1999-08-19 00:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_Translated( GLdouble x, GLdouble y, GLdouble z )
|
|
|
|
{
|
2001-09-18 16:16:21 +00:00
|
|
|
_mesa_Translatef((GLfloat) x, (GLfloat) y, (GLfloat) z);
|
1999-11-11 01:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-10 20:01:06 +00:00
|
|
|
void
|
|
|
|
_mesa_LoadTransposeMatrixfARB( const GLfloat *m )
|
|
|
|
{
|
|
|
|
GLfloat tm[16];
|
2000-11-16 21:05:34 +00:00
|
|
|
_math_transposef(tm, m);
|
1999-12-10 20:01:06 +00:00
|
|
|
_mesa_LoadMatrixf(tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
_mesa_LoadTransposeMatrixdARB( const GLdouble *m )
|
|
|
|
{
|
2000-11-16 21:05:34 +00:00
|
|
|
GLfloat tm[16];
|
|
|
|
_math_transposefd(tm, m);
|
|
|
|
_mesa_LoadMatrixf(tm);
|
1999-12-10 20:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
_mesa_MultTransposeMatrixfARB( const GLfloat *m )
|
|
|
|
{
|
|
|
|
GLfloat tm[16];
|
2000-11-16 21:05:34 +00:00
|
|
|
_math_transposef(tm, m);
|
1999-12-10 20:01:06 +00:00
|
|
|
_mesa_MultMatrixf(tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
_mesa_MultTransposeMatrixdARB( const GLdouble *m )
|
|
|
|
{
|
2000-11-16 21:05:34 +00:00
|
|
|
GLfloat tm[16];
|
|
|
|
_math_transposefd(tm, m);
|
|
|
|
_mesa_MultMatrixf(tm);
|
1999-12-10 20:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-19 00:55:39 +00:00
|
|
|
/*
|
1999-11-12 18:10:47 +00:00
|
|
|
* Called via glViewport or display list execution.
|
1999-08-19 00:55:39 +00:00
|
|
|
*/
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_Viewport( GLint x, GLint y, GLsizei width, GLsizei height )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
2001-03-03 20:33:27 +00:00
|
|
|
_mesa_set_viewport(ctx, x, y, width, height);
|
1999-11-12 18:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define a new viewport and reallocate auxillary buffers if the size of
|
|
|
|
* the window (color buffer) has changed.
|
|
|
|
*/
|
|
|
|
void
|
2001-03-03 20:33:27 +00:00
|
|
|
_mesa_set_viewport( GLcontext *ctx, GLint x, GLint y,
|
|
|
|
GLsizei width, GLsizei height )
|
1999-11-12 18:10:47 +00:00
|
|
|
{
|
2001-03-19 22:45:52 +00:00
|
|
|
const GLfloat n = ctx->Viewport.Near;
|
|
|
|
const GLfloat f = ctx->Viewport.Far;
|
|
|
|
|
2001-03-03 20:33:27 +00:00
|
|
|
if (width < 0 || height < 0) {
|
|
|
|
_mesa_error( ctx, GL_INVALID_VALUE, "glViewport" );
|
1999-08-19 00:55:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MESA_VERBOSE & VERBOSE_API)
|
|
|
|
fprintf(stderr, "glViewport %d %d %d %d\n", x, y, width, height);
|
2000-11-22 07:32:16 +00:00
|
|
|
|
1999-08-19 00:55:39 +00:00
|
|
|
/* clamp width, and height to implementation dependent range */
|
|
|
|
width = CLAMP( width, 1, MAX_WIDTH );
|
|
|
|
height = CLAMP( height, 1, MAX_HEIGHT );
|
|
|
|
|
|
|
|
/* Save viewport */
|
|
|
|
ctx->Viewport.X = x;
|
|
|
|
ctx->Viewport.Width = width;
|
|
|
|
ctx->Viewport.Y = y;
|
|
|
|
ctx->Viewport.Height = height;
|
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
/* compute scale and bias values :: This is really driver-specific
|
|
|
|
* and should be maintained elsewhere if at all.
|
|
|
|
*/
|
2000-11-05 18:40:57 +00:00
|
|
|
ctx->Viewport._WindowMap.m[MAT_SX] = (GLfloat) width / 2.0F;
|
|
|
|
ctx->Viewport._WindowMap.m[MAT_TX] = ctx->Viewport._WindowMap.m[MAT_SX] + x;
|
|
|
|
ctx->Viewport._WindowMap.m[MAT_SY] = (GLfloat) height / 2.0F;
|
|
|
|
ctx->Viewport._WindowMap.m[MAT_TY] = ctx->Viewport._WindowMap.m[MAT_SY] + y;
|
2001-09-18 16:16:21 +00:00
|
|
|
ctx->Viewport._WindowMap.m[MAT_SZ] = ctx->DepthMaxF * ((f - n) / 2.0F);
|
|
|
|
ctx->Viewport._WindowMap.m[MAT_TZ] = ctx->DepthMaxF * ((f - n) / 2.0F + n);
|
2000-11-05 18:40:57 +00:00
|
|
|
ctx->Viewport._WindowMap.flags = MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION;
|
|
|
|
ctx->Viewport._WindowMap.type = MATRIX_3D_NO_ROT;
|
2000-10-30 13:31:59 +00:00
|
|
|
ctx->NewState |= _NEW_VIEWPORT;
|
1999-08-19 00:55:39 +00:00
|
|
|
|
|
|
|
/* Check if window/buffer has been resized and if so, reallocate the
|
|
|
|
* ancillary buffers.
|
|
|
|
*/
|
1999-11-11 01:22:25 +00:00
|
|
|
_mesa_ResizeBuffersMESA();
|
1999-08-19 00:55:39 +00:00
|
|
|
|
|
|
|
if (ctx->Driver.Viewport) {
|
|
|
|
(*ctx->Driver.Viewport)( ctx, x, y, width, height );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-11-11 01:22:25 +00:00
|
|
|
void
|
|
|
|
_mesa_DepthRange( GLclampd nearval, GLclampd farval )
|
1999-08-19 00:55:39 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* nearval - specifies mapping of the near clipping plane to window
|
|
|
|
* coordinates, default is 0
|
|
|
|
* farval - specifies mapping of the far clipping plane to window
|
|
|
|
* coordinates, default is 1
|
|
|
|
*
|
|
|
|
* After clipping and div by w, z coords are in -1.0 to 1.0,
|
|
|
|
* corresponding to near and far clipping planes. glDepthRange
|
|
|
|
* specifies a linear mapping of the normalized z coords in
|
|
|
|
* this range to window z coords.
|
|
|
|
*/
|
|
|
|
GLfloat n, f;
|
1999-11-11 01:22:25 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
|
1999-08-19 00:55:39 +00:00
|
|
|
|
|
|
|
if (MESA_VERBOSE&VERBOSE_API)
|
2000-11-22 07:32:16 +00:00
|
|
|
fprintf(stderr, "glDepthRange %f %f\n", nearval, farval);
|
1999-08-19 00:55:39 +00:00
|
|
|
|
|
|
|
n = (GLfloat) CLAMP( nearval, 0.0, 1.0 );
|
|
|
|
f = (GLfloat) CLAMP( farval, 0.0, 1.0 );
|
|
|
|
|
|
|
|
ctx->Viewport.Near = n;
|
|
|
|
ctx->Viewport.Far = f;
|
2001-09-18 16:16:21 +00:00
|
|
|
ctx->Viewport._WindowMap.m[MAT_SZ] = ctx->DepthMaxF * ((f - n) / 2.0F);
|
|
|
|
ctx->Viewport._WindowMap.m[MAT_TZ] = ctx->DepthMaxF * ((f - n) / 2.0F + n);
|
2000-10-30 13:31:59 +00:00
|
|
|
ctx->NewState |= _NEW_VIEWPORT;
|
1999-08-19 00:55:39 +00:00
|
|
|
|
|
|
|
if (ctx->Driver.DepthRange) {
|
|
|
|
(*ctx->Driver.DepthRange)( ctx, nearval, farval );
|
|
|
|
}
|
|
|
|
}
|