mirror of
https://github.com/wez/wezterm.git
synced 2024-11-10 15:04:32 +03:00
we can now init opengl but not render it
This commit is contained in:
parent
3779a1a0b1
commit
41e392fc79
@ -187,6 +187,7 @@ struct Vertex {
|
||||
}
|
||||
::window::glium::implement_vertex!(Vertex, position, tex);
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct RenderMetrics {
|
||||
descender: f64,
|
||||
descender_row: isize,
|
||||
@ -363,6 +364,23 @@ struct OpenGLRenderState {
|
||||
util_sprites: UtilSprites<SrgbTexture2d>,
|
||||
}
|
||||
|
||||
impl OpenGLRenderState {
|
||||
pub fn new(
|
||||
context: Rc<GliumContext>,
|
||||
fonts: &Rc<FontConfiguration>,
|
||||
metrics: &RenderMetrics,
|
||||
size: usize,
|
||||
) -> Fallible<Self> {
|
||||
let glyph_cache = RefCell::new(GlyphCache::new_gl(&context, fonts, size)?);
|
||||
let util_sprites = UtilSprites::new(&mut *glyph_cache.borrow_mut(), metrics)?;
|
||||
Ok(Self {
|
||||
context,
|
||||
glyph_cache,
|
||||
util_sprites,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
enum RenderState {
|
||||
Software(SoftwareRenderState),
|
||||
GL(OpenGLRenderState),
|
||||
@ -651,8 +669,12 @@ impl TermWindow {
|
||||
let width = render_metrics.cell_size.width as usize * physical_cols;
|
||||
let height = render_metrics.cell_size.height as usize * physical_rows;
|
||||
|
||||
let render_state =
|
||||
RenderState::Software(SoftwareRenderState::new(fontconfig, &render_metrics, 4096)?);
|
||||
const ATLAS_SIZE: usize = 4096;
|
||||
let render_state = RenderState::Software(SoftwareRenderState::new(
|
||||
fontconfig,
|
||||
&render_metrics,
|
||||
ATLAS_SIZE,
|
||||
)?);
|
||||
|
||||
let window = Window::new_window(
|
||||
"wezterm",
|
||||
@ -698,7 +720,29 @@ impl TermWindow {
|
||||
window.show();
|
||||
|
||||
if super::is_opengl_enabled() {
|
||||
log::error!("I should use opengl");
|
||||
window.enable_opengl(|any, window, maybe_ctx| {
|
||||
let termwindow = any.downcast_ref::<TermWindow>().expect("to be TermWindow");
|
||||
|
||||
log::error!("I should use opengl");
|
||||
match maybe_ctx {
|
||||
Ok(ctx) => {
|
||||
match OpenGLRenderState::new(
|
||||
ctx,
|
||||
&termwindow.fonts,
|
||||
&termwindow.render_metrics,
|
||||
ATLAS_SIZE,
|
||||
) {
|
||||
Ok(gl) => {
|
||||
log::error!("OpenGL initialized!");
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("OpenGL init failed: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => log::error!("OpenGL init failed: {}", err),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -42,12 +42,10 @@ fn spawn_window() -> Fallible<()> {
|
||||
)?;
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
match win.enable_opengl() {
|
||||
Ok(_ctx) => {
|
||||
eprintln!("opengl enabled!");
|
||||
}
|
||||
win.enable_opengl(|_any, _window, maybe_ctx| match maybe_ctx {
|
||||
Ok(_ctx) => eprintln!("opengl enabled!"),
|
||||
Err(err) => eprintln!("opengl fail: {}", err),
|
||||
};
|
||||
});
|
||||
|
||||
#[cfg(not(feature = "opengl"))]
|
||||
eprintln!(
|
||||
|
@ -171,9 +171,15 @@ pub trait WindowOps {
|
||||
Self: Sized;
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&self) -> failure::Fallible<std::rc::Rc<glium::backend::Context>> {
|
||||
failure::bail!("opengl support is not implemented");
|
||||
}
|
||||
fn enable_opengl<
|
||||
F: Send
|
||||
+ 'static
|
||||
+ Fn(&mut dyn Any, &dyn WindowOps, failure::Fallible<std::rc::Rc<glium::backend::Context>>),
|
||||
>(
|
||||
&self,
|
||||
func: F,
|
||||
) where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait WindowOpsMut {
|
||||
|
@ -271,31 +271,44 @@ impl WindowOps for Window {
|
||||
}
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
fn enable_opengl(&self) -> Fallible<Rc<glium::backend::Context>> {
|
||||
if let Some(handle) = Connection::get().unwrap().window_by_id(self.0) {
|
||||
let inner = handle.borrow_mut();
|
||||
let gl_state = opengl::GlState::create(*inner.view)?;
|
||||
fn enable_opengl<
|
||||
F: Send
|
||||
+ 'static
|
||||
+ Fn(&mut dyn Any, &dyn WindowOps, failure::Fallible<std::rc::Rc<glium::backend::Context>>),
|
||||
>(
|
||||
&self,
|
||||
func: F,
|
||||
) where
|
||||
Self: Sized,
|
||||
{
|
||||
Connection::with_window_inner(self.0, move |inner| {
|
||||
let window = Window(inner.window_id);
|
||||
|
||||
let glium_context = unsafe {
|
||||
glium::backend::Context::new(
|
||||
Rc::new(gl_state),
|
||||
true,
|
||||
if cfg!(debug_assertions) {
|
||||
glium::debug::DebugCallbackBehavior::DebugMessageOnError
|
||||
} else {
|
||||
glium::debug::DebugCallbackBehavior::Ignore
|
||||
},
|
||||
)?
|
||||
};
|
||||
let glium_context = opengl::GlState::create(*inner.view).and_then(|gl_state| {
|
||||
Ok(unsafe {
|
||||
glium::backend::Context::new(
|
||||
Rc::new(gl_state),
|
||||
true,
|
||||
if cfg!(debug_assertions) {
|
||||
glium::debug::DebugCallbackBehavior::DebugMessageOnError
|
||||
} else {
|
||||
glium::debug::DebugCallbackBehavior::Ignore
|
||||
},
|
||||
)?
|
||||
})
|
||||
});
|
||||
|
||||
if let Some(window_view) = WindowView::get_this(unsafe { &**inner.view }) {
|
||||
window_view.inner.borrow_mut().gl_context = Some(Rc::clone(&glium_context));
|
||||
}
|
||||
window_view.inner.borrow_mut().gl_context =
|
||||
glium_context.as_ref().map(Rc::clone).ok();
|
||||
|
||||
Ok(glium_context)
|
||||
} else {
|
||||
failure::bail!("invalid window?");
|
||||
}
|
||||
func(
|
||||
window_view.inner.borrow_mut().callbacks.as_any(),
|
||||
&window,
|
||||
glium_context,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user