mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 13:48:30 +09:00
[Fix] (MG_State/Buffer): pass PingPong test
This commit is contained in:
@@ -15,7 +15,8 @@ namespace MobileGL {
|
|||||||
AtomicCounter,
|
AtomicCounter,
|
||||||
DispatchIndirect,
|
DispatchIndirect,
|
||||||
DrawIndirect,
|
DrawIndirect,
|
||||||
ShaderStorage
|
ShaderStorage,
|
||||||
|
BufferTargetCount
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class BufferUsage {
|
enum class BufferUsage {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace MobileGL {
|
|||||||
// m_size = data.size;
|
// m_size = data.size;
|
||||||
memcpy(m_data.data() + atOffset, data.data, data.size);
|
memcpy(m_data.data() + atOffset, data.data, data.size);
|
||||||
// m_dirtyRange = MakeUnique<Range1D>(0, m_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) {
|
void* BufferObject::AcquireMemory(Bool markMapped, Bool read, Bool write) {
|
||||||
@@ -78,13 +78,7 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BindingSlot<BufferObject>& BufferState::GetBindingSlot(BufferTarget target) {
|
BindingSlot<BufferObject>& BufferState::GetBindingSlot(BufferTarget target) {
|
||||||
for (auto& slot : m_bindingSlots) {
|
return m_bindingSlots[(SizeT)target];
|
||||||
if (slot.GetTarget() == target) {
|
|
||||||
return slot;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_bindingSlots.emplace_back(target);
|
|
||||||
return m_bindingSlots.back();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ namespace MobileGL {
|
|||||||
namespace GLState {
|
namespace GLState {
|
||||||
class BufferState {
|
class BufferState {
|
||||||
public:
|
public:
|
||||||
|
BufferState() {
|
||||||
|
for (SizeT i = 0; i < (SizeT)BufferTarget::BufferTargetCount; ++i) {
|
||||||
|
m_bindingSlots[i] = BindingSlot<BufferObject>((BufferTarget)i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SharedPtr<BufferObject> GetBufferObject(Uint index);
|
SharedPtr<BufferObject> GetBufferObject(Uint index);
|
||||||
Vector<Uint> GenerateNames(Uint number);
|
Vector<Uint> GenerateNames(Uint number);
|
||||||
SharedPtr<BufferObject> CreateBufferObject(Uint index);
|
SharedPtr<BufferObject> CreateBufferObject(Uint index);
|
||||||
@@ -13,7 +19,7 @@ namespace MobileGL {
|
|||||||
private:
|
private:
|
||||||
UnorderedMap<Uint, SharedPtr<BufferObject>> m_bufferObjects;
|
UnorderedMap<Uint, SharedPtr<BufferObject>> m_bufferObjects;
|
||||||
IndexGenerator<Uint> m_indexGenerator;
|
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 };
|
Vector<Int> data { 1, 2, 3, 4, 5 };
|
||||||
|
|
||||||
|
SizeT byte_size = data.size() * sizeof(Int);
|
||||||
// Write data
|
// Write data
|
||||||
bufWrite->Resize(data.size());
|
bufWrite->Resize(byte_size);
|
||||||
DataPtr ptr { .data = data.data(), .size = data.size() };
|
DataPtr ptr { .data = data.data(), .size = byte_size };
|
||||||
bufWrite->UploadData(ptr, 0);
|
bufWrite->UploadData(ptr, 0);
|
||||||
|
|
||||||
// Readback
|
// Readback
|
||||||
auto bufRead = readSlot.GetBoundObject();
|
auto bufRead = readSlot.GetBoundObject();
|
||||||
void* p = bufRead->AcquireMemory(true, true, false);
|
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:
|
public:
|
||||||
using TargetEnum = typename ObjectType::TargetEnum;
|
using TargetEnum = typename ObjectType::TargetEnum;
|
||||||
|
|
||||||
|
BindingSlot(): m_target((TargetEnum)0), m_boundObject(nullptr) {}
|
||||||
|
|
||||||
explicit BindingSlot(TargetEnum target)
|
explicit BindingSlot(TargetEnum target)
|
||||||
: m_target(target), m_boundObject(nullptr) {
|
: m_target(target), m_boundObject(nullptr) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user