CCRenderCommand.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /****************************************************************************
  2. Copyright (c) 2013-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CCRENDERCOMMAND_H_
  22. #define __CCRENDERCOMMAND_H_
  23. #include <stdint.h>
  24. #include "platform/CCPlatformMacros.h"
  25. #include "base/ccTypes.h"
  26. /**
  27. * @addtogroup renderer
  28. * @{
  29. */
  30. NS_CC_BEGIN
  31. /** Base class of the `RenderCommand` hierarchy.
  32. *
  33. The `Renderer` knows how to render `RenderCommands` objects.
  34. */
  35. class CC_DLL RenderCommand
  36. {
  37. public:
  38. /**Enum the type of render command. */
  39. enum class Type
  40. {
  41. /** Reserved type.*/
  42. UNKNOWN_COMMAND,
  43. /** Quad command, used for draw quad.*/
  44. QUAD_COMMAND,
  45. /**Custom command, used for calling callback for rendering.*/
  46. CUSTOM_COMMAND,
  47. /**Batch command, used for draw batches in texture atlas.*/
  48. BATCH_COMMAND,
  49. /**Group command, which can group command in a tree hierarchy.*/
  50. GROUP_COMMAND,
  51. /**Mesh command, used to draw 3D meshes.*/
  52. MESH_COMMAND,
  53. /**Primitive command, used to draw primitives such as lines, points and triangles.*/
  54. PRIMITIVE_COMMAND,
  55. /**Triangles command, used to draw triangles.*/
  56. TRIANGLES_COMMAND
  57. };
  58. /**
  59. Init function, will be called by all the render commands.
  60. @param globalZOrder The global order of command, used for rendercommand sorting.
  61. @param modelViewTransform Modelview matrix when submitting the render command.
  62. @param flags Flag used to indicate whether the command should be draw at 3D mode or not.
  63. */
  64. void init(float globalZOrder, const Mat4& modelViewTransform, uint32_t flags);
  65. /** Get global Z order. */
  66. float getGlobalOrder() const { return _globalOrder; }
  67. /** Returns the Command type. */
  68. Type getType() const { return _type; }
  69. /** Returns whether is transparent. */
  70. bool isTransparent() const { return _isTransparent; }
  71. /** Set transparent flag. */
  72. void setTransparent(bool isTransparent) { _isTransparent = isTransparent; }
  73. /**
  74. Get skip batching status, if a rendering is skip batching, it will be forced to be rendering separately.
  75. */
  76. bool isSkipBatching() const { return _skipBatching; }
  77. /**Set skip batching.*/
  78. void setSkipBatching(bool value) { _skipBatching = value; }
  79. /**Whether the command should be rendered at 3D mode.*/
  80. bool is3D() const { return _is3D; }
  81. /**Set the command rendered in 3D mode or not.*/
  82. void set3D(bool value) { _is3D = value; }
  83. /**Get the depth by current model view matrix.*/
  84. float getDepth() const { return _depth; }
  85. protected:
  86. /**Constructor.*/
  87. RenderCommand();
  88. /**Destructor.*/
  89. virtual ~RenderCommand();
  90. //used for debug but it is not implemented.
  91. void printID();
  92. /**Type used in order to avoid dynamic cast, faster. */
  93. Type _type;
  94. /** Commands are sort by global Z order. */
  95. float _globalOrder;
  96. /** Transparent flag. */
  97. bool _isTransparent;
  98. /**
  99. QuadCommand and TrianglesCommand could be auto batched if there material ID is the same, however, if
  100. a command is skip batching, it would be forced to draw in a separate function call, and break the batch.
  101. */
  102. bool _skipBatching;
  103. /** Is the command been rendered on 3D pass. */
  104. bool _is3D;
  105. /** Depth from the model view matrix.*/
  106. float _depth;
  107. };
  108. NS_CC_END
  109. /**
  110. end of support group
  111. @}
  112. */
  113. #endif //__CCRENDERCOMMAND_H_