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

📄 texture.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
<module>
* Name         : Texture.c
* Title        : D3DM texture fucntions
* 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  : Texture creation, manipulation and set up fucntions
*
* Platform     : Windows CE
*
</module>
 $Log: texture.c $
********************************************************************************/

#include "context.h"

/*----------------------------------------------------------------------------
<function>
 FUNCTION	: GetSizeInfo
    
 PURPOSE	: Determines size related info for texture

 PARAMETERS	: dwSize		- x/y size of texture
			  pdwTSPSize	- Pointer to TSP size to fill out
			  pdwScale		- Pointer required scaling factore
			  pdwMapLevels	- Number mip map levels for top dwSize.

 RETURNS	: FALSE if invalid size
</function>
------------------------------------------------------------------------------*/
BOOL GetSizeInfo(DWORD	dwSize,
				 PDWORD pdwTSPSize,
				 PDWORD pdwScale,
				 PDWORD pdwMapLevels)
{
	DWORD dwScale;
	DWORD dwTSPSize;
	DWORD dwMapLevels;

	dwScale = 1;

	switch (dwSize)
	{
		case 2048:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE2048;
			dwMapLevels = 12;
			break;
		}
		case 1024:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE1024;
			dwMapLevels = 11;
			break;
		}
		case 512:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE512;
			dwMapLevels = 10;
			break;
		}
		case 256:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE256;
			dwMapLevels = 9;
			break;
		}
		case 128:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE128;
			dwMapLevels = 8;
			break;
		}
		case 64:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE64;
			dwMapLevels = 7;
			break;
		}
		case 32:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE32;
			dwMapLevels = 6;
			break;
		}
		case 16:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE16;
			dwMapLevels = 5;
			break;
		}
		case 8:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE8;
			dwMapLevels = 4;
			break;
		}
		case 4:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE8;
			dwScale = 2;
			dwMapLevels = 3;
			break;
		}
		case 2:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE8;
			dwScale = 4;
			dwMapLevels = 2;
			break;
		}
		case 1:
		{
			dwTSPSize = MBX1_TSPPL1_TSIZE8;
			dwScale = 8;
			dwMapLevels = 1;
			break;
		}
		default:
		{
			return FALSE;
		}
	}

	if(pdwTSPSize)		*pdwTSPSize		= dwTSPSize;
	if(pdwScale)		*pdwScale		= dwScale;
	if(pdwMapLevels)	*pdwMapLevels	= dwMapLevels;
	return TRUE;
}
/*----------------------------------------------------------------------------
<function
 FUNCTION	: AllocateMipMapChain
 
 PURPOSE	: Calculates and allocates a mip map chain surface

 PARAMETERS	: dwWidth		- width of top map
			  dwHeight		- height of top map
			  eFormat		- Format of tex surface
			  psMapDetails	- TopMapDetails
			  dwBpp			- bits per pixel
 
 RETURNS	: DDHAL return code.
</function>
------------------------------------------------------------------------------*/
BOOL AllocateMipMapChain(LPD3DM_SURFACE	psSurface)
{
	DWORD				dwCurrentWidth;
	DWORD				dwCurrentHeight;
	DWORD				i;
	DWORD				dwAllocSize;
	DWORD				dwMinWidth; 
	DWORD				dwMinHeight;
	PMAP_DETAILS		psMapDetails;
	LPD3DM_CONTEXT		psContext;
	PVRSRV_ERROR		eError;

	dwAllocSize		= 0;
	psContext		= psSurface->psContext;
	psMapDetails	= psSurface->sDescription.sTexture.psMapDetails;

	/* Determine minimum width and height*/
	switch (psSurface->eFormat)
	{
	 	case D3DMFMT_UYVY:
		case D3DMFMT_YUY2:
		{
			dwMinWidth  = 2;
			dwMinHeight = 1;
			break;
		}
 		case MBXFOURCC_PVRTC2:
		{
			dwMinWidth  = 16;
			dwMinHeight = 8;
			break;
		}
		case MBXFOURCC_PVRTC4:
		{
			dwMinWidth  = 8;
			dwMinHeight = 8;
			break;
		}
		default:
		{
			dwMinWidth  = 1;
			dwMinHeight = 1;
		}
	}

	/* Get scaled width and height */
	dwCurrentWidth  = psSurface->sDescription.sTexture.dwScaledWidth;
	dwCurrentHeight = psSurface->sDescription.sTexture.dwScaledHeight;

	/* Loop through map levels */
	for (i = 0; i < psMapDetails->dwMipLevels; i++)
	{
		dwAllocSize += dwCurrentWidth * dwCurrentHeight;

		if (dwCurrentWidth > dwMinWidth)
		{
			dwCurrentWidth >>= 1;
		}
		if (dwCurrentHeight > dwMinHeight)
		{
			dwCurrentHeight >>= 1;
		}
	}

	/* Size in bytes */
	dwAllocSize = (dwAllocSize * psSurface->dwBpp) >> 3;

	/* Allocate memory for complete map */
	if((eError = D3DMAllocDeviceMem(&psContext->sDevData,
									0,
									dwAllocSize,
									MBX1_TSPPL2_TEXADDRALIGNSIZE,
									&psSurface->psMemInfo)) != PVRSRV_OK)
	{
		D3DM_DPF((DPF_WARN,"AllocateMipMapChain:Failed to allocate surface memory"));

		if(eError == PVRSRV_ERROR_OUT_OF_MEMORY)
			psContext->hrLastError = D3DMERR_MEMORYPOOLEMPTY;
		else
			psContext->hrLastError = D3DMERR_DRIVERINTERNALERROR;

		return FALSE;
	}

	/* Record Allocation Size */
	psMapDetails->dwAllocSize = dwAllocSize;

	return TRUE;
}
/*----------------------------------------------------------------------------
<function
 FUNCTION	: SetUpMAPDetails
    
 PURPOSE	: Set up and allocate MIP MAP. 

 PARAMETERS	: pTexDesc		- D3D texture description
 			  psSurface		- Pointer to surface data	
			  
 RETURNS	: TRUE Ok, FALSE if not valid for use as texture.
</function>
------------------------------------------------------------------------------*/
static BOOL SetUpMAPDetails(D3DMTEXTURE_DESC *pTexDesc, LPD3DM_SURFACE psSurface)
{
	DWORD			dwTSPSizeWidth;
	DWORD			dwTSPSizeHeight;
	DWORD			dwScaleU;
	DWORD			dwScaleV;
	DWORD			dwLevelU;
	DWORD			dwLevelV;
	DWORD			dwScaledWidth;
	DWORD			dwScaledHeight;
	BOOL			bStride;
	PMAP_DETAILS	psMapDetails;
	PVR_DEVFORMAT   *psDevFormat = NULL;
	LPD3DM_CONTEXT	psContext;

	bStride							= TRUE;
	psMapDetails					= psSurface->sDescription.sTexture.psMapDetails;
	psMapDetails->dwSuppliedLevels	= 1;
	psContext						= psSurface->psContext;
	psDevFormat						= GetFormatDescriptorD3DM(psContext, pTexDesc->Format);

	/* Record format type */
	psMapDetails->sTSPCtl.dwLCtl1						|= psDevFormat->dwPVRHWFormat;
	psSurface->sDescription.sTexture.dwTextureFormat	 = psDevFormat->dwPVRHWFormat;

	if(!bStride)
	{
		psMapDetails->dwFlags |= MAPDETAILSFLAGS_CANNOT_BE_STRIDE;
	}			 

	if(psDevFormat->bOpaque)
	{
		psMapDetails->dwFlags |= MAPDETAILSFLAGS_OPAQUE;
	}

	/* Sort out the mip-map dimensions (can be rectangular)	*/
	if(!GetSizeInfo(pTexDesc->Width, &dwTSPSizeWidth, &dwScaleU, &dwLevelU))
	{
		D3DM_DPF((DPF_ERROR, "SetUpMAPDetails:Invalid texture width (%d)!", pTexDesc->Width));
		psContext->hrLastError = D3DMERR_DRIVERUNSUPPORTED;
		return FALSE;
	}
	if(!GetSizeInfo(pTexDesc->Height, &dwTSPSizeHeight, &dwScaleV, &dwLevelV))
	{
		D3DM_DPF((DPF_ERROR, "SetUpMAPDetails:Invalid texture height (%d)!", pTexDesc->Height));

⌨️ 快捷键说明

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