glutin icon indicating copy to clipboard operation
glutin copied to clipboard

Macos: build_windowed: NoAvailablePixelFormat

Open alexheretic opened this issue 6 years ago • 6 comments

I'm testing Robo Instructus on macos with glutin 0.21. One of the testers is getting this error running on a 2010 MacBook Pro (ie not a vm).

build_windowed: NoAvailablePixelFormat

I'm building the window with

// robo instructus
ContextBuilder::new()
    .with_gl_profile(GlProfile::Core)
    .with_gl(GlRequest::Specific(Api::OpenGl, (3, 3)))
    .with_depth_buffer(depth_total_bits - stencil_bits) // 24
    .with_stencil_buffer(stencil_bits) // 8
    .with_pixel_format(color_total_bits - alpha_bits, alpha_bits) // 24, 8
    .build_windowed(window_builder, &events_loop)
    .expect("build_windowed")

Looking at the mac platform code it looks like the error comes from

// glutin/src/platform_impl/macos/mod.rs:77
let pixel_format = IdRef::new(
    NSOpenGLPixelFormat::alloc(nil)
        .initWithAttributes_(&attributes),
);
let pixel_format = match pixel_format.non_nil() {
    None => return Err(CreationError::NoAvailablePixelFormat),
    Some(pf) => pf,
};

Any ideas on how I could debug this or reason why this isn't working?

Downstream with links to mac game builds: https://github.com/big-ab-games/robo-instructus/issues/229

alexheretic avatar Aug 25 '19 10:08 alexheretic

I'd print out attributes and see what is populated with. I'd then go commenting out lines from here 1 by one till it works: https://github.com/rust-windowing/glutin/blob/master/glutin/src/platform_impl/macos/helpers.rs#L79

I'd also find out a way to list all supported pixel formats. You can do this on linux via glxinfo. I've used this program on windows, and it has macos support apparently: https://apps.apple.com/app/id444052073?mt=12

goddessfreya avatar Aug 25 '19 12:08 goddessfreya

It looks like this was caused by the macbook lacking hardware acceleration, which is strange as this is not a vm.

I wonder if the error messages can be improved here, ideally this would produce a Hardware acceleration unavailable error which would really help point in the right direction, where NoAvailablePixelFormat misleads.

alexheretic avatar Aug 27 '19 10:08 alexheretic

I'm not aware of any method for glutin discovering why it couldn't find a matching pixel format. Even if there was, what would glutin print out if you selected two mutually exclusive requirements, e.g., maybe the rig supports hardware accelerated pixel formats and pixel formats with stencil bits, but not both. Should glutin print out "Hardware acceleration unavailable" or "Stencil bits unavailable"?

Anyways, is it possible that the mac doesn't support hardware acceleration + some other option you are requesting? I've yet to hear of macs that don't support hardware acceleration. What's its model, os version and stuff?

goddessfreya avatar Aug 27 '19 20:08 goddessfreya

Should glutin print out "Hardware acceleration unavailable" or "Stencil bits unavailable"?

I guess either would be more helpful than the current situation. It's currently a wide error that can be affected by many configs and it doesn't inform you of the cause(s) at all.

Anyways, is it possible that the mac doesn't support hardware acceleration + some other option you are requesting? I've yet to hear of macs that don't support hardware acceleration. What's its model, os version and stuff?

As far as I can tell the model should be fine, maybe driver updates will help.

alexheretic avatar Aug 28 '19 08:08 alexheretic

Hmmm, does hardware acceleration work if you force it to use the integrated/discrete gpu via tools like gfxCardStatus? As far as I know, that laptop should support hardware acceleration, it has two gpus in it!

goddessfreya avatar Aug 28 '19 10:08 goddessfreya

I believe I encountered this issue as well, described here: https://github.com/servo/pathfinder/issues/267.

The interesting part is that rust-sdl2 seems to return a 3.3 context just fine on my machine. See pathfinder/examples/canvas_minimal.

jfizz avatar Feb 19 '20 19:02 jfizz

Not relevant anymore.

kchibisov avatar Sep 03 '22 06:09 kchibisov