FCT
载入中...
搜索中...
未找到
layout.hpp
浏览该文件的文档.
1//
2// Created by Administrator on 2025/8/17.
3//
4
5#ifndef LAYOUT_HPP
6#define LAYOUT_HPP
7#include "layout.h"
9#include "PassResource.h"
10
11namespace FCT
12{
13 template <typename ... Args>
14 void Layout::proccessArgs(FCT::VertexLayout vertexLayout, Args... args)
15 {
16 uint32_t index = findNextAvailableIndex();
17 m_vertexLayouts[index] = vertexLayout;
18 m_hasVertexLayout = true;
20 proccessArgs(args...);
21 }
22 template <typename ... Args>
23 void Layout::proccessArgs(const std::vector<FCT::VertexLayout>& vertexLayouts, Args... args)
24 {
25 for(const auto& vertexLayout : vertexLayouts)
26 {
27 uint32_t index = findNextAvailableIndex();
28 m_vertexLayouts[index] = vertexLayout;
29 }
30 m_hasVertexLayout = !vertexLayouts.empty();
32 proccessArgs(args...);
33 }
34
35 template <typename ... Args>
36 void Layout::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
53 template <typename ... Args>
54 void Layout::proccessArgs(PassName passName, Args... args)
55 {
56 attachPass(passName.name);
57 /*
58 if (m_ctx && m_ctx->getModule<FCT::RenderGraph>()) {
59 attachPass(m_ctx->getModule<FCT::RenderGraph>(), passName.name);
60 }*/
61 proccessArgs(args...);
62 }
63
64 template <typename ... Args>
65 void Layout::proccessArgs(uint32_t index, FCT::VertexLayout vertexLayout, Args... args)
66 {
67 m_vertexLayouts[index] = vertexLayout;
68 m_hasVertexLayout = true;
70 proccessArgs(args...);
71 }
72
73 template <typename ... Args>
74 void Layout::proccessArgs(FCT::PixelLayout pixelLayout, Args... args)
75 {
76 m_pixelLayout = pixelLayout;
77 m_hasPixelLayout = true;
79 proccessArgs(args...);
80 }
81
82 template <typename ... Args>
83 void Layout::proccessArgs(TextureSlot textureSlot, Args... args)
84 {
85 m_unhandledTextureSlots.push_back(textureSlot);
87 proccessArgs(args...);
88 }
89
90 template <typename ... Args>
91 void Layout::proccessArgs(UniformSlot uniformSlot, Args... args)
92 {
93 m_uniformLayouts[uniformSlot.getName()] = uniformSlot;
94 proccessArgs(args...);
95 }
96
97 template <typename ... Args>
99 {
100 proccessArgs(args...);
101 }
102
103 template <typename T>
104 void Layout::drawMesh(RHI::CommandBuffer* cmdBuffer, T* mesh)
105 {
106 auto resource = getCurrentPassResource();
107 auto pipeline = getCurrentPipeline();
108
109 pipeline->bind(cmdBuffer);
110 resource->bind(cmdBuffer,pipeline);
111 mesh->bind(cmdBuffer);
112 mesh->draw(cmdBuffer);
113 }
114
115 template <typename T>
116 void Layout::drawMesh(RHI::CommandBuffer* cmdBuffer, T& mesh)
117 {
118 auto resource = getCurrentPassResource();
119 auto pipeline = getCurrentPipeline();
120
121 pipeline->bind(cmdBuffer);
122 resource->bind(cmdBuffer,pipeline);
123 mesh.bind(cmdBuffer);
124 mesh.draw(cmdBuffer);
125 }
126}
127#endif //LAYOUTS_H
constexpr const char * getName() const noexcept
std::map< std::string, FCT::ConstLayout > m_uniformLayouts
void processUnhandledTextureSlots()
FCT::ResourceLayout m_pixelResourceLayout
void attachPass(std::string passName)
将此 Layout 附加到一个渲染通道。
bool m_hasVertexLayout
FCT::Context * m_ctx
void proccessArgs()
Layout(FCT::Context *ctx, Args... args)
void drawMesh(RHI::CommandBuffer *cmdBuffer, T *mesh)
绘制一个网格。
uint32_t findNextAvailableIndex()
FCT::ResourceLayout m_vertexResourceLayout
FCT::ResourceLayout m_resourceLayout
std::map< uint32_t, FCT::VertexLayout > m_vertexLayouts
FCT::RHI::RasterizationPipeline * getCurrentPipeline()
FCT::PixelLayout m_pixelLayout
bool m_hasPixelLayout
void ctx(FCT::Context *ctx)
重新设置 FCT 上下文。
FCT::PassResource * getCurrentPassResource()
std::vector< TextureSlot > m_unhandledTextureSlots
constexpr ShaderStages getShaderStages() const noexcept
FCT::SamplerElement SamplerSlot
FCT::ConstLayout UniformSlot
定义 Layout 将要附加到的渲染通道(Render Pass)的名称。
std::string name
定义一个纹理槽位,用于在着色器中绑定纹理。