/* * Create shader, load in source, compile, dump debug as necessary. * * shader: Pointer to return created shader ID. * source: Passed-in shader source code. * shader_type: Passed to GL, e.g. GL_VERTEX_SHADER. */ void process_shader(GLuint *shader, const char * source, GLint shader_type) { GLint status = GL_FALSE; const char *shaders[1] = { NULL }; char buffer[1024]; GLsizei length; /* Create shader and load into GL. */ *shader = GL_CHECK(ctx.glCreateShader(shader_type)); shaders[0] = source; GL_CHECK(ctx.glShaderSource(*shader, 1, shaders, NULL)); /* Clean up shader source. */ shaders[0] = NULL; /* Try compiling the shader. */ GL_CHECK(ctx.glCompileShader(*shader)); GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); /* Dump debug info (source and log) if compilation failed. */ if(status != GL_TRUE) { ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]); buffer[length] = '\0'; SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr); quit(-1); } }
/* * Create shader, load in source, compile, dump debug as necessary. * * shader: Pointer to return created shader ID. * source: Passed-in shader source code. * shader_type: Passed to GL, e.g. GL_VERTEX_SHADER. */ void process_shader(GLuint *shader, const char * source, GLint shader_type) { GLint status = GL_FALSE; const char *shaders[1] = { NULL }; /* Create shader and load into GL. */ *shader = GL_CHECK(ctx.glCreateShader(shader_type)); shaders[0] = source; GL_CHECK(ctx.glShaderSource(*shader, 1, shaders, NULL)); /* Clean up shader source. */ shaders[0] = NULL; /* Try compiling the shader. */ GL_CHECK(ctx.glCompileShader(*shader)); GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status)); // Dump debug info (source and log) if compilation failed. if(status != GL_TRUE) { SDL_Log("Shader compilation failed"); quit(-1); } }