⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ************************************************************************* *\
** ************************************************************************* **
**
**    INTEL Corporation Proprietary Information
**
**    This listing is supplied under the terms of a license
**    agreement with INTEL Corporation and may not be copied
**    nor disclosed except in accordance with the terms of
**    that agreement.
**
**    Copyright (c) 2003 Intel Corporation.
**    All Rights Reserved.
**
** ************************************************************************* **
\* ************************************************************************* */

/**************************************************************************
 * Name         : matrix.c
 * Author       : BCB
 * Created      : 08/05/2003
 *
 * Copyright    : 2003 by Imagination Technologies Limited. All rights reserved.
 *              : No part of this software, either material or conceptual
 *              : may be copied or distributed, transmitted, transcribed,
 *              : stored in a retrieval system or translated into any
 *              : human or computer language in any form by any means,
 *              : electronic, mechanical, manual or other-wise, or
 *              : disclosed to third parties without the express written
 *              : permission of Imagination Technologies Limited, Unit 8, HomePark
 *              : Industrial Estate, King's Langley, Hertfordshire,
 *              : WD4 8LZ, U.K.
 *
 * Platform     : ANSI
 *
 **************************************************************************/
#define MODULE_ID MODID_MATRIX

#include "context.h"
#include "ws.h"
#include "mbx1defs.h"

#include "HXFProfiler.h"
#include "CTL.h"

/***********************************************************************************
 Function Name      : UpdateMatrixChangeCount
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        :
************************************************************************************/
U32 UpdateMatrixChangeCount(GLESContext* gc)
{
	if(++gc->sTransform.MatrixChangeCounter == GLES_MATRIX_CHANGECOUNT_INVALID)
	{
		gc->sTransform.MatrixChangeCounter = GLES_MATRIX_CHANGECOUNT_INVALID + 1;
	}
	return gc->sTransform.MatrixChangeCounter;
}


/***********************************************************************************
 Function Name      : ApplyViewport
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        : UTILITY: Sets current viewport transform
************************************************************************************/

void ApplyViewport(GLESContext *gc)
{
	gc->sState.sViewport.bDirty = TRUE;
}

/***********************************************************************************
 Function Name      : glViewport
 Inputs             : x, y, width, height
 Outputs            : -
 Returns            : -
 Description        : ENTRYPOINT: Sets current viewport state.
					  We use ISP viewport objects to enable portions of a drawable.
					  Also used in VGP viewport/SW TNL calculations.
************************************************************************************/
GLAPI void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
{
	GLESviewport *psViewport = NULL;
	__GL_GET_CONTEXT();
	HXF_PROFILER_START(HXFPROFILE_STATE_MATRIX);
	psViewport = &gc->sState.sViewport;

	if ((width < 0) || (height < 0))
	{
		SetError(gc, GL_INVALID_VALUE);
		return;
    }

	if (width > GLES_MAX_VIEWPORT_WIDTH)
	{
		width = GLES_MAX_VIEWPORT_WIDTH;
    }

    if (height > GLES_MAX_VIEWPORT_HEIGHT)
	{
		height = GLES_MAX_VIEWPORT_HEIGHT;
    }

	switch(gc->sDrawableParams.eRotationAngle)
	{
	case ROTATE_0:
	case ROTATE_180:
		psViewport->i32X = x;
		psViewport->i32Y = y;
		psViewport->ui32Width = width;
		psViewport->ui32Height = height;
		break;
	case ROTATE_90:
	case ROTATE_270:
		psViewport->i32X = y;
		psViewport->i32Y = x;
		psViewport->ui32Width = height;
		psViewport->ui32Height = width;
		break;
	}

	ApplyViewport(gc);

	HXF_PROFILER_STOP(HXFPROFILE_STATE_MATRIX);

	if (!gc->psRenderSurface->bInFrame && (x == 0) && (y == 0) &&
		(psViewport->ui32Width == gc->sDrawableParams.ui32Width) &&
		(psViewport->ui32Height == gc->sDrawableParams.ui32Height))
	{
	   	return;
	}
	gc->bDrawMaskInvalid = IMG_TRUE;

}

/***********************************************************************************
 Function Name      : ApplyDepthRange
 Inputs             : gc, fZNear, fZFar
 Outputs            : -
 Returns            : -
 Description        : UTILITY: Sets current depth range state.
					  Sets VGP viewport/SW TNL state.
************************************************************************************/
void ApplyDepthRange(GLESContext *gc, GLfloat fZNear, GLfloat fZFar)
{
    GLESviewport *psViewport = &gc->sState.sViewport;

	gc->sState.sViewport.MinZ = Clampf(fZNear, GLES_Zero, GLES_One);
	gc->sState.sViewport.MaxZ = Clampf(fZFar, GLES_Zero, GLES_One);

	psViewport->bDirty = HTRUE;
}

/***********************************************************************************
 Function Name      : glDepthRange[f/x]
 Inputs             : fZNear, fZFar
 Outputs            : -
 Returns            : -
 Description        : ENTRYPOINT: Sets current depth range state.
					  Sets VGP viewport/SW TNL state.
************************************************************************************/
#if defined( PROFILE_COMMON )

GLAPI void APIENTRY glDepthRangef( GLclampf fZNear, GLclampf fZFar )
   {
	__GL_GET_CONTEXT();
	GLES_TIME_START( GLES_TIMES_MATRIXMATHS );

	ApplyDepthRange( gc, fZNear, fZFar );

	GLES_TIME_STOP( GLES_TIMES_MATRIXMATHS );

   }   /* glepthRangef */

#endif  /* PROFILE */

GLAPI void APIENTRY glDepthRangex(GLclampx fZNear, GLclampx fZFar)
   {
   __GL_GET_CONTEXT();
   GLES_TIME_START( GLES_TIMES_MATRIXMATHS );

   ApplyDepthRange( gc, XtoF( fZNear ), XtoF( fZFar ));

   GLES_TIME_STOP( GLES_TIMES_MATRIXMATHS );
   
   }  /* glDepthRangex */


/***********************************************************************************
 Function Name      : glMatrixMode
 Inputs             : mode
 Outputs            : -
 Returns            : -
 Description        : ENTRYPOINT: Sets current matrix mode.
					  Picks appropriate function pointers for push/pop/loadidentity.
************************************************************************************/

GLAPI void APIENTRY glMatrixMode(GLenum mode)
{
	__GL_GET_CONTEXT();
	HXF_PROFILER_START(HXFPROFILE_STATE_MATRIX);

	switch (mode)
	{
		case GL_MODELVIEW:
			gc->sProcs.pfnPushMatrix       = ModelViewPushMatrix;
			gc->sProcs.pfnPopMatrix        = ModelViewPopMatrix;
			gc->sProcs.pfnGetCurrentMatrix = ModelViewGetCurrentMatrix;
			break;
		case GL_PROJECTION:
			gc->sProcs.pfnPushMatrix       = ProjectionPushMatrix;
			gc->sProcs.pfnPopMatrix        = ProjectionPopMatrix;
			gc->sProcs.pfnGetCurrentMatrix = ProjectionGetCurrentMatrix;
			break;
		case GL_TEXTURE:
			gc->sProcs.pfnPushMatrix       = TexturePushMatrix;
			gc->sProcs.pfnPopMatrix        = TexturePopMatrix;
			gc->sProcs.pfnGetCurrentMatrix = TextureGetCurrentMatrix;
			break;
		default:
			SetError(gc, GL_INVALID_ENUM);
			return;
    }

	gc->sState.eMatrixMode = mode;
	HXF_PROFILER_STOP(HXFPROFILE_STATE_MATRIX);
}


/***********************************************************************************
 Function Name      : glFrustum[f/x]
 Inputs             : left, right, bottom, top, zNear, zFar
 Outputs            : -
 Returns            : -
 Description        : ENTRYPOINT: Multiplies the current matrix by a perspective
					  matrix.
************************************************************************************/
#if defined( PROFILE_COMMON )

GLAPI void APIENTRY glFrustumf( 
      GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, 
      GLfloat zNear, GLfloat zFar )
   {
	Matrix4f* pMat = 0;
   Matrix4f tmp;
	
   F32 l, r, b, t, n, f;
   F32 deltax, deltay, deltaz;

	__GL_GET_CONTEXT();

	l = left;
	r = right;
	b = bottom;
	t = top;
	n = zNear;
	f = zFar;

   deltax = r - l;
   deltay = t - b;
   deltaz = f - n;

   if(( zNear <= fZERO ) || ( zFar <= fZERO ) || ( deltax == fZERO ) ||
	   ( deltay == fZERO ) || ( deltaz == fZERO ))
	   {
		SetError( gc, GL_INVALID_VALUE );
		return;
      }  // if

	HXF_PROFILER_START( HXFPROFILE_STATE_MATRIX );
   pMat = (*gc->sProcs.pfnGetCurrentMatrix)( gc, TRUE );

	tmp._11 = ( n * 2.0f ) / deltax;
	tmp._12 = fZERO;
	tmp._13 = fZERO;
	tmp._14 = fZERO;

	tmp._21 = fZERO;
	tmp._22 = ( n * 2.0f ) / deltay;
	tmp._23 = fZERO;
	tmp._24 = fZERO;

	tmp._31 =  ( r + l ) / deltax;
	tmp._32 =  ( t + b ) / deltay;
	tmp._33 = -( f + n ) / deltaz;
	tmp._34 = -fONE;

	tmp._41 = fZERO;
	tmp._42 = fZERO;
	tmp._43 = -( f * n * 2 ) / deltaz;
	tmp._44 = fZERO;

	Matrix4f_Multiply( (F32*)pMat, (F32*)&tmp, (F32*)pMat );

	HXF_PROFILER_STOP( HXFPROFILE_STATE_MATRIX );

   }  /* glFrustumf */

GLAPI void APIENTRY glFrustumx( 
      GLfixed left, GLfixed right, GLfixed bottom, GLfixed top, 
      GLfixed zNear, GLfixed zFar )
   {
   glFrustumf( XtoF( left ), XtoF( right ), XtoF( bottom ), XtoF( top ), 
         XtoF( zNear ), XtoF( zFar ));
   }  /* glFrustumx */

#elif defined( PROFILE_COMMON_LITE )

GLAPI void APIENTRY glFrustumx(
      GLfixed left, GLfixed right, GLfixed bottom, GLfixed top,
		GLfixed zNear, GLfixed zFar )
   {
	Matrix4x* pMat = 0;
   Matrix4x tmp;
	
   float l, r, b, t, n, f;
   float deltax, deltay, deltaz;

	__GL_GET_CONTEXT();

	l = XtoF( left );
	r = XtoF( right );
	b = XtoF( bottom );
	t = XtoF( top );
	n = XtoF( zNear );
	f = XtoF( zFar );

   deltax = r - l;
   deltay = t - b;
   deltaz = f - n;

   if(( zNear <= xZERO ) || ( zFar <= xZERO ) || ( deltax == xZERO ) ||
	   ( deltay == xZERO ) || ( deltaz == xZERO ))
	   {
		SetError( gc, GL_INVALID_VALUE );
		return;
      }  // if

	HXF_PROFILER_START( HXFPROFILE_STATE_MATRIX );
   pMat = (*gc->sProcs.pfnGetCurrentMatrix)( gc, TRUE );

	tmp._11 = FtoX( 2.0f * n / deltax );
	tmp._12 = xZERO;
	tmp._13 = xZERO;
	tmp._14 = xZERO;

	tmp._21 = xZERO;
	tmp._22 = FtoX( 2.0f * n / deltay );
	tmp._23 = xZERO;
	tmp._24 = xZERO;

	tmp._31 = FtoX(  ( r + l ) / deltax );
	tmp._32 = FtoX(  ( t + b ) / deltay );
	tmp._33 = FtoX( -( f + n ) / deltaz );
	tmp._34 = -xONE;

	tmp._41 = xZERO;
	tmp._42 = xZERO;
	tmp._43 = FtoX(( -2.0f * n * f ) / deltaz );
	tmp._44 = xZERO;

	Matrix4x_Multiply( (X32*)pMat, (X32*)&tmp, (X32*)pMat );

	HXF_PROFILER_STOP( HXFPROFILE_STATE_MATRIX );

   }  /* glFrustumx */

#else
#error "Profile not defined for glFrustum"
#endif  /* PROFILE */


/***********************************************************************************
 Function Name      : glOrtho[f/x]
 Inputs             : left, right, bottom, top, zNear, zFar
 Outputs            : -
 Returns            : -
 Description        : ENTRYPOINT: Multiplies the current matrix by an orthographic
					  matrix.
************************************************************************************/

#if defined( PROFILE_COMMON )

GLAPI void APIENTRY glOrthof(
      GLfloat left, GLfloat right, GLfloat bottom, GLfloat top,
		GLfloat zNear, GLfloat zFar )
   {
   F32 deltax, deltay, deltaz;
	Matrix4f* pMat = 0;
	Matrix4f tmp;
    
   __GL_GET_CONTEXT();

   deltax = right - left;
   deltay = top - bottom;
   deltaz = zFar - zNear;

	if(( deltax == fZERO ) || ( deltay == fZERO ) || ( deltaz == fZERO ))
	   {
		SetError( gc, GL_INVALID_VALUE );
		return;
      }  // if

	HXF_PROFILER_START( HXFPROFILE_STATE_MATRIX );
	pMat = gc->sProcs.pfnGetCurrentMatrix( gc, TRUE );

	tmp._11 = 2.0f / deltax;
	tmp._12 = fZERO;
	tmp._13 = fZERO;
	tmp._14 = fZERO;

	tmp._21 = fZERO;
	tmp._22 = 2.0f / deltay;
	tmp._23 = fZERO;
	tmp._24 = fZERO;

	tmp._31 = fZERO;
	tmp._32 = fZERO;
	tmp._33 = -2.0f / deltaz;
	tmp._34 = fZERO;

	tmp._41 = -( right + left ) / deltax;
	tmp._42 = -( top + bottom ) / deltay;
	tmp._43 = -( zFar + zNear ) / deltaz;
	tmp._44 = fONE;

	Matrix4f_Multiply( (F32*)pMat, (F32*)&tmp, (F32*)pMat );

	HXF_PROFILER_STOP( HXFPROFILE_STATE_MATRIX );

   }  /* glOrthof */

GLAPI void APIENTRY glOrthox(
      GLfixed left, GLfixed right, GLfixed bottom, GLfixed top,
		GLfixed zNear, GLfixed zFar )
   {
   glOrthof( XtoF( left ), XtoF( right ), XtoF( bottom ), XtoF( top ),
         XtoF( zNear ), XtoF( zFar ));
   }  /* glOrthox */

#elif defined( PROFILE_COMMON_LITE )

GLAPI void APIENTRY glOrthox(
      GLfixed left, GLfixed right, GLfixed bottom, GLfixed top,
		GLfixed zNear, GLfixed zFar )
   {
   X32 deltax, deltay, deltaz;
	Matrix4x* pMat = 0;
	Matrix4x tmp;
    
   __GL_GET_CONTEXT();

   deltax = right - left;
   deltay = top - bottom;
   deltaz = zFar - zNear;

	if(( deltax == xZERO ) || ( deltay == xZERO ) || ( deltaz == xZERO ))
	   {
		SetError( gc, GL_INVALID_VALUE );
		return;
      }  // if

	HXF_PROFILER_START( HXFPROFILE_STATE_MATRIX );
	pMat = gc->sProcs.pfnGetCurrentMatrix( gc, TRUE );

	tmp._11 = Fixed_Div( xONE << 1, deltax );
	tmp._12 = xZERO;
	tmp._13 = xZERO;
	tmp._14 = xZERO;

	tmp._21 = xZERO;
	tmp._22 = Fixed_Div( xONE << 1, deltay );
	tmp._23 = xZERO;
	tmp._24 = xZERO;

	tmp._31 = xZERO;
	tmp._32 = xZERO;
	tmp._33 = -Fixed_Div( xONE << 1, deltaz );
	tmp._34 = xZERO;

	tmp._41 = Fixed_Div( -( right + left ), deltax );
	tmp._42 = Fixed_Div( -( top + bottom ), deltay );
	tmp._43 = Fixed_Div( -( zFar + zNear ), deltaz );
	tmp._44 = xONE;

	Matrix4x_Multiply( (X32*)pMat, (X32*)&tmp, (X32*)pMat );

	HXF_PROFILER_STOP( HXFPROFILE_STATE_MATRIX );

   }  /* glOrthox */

#else
#error "Profile not defined for glFrustum"
#endif  /* PROFILE */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -