summary refs log tree commit diff
path: root/src/graphics_window_dressing.rs
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-07-20 20:43:48 -0700
committerIrene Knapp <ireneista@irenes.space>2026-07-20 20:43:48 -0700
commit3ac1e5e5a9ebcb4beb2bfe149dd5095f2250f60d (patch)
treed409eb8dfcca1b56dffe8c143a2c9028818d6d5d /src/graphics_window_dressing.rs
parent365c2f8bdc217f33264e3aed394f67840a4c075d (diff)
load a nontrivial model and render it with a texture HEAD main
yay

Force-Push: yes
Change-Id: Icb715692286c8560532ab73d32a49be8f485d790
Diffstat (limited to 'src/graphics_window_dressing.rs')
-rw-r--r--src/graphics_window_dressing.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/graphics_window_dressing.rs b/src/graphics_window_dressing.rs
index ce5ccda..e774177 100644
--- a/src/graphics_window_dressing.rs
+++ b/src/graphics_window_dressing.rs
@@ -3,7 +3,8 @@ use crate::error::*;
 use crate::graphics_permanent::{
   PermanentGraphicsState, GraphicsStateForReinit, QueueFamilyIndices
 };
-use crate::shader_data::{ VERTICES, INDICES, Vertex, UniformBlock };
+use crate::model_loader::load_model;
+use crate::shader_data::{ Vertex, UniformBlock };
 
 use std::collections::BTreeSet;
 use std::io::Cursor;
@@ -50,6 +51,7 @@ pub struct WindowDressing {
 
   index_buffer: vk::Buffer,
   index_buffer_memory: vk::DeviceMemory,
+  index_count: usize,
 
   texture_image: vk::Image,
   texture_image_memory: vk::DeviceMemory,
@@ -137,11 +139,14 @@ impl WindowDressing {
     let (primary_command_pool, transient_command_pool)
             = init_command_pools(device, indices)?;
 
+    let (vertices, indices) = load_model()?;
+    let index_count = indices.len();
+
     let (vertex_buffer, vertex_buffer_memory)
-            = init_vertex_buffer(instance, physical_device, device,
+            = init_vertex_buffer(vertices, instance, physical_device, device,
                                  graphics_queue, &transient_command_pool)?;
     let (index_buffer, index_buffer_memory)
-            = init_index_buffer(instance, physical_device, device,
+            = init_index_buffer(indices, instance, physical_device, device,
                                 graphics_queue, &transient_command_pool)?;
 
     let (texture_image, texture_image_memory, texture_image_view)
@@ -163,7 +168,7 @@ impl WindowDressing {
     let command_buffers = init_commands(
             device, &swapchain.extent, &framebuffers, &render_pass,
             &pipeline_layout, &pipeline, &vertex_buffer, &index_buffer,
-            &descriptor_sets, &primary_command_pool)?;
+            index_count, &descriptor_sets, &primary_command_pool)?;
 
     let concurrency = init_concurrency(device, &swapchain.images)?;
 
@@ -181,6 +186,7 @@ impl WindowDressing {
       vertex_buffer_memory,
       index_buffer,
       index_buffer_memory,
+      index_count,
       texture_image,
       texture_image_memory,
       texture_image_view,
@@ -250,7 +256,7 @@ impl WindowDressing {
     let command_buffers = init_commands(
             device, &swapchain.extent, &framebuffers, &render_pass,
             &pipeline_layout, &pipeline, &self.vertex_buffer,
-            &self.index_buffer, &descriptor_sets,
+            &self.index_buffer, self.index_count, &descriptor_sets,
             &self.primary_command_pool)?;
 
     self.concurrency.image_fences.resize(swapchain.images.len(),
@@ -689,23 +695,23 @@ fn init_framebuffers(device: &Device, extent: &vk::Extent2D,
 }
 
 
-fn init_vertex_buffer(instance: &Instance,
+fn init_vertex_buffer(vertices: Vec<Vertex<f32>>, instance: &Instance,
                       physical_device: &vk::PhysicalDevice, device: &Device,
                       queue: &vk::Queue, command_pool: &vk::CommandPool)
     -> Result<(vk::Buffer, vk::DeviceMemory)>
 {
   init_buffer(instance, physical_device, device, queue, command_pool,
-              vk::BufferUsageFlags::VERTEX_BUFFER, &VERTICES)
+              vk::BufferUsageFlags::VERTEX_BUFFER, &vertices)
 }
 
 
-fn init_index_buffer(instance: &Instance,
+fn init_index_buffer(indices: Vec<u32>, instance: &Instance,
                      physical_device: &vk::PhysicalDevice, device: &Device,
                      queue: &vk::Queue, command_pool: &vk::CommandPool)
     -> Result<(vk::Buffer, vk::DeviceMemory)>
 {
   init_buffer(instance, physical_device, device, queue, command_pool,
-              vk::BufferUsageFlags::INDEX_BUFFER, INDICES)
+              vk::BufferUsageFlags::INDEX_BUFFER, &indices)
 }
 
 
@@ -912,6 +918,7 @@ fn init_commands(device: &Device,
                  pipeline: &vk::Pipeline,
                  vertex_buffer: &vk::Buffer,
                  index_buffer: &vk::Buffer,
+                 index_count: usize,
                  descriptor_sets: &Vec<vk::DescriptorSet>,
                  command_pool: &vk::CommandPool)
     -> Result<Vec<vk::CommandBuffer>>
@@ -979,7 +986,7 @@ fn init_commands(device: &Device,
 
     unsafe {
       device.cmd_bind_index_buffer(command_buffer, *index_buffer, 0,
-                                   vk::IndexType::UINT16)
+                                   vk::IndexType::UINT32)
     };
 
     unsafe {
@@ -992,7 +999,7 @@ fn init_commands(device: &Device,
     };
 
     unsafe {
-      device.cmd_draw_indexed(command_buffer, INDICES.len() as u32,
+      device.cmd_draw_indexed(command_buffer, index_count as u32,
                               1, 0, 0, 0)
     };