From 0886e6a302e8d74254fd3ec6ede5fd483e0220b7 Mon Sep 17 00:00:00 2001 From: Sarthak Singh <35749450+SarthakSingh31@users.noreply.github.com> Date: Tue, 30 Jul 2024 05:10:39 +0530 Subject: [PATCH] Disabled usage of the POLYGON_MODE_LINE gpu feature in the examples (#14402) Fixes #14353 Fixes #14371 --------- Signed-off-by: Sarthak Singh Co-authored-by: Alice Cecile Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com> --- Cargo.toml | 3 ++- examples/2d/2d_shapes.rs | 24 ++++++++++++++++++------ examples/3d/3d_shapes.rs | 18 ++++++++++++++++-- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 77c155af84..24e96e3754 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -753,7 +753,8 @@ doc-scrape-examples = true name = "Lines" description = "Create a custom material to draw 3d lines" category = "3D Rendering" -wasm = true +# WASM does not support the `POLYGON_MODE_LINE` feature. +wasm = false [[example]] name = "ssao" diff --git a/examples/2d/2d_shapes.rs b/examples/2d/2d_shapes.rs index cf00f897a8..37e81e40c2 100644 --- a/examples/2d/2d_shapes.rs +++ b/examples/2d/2d_shapes.rs @@ -1,16 +1,26 @@ //! Shows how to render simple primitive shapes with a single color. +//! +//! You can toggle wireframes with the space bar except on wasm. Wasm does not support +//! `POLYGON_MODE_LINE` on the gpu. +#[cfg(not(target_arch = "wasm32"))] +use bevy::sprite::{Wireframe2dConfig, Wireframe2dPlugin}; use bevy::{ prelude::*, - sprite::{MaterialMesh2dBundle, Mesh2dHandle, Wireframe2dConfig, Wireframe2dPlugin}, + sprite::{MaterialMesh2dBundle, Mesh2dHandle}, }; fn main() { - App::new() - .add_plugins((DefaultPlugins, Wireframe2dPlugin)) - .add_systems(Startup, setup) - .add_systems(Update, toggle_wireframe) - .run(); + let mut app = App::new(); + app.add_plugins(( + DefaultPlugins, + #[cfg(not(target_arch = "wasm32"))] + Wireframe2dPlugin, + )) + .add_systems(Startup, setup); + #[cfg(not(target_arch = "wasm32"))] + app.add_systems(Update, toggle_wireframe); + app.run(); } const X_EXTENT: f32 = 900.; @@ -57,6 +67,7 @@ fn setup( }); } + #[cfg(not(target_arch = "wasm32"))] commands.spawn( TextBundle::from_section("Press space to toggle wireframes", TextStyle::default()) .with_style(Style { @@ -68,6 +79,7 @@ fn setup( ); } +#[cfg(not(target_arch = "wasm32"))] fn toggle_wireframe( mut wireframe_config: ResMut, keyboard: Res>, diff --git a/examples/3d/3d_shapes.rs b/examples/3d/3d_shapes.rs index 63fbcfe3f3..6abac8371a 100644 --- a/examples/3d/3d_shapes.rs +++ b/examples/3d/3d_shapes.rs @@ -1,11 +1,15 @@ //! This example demonstrates the built-in 3d shapes in Bevy. //! The scene includes a patterned texture and a rotation for visualizing the normals and UVs. +//! +//! You can toggle wireframes with the space bar except on wasm. Wasm does not support +//! `POLYGON_MODE_LINE` on the gpu. use std::f32::consts::PI; +#[cfg(not(target_arch = "wasm32"))] +use bevy::pbr::wireframe::{WireframeConfig, WireframePlugin}; use bevy::{ color::palettes::basic::SILVER, - pbr::wireframe::{WireframeConfig, WireframePlugin}, prelude::*, render::{ render_asset::RenderAssetUsages, @@ -17,10 +21,18 @@ fn main() { App::new() .add_plugins(( DefaultPlugins.set(ImagePlugin::default_nearest()), + #[cfg(not(target_arch = "wasm32"))] WireframePlugin, )) .add_systems(Startup, setup) - .add_systems(Update, (rotate, toggle_wireframe)) + .add_systems( + Update, + ( + rotate, + #[cfg(not(target_arch = "wasm32"))] + toggle_wireframe, + ), + ) .run(); } @@ -128,6 +140,7 @@ fn setup( ..default() }); + #[cfg(not(target_arch = "wasm32"))] commands.spawn( TextBundle::from_section("Press space to toggle wireframes", TextStyle::default()) .with_style(Style { @@ -174,6 +187,7 @@ fn uv_debug_texture() -> Image { ) } +#[cfg(not(target_arch = "wasm32"))] fn toggle_wireframe( mut wireframe_config: ResMut, keyboard: Res>,