From a6a00f4b2d9d330e3395a6cdf13294b9d0c6b206 Mon Sep 17 00:00:00 2001 From: charlotte Date: Thu, 5 Mar 2026 21:10:27 -0800 Subject: [PATCH] Fix scale factor when using GLFW. --- crates/processing_pyo3/src/glfw.rs | 12 ++++++++---- crates/processing_pyo3/src/gltf.rs | 4 ++-- crates/processing_pyo3/src/graphics.rs | 2 +- crates/processing_pyo3/src/lib.rs | 2 +- examples/animated_mesh.rs | 4 +--- examples/background_image.rs | 4 +--- examples/box.rs | 4 +--- examples/custom_attribute.rs | 4 +--- examples/glfw.rs | 12 ++++++++---- examples/gltf_load.rs | 2 +- examples/lights.rs | 4 +--- examples/materials.rs | 2 +- examples/midi.rs | 4 +--- examples/pbr.rs | 2 +- examples/rectangle.rs | 4 +--- examples/transforms.rs | 2 +- examples/update_pixels.rs | 4 +--- 17 files changed, 32 insertions(+), 40 deletions(-) diff --git a/crates/processing_pyo3/src/glfw.rs b/crates/processing_pyo3/src/glfw.rs index fe4c115..37a15d2 100644 --- a/crates/processing_pyo3/src/glfw.rs +++ b/crates/processing_pyo3/src/glfw.rs @@ -31,8 +31,9 @@ impl GlfwContext { } #[cfg(target_os = "macos")] - pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result { + pub fn create_surface(&self, width: u32, height: u32) -> Result { use processing::prelude::surface_create_macos; + let (scale_factor, _) = self.window.get_content_scale(); surface_create_macos( self.window.get_cocoa_window() as u64, width, @@ -42,8 +43,9 @@ impl GlfwContext { } #[cfg(target_os = "windows")] - pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result { + pub fn create_surface(&self, width: u32, height: u32) -> Result { use processing::prelude::surface_create_windows; + let (scale_factor, _) = self.window.get_content_scale(); surface_create_windows( self.window.get_win32_window() as u64, width, @@ -53,8 +55,9 @@ impl GlfwContext { } #[cfg(all(target_os = "linux", feature = "wayland"))] - pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result { + pub fn create_surface(&self, width: u32, height: u32) -> Result { use processing::prelude::surface_create_wayland; + let (scale_factor, _) = self.window.get_content_scale(); surface_create_wayland( self.window.get_wayland_window() as u64, self.glfw.get_wayland_display() as u64, @@ -65,8 +68,9 @@ impl GlfwContext { } #[cfg(all(target_os = "linux", feature = "x11"))] - pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result { + pub fn create_surface(&self, width: u32, height: u32) -> Result { use processing::prelude::surface_create_x11; + let (scale_factor, _) = self.window.get_content_scale(); surface_create_x11( self.window.get_x11_window() as u64, self.glfw.get_x11_display() as u64, diff --git a/crates/processing_pyo3/src/gltf.rs b/crates/processing_pyo3/src/gltf.rs index ee617de..9764beb 100644 --- a/crates/processing_pyo3/src/gltf.rs +++ b/crates/processing_pyo3/src/gltf.rs @@ -46,8 +46,8 @@ impl Gltf { #[pyfunction] #[pyo3(pass_module)] pub fn load_gltf(module: &Bound<'_, PyModule>, path: &str) -> PyResult { - let graphics = get_graphics(module)? - .ok_or_else(|| PyRuntimeError::new_err("call size() first"))?; + let graphics = + get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?; let entity = gltf_load(graphics.entity, path).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; Ok(Gltf { entity }) diff --git a/crates/processing_pyo3/src/graphics.rs b/crates/processing_pyo3/src/graphics.rs index 5d58765..32b43b0 100644 --- a/crates/processing_pyo3/src/graphics.rs +++ b/crates/processing_pyo3/src/graphics.rs @@ -176,7 +176,7 @@ impl Graphics { init(config).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; let surface = glfw_ctx - .create_surface(width, height, 1.0) + .create_surface(width, height) .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; let surface = Surface { diff --git a/crates/processing_pyo3/src/lib.rs b/crates/processing_pyo3/src/lib.rs index f67b645..678a6c3 100644 --- a/crates/processing_pyo3/src/lib.rs +++ b/crates/processing_pyo3/src/lib.rs @@ -22,8 +22,8 @@ use pyo3::{ }; use std::ffi::{CStr, CString}; -use gltf::Gltf; use bevy::log::warn; +use gltf::Gltf; use std::env; /// Get a shared ref to the Graphics context, or return Ok(()) if not yet initialized. diff --git a/examples/animated_mesh.rs b/examples/animated_mesh.rs index 5881fad..02d7ba2 100644 --- a/examples/animated_mesh.rs +++ b/examples/animated_mesh.rs @@ -24,9 +24,7 @@ fn sketch() -> error::Result<()> { let width = 600; let height = 600; - let scale_factor = 1.0; - - let surface = glfw_ctx.create_surface(width, height, scale_factor)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; let grid_size = 20; diff --git a/examples/background_image.rs b/examples/background_image.rs index e4c4676..3d76775 100644 --- a/examples/background_image.rs +++ b/examples/background_image.rs @@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> { let width = 400; let height = 400; - let scale_factor = 1.0; - - let surface = glfw_ctx.create_surface(width, height, scale_factor)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; let image = image_load("images/logo.png")?; diff --git a/examples/box.rs b/examples/box.rs index 7f2472d..df38a17 100644 --- a/examples/box.rs +++ b/examples/box.rs @@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> { let width = 400; let height = 400; - let scale_factor = 1.0; - - let surface = glfw_ctx.create_surface(width, height, scale_factor)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; let box_geo = geometry_box(100.0, 100.0, 100.0)?; diff --git a/examples/custom_attribute.rs b/examples/custom_attribute.rs index 68f3a17..680196b 100644 --- a/examples/custom_attribute.rs +++ b/examples/custom_attribute.rs @@ -24,9 +24,7 @@ fn sketch() -> error::Result<()> { let width = 600; let height = 600; - let scale_factor = 1.0; - - let surface = glfw_ctx.create_surface(width, height, scale_factor)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; let custom_attr = geometry_attribute_create("Custom", AttributeFormat::Float)?; diff --git a/examples/glfw.rs b/examples/glfw.rs index 366640e..6387d1d 100644 --- a/examples/glfw.rs +++ b/examples/glfw.rs @@ -31,8 +31,9 @@ impl GlfwContext { } #[cfg(target_os = "macos")] - pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result { + pub fn create_surface(&self, width: u32, height: u32) -> Result { use processing_render::surface_create_macos; + let (scale_factor, _) = self.window.get_content_scale(); surface_create_macos( self.window.get_cocoa_window() as u64, width, @@ -42,8 +43,9 @@ impl GlfwContext { } #[cfg(target_os = "windows")] - pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result { + pub fn create_surface(&self, width: u32, height: u32) -> Result { use processing_render::surface_create_windows; + let (scale_factor, _) = self.window.get_content_scale(); surface_create_windows( self.window.get_win32_window() as u64, width, @@ -53,8 +55,9 @@ impl GlfwContext { } #[cfg(all(target_os = "linux", feature = "wayland"))] - pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result { + pub fn create_surface(&self, width: u32, height: u32) -> Result { use processing_render::surface_create_wayland; + let (scale_factor, _) = self.window.get_content_scale(); surface_create_wayland( self.window.get_wayland_window() as u64, self.glfw.get_wayland_display() as u64, @@ -65,8 +68,9 @@ impl GlfwContext { } #[cfg(all(target_os = "linux", feature = "x11"))] - pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result { + pub fn create_surface(&self, width: u32, height: u32) -> Result { use processing_render::surface_create_x11; + let (scale_factor, _) = self.window.get_content_scale(); surface_create_x11( self.window.get_x11_window() as u64, self.glfw.get_x11_display() as u64, diff --git a/examples/gltf_load.rs b/examples/gltf_load.rs index 8abf3f4..834f981 100644 --- a/examples/gltf_load.rs +++ b/examples/gltf_load.rs @@ -24,7 +24,7 @@ fn sketch() -> error::Result<()> { let mut glfw_ctx = GlfwContext::new(width, height)?; init(Config::default())?; - let surface = glfw_ctx.create_surface(width, height, 1.0)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height)?; let gltf = gltf_load(graphics, "gltf/Duck.glb")?; diff --git a/examples/lights.rs b/examples/lights.rs index 11f69e1..c5254af 100644 --- a/examples/lights.rs +++ b/examples/lights.rs @@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> { let width = 400; let height = 400; - let scale_factor = 1.0; - - let surface = glfw_ctx.create_surface(width, height, scale_factor)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; let box_geo = geometry_box(100.0, 100.0, 100.0)?; let pbr_mat = material_create_pbr()?; diff --git a/examples/materials.rs b/examples/materials.rs index f64282b..1e69e4f 100644 --- a/examples/materials.rs +++ b/examples/materials.rs @@ -23,7 +23,7 @@ fn sketch() -> error::Result<()> { let mut glfw_ctx = GlfwContext::new(width, height)?; init(Config::default())?; - let surface = glfw_ctx.create_surface(width, height, 1.0)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; let sphere = geometry_sphere(30.0, 32, 18)?; diff --git a/examples/midi.rs b/examples/midi.rs index 2a001fa..38d44f2 100644 --- a/examples/midi.rs +++ b/examples/midi.rs @@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> { let width = 400; let height = 400; - let scale_factor = 1.0; - - let surface = glfw_ctx.create_surface(width, height, scale_factor)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; processing_midi::connect(0); diff --git a/examples/pbr.rs b/examples/pbr.rs index c6bf503..f71d68e 100644 --- a/examples/pbr.rs +++ b/examples/pbr.rs @@ -23,7 +23,7 @@ fn sketch() -> error::Result<()> { let mut glfw_ctx = GlfwContext::new(width, height)?; init(Config::default())?; - let surface = glfw_ctx.create_surface(width, height, 1.0)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; graphics_mode_3d(graphics)?; diff --git a/examples/rectangle.rs b/examples/rectangle.rs index add70e4..3ea755b 100644 --- a/examples/rectangle.rs +++ b/examples/rectangle.rs @@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> { let width = 400; let height = 400; - let scale_factor = 1.0; - - let surface = glfw_ctx.create_surface(width, height, scale_factor)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; while glfw_ctx.poll_events() { diff --git a/examples/transforms.rs b/examples/transforms.rs index 892acf0..6893aa3 100644 --- a/examples/transforms.rs +++ b/examples/transforms.rs @@ -15,7 +15,7 @@ fn sketch() -> error::Result<()> { let mut glfw_ctx = GlfwContext::new(400, 400)?; init(Config::default())?; - let surface = glfw_ctx.create_surface(400, 400, 1.0)?; + let surface = glfw_ctx.create_surface(400, 400)?; let graphics = graphics_create(surface, 400, 400, TextureFormat::Rgba16Float)?; let mut t: f32 = 0.0; diff --git a/examples/update_pixels.rs b/examples/update_pixels.rs index 21f0878..a1a187e 100644 --- a/examples/update_pixels.rs +++ b/examples/update_pixels.rs @@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> { let width = 100; let height = 100; - let scale_factor = 1.0; - - let surface = glfw_ctx.create_surface(width, height, scale_factor)?; + let surface = glfw_ctx.create_surface(width, height)?; let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?; let rect_w = 10;