CCPrimitive.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 __CC_PRIMITIVE_H__
  22. #define __CC_PRIMITIVE_H__
  23. #include "renderer/CCVertexIndexData.h"
  24. /**
  25. * @addtogroup renderer
  26. * @{
  27. */
  28. NS_CC_BEGIN
  29. class IndexBuffer;
  30. /**
  31. Primitive can support sending points, lines and triangles to glpipeline, which is an abstraction
  32. of primitive data.
  33. */
  34. class CC_DLL Primitive : public Ref
  35. {
  36. public:
  37. /**
  38. Create an instance of primitive.
  39. @param verts VertexData used in the primitive.
  40. @param indices Optional index data.
  41. @param type The type (Points, Lines, Triangles) used.
  42. */
  43. static Primitive* create(VertexData* verts, IndexBuffer* indices, int type);
  44. /**Get the vertexData.*/
  45. const VertexData* getVertexData() const;
  46. /**Get the optional index data, will return null if index data is not used.*/
  47. const IndexBuffer* getIndexData() const;
  48. /**Get the primitive type.*/
  49. int getType() const { return _type; }
  50. /**called by rendering framework, will send the data to GLPipeline.*/
  51. void draw();
  52. /**Get the start index of primitive.*/
  53. int getStart() const { return _start; }
  54. /**Get the number of vertices or indices used for drawing.*/
  55. int getCount() const { return _count; }
  56. /**Setter for the start index.*/
  57. void setStart(int start);
  58. /**Setter for the count. */
  59. void setCount(int count);
  60. protected:
  61. Primitive();
  62. virtual ~Primitive();
  63. bool init(VertexData* verts, IndexBuffer* indices, int type);
  64. protected:
  65. VertexData* _verts;
  66. IndexBuffer* _indices;
  67. int _start;
  68. int _count;
  69. int _type;
  70. };
  71. NS_CC_END
  72. /**
  73. end of support group
  74. @}
  75. */
  76. #endif //__CC_PRIMITIVE_H__