1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#pragma once
#include <string>
#include <unordered_map>
#include <memory>
#include <glm/glm.hpp>
#define SHADER_STORAGE_BARRIER_BIT 0x00002000
#define UNIFORM_BARRIER_BIT 0x00000004
#define TEXTURE_FETCH_BARRIER_BIT 0x00000008
#define IMAGE_ACCESS_BARRIER_BIT 0x00000020
namespace Donut
{
class Shader
{
public:
virtual ~Shader() = default;
virtual void bind() const = 0;
virtual void unbind() const = 0;
virtual void set_int( const std::string& name, int value) = 0;
virtual void set_int_array(const std::string& name, int* values, uint32_t count) = 0;
virtual void set_float( const std::string& name, float value) = 0;
virtual void set_float2( const std::string& name, const glm::vec2& value) = 0;
virtual void set_float3( const std::string& name, const glm::vec3& value) = 0;
virtual void set_float4( const std::string& name, const glm::vec4& value) = 0;
virtual void set_mat4( const std::string& name, const glm::mat4& value) = 0;
virtual void dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) = 0;
virtual void dispatch_indirect(uint32_t offset = 0) = 0;
virtual void memory_barrier(uint32_t barriers) = 0;
virtual const std::string& get_name() const = 0;
static Shader* create(const std::string& filepath);
static Shader* create(const std::string& name, const std::string& vertex_src, const std::string& fragment_src);
static Shader* create_compute(const std::string& name, const std::string& compute_src);
};
class ShaderLibrary
{
public:
void add(const std::shared_ptr<Shader>& shader);
void add(const std::string& name, const std::shared_ptr<Shader>& shader);
std::shared_ptr<Shader> load(const std::string& filepath);
std::shared_ptr<Shader> load(const std::string& name, const std::string& filepath);
std::shared_ptr<Shader> get(const std::string& name);
bool exists(const std::string& name) const;
private:
std::unordered_map<std::string, std::shared_ptr<Shader>> m_shaders;
};
};
|