MQEngine
载入中...
搜索中...
未找到
Tech.h
浏览该文件的文档.
1#ifndef TECH_H
2#define TECH_H
3#pragma once
4
5#include <string>
6#include <vector>
7#include <map>
8#include <functional>
9#include <set>
10#include <algorithm>
11#include "../Thirdparty/thirdparty.h"
12
13namespace MQEngine
14{
15 class DataManager;
16
23 using TechBindCallback = std::function<void(FCT::Layout* layout, const std::string& techName, const std::string& passName)>;
24
29 entt::registry& registry;
30 entt::entity entity;
31 FCT::Layout* layout;
32 FCT::RHI::CommandBuffer* cmdBuf;
33 const std::string& techName;
34 const std::string& passName;
35 };
36
41 using EntityOperationCallback = std::function<void(const EntityRenderContext& context)>;
42
46 struct TechName
47 {
48 std::string name;
49 };
50
55 {
56 std::string source;
57 };
58
63 {
64 std::string source;
65 };
66
71 {
72 std::vector<entt::type_info> include_types; // 必须包含的组件类型
73 std::vector<entt::type_info> exclude_types; // 必须排除的组件类型
74
75 template<typename... Components>
77 {
78 (include_types.push_back(entt::type_id<Components>()), ...);
79 return *this;
80 }
81
82 template<typename... Components>
84 {
85 (exclude_types.push_back(entt::type_id<Components>()), ...);
86 return *this;
87 }
88 };
89
90
91 class Tech
92 {
93 public:
97 template<typename... Args>
98 Tech(Args... args);
99
100
102
106 const std::string& getName() const { return m_name; }
107 const std::string& getVertexShaderSource() const { return m_vs_source; }
108 const std::string& getPixelShaderSource() const { return m_ps_source; }
109 const std::vector<FCT::VertexLayout>& getVertexLayouts() const { return m_vertexLayouts; }
110 const FCT::PixelLayout& getPixelLayout() const { return m_pixelLayout; }
111 const std::vector<FCT::UniformSlot>& getUniformSlots() const { return m_uniformSlots; }
112 const std::vector<FCT::SamplerSlot>& getSamplerSlots() const { return m_samplerSlots; }
113 const std::vector<FCT::TextureSlot>& getTextureSlots() const { return m_textureSlots; }
114 const std::string& getPassName() const { return m_passName; }
115 const ShaderRef& getVertexShaderRef() const { return m_vs_ref; }
116 const ShaderRef& getPixelShaderRef() const { return m_ps_ref; }
119
123 void executeEntityOperationCallback(entt::registry& registry, entt::entity entity, FCT::Layout* layout, FCT::RHI::CommandBuffer* cmdBuf) const {
125 EntityRenderContext context{registry, entity, layout, cmdBuf, m_name, m_passName};
127 }
128 }
129
130
134 void setPassName(const std::string& passName) { m_passName = passName; }
135 void setVertexShaderRef(const ShaderRef& ref) { m_vs_ref = ref; }
136 void setPixelShaderRef(const ShaderRef& ref) { m_ps_ref = ref; }
137 void setBindCallback(const TechBindCallback& callback) { m_bindCallback = callback; }
140
144 void executeBindCallback(FCT::Layout* layout) const {
145 if (m_bindCallback) {
147 }
148 }
149
150
151 private:
152 // --- 构造函数参数处理 ---
153 void processArgs() {} // 终止递归
154
155 template<typename... Args>
156 void processArgs(const TechName& name, Args... args);
157
158 template<typename... Args>
159 void processArgs(const VertexShaderSource& vs, Args... args);
160
161 template<typename... Args>
162 void processArgs(const PixelShaderSource& ps, Args... args);
163
164 template<typename... Args>
165 void processArgs(const FCT::VertexLayout& layout, Args... args);
166
167 template<typename... Args>
168 void processArgs(const std::vector<FCT::VertexLayout>& layouts, Args... args);
169
170 template<typename... Args>
171 void processArgs(const FCT::PixelLayout& layout, Args... args);
172
173 template<typename... Args>
174 void processArgs(const FCT::UniformSlot& slot, Args... args);
175
176 template<typename... Args>
177 void processArgs(const std::vector<FCT::UniformSlot>& slots, Args... args);
178
179 template<typename... Args>
180 void processArgs(const FCT::SamplerSlot& slot, Args... args);
181
182 template<typename... Args>
183 void processArgs(const std::vector<FCT::SamplerSlot>& slots, Args... args);
184
185 template<typename... Args>
186 void processArgs(const FCT::TextureSlot& slot, Args... args);
187
188 template<typename... Args>
189 void processArgs(const std::vector<FCT::TextureSlot>& slots, Args... args);
190
191 template<typename... Args>
192 void processArgs(const ComponentFilter& filter, Args... args);
193
194 template<typename... Args>
195 void processArgs(const TechBindCallback& callback, Args... args);
196
197 template<typename... Args>
198 void processArgs(const EntityOperationCallback& callback, Args... args);
199
200 // --- 成员变量 ---
201 std::string m_name;
202 std::string m_vs_source;
203 std::string m_ps_source;
204 std::vector<FCT::VertexLayout> m_vertexLayouts;
205 FCT::PixelLayout m_pixelLayout;
206 std::vector<FCT::UniformSlot> m_uniformSlots;
207 std::vector<FCT::SamplerSlot> m_samplerSlots;
208 std::vector<FCT::TextureSlot> m_textureSlots;
211 std::string m_passName;
213 TechBindCallback m_bindCallback; // Tech绑定回调函数
215 };
216
218 {
219 public:
220 TechManager();
221
222 void addTech(const std::string& passName, Tech&& tech);
223
224 const std::vector<Tech*>& getTechsForPass(const std::string& passName);
225
226 FCT::Layout* getLayoutForTech(const std::string& techName);
227
232 void subscribeToPass(const std::string& passName);
233
234
235
236 private:
238 {
239 std::string passName;
242
243 bool operator<(const LayoutKey& other) const
244 {
245 if (passName < other.passName) return true;
246 if (passName > other.passName) return false;
247 if (vertexLayoutHash < other.vertexLayoutHash) return true;
248 if (vertexLayoutHash > other.vertexLayoutHash) return false;
249 return pixelLayoutHash < other.pixelLayoutHash;
250 }
251 };
252
254 std::map<std::string, Tech> m_techs;
255 std::map<std::string, std::vector<Tech*>> m_passTechs;
256 std::map<LayoutKey, std::unique_ptr<FCT::Layout>> m_layouts;
257 std::map<std::string, FCT::Layout*> m_techToLayoutMap;
258 std::set<std::string> m_subscribedPasses; // 跟踪已订阅的Pass
259 std::map<std::string, FCT::OutputInfo> m_passOutputInfos; // 存储各Pass的输出信息
261 };
262}
263#endif
定义 DataManager.h:58
定义 Tech.h:92
const ShaderRef & getPixelShaderRef() const
定义 Tech.h:116
std::string m_vs_source
定义 Tech.h:202
std::vector< FCT::UniformSlot > m_uniformSlots
定义 Tech.h:206
Tech(Args... args)
定义 Tech.hpp:8
const std::vector< FCT::UniformSlot > & getUniformSlots() const
定义 Tech.h:111
ShaderRef m_vs_ref
定义 Tech.h:209
const std::vector< FCT::TextureSlot > & getTextureSlots() const
定义 Tech.h:113
const std::vector< FCT::SamplerSlot > & getSamplerSlots() const
定义 Tech.h:112
EntityOperationCallback m_entityOperationCallback
定义 Tech.h:214
void setBindCallback(const TechBindCallback &callback)
定义 Tech.h:137
void setVertexShaderRef(const ShaderRef &ref)
定义 Tech.h:135
void setPassName(const std::string &passName)
定义 Tech.h:134
std::string m_name
定义 Tech.h:201
std::string m_passName
定义 Tech.h:211
const FCT::PixelLayout & getPixelLayout() const
定义 Tech.h:110
std::vector< FCT::TextureSlot > m_textureSlots
定义 Tech.h:208
void executeBindCallback(FCT::Layout *layout) const
定义 Tech.h:144
TechBindCallback m_bindCallback
定义 Tech.h:213
const std::string & getPassName() const
定义 Tech.h:114
void executeEntityOperationCallback(entt::registry &registry, entt::entity entity, FCT::Layout *layout, FCT::RHI::CommandBuffer *cmdBuf) const
定义 Tech.h:123
std::string m_ps_source
定义 Tech.h:203
ShaderRef m_ps_ref
定义 Tech.h:210
std::vector< FCT::VertexLayout > m_vertexLayouts
定义 Tech.h:204
const std::string & getPixelShaderSource() const
定义 Tech.h:108
const ShaderRef & getVertexShaderRef() const
定义 Tech.h:115
const std::vector< FCT::VertexLayout > & getVertexLayouts() const
定义 Tech.h:109
FCT::PixelLayout m_pixelLayout
定义 Tech.h:205
void processArgs()
定义 Tech.h:153
ComponentFilter m_componentFilter
定义 Tech.h:212
void setEntityOperationCallback(const EntityOperationCallback &callback)
定义 Tech.h:138
const std::string & getName() const
定义 Tech.h:106
std::vector< FCT::SamplerSlot > m_samplerSlots
定义 Tech.h:207
const std::string & getVertexShaderSource() const
定义 Tech.h:107
const ComponentFilter & getComponentFilter() const
定义 Tech.h:117
void setPixelShaderRef(const ShaderRef &ref)
定义 Tech.h:136
void subscribeToPass(const std::string &passName)
为指定Pass订阅渲染事件和PassInfo更新
定义 Tech.cpp:100
std::map< std::string, FCT::Layout * > m_techToLayoutMap
定义 Tech.h:257
FCT::Layout * getLayoutForTech(const std::string &techName)
定义 Tech.cpp:44
DataManager * m_dataManager
定义 Tech.h:260
std::map< std::string, Tech > m_techs
定义 Tech.h:254
TechManager()
定义 Tech.cpp:13
const std::vector< Tech * > & getTechsForPass(const std::string &passName)
定义 Tech.cpp:33
std::map< std::string, std::vector< Tech * > > m_passTechs
定义 Tech.h:255
std::map< std::string, FCT::OutputInfo > m_passOutputInfos
定义 Tech.h:259
std::map< LayoutKey, std::unique_ptr< FCT::Layout > > m_layouts
定义 Tech.h:256
std::set< std::string > m_subscribedPasses
定义 Tech.h:258
Context * m_ctx
定义 Tech.h:253
void addTech(const std::string &passName, Tech &&tech)
定义 Tech.cpp:19
定义 application.h:5
FCT::Context Context
定义 EngineGlobal.h:14
std::function< void(const EntityRenderContext &context)> EntityOperationCallback
实体操作回调函数类型
定义 Tech.h:41
FCT::ShaderRef ShaderRef
定义 thirdparty.h:28
std::function< void(FCT::Layout *layout, const std::string &techName, const std::string &passName)> TechBindCallback
Tech绑定回调函数类型
定义 Tech.h:23
定义组件过滤器,用于runtime view
定义 Tech.h:71
std::vector< entt::type_info > exclude_types
定义 Tech.h:73
std::vector< entt::type_info > include_types
定义 Tech.h:72
ComponentFilter & include()
定义 Tech.h:76
ComponentFilter & exclude()
定义 Tech.h:83
实体渲染上下文结构体
定义 Tech.h:28
FCT::Layout * layout
定义 Tech.h:31
const std::string & passName
定义 Tech.h:34
const std::string & techName
定义 Tech.h:33
FCT::RHI::CommandBuffer * cmdBuf
定义 Tech.h:32
entt::registry & registry
定义 Tech.h:29
entt::entity entity
定义 Tech.h:30
定义像素着色器源码
定义 Tech.h:63
std::string source
定义 Tech.h:64
bool operator<(const LayoutKey &other) const
定义 Tech.h:243
std::string passName
定义 Tech.h:239
size_t vertexLayoutHash
定义 Tech.h:240
size_t pixelLayoutHash
定义 Tech.h:241
定义Tech的名称
定义 Tech.h:47
std::string name
定义 Tech.h:48
定义顶点着色器源码
定义 Tech.h:55
std::string source
定义 Tech.h:56