Files
ddidderr c548e63bd1 feat(renderer): port the OpenGL backend, shaders and size math
Ports the terminal-independent half of ZIG/src/renderer (OpenGL only):
- opengl/*: buffers, frames, pipelines, render passes, samplers,
  targets, textures and the OpenGL GraphicsAPI backend on top of glow;
  the GTK GLArea glue is replaced by a get_proc_address loader closure
- the GLSL shaders, copied verbatim and embedded; uniform/vertex structs
  as bytemuck Pod types with std140 offsets asserted in tests
- shadertoy custom shaders converted with naga (GLSL in -> validate ->
  GLSL 430 out) instead of glslang + spirv-cross
- size (screen/grid/cell/padding math), cursor style logic, backend
  health, options and message types

The crate opts into unsafe_code = "deny"; unsafe glow calls live only in
opengl/gl.rs. A headless EGL integration test builds every pipeline and
the converted shadertoy shaders on Mesa and reads back rendered pixels.

Note: Zig's shadertoy Uniforms order the selection background/foreground
colors opposite to the GLSL block (likely an upstream bug); kept as in
Zig for parity and recorded in the notes.

Deferred to the next renderer pass: generic, cell, image, link, row,
State, Thread, Overlay (need terminal render state).

Test Plan:
- cargo test -p ghostty-renderer (33 tests incl. tests/egl_headless.rs)
2026-10-11 22:26:09 +02:00

62 lines
1.6 KiB
GLSL

#include "common.glsl"
// Position the origin to the upper left
layout(origin_upper_left) in vec4 gl_FragCoord;
// Must declare this output for some versions of OpenGL.
layout(location = 0) out vec4 out_FragColor;
layout(binding = 1, std430) readonly buffer bg_cells {
uint cells[];
};
vec4 cell_bg() {
uvec2 grid_size = unpack2u16(grid_size_packed_2u16);
ivec2 grid_pos = ivec2(floor((gl_FragCoord.xy - grid_padding.wx) / cell_size));
bool use_linear_blending = (bools & USE_LINEAR_BLENDING) != 0;
vec4 bg = vec4(0.0);
// Clamp x position, extends edge bg colors in to padding on sides.
if (grid_pos.x < 0) {
if ((padding_extend & EXTEND_LEFT) != 0) {
grid_pos.x = 0;
} else {
return bg;
}
} else if (grid_pos.x > grid_size.x - 1) {
if ((padding_extend & EXTEND_RIGHT) != 0) {
grid_pos.x = int(grid_size.x) - 1;
} else {
return bg;
}
}
// Clamp y position if we should extend, otherwise discard if out of bounds.
if (grid_pos.y < 0) {
if ((padding_extend & EXTEND_UP) != 0) {
grid_pos.y = 0;
} else {
return bg;
}
} else if (grid_pos.y > grid_size.y - 1) {
if ((padding_extend & EXTEND_DOWN) != 0) {
grid_pos.y = int(grid_size.y) - 1;
} else {
return bg;
}
}
// Load the color for the cell.
vec4 cell_color = load_color(
unpack4u8(cells[grid_pos.y * grid_size.x + grid_pos.x]),
use_linear_blending
);
return cell_color;
}
void main() {
out_FragColor = cell_bg();
}