| 188 | /// Represents a single shader module made up from a list of sources (files/strings). |
| 189 | /// A shader module corresponds to a single translation unit. |
| 190 | struct ShaderModule |
| 191 | { |
| 192 | /// The name of the shader module. |
| 193 | /// This is the name used by other modules to import this module. |
| 194 | /// If left empty, a name based on a hash from the module sources will be generated. |
| 195 | std::string name; |
| 196 | |
| 197 | /// List of shader sources. |
| 198 | std::vector<ShaderSource> sources; |
| 199 | |
| 200 | ShaderModule() = default; |
| 201 | explicit ShaderModule(std::string name_) : name(std::move(name_)) {} |
| 202 | |
| 203 | /// Create a shader module description containing a single file. |
| 204 | static ShaderModule fromFile(std::filesystem::path path) |
| 205 | { |
| 206 | ShaderModule sm; |
| 207 | sm.addFile(std::move(path)); |
| 208 | return sm; |
| 209 | } |
| 210 | |
| 211 | /// Create a shader module description containing a single string. |
| 212 | static ShaderModule fromString(std::string string, std::filesystem::path path = {}, std::string moduleName = {}) |
| 213 | { |
| 214 | ShaderModule sm(std::move(moduleName)); |
| 215 | sm.addString(std::move(string), std::move(path)); |
| 216 | return sm; |
| 217 | } |
| 218 | |
| 219 | /// Add a source file to the shader module. |
| 220 | ShaderModule& addFile(std::filesystem::path path) |
| 221 | { |
| 222 | sources.push_back({ShaderSource::Type::File, std::move(path), {}}); |
| 223 | return *this; |
| 224 | } |
| 225 | |
| 226 | /// Add a source string to the shader module. |
| 227 | /// The path is optional and only used for diagnostic purposes. |
| 228 | ShaderModule& addString(std::string string, std::filesystem::path path = {}) |
| 229 | { |
| 230 | sources.push_back({ShaderSource::Type::String, std::move(path), std::move(string)}); |
| 231 | return *this; |
| 232 | } |
| 233 | |
| 234 | bool operator==(const ShaderModule& rhs) const { return name == rhs.name && sources == rhs.sources; } |
| 235 | }; |
| 236 | |
| 237 | /// Represents a single entry point. |
| 238 | struct EntryPoint |