From 5cb175ff63a93c5ed1fcc80dd0976d4ee6614db0 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Wed, 25 Jun 2025 10:53:42 -0600 Subject: [PATCH] renderer/OpenGL: use compressed texture formats for images BPTC is required to be available OpenGL >= 4.2 and our minimum is 4.3 so this is safe in terms of support. I tested briefly in a VM and didn't encounter any problems so this should just be a complete win. (Note: texture data is already automatically compressed on Metal) --- pkg/opengl/Texture.zig | 6 ++++-- src/renderer/OpenGL.zig | 2 +- src/renderer/opengl/Texture.zig | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/opengl/Texture.zig b/pkg/opengl/Texture.zig index 4a1d61433..2c8e05eff 100644 --- a/pkg/opengl/Texture.zig +++ b/pkg/opengl/Texture.zig @@ -74,6 +74,9 @@ pub const InternalFormat = enum(c_int) { srgb = c.GL_SRGB8, srgba = c.GL_SRGB8_ALPHA8, + rgba_compressed = c.GL_COMPRESSED_RGBA_BPTC_UNORM, + srgba_compressed = c.GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, + // There are so many more that I haven't filled in. _, }; @@ -126,7 +129,6 @@ pub const Binding = struct { internal_format: InternalFormat, width: c.GLsizei, height: c.GLsizei, - border: c.GLint, format: Format, typ: DataType, data: ?*const anyopaque, @@ -137,7 +139,7 @@ pub const Binding = struct { @intFromEnum(internal_format), width, height, - border, + 0, @intFromEnum(format), @intFromEnum(typ), data, diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 3b4ba6d80..e112c0df7 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -395,7 +395,7 @@ pub inline fn textureOptions(self: OpenGL) Texture.Options { _ = self; return .{ .format = .rgba, - .internal_format = .srgba, + .internal_format = .srgba_compressed, .target = .@"2D", }; } diff --git a/src/renderer/opengl/Texture.zig b/src/renderer/opengl/Texture.zig index 07123922f..9be2b7078 100644 --- a/src/renderer/opengl/Texture.zig +++ b/src/renderer/opengl/Texture.zig @@ -57,7 +57,6 @@ pub fn init( opts.internal_format, @intCast(width), @intCast(height), - 0, opts.format, .UnsignedByte, if (data) |d| @ptrCast(d.ptr) else null,