axmol/cocos/2d/CCDrawNode.h

124 lines
4.2 KiB
C
Raw Normal View History

2012-11-09 12:08:18 +08:00
/* Copyright (c) 2012 Scott Lembcke and Howling Moon Software
* Copyright (c) 2012 cocos2d-x.org
* 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__
#include "2d/CCNode.h"
#include "2d/ccTypes.h"
#include "2d/renderer/CCCustomCommand.h"
2012-11-09 12:08:18 +08:00
NS_CC_BEGIN
/** 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
*/
class CC_DLL DrawNode : public Node
2012-11-09 12:08:18 +08:00
{
public:
/** creates and initialize a DrawNode node */
static DrawNode* create();
2012-11-09 12:08:18 +08:00
/** draw a dot at a position, with a given radius and color */
2014-04-15 18:08:29 +08:00
void drawDot(const Vector2 &pos, float radius, const Color4F &color);
2012-11-09 12:08:18 +08:00
/** draw a segment with a radius and color */
2014-04-15 18:08:29 +08:00
void drawSegment(const Vector2 &from, const Vector2 &to, float radius, const Color4F &color);
2012-11-09 12:08:18 +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
*/
2014-04-15 18:08:29 +08:00
void drawPolygon(Vector2 *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
/** draw a triangle with color */
2014-04-15 18:08:29 +08:00
void drawTriangle(const Vector2 &p1, const Vector2 &p2, const Vector2 &p3, const Color4F &color);
/** draw a cubic bezier curve with color and number of segments */
2014-04-15 18:08:29 +08:00
void drawCubicBezier(const Vector2& from, const Vector2& control1, const Vector2& control2, const Vector2& to, unsigned int segments, const Color4F &color);
/** draw a quadratic bezier curve with color and number of segments */
2014-04-15 18:08:29 +08:00
void drawQuadraticBezier(const Vector2& from, const Vector2& control, const Vector2& to, unsigned int segments, const Color4F &color);
2012-11-09 12:08:18 +08:00
/** Clear the geometry in the node's buffer. */
void clear();
/**
* @js NA
* @lua NA
*/
const BlendFunc& getBlendFunc() const;
/**
* @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
*/
void setBlendFunc(const BlendFunc &blendFunc);
void onDraw(const Matrix &transform, bool transformUpdated);
// Overrides
2014-04-08 22:07:35 +08:00
virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override;
2014-03-24 17:44:01 +08:00
CC_CONSTRUCTOR_ACCESS:
DrawNode();
virtual ~DrawNode();
virtual bool init();
2014-03-24 17:44:01 +08:00
protected:
2013-12-05 17:19:01 +08:00
void ensureCapacity(int count);
GLuint _vao;
GLuint _vbo;
2013-12-05 17:19:01 +08:00
int _bufferCapacity;
GLsizei _bufferCount;
V2F_C4B_T2F *_buffer;
BlendFunc _blendFunc;
CustomCommand _customCommand;
bool _dirty;
private:
CC_DISALLOW_COPY_AND_ASSIGN(DrawNode);
2012-11-09 12:08:18 +08:00
};
NS_CC_END
#endif // __CCDRAWNODES_CCDRAW_NODE_H__