add shader compilation error logging

This commit is contained in:
2025-06-06 12:49:35 +02:00
parent c5d3449abc
commit ed7a157ee3
2 changed files with 22 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
#include "../util/vec/float2.h" #include "../util/vec/float2.h"
#include "shader.h" #include "shader.h"
#include "../error.h"
#define VERTC 6 #define VERTC 6
GLuint pipe; GLuint pipe;
@@ -36,6 +37,15 @@ int render_init(void) {
glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
int len;
glGetProgramiv(pipe, GL_INFO_LOG_LENGTH, &len);
if (len > 0) {
char log[len];
glGetProgramInfoLog(pipe, len, &len, log);
log[len - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
fatal("error whilst linking the pipe: '%s'", log);
}
// init the VAO // init the VAO
glGenVertexArrays(1, &vao); glGenVertexArrays(1, &vao);
glBindVertexArray(vao); glBindVertexArray(vao);

View File

@@ -5,6 +5,8 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "../error.h"
#define NAM_S(name) _binary_res_##name##_start // name of a start variable #define NAM_S(name) _binary_res_##name##_start // name of a start variable
#define NAM_E(name) _binary_res_##name##_end // name of an end variable #define NAM_E(name) _binary_res_##name##_end // name of an end variable
@@ -22,6 +24,16 @@ static GLuint shader_compile(GLenum type, char const* src, size_t len) {
GLuint shader = glCreateShader(type); GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &src, &ilen); glShaderSource(shader, 1, &src, &ilen);
glCompileShader(shader); glCompileShader(shader);
// repurposing ilen for the max length of the shader log
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &ilen);
if (ilen > 0) {
char log[ilen];
glGetShaderInfoLog(shader, ilen, &ilen, log);
log[ilen - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
error("error whilst compiling shader type '0x%x': '%s'", type, log);
}
return shader; return shader;
} }