CmD3D9ResourceManager.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __D3D9ResourceManager_H__
  25. #define __D3D9ResourceManager_H__
  26. #include "CmD3D9Prerequisites.h"
  27. namespace CamelotFramework {
  28. enum D3D9ResourceCreationPolicy
  29. {
  30. // Creates the rendering resource on the current active device that needs it.
  31. // This policy should be used when video memory consumption should be minimized but
  32. // it might cause some performance issues when using loader resource thread since
  33. // a resource that was not created on specified device will be created on demand during
  34. // the rendering process and might cause the FPS to drop down.
  35. RCP_CREATE_ON_ACTIVE_DEVICE,
  36. // Create the rendering resource on every existing device.
  37. // This policy should be used when working intensively with a background loader thread.
  38. // In that case when multiple devices exist, the resource will be created on each device
  39. // and will be ready to use in the core thread.
  40. // The draw back can be some video memory waste in case that each device render different
  41. // scene and doesn't really need all the resources.
  42. RCP_CREATE_ON_ALL_DEVICES
  43. };
  44. class CM_D3D9_EXPORT D3D9ResourceManager
  45. {
  46. // Interface.
  47. public:
  48. // Called immediately after the Direct3D device has been created.
  49. void notifyOnDeviceCreate (IDirect3DDevice9* d3d9Device);
  50. // Called before the Direct3D device is going to be destroyed.
  51. void notifyOnDeviceDestroy (IDirect3DDevice9* d3d9Device);
  52. // Called immediately after the Direct3D device has entered a lost state.
  53. void notifyOnDeviceLost (IDirect3DDevice9* d3d9Device);
  54. // Called immediately after the Direct3D device has been reset.
  55. void notifyOnDeviceReset (IDirect3DDevice9* d3d9Device);
  56. // Called when device state is changing. Access to any device should be locked.
  57. // Relevant for multi thread application.
  58. void lockDeviceAccess ();
  59. // Called when device state change completed. Access to any device is allowed.
  60. // Relevant for multi thread application.
  61. void unlockDeviceAccess ();
  62. // Called when new resource created.
  63. void _notifyResourceCreated (D3D9Resource* pResource);
  64. // Called when resource is about to be destroyed.
  65. void _notifyResourceDestroyed (D3D9Resource* pResource);
  66. D3D9ResourceManager ();
  67. ~D3D9ResourceManager ();
  68. void setCreationPolicy (D3D9ResourceCreationPolicy creationPolicy);
  69. D3D9ResourceCreationPolicy getCreationPolicy () const;
  70. // Friends.
  71. protected:
  72. friend class D3D9Resource;
  73. // Types.
  74. protected:
  75. typedef Vector<D3D9Resource*>::type ResourceContainer;
  76. typedef ResourceContainer::iterator ResourceContainerIterator;
  77. // Attributes.
  78. protected:
  79. CM_MUTEX(mResourcesMutex)
  80. ResourceContainer mResources;
  81. D3D9ResourceCreationPolicy mResourceCreationPolicy;
  82. long mDeviceAccessLockCount;
  83. };
  84. }
  85. #endif