From f8f3d6e657184db3530ac5edbf4ddff5e5f18133 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Tue, 17 Feb 2026 08:17:26 +0800 Subject: [PATCH] [Feat] (GL_State/RenderState): implement ClearStencil --- MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp | 4 ++-- .../MG_Impl/GLImpl/RenderState/GL_RenderState.cpp | 2 +- MobileGL/MG_State/GLState/Core.cpp | 10 +++++++++- MobileGL/MG_State/GLState/Core.h | 4 +++- MobileGL/MG_State/GLState/RenderState/RenderState.cpp | 11 +++++++++++ MobileGL/MG_State/GLState/RenderState/RenderState.h | 5 ++++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp b/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp index 14957df5..10cdf8dd 100644 --- a/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp +++ b/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp @@ -721,7 +721,7 @@ namespace MobileGL { *params = 0; // TODO break; case GL_STENCIL_CLEAR_VALUE: - *params = 0; // TODO + *params = MG_State::pGLContext->GetClearStencil(); break; case GL_STENCIL_FAIL: *params = 0; // TODO @@ -922,4 +922,4 @@ namespace MobileGL { return MG_Util::ConvertErrorCodeToGLEnum(errorCode); } } // namespace MG_Impl::GLImpl -} // namespace MobileGL \ No newline at end of file +} // namespace MobileGL diff --git a/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.cpp b/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.cpp index 3f4f2b55..bc3b9150 100644 --- a/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.cpp +++ b/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.cpp @@ -261,7 +261,7 @@ namespace MobileGL { } void ClearStencil_State(GLint s) { - // TODO: implement + MG_State::pGLContext->SetClearStencil(static_cast(s)); } void ClearDepth_State(GLclampd depth) { diff --git a/MobileGL/MG_State/GLState/Core.cpp b/MobileGL/MG_State/GLState/Core.cpp index 93008e65..dc91933a 100644 --- a/MobileGL/MG_State/GLState/Core.cpp +++ b/MobileGL/MG_State/GLState/Core.cpp @@ -312,6 +312,14 @@ namespace MobileGL { return m_renderState.GetClearDepth(); } + void GLContext::SetClearStencil(Int stencil) { + m_renderState.SetClearStencil(stencil); + } + + Int GLContext::GetClearStencil() const { + return m_renderState.GetClearStencil(); + } + void GLContext::SetPixelStoreParam(PixelStoreParam param, Int value) { m_renderState.SetPixelStoreParam(param, value); } @@ -432,4 +440,4 @@ namespace MobileGL { GLState::GLContext* pGLContext; } // namespace MG_State -} // namespace MobileGL \ No newline at end of file +} // namespace MobileGL diff --git a/MobileGL/MG_State/GLState/Core.h b/MobileGL/MG_State/GLState/Core.h index 3ac2eeac..3bc61ea6 100644 --- a/MobileGL/MG_State/GLState/Core.h +++ b/MobileGL/MG_State/GLState/Core.h @@ -111,6 +111,8 @@ namespace MobileGL { const FloatVec4& GetClearColor() const; void SetClearDepth(Float depth); Float GetClearDepth() const; + void SetClearStencil(Int stencil); + Int GetClearStencil() const; void SetPixelStoreParam(PixelStoreParam param, Int value); Int GetPixelStoreParam(PixelStoreParam param) const; PixelStoreParameters GetPixelStoreParameters(Bool isUnpack) const; @@ -161,4 +163,4 @@ namespace MobileGL { extern GLState::GLContext* pGLContext; } // namespace MG_State -} // namespace MobileGL \ No newline at end of file +} // namespace MobileGL diff --git a/MobileGL/MG_State/GLState/RenderState/RenderState.cpp b/MobileGL/MG_State/GLState/RenderState/RenderState.cpp index b23f5c34..434af714 100644 --- a/MobileGL/MG_State/GLState/RenderState/RenderState.cpp +++ b/MobileGL/MG_State/GLState/RenderState/RenderState.cpp @@ -222,6 +222,17 @@ namespace MobileGL { return m_parameters.ClearDepth; } + void RenderState::SetClearStencil(Int stencil) { + if (m_parameters.ClearStencil == stencil) return; + + m_parameters.ClearStencil = stencil; + ++m_version; + } + + Int RenderState::GetClearStencil() const { + return m_parameters.ClearStencil; + } + // -------------------- Pixel Store -------------------- void RenderState::SetPixelStoreParam(PixelStoreParam param, Int value) { #define SET_PIXEL_STORE_PARAM(paramNameHead, paramNameTail, val) \ diff --git a/MobileGL/MG_State/GLState/RenderState/RenderState.h b/MobileGL/MG_State/GLState/RenderState/RenderState.h index 0b1a3214..6f7b4096 100644 --- a/MobileGL/MG_State/GLState/RenderState/RenderState.h +++ b/MobileGL/MG_State/GLState/RenderState/RenderState.h @@ -154,6 +154,7 @@ namespace MobileGL { // Clear State FloatVec4 ClearColor = FloatVec4(0.0f, 0.0f, 0.0f, 1.0f); Float ClearDepth = 1.0f; + Int ClearStencil = 0; // Cull Face Bool CullFaceEnabled = false; @@ -207,6 +208,8 @@ namespace MobileGL { const FloatVec4& GetClearColor() const; void SetClearDepth(Float depth); Float GetClearDepth() const; + void SetClearStencil(Int stencil); + Int GetClearStencil() const; // Pixel Store void SetPixelStoreParam(PixelStoreParam param, Int value); @@ -231,4 +234,4 @@ namespace MobileGL { }; } // namespace GLState } // namespace MG_State -} // namespace MobileGL \ No newline at end of file +} // namespace MobileGL