This commit is contained in:
ZY4N
2024-12-22 16:58:40 +01:00
parent 2704814de2
commit db8db8f9d7
161 changed files with 17102 additions and 0 deletions

View 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 {};
}
}