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.
pull/7697/head
Qwerasd 2025-06-26 16:37:06 -06:00
parent 810ab6a844
commit d6db3013be
5 changed files with 12 additions and 10 deletions

View File

@ -428,7 +428,7 @@ pub inline fn imageTextureOptions(
return .{
.format = format.toPixelFormat(),
.internal_format = if (srgb) .srgba else .rgba,
.target = .Rectangle,
.target = .@"2D",
};
}

View File

@ -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);

View File

@ -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) {

View File

@ -1,6 +1,6 @@
#include "common.glsl"
layout(binding = 0) uniform sampler2DRect image;
layout(binding = 0) uniform sampler2D image;
in vec2 tex_coord;

View File

@ -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;