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

📄 scene.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
<module>
* Name         : scene.c
* Title        : D3DM scene handling routines
* Author(s)    : Imagination Technologies
* Created      : 2 March 2004
*
* Copyright    : 2004 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.
*
* Description  : D3DM scene handling routines
*
* Platform     : Windows CE
*
</module>
********************************************************************************/

#include "context.h"

void ResubmitHWState(LPD3DM_CONTEXT psContext)
{
	PHWSTATECTL	psHWStateCtl;

#if defined (SUPPORT_VGP) || defined (SUPPORT_VGP_LITE)
    PFLAGARRAY	psChanged;
    PFLAGARRAY	psSetup;
#endif

	D3DM_DPF((DPF_MESSAGE, "ResubmitHWState: Forcing all HW-state for context 0x%8.8lX to be resent", psContext));

	/*
		Flag that all HW-state previously-setup has changed, and that nothing
		has been setup before (thus forcing all state to be resubmitted to
		the HW).
	*/
	psHWStateCtl = &psContext->sHWStateCtl;

	psHWStateCtl->dwTACtl3DStateChanged |= psHWStateCtl->dwTACtl3DStateSetup;
	psHWStateCtl->dwTACtl3DStateSetup = 0;

#if defined (SUPPORT_VGP) || defined (SUPPORT_VGP_LITE)
	psHWStateCtl->dwVGPCtlStateChanged |= psHWStateCtl->dwVGPCtlStateSetup;
	psHWStateCtl->dwVGPCtlStateSetup = 0;

	psChanged = (PFLAGARRAY)(&psHWStateCtl->sVGPConstsChanged);
	psSetup   = (PFLAGARRAY)(&psHWStateCtl->sVGPConstsSetup);

	FlagArraySetFlags(psChanged, psSetup);
	FlagArrayClearFlagRange(psSetup, 0, psSetup->dwSize);

	psChanged = (PFLAGARRAY)(&psHWStateCtl->sVGPInstsChanged);
	psSetup   = (PFLAGARRAY)(&psHWStateCtl->sVGPInstsSetup);

	FlagArraySetFlags(psChanged, psSetup);
	FlagArrayClearFlagRange(psSetup, 0, psSetup->dwSize);
#endif
}

/*****************************************************************************
 FUNCTION	: SetupBGO
    
 PURPOSE	: Setup the BGO  

 PARAMETERS	: psBGObjInfo		- BG OBJ to be setup
			  psRenderTarget    - RT Surface object

 RETURNS	: none
*****************************************************************************/
void SetupBGO(PVRSRV_BGOBJ_INFO	*psBGObjInfo,
			  LPD3DM_SURFACE	psRenderTarget)
{
	DWORD				dwTexFormat;
	DWORD				dwTexAddr;
	DWORD				dwStride;

	/* Use frame buffer pixel format to get texture format */
	switch (psRenderTarget->eFormat)
	{
		case D3DMFMT_A8R8G8B8:
		{
			dwTexFormat = MBX1_TSPPL1_TPIXFORM8888;
			break;
		}
		case D3DMFMT_A1R5G5B5:
		{
			/*
				1555.
			*/
			dwTexFormat = MBX1_TSPPL1_TPIXFORM1555;
			break;
		}
		case D3DMFMT_R5G6B5:
		{
			/*
				565.
			*/
			dwTexFormat = MBX1_TSPPL1_TPIXFORM565;
			break;
		}
		case D3DMFMT_A4R4G4B4:
		{
			/*
				4444.
			*/
			dwTexFormat = MBX1_TSPPL1_TPIXFORM4444;
			break;
		}
		default: 
		{
			//FIXME: error
			break;
		}
	}
	/*
		NB:	MBX1 stride is in terms of 8-pixels
			surface-data stride is in pixels
	*/
	dwStride  = (DWORD)psRenderTarget->dwStridePixel >> 3;

	dwTexAddr = (psRenderTarget->psMemInfo->uiDevAddr.uiAddr >> MBX1_TSPPL2_TEXADDRALIGNSHIFT) 
				& ~MBX1_TSPPL2_TEXADDRCLRMASK;
					
	
	psBGObjInfo->ui32TexAddrStride		= dwTexAddr |
										  ((dwStride << (MBX1_TSPPL2_TEXSTRIDESHIFT - 1)) 
										  & ~MBX1_TSPPL2_TEXSTRIDECLRMASK);
	psBGObjInfo->ui32TexFormatStride	= dwTexFormat |
										  ((dwStride << MBX1_TSPPL1_TEXSTRIDE_LSBSHIFT) 
										  & MBX1_TSPPL1_TEXSTRIDE_LSB);
}


/*****************************************************************************
 FUNCTION	: D3DMQueueRender
    
 PURPOSE	: Starts a Render

 PARAMETERS	: psDevInfo			- Pointer to device-specific data
			  dwNum3DRegs		- Number of global registers to set
			  ps3DRegs			- List of global registers to set
			  
 RETURNS	: void
*****************************************************************************/
void D3DMQueueRender(LPD3DM_CONTEXT	psContext,
					DWORD			dwNum3DRegs,
					PVRSRV_HWREG	*ps3DRegs)
{
	PVRSRV_DEV_INFO		*psDevInfo;
	LPD3DM_SURFACE		psRenderTarget;
	PVRSRV_TARENDERINFO	*psTARenderInfo;
	PVRSRV_DEV_LOCATION *psDevLocation;
	PVRSRV_ERROR		eError;
	PVR3DIF_SHAREDDATA  *ps3DIFSharedData;
	DWORD				dwCurrentRenderData;
	BOOL				bExternalZ;

	eError				= PVRSRV_OK;
	psDevInfo			= GetDevInfo(psContext);
	psRenderTarget		= psContext->psCurrentRenderTarget;
	psTARenderInfo		= psRenderTarget->sDescription.sSurface.psTARenderInfo;
	psDevLocation		= &psDevInfo->sDevLocation;
	ps3DIFSharedData	= psTARenderInfo->psSharedData;
	dwCurrentRenderData = ps3DIFSharedData->ui32CurrentRenderData;
	bExternalZ			= ((psContext->psCurrentDepthBuffer != NULL) ?
						   (psContext->psCurrentDepthBuffer->psMemInfo != NULL) : FALSE);	
	
	PROFILE_START_FUNC(D3DM_QUEUE_RENDER);

	/*
		Check that scene is valid.
	*/
	if( psRenderTarget
	&&	(!IS_RENDER_TARGET(psRenderTarget) || SCENE_IS_INVALID(psRenderTarget)))
	{
		return;
	}

	D3DM_DPF((DPF_MESSAGE, "D3DMQueueRender: Queueing render"));

	/*
		Set reg's for this scene
	*/
	SetupSceneRegs(psContext);

	/*
		Set up background object
	*/
	SetupBGO(&psContext->sBGObjInfo, psContext->psCurrentRenderTarget);

	/*
		Queue the render to the render target queue
	*/
	PDUMPSTRING(psContext->psPDContext, "---- Queueing the render");
	eError = PVRSRVQueueRender(psRenderTarget->sDescription.sSurface.psQueue,
							   psTARenderInfo,
							   &psContext->sBGObjInfo,
							   bExternalZ,
							   psRenderTarget->psMemInfo->psSyncInfo,
							   0, 
							   NULL, 
							   dwNum3DRegs, 
							   ps3DRegs);
	
	if(eError != PVRSRV_OK)
	{
		ASSERT(0);
	}


	PROFILE_STOP_FUNC(D3DM_QUEUE_RENDER);
}


/*****************************************************************************
 FUNCTION	: TAStart
    
 PURPOSE	: Starts the TA

 PARAMETERS	: psContext			- Pointer to context data
			  dwNumTARegs		- Number of global registers to set
			  psTARegs			- List of global registers to set
			  
 RETURNS	: void
*****************************************************************************/
void TAStart(LPD3DM_CONTEXT psContext)
{
	PVRSRV_DEV_INFO		*psDevInfo;
	PVRSRV_HWREG		*psTARegs;
	PVR3DIF_SHAREDDATA  *ps3DIFSharedData;
	PVRSRV_TARENDERINFO *psTARenderInfo;
	DWORD				dwCurrentRenderData;
	LPD3DM_SURFACE		psRenderTarget;
	DEVICE3D			*ps3D; 

	psRenderTarget		= psContext->psCurrentRenderTarget;
	psTARenderInfo		= psRenderTarget->sDescription.sSurface.psTARenderInfo;
	ps3DIFSharedData	= psTARenderInfo->psSharedData;	
	psTARegs			= psContext->psTARegs;
	psDevInfo			= GetDevInfo(psContext);
	dwCurrentRenderData = ps3DIFSharedData->ui32CurrentRenderData;
	ps3D				= &psDevInfo->sDeviceSpecific.s3D;

	PROFILE_START_FUNC(TA_START);

	/*
		Check that scene is valid.
	*/
	if((psRenderTarget) &&
	  (!IS_RENDER_TARGET(psRenderTarget) || SCENE_IS_INVALID(psRenderTarget)))
	{
		return;
	}

	D3DM_DPF((DPF_MESSAGE, "TAStart: Starting scene"));
	PDUMPSTRING(psContext->psPDContext, " \r\n");
	PDUMPSTRING(psContext->psPDContext, "---- Starting scene");

	/*
		Set TA Region-header base addresses
	*/
	PDUMPSTRING(psContext->psPDContext, "---- Pre-TA region-header base addresses Updated");
	psTARegs[D3DM_SWTAREG_REGION_BASE].ui32RegVal = 
		ps3DIFSharedData->asRgnHeaderDevVAddr[dwCurrentRenderData].uiAddr & MBX1_TA_REGION_BASE_MASK;

	/* Load general TA registers. We should have previously acquired the TA */
	PDUMPSTRING(psContext->psPDContext, "---- Loading TA regs");

	WriteHWRegs(GetRegisterBase(psContext), D3DM_SWTAREG_COUNT, psTARegs);

	/*
		PDump TA registers
	*/
	PDUMPREGARRAY(psContext->psPDContext, PDUMPTAGS_REG_MBX, psTARegs, D3DM_SWTAREG_COUNT);

	/* Write to TA-start */
	PDUMPSTRING(psContext->psPDContext, "---- Start the TA");
	PDUMPREG(psContext->psPDContext, PDUMPTAGS_REG_MBX, MBX1_TAGLOBREG_START, 1);

	WriteHWReg(GetRegisterBase(psContext), MBX1_TAGLOBREG_START, 1);
	
	/* Flag all state for re-submission */
//	ResubmitHWState(psContext);//FIXME - DO we really need this here

	PROFILE_STOP_FUNC(TA_START);
}
/*****************************************************************************
 FUNCTION	: TAFinish
    
 PURPOSE	: Terminate the current TA control-stream and terminate the
			  object-lists (finishing the scene for good)

 PARAMETERS	: psContext	- The current SW context
			  psDevInfo	- Pointer to device-specific data
			  
 RETURNS	: void

⌨️ 快捷键说明

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