Exemplo n.º 1
0
/*!***************************************************************************
	@Function			SetTextures
	@Input				pContext		Context
	@Input				pTexData		User-provided font texture
	@Input				uiDataSize		Size of the data provided
	@Input				dwScreenX		Screen resolution along X
	@Input				dwScreenY		Screen resolution along Y
	@Input				bRotate			Rotate print3D by 90 degrees
	@Input				bMakeCopy		This instance of Print3D creates a copy
										of it's data instead of sharing with previous
										contexts. Set this parameter if you require
										thread safety.	
	@Return			PVR_SUCCESS or PVR_FAIL
	@Description		Initialization and texture upload of user-provided font 
					data. Should be called only once for a Print3D object.
*****************************************************************************/
EPVRTError CPVRTPrint3D::SetTextures(
	const SPVRTContext	* const pContext,
	const void * const pTexData,
	const unsigned int	dwScreenX,
	const unsigned int	dwScreenY,
	const bool bRotate,
	const bool bMakeCopy)
{
	#if !defined (DISABLE_PRINT3D)

	unsigned short	i;
	bool			bStatus;

	// Set the aspect ratio, so we can change it without updating textures or anything else
	float fX, fY;

	m_bRotate = bRotate;
	m_ui32ScreenDim[0] = bRotate ? dwScreenY : dwScreenX;
	m_ui32ScreenDim[1] = bRotate ? dwScreenX : dwScreenY;

	// Alter the X, Y resolutions if the screen isn't portrait.
	if(dwScreenX > dwScreenY)
	{
		fX = (float) dwScreenX;
		fY = (float) dwScreenY;
	}
	else
	{
		fX = (float) dwScreenY;
		fY = (float) dwScreenX;
	}

	m_fScreenScale[0] = (bRotate ? fY : fX) /640.0f;
	m_fScreenScale[1] = (bRotate ? fX : fY) /480.0f;

	// Check whether textures are already set up just in case
	if (m_bTexturesSet)
		return PVR_SUCCESS;

	if(!APIInit(pContext, bMakeCopy))
		return PVR_FAIL;

	/*
		This is the texture with the fonts.
	*/
	PVRTextureHeaderV3 header;
	CPVRTMap<PVRTuint32, CPVRTMap<PVRTuint32, MetaDataBlock> > MetaDataMap;
	bStatus = APIUpLoadTexture((unsigned char *)pTexData, &header, MetaDataMap);
	if (!bStatus) return PVR_FAIL;

	/*
		This is the associated font data with the default font
	*/
	bStatus = LoadFontData(&header, MetaDataMap);
	if (!bStatus) return PVR_FAIL;

	// INDEX BUFFERS
	m_pwFacesFont = (unsigned short*)malloc(PVRTPRINT3D_MAX_RENDERABLE_LETTERS*2*3*sizeof(unsigned short));

	if(!m_pwFacesFont)
		return PVR_FAIL;

	bStatus = APIUpLoadIcons(PVRTPrint3DIMGLogo);
	if (!bStatus) return PVR_FAIL;

	// Vertex indices for letters
	for (i=0; i < PVRTPRINT3D_MAX_RENDERABLE_LETTERS; i++)
	{
		m_pwFacesFont[i*6+0] = 0+i*4;
		m_pwFacesFont[i*6+1] = 3+i*4;
		m_pwFacesFont[i*6+2] = 1+i*4;

		m_pwFacesFont[i*6+3] = 3+i*4;
		m_pwFacesFont[i*6+4] = 0+i*4;
		m_pwFacesFont[i*6+5] = 2+i*4;
	}

	m_nVtxCacheMax = MIN_CACHED_VTX;
	m_pVtxCache = (SPVRTPrint3DAPIVertex*)malloc(m_nVtxCacheMax * sizeof(*m_pVtxCache));
	m_nVtxCache = 0;

	if(!m_pVtxCache)
	{
		return PVR_FAIL;
	}

	// Everything is OK
	m_bTexturesSet = true;

	// Return Success
	return PVR_SUCCESS;

#else
	return PVR_SUCCESS;
#endif
}
Exemplo n.º 2
0
/*!***************************************************************************
 @Function			SetTextures
 @Input				pContext		Context
 @Input				dwScreenX		Screen resolution along X
 @Input				dwScreenY		Screen resolution along Y
 @Input				bRotate			Rotate print3D by 90 degrees
 @Return			PVR_SUCCESS or PVR_FAIL
 @Description		Initialization and texture upload. Should be called only once
					for a given context.
*****************************************************************************/
EPVRTError CPVRTPrint3D::SetTextures(
	const SPVRTContext	* const pContext,
	const unsigned int	dwScreenX,
	const unsigned int	dwScreenY,
	const bool bRotate)
{
#if !defined (DISABLE_PRINT3D)

	unsigned short	i;
	bool			bStatus;

	// Set the aspect ratio, so we can chage it without updating textures or anything else
	float fX, fY;

	m_bRotate = bRotate;
	m_ui32ScreenDim[0] = bRotate ? dwScreenY : dwScreenX;
	m_ui32ScreenDim[1] = bRotate ? dwScreenX : dwScreenY;

	// Alter the X, Y resolutions if the screen isn't portrait.
	if(dwScreenX > dwScreenY)
	{
		fX = (float) dwScreenX;
		fY = (float) dwScreenY;
	}
	else
	{
		fX = (float) dwScreenY;
		fY = (float) dwScreenX;
	}

	m_fScreenScale[0] = (bRotate ? fY : fX) /640.0f;
	m_fScreenScale[1] = (bRotate ? fX : fY) /480.0f;

	// Check whether textures are already set up just in case
	if (m_bTexturesSet)
		return PVR_SUCCESS;

	if(!APIInit(pContext))
		return PVR_FAIL;

	/*
		This is the window background texture
		Type 0 because the data comes in TexTool rectangular format.
	*/
	bStatus = APIUpLoad4444(1, (unsigned char *)WindowBackground, 16, 0);
	if (!bStatus) return PVR_FAIL;

	bStatus = APIUpLoad4444(2, (unsigned char *)WindowPlainBackground, 16, 0);
	if (!bStatus) return PVR_FAIL;

	bStatus = APIUpLoad4444(3, (unsigned char *)WindowBackgroundOp, 16, 0);
	if (!bStatus) return PVR_FAIL;

	bStatus = APIUpLoad4444(4, (unsigned char *)WindowPlainBackgroundOp, 16, 0);
	if (!bStatus) return PVR_FAIL;

	/*
		This is the texture with the fonts.
		Type 1 because there is only alpha component (RGB are white).
	*/
	bStatus = APIUpLoad4444(0, (unsigned char *)PVRTPrint3DABC_Pixels, 256, 1);
	if (!bStatus) return PVR_FAIL;

	// INDEX BUFFERS
	m_pwFacesFont = (unsigned short*)malloc(PVRTPRINT3D_MAX_RENDERABLE_LETTERS*2*3*sizeof(unsigned short));

	if(!m_pwFacesFont)
		return PVR_FAIL;

	bStatus = APIUpLoadIcons((const PVRTuint32 *)PVRTPrint3DPVRLogo, (const PVRTuint32 *)PVRTPrint3DIMGLogo);
	if (!bStatus) return PVR_FAIL;

	// Vertex indices for letters
	for (i=0; i < PVRTPRINT3D_MAX_RENDERABLE_LETTERS; i++)
	{
		m_pwFacesFont[i*6+0] = 0+i*4;
		m_pwFacesFont[i*6+1] = 3+i*4;
		m_pwFacesFont[i*6+2] = 1+i*4;

		m_pwFacesFont[i*6+3] = 3+i*4;
		m_pwFacesFont[i*6+4] = 0+i*4;
		m_pwFacesFont[i*6+5] = 2+i*4;
	}

	m_nVtxCacheMax = MIN_CACHED_VTX;
	m_pVtxCache = (SPVRTPrint3DAPIVertex*)malloc(m_nVtxCacheMax * sizeof(*m_pVtxCache));
	m_nVtxCache = 0;

	if(!m_pVtxCache)
	{
		return PVR_FAIL;
	}

	// Everything is OK
	m_bTexturesSet = true;

	// set all windows for an update
	for (i=0; i<PVRTPRINT3D_MAX_WINDOWS; i++)
		m_pWin[i].bNeedUpdated = true;

	// Return Success
	return PVR_SUCCESS;

#else
	return PVR_SUCCESS;
#endif
}