mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-17 22:14:53 +02:00
Do the transform to UV space in the shader so that the texture can be dynamically resized
This commit is contained in:
@@ -23,13 +23,14 @@ void main() {
|
|||||||
|
|
||||||
'''\
|
'''\
|
||||||
uniform sampler2DArray sprites;
|
uniform sampler2DArray sprites;
|
||||||
|
uniform vec3 sprite_scale;
|
||||||
in vec3 texture_position_for_fs;
|
in vec3 texture_position_for_fs;
|
||||||
out vec4 final_color;
|
out vec4 final_color;
|
||||||
const vec3 background = vec3(0, 1, 0);
|
const vec3 background = vec3(0, 1, 0);
|
||||||
const vec3 foreground = vec3(0, 0, 1);
|
const vec3 foreground = vec3(0, 0, 1);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float alpha = texture(sprites, texture_position_for_fs).r;
|
float alpha = texture(sprites, texture_position_for_fs / sprite_scale).r;
|
||||||
vec3 color = background * (1 - alpha) + foreground * alpha;
|
vec3 color = background * (1 - alpha) + foreground * alpha;
|
||||||
final_color = vec4(color, 1);
|
final_color = vec4(color, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class Sprites:
|
|||||||
offset_to_start_of_row += pixels_per_line
|
offset_to_start_of_row += pixels_per_line
|
||||||
|
|
||||||
# UV space co-ordinates
|
# UV space co-ordinates
|
||||||
left, top, z = self.x / self.xnum, self.y / self.ynum, len(self.previous_layers)
|
left, top, z = self.x, self.y, len(self.previous_layers)
|
||||||
|
|
||||||
# Now increment the current cell position
|
# Now increment the current cell position
|
||||||
self.x += 1
|
self.x += 1
|
||||||
@@ -109,7 +109,7 @@ class Sprites:
|
|||||||
self.texture_id = gl.glGenTextures(1)
|
self.texture_id = gl.glGenTextures(1)
|
||||||
self.current_layer_buffer = (gl.GLubyte * (self.width * self.height))()
|
self.current_layer_buffer = (gl.GLubyte * (self.width * self.height))()
|
||||||
self.commit_all_layers()
|
self.commit_all_layers()
|
||||||
return left, top, left + self.dx, top + self.dy, z
|
return left, top, left + 1, top + 1, z
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
gl.glActiveTexture(self.texture_unit)
|
gl.glActiveTexture(self.texture_unit)
|
||||||
@@ -193,6 +193,7 @@ class ShaderProgram:
|
|||||||
gl.glUseProgram(self.program_id)
|
gl.glUseProgram(self.program_id)
|
||||||
gl.glBindVertexArray(self.vao_id)
|
gl.glBindVertexArray(self.vao_id)
|
||||||
gl.glUniform1i(self.uniform_location('sprites'), self.sprites.sampler_num)
|
gl.glUniform1i(self.uniform_location('sprites'), self.sprites.sampler_num)
|
||||||
|
gl.glUniform3f(self.uniform_location('sprite_scale'), self.sprites.xnum, self.sprites.ynum, 1)
|
||||||
self.sprites.__enter__()
|
self.sprites.__enter__()
|
||||||
self.is_active = True
|
self.is_active = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user