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

📄 context.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 2 页
字号:

	/* Setup default registers for this context */
	SetupHWRegs(psContext);

	/*********************************************************************
	*   3D State initialisation											 *
	**********************************************************************/
	/* Default TA primitive-block header word */
	psContext->dwTAPrimCtl			= MBX1_TAPRIM_ZBIAS_MODEINCREASING |
									  MBX1_TAPRIM_CULLMODECW		   |
									  MBX1_TAPRIM_ZEROOFFSETCOL;

	/* Initialise (non-zero) temporary context-state */
	psTState						= &psContext->sTState;
	psTState->dwRSFlags				= TSTATE_RSFLAGS_ZENABLE		|
									  TSTATE_RSFLAGS_COLORVERTEX	|
									  TSTATE_RSFLAGS_LIGHTING		|
									  TSTATE_RSFLAGS_CLIPPING;
									
	psTState->dwBlendMode			= MBX1_ISPTSPCTL_SRCBLENDONE |
									  MBX1_ISPTSPCTL_DESTBLENDZERO;
	psTState->dwAlphaTest			= MBX1_TSPOBJ_ACMPMODEALWAYS;
	psTState->dwDepthCtl			= MBX1_ISPTSPCTL_DCMPMODELE;

	psTState->dwD3DfillMode			= D3DMFILL_SOLID;
	psTState->dwD3DDepthFunc		= D3DMCMP_LESSEQUAL;
	psTState->dwD3DTableFogMode		= D3DMFOG_NONE;
	psTState->dwD3DVertexFogMode	= D3DMFOG_NONE;
	psTState->D3DFogDensity			= D3DM_One;
	psTState->D3DFogStart			= D3DM_One;
	psTState->D3DFogEnd				= D3DM_OneHundred;

	/* Default W-rangle and depth (used if driver gets no WINFO or depth-clear) */
	fTmp = 1e-5f;
	psTState->WNear					= FL2NTV(fTmp);
	psTState->WFar					= D3DM_One;
	psTState->ZMin					= D3DM_Zero;
	psTState->ZMax					= D3DM_One;
	psTState->fLastClearZ			= 1.0f;
	psTState->dwLastClearColour		= 0x00000000;

	/*
		Initialise (non zero) temporary texture-stage related state

		NB:	Don't need to set the colour and alpha operations and arguments,
			as DirectX sets them all the known values when it starts up.
	*/
	for (dwIndex = 0; dwIndex < MBX1_MAXTEXTURE_LAYERS; dwIndex++)
	{
		PLAYER_TSTATE	psLState;

		psLState = &psTState->sLState[dwIndex];

		psLState->pdwD3DAddrMode[0]		= D3DMTADDRESS_WRAP;
		psLState->pdwD3DAddrMode[1]		= D3DMTADDRESS_WRAP;

		psLState->sTSPLState.dwLCtl1	= MBX1_TSPPL1_TUADDRMODEWRAP | 
										  MBX1_TSPPL1_TVADDRMODEWRAP;

		if(psContext->sRegData.dwFlags & D3DMREG_SOFTEN_PUNCH_THROUGH)
		{
			psLState->sTSPLState.dwLCtl1 |= MBX1_TSPPL1_TSOFTEDGEPT;
		}

		psLState->sTSPLState.dwLCtl3	= MBX1_TSPPL3_CS1SELONE | 		
										  MBX1_TSPPL3_CS2SELDIFFUSE | 
										  MBX1_TSPPL3_CS3SELONE | 
										  MBX1_TSPPL3_INVCS3 |
										  MBX1_TSPPL3_AS1SELONE | 
										  MBX1_TSPPL3_AS2SELDIFFUSEALPHA | 
										  MBX1_TSPPL3_AS3SELONE | 
										  MBX1_TSPPL3_INVAS3;

		psLState->dwCoordSetNum = dwIndex;
	}

	/*
		Flag stage-zero as the first stage, so that 'current' gets mapped to
		'diffuse' for texture-blending arguments
	*/
	psTState->sLState[0].dwArgTransFlags = PVR_ARGTRANSFLAG_STAGEZERO;

	/* Set all the FFTNL matrices to an identity transform */
	psSWTNLState = &psTState->sSWTNLState;

	psSWTNLState->sWorldMatrix._11 = D3DM_One;
	psSWTNLState->sWorldMatrix._22 = D3DM_One;
	psSWTNLState->sWorldMatrix._33 = D3DM_One;
	psSWTNLState->sWorldMatrix._44 = D3DM_One;

	psSWTNLState->sViewMatrix._11 = D3DM_One;
	psSWTNLState->sViewMatrix._22 = D3DM_One;
	psSWTNLState->sViewMatrix._33 = D3DM_One;
	psSWTNLState->sViewMatrix._44 = D3DM_One;

	psSWTNLState->sProjMatrix._11 = D3DM_One;
	psSWTNLState->sProjMatrix._22 = D3DM_One;
	psSWTNLState->sProjMatrix._33 = D3DM_One;
	psSWTNLState->sProjMatrix._44 = D3DM_One;

	for	(dwIndex = 0; dwIndex < 4; dwIndex++)
	{
		psSWTNLState->sTexMatrix[dwIndex]._11 = D3DM_One;
		psSWTNLState->sTexMatrix[dwIndex]._22 = D3DM_One;
		psSWTNLState->sTexMatrix[dwIndex]._33 = D3DM_One;
		psSWTNLState->sTexMatrix[dwIndex]._44 = D3DM_One;
	}

	/* Setup default material */
	psSWTNLState->sMaterial.Diffuse.r = D3DM_One;
	psSWTNLState->sMaterial.Diffuse.g = D3DM_One;
	psSWTNLState->sMaterial.Diffuse.b = D3DM_One;
	psSWTNLState->sMaterial.Diffuse.a = D3DM_One;

	/* Set default FF-TNL lighting colour source selections	*/
	psSWTNLState->psD3DColourSourceSel[TNLCOLSRCTYPE_DIFFUSE]  = D3DMMCS_COLOR1;
	psSWTNLState->psD3DColourSourceSel[TNLCOLSRCTYPE_SPECULAR] = D3DMMCS_COLOR2;
	psSWTNLState->psD3DColourSourceSel[TNLCOLSRCTYPE_AMBIENT]  = D3DMMCS_COLOR2;

	/* Initialise (non-zero) default HW state */
	psHWState = &psContext->sHWState;

#if defined(FIX_HW_PRN_145)

	psHWState->sTACtl3DState.dwISPTSPCtl = MBX1_ISPTSPCTL_SRCBLENDONE			|
										   MBX1_ISPTSPCTL_DESTBLENDZERO			|
										   MBX1_ISPTSPCTL_BLENDOPMODEFOGNONE	|
										   MBX1_ISPTSPCTL_GOURAUD				| 
										   MBX1_ISPTSPCTL_CKDISABLE				|	
										   (0 << MBX1_ISPTSPCTL_NUMPASSESSHIFT) |
										   (0 << MBX1_ISPTSPCTL_UVCOUNTSHIFT)	|
										   MBX1_ISPTSPCTL_OBJTYPE_OPAQUE		|
										   MBX1_ISPTSPCTL_DCMPMODELE			|
										   MBX1_ISPTSPCTL_VTXORDERSTRIP;
#else

	psHWState->sTACtl3DState.dwISPTSPCtl = MBX1_ISPTSPCTL_SRCBLENDONE			|
										   MBX1_ISPTSPCTL_DESTBLENDZERO			|
										   MBX1_ISPTSPCTL_LOGICALOPDISABLE		|
										   MBX1_ISPTSPCTL_GOURAUD				| 
										   MBX1_ISPTSPCTL_CKDISABLE				|
										   (0 << MBX1_ISPTSPCTL_NUMPASSESSHIFT) |
										   (0 << MBX1_ISPTSPCTL_UVCOUNTSHIFT)	|
										   MBX1_ISPTSPCTL_OBJTYPE_OPAQUE		|
										   MBX1_ISPTSPCTL_DCMPMODELE			|
										   MBX1_ISPTSPCTL_VTXORDERSTRIP;
#endif

	psHWState->sTACtl3DState.dwTSPObjCtl = MBX1_TSPOBJ_ACMPMODEALWAYS;

	for(dwIndex = 0; dwIndex < MBX1_MAXTEXTURE_LAYERS; dwIndex++)
	{
		psHWState->sTACtl3DState.sTSPLState[dwIndex]	= psTState->sLState[dwIndex].sTSPLState;
	}

#if defined (D3DM_NATIVE_FLOAT)
	psHWState->sTACtl3DState.dwFPFormat			= MBX1_TAFPFORMAT_TYPEIEEEFLOAT;

#if defined (SUPPORT_VGP) || defined (SUPPORT_VGP_LITE)
	psContext->dwNativeFPFormat					= MBX1_TAFPFORMAT_TYPEIEEEFLOAT;
#endif

#else
	psHWState->sTACtl3DState.dwFPFormat			= MBX1_TAFPFORMAT_TYPEFIXEDPOINT | (0x00000010);

#if defined (SUPPORT_VGP) || defined (SUPPORT_VGP_LITE)
	psContext->dwNativeFPFormat					= MBX1_TAFPFORMAT_TYPEFIXEDPOINT | (0x00000010);
#endif

#endif
	psHWState->sTACtl3DState.sVPTrans.ZScale	= D3DM_One;
	psHWState->sTACtl3DState.sVPTrans.ZOffset	= D3DM_Zero;

	/*
		Initialise the non-zero HW state-control data

		NB:	To force all TA-control, 3D-state and VGP section-definitions
			to be submitted before the first primitive, we flag that ALL
			such state has changed. It is assumed that all VGP-constansts 
			and instructions will be setup (and flagged as changed) as
			required - ready to be submitted to the HW before the first
			primitive.
			
		    Since no state has been sent to the HW yet ('state-setup' flags
			will be zero), no comparisons will be made with the 'current'
			HW-state data in the context. This is consistent with the fact
			that the real state in use by the HW (until we submit some) is
			undefined.
	*/
	psStateCtl = &psContext->sHWStateCtl;

	psStateCtl->dwTACtl3DStateChanged		= MBX1_TASTATEPRES_ISPCTL |
											  MBX1_TASTATEPRES_TSPCTL |
											  MBX1_TASTATEPRES_LAYER0CTL |
											  MBX1_TASTATEPRES_LAYER1CTL |
											  MBX1_TASTATEPRES_FP_INPUTFORMAT;

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

	psStateCtl->sVGPConstsChanged.dwSize				= MBX1_VGPCONSTANTS_CONST_COUNT;
	psStateCtl->sVGPConstsSetup.dwSize					= MBX1_VGPCONSTANTS_CONST_COUNT;

	/* Flags all sections for submission */
	psContext->sTState.sSWTNLState.dwSectionModFlags	= 0x0000FFFF;

	/*
		Create the passthrough and fixed-function TNL vertex-shaders for
		FVF-type vertex-data
	*/
	if	(!VGPTNLSetup(psContext))
	{
		D3DM_DPF((DPF_ERROR,"PVRD3DM_CreateContext:Failed to create the FVF-type vertex-shaders");
		pccd->rval = D3DM_GENERICFAILURE;
		goto error_exit;
	}
#endif /* #if defined(SUPPORT_VGP) */

	/*********************************************************************
	*   PVR Services initialisation										 *
	**********************************************************************/

	/* Connect to Services */
	D3DMServicesConnect(&psContext->hServices);

	PDUMPINITUM(&psContext->psPDContext, psContext->hServices);

	/* Enumerate PVRSRV devices	*/
	if(PVRSRVEnumerateDevices(psContext->hServices, &dwNumDevices, asDevId) != PVRSRV_OK)
	{
		D3DM_DPF((DPF_ERROR, "PVRD3DM_CreateContext:Failed to enumerate available devices!"));
		goto error_exit;
	}

	/* Obtain 3D and display device data objects */
	for(dwIndex = 0; dwIndex < dwNumDevices; dwIndex++)
	{
		/* Get class of current device */
		PVRSRV_DEVICE_CLASS eDevClass = asDevId[dwIndex].eDeviceClass;

		if(eDevClass == PVRSRV_DEVICE_CLASS_DISPLAY)
		{
			/* Acquire device data for the Display device*/
			if(PVRSRVAcquireDeviceData(psContext->hServices, 
									   dwIndex,
									   &psContext->sDisplayDevData,
									   PVRSRV_DEVICE_TYPE_UNKNOWN) != PVRSRV_OK)
			{
				D3DM_DPF((DPF_ERROR, "PVRD3DM_CreateContext:Failed to acquire device data!"));
				pccd->rval = D3DM_GENERICFAILURE;
				goto error_exit;
			}
		}	
		else if(eDevClass == PVRSRV_DEVICE_CLASS_3D)
		{
			/* Acquire device data for the 3D device */
			if(PVRSRVAcquireDeviceData(psContext->hServices, 
									   dwIndex,
									   &psContext->sDevData, 
									   PVRSRV_DEVICE_TYPE_UNKNOWN) != PVRSRV_OK)
			{
				D3DM_DPF((DPF_ERROR, "PVRD3DM_CreateContext:Failed to acquire device data!"));
				pccd->rval = D3DM_GENERICFAILURE;
				goto error_exit;
			}
		}
	}

	/* Obtain the primary surface object and populate our surface structure */
	GetCurrentModeDetails();

	psDevFormat = GetFormatDescriptorD3DM(psContext, psPVRSupportedDisplayModes[dwCurrentModeIndex].Format);
	if(psDevFormat == IMG_NULL)
	{
		D3DM_DPF((DPF_ERROR, "PVRD3DM_CreateContext:Invalid primary mode"));
		pccd->rval = D3DM_GENERICFAILURE;
		goto error_exit;
	}

	if(PVRSRVAcquirePrimary(&psContext->sDisplayDevData,
							0,
							psPVRSupportedDisplayModes[dwCurrentModeIndex].Width,
							psPVRSupportedDisplayModes[dwCurrentModeIndex].Height,
							psDevFormat->ePVRPixelFormat,
					  		&psContext->psPrimSurfData))
	{
		D3DM_DPF((DPF_ERROR, "PVRD3DM_CreateContext:Failed to get Primary surface data!"));
		pccd->rval = D3DM_GENERICFAILURE;
		goto error_exit;
	}

	/* Create context based command queue for queueing blits, flips and locks*/
	if(PVRSRVCreateCommandQueue(&psContext->sDevData, D3DM_COMMANDQUEUE_SIZE, &psContext->psContextQueue) != PVRSRV_OK)
	{
		D3DM_DPF((DPF_ERROR, "PVRD3DM_CreateContext:Failed to create command queue!"));
		pccd->rval = D3DM_GENERICFAILURE;
		goto error_exit;
	}

	/* Retrieve hardware info struct */
	PVRSRVGetHWInfo(&psContext->sDevData, &psContext->sHWInfo);

#if defined(D3DM_REMOTE_HOOK)
	/* FIXME - TODO */
#else
	/* Call rotation Driver escape */
	psContext->dwRotationAngle = GetRotationAngle();
#endif

	/* Copy back Context handle */
	pccd->nContextId = (ULONG) psContext;

	/* Marh this as a new context */
	psContext->dwFlags |= D3DM_CONTEXT_SWFLAGS_NEW_CONTEXT;

	D3DM_DPF((DPF_EXIT, "<-PVRD3DM_CreateContext"));
    return D3DM_DRIVER_HANDLED;

error_exit:

	/* Clean up and exit */
	if(psContext->psContextQueue)
		PVRSRVDestroyCommandQueue(&psContext->sDevData, psContext->psContextQueue);

	if(psContext->psPrimSurfData)
		PVRSRVReleasePrimary(&psContext->sDisplayDevData, psContext->psPrimSurfData);

	if(GetDevInfo(psContext) != NULL)
		PVRSRVReleaseDeviceData(&psContext->sDevData);

	if(GetDisplayDevInfo(psContext) != NULL)
		PVRSRVReleaseDeviceData(&psContext->sDisplayDevData);

	/* Disconnect from Services */
	D3DMServicesDisconnect(psContext->hServices);

#if defined (SUPPORT_VGP) || defined (SUPPORT_VGP_LITE)
	VGPTNLCleanup(psContext);
#endif /* #if defined(SUPPORT_VGP) */

	if(psContext->ppfnsTSStateFunctions != NULL)
		D3DMFree(psContext->ppfnsTSStateFunctions);

	if(psContext->ppfnsRStateFunctions != NULL)
		D3DMFree(psContext->ppfnsRStateFunctions);

	if(psContext->ppfnsDPOpHandlers != NULL)
		D3DMFree(psContext->ppfnsDPOpHandlers);

	if(psContext != NULL)
		D3DMFree(psContext);

	D3DM_DPF((DPF_EXIT, "<-PVRD3DM_CreateContext"));
	return D3DM_DRIVER_HANDLED;
}

/*----------------------------------------------------------------------------
<function>
	FUNCTION:   PVRD3DM_DestroyContext

	PURPOSE:    

	PARAMETERS:	In:  
	RETURNS:	D3DM_DRIVER_HANDLED || D3DM_DRIVER_NOTHANDLED
</function>
------------------------------------------------------------------------------*/

DWORD PVRD3DM_DestroyContext(D3DM_DESTROYCONTEXT_DATA *pdcd)
{
	LPD3DM_CONTEXT psContext = (LPD3DM_CONTEXT) pdcd->nContextId;
	PLIGHTDATA	   psLight;
	/* Clean up */

	while(psContext->psLightList)
	{
		 psLight = psContext->psLightList;
		 psContext->psLightList = psContext->psLightList->psNext;
		 D3DMFree(psLight);
	}

	PVRSRVDestroyCommandQueue(&psContext->sDevData, psContext->psContextQueue);

	PVRSRVReleasePrimary(&psContext->sDisplayDevData, psContext->psPrimSurfData);

	PVRSRVReleaseDeviceData(&psContext->sDevData);

	PVRSRVReleaseDeviceData(&psContext->sDisplayDevData);

	/* Disconnect from Services */
	D3DMServicesDisconnect(psContext->hServices);

#if defined (SUPPORT_VGP) || defined (SUPPORT_VGP_LITE)
	VGPTNLCleanup(psContext);
#endif /* #if defined(SUPPORT_VGP) */

	D3DMFree(psContext->ppfnsTSStateFunctions);

	D3DMFree(psContext->ppfnsRStateFunctions);

	D3DMFree(psContext->ppfnsDPOpHandlers);

	D3DMFree(psContext);

	ForceDesktopRedraw();

	/* Local profiling */
	PROFILE_PROCESS();

    return D3DM_DRIVER_HANDLED;
}


/*****************************************************************************
 End of file (Context.c)
*****************************************************************************/

⌨️ 快捷键说明

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