diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-03-10 10:22:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-10 20:20:05 +0100 |
commit | 5d0a64bfdea5bafbaf10c5a60b641cf47e3d7883 (patch) | |
tree | 8d6ed1f5862d8ea73e4a703919580d06c7f6f41b | |
parent | 2362cc2943b5b78931ac062f54d66100cdbe07cd (diff) | |
download | serenity-5d0a64bfdea5bafbaf10c5a60b641cf47e3d7883.zip |
LibGL: Only normalize in `glRotate*` if possible
Vectors of length 0 cannot be normalized, so prevent dividing by zero
in the `glRotate*` API. This fixes the skybox rendering of Quake2.
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.h | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/Userland/Libraries/LibGL/GLContext.cpp b/Userland/Libraries/LibGL/GLContext.cpp index 82c4ff8483..324351c62e 100644 --- a/Userland/Libraries/LibGL/GLContext.cpp +++ b/Userland/Libraries/LibGL/GLContext.cpp @@ -594,15 +594,16 @@ void GLContext::gl_mult_matrix(FloatMatrix4x4 const& matrix) VERIFY_NOT_REACHED(); } -void GLContext::gl_rotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) +void GLContext::gl_rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_rotate, angle, x, y, z); RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); - FloatVector3 axis = { (float)x, (float)y, (float)z }; - axis.normalize(); - auto rotation_mat = Gfx::rotation_matrix(axis, static_cast<float>(angle * M_PI * 2 / 360)); + FloatVector3 axis = { x, y, z }; + if (axis.length() > 0.f) + axis.normalize(); + auto rotation_mat = Gfx::rotation_matrix(axis, angle * static_cast<float>(M_PI * 2 / 360)); if (m_current_matrix_mode == GL_MODELVIEW) m_model_view_matrix = m_model_view_matrix * rotation_mat; diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 7a61e2fd8c..ec6e80378b 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -70,7 +70,7 @@ public: void gl_push_matrix(); void gl_pop_matrix(); void gl_mult_matrix(FloatMatrix4x4 const& matrix); - void gl_rotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble z); + void gl_rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); void gl_scale(GLdouble x, GLdouble y, GLdouble z); void gl_translate(GLdouble x, GLdouble y, GLdouble z); void gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w); |