bool CTechnique::Finialise() { GLint success = 0; GLchar errorLog[1024] = { 0 }; glLinkProgram(m_shaderProg); glGetProgramiv(m_shaderProg, GL_LINK_STATUS, &success); if (success == 0) { glGetProgramInfoLog(m_shaderProg, sizeof(errorLog), NULL, errorLog); OutputDebugString(errorLog); return false; } glValidateProgram(m_shaderProg); glGetProgramiv(m_shaderProg, GL_VALIDATE_STATUS, &success); if (!success) { glGetProgramInfoLog(m_shaderProg, sizeof(errorLog), NULL, errorLog); OutputDebugString(errorLog); return false; } for (auto it = m_shaderObjList.begin(); it != m_shaderObjList.end(); it++) glDeleteShader(*it); m_shaderObjList.clear(); return true; }
static void set_shader_source(wip24_state* state, const char* source) { GLuint frag = glCreateShader(GL_FRAGMENT_SHADER); const char* sources[2] = {source_header, source}; glShaderSource(frag, 2, sources, NULL); glCompileShader(frag); GLint status; glGetShaderiv(frag, GL_COMPILE_STATUS, &status); if (!status) { char log[1024]; glGetShaderInfoLog(frag, sizeof(log), NULL, log); log_entry("Error: Unable to compile shader: %s\n", log); glDeleteShader(frag); return; } state->program = glCreateProgram(); glAttachShader(state->program, frag); glLinkProgram(state->program); glValidateProgram(state->program); glDeleteShader(frag); glGetProgramiv(state->program, GL_LINK_STATUS, &status); if (!status) { char log[1024]; glGetProgramInfoLog(state->program, sizeof(log), NULL, log); log_entry("Error: Unable to link program: %s\n", log); glDeleteProgram(state->program); state->program = 0; return; } }
// // Initialise les shader & program object // bool EsgiShader::Create() { // Cree le program object m_ProgramObject = glCreateProgram(); if (m_ProgramObject == 0) { return false; } if (m_VertexShader) { glAttachShader(m_ProgramObject, m_VertexShader); } if (m_FragmentShader) { glAttachShader(m_ProgramObject, m_FragmentShader); } // Liage des shaders dans le programme glLinkProgram(m_ProgramObject); GLint linked = 0; GLint infoLen = 0; // verification du statut du linkage glGetProgramiv(m_ProgramObject, GL_LINK_STATUS, &linked); if (!linked) { glGetProgramiv(m_ProgramObject, GL_INFO_LOG_LENGTH, &infoLen); if (infoLen > 1) { char* infoLog = (char *)malloc(sizeof(char) * infoLen); glGetProgramInfoLog(m_ProgramObject, infoLen, NULL, infoLog); printf("Erreur de lien du programme:\n%s\n", infoLog); free(infoLog); } glDeleteProgram(m_ProgramObject); return false; } glValidateProgram(m_ProgramObject); glGetProgramiv(m_ProgramObject, GL_INFO_LOG_LENGTH, &infoLen); if (infoLen > 1) { char* infoLog = (char *)malloc(sizeof(char) * infoLen); glGetProgramInfoLog(m_ProgramObject, infoLen, NULL, infoLog); printf("Resultat de la validation du programme:\n%s\n", infoLog); free(infoLog); } return true; }
void Shader::linkProgram(std::vector<GLuint> shaderIDs) { glLinkProgram(m_ProgramID); glValidateProgram(m_ProgramID); for (GLuint id : shaderIDs) { glDeleteShader(id); } LOG(Success, "Shader", "ID: %d", m_ProgramID); }
void ShaderData::CompileShader() const { glLinkProgram(m_program); CheckShaderError(m_program, GL_LINK_STATUS, true, "Error linking shader program"); glValidateProgram(m_program); CheckShaderError(m_program, GL_VALIDATE_STATUS, true, "Invalid shader program"); }
bool gfx::ShaderProgram::Validate() { glValidateProgram ( m_Handle ); GLint status; glGetProgramiv ( m_Handle, GL_VALIDATE_STATUS, &status ); m_Validated = ( status == GL_TRUE ); return m_Validated; }
void ProgramValidate(GLint program){ glValidateProgram(program); if (GLGET(Program,program,GL_VALIDATE_STATUS) == GL_TRUE) return; THROW_RT_ERR( std::string("Could not validate program - Error: ") +ProgramInfoLog(program) ); }
GLuint Shader::Load() { GLuint program = glCreateProgram(); GLuint vertex = glCreateShader(GL_VERTEX_SHADER); GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER); std::string vertString = FileUtil::Read_File(m_vertpath); std::string fragString = FileUtil::Read_File(m_fragpath); const char* vertSource = vertString.c_str(); const char* fragSource = fragString.c_str(); glShaderSource(vertex, 1, &vertSource, NULL); glCompileShader(vertex); GLint result; glGetShaderiv(vertex, GL_COMPILE_STATUS, &result); if (result == GL_FALSE) { GLint length; glGetShaderiv(vertex, GL_INFO_LOG_LENGTH, &length); std::vector<char> log(length); glGetShaderInfoLog(vertex, length, &length, &log[0]); std::cout << "Failed to compile Vertex Shader" << std::endl << &log[0] << std::endl; glDeleteShader(vertex); return 0; } glShaderSource(fragment, 1, &fragSource, NULL); glCompileShader(fragment); glGetShaderiv(fragment, GL_COMPILE_STATUS, &result); if (result == GL_FALSE) { GLint length; glGetShaderiv(fragment, GL_INFO_LOG_LENGTH, &length); std::vector<char> log(length); glGetShaderInfoLog(fragment, length, &length, &log[0]); std::cout << "Failed to compile Fragment Shader" << std::endl << &log[0] << std::endl; glDeleteShader(fragment); return 0; } glAttachShader(program, vertex); glAttachShader(program, fragment); glLinkProgram(program); glValidateProgram(program); glDeleteShader(vertex); glDeleteShader(fragment); return program; }
//////////////////////////////////init//////////////////////////////////////// void Shader::init() { GLuint program = glCreateProgram(); GLuint vertex = glCreateShader(GL_VERTEX_SHADER); GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER); std::string vertSourceString = FileUtils::ReadFile(m_VertPath); std::string fragSourceString = FileUtils::ReadFile(m_FragPath); const char* vertSource = vertSourceString.c_str(); const char* fragSource = fragSourceString.c_str(); glShaderSource(vertex, 1, &vertSource, NULL); glCompileShader(vertex); // ±àÒë GLint result; glGetShaderiv(vertex, GL_COMPILE_STATUS, &result); if (result == GL_FALSE) // ²¶»ñ±àÒë´íÎóÐÅÏ¢ { GLint length; glGetShaderiv(vertex, GL_INFO_LOG_LENGTH, &length); std::vector<char> error(length); glGetShaderInfoLog(vertex, length, &length, &error[0]); // log("error compile vertex shader"); // log(&error[0]); glDeleteShader(vertex); return; } glShaderSource(fragment, 1, &fragSource, NULL); glCompileShader(fragment); // ±àÒë glGetShaderiv(fragment, GL_COMPILE_STATUS, &result); if (result == GL_FALSE) // ²¶»ñ±àÒë´íÎóÐÅÏ¢ { GLint length; glGetShaderiv(fragment, GL_INFO_LOG_LENGTH, &length); std::vector<char> error(length); glGetShaderInfoLog(fragment, length, &length, &error[0]); // log("error compile fragment shader"); // log(&error[0]); glDeleteShader(fragment); return; } // attach glAttachShader(program, vertex); glAttachShader(program, fragment); // link glLinkProgram(program); glValidateProgram(program); // delete glDeleteShader(vertex); glDeleteShader(fragment); m_ShaderID = program; }
// // Validate // bool CShadingProgram::Validate() const { glValidateProgram( m_Program ); GLint ValidateStatus; glGetProgramiv( m_Program, GL_VALIDATE_STATUS, &ValidateStatus ); return ValidateStatus == GL_TRUE; }
/** * return state of program (true, if program can be used) */ inline bool validate() { glValidateProgram(program); GLint status; glGetProgramiv(1, GL_VALIDATE_STATUS, &status); return status == GL_TRUE; }
bool TGLProgram::Validate() const { int status=GL_FALSE; glValidateProgram(hObject); glGetProgramiv(hObject, GL_VALIDATE_STATUS, &status); if (status != GL_TRUE) LogFile->Write(Format("Some shader validate error"), LT_ERROR); return true; }
static DFBBoolean init_program(GLuint prog_obj, char *vert_prog_name, const char *vert_prog_src, char *frag_prog_name, const char *frag_prog_src, DFBBoolean texcoords) { char *log; GLint status, log_length, char_count; if (!init_shader(prog_obj, vert_prog_src, GL_VERTEX_SHADER)) { D_ERROR("GLES2/Driver: %s failed to compile!\n", vert_prog_name); return DFB_FALSE; } if (!init_shader(prog_obj, frag_prog_src, GL_FRAGMENT_SHADER)) { D_ERROR("GLES2/Driver: %s failed to compile!\n", frag_prog_name); return DFB_FALSE; } // Bind vertex positions to "dfbPos" vertex attribute slot. glBindAttribLocation(prog_obj, GLES2VA_POSITIONS, "dfbPos"); if (texcoords) // Bind vertex texture coords to "dfbUV" vertex attribute slot. glBindAttribLocation(prog_obj, GLES2VA_TEXCOORDS, "dfbUV"); // Link the program object and check for errors. glLinkProgram(prog_obj); glValidateProgram(prog_obj); glGetProgramiv(prog_obj, GL_LINK_STATUS, &status); if (status) { // Don't need the shader objects anymore. GLuint shaders[2]; GLsizei shader_count; glGetAttachedShaders(prog_obj, 2, &shader_count, shaders); glDetachShader(prog_obj, shaders[0]); glDetachShader(prog_obj, shaders[1]); return DFB_TRUE; } else { // Report errors. Shader objects detached when program is deleted. glGetProgramiv(prog_obj, GL_INFO_LOG_LENGTH, &log_length); log = D_MALLOC(log_length); glGetProgramInfoLog(prog_obj, log_length, &char_count, log); D_ERROR("GLES2/Driver: shader program link failure:\n%s\n", log); D_FREE(log); return DFB_FALSE; } glUseProgram( prog_obj ); }
// Called to draw scene void RenderScene(void) { // Track camera angle glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (windowWidth > windowHeight) { GLdouble ar = (GLdouble)windowWidth / (GLdouble)windowHeight; glFrustum(-ar * cameraZoom, ar * cameraZoom, -cameraZoom, cameraZoom, 1.0, 1000.0); } else { GLdouble ar = (GLdouble)windowHeight / (GLdouble)windowWidth; glFrustum(-cameraZoom, cameraZoom, -ar * cameraZoom, ar * cameraZoom, 1.0, 1000.0); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(cameraPos[0], cameraPos[1], cameraPos[2], 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glViewport(0, 0, windowWidth, windowHeight); glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Validate our shader before first use if (needsValidation[whichShader]) { GLint success; glValidateProgram(progObj[whichShader]); glGetProgramiv(progObj[whichShader], GL_VALIDATE_STATUS, &success); if (!success) { GLchar infoLog[MAX_INFO_LOG_SIZE]; glGetProgramInfoLog(progObj[whichShader], MAX_INFO_LOG_SIZE, NULL, infoLog); fprintf(stderr, "Error in program #%d validation!\n", whichShader); fprintf(stderr, "Info log: %s\n", infoLog); Sleep(10000); exit(0); } needsValidation[whichShader] = GL_FALSE; } // Draw objects in the scene DrawModels(); if (glGetError() != GL_NO_ERROR) fprintf(stderr, "GL Error!\n"); // Flush drawing commands glutSwapBuffers(); }
GLuint setupShaders(char * vertexfile, char * fragmentfile, GLuint * program) { char *vs = NULL,*fs = NULL,*fs2 = NULL; vertexShader = glCreateShader(GL_VERTEX_SHADER); fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); if(vertexShader == 0 || fragmentShader == 0) std::cout << " Error with glCreateShader" << std::endl; vs = textFileRead(vertexfile); fs = textFileRead(fragmentfile); if(vs == NULL) std::cout << "vs files null\n" << std::endl; if(fs == NULL) std::cout << "fs files null\n" << std::endl; const char * vv = vs; const char * ff = fs; glShaderSource(vertexShader, 1, &vv,NULL); glShaderSource(fragmentShader, 1, &ff,NULL); free(vs);free(fs); glCompileShader(vertexShader); glCompileShader(fragmentShader); printShaderInfoLog(vertexShader); printShaderInfoLog(fragmentShader); *program = glCreateProgram(); glAttachShader(*program,vertexShader); glAttachShader(*program,fragmentShader); glBindFragDataLocation(*program, 0, "output"); glBindAttribLocation(*program,vertexLoc,"position"); glBindAttribLocation(*program,normalLoc,"normal"); glBindAttribLocation(*program,texCoordLoc,"texCoord"); glLinkProgram(*program); glValidateProgram(*program); IO::printProgramInfoLog(*program); GLuint k = glGetUniformBlockIndex(*program,"Matrices"); glUniformBlockBinding(*program, k, matricesUniLoc); glUniformBlockBinding(*program, glGetUniformBlockIndex(*program,"Material"), materialUniLoc); texUnit = glGetUniformLocation(*program,"texUnit"); return(*program); }
GLuint createProgram(const char * vertexShaderCode, const char * fragmentShaderCode) { GLuint program = glCreateProgram(); glAttachShader(program, createShader(vertexShaderCode, GL_VERTEX_SHADER)); glAttachShader(program, createShader(fragmentShaderCode, GL_FRAGMENT_SHADER)); glLinkProgram(program); glValidateProgram(program); return program; }
GLuint Shader::Load(const String& vertSrc, const String& fragSrc) { const char* vertexSource = vertSrc.c_str(); const char* fragmentSource = fragSrc.c_str(); GLuint program = glCreateProgram(); GLuint vertex = glCreateShader(GL_VERTEX_SHADER); GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(vertex, 1, &vertexSource, NULL); glCompileShader(vertex); GLint result; glGetShaderiv(vertex, GL_COMPILE_STATUS, &result); if (result == GL_FALSE) { GLint length; glGetShaderiv(vertex, GL_INFO_LOG_LENGTH, &length); std::vector<char> error(length); glGetShaderInfoLog(vertex, length, &length, &error[0]); SP_ERROR("Failed to compile vertex shader!"); SP_ERROR(&error[0]); SP_ASSERT(false, "Failed to compile vertex shader!"); glDeleteShader(vertex); return 0; } glShaderSource(fragment, 1, &fragmentSource, NULL); glCompileShader(fragment); glGetShaderiv(fragment, GL_COMPILE_STATUS, &result); if (result == GL_FALSE) { GLint length; glGetShaderiv(fragment, GL_INFO_LOG_LENGTH, &length); std::vector<char> error(length); glGetShaderInfoLog(fragment, length, &length, &error[0]); SP_ERROR("Failed to compile fragment shader!"); SP_ERROR(&error[0]); SP_ASSERT(false, "Failed to compile fragment shader!"); glDeleteShader(fragment); return 0; } glAttachShader(program, vertex); glAttachShader(program, fragment); glLinkProgram(program); glValidateProgram(program); glDeleteShader(vertex); glDeleteShader(fragment); return program; }
GLuint ShaderTool_CreateShaderProgram(const char * vertex_shader_filename, const char * geometry_shader_filename, const char * fragment_shader_filename) { GLuint prog; ShaderTool_SInfo_T vertex, geometry, fragment; char info_log[1024]; GLint success; vertex.filename = vertex_shader_filename; vertex.shader_type = GL_VERTEX_SHADER; geometry.filename = geometry_shader_filename; geometry.shader_type = GL_GEOMETRY_SHADER; fragment.filename = fragment_shader_filename; fragment.shader_type = GL_FRAGMENT_SHADER; prog = glCreateProgram(); ShaderTool_CreateAndAttachShader(&vertex, prog); ShaderTool_CreateAndAttachShader(&geometry, prog); ShaderTool_CreateAndAttachShader(&fragment, prog); glLinkProgram(prog); glGetProgramiv(prog, GL_LINK_STATUS, &success); if(success) { glValidateProgram(prog); } else { glGetProgramInfoLog(prog, sizeof(info_log), NULL, info_log); printf("Error: ShaderTool_CreateShaderProgram Failed to link program containg:\n"); if(vertex.attached_flag) { printf("Error: File: %s\n", vertex.filename); } if(geometry.attached_flag) { printf("Error: File: %s\n", geometry.filename); } if(fragment.attached_flag) { printf("Error: File: %s\n", fragment.filename); } printf("Program Error: %s\n", info_log); } ShaderTool_PostLinkCleanup(&vertex, prog); ShaderTool_PostLinkCleanup(&geometry, prog); ShaderTool_PostLinkCleanup(&fragment, prog); return prog; }
void GLshader::validate(void) { GLint validate_ok = GL_FALSE; glValidateProgram(program); glGetProgramiv(program, GL_VALIDATE_STATUS, &validate_ok); if (!validate_ok) { fprintf(stderr, "glValidateProgram Shader:"); this->print_log(program); } }
void initRender() { // Create 2 shader programs Shader[0] = glCreateShader(GL_VERTEX_SHADER); Shader[1] = glCreateShader(GL_FRAGMENT_SHADER); LoadShader((char *)VertexShader, Shader[0]); LoadShader((char *)FragmentShader, Shader[1]); // Create the prorgam and attach the shaders & attributes Program = glCreateProgram(); glAttachShader(Program, Shader[0]); glAttachShader(Program, Shader[1]); glBindAttribLocation(Program, 0, "Position"); glBindAttribLocation(Program, 1, "Normal"); glBindAttribLocation(Program, 2, "Texture"); // Link glLinkProgram(Program); // Validate our work thus far int ShaderStatus; glGetProgramiv(Program, GL_LINK_STATUS, &ShaderStatus); if (ShaderStatus != GL_TRUE) { LOGE("Error: Failed to link GLSL program\n"); int Len = 1024; char Error[1024]; glGetProgramInfoLog(Program, 1024, &Len, Error); LOGE("%s",Error); exit(-1); } glValidateProgram(Program); checkGlError("glValidateProgram"); // Enable the program glUseProgram (Program); // Retrieve our uniforms iProj = glGetUniformLocation(Program, "Proj"); iModel = glGetUniformLocation(Program, "Model"); iCamera = glGetUniformLocation(Program, "Camera"); // Basic GL setup glClearColor (0.15, 0.15, 0.15, 1.0); glEnable (GL_CULL_FACE); glEnable (GL_DEPTH_TEST); glCullFace (GL_BACK); }
bool CShader::validateSP( const GLuint& t_spIndex ) { int param = -1; glValidateProgram( t_spIndex ); glGetProgramiv( t_spIndex, GL_VALIDATE_STATUS, ¶m ); LogMsg<<"program "<<t_spIndex<<" GL_VALIDATE_STATUS = " << param<<LogEndl; if (GL_TRUE != param) { printSPInfoLog( t_spIndex ); return false; } return true; }
void Effect::validate() { assert(id != 0); glValidateProgram(id); GLint status; glGetProgramiv(id, GL_VALIDATE_STATUS, &status); if (status == GL_FALSE) logError("Programm validation failed"); valid = (status == GL_TRUE); }
void GLProgram::linkShaders(void) { glLinkProgram(ID); // everything will be linked together if(!checkErrors()) { return; } else { //given the current pipeline state, can the shaders be executed? (this should be done before every draw call.......) glValidateProgram(ID); } }
GLuint Shader::load() { GLuint program = glCreateProgram(); glAttachShader(program, createShader(GL_VERTEX_SHADER)); glAttachShader(program, createShader(GL_FRAGMENT_SHADER)); glLinkProgram(program); glValidateProgram(program); return program; }
void Shader::PrintProgramValidationLog(GLuint obj, const char* fileName) { char log[1024]; int len = 0; glValidateProgram(obj); glGetProgramInfoLog(obj, 1024, &len, log); if(len > 0) { FileOut f(fileName); f.Put(log); } }
/* validateProgram: checks whether the program can execute given the current pipeline state */ void validateProgram(GLuint shader_program) { GLint success; GLchar InfoLog[1024]; glValidateProgram(shader_program); glGetProgramiv(shader_program, GL_VALIDATE_STATUS, &success); if (!success) { glGetProgramInfoLog(shader_program, sizeof(InfoLog), NULL, InfoLog); fprintf(stderr, "Invalid shader program: '%s'\n", InfoLog); exit(1); } }
int compileShaders() { GLuint shaderProgram; GLint success; GLchar infolog[1024]; shaderProgram = glCreateProgram(); if(shaderProgram == 0) { printf("Error: glCreateProgram() == 0"); return -1; } if(addShader(shaderProgram, pVS, GL_VERTEX_SHADER) < 0) { printf("Error: addShader(shaderProgram, pVS, GL_VERTEX_SHADER)\n"); return -1; } if(addShader(shaderProgram, pFS, GL_FRAGMENT_SHADER) < 0) { printf("Error: addShader(shaderProgram, pFS, GL_FRAGMENT_SHADER)\n"); return -1; } success = 0; glLinkProgram(shaderProgram); glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); if(success == 0) { glGetProgramInfoLog(shaderProgram, sizeof(infolog), NULL, infolog); printf("Error glLinkProgram(): %s\n",infolog); return -1; } success = 0; glValidateProgram(shaderProgram); glGetProgramiv(shaderProgram, GL_VALIDATE_STATUS, &success); if(success == 0) { glGetProgramInfoLog(shaderProgram, sizeof(infolog), NULL, infolog); printf("Error glValidateProgram(): %s\n",infolog); return -1; } glUseProgram(shaderProgram); return 0; }
void linkShaderProgram(GLuint programID) { // Link all shaders togethers into the GLSL program glLinkProgram(programID); if (checkProgramInfo(programID, GL_LINK_STATUS, nullptr)){ // Validate program executability giving current OpenGL states glValidateProgram(programID); if (checkProgramInfo(programID, GL_VALIDATE_STATUS, nullptr)){ std::cout << "Program " << programID << " linked\n"; } } }
bool is_programme_valid (GLuint sp) { glValidateProgram (sp); GLint params = -1; glGetProgramiv (sp, GL_VALIDATE_STATUS, ¶ms); if (GL_TRUE != params) { gl_log_err ("program %i GL_VALIDATE_STATUS = GL_FALSE\n", sp); print_programme_info_log (sp); return false; } gl_log ("program %i GL_VALIDATE_STATUS = GL_TRUE\n", sp); return true; }
/* validate shader */ bool is_valid (GLuint sp) { int params = -1; glValidateProgram (sp); glGetProgramiv (sp, GL_VALIDATE_STATUS, ¶ms); printf ("program %i GL_VALIDATE_STATUS = %i\n", sp, params); if (GL_TRUE != params) { _print_programme_info_log (sp); return false; } return true; }