From: Mikko Rasa Date: Sat, 12 Dec 2015 11:16:17 +0000 (+0200) Subject: Move shader program linking to a separate function X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7726f59d95180e7fcb985dd94b3815749e102069;p=geometrycompositor.git Move shader program linking to a separate function --- diff --git a/source/main.c b/source/main.c index 731323f..0992542 100644 --- a/source/main.c +++ b/source/main.c @@ -181,12 +181,36 @@ unsigned compile_shader(GLenum type, const char *source) return shader; } -int create_gl_resources(Compositor *compositor, CompositedScreen *screen) +unsigned link_program(unsigned *shaders, unsigned nshaders) { + unsigned program; + unsigned i; int status; char info_log[1024]; GLsizei length; + program = glCreateProgram(); + for(i=0; ishaders[0] = compile_shader(GL_VERTEX_SHADER, vshader); @@ -194,25 +218,12 @@ int create_gl_resources(Compositor *compositor, CompositedScreen *screen) if(!screen->shaders[0] || !screen->shaders[1]) return 0; - screen->program = glCreateProgram(); - glAttachShader(screen->program, screen->shaders[0]); - glAttachShader(screen->program, screen->shaders[1]); - glBindAttribLocation(screen->program, 0, "vertex"); - glLinkProgram(screen->program); + screen->program = link_program(screen->shaders, 2); + if(!screen->program) + return 0; screen->geometry_loc = glGetUniformLocation(screen->program, "geometry"); - glGetProgramiv(screen->program, GL_LINK_STATUS, &status); - glGetProgramInfoLog(screen->program, sizeof(info_log), &length, info_log); - if(!status) - { - fprintf(stderr, "Program link failed:\n%s\n", info_log); - glDeleteProgram(screen->program); - return 0; - } - else if(length) - printf("Program info log:\n%s\n", info_log); - glGenBuffers(1, &screen->vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, screen->vertex_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);