Exemple #1
0
/*!****************************************************************************
 @Function		LoadPFX
 @Return		bool			true if no error occurred
 @Description	Loads and compiles the shaders and links the shader programs
				required for this training course
******************************************************************************/
bool OGLES3ShadowMapping::LoadPFX(CPVRTString* pErrorStr)
{
	// Parse the whole PFX and store all data.
	m_pPFXEffectParser = new CPVRTPFXParser();
	if(m_pPFXEffectParser->ParseFromFile(c_szPFXFile, pErrorStr) != PVR_SUCCESS)
	{
		*pErrorStr = "Parse failed:\n" + *pErrorStr;
		return false;
	}

	// Setup all effects in the PFX file so we initialize the shaders and
	// store uniforms and attributes locations.
	unsigned int uiNumEffects = m_pPFXEffectParser->GetNumberEffects();
	m_ppPFXEffects = new CPVRTPFXEffect*[uiNumEffects];
	for (unsigned int i=0; i < uiNumEffects; i++)
		m_ppPFXEffects[i] = 0;

	// Load one by one the effects. This will also compile the shaders.
	for (unsigned int i=0; i < uiNumEffects; i++)
	{
		m_ppPFXEffects[i] = new CPVRTPFXEffect(m_sContext);
				
		if(m_ppPFXEffects[i]->RegisterUniformSemantic(c_CustomSemantics, c_uiNumCustomSemantics, pErrorStr))
		{
			*pErrorStr = "Failed to set custom semantics:\n" + *pErrorStr;
			return false;
		}

		unsigned int nUnknownUniformCount = 0;
		if(m_ppPFXEffects[i]->Load(*m_pPFXEffectParser, m_pPFXEffectParser->GetEffect(i).Name.c_str(), NULL, NULL, nUnknownUniformCount, pErrorStr)  != PVR_SUCCESS)
		{
			*pErrorStr = "Failed to load effect " + m_pPFXEffectParser->GetEffect(i).Name.String() + CPVRTString(":\n") + *pErrorStr;
			return false;
		}

		// .. upps, some uniforms are not in our table. Better to quit because something is not quite right.
		if(nUnknownUniformCount)
		{
			*pErrorStr = "Unknown uniform semantic.\n";
			return false;
		}		
	}
	
	return true;
}
Exemple #2
0
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occurred
 @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 dependent on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES3Skybox2::InitView()
{
	// Sets the clear colour
	glClearColor(0.6f, 0.8f, 1.0f, 1.0f);

	// Enables depth test using the z-buffer
	glEnable(GL_DEPTH_TEST);

	CPVRTString ErrorStr;

	/*
		Load textures
	*/
	if(!LoadTextures(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	/*********************/
	/* Create the Skybox */
	/*********************/
	float* skyboxVertices;
	float* skyboxUVs;

	PVRTCreateSkybox( 500.0f, true, 512, &skyboxVertices, &skyboxUVs );

	glGenBuffers(1, &m_iSkyVboID);
	glBindBuffer(GL_ARRAY_BUFFER, m_iSkyVboID);
	glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 24, &skyboxVertices[0], GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	PVRTDestroySkybox(skyboxVertices, skyboxUVs);

	/**********************/
	/* Create the Effects */
	/**********************/

	{
		// Parse the file
		m_pEffectParser = new CPVRTPFXParser();

		if(m_pEffectParser->ParseFromFile(g_pszEffectFileName, &ErrorStr) != PVR_SUCCESS)
		{
			delete m_pEffectParser;
			PVRShellSet(prefExitMessage, ErrorStr.c_str());
			return false;
		}

		m_ppEffects = new CPVRTPFXEffect*[g_ui32NoOfEffects];
		memset(m_ppEffects, 0, sizeof(CPVRTPFXEffect*) * g_ui32NoOfEffects);

		// Skybox shader
		if(!LoadEffect(&m_ppEffects[0], "skybox_effect", g_pszEffectFileName))
		{
			delete m_pEffectParser;
			delete[] m_ppEffects;
			return false;
		}

		// The Balloon Shaders
		if(!LoadEffect(&m_ppEffects[1], "balloon_effect1", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[2], "balloon_effect2", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[3], "balloon_effect3", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[4], "balloon_effect4", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[5], "balloon_effect5", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[6], "balloon_effect6", g_pszEffectFileName) ||
			!LoadEffect(&m_ppEffects[7], "balloon_effect7", g_pszEffectFileName))
		{
			delete m_pEffectParser;
			delete[] m_ppEffects;
			return false;
		}
	}

	// Create Geometry Buffer Objects.
	m_aiVboID = new GLuint[m_Scene.nNumMeshNode];
	glGenBuffers(m_Scene.nNumMeshNode, m_aiVboID);

	for(unsigned int i = 0; i < m_Scene.nNumMeshNode ; ++i)
	{
		SPODNode* pNode = &m_Scene.pNode[i];

		// Gets pMesh referenced by the pNode
		SPODMesh* pMesh = &m_Scene.pMesh[pNode->nIdx];

		// Genereta a vertex buffer and set the interleaved vertex datas.
		glBindBuffer(GL_ARRAY_BUFFER, m_aiVboID[i]);
		glBufferData(GL_ARRAY_BUFFER, pMesh->sVertex.nStride*pMesh->nNumVertex, pMesh->pInterleaved, GL_STATIC_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, 0);

	}

	/**********************
	** Projection Matrix **
	**********************/
	/* Projection */
	bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);
	m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PI / 6, (float) PVRShellGet(prefWidth) / (float) PVRShellGet(prefHeight), 4.0f, 1000.0f, PVRTMat4::OGL, bRotate);

	// Calculate the model view matrix turning around the balloon
	ComputeViewMatrix();

	/* Init Values */
	bPause = false;
	fDemoFrame = 0.0;
	fBurnAnim = 0.0f;

	m_i32Effect = 1;

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

	// Initialise variables used for the animation
	m_iTimePrev = PVRShellGetTime();

	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 OGLESIntroducingPFX::InitView()
{
	/*
		Initialize Print3D
	*/
	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);

	// Enables depth test using the z-buffer
	glEnable(GL_DEPTH_TEST);

	/*
		Loads the light direction from the scene.
	*/
	// We check the scene contains at least one
	if (m_Scene.nNumLight == 0)
	{
		PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a light\n");
		return false;
	}

	/*
		Load the effect file
	*/
	{
		unsigned int	nUnknownUniformCount;
		CPVRTString	error;

		// Parse the file
		m_pEffectParser = new CPVRTPFXParser;
		if(m_pEffectParser->ParseFromFile(c_szPfxFile, &error) != PVR_SUCCESS)
		{
			PVRShellSet(prefExitMessage, error.c_str());
			return false;
		}

		// Load an effect from the file
		m_pEffect = new CPVRTPFXEffect();
		if(m_pEffect->Load(*m_pEffectParser, "Effect", c_szPfxFile, &error) != PVR_SUCCESS)
		{
			PVRShellSet(prefExitMessage, error.c_str());
			return false;
		}

		// Generate uniform array
		if(m_pEffect->BuildUniformTable(
			&m_psUniforms, &m_nUniformCnt, &nUnknownUniformCount,
			c_psUniformSemantics, sizeof(c_psUniformSemantics) / sizeof(*c_psUniformSemantics),
			&error) != PVR_SUCCESS)
		{
			PVRShellOutputDebug(error.c_str());
			return false;
		}
		if(nUnknownUniformCount)
		{
			PVRShellOutputDebug(error.c_str());
			PVRShellOutputDebug("Unknown uniform semantic count: %d\n", nUnknownUniformCount);
		}
	}

	/*
		Loads the textures.
		For a more detailed explanation, see Texturing and IntroducingPVRTools
	*/
	{
		const SPVRTPFXTexture	*psTex;
		unsigned int			nCnt, i;
		GLuint					ui;

		psTex = m_pEffect->GetTextureArray(nCnt);

		for(i = 0; i < nCnt; ++i)
		{
			if(strcmp(psTex[i].p, "Reflection.pvr") == 0)
			{
				if(PVRTTextureLoadFromPVR(c_szReflectTexFile, &ui) != PVR_SUCCESS)
				{
					PVRShellSet(prefExitMessage, "ERROR: Cannot load the texture\n");
					return false;
				}
			
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

				m_pEffect->SetTexture(i, ui);
			}
			else if (strcmp(psTex[i].p, "Basetex.pvr") == 0)
			{
				if(PVRTTextureLoadFromPVR(c_szBaseTexFile, &ui) != PVR_SUCCESS)
				{
					PVRShellSet(prefExitMessage, "ERROR: Cannot load the texture\n");
					return false;
				}
			
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
				
				m_pEffect->SetTexture(i, ui);
			}
			else
			{
				PVRShellOutputDebug("Warning: effect file requested unrecognised texture: \"%s\"\n", psTex[i].p);
				m_pEffect->SetTexture(i, 0);
			}
		}
	}

	// Create buffer objects.
	m_aiVboID = new GLuint[m_Scene.nNumMeshNode];
	glGenBuffers(m_Scene.nNumMeshNode, m_aiVboID);
	for(int i = 0; i < (int)m_Scene.nNumMeshNode ; i++)
	{
		SPODNode* pNode = &m_Scene.pNode[i];

		// Gets pMesh referenced by the pNode
		SPODMesh* pMesh = &m_Scene.pMesh[pNode->nIdx];

		// Generate a vertex buffer and set the interleaved vertex data.
		glBindBuffer(GL_ARRAY_BUFFER, m_aiVboID[i]);
		glBufferData(GL_ARRAY_BUFFER, pMesh->sVertex.nStride*pMesh->nNumVertex, pMesh->pInterleaved, GL_STATIC_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}

	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 OGLES3IntroducingPFX::InitView()
{
	/*
		Initialize Print3D
	*/
	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);

	// Enables depth test using the z-buffer
	glEnable(GL_DEPTH_TEST);

	/*
		Loads the light direction from the scene.
	*/
	// We check the scene contains at least one
	if (m_Scene.nNumLight == 0)
	{
		PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a light\n");
		return false;
	}

	// Load the VBOs
	LoadVBOs();

	/*
		Load the effect file
	*/
	CPVRTString	error;
	unsigned int uiUnknownUniforms;

	// Parse the file
	m_pEffectParser = new CPVRTPFXParser;
	if(m_pEffectParser->ParseFromFile(c_szPfxFile, &error) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, error.c_str());
		return false;
	}

	// --- Load an effect from the file
	m_pEffect = new CPVRTPFXEffect();

	// Register a custom uniform
	if(m_pEffect->RegisterUniformSemantic(c_sCustomSemantics, sizeof(c_sCustomSemantics) / sizeof(c_sCustomSemantics[0]), &error) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, error.c_str());
		return false;
	}

	/* 
		Load the effect.
		We pass 'this' as an argument as we wish to receive callbacks as the PFX is loaded.
		This is optional and supplying NULL implies that the developer will take care
		of all texture loading and binding to to the Effect instead.
	*/
	if(m_pEffect->Load(*m_pEffectParser, "Effect", c_szPfxFile, this, uiUnknownUniforms, &error) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, error.c_str());
		return false;
	}

	/*
		'Unknown uniforms' are uniform semantics that have been detected in the PFX file
		but are unknown to PVRTools. If you wish to utilise this semantic, register
		the semantic by calling RegisterUniformSemantic(). This is performed above.
	*/
	if(uiUnknownUniforms)
	{
		PVRShellOutputDebug(error.c_str());
		PVRShellOutputDebug("Unknown uniform semantic count: %u\n", uiUnknownUniforms);
	}

	// Enable culling
	glEnable(GL_CULL_FACE);
	return true;
}
Exemple #5
0
/*!****************************************************************************
 @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 OGLES2MaximumIntensityBlend::InitView()
{
	/*
	 Check that EXT_blend_minmax is supported
	 */
	if(!CPVRTgles2Ext::IsGLExtensionSupported("GL_EXT_blend_minmax"))
	{
		PVRShellSet(prefExitMessage, "ERROR: GL_EXT_blend_minmax extension is required to run this example.");
		return false;
	}
	
	/*
	 Initialize Print3D
	 */
	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.0f, 0.0f, 0.0f, 1.0f);
	
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CW);
	
	// Load the VBOs
	LoadVBOs();
	
	/*
	 Load the effect file
	 */
	CPVRTString	error;
	unsigned int uiUnknownUniforms;
	
	// Parse the file
	m_pEffectParser = new CPVRTPFXParser;
	if(m_pEffectParser->ParseFromFile(c_szPfxFile, &error) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, error.c_str());
		return false;
	}
	
	// --- Load an effect from the file
	m_pEffect = new CPVRTPFXEffect();
	m_pEffect->RegisterUniformSemantic(c_sCustomSemantics, sizeof(c_sCustomSemantics) / sizeof(c_sCustomSemantics[0]), &error);
	
	/*
	 Load the effect.
	 */
	if(m_pEffect->Load(*m_pEffectParser, "Effect", c_szPfxFile, NULL, uiUnknownUniforms, &error) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, error.c_str());
		return false;
	}
	
	// --- Load the textured effect
	m_pEffectTextured = new CPVRTPFXEffect();
	m_pEffectTextured->RegisterUniformSemantic(c_sCustomSemantics, sizeof(c_sCustomSemantics) / sizeof(c_sCustomSemantics[0]), &error);
	
	/*
	 Load the effect.
	 */
	if(m_pEffectTextured->Load(*m_pEffectParser, "TexturedEffect", c_szPfxFile, this, uiUnknownUniforms, &error) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, error.c_str());
		return false;
	}
	
	return true;
}
/*!****************************************************************************
 @Function		LoadPFX
 @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 OGLES3MagicLantern::LoadPFX(void)
{
	CPVRTString error = "";
	
	// Parse the whole PFX and store all data.
	m_ppEffectParser = new CPVRTPFXParser();
	if(m_ppEffectParser->ParseFromFile(c_szPFXSrcFile, &error) != PVR_SUCCESS)
	{
		error = "Parse failed:\n\n" + error;
		PVRShellSet(prefExitMessage, error.c_str());
		return false;
	}

	// Setup all effects in the PFX file so we initialise the shaders and
	// store uniforms and attributes locations.
	unsigned int uNumEffects = m_ppEffectParser->GetNumberEffects();
	for (unsigned int i=0; i<uNumEffects; i++)
	{
		// Load one by one the effects. This will also compile the shaders.
		m_pFX[i] = new CPVRTPFXEffect();
		unsigned int nUnknownUniformCount = 0;
		if(m_pFX[i]->Load(*m_ppEffectParser, m_ppEffectParser->GetEffect(i).Name.c_str(), NULL, this, nUnknownUniformCount, &error)  != PVR_SUCCESS)
		{
			error = "Effect load failed:\n\n" + error;
			PVRShellSet(prefExitMessage, error.c_str());
			return false;
		}

		// .. upps, some uniforms are not in our table. Better to quit because something is not quite right.
		if(nUnknownUniformCount)
		{
			PVRShellOutputDebug(error.c_str());
			PVRShellOutputDebug("Unknown uniform semantic count: %d\n", nUnknownUniformCount);
			return false;
		}
	}

	// Allocate an array of integers to hold an effect ID per material.
	m_puiMaterialEffectID = new GLuint[m_Scene.nNumMaterial];
	
	// Assign an effect to each material based on its name.
	// If there is a material with an effect name which is not in the PFX 
	// file, the application will quit and report an error.
	for(int i = 0; i < (int) m_Scene.nNumMaterial; ++i)
	{
		SPODMaterial* pMaterial = &m_Scene.pMaterial[i];

		m_puiMaterialEffectID[i] = 0xbad;

		for (unsigned int j=0; j<uNumEffects; j++)
		{
			// Compare the effect string in the material to each effect in our file so we can
			// match effects to meshes.
			// All effects are contained in the same PFX file so we do not have to worry about
			// effects spread across several files.
			// Note: Each material can only contain a single effect but the same effect
			// might be applied to several materials.
			if (m_ppEffectParser->GetEffect(j).Name == pMaterial->pszEffectName)
			{
				m_puiMaterialEffectID[i] = j;
			}
		}

		if(m_puiMaterialEffectID[i] == 0xbad)
		{
			PVRShellOutputDebug("ERROR: %s effect not found in PFX\n", pMaterial->pszEffectName);
			return false;
		}
	}

	return true;
}