diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-01-12 00:54:14 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-12 01:08:38 +0100 |
commit | a41d5ffa1e8bdb8c774df2418fae10740fec75dc (patch) | |
tree | 700ce9df7f2892b673bce48d15d657b896e87dbe | |
parent | b2e0bf24efd1e9f0f2ac507561437d28bd8d535d (diff) | |
download | serenity-a41d5ffa1e8bdb8c774df2418fae10740fec75dc.zip |
LibGfx+LibGL: Allow singular matrices to be inverted
This is basically the old behavior before the GLtron port was
introduced, but `.inverse()` no longer crashes if the matrix is
singular.
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Matrix.h | 8 |
2 files changed, 5 insertions, 12 deletions
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 27d2f32215..7f8f3452a8 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -317,8 +317,7 @@ void SoftwareGLContext::gl_end() mv_elements[0][0], mv_elements[1][0], mv_elements[2][0], mv_elements[0][1], mv_elements[1][1], mv_elements[2][1], mv_elements[0][2], mv_elements[1][2], mv_elements[2][2]); - auto normal_transform_or_error = model_view_transposed.inverse(); - auto const& normal_transform = normal_transform_or_error.is_error() ? model_view_transposed : normal_transform_or_error.release_value(); + auto const& normal_transform = model_view_transposed.inverse(); m_rasterizer.draw_primitives(primitive_type, m_model_view_matrix, normal_transform, m_projection_matrix, m_texture_matrix, m_vertex_list, enabled_texture_units); @@ -2810,9 +2809,7 @@ void SoftwareGLContext::gl_tex_gen_floatv(GLenum coord, GLenum pname, GLfloat co texture_coordinate_generation(capability).object_plane_coefficients = { params[0], params[1], params[2], params[3] }; break; case GL_EYE_PLANE: { - auto inverse_matrix_or_error = m_model_view_matrix.inverse(); - auto const& inverse_model_view_matrix = inverse_matrix_or_error.is_error() ? m_model_view_matrix : inverse_matrix_or_error.release_value(); - + auto const& inverse_model_view = m_model_view_matrix.inverse(); auto input_coefficients = FloatVector4 { params[0], params[1], params[2], params[3] }; // Note: we are allowed to store transformed coefficients here, according to the documentation on @@ -2821,7 +2818,7 @@ void SoftwareGLContext::gl_tex_gen_floatv(GLenum coord, GLenum pname, GLfloat co // "The returned values are those maintained in eye coordinates. They are not equal to the values // specified using glTexGen, unless the modelview matrix was identity when glTexGen was called." - texture_coordinate_generation(capability).eye_plane_coefficients = inverse_model_view_matrix * input_coefficients; + texture_coordinate_generation(capability).eye_plane_coefficients = inverse_model_view * input_coefficients; break; } default: diff --git a/Userland/Libraries/LibGfx/Matrix.h b/Userland/Libraries/LibGfx/Matrix.h index 33f9536ce2..2e251de293 100644 --- a/Userland/Libraries/LibGfx/Matrix.h +++ b/Userland/Libraries/LibGfx/Matrix.h @@ -6,7 +6,6 @@ #pragma once -#include <AK/Error.h> #include <AK/Types.h> #include <initializer_list> @@ -159,12 +158,9 @@ public: return result; } - [[nodiscard]] constexpr ErrorOr<Matrix> inverse() const + [[nodiscard]] constexpr Matrix inverse() const { - auto det = determinant(); - if (det == 0) - return Error::from_string_literal("inverse of matrix does not exist"sv); - return adjugate() / det; + return adjugate() / determinant(); } [[nodiscard]] constexpr Matrix transpose() const |