aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/renderer/mod.rs
diff options
context:
space:
mode:
authorVasily Khoruzhick <vasily.khoruzhick@gmail.com>2022-06-08 02:02:57 -0700
committerGitHub <noreply@github.com>2022-06-08 12:02:57 +0300
commit6dc670cde0c136e28c71d4ebe67c5c8bb9df65b1 (patch)
tree31ca11c0e1784d6f608286d7f883406231b74068 /alacritty/src/renderer/mod.rs
parent29b1ff59e29cccd69bee349ca6937082dee718f6 (diff)
downloadr-alacritty-6dc670cde0c136e28c71d4ebe67c5c8bb9df65b1.tar.gz
r-alacritty-6dc670cde0c136e28c71d4ebe67c5c8bb9df65b1.tar.bz2
r-alacritty-6dc670cde0c136e28c71d4ebe67c5c8bb9df65b1.zip
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 <contact@kchibisov.com> Co-authored-by: Christian Duerr <contact@christianduerr.com>
Diffstat (limited to 'alacritty/src/renderer/mod.rs')
-rw-r--r--alacritty/src/renderer/mod.rs39
1 files changed, 39 insertions, 0 deletions
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<HashSet<&'static str>> = 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(),
+ }
+ }
+ }
+ }
+}