diff --git a/include/Nazara/OpenGLRenderer/Wrapper/Shader.hpp b/include/Nazara/OpenGLRenderer/Wrapper/Shader.hpp index bd3d7ac5c..fef467050 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/Shader.hpp +++ b/include/Nazara/OpenGLRenderer/Wrapper/Shader.hpp @@ -26,7 +26,8 @@ namespace Nz::GL inline void Compile(); - inline bool GetCompilationStatus(std::string* error = nullptr); + inline bool GetCompilationStatus(std::string* error = nullptr) const; + inline std::string GetSource() const; inline void SetBinarySource(GLenum binaryFormat, const void* binary, GLsizei length); inline void SetSource(const char* source, GLint length); diff --git a/include/Nazara/OpenGLRenderer/Wrapper/Shader.inl b/include/Nazara/OpenGLRenderer/Wrapper/Shader.inl index 20986a525..39cdc94cb 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/Shader.inl +++ b/include/Nazara/OpenGLRenderer/Wrapper/Shader.inl @@ -16,7 +16,7 @@ namespace Nz::GL context.glCompileShader(m_objectId); } - inline bool Shader::GetCompilationStatus(std::string* error) + inline bool Shader::GetCompilationStatus(std::string* error) const { assert(m_objectId); const Context& context = EnsureDeviceContext(); @@ -45,6 +45,28 @@ namespace Nz::GL return true; } + inline std::string Shader::GetSource() const + { + assert(m_objectId); + const Context& context = EnsureDeviceContext(); + + GLint sourceLength; + context.glGetShaderiv(m_objectId, GL_SHADER_SOURCE_LENGTH, &sourceLength); + + if (sourceLength <= 1) + return {}; + + std::string source; + source.resize(sourceLength - 1); + + GLsizei length; + context.glGetShaderSource(m_objectId, sourceLength, &length, &source[0]); + + assert(length == sourceLength - 1); + + return source; + } + inline void Shader::SetBinarySource(GLenum binaryFormat, const void* binary, GLsizei length) { assert(m_objectId); diff --git a/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp b/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp index 5f3a36c0e..9fc12d6da 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp @@ -159,6 +159,10 @@ namespace Nz { std::string errorLog; if (!shader.GetCompilationStatus(&errorLog)) - throw std::runtime_error("Failed to compile shader: " + errorLog); + { + std::string source = shader.GetSource(); + + throw std::runtime_error("Failed to compile shader: " + errorLog + "\nSource: " + source); + } } }