Skip to content

Commit

Permalink
Port to Bevy 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
johanhelsing committed Apr 18, 2022
1 parent eea99ec commit be060cb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
19 changes: 6 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_smud"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
license = "MIT OR Apache-2.0"
authors = ["Johan Helsing <[email protected]>"]
Expand All @@ -10,25 +10,18 @@ categories = ["game-development", "rendering", "graphics"]
repository = "https://github.com/johanhelsing/bevy_smud"

[dependencies]
bevy = { version = "0.6.0", default-features = false, features = ["render"] }
bevy = { version = "0.7.0", default-features = false, features = ["render"] }
bytemuck = "1.7"
bitflags = "1.2"
copyless = "0.1"

[dev-dependencies]
bevy = "0.6"
bevy_pancam = "0.2"
bevy_lospec = { git = "https://github.com/johanhelsing/bevy_lospec", branch = "main" }
bevy_asset_loader = "0.8"
bevy = "0.7"
bevy_pancam = "0.3"
bevy_lospec = "0.1"
bevy_asset_loader = "0.10"
rand = "0.8"

# [features]
# smud_shader_hot_reloading = ["bevy/bevy_shader_hot_reloading"]

# [patch.crates-io]
# bevy = { git = "https://github.com/superdump/bevy", branch = "hot-reload-core-shaders" }
# bevy = { path = "../bevy" }

[profile.dev]
opt-level = 1

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ I intend to support the `main` branch of Bevy in the `bevy-main` branch.

|bevy|bevy_smud|
|---|---|
|0.6|0.1, main|
|0.7|0.2, main|
|0.6|0.1|

## Thanks!

Expand Down
22 changes: 11 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use bevy::{
render_resource::{
std140::AsStd140, BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout,
BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BlendState,
BufferBindingType, BufferSize, BufferUsages, BufferVec, CachedPipelineId,
BufferBindingType, BufferSize, BufferUsages, BufferVec, CachedRenderPipelineId,
ColorTargetState, ColorWrites, Face, FragmentState, FrontFace, MultisampleState,
PolygonMode, PrimitiveState, PrimitiveTopology, RenderPipelineCache,
RenderPipelineDescriptor, ShaderImport, ShaderStages, SpecializedPipeline,
SpecializedPipelines, TextureFormat, VertexAttribute, VertexBufferLayout, VertexFormat,
VertexState, VertexStepMode,
PipelineCache, PolygonMode, PrimitiveState, PrimitiveTopology,
RenderPipelineDescriptor, ShaderImport, ShaderStages, SpecializedRenderPipeline,
SpecializedRenderPipelines, TextureFormat, VertexAttribute, VertexBufferLayout,
VertexFormat, VertexState, VertexStepMode,
},
renderer::{RenderDevice, RenderQueue},
texture::BevyDefault,
Expand Down Expand Up @@ -84,7 +84,7 @@ impl Plugin for SmudPlugin {
.init_resource::<ExtractedShapes>()
.init_resource::<ShapeMeta>()
.init_resource::<SmudPipeline>()
.init_resource::<SpecializedPipelines<SmudPipeline>>()
.init_resource::<SpecializedRenderPipelines<SmudPipeline>>()
.add_system_to_stage(RenderStage::Extract, extract_shapes)
.add_system_to_stage(RenderStage::Extract, extract_sdf_shaders)
.add_system_to_stage(RenderStage::Queue, queue_shapes);
Expand Down Expand Up @@ -220,7 +220,7 @@ struct SmudPipelineKey {
shader: (HandleId, HandleId),
}

impl SpecializedPipeline for SmudPipeline {
impl SpecializedRenderPipeline for SmudPipeline {
type Key = SmudPipelineKey;

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
Expand Down Expand Up @@ -421,8 +421,8 @@ fn extract_shapes(
fn queue_shapes(
mut commands: Commands,
mut views: Query<(&mut RenderPhase<Transparent2d>, &VisibleEntities)>,
mut pipelines: ResMut<SpecializedPipelines<SmudPipeline>>,
mut pipeline_cache: ResMut<RenderPipelineCache>,
mut pipelines: ResMut<SpecializedRenderPipelines<SmudPipeline>>,
mut pipeline_cache: ResMut<PipelineCache>,
mut extracted_shapes: ResMut<ExtractedShapes>, // todo needs mut?
mut shape_meta: ResMut<ShapeMeta>,
transparent_draw_functions: Res<DrawFunctions<Transparent2d>>,
Expand Down Expand Up @@ -491,7 +491,7 @@ fn queue_shapes(
),
};
let mut current_batch_entity = Entity::from_raw(u32::MAX);
let mut current_batch_pipeline = CachedPipelineId::INVALID;
let mut current_batch_pipeline = CachedRenderPipelineId::INVALID;

// Add a phase item for each shape, and detect when successive items can be batched.
// Spawn an entity with a `ShapeBatch` component for each possible batch.
Expand Down Expand Up @@ -522,7 +522,7 @@ fn queue_shapes(
}
}

if current_batch_pipeline == CachedPipelineId::INVALID {
if current_batch_pipeline == CachedRenderPipelineId::INVALID {
debug!("Shape not ready yet, skipping");
continue; // skip shapes that are not ready yet
}
Expand Down
16 changes: 8 additions & 8 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use bevy::{
SetItemPipeline, TrackedRenderPass,
},
render_resource::{
BindGroupDescriptor, BindGroupEntry, CachedPipelineId, PrimitiveTopology,
RenderPipelineCache, SpecializedPipelines,
BindGroupDescriptor, BindGroupEntry, CachedRenderPipelineId, PipelineCache,
PrimitiveTopology, SpecializedRenderPipelines,
},
renderer::{RenderDevice, RenderQueue},
view::ViewUniforms,
Expand Down Expand Up @@ -109,8 +109,8 @@ fn extract_ui_shapes(

fn prepare_ui_shapes(
mut commands: Commands,
mut pipelines: ResMut<SpecializedPipelines<SmudPipeline>>,
mut pipeline_cache: ResMut<RenderPipelineCache>,
mut pipelines: ResMut<SpecializedRenderPipelines<SmudPipeline>>,
mut pipeline_cache: ResMut<PipelineCache>,
mut extracted_shapes: ResMut<ExtractedUiShapes>,
mut shape_meta: ResMut<ShapeMeta>, // TODO: make UI meta?
render_device: Res<RenderDevice>,
Expand Down Expand Up @@ -144,7 +144,7 @@ fn prepare_ui_shapes(
HandleId::Id(Uuid::nil(), u64::MAX),
);
let mut last_z = 0.;
let mut current_batch_pipeline = CachedPipelineId::INVALID;
let mut current_batch_pipeline = CachedRenderPipelineId::INVALID;

// todo: how should msaa be handled for ui?
// would perhaps be solved if I move this to queue?
Expand Down Expand Up @@ -181,11 +181,11 @@ fn prepare_ui_shapes(
};
pipelines.specialize(&mut pipeline_cache, &smud_pipeline, specialize_key)
}
None => CachedPipelineId::INVALID,
None => CachedRenderPipelineId::INVALID,
}
}

if current_batch_pipeline == CachedPipelineId::INVALID {
if current_batch_pipeline == CachedRenderPipelineId::INVALID {
debug!("Shape not ready yet, skipping");
continue; // skip shapes that are not ready yet
}
Expand Down Expand Up @@ -278,5 +278,5 @@ pub struct UiShapeBatch {
range: Range<u32>,
shader_key: (HandleId, HandleId),
z: FloatOrd,
pipeline: CachedPipelineId,
pipeline: CachedRenderPipelineId,
}

0 comments on commit be060cb

Please sign in to comment.