mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' into data-refactor
Conflicts: tools/tolua/cocos2dx.ini
This commit is contained in:
commit
d33b2c41c7
|
@ -11,6 +11,8 @@ cocos2d-x-3.0beta0 ?? 2013
|
|||
[NEW] New renderer support.
|
||||
[FIX] Potential hash collision fix.
|
||||
[FIX] Updates spine runtime to the latest version.
|
||||
[FIX] Uses `const std::string&` instead of `const char*`.
|
||||
[FIX] LabelBMFont string can't be shown integrally.
|
||||
[Android]
|
||||
[NEW] build/android-build.sh: add supporting to generate .apk file
|
||||
[FIX] XMLHttpRequest receives wrong binary array.
|
||||
|
@ -19,6 +21,9 @@ cocos2d-x-3.0beta0 ?? 2013
|
|||
[FIX] UserDefault::getDoubleForKey() doesn't pass default value to Java.
|
||||
[Windows]
|
||||
[NEW] CMake support for windows.
|
||||
[Bindings]
|
||||
[FIX] Don't bind override functions for JSB and LuaBining since they aren't needed at all.
|
||||
[NEW] Adds spine JS binding support.
|
||||
|
||||
cocos2d-x-3.0alpha1 Nov.19 2013
|
||||
[all platforms]
|
||||
|
|
|
@ -1 +1 @@
|
|||
1df2ba5492ecdbe0c160d2429733c1371b35b21a
|
||||
fc76c8739d4c7baa28d56f632e8d4c98c5eaf85e
|
|
@ -1 +1 @@
|
|||
52a991e88e049cd371a153ee168260276a7ac664
|
||||
f36b451a97f9a0c93a4e23c417d7333f1e293993
|
|
@ -117,15 +117,10 @@ platform/CCEGLViewProtocol.cpp \
|
|||
platform/CCFileUtils.cpp \
|
||||
platform/CCSAXParser.cpp \
|
||||
platform/CCThread.cpp \
|
||||
renderer/CCNewRenderTexture.cpp \
|
||||
renderer/CCNewSprite.cpp \
|
||||
renderer/CCNewSpriteBatchNode.cpp \
|
||||
renderer/CCNewTextureAtlas.cpp \
|
||||
renderer/CCCustomCommand.cpp \
|
||||
renderer/CCFrustum.cpp \
|
||||
renderer/CCGroupCommand.cpp \
|
||||
renderer/CCMaterialManager.cpp \
|
||||
renderer/CCNewClippingNode.cpp \
|
||||
renderer/CCQuadCommand.cpp \
|
||||
renderer/CCRenderCommand.cpp \
|
||||
renderer/CCRenderer.cpp \
|
||||
|
@ -210,6 +205,7 @@ LOCAL_EXPORT_LDLIBS := -lGLESv2 \
|
|||
LOCAL_WHOLE_STATIC_LIBRARIES := cocos_freetype2_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += spine_static
|
||||
|
||||
# define the macro to compile through support/zip_support/ioapi.c
|
||||
LOCAL_CFLAGS := -Wno-psabi -DUSE_FILE32API
|
||||
|
@ -222,3 +218,4 @@ include $(BUILD_STATIC_LIBRARY)
|
|||
$(call import-module,freetype2/prebuilt/android)
|
||||
$(call import-module,chipmunk)
|
||||
$(call import-module,2d/platform/android)
|
||||
$(call import-module,editor-support/spine)
|
||||
|
|
|
@ -31,10 +31,17 @@
|
|||
#include "CCShaderCache.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCDrawingPrimitives.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
static GLint g_sStencilBits = -1;
|
||||
// store the current stencil layer (position in the stencil buffer),
|
||||
// this will allow nesting up to n ClippingNode,
|
||||
// where n is the number of bits of the stencil buffer.
|
||||
static GLint s_layer = -1;
|
||||
|
||||
static void setProgram(Node *n, GLProgram *p)
|
||||
{
|
||||
|
@ -50,7 +57,21 @@ ClippingNode::ClippingNode()
|
|||
: _stencil(nullptr)
|
||||
, _alphaThreshold(0.0f)
|
||||
, _inverted(false)
|
||||
{}
|
||||
, _currentStencilEnabled(GL_FALSE)
|
||||
, _currentStencilWriteMask(~0)
|
||||
, _currentStencilFunc(GL_ALWAYS)
|
||||
, _currentStencilRef(0)
|
||||
, _currentStencilValueMask(~0)
|
||||
, _currentStencilFail(GL_KEEP)
|
||||
, _currentStencilPassDepthFail(GL_KEEP)
|
||||
, _currentStencilPassDepthPass(GL_KEEP)
|
||||
, _currentDepthWriteMask(GL_TRUE)
|
||||
, _currentAlphaTestEnabled(GL_FALSE)
|
||||
, _currentAlphaTestFunc(GL_ALWAYS)
|
||||
, _currentAlphaTestRef(1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ClippingNode::~ClippingNode()
|
||||
{
|
||||
|
@ -179,225 +200,36 @@ void ClippingNode::drawFullScreenQuadClearStencil()
|
|||
|
||||
void ClippingNode::visit()
|
||||
{
|
||||
// if stencil buffer disabled
|
||||
if (g_sStencilBits < 1)
|
||||
{
|
||||
// draw everything, as if there where no stencil
|
||||
Node::visit();
|
||||
return;
|
||||
}
|
||||
//Add group command
|
||||
|
||||
// return fast (draw nothing, or draw everything if in inverted mode) if:
|
||||
// - nil stencil node
|
||||
// - or stencil node invisible:
|
||||
if (!_stencil || !_stencil->isVisible())
|
||||
{
|
||||
if (_inverted)
|
||||
{
|
||||
// draw everything
|
||||
Node::visit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
|
||||
// store the current stencil layer (position in the stencil buffer),
|
||||
// this will allow nesting up to n ClippingNode,
|
||||
// where n is the number of bits of the stencil buffer.
|
||||
static GLint layer = -1;
|
||||
|
||||
// all the _stencilBits are in use?
|
||||
if (layer + 1 == g_sStencilBits)
|
||||
{
|
||||
// warn once
|
||||
static bool once = true;
|
||||
if (once)
|
||||
{
|
||||
char warning[200] = {0};
|
||||
snprintf(warning, sizeof(warning), "Nesting more than %d stencils is not supported. Everything will be drawn without stencil for this node and its childs.", g_sStencilBits);
|
||||
CCLOG("%s", warning);
|
||||
|
||||
once = false;
|
||||
}
|
||||
// draw everything, as if there where no stencil
|
||||
Node::visit();
|
||||
return;
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
// INIT
|
||||
|
||||
// increment the current layer
|
||||
layer++;
|
||||
|
||||
// mask of the current layer (ie: for layer 3: 00000100)
|
||||
GLint mask_layer = 0x1 << layer;
|
||||
// mask of all layers less than the current (ie: for layer 3: 00000011)
|
||||
GLint mask_layer_l = mask_layer - 1;
|
||||
// mask of all layers less than or equal to the current (ie: for layer 3: 00000111)
|
||||
GLint mask_layer_le = mask_layer | mask_layer_l;
|
||||
|
||||
// manually save the stencil state
|
||||
GLboolean currentStencilEnabled = GL_FALSE;
|
||||
GLuint currentStencilWriteMask = ~0;
|
||||
GLenum currentStencilFunc = GL_ALWAYS;
|
||||
GLint currentStencilRef = 0;
|
||||
GLuint currentStencilValueMask = ~0;
|
||||
GLenum currentStencilFail = GL_KEEP;
|
||||
GLenum currentStencilPassDepthFail = GL_KEEP;
|
||||
GLenum currentStencilPassDepthPass = GL_KEEP;
|
||||
currentStencilEnabled = glIsEnabled(GL_STENCIL_TEST);
|
||||
glGetIntegerv(GL_STENCIL_WRITEMASK, (GLint *)¤tStencilWriteMask);
|
||||
glGetIntegerv(GL_STENCIL_FUNC, (GLint *)¤tStencilFunc);
|
||||
glGetIntegerv(GL_STENCIL_REF, ¤tStencilRef);
|
||||
glGetIntegerv(GL_STENCIL_VALUE_MASK, (GLint *)¤tStencilValueMask);
|
||||
glGetIntegerv(GL_STENCIL_FAIL, (GLint *)¤tStencilFail);
|
||||
glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, (GLint *)¤tStencilPassDepthFail);
|
||||
glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, (GLint *)¤tStencilPassDepthPass);
|
||||
|
||||
// enable stencil use
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
// check for OpenGL error while enabling stencil test
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// all bits on the stencil buffer are readonly, except the current layer bit,
|
||||
// this means that operation like glClear or glStencilOp will be masked with this value
|
||||
glStencilMask(mask_layer);
|
||||
|
||||
// manually save the depth test state
|
||||
//GLboolean currentDepthTestEnabled = GL_TRUE;
|
||||
GLboolean currentDepthWriteMask = GL_TRUE;
|
||||
//currentDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
|
||||
glGetBooleanv(GL_DEPTH_WRITEMASK, ¤tDepthWriteMask);
|
||||
|
||||
// disable depth test while drawing the stencil
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
// disable update to the depth buffer while drawing the stencil,
|
||||
// as the stencil is not meant to be rendered in the real scene,
|
||||
// it should never prevent something else to be drawn,
|
||||
// only disabling depth buffer update should do
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
///////////////////////////////////
|
||||
// CLEAR STENCIL BUFFER
|
||||
|
||||
// manually clear the stencil buffer by drawing a fullscreen rectangle on it
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel in the fullscreen rectangle
|
||||
// never draw it into the frame buffer
|
||||
// if not in inverted mode: set the current layer value to 0 in the stencil buffer
|
||||
// if in inverted mode: set the current layer value to 1 in the stencil buffer
|
||||
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
|
||||
glStencilOp(!_inverted ? GL_ZERO : GL_REPLACE, GL_KEEP, GL_KEEP);
|
||||
|
||||
// draw a fullscreen solid rectangle to clear the stencil buffer
|
||||
//ccDrawSolidRect(Point::ZERO, ccpFromSize([[Director sharedDirector] winSize]), Color4F(1, 1, 1, 1));
|
||||
drawFullScreenQuadClearStencil();
|
||||
|
||||
///////////////////////////////////
|
||||
// DRAW CLIPPING STENCIL
|
||||
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel in the stencil node
|
||||
// never draw it into the frame buffer
|
||||
// if not in inverted mode: set the current layer value to 1 in the stencil buffer
|
||||
// if in inverted mode: set the current layer value to 0 in the stencil buffer
|
||||
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
|
||||
glStencilOp(!_inverted ? GL_REPLACE : GL_ZERO, GL_KEEP, GL_KEEP);
|
||||
|
||||
// enable alpha test only if the alpha threshold < 1,
|
||||
// indeed if alpha threshold == 1, every pixel will be drawn anyways
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
GLboolean currentAlphaTestEnabled = GL_FALSE;
|
||||
GLenum currentAlphaTestFunc = GL_ALWAYS;
|
||||
GLclampf currentAlphaTestRef = 1;
|
||||
#endif
|
||||
if (_alphaThreshold < 1) {
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// manually save the alpha test state
|
||||
currentAlphaTestEnabled = glIsEnabled(GL_ALPHA_TEST);
|
||||
glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint *)¤tAlphaTestFunc);
|
||||
glGetFloatv(GL_ALPHA_TEST_REF, ¤tAlphaTestRef);
|
||||
// enable alpha testing
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
// check for OpenGL error while enabling alpha test
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
// pixel will be drawn only if greater than an alpha threshold
|
||||
glAlphaFunc(GL_GREATER, _alphaThreshold);
|
||||
#else
|
||||
// since glAlphaTest do not exists in OES, use a shader that writes
|
||||
// pixel only if greater than an alpha threshold
|
||||
GLProgram *program = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
|
||||
GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
|
||||
// set our alphaThreshold
|
||||
program->use();
|
||||
program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
|
||||
// we need to recursively apply this shader to all the nodes in the stencil node
|
||||
// XXX: we should have a way to apply shader to all nodes without having to do this
|
||||
setProgram(_stencil, program);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
// draw the stencil node as if it was one of our child
|
||||
// (according to the stencil test func/op and alpha (or alpha shader) test)
|
||||
kmGLPushMatrix();
|
||||
transform();
|
||||
if (_stencil != nullptr)
|
||||
{
|
||||
_stencil->visit();
|
||||
}
|
||||
kmGLPopMatrix();
|
||||
|
||||
// restore alpha test state
|
||||
if (_alphaThreshold < 1)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// manually restore the alpha test state
|
||||
glAlphaFunc(currentAlphaTestFunc, currentAlphaTestRef);
|
||||
if (!currentAlphaTestEnabled)
|
||||
{
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
}
|
||||
#else
|
||||
// XXX: we need to find a way to restore the shaders of the stencil node and its childs
|
||||
#endif
|
||||
}
|
||||
|
||||
// restore the depth test state
|
||||
glDepthMask(currentDepthWriteMask);
|
||||
//if (currentDepthTestEnabled) {
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
//}
|
||||
|
||||
///////////////////////////////////
|
||||
// DRAW CONTENT
|
||||
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel of this node and its childs
|
||||
// if all layers less than or equals to the current are set to 1 in the stencil buffer
|
||||
// draw the pixel and keep the current layer in the stencil buffer
|
||||
// else
|
||||
// do not draw the pixel but keep the current layer in the stencil buffer
|
||||
glStencilFunc(GL_EQUAL, mask_layer_le, mask_layer_le);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
|
||||
// draw (according to the stencil test func) this node and its childs
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0,_vertexZ);
|
||||
renderer->addCommand(groupCommand);
|
||||
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
|
||||
CustomCommand* beforeVisitCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beforeVisitCmd->init(0,_vertexZ);
|
||||
beforeVisitCmd->func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this);
|
||||
renderer->addCommand(beforeVisitCmd);
|
||||
|
||||
_stencil->visit();
|
||||
|
||||
CustomCommand* afterDrawStencilCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
afterDrawStencilCmd->init(0,_vertexZ);
|
||||
afterDrawStencilCmd->func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this);
|
||||
renderer->addCommand(afterDrawStencilCmd);
|
||||
|
||||
Node::visit();
|
||||
|
||||
///////////////////////////////////
|
||||
// CLEANUP
|
||||
|
||||
// manually restore the stencil state
|
||||
glStencilFunc(currentStencilFunc, currentStencilRef, currentStencilValueMask);
|
||||
glStencilOp(currentStencilFail, currentStencilPassDepthFail, currentStencilPassDepthPass);
|
||||
glStencilMask(currentStencilWriteMask);
|
||||
if (!currentStencilEnabled)
|
||||
{
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
// we are done using this layer, decrement
|
||||
layer--;
|
||||
|
||||
CustomCommand* afterVisitCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
afterVisitCmd->init(0,_vertexZ);
|
||||
afterVisitCmd->func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this);
|
||||
renderer->addCommand(afterVisitCmd);
|
||||
|
||||
renderer->popGroup();
|
||||
}
|
||||
|
||||
Node* ClippingNode::getStencil() const
|
||||
|
@ -432,4 +264,167 @@ void ClippingNode::setInverted(bool inverted)
|
|||
_inverted = inverted;
|
||||
}
|
||||
|
||||
void ClippingNode::onBeforeVisit()
|
||||
{
|
||||
///////////////////////////////////
|
||||
// INIT
|
||||
|
||||
// increment the current layer
|
||||
s_layer++;
|
||||
|
||||
// mask of the current layer (ie: for layer 3: 00000100)
|
||||
GLint mask_layer = 0x1 << s_layer;
|
||||
// mask of all layers less than the current (ie: for layer 3: 00000011)
|
||||
GLint mask_layer_l = mask_layer - 1;
|
||||
// mask of all layers less than or equal to the current (ie: for layer 3: 00000111)
|
||||
_mask_layer_le = mask_layer | mask_layer_l;
|
||||
|
||||
// manually save the stencil state
|
||||
|
||||
_currentStencilEnabled = glIsEnabled(GL_STENCIL_TEST);
|
||||
glGetIntegerv(GL_STENCIL_WRITEMASK, (GLint *)&_currentStencilWriteMask);
|
||||
glGetIntegerv(GL_STENCIL_FUNC, (GLint *)&_currentStencilFunc);
|
||||
glGetIntegerv(GL_STENCIL_REF, &_currentStencilRef);
|
||||
glGetIntegerv(GL_STENCIL_VALUE_MASK, (GLint *)&_currentStencilValueMask);
|
||||
glGetIntegerv(GL_STENCIL_FAIL, (GLint *)&_currentStencilFail);
|
||||
glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, (GLint *)&_currentStencilPassDepthFail);
|
||||
glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, (GLint *)&_currentStencilPassDepthPass);
|
||||
|
||||
// enable stencil use
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
// check for OpenGL error while enabling stencil test
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// all bits on the stencil buffer are readonly, except the current layer bit,
|
||||
// this means that operation like glClear or glStencilOp will be masked with this value
|
||||
glStencilMask(mask_layer);
|
||||
|
||||
// manually save the depth test state
|
||||
|
||||
glGetBooleanv(GL_DEPTH_WRITEMASK, &_currentDepthWriteMask);
|
||||
|
||||
// disable depth test while drawing the stencil
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
// disable update to the depth buffer while drawing the stencil,
|
||||
// as the stencil is not meant to be rendered in the real scene,
|
||||
// it should never prevent something else to be drawn,
|
||||
// only disabling depth buffer update should do
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
///////////////////////////////////
|
||||
// CLEAR STENCIL BUFFER
|
||||
|
||||
// manually clear the stencil buffer by drawing a fullscreen rectangle on it
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel in the fullscreen rectangle
|
||||
// never draw it into the frame buffer
|
||||
// if not in inverted mode: set the current layer value to 0 in the stencil buffer
|
||||
// if in inverted mode: set the current layer value to 1 in the stencil buffer
|
||||
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
|
||||
glStencilOp(!_inverted ? GL_ZERO : GL_REPLACE, GL_KEEP, GL_KEEP);
|
||||
|
||||
// draw a fullscreen solid rectangle to clear the stencil buffer
|
||||
//ccDrawSolidRect(Point::ZERO, ccpFromSize([[Director sharedDirector] winSize]), Color4F(1, 1, 1, 1));
|
||||
drawFullScreenQuadClearStencil();
|
||||
|
||||
///////////////////////////////////
|
||||
// DRAW CLIPPING STENCIL
|
||||
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel in the stencil node
|
||||
// never draw it into the frame buffer
|
||||
// if not in inverted mode: set the current layer value to 1 in the stencil buffer
|
||||
// if in inverted mode: set the current layer value to 0 in the stencil buffer
|
||||
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
|
||||
glStencilOp(!_inverted ? GL_REPLACE : GL_ZERO, GL_KEEP, GL_KEEP);
|
||||
|
||||
// enable alpha test only if the alpha threshold < 1,
|
||||
// indeed if alpha threshold == 1, every pixel will be drawn anyways
|
||||
if (_alphaThreshold < 1) {
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// manually save the alpha test state
|
||||
_currentAlphaTestEnabled = glIsEnabled(GL_ALPHA_TEST);
|
||||
glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint *)&_currentAlphaTestFunc);
|
||||
glGetFloatv(GL_ALPHA_TEST_REF, &_currentAlphaTestRef);
|
||||
// enable alpha testing
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
// check for OpenGL error while enabling alpha test
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
// pixel will be drawn only if greater than an alpha threshold
|
||||
glAlphaFunc(GL_GREATER, _alphaThreshold);
|
||||
#else
|
||||
// since glAlphaTest do not exists in OES, use a shader that writes
|
||||
// pixel only if greater than an alpha threshold
|
||||
GLProgram *program = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
|
||||
GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
|
||||
// set our alphaThreshold
|
||||
program->use();
|
||||
program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
|
||||
// we need to recursively apply this shader to all the nodes in the stencil node
|
||||
// XXX: we should have a way to apply shader to all nodes without having to do this
|
||||
setProgram(_stencil, program);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//Draw _stencil
|
||||
}
|
||||
|
||||
void ClippingNode::onAfterDrawStencil()
|
||||
{
|
||||
// restore alpha test state
|
||||
if (_alphaThreshold < 1)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// manually restore the alpha test state
|
||||
glAlphaFunc(_currentAlphaTestFunc, _currentAlphaTestRef);
|
||||
if (!_currentAlphaTestEnabled)
|
||||
{
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
}
|
||||
#else
|
||||
// XXX: we need to find a way to restore the shaders of the stencil node and its childs
|
||||
#endif
|
||||
}
|
||||
|
||||
// restore the depth test state
|
||||
glDepthMask(_currentDepthWriteMask);
|
||||
//if (currentDepthTestEnabled) {
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
//}
|
||||
|
||||
///////////////////////////////////
|
||||
// DRAW CONTENT
|
||||
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel of this node and its childs
|
||||
// if all layers less than or equals to the current are set to 1 in the stencil buffer
|
||||
// draw the pixel and keep the current layer in the stencil buffer
|
||||
// else
|
||||
// do not draw the pixel but keep the current layer in the stencil buffer
|
||||
glStencilFunc(GL_EQUAL, _mask_layer_le, _mask_layer_le);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
|
||||
// draw (according to the stencil test func) this node and its childs
|
||||
}
|
||||
|
||||
|
||||
void ClippingNode::onAfterVisit()
|
||||
{
|
||||
///////////////////////////////////
|
||||
// CLEANUP
|
||||
|
||||
// manually restore the stencil state
|
||||
glStencilFunc(_currentStencilFunc, _currentStencilRef, _currentStencilValueMask);
|
||||
glStencilOp(_currentStencilFail, _currentStencilPassDepthFail, _currentStencilPassDepthPass);
|
||||
glStencilMask(_currentStencilWriteMask);
|
||||
if (!_currentStencilEnabled)
|
||||
{
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
// we are done using this layer, decrement
|
||||
s_layer--;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -120,6 +120,27 @@ protected:
|
|||
Node* _stencil;
|
||||
GLfloat _alphaThreshold;
|
||||
bool _inverted;
|
||||
protected:
|
||||
//renderData and callback
|
||||
void onBeforeVisit();
|
||||
void onAfterDrawStencil();
|
||||
void onAfterVisit();
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(ClippingNode);
|
||||
|
|
|
@ -817,9 +817,6 @@ void LabelBMFont::updateLabel()
|
|||
}
|
||||
|
||||
skip += justSkipped;
|
||||
|
||||
if (!characterSprite->isVisible())
|
||||
continue;
|
||||
|
||||
if (i >= stringLength)
|
||||
break;
|
||||
|
@ -867,6 +864,8 @@ void LabelBMFont::updateLabel()
|
|||
startOfLine = startOfWord;
|
||||
start_line = true;
|
||||
}
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Whitespace.
|
||||
|
|
|
@ -33,7 +33,7 @@ Use any of these editors to generate BMFonts:
|
|||
#ifndef __CCBITMAP_FONT_ATLAS_H__
|
||||
#define __CCBITMAP_FONT_ATLAS_H__
|
||||
|
||||
#include "renderer/CCNewSpriteBatchNode.h"
|
||||
#include "CCSpriteBatchNode.h"
|
||||
#include "uthash.h"
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
|
@ -190,7 +190,7 @@ http://www.angelcode.com/products/bmfont/ (Free, Windows only)
|
|||
@since v0.8
|
||||
*/
|
||||
|
||||
class CC_DLL LabelBMFont : public NewSpriteBatchNode, public LabelProtocol
|
||||
class CC_DLL LabelBMFont : public SpriteBatchNode, public LabelProtocol
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -25,8 +25,8 @@ THE SOFTWARE.
|
|||
#ifndef __CCLABELTTF_H__
|
||||
#define __CCLABELTTF_H__
|
||||
|
||||
#include "renderer/CCNewSprite.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "CCSprite.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -54,7 +54,7 @@ NS_CC_BEGIN
|
|||
* @endcode
|
||||
*
|
||||
*/
|
||||
class CC_DLL LabelTTF : public NewSprite, public LabelProtocol
|
||||
class CC_DLL LabelTTF : public Sprite, public LabelProtocol
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -143,16 +143,6 @@ void ParticleBatchNode::visit()
|
|||
}
|
||||
|
||||
// override addChild:
|
||||
void ParticleBatchNode::addChild(Node * child)
|
||||
{
|
||||
Node::addChild(child);
|
||||
}
|
||||
|
||||
void ParticleBatchNode::addChild(Node * child, int zOrder)
|
||||
{
|
||||
Node::addChild(child, zOrder);
|
||||
}
|
||||
|
||||
void ParticleBatchNode::addChild(Node * aChild, int zOrder, int tag)
|
||||
{
|
||||
CCASSERT( aChild != nullptr, "Argument must be non-nullptr");
|
||||
|
|
|
@ -105,8 +105,8 @@ public:
|
|||
|
||||
// Overrides
|
||||
void visit();
|
||||
virtual void addChild(Node * child) override;
|
||||
virtual void addChild(Node * child, int zOrder) override;
|
||||
|
||||
using Node::addChild;
|
||||
virtual void addChild(Node * child, int zOrder, int tag) override;
|
||||
virtual void removeChild(Node* child, bool cleanup) override;
|
||||
virtual void reorderChild(Node * child, int zOrder) override;
|
||||
|
|
|
@ -37,6 +37,11 @@ THE SOFTWARE.
|
|||
#include "CCNotificationCenter.h"
|
||||
#include "CCEventType.h"
|
||||
#include "CCGrid.h"
|
||||
|
||||
#include "CCRenderer.h"
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCCustomCommand.h"
|
||||
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
||||
|
@ -296,47 +301,6 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat
|
|||
return ret;
|
||||
}
|
||||
|
||||
void RenderTexture::begin()
|
||||
{
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLPushMatrix();
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLPushMatrix();
|
||||
|
||||
Director *director = Director::getInstance();
|
||||
director->setProjection(director->getProjection());
|
||||
|
||||
const Size& texSize = _texture->getContentSizeInPixels();
|
||||
|
||||
// Calculate the adjustment ratios based on the old and new projections
|
||||
Size size = director->getWinSizeInPixels();
|
||||
float widthRatio = size.width / texSize.width;
|
||||
float heightRatio = size.height / texSize.height;
|
||||
|
||||
// Adjust the orthographic projection and viewport
|
||||
glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height);
|
||||
|
||||
|
||||
kmMat4 orthoMatrix;
|
||||
kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio,
|
||||
(float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
|
||||
kmGLMultMatrix(&orthoMatrix);
|
||||
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
|
||||
|
||||
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
|
||||
*/
|
||||
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
|
||||
{
|
||||
// -- bind a temporary texture so we can clear the render buffer without losing our texture
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0);
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTexture::beginWithClear(float r, float g, float b, float a)
|
||||
{
|
||||
beginWithClear(r, g, b, a, 0, 0, GL_COLOR_BUFFER_BIT);
|
||||
|
@ -354,61 +318,21 @@ void RenderTexture::beginWithClear(float r, float g, float b, float a, float dep
|
|||
|
||||
void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags)
|
||||
{
|
||||
setClearColor(Color4F(r, g, b, a));
|
||||
|
||||
setClearDepth(depthValue);
|
||||
|
||||
setClearStencil(stencilValue);
|
||||
|
||||
setClearFlags(flags);
|
||||
|
||||
this->begin();
|
||||
|
||||
// save clear color
|
||||
GLfloat clearColor[4] = {0.0f};
|
||||
GLfloat depthClearValue = 0.0f;
|
||||
int stencilClearValue = 0;
|
||||
|
||||
if (flags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE,clearColor);
|
||||
glClearColor(r, g, b, a);
|
||||
}
|
||||
|
||||
if (flags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthClearValue);
|
||||
glClearDepth(depthValue);
|
||||
}
|
||||
|
||||
if (flags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &stencilClearValue);
|
||||
glClearStencil(stencilValue);
|
||||
}
|
||||
|
||||
glClear(flags);
|
||||
|
||||
// restore
|
||||
if (flags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
|
||||
}
|
||||
if (flags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glClearDepth(depthClearValue);
|
||||
}
|
||||
if (flags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glClearStencil(stencilClearValue);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTexture::end()
|
||||
{
|
||||
Director *director = Director::getInstance();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO);
|
||||
|
||||
// restore viewport
|
||||
director->setViewport();
|
||||
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLPopMatrix();
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLPopMatrix();
|
||||
//clear screen
|
||||
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
clearCmd->init(0, _vertexZ);
|
||||
clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
}
|
||||
|
||||
//TODO find a better way to clear the screen, there is no need to rebind render buffer there.
|
||||
|
@ -420,16 +344,16 @@ void RenderTexture::clear(float r, float g, float b, float a)
|
|||
|
||||
void RenderTexture::clearDepth(float depthValue)
|
||||
{
|
||||
setClearDepth(depthValue);
|
||||
|
||||
this->begin();
|
||||
//! save old depth value
|
||||
GLfloat depthClearValue;
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthClearValue);
|
||||
|
||||
glClearDepth(depthValue);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(RenderTexture::onClearDepth, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
|
||||
// restore clear color
|
||||
glClearDepth(depthClearValue);
|
||||
this->end();
|
||||
}
|
||||
|
||||
|
@ -466,69 +390,6 @@ void RenderTexture::visit()
|
|||
_orderOfArrival = 0;
|
||||
}
|
||||
|
||||
void RenderTexture::draw()
|
||||
{
|
||||
if( _autoDraw)
|
||||
{
|
||||
begin();
|
||||
|
||||
if (_clearFlags)
|
||||
{
|
||||
GLfloat oldClearColor[4] = {0.0f};
|
||||
GLfloat oldDepthClearValue = 0.0f;
|
||||
GLint oldStencilClearValue = 0;
|
||||
|
||||
// backup and set
|
||||
if (_clearFlags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor);
|
||||
glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a);
|
||||
}
|
||||
|
||||
if (_clearFlags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &oldDepthClearValue);
|
||||
glClearDepth(_clearDepth);
|
||||
}
|
||||
|
||||
if (_clearFlags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &oldStencilClearValue);
|
||||
glClearStencil(_clearStencil);
|
||||
}
|
||||
|
||||
// clear
|
||||
glClear(_clearFlags);
|
||||
|
||||
// restore
|
||||
if (_clearFlags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[3]);
|
||||
}
|
||||
if (_clearFlags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glClearDepth(oldDepthClearValue);
|
||||
}
|
||||
if (_clearFlags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glClearStencil(oldStencilClearValue);
|
||||
}
|
||||
}
|
||||
|
||||
//! make sure all children are drawn
|
||||
sortAllChildren();
|
||||
|
||||
for(const auto &child : _children) {
|
||||
if (child != _sprite)
|
||||
{
|
||||
child->visit();
|
||||
}
|
||||
}
|
||||
|
||||
end();
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderTexture::saveToFile(const std::string& filename)
|
||||
{
|
||||
bool ret = false;
|
||||
|
@ -625,4 +486,186 @@ Image* RenderTexture::newImage(bool fliimage)
|
|||
return image;
|
||||
}
|
||||
|
||||
void RenderTexture::onBegin()
|
||||
{
|
||||
//
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &_oldProjMatrix);
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLLoadMatrix(&_projectionMatrix);
|
||||
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix);
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLLoadMatrix(&_transformMatrix);
|
||||
|
||||
Director *director = Director::getInstance();
|
||||
director->setProjection(director->getProjection());
|
||||
|
||||
const Size& texSize = _texture->getContentSizeInPixels();
|
||||
|
||||
// Calculate the adjustment ratios based on the old and new projections
|
||||
Size size = director->getWinSizeInPixels();
|
||||
float widthRatio = size.width / texSize.width;
|
||||
float heightRatio = size.height / texSize.height;
|
||||
|
||||
// Adjust the orthographic projection and viewport
|
||||
glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height);
|
||||
|
||||
|
||||
kmMat4 orthoMatrix;
|
||||
kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio,
|
||||
(float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
|
||||
kmGLMultMatrix(&orthoMatrix);
|
||||
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
|
||||
|
||||
//TODO move this to configration, so we don't check it every time
|
||||
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
|
||||
*/
|
||||
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
|
||||
{
|
||||
// -- bind a temporary texture so we can clear the render buffer without losing our texture
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0);
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTexture::onEnd()
|
||||
{
|
||||
Director *director = Director::getInstance();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO);
|
||||
|
||||
// restore viewport
|
||||
director->setViewport();
|
||||
|
||||
//
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLLoadMatrix(&_oldProjMatrix);
|
||||
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLLoadMatrix(&_oldTransMatrix);
|
||||
}
|
||||
|
||||
void RenderTexture::onClear()
|
||||
{
|
||||
// save clear color
|
||||
GLfloat oldClearColor[4] = {0.0f};
|
||||
GLfloat oldDepthClearValue = 0.0f;
|
||||
GLint oldStencilClearValue = 0;
|
||||
|
||||
// backup and set
|
||||
if (_clearFlags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor);
|
||||
glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a);
|
||||
}
|
||||
|
||||
if (_clearFlags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &oldDepthClearValue);
|
||||
glClearDepth(_clearDepth);
|
||||
}
|
||||
|
||||
if (_clearFlags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &oldStencilClearValue);
|
||||
glClearStencil(_clearStencil);
|
||||
}
|
||||
|
||||
// clear
|
||||
glClear(_clearFlags);
|
||||
|
||||
// restore
|
||||
if (_clearFlags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[3]);
|
||||
}
|
||||
if (_clearFlags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glClearDepth(oldDepthClearValue);
|
||||
}
|
||||
if (_clearFlags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glClearStencil(oldStencilClearValue);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTexture::onClearDepth()
|
||||
{
|
||||
//! save old depth value
|
||||
GLfloat depthClearValue;
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthClearValue);
|
||||
|
||||
glClearDepth(_clearDepth);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// restore clear color
|
||||
glClearDepth(depthClearValue);
|
||||
}
|
||||
|
||||
void RenderTexture::draw()
|
||||
{
|
||||
if (_autoDraw)
|
||||
{
|
||||
//Begin will create a render group using new render target
|
||||
begin();
|
||||
|
||||
//clear screen
|
||||
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
clearCmd->init(0, _vertexZ);
|
||||
clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
|
||||
//! make sure all children are drawn
|
||||
sortAllChildren();
|
||||
|
||||
for(const auto &child: _children)
|
||||
{
|
||||
if (child != _sprite)
|
||||
child->visit();
|
||||
}
|
||||
|
||||
//End will pop the current render group
|
||||
end();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTexture::begin()
|
||||
{
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLPushMatrix();
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &_projectionMatrix);
|
||||
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLPushMatrix();
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
|
||||
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0, _vertexZ);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(groupCommand);
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
|
||||
CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beginCmd->init(0, _vertexZ);
|
||||
beginCmd->func = CC_CALLBACK_0(RenderTexture::onBegin, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(beginCmd);
|
||||
}
|
||||
|
||||
void RenderTexture::end()
|
||||
{
|
||||
CustomCommand* endCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
endCmd->init(0, _vertexZ);
|
||||
endCmd->func = CC_CALLBACK_0(RenderTexture::onEnd, this);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(endCmd);
|
||||
renderer->popGroup();
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -187,7 +187,16 @@ protected:
|
|||
- [[renderTexture sprite] setBlendFunc:(BlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
|
||||
*/
|
||||
Sprite* _sprite;
|
||||
protected:
|
||||
//renderer caches and callbacks
|
||||
void onBegin();
|
||||
void onEnd();
|
||||
|
||||
void onClear();
|
||||
void onClearDepth();
|
||||
|
||||
kmMat4 _oldTransMatrix, _oldProjMatrix;
|
||||
kmMat4 _transformMatrix, _projectionMatrix;
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(RenderTexture);
|
||||
|
||||
|
|
|
@ -121,16 +121,6 @@ bool Scene::initWithPhysics()
|
|||
return ret;
|
||||
}
|
||||
|
||||
void Scene::addChild(Node* child)
|
||||
{
|
||||
Node::addChild(child);
|
||||
}
|
||||
|
||||
void Scene::addChild(Node* child, int zOrder)
|
||||
{
|
||||
Node::addChild(child, zOrder);
|
||||
}
|
||||
|
||||
void Scene::addChild(Node* child, int zOrder, int tag)
|
||||
{
|
||||
Node::addChild(child, zOrder, tag);
|
||||
|
|
|
@ -64,8 +64,7 @@ public:
|
|||
|
||||
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
|
||||
|
||||
virtual void addChild(Node* child) override;
|
||||
virtual void addChild(Node* child, int zOrder) override;
|
||||
using Node::addChild;
|
||||
virtual void addChild(Node* child, int zOrder, int tag) override;
|
||||
virtual void update(float delta) override;
|
||||
virtual std::string getDescription() const override;
|
||||
|
|
|
@ -222,6 +222,7 @@ bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame)
|
|||
// designated initializer
|
||||
bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated)
|
||||
{
|
||||
bool result;
|
||||
if (Node::init())
|
||||
{
|
||||
_batchNode = nullptr;
|
||||
|
@ -262,13 +263,15 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated)
|
|||
// by default use "Self Render".
|
||||
// if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
|
||||
setBatchNode(nullptr);
|
||||
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
result = false;
|
||||
}
|
||||
_recursiveDirty = true;
|
||||
setDirty(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
Sprite::Sprite(void)
|
||||
|
@ -694,7 +697,7 @@ bool Sprite::culling() const
|
|||
Rect newRect = RectApplyTransform(_rect, worldTM);
|
||||
|
||||
kmVec3 point = {newRect.getMinX(), newRect.getMinY(), _vertexZ};
|
||||
|
||||
|
||||
AABB aabb(point,point);
|
||||
kmVec3Fill(&point,newRect.getMaxX(), newRect.getMinY(), _vertexZ);
|
||||
aabb.expand(point);
|
||||
|
@ -725,8 +728,8 @@ void Sprite::updateQuadVertices()
|
|||
// }
|
||||
// else
|
||||
// {
|
||||
// CCASSERT( dynamic_cast<NewSprite*>(_parent), "Logic error in Sprite. Parent must be a Sprite");
|
||||
// _transformToBatch = AffineTransformConcat( getNodeToParentTransform() , static_cast<NewSprite*>(_parent)->_transformToBatch );
|
||||
// CCASSERT( dynamic_cast<Sprite*>(_parent), "Logic error in Sprite. Parent must be a Sprite");
|
||||
// _transformToBatch = AffineTransformConcat( getNodeToParentTransform() , static_cast<Sprite*>(_parent)->_transformToBatch );
|
||||
// }
|
||||
|
||||
//TODO optimize this transformation, should use parent's transformation instead
|
||||
|
@ -749,16 +752,6 @@ void Sprite::updateQuadVertices()
|
|||
|
||||
// Node overrides
|
||||
|
||||
void Sprite::addChild(Node *child)
|
||||
{
|
||||
Node::addChild(child);
|
||||
}
|
||||
|
||||
void Sprite::addChild(Node *child, int zOrder)
|
||||
{
|
||||
Node::addChild(child, zOrder);
|
||||
}
|
||||
|
||||
void Sprite::addChild(Node *child, int zOrder, int tag)
|
||||
{
|
||||
CCASSERT(child != nullptr, "Argument must be non-nullptr");
|
||||
|
|
|
@ -413,10 +413,7 @@ public:
|
|||
virtual void removeChild(Node* child, bool cleanup) override;
|
||||
virtual void removeAllChildrenWithCleanup(bool cleanup) override;
|
||||
virtual void reorderChild(Node *child, int zOrder) override;
|
||||
// Should also override addChild(Node*) and addChild(Node*, int), or binding generator will only
|
||||
// bind addChild(Node*, int, int);
|
||||
virtual void addChild(Node* child) override;
|
||||
virtual void addChild(Node* child, int zOrder) override;
|
||||
using Node::addChild;
|
||||
virtual void addChild(Node *child, int zOrder, int tag) override;
|
||||
virtual void sortAllChildren() override;
|
||||
virtual void setScale(float scale) override;
|
||||
|
|
|
@ -42,6 +42,8 @@ THE SOFTWARE.
|
|||
#include "CCProfiling.h"
|
||||
#include "CCLayer.h"
|
||||
#include "CCScene.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.h"
|
||||
// external
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
||||
|
@ -342,28 +344,32 @@ void SpriteBatchNode::reorderBatch(bool reorder)
|
|||
_reorderChildDirty=reorder;
|
||||
}
|
||||
|
||||
// draw
|
||||
void SpriteBatchNode::draw(void)
|
||||
void SpriteBatchNode::draw()
|
||||
{
|
||||
CC_PROFILER_START("CCSpriteBatchNode - draw");
|
||||
|
||||
// Optimization: Fast Dispatch
|
||||
if( _textureAtlas->getTotalQuads() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
for(const auto &child: _children) {
|
||||
for(const auto &child: _children)
|
||||
child->updateTransform();
|
||||
}
|
||||
|
||||
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
_textureAtlas->drawQuads();
|
||||
kmMat4 mv;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||
|
||||
CC_PROFILER_STOP("CCSpriteBatchNode - draw");
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0,
|
||||
_vertexZ,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
shader,
|
||||
_blendFunc,
|
||||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void SpriteBatchNode::increaseAtlasCapacity(void)
|
||||
|
|
|
@ -154,8 +154,8 @@ public:
|
|||
virtual const BlendFunc& getBlendFunc() const override;
|
||||
|
||||
virtual void visit() override;
|
||||
virtual void addChild(Node* child) override{ Node::addChild(child);}
|
||||
virtual void addChild(Node * child, int zOrder) override { Node::addChild(child, zOrder);}
|
||||
|
||||
using Node::addChild;
|
||||
virtual void addChild(Node * child, int zOrder, int tag) override;
|
||||
virtual void reorderChild(Node *child, int zOrder) override;
|
||||
|
||||
|
|
|
@ -185,6 +185,7 @@ public:
|
|||
/** TMXLayer doesn't support adding a Sprite manually.
|
||||
@warning addchild(z, tag); is not supported on TMXLayer. Instead of setTileGID.
|
||||
*/
|
||||
using SpriteBatchNode::addChild;
|
||||
virtual void addChild(Node * child, int zOrder, int tag) override;
|
||||
// super method
|
||||
void removeChild(Node* child, bool cleanup) override;
|
||||
|
|
|
@ -35,8 +35,6 @@ THE SOFTWARE.
|
|||
#include "CCLayer.h"
|
||||
#include "CCRenderTexture.h"
|
||||
#include "CCNodeGrid.h"
|
||||
#include "CCNewRenderTexture.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -1275,7 +1273,7 @@ void TransitionCrossFade::onEnter()
|
|||
LayerColor* layer = LayerColor::create(color);
|
||||
|
||||
// create the first render texture for inScene
|
||||
RenderTexture* inTexture = NewRenderTexture::create((int)size.width, (int)size.height);
|
||||
RenderTexture* inTexture = RenderTexture::create((int)size.width, (int)size.height);
|
||||
|
||||
if (nullptr == inTexture)
|
||||
{
|
||||
|
@ -1292,7 +1290,7 @@ void TransitionCrossFade::onEnter()
|
|||
inTexture->end();
|
||||
|
||||
// create the second render texture for outScene
|
||||
RenderTexture* outTexture = NewRenderTexture::create((int)size.width, (int)size.height);
|
||||
RenderTexture* outTexture = RenderTexture::create((int)size.width, (int)size.height);
|
||||
outTexture->getSprite()->setAnchorPoint( Point(0.5f,0.5f) );
|
||||
outTexture->setPosition( Point(size.width/2, size.height/2) );
|
||||
outTexture->setAnchorPoint( Point(0.5f,0.5f) );
|
||||
|
|
|
@ -32,7 +32,6 @@ THE SOFTWARE.
|
|||
#include "CCLayer.h"
|
||||
#include "CCActionInstant.h"
|
||||
#include "CCActionProgressTimer.h"
|
||||
#include "CCNewRenderTexture.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -72,7 +71,7 @@ void TransitionProgress::onEnter()
|
|||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
// create the second render texture for outScene
|
||||
RenderTexture *texture = NewRenderTexture::create((int)size.width, (int)size.height);
|
||||
RenderTexture *texture = RenderTexture::create((int)size.width, (int)size.height);
|
||||
texture->getSprite()->setAnchorPoint(Point(0.5f,0.5f));
|
||||
texture->setPosition(Point(size.width/2, size.height/2));
|
||||
texture->setAnchorPoint(Point(0.5f,0.5f));
|
||||
|
|
|
@ -139,15 +139,10 @@ set(COCOS2D_SRC
|
|||
platform/CCEGLViewProtocol.cpp
|
||||
platform/CCFileUtils.cpp
|
||||
../../external/edtaa3func/edtaa3func.cpp
|
||||
renderer/CCNewRenderTexture.cpp
|
||||
renderer/CCNewSprite.cpp
|
||||
renderer/CCNewSpriteBatchNode.cpp
|
||||
renderer/CCNewTextureAtlas.cpp
|
||||
renderer/CCCustomCommand.cpp
|
||||
renderer/CCFrustum.cpp
|
||||
renderer/CCGroupCommand.cpp
|
||||
renderer/CCMaterialManager.cpp
|
||||
renderer/CCNewClippingNode.cpp
|
||||
renderer/CCQuadCommand.cpp
|
||||
renderer/CCRenderCommand.cpp
|
||||
renderer/CCRenderer.cpp
|
||||
|
|
|
@ -119,15 +119,10 @@ THE SOFTWARE.
|
|||
#include "CCParticleSystemQuad.h"
|
||||
|
||||
// new renderer
|
||||
#include "renderer/CCNewRenderTexture.h"
|
||||
#include "renderer/CCNewSprite.h"
|
||||
#include "renderer/CCNewSpriteBatchNode.h"
|
||||
#include "renderer/CCNewTextureAtlas.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCFrustum.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCMaterialManager.h"
|
||||
#include "renderer/CCNewClippingNode.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "renderer/CCRenderCommand.h"
|
||||
#include "renderer/CCRenderCommandPool.h"
|
||||
|
|
|
@ -321,11 +321,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClCompile Include="renderer\CCFrustum.cpp" />
|
||||
<ClCompile Include="renderer\CCGroupCommand.cpp" />
|
||||
<ClCompile Include="renderer\CCMaterialManager.cpp" />
|
||||
<ClCompile Include="renderer\CCNewClippingNode.cpp" />
|
||||
<ClCompile Include="renderer\CCNewRenderTexture.cpp" />
|
||||
<ClCompile Include="renderer\CCNewSprite.cpp" />
|
||||
<ClCompile Include="renderer\CCNewSpriteBatchNode.cpp" />
|
||||
<ClCompile Include="renderer\CCNewTextureAtlas.cpp" />
|
||||
<ClCompile Include="renderer\CCQuadCommand.cpp" />
|
||||
<ClCompile Include="renderer\CCRenderCommand.cpp" />
|
||||
<ClCompile Include="renderer\CCRenderer.cpp" />
|
||||
|
@ -530,11 +525,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClInclude Include="renderer\CCFrustum.h" />
|
||||
<ClInclude Include="renderer\CCGroupCommand.h" />
|
||||
<ClInclude Include="renderer\CCMaterialManager.h" />
|
||||
<ClInclude Include="renderer\CCNewClippingNode.h" />
|
||||
<ClInclude Include="renderer\CCNewRenderTexture.h" />
|
||||
<ClInclude Include="renderer\CCNewSprite.h" />
|
||||
<ClInclude Include="renderer\CCNewSpriteBatchNode.h" />
|
||||
<ClInclude Include="renderer\CCNewTextureAtlas.h" />
|
||||
<ClInclude Include="renderer\CCQuadCommand.h" />
|
||||
<ClInclude Include="renderer\CCRenderCommand.h" />
|
||||
<ClInclude Include="renderer\CCRenderCommandPool.h" />
|
||||
|
|
|
@ -586,21 +586,6 @@
|
|||
<ClCompile Include="renderer\CCMaterialManager.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewClippingNode.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewRenderTexture.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewSprite.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewSpriteBatchNode.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewTextureAtlas.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCQuadCommand.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
|
@ -1207,21 +1192,6 @@
|
|||
<ClInclude Include="renderer\CCMaterialManager.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewClippingNode.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewRenderTexture.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewSprite.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewSpriteBatchNode.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewTextureAtlas.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCQuadCommand.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -1,301 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCNewClippingNode.h"
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// store the current stencil layer (position in the stencil buffer),
|
||||
// this will allow nesting up to n ClippingNode,
|
||||
// where n is the number of bits of the stencil buffer.
|
||||
static GLint layer = -1;
|
||||
|
||||
static void setProgram(Node *n, GLProgram *p)
|
||||
{
|
||||
n->setShaderProgram(p);
|
||||
|
||||
for(const auto &child : n->getChildren())
|
||||
setProgram(child, p);
|
||||
}
|
||||
|
||||
NewClippingNode *NewClippingNode::create()
|
||||
{
|
||||
NewClippingNode* pRet = new NewClippingNode();
|
||||
if(pRet && pRet->init())
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
NewClippingNode *NewClippingNode::create(Node *pStencil)
|
||||
{
|
||||
NewClippingNode* pRet = new NewClippingNode();
|
||||
if(pRet && pRet->init(pStencil))
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
NewClippingNode::~NewClippingNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewClippingNode::NewClippingNode()
|
||||
:ClippingNode()
|
||||
{
|
||||
currentStencilEnabled = GL_FALSE;
|
||||
currentStencilWriteMask = ~0;
|
||||
currentStencilFunc = GL_ALWAYS;
|
||||
currentStencilRef = 0;
|
||||
currentStencilValueMask = ~0;
|
||||
currentStencilFail = GL_KEEP;
|
||||
currentStencilPassDepthFail = GL_KEEP;
|
||||
currentStencilPassDepthPass = GL_KEEP;
|
||||
currentDepthWriteMask = GL_TRUE;
|
||||
|
||||
currentAlphaTestEnabled = GL_FALSE;
|
||||
currentAlphaTestFunc = GL_ALWAYS;
|
||||
currentAlphaTestRef = 1;
|
||||
}
|
||||
|
||||
void NewClippingNode::visit()
|
||||
{
|
||||
//Add group command
|
||||
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0,_vertexZ);
|
||||
renderer->addCommand(groupCommand);
|
||||
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
|
||||
CustomCommand* beforeVisitCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beforeVisitCmd->init(0,_vertexZ);
|
||||
beforeVisitCmd->func = CC_CALLBACK_0(NewClippingNode::beforeVisit, this);
|
||||
renderer->addCommand(beforeVisitCmd);
|
||||
|
||||
_stencil->visit();
|
||||
|
||||
CustomCommand* afterDrawStencilCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
afterDrawStencilCmd->init(0,_vertexZ);
|
||||
afterDrawStencilCmd->func = CC_CALLBACK_0(NewClippingNode::afterDrawStencil, this);
|
||||
renderer->addCommand(afterDrawStencilCmd);
|
||||
|
||||
Node::visit();
|
||||
|
||||
CustomCommand* afterVisitCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
afterVisitCmd->init(0,_vertexZ);
|
||||
afterVisitCmd->func = CC_CALLBACK_0(NewClippingNode::afterVisit, this);
|
||||
renderer->addCommand(afterVisitCmd);
|
||||
|
||||
renderer->popGroup();
|
||||
}
|
||||
|
||||
void NewClippingNode::beforeVisit()
|
||||
{
|
||||
///////////////////////////////////
|
||||
// INIT
|
||||
|
||||
// increment the current layer
|
||||
layer++;
|
||||
|
||||
// mask of the current layer (ie: for layer 3: 00000100)
|
||||
GLint mask_layer = 0x1 << layer;
|
||||
// mask of all layers less than the current (ie: for layer 3: 00000011)
|
||||
GLint mask_layer_l = mask_layer - 1;
|
||||
// mask of all layers less than or equal to the current (ie: for layer 3: 00000111)
|
||||
mask_layer_le = mask_layer | mask_layer_l;
|
||||
|
||||
// manually save the stencil state
|
||||
|
||||
currentStencilEnabled = glIsEnabled(GL_STENCIL_TEST);
|
||||
glGetIntegerv(GL_STENCIL_WRITEMASK, (GLint *)¤tStencilWriteMask);
|
||||
glGetIntegerv(GL_STENCIL_FUNC, (GLint *)¤tStencilFunc);
|
||||
glGetIntegerv(GL_STENCIL_REF, ¤tStencilRef);
|
||||
glGetIntegerv(GL_STENCIL_VALUE_MASK, (GLint *)¤tStencilValueMask);
|
||||
glGetIntegerv(GL_STENCIL_FAIL, (GLint *)¤tStencilFail);
|
||||
glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, (GLint *)¤tStencilPassDepthFail);
|
||||
glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, (GLint *)¤tStencilPassDepthPass);
|
||||
|
||||
// enable stencil use
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
// check for OpenGL error while enabling stencil test
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// all bits on the stencil buffer are readonly, except the current layer bit,
|
||||
// this means that operation like glClear or glStencilOp will be masked with this value
|
||||
glStencilMask(mask_layer);
|
||||
|
||||
// manually save the depth test state
|
||||
|
||||
//currentDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
|
||||
glGetBooleanv(GL_DEPTH_WRITEMASK, ¤tDepthWriteMask);
|
||||
|
||||
// disable depth test while drawing the stencil
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
// disable update to the depth buffer while drawing the stencil,
|
||||
// as the stencil is not meant to be rendered in the real scene,
|
||||
// it should never prevent something else to be drawn,
|
||||
// only disabling depth buffer update should do
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
///////////////////////////////////
|
||||
// CLEAR STENCIL BUFFER
|
||||
|
||||
// manually clear the stencil buffer by drawing a fullscreen rectangle on it
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel in the fullscreen rectangle
|
||||
// never draw it into the frame buffer
|
||||
// if not in inverted mode: set the current layer value to 0 in the stencil buffer
|
||||
// if in inverted mode: set the current layer value to 1 in the stencil buffer
|
||||
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
|
||||
glStencilOp(!_inverted ? GL_ZERO : GL_REPLACE, GL_KEEP, GL_KEEP);
|
||||
|
||||
// draw a fullscreen solid rectangle to clear the stencil buffer
|
||||
//ccDrawSolidRect(Point::ZERO, ccpFromSize([[Director sharedDirector] winSize]), Color4F(1, 1, 1, 1));
|
||||
drawFullScreenQuadClearStencil();
|
||||
|
||||
///////////////////////////////////
|
||||
// DRAW CLIPPING STENCIL
|
||||
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel in the stencil node
|
||||
// never draw it into the frame buffer
|
||||
// if not in inverted mode: set the current layer value to 1 in the stencil buffer
|
||||
// if in inverted mode: set the current layer value to 0 in the stencil buffer
|
||||
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
|
||||
glStencilOp(!_inverted ? GL_REPLACE : GL_ZERO, GL_KEEP, GL_KEEP);
|
||||
|
||||
// enable alpha test only if the alpha threshold < 1,
|
||||
// indeed if alpha threshold == 1, every pixel will be drawn anyways
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// GLboolean currentAlphaTestEnabled = GL_FALSE;
|
||||
// GLenum currentAlphaTestFunc = GL_ALWAYS;
|
||||
// GLclampf currentAlphaTestRef = 1;
|
||||
#endif
|
||||
if (_alphaThreshold < 1) {
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// manually save the alpha test state
|
||||
currentAlphaTestEnabled = glIsEnabled(GL_ALPHA_TEST);
|
||||
glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint *)¤tAlphaTestFunc);
|
||||
glGetFloatv(GL_ALPHA_TEST_REF, ¤tAlphaTestRef);
|
||||
// enable alpha testing
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
// check for OpenGL error while enabling alpha test
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
// pixel will be drawn only if greater than an alpha threshold
|
||||
glAlphaFunc(GL_GREATER, _alphaThreshold);
|
||||
#else
|
||||
// since glAlphaTest do not exists in OES, use a shader that writes
|
||||
// pixel only if greater than an alpha threshold
|
||||
GLProgram *program = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
|
||||
GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
|
||||
// set our alphaThreshold
|
||||
program->use();
|
||||
program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
|
||||
// we need to recursively apply this shader to all the nodes in the stencil node
|
||||
// XXX: we should have a way to apply shader to all nodes without having to do this
|
||||
setProgram(_stencil, program);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//Draw _stencil
|
||||
}
|
||||
|
||||
void NewClippingNode::afterDrawStencil()
|
||||
{
|
||||
// restore alpha test state
|
||||
if (_alphaThreshold < 1)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// manually restore the alpha test state
|
||||
glAlphaFunc(currentAlphaTestFunc, currentAlphaTestRef);
|
||||
if (!currentAlphaTestEnabled)
|
||||
{
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
}
|
||||
#else
|
||||
// XXX: we need to find a way to restore the shaders of the stencil node and its childs
|
||||
#endif
|
||||
}
|
||||
|
||||
// restore the depth test state
|
||||
glDepthMask(currentDepthWriteMask);
|
||||
//if (currentDepthTestEnabled) {
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
//}
|
||||
|
||||
///////////////////////////////////
|
||||
// DRAW CONTENT
|
||||
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel of this node and its childs
|
||||
// if all layers less than or equals to the current are set to 1 in the stencil buffer
|
||||
// draw the pixel and keep the current layer in the stencil buffer
|
||||
// else
|
||||
// do not draw the pixel but keep the current layer in the stencil buffer
|
||||
glStencilFunc(GL_EQUAL, mask_layer_le, mask_layer_le);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
|
||||
// draw (according to the stencil test func) this node and its childs
|
||||
}
|
||||
|
||||
|
||||
void NewClippingNode::afterVisit()
|
||||
{
|
||||
///////////////////////////////////
|
||||
// CLEANUP
|
||||
|
||||
// manually restore the stencil state
|
||||
glStencilFunc(currentStencilFunc, currentStencilRef, currentStencilValueMask);
|
||||
glStencilOp(currentStencilFail, currentStencilPassDepthFail, currentStencilPassDepthPass);
|
||||
glStencilMask(currentStencilWriteMask);
|
||||
if (!currentStencilEnabled)
|
||||
{
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
// we are done using this layer, decrement
|
||||
layer--;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,70 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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 __NewClippingNode_H_
|
||||
#define __NewClippingNode_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCClippingNode.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewClippingNode : public ClippingNode
|
||||
{
|
||||
public:
|
||||
static NewClippingNode* create();
|
||||
static NewClippingNode* create(Node* pStencil);
|
||||
|
||||
virtual ~NewClippingNode();
|
||||
|
||||
virtual void visit() override;
|
||||
|
||||
protected:
|
||||
NewClippingNode();
|
||||
|
||||
void beforeVisit();
|
||||
void afterDrawStencil();
|
||||
void afterVisit();
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__NewClippingNode_H_
|
|
@ -1,316 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "CCNewRenderTexture.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCConfiguration.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
NewRenderTexture* NewRenderTexture::create(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat)
|
||||
{
|
||||
NewRenderTexture* pRet = new NewRenderTexture();
|
||||
|
||||
if(pRet && pRet->initWithWidthAndHeight(w, h, eFormat, uDepthStencilFormat))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NewRenderTexture* NewRenderTexture::create(int w, int h, Texture2D::PixelFormat eFormat)
|
||||
{
|
||||
NewRenderTexture* pRet = new NewRenderTexture();
|
||||
|
||||
if(pRet && pRet->initWithWidthAndHeight(w, h, eFormat))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NewRenderTexture* NewRenderTexture::create(int w, int h)
|
||||
{
|
||||
NewRenderTexture* pRet = new NewRenderTexture();
|
||||
|
||||
if(pRet && pRet->initWithWidthAndHeight(w, h, Texture2D::PixelFormat::RGB888 , 0))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void NewRenderTexture::draw()
|
||||
{
|
||||
if (_autoDraw)
|
||||
{
|
||||
//Begin will create a render group using new render target
|
||||
begin();
|
||||
|
||||
//clear screen
|
||||
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
clearCmd->init(0, _vertexZ);
|
||||
clearCmd->func = CC_CALLBACK_0(NewRenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
|
||||
//! make sure all children are drawn
|
||||
sortAllChildren();
|
||||
|
||||
for(const auto &child: _children)
|
||||
{
|
||||
if (child != _sprite)
|
||||
child->visit();
|
||||
}
|
||||
|
||||
//End will pop the current render group
|
||||
end();
|
||||
}
|
||||
}
|
||||
|
||||
void NewRenderTexture::beginWithClear(float r, float g, float b, float a)
|
||||
{
|
||||
beginWithClear(r, g, b, a, 0, 0, GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue)
|
||||
{
|
||||
beginWithClear(r, g, b, a, depthValue, 0, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue)
|
||||
{
|
||||
beginWithClear(r, g, b, a, depthValue, stencilValue, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags)
|
||||
{
|
||||
setClearColor(Color4F(r, g, b, a));
|
||||
|
||||
setClearDepth(depthValue);
|
||||
|
||||
setClearStencil(stencilValue);
|
||||
|
||||
setClearFlags(flags);
|
||||
|
||||
this->begin();
|
||||
|
||||
//clear screen
|
||||
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
clearCmd->init(0, _vertexZ);
|
||||
clearCmd->func = CC_CALLBACK_0(NewRenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
}
|
||||
|
||||
void NewRenderTexture::begin()
|
||||
{
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLPushMatrix();
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &_projectionMatrix);
|
||||
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLPushMatrix();
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
|
||||
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0, _vertexZ);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(groupCommand);
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
|
||||
CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beginCmd->init(0, _vertexZ);
|
||||
beginCmd->func = CC_CALLBACK_0(NewRenderTexture::onBegin, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(beginCmd);
|
||||
}
|
||||
|
||||
void NewRenderTexture::end()
|
||||
{
|
||||
CustomCommand* endCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
endCmd->init(0, _vertexZ);
|
||||
endCmd->func = CC_CALLBACK_0(NewRenderTexture::onEnd, this);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(endCmd);
|
||||
renderer->popGroup();
|
||||
}
|
||||
|
||||
void NewRenderTexture::onBegin()
|
||||
{
|
||||
//
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &_oldProjMatrix);
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLLoadMatrix(&_projectionMatrix);
|
||||
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix);
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLLoadMatrix(&_transformMatrix);
|
||||
|
||||
Director *director = Director::getInstance();
|
||||
director->setProjection(director->getProjection());
|
||||
|
||||
const Size& texSize = _texture->getContentSizeInPixels();
|
||||
|
||||
// Calculate the adjustment ratios based on the old and new projections
|
||||
Size size = director->getWinSizeInPixels();
|
||||
float widthRatio = size.width / texSize.width;
|
||||
float heightRatio = size.height / texSize.height;
|
||||
|
||||
// Adjust the orthographic projection and viewport
|
||||
glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height);
|
||||
|
||||
|
||||
kmMat4 orthoMatrix;
|
||||
kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio,
|
||||
(float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
|
||||
kmGLMultMatrix(&orthoMatrix);
|
||||
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
|
||||
|
||||
//TODO move this to configration, so we don't check it every time
|
||||
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
|
||||
*/
|
||||
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
|
||||
{
|
||||
// -- bind a temporary texture so we can clear the render buffer without losing our texture
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0);
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void NewRenderTexture::onEnd()
|
||||
{
|
||||
Director *director = Director::getInstance();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO);
|
||||
|
||||
// restore viewport
|
||||
director->setViewport();
|
||||
|
||||
//
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLLoadMatrix(&_oldProjMatrix);
|
||||
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLLoadMatrix(&_oldTransMatrix);
|
||||
}
|
||||
|
||||
void NewRenderTexture::onClear()
|
||||
{
|
||||
// save clear color
|
||||
GLfloat oldClearColor[4] = {0.0f};
|
||||
GLfloat oldDepthClearValue = 0.0f;
|
||||
GLint oldStencilClearValue = 0;
|
||||
|
||||
// backup and set
|
||||
if (_clearFlags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor);
|
||||
glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a);
|
||||
}
|
||||
|
||||
if (_clearFlags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &oldDepthClearValue);
|
||||
glClearDepth(_clearDepth);
|
||||
}
|
||||
|
||||
if (_clearFlags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &oldStencilClearValue);
|
||||
glClearStencil(_clearStencil);
|
||||
}
|
||||
|
||||
// clear
|
||||
glClear(_clearFlags);
|
||||
|
||||
// restore
|
||||
if (_clearFlags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[3]);
|
||||
}
|
||||
if (_clearFlags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glClearDepth(oldDepthClearValue);
|
||||
}
|
||||
if (_clearFlags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glClearStencil(oldStencilClearValue);
|
||||
}
|
||||
}
|
||||
|
||||
void NewRenderTexture::clearDepth(float depthValue)
|
||||
{
|
||||
setClearDepth(depthValue);
|
||||
|
||||
this->begin();
|
||||
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(NewRenderTexture::onClearDepth, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
|
||||
this->end();
|
||||
}
|
||||
|
||||
void NewRenderTexture::onClearDepth()
|
||||
{
|
||||
//! save old depth value
|
||||
GLfloat depthClearValue;
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthClearValue);
|
||||
|
||||
glClearDepth(_clearDepth);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// restore clear color
|
||||
glClearDepth(depthClearValue);
|
||||
}
|
||||
|
||||
NewRenderTexture::NewRenderTexture()
|
||||
:RenderTexture()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewRenderTexture::~NewRenderTexture()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,67 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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 __CCNewRenderTexture_H_
|
||||
#define __CCNewRenderTexture_H_
|
||||
|
||||
#include "CCRenderTexture.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewRenderTexture : public RenderTexture
|
||||
{
|
||||
public:
|
||||
static NewRenderTexture* create(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat);
|
||||
static NewRenderTexture* create(int w, int h, Texture2D::PixelFormat eFormat);
|
||||
static NewRenderTexture* create(int w, int h);
|
||||
|
||||
void beginWithClear(float r, float g, float b, float a);
|
||||
void beginWithClear(float r, float g, float b, float a, float depthValue);
|
||||
void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue);
|
||||
void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags);
|
||||
|
||||
virtual void begin() override;
|
||||
virtual void end() override;
|
||||
virtual void draw() override;
|
||||
|
||||
void clearDepth(float depthValue);
|
||||
|
||||
protected:
|
||||
NewRenderTexture();
|
||||
virtual ~NewRenderTexture();
|
||||
|
||||
void onBegin();
|
||||
void onEnd();
|
||||
|
||||
//Clear render buffer
|
||||
void onClear();
|
||||
void onClearDepth();
|
||||
|
||||
kmMat4 _oldTransMatrix, _oldProjMatrix;
|
||||
kmMat4 _transformMatrix, _projectionMatrix;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCNewRenderTexture_H_
|
|
@ -1,165 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCNewSprite.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCFrustum.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCQuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#if CC_SPRITEBATCHNODE_RENDER_SUBPIXEL
|
||||
#define RENDER_IN_SUBPIXEL
|
||||
#else
|
||||
#define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__))
|
||||
#endif
|
||||
|
||||
NewSprite* NewSprite::create()
|
||||
{
|
||||
NewSprite* sprite = new NewSprite();
|
||||
if(sprite && sprite->init())
|
||||
{
|
||||
sprite->autorelease();
|
||||
return sprite;
|
||||
}
|
||||
CC_SAFE_DELETE(sprite);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NewSprite* NewSprite::create(const char *filename)
|
||||
{
|
||||
NewSprite* sprite = new NewSprite();
|
||||
if(sprite && sprite->initWithFile(filename))
|
||||
{
|
||||
sprite->autorelease();
|
||||
return sprite;
|
||||
}
|
||||
CC_SAFE_DELETE(sprite);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NewSprite::NewSprite()
|
||||
:Sprite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewSprite::~NewSprite(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool NewSprite::initWithTexture(Texture2D *texture, const Rect &rect, bool rotated)
|
||||
{
|
||||
bool result = Sprite::initWithTexture(texture, rect, rotated);
|
||||
_recursiveDirty = true;
|
||||
setDirty(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
void NewSprite::updateQuadVertices()
|
||||
{
|
||||
#ifdef CC_USE_PHYSICS
|
||||
updatePhysicsTransform();
|
||||
setDirty(true);
|
||||
#endif
|
||||
|
||||
//TODO optimize the performance cache affineTransformation
|
||||
|
||||
// recalculate matrix only if it is dirty
|
||||
if(isDirty())
|
||||
{
|
||||
|
||||
// if( ! _parent || _parent == (Node*)_batchNode )
|
||||
// {
|
||||
// _transformToBatch = getNodeToParentTransform();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// CCASSERT( dynamic_cast<NewSprite*>(_parent), "Logic error in Sprite. Parent must be a Sprite");
|
||||
// _transformToBatch = AffineTransformConcat( getNodeToParentTransform() , static_cast<NewSprite*>(_parent)->_transformToBatch );
|
||||
// }
|
||||
|
||||
//TODO optimize this transformation, should use parent's transformation instead
|
||||
_transformToBatch = getNodeToWorldTransform();
|
||||
|
||||
//
|
||||
// calculate the Quad based on the Affine Matrix
|
||||
//
|
||||
Rect newRect = RectApplyTransform(_rect, _transformToBatch);
|
||||
|
||||
_quad.bl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMinX()), RENDER_IN_SUBPIXEL(newRect.getMinY()), _vertexZ );
|
||||
_quad.br.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMaxX()), RENDER_IN_SUBPIXEL(newRect.getMinY()), _vertexZ );
|
||||
_quad.tl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMinX()), RENDER_IN_SUBPIXEL(newRect.getMaxY()), _vertexZ );
|
||||
_quad.tr.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMaxX()), RENDER_IN_SUBPIXEL(newRect.getMaxY()), _vertexZ );
|
||||
|
||||
_recursiveDirty = false;
|
||||
setDirty(false);
|
||||
}
|
||||
}
|
||||
|
||||
void NewSprite::draw(void)
|
||||
{
|
||||
kmMat4 mv;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||
//TODO implement z order
|
||||
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
|
||||
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv);
|
||||
|
||||
if(!culling())
|
||||
{
|
||||
renderCommand->releaseToCommandPool();
|
||||
return;
|
||||
}
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(renderCommand);
|
||||
}
|
||||
|
||||
bool NewSprite::culling() const
|
||||
{
|
||||
Frustum* frustum = Director::getInstance()->getFrustum();
|
||||
//TODO optimize this transformation, should use parent's transformation instead
|
||||
kmMat4 worldTM = getNodeToWorldTransform();
|
||||
//generate aabb
|
||||
|
||||
//
|
||||
// calculate the Quad based on the Affine Matrix
|
||||
//
|
||||
Rect newRect = RectApplyTransform(_rect, worldTM);
|
||||
|
||||
kmVec3 point = {newRect.getMinX(), newRect.getMinY(), _vertexZ};
|
||||
|
||||
AABB aabb(point,point);
|
||||
kmVec3Fill(&point,newRect.getMaxX(), newRect.getMinY(), _vertexZ);
|
||||
aabb.expand(point);
|
||||
kmVec3Fill(&point,newRect.getMinX(), newRect.getMaxY(), _vertexZ);
|
||||
aabb.expand(point);
|
||||
kmVec3Fill(&point,newRect.getMaxX(), newRect.getMaxY(), _vertexZ);
|
||||
aabb.expand(point);
|
||||
|
||||
return Frustum::IntersectResult::OUTSIDE !=frustum->intersectAABB(aabb);
|
||||
}
|
||||
|
||||
|
||||
NS_CC_END
|
|
@ -1,54 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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 __CCNEWSPRITE_H_
|
||||
#define __CCNEWSPRITE_H_
|
||||
|
||||
#include "CCSprite.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewSprite : public Sprite
|
||||
{
|
||||
|
||||
public:
|
||||
static NewSprite* create();
|
||||
static NewSprite* create(const char *filename);
|
||||
|
||||
virtual void updateQuadVertices();
|
||||
virtual void draw(void) override;
|
||||
|
||||
bool culling() const;
|
||||
|
||||
protected:
|
||||
NewSprite(void);
|
||||
~NewSprite();
|
||||
|
||||
virtual bool initWithTexture(Texture2D *texture, const Rect& rect, bool rotated);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(__CCNEWSPRITE_H_) */
|
|
@ -1,102 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCNewSpriteBatchNode.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "CCTextureCache.h"
|
||||
#include "CCSprite.h"
|
||||
#include "CCNewSprite.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
NewSpriteBatchNode *NewSpriteBatchNode::createWithTexture(Texture2D *tex, int capacity)
|
||||
{
|
||||
NewSpriteBatchNode* batchNode = new NewSpriteBatchNode();
|
||||
batchNode->initWithTexture(tex, capacity);
|
||||
batchNode->autorelease();
|
||||
|
||||
return batchNode;
|
||||
}
|
||||
|
||||
NewSpriteBatchNode *NewSpriteBatchNode::create(const char *fileImage, long capacity)
|
||||
{
|
||||
NewSpriteBatchNode* batchNode = new NewSpriteBatchNode();
|
||||
batchNode->initWithFile(fileImage, capacity);
|
||||
batchNode->autorelease();
|
||||
|
||||
return batchNode;
|
||||
}
|
||||
|
||||
NewSpriteBatchNode::NewSpriteBatchNode()
|
||||
:SpriteBatchNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewSpriteBatchNode::~NewSpriteBatchNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool NewSpriteBatchNode::init()
|
||||
{
|
||||
Texture2D* texture = new Texture2D();
|
||||
texture->autorelease();
|
||||
return this->initWithTexture(texture, 0);
|
||||
}
|
||||
|
||||
void NewSpriteBatchNode::draw()
|
||||
{
|
||||
// Optimization: Fast Dispatch
|
||||
if( _textureAtlas->getTotalQuads() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(const auto &child: _children)
|
||||
child->updateTransform();
|
||||
|
||||
// arrayMakeObjectsPerformSelector(_children, updateTransform, NewSprite*);
|
||||
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
kmMat4 mv;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0,
|
||||
_vertexZ,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
shader,
|
||||
_blendFunc,
|
||||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,51 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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 __CCNewSpriteBatchNode_H_
|
||||
#define __CCNewSpriteBatchNode_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "CCSpriteBatchNode.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewSpriteBatchNode : public SpriteBatchNode
|
||||
{
|
||||
static const int DEFAULT_CAPACITY = 29;
|
||||
public:
|
||||
static NewSpriteBatchNode* createWithTexture(Texture2D* tex, int capacity = DEFAULT_CAPACITY);
|
||||
static NewSpriteBatchNode* create(const char* fileImage, long capacity = DEFAULT_CAPACITY);
|
||||
|
||||
void draw(void);
|
||||
|
||||
protected:
|
||||
NewSpriteBatchNode();
|
||||
virtual ~NewSpriteBatchNode();
|
||||
bool init();
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCNewSpriteBatchNode_H_
|
|
@ -1,77 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCNewTextureAtlas.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
NewTextureAtlas::NewTextureAtlas()
|
||||
:TextureAtlas()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewTextureAtlas::~NewTextureAtlas()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewTextureAtlas *NewTextureAtlas::create(const char *file, long capacity)
|
||||
{
|
||||
NewTextureAtlas * textureAtlas = new NewTextureAtlas();
|
||||
if(textureAtlas && textureAtlas->initWithFile(file, capacity))
|
||||
{
|
||||
textureAtlas->autorelease();
|
||||
return textureAtlas;
|
||||
}
|
||||
CC_SAFE_DELETE(textureAtlas);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NewTextureAtlas *NewTextureAtlas::createWithTexture(Texture2D *texture, long capacity)
|
||||
{
|
||||
NewTextureAtlas * textureAtlas = new NewTextureAtlas();
|
||||
if (textureAtlas && textureAtlas->initWithTexture(texture, capacity))
|
||||
{
|
||||
textureAtlas->autorelease();
|
||||
return textureAtlas;
|
||||
}
|
||||
CC_SAFE_DELETE(textureAtlas);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void NewTextureAtlas::drawNumberOfQuads(long numberOfQuads, long start)
|
||||
{
|
||||
// updateTransform();
|
||||
// QuadCommand* renderCommand = new QuadCommand(0, 0,_texture->getName(), _shaderProgram, _blendFunc, _quad);
|
||||
//
|
||||
// Renderer::getInstance()->addCommand(renderCommand);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,50 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.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 __CCNewTextureAtlas_H_
|
||||
#define __CCNewTextureAtlas_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCTextureAtlas.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewTextureAtlas : public TextureAtlas
|
||||
{
|
||||
public:
|
||||
static NewTextureAtlas* create(const char* file, long capacity);
|
||||
static NewTextureAtlas* createWithTexture(Texture2D *texture, long capacity);
|
||||
|
||||
void drawNumberOfQuads(long numberOfQuads, long start);
|
||||
|
||||
protected:
|
||||
NewTextureAtlas();
|
||||
virtual ~NewTextureAtlas();
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCNewTextureAtlas_H_
|
|
@ -56,7 +56,7 @@ Armature *Armature::create()
|
|||
}
|
||||
|
||||
|
||||
Armature *Armature::create(const char *name)
|
||||
Armature *Armature::create(const std::string& name)
|
||||
{
|
||||
Armature *armature = new Armature();
|
||||
if (armature && armature->init(name))
|
||||
|
@ -68,7 +68,7 @@ Armature *Armature::create(const char *name)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Armature *Armature::create(const char *name, Bone *parentBone)
|
||||
Armature *Armature::create(const std::string& name, Bone *parentBone)
|
||||
{
|
||||
Armature *armature = new Armature();
|
||||
if (armature && armature->init(name, parentBone))
|
||||
|
@ -105,7 +105,7 @@ bool Armature::init()
|
|||
}
|
||||
|
||||
|
||||
bool Armature::init(const char *name)
|
||||
bool Armature::init(const std::string& name)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
|
@ -121,14 +121,12 @@ bool Armature::init(const char *name)
|
|||
|
||||
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
||||
|
||||
_name = name == nullptr ? "" : name;
|
||||
_name = name;
|
||||
|
||||
ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance();
|
||||
|
||||
if(_name.length() != 0)
|
||||
if(!_name.empty())
|
||||
{
|
||||
_name = name;
|
||||
|
||||
AnimationData *animationData = armatureDataManager->getAnimationData(name);
|
||||
CCASSERT(animationData, "AnimationData not exist! ");
|
||||
|
||||
|
@ -196,14 +194,14 @@ bool Armature::init(const char *name)
|
|||
return bRet;
|
||||
}
|
||||
|
||||
bool Armature::init(const char *name, Bone *parentBone)
|
||||
bool Armature::init(const std::string& name, Bone *parentBone)
|
||||
{
|
||||
_parentBone = parentBone;
|
||||
return init(name);
|
||||
}
|
||||
|
||||
|
||||
Bone *Armature::createBone(const char *boneName)
|
||||
Bone *Armature::createBone(const std::string& boneName)
|
||||
{
|
||||
Bone *existedBone = getBone(boneName);
|
||||
if(existedBone != nullptr)
|
||||
|
@ -233,12 +231,12 @@ Bone *Armature::createBone(const char *boneName)
|
|||
}
|
||||
|
||||
|
||||
void Armature::addBone(Bone *bone, const char *parentName)
|
||||
void Armature::addBone(Bone *bone, const std::string& parentName)
|
||||
{
|
||||
CCASSERT( bone != nullptr, "Argument must be non-nil");
|
||||
CCASSERT(_boneDic.at(bone->getName()) == nullptr, "bone already added. It can't be added again");
|
||||
|
||||
if (nullptr != parentName)
|
||||
if (!parentName.empty())
|
||||
{
|
||||
Bone *boneParent = _boneDic.at(parentName);
|
||||
if (boneParent)
|
||||
|
@ -278,13 +276,13 @@ void Armature::removeBone(Bone *bone, bool recursion)
|
|||
}
|
||||
|
||||
|
||||
Bone *Armature::getBone(const char *name) const
|
||||
Bone *Armature::getBone(const std::string& name) const
|
||||
{
|
||||
return _boneDic.at(name);
|
||||
}
|
||||
|
||||
|
||||
void Armature::changeBoneParent(Bone *bone, const char *parentName)
|
||||
void Armature::changeBoneParent(Bone *bone, const std::string& parentName)
|
||||
{
|
||||
CCASSERT(bone != nullptr, "bone must be added to the bone dictionary!");
|
||||
|
||||
|
@ -294,7 +292,7 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName)
|
|||
bone->setParentBone(nullptr);
|
||||
}
|
||||
|
||||
if (parentName != nullptr)
|
||||
if (!parentName.empty())
|
||||
{
|
||||
Bone *boneParent = _boneDic.at(parentName);
|
||||
|
||||
|
|
|
@ -84,9 +84,9 @@ public:
|
|||
* @param name Armature will use the name to find the ArmatureData to initializes it.
|
||||
* @return A initialized armature which is marked as "autorelease".
|
||||
*/
|
||||
static Armature *create(const char *name);
|
||||
static Armature *create(const std::string& name);
|
||||
|
||||
static Armature *create(const char *name, Bone *parentBone);
|
||||
static Armature *create(const std::string& name, Bone *parentBone);
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -108,29 +108,29 @@ public:
|
|||
* Init an armature with specified name
|
||||
* @param name Armature name
|
||||
*/
|
||||
virtual bool init(const char *name);
|
||||
virtual bool init(const std::string& name);
|
||||
|
||||
virtual bool init(const char *name, Bone *parentBone);
|
||||
virtual bool init(const std::string& name, Bone *parentBone);
|
||||
/**
|
||||
* Add a Bone to this Armature,
|
||||
*
|
||||
* @param bone The Bone you want to add to Armature
|
||||
* @param parentName The parent Bone's name you want to add to . If it's nullptr, then set Armature to its parent
|
||||
*/
|
||||
virtual void addBone(Bone *bone, const char *parentName);
|
||||
virtual void addBone(Bone *bone, const std::string& parentName);
|
||||
/**
|
||||
* Get a bone with the specified name
|
||||
*
|
||||
* @param name The bone's name you want to get
|
||||
*/
|
||||
virtual Bone *getBone(const char *name) const;
|
||||
virtual Bone *getBone(const std::string& name) const;
|
||||
/**
|
||||
* Change a bone's parent with the specified parent name.
|
||||
*
|
||||
* @param bone The bone you want to change parent
|
||||
* @param parentName The new parent's name.
|
||||
*/
|
||||
virtual void changeBoneParent(Bone *bone, const char *parentName);
|
||||
virtual void changeBoneParent(Bone *bone, const std::string& parentName);
|
||||
/**
|
||||
* Remove a bone with the specified name. If recursion it will also remove child Bone recursionly.
|
||||
*
|
||||
|
@ -247,7 +247,7 @@ protected:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Bone *createBone(const char *boneName );
|
||||
Bone *createBone(const std::string& boneName );
|
||||
|
||||
protected:
|
||||
ArmatureData *_armatureData;
|
||||
|
|
|
@ -164,11 +164,11 @@ float ArmatureAnimation::getSpeedScale() const
|
|||
}
|
||||
|
||||
|
||||
void ArmatureAnimation::play(const char *animationName, int durationTo, int loop)
|
||||
void ArmatureAnimation::play(const std::string& animationName, int durationTo, int loop)
|
||||
{
|
||||
CCASSERT(_animationData, "_animationData can not be null");
|
||||
|
||||
_movementData = _animationData->getMovement(animationName);
|
||||
_movementData = _animationData->getMovement(animationName.c_str());
|
||||
CCASSERT(_movementData, "_movementData can not be null");
|
||||
|
||||
//! Get key frame count
|
||||
|
@ -461,11 +461,11 @@ void ArmatureAnimation::setFrameEventCallFunc(Object *target, SEL_FrameEventCall
|
|||
_frameEventCallFunc = callFunc;
|
||||
}
|
||||
|
||||
void ArmatureAnimation::setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const char *movementID)> listener)
|
||||
void ArmatureAnimation::setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const std::string& movementID)> listener)
|
||||
{
|
||||
_movementEventListener = listener;
|
||||
}
|
||||
void ArmatureAnimation::setFrameEventCallFunc(std::function<void(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)> listener)
|
||||
void ArmatureAnimation::setFrameEventCallFunc(std::function<void(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex)> listener)
|
||||
{
|
||||
_frameEventListener = listener;
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ void ArmatureAnimation::setUserObject(Object *pUserObject)
|
|||
_userObject = pUserObject;
|
||||
}
|
||||
|
||||
void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)
|
||||
void ArmatureAnimation::frameEvent(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex)
|
||||
{
|
||||
if ((_frameEventTarget && _frameEventCallFunc) || _frameEventListener)
|
||||
{
|
||||
|
@ -492,7 +492,7 @@ void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int o
|
|||
}
|
||||
|
||||
|
||||
void ArmatureAnimation::movementEvent(Armature *armature, MovementEventType movementType, const char *movementID)
|
||||
void ArmatureAnimation::movementEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
|
||||
{
|
||||
if ((_movementEventTarget && _movementEventCallFunc) || _movementEventListener)
|
||||
{
|
||||
|
|
|
@ -44,8 +44,8 @@ enum MovementEventType
|
|||
class Armature;
|
||||
class Bone;
|
||||
|
||||
typedef void (cocos2d::Object::*SEL_MovementEventCallFunc)(Armature *, MovementEventType, const char *);
|
||||
typedef void (cocos2d::Object::*SEL_FrameEventCallFunc)(Bone *, const char *, int, int);
|
||||
typedef void (cocos2d::Object::*SEL_MovementEventCallFunc)(Armature *, MovementEventType, const std::string&);
|
||||
typedef void (cocos2d::Object::*SEL_FrameEventCallFunc)(Bone *, const std::string&, int, int);
|
||||
|
||||
#define movementEvent_selector(_SELECTOR) (cocostudio::SEL_MovementEventCallFunc)(&_SELECTOR)
|
||||
#define frameEvent_selector(_SELECTOR) (cocostudio::SEL_FrameEventCallFunc)(&_SELECTOR)
|
||||
|
@ -53,7 +53,7 @@ typedef void (cocos2d::Object::*SEL_FrameEventCallFunc)(Bone *, const char *, in
|
|||
struct FrameEvent
|
||||
{
|
||||
Bone *bone;
|
||||
const char *frameEventName;
|
||||
std::string frameEventName;
|
||||
int originFrameIndex;
|
||||
int currentFrameIndex;
|
||||
};
|
||||
|
@ -62,7 +62,7 @@ struct MovementEvent
|
|||
{
|
||||
Armature *armature;
|
||||
MovementEventType movementType;
|
||||
const char *movementID;
|
||||
std::string movementID;
|
||||
};
|
||||
|
||||
class ArmatureAnimation : public ProcessBase
|
||||
|
@ -123,7 +123,7 @@ public:
|
|||
* loop = 0 : this animation is not loop
|
||||
* loop > 0 : this animation is loop
|
||||
*/
|
||||
virtual void play(const char *animationName, int durationTo = -1, int loop = -1);
|
||||
virtual void play(const std::string& animationName, int durationTo = -1, int loop = -1);
|
||||
|
||||
/**
|
||||
* Play animation by index, the other param is the same to play.
|
||||
|
@ -191,8 +191,8 @@ public:
|
|||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE void setFrameEventCallFunc(cocos2d::Object *target, SEL_FrameEventCallFunc callFunc);
|
||||
|
||||
void setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const char *movementID)> listener);
|
||||
void setFrameEventCallFunc(std::function<void(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)> listener);
|
||||
void setMovementEventCallFunc(std::function<void(Armature *armature, MovementEventType movementType, const std::string& movementID)> listener);
|
||||
void setFrameEventCallFunc(std::function<void(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex)> listener);
|
||||
|
||||
virtual void setAnimationData(AnimationData *data)
|
||||
{
|
||||
|
@ -254,12 +254,12 @@ protected:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex);
|
||||
void frameEvent(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex);
|
||||
|
||||
/**
|
||||
* Emit a movement event
|
||||
*/
|
||||
void movementEvent(Armature *armature, MovementEventType movementType, const char *movementID);
|
||||
void movementEvent(Armature *armature, MovementEventType movementType, const std::string& movementID);
|
||||
|
||||
void updateMovementList();
|
||||
|
||||
|
@ -319,8 +319,8 @@ protected:
|
|||
cocos2d::Object *_frameEventTarget;
|
||||
|
||||
|
||||
std::function<void(Armature *armature, MovementEventType movementType, const char *movementID)> _movementEventListener;
|
||||
std::function<void(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)> _frameEventListener;
|
||||
std::function<void(Armature *armature, MovementEventType movementType, const std::string& movementID)> _movementEventListener;
|
||||
std::function<void(Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex)> _frameEventListener;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ bool ArmatureDataManager::init()
|
|||
return bRet;
|
||||
}
|
||||
|
||||
void ArmatureDataManager::removeArmatureFileInfo(const char *configFilePath)
|
||||
void ArmatureDataManager::removeArmatureFileInfo(const std::string& configFilePath)
|
||||
{
|
||||
if (RelativeData *data = getRelativeData(configFilePath))
|
||||
{
|
||||
|
@ -119,7 +119,7 @@ void ArmatureDataManager::removeArmatureFileInfo(const char *configFilePath)
|
|||
}
|
||||
|
||||
|
||||
void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData, const char *configFilePath)
|
||||
void ArmatureDataManager::addArmatureData(const std::string& id, ArmatureData *armatureData, const std::string& configFilePath)
|
||||
{
|
||||
if (RelativeData *data = getRelativeData(configFilePath))
|
||||
{
|
||||
|
@ -129,19 +129,19 @@ void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armature
|
|||
_armarureDatas.insert(id, armatureData);
|
||||
}
|
||||
|
||||
ArmatureData *ArmatureDataManager::getArmatureData(const char *id)
|
||||
ArmatureData *ArmatureDataManager::getArmatureData(const std::string& id)
|
||||
{
|
||||
ArmatureData *armatureData = nullptr;
|
||||
armatureData = (ArmatureData *)_armarureDatas.at(id);
|
||||
return armatureData;
|
||||
}
|
||||
|
||||
void ArmatureDataManager::removeArmatureData(const char *id)
|
||||
void ArmatureDataManager::removeArmatureData(const std::string& id)
|
||||
{
|
||||
_armarureDatas.erase(id);
|
||||
}
|
||||
|
||||
void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData, const char *configFilePath)
|
||||
void ArmatureDataManager::addAnimationData(const std::string& id, AnimationData *animationData, const std::string& configFilePath)
|
||||
{
|
||||
if (RelativeData *data = getRelativeData(configFilePath))
|
||||
{
|
||||
|
@ -151,19 +151,19 @@ void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animat
|
|||
_animationDatas.insert(id, animationData);
|
||||
}
|
||||
|
||||
AnimationData *ArmatureDataManager::getAnimationData(const char *id)
|
||||
AnimationData *ArmatureDataManager::getAnimationData(const std::string& id)
|
||||
{
|
||||
AnimationData *animationData = nullptr;
|
||||
animationData = (AnimationData *)_animationDatas.at(id);
|
||||
return animationData;
|
||||
}
|
||||
|
||||
void ArmatureDataManager::removeAnimationData(const char *id)
|
||||
void ArmatureDataManager::removeAnimationData(const std::string& id)
|
||||
{
|
||||
_animationDatas.erase(id);
|
||||
}
|
||||
|
||||
void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData, const char *configFilePath)
|
||||
void ArmatureDataManager::addTextureData(const std::string& id, TextureData *textureData, const std::string& configFilePath)
|
||||
{
|
||||
if (RelativeData *data = getRelativeData(configFilePath))
|
||||
{
|
||||
|
@ -174,7 +174,7 @@ void ArmatureDataManager::addTextureData(const char *id, TextureData *textureDat
|
|||
}
|
||||
|
||||
|
||||
TextureData *ArmatureDataManager::getTextureData(const char *id)
|
||||
TextureData *ArmatureDataManager::getTextureData(const std::string& id)
|
||||
{
|
||||
TextureData *textureData = nullptr;
|
||||
textureData = (TextureData *)_textureDatas.at(id);
|
||||
|
@ -182,12 +182,12 @@ TextureData *ArmatureDataManager::getTextureData(const char *id)
|
|||
}
|
||||
|
||||
|
||||
void ArmatureDataManager::removeTextureData(const char *id)
|
||||
void ArmatureDataManager::removeTextureData(const std::string& id)
|
||||
{
|
||||
_textureDatas.erase(id);
|
||||
}
|
||||
|
||||
void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath)
|
||||
void ArmatureDataManager::addArmatureFileInfo(const std::string& configFilePath)
|
||||
{
|
||||
addRelativeData(configFilePath);
|
||||
|
||||
|
@ -195,7 +195,7 @@ void ArmatureDataManager::addArmatureFileInfo(const char *configFilePath)
|
|||
DataReaderHelper::getInstance()->addDataFromFile(configFilePath);
|
||||
}
|
||||
|
||||
void ArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, Object *target, SEL_SCHEDULE selector)
|
||||
void ArmatureDataManager::addArmatureFileInfoAsync(const std::string& configFilePath, Object *target, SEL_SCHEDULE selector)
|
||||
{
|
||||
addRelativeData(configFilePath);
|
||||
|
||||
|
@ -203,7 +203,7 @@ void ArmatureDataManager::addArmatureFileInfoAsync(const char *configFilePath, O
|
|||
DataReaderHelper::getInstance()->addDataFromFileAsync("", "", configFilePath, target, selector);
|
||||
}
|
||||
|
||||
void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath)
|
||||
void ArmatureDataManager::addArmatureFileInfo(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath)
|
||||
{
|
||||
addRelativeData(configFilePath);
|
||||
|
||||
|
@ -212,7 +212,7 @@ void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char
|
|||
addSpriteFrameFromFile(plistPath, imagePath);
|
||||
}
|
||||
|
||||
void ArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, Object *target, SEL_SCHEDULE selector)
|
||||
void ArmatureDataManager::addArmatureFileInfoAsync(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath, Object *target, SEL_SCHEDULE selector)
|
||||
{
|
||||
addRelativeData(configFilePath);
|
||||
|
||||
|
@ -221,7 +221,7 @@ void ArmatureDataManager::addArmatureFileInfoAsync(const char *imagePath, const
|
|||
addSpriteFrameFromFile(plistPath, imagePath);
|
||||
}
|
||||
|
||||
void ArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath, const char *configFilePath)
|
||||
void ArmatureDataManager::addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath, const std::string& configFilePath)
|
||||
{
|
||||
if (RelativeData *data = getRelativeData(configFilePath))
|
||||
{
|
||||
|
@ -249,7 +249,7 @@ const cocos2d::Map<std::string, TextureData*>& ArmatureDataManager::getTextureDa
|
|||
return _textureDatas;
|
||||
}
|
||||
|
||||
void CCArmatureDataManager::addRelativeData(const char *configFilePath)
|
||||
void CCArmatureDataManager::addRelativeData(const std::string& configFilePath)
|
||||
{
|
||||
if (_relativeDatas.find(configFilePath) == _relativeDatas.end())
|
||||
{
|
||||
|
@ -257,7 +257,7 @@ void CCArmatureDataManager::addRelativeData(const char *configFilePath)
|
|||
}
|
||||
}
|
||||
|
||||
RelativeData *CCArmatureDataManager::getRelativeData(const char* configFilePath)
|
||||
RelativeData *CCArmatureDataManager::getRelativeData(const std::string& configFilePath)
|
||||
{
|
||||
return &_relativeDatas[configFilePath];
|
||||
}
|
||||
|
|
|
@ -77,89 +77,89 @@ public:
|
|||
* @param id The id of the armature data
|
||||
* @param armatureData ArmatureData *
|
||||
*/
|
||||
void addArmatureData(const char *id, ArmatureData *armatureData, const char *configFilePath = "");
|
||||
void addArmatureData(const std::string& id, ArmatureData *armatureData, const std::string& configFilePath = "");
|
||||
|
||||
/**
|
||||
* @brief get armature data
|
||||
* @param id the id of the armature data you want to get
|
||||
* @return ArmatureData *
|
||||
*/
|
||||
ArmatureData *getArmatureData(const char *id);
|
||||
ArmatureData *getArmatureData(const std::string& id);
|
||||
|
||||
/**
|
||||
* @brief remove armature data
|
||||
* @param id the id of the armature data you want to get
|
||||
*/
|
||||
void removeArmatureData(const char *id);
|
||||
void removeArmatureData(const std::string& id);
|
||||
|
||||
/**
|
||||
* @brief add animation data
|
||||
* @param id the id of the animation data
|
||||
* @return AnimationData *
|
||||
*/
|
||||
void addAnimationData(const char *id, AnimationData *animationData, const char *configFilePath = "");
|
||||
void addAnimationData(const std::string& id, AnimationData *animationData, const std::string& configFilePath = "");
|
||||
|
||||
/**
|
||||
* @brief get animation data from _animationDatas(Dictionary)
|
||||
* @param id the id of the animation data you want to get
|
||||
* @return AnimationData *
|
||||
*/
|
||||
AnimationData *getAnimationData(const char *id);
|
||||
AnimationData *getAnimationData(const std::string& id);
|
||||
|
||||
/**
|
||||
* @brief remove animation data
|
||||
* @param id the id of the animation data
|
||||
*/
|
||||
void removeAnimationData(const char *id);
|
||||
void removeAnimationData(const std::string& id);
|
||||
|
||||
/**
|
||||
* @brief add texture data
|
||||
* @param id the id of the texture data
|
||||
* @return TextureData *
|
||||
*/
|
||||
void addTextureData(const char *id, TextureData *textureData, const char *configFilePath = "");
|
||||
void addTextureData(const std::string& id, TextureData *textureData, const std::string& configFilePath = "");
|
||||
|
||||
/**
|
||||
* @brief get texture data
|
||||
* @param id the id of the texture data you want to get
|
||||
* @return TextureData *
|
||||
*/
|
||||
TextureData *getTextureData(const char *id);
|
||||
TextureData *getTextureData(const std::string& id);
|
||||
|
||||
/**
|
||||
* @brief remove texture data
|
||||
* @param id the id of the texture data you want to get
|
||||
*/
|
||||
void removeTextureData(const char *id);
|
||||
void removeTextureData(const std::string& id);
|
||||
|
||||
/**
|
||||
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
|
||||
*/
|
||||
void addArmatureFileInfo(const char *configFilePath);
|
||||
void addArmatureFileInfo(const std::string& configFilePath);
|
||||
|
||||
/**
|
||||
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
|
||||
* It will load data in a new thread
|
||||
*/
|
||||
void addArmatureFileInfoAsync(const char *configFilePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector);
|
||||
void addArmatureFileInfoAsync(const std::string& configFilePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector);
|
||||
|
||||
/**
|
||||
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
|
||||
*/
|
||||
void addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath);
|
||||
void addArmatureFileInfo(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath);
|
||||
|
||||
/**
|
||||
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
|
||||
* It will load data in a new thread
|
||||
*/
|
||||
void addArmatureFileInfoAsync(const char *imagePath, const char *plistPath, const char *configFilePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector);
|
||||
void addArmatureFileInfoAsync(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector);
|
||||
|
||||
/**
|
||||
* @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name
|
||||
*/
|
||||
void addSpriteFrameFromFile(const char *plistPath, const char *imagePath, const char *configFilePath = "");
|
||||
void addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath, const std::string& configFilePath = "");
|
||||
|
||||
virtual void removeArmatureFileInfo(const char *configFilePath);
|
||||
virtual void removeArmatureFileInfo(const std::string& configFilePath);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -173,8 +173,8 @@ public:
|
|||
const cocos2d::Map<std::string, TextureData*>& getTextureDatas() const;
|
||||
|
||||
protected:
|
||||
void addRelativeData(const char* configFilePath);
|
||||
RelativeData *getRelativeData(const char* configFilePath);
|
||||
void addRelativeData(const std::string& configFilePath);
|
||||
RelativeData *getRelativeData(const std::string& configFilePath);
|
||||
private:
|
||||
/**
|
||||
* @brief save amature datas
|
||||
|
|
|
@ -47,7 +47,7 @@ Bone *Bone::create()
|
|||
|
||||
}
|
||||
|
||||
Bone *Bone::create(const char *name)
|
||||
Bone *Bone::create(const std::string& name)
|
||||
{
|
||||
|
||||
Bone *pBone = new Bone();
|
||||
|
@ -101,16 +101,13 @@ bool Bone::init()
|
|||
}
|
||||
|
||||
|
||||
bool Bone::init(const char *name)
|
||||
bool Bone::init(const std::string& name)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
|
||||
if(nullptr != name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
_name = name;
|
||||
|
||||
CC_SAFE_DELETE(_tweenData);
|
||||
_tweenData = new FrameData();
|
||||
|
@ -425,7 +422,7 @@ void Bone::changeDisplayByIndex(int index, bool force)
|
|||
}
|
||||
|
||||
|
||||
void Bone::changeDisplayByName(const char *name, bool force)
|
||||
void Bone::changeDisplayByName(const std::string& name, bool force)
|
||||
{
|
||||
_displayManager->changeDisplayByName(name, force);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
* @param name If name is not null, then set name to the bone's name
|
||||
* @return A initialized bone which is marked as "autorelease".
|
||||
*/
|
||||
static Bone *create(const char *name);
|
||||
static Bone *create(const std::string& name);
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
* Initializes a Bone with the specified name
|
||||
* @param name Bone's name.
|
||||
*/
|
||||
virtual bool init(const char *name);
|
||||
virtual bool init(const std::string& name);
|
||||
|
||||
/**
|
||||
* Add display and use displayData to init the display.
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
void removeDisplay(int index);
|
||||
|
||||
void changeDisplayByIndex(int index, bool force);
|
||||
void changeDisplayByName(const char *name, bool force);
|
||||
void changeDisplayByName(const std::string& name, bool force);
|
||||
|
||||
/**
|
||||
* Add a child to this bone, and it will let this child call setParent(Bone *parent) function to set self to it's parent
|
||||
|
|
|
@ -59,8 +59,6 @@ static const char *A_MOVEMENT_SCALE = "sc";
|
|||
static const char *A_MOVEMENT_DELAY = "dl";
|
||||
static const char *A_DISPLAY_INDEX = "dI";
|
||||
|
||||
// static const char *A_VERT = "vert";
|
||||
// static const char *A_FRAG = "frag";
|
||||
static const char *A_PLIST = "plist";
|
||||
|
||||
static const char *A_PARENT = "parent";
|
||||
|
@ -73,9 +71,8 @@ static const char *A_EVENT = "evt";
|
|||
static const char *A_SOUND = "sd";
|
||||
static const char *A_SOUND_EFFECT = "sdE";
|
||||
static const char *A_TWEEN_EASING = "twE";
|
||||
//static const char *A_EASING_PARAM_NUMBER = "twEPN";
|
||||
static const char *A_EASING_PARAM = "twEP";
|
||||
//static const char *A_TWEEN_ROTATE = "twR";
|
||||
static const char *A_TWEEN_ROTATE = "twR";
|
||||
static const char *A_IS_ARMATURE = "isArmature";
|
||||
static const char *A_DISPLAY_TYPE = "displayType";
|
||||
static const char *A_MOVEMENT = "mov";
|
||||
|
@ -108,17 +105,12 @@ static const char *A_GREEN_OFFSET = "gM";
|
|||
static const char *A_BLUE_OFFSET = "bM";
|
||||
static const char *A_COLOR_TRANSFORM = "colorTransform";
|
||||
static const char *A_TWEEN_FRAME = "tweenFrame";
|
||||
//static const char *A_ROTATION = "rotation";
|
||||
//static const char *A_USE_COLOR_INFO = "uci";
|
||||
|
||||
|
||||
|
||||
static const char *CONTOUR = "con";
|
||||
static const char *CONTOUR_VERTEX = "con_vt";
|
||||
|
||||
//static const char *MOVEMENT_EVENT_FRAME = "movementEventFrame";
|
||||
//static const char *SOUND_FRAME = "soundFrame";
|
||||
|
||||
|
||||
static const char *FL_NAN = "NaN";
|
||||
|
||||
|
@ -262,14 +254,14 @@ DataReaderHelper::~DataReaderHelper()
|
|||
_dataReaderHelper = nullptr;
|
||||
}
|
||||
|
||||
void DataReaderHelper::addDataFromFile(const char *filePath)
|
||||
void DataReaderHelper::addDataFromFile(const std::string& filePath)
|
||||
{
|
||||
/*
|
||||
* Check if file is already added to ArmatureDataManager, if then return.
|
||||
*/
|
||||
for(unsigned int i = 0; i < _configFileList.size(); i++)
|
||||
{
|
||||
if (_configFileList[i].compare(filePath) == 0)
|
||||
if (_configFileList[i] == filePath)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -295,34 +287,38 @@ void DataReaderHelper::addDataFromFile(const char *filePath)
|
|||
size_t startPos = filePathStr.find_last_of(".");
|
||||
std::string str = &filePathStr[startPos];
|
||||
|
||||
// Read content from file
|
||||
ssize_t size;
|
||||
std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
char *pFileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size);
|
||||
unsigned char *pTempContent = (unsigned char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size);
|
||||
|
||||
std::string contentStr = std::string((const char*)pTempContent, size);
|
||||
|
||||
DataInfo dataInfo;
|
||||
dataInfo.filename = filePathStr;
|
||||
dataInfo.asyncStruct = nullptr;
|
||||
dataInfo.baseFilePath = basefilePath;
|
||||
|
||||
if (str.compare(".xml") == 0)
|
||||
if (str == ".xml")
|
||||
{
|
||||
DataReaderHelper::addDataFromCache(pFileContent, &dataInfo);
|
||||
DataReaderHelper::addDataFromCache(contentStr, &dataInfo);
|
||||
}
|
||||
else if(str.compare(".json") == 0 || str.compare(".ExportJson") == 0)
|
||||
else if(str == ".json" || str == ".ExportJson")
|
||||
{
|
||||
DataReaderHelper::addDataFromJsonCache(pFileContent, &dataInfo);
|
||||
DataReaderHelper::addDataFromJsonCache(contentStr, &dataInfo);
|
||||
}
|
||||
free(pFileContent);
|
||||
|
||||
free(pTempContent);
|
||||
}
|
||||
|
||||
void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *plistPath, const char *filePath, Object *target, SEL_SCHEDULE selector)
|
||||
void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, Object *target, SEL_SCHEDULE selector)
|
||||
{
|
||||
/*
|
||||
* Check if file is already added to ArmatureDataManager, if then return.
|
||||
*/
|
||||
for(unsigned int i = 0; i < _configFileList.size(); i++)
|
||||
{
|
||||
if (_configFileList[i].compare(filePath) == 0)
|
||||
if (_configFileList[i] == filePath)
|
||||
{
|
||||
if (target && selector)
|
||||
{
|
||||
|
@ -400,11 +396,11 @@ void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *p
|
|||
// XXX fileContent is being leaked
|
||||
data->fileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size);
|
||||
|
||||
if (str.compare(".xml") == 0)
|
||||
if (str == ".xml")
|
||||
{
|
||||
data->configType = DragonBone_XML;
|
||||
}
|
||||
else if(str.compare(".json") == 0 || str.compare(".ExportJson") == 0)
|
||||
else if(str == ".json" || str == ".ExportJson")
|
||||
{
|
||||
data->configType = CocoStudio_JSON;
|
||||
}
|
||||
|
@ -478,7 +474,7 @@ void DataReaderHelper::addDataAsyncCallBack(float dt)
|
|||
}
|
||||
|
||||
|
||||
void DataReaderHelper::removeConfigFile(const char *configFile)
|
||||
void DataReaderHelper::removeConfigFile(const std::string& configFile)
|
||||
{
|
||||
std::vector<std::string>::iterator it = _configFileList.end();
|
||||
for (std::vector<std::string>::iterator i = _configFileList.begin(); i != _configFileList.end(); i++)
|
||||
|
@ -497,10 +493,10 @@ void DataReaderHelper::removeConfigFile(const char *configFile)
|
|||
|
||||
|
||||
|
||||
void DataReaderHelper::addDataFromCache(const char *pFileContent, DataInfo *dataInfo)
|
||||
void DataReaderHelper::addDataFromCache(const std::string& pFileContent, DataInfo *dataInfo)
|
||||
{
|
||||
tinyxml2::XMLDocument document;
|
||||
document.Parse(pFileContent);
|
||||
document.Parse(pFileContent.c_str());
|
||||
|
||||
tinyxml2::XMLElement *root = document.RootElement();
|
||||
CCASSERT(root, "XML error or XML is empty.");
|
||||
|
@ -600,7 +596,7 @@ ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML
|
|||
std::string parentNameStr = parentName;
|
||||
while (parentXML)
|
||||
{
|
||||
if (parentNameStr.compare(parentXML->Attribute(A_NAME)) == 0)
|
||||
if (parentNameStr == parentXML->Attribute(A_NAME))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -745,7 +741,7 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML
|
|||
if(_easing != nullptr)
|
||||
{
|
||||
std::string str = _easing;
|
||||
if(str.compare(FL_NAN) != 0)
|
||||
if(str != FL_NAN)
|
||||
{
|
||||
if( movementXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS)
|
||||
{
|
||||
|
@ -782,7 +778,7 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML
|
|||
|
||||
while (parentXml)
|
||||
{
|
||||
if (parentName.compare(parentXml->Attribute(A_NAME)) == 0)
|
||||
if (parentName == parentXml->Attribute(A_NAME))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -921,8 +917,8 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov
|
|||
|
||||
FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, BoneData *boneData, DataInfo *dataInfo)
|
||||
{
|
||||
float x, y, scale_x, scale_y, skew_x, skew_y = 0;
|
||||
int duration, displayIndex, zOrder, tweenEasing, blendType = 0;
|
||||
float x = 0, y = 0, scale_x = 0, scale_y = 0, skew_x = 0, skew_y = 0, tweenRotate = 0;
|
||||
int duration = 0, displayIndex = 0, zOrder = 0, tweenEasing = 0, blendType = 0;
|
||||
|
||||
FrameData *frameData = new FrameData();
|
||||
|
||||
|
@ -1005,6 +1001,10 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm
|
|||
{
|
||||
frameData->zOrder = zOrder;
|
||||
}
|
||||
if( frameXML->QueryFloatAttribute(A_TWEEN_ROTATE, &tweenRotate) == tinyxml2::XML_SUCCESS )
|
||||
{
|
||||
frameData->tweenRotate = tweenRotate;
|
||||
}
|
||||
if ( frameXML->QueryIntAttribute(A_BLEND_TYPE, &blendType) == tinyxml2::XML_SUCCESS )
|
||||
{
|
||||
switch (blendType)
|
||||
|
@ -1070,7 +1070,7 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm
|
|||
if(_easing != nullptr)
|
||||
{
|
||||
std::string str = _easing;
|
||||
if(str.compare(FL_NAN) != 0)
|
||||
if(str != FL_NAN)
|
||||
{
|
||||
if( frameXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS)
|
||||
{
|
||||
|
@ -1184,10 +1184,10 @@ ContourData *DataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML, D
|
|||
|
||||
|
||||
|
||||
void DataReaderHelper::addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo)
|
||||
void DataReaderHelper::addDataFromJsonCache(const std::string& fileContent, DataInfo *dataInfo)
|
||||
{
|
||||
JsonDictionary json;
|
||||
json.initWithDescription(fileContent);
|
||||
json.initWithDescription(fileContent.c_str());
|
||||
|
||||
dataInfo->contentScale = json.getItemFloatValue(CONTENT_SCALE, 1);
|
||||
|
||||
|
|
|
@ -108,12 +108,12 @@ public:
|
|||
*/
|
||||
~DataReaderHelper();
|
||||
|
||||
void addDataFromFile(const char *filePath);
|
||||
void addDataFromFileAsync(const char *imagePath, const char *plistPath, const char *filePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector);
|
||||
void addDataFromFile(const std::string& filePath);
|
||||
void addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, cocos2d::Object *target, cocos2d::SEL_SCHEDULE selector);
|
||||
|
||||
void addDataAsyncCallBack(float dt);
|
||||
|
||||
void removeConfigFile(const char *configFile);
|
||||
void removeConfigFile(const std::string& configFile);
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -122,7 +122,7 @@ public:
|
|||
*
|
||||
* @param xmlPath The cache of the xml
|
||||
*/
|
||||
static void addDataFromCache(const char *pFileContent, DataInfo *dataInfo = nullptr);
|
||||
static void addDataFromCache(const std::string& pFileContent, DataInfo *dataInfo = nullptr);
|
||||
|
||||
|
||||
|
||||
|
@ -154,7 +154,7 @@ public:
|
|||
static ContourData *decodeContour(tinyxml2::XMLElement *contourXML, DataInfo *dataInfo);
|
||||
|
||||
public:
|
||||
static void addDataFromJsonCache(const char *fileContent, DataInfo *dataInfo = nullptr);
|
||||
static void addDataFromJsonCache(const std::string& fileContent, DataInfo *dataInfo = nullptr);
|
||||
|
||||
static ArmatureData *decodeArmature(JsonDictionary &json, DataInfo *dataInfo);
|
||||
static BoneData *decodeBone(JsonDictionary &json, DataInfo *dataInfo);
|
||||
|
|
|
@ -123,8 +123,8 @@ void BaseData::subtract(BaseData *from, BaseData *to, bool limit)
|
|||
|
||||
if (to->tweenRotate)
|
||||
{
|
||||
skewX += to->tweenRotate;
|
||||
skewY -= to->tweenRotate;
|
||||
skewX += to->tweenRotate * M_PI * 2;
|
||||
skewY -= to->tweenRotate * M_PI * 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ Color4B BaseData::getColor()
|
|||
return Color4B(r, g, b, a);
|
||||
}
|
||||
|
||||
const char *DisplayData::changeDisplayToTexture(const char *displayName)
|
||||
const std::string& DisplayData::changeDisplayToTexture(const std::string& displayName)
|
||||
{
|
||||
// remove .xxx
|
||||
std::string textureName = displayName;
|
||||
|
@ -241,7 +241,7 @@ void ArmatureData::addBoneData(BoneData *boneData)
|
|||
boneDataDic.insert(boneData->name, boneData);
|
||||
}
|
||||
|
||||
BoneData *ArmatureData::getBoneData(const char *boneName)
|
||||
BoneData *ArmatureData::getBoneData(const std::string& boneName)
|
||||
{
|
||||
return static_cast<BoneData*>(boneDataDic.at(boneName));
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ void MovementData::addMovementBoneData(MovementBoneData *movBoneData)
|
|||
movBoneDataDic.insert(movBoneData->name, movBoneData);
|
||||
}
|
||||
|
||||
MovementBoneData *MovementData::getMovementBoneData(const char *boneName)
|
||||
MovementBoneData *MovementData::getMovementBoneData(const std::string& boneName)
|
||||
{
|
||||
return movBoneDataDic.at(boneName);
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ void AnimationData::addMovement(MovementData *movData)
|
|||
movementNames.push_back(movData->name);
|
||||
}
|
||||
|
||||
MovementData *AnimationData::getMovement(const char *movementName)
|
||||
MovementData *AnimationData::getMovement(const std::string& movementName)
|
||||
{
|
||||
return movementDataDic.at(movementName);
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ class DisplayData : public cocos2d::Object
|
|||
public:
|
||||
CC_CREATE_NO_PARAM_NO_INIT(DisplayData)
|
||||
|
||||
static const char *changeDisplayToTexture(const char *displayName);
|
||||
static const std::string& changeDisplayToTexture(const std::string& displayName);
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
|
@ -279,7 +279,7 @@ public:
|
|||
|
||||
bool init();
|
||||
void addBoneData(BoneData *boneData);
|
||||
BoneData *getBoneData(const char *boneName);
|
||||
BoneData *getBoneData(const std::string& boneName);
|
||||
public:
|
||||
std::string name;
|
||||
cocos2d::Map<std::string, BoneData*> boneDataDic;
|
||||
|
@ -403,7 +403,7 @@ public:
|
|||
~MovementData(void);
|
||||
|
||||
void addMovementBoneData(MovementBoneData *movBoneData);
|
||||
MovementBoneData *getMovementBoneData(const char *boneName);
|
||||
MovementBoneData *getMovementBoneData(const std::string& boneName);
|
||||
public:
|
||||
std::string name;
|
||||
int duration; //! the frames this movement will last
|
||||
|
@ -435,7 +435,7 @@ public:
|
|||
|
||||
/**
|
||||
* @brief save movment bone data
|
||||
* @key const char *
|
||||
* @key const std::string&
|
||||
* @value MovementBoneData *
|
||||
*/
|
||||
cocos2d::Map<std::string, MovementBoneData*> movBoneDataDic;
|
||||
|
@ -465,7 +465,7 @@ public:
|
|||
~AnimationData(void);
|
||||
|
||||
void addMovement(MovementData *movData);
|
||||
MovementData *getMovement(const char *movementName);
|
||||
MovementData *getMovement(const std::string& movementName);
|
||||
ssize_t getMovementCount();
|
||||
public:
|
||||
std::string name;
|
||||
|
|
|
@ -243,7 +243,7 @@ void DisplayManager::changeDisplayByIndex(int index, bool force)
|
|||
setCurrentDecorativeDisplay(decoDisplay);
|
||||
}
|
||||
|
||||
void CCDisplayManager::changeDisplayByName(const char *name, bool force)
|
||||
void CCDisplayManager::changeDisplayByName(const std::string& name, bool force)
|
||||
{
|
||||
for (int i = 0; i<_decoDisplayList.size(); i++)
|
||||
{
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
*/
|
||||
void changeDisplayByIndex(int index, bool force);
|
||||
|
||||
void changeDisplayByName(const char *name, bool force);
|
||||
void changeDisplayByName(const std::string& name, bool force);
|
||||
|
||||
cocos2d::Node *getDisplayRenderNode() const;
|
||||
DisplayType getDisplayRenderNodeType() const;
|
||||
|
|
|
@ -51,7 +51,7 @@ Skin *Skin::create()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName)
|
||||
Skin *Skin::createWithSpriteFrameName(const std::string& pszSpriteFrameName)
|
||||
{
|
||||
Skin *skin = new Skin();
|
||||
if(skin && skin->initWithSpriteFrameName(pszSpriteFrameName))
|
||||
|
@ -63,7 +63,7 @@ Skin *Skin::createWithSpriteFrameName(const char *pszSpriteFrameName)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Skin *Skin::create(const char *pszFileName)
|
||||
Skin *Skin::create(const std::string& pszFileName)
|
||||
{
|
||||
Skin *skin = new Skin();
|
||||
if(skin && skin->initWithFile(pszFileName))
|
||||
|
|
|
@ -34,8 +34,8 @@ class Skin : public cocos2d::Sprite
|
|||
{
|
||||
public:
|
||||
static Skin *create();
|
||||
static Skin *createWithSpriteFrameName(const char *pszSpriteFrameName);
|
||||
static Skin *create(const char *pszFileName);
|
||||
static Skin *createWithSpriteFrameName(const std::string& pszSpriteFrameName);
|
||||
static Skin *create(const std::string& pszFileName);
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
|
|
|
@ -47,7 +47,7 @@ void SpriteFrameCacheHelper::purge()
|
|||
_spriteFrameCacheHelper = nullptr;
|
||||
}
|
||||
|
||||
void SpriteFrameCacheHelper::addSpriteFrameFromFile(const char *plistPath, const char *imagePath)
|
||||
void SpriteFrameCacheHelper::addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath)
|
||||
{
|
||||
CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath, imagePath);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
/**
|
||||
* @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name
|
||||
*/
|
||||
void addSpriteFrameFromFile(const char *plistPath, const char *imagePath);
|
||||
void addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath);
|
||||
|
||||
private:
|
||||
SpriteFrameCacheHelper();
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace spine {
|
|||
/**
|
||||
Draws a skeleton.
|
||||
*/
|
||||
class CCSkeleton: public cocos2d::NodeRGBA, public cocos2d::BlendProtocol {
|
||||
class CCSkeleton: public cocos2d::Node, public cocos2d::BlendProtocol {
|
||||
public:
|
||||
spSkeleton* skeleton;
|
||||
spBone* rootBone;
|
||||
|
|
|
@ -555,7 +555,7 @@ void PhysicsBody::setVelocity(const Point& velocity)
|
|||
{
|
||||
if (!_dynamic)
|
||||
{
|
||||
CCLOG("physics warning: your cann't set velocity for a static body.");
|
||||
CCLOG("physics warning: your can't set velocity for a static body.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -581,7 +581,7 @@ void PhysicsBody::setAngularVelocity(float velocity)
|
|||
{
|
||||
if (!_dynamic)
|
||||
{
|
||||
CCLOG("physics warning: your cann't set angular velocity for a static body.");
|
||||
CCLOG("physics warning: your can't set angular velocity for a static body.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 0130b23910e0fe7aa27738403c84ee259677a1b8
|
||||
Subproject commit daff147b1ff3d3754cb014c4e9c575676dea68b9
|
|
@ -14,7 +14,8 @@ LOCAL_SRC_FILES := ScriptingCore.cpp \
|
|||
jsb_opengl_functions.cpp \
|
||||
jsb_opengl_manual.cpp \
|
||||
jsb_opengl_registration.cpp \
|
||||
../../auto-generated/js-bindings/jsb_cocos2dx_auto.cpp
|
||||
../../auto-generated/js-bindings/jsb_cocos2dx_auto.cpp \
|
||||
../../auto-generated/js-bindings/jsb_cocos2dx_spine_auto.cpp
|
||||
|
||||
LOCAL_CFLAGS := -DCOCOS2D_JAVASCRIPT
|
||||
|
||||
|
@ -24,7 +25,10 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) \
|
|||
$(LOCAL_PATH)/../../../audio/include \
|
||||
$(LOCAL_PATH)/../../../storage \
|
||||
$(LOCAL_PATH)/../../auto-generated/js-bindings \
|
||||
$(LOCAL_PATH)/../../../../extensions
|
||||
$(LOCAL_PATH)/../../../../extensions \
|
||||
$(LOCAL_PATH)/../../../editor-support/spine \
|
||||
$(LOCAL_PATH)/../../../editor-support
|
||||
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
|
||||
$(LOCAL_PATH)/../../auto-generated/js-bindings \
|
||||
|
|
|
@ -1 +1 @@
|
|||
7ca5b334921bd71783d2c8fb31efc09f8dea8afd
|
||||
9af2a4febb0a58cf084fc9adfb24c1ac8138cd27
|
|
@ -350,7 +350,7 @@ private:
|
|||
return false;
|
||||
}
|
||||
|
||||
bool callJSDelegate(TableView* table, long idx, std::string jsFunctionName, jsval& retVal)
|
||||
bool callJSDelegate(TableView* table, ssize_t idx, std::string jsFunctionName, jsval& retVal)
|
||||
{
|
||||
js_proxy_t * p = jsb_get_native_proxy(table);
|
||||
if (!p) return false;
|
||||
|
@ -360,7 +360,7 @@ private:
|
|||
JS::RootedValue temp_retval(cx);
|
||||
jsval dataVal[2];
|
||||
dataVal[0] = OBJECT_TO_JSVAL(p->obj);
|
||||
dataVal[1] = long_to_jsval(cx,idx);
|
||||
dataVal[1] = ssize_to_jsval(cx,idx);
|
||||
|
||||
JSObject* obj = _JSTableViewDataSource;
|
||||
JSAutoCompartment ac(cx, obj);
|
||||
|
@ -377,9 +377,9 @@ private:
|
|||
return false;
|
||||
}
|
||||
|
||||
JS_CallFunctionName(cx, obj, jsFunctionName.c_str(),
|
||||
JSBool ret = JS_CallFunctionName(cx, obj, jsFunctionName.c_str(),
|
||||
2, dataVal, &retVal);
|
||||
return true;
|
||||
return ret == JS_TRUE ? true : false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_auto.cpp" />
|
||||
<ClCompile Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_spine_auto.cpp" />
|
||||
<ClCompile Include="..\cocos2d_specifics.cpp" />
|
||||
<ClCompile Include="..\jsb_opengl_functions.cpp" />
|
||||
<ClCompile Include="..\jsb_opengl_manual.cpp" />
|
||||
|
@ -23,6 +24,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_auto.hpp" />
|
||||
<ClInclude Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_spine_auto.hpp" />
|
||||
<ClInclude Include="..\cocos2d_specifics.hpp" />
|
||||
<ClInclude Include="..\jsb_helper.h" />
|
||||
<ClInclude Include="..\jsb_opengl_functions.h" />
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
<ClCompile Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_auto.cpp">
|
||||
<Filter>generated</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_spine_auto.cpp">
|
||||
<Filter>generated</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\cocos2d_specifics.hpp">
|
||||
|
@ -79,6 +82,9 @@
|
|||
<ClInclude Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_auto.hpp">
|
||||
<Filter>generated</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_spine_auto.hpp">
|
||||
<Filter>generated</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\auto-generated\js-bindings\jsb_cocos2dx_auto_api.js">
|
||||
|
|
|
@ -1425,14 +1425,81 @@ bool luaval_to_ccvaluevector(lua_State* L, int lo, cocos2d::ValueVector* ret)
|
|||
|
||||
bool luaval_to_std_vector_string(lua_State* L, int lo, std::vector<std::string>* ret)
|
||||
{
|
||||
// TO BE DONE IN CPP FILE
|
||||
return false;
|
||||
if (nullptr == L || nullptr == ret || lua_gettop(L) < lo)
|
||||
return false;
|
||||
|
||||
tolua_Error tolua_err;
|
||||
bool ok = true;
|
||||
if (!tolua_istable(L, lo, 0, &tolua_err))
|
||||
{
|
||||
#if COCOS2D_DEBUG >=1
|
||||
luaval_to_native_err(L,"#ferror:",&tolua_err);
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
size_t len = lua_objlen(L, lo);
|
||||
std::string value = "";
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
lua_pushnumber(L, i + 1);
|
||||
lua_gettable(L,lo);
|
||||
if(lua_isstring(L, -1))
|
||||
{
|
||||
ok = luaval_to_std_string(L, -1, &value);
|
||||
if(ok)
|
||||
ret->push_back(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCASSERT(false, "string type is needed");
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool luaval_to_std_vector_int(lua_State* L, int lo, std::vector<int>* ret)
|
||||
{
|
||||
// TO BE DONE IN CPP FILE
|
||||
return false;
|
||||
if (nullptr == L || nullptr == ret || lua_gettop(L) < lo)
|
||||
return false;
|
||||
|
||||
tolua_Error tolua_err;
|
||||
bool ok = true;
|
||||
if (!tolua_istable(L, lo, 0, &tolua_err))
|
||||
{
|
||||
#if COCOS2D_DEBUG >=1
|
||||
luaval_to_native_err(L,"#ferror:",&tolua_err);
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
size_t len = lua_objlen(L, lo);
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
lua_pushnumber(L, i + 1);
|
||||
lua_gettable(L,lo);
|
||||
if(lua_isnumber(L, -1))
|
||||
{
|
||||
ret->push_back((int)tolua_tonumber(L, -1, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
CCASSERT(false, "int type is needed");
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
void point_to_luaval(lua_State* L,const Point& pt)
|
||||
|
|
|
@ -120,8 +120,47 @@ bool luaval_to_std_vector_int(lua_State* L, int lo, std::vector<int>* ret);
|
|||
template <class T>
|
||||
bool luaval_to_ccmap_string_key(lua_State* L, int lo, cocos2d::Map<std::string, T>* ret)
|
||||
{
|
||||
// TO BE DONE:
|
||||
return false;
|
||||
if(nullptr == L || nullptr == ret || lua_gettop(L) < lo)
|
||||
return false;
|
||||
|
||||
tolua_Error tolua_err;
|
||||
bool ok = true;
|
||||
if (!tolua_istable(L, lo, 0, &tolua_err))
|
||||
{
|
||||
#if COCOS2D_DEBUG >=1
|
||||
luaval_to_native_err(L,"#ferror:",&tolua_err);
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
std::string stringKey = "";
|
||||
lua_pushnil(L); /* first key L: lotable ..... nil */
|
||||
while ( 0 != lua_next(L, lo ) ) /* L: lotable ..... key value */
|
||||
{
|
||||
if (!lua_isstring(L, -2))
|
||||
{
|
||||
lua_pop(L, 1); /* removes 'value'; keep 'key' for next iteration*/
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lua_isnil(L, -1) || !lua_isuserdata(L, -1))
|
||||
{
|
||||
lua_pop(L, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
luaval_to_std_string(L, -2, &stringKey);
|
||||
T obj = static_cast<T>(tolua_tousertype(L, -1, NULL) );
|
||||
if (nullptr != obj)
|
||||
ret->insert(stringKey, obj);
|
||||
|
||||
lua_pop(L, 1); /* L: lotable ..... key */
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
@ -179,7 +218,29 @@ void ccvector_to_luaval(lua_State* L,const cocos2d::Vector<T>& inValue)
|
|||
template <class T>
|
||||
void ccmap_string_key_to_luaval(lua_State* L, const cocos2d::Map<std::string, T>& v)
|
||||
{
|
||||
// TO BE DONE:
|
||||
lua_newtable(L);
|
||||
|
||||
if(nullptr == L)
|
||||
return;
|
||||
|
||||
for (auto iter = v.begin(); iter != v.end(); ++iter)
|
||||
{
|
||||
std::string key = iter->first;
|
||||
T obj = iter->second;
|
||||
if (nullptr != dynamic_cast<cocos2d::Object *>(obj))
|
||||
{
|
||||
std::string name = typeid(*obj).name();
|
||||
auto typeIter = g_luaType.find(name);
|
||||
if (g_luaType.end() != typeIter)
|
||||
{
|
||||
lua_pushstring(L, name.c_str());
|
||||
int ID = (obj) ? (int)obj->_ID : -1;
|
||||
int* luaID = (obj) ? &obj->_luaID : NULL;
|
||||
toluafix_pushusertype_ccobject(L, ID, luaID, (void*)obj,typeIter->second.c_str());
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ccvalue_to_luaval(lua_State* L,const cocos2d::Value& inValue);
|
||||
|
|
|
@ -1 +1 @@
|
|||
1e763897b95ab905739a5f8914e1e3d997a61de1
|
||||
f05859d168dd3698182a8600d48c51d322754463
|
|
@ -53,7 +53,8 @@ TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L,
|
|||
//printf("[LUA] push CCObject OK - refid: %d, ptr: %x, type: %s\n", *p_refid, (int)ptr, type);
|
||||
}
|
||||
|
||||
tolua_pushusertype(L, ptr, type);
|
||||
tolua_pushusertype_and_addtoroot(L, ptr, type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -118,6 +119,10 @@ TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid)
|
|||
lua_pushstring(L, "tolua_ubox"); /* stack: mt key */
|
||||
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: mt ubox */
|
||||
};
|
||||
|
||||
|
||||
// cleanup root
|
||||
tolua_remove_value_from_root(L, ptr);
|
||||
|
||||
lua_pushlightuserdata(L, ptr); /* stack: mt ubox ptr */
|
||||
lua_rawget(L,-2); /* stack: mt ubox ud */
|
||||
|
|
|
@ -300,45 +300,6 @@ end
|
|||
rawset(CCLabelAtlas,"create",CCLabelAtlasDeprecated.create)
|
||||
--functions of CCLabelAtlas will be deprecated end
|
||||
|
||||
--functions of CCCamera will be deprecated begin
|
||||
local CCCameraDeprecated = {}
|
||||
function CCCameraDeprecated.setUpXYZ(self,...)
|
||||
deprecatedTip("CCCameraDeprecated:setUpXYZ","CCCameraDeprecated:setUp")
|
||||
return self:setUp(...)
|
||||
end
|
||||
rawset(CCCamera,"setUpXYZ",CCCameraDeprecated.setUpXYZ)
|
||||
|
||||
function CCCameraDeprecated.getUpXYZ(self)
|
||||
deprecatedTip("CCCameraDeprecated:getUpXYZ","CCCameraDeprecated:getUp")
|
||||
return self:getUp()
|
||||
end
|
||||
rawset(CCCamera,"getUpXYZ",CCCameraDeprecated.getUpXYZ)
|
||||
|
||||
function CCCameraDeprecated.setEyeXYZ(self,...)
|
||||
deprecatedTip("CCCameraDeprecated:setEyeXYZ","CCCameraDeprecated:setEye")
|
||||
return self:setEye(...)
|
||||
end
|
||||
rawset(CCCamera,"setEyeXYZ",CCCameraDeprecated.setEyeXYZ)
|
||||
|
||||
function CCCameraDeprecated.getEyeXYZ(self)
|
||||
deprecatedTip("CCCameraDeprecated:getEyeXYZ","CCCameraDeprecated:getEye")
|
||||
return self:getEye()
|
||||
end
|
||||
rawset(CCCamera,"getEyeXYZ",CCCameraDeprecated.getEyeXYZ)
|
||||
|
||||
function CCCameraDeprecated.setCenterXYZ(self,...)
|
||||
deprecatedTip("CCCameraDeprecated:setCenterXYZ","CCCameraDeprecated:setCenter")
|
||||
return self:setCenter(...)
|
||||
end
|
||||
rawset(CCCamera,"setCenterXYZ",CCCameraDeprecated.setCenterXYZ)
|
||||
|
||||
function CCCameraDeprecated.getCenterXYZ(self)
|
||||
deprecatedTip("CCCameraDeprecated:getCenterXYZ","CCCameraDeprecated:getCenter")
|
||||
return self:getCenter()
|
||||
end
|
||||
rawset(CCCamera,"getCenterXYZ",CCCameraDeprecated.getCenterXYZ)
|
||||
--functions of CCCamera will be deprecated end
|
||||
|
||||
|
||||
---------------------------
|
||||
--global functions wil be deprecated, begin
|
||||
|
|
|
@ -485,16 +485,6 @@ void ScrollView::addChild(Node * child, int zOrder, int tag)
|
|||
}
|
||||
}
|
||||
|
||||
void ScrollView::addChild(Node * child, int zOrder)
|
||||
{
|
||||
this->addChild(child, zOrder, child->getTag());
|
||||
}
|
||||
|
||||
void ScrollView::addChild(Node * child)
|
||||
{
|
||||
this->addChild(child, child->getZOrder(), child->getTag());
|
||||
}
|
||||
|
||||
/**
|
||||
* clip this view so that outside of the visible bounds can be hidden.
|
||||
*/
|
||||
|
|
|
@ -224,9 +224,9 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual void visit() override;
|
||||
|
||||
using Node::addChild;
|
||||
virtual void addChild(Node * child, int zOrder, int tag) override;
|
||||
virtual void addChild(Node * child, int zOrder) override;
|
||||
virtual void addChild(Node * child) override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
|
|
@ -41,6 +41,8 @@ extern "C" {
|
|||
#define TOLUA_PROTECTED_DESTRUCTOR
|
||||
#define TOLUA_PROPERTY_TYPE(p)
|
||||
|
||||
#define TOLUA_VALUE_ROOT "tolua_value_root"
|
||||
|
||||
typedef int lua_Object;
|
||||
|
||||
#include "lua.h"
|
||||
|
@ -117,6 +119,10 @@ TOLUA_API void tolua_pushfieldstring (lua_State* L, int lo, int index, const cha
|
|||
TOLUA_API void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v);
|
||||
TOLUA_API void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, const char* type);
|
||||
TOLUA_API void tolua_pushfieldusertype_and_takeownership (lua_State* L, int lo, int index, void* v, const char* type);
|
||||
|
||||
TOLUA_API void tolua_pushusertype_and_addtoroot (lua_State* L, void* value, const char* type);
|
||||
TOLUA_API void tolua_add_value_to_root (lua_State* L,void* value);
|
||||
TOLUA_API void tolua_remove_value_from_root (lua_State* L, void* value);
|
||||
|
||||
TOLUA_API lua_Number tolua_tonumber (lua_State* L, int narg, lua_Number def);
|
||||
TOLUA_API const char* tolua_tostring (lua_State* L, int narg, const char* def);
|
||||
|
|
|
@ -304,6 +304,11 @@ TOLUA_API void tolua_open (lua_State* L)
|
|||
lua_pushstring(L,"tolua_opened");
|
||||
lua_pushboolean(L,1);
|
||||
lua_rawset(L,LUA_REGISTRYINDEX);
|
||||
|
||||
// create value root table
|
||||
lua_pushstring(L, TOLUA_VALUE_ROOT);
|
||||
lua_newtable(L);
|
||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||
|
||||
#ifndef LUA_VERSION_NUM /* only prior to lua 5.1 */
|
||||
/* create peer object table */
|
||||
|
|
|
@ -17,6 +17,82 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
void tolua_pushusertype_internal (lua_State* L, void* value, const char* type, int addToRoot)
|
||||
{
|
||||
if (value == NULL)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
{
|
||||
luaL_getmetatable(L, type); /* stack: mt */
|
||||
if (lua_isnil(L, -1)) { /* NOT FOUND metatable */
|
||||
lua_pop(L, 1);
|
||||
return;
|
||||
}
|
||||
lua_pushstring(L,"tolua_ubox");
|
||||
lua_rawget(L,-2); /* stack: mt ubox */
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
lua_pushstring(L, "tolua_ubox");
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
};
|
||||
|
||||
lua_pushlightuserdata(L,value); /* stack: mt ubox key<value> */
|
||||
lua_rawget(L,-2); /* stack: mt ubox ubox[value] */
|
||||
|
||||
if (lua_isnil(L,-1))
|
||||
{
|
||||
lua_pop(L,1); /* stack: mt ubox */
|
||||
lua_pushlightuserdata(L,value);
|
||||
*(void**)lua_newuserdata(L,sizeof(void *)) = value; /* stack: mt ubox value newud */
|
||||
lua_pushvalue(L,-1); /* stack: mt ubox value newud newud */
|
||||
lua_insert(L,-4); /* stack: mt newud ubox value newud */
|
||||
lua_rawset(L,-3); /* ubox[value] = newud, stack: mt newud ubox */
|
||||
lua_pop(L,1); /* stack: mt newud */
|
||||
/*luaL_getmetatable(L,type);*/
|
||||
lua_pushvalue(L, -2); /* stack: mt newud mt */
|
||||
lua_setmetatable(L,-2); /* update mt, stack: mt newud */
|
||||
|
||||
#ifdef LUA_VERSION_NUM
|
||||
lua_pushvalue(L, TOLUA_NOPEER); /* stack: mt newud peer */
|
||||
lua_setfenv(L, -2); /* stack: mt newud */
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* check the need of updating the metatable to a more specialized class */
|
||||
lua_insert(L,-2); /* stack: mt ubox[u] ubox */
|
||||
lua_pop(L,1); /* stack: mt ubox[u] */
|
||||
lua_pushstring(L,"tolua_super");
|
||||
lua_rawget(L,LUA_REGISTRYINDEX); /* stack: mt ubox[u] super */
|
||||
lua_getmetatable(L,-2); /* stack: mt ubox[u] super mt */
|
||||
lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] */
|
||||
if (lua_istable(L,-1))
|
||||
{
|
||||
lua_pushstring(L,type); /* stack: mt ubox[u] super super[mt] type */
|
||||
lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] flag */
|
||||
if (lua_toboolean(L,-1) == 1) /* if true */
|
||||
{
|
||||
lua_pop(L,3); /* mt ubox[u]*/
|
||||
lua_remove(L, -2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* type represents a more specilized type */
|
||||
/*luaL_getmetatable(L,type); // stack: mt ubox[u] super super[mt] flag mt */
|
||||
lua_pushvalue(L, -5); /* stack: mt ubox[u] super super[mt] flag mt */
|
||||
lua_setmetatable(L,-5); /* stack: mt ubox[u] super super[mt] flag */
|
||||
lua_pop(L,3); /* stack: mt ubox[u] */
|
||||
}
|
||||
lua_remove(L, -2); /* stack: ubox[u]*/
|
||||
|
||||
if (0 != addToRoot)
|
||||
{
|
||||
lua_pushvalue(L, -1);
|
||||
tolua_add_value_to_root(L, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TOLUA_API void tolua_pushvalue (lua_State* L, int lo)
|
||||
{
|
||||
lua_pushvalue(L,lo);
|
||||
|
@ -50,72 +126,12 @@ TOLUA_API void tolua_pushuserdata (lua_State* L, void* value)
|
|||
|
||||
TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type)
|
||||
{
|
||||
if (value == NULL)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
{
|
||||
luaL_getmetatable(L, type); /* stack: mt */
|
||||
if (lua_isnil(L, -1)) { /* NOT FOUND metatable */
|
||||
lua_pop(L, 1);
|
||||
return;
|
||||
}
|
||||
lua_pushstring(L,"tolua_ubox");
|
||||
lua_rawget(L,-2); /* stack: mt ubox */
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
lua_pushstring(L, "tolua_ubox");
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
};
|
||||
|
||||
lua_pushlightuserdata(L,value); /* stack: mt ubox key<value> */
|
||||
lua_rawget(L,-2); /* stack: mt ubox ubox[value] */
|
||||
|
||||
if (lua_isnil(L,-1))
|
||||
{
|
||||
lua_pop(L,1); /* stack: mt ubox */
|
||||
lua_pushlightuserdata(L,value);
|
||||
*(void**)lua_newuserdata(L,sizeof(void *)) = value; /* stack: mt ubox value newud */
|
||||
lua_pushvalue(L,-1); /* stack: mt ubox value newud newud */
|
||||
lua_insert(L,-4); /* stack: mt newud ubox value newud */
|
||||
lua_rawset(L,-3); /* ubox[value] = newud, stack: mt newud ubox */
|
||||
lua_pop(L,1); /* stack: mt newud */
|
||||
/*luaL_getmetatable(L,type);*/
|
||||
lua_pushvalue(L, -2); /* stack: mt newud mt */
|
||||
lua_setmetatable(L,-2); /* update mt, stack: mt newud */
|
||||
tolua_pushusertype_internal(L, value, type, 0);
|
||||
}
|
||||
|
||||
#ifdef LUA_VERSION_NUM
|
||||
lua_pushvalue(L, TOLUA_NOPEER);
|
||||
lua_setfenv(L, -2);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* check the need of updating the metatable to a more specialized class */
|
||||
lua_insert(L,-2); /* stack: mt ubox[u] ubox */
|
||||
lua_pop(L,1); /* stack: mt ubox[u] */
|
||||
lua_pushstring(L,"tolua_super");
|
||||
lua_rawget(L,LUA_REGISTRYINDEX); /* stack: mt ubox[u] super */
|
||||
lua_getmetatable(L,-2); /* stack: mt ubox[u] super mt */
|
||||
lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] */
|
||||
if (lua_istable(L,-1))
|
||||
{
|
||||
lua_pushstring(L,type); /* stack: mt ubox[u] super super[mt] type */
|
||||
lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] flag */
|
||||
if (lua_toboolean(L,-1) == 1) /* if true */
|
||||
{
|
||||
lua_pop(L,3); /* mt ubox[u]*/
|
||||
lua_remove(L, -2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* type represents a more specilized type */
|
||||
/*luaL_getmetatable(L,type); // stack: mt ubox[u] super super[mt] flag mt */
|
||||
lua_pushvalue(L, -5); /* stack: mt ubox[u] super super[mt] flag mt */
|
||||
lua_setmetatable(L,-5); /* stack: mt ubox[u] super super[mt] flag */
|
||||
lua_pop(L,3); /* stack: mt ubox[u] */
|
||||
}
|
||||
lua_remove(L, -2); /* stack: ubox[u]*/
|
||||
}
|
||||
TOLUA_API void tolua_pushusertype_and_addtoroot (lua_State* L, void* value, const char* type)
|
||||
{
|
||||
tolua_pushusertype_internal(L, value, type, 1);
|
||||
}
|
||||
|
||||
TOLUA_API void tolua_pushusertype_and_takeownership (lua_State* L, void* value, const char* type)
|
||||
|
@ -124,6 +140,30 @@ TOLUA_API void tolua_pushusertype_and_takeownership (lua_State* L, void* value,
|
|||
tolua_register_gc(L,lua_gettop(L));
|
||||
}
|
||||
|
||||
TOLUA_API void tolua_add_value_to_root(lua_State* L, void* ptr)
|
||||
{
|
||||
|
||||
lua_pushstring(L, TOLUA_VALUE_ROOT);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: value root */
|
||||
lua_insert(L, -2); /* stack: root value */
|
||||
lua_pushlightuserdata(L, ptr); /* stack: root value ptr */
|
||||
lua_insert(L, -2); /* stack: root ptr value */
|
||||
lua_rawset(L, -3); /* root[ptr] = value, stack: root */
|
||||
lua_pop(L, 1); /* stack: - */
|
||||
}
|
||||
|
||||
|
||||
TOLUA_API void tolua_remove_value_from_root (lua_State* L, void* ptr)
|
||||
{
|
||||
lua_pushstring(L, TOLUA_VALUE_ROOT);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX); /* stack: root */
|
||||
lua_pushlightuserdata(L, ptr); /* stack: root ptr */
|
||||
|
||||
lua_pushnil(L); /* stack: root ptr nil */
|
||||
lua_rawset(L, -3); /* root[ptr] = nil, stack: root */
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
TOLUA_API void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v)
|
||||
{
|
||||
lua_pushnumber(L,index);
|
||||
|
|
|
@ -535,20 +535,18 @@ std::string TestAnimationEvent::title() const
|
|||
{
|
||||
return "Test Armature Animation Event";
|
||||
}
|
||||
void TestAnimationEvent::animationEvent(Armature *armature, MovementEventType movementType, const char *movementID)
|
||||
void TestAnimationEvent::animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
|
||||
{
|
||||
std::string id = movementID;
|
||||
|
||||
if (movementType == LOOP_COMPLETE)
|
||||
{
|
||||
if (id.compare("Fire") == 0)
|
||||
if (movementID == "Fire")
|
||||
{
|
||||
ActionInterval *actionToRight = MoveTo::create(2, Point(VisibleRect::right().x - 50, VisibleRect::right().y));
|
||||
armature->stopAllActions();
|
||||
armature->runAction(Sequence::create(actionToRight, CallFunc::create( CC_CALLBACK_0(TestAnimationEvent::callback1, this)), nullptr));
|
||||
armature->getAnimation()->play("Walk");
|
||||
}
|
||||
else if (id.compare("FireMax") == 0)
|
||||
else if (movementID == "FireMax")
|
||||
{
|
||||
ActionInterval *actionToLeft = MoveTo::create(2, Point(VisibleRect::left().x + 50, VisibleRect::left().y));
|
||||
armature->stopAllActions();
|
||||
|
@ -596,9 +594,9 @@ std::string TestFrameEvent::title() const
|
|||
{
|
||||
return "Test Frame Event";
|
||||
}
|
||||
void TestFrameEvent::onFrameEvent(Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex)
|
||||
void TestFrameEvent::onFrameEvent(Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
|
||||
{
|
||||
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt, currentFrameIndex);
|
||||
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt.c_str(), currentFrameIndex);
|
||||
|
||||
if (!_gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG) || _gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG)->isDone())
|
||||
{
|
||||
|
@ -778,9 +776,9 @@ std::string TestColliderDetector::title() const
|
|||
{
|
||||
return "Test Collider Detector";
|
||||
}
|
||||
void TestColliderDetector::onFrameEvent(Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex)
|
||||
void TestColliderDetector::onFrameEvent(Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
|
||||
{
|
||||
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt, currentFrameIndex);
|
||||
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt.c_str(), currentFrameIndex);
|
||||
|
||||
/*
|
||||
* originFrameIndex is the frame index editted in Action Editor
|
||||
|
|
|
@ -153,7 +153,7 @@ public:
|
|||
|
||||
virtual void onEnter();
|
||||
virtual std::string title() const override;
|
||||
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const char *movementID);
|
||||
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID);
|
||||
void callback1();
|
||||
void callback2();
|
||||
|
||||
|
@ -166,7 +166,7 @@ class TestFrameEvent : public ArmatureTestLayer
|
|||
public:
|
||||
virtual void onEnter();
|
||||
virtual std::string title() const override;
|
||||
void onFrameEvent(cocostudio::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex);
|
||||
void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex);
|
||||
void checkAction(float dt);
|
||||
protected:
|
||||
NodeGrid* _gridNode;
|
||||
|
@ -215,7 +215,7 @@ public:
|
|||
virtual void draw();
|
||||
virtual void update(float delta);
|
||||
|
||||
void onFrameEvent(cocostudio::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex);
|
||||
void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex);
|
||||
|
||||
void initWorld();
|
||||
|
||||
|
@ -273,7 +273,7 @@ public:
|
|||
virtual void update(float delta);
|
||||
virtual void draw();
|
||||
|
||||
void onFrameEvent(cocostudio::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex);
|
||||
void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex);
|
||||
|
||||
void initWorld() {};
|
||||
cocostudio::Armature *armature;
|
||||
|
|
|
@ -179,21 +179,21 @@ void NewSpriteTest::createNewSpriteTest()
|
|||
{
|
||||
Size winSize = Director::getInstance()->getWinSize();
|
||||
|
||||
NewSprite* parent = NewSprite::create("Images/grossini.png");
|
||||
Sprite* parent = Sprite::create("Images/grossini.png");
|
||||
parent->setPosition(winSize.width*2/3, winSize.height/2);
|
||||
NewSprite* child1 = NewSprite::create("Images/grossinis_sister1.png");
|
||||
Sprite* child1 = Sprite::create("Images/grossinis_sister1.png");
|
||||
child1->setPosition(0.0f, -20.0f);
|
||||
NewSprite* child2 = NewSprite::create("Images/grossinis_sister2.png");
|
||||
Sprite* child2 = Sprite::create("Images/grossinis_sister2.png");
|
||||
child2->setPosition(20.0f, -20.0f);
|
||||
NewSprite* child3 = NewSprite::create("Images/grossinis_sister1.png");
|
||||
Sprite* child3 = Sprite::create("Images/grossinis_sister1.png");
|
||||
child3->setPosition(40.0f, -20.0f);
|
||||
NewSprite* child4 = NewSprite::create("Images/grossinis_sister2.png");
|
||||
Sprite* child4 = Sprite::create("Images/grossinis_sister2.png");
|
||||
child4->setPosition(60.0f, -20.0f);
|
||||
NewSprite* child5 = NewSprite::create("Images/grossinis_sister2.png");
|
||||
Sprite* child5 = Sprite::create("Images/grossinis_sister2.png");
|
||||
child5->setPosition(80.0f, -20.0f);
|
||||
NewSprite* child6 = NewSprite::create("Images/grossinis_sister2.png");
|
||||
Sprite* child6 = Sprite::create("Images/grossinis_sister2.png");
|
||||
child6->setPosition(100.0f, -20.0f);
|
||||
NewSprite* child7 = NewSprite::create("Images/grossinis_sister2.png");
|
||||
Sprite* child7 = Sprite::create("Images/grossinis_sister2.png");
|
||||
child7->setPosition(120.0f, -20.0f);
|
||||
|
||||
parent->addChild(child1);
|
||||
|
@ -229,7 +229,7 @@ NewSpriteBatchTest::NewSpriteBatchTest()
|
|||
touchListener->onTouchesEnded = CC_CALLBACK_2(NewSpriteBatchTest::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
|
||||
|
||||
auto BatchNode = NewSpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);
|
||||
auto BatchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 50);
|
||||
addChild(BatchNode, 0, kTagSpriteBatchNode);
|
||||
}
|
||||
|
||||
|
@ -259,14 +259,14 @@ void NewSpriteBatchTest::onTouchesEnded(const std::vector<Touch *> &touches, Eve
|
|||
|
||||
void NewSpriteBatchTest::addNewSpriteWithCoords(Point p)
|
||||
{
|
||||
auto BatchNode = static_cast<NewSpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
|
||||
auto BatchNode = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
|
||||
|
||||
int idx = (int) (CCRANDOM_0_1() * 1400 / 100);
|
||||
int x = (idx%5) * 85;
|
||||
int y = (idx/5) * 121;
|
||||
|
||||
|
||||
auto sprite = NewSprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121));
|
||||
auto sprite = Sprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121));
|
||||
BatchNode->addChild(sprite);
|
||||
|
||||
sprite->setPosition( Point( p.x, p.y) );
|
||||
|
@ -295,7 +295,7 @@ NewClippingNodeTest::NewClippingNodeTest()
|
|||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
auto clipper = NewClippingNode::create();
|
||||
auto clipper = ClippingNode::create();
|
||||
clipper->setTag( kTagClipperNode );
|
||||
clipper->setContentSize( Size(200, 200) );
|
||||
clipper->setAnchorPoint( Point(0.5, 0.5) );
|
||||
|
@ -318,11 +318,11 @@ NewClippingNodeTest::NewClippingNodeTest()
|
|||
|
||||
//Test with alpha Test
|
||||
clipper->setAlphaThreshold(0.05f);
|
||||
auto stencil = NewSprite::create("Images/grossini.png");
|
||||
auto stencil = Sprite::create("Images/grossini.png");
|
||||
stencil->setPosition(s.width/2, s.height/2);
|
||||
clipper->setStencil(stencil);
|
||||
|
||||
auto content = NewSprite::create("Images/background2.png");
|
||||
auto content = Sprite::create("Images/background2.png");
|
||||
content->setTag( kTagContentNode );
|
||||
content->setAnchorPoint( Point(0.5, 0.5) );
|
||||
content->setPosition( Point(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) );
|
||||
|
@ -448,7 +448,7 @@ NewCullingTest::NewCullingTest()
|
|||
parent->addChild(parent2);
|
||||
parent2->setPosition(-50,0);
|
||||
parent2->runAction(RepeatForever::create((JumpBy::create(10, Point(0,0), 400, 1))));
|
||||
NewSprite* sprite = NewSprite::create(images[index % images.size()].c_str());
|
||||
Sprite* sprite = Sprite::create(images[index % images.size()].c_str());
|
||||
sprite->setPosition(Point(0,0));
|
||||
//sprite->runAction(RepeatForever::create(RotateBy::create(3, 360)));
|
||||
sprite->runAction(RepeatForever::create(Sequence::createWithTwoActions(ScaleBy::create(2, 2), ScaleBy::create(2,0.5))));
|
||||
|
@ -461,7 +461,7 @@ NewCullingTest::NewCullingTest()
|
|||
parent->addChild(parent2);
|
||||
parent2->setPosition(50,0);
|
||||
parent2->runAction(RepeatForever::create((JumpBy::create(7, Point(0,0), 400, 1))));
|
||||
NewSprite* sprite = NewSprite::create(images[index % images.size()].c_str());
|
||||
Sprite* sprite = Sprite::create(images[index % images.size()].c_str());
|
||||
sprite->setPosition(Point(0,0));
|
||||
//sprite->runAction(RepeatForever::create(RotateBy::create(3, 360)));
|
||||
sprite->runAction(RepeatForever::create(Sequence::createWithTwoActions(ScaleBy::create(2, 2), ScaleBy::create(2,0.5))));
|
||||
|
|
|
@ -396,7 +396,6 @@ void PhysicsDemo::onTouchMoved(Touch* touch, Event* event)
|
|||
|
||||
if (it != _mouses.end())
|
||||
{
|
||||
it->second->getPhysicsBody()->setVelocity((touch->getLocation() - it->second->getPosition()) * 60.0f);
|
||||
it->second->setPosition(touch->getLocation());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "CCConfiguration.h"
|
||||
#include "RenderTextureTest.h"
|
||||
#include "../testBasic.h"
|
||||
#include "renderer/CCNewRenderTexture.h"
|
||||
|
||||
// Test #1 by Jason Booth (slipster216)
|
||||
// Test #3 by David Deaco (ddeaco)
|
||||
|
@ -93,7 +92,7 @@ RenderTextureSave::RenderTextureSave()
|
|||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
// create a render texture, this is what we are going to draw into
|
||||
_target = NewRenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888);
|
||||
_target = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888);
|
||||
_target->retain();
|
||||
_target->setPosition(Point(s.width / 2, s.height / 2));
|
||||
|
||||
|
@ -241,7 +240,7 @@ RenderTextureIssue937::RenderTextureIssue937()
|
|||
|
||||
|
||||
/* A2 & B2 setup */
|
||||
auto rend = NewRenderTexture::create(32, 64, Texture2D::PixelFormat::RGBA8888);
|
||||
auto rend = RenderTexture::create(32, 64, Texture2D::PixelFormat::RGBA8888);
|
||||
|
||||
if (NULL == rend)
|
||||
{
|
||||
|
@ -410,7 +409,7 @@ void RenderTextureZbuffer::onTouchesEnded(const std::vector<Touch*>& touches, Ev
|
|||
|
||||
void RenderTextureZbuffer::renderScreenShot()
|
||||
{
|
||||
auto texture = NewRenderTexture::create(512, 512);
|
||||
auto texture = RenderTexture::create(512, 512);
|
||||
if (NULL == texture)
|
||||
{
|
||||
return;
|
||||
|
@ -444,7 +443,7 @@ RenderTextureTestDepthStencil::RenderTextureTestDepthStencil()
|
|||
auto sprite = Sprite::create("Images/fire.png");
|
||||
sprite->setPosition(Point(s.width * 0.25f, 0));
|
||||
sprite->setScale(10);
|
||||
auto rend = NewRenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444, GL_DEPTH24_STENCIL8);
|
||||
auto rend = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444, GL_DEPTH24_STENCIL8);
|
||||
|
||||
glStencilMask(0xFF);
|
||||
rend->beginWithClear(0, 0, 0, 0, 0, 0);
|
||||
|
@ -506,7 +505,7 @@ RenderTextureTargetNode::RenderTextureTargetNode()
|
|||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
/* Create the render texture */
|
||||
auto renderTexture = NewRenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444);
|
||||
auto renderTexture = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444);
|
||||
this->renderTexture = renderTexture;
|
||||
|
||||
renderTexture->setPosition(Point(s.width/2, s.height/2));
|
||||
|
@ -591,7 +590,7 @@ void SpriteRenderTextureBug::SimpleSprite::draw()
|
|||
if (_rt == nullptr)
|
||||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
_rt = NewRenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888);
|
||||
_rt = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888);
|
||||
_rt->retain();
|
||||
}
|
||||
_rt->beginWithClear(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "cocos2d.h"
|
||||
#include "../testBasic.h"
|
||||
#include "../BaseTest.h"
|
||||
#include "renderer/CCNewRenderTexture.h"
|
||||
|
||||
class RenderTextureTest : public BaseTest
|
||||
{
|
||||
|
@ -31,7 +30,7 @@ public:
|
|||
void saveImage(Object *pSender);
|
||||
|
||||
private:
|
||||
NewRenderTexture *_target;
|
||||
RenderTexture *_target;
|
||||
Sprite *_brush;
|
||||
};
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 148868f7f4407a12444f07cb5e5378b1dbd7511c
|
||||
Subproject commit fda861cde4387948e95811966d9c4ceea04dc758
|
|
@ -8,6 +8,7 @@
|
|||
#include "jsb_cocos2dx_builder_auto.hpp"
|
||||
#include "jsb_cocos2dx_studio_auto.hpp"
|
||||
#include "jsb_cocos2dx_gui_auto.hpp"
|
||||
#include "jsb_cocos2dx_spine_auto.hpp"
|
||||
#include "extension/jsb_cocos2dx_extension_manual.h"
|
||||
#include "cocostudio/jsb_cocos2dx_studio_manual.h"
|
||||
#include "gui/jsb_cocos2dx_gui_manual.h"
|
||||
|
@ -70,6 +71,8 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
sc->addRegisterCallback(register_all_cocos2dx_studio);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_studio_manual);
|
||||
|
||||
sc->addRegisterCallback(register_all_cocos2dx_spine);
|
||||
|
||||
sc->start();
|
||||
|
||||
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "ScriptingCore.h"
|
||||
#include "jsb_cocos2dx_auto.hpp"
|
||||
#include "jsb_cocos2dx_extension_auto.hpp"
|
||||
#include "jsb_cocos2dx_spine_auto.hpp"
|
||||
#include "cocos2d_specifics.hpp"
|
||||
#include "extension/jsb_cocos2dx_extension_manual.h"
|
||||
#include "chipmunk/js_bindings_chipmunk_registration.h"
|
||||
|
@ -40,6 +41,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
||||
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_spine);
|
||||
sc->addRegisterCallback(jsb_register_chipmunk);
|
||||
sc->addRegisterCallback(JSB_register_opengl);
|
||||
sc->addRegisterCallback(jsb_register_system);
|
||||
|
|
|
@ -24,4 +24,4 @@ include $(BUILD_SHARED_LIBRARY)
|
|||
$(call import-module,scripting/javascript/bindings)
|
||||
$(call import-module,scripting/javascript/bindings/extension)
|
||||
$(call import-module,scripting/javascript/bindings/chipmunk)
|
||||
$(call import-module,scripting/javascript/bindings/localstorage)
|
||||
$(call import-module,scripting/javascript/bindings/localstorage)
|
|
@ -1 +1 @@
|
|||
Subproject commit ad532012457e2eaff15d73d9ba28a638fa748d2d
|
||||
Subproject commit 1b34f5852fcf494499be7eb5ce2bada72a0b16a2
|
|
@ -37,7 +37,7 @@ classes_need_extend = Node Layer.* Sprite MenuItemFont Scene DrawNode
|
|||
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
|
||||
# functions from all classes.
|
||||
|
||||
skip = Node::[^setPosition$ setGrid setGLServerState description getUserObject .*UserData getGLServerState .*schedule],
|
||||
skip = Node::[^setPosition$ setGrid setGLServerState description getUserObject .*UserData getGLServerState .*schedule setContentSize setAnchorPoint],
|
||||
Sprite::[getQuad getBlendFunc ^setPosition$ setBlendFunc],
|
||||
SpriteBatchNode::[getBlendFunc setBlendFunc getDescendants],
|
||||
MotionStreak::[getBlendFunc setBlendFunc draw update],
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
[cocos2dx_spine]
|
||||
prefix = cocos2dx_spine
|
||||
|
||||
target_namespace = cc
|
||||
|
||||
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include
|
||||
android_flags = -D_SIZE_T_DEFINED_
|
||||
|
||||
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
|
||||
clang_flags = -nostdinc -x c++ -std=c++11
|
||||
|
||||
cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s
|
||||
|
||||
cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT
|
||||
|
||||
cxxgenerator_headers =
|
||||
|
||||
# extra arguments for clang
|
||||
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
|
||||
|
||||
headers = %(cocosdir)s/cocos/editor-support/spine/spine-cocos2dx.h
|
||||
|
||||
skip = CCSkeleton::[createWithData],
|
||||
CCSkeletonAnimation::[createWithData]
|
||||
|
||||
classes = CCSkeleton CCSkeletonAnimation
|
||||
|
||||
remove_prefix = CC
|
||||
|
||||
classes_have_no_parents =
|
||||
|
||||
base_classes_to_skip =
|
||||
|
||||
abstract_classes =
|
||||
|
||||
script_control_cpp =
|
||||
|
||||
rename_functions =
|
||||
|
||||
rename_classes =
|
|
@ -92,4 +92,7 @@ echo "Generating bindings for cocos2dx_gui..."
|
|||
LD_LIBRARY_PATH=${CLANG_ROOT}/lib $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TO_JS_ROOT}/cocos2dx_gui.ini -s cocos2dx_gui -t spidermonkey -o ${COCOS2DX_ROOT}/cocos/scripting/auto-generated/js-bindings -n jsb_cocos2dx_gui_auto
|
||||
|
||||
echo "Generating bindings for cocos2dx_studio..."
|
||||
LD_LIBRARY_PATH=${CLANG_ROOT}/lib $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TO_JS_ROOT}/cocos2dx_studio.ini -s cocos2dx_studio -t spidermonkey -o ${COCOS2DX_ROOT}/cocos/scripting/auto-generated/js-bindings -n jsb_cocos2dx_studio_auto
|
||||
LD_LIBRARY_PATH=${CLANG_ROOT}/lib $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TO_JS_ROOT}/cocos2dx_studio.ini -s cocos2dx_studio -t spidermonkey -o ${COCOS2DX_ROOT}/cocos/scripting/auto-generated/js-bindings -n jsb_cocos2dx_studio_auto
|
||||
|
||||
echo "Generating bindings for cocos2dx_spine..."
|
||||
LD_LIBRARY_PATH=${CLANG_ROOT}/lib $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TO_JS_ROOT}/cocos2dx_spine.ini -s cocos2dx_spine -t spidermonkey -o ${COCOS2DX_ROOT}/cocos/scripting/auto-generated/js-bindings -n jsb_cocos2dx_spine_auto
|
|
@ -35,7 +35,7 @@ classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* M
|
|||
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
|
||||
# functions from all classes.
|
||||
|
||||
skip = Node::[setGLServerState description getUserObject .*UserData getGLServerState .*schedule getPosition$],
|
||||
skip = Node::[setGLServerState description getUserObject .*UserData getGLServerState .*schedule getPosition$ setContentSize setAnchorPoint],
|
||||
Sprite::[getQuad getBlendFunc ^setPosition$ setBlendFunc],
|
||||
SpriteBatchNode::[getBlendFunc setBlendFunc getDescendants],
|
||||
MotionStreak::[getBlendFunc setBlendFunc draw update],
|
||||
|
@ -111,7 +111,8 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS
|
|||
Label::[getLettersInfo],
|
||||
EGLViewProtocol::[setTouchDelegate],
|
||||
EGLView::[end swapBuffers],
|
||||
NewTextureAtlas::[*]
|
||||
NewTextureAtlas::[*],
|
||||
DisplayLinkDirector::[mainLoop setAnimationInterval startAnimation stopAnimation]
|
||||
|
||||
rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame],
|
||||
ProgressTimer::[setReverseProgress=setReverseDirection],
|
||||
|
@ -142,7 +143,7 @@ base_classes_to_skip = Clonable
|
|||
|
||||
# classes that create no constructor
|
||||
# Set is special and we will use a hand-written constructor
|
||||
abstract_classes = Action FiniteTimeAction ActionInterval ActionEase EaseRateAction EaseElastic EaseBounce ActionInstant GridAction Grid3DAction TiledGrid3DAction Director SpriteFrameCache TransitionEaseScene Set SimpleAudioEngine FileUtils Application ClippingNode Label EGLViewProtocol EGLView EventAcceleration
|
||||
abstract_classes = Action FiniteTimeAction ActionInterval ActionEase EaseRateAction EaseElastic EaseBounce ActionInstant GridAction Grid3DAction TiledGrid3DAction Director SpriteFrameCache TransitionEaseScene Set SimpleAudioEngine FileUtils Application ClippingNode Label EGLViewProtocol EGLView EventAcceleration DisplayLinkDirector
|
||||
|
||||
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
|
||||
script_control_cpp = no
|
||||
|
|
Loading…
Reference in New Issue