/*!**************************************************************************** @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 PVRTStringStripWhiteSpaceFromStartOf @Input strLine A string @Returns Result of the white space stripping @Description strips white space characters from the beginning of a CPVRTString. ************************************************************************/ CPVRTString PVRTStringStripWhiteSpaceFromStartOf(const CPVRTString& strLine) { size_t start = strLine.find_first_not_of(" \t "); if(start!=strLine.npos) return strLine.substr(start,strLine.length()-start+1); return strLine; }
/*!**************************************************************************** @Function InitApplication @Return bool true if no error occured @Description Code in InitApplication() will be called by PVRShell once per run, before the rendering context is created. Used to initialize variables that are not dependant on it (e.g. external modules, loading meshes, etc.) If the rendering context is lost, InitApplication() will not be called again. ******************************************************************************/ bool OGLESRenderToTexture::InitApplication() { // Get and set the read path for content files CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath)); // Get and set the load/release functions for loading external files. // In the majority of cases the PVRShell will return NULL function pointers implying that // nothing special is required to load external files. CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc)); /* Loads the scene from the .pod file into a CPVRTModelPOD object. We could also export the scene as a header file and load it with ReadFromMemory(). */ if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS) { CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_szSceneFile) + "'."; PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } return true; }
/*!**************************************************************************** @Function InitApplication @Return bool true if no error occured @Description Code in InitApplication() will be called by PVRShell once per run, before the rendering context is created. Used to initialize variables that are not dependant on it (e.g. external modules, loading meshes, etc.) If the rendering context is lost, InitApplication() will not be called again. ******************************************************************************/ bool OGLES2EdgeDetection::InitApplication() { #ifdef SHOW_MAX_FPS // Disable v-sync PVRShellSet(prefSwapInterval,0); #endif // Get and set the read path for content files CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath)); // Get and set the load/release functions for loading external files. // In the majority of cases the PVRShell will return NULL function pointers implying that // nothing special is required to load external files. CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc)); /* Loads the scene from the .pod file into a CPVRTModelPOD object. We could also export the scene as a header file and load it with ReadFromMemory(). */ if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS) { CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_szSceneFile) + "'."; PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } //Initialises the time variables. m_ulCurrentTime = PVRShellGetTime(); m_ulPreviousTimeAngle = m_ulCurrentTime; m_ulPreviousTimeFPS = m_ulCurrentTime; return true; }
/*!**************************************************************************** @Function InitApplication @Return bool true if no error occurred @Description Code in InitApplication() will be called by PVRShell once per run, before the rendering context is created. Used to initialize variables that are not dependant on it (e.g. external modules, loading meshes, etc.) If the rendering context is lost, InitApplication() will not be called again. ******************************************************************************/ bool OGLES2FilmTV::InitApplication() { // Get and set the read path for content files CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath)); // Get and set the load/release functions for loading external files. // In the majority of cases the PVRShell will return NULL function pointers implying that // nothing special is required to load external files. CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc)); // Load the scene if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS) { CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_szSceneFile) + "'."; PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // The cameras are stored in the file. We check it contains at least one. if(m_Scene.nNumCamera == 0) { PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a camera. Please add one and re-export.\n"); return false; } // We also check that the scene contains at least one light if(m_Scene.nNumLight == 0) { PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a light. Please add one and re-export.\n"); return false; } return true; }
/*!**************************************************************************** @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 OGLESPVRScopeRemote::InitView() { CPPLProcessingScoped PPLProcessingScoped(m_psSPSCommsData, __FUNCTION__, static_cast<unsigned int>(strlen(__FUNCTION__)), m_i32FrameCounter); CPVRTString ErrorStr; /* 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 texturing glEnable(GL_TEXTURE_2D); // 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; } /* Calculate the projection and view matrices */ m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PIf/6, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), CAM_NEAR, CAM_FAR, PVRTMat4::OGL, bRotate); m_mView = PVRTMat4::LookAtRH(PVRTVec3(0, 0, 75.0f), PVRTVec3(0, 0, 0), PVRTVec3(0, 1, 0)); // Enable the depth test glEnable(GL_DEPTH_TEST); // Enable culling glEnable(GL_CULL_FACE); // Initialise variables used for the animation m_fFrame = 0; m_iTimePrev = PVRShellGetTime(); return true; }
/*!*************************************************************************** @Function LoadEffect @Output ppEffect @Input pszEffectName @Input pszFileName @Return bool @Description Loads a PFX Effect. *****************************************************************************/ bool OGLES3Skybox2::LoadEffect( CPVRTPFXEffect **ppEffect, const char * pszEffectName, const char *pszFileName ) { if(!ppEffect) return false; unsigned int nUnknownUniformCount; CPVRTString error; CPVRTPFXEffect* pEffect = *ppEffect; // Load an effect from the file if(!pEffect) { *ppEffect = new CPVRTPFXEffect(); pEffect = *ppEffect; if(!pEffect) { delete m_pEffectParser; PVRShellSet(prefExitMessage, "Failed to create effect.\n"); return false; } } if(pEffect->Load(*m_pEffectParser, pszEffectName, pszFileName, NULL, nUnknownUniformCount, &error) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, error.c_str()); return false; } if(nUnknownUniformCount) { PVRShellOutputDebug(error.c_str()); PVRShellOutputDebug("Unknown uniform semantic count: %d\n", nUnknownUniformCount); } /* Set the textures for each effect */ unsigned int i,j ; const CPVRTArray<SPVRTPFXTexture>& sTex = pEffect->GetTextureArray(); for(i = 0; i < sTex.GetSize(); ++i) { for(j = 0; j < g_ui32TexNo; ++j) { int iTexIdx = m_pEffectParser->FindTextureByName(sTex[i].Name); const CPVRTStringHash& FileName = m_pEffectParser->GetTexture(iTexIdx)->FileName; if(FileName == g_aszTextureNames[j]) { if(j == 3 || j == 4) pEffect->SetTexture(i, m_ui32TextureIDs[j], PVRTEX_CUBEMAP); else pEffect->SetTexture(i, m_ui32TextureIDs[j]); break; } } } 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 OGLES3TextureStreaming::InitView() { CPVRTString ErrorStr; // 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; } /* 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; } //Set OpenGL ES render states needed for this demo // Enable backface culling and depth test glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); // Sets the clear color glClearColor(0.6f, 0.8f, 1.0f, 1.0f); // Setup the AV capture if(!m_Camera.InitialiseSession(ePVRTHWCamera_Front)) return false; 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 OGLES2ChameleonMan::InitView() { CPVRTString ErrorStr; /* Initialize VBO data */ LoadVbos(); /* 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; } /* Initialize Print3D */ // Is the screen rotated? 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; } /* Set OpenGL ES render states needed for this training course */ // Enable backface culling and depth test glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); // Use black as our clear colour glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Initialise variables used for the animation m_iTimePrev = PVRShellGetTime(); return true; }
/*!*********************************************************************** @Function PVRTStringGetFileExtension @Input strFilePath A string @Returns Extension @Description Extracts the file extension from a file path. Returns an empty CPVRTString if no extension is found. ************************************************************************/ CPVRTString PVRTStringGetFileExtension(const CPVRTString& strFilePath) { CPVRTString::size_type idx = strFilePath.find_last_of ( '.' ); if (idx == CPVRTString::npos) return CPVRTString(""); else return strFilePath.substr(idx); }
/*!**************************************************************************** @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 OGLES3IntroducingPOD::InitView() { CPVRTString ErrorStr; /* 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; } /* 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; } /* Set OpenGL ES render states needed for this training course */ // Enable backface culling and depth test glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); // Use a nice bright blue as clear colour glClearColor(0.6f, 0.8f, 1.0f, 1.0f); return true; }
/*!**************************************************************************** @Function InitApplication @Return bool true if no error occured @Description Code in InitApplication() will be called by PVRShell once per run, before the rendering context is created. Used to initialize variables that are not dependant on it (e.g. external modules, loading meshes, etc.) If the rendering context is lost, InitApplication() will not be called again. ******************************************************************************/ bool OGLES3TextureStreaming::InitApplication() { m_i32Frame = 0; m_puiVbo = 0; m_puiIndexVbo = 0; m_ulGlowTime = 0; m_iNoiseCoordIdx = 0; m_uiTVScreen = -1; m_bGlowState = false; /* CPVRTResourceFile is a resource file helper class. Resource files can be placed on disk next to the executable or in a platform dependent read path. We need to tell the class where that read path is. Additionally, it is possible to wrap files into cpp modules and link them directly into the executable. In this case no path will be used. Files on disk will override "memory files". */ // Get and set the read path for content files CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath)); // Get and set the load/release functions for loading external files. // In the majority of cases the PVRShell will return NULL function pointers implying that // nothing special is required to load external files. CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc)); // Load the scene if(m_Scene.ReadFromFile(c_pszSceneFile) != PVR_SUCCESS) { CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_pszSceneFile) + "'.\n"; PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // The cameras are stored in the file. We check it contains at least one. if(m_Scene.nNumCamera == 0) { PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a camera. Please add one and re-export.\n"); return false; } // We also check that the scene contains at least one light if(m_Scene.nNumLight == 0) { PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a light. Please add one and re-export.\n"); return false; } // Initialize variables used for the animation. m_fFrame = 0.0f; m_fBandScroll = -c_fBandWidth; m_ulTimePrev = PVRShellGetTime(); return true; }
/*!**************************************************************************** @Function LoadTextures @Return bool true if no error occured @Description Loads the textures required for this training course ******************************************************************************/ bool OGLES2FilmTV::LoadTextures(CPVRTString* pErrorStr) { /* Loads the textures. For a more detailed explanation, see Texturing and IntroducingPVRTools */ /* Initialises an array to lookup the textures for each material in the scene. */ m_puiTextureIDs = new GLuint[m_Scene.nNumMaterial]; if(!m_puiTextureIDs) { *pErrorStr = "ERROR: Insufficient memory."; return false; } for(unsigned int i = 0; i < m_Scene.nNumMaterial; ++i) { m_puiTextureIDs[i] = 0; SPODMaterial* pMaterial = &m_Scene.pMaterial[i]; if(pMaterial->nIdxTexDiffuse != -1) { /* Using the tools function PVRTTextureLoadFromPVR load the textures required by the pod file. Note: This function only loads .pvr files. You can set the textures in 3D Studio Max to .pvr files using the PVRTexTool plug-in for max. Alternatively, the pod material properties can be modified in PVRShaman. */ CPVRTString sTextureName = m_Scene.pTexture[pMaterial->nIdxTexDiffuse].pszName; if(sTextureName == "TV.pvr") m_uiTVScreen = i; if(PVRTTextureLoadFromPVR(sTextureName.c_str(), &m_puiTextureIDs[i]) != PVR_SUCCESS) { *pErrorStr = "ERROR: Failed to load " + sTextureName + "."; // Check to see if we're trying to load .pvr or not CPVRTString sFileExtension = PVRTStringGetFileExtension(sTextureName); if(sFileExtension.toLower() != "pvr") *pErrorStr += "Note: FilmTV can only load .pvr files."; return false; } } } return true; }
/*!**************************************************************************** @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 dependant on the rendering context (e.g. textures, vertex buffers, etc.) ******************************************************************************/ bool OGLES3EdgeDetection::InitView() { // Store width and height of the viewport. m_i32TexWidth = PVRShellGet(prefWidth); m_i32TexHeight = PVRShellGet(prefHeight); /* Get the current frame buffer object. As the program hasn't set it yet, this is the default buffer. On most platforms this just gives 0, but there are exceptions. */ glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_i32OriginalFramebuffer); // Create string for error codes. CPVRTString ErrorStr; // Checks to see if the screen is rotated or not. bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); // Initialize VBO data if(!LoadVbos(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Initialise Print3D if(m_Print3D.SetTextures(0,m_i32TexWidth,m_i32TexHeight,bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n"); return false; } // Load external textures and create internal ones. 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; } // Creates and checks FBO creation if (!CreateFBO(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } SetupView(bRotate); return true; }
/*!*********************************************************************** @Function PVRTStringGetContainingDirectoryPath @Input strFilePath A string @Returns Directory @Description Extracts the directory portion from a file path. ************************************************************************/ CPVRTString PVRTStringGetContainingDirectoryPath(const CPVRTString& strFilePath) { size_t i32sep = strFilePath.find_last_of('/'); if(i32sep == strFilePath.npos) { i32sep = strFilePath.find_last_of('\\'); if(i32sep == strFilePath.npos) { // can't find an actual \ or / so leave it be return strFilePath; } } return strFilePath.substr(0,i32sep); }
/*!*********************************************************************** @Function PVRTStringGetFileName @Input strFilePath A string @Returns FileName @Description Extracts the name and extension portion from a file path. ************************************************************************/ CPVRTString PVRTStringGetFileName(const CPVRTString& strFilePath) { size_t i32sep = strFilePath.find_last_of('/'); if(i32sep == strFilePath.npos) { i32sep = strFilePath.find_last_of('\\'); if(i32sep == strFilePath.npos) { // can't find an actual \ or / so leave it be return strFilePath; } } return strFilePath.substr(i32sep+1,strFilePath.length()); }
/*!**************************************************************************** @Function InitApplication @Return bool true if no error occured @Description Code in InitApplication() will be called by PVRShell once per run, before the rendering context is created. Used to initialize variables that are not dependant on it (e.g. external modules, loading meshes, etc.) If the rendering context is lost, InitApplication() will not be called again. ******************************************************************************/ bool OGLESPVRScopeExample::InitApplication() { // At the time of writing, this counter is the USSE load for vertex + pixel processing m_i32Counter = 46; m_i32Group = 0; m_i32Interval = 0; // Get and set the read path for content files CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath)); // Get and set the load/release functions for loading external files. // In the majority of cases the PVRShell will return NULL function pointers implying that // nothing special is required to load external files. CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc)); /* Loads the scene from the .pod file into a CPVRTModelPOD object. We could also export the scene as a header file and load it with ReadFromMemory(). */ if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS) { CPVRTString ErrorStr = "ERROR: Couldn't load '" + CPVRTString(c_szSceneFile) + "'."; PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Process the command line { const unsigned int nOptNum = PVRShellGet(prefCommandLineOptNum); const SCmdLineOpt * const psOpt = (const SCmdLineOpt*)PVRShellGet(prefCommandLineOpts); for(unsigned int i = 0; i < nOptNum; ++i) { if(_stricmp(psOpt[i].pArg, "-counter") == 0 && psOpt[i].pVal) { m_i32Counter = atoi(psOpt[i].pVal); } else if(_stricmp(psOpt[i].pArg, "-group") == 0 && psOpt[i].pVal) { m_i32Group = atoi(psOpt[i].pVal); } else if(_stricmp(psOpt[i].pArg, "-interval") == 0 && psOpt[i].pVal) { m_i32Interval = atoi(psOpt[i].pVal); } } } 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 OGLES2ParticleSystem::InitView() { CPVRTString ErrorStr; bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); // Initialize Print3D textures if(m_Print3D.SetTextures(0, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n"); return false; } // Load and compile the shaders & link programs if (!LoadVbos(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Load and compile the shaders & link programs 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; } // Creates the projection matrix. m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PI / 3.0f, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate); m_pParticleSystem = new ParticleSystemCPU(); if (!m_pParticleSystem->Init(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } m_pParticleSystem->SetNumberOfParticles(g_ui32InitialNoParticles); m_pParticleSystem->SetCollisionSpheres(g_caSpheres, g_cuiNumSpheres); glBindBuffer(GL_ARRAY_BUFFER, 0); return true; }
/*!*************************************************************************** @Function PVRTShaderLoadFromFile @Input pszBinFile binary shader filename @Input pszSrcFile source shader filename @Input Type type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER) @Input Format shader binary format, or 0 for source shader @Output pObject the resulting shader object @Output pReturnError the error message if it failed @Input pContext Context @Input aszDefineArray Array of defines to be pre-appended to shader string @Input uiDefArraySize Size of the define array @Return PVR_SUCCESS on success and PVR_FAIL on failure (also fills pReturnError) @Description Loads a shader file into memory and passes it to the GL. It also passes defines that need to be pre-appended to the shader before compilation. *****************************************************************************/ EPVRTError PVRTShaderLoadFromFile( const char* const pszBinFile, const char* const pszSrcFile, const GLenum Type, const GLenum Format, GLuint* const pObject, CPVRTString* const pReturnError, const SPVRTContext* const pContext, const char* const* aszDefineArray, GLuint uiDefArraySize) { PVRT_UNREFERENCED_PARAMETER(pContext); *pReturnError = ""; /* Prepending defines relies on altering the source file that is loaded. For this reason, the function calls the source loader instead of the binary loader if defines have been passed in. */ if(Format && pszBinFile && uiDefArraySize == 0) { CPVRTResourceFile ShaderFile(pszBinFile); if (ShaderFile.IsOpen()) { if(PVRTShaderLoadBinaryFromMemory(ShaderFile.DataPtr(), ShaderFile.Size(), Type, Format, pObject, pReturnError) == PVR_SUCCESS) return PVR_SUCCESS; } *pReturnError += CPVRTString("Failed to open shader ") + pszBinFile + "\n"; } CPVRTResourceFile ShaderFile(pszSrcFile); if (!ShaderFile.IsOpen()) { *pReturnError += CPVRTString("Failed to open shader ") + pszSrcFile + "\n"; return PVR_FAIL; } CPVRTString ShaderFileString; const char* pShaderData = (const char*) ShaderFile.DataPtr(); // Is our shader resource file data null terminated? if(pShaderData[ShaderFile.Size()-1] != '\0') { // If not create a temporary null-terminated string ShaderFileString.assign(pShaderData, ShaderFile.Size()); pShaderData = ShaderFileString.c_str(); } return PVRTShaderLoadSourceFromMemory(pShaderData, Type, pObject, pReturnError, aszDefineArray, uiDefArraySize); }
/*!**************************************************************************** @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 OGLES2Coverflow::InitView() { CPVRTString ErrorStr; // Get and set the read path for content files CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath)); // Get and set the load/release functions for loading external files. // In the majority of cases the PVRShell will return NULL function pointers implying that // nothing special is required to load external files. CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc)); if (!LoadTextures(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } if (!LoadShaders(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } 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; } PVRTVECTOR3 vFrom = {0.0f, 0.0f, 15.0f }, vTo = { 0, 0, 0 }, vUp = { 0, 1, 0 }; PVRTMatrixPerspectiveFovRH(m_mProjection, g_FOV, f2vt((float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight)), f2vt(g_fCameraNear), f2vt(g_fCameraFar), bRotate); PVRTMatrixLookAtRH(m_mView, vFrom, vTo, vUp); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //this must be called after InitApplication CreateCover(); // Enable culling glEnable(GL_CULL_FACE); 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 OGLES3AlphaBlend::InitView() { CPVRTString ErrorStr; /* Initialize VBO data */ LoadVbos(); /* 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; } /* Get screen rotation state */ m_bRotateScreen = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); /* Initialize Print3D */ if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), m_bRotateScreen) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n"); return false; } // Disable the depth test glDisable(GL_DEPTH_TEST); // Enable culling glEnable(GL_CULL_FACE); return true; }
/*!**************************************************************************** @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 dependant on the rendering context (e.g. textures, vertex buffers, etc.) ******************************************************************************/ bool OGLES3PhantomMask::InitView() { CPVRTString ErrorStr; // Initialise 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; } // Initialise 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; } // Initialise the background if(m_Background.Init(0, bRotate, &ErrorStr) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Use a nice bright blue as clear colour glClearColor(0.6f, 0.8f, 1.0f, 1.0f); return true; }
bool getline(CPVRTString& strSrc, CPVRTString& strLine, const char delimiter) { if(strSrc.size()>0) { size_t i32LineLength = strSrc.find_first_of(delimiter); if(!i32LineLength || i32LineLength==CPVRTString::npos) { strLine = strSrc; strSrc.clear(); } else { strLine = strSrc.substr(0,i32LineLength-1); strSrc = strSrc.substr(i32LineLength+1); } return true; } return false; }
unsigned createProgramFromSource( const char * vss, // vertex shader source const char * fss, // fragment shader source const char** attribs, // attribute list unsigned * attrLocal, // store attribute locations const unsigned num // attribute list size ) { unsigned id = 0; unsigned vs = 0; unsigned fs = 0; EPVRTError ret = PVR_SUCCESS; CPVRTString msg; int step = 0; do { if (!vss || !fss || (num && (!attribs || !attrLocal))) { Debug::logd("There's no shader source!!"); break; } // 1 Compile vertex shader. step = 1; if (PVR_SUCCESS != PVRTShaderLoadSourceFromMemory( vss, GL_VERTEX_SHADER, &vs, &msg, 0, 0)) break; // 2 Compile fragment shader. step = 2; if (PVR_SUCCESS != PVRTShaderLoadSourceFromMemory( fss, GL_FRAGMENT_SHADER, &fs, &msg, 0, 0)) break; // 3 Link two shaders to program, and bind attribs to specific locations. step = 3; if (PVR_SUCCESS != PVRTCreateProgram( &id, vs, fs, attribs, num, &msg)) break; for (unsigned i = 0; i < num; i++) *(attrLocal + i) = i; } while (false); if (! id) { Debug::logd("(step:%d)%s", step, msg.c_str()); } return id; }
// --------------------------------------------------------------- bool MyPVRDemo::InitView() { CPVRTString ErrorStr; LoadVBOs(); bool bResult = true; bResult &= LoadTextures(&ErrorStr); bResult &= LoadShaders(&ErrorStr); bResult &= CreateFBOs(&ErrorStr); if(!bResult) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } m_bRotated = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); // --- Set up light position, projection and view m_vLightPos = PVRTVec3(0, 125, 200); m_mxLightProj = PVRTMat4::PerspectiveFovRH(PVRT_PI / 4, 1.0f, 10.0f, 1000.0f, PVRTMat4::OGL, m_bRotated); m_mxLightView = PVRTMat4::LookAtRH(m_vLightPos, PVRTVec3(0,25,0), PVRTVec3(0,1,0)); m_mxLightBias = PVRTMat4(0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.5f, 0.5f, 1.0f); // --- Set up Camera projection and view float fAspect = PVRShellGet(prefWidth) / (float)PVRShellGet(prefHeight); m_mxProjection = PVRTMat4::PerspectiveFovFloatDepthRH(0.75f, fAspect, 10.0f, PVRTMat4::OGL, m_bRotated); m_mxCam = PVRTMat4::LookAtRH(PVRTVec3(0, 55, 150), PVRTVec3(0, 35, 0), PVRTVec3(0, 1, 0)); // --- Set GL states glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_GEQUAL); glClearDepthf(0.0f); glClearColor(0,0,0,1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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 dependent on the rendering context (e.g. textures, vertex buffers, etc.) ******************************************************************************/ bool OGLES2ProceduralTextures::InitView() { CPVRTString ErrorStr; bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); if (!LoadShaders(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Initialize Print3D textures if (m_Print3D.SetTextures(NULL, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "Error: Cannot initialise Print3D.\n"); return false; } if (!m_pProceduralTextures->Init(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } if (!GenerateFnTexture()) { PVRShellSet(prefExitMessage, "Error: Failed to generate texture.\n"); return false; } glGenTextures(1, &m_ui32ColourSplineTexture); glBindTexture(GL_TEXTURE_2D, m_ui32ColourSplineTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, c_pszColourSplineData); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glBindTexture(GL_TEXTURE_2D, 0); return true; }
Texture::Texture(const CPVRTString& strFilename) { PVR_Texture_Header sOldHeader; if(PVRTTextureLoadFromPVR(strFilename.c_str(),(GLuint*)&m_u32Handle,&sOldHeader) == PVR_SUCCESS) { m_strFilename = strFilename; m_bIsCubeMap = (sOldHeader.dwpfFlags&PVRTEX_CUBEMAP)!=0; } else { ConsoleLog::inst().log("PVREngine::Texture: Could not load texture.\n"); return; } }
/*!**************************************************************************** @Function LoadTextures @Output pErrorStr A CPVRTString describing the error on failure @Return bool true if no error occured @Description Loads the textures required for this training course ******************************************************************************/ bool OGLES3ShadowMapping::LoadTextures(CPVRTString* const pszErrorStr) { for (unsigned int i=0; i < c_uiNumTextureNames; i++) { // Check if the texture already exists in the map if(m_TextureCache.Exists(c_sTextureNames[i])) continue; CPVRTString filename = c_sTextureNames[i].String() + CPVRTString(".pvr"); // Texture is not loaded. Load and add to the map. GLuint uiHandle; PVRTextureHeaderV3 sHeader; if(PVRTTextureLoadFromPVR(filename.c_str(), &uiHandle, &sHeader) != PVR_SUCCESS) { *pszErrorStr = CPVRTString("Failed to load texture: ") + filename; return false; } m_TextureCache[c_sTextureNames[i]] = uiHandle; } return true; }
/******************************************************************************* * Function Name : InitView * Returns : true if no error occured * Description : Code in InitView() will be called by the Shell upon a change * in the rendering context. * Used to initialize variables that are dependant on the rendering * context (e.g. textures, vertex buffers, etc.) *******************************************************************************/ bool OGLESSkinning::InitView() { CPVRTString error; // Check to see whether the matrix palette extension is supported. if(!CPVRTglesExt::IsGLExtensionSupported("GL_OES_matrix_palette")) { PVRShellSet(prefExitMessage, "ERROR: The extension GL_OES_matrix_palette is unsupported.\n"); return false; } // Initialise the matrix palette extensions m_Extensions.LoadExtensions(); // Load the textures if(!LoadTextures(&error)) { PVRShellSet(prefExitMessage, error.c_str()); return false; } // Init Print3D to display text on screen 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; } // Model View Matrix CameraGetMatrix(); // Projection Matrix glMatrixMode(GL_PROJECTION); glLoadMatrixf(m_mProjection.f); // GENERIC RENDER STATES // Enables Depth Testing glEnable(GL_DEPTH_TEST); // Enables Smooth Colour Shading glShadeModel(GL_SMOOTH); // Enable texturing glEnable(GL_TEXTURE_2D); // Define front faces glFrontFace(GL_CW); // Enables texture clamping glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); // Reset the model view matrix to position the light glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Setup ambiant light glEnable(GL_LIGHTING); PVRTVec4 lightGlobalAmbient = PVRTVec4(1.0f, 1.0f, 1.0f, 1.0f); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lightGlobalAmbient.ptr()); // Setup a directional light source PVRTVec4 lightPosition = PVRTVec4(-0.7f, -1.0f, 0.2f, 0.0f); PVRTVec4 lightAmbient = PVRTVec4(1.0f, 1.0f, 1.0f, 1.0f); PVRTVec4 lightDiffuse = PVRTVec4(1.0f, 1.0f, 1.0f, 1.0f); PVRTVec4 lightSpecular = PVRTVec4(0.2f, 0.2f, 0.2f, 1.0f); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition.ptr()); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient.ptr()); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse.ptr()); glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular.ptr()); LoadVbos(); /* Initialise an array to lookup the textures for each material in the scene. */ m_puiTextures = new GLuint[m_Scene.nNumMaterial]; for(unsigned int i = 0; i < m_Scene.nNumMaterial; ++i) { m_puiTextures[i] = m_uiLegTex; SPODMaterial* pMaterial = &m_Scene.pMaterial[i]; if(strcmp(pMaterial->pszName, "Mat_body") == 0) { m_puiTextures[i] = m_uiBodyTex; } else if(strcmp(pMaterial->pszName, "Mat_legs") == 0) { m_puiTextures[i] = m_uiLegTex; } else if(strcmp(pMaterial->pszName, "Mat_belt") == 0) { m_puiTextures[i] = m_uiBeltTex; } } 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 OGLES3Refraction::InitView() { CPVRTString ErrorStr; /* Initialize VBO data */ LoadVbos(); /* 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; } // Set the sampler2D uniforms to corresponding texture units glUniform1i(glGetUniformLocation(m_ShaderProgram.uiId, "sTexture"), 0); // Is the screen rotated? m_bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); /* Initialize Print3D */ if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), m_bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n"); return false; } /* Initalise the background */ if(m_Background.Init(0, m_bRotate, &ErrorStr) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } /* Calculate the projection and view matrices */ m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PI/6, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), CAM_NEAR, CAM_FAR, PVRTMat4::OGL, m_bRotate); m_mView = PVRTMat4::LookAtRH(PVRTVec3(0, 0, 150), PVRTVec3(0, 0, 0), PVRTVec3(0, 1, 0)); /* Set OpenGL ES render states needed for this training course */ // Use a nice bright blue as clear colour glClearColor(0.6f, 0.8f, 1.0f, 1.0f); return true; }