Skip to content

Commit

Permalink
logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Jul 25, 2024
1 parent 2e022ae commit ec5f5eb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/utils/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

void Shader::setup(std::string vertexSource, std::string fragmentSource){

auto getShaderLog = [](GLuint id) -> std::string {
GLint length, written;
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
if (length <= 0)
return "";
auto stuff = new char[length + 1];
glGetShaderInfoLog(id, length, &written, stuff);
std::string result(stuff);
delete[] stuff;
return result;
};

GLint res;

vertex = glCreateShader(GL_VERTEX_SHADER);
Expand All @@ -18,6 +30,8 @@ void Shader::setup(std::string vertexSource, std::string fragmentSource){
glShaderSource(vertex, sizeof(vertexSources) / sizeof(char*), vertexSources, nullptr);
glCompileShader(vertex);

auto vertexLog = string::trim(getShaderLog(vertex));

glGetShaderiv(vertex, GL_COMPILE_STATUS, &res);
if(!res) {
glDeleteShader(vertex);
Expand All @@ -39,6 +53,8 @@ void Shader::setup(std::string vertexSource, std::string fragmentSource){
glShaderSource(fragment, sizeof(fragmentSources) / sizeof(char*), fragmentSources, nullptr);
glCompileShader(fragment);

auto fragmentLog = string::trim(getShaderLog(fragment));

glGetShaderiv(fragment, GL_COMPILE_STATUS, &res);
if(!res) {
glDeleteShader(vertex);
Expand All @@ -58,6 +74,9 @@ void Shader::setup(std::string vertexSource, std::string fragmentSource){
vertex = 0;
fragment = 0;

log::info("vertex log: {}", vertexLog);
log::info("fragment log: {}", fragmentLog);

glGetProgramiv(program, GL_LINK_STATUS, &res);
if(!res) {
glDeleteProgram(program);
Expand Down

0 comments on commit ec5f5eb

Please sign in to comment.