use wrapper struct to enforce common api between platforms
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
use raw_gl_context::GlContext;
|
||||
|
||||
use raw_window_handle::HasRawWindowHandle;
|
||||
|
||||
use baseview::{Event, Window, WindowHandler, WindowScalePolicy};
|
||||
|
||||
struct Example {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use raw_gl_context::GlContext;
|
||||
|
||||
use raw_window_handle::HasRawWindowHandle;
|
||||
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit::window::WindowBuilder;
|
||||
|
||||
|
||||
41
src/lib.rs
41
src/lib.rs
@@ -1,14 +1,49 @@
|
||||
use raw_window_handle::HasRawWindowHandle;
|
||||
|
||||
use std::ffi::c_void;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod win;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use win::*;
|
||||
use win as platform;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod x11;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub use crate::x11::*;
|
||||
use crate::x11 as platform;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
mod macos;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use macos::*;
|
||||
use macos as platform;
|
||||
|
||||
pub struct GlContext {
|
||||
context: platform::GlContext,
|
||||
phantom: PhantomData<*mut ()>,
|
||||
}
|
||||
|
||||
impl GlContext {
|
||||
pub fn create(parent: &impl HasRawWindowHandle) -> Result<GlContext, ()> {
|
||||
platform::GlContext::create(parent).map(|context| GlContext {
|
||||
context,
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn make_current(&self) {
|
||||
self.context.make_current();
|
||||
}
|
||||
|
||||
pub fn make_not_current(&self) {
|
||||
self.context.make_not_current();
|
||||
}
|
||||
|
||||
pub fn get_proc_address(&self, symbol: &str) -> *const c_void {
|
||||
self.context.get_proc_address(symbol)
|
||||
}
|
||||
|
||||
pub fn swap_buffers(&self) {
|
||||
self.context.swap_buffers();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user