diff options
| author | hachem <im@hachem.wtf> | 2026-08-20 22:05:09 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-20 22:05:09 +0200 |
| commit | 0f49e8fd2a364f91f0a4c3bc2210fac4d9bf2ecc (patch) | |
| tree | 8afb5564714fec75b19dbe3b7a42df2cfbee34c5 /src/rendering/shader.h | |
| parent | 85b63b3b61174a99811f3cba235da4537634edd4 (diff) | |
refactor: fold the OpenGL backend classes into rendering
Diffstat (limited to 'src/rendering/shader.h')
| -rw-r--r-- | src/rendering/shader.h | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/src/rendering/shader.h b/src/rendering/shader.h index 7e4f48c..c974ec4 100644 --- a/src/rendering/shader.h +++ b/src/rendering/shader.h @@ -11,34 +11,55 @@ #define TEXTURE_FETCH_BARRIER_BIT 0x00000008 #define IMAGE_ACCESS_BARRIER_BIT 0x00000020 -namespace Donut +namespace Donut { class Shader { public: - virtual ~Shader() = default; + Shader(const std::string& filepath); + Shader(const std::string& name, const std::string& vertex_src, const std::string& fragment_src); + Shader(const std::string& name, const std::string& compute_src); + ~Shader(); - virtual auto bind() const -> void = 0; - virtual auto unbind() const -> void = 0; + auto bind() const -> void; + auto unbind() const -> void; - virtual auto set_int( const std::string& name, int value) -> void = 0; - virtual auto set_int_array(const std::string& name, int* values, uint32_t count) -> void = 0; - virtual auto set_float( const std::string& name, float value) -> void = 0; - virtual auto set_float2( const std::string& name, const glm::vec2& value) -> void = 0; - virtual auto set_float3( const std::string& name, const glm::vec3& value) -> void = 0; - virtual auto set_float4( const std::string& name, const glm::vec4& value) -> void = 0; - virtual auto set_mat4( const std::string& name, const glm::mat4& value) -> void = 0; + auto set_int( const std::string& name, int value) -> void; + auto set_int_array(const std::string& name, int* values, uint32_t count) -> void; + auto set_float( const std::string& name, float value) -> void; + auto set_float2( const std::string& name, const glm::vec2& value) -> void; + auto set_float3( const std::string& name, const glm::vec3& value) -> void; + auto set_float4( const std::string& name, const glm::vec4& value) -> void; + auto set_mat4( const std::string& name, const glm::mat4& value) -> void; - virtual auto dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) -> void = 0; - virtual auto dispatch_indirect(uint32_t offset = 0) -> void = 0; - virtual auto memory_barrier(uint32_t barriers) -> void = 0; + auto dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) -> void; + auto dispatch_indirect(uint32_t offset = 0) -> void; + auto memory_barrier(uint32_t barriers) -> void; - virtual auto get_name() const -> const std::string& = 0; - virtual auto get_renderer_id() const -> uint32_t = 0; + auto get_name() const -> const std::string& { return m_name; } + auto get_renderer_id() const -> uint32_t { return m_renderer_id; } + + auto upload_uniform_int( const std::string& name, int value) -> void; + auto upload_uniform_int_array(const std::string& name, int* values, uint32_t count) -> void; + auto upload_uniform_float( const std::string& name, float value) -> void; + auto upload_uniform_float2( const std::string& name, const glm::vec2& value) -> void; + auto upload_uniform_float3( const std::string& name, const glm::vec3& value) -> void; + auto upload_uniform_float4( const std::string& name, const glm::vec4& value) -> void; + auto upload_uniform_mat3( const std::string& name, const glm::mat3& matrix) -> void; + auto upload_uniform_mat4( const std::string& name, const glm::mat4& matrix) -> void; static auto create(const std::string& filepath) -> Shader*; static auto create(const std::string& name, const std::string& vertex_src, const std::string& fragment_src) -> Shader*; static auto create_compute(const std::string& name, const std::string& compute_src) -> Shader*; + + private: + auto read_file(const std::string& filepath) -> std::string; + auto pre_process(const std::string& source) -> std::unordered_map<uint32_t, std::string>; + auto compile(const std::unordered_map<uint32_t, std::string>& shader_sources) -> void; + + uint32_t m_renderer_id = 0; + std::string m_name; + bool m_is_slang = false; }; class ShaderLibrary @@ -49,7 +70,7 @@ namespace Donut auto load(const std::string& filepath) -> Ref<Shader>; auto load(const std::string& name, const std::string& filepath) -> Ref<Shader>; - Ref<Shader> get(const std::string& name); + auto get(const std::string& name) -> Ref<Shader>; auto exists(const std::string& name) const -> bool; private: |
