void GLSLProgram::getMicrocodeFromCache(uint32 id) { GpuProgramManager::Microcode cacheMicrocode = GpuProgramManager::getSingleton().getMicrocodeFromCache(id); cacheMicrocode->seek(0); // Turns out we need this param when loading. GLenum binaryFormat = 0; cacheMicrocode->read(&binaryFormat, sizeof(GLenum)); // Get size of binary. GLint binaryLength = static_cast<GLint>(cacheMicrocode->size() - sizeof(GLenum)); // Load binary. OGRE_CHECK_GL_ERROR(glProgramBinary(mGLProgramHandle, binaryFormat, cacheMicrocode->getCurrentPtr(), binaryLength)); GLint success = 0; OGRE_CHECK_GL_ERROR(glGetProgramiv(mGLProgramHandle, GL_LINK_STATUS, &success)); if(success) { mLinked = true; return; } logObjectInfo("could not load from cache "+getCombinedName(), mGLProgramHandle); // Something must have changed since the program binaries // were cached away. Fallback to source shader loading path, // and then retrieve and cache new program binaries once again. compileAndLink(); }
//----------------------------------------------------------------------- void GLSLESLinkProgram::activate(void) { if (!mLinked && !mTriedToLinkAndFailed) { glGetError(); // Clean up the error. Otherwise will flood log. mGLHandle = glCreateProgram(); GL_CHECK_ERROR if ( GpuProgramManager::getSingleton().canGetCompiledShaderBuffer() && GpuProgramManager::getSingleton().isMicrocodeAvailableInCache(getCombinedName()) ) { getMicrocodeFromCache(); } else { #ifdef OGRE_USE_GLES2_GLSL_OPTIMISER // check CmdParams for each shader type to see if we should optimize String paramStr = mVertexProgram->getGLSLProgram()->getParameter("use_optimiser"); if((paramStr == "true") || paramStr.empty()) { GLSLESLinkProgramManager::getSingleton().optimiseShaderSource(mVertexProgram); } paramStr = mFragmentProgram->getGLSLProgram()->getParameter("use_optimiser"); if((paramStr == "true") || paramStr.empty()) { GLSLESLinkProgramManager::getSingleton().optimiseShaderSource(mFragmentProgram); } #endif compileAndLink(); } buildGLUniformReferences(); }
//----------------------------------------------------------------------- void GLSLESProgramPipeline::activate(void) { if (!mLinked && !mTriedToLinkAndFailed) { glGetError(); // Clean up the error. Otherwise will flood log. #if !OGRE_NO_GLES2_GLSL_OPTIMISER // Check CmdParams for each shader type to see if we should optimise if(mVertexProgram) { String paramStr = mVertexProgram->getGLSLProgram()->getParameter("use_optimiser"); if((paramStr == "true") || paramStr.empty()) { GLSLESProgramPipelineManager::getSingleton().optimiseShaderSource(mVertexProgram); } } if(mFragmentProgram) { String paramStr = mFragmentProgram->getGLSLProgram()->getParameter("use_optimiser"); if((paramStr == "true") || paramStr.empty()) { GLSLESProgramPipelineManager::getSingleton().optimiseShaderSource(mFragmentProgram); } } #endif compileAndLink(); extractLayoutQualifiers(); buildGLUniformReferences(); } _useProgram(); }
bool ShadowMapping::init() { if(!this->initGlew() || !this->initSetup()) return false; return compileAndLink( this->_shadowMappingProgram, this->_shadowMappingVert, this->_shadowMappingFrag, PluginManager::getBaseDirPath().append(QString("/shaders/decorate_shadow/sm/object"))); }
bool SSAO::init() { if(!this->initGlew() || !this->initSetup()) return false; if(!compileAndLink( this->_ssaoShaderProgram, this->_ssaoVert, this->_ssaoFrag, PluginManager::getBaseDirPath().append(QString("/shaders/decorate_shadow/ssao/ssao"))) || !compileAndLink( this->_normalMapShaderProgram, this->_normalMapVert, this->_normalMapFrag, PluginManager::getBaseDirPath().append(QString("/shaders/decorate_shadow/ssao/normalMap"))) || !compileAndLink( this->_blurShaderProgram, this->_blurVert, this->_blurFrag, PluginManager::getBaseDirPath().append(QString("/shaders/decorate_shadow/ssao/blur")))) return false; return true; }
void GLSLSeparableProgram::activate(void) { if (!mLinked && !mTriedToLinkAndFailed) { compileAndLink(); extractLayoutQualifiers(); buildGLUniformReferences(); } // _useProgram(); if (mLinked) { OGRE_CHECK_GL_ERROR(glBindProgramPipeline(mGLProgramPipelineHandle)); } }
//----------------------------------------------------------------------- void GLSLProgramPipeline::activate(void) { if (!mLinked && !mTriedToLinkAndFailed) { if ( GpuProgramManager::getSingleton().canGetCompiledShaderBuffer() && GpuProgramManager::getSingleton().isMicrocodeAvailableInCache(getCombinedName()) ) { getMicrocodeFromCache(); } else { compileAndLink(); } extractLayoutQualifiers(); buildGLUniformReferences(); } _useProgram(); }
//----------------------------------------------------------------------- void GLSLESProgramCommon::getMicrocodeFromCache(void) { GpuProgramManager::Microcode cacheMicrocode = GpuProgramManager::getSingleton().getMicrocodeFromCache(getCombinedName()); // add to the microcode to the cache String name; name = getCombinedName(); // turns out we need this param when loading GLenum binaryFormat = 0; cacheMicrocode->seek(0); // get size of binary cacheMicrocode->read(&binaryFormat, sizeof(GLenum)); if(getGLES2SupportRef()->checkExtension("GL_OES_get_program_binary") || gleswIsSupported(3, 0)) { GLint binaryLength = static_cast<GLint>(cacheMicrocode->size() - sizeof(GLenum)); // load binary OGRE_CHECK_GL_ERROR(glProgramBinaryOES(mGLProgramHandle, binaryFormat, cacheMicrocode->getPtr(), binaryLength)); } GLint success = 0; OGRE_CHECK_GL_ERROR(glGetProgramiv(mGLProgramHandle, GL_LINK_STATUS, &success)); if (!success) { // // Something must have changed since the program binaries // were cached away. Fallback to source shader loading path, // and then retrieve and cache new program binaries once again. // compileAndLink(); } }
void Shader::loadShader(const std::string &vertexShader, const std::string &fragmentShader) { const char *vs = textFileRead(vertexShader.c_str()); const char *fs = textFileRead(fragmentShader.c_str()); compileAndLink(vs,fs); }