Toast Engine
Loading...
Searching...
No Matches
material.hpp
Go to the documentation of this file.
1
8
9#pragma once
10#include "core_types.hpp"
11#include "data.hpp"
12#include "shader.hpp"
13
14namespace assets {
15
16enum class BlendMode : uint8_t {
17 opaque,
18 alpha,
19 additive,
20 multiply,
21};
22
23enum class CullMode : uint8_t {
24 none,
25 front,
26 back,
27};
28
34 BlendMode blend_mode = BlendMode::opaque;
35 bool depth_test = true;
36 bool depth_write = true;
37 CullMode cull_mode = CullMode::back;
38};
39
49class TOAST_API Material : public Data {
50public:
51 explicit Material(const toml::table& table, Handle<Schema> schema = {});
52 ~Material() override;
53
54 [[nodiscard]]
55 auto type() const -> std::string_view override {
56 return "material";
57 }
58
59 [[nodiscard]]
60 auto serialize(SaveMode mode) const -> std::vector<uint8_t> override;
61
62 void reload(const toml::table& table) override;
63
64 [[nodiscard]]
65 auto name() const -> std::string;
66
67 [[nodiscard]]
68 virtual auto shaders() const -> const std::vector<Handle<Shader>>&;
69
70 [[nodiscard]]
71 virtual auto settings() const -> MaterialSettings;
72
76 [[nodiscard]]
77 virtual auto value(std::string_view key) const -> const DataValue*;
78
82 [[nodiscard]]
83 virtual auto rootMaterial() -> Material* {
84 return this;
85 }
86
87private:
88 mutable std::vector<Handle<Shader>> m_shader_handles;
89 mutable bool m_shaders_dirty = true;
90};
91}
Typed value for TOML files.
Definition data_value.hpp:50
Type-safe smart pointer for assets.
Definition core_types.hpp:149
virtual auto rootMaterial() -> Material *
The material owning the render pass, instances return their parent.
Definition material.hpp:83
void reload(const toml::table &table) override
Re-parses the asset contents in place.
Definition material.cpp:32
auto name() const -> std::string
Display name of the material.
Definition material.cpp:37
virtual auto value(std::string_view key) const -> const DataValue *
Looks up a shader parameter value by name.
Definition material.cpp:112
Base types for the asset system.
SaveMode
Definition core_types.hpp:25
Typed data asset backed by schema-driven TOML.
Slang shader source asset, compiled to SPIR-V by the renderer's ShaderCache.
Fixed-function pipeline state carried by the material's [settings] block.
Definition material.hpp:33