diff --git a/Cargo.toml b/Cargo.toml index 0abe25c..c96212d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2021" name = "bevy_polyline" -version = "0.13.0" +version = "0.14.0" description = "Polyline Rendering for Bevy" license = "MIT OR Apache-2.0" repository = "https://github.com/ForesightMiningSoftwareCorporation/bevy_polyline" @@ -17,20 +17,20 @@ authors = [ ] [dependencies] -bitflags = "2.3" -bevy = { version = "0.17", default-features = false, features = [ +bitflags = "2.11" +bevy = { version = "0.18", default-features = false, features = [ "bevy_core_pipeline", "bevy_render", "bevy_asset", ] } -bevy_post_process = "0.17" -bytemuck = "1.16.1" +bevy_post_process = "0.18" +bytemuck = "1.25" [dev-dependencies] -lazy_static = "1.4.0" -rand = "0.8.4" -ringbuffer = "0.15" -bevy = { version = "0.17", default-features = false, features = [ +lazy_static = "1.5.0" +rand = "0.10" +ringbuffer = "0.16" +bevy = { version = "0.18", default-features = false, features = [ "bevy_window", "bevy_winit", "bevy_pbr", diff --git a/README.md b/README.md index 0964f1c..19ef3cf 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ We intend to track the `main` branch of Bevy. PRs supporting this are welcome! | bevy | bevy_polyline | | ---- | ------------- | +| 0.18 | 0.14 | | 0.17 | 0.13 | | 0.16 | 0.12 | | 0.15 | 0.11 | diff --git a/examples/nbody.rs b/examples/nbody.rs index ea46005..73a7e7a 100644 --- a/examples/nbody.rs +++ b/examples/nbody.rs @@ -11,7 +11,7 @@ use bevy_polyline::prelude::*; use bevy_post_process::bloom::Bloom; use lazy_static::*; -use rand::{prelude::*, Rng}; +use rand::prelude::*; use ringbuffer::{ConstGenericRingBuffer, RingBuffer}; const NUM_BODIES: usize = 512; @@ -44,14 +44,14 @@ fn setup( ) { let mut rng = StdRng::seed_from_u64(0); for _index in 0..NUM_BODIES { - let r = rng.gen_range(2f32..800f32); - let theta = rng.gen_range(0f32..2.0 * PI); + let r = rng.random_range(2f32..800f32); + let theta = rng.random_range(0f32..2.0 * PI); let position = Vec3A::new( r * f32::cos(theta), - rng.gen_range(-500f32..500f32), + rng.random_range(-500f32..500f32), r * f32::sin(theta), ); - let size = rng.gen_range(50f32..1000f32); + let size = rng.random_range(50f32..1000f32); commands.spawn(( Body { mass: size, @@ -67,7 +67,7 @@ fn setup( material: PolylineMaterialHandle( polyline_materials.add(PolylineMaterial { width: (size * 0.1).powf(1.8), - color: Color::hsl(rng.gen_range(0.0..360.0), 1.0, rng.gen_range(1.2..3.0)) + color: Color::hsl(rng.random_range(0.0..360.0), 1.0, rng.random_range(1.2..3.0)) .to_linear(), perspective: true, ..Default::default() @@ -217,7 +217,7 @@ fn update_trails( }; let gt_min_angle = last_vec.dot(last_last_vec) > MINIMUM_ANGLE; if gt_min_angle { - trail.0.push(body.position); + trail.0.enqueue(body.position); polylines.get_mut(&polyline.0).unwrap().vertices = trail.0.iter().map(|v| Vec3::from(*v)).collect() } else { @@ -233,7 +233,7 @@ fn update_trails( } } } else { - trail.0.push(body.position); + trail.0.enqueue(body.position); polylines.get_mut(&polyline.0).unwrap().vertices = trail.0.iter().map(|v| Vec3::from(*v)).collect() } diff --git a/src/lib.rs b/src/lib.rs index c8fb605..72bde19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ pub struct PolylinePlugin; pub const SHADER_HANDLE: Handle = uuid_handle!("b180bfe9-10c8-48fe-b27a-dfa41436d7d0"); impl Plugin for PolylinePlugin { - fn build(&self, app: &mut bevy::prelude::App) { + fn build(&self, app: &mut App) { load_internal_asset!( app, SHADER_HANDLE, diff --git a/src/material.rs b/src/material.rs index 77ea074..a148e18 100644 --- a/src/material.rs +++ b/src/material.rs @@ -9,7 +9,7 @@ use bevy::{ prepass::{OpaqueNoLightmap3dBatchSetKey, OpaqueNoLightmap3dBinKey}, }, ecs::{ - component::Tick, + change_detection::Tick, query::ROQueryItem, system::{ lifetimeless::{Read, SRes}, @@ -76,8 +76,8 @@ impl Default for PolylineMaterial { } impl PolylineMaterial { - pub fn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout { - render_device.create_bind_group_layout( + pub fn bind_group_layout_descriptor() -> BindGroupLayoutDescriptor { + BindGroupLayoutDescriptor::new( "polyline_material_layout", &BindGroupLayoutEntries::single( ShaderStages::VERTEX, @@ -116,6 +116,7 @@ impl RenderAsset for GpuPolylineMaterial { type SourceAsset = PolylineMaterial; type Param = ( SRes, + SRes, SRes, SRes, ); @@ -123,7 +124,7 @@ impl RenderAsset for GpuPolylineMaterial { fn prepare_asset( polyline_material: Self::SourceAsset, _: AssetId, - (device, queue, polyline_pipeline): &mut bevy::ecs::system::SystemParamItem, + (device, cache, queue, polyline_pipeline): &mut SystemParamItem, _: Option<&Self>, ) -> Result> { let value = PolylineMaterialUniform { @@ -141,7 +142,7 @@ impl RenderAsset for GpuPolylineMaterial { let bind_group = device.create_bind_group( Some("polyline_material_bind_group"), - &polyline_pipeline.material_layout, + &cache.get_bind_group_layout(&polyline_pipeline.material_layout), &BindGroupEntries::single(buffer_binding), ); @@ -190,13 +191,12 @@ impl Plugin for PolylineMaterialPlugin { #[derive(Resource)] pub struct PolylineMaterialPipeline { pub polyline_pipeline: PolylinePipeline, - pub material_layout: BindGroupLayout, + pub material_layout: BindGroupLayoutDescriptor, } impl FromWorld for PolylineMaterialPipeline { fn from_world(world: &mut World) -> Self { - let render_device = world.get_resource::().unwrap(); - let material_layout = PolylineMaterial::bind_group_layout(render_device); + let material_layout = PolylineMaterial::bind_group_layout_descriptor(); let pipeline = world.get_resource::().unwrap(); PolylineMaterialPipeline { polyline_pipeline: pipeline.to_owned(), @@ -234,9 +234,9 @@ type DrawPolylineMaterial = ( pub struct SetPolylineViewBindGroup; impl RenderCommand

for SetPolylineViewBindGroup { + type Param = (); type ViewQuery = (Read, Read); type ItemQuery = (); - type Param = (); #[inline] fn render<'w>( @@ -253,9 +253,9 @@ impl RenderCommand

for SetPolylineViewBindGroup pub struct SetMaterialBindGroup; impl RenderCommand

for SetMaterialBindGroup { + type Param = SRes>; type ViewQuery = (); type ItemQuery = Read; - type Param = SRes>; fn render<'w>( _item: &P, diff --git a/src/polyline.rs b/src/polyline.rs index 4c33bc7..7d5bafa 100644 --- a/src/polyline.rs +++ b/src/polyline.rs @@ -83,7 +83,7 @@ impl RenderAsset for GpuPolyline { fn prepare_asset( polyline: Self::SourceAsset, _: AssetId, - render_device: &mut bevy::ecs::system::SystemParamItem, + render_device: &mut SystemParamItem, _: Option<&Self>, ) -> Result> { let vertex_buffer_data = bytemuck::cast_slice(polyline.vertices.as_slice()); @@ -145,15 +145,14 @@ pub fn extract_polylines( #[derive(Clone, Resource)] pub struct PolylinePipeline { - pub view_layout: BindGroupLayout, - pub polyline_layout: BindGroupLayout, + pub view_layout: BindGroupLayoutDescriptor, + pub polyline_layout: BindGroupLayoutDescriptor, pub shader: Handle, } impl FromWorld for PolylinePipeline { - fn from_world(world: &mut World) -> Self { - let render_device = world.get_resource::().unwrap(); - let view_layout = render_device.create_bind_group_layout( + fn from_world(_world: &mut World) -> Self { + let view_layout = BindGroupLayoutDescriptor::new( "polyline_view_layout", &BindGroupLayoutEntries::single( ShaderStages::VERTEX, @@ -161,7 +160,7 @@ impl FromWorld for PolylinePipeline { ), ); - let polyline_layout = render_device.create_bind_group_layout( + let polyline_layout = BindGroupLayoutDescriptor::new( "polyline_layout", &BindGroupLayoutEntries::single( ShaderStages::VERTEX, @@ -286,9 +285,9 @@ bitflags::bitflags! { // MSAA uses the highest 3 bits for the MSAA log2(sample count) to support up to 128x MSAA. pub struct PolylinePipelineKey: u32 { const NONE = 0; - const PERSPECTIVE = (1 << 0); - const TRANSPARENT_MAIN_PASS = (1 << 1); - const HDR = (1 << 2); + const PERSPECTIVE = 1 << 0; + const TRANSPARENT_MAIN_PASS = 1 << 1; + const HDR = 1 << 2; const MSAA_RESERVED_BITS = Self::MSAA_MASK_BITS << Self::MSAA_SHIFT_BITS; } } @@ -325,13 +324,14 @@ pub fn prepare_polyline_bind_group( mut commands: Commands, polyline_pipeline: Res, render_device: Res, + pipeline_cache: Res, polyline_uniforms: Res>, ) { if let Some(binding) = polyline_uniforms.uniforms().binding() { commands.insert_resource(PolylineBindGroup { value: render_device.create_bind_group( Some("polyline_bind_group"), - &polyline_pipeline.polyline_layout, + &pipeline_cache.get_bind_group_layout(&polyline_pipeline.polyline_layout), &BindGroupEntries::single(binding), ), }); @@ -347,15 +347,20 @@ pub struct PolylineViewBindGroup { pub fn prepare_polyline_view_bind_groups( mut commands: Commands, render_device: Res, + pipeline_cache: Res, polyline_pipeline: Res, view_uniforms: Res, views: Query>, ) { for entity in views.iter() { + let Some(view_uniforms_binding) = view_uniforms.uniforms.binding() else { + continue; + }; + let view_bind_group = render_device.create_bind_group( Some("polyline_view_bind_group"), - &polyline_pipeline.view_layout, - &BindGroupEntries::single(&view_uniforms.uniforms), + &pipeline_cache.get_bind_group_layout(&polyline_pipeline.view_layout), + &BindGroupEntries::single(view_uniforms_binding), ); commands.entity(entity).insert(PolylineViewBindGroup { @@ -366,9 +371,9 @@ pub fn prepare_polyline_view_bind_groups( pub struct SetPolylineBindGroup; impl RenderCommand

for SetPolylineBindGroup { + type Param = SRes; type ViewQuery = (); type ItemQuery = Read>; - type Param = SRes; #[inline] fn render<'w>( @@ -388,9 +393,9 @@ impl RenderCommand

for SetPolylineBindGroup pub struct DrawPolyline; impl RenderCommand

for DrawPolyline { + type Param = SRes>; type ViewQuery = (); type ItemQuery = Read; - type Param = SRes>; #[inline] fn render<'w>(