Skip to content

Commit

Permalink
LibGL: Impement glLoadMatrixf and underlying function
Browse files Browse the repository at this point in the history
  • Loading branch information
Quaker762 authored and awesomekling committed May 8, 2021
1 parent ea0df0b commit f07a7f7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Userland/Libraries/LibGL/GL/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ GLAPI void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble to
GLAPI GLenum glGetError();
GLAPI GLubyte* glGetString(GLenum name);
GLAPI void glLoadIdentity();
GLAPI void glLoadMatrixf(const GLfloat* matrix);
GLAPI void glMatrixMode(GLenum mode);
GLAPI void glPushMatrix();
GLAPI void glPopMatrix();
Expand Down
2 changes: 2 additions & 0 deletions Userland/Libraries/LibGL/GLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "GL/gl.h"
#include <AK/OwnPtr.h>
#include <LibGfx/Matrix4x4.h>

namespace GL {

Expand All @@ -25,6 +26,7 @@ class GLContext {
virtual GLenum gl_get_error() = 0;
virtual GLubyte* gl_get_string(GLenum name) = 0;
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_push_matrix() = 0;
virtual void gl_pop_matrix() = 0;
Expand Down
11 changes: 11 additions & 0 deletions Userland/Libraries/LibGL/GLMat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ void glPopMatrix()
g_gl_context->gl_pop_matrix();
}

void glLoadMatrixf(const GLfloat* matrix)
{
FloatMatrix4x4 mat(
matrix[0], matrix[1], matrix[2], matrix[3],
matrix[4], matrix[5], matrix[6], matrix[7],
matrix[8], matrix[9], matrix[10], matrix[11],
matrix[12], matrix[13], matrix[14], matrix[15]);

g_gl_context->gl_load_matrix(mat);
}

void glLoadIdentity()
{
g_gl_context->gl_load_identity();
Expand Down
17 changes: 17 additions & 0 deletions Userland/Libraries/LibGL/SoftwareGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,23 @@ void SoftwareGLContext::gl_load_identity()
m_error = GL_NO_ERROR;
}

void SoftwareGLContext::gl_load_matrix(const FloatMatrix4x4& matrix)
{
if (m_in_draw_state) {
m_error = GL_INVALID_OPERATION;
return;
}

if (m_current_matrix_mode == GL_PROJECTION)
m_projection_matrix = matrix;
else if (m_current_matrix_mode == GL_MODELVIEW)
m_model_view_matrix = matrix;
else
VERIFY_NOT_REACHED();

m_error = GL_NO_ERROR;
}

void SoftwareGLContext::gl_matrix_mode(GLenum mode)
{
if (m_in_draw_state) {
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibGL/SoftwareGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SoftwareGLContext : public GLContext {
virtual GLenum gl_get_error() override;
virtual GLubyte* gl_get_string(GLenum name) override;
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_push_matrix() override;
virtual void gl_pop_matrix() override;
Expand Down

0 comments on commit f07a7f7

Please sign in to comment.