renderPassStateToken.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #include "renderInstance/renderPassStateToken.h"
  23. #include "console/consoleTypes.h"
  24. #include "console/engineAPI.h"
  25. IMPLEMENT_CONOBJECT(RenderPassStateToken);
  26. ConsoleDocClass( RenderPassStateToken,
  27. "@brief Abstract base class for RenderFormatToken, used to manipulate what goes on in the render manager\n\n"
  28. "You cannot actually instantiate RenderPassToken, only its child: RenderFormatToken. "
  29. "RenderFormatToken is an implementation which changes the format of the "
  30. "back buffer and/or the depth buffer.\n\n"
  31. "The RenderPassStateBin manager changes the rendering state associated with "
  32. "a token it is declared with. In stock Torque 3D, a single example exists in the "
  33. "way of AL_FormatToken (found in renderManager." TORQUE_SCRIPT_EXTENSION "). In that script file, all the "
  34. "render managers are intialized, and a single RenderFormatToken is used. This "
  35. "implementation basically exists to ensure Advanced Lighting works with MSAA.\n\n"
  36. "@see RenderFormatToken\n"
  37. "@see RenderPassStateBin\n"
  38. "@see game/core/scripts/client/renderManager." TORQUE_SCRIPT_EXTENSION "\n"
  39. "@ingroup RenderBin\n"
  40. );
  41. void RenderPassStateToken::process(SceneRenderState *state, RenderPassStateBin *callingBin)
  42. {
  43. TORQUE_UNUSED(state);
  44. TORQUE_UNUSED(callingBin);
  45. AssertWarn(false, "RenderPassStateToken is an abstract class, you must re-implement process()");
  46. }
  47. void RenderPassStateToken::reset()
  48. {
  49. AssertWarn(false, "RenderPassStateToken is an abstract class, you must re-implement reset()");
  50. }
  51. void RenderPassStateToken::enable( bool enabled /*= true*/ )
  52. {
  53. TORQUE_UNUSED(enabled);
  54. AssertWarn(false, "RenderPassStateToken is an abstract class, you must re-implement enable()");
  55. }
  56. bool RenderPassStateToken::isEnabled() const
  57. {
  58. AssertWarn(false, "RenderPassStateToken is an abstract class, you must re-implement isEnabled()");
  59. return false;
  60. }
  61. static bool _set_enable( void *object, const char *index, const char *data )
  62. {
  63. reinterpret_cast<RenderPassStateToken *>(object)->enable(dAtob(data));
  64. return false;
  65. }
  66. static const char *_get_enable(void* obj, const char* data)
  67. {
  68. TORQUE_UNUSED(data);
  69. return reinterpret_cast<RenderPassStateToken *>(obj)->isEnabled() ? "true" : "false";
  70. }
  71. void RenderPassStateToken::initPersistFields()
  72. {
  73. addProtectedField("enabled", TypeBool, 0, &_set_enable, &_get_enable, "Enables or disables this token.");
  74. Parent::initPersistFields();
  75. }
  76. //------------------------------------------------------------------------------
  77. //------------------------------------------------------------------------------
  78. IMPLEMENT_CONOBJECT(RenderPassStateBin);
  79. ConsoleDocClass( RenderPassStateBin,
  80. "@brief A non-rendering render bin used to enable/disable a RenderPassStateToken.\n\n"
  81. "This is a utility RenderBinManager which does not render any render instances. Its only "
  82. "used to define a point in the render bin order at which a RenderPassStateToken is triggered.\n\n"
  83. "@see RenderPassStateToken\n"
  84. "@ingroup RenderBin\n"
  85. );
  86. RenderPassStateBin::RenderPassStateBin()
  87. : Parent()
  88. {
  89. }
  90. RenderPassStateBin::~RenderPassStateBin()
  91. {
  92. }
  93. void RenderPassStateBin::render(SceneRenderState *state)
  94. {
  95. if(mStateToken.isValid())
  96. mStateToken->process(state, this);
  97. }
  98. void RenderPassStateBin::clear()
  99. {
  100. if(mStateToken.isValid())
  101. mStateToken->reset();
  102. }
  103. void RenderPassStateBin::sort()
  104. {
  105. }
  106. void RenderPassStateBin::initPersistFields()
  107. {
  108. addProtectedField( "stateToken", TYPEID< RenderPassStateToken >(), Offset( mStateToken, RenderPassStateBin ),
  109. _setStateToken, _getStateToken, "");
  110. Parent::initPersistFields();
  111. }
  112. //------------------------------------------------------------------------------
  113. DefineEngineMethod(RenderPassStateToken, enable, void, (),,
  114. "@brief Enables the token." )
  115. {
  116. object->enable(true);
  117. }
  118. DefineEngineMethod(RenderPassStateToken, disable, void, (),,
  119. "@brief Disables the token.")
  120. {
  121. object->enable(false);
  122. }
  123. DefineEngineMethod(RenderPassStateToken, toggle, void, (),,
  124. "@brief Toggles the token from enabled to disabled or vice versa." )
  125. {
  126. object->enable(!object->isEnabled());
  127. }