diff --git a/MobileGL/MG_State/GLState/BufferState/BufferObject.h b/MobileGL/MG_State/GLState/BufferState/BufferObject.h index bb55fc25..4d86ab44 100644 --- a/MobileGL/MG_State/GLState/BufferState/BufferObject.h +++ b/MobileGL/MG_State/GLState/BufferState/BufferObject.h @@ -15,7 +15,8 @@ namespace MobileGL { AtomicCounter, DispatchIndirect, DrawIndirect, - ShaderStorage + ShaderStorage, + BufferTargetCount }; enum class BufferUsage { diff --git a/MobileGL/MG_State/GLState/BufferState/BufferState.cpp b/MobileGL/MG_State/GLState/BufferState/BufferState.cpp index 462190d9..a98931cd 100644 --- a/MobileGL/MG_State/GLState/BufferState/BufferState.cpp +++ b/MobileGL/MG_State/GLState/BufferState/BufferState.cpp @@ -18,7 +18,7 @@ namespace MobileGL { // m_size = data.size; memcpy(m_data.data() + atOffset, data.data, data.size); // m_dirtyRange = MakeUnique(0, m_size); - m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size - 1); + m_dirtyRange.UnionUpdate(atOffset, atOffset + data.size); } void* BufferObject::AcquireMemory(Bool markMapped, Bool read, Bool write) { @@ -78,13 +78,7 @@ namespace MobileGL { } BindingSlot& BufferState::GetBindingSlot(BufferTarget target) { - for (auto& slot : m_bindingSlots) { - if (slot.GetTarget() == target) { - return slot; - } - } - m_bindingSlots.emplace_back(target); - return m_bindingSlots.back(); + return m_bindingSlots[(SizeT)target]; } } } diff --git a/MobileGL/MG_State/GLState/BufferState/BufferState.h b/MobileGL/MG_State/GLState/BufferState/BufferState.h index 8e9b02d0..cc9eb28f 100644 --- a/MobileGL/MG_State/GLState/BufferState/BufferState.h +++ b/MobileGL/MG_State/GLState/BufferState/BufferState.h @@ -5,6 +5,12 @@ namespace MobileGL { namespace GLState { class BufferState { public: + BufferState() { + for (SizeT i = 0; i < (SizeT)BufferTarget::BufferTargetCount; ++i) { + m_bindingSlots[i] = BindingSlot((BufferTarget)i); + } + } + SharedPtr GetBufferObject(Uint index); Vector GenerateNames(Uint number); SharedPtr CreateBufferObject(Uint index); @@ -13,7 +19,7 @@ namespace MobileGL { private: UnorderedMap> m_bufferObjects; IndexGenerator m_indexGenerator; - Vector> m_bindingSlots; + Array, (SizeT)BufferTarget::BufferTargetCount> m_bindingSlots; }; } } diff --git a/MobileGL/MG_Test/Buffer/BufferTest.cpp b/MobileGL/MG_Test/Buffer/BufferTest.cpp index 9ff51df3..6116fb3e 100644 --- a/MobileGL/MG_Test/Buffer/BufferTest.cpp +++ b/MobileGL/MG_Test/Buffer/BufferTest.cpp @@ -48,13 +48,17 @@ TEST_F(BufferTest, PingPong) { Vector data { 1, 2, 3, 4, 5 }; + SizeT byte_size = data.size() * sizeof(Int); // Write data - bufWrite->Resize(data.size()); - DataPtr ptr { .data = data.data(), .size = data.size() }; + bufWrite->Resize(byte_size); + DataPtr ptr { .data = data.data(), .size = byte_size }; bufWrite->UploadData(ptr, 0); // Readback auto bufRead = readSlot.GetBoundObject(); void* p = bufRead->AcquireMemory(true, true, false); - ASSERT_TRUE(memcmp(data.data(), p, data.size()) == 0); + ASSERT_TRUE(memcmp(data.data(), p, byte_size) == 0); + auto range = bufRead->GetDirtyRange(); + ASSERT_EQ(range.start, 0); + ASSERT_EQ(range.end, byte_size); } diff --git a/MobileGL/MG_Util/Types.h b/MobileGL/MG_Util/Types.h index 3be46c7d..6edea2f3 100644 --- a/MobileGL/MG_Util/Types.h +++ b/MobileGL/MG_Util/Types.h @@ -113,6 +113,8 @@ namespace MobileGL { public: using TargetEnum = typename ObjectType::TargetEnum; + BindingSlot(): m_target((TargetEnum)0), m_boundObject(nullptr) {} + explicit BindingSlot(TargetEnum target) : m_target(target), m_boundObject(nullptr) { }