mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-22 10:40:25 +00:00
glsl_compile_link: no abort if compile/link fails
Do not abort if compile/link fails but return 0. Some of callers already expect returning 0 on error. + print the errors with ERROR severity to be more obvious in program output
This commit is contained in:
@@ -149,42 +149,49 @@ bool init_gl_context(struct gl_context *context, int which) {
|
||||
GLuint glsl_compile_link(const char *vprogram, const char *fprogram)
|
||||
{
|
||||
char log[32768];
|
||||
GLuint vhandle, fhandle;
|
||||
GLuint phandle;
|
||||
GLuint vhandle = 0;
|
||||
GLuint fhandle = 0;
|
||||
GLint status;
|
||||
|
||||
phandle = glCreateProgram();
|
||||
vhandle = glCreateShader(GL_VERTEX_SHADER);
|
||||
fhandle = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
log_msg(LOG_LEVEL_DEBUG, "Compiling program:\nVertex:%s\nShader:\n%s\n", IF_NOT_NULL_ELSE(vprogram, "(none)"), IF_NOT_NULL_ELSE(fprogram, "(none)"));
|
||||
|
||||
/* compile */
|
||||
/* fragmemt */
|
||||
if (fprogram) {
|
||||
fhandle = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fhandle, 1, &fprogram, NULL);
|
||||
glCompileShader(fhandle);
|
||||
/* Print compile log */
|
||||
glGetShaderInfoLog(fhandle, sizeof log, NULL, log);
|
||||
if (strlen(log) > 0) {
|
||||
log_msg(LOG_LEVEL_INFO, "Fragment compile log: %s\n", log);
|
||||
log_msg(LOG_LEVEL_ERROR, "Fragment compile log: %s\n", log);
|
||||
}
|
||||
glGetShaderiv(fhandle, GL_COMPILE_STATUS, &status);
|
||||
assert(status == GL_TRUE);
|
||||
if (status != GL_TRUE) {
|
||||
glDeleteShader(fhandle);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* vertex */
|
||||
if (vprogram) {
|
||||
vhandle = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vhandle, 1, &vprogram, NULL);
|
||||
glCompileShader(vhandle);
|
||||
/* Print compile log */
|
||||
glGetShaderInfoLog(vhandle, sizeof log, NULL, log);
|
||||
if (strlen(log) > 0) {
|
||||
log_msg(LOG_LEVEL_INFO, "Vertex compile log: %s\n", log);
|
||||
log_msg(LOG_LEVEL_ERROR, "Vertex compile log: %s\n", log);
|
||||
}
|
||||
glGetShaderiv(vhandle, GL_COMPILE_STATUS, &status);
|
||||
assert(status == GL_TRUE);
|
||||
if (status != GL_TRUE) {
|
||||
glDeleteShader(fhandle);
|
||||
glDeleteShader(vhandle);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint phandle = glCreateProgram();
|
||||
|
||||
/* attach and link */
|
||||
if (vprogram) {
|
||||
glAttachShader(phandle, vhandle);
|
||||
@@ -193,20 +200,24 @@ GLuint glsl_compile_link(const char *vprogram, const char *fprogram)
|
||||
glAttachShader(phandle, fhandle);
|
||||
}
|
||||
glLinkProgram(phandle);
|
||||
glGetProgramiv(phandle, GL_LINK_STATUS, &status);
|
||||
assert(status == GL_TRUE);
|
||||
glGetProgramInfoLog(phandle, sizeof log, NULL, (GLchar*) log);
|
||||
if (strlen(log) > 0) {
|
||||
log_msg(LOG_LEVEL_INFO, "Link Log: %s\n", log);
|
||||
}
|
||||
|
||||
// check GL errors
|
||||
gl_check_error();
|
||||
|
||||
// mark shaders for deletion when program is deleted
|
||||
glDeleteShader(vhandle);
|
||||
glDeleteShader(fhandle);
|
||||
|
||||
glGetProgramInfoLog(phandle, sizeof log, NULL, (GLchar*) log);
|
||||
if (strlen(log) > 0) {
|
||||
log_msg(LOG_LEVEL_ERROR, "Link Log: %s\n", log);
|
||||
}
|
||||
glGetProgramiv(phandle, GL_LINK_STATUS, &status);
|
||||
if (status != GL_TRUE) {
|
||||
glDeleteProgram(phandle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// check GL errors
|
||||
gl_check_error();
|
||||
|
||||
return phandle;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,6 +123,11 @@ void destroy_gl_context(struct gl_context *context);
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* compiles and links specified program shaders
|
||||
* @returns shader ID
|
||||
* @retval 0 on error
|
||||
*/
|
||||
GLuint glsl_compile_link(const char *vprogram, const char *fprogram);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -252,6 +252,7 @@ static void oneshot_init(int value [[gnu::unused]])
|
||||
|
||||
if (!s->use_rgb) {
|
||||
s->program_to_yuv422 = glsl_compile_link(NULL, fp_display_rgba_to_yuv422_legacy);
|
||||
assert(s->program_to_yuv422 != NULL);
|
||||
glUseProgram(s->program_to_yuv422);
|
||||
glUniform1i(glGetUniformLocation(s->program_to_yuv422, "image"), 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user