BsD3D9ResourceManager.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "BsD3D9Prerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. enum D3D9ResourceCreationPolicy
  6. {
  7. // Creates the rendering resource on the current active device that needs it.
  8. // This policy should be used when video memory consumption should be minimized but
  9. // it might cause some performance issues when using loader resource thread since
  10. // a resource that was not created on specified device will be created on demand during
  11. // the rendering process and might cause the FPS to drop down.
  12. RCP_CREATE_ON_ACTIVE_DEVICE,
  13. // Create the rendering resource on every existing device.
  14. // This policy should be used when working intensively with a background loader thread.
  15. // In that case when multiple devices exist, the resource will be created on each device
  16. // and will be ready to use in the core thread.
  17. // The draw back can be some video memory waste in case that each device render different
  18. // scene and doesn't really need all the resources.
  19. RCP_CREATE_ON_ALL_DEVICES
  20. };
  21. class BS_D3D9_EXPORT D3D9ResourceManager
  22. {
  23. public:
  24. D3D9ResourceManager();
  25. ~D3D9ResourceManager();
  26. // Called immediately after the Direct3D device has been created.
  27. void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
  28. // Called before the Direct3D device is going to be destroyed.
  29. void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
  30. // Called immediately after the Direct3D device has entered a lost state.
  31. void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
  32. // Called immediately after the Direct3D device has been reset.
  33. void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
  34. // Called when device state is changing. Access to any device should be locked.
  35. // Relevant for multi thread application.
  36. void lockDeviceAccess();
  37. // Called when device state change completed. Access to any device is allowed.
  38. // Relevant for multi thread application.
  39. void unlockDeviceAccess();
  40. // Called when new resource created.
  41. void _notifyResourceCreated(D3D9Resource* pResource);
  42. // Called when resource is about to be destroyed.
  43. void _notifyResourceDestroyed(D3D9Resource* pResource);
  44. void setCreationPolicy(D3D9ResourceCreationPolicy creationPolicy);
  45. D3D9ResourceCreationPolicy getCreationPolicy() const;
  46. protected:
  47. friend class D3D9Resource;
  48. BS_MUTEX(mResourcesMutex)
  49. Vector<D3D9Resource*> mResources;
  50. D3D9ResourceCreationPolicy mResourceCreationPolicy;
  51. long mDeviceAccessLockCount;
  52. };
  53. }