Skip to content

Commit

Permalink
Allow GLES 3.1, and log GL shader compile errors properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
maluoi committed Aug 20, 2023
1 parent 06177fd commit 80bfde0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 14 additions & 3 deletions sk_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3827,7 +3827,7 @@ skg_shader_stage_t skg_shader_stage_create(const void *file_data, size_t shader_

// Convert the prefix if it doesn't match the GL version we're using
#if defined(_SKG_GL_ES)
const char *prefix_gl = "#version 320 es";
const char *prefix_gl = "#version 310 es";
#elif defined(_SKG_GL_DESKTOP)
const char *prefix_gl = "#version 450";
#elif defined(_SKG_GL_WEB)
Expand Down Expand Up @@ -3878,7 +3878,11 @@ skg_shader_stage_t skg_shader_stage_create(const void *file_data, size_t shader_
log = (char*)malloc(length);
glGetShaderInfoLog(result._shader, length, &err, log);

skg_logf(skg_log_warning, "Unable to compile shader: ", log);
// Trim trailing newlines, we've already got that covered
size_t len = strlen(log);
while(len > 0 && log[len-1] == '\n') { log[len-1] = '\0'; len -= 1; }

skg_logf(skg_log_warning, "Unable to compile shader (%d):\n%s", err, log);
free(log);

glDeleteShader(result._shader);
Expand All @@ -3901,7 +3905,14 @@ void skg_shader_stage_destroy(skg_shader_stage_t *shader) {

skg_shader_t skg_shader_create_manual(skg_shader_meta_t *meta, skg_shader_stage_t v_shader, skg_shader_stage_t p_shader, skg_shader_stage_t c_shader) {
if (v_shader._shader == 0 && p_shader._shader == 0 && c_shader._shader == 0) {
skg_logf(skg_log_warning, "Shader '%s' has no valid stages!", meta->name);
#if defined(_SKG_GL_ES)
const char *gl_name = "GLES";
#elif defined(_SKG_GL_DESKTOP)
const char *gl_name = "OpenGL";
#elif defined(_SKG_GL_WEB)
const char *gl_name = "WebGL";
#endif
skg_logf(skg_log_warning, "Shader '%s' has no valid stages for %s!", meta->name, gl_name);
return {};
}

Expand Down
17 changes: 14 additions & 3 deletions src/sk_gpu_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ skg_shader_stage_t skg_shader_stage_create(const void *file_data, size_t shader_

// Convert the prefix if it doesn't match the GL version we're using
#if defined(_SKG_GL_ES)
const char *prefix_gl = "#version 320 es";
const char *prefix_gl = "#version 310 es";
#elif defined(_SKG_GL_DESKTOP)
const char *prefix_gl = "#version 450";
#elif defined(_SKG_GL_WEB)
Expand Down Expand Up @@ -1196,7 +1196,11 @@ skg_shader_stage_t skg_shader_stage_create(const void *file_data, size_t shader_
log = (char*)malloc(length);
glGetShaderInfoLog(result._shader, length, &err, log);

skg_logf(skg_log_warning, "Unable to compile shader: ", log);
// Trim trailing newlines, we've already got that covered
size_t len = strlen(log);
while(len > 0 && log[len-1] == '\n') { log[len-1] = '\0'; len -= 1; }

skg_logf(skg_log_warning, "Unable to compile shader (%d):\n%s", err, log);
free(log);

glDeleteShader(result._shader);
Expand All @@ -1219,7 +1223,14 @@ void skg_shader_stage_destroy(skg_shader_stage_t *shader) {

skg_shader_t skg_shader_create_manual(skg_shader_meta_t *meta, skg_shader_stage_t v_shader, skg_shader_stage_t p_shader, skg_shader_stage_t c_shader) {
if (v_shader._shader == 0 && p_shader._shader == 0 && c_shader._shader == 0) {
skg_logf(skg_log_warning, "Shader '%s' has no valid stages!", meta->name);
#if defined(_SKG_GL_ES)
const char *gl_name = "GLES";
#elif defined(_SKG_GL_DESKTOP)
const char *gl_name = "OpenGL";
#elif defined(_SKG_GL_WEB)
const char *gl_name = "WebGL";
#endif
skg_logf(skg_log_warning, "Shader '%s' has no valid stages for %s!", meta->name, gl_name);
return {};
}

Expand Down

0 comments on commit 80bfde0

Please sign in to comment.