gfxFence.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 _GFXFENCE_H_
  23. #define _GFXFENCE_H_
  24. #ifndef _GFXDEVICE_H_
  25. #include "gfx/gfxDevice.h"
  26. #endif
  27. ///
  28. class GFXFence : public GFXResource
  29. {
  30. protected:
  31. GFXDevice *mDevice;
  32. public:
  33. /// The states returned by getStatus()
  34. enum FenceStatus
  35. {
  36. Unset, ///< The fence has not been set
  37. Pending, ///< The fence has been set and has not been hit
  38. Processed, ///< The fence has been processed
  39. Unsupported ///< A non-blocking query of fence status is not supported by the implementation
  40. };
  41. public:
  42. GFXFence( GFXDevice *device ) : mDevice( device ) {};
  43. virtual ~GFXFence(){};
  44. /// This method inserts the fence into the command buffer
  45. virtual void issue() = 0;
  46. // CodeReview: Do we need a remove() [5/10/2007 Pat]
  47. /// This is a non-blocking call to get the status of the fence
  48. /// @see GFXFence::FenceStatus
  49. virtual FenceStatus getStatus() const = 0;
  50. /// This method will not return until the fence has been processed by the GPU
  51. virtual void block() = 0;
  52. };
  53. ///
  54. class GFXGeneralFence : public GFXFence
  55. {
  56. protected:
  57. bool mInitialized;
  58. GFXTextureTargetRef mRenderTarget;
  59. GFXTexHandle mRTTexHandle;
  60. GFXStateBlockRef mRenderSB;
  61. void _init();
  62. /// The callback used to get texture events.
  63. /// @see GFXTextureManager::addEventDelegate
  64. void _onTextureEvent( GFXTexCallbackCode code );
  65. public:
  66. GFXGeneralFence( GFXDevice *device )
  67. : GFXFence( device ),
  68. mInitialized( false )
  69. {
  70. }
  71. virtual ~GFXGeneralFence();
  72. virtual void issue();
  73. virtual FenceStatus getStatus() const { return GFXFence::Unsupported; };
  74. virtual void block();
  75. // GFXResource interface
  76. virtual void zombify();
  77. virtual void resurrect();
  78. /// The resource should put a description of itself (number of vertices, size/width of texture, etc.) in buffer
  79. virtual const String describeSelf() const;
  80. };
  81. #endif // _GFXFENCE_H_