aboutsummaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-03-15 15:33:58 +0100
committeremersion <contact@emersion.fr>2018-03-15 15:33:58 +0100
commit824a95ad19062e867178593f0937d14049422989 (patch)
tree1ad1793d6e7379979340eff1f0385afa549ea58d /render
parentd26b67cb06509fb39d9ed473a5d27b1f241ff635 (diff)
matrix: use 2D matrices
Diffstat (limited to 'render')
-rw-r--r--render/gles2/renderer.c24
-rw-r--r--render/gles2/shaders.c67
-rw-r--r--render/gles2/texture.c13
-rw-r--r--render/wlr_renderer.c10
-rw-r--r--render/wlr_texture.c2
5 files changed, 57 insertions, 59 deletions
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 9134a2fd..e0a98d29 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -85,11 +85,13 @@ static void init_default_shaders() {
if (!compile_program(quad_vertex_src, quad_fragment_src, &shaders.quad)) {
goto error;
}
- if (!compile_program(quad_vertex_src, ellipse_fragment_src, &shaders.ellipse)) {
+ if (!compile_program(quad_vertex_src, ellipse_fragment_src,
+ &shaders.ellipse)) {
goto error;
}
if (glEGLImageTargetTexture2DOES) {
- if (!compile_program(quad_vertex_src, fragment_src_external, &shaders.external)) {
+ if (!compile_program(quad_vertex_src, fragment_src_external,
+ &shaders.external)) {
goto error;
}
}
@@ -170,16 +172,16 @@ static void draw_quad() {
GL_CALL(glDisableVertexAttribArray(1));
}
-static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer,
- struct wlr_texture *texture, const float matrix[static 16],
- float alpha) {
+static bool wlr_gles2_render_texture_with_matrix(
+ struct wlr_renderer *wlr_renderer, struct wlr_texture *texture,
+ const float matrix[static 9], float alpha) {
if (!texture || !texture->valid) {
wlr_log(L_ERROR, "attempt to render invalid texture");
return false;
}
wlr_texture_bind(texture);
- GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix));
+ GL_CALL(glUniformMatrix3fv(0, 1, GL_FALSE, matrix));
GL_CALL(glUniform1f(2, alpha));
draw_quad();
return true;
@@ -187,17 +189,17 @@ static bool wlr_gles2_render_texture(struct wlr_renderer *wlr_renderer,
static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer,
- const float color[static 4], const float matrix[static 16]) {
+ const float color[static 4], const float matrix[static 9]) {
GL_CALL(glUseProgram(shaders.quad));
- GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, matrix));
+ GL_CALL(glUniformMatrix3fv(0, 1, GL_FALSE, matrix));
GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3]));
draw_quad();
}
static void wlr_gles2_render_ellipse(struct wlr_renderer *wlr_renderer,
- const float color[static 4], const float matrix[static 16]) {
+ const float color[static 4], const float matrix[static 9]) {
GL_CALL(glUseProgram(shaders.ellipse));
- GL_CALL(glUniformMatrix4fv(0, 1, GL_TRUE, matrix));
+ GL_CALL(glUniformMatrix3fv(0, 1, GL_TRUE, matrix));
GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3]));
draw_quad();
}
@@ -258,7 +260,7 @@ static struct wlr_renderer_impl wlr_renderer_impl = {
.clear = wlr_gles2_clear,
.scissor = wlr_gles2_scissor,
.texture_create = wlr_gles2_texture_create,
- .render_with_matrix = wlr_gles2_render_texture,
+ .render_texture_with_matrix = wlr_gles2_render_texture_with_matrix,
.render_quad = wlr_gles2_render_quad,
.render_ellipse = wlr_gles2_render_ellipse,
.formats = wlr_gles2_formats,
diff --git a/render/gles2/shaders.c b/render/gles2/shaders.c
index 46a10248..9d3a67c2 100644
--- a/render/gles2/shaders.c
+++ b/render/gles2/shaders.c
@@ -3,29 +3,29 @@
// Colored quads
const GLchar quad_vertex_src[] =
-"uniform mat4 proj;"
+"uniform mat3 proj;"
"uniform vec4 color;"
"attribute vec2 pos;"
"attribute vec2 texcoord;"
"varying vec4 v_color;"
"varying vec2 v_texcoord;"
-"mat4 transpose(in mat4 inMatrix) {"
-" vec4 i0 = inMatrix[0];"
-" vec4 i1 = inMatrix[1];"
-" vec4 i2 = inMatrix[2];"
-" vec4 i3 = inMatrix[3];"
-" mat4 outMatrix = mat4("
-" vec4(i0.x, i1.x, i2.x, i3.x),"
-" vec4(i0.y, i1.y, i2.y, i3.y),"
-" vec4(i0.z, i1.z, i2.z, i3.z),"
-" vec4(i0.w, i1.w, i2.w, i3.w)"
-" );"
-" return outMatrix;"
+""
+"mat3 transpose(in mat3 inMatrix) {"
+" vec3 i0 = inMatrix[0];"
+" vec3 i1 = inMatrix[1];"
+" vec3 i2 = inMatrix[2];"
+" mat3 outMatrix = mat3("
+" vec3(i0.x, i1.x, i2.x),"
+" vec3(i0.y, i1.y, i2.y),"
+" vec3(i0.z, i1.z, i2.z)"
+" );"
+" return outMatrix;"
"}"
+""
"void main() {"
-" gl_Position = transpose(proj) * vec4(pos, 0.0, 1.0);"
-" v_color = color;"
-" v_texcoord = texcoord;"
+" gl_Position = vec4(transpose(proj) * vec3(pos, 1.0), 1.0);"
+" v_color = color;"
+" v_texcoord = texcoord;"
"}";
const GLchar quad_fragment_src[] =
@@ -49,26 +49,25 @@ const GLchar ellipse_fragment_src[] =
// Textured quads
const GLchar vertex_src[] =
-"uniform mat4 proj;"
+"uniform mat3 proj;"
"attribute vec2 pos;"
"attribute vec2 texcoord;"
"varying vec2 v_texcoord;"
-"mat4 transpose(in mat4 inMatrix) {"
-" vec4 i0 = inMatrix[0];"
-" vec4 i1 = inMatrix[1];"
-" vec4 i2 = inMatrix[2];"
-" vec4 i3 = inMatrix[3];"
-" mat4 outMatrix = mat4("
-" vec4(i0.x, i1.x, i2.x, i3.x),"
-" vec4(i0.y, i1.y, i2.y, i3.y),"
-" vec4(i0.z, i1.z, i2.z, i3.z),"
-" vec4(i0.w, i1.w, i2.w, i3.w)"
-" );"
""
-" return outMatrix;"
+"mat3 transpose(in mat3 inMatrix) {"
+" vec3 i0 = inMatrix[0];"
+" vec3 i1 = inMatrix[1];"
+" vec3 i2 = inMatrix[2];"
+" mat3 outMatrix = mat3("
+" vec3(i0.x, i1.x, i2.x),"
+" vec3(i0.y, i1.y, i2.y),"
+" vec3(i0.z, i1.z, i2.z)"
+" );"
+" return outMatrix;"
"}"
+""
"void main() {"
-" gl_Position = transpose(proj) * vec4(pos, 0.0, 1.0);"
+" gl_Position = vec4(transpose(proj) * vec3(pos, 1.0), 1.0);"
" v_texcoord = texcoord;"
"}";
@@ -87,8 +86,8 @@ const GLchar fragment_src_rgbx[] =
"uniform sampler2D tex;"
"uniform float alpha;"
"void main() {"
-" gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb;"
-" gl_FragColor.a = alpha;"
+" gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb;"
+" gl_FragColor.a = alpha;"
"}";
const GLchar fragment_src_external[] =
@@ -97,6 +96,6 @@ const GLchar fragment_src_external[] =
"varying vec2 v_texcoord;"
"uniform samplerExternalOES texture0;"
"void main() {"
-" vec4 col = texture2D(texture0, v_texcoord);"
-" gl_FragColor = vec4(col.rgb, col.a);"
+" vec4 col = texture2D(texture0, v_texcoord);"
+" gl_FragColor = vec4(col.rgb, col.a);"
"}";
diff --git a/render/gles2/texture.c b/render/gles2/texture.c
index 0dfebc48..9ee2a3e3 100644
--- a/render/gles2/texture.c
+++ b/render/gles2/texture.c
@@ -227,16 +227,13 @@ static bool gles2_texture_upload_eglimage(struct wlr_texture *wlr_tex,
}
static void gles2_texture_get_matrix(struct wlr_texture *_texture,
- float mat[static 16], const float projection[static 16], int x, int y) {
+ float mat[static 9], const float projection[static 9], int x, int y) {
struct wlr_gles2_texture *texture = (struct wlr_gles2_texture *)_texture;
- float world[16];
wlr_matrix_identity(mat);
- wlr_matrix_translate(world, x, y, 0);
- wlr_matrix_mul(mat, mat, world);
- wlr_matrix_scale(world,
- texture->wlr_texture.width, texture->wlr_texture.height, 1);
- wlr_matrix_mul(mat, mat, world);
- wlr_matrix_mul(mat, projection, mat);
+ wlr_matrix_translate(mat, x, y);
+ wlr_matrix_scale(mat, texture->wlr_texture.width,
+ texture->wlr_texture.height);
+ wlr_matrix_multiply(mat, projection, mat);
}
static void gles2_texture_get_buffer_size(struct wlr_texture *texture, struct
diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c
index 372e4caf..e847fcc2 100644
--- a/render/wlr_renderer.c
+++ b/render/wlr_renderer.c
@@ -35,19 +35,19 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) {
return r->impl->texture_create(r);
}
-bool wlr_render_with_matrix(struct wlr_renderer *r,
- struct wlr_texture *texture, const float matrix[static 16],
+bool wlr_render_texture_with_matrix(struct wlr_renderer *r,
+ struct wlr_texture *texture, const float matrix[static 9],
float alpha) {
- return r->impl->render_with_matrix(r, texture, matrix, alpha);
+ return r->impl->render_texture_with_matrix(r, texture, matrix, alpha);
}
void wlr_render_colored_quad(struct wlr_renderer *r,
- const float color[static 4], const float matrix[static 16]) {
+ const float color[static 4], const float matrix[static 9]) {
r->impl->render_quad(r, color, matrix);
}
void wlr_render_colored_ellipse(struct wlr_renderer *r,
- const float color[static 4], const float matrix[static 16]) {
+ const float color[static 4], const float matrix[static 9]) {
r->impl->render_ellipse(r, color, matrix);
}
diff --git a/render/wlr_texture.c b/render/wlr_texture.c
index 0bfac32c..1ec9beb9 100644
--- a/render/wlr_texture.c
+++ b/render/wlr_texture.c
@@ -54,7 +54,7 @@ bool wlr_texture_upload_eglimage(struct wlr_texture *texture,
}
void wlr_texture_get_matrix(struct wlr_texture *texture,
- float mat[static 16], const float projection[static 16], int x, int y) {
+ float mat[static 9], const float projection[static 9], int x, int y) {
texture->impl->get_matrix(texture, mat, projection, x, y);
}