From 7eafea521f3f7d405a20a015b9e84fecac0a02c1 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Wed, 8 May 2024 03:04:50 +0200 Subject: [PATCH] kubiui integration update --- Cargo.lock | 19 ++++++++++++++++--- kubi/Cargo.toml | 5 +++-- kubi/src/hui_integration.rs | 27 ++++++++++++++------------- kubi/src/rendering.rs | 10 ++++++---- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2194bb8..1f05822 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -988,7 +988,7 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" [[package]] name = "hui" version = "0.1.0-alpha.5" -source = "git+https://github.com/griffi-gh/hui?rev=3a50d2d0dde#3a50d2d0dde7044d02860dac9ab059bd353657a2" +source = "git+https://github.com/griffi-gh/hui?rev=b6dc8f370b6#b6dc8f370b6dac971394e8cb82fdb505b529e964" dependencies = [ "derive_more", "derive_setters", @@ -1008,16 +1008,28 @@ dependencies = [ [[package]] name = "hui-derive" version = "0.1.0-alpha.5" -source = "git+https://github.com/griffi-gh/hui?rev=3a50d2d0dde#3a50d2d0dde7044d02860dac9ab059bd353657a2" +source = "git+https://github.com/griffi-gh/hui?rev=b6dc8f370b6#b6dc8f370b6dac971394e8cb82fdb505b529e964" dependencies = [ "quote", "syn 2.0.60", ] +[[package]] +name = "hui-wgpu" +version = "0.1.0-alpha.5" +source = "git+https://github.com/griffi-gh/hui?rev=b6dc8f370b6#b6dc8f370b6dac971394e8cb82fdb505b529e964" +dependencies = [ + "bytemuck", + "glam", + "hui", + "log", + "wgpu", +] + [[package]] name = "hui-winit" version = "0.1.0-alpha.5" -source = "git+https://github.com/griffi-gh/hui?rev=3a50d2d0dde#3a50d2d0dde7044d02860dac9ab059bd353657a2" +source = "git+https://github.com/griffi-gh/hui?rev=b6dc8f370b6#b6dc8f370b6dac971394e8cb82fdb505b529e964" dependencies = [ "glam", "hui", @@ -1211,6 +1223,7 @@ dependencies = [ "glam", "hashbrown 0.14.5", "hui", + "hui-wgpu", "hui-winit", "image", "kubi-logging", diff --git a/kubi/Cargo.toml b/kubi/Cargo.toml index 6542e1d..5b58b3b 100644 --- a/kubi/Cargo.toml +++ b/kubi/Cargo.toml @@ -11,8 +11,9 @@ crate-type = ["lib", "cdylib"] [dependencies] kubi-shared = { path = "../kubi-shared" } kubi-logging = { path = "../kubi-logging" } -hui = { git = "https://github.com/griffi-gh/hui", rev = "3a50d2d0dde" } -hui-winit = { git = "https://github.com/griffi-gh/hui", rev = "3a50d2d0dde", features = ["winit_30"] } +hui = { git = "https://github.com/griffi-gh/hui", rev = "b6dc8f370b6" } +hui-wgpu = { git = "https://github.com/griffi-gh/hui", rev = "b6dc8f370b6" } +hui-winit = { git = "https://github.com/griffi-gh/hui", rev = "b6dc8f370b6", features = ["winit_30"] } log = "0.4" wgpu = { version = "0.20", features = ["webgl"] } pollster = "0.3" diff --git a/kubi/src/hui_integration.rs b/kubi/src/hui_integration.rs index 95fcfae..78f0b02 100644 --- a/kubi/src/hui_integration.rs +++ b/kubi/src/hui_integration.rs @@ -1,12 +1,13 @@ use hui::UiInstance; +use hui_wgpu::WgpuUiRenderer; //use hui_glium::GliumUiRenderer; use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut}; -use crate::rendering::Renderer; +use crate::rendering::{RenderCtx, Renderer}; #[derive(Unique)] pub struct UiState { pub hui: UiInstance, - //pub renderer: GliumUiRenderer + pub renderer: WgpuUiRenderer, } pub fn kubi_ui_init( @@ -15,7 +16,7 @@ pub fn kubi_ui_init( let renderer = storages.borrow::>>().unwrap(); storages.add_unique_non_send_sync(UiState { hui: UiInstance::new(), - //renderer: GliumUiRenderer::new(&renderer.display), + renderer: WgpuUiRenderer::new(renderer.device(), renderer.surface_config().format), }); } @@ -26,21 +27,21 @@ pub fn kubi_ui_begin( } pub fn kubi_ui_end( - mut ui: NonSendSync> + mut ui: NonSendSync>, + renderer: UniqueView, ) { let ui: &mut UiState = &mut ui; - let UiState { hui, /*renderer,*/ .. } = ui; + let UiState { hui, renderer: ui_renderer } = ui; hui.end(); - //renderer.update(hui); + ui_renderer.update(hui, renderer.queue(), renderer.device(), renderer.size_vec2()); } -// pub fn kubi_ui_draw( -// ui: NonSendSync>, -// mut target: NonSendSync>, -// size: UniqueView -// ) { -// ui.renderer.draw(&mut target.0, size.0.as_vec2()); -// } +pub fn kubi_ui_draw( + ctx: &mut RenderCtx, + ui: NonSendSync>, +) { + ui.renderer.draw(ctx.encoder, ctx.surface_view); +} pub fn hui_process_winit_events( event: &winit::event::Event<()>, diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index 688aa9d..f3342ab 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -1,7 +1,7 @@ -use shipyard::{AllStoragesViewMut, IntoIter, IntoWorkload, SystemModificator, Unique, UniqueView, UniqueViewMut, View, Workload, WorkloadModificator}; +use shipyard::{AllStoragesViewMut, IntoIter, IntoWorkload, SystemModificator, Unique, UniqueView, UniqueViewMut, View, Workload}; use winit::dpi::PhysicalSize; use glam::Vec3; -use crate::{events::WindowResizedEvent, state::is_ingame}; +use crate::{events::WindowResizedEvent, hui_integration::kubi_ui_draw, state::is_ingame}; mod renderer; mod primitives; @@ -24,7 +24,7 @@ pub struct BufferPair { pub struct BackgroundColor(pub Vec3); pub struct RenderCtx<'a> { - pub renderer: &'a Renderer, + //pub renderer: &'a Renderer, pub encoder: &'a mut wgpu::CommandEncoder, pub surface_view: &'a wgpu::TextureView, } @@ -65,7 +65,7 @@ pub fn render_master(storages: AllStoragesViewMut) { let surface_view = surface_texture.texture.create_view(&wgpu::TextureViewDescriptor::default()); let mut data = RenderCtx { - renderer: &renderer, + //renderer: &renderer, encoder: &mut encoder, surface_view: &surface_view, }; @@ -76,6 +76,8 @@ pub fn render_master(storages: AllStoragesViewMut) { storages.run_with_data(selection_box::draw_selection_box, &mut data); } + storages.run_with_data(kubi_ui_draw, &mut data); + renderer.queue().submit([encoder.finish()]); surface_texture.present(); }