Skip to content

Instantly share code, notes, and snippets.

@goddessfreya
Created July 15, 2018 20:47
Show Gist options
  • Save goddessfreya/b89b13c108d7242b8a4608cac59f063b to your computer and use it in GitHub Desktop.
Save goddessfreya/b89b13c108d7242b8a4608cac59f063b to your computer and use it in GitHub Desktop.
diff --git a/src/api/egl/mod.rs b/src/api/egl/mod.rs
index e85c66f..25a7b65 100644
--- a/src/api/egl/mod.rs
+++ b/src/api/egl/mod.rs
@@ -39,7 +39,7 @@ pub struct Context {
egl: ffi::egl::Egl,
display: ffi::egl::types::EGLDisplay,
context: ffi::egl::types::EGLContext,
- surface: Cell<ffi::egl::types::EGLSurface>,
+ //surface: Cell<ffi::egl::types::EGLSurface>,
api: Api,
pixel_format: PixelFormat,
config_id: ffi::egl::types::EGLConfig,
@@ -170,11 +170,12 @@ impl Context {
) -> Result<ContextPrototype<'a>, CreationError>
{
// calling `eglGetDisplay` or equivalent
- let display = get_native_display(&egl, native_display);
+ //let display = get_native_display(&egl, native_display);
- if display.is_null() {
- return Err(CreationError::OsError("Could not create EGL display object".to_string()));
- }
+ //if display.is_null() {
+ // return Err(CreationError::OsError("Could not create EGL display object".to_string()));
+ //}
+ let display = unsafe { egl.GetDisplay(ffi::egl::DEFAULT_DISPLAY as *mut _) };
let egl_version = unsafe {
let mut major: ffi::egl::types::EGLint = mem::uninitialized();
@@ -266,7 +267,7 @@ impl Context {
}
pub unsafe fn make_current(&self) -> Result<(), ContextError> {
- let ret = self.egl.MakeCurrent(self.display, self.surface.get(), self.surface.get(), self.context);
+ let ret = self.egl.MakeCurrent(self.display, ffi::egl::NO_SURFACE, ffi::egl::NO_SURFACE, self.context);
if ret == 0 {
match self.egl.GetError() as u32 {
@@ -294,23 +295,8 @@ impl Context {
#[inline]
pub fn swap_buffers(&self) -> Result<(), ContextError> {
- if self.surface.get() == ffi::egl::NO_SURFACE {
return Err(ContextError::ContextLost);
- }
-
- let ret = unsafe {
- self.egl.SwapBuffers(self.display, self.surface.get())
- };
-
- if ret == 0 {
- match unsafe { self.egl.GetError() } as u32 {
- ffi::egl::CONTEXT_LOST => return Err(ContextError::ContextLost),
- err => panic!("eglSwapBuffers failed (eglGetError returned 0x{:x})", err)
- }
- } else {
- Ok(())
- }
}
#[inline]
@@ -375,7 +361,7 @@ impl Drop for Context {
// we don't call MakeCurrent(0, 0) because we are not sure that the context
// is still the current one
self.egl.DestroyContext(self.display, self.context);
- self.egl.DestroySurface(self.display, self.surface.get());
+ //self.egl.DestroySurface(self.display, self.surface.get());
self.egl.Terminate(self.display);
}
}
@@ -403,19 +389,10 @@ impl<'a> ContextPrototype<'a> {
value
}
- pub fn finish(self, native_window: ffi::EGLNativeWindowType)
+ pub fn finish(self)
-> Result<Context, CreationError>
{
- let surface = unsafe {
- let surface = self.egl.CreateWindowSurface(self.display, self.config_id, native_window,
- ptr::null());
- if surface.is_null() {
- return Err(CreationError::OsError(format!("eglCreateWindowSurface failed")))
- }
- surface
- };
-
- self.finish_impl(surface)
+ self.finish_pbuffer((1, 1))
}
pub fn finish_pbuffer(self, dimensions: (u32, u32)) -> Result<Context, CreationError> {
@@ -495,7 +472,7 @@ impl<'a> ContextPrototype<'a> {
egl: self.egl,
display: self.display,
context: context,
- surface: Cell::new(surface),
+ //surface: Cell::new(surface),
api: self.api,
pixel_format: self.pixel_format,
config_id: self.config_id
diff --git a/src/lib.rs b/src/lib.rs
index d678907..c7754a5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -178,7 +178,7 @@ pub struct ContextBuilder<'a> {
/// ```
pub struct GlWindow {
context: Context,
- window: Window,
+ //window: Window,
}
impl<'a> ContextBuilder<'a> {
@@ -339,7 +339,7 @@ impl GlWindow {
/// this function. It is also shareable with headless contexts made with the
/// `shareable_with_windowed_contexts` flag set to `true`.
///
- /// One limitation of the wayland backend when it comes to shared contexts
+ /// One limitation of the wayland backend when it comes to shared contexts
/// is tha both contexts must use the same events loop.
///
/// Error should be very rare and only occur in case of permission denied,
@@ -354,16 +354,11 @@ impl GlWindow {
let gl_attr = gl_attr.map_sharing(|ctxt| &ctxt.context);
platform::Context::new(window_builder, events_loop, &pf_reqs, &gl_attr)
.map(|(window, context)| GlWindow {
- window: window,
+ //window: window,
context: Context { context: context },
})
}
- /// Borrow the inner `Window`.
- pub fn window(&self) -> &Window {
- &self.window
- }
-
/// Borrow the inner GL `Context`.
pub fn context(&self) -> &Context {
&self.context
@@ -429,7 +424,7 @@ impl Context {
/// If the flag is not set on the otherhand, the context can only be shared
/// with other contexts made with the flag unset.
///
- /// One limitation of the wayland backend when it comes to shared contexts
+ /// One limitation of the wayland backend when it comes to shared contexts
/// is tha both contexts must use the same events loop.
///
/// Error should be very rare and only occur in case of permission denied,
@@ -465,13 +460,6 @@ impl GlContext for GlWindow {
}
}
-impl std::ops::Deref for GlWindow {
- type Target = Window;
- fn deref(&self) -> &Self::Target {
- &self.window
- }
-}
-
/// Error that can happen while creating a window or a headless renderer.
#[derive(Debug)]
pub enum CreationError {
diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs
index 555d7a4..cc865ca 100644
--- a/src/platform/linux/mod.rs
+++ b/src/platform/linux/mod.rs
@@ -30,9 +30,9 @@ pub enum ContextType {
pub enum Context {
WindowedX11(x11::Context),
- HeadlessX11(winit::Window, x11::Context),
+ HeadlessX11((), x11::Context),
WindowedWayland(wayland::Context),
- HeadlessWayland(winit::Window, wayland::Context),
+ HeadlessWayland((), wayland::Context),
OsMesa(osmesa::OsMesaContext),
}
@@ -79,7 +79,7 @@ impl Context {
events_loop: &winit::EventsLoop,
pf_reqs: &PixelFormatRequirements,
gl_attr: &GlAttributes<&Context>,
- ) -> Result<(winit::Window, Self), CreationError>
+ ) -> Result<((), Self), CreationError>
{
if events_loop.is_wayland() {
Context::is_compatible(&gl_attr.sharing, ContextType::Wayland)?;
@@ -89,7 +89,7 @@ impl Context {
_ => unreachable!(),
});
wayland::Context::new(window_builder, events_loop, pf_reqs, &gl_attr)
- .map(|(window, context)| (window, Context::WindowedWayland(context)))
+ .map(|(window, context)| ((), Context::WindowedWayland(context)))
} else {
Context::is_compatible(&gl_attr.sharing, ContextType::X11)?;
let gl_attr = gl_attr.clone().map_sharing(|ctxt| match ctxt {
diff --git a/src/platform/linux/wayland.rs b/src/platform/linux/wayland.rs
index 071b350..043d771 100644
--- a/src/platform/linux/wayland.rs
+++ b/src/platform/linux/wayland.rs
@@ -8,29 +8,27 @@ use api::egl::{self, ffi, Context as EglContext};
use wayland_client::egl as wegl;
pub struct Context {
- egl_surface: Arc<wegl::WlEglSurface>,
+ //egl_surface: Arc<wegl::WlEglSurface>,
context: EglContext,
}
impl Context {
pub fn new(
- window_builder: winit::WindowBuilder,
- events_loop: &winit::EventsLoop,
+ _window_builder: winit::WindowBuilder,
+ _events_loop: &winit::EventsLoop,
pf_reqs: &PixelFormatRequirements,
gl_attr: &GlAttributes<&Context>,
- ) -> Result<(winit::Window, Self), CreationError>
+ ) -> Result<((), Self), CreationError>
{
- let window = window_builder.build(events_loop)?;
- let logical_size = window.get_inner_size().unwrap();
- let (w, h) = (logical_size.width, logical_size.height);
+ let (w, h) = (1, 1);
- let surface = window.get_wayland_surface();
- let surface = match surface {
- Some(s) => s,
- None => return Err(CreationError::NotSupported("Wayland not found")),
- };
+ //let surface = window.get_wayland_surface();
+ //let surface = match surface {
+ // Some(s) => s,
+ // None => return Err(CreationError::NotSupported("Wayland not found")),
+ //};
- let egl_surface = unsafe { wegl::WlEglSurface::new_from_raw(surface as *mut _, w as i32, h as i32) };
+ //let egl_surface = unsafe { wegl::WlEglSurface::new_from_raw(surface as *mut _, w as i32, h as i32) };
let context = {
let libegl = unsafe { dlopen::dlopen(b"libEGL.so\0".as_ptr() as *const _, dlopen::RTLD_NOW) };
if libegl.is_null() {
@@ -42,21 +40,22 @@ impl Context {
});
let gl_attr = gl_attr.clone().map_sharing(|c| &c.context);
let native_display = egl::NativeDisplay::Wayland(Some(
- window.get_wayland_display().unwrap() as *const _
+ //window.get_wayland_display().unwrap() as *const _
+ unsafe { egl.GetDisplay(ffi::egl::DEFAULT_DISPLAY as *mut _) as *const _}
));
EglContext::new(egl, pf_reqs, &gl_attr, native_display)
- .and_then(|p| p.finish(egl_surface.ptr() as *const _))?
+ .and_then(|p| p.finish())?
};
let context = Context {
- egl_surface: Arc::new(egl_surface),
+ //egl_surface: Arc::new(egl_surface),
context: context,
};
- Ok((window, context))
+ Ok(((), context))
}
#[inline]
pub fn resize(&self, width: u32, height: u32) {
- self.egl_surface.resize(width as i32, height as i32, 0, 0);
+ //self.egl_surface.resize(width as i32, height as i32, 0, 0);
}
#[inline]
diff --git a/src/platform/linux/x11.rs b/src/platform/linux/x11.rs
index 606053b..cb43849 100644
--- a/src/platform/linux/x11.rs
+++ b/src/platform/linux/x11.rs
@@ -111,11 +111,11 @@ impl Drop for Context {
impl Context {
pub fn new(
- window_builder: winit::WindowBuilder,
+ _window_builder: winit::WindowBuilder,
events_loop: &winit::EventsLoop,
pf_reqs: &PixelFormatRequirements,
gl_attr: &GlAttributes<&Context>,
- ) -> Result<(winit::Window, Self), CreationError>
+ ) -> Result<((), Self), CreationError>
{
let xconn = match events_loop.get_xlib_xconnection() {
Some(xconn) => xconn,
@@ -154,7 +154,7 @@ impl Context {
pf_reqs,
&builder_glx_u,
screen_id,
- window_builder.window.transparent,
+ true,
)?)
} else if let Some(ref egl) = backend.egl {
builder_egl_u = builder.map_sharing(|c| match c.context {
@@ -215,19 +215,14 @@ impl Context {
},
};
- let window = window_builder
- .with_x11_visual(&visual_infos as *const _)
- .with_x11_screen(screen_id)
- .build(events_loop)?;
-
- let xlib_window = window.get_xlib_window().unwrap();
+ let xlib_window = unsafe { (xconn.xlib.XDefaultRootWindow)(xconn.display) };
// finish creating the OpenGL context
let context = match context {
Prototype::Glx(ctxt) => {
GlContext::Glx(ctxt.finish(xlib_window)?)
},
Prototype::Egl(ctxt) => {
- GlContext::Egl(ctxt.finish(xlib_window as _)?)
+ GlContext::Egl(ctxt.finish()?)
},
};
@@ -250,7 +245,7 @@ impl Context {
colormap,
};
- Ok((window, context))
+ Ok(((), context))
}
#[inline]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment