Avoid spawning gizmo meshes when no gizmos are being drawn (#8180)
# Objective Avoid queuing empty meshes for rendering. Should prevent #8144 from triggering when no gizmos are in use. Not a real fix, unfortunately. ## Solution Add an `in_use` field to `GizmoStorage` and only set it to true when there are gizmos to draw.
This commit is contained in:
parent
ce252f8cf7
commit
e54057c50d
@ -20,6 +20,7 @@ pub(crate) struct GizmoStorage {
|
|||||||
pub list_colors: Vec<ColorItem>,
|
pub list_colors: Vec<ColorItem>,
|
||||||
pub strip_positions: Vec<PositionItem>,
|
pub strip_positions: Vec<PositionItem>,
|
||||||
pub strip_colors: Vec<ColorItem>,
|
pub strip_colors: Vec<ColorItem>,
|
||||||
|
pub in_use: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`SystemParam`](bevy_ecs::system::SystemParam) for drawing gizmos.
|
/// A [`SystemParam`](bevy_ecs::system::SystemParam) for drawing gizmos.
|
||||||
|
@ -151,31 +151,42 @@ fn update_gizmo_meshes(
|
|||||||
) {
|
) {
|
||||||
let list_mesh = meshes.get_mut(&handles.list).unwrap();
|
let list_mesh = meshes.get_mut(&handles.list).unwrap();
|
||||||
|
|
||||||
let positions = mem::take(&mut storage.list_positions);
|
storage.in_use = false;
|
||||||
list_mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions);
|
|
||||||
|
|
||||||
let colors = mem::take(&mut storage.list_colors);
|
if !storage.list_positions.is_empty() {
|
||||||
list_mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors);
|
storage.in_use = true;
|
||||||
|
|
||||||
let strip_mesh = meshes.get_mut(&handles.strip).unwrap();
|
let positions = mem::take(&mut storage.list_positions);
|
||||||
|
list_mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions);
|
||||||
|
|
||||||
let positions = mem::take(&mut storage.strip_positions);
|
let colors = mem::take(&mut storage.list_colors);
|
||||||
strip_mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions);
|
list_mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors);
|
||||||
|
}
|
||||||
|
|
||||||
let colors = mem::take(&mut storage.strip_colors);
|
if !storage.strip_positions.is_empty() {
|
||||||
strip_mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors);
|
storage.in_use = true;
|
||||||
|
|
||||||
|
let strip_mesh = meshes.get_mut(&handles.strip).unwrap();
|
||||||
|
|
||||||
|
let positions = mem::take(&mut storage.strip_positions);
|
||||||
|
strip_mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, positions);
|
||||||
|
|
||||||
|
let colors = mem::take(&mut storage.strip_colors);
|
||||||
|
strip_mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_gizmo_data(
|
fn extract_gizmo_data(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
handles: Extract<Res<MeshHandles>>,
|
handles: Extract<Res<MeshHandles>>,
|
||||||
config: Extract<Res<GizmoConfig>>,
|
config: Extract<Res<GizmoConfig>>,
|
||||||
|
storage: Extract<Res<GizmoStorage>>,
|
||||||
) {
|
) {
|
||||||
if config.is_changed() {
|
if config.is_changed() {
|
||||||
commands.insert_resource(**config);
|
commands.insert_resource(**config);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !config.enabled {
|
if !config.enabled || !storage.in_use {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +197,7 @@ fn extract_gizmo_data(
|
|||||||
GizmoMesh,
|
GizmoMesh,
|
||||||
#[cfg(feature = "bevy_pbr")]
|
#[cfg(feature = "bevy_pbr")]
|
||||||
(
|
(
|
||||||
handle.clone(),
|
handle.clone_weak(),
|
||||||
MeshUniform {
|
MeshUniform {
|
||||||
flags: 0,
|
flags: 0,
|
||||||
transform,
|
transform,
|
||||||
@ -196,7 +207,7 @@ fn extract_gizmo_data(
|
|||||||
),
|
),
|
||||||
#[cfg(feature = "bevy_sprite")]
|
#[cfg(feature = "bevy_sprite")]
|
||||||
(
|
(
|
||||||
Mesh2dHandle(handle.clone()),
|
Mesh2dHandle(handle.clone_weak()),
|
||||||
Mesh2dUniform {
|
Mesh2dUniform {
|
||||||
flags: 0,
|
flags: 0,
|
||||||
transform,
|
transform,
|
||||||
|
Loading…
Reference in New Issue
Block a user