载入中...
搜索中...
未找到
GraphicsPipelineSupport.cpp
浏览该文件的文档.
2
4wgpu::Sampler createLinearSampler(wgpu::Device& dev) {
5 WGPUSamplerDescriptor d{};
6 d.label = sv("eve_linear");
7 d.addressModeU = WGPUAddressMode_ClampToEdge;
8 d.addressModeV = WGPUAddressMode_ClampToEdge;
9 d.addressModeW = WGPUAddressMode_ClampToEdge;
10 d.magFilter = WGPUFilterMode_Linear;
11 d.minFilter = WGPUFilterMode_Linear;
12 d.mipmapFilter = WGPUMipmapFilterMode_Linear;
13 d.lodMinClamp = 0.f;
14 d.lodMaxClamp = 1000.f;
15 d.maxAnisotropy = 1;
16 return dev.CreateSampler(reinterpret_cast<const wgpu::SamplerDescriptor*>(&d));
17}
18WGPUShaderModuleDescriptor mdDesc(const std::string& code) {
19 static WGPUShaderSourceWGSL wd{};
20 wd.chain.sType = WGPUSType_ShaderSourceWGSL;
21 wd.code = sv(code.c_str());
22 WGPUShaderModuleDescriptor md{};
23 md.nextInChain = &wd.chain;
24 return md;
25}
26
27void fillVertexLayout(WGPUVertexBufferLayout& layout, uint64_t stride, const WGPUVertexAttribute* attrs,
28 uint32_t attrCount) {
29 layout.arrayStride = stride;
30 layout.stepMode = WGPUVertexStepMode_Vertex;
31 layout.attributeCount = attrCount;
32 layout.attributes = attrs;
33}
34
35WGPUBlendState alphaBlend() {
36 WGPUBlendState b{};
37 b.color.srcFactor = WGPUBlendFactor_SrcAlpha;
38 b.color.dstFactor = WGPUBlendFactor_OneMinusSrcAlpha;
39 b.color.operation = WGPUBlendOperation_Add;
40 b.alpha.srcFactor = WGPUBlendFactor_One;
41 b.alpha.dstFactor = WGPUBlendFactor_OneMinusSrcAlpha;
42 b.alpha.operation = WGPUBlendOperation_Add;
43 return b;
44}
45
46WGPUBlendState noBlend() {
47 WGPUBlendState b{};
48 b.color.srcFactor = WGPUBlendFactor_One;
49 b.color.dstFactor = WGPUBlendFactor_Zero;
50 b.color.operation = WGPUBlendOperation_Add;
51 b.alpha.srcFactor = WGPUBlendFactor_One;
52 b.alpha.dstFactor = WGPUBlendFactor_Zero;
53 b.alpha.operation = WGPUBlendOperation_Add;
54 return b;
55}
56
57WGPUBlendState additiveBlend() {
58 WGPUBlendState b{};
59 b.color.srcFactor = WGPUBlendFactor_SrcAlpha;
60 b.color.dstFactor = WGPUBlendFactor_One;
61 b.color.operation = WGPUBlendOperation_Add;
62 b.alpha.srcFactor = WGPUBlendFactor_One;
63 b.alpha.dstFactor = WGPUBlendFactor_One;
64 b.alpha.operation = WGPUBlendOperation_Add;
65 return b;
66}
67
68WGPUBlendState premultipliedBlend() {
69 WGPUBlendState b = alphaBlend();
70 b.color.srcFactor = WGPUBlendFactor_One;
71 return b;
72}
73
74WGPUBlendState multiplyBlend() {
75 WGPUBlendState b = alphaBlend();
76 b.color.srcFactor = WGPUBlendFactor_Dst;
77 return b;
78}
79
80size_t meshPipelineIndex(BlendMode blend, bool depthWrite, bool doubleSided) {
81 return size_t(blend) * 4u + (depthWrite ? 2u : 0u) + (doubleSided ? 1u : 0u);
82}
83
84WGPUBlendState blendState(BlendMode mode) {
85 switch (mode) {
89 case BlendMode::Opaque: return noBlend();
91 default: return alphaBlend();
92 }
93}
94void fillMeshAttributes(WGPUVertexAttribute (&attrs)[6]) {
95 attrs[0].format = WGPUVertexFormat_Float32x3;
96 attrs[0].offset = 0;
97 attrs[0].shaderLocation = 0;
98 attrs[1].format = WGPUVertexFormat_Float32x3;
99 attrs[1].offset = 12;
100 attrs[1].shaderLocation = 1;
101 attrs[2].format = WGPUVertexFormat_Float32x2;
102 attrs[2].offset = 24;
103 attrs[2].shaderLocation = 2;
104 attrs[3].format = WGPUVertexFormat_Uint16x4;
105 attrs[3].offset = 32;
106 attrs[3].shaderLocation = 3;
107 attrs[4].format = WGPUVertexFormat_Float32x4;
108 attrs[4].offset = 40;
109 attrs[4].shaderLocation = 4;
110 attrs[5].format = WGPUVertexFormat_Float32x4;
111 attrs[5].offset = 56;
112 attrs[5].shaderLocation = 5;
113}
114} // namespace eve::graphics::webgpu::detail
std::string layout
DiagnosticCode code
float u
Definition Grass.cpp:233
float blend
MeleePoint3 b
Definition MeleeHit.cpp:41
bool doubleSided
float d
WGPUBlendState premultipliedBlend()
Internal WebGPU pipeline/descriptor helper; render-thread only.
WGPUBlendState noBlend()
Internal WebGPU pipeline/descriptor helper; render-thread only.
wgpu::Sampler createLinearSampler(wgpu::Device &dev)
Internal WebGPU pipeline/descriptor helper; render-thread only.
void fillMeshAttributes(WGPUVertexAttribute(&attrs)[6])
Internal WebGPU pipeline/descriptor helper; render-thread only.
WGPUBlendState alphaBlend()
Internal WebGPU pipeline/descriptor helper; render-thread only.
WGPUBlendState blendState(BlendMode mode)
Internal WebGPU pipeline/descriptor helper; render-thread only.
void fillVertexLayout(WGPUVertexBufferLayout &layout, uint64_t stride, const WGPUVertexAttribute *attrs, uint32_t attrCount)
Internal WebGPU pipeline/descriptor helper; render-thread only.
WGPUShaderModuleDescriptor mdDesc(const std::string &code)
Internal WebGPU pipeline/descriptor helper; render-thread only.
WGPUBlendState additiveBlend()
Internal WebGPU pipeline/descriptor helper; render-thread only.
WGPUBlendState multiplyBlend()
Internal WebGPU pipeline/descriptor helper; render-thread only.
size_t meshPipelineIndex(BlendMode blend, bool depthWrite, bool doubleSided)
Internal WebGPU pipeline/descriptor helper; render-thread only.
WGPUStringView sv(const char *s)
Build a WGPUStringView from a C string (null-safe, length auto-computed).
Definition wgpu_types.h:20
BlendMode
Render-neutral 2D blend mode shared by graphics-facing modules.
Definition RenderTypes.h:11