mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
renderer/opengl: draw custom shaders, simplified
This commit is contained in:
@ -1410,6 +1410,9 @@ pub fn drawFrame(self: *OpenGL, surface: *apprt.Surface) !void {
|
|||||||
// Draw our terminal cells
|
// Draw our terminal cells
|
||||||
try self.drawCellProgram(&gl_state);
|
try self.drawCellProgram(&gl_state);
|
||||||
|
|
||||||
|
// Draw our custom shaders
|
||||||
|
try self.drawCustomPrograms(&gl_state);
|
||||||
|
|
||||||
// Swap our window buffers
|
// Swap our window buffers
|
||||||
switch (apprt.runtime) {
|
switch (apprt.runtime) {
|
||||||
apprt.glfw => surface.window.swapBuffers(),
|
apprt.glfw => surface.window.swapBuffers(),
|
||||||
@ -1418,6 +1421,20 @@ pub fn drawFrame(self: *OpenGL, surface: *apprt.Surface) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn drawCustomPrograms(
|
||||||
|
self: *OpenGL,
|
||||||
|
gl_state: *const GLState,
|
||||||
|
) !void {
|
||||||
|
_ = self;
|
||||||
|
|
||||||
|
for (gl_state.custom_programs) |program| {
|
||||||
|
// Bind our cell program state, buffers
|
||||||
|
const bind = try program.bind();
|
||||||
|
defer bind.unbind();
|
||||||
|
try gl.drawElementsInstanced(gl.c.GL_TRIANGLES, 6, gl.c.GL_UNSIGNED_BYTE, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Runs the cell program (shaders) to draw the terminal grid.
|
/// Runs the cell program (shaders) to draw the terminal grid.
|
||||||
fn drawCellProgram(
|
fn drawCellProgram(
|
||||||
self: *OpenGL,
|
self: *OpenGL,
|
||||||
|
@ -84,3 +84,32 @@ pub fn deinit(self: CustomProgram) void {
|
|||||||
self.vao.destroy();
|
self.vao.destroy();
|
||||||
self.program.destroy();
|
self.program.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn bind(self: CustomProgram) !Binding {
|
||||||
|
const program = try self.program.use();
|
||||||
|
errdefer program.unbind();
|
||||||
|
|
||||||
|
const vao = try self.vao.bind();
|
||||||
|
errdefer vao.unbind();
|
||||||
|
|
||||||
|
const ebo = try self.ebo.bind(.element_array);
|
||||||
|
errdefer ebo.unbind();
|
||||||
|
|
||||||
|
return .{
|
||||||
|
.program = program,
|
||||||
|
.vao = vao,
|
||||||
|
.ebo = ebo,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const Binding = struct {
|
||||||
|
program: gl.Program.Binding,
|
||||||
|
vao: gl.VertexArray.Binding,
|
||||||
|
ebo: gl.Buffer.Binding,
|
||||||
|
|
||||||
|
pub fn unbind(self: Binding) void {
|
||||||
|
self.ebo.unbind();
|
||||||
|
self.vao.unbind();
|
||||||
|
self.program.unbind();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
vec2 position;
|
vec2 position;
|
||||||
position.x = (gl_VertexID == 0 || gl_VertexID == 1) ? 1. : 0.;
|
position.x = (gl_VertexID == 0 || gl_VertexID == 1) ? -1. : 1.;
|
||||||
position.y = (gl_VertexID == 0 || gl_VertexID == 3) ? 0. : 1.;
|
position.y = (gl_VertexID == 0 || gl_VertexID == 3) ? 1. : -1.;
|
||||||
gl_Position = vec4(position.xy, 0.0f, 1.0f);
|
gl_Position = vec4(position.xy, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
layout(location = 0) out vec4 out_FragColor;
|
layout(location = 0) out vec4 out_FragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// read
|
// red
|
||||||
out_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
//out_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
|
// maze
|
||||||
|
vec4 I = gl_FragCoord;
|
||||||
|
out_FragColor = vec4(3)*modf(I*.1,I)[int(length(I)*1e4)&1];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user