My Project
ParaVertexBufferPool.h
1 #pragma once
2 #include "AssetManager.h"
3 #include <unordered_set>
4 
5 namespace ParaEngine
6 {
7  class ParaVertexBuffer;
8 
11  {
12  public:
13  ParaVertexBufferPool(const AssetKey& key);
15  virtual ~ParaVertexBufferPool();
16 
17  ATTRIBUTE_DEFINE_CLASS(ParaVertexBufferPool);
19  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
20  ATTRIBUTE_METHOD1(ParaVertexBufferPool, GetFullSizedBufferSize_s, int*) { *p1 = cls->GetFullSizedBufferSize(); return S_OK; }
21  ATTRIBUTE_METHOD1(ParaVertexBufferPool, SetFullSizedBufferSize_s, int) { cls->SetFullSizedBufferSize((uint32)p1); return S_OK; }
22 
23  ATTRIBUTE_METHOD1(ParaVertexBufferPool, GetMaxPooledCount_s, int*) { *p1 = cls->GetMaxPooledCount(); return S_OK; }
24  ATTRIBUTE_METHOD1(ParaVertexBufferPool, SetMaxPooledCount_s, int) { cls->SetMaxPooledCount((uint32)p1); return S_OK; }
25 
26  ATTRIBUTE_METHOD1(ParaVertexBufferPool, GetActiveBufferCount_s, int*) { *p1 = cls->GetActiveBufferCount(); return S_OK; }
27  ATTRIBUTE_METHOD1(ParaVertexBufferPool, GetTotalBufferCount_s, int*) { *p1 = cls->GetTotalBufferCount(); return S_OK; }
28  ATTRIBUTE_METHOD1(ParaVertexBufferPool, GetTotalBufferBytes_s, int*) { *p1 = cls->GetTotalBufferBytes(); return S_OK; }
29 
30  public:
31 
32  uint32 GetFullSizedBufferSize() const;
33  void SetFullSizedBufferSize(uint32 val);
34  uint32 GetMaxPooledCount() const;
35  void SetMaxPooledCount(uint32 val);
36  size_t GetTotalBufferBytes(bool bRecalculate=false);
37 
38  int GetActiveBufferCount() const;
40  int GetTotalBufferCount() const;
41 
48  ParaVertexBuffer* CreateBuffer(uint32 nBufferSize, DWORD dwFormat = 0, DWORD dwUsage = 0, D3DPOOL dwPool = D3DPOOL_MANAGED);
49 
52  void ReleaseBuffer(ParaVertexBuffer* pBuffer);
53 
55  void TickCache();
56 
58  virtual void Cleanup();
59 
60  virtual HRESULT RendererRecreated();
61 
62 
63  protected:
64  std::unordered_set<ParaVertexBuffer*> m_activeBuffers;
65  std::unordered_set<ParaVertexBuffer*> m_unusedFullSizedBuffers;
66 
69 
72 
75 
76  };
77 
78 
80  class CVertexBufferPoolManager : public AssetManager < ParaVertexBufferPool, ParaVertexBufferPool, ParaVertexBufferPool >
81  {
82  public:
84 
85  ParaVertexBufferPool* CreateGetPool(const std::string& name);
86 
87  static CVertexBufferPoolManager& GetInstance();
88  public:
89  void TickCache();
90 
92  size_t GetVertexBufferPoolTotalBytes();
93 
94  };
95 
96 }
97 
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
void TickCache()
called between render tick to release some cached pool object if needed.
Definition: ParaVertexBufferPool.cpp:112
different physics engine has different winding order.
Definition: EventBinding.h:32
pool of vertex buffer object.
Definition: ParaVertexBufferPool.h:10
cross platform vertex/index buffer.
Definition: ParaVertexBuffer.h:18
virtual void Cleanup()
clear all pooled objects.
Definition: ParaVertexBufferPool.cpp:64
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: ParaVertexBufferPool.cpp:241
uint32 m_nFullSizedBufferSize
we will reuse full sized buffer
Definition: ParaVertexBufferPool.h:68
AssetManager manages a set of asset entities of a certain type.
Definition: AssetManager.h:13
size_t m_nTotalBufferBytes
total number of bytes in memory.
Definition: ParaVertexBufferPool.h:74
void ReleaseBuffer(ParaVertexBuffer *pBuffer)
release the buffer.
Definition: ParaVertexBufferPool.cpp:163
int GetTotalBufferCount() const
including active and unused buffer count.
Definition: ParaVertexBufferPool.cpp:59
a manger of sequences
Definition: ParaVertexBufferPool.h:80
virtual HRESULT RendererRecreated()
callback of listening the event that renderer was recreated on Android/WP8 all opengl related id has ...
Definition: ParaVertexBufferPool.cpp:88
std::string AssetKey
the unique key object for asset entity.
Definition: AssetEntity.h:13
uint32 m_nMaxPooledCount
max number of pooled objects.
Definition: ParaVertexBufferPool.h:71
ParaVertexBuffer * CreateBuffer(uint32 nBufferSize, DWORD dwFormat=0, DWORD dwUsage=0, D3DPOOL dwPool=D3DPOOL_MANAGED)
recreate the buffer based on the new size.
Definition: ParaVertexBufferPool.cpp:130
Base class for managed asset entity in ParaEngine.
Definition: AssetEntity.h:25