From e83854a7607c9f3dab3d153f5b0aae48a08f4053 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 30 Jul 2023 11:13:48 +0900 Subject: [PATCH] [vulkan] Make z_up and box_rotations public They're now qfv_* and shared within the vulkan renderer. qfv_z_up cannot be shared across renderers as they have their own ideas for the world frame. qfv_box_rotations currently can't be shared across renderers because if the Y-axis flip and the way it's handled, but sharing should be achievable by modifying the other renderers to handle the sides correctly (glsl and gl need to do lookups for the side enums, sw just needs to be shown which way is up). --- include/QF/Vulkan/projection.h | 3 ++ libs/video/renderer/vulkan/projection.c | 50 +++++++++++++++++ libs/video/renderer/vulkan/vulkan_matrices.c | 56 ++------------------ 3 files changed, 56 insertions(+), 53 deletions(-) diff --git a/include/QF/Vulkan/projection.h b/include/QF/Vulkan/projection.h index 7936008aa..1b424ef9b 100644 --- a/include/QF/Vulkan/projection.h +++ b/include/QF/Vulkan/projection.h @@ -9,4 +9,7 @@ void QFV_Orthographic (mat4f_t proj, float xmin, float xmax, void QFV_PerspectiveTan (mat4f_t proj, float fov_x, float fov_y); void QFV_PerspectiveCos (mat4f_t proj, float fov); +extern const mat4f_t qfv_z_up; +extern const mat4f_t qfv_box_rotations[6]; + #endif//__QF_Vulkan_projection_h diff --git a/libs/video/renderer/vulkan/projection.c b/libs/video/renderer/vulkan/projection.c index 3b70aafd7..1c2d87c3c 100644 --- a/libs/video/renderer/vulkan/projection.c +++ b/libs/video/renderer/vulkan/projection.c @@ -35,6 +35,56 @@ #include "r_internal.h" +//FIXME? The box rotations (in particular top/bottom) for vulkan are not +//compatible with the other renderers, so need a local version +const mat4f_t qfv_box_rotations[] = { + [BOX_FRONT] = { + { 1, 0, 0, 0}, + { 0, 1, 0, 0}, + { 0, 0, 1, 0}, + { 0, 0, 0, 1} + }, + [BOX_RIGHT] = { + { 0,-1, 0, 0}, + { 1, 0, 0, 0}, + { 0, 0, 1, 0}, + { 0, 0, 0, 1} + }, + [BOX_BEHIND] = { + {-1, 0, 0, 0}, + { 0,-1, 0, 0}, + { 0, 0, 1, 0}, + { 0, 0, 0, 1} + }, + [BOX_LEFT] = { + { 0, 1, 0, 0}, + {-1, 0, 0, 0}, + { 0, 0, 1, 0}, + { 0, 0, 0, 1} + }, + [BOX_BOTTOM] = { + { 0, 0, 1, 0}, + { 0, 1, 0, 0}, + {-1, 0, 0, 0}, + { 0, 0, 0, 1} + }, + [BOX_TOP] = { + { 0, 0,-1, 0}, + { 0, 1, 0, 0}, + { 1, 0, 0, 0}, + { 0, 0, 0, 1} + }, +}; + +// Quake's world is z-up, x-forward, y-left, but Vulkan's world is +// z-forward, x-right, y-down. +const mat4f_t qfv_z_up = { + { 0, 0, 1, 0}, + {-1, 0, 0, 0}, + { 0,-1, 0, 0}, + { 0, 0, 0, 1}, +}; + void QFV_Orthographic (mat4f_t proj, float xmin, float xmax, float ymin, float ymax, float znear, float zfar) diff --git a/libs/video/renderer/vulkan/vulkan_matrices.c b/libs/video/renderer/vulkan/vulkan_matrices.c index 1555f0573..5293728e0 100644 --- a/libs/video/renderer/vulkan/vulkan_matrices.c +++ b/libs/video/renderer/vulkan/vulkan_matrices.c @@ -58,56 +58,6 @@ #include "r_internal.h" #include "vid_vulkan.h" -//FIXME? The box rotations (in particular top/bottom) for vulkan are not -//compatible with the other renderers, so need a local version -static mat4f_t box_rotations[] = { - [BOX_FRONT] = { - { 1, 0, 0, 0}, - { 0, 1, 0, 0}, - { 0, 0, 1, 0}, - { 0, 0, 0, 1} - }, - [BOX_RIGHT] = { - { 0,-1, 0, 0}, - { 1, 0, 0, 0}, - { 0, 0, 1, 0}, - { 0, 0, 0, 1} - }, - [BOX_BEHIND] = { - {-1, 0, 0, 0}, - { 0,-1, 0, 0}, - { 0, 0, 1, 0}, - { 0, 0, 0, 1} - }, - [BOX_LEFT] = { - { 0, 1, 0, 0}, - {-1, 0, 0, 0}, - { 0, 0, 1, 0}, - { 0, 0, 0, 1} - }, - [BOX_BOTTOM] = { - { 0, 0, 1, 0}, - { 0, 1, 0, 0}, - {-1, 0, 0, 0}, - { 0, 0, 0, 1} - }, - [BOX_TOP] = { - { 0, 0,-1, 0}, - { 0, 1, 0, 0}, - { 1, 0, 0, 0}, - { 0, 0, 0, 1} - }, -}; - -// Quake's world is z-up, x-forward, y-left, but Vulkan's world is -// z-forward, x-right, y-down. -static mat4f_t z_up = { - { 0, 0, 1, 0}, - {-1, 0, 0, 0}, - { 0,-1, 0, 0}, - { 0, 0, 0, 1}, -}; - static void setup_view (vulkan_ctx_t *ctx) { @@ -118,14 +68,14 @@ setup_view (vulkan_ctx_t *ctx) mat4f_t views[6]; for (int i = 0; i < 6; i++) { mat4f_t rotinv; - mat4ftranspose (rotinv, box_rotations[i]); + mat4ftranspose (rotinv, qfv_box_rotations[i]); mmulf (views[i], rotinv, r_refdef.camera_inverse); - mmulf (views[i], z_up, views[i]); + mmulf (views[i], qfv_z_up, views[i]); } Vulkan_SetViewMatrices (ctx, views, 6); } else { mat4f_t view; - mmulf (view, z_up, r_refdef.camera_inverse); + mmulf (view, qfv_z_up, r_refdef.camera_inverse); Vulkan_SetViewMatrices (ctx, &view, 1); } }