BsD3D9ResourceManager.h 2.5 KB

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