gfxResource.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GFXRESOURCE_H_
  23. #define _GFXRESOURCE_H_
  24. #ifndef _TORQUE_TYPES_H_
  25. #include "platform/types.h"
  26. #endif
  27. #ifndef _TORQUE_STRING_H_
  28. #include "core/util/str.h"
  29. #endif
  30. class GFXDevice;
  31. /// Mixin for the purpose of tracking GFX resources owned by a GFXDevice.
  32. ///
  33. /// There are many types of resource that are allocated from a GFXDevice that
  34. /// must be participatory in device resets. For instance, all default pool
  35. /// DirectX resources have to be involved when the device resets. Render
  36. /// targets in all APIs need to unbind themselves when resets happen.
  37. ///
  38. /// This system is also handy for accounting purposes. For instance, we may
  39. /// want to traverse all registered VBs, IBs, Textures, or RTs in order to
  40. /// determine what, if any, items are still allocated. This can be used in
  41. /// leak reports, memory usage reports, etc.
  42. class GFXResource
  43. {
  44. private:
  45. friend class GFXDevice;
  46. GFXResource *mPrevResource;
  47. GFXResource *mNextResource;
  48. GFXDevice *mOwningDevice;
  49. /// Helper flag to check new resource allocations
  50. bool mFlagged;
  51. public:
  52. GFXResource();
  53. virtual ~GFXResource();
  54. /// Registers this resource with the given device
  55. void registerResourceWithDevice(GFXDevice *device);
  56. /// When called the resource should destroy all device sensitive information (e.g. D3D resources in D3DPOOL_DEFAULT
  57. virtual void zombify()=0;
  58. /// When called the resource should restore all device sensitive information destroyed by zombify()
  59. virtual void resurrect()=0;
  60. /// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer
  61. virtual const String describeSelf() const = 0;
  62. inline GFXResource *getNextResource() const
  63. {
  64. return mNextResource;
  65. }
  66. inline GFXResource *getPrevResource() const
  67. {
  68. return mPrevResource;
  69. }
  70. inline GFXDevice *getOwningDevice() const
  71. {
  72. return mOwningDevice;
  73. }
  74. inline bool isFlagged()
  75. {
  76. return mFlagged;
  77. }
  78. inline void setFlag()
  79. {
  80. mFlagged = true;
  81. }
  82. inline void clearFlag()
  83. {
  84. mFlagged = false;
  85. }
  86. };
  87. #endif