11 _gl GLenum type, std::string_view source) {
12 _gl GLuint shader = _gl glCreateShader(type);
13 const char *src = source.data();
14 _gl glShaderSource(shader, 1, &src,
nullptr);
15 _gl glCompileShader(shader);
17 _gl glGetShaderiv(shader, _gl GL_COMPILE_STATUS, &ok);
20 _gl glGetShaderiv(shader, _gl GL_INFO_LOG_LENGTH, &length);
21 std::string log(length,
'\0');
22 _gl glGetShaderInfoLog(shader, length,
nullptr, log.data());
23 _E(
"Failed to compile shader: " << log);
24 throw std::runtime_error(log);
26 return Shader{type, shader};
29 _gl GLenum type, std::string_view file_path) {
30 _I(
"Loading shader from file: " << file_path);
31 std::ifstream file(file_path.data());
32 if (!file.is_open()) {
33 throw std::runtime_error(
_STD string(
"Failed to open file: ") +
34 _STD string(file_path.data()));
36 std::string source((std::istreambuf_iterator<char>(file)),
37 std::istreambuf_iterator<char>());
39 _I(
"Shader source: " << source);
40 return from_source(type, source);