FCT
载入中...
搜索中...
未找到
layout.h
浏览该文件的文档.
1//
2// Created by Administrator on 2025/8/17.
3//
4
5#ifndef LAYOUT_H
6#define LAYOUT_H
7#include "ShaderStage.h"
8#include "Context.h"
9#include "UniformWrapper.h"
10namespace FCT {
13 {
14 std::string name;
15 };
16 struct PassName
17 {
18 std::string name;
19 };
24 class Layout {
25 public:
26 template<typename... Args>
27 void proccessArgs(FCT::VertexLayout vertexLayout, Args... args)
28 {
29 uint32_t index = findNextAvailableIndex();
30 m_vertexLayouts[index] = vertexLayout;
31 m_hasVertexLayout = true;
33 proccessArgs(args...);
34 }
35 template<typename... Args>
36 void proccessArgs(SamplerSlot samplerSlot, Args... args)
37 {
38 m_resourceLayout.addSampler(samplerSlot);
39
40 if (samplerSlot.getShaderStages() & FCT::ShaderStage::Vertex)
41 {
42 m_vertexResourceLayout.addSampler(samplerSlot);
43 }
45 {
46 m_pixelResourceLayout.addSampler(samplerSlot);
47 }
48 m_resourceLayout.addSampler(samplerSlot);
49
50 proccessArgs(args...);
51 }
52 template<typename... Args>
53 void proccessArgs(PassName passName, Args... args)
54 {
55 if (m_ctx && m_ctx->getModule<FCT::RenderGraph>()) {
56 attachPass(m_ctx->getModule<FCT::RenderGraph>(), passName.name);
57 }
58 proccessArgs(args...);
59 }
60
61 template<typename... Args>
62 void proccessArgs(uint32_t index, FCT::VertexLayout vertexLayout, Args... args)
63 {
64 m_vertexLayouts[index] = vertexLayout;
65 m_hasVertexLayout = true;
67 proccessArgs(args...);
68 }
69
70
71 template<typename... Args>
72 void proccessArgs(FCT::PixelLayout pixelLayout, Args... args)
73 {
74 m_pixelLayout = pixelLayout;
75 m_hasPixelLayout = true;
77 proccessArgs(args...);
78 }
79
80 template<typename... Args>
81 void proccessArgs(TextureSlot textureSlot, Args... args)
82 {
83 m_unhandledTextureSlots.push_back(textureSlot);
85 proccessArgs(args...);
86 }
87 template<typename... Args>
88 void proccessArgs(UniformSlot uniformSlot, Args... args)
89 {
90 m_uniformLayouts[uniformSlot.getName()] = uniformSlot;
91 proccessArgs(args...);
92 }
93
95 {
97 {
98 m_pixelLayout = m_vertexLayouts.begin()->second;
99 }
100 }
101
102 template<typename... Args>
103 Layout(FCT::Context* ctx,Args... args) : m_ctx(ctx)
104 {
105 proccessArgs(args...);
106 }
107 void ctx(FCT::Context* ctx);
108 void setFixedImage(std::string name, FCT::Image* image);
110 void attachPass(FCT::RenderGraph* graph,std::string passName);
111 Uniform allocateUniform(std::string name);
112 FCT::VertexShader* allocateVertexShader(std::string code);
113 FCT::PixelShader* allocatePixelShader(std::string code);
114 void begin();
115 //passresource
116 void bindUniform(const Uniform& uniform);
117 void bindTexture(std::string name, FCT::Image* image);
118 void bindSampler(std::string name, FCT::Sampler* sampler);
119 //pipeline
121 void bindPixelShader(FCT::PixelShader* shader);
122 //void drawMesh(FCT::RHI::CommandBuffer* cmdBuffer,FCT::StaticMesh<uint32_t>* mesh);
123 template<typename T>
124 void drawMesh(RHI::CommandBuffer* cmdBuffer,T* mesh);
125 template<typename T>
126 void drawMesh(RHI::CommandBuffer* cmdBuffer,T& mesh);
127 void end();
128 private:
140 {
141 std::unordered_map<std::string, FCT::Image*> boundTextures;
142 std::unordered_map<std::string, FCT::Sampler*> boundSamplers;
143 std::unordered_map<std::string, FCT::RHI::ConstBuffer*> boundUniforms;
144 void clear();
145 void bindTexture(const std::string& name, FCT::Image* image);
146 void bindSampler(const std::string& name, FCT::Sampler* sampler);
147 void bindUniform(const std::string& name, const Uniform& uniform);
148 size_t hash() const;
149 };
151 {
152 std::unordered_map<size_t,FCT::PassResource*> m_passResources;
153 FCT::PassResource* get(const PassResourceState& state, const std::function<FCT::PassResource*(const PassResourceState& state)>& creator);
154 };
156 {
157 std::unordered_map<size_t, FCT::RHI::RasterizationPipeline*> m_pipelines;
159 };
161 uint32_t findNextAvailableIndex();
163 std::map<uint32_t, FCT::VertexLayout> m_vertexLayouts;
164 std::map<std::string, FCT::ConstLayout> m_uniformLayouts;
169 std::unordered_map<std::string, FCT::Image*> m_fixedImages;
171 std::vector<TextureSlot> m_unhandledTextureSlots;
172 bool m_hasVertexLayout = false;
173 bool m_hasPixelLayout = false;
181 std::unordered_map<std::string,const char*> m_textureNames;
182 };
183
184}
185#endif //LAYOUT_H
constexpr const char * getName() const noexcept
std::map< std::string, FCT::ConstLayout > m_uniformLayouts
void bindVertexShader(FCT::VertexShader *shader)
void proccessArgs(FCT::PixelLayout pixelLayout, Args... args)
void bindUniform(const Uniform &uniform)
std::unordered_map< std::string, const char * > m_textureNames
void proccessArgs(PassName passName, Args... args)
void setFixedImage(std::string name, FCT::Image *image)
void bindPixelShader(FCT::PixelShader *shader)
void processUnhandledTextureSlots()
FCT::ResourceLayout m_pixelResourceLayout
void attachPass(FCT::RenderGraph *graph, std::string passName)
void proccessArgs(UniformSlot uniformSlot, Args... args)
bool m_hasVertexLayout
void proccessArgs(SamplerSlot samplerSlot, Args... args)
FCT::Context * m_ctx
void proccessArgs()
Layout(FCT::Context *ctx, Args... args)
void bindSampler(std::string name, FCT::Sampler *sampler)
void drawMesh(RHI::CommandBuffer *cmdBuffer, T *mesh)
uint32_t m_nextAvailableIndex
uint32_t findNextAvailableIndex()
void bindTexture(std::string name, FCT::Image *image)
FCT::ResourceLayout m_vertexResourceLayout
void proccessArgs(TextureSlot textureSlot, Args... args)
std::unordered_map< std::string, FCT::Image * > m_fixedImages
void addTextureSlot(FCT::TextureElement element)
TraditionPipelineState m_pipelineState
FCT::ResourceLayout m_resourceLayout
std::map< uint32_t, FCT::VertexLayout > m_vertexLayouts
FCT::RHI::RasterizationPipeline * getCurrentPipeline()
PassResourceState m_passResourceState
void proccessArgs(FCT::VertexLayout vertexLayout, Args... args)
PassResourceCache m_passResourceCache
FCT::PixelLayout m_pixelLayout
PipelineCache m_pipelineCache
bool m_hasPixelLayout
FCT::RHI::Pass * m_pass
void ctx(FCT::Context *ctx)
FCT::PixelShader * allocatePixelShader(std::string code)
void proccessArgs(uint32_t index, FCT::VertexLayout vertexLayout, Args... args)
Uniform allocateUniform(std::string name)
FCT::VertexShader * allocateVertexShader(std::string code)
FCT::PassResource * getCurrentPassResource()
std::vector< TextureSlot > m_unhandledTextureSlots
constexpr ShaderStages getShaderStages() const noexcept
FCT::SamplerElement SamplerSlot
FCT::ConstType UniformType
FCT::ConstElement UniformVar
FCT::ConstLayout UniformSlot
FCT::PassResource * get(const PassResourceState &state, const std::function< FCT::PassResource *(const PassResourceState &state)> &creator)
std::unordered_map< size_t, FCT::PassResource * > m_passResources
std::unordered_map< std::string, FCT::RHI::ConstBuffer * > boundUniforms
void bindUniform(const std::string &name, const Uniform &uniform)
void bindTexture(const std::string &name, FCT::Image *image)
std::unordered_map< std::string, FCT::Image * > boundTextures
std::unordered_map< std::string, FCT::Sampler * > boundSamplers
void bindSampler(const std::string &name, FCT::Sampler *sampler)
std::unordered_map< size_t, FCT::RHI::RasterizationPipeline * > m_pipelines
FCT::RHI::RasterizationPipeline * get(const TraditionPipelineState &state, const std::function< FCT::RHI::RasterizationPipeline *(const TraditionPipelineState &state)> &creator)
FCT::DepthStencilState * depthStencilState
FCT::RasterizationState * rasterizationState
bool operator==(const TraditionPipelineState &other) const
std::string name
std::string name