Skip to content

Commit

Permalink
LibGL: Implement very basic version of glGetFloatv
Browse files Browse the repository at this point in the history
This is a very basic implementation of glGetfloatv. It will only give a
result when used with GL_MODELVIEW_MATRIX. In the future
 we can update and extend it's functionality.
  • Loading branch information
ebiederstadt authored and awesomekling committed Jun 9, 2021
1 parent 99ffcc2 commit 61bd189
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Userland/Libraries/LibGL/GL/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ extern "C" {
#define GL_NEAREST_MIPMAP_LINEAR 0x2602
#define GL_REPEAT 0x2603

// OpenGL State & GLGet
#define GL_MODELVIEW_MATRIX 0x0BA6

//
// OpenGL typedefs
//
Expand Down Expand Up @@ -294,6 +297,7 @@ GLAPI void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsize
GLAPI void glTexCoord2f(GLfloat s, GLfloat t);
GLAPI void glBindTexture(GLenum target, GLuint texture);
GLAPI void glActiveTexture(GLenum texture);
GLAPI void glGetFloatv(GLenum pname, GLfloat* params);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibGL/GLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class GLContext {
virtual void gl_tex_coord(GLfloat s, GLfloat t, GLfloat r, GLfloat q) = 0;
virtual void gl_bind_texture(GLenum target, GLuint texture) = 0;
virtual void gl_active_texture(GLenum texture) = 0;
virtual void gl_get_floatv(GLenum pname, GLfloat* params) = 0;

virtual void present() = 0;
};
Expand Down
5 changes: 5 additions & 0 deletions Userland/Libraries/LibGL/GLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@ void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format
{
g_gl_context->gl_read_pixels(x, y, width, height, format, type, pixels);
}

void glGetFloatv(GLenum pname, GLfloat* params)
{
g_gl_context->gl_get_floatv(pname, params);
}
32 changes: 32 additions & 0 deletions Userland/Libraries/LibGL/SoftwareGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,38 @@ void SoftwareGLContext::gl_active_texture(GLenum texture)
m_active_texture_unit = &m_texture_units.at(texture - GL_TEXTURE0);
}

void SoftwareGLContext::gl_get_floatv(GLenum pname, GLfloat* params)
{
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);

auto flatten_and_assign_matrix = [&params](const FloatMatrix4x4& matrix) {
auto elements = matrix.elements();

for (size_t i = 0; i < 4; ++i) {
for (size_t j = 0; j < 4; ++j) {
params[i * 4 + j] = elements[i][j];
}
}
};

switch (pname) {
case GL_MODELVIEW_MATRIX:
if (m_current_matrix_mode == GL_MODELVIEW)
flatten_and_assign_matrix(m_model_view_matrix);
else {
if (m_model_view_matrix_stack.is_empty())
flatten_and_assign_matrix(FloatMatrix4x4::identity());
else
flatten_and_assign_matrix(m_model_view_matrix_stack.last());
}
break;
default:
// FIXME: Because glQuake only requires GL_MODELVIEW_MATRIX, that is the only parameter
// that we currently support. More parameters should be supported.
TODO();
}
}

void SoftwareGLContext::present()
{
m_rasterizer.blit_to(*m_frontbuffer);
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 @@ -71,6 +71,7 @@ class SoftwareGLContext : public GLContext {
virtual void gl_tex_coord(GLfloat s, GLfloat t, GLfloat r, GLfloat q) override;
virtual void gl_bind_texture(GLenum target, GLuint texture) override;
virtual void gl_active_texture(GLenum texture) override;
virtual void gl_get_floatv(GLenum pname, GLfloat* params) override;

virtual void present() override;

Expand Down

0 comments on commit 61bd189

Please sign in to comment.