AssemblerBase.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /****************************************************************************
  2. Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos2d-x.org
  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 deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #pragma once
  21. #include "../../Macro.h"
  22. #include <stdint.h>
  23. #include "base/CCVector.h"
  24. #include "../../renderer/Effect.h"
  25. #include "scripting/js-bindings/jswrapper/Object.hpp"
  26. #include "math/Mat4.h"
  27. RENDERER_BEGIN
  28. class NodeProxy;
  29. class ModelBatcher;
  30. class Scene;
  31. /**
  32. * @addtogroup scene
  33. * @{
  34. */
  35. /**
  36. * @brief Base class for all assembler
  37. * A assembler could take actions during node visit process, before and after all children visit.
  38. */
  39. class AssemblerBase: public cocos2d::Ref
  40. {
  41. public:
  42. enum AssemblerFlag {
  43. VERTICES_OPACITY_CHANGED = 1 << 0,
  44. VERTICES_DIRTY = 1 << 1,
  45. };
  46. AssemblerBase();
  47. virtual ~AssemblerBase();
  48. /**
  49. * @brief Callback which will be invoked before visiting child nodes.
  50. * @param[in] node The node being processed.
  51. * @param[in] batcher
  52. * @param[in] scene
  53. */
  54. virtual void handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) {}
  55. /**
  56. * @brief Callback which will be invoked after visiting child nodes.
  57. * @param[in] node The node being processed.
  58. * @param[in] batcher
  59. * @param[in] scene
  60. */
  61. virtual void postHandle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) {}
  62. /**
  63. * @brief Gets whether the current handle should use model matrix uniform during rendering
  64. */
  65. bool getUseModel() const
  66. {
  67. return _useModel;
  68. }
  69. /**
  70. * @brief Sets whether the current handle should use model matrix uniform during rendering
  71. */
  72. void setUseModel(bool useModel)
  73. {
  74. _useModel = useModel;
  75. }
  76. /**
  77. * @brief Gets custom world matrix
  78. */
  79. const cocos2d::Mat4* getCustomWorldMatrix() const
  80. {
  81. return _worldMatrix;
  82. }
  83. /**
  84. * @brief Sets custom world matrix
  85. */
  86. void setCustomWorldMatrix(const cocos2d::Mat4& matrix)
  87. {
  88. if (!_worldMatrix)
  89. {
  90. _worldMatrix = new cocos2d::Mat4();
  91. }
  92. *_worldMatrix = matrix;
  93. }
  94. /**
  95. * @brief Clear custom world matrix
  96. */
  97. void clearCustomWorldMatirx()
  98. {
  99. if (_worldMatrix)
  100. {
  101. delete _worldMatrix;
  102. _worldMatrix = nullptr;
  103. }
  104. }
  105. /**
  106. * @brief Sync script dirty flag.
  107. */
  108. void setDirty(se_object_ptr jsDirty);
  109. /**
  110. * @brief Changes dirty flag.
  111. */
  112. void enableDirty(uint32_t flag)
  113. {
  114. if (_dirty)
  115. {
  116. *_dirty |= flag;
  117. }
  118. }
  119. /**
  120. * @brief Changes dirty flag.
  121. */
  122. void disableDirty(uint32_t flag)
  123. {
  124. if (_dirty)
  125. {
  126. *_dirty &= ~flag;
  127. }
  128. }
  129. /**
  130. * @brief Is flag dirty.
  131. */
  132. bool isDirty(uint32_t flag)
  133. {
  134. if (_dirty)
  135. {
  136. return *_dirty & flag;
  137. }
  138. return false;
  139. }
  140. /**
  141. * @brief Resets data.
  142. */
  143. virtual void reset() {}
  144. protected:
  145. se::Object* _jsDirty = nullptr;
  146. uint32_t* _dirty = nullptr;
  147. std::size_t _dirtyLen = 0;
  148. bool _useModel = false;
  149. cocos2d::Mat4* _worldMatrix = nullptr;
  150. };
  151. // end of scene group
  152. /// @}
  153. RENDERER_END