aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkumattau <kumattau@gmail.com>2022-10-05 01:14:14 +0900
committerkumattau <kumattau@gmail.com>2022-10-05 01:14:14 +0900
commit03cf6302dd1e7630c177efc05c07abf645c3a0ec (patch)
tree738212a18a1b46a28e04107411c48710a49bdc80
parent2301bf116f94568e03f9670049e318e5c1a0f502 (diff)
downloadr-alacritty-03cf6302dd1e7630c177efc05c07abf645c3a0ec.tar.gz
r-alacritty-03cf6302dd1e7630c177efc05c07abf645c3a0ec.tar.bz2
r-alacritty-03cf6302dd1e7630c177efc05c07abf645c3a0ec.zip
Support GLES2 Renderer in sixel
-rw-r--r--alacritty/res/graphics.f.glsl67
-rw-r--r--alacritty/res/graphics.v.glsl70
-rw-r--r--alacritty/src/renderer/graphics/mod.rs6
-rw-r--r--alacritty/src/renderer/graphics/shader.rs21
-rw-r--r--alacritty/src/renderer/mod.rs21
5 files changed, 124 insertions, 61 deletions
diff --git a/alacritty/res/graphics.f.glsl b/alacritty/res/graphics.f.glsl
index 3423eee5..4fa4806e 100644
--- a/alacritty/res/graphics.f.glsl
+++ b/alacritty/res/graphics.f.glsl
@@ -1,15 +1,42 @@
+#if defined(GLES2_RENDERER) ///////////////////////////////////////////
+
+precision highp float;
+
+#define FLAT
+#define IN varying
+
+#define INT float
+
+#define SWITCH(X) int ind = int(X);
+#define CASE(N) if (ind == N) {gl_FragColor = texture2D(textures[N], texCoords); return;}
+#define DEFAULT(X) X;
+#define END_SWITCH
+
+#else // GLSL3_RENDERER ///////////////////////////////////////////////
+
+#define FLAT flat
+#define IN in
+
+#define INT int
+
+#define SWITCH(X) switch(X) {
+#define CASE(N) case N: color = texture(textures[N], texCoords); break;
+#define DEFAULT(X) default: X;
+#define END_SWITCH }
+
+out vec4 color;
+
+#endif ////////////////////////////////////////////////////////////////
+
// Index in the textures[] uniform.
-flat in int texId;
+FLAT IN INT texId;
// Texture coordinates.
-in vec2 texCoords;
+IN vec2 texCoords;
// Array with graphics data.
uniform sampler2D textures[16];
-// Computed color.
-out vec4 color;
-
void main() {
// The expression `textures[texId]` can't be used in OpenGL 3.3.
// If we try to use it, the compiler throws this error:
@@ -24,15 +51,23 @@ void main() {
// or later (using `#version 400 core`). If Alacritty drops support
// for OpenGL 3.3, this switch block can be replaced with it.
-
-#define TEX(N) case N: color = texture(textures[N], texCoords); break;
-
- switch(texId) {
- TEX( 0) TEX( 1) TEX( 2) TEX( 3)
- TEX( 4) TEX( 5) TEX( 6) TEX( 7)
- TEX( 8) TEX( 9) TEX(10) TEX(11)
- TEX(12) TEX(13) TEX(14) TEX(15)
- default:
- discard;
- }
+ SWITCH(texId)
+ CASE(0)
+ CASE(1)
+ CASE(2)
+ CASE(3)
+ CASE(4)
+ CASE(5)
+ CASE(6)
+ CASE(7)
+ CASE(8)
+ CASE(9)
+ CASE(10)
+ CASE(11)
+ CASE(12)
+ CASE(13)
+ CASE(14)
+ CASE(15)
+ DEFAULT(discard)
+ END_SWITCH
}
diff --git a/alacritty/res/graphics.v.glsl b/alacritty/res/graphics.v.glsl
index eaeeb4ed..31d9e49d 100644
--- a/alacritty/res/graphics.v.glsl
+++ b/alacritty/res/graphics.v.glsl
@@ -1,44 +1,72 @@
+#if defined(GLES2_RENDERER) ///////////////////////////////////////////
+
+precision highp float;
+
+#define LAYOUT_LOCATION(N) attribute
+#define IN
+#define FLAT
+#define OUT varying
+
+#define INT float
+
+#define IS_RIGHT_SIDE (int(sides) == 1 || int(sides) == 3)
+#define IS_BOTTOM_SIDE (int(sides) == 2 || int(sides) == 3)
+
+#else // GLSL3_RENDERER ///////////////////////////////////////////////
+
+#define LAYOUT_LOCATION(N) layout(location = N)
+#define IN in
+#define FLAT flat
+#define OUT out
+
+#define INT int
+
+#define IS_RIGHT_SIDE ((sides & 1) == 1)
+#define IS_BOTTOM_SIDE ((sides & 2) == 2)
+
+#endif ////////////////////////////////////////////////////////////////
+
// ------
// INPUTS
// Texture associated to the graphic.
-layout(location = 0) in int textureId;
+LAYOUT_LOCATION(0) IN INT textureId;
// Sides where the vertex is located.
//
// Bit 0 (LSB) is 0 for top and 1 for bottom.
// Bit 1 is 0 for left and 1 for right.
-layout(location = 1) in int sides;
+LAYOUT_LOCATION(1) IN INT sides;
// Column number in the grid where the left vertex is set.
-layout(location = 2) in float column;
+LAYOUT_LOCATION(2) IN float column;
// Line number in the grid where the left vertex is set.
-layout(location = 3) in float line;
+LAYOUT_LOCATION(3) IN float line;
// Height in pixels of the texture.
-layout(location = 4) in float height;
+LAYOUT_LOCATION(4) IN float height;
// Width in pixels of the texture.
-layout(location = 5) in float width;
+LAYOUT_LOCATION(5) IN float width;
// Offset in the X direction.
-layout(location = 6) in float offsetX;
+LAYOUT_LOCATION(6) IN float offsetX;
// Offset in the Y direction.
-layout(location = 7) in float offsetY;
+LAYOUT_LOCATION(7) IN float offsetY;
// Height in pixels of a single cell when the graphic was added.
-layout(location = 8) in float baseCellHeight;
+LAYOUT_LOCATION(8) IN float baseCellHeight;
// -------
// OUTPUTS
// Texture sent to the fragment shader.
-flat out int texId;
+FLAT OUT INT texId;
// Coordinates sent to the fragment shader.
-out vec2 texCoords;
+OUT vec2 texCoords;
// --------
// UNIFORMS
@@ -49,26 +77,22 @@ uniform vec2 cellDimensions;
// Width and height of the view.
uniform vec2 viewDimensions;
-
-#define IS_RIGHT_SIDE ((sides & 1) == 1)
-#define IS_BOTTOM_SIDE ((sides & 2) == 2)
-
void main() {
float scale = cellDimensions.y / baseCellHeight;
- float x = (column * cellDimensions.x - offsetX * scale) / (viewDimensions.x / 2) - 1;
- float y = -(line * cellDimensions.y - offsetY * scale) / (viewDimensions.y / 2) + 1;
+ float x = (column * cellDimensions.x - offsetX * scale) / (viewDimensions.x / 2.) - 1.;
+ float y = -(line * cellDimensions.y - offsetY * scale) / (viewDimensions.y / 2.) + 1.;
- vec4 position = vec4(x, y, 0, 1);
- vec2 coords = vec2(0, 0);
+ vec4 position = vec4(x, y, 0., 1.);
+ vec2 coords = vec2(0., 0.);
if(IS_RIGHT_SIDE) {
- position.x += scale * width / (viewDimensions.x / 2);
- coords.x = 1;
+ position.x += scale * width / (viewDimensions.x / 2.);
+ coords.x = 1.;
}
if(IS_BOTTOM_SIDE) {
- position.y += -scale * height / (viewDimensions.y / 2);
- coords.y = 1;
+ position.y += -scale * height / (viewDimensions.y / 2.);
+ coords.y = 1.;
}
gl_Position = position;
diff --git a/alacritty/src/renderer/graphics/mod.rs b/alacritty/src/renderer/graphics/mod.rs
index 5a6c59a7..9a22e871 100644
--- a/alacritty/src/renderer/graphics/mod.rs
+++ b/alacritty/src/renderer/graphics/mod.rs
@@ -3,7 +3,7 @@
use std::mem;
use crate::display::SizeInfo;
-use crate::renderer::RenderRect;
+use crate::renderer::{RenderRect, ShaderVersion};
use alacritty_terminal::graphics::{
ClearSubregion, ColorType, GraphicData, GraphicId, UpdateQueues,
};
@@ -84,8 +84,8 @@ pub struct GraphicsRenderer {
}
impl GraphicsRenderer {
- pub fn new() -> Result<GraphicsRenderer, renderer::Error> {
- let program = shader::GraphicsShaderProgram::new()?;
+ pub fn new(shader_version: ShaderVersion) -> Result<GraphicsRenderer, renderer::Error> {
+ let program = shader::GraphicsShaderProgram::new(shader_version)?;
let clear_texture_ext = check_opengl_extensions(&["GL_ARB_clear_texture"]);
Ok(GraphicsRenderer { program, graphic_textures: HashMap::default(), clear_texture_ext })
}
diff --git a/alacritty/src/renderer/graphics/shader.rs b/alacritty/src/renderer/graphics/shader.rs
index 773db447..1aff2f3e 100644
--- a/alacritty/src/renderer/graphics/shader.rs
+++ b/alacritty/src/renderer/graphics/shader.rs
@@ -80,9 +80,8 @@ pub struct GraphicsShaderProgram {
}
impl GraphicsShaderProgram {
- pub fn new() -> Result<Self, ShaderError> {
- let shader =
- ShaderProgram::new(ShaderVersion::Glsl3, GRAPHICS_SHADER_V, GRAPHICS_SHADER_F)?;
+ pub fn new(shader_version: ShaderVersion) -> Result<Self, ShaderError> {
+ let shader = ShaderProgram::new(shader_version, GRAPHICS_SHADER_V, GRAPHICS_SHADER_F)?;
let u_cell_dimensions;
let u_view_dimensions;
@@ -119,7 +118,7 @@ impl GraphicsShaderProgram {
gl::UseProgram(0);
}
- let (vao, vbo) = define_vertex_attributes();
+ let (vao, vbo) = define_vertex_attributes(shader_version);
let shader = Self { shader, u_cell_dimensions, u_view_dimensions, u_textures, vao, vbo };
@@ -129,7 +128,7 @@ impl GraphicsShaderProgram {
/// Build a Vertex Array Object (VAO) and a Vertex Buffer Object (VBO) for
/// instances of the `Vertex` type.
-fn define_vertex_attributes() -> (GLuint, GLuint) {
+fn define_vertex_attributes(shader_version: ShaderVersion) -> (GLuint, GLuint) {
let mut vao = 0;
let mut vbo = 0;
@@ -171,8 +170,16 @@ fn define_vertex_attributes() -> (GLuint, GLuint) {
};
}
- int_attr!(UNSIGNED_INT, texture_id);
- int_attr!(UNSIGNED_BYTE, sides);
+ match shader_version {
+ ShaderVersion::Glsl3 => {
+ int_attr!(UNSIGNED_INT, texture_id);
+ int_attr!(UNSIGNED_BYTE, sides);
+ },
+ ShaderVersion::Gles2 => {
+ float_attr!(UNSIGNED_INT, texture_id);
+ float_attr!(UNSIGNED_BYTE, sides);
+ },
+ }
float_attr!(UNSIGNED_INT, column);
float_attr!(UNSIGNED_INT, line);
diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs
index 898df15d..5f21a65b 100644
--- a/alacritty/src/renderer/mod.rs
+++ b/alacritty/src/renderer/mod.rs
@@ -76,7 +76,7 @@ enum TextRendererProvider {
pub struct Renderer {
text_renderer: TextRendererProvider,
rect_renderer: RectRenderer,
- graphics_renderer: Option<GraphicsRenderer>,
+ graphics_renderer: GraphicsRenderer,
}
impl Renderer {
@@ -96,12 +96,13 @@ impl Renderer {
let (text_renderer, rect_renderer, graphics_renderer) = if version.as_ref() >= "3.3" {
let text_renderer = TextRendererProvider::Glsl3(Glsl3Renderer::new()?);
let rect_renderer = RectRenderer::new(ShaderVersion::Glsl3)?;
- let graphics_renderer = GraphicsRenderer::new()?;
- (text_renderer, rect_renderer, Some(graphics_renderer))
+ let graphics_renderer = GraphicsRenderer::new(ShaderVersion::Glsl3)?;
+ (text_renderer, rect_renderer, graphics_renderer)
} else {
let text_renderer = TextRendererProvider::Gles2(Gles2Renderer::new()?);
let rect_renderer = RectRenderer::new(ShaderVersion::Gles2)?;
- (text_renderer, rect_renderer, None)
+ let graphics_renderer = GraphicsRenderer::new(ShaderVersion::Gles2)?;
+ (text_renderer, rect_renderer, graphics_renderer)
};
Ok(Self { text_renderer, rect_renderer, graphics_renderer })
@@ -228,12 +229,10 @@ impl Renderer {
/// Run the required actions to apply changes for the graphics in the grid.
#[inline]
pub fn graphics_run_updates(&mut self, update_queues: UpdateQueues, size_info: &SizeInfo) {
- if let Some(graphics_renderer) = self.graphics_renderer.as_mut() {
- let result = graphics_renderer.run_updates(update_queues, size_info);
+ let result = self.graphics_renderer.run_updates(update_queues, size_info);
- if result.contains(graphics::UpdateResult::NEED_RESET_ACTIVE_TEX) {
- self.reset_active_tex();
- }
+ if result.contains(graphics::UpdateResult::NEED_RESET_ACTIVE_TEX) {
+ self.reset_active_tex();
}
}
@@ -246,9 +245,7 @@ impl Renderer {
rects: &mut Vec<RenderRect>,
metrics: &Metrics,
) {
- if let Some(graphics_renderer) = self.graphics_renderer.as_mut() {
- graphics_renderer.draw(render_list, size_info, rects, metrics);
- }
+ self.graphics_renderer.draw(render_list, size_info, rects, metrics);
self.reset_active_tex();
}