@@ -78,7 +78,7 @@ String OpenXRUtil::make_xr_version_string(XrVersion p_version) {
7878 return version;
7979}
8080
81- // Copied from OpenXR xr_linear.h private header, so we can still link against
81+ // Based on the OpenXR xr_linear.h private header, so we can still link against
8282// system-provided packages without relying on our `thirdparty` code.
8383
8484// Copyright (c) 2017 The Khronos Group Inc.
@@ -87,25 +87,22 @@ String OpenXRUtil::make_xr_version_string(XrVersion p_version) {
8787// SPDX-License-Identifier: Apache-2.0
8888
8989// Creates a projection matrix based on the specified dimensions.
90- // The projection matrix transforms -Z=forward, +Y=up, +X=right to the appropriate clip space for the graphics API .
90+ // The projection matrix transforms -Z=forward, +Y=up, +X=right to the appropriate clip space for Godot (OpenGL convention) .
9191// The far plane is placed at infinity if farZ <= nearZ.
9292// An infinite projection matrix is preferred for rasterization because, except for
9393// things *right* up against the near plane, it always provides better precision:
9494// "Tightening the Precision of Perspective Rendering"
9595// Paul Upchurch, Mathieu Desbrun
9696// Journal of Graphics Tools, Volume 16, Issue 1, 2012
97- void OpenXRUtil::XrMatrix4x4f_CreateProjection (XrMatrix4x4f *result, GraphicsAPI graphicsApi, const float tanAngleLeft,
98- const float tanAngleRight, const float tanAngleUp, float const tanAngleDown,
99- const float nearZ, const float farZ) {
97+ void OpenXRUtil::XrMatrix4x4f_CreateProjection (XrMatrix4x4f *result, const float tanAngleLeft, const float tanAngleRight,
98+ const float tanAngleUp, float const tanAngleDown, const float nearZ, const float farZ) {
10099 const float tanAngleWidth = tanAngleRight - tanAngleLeft;
101100
102- // Set to tanAngleDown - tanAngleUp for a clip space with positive Y down (Vulkan).
103- // Set to tanAngleUp - tanAngleDown for a clip space with positive Y up (OpenGL / D3D / Metal).
104- const float tanAngleHeight = graphicsApi == GRAPHICS_VULKAN ? (tanAngleDown - tanAngleUp) : (tanAngleUp - tanAngleDown);
101+ // Set to tanAngleUp - tanAngleDown for a clip space with positive Y up.
102+ const float tanAngleHeight = (tanAngleUp - tanAngleDown);
105103
106- // Set to nearZ for a [-1,1] Z clip space (OpenGL / OpenGL ES).
107- // Set to zero for a [0,1] Z clip space (Vulkan / D3D / Metal).
108- const float offsetZ = (graphicsApi == GRAPHICS_OPENGL || graphicsApi == GRAPHICS_OPENGL_ES) ? nearZ : 0 ;
104+ // Set to nearZ for a [-1,1] Z clip space.
105+ const float offsetZ = nearZ;
109106
110107 if (farZ <= nearZ) {
111108 // place the far plane at infinity
@@ -153,13 +150,12 @@ void OpenXRUtil::XrMatrix4x4f_CreateProjection(XrMatrix4x4f *result, GraphicsAPI
153150}
154151
155152// Creates a projection matrix based on the specified FOV.
156- void OpenXRUtil::XrMatrix4x4f_CreateProjectionFov (XrMatrix4x4f *result, GraphicsAPI graphicsApi, const XrFovf fov,
157- const float nearZ, const float farZ) {
153+ void OpenXRUtil::XrMatrix4x4f_CreateProjectionFov (XrMatrix4x4f *result, const XrFovf fov, const float nearZ, const float farZ) {
158154 const float tanLeft = std::tan (fov.angleLeft );
159155 const float tanRight = std::tan (fov.angleRight );
160156
161157 const float tanDown = std::tan (fov.angleDown );
162158 const float tanUp = std::tan (fov.angleUp );
163159
164- XrMatrix4x4f_CreateProjection (result, graphicsApi, tanLeft, tanRight, tanUp, tanDown, nearZ, farZ);
160+ XrMatrix4x4f_CreateProjection (result, tanLeft, tanRight, tanUp, tanDown, nearZ, farZ);
165161}
0 commit comments