diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:22 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:22 +0100 |
commit | b688a25810840c5ebf4bf2c18bbdae52c62f6b4d (patch) | |
tree | 923c81d1be62d1344694306d5fb8728841620b6f /stockton-render/src/draw/ui/render.rs | |
parent | bf9573764c695e65b1504419fafb76ccabb0322b (diff) |
feat(render): WIP eGUI integration
Diffstat (limited to 'stockton-render/src/draw/ui/render.rs')
-rw-r--r-- | stockton-render/src/draw/ui/render.rs | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/stockton-render/src/draw/ui/render.rs b/stockton-render/src/draw/ui/render.rs index b965a80..ad23dfb 100644 --- a/stockton-render/src/draw/ui/render.rs +++ b/stockton-render/src/draw/ui/render.rs @@ -15,14 +15,65 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +use crate::draw::texture::TextureStore; +use arrayvec::ArrayVec; +use egui::Pos2; use hal::prelude::*; +use hal::pso::ShaderStageFlags; +use super::UIPoint; use crate::draw::draw_buffers::DrawBuffers; use crate::types::*; +use crate::UIState; +use std::convert::TryInto; +use std::mem::transmute; +use stockton_types::Vector2; -pub fn do_render(cmd_buffer: &mut CommandBuffer, _draw_buffers: &mut DrawBuffers) { +pub fn do_render( + cmd_buffer: &mut CommandBuffer, + pipeline_layout: &PipelineLayout, + draw_buffers: &mut DrawBuffers<UIPoint>, + texture_store: &mut TextureStore, + ui: &mut UIState, +) { // TODO: Actual UI Rendering + let (_out, paint) = ui.end_frame(); + let screen = ui.dimensions(); + unsafe { - cmd_buffer.draw(0..3, 0..1); + cmd_buffer.push_graphics_constants( + &pipeline_layout, + ShaderStageFlags::VERTEX, + 0, + &[transmute(screen.x), transmute(screen.y)], + ); + } + + for (_rect, tris) in paint.iter() { + // Copy triangles/indicies + for i in (0..tris.indices.len()).step_by(3) { + draw_buffers.index_buffer[i / 3] = ( + tris.indices[i].try_into().unwrap(), + tris.indices[i + 1].try_into().unwrap(), + tris.indices[i + 2].try_into().unwrap(), + ); + } + for (i, vertex) in tris.vertices.iter().enumerate() { + draw_buffers.vertex_buffer[i] = UIPoint( + Vector2::new(vertex.pos.x, vertex.pos.y), + Vector2::new(vertex.uv.x, vertex.uv.y), + vertex.color, + ); + } + + // TODO: *Properly* deal with textures + let mut descriptor_sets: ArrayVec<[_; 1]> = ArrayVec::new(); + descriptor_sets.push(texture_store.get_chunk_descriptor_set(0)); + + unsafe { + cmd_buffer.bind_graphics_descriptor_sets(pipeline_layout, 0, descriptor_sets, &[]); + // Call draw + cmd_buffer.draw_indexed(0..tris.indices.len() as u32, 0, 0..1); + } } } |