From 0e418bc2f761617455cc58aaabc375055dfe4284 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Thu, 3 Nov 2022 19:37:54 +0300 Subject: 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. --- alacritty/src/renderer/mod.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'alacritty/src/renderer/mod.rs') 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 { + pub fn new(context: &PossiblyCurrentContext) -> Result { + // 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 _); -- cgit