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

📄 clear.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
								MBX1_ISPTSPCTL_VTXORDERSTRIP		|
								MBX1_ISPTSPCTL_DWDISABLE;
#endif

	sTACtl3DState.dwTSPObjCtl = MBX1_TSPOBJ_ACMPMODEALWAYS;

#if defined (SUPPORT_VGP) || defined (SUPPORT_VGP_LITE)

	sTACtl3DState.dwFPFormat = psContext->dwNativeFPFormat;
	dwStateChanged = MBX1_TASTATEPRES_FP_INPUTFORMAT;

#endif

	dwStateChanged |=  (MBX1_TASTATEPRES_ISPCTL	| 
					    MBX1_TASTATEPRES_TSPCTL);

	/*
		Enable depth write if we've had a depth clear.
	*/
	if(psRenderTarget->sDescription.sSurface.dwClearFlags & D3DM_SURFACE_CLEARFLAGS_FULLSCREEN_DEPTH)
	{
		sTACtl3DState.dwISPTSPCtl &= ~MBX1_ISPTSPCTL_DWDISABLE;
		psRenderTarget->sDescription.sSurface.dwClearFlags &= ~D3DM_SURFACE_CLEARFLAGS_FULLSCREEN_DEPTH;
	}

	/*
		Ensure tag write is enabled, if necessary.
	*/
	if(psRenderTarget->sDescription.sSurface.dwClearFlags & D3DM_SURFACE_CLEARFLAGS_FULLSCREEN_TARGET)
	{
		bAccumulatePrevious = FALSE;
		psRenderTarget->sDescription.sSurface.dwClearFlags &= ~D3DM_SURFACE_CLEARFLAGS_FULLSCREEN_TARGET;
	}

	/*
		Are we accumulating from the previous frame?
	*/
	if(bAccumulatePrevious)
	{
		PMBX1_TSPLAYER_STATE	psTSPLState;
		DWORD					dwStride;

		psTSPLState = &sTACtl3DState.sTSPLState[0];

		/*
			1 pass as we're textured (untextured has default of zero).
		*/
		sTACtl3DState.dwISPTSPCtl |= (1 << MBX1_ISPTSPCTL_NUMPASSESSHIFT);

		/*
			Use clamp mode so bilinear doesnt wrap
			UVs at 0.0 back around to 1.0 (vice versa).
		*/
		psTSPLState->dwLCtl1  = MBX1_TSPPL1_TUADDRMODECLAMP | 
								MBX1_TSPPL1_TVADDRMODECLAMP;

		/* 
			and initialise layer 2 
		*/
		psTSPLState->dwLCtl2 = 0;

		/*
			Always set texture size to 2048x2048. 
			Textures smaller than this are handled by scaling down of UV coords,
			ensuring 3d core never reads off the end of the real allocated texture.
		*/
		psTSPLState->dwLCtl1 |= (MBX1_TSPPL1_TSIZE2048 << MBX1_TSPPL1_TUSIZESHIFT) |
								(MBX1_TSPPL1_TSIZE2048 << MBX1_TSPPL1_TVSIZESHIFT);

		/*
			select texture format.
		*/
		switch (psRenderTarget->eFormat)
		{
			case D3DMFMT_A8R8G8B8:
			{
				dwMBXTextureFormat = MBX1_TSPPL1_TPIXFORM8888;
				break;
			}
			case D3DMFMT_A1R5G5B5:
			{
				/*
					1555.
				*/
				dwMBXTextureFormat = MBX1_TSPPL1_TPIXFORM1555;
				break;
			}
			case D3DMFMT_R5G6B5:
			{
				/*
					565.
				*/
				dwMBXTextureFormat = MBX1_TSPPL1_TPIXFORM565;
				break;
			}
			case D3DMFMT_A4R4G4B4:
			{
				/*
					4444.
				*/
				dwMBXTextureFormat = MBX1_TSPPL1_TPIXFORM4444;
				break;
			}
			default: 
			{
				D3DM_DPF((DPF_ERROR, "SendBackgroundObject:Invalid render target format 0x%8.8X", psRenderTarget->eFormat));
				break;
			}
		}

		/*
			Now write MBX Texture format into control word.
		*/
		psTSPLState->dwLCtl1 |= dwMBXTextureFormat;

		/*
			NB:	MBX1 stride is in terms of 8-pixels
				surface-data stride is in pixels
		*/
		dwStride = (DWORD)psRenderTarget->dwStridePixel >> 3;

		/*
			Write stride into layer-words 1 and 2
		*/
		psTSPLState->dwLCtl1 &= ~MBX1_TSPPL1_TEXSTRIDE_LSB;
		psTSPLState->dwLCtl1 |= (dwStride << MBX1_TSPPL1_TEXSTRIDE_LSBSHIFT) &
								MBX1_TSPPL1_TEXSTRIDE_LSB;

		psTSPLState->dwLCtl2 &= MBX1_TSPPL2_TEXSTRIDECLRMASK;
		psTSPLState->dwLCtl2 |= (dwStride << (MBX1_TSPPL2_TEXSTRIDESHIFT - 1)) & 
								(~MBX1_TSPPL2_TEXSTRIDECLRMASK);

		/*
			texture address
		*/
 		dwTextureAddress = psRenderTarget->psMemInfo->uiDevAddr.uiAddr;

		psTSPLState->dwLCtl2 |= (dwTextureAddress >> MBX1_TSPPL2_TEXADDRALIGNSHIFT) &
								(~MBX1_TSPPL2_TEXADDRCLRMASK);

 		/*
			copy tex colour & tex alpha
		*/
		psTSPLState->dwLCtl3 = MBX1_TSPPL3_CS1SELONE |
							   MBX1_TSPPL3_CS2SELTEXTURE |
							   MBX1_TSPPL3_CS3SELONE |
							   MBX1_TSPPL3_CS4SELDIFFUSE |
							   MBX1_TSPPL3_INVCS3 |
							   MBX1_TSPPL3_AS1SELONE |
							   MBX1_TSPPL3_AS2SELTEXTUREALPHA |
							   MBX1_TSPPL3_AS3SELONE |
							   MBX1_TSPPL3_AS4SELDIFFUSEALPHA |
							   MBX1_TSPPL3_INVAS3;

		/*
			Add texture-layer 0 to the state we have to write
		*/
		dwStateChanged |= MBX1_TASTATEPRES_LAYER0CTL;
	}

	/*
		Set the required TA-ctl/3D state
	*/
	TACSWriteTACtlAnd3DState(psContext,
							 dwStateChanged,
							 &sTACtl3DState,
							 FALSE);

	/*
		Record what state we have changed
	*/
	psContext->sHWStateCtl.dwTACtl3DStateChanged |= dwStateChanged;

	/*
		D3D wbuffering mode requires use of W in depth compare.
		this is done by taking reciprocal of rhw.
		we cant do this in hardware, so we simply use rhw for
		depth comparison in ISP.
	*/
	fDepth = psContext->sTState.fLastClearZ;

	/*
		Fix for Rogue Squadron, that changes Wnear and Wfar midscene.
		We put background at infinity hence use min float as RHW
	*/
	if	(fDepth > 0.9999f)
	{
		/* Min float */
		fDepth = 1.1754944e-038f; 
	}
	else
	{
		D3DM_DPF((DPF_MESSAGE, "wbuffered bckgrnd depth %#8.8lX", FLOAT_TO_LONG(fDepth)));
		
		/*
			Clear depth is normalised W value between 0 -> 1,
			(eye space - post projection, pre-perspective divide), 
			with 0.0 at near clip depth & 1.0 at far clip.
			=> must use WNear & WFar to scale clear W (depth) to
			original range between WNear & WFar.
			(wnear & wfar values are the same as the near/far clip depths used to
			construct the projection matrix, where wnear < wfar)
		*/
		fDepth = NTV2FL(Add(Mul(FL2NTV(fDepth), 
				Sub(psContext->sTState.WFar, psContext->sTState.WNear)), 
				psContext->sTState.WNear));

		D3DM_DPF((DPF_MESSAGE, "       scaled depth %#8.8lX",FLOAT_TO_LONG(fDepth)));

		/*
			Now we must convert it to rhw (= 1 / Wscaled),
			so its in the same space as the 3d data.
			(The TA will take rhw in each vtx and put it
			into the z field of each vtx output to core 3d,
			for depth comparison)
		*/
		if(fDepth == 0.0f)
		{
			/* instead of divide by zero, return max float value */
			fDepth = FLT_MAX;
		}
		else
		{
			fDepth = NTV2FL(Div(D3DM_One, FL2NTV(fDepth)));
		}
	}
	
	D3DM_DPF((DPF_MESSAGE, "          rhw = 1/w %#8.8lX",FLOAT_TO_LONG(fDepth)));

	/*
		Depth clears - all handled as W-buffered.
	*/
	ntvLastClearZ		 = FL2NTV(psContext->sTState.fLastClearZ);
	ntvDepth			 = FL2NTV(fDepth);
	sTexRect.dwFillDepth = TO_ULONG(ntvLastClearZ);
	sTexRect.dwFillRHW   = TO_ULONG(ntvDepth);

	/*
		scale factor for getting src rectangle
		at correct UV coordinates in source texture
	*/
	sTexRect.fUScale = 1.0f / 2048.0f;
	sTexRect.fVScale = 1.0f / 2048.0f;
	sTexRect.bFullScreenClip = TRUE;

	/*
		Since we are using the rendersurface as a texture,
		we know the actual allocated stride is width rounded up to
		nearest tile boundary.
	*/
//FIXME-TILE - We need to re-vist this with respect to Macro tiles
//			- Get Dave R to sort out what is happeneing in the services, then we
//			MACROTILE * TILESPER MACROTILE * PIXELSINTTIL
//		- MAY BREAK IN ANTI-ALIAS

	dwWidth  = psSharedData->ui32XTilesPerMT  * 
			   psSharedData->ui32MTilesX	  * 
			   ps3DDevice->ui32PixelsInTileX;

	dwHeight = psSharedData->ui32YTilesPerMT  *
			   psSharedData->ui32MTilesY	  * 
			   ps3DDevice->ui32PixelsInTileY;

	/*
		Set the rectangle to as much of render surface as possible
	*/
	VLSetRect(	&sTexRect.sSrcRect,
				0,
				0,
				dwWidth,
				dwHeight);

	VLSetRect(	&sTexRect.sDestRect,
				0,
				0,
				dwWidth,
				dwHeight);

	/*
		Draw the render surface rectangle.
	*/
	if(bAccumulatePrevious)
	{
		TexturedRectangle(&sTexRect);
	}
	else
	{
		ClearRectangle(psContext,
					   &sTexRect.sDestRect,
					   psContext->sTState.dwLastClearColour,
					   sTexRect.dwFillDepth,
					   sTexRect.dwFillRHW,
					   TRUE);
	}

	/*
		Reset Flags
	*/
	psRenderTarget->sDescription.sSurface.dwClearFlags = 0;
}
#if !defined(FIX_HW_PRN_302)
/*****************************************************************************
 FUNCTION	: SendFogColourChangeObject
    
 PURPOSE	: Sends full render surface invisible trans object with ISPA fogmode
			  set to special "reserved" mode (3).
			  The vertex colours sent are set to the current fog colour.
			  Allows us to change the value in the Fog Colour registers
			  during the scene between primitives.

 PARAMETERS	:	PD3D_CONTEXT	psContext
				DWORD			dwFogColour
			  
 RETURNS	: 
*****************************************************************************/
void SendFogColourChangeObject(LPD3DM_CONTEXT psContext, DWORD dwFogColour)
{
	HWTACTL3DSTATE		sTACtl3DState;
	DWORD				dwStateChanged = 0;
	LPD3DM_SURFACE		psSurface;
	DWORD				dwWidth;
	DWORD				dwHeight;
	DWORD				dwDepth;
	DWORD				dwRHW;
	D3DMRECT			sRect;
	BOOL				bFullScreen;
	DEVICE3D			*p3DDevice;
	PVR3DIF_SHAREDDATA	*p3DSharedData;
	NTV_TYPE			ntvOne = D3DM_One, ntvZero = D3DM_Zero;

	p3DDevice		 = &psContext->sDevData.psDevInfoKM->sDeviceSpecific.s3D;
	p3DSharedData	 = psContext->psCurrentRenderTarget->sDescription.sSurface.psTARenderInfo->psSharedData;

	D3DM_DPF((DPF_CLEAR, "SendFogColourChangeObject: colour %#8.8lX",dwFogColour));

	/*
		Setup basic TA-Ctl/3D state as required.

		NB:	No need to send VGP viewport-transform as all such internally-
			generated clear-type primitives use passthough VGP-code and 
			have the viewport-tansform disabled in the VGP-clip control word.
			Same for W-clamp.
	*/

#if defined(FIX_HW_PRN_145)

	sTACtl3DState.dwISPTSPCtl = MBX1_ISPTSPCTL_SRCBLENDONE				|
								MBX1_ISPTSPCTL_DESTBLENDZERO			|
								MBX1_ISPTSPCTL_BLENDOPMODELOADFOGCOLOUR |
								MBX1_ISPTSPCTL_CKDISABLE				|
								(0 << MBX1_ISPTSPCTL_NUMPASSESSHIFT)	|
								(0 << MBX1_ISPTSPCTL_UVCOUNTSHIFT)		|
								MBX1_ISPTSPCTL_OBJTYPE_PSTRANS			|
								MBX1_ISPTSPCTL_DCMPMODEALWAYS			|
								MBX1_ISPTSPCTL_TAGWDISABLE				|
								MBX1_ISPTSPCTL_DWDISABLE				|
								MBX1_ISPTSPCTL_VTXORDERSTRIP;

#else
	sTACtl3DState.dwISPTSPCtl = MBX1_ISPTSPCTL_LO_NOOP					|
								MBX1_ISPTSPCTL_LOADFOGCOLOUR			|
								MBX1_ISPTSPCTL_CKDISABLE				|
								(0 << MBX1_ISPTSPCTL_NUMPASSESSHIFT)	|
								(0 << MBX1_ISPTSPCTL_UVCOUNTSHIFT)		|
								MBX1_ISPTSPCTL_OBJTYPE_PSTRANS			|
								MBX1_ISPTSPCTL_DCMPMODEALWAYS			|
								MBX1_ISPTSPCTL_TAGWDISABLE				|
								MBX1_ISPTSPCTL_DWDISABLE				|
								MBX1_ISPTSPCTL_VTXORDERSTRIP;
#endif

	sTACtl3DState.dwTSPObjCtl = MBX1_TSPOBJ_ACMPMODEALWAYS;
								
	dwStateChanged = MBX1_TASTATEPRES_ISPCTL | MBX1_TASTATEPRES_TSPCTL;

#if defined (SUPPORT_VGP) || defined (SUPPORT_VGP_LITE)

	sTACtl3DState.dwFPFormat  = psContext->dwNativeFPFormat;
	dwStateChanged			 |= MBX1_TASTATEPRES_FP_INPUTFORMAT;

#endif

	/*
		Set the required TA-ctl/3D state
	*/
	TACSWriteTACtlAnd3DState(psContext,
							 dwStateChanged,
							 &sTACtl3DState,
							 FALSE);

	/*
		Record what state we have changed
	*/
	psContext->sHWStateCtl.dwTACtl3DStateChanged |= dwStateChanged;

	/*
		Setup some values for depth & rhw.
		RHW must be 1.0 so colours dont get interpolated
		across object.
	*/
	dwDepth = TO_ULONG(ntvZero);
	dwRHW   = TO_ULONG(ntvOne);
	
	/* We want this to be fullscreen */
	bFullScreen = TRUE;

	/*
		Set up rectangle the size of render surface.
		We know the actual allocated stride is width rounded up to
		nearest tile boundary.
	*/
	psSurface = psContext->psCurrentRenderTarget;
//FIXME-TILE - Should this be tie gran boundary
//			MACROTILE * TILESPER MACROTILE * PIXELSINTTIL
//		- MAY BREAK IN ANTI-ALIAS

	dwWidth  = p3DSharedData->ui32XTilesPerMT * 
			   p3DSharedData->ui32MTilesX	  * 
			   p3DDevice->ui32PixelsInTileX;

	dwHeight = p3DSharedData->ui32YTilesPerMT *
			   p3DSharedData->ui32MTilesY	  * 
			   p3DDevice->ui32PixelsInTileY;

	VLSetRect(&sRect, 0, 0, dwWidth, dwHeight);

	/* Use the clear function */
	ClearRectangle(psContext, &sRect, dwFogColour, dwDepth, dwRHW, bFullScreen);

#if defined (SUPPORT_VGP) || defined (SUPPORT_VGP_LITE)
	/* We need to call this here to set up correct copy function and make sure FP format is correct*/
	SetupVertexCopyData(psContext, &psContext->psVertexSource->sVSIFDef);
#endif
}
/*****************************************************************************
 FUNCTION	: SortOutFogColour
    
 PURPOSE	:	The fog registers are a scarce resource, and we send colour
				change objects once they are used up.
				Sending them when prims come down minimises redundant objects.

 PARAMETERS	:	psContext 
 RETURNS	: 
*****************************************************************************/
IMG_VOID SortOutFogColour(LPD3DM_CONTEXT psContext)
{
	PTRANSIENT_STATE	psTState;

	psTState = &psContext->sTState;

	/* Is fog enabled? */
	if(psTState->dwRSFlags & TSTATE_RSFLAGS_FOG) &&
	 !(psContext->sRegData.dwFlags2 & D3DMREG2_ONLYUSELASTFOGCOLOUR))
	{
		/*
			Is current D3D colour different to what was last sent?
			If so, we have a multiple fog-colour per-scene scenario - 
			so send Fog Colour Change Object to handle it.
		*/
		if(psTState->dwVertexFogColour != psTState->dwLastSentVertexFogColour)
		{
			DWORD	dwFogColour;

			/*
				Get D3D Fog Colour & ensure top byte is zeroed. Set top 2 bits
				in order to use colour for both Table Fog & Vertex Fog.
			*/
			dwFogColour = psTState->dwVertexFogColour;
			dwFogColour = (dwFogColour & 0x00FFFFFF);
			dwFogColour |= 0xC0000000;

			/* Send object with fog colour in current D3D renderstate */
			SendFogColourChangeObject(psContext, dwFogColour);

			/*
				Remember what last fog colour sent was.
			*/
			psTState->dwLastSentVertexFogColour = psTState->dwVertexFogColour;
			psTState->dwFogChangeCount++;
		}
	}
}
#endif /*!defined(FIX_HW_PRN_302)*/
/*****************************************************************************
 End of file (clear.c)
*****************************************************************************/

⌨️ 快捷键说明

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