From e7a21423da6f653698b16752f88b5e513fb46825 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Fri, 25 Jul 2025 19:28:40 +0800 Subject: [PATCH] [Feat] (MG_State/VertexArrayState): Add IsInteger in attribute. --- .../GLState/VertexArrayState/VertexArrayObject.cpp | 3 ++- .../GLState/VertexArrayState/VertexArrayObject.h | 3 ++- MobileGL/MG_Test/VertexArray/VertexArrayTest.cpp | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp index db0b71c3..9a41d0cf 100644 --- a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp +++ b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp @@ -31,7 +31,7 @@ namespace MobileGL { } void VertexArrayObject::SetAttributeFormat(Uint index, int size, DataType type, - bool normalized, int stride, SizeT offset) { + bool normalized, int stride, SizeT offset, bool isInteger) { if (index >= MAX_VERTEX_ATTRIBS) return; if (size < 1 || size > 4) { @@ -44,6 +44,7 @@ namespace MobileGL { attr.Normalized = normalized; attr.Stride = stride; attr.Offset = offset; + attr.IsInteger = isInteger; } void VertexArrayObject::BindAttributeBuffer(Uint index, diff --git a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h index 1a20773e..be8fc26f 100644 --- a/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h +++ b/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.h @@ -10,6 +10,7 @@ namespace MobileGL { bool Normalized = false; int Stride = 0; SizeT Offset = 0; + bool IsInteger = false; SharedPtr Buffer; }; @@ -23,7 +24,7 @@ namespace MobileGL { void DisableAttribute(Uint index); bool IsAttributeEnabled(Uint index) const; - void SetAttributeFormat(Uint index, int size, DataType type, bool normalized, int stride, SizeT offset); + void SetAttributeFormat(Uint index, int size, DataType type, bool normalized, int stride, SizeT offset, bool isInteger); void BindAttributeBuffer(Uint index, const SharedPtr& buffer); diff --git a/MobileGL/MG_Test/VertexArray/VertexArrayTest.cpp b/MobileGL/MG_Test/VertexArray/VertexArrayTest.cpp index f4e60372..45caef9a 100644 --- a/MobileGL/MG_Test/VertexArray/VertexArrayTest.cpp +++ b/MobileGL/MG_Test/VertexArray/VertexArrayTest.cpp @@ -48,11 +48,11 @@ TEST_F(VertexArrayTest, VertexAttributeSetup) { auto vbo = CreateTestVBO(); vao->EnableAttribute(0); - vao->SetAttributeFormat(0, 4, DataType::Float32, false, 8 * sizeof(float), 0); + vao->SetAttributeFormat(0, 4, DataType::Float32, false, 8 * sizeof(float), 0, false); vao->BindAttributeBuffer(0, vbo); vao->EnableAttribute(1); - vao->SetAttributeFormat(1, 4, DataType::Float32, false, 8 * sizeof(float), 4 * sizeof(float)); + vao->SetAttributeFormat(1, 4, DataType::Float32, false, 8 * sizeof(float), 4 * sizeof(float), false); vao->BindAttributeBuffer(1, vbo); const auto& attr0 = vao->GetAttribute(0); @@ -145,15 +145,15 @@ TEST_F(VertexArrayTest, MultipleAttributes) { vboNormal->UploadData(ptr, 0); vao->EnableAttribute(0); - vao->SetAttributeFormat(0, 3, DataType::Float32, false, 3 * sizeof(float), 0); + vao->SetAttributeFormat(0, 3, DataType::Float32, false, 3 * sizeof(float), 0, false); vao->BindAttributeBuffer(0, vboPos); vao->EnableAttribute(1); - vao->SetAttributeFormat(1, 3, DataType::Float32, true, 3 * sizeof(float), 0); + vao->SetAttributeFormat(1, 3, DataType::Float32, true, 3 * sizeof(float), 0, false); vao->BindAttributeBuffer(1, vboNormal); vao->EnableAttribute(2); - vao->SetAttributeFormat(2, 4, DataType::Uint8, true, 4 * sizeof(Uint8), 0); + vao->SetAttributeFormat(2, 4, DataType::Uint8, true, 4 * sizeof(Uint8), 0, false); const auto& attr0 = vao->GetAttribute(0); ASSERT_EQ(attr0.Size, 3); @@ -181,12 +181,12 @@ TEST_F(VertexArrayTest, BoundVAOPreservesState) { glContext.BindVertexArray(vaoNames[0]); vao1->EnableAttribute(0); - vao1->SetAttributeFormat(0, 4, DataType::Float32, false, 0, 0); + vao1->SetAttributeFormat(0, 4, DataType::Float32, false, 0, 0, false); vao1->BindAttributeBuffer(0, vbo); glContext.BindVertexArray(vaoNames[1]); vao2->EnableAttribute(1); - vao2->SetAttributeFormat(1, 3, DataType::Float32, true, 0, 0); + vao2->SetAttributeFormat(1, 3, DataType::Float32, true, 0, 0, false); glContext.BindVertexArray(vaoNames[0]);