Skip to content

Commit

Permalink
Fix 2d_shapes and general 2D mesh instancing (bevyengine#10051)
Browse files Browse the repository at this point in the history
# Objective

- Fix bevyengine#10050 

## Solution

- Push constants needed to be defined in the pipeline layout and
`bevy_sprite` needed to have a `webgl` feature.
  • Loading branch information
superdump authored and Thomas Wilgenbus committed Oct 13, 2023
1 parent 384ac6a commit 7c8b9c9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ x11 = ["bevy_winit/x11"]
subpixel_glyph_atlas = ["bevy_text/subpixel_glyph_atlas"]

# Optimise for WebGL2
webgl = ["bevy_core_pipeline?/webgl", "bevy_pbr?/webgl", "bevy_render?/webgl", "bevy_gizmos?/webgl"]
webgl = ["bevy_core_pipeline?/webgl", "bevy_pbr?/webgl", "bevy_render?/webgl", "bevy_gizmos?/webgl", "bevy_sprite?/webgl"]

# enable systems that allow for automated testing on CI
bevy_ci_testing = ["bevy_app/bevy_ci_testing", "bevy_time/bevy_ci_testing", "bevy_render?/bevy_ci_testing", "bevy_render?/ci_limits"]
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_sprite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
webgl = []

[dependencies]
# bevy
bevy_app = { path = "../bevy_app", version = "0.12.0-dev" }
Expand Down
9 changes: 8 additions & 1 deletion crates/bevy_sprite/src/mesh2d/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,13 @@ impl SpecializedMeshPipeline for Mesh2dPipeline {
true => ViewTarget::TEXTURE_FORMAT_HDR,
false => TextureFormat::bevy_default(),
};
let mut push_constant_ranges = Vec::with_capacity(1);
if cfg!(all(feature = "webgl", target_arch = "wasm32")) {
push_constant_ranges.push(PushConstantRange {
stages: ShaderStages::VERTEX,
range: 0..4,
});
}

Ok(RenderPipelineDescriptor {
vertex: VertexState {
Expand All @@ -555,7 +562,7 @@ impl SpecializedMeshPipeline for Mesh2dPipeline {
})],
}),
layout: vec![self.view_layout.clone(), self.mesh_layout.clone()],
push_constant_ranges: Vec::new(),
push_constant_ranges,
primitive: PrimitiveState {
front_face: FrontFace::Ccw,
cull_mode: None,
Expand Down

0 comments on commit 7c8b9c9

Please sign in to comment.