1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

LibGL: Implement glClearStencil

This commit is contained in:
Jelle Raaijmakers 2021-12-01 16:20:22 +01:00 committed by Andreas Kling
parent 07bf37be75
commit 9c9fa33495
5 changed files with 27 additions and 2 deletions

View file

@ -51,6 +51,7 @@ extern "C" {
// Buffer bits
#define GL_DEPTH_BUFFER_BIT 0x00100
#define GL_STENCIL_BUFFER_BIT 0x00400
#define GL_COLOR_BUFFER_BIT 0x04000
// Enable capabilities
@ -349,6 +350,7 @@ GLAPI void glBegin(GLenum mode);
GLAPI void glClear(GLbitfield mask);
GLAPI void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
GLAPI void glClearDepth(GLdouble depth);
GLAPI void glClearStencil(GLint s);
GLAPI void glColor3f(GLfloat r, GLfloat g, GLfloat b);
GLAPI void glColor3fv(const GLfloat* v);
GLAPI void glColor3ub(GLubyte r, GLubyte g, GLubyte b);

View file

@ -22,6 +22,7 @@ public:
virtual void gl_clear(GLbitfield mask) = 0;
virtual void gl_clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) = 0;
virtual void gl_clear_depth(GLdouble depth) = 0;
virtual void gl_clear_stencil(GLint s) = 0;
virtual void gl_color(GLdouble r, GLdouble g, GLdouble b, GLdouble a) = 0;
virtual void gl_delete_textures(GLsizei n, const GLuint* textures) = 0;
virtual void gl_end() = 0;

View file

@ -9,6 +9,11 @@
extern GL::GLContext* g_gl_context;
void glClearStencil(GLint s)
{
g_gl_context->gl_clear_stencil(s);
}
void glStencilFunc(GLenum func, GLint ref, GLuint mask)
{
g_gl_context->gl_stencil_func_separate(GL_FRONT_AND_BACK, func, ref, mask);

View file

@ -84,6 +84,8 @@ void SoftwareGLContext::gl_clear(GLbitfield mask)
if (mask & GL_DEPTH_BUFFER_BIT)
m_rasterizer.clear_depth(static_cast<float>(m_clear_depth));
// FIXME: implement GL_STENCIL_BUFFER_BIT
}
void SoftwareGLContext::gl_clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
@ -104,6 +106,17 @@ void SoftwareGLContext::gl_clear_depth(GLdouble depth)
m_clear_depth = depth;
}
void SoftwareGLContext::gl_clear_stencil(GLint s)
{
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_clear_stencil, s);
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
// FIXME: "s is masked with 2^m - 1 , where m is the number of bits in the stencil buffer"
m_clear_stencil = s;
}
void SoftwareGLContext::gl_color(GLdouble r, GLdouble g, GLdouble b, GLdouble a)
{
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_color, r, g, b, a);

View file

@ -33,6 +33,7 @@ public:
virtual void gl_clear(GLbitfield mask) override;
virtual void gl_clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) override;
virtual void gl_clear_depth(GLdouble depth) override;
virtual void gl_clear_stencil(GLint s) override;
virtual void gl_color(GLdouble r, GLdouble g, GLdouble b, GLdouble a) override;
virtual void gl_delete_textures(GLsizei n, const GLuint* textures) override;
virtual void gl_end() override;
@ -142,8 +143,10 @@ private:
Vector<FloatMatrix4x4> m_projection_matrix_stack;
Vector<FloatMatrix4x4> m_model_view_matrix_stack;
FloatVector4 m_clear_color = { 0.0f, 0.0f, 0.0f, 0.0f };
double m_clear_depth = { 1.0 };
FloatVector4 m_clear_color { 0.0f, 0.0f, 0.0f, 0.0f };
double m_clear_depth { 1.0 };
GLint m_clear_stencil { 0 };
FloatVector4 m_current_vertex_color = { 1.0f, 1.0f, 1.0f, 1.0f };
FloatVector4 m_current_vertex_tex_coord = { 0.0f, 0.0f, 0.0f, 0.0f };
FloatVector3 m_current_vertex_normal = { 0.0f, 0.0f, 1.0f };
@ -236,6 +239,7 @@ private:
decltype(&SoftwareGLContext::gl_clear),
decltype(&SoftwareGLContext::gl_clear_color),
decltype(&SoftwareGLContext::gl_clear_depth),
decltype(&SoftwareGLContext::gl_clear_stencil),
decltype(&SoftwareGLContext::gl_color),
decltype(&SoftwareGLContext::gl_end),
decltype(&SoftwareGLContext::gl_frustum),