aboutsummaryrefslogtreecommitdiff
path: root/render/gles2
diff options
context:
space:
mode:
authorAlexander Orzechowski <alex@ozal.ski>2023-05-23 02:16:29 -0400
committerAlexander Orzechowski <alex@ozal.ski>2023-05-28 14:53:34 -0400
commitb1d26ed47bfd3725100bde10c20b6ee9b1045e65 (patch)
tree486826a4d1cc8410052cb9abd6eff2c1e48cde4a /render/gles2
parent45b2a8eee2f1ee30bd021cba7e918c758b8f4cea (diff)
renderer/gles2: Compute texture coordinates based off of vertex positions
Diffstat (limited to 'render/gles2')
-rw-r--r--render/gles2/renderer.c26
-rw-r--r--render/gles2/shaders/common.vert7
2 files changed, 14 insertions, 19 deletions
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 67168fe9..48883a2f 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -321,27 +321,21 @@ static bool gles2_render_subtexture_with_matrix(
glUniform1i(shader->tex, 0);
glUniform1f(shader->alpha, alpha);
- const GLfloat x1 = box->x / wlr_texture->width;
- const GLfloat y1 = box->y / wlr_texture->height;
- const GLfloat x2 = (box->x + box->width) / wlr_texture->width;
- const GLfloat y2 = (box->y + box->height) / wlr_texture->height;
- const GLfloat texcoord[] = {
- x2, y1, // top right
- x1, y1, // top left
- x2, y2, // bottom right
- x1, y2, // bottom left
- };
+ float tex_matrix[9];
+ wlr_matrix_identity(tex_matrix);
+ wlr_matrix_translate(tex_matrix, box->x / texture->wlr_texture.width,
+ box->y / texture->wlr_texture.height);
+ wlr_matrix_scale(tex_matrix, box->width / texture->wlr_texture.width,
+ box->height / texture->wlr_texture.height);
+ glUniformMatrix3fv(shader->tex_proj, 1, GL_FALSE, tex_matrix);
glVertexAttribPointer(shader->pos_attrib, 2, GL_FLOAT, GL_FALSE, 0, verts);
- glVertexAttribPointer(shader->tex_attrib, 2, GL_FLOAT, GL_FALSE, 0, texcoord);
glEnableVertexAttribArray(shader->pos_attrib);
- glEnableVertexAttribArray(shader->tex_attrib);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(shader->pos_attrib);
- glDisableVertexAttribArray(shader->tex_attrib);
glBindTexture(texture->target, 0);
@@ -828,10 +822,10 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
goto error;
}
renderer->shaders.tex_rgba.proj = glGetUniformLocation(prog, "proj");
+ renderer->shaders.tex_rgba.tex_proj = glGetUniformLocation(prog, "tex_proj");
renderer->shaders.tex_rgba.tex = glGetUniformLocation(prog, "tex");
renderer->shaders.tex_rgba.alpha = glGetUniformLocation(prog, "alpha");
renderer->shaders.tex_rgba.pos_attrib = glGetAttribLocation(prog, "pos");
- renderer->shaders.tex_rgba.tex_attrib = glGetAttribLocation(prog, "texcoord");
renderer->shaders.tex_rgbx.program = prog =
link_program(renderer, common_vert_src, tex_rgbx_frag_src);
@@ -839,10 +833,10 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
goto error;
}
renderer->shaders.tex_rgbx.proj = glGetUniformLocation(prog, "proj");
+ renderer->shaders.tex_rgbx.tex_proj = glGetUniformLocation(prog, "tex_proj");
renderer->shaders.tex_rgbx.tex = glGetUniformLocation(prog, "tex");
renderer->shaders.tex_rgbx.alpha = glGetUniformLocation(prog, "alpha");
renderer->shaders.tex_rgbx.pos_attrib = glGetAttribLocation(prog, "pos");
- renderer->shaders.tex_rgbx.tex_attrib = glGetAttribLocation(prog, "texcoord");
if (renderer->exts.OES_egl_image_external) {
renderer->shaders.tex_ext.program = prog =
@@ -851,10 +845,10 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
goto error;
}
renderer->shaders.tex_ext.proj = glGetUniformLocation(prog, "proj");
+ renderer->shaders.tex_ext.tex_proj = glGetUniformLocation(prog, "tex_proj");
renderer->shaders.tex_ext.tex = glGetUniformLocation(prog, "tex");
renderer->shaders.tex_ext.alpha = glGetUniformLocation(prog, "alpha");
renderer->shaders.tex_ext.pos_attrib = glGetAttribLocation(prog, "pos");
- renderer->shaders.tex_ext.tex_attrib = glGetAttribLocation(prog, "texcoord");
}
pop_gles2_debug(renderer);
diff --git a/render/gles2/shaders/common.vert b/render/gles2/shaders/common.vert
index 4f855a5d..f51548ab 100644
--- a/render/gles2/shaders/common.vert
+++ b/render/gles2/shaders/common.vert
@@ -1,9 +1,10 @@
uniform mat3 proj;
+uniform mat3 tex_proj;
attribute vec2 pos;
-attribute vec2 texcoord;
varying vec2 v_texcoord;
void main() {
- gl_Position = vec4(vec3(pos, 1.0) * proj, 1.0);
- v_texcoord = texcoord;
+ vec3 pos3 = vec3(pos, 1.0);
+ gl_Position = vec4(pos3 * proj, 1.0);
+ v_texcoord = (pos3 * tex_proj).xy;
}