From 810ab6a8447f45a84155b58a00606afef5637eb3 Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Thu, 26 Jun 2025 16:34:51 -0600 Subject: [PATCH 1/2] renderer/OpenGL: revert change to compressed texture format This was applied to the wrong thing by accident, making the custom shader ping-pong textures compressed, which breaks custom shaders because compressed texture formats are not color renderable. Additionally, I've not switched the compressed format to the correct texture options, because I tried that and it turns out that the default compression applied by drivers can't be trusted to be good quality and generally speaking looks terrible. In the future we can explore doing the compression ourselves CPU-side with something like b7enc_rdo. --- src/renderer/OpenGL.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index e112c0df7..3b4ba6d80 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_compressed, + .internal_format = .srgba, .target = .@"2D", }; } From d6db3013be7aff7982814c1f9ea4c17d71c71f8f Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Thu, 26 Jun 2025 16:37:06 -0600 Subject: [PATCH 2/2] renderer/OpenGL: switch image texture from Rect to 2D We were using the Rectangle target for simpler addressing, since that allows for pixel coordinates instead of normalized coordinates, but there are downsides to rectangle textures, including not supporting compressed texture formats, and we do probably want to use compressed formats in the future, so I'm making this change now. --- src/renderer/OpenGL.zig | 2 +- src/renderer/shaders/glsl/bg_image.f.glsl | 7 ++++--- src/renderer/shaders/glsl/bg_image.v.glsl | 4 ++-- src/renderer/shaders/glsl/image.f.glsl | 2 +- src/renderer/shaders/glsl/image.v.glsl | 7 ++++--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 3b4ba6d80..cf195361e 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -428,7 +428,7 @@ pub inline fn imageTextureOptions( return .{ .format = format.toPixelFormat(), .internal_format = if (srgb) .srgba else .rgba, - .target = .Rectangle, + .target = .@"2D", }; } diff --git a/src/renderer/shaders/glsl/bg_image.f.glsl b/src/renderer/shaders/glsl/bg_image.f.glsl index 7c3e4363a..ee1195ef5 100644 --- a/src/renderer/shaders/glsl/bg_image.f.glsl +++ b/src/renderer/shaders/glsl/bg_image.f.glsl @@ -4,7 +4,7 @@ // so as to align with our texture's directionality. layout(origin_upper_left) in vec4 gl_FragCoord; -layout(binding = 0) uniform sampler2DRect image; +layout(binding = 0) uniform sampler2D image; flat in vec4 bg_color; flat in vec2 offset; @@ -23,7 +23,7 @@ void main() { // size of the texture to the dest rect size. vec2 tex_coord = (gl_FragCoord.xy - offset) * scale; - vec2 tex_size = textureSize(image); + vec2 tex_size = textureSize(image, 0); // If we need to repeat the texture, wrap the coordinates. if (repeat != 0) { @@ -38,7 +38,8 @@ void main() { { rgba = vec4(0.0); } else { - rgba = texture(image, tex_coord); + // We divide by the texture size to normalize for sampling. + rgba = texture(image, tex_coord / tex_size); if (!use_linear_blending) { rgba = unlinearize(rgba); diff --git a/src/renderer/shaders/glsl/bg_image.v.glsl b/src/renderer/shaders/glsl/bg_image.v.glsl index 875c40518..d55aa174a 100644 --- a/src/renderer/shaders/glsl/bg_image.v.glsl +++ b/src/renderer/shaders/glsl/bg_image.v.glsl @@ -1,6 +1,6 @@ #include "common.glsl" -layout(binding = 0) uniform sampler2DRect image; +layout(binding = 0) uniform sampler2D image; layout(location = 0) in float in_opacity; layout(location = 1) in uint info; @@ -64,7 +64,7 @@ void main() { repeat = info & BG_IMAGE_REPEAT; vec2 screen_size = screen_size; - vec2 tex_size = textureSize(image); + vec2 tex_size = textureSize(image, 0); vec2 dest_size = tex_size; switch (info & BG_IMAGE_FIT) { diff --git a/src/renderer/shaders/glsl/image.f.glsl b/src/renderer/shaders/glsl/image.f.glsl index cd93cf666..4f89d7a78 100644 --- a/src/renderer/shaders/glsl/image.f.glsl +++ b/src/renderer/shaders/glsl/image.f.glsl @@ -1,6 +1,6 @@ #include "common.glsl" -layout(binding = 0) uniform sampler2DRect image; +layout(binding = 0) uniform sampler2D image; in vec2 tex_coord; diff --git a/src/renderer/shaders/glsl/image.v.glsl b/src/renderer/shaders/glsl/image.v.glsl index 55b12ed68..779fae32f 100644 --- a/src/renderer/shaders/glsl/image.v.glsl +++ b/src/renderer/shaders/glsl/image.v.glsl @@ -1,6 +1,6 @@ #include "common.glsl" -layout(binding = 0) uniform sampler2DRect image; +layout(binding = 0) uniform sampler2D image; layout(location = 0) in vec2 grid_pos; layout(location = 1) in vec2 cell_offset; @@ -32,11 +32,12 @@ void main() { // The texture coordinates start at our source x/y // and add the width/height depending on the corner. - // - // We don't need to normalize because we use pixel addressing for our sampler. tex_coord = source_rect.xy; tex_coord += source_rect.zw * corner; + // Normalize the coordinates. + tex_coord /= textureSize(image, 0); + // The position of our image starts at the top-left of the grid cell and // adds the source rect width/height components. vec2 image_pos = (cell_size * grid_pos) + cell_offset;