aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/renderer/mod.rs
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2022-11-03 19:37:54 +0300
committerGitHub <noreply@github.com>2022-11-03 19:37:54 +0300
commit0e418bc2f761617455cc58aaabc375055dfe4284 (patch)
treefc15d2260404914e21297d392f7f9c32a5f2bffc /alacritty/src/renderer/mod.rs
parent578e08486dfcdee0b2cd0e7a66752ff50edc46b8 (diff)
downloadr-alacritty-0e418bc2f761617455cc58aaabc375055dfe4284.tar.gz
r-alacritty-0e418bc2f761617455cc58aaabc375055dfe4284.tar.bz2
r-alacritty-0e418bc2f761617455cc58aaabc375055dfe4284.zip
Update glutin to 0.30.0
The glutin 0.30.0 update decouples glutin from winit which provides us with basis for a multithreaded renderer. This also improves robustness of our configuration picking, context creation, and surface handling. As an example we're now able to start on systems without a vsync, we don't try to build lots of contexts to check if some config works, and so on. That also brings us possibility to handle context losses, but that's a future work. Fixes #1268.
Diffstat (limited to 'alacritty/src/renderer/mod.rs')
-rw-r--r--alacritty/src/renderer/mod.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs
index 6ee8815c..d8c6fb6d 100644
--- a/alacritty/src/renderer/mod.rs
+++ b/alacritty/src/renderer/mod.rs
@@ -1,8 +1,11 @@
use std::collections::HashSet;
-use std::ffi::CStr;
+use std::ffi::{CStr, CString};
use std::fmt;
+use std::sync::atomic::{AtomicBool, Ordering};
use crossfont::Metrics;
+use glutin::context::PossiblyCurrentContext;
+use glutin::display::{GetGlDisplay, GlDisplay};
use log::info;
use once_cell::sync::OnceCell;
@@ -16,6 +19,7 @@ use crate::gl;
use crate::renderer::rects::{RectRenderer, RenderRect};
use crate::renderer::shader::ShaderError;
+pub mod platform;
pub mod rects;
mod shader;
mod text;
@@ -33,6 +37,9 @@ macro_rules! cstr {
}
pub(crate) use cstr;
+/// Whether the OpenGL functions have been loaded.
+pub static GL_FUNS_LOADED: AtomicBool = AtomicBool::new(false);
+
#[derive(Debug)]
pub enum Error {
/// Shader error.
@@ -80,7 +87,17 @@ impl Renderer {
///
/// This will automatically pick between the GLES2 and GLSL3 renderer based on the GPU's
/// supported OpenGL version.
- pub fn new() -> Result<Self, Error> {
+ pub fn new(context: &PossiblyCurrentContext) -> Result<Self, Error> {
+ // We need to load OpenGL functions once per instance, but only after we make our context
+ // current due to WGL limitations.
+ if !GL_FUNS_LOADED.swap(true, Ordering::Relaxed) {
+ let gl_display = context.display();
+ gl::load_with(|symbol| {
+ let symbol = CString::new(symbol).unwrap();
+ gl_display.get_proc_address(symbol.as_c_str()).cast()
+ });
+ }
+
let (version, renderer) = unsafe {
let renderer = CStr::from_ptr(gl::GetString(gl::RENDERER) as *mut _);
let version = CStr::from_ptr(gl::GetString(gl::SHADING_LANGUAGE_VERSION) as *mut _);