2012-11-09 12:08:18 +08:00
|
|
|
/* Copyright (c) 2012 Scott Lembcke and Howling Moon Software
|
|
|
|
* Copyright (c) 2012 cocos2d-x.org
|
2014-01-07 11:25:07 +08:00
|
|
|
* Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2012-11-09 12:08:18 +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:
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code copied & pasted from SpacePatrol game https://github.com/slembcke/SpacePatrol
|
|
|
|
*
|
|
|
|
* Renamed and added some changes for cocos2d
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CCDRAWNODES_CCDRAW_NODE_H__
|
|
|
|
#define __CCDRAWNODES_CCDRAW_NODE_H__
|
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCNode.h"
|
2012-11-09 12:08:18 +08:00
|
|
|
#include "ccTypes.h"
|
2013-12-26 21:19:12 +08:00
|
|
|
#include "renderer/CCCustomCommand.h"
|
2012-11-09 12:08:18 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** DrawNode
|
2012-11-09 12:08:18 +08:00
|
|
|
Node that draws dots, segments and polygons.
|
|
|
|
Faster than the "drawing primitives" since they it draws everything in one single batch.
|
|
|
|
|
|
|
|
@since v2.1
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL DrawNode : public Node
|
2012-11-09 12:08:18 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 07:56:19 +08:00
|
|
|
/** creates and initialize a DrawNode node */
|
2013-06-20 14:13:12 +08:00
|
|
|
static DrawNode* create();
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2012-11-09 12:08:18 +08:00
|
|
|
/** draw a dot at a position, with a given radius and color */
|
2013-07-05 16:49:22 +08:00
|
|
|
void drawDot(const Point &pos, float radius, const Color4F &color);
|
2012-11-09 12:08:18 +08:00
|
|
|
|
|
|
|
/** draw a segment with a radius and color */
|
2013-07-05 16:49:22 +08:00
|
|
|
void drawSegment(const Point &from, const Point &to, float radius, const Color4F &color);
|
2012-11-09 12:08:18 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** draw a polygon with a fill color and line color
|
|
|
|
* @code
|
|
|
|
* When this function bound into js or lua,the parameter will be changed
|
|
|
|
* In js: var drawPolygon(var Arrayofpoints, var fillColor, var width, var borderColor)
|
|
|
|
* In lua:local drawPolygon(local pointTable,local tableCount,local fillColor,local width,local borderColor)
|
|
|
|
* @endcode
|
|
|
|
*/
|
2013-12-05 17:19:01 +08:00
|
|
|
void drawPolygon(Point *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
|
2012-11-09 12:08:18 +08:00
|
|
|
|
|
|
|
/** Clear the geometry in the node's buffer. */
|
|
|
|
void clear();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
const BlendFunc& getBlendFunc() const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @code
|
|
|
|
* When this function bound into js or lua,the parameter will be changed
|
|
|
|
* In js: var setBlendFunc(var src, var dst)
|
|
|
|
* @endcode
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
void setBlendFunc(const BlendFunc &blendFunc);
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2013-12-19 03:43:45 +08:00
|
|
|
void onDraw();
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
|
|
|
virtual void draw() override;
|
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
protected:
|
2013-11-15 08:21:49 +08:00
|
|
|
DrawNode();
|
|
|
|
virtual ~DrawNode();
|
|
|
|
virtual bool init();
|
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
void ensureCapacity(int count);
|
2012-11-09 12:08:18 +08:00
|
|
|
void render();
|
2013-07-18 07:56:19 +08:00
|
|
|
|
|
|
|
GLuint _vao;
|
|
|
|
GLuint _vbo;
|
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
int _bufferCapacity;
|
2013-07-20 13:01:27 +08:00
|
|
|
GLsizei _bufferCount;
|
|
|
|
V2F_C4B_T2F *_buffer;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
BlendFunc _blendFunc;
|
2013-12-26 21:19:12 +08:00
|
|
|
CustomCommand _customCommand;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
bool _dirty;
|
2013-11-15 08:21:49 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(DrawNode);
|
2012-11-09 12:08:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // __CCDRAWNODES_CCDRAW_NODE_H__
|