mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-25 16:42:26 +00:00
renderer/gles2: Compute texture coordinates based off of vertex positions
This commit is contained in:
parent
45b2a8eee2
commit
b1d26ed47b
@ -25,10 +25,10 @@ struct wlr_gles2_pixel_format {
|
|||||||
struct wlr_gles2_tex_shader {
|
struct wlr_gles2_tex_shader {
|
||||||
GLuint program;
|
GLuint program;
|
||||||
GLint proj;
|
GLint proj;
|
||||||
|
GLint tex_proj;
|
||||||
GLint tex;
|
GLint tex;
|
||||||
GLint alpha;
|
GLint alpha;
|
||||||
GLint pos_attrib;
|
GLint pos_attrib;
|
||||||
GLint tex_attrib;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_gles2_renderer {
|
struct wlr_gles2_renderer {
|
||||||
|
@ -321,27 +321,21 @@ static bool gles2_render_subtexture_with_matrix(
|
|||||||
glUniform1i(shader->tex, 0);
|
glUniform1i(shader->tex, 0);
|
||||||
glUniform1f(shader->alpha, alpha);
|
glUniform1f(shader->alpha, alpha);
|
||||||
|
|
||||||
const GLfloat x1 = box->x / wlr_texture->width;
|
float tex_matrix[9];
|
||||||
const GLfloat y1 = box->y / wlr_texture->height;
|
wlr_matrix_identity(tex_matrix);
|
||||||
const GLfloat x2 = (box->x + box->width) / wlr_texture->width;
|
wlr_matrix_translate(tex_matrix, box->x / texture->wlr_texture.width,
|
||||||
const GLfloat y2 = (box->y + box->height) / wlr_texture->height;
|
box->y / texture->wlr_texture.height);
|
||||||
const GLfloat texcoord[] = {
|
wlr_matrix_scale(tex_matrix, box->width / texture->wlr_texture.width,
|
||||||
x2, y1, // top right
|
box->height / texture->wlr_texture.height);
|
||||||
x1, y1, // top left
|
glUniformMatrix3fv(shader->tex_proj, 1, GL_FALSE, tex_matrix);
|
||||||
x2, y2, // bottom right
|
|
||||||
x1, y2, // bottom left
|
|
||||||
};
|
|
||||||
|
|
||||||
glVertexAttribPointer(shader->pos_attrib, 2, GL_FLOAT, GL_FALSE, 0, verts);
|
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->pos_attrib);
|
||||||
glEnableVertexAttribArray(shader->tex_attrib);
|
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
||||||
glDisableVertexAttribArray(shader->pos_attrib);
|
glDisableVertexAttribArray(shader->pos_attrib);
|
||||||
glDisableVertexAttribArray(shader->tex_attrib);
|
|
||||||
|
|
||||||
glBindTexture(texture->target, 0);
|
glBindTexture(texture->target, 0);
|
||||||
|
|
||||||
@ -828,10 +822,10 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
renderer->shaders.tex_rgba.proj = glGetUniformLocation(prog, "proj");
|
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.tex = glGetUniformLocation(prog, "tex");
|
||||||
renderer->shaders.tex_rgba.alpha = glGetUniformLocation(prog, "alpha");
|
renderer->shaders.tex_rgba.alpha = glGetUniformLocation(prog, "alpha");
|
||||||
renderer->shaders.tex_rgba.pos_attrib = glGetAttribLocation(prog, "pos");
|
renderer->shaders.tex_rgba.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||||
renderer->shaders.tex_rgba.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
|
||||||
|
|
||||||
renderer->shaders.tex_rgbx.program = prog =
|
renderer->shaders.tex_rgbx.program = prog =
|
||||||
link_program(renderer, common_vert_src, tex_rgbx_frag_src);
|
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;
|
goto error;
|
||||||
}
|
}
|
||||||
renderer->shaders.tex_rgbx.proj = glGetUniformLocation(prog, "proj");
|
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.tex = glGetUniformLocation(prog, "tex");
|
||||||
renderer->shaders.tex_rgbx.alpha = glGetUniformLocation(prog, "alpha");
|
renderer->shaders.tex_rgbx.alpha = glGetUniformLocation(prog, "alpha");
|
||||||
renderer->shaders.tex_rgbx.pos_attrib = glGetAttribLocation(prog, "pos");
|
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) {
|
if (renderer->exts.OES_egl_image_external) {
|
||||||
renderer->shaders.tex_ext.program = prog =
|
renderer->shaders.tex_ext.program = prog =
|
||||||
@ -851,10 +845,10 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
renderer->shaders.tex_ext.proj = glGetUniformLocation(prog, "proj");
|
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.tex = glGetUniformLocation(prog, "tex");
|
||||||
renderer->shaders.tex_ext.alpha = glGetUniformLocation(prog, "alpha");
|
renderer->shaders.tex_ext.alpha = glGetUniformLocation(prog, "alpha");
|
||||||
renderer->shaders.tex_ext.pos_attrib = glGetAttribLocation(prog, "pos");
|
renderer->shaders.tex_ext.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||||
renderer->shaders.tex_ext.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pop_gles2_debug(renderer);
|
pop_gles2_debug(renderer);
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
uniform mat3 proj;
|
uniform mat3 proj;
|
||||||
|
uniform mat3 tex_proj;
|
||||||
attribute vec2 pos;
|
attribute vec2 pos;
|
||||||
attribute vec2 texcoord;
|
|
||||||
varying vec2 v_texcoord;
|
varying vec2 v_texcoord;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(vec3(pos, 1.0) * proj, 1.0);
|
vec3 pos3 = vec3(pos, 1.0);
|
||||||
v_texcoord = texcoord;
|
gl_Position = vec4(pos3 * proj, 1.0);
|
||||||
|
v_texcoord = (pos3 * tex_proj).xy;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user