BsD3D9ResourceManager.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief Types of resource creation policies.
  7. */
  8. enum D3D9ResourceCreationPolicy
  9. {
  10. /**
  11. * Creates resources only on active device. Meaning those resources will be unavailable
  12. * for other devices.
  13. */
  14. RCP_CREATE_ON_ACTIVE_DEVICE,
  15. /**
  16. * Creates resources on all devices making them available to all of them.
  17. */
  18. RCP_CREATE_ON_ALL_DEVICES
  19. };
  20. /**
  21. * @brief Handles DirectX 9 resource life, notifying them
  22. * about relevant device changes.
  23. */
  24. class BS_D3D9_EXPORT D3D9ResourceManager
  25. {
  26. public:
  27. D3D9ResourceManager();
  28. ~D3D9ResourceManager();
  29. /**
  30. * @brief Called after the device has been created.
  31. */
  32. void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  33. /**
  34. * @brief Called before the device is destroyed.
  35. */
  36. void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  37. /**
  38. * @brief Called after the device has entered the lost state.
  39. */
  40. void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
  41. /**
  42. * @brief Called after the device has been reset.
  43. */
  44. void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
  45. /**
  46. * @brief Called when device state is changing. Access to any device should be locked.
  47. */
  48. void lockDeviceAccess();
  49. /**
  50. * @brief Called when device state change completed. Access to any device is allowed.
  51. */
  52. void unlockDeviceAccess();
  53. /**
  54. * @brief Called when new resource is created.
  55. */
  56. void _notifyResourceCreated(D3D9Resource* pResource);
  57. /**
  58. * @brief Called before resource is destroyed.
  59. */
  60. void _notifyResourceDestroyed(D3D9Resource* pResource);
  61. /**
  62. * @brief Sets creation policy that specifies on what devices will resources be created on.
  63. */
  64. void setCreationPolicy(D3D9ResourceCreationPolicy creationPolicy);
  65. /**
  66. * @brief Returns creation policy that specifies on what devices will resources be created on.
  67. */
  68. D3D9ResourceCreationPolicy getCreationPolicy() const;
  69. protected:
  70. friend class D3D9Resource;
  71. BS_MUTEX(mResourcesMutex)
  72. Vector<D3D9Resource*> mResources;
  73. D3D9ResourceCreationPolicy mResourceCreationPolicy;
  74. long mDeviceAccessLockCount;
  75. };
  76. }