Compare commits

...

3 commits

Author SHA1 Message Date
0dbd2d7a7d
Update CI rust version
Some checks failed
continuous-integration/drone/push Build is failing
2022-08-23 00:48:48 +02:00
75686c6c34
Simplify cargo.toml
Some checks failed
continuous-integration/drone/push Build is failing
2022-08-23 00:47:51 +02:00
bfdd61775f
Update to wgpu 0.13, some errors are left
Some checks failed
continuous-integration/drone/push Build is failing
2022-08-23 00:46:54 +02:00
17 changed files with 1016 additions and 853 deletions

View file

@ -4,6 +4,6 @@ name: frontend
steps: steps:
- name: build - name: build
image: rust:1.53.0-slim image: rust:1.63.0-slim
commands: commands:
- cargo build - cargo build

1693
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
[package] [package]
name = "minecrab" name = "minecrab"
version = "0.1.0" version = "0.1.0"
edition = "2018" edition = "2021"
# 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
@ -9,21 +9,21 @@ edition = "2018"
anyhow = "1.0.40" anyhow = "1.0.40"
bytemuck = { version = "1.5.1", features = ["derive"] } bytemuck = { version = "1.5.1", features = ["derive"] }
cgmath = "0.18.0" cgmath = "0.18.0"
env_logger = "0.8.3" env_logger = "0.9"
futures = "0.3.15" futures = "0.3.15"
fxhash = "0.2.1" fxhash = "0.2.1"
gltf = "0.16" gltf = "1.0.0"
image = "0.23.14" image = "0.24"
itertools = "0.10.0" itertools = "0.10.0"
log = "0.4.14" log = "0.4.14"
noise = "0.7.0" noise = "0.7.0"
rayon = "1.5.1" rayon = "1.5.1"
rmp-serde = "0.15.4" rmp-serde = "1.1"
serde = { version = "1.0.126", features = ["derive"] } serde = { version = "1.0.126", features = ["derive"] }
serde_repr = "0.1.7" serde_repr = "0.1.7"
sled = { version = "0.34.6", features = ["compression"] } sled = { version = "0.34.6", features = ["compression"] }
wgpu = "0.8.1" wgpu = "0.13"
winit = { version = "0.25.0" } winit = "0.27"
[profile.release] [profile.release]
debug = true debug = true

View file

@ -9,6 +9,7 @@ pkgs.mkShell {
# Needed by cargo dependencies. # Needed by cargo dependencies.
cmake gcc zlib pkgconfig openssl cmake gcc zlib pkgconfig openssl
fontconfig
# wgpu graphics dependencies # wgpu graphics dependencies
vulkan-loader vulkan-tools vulkan-loader vulkan-tools

View file

@ -20,14 +20,14 @@ impl<I: bytemuck::Pod> GeometryBuffers<I> {
pub fn from_geometry<V: Vertex + bytemuck::Pod>( pub fn from_geometry<V: Vertex + bytemuck::Pod>(
render_context: &RenderContext, render_context: &RenderContext,
geometry: &Geometry<V, I>, geometry: &Geometry<V, I>,
usage: wgpu::BufferUsage, usage: wgpu::BufferUsages,
) -> Self { ) -> Self {
let vertices = render_context let vertices = render_context
.device .device
.create_buffer_init(&BufferInitDescriptor { .create_buffer_init(&BufferInitDescriptor {
label: None, label: None,
contents: bytemuck::cast_slice(&geometry.vertices), contents: bytemuck::cast_slice(&geometry.vertices),
usage: wgpu::BufferUsage::VERTEX | usage, usage: wgpu::BufferUsages::VERTEX | usage,
}); });
let indices = render_context let indices = render_context
@ -35,7 +35,7 @@ impl<I: bytemuck::Pod> GeometryBuffers<I> {
.create_buffer_init(&BufferInitDescriptor { .create_buffer_init(&BufferInitDescriptor {
label: None, label: None,
contents: bytemuck::cast_slice(&geometry.indices), contents: bytemuck::cast_slice(&geometry.indices),
usage: wgpu::BufferUsage::INDEX | usage, usage: wgpu::BufferUsages::INDEX | usage,
}); });
Self { Self {

View file

@ -1,5 +1,4 @@
use cgmath::{ElementWise, Vector4}; use cgmath::{ElementWise, Vector4};
use wgpu::{BufferUsage, RenderPass};
use crate::{ use crate::{
geometry::Geometry, geometry::Geometry,
@ -38,7 +37,7 @@ impl HotbarHud {
geometry_buffers: GeometryBuffers::from_geometry( geometry_buffers: GeometryBuffers::from_geometry(
render_context, render_context,
&Geometry::<HudVertex, _>::default(), &Geometry::<HudVertex, _>::default(),
BufferUsage::empty(), wgpu::BufferUsages::empty(),
), ),
} }
} }
@ -48,7 +47,7 @@ impl HotbarHud {
self.geometry_buffers = GeometryBuffers::from_geometry( self.geometry_buffers = GeometryBuffers::from_geometry(
render_context, render_context,
&self.block_vertices(), &self.block_vertices(),
wgpu::BufferUsage::empty(), wgpu::BufferUsages::empty(),
); );
} }
} }
@ -56,7 +55,7 @@ impl HotbarHud {
pub fn render<'a>( pub fn render<'a>(
&'a self, &'a self,
render_context: &'a RenderContext, render_context: &'a RenderContext,
render_pass: &mut RenderPass<'a>, render_pass: &mut wgpu::RenderPass<'a>,
) -> usize { ) -> usize {
let texture_manager = render_context.texture_manager.as_ref().unwrap(); let texture_manager = render_context.texture_manager.as_ref().unwrap();
@ -76,8 +75,12 @@ impl HotbarHud {
let texture_indices = block.texture_indices(); let texture_indices = block.texture_indices();
let color = block.color(); let color = block.color();
let color_left = color.mul_element_wise(Vector4::new(0.5, 0.5, 0.5, 1.0)).into(); let color_left = color
let color_front = color.mul_element_wise(Vector4::new(0.15, 0.15, 0.15, 1.0)).into(); .mul_element_wise(Vector4::new(0.5, 0.5, 0.5, 1.0))
.into();
let color_front = color
.mul_element_wise(Vector4::new(0.15, 0.15, 0.15, 1.0))
.into();
let color_top = color.into(); let color_top = color.into();
vertices.extend([ vertices.extend([
@ -106,7 +109,6 @@ impl HotbarHud {
texture_index: texture_indices.0 as i32, texture_index: texture_indices.0 as i32,
color: color_left, color: color_left,
}, },
// Front face // Front face
HudVertex { HudVertex {
position: [UI_SCALE_X * (x + 19.0), -1.0 + UI_SCALE_Y * 15.5], position: [UI_SCALE_X * (x + 19.0), -1.0 + UI_SCALE_Y * 15.5],
@ -132,7 +134,6 @@ impl HotbarHud {
texture_index: texture_indices.3 as i32, texture_index: texture_indices.3 as i32,
color: color_front, color: color_front,
}, },
// Top face // Top face
HudVertex { HudVertex {
position: [UI_SCALE_X * (x + 19.0), -1.0 + UI_SCALE_Y * 15.5], position: [UI_SCALE_X * (x + 19.0), -1.0 + UI_SCALE_Y * 15.5],

View file

@ -1,4 +1,4 @@
use wgpu::{CommandEncoder, RenderPipeline, SwapChainTexture}; use wgpu::{CommandEncoder, RenderPipeline};
use crate::{ use crate::{
render_context::RenderContext, render_context::RenderContext,
@ -44,16 +44,13 @@ impl Hud {
entries: &[ entries: &[
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Sampler { ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 1, binding: 1,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture { ty: wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Float { filterable: true }, sample_type: wgpu::TextureSampleType::Float { filterable: true },
view_dimension: wgpu::TextureViewDimension::D2Array, view_dimension: wgpu::TextureViewDimension::D2Array,
@ -66,9 +63,8 @@ impl Hud {
let module = &render_context let module = &render_context
.device .device
.create_shader_module(&wgpu::ShaderModuleDescriptor { .create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("UI shader"), label: Some("UI shader"),
flags: wgpu::ShaderFlags::all(),
source: wgpu::ShaderSource::Wgsl(include_str!("../shaders/ui.wgsl").into()), source: wgpu::ShaderSource::Wgsl(include_str!("../shaders/ui.wgsl").into()),
}); });
@ -94,23 +90,24 @@ impl Hud {
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module, module,
entry_point: "main", entry_point: "main",
targets: &[wgpu::ColorTargetState { targets: &[Some(wgpu::ColorTargetState {
format: render_context.swap_chain_descriptor.format, format: render_context.swap_chain_descriptor.format,
blend: Some(wgpu::BlendState::ALPHA_BLENDING), blend: Some(wgpu::BlendState::ALPHA_BLENDING),
write_mask: wgpu::ColorWrite::ALL, write_mask: wgpu::ColorWrites::ALL,
}], })],
}), }),
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None, strip_index_format: None,
front_face: wgpu::FrontFace::Ccw, front_face: wgpu::FrontFace::Ccw,
cull_mode: None, cull_mode: None,
clamp_depth: false, unclipped_depth: false,
polygon_mode: wgpu::PolygonMode::Fill, polygon_mode: wgpu::PolygonMode::Fill,
conservative: false, conservative: false,
}, },
depth_stencil: None, depth_stencil: None,
multisample: Default::default(), multisample: Default::default(),
multiview: None,
}) })
} }
@ -130,14 +127,14 @@ impl Hud {
frame: &SwapChainTexture, frame: &SwapChainTexture,
) -> usize { ) -> usize {
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &frame.view, view: &frame.view,
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
load: wgpu::LoadOp::Load, load: wgpu::LoadOp::Load,
store: true, store: true,
}, },
}], })],
..Default::default() ..Default::default()
}); });
render_pass.set_pipeline(&self.pipeline); render_pass.set_pipeline(&self.pipeline);

View file

@ -1,5 +1,4 @@
// TODO Might want to move the hotbar outside // TODO Might want to move the hotbar outside
use wgpu::{BindGroup, BufferUsage, RenderPass};
use crate::{ use crate::{
geometry::Geometry, geometry::Geometry,
@ -11,7 +10,7 @@ use crate::{
}; };
pub struct WidgetsHud { pub struct WidgetsHud {
texture_bind_group: BindGroup, texture_bind_group: wgpu::BindGroup,
geometry_buffers: GeometryBuffers<u16>, geometry_buffers: GeometryBuffers<u16>,
pub hotbar_cursor_position: usize, pub hotbar_cursor_position: usize,
} }
@ -25,7 +24,7 @@ impl WidgetsHud {
indices: INDICES.to_vec(), indices: INDICES.to_vec(),
}; };
let geometry_buffers = let geometry_buffers =
GeometryBuffers::from_geometry(render_context, &geometry, BufferUsage::COPY_DST); GeometryBuffers::from_geometry(render_context, &geometry, wgpu::BufferUsages::COPY_DST);
Self { Self {
texture_bind_group, texture_bind_group,
@ -58,16 +57,13 @@ impl WidgetsHud {
entries: &[ entries: &[
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Sampler { ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 1, binding: 1,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture { ty: wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Float { filterable: true }, sample_type: wgpu::TextureSampleType::Float { filterable: true },
view_dimension: wgpu::TextureViewDimension::D2Array, view_dimension: wgpu::TextureViewDimension::D2Array,
@ -129,7 +125,7 @@ impl WidgetsHud {
); );
} }
pub fn render<'a>(&'a self, render_pass: &mut RenderPass<'a>) -> usize { pub fn render<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) -> usize {
// Render the HUD elements // Render the HUD elements
self.geometry_buffers.apply_buffers(render_pass); self.geometry_buffers.apply_buffers(render_pass);
render_pass.set_bind_group(0, &self.texture_bind_group, &[]); render_pass.set_bind_group(0, &self.texture_bind_group, &[]);

View file

@ -15,12 +15,11 @@ mod view;
mod world; mod world;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use wgpu::SwapChainError;
use winit::{ use winit::{
dpi::{PhysicalSize, Size}, dpi::{PhysicalSize, Size},
event::{ElementState, Event, KeyboardInput, MouseButton, VirtualKeyCode, WindowEvent}, event::{ElementState, Event, KeyboardInput, MouseButton, VirtualKeyCode, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
window::{Window, WindowBuilder}, window::{CursorGrabMode, Window, WindowBuilder},
}; };
use crate::state::State; use crate::state::State;
@ -41,7 +40,7 @@ fn handle_window_event(
}, },
.. ..
} => { } => {
let _ = window.set_cursor_grab(false); let _ = window.set_cursor_grab(CursorGrabMode::None);
window.set_cursor_visible(true); window.set_cursor_visible(true);
state.mouse_grabbed = false; state.mouse_grabbed = false;
None None
@ -63,7 +62,7 @@ fn handle_window_event(
&& *button == MouseButton::Left && *button == MouseButton::Left
&& *mouse_state == ElementState::Pressed && *mouse_state == ElementState::Pressed
{ {
let _ = window.set_cursor_grab(true); let _ = window.set_cursor_grab(CursorGrabMode::Locked);
window.set_cursor_visible(false); window.set_cursor_visible(false);
state.mouse_grabbed = true; state.mouse_grabbed = true;
} else { } else {
@ -72,7 +71,7 @@ fn handle_window_event(
None None
} }
WindowEvent::Focused(false) => { WindowEvent::Focused(false) => {
let _ = window.set_cursor_grab(false); let _ = window.set_cursor_grab(CursorGrabMode::Locked);
window.set_cursor_visible(true); window.set_cursor_visible(true);
state.mouse_grabbed = false; state.mouse_grabbed = false;
None None

View file

@ -30,12 +30,13 @@ impl State {
async fn create_render_device( async fn create_render_device(
window: &Window, window: &Window,
) -> (wgpu::Surface, wgpu::Adapter, wgpu::Device, wgpu::Queue) { ) -> (wgpu::Surface, wgpu::Adapter, wgpu::Device, wgpu::Queue) {
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY);
let render_surface = unsafe { instance.create_surface(window) }; let render_surface = unsafe { instance.create_surface(window) };
let adapter = instance let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions { .request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance, power_preference: wgpu::PowerPreference::HighPerformance,
compatible_surface: Some(&render_surface), compatible_surface: Some(&render_surface),
force_fallback_adapter: false,
}) })
.await .await
.unwrap(); .unwrap();
@ -45,7 +46,7 @@ impl State {
.request_device( .request_device(
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
label: Some("render_device"), label: Some("render_device"),
features: wgpu::Features::SAMPLED_TEXTURE_BINDING_ARRAY, features: wgpu::Features::TEXTURE_BINDING_ARRAY,
limits: wgpu::Limits::default(), limits: wgpu::Limits::default(),
}, },
None, None,
@ -65,7 +66,7 @@ impl State {
let size = window.inner_size(); let size = window.inner_size();
let swap_chain_descriptor = wgpu::SwapChainDescriptor { let swap_chain_descriptor = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::RENDER_ATTACHMENT, usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: adapter format: adapter
.get_swap_chain_preferred_format(render_surface) .get_swap_chain_preferred_format(render_surface)
.unwrap(), .unwrap(),

View file

@ -50,16 +50,13 @@ impl TextRenderer {
entries: &[ entries: &[
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Sampler { ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 1, binding: 1,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture { ty: wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Float { filterable: true }, sample_type: wgpu::TextureSampleType::Float { filterable: true },
view_dimension: wgpu::TextureViewDimension::D2Array, view_dimension: wgpu::TextureViewDimension::D2Array,
@ -162,6 +159,6 @@ impl TextRenderer {
string: &str, string: &str,
) -> GeometryBuffers<u16> { ) -> GeometryBuffers<u16> {
let geometry = self.string_geometry(x, y, string); let geometry = self.string_geometry(x, y, string);
GeometryBuffers::from_geometry(render_context, &geometry, wgpu::BufferUsage::empty()) GeometryBuffers::from_geometry(render_context, &geometry, wgpu::BufferUsages::empty())
} }
} }

View file

@ -32,7 +32,7 @@ impl Texture {
sample_count: 1, sample_count: 1,
dimension: wgpu::TextureDimension::D2, dimension: wgpu::TextureDimension::D2,
format: Self::DEPTH_FORMAT, format: Self::DEPTH_FORMAT,
usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
}); });
let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
@ -80,9 +80,7 @@ impl Texture {
sample_count: 1, sample_count: 1,
dimension: wgpu::TextureDimension::D2, dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb, format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsage::SAMPLED usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::COPY_SRC,
| wgpu::TextureUsage::COPY_DST
| wgpu::TextureUsage::COPY_SRC,
}); });
let stride = 4 * rgba.width(); let stride = 4 * rgba.width();
@ -92,6 +90,7 @@ impl Texture {
texture: &texture, texture: &texture,
mip_level: 0, mip_level: 0,
origin: wgpu::Origin3d::ZERO, origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
}, },
&rgba.as_bytes()[offset..offset + (size.y * stride) as usize], &rgba.as_bytes()[offset..offset + (size.y * stride) as usize],
wgpu::ImageDataLayout { wgpu::ImageDataLayout {
@ -182,16 +181,13 @@ impl TextureManager {
entries: &[ entries: &[
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Sampler { ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 1, binding: 1,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture { ty: wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Float { filterable: true }, sample_type: wgpu::TextureSampleType::Float { filterable: true },
view_dimension: wgpu::TextureViewDimension::D2Array, view_dimension: wgpu::TextureViewDimension::D2Array,
@ -252,7 +248,7 @@ impl TextureManager {
sample_count: 1, sample_count: 1,
dimension: wgpu::TextureDimension::D2, dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb, format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, usage: wgpu::TextureUsages::COPY_DST,
}); });
let mut encoder = let mut encoder =
@ -268,6 +264,7 @@ impl TextureManager {
texture: &texture.texture, texture: &texture.texture,
mip_level: 0, mip_level: 0,
origin: Origin3d::ZERO, origin: Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
}, },
wgpu::ImageCopyTexture { wgpu::ImageCopyTexture {
texture: &texture_array, texture: &texture_array,
@ -277,6 +274,7 @@ impl TextureManager {
y: 0, y: 0,
z: i as u32, z: i as u32,
}, },
aspect: wgpu::TextureAspect::All,
}, },
wgpu::Extent3d { wgpu::Extent3d {
width: 16, width: 16,

View file

@ -31,7 +31,7 @@ impl Vertex for HudVertex {
fn descriptor() -> wgpu::VertexBufferLayout<'static> { fn descriptor() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout { wgpu::VertexBufferLayout {
array_stride: size_of::<Self>() as wgpu::BufferAddress, array_stride: size_of::<Self>() as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex, step_mode: wgpu::VertexStepMode::Vertex,
attributes: HUD_VERTEX_ATTRIBUTES, attributes: HUD_VERTEX_ATTRIBUTES,
} }
} }
@ -66,7 +66,7 @@ impl Vertex for BlockVertex {
fn descriptor() -> wgpu::VertexBufferLayout<'static> { fn descriptor() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout { wgpu::VertexBufferLayout {
array_stride: size_of::<Self>() as wgpu::BufferAddress, array_stride: size_of::<Self>() as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex, step_mode: wgpu::VertexStepMode::Vertex,
attributes: BLOCK_VERTEX_ATTRIBUTES, attributes: BLOCK_VERTEX_ATTRIBUTES,
} }
} }

View file

@ -1,7 +1,7 @@
use std::mem::size_of; use std::mem::size_of;
use cgmath::{EuclideanSpace, Matrix4, Point3, SquareMatrix, Vector4, Zero}; use cgmath::{EuclideanSpace, Matrix4, Point3, SquareMatrix, Vector4, Zero};
use wgpu::{BindGroup, BindGroupLayout, Buffer, BufferDescriptor, BufferUsage}; use wgpu::{BindGroup, BindGroupLayout, Buffer, BufferDescriptor, BufferUsages};
use crate::{ use crate::{
aabb::Aabb, aabb::Aabb,
@ -48,7 +48,7 @@ impl View {
let buffer = render_context.device.create_buffer(&BufferDescriptor { let buffer = render_context.device.create_buffer(&BufferDescriptor {
label: Some("view buffer"), label: Some("view buffer"),
size: size_of::<ViewRaw>() as u64, size: size_of::<ViewRaw>() as u64,
usage: BufferUsage::UNIFORM | BufferUsage::COPY_DST, usage: BufferUsages::UNIFORM | BufferUsages::COPY_DST,
mapped_at_creation: false, mapped_at_creation: false,
}); });
@ -58,7 +58,7 @@ impl View {
.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { .create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[wgpu::BindGroupLayoutEntry { entries: &[wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Buffer { ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform, ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false, has_dynamic_offset: false,

View file

@ -22,7 +22,6 @@ use serde::{
ser::SerializeSeq, ser::SerializeSeq,
Deserialize, Serialize, Serializer, Deserialize, Serialize, Serializer,
}; };
use wgpu::{BufferUsage, RenderPass};
pub const CHUNK_SIZE: usize = 32; pub const CHUNK_SIZE: usize = 32;
pub const CHUNK_ISIZE: isize = CHUNK_SIZE as isize; pub const CHUNK_ISIZE: isize = CHUNK_SIZE as isize;
@ -98,7 +97,7 @@ impl<'de> Deserialize<'de> for Chunk {
impl Chunk { impl Chunk {
pub fn render<'a>( pub fn render<'a>(
&'a self, &'a self,
render_pass: &mut RenderPass<'a>, render_pass: &mut wgpu::RenderPass<'a>,
position: &Point3<isize>, position: &Point3<isize>,
view: &View, view: &View,
) -> usize { ) -> usize {
@ -418,7 +417,7 @@ impl Chunk {
self.buffers = Some(GeometryBuffers::from_geometry( self.buffers = Some(GeometryBuffers::from_geometry(
render_context, render_context,
&Self::quads_to_geometry(quads), &Self::quads_to_geometry(quads),
BufferUsage::empty(), wgpu::BufferUsages::empty(),
)); ));
self.update_fullness(); self.update_fullness();

View file

@ -26,7 +26,7 @@ use cgmath::{EuclideanSpace, InnerSpace, Point3, Vector3};
use fxhash::FxHashMap; use fxhash::FxHashMap;
use wgpu::{ use wgpu::{
util::{BufferInitDescriptor, DeviceExt}, util::{BufferInitDescriptor, DeviceExt},
BindGroup, Buffer, CommandEncoder, RenderPipeline, SwapChainTexture, BindGroup, Buffer, CommandEncoder, RenderPipeline,
}; };
pub struct World { pub struct World {
@ -186,7 +186,7 @@ impl World {
let mut render_pass = render_encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let mut render_pass = render_encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("render_pass"), label: Some("render_pass"),
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &frame.view, view: &frame.view,
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
@ -198,7 +198,7 @@ impl World {
}), }),
store: true, store: true,
}, },
}], })],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view, view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations { depth_ops: Some(wgpu::Operations {
@ -244,7 +244,7 @@ impl World {
.create_buffer_init(&BufferInitDescriptor { .create_buffer_init(&BufferInitDescriptor {
label: Some("time_buffer"), label: Some("time_buffer"),
contents: bytemuck::cast_slice(&[time]), contents: bytemuck::cast_slice(&[time]),
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
}); });
let time_bind_group_layout = let time_bind_group_layout =
@ -253,7 +253,7 @@ impl World {
.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { .create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[wgpu::BindGroupLayoutEntry { entries: &[wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Buffer { ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform, ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false, has_dynamic_offset: false,
@ -289,13 +289,12 @@ impl World {
], ],
}); });
let shader = render_context.device.create_shader_module( let shader = render_context
&(wgpu::ShaderModuleDescriptor { .device
.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("shader"), label: Some("shader"),
flags: wgpu::ShaderFlags::all(),
source: wgpu::ShaderSource::Wgsl(include_str!("../shaders/world.wgsl").into()), source: wgpu::ShaderSource::Wgsl(include_str!("../shaders/world.wgsl").into()),
}), });
);
let render_pipeline = let render_pipeline =
render_context render_context
@ -311,14 +310,14 @@ impl World {
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &shader, module: &shader,
entry_point: "main", entry_point: "main",
targets: &[wgpu::ColorTargetState { targets: &[Some(wgpu::ColorTargetState {
format: render_context.swap_chain_descriptor.format, format: render_context.swap_chain_descriptor.format,
blend: Some(wgpu::BlendState { blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE,
}), }),
write_mask: wgpu::ColorWrite::ALL, write_mask: wgpu::ColorWrites::ALL,
}], })],
}), }),
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
cull_mode: Some(wgpu::Face::Back), cull_mode: Some(wgpu::Face::Back),
@ -333,6 +332,7 @@ impl World {
bias: wgpu::DepthBiasState::default(), bias: wgpu::DepthBiasState::default(),
}), }),
multisample: wgpu::MultisampleState::default(), multisample: wgpu::MultisampleState::default(),
multiview: None,
}); });
let depth_texture = Texture::create_depth_texture(render_context, "depth_texture"); let depth_texture = Texture::create_depth_texture(render_context, "depth_texture");

View file

@ -2,7 +2,6 @@ extern crate gltf;
extern crate wgpu; extern crate wgpu;
use cgmath::Vector3; use cgmath::Vector3;
use wgpu::{BufferUsage, RenderPass};
use crate::{ use crate::{
geometry::Geometry, geometry_buffers::GeometryBuffers, render_context::RenderContext, geometry::Geometry, geometry_buffers::GeometryBuffers, render_context::RenderContext,
@ -68,11 +67,11 @@ impl Npc {
self.geometry_buffers = Some(GeometryBuffers::from_geometry( self.geometry_buffers = Some(GeometryBuffers::from_geometry(
render_context, render_context,
&self.geometry, &self.geometry,
BufferUsage::empty(), wgpu::BufferUsages::empty(),
)); ));
} }
pub fn render<'a>(&'a self, render_pass: &mut RenderPass<'a>) -> usize { pub fn render<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) -> usize {
let buffers = self.geometry_buffers.as_ref().unwrap(); let buffers = self.geometry_buffers.as_ref().unwrap();
buffers.apply_buffers(render_pass); buffers.apply_buffers(render_pass);
buffers.draw_indexed(render_pass) buffers.draw_indexed(render_pass)