diff --git a/libs/gfx/source/program.cpp b/libs/gfx/source/program.cpp index 65e16431..9c533803 100644 --- a/libs/gfx/source/program.cpp +++ b/libs/gfx/source/program.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace psemek::gfx { @@ -209,6 +210,32 @@ namespace psemek::gfx gl::Uniform2f(location_, i.min, i.max); } + static std::string annotated_source(std::string_view source) + { + std::ostringstream os; + + bool first = true; + + int line = 0; + for (char c : source) + { + if (first) + { + os << line << ": "; + first = false; + } + + os.put(c); + if (c == '\n') + { + ++line; + first = true; + } + } + + return os.str(); + } + static void load_shader(GLuint shader, std::string_view source) { char const * vert_sources[1] { source.data() }; @@ -224,7 +251,7 @@ namespace psemek::gfx gl::GetShaderiv(shader, gl::INFO_LOG_LENGTH, &log_len); std::unique_ptr log(new char [log_len]); gl::GetShaderInfoLog(shader, log_len, nullptr, log.get()); - throw std::runtime_error(util::to_string("Shader compilation failed: ", log.get(), "\nShader source: \n", source)); + throw std::runtime_error(util::to_string("Shader compilation failed: ", log.get(), "\nShader source: \n", annotated_source(source))); } }