From 169d6f92ceeb73fb3bc60a49e8cd58061531c832 Mon Sep 17 00:00:00 2001 From: Tei Leelo Roberts Date: Sat, 19 Oct 2024 17:14:35 +0200 Subject: [PATCH] chore: expose more apis --- violet-wgpu/src/app.rs | 14 ++++++++++++- violet-wgpu/src/graphics/gpu.rs | 16 ++++++-------- violet-wgpu/src/renderer/mod.rs | 23 +++++++++++++-------- violet-wgpu/src/renderer/window_renderer.rs | 2 +- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/violet-wgpu/src/app.rs b/violet-wgpu/src/app.rs index ab2aee9..4eb9e61 100644 --- a/violet-wgpu/src/app.rs +++ b/violet-wgpu/src/app.rs @@ -167,7 +167,7 @@ impl AppBuilder { /// A running application instance of violet pub struct AppInstance { pub frame: Frame, - root: Entity, + pub root: Entity, scale_factor: f64, current_time: Instant, start_time: Instant, @@ -293,6 +293,18 @@ impl AppInstance { pub fn frame(&self) -> &Frame { &self.frame } + + pub fn root(&self) -> Entity { + self.root + } + + pub fn text_system(&self) -> &Arc> { + &self.text_system + } + + pub fn layout_changes_rx(&self) -> &flume::Receiver<(Entity, LayoutUpdateEvent)> { + &self.layout_changes_rx + } } struct WindowEventHandler { diff --git a/violet-wgpu/src/graphics/gpu.rs b/violet-wgpu/src/graphics/gpu.rs index 1bcc295..8a092f0 100644 --- a/violet-wgpu/src/graphics/gpu.rs +++ b/violet-wgpu/src/graphics/gpu.rs @@ -6,9 +6,9 @@ use winit::{dpi::PhysicalSize, window::Window}; /// Represents the Gpu and graphics state #[derive(Debug)] pub struct Gpu { - pub adapter: Adapter, - pub device: wgpu::Device, - pub queue: wgpu::Queue, + pub adapter: Arc, + pub device: Arc, + pub queue: Arc, } pub struct Surface { @@ -138,9 +138,9 @@ impl Gpu { ( Self { - adapter, - device, - queue, + adapter: Arc::new(adapter), + device: Arc::new(device), + queue: Arc::new(queue), }, Surface { surface, @@ -149,8 +149,4 @@ impl Gpu { }, ) } - - // pub fn surface_caps(&self) -> &SurfaceCapabilities { - // &self.surface_caps - // } } diff --git a/violet-wgpu/src/renderer/mod.rs b/violet-wgpu/src/renderer/mod.rs index fb21206..daa367f 100644 --- a/violet-wgpu/src/renderer/mod.rs +++ b/violet-wgpu/src/renderer/mod.rs @@ -18,8 +18,8 @@ use violet_core::{ Frame, Rect, }; use wgpu::{ - BindGroup, BindGroupLayout, BufferUsages, CommandEncoder, Operations, RenderPassDescriptor, - ShaderStages, StoreOp, TextureFormat, TextureView, + BindGroup, BindGroupLayout, BufferUsages, CommandEncoder, LoadOp, Operations, + RenderPassDescriptor, ShaderStages, StoreOp, TextureFormat, TextureView, }; use crate::{ @@ -280,6 +280,7 @@ impl MainRenderer { frame: &mut Frame, encoder: &mut CommandEncoder, target_view: &TextureView, + clear: bool, ) -> anyhow::Result<()> { puffin::profile_function!(); @@ -289,12 +290,16 @@ impl MainRenderer { view: target_view, resolve_target: None, ops: Operations { - load: wgpu::LoadOp::Clear(wgpu::Color { - r: 0.0, - g: 0.0, - b: 0.0, - a: 0.0, - }), + load: if clear { + LoadOp::Clear(wgpu::Color { + r: 0.0, + g: 0.0, + b: 0.0, + a: 0.0, + }) + } else { + LoadOp::Load + }, store: StoreOp::Store, }, })], @@ -390,7 +395,7 @@ impl MainRenderer { Ok(()) } - fn resize( + pub fn resize( &mut self, ctx: &RendererContext, physical_size: winit::dpi::PhysicalSize, diff --git a/violet-wgpu/src/renderer/window_renderer.rs b/violet-wgpu/src/renderer/window_renderer.rs index 9d46364..d2536bd 100644 --- a/violet-wgpu/src/renderer/window_renderer.rs +++ b/violet-wgpu/src/renderer/window_renderer.rs @@ -94,7 +94,7 @@ impl WindowRenderer { }); self.main_renderer - .draw(&mut self.ctx, frame, &mut encoder, &view) + .draw(&mut self.ctx, frame, &mut encoder, &view, true) .context("Failed to draw shapes")?; {