feat: basic smithay setup
This commit is contained in:
63
src/main.rs
63
src/main.rs
@@ -1,14 +1,22 @@
|
||||
mod core;
|
||||
mod nodes;
|
||||
mod wayland;
|
||||
|
||||
use crate::nodes::model::{MODELS_TO_DROP, MODEL_REGISTRY};
|
||||
use crate::wayland::{ClientState, WaylandState};
|
||||
|
||||
use self::core::eventloop::EventLoop;
|
||||
use anyhow::Result;
|
||||
use anyhow::{ensure, Result};
|
||||
use clap::Parser;
|
||||
use once_cell::sync::Lazy;
|
||||
use parking_lot::Mutex;
|
||||
use slog::Drain;
|
||||
use smithay::backend::egl::EGLContext;
|
||||
use smithay::backend::renderer::gles2::Gles2Renderer;
|
||||
use smithay::reexports::wayland_server::{Display, ListeningSocket};
|
||||
use std::ffi::c_void;
|
||||
use std::sync::Arc;
|
||||
use stereokit as sk;
|
||||
use stereokit::{lifecycle::DisplayMode, Settings};
|
||||
use tokio::{runtime::Handle, sync::oneshot};
|
||||
|
||||
@@ -26,8 +34,31 @@ struct CliArgs {
|
||||
overlay: bool,
|
||||
}
|
||||
|
||||
struct EGLRawHandles {
|
||||
display: *const c_void,
|
||||
config: *const c_void,
|
||||
context: *const c_void,
|
||||
}
|
||||
fn get_sk_egl() -> Result<EGLRawHandles> {
|
||||
ensure!(
|
||||
unsafe { sk::sys::backend_graphics_get() }
|
||||
== sk::sys::backend_graphics__backend_graphics_opengles_egl,
|
||||
"StereoKit is not running using EGL!"
|
||||
);
|
||||
|
||||
Ok(unsafe {
|
||||
EGLRawHandles {
|
||||
display: sk::sys::backend_opengl_egl_get_display() as *const c_void,
|
||||
config: sk::sys::backend_opengl_egl_get_config() as *const c_void,
|
||||
context: sk::sys::backend_opengl_egl_get_context() as *const c_void,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let cli_args = Arc::new(CliArgs::parse());
|
||||
let log = ::slog::Logger::root(::slog_stdlog::StdLog.fuse(), slog::o!());
|
||||
slog_stdlog::init()?;
|
||||
|
||||
let stereokit = Settings::default()
|
||||
.app_name("Stardust XR")
|
||||
@@ -47,13 +78,43 @@ fn main() -> Result<()> {
|
||||
.name("event_loop".to_owned())
|
||||
.spawn(move || event_loop(event_stop_rx))?;
|
||||
|
||||
let egl_raw_handles = get_sk_egl()?;
|
||||
let renderer = unsafe {
|
||||
Gles2Renderer::new(
|
||||
EGLContext::from_raw(
|
||||
egl_raw_handles.display,
|
||||
egl_raw_handles.config,
|
||||
egl_raw_handles.context,
|
||||
log.clone(),
|
||||
)?,
|
||||
log.clone(),
|
||||
)?
|
||||
};
|
||||
|
||||
let mut display: Display<WaylandState> = Display::new()?;
|
||||
let socket = ListeningSocket::bind_auto("wayland", 0..33)?;
|
||||
if let Some(socket_name) = socket.socket_name() {
|
||||
println!("Wayland compositor {:?} active", socket_name);
|
||||
}
|
||||
let mut wayland_state = WaylandState::new(&display, renderer, log)?;
|
||||
|
||||
stereokit.run(
|
||||
|draw_ctx| {
|
||||
if let Ok(Some(client)) = socket.accept() {
|
||||
let _ = display
|
||||
.handle()
|
||||
.insert_client(client, Arc::new(ClientState));
|
||||
}
|
||||
display.dispatch_clients(&mut wayland_state).unwrap();
|
||||
display.flush_clients().unwrap();
|
||||
|
||||
nodes::root::Root::logic_step(stereokit.time_elapsed());
|
||||
for model in MODEL_REGISTRY.get_valid_contents() {
|
||||
model.draw(&stereokit, draw_ctx);
|
||||
}
|
||||
MODELS_TO_DROP.lock().clear();
|
||||
|
||||
unsafe { wayland_state.renderer.egl_context().make_current().unwrap() };
|
||||
},
|
||||
|| {
|
||||
println!("Cleanly shut down StereoKit");
|
||||
|
||||
Reference in New Issue
Block a user