载入中...
搜索中...
未找到
Shader.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <array>
6#include <cstddef>
7#include <cstdint>
8#include <map>
9#include <string>
10#include <vector>
11#include "common/Result.h"
12#include "graphics/BlendMode.h"
14
15#include <glm/mat4x4.hpp>
16
17namespace eve::graphics {
18class Texture;
19namespace vulkan {
20class Graphics;
21}
22
40public:
41 static constexpr int kMaxFloats = 32;
42 static constexpr std::size_t kMaxMeshTextures = 4;
43 static constexpr uint32_t kPushConstantBytes = uint32_t(kMaxFloats * sizeof(float));
44
46 enum class Kind { eSprite2D, eMesh3D };
47
56
59
60 Shader(const Shader &) = delete;
61 Shader &operator=(const Shader &) = delete;
62
63 Kind getKind() const { return kind_; }
64 void setKind(Kind k) { kind_ = k; }
65
72 void setXray(bool x) { isXray_ = x; }
73 bool isXray() const { return isXray_; }
74
76 BlendMode meshBlend = BlendMode::Opaque;
78 bool meshDepthWrite = true;
80 bool meshDoubleSided = true;
82 const MeshShaderRasterState &meshRasterState() const noexcept { return meshRaster_; }
83
85 int declareFloat(const std::string &name);
86 int declareVec2(const std::string &name);
87 int declareVec3(const std::string &name);
88 int declareVec4(const std::string &name);
89 int declareMatrix(const std::string &name);
90
91 void sendFloat(const std::string &name, float x);
92 void sendVec2(const std::string &name, float x, float y);
93 void sendVec3(const std::string &name, float x, float y, float z);
94 void sendVec4(const std::string &name, float x, float y, float z, float w);
95 void sendMatrix(const std::string &name, const glm::mat4 &m);
96
98 int sendToVar(const std::string &name, const void *data, size_t size);
99 int getFromVar(const std::string &name, void *data, size_t size) const;
100
101 bool hasUniform(const std::string &name) const;
102 int getUniformIndex(const std::string &name) const;
103 int getUniformFloatCount(const std::string &name) const;
104
105 const float *pushConstantData() const { return floats_.data(); }
113 void setPushConstantBlock(const std::array<float, kMaxFloats> &values) noexcept;
114 uint32_t pushConstantSize() const { return uint32_t(usedFloats_ * sizeof(float)); }
115 int usedFloats() const { return usedFloats_; }
116
125 [[nodiscard]] Result<void> setMeshTexture(std::size_t slot, Texture *texture);
132 Texture *meshTexture(std::size_t slot) const {
133 return slot < meshTextures_.size() ? meshTextures_[slot] : nullptr;
134 }
135
136 const std::vector<uint32_t> &vertexSpirv() const { return vertSpv_; }
137 const std::vector<uint32_t> &fragmentSpirv() const { return fragSpv_; }
138
139 void setSpirv(std::vector<uint32_t> vert, std::vector<uint32_t> frag) {
140 vertSpv_ = std::move(vert);
141 fragSpv_ = std::move(frag);
142 }
143
145 void *gpuHandle = nullptr;
146
147private:
148 friend class vulkan::Graphics;
149 MeshShaderRasterState meshRaster_;
150 struct Uniform {
151 int index = 0;
152 int floatCount = 0;
153 };
154
155 int declareUniform(const std::string &name, int floatCount);
156 Uniform *findUniform(const std::string &name);
157 const Uniform *findUniform(const std::string &name) const;
158
159 Kind kind_ = Kind::eSprite2D;
160 bool isXray_ = false;
161 std::vector<uint32_t> vertSpv_;
162 std::vector<uint32_t> fragSpv_;
163 std::map<std::string, Uniform> uniforms_;
164 std::array<float, kMaxFloats> floats_{};
165 std::array<Texture *, kMaxMeshTextures> meshTextures_{};
166 int usedFloats_ = 0;
167};
168
169} // namespace eve::graphics
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
std::map< std::string, Var > values
#define EVENGINE_API_BACKENDS
Definition Export.h:108
vk::ShaderModule vert
vk::ShaderModule frag
std::string name
Move-only, checked operation results for the common layer.
float size
Definition TreeMesh.cpp:156
uint32_t index
float m[16]
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Custom GPU program.
Definition Shader.h:39
void setSpirv(std::vector< uint32_t > vert, std::vector< uint32_t > frag)
Definition Shader.h:139
Shader & operator=(const Shader &)=delete
Kind getKind() const
Definition Shader.h:63
int usedFloats() const
Definition Shader.h:115
const std::vector< uint32_t > & fragmentSpirv() const
Definition Shader.h:137
Kind
Kind public API.
Definition Shader.h:46
void setXray(bool x)
X-ray mesh shader. When true, drawMeshShader renders this mesh a second pass over the already-lit sce...
Definition Shader.h:72
const MeshShaderRasterState & meshRasterState() const noexcept
Read the committed raster snapshot; render-thread affinity matches the owning Graphics.
Definition Shader.h:82
bool isXray() const
Definition Shader.h:73
Shader(const Shader &)=delete
const std::vector< uint32_t > & vertexSpirv() const
Definition Shader.h:136
void setKind(Kind k)
Definition Shader.h:64
Texture * meshTexture(std::size_t slot) const
Return the borrowed texture assigned to a custom-mesh slot, or null.
Definition Shader.h:132
uint32_t pushConstantSize() const
Definition Shader.h:114
const float * pushConstantData() const
Definition Shader.h:105
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
EVENGINE_API_BACKENDS public API.
Definition Graphics.h:342
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
BlendMode
Render-neutral 2D blend mode shared by graphics-facing modules.
Definition RenderTypes.h:11
Value snapshot of custom mesh rasterization state, independent of blending/culling.