Skip to content

Commit

Permalink
Fix OpenGL transparency on MacOS
Browse files Browse the repository at this point in the history
Fake cfgs at it again...
  • Loading branch information
Speykious committed Feb 25, 2024
1 parent 2632d97 commit 9139ff0
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions examples/render-opengl/src/app_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,29 @@ pub struct AppFrame {
impl AppFrame {
pub fn init(window_builder: WindowBuilder) -> Result<Self, Box<dyn Error>> {
let event_loop = EventLoop::new()?;
let mut template = ConfigTemplateBuilder::new();

// The template will match only the configurations supporting rendering
// to windows.
//
// XXX We force transparency only on macOS, given that EGL on X11 doesn't
// have it, but we still want to show window. The macOS situation is like
// that, because we can query only one config at a time on it, but all
// normal platforms will return multiple configs, so we can find the config
// with transparency ourselves inside the `reduce`.
if window_builder.transparent() {
template = template
// The template will match only the configurations supporting rendering to windows.
let template = if window_builder.transparent() {
// We force transparency only on macOS, given that EGL on X11 doesn't
// have it, but we still want to show window. The macOS situation is like
// that, because we can query only one config at a time on it, but all
// normal platforms will return multiple configs, so we can find the config
// with transparency ourselves inside the `reduce`.

ConfigTemplateBuilder::new()
.with_alpha_size(8)
.with_transparency(cfg!(all(macos_platform, not(wasm_platform))));
.with_transparency(cfg!(target_os = "macos"))
} else {
template = template.with_transparency(false);
}
ConfigTemplateBuilder::new().with_transparency(false)
};

// Only Windows requires the window to be present before creating the display.
// Other platforms don't really need one.
//
// XXX if you don't care about running on Android or so you can safely remove
// this condition and always pass the window builder.
let maydow_builder = {
let wgl_backend = cfg!(all(windows, not(wasm_platform)));
let wgl_backend = cfg!(target_os = "windows");
wgl_backend.then_some(window_builder.clone())
};

Expand Down

0 comments on commit 9139ff0

Please sign in to comment.