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