fixes
This commit is contained in:
46
source/opengl/data/shader_data.cpp
Executable file
46
source/opengl/data/shader_data.cpp
Executable file
@@ -0,0 +1,46 @@
|
||||
#include "opengl/data/shader_data.hpp"
|
||||
|
||||
#include "GL/glew.h"
|
||||
#include "opengl/error.hpp"
|
||||
#include "util/logger.hpp"
|
||||
|
||||
namespace zgl
|
||||
{
|
||||
std::error_code shader_data::build_from(
|
||||
const GLenum type,
|
||||
const std::string& source,
|
||||
shader_data& data
|
||||
) {
|
||||
auto shader_id = GLuint{ 0 };
|
||||
|
||||
if (not source.empty())
|
||||
{
|
||||
shader_id = glCreateShader(type);
|
||||
|
||||
// Curious choice to take lists as parameters...
|
||||
const auto first_list_element = source.c_str();
|
||||
const auto first_list_element_len = static_cast<GLint>(source.length());
|
||||
glShaderSource(shader_id, 1, &first_list_element, &first_list_element_len);
|
||||
glCompileShader(shader_id);
|
||||
|
||||
GLint success;
|
||||
glGetShaderiv(shader_id, GL_COMPILE_STATUS, &success);
|
||||
if (not success)
|
||||
{
|
||||
GLint log_length{};
|
||||
glGetShaderiv(shader_id, GL_INFO_LOG_LENGTH, &log_length);
|
||||
|
||||
auto log = std::string(log_length, ' ');
|
||||
glGetShaderInfoLog(shader_id, log_length, nullptr, log.data());
|
||||
|
||||
ztu::logger::warn("Error while compiling shader:\n%", log);
|
||||
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
}
|
||||
}
|
||||
|
||||
data = shader_data{ shader_id, type };
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user