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

📄 validate.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************
 * Name         : validate.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
 *
 * $Date: 2004/10/06 14:47:38 $ $Revision: 1.18.1.4 $
 * $Log: validate.c $
 **************************************************************************/
#define MODULE_ID MODID_VALIDATE

#include "context.h"
#include "slaveport.h"
#include "texblend.h"

#if defined(SUPPORT_MBX1_LITE)
#include "texblendext.h"
#endif



/***********************************************************************************
 Function Name      : ValidatePointLineSize
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        : Sets up pointer to relevant point/line size/width
************************************************************************************/
IMG_VOID ValidatePointLineSize(GLESContext *gc)
{
	if(gc->ui32RasterEnables & GLES_RS_LINESMOOTH_ENABLE)
	{
		gc->sState.sLine.pfLineWidth = &gc->sState.sLine.fSmoothWidth;
	}
	else
	{
		gc->sState.sLine.pfLineWidth = &gc->sState.sLine.fAliasedWidth;
	}

	if(gc->ui32RasterEnables & GLES_RS_POINTSMOOTH_ENABLE)
	{
		gc->sState.sPoint.pfPointSize = &gc->sState.sPoint.fSmoothSize;
	}
	else
	{
		gc->sState.sPoint.pfPointSize = &gc->sState.sPoint.fAliasedSize;
	}
}

/***********************************************************************************
 Function Name      : ValidatePolygonOffset
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        : Sets up primitive Block Header with z-bias info
************************************************************************************/
IMG_VOID ValidatePolygonOffset(GLESContext *gc)
{
	gc->sHWContext.ui32PrimitiveHeader &= MBX1_TAPRIM_ZBIAS_CLRMASK;
	
	if(gc->ui32RasterEnables & GLES_RS_POLYOFFSET_ENABLE)
	{
		gc->sHWContext.ui32PrimitiveHeader |= gc->sState.sPolygon.ui32DepthBias;
	}
}


/***********************************************************************************
 Function Name      : ValidateTextureState
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        : Makes textures resident if valid and not already resident.
 Description        : Sets up texture blend words from currently valid texture units.
					  Uses environment blend and texture base format to lookup table.
					  Also sets TSPObject word factor color from the last used
					  factor color. (Cannot correctly support GL_BLEND on more than
					  one layer). Sets us TSP pass count based on texture enables and
					  filtering.
************************************************************************************/

IMG_VOID ValidateTextureState(GLESContext *gc)
{
	GLEStextureManager *psTexMgr = gc->sTexture.psTextureManager;
	IMG_UINT32 ui32Loop;
	IMG_UINT32 ui32Count = 0;
	IMG_UINT32 ui32PassCount = 0;
	IMG_BOOL bIsDot3;
	IMG_BOOL bHasFactorCol;

	for (ui32Loop = 0; ui32Loop < GLES_MAX_TEXTURE_UNITS; ui32Loop++)
	{
		GLEStexture *psTex;
		GLEStextureParamState *psParam;
		IMG_FLOAT fMipmapOffset;
		IMG_UINT32 ui32Offset;

		if(gc->sTexture.abTexUnitValid[ui32Loop])
		{
			GLEStextureEnvState *psEnvState = &gc->sState.sTexture.asUnit[ui32Loop].sEnv;
			IMG_UINT32 ui32EnvMode = psEnvState->ui32Mode;

			psTex = gc->sTexture.apsBoundTexture[ui32Loop];
			psParam = &psTex->sState.sParams;

			/* 
			* Set age to zero to indicate texture used in current frame
			*/
			psTex->ui32FrameLastUsed = psTexMgr->ui32CurrentFrame;

			if(psTex->bResidence == IMG_FALSE)
			{
				if(TextureMakeResident(gc, psTex) != IMG_TRUE)
				{
					gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[0] =	
						
						MBX1_TSPPL1_TUADDRMODECLAMP | MBX1_TSPPL1_TVADDRMODECLAMP			| 
						(MBX1_TSPPL1_TSIZE8 << MBX1_TSPPL1_TUSIZESHIFT)						|  
						(MBX1_TSPPL1_TSIZE8 << MBX1_TSPPL1_TVSIZESHIFT)						| 
						MBX1_TSPPL1_TPIXFORM8												|
						(GLES_MAX_TEXTURE_MIPMAP_LEVELS << MBX1_TSPPL1_MIPMAPCLAMPSHIFT);

					gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[1] = 
						MBX1_TSPPL2_MAPFILTERENABLE | MBX1_TSPPL2_MIPCTLNOMIPFILTER			|
						(0x7 << MBX1_TSPPL2_DADJUSTSHIFT)									|
						(psTexMgr->psDummyTexture->uiDevAddr.uiAddr >> MBX1_TSPPL2_TEXADDRALIGNSHIFT);
					
						
					gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[2] = 
						aui32LayerBlendWord[ui32Count][GLES_LUMINANCE_TEX_INDEX][GLES_REPLACE_INDEX];

				
					ui32PassCount++;
					ui32Count++;
					continue;
				}
			}

			/*
			 * This width scale adjust is required because the minimum top map size we support is 8x8.
			 * The D calc must be adjusted to get the correct map compared to the "real" top map size.
			 * The width scale is used (rather than the height scale) to pass conformance, which only
			 * draws horizontal lines to test mipmap transition!
			 */

			if(psParam->ui32MinFilter & MBX1_TSPPL2_MIPCTLMIPFILTER)
			{
				fMipmapOffset = 0.0f - (IMG_FLOAT)psTex->ui32WidthScale;
			}
			else
			{
				fMipmapOffset = 0.5f - (IMG_FLOAT)psTex->ui32WidthScale;
			}

			if(psTex->bForceMipMapped)
			{
				fMipmapOffset += (IMG_FLOAT)psTex->ui32ScaleShift;
			}
			
			fMipmapOffset = Clampf(fMipmapOffset, -1.75, 2.0);
			ui32Offset = (IMG_UINT32) ((fMipmapOffset + 1.75f) * 4.0f);

			psParam->ui32StateWord2 &= ~MBX1_TSPPL2_MAPFILTERENABLE;
			psParam->ui32StateWord2 &= MBX1_TSPPL2_MIPCTLCLRMASK;
			psParam->ui32StateWord2 &= MBX1_TSPPL2_DADJUSTCLRMASK;
		
			psParam->ui32StateWord2 |= (psParam->ui32MinFilter | psParam->ui32MagFilter);
			psParam->ui32StateWord2 |= (ui32Offset << MBX1_TSPPL2_DADJUSTSHIFT);

			if(psParam->ui32StateWord2 & MBX1_TSPPL2_MIPCTLMIPFILTER)
			{
				ui32PassCount += 2;
			}
			else
			{
				ui32PassCount++;
			}

			bIsDot3 = IMG_FALSE;
			bHasFactorCol = IMG_FALSE;

			gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[0] = 
				psParam->ui32StateWord1;
			
			gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[1] = 
				psParam->ui32StateWord2;
			
#if defined(SUPPORT_MBX1_LITE)
			if(ui32EnvMode == GLES_DOT3_RGBA_INDEX)
			{
				bIsDot3 = IMG_TRUE;
			}

			if((ui32EnvMode == GLES_FACTOR_ALPHA_MODULATE_INDEX) ||
				(ui32EnvMode == GLES_BLEND_INDEX && psTex->psFormat->ui32BaseFormatIndex != GLES_ALPHA_TEX_INDEX))
			{
				bHasFactorCol = IMG_TRUE;
			}

			if(ui32EnvMode >= GLES_NUM_TEX_BLENDS)
			{
				ui32EnvMode -= GLES_NUM_TEX_BLENDS;

				gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[2] = 
					aui32ExtLayerBlendWord[ui32Count][psTex->psFormat->ui32BaseFormatIndex][ui32EnvMode];
			}
			else
			{
				gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[2] = 
					aui32LayerBlendWord[ui32Count][psTex->psFormat->ui32BaseFormatIndex][ui32EnvMode];
			}

#else
			if(ui32EnvMode == GLES_COMBINE_INDEX)
			{
				gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[2] =  
					CalcCombineControlWord(psEnvState, &bHasFactorCol, &bIsDot3);
			}
			else
			{
				
				if(ui32EnvMode == GLES_BLEND_INDEX && psTex->psFormat->ui32BaseFormatIndex != GLES_ALPHA_TEX_INDEX)
				{
					bHasFactorCol = IMG_TRUE;
				}
				
				gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[2] = 
					aui32LayerBlendWord[ui32Count][psTex->psFormat->ui32BaseFormatIndex][ui32EnvMode];
			}
#endif		

			if(bHasFactorCol)
			{
				gc->sHWContext.ui32TSPObjectWord &= MBX1_TSPOBJ_FACTORCLRMASK;
				gc->sHWContext.ui32TSPObjectWord |= 
					(gc->sState.sTexture.asUnit[ui32Loop].sEnv.ui32Color << MBX1_TSPOBJ_FACTORSHIFT);
				
				gc->ui32DirtyMask |= GLES_DIRTY_HW_TSPOBJECT;
			}

			if(bIsDot3)
			{
				gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[0] |= MBX1_TSPPL1_CSUM;
			}
			else
			{
				gc->sHWContext.asLayerState[ui32Count].aui32LayerWord[0] &= ~MBX1_TSPPL1_CSUM;
			}
			
			gc->sHWContext.ui32TAControland3DState |= (MBX1_TASTATEPRES_LAYER0CTL << ui32Count);
			ui32Count++;
		}
	}

	if(gc->sHWContext.ui32PassCount != ui32PassCount)
	{
		gc->sHWContext.ui32PassCount = ui32PassCount;
		gc->ui32DirtyMask |= GLES_DIRTY_SW_VERTEXFORMAT;
	}
}


/***********************************************************************************
 Function Name      : SetupControlWords
 Inputs             : gc
 Outputs            : -
 Returns            : -
 Description        : Sets up ISPTSP and TSPObject control words from all relevant
					  GL state. Note: there are some optimisations which can only 
					  be made knowing ALL the state at this time.
************************************************************************************/

IMG_VOID SetupControlWords(GLESContext *gc)
{
	/* 
	 * Start with Object type of opaque - will be changed according to state. 
	 * Start with Blendop mode of no fog (implies alpha blending). 
	 */
	IMG_UINT32 ui32ISPTSP;
	IMG_UINT32 ui32ObjectType = MBX1_ISPTSPCTL_OBJTYPE_OPAQUE;
	IMG_UINT32 ui32BlendOpMode;
	IMG_UINT32 ui32TSPObjectWord; 
	IMG_FLOAT  fWClampVal;

	/*
	 * Start with TSPObject word from context which contains: 
	 *					Alpha test func;Alpha test ref val;Factor color

⌨️ 快捷键说明

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