Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed Feb 5, 2020
1 parent 32f8e4a commit 691cfc9
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 120 deletions.
16 changes: 11 additions & 5 deletions examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,34 @@ fn main() {
let ctx = unsafe { ContextBuilder::new().build(conf).unwrap() };
let (win, surf) = unsafe { Surface::new_window(conf, &*el, wb).unwrap() };

unsafe { ctx.make_current(&surf).unwrap() }
let gl = support::Gl::load(|s| ctx.get_proc_address(s).unwrap());

let mut gl = None;
el.run(move |event, _, control_flow| {
println!("{:?}", event);
*control_flow = ControlFlow::Wait;

match event {
Event::Resumed => {
unsafe { ctx.make_current(&surf).unwrap() }
gl = Some(support::Gl::load(|s| ctx.get_proc_address(s).unwrap()));
}
Event::Suspended => gl = None,
Event::LoopDestroyed => return,
Event::MainEventsCleared => {
win.request_redraw();
}
Event::RedrawRequested(_) => {
gl.draw_frame([1.0, 0.5, 0.7, 1.0]);
gl.as_ref().unwrap().draw_frame([1.0, 0.5, 0.7, 1.0]);
surf.swap_buffers().unwrap();
}
Event::WindowEvent { ref event, .. } => match event {
WindowEvent::Resized(size) => {
ctx.update_after_resize();
surf.update_after_resize(*size);
unsafe {
gl.gl.Viewport(0, 0, size.width as _, size.height as _);
gl.as_ref()
.unwrap()
.gl
.Viewport(0, 0, size.width as _, size.height as _);
}
}
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
Expand Down
78 changes: 7 additions & 71 deletions src/api/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ macro_rules! attrib {

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Config {
display: Arc<Display>,
config: ffi::EGLConfig,
pub(crate) display: Arc<Display>,
pub(crate) config: ffi::EGLConfig,
}

unsafe impl Send for Config {}
Expand Down Expand Up @@ -980,70 +980,6 @@ impl Context {
self.config.clone()
}

// FIXME: Needed for android support.
// winit doesn't have it, I'll add this back in when it does.
//
// // Handle Android Life Cycle.
// // Android has started the activity or sent it to foreground.
// // Create a new surface and attach it to the recreated ANativeWindow.
// // Restore the EGLContext.
// #[cfg(target_os = "android")]
// pub unsafe fn on_surface_created(&self, nwin: ffi::EGLNativeWindowType) {
// let egl = EGL.as_ref().unwrap();
// let mut surface = self.surface.as_ref().unwrap().lock();
// if *surface != ffi::egl::NO_SURFACE {
// return;
// }
// *surface = egl.CreateWindowSurface(
// **self.display,
// self.config,
// nwin,
// std::ptr::null(),
// );
// if surface.is_null() {
// panic!(
// "[glutin] on_surface_created: eglCreateWindowSurface failed with
// 0x{:x}", egl.GetError()
// )
// }
// let ret =
// egl.MakeCurrent(**self.display, *surface, *surface,
// self.context); if ret == 0 {
// panic!(
// "[glutin] on_surface_created: eglMakeCurrent failed with 0x{:x}",
// egl.GetError()
// )
// }
// }
//
// // Handle Android Life Cycle.
// // Android has stopped the activity or sent it to background.
// // Release the surface attached to the destroyed ANativeWindow.
// // The EGLContext is not destroyed so it can be restored later.
// #[cfg(target_os = "android")]
// pub unsafe fn on_surface_destroyed(&self) {
// let egl = EGL.as_ref().unwrap();
// let mut surface = self.surface.as_ref().unwrap().lock();
// if *surface == ffi::egl::NO_SURFACE {
// return;
// }
// let ret = egl.MakeCurrent(
// **self.display,
// ffi::egl::NO_SURFACE,
// ffi::egl::NO_SURFACE,
// ffi::egl::NO_CONTEXT,
// );
// if ret == 0 {
// panic!(
// "[glutin] on_surface_destroyed: eglMakeCurrent failed with 0x{:x}",
// egl.GetError()
// )
// }
//
// egl.DestroySurface(**self.display, *surface);
// *surface = ffi::egl::NO_SURFACE;
// }

#[inline]
pub fn get_proc_address(&self, addr: &str) -> Result<*const raw::c_void, Error> {
let egl = EGL.as_ref().unwrap();
Expand All @@ -1053,7 +989,7 @@ impl Context {
}

#[inline]
fn check_errors(ret: Option<u32>) -> Result<(), Error> {
pub(crate) fn check_errors(ret: Option<u32>) -> Result<(), Error> {
let egl = EGL.as_ref().unwrap();
if ret == Some(ffi::egl::FALSE) || ret == None {
match unsafe { egl.GetError() } as u32 {
Expand Down Expand Up @@ -1098,10 +1034,10 @@ pub fn get_native_visual_id(

#[derive(Debug, PartialEq, Eq)]
pub struct Surface<T: SurfaceTypeTrait> {
display: Arc<Display>,
surface: ffi::EGLSurface,
config: ConfigWrapper<Config, ConfigAttribs>,
phantom: PhantomData<T>,
pub(crate) display: Arc<Display>,
pub(crate) surface: ffi::EGLSurface,
pub(crate) config: ConfigWrapper<Config, ConfigAttribs>,
pub(crate) phantom: PhantomData<T>,
}

unsafe impl<T: SurfaceTypeTrait> Send for Surface<T> {}
Expand Down
Loading

0 comments on commit 691cfc9

Please sign in to comment.