Просмотр исходного кода

wallet: defer allocs in async code. we use an internal hashmap and generate random IDs rather than waiting for GL to wake up and provide us with them.

darkfi 1 год назад
Родитель
Сommit
d3b0f38ed7

+ 124 - 68
bin/darkwallet/src/gfx/mod.rs

@@ -19,10 +19,10 @@
 use darkfi_serial::{async_trait, SerialDecodable, SerialEncodable};
 use darkfi_serial::{async_trait, SerialDecodable, SerialEncodable};
 use log::debug;
 use log::debug;
 use miniquad::{
 use miniquad::{
-    conf, window, Backend, Bindings, BlendFactor, BlendState, BlendValue, BufferId, BufferLayout,
+    conf, window, Backend, Bindings, BlendFactor, BlendState, BlendValue, BufferLayout,
     BufferSource, BufferType, BufferUsage, Equation, EventHandler, KeyCode, KeyMods, MouseButton,
     BufferSource, BufferType, BufferUsage, Equation, EventHandler, KeyCode, KeyMods, MouseButton,
-    PassAction, Pipeline, PipelineParams, RenderingBackend, ShaderMeta, ShaderSource, TextureId,
-    TouchPhase, UniformDesc, UniformType, VertexAttribute, VertexFormat,
+    PassAction, Pipeline, PipelineParams, RenderingBackend, ShaderMeta, ShaderSource, TouchPhase,
+    UniformDesc, UniformType, VertexAttribute, VertexFormat,
 };
 };
 use std::{
 use std::{
     collections::HashMap,
     collections::HashMap,
@@ -38,6 +38,9 @@ use crate::{
     pubsub::{Publisher, PublisherPtr, Subscription, SubscriptionId},
     pubsub::{Publisher, PublisherPtr, Subscription, SubscriptionId},
 };
 };
 
 
+pub type GfxTextureId = u32;
+pub type GfxBufferId = u32;
+
 // This is very noisy so suppress output by default
 // This is very noisy so suppress output by default
 const DEBUG_RENDER: bool = false;
 const DEBUG_RENDER: bool = false;
 
 
@@ -188,88 +191,141 @@ impl RenderApi {
         Arc::new(Self { method_req })
         Arc::new(Self { method_req })
     }
     }
 
 
-    pub async fn new_texture(&self, width: u16, height: u16, data: Vec<u8>) -> Result<TextureId> {
-        let (sendr, recvr) = async_channel::bounded(1);
-
-        let method = GraphicsMethod::NewTexture((width, height, data, sendr));
+    pub fn new_texture(&self, width: u16, height: u16, data: Vec<u8>) -> GfxTextureId {
+        let gfx_texture_id = rand::random();
 
 
-        self.method_req.send(method).map_err(|_| Error::GfxWindowClosed)?;
+        let method = GraphicsMethod::NewTexture((width, height, data, gfx_texture_id));
+        let _ = self.method_req.send(method);
 
 
-        let texture_id = recvr.recv().await.map_err(|_| Error::GfxWindowClosed)?;
-        Ok(texture_id)
+        gfx_texture_id
     }
     }
 
 
-    pub fn delete_texture(&self, texture: TextureId) {
+    pub fn delete_texture(&self, texture: GfxTextureId) {
         let method = GraphicsMethod::DeleteTexture(texture);
         let method = GraphicsMethod::DeleteTexture(texture);
-
-        // Ignore any error
         let _ = self.method_req.send(method);
         let _ = self.method_req.send(method);
     }
     }
 
 
-    pub async fn new_vertex_buffer(&self, verts: Vec<Vertex>) -> Result<BufferId> {
-        let (sendr, recvr) = async_channel::bounded(1);
-
-        let method = GraphicsMethod::NewVertexBuffer((verts, sendr));
+    pub fn new_vertex_buffer(&self, verts: Vec<Vertex>) -> GfxBufferId {
+        let gfx_buffer_id = rand::random();
 
 
-        self.method_req.send(method).map_err(|_| Error::GfxWindowClosed)?;
+        let method = GraphicsMethod::NewVertexBuffer((verts, gfx_buffer_id));
+        let _ = self.method_req.send(method);
 
 
-        let buffer = recvr.recv().await.map_err(|_| Error::GfxWindowClosed)?;
-        Ok(buffer)
+        gfx_buffer_id
     }
     }
 
 
-    pub async fn new_index_buffer(&self, indices: Vec<u16>) -> Result<BufferId> {
-        let (sendr, recvr) = async_channel::bounded(1);
-
-        let method = GraphicsMethod::NewIndexBuffer((indices, sendr));
+    pub fn new_index_buffer(&self, indices: Vec<u16>) -> GfxBufferId {
+        let gfx_buffer_id = rand::random();
 
 
-        self.method_req.send(method).map_err(|_| Error::GfxWindowClosed)?;
+        let method = GraphicsMethod::NewIndexBuffer((indices, gfx_buffer_id));
+        let _ = self.method_req.send(method);
 
 
-        let buffer = recvr.recv().await.map_err(|_| Error::GfxWindowClosed)?;
-        Ok(buffer)
+        gfx_buffer_id
     }
     }
 
 
-    pub fn delete_buffer(&self, buffer: BufferId) {
+    pub fn delete_buffer(&self, buffer: GfxBufferId) {
         let method = GraphicsMethod::DeleteBuffer(buffer);
         let method = GraphicsMethod::DeleteBuffer(buffer);
-
-        // Ignore any error
         let _ = self.method_req.send(method);
         let _ = self.method_req.send(method);
     }
     }
 
 
-    pub async fn replace_draw_calls(&self, dcs: Vec<(u64, DrawCall)>) {
+    pub fn replace_draw_calls(&self, dcs: Vec<(u64, GfxDrawCall)>) {
         let method = GraphicsMethod::ReplaceDrawCalls(dcs);
         let method = GraphicsMethod::ReplaceDrawCalls(dcs);
-
-        // Ignore any error
         let _ = self.method_req.send(method);
         let _ = self.method_req.send(method);
     }
     }
 }
 }
 
 
 #[derive(Clone, Debug)]
 #[derive(Clone, Debug)]
-pub struct DrawMesh {
-    pub vertex_buffer: BufferId,
-    pub index_buffer: BufferId,
-    pub texture: Option<TextureId>,
+pub struct GfxDrawMesh {
+    pub vertex_buffer: GfxBufferId,
+    pub index_buffer: GfxBufferId,
+    pub texture: Option<GfxTextureId>,
     pub num_elements: i32,
     pub num_elements: i32,
 }
 }
 
 
+impl GfxDrawMesh {
+    fn compile(
+        self,
+        textures: &HashMap<GfxTextureId, miniquad::TextureId>,
+        buffers: &HashMap<GfxBufferId, miniquad::BufferId>,
+    ) -> DrawMesh {
+        DrawMesh {
+            vertex_buffer: buffers[&self.vertex_buffer],
+            index_buffer: buffers[&self.index_buffer],
+            texture: self.texture.map(|t| textures[&t]),
+            num_elements: self.num_elements,
+        }
+    }
+}
+
 #[derive(Debug, Clone)]
 #[derive(Debug, Clone)]
-pub enum DrawInstruction {
+pub enum GfxDrawInstruction {
     ApplyViewport(Rectangle),
     ApplyViewport(Rectangle),
     ApplyMatrix(glam::Mat4),
     ApplyMatrix(glam::Mat4),
-    Draw(DrawMesh),
+    Draw(GfxDrawMesh),
+}
+
+impl GfxDrawInstruction {
+    fn compile(
+        self,
+        textures: &HashMap<GfxTextureId, miniquad::TextureId>,
+        buffers: &HashMap<GfxBufferId, miniquad::BufferId>,
+    ) -> DrawInstruction {
+        match self {
+            Self::ApplyViewport(rect) => DrawInstruction::ApplyViewport(rect),
+            Self::ApplyMatrix(mat) => DrawInstruction::ApplyMatrix(mat),
+            Self::Draw(mesh) => DrawInstruction::Draw(mesh.compile(textures, buffers)),
+        }
+    }
 }
 }
 
 
 #[derive(Debug)]
 #[derive(Debug)]
-pub struct DrawCall {
-    pub instrs: Vec<DrawInstruction>,
+pub struct GfxDrawCall {
+    pub instrs: Vec<GfxDrawInstruction>,
     pub dcs: Vec<u64>,
     pub dcs: Vec<u64>,
     pub z_index: u32,
     pub z_index: u32,
 }
 }
 
 
+impl GfxDrawCall {
+    fn compile(
+        self,
+        textures: &HashMap<GfxTextureId, miniquad::TextureId>,
+        buffers: &HashMap<GfxBufferId, miniquad::BufferId>,
+    ) -> DrawCall {
+        DrawCall {
+            instrs: self.instrs.into_iter().map(|i| i.compile(textures, buffers)).collect(),
+            dcs: self.dcs,
+            z_index: self.z_index,
+        }
+    }
+}
+
+#[derive(Clone, Debug)]
+struct DrawMesh {
+    vertex_buffer: miniquad::BufferId,
+    index_buffer: miniquad::BufferId,
+    texture: Option<miniquad::TextureId>,
+    num_elements: i32,
+}
+
+#[derive(Debug, Clone)]
+enum DrawInstruction {
+    ApplyViewport(Rectangle),
+    ApplyMatrix(glam::Mat4),
+    Draw(DrawMesh),
+}
+
+#[derive(Debug)]
+struct DrawCall {
+    instrs: Vec<DrawInstruction>,
+    dcs: Vec<u64>,
+    z_index: u32,
+}
+
 struct RenderContext<'a> {
 struct RenderContext<'a> {
     ctx: &'a mut Box<dyn RenderingBackend>,
     ctx: &'a mut Box<dyn RenderingBackend>,
     draw_calls: &'a HashMap<u64, DrawCall>,
     draw_calls: &'a HashMap<u64, DrawCall>,
     uniforms_data: [u8; 128],
     uniforms_data: [u8; 128],
-    white_texture: TextureId,
+    white_texture: miniquad::TextureId,
 }
 }
 
 
 impl<'a> RenderContext<'a> {
 impl<'a> RenderContext<'a> {
@@ -365,12 +421,12 @@ impl<'a> RenderContext<'a> {
 
 
 #[derive(Debug)]
 #[derive(Debug)]
 pub enum GraphicsMethod {
 pub enum GraphicsMethod {
-    NewTexture((u16, u16, Vec<u8>, async_channel::Sender<TextureId>)),
-    DeleteTexture(TextureId),
-    NewVertexBuffer((Vec<Vertex>, async_channel::Sender<BufferId>)),
-    NewIndexBuffer((Vec<u16>, async_channel::Sender<BufferId>)),
-    DeleteBuffer(BufferId),
-    ReplaceDrawCalls(Vec<(u64, DrawCall)>),
+    NewTexture((u16, u16, Vec<u8>, GfxTextureId)),
+    DeleteTexture(GfxTextureId),
+    NewVertexBuffer((Vec<Vertex>, GfxBufferId)),
+    NewIndexBuffer((Vec<u16>, GfxBufferId)),
+    DeleteBuffer(GfxBufferId),
+    ReplaceDrawCalls(Vec<(u64, GfxDrawCall)>),
 }
 }
 
 
 pub type GraphicsEventPublisherPtr = Arc<GraphicsEventPublisher>;
 pub type GraphicsEventPublisherPtr = Arc<GraphicsEventPublisher>;
@@ -633,10 +689,13 @@ struct Stage {
 
 
     ctx: Box<dyn RenderingBackend>,
     ctx: Box<dyn RenderingBackend>,
     pipeline: Pipeline,
     pipeline: Pipeline,
-    white_texture: TextureId,
+    white_texture: miniquad::TextureId,
     draw_calls: HashMap<u64, DrawCall>,
     draw_calls: HashMap<u64, DrawCall>,
     last_draw_time: Option<Instant>,
     last_draw_time: Option<Instant>,
 
 
+    textures: HashMap<GfxTextureId, miniquad::TextureId>,
+    buffers: HashMap<GfxBufferId, miniquad::BufferId>,
+
     method_rep: mpsc::Receiver<GraphicsMethod>,
     method_rep: mpsc::Receiver<GraphicsMethod>,
     event_pub: GraphicsEventPublisherPtr,
     event_pub: GraphicsEventPublisherPtr,
 }
 }
@@ -705,6 +764,8 @@ impl Stage {
             white_texture,
             white_texture,
             draw_calls: HashMap::from([(0, DrawCall { instrs: vec![], dcs: vec![], z_index: 0 })]),
             draw_calls: HashMap::from([(0, DrawCall { instrs: vec![], dcs: vec![], z_index: 0 })]),
             last_draw_time: None,
             last_draw_time: None,
+            textures: HashMap::new(),
+            buffers: HashMap::new(),
             method_rep,
             method_rep,
             event_pub,
             event_pub,
         }
         }
@@ -713,8 +774,8 @@ impl Stage {
     fn process_method(&mut self, method: GraphicsMethod) {
     fn process_method(&mut self, method: GraphicsMethod) {
         //debug!(target: "gfx", "Received method: {:?}", method);
         //debug!(target: "gfx", "Received method: {:?}", method);
         match method {
         match method {
-            GraphicsMethod::NewTexture((width, height, data, sendr)) => {
-                self.method_new_texture(width, height, data, sendr)
+            GraphicsMethod::NewTexture((width, height, data, gfx_texture_id)) => {
+                self.method_new_texture(width, height, data, gfx_texture_id)
             }
             }
             GraphicsMethod::DeleteTexture(texture) => self.method_delete_texture(texture),
             GraphicsMethod::DeleteTexture(texture) => self.method_delete_texture(texture),
             GraphicsMethod::NewVertexBuffer((verts, sendr)) => {
             GraphicsMethod::NewVertexBuffer((verts, sendr)) => {
@@ -733,7 +794,7 @@ impl Stage {
         width: u16,
         width: u16,
         height: u16,
         height: u16,
         data: Vec<u8>,
         data: Vec<u8>,
-        sendr: async_channel::Sender<TextureId>,
+        gfx_texture_id: GfxTextureId,
     ) {
     ) {
         let texture = self.ctx.new_texture_from_rgba8(width, height, &data);
         let texture = self.ctx.new_texture_from_rgba8(width, height, &data);
         //debug!(target: "gfx", "Invoked method: new_texture({}, {}, ...) -> {:?}",
         //debug!(target: "gfx", "Invoked method: new_texture({}, {}, ...) -> {:?}",
@@ -741,45 +802,40 @@ impl Stage {
         //debug!(target: "gfx", "Invoked method: new_texture({}, {}, ...) -> {:?}\n{}",
         //debug!(target: "gfx", "Invoked method: new_texture({}, {}, ...) -> {:?}\n{}",
         //       width, height, texture,
         //       width, height, texture,
         //       ansi_texture(width as usize, height as usize, &data));
         //       ansi_texture(width as usize, height as usize, &data));
-        sendr.try_send(texture).unwrap();
+        self.textures.insert(gfx_texture_id, texture);
     }
     }
-    fn method_delete_texture(&mut self, texture: TextureId) {
+    fn method_delete_texture(&mut self, gfx_texture_id: GfxTextureId) {
         //debug!(target: "gfx", "Invoked method: delete_texture({:?})", texture);
         //debug!(target: "gfx", "Invoked method: delete_texture({:?})", texture);
+        let texture = self.textures.remove(&gfx_texture_id).expect("couldn't find gfx_texture_id");
         self.ctx.delete_texture(texture);
         self.ctx.delete_texture(texture);
     }
     }
-    fn method_new_vertex_buffer(
-        &mut self,
-        verts: Vec<Vertex>,
-        sendr: async_channel::Sender<BufferId>,
-    ) {
+    fn method_new_vertex_buffer(&mut self, verts: Vec<Vertex>, gfx_buffer_id: GfxBufferId) {
         let buffer = self.ctx.new_buffer(
         let buffer = self.ctx.new_buffer(
             BufferType::VertexBuffer,
             BufferType::VertexBuffer,
             BufferUsage::Immutable,
             BufferUsage::Immutable,
             BufferSource::slice(&verts),
             BufferSource::slice(&verts),
         );
         );
         //debug!(target: "gfx", "Invoked method: new_vertex_buffer({:?}) -> {:?}", verts, buffer);
         //debug!(target: "gfx", "Invoked method: new_vertex_buffer({:?}) -> {:?}", verts, buffer);
-        sendr.try_send(buffer).unwrap();
+        self.buffers.insert(gfx_buffer_id, buffer);
     }
     }
-    fn method_new_index_buffer(
-        &mut self,
-        indices: Vec<u16>,
-        sendr: async_channel::Sender<BufferId>,
-    ) {
+    fn method_new_index_buffer(&mut self, indices: Vec<u16>, gfx_buffer_id: GfxBufferId) {
         let buffer = self.ctx.new_buffer(
         let buffer = self.ctx.new_buffer(
             BufferType::IndexBuffer,
             BufferType::IndexBuffer,
             BufferUsage::Immutable,
             BufferUsage::Immutable,
             BufferSource::slice(&indices),
             BufferSource::slice(&indices),
         );
         );
         //debug!(target: "gfx", "Invoked method: new_index_buffer({:?}) -> {:?}", indices, buffer);
         //debug!(target: "gfx", "Invoked method: new_index_buffer({:?}) -> {:?}", indices, buffer);
-        sendr.try_send(buffer).unwrap();
+        self.buffers.insert(gfx_buffer_id, buffer);
     }
     }
-    fn method_delete_buffer(&mut self, buffer: BufferId) {
+    fn method_delete_buffer(&mut self, gfx_buffer_id: GfxBufferId) {
         //debug!(target: "gfx", "Invoked method: delete_buffer({:?})", buffer);
         //debug!(target: "gfx", "Invoked method: delete_buffer({:?})", buffer);
+        let buffer = self.buffers.remove(&gfx_buffer_id).expect("couldn't find gfx_buffer_id");
         self.ctx.delete_buffer(buffer);
         self.ctx.delete_buffer(buffer);
     }
     }
-    fn method_replace_draw_calls(&mut self, dcs: Vec<(u64, DrawCall)>) {
+    fn method_replace_draw_calls(&mut self, dcs: Vec<(u64, GfxDrawCall)>) {
         //debug!(target: "gfx", "Invoked method: replace_draw_calls({:?})", dcs);
         //debug!(target: "gfx", "Invoked method: replace_draw_calls({:?})", dcs);
         for (key, val) in dcs {
         for (key, val) in dcs {
+            let val = val.compile(&self.textures, &self.buffers);
             self.draw_calls.insert(key, val);
             self.draw_calls.insert(key, val);
         }
         }
     }
     }

+ 11 - 12
bin/darkwallet/src/mesh.rs

@@ -18,9 +18,8 @@
 
 
 use crate::{
 use crate::{
     error::Result,
     error::Result,
-    gfx::{DrawMesh, Rectangle, RenderApi, Vertex},
+    gfx::{GfxBufferId, GfxDrawMesh, GfxTextureId, Rectangle, RenderApi, Vertex},
 };
 };
-use miniquad::{BufferId, TextureId};
 
 
 pub type Color = [f32; 4];
 pub type Color = [f32; 4];
 
 
@@ -41,15 +40,15 @@ pub const COLOR_GREY: Color = [0.5, 0.5, 0.5, 1.];
 
 
 #[derive(Clone)]
 #[derive(Clone)]
 pub struct MeshInfo {
 pub struct MeshInfo {
-    pub vertex_buffer: BufferId,
-    pub index_buffer: BufferId,
+    pub vertex_buffer: GfxBufferId,
+    pub index_buffer: GfxBufferId,
     pub num_elements: i32,
     pub num_elements: i32,
 }
 }
 
 
 impl MeshInfo {
 impl MeshInfo {
     /// Convenience method
     /// Convenience method
-    pub fn draw_with_texture(self, texture: TextureId) -> DrawMesh {
-        DrawMesh {
+    pub fn draw_with_texture(self, texture: GfxTextureId) -> GfxDrawMesh {
+        GfxDrawMesh {
             vertex_buffer: self.vertex_buffer,
             vertex_buffer: self.vertex_buffer,
             index_buffer: self.index_buffer,
             index_buffer: self.index_buffer,
             texture: Some(texture),
             texture: Some(texture),
@@ -57,8 +56,8 @@ impl MeshInfo {
         }
         }
     }
     }
     /// Convenience method
     /// Convenience method
-    pub fn draw_untextured(self) -> DrawMesh {
-        DrawMesh {
+    pub fn draw_untextured(self) -> GfxDrawMesh {
+        GfxDrawMesh {
             vertex_buffer: self.vertex_buffer,
             vertex_buffer: self.vertex_buffer,
             index_buffer: self.index_buffer,
             index_buffer: self.index_buffer,
             texture: None,
             texture: None,
@@ -158,14 +157,14 @@ impl MeshBuilder {
         self.draw_filled_box(&Rectangle::new(x1, y2 - thickness, dist_x, thickness), color);
         self.draw_filled_box(&Rectangle::new(x1, y2 - thickness, dist_x, thickness), color);
     }
     }
 
 
-    pub async fn alloc(self, render_api: &RenderApi) -> Result<MeshInfo> {
+    pub fn alloc(self, render_api: &RenderApi) -> MeshInfo {
         //debug!(target: "mesh", "allocating {} verts:", self.verts.len());
         //debug!(target: "mesh", "allocating {} verts:", self.verts.len());
         //for vert in &self.verts {
         //for vert in &self.verts {
         //    debug!(target: "mesh", "  {:?}", vert);
         //    debug!(target: "mesh", "  {:?}", vert);
         //}
         //}
         let num_elements = self.indices.len() as i32;
         let num_elements = self.indices.len() as i32;
-        let vertex_buffer = render_api.new_vertex_buffer(self.verts).await?;
-        let index_buffer = render_api.new_index_buffer(self.indices).await?;
-        Ok(MeshInfo { vertex_buffer, index_buffer, num_elements })
+        let vertex_buffer = render_api.new_vertex_buffer(self.verts);
+        let index_buffer = render_api.new_index_buffer(self.indices);
+        MeshInfo { vertex_buffer, index_buffer, num_elements }
     }
     }
 }
 }

+ 1 - 2
bin/darkwallet/src/ringbuf.rs

@@ -20,7 +20,7 @@
 pub struct RingBuffer<T, const N: usize> {
 pub struct RingBuffer<T, const N: usize> {
     vals: [Option<T>; N],
     vals: [Option<T>; N],
     head: i64,
     head: i64,
-    tail: i64
+    tail: i64,
 }
 }
 
 
 impl<T, const N: usize> RingBuffer<T, N> {
 impl<T, const N: usize> RingBuffer<T, N> {
@@ -59,4 +59,3 @@ impl<T, const N: usize> RingBuffer<T, N> {
         Some(self.vals[self.tail as usize].as_ref().unwrap())
         Some(self.vals[self.tail as usize].as_ref().unwrap())
     }
     }
 }
 }
-

+ 8 - 15
bin/darkwallet/src/text/atlas.rs

@@ -1,25 +1,19 @@
-use miniquad::TextureId;
-
+use super::{Glyph, Sprite, SpritePtr};
 use crate::{
 use crate::{
     error::Result,
     error::Result,
-    gfx::{Rectangle, RenderApi},
+    gfx::{GfxTextureId, Rectangle, RenderApi},
 };
 };
 
 
-use super::{Glyph, Sprite, SpritePtr};
-
 /// Prevents render artifacts from aliasing.
 /// Prevents render artifacts from aliasing.
 /// Even with aliasing turned off, some bleed still appears possibly
 /// Even with aliasing turned off, some bleed still appears possibly
 /// due to UV coord calcs. Adding a gap perfectly fixes this.
 /// due to UV coord calcs. Adding a gap perfectly fixes this.
 const ATLAS_GAP: usize = 2;
 const ATLAS_GAP: usize = 2;
 
 
 /// Convenience wrapper fn. Use if rendering a single line of glyphs.
 /// Convenience wrapper fn. Use if rendering a single line of glyphs.
-pub async fn make_texture_atlas(
-    render_api: &RenderApi,
-    glyphs: &Vec<Glyph>,
-) -> Result<RenderedAtlas> {
+pub fn make_texture_atlas(render_api: &RenderApi, glyphs: &Vec<Glyph>) -> RenderedAtlas {
     let mut atlas = Atlas::new(render_api);
     let mut atlas = Atlas::new(render_api);
     atlas.push(&glyphs);
     atlas.push(&glyphs);
-    atlas.make().await
+    atlas.make()
 }
 }
 
 
 /// Responsible for aggregating glyphs, and then producing a single software
 /// Responsible for aggregating glyphs, and then producing a single software
@@ -135,7 +129,7 @@ impl<'a> Atlas<'a> {
     /// Each glyph is given a sub-rect within the texture, accessible by calling
     /// Each glyph is given a sub-rect within the texture, accessible by calling
     /// `rendered_atlas.fetch_uv(my_glyph_id)`.
     /// `rendered_atlas.fetch_uv(my_glyph_id)`.
     /// The texture ID is a struct member: `rendered_atlas.texture_id`.
     /// The texture ID is a struct member: `rendered_atlas.texture_id`.
-    pub async fn make(self) -> Result<RenderedAtlas> {
+    pub fn make(self) -> RenderedAtlas {
         //if self.glyph_ids.is_empty() {
         //if self.glyph_ids.is_empty() {
         //    return Err(Error::AtlasIsEmpty);
         //    return Err(Error::AtlasIsEmpty);
         //}
         //}
@@ -144,13 +138,12 @@ impl<'a> Atlas<'a> {
         assert_eq!(self.glyph_ids.len(), self.x_pos.len());
         assert_eq!(self.glyph_ids.len(), self.x_pos.len());
 
 
         let atlas = self.render();
         let atlas = self.render();
-        let texture_id =
-            self.render_api.new_texture(self.width as u16, self.height as u16, atlas).await?;
+        let texture_id = self.render_api.new_texture(self.width as u16, self.height as u16, atlas);
 
 
         let uv_rects = self.compute_uvs();
         let uv_rects = self.compute_uvs();
         let glyph_ids = self.glyph_ids;
         let glyph_ids = self.glyph_ids;
 
 
-        Ok(RenderedAtlas { glyph_ids, uv_rects, texture_id })
+        RenderedAtlas { glyph_ids, uv_rects, texture_id }
     }
     }
 }
 }
 
 
@@ -180,7 +173,7 @@ pub struct RenderedAtlas {
     /// UV rectangle within the texture.
     /// UV rectangle within the texture.
     uv_rects: Vec<Rectangle>,
     uv_rects: Vec<Rectangle>,
     /// Allocated atlas texture. Must be manually deallocated by the user.
     /// Allocated atlas texture. Must be manually deallocated by the user.
-    pub texture_id: TextureId,
+    pub texture_id: GfxTextureId,
 }
 }
 
 
 impl RenderedAtlas {
 impl RenderedAtlas {

+ 11 - 10
bin/darkwallet/src/ui/chatview/mod.rs

@@ -40,7 +40,7 @@ use page::{FreedData, MessageBuffer};
 
 
 use crate::{
 use crate::{
     gfx::{
     gfx::{
-        DrawCall, DrawInstruction, DrawMesh, GraphicsEventPublisherPtr, Point, Rectangle,
+        GfxDrawCall, GfxDrawInstruction, GfxDrawMesh, GraphicsEventPublisherPtr, Point, Rectangle,
         RenderApi, RenderApiPtr,
         RenderApi, RenderApiPtr,
     },
     },
     mesh::{Color, MeshBuilder, COLOR_BLUE, COLOR_GREEN},
     mesh::{Color, MeshBuilder, COLOR_BLUE, COLOR_GREEN},
@@ -498,7 +498,8 @@ impl ChatView {
 
 
                     let start_elapsed = touch_info.start_instant.elapsed().as_millis_f32();
                     let start_elapsed = touch_info.start_instant.elapsed().as_millis_f32();
 
 
-                    let last_sample = touch_info.samples.head().unwrap().0.elapsed().as_millis_f32();
+                    let last_sample =
+                        touch_info.samples.head().unwrap().0.elapsed().as_millis_f32();
                     // Sample every 40ms
                     // Sample every 40ms
                     // Average small touch time is 80ms, sometimes 40ms
                     // Average small touch time is 80ms, sometimes 40ms
                     // A longer sample time means a more accurate reading for the exit velocity.
                     // A longer sample time means a more accurate reading for the exit velocity.
@@ -781,7 +782,7 @@ impl ChatView {
         &self,
         &self,
         msgbuf: &mut MessageBuffer,
         msgbuf: &mut MessageBuffer,
         rect: &Rectangle,
         rect: &Rectangle,
-    ) -> (Vec<DrawInstruction>, FreedData) {
+    ) -> (Vec<GfxDrawInstruction>, FreedData) {
         let scroll = self.scroll.get();
         let scroll = self.scroll.get();
 
 
         let total_height = msgbuf.calc_total_height().await;
         let total_height = msgbuf.calc_total_height().await;
@@ -808,9 +809,9 @@ impl ChatView {
             let model = glam::Mat4::from_translation(glam::Vec3::new(off_x, off_y, 0.)) *
             let model = glam::Mat4::from_translation(glam::Vec3::new(off_x, off_y, 0.)) *
                 glam::Mat4::from_scale(glam::Vec3::new(scale_x, scale_y, 1.));
                 glam::Mat4::from_scale(glam::Vec3::new(scale_x, scale_y, 1.));
 
 
-            instrs.push(DrawInstruction::ApplyMatrix(model));
+            instrs.push(GfxDrawInstruction::ApplyMatrix(model));
 
 
-            instrs.push(DrawInstruction::Draw(mesh));
+            instrs.push(GfxDrawInstruction::Draw(mesh));
         }
         }
 
 
         let freed = std::mem::take(&mut msgbuf.freed);
         let freed = std::mem::take(&mut msgbuf.freed);
@@ -839,14 +840,14 @@ impl ChatView {
         let (mut mesh_instrs, freed) = self.get_meshes(&mut msgbuf, &rect).await;
         let (mut mesh_instrs, freed) = self.get_meshes(&mut msgbuf, &rect).await;
         drop(msgbuf);
         drop(msgbuf);
 
 
-        let mut instrs = vec![DrawInstruction::ApplyViewport(rect)];
+        let mut instrs = vec![GfxDrawInstruction::ApplyViewport(rect)];
         instrs.append(&mut mesh_instrs);
         instrs.append(&mut mesh_instrs);
 
 
         Some(DrawUpdate {
         Some(DrawUpdate {
             key: self.dc_key,
             key: self.dc_key,
             draw_calls: vec![(
             draw_calls: vec![(
                 self.dc_key,
                 self.dc_key,
-                DrawCall { instrs, dcs: vec![], z_index: self.z_index.get() },
+                GfxDrawCall { instrs, dcs: vec![], z_index: self.z_index.get() },
             )],
             )],
             freed_textures: freed.textures,
             freed_textures: freed.textures,
             freed_buffers: freed.buffers,
             freed_buffers: freed.buffers,
@@ -858,13 +859,13 @@ impl ChatView {
 
 
         let (mut mesh_instrs, freed) = self.get_meshes(msgbuf, &rect).await;
         let (mut mesh_instrs, freed) = self.get_meshes(msgbuf, &rect).await;
 
 
-        let mut instrs = vec![DrawInstruction::ApplyViewport(rect)];
+        let mut instrs = vec![GfxDrawInstruction::ApplyViewport(rect)];
         instrs.append(&mut mesh_instrs);
         instrs.append(&mut mesh_instrs);
 
 
         let draw_calls =
         let draw_calls =
-            vec![(self.dc_key, DrawCall { instrs, dcs: vec![], z_index: self.z_index.get() })];
+            vec![(self.dc_key, GfxDrawCall { instrs, dcs: vec![], z_index: self.z_index.get() })];
 
 
-        self.render_api.replace_draw_calls(draw_calls).await;
+        self.render_api.replace_draw_calls(draw_calls);
 
 
         for buffer_id in freed.buffers {
         for buffer_id in freed.buffers {
             self.render_api.delete_buffer(buffer_id);
             self.render_api.delete_buffer(buffer_id);

+ 52 - 61
bin/darkwallet/src/ui/chatview/page.rs

@@ -20,7 +20,6 @@ use async_gen::{gen as async_gen, AsyncIter};
 use async_lock::Mutex as AsyncMutex;
 use async_lock::Mutex as AsyncMutex;
 use chrono::{Local, NaiveDate, TimeZone};
 use chrono::{Local, NaiveDate, TimeZone};
 use futures::stream::{Stream, StreamExt};
 use futures::stream::{Stream, StreamExt};
-use miniquad::{BufferId, TextureId};
 use std::{
 use std::{
     collections::HashMap,
     collections::HashMap,
     hash::{DefaultHasher, Hash, Hasher},
     hash::{DefaultHasher, Hash, Hasher},
@@ -31,8 +30,8 @@ use std::{
 
 
 use crate::{
 use crate::{
     gfx::{
     gfx::{
-        DrawCall, DrawInstruction, DrawMesh, GraphicsEventPublisherPtr, Point, Rectangle,
-        RenderApi, RenderApiPtr,
+        GfxBufferId, GfxDrawCall, GfxDrawInstruction, GfxDrawMesh, GfxTextureId,
+        GraphicsEventPublisherPtr, Point, Rectangle, RenderApi, RenderApiPtr,
     },
     },
     mesh::{Color, MeshBuilder, COLOR_BLUE, COLOR_GREEN, COLOR_PINK},
     mesh::{Color, MeshBuilder, COLOR_BLUE, COLOR_GREEN, COLOR_PINK},
     prop::{PropertyBool, PropertyColor, PropertyFloat32, PropertyPtr, PropertyUint32, Role},
     prop::{PropertyBool, PropertyColor, PropertyFloat32, PropertyPtr, PropertyUint32, Role},
@@ -66,7 +65,7 @@ pub(super) struct PrivMessage {
     wrapped_lines: Vec<Vec<Glyph>>,
     wrapped_lines: Vec<Vec<Glyph>>,
 
 
     atlas: text::RenderedAtlas,
     atlas: text::RenderedAtlas,
-    mesh_cache: Option<DrawMesh>,
+    mesh_cache: Option<GfxDrawMesh>,
 }
 }
 
 
 impl PrivMessage {
 impl PrivMessage {
@@ -91,7 +90,7 @@ impl PrivMessage {
 
 
         let mut atlas = text::Atlas::new(render_api);
         let mut atlas = text::Atlas::new(render_api);
         atlas.push(&unwrapped_glyphs);
         atlas.push(&unwrapped_glyphs);
-        let atlas = atlas.make().await.expect("unable to make atlas");
+        let atlas = atlas.make();
 
 
         let mut self_ = Self {
         let mut self_ = Self {
             font_size,
             font_size,
@@ -112,7 +111,7 @@ impl PrivMessage {
         self.wrapped_lines.len() as f32 * line_height
         self.wrapped_lines.len() as f32 * line_height
     }
     }
 
 
-    async fn gen_mesh(
+    fn gen_mesh(
         &mut self,
         &mut self,
         clip: &Rectangle,
         clip: &Rectangle,
         line_height: f32,
         line_height: f32,
@@ -122,7 +121,7 @@ impl PrivMessage {
         text_color: Color,
         text_color: Color,
         debug_render: bool,
         debug_render: bool,
         render_api: &RenderApi,
         render_api: &RenderApi,
-    ) -> DrawMesh {
+    ) -> GfxDrawMesh {
         if let Some(mesh) = &self.mesh_cache {
         if let Some(mesh) = &self.mesh_cache {
             return mesh.clone()
             return mesh.clone()
         }
         }
@@ -165,7 +164,7 @@ impl PrivMessage {
             );
             );
         }
         }
 
 
-        let mesh = mesh.alloc(render_api).await.unwrap();
+        let mesh = mesh.alloc(render_api);
         let mesh = mesh.draw_with_texture(self.atlas.texture_id);
         let mesh = mesh.draw_with_texture(self.atlas.texture_id);
         self.mesh_cache = Some(mesh.clone());
         self.mesh_cache = Some(mesh.clone());
 
 
@@ -217,7 +216,7 @@ impl PrivMessage {
         }
         }
     }
     }
 
 
-    fn clear_mesh(&mut self) -> Option<DrawMesh> {
+    fn clear_mesh(&mut self) -> Option<GfxDrawMesh> {
         std::mem::replace(&mut self.mesh_cache, None)
         std::mem::replace(&mut self.mesh_cache, None)
     }
     }
 
 
@@ -242,7 +241,7 @@ pub(super) struct DateMessage {
     glyphs: Vec<Glyph>,
     glyphs: Vec<Glyph>,
 
 
     atlas: text::RenderedAtlas,
     atlas: text::RenderedAtlas,
-    mesh_cache: Option<DrawMesh>,
+    mesh_cache: Option<GfxDrawMesh>,
 }
 }
 
 
 impl DateMessage {
 impl DateMessage {
@@ -264,12 +263,12 @@ impl DateMessage {
 
 
         let mut atlas = text::Atlas::new(render_api);
         let mut atlas = text::Atlas::new(render_api);
         atlas.push(&glyphs);
         atlas.push(&glyphs);
-        let atlas = atlas.make().await.expect("unable to make atlas");
+        let atlas = atlas.make();
 
 
         Message::Date(Self { font_size, timestamp, glyphs, atlas, mesh_cache: None })
         Message::Date(Self { font_size, timestamp, glyphs, atlas, mesh_cache: None })
     }
     }
 
 
-    fn clear_mesh(&mut self) -> Option<DrawMesh> {
+    fn clear_mesh(&mut self) -> Option<GfxDrawMesh> {
         None
         None
     }
     }
 
 
@@ -277,7 +276,7 @@ impl DateMessage {
         // Do nothing
         // Do nothing
     }
     }
 
 
-    async fn gen_mesh(
+    fn gen_mesh(
         &mut self,
         &mut self,
         clip: &Rectangle,
         clip: &Rectangle,
         line_height: f32,
         line_height: f32,
@@ -287,7 +286,7 @@ impl DateMessage {
         text_color: Color,
         text_color: Color,
         debug_render: bool,
         debug_render: bool,
         render_api: &RenderApi,
         render_api: &RenderApi,
-    ) -> DrawMesh {
+    ) -> GfxDrawMesh {
         let mut mesh = MeshBuilder::new();
         let mut mesh = MeshBuilder::new();
 
 
         let glyph_pos_iter = GlyphPositionIter::new(self.font_size, &self.glyphs, baseline);
         let glyph_pos_iter = GlyphPositionIter::new(self.font_size, &self.glyphs, baseline);
@@ -305,7 +304,7 @@ impl DateMessage {
             );
             );
         }
         }
 
 
-        let mesh = mesh.alloc(render_api).await.unwrap();
+        let mesh = mesh.alloc(render_api);
         let mesh = mesh.draw_with_texture(self.atlas.texture_id);
         let mesh = mesh.draw_with_texture(self.atlas.texture_id);
         self.mesh_cache = Some(mesh.clone());
         self.mesh_cache = Some(mesh.clone());
 
 
@@ -343,7 +342,7 @@ impl Message {
         }
         }
     }
     }
 
 
-    fn clear_mesh(&mut self) -> Option<DrawMesh> {
+    fn clear_mesh(&mut self) -> Option<GfxDrawMesh> {
         match self {
         match self {
             Self::Priv(m) => m.clear_mesh(),
             Self::Priv(m) => m.clear_mesh(),
             Self::Date(m) => m.clear_mesh(),
             Self::Date(m) => m.clear_mesh(),
@@ -357,7 +356,7 @@ impl Message {
         }
         }
     }
     }
 
 
-    async fn gen_mesh(
+    fn gen_mesh(
         &mut self,
         &mut self,
         clip: &Rectangle,
         clip: &Rectangle,
         line_height: f32,
         line_height: f32,
@@ -367,34 +366,28 @@ impl Message {
         text_color: Color,
         text_color: Color,
         debug_render: bool,
         debug_render: bool,
         render_api: &RenderApi,
         render_api: &RenderApi,
-    ) -> DrawMesh {
+    ) -> GfxDrawMesh {
         match self {
         match self {
-            Self::Priv(m) => {
-                m.gen_mesh(
-                    clip,
-                    line_height,
-                    baseline,
-                    nick_colors,
-                    timestamp_color,
-                    text_color,
-                    debug_render,
-                    render_api,
-                )
-                .await
-            }
-            Self::Date(m) => {
-                m.gen_mesh(
-                    clip,
-                    line_height,
-                    baseline,
-                    nick_colors,
-                    timestamp_color,
-                    text_color,
-                    debug_render,
-                    render_api,
-                )
-                .await
-            }
+            Self::Priv(m) => m.gen_mesh(
+                clip,
+                line_height,
+                baseline,
+                nick_colors,
+                timestamp_color,
+                text_color,
+                debug_render,
+                render_api,
+            ),
+            Self::Date(m) => m.gen_mesh(
+                clip,
+                line_height,
+                baseline,
+                nick_colors,
+                timestamp_color,
+                text_color,
+                debug_render,
+                render_api,
+            ),
         }
         }
     }
     }
 
 
@@ -416,16 +409,16 @@ fn select_nick_color(nick: &str, nick_colors: &[Color]) -> Color {
 
 
 #[derive(Default)]
 #[derive(Default)]
 pub(super) struct FreedData {
 pub(super) struct FreedData {
-    pub(super) buffers: Vec<BufferId>,
-    pub(super) textures: Vec<TextureId>,
+    pub(super) buffers: Vec<GfxBufferId>,
+    pub(super) textures: Vec<GfxTextureId>,
 }
 }
 
 
 impl FreedData {
 impl FreedData {
-    fn add_mesh(&mut self, mesh: DrawMesh) {
+    fn add_mesh(&mut self, mesh: GfxDrawMesh) {
         self.buffers.push(mesh.vertex_buffer);
         self.buffers.push(mesh.vertex_buffer);
         self.buffers.push(mesh.index_buffer);
         self.buffers.push(mesh.index_buffer);
     }
     }
-    fn add_texture(&mut self, texture_id: TextureId) {
+    fn add_texture(&mut self, texture_id: GfxTextureId) {
         self.textures.push(texture_id);
         self.textures.push(texture_id);
     }
     }
 }
 }
@@ -611,7 +604,7 @@ impl MessageBuffer {
         &mut self,
         &mut self,
         rect: &Rectangle,
         rect: &Rectangle,
         scroll: f32,
         scroll: f32,
-    ) -> Vec<(f32, DrawMesh)> {
+    ) -> Vec<(f32, GfxDrawMesh)> {
         let line_height = self.line_height.get();
         let line_height = self.line_height.get();
         let baseline = self.baseline.get();
         let baseline = self.baseline.get();
         let debug_render = self.debug.get();
         let debug_render = self.debug.get();
@@ -640,18 +633,16 @@ impl MessageBuffer {
                 continue
                 continue
             }
             }
 
 
-            let mesh = msg
-                .gen_mesh(
-                    rect,
-                    line_height,
-                    baseline,
-                    &nick_colors,
-                    timest_color,
-                    text_color,
-                    debug_render,
-                    &render_api,
-                )
-                .await;
+            let mesh = msg.gen_mesh(
+                rect,
+                line_height,
+                baseline,
+                &nick_colors,
+                timest_color,
+                text_color,
+                debug_render,
+                &render_api,
+            );
 
 
             meshes.push((current_pos, mesh));
             meshes.push((current_pos, mesh));
             current_pos += mesh_height;
             current_pos += mesh_height;

+ 17 - 14
bin/darkwallet/src/ui/editbox.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use miniquad::{window, KeyCode, KeyMods, MouseButton, TextureId, TouchPhase};
+use miniquad::{window, KeyCode, KeyMods, MouseButton, TouchPhase};
 use rand::{rngs::OsRng, Rng};
 use rand::{rngs::OsRng, Rng};
 use std::{
 use std::{
     collections::HashMap,
     collections::HashMap,
@@ -30,8 +30,8 @@ use std::{
 use crate::{
 use crate::{
     error::Result,
     error::Result,
     gfx::{
     gfx::{
-        DrawCall, DrawInstruction, DrawMesh, GraphicsEventPublisherPtr, Point, Rectangle,
-        RenderApiPtr,
+        GfxDrawCall, GfxDrawInstruction, GfxDrawMesh, GfxTextureId, GraphicsEventPublisherPtr,
+        Point, Rectangle, RenderApiPtr,
     },
     },
     mesh::{MeshBuilder, MeshInfo, COLOR_BLUE, COLOR_WHITE},
     mesh::{MeshBuilder, MeshInfo, COLOR_BLUE, COLOR_WHITE},
     prop::{
     prop::{
@@ -129,7 +129,7 @@ impl RepeatingKeyTimer {
 #[derive(Clone)]
 #[derive(Clone)]
 struct TextRenderInfo {
 struct TextRenderInfo {
     mesh: MeshInfo,
     mesh: MeshInfo,
-    texture_id: TextureId,
+    texture_id: GfxTextureId,
 }
 }
 
 
 pub type EditBoxPtr = Arc<EditBox>;
 pub type EditBoxPtr = Arc<EditBox>;
@@ -339,7 +339,7 @@ impl EditBox {
 
 
     /// Called whenever the text or any text property changes.
     /// Called whenever the text or any text property changes.
     /// Not related to cursor, text highlighting or bounding (clip) rects.
     /// Not related to cursor, text highlighting or bounding (clip) rects.
-    async fn regen_mesh(&self, mut clip: Rectangle) -> TextRenderInfo {
+    fn regen_mesh(&self, mut clip: Rectangle) -> TextRenderInfo {
         clip.x = 0.;
         clip.x = 0.;
         clip.y = 0.;
         clip.y = 0.;
 
 
@@ -356,7 +356,7 @@ impl EditBox {
         debug!(target: "ui::editbox", "    cursor_pos={cursor_pos}, is_focused={is_focused}");
         debug!(target: "ui::editbox", "    cursor_pos={cursor_pos}, is_focused={is_focused}");
 
 
         let glyphs = self.glyphs.lock().unwrap().clone();
         let glyphs = self.glyphs.lock().unwrap().clone();
-        let atlas = text::make_texture_atlas(&self.render_api, &glyphs).await.unwrap();
+        let atlas = text::make_texture_atlas(&self.render_api, &glyphs);
 
 
         let mut mesh = MeshBuilder::with_clip(clip.clone());
         let mut mesh = MeshBuilder::with_clip(clip.clone());
         self.draw_selected(&mut mesh, &glyphs, clip.h).unwrap();
         self.draw_selected(&mut mesh, &glyphs, clip.h).unwrap();
@@ -403,7 +403,7 @@ impl EditBox {
             mesh.draw_outline(&clip, COLOR_BLUE, 1.);
             mesh.draw_outline(&clip, COLOR_BLUE, 1.);
         }
         }
 
 
-        let mesh = mesh.alloc(&self.render_api).await.unwrap();
+        let mesh = mesh.alloc(&self.render_api);
 
 
         TextRenderInfo { mesh, texture_id: atlas.texture_id }
         TextRenderInfo { mesh, texture_id: atlas.texture_id }
     }
     }
@@ -1193,11 +1193,11 @@ impl EditBox {
             return;
             return;
         };
         };
 
 
-        let Some(draw_update) = self.draw(&sg, &parent_rect).await else {
+        let Some(draw_update) = self.draw(&sg, &parent_rect) else {
             error!(target: "ui::editbox", "Text {:?} failed to draw", node);
             error!(target: "ui::editbox", "Text {:?} failed to draw", node);
             return;
             return;
         };
         };
-        self.render_api.replace_draw_calls(draw_update.draw_calls).await;
+        self.render_api.replace_draw_calls(draw_update.draw_calls);
         debug!(target: "ui::editbox", "replace draw calls done");
         debug!(target: "ui::editbox", "replace draw calls done");
         for buffer_id in draw_update.freed_buffers {
         for buffer_id in draw_update.freed_buffers {
             self.render_api.delete_buffer(buffer_id);
             self.render_api.delete_buffer(buffer_id);
@@ -1207,7 +1207,7 @@ impl EditBox {
         }
         }
     }
     }
 
 
-    pub async fn draw(&self, sg: &SceneGraph, parent_rect: &Rectangle) -> Option<DrawUpdate> {
+    pub fn draw(&self, sg: &SceneGraph, parent_rect: &Rectangle) -> Option<DrawUpdate> {
         debug!(target: "ui::editbox", "EditBox::draw()");
         debug!(target: "ui::editbox", "EditBox::draw()");
         // Only used for debug messages
         // Only used for debug messages
         let node = sg.get_node(self.node_id).unwrap();
         let node = sg.get_node(self.node_id).unwrap();
@@ -1221,7 +1221,7 @@ impl EditBox {
         };
         };
 
 
         // draw will recalc this when it's None
         // draw will recalc this when it's None
-        let render_info = self.regen_mesh(rect.clone()).await;
+        let render_info = self.regen_mesh(rect.clone());
         let old_render_info =
         let old_render_info =
             std::mem::replace(&mut *self.render_info.lock().unwrap(), Some(render_info.clone()));
             std::mem::replace(&mut *self.render_info.lock().unwrap(), Some(render_info.clone()));
 
 
@@ -1234,7 +1234,7 @@ impl EditBox {
             freed_buffers.push(old.mesh.index_buffer);
             freed_buffers.push(old.mesh.index_buffer);
         }
         }
 
 
-        let mesh = DrawMesh {
+        let mesh = GfxDrawMesh {
             vertex_buffer: render_info.mesh.vertex_buffer,
             vertex_buffer: render_info.mesh.vertex_buffer,
             index_buffer: render_info.mesh.index_buffer,
             index_buffer: render_info.mesh.index_buffer,
             texture: Some(render_info.texture_id),
             texture: Some(render_info.texture_id),
@@ -1252,8 +1252,11 @@ impl EditBox {
             key: self.dc_key,
             key: self.dc_key,
             draw_calls: vec![(
             draw_calls: vec![(
                 self.dc_key,
                 self.dc_key,
-                DrawCall {
-                    instrs: vec![DrawInstruction::ApplyMatrix(model), DrawInstruction::Draw(mesh)],
+                GfxDrawCall {
+                    instrs: vec![
+                        GfxDrawInstruction::ApplyMatrix(model),
+                        GfxDrawInstruction::Draw(mesh),
+                    ],
                     dcs: vec![],
                     dcs: vec![],
                     z_index: self.z_index.get(),
                     z_index: self.z_index.get(),
                 },
                 },

+ 18 - 17
bin/darkwallet/src/ui/image.rs

@@ -16,9 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-//use async_lock::Mutex;
 use image::ImageReader;
 use image::ImageReader;
-use miniquad::TextureId;
 use rand::{rngs::OsRng, Rng};
 use rand::{rngs::OsRng, Rng};
 use std::{
 use std::{
     io::Cursor,
     io::Cursor,
@@ -26,7 +24,7 @@ use std::{
 };
 };
 
 
 use crate::{
 use crate::{
-    gfx::{DrawCall, DrawInstruction, DrawMesh, Rectangle, RenderApiPtr},
+    gfx::{GfxDrawCall, GfxDrawInstruction, GfxDrawMesh, GfxTextureId, Rectangle, RenderApiPtr},
     mesh::{MeshBuilder, MeshInfo, COLOR_WHITE},
     mesh::{MeshBuilder, MeshInfo, COLOR_WHITE},
     prop::{PropertyPtr, PropertyStr, PropertyUint32, Role},
     prop::{PropertyPtr, PropertyStr, PropertyUint32, Role},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
@@ -44,7 +42,7 @@ pub struct Image {
     tasks: Vec<smol::Task<()>>,
     tasks: Vec<smol::Task<()>>,
 
 
     mesh: SyncMutex<Option<MeshInfo>>,
     mesh: SyncMutex<Option<MeshInfo>>,
-    texture: SyncMutex<Option<TextureId>>,
+    texture: SyncMutex<Option<GfxTextureId>>,
     dc_key: u64,
     dc_key: u64,
 
 
     node_id: SceneNodeId,
     node_id: SceneNodeId,
@@ -88,13 +86,13 @@ impl Image {
             }
             }
         });
         });
 
 
-        *self_.texture.lock().unwrap() = Some(self_.load_texture().await);
+        *self_.texture.lock().unwrap() = Some(self_.load_texture());
 
 
         Pimpl::Image(self_)
         Pimpl::Image(self_)
     }
     }
 
 
     async fn reload(self: Arc<Self>) {
     async fn reload(self: Arc<Self>) {
-        let texture = self.load_texture().await;
+        let texture = self.load_texture();
         let old_texture = std::mem::replace(&mut *self.texture.lock().unwrap(), Some(texture));
         let old_texture = std::mem::replace(&mut *self.texture.lock().unwrap(), Some(texture));
 
 
         self.clone().redraw().await;
         self.clone().redraw().await;
@@ -104,7 +102,7 @@ impl Image {
         }
         }
     }
     }
 
 
-    async fn load_texture(&self) -> TextureId {
+    fn load_texture(&self) -> GfxTextureId {
         let path = self.path.get();
         let path = self.path.get();
 
 
         // TODO we should NOT use unwrap here
         // TODO we should NOT use unwrap here
@@ -124,7 +122,7 @@ impl Image {
         let height = img.height() as u16;
         let height = img.height() as u16;
         let bmp = img.into_raw();
         let bmp = img.into_raw();
 
 
-        let texture_id = self.render_api.new_texture(width, height, bmp).await.unwrap();
+        let texture_id = self.render_api.new_texture(width, height, bmp);
         texture_id
         texture_id
     }
     }
 
 
@@ -136,24 +134,24 @@ impl Image {
             return;
             return;
         };
         };
 
 
-        let Some(draw_update) = self.draw(&sg, &parent_rect).await else {
+        let Some(draw_update) = self.draw(&sg, &parent_rect) else {
             error!(target: "ui::text", "Text {:?} failed to draw", node);
             error!(target: "ui::text", "Text {:?} failed to draw", node);
             return;
             return;
         };
         };
-        self.render_api.replace_draw_calls(draw_update.draw_calls).await;
+        self.render_api.replace_draw_calls(draw_update.draw_calls);
         debug!(target: "ui::text", "replace draw calls done");
         debug!(target: "ui::text", "replace draw calls done");
     }
     }
 
 
     /// Called whenever any property changes.
     /// Called whenever any property changes.
-    async fn regen_mesh(&self, _clip: Rectangle) -> MeshInfo {
+    fn regen_mesh(&self, _clip: Rectangle) -> MeshInfo {
         let basic = Rectangle { x: 0., y: 0., w: 1., h: 1. };
         let basic = Rectangle { x: 0., y: 0., w: 1., h: 1. };
 
 
         let mut mesh = MeshBuilder::new();
         let mut mesh = MeshBuilder::new();
         mesh.draw_box(&basic, COLOR_WHITE, &basic);
         mesh.draw_box(&basic, COLOR_WHITE, &basic);
-        mesh.alloc(&self.render_api).await.unwrap()
+        mesh.alloc(&self.render_api)
     }
     }
 
 
-    pub async fn draw(&self, sg: &SceneGraph, parent_rect: &Rectangle) -> Option<DrawUpdate> {
+    pub fn draw(&self, sg: &SceneGraph, parent_rect: &Rectangle) -> Option<DrawUpdate> {
         debug!(target: "ui::text", "Text::draw()");
         debug!(target: "ui::text", "Text::draw()");
         // Only used for debug messages
         // Only used for debug messages
         let node = sg.get_node(self.node_id).unwrap();
         let node = sg.get_node(self.node_id).unwrap();
@@ -167,7 +165,7 @@ impl Image {
         };
         };
 
 
         // draw will recalc this when it's None
         // draw will recalc this when it's None
-        let mesh = self.regen_mesh(rect.clone()).await;
+        let mesh = self.regen_mesh(rect.clone());
         let old_mesh = std::mem::replace(&mut *self.mesh.lock().unwrap(), Some(mesh.clone()));
         let old_mesh = std::mem::replace(&mut *self.mesh.lock().unwrap(), Some(mesh.clone()));
 
 
         let Some(texture_id) = *self.texture.lock().unwrap() else {
         let Some(texture_id) = *self.texture.lock().unwrap() else {
@@ -181,7 +179,7 @@ impl Image {
             freed_buffers.push(old.index_buffer);
             freed_buffers.push(old.index_buffer);
         }
         }
 
 
-        let mesh = DrawMesh {
+        let mesh = GfxDrawMesh {
             vertex_buffer: mesh.vertex_buffer,
             vertex_buffer: mesh.vertex_buffer,
             index_buffer: mesh.index_buffer,
             index_buffer: mesh.index_buffer,
             texture: Some(texture_id),
             texture: Some(texture_id),
@@ -200,8 +198,11 @@ impl Image {
             key: self.dc_key,
             key: self.dc_key,
             draw_calls: vec![(
             draw_calls: vec![(
                 self.dc_key,
                 self.dc_key,
-                DrawCall {
-                    instrs: vec![DrawInstruction::ApplyMatrix(model), DrawInstruction::Draw(mesh)],
+                GfxDrawCall {
+                    instrs: vec![
+                        GfxDrawInstruction::ApplyMatrix(model),
+                        GfxDrawInstruction::Draw(mesh),
+                    ],
                     dcs: vec![],
                     dcs: vec![],
                     z_index: self.z_index.get(),
                     z_index: self.z_index.get(),
                 },
                 },

+ 7 - 7
bin/darkwallet/src/ui/layer.rs

@@ -21,7 +21,7 @@ use rand::{rngs::OsRng, Rng};
 use std::sync::{Arc, Weak};
 use std::sync::{Arc, Weak};
 
 
 use crate::{
 use crate::{
-    gfx::{DrawCall, DrawInstruction, Rectangle, RenderApiPtr},
+    gfx::{GfxDrawCall, GfxDrawInstruction, Rectangle, RenderApiPtr},
     prop::{PropertyBool, PropertyPtr, Role},
     prop::{PropertyBool, PropertyPtr, Role},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
     ExecutorPtr,
     ExecutorPtr,
@@ -91,7 +91,7 @@ impl RenderLayer {
             error!(target: "ui::layer", "RenderLayer {:?} failed to draw", node);
             error!(target: "ui::layer", "RenderLayer {:?} failed to draw", node);
             return;
             return;
         };
         };
-        self.render_api.replace_draw_calls(draw_update.draw_calls).await;
+        self.render_api.replace_draw_calls(draw_update.draw_calls);
         debug!(target: "ui::layer", "replace draw calls done");
         debug!(target: "ui::layer", "replace draw calls done");
     }
     }
 
 
@@ -141,10 +141,10 @@ impl RenderLayer {
             let dcs = match &node.pimpl {
             let dcs = match &node.pimpl {
                 Pimpl::RenderLayer(layer) => layer.draw(&sg, &rect).await,
                 Pimpl::RenderLayer(layer) => layer.draw(&sg, &rect).await,
                 Pimpl::Mesh(mesh) => mesh.draw(&sg, &rect),
                 Pimpl::Mesh(mesh) => mesh.draw(&sg, &rect),
-                Pimpl::Text(txt) => txt.draw(&sg, &rect).await,
-                Pimpl::EditBox(editb) => editb.draw(&sg, &rect).await,
+                Pimpl::Text(txt) => txt.draw(&sg, &rect),
+                Pimpl::EditBox(editb) => editb.draw(&sg, &rect),
                 Pimpl::ChatView(chat) => chat.draw(&sg, &rect).await,
                 Pimpl::ChatView(chat) => chat.draw(&sg, &rect).await,
-                Pimpl::Image(img) => img.draw(&sg, &rect).await,
+                Pimpl::Image(img) => img.draw(&sg, &rect),
                 Pimpl::Button(btn) => {
                 Pimpl::Button(btn) => {
                     btn.set_parent_rect(&rect);
                     btn.set_parent_rect(&rect);
                     continue
                     continue
@@ -161,8 +161,8 @@ impl RenderLayer {
             freed_buffers.append(&mut draw_update.freed_buffers);
             freed_buffers.append(&mut draw_update.freed_buffers);
         }
         }
 
 
-        let dc = DrawCall {
-            instrs: vec![DrawInstruction::ApplyViewport(rect)],
+        let dc = GfxDrawCall {
+            instrs: vec![GfxDrawInstruction::ApplyViewport(rect)],
             dcs: child_calls,
             dcs: child_calls,
             z_index: 0,
             z_index: 0,
         };
         };

+ 14 - 9
bin/darkwallet/src/ui/mesh.rs

@@ -20,7 +20,9 @@ use rand::{rngs::OsRng, Rng};
 use std::sync::{Arc, Weak};
 use std::sync::{Arc, Weak};
 
 
 use crate::{
 use crate::{
-    gfx::{DrawCall, DrawInstruction, DrawMesh, Rectangle, RenderApiPtr, Vertex},
+    gfx::{
+        GfxBufferId, GfxDrawCall, GfxDrawInstruction, GfxDrawMesh, Rectangle, RenderApiPtr, Vertex,
+    },
     prop::{PropertyPtr, PropertyUint32, Role},
     prop::{PropertyPtr, PropertyUint32, Role},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
     ExecutorPtr,
     ExecutorPtr,
@@ -35,8 +37,8 @@ pub struct Mesh {
     render_api: RenderApiPtr,
     render_api: RenderApiPtr,
     _tasks: Vec<smol::Task<()>>,
     _tasks: Vec<smol::Task<()>>,
 
 
-    vertex_buffer: miniquad::BufferId,
-    index_buffer: miniquad::BufferId,
+    vertex_buffer: GfxBufferId,
+    index_buffer: GfxBufferId,
     // Texture
     // Texture
     num_elements: i32,
     num_elements: i32,
 
 
@@ -57,8 +59,8 @@ impl Mesh {
         indices: Vec<u16>,
         indices: Vec<u16>,
     ) -> Pimpl {
     ) -> Pimpl {
         let num_elements = indices.len() as i32;
         let num_elements = indices.len() as i32;
-        let vertex_buffer = render_api.new_vertex_buffer(verts).await.unwrap();
-        let index_buffer = render_api.new_index_buffer(indices).await.unwrap();
+        let vertex_buffer = render_api.new_vertex_buffer(verts);
+        let index_buffer = render_api.new_index_buffer(indices);
 
 
         let scene_graph = sg.lock().await;
         let scene_graph = sg.lock().await;
         let node = scene_graph.get_node(node_id).unwrap();
         let node = scene_graph.get_node(node_id).unwrap();
@@ -101,7 +103,7 @@ impl Mesh {
             error!(target: "ui::mesh", "Mesh {:?} failed to draw", node);
             error!(target: "ui::mesh", "Mesh {:?} failed to draw", node);
             return;
             return;
         };
         };
-        self.render_api.replace_draw_calls(draw_update.draw_calls).await;
+        self.render_api.replace_draw_calls(draw_update.draw_calls);
         debug!(target: "ui::mesh", "replace draw calls done");
         debug!(target: "ui::mesh", "replace draw calls done");
     }
     }
 
 
@@ -110,7 +112,7 @@ impl Mesh {
         // Only used for debug messages
         // Only used for debug messages
         let node = sg.get_node(self.node_id).unwrap();
         let node = sg.get_node(self.node_id).unwrap();
 
 
-        let mesh = DrawMesh {
+        let mesh = GfxDrawMesh {
             vertex_buffer: self.vertex_buffer,
             vertex_buffer: self.vertex_buffer,
             index_buffer: self.index_buffer,
             index_buffer: self.index_buffer,
             texture: None,
             texture: None,
@@ -139,8 +141,11 @@ impl Mesh {
             key: self.dc_key,
             key: self.dc_key,
             draw_calls: vec![(
             draw_calls: vec![(
                 self.dc_key,
                 self.dc_key,
-                DrawCall {
-                    instrs: vec![DrawInstruction::ApplyMatrix(model), DrawInstruction::Draw(mesh)],
+                GfxDrawCall {
+                    instrs: vec![
+                        GfxDrawInstruction::ApplyMatrix(model),
+                        GfxDrawInstruction::Draw(mesh),
+                    ],
                     dcs: vec![],
                     dcs: vec![],
                     z_index: self.z_index.get(),
                     z_index: self.z_index.get(),
                 },
                 },

+ 4 - 5
bin/darkwallet/src/ui/mod.rs

@@ -16,13 +16,12 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-use miniquad::{BufferId, TextureId};
 use std::sync::{Arc, Weak};
 use std::sync::{Arc, Weak};
 
 
 use crate::{
 use crate::{
     error::{Error, Result},
     error::{Error, Result},
     expr::{SExprMachine, SExprVal},
     expr::{SExprMachine, SExprVal},
-    gfx::{DrawCall, Rectangle},
+    gfx::{GfxBufferId, GfxDrawCall, GfxTextureId, Rectangle},
     prop::{PropertyPtr, Role},
     prop::{PropertyPtr, Role},
     scene::{SceneGraph, SceneNode, SceneNodeId, SceneNodeType},
     scene::{SceneGraph, SceneNode, SceneNodeId, SceneNodeType},
     ExecutorPtr,
     ExecutorPtr,
@@ -51,9 +50,9 @@ pub trait Stoppable {
 
 
 pub struct DrawUpdate {
 pub struct DrawUpdate {
     pub key: u64,
     pub key: u64,
-    pub draw_calls: Vec<(u64, DrawCall)>,
-    pub freed_textures: Vec<TextureId>,
-    pub freed_buffers: Vec<BufferId>,
+    pub draw_calls: Vec<(u64, GfxDrawCall)>,
+    pub freed_textures: Vec<GfxTextureId>,
+    pub freed_buffers: Vec<GfxBufferId>,
 }
 }
 
 
 pub struct OnModify<T> {
 pub struct OnModify<T> {

+ 16 - 12
bin/darkwallet/src/ui/text.rs

@@ -16,13 +16,14 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
 
 
-//use async_lock::Mutex;
-use miniquad::TextureId;
 use rand::{rngs::OsRng, Rng};
 use rand::{rngs::OsRng, Rng};
 use std::sync::{Arc, Mutex as SyncMutex, Weak};
 use std::sync::{Arc, Mutex as SyncMutex, Weak};
 
 
 use crate::{
 use crate::{
-    gfx::{DrawCall, DrawInstruction, DrawMesh, Rectangle, RenderApi, RenderApiPtr},
+    gfx::{
+        GfxDrawCall, GfxDrawInstruction, GfxDrawMesh, GfxTextureId, Rectangle, RenderApi,
+        RenderApiPtr,
+    },
     mesh::{Color, MeshBuilder, MeshInfo, COLOR_BLUE, COLOR_WHITE},
     mesh::{Color, MeshBuilder, MeshInfo, COLOR_BLUE, COLOR_WHITE},
     prop::{
     prop::{
         PropertyBool, PropertyColor, PropertyFloat32, PropertyPtr, PropertyStr, PropertyUint32,
         PropertyBool, PropertyColor, PropertyFloat32, PropertyPtr, PropertyStr, PropertyUint32,
@@ -40,7 +41,7 @@ pub type TextPtr = Arc<Text>;
 #[derive(Clone)]
 #[derive(Clone)]
 struct TextRenderInfo {
 struct TextRenderInfo {
     mesh: MeshInfo,
     mesh: MeshInfo,
-    texture_id: TextureId,
+    texture_id: GfxTextureId,
 }
 }
 
 
 pub struct Text {
 pub struct Text {
@@ -135,7 +136,7 @@ impl Text {
     ) -> TextRenderInfo {
     ) -> TextRenderInfo {
         debug!(target: "ui::text", "Rendering label '{}'", text);
         debug!(target: "ui::text", "Rendering label '{}'", text);
         let glyphs = text_shaper.shape(text, font_size).await;
         let glyphs = text_shaper.shape(text, font_size).await;
-        let atlas = text::make_texture_atlas(render_api, &glyphs).await.unwrap();
+        let atlas = text::make_texture_atlas(render_api, &glyphs);
 
 
         let mut mesh = MeshBuilder::new();
         let mut mesh = MeshBuilder::new();
         let glyph_pos_iter = GlyphPositionIter::new(font_size, &glyphs, baseline);
         let glyph_pos_iter = GlyphPositionIter::new(font_size, &glyphs, baseline);
@@ -153,7 +154,7 @@ impl Text {
             mesh.draw_box(&glyph_rect, color, uv_rect);
             mesh.draw_box(&glyph_rect, color, uv_rect);
         }
         }
 
 
-        let mesh = mesh.alloc(&render_api).await.unwrap();
+        let mesh = mesh.alloc(&render_api);
 
 
         TextRenderInfo { mesh, texture_id: atlas.texture_id }
         TextRenderInfo { mesh, texture_id: atlas.texture_id }
     }
     }
@@ -181,11 +182,11 @@ impl Text {
             return;
             return;
         };
         };
 
 
-        let Some(draw_update) = self.draw(&sg, &parent_rect).await else {
+        let Some(draw_update) = self.draw(&sg, &parent_rect) else {
             error!(target: "ui::text", "Text {:?} failed to draw", node);
             error!(target: "ui::text", "Text {:?} failed to draw", node);
             return;
             return;
         };
         };
-        self.render_api.replace_draw_calls(draw_update.draw_calls).await;
+        self.render_api.replace_draw_calls(draw_update.draw_calls);
         debug!(target: "ui::text", "replace draw calls done");
         debug!(target: "ui::text", "replace draw calls done");
 
 
         // We're finished with these so clean up.
         // We're finished with these so clean up.
@@ -194,14 +195,14 @@ impl Text {
         self.render_api.delete_texture(old.texture_id);
         self.render_api.delete_texture(old.texture_id);
     }
     }
 
 
-    pub async fn draw(&self, sg: &SceneGraph, parent_rect: &Rectangle) -> Option<DrawUpdate> {
+    pub fn draw(&self, sg: &SceneGraph, parent_rect: &Rectangle) -> Option<DrawUpdate> {
         debug!(target: "ui::text", "Text::draw()");
         debug!(target: "ui::text", "Text::draw()");
         // Only used for debug messages
         // Only used for debug messages
         let node = sg.get_node(self.node_id).unwrap();
         let node = sg.get_node(self.node_id).unwrap();
 
 
         let render_info = self.render_info.lock().unwrap().clone();
         let render_info = self.render_info.lock().unwrap().clone();
 
 
-        let mesh = DrawMesh {
+        let mesh = GfxDrawMesh {
             vertex_buffer: render_info.mesh.vertex_buffer,
             vertex_buffer: render_info.mesh.vertex_buffer,
             index_buffer: render_info.mesh.index_buffer,
             index_buffer: render_info.mesh.index_buffer,
             texture: Some(render_info.texture_id),
             texture: Some(render_info.texture_id),
@@ -227,8 +228,11 @@ impl Text {
             key: self.dc_key,
             key: self.dc_key,
             draw_calls: vec![(
             draw_calls: vec![(
                 self.dc_key,
                 self.dc_key,
-                DrawCall {
-                    instrs: vec![DrawInstruction::ApplyMatrix(model), DrawInstruction::Draw(mesh)],
+                GfxDrawCall {
+                    instrs: vec![
+                        GfxDrawInstruction::ApplyMatrix(model),
+                        GfxDrawInstruction::Draw(mesh),
+                    ],
                     dcs: vec![],
                     dcs: vec![],
                     z_index: self.z_index.get(),
                     z_index: self.z_index.get(),
                 },
                 },

+ 3 - 3
bin/darkwallet/src/ui/win.rs

@@ -19,7 +19,7 @@
 use std::sync::{Arc, Weak};
 use std::sync::{Arc, Weak};
 
 
 use crate::{
 use crate::{
-    gfx::{DrawCall, GraphicsEventPublisherPtr, Rectangle, RenderApiPtr},
+    gfx::{GfxDrawCall, GraphicsEventPublisherPtr, Rectangle, RenderApiPtr},
     prop::{PropertyPtr, Role},
     prop::{PropertyPtr, Role},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
     scene::{Pimpl, SceneGraph, SceneGraphPtr2, SceneNodeId},
     ExecutorPtr,
     ExecutorPtr,
@@ -138,11 +138,11 @@ impl Window {
             freed_buffers.append(&mut draw_update.freed_buffers);
             freed_buffers.append(&mut draw_update.freed_buffers);
         }
         }
 
 
-        let root_dc = DrawCall { instrs: vec![], dcs: child_calls, z_index: 0 };
+        let root_dc = GfxDrawCall { instrs: vec![], dcs: child_calls, z_index: 0 };
         draw_calls.push((0, root_dc));
         draw_calls.push((0, root_dc));
         //debug!(target: "ui::win", "  => {:?}", draw_calls);
         //debug!(target: "ui::win", "  => {:?}", draw_calls);
 
 
-        self.render_api.replace_draw_calls(draw_calls).await;
+        self.render_api.replace_draw_calls(draw_calls);
 
 
         for texture in freed_textures {
         for texture in freed_textures {
             self.render_api.delete_texture(texture);
             self.render_api.delete_texture(texture);