uint32_t cShaderObject::GetSubroutineInstance(eShaderType type, cStringRef name) { uint32_t ret = glGetSubroutineIndex(mShaderProgram, GLShaderType(type), name.data()); AKJ_ASSERT_AND_THROW(ret != GL_INVALID_INDEX); return ret; }
Option<core::uint> ShaderCompiler::compile(const boost::container::set<std::string>& flags) { auto it = _shader.find(flags); if(it != _shader.end()) return Option<core::uint>(it->second); std::string finalSource=_source; size_t pos = finalSource.find("#version"); pos = finalSource.find("\n", pos); std::string defineStat; for(auto it=flags.begin() ; it != flags.end() ; ++it) defineStat += "#define "+*it+"\n"; defineStat += getBuiltInDefine(); if(pos != std::string::npos) finalSource.insert(pos+1, defineStat); core::uint id = glCreateShader(GLShaderType(_shaderType)); const GLchar* gchar = (const GLchar*)finalSource.c_str(); glShaderSource(id, 1, &gchar, NULL); glCompileShader(id); int compileStatus = GL_TRUE; glGetShaderiv(id, GL_COMPILE_STATUS, &compileStatus); if(compileStatus != GL_TRUE) { _lastError="Compiling with:"; for(auto it=flags.begin() ; it != flags.end() ; ++it) _lastError += *it +" "; _lastError += "\n"; logError(id); glDeleteShader(id); return Option<core::uint>(); } _shader[flags] = id; return Option<core::uint>(id); }
bool GLShader::LoadShader(const GLchar* source) { GLenum type = GLShaderType(m_info.type); if (type == GL_NONE) { DebugPrintF(VTEXT("Failed to Load Shader due to invalid type\n")); return false; } /*create shader object*/ m_shader = glCreateShader(type); /*put shader source into memory*/ glShaderSource(m_shader, 1, &source, NULL); /*cleanup allocated source*/ /*compile shader*/ glCompileShader(m_shader); return ValidateCompile(m_shader); }