Optimize text rendering for long strings

This commit is contained in:
Phireh 2024-01-06 14:35:11 +01:00
commit 3b78739efd
3 changed files with 71 additions and 56 deletions

View file

@ -1,12 +1,18 @@
#version 330 core
in vec2 texuv;
out vec4 color;
uniform sampler2D text;
in VS_OUT {
vec2 texuv;
flat int index;
} fs_in;
uniform sampler2DArray text;
uniform int letter_map[400];
uniform vec3 text_color;
void main()
{
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, texuv).r);
{
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, vec3(fs_in.texuv.xy, letter_map[fs_in.index])).r);
color = vec4(text_color, 1.0) * sampled;
}

View file

@ -1,13 +1,17 @@
#version 330 core
layout (location = 0) in vec2 vertex; // <vec2 pos>
out vec2 texuv;
uniform mat4 transform;
out VS_OUT {
vec2 texuv;
flat int index;
} vs_out;
uniform mat4 transforms[400];
uniform mat4 projection;
void main()
{
gl_Position = projection * transform * vec4(vertex.xy, 0.0, 1.0);
texuv = vertex.xy;
texuv.y=1.0f-texuv.y;
gl_Position = projection * transforms[gl_InstanceID] * vec4(vertex.xy, 0.0, 1.0);
vs_out.index = gl_InstanceID;
vs_out.texuv = vec2(vertex.x, 1.0f - vertex.y);
}