Skip to content

Commit a6a00f4

Browse files
committed
Fix scale factor when using GLFW.
1 parent 96ca163 commit a6a00f4

File tree

17 files changed

+32
-40
lines changed

17 files changed

+32
-40
lines changed

crates/processing_pyo3/src/glfw.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ impl GlfwContext {
3131
}
3232

3333
#[cfg(target_os = "macos")]
34-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
34+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
3535
use processing::prelude::surface_create_macos;
36+
let (scale_factor, _) = self.window.get_content_scale();
3637
surface_create_macos(
3738
self.window.get_cocoa_window() as u64,
3839
width,
@@ -42,8 +43,9 @@ impl GlfwContext {
4243
}
4344

4445
#[cfg(target_os = "windows")]
45-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
46+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
4647
use processing::prelude::surface_create_windows;
48+
let (scale_factor, _) = self.window.get_content_scale();
4749
surface_create_windows(
4850
self.window.get_win32_window() as u64,
4951
width,
@@ -53,8 +55,9 @@ impl GlfwContext {
5355
}
5456

5557
#[cfg(all(target_os = "linux", feature = "wayland"))]
56-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
58+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
5759
use processing::prelude::surface_create_wayland;
60+
let (scale_factor, _) = self.window.get_content_scale();
5861
surface_create_wayland(
5962
self.window.get_wayland_window() as u64,
6063
self.glfw.get_wayland_display() as u64,
@@ -65,8 +68,9 @@ impl GlfwContext {
6568
}
6669

6770
#[cfg(all(target_os = "linux", feature = "x11"))]
68-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
71+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
6972
use processing::prelude::surface_create_x11;
73+
let (scale_factor, _) = self.window.get_content_scale();
7074
surface_create_x11(
7175
self.window.get_x11_window() as u64,
7276
self.glfw.get_x11_display() as u64,

crates/processing_pyo3/src/gltf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ impl Gltf {
4646
#[pyfunction]
4747
#[pyo3(pass_module)]
4848
pub fn load_gltf(module: &Bound<'_, PyModule>, path: &str) -> PyResult<Gltf> {
49-
let graphics = get_graphics(module)?
50-
.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
49+
let graphics =
50+
get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
5151
let entity =
5252
gltf_load(graphics.entity, path).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
5353
Ok(Gltf { entity })

crates/processing_pyo3/src/graphics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl Graphics {
176176
init(config).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
177177

178178
let surface = glfw_ctx
179-
.create_surface(width, height, 1.0)
179+
.create_surface(width, height)
180180
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
181181

182182
let surface = Surface {

crates/processing_pyo3/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use pyo3::{
2222
};
2323
use std::ffi::{CStr, CString};
2424

25-
use gltf::Gltf;
2625
use bevy::log::warn;
26+
use gltf::Gltf;
2727
use std::env;
2828

2929
/// Get a shared ref to the Graphics context, or return Ok(()) if not yet initialized.

examples/animated_mesh.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ fn sketch() -> error::Result<()> {
2424

2525
let width = 600;
2626
let height = 600;
27-
let scale_factor = 1.0;
28-
29-
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
27+
let surface = glfw_ctx.create_surface(width, height)?;
3028
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
3129

3230
let grid_size = 20;

examples/background_image.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> {
2323

2424
let width = 400;
2525
let height = 400;
26-
let scale_factor = 1.0;
27-
28-
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
26+
let surface = glfw_ctx.create_surface(width, height)?;
2927
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
3028
let image = image_load("images/logo.png")?;
3129

examples/box.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ fn sketch() -> error::Result<()> {
2323

2424
let width = 400;
2525
let height = 400;
26-
let scale_factor = 1.0;
27-
28-
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
26+
let surface = glfw_ctx.create_surface(width, height)?;
2927
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
3028
let box_geo = geometry_box(100.0, 100.0, 100.0)?;
3129

examples/custom_attribute.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ fn sketch() -> error::Result<()> {
2424

2525
let width = 600;
2626
let height = 600;
27-
let scale_factor = 1.0;
28-
29-
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
27+
let surface = glfw_ctx.create_surface(width, height)?;
3028
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
3129

3230
let custom_attr = geometry_attribute_create("Custom", AttributeFormat::Float)?;

examples/glfw.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ impl GlfwContext {
3131
}
3232

3333
#[cfg(target_os = "macos")]
34-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
34+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
3535
use processing_render::surface_create_macos;
36+
let (scale_factor, _) = self.window.get_content_scale();
3637
surface_create_macos(
3738
self.window.get_cocoa_window() as u64,
3839
width,
@@ -42,8 +43,9 @@ impl GlfwContext {
4243
}
4344

4445
#[cfg(target_os = "windows")]
45-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
46+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
4647
use processing_render::surface_create_windows;
48+
let (scale_factor, _) = self.window.get_content_scale();
4749
surface_create_windows(
4850
self.window.get_win32_window() as u64,
4951
width,
@@ -53,8 +55,9 @@ impl GlfwContext {
5355
}
5456

5557
#[cfg(all(target_os = "linux", feature = "wayland"))]
56-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
58+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
5759
use processing_render::surface_create_wayland;
60+
let (scale_factor, _) = self.window.get_content_scale();
5861
surface_create_wayland(
5962
self.window.get_wayland_window() as u64,
6063
self.glfw.get_wayland_display() as u64,
@@ -65,8 +68,9 @@ impl GlfwContext {
6568
}
6669

6770
#[cfg(all(target_os = "linux", feature = "x11"))]
68-
pub fn create_surface(&self, width: u32, height: u32, scale_factor: f32) -> Result<Entity> {
71+
pub fn create_surface(&self, width: u32, height: u32) -> Result<Entity> {
6972
use processing_render::surface_create_x11;
73+
let (scale_factor, _) = self.window.get_content_scale();
7074
surface_create_x11(
7175
self.window.get_x11_window() as u64,
7276
self.glfw.get_x11_display() as u64,

examples/gltf_load.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn sketch() -> error::Result<()> {
2424
let mut glfw_ctx = GlfwContext::new(width, height)?;
2525
init(Config::default())?;
2626

27-
let surface = glfw_ctx.create_surface(width, height, 1.0)?;
27+
let surface = glfw_ctx.create_surface(width, height)?;
2828
let graphics = graphics_create(surface, width, height)?;
2929

3030
let gltf = gltf_load(graphics, "gltf/Duck.glb")?;

0 commit comments

Comments
 (0)