From c260bde863808d59fe05784720a97a02c075da54 Mon Sep 17 00:00:00 2001 From: prushton2 Date: Tue, 14 Apr 2026 09:29:06 -0400 Subject: [PATCH] Added config to init --- src/main.rs | 12 +++++++++--- src/wgpu_handler.rs | 10 +++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 18a7f83..393c54e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use std::sync::{Arc, RwLock}; use clap::Parser; use image::ImageReader; use render_engine::ui::{self, UIElement}; +use render_engine::wgpu_handler::GpuConfig; use winit::application::ApplicationHandler; use winit::event::{ElementState, KeyEvent, WindowEvent, DeviceEvent, DeviceId}; use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; @@ -187,12 +188,17 @@ impl ApplicationHandler for App { // wgpu init is async but resumed() isn't — use pollster to block pollster::block_on( - self.gpu.init( + self.gpu.init( window.clone(), self.config.width as u32, self.config.height as u32, - &mut self.ui, - vec!["textures/dirt.png", "textures/grass_side.png", "textures/grass_top.png"]) + &mut self.ui, + vec!["textures/dirt.png", "textures/grass_side.png", "textures/grass_top.png"], + GpuConfig{ + sphere_buffer_max: 512, + quad_buffer_max: 512 + } + ) ); std::thread::sleep(std::time::Duration::from_millis(1000)); diff --git a/src/wgpu_handler.rs b/src/wgpu_handler.rs index 90c38ba..317f627 100644 --- a/src/wgpu_handler.rs +++ b/src/wgpu_handler.rs @@ -8,6 +8,10 @@ use crate::object::{self, camera::GpuUniform, quad::GpuQuad, sphere::GpuSphere}; use crate::ui::ui_element::GPUUIElement; use crate::ui::{self, UIElement}; +pub struct GpuConfig { + pub sphere_buffer_max: usize, + pub quad_buffer_max: usize, +} pub struct GpuHandler { pub device: Option, pub queue: Option, @@ -237,7 +241,7 @@ impl GpuHandler { } // vibecoded but man thats a lot - pub async fn init(&mut self, window: Arc, width: u32, height: u32, ui_elements: &mut Vec, texture_paths: Vec<&str>) { + pub async fn init(&mut self, window: Arc, width: u32, height: u32, ui_elements: &mut Vec, texture_paths: Vec<&str>, config: GpuConfig) { // --- get a handle to the graphics card --- let instance = wgpu::Instance::default(); let surface = instance.create_surface(window).unwrap(); @@ -332,14 +336,14 @@ impl GpuHandler { let spheres_buf = device.create_buffer(&wgpu::BufferDescriptor { label: Some("spheres"), - size: (std::mem::size_of::() * 512) as u64, + size: (std::mem::size_of::() * config.sphere_buffer_max) as u64, usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); let quads_buf = device.create_buffer(&wgpu::BufferDescriptor { label: Some("quads"), - size: (std::mem::size_of::() * 512) as u64, + size: (std::mem::size_of::() * config.quad_buffer_max) as u64, usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, });