SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
Shader.h
1#pragma once
2
3#include "spark/render/Export.h"
4#include "spark/render/Pipeline.h"
5#include "spark/render/ShaderStages.h"
6
7#include <algorithm>
8#include <memory>
9#include <string>
10
11namespace spark::render
12{
17 class SPARK_RENDER_EXPORT IShaderModule
18 {
19 public:
20 virtual ~IShaderModule() noexcept = default;
21
26 [[nodiscard]] virtual ShaderStage stage() const noexcept = 0;
27
32 [[nodiscard]] virtual const std::string& fileName() const noexcept = 0;
33
38 [[nodiscard]] virtual const std::string& entryPoint() const noexcept = 0;
39 };
40
44 class SPARK_RENDER_EXPORT IShaderProgram
45 {
46 public:
47 virtual ~IShaderProgram() noexcept = default;
48
53 [[nodiscard]] std::vector<const IShaderModule*> shaders() const noexcept { return genericShaders(); }
54
64 [[nodiscard]] virtual std::shared_ptr<IPipelineLayout> reflectPipelineLayout() const = 0;
65
66 private:
68 [[nodiscard]] virtual std::vector<const IShaderModule*> genericShaders() const noexcept = 0;
69 };
70
75 template <typename ShaderModuleType>
77 {
78 public:
79 using shader_module_type = ShaderModuleType;
80
81 public:
83 [[nodiscard]] virtual std::vector<const shader_module_type*> shaders() const noexcept = 0;
84
85 private:
86 [[nodiscard]] std::vector<const IShaderModule*> genericShaders() const noexcept final
87 {
88 auto tmp = shaders();
89 std::vector<const IShaderModule*> result;
90 result.reserve(tmp.size());
91 std::ranges::transform(tmp, std::back_inserter(result), [](const auto& shader) { return static_cast<const IShaderModule*>(shader); });
92 return result;
93 }
94 };
95}
Interface representing a single shader module, a part of a IShaderProgram.
Definition Shader.h:18
virtual ShaderStage stage() const noexcept=0
Gets the type of the shader.
Interface representing a shader program, a collection of IShaderModule.
Definition Shader.h:45
virtual std::shared_ptr< IPipelineLayout > reflectPipelineLayout() const =0
Uses shader reflexion to extract the pipeline layout from this shader program.
std::vector< const IShaderModule * > shaders() const noexcept
Gets all shaders contained in this program.
Definition Shader.h:53
Represents a shader program with a specific type of IShaderModule.
Definition Shader.h:77
virtual std::vector< const shader_module_type * > shaders() const noexcept=0
Gets all shaders contained in this program.