Skip to content

Commit c6c8c22

Browse files
committed
fix webgl2 by default
1 parent b911823 commit c6c8c22

File tree

8 files changed

+28
-23
lines changed

8 files changed

+28
-23
lines changed

crates/bevy_core_pipeline/src/core_2d/main_pass_2d_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl Node for MainPass2dNode {
8181

8282
// WebGL2 quirk: if ending with a render pass with a custom viewport, the viewport isn't
8383
// reset for the next render pass so add an empty render pass without a custom viewport
84-
#[cfg(feature = "webgl")]
84+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
8585
if camera.viewport.is_some() {
8686
#[cfg(feature = "trace")]
8787
let _reset_viewport_pass_2d = info_span!("reset_viewport_pass_2d").entered();

crates/bevy_core_pipeline/src/core_3d/main_transparent_pass_3d_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl Node for MainTransparentPass3dNode {
9292

9393
// WebGL2 quirk: if ending with a render pass with a custom viewport, the viewport isn't
9494
// reset for the next render pass so add an empty render pass without a custom viewport
95-
#[cfg(feature = "webgl")]
95+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
9696
if camera.viewport.is_some() {
9797
#[cfg(feature = "trace")]
9898
let _reset_viewport_pass_3d = info_span!("reset_viewport_pass_3d").entered();

crates/bevy_pbr/src/light.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl CascadeShadowConfigBuilder {
353353

354354
impl Default for CascadeShadowConfigBuilder {
355355
fn default() -> Self {
356-
if cfg!(feature = "webgl") {
356+
if cfg!(all(feature = "webgl", target_arch = "wasm32")) {
357357
// Currently only support one cascade in webgl.
358358
Self {
359359
num_cascades: 1,

crates/bevy_pbr/src/render/light.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ pub struct GpuLights {
217217
// NOTE: this must be kept in sync with the same constants in pbr.frag
218218
pub const MAX_UNIFORM_BUFFER_POINT_LIGHTS: usize = 256;
219219
pub const MAX_DIRECTIONAL_LIGHTS: usize = 10;
220-
#[cfg(not(feature = "webgl"))]
220+
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
221221
pub const MAX_CASCADES_PER_LIGHT: usize = 4;
222-
#[cfg(feature = "webgl")]
222+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
223223
pub const MAX_CASCADES_PER_LIGHT: usize = 1;
224224
pub const SHADOW_FORMAT: TextureFormat = TextureFormat::Depth32Float;
225225

@@ -683,13 +683,13 @@ pub fn prepare_lights(
683683
let mut point_lights: Vec<_> = point_lights.iter().collect::<Vec<_>>();
684684
let mut directional_lights: Vec<_> = directional_lights.iter().collect::<Vec<_>>();
685685

686-
#[cfg(not(feature = "webgl"))]
686+
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
687687
let max_texture_array_layers = render_device.limits().max_texture_array_layers as usize;
688-
#[cfg(not(feature = "webgl"))]
688+
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
689689
let max_texture_cubes = max_texture_array_layers / 6;
690-
#[cfg(feature = "webgl")]
690+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
691691
let max_texture_array_layers = 1;
692-
#[cfg(feature = "webgl")]
692+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
693693
let max_texture_cubes = 1;
694694

695695
if !*max_directional_lights_warning_emitted && directional_lights.len() > MAX_DIRECTIONAL_LIGHTS
@@ -1162,9 +1162,9 @@ pub fn prepare_lights(
11621162
.create_view(&TextureViewDescriptor {
11631163
label: Some("point_light_shadow_map_array_texture_view"),
11641164
format: None,
1165-
#[cfg(not(feature = "webgl"))]
1165+
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
11661166
dimension: Some(TextureViewDimension::CubeArray),
1167-
#[cfg(feature = "webgl")]
1167+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
11681168
dimension: Some(TextureViewDimension::Cube),
11691169
aspect: TextureAspect::All,
11701170
base_mip_level: 0,
@@ -1177,9 +1177,9 @@ pub fn prepare_lights(
11771177
.create_view(&TextureViewDescriptor {
11781178
label: Some("directional_light_shadow_map_array_texture_view"),
11791179
format: None,
1180-
#[cfg(not(feature = "webgl"))]
1180+
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
11811181
dimension: Some(TextureViewDimension::D2Array),
1182-
#[cfg(feature = "webgl")]
1182+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
11831183
dimension: Some(TextureViewDimension::D2),
11841184
aspect: TextureAspect::All,
11851185
base_mip_level: 0,

crates/bevy_pbr/src/render/mesh.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ impl FromWorld for MeshPipeline {
333333
ty: BindingType::Texture {
334334
multisampled: false,
335335
sample_type: TextureSampleType::Depth,
336-
#[cfg(not(feature = "webgl"))]
336+
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
337337
view_dimension: TextureViewDimension::CubeArray,
338-
#[cfg(feature = "webgl")]
338+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
339339
view_dimension: TextureViewDimension::Cube,
340340
},
341341
count: None,
@@ -354,9 +354,9 @@ impl FromWorld for MeshPipeline {
354354
ty: BindingType::Texture {
355355
multisampled: false,
356356
sample_type: TextureSampleType::Depth,
357-
#[cfg(not(feature = "webgl"))]
357+
#[cfg(any(not(feature = "webgl"), not(target_arch = "wasm32")))]
358358
view_dimension: TextureViewDimension::D2Array,
359-
#[cfg(feature = "webgl")]
359+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
360360
view_dimension: TextureViewDimension::D2,
361361
},
362362
count: None,
@@ -444,7 +444,9 @@ impl FromWorld for MeshPipeline {
444444
let tonemapping_lut_entries = get_lut_bind_group_layout_entries([14, 15]);
445445
entries.extend_from_slice(&tonemapping_lut_entries);
446446

447-
if cfg!(not(feature = "webgl")) || (cfg!(feature = "webgl") && !multisampled) {
447+
if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32")))
448+
|| (cfg!(all(feature = "webgl", target_arch = "wasm32")) && !multisampled)
449+
{
448450
entries.extend_from_slice(&prepass::get_bind_group_layout_entries(
449451
[16, 17, 18],
450452
multisampled,
@@ -1065,7 +1067,9 @@ pub fn queue_mesh_view_bind_groups(
10651067
entries.extend_from_slice(&tonemapping_luts);
10661068

10671069
// When using WebGL, we can't have a depth texture with multisampling
1068-
if cfg!(not(feature = "webgl")) || (cfg!(feature = "webgl") && msaa.samples() == 1) {
1070+
if cfg!(any(not(feature = "webgl"), not(target_arch = "wasm32")))
1071+
|| (cfg!(all(feature = "webgl", target_arch = "wasm32")) && msaa.samples() == 1)
1072+
{
10691073
entries.extend_from_slice(&prepass::get_bindings(
10701074
prepass_textures,
10711075
&mut fallback_images,

crates/bevy_render/src/globals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct GlobalsUniform {
5454
/// It wraps to zero when it reaches the maximum value of a u32.
5555
frame_count: u32,
5656
/// WebGL2 structs must be 16 byte aligned.
57-
#[cfg(feature = "webgl")]
57+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
5858
_wasm_padding: f32,
5959
}
6060

crates/bevy_render/src/render_resource/pipeline_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl ShaderCache {
194194
Entry::Occupied(entry) => entry.into_mut(),
195195
Entry::Vacant(entry) => {
196196
let mut shader_defs = shader_defs.to_vec();
197-
#[cfg(feature = "webgl")]
197+
#[cfg(all(feature = "webgl", target_arch = "wasm32"))]
198198
{
199199
shader_defs.push("NO_ARRAY_TEXTURES_SUPPORT".into());
200200
shader_defs.push("SIXTEEN_BYTE_ALIGNMENT".into());

crates/bevy_render/src/settings.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct WgpuSettings {
4545

4646
impl Default for WgpuSettings {
4747
fn default() -> Self {
48-
let default_backends = if cfg!(feature = "webgl") {
48+
let default_backends = if cfg!(all(feature = "webgl", target_arch = "wasm32")) {
4949
Backends::GL
5050
} else {
5151
Backends::all()
@@ -55,7 +55,8 @@ impl Default for WgpuSettings {
5555

5656
let priority = settings_priority_from_env().unwrap_or(WgpuSettingsPriority::Functionality);
5757

58-
let limits = if cfg!(feature = "webgl") || matches!(priority, WgpuSettingsPriority::WebGL2)
58+
let limits = if cfg!(all(feature = "webgl", target_arch = "wasm32"))
59+
|| matches!(priority, WgpuSettingsPriority::WebGL2)
5960
{
6061
wgpu::Limits::downlevel_webgl2_defaults()
6162
} else {

0 commit comments

Comments
 (0)