This repository has been archived on 2024-12-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2024CG-project-render/include/print_shader_info_log.h
github-classroom[bot] 686dcaf351
Initial commit
2024-11-29 09:50:03 +00:00

51 lines
1.3 KiB
C++

#ifndef PRINT_SHADER_INFO_LOG_H
#define PRINT_SHADER_INFO_LOG_H
#include <string>
#include <vector>
// Print information (e.g., compilation errors and warnings) about a give glsl
// shader.
//
// Inputs:
// type_str string identifying which kind of shader we're asking about (just
// a prefix to print)
// obj id of object we're querying
// paths list of file paths containing corresponding shader source code
// (assumings `#line ...` directive has been inserted between files).
// Returns true if printed anything.
bool print_shader_info_log(
const std::string & type_str,
const GLuint obj,
const std::vector<std::string> & paths);
// Implementation
#include "REDRUM.h"
#include "STR.h"
#include <iostream>
bool print_shader_info_log(
const std::string & type_str,
const GLuint obj,
const std::vector<std::string> & paths)
{
GLint infologLength = 0;
GLint charsWritten = 0;
glGetShaderiv(obj, GL_INFO_LOG_LENGTH,&infologLength);
if (infologLength > 0)
{
char * infoLog = new char[infologLength];
std::cerr<<REDRUM("ERROR")<<": failed to compile "<<type_str<<std::endl;
glGetShaderInfoLog(obj, infologLength, &charsWritten, infoLog);
std::string log(infoLog);
std::cerr<<log<<std::endl;
delete[] infoLog;
return true;
}
return false;
}
#endif