From 6dc670cde0c136e28c71d4ebe67c5c8bb9df65b1 Mon Sep 17 00:00:00 2001 From: Vasily Khoruzhick Date: Wed, 8 Jun 2022 02:02:57 -0700 Subject: Support dual source blending in GLES2 renderer GLES2 has GL_EXT_blend_func_extended extension that enables dual-source blending, so essentially we can reuse fragment shader from GLSL3 renderer and do 1 rendering pass instead of 3 for the text. Co-authored-by: Kirill Chibisov Co-authored-by: Christian Duerr --- alacritty/src/renderer/mod.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'alacritty/src/renderer/mod.rs') diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index 0446379e..eb0012bd 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -1,8 +1,10 @@ +use std::collections::HashSet; use std::ffi::CStr; use std::fmt; use crossfont::Metrics; use log::info; +use once_cell::sync::OnceCell; use alacritty_terminal::index::Point; use alacritty_terminal::term::cell::Flags; @@ -218,3 +220,40 @@ impl Renderer { } } } + +struct GlExtensions; + +impl GlExtensions { + /// Check if the given `extension` is supported. + /// + /// This function will lazyly load OpenGL extensions. + fn contains(extension: &str) -> bool { + static OPENGL_EXTENSIONS: OnceCell> = OnceCell::new(); + + OPENGL_EXTENSIONS.get_or_init(Self::load_extensions).contains(extension) + } + + /// Load available OpenGL extensions. + fn load_extensions() -> HashSet<&'static str> { + unsafe { + let extensions = gl::GetString(gl::EXTENSIONS); + + if extensions.is_null() { + let mut extensions_number = 0; + gl::GetIntegerv(gl::NUM_EXTENSIONS, &mut extensions_number); + + (0..extensions_number as gl::types::GLuint) + .flat_map(|i| { + let extension = CStr::from_ptr(gl::GetStringi(gl::EXTENSIONS, i) as *mut _); + extension.to_str() + }) + .collect() + } else { + match CStr::from_ptr(extensions as *mut _).to_str() { + Ok(ext) => ext.split_whitespace().collect(), + Err(_) => HashSet::new(), + } + } + } + } +} -- cgit