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

Sample code for shared contexts #852

Closed
jasongrlicky opened this issue Jan 26, 2017 · 3 comments
Closed

Sample code for shared contexts #852

jasongrlicky opened this issue Jan 26, 2017 · 3 comments

Comments

@jasongrlicky
Copy link

Hey there! I'm trying to implement an app where I share contexts between multiple headless renderers. It seems like it should be possible to do this using glutin via GLAttributes, but when I attempt to use it as I've shown below, I get a compilation error:

extern crate gl;
extern crate glutin;

fn main() {
    let c1 = glutin::HeadlessRendererBuilder::new(640, 480).build().unwrap();
    unsafe { c1.make_current() }.unwrap();
    gl::load_with(|symbol| c1.get_proc_address(symbol) as *const _);

    let mut builder = glutin::HeadlessRendererBuilder::new(640, 480);
    let mut attributes = glutin::GlAttributes::default();
    attributes.sharing = Some(&c1);
    builder.opengl = attributes; 
    let c2 = builder.build().unwrap();
    unsafe { c2.make_current() }.unwrap();
    gl::load_with(|symbol| c2.get_proc_address(symbol) as *const _);
}

The error I'm seeing is:

error[E0308]: mismatched types
  --> examples/sharing.rs:15:22
   |
15 |     builder.opengl = attributes;
   |                      ^^^^^^^^^^ expected struct `glutin::platform::platform::headless::HeadlessContext`, found struct `glutin::HeadlessContext`
   |
   = note: expected type `glutin::GlAttributes<&glutin::platform::platform::headless::HeadlessContext>`
   = note:    found type `glutin::GlAttributes<&glutin::HeadlessContext>`

After looking into it, I found glutin::HeadlessContext's .context property, which I believe is of the right type, but doesn't seem to be public. Can anyone point me in the right direction for setting up shared contexts? Once we get it sorted out, I'll gladly contribute back a new example that demonstrates it. Thank you!

@tomaka tomaka added the bug label Jan 27, 2017
@tomaka
Copy link
Contributor

tomaka commented Jan 27, 2017

This is clearly a problem here: https://github.com/tomaka/glutin/blob/06247af952aa29c0eb5fecf89fd099004e4bc2a0/src/headless.rs#L21
It should be HeadlessContext and not platform::HeadlessContext.

@jasongrlicky
Copy link
Author

Oh, great! Thank you so much for the quick response. I was going to try and fix it and submit a patch, but I ran into #853 when trying to build Glutin locally, and am not an experienced-enough Rust developer to work around that one.

@jasongrlicky
Copy link
Author

Thanks so much for fixing #853, @tomaka 👍 Now that I've had a chance to dive into the code, I realized that context sharing isn't itself supported on Cocoa yet (#135). I'm definitely too new of a Rust developer to tackle that whole feature, but maybe someday.

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

No branches or pull requests

3 participants