Ejemplo n.º 1
0
/*!***************************************************************************
 @fn       			SetTextures
 @param[in]			pContext		Context
 @param[in]			dwScreenX		Screen resolution along X
 @param[in]			dwScreenY		Screen resolution along Y
 @param[in]			bRotate			Rotate print3D by 90 degrees
 @param[in]			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
 @brief      		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,
	const bool bMakeCopy)
{
	// Determine which set of textures to use depending on the screen resolution.
	const unsigned int uiShortestEdge = PVRT_MIN(dwScreenX, dwScreenY);
	const void* pData = NULL;

	if(uiShortestEdge >= 720)
	{
		pData = (void*)_helvbd_56_pvr;
	}
	else if(uiShortestEdge >= 640)
	{
		pData = (void*)_helvbd_46_pvr;
	}
	else
	{
		pData = (void*)_helvbd_36_pvr;
	}
	
	PVRT_UNREFERENCED_PARAMETER(_helvbd_36_pvr_size);
	PVRT_UNREFERENCED_PARAMETER(_helvbd_46_pvr_size);
	PVRT_UNREFERENCED_PARAMETER(_helvbd_56_pvr_size);

	return SetTextures(pContext, pData, dwScreenX, dwScreenY, bRotate, bMakeCopy);
}
Ejemplo n.º 2
0
/*!***************************************************************************
 @Function		PVRTShaderLoadFromFile
 @Input			pszBinFile			binary shader filename
 @Input			pszSrcFile			source shader filename
 @Input			Type				type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
 @Input			Format				shader binary format, or 0 for source shader
 @Output		pObject				the resulting shader object
 @Output		pReturnError		the error message if it failed
 @Input			pContext			Context
 @Input			aszDefineArray		Array of defines to be pre-appended to shader string
 @Input			uiDefArraySize		Size of the define array
 @Return		PVR_SUCCESS on success and PVR_FAIL on failure (also fills pReturnError)
 @Description	Loads a shader file into memory and passes it to the GL. 
				It also passes defines that need to be pre-appended to the shader before compilation.
*****************************************************************************/
EPVRTError PVRTShaderLoadFromFile(	const char* const pszBinFile,
									const char* const pszSrcFile,
									const GLenum Type,
									const GLenum Format,
									GLuint* const pObject,
									CPVRTString* const pReturnError,
									const SPVRTContext* const pContext,
									const char* const* aszDefineArray, GLuint uiDefArraySize)
{
	PVRT_UNREFERENCED_PARAMETER(pContext);

	*pReturnError = "";

	/* 	
		Prepending defines relies on altering the source file that is loaded.
		For this reason, the function calls the source loader instead of the binary loader if defines have
		been passed in.
	*/
	if(Format && pszBinFile && uiDefArraySize == 0)
	{
		CPVRTResourceFile ShaderFile(pszBinFile);
		if (ShaderFile.IsOpen())
		{
			if(PVRTShaderLoadBinaryFromMemory(ShaderFile.DataPtr(), ShaderFile.Size(), Type, Format, pObject, pReturnError) == PVR_SUCCESS)
				return PVR_SUCCESS;
		}

		*pReturnError += CPVRTString("Failed to open shader ") + pszBinFile + "\n";
	}

	CPVRTResourceFile ShaderFile(pszSrcFile);
	if (!ShaderFile.IsOpen())
	{
		*pReturnError += CPVRTString("Failed to open shader ") + pszSrcFile + "\n";
		return PVR_FAIL;
	}
 
	CPVRTString ShaderFileString;
	const char* pShaderData = (const char*) ShaderFile.DataPtr();

	// Is our shader resource file data null terminated?
	if(pShaderData[ShaderFile.Size()-1] != '\0')
	{
		// If not create a temporary null-terminated string
		ShaderFileString.assign(pShaderData, ShaderFile.Size());
		pShaderData = ShaderFileString.c_str();
	}

	return PVRTShaderLoadSourceFromMemory(pShaderData, Type, pObject, pReturnError, aszDefineArray, uiDefArraySize);
}
Ejemplo n.º 3
0
/****************************************************************************
@Function 		Add
@Input			pSrc			The block option to add
@Input			pOb				Object to use vertices from
@Description	Add's the input vertex and triangle data to the current block option
****************************************************************************/
void CBlockOption::Add(
	const CBlockOption	* const pSrc,
	const CObject		* const pOb)
{
	PVRT_UNREFERENCED_PARAMETER(pOb);

	int i;

	// Add vertices from job to block
	for(i = 0; i < pSrc->nVtxNum; ++i)
		AddVertexCheckDup(pSrc->psVtx[i]);

	// Add triangles from job to block
	for(i = 0; i < pSrc->nTriNum; ++i)
		AddTriangle(pSrc->psTri[i]);
}
/*!***************************************************************************
 @Function		Init
 @Input			pContext	A pointer to a PVRTContext
 @Input			bRotate		true to rotate texture 90 degrees.
 @Input			pszError	An option string for returning errors
 @Return 		PVR_SUCCESS on success
 @Description	Initialises the background
*****************************************************************************/
EPVRTError CPVRTBackground::Init(const SPVRTContext * const pContext, bool bRotate, CPVRTString *pszError)
{
	PVRT_UNREFERENCED_PARAMETER(pContext);

	Destroy();

	m_pAPI = new SPVRTBackgroundAPI;

	if(!m_pAPI)
	{
		if(pszError)
			*pszError = "Error: Insufficient memory to allocate SCPVRTBackgroundAPI.";

		return PVR_FAIL;
	}

	m_pAPI->m_ui32VertexShader = 0;
	m_pAPI->m_ui32FragShader = 0;
	m_pAPI->m_ui32ProgramObject = 0;
	m_pAPI->m_ui32VertexBufferObject = 0;

	bool bResult;
	CPVRTString sTmpErrStr;

	// The shader loading code doesn't expect a null pointer for the error string
	if(!pszError)
		pszError = &sTmpErrStr;

	/* Compiles the shaders. For a more detailed explanation, see IntroducingPVRTools */
#if defined(GL_SGX_BINARY_IMG)
	// Try binary shaders first
	bResult = (PVRTShaderLoadBinaryFromMemory(_BackgroundFragShader_fsc, _BackgroundFragShader_fsc_size,
					GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_pAPI->m_ui32FragShader, pszError) == PVR_SUCCESS)
		       && (PVRTShaderLoadBinaryFromMemory(_BackgroundVertShader_vsc, _BackgroundVertShader_vsc_size,
					GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_pAPI->m_ui32VertexShader, pszError) == PVR_SUCCESS);
	if(!bResult)
#endif
	{
		// if binary shaders don't work, try source shaders
		bResult = (PVRTShaderLoadSourceFromMemory(_BackgroundFragShader_fsh, GL_FRAGMENT_SHADER, &m_pAPI->m_ui32FragShader, pszError) == PVR_SUCCESS) &&
				(PVRTShaderLoadSourceFromMemory(_BackgroundVertShader_vsh, GL_VERTEX_SHADER, &m_pAPI->m_ui32VertexShader, pszError)  == PVR_SUCCESS);
	}

	_ASSERT(bResult);

	if(!bResult)
		return PVR_FAIL;

	// Reset the error string
	if(pszError)
		*pszError = "";

	// Create the shader program
	m_pAPI->m_ui32ProgramObject = glCreateProgram();

	// Attach the fragment and vertex shaders to it
	glAttachShader(m_pAPI->m_ui32ProgramObject, m_pAPI->m_ui32FragShader);
	glAttachShader(m_pAPI->m_ui32ProgramObject, m_pAPI->m_ui32VertexShader);

	// Bind the custom vertex attribute "myVertex" to location VERTEX_ARRAY
	glBindAttribLocation(m_pAPI->m_ui32ProgramObject, VERTEX_ARRAY, "myVertex");

	// Bind the custom vertex attribute "myUV" to location TEXCOORD_ARRAY
	glBindAttribLocation(m_pAPI->m_ui32ProgramObject, TEXCOORD_ARRAY, "myUV");

	// Link the program
	glLinkProgram(m_pAPI->m_ui32ProgramObject);
	GLint Linked;
	glGetProgramiv(m_pAPI->m_ui32ProgramObject, GL_LINK_STATUS, &Linked);
	if (!Linked)
	{
		int i32InfoLogLength, i32CharsWritten;
		glGetProgramiv(m_pAPI->m_ui32ProgramObject, GL_INFO_LOG_LENGTH, &i32InfoLogLength);
		char* pszInfoLog = new char[i32InfoLogLength];
		glGetProgramInfoLog(m_pAPI->m_ui32ProgramObject, i32InfoLogLength, &i32CharsWritten, pszInfoLog);
		*pszError = CPVRTString("Failed to link: ") + pszInfoLog + "\n";
		delete [] pszInfoLog;
		bResult = false;
	}

	_ASSERT(bResult);

	if(!bResult)
		return PVR_FAIL;

	// Use the loaded shader program
	glUseProgram(m_pAPI->m_ui32ProgramObject);

	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_pAPI->m_ui32ProgramObject, "sampler2d"), 0);

	// Create the vertex buffer object
	GLfloat *pVertexData = 0;

	// The vertex data for non-rotated
	GLfloat afVertexData[16] = { -1, -1, 1, -1, -1, 1, 1, 1,
						0, 0, 1, 0, 0, 1, 1, 1};

	// The vertex data for rotated
	GLfloat afVertexDataRotated[16] = {-1, 1, -1, -1, 1, 1, 1, -1,
						1, 1, 0, 1, 1, 0, 0, 0};

	if(!bRotate)
		pVertexData = &afVertexData[0];
	else
		pVertexData = &afVertexDataRotated[0];

	glGenBuffers(1, &m_pAPI->m_ui32VertexBufferObject);
	glBindBuffer(GL_ARRAY_BUFFER, m_pAPI->m_ui32VertexBufferObject);

	glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 16, pVertexData, GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, 0);

	m_bInit = true;

	return PVR_SUCCESS;
}
Ejemplo n.º 5
0
/*!***************************************************************************
 @Function			APIInit
 @Description		Initialisation and texture upload. Should be called only once
					for a given context.
*****************************************************************************/
bool CPVRTPrint3D::APIInit(const SPVRTContext	* const pContext, bool bMakeCopy)
{
	PVRT_UNREFERENCED_PARAMETER(pContext);

	m_pAPI = new SPVRTPrint3DAPI;
	if(!m_pAPI)
		return false;

	if(bMakeCopy)
		m_pAPI->m_pInstanceData = new SPVRTPrint3DAPI::SInstanceData();

	SPVRTPrint3DAPI::SInstanceData& Data = (m_pAPI->m_pInstanceData ? *m_pAPI->m_pInstanceData : SPVRTPrint3DAPI::s_InstanceData);

	// Check to see if these shaders have already been loaded previously. Optimisation as we don't want to load many copies of the same shader!
	if(	Data.uFragmentShaderLogo != UNDEFINED_HANDLE && Data.uVertexShaderLogo != UNDEFINED_HANDLE && Data.uProgramLogo != UNDEFINED_HANDLE &&
		Data.uFragmentShaderFont != UNDEFINED_HANDLE && Data.uVertexShaderFont != UNDEFINED_HANDLE && Data.uProgramFont != UNDEFINED_HANDLE
	)
	{
		++SPVRTPrint3DAPI::s_iRefCount;
		return true;
	}

	// Compiles the shaders. For a more detailed explanation, see IntroducingPVRTools
	CPVRTString error;
	GLint Linked;
	bool bRes = true;

	bRes &= (PVRTShaderLoadSourceFromMemory(_Print3DFragShaderLogo_fsh, GL_FRAGMENT_SHADER, &Data.uFragmentShaderLogo, &error) == PVR_SUCCESS);
	bRes &= (PVRTShaderLoadSourceFromMemory(_Print3DVertShaderLogo_vsh, GL_VERTEX_SHADER, &Data.uVertexShaderLogo, &error)  == PVR_SUCCESS);

	_ASSERT(bRes);

	// Create the 'text' program
	Data.uProgramLogo = glCreateProgram();
	glAttachShader(Data.uProgramLogo, Data.uVertexShaderLogo);
	glAttachShader(Data.uProgramLogo, Data.uFragmentShaderLogo);
	glBindAttribLocation(Data.uProgramLogo, VERTEX_ARRAY, "myVertex");
	glBindAttribLocation(Data.uProgramLogo, UV_ARRAY, "myUV");

	glLinkProgram(Data.uProgramLogo);
	glGetProgramiv(Data.uProgramLogo, GL_LINK_STATUS, &Linked);

	if (!Linked)
		bRes = false;

	bRes &= (PVRTShaderLoadSourceFromMemory(_Print3DFragShader_fsh, GL_FRAGMENT_SHADER, &Data.uFragmentShaderFont, &error) == PVR_SUCCESS);
	bRes &= (PVRTShaderLoadSourceFromMemory(_Print3DVertShader_vsh, GL_VERTEX_SHADER, &Data.uVertexShaderFont, &error)  == PVR_SUCCESS);

	_ASSERT(bRes);

	// Create the 'text' program
	Data.uProgramFont = glCreateProgram();
	glAttachShader(Data.uProgramFont, Data.uVertexShaderFont);
	glAttachShader(Data.uProgramFont, Data.uFragmentShaderFont);
	glBindAttribLocation(Data.uProgramFont, VERTEX_ARRAY, "myVertex");
	glBindAttribLocation(Data.uProgramFont, UV_ARRAY, "myUV");
	glBindAttribLocation(Data.uProgramFont, COLOR_ARRAY, "myColour");

	glLinkProgram(Data.uProgramFont);
	glGetProgramiv(Data.uProgramFont, GL_LINK_STATUS, &Linked);

	if (!Linked)
		bRes = false;

	Data.mvpLocationLogo = glGetUniformLocation(Data.uProgramFont, "myMVPMatrix");
	Data.mvpLocationFont = glGetUniformLocation(Data.uProgramLogo, "myMVPMatrix");

	_ASSERT(bRes && Data.mvpLocationLogo != -1 && Data.mvpLocationFont != -1);

	return bRes;
}
Ejemplo n.º 6
0
/*!***************************************************************************
 @Function			UpdateLine
 @Description
*****************************************************************************/
unsigned int CPVRTPrint3D::UpdateLine(const unsigned int dwWin, const float fZPos, float XPos, float YPos, const float fScale, const unsigned int Colour, const char * const Text, SPVRTPrint3DAPIVertex * const pVertices)
{
	unsigned	i=0, VertexCount=0;
	unsigned	Val;
	float		XSize = 0.0f, XFixBug,	YSize = 0;
	float		UPos,	VPos;
	float		USize,	VSize;
#if 0
	float		fWinClipX[2],fWinClipY[2];
#endif
	float		fScaleX, fScaleY, fPreXPos;

	PVRT_UNREFERENCED_PARAMETER(dwWin);

	/* Nothing to update */
	if (Text==NULL) return 0;

	_ASSERT(m_pWin[dwWin].dwFlags & Print3D_WIN_EXIST || !dwWin);

	if (fScale>0)
	{
		fScaleX = m_fScreenScale[0] * fScale * 255.0f;
		fScaleY = m_fScreenScale[1] * fScale * 27.0f;
	}
	else
	{
		fScaleX = m_fScreenScale[0] * 255.0f;
		fScaleY = m_fScreenScale[1] * 12.0f;
	}

	XPos *= m_fScreenScale[0];
	YPos *= m_fScreenScale[1];

	fPreXPos = XPos;

#if 0
	/*
		Calculating our margins
	*/
	if (dwWin)
	{
		fWinClipX[0] = (m_pWin[dwWin].fWinPos[0] + 6.0f) * m_fScreenScale[0];
		fWinClipX[1] = (m_pWin[dwWin].fWinPos[0] + m_pWin[dwWin].fWinSize[0] - 6.0f) * m_fScreenScale[0];

		fWinClipY[0] = (m_pWin[dwWin].fWinPos[1] + 6.0f) * m_fScreenScale[1];
		fWinClipY[1] = (m_pWin[dwWin].fWinPos[1] + m_pWin[dwWin].fWinSize[1]  + 9.0f) * m_fScreenScale[1];

		if(m_pWin[dwWin].dwFlags & Print3D_WIN_TITLE)
		{
			if (m_pWin[dwWin].fTitleFontSize>0)
			{
				fWinClipY[0] +=  m_pWin[dwWin].fTitleFontSize * 25.0f  * m_fScreenScale[1];
				fWinClipY[1] +=  m_pWin[dwWin].fTitleFontSize * 25.0f *  m_fScreenScale[1];
			}
			else
			{
				fWinClipY[0] +=  10.0f * m_fScreenScale[1];
				fWinClipY[1] +=  8.0f  * m_fScreenScale[1];
			}
		}
	}
#endif 

	for(;;)
	{
		Val = (int)Text[i++];

		/* End of the string */
		if (Val==0 || i>MAX_LETTERS) break;

		/* It is SPACE so don't draw and carry on... */
		if (Val==' ')
		{
			if (fScale>0)	XPos += 10.0f/255.0f * fScaleX;
			else			XPos += 5.0f * m_fScreenScale[0];
			continue;
		}

		/* It is HASH so don't draw and carry on... */
		if (Val=='#')
		{
			if (fScale>0)	XPos += 1.0f/255.0f * fScaleX;
			else			XPos += 5.0f * m_fScreenScale[0];
			continue;
		}

		/* It is RETURN so jump a line */
		if (Val==0x0A)
		{
			XPos = fPreXPos - XSize;
			YPos += YSize;
			continue;
		}

		/* If fScale is negative then select the small set of letters (System) */
		if (fScale < 0.0f)
		{
			XPos    += XSize;
			UPos    =  PVRTPrint3DU_System[Val];
			VPos    =  PVRTPrint3DV_System[Val] - 0.0001f; /* Some cards need this little bit */
			YSize   =  fScaleY;
			XSize   =  PVRTPrint3DSize_System[Val] * fScaleX;
			USize	=  PVRTPrint3DSize_System[Val];
			VSize	=  12.0f/255.0f;
		}
		else /* Big set of letters (Bold) */
		{
			XPos    += XSize;
			UPos    =  PVRTPrint3DU_Bold[Val];
			VPos    =  PVRTPrint3DV_Bold[Val] - 1.0f/230.0f;
			YSize   =  fScaleY;
			XSize   =  PVRTPrint3DSize_Bold[Val] * fScaleX;
			USize	=  PVRTPrint3DSize_Bold[Val];
			VSize	=  29.0f/255.0f;
		}

		/*
			CLIPPING
		*/
		XFixBug = XSize;
#if 0
		if(dwWin) /* for dwWin==0 (screen) no clipping */
		{
			float TempSize;

			/* Outside */
			if (XPos>fWinClipX[1]  ||  (YPos)>fWinClipY[1])
			{
				continue;
			}

			/* Clip X */
			if (XPos<fWinClipX[1] && XPos+XSize > fWinClipX[1])
			{
				TempSize = XSize;

				XSize = fWinClipX[1] - XPos;

				if (fScale < 0.0f)
					USize	=  PVRTPrint3DSize_System[Val] * (XSize/TempSize);
				else
					USize	=  PVRTPrint3DSize_Bold[Val] * (XSize/TempSize);
			}

			/*
				Clip Y
			*/
			if (YPos<fWinClipY[1] && YPos+YSize > fWinClipY[1])
			{
				TempSize = YSize;
				YSize = fWinClipY[1] - YPos;

				if(fScale < 0.0f)
				 	VSize	=  (YSize/TempSize)*12.0f/255.0f;
				else
					VSize	=  (YSize/TempSize)*28.0f/255.0f;
			}
		}
#endif

		/* Filling vertex data */
		pVertices[VertexCount+0].sx		= f2vt(XPos);
		pVertices[VertexCount+0].sy		= f2vt(YPos);
		pVertices[VertexCount+0].sz		= f2vt(fZPos);
		pVertices[VertexCount+0].rhw	= f2vt(1.0f);
		pVertices[VertexCount+0].tu		= f2vt(UPos);
		pVertices[VertexCount+0].tv		= f2vt(VPos);

		pVertices[VertexCount+1].sx		= f2vt(XPos+XSize);
		pVertices[VertexCount+1].sy		= f2vt(YPos);
		pVertices[VertexCount+1].sz		= f2vt(fZPos);
		pVertices[VertexCount+1].rhw	= f2vt(1.0f);
		pVertices[VertexCount+1].tu		= f2vt(UPos+USize);
		pVertices[VertexCount+1].tv		= f2vt(VPos);

		pVertices[VertexCount+2].sx		= f2vt(XPos);
		pVertices[VertexCount+2].sy		= f2vt(YPos+YSize);
		pVertices[VertexCount+2].sz		= f2vt(fZPos);
		pVertices[VertexCount+2].rhw	= f2vt(1.0f);
		pVertices[VertexCount+2].tu		= f2vt(UPos);
		pVertices[VertexCount+2].tv		= f2vt(VPos-VSize);

		pVertices[VertexCount+3].sx		= f2vt(XPos+XSize);
		pVertices[VertexCount+3].sy		= f2vt(YPos+YSize);
		pVertices[VertexCount+3].sz		= f2vt(fZPos);
		pVertices[VertexCount+3].rhw	= f2vt(1.0f);
		pVertices[VertexCount+3].tu		= f2vt(UPos+USize);
		pVertices[VertexCount+3].tv		= f2vt(VPos-VSize);

		pVertices[VertexCount+0].color	= Colour;
		pVertices[VertexCount+1].color	= Colour;
		pVertices[VertexCount+2].color	= Colour;
		pVertices[VertexCount+3].color	= Colour;

		VertexCount += 4;

		XSize = XFixBug;

		/* Fix number width */
		if (Val >='0' && Val <='9')
		{
			if (fScale < 0.0f)
				XSize = PVRTPrint3DSize_System[(int)'0'] * fScaleX;
			else
				XSize = PVRTPrint3DSize_Bold[(int)'0'] * fScaleX;
		}
	}

	if(m_bRotate)
		Rotate(pVertices, VertexCount);

	return VertexCount;
}