mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-02 16:08:39 +00:00
renderer/opengl: create the screen texture
This commit is contained in:
@@ -20,8 +20,13 @@ pub fn destroy(v: Framebuffer) void {
|
||||
}
|
||||
|
||||
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, ¤t);
|
||||
glad.context.BindFramebuffer.?(@intFromEnum(target), v.id);
|
||||
return .{ .target = target };
|
||||
return .{ .target = target, .previous = @intCast(current) };
|
||||
}
|
||||
|
||||
/// Enum for possible binding targets.
|
||||
@@ -55,9 +60,13 @@ pub const Status = enum(c_uint) {
|
||||
|
||||
pub const Binding = struct {
|
||||
target: Target,
|
||||
previous: c.GLuint,
|
||||
|
||||
pub fn unbind(self: Binding) void {
|
||||
glad.context.BindFramebuffer.?(@intFromEnum(self.target), 0);
|
||||
glad.context.BindFramebuffer.?(
|
||||
@intFromEnum(self.target),
|
||||
self.previous,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn texture2D(
|
||||
@@ -78,6 +87,6 @@ pub const Binding = struct {
|
||||
}
|
||||
|
||||
pub fn checkStatus(self: Binding) Status {
|
||||
return @enumFromInt(glad.context.CheckFramebufferStatus.?(self.target));
|
||||
return @enumFromInt(glad.context.CheckFramebufferStatus.?(@intFromEnum(self.target)));
|
||||
}
|
||||
};
|
||||
|
@@ -7,11 +7,29 @@ const glad = @import("glad.zig");
|
||||
|
||||
id: c.GLuint,
|
||||
|
||||
pub inline fn active(target: c.GLenum) !void {
|
||||
pub fn active(target: c.GLenum) !void {
|
||||
glad.context.ActiveTexture.?(target);
|
||||
try errors.getError();
|
||||
}
|
||||
|
||||
/// Create a single texture.
|
||||
pub fn create() !Texture {
|
||||
var id: c.GLuint = undefined;
|
||||
glad.context.GenTextures.?(1, &id);
|
||||
return .{ .id = id };
|
||||
}
|
||||
|
||||
/// glBindTexture
|
||||
pub fn bind(v: Texture, target: Target) !Binding {
|
||||
glad.context.BindTexture.?(@intFromEnum(target), v.id);
|
||||
try errors.getError();
|
||||
return .{ .target = target };
|
||||
}
|
||||
|
||||
pub fn destroy(v: Texture) void {
|
||||
glad.context.DeleteTextures.?(1, &v.id);
|
||||
}
|
||||
|
||||
/// Enun for possible texture binding targets.
|
||||
pub const Target = enum(c_uint) {
|
||||
@"1D" = c.GL_TEXTURE_1D,
|
||||
@@ -48,8 +66,9 @@ pub const Parameter = enum(c_uint) {
|
||||
|
||||
/// Internal format enum for texture images.
|
||||
pub const InternalFormat = enum(c_int) {
|
||||
Red = c.GL_RED,
|
||||
RGBA = c.GL_RGBA,
|
||||
red = c.GL_RED,
|
||||
rgb = c.GL_RGB,
|
||||
rgba = c.GL_RGBA,
|
||||
|
||||
// There are so many more that I haven't filled in.
|
||||
_,
|
||||
@@ -57,8 +76,9 @@ pub const InternalFormat = enum(c_int) {
|
||||
|
||||
/// Format for texture images
|
||||
pub const Format = enum(c_uint) {
|
||||
Red = c.GL_RED,
|
||||
BGRA = c.GL_BGRA,
|
||||
red = c.GL_RED,
|
||||
rgb = c.GL_RGB,
|
||||
bgra = c.GL_BGRA,
|
||||
|
||||
// There are so many more that I haven't filled in.
|
||||
_,
|
||||
@@ -75,9 +95,8 @@ pub const DataType = enum(c_uint) {
|
||||
pub const Binding = struct {
|
||||
target: Target,
|
||||
|
||||
pub inline fn unbind(b: *Binding) void {
|
||||
pub fn unbind(b: *const Binding) void {
|
||||
glad.context.BindTexture.?(@intFromEnum(b.target), 0);
|
||||
b.* = undefined;
|
||||
}
|
||||
|
||||
pub fn generateMipmap(b: Binding) void {
|
||||
@@ -143,21 +162,3 @@ pub const Binding = struct {
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/// Create a single texture.
|
||||
pub inline fn create() !Texture {
|
||||
var id: c.GLuint = undefined;
|
||||
glad.context.GenTextures.?(1, &id);
|
||||
return Texture{ .id = id };
|
||||
}
|
||||
|
||||
/// glBindTexture
|
||||
pub inline fn bind(v: Texture, target: Target) !Binding {
|
||||
glad.context.BindTexture.?(@intFromEnum(target), v.id);
|
||||
try errors.getError();
|
||||
return Binding{ .target = target };
|
||||
}
|
||||
|
||||
pub inline fn destroy(v: Texture) void {
|
||||
glad.context.DeleteTextures.?(1, &v.id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user