editorconfig
[zinnia.git] / src / shaders.h
blobc24b6c78c00f72605d8abd8f12121e7b93e355cb
1 #pragma once
3 #include <GL/gl3w.h>
4 #include <vector>
5 #include <string>
6 #include <map>
7 #include <set>
8 #include <experimental/filesystem>
10 namespace fs = std::experimental::filesystem;
12 class ShaderBundle {
13 public:
14 using ShaderHandle = GLuint;
15 using ProgramHandle = GLuint;
16 using ShaderType = GLenum;
18 struct ShaderId {
19 fs::path path;
20 ShaderType type;
21 bool operator<(const ShaderId& rhs) const {
22 return std::tie(path, type) < std::tie(rhs.path, rhs.type);
24 bool operator==(const ShaderId& rhs) const {
25 return std::tie(path, type) == std::tie(rhs.path, rhs.type);
29 struct Shader {
30 ShaderHandle handle;
32 int32_t hash;
35 struct Program {
36 // public handle; 0 until the program has successfully linked
37 ProgramHandle handle;
39 ProgramHandle internal_handle;
42 ShaderBundle() = default;
43 ~ShaderBundle();
45 std::map<ShaderId, Shader> shader_pool;
46 std::map<std::vector<ShaderId>, Program> programs;
48 ProgramHandle* add_program(const std::vector<std::pair<fs::path, ShaderType>>& shaders);
50 ShaderBundle& recompile();
51 ShaderBundle& link();
53 static std::string preprocess(fs::path path, std::string shader);