/*----------------------------------------------------------------------------*/ GLint Shader::link() { GLint linked = oogl::ShaderProgram::link(); if (*getInfoLog() != 0) { // if info log not empty oogl::logEvent("Link status: %i, info log:\n%s", linked, getInfoLog()); } return linked; }
/*----------------------------------------------------------------------------*/ GLint ShaderUnit::compile() { GLint compiled = oogl::ShaderObject::compile(); if (*getInfoLog() != 0) { // if info log not empty oogl::logEvent("Compile status: %i, info log:\n\n%s", compiled, getInfoLog()); }/* else { oogl::logEvent("Compile status: %i", compiled); }*/ return compiled; }
bool GLSLShader::link() { int status; char *info_log; /*** link program object ***/ glLinkProgram( *m_program_object ); glGetProgramiv( *m_program_object, GL_OBJECT_LINK_STATUS_ARB, &status ); if( !status ) { CGoGNerr << "ERROR - GLSLShader::create() - error occured while linking shader program." << CGoGNendl; info_log = getInfoLog( *m_program_object ); CGoGNerr << " LINK " << info_log << CGoGNendl; delete [] info_log; glDetachShader( *m_program_object, *m_vertex_shader_object ); glDetachShader( *m_program_object, *m_fragment_shader_object ); if (*m_geom_shader_object) glDetachShader( *m_program_object, *m_geom_shader_object ); glDeleteShader( *m_program_object ); *m_program_object = 0; return false; } return true; }
void GlShaderProgram::link() { bool allShaderCompiled = true; for (size_t i = 0 ; i < attachedShaders.size() ; ++i) { if (!attachedShaders[i]->isCompiled()) { allShaderCompiled = false; } if (attachedShaders[i]->getShaderType() == Geometry) { glProgramParameteriEXT(programObjectId, GL_GEOMETRY_INPUT_TYPE_EXT, attachedShaders[i]->getInputPrimitiveType()); glProgramParameteriEXT(programObjectId, GL_GEOMETRY_OUTPUT_TYPE_EXT, attachedShaders[i]->getOutputPrimitiveType()); GLint maxOutputVertices = maxGeometryShaderOutputVertices; if (maxOutputVertices == 0) glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT, &maxOutputVertices); glProgramParameteriEXT(programObjectId, GL_GEOMETRY_VERTICES_OUT_EXT, maxOutputVertices); } } glLinkProgram(programObjectId); getInfoLog(programObjectId, PROGRAM, programLinkLog); GLint linked; glGetProgramiv(programObjectId, GL_LINK_STATUS, &linked); programLinked = allShaderCompiled && linked > 0; }
GlShaderBlinnShadowMap() { std::string infoLog; initVertFragShadersFromDirectory("shader_blinn_shadow_map"); attachFragShader(SHADER_GLSL_DEFAULT_DIR"shader_blinn/fragment_shader_skeleton.glsl"); // link programs if (!link()) { std::string infoLog; getInfoLog(infoLog); std::cerr << "info Log: during linking: " << infoLog << std::endl; return; } setupUniform(texture0_enabled, "texture0_enabled"); setupUniform(shadow_map_matrix_uniform, "shadow_map_matrix"); use(); setUniform1i("texture0", 0); setUniform1i("texture_shadow_map", 1); disable(); initBlinnSkeleton(*this); }
CrossCompiler::Spirv CrossCompiler::hlslToSpirv(std::string hlslText) { auto program = glslang::TProgram(); auto entryPoints = getEntryPoints(hlslText); for (auto& stageEntries : entryPoints) { auto stage = toEShLanguage(stageEntries.first); for (auto name : stageEntries.second) { addShader(program, hlslText, stage, name); } } if (!program.link(messagesType)) throw std::exception(program.getInfoLog()); Spirv spirv; if (entryPoints["vs"].size() > 0) spirv.vs = getBinary(program, EShLanguage::EShLangVertex); if (entryPoints["ps"].size() > 0) spirv.ps = getBinary(program, EShLanguage::EShLangFragment); return spirv; }
void GlShader::compileShaderObject(const char *shaderSrc) { glShaderSource(shaderObjectId, 1,(const char **) &shaderSrc, NULL); glCompileShader(shaderObjectId); GLint compileStatus; glGetShaderiv(shaderObjectId, GL_COMPILE_STATUS, &compileStatus); shaderCompiled = compileStatus > 0; getInfoLog(shaderObjectId, SHADER, compilationLog); }
void PlainShaderProgram::init() { Commons::Render::ShaderPtr vs(new Commons::Render::Shader(GL_VERTEX_SHADER)); vs->setSource(VERTEX_SHADER); LOG_INFO("Compiling plain vertex shader..."); bool isCompiled = vs->compile(); std::string log; vs->getInfoLog(log); WriteShaderLog(log); if (!isCompiled) throw Commons::GLException("Can't compile vertex shader. See log for details"); Commons::Render::ShaderPtr fs(new Commons::Render::Shader(GL_FRAGMENT_SHADER)); fs->setSource(FRAGMENT_SHADER); isCompiled = fs->compile(); fs->getInfoLog(log); WriteShaderLog(log); if (!isCompiled) throw Commons::GLException("Can't compile fragment shader. See log for details"); // Link attach(fs); attach(vs); bool isLinked = link(); getInfoLog(log); WriteShaderLog(log); if (!isLinked) throw Commons::GLException("Can't link shader program. See log for details"); bool isValidated = validate(); getInfoLog(log); WriteShaderLog(log); if (!isValidated) throw Commons::GLException("Can't validate shader program. See log for details"); //uint32_t a = m_shader->getNumAttributes(); //uint32_t un = m_shader->getNumUniforms(); // TODO: helpers... m_uMVP = getUniformLocation("m_MVP"); m_uTex1 = getUniformLocation("u_tex1"); setUniformSampler2D(m_uTex1, 0); }
/*----------------------------------------------------------------------------*/ void Shader::use() { #ifndef NDEBUG if (!validate()) { oogl::logEvent("Failed to validate Shader#%u.\nInfo log:\n%s", getHandle(), getInfoLog()); assert(false); // abort! } #endif oogl::ShaderProgram::use(); }
void GLSLProgram::link() { LOG_DEBUG << "linking program" << std::endl; GLint status; glLinkProgram(prog); glGetProgramiv(prog, GL_LINK_STATUS, &status); if (!status) { std::string log = "can't link program: " + getInfoLog(prog); LOG_ERROR << log << std::endl; throw std::runtime_error(log); } else { LOG_DEBUG << "linked program - no errors" << std::endl; } }
void gle::Program::link() { GLint status; glLinkProgram(_id); GLenum error = glGetError(); if (error == GL_INVALID_OPERATION) throw new gle::Exception::InvalidOperation("Cannot link the program"); else if (error != GL_NO_ERROR) throw new gle::Exception::OpenGLError(); glGetProgramiv(_id, GL_LINK_STATUS, &status); if (status != GL_TRUE) throw new gle::Exception::LinkageError(getInfoLog()); }
void addShader(glslang::TProgram& program, std::string& hlslText, EShLanguage stage, std::string entryPointName) { auto shader = new glslang::TShader(stage); const char * text = hlslText.c_str(); shader->setStrings(&text, 1); shader->setEntryPoint(entryPointName.c_str()); program.addShader(shader); if (!shader->parse(&DefaultResources, defaultVersion, false, messagesType)) { throw std::exception(shader->getInfoLog()); } }
GlShaderTexturize() { if (!initVertFragShadersFromDirectory("shader_texturize")) return; if (!link()) { std::string infoLog; getInfoLog(infoLog); std::cerr << "info Log: linking: " << infoLog << std::endl; return; } setupUniform(pvm_matrix_uniform, "pvm_matrix"); }
void Shader::compile() { GLint res; glCompileShader( _obj ); glGetShaderiv( _obj, GL_COMPILE_STATUS, &res ); if (res != GL_TRUE) { CLOG(getInfoLog()); _compiled = false; } else { _compiled = true; } assert(res == GL_TRUE); }
CShaderBathymetry() { std::string infoLog; initVertFragShadersFromDirectory("shader_bathymetry"); attachFragShader(SHADER_GLSL_DEFAULT_DIR"shader_blinn/fragment_shader_skeleton.glsl"); // link programs link(); if (error()) { std::string infoLog; getInfoLog(infoLog); std::cerr << "info Log: during linking: " << infoLog << std::endl; return; } initBlinnSkeleton(*this); }
void Program::link() //[]----------------------------------------------------[] //| Link | //[]----------------------------------------------------[] { // Link program glLinkProgram(handle); GLint ok; // Get link status glGetProgramiv(handle, GL_LINK_STATUS, &ok); if (ok == GL_TRUE) state = BUILT; else { string log = getInfoLog(handle, glGetProgramiv, glGetProgramInfoLog); error(LINK_ERROR, getName(), log.c_str()); } }
void Shader::compile() //[]----------------------------------------------------[] //| Compile | //[]----------------------------------------------------[] { // Compile shader glCompileShader(handle); GLint ok; // Get compile status glGetShaderiv(handle, GL_COMPILE_STATUS, &ok); if (ok == GL_TRUE) compiled = true; else { string log = getInfoLog(handle, glGetShaderiv, glGetShaderInfoLog); error(COMPILE_ERROR, getName(), log.c_str()); } }
GlShaderBlinn() { std::string infoLog; initVertFragShadersFromDirectory("shader_blinn"); attachFragShader(SHADER_GLSL_DEFAULT_DIR"shader_blinn/fragment_shader_skeleton.glsl"); // link programs if (!link()) { std::string infoLog; getInfoLog(infoLog); std::cerr << "info Log: during linking: " << infoLog << std::endl; return; } setupUniform(texture0_enabled, "texture0_enabled"); setupUniform(vertex_color, "vertex_color"); initBlinnSkeleton(*this); }
/** * link compiled shaders */ bool link() { glLinkProgram(program); CGlErrorCheck(); GLint status; glGetProgramiv(program, GL_LINK_STATUS, &status); if (status == GL_TRUE) return true; std::cerr << getInfoLog() << std::endl; error = true; for (CGlShader &s : shaders) { std::cerr << " Shader filename: " << s.filename << std::endl; error = true; } return false; }
GLShaderHeightColorBlinn() { std::string infoLog; initVertFragShadersFromDirectory("shader_height_color_blinn"); attachFragShader(SHADER_GLSL_DEFAULT_DIR"shader_blinn/fragment_shader_skeleton.glsl"); // link programs if (!link()) { std::string infoLog; getInfoLog(infoLog); std::cerr << "info Log: during linking: " << infoLog << std::endl; return; } setupUniform(height_color_scale, "height_color_scale"); setupUniform(height_color_offset, "height_color_offset"); initBlinnSkeleton(*this); setupColorScaleAndOffset(); }
void Program::debugLog() const { std::string program_log = getInfoLog(); if(program_log.size() > 0) { LOG("ShaderLog: %s", &program_log[0]); } }
bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimitive, int nb_max_vertices) { int status; char* info_log; if (nb_max_vertices != -1) m_nbMaxVertices = nb_max_vertices; m_geom_inputPrimitives = inputGeometryPrimitive; m_geom_outputPrimitives = outputGeometryPrimitive; /*** check if shaders are loaded ***/ if( !*m_vertex_shader_object || !*m_fragment_shader_object ) { CGoGNerr << "ERROR - GLSLShader::create() - shaders are not defined." << CGoGNendl; return false; } /*** create program object ***/ m_program_object = glCreateProgram(); if( !*m_program_object ) { CGoGNerr << "ERROR - GLSLShader::create() - unable to create program object." << CGoGNendl; return false; } /*** attach shaders to program object ***/ glAttachShader( *m_program_object, *m_vertex_shader_object ); glAttachShader( *m_program_object, *m_fragment_shader_object ); if (*m_geom_shader_object) { glAttachShader( *m_program_object, *m_geom_shader_object ); if (CURRENT_OGL_VERSION == 2) { glProgramParameteriEXT(*m_program_object, GL_GEOMETRY_INPUT_TYPE_EXT, inputGeometryPrimitive); glProgramParameteriEXT(*m_program_object, GL_GEOMETRY_OUTPUT_TYPE_EXT, outputGeometryPrimitive); glProgramParameteriEXT(*m_program_object, GL_GEOMETRY_VERTICES_OUT_EXT, m_nbMaxVertices); } } /*** link program object ***/ glLinkProgram( *m_program_object ); glGetProgramiv( *m_program_object, GL_LINK_STATUS, &status ); if( !status ) { CGoGNerr << "ERROR - GLSLShader::create() - error occured while linking shader program." << CGoGNendl; info_log = getInfoLog( *m_program_object ); CGoGNerr << " LINK " << info_log << CGoGNendl; delete [] info_log; glDetachShader( *m_program_object, *m_vertex_shader_object ); glDetachShader( *m_program_object, *m_fragment_shader_object ); if (*m_geom_shader_object) glDetachShader( *m_program_object, *m_geom_shader_object ); glDeleteShader( *m_program_object ); *m_program_object = 0; return false; } *m_uniMat_Proj = glGetUniformLocation(*m_program_object, "ProjectionMatrix"); *m_uniMat_Model = glGetUniformLocation(*m_program_object, "ModelViewMatrix"); *m_uniMat_ModelProj = glGetUniformLocation(*m_program_object, "ModelViewProjectionMatrix"); *m_uniMat_Normal = glGetUniformLocation(*m_program_object, "NormalMatrix"); return true; }
/** Retrieves compilation info log for a shader object with GLES id * @param shader_id. * * @param shader_id GLES id of a shader object to retrieve compilation * info log for. * * @return String instance containing the log. **/ std::string TestCaseBase::getCompilationInfoLog(glw::GLuint shader_id) { return getInfoLog(LT_SHADER_OBJECT, shader_id); }
/** Retrieves linking info log for a program object with GLES id * @param po_id. * * @param po_id GLES id of a program object to retrieve linking * info log for. * * @return String instance containing the log. **/ std::string TestCaseBase::getLinkingInfoLog(glw::GLuint po_id) { return getInfoLog(LT_PROGRAM_OBJECT, po_id); }
/** Retrieves linking info log for a pipeline object with GLES id * @param ppo_id. * * @param ppo_id GLES id of a pipeline object to retrieve validation * info log for. * * @return String instance containing the log. **/ std::string TestCaseBase::getPipelineInfoLog(glw::GLuint ppo_id) { return getInfoLog(LT_PIPELINE_OBJECT, ppo_id); }