8000 egl: fall back to fewer samples when no config offers sample_count by benface · Pull Request #671 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content
Open
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
47 changes: 28 additions & 19 deletions src/native/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,37 @@ pub unsafe fn create_egl_context(
}

let alpha_size = if alpha { 8 } else { 0 };
#[rustfmt::skip]
let cfg_attributes = [
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, alpha_size,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, 0,
EGL_SAMPLES, sample_count as u32,
EGL_NONE,
];
let mut available_cfgs: Vec<EGLConfig> = vec![null_mut(); 32];
let mut cfg_count = 0;

(egl.eglChooseConfig)(
display,
cfg_attributes.as_ptr() as _,
available_cfgs.as_ptr() as _,
32,
&mut cfg_count as *mut _ as *mut _,
);
// Fall back to fewer samples when no config offers the requested count
// (the Android emulator has none with 2 or 4) instead of failing.
let mut samples = sample_count;
loop {
#[rustfmt::skip]
let cfg_attributes = [
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, alpha_size,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, 0,
EGL_SAMPLES, samples as u32,
EGL_NONE,
];
(egl.eglChooseConfig)(
display,
cfg_attributes.as_ptr() as _,
available_cfgs.as_ptr() as _,
32,
&mut cfg_count as *mut _ as *mut _,
);
if cfg_count > 0 || samples == 0 {
break;
}
samples /= 2;
}
assert!(cfg_count > 0);
assert!(cfg_count <= 32);

Expand Down
Loading
0