/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3PVRScopeRemote::LoadShaders(CPVRTString* pErrorStr, const char * const pszFrag, const char * const pszVert)
{
	CPPLProcessingScoped PPLProcessingScoped(m_psSPSCommsData,
		__FUNCTION__, static_cast<unsigned int>(strlen(__FUNCTION__)), m_i32FrameCounter);

	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadSourceFromMemory(
			pszVert, GL_VERTEX_SHADER, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadSourceFromMemory(
			pszFrag, GL_FRAGMENT_SHADER, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	const char* aszAttribs[] = { "inVertex", "inNormal", "inTexCoord" };
	if (PVRTCreateProgram(&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, aszAttribs, 3, pErrorStr))
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}
	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "sThicknessTex"), 0);

	// Store the location of uniforms for later use
	m_ShaderProgram.uiMVPMatrixLoc		= glGetUniformLocation(m_ShaderProgram.uiId, "MVPMatrix");
	m_ShaderProgram.uiLightDirLoc		= glGetUniformLocation(m_ShaderProgram.uiId, "LightDirection");
	m_ShaderProgram.uiEyePosLoc			= glGetUniformLocation(m_ShaderProgram.uiId, "EyePosition");
	m_ShaderProgram.uiMinThicknessLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "MinThickness");
	m_ShaderProgram.uiMaxVariationLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "MaxVariation");

	return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3ComplexLighting::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	const char* aszAttribs[] = { "inVertex", "inNormal", "inTexCoord" };
	if (PVRTCreateProgram(&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}
	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "sTexture"), 0);

	// Store the location of the MVP matrix uniform for later use
	m_ShaderProgram.uiMVPMatrixLoc		= glGetUniformLocation(m_ShaderProgram.uiId, "MVPMatrix");
	m_ShaderProgram.uiModelViewLoc		= glGetUniformLocation(m_ShaderProgram.uiId, "ModelView");
	m_ShaderProgram.uiModelViewITLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "ModelViewIT");
	m_ShaderProgram.uiLightSelLoc		= glGetUniformLocation(m_ShaderProgram.uiId, "iLightSel");
	m_ShaderProgram.uiLightPosLoc		= glGetUniformLocation(m_ShaderProgram.uiId, "LightPosition");
	m_ShaderProgram.uiLightDirLoc		= glGetUniformLocation(m_ShaderProgram.uiId, "LightDirection");
	m_ShaderProgram.uiLightColorLoc		= glGetUniformLocation(m_ShaderProgram.uiId, "LightColor");

	return true;
}
Esempio n. 3
0
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occurred
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3DisplacementMap::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if(PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	const char* aszAttribs[] = { "inVertex", "inNormal", "inTexCoord" };

	if(PVRTCreateProgram(
			&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Store the location of uniforms for later use
	m_ShaderProgram.uiMVPMatrixLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "MVPMatrix");
	m_ShaderProgram.uiLightDirLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "LightDirection");
	m_ShaderProgram.uiDisplacementFactor = glGetUniformLocation(m_ShaderProgram.uiId, "DisplacementFactor");

	m_ShaderProgram.uiTexture = glGetUniformLocation(m_ShaderProgram.uiId, "sTexture");
	m_ShaderProgram.uiDisMap  = glGetUniformLocation(m_ShaderProgram.uiId, "sDisMap");

	return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3Skinning::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/

	if (PVRTCreateProgram(&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, g_aszAttribNames, eNumAttribs, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Store the location of uniforms for later use
	for (int i = 0; i < eNumUniforms; ++i)
	{
		m_ShaderProgram.auiLoc[i] = glGetUniformLocation(m_ShaderProgram.uiId, g_aszUniformNames[i]);
	}


	return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3CellShading::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	// Set up a mapping of attribute names to locations
	const char* aszAttribs[] = { "inVertex", "inNormal" };

	if (PVRTCreateProgram(&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, aszAttribs, 2, pErrorStr))
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Store the location of the MVP matrix uniform for later use
	m_ShaderProgram.uiMVPMatrixLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "MVPMatrix");
	m_ShaderProgram.uiLightDirLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "LightDirection");
	m_ShaderProgram.uiEyePosLoc		= glGetUniformLocation(m_ShaderProgram.uiId, "EyePosition");

	return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occurred
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES2ProceduralTextures::LoadShaders(CPVRTString* pErrorStr)
{
	const char* pszAttribs[] = { "inVertex", "inTexCoord" };
	const unsigned int uiNumAttribs = sizeof(pszAttribs) / sizeof(pszAttribs[0]);
	if (PVRTShaderLoadFromFile(c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShaderId, pErrorStr) != PVR_SUCCESS)
	{ return false; }

	for (unsigned int i = 0; i < NUM_VISUALISATIONS; i++)
	{
		if (PVRTShaderLoadFromFile(c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_auiFragShaderId[i], pErrorStr, NULL, &c_szVisualisations[i], 1) != PVR_SUCCESS)
		{ return false; }

		if (PVRTCreateProgram(&m_auiShaderProgramId[i], m_uiVertShaderId, m_auiFragShaderId[i], pszAttribs, uiNumAttribs, pErrorStr) != PVR_SUCCESS)
		{ return false; }

		glUniform1i(glGetUniformLocation(m_auiShaderProgramId[i], "sTexture"), 0);
		glUniform1i(glGetUniformLocation(m_auiShaderProgramId[i], "sColourSpline"), 1);

		m_aiColourSplineIndices[i] = glGetUniformLocation(m_auiShaderProgramId[i], "uColourSplineIndex");
	}

	return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3AlphaBlend::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	const char* aszAttribs[] = { "inVertex" };
	if (PVRTCreateProgram(&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, aszAttribs, 1, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}
	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "sTexture"), 0);

	// Store the location of uniforms for later use
	m_ShaderProgram.uiLowerLeftLoc = glGetUniformLocation(m_ShaderProgram.uiId, "LowerLeft");
	m_ShaderProgram.uiScaleMatrixLoc = glGetUniformLocation(m_ShaderProgram.uiId, "ScaleMatrix");

	return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES2Coverflow::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if(PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	const char* aszAttribs[] = { "inVertex", "inNormal", "inColor", "inTexCoord" };

	if(PVRTCreateProgram(
			&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, aszAttribs, 4, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}
	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "sTexture"), 0);

	// Store the location of uniforms for later use
	m_ShaderProgram.uiMVPMatrixLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "MVPMatrix");

	return true;
}
Esempio n. 9
0
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3AlphaTest::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile,
			GL_VERTEX_SHADER, GL_SGX_BINARY_IMG,
			&m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szTexFragShaderBinFile, c_szTexFragShaderSrcFile,
			GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG,
			&m_uiTexFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szDiscardFragShaderBinFile, c_szDiscardFragShaderSrcFile,
			GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG,
			&m_uiDiscardFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	const char* aszAttribs[] = { "inVertex", "inTexCoord" };
	// Shader program for alpha blend
	if (PVRTCreateProgram(&m_TexShaderProgram.uiId, m_uiVertShader, m_uiTexFragShader, aszAttribs, 2, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_TexShaderProgram.uiId, "sTexture"), 0);

	// Store the location of uniforms for later use
	m_TexShaderProgram.uiMVPMatrixLoc = glGetUniformLocation(m_TexShaderProgram.uiId, "MVPMatrix");

	// Shader program for alpha test
	if (PVRTCreateProgram(&m_DiscardShaderProgram.uiId, m_uiVertShader, m_uiDiscardFragShader, aszAttribs, 2, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}
	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_DiscardShaderProgram.uiId, "sTexture"), 0);

	// Store the location of uniforms for later use
	m_DiscardShaderProgram.uiMVPMatrixLoc = glGetUniformLocation(m_DiscardShaderProgram.uiId, "MVPMatrix");
	m_DiscardShaderProgram.uiAlphaRefLoc = glGetUniformLocation(m_DiscardShaderProgram.uiId, "AlphaReference");

	return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3EdgeDetection::LoadShaders(CPVRTString* pErrorStr)
{
	/*	Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback. */

	// Load vertex shaders
	if (PVRTShaderLoadFromFile(
			c_szPreVertShaderBin, c_szPreVertShaderSrc, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiPreVertShader, pErrorStr) != PVR_SUCCESS)
	{
		*pErrorStr += "Error: Could not load Pre Process Vertex Shader.";
		return false;
	}
	for (int i=0; i<eNumPostShaders; ++i)
	{
		if (PVRTShaderLoadFromFile(
				c_szPostVertShaderBin, c_szPostVertShaderSrc, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiPostVertShaders[i],
				pErrorStr, 0, c_aszPostShaderDefines[i], g_auiNumPostShaderDefines[i]) != PVR_SUCCESS)
		{
			*pErrorStr += "Error: Could not load Post Process Vertex Shader: ";
			*pErrorStr += g_aszPostShaderNames[i];
			return false;
		}
	}

	// Load fragment shaders
	if (PVRTShaderLoadFromFile(
			c_szPreFragShaderBin, c_szPreFragShaderSrc, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiPreFragShader, pErrorStr) != PVR_SUCCESS)
	{
		*pErrorStr += "Error: Could not load Pre Process Fragment Shader.";
		return false;
	}
	for (int i=0; i<eNumPostShaders; ++i)
	{
		if (PVRTShaderLoadFromFile(
				c_szPostFragShaderBin, c_szPostFragShaderSrc, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiPostFragShaders[i],
				pErrorStr, 0, c_aszPostShaderDefines[i], g_auiNumPostShaderDefines[i]) != PVR_SUCCESS)
		{
			*pErrorStr += "Error: Could not load Post Process Vertex Shader: ";
			*pErrorStr += g_aszPostShaderNames[i];
			return false;
		}
	}

	// Set up and link the shader programs
	if (PVRTCreateProgram(&m_PreShader.uiId, m_uiPreVertShader, m_uiPreFragShader, g_aszAttribNames, eNumAttribs, pErrorStr) != PVR_SUCCESS)
	{
		*pErrorStr += "Failed to Link Pre Shader";
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}
	for (int i=0; i<eNumPostShaders; i++)
	{
		if (PVRTCreateProgram(&m_PostShaders[i].uiId, m_uiPostVertShaders[i], m_uiPostFragShaders[i], g_aszAttribNames, eNumAttribs, pErrorStr) != PVR_SUCCESS)
		{
			*pErrorStr += "Failed to Link Post Shader: ";
			*pErrorStr += g_aszPostShaderNames[i];
			PVRShellSet(prefExitMessage, pErrorStr->c_str());
			return false;
		}
	}

	// Store the location of uniforms for later use
	for (int i = 0; i < eNumPreUniforms; ++i)
	{
		m_PreShader.auiLoc[i] = glGetUniformLocation(m_PreShader.uiId, g_aszPreUniformNames[i]);
	}
	for (int i = 0; i < eNumPostShaders; i++)
	{
		for (int j = 0; j <eNumPostUniforms; j++)
		{
			m_PostShaders[i].auiLoc[j] = glGetUniformLocation(m_PostShaders[i].uiId, g_aszPostUniformNames[j]);
		}
		//Set the post shaders to use the render texture.
		glUseProgram(m_PostShaders[i].uiId);
		glUniform1i(m_PostShaders[i].auiLoc[eColorBufferTexture], 1);
	}

	return true;
}
Esempio n. 11
0
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES2Glass::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiDefaultVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiDefaultFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	if (PVRTCreateProgram(&m_DefaultProgram.uiId, m_uiDefaultVertShader, m_uiDefaultFragShader, g_aszAttribNames, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Store the location of uniforms for later use
	for (int i = 0; i < eNumUniforms; ++i)
	{
		m_DefaultProgram.auiLoc[i] = glGetUniformLocation(m_DefaultProgram.uiId, g_aszUniformNames[i]);
	}



	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadFromFile(
			c_szSkyboxVertShaderBinFile, c_szSkyboxVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiSkyboxVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szSkyboxFragShaderBinFile, c_szSkyboxFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiSkyboxFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	if (PVRTCreateProgram(&m_SkyboxProgram.uiId, m_uiSkyboxVertShader, m_uiSkyboxFragShader, g_aszAttribNames, 1, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Store the location of uniforms for later use
	for (int i = 0; i < eNumUniforms; ++i)
	{
		m_SkyboxProgram.auiLoc[i] = glGetUniformLocation(m_SkyboxProgram.uiId, g_aszUniformNames[i]);
	}



	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadFromFile(
			c_szParaboloidVertShaderBinFile, c_szParaboloidVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiParaboloidVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	if (PVRTCreateProgram(&m_ParaboloidProgram.uiId, m_uiParaboloidVertShader, m_uiDefaultFragShader, g_aszAttribNames, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Store the location of uniforms for later use
	for (int i = 0; i < eNumUniforms; ++i)
	{
		m_ParaboloidProgram.auiLoc[i] = glGetUniformLocation(m_ParaboloidProgram.uiId, g_aszUniformNames[i]);
	}



	for (int i = 0; i < g_iNumEffects; ++i) {
		/*
			Load and compile the shaders from files.
			Binary shaders are tried first, source shaders
			are used as fallback.
		*/
		if (PVRTShaderLoadFromFile(
				c_szReflectionVertShaderBinFile, c_szReflectionVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_auiEffectVertShaders[i], pErrorStr, 0, g_aaszEffectDefines[i], g_aiNumEffectDefines[i]) != PVR_SUCCESS)
		{
			return false;
		}

		if (PVRTShaderLoadFromFile(
				c_szReflectionFragShaderBinFile, c_szReflectionFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_auiEffectFragShaders[i], pErrorStr, 0, g_aaszEffectDefines[i], g_aiNumEffectDefines[i]) != PVR_SUCCESS)
		{
			return false;
		}

		/*
			Set up and link the shader program
		*/
		if (PVRTCreateProgram(&m_aEffectPrograms[i].uiId, m_auiEffectVertShaders[i], m_auiEffectFragShaders[i], g_aszAttribNames, 2, pErrorStr) != PVR_SUCCESS)
		{
			PVRShellSet(prefExitMessage, pErrorStr->c_str());
			return false;
		}

		// Store the location of uniforms for later use
		for (int j = 0; j < eNumUniforms; ++j)
		{
			m_aEffectPrograms[i].auiLoc[j] = glGetUniformLocation(m_aEffectPrograms[i].uiId, g_aszUniformNames[j]);
		}
	}

	return true;
}
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occured
 @Description	Code in InitView() will be called by PVRShell upon
				initialization or after a change in the rendering context.
				Used to initialize variables that are dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLESIntroducingPVRTools::InitView()
{
	/*
		Initialize the textures used by Print3D.
		To properly display text, Print3D needs to know the viewport dimensions
		and whether the text should be rotated. We get the dimensions using the
		shell function PVRShellGet(prefWidth/prefHeight). We can also get the
		rotate parameter by checking prefIsRotated and prefFullScreen.
	*/
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	if(m_Print3D.SetTextures(0, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
		return false;
	}

	// Sets the clear color
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);

	/*
		Loads the texture using the tool function PVRTTextureLoadFromPVR.
		The first parameter is the name of the file and the
		second parameter returns the resulting texture handle.
		The third parameter is a CPVRTString for error message output.
		This function can also be used to conveniently set the filter modes. If
		those parameters are not given, OpenGL ES defaults are used.
		Setting a mipmap filter on a mipmap-less texture will result in an error.
	*/

	if(PVRTTextureLoadFromPVR(c_szTextureFile, &m_uiTexture) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot load the texture\n");
		return false;
	}

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	/*
		Compiles the shaders.
		First we use CPVRTResourceFile to load a file into memory. After construction with a
		file name, we just have to check whether the file is open or an error occured.
		We load both source and binary shaders, then try the binary shader first.
		The data of a CPVRTResourceFile will always be terminated with a 0 byte so it can
		safely be used as a C string.
	*/
	CPVRTResourceFile VertexShaderSrcFile(c_szVertShaderSrcFile);
	CPVRTResourceFile VertexShaderBinFile(c_szVertShaderBinFile);

	CPVRTString ErrorStr;
	/*
		PVRTShaderLoadBinaryFromMemory takes a pointer to the binary shader and the shader size as
		its first arguments. Then follows the shader type and binary format.
		On success, the handle to the new shader object is returned in the fifth parameter, while
		an error string is returned on failure.
	*/
	if (!VertexShaderBinFile.IsOpen() ||
		(PVRTShaderLoadBinaryFromMemory(VertexShaderBinFile.DataPtr(), VertexShaderBinFile.Size(),
			GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertexShader, &ErrorStr) != PVR_SUCCESS))
	{
		/*
			Fallback to source shader
			PVRTShaderLoadSourceFromMemory() takes the shader source code as its 1st argument.
			The shader type as 2nd argument (for now either GL_VERTEX_SHADER or GL_FRAGMENT_SHADER.
			It returns the shader object in its 3rd argument.
			If an error occurs during compilation, the resulting log is returned in the 4th parameter.
			We could also use PVRTLoadAndCompileShaderFromFile() to load and
			compile a shader from an external text file
		*/

		CPVRTString vertexShaderSrc((const char*) VertexShaderSrcFile.DataPtr(), VertexShaderSrcFile.Size());

		if (!VertexShaderSrcFile.IsOpen() ||
			(PVRTShaderLoadSourceFromMemory(vertexShaderSrc.c_str(), GL_VERTEX_SHADER, &m_uiVertexShader, &ErrorStr) != PVR_SUCCESS))
		{
			PVRShellSet(prefExitMessage, ErrorStr.c_str());
			return false;
		}
	}

	/*
		PVRTShaderLoadFromFile can be used to try compiling/loading shaders from files. In this variant,
		two files are tried before failing (usually binary and source files). The type of shader is determined
		from the file extension (.fsh and .vsh for source, .fsc and .vsc for SGX binary shaders)
	*/
	if (PVRTShaderLoadFromFile(c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, &ErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	/*
		PVRTCreateProgram creates a new program object, attaches the shaders, binds attributes (given as an array
		of strings and the size thereof), and makes the program current - or it returns an error string on failure.
	*/
	if (PVRTCreateProgram(&m_ShaderProgram.uiId, m_uiVertexShader, m_uiFragShader, g_aszAttribNames, eNumAttribs, &ErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Store the location of uniforms for later use
	for (int i = 0; i < eNumUniforms; ++i)
	{
		m_ShaderProgram.auiLoc[i] = glGetUniformLocation(m_ShaderProgram.uiId, g_aszUniformNames[i]);
	}

	// Create VBO for the triangle from our data

	// Interleaved vertex data
	GLfloat afVertices[] = {-0.4f,-0.4f,0.0f, // Pos
							 0.0f,0.0f ,				 // UVs
							 0.4f,-0.4f,0.0f,
							 1.0f,0.0f ,
							 0.0f,0.4f ,0.0f,
							 0.5f,1.0f};

	glGenBuffers(1, &m_ui32Vbo);

	m_ui32VertexStride = 5 * sizeof(GLfloat); // 3 floats for the pos, 2 for the UVs

	// Bind the VBO
	glBindBuffer(GL_ARRAY_BUFFER, m_ui32Vbo);

	// Set the buffer's data
	glBufferData(GL_ARRAY_BUFFER, 3 * m_ui32VertexStride, afVertices, GL_STATIC_DRAW);

	// Unbind the VBO
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	return true;
}
Esempio n. 13
0
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occurred
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES2FilmTV::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if(PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	/*
		Set up and link the shader program
	*/
	const char* aszAttribs[] = { "inVertex", "inNormal", "inTexCoord" };

	if(PVRTCreateProgram(
			&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "sTexture"), 0);

	// Store the location of uniforms for later use
	m_ShaderProgram.uiMVPMatrixLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "MVPMatrix");
	m_ShaderProgram.uiLightPosLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "LightPosition");

	// Load and compile the Black and White shader used on the TV screen
	if(PVRTShaderLoadFromFile(
			c_szBWFragShaderBinFile, c_szBWFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiBWFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	// Set up and link the shader program (re-using the already loaded vertex shader
	if(PVRTCreateProgram(
			&m_BWShaderProgram.uiId, m_uiVertShader, m_uiBWFragShader, aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_BWShaderProgram.uiId, "sTexture"), 0);

	// Store the location of uniforms for later use
	m_BWShaderProgram.uiMVPMatrixLoc= glGetUniformLocation(m_BWShaderProgram.uiId, "MVPMatrix");
	m_BWShaderProgram.uiLightPosLoc	= glGetUniformLocation(m_BWShaderProgram.uiId, "LightPosition");

	return true;
}
Esempio n. 14
0
// ---------------------------------------------------------------
bool MyPVRDemo::LoadShaders(CPVRTString* pErrorStr)
	{
	// ---- Load Model Shader
		{
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szModelShaderVSrc), GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader[enumEFFECT_Model], pErrorStr) != PVR_SUCCESS)
			return false;
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szModelShaderFSrc), GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader[enumEFFECT_Model], pErrorStr) != PVR_SUCCESS)
			return false;

		const char* aszAttribs[] = { "inVertex", "inTexCoord", "inNormal", "inTangent" };
		if (PVRTCreateProgram(&m_StatueShader.uiID, m_uiVertShader[enumEFFECT_Model], m_uiFragShader[enumEFFECT_Model], aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
			return false;

		// --- Get Uniform locations
		m_StatueShader.uiMVP			= glGetUniformLocation(m_StatueShader.uiID, "MVPMatrix");
		m_StatueShader.uiModelView		= glGetUniformLocation(m_StatueShader.uiID, "ModelView");
		m_StatueShader.uiLightPos		= glGetUniformLocation(m_StatueShader.uiID, "LightPosition");

		// --- Set some uniforms
		glUniform3f(glGetUniformLocation(m_StatueShader.uiID, "vDiffuse"), 0.5f, 0.5f, 0.5f);
		glUniform3f(glGetUniformLocation(m_StatueShader.uiID, "vSpecular"), 0.3f, 0.3f, 0.3f);
		glUniform1f(glGetUniformLocation(m_StatueShader.uiID, "fShininess"), 50.0f);
		glUniform1i(glGetUniformLocation(m_StatueShader.uiID, "sNormMap"), 0);
		}

	// ---- Load Bloom 1 shader. (Like Model Shader, but more optimized)
		{
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szBloom1ShaderVSrc), GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader[enumEFFECT_Bloom1], pErrorStr) != PVR_SUCCESS)
			return false;
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szBloom1ShaderFSrc), GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader[enumEFFECT_Bloom1], pErrorStr) != PVR_SUCCESS)
			return false;

		const char* aszAttribs[] = { "inVertex", "inTexCoord", "inNormal", "inTangent" };
		if (PVRTCreateProgram(&m_Bloom1Shader.uiID, m_uiVertShader[enumEFFECT_Bloom1], m_uiFragShader[enumEFFECT_Bloom1], aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
			return false;

		// --- Get Uniform locations
		m_Bloom1Shader.uiMVP			= glGetUniformLocation(m_Bloom1Shader.uiID, "MVPMatrix");
		m_Bloom1Shader.uiModelView		= glGetUniformLocation(m_Bloom1Shader.uiID, "ModelView");
		m_Bloom1Shader.uiLightPos		= glGetUniformLocation(m_Bloom1Shader.uiID, "LightPosition");
		m_Bloom1Shader.uiBloomMulti		= glGetUniformLocation(m_Bloom1Shader.uiID, "fBloomMulti");

		// --- Set some uniforms
		glUniform1i(glGetUniformLocation(m_Bloom1Shader.uiID, "sNormMap"), 0);
		glUniform1i(glGetUniformLocation(m_Bloom1Shader.uiID, "sBloomMap"), 1);
		}

	// ---- Load Church Shader
		{
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szChurchShaderVSrc), GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader[enumEFFECT_Church], pErrorStr, 0, c_szChurchShaderDefs, 1) != PVR_SUCCESS)
			return false;
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szChurchShaderFSrc), GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader[enumEFFECT_Church], pErrorStr, 0, c_szChurchShaderDefs, 1) != PVR_SUCCESS)
			return false;

		const char* aszAttribs[] = { "inVertex", "inTexCoord0", "inTexCoord1" };
		if (PVRTCreateProgram(&m_ChurchShader.uiID, m_uiVertShader[enumEFFECT_Church], m_uiFragShader[enumEFFECT_Church], aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
			return false;

		// --- Get Uniform locations
		m_ChurchShader.uiModelView				= glGetUniformLocation(m_ChurchShader.uiID, "mxModelView");
		m_ChurchShader.uiProjection				= glGetUniformLocation(m_ChurchShader.uiID, "mxProjection");
		m_ChurchShader.uiTexProjection			= glGetUniformLocation(m_ChurchShader.uiID, "mxTexProjection");
		m_ChurchShader.uiAlpha					= glGetUniformLocation(m_ChurchShader.uiID, "fAlpha");

		// --- Set some uniforms
		glUniform1i(glGetUniformLocation(m_ChurchShader.uiID, "sTexture"), 0);
		glUniform1i(glGetUniformLocation(m_ChurchShader.uiID, "sShadow"), 1);
		glUniform1i(glGetUniformLocation(m_ChurchShader.uiID, "sLightmap"), 2);
		}

	// ---- Load Church Reflection shader
		{
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szChurchShaderVSrc), GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader[enumEFFECT_ChurchRefl], pErrorStr) != PVR_SUCCESS)
			return false;
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szChurchShaderFSrc), GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader[enumEFFECT_ChurchRefl], pErrorStr) != PVR_SUCCESS)
			return false;

		const char* aszAttribs[] = { "inVertex", "inTexCoord0", "inTexCoord1" };
		if (PVRTCreateProgram(&m_ChurchReflShader.uiID, m_uiVertShader[enumEFFECT_ChurchRefl], m_uiFragShader[enumEFFECT_ChurchRefl], aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
			return false;

		// --- Get Uniform locations
		m_ChurchReflShader.uiModelView				= glGetUniformLocation(m_ChurchReflShader.uiID, "mxModelView");
		m_ChurchReflShader.uiProjection				= glGetUniformLocation(m_ChurchReflShader.uiID, "mxProjection");

		// --- Set some uniforms
		glUniform1i(glGetUniformLocation(m_ChurchReflShader.uiID, "sTexture"), 0);
		glUniform1i(glGetUniformLocation(m_ChurchReflShader.uiID, "sLightmap"), 2);
		}

	// ---- Load Screen Aligned Texture shader
		{
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szSATextureVSrc), GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader[enumEFFECT_ScreenAlignedTex], pErrorStr) != PVR_SUCCESS)
			return false;
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szSATextureFSrc), GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader[enumEFFECT_ScreenAlignedTex], pErrorStr) != PVR_SUCCESS)
			return false;

		const char* aszAttribs[] = { "inVertex", "inTexCoord" };
		if (PVRTCreateProgram(&m_SATexShader.uiID, m_uiVertShader[enumEFFECT_ScreenAlignedTex], m_uiFragShader[enumEFFECT_ScreenAlignedTex], aszAttribs, 2, pErrorStr) != PVR_SUCCESS)
			return false;

		// --- Set some uniforms
		glUniform1i(glGetUniformLocation(m_SATexShader.uiID, "sTexture"), 0);
		}

	// ---- Load Blur shader
		{
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szBloomBlurVSrc), GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader[enumEFFECT_BloomBlur], pErrorStr) != PVR_SUCCESS)
			return false;
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szBloomBlurFSrc), GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader[enumEFFECT_BloomBlur], pErrorStr) != PVR_SUCCESS)
			return false;

		const char* aszAttribs[] = { "inVertex", "inTexCoord" };
		if (PVRTCreateProgram(&m_BloomBlurShader.uiID, m_uiVertShader[enumEFFECT_BloomBlur], m_uiFragShader[enumEFFECT_BloomBlur], aszAttribs, 2, pErrorStr) != PVR_SUCCESS)
			return false;

		m_BloomBlurShader.uiTexelOffset				= glGetUniformLocation(m_BloomBlurShader.uiID, "vTexelOffset");

		// --- Set some uniforms
		glUniform1i(glGetUniformLocation(m_BloomBlurShader.uiID, "sTexture"), 0);
		}


	// ---- Load a simple model shader
		{
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szSimpleVSrc), GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader[enumEFFECT_SimpleModel], pErrorStr) != PVR_SUCCESS)
			return false;
		if (PVRTShaderLoadFromFile(NULL, StripFolder(c_szSimpleFSrc), GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader[enumEFFECT_SimpleModel], pErrorStr) != PVR_SUCCESS)
			return false;

		const char* aszAttribs[] = { "inVertex" };
		if (PVRTCreateProgram(&m_SimpleShader.uiID, m_uiVertShader[enumEFFECT_SimpleModel], m_uiFragShader[enumEFFECT_SimpleModel], aszAttribs, 1, pErrorStr) != PVR_SUCCESS)
			return false;

		m_SimpleShader.uiMVP				= glGetUniformLocation(m_SimpleShader.uiID, "mxMVP");
		}

	return true;
	}
Esempio n. 15
0
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3PhantomMask::LoadShaders(CPVRTString* pErrorStr)
{
    int i;

    // Load the common frag shader
    if (PVRTShaderLoadFromFile(
                c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
    {
        return false;
    }

    // Load the vertex shader and create the program
    if(PVRTShaderLoadFromFile(
                c_szSHVertShaderBinFile, c_szSHVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiSHVertShader, pErrorStr) != PVR_SUCCESS)
    {
        return false;
    }

    if(PVRTCreateProgram(
                &m_SHShaderProgram.uiId, m_uiSHVertShader, m_uiFragShader, g_aszAttribNames, 3, pErrorStr) != PVR_SUCCESS)
    {
        PVRShellSet(prefExitMessage, pErrorStr->c_str());
        return false;
    }

    // Store the location of uniforms for later use
    for(i = 0; i < eNumSHUniforms; ++i)
        m_SHShaderProgram.auiLoc[i] = glGetUniformLocation(m_SHShaderProgram.uiId, g_aszSHUniformNames[i]);

    // Set the sampler2D variable to the first texture unit
    glUniform1i(glGetUniformLocation(m_SHShaderProgram.uiId, "sTexture"), 0);

    // Setup shader constants

    // Setup some base constants
    bool light0 = false;
    bool light1 = false;
    bool envlight = true;

    // SH Data Sets
    // Not all are used
    float SHCoeffsLight1Red[9] = {0.83409595f, -1.4446964f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, -0.93254757f, 0.00000000f, -1.6152197f};
    float SHCoeffsLight1Green[9] = {0.83409595f, -1.4446964f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, -0.93254757f, 0.00000000f, -1.6152197f};
    float SHCoeffsLight1Blue[9] = {0.83409595f, -1.4446964f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, -0.93254757f, 0.00000000f, -1.6152197f};

    float SHCoeffsLight2Red[9] = {0.83409595f, -1.2120811f, -0.24892779f, -0.74568230f, -1.3989232f, -0.46699628f, -0.84948879f, 0.28729999f, -0.70663643f};
    float SHCoeffsLight2Green[9] = {0.83409595f, -1.2120811f, -0.24892779f, -0.74568230f, -1.3989232f, -0.46699628f, -0.84948879f, 0.28729999f, -0.70663643f};
    float SHCoeffsLight2Blue[9] = {0.83409595f, -1.2120811f, -0.24892779f, -0.74568230f, -1.3989232f, -0.46699628f, -0.84948879f, 0.28729999f, -0.70663643f};

    float SHCoeffsLightEnvRed[9] = {1.2961891f, -0.42659417f, -0.10065936f, -8.4035477e-005f, -0.00021227333f, 0.10019236f, 0.011847760f, 0.00016783635f, -0.10584830f};
    float SHCoeffsLightEnvGreen[9] = {1.2506844f, -0.12775756f, 0.33325988f, -8.7283181e-005f, -0.00015105936f, -0.025249202f, -0.048718069f, 0.00026852929f, -0.28519103f};
    float SHCoeffsLightEnvBlue[9] = {1.6430428f, 0.098693930f, 0.071262904f, 0.00044371662f, 0.00027166531f, 0.056100018f, -0.23762819f, -0.00015725456f, -0.49318397f};

    float SHCoeffsLightSideRed[9] = {	0.83409595f, 0.00000000f, 0.00000000f, -1.4446964f, 0.00000000f, 0.00000000f, -0.93254757f, 0.00000000f, 1.6152197f};
    float SHCoeffsLightSideGreen[9] = {	0.83409595f, 0.00000000f, 0.00000000f, -1.4446964f, 0.00000000f, 0.00000000f, -0.93254757f, 0.00000000f, 1.6152197f};
    float SHCoeffsLightSideBlue[9] = {	0.83409595f, 0.00000000f, 0.00000000f, -1.4446964f, 0.00000000f, 0.00000000f, -0.93254757f, 0.00000000f, 1.6152197f};

    float SHCoeffsLightEnvGraceCrossRed[9] = {10.153550f, -5.0607910f, -4.3494077f, 3.7619650f, -1.4272760f, 3.3470039f, -2.0500889f, -7.1480651f, 2.7244451f};
    float SHCoeffsLightEnvGraceCrossGreen[9] = {5.6218147f, -4.4867749f, -2.3315217f, 0.71724868f, -0.65607071f, 2.8644383f, -1.2423282f, -2.7321301f, -0.70176142f};
    float SHCoeffsLightEnvGraceCrossBlue[9] = {6.9620109f, -7.7706318f, -3.4473803f, -0.12024292f, -1.5760463f, 6.0764866f, -1.9274533f, -1.7631743f, -3.9185245f};

    float	SHCoeffsLightSummedRed[9];
    float	SHCoeffsLightSummedGreen[9];
    float	SHCoeffsLightSummedBlue[9];

    float LIGHT1WEIGHT,LIGHT2WEIGHT,LIGHTENVWEIGHT,LIGHTSIDEWEIGHT,LIGHTGRACECROSSWEIGHT;

    // SH Weights
    LIGHT1WEIGHT=0.0f;
    LIGHT2WEIGHT=0.0f;
    LIGHTENVWEIGHT=0.0f;
    LIGHTSIDEWEIGHT=0.0f;
    LIGHTGRACECROSSWEIGHT=0.0f;

    // Set weights based on scene info

    if(light0 && light1 && envlight)
    {
        LIGHT1WEIGHT=0.3f;
        LIGHT2WEIGHT=0.3f;
        LIGHTENVWEIGHT=1.0f;
    }
    else if(!light0 && !light1 && envlight)
    {
        LIGHTENVWEIGHT=1.0f;
    }

    // Calculate the final SH coefs using the different lights and weights
    for(i = 0; i < 9; ++i)
    {
        SHCoeffsLightSummedRed[i]   = LIGHT1WEIGHT * SHCoeffsLight1Red[i]
                                      + LIGHT2WEIGHT  * SHCoeffsLight2Red[i]
                                      + LIGHTENVWEIGHT* SHCoeffsLightEnvRed[i]
                                      + LIGHTSIDEWEIGHT * SHCoeffsLightSideRed[i]
                                      + LIGHTGRACECROSSWEIGHT * SHCoeffsLightEnvGraceCrossRed[i];

        SHCoeffsLightSummedGreen[i] = LIGHT1WEIGHT * SHCoeffsLight1Green[i]
                                      + LIGHT2WEIGHT * SHCoeffsLight2Green[i]
                                      + LIGHTENVWEIGHT * SHCoeffsLightEnvGreen[i]
                                      + LIGHTSIDEWEIGHT * SHCoeffsLightSideGreen[i]
                                      + LIGHTGRACECROSSWEIGHT * SHCoeffsLightEnvGraceCrossGreen[i];

        SHCoeffsLightSummedBlue[i]  = LIGHT1WEIGHT * SHCoeffsLight1Blue[i]
                                      + LIGHT2WEIGHT * SHCoeffsLight2Blue[i]
                                      + LIGHTENVWEIGHT * SHCoeffsLightEnvBlue[i]
                                      + LIGHTSIDEWEIGHT * SHCoeffsLightSideBlue[i]
                                      + LIGHTGRACECROSSWEIGHT * SHCoeffsLightEnvGraceCrossBlue[i];
    }

    ComputeAndSetSHIrradEnvMapConstants(SHCoeffsLightSummedRed, SHCoeffsLightSummedGreen, SHCoeffsLightSummedBlue);

    // Setup the shaders we're going to use for Vertex lighting

    // Load the vertex shader and create the program
    if(PVRTShaderLoadFromFile(
                c_szDifVertShaderBinFile, c_szDifVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiDifVertShader, pErrorStr) != PVR_SUCCESS)
    {
        return false;
    }

    if(PVRTCreateProgram(
                &m_DiffuseShaderProgram.uiId, m_uiDifVertShader, m_uiFragShader, g_aszAttribNames, 3, pErrorStr) != PVR_SUCCESS)
    {
        PVRShellSet(prefExitMessage, pErrorStr->c_str());
        return false;
    }

    // Store the location of uniforms for later use
    for(i = 0; i < eNumDifUniforms; ++i)
        m_DiffuseShaderProgram.auiLoc[i] = glGetUniformLocation(m_DiffuseShaderProgram.uiId, g_aszDifUniformNames[i]);

    // Setup constants

    // Light direction 1 : TOP
    glUniform3fv(m_DiffuseShaderProgram.auiLoc[eLightDir1], 1, PVRTVec3(0.0f,0.5f,0.0f).ptr());

    // Light direction 2 : BOTTOM
    glUniform3fv(m_DiffuseShaderProgram.auiLoc[eLightDir2], 1, PVRTVec3(0.0f,-0.5f,0.0f).ptr());

    // Light direction 3 : LEFT
    glUniform3fv(m_DiffuseShaderProgram.auiLoc[eLightDir3], 1, PVRTVec3(-0.5f,0.0f,0.0f).ptr());

    // Light direction 4 : RIGHT
    glUniform3fv(m_DiffuseShaderProgram.auiLoc[eLightDir4], 1, PVRTVec3(0.5f,0.0f,0.0f).ptr());

    // Ambient Light
    glUniform4fv(m_DiffuseShaderProgram.auiLoc[eAmbient], 1, PVRTVec4(0.05f,0.05f,0.05f,0.05f).ptr());

    // Set the sampler2D variable to the first texture unit
    glUniform1i(glGetUniformLocation(m_DiffuseShaderProgram.uiId, "sTexture"), 0);
    return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occurred
 @Description	Loads and compiles the shaders and links the shader programs
                required for this training course
 ******************************************************************************/
bool OGLES3TextureStreaming::LoadShaders(CPVRTString* pErrorStr)
{
	/*
	 Load and compile the shaders from files.
	 */
	for(int idx = 0; idx < eNumEffects; ++idx)
	{
		if(PVRTShaderLoadFromFile(NULL,                         // Binary shader source file
								  c_pszVertexShaderSrc[idx],    // Text source file
								  GL_VERTEX_SHADER,             // Shader type
								  0,                            // Binary shader GL format
								  &m_uiVertexShaders[idx],      // Output GL handle
								  pErrorStr,                    // Output error string
								  NULL,                         // Context (not required for OGLES3)
								  c_pszEffectDefines[idx],      // Define array
								  c_uiNumDefines[idx]           // Number of defines in the array
								  ) != PVR_SUCCESS)
		{
			return false;
		}

		if(PVRTShaderLoadFromFile(NULL,                         // Binary shader source file
								  c_pszFragmentShaderSrc[idx],  // Text source file
								  GL_FRAGMENT_SHADER,           // Shader type
								  0,                            // Binary shader GL format
								  &m_uiFragmentShaders[idx],    // Output GL handle
								  pErrorStr,                    // Output error string
								  NULL,                         // Context (not required for OGLES3)
								  c_pszEffectDefines[idx],      // Define array
								  c_uiNumDefines[idx]           // Number of defines in the array
								  ) != PVR_SUCCESS)
		{
			return false;
		}
	}

	/*
	 Set up and link the shader program
	 */
	{
		// Lit shader
		const char* aszAttribs[] = { "inVertex", "inTexCoord", "inNormal" };
		if(PVRTCreateProgram(&m_LitProgram.uiId, m_uiVertexShaders[eLit], m_uiFragmentShaders[eLit],
							 aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
		{
			return false;
		}

		// Store the location of uniforms for later use
		m_LitProgram.uiLightPosition = glGetUniformLocation(m_LitProgram.uiId, "vLightPosition");
		m_LitProgram.uiMVP           = glGetUniformLocation(m_LitProgram.uiId, "MVPMatrix");
		m_LitProgram.uiSampler       = glGetUniformLocation(m_LitProgram.uiId, "SamplerTexture");

		// Set the sampler2D variable to the first texture unit
		glUniform1i(m_LitProgram.uiSampler, 0);
	}
	{
		// Ambient shader
		const char* aszAttribs[] = { "inVertex", "inTexCoord", };
		if(PVRTCreateProgram(&m_AmbientShaderProgram.uiId, m_uiVertexShaders[eAmbient], m_uiFragmentShaders[eAmbient],
							 aszAttribs, 2, pErrorStr) != PVR_SUCCESS)
		{
			return false;
		}

		// Store the location of uniforms for later use
		m_AmbientShaderProgram.uiMVP           = glGetUniformLocation(m_AmbientShaderProgram.uiId, "MVPMatrix");
		m_AmbientShaderProgram.uiSampler       = glGetUniformLocation(m_AmbientShaderProgram.uiId, "SamplerTexture");

		// Set the sampler2D variable to the first texture unit
		glUniform1i(m_AmbientShaderProgram.uiSampler, 0);
	}
	{
		// TV colour shader
		const char* aszAttribs[] = { "inVertex", "inTexCoord" };
		if(PVRTCreateProgram(&m_TVShaderProgram.uiId, m_uiVertexShaders[eTVColour], m_uiFragmentShaders[eTVColour],
							 aszAttribs, 2, pErrorStr) != PVR_SUCCESS)
		{
			return false;
		}

		// Store the location of uniforms for later use
		m_TVShaderProgram.uiMVP       = glGetUniformLocation(m_TVShaderProgram.uiId, "MVPMatrix");
#if defined(__ANDROID__)
		m_TVShaderProgram.uiVideoTexProjM = glGetUniformLocation(m_TVShaderProgram.uiId, "TexSamplerPMatrix");
		m_TVShaderProgram.uiSampler       = glGetUniformLocation(m_TVShaderProgram.uiId, "Sampler");

		// Set the sampler2D variables
		glUniform1i(m_TVShaderProgram.uiSampler,  0);
#elif defined(__APPLE__)
		m_TVShaderProgram.uiSamplerUV = glGetUniformLocation(m_TVShaderProgram.uiId, "SamplerUV");
		m_TVShaderProgram.uiSamplerY  = glGetUniformLocation(m_TVShaderProgram.uiId, "SamplerY");

		// Set the sampler2D variables
		glUniform1i(m_TVShaderProgram.uiSamplerY,  0);
		glUniform1i(m_TVShaderProgram.uiSamplerUV, 1);
#endif
	}
	{
		// TV greyscale shader
		const char* aszAttribs[] = { "inVertex", "inTexCoord" };
		if(PVRTCreateProgram(&m_TVGreyscaleShaderProgram.uiId, m_uiVertexShaders[eTVGreyscale], m_uiFragmentShaders[eTVGreyscale],
							 aszAttribs, 2, pErrorStr) != PVR_SUCCESS)
		{
			return false;
		}

		// Store the location of uniforms for later use
		m_TVGreyscaleShaderProgram.uiMVP       = glGetUniformLocation(m_TVGreyscaleShaderProgram.uiId, "MVPMatrix");
#if defined(__ANDROID__)
		m_TVGreyscaleShaderProgram.uiVideoTexProjM = glGetUniformLocation(m_TVGreyscaleShaderProgram.uiId, "TexSamplerPMatrix");
		m_TVGreyscaleShaderProgram.uiSampler = glGetUniformLocation(m_TVGreyscaleShaderProgram.uiId, "Sampler");

		// Set the sampler2D variables
		glUniform1i(m_TVGreyscaleShaderProgram.uiSampler,  0);
#elif defined(__APPLE__)
		m_TVGreyscaleShaderProgram.uiSamplerUV = glGetUniformLocation(m_TVGreyscaleShaderProgram.uiId, "SamplerUV");
		m_TVGreyscaleShaderProgram.uiSamplerY  = glGetUniformLocation(m_TVGreyscaleShaderProgram.uiId, "SamplerY");

		// Set the sampler2D variables
		glUniform1i(m_TVGreyscaleShaderProgram.uiSamplerY,  0);
		glUniform1i(m_TVGreyscaleShaderProgram.uiSamplerUV, 1);
#endif
	}
	{
		// TV noise shader
		const char* aszAttribs[] = { "inVertex", "inTexCoord" };
		if(PVRTCreateProgram(&m_TVNoiseShaderProgram.uiId, m_uiVertexShaders[eTVNoise], m_uiFragmentShaders[eTVNoise],
							 aszAttribs, 2, pErrorStr) != PVR_SUCCESS)
		{
			return false;
		}

		// Store the location of uniforms for later use
		m_TVNoiseShaderProgram.uiMVP          = glGetUniformLocation(m_TVNoiseShaderProgram.uiId, "MVPMatrix");
		m_TVNoiseShaderProgram.uiScreenBand   = glGetUniformLocation(m_TVNoiseShaderProgram.uiId, "vScreenBand");
		m_TVNoiseShaderProgram.uiNoiseLoc     = glGetUniformLocation(m_TVNoiseShaderProgram.uiId, "vNoiseLoc");
		m_TVNoiseShaderProgram.uiSamplerNoise = glGetUniformLocation(m_TVNoiseShaderProgram.uiId, "SamplerNoise");

#if defined(__ANDROID__)
		m_TVNoiseShaderProgram.uiSampler       = glGetUniformLocation(m_TVNoiseShaderProgram.uiId, "Sampler");
		m_TVNoiseShaderProgram.uiVideoTexProjM = glGetUniformLocation(m_TVNoiseShaderProgram.uiId, "TexSamplerPMatrix");

		// Set the sampler2D variables
		glUniform1i(m_TVNoiseShaderProgram.uiSampler, 0);
#elif defined(__APPLE__)
		m_TVNoiseShaderProgram.uiSamplerUV    = glGetUniformLocation(m_TVNoiseShaderProgram.uiId, "SamplerUV");
		m_TVNoiseShaderProgram.uiSamplerY     = glGetUniformLocation(m_TVNoiseShaderProgram.uiId, "SamplerY");

		// Set the sampler2D variables
		glUniform1i(m_TVNoiseShaderProgram.uiSamplerY,  0);
		glUniform1i(m_TVNoiseShaderProgram.uiSamplerUV, 1);
#endif

		// Set the noise texture unit
		glUniform1i(m_TVNoiseShaderProgram.uiSamplerNoise, 2);
	}

	return true;
}
Esempio n. 17
0
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES2ShadowMapping::LoadShaders(CPVRTString* pErrorStr)
{
	const char* aszAttribs[] = { "inVertex", "inNormal", "inTexCoord" };

	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/

	if(PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiSimpleVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiSimpleFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTCreateProgram(&m_SimpleShaderProgram.uiId, m_uiSimpleVertShader, m_uiSimpleFragShader, 0, 0, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}
	m_SimpleShaderProgram.uiModelViewMatrixLoc	= glGetUniformLocation(m_SimpleShaderProgram.uiId, "ModelViewMatrix");
	m_SimpleShaderProgram.uiProjectionMatrixLoc	= glGetUniformLocation(m_SimpleShaderProgram.uiId, "ProjectionMatrix");
	

	if(PVRTCreateProgram(&m_SimpleShaderProgram.uiId, m_uiSimpleVertShader, m_uiSimpleFragShader, aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	if(PVRTShaderLoadFromFile(
			c_szShadowMapppingVertBinFile, c_szShadowMapppingVertSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiShadowVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTShaderLoadFromFile(
			c_szShadowMapppingFragBinFile, c_szShadowMapppingFragSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiShadowFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTCreateProgram(&m_ShadowShaderProgram.uiId, m_uiShadowVertShader, m_uiShadowFragShader, 0, 0, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}


	m_ShadowShaderProgram.uiTexProjMatrixLoc	= glGetUniformLocation(m_ShadowShaderProgram.uiId, "TexProjectionMatrix");
	m_ShadowShaderProgram.uiModelViewMatrixLoc	= glGetUniformLocation(m_ShadowShaderProgram.uiId, "ModelViewMatrix");
	m_ShadowShaderProgram.uiProjectionMatrixLoc	= glGetUniformLocation(m_ShadowShaderProgram.uiId, "ProjectionMatrix");
	m_ShadowShaderProgram.uiLightDirLoc	= glGetUniformLocation(m_ShadowShaderProgram.uiId, "LightDirection");

 	if(PVRTCreateProgram(&m_ShadowShaderProgram.uiId, m_uiShadowVertShader, m_uiShadowFragShader, aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	glUniform1i(glGetUniformLocation(m_ShadowShaderProgram.uiId, "sShadow"), 0);
	glUniform1i(glGetUniformLocation(m_ShadowShaderProgram.uiId, "sTexture"), 1);
	return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES2ChameleonMan::LoadShaders(CPVRTString* pErrorStr)
{
	int i;

	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/


	// Create the skinned program
	if(PVRTShaderLoadFromFile(
			c_szSkinnedVertShaderBinFile, c_szSkinnedVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiSkinnedVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTShaderLoadFromFile(
			c_szSkinnedFragShaderBinFile, c_szSkinnedFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiSkinnedFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTCreateProgram(&m_SkinnedShaderProgram.uiId, m_uiSkinnedVertShader, m_uiSkinnedFragShader, g_aszAttribNames, eNumAttribs, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Store the location of uniforms for later use
	for(i = 0; i < eNumSkinnedUniforms; ++i)
	{
		m_SkinnedShaderProgram.auiLoc[i] = glGetUniformLocation(m_SkinnedShaderProgram.uiId, g_aszSkinnedUniformNames[i]);
	}

	glUniform1i(m_SkinnedShaderProgram.auiLoc[ebUseDot3], m_bEnableDOT3);

	// Set the sampler2D uniforms to corresponding texture units
	glUniform1i(glGetUniformLocation(m_SkinnedShaderProgram.uiId, "sTexture"), 0);
	glUniform1i(glGetUniformLocation(m_SkinnedShaderProgram.uiId, "sNormalMap"), 1);

	// Create the non-skinned program
	if(PVRTShaderLoadFromFile(
			c_szDefaultVertShaderBinFile, c_szDefaultVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiDefaultVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTShaderLoadFromFile(
			c_szDefaultFragShaderBinFile, c_szDefaultFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiDefaultFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTCreateProgram(&m_DefaultShaderProgram.uiId, m_uiDefaultVertShader, m_uiDefaultFragShader, g_aszDefaultAttribNames, eNumDefaultAttribs, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Store the location of uniforms for later use
	for(i = 0; i < eNumDefaultUniforms; ++i)
	{
		m_DefaultShaderProgram.auiLoc[i] = glGetUniformLocation(m_DefaultShaderProgram.uiId, g_aszDefaultUniformNames[i]);
	}

	// Set the sampler2D uniforms to corresponding texture units
	glUniform1i(glGetUniformLocation(m_DefaultShaderProgram.uiId, "sTexture"), 0);

	return true;
}
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES2AnisotropicLighting::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if (PVRTShaderLoadFromFile(c_szFastVsBinFile,
			                   c_szFastVsSrcFile,
							   GL_VERTEX_SHADER,
							   GL_SGX_BINARY_IMG,
							   &m_uiFastVertShader,
							   pErrorStr) != PVR_SUCCESS)
	{
		*pErrorStr = CPVRTString("From file '") + c_szFastVsBinFile +
					 "' or '" + c_szFastVsSrcFile + "':\n" + *pErrorStr;
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	if (PVRTShaderLoadFromFile(c_szFastFsBinFile,
							   c_szFastFsSrcFile,
							   GL_FRAGMENT_SHADER,
							   GL_SGX_BINARY_IMG,
							   &m_uiFastFragShader,
							   pErrorStr) != PVR_SUCCESS)
	{
		*pErrorStr = CPVRTString("From file '") + c_szFastVsBinFile +
					 "' or '" + c_szFastVsSrcFile + "':\n" + *pErrorStr;
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	if (PVRTShaderLoadFromFile(c_szSlowVsBinFile,
							   c_szSlowVsSrcFile,
							   GL_VERTEX_SHADER,
							   GL_SGX_BINARY_IMG,
							   &m_uiSlowVertShader,
							   pErrorStr) != PVR_SUCCESS)
	{
		*pErrorStr = CPVRTString("From file '") + c_szFastVsBinFile +
					 "' or '" + c_szFastVsSrcFile + "':\n" + *pErrorStr;
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	if (PVRTShaderLoadFromFile(c_szSlowFsBinFile,
							   c_szSlowFsSrcFile,
							   GL_FRAGMENT_SHADER,
							   GL_SGX_BINARY_IMG,
							   &m_uiSlowFragShader,
							   pErrorStr) != PVR_SUCCESS)
	{
		*pErrorStr = CPVRTString("From file '") + c_szFastVsBinFile +
					 "' or '" + c_szFastVsSrcFile + "':\n" + *pErrorStr;
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	/*
		Set up and link the shader programs
	*/
	const char* aszAttribs[] = { "inVertex", "inNormal"	};
	if	(
		(PVRTCreateProgram(&m_FastShader.uiId, m_uiFastVertShader, m_uiFastFragShader, aszAttribs, 2, pErrorStr) != PVR_SUCCESS) ||
		(PVRTCreateProgram(&m_SlowShader.uiId, m_uiSlowVertShader, m_uiSlowFragShader, aszAttribs, 2, pErrorStr) != PVR_SUCCESS)
		)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	/*
		Store the location of uniforms for later use
	*/
	m_FastShader.uiMVPMatrixLoc		= glGetUniformLocation(m_FastShader.uiId, "MVPMatrix");
	m_FastShader.uiMsLightDirLoc	= glGetUniformLocation(m_FastShader.uiId, "msLightDir");
	m_FastShader.uiMsEyePosLoc		= glGetUniformLocation(m_FastShader.uiId, "msEyePos");

	m_SlowShader.uiMVPMatrixLoc		= glGetUniformLocation(m_SlowShader.uiId, "MVPMatrix");
	m_SlowShader.uiMsLightDirLoc	= glGetUniformLocation(m_SlowShader.uiId, "msLightDir");
	m_SlowShader.uiMsEyeDirLoc		= glGetUniformLocation(m_SlowShader.uiId, "msEyeDir");

	return true;
}
Esempio n. 20
0
/*!****************************************************************************
 @Function		LoadShaders
 @Output		pErrorStr		A string describing the error on failure
 @Return		bool			true if no error occured
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES2Bloom::LoadShaders(CPVRTString* pErrorStr)
{
	/*
		Load and compile the shaders from files.
		Binary shaders are tried first, source shaders
		are used as fallback.
	*/
	if(PVRTShaderLoadFromFile(
			c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
			c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	// Set up and link the shader program
	const char* aszAttribs[] = { "inVertex", "inNormal", "inTexCoord" };

	if(PVRTCreateProgram(
			&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Set the sampler2D variable to the first texture unit
	glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "sTexture"), 0);

	// Store the location of uniforms for later use
	m_ShaderProgram.uiMVPMatrixLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "MVPMatrix");
	m_ShaderProgram.uiLightDirLoc	= glGetUniformLocation(m_ShaderProgram.uiId, "LightDirection");


	/*
	    Load shaders required for bloom post processing effect
	*/

	/*
	    Pre-Bloom shader program
    */

	if(PVRTShaderLoadFromFile(
		c_szPreBloomVertShaderBinFile, c_szPreBloomVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiPreBloomVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTShaderLoadFromFile(
		c_szPreBloomFragShaderBinFile, c_szPreBloomFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiPreBloomFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	// Set up and link the shader program
	const char* aszPreBloomAttribs[] = { "inVertex", "inNormal", "inTexCoord" };

	if(PVRTCreateProgram(
		&m_PreBloomShaderProgram.uiId, m_uiPreBloomVertShader, m_uiPreBloomFragShader, aszPreBloomAttribs, 3, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Set the sampler2D variables to the first and second texture units
	glUniform1i(glGetUniformLocation(m_PreBloomShaderProgram.uiId, "sBloomMapping"), 0);

	// Store the location of uniforms for later use
	m_PreBloomShaderProgram.uiMVPMatrixLoc = glGetUniformLocation(m_PreBloomShaderProgram.uiId, "MVPMatrix");
	m_PreBloomShaderProgram.uiLightDirLoc  = glGetUniformLocation(m_PreBloomShaderProgram.uiId, "LightDirection");
	m_PreBloomShaderProgram.uiBloomIntensity  = glGetUniformLocation(m_PreBloomShaderProgram.uiId, "fBloomIntensity");

	/*
	    Post-Bloom shader program
    */

	if(PVRTShaderLoadFromFile(
		c_szPostBloomVertShaderBinFile, c_szPostBloomVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiPostBloomVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if(PVRTShaderLoadFromFile(
		c_szPostBloomFragShaderBinFile, c_szPostBloomFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiPostBloomFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	// Set up and link the shader program
	const char* aszPostBloomAttribs[] = { "inVertex", "inTexCoord" };

	if(PVRTCreateProgram(
		&m_PostBloomShaderProgram.uiId, m_uiPostBloomVertShader, m_uiPostBloomFragShader, aszPostBloomAttribs, 2, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Set the sampler2D variables to the first and second texture units
	glUniform1i(glGetUniformLocation(m_PostBloomShaderProgram.uiId, "sTexture"), 0);

	/*
	    Blur shader program
    */

	if (PVRTShaderLoadFromFile(
		c_szBlurFragBinFile, c_szBlurFragSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiBlurFragShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	if (PVRTShaderLoadFromFile(
		c_szBlurVertBinFile, c_szBlurVertSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiBlurVertShader, pErrorStr) != PVR_SUCCESS)
	{
		return false;
	}

	// Set up and link the shader program
	const char* aszBlurAttribs[] = { "inVertex", "inTexCoord" };

	if(PVRTCreateProgram(
		&m_BlurShaderProgram.uiId, m_uiBlurVertShader, m_uiBlurFragShader, aszBlurAttribs, 2, pErrorStr) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, pErrorStr->c_str());
		return false;
	}

	// Set the sampler2D variables to the first and second texture units
	glUniform1i(glGetUniformLocation(m_BlurShaderProgram.uiId, "sTexture"), 0);

	m_BlurShaderProgram.uiTexelOffsetX = glGetUniformLocation(m_BlurShaderProgram.uiId, "TexelOffsetX");
	m_BlurShaderProgram.uiTexelOffsetY = glGetUniformLocation(m_BlurShaderProgram.uiId, "TexelOffsetY");

	return true;
}