From bde009c58b06934924e276a7ce7b07564b5d9edd Mon Sep 17 00:00:00 2001 From: Ilia Bozhinov Date: Sat, 24 Feb 2024 15:40:33 +0100 Subject: [PATCH 1/2] opengl: report linking errors from program compilation as well --- src/core/opengl.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/core/opengl.cpp b/src/core/opengl.cpp index e498ef2d9..ad82ae07d 100644 --- a/src/core/opengl.cpp +++ b/src/core/opengl.cpp @@ -87,11 +87,25 @@ GLuint compile_program(std::string vertex_source, std::string frag_source) GL_CALL(glAttachShader(result_program, fragment_shader)); GL_CALL(glLinkProgram(result_program)); + int s = GL_FALSE; +#define LENGTH 1024 * 128 + char log[LENGTH]; + GL_CALL(glGetProgramiv(result_program, GL_LINK_STATUS, &s)); + GL_CALL(glGetProgramInfoLog(result_program, LENGTH, NULL, log)); + + if (s == GL_FALSE) + { + LOGE("Failed to link vertex shader:\n", vertex_source, + "\nFragment shader:\n", frag_source, + "\nLinker output:\n", log); + + GL_CALL(glDeleteProgram(result_program)); + } + /* won't be really deleted until program is deleted as well */ GL_CALL(glDeleteShader(vertex_shader)); GL_CALL(glDeleteShader(fragment_shader)); - - return result_program; + return (s == GL_FALSE) ? 0 : result_program; } void init() From 43a36581fc7770c2b390d92ed1ae0c94f0836fc3 Mon Sep 17 00:00:00 2001 From: Ilia Bozhinov Date: Sat, 24 Feb 2024 15:40:47 +0100 Subject: [PATCH 2/2] opengl: print an error if trying to set uniforms which don't exist --- src/core/opengl.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/opengl.cpp b/src/core/opengl.cpp index ad82ae07d..e3cb494ac 100644 --- a/src/core/opengl.cpp +++ b/src/core/opengl.cpp @@ -633,6 +633,11 @@ class program_t::impl uniforms[active_program_idx][name] = GL_CALL(glGetUniformLocation(id[active_program_idx], name.c_str())); + if (uniforms[active_program_idx][name] == -1) + { + LOGE("Uniform ", name, " not found in program"); + } + return uniforms[active_program_idx][name]; }