pass size on creation
This commit is contained in:
parent
c40ff3e324
commit
a8f72096d8
|
|
@ -124,7 +124,7 @@ impl OrbitalCamera {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Core {
|
impl Core {
|
||||||
pub fn new(gpu: Gpu) -> Self {
|
pub fn new(gpu: Gpu, pixel_size: UVec2) -> Self {
|
||||||
let Gpu {
|
let Gpu {
|
||||||
device,
|
device,
|
||||||
queue,
|
queue,
|
||||||
|
|
@ -136,14 +136,16 @@ impl Core {
|
||||||
let tripod = new_tripod(&device);
|
let tripod = new_tripod(&device);
|
||||||
queue.submit([]); // flush buffer updates
|
queue.submit([]); // flush buffer updates
|
||||||
|
|
||||||
Self {
|
let mut this = Self {
|
||||||
device,
|
device,
|
||||||
queue,
|
queue,
|
||||||
surface,
|
surface,
|
||||||
pipeline,
|
pipeline,
|
||||||
tripod,
|
tripod,
|
||||||
mesh_pipe,
|
mesh_pipe,
|
||||||
}
|
};
|
||||||
|
this.configure(pixel_size);
|
||||||
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&self, output: &wgpu::Texture, args: &RedrawArgs) {
|
fn render(&self, output: &wgpu::Texture, args: &RedrawArgs) {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@ impl MainWindow {
|
||||||
instance.create_surface(Arc::clone(&window))
|
instance.create_surface(Arc::clone(&window))
|
||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut core = Core::new(gpu);
|
let core = Core::new(gpu, uvec2(1, 1));
|
||||||
core.configure(uvec2(1, 1));
|
|
||||||
Self { window, core }
|
Self { window, core }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace ffi {
|
namespace ffi {
|
||||||
extern "C" Core* rt4_viewport_create(xcb_connection_t* connection, std::uint32_t window);
|
extern "C" Core* rt4_viewport_create(xcb_connection_t* connection, std::uint32_t window, std::uint32_t width, std::uint32_t height);
|
||||||
extern "C" void rt4_viewport_destroy(Core* viewport);
|
extern "C" void rt4_viewport_destroy(Core* viewport);
|
||||||
extern "C" void rt4_viewport_configure(Core* viewport, std::uint32_t width, std::uint32_t height);
|
extern "C" void rt4_viewport_configure(Core* viewport, std::uint32_t width, std::uint32_t height);
|
||||||
extern "C" void rt4_viewport_redraw(Core* viewport, const RedrawArgs* args);
|
extern "C" void rt4_viewport_redraw(Core* viewport, const RedrawArgs* args);
|
||||||
|
|
@ -26,13 +26,13 @@ BoxCore& BoxCore::operator=(BoxCore&& b) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoxCore BoxCore::from_xcb(xcb_connection_t* connection, std::uint32_t window) {
|
BoxCore BoxCore::from_xcb(xcb_connection_t* connection, std::uint32_t window, std::uint32_t width, std::uint32_t height) {
|
||||||
if (!connection)
|
if (!connection)
|
||||||
throw std::logic_error("attempt to use a null connection");
|
throw std::logic_error("attempt to use a null connection");
|
||||||
if (!window)
|
if (!window)
|
||||||
throw std::logic_error("attempt to use a null window");
|
throw std::logic_error("attempt to use a null window");
|
||||||
BoxCore out;
|
BoxCore out;
|
||||||
out.ptr.ptr = ffi::rt4_viewport_create(connection, window);
|
out.ptr.ptr = ffi::rt4_viewport_create(connection, window, width, height);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ public:
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
static BoxCore from_xcb(xcb_connection_t* connection, std::uint32_t window);
|
static BoxCore from_xcb(xcb_connection_t* connection, std::uint32_t window, std::uint32_t width, std::uint32_t height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MutCore ptr;
|
MutCore ptr;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
use std::{ffi::c_void, num::NonZero, ptr::NonNull};
|
use std::{ffi::c_void, num::NonZero, ptr::NonNull};
|
||||||
|
|
||||||
use glam::uvec2;
|
use glam::{UVec2, uvec2};
|
||||||
use photon_light::{Core, RedrawArgs, init_gpu_inner};
|
use photon_light::{Core, RedrawArgs, init_gpu_inner};
|
||||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XcbDisplayHandle, XcbWindowHandle};
|
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XcbDisplayHandle, XcbWindowHandle};
|
||||||
|
|
||||||
unsafe fn create_viewport(
|
unsafe fn create_viewport(
|
||||||
display: impl Into<RawDisplayHandle>,
|
display: impl Into<RawDisplayHandle>,
|
||||||
window: impl Into<RawWindowHandle>,
|
window: impl Into<RawWindowHandle>,
|
||||||
|
size: UVec2,
|
||||||
) -> Box<Core> {
|
) -> Box<Core> {
|
||||||
let target = wgpu::SurfaceTargetUnsafe::RawHandle {
|
let target = wgpu::SurfaceTargetUnsafe::RawHandle {
|
||||||
raw_display_handle: display.into(),
|
raw_display_handle: display.into(),
|
||||||
|
|
@ -16,17 +17,19 @@ unsafe fn create_viewport(
|
||||||
instance.create_surface_unsafe(target)
|
instance.create_surface_unsafe(target)
|
||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Box::new(Core::new(gpu))
|
Box::new(Core::new(gpu, size))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
unsafe extern "C" fn rt4_viewport_create(
|
unsafe extern "C" fn rt4_viewport_create(
|
||||||
connection: NonNull<c_void>,
|
connection: NonNull<c_void>,
|
||||||
window: NonZero<u32>,
|
window: NonZero<u32>,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
) -> Box<Core> {
|
) -> Box<Core> {
|
||||||
let display = XcbDisplayHandle::new(Some(connection), 0);
|
let display = XcbDisplayHandle::new(Some(connection), 0);
|
||||||
let window = XcbWindowHandle::new(window);
|
let window = XcbWindowHandle::new(window);
|
||||||
unsafe { create_viewport(display, window) }
|
unsafe { create_viewport(display, window, uvec2(width, height)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,9 @@ void Viewport::recreate() try {
|
||||||
|
|
||||||
fprintf(stderr, "connection %p, window %#08x\n", xcb_connection, x11_window);
|
fprintf(stderr, "connection %p, window %#08x\n", xcb_connection, x11_window);
|
||||||
|
|
||||||
|
const QSize device_size = size() * devicePixelRatio();
|
||||||
core.reset();
|
core.reset();
|
||||||
core = BoxCore::from_xcb(xcb_connection, x11_window);
|
core = BoxCore::from_xcb(xcb_connection, x11_window, device_size.width(), device_size.height());
|
||||||
updateSize();
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
fprintf(stderr, "failed to recreate the viewport: %s", e.what());
|
fprintf(stderr, "failed to recreate the viewport: %s", e.what());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user