FCT
载入中...
搜索中...
未找到
VertexShader.h
浏览该文件的文档.
1//
2// Created by Administrator on 2025/4/6.
3//
5#include "Vertex.h"
6#include "Context.h"
7#include "Uniform.h"
10
11#ifndef FCT_VERTEXSHADER_H
12#define FCT_VERTEXSHADER_H
13namespace FCT {
14 /*
15 *包装RHI::VertexShader
16 *提供自动生成Shader
17 *反射shader信息
18 */
20 {
21 public:
27 {
28 m_ctx = ctx;
29 }
30 void code(std::string source)
31 {
32 m_userSource = source;
33 }
34 void create()
35 {
36 m_vertexShader = m_ctx->createResource<RHI::VertexShader>();
37 if (m_userSource.empty())
38 {
40 }
41 if (m_binaryCode.code().empty())
42 {
43 preprocess();
44 compile();
45 }
46 m_vertexShader->code(m_binaryCode.code());
47 m_vertexShader->create();
48 }
54 {
55 RHI::InputLayout* il = m_ctx->createResource<RHI::InputLayout>();
56 for (auto [slot, layout] : m_vertexLayouts)
57 {
58 il->add(slot,layout);
59 }
61 il->create();
62 return il;
63 }
68 void addLayout(uint32_t slot, VertexLayout layout)
69 {
70 m_vertexLayouts[slot] = layout;
71 }
73 {
74 m_pixelLayout = layout;
75 }
77 {
78 if (std::find(m_uniformLayouts.begin(), m_uniformLayouts.end(), layout) == m_uniformLayouts.end())
79 m_uniformLayouts.push_back(layout);
80 }
82 {
83 m_resourceLayout = layout;
84 }
85 protected:
87 {
88 m_userSource = m_ctx->getGenerator()->generateDefaultVertexMain(m_vertexLayouts,m_pixelLayout);
89 }
90 void compile()
91 {
92 m_binaryCode.code(
93 m_ctx->getCompiler()->compile(m_source,"FCTEntry",ShaderKind::VertexShader)
94 );
95 }
102 std::map<uint32_t,VertexLayout> m_vertexLayouts;
103 std::vector<ConstLayout> m_uniformLayouts;
106 std::string m_userSource;
107 std::string m_source;
109 };
110}
111#endif //FCT_VERTEXSHADER_H
virtual void create()=0
void add(uint32_t slot, VertexLayout vertexLayout)
void inputShaderCode(ShaderBinary binary)
RHI::ShaderBinary binaryCode()
RHI::VertexShader * m_vertexShader
void addUniform(ConstLayout layout)
RHI::InputLayout * createBindedInputLayout()
void addLayout(uint32_t slot, VertexLayout layout)
RHI::ShaderBinary m_binaryCode
VertexShader(Context *ctx)
void pixelLayout(PixelLayout layout)
void code(std::string source)
PipelineResourceType getType() const override
void resourceLayout(ResourceLayout layout)
std::vector< ConstLayout > m_uniformLayouts
ResourceLayout m_resourceLayout
std::map< uint32_t, VertexLayout > m_vertexLayouts
RHI::VertexShader * vertexShader()