migrated imgui showcase

pull/140/head
Ben Hansen 4 years ago
parent 87d0a97404
commit fb73851e5d

87
Cargo.lock generated

@ -353,6 +353,12 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "chlorine"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd650552110e39b7c5058986cf177decd3365841836578ac50a286094eac0be6"
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.19" version = "0.4.19"
@ -485,7 +491,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -838,7 +844,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
dependencies = [ dependencies = [
"atty", "atty",
"humantime", "humantime 1.3.0",
"log",
"regex",
"termcolor",
]
[[package]]
name = "env_logger"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f"
dependencies = [
"atty",
"humantime 2.1.0",
"log", "log",
"regex", "regex",
"termcolor", "termcolor",
@ -899,8 +918,8 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.18.0",
"env_logger", "env_logger 0.8.3",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -912,7 +931,7 @@ dependencies = [
"tobj 2.0.2", "tobj 2.0.2",
"wgpu 0.7.0", "wgpu 0.7.0",
"wgpu-subscriber", "wgpu-subscriber",
"winit 0.23.0", "winit 0.24.0",
] ]
[[package]] [[package]]
@ -1517,7 +1536,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"framework", "framework",
"fs_extra", "fs_extra",
"futures", "futures",
@ -1677,6 +1696,12 @@ dependencies = [
"quick-error", "quick-error",
] ]
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "ident_case" name = "ident_case"
version = "1.0.1" version = "1.0.1"
@ -1703,13 +1728,12 @@ dependencies = [
[[package]] [[package]]
name = "imgui" name = "imgui"
version = "0.6.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a714f73a3f08446d92c47a38b536a03deba500aa6bb6fa805e8c0b6f90945e4f" checksum = "24cfcf6e3326886321c5d637caf1ce217006651059015fae372b1c49c0e722b2"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"imgui-sys", "imgui-sys",
"lazy_static",
"parking_lot 0.11.0", "parking_lot 0.11.0",
] ]
@ -1728,34 +1752,35 @@ dependencies = [
[[package]] [[package]]
name = "imgui-sys" name = "imgui-sys"
version = "0.6.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0522b693da8a64322afbb32c63c04f39d9b9435cc75199d630207eee48886fc1" checksum = "85ca00be6b78bf02b57e91468cf19d08dfcc11d0fb3c2f3dc491c29404d8d330"
dependencies = [ dependencies = [
"cc", "cc",
"chlorine",
] ]
[[package]] [[package]]
name = "imgui-wgpu" name = "imgui-wgpu"
version = "0.12.0" version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8017f74f8880049c1c3fc055868486a610178ab93ad18eadaf5b0bb52f738365" checksum = "79d5d73b68effcb4bcb89048e8c437e01c6d5675247d664188c584ce4d6d9696"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"imgui", "imgui",
"log", "log",
"smallvec", "smallvec",
"wgpu 0.6.0", "wgpu 0.7.0",
] ]
[[package]] [[package]]
name = "imgui-winit-support" name = "imgui-winit-support"
version = "0.6.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e0fc247afc385ed9cd26860cdb7fae988d5c7e2ad1d70c70aef728ce9b78e85" checksum = "d632440e05c964e8a7f00f2659c4f71c97897d8c38a77a0c2dc1f3fe8d632208"
dependencies = [ dependencies = [
"imgui", "imgui",
"winit 0.23.0", "winit 0.24.0",
] ]
[[package]] [[package]]
@ -2522,7 +2547,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"failure", "failure",
"fs_extra", "fs_extra",
"futures", "futures",
@ -3451,7 +3476,7 @@ name = "tutorial1-window"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"futures", "futures",
"image", "image",
"log", "log",
@ -3467,7 +3492,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3486,7 +3511,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3505,7 +3530,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3524,7 +3549,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3542,7 +3567,7 @@ name = "tutorial2-swapchain"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"futures", "futures",
"image", "image",
"log", "log",
@ -3557,7 +3582,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3575,7 +3600,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3593,7 +3618,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3611,7 +3636,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3629,7 +3654,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3647,7 +3672,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",
@ -3665,7 +3690,7 @@ dependencies = [
"anyhow", "anyhow",
"bytemuck", "bytemuck",
"cgmath 0.17.0", "cgmath 0.17.0",
"env_logger", "env_logger 0.7.1",
"fs_extra", "fs_extra",
"futures", "futures",
"glob", "glob",

@ -8,15 +8,15 @@ edition = "2018"
anyhow = "1.0" anyhow = "1.0"
thiserror = "1.0" thiserror = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] } bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.17" cgmath = "0.18"
env_logger = "0.7" env_logger = "0.8"
futures = "0.3" futures = "0.3"
image = "0.23" image = "0.23"
log = "0.4" log = "0.4"
tobj = "2.0" tobj = "2.0"
wgpu = "0.7" wgpu = "0.7"
wgpu-subscriber = "0.1" wgpu-subscriber = "0.1"
winit = "0.23" winit = "0.24"
[build-dependencies] [build-dependencies]
anyhow = "1.0" anyhow = "1.0"

@ -163,7 +163,7 @@ impl UniformBinding {
layout: &layout, layout: &layout,
entries: &[wgpu::BindGroupEntry { entries: &[wgpu::BindGroupEntry {
binding: 0, binding: 0,
resource: wgpu::BindingResource::Buffer(uniforms.buffer.slice(..)), resource: uniforms.buffer.as_entire_binding(),
}], }],
label: Some("UniformBinding::bind_group"), label: Some("UniformBinding::bind_group"),
}); });
@ -176,7 +176,7 @@ impl UniformBinding {
layout: &self.layout, layout: &self.layout,
entries: &[wgpu::BindGroupEntry { entries: &[wgpu::BindGroupEntry {
binding: 0, binding: 0,
resource: wgpu::BindingResource::Buffer(uniforms.buffer.slice(..)), resource: uniforms.buffer.as_entire_binding(),
}], }],
label: Some("UniformBinding::bind_group"), label: Some("UniformBinding::bind_group"),
}); });

@ -11,7 +11,7 @@ pub struct RenderPipelineBuilder<'a> {
depth_bias_slope_scale: f32, depth_bias_slope_scale: f32,
depth_bias_clamp: f32, depth_bias_clamp: f32,
primitive_topology: wgpu::PrimitiveTopology, primitive_topology: wgpu::PrimitiveTopology,
color_states: Vec<wgpu::ColorStateDescriptor>, color_states: Vec<wgpu::ColorTargetState>,
depth_stencil: Option<wgpu::DepthStencilState>, depth_stencil: Option<wgpu::DepthStencilState>,
index_format: wgpu::IndexFormat, index_format: wgpu::IndexFormat,
vertex_buffers: Vec<wgpu::VertexBufferLayout<'a>>, vertex_buffers: Vec<wgpu::VertexBufferLayout<'a>>,
@ -31,18 +31,14 @@ impl<'a> RenderPipelineBuilder<'a> {
depth_bias: 0, depth_bias: 0,
depth_bias_slope_scale: 0.0, depth_bias_slope_scale: 0.0,
depth_bias_clamp: 0.0, depth_bias_clamp: 0.0,
primitive: wgpu::PrimitiveState { primitive_topology: wgpu::PrimitiveTopology::TriangleList,
topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None,
front_face: wgpu::FrontFace::Ccw,
cull_mode: wgpu::CullMode::Back,
// Setting this to anything other than Fill requires Features::NON_FILL_POLYGON_MODE
polygon_mode: wgpu::PolygonMode::Fill,
},
color_states: Vec::new(), color_states: Vec::new(),
depth_stencil: None, depth_stencil: None,
index_format: wgpu::IndexFormat::Uint32, index_format: wgpu::IndexFormat::Uint32,
vertex_buffers: Vec::new(), vertex_buffers: Vec::new(),
sample_count: 1,
sample_mask: !0,
alpha_to_coverage_enabled: false,
} }
} }
@ -97,17 +93,17 @@ impl<'a> RenderPipelineBuilder<'a> {
self self
} }
pub fn color_state(&mut self, cs: wgpu::ColorStateDescriptor) -> &mut Self { pub fn color_state(&mut self, cs: wgpu::ColorTargetState) -> &mut Self {
self.color_states.push(cs); self.color_states.push(cs);
self self
} }
/// Helper method for [RenderPipelineBuilder::color_state] /// Helper method for [RenderPipelineBuilder::color_state]
pub fn color_solid(&mut self, format: wgpu::TextureFormat) -> &mut Self { pub fn color_solid(&mut self, format: wgpu::TextureFormat) -> &mut Self {
self.color_state(wgpu::ColorStateDescriptor { self.color_state(wgpu::ColorTargetState {
format, format,
alpha_blend: wgpu::BlendDescriptor::REPLACE, alpha_blend: wgpu::BlendState::REPLACE,
color_blend: wgpu::BlendDescriptor::REPLACE, color_blend: wgpu::BlendState::REPLACE,
write_mask: wgpu::ColorWrite::ALL, write_mask: wgpu::ColorWrite::ALL,
}) })
} }
@ -129,6 +125,9 @@ impl<'a> RenderPipelineBuilder<'a> {
depth_write_enabled, depth_write_enabled,
depth_compare, depth_compare,
stencil: Default::default(), stencil: Default::default(),
// Setting this to true requires Features::DEPTH_CLAMPING
clamp_depth: false,
bias: wgpu::DepthBiasState::default(),
}) })
} }
@ -212,29 +211,33 @@ impl<'a> RenderPipelineBuilder<'a> {
vertex: wgpu::VertexState { vertex: wgpu::VertexState {
module: &vs, module: &vs,
entry_point: "main", entry_point: "main",
buffers: &self.vertex_buffers,
}, },
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &fs, module: &fs,
entry_point: "main", entry_point: "main",
targets: &self.color_states,
}), }),
rasterization_state: Some(wgpu::RasterizationStateDescriptor { primitive: wgpu::PrimitiveState {
topology: self.primitive_topology,
front_face: self.front_face, front_face: self.front_face,
cull_mode: self.cull_mode, cull_mode: self.cull_mode,
depth_bias: self.depth_bias, strip_index_format: None,
depth_bias_slope_scale: self.depth_bias_slope_scale, polygon_mode: wgpu::PolygonMode::Fill,
depth_bias_clamp: self.depth_bias_clamp, },
clamp_depth: false,
}),
primitive_topology: self.primitive_topology,
color_states: &self.color_states,
depth_stencil: self.depth_stencil.clone(), depth_stencil: self.depth_stencil.clone(),
vertex_state: wgpu::VertexStateDescriptor { multisample: wgpu::MultisampleState {
index_format: self.index_format, count: 1,
vertex_buffers: &self.vertex_buffers, mask: !0,
alpha_to_coverage_enabled: false,
}, },
sample_count: self.sample_count, // vertex_state: wgpu::VertexStateDescriptor {
sample_mask: self.sample_mask, // index_format: self.index_format,
alpha_to_coverage_enabled: self.alpha_to_coverage_enabled, // vertex_buffers: &self.vertex_buffers,
// },
// sample_count: self.sample_count,
// sample_mask: self.sample_mask,
// alpha_to_coverage_enabled: self.alpha_to_coverage_enabled,
}); });
Ok(pipeline) Ok(pipeline)
} }
@ -244,5 +247,5 @@ fn create_shader_module(
device: &wgpu::Device, device: &wgpu::Device,
spirv: wgpu::ShaderModuleDescriptor, spirv: wgpu::ShaderModuleDescriptor,
) -> wgpu::ShaderModule { ) -> wgpu::ShaderModule {
device.create_shader_module(spirv) device.create_shader_module(&spirv)
} }

@ -79,6 +79,7 @@ impl ShaderCanvas {
); );
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Shader Canvas Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: frame, attachment: frame,
resolve_target: None, resolve_target: None,
@ -189,12 +190,12 @@ impl<'a> ShaderCanvasBuilder<'a> {
label: self.label, label: self.label,
entries: &[wgpu::BindGroupEntry { entries: &[wgpu::BindGroupEntry {
binding: 0, binding: 0,
resource: wgpu::BindingResource::Buffer(simulation_data_buffer.slice(..)), resource: simulation_data_buffer.as_entire_binding(),
}], }],
}); });
let vert_module = device.create_shader_module(vert_code); let vert_module = device.create_shader_module(&vert_code);
let frag_module = device.create_shader_module(frag_code); let frag_module = device.create_shader_module(&frag_code);
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: self.label, label: self.label,
@ -207,18 +208,18 @@ impl<'a> ShaderCanvasBuilder<'a> {
vertex: wgpu::VertexState { vertex: wgpu::VertexState {
entry_point: "main", entry_point: "main",
module: &vert_module, module: &vert_module,
buffers: &[],
}, },
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
entry_point: "main", entry_point: "main",
module: &frag_module, module: &frag_module,
targets: &[wgpu::ColorTargetState {
format: display_format,
alpha_blend: wgpu::BlendState::REPLACE,
color_blend: wgpu::BlendState::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}), }),
color_states: &[wgpu::ColorStateDescriptor {
format: display_format,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
color_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
rasterization_state: None,
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None, strip_index_format: None,
@ -228,9 +229,10 @@ impl<'a> ShaderCanvasBuilder<'a> {
polygon_mode: wgpu::PolygonMode::Fill, polygon_mode: wgpu::PolygonMode::Fill,
}, },
depth_stencil: None, depth_stencil: None,
vertex_state: wgpu::VertexStateDescriptor { multisample: wgpu::MultisampleState {
index_format: wgpu::IndexFormat::Uint16, count: 1,
vertex_buffers: &[], mask: !0,
alpha_to_coverage_enabled: false,
}, },
}); });

@ -10,7 +10,7 @@ edition = "2018"
anyhow = "1.0" anyhow = "1.0"
wgpu = "0.7" wgpu = "0.7"
futures = "0.3" futures = "0.3"
imgui = "0.6" imgui = "0.7"
imgui-wgpu = "0.12" imgui-wgpu = "0.14"
imgui-winit-support = "0.6" imgui-winit-support = "0.7"
framework = { path = "../framework" } framework = { path = "../framework" }

@ -114,6 +114,7 @@ impl framework::Demo for ImguiDemo {
} }
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("UI RenderPass"),
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &output.view, attachment: &output.view,
resolve_target: None, resolve_target: None,

@ -3,9 +3,9 @@
This is not an in depth guid on how to use Imgui. But here are some of the basics you'll need to get started. We'll need to import [imgui-rs](https://docs.rs/imgui), [imgui-wgpu](https://docs.rs/imgui-wgpu), and [imgui-winit-support](https://docs.rs/imgui-winit-support). This is not an in depth guid on how to use Imgui. But here are some of the basics you'll need to get started. We'll need to import [imgui-rs](https://docs.rs/imgui), [imgui-wgpu](https://docs.rs/imgui-wgpu), and [imgui-winit-support](https://docs.rs/imgui-winit-support).
```toml ```toml
imgui = "0.6" imgui = "0.7"
imgui-wgpu = "0.12" imgui-wgpu = "0.14"
imgui-winit-support = "0.6" imgui-winit-support = "0.7"
``` ```
<div class="note"> <div class="note">
@ -110,6 +110,7 @@ if self.last_cursor != ui.mouse_cursor() {
} }
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("UI RenderPass"),
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &output.view, attachment: &output.view,
resolve_target: None, resolve_target: None,

Loading…
Cancel
Save