mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 09:59:48 +01:00
renderer/gles2: Compute texture coordinates based off of vertex positions
This commit is contained in:
parent
45b2a8eee2
commit
b1d26ed47b
3 changed files with 15 additions and 20 deletions
|
@ -25,10 +25,10 @@ struct wlr_gles2_pixel_format {
|
|||
struct wlr_gles2_tex_shader {
|
||||
GLuint program;
|
||||
GLint proj;
|
||||
GLint tex_proj;
|
||||
GLint tex;
|
||||
GLint alpha;
|
||||
GLint pos_attrib;
|
||||
GLint tex_attrib;
|
||||
};
|
||||
|
||||
struct wlr_gles2_renderer {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue