mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-22 19:08:37 +00:00
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:
parent
b6e5086eb2
commit
1d64e4e185
@ -9,10 +9,10 @@ license = "MIT/Apache-2.0"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
gfx = "0.16"
|
gfx = "0.17"
|
||||||
gfx_window_glutin = "0.19"
|
gfx_window_glutin = "0.22"
|
||||||
glium = { version = "0.21", default-features = true }
|
glium = { version = "0.21", default-features = true }
|
||||||
glutin = "0.11"
|
glutin = "0.14"
|
||||||
imgui = { version = "0.0.19-pre", path = "../" }
|
imgui = { version = "0.0.19-pre", path = "../" }
|
||||||
imgui-gfx-renderer = { version = "0.0.19-pre", path = "../imgui-gfx-renderer" }
|
imgui-gfx-renderer = { version = "0.0.19-pre", path = "../imgui-gfx-renderer" }
|
||||||
imgui-glium-renderer = { version = "0.0.19-pre", path = "../imgui-glium-renderer" }
|
imgui-glium-renderer = { version = "0.0.19-pre", path = "../imgui-glium-renderer" }
|
||||||
|
|||||||
@ -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 ColorFormat = gfx::format::Rgba8;
|
||||||
type DepthFormat = gfx::format::DepthStencil;
|
type DepthFormat = gfx::format::DepthStencil;
|
||||||
|
|
||||||
|
|
||||||
let mut events_loop = glutin::EventsLoop::new();
|
let mut events_loop = glutin::EventsLoop::new();
|
||||||
let context = glutin::ContextBuilder::new().with_vsync(true);
|
let context = glutin::ContextBuilder::new().with_vsync(true);
|
||||||
let window = glutin::WindowBuilder::new()
|
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 mouse_state = MouseState::default();
|
||||||
let mut quit = false;
|
let mut quit = false;
|
||||||
|
|
||||||
loop {
|
'running: loop {
|
||||||
events_loop.poll_events(|event| {
|
events_loop.poll_events(|event| {
|
||||||
use glutin::WindowEvent::*;
|
use glutin::WindowEvent::*;
|
||||||
use glutin::ElementState::Pressed;
|
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 now = Instant::now();
|
||||||
let delta = now - last_frame;
|
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);
|
encoder.flush(&mut device);
|
||||||
window.context().swap_buffers().unwrap();
|
window.context().swap_buffers().unwrap();
|
||||||
device.cleanup();
|
device.cleanup();
|
||||||
|
|
||||||
if quit {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,6 @@ categories = ["gui", "rendering"]
|
|||||||
travis-ci = { repository = "Gekkio/imgui-rs" }
|
travis-ci = { repository = "Gekkio/imgui-rs" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gfx = "0.16"
|
gfx = "0.17"
|
||||||
imgui = { version = "0.0.19-pre", path = "../" }
|
imgui = { version = "0.0.19-pre", path = "../" }
|
||||||
imgui-sys = { version = "0.0.19-pre", path = "../imgui-sys", features = ["gfx"] }
|
imgui-sys = { version = "0.0.19-pre", path = "../imgui-sys", features = ["gfx"] }
|
||||||
|
|||||||
@ -2,8 +2,10 @@
|
|||||||
extern crate gfx;
|
extern crate gfx;
|
||||||
extern crate imgui;
|
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::handle::{Buffer, RenderTargetView};
|
||||||
|
use gfx::texture::{FilterMethod, SamplerInfo, WrapMode};
|
||||||
use gfx::traits::FactoryExt;
|
use gfx::traits::FactoryExt;
|
||||||
use imgui::{DrawList, ImDrawIdx, ImDrawVert, ImGui, Ui};
|
use imgui::{DrawList, ImDrawIdx, ImDrawVert, ImGui, Ui};
|
||||||
|
|
||||||
@ -38,7 +40,11 @@ gfx_defines!{
|
|||||||
vertex_buffer: gfx::VertexBuffer<ImDrawVert> = (),
|
vertex_buffer: gfx::VertexBuffer<ImDrawVert> = (),
|
||||||
matrix: gfx::Global<[[f32; 4]; 4]> = "matrix",
|
matrix: gfx::Global<[[f32; 4]; 4]> = "matrix",
|
||||||
tex: gfx::TextureSampler<[f32; 4]> = "tex",
|
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 = (),
|
scissor: gfx::Scissor = (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,11 +123,13 @@ impl<R: Resources> Renderer<R> {
|
|||||||
handle.height as u16,
|
handle.height as u16,
|
||||||
gfx::texture::AaMode::Single,
|
gfx::texture::AaMode::Single,
|
||||||
),
|
),
|
||||||
|
gfx::texture::Mipmap::Provided,
|
||||||
&[handle.pixels],
|
&[handle.pixels],
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
// TODO: set texture id in imgui
|
// 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 {
|
let data = pipe::Data {
|
||||||
vertex_buffer: vertex_buffer,
|
vertex_buffer: vertex_buffer,
|
||||||
matrix: [
|
matrix: [
|
||||||
@ -183,29 +191,22 @@ impl<R: Resources> Renderer<R> {
|
|||||||
encoder: &mut Encoder<R, C>,
|
encoder: &mut Encoder<R, C>,
|
||||||
draw_list: &DrawList<'a>,
|
draw_list: &DrawList<'a>,
|
||||||
) -> RendererResult<()> {
|
) -> RendererResult<()> {
|
||||||
|
let (width, height) = ui.imgui().display_size();
|
||||||
let (scale_width, scale_height) = ui.imgui().display_framebuffer_scale();
|
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;
|
self.bundle.slice.start = 0;
|
||||||
for cmd in draw_list.cmd_buffer {
|
for cmd in draw_list.cmd_buffer {
|
||||||
// TODO: check cmd.texture_id
|
// 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.slice.end = self.bundle.slice.start + cmd.elem_count;
|
||||||
self.bundle.data.scissor = Rect {
|
self.bundle.data.scissor = Rect {
|
||||||
x: (cmd.clip_rect.x * scale_width) as u16,
|
x: (cmd.clip_rect.x.max(0.0) * scale_width) as u16,
|
||||||
y: (cmd.clip_rect.y * scale_height) as u16,
|
y: (cmd.clip_rect.y.max(0.0) * scale_height) as u16,
|
||||||
w: ((cmd.clip_rect.z - cmd.clip_rect.x).abs() * scale_width) 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() * scale_height) as u16,
|
h: ((cmd.clip_rect.w - cmd.clip_rect.y).abs().min(height) * scale_height) as u16,
|
||||||
};
|
};
|
||||||
self.bundle.encode(encoder);
|
self.bundle.encode(encoder);
|
||||||
self.bundle.slice.start = self.bundle.slice.end;
|
self.bundle.slice.start = self.bundle.slice.end;
|
||||||
|
|||||||
@ -15,7 +15,7 @@ travis-ci = { repository = "Gekkio/imgui-rs" }
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
glium = { version = "0.21", default-features = false, optional = true }
|
glium = { version = "0.21", default-features = false, optional = true }
|
||||||
gfx = { version = "0.16", optional = true }
|
gfx = { version = "0.17", optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cc = "1.0"
|
cc = "1.0"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user