CustomAssembler.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "AssemblerBase.hpp"
  22. #include <vector>
  23. #include "../../renderer/InputAssembler.h"
  24. #include "../../renderer/EffectVariant.hpp"
  25. RENDERER_BEGIN
  26. /**
  27. * @addtogroup scene
  28. * @{
  29. */
  30. /**
  31. * @brief Custom render handle base class
  32. * Render components that manages render buffer directly like spine, dragonBones should extend from this handle type.
  33. */
  34. class CustomAssembler : public AssemblerBase
  35. {
  36. public:
  37. CustomAssembler();
  38. virtual ~CustomAssembler();
  39. /**
  40. * @brief Updates InputAssembler indices range
  41. * @param[in] index InputAssembler index.
  42. * @param[in] start Indices buffer start pos
  43. * @param[in] count Indices count
  44. */
  45. virtual void updateIARange(std::size_t index, int start, int count);
  46. /**
  47. * @brief Updates InputAssembler indices and vertices buffer
  48. * @param[in] index InputAssembler index.
  49. * @param[in] vb Vertices buffer pointer
  50. * @param[in] ib Indices buffer pointer
  51. */
  52. virtual void updateIABuffer(std::size_t index, cocos2d::renderer::VertexBuffer* vb, cocos2d::renderer::IndexBuffer* ib);
  53. /**
  54. * @brief Gets input assembler by index
  55. * @param[in] index.
  56. */
  57. InputAssembler* getIA(std::size_t index) const;
  58. /**
  59. * @brief Gets input assembler count.
  60. * @return Count.
  61. */
  62. virtual inline std::size_t getIACount() const
  63. {
  64. return _iaCount;
  65. }
  66. /**
  67. * @brief Commit the current render handle to ModelBatcher
  68. */
  69. virtual void handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override;
  70. /**
  71. * @brief Do nothing
  72. */
  73. virtual void postHandle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override {}
  74. /**
  75. * @brief Resets ia data.
  76. */
  77. virtual void reset() override;
  78. /**
  79. * @brief Adjusts ia data.
  80. */
  81. virtual InputAssembler* adjustIA(std::size_t index);
  82. /**
  83. * @brief Update the material for the given index.
  84. * @param[in] index Render data index.
  85. * @param[in] effect Effect pointer.
  86. */
  87. virtual void updateEffect(std::size_t index, EffectVariant* effect);
  88. /**
  89. * @brief Gets the material for the given index.
  90. * @param[in] index Render data index.
  91. * @return Effect pointer.
  92. */
  93. inline EffectVariant* getEffect(std::size_t index) const
  94. {
  95. if (index >= _effects.size())
  96. {
  97. return nullptr;
  98. }
  99. return _effects.at(index);
  100. }
  101. /**
  102. * @brief Clears all effect.
  103. * @return Count.
  104. */
  105. virtual void clearEffect()
  106. {
  107. _effects.clear();
  108. }
  109. protected:
  110. std::vector<cocos2d::renderer::InputAssembler*> _iaPool;
  111. cocos2d::Vector<EffectVariant*> _effects;
  112. std::size_t _iaCount = 0;
  113. };
  114. // end of scene group
  115. /// @}
  116. RENDERER_END