-
Notifications
You must be signed in to change notification settings - Fork 50
/
mod.rs
142 lines (126 loc) · 4.18 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#[cfg(feature = "svg")]
use bevy::prelude::AssetApp;
use bevy::{
asset::{load_internal_asset, Handle},
prelude::{Commands, IntoSystemConfigs, Plugin, Query, Res, ResMut, Resource, With},
render::{
render_phase::AddRenderCommand,
render_resource::{Shader, SpecializedRenderPipelines},
renderer::{RenderDevice, RenderQueue},
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
},
window::{PrimaryWindow, Window},
};
#[cfg(feature = "svg")]
use bevy_svg::prelude::Svg;
use crate::{
render::{
ui_pass::TransparentUI,
unified::pipeline::{DrawUI, QuadMeta, UnifiedPipeline},
},
WindowSize,
};
use self::pipeline::{
queue_quad_types, queue_ui_view_bind_groups, DrawUITransparent, ExtractedQuads,
ImageBindGroups, PreviousClip, PreviousIndex, QuadTypeOffsets,
};
#[cfg(feature = "svg")]
use super::svg::RenderSvgs;
use super::ui_pass::TransparentOpacityUI;
pub mod pipeline;
pub mod text;
pub const UNIFIED_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(7604018236855288450);
pub const UNIFIED_BINDINGS_HANDLE: Handle<Shader> = Handle::weak_from_u128(13885898746900949245);
pub const SAMPLE_QUAD_HANDLE: Handle<Shader> = Handle::weak_from_u128(5975018398368429820);
pub const VERTEX_OUTPUT_HANDLE: Handle<Shader> = Handle::weak_from_u128(8828896277688845893);
pub struct UnifiedRenderPlugin;
impl Plugin for UnifiedRenderPlugin {
fn build(&self, app: &mut bevy::prelude::App) {
#[cfg(feature = "svg")]
app.init_asset::<Svg>();
app.add_plugins(text::TextRendererPlugin);
load_internal_asset!(
app,
UNIFIED_BINDINGS_HANDLE,
"shaders/bindings.wgsl",
Shader::from_wgsl
);
load_internal_asset!(
app,
SAMPLE_QUAD_HANDLE,
"shaders/sample_quad.wgsl",
Shader::from_wgsl
);
load_internal_asset!(
app,
VERTEX_OUTPUT_HANDLE,
"shaders/vertex_output.wgsl",
Shader::from_wgsl
);
load_internal_asset!(
app,
UNIFIED_SHADER_HANDLE,
"shaders/shader.wgsl",
Shader::from_wgsl
);
}
fn finish(&self, app: &mut bevy::prelude::App) {
let render_app = app.sub_app_mut(RenderApp);
render_app
.init_resource::<UnifiedPipeline>()
.init_resource::<SpecializedRenderPipelines<UnifiedPipeline>>()
.init_resource::<QuadTypeOffsets>()
.init_resource::<ExtractedQuads>()
.init_resource::<ImageBindGroups>()
.init_resource::<QuadMeta>();
#[cfg(feature = "svg")]
render_app.init_resource::<RenderSvgs>();
render_app
.init_resource::<PreviousClip>()
.init_resource::<PreviousIndex>()
.add_systems(
ExtractSchedule,
(
#[cfg(feature = "svg")]
super::svg::extract_svg_asset,
extract_baseline,
),
)
.add_systems(
Render,
(
queue_quad_types,
(pipeline::queue_quads, queue_ui_view_bind_groups),
)
.chain()
.in_set(RenderSet::Queue),
)
.add_systems(Render, queue_vertices.in_set(RenderSet::QueueMeshes));
render_app.add_render_command::<TransparentUI, DrawUI>();
render_app.add_render_command::<TransparentOpacityUI, DrawUITransparent>();
}
}
#[derive(Resource)]
pub struct Dpi(f32);
pub fn extract_baseline(
mut commands: Commands,
windows: Extract<Query<&Window, With<PrimaryWindow>>>,
window_size: Extract<Res<WindowSize>>,
) {
let dpi = if let Ok(window) = windows.get_single() {
window.scale_factor()
} else {
1.0
};
commands.insert_resource(**window_size);
commands.insert_resource(Dpi(dpi));
}
pub fn queue_vertices(
render_device: Res<RenderDevice>,
render_queue: Res<RenderQueue>,
mut quad_meta: ResMut<QuadMeta>,
) {
quad_meta
.vertices
.write_buffer(&render_device, &render_queue);
}