VenomEngine
Cross-Platform Modern Graphics Engine
Loading...
Searching...
No Matches
ShaderPipeline.h
Go to the documentation of this file.
1
8#pragma once
9
12
13namespace venom
14{
15namespace common
16{
17class VENOM_COMMON_API ShaderResource : public GraphicsCachedResource
18{
19public:
20 ShaderResource(GraphicsCachedResourceHolder * holder);
21
22 Vector<String> shaderPaths;
23};
24
25enum class ShaderVertexFormat
26{
27 Float,
28 Vec2,
29 Vec3,
30 Vec4,
31 Int,
32 IVec2,
33 IVec3,
34 IVec4,
35 Uint,
36 UVec2,
37 UVec3,
38 UVec4,
39 Mat2,
40 Mat3,
41 Mat4
42};
43
44class VENOM_COMMON_API ShaderPipelineImpl : public PluginObjectImpl, public GraphicsPluginObject, public GraphicsCachedResourceHolder
45{
46public:
47 ShaderPipelineImpl();
48 virtual ~ShaderPipelineImpl() = default;
49
56 vc::Error LoadShaderFromFile(const vc::String & path);
57
59 {
60 const ShaderVertexFormat format;
61 const uint32_t binding;
62 const uint32_t location;
63 const uint32_t offset;
64 };
65
72 void AddVertexBufferToLayout(const ShaderVertexFormat format, const uint32_t binding, const uint32_t location, const uint32_t offset);
82 void AddVertexBufferToLayout(const vc::Vector<VertexBufferLayout> & layouts);
83
84
89 void SetCustomMultiSamplingCount(const int samples);
90 void SetMultiSamplingCount(const int samples);
91 inline vc::Error SetLineWidth(const float width) { _SetLineWidth(width); return _ReloadShaderAfterSettings(); }
92 inline vc::Error SetDepthTest(const bool enable) { _SetDepthTest(enable); return _ReloadShaderAfterSettings(); }
93 inline vc::Error SetDepthWrite(const bool enable) { _SetDepthWrite(enable); return _ReloadShaderAfterSettings(); }
94 inline vc::Error OpenAndReloadShader()
95 {
96 if (_OpenShaders() != vc::Error::Success) return vc::Error::Failure;
97 return _ReloadShader();
98 }
99
100 inline void SetRenderingPipelineType(const RenderingPipelineType type) { _renderingPipelineType = type; }
101 inline void SetRenderingPipelineShaderType(const RenderingPipelineShaderType type) { _renderingPipelineShaderType = type; }
102 inline void SetRenderingPipelineIndex(const uint32_t index) { _renderingPipelineIndex = index; }
103
104 inline RenderingPipelineType GetRenderingPipelineType() const { return _renderingPipelineType; }
105 inline RenderingPipelineShaderType GetRenderingPipelineShaderType() const { return _renderingPipelineShaderType; }
106
107protected:
108 virtual void _SetMultiSamplingCount(const int samples) = 0;
109 virtual void _SetLineWidth(const float width) = 0;
110 virtual void _SetDepthTest(const bool enable) = 0;
111 virtual void _SetDepthWrite(const bool enable) = 0;
112 virtual vc::Error _LoadShader(const vc::String & path) = 0;
113 virtual void _AddVertexBufferToLayout(const uint32_t vertexSize, const uint32_t binding, const uint32_t location, const uint32_t offset, const ShaderVertexFormat format) = 0;
114
115 virtual vc::Error _OpenShaders() = 0;
116 virtual vc::Error _ReloadShader() = 0;
117 inline vc::Error _ReloadShaderAfterSettings() {
118 if (_loaded) return _ReloadShader();
119 return vc::Error::Success;
120 }
121protected:
122 RenderingPipelineType _renderingPipelineType;
123 RenderingPipelineShaderType _renderingPipelineShaderType;
124 uint32_t _renderingPipelineIndex;
125 bool _loaded;
126
127private:
128 bool __customSamples;
129};
130
131class VENOM_COMMON_API ShaderPipeline : public PluginObjectImplWrapper
132{
133public:
134 ShaderPipeline();
135 ShaderPipeline(const char * path);
136 ~ShaderPipeline();
137
138 static vc::Error RecompileAllShaders();
139 static vc::Error ReloadAllShaders();
140 inline vc::Error OpenAndReloadShader() { return _impl->As<ShaderPipelineImpl>()->OpenAndReloadShader(); }
141 inline void SetRenderingPipelineIndex(const uint32_t index) { _impl->As<ShaderPipelineImpl>()->SetRenderingPipelineIndex(index); }
142 inline void SetRenderingPipelineType(const RenderingPipelineType type) { _impl->As<ShaderPipelineImpl>()->SetRenderingPipelineType(type); }
143 inline void SetRenderingPipelineShaderType(const RenderingPipelineShaderType type) { _impl->As<ShaderPipelineImpl>()->SetRenderingPipelineShaderType(type); }
144 inline vc::Error LoadShaderFromFile(const char * path) { return _impl->As<ShaderPipelineImpl>()->LoadShaderFromFile(path); }
145 inline void AddVertexBufferToLayout(const ShaderVertexFormat format, const uint32_t binding, const uint32_t location, const uint32_t offset) { _impl->As<ShaderPipelineImpl>()->AddVertexBufferToLayout(format, binding, location, offset); }
146 inline void AddVertexBufferToLayout(const ShaderPipelineImpl::VertexBufferLayout & layout) { _impl->As<ShaderPipelineImpl>()->AddVertexBufferToLayout(layout); }
147 inline void AddVertexBufferToLayout(const vc::Vector<ShaderPipelineImpl::VertexBufferLayout> & layouts) { _impl->As<ShaderPipelineImpl>()->AddVertexBufferToLayout(layouts); }
148 inline void SetLineWidth(const float width) { _impl->As<ShaderPipelineImpl>()->SetLineWidth(width); }
149 inline void SetDepthTest(const bool enable) { _impl->As<ShaderPipelineImpl>()->SetDepthTest(enable); }
150 inline void SetDepthWrite(const bool enable) { _impl->As<ShaderPipelineImpl>()->SetDepthWrite(enable); }
151
152 inline void SetCustomMultiSamplingCount(const int samples) { _impl->As<ShaderPipelineImpl>()->SetCustomMultiSamplingCount(samples); }
153};
154}
155}
Base class for cached resource holders.
Definition GraphicsPluginObject.h:63
Definition ShaderPipeline.h:45
void SetCustomMultiSamplingCount(const int samples)
To separate from Swap Chain multisampling.
Definition ShaderPipeline.cc:130
vc::Error LoadShaderFromFile(const vc::String &path)
Load a shader from a base path (e.g. ./shader_mesh to load ./shader_mesh.vert and ....
Definition ShaderPipeline.cc:36
void AddVertexBufferToLayout(const ShaderVertexFormat format, const uint32_t binding, const uint32_t location, const uint32_t offset)
Add a vertex buffer to the layout.
Definition ShaderPipeline.cc:60
High-Level Frontend of the VenomEngine project. It also contains all the code shared between every AP...
Definition Callback.h:15
Contains the entirety of the code of the VenomEngine project.
Definition Callback.h:13