aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/pkg/opengl/Shader.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/pkg/opengl/Shader.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/pkg/opengl/Shader.zig')
-rw-r--r--vendor/libghostty-vt/pkg/opengl/Shader.zig56
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/pkg/opengl/Shader.zig b/vendor/libghostty-vt/pkg/opengl/Shader.zig
new file mode 100644
index 00000000..8973ace3
--- /dev/null
+++ b/vendor/libghostty-vt/pkg/opengl/Shader.zig
@@ -0,0 +1,56 @@
+const Shader = @This();
+
+const std = @import("std");
+const assert = std.debug.assert;
+const log = std.log.scoped(.opengl);
+
+const c = @import("c.zig").c;
+const errors = @import("errors.zig");
+const glad = @import("glad.zig");
+
+id: c.GLuint,
+
+pub inline fn create(typ: c.GLenum) errors.Error!Shader {
+ const id = glad.context.CreateShader.?(typ);
+ if (id == 0) {
+ try errors.mustError();
+ unreachable;
+ }
+
+ log.debug("shader created id={}", .{id});
+ return Shader{ .id = id };
+}
+
+/// Set the source and compile a shader.
+pub inline fn setSourceAndCompile(s: Shader, source: [:0]const u8) !void {
+ glad.context.ShaderSource.?(s.id, 1, &@as([*c]const u8, @ptrCast(source)), null);
+ glad.context.CompileShader.?(s.id);
+
+ // Check if compilation succeeded
+ var success: c_int = undefined;
+ glad.context.GetShaderiv.?(s.id, c.GL_COMPILE_STATUS, &success);
+ if (success == c.GL_TRUE) return;
+ log.err("shader compilation failure id={} message={s}", .{
+ s.id,
+ std.mem.sliceTo(&s.getInfoLog(), 0),
+ });
+ return error.CompileFailed;
+}
+
+/// getInfoLog returns the info log for this shader. This attempts to
+/// keep the log fully stack allocated and is therefore limited to a max
+/// amount of elements.
+//
+// NOTE(mitchellh): we can add a dynamic version that uses an allocator
+// if we ever need it.
+pub inline fn getInfoLog(s: Shader) [512]u8 {
+ var msg: [512]u8 = undefined;
+ glad.context.GetShaderInfoLog.?(s.id, msg.len, null, &msg);
+ return msg;
+}
+
+pub inline fn destroy(s: Shader) void {
+ assert(s.id != 0);
+ glad.context.DeleteShader.?(s.id);
+ log.debug("shader destroyed id={}", .{s.id});
+}