14 struct ShaderAssetChoice
22 std::expected<ShaderAssetChoice, World3DShaderError>
26 return std::unexpected(World3DShaderError{
37 return std::unexpected(World3DShaderError{
39 "SPIR-V World3D texture shader has not been regenerated; refusing the stale untextured asset"});
41 return std::unexpected(World3DShaderError{
43 "device exposes no current generated World3D shader format"});
46 std::expected<std::vector<Uint8>, World3DShaderError>
49 if (!std::filesystem::exists(
path))
50 return std::unexpected(World3DShaderError{
53 std::ifstream stream(
path, std::ios::binary);
55 return std::unexpected(World3DShaderError{
58 std::vector<Uint8>
bytes{
59 std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>()};
60 if (!stream.eof() && stream.fail())
61 return std::unexpected(World3DShaderError{
66 std::expected<SDL_GPUShader*, World3DShaderError>
createShader(
68 const std::filesystem::path&
path,
69 const ShaderAssetChoice& choice,
73 if (!
bytes)
return std::unexpected(
bytes.error());
76 info.code_size = choice.text ?
bytes->size() - 1U :
bytes->size();
77 info.code =
bytes->data();
78 info.entrypoint = choice.entrypoint;
79 info.format = choice.format;
81 info.num_uniform_buffers = 1;
86 return std::unexpected(World3DShaderError{
99 *
this = std::move(
other);
103 if (
this == &
other)
return *
this;
105 device_ = std::exchange(
other.device_,
nullptr);
106 vertex_ = std::exchange(
other.vertex_,
nullptr);
107 fragment_ = std::exchange(
other.fragment_,
nullptr);
109 entrypoint_ = std::exchange(
other.entrypoint_,
"main");
121 entrypoint_ =
"main";
129 if (!choice)
return std::unexpected(choice.error());
131 const std::string
name =
modernPBR ?
"ModernPBR" :
"World3D";
141 return std::unexpected(
fragment.error());
145 result.device_ = device;
148 result.format_ = choice->format;
149 result.entrypoint_ = choice->entrypoint;
std::vector< std::byte > bytes
SDL_GPUShaderFormat format
static std::expected< World3DShaderSet, World3DShaderError > load(SDL_GPUDevice *device, const std::filesystem::path &shaderDirectory, bool modernPBR=false)
World3DShaderSet & operator=(const World3DShaderSet &)=delete
World3DShaderSet()=default
SDL_GPUShader * vertex() const noexcept
SDL_GPUShader * fragment() const noexcept