summaryrefslogtreecommitdiff
path: root/crates/renderer/src/background.rs
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-07-26 16:54:07 -0400
committerLLLL Colonq <llll@colonq>2025-07-26 16:54:07 -0400
commit86862272e9cdb7a8358db91ec4bea3edbacf2e97 (patch)
tree5e347bc8f5190921ac74f6d1870cc7e43a5c5d2d /crates/renderer/src/background.rs
parentba1ff8e7e3ea915c6d673c05cdcdee10a9b5b9f0 (diff)
WIP
Diffstat (limited to 'crates/renderer/src/background.rs')
-rw-r--r--crates/renderer/src/background.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/crates/renderer/src/background.rs b/crates/renderer/src/background.rs
new file mode 100644
index 0000000..cf99fc9
--- /dev/null
+++ b/crates/renderer/src/background.rs
@@ -0,0 +1,62 @@
+use teleia::*;
+
+use byteorder::ReadBytesExt;
+
+use glow::HasContext;
+
+pub struct Frame<'a> {
+ tag: &'a [u8],
+ width: u32,
+ height: u32,
+ pixels: &'a [u8],
+}
+impl<'a> Frame<'a> {
+ fn read_length_prefixed(reader: &mut &'a [u8]) -> Option<&'a [u8]> {
+ let len = reader.read_u32::<byteorder::LE>().ok()? as usize;
+ log::info!("len: {}", len);
+ let (x, xs) = reader.split_at(len);
+ *reader = xs;
+ Some(x)
+ }
+ pub fn parse(reader: &mut &'a [u8]) -> Option<Self> {
+ log::info!("message: {:?}", reader);
+ let tag = Self::read_length_prefixed(reader)?;
+ log::info!("tag: {:?}", tag);
+ let width = reader.read_u32::<byteorder::LE>().ok()?;
+ log::info!("width: {:?}", width);
+ let height = reader.read_u32::<byteorder::LE>().ok()?;
+ log::info!("height: {:?}", height);
+ let pixels = *reader;
+ Some(Self { tag, width, height, pixels })
+ }
+}
+
+pub struct Backgrounds {
+ pub drawing: texture::Texture,
+}
+impl Backgrounds {
+ pub fn new(ctx: &context::Context) -> Self {
+ Self {
+ // drawing: texture::Texture::new_empty(ctx),
+ drawing: texture::Texture::new(ctx, include_bytes!("assets/textures/everest.jpg")),
+ }
+ }
+ pub fn update<'a>(&self, ctx: &context::Context, f: Frame<'a>) {
+ unsafe {
+ let err = ctx.gl.get_error();
+ self.drawing.bind(ctx);
+ ctx.gl.tex_image_2d(
+ glow::TEXTURE_2D,
+ 0,
+ glow::RGBA as i32,
+ f.width as i32,
+ f.height as i32,
+ 0,
+ glow::RGBA,
+ glow::UNSIGNED_BYTE,
+ Some(&f.pixels),
+ );
+ ctx.gl.generate_mipmap(glow::TEXTURE_2D);
+ }
+ }
+}