mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 04:08:32 +09:00
[Fix] (MG_State/Buffer): pass PingPong test
This commit is contained in:
@@ -15,7 +15,8 @@ namespace MobileGL {
|
||||
AtomicCounter,
|
||||
DispatchIndirect,
|
||||
DrawIndirect,
|
||||
ShaderStorage
|
||||
ShaderStorage,
|
||||
BufferTargetCount
|
||||
};
|
||||
|
||||
enum class BufferUsage {
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace MobileGL {
|
||||
// m_size = data.size;
|
||||
memcpy(m_data.data() + atOffset, data.data, data.size);
|
||||
// m_dirtyRange = MakeUnique<Range1D>(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<BufferObject>& 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<BufferObject>((BufferTarget)i);
|
||||
}
|
||||
}
|
||||
|
||||
SharedPtr<BufferObject> GetBufferObject(Uint index);
|
||||
Vector<Uint> GenerateNames(Uint number);
|
||||
SharedPtr<BufferObject> CreateBufferObject(Uint index);
|
||||
@@ -13,7 +19,7 @@ namespace MobileGL {
|
||||
private:
|
||||
UnorderedMap<Uint, SharedPtr<BufferObject>> m_bufferObjects;
|
||||
IndexGenerator<Uint> m_indexGenerator;
|
||||
Vector<BindingSlot<BufferObject>> m_bindingSlots;
|
||||
Array<BindingSlot<BufferObject>, (SizeT)BufferTarget::BufferTargetCount> m_bindingSlots;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,13 +48,17 @@ TEST_F(BufferTest, PingPong) {
|
||||
|
||||
Vector<Int> 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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user