BsD3D9IndexBuffer.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /** @addtogroup D3D9
  10. * @{
  11. */
  12. /** DirectX 9 implementation of an index buffer. */
  13. class BS_D3D9_EXPORT D3D9IndexBufferCore : public IndexBufferCore, public D3D9Resource
  14. {
  15. protected:
  16. /** Container for internal buffer resources. */
  17. struct BufferResources
  18. {
  19. IDirect3DIndexBuffer9* mBuffer;
  20. bool mOutOfDate;
  21. UINT32 mLockOffset;
  22. UINT32 mLockLength;
  23. GpuLockOptions mLockOptions;
  24. };
  25. public:
  26. D3D9IndexBufferCore(IndexType idxType, UINT32 numIndices, GpuBufferUsage usage);
  27. ~D3D9IndexBufferCore();
  28. /** @copydoc IndexBufferCore::readData */
  29. void readData(UINT32 offset, UINT32 length, void* dest) override;
  30. /** @copydoc IndexBufferCore::writeData */
  31. void writeData(UINT32 offset, UINT32 length, const void* source,
  32. BufferWriteType writeFlags = BufferWriteType::Normal) override;
  33. /** @copydoc D3D9Resource::notifyOnDeviceCreate */
  34. void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device) override;
  35. /** @copydoc D3D9Resource::notifyOnDeviceDestroy */
  36. void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device) override;
  37. /** @copydoc D3D9Resource::notifyOnDeviceLost */
  38. void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device) override;
  39. /** @copydoc D3D9Resource::notifyOnDeviceReset */
  40. void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device) override;
  41. /** Creates a DX9 index buffer object in the provided memory pool. */
  42. void createBuffer(IDirect3DDevice9* d3d9Device, D3DPOOL ePool);
  43. /** Returns the DX9 index buffer object. */
  44. IDirect3DIndexBuffer9* getD3DIndexBuffer();
  45. protected:
  46. /** @copydoc IndexBufferCore::lockImpl */
  47. void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options) override;
  48. /** @copydoc IndexBufferCore::unlockImpl */
  49. void unlockImpl() override;
  50. /** Updates buffer resources from cached system memory buffer. */
  51. bool updateBufferResources(const UINT8* systemMemoryBuffer, BufferResources* bufferResources);
  52. /** @copydoc IndexBufferCore::initialize */
  53. void initialize() override;
  54. protected:
  55. Map<IDirect3DDevice9*, BufferResources*> mMapDeviceToBufferResources;
  56. D3DINDEXBUFFER_DESC mBufferDesc;
  57. UINT8* mSystemMemoryBuffer;
  58. };
  59. /** @} */
  60. }