1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:27:45 +00:00

LibGL: Implement glGetError and underlying function

This implements `glGetError` and correctly sets the state machine's
error macro (similar to LibC `errno`) when an invalid operation is
performed. This is reset on completion of a successful operation.
This commit is contained in:
Jesse Buhagiar 2021-04-23 23:48:28 +10:00 committed by Andreas Kling
parent 4807d32139
commit e537e2690a
5 changed files with 58 additions and 4 deletions

View file

@ -129,7 +129,13 @@ static void clip_triangle_against_frustum(Vector<FloatVector4>& in_vec)
void SoftwareGLContext::gl_begin(GLenum mode)
{
if (mode < GL_TRIANGLES || mode > GL_POLYGON) {
m_error = GL_INVALID_ENUM;
return;
}
m_current_draw_mode = mode;
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_clear(GLbitfield mask)
@ -141,19 +147,22 @@ void SoftwareGLContext::gl_clear(GLbitfield mask)
uint64_t color = r << 16 | g << 8 | b;
(void)(color);
m_error = GL_NO_ERROR;
} else {
// set gl error here!?
m_error = GL_INVALID_ENUM;
}
}
void SoftwareGLContext::gl_clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
m_clear_color = { red, green, blue, alpha };
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_color(GLdouble r, GLdouble g, GLdouble b, GLdouble a)
{
m_current_vertex_color = { (float)r, (float)g, (float)b, (float)a };
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_end()
@ -218,7 +227,8 @@ void SoftwareGLContext::gl_end()
triangle_list.append(triangle);
}
} else {
VERIFY_NOT_REACHED();
m_error = GL_INVALID_ENUM;
return;
}
// Now let's transform each triangle and send that to the GPU
@ -374,6 +384,8 @@ void SoftwareGLContext::gl_end()
triangle_list.clear();
processed_triangles.clear();
vertex_list.clear();
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val)
@ -398,6 +410,13 @@ void SoftwareGLContext::gl_frustum(GLdouble left, GLdouble right, GLdouble botto
dbgln_if(GL_DEBUG, "glFrustum(): frustum created with curr_matrix_mode == GL_MODELVIEW!!!");
m_projection_matrix = m_model_view_matrix * frustum;
}
m_error = GL_NO_ERROR;
}
GLenum SoftwareGLContext::gl_get_error()
{
return m_error;
}
GLubyte* SoftwareGLContext::gl_get_string(GLenum name)
@ -414,7 +433,7 @@ GLubyte* SoftwareGLContext::gl_get_string(GLenum name)
break;
}
// FIXME: Set glError to GL_INVALID_ENUM here
m_error = GL_INVALID_ENUM;
return nullptr;
}
@ -426,12 +445,19 @@ void SoftwareGLContext::gl_load_identity()
m_model_view_matrix = FloatMatrix4x4::identity();
else
VERIFY_NOT_REACHED();
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_matrix_mode(GLenum mode)
{
VERIFY(mode == GL_MODELVIEW || mode == GL_PROJECTION);
if (mode < GL_MODELVIEW || mode > GL_PROJECTION) {
m_error = GL_INVALID_ENUM;
return;
}
m_current_matrix_mode = mode;
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_push_matrix()
@ -449,6 +475,8 @@ void SoftwareGLContext::gl_push_matrix()
dbgln_if(GL_DEBUG, "glPushMatrix(): Attempt to push matrix with invalid matrix mode {})", m_current_matrix_mode);
return;
}
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_pop_matrix()
@ -467,6 +495,8 @@ void SoftwareGLContext::gl_pop_matrix()
dbgln_if(GL_DEBUG, "glPopMatrix(): Attempt to pop matrix with invalid matrix mode, {}", m_current_matrix_mode);
return;
}
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_rotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)
@ -479,6 +509,8 @@ void SoftwareGLContext::gl_rotate(GLdouble angle, GLdouble x, GLdouble y, GLdoub
m_model_view_matrix = m_model_view_matrix * rotation_mat;
else if (m_current_matrix_mode == GL_PROJECTION)
m_projection_matrix = m_projection_matrix * rotation_mat;
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_translate(GLdouble x, GLdouble y, GLdouble z)
@ -488,6 +520,8 @@ void SoftwareGLContext::gl_translate(GLdouble x, GLdouble y, GLdouble z)
} else if (m_current_matrix_mode == GL_PROJECTION) {
m_projection_matrix = m_projection_matrix * FloatMatrix4x4::translate({ (float)x, (float)y, (float)z });
}
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w)
@ -509,6 +543,7 @@ void SoftwareGLContext::gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w
vertex.v = 0.0f;
vertex_list.append(vertex);
m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_viewport(GLint x, GLint y, GLsizei width, GLsizei height)
@ -517,6 +552,7 @@ void SoftwareGLContext::gl_viewport(GLint x, GLint y, GLsizei width, GLsizei hei
(void)(y);
(void)(width);
(void)(height);
m_error = GL_NO_ERROR;
}
}