From 33f17e345aa8b8c4a30ee8788a9962cbd8669cde Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 28 Oct 2019 17:18:59 +0100 Subject: [PATCH] option -dgl to debug shaders --- debug.cpp | 3 +++ glhr.cpp | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/debug.cpp b/debug.cpp index 8aef3198..fb6f8436 100644 --- a/debug.cpp +++ b/debug.cpp @@ -797,6 +797,9 @@ int read_cheat_args() { fixseed = true; autocheat = true; shift(); steplimit = argi(); } + else if(argis("-dgl")) { + debug_gl = true; + } else if(argis("-W")) { PHASEFROM(2); shift(); diff --git a/glhr.cpp b/glhr.cpp index 19a38fe3..231ab987 100644 --- a/glhr.cpp +++ b/glhr.cpp @@ -255,12 +255,21 @@ struct GLprogram { EX shared_ptr current_glprogram = nullptr; +EX bool debug_gl; + EX int compileShader(int type, const string& s) { GLint status; -#if DEBUG_GL - printf("===\n%s\n===\n", s.c_str()); -#endif + if(debug_gl) { + println(hlog, "===\n"); + int lineno = 1; + string cline = ""; + for(char c: s+"\n") { + if(c == '\n') println(hlog, format("%4d : ", lineno), cline), lineno++, cline = ""; + else cline += c; + } + println(hlog, "==="); + } GLint shader = glCreateShader(type); const char *ss = s.c_str(); @@ -274,6 +283,7 @@ EX int compileShader(int type, const string& s) { glGetShaderInfoLog(shader, logLength, &logLength, log.data()); if(logLength > 0) printf("compiler log (%d): '%s'\n", logLength, log.data()); + if(debug_gl) exit(1); } glGetShaderiv(shader, GL_COMPILE_STATUS, &status);