Compare commits

..

No commits in common. "ab76a63256cd399a65a434976a8bdc79c20e0604" and "247607a4a6bc0143f99b5ff63fcfd822ff516046" have entirely different histories.

2 changed files with 6 additions and 93 deletions

View File

@ -2,11 +2,7 @@ use std::sync::Arc;
use thiserror::Error;
use winit::{
dpi::PhysicalSize,
error::{EventLoopError, OsError},
event::WindowEvent,
event_loop::{EventLoop, EventLoopWindowTarget},
window::{Window, WindowBuilder},
dpi::PhysicalSize, event::WindowEvent, event_loop::EventLoopWindowTarget, window::Window,
};
#[derive(Error, Debug)]
@ -19,10 +15,6 @@ pub enum ContextError {
Adapter,
#[error("Device request failed: {0}")]
Device(#[from] wgpu::RequestDeviceError),
#[error("Event loop creation failed: {0}")]
EventLoop(#[from] EventLoopError),
#[error("Window creation failed: {0}")]
Os(#[from] OsError),
}
pub struct Context<'window> {
@ -37,15 +29,10 @@ pub struct Context<'window> {
}
impl<'window> Context<'window> {
pub async fn new(
window: Arc<Window>,
backends: wgpu::Backends,
required_features: wgpu::Features,
required_limits: wgpu::Limits,
) -> Result<Self, ContextError> {
pub async fn new(window: Arc<Window>, limits: wgpu::Limits) -> Result<Self, ContextError> {
log::info!("Initialising WGPU context...");
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends,
backends: wgpu::Backends::VULKAN,
dx12_shader_compiler: Default::default(),
..Default::default()
});
@ -76,8 +63,8 @@ impl<'window> Context<'window> {
.request_device(
&wgpu::DeviceDescriptor {
label: None,
required_features,
required_limits,
required_features: wgpu::Features::empty(),
required_limits: limits,
},
None,
)
@ -139,75 +126,3 @@ impl<'window> Context<'window> {
handled
}
}
pub struct ContextBuilder {
title: String,
vsync: bool,
resolution: PhysicalSize<u32>,
backends: wgpu::Backends,
features: wgpu::Features,
limits: wgpu::Limits,
}
impl Default for ContextBuilder {
fn default() -> Self {
Self {
title: "Crawl".to_string(),
vsync: true,
resolution: PhysicalSize::new(1280, 720),
backends: Default::default(),
features: Default::default(),
limits: Default::default(),
}
}
}
impl ContextBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn with_title(mut self, title: &str) -> Self {
self.title = title.to_string();
self
}
pub fn with_vsync(mut self, vsync: bool) -> Self {
self.vsync = vsync;
self
}
pub fn with_resolution(mut self, width: u32, height: u32) -> Self {
self.resolution = PhysicalSize::new(width, height);
self
}
pub fn with_backends(mut self, backends: wgpu::Backends) -> Self {
self.backends = backends;
self
}
pub fn with_features(mut self, features: wgpu::Features) -> Self {
self.features = features;
self
}
pub fn with_limits(mut self, limits: wgpu::Limits) -> Self {
self.limits = limits;
self
}
pub async fn build(self) -> Result<(Context<'static>, EventLoop<()>), ContextError> {
let event_loop = EventLoop::new()?;
let window = Arc::new(
WindowBuilder::new()
.with_title(self.title)
.with_inner_size(self.resolution)
.build(&event_loop)?,
);
let context = Context::new(window, self.backends, self.features, self.limits).await?;
Ok((context, event_loop))
}
}

View File

@ -6,8 +6,6 @@ mod texture;
pub use self::{
bind_group::{BindGroupBuilder, BindGroupLayoutBuilder},
buffer::{BufferExt, BulkBufferBuilder},
context::{Context, ContextBuilder},
context::Context,
texture::{Texture, TextureBuilder},
};
pub use {wgpu, winit};