mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-12 12:56:06 +00:00
renderer/opengl: simplifying the custom shader to get things working
This commit is contained in:
@@ -7,6 +7,12 @@ const gl = @import("opengl");
|
||||
|
||||
program: gl.Program,
|
||||
|
||||
/// This VAO is used for all custom shaders. It contains a single quad
|
||||
/// by using an EBO. The vertex ID (gl_VertexID) can be used to determine the
|
||||
/// position of the vertex.
|
||||
vao: gl.VertexArray,
|
||||
ebo: gl.Buffer,
|
||||
|
||||
pub const Uniforms = extern struct {
|
||||
resolution: [3]f32 align(16),
|
||||
time: f32 align(4),
|
||||
@@ -33,24 +39,48 @@ pub fn createList(alloc: Allocator, srcs: []const [:0]const u8) ![]const CustomP
|
||||
}
|
||||
|
||||
pub fn init(src: [:0]const u8) !CustomProgram {
|
||||
_ = src;
|
||||
const program = try gl.Program.createVF(
|
||||
@embedFile("../shaders/custom.v.glsl"),
|
||||
src,
|
||||
//src,
|
||||
@embedFile("../shaders/temp.f.glsl"),
|
||||
);
|
||||
errdefer program.destroy();
|
||||
|
||||
// Create our uniform buffer that is shared across all custom shaders
|
||||
const ubo = try gl.Buffer.create();
|
||||
errdefer ubo.destroy();
|
||||
var ubobind = try ubo.bind(.uniform);
|
||||
defer ubobind.unbind();
|
||||
try ubobind.setDataNull(Uniforms, .static_draw);
|
||||
{
|
||||
var ubobind = try ubo.bind(.uniform);
|
||||
defer ubobind.unbind();
|
||||
try ubobind.setDataNull(Uniforms, .static_draw);
|
||||
}
|
||||
|
||||
// Setup our VAO for the custom shader.
|
||||
const vao = try gl.VertexArray.create();
|
||||
errdefer vao.destroy();
|
||||
const vaobind = try vao.bind();
|
||||
defer vaobind.unbind();
|
||||
|
||||
// Element buffer (EBO)
|
||||
const ebo = try gl.Buffer.create();
|
||||
errdefer ebo.destroy();
|
||||
var ebobind = try ebo.bind(.element_array);
|
||||
defer ebobind.unbind();
|
||||
try ebobind.setData([6]u8{
|
||||
0, 1, 3, // Top-left triangle
|
||||
1, 2, 3, // Bottom-right triangle
|
||||
}, .static_draw);
|
||||
|
||||
return .{
|
||||
.program = program,
|
||||
.vao = vao,
|
||||
.ebo = ebo,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: CustomProgram) void {
|
||||
self.ebo.destroy();
|
||||
self.vao.destroy();
|
||||
self.program.destroy();
|
||||
}
|
||||
|
Reference in New Issue
Block a user