Files
wehub-resource-sync bd44b5aa08
Nix / Required Checks: Nix (push) Blocked by required conditions
Nix / check-zig-cache-hash (push) Waiting to run
Test / skip (push) Waiting to run
Test / Required Checks: Test (push) Blocked by required conditions
Test / build-bench (push) Blocked by required conditions
Test / list-examples (push) Blocked by required conditions
Test / Example ${{ matrix.dir }} (Windows) (push) Blocked by required conditions
Test / Example ${{ matrix.dir }} (push) Blocked by required conditions
Test / build-cmake (push) Blocked by required conditions
Test / test-lib-vt-pkgconfig (push) Blocked by required conditions
Test / build-flatpak (push) Blocked by required conditions
Test / build-snap (push) Blocked by required conditions
Test / build-linux (namespace-profile-ghostty-md-arm64) (push) Blocked by required conditions
Test / build-nix (namespace-profile-ghostty-md) (push) Blocked by required conditions
Test / build-libghostty-vt (aarch64-linux) (push) Blocked by required conditions
Test / build-libghostty-vt (aarch64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt (wasm32-freestanding) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-linux) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-linux-musl) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-windows-gnu) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (aarch64-ios) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (aarch64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (x86_64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt-android (aarch64-linux-android) (push) Blocked by required conditions
Test / build-libghostty-vt-android (arm-linux-androideabi) (push) Blocked by required conditions
Test / build-libghostty-vt-android (x86_64-linux-android) (push) Blocked by required conditions
Test / build-libghostty-vt-windows (push) Blocked by required conditions
Test / build-libghostty-windows-gnu (push) Blocked by required conditions
Test / build-linux (namespace-profile-ghostty-md) (push) Blocked by required conditions
Test / build-linux-libghostty (push) Blocked by required conditions
Test / build-nix (namespace-profile-ghostty-md-arm64) (push) Blocked by required conditions
Test / build-dist (push) Blocked by required conditions
Test / build-dist-lib-vt (push) Blocked by required conditions
Test / trigger-snap (push) Blocked by required conditions
Test / trigger-flatpak (push) Blocked by required conditions
Test / build-macos (push) Blocked by required conditions
Test / build-macos-freetype (push) Blocked by required conditions
Test / test (push) Blocked by required conditions
Test / test-lib-vt (push) Blocked by required conditions
Test / GTK x11=false wayland=false (push) Blocked by required conditions
Test / GTK x11=true wayland=false (push) Blocked by required conditions
Test / GTK x11=false wayland=true (push) Blocked by required conditions
Test / GTK x11=true wayland=true (push) Blocked by required conditions
Test / Build -Dsimd=false (push) Blocked by required conditions
Test / Build -Dsimd=true (push) Blocked by required conditions
Test / Build -Dsentry=false (push) Blocked by required conditions
Test / Build -Dsentry=true (push) Blocked by required conditions
Test / test-macos (push) Blocked by required conditions
Test / test-windows (push) Blocked by required conditions
Test / Build -Di18n=false (push) Blocked by required conditions
Test / Build -Di18n=true (push) Blocked by required conditions
Test / Build test/fuzz-libghostty (push) Blocked by required conditions
Test / zig-fmt (push) Blocked by required conditions
Test / GitHub Actions Pins (push) Blocked by required conditions
Test / prettier (push) Blocked by required conditions
Test / swiftlint (push) Blocked by required conditions
Test / alejandra (push) Blocked by required conditions
Test / typos (push) Blocked by required conditions
Test / shellcheck (push) Blocked by required conditions
Test / translations (push) Blocked by required conditions
Test / blueprint-compiler (push) Blocked by required conditions
Test / Test pkg/wuffs (push) Blocked by required conditions
Test / Test build on Debian 13 (push) Blocked by required conditions
Test / valgrind (push) Blocked by required conditions
chore: import upstream snapshot with attribution
2026-07-13 12:02:48 +08:00

117 lines
3.3 KiB
Zig

const Framebuffer = @This();
const std = @import("std");
const c = @import("c.zig").c;
const errors = @import("errors.zig");
const glad = @import("glad.zig");
const Texture = @import("Texture.zig");
const Renderbuffer = @import("Renderbuffer.zig");
id: c.GLuint,
/// Create a single buffer.
pub fn create() !Framebuffer {
var fbo: c.GLuint = undefined;
glad.context.GenFramebuffers.?(1, &fbo);
return .{ .id = fbo };
}
pub fn destroy(v: Framebuffer) void {
glad.context.DeleteFramebuffers.?(1, &v.id);
}
pub fn bind(v: Framebuffer, target: Target) !Binding {
// The default framebuffer is documented as being zero but
// on multiple OpenGL drivers its not zero, so we grab it
// at runtime.
var current: c.GLint = undefined;
glad.context.GetIntegerv.?(c.GL_FRAMEBUFFER_BINDING, &current);
glad.context.BindFramebuffer.?(@intFromEnum(target), v.id);
return .{ .target = target, .previous = @intCast(current) };
}
/// Enum for possible binding targets.
pub const Target = enum(c_uint) {
framebuffer = c.GL_FRAMEBUFFER,
draw = c.GL_DRAW_FRAMEBUFFER,
read = c.GL_READ_FRAMEBUFFER,
_,
};
pub const Attachment = enum(c_uint) {
color0 = c.GL_COLOR_ATTACHMENT0,
depth = c.GL_DEPTH_ATTACHMENT,
stencil = c.GL_STENCIL_ATTACHMENT,
depth_stencil = c.GL_DEPTH_STENCIL_ATTACHMENT,
_,
};
pub const Status = enum(c_uint) {
complete = c.GL_FRAMEBUFFER_COMPLETE,
undefined = c.GL_FRAMEBUFFER_UNDEFINED,
incomplete_attachment = c.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
incomplete_missing_attachment = c.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT,
incomplete_draw_buffer = c.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER,
incomplete_read_buffer = c.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER,
unsupported = c.GL_FRAMEBUFFER_UNSUPPORTED,
incomplete_multisample = c.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE,
incomplete_layer_targets = c.GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS,
_,
};
pub const Binding = struct {
target: Target,
previous: c.GLuint,
pub fn unbind(self: Binding) void {
glad.context.BindFramebuffer.?(
@intFromEnum(self.target),
self.previous,
);
}
pub fn texture2D(
self: Binding,
attachment: Attachment,
textarget: Texture.Target,
texture: Texture,
level: c.GLint,
) !void {
glad.context.FramebufferTexture2D.?(
@intFromEnum(self.target),
@intFromEnum(attachment),
@intFromEnum(textarget),
texture.id,
level,
);
try errors.getError();
}
pub fn renderbuffer(
self: Binding,
attachment: Attachment,
buffer: Renderbuffer,
) !void {
glad.context.FramebufferRenderbuffer.?(
@intFromEnum(self.target),
@intFromEnum(attachment),
c.GL_RENDERBUFFER,
buffer.id,
);
try errors.getError();
}
pub fn drawBuffers(
self: Binding,
bufs: []Attachment,
) !void {
_ = self;
glad.context.DrawBuffers.?(@intCast(bufs.len), bufs.ptr);
try errors.getError();
}
pub fn checkStatus(self: Binding) Status {
return @enumFromInt(glad.context.CheckFramebufferStatus.?(@intFromEnum(self.target)));
}
};