/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES2MultiThreading::ReleaseView() { // Frees the OpenGL handles for the program and the 2 shaders if(handles.uiProgramObject) glDeleteProgram(handles.uiProgramObject); if(handles.uiFragShader) glDeleteShader(handles.uiFragShader); if(handles.uiVertShader) glDeleteShader(handles.uiVertShader); if(handles.uiLoadProgram) glDeleteProgram(handles.uiLoadProgram); if(handles.uiLoadFragShader) glDeleteShader(handles.uiLoadFragShader); if(handles.uiLoadVertShader) glDeleteShader(handles.uiLoadVertShader); // Delete the VBO as it is no longer needed if(handles.uiLoadVbo) glDeleteBuffers(1, &handles.uiLoadVbo); if(handles.uiVbo) glDeleteBuffers(1, &handles.uiVbo); if(handles.uiTexture) glDeleteTextures(1, &handles.uiTexture); // Clean up Print3D print3D.ReleaseTextures(); loadingText.ReleaseTextures(); // Destroy the pthread mutex. DeleteCriticalSection(&handles.mutex); return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2Glass::RenderScene() { if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT)) m_iEffect -= 1; if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) m_iEffect += 1; m_iEffect = (m_iEffect + g_iNumEffects) % g_iNumEffects; UpdateScene(); DrawIntoParaboloids(PVRTVec3(0, 0, 0)); // Clear the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw the ball DrawBall(); // Draw the balloons DrawBalloons(&m_DefaultProgram, m_mProjection, m_mView, m_mModels, 2); // Draw the skybox DrawSkybox(); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("Glass", g_aszEffectNames[m_iEffect], ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES3ShadowMapping::RenderScene() { Update(); // Bind the frame buffer object glBindFramebuffer(GL_FRAMEBUFFER, m_uiFrameBufferObject); // Clear the screen and depth buffer so we can render from the light's view glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); // Set the current viewport to our texture size but leave a one pixel margin. // As we are clamping to the edge of the texture when shadow mapping, no object // should be rendered to the border, otherwise stretching artefacts might occur // outside of the coverage of the shadow map. glViewport(1, 1, m_ui32ShadowMapSize-2, m_ui32ShadowMapSize-2); // Since we don't care about colour when rendering the depth values to // the shadow-map texture, we disable color writing to increase speed. glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Cull the front faces, so that only the backfaces are rendered into the shadowmap glCullFace(GL_FRONT); // Draw everything that we would like to cast a shadow RenderSceneWithEffect(INDEX_RENDERSHADOW, m_mLightProjection, m_mLightView); // Set the culling mode for the normal rendering glCullFace(GL_BACK); // Turn colour buffer writes back on again glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // Restore our normal viewport size to our screen width and height glViewport(0, 0,PVRShellGet(prefWidth),PVRShellGet(prefHeight)); //Invalidate the framebuffer attachments we don't need to avoid unnecessary copying to system memory const GLenum attachment = GL_COLOR_ATTACHMENT0; glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, &attachment); glBindFramebuffer(GL_FRAMEBUFFER, m_i32OriginalFbo); // Clear the colour and depth buffers, we are now going to render the scene again from scratch glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Load the shadow shader. This shader requires additional parameters; texProjMatrix for the depth buffer // look up and the light direction for diffuse light (the effect is a lot nicer with the addition of the // diffuse light). glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_uiShadowMapTexture); glActiveTexture(GL_TEXTURE0); RenderSceneWithEffect(INDEX_RENDERSCENE, m_mProjection, m_mView); m_Print3D.DisplayDefaultTitle("ShadowMap", "", ePVRTPrint3DSDKLogo); m_Print3D.Print3D(5.0f, 90.0f, 1.0f, 0xFFFFFFFF, "Bias: %f", m_fBias); m_Print3D.Flush(); return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES3AlphaTest::RenderScene() { // Clear color and z buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set texture glBindTexture(GL_TEXTURE_2D, m_uiTexture); /* Draw the left cube using alpha blending */ glUseProgram(m_TexShaderProgram.uiId); glEnable(GL_BLEND); // Setup blending for transparency glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Calculate the model matrix for the left cube PVRTMat4 mModel = PVRTMat4::RotationY(m_fAngleY); m_fAngleY += .005f; mModel.preTranslate(0.6f, 0, 0); // Calculate the model view projection (MVP) matrix and pass it to the shader PVRTMat4 mMVP = m_mViewProj * mModel; glUniformMatrix4fv(m_TexShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr()); // Draw left cube DrawModel(); /* Draw the right cube using alpha test. */ glUseProgram(m_DiscardShaderProgram.uiId); glDisable(GL_BLEND); // Set alpha test to discard fragments with an alpha value of less than 0.2 glUniform1f(m_DiscardShaderProgram.uiAlphaRefLoc, 0.2f); // Calculate the model matrix for the right cube mModel.preTranslate(-1.2f, 0, 0); // Calculate the model view projection (MVP) matrix and pass it to the shader mMVP = m_mViewProj * mModel; glUniformMatrix4fv(m_DiscardShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr()); // Draw right cube DrawModel(); // Display the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("AlphaTest", "", ePVRTPrint3DSDKLogo); m_Print3D.Print3D(10.0f, 10.0f, 1.0f, 0xFFFF00FF, "Alpha Blend"); m_Print3D.Print3D(60.0f, 10.0f, 1.0f, 0xFFFF00FF, "Alpha Test"); m_Print3D.Flush(); return true; }
/*!**************************************************************************** @Function RenderLoadingScene @Input iFrame @Description Renders an animated loading screen. ******************************************************************************/ void OGLES2MultiThreading::RenderLoadingScene(int iFrame) { bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); float fHW = PVRShellGet(prefWidth) / 2.0f; float fHH = PVRShellGet(prefHeight) / 2.0f; PVRTMat4 mxProjection = PVRTMat4::Ortho(-fHW, fHH, fHW, -fHH, -1.0f, 1.0f, PVRTMat4::OGL, bRotate); /* Clears the color buffer. */ glClear(GL_COLOR_BUFFER_BIT); // Actually use the created program glUseProgram(handles.uiLoadProgram); // First gets the location of that variable in the shader using its name int i32MVPLocation = glGetUniformLocation(handles.uiLoadProgram, "myPMVMatrix"); int i32ColLocation = glGetUniformLocation(handles.uiLoadProgram, "myCol"); for(int iCircleIdx = 0; iCircleIdx < c_iNumCircles; ++iCircleIdx) { int iProg = iFrame+iCircleIdx*4; float fScale = (0.75f + cos(iProg * 0.1f) * 0.25f); float fY = sin(iProg * 0.1f) * 25.0f; // Then passes the matrix to that variable PVRTMat4 mxMVP = mxProjection * PVRTMat4::Translation(-175.0f + iCircleIdx * 50.0f, fY, 0.0f) * PVRTMat4::Scale(fScale,fScale,1.0f); glUniformMatrix4fv(i32MVPLocation, 1, GL_FALSE, mxMVP.ptr()); // Pass the colour glUniform3f(i32ColLocation, c_vCircleCols[iCircleIdx].x, c_vCircleCols[iCircleIdx].y, c_vCircleCols[iCircleIdx].z); // Draw the loading circle glBindBuffer(GL_ARRAY_BUFFER, handles.uiLoadVbo); glEnableVertexAttribArray(VERTEX_ARRAY); glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, 0); // Submit glDrawArrays(GL_TRIANGLE_FAN, 0, c_iNumCirclePoints+2); glDisableVertexAttribArray(VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); } float fW; loadingText.SetProjection(mxProjection); ELoadingProgress eProgress = eProgress_Init; EnterCriticalSection(&handles.mutex); eProgress = g_eProgress; LeaveCriticalSection(&handles.mutex); loadingText.MeasureText(&fW, NULL, 1.0f, c_pszLoadingProgress[eProgress]); loadingText.Print3D(-fW*0.5f, -50.0f, 1.0f, 0xFFFFFFFF, c_pszLoadingProgress[eProgress]); loadingText.Flush(); }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2Fog::RenderScene() { // Clear the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Keyboard input (cursor to change fog function) if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT)) { m_eFogMode = EFogMode((m_eFogMode + eNumFogModes - 1) % eNumFogModes); } if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) { m_eFogMode = EFogMode((m_eFogMode + 1) % eNumFogModes); } // Use the loaded shader program glUseProgram(m_ShaderProgram.uiId); // Bind texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiTexture); // Set uniforms glUniform1i(m_ShaderProgram.uiFogFuncLoc, m_eFogMode); // Rotate and translate the model matrix PVRTMat4 mModel = PVRTMat4::RotationY(m_fAngleY); m_fAngleY += PVRT_PI / 90; mModel.preTranslate(0, 0, 500 * cos(m_fPositionZ) - 450); m_fPositionZ += (2*PVRT_PI)*0.0008f; // Feed Projection and Model View matrices to the shaders PVRTMat4 mModelView = m_mView * mModel; PVRTMat4 mMVP = m_mProjection * mModelView; glUniformMatrix4fv(m_ShaderProgram.uiModelViewLoc, 1, GL_FALSE, mModelView.ptr()); glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr()); // Pass the light direction transformed with the inverse of the ModelView matrix // This saves the transformation of the normals per vertex. A simple dot3 between this direction // and the un-transformed normal will allow proper smooth shading. PVRTVec3 vMsLightDir = (PVRTMat3(mModel).inverse() * PVRTVec3(1, 1, 1)).normalized(); glUniform3fv(m_ShaderProgram.uiLightDirLoc, 1, vMsLightDir.ptr()); /* Now that the model-view matrix is set and the materials ready, call another function to actually draw the mesh. */ DrawMesh(0); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("Fog", "", ePVRTPrint3DLogoIMG); m_Print3D.Print3D(0.3f, 7.5f, 0.75f, PVRTRGBA(255,255,255,255), "Fog Mode: %s", g_FogFunctionList[m_eFogMode]); m_Print3D.Flush(); return true; }
/******************************************************************************* * Function Name : ReleaseView * Returns : Nothing * Description : Code in ReleaseView() will be called by the Shell before * changing to a new rendering context. *******************************************************************************/ bool OGLESOptimizeMesh::ReleaseView() { // Release all Textures glDeleteTextures(1, &m_Texture); // Release the Print3D textures and windows m_Print3D.DeleteAllWindows(); m_Print3D.ReleaseTextures(); return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occurred @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES2IntroducingPrint3D::ReleaseView() { // Release Print3D Textures m_Print3D.ReleaseTextures(); m_CentralText.ReleaseTextures(); m_IntroText.ReleaseTextures(); m_TitleText.ReleaseTextures(); m_BG.Destroy(); return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occurred @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevant OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2FilmTV::RenderScene() { // Use shader program glUseProgram(m_ShaderProgram.uiId); // Enable the vertex attribute arrays glEnableVertexAttribArray(VERTEX_ARRAY); glEnableVertexAttribArray(NORMAL_ARRAY); // Render everything from the mini-camera's point of view if we have the FBOs CalcMiniCameraView(); if(m_bFBOsCreated) { // Setup the Viewport to the dimensions of the texture glViewport(0, 0, m_i32TexSize, m_i32TexSize); glBindFramebuffer(GL_FRAMEBUFFER, m_uiFbo[m_i32CurrentFBO]); DrawPODScene(m_MiniCamViewProj, false); if(m_bDiscard) // Was GL_EXT_discard_framebuffer supported? { /* Give the drivers a hint that we don't want the depth and stencil information stored for future use. Note: This training course doesn't have any stencil information so the STENCIL_ATTACHMENT enum is used for demonstrations purposes only and will be ignored by the driver. */ const GLenum attachments[] = { GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT }; m_Extensions.glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments); } glBindFramebuffer(GL_FRAMEBUFFER, m_i32OriginalFB); // Render everything // Setup the Viewport to the dimensions of the screen glViewport(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight)); } DrawPODScene(m_ViewProjection, true); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("FilmTV", "", ePVRTPrint3DSDKLogo); m_Print3D.Flush(); // Swap the FBO that we want to render to m_i32CurrentFBO = 1 - m_i32CurrentFBO; ++m_i32Frame; return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES3TextureStreaming::RenderScene() { // Clears the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Time based animation and locks the app to 60 FPS. // Uses the shell function PVRShellGetTime() to get the time in milliseconds. unsigned long ulTime = PVRShellGetTime(); unsigned long ulDeltaTime = ulTime - m_ulTimePrev; m_ulTimePrev = ulTime; m_fFrame += (float)ulDeltaTime * (60.0f/1000.0f); m_fBandScroll += (float)ulDeltaTime * (60.0f/1000.0f) * c_fBandScrollSpeed; if(m_fFrame > m_Scene.nNumFrame - 1) m_fFrame = 0.0f; if(m_fBandScroll > 1.0f) m_fBandScroll = -c_fBandWidth; bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); m_Scene.SetFrame(m_fFrame); // Setup the main camera PVRTVec3 vFrom, vTo(0.0f), vUp(0.0f, 1.0f, 0.0f); float fFOV; // Camera nodes are after the mesh and light nodes in the array int i32CamID = m_Scene.pNode[m_Scene.nNumMeshNode + m_Scene.nNumLight + c_ui32Camera].nIdx; // Get the camera position, target and field of view (fov) if(m_Scene.pCamera[i32CamID].nIdxTarget != -1) // Does the camera have a target? fFOV = m_Scene.GetCameraPos( vFrom, vTo, c_ui32Camera); // vTo is taken from the target node else fFOV = m_Scene.GetCamera( vFrom, vTo, vUp, c_ui32Camera); // vTo is calculated from the rotation float fTargetAspect = 960.0f/640.0f; float fAspect = (float)PVRShellGet(prefWidth) / (float)PVRShellGet(prefHeight); fFOV *= fTargetAspect / fAspect; PVRTMat4 mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp); PVRTMat4 mProjection = PVRTMat4::PerspectiveFovRH(fFOV, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), c_fCameraNear, c_fCameraFar, PVRTMat4::OGL, bRotate); PVRTMat4 mViewProjection = mProjection * mView; DrawPODScene(mViewProjection); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("Texture Streaming", c_pszDescription, ePVRTPrint3DSDKLogo); m_Print3D.Flush(); ++m_i32Frame; return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2MultiThreading::RenderScene() { // Render the loading screen while we wait for resources to load. if(bLoading) { // Render the animated loading scene. RenderLoadingScene(iFrame++); /* Check if the resources are still being loaded. This is performed by querying EGL to determine if a sync object has been signalled. */ EnterCriticalSection(&handles.mutex); if(handles.eglSync != EGL_NO_SYNC_KHR) { // Perform a non-blocking poll to check if the shared egl sync object has been signalled. EGLint status = eglClientWaitSyncKHR(handles.eglDisplay, handles.eglSync, 0, 0); if(status == EGL_CONDITION_SATISFIED_KHR) { // Destroy the egl sync object as soon as we aware of it's signal status. if(eglDestroySyncKHR(handles.eglDisplay, handles.eglSync) != EGL_TRUE) { PVRShellSet(prefExitMessage, "eglDestroySyncKHR returned unexpected EGL_FALSE.\n"); return false; } bLoading = false; } else if(status == EGL_FALSE) { PVRShellSet(prefExitMessage, "eglClientWaitSyncKHR returned unexpected EGL_FALSE.\n"); return false; } } LeaveCriticalSection(&handles.mutex); } else { glEnable(GL_DEPTH_TEST); // Render the pre-loaded scene RenderCubeScene(iFrame++); glDisable(GL_DEPTH_TEST); } print3D.DisplayDefaultTitle("MultiThreading", "", ePVRTPrint3DSDKLogo); print3D.Flush(); return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occurred @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevant OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2ParallaxBumpMap::RenderScene() { // Clear the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Use shader program glUseProgram(m_ShaderProgram.uiId); // Bind textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiBaseTex); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_uiNormalMap); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, m_uiHeightMap); // Calculate the model matrix PVRTMat4 mModel = PVRTMat4::Scale(g_CubeScale); mModel *= PVRTMat4::Translation(g_CubeTranslation); mModel *= PVRTMat4::RotationY(m_fAngleY); m_fAngleY += PVRT_PI / 450; // Set the Model View matrix PVRTMat4 mMV = m_mView * mModel; glUniformMatrix4fv(m_ShaderProgram.auiLoc[eModelViewMatrix], 1, GL_FALSE, mMV.ptr()); // Set the ModelViewIT Matrix PVRTMat4 mMIT = mMV.transpose(); mMIT = mMIT.inverseEx(); PVRTMat3 mMIT3x3 = PVRTMat3(mMIT); glUniformMatrix3fv(m_ShaderProgram.auiLoc[eNormal], 1, GL_FALSE, mMIT3x3.ptr()); // Set model view projection matrix PVRTMat4 mMVP = m_mViewProj * mModel; glUniformMatrix4fv(m_ShaderProgram.auiLoc[eModelViewProj], 1, GL_FALSE, mMVP.ptr()); // Set light position in eye space PVRTVec4 vEyeSpaceLightPos = m_mView * g_LightPos; glUniform3fv(m_ShaderProgram.auiLoc[eLightEyeSpacePos], 1, vEyeSpaceLightPos.ptr()); DrawMesh(0); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("Parallax Bumpmap", "", ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2ProceduralTextures::RenderScene() { if (!HandleInput()) { return false; } glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, m_ui32ColourSplineTexture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_FnTexture); glDisable(GL_CULL_FACE); glDisable(GL_BLEND); glDisable(GL_DEPTH_TEST); glUseProgram(m_auiShaderProgramId[m_uiVisualisation]); const float fIndex = m_uiGenerator / (float)(NUM_GENERATORS - 1); glUniform1f(m_aiColourSplineIndices[m_uiGenerator], fIndex); glEnableVertexAttribArray(VERTEX_ARRAY); glEnableVertexAttribArray(TEXTURE_ARRAY); // Pass the vertex data GLfloat pfVertices[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f }; glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, pfVertices); // Pass the texture coordinates data GLfloat pfTexCoord[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }; glVertexAttribPointer(TEXTURE_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, pfTexCoord); unsigned short indices[] = { 0, 1, 3, 1, 2, 3 }; glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); glDisableVertexAttribArray(VERTEX_ARRAY); glDisableVertexAttribArray(TEXTURE_ARRAY); glUseProgram(0); m_Print3D.DisplayDefaultTitle("OpenGL ES Compute Shader Procedural Textures", NULL, ePVRTPrint3DSDKLogo); m_Print3D.Print3D(1.0f, 80.0f, 1.0f, 0xFFFFFFFF, "Metric: %s", m_pProceduralTextures->GetModeDescription((eGenerator)m_uiGenerator)); m_Print3D.Print3D(1.0f, 90.0f, 1.0f, 0xFFFFFFFF, "Evaluator: %s", c_szVisualisationsDescriptions[m_uiVisualisation]); m_Print3D.Flush(); return true; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES3ComplexLighting::RenderScene() { // Clears the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Keyboard input (cursor to change light) if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT)) { m_eLightType = ELightType((m_eLightType + eNumLightTypes - 1) % eNumLightTypes); } if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) { m_eLightType = ELightType((m_eLightType + 1) % eNumLightTypes); } // Use shader program glUseProgram(m_ShaderProgram.uiId); // Bind texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiTexture); glUniform1i(m_ShaderProgram.uiLightSelLoc, m_eLightType); // Rotate and Translation the model matrix PVRTMat4 mModel = PVRTMat4::RotationY(m_fAngleY); m_fAngleY += PVRT_PI / 150; // Set model view projection matrix PVRTMat4 mModelView = m_mView * mModel; PVRTMat4 mMVP = m_mProjection * mModelView; glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.ptr()); // Set model view matrix glUniformMatrix4fv(m_ShaderProgram.uiModelViewLoc, 1, GL_FALSE, mModelView.ptr()); // Set model view inverse transpose matrix PVRTMat3 mModelViewIT = PVRTMat3(mModelView).inverse().transpose(); glUniformMatrix3fv(m_ShaderProgram.uiModelViewITLoc, 1, GL_FALSE, mModelViewIT.ptr()); DrawMesh(0); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("ComplexLighting", c_aszLightTypeList[m_eLightType], ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES2ShadowMapping::ReleaseView() { // Deletes the textures glDeleteTextures(m_Scene.nNumMaterial, &m_puiTextureIDs[0]); // Frees the texture lookup array delete[] m_puiTextureIDs; m_puiTextureIDs = 0; // Delete program and shader objects glDeleteProgram(m_ShadowShaderProgram.uiId); glDeleteShader(m_uiShadowVertShader); glDeleteShader(m_uiShadowFragShader); // Delete program and shader objects glDeleteProgram(m_SimpleShaderProgram.uiId); glDeleteShader(m_uiSimpleVertShader); glDeleteShader(m_uiSimpleFragShader); // Delete buffer objects glDeleteBuffers(m_Scene.nNumMesh, m_puiVbo); glDeleteBuffers(m_Scene.nNumMesh, m_puiIndexVbo); // Release Print3D Textures m_Print3D.ReleaseTextures(); 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 OGLES2ShadowMapping::InitView() { CPVRTString ErrorStr; if(!CPVRTgles2Ext::IsGLExtensionSupported("GL_OES_depth_texture")) { PVRShellSet(prefExitMessage, "Error: Unable to run this training course as it requires extension 'GL_OES_depth_texture'"); return false; } m_bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); // Initialize VBO data if(!LoadVbos(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Load textures if (!LoadTextures(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Load and compile the shaders & link programs if (!LoadShaders(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Create a frame buffer with only the depth buffer attached glGenFramebuffers(1, &m_uiFrameBufferObject); glBindFramebuffer(GL_FRAMEBUFFER, m_uiFrameBufferObject); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_uiShadowMapTexture, 0); if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { PVRShellSet(prefExitMessage, "ERROR: Frame buffer not set up correctly\n"); return false; } glBindFramebuffer(GL_FRAMEBUFFER, 0); // Initialize Print3D if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight),m_bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n"); return false; } // Use a nice bright blue as clear colour glClearColor(0.6f, 0.8f, 1.0f, 1.0f); return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLESIntroducingPFX::ReleaseView() { // Release textures { const SPVRTPFXTexture *psTex; unsigned int nCnt, i; psTex = m_pEffect->GetTextureArray(nCnt); for(i = 0; i < nCnt; ++i) { glDeleteTextures(1, &psTex[i].ui); } } // Release the effect[s] then the parser delete m_pEffect; delete m_pEffectParser; FREE(m_psUniforms); // Release Print3D Textures m_Print3D.ReleaseTextures(); // Release Vertex buffer objects. glDeleteBuffers(m_Scene.nNumMeshNode, m_aiVboID); delete[] m_aiVboID; return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES2PVRScopeRemote::ReleaseView() { CPPLProcessingScoped PPLProcessingScoped(m_psSPSCommsData, __FUNCTION__, static_cast<unsigned int>(strlen(__FUNCTION__)), m_i32FrameCounter); // Delete textures glDeleteTextures(1, &m_uiTexture); // Delete program and shader objects glDeleteProgram(m_ShaderProgram.uiId); glDeleteShader(m_uiVertShader); glDeleteShader(m_uiFragShader); // Delete buffer objects glDeleteBuffers(m_Scene.nNumMesh, m_puiVbo); glDeleteBuffers(m_Scene.nNumMesh, m_puiIndexVbo); // Release Print3D Textures m_Print3D.ReleaseTextures(); delete [] m_pszVertShader; delete [] m_pszFragShader; return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES3ShadowMapping::ReleaseView() { // Release textures { const CPVRTArray<SPVRTPFXTexture>& sTex = m_ppPFXEffects[0]->GetTextureArray(); for(unsigned int i = 0; i < sTex.GetSize(); ++i) glDeleteTextures(1, &sTex[i].ui); } // Release Print3D Textures m_Print3D.ReleaseTextures(); glDeleteBuffers(m_Scene.nNumMeshNode, m_puiVbo); glDeleteBuffers(m_Scene.nNumMeshNode, m_puiIndexVbo); // Release the effect[s] then the parser if (m_pPFXEffectParser) for (unsigned int i=0; i < m_pPFXEffectParser->GetNumberEffects(); i++) if (m_ppPFXEffects[i]) delete m_ppPFXEffects[i]; delete [] m_ppPFXEffects; delete m_pPFXEffectParser; return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occurred @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES3MagicLantern::ReleaseView() { // Delete all effects. for (unsigned int i=0; i<m_ppEffectParser->GetNumberEffects(); i++) { delete m_pFX[i]; } // Delete the PFX container. delete m_ppEffectParser; // Delete buffer objects. glDeleteBuffers(m_Scene.nNumMesh, m_puiVbo); glDeleteBuffers(m_Scene.nNumMesh, m_puiIndexVbo); // Release loaded textures for(unsigned int uiIndex = 0; uiIndex < m_TextureCache.GetSize(); ++uiIndex) { GLuint uiHandle = m_TextureCache.GetDataAtIndex(uiIndex)->uiHandle; glDeleteTextures(1, &uiHandle); } m_TextureCache.Clear(); // Release Print3D Textures m_Print3D.ReleaseTextures(); return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES2PVRScopeExample::ReleaseView() { // Delete textures glDeleteTextures(1, &m_uiTexture); // Delete program and shader objects glDeleteProgram(m_ShaderProgram.uiId); glDeleteShader(m_uiVertShader); glDeleteShader(m_uiFragShader); // Delete buffer objects glDeleteBuffers(m_Scene.nNumMesh, m_puiVbo); glDeleteBuffers(m_Scene.nNumMesh, m_puiIndexVbo); // Release Print3D Textures m_Print3D.ReleaseTextures(); if(m_pScopeGraph) { delete m_pScopeGraph; m_pScopeGraph = 0; } return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occurred @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES2FilmTV::ReleaseView() { // Delete program and shader objects glDeleteProgram(m_ShaderProgram.uiId); glDeleteProgram(m_BWShaderProgram.uiId); glDeleteShader(m_uiVertShader); glDeleteShader(m_uiFragShader); glDeleteShader(m_uiBWFragShader); // Delete buffer objects glDeleteBuffers(m_Scene.nNumMesh, m_puiVbo); glDeleteBuffers(m_Scene.nNumMesh, m_puiIndexVbo); glDeleteFramebuffers(2, m_uiFbo); // Delete our depth buffer render buffers glDeleteRenderbuffers(2, m_uiDepthBuffer); // Release Print3D Textures m_Print3D.ReleaseTextures(); // Deletes the textures glDeleteTextures(m_Scene.nNumMaterial, &m_puiTextureIDs[0]); glDeleteTextures(2, &m_uiTexture[0]); // Frees the texture lookup array delete[] m_puiTextureIDs; m_puiTextureIDs = 0; return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occurred @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES3PhantomMask::ReleaseView() { // Release all Textures glDeleteTextures(1, &m_ui32TexMask); glDeleteTextures(1, &m_ui32TexBackground); // Delete program and shader objects glDeleteProgram(m_SHShaderProgram.uiId); glDeleteProgram(m_DiffuseShaderProgram.uiId); glDeleteShader(m_uiSHVertShader); glDeleteShader(m_uiDifVertShader); glDeleteShader(m_uiFragShader); // Delete buffer objects glDeleteBuffers(m_Scene.nNumMesh, m_puiVbo); glDeleteBuffers(m_Scene.nNumMesh, m_puiIndexVbo); // Release Print3D Textures m_Print3D.ReleaseTextures(); m_Background.Destroy(); return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES2MaximumIntensityBlend::ReleaseView() { // Release textures { const CPVRTArray<SPVRTPFXTexture>& sTex = m_pEffect->GetTextureArray(); for(unsigned int i = 0; i < sTex.GetSize(); ++i) { glDeleteTextures(1, &sTex[i].ui); } } // Release the effect[s] then the parser delete m_pEffect; delete m_pEffectTextured; delete m_pEffectParser; // Release Print3D Textures m_Print3D.ReleaseTextures(); // Release Vertex buffer objects. glDeleteBuffers(m_Scene.nNumMeshNode, m_aiVboID); delete[] m_aiVboID; return true; }
bool PVRESettings::InitPrint3D(CPVRTPrint3D& sPrint3d, const unsigned int u32Width, const unsigned int u32Height, const bool bRotate) { return sPrint3d.SetTextures(m_pContext,u32Width,u32Height,bRotate) == PVR_SUCCESS; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES3EdgeDetection::ReleaseView() { // Delete the color texture glDeleteTextures(1, &m_uiColorTexture); // Delete the depth render buffer glDeleteRenderbuffers(1, &m_uiDepthRenderbuffer); // delete shader program , and shaders glDeleteProgram(m_PreShader.uiId); glDeleteShader(m_uiPreVertShader); glDeleteShader(m_uiPreFragShader); for (int i=0; i<eNumPostShaders; ++i) { glDeleteProgram(m_PostShaders[i].uiId); glDeleteShader(m_uiPostVertShaders[i]); glDeleteShader(m_uiPostFragShaders[i]); } // Delete the stored color data. delete [] m_pvColorData->ptr(); m_pvColorData=NULL; // Release Print3D Textures m_Print3D.ReleaseTextures(); // Delete frame buffer objects glDeleteFramebuffers(1, &m_uiFramebufferObject); return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLESRenderToTexture::ReleaseView() { // Delete the texture glDeleteTextures(1, &m_uiTextureID); glDeleteTextures(1, &m_uiTextureToRenderTo); // Release Print3D Textures m_Print3D.ReleaseTextures(); // Destroy the FBO or PBuffer surface we were using switch(m_eR2TType) { case eFBO: // Delete frame buffer objects m_Extensions.glDeleteFramebuffersOES(1, &m_uFBO); // Delete our depth buffer m_Extensions.glDeleteRenderbuffersOES(1, &m_uDepthBuffer); break; #if !defined(EGL_NOT_PRESENT) case ePBuffer: // Destroy the surfaces we created eglDestroySurface(m_CurrentDisplay, m_PBufferSurface); break; #endif default: break; } return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES2ChameleonMan::ReleaseView() { // Delete textures glDeleteTextures(1, &m_ui32TexLegs); glDeleteTextures(1, &m_ui32TexBeltNormalMap); glDeleteTextures(1, &m_ui32TexHeadNormalMap); glDeleteTextures(1, &m_ui32TexLegsNormalMap); glDeleteTextures(1, &m_ui32TexSkyLine); glDeleteTextures(1, &m_ui32TexWall); glDeleteTextures(1, &m_ui32TexLamp); glDeleteTextures(1, &m_ui32TexBelt); // Delete program and shader objects glDeleteProgram(m_SkinnedShaderProgram.uiId); glDeleteProgram(m_DefaultShaderProgram.uiId); glDeleteShader(m_uiSkinnedVertShader); glDeleteShader(m_uiDefaultVertShader); glDeleteShader(m_uiSkinnedFragShader); glDeleteShader(m_uiDefaultFragShader); // Delete buffer objects glDeleteBuffers(m_Scene.nNumMesh, m_puiVbo); glDeleteBuffers(m_Scene.nNumMesh, m_puiIndexVbo); // Release Print3D Textures m_Print3D.ReleaseTextures(); return true; }
/*!**************************************************************************** @Function ReleaseView @Return bool true if no error occured @Description Code in ReleaseView() will be called by PVRShell when the application quits or before a change in the rendering context. ******************************************************************************/ bool OGLES3Skybox2::ReleaseView() { // Free the textures unsigned int i; for(i = 0; i < g_ui32TexNo; ++i) { glDeleteTextures(1, &(m_ui32TextureIDs[i])); } // Release Print3D Textures m_Print3D.ReleaseTextures(); // Release Vertex buffer objects. glDeleteBuffers(m_Scene.nNumMeshNode, m_aiVboID); glDeleteBuffers(1, &m_iSkyVboID); delete[] m_aiVboID; // Destroy the effects for(i = 0; i < g_ui32NoOfEffects; ++i) DestroyEffect(&m_ppEffects[i]); delete[] m_ppEffects; delete m_pEffectParser; return true; }
void RudeText::Flush() { RGL.EnableClient(kVertexArray, true); RGL.EnableClient(kColorArray, true); RGL.EnableClient(kTextureCoordArray, true); gTextPrint.Flush(); }