BsD3D9IndexBuffer.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 D3D9IndexBuffer : public IndexBuffer, 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. ~D3D9IndexBuffer();
  26. /**
  27. * @copydoc IndexBuffer::readData
  28. */
  29. void readData(UINT32 offset, UINT32 length, void* dest);
  30. /**
  31. * @copydoc IndexBuffer::writeData
  32. */
  33. void writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags = BufferWriteType::Normal);
  34. /**
  35. * @copydoc D3D9Resource::notifyOnDeviceCreate
  36. */
  37. virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  38. /**
  39. * @copydoc D3D9Resource::notifyOnDeviceDestroy
  40. */
  41. virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  42. /**
  43. * @copydoc D3D9Resource::notifyOnDeviceLost
  44. */
  45. virtual void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
  46. /**
  47. * @copydoc D3D9Resource::notifyOnDeviceReset
  48. */
  49. virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
  50. /**
  51. * @brief Creates a DX9 index buffer object in the provided memory pool.
  52. */
  53. void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool);
  54. /**
  55. * @brief Returns the DX9 index buffer object.
  56. */
  57. IDirect3DIndexBuffer9* getD3DIndexBuffer();
  58. protected:
  59. friend class D3D9HardwareBufferManager;
  60. D3D9IndexBuffer(IndexType idxType, UINT32 numIndexes, GpuBufferUsage usage, bool useSystemMem);
  61. /**
  62. * @copydoc IndexBuffer::lockImpl
  63. */
  64. void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
  65. /**
  66. * @copydoc IndexBuffer::unlockImpl
  67. */
  68. void unlockImpl();
  69. /**
  70. * @brief Updates buffer resources from cached system memory buffer.
  71. */
  72. bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);
  73. /**
  74. * @copydoc IndexBuffer::initialize_internal
  75. */
  76. void initialize_internal();
  77. /**
  78. * @copydoc IndexBuffer::destroy_internal
  79. */
  80. void destroy_internal();
  81. protected:
  82. Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
  83. D3DINDEXBUFFER_DESC mBufferDesc;
  84. UINT8* mSystemMemoryBuffer;
  85. };
  86. }