wgui: introduce SharedContext to share between Contexts
This commit is contained in:
@@ -33,11 +33,11 @@ pub struct GuiPanel {
|
||||
}
|
||||
|
||||
impl GuiPanel {
|
||||
pub fn new_from_template(app: &AppState, path: &str) -> anyhow::Result<Self> {
|
||||
pub fn new_from_template(app: &mut AppState, path: &str) -> anyhow::Result<Self> {
|
||||
let (layout, _state) =
|
||||
wgui::parser::new_layout_from_assets(Box::new(gui::asset::GuiAsset {}), path)?;
|
||||
|
||||
let context = WguiContext::new(app.gfx.clone(), app.gfx.surface_format, 1.0)?;
|
||||
let context = WguiContext::new(&mut app.wgui_shared, 1.0)?;
|
||||
let mut timestep = Timestep::new();
|
||||
timestep.set_tps(60.0);
|
||||
|
||||
@@ -48,9 +48,9 @@ impl GuiPanel {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_blank(app: &AppState) -> anyhow::Result<Self> {
|
||||
pub fn new_blank(app: &mut AppState) -> anyhow::Result<Self> {
|
||||
let layout = Layout::new(Box::new(GuiAsset {}))?;
|
||||
let context = WguiContext::new(app.gfx.clone(), app.gfx.surface_format, 1.0)?;
|
||||
let context = WguiContext::new(&mut app.wgui_shared, 1.0)?;
|
||||
let mut timestep = Timestep::new();
|
||||
timestep.set_tps(60.0);
|
||||
|
||||
@@ -177,7 +177,8 @@ impl OverlayRenderer for GuiPanel {
|
||||
buf: &mut CommandBuffers,
|
||||
_alpha: f32,
|
||||
) -> anyhow::Result<bool> {
|
||||
self.context.update_viewport(tgt.extent_u32arr(), 1.0)?;
|
||||
self.context
|
||||
.update_viewport(&mut app.wgui_shared, tgt.extent_u32arr(), 1.0)?;
|
||||
self.layout.update(MAX_SIZE_VEC2, self.timestep.alpha)?;
|
||||
|
||||
let mut cmd_buf = app
|
||||
@@ -187,7 +188,8 @@ impl OverlayRenderer for GuiPanel {
|
||||
|
||||
cmd_buf.begin_rendering(tgt)?;
|
||||
let primitives = wgui::drawing::draw(&self.layout)?;
|
||||
self.context.draw(&app.gfx, &mut cmd_buf, &primitives)?;
|
||||
self.context
|
||||
.draw(&mut app.wgui_shared, &mut cmd_buf, &primitives)?;
|
||||
cmd_buf.end_rendering()?;
|
||||
buf.push(cmd_buf.build()?);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ const PIXELS_PER_UNIT: f32 = 80.;
|
||||
|
||||
#[allow(clippy::too_many_lines, clippy::significant_drop_tightening)]
|
||||
pub fn create_keyboard<O>(
|
||||
app: &AppState,
|
||||
app: &mut AppState,
|
||||
mut keymap: Option<XkbKeymap>,
|
||||
) -> anyhow::Result<OverlayData<O>>
|
||||
where
|
||||
|
||||
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use std::sync::Arc;
|
||||
use vulkano::image::view::ImageView;
|
||||
use wgui::gfx::WGfx;
|
||||
use wgui::{gfx::WGfx, renderer_vk::context::SharedContext as WSharedContext};
|
||||
|
||||
#[cfg(feature = "wayvr")]
|
||||
use {
|
||||
@@ -34,6 +34,8 @@ pub struct AppState {
|
||||
pub hid_provider: HidWrapper,
|
||||
pub audio_provider: AudioOutput,
|
||||
|
||||
pub wgui_shared: WSharedContext,
|
||||
|
||||
pub input_state: InputState,
|
||||
pub screens: SmallVec<[ScreenMeta; 8]>,
|
||||
pub anchor: Affine3A,
|
||||
@@ -71,6 +73,8 @@ impl AppState {
|
||||
include_bytes!("res/557297.wav"),
|
||||
);
|
||||
|
||||
let wgui_shared = WSharedContext::new(gfx.clone())?;
|
||||
|
||||
Ok(Self {
|
||||
session,
|
||||
tasks,
|
||||
@@ -78,6 +82,7 @@ impl AppState {
|
||||
gfx_extras,
|
||||
hid_provider: HidWrapper::new(),
|
||||
audio_provider: AudioOutput::new(),
|
||||
wgui_shared,
|
||||
input_state: InputState::new(),
|
||||
screens: smallvec![],
|
||||
anchor: Affine3A::IDENTITY,
|
||||
|
||||
Reference in New Issue
Block a user