CmD3D9IndexBuffer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include "CmD3D9Prerequisites.h"
  3. #include "CmIndexBuffer.h"
  4. #include "CmD3D9Resource.h"
  5. namespace BansheeEngine
  6. {
  7. class BS_D3D9_EXPORT D3D9IndexBuffer : public IndexBuffer, public D3D9Resource
  8. {
  9. protected:
  10. struct BufferResources
  11. {
  12. IDirect3DIndexBuffer9* mBuffer;
  13. bool mOutOfDate;
  14. UINT32 mLockOffset;
  15. UINT32 mLockLength;
  16. GpuLockOptions mLockOptions;
  17. };
  18. public:
  19. ~D3D9IndexBuffer();
  20. /** See HardwareBuffer. */
  21. void readData(UINT32 offset, UINT32 length, void* dest);
  22. /** See HardwareBuffer. */
  23. void writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags = BufferWriteType::Normal);
  24. /**
  25. * @copydoc D3D9Resource::notifyOnDeviceCreate
  26. */
  27. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  28. /**
  29. * @copydoc D3D9Resource::notifyOnDeviceDestroy
  30. */
  31. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  32. /**
  33. * @copydoc D3D9Resource::notifyOnDeviceLost
  34. */
  35. virtual void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
  36. /**
  37. * @copydoc D3D9Resource::notifyOnDeviceReset
  38. */
  39. virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
  40. // Create the actual index buffer.
  41. void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool);
  42. /// Get the D3D-specific index buffer
  43. IDirect3DIndexBuffer9* getD3DIndexBuffer();
  44. protected:
  45. friend class D3D9HardwareBufferManager;
  46. D3D9IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMem);
  47. /** See HardwareBuffer. */
  48. void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
  49. /** See HardwareBuffer. */
  50. void unlockImpl();
  51. // updates buffer resources from system memory buffer.
  52. bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);
  53. /**
  54. * @copydoc IndexBuffer::initialize_internal()
  55. */
  56. void initialize_internal();
  57. /**
  58. * @copydoc IndexBuffer::destroy_internal()
  59. */
  60. void destroy_internal();
  61. protected:
  62. Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources; // Map between device to buffer resources.
  63. D3DINDEXBUFFER_DESC mBufferDesc; // Buffer description.
  64. UINT8* mSystemMemoryBuffer; // Consistent system memory buffer for multiple devices support.
  65. };
  66. }