diff --git a/src/config.rs b/src/config.rs index e9f05ce..d3803cf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,8 +11,6 @@ /// } /// ``` /// -/// To streamline this pattern and save you imports, see the `get_fancy!` macro. -/// /// If there's a config option you want to see or think is missing, please open an issue! pub struct Config { /// Sets the scale of the buffer. The buffer will automatically scale to the size of the diff --git a/src/core.rs b/src/core.rs index 46a0c76..d5e2ab9 100644 --- a/src/core.rs +++ b/src/core.rs @@ -43,13 +43,18 @@ pub fn init_glutin_context(config: &Config) -> (EventsLoop, GlWi type VertexFormat = buffer_layout!([f32; 2], [f32; 2]); /// Create the OpenGL resources needed for drawing to a buffer. -pub fn init_framebuffer(config: &Config) -> Framebuffer { +pub fn init_framebuffer( + buffer_width: u32, + buffer_height: u32, + viewport_width: u32, + viewport_height: u32 +) -> Framebuffer { // The config takes the size in u32 because that's all that actually makes sense but since // OpenGL is from the Land of C where a Working Type System doesn't exist, we work with i32s - let buffer_width = if config.buffer_size.0 == 0 { config.window_size.0.round() as _ } - else { config.buffer_size.0 as _ }; - let buffer_height = if config.buffer_size.1 == 0 { config.window_size.1.round() as _ } - else { config.buffer_size.1 as _ }; + let buffer_width = buffer_width as i32; + let buffer_height = buffer_height as i32; + let vp_width = viewport_width as i32; + let vp_height = viewport_height as i32; let vertex_shader = rustic_gl::raw::create_shader( gl::VERTEX_SHADER, @@ -105,10 +110,10 @@ pub fn init_framebuffer(config: &Config) -> Framebuffer { } Framebuffer { - buffer_width: buffer_width, - buffer_height: buffer_height, - vp_width: config.window_size.0 as _, - vp_height: config.window_size.1 as _, + buffer_width, + buffer_height, + vp_width, + vp_height, program, sampler_location, vertex_shader: Some(vertex_shader), diff --git a/src/lib.rs b/src/lib.rs index 1bcab3a..cbc7887 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,46 +76,6 @@ pub use breakout::GlutinBreakout; pub use config::Config; pub use core::{Internal, BufferFormat}; -/* -// TODO: Support mixed { prop, prop: value, .. } for creating configs through the macro - -#[macro_export] -macro_rules! get_fancy { - ( - $($setting:ident: $setting_value:expr),* - ) => { - // Support both no trailing comma and trailing comma - // (The core macro impl assumes trailing comma) - get_fancy!($($setting: $setting_value),*,) - }; - - ( - $($setting:ident),* - ) => { - // Support both no trailing comma and trailing comma - // (The core macro impl assumes trailing comma) - get_fancy!($($setting),*,) - }; - - ( - $($setting:ident),*, - ) => { - get_fancy!($($setting: $setting),*,) - }; - - ( - $($setting:ident: $setting_value:expr),*, - ) => {{ - let config = $crate::Config { - $( - $setting: $setting_value - ),*, - .. Default::default() - }; - $crate::get_fancy(config) - }}; -}*/ - /// Creates a non resizable window and framebuffer with a given size in pixels. /// /// Please note that the window size is in logical device pixels, so on a high DPI monitor the @@ -145,8 +105,25 @@ pub fn gotta_go_fast( /// glutin or in this library, this function exists as a possible work around (or in case for some /// reason everything must be absolutely correct at window creation) pub fn get_fancy(config: Config) -> MiniGlFb { + let buffer_width = if config.buffer_size.0 == 0 { config.window_size.0.round() as _ } + else { config.buffer_size.0 }; + let buffer_height = if config.buffer_size.1 == 0 { config.window_size.1.round() as _ } + else { config.buffer_size.1 }; + let (events_loop, gl_window) = core::init_glutin_context(&config); - let fb = core::init_framebuffer(&config); + + let dpi_factor = gl_window.get_hidpi_factor(); + let (vp_width, vp_height) = gl_window.get_inner_size() + .unwrap() + .to_physical(dpi_factor) + .into(); + + let fb = core::init_framebuffer( + buffer_width, + buffer_height, + vp_width, + vp_height, + ); MiniGlFb { internal: Internal {