summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-04-24 17:40:15 +0430
committerAndreas Kling <kling@serenityos.org>2021-05-08 10:13:22 +0200
commitf601f12801b878568cf1c8e123f76fca0b43c9c3 (patch)
tree9493fd374f9cf2f05002ca6fc55451e8bd0ed7f0
parentf07a7f7b946852ab0df6201676501578c02ef133 (diff)
downloadserenity-f601f12801b878568cf1c8e123f76fca0b43c9c3.zip
LibGL: Implement glOrtho and underlying functions
-rw-r--r--Userland/Libraries/LibGL/GL/gl.h1
-rw-r--r--Userland/Libraries/LibGL/GLContext.h1
-rw-r--r--Userland/Libraries/LibGL/GLMat.cpp5
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp35
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.h1
5 files changed, 43 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h
index 76f67d7005..7de99d5aeb 100644
--- a/Userland/Libraries/LibGL/GL/gl.h
+++ b/Userland/Libraries/LibGL/GL/gl.h
@@ -81,6 +81,7 @@ GLAPI GLubyte* glGetString(GLenum name);
GLAPI void glLoadIdentity();
GLAPI void glLoadMatrixf(const GLfloat* matrix);
GLAPI void glMatrixMode(GLenum mode);
+GLAPI void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal);
GLAPI void glPushMatrix();
GLAPI void glPopMatrix();
GLAPI void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h
index 4d6f02a4a2..dc7f75288c 100644
--- a/Userland/Libraries/LibGL/GLContext.h
+++ b/Userland/Libraries/LibGL/GLContext.h
@@ -28,6 +28,7 @@ public:
virtual void gl_load_identity() = 0;
virtual void gl_load_matrix(const FloatMatrix4x4& matrix) = 0;
virtual void gl_matrix_mode(GLenum mode) = 0;
+ virtual void gl_ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val) = 0;
virtual void gl_push_matrix() = 0;
virtual void gl_pop_matrix() = 0;
virtual void gl_rotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) = 0;
diff --git a/Userland/Libraries/LibGL/GLMat.cpp b/Userland/Libraries/LibGL/GLMat.cpp
index 7b0bde969f..a80a54990b 100644
--- a/Userland/Libraries/LibGL/GLMat.cpp
+++ b/Userland/Libraries/LibGL/GLMat.cpp
@@ -65,3 +65,8 @@ void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLd
{
g_gl_context->gl_frustum(left, right, bottom, top, nearVal, farVal);
}
+
+void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal)
+{
+ g_gl_context->gl_ortho(left, right, bottom, top, nearVal, farVal);
+}
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index 3dc67eb8cd..514ce2f126 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -445,6 +445,41 @@ void SoftwareGLContext::gl_frustum(GLdouble left, GLdouble right, GLdouble botto
m_error = GL_NO_ERROR;
}
+void SoftwareGLContext::gl_ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val)
+{
+ if (m_in_draw_state) {
+ m_error = GL_INVALID_OPERATION;
+ return;
+ }
+
+ if (left == right || bottom == top || near_val == far_val) {
+ m_error = GL_INVALID_VALUE;
+ return;
+ }
+
+ auto rl = right - left;
+ auto tb = top - bottom;
+ auto fn = far_val - near_val;
+ auto tx = -(right + left) / rl;
+ auto ty = -(top + bottom) / tb;
+ auto tz = -(far_val + near_val) / fn;
+
+ FloatMatrix4x4 projection {
+ static_cast<float>(2 / rl), 0, 0, static_cast<float>(tx),
+ 0, static_cast<float>(2 / tb), 0, static_cast<float>(ty),
+ 0, 0, static_cast<float>(-2 / fn), static_cast<float>(tz),
+ 0, 0, 0, 1
+ };
+
+ if (m_current_matrix_mode == GL_PROJECTION) {
+ m_projection_matrix = m_projection_matrix * projection;
+ } else if (m_current_matrix_mode == GL_MODELVIEW) {
+ m_projection_matrix = m_model_view_matrix * projection;
+ }
+
+ m_error = GL_NO_ERROR;
+}
+
GLenum SoftwareGLContext::gl_get_error()
{
if (m_in_draw_state) {
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h
index 54a0cea7a8..d1b9bca826 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.h
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.h
@@ -27,6 +27,7 @@ public:
virtual void gl_load_identity() override;
virtual void gl_load_matrix(const FloatMatrix4x4& matrix) override;
virtual void gl_matrix_mode(GLenum mode) override;
+ virtual void gl_ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val) override;
virtual void gl_push_matrix() override;
virtual void gl_pop_matrix() override;
virtual void gl_rotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) override;