📄 utils.c
字号:
/* Enumerate PVRSRV devices */
PVRSRVEnumerateDevices(hServicesHandle, &dwNumDevices, asDevId);
/* Obtain Display device data object */
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(hServicesHandle,
dwIndex,
&sDisplayDevData,
PVRSRV_DEVICE_TYPE_UNKNOWN) != PVRSRV_OK)
{
D3DM_DPF((DPF_ERROR, "GetCurrentModeIndex:Failed to acquire device data!"));
goto Error_Exit;
}
}
}
/* Obtain the primary surface object and populate our surface structure */
if(PVRSRVQueryPrimary(&sDisplayDevData, &sPrimSurfData) != PVRSRV_OK)
{
D3DM_DPF((DPF_ERROR, "GetCurrentModeIndex:Failed to get Primary surface data!"));
goto Error_Exit;
}
/* Get format descriptor */
psDevFormat = GetFormatDescriptorPVR(sPrimSurfData.ePixelFormat);
if(psDevFormat == NULL)
{
D3DM_DPF((DPF_ERROR, "GetCurrentModeIndex:Failed to find a match for display mode format"));
goto Error_Exit;
}
/* Store Data */
psPVRSupportedDisplayModes[0].Format = psDevFormat->sD3DDevFormat.Format;
psPVRSupportedDisplayModes[0].Width = sPrimSurfData.ui32PixelWidth;
psPVRSupportedDisplayModes[0].Height = sPrimSurfData.ui32PixelHeight;
Error_Exit:
/* clean up and exit */
if(sDisplayDevData.psDevInfoKM != NULL)
PVRSRVReleaseDeviceData(&sDisplayDevData);
/* Disconnect from Services */
D3DMServicesDisconnect(hServicesHandle);
return;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: GetSupportedD3DMFormatList
PURPOSE: Constructs D3DM Device Format list
PARAMETERS: In: psDevFmts - pointer to middleware allocated array to be set up
RETURNS:
</function>
------------------------------------------------------------------------------*/
VOID SetUpSupportedD3DMFormatList(D3DMDEVICEFORMAT *psDevFmts)
{
DWORD i;
for(i=0; i<dwPVRNumSupportedFormats; i++)
{
psDevFmts[i] = psPVR_Formats[i].sD3DDevFormat;
}
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: GetFormatDescriptorPVR
PURPOSE: returns pointer to format descriptor for passed in
PVR pixel format
PARAMETERS: In: eFormat - PVR Format type
RETURNS: A PVR Format description
</function>
------------------------------------------------------------------------------*/
PVR_DEVFORMAT* GetFormatDescriptorPVR(PVRSRV_PIXEL_FORMAT eFormat)
{
DWORD i;
for(i=0; i<dwPVRNumSupportedFormats; i++)
{
if(psPVR_Formats[i].ePVRPixelFormat == eFormat)
return &(psPVR_Formats[i]);
}
return NULL;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: GetFormatDescriptorD3DM
PURPOSE: returns pointer to format descriptor for passed in
D3D pixel format
PARAMETERS: In: eFormat - d3dm Format type
RETURNS:
</function>
------------------------------------------------------------------------------*/
PVR_DEVFORMAT* GetFormatDescriptorD3DM(LPD3DM_CONTEXT psContext, D3DMFORMAT eFormat)
{
DWORD i;
/* Check we don't get any YUV surfaces if we aren't expecting them */
if((psContext->sRegData.dwFlags & D3DMREG_DISABLE_YUV) &&
((eFormat == D3DMFMT_UYVY) || (eFormat == D3DMFMT_YUY2)))
{
return NULL;
}
for(i=0; i<dwPVRNumSupportedFormats; i++)
{
if(psPVR_Formats[i].sD3DDevFormat.Format == eFormat)
return &(psPVR_Formats[i]);
}
return NULL;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: ValidatePoolType
PURPOSE: Validates a D3DMRESOURCETYPE aginst current
CAPs for given pool type
PARAMETERS: In: eResourceType - Resource type
In: ePoolType -requested pool typ
RETURNS: true or false
</function>
------------------------------------------------------------------------------*/
BOOL ValidatePoolType(D3DMRESOURCETYPE eResourceType, D3DMPOOL ePoolType)
{
DWORD dwValidateWord = 0;
if(ePoolType == D3DMPOOL_MANAGED)
{
if(sPVRD3DMCaps.SurfaceCaps & D3DMSURFCAPS_MANAGEDPOOL)
return TRUE;
else
return FALSE;
}
switch(eResourceType)
{
case D3DMRTYPE_SURFACE:
{
if(ePoolType == D3DMPOOL_VIDEOMEM)
dwValidateWord = D3DMSURFCAPS_VIDIMAGESURFACE;
else
dwValidateWord = D3DMSURFCAPS_SYSIMAGESURFACE;
break;
}
case D3DMRTYPE_BACKBUFFER:
{
if(ePoolType == D3DMPOOL_VIDEOMEM)
dwValidateWord = D3DMSURFCAPS_VIDBACKBUFFER;
else
dwValidateWord = D3DMSURFCAPS_SYSBACKBUFFER;
}
case D3DMRTYPE_FRONTBUFFER:
{
if(ePoolType == D3DMPOOL_VIDEOMEM)
dwValidateWord = D3DMSURFCAPS_VIDFRONTBUFFER;
else
dwValidateWord = D3DMSURFCAPS_SYSFRONTBUFFER;
}
case D3DMRTYPE_DEPTHSTENCIL:
{
if(ePoolType == D3DMPOOL_VIDEOMEM)
dwValidateWord = D3DMSURFCAPS_VIDDEPTHBUFFER;
else
dwValidateWord = D3DMSURFCAPS_SYSDEPTHBUFFER;
}
case D3DMRTYPE_TEXTURE:
{
if(ePoolType == D3DMPOOL_VIDEOMEM)
dwValidateWord = D3DMSURFCAPS_VIDTEXTURE;
else
dwValidateWord = D3DMSURFCAPS_SYSTEXTURE;
break;
}
case D3DMRTYPE_VERTEXBUFFER:
{
if(ePoolType == D3DMPOOL_VIDEOMEM)
dwValidateWord = D3DMSURFCAPS_VIDVERTEXBUFFER;
else
dwValidateWord = D3DMSURFCAPS_SYSVERTEXBUFFER;
break;
}
case D3DMRTYPE_INDEXBUFFER:
{
if(ePoolType == D3DMPOOL_VIDEOMEM)
dwValidateWord = D3DMSURFCAPS_VIDINDEXBUFFER;
else
dwValidateWord = D3DMSURFCAPS_SYSINDEXBUFFER;
break;
}
default:
return FALSE;
}
/* Validate*/
if(sPVRD3DMCaps.SurfaceCaps & dwValidateWord)
return TRUE;
else
return FALSE;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: ValidateLockTarget
PURPOSE: Validates a lockability of given D3DMRESOURCETYPE
PARAMETERS: In: eResourceType - Resource type
In: dwUsage - Usage flags
RETURNS: true or false
</function>
------------------------------------------------------------------------------*/
BOOL ValidateLockTarget(D3DMRESOURCETYPE eResourceType, DWORD dwUsage)
{
DWORD dwValidateWord = 0;
switch(eResourceType)
{
case D3DMRTYPE_SURFACE:
{
if(dwUsage & D3DMUSAGE_RENDERTARGET)
{
dwValidateWord = D3DMSURFCAPS_LOCKRENDERTARGET;
break;
}
else
/* Normal image surface can always be locked */
return TRUE;
}
case D3DMRTYPE_BACKBUFFER:
case D3DMRTYPE_FRONTBUFFER:
{
dwValidateWord = D3DMSURFCAPS_LOCKRENDERTARGET;
break;
}
case D3DMRTYPE_DEPTHSTENCIL:
{
dwValidateWord = D3DMSURFCAPS_LOCKDEPTHBUFFER;
break;
}
case D3DMRTYPE_TEXTURE:
{
dwValidateWord = D3DMSURFCAPS_LOCKTEXTURE;
break;
}
case D3DMRTYPE_VERTEXBUFFER:
case D3DMRTYPE_INDEXBUFFER:
/* Vertex and Index buffer can always be locked */
return TRUE;
default:
return FALSE;
}
/* Validate*/
if(sPVRD3DMCaps.SurfaceCaps & dwValidateWord)
return TRUE;
else
return FALSE;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: ValidateNativeDataFormat
PURPOSE: Validates the given data format against the native data format
set in the caps
PARAMETERS: In: eDataFormat - Format to test
RETURNS: BOOL
</function>
------------------------------------------------------------------------------*/
BOOL ValidateNativeDataFormat(D3DMFORMAT eDataFormat)
{
if(eDataFormat == D3DMFMT_D3DMVALUE_FLOAT)
{
return (sPVRD3DMCaps.DevCaps & D3DMDEVCAPS_NATIVEFLOAT ? TRUE : FALSE);
}
else if(eDataFormat == D3DMFMT_D3DMVALUE_FIXED)
{
return (sPVRD3DMCaps.DevCaps & D3DMDEVCAPS_NATIVEFLOAT ? FALSE : TRUE);
}
else
{
D3DM_DPF((DPF_ERROR, "ValidateNativeDataFormat:Invalid data format type"));
return FALSE;
}
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: GetVertexSizeBytes
PURPOSE: Calculates the size of a Vertex in bytes from the passed in FVF
code;
PARAMETERS: In: dwFVF - FVF to decode
RETURNS: DWORD
</function>
------------------------------------------------------------------------------*/
DWORD GetVertexSizeBytes(DWORD dwFVF)
{
DWORD dwBytes = 0;
DWORD dwTextureCount, i;
switch (dwFVF & D3DMFVF_POSITION_MASK)
{
case D3DMFVF_XYZ_FLOAT:
dwBytes += 12;
break;
case D3DMFVF_XYZRHW_FLOAT:
dwBytes += 16;
break;
case D3DMFVF_XYZ_FIXED:
dwBytes += 12;
break;
case D3DMFVF_XYZRHW_FIXED:
dwBytes += 16;
break;
default:
//error!!!!!!!!!!!
break;
}
switch (dwFVF & D3DMFVF_NORMAL_MASK)
{
case D3DMFVF_NORMAL_NONE:
break;
case D3DMFVF_NORMAL_FLOAT:
dwBytes += 12;
break;
case D3DMFVF_NORMAL_FIXED:
dwBytes += 12;
break;
default:
//error!!!!!!!!!!!
break;
}
if((dwFVF & D3DMFVF_DIFFUSE) == D3DMFVF_DIFFUSE)
{
dwBytes += 4;
}
if((dwFVF & D3DMFVF_SPECULAR) == D3DMFVF_SPECULAR)
{
dwBytes += 4;
}
/*
How many textures
*/
switch (dwFVF & D3DMFVF_TEXCOUNT_MASK)
{
case D3DMFVF_TEX0:
dwTextureCount = 0;
break;
case D3DMFVF_TEX1:
dwTextureCount = 1;
break;
case D3DMFVF_TEX2:
dwTextureCount = 2;
break;
case D3DMFVF_TEX3:
dwTextureCount = 3;
break;
case D3DMFVF_TEX4:
dwTextureCount = 4;
break;
default:
ASSERT(0);
//error - don't support more than 2 layers
break;
}
/*
For each texture extract the dimensionality/format and therefore the size
of each texture
FIXME: n.b. because fixed point and float are both 32bit we only need to
look at dimensionality - if spec changes we need to distinguish between
float and fixed
*/
for (i=0; i<dwTextureCount; i++)
{
switch ((dwFVF>>(16+(i*2))) & 0x3)
{
case D3DMFVF_TEXCOORDCOUNT1:
dwBytes += 4;
break;
case D3DMFVF_TEXCOORDCOUNT2:
dwBytes += 8;
break;
case D3DMFVF_TEXCOORDCOUNT3:
dwBytes += 12;
break;
default:
ASSERT(0);
//error unsupported
break;
}
}
return dwBytes;
}
/*----------------------------------------------------------------------------
<function>
FUNCTION: ValidateFVF
PURPOSE: Validates the passed in FVF code agains Caps
PARAMETERS: In: dwFVF - FVF to validate
RETURNS: DWORD
</function>
------------------------------------------------------------------------------*/
BOOL ValidateFVF(DWORD dwFVF)
{
DWORD dwTextureCount = 0;
/* How many textures */
switch (dwFVF & D3DMFVF_TEXCOUNT_MASK)
{
case D3DMFVF_TEX0:
case D3DMFVF_TEX1:
case D3DMFVF_TEX2:
case D3DMFVF_TEX3:
case D3DMFVF_TEX4:
return TRUE;
break;
default:
return FALSE;
break;
}
/*FIXME - validate OTHER STUFF */
}
/*----------------------------------------------------------------------------
<function>
FUNCTION : RoundToTileBoundary
PURPOSE : Rounds pixel X,Y values up to nearest tile boundary.
PARAMETERS : DWORD dwInX - (in) x value in pixels
DWORD dwInY - (in) y value in pixels
LPDWORD pdwOutX - (out) rounded up x value in pixels
LPDWORD pdwOutY - (out) rounded up y value in pixels
LPDWORD pdwTilesOutX - (out) rounded up x value in tiles
LPDWORD pdwTilesOutX - (out) rounded up y value in tiles
RETURNS : void
</function>
------------------------------------------------------------------------------*/
void RoundToTileBoundary(LPD3DM_CONTEXT psContext, BOOL bRoundUp, DWORD dwInX, DWORD dwInY,
LPDWORD pdwOutX, LPDWORD pdwOutY, LPDWORD pdwTilesOutX,
LPDWORD pdwTilesOutY)
{
DEVICE3D *p3DDevice;
p3DDevice = &GetDevInfo(psContext)->sDeviceSpecific.s3D;
if(bRoundUp)
{
dwInX = (dwInX + p3DDevice->ui32PixelsInTileX -1) / p3DDevice->ui32PixelsInTileX;
dwInY = (dwInY + p3DDevice->ui32PixelsInTileY -1) / p3DDevice->ui32PixelsInTileY;
}
else
{
dwInX /= p3DDevice->ui32PixelsInTileX;
dwInY /= p3DDevice->ui32PixelsInTileY;
}
/*
Load up the out parameters
*/
if(pdwOutX) *pdwOutX = dwInX * p3DDevice->ui32PixelsInTileX;
if(pdwOutY) *pdwOutY = dwInY * p3DDevice->ui32PixelsInTileY;
if(pdwTilesOutX) *pdwTilesOutX = dwInX;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -