Update gfx

- Fixes the screen resolution and mouse coordinates on macOS
- Fixes the blurry font by using linear filtering on the texture sampler
This commit is contained in:
Jay Oster 2018-04-26 20:01:24 -07:00
parent b6e5086eb2
commit 1d64e4e185
5 changed files with 28 additions and 29 deletions

View File

@ -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" }

View File

@ -17,7 +17,6 @@ pub fn run<F: FnMut(&Ui) -> 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<F: FnMut(&Ui) -> 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<F: FnMut(&Ui) -> 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<F: FnMut(&Ui) -> bool>(title: String, clear_color: [f32; 4], mut run_
encoder.flush(&mut device);
window.context().swap_buffers().unwrap();
device.cleanup();
if quit {
break;
}
}
}

View File

@ -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"] }

View File

@ -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<ImDrawVert> = (),
matrix: gfx::Global<[[f32; 4]; 4]> = "matrix",
tex: gfx::TextureSampler<[f32; 4]> = "tex",
out: gfx::BlendTarget<gfx::format::Rgba8> = ("Target0", gfx::state::MASK_ALL, gfx::preset::blend::ALPHA),
out: gfx::BlendTarget<gfx::format::Rgba8> = (
"Target0",
gfx::state::ColorMask::all(),
gfx::preset::blend::ALPHA,
),
scissor: gfx::Scissor = (),
}
}
@ -117,11 +123,13 @@ impl<R: Resources> Renderer<R> {
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<R: Resources> Renderer<R> {
encoder: &mut Encoder<R, C>,
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;

View File

@ -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"