Assembler.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 "AssemblerBase.hpp"
  23. #include "../MeshBuffer.hpp"
  24. #include "math/CCMath.h"
  25. #include "../../renderer/Effect.h"
  26. #include "RenderDataList.hpp"
  27. #include "../../renderer/EffectVariant.hpp"
  28. namespace se {
  29. class Object;
  30. class HandleObject;
  31. }
  32. RENDERER_BEGIN
  33. class NodeProxy;
  34. class ModelBatcher;
  35. /**
  36. * @addtogroup scene
  37. * @{
  38. */
  39. class Assembler : public AssemblerBase
  40. {
  41. public:
  42. class IARenderData {
  43. public:
  44. IARenderData();
  45. IARenderData(const IARenderData& o);
  46. ~IARenderData();
  47. void setEffect(EffectVariant* effect);
  48. EffectVariant* getEffect() const;
  49. private:
  50. EffectVariant* _effect = nullptr;
  51. public:
  52. int meshIndex = -1;
  53. int verticesStart = 0;
  54. int verticesCount = -1;
  55. int indicesStart = 0;
  56. int indicesCount = -1;
  57. };
  58. Assembler();
  59. virtual ~Assembler();
  60. /*
  61. * @brief Commit the current render handle to ModelBatcher
  62. */
  63. virtual void handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override;
  64. /*
  65. * @brief Do nothing
  66. */
  67. virtual void postHandle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override {}
  68. /*
  69. * @brief before fill buffers handle
  70. */
  71. virtual void beforeFillBuffers(std::size_t index) {}
  72. /*
  73. * @brief Fills render data in given index to the MeshBuffer
  74. * @param[in] buffer The shared mesh buffer
  75. * @param[in] index The index of render data to be updated
  76. * @param[in] node
  77. */
  78. virtual void fillBuffers(NodeProxy* node, ModelBatcher* batcher, std::size_t index);
  79. /**
  80. * @brief Sets IArenderDataList
  81. */
  82. virtual void setRenderDataList(RenderDataList* datas);
  83. /**
  84. * @brief Gets the vertex format.
  85. */
  86. VertexFormat* getVertexFormat() const { return _vfmt; };
  87. /**
  88. * @brief Sets the vertex format.
  89. */
  90. virtual void setVertexFormat(VertexFormat* vfmt);
  91. /*
  92. * @brief Update local render buffer opacity
  93. * @param[in] index The index of render data to be updated
  94. * @param[in] opacity Inherit opacity
  95. */
  96. virtual void updateOpacity(std::size_t index, uint8_t opacity);
  97. /**
  98. * @brief ignore opacity flag, it will always not update vertices opacity
  99. */
  100. void ignoreOpacityFlag() { _ignoreOpacityFlag = true; }
  101. /**
  102. * @brief Is ignore opacity.
  103. * @return _ignoreOpacityFlag
  104. */
  105. bool isIgnoreOpacityFlag() { return _ignoreOpacityFlag; }
  106. /**
  107. * @brief Enable ignore world matrix.
  108. */
  109. void ignoreWorldMatrix() { _ignoreWorldMatrix = true; }
  110. /**
  111. * @brief Is ignore world matrix.
  112. * @return _opacityAlwaysDirty
  113. */
  114. bool isIgnoreWorldMatrix() { return _ignoreWorldMatrix; }
  115. /**
  116. * @brief Updates mesh index
  117. */
  118. void updateMeshIndex(std::size_t iaIndex, int meshIndex);
  119. /**
  120. * @brief Updates indices range
  121. */
  122. void updateIndicesRange(std::size_t iaIndex, int start, int count);
  123. /**
  124. * @brief Updates vertices range
  125. */
  126. void updateVerticesRange(std::size_t iaIndex, int start, int count);
  127. /**
  128. * @brief Update the material for the given index.
  129. * @param[in] iaIndex Render data index.
  130. * @param[in] effect Effect pointer.
  131. */
  132. virtual void updateEffect(std::size_t iaIndex, EffectVariant* effect);
  133. /**
  134. * @brief Resets ia data.
  135. */
  136. virtual void reset() override;
  137. /**
  138. * @brief Gets the material for the given index.
  139. * @param[in] index Render data index.
  140. * @return Effect pointer.
  141. */
  142. inline EffectVariant* getEffect(std::size_t index) const
  143. {
  144. if (index >= _iaDatas.size())
  145. {
  146. return nullptr;
  147. }
  148. return _iaDatas[index].getEffect();
  149. }
  150. /**
  151. * @brief Gets Effect count.
  152. * @return Count.
  153. */
  154. inline std::size_t getIACount() const
  155. {
  156. return _iaDatas.size();
  157. }
  158. protected:
  159. RenderDataList* _datas = nullptr;
  160. std::vector<IARenderData> _iaDatas;
  161. uint32_t _bytesPerVertex = 0;
  162. size_t _posOffset = 0;
  163. size_t _alphaOffset = 0;
  164. VertexFormat* _vfmt = nullptr;
  165. const VertexFormat::Element* _vfPos = nullptr;
  166. const VertexFormat::Element* _vfColor = nullptr;
  167. bool _ignoreWorldMatrix = false;
  168. bool _ignoreOpacityFlag = false;
  169. };
  170. // end of scene group
  171. /// @}
  172. RENDERER_END