glupload: update glutin API

GlWindow was dropped in favor of CombinedContext and ContextTrait

Fixes: #190
This commit is contained in:
Víctor Manuel Jáquez Leal 2019-02-27 19:58:04 +01:00
parent 490004d9c5
commit 07ddf2f370

View file

@ -30,8 +30,8 @@ extern crate failure_derive;
extern crate glutin; extern crate glutin;
use glutin::os::unix::RawHandle; use glutin::os::unix::RawHandle;
use glutin::os::GlContextExt; use glutin::os::ContextTraitExt;
use glutin::GlContext; use glutin::ContextTrait;
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
@ -53,10 +53,6 @@ struct ErrorMessage {
cause: glib::Error, cause: glib::Error,
} }
#[derive(Debug, Fail)]
#[fail(display = "Glutin error")]
struct GlutinError();
#[cfg_attr(rustfmt, rustfmt_skip)] #[cfg_attr(rustfmt, rustfmt_skip)]
static VERTICES: [f32; 20] = [ static VERTICES: [f32; 20] = [
1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0,
@ -332,7 +328,7 @@ struct App {
appsink: gst_app::AppSink, appsink: gst_app::AppSink,
bus: gst::Bus, bus: gst::Bus,
events_loop: Arc<glutin::EventsLoop>, events_loop: Arc<glutin::EventsLoop>,
gl_window: Arc<glutin::GlWindow>, combined_context: Arc<glutin::CombinedContext>,
} }
impl App { impl App {
@ -346,13 +342,14 @@ impl App {
let events_loop = glutin::EventsLoop::new(); let events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new().with_title("GL rendering"); let window = glutin::WindowBuilder::new().with_title("GL rendering");
let context = glutin::ContextBuilder::new(); let combined_context = Arc::new(
let gl_window = Arc::new( glutin::ContextBuilder::new()
glutin::GlWindow::new(window, context, &events_loop).or_else(|_| Err(GlutinError()))?, .with_vsync(true)
.build_combined(window, &events_loop)?,
); );
let window_ = gl_window.clone(); let combined_context_ = combined_context.clone();
let context = window_.context(); let context = combined_context_.context();
let egl_context = match unsafe { context.raw_handle() } { let egl_context = match unsafe { context.raw_handle() } {
RawHandle::Egl(egl_context) => egl_context as usize, RawHandle::Egl(egl_context) => egl_context as usize,
_ => panic!("Invalid platform"), _ => panic!("Invalid platform"),
@ -410,7 +407,7 @@ impl App {
appsink, appsink,
bus, bus,
events_loop: Arc::new(events_loop), events_loop: Arc::new(events_loop),
gl_window, combined_context: combined_context,
}) })
} }
@ -533,28 +530,28 @@ impl App {
} }
fn main_loop(mut app: App) -> Result<(), Error> { fn main_loop(mut app: App) -> Result<(), Error> {
let _ = unsafe { app.gl_window.make_current() }; unsafe { app.combined_context.make_current()? };
println!( println!(
"Pixel format of the window's GL context {:?}", "Pixel format of the window's GL context {:?}",
app.gl_window.get_pixel_format() app.combined_context.get_pixel_format()
); );
let gl = load(&app.gl_window.context()); let gl = load(&app.combined_context.context());
let (bus_handler, receiver) = app.setup()?; let (bus_handler, receiver) = app.setup()?;
let mut curr_frame: Option<Arc<gst_video::VideoFrame<gst_video::video_frame::Readable>>> = None; let mut curr_frame: Option<Arc<gst_video::VideoFrame<gst_video::video_frame::Readable>>> = None;
let mut running = true; let mut running = true;
let events_loop = Arc::get_mut(&mut app.events_loop).unwrap(); let events_loop = Arc::get_mut(&mut app.events_loop).unwrap();
let gl_window = app.gl_window.clone(); let combined_context = app.combined_context.clone();
while running { while running {
events_loop.poll_events(|event| match event { events_loop.poll_events(|event| match event {
glutin::Event::WindowEvent { event, .. } => match event { glutin::Event::WindowEvent { event, .. } => match event {
glutin::WindowEvent::CloseRequested => running = false, glutin::WindowEvent::CloseRequested => running = false,
glutin::WindowEvent::Resized(logical_size) => { glutin::WindowEvent::Resized(logical_size) => {
let dpi_factor = gl_window.get_hidpi_factor(); let dpi_factor = combined_context.get_hidpi_factor();
gl_window.resize(logical_size.to_physical(dpi_factor)); combined_context.resize(logical_size.to_physical(dpi_factor));
gl.resize(logical_size.to_physical(dpi_factor)); gl.resize(logical_size.to_physical(dpi_factor));
} }
_ => (), _ => (),
@ -579,7 +576,7 @@ fn main_loop(mut app: App) -> Result<(), Error> {
gl.draw_frame(texture as gl::types::GLuint); gl.draw_frame(texture as gl::types::GLuint);
} }
} }
let _ = app.gl_window.swap_buffers(); app.combined_context.swap_buffers()?;
} }
app.pipeline.send_event(gst::Event::new_eos().build()); app.pipeline.send_event(gst::Event::new_eos().build());