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
31 ~VertexShader() override
32 {
34 {
35 m_vertexShader->release();
36 }
37
38 }
39 void code(std::string source)
40 {
41 m_userSource = source;
42 }
43 void create()
44 {
45 m_vertexShader = m_ctx->createResource<RHI::VertexShader>();
46 if (m_userSource.empty())
47 {
49 }
50 if (m_binaryCode.code().empty())
51 {
52 preprocess();
53 compile();
54 }
55 m_vertexShader->code(m_binaryCode.code());
56 m_vertexShader->create();
57 }
63 {
64 RHI::InputLayout* il = m_ctx->createResource<RHI::InputLayout>();
65 for (auto [slot, layout] : m_vertexLayouts)
66 {
67 il->add(slot,layout);
68 }
70 il->create();
71 return il;
72 }
77 void addLayout(uint32_t slot, VertexLayout layout)
78 {
79 m_vertexLayouts[slot] = layout;
80 }
82 {
83 m_pixelLayout = layout;
84 }
86 {
87 if (std::find(m_uniformLayouts.begin(), m_uniformLayouts.end(), layout) == m_uniformLayouts.end())
88 m_uniformLayouts.push_back(layout);
89 }
91 {
92 m_resourceLayout = layout;
93 }
94 protected:
96 {
97 m_userSource = m_ctx->getGenerator()->generateDefaultVertexMain(m_vertexLayouts,m_pixelLayout);
98 }
99 void compile()
100 {
101 m_binaryCode.code(
102 m_ctx->getCompiler()->compile(m_source,"FCTEntry",ShaderKind::VertexShader)
103 );
104 }
106 {
108 }
111 std::map<uint32_t,VertexLayout> m_vertexLayouts;
112 std::vector<ConstLayout> m_uniformLayouts;
115 std::string m_userSource;
116 std::string m_source;
118 };
119}
120#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()