candlewick 0.1.0
A renderer
Loading...
Searching...
No Matches
Shader.h
Go to the documentation of this file.
1
2#pragma once
3
4#include "Core.h"
5#include <SDL3/SDL_gpu.h>
6
7namespace candlewick {
8
9constexpr const char *g_default_shader_dir = CANDLEWICK_SHADER_BIN_DIR;
10
13void setShadersDirectory(const char *path);
16
17SDL_GPUShaderStage detect_shader_stage(const char *filename);
18
19const char *shader_format_name(SDL_GPUShaderFormat shader_format);
20
26struct Shader {
29 struct Config {
31 Uint32 samplers;
32 Uint32 storage_textures = 0;
33 Uint32 storage_buffers = 0;
34 };
35
40 Shader(const Device &device, const char *filename, const Config &config);
42 Shader(const Shader &) = delete;
44 Shader(Shader &&other) noexcept;
45
46 operator SDL_GPUShader *() const noexcept { return _shader; }
47 void release() noexcept;
48 ~Shader() noexcept { release(); }
49
51 static Shader fromMetadata(const Device &device, const char *filename);
52
53private:
54 SDL_GPUShader *_shader;
55 SDL_GPUDevice *_device;
56};
57
58inline Shader::Shader(Shader &&other) noexcept
59 : _shader(other._shader), _device(other._device) {
60 other._shader = nullptr;
61 other._device = nullptr;
62}
63
66Shader::Config loadShaderMetadata(const char *shader_name);
67
68inline Shader Shader::fromMetadata(const Device &device,
69 const char *shader_name) {
70 auto config = loadShaderMetadata(shader_name);
71 return Shader{device, shader_name, config};
72}
73
74} // namespace candlewick
Definition Camera.h:8
void setShadersDirectory(const char *path)
Set the current (global) directory where shaders are to be found.
const char * currentShaderDirectory()
Get the current (global) directory where shaders are found.
Shader::Config loadShaderMetadata(const char *shader_name)
Load shader config from metadata. Metadata filename (in JSON format) is inferred from the shader name...
constexpr const char * g_default_shader_dir
Definition Shader.h:9
SDL_GPUShaderStage detect_shader_stage(const char *filename)
const char * shader_format_name(SDL_GPUShaderFormat shader_format)
RAII wrapper for SDL_GPUDevice.
Definition Device.h:17
Shader configuration: number of uniforms, texture samplers, storage textures and storage buffers.
Definition Shader.h:29
Uint32 storage_buffers
Definition Shader.h:33
Uint32 samplers
Definition Shader.h:31
Uint32 storage_textures
Definition Shader.h:32
Uint32 uniform_buffers
Definition Shader.h:30
RAII wrapper around SDL_GPUShader, with loading utilities.
Definition Shader.h:26
Shader(const Shader &)=delete
Deleted copy constructor.
void release() noexcept
static Shader fromMetadata(const Device &device, const char *filename)
Load shader from metadata.
Definition Shader.h:68
Shader(const Device &device, const char *filename, const Config &config)
Load a shader to device provided the shader name and configuration.