mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03: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,
|
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 {
|
pub const Uniforms = extern struct {
|
||||||
resolution: [3]f32 align(16),
|
resolution: [3]f32 align(16),
|
||||||
time: f32 align(4),
|
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 {
|
pub fn init(src: [:0]const u8) !CustomProgram {
|
||||||
|
_ = src;
|
||||||
const program = try gl.Program.createVF(
|
const program = try gl.Program.createVF(
|
||||||
@embedFile("../shaders/custom.v.glsl"),
|
@embedFile("../shaders/custom.v.glsl"),
|
||||||
src,
|
//src,
|
||||||
|
@embedFile("../shaders/temp.f.glsl"),
|
||||||
);
|
);
|
||||||
errdefer program.destroy();
|
errdefer program.destroy();
|
||||||
|
|
||||||
// Create our uniform buffer that is shared across all custom shaders
|
// Create our uniform buffer that is shared across all custom shaders
|
||||||
const ubo = try gl.Buffer.create();
|
const ubo = try gl.Buffer.create();
|
||||||
errdefer ubo.destroy();
|
errdefer ubo.destroy();
|
||||||
var ubobind = try ubo.bind(.uniform);
|
{
|
||||||
defer ubobind.unbind();
|
var ubobind = try ubo.bind(.uniform);
|
||||||
try ubobind.setDataNull(Uniforms, .static_draw);
|
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 .{
|
return .{
|
||||||
.program = program,
|
.program = program,
|
||||||
|
.vao = vao,
|
||||||
|
.ebo = ebo,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: CustomProgram) void {
|
pub fn deinit(self: CustomProgram) void {
|
||||||
|
self.ebo.destroy();
|
||||||
|
self.vao.destroy();
|
||||||
self.program.destroy();
|
self.program.destroy();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout (location = 0) in vec2 position;
|
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
gl_Position = vec4(position.x, position.y, 0.0f, 1.0f);
|
vec2 position;
|
||||||
|
position.x = (gl_VertexID == 0 || gl_VertexID == 1) ? 1. : 0.;
|
||||||
|
position.y = (gl_VertexID == 0 || gl_VertexID == 3) ? 0. : 1.;
|
||||||
|
gl_Position = vec4(position.xy, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
8
src/renderer/shaders/temp.f.glsl
Normal file
8
src/renderer/shaders/temp.f.glsl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 out_FragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// read
|
||||||
|
out_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
}
|
Reference in New Issue
Block a user