Skip to content

Commit

Permalink
tech: Upgrade winit, wgpu, bytemuck and serde (#112)
Browse files Browse the repository at this point in the history
FIXES #96
FIXES #95
FIXES #94
  • Loading branch information
suspistew authored Jun 3, 2021
1 parent aeb0f13 commit 07f7441
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ parallel = ["legion/parallel"]
legion = { version = "0.4", default-features = false, features = ["codegen"] }

# window & rendering
winit = "0.24.0"
wgpu = "0.7.0"
winit = "0.25"
wgpu = "0.8"
futures = "0.3"

# maths
ultraviolet = "0.8"

# serialization
serde = { version = "1.0.124", features = ["derive"] }
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
bytemuck = { version = "1.4", features = ["derive"] }
bytemuck = { version = "1.5", features = ["derive"] }
image = { version = "0.23", default-features = false, features = ["png"] }

# logging
Expand All @@ -45,7 +45,7 @@ deflate = { opt-level = 3 }

[build-dependencies]
anyhow = "1.0"
fs_extra = "1.1"
fs_extra = "1.2"
glob = "0.3"
shaderc = "0.7"

Expand Down
1 change: 1 addition & 0 deletions src/config/window_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl Into<WindowBuilder> for WindowConfig {
maximized: self.maximized,
resizable: self.resizable,
transparent: self.transparent,
position: None
};
builder
}
Expand Down
8 changes: 4 additions & 4 deletions src/rendering/bidimensional/gl_representations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ impl ColoredGlVertex {
wgpu::VertexAttribute {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
},
wgpu::VertexAttribute {
offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
shader_location: 1,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
},
],
}
Expand All @@ -104,12 +104,12 @@ impl TexturedGlVertex {
wgpu::VertexAttribute {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
},
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
shader_location: 1,
format: wgpu::VertexFormat::Float2,
format: wgpu::VertexFormat::Float32x2,
},
],
}
Expand Down
28 changes: 12 additions & 16 deletions src/rendering/bidimensional/scion2d.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use std::{collections::HashMap, ops::Range, path::Path};

use legion::{storage::Component, Entity, IntoQuery, Resources, World};
use wgpu::{
util::{BufferInitDescriptor, DeviceExt},
BindGroup, BindGroupLayout, Buffer, CommandEncoder, Device, Queue,
RenderPassColorAttachmentDescriptor, RenderPipeline, SwapChainDescriptor, SwapChainTexture,
};
use wgpu::{util::{BufferInitDescriptor, DeviceExt}, BindGroup, BindGroupLayout, Buffer, CommandEncoder, Device, Queue, RenderPipeline, SwapChainDescriptor, SwapChainTexture, RenderPassColorAttachment};

use crate::{
core::components::{
Expand Down Expand Up @@ -114,7 +110,7 @@ fn load_texture_to_queue(
let texture_size = wgpu::Extent3d {
width: texture.width as u32,
height: texture.height as u32,
depth: 1,
depth_or_array_layers: 1
};

let diffuse_texture = device.create_texture(&wgpu::TextureDescriptor {
Expand All @@ -127,16 +123,16 @@ fn load_texture_to_queue(
label: Some("diffuse_texture"),
});
queue.write_texture(
wgpu::TextureCopyView {
wgpu::ImageCopyTexture {
texture: &diffuse_texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
},
&*texture.bytes,
wgpu::TextureDataLayout {
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: (4 * texture.width) as u32,
rows_per_image: texture.height as u32,
bytes_per_row: std::num::NonZeroU32::new((4 * texture.width) as u32),
rows_per_image: std::num::NonZeroU32::new((texture.height as u32)),
},
texture_size,
);
Expand Down Expand Up @@ -242,9 +238,9 @@ fn create_transform_uniform_bind_group(
)
}

fn get_default_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAttachmentDescriptor {
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
fn get_default_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAttachment {
RenderPassColorAttachment {
view: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
Expand All @@ -258,9 +254,9 @@ fn get_default_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAtta
}
}

fn get_no_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAttachmentDescriptor {
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
fn get_no_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAttachment {
RenderPassColorAttachment {
view: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/renderer_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl RendererState {

let sc_desc = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
format: adapter.get_swap_chain_preferred_format(&surface),
format: adapter.get_swap_chain_preferred_format(&surface).unwrap(),
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
Expand Down
32 changes: 18 additions & 14 deletions src/rendering/shaders/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use wgpu::{
BindGroupLayout, BlendFactor, BlendOperation, Device, RenderPipeline, SwapChainDescriptor,
};
use wgpu::{BindGroupLayout, BlendFactor, BlendOperation, Device, RenderPipeline, SwapChainDescriptor, BlendComponent};

use crate::rendering::bidimensional::gl_representations::TexturedGlVertex;

Expand Down Expand Up @@ -32,25 +30,31 @@ pub fn pipeline(
entry_point: "main",
targets: &[wgpu::ColorTargetState {
format: sc_desc.format,
alpha_blend: wgpu::BlendState {
src_factor: BlendFactor::One,
dst_factor: BlendFactor::One,
operation: BlendOperation::Add,
},
color_blend: wgpu::BlendState {
src_factor: BlendFactor::SrcAlpha,
dst_factor: BlendFactor::OneMinusSrcAlpha,
operation: BlendOperation::Add,
},
write_mask: wgpu::ColorWrite::ALL,
blend: Some(
wgpu::BlendState {
color: BlendComponent {
src_factor: BlendFactor::SrcAlpha,
dst_factor: BlendFactor::OneMinusSrcAlpha,
operation: BlendOperation::Add,
},
alpha: BlendComponent {
src_factor: BlendFactor::One,
dst_factor: BlendFactor::One,
operation: BlendOperation::Add,
},
}
),
}],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None,
front_face: wgpu::FrontFace::Ccw,
cull_mode: wgpu::CullMode::Back,
cull_mode: Some(wgpu::Face::Back),
clamp_depth: false,
polygon_mode: wgpu::PolygonMode::Fill,
conservative: false,
},
depth_stencil: None,
multisample: wgpu::MultisampleState {
Expand Down

0 comments on commit 07f7441

Please # to comment.