fixed texture loading

This commit is contained in:
Asuro
2025-02-17 18:25:39 +01:00
parent f93c40f3b6
commit fb5851020f
14 changed files with 30 additions and 16 deletions

View File

@@ -109,14 +109,16 @@ namespace Game
GameInst = &instance;
}
void* AllocateScratch(size_t byteCount, size_t align = 16)
void* AllocateScratch(size_t byteCount, size_t align)
{
size_t offset = GetInstance().UsedScratchAmount;
uint8_t* base = static_cast<uint8_t*>(GetShared().Game.TransientStorage);
uint8_t* current = base + offset;
uintptr_t ptrAligned = ((reinterpret_cast<uintptr_t>(current) + align - 1) / align) * align;
uintptr_t newOffset = ptrAligned - reinterpret_cast<uintptr_t>(base) + byteCount;
size_t offsetAligned = ((offset + align - 1) / align) * align;
uint8_t* ptrAligned = base + offsetAligned;
size_t newOffset = offsetAligned + byteCount;
if (newOffset > GetShared().Game.TransientStorageSize) return nullptr;
GetInstance().UsedScratchAmount = newOffset;
return reinterpret_cast<void*>(ptrAligned);
}
} // namespace Game