From 9c9fa3349583e4ad84c17fd9308bc426ef36df7d Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 1 Dec 2021 16:20:22 +0100 Subject: [PATCH] LibGL: Implement `glClearStencil` --- Userland/Libraries/LibGL/GL/gl.h | 2 ++ Userland/Libraries/LibGL/GLContext.h | 1 + Userland/Libraries/LibGL/GLStencil.cpp | 5 +++++ Userland/Libraries/LibGL/SoftwareGLContext.cpp | 13 +++++++++++++ Userland/Libraries/LibGL/SoftwareGLContext.h | 8 ++++++-- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index 62a16caf05..b6fb20b2d4 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -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); diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 6ab2238c36..56e2337df9 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -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; diff --git a/Userland/Libraries/LibGL/GLStencil.cpp b/Userland/Libraries/LibGL/GLStencil.cpp index ba0e3028fb..681784fe3a 100644 --- a/Userland/Libraries/LibGL/GLStencil.cpp +++ b/Userland/Libraries/LibGL/GLStencil.cpp @@ -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); diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index ed83822ce8..db0370e6d7 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -84,6 +84,8 @@ void SoftwareGLContext::gl_clear(GLbitfield mask) if (mask & GL_DEPTH_BUFFER_BIT) m_rasterizer.clear_depth(static_cast(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); diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index 935ca0f76d..fc2c18058c 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -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 m_projection_matrix_stack; Vector 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),