[Feat] (MG_State/Buffer): separate UploadData() into Resize()+UploadData()

This commit is contained in:
2025-07-18 10:01:40 +08:00
parent 99eaf317ba
commit 0d73120d15
4 changed files with 67 additions and 24 deletions
+25 -1
View File
@@ -31,4 +31,28 @@ TEST_F(BufferTest, Binding) {
indexSlot.Bind(obj2);
ASSERT_TRUE(arraySlot.GetBoundObject() == obj2);
ASSERT_TRUE(indexSlot.GetBoundObject() == obj2);
}
}
TEST_F(BufferTest, PingPong) {
auto& readSlot = glContext.GetBufferBindingSlot(BufferTarget::CopyRead);
auto& writeSlot = glContext.GetBufferBindingSlot(BufferTarget::CopyWrite);
{
auto bufferNames = glContext.GenBufferNames(1);
auto bufObj = glContext.CreateBufferObject(bufferNames[0]);
writeSlot.Bind(bufObj);
readSlot.Bind(bufObj);
}
auto bufWrite = writeSlot.GetBoundObject();
Vector<Int> data { 1, 2, 3, 4, 5 };
bufWrite->Resize(data.size());
DataPtr ptr { .data = data.data(), .size = data.size() };
bufWrite->UploadData(ptr, 0);
auto bufRead = readSlot.GetBoundObject();
void* p = bufRead->AcquireMemory(true, true, false);
ASSERT_TRUE(memcmp(data.data(), p, data.size()) == 0);
}