diff --git a/imgui-examples/Cargo.toml b/imgui-examples/Cargo.toml index 4c978d5..01e0e6a 100644 --- a/imgui-examples/Cargo.toml +++ b/imgui-examples/Cargo.toml @@ -9,10 +9,10 @@ license = "MIT/Apache-2.0" publish = false [dev-dependencies] -gfx = "0.16" -gfx_window_glutin = "0.19" +gfx = "0.17" +gfx_window_glutin = "0.22" glium = { version = "0.21", default-features = true } -glutin = "0.11" +glutin = "0.14" imgui = { version = "0.0.19-pre", path = "../" } imgui-gfx-renderer = { version = "0.0.19-pre", path = "../imgui-gfx-renderer" } imgui-glium-renderer = { version = "0.0.19-pre", path = "../imgui-glium-renderer" } diff --git a/imgui-examples/examples/support_gfx/mod.rs b/imgui-examples/examples/support_gfx/mod.rs index 9915acd..77cbf97 100644 --- a/imgui-examples/examples/support_gfx/mod.rs +++ b/imgui-examples/examples/support_gfx/mod.rs @@ -17,7 +17,6 @@ pub fn run bool>(title: String, clear_color: [f32; 4], mut run_ type ColorFormat = gfx::format::Rgba8; type DepthFormat = gfx::format::DepthStencil; - let mut events_loop = glutin::EventsLoop::new(); let context = glutin::ContextBuilder::new().with_vsync(true); let window = glutin::WindowBuilder::new() @@ -58,7 +57,7 @@ pub fn run bool>(title: String, clear_color: [f32; 4], mut run_ let mut mouse_state = MouseState::default(); let mut quit = false; - loop { + 'running: loop { events_loop.poll_events(|event| { use glutin::WindowEvent::*; use glutin::ElementState::Pressed; @@ -128,6 +127,9 @@ pub fn run bool>(title: String, clear_color: [f32; 4], mut run_ } } }); + if quit { + break 'running; + } let now = Instant::now(); let delta = now - last_frame; @@ -174,10 +176,6 @@ pub fn run bool>(title: String, clear_color: [f32; 4], mut run_ encoder.flush(&mut device); window.context().swap_buffers().unwrap(); device.cleanup(); - - if quit { - break; - } } } diff --git a/imgui-gfx-renderer/Cargo.toml b/imgui-gfx-renderer/Cargo.toml index 6dbcf67..214a112 100644 --- a/imgui-gfx-renderer/Cargo.toml +++ b/imgui-gfx-renderer/Cargo.toml @@ -12,6 +12,6 @@ categories = ["gui", "rendering"] travis-ci = { repository = "Gekkio/imgui-rs" } [dependencies] -gfx = "0.16" +gfx = "0.17" imgui = { version = "0.0.19-pre", path = "../" } imgui-sys = { version = "0.0.19-pre", path = "../imgui-sys", features = ["gfx"] } diff --git a/imgui-gfx-renderer/src/lib.rs b/imgui-gfx-renderer/src/lib.rs index ce87a29..be792bd 100644 --- a/imgui-gfx-renderer/src/lib.rs +++ b/imgui-gfx-renderer/src/lib.rs @@ -2,8 +2,10 @@ extern crate gfx; extern crate imgui; -use gfx::{Bind, Bundle, CommandBuffer, Encoder, Factory, IntoIndexBuffer, Rect, Resources, Slice}; +use gfx::{Bundle, CommandBuffer, Encoder, Factory, IntoIndexBuffer, Rect, Resources, Slice}; +use gfx::memory::Bind; use gfx::handle::{Buffer, RenderTargetView}; +use gfx::texture::{FilterMethod, SamplerInfo, WrapMode}; use gfx::traits::FactoryExt; use imgui::{DrawList, ImDrawIdx, ImDrawVert, ImGui, Ui}; @@ -38,7 +40,11 @@ gfx_defines!{ vertex_buffer: gfx::VertexBuffer = (), matrix: gfx::Global<[[f32; 4]; 4]> = "matrix", tex: gfx::TextureSampler<[f32; 4]> = "tex", - out: gfx::BlendTarget = ("Target0", gfx::state::MASK_ALL, gfx::preset::blend::ALPHA), + out: gfx::BlendTarget = ( + "Target0", + gfx::state::ColorMask::all(), + gfx::preset::blend::ALPHA, + ), scissor: gfx::Scissor = (), } } @@ -117,11 +123,13 @@ impl Renderer { handle.height as u16, gfx::texture::AaMode::Single, ), + gfx::texture::Mipmap::Provided, &[handle.pixels], ) })?; // TODO: set texture id in imgui - let sampler = factory.create_sampler_linear(); + let sampler = + factory.create_sampler(SamplerInfo::new(FilterMethod::Scale, WrapMode::Clamp)); let data = pipe::Data { vertex_buffer: vertex_buffer, matrix: [ @@ -183,29 +191,22 @@ impl Renderer { encoder: &mut Encoder, draw_list: &DrawList<'a>, ) -> RendererResult<()> { + let (width, height) = ui.imgui().display_size(); let (scale_width, scale_height) = ui.imgui().display_framebuffer_scale(); + self.upload_vertex_buffer(factory, encoder, draw_list.vtx_buffer)?; + self.upload_index_buffer(factory, encoder, draw_list.idx_buffer)?; + self.bundle.slice.start = 0; for cmd in draw_list.cmd_buffer { // TODO: check cmd.texture_id - self.upload_vertex_buffer( - factory, - encoder, - draw_list.vtx_buffer, - )?; - self.upload_index_buffer( - factory, - encoder, - draw_list.idx_buffer, - )?; - self.bundle.slice.end = self.bundle.slice.start + cmd.elem_count; self.bundle.data.scissor = Rect { - x: (cmd.clip_rect.x * scale_width) as u16, - y: (cmd.clip_rect.y * scale_height) as u16, - w: ((cmd.clip_rect.z - cmd.clip_rect.x).abs() * scale_width) as u16, - h: ((cmd.clip_rect.w - cmd.clip_rect.y).abs() * scale_height) as u16, + x: (cmd.clip_rect.x.max(0.0) * scale_width) as u16, + y: (cmd.clip_rect.y.max(0.0) * scale_height) as u16, + w: ((cmd.clip_rect.z - cmd.clip_rect.x).abs().min(width) * scale_width) as u16, + h: ((cmd.clip_rect.w - cmd.clip_rect.y).abs().min(height) * scale_height) as u16, }; self.bundle.encode(encoder); self.bundle.slice.start = self.bundle.slice.end; diff --git a/imgui-sys/Cargo.toml b/imgui-sys/Cargo.toml index 49332a0..bbc0fe1 100644 --- a/imgui-sys/Cargo.toml +++ b/imgui-sys/Cargo.toml @@ -15,7 +15,7 @@ travis-ci = { repository = "Gekkio/imgui-rs" } [dependencies] bitflags = "1.0" glium = { version = "0.21", default-features = false, optional = true } -gfx = { version = "0.16", optional = true } +gfx = { version = "0.17", optional = true } [build-dependencies] cc = "1.0"