renderPassStateToken.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 _RENDERPASSSTATETOKEN_H_
  23. #define _RENDERPASSSTATETOKEN_H_
  24. #ifndef _RENDERBINMANAGER_H_
  25. #include "renderInstance/renderBinManager.h"
  26. #endif
  27. class RenderPassStateBin;
  28. class RenderPassStateToken : public SimObject
  29. {
  30. typedef SimObject Parent;
  31. public:
  32. DECLARE_CONOBJECT(RenderPassStateToken);
  33. static void initPersistFields();
  34. // These must be re-implemented, and will assert if called on the base class.
  35. // They just can't be pure-virtual, due to SimObject.
  36. virtual void process(SceneRenderState *state, RenderPassStateBin *callingBin);
  37. virtual void reset();
  38. virtual void enable(bool enabled = true);
  39. virtual bool isEnabled() const;
  40. };
  41. //------------------------------------------------------------------------------
  42. class RenderPassStateBin : public RenderBinManager
  43. {
  44. typedef RenderBinManager Parent;
  45. protected:
  46. SimObjectPtr< RenderPassStateToken > mStateToken;
  47. static bool _setStateToken( void* object, const char* index, const char* data )
  48. {
  49. RenderPassStateToken* stateToken;
  50. Sim::findObject( data, stateToken );
  51. reinterpret_cast< RenderPassStateBin* >( object )->mStateToken = stateToken;
  52. return false;
  53. }
  54. static const char* _getStateToken( void* object, const char* data )
  55. {
  56. RenderPassStateBin* bin = reinterpret_cast< RenderPassStateBin* >( object );
  57. if( bin->mStateToken.isValid() )
  58. return bin->mStateToken->getIdString();
  59. else
  60. return "0";
  61. }
  62. public:
  63. DECLARE_CONOBJECT(RenderPassStateBin);
  64. static void initPersistFields();
  65. RenderPassStateBin();
  66. virtual ~RenderPassStateBin();
  67. void render(SceneRenderState *state);
  68. void clear();
  69. void sort();
  70. };
  71. #endif // _RENDERPASSSTATETOKEN_H_