use wrapper struct to enforce common api between platforms

This commit is contained in:
Micah Johnston
2020-12-13 20:29:38 -06:00
parent f9af040f91
commit d846c70c6e
3 changed files with 38 additions and 7 deletions

View File

@@ -1,7 +1,5 @@
use raw_gl_context::GlContext;
use raw_window_handle::HasRawWindowHandle;
use baseview::{Event, Window, WindowHandler, WindowScalePolicy};
struct Example {

View File

@@ -1,7 +1,5 @@
use raw_gl_context::GlContext;
use raw_window_handle::HasRawWindowHandle;
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;

View File

@@ -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();
}
}