summaryrefslogtreecommitdiff
path: root/render/fx_renderer/matrix.c
diff options
context:
space:
mode:
authorErik Reider <[email protected]>2023-07-13 14:55:28 +0200
committerWilliam McKinnon <[email protected]>2023-07-18 13:14:53 -0400
commitd462d952de20bdb7c3c84b05ed94d15b07ee5116 (patch)
tree7cbe0e380c6c130495a30d8728365ab49cc4d956 /render/fx_renderer/matrix.c
parent920c3c70d20e58b4af5a7abe52b24f47b90bc575 (diff)
feat: initial fx_renderer implementation
Diffstat (limited to 'render/fx_renderer/matrix.c')
-rw-r--r--render/fx_renderer/matrix.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/render/fx_renderer/matrix.c b/render/fx_renderer/matrix.c
new file mode 100644
index 0000000..8f0fe15
--- /dev/null
+++ b/render/fx_renderer/matrix.c
@@ -0,0 +1,70 @@
+#include <math.h>
+#include <string.h>
+#include <wlr/types/wlr_output.h>
+
+#include "render/fx_renderer/matrix.h"
+
+static const float transforms[][9] = {
+ [WL_OUTPUT_TRANSFORM_NORMAL] = {
+ 1.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f,
+ },
+ [WL_OUTPUT_TRANSFORM_90] = {
+ 0.0f, 1.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f,
+ },
+ [WL_OUTPUT_TRANSFORM_180] = {
+ -1.0f, 0.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f,
+ },
+ [WL_OUTPUT_TRANSFORM_270] = {
+ 0.0f, -1.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f,
+ },
+ [WL_OUTPUT_TRANSFORM_FLIPPED] = {
+ -1.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f,
+ },
+ [WL_OUTPUT_TRANSFORM_FLIPPED_90] = {
+ 0.0f, 1.0f, 0.0f,
+ 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f,
+ },
+ [WL_OUTPUT_TRANSFORM_FLIPPED_180] = {
+ 1.0f, 0.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f,
+ },
+ [WL_OUTPUT_TRANSFORM_FLIPPED_270] = {
+ 0.0f, -1.0f, 0.0f,
+ -1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f,
+ },
+};
+
+void matrix_projection(float mat[static 9], int width, int height,
+ enum wl_output_transform transform) {
+ memset(mat, 0, sizeof(*mat) * 9);
+
+ const float *t = transforms[transform];
+ float x = 2.0f / width;
+ float y = 2.0f / height;
+
+ // Rotation + reflection
+ mat[0] = x * t[0];
+ mat[1] = x * t[1];
+ mat[3] = y * -t[3];
+ mat[4] = y * -t[4];
+
+ // Translation
+ mat[2] = -copysign(1.0f, mat[0] + mat[1]);
+ mat[5] = -copysign(1.0f, mat[3] + mat[4]);
+
+ // Identity
+ mat[8] = 1.0f;
+}