1
0

CCMeshVertexIndexData.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /****************************************************************************
  2. Copyright (c) 2014-2017 Chukong Technologies Inc.
  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. #ifndef __CCMESHVERTEXINDEXDATA_H__
  21. #define __CCMESHVERTEXINDEXDATA_H__
  22. #include <string>
  23. #include <vector>
  24. #include "3d/CCBundle3DData.h"
  25. #include "3d/CCAABB.h"
  26. #include "base/CCRef.h"
  27. #include "base/CCVector.h"
  28. #include "math/CCMath.h"
  29. #include "renderer/CCGLProgram.h"
  30. #include "renderer/CCVertexIndexData.h"
  31. #include "renderer/CCVertexIndexBuffer.h"
  32. NS_CC_BEGIN
  33. /**
  34. * @addtogroup _3d
  35. * @{
  36. */
  37. class MeshVertexData;
  38. /**
  39. * the MeshIndexData class.
  40. * @brief the MeshIndexData contain all of the indices data which mesh need.
  41. * @js NA
  42. * @lua NA
  43. */
  44. class CC_DLL MeshIndexData : public Ref
  45. {
  46. public:
  47. /** create */
  48. static MeshIndexData* create(const std::string& id, MeshVertexData* vertexData, IndexBuffer* indexbuffer, const AABB& aabb);
  49. /**get index buffer*/
  50. const IndexBuffer* getIndexBuffer() const { return _indexBuffer; }
  51. /**get vertex buffer*/
  52. const VertexBuffer* getVertexBuffer() const;
  53. /**get vertex data*/
  54. const MeshVertexData* getMeshVertexData() const { return _vertexData; }
  55. /** aabb getter and setter */
  56. void setAABB(const AABB& aabb) { _aabb = aabb; }
  57. const AABB& getAABB() const { return _aabb; }
  58. /** id setter and getter */
  59. void setId(const std::string& id) { _id = id; }
  60. const std::string& getId() const { return _id; }
  61. /**primitive type setter & getter*/
  62. GLenum getPrimitiveType() const { return _primitiveType; }
  63. void setPrimitiveType(GLenum primitive) { _primitiveType = primitive; }
  64. CC_CONSTRUCTOR_ACCESS:
  65. MeshIndexData();
  66. virtual ~MeshIndexData();
  67. protected:
  68. IndexBuffer* _indexBuffer; //index buffer
  69. MeshVertexData* _vertexData; //vertex buffer, weak ref
  70. AABB _aabb; // original aabb of the submesh
  71. std::string _id; //id
  72. GLenum _primitiveType;
  73. friend class MeshVertexData;
  74. friend class Sprite3D;
  75. };
  76. /**
  77. * the MeshVertexData class.
  78. * @brief the MeshIndexData contain all of the vertices data which mesh need.
  79. */
  80. class CC_DLL MeshVertexData : public Ref
  81. {
  82. friend class Sprite3D;
  83. friend class Mesh;
  84. public:
  85. /**create*/
  86. static MeshVertexData* create(const MeshData& meshdata);
  87. /** get vertexbuffer */
  88. const VertexBuffer* getVertexBuffer() const { return _vertexBuffer; }
  89. /** get attributes count */
  90. ssize_t getMeshVertexAttribCount() const { return _attribs.size(); }
  91. /** get attribute by index */
  92. const MeshVertexAttrib& getMeshVertexAttrib(ssize_t index) const { return _attribs[index]; }
  93. /** get index data count */
  94. ssize_t getMeshIndexDataCount() const { return _indexs.size(); }
  95. /** get index data by index */
  96. MeshIndexData* getMeshIndexDataByIndex(int index) const { return _indexs.at(index); }
  97. /** get index data by id */
  98. MeshIndexData* getMeshIndexDataById(const std::string& id) const;
  99. /**has vertex attribute?*/
  100. bool hasVertexAttrib(int attrib) const;
  101. CC_CONSTRUCTOR_ACCESS:
  102. MeshVertexData();
  103. virtual ~MeshVertexData();
  104. protected:
  105. VertexData* _vertexData; //mesh vertex data
  106. VertexBuffer* _vertexBuffer; // vertex buffer
  107. Vector<MeshIndexData*> _indexs; //index data
  108. std::vector<MeshVertexAttrib> _attribs; //vertex attributes
  109. int _vertexCount; //vertex count
  110. };
  111. // end of 3d group
  112. /// @}
  113. NS_CC_END
  114. #endif // __CCMESHVERTEXINDEXDATA_H__