Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the windows-static-egl Cargo feature #998

Closed

Conversation

SimonSapin
Copy link
Contributor

Fixes #997: this allows using Glutin together with https://crates.io/crates/mozangle

@SimonSapin
Copy link
Contributor Author

Should mozangle be mentioned in the doc as a possible way to use this feature?

Should mozangle be added as in dev-dependencies and the program below added under examples/?

#[cfg(not(windows))]
fn main() {
    println!("This example only runs on Windows.");
}

#[cfg(windows)] extern crate mozangle;
#[cfg(windows)] extern crate glutin;

#[cfg(windows)]
fn main() {
    use glutin::GlContext;
    use glutin::os::GlContextExt;
    use glutin::os::windows::RawHandle;
    use mozangle::egl::get_proc_address;
    use mozangle::gles::ffi as gl;

    let mut events_loop = glutin::EventsLoop::new();
    let window = glutin::WindowBuilder::new();
    let context = glutin::ContextBuilder::new()
        // Requesting OpenGlEs is required to make glutin try to use EGL.
        .with_gl(glutin::GlRequest::Specific(glutin::Api::OpenGlEs, (2, 0)));
    let gl_window = glutin::GlWindow::new(window, context, &events_loop).unwrap();

    let handle = unsafe {
        gl_window.context().raw_handle()
    };
    match handle {
        RawHandle::Egl(_) => {},
        RawHandle::Wgl(_) => panic!("Expected an EGL context, found a WGL one.")
    }

    assert_ne!(gl_window.get_proc_address("glClearColor"), 0 as _);
    assert_eq!(gl_window.get_proc_address("glClearColor"), get_proc_address("glClearColor") as _);

    unsafe {
        gl_window.make_current().unwrap();
        gl::ClearColor(0., 0.5, 0., 1.);
    }

    events_loop.run_forever(|event| {
        match event {
            glutin::Event::WindowEvent { event, .. } => match event {
                glutin::WindowEvent::Closed => return glutin::ControlFlow::Break,
                glutin::WindowEvent::Resized(w, h) => gl_window.resize(w, h),
                _ => (),
            },
            _ => ()
        }

        unsafe {
            gl::Clear(gl::COLOR_BUFFER_BIT);
        }

        gl_window.swap_buffers().unwrap();
        glutin::ControlFlow::Continue
    });
}

@SimonSapin
Copy link
Contributor Author

The example program in the previous comment is subject to rust-windowing/winit#415. (Maybe Clear + swap_buffers is slow in debug mode? And re-rendering on non-resize events is unnecessary.)

bors-servo pushed a commit to servo/webrender that referenced this pull request Mar 6, 2018
Switch from servo/angle to the mozangle crate

https://github.com/servo/mozangle

This is a step towards #2420. (The next step is blocked on rust-windowing/glutin#998.)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/2492)
<!-- Reviewable:end -->
bors-servo pushed a commit to servo/webrender that referenced this pull request Mar 6, 2018
Switch from servo/angle to the mozangle crate

https://github.com/servo/mozangle

This is a step towards #2420. (The next step is blocked on rust-windowing/glutin#998.)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/2492)
<!-- Reviewable:end -->
@tomaka
Copy link
Contributor

tomaka commented Mar 14, 2018

I'm not fan of this feature but I guess I will merge anyway.

Please solve the conflict, and also please remove the example because for such a niche feature I don't think an example really makes sense.

@SimonSapin
Copy link
Contributor Author

SimonSapin commented Mar 15, 2018

I’m not really a fan of it either. I think it’s preferable for WebRender/Wrench to use winit + EGL instead of this: servo/webrender#2529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants