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

Added a feature to use a custom GL config for wayland and nvidia machines #198

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ texture_to_file = ["notan_graphics/texture_to_file"]
random = ["notan_random"]
glsl-to-spirv = ["notan_macro/glsl-to-spirv"]
shaderc = ["notan_macro/shaderc"]
nvidia-wayland = ["notan_backend?/nvidia-wayland"]

[dev-dependencies]
egui_demo_lib = "0.20.0"
Expand Down
1 change: 1 addition & 0 deletions crates/notan_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ audio = ["notan_web/audio", "notan_winit/audio"]
links = ["notan_winit/links"]
drop_files = ["notan_winit/drop_files", "notan_web/drop_files"]
clipboard = ["notan_winit/clipboard", "notan_web/clipboard"]
nvidia-wayland = ["notan_winit/nvidia-wayland"]
1 change: 1 addition & 0 deletions crates/notan_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ audio = ["notan_app/audio", "notan_audio", "notan_oddio"]
links = ["webbrowser"]
drop_files = ["mime_guess"]
clipboard = ["arboard", "notan_input"]
nvidia-wayland = []
96 changes: 61 additions & 35 deletions crates/notan_winit/src/gl_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use glutin::config::{ConfigTemplateBuilder, GlConfig};
use glutin::config::{Config, ConfigTemplateBuilder, GlConfig};
use glutin::context::{
ContextApi, ContextAttributesBuilder, GlProfile, NotCurrentGlContextSurfaceAccessor,
PossiblyCurrentContext, Version,
Expand Down Expand Up @@ -38,40 +38,7 @@ impl GlManager {

let (window, gl_config) = DisplayBuilder::new()
.with_window_builder(Some(builder))
.build(event_loop, template, |configs| {
configs
.reduce(|accum, conf| {
let next_srgb = conf.srgb_capable();
let next_transparency = conf.supports_transparency().unwrap_or(false);
let more_samples = conf.num_samples() > accum.num_samples();

// value of transparency for the priority check
let transparency_check = if config.transparent {
next_transparency
} else {
true
};

// priority 1: supports srgba, transparency and has more samples than current one
let full_support = next_srgb && transparency_check && more_samples;

// priority 2: we don't care about transparency if it's not supported by next config
let srgba_plus_samples = next_srgb && more_samples;

// priority 3: if it supports srgba is enough
let only_srgba = next_srgb;

// select the config in order of priority
let select_config = full_support || srgba_plus_samples || only_srgba;

if select_config {
conf
} else {
accum
}
})
.unwrap()
})
.build(event_loop, template, get_config(config))
.map_err(|e| {
let mut err = String::from("Cannot select a valid OpenGL configuration");
if config.multisampling != 0 {
Expand Down Expand Up @@ -184,3 +151,62 @@ impl GlManager {
);
}
}

#[cfg(not(feature = "nvidia-wayland"))]
fn get_config(
config: &WindowConfig,
) -> impl FnOnce(Box<dyn Iterator<Item = Config> + '_>) -> Config + '_ {
|configs| {
configs
.reduce(|accum, conf| {
let next_srgb = conf.srgb_capable();
let next_transparency = conf.supports_transparency().unwrap_or(false);
let more_samples = conf.num_samples() > accum.num_samples();

// value of transparency for the priority check
let transparency_check = if config.transparent {
next_transparency
} else {
true
};

// priority 1: supports srgba, transparency and has more samples than current one
let full_support = next_srgb && transparency_check && more_samples;

// priority 2: we don't care about transparency if it's not supported by next config
let srgba_plus_samples = next_srgb && more_samples;

// priority 3: if it supports srgba is enough
let only_srgba = next_srgb;

// select the config in order of priority
let select_config = full_support || srgba_plus_samples || only_srgba;

if select_config {
conf
} else {
accum
}
})
.unwrap()
}
}
#[cfg(feature = "nvidia-wayland")]
fn get_config(
_config: &WindowConfig,
) -> impl FnOnce(Box<dyn Iterator<Item = Config> + '_>) -> Config + '_ {
|configs| {
configs
.reduce(|accum, conf| {
let transparency_check = conf.supports_transparency().unwrap_or(false)
& !accum.supports_transparency().unwrap_or(false);

if transparency_check || conf.num_samples() > accum.num_samples() {
conf
} else {
accum
}
})
.unwrap()
}
}