Skip to content

Commit

Permalink
GL backend: Prospective fix for panic when trying to create window wi…
Browse files Browse the repository at this point in the history
…th AMD GL driver

The srgb workaround from commit a0e827e
appears to work with the AMD GL driver, without which the GL context
creation works (as tested by the reporter).

So instead of panicing, fall back to the glutin default with possibly an
srgb framebuffer, when trying to create a GL context. If that also
fails, provide a better error message than "called unwrap on an err".

cc slint-ui#481
  • Loading branch information
tronical committed Sep 9, 2021
1 parent ea104ed commit 011a9ff
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions sixtyfps_runtime/rendering_backends/gl/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,24 @@ impl OpenGLContext {
) -> (Self, femtovg::renderer::OpenGl) {
#[cfg(not(target_arch = "wasm32"))]
{
use glutin::ContextBuilder;
let windowed_context = crate::event_loop::with_window_target(|event_loop| {
let builder = glutin::ContextBuilder::new().with_vsync(true);

let builder = ContextBuilder::new().with_vsync(true);
// With latest Windows 10 and VmWare glutin's default for srgb produces surfaces that are always rendered black :(
#[cfg(target_os = "windows")]
let builder = builder.with_srgb(false);

builder.build_windowed(window_builder, event_loop.event_loop_target()).unwrap()
if let Ok(builder) =
builder.build_windowed(window_builder.clone(), event_loop.event_loop_target())
{
builder
} else {
// Try again with glutin defaults
ContextBuilder::new()
.with_vsync(true)
.build_windowed(window_builder, event_loop.event_loop_target())
.expect("Failed to create OpenGL Context:")
}
});
let windowed_context = unsafe { windowed_context.make_current().unwrap() };

Expand Down

0 comments on commit 011a9ff

Please sign in to comment.