2012-11-08 17:55:25 +08:00
|
|
|
/*
|
|
|
|
* cocos2d for iPhone: http://www.cocos2d-iphone.org
|
|
|
|
* cocos2d-x: http://www.cocos2d-x.org
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Pierre-David Bélanger
|
|
|
|
* Copyright (c) 2012 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 __MISCNODE_CCCLIPPING_NODE_H__
|
|
|
|
#define __MISCNODE_CCCLIPPING_NODE_H__
|
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCNode.h"
|
2012-11-08 17:55:25 +08:00
|
|
|
#include "CCGL.h"
|
2013-12-26 18:11:23 +08:00
|
|
|
#include "renderer/CCGroupCommand.h"
|
2012-11-08 17:55:25 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** ClippingNode is a subclass of Node.
|
2012-11-08 17:55:25 +08:00
|
|
|
It draws its content (childs) clipped using a stencil.
|
2013-06-20 14:13:12 +08:00
|
|
|
The stencil is an other Node that will not be drawn.
|
2012-11-08 17:55:25 +08:00
|
|
|
The clipping is done using the alpha part of the stencil (adjusted with an alphaThreshold).
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL ClippingNode : public Node
|
2012-11-08 17:55:25 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Creates and initializes a clipping node without a stencil.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static ClippingNode* create();
|
2012-11-08 17:55:25 +08:00
|
|
|
|
|
|
|
/** Creates and initializes a clipping node with an other node as its stencil.
|
|
|
|
The stencil node will be retained.
|
|
|
|
*/
|
2013-12-18 17:47:20 +08:00
|
|
|
static ClippingNode* create(Node *stencil);
|
2013-11-15 08:33:43 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** The Node to use as a stencil to do the clipping.
|
2012-11-08 17:55:25 +08:00
|
|
|
The stencil node will be retained.
|
|
|
|
This default to nil.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
Node* getStencil() const;
|
2013-12-18 17:47:20 +08:00
|
|
|
void setStencil(Node *stencil);
|
2012-11-08 17:55:25 +08:00
|
|
|
|
|
|
|
/** The alpha threshold.
|
|
|
|
The content is drawn only where the stencil have pixel with alpha greater than the alphaThreshold.
|
|
|
|
Should be a float between 0 and 1.
|
|
|
|
This default to 1 (so alpha test is disabled).
|
|
|
|
*/
|
2012-11-09 12:08:18 +08:00
|
|
|
GLfloat getAlphaThreshold() const;
|
2013-12-18 17:47:20 +08:00
|
|
|
void setAlphaThreshold(GLfloat alphaThreshold);
|
2012-11-08 17:55:25 +08:00
|
|
|
|
2013-08-01 16:39:42 +08:00
|
|
|
/** Inverted. If this is set to true,
|
2012-11-08 17:55:25 +08:00
|
|
|
the stencil is inverted, so the content is drawn where the stencil is NOT drawn.
|
2013-08-01 16:39:42 +08:00
|
|
|
This default to false.
|
2012-11-08 17:55:25 +08:00
|
|
|
*/
|
2012-11-09 12:08:18 +08:00
|
|
|
bool isInverted() const;
|
2013-12-18 17:47:20 +08:00
|
|
|
void setInverted(bool inverted);
|
2013-07-18 07:56:19 +08:00
|
|
|
|
|
|
|
// Overrides
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void onEnter() override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void onEnterTransitionDidFinish() override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void onExitTransitionDidStart() override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void onExit() override;
|
|
|
|
virtual void visit() override;
|
|
|
|
|
2013-11-15 08:33:43 +08:00
|
|
|
protected:
|
|
|
|
ClippingNode();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~ClippingNode();
|
|
|
|
|
|
|
|
/** Initializes a clipping node without a stencil.
|
|
|
|
*/
|
|
|
|
virtual bool init();
|
|
|
|
|
|
|
|
/** Initializes a clipping node with an other node as its stencil.
|
|
|
|
The stencil node will be retained, and its parent will be set to this clipping node.
|
|
|
|
*/
|
2013-12-18 17:47:20 +08:00
|
|
|
virtual bool init(Node *stencil);
|
2013-11-15 08:33:43 +08:00
|
|
|
|
2013-07-10 15:33:43 +08:00
|
|
|
/**draw fullscreen quad to clear stencil bits
|
|
|
|
*/
|
|
|
|
void drawFullScreenQuadClearStencil();
|
2013-07-18 07:56:19 +08:00
|
|
|
|
|
|
|
Node* _stencil;
|
|
|
|
GLfloat _alphaThreshold;
|
|
|
|
bool _inverted;
|
2013-12-24 14:08:57 +08:00
|
|
|
protected:
|
|
|
|
//renderData and callback
|
2013-12-24 14:53:49 +08:00
|
|
|
void onBeforeVisit();
|
|
|
|
void onAfterDrawStencil();
|
|
|
|
void onAfterVisit();
|
2013-12-24 14:08:57 +08:00
|
|
|
|
|
|
|
GLboolean _currentStencilEnabled;
|
|
|
|
GLuint _currentStencilWriteMask;
|
|
|
|
GLenum _currentStencilFunc;
|
|
|
|
GLint _currentStencilRef;
|
|
|
|
GLuint _currentStencilValueMask;
|
|
|
|
GLenum _currentStencilFail;
|
|
|
|
GLenum _currentStencilPassDepthFail;
|
|
|
|
GLenum _currentStencilPassDepthPass;
|
|
|
|
GLboolean _currentDepthWriteMask;
|
|
|
|
|
|
|
|
GLboolean _currentAlphaTestEnabled;
|
|
|
|
GLenum _currentAlphaTestFunc;
|
|
|
|
GLclampf _currentAlphaTestRef;
|
|
|
|
|
|
|
|
GLint _mask_layer_le;
|
2013-12-26 18:11:23 +08:00
|
|
|
|
|
|
|
GroupCommand _groupCommand;
|
2013-11-15 08:33:43 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(ClippingNode);
|
2012-11-08 17:55:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // __MISCNODE_CCCLIPPING_NODE_H__
|