diff --git a/Common/GPU/OpenGL/GLMemory.h b/Common/GPU/OpenGL/GLMemory.h index 3c623eeed5..180e8aa583 100644 --- a/Common/GPU/OpenGL/GLMemory.h +++ b/Common/GPU/OpenGL/GLMemory.h @@ -78,6 +78,9 @@ public: void Reset() { offset_ = 0; } + // Utility for users of this class, not used internally. + const uint32_t INVALID_OFFSET = 0xFFFFFFFF; + private: // Needs context in case of defragment. void Begin() { @@ -105,7 +108,9 @@ public: return writePtr_ != nullptr; } - // Recommended - write directly into the buffer through the returned pointer. + // Recommended - lets you write directly into the buffer through the returned pointer. + // If you didn't end up using all the memory you grabbed here, then before calling Allocate or Push + // again, call Rewind (see below). uint8_t *Allocate(uint32_t numBytes, uint32_t alignment, GLRBuffer **buf, uint32_t *bindOffset) { uint32_t offset = ((uint32_t)offset_ + alignment - 1) & ~(alignment - 1); if (offset + numBytes <= size_) { @@ -130,6 +135,12 @@ public: return bindOffset; } + // If you didn't use all of the previous allocation you just made (obviously can't be another one), + // you can return memory to the buffer by specifying the offset up until which you wrote data. + void Rewind(uint32_t offset) { + offset_ = offset; + } + size_t GetOffset() const { return offset_; } size_t GetTotalSize() const;