Skip to content

Commit 03f2369

Browse files
authored
Merge pull request Yatekii#73 from Yatekii/imgui-0.8
2 parents a81670c + 129324f commit 03f2369

18 files changed

+151
-176
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ Per Keep a Changelog there are 6 main categories of changes:
2828

2929
## Unreleased
3030

31+
#### Updated
32+
- updated imgui dependency to `>=0.1,<0.9`
33+
34+
#### Removed
35+
- unstable simple-api is now it's own, unpublished, crate.
36+
3137
## v0.17.0
3238

3339
Released 2021-09-04

Cargo.toml

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[workspace]
2+
members = [".", "simple-api"]
3+
default-members = [".", "simple-api"]
4+
resolver = "2"
5+
16
[package]
27
name = "imgui-wgpu"
38
version = "0.17.0"
@@ -11,22 +16,13 @@ readme = "README.md"
1116
categories = ["gui", "graphics", "rendering", "rendering::graphics-api"]
1217
keywords = ["gui", "graphics", "wgpu", "imgui"]
1318
license = "MIT OR Apache-2.0"
14-
resolver = "2"
1519

1620
exclude = [
1721
".gitignore",
1822
".github",
1923
"resources",
2024
]
2125

22-
[[example]]
23-
name = "basic_simple_api"
24-
required-features = ["simple_api_unstable"]
25-
26-
[[example]]
27-
name = "fullscreen_simple_api"
28-
required-features = ["simple_api_unstable"]
29-
3026
[[package.metadata.release.pre-release-replacements]]
3127
file = "CHANGELOG.md"
3228
search = "\\[Unreleased\\]\\(#unreleased\\)"
@@ -50,32 +46,22 @@ search = "<!-- Begin Diffs -->"
5046
replace = "- [Unreleased](https://github.com/Yatekii/imgui-wgpu-rs/compare/v{{version}}...HEAD)"
5147
min = 0 # allow non-first increment
5248

53-
[features]
54-
# used in src/simple_api.rs
55-
default = []
56-
simple_api_unstable = [ "winit", "pollster", "imgui-winit-support" ]
57-
5849
[dependencies]
5950
bytemuck = "1"
60-
imgui = "0.7"
51+
imgui = ">=0.1, <0.9"
6152
log = "0.4"
6253
smallvec = "1"
63-
wgpu = { version = "0.10", features = ["spirv"] }
64-
65-
# deps for simple_api_unstable
66-
imgui-winit-support = { version = "0.7", optional = true }
67-
pollster = { version = "0.2.0", optional = true } # for block_on executor
68-
winit = { version = ">= 0.23, < 0.25", optional = true }
54+
wgpu = "0.10"
6955

7056
[dev-dependencies]
7157
bytemuck = { version = "1.4", features = ["derive"] }
7258
cgmath = "0.18"
7359
env_logger = "0.9"
7460
image = { version = "0.23", default-features = false, features = ["jpeg"] }
75-
imgui-winit-support = "0.7"
61+
imgui-winit-support = "0.8"
7662
pollster = "0.2"
7763
raw-window-handle = "0.3"
78-
winit = "0.24"
64+
winit = "0.25"
7965

8066
[package.metadata.docs.rs]
8167
all-features = true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cargo run --release --example hello_world
2222

2323
# Status
2424

25-
Basic features are useable. Uses `wgpu-0.9` and `imgui-0.7` upstream. `winit-0.24` is used with the examples.
25+
Uses `wgpu-0.10` upstream. Compatible with all imgui versions after `0.1`. `winit-0.25` is used with the examples.
2626

2727
Contributions are very welcome.
2828

deny.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ skip = [
1818
{ name = "dlib", version = "0.4.2" },
1919
{ name = "libloading", version = "0.6.7" },
2020
{ name = "nix", version = "0.18.0" },
21-
{ name = "winapi", version = "0.2.8" },
21+
{ name = "proc-macro-crate", version = "0.1.5" },
2222
]
2323

2424
[advisories]
2525
vulnerability = "deny"
2626
unmaintained = "deny"
2727
ignore = [
28-
"RUSTSEC-2020-0016"
2928
]
3029

3130
[sources]

examples/basic_simple_api.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/cube.rs

Lines changed: 42 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ use bytemuck::{Pod, Zeroable};
22
use imgui::*;
33
use imgui_wgpu::{Renderer, RendererConfig, Texture, TextureConfig};
44
use pollster::block_on;
5-
use std::num::NonZeroU32;
65
use std::time::Instant;
7-
use wgpu::{util::DeviceExt, BlendState, Extent3d};
6+
use wgpu::{include_wgsl, util::DeviceExt, Extent3d};
87
use winit::{
98
dpi::LogicalSize,
109
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
1110
event_loop::{ControlFlow, EventLoop},
1211
window::Window,
1312
};
1413

15-
// Example code modified from https://github.com/gfx-rs/wgpu-rs/tree/master/examples/cube
16-
1714
const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
1815
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 1.0,
1916
);
2017

18+
// Example code modified from https://github.com/gfx-rs/wgpu-rs/tree/master/examples/cube
2119
#[repr(C)]
2220
#[derive(Clone, Copy, Pod, Zeroable)]
2321
struct Vertex {
@@ -79,10 +77,8 @@ fn create_vertices() -> (Vec<Vertex>, Vec<u16>) {
7977
}
8078

8179
fn create_texels(size: usize) -> Vec<u8> {
82-
use std::iter;
83-
8480
(0..size * size)
85-
.flat_map(|id| {
81+
.map(|id| {
8682
// get high five for recognizing this ;)
8783
let cx = 3.0 * (id % size) as f32 / (size - 1) as f32 - 2.0;
8884
let cy = 2.0 * (id / size) as f32 / (size - 1) as f32 - 1.0;
@@ -93,10 +89,7 @@ fn create_texels(size: usize) -> Vec<u8> {
9389
y = 2.0 * old_x * y + cy;
9490
count += 1;
9591
}
96-
iter::once(0xFF - (count * 5) as u8)
97-
.chain(iter::once(0xFF - (count * 15) as u8))
98-
.chain(iter::once(0xFF - (count * 50) as u8))
99-
.chain(iter::once(1))
92+
count
10093
})
10194
.collect()
10295
}
@@ -112,10 +105,10 @@ struct Example {
112105
}
113106

114107
impl Example {
115-
fn generate_matrix(aspect_ratio: f32, theta: f32) -> cgmath::Matrix4<f32> {
108+
fn generate_matrix(aspect_ratio: f32) -> cgmath::Matrix4<f32> {
116109
let mx_projection = cgmath::perspective(cgmath::Deg(45f32), aspect_ratio, 1.0, 10.0);
117110
let mx_view = cgmath::Matrix4::look_at_rh(
118-
cgmath::Point3::new(6.0 * theta.cos(), 6.0 * theta.sin(), 3.0),
111+
cgmath::Point3::new(1.5f32, -5.0, 3.0),
119112
cgmath::Point3::new(0f32, 0.0, 0.0),
120113
cgmath::Vector3::unit_z(),
121114
);
@@ -126,7 +119,7 @@ impl Example {
126119

127120
impl Example {
128121
fn init(
129-
surface_desc: &wgpu::SurfaceConfiguration,
122+
config: &wgpu::SurfaceConfiguration,
130123
device: &wgpu::Device,
131124
queue: &wgpu::Queue,
132125
) -> Self {
@@ -167,20 +160,11 @@ impl Example {
167160
visibility: wgpu::ShaderStages::FRAGMENT,
168161
ty: wgpu::BindingType::Texture {
169162
multisampled: false,
170-
sample_type: wgpu::TextureSampleType::Float { filterable: true },
163+
sample_type: wgpu::TextureSampleType::Uint,
171164
view_dimension: wgpu::TextureViewDimension::D2,
172165
},
173166
count: None,
174167
},
175-
wgpu::BindGroupLayoutEntry {
176-
binding: 2,
177-
visibility: wgpu::ShaderStages::FRAGMENT,
178-
ty: wgpu::BindingType::Sampler {
179-
filtering: true,
180-
comparison: false,
181-
},
182-
count: None,
183-
},
184168
],
185169
});
186170
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
@@ -203,38 +187,23 @@ impl Example {
203187
mip_level_count: 1,
204188
sample_count: 1,
205189
dimension: wgpu::TextureDimension::D2,
206-
format: wgpu::TextureFormat::Rgba8UnormSrgb,
190+
format: wgpu::TextureFormat::R8Uint,
207191
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
208192
});
209193
let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default());
210194
queue.write_texture(
211-
wgpu::ImageCopyTexture {
212-
texture: &texture,
213-
mip_level: 0,
214-
origin: wgpu::Origin3d::ZERO,
215-
aspect: wgpu::TextureAspect::All,
216-
},
195+
texture.as_image_copy(),
217196
&texels,
218197
wgpu::ImageDataLayout {
219198
offset: 0,
220-
bytes_per_row: NonZeroU32::new(4 * size),
199+
bytes_per_row: Some(std::num::NonZeroU32::new(size).unwrap()),
221200
rows_per_image: None,
222201
},
223202
texture_extent,
224203
);
225204

226205
// Create other resources
227-
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
228-
address_mode_u: wgpu::AddressMode::ClampToEdge,
229-
address_mode_v: wgpu::AddressMode::ClampToEdge,
230-
address_mode_w: wgpu::AddressMode::ClampToEdge,
231-
mag_filter: wgpu::FilterMode::Nearest,
232-
min_filter: wgpu::FilterMode::Linear,
233-
mipmap_filter: wgpu::FilterMode::Nearest,
234-
..Default::default()
235-
});
236-
let mx_total =
237-
Self::generate_matrix(surface_desc.width as f32 / surface_desc.height as f32, 0.0);
206+
let mx_total = Self::generate_matrix(config.width as f32 / config.height as f32);
238207
let mx_ref: &[f32; 16] = mx_total.as_ref();
239208
let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
240209
label: Some("Uniform Buffer"),
@@ -254,62 +223,48 @@ impl Example {
254223
binding: 1,
255224
resource: wgpu::BindingResource::TextureView(&texture_view),
256225
},
257-
wgpu::BindGroupEntry {
258-
binding: 2,
259-
resource: wgpu::BindingResource::Sampler(&sampler),
260-
},
261226
],
262227
label: None,
263228
});
264229

265-
// Create the render pipeline
266-
let vs_module =
267-
device.create_shader_module(&wgpu::include_spirv!("../resources/cube.vert.spv"));
268-
let fs_module =
269-
device.create_shader_module(&wgpu::include_spirv!("../resources/cube.frag.spv"));
230+
let shader = device.create_shader_module(&include_wgsl!("../resources/cube.wgsl"));
231+
232+
let vertex_buffers = [wgpu::VertexBufferLayout {
233+
array_stride: vertex_size as wgpu::BufferAddress,
234+
step_mode: wgpu::VertexStepMode::Vertex,
235+
attributes: &[
236+
wgpu::VertexAttribute {
237+
format: wgpu::VertexFormat::Float32x4,
238+
offset: 0,
239+
shader_location: 0,
240+
},
241+
wgpu::VertexAttribute {
242+
format: wgpu::VertexFormat::Float32x2,
243+
offset: 4 * 4,
244+
shader_location: 1,
245+
},
246+
],
247+
}];
270248

271249
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
272250
label: None,
273251
layout: Some(&pipeline_layout),
274252
vertex: wgpu::VertexState {
275-
module: &vs_module,
276-
entry_point: "main",
277-
buffers: &[wgpu::VertexBufferLayout {
278-
array_stride: vertex_size as wgpu::BufferAddress,
279-
step_mode: wgpu::VertexStepMode::Vertex,
280-
attributes: &[
281-
wgpu::VertexAttribute {
282-
format: wgpu::VertexFormat::Float32x4,
283-
offset: 0,
284-
shader_location: 0,
285-
},
286-
wgpu::VertexAttribute {
287-
format: wgpu::VertexFormat::Float32x2,
288-
offset: 4 * 4,
289-
shader_location: 1,
290-
},
291-
],
292-
}],
253+
module: &shader,
254+
entry_point: "vs_main",
255+
buffers: &vertex_buffers,
293256
},
257+
fragment: Some(wgpu::FragmentState {
258+
module: &shader,
259+
entry_point: "fs_main",
260+
targets: &[config.format.into()],
261+
}),
294262
primitive: wgpu::PrimitiveState {
295-
front_face: wgpu::FrontFace::Ccw,
296263
cull_mode: Some(wgpu::Face::Back),
297264
..Default::default()
298265
},
299266
depth_stencil: None,
300267
multisample: wgpu::MultisampleState::default(),
301-
fragment: Some(wgpu::FragmentState {
302-
module: &fs_module,
303-
entry_point: "main",
304-
targets: &[wgpu::ColorTargetState {
305-
format: surface_desc.format,
306-
blend: Some(BlendState {
307-
color: wgpu::BlendComponent::REPLACE,
308-
alpha: wgpu::BlendComponent::REPLACE,
309-
}),
310-
write_mask: wgpu::ColorWrites::ALL,
311-
}],
312-
}),
313268
});
314269

315270
// Done
@@ -329,7 +284,7 @@ impl Example {
329284
}
330285

331286
fn setup_camera(&mut self, queue: &wgpu::Queue, size: [f32; 2]) {
332-
let mx_total = Self::generate_matrix(size[0] / size[1], self.time * 0.1);
287+
let mx_total = Self::generate_matrix(size[0] / size[1]);
333288
let mx_ref: &[f32; 16] = mx_total.as_ref();
334289
queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(mx_ref));
335290
}
@@ -341,14 +296,14 @@ impl Example {
341296
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
342297
label: None,
343298
color_attachments: &[wgpu::RenderPassColorAttachment {
344-
view: &view,
299+
view,
345300
resolve_target: None,
346301
ops: wgpu::Operations {
347302
load: wgpu::LoadOp::Clear(wgpu::Color {
348303
r: 0.1,
349304
g: 0.2,
350305
b: 0.3,
351-
a: 0.1, // semi-transparent background
306+
a: 1.0,
352307
}),
353308
store: true,
354309
},
@@ -551,7 +506,7 @@ fn main() {
551506
// Store the new size of Image() or None to indicate that the window is collapsed.
552507
let mut new_example_size: Option<[f32; 2]> = None;
553508

554-
imgui::Window::new(im_str!("Cube"))
509+
imgui::Window::new("Cube")
555510
.size([512.0, 512.0], Condition::FirstUseEver)
556511
.build(&ui, || {
557512
new_example_size = Some(ui.content_region_avail());

examples/custom_textures.rs renamed to examples/custom-texture.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ fn main() {
194194

195195
{
196196
let size = [width as f32, height as f32];
197-
let window = imgui::Window::new(im_str!("Hello world"));
197+
let window = imgui::Window::new("Hello world");
198198
window
199199
.size([400.0, 600.0], Condition::FirstUseEver)
200200
.build(&ui, || {
201-
ui.text(im_str!("Hello textures!"));
202-
ui.text(im_str!("Say hello to Lenna.jpg"));
201+
ui.text("Hello textures!");
202+
ui.text("Say hello to Lenna.jpg");
203203
Image::new(lenna_texture_id, size).build(&ui);
204204
});
205205
}

0 commit comments

Comments
 (0)