BsD3D9IndexBuffer.h 2.7 KB

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