BsD3D9IndexBuffer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. #include "BsIndexBuffer.h"
  4. #include "BsD3D9Resource.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief DirectX 9 implementation of an index buffer.
  9. */
  10. class BS_D3D9_EXPORT D3D9IndexBufferCore : public IndexBufferCore, public D3D9Resource
  11. {
  12. protected:
  13. /**
  14. * @brief Container for internal buffer resources.
  15. */
  16. struct BufferResources
  17. {
  18. IDirect3DIndexBuffer9* mBuffer;
  19. bool mOutOfDate;
  20. UINT32 mLockOffset;
  21. UINT32 mLockLength;
  22. GpuLockOptions mLockOptions;
  23. };
  24. public:
  25. D3D9IndexBufferCore(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage);
  26. ~D3D9IndexBufferCore();
  27. /**
  28. * @copydoc IndexBufferCore::readData
  29. */
  30. void readData(UINT32 offset, UINT32 length, void* dest);
  31. /**
  32. * @copydoc IndexBufferCore::writeData
  33. */
  34. void writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags = BufferWriteType::Normal);
  35. /**
  36. * @copydoc D3D9Resource::notifyOnDeviceCreate
  37. */
  38. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  39. /**
  40. * @copydoc D3D9Resource::notifyOnDeviceDestroy
  41. */
  42. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  43. /**
  44. * @copydoc D3D9Resource::notifyOnDeviceLost
  45. */
  46. virtual void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
  47. /**
  48. * @copydoc D3D9Resource::notifyOnDeviceReset
  49. */
  50. virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
  51. /**
  52. * @brief Creates a DX9 index buffer object in the provided memory pool.
  53. */
  54. void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool);
  55. /**
  56. * @brief Returns the DX9 index buffer object.
  57. */
  58. IDirect3DIndexBuffer9* getD3DIndexBuffer();
  59. protected:
  60. /**
  61. * @copydoc IndexBufferCore::lockImpl
  62. */
  63. void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
  64. /**
  65. * @copydoc IndexBufferCore::unlockImpl
  66. */
  67. void unlockImpl();
  68. /**
  69. * @brief Updates buffer resources from cached system memory buffer.
  70. */
  71. bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);
  72. /**
  73. * @copydoc IndexBufferCore::initialize
  74. */
  75. void initialize();
  76. protected:
  77. Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
  78. D3DINDEXBUFFER_DESC mBufferDesc;
  79. UINT8* mSystemMemoryBuffer;
  80. };
  81. }