Skip to content

Commit

Permalink
Merge pull request #975 from tychedelia/0.15-dev
Browse files Browse the repository at this point in the history
Upgrade to Bevy `0.15-dev`
  • Loading branch information
tychedelia authored Sep 6, 2024
2 parents 384f42e + 8bf87f7 commit e6c19ab
Show file tree
Hide file tree
Showing 21 changed files with 1,432 additions and 616 deletions.
1,596 changes: 1,156 additions & 440 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ members = [
resolver = "2"

[workspace.dependencies]
bevy = "0.14.0"
bevy_egui = "0.28.0"
bevy-inspector-egui = "0.25.0"
bevy = { git = "https://github.com/bevyengine/bevy", branch = "main" }
bevy_egui = { git = "https://github.com/tychedelia/bevy_egui", branch = "main" }
bevy-inspector-egui = { git = "https://github.com/tychedelia/bevy-inspector-egui", branch = "main" }
image = "0.25"
rayon = "1.10"
bevy_common_assets = "0.11.0"
serde = "1"
serde_json = "1"
toml = "0.8"
serde_yaml = "0.9"
wgpu = "0.20"
wgpu = "22.0"
2 changes: 1 addition & 1 deletion bevy_nannou/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bevy = { workspace = true }
bevy = { workspace = true, features = ["jpeg"]}
bevy_nannou_draw = { path = "../bevy_nannou_draw" }
bevy_nannou_isf = { path = "../bevy_nannou_isf", optional = true }
bevy_nannou_video = { path = "../bevy_nannou_video", optional = true }
Expand Down
6 changes: 5 additions & 1 deletion bevy_nannou/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ pub mod prelude {
pub use bevy::color::*;
pub use bevy::core_pipeline::bloom::*;
pub use bevy::input::mouse::MouseWheel;
pub use bevy::prelude::*;
pub use bevy::prelude::{
debug, default, error, info, light_consts, trace, warn, ClearColorConfig, Entity, Handle,
Image, KeyCode, MonitorSelection, MouseButton, OrthographicProjection, TouchInput, Vec3,
Window, WindowResizeConstraints,
};
pub use bevy::render::render_asset::*;
pub use bevy::render::render_resource::*;
pub use bevy::winit::UpdateMode;
Expand Down
57 changes: 39 additions & 18 deletions bevy_nannou_draw/src/draw/instanced.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! A shader that renders a mesh multiple times in one draw call.

use bevy::render::mesh::allocator::MeshAllocator;
use bevy::render::mesh::RenderMeshBufferInfo;
use bevy::render::render_phase::ViewSortedRenderPhases;
use bevy::{
core_pipeline::core_3d::Transparent3d,
Expand All @@ -13,7 +15,7 @@ use bevy::{
prelude::*,
render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
mesh::{GpuBufferInfo, GpuMesh, MeshVertexBufferLayoutRef},
mesh::{MeshVertexBufferLayoutRef, RenderMesh},
render_asset::RenderAssets,
render_phase::{
AddRenderCommand, DrawFunctions, PhaseItem, PhaseItemExtraIndex, RenderCommand,
Expand Down Expand Up @@ -155,20 +157,18 @@ pub struct InstanceData {
fn queue_instanced(
transparent_3d_draw_functions: Res<DrawFunctions<Transparent3d>>,
custom_pipeline: Res<InstancedDataPipeline>,
msaa: Res<Msaa>,
mut pipelines: ResMut<SpecializedMeshPipelines<InstancedDataPipeline>>,
pipeline_cache: Res<PipelineCache>,
meshes: Res<RenderAssets<GpuMesh>>,
meshes: Res<RenderAssets<RenderMesh>>,
render_mesh_instances: Res<RenderMeshInstances>,
material_meshes: Query<Entity, With<InstanceMaterialData>>,
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<Transparent3d>>,
mut views: Query<(Entity, &ExtractedView)>,
mut views: Query<(Entity, &ExtractedView, &Msaa)>,
) {
let draw_custom = transparent_3d_draw_functions.read().id::<DrawInstanced>();

let msaa_key = MeshPipelineKey::from_msaa_samples(msaa.samples());

for (view_entity, view) in &mut views {
for (view_entity, view, msaa) in &mut views {
let msaa_key = MeshPipelineKey::from_msaa_samples(msaa.samples());
let Some(transparent_phase) = transparent_render_phases.get_mut(&view_entity) else {
continue;
};
Expand Down Expand Up @@ -282,7 +282,11 @@ type DrawInstanced = (
struct DrawMeshInstanced;

impl<P: PhaseItem> RenderCommand<P> for DrawMeshInstanced {
type Param = (SRes<RenderAssets<GpuMesh>>, SRes<RenderMeshInstances>);
type Param = (
SRes<RenderAssets<RenderMesh>>,
SRes<RenderMeshInstances>,
SRes<MeshAllocator>,
);
type ViewQuery = ();
type ItemQuery = Read<InstanceBuffer>;

Expand All @@ -291,33 +295,50 @@ impl<P: PhaseItem> RenderCommand<P> for DrawMeshInstanced {
item: &P,
_view: (),
instance_buffer: Option<&'w InstanceBuffer>,
(meshes, render_mesh_instances): SystemParamItem<'w, '_, Self::Param>,
(meshes, render_mesh_instances, mesh_allocator): SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
// A borrow check workaround.
let mesh_allocator = mesh_allocator.into_inner();

let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(item.entity())
else {
return RenderCommandResult::Failure;
return RenderCommandResult::Skip;
};
let Some(gpu_mesh) = meshes.into_inner().get(mesh_instance.mesh_asset_id) else {
return RenderCommandResult::Failure;
return RenderCommandResult::Skip;
};
let Some(instance_buffer) = instance_buffer else {
return RenderCommandResult::Failure;
return RenderCommandResult::Skip;
};
let Some(vertex_buffer_slice) =
mesh_allocator.mesh_vertex_slice(&mesh_instance.mesh_asset_id)
else {
return RenderCommandResult::Skip;
};

pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..));
pass.set_vertex_buffer(0, vertex_buffer_slice.buffer.slice(..));
pass.set_vertex_buffer(1, instance_buffer.buffer.slice(..));

match &gpu_mesh.buffer_info {
GpuBufferInfo::Indexed {
buffer,
RenderMeshBufferInfo::Indexed {
index_format,
count,
} => {
pass.set_index_buffer(buffer.slice(..), 0, *index_format);
pass.draw_indexed(0..*count, 0, 0..instance_buffer.length as u32);
let Some(index_buffer_slice) =
mesh_allocator.mesh_index_slice(&mesh_instance.mesh_asset_id)
else {
return RenderCommandResult::Skip;
};

pass.set_index_buffer(index_buffer_slice.buffer.slice(..), 0, *index_format);
pass.draw_indexed(
index_buffer_slice.range.start..(index_buffer_slice.range.start + count),
vertex_buffer_slice.range.start as i32,
0..instance_buffer.length as u32,
);
}
GpuBufferInfo::NonIndexed => {
RenderMeshBufferInfo::NonIndexed => {
pass.draw(0..gpu_mesh.vertex_count, 0..instance_buffer.length as u32);
}
}
Expand Down
2 changes: 1 addition & 1 deletion bevy_nannou_isf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
bevy = { workspace = true, features = ["shader_format_glsl"] }
bevy_egui = { workspace = true }
bevy-inspector-egui = { workspace = true, features = ["bevy_render"] }
bevy-inspector-egui = { workspace = true }
isf = "0.1.0"
thiserror = "1"
bytemuck = "1"
Expand Down
3 changes: 1 addition & 2 deletions bevy_nannou_isf/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl AssetLoader for IsfLoader {

async fn load<'a>(
&'a self,
reader: &'a mut Reader<'_>,
reader: &'a mut dyn Reader,
settings: &'a Self::Settings,
load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
Expand All @@ -75,7 +75,6 @@ impl AssetLoader for IsfLoader {
let isf = isf::parse(glsl_src).map_err(|e| IsfAssetLoaderError::Parse(e))?;
let glsl = glsl_string_from_isf(&isf);
let glsl = prefix_isf_glsl_str(&glsl, glsl_src.to_string());
info!("GLSL: {}", glsl);
let shader = Shader::from_glsl(glsl, ShaderStage::Fragment, file!());
let shader = load_context.add_labeled_asset(String::from("shader"), shader);

Expand Down
Loading

0 comments on commit e6c19ab

Please sign in to comment.