aboutsummaryrefslogtreecommitdiffstats
path: root/src/gl.zig
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-03-05 17:38:04 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-10 11:44:48 +0000
commitcf3475eab439df049fb48a039801da8270dc044c (patch)
tree006e6a677696f9ce6e030614167158ff6a84c682 /src/gl.zig
parentUpdate README.md (diff)
downloadglsl-view-cf3475eab439df049fb48a039801da8270dc044c.tar.gz
glsl-view-cf3475eab439df049fb48a039801da8270dc044c.zip
implement HAP decoding straight to compressed GPU texture
Supports HAP and HAP Alpha (Hap1/Hap5) formats
Diffstat (limited to 'src/gl.zig')
-rw-r--r--src/gl.zig111
1 files changed, 76 insertions, 35 deletions
diff --git a/src/gl.zig b/src/gl.zig
index c1543dc..22a2ebe 100644
--- a/src/gl.zig
+++ b/src/gl.zig
@@ -73,54 +73,95 @@ pub const Texture = struct {
c.glDeleteTextures(1, &self.id);
}
- pub fn setData2D(self: *const Texture, width: i32, height: i32, data: [*]const u8) void {
+ pub fn allocate(self: *const Texture, width: i32, height: i32, depth: i32, format: c.GLenum) void {
c.glBindTexture(@intFromEnum(self.type), self.id);
defer c.glBindTexture(@intFromEnum(self.type), 0);
- c.glTexImage2D(
- @intFromEnum(self.type),
- 0,
- c.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, // c.GL_RGBA,
- width,
- height,
- 0,
- c.GL_RGBA,
- c.GL_UNSIGNED_BYTE,
- data,
- );
+ switch (self.type) {
+ .TEXTURE_2D => c.glTexStorage2D(
+ @intFromEnum(self.type),
+ 1,
+ format,
+ width,
+ height,
+ ),
+
+ .TEXTURE_2D_ARRAY, .TEXTURE_3D => c.glTexStorage3D(
+ @intFromEnum(self.type),
+ 1,
+ format,
+ width,
+ height,
+ depth,
+ ),
+ else => unreachable,
+ }
}
- pub fn allocate3D(self: *const Texture, width: i32, height: i32, depth: i32) void {
+ pub fn setLayer(self: *const Texture, width: i32, height: i32, layer: i32, format: c.GLenum, data: [*]const u8) void {
c.glBindTexture(@intFromEnum(self.type), self.id);
defer c.glBindTexture(@intFromEnum(self.type), 0);
- c.glTexStorage3D(
- @intFromEnum(self.type),
- 1,
- c.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, // c.GL_RGBA,
- width,
- height,
- depth,
- );
+ switch (self.type) {
+ .TEXTURE_2D => c.glTexSubImage2D(
+ @intFromEnum(self.type),
+ 0,
+ 0,
+ 0,
+ width,
+ height,
+ format,
+ c.GL_UNSIGNED_BYTE,
+ data,
+ ),
+ .TEXTURE_2D_ARRAY, .TEXTURE_3D => c.glTexSubImage3D(
+ @intFromEnum(self.type),
+ 0,
+ 0,
+ 0,
+ layer,
+ width,
+ height,
+ 1,
+ format,
+ c.GL_UNSIGNED_BYTE,
+ data,
+ ),
+ else => unreachable,
+ }
}
- pub fn setLayer3D(self: *const Texture, width: i32, height: i32, layer: i32, data: [*]const u8) void {
+ pub fn setLayerCompressed(self: *const Texture, width: i32, height: i32, layer: i32, format: c.GLenum, data: []const u8) void {
c.glBindTexture(@intFromEnum(self.type), self.id);
defer c.glBindTexture(@intFromEnum(self.type), 0);
- c.glTexSubImage3D(
- @intFromEnum(self.type),
- 0,
- 0,
- 0,
- layer,
- width,
- height,
- 1,
- c.GL_RGBA,
- c.GL_UNSIGNED_BYTE,
- data,
- );
+ switch (self.type) {
+ .TEXTURE_2D => c.glCompressedTexSubImage2D(
+ @intFromEnum(self.type),
+ 0,
+ 0,
+ 0,
+ width,
+ height,
+ format,
+ @intCast(data.len),
+ data.ptr,
+ ),
+ .TEXTURE_2D_ARRAY, .TEXTURE_3D => c.glCompressedTexSubImage3D(
+ @intFromEnum(self.type),
+ 0,
+ 0,
+ 0,
+ layer,
+ width,
+ height,
+ 1,
+ format,
+ @intCast(data.len),
+ data.ptr,
+ ),
+ else => unreachable,
+ }
}
};