summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/GPUDataBuffer.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-27 23:37:24 +0800
committerchai <chaifix@163.com>2021-10-27 23:37:24 +0800
commit305ca0a09d4e750186b5190432de47f3493e806a (patch)
treed82f9ef73191abc2acbcbfdca4b184a28e6c381b /Runtime/Graphics/GPUDataBuffer.h
parent51ced5a191078ce4ef08d57e343e91db007f556f (diff)
*GfxDevice
Diffstat (limited to 'Runtime/Graphics/GPUDataBuffer.h')
-rw-r--r--Runtime/Graphics/GPUDataBuffer.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/Runtime/Graphics/GPUDataBuffer.h b/Runtime/Graphics/GPUDataBuffer.h
new file mode 100644
index 0000000..f66d951
--- /dev/null
+++ b/Runtime/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:
+ 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;
+
+ DataBuffer();
+ ~DataBuffer();
+
+ 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