diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-02-21 01:31:24 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-22 23:48:59 +0000 |
commit | 5cf967e4f29a9f48554b19674c899835564ccbc0 (patch) | |
tree | 89c427a28de65e1dcd679a6a7c14f683b9c1b01d | |
parent | d92047c74da2f4c15926351d7f7f0798a77f5e38 (diff) | |
download | serenity-5cf967e4f29a9f48554b19674c899835564ccbc0.zip |
LibGL: Improve `glFrustum` precision and error handling
Do not convert to float too early. Additionally, handle some error
cases for the input parameters.
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index fe2b858b81..8ce1055fab 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -382,17 +382,18 @@ void SoftwareGLContext::gl_frustum(GLdouble left, GLdouble right, GLdouble botto APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_frustum, left, right, bottom, top, near_val, far_val); RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); + RETURN_WITH_ERROR_IF(near_val < 0 || far_val < 0, GL_INVALID_VALUE); + RETURN_WITH_ERROR_IF(left == right || bottom == top || near_val == far_val, GL_INVALID_VALUE); // Let's do some math! - // FIXME: Are we losing too much precision by doing this? - float a = static_cast<float>((right + left) / (right - left)); - float b = static_cast<float>((top + bottom) / (top - bottom)); - float c = static_cast<float>(-((far_val + near_val) / (far_val - near_val))); - float d = static_cast<float>(-((2 * (far_val * near_val)) / (far_val - near_val))); + auto a = static_cast<float>((right + left) / (right - left)); + auto b = static_cast<float>((top + bottom) / (top - bottom)); + auto c = static_cast<float>(-((far_val + near_val) / (far_val - near_val))); + auto d = static_cast<float>(-((2 * far_val * near_val) / (far_val - near_val))); FloatMatrix4x4 frustum { - ((2 * (float)near_val) / ((float)right - (float)left)), 0, a, 0, - 0, ((2 * (float)near_val) / ((float)top - (float)bottom)), b, 0, + static_cast<float>(2 * near_val / (right - left)), 0, a, 0, + 0, static_cast<float>(2 * near_val / (top - bottom)), b, 0, 0, 0, c, d, 0, 0, -1, 0 }; |