-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from TheRawMeatball/split-renderer
Split the renderer
- Loading branch information
Showing
28 changed files
with
415 additions
and
276 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "bevy_kayak_renderer" | ||
version = "0.0.1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bytemuck = "1.7.2" | ||
bevy = { version = "0.6.0" } | ||
kayak_font = { path = "../kayak_font" } | ||
serde = "1.0" | ||
serde_json = "1.0" | ||
serde_path_to_error = "0.1" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use bevy::{ | ||
prelude::*, | ||
window::{WindowCreated, WindowResized}, | ||
}; | ||
|
||
pub mod camera; | ||
pub mod render; | ||
|
||
pub use camera::*; | ||
|
||
#[derive(Default)] | ||
pub struct BevyKayakRendererPlugin; | ||
|
||
impl Plugin for BevyKayakRendererPlugin { | ||
fn build(&self, app: &mut bevy::prelude::App) { | ||
app.add_system(update_window_size) | ||
.init_resource::<WindowSize>() | ||
.add_plugin(render::BevyKayakUIRenderPlugin) | ||
.add_plugin(camera::KayakUICameraPlugin); | ||
} | ||
} | ||
|
||
/// Tracks the bevy window size. | ||
#[derive(Default, Debug, Clone, Copy, PartialEq)] | ||
pub struct WindowSize(pub f32, pub f32); | ||
|
||
fn update_window_size( | ||
mut window_resized_events: EventReader<WindowResized>, | ||
mut window_created_events: EventReader<WindowCreated>, | ||
) { | ||
let mut changed_window_ids = Vec::new(); | ||
// handle resize events. latest events are handled first because we only want to resize each | ||
// window once | ||
for event in window_resized_events.iter().rev() { | ||
if changed_window_ids.contains(&event.id) { | ||
continue; | ||
} | ||
|
||
changed_window_ids.push(event.id); | ||
} | ||
|
||
// handle resize events. latest events are handled first because we only want to resize each | ||
// window once | ||
for event in window_created_events.iter().rev() { | ||
if changed_window_ids.contains(&event.id) { | ||
continue; | ||
} | ||
|
||
changed_window_ids.push(event.id); | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Default)] | ||
pub struct Corner<T> { | ||
pub top_left: T, | ||
pub top_right: T, | ||
pub bottom_left: T, | ||
pub bottom_right: T, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use bevy::{ | ||
core_pipeline::node::MAIN_PASS_DRIVER, | ||
prelude::{Commands, Plugin, Res}, | ||
render::{ | ||
camera::ActiveCameras, | ||
render_graph::{EmptyNode, RenderGraph, SlotInfo, SlotType}, | ||
render_phase::{DrawFunctions, RenderPhase}, | ||
RenderApp, RenderStage, | ||
}, | ||
}; | ||
|
||
use crate::{ | ||
render::{ | ||
ui_pass::MainPassUINode, ui_pass_driver::UIPassDriverNode, unified::UnifiedRenderPlugin, | ||
}, | ||
UICameraBundle, | ||
}; | ||
|
||
use self::ui_pass::TransparentUI; | ||
|
||
mod ui_pass; | ||
mod ui_pass_driver; | ||
pub mod unified; | ||
|
||
pub mod node { | ||
pub const UI_PASS_DEPENDENCIES: &str = "kayak_ui_pass_dependencies"; | ||
pub const UI_PASS_DRIVER: &str = "kayak_ui_pass_driver"; | ||
} | ||
|
||
pub mod draw_ui_graph { | ||
pub const NAME: &str = "kayak_draw_ui"; | ||
pub mod input { | ||
pub const VIEW_ENTITY: &str = "kayak_view_entity"; | ||
} | ||
pub mod node { | ||
pub const MAIN_PASS: &str = "kayak_ui_pass"; | ||
} | ||
} | ||
|
||
pub struct BevyKayakUIRenderPlugin; | ||
|
||
impl Plugin for BevyKayakUIRenderPlugin { | ||
fn build(&self, app: &mut bevy::prelude::App) { | ||
let render_app = app.sub_app_mut(RenderApp); | ||
render_app | ||
.init_resource::<DrawFunctions<TransparentUI>>() | ||
.add_system_to_stage(RenderStage::Extract, extract_core_pipeline_camera_phases); | ||
// .add_system_to_stage(RenderStage::PhaseSort, sort_phase_system::<TransparentUI>); | ||
|
||
let pass_node_ui = MainPassUINode::new(&mut render_app.world); | ||
let mut graph = render_app.world.get_resource_mut::<RenderGraph>().unwrap(); | ||
|
||
let mut draw_ui_graph = RenderGraph::default(); | ||
draw_ui_graph.add_node(draw_ui_graph::node::MAIN_PASS, pass_node_ui); | ||
let input_node_id = draw_ui_graph.set_input(vec![SlotInfo::new( | ||
draw_ui_graph::input::VIEW_ENTITY, | ||
SlotType::Entity, | ||
)]); | ||
draw_ui_graph | ||
.add_slot_edge( | ||
input_node_id, | ||
draw_ui_graph::input::VIEW_ENTITY, | ||
draw_ui_graph::node::MAIN_PASS, | ||
MainPassUINode::IN_VIEW, | ||
) | ||
.unwrap(); | ||
graph.add_sub_graph(draw_ui_graph::NAME, draw_ui_graph); | ||
|
||
graph.add_node(node::UI_PASS_DEPENDENCIES, EmptyNode); | ||
graph.add_node(node::UI_PASS_DRIVER, UIPassDriverNode); | ||
graph | ||
.add_node_edge(node::UI_PASS_DEPENDENCIES, node::UI_PASS_DRIVER) | ||
.unwrap(); | ||
graph | ||
.add_node_edge(MAIN_PASS_DRIVER, node::UI_PASS_DRIVER) | ||
.unwrap(); | ||
|
||
app.add_plugin(UnifiedRenderPlugin); | ||
} | ||
} | ||
|
||
pub fn extract_core_pipeline_camera_phases( | ||
mut commands: Commands, | ||
active_cameras: Res<ActiveCameras>, | ||
) { | ||
if let Some(camera_2d) = active_cameras.get(UICameraBundle::UI_CAMERA) { | ||
if let Some(entity) = camera_2d.entity { | ||
commands | ||
.get_or_spawn(entity) | ||
.insert(RenderPhase::<TransparentUI>::default()); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use bevy::{ | ||
prelude::{Assets, Commands, HandleUntyped, Plugin, Res}, | ||
reflect::TypeUuid, | ||
render::{render_phase::DrawFunctions, render_resource::Shader, RenderApp, RenderStage}, | ||
window::Windows, | ||
}; | ||
|
||
use crate::{ | ||
render::{ | ||
ui_pass::TransparentUI, | ||
unified::pipeline::{DrawUI, QuadMeta, UnifiedPipeline}, | ||
}, | ||
WindowSize, | ||
}; | ||
|
||
use self::pipeline::ImageBindGroups; | ||
|
||
pub mod pipeline; | ||
mod text; | ||
|
||
pub const UNIFIED_SHADER_HANDLE: HandleUntyped = | ||
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 7604018236855288450); | ||
|
||
pub struct UnifiedRenderPlugin; | ||
|
||
impl Plugin for UnifiedRenderPlugin { | ||
fn build(&self, app: &mut bevy::prelude::App) { | ||
let mut shaders = app.world.get_resource_mut::<Assets<Shader>>().unwrap(); | ||
let unified_shader = Shader::from_wgsl(include_str!("shader.wgsl")); | ||
shaders.set_untracked(UNIFIED_SHADER_HANDLE, unified_shader); | ||
|
||
app.add_plugin(text::TextRendererPlugin); | ||
|
||
let render_app = app.sub_app_mut(RenderApp); | ||
render_app | ||
.init_resource::<ImageBindGroups>() | ||
.init_resource::<UnifiedPipeline>() | ||
.init_resource::<QuadMeta>() | ||
.add_system_to_stage(RenderStage::Extract, extract_baseline) | ||
.add_system_to_stage(RenderStage::Prepare, pipeline::prepare_quads) | ||
.add_system_to_stage(RenderStage::Queue, pipeline::queue_quads); | ||
|
||
let draw_quad = DrawUI::new(&mut render_app.world); | ||
|
||
render_app | ||
.world | ||
.get_resource::<DrawFunctions<TransparentUI>>() | ||
.unwrap() | ||
.write() | ||
.add(draw_quad); | ||
} | ||
} | ||
|
||
pub struct Dpi(f32); | ||
|
||
pub fn extract_baseline( | ||
mut commands: Commands, | ||
windows: Res<Windows>, | ||
window_size: Res<WindowSize>, | ||
) { | ||
let dpi = if let Some(window) = windows.get_primary() { | ||
window.scale_factor() as f32 | ||
} else { | ||
1.0 | ||
}; | ||
|
||
commands.insert_resource(*window_size); | ||
commands.insert_resource(Dpi(dpi)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
32 changes: 3 additions & 29 deletions
32
bevy_kayak_ui/src/render/unified/font/mod.rs → ...kayak_renderer/src/render/unified/text.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.