mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-03 20:14:22 +02:00
Rewrite terminal.cpp
Rewrites the Terminal class as a GDExtension to be used directly in Godot without a terminal.gd proxy. Breaks a lot of things in its current state (e.g. signals and other functions have not be implemented yet), but does add support for transparent colors and true color inversion. It also seems to be about 4x faster (FPS-wise) than the old version with some basic stress testing. Old source code has been moved to a different directory to be copied over and/or rewritten piece by piece.
This commit is contained in:
parent
7d2e22530e
commit
a849423096
29 changed files with 1431 additions and 857 deletions
38
addons/godot_xterm/shaders/background.gdshader
Normal file
38
addons/godot_xterm/shaders/background.gdshader
Normal file
|
@ -0,0 +1,38 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
uniform int cols;
|
||||
uniform int rows;
|
||||
uniform vec2 size; // Total size of the Terminal control.
|
||||
uniform vec2 cell_size;
|
||||
uniform vec4 background;
|
||||
uniform sampler2D cell_colors; // Texture containing the cell colors, one pixel per cell.
|
||||
|
||||
const int INVERSE_FLAG = 1 << 0;
|
||||
// Texture containing the cell attributes encoded using bit flags, one flag per cell in the R channel.
|
||||
uniform sampler2D attributes;
|
||||
|
||||
void fragment() {
|
||||
// Grid means the part of the terminal that contains the cells.
|
||||
// Will vary depending on font size and the size of the control.
|
||||
vec2 grid_size = vec2(cell_size.x * float(cols), cell_size.y * float(rows));
|
||||
|
||||
if (UV.x * size.x < grid_size.x && UV.y * size.y < grid_size.y) {
|
||||
vec2 grid_uv = UV * size / cell_size;
|
||||
|
||||
int cell_x = int(grid_uv.x);
|
||||
int cell_y = int(grid_uv.y);
|
||||
|
||||
vec2 sample_uv = (vec2(float(cell_x), float(cell_y)) + 0.5) / vec2(float(cols), float(rows));
|
||||
vec4 color = texture(cell_colors, sample_uv);
|
||||
|
||||
int attr_flags = int(texture(attributes, sample_uv).r * 255.0 + 0.5);
|
||||
if ((attr_flags & INVERSE_FLAG) != 0) {
|
||||
color = vec4(1.0 - color.rgb, color.a);
|
||||
}
|
||||
|
||||
COLOR = color;
|
||||
} else {
|
||||
// If outside the grid area, use the background color.
|
||||
COLOR = background;
|
||||
}
|
||||
}
|
7
addons/godot_xterm/shaders/foreground.gdshader
Normal file
7
addons/godot_xterm/shaders/foreground.gdshader
Normal file
|
@ -0,0 +1,7 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
void fragment() {
|
||||
COLOR = texture(TEXTURE, UV);
|
||||
// TODO: Check blink attribute and hide/show using the below.
|
||||
//COLOR = vec4(0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue