diff options
Diffstat (limited to 'Client/Source/Graphics/GPUDataBuffer.h')
-rw-r--r-- | Client/Source/Graphics/GPUDataBuffer.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Client/Source/Graphics/GPUDataBuffer.h b/Client/Source/Graphics/GPUDataBuffer.h new file mode 100644 index 0000000..3d24514 --- /dev/null +++ b/Client/Source/Graphics/GPUDataBuffer.h @@ -0,0 +1,75 @@ +#ifndef GPU_DATABUFFER_H +#define GPU_DATABUFFER_H + +#include <vector> + +#include "../Utilities/Type.h" +#include "../Utilities/Singleton.h" +#include "../Utilities/UtilMacros.h" +#include "../Utilities/Assert.h" +#include "OpenGL.h" + +namespace GPU +{ + + class DataBuffer + { + public: + DataBuffer(); + ~DataBuffer(); + + void Upload(int offset, int size, const void* data); + void* Map(uint32 access); + void* MapRange(int offset, int size, uint32 access); // ÐÔÄÜ×î¼Ñ + void FlushMapedRange(int offset, int size); + + void UnMap(); + + void Orphan(); + + void Restore(int size, GLenum usage); + void RestoreWithData(int size, GLenum usage, const void* data); + + GET(int, Size, m_Size); + GET(GLenum, Usage, m_Usage); + GET(GLuint, Handle, m_Handle); + + private: + friend class BufferPool; + + GLuint m_Handle; + int m_Size; + GLenum m_Usage; + }; + + class BufferPool : public Singleton<BufferPool> + { + public: + BufferPool(); + ~BufferPool(); + + DataBuffer* ClaimBuffer(int size, GLenum usage); + void ReleaseBuffer(DataBuffer* buffer); + + void OnEndFrame(); + + private: + static const int kSizeClassBaseLog2 = 10; + static const int kSizeClassStepLog2 = 1; + static const int kSizeClassCount = 7; + + int GetSizeClassLimit(int classNdx); + void UpdatePendingBuffersArray(); + void InsertToLive(DataBuffer* buffer); + uint GetSizeClass(uint bufferSize); + + std::vector<DataBuffer*> m_LiveBuffers[kSizeClassCount]; + + }; + + DataBuffer* ClaimBuffer(int size = 0, GLenum usage = GL_ARRAY_BUFFER); + void ReleaseBuffer(DataBuffer* buffer); + +} + +#endif
\ No newline at end of file |