From 75a0fc2c0c5bcf4569f1ec1b3c9661231d5d4fb8 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Wed, 10 Jun 2026 23:33:59 +0800 Subject: [PATCH] [Fix] (MG_Impl/GLImpl): fix DSA state queries and compatibility tests Fix texture parameter getters and element array buffer binding queries. Update framebuffer, texture, program, and VAO tests to match current OpenGL semantics, while preserving VAO 0 compatibility behavior. --- MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp | 10 ++++++ .../MG_Impl/GLImpl/Texture/GL_Texture.cpp | 33 ++++++++++++++----- .../MG_Test/Framebuffer/FramebufferTest.cpp | 15 ++++++++- MobileGL/MG_Test/Program/ProgramTest.cpp | 2 +- MobileGL/MG_Test/Texture/TextureTest.cpp | 8 +++-- .../MG_Test/VertexArray/VertexArrayTest.cpp | 10 +++--- 6 files changed, 61 insertions(+), 17 deletions(-) diff --git a/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp b/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp index 2f0ab69d..f958659c 100644 --- a/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp +++ b/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp @@ -722,6 +722,16 @@ namespace MobileGL::MG_Impl::GLImpl { return; } + if (pname == GL_ELEMENT_ARRAY_BUFFER_BINDING) { + if (!MG_State::pGLContext->GetBoundVertexArray()) { + *params = 0; + return; + } + const auto& bufferObject = MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::Index).GetBoundObject(); + *params = bufferObject ? static_cast(bufferObject->GetExternalIndex()) : 0; + return; + } + const auto& activeBackendObject = MG_Backend::pActiveBackendObject; if (!activeBackendObject) { MGLOG_E("activeBackendObject is not initialized!"); diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index 613ea72a..f3336d59 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -1356,7 +1356,8 @@ namespace MobileGL::MG_Impl::GLImpl { GLint signedParams[4] = {0, 0, 0, 0}; GetTexParameteriv_State(target, pname, signedParams); - for (int i = 0; i < 4; ++i) { + const int componentCount = pname == GL_TEXTURE_BORDER_COLOR || pname == GL_TEXTURE_SWIZZLE_RGBA ? 4 : 1; + for (int i = 0; i < componentCount; ++i) { params[i] = static_cast(signedParams[i]); } } @@ -1423,6 +1424,15 @@ namespace MobileGL::MG_Impl::GLImpl { params[3] = static_cast(borderColor.w()); } break; + case GL_TEXTURE_SWIZZLE_RGBA: + if (params) { + const auto& swizzleParams = textureObject->GetAllSwizzleParams(); + params[0] = static_cast(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[0])); + params[1] = static_cast(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[1])); + params[2] = static_cast(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[2])); + params[3] = static_cast(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[3])); + } + break; case GL_TEXTURE_SWIZZLE_R: if (params) { *params = static_cast( @@ -1531,6 +1541,15 @@ namespace MobileGL::MG_Impl::GLImpl { *params = static_cast(textureObject->GetLevelRange().y()); } break; + case GL_TEXTURE_BORDER_COLOR: + if (params) { + const auto& borderColor = textureObject->GetBorderColor(); + params[0] = borderColor.x(); + params[1] = borderColor.y(); + params[2] = borderColor.z(); + params[3] = borderColor.w(); + } + break; case GL_TEXTURE_SWIZZLE_R: if (params) { *params = static_cast( @@ -1556,14 +1575,12 @@ namespace MobileGL::MG_Impl::GLImpl { } break; case GL_TEXTURE_SWIZZLE_RGBA: - break; // TODO - case GL_TEXTURE_BORDER_COLOR: if (params) { - const auto& borderColor = textureObject->GetBorderColor(); - params[0] = borderColor.x(); - params[1] = borderColor.y(); - params[2] = borderColor.z(); - params[3] = borderColor.w(); + const auto& swizzleParams = textureObject->GetAllSwizzleParams(); + params[0] = static_cast(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[0])); + params[1] = static_cast(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[1])); + params[2] = static_cast(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[2])); + params[3] = static_cast(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[3])); } break; case GL_TEXTURE_WRAP_S: diff --git a/MobileGL/MG_Test/Framebuffer/FramebufferTest.cpp b/MobileGL/MG_Test/Framebuffer/FramebufferTest.cpp index 11221c5f..70ae7d11 100644 --- a/MobileGL/MG_Test/Framebuffer/FramebufferTest.cpp +++ b/MobileGL/MG_Test/Framebuffer/FramebufferTest.cpp @@ -75,6 +75,16 @@ class FramebufferTest : public ::testing::Test { protected: void SetUp() override { MobileGL::Initialize(); + const auto defaultFramebuffer = MG_State::pGLContext->GetFramebufferObject(0); + ASSERT_NE(defaultFramebuffer, nullptr); + MG_State::pGLContext->GetFramebufferBindingSlot(FramebufferTarget::Draw).Bind(defaultFramebuffer); + MG_State::pGLContext->GetFramebufferBindingSlot(FramebufferTarget::Read).Bind(defaultFramebuffer); + defaultFramebuffer->SetDrawBuffer(0, FramebufferAttachmentType::BackLeft); + for (Uint i = 1; i < MG_State::GLState::FramebufferObject::MAX_DRAW_BUFFERS; ++i) { + defaultFramebuffer->SetDrawBuffer(i, FramebufferAttachmentType::None); + } + defaultFramebuffer->SetReadBuffer(FramebufferAttachmentType::BackLeft); + g_lastBlitReadFramebuffer = nullptr; g_lastBlitDrawFramebuffer = nullptr; g_blitNamedFramebufferCallCount = 0; @@ -258,6 +268,8 @@ TEST_F(FramebufferTest, NamedFramebufferDrawBuffersDoNotModifyDefaultFramebuffer MG_State::pGLContext->GetFramebufferBindingSlot(FramebufferTarget::Draw).GetBoundObject(); const auto defaultRead = MG_State::pGLContext->GetFramebufferBindingSlot(FramebufferTarget::Read).GetBoundObject(); + const auto defaultDrawBuffer = defaultDraw->GetDrawBuffers()[0]; + const auto defaultReadBuffer = defaultRead->GetReadBuffer(); GLenum bufs[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; MG_Impl::GLImpl::NamedFramebufferDrawBuffers(framebuffer, 2, bufs); @@ -267,7 +279,8 @@ TEST_F(FramebufferTest, NamedFramebufferDrawBuffersDoNotModifyDefaultFramebuffer EXPECT_EQ(framebufferObject->GetDrawBuffers()[0], FramebufferAttachmentType::Color0); EXPECT_EQ(framebufferObject->GetDrawBuffers()[1], FramebufferAttachmentType::Color1); EXPECT_EQ(framebufferObject->GetReadBuffer(), FramebufferAttachmentType::Color1); - EXPECT_EQ(defaultDraw->GetDrawBuffers()[0], FramebufferAttachmentType::Color0); + EXPECT_EQ(defaultDraw->GetDrawBuffers()[0], defaultDrawBuffer); + EXPECT_EQ(defaultRead->GetReadBuffer(), defaultReadBuffer); EXPECT_EQ(MG_State::pGLContext->GetFramebufferBindingSlot(FramebufferTarget::Draw).GetBoundObject(), defaultDraw); EXPECT_EQ(MG_State::pGLContext->GetFramebufferBindingSlot(FramebufferTarget::Read).GetBoundObject(), defaultRead); EXPECT_EQ(MG_Impl::GLImpl::GetError(), GL_NO_ERROR); diff --git a/MobileGL/MG_Test/Program/ProgramTest.cpp b/MobileGL/MG_Test/Program/ProgramTest.cpp index 37c24df6..3911b459 100644 --- a/MobileGL/MG_Test/Program/ProgramTest.cpp +++ b/MobileGL/MG_Test/Program/ProgramTest.cpp @@ -399,7 +399,7 @@ TEST_F(ProgramTest, CompileAndLink) { ASSERT_EQ(uniformCount, 14); GLint uniformNameMaxLength = 0; GetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &uniformNameMaxLength); - ASSERT_EQ(uniformNameMaxLength, 12); + ASSERT_EQ(uniformNameMaxLength, static_cast(sizeof("GreenMatrix0"))); ASSERT_EQ(GetAttribLocation(program, "Position"), 2); ASSERT_EQ(GetAttribLocation(program, "fIn1"), 1); diff --git a/MobileGL/MG_Test/Texture/TextureTest.cpp b/MobileGL/MG_Test/Texture/TextureTest.cpp index 9ec245d7..a28a7f40 100644 --- a/MobileGL/MG_Test/Texture/TextureTest.cpp +++ b/MobileGL/MG_Test/Texture/TextureTest.cpp @@ -127,12 +127,13 @@ TEST_F(TextureTest, TextureStorage2DMultisampleTracksNamedObjectState) { GLuint texture = 0; MG_Impl::GLImpl::CreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &texture); - MG_Impl::GLImpl::TextureStorage2DMultisample(texture, 4, GL_RGBA8, 8, 6, GL_TRUE); + constexpr GLsizei sampleCount = 1; + MG_Impl::GLImpl::TextureStorage2DMultisample(texture, sampleCount, GL_RGBA8, 8, 6, GL_TRUE); const auto textureObject = MG_State::pGLContext->GetTextureObject(texture); ASSERT_NE(textureObject, nullptr); EXPECT_EQ(textureObject->GetTarget(), TextureTarget::Texture2DMultisample); - EXPECT_EQ(textureObject->GetSamples(), 4); + EXPECT_EQ(textureObject->GetSamples(), sampleCount); EXPECT_TRUE(textureObject->HasFixedSampleLocations()); auto* textureMipmapObject = static_cast(textureObject.get()); @@ -145,7 +146,7 @@ TEST_F(TextureTest, TextureStorage2DMultisampleTracksNamedObjectState) { GLint fixed = 0; MG_Impl::GLImpl::GetTextureLevelParameteriv(texture, 0, GL_TEXTURE_SAMPLES, &samples); MG_Impl::GLImpl::GetTextureLevelParameteriv(texture, 0, GL_TEXTURE_FIXED_SAMPLE_LOCATIONS, &fixed); - EXPECT_EQ(samples, 4); + EXPECT_EQ(samples, sampleCount); EXPECT_EQ(fixed, GL_TRUE); EXPECT_EQ(MG_Impl::GLImpl::GetError(), GL_NO_ERROR); } @@ -303,6 +304,7 @@ TEST_F(TextureTest, TextureStorage3DAndSubImageModifyNamedObjectOnly) { 1, 2, 3, 4, 5, 6, 7, 8, }; + MG_Impl::GLImpl::PixelStorei(GL_UNPACK_ALIGNMENT, 1); MG_Impl::GLImpl::TextureSubImage3D(texture, 0, 0, 0, 0, 2, 2, 2, GL_RED, GL_UNSIGNED_BYTE, pixels); const auto textureObject = MG_State::pGLContext->GetTextureObject(texture); diff --git a/MobileGL/MG_Test/VertexArray/VertexArrayTest.cpp b/MobileGL/MG_Test/VertexArray/VertexArrayTest.cpp index 4196f6d3..a7937bac 100644 --- a/MobileGL/MG_Test/VertexArray/VertexArrayTest.cpp +++ b/MobileGL/MG_Test/VertexArray/VertexArrayTest.cpp @@ -127,7 +127,9 @@ TEST_F(VertexArrayTest, DeleteVAO) { ASSERT_FALSE(MobileGL::MG_State::pGLContext->ValidateVertexArrayObject(vaoNames[0])); ASSERT_EQ(MobileGL::MG_State::pGLContext->GetVertexArrayObject(vaoNames[0]), nullptr); - ASSERT_EQ(MobileGL::MG_State::pGLContext->GetBoundVertexArray(), nullptr); + const auto boundVao = MobileGL::MG_State::pGLContext->GetBoundVertexArray(); + ASSERT_NE(boundVao, nullptr); + ASSERT_EQ(boundVao->GetExternalIndex(), 0u); } TEST_F(VertexArrayTest, ValidateNamesAndObjects) { @@ -598,12 +600,12 @@ TEST_F(GeneralVertexArrayTest, General_DeleteBoundVAO) { DeleteVertexArrays(1, &vao); - EXPECT_EQ(MG_State::pGLContext->GetBoundVertexArray(), nullptr); + const auto boundVao = MG_State::pGLContext->GetBoundVertexArray(); + ASSERT_NE(boundVao, nullptr); + EXPECT_EQ(boundVao->GetExternalIndex(), 0u); EXPECT_EQ(MG_State::pGLContext->GetVertexArrayObject(vao), nullptr); VertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); - EXPECT_EQ(GetError(), GL_INVALID_OPERATION); - EXPECT_EQ(GetError(), GL_NO_ERROR); }