diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
commit | 6eb9083b1f2fec63e17dc8ef462ea89bae0854b5 (patch) | |
tree | 814f670c38040c37408db06b66c9cb24550393e9 /stockton-render/src/draw/ui/mod.rs | |
parent | 6ef351de4ba506e7f0f285569aa0e22255bb68c6 (diff) |
feat(render): ui draw pass
Diffstat (limited to 'stockton-render/src/draw/ui/mod.rs')
-rw-r--r-- | stockton-render/src/draw/ui/mod.rs | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/stockton-render/src/draw/ui/mod.rs b/stockton-render/src/draw/ui/mod.rs index 5daa117..1b52753 100644 --- a/stockton-render/src/draw/ui/mod.rs +++ b/stockton-render/src/draw/ui/mod.rs @@ -1,11 +1,52 @@ -pub mod pipeline; -pub mod render; -pub mod texture; +use crate::draw::texture::{resolver::TextureResolver, LoadableImage}; +use egui::{CtxRef, Texture}; +use std::{convert::TryInto, sync::Arc}; -pub use pipeline::UiPipeline; -pub use render::do_render; -use stockton_types::Vector2; -pub use texture::{ensure_textures, UiTextures}; +pub struct UiTextures { + ctx: CtxRef, +} -#[derive(Debug)] -pub struct UiPoint(pub Vector2, pub Vector2, pub [f32; 4]); +impl TextureResolver for UiTextures { + type Image = Arc<Texture>; + fn resolve(&mut self, tex: u32) -> Option<Self::Image> { + if tex == 0 { + Some(self.ctx.texture()) + } else { + None + } + } +} + +impl UiTextures { + pub fn new(ctx: CtxRef) -> Self { + UiTextures { ctx } + } +} + +impl LoadableImage for Arc<Texture> { + fn width(&self) -> u32 { + self.width as u32 + } + fn height(&self) -> u32 { + self.height as u32 + } + fn copy_row(&self, y: u32, ptr: *mut u8) { + let row_size = self.width(); + let pixels = &self.pixels[(y * row_size) as usize..((y + 1) * row_size) as usize]; + + for (i, x) in pixels.iter().enumerate() { + unsafe { + *ptr.offset(i as isize * 4) = 255; + *ptr.offset((i as isize * 4) + 1) = 255; + *ptr.offset((i as isize * 4) + 2) = 255; + *ptr.offset((i as isize * 4) + 3) = *x; + } + } + } + + unsafe fn copy_into(&self, ptr: *mut u8, row_size: usize) { + for y in 0..self.height() { + self.copy_row(y, ptr.offset((row_size * y as usize).try_into().unwrap())); + } + } +} |