From ea0df0b5da0247108bc7fe3c6a7c23f709802ef2 Mon Sep 17 00:00:00 2001 From: Jesse Buhagiar Date: Sat, 24 Apr 2021 22:11:48 +1000 Subject: LibGL: Implement glScalef --- Userland/Libraries/LibGL/GL/gl.h | 1 + Userland/Libraries/LibGL/GLContext.h | 1 + Userland/Libraries/LibGL/GLVert.cpp | 5 +++++ Userland/Libraries/LibGL/SoftwareGLContext.cpp | 16 ++++++++++++++++ Userland/Libraries/LibGL/SoftwareGLContext.h | 1 + 5 files changed, 24 insertions(+) (limited to 'Userland/Libraries/LibGL') diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index 9dfaefec82..9979f997cb 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -83,6 +83,7 @@ GLAPI void glMatrixMode(GLenum mode); GLAPI void glPushMatrix(); GLAPI void glPopMatrix(); GLAPI void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +GLAPI void glScalef(GLfloat x, GLfloat y, GLfloat z); GLAPI void glTranslatef(GLfloat x, GLfloat y, GLfloat z); GLAPI void glVertex3f(GLfloat x, GLfloat y, GLfloat z); GLAPI void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 8e00018b25..48bc94d521 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -29,6 +29,7 @@ public: 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; + virtual void gl_scale(GLdouble x, GLdouble y, GLdouble z) = 0; virtual void gl_translate(GLdouble x, GLdouble y, GLdouble z) = 0; virtual void gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w) = 0; virtual void gl_viewport(GLint x, GLint y, GLsizei width, GLsizei height) = 0; diff --git a/Userland/Libraries/LibGL/GLVert.cpp b/Userland/Libraries/LibGL/GLVert.cpp index 394c39861f..e972741327 100644 --- a/Userland/Libraries/LibGL/GLVert.cpp +++ b/Userland/Libraries/LibGL/GLVert.cpp @@ -30,6 +30,11 @@ void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) g_gl_context->gl_rotate(angle, x, y, z); } +void glScalef(GLfloat x, GLfloat y, GLfloat z) +{ + g_gl_context->gl_scale(x, y, z); +} + void glTranslatef(GLfloat x, GLfloat y, GLfloat z) { g_gl_context->gl_translate(x, y, z); diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index c6b54c40ef..0b85ad1778 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -594,6 +594,22 @@ void SoftwareGLContext::gl_rotate(GLdouble angle, GLdouble x, GLdouble y, GLdoub m_error = GL_NO_ERROR; } +void SoftwareGLContext::gl_scale(GLdouble x, GLdouble y, GLdouble z) +{ + if (m_in_draw_state) { + m_error = GL_INVALID_OPERATION; + return; + } + + if (m_current_matrix_mode == GL_MODELVIEW) { + m_model_view_matrix = m_model_view_matrix * FloatMatrix4x4::scale({ static_cast(x), static_cast(y), static_cast(z) }); + } else if (m_current_matrix_mode == GL_PROJECTION) { + m_projection_matrix = m_projection_matrix * FloatMatrix4x4::scale({ static_cast(x), static_cast(y), static_cast(z) }); + } + + m_error = GL_NO_ERROR; +} + void SoftwareGLContext::gl_translate(GLdouble x, GLdouble y, GLdouble z) { if (m_in_draw_state) { diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index 58bb859867..33fa7b3feb 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -29,6 +29,7 @@ public: 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; + virtual void gl_scale(GLdouble x, GLdouble y, GLdouble z) override; virtual void gl_translate(GLdouble x, GLdouble y, GLdouble z) override; virtual void gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w) override; virtual void gl_viewport(GLint x, GLint y, GLsizei width, GLsizei height) override; -- cgit v1.2.3