mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-09 04:38:30 +09:00
[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.
This commit is contained in:
@@ -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<GLint>(bufferObject->GetExternalIndex()) : 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& activeBackendObject = MG_Backend::pActiveBackendObject;
|
||||
if (!activeBackendObject) {
|
||||
MGLOG_E("activeBackendObject is not initialized!");
|
||||
|
||||
@@ -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<GLuint>(signedParams[i]);
|
||||
}
|
||||
}
|
||||
@@ -1423,6 +1424,15 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
params[3] = static_cast<GLint>(borderColor.w());
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_SWIZZLE_RGBA:
|
||||
if (params) {
|
||||
const auto& swizzleParams = textureObject->GetAllSwizzleParams();
|
||||
params[0] = static_cast<GLint>(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[0]));
|
||||
params[1] = static_cast<GLint>(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[1]));
|
||||
params[2] = static_cast<GLint>(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[2]));
|
||||
params[3] = static_cast<GLint>(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[3]));
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_SWIZZLE_R:
|
||||
if (params) {
|
||||
*params = static_cast<GLint>(
|
||||
@@ -1531,6 +1541,15 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
*params = static_cast<GLfloat>(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<GLfloat>(
|
||||
@@ -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<GLfloat>(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[0]));
|
||||
params[1] = static_cast<GLfloat>(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[1]));
|
||||
params[2] = static_cast<GLfloat>(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[2]));
|
||||
params[3] = static_cast<GLfloat>(MG_Util::ConvertTextureSwizzleParamToGLEnum(swizzleParams[3]));
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_WRAP_S:
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<GLint>(sizeof("GreenMatrix0")));
|
||||
|
||||
ASSERT_EQ(GetAttribLocation(program, "Position"), 2);
|
||||
ASSERT_EQ(GetAttribLocation(program, "fIn1"), 1);
|
||||
|
||||
@@ -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<MG_State::GLState::TextureObjectMipmap*>(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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user