8 const wgpu::VertexAttribute *attrs,
10 wgpu::VertexBufferLayout l{};
11 l.arrayStride = stride;
12 l.stepMode = stepMode;
13 l.attributeCount = attrCount;
15 vertexBuffers_.push_back(l);
47 if (!vertModule_)
throw Exception(
"PipelineBuilder::build: no vertex shader");
48 if (!hasColorTarget_ && !hasDepth_)
49 throw Exception(
"PipelineBuilder::build: no color or depth target");
51 wgpu::RenderPipelineDescriptor
d{};
54 d.multisample.count = sampleCount_;
58 d.vertex.module = vertModule_;
59 d.vertex.entryPoint = vertEntry_;
60 d.vertex.bufferCount =
static_cast<uint32_t
>(vertexBuffers_.size());
61 d.vertex.buffers = vertexBuffers_.data();
64 d.primitive.topology = topology_;
65 d.primitive.frontFace = frontFace_;
66 d.primitive.cullMode = cullMode_;
67 d.primitive.stripIndexFormat = wgpu::IndexFormat::Undefined;
70 wgpu::DepthStencilState ds{};
72 ds.format = depthFormat_;
73 ds.depthCompare = depthCompare_;
74 ds.depthWriteEnabled = depthWrite_;
79 wgpu::ColorTargetState
target{};
80 wgpu::FragmentState fs{};
81 wgpu::BlendState
blend{};
82 if (hasColorTarget_) {
83 target.format = colorFormat_;
87 case eve::graphics::BlendMode::Alpha:
88 blend.color = {wgpu::BlendOperation::Add, wgpu::BlendFactor::SrcAlpha,
89 wgpu::BlendFactor::OneMinusSrcAlpha};
90 blend.alpha = {wgpu::BlendOperation::Add, wgpu::BlendFactor::One,
91 wgpu::BlendFactor::OneMinusSrcAlpha};
94 case eve::graphics::BlendMode::Additive:
95 blend.color = {wgpu::BlendOperation::Add, wgpu::BlendFactor::SrcAlpha,
96 wgpu::BlendFactor::One};
97 blend.alpha = {wgpu::BlendOperation::Add, wgpu::BlendFactor::One,
98 wgpu::BlendFactor::One};
101 case eve::graphics::BlendMode::Premultiplied:
102 blend.color = {wgpu::BlendOperation::Add, wgpu::BlendFactor::One,
103 wgpu::BlendFactor::OneMinusSrcAlpha};
104 blend.alpha = {wgpu::BlendOperation::Add, wgpu::BlendFactor::One,
105 wgpu::BlendFactor::OneMinusSrcAlpha};
108 case eve::graphics::BlendMode::Multiply:
109 blend.color = {wgpu::BlendOperation::Add, wgpu::BlendFactor::Dst,
110 wgpu::BlendFactor::OneMinusSrcAlpha};
111 blend.alpha = {wgpu::BlendOperation::Add, wgpu::BlendFactor::One,
112 wgpu::BlendFactor::OneMinusSrcAlpha};
115 case eve::graphics::BlendMode::Opaque:
120 fs.module = fragModule_;
121 fs.entryPoint = fragEntry_;
127 return device.CreateRenderPipeline(&
d);