Show source lines when reporting shader compilation errors
This commit is contained in:
parent
fe873209c6
commit
e8c0d9492b
1 changed files with 28 additions and 1 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
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<char[]> 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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue