/*!**************************************************************************** @Function LoadTextures @Output pErrorStr A string describing the error on failure @Return bool true if no error occured @Description Loads the textures required for this training course ******************************************************************************/ bool OGLESVase::LoadTextures(CPVRTString* const pErrorStr) { if(PVRTTextureLoadFromPVR(c_szBackgroundTexFile, &m_uiBackTex) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture ") + c_szBackgroundTexFile; return false; } myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szFloraTexFile, &m_uiFloraTex) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture ") + c_szFloraTexFile; return false; } myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szReflectionTexFile, &m_uiReflectTex) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture ") + c_szReflectionTexFile; return false; } myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); myglTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); return true; }
/*!**************************************************************************** @Function LoadTextures @Output pErrorStr A string describing the error on failure @Return bool true if no error occured @Description Loads the textures required for this training course ******************************************************************************/ bool OGLES2ChameleonMan::LoadTextures(CPVRTString* const pErrorStr) { // Load Textures if(PVRTTextureLoadFromPVR(c_szFinalChameleonManHeadBodyTexFile, &m_ui32TexHeadBody) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture for Upper Body.\n"); return false; } if(PVRTTextureLoadFromPVR(c_szFinalChameleonManLegsTexFile, &m_ui32TexLegs) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture for Legs.\n"); return false; } if(PVRTTextureLoadFromPVR(c_szTang_space_BodyMapTexFile, &m_ui32TexHeadNormalMap) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load normalmap texture for Upper Body.\n"); return false; } if(PVRTTextureLoadFromPVR(c_szTang_space_LegsMapTexFile, &m_ui32TexLegsNormalMap) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load normalmap texture for Legs.\n"); return false; } if(PVRTTextureLoadFromPVR(c_szTang_space_BeltMapTexFile, &m_ui32TexBeltNormalMap) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load normalmap texture for Belt.\n"); return false; } if(PVRTTextureLoadFromPVR(c_szSkylineTexFile, &m_ui32TexSkyLine) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture for SkyLine.\n"); return false; } if(PVRTTextureLoadFromPVR(c_szWallDiffuseBakedTexFile, &m_ui32TexWall) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture for Wall.\n"); return false; } if(PVRTTextureLoadFromPVR(c_szLampTexFile, &m_ui32TexLamp) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture for Lamps.\n"); return false; } if(PVRTTextureLoadFromPVR(c_szChameleonBeltTexFile, &m_ui32TexBelt) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture for Belt.\n"); return false; } return true; }
/*!**************************************************************************** @Function LoadTextures @Output pErrorStr A string describing the error on failure @Return bool true if no error occured @Description Loads the textures required for this training course ******************************************************************************/ bool OGLESPolybump::LoadTextures(CPVRTString* const pErrorStr) { // Load Textures /* First we check for support of the GL_IMG_texture_format_BGRA8888 extension to determine which normal map to use. If it is supported then we will be using the BGRA format that is 32bits per pixel avoiding any artefacts related to compression. When using a normal map any artefacts present will be clearly visible as they will affect the normal directions. If the extension is unsupported we will be using the PVRTC compressed version. In general for performance using a 32bit texture is not recommended but in the case of a normal map maximum quality is required. */ m_bBGRASupported = CPVRTglesExt::IsGLExtensionSupported("GL_IMG_texture_format_BGRA8888"); if(m_bBGRASupported) { if(PVRTTextureLoadFromPVR(c_szHeadCloneSpaceBGRATexFile, &m_ui32CloneMap) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture ") + c_szHeadCloneSpaceBGRATexFile; return false; } m_pDescription = &c_szDescriptionBGRA[0]; } else { if(PVRTTextureLoadFromPVR(c_szHeadCloneSpacePVRTCTexFile, &m_ui32CloneMap) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture ") + c_szHeadCloneSpacePVRTCTexFile; return false; } m_pDescription = &c_szDescriptionPVRTC[0]; } glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szHeadDiffuseTexFile, &m_ui32DiffuseMap) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture ") + c_szHeadDiffuseTexFile; return false; } glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 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 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 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 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; }
bool ParticleSystemGPU::CompileComputeShader(CPVRTString& errorStr) { CPVRTArray<char> defines("WORKGROUP_SIZE ", 30); sprintf(&defines[15], "%d", m_ui32WorkgroupSize); char* defines_buffer = &defines[0]; if (m_glComputeShader) { glDeleteShader(m_glComputeShader); m_glComputeShader = 0; } if (m_glProgram) { glDeleteProgram(m_glProgram); m_glProgram = 0; } if (PVRTShaderLoadFromFile(c_szComputeShaderBinFile, c_szComputeShaderSrcFile, GL_COMPUTE_SHADER, GL_SGX_BINARY_IMG, &m_glComputeShader, &errorStr, &m_PVRTContext, &defines_buffer, 1) != PVR_SUCCESS) { errorStr = "Particle Compute Shader : " + errorStr; return false; } m_glProgram = glCreateProgram(); glAttachShader(m_glProgram, m_glComputeShader); glLinkProgram(m_glProgram); GLint Linked; glGetProgramiv(m_glProgram, GL_LINK_STATUS, &Linked); if (!Linked) { int i32InfoLogLength, i32CharsWritten; glGetProgramiv(m_glProgram, GL_INFO_LOG_LENGTH, &i32InfoLogLength); char* pszInfoLog = new char[i32InfoLogLength]; glGetProgramInfoLog(m_glProgram, i32InfoLogLength, &i32CharsWritten, pszInfoLog); errorStr = CPVRTString("Failed to link compute shader:: ") + pszInfoLog + "\n"; delete [] pszInfoLog; return false; } return true; }
/*!*************************************************************************** @Function LoadTextures @Input pErrorStr @Return bool @Description Loads all of the required textures. *****************************************************************************/ bool OGLES3Skybox2::LoadTextures(CPVRTString* const pErrorStr) { for(int i = 0; i < 3; ++i) { if(PVRTTextureLoadFromPVR(g_aszTextureNames[i], &m_ui32TextureIDs[i]) != PVR_SUCCESS) return false; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } // Load cube maps for(int i = 3; i < 5; ++i) { if(PVRTTextureLoadFromPVR(g_aszTextureNames[i], &m_ui32TextureIDs[i])) { *pErrorStr = CPVRTString("ERROR: Could not open texture file ") + g_aszTextureNames[i]; return false; } glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } 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 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; }
// --------------------------------------------------------------- bool MyPVRDemo::LoadTextures(CPVRTString* const pErrorStr) { ASSERT(ELEMENTS_IN_ARRAY(c_pszTextures) == enumTEXTURE_MAX); // Load Textures from PVR files for(int i = 0; i < enumTEXTURE_MAX; ++i) { if(PVRTTextureLoadFromPVR(c_pszTextures[i], &m_tex[i]) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Could not load: ") + CPVRTString(c_pszTextures[i]); return false; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } // Set some options glBindTexture(GL_TEXTURE_2D, m_tex[enumTEXTURE_BloomMap]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Allocate a texture for the RTT glGenTextures(enumFB_MAX, m_uiRTT); for(int i = 0; i < enumFB_MAX; i++) { glBindTexture(GL_TEXTURE_2D, m_uiRTT[i]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, RTT_SIZE, RTT_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } // Allocate a texture for the shadow map glGenTextures(1, &m_uiShadowMapTex); glBindTexture(GL_TEXTURE_2D, m_uiShadowMapTex); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); return true; }
/*!*************************************************************************** @Function ParseFromFile @Input pszFileName PFX file name @Output pReturnError error string @Return EPVRTError PVR_SUCCESS for success parsing file PVR_FAIL if file doesn't exist or is invalid @Description Reads the PFX file and calls the parser. *****************************************************************************/ EPVRTError CPVRTPFXParser::ParseFromFile(const char * const pszFileName, CPVRTString * const pReturnError) { CPVRTResourceFile PfxFile(pszFileName); if (!PfxFile.IsOpen()) { *pReturnError = CPVRTString("Unable to open file ") + pszFileName; return PVR_FAIL; } return ParseFromMemory(PfxFile.StringPtr(), pReturnError); }
/*!**************************************************************************** @Function LoadTextures @Output pErrorStr A string describing the error on failure @Return bool true if no error occured @Description Loads the textures required for this training course ******************************************************************************/ bool OGLESLighting::LoadTextures(CPVRTString* const pErrorStr) { if(PVRTTextureLoadFromPVR(c_szStoneTexFile, &m_ui32Stone) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture ") + c_szStoneTexFile; return false; } glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szLightTexFile, &m_ui32Light) != PVR_SUCCESS) { *pErrorStr = CPVRTString("ERROR: Failed to load texture ") + c_szLightTexFile; return false; } glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); return true; }
/*!**************************************************************************** @Function LoadTextures @Return bool true for success, false for failure @Description Loads the textures. ******************************************************************************/ bool OGLESFur::LoadTextures(CPVRTString* const pErrorStr) { // Load the textures. // For a detailed explanation see the Texturing training course. if(PVRTTextureLoadFromPVR(c_szBridgeTexFile, &m_aTexIDs[eTexBridge]) != PVR_SUCCESS) { *pErrorStr = "ERROR: Failed to load " + CPVRTString(c_szBridgeTexFile); return false; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szGrassTexFile, &m_aTexIDs[eTexGrass]) != PVR_SUCCESS) { *pErrorStr = "ERROR: Failed to load " + CPVRTString(c_szGrassTexFile); return false; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szWaterTexFile, &m_aTexIDs[eTexWater]) != PVR_SUCCESS) { *pErrorStr = "ERROR: Failed to load " + CPVRTString(c_szWaterTexFile); return false; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szSkinTexFile, &m_aTexIDs[eTexSkin]) != PVR_SUCCESS) { *pErrorStr = "ERROR: Failed to load " + CPVRTString(c_szSkinTexFile); return false; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szFurTexFile, &m_aTexIDs[eTexFur]) != PVR_SUCCESS) { *pErrorStr = "ERROR: Failed to load " + CPVRTString(c_szFurTexFile); return false; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if(PVRTTextureLoadFromPVR(c_szCloudTexFile, &m_aTexIDs[eTexCloud]) != PVR_SUCCESS) { *pErrorStr = "ERROR: Failed to load " + CPVRTString(c_szCloudTexFile); return false; } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); return true; }
/*!*************************************************************************** @Function PVRTShaderLoadBinaryFromMemory @Input ShaderData shader compiled binary data @Input Size size of shader binary data in bytes @Input Type type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER) @Input Format shader binary format @Output pObject the resulting shader object @Output pReturnError the error message if it failed @Return PVR_SUCCESS on success and PVR_FAIL on failure (also fills the str string) @Description Takes a shader binary from memory and passes it to the GL. *****************************************************************************/ EPVRTError PVRTShaderLoadBinaryFromMemory( const void* const ShaderData, const size_t Size, const GLenum Type, const GLenum Format, GLuint* const pObject, CPVRTString* const pReturnError) { /* Create and compile the shader object */ *pObject = glCreateShader(Type); // Get the list of supported binary formats // and if (more then 0) find given Format among them GLint numFormats = 0; GLint *listFormats; int i; glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS,&numFormats); if(numFormats != 0) { listFormats = new GLint[numFormats]; for(i=0;i<numFormats;++i) listFormats[i] = 0; glGetIntegerv(GL_SHADER_BINARY_FORMATS,listFormats); for(i=0;i<numFormats;++i) { if(listFormats[i] == (int) Format) { glShaderBinary(1, pObject, Format, ShaderData, (GLint)Size); if (glGetError() != GL_NO_ERROR) { *pReturnError = CPVRTString("Failed to load binary shader\n"); glDeleteShader(*pObject); return PVR_FAIL; } return PVR_SUCCESS; } } delete [] listFormats; } *pReturnError = CPVRTString("Failed to load binary shader\n"); glDeleteShader(*pObject); return PVR_FAIL; }
/*!**************************************************************************** @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 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; }
bool OGLESCoverflow::LoadTextures(CPVRTString* const pErrorStr) { for(int i = 0; i < g_i32CoverNo ; ++i) { if(PVRTTextureLoadFromPVR(g_Covers[i].pTextureName, &g_Covers[i].ui32TexID) != PVR_SUCCESS) { *pErrorStr = "Failed to load '" + CPVRTString(g_Covers[i].pTextureName) + "'."; return false; } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } } return true; }
/*!*************************************************************************** @Function PVRTCreateProgram @Output pProgramObject the created program object @Input VertexShader the vertex shader to link @Input FragmentShader the fragment shader to link @Input pszAttribs an array of attribute names @Input i32NumAttribs the number of attributes to bind @Output pReturnError the error message if it failed @Returns PVR_SUCCESS on success, PVR_FAIL if failure @Description Links a shader program. *****************************************************************************/ EPVRTError PVRTCreateProgram( GLuint* const pProgramObject, const GLuint VertexShader, const GLuint FragmentShader, const char** const pszAttribs, const int i32NumAttribs, CPVRTString* const pReturnError) { *pProgramObject = glCreateProgram(); glAttachShader(*pProgramObject, FragmentShader); glAttachShader(*pProgramObject, VertexShader); for (int i = 0; i < i32NumAttribs; ++i) { glBindAttribLocation(*pProgramObject, i, pszAttribs[i]); } // Link the program object glLinkProgram(*pProgramObject); GLint Linked; glGetProgramiv(*pProgramObject, GL_LINK_STATUS, &Linked); if (!Linked) { int i32InfoLogLength, i32CharsWritten; glGetProgramiv(*pProgramObject, GL_INFO_LOG_LENGTH, &i32InfoLogLength); char* pszInfoLog = new char[i32InfoLogLength]; glGetProgramInfoLog(*pProgramObject, i32InfoLogLength, &i32CharsWritten, pszInfoLog); *pReturnError = CPVRTString("Failed to link: ") + pszInfoLog + "\n"; delete [] pszInfoLog; return PVR_FAIL; } glUseProgram(*pProgramObject); return PVR_SUCCESS; }
/*!*********************************************************************** @Function + @Input _Left A string @Input _Right A string @Returns An updated string @Description + Operator *************************************************************************/ CPVRTString operator+ (const char _Left, const CPVRTString& _Right) { return CPVRTString(_Left).append(_Right); }
/*!*********************************************************************** @Function substr @Input _Off Start of the substring @Input _Count Length of the substring @Returns A substring of the string @Description Returns the size of the string *************************************************************************/ CPVRTString CPVRTString::substr(size_t _Off, size_t _Count) const { return CPVRTString(*this, _Off, _Count); }
/*!*************************************************************************** @Function GetReadPath @Returns The currently set read path @Description Returns the currently set read path *****************************************************************************/ CPVRTString CPVRTResourceFile::GetReadPath() { return CPVRTString(s_ReadPath); }
/*!*************************************************************************** @Function Init @Input pContext A pointer to a PVRTContext @Input bRotate true to rotate texture 90 degrees. @Input pszError An option string for returning errors @Return PVR_SUCCESS on success @Description Initialises the background *****************************************************************************/ EPVRTError CPVRTBackground::Init(const SPVRTContext * const pContext, bool bRotate, CPVRTString *pszError) { Destroy(); m_pAPI = new SPVRTBackgroundAPI; if(!m_pAPI) { if(pszError) *pszError = "Error: Insufficient memory to allocate SCPVRTBackgroundAPI."; return PVR_FAIL; } m_pAPI->m_ui32VertexShader = 0; m_pAPI->m_ui32FragShader = 0; m_pAPI->m_ui32ProgramObject = 0; m_pAPI->m_ui32VertexBufferObject = 0; bool bResult; CPVRTString sTmpErrStr; // The shader loading code doesn't expect a null pointer for the error string if(!pszError) pszError = &sTmpErrStr; /* Compiles the shaders. For a more detailed explanation, see IntroducingPVRTools */ // Try binary shaders first bResult = (PVRTShaderLoadBinaryFromMemory(_BackgroundFragShader_fsc, _BackgroundFragShader_fsc_size, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_pAPI->m_ui32FragShader, pszError) == PVR_SUCCESS) && (PVRTShaderLoadBinaryFromMemory(_BackgroundVertShader_vsc, _BackgroundVertShader_vsc_size, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_pAPI->m_ui32VertexShader, pszError) == PVR_SUCCESS); if(!bResult) { // if binary shaders don't work, try source shaders bResult = (PVRTShaderLoadSourceFromMemory(_BackgroundFragShader_fsh, GL_FRAGMENT_SHADER, &m_pAPI->m_ui32FragShader, pszError) == PVR_SUCCESS) && (PVRTShaderLoadSourceFromMemory(_BackgroundVertShader_vsh, GL_VERTEX_SHADER, &m_pAPI->m_ui32VertexShader, pszError) == PVR_SUCCESS); } _ASSERT(bResult); if(!bResult) return PVR_FAIL; // Reset the error string if(pszError) *pszError = ""; // Create the shader program m_pAPI->m_ui32ProgramObject = glCreateProgram(); // Attach the fragment and vertex shaders to it glAttachShader(m_pAPI->m_ui32ProgramObject, m_pAPI->m_ui32FragShader); glAttachShader(m_pAPI->m_ui32ProgramObject, m_pAPI->m_ui32VertexShader); // Bind the custom vertex attribute "myVertex" to location VERTEX_ARRAY glBindAttribLocation(m_pAPI->m_ui32ProgramObject, VERTEX_ARRAY, "myVertex"); // Bind the custom vertex attribute "myUV" to location TEXCOORD_ARRAY glBindAttribLocation(m_pAPI->m_ui32ProgramObject, TEXCOORD_ARRAY, "myUV"); // Link the program glLinkProgram(m_pAPI->m_ui32ProgramObject); GLint Linked; glGetProgramiv(m_pAPI->m_ui32ProgramObject, GL_LINK_STATUS, &Linked); if (!Linked) { int i32InfoLogLength, i32CharsWritten; glGetProgramiv(m_pAPI->m_ui32ProgramObject, GL_INFO_LOG_LENGTH, &i32InfoLogLength); char* pszInfoLog = new char[i32InfoLogLength]; glGetProgramInfoLog(m_pAPI->m_ui32ProgramObject, i32InfoLogLength, &i32CharsWritten, pszInfoLog); *pszError = CPVRTString("Failed to link: ") + pszInfoLog + "\n"; delete [] pszInfoLog; bResult = false; } _ASSERT(bResult); if(!bResult) return PVR_FAIL; // Use the loaded shader program glUseProgram(m_pAPI->m_ui32ProgramObject); // Set the sampler2D variable to the first texture unit glUniform1i(glGetUniformLocation(m_pAPI->m_ui32ProgramObject, "sampler2d"), 0); // Create the vertex buffer object GLfloat *pVertexData = 0; // The vertex data for non-rotated GLfloat afVertexData[16] = { -1, -1, 1, -1, -1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1}; // The vertex data for rotated GLfloat afVertexDataRotated[16] = {-1, 1, -1, -1, 1, 1, 1, -1, 1, 1, 0, 1, 1, 0, 0, 0}; if(!bRotate) pVertexData = &afVertexData[0]; else pVertexData = &afVertexDataRotated[0]; glGenBuffers(1, &m_pAPI->m_ui32VertexBufferObject); glBindBuffer(GL_ARRAY_BUFFER, m_pAPI->m_ui32VertexBufferObject); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 16, pVertexData, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); m_bInit = true; return PVR_SUCCESS; }
/*!**************************************************************************** @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 dependent on it (e.g. external modules, loading meshes, etc.) If the rendering context is lost, InitApplication() will not be called again. ******************************************************************************/ bool OGLESPVRScopeRemote::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_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)); /* 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; } /* Remotely editable library items */ if(m_psSPSCommsData) { SSPSCommsLibraryItem asItems[8]; unsigned int nItemCount = 0; // 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 ParseSemantic @Output semantic semantic data object @Input nStartLine start line number @Input nEndLine end line number @Output pReturnError error string @Return bool true if parse is successful @Description Parses a semantic. *****************************************************************************/ bool CPVRTPFXParser::ParseSemantic(SPVRTPFXParserSemantic &semantic, const int nStartLine, const int nEndLine, CPVRTString * const pReturnError) { char *str; semantic.pszName = 0; semantic.pszValue = 0; semantic.sDefaultValue.eType = eDataTypeNone; semantic.nIdx = 0; str = strtok (NULL, " "); if(str == NULL) { sprintf(errorMsg, "UNIFORM missing name in [EFFECT] on line %d\n", m_psContext->pnFileLineNumber[nStartLine]); *pReturnError = errorMsg; return false; } semantic.pszName = (char*)malloc((strlen(str)+1) * sizeof(char)); strcpy(semantic.pszName, str); str = strtok (NULL, " "); if(str == NULL) { sprintf(errorMsg, "UNIFORM missing value in [EFFECT] on line %d\n", m_psContext->pnFileLineNumber[nStartLine]); *pReturnError = errorMsg; FREE(semantic.pszName); return false; } /* If the final digits of the semantic are a number they are stripped off and used as the index, with the remainder used as the semantic. */ { size_t idx, len; len = strlen(str); idx = len; while(idx) { --idx; if(strcspn(&str[idx], "0123456789") != 0) { break; } } if(idx == 0) { sprintf(errorMsg, "Semantic contains only numbers in [EFFECT] on line %d\n", m_psContext->pnFileLineNumber[nStartLine]); *pReturnError = errorMsg; FREE(semantic.pszName); return false; } ++idx; // Store the semantic index if(len == idx) { semantic.nIdx = 0; } else { semantic.nIdx = atoi(&str[idx]); } // Chop off the index from the string containing the semantic str[idx] = 0; } // Store a copy of the semantic name semantic.pszValue = (char*)malloc((strlen(str)+1) * sizeof(char)); strcpy(semantic.pszValue, str); /* Optional default semantic value */ char pszString[2048]; strcpy(pszString,""); str = strtok (NULL, " "); if(str != NULL) { // Get all ramainning arguments while(str != NULL) { strcat(pszString, str); strcat(pszString, " "); str = strtok (NULL, " "); } // default value int i; for(i = 0; i < eNumDefaultDataTypes; i++) { if(strncmp(pszString, c_psSemanticDefaultDataTypeInfo[i].pszName, strlen(c_psSemanticDefaultDataTypeInfo[i].pszName)) == 0) { if(!GetSemanticDataFromString( &semantic.sDefaultValue, &pszString[strlen(c_psSemanticDefaultDataTypeInfo[i].pszName)], c_psSemanticDefaultDataTypeInfo[i].eType, pReturnError )) { sprintf(errorMsg, " on line %d.\n", m_psContext->pnFileLineNumber[nStartLine]); *pReturnError = *pReturnError + errorMsg; FREE(semantic.pszValue); FREE(semantic.pszName); return false; } semantic.sDefaultValue.eType = c_psSemanticDefaultDataTypeInfo[i].eType; break; } } // invalid data type if(i == eNumDefaultDataTypes) { sprintf(errorMsg, "'%s' unknown on line %d.\n", pszString, m_psContext->pnFileLineNumber[nStartLine]); *pReturnError = CPVRTString(errorMsg); FREE(semantic.pszValue); FREE(semantic.pszName); return false; } } return true; }
/*!*************************************************************************** @Function GetSemanticDataFromString @Output pDataItem @Modified pszArgumentString @Input eType @Output pError error message @Return true if successful @Description Extracts the semantic data from the string and stores it in the output SPVRTSemanticDefaultData parameter. *****************************************************************************/ bool GetSemanticDataFromString(SPVRTSemanticDefaultData *pDataItem, const char * const pszArgumentString, ESemanticDefaultDataType eType, CPVRTString *pError) { char *pszString = (char *)pszArgumentString; char *pszTmp; IgnoreWhitespace(&pszString); if(pszString[0] != '(') { *pError = CPVRTString("Missing '(' after ") + c_psSemanticDefaultDataTypeInfo[eType].pszName; return false; } pszString++; IgnoreWhitespace(&pszString); if(!strlen(pszString)) { *pError = c_psSemanticDefaultDataTypeInfo[eType].pszName + CPVRTString(" missing arguments"); return false; } pszTmp = pszString; switch(c_psSemanticDefaultDataTypeInfo[eType].eInternalType) { case eFloating: pDataItem->pfData[0] = (float)strtod(pszString, &pszTmp); break; case eInteger: pDataItem->pnData[0] = (int)strtol(pszString, &pszTmp, 10); break; case eBoolean: if(strncmp(pszString, "true", 4) == 0) { pDataItem->pbData[0] = true; pszTmp = &pszString[4]; } else if(strncmp(pszString, "false", 5) == 0) { pDataItem->pbData[0] = false; pszTmp = &pszString[5]; } break; } if(pszString == pszTmp) { size_t n = strcspn(pszString, ",\t "); char *pszError = (char *)malloc(n + 1); strcpy(pszError, ""); strncat(pszError, pszString, n); *pError = CPVRTString("'") + pszError + "' unexpected for " + c_psSemanticDefaultDataTypeInfo[eType].pszName; FREE(pszError); return false; } pszString = pszTmp; IgnoreWhitespace(&pszString); for(unsigned int i = 1; i < c_psSemanticDefaultDataTypeInfo[eType].nNumberDataItems; i++) { if(!strlen(pszString)) { *pError = c_psSemanticDefaultDataTypeInfo[eType].pszName + CPVRTString(" missing arguments"); return false; } if(pszString[0] != ',') { size_t n = strcspn(pszString, ",\t "); char *pszError = (char *)malloc(n + 1); strcpy(pszError, ""); strncat(pszError, pszString, n); *pError = CPVRTString("'") + pszError + "' unexpected for " + c_psSemanticDefaultDataTypeInfo[eType].pszName; FREE(pszError); return false; } pszString++; IgnoreWhitespace(&pszString); if(!strlen(pszString)) { *pError = c_psSemanticDefaultDataTypeInfo[eType].pszName + CPVRTString(" missing arguments"); return false; } pszTmp = pszString; switch(c_psSemanticDefaultDataTypeInfo[eType].eInternalType) { case eFloating: pDataItem->pfData[i] = (float)strtod(pszString, &pszTmp); break; case eInteger: pDataItem->pnData[i] = (int)strtol(pszString, &pszTmp, 10); break; case eBoolean: if(strncmp(pszString, "true", 4) == 0) { pDataItem->pbData[i] = true; pszTmp = &pszString[4]; } else if(strncmp(pszString, "false", 5) == 0) { pDataItem->pbData[i] = false; pszTmp = &pszString[5]; } break; } if(pszString == pszTmp) { size_t n = strcspn(pszString, ",\t "); char *pszError = (char *)malloc(n + 1); strcpy(pszError, ""); strncat(pszError, pszString, n); *pError = CPVRTString("'") + pszError + "' unexpected for " + c_psSemanticDefaultDataTypeInfo[eType].pszName; FREE(pszError); return false; } pszString = pszTmp; IgnoreWhitespace(&pszString); } if(pszString[0] != ')') { size_t n = strcspn(pszString, "\t )"); char *pszError = (char *)malloc(n + 1); strcpy(pszError, ""); strncat(pszError, pszString, n); *pError = CPVRTString("'") + pszError + "' found when expecting ')' for " + c_psSemanticDefaultDataTypeInfo[eType].pszName; FREE(pszError); return false; } pszString++; IgnoreWhitespace(&pszString); if(strlen(pszString)) { *pError = CPVRTString("'") + pszString + "' unexpected after ')'"; 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 OGLES2Shaders::InitView() { // Is the screen rotated bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); /* Initialize Print3D textures */ if (m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS) { PVRShellOutputDebug("ERROR: Cannot initialise Print3D\n"); return false; } glClearColor(0.6f, 0.8f, 1.0f, 1.0f); m_mProjection = PVRTMat4::PerspectiveFovRH(PVRT_PI/6, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), CAM_NEAR, CAM_FAR, PVRTMat4::OGL, bRotate); m_mView = PVRTMat4::Identity(); /* Loads the textures. */ // Textures // Get pointer to the texture name CPVRTString ErrorStr; char *pTexture = 0; PVRTextureHeaderV3 Header; for(int i = 0; i < g_numTextures; ++i) { if(strcmp(g_TextureList[i], "base") == 0) pTexture = (char*) g_aszTextureNames[eTexBase]; else if(strcmp(g_TextureList[i], "reflection") == 0) pTexture = (char*) g_aszTextureNames[eTexReflection]; else if(strcmp(g_TextureList[i], "cubemap") == 0) pTexture = (char*) g_aszTextureNames[eTexCubeMap]; else if(strcmp(g_TextureList[i], "anisotropicmap") == 0) pTexture = (char*) g_aszTextureNames[eTexAnisotropic]; if(PVRTTextureLoadFromPVR(pTexture, &m_puiTextureHandle[i], &Header) != PVR_SUCCESS) { ErrorStr = CPVRTString("ERROR: Could not open texture file ") + pTexture; PVRShellSet(prefExitMessage, ErrorStr.c_str()); return false; } // Get texture flags form the header m_uiTextureFlags[i] = (Header.u32NumFaces==6?PVRTEX_CUBEMAP:0) | (Header.u32MIPMapCount>1?PVRTEX_MIPMAP:0) | (Header.u32Depth>1?PVRTEX_VOLUME:0); } /* Load the effect file */ for(int j = 0; j < g_numShaders; j++) { CPVRTString fileName; unsigned int nUnknownUniformCount; CPVRTString error; /* Parse the file */ m_ppEffectParser[j] = new CPVRTPFXParser(); fileName = CPVRTString(g_ShaderList[j]) + ".pfx"; if(m_ppEffectParser[j]->ParseFromFile(fileName.c_str(), &error) != PVR_SUCCESS) { error = CPVRTString("Parse failed for ") + fileName + ":\n\n" + error; PVRShellSet(prefExitMessage, error.c_str()); FreeMemory(); return false; } /* Load the effect from the file */ error = ""; m_ppEffect[j] = new CPVRTPFXEffect(); if(m_ppEffect[j]->Load(*(m_ppEffectParser[j]), "myEffect", fileName.c_str(), NULL, nUnknownUniformCount, &error) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, error.c_str()); FreeMemory(); return false; } if(nUnknownUniformCount) { error = PVRTStringFromFormattedStr("PFX File: %s\n%s Unknown uniform semantic count: %d\n", fileName.c_str(), error.c_str(), nUnknownUniformCount); PVRShellSet(prefExitMessage, error.c_str()); FreeMemory(); return false; } if(!error.empty()) { PVRShellOutputDebug(error.c_str()); } /* Link the textrues to the effect. */ const CPVRTArray<SPVRTPFXTexture>& sTex = m_ppEffect[j]->GetTextureArray(); // Loop over textures used in the CPVRTPFXEffect for(unsigned int i = 0; i < sTex.GetSize(); ++i) { int iTexIdx = m_ppEffectParser[j]->FindTextureByName(sTex[i].Name); const CPVRTStringHash& FileName = m_ppEffectParser[j]->GetTexture(iTexIdx)->FileName; int k; // Loop over available textures for( k = 0; k < g_numTextures; k++) { CPVRTString texName; texName = CPVRTString(g_TextureList[k]) + ".pvr"; if(FileName == texName) { // Set the current texture if((m_uiTextureFlags[k] & CUBEMAP_FLAG) != 0) glBindTexture(GL_TEXTURE_CUBE_MAP, m_puiTextureHandle[k]); else glBindTexture(GL_TEXTURE_2D, m_puiTextureHandle[k]); // Link the texture to the CPVRTPFXEffect and apply filtering m_ppEffect[j]->SetTexture(i, m_puiTextureHandle[k], m_uiTextureFlags[k]); break; } } if(k == g_numTextures) { // Texture not found PVRShellOutputDebug("Warning: effect file requested unrecognised texture: \"%s\"\n", FileName.c_str()); m_ppEffect[j]->SetTexture(i, 0); } } } glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); // Create the surface m_Surface = new ParametricSurface(50,50); ComputeSurface(m_nCurrentSurface); return true; }
/*!**************************************************************************** @Function LoadShaders @Output pErrorStr A string describing the error on failure @Return bool true if no error occured @Description Loads and compiles the shaders and links the shader programs required for this training course ******************************************************************************/ bool OGLES2AnisotropicLighting::LoadShaders(CPVRTString* pErrorStr) { /* Load and compile the shaders from files. Binary shaders are tried first, source shaders are used as fallback. */ if (PVRTShaderLoadFromFile(c_szFastVsBinFile, c_szFastVsSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiFastVertShader, pErrorStr) != PVR_SUCCESS) { *pErrorStr = CPVRTString("From file '") + c_szFastVsBinFile + "' or '" + c_szFastVsSrcFile + "':\n" + *pErrorStr; PVRShellSet(prefExitMessage, pErrorStr->c_str()); return false; } if (PVRTShaderLoadFromFile(c_szFastFsBinFile, c_szFastFsSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFastFragShader, pErrorStr) != PVR_SUCCESS) { *pErrorStr = CPVRTString("From file '") + c_szFastVsBinFile + "' or '" + c_szFastVsSrcFile + "':\n" + *pErrorStr; PVRShellSet(prefExitMessage, pErrorStr->c_str()); return false; } if (PVRTShaderLoadFromFile(c_szSlowVsBinFile, c_szSlowVsSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiSlowVertShader, pErrorStr) != PVR_SUCCESS) { *pErrorStr = CPVRTString("From file '") + c_szFastVsBinFile + "' or '" + c_szFastVsSrcFile + "':\n" + *pErrorStr; PVRShellSet(prefExitMessage, pErrorStr->c_str()); return false; } if (PVRTShaderLoadFromFile(c_szSlowFsBinFile, c_szSlowFsSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiSlowFragShader, pErrorStr) != PVR_SUCCESS) { *pErrorStr = CPVRTString("From file '") + c_szFastVsBinFile + "' or '" + c_szFastVsSrcFile + "':\n" + *pErrorStr; PVRShellSet(prefExitMessage, pErrorStr->c_str()); return false; } /* Set up and link the shader programs */ const char* aszAttribs[] = { "inVertex", "inNormal" }; if ( (PVRTCreateProgram(&m_FastShader.uiId, m_uiFastVertShader, m_uiFastFragShader, aszAttribs, 2, pErrorStr) != PVR_SUCCESS) || (PVRTCreateProgram(&m_SlowShader.uiId, m_uiSlowVertShader, m_uiSlowFragShader, aszAttribs, 2, pErrorStr) != PVR_SUCCESS) ) { PVRShellSet(prefExitMessage, pErrorStr->c_str()); return false; } /* Store the location of uniforms for later use */ m_FastShader.uiMVPMatrixLoc = glGetUniformLocation(m_FastShader.uiId, "MVPMatrix"); m_FastShader.uiMsLightDirLoc = glGetUniformLocation(m_FastShader.uiId, "msLightDir"); m_FastShader.uiMsEyePosLoc = glGetUniformLocation(m_FastShader.uiId, "msEyePos"); m_SlowShader.uiMVPMatrixLoc = glGetUniformLocation(m_SlowShader.uiId, "MVPMatrix"); m_SlowShader.uiMsLightDirLoc = glGetUniformLocation(m_SlowShader.uiId, "msLightDir"); m_SlowShader.uiMsEyeDirLoc = glGetUniformLocation(m_SlowShader.uiId, "msEyeDir"); return true; }
CPVRTString OptionInt::getDisplayValue() { char pszInt[20]; sprintf(pszInt,"%d",m_i32CurrentValue); return CPVRTString(pszInt); }