Skip to content

Commit

Permalink
Disabled usage of the POLYGON_MODE_LINE gpu feature in the examples (#…
Browse files Browse the repository at this point in the history
…14402)

Fixes #14353
Fixes #14371

---------

Signed-off-by: Sarthak Singh <[email protected]>
Co-authored-by: Alice Cecile <[email protected]>
Co-authored-by: BD103 <[email protected]>
  • Loading branch information
3 people authored Jul 29, 2024
1 parent 848e7fa commit a9f4fd8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,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"
Expand Down
24 changes: 18 additions & 6 deletions examples/2d/2d_shapes.rs
Original file line number Diff line number Diff line change
@@ -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.;
Expand Down Expand Up @@ -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 {
Expand All @@ -68,6 +79,7 @@ fn setup(
);
}

#[cfg(not(target_arch = "wasm32"))]
fn toggle_wireframe(
mut wireframe_config: ResMut<Wireframe2dConfig>,
keyboard: Res<ButtonInput<KeyCode>>,
Expand Down
18 changes: 16 additions & 2 deletions examples/3d/3d_shapes.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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();
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -174,6 +187,7 @@ fn uv_debug_texture() -> Image {
)
}

#[cfg(not(target_arch = "wasm32"))]
fn toggle_wireframe(
mut wireframe_config: ResMut<WireframeConfig>,
keyboard: Res<ButtonInput<KeyCode>>,
Expand Down

0 comments on commit a9f4fd8

Please sign in to comment.