Skip to content

Commit 81a38cd

Browse files
authored
fix WebGPU rendering (#66)
1 parent d811580 commit 81a38cd

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/polyline.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,6 @@ impl SpecializedRenderPipeline for PolylinePipeline {
166166
type Key = PolylinePipelineKey;
167167

168168
fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
169-
let vertex_attributes = vec![
170-
VertexAttribute {
171-
format: VertexFormat::Float32x3,
172-
offset: 0,
173-
shader_location: 0,
174-
},
175-
VertexAttribute {
176-
format: VertexFormat::Float32x3,
177-
offset: 12,
178-
shader_location: 1,
179-
},
180-
];
181169
let shader_defs = Vec::new();
182170
let (label, blend, depth_write_enabled);
183171

@@ -208,15 +196,24 @@ impl SpecializedRenderPipeline for PolylinePipeline {
208196
false => TextureFormat::bevy_default(),
209197
};
210198

199+
let mut vertex_layout = VertexBufferLayout {
200+
step_mode: VertexStepMode::Instance,
201+
array_stride: VertexFormat::Float32x3.size(),
202+
attributes: vec![VertexAttribute {
203+
format: VertexFormat::Float32x3,
204+
offset: 0,
205+
shader_location: 0,
206+
}],
207+
};
208+
211209
RenderPipelineDescriptor {
212210
vertex: VertexState {
213211
shader: self.shader.clone(),
214212
entry_point: "vertex".into(),
215213
shader_defs: shader_defs.clone(),
216-
buffers: vec![VertexBufferLayout {
217-
array_stride: 12,
218-
step_mode: VertexStepMode::Instance,
219-
attributes: vertex_attributes,
214+
buffers: vec![vertex_layout.clone(), {
215+
vertex_layout.attributes[0].shader_location = 1;
216+
vertex_layout
220217
}],
221218
},
222219
fragment: Some(FragmentState {
@@ -388,9 +385,18 @@ impl<P: PhaseItem> RenderCommand<P> for DrawPolyline {
388385
pass: &mut TrackedRenderPass<'w>,
389386
) -> RenderCommandResult {
390387
if let Some(gpu_polyline) = polylines.into_inner().get(pl_handle.unwrap()) {
391-
pass.set_vertex_buffer(0, gpu_polyline.vertex_buffer.slice(..));
388+
if gpu_polyline.vertex_count < 2 {
389+
return RenderCommandResult::Success;
390+
}
391+
392+
let item_size = VertexFormat::Float32x3.size();
393+
let buffer_size = gpu_polyline.vertex_buffer.size() - item_size;
394+
pass.set_vertex_buffer(0, gpu_polyline.vertex_buffer.slice(..buffer_size));
395+
pass.set_vertex_buffer(1, gpu_polyline.vertex_buffer.slice(item_size..));
396+
392397
let num_instances = gpu_polyline.vertex_count.max(1) - 1;
393398
pass.draw(0..6, 0..num_instances);
399+
394400
RenderCommandResult::Success
395401
} else {
396402
RenderCommandResult::Failure

0 commit comments

Comments
 (0)