aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-03-19 20:21:02 +0100
committeremersion <contact@emersion.fr>2018-03-19 20:21:02 +0100
commit6ecb0eefcba21d923bd01fce688dbd6bd399fbae (patch)
tree0ba90e941dc9029e6d9e12d8bbc85b52e183dcb7
parent6227da96b113f00b4b8134c10a43994716a53fef (diff)
render/gles2: transpose matrices before binding them
Setting glUniformMatrix3fv's transpose parameter to GL_TRUE is not allowed for OpenGL ES 2. This adds a wlr_matrix_transpose function.
-rw-r--r--include/wlr/types/wlr_matrix.h5
-rw-r--r--render/gles2/renderer.c21
-rw-r--r--types/wlr_matrix.c9
3 files changed, 30 insertions, 5 deletions
diff --git a/include/wlr/types/wlr_matrix.h b/include/wlr/types/wlr_matrix.h
index fd060d11..02111db8 100644
--- a/include/wlr/types/wlr_matrix.h
+++ b/include/wlr/types/wlr_matrix.h
@@ -5,11 +5,12 @@
#include <wlr/types/wlr_box.h>
void wlr_matrix_identity(float mat[static 9]);
+void wlr_matrix_multiply(float mat[static 9], const float a[static 9],
+ const float b[static 9]);
+void wlr_matrix_transpose(float mat[static 9], const float a[static 9]);
void wlr_matrix_translate(float mat[static 9], float x, float y);
void wlr_matrix_scale(float mat[static 9], float x, float y);
void wlr_matrix_rotate(float mat[static 9], float rad);
-void wlr_matrix_multiply(float mat[static 9], const float a[static 9],
- const float b[static 9]);
void wlr_matrix_transform(float mat[static 9],
enum wl_output_transform transform);
void wlr_matrix_projection(float mat[static 9], int width, int height,
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index a212e908..8d8dd17f 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -180,8 +180,13 @@ static bool wlr_gles2_render_texture_with_matrix(
return false;
}
+ // OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
+ // to GL_FALSE
+ float transposition[9];
+ wlr_matrix_transpose(transposition, matrix);
+
wlr_texture_bind(texture);
- GL_CALL(glUniformMatrix3fv(0, 1, GL_TRUE, matrix));
+ GL_CALL(glUniformMatrix3fv(0, 1, GL_FALSE, transposition));
GL_CALL(glUniform1i(1, texture->inverted_y));
GL_CALL(glUniform1f(3, alpha));
draw_quad();
@@ -191,16 +196,26 @@ static bool wlr_gles2_render_texture_with_matrix(
static void wlr_gles2_render_quad(struct wlr_renderer *wlr_renderer,
const float color[static 4], const float matrix[static 9]) {
+ // OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
+ // to GL_FALSE
+ float transposition[9];
+ wlr_matrix_transpose(transposition, matrix);
+
GL_CALL(glUseProgram(shaders.quad));
- GL_CALL(glUniformMatrix3fv(0, 1, GL_TRUE, matrix));
+ GL_CALL(glUniformMatrix3fv(0, 1, GL_FALSE, transposition));
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 9]) {
+ // OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
+ // to GL_FALSE
+ float transposition[9];
+ wlr_matrix_transpose(transposition, matrix);
+
GL_CALL(glUseProgram(shaders.ellipse));
- GL_CALL(glUniformMatrix3fv(0, 1, GL_TRUE, matrix));
+ GL_CALL(glUniformMatrix3fv(0, 1, GL_FALSE, transposition));
GL_CALL(glUniform4f(1, color[0], color[1], color[2], color[3]));
draw_quad();
}
diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c
index c5fa1340..6eb47ca8 100644
--- a/types/wlr_matrix.c
+++ b/types/wlr_matrix.c
@@ -33,6 +33,15 @@ void wlr_matrix_multiply(float mat[static 9], const float a[static 9],
memcpy(mat, product, sizeof(product));
}
+void wlr_matrix_transpose(float mat[static 9], const float a[static 9]) {
+ float transposition[9] = {
+ a[0], a[3], a[6],
+ a[1], a[4], a[7],
+ a[2], a[5], a[8],
+ };
+ memcpy(mat, transposition, sizeof(transposition));
+}
+
void wlr_matrix_translate(float mat[static 9], float x, float y) {
float translate[9] = {
1.0f, 0.0f, x,