use windowBuilder

This commit is contained in:
Jérémi N ‘EndMove’ 2023-09-16 14:54:36 +02:00
parent 2d22de28b9
commit 35ad1762d6
Signed by: EndMove
GPG Key ID: 65C4A02E1F5371A4
4 changed files with 34 additions and 15 deletions

View File

@ -2,6 +2,8 @@
name = "rust-game-engine" name = "rust-game-engine"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
authors = ["phito", "endmove"]
repository = "https://git.endmove.eu/phito/rust-game-engine.git"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -11,7 +13,7 @@ env_logger = "0.10.0"
pollster = "0.3.0" pollster = "0.3.0"
wgpu = "0.17.0" wgpu = "0.17.0"
winit = "0.28.6" winit = "0.28.6"
criterion = { version = "0.4", features = ["html_reports"] } criterion = { version = "0.5.1", features = ["html_reports"] }
[[bench]] [[bench]]

BIN
assets/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -14,7 +14,7 @@ fn voxel_vec_1d(data: Vec<Voxel>) -> Voxel {
const Y: usize = 0; const Y: usize = 0;
const Z: usize = 0; const Z: usize = 0;
return data[X + Y * MAP_WIDTH + Z * MAP_WIDTH * MAP_HEIGHT]; data[X + Y * MAP_WIDTH + Z * MAP_WIDTH * MAP_HEIGHT]
} }
fn voxel_vec_3d(data: Vec<Vec<Vec<Voxel>>>) -> Voxel { fn voxel_vec_3d(data: Vec<Vec<Vec<Voxel>>>) -> Voxel {
@ -22,7 +22,7 @@ fn voxel_vec_3d(data: Vec<Vec<Vec<Voxel>>>) -> Voxel {
const Y: usize = 0; const Y: usize = 0;
const Z: usize = 0; const Z: usize = 0;
return data[X][Y][Z]; data[X][Y][Z]
} }
fn criterion_benchmark(c: &mut Criterion) { fn criterion_benchmark(c: &mut Criterion) {

View File

@ -4,22 +4,24 @@ use std::borrow::Cow;
use winit::{ use winit::{
event::{Event, WindowEvent}, event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
window::Window, window::{WindowBuilder, Window},
}; };
async fn run(event_loop: EventLoop<()>, window: Window) { async fn run(event_loop: EventLoop<()>, window: Window) {
let size = window.inner_size(); let size = window.inner_size();
let instance = wgpu::Instance::default(); let instance = wgpu::Instance::default();
let surface = unsafe { instance.create_surface(&window) }
.expect("Failed to create surface");
let surface = unsafe { instance.create_surface(&window) }.unwrap(); let adapter_options = wgpu::RequestAdapterOptions {
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::default(), power_preference: wgpu::PowerPreference::default(),
force_fallback_adapter: false, force_fallback_adapter: false,
// Request an adapter which can render to our surface compatible_surface: None,
compatible_surface: Some(&surface), };
})
let adapter = instance
.request_adapter(&adapter_options)
.await .await
.expect("Failed to find an appropriate adapter"); .expect("Failed to find an appropriate adapter");
@ -40,12 +42,12 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
// Load the shaders from disk // Load the shaders from disk
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None, label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
}); });
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None, label: Some("Pipeline Layout"),
bind_group_layouts: &[], bind_group_layouts: &[],
push_constant_ranges: &[], push_constant_ranges: &[],
}); });
@ -54,7 +56,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
let swapchain_format = swapchain_capabilities.formats[0]; let swapchain_format = swapchain_capabilities.formats[0];
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None, label: Some("Render Pipeline"),
layout: Some(&pipeline_layout), layout: Some(&pipeline_layout),
vertex: wgpu::VertexState { vertex: wgpu::VertexState {
module: &shader, module: &shader,
@ -142,8 +144,23 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
} }
fn main() { fn main() {
// Instantiate event loop and win builder
let event_loop = EventLoop::new(); let event_loop = EventLoop::new();
let window = winit::window::Window::new(&event_loop).unwrap(); let win_builder = WindowBuilder::new();
// Create and configure window
let window_def_size = winit::dpi::LogicalSize::new(640, 360);
// let window_icon = Icon::from_path("../assets/icon.ico", None).expect("Failed to load icon");
let window = win_builder.with_title("Rust Game Engine")
.with_inner_size(window_def_size)
.with_min_inner_size(window_def_size)
.with_resizable(true)
.with_enabled_buttons(winit::window::WindowButtons::from_bits(3).unwrap())
.with_transparent(true)
// .with_window_icon(Some(window_icon))
.build(&event_loop)
.unwrap();
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
{ {
env_logger::init(); env_logger::init();