My Project
ParaVertexBuffer.h
1 #pragma once
2 namespace ParaEngine
3 {
4 #ifdef USE_DIRECTX_RENDERER
5  typedef IDirect3DVertexBuffer9* VertexBufferDevicePtr_type;
6  typedef IDirect3DIndexBuffer9* IndexBufferDevicePtr_type;
7 #elif defined(USE_OPENGL_RENDERER)
8  typedef GLuint VertexBufferDevicePtr_type;
9  typedef GLuint IndexBufferDevicePtr_type;
10 #else
11  typedef int32_t VertexBufferDevicePtr_type;
12  typedef int32_t IndexBufferDevicePtr_type;
13 #endif
14 
19  {
20  public:
23 
24  enum EnumBufferType
25  {
26  BufferType_VertexBuffer = 0,
27  BufferType_IndexBuffer,
28  BufferType_MemoryBuffer,
29  };
30  public:
31  VertexBufferDevicePtr_type GetDevicePointer();
32 
33  IndexBufferDevicePtr_type GetDevicePointerAsIndexBuffer();
34  char* GetMemoryPointer();
35 
40  bool CreateBuffer(uint32 nBufferSize, DWORD dwFormat = 0, DWORD dwUsage = 0, D3DPOOL dwPool = D3DPOOL_MANAGED);
41  bool CreateIndexBuffer(uint32 nBufferSize, DWORD dwFormat = 0, DWORD dwUsage = 0);
42  bool CreateMemoryBuffer(uint32 nBufferSize, DWORD dwFormat = 0, DWORD dwUsage = 0);
43 
47  void ReleaseBuffer();
48 
50  bool Lock(void** ppData, uint32 offsetToLock = 0, uint32 sizeToLock = 0, DWORD dwFlag = 0);
52  void Unlock();
53 
55  uint32 GetBufferSize();
56 
58  bool IsValid() const;
59  operator bool() const { return IsValid(); };
60  bool operator !() const { return !IsValid(); };
61  void RendererRecreated();
62  void UploadMemoryBuffer(const char* pBuffer, int32 nBufSize = -1);
63  protected:
64  union {
65  IndexBufferDevicePtr_type m_indexBuffer;
66  VertexBufferDevicePtr_type m_vertexBuffer;
67  };
68 
69  uint32 m_nBufferSize;
70  // only valid between Lock and Unlock or type is BufferType_MemoryBuffer
71  char* m_buffer;
72  EnumBufferType m_bufferType;
73  };
74 
79  {
80  public:
81  bool CreateBuffer(uint32 nBufferSize, DWORD dwFormat = 0, DWORD dwUsage = 0);
82  IndexBufferDevicePtr_type GetDevicePointer();
83  };
84 
88  {
89  public:
90  bool CreateBuffer(uint32 nBufferSize, DWORD dwFormat = 0, DWORD dwUsage = 0);
91  char* GetDevicePointer();
92  };
93 
94 }
bool CreateBuffer(uint32 nBufferSize, DWORD dwFormat=0, DWORD dwUsage=0, D3DPOOL dwPool=D3DPOOL_MANAGED)
recreate the buffer based on the new size
Definition: ParaVertexBuffer.cpp:49
pure memory buffer, useful for filling in another thread and then upload to a real vertex buffer in t...
Definition: ParaVertexBuffer.h:87
different physics engine has different winding order.
Definition: EventBinding.h:32
cross platform vertex/index buffer.
Definition: ParaVertexBuffer.h:18
void ReleaseBuffer()
release the buffer.
Definition: ParaVertexBuffer.cpp:95
in OpenGL, there is no different between vertex and index buffer.
Definition: ParaVertexBuffer.h:78
void Unlock()
unlock the buffer
Definition: ParaVertexBuffer.cpp:144
uint32 GetBufferSize()
get the current buffer size.
Definition: ParaVertexBuffer.cpp:36
bool Lock(void **ppData, uint32 offsetToLock=0, uint32 sizeToLock=0, DWORD dwFlag=0)
lock and return a writable buffer into which one can fill the buffer.
Definition: ParaVertexBuffer.cpp:121
bool IsValid() const
boolean: test validity
Definition: ParaVertexBuffer.cpp:177