123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- /****************************************************************************
- Copyright (c) 2014-2017 Chukong Technologies Inc.
- http://www.cocos2d-x.org
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- #ifndef __CCMESHVERTEXINDEXDATA_H__
- #define __CCMESHVERTEXINDEXDATA_H__
- #include <string>
- #include <vector>
- #include "3d/CCBundle3DData.h"
- #include "3d/CCAABB.h"
- #include "base/CCRef.h"
- #include "base/CCVector.h"
- #include "math/CCMath.h"
- #include "renderer/CCGLProgram.h"
- #include "renderer/CCVertexIndexData.h"
- #include "renderer/CCVertexIndexBuffer.h"
- NS_CC_BEGIN
- /**
- * @addtogroup _3d
- * @{
- */
- class MeshVertexData;
- /**
- * the MeshIndexData class.
- * @brief the MeshIndexData contain all of the indices data which mesh need.
- * @js NA
- * @lua NA
- */
- class CC_DLL MeshIndexData : public Ref
- {
- public:
- /** create */
- static MeshIndexData* create(const std::string& id, MeshVertexData* vertexData, IndexBuffer* indexbuffer, const AABB& aabb);
-
- /**get index buffer*/
- const IndexBuffer* getIndexBuffer() const { return _indexBuffer; }
- /**get vertex buffer*/
- const VertexBuffer* getVertexBuffer() const;
-
- /**get vertex data*/
- const MeshVertexData* getMeshVertexData() const { return _vertexData; }
-
- /** aabb getter and setter */
- void setAABB(const AABB& aabb) { _aabb = aabb; }
- const AABB& getAABB() const { return _aabb; }
-
- /** id setter and getter */
- void setId(const std::string& id) { _id = id; }
- const std::string& getId() const { return _id; }
-
- /**primitive type setter & getter*/
- GLenum getPrimitiveType() const { return _primitiveType; }
- void setPrimitiveType(GLenum primitive) { _primitiveType = primitive; }
-
- CC_CONSTRUCTOR_ACCESS:
- MeshIndexData();
- virtual ~MeshIndexData();
-
- protected:
- IndexBuffer* _indexBuffer; //index buffer
- MeshVertexData* _vertexData; //vertex buffer, weak ref
- AABB _aabb; // original aabb of the submesh
- std::string _id; //id
- GLenum _primitiveType;
-
- friend class MeshVertexData;
- friend class Sprite3D;
- };
- /**
- * the MeshVertexData class.
- * @brief the MeshIndexData contain all of the vertices data which mesh need.
- */
- class CC_DLL MeshVertexData : public Ref
- {
- friend class Sprite3D;
- friend class Mesh;
- public:
- /**create*/
- static MeshVertexData* create(const MeshData& meshdata);
-
- /** get vertexbuffer */
- const VertexBuffer* getVertexBuffer() const { return _vertexBuffer; }
-
- /** get attributes count */
- ssize_t getMeshVertexAttribCount() const { return _attribs.size(); }
-
- /** get attribute by index */
- const MeshVertexAttrib& getMeshVertexAttrib(ssize_t index) const { return _attribs[index]; }
-
- /** get index data count */
- ssize_t getMeshIndexDataCount() const { return _indexs.size(); }
- /** get index data by index */
- MeshIndexData* getMeshIndexDataByIndex(int index) const { return _indexs.at(index); }
- /** get index data by id */
- MeshIndexData* getMeshIndexDataById(const std::string& id) const;
-
- /**has vertex attribute?*/
- bool hasVertexAttrib(int attrib) const;
-
- CC_CONSTRUCTOR_ACCESS:
- MeshVertexData();
- virtual ~MeshVertexData();
- protected:
- VertexData* _vertexData; //mesh vertex data
- VertexBuffer* _vertexBuffer; // vertex buffer
- Vector<MeshIndexData*> _indexs; //index data
- std::vector<MeshVertexAttrib> _attribs; //vertex attributes
-
- int _vertexCount; //vertex count
- };
- // end of 3d group
- /// @}
- NS_CC_END
- #endif // __CCMESHVERTEXINDEXDATA_H__
|