Fix gizmos in WebGPU (#8910)
# Objective Fix #8908. ## Solution Assign the vertex buffers twice with a single item offset instead of setting the array_stride lower than the vertex layout's size for linestrips.
This commit is contained in:
parent
f7ea93a7cf
commit
bb59509d44
@ -452,12 +452,22 @@ impl<P: PhaseItem> RenderCommand<P> for DrawLineGizmo {
|
|||||||
return RenderCommandResult::Failure;
|
return RenderCommandResult::Failure;
|
||||||
};
|
};
|
||||||
|
|
||||||
pass.set_vertex_buffer(0, line_gizmo.position_buffer.slice(..));
|
|
||||||
pass.set_vertex_buffer(1, line_gizmo.color_buffer.slice(..));
|
|
||||||
|
|
||||||
let instances = if line_gizmo.strip {
|
let instances = if line_gizmo.strip {
|
||||||
|
let item_size = VertexFormat::Float32x3.size();
|
||||||
|
let buffer_size = line_gizmo.position_buffer.size() - item_size;
|
||||||
|
pass.set_vertex_buffer(0, line_gizmo.position_buffer.slice(..buffer_size));
|
||||||
|
pass.set_vertex_buffer(1, line_gizmo.position_buffer.slice(item_size..));
|
||||||
|
|
||||||
|
let item_size = VertexFormat::Float32x4.size();
|
||||||
|
let buffer_size = line_gizmo.color_buffer.size() - item_size;
|
||||||
|
pass.set_vertex_buffer(2, line_gizmo.color_buffer.slice(..buffer_size));
|
||||||
|
pass.set_vertex_buffer(3, line_gizmo.color_buffer.slice(item_size..));
|
||||||
|
|
||||||
u32::max(line_gizmo.vertex_count, 1) - 1
|
u32::max(line_gizmo.vertex_count, 1) - 1
|
||||||
} else {
|
} else {
|
||||||
|
pass.set_vertex_buffer(0, line_gizmo.position_buffer.slice(..));
|
||||||
|
pass.set_vertex_buffer(1, line_gizmo.color_buffer.slice(..));
|
||||||
|
|
||||||
line_gizmo.vertex_count / 2
|
line_gizmo.vertex_count / 2
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -468,42 +478,55 @@ impl<P: PhaseItem> RenderCommand<P> for DrawLineGizmo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn line_gizmo_vertex_buffer_layouts(strip: bool) -> Vec<VertexBufferLayout> {
|
fn line_gizmo_vertex_buffer_layouts(strip: bool) -> Vec<VertexBufferLayout> {
|
||||||
let stride_multiplier = if strip { 1 } else { 2 };
|
|
||||||
use VertexFormat::*;
|
use VertexFormat::*;
|
||||||
vec![
|
let mut position_layout = VertexBufferLayout {
|
||||||
// Positions
|
array_stride: Float32x3.size(),
|
||||||
VertexBufferLayout {
|
step_mode: VertexStepMode::Instance,
|
||||||
array_stride: Float32x3.size() * stride_multiplier,
|
attributes: vec![VertexAttribute {
|
||||||
step_mode: VertexStepMode::Instance,
|
format: Float32x3,
|
||||||
attributes: vec![
|
offset: 0,
|
||||||
VertexAttribute {
|
shader_location: 0,
|
||||||
format: Float32x3,
|
}],
|
||||||
offset: 0,
|
};
|
||||||
shader_location: 0,
|
|
||||||
},
|
let mut color_layout = VertexBufferLayout {
|
||||||
VertexAttribute {
|
array_stride: Float32x4.size(),
|
||||||
format: Float32x3,
|
step_mode: VertexStepMode::Instance,
|
||||||
offset: Float32x3.size(),
|
attributes: vec![VertexAttribute {
|
||||||
shader_location: 1,
|
format: Float32x4,
|
||||||
},
|
offset: 0,
|
||||||
],
|
shader_location: 2,
|
||||||
},
|
}],
|
||||||
// Colors
|
};
|
||||||
VertexBufferLayout {
|
|
||||||
array_stride: Float32x4.size() * stride_multiplier,
|
if strip {
|
||||||
step_mode: VertexStepMode::Instance,
|
vec![
|
||||||
attributes: vec![
|
position_layout.clone(),
|
||||||
VertexAttribute {
|
{
|
||||||
format: Float32x4,
|
position_layout.attributes[0].shader_location = 1;
|
||||||
offset: 0,
|
position_layout
|
||||||
shader_location: 2,
|
},
|
||||||
},
|
color_layout.clone(),
|
||||||
VertexAttribute {
|
{
|
||||||
format: Float32x4,
|
color_layout.attributes[0].shader_location = 3;
|
||||||
offset: Float32x4.size(),
|
color_layout
|
||||||
shader_location: 3,
|
},
|
||||||
},
|
]
|
||||||
],
|
} else {
|
||||||
},
|
position_layout.array_stride *= 2;
|
||||||
]
|
position_layout.attributes.push(VertexAttribute {
|
||||||
|
format: Float32x3,
|
||||||
|
offset: Float32x3.size(),
|
||||||
|
shader_location: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
color_layout.array_stride *= 2;
|
||||||
|
color_layout.attributes.push(VertexAttribute {
|
||||||
|
format: Float32x4,
|
||||||
|
offset: Float32x4.size(),
|
||||||
|
shader_location: 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
vec![position_layout, color_layout]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user