2014-07-31 13:52:39 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-08-07 15:53:20 +08:00
|
|
|
|
2014-07-31 13:52:39 +08:00
|
|
|
http://www.cocos2d-x.org
|
2014-08-07 15:53:20 +08:00
|
|
|
|
2014-07-31 13:52:39 +08:00
|
|
|
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:
|
2014-08-07 15:53:20 +08:00
|
|
|
|
2014-07-31 13:52:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2014-08-07 15:53:20 +08:00
|
|
|
|
2014-07-31 13:52:39 +08:00
|
|
|
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 __CC_PRIMITIVE_H__
|
|
|
|
#define __CC_PRIMITIVE_H__
|
|
|
|
|
|
|
|
#include "renderer/CCVertexIndexData.h"
|
|
|
|
|
2015-03-27 11:54:40 +08:00
|
|
|
/**
|
2015-06-01 13:43:56 +08:00
|
|
|
* @addtogroup renderer
|
2015-03-27 11:54:40 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-07-31 13:52:39 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-08-29 15:39:52 +08:00
|
|
|
class IndexBuffer;
|
|
|
|
|
2015-03-23 21:19:02 +08:00
|
|
|
/**
|
|
|
|
Primitive can support sending points, lines and triangles to glpipeline, which is an abstraction
|
|
|
|
of primitive data.
|
|
|
|
*/
|
2014-08-12 11:56:21 +08:00
|
|
|
class CC_DLL Primitive : public Ref
|
2014-07-31 13:52:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-23 21:19:02 +08:00
|
|
|
/**
|
|
|
|
Create an instance of primitive.
|
|
|
|
@param verts VertexData used in the primitive.
|
|
|
|
@param indices Optional index data.
|
|
|
|
@param type The type (Points, Lines, Triangles) used.
|
|
|
|
*/
|
2014-08-05 17:49:35 +08:00
|
|
|
static Primitive* create(VertexData* verts, IndexBuffer* indices, int type);
|
2015-03-23 21:19:02 +08:00
|
|
|
/**Get the vertexData.*/
|
2014-08-07 17:59:36 +08:00
|
|
|
const VertexData* getVertexData() const;
|
2015-03-23 21:19:02 +08:00
|
|
|
/**Get the optional index data, will return null if index data is not used.*/
|
2014-08-07 17:59:36 +08:00
|
|
|
const IndexBuffer* getIndexData() const;
|
2015-03-23 21:19:02 +08:00
|
|
|
/**Get the primitive type.*/
|
2014-08-05 17:49:35 +08:00
|
|
|
int getType() const { return _type; }
|
2014-08-01 14:46:35 +08:00
|
|
|
|
2015-03-23 21:19:02 +08:00
|
|
|
/**called by rendering framework, will send the data to GLPipeline.*/
|
2014-08-01 14:46:35 +08:00
|
|
|
void draw();
|
2014-08-04 17:00:08 +08:00
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
/**Get the start index of primitive.*/
|
2014-08-04 17:00:08 +08:00
|
|
|
int getStart() const { return _start; }
|
2015-03-23 21:19:02 +08:00
|
|
|
/**Get the number of vertices or indices used for drawing.*/
|
2014-08-04 17:00:08 +08:00
|
|
|
int getCount() const { return _count; }
|
2015-03-23 21:19:02 +08:00
|
|
|
/**Setter for the start index.*/
|
2015-08-26 06:07:03 +08:00
|
|
|
void setStart(int start);
|
2015-03-23 21:19:02 +08:00
|
|
|
/**Setter for the count. */
|
2015-08-26 06:07:03 +08:00
|
|
|
void setCount(int count);
|
2014-08-04 17:00:08 +08:00
|
|
|
|
2014-07-31 13:52:39 +08:00
|
|
|
protected:
|
|
|
|
Primitive();
|
|
|
|
virtual ~Primitive();
|
|
|
|
|
2014-08-05 17:49:35 +08:00
|
|
|
bool init(VertexData* verts, IndexBuffer* indices, int type);
|
2014-07-31 13:52:39 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
VertexData* _verts;
|
2014-08-04 17:00:08 +08:00
|
|
|
IndexBuffer* _indices;
|
|
|
|
int _start;
|
|
|
|
int _count;
|
2014-08-05 17:49:35 +08:00
|
|
|
int _type;
|
2014-07-31 13:52:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2015-03-27 11:54:40 +08:00
|
|
|
/**
|
|
|
|
end of support group
|
|
|
|
@}
|
|
|
|
*/
|
2014-07-31 13:52:39 +08:00
|
|
|
#endif //__CC_PRIMITIVE_H__
|