Merge pull request #450 from Subv/shader_link_error
GLRenderer: Log the shader source code when program linking fails.
This commit is contained in:
commit
03388c3071
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
@ -11,6 +12,27 @@
|
|||||||
|
|
||||||
namespace GLShader {
|
namespace GLShader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to log the source code of a list of shaders.
|
||||||
|
* @param shaders The OpenGL shaders whose source we will print.
|
||||||
|
*/
|
||||||
|
template <typename... T>
|
||||||
|
void LogShaderSource(T... shaders) {
|
||||||
|
auto shader_list = {shaders...};
|
||||||
|
|
||||||
|
for (const auto& shader : shader_list) {
|
||||||
|
if (shader == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
GLint source_length;
|
||||||
|
glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &source_length);
|
||||||
|
|
||||||
|
std::string source(source_length, ' ');
|
||||||
|
glGetShaderSource(shader, source_length, nullptr, &source[0]);
|
||||||
|
NGLOG_INFO(Render_OpenGL, "Shader source {}", source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function to create and compile an OpenGL GLSL shader
|
* Utility function to create and compile an OpenGL GLSL shader
|
||||||
* @param source String of the GLSL shader program
|
* @param source String of the GLSL shader program
|
||||||
@ -55,6 +77,11 @@ GLuint LoadProgram(bool separable_program, T... shaders) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result == GL_FALSE) {
|
||||||
|
// There was a problem linking the shader, print the source for debugging purposes.
|
||||||
|
LogShaderSource(shaders...);
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT_MSG(result == GL_TRUE, "Shader not linked");
|
ASSERT_MSG(result == GL_TRUE, "Shader not linked");
|
||||||
|
|
||||||
((shaders == 0 ? (void)0 : glDetachShader(program_id, shaders)), ...);
|
((shaders == 0 ? (void)0 : glDetachShader(program_id, shaders)), ...);
|
||||||
|
Loading…
Reference in New Issue
Block a user