/*!**************************************************************************** @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 OGLES2PVRScopeRemote::InitApplication() { // We want a data connection to PVRPerfServer { m_psSPSCommsData = pplInitialise("PVRScopeRemote", 14); m_bCommsError = false; // Demonstrate that there is a good chance of the initial data being // lost - the connection is normally completed asynchronously. pplSendMark(m_psSPSCommsData, "lost", static_cast<unsigned int>(strlen("lost"))); // This is entirely optional. Wait for the connection to succeed, it will // timeout if e.g. PVRPerfServer is not running. int nBoolConnected; pplWaitForConnection(m_psSPSCommsData, &nBoolConnected, 1, 200); } CPPLProcessingScoped PPLProcessingScoped(m_psSPSCommsData, __FUNCTION__, static_cast<unsigned int>(strlen(__FUNCTION__)), m_i32FrameCounter); // set thickness variation of the film m_fMaxVariation = 100.0f; // set the minimum thickness of the film m_fMinThickness = 100.0f; m_puiVbo = 0; m_puiIndexVbo = 0; m_i32FrameCounter = 0; m_i32Frame10Counter = 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)); // Load the scene if (m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n"); return false; } // set angle of rotation m_fAngleY = 0.0f; /* Remotely editable library items */ if(m_psSPSCommsData) { SSPSCommsLibraryItem asItems[8]; unsigned int nItemCount = 0; /* Want editable shaders */ CPVRTResourceFile FragShaderFile(c_szFragShaderSrcFile); CPVRTResourceFile VertShaderFile(c_szVertShaderSrcFile); struct SLibList { const char * const pszName; const CPVRTResourceFile * const pFile; } aShaders[2] = { { c_szFragShaderSrcFile, &FragShaderFile }, { c_szVertShaderSrcFile, &VertShaderFile } }; for(unsigned int i = 0; i < sizeof(aShaders) / sizeof(*aShaders); ++i) { if(aShaders[i].pFile->IsOpen()) { asItems[nItemCount].pszName = aShaders[i].pszName; asItems[nItemCount].nNameLength = (unsigned int)strlen(aShaders[i].pszName); asItems[nItemCount].eType = eSPSCommsLibTypeString; asItems[nItemCount].pData = (const char*)aShaders[i].pFile->DataPtr(); asItems[nItemCount].nDataLength = (unsigned int)aShaders[i].pFile->Size(); ++nItemCount; } } // Want editable: min thickness m_sCommsLibMinThickness.fCurrent = m_fMinThickness; m_sCommsLibMinThickness.fMin = 0.0f; m_sCommsLibMinThickness.fMax = 500.0f; asItems[nItemCount].pszName = "min thickness"; asItems[nItemCount].nNameLength = (unsigned int)strlen(asItems[nItemCount].pszName); asItems[nItemCount].eType = eSPSCommsLibTypeFloat; asItems[nItemCount].pData = (const char*)&m_sCommsLibMinThickness; asItems[nItemCount].nDataLength = sizeof(m_sCommsLibMinThickness); ++nItemCount; // Want editable: max variation m_sCommsLibMaxVariation.fCurrent = m_fMaxVariation; m_sCommsLibMaxVariation.fMin = 50.0f; m_sCommsLibMaxVariation.fMax = 150.0f; asItems[nItemCount].pszName = "max variation"; asItems[nItemCount].nNameLength = (unsigned int)strlen(asItems[nItemCount].pszName); asItems[nItemCount].eType = eSPSCommsLibTypeFloat; asItems[nItemCount].pData = (const char*)&m_sCommsLibMaxVariation; asItems[nItemCount].nDataLength = sizeof(m_sCommsLibMaxVariation); ++nItemCount; _ASSERT(nItemCount < sizeof(asItems) / sizeof(*asItems)); /* Ok, submit our library */ if(!pplLibraryCreate(m_psSPSCommsData, asItems, nItemCount)) { PVRShellOutputDebug("PVRScopeRemote: pplLibraryCreate() failed\n"); } } /* User defined counters */ if(m_psSPSCommsData) { SSPSCommsCounterDef asDefs[eCounterNum]; for(unsigned int i = 0; i < eCounterNum; ++i) { asDefs[i].pszName = c_apszDefs[i]; asDefs[i].nNameLength = (unsigned int)strlen(c_apszDefs[i]); } if(!pplCountersCreate(m_psSPSCommsData, asDefs, eCounterNum)) { PVRShellOutputDebug("PVRScopeRemote: pplCountersCreate() failed\n"); } } 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 OGLES2PVRScopeRemote::InitView() { CPPLProcessingScoped PPLProcessingScoped(m_psSPSCommsData, __FUNCTION__, static_cast<unsigned int>(strlen(__FUNCTION__)), m_i32FrameCounter); CPVRTString ErrorStr; /* Initialize VBO data */ LoadVbos(); /* Load textures */ if (!LoadTextures(&ErrorStr)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Take our initial vert shader source { CPVRTResourceFile VertShaderFile(c_szVertShaderSrcFile); m_pszVertShader = new char[VertShaderFile.Size() + 1]; strncpy(m_pszVertShader, (char*)VertShaderFile.DataPtr(), VertShaderFile.Size()); m_pszVertShader[VertShaderFile.Size()] = 0; } // Take our initial frag shader source { CPVRTResourceFile FragShaderFile(c_szFragShaderSrcFile); m_pszFragShader = new char[FragShaderFile.Size() + 1]; strncpy(m_pszFragShader, (char*)FragShaderFile.DataPtr(), FragShaderFile.Size()); m_pszFragShader[FragShaderFile.Size()] = 0; } /* Load and compile the shaders & link programs */ if (!LoadShaders(&ErrorStr, m_pszFragShader, m_pszVertShader)) { PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Is the screen rotated? bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); /* Initialize Print3D */ if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n"); 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, bRotate); m_mView = PVRTMat4::LookAtRH(PVRTVec3(0, 0, 75), PVRTVec3(0, 0, 0), PVRTVec3(0, 1, 0)); /* 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 OGLES2PVRScopeRemote::InitApplication() { // set thickness variation of the film m_fMaxVariation = 100.0f; // set the minimum thickness of the film m_fMinThickness = 100.0f; m_puiVbo = 0; m_puiIndexVbo = 0; m_i32FrameCounter = 0; m_i32Frame10Counter = 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)); // Load the scene if (m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n"); return false; } // set angle of rotation m_fAngleY = 0.0f; // We want a data connection to PVRPerfServer m_psSPSCommsData = pplInitialise("PVRScopeRemote", 14); /* Remotely editable library items */ if(m_psSPSCommsData) { SSPSCommsLibraryItem asItems[8]; unsigned int nItemCount = 0; /* Want editable shaders */ CPVRTResourceFile FragShaderFile(c_szFragShaderSrcFile); CPVRTResourceFile VertShaderFile(c_szVertShaderSrcFile); struct SLibList { const char * const pszName; const CPVRTResourceFile * const pFile; } aShaders[2] = { { c_szFragShaderSrcFile, &FragShaderFile }, { c_szVertShaderSrcFile, &VertShaderFile } }; for(unsigned int i = 0; i < sizeof(aShaders) / sizeof(*aShaders); ++i) { if(aShaders[i].pFile->IsOpen()) { asItems[nItemCount].pszName = aShaders[i].pszName; asItems[nItemCount].nNameLength = (unsigned int)strlen(aShaders[i].pszName); asItems[nItemCount].eType = eSPSCommsLibTypeString; asItems[nItemCount].pData = (const char*)aShaders[i].pFile->DataPtr(); asItems[nItemCount].nDataLength = (unsigned int)aShaders[i].pFile->Size(); ++nItemCount; } } // Want editable: min thickness m_sCommsLibMinThickness.fCurrent = m_fMinThickness; m_sCommsLibMinThickness.fMin = 0.0f; m_sCommsLibMinThickness.fMax = 500.0f; asItems[nItemCount].pszName = "min thickness"; asItems[nItemCount].nNameLength = (unsigned int)strlen(asItems[nItemCount].pszName); asItems[nItemCount].eType = eSPSCommsLibTypeFloat; asItems[nItemCount].pData = (const char*)&m_sCommsLibMinThickness; asItems[nItemCount].nDataLength = sizeof(m_sCommsLibMinThickness); ++nItemCount; // Want editable: max variation m_sCommsLibMaxVariation.fCurrent = m_fMaxVariation; m_sCommsLibMaxVariation.fMin = 50.0f; m_sCommsLibMaxVariation.fMax = 150.0f; asItems[nItemCount].pszName = "max variation"; asItems[nItemCount].nNameLength = (unsigned int)strlen(asItems[nItemCount].pszName); asItems[nItemCount].eType = eSPSCommsLibTypeFloat; asItems[nItemCount].pData = (const char*)&m_sCommsLibMaxVariation; asItems[nItemCount].nDataLength = sizeof(m_sCommsLibMaxVariation); ++nItemCount; /* Ok, submit our library */ if(!pplLibraryCreate(*m_psSPSCommsData, asItems, nItemCount)) { PVRShellOutputDebug("PVRScopeRemote: pplLibraryCreate() failed\n"); } } /* User defined counters */ { SSPSCommsCounterDef asDefs[eCounterNum]; for(unsigned int i = 0; i < eCounterNum; ++i) { asDefs[i].pszName = c_apszDefs[i]; asDefs[i].nNameLength = (unsigned int)strlen(c_apszDefs[i]); } if(!pplCountersCreate(*m_psSPSCommsData, asDefs, eCounterNum)) { PVRShellOutputDebug("PVRScopeRemote: pplCountersCreate() failed\n"); } } return true; }