summaryrefslogtreecommitdiff
path: root/gfx/gl/shader.h
blob: 1a8ddefa409cd21ee70e4e74e2f87222279ce62b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#pragma once

#include <GL/glew.h>
#include <glRef.hpp>
#include <optional>
#include <string_view>

class Shader {
public:
	constexpr Shader(const GLchar * text, GLint len, GLuint type) : text {text}, len {len}, type {type} { }

	operator GLuint() const;
	static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage);

private:
	using ShaderRef = glRef<GLuint, &__glewCreateShader, &__glewDeleteShader>;
	const GLchar * text;
	GLint len;
	GLuint type;
	mutable std::optional<ShaderRef> shader {};
};