Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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));
Expand Down
10 changes: 7 additions & 3 deletions src/wgpu_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<wgpu::Device>,
pub queue: Option<wgpu::Queue>,
Expand Down Expand Up @@ -237,7 +241,7 @@ impl GpuHandler {
}

// vibecoded but man thats a lot
pub async fn init(&mut self, window: Arc<Window>, width: u32, height: u32, ui_elements: &mut Vec<UIElement>, texture_paths: Vec<&str>) {
pub async fn init(&mut self, window: Arc<Window>, width: u32, height: u32, ui_elements: &mut Vec<UIElement>, 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();
Expand Down Expand Up @@ -332,14 +336,14 @@ impl GpuHandler {

let spheres_buf = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("spheres"),
size: (std::mem::size_of::<object::sphere::GpuSphere>() * 512) as u64,
size: (std::mem::size_of::<object::sphere::GpuSphere>() * 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::<object::quad::GpuQuad>() * 512) as u64,
size: (std::mem::size_of::<object::quad::GpuQuad>() * config.quad_buffer_max) as u64,
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
Expand Down
Loading