GLMat.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
  3. * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include "GL/gl.h"
  8. #include "GLContext.h"
  9. extern GL::GLContext* g_gl_context;
  10. void glMatrixMode(GLenum mode)
  11. {
  12. g_gl_context->gl_matrix_mode(mode);
  13. }
  14. /*
  15. * Push the current matrix (based on the current matrix mode)
  16. * to its' corresponding matrix stack in the current OpenGL
  17. * state context
  18. */
  19. void glPushMatrix()
  20. {
  21. g_gl_context->gl_push_matrix();
  22. }
  23. /*
  24. * Pop a matrix from the corresponding matrix stack into the
  25. * corresponding matrix in the state based on the current
  26. * matrix mode
  27. */
  28. void glPopMatrix()
  29. {
  30. g_gl_context->gl_pop_matrix();
  31. }
  32. void glLoadMatrixf(const GLfloat* matrix)
  33. {
  34. // Transpose the matrix here because glLoadMatrix expects elements
  35. // in column major order but out Matrix class stores elements in
  36. // row major order.
  37. FloatMatrix4x4 mat(
  38. matrix[0], matrix[4], matrix[8], matrix[12],
  39. matrix[1], matrix[5], matrix[9], matrix[13],
  40. matrix[2], matrix[6], matrix[10], matrix[14],
  41. matrix[3], matrix[7], matrix[11], matrix[15]);
  42. g_gl_context->gl_load_matrix(mat);
  43. }
  44. void glLoadIdentity()
  45. {
  46. g_gl_context->gl_load_identity();
  47. }
  48. /**
  49. * Create a viewing frustum (a.k.a a "Perspective Matrix") in the current matrix. This
  50. * is usually done to the projection matrix. The current matrix is then multiplied
  51. * by this viewing frustum matrix.
  52. *
  53. * https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glFrustum.xml
  54. *
  55. *
  56. * FIXME: We need to check for some values that could result in a division by zero
  57. */
  58. void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal)
  59. {
  60. g_gl_context->gl_frustum(left, right, bottom, top, nearVal, farVal);
  61. }
  62. void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal)
  63. {
  64. g_gl_context->gl_ortho(left, right, bottom, top, nearVal, farVal);
  65. }