mirror of https://github.com/axmolengine/axmol.git
Merge branch 'newRenderer' into Array
Conflicts: cocos/editor-support/cocostudio/CCArmature.cpp cocos/editor-support/cocostudio/CCArmature.h cocos/editor-support/cocostudio/CCBatchNode.cpp cocos/editor-support/cocostudio/CCColliderDetector.cpp cocos/scripting/auto-generated tools/bindings-generator
This commit is contained in:
commit
6ff45b09e7
3
AUTHORS
3
AUTHORS
|
@ -666,6 +666,9 @@ Developers:
|
|||
hulefei
|
||||
Added gui namespace before SEL_TouchEvent.
|
||||
|
||||
zhiqiangxu
|
||||
Fixed a logic error in ControlUtils::RectUnion.
|
||||
|
||||
Retired Core Developers:
|
||||
WenSheng Yang
|
||||
Author of windows port, CCTextField,
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
cocos2d-x-3.0beta0 ?? 2013
|
||||
[All]
|
||||
[NEW] Upgrated Box2D to 2.3.0
|
||||
[NEW] Added ThreadHelper, ThreadHelper::runOnGLThread() simplify invoking engine codes and OpenGL ES commands in a thread other then gl thread.
|
||||
[NEW] SChedule::performFunctionInCocosThread()
|
||||
[NEW] Added tga format support again.
|
||||
[FIX] A Logic error in ControlUtils::RectUnion.
|
||||
[Android]
|
||||
[NEW] build/android-build.sh: add supporting to generate .apk file
|
||||
[FIX] XMLHttpRequest receives wrong binary array.
|
||||
|
|
|
@ -1 +1 @@
|
|||
77ef9ee3921db604edd06a2cc0b9f9a89259a431
|
||||
e4898923edd8b218b9dc8b238b747331ad601585
|
|
@ -1 +1 @@
|
|||
133130a8ae8d6597399a7de05ba9b63ee55f5e2d
|
||||
6824f39ae1cedec2e43627c2637f672203c4a460
|
|
@ -87,7 +87,7 @@ void ActionManager::actionAllocWithHashElement(tHashElement *element)
|
|||
|
||||
}
|
||||
|
||||
void ActionManager::removeActionAtIndex(int index, tHashElement *element)
|
||||
void ActionManager::removeActionAtIndex(ssize_t index, tHashElement *element)
|
||||
{
|
||||
Action *action = (Action*)element->actions->arr[index];
|
||||
|
||||
|
@ -324,7 +324,7 @@ Action* ActionManager::getActionByTag(int tag, const Node *target) const
|
|||
|
||||
// XXX: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer
|
||||
// and, it is not possible to get the address of a reference
|
||||
int ActionManager::getNumberOfRunningActionsInTarget(const Node *target) const
|
||||
ssize_t ActionManager::getNumberOfRunningActionsInTarget(const Node *target) const
|
||||
{
|
||||
tHashElement *element = NULL;
|
||||
HASH_FIND_PTR(_targets, &target, element);
|
||||
|
|
|
@ -100,10 +100,10 @@ public:
|
|||
* - If you are running 1 Sequence of 7 actions, it will return 1.
|
||||
* - If you are running 7 Sequences of 2 actions, it will return 7.
|
||||
*/
|
||||
int getNumberOfRunningActionsInTarget(const Node *target) const;
|
||||
ssize_t getNumberOfRunningActionsInTarget(const Node *target) const;
|
||||
|
||||
/** @deprecated use getNumberOfRunningActionsInTarget() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE inline int numberOfRunningActionsInTarget(Node *target) const { return getNumberOfRunningActionsInTarget(target); }
|
||||
CC_DEPRECATED_ATTRIBUTE inline ssize_t numberOfRunningActionsInTarget(Node *target) const { return getNumberOfRunningActionsInTarget(target); }
|
||||
|
||||
/** Pauses the target: all running actions and newly added actions will be paused.
|
||||
*/
|
||||
|
@ -124,7 +124,7 @@ public:
|
|||
protected:
|
||||
// declared in ActionManager.m
|
||||
|
||||
void removeActionAtIndex(int index, struct _hashElement *pElement);
|
||||
void removeActionAtIndex(ssize_t index, struct _hashElement *pElement);
|
||||
void deleteHashElement(struct _hashElement *pElement);
|
||||
void actionAllocWithHashElement(struct _hashElement *pElement);
|
||||
void update(float dt);
|
||||
|
|
|
@ -45,7 +45,7 @@ THE SOFTWARE.
|
|||
#include "platform/CCFileUtils.h"
|
||||
#include "CCApplication.h"
|
||||
#include "CCLabelBMFont.h"
|
||||
#include "CCLabelAtlas.h"
|
||||
#include "CCNewLabelAtlas.h"
|
||||
#include "CCActionManager.h"
|
||||
#include "CCAnimationCache.h"
|
||||
#include "CCTouch.h"
|
||||
|
@ -61,7 +61,8 @@ THE SOFTWARE.
|
|||
#include "CCConfiguration.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
#include "CCFontFreeType.h"
|
||||
|
||||
#include "Renderer.h"
|
||||
#include "renderer/Frustum.h"
|
||||
/**
|
||||
Position of the FPS
|
||||
|
||||
|
@ -135,6 +136,8 @@ bool Director::init(void)
|
|||
|
||||
_openGLView = nullptr;
|
||||
|
||||
_cullingFrustum = new Frustum();
|
||||
|
||||
_contentScaleFactor = 1.0f;
|
||||
|
||||
// scheduler
|
||||
|
@ -258,6 +261,16 @@ void Director::drawScene()
|
|||
|
||||
kmGLPushMatrix();
|
||||
|
||||
//construct the frustum
|
||||
{
|
||||
kmMat4 view;
|
||||
kmMat4 projection;
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &projection);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &view);
|
||||
|
||||
_cullingFrustum->setupFromMatrix(view, projection);
|
||||
}
|
||||
|
||||
// draw the scene
|
||||
if (_runningScene)
|
||||
{
|
||||
|
@ -275,6 +288,8 @@ void Director::drawScene()
|
|||
showStats();
|
||||
}
|
||||
|
||||
Renderer::getInstance()->render();
|
||||
|
||||
kmGLPopMatrix();
|
||||
|
||||
_totalFrames++;
|
||||
|
@ -353,6 +368,8 @@ void Director::setOpenGLView(EGLView *openGLView)
|
|||
setGLDefaultValues();
|
||||
}
|
||||
|
||||
Renderer::getInstance()->initGLView();
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// _touchDispatcher->setDispatchEvents(true);
|
||||
|
@ -595,7 +612,7 @@ void Director::replaceScene(Scene *scene)
|
|||
CCASSERT(_runningScene, "Use runWithScene: instead to start the director");
|
||||
CCASSERT(scene != nullptr, "the scene should not be null");
|
||||
|
||||
int index = _scenesStack.size();
|
||||
ssize_t index = _scenesStack.size();
|
||||
|
||||
_sendCleanupToScene = true;
|
||||
_scenesStack.replace(index - 1, scene);
|
||||
|
@ -618,7 +635,7 @@ void Director::popScene(void)
|
|||
CCASSERT(_runningScene != nullptr, "running scene should not null");
|
||||
|
||||
_scenesStack.popBack();
|
||||
int c = _scenesStack.size();
|
||||
ssize_t c = _scenesStack.size();
|
||||
|
||||
if (c == 0)
|
||||
{
|
||||
|
@ -639,7 +656,7 @@ void Director::popToRootScene(void)
|
|||
void Director::popToSceneStackLevel(int level)
|
||||
{
|
||||
CCASSERT(_runningScene != nullptr, "A running Scene is needed");
|
||||
int c = _scenesStack.size();
|
||||
ssize_t c = _scenesStack.size();
|
||||
|
||||
// level 0? -> end
|
||||
if (level == 0)
|
||||
|
@ -706,6 +723,7 @@ void Director::purgeDirector()
|
|||
CC_SAFE_RELEASE_NULL(_FPSLabel);
|
||||
CC_SAFE_RELEASE_NULL(_SPFLabel);
|
||||
CC_SAFE_RELEASE_NULL(_drawsLabel);
|
||||
CC_SAFE_DELETE(_cullingFrustum);
|
||||
|
||||
// purge bitmap cache
|
||||
LabelBMFont::purgeCachedData();
|
||||
|
@ -906,17 +924,17 @@ void Director::createStatsLabel()
|
|||
*/
|
||||
float factor = EGLView::getInstance()->getDesignResolutionSize().height / 320.0f;
|
||||
|
||||
_FPSLabel = new LabelAtlas();
|
||||
_FPSLabel = new NewLabelAtlas;
|
||||
_FPSLabel->setIgnoreContentScaleFactor(true);
|
||||
_FPSLabel->initWithString("00.0", texture, 12, 32 , '.');
|
||||
_FPSLabel->setScale(factor);
|
||||
|
||||
_SPFLabel = new LabelAtlas();
|
||||
_SPFLabel = new NewLabelAtlas;
|
||||
_SPFLabel->setIgnoreContentScaleFactor(true);
|
||||
_SPFLabel->initWithString("0.000", texture, 12, 32, '.');
|
||||
_SPFLabel->setScale(factor);
|
||||
|
||||
_drawsLabel = new LabelAtlas();
|
||||
_drawsLabel = new NewLabelAtlas;
|
||||
_drawsLabel->setIgnoreContentScaleFactor(true);
|
||||
_drawsLabel->initWithString("000", texture, 12, 32, '.');
|
||||
_drawsLabel->setScale(factor);
|
||||
|
|
|
@ -55,6 +55,7 @@ class Scheduler;
|
|||
class ActionManager;
|
||||
class EventDispatcher;
|
||||
class TextureCache;
|
||||
class Frustum;
|
||||
|
||||
/**
|
||||
@brief Class that creates and handles the main Window and manages how
|
||||
|
@ -331,6 +332,12 @@ public:
|
|||
void setContentScaleFactor(float scaleFactor);
|
||||
float getContentScaleFactor() const;
|
||||
|
||||
/**
|
||||
Get the Culling Frustum
|
||||
*/
|
||||
|
||||
Frustum* getFrustum() const { return _cullingFrustum; }
|
||||
|
||||
public:
|
||||
/** Gets the Scheduler associated with this director
|
||||
@since v2.0
|
||||
|
@ -435,6 +442,8 @@ protected:
|
|||
unsigned int _frames;
|
||||
float _secondsPerFrame;
|
||||
|
||||
Frustum* _cullingFrustum;
|
||||
|
||||
/* The running scene */
|
||||
Scene *_runningScene;
|
||||
|
||||
|
|
|
@ -136,12 +136,12 @@ private:
|
|||
|
||||
inline std::vector<EventListener*>* getFixedPriorityListeners() const { return _fixedListeners; };
|
||||
inline std::vector<EventListener*>* getSceneGraphPriorityListeners() const { return _sceneGraphListeners; };
|
||||
inline int getGt0Index() const { return _gt0Index; };
|
||||
inline void setGt0Index(int index) { _gt0Index = index; };
|
||||
inline ssize_t getGt0Index() const { return _gt0Index; };
|
||||
inline void setGt0Index(ssize_t index) { _gt0Index = index; };
|
||||
private:
|
||||
std::vector<EventListener*>* _fixedListeners;
|
||||
std::vector<EventListener*>* _sceneGraphListeners;
|
||||
int _gt0Index;
|
||||
ssize_t _gt0Index;
|
||||
};
|
||||
|
||||
/** Adds event listener with item */
|
||||
|
|
|
@ -46,6 +46,7 @@ typedef struct _hashUniformEntry
|
|||
} tHashUniformEntry;
|
||||
|
||||
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR = "ShaderPositionTextureColor";
|
||||
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP = "ShaderPositionTextureColor_noMVP";
|
||||
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST = "ShaderPositionTextureColorAlphaTest";
|
||||
const char* GLProgram::SHADER_NAME_POSITION_COLOR = "ShaderPositionColor";
|
||||
const char* GLProgram::SHADER_NAME_POSITION_TEXTURE = "ShaderPositionTexture";
|
||||
|
@ -234,8 +235,9 @@ void GLProgram::updateUniforms()
|
|||
|
||||
_uniforms[UNIFORM_SAMPLER] = glGetUniformLocation(_program, UNIFORM_NAME_SAMPLER);
|
||||
|
||||
_flags.usesP = _uniforms[UNIFORM_P_MATRIX] != -1;
|
||||
_flags.usesMV = _uniforms[UNIFORM_MV_MATRIX] != -1;
|
||||
_flags.usesMVP = _uniforms[UNIFORM_MVP_MATRIX] != -1;
|
||||
_flags.usesMV = (_uniforms[UNIFORM_MV_MATRIX] != -1 && _uniforms[UNIFORM_P_MATRIX] != -1 );
|
||||
_flags.usesTime = (
|
||||
_uniforms[UNIFORM_TIME] != -1 ||
|
||||
_uniforms[UNIFORM_SIN_TIME] != -1 ||
|
||||
|
@ -323,7 +325,7 @@ std::string GLProgram::getProgramLog() const
|
|||
|
||||
// Uniform cache
|
||||
|
||||
bool GLProgram::updateUniformLocation(GLint location, GLvoid* data, unsigned int bytes)
|
||||
bool GLProgram::updateUniformLocation(GLint location, const GLvoid* data, unsigned int bytes)
|
||||
{
|
||||
if (location < 0)
|
||||
{
|
||||
|
@ -486,7 +488,7 @@ void GLProgram::setUniformLocationWith4f(GLint location, GLfloat f1, GLfloat f2,
|
|||
}
|
||||
}
|
||||
|
||||
void GLProgram::setUniformLocationWith2fv(GLint location, GLfloat* floats, unsigned int numberOfArrays)
|
||||
void GLProgram::setUniformLocationWith2fv(GLint location, const GLfloat* floats, unsigned int numberOfArrays)
|
||||
{
|
||||
bool updated = updateUniformLocation(location, floats, sizeof(float)*2*numberOfArrays);
|
||||
|
||||
|
@ -496,7 +498,7 @@ void GLProgram::setUniformLocationWith2fv(GLint location, GLfloat* floats, unsig
|
|||
}
|
||||
}
|
||||
|
||||
void GLProgram::setUniformLocationWith3fv(GLint location, GLfloat* floats, unsigned int numberOfArrays)
|
||||
void GLProgram::setUniformLocationWith3fv(GLint location, const GLfloat* floats, unsigned int numberOfArrays)
|
||||
{
|
||||
bool updated = updateUniformLocation(location, floats, sizeof(float)*3*numberOfArrays);
|
||||
|
||||
|
@ -506,7 +508,7 @@ void GLProgram::setUniformLocationWith3fv(GLint location, GLfloat* floats, unsig
|
|||
}
|
||||
}
|
||||
|
||||
void GLProgram::setUniformLocationWith4fv(GLint location, GLfloat* floats, unsigned int numberOfArrays)
|
||||
void GLProgram::setUniformLocationWith4fv(GLint location, const GLfloat* floats, unsigned int numberOfArrays)
|
||||
{
|
||||
bool updated = updateUniformLocation(location, floats, sizeof(float)*4*numberOfArrays);
|
||||
|
||||
|
@ -516,7 +518,7 @@ void GLProgram::setUniformLocationWith4fv(GLint location, GLfloat* floats, unsig
|
|||
}
|
||||
}
|
||||
|
||||
void GLProgram::setUniformLocationWithMatrix2fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices) {
|
||||
void GLProgram::setUniformLocationWithMatrix2fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices) {
|
||||
bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*4*numberOfMatrices);
|
||||
|
||||
if( updated )
|
||||
|
@ -525,7 +527,7 @@ void GLProgram::setUniformLocationWithMatrix2fv(GLint location, GLfloat* matrixA
|
|||
}
|
||||
}
|
||||
|
||||
void GLProgram::setUniformLocationWithMatrix3fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices) {
|
||||
void GLProgram::setUniformLocationWithMatrix3fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices) {
|
||||
bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*9*numberOfMatrices);
|
||||
|
||||
if( updated )
|
||||
|
@ -535,7 +537,7 @@ void GLProgram::setUniformLocationWithMatrix3fv(GLint location, GLfloat* matrixA
|
|||
}
|
||||
|
||||
|
||||
void GLProgram::setUniformLocationWithMatrix4fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices)
|
||||
void GLProgram::setUniformLocationWithMatrix4fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices)
|
||||
{
|
||||
bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*16*numberOfMatrices);
|
||||
|
||||
|
@ -547,12 +549,23 @@ void GLProgram::setUniformLocationWithMatrix4fv(GLint location, GLfloat* matrixA
|
|||
|
||||
void GLProgram::setUniformsForBuiltins()
|
||||
{
|
||||
kmMat4 matrixP;
|
||||
kmMat4 matrixMV;
|
||||
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &matrixP);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV);
|
||||
|
||||
setUniformsForBuiltins(matrixMV);
|
||||
}
|
||||
|
||||
void GLProgram::setUniformsForBuiltins(const kmMat4 &matrixMV)
|
||||
{
|
||||
kmMat4 matrixP;
|
||||
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &matrixP);
|
||||
|
||||
if(_flags.usesP)
|
||||
setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_P_MATRIX], matrixP.mat, 1);
|
||||
|
||||
if(_flags.usesMV)
|
||||
setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_MV_MATRIX], matrixMV.mat, 1);
|
||||
|
||||
if(_flags.usesMVP) {
|
||||
kmMat4 matrixMVP;
|
||||
|
@ -560,11 +573,6 @@ void GLProgram::setUniformsForBuiltins()
|
|||
setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_MVP_MATRIX], matrixMVP.mat, 1);
|
||||
}
|
||||
|
||||
if(_flags.usesMV) {
|
||||
setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_P_MATRIX], matrixP.mat, 1);
|
||||
setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_MV_MATRIX], matrixMV.mat, 1);
|
||||
}
|
||||
|
||||
if(_flags.usesTime) {
|
||||
Director *director = Director::getInstance();
|
||||
// This doesn't give the most accurate global time value.
|
||||
|
|
|
@ -32,6 +32,7 @@ THE SOFTWARE.
|
|||
#include "CCObject.h"
|
||||
|
||||
#include "CCGL.h"
|
||||
#include "kazmath/kazmath.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -78,6 +79,7 @@ public:
|
|||
};
|
||||
|
||||
static const char* SHADER_NAME_POSITION_TEXTURE_COLOR;
|
||||
static const char* SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP;
|
||||
static const char* SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST;
|
||||
static const char* SHADER_NAME_POSITION_COLOR;
|
||||
static const char* SHADER_NAME_POSITION_TEXTURE;
|
||||
|
@ -190,25 +192,26 @@ public:
|
|||
void setUniformLocationWith4f(GLint location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4);
|
||||
|
||||
/** calls glUniform2fv only if the values are different than the previous call for this same shader program. */
|
||||
void setUniformLocationWith2fv(GLint location, GLfloat* floats, unsigned int numberOfArrays);
|
||||
void setUniformLocationWith2fv(GLint location, const GLfloat* floats, unsigned int numberOfArrays);
|
||||
|
||||
/** calls glUniform3fv only if the values are different than the previous call for this same shader program. */
|
||||
void setUniformLocationWith3fv(GLint location, GLfloat* floats, unsigned int numberOfArrays);
|
||||
void setUniformLocationWith3fv(GLint location, const GLfloat* floats, unsigned int numberOfArrays);
|
||||
|
||||
/** calls glUniform4fv only if the values are different than the previous call for this same shader program. */
|
||||
void setUniformLocationWith4fv(GLint location, GLfloat* floats, unsigned int numberOfArrays);
|
||||
void setUniformLocationWith4fv(GLint location, const GLfloat* floats, unsigned int numberOfArrays);
|
||||
|
||||
/** calls glUniformMatrix2fv only if the values are different than the previous call for this same shader program. */
|
||||
void setUniformLocationWithMatrix2fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices);
|
||||
void setUniformLocationWithMatrix2fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices);
|
||||
|
||||
/** calls glUniformMatrix3fv only if the values are different than the previous call for this same shader program. */
|
||||
void setUniformLocationWithMatrix3fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices);
|
||||
void setUniformLocationWithMatrix3fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices);
|
||||
|
||||
/** calls glUniformMatrix4fv only if the values are different than the previous call for this same shader program. */
|
||||
void setUniformLocationWithMatrix4fv(GLint location, GLfloat* matrixArray, unsigned int numberOfMatrices);
|
||||
void setUniformLocationWithMatrix4fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices);
|
||||
|
||||
/** will update the builtin uniforms if they are different than the previous call for this same shader program. */
|
||||
void setUniformsForBuiltins();
|
||||
void setUniformsForBuiltins(const kmMat4 &modelView);
|
||||
|
||||
/** returns the vertexShader error log */
|
||||
std::string getVertexShaderLog() const;
|
||||
|
@ -226,8 +229,9 @@ public:
|
|||
inline const GLuint getProgram() const { return _program; }
|
||||
|
||||
private:
|
||||
bool updateUniformLocation(GLint location, GLvoid* data, unsigned int bytes);
|
||||
bool updateUniformLocation(GLint location, const GLvoid* data, unsigned int bytes);
|
||||
virtual std::string getDescription() const;
|
||||
|
||||
bool compileShader(GLuint * shader, GLenum type, const GLchar* source);
|
||||
std::string logForOpenGLObject(GLuint object, GLInfoFunction infoFunc, GLLogFunction logFunc) const;
|
||||
|
||||
|
@ -242,6 +246,7 @@ private:
|
|||
unsigned int usesTime:1;
|
||||
unsigned int usesMVP:1;
|
||||
unsigned int usesMV:1;
|
||||
unsigned int usesP:1;
|
||||
unsigned int usesRandom:1;
|
||||
|
||||
// handy way to initialize the bitfield
|
||||
|
|
|
@ -33,7 +33,7 @@ Use any of these editors to generate BMFonts:
|
|||
#ifndef __CCBITMAP_FONT_ATLAS_H__
|
||||
#define __CCBITMAP_FONT_ATLAS_H__
|
||||
|
||||
#include "CCSpriteBatchNode.h"
|
||||
#include "renderer/CCNewSpriteBatchNode.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 SpriteBatchNode, public LabelProtocol, public RGBAProtocol
|
||||
class CC_DLL LabelBMFont : public NewSpriteBatchNode, public LabelProtocol, public RGBAProtocol
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -131,7 +131,7 @@ bool LabelTTF::initWithString(const std::string& string, const std::string& font
|
|||
if (Sprite::init())
|
||||
{
|
||||
// shader program
|
||||
this->setShaderProgram(ShaderCache::getInstance()->getProgram(SHADER_PROGRAM));
|
||||
// this->setShaderProgram(ShaderCache::getInstance()->getProgram(SHADER_PROGRAM));
|
||||
|
||||
_dimensions = Size(dimensions.width, dimensions.height);
|
||||
_alignment = hAlignment;
|
||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
|||
#ifndef __CCLABELTTF_H__
|
||||
#define __CCLABELTTF_H__
|
||||
|
||||
#include "CCSprite.h"
|
||||
#include "renderer/CCNewSprite.h"
|
||||
#include "CCTexture2D.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -54,7 +54,7 @@ NS_CC_BEGIN
|
|||
* @endcode
|
||||
*
|
||||
*/
|
||||
class CC_DLL LabelTTF : public Sprite, public LabelProtocol
|
||||
class CC_DLL LabelTTF : public NewSprite, public LabelProtocol
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -43,6 +43,8 @@ THE SOFTWARE.
|
|||
#include "CCEventListenerAcceleration.h"
|
||||
#include "platform/CCDevice.h"
|
||||
#include "CCScene.h"
|
||||
#include "CustomCommand.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -698,6 +700,14 @@ void LayerColor::updateColor()
|
|||
}
|
||||
|
||||
void LayerColor::draw()
|
||||
{
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(LayerColor::onDraw, this);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void LayerColor::onDraw()
|
||||
{
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
|
@ -1073,7 +1083,7 @@ void LayerMultiplex::switchToAndReleaseMe(int n)
|
|||
|
||||
std::string LayerMultiplex::getDescription() const
|
||||
{
|
||||
return StringUtils::format("<LayerMultiplex | Tag = %d, Layers = %d", _tag, _children.size());
|
||||
return StringUtils::format("<LayerMultiplex | Tag = %d, Layers = %zd", _tag, _children.size());
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -271,6 +271,8 @@ public:
|
|||
// Overrides
|
||||
//
|
||||
virtual void draw() override;
|
||||
virtual void onDraw();
|
||||
|
||||
virtual void setColor(const Color3B &color) override;
|
||||
virtual void setOpacity(GLubyte opacity) override;
|
||||
virtual void setContentSize(const Size & var) override;
|
||||
|
|
|
@ -103,9 +103,6 @@ Node::Node(void)
|
|||
, _anchorPointInPoints(Point::ZERO)
|
||||
, _anchorPoint(Point::ZERO)
|
||||
, _contentSize(Size::ZERO)
|
||||
, _additionalTransform(AffineTransform::IDENTITY)
|
||||
, _transform(AffineTransform::IDENTITY)
|
||||
, _inverse(AffineTransform::IDENTITY)
|
||||
, _additionalTransformDirty(false)
|
||||
, _transformDirty(true)
|
||||
, _inverseDirty(true)
|
||||
|
@ -144,6 +141,10 @@ Node::Node(void)
|
|||
|
||||
ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine();
|
||||
_scriptType = pEngine != NULL ? pEngine->getScriptType() : kScriptTypeNone;
|
||||
|
||||
kmMat4Identity(&_transform);
|
||||
kmMat4Identity(&_inverse);
|
||||
kmMat4Identity(&_additionalTransform);
|
||||
}
|
||||
|
||||
Node::~Node()
|
||||
|
@ -395,7 +396,7 @@ void Node::setPositionY(float y)
|
|||
setPosition(Point(_position.x, y));
|
||||
}
|
||||
|
||||
int Node::getChildrenCount() const
|
||||
ssize_t Node::getChildrenCount() const
|
||||
{
|
||||
return _children.size();
|
||||
}
|
||||
|
@ -543,7 +544,7 @@ void Node::setShaderProgram(GLProgram *pShaderProgram)
|
|||
Rect Node::getBoundingBox() const
|
||||
{
|
||||
Rect rect = Rect(0, 0, _contentSize.width, _contentSize.height);
|
||||
return RectApplyAffineTransform(rect, getNodeToParentTransform());
|
||||
return RectApplyAffineTransform(rect, getNodeToParentAffineTransform());
|
||||
}
|
||||
|
||||
Node * Node::create(void)
|
||||
|
@ -683,7 +684,7 @@ void Node::removeChild(Node* child, bool cleanup /* = true */)
|
|||
return;
|
||||
}
|
||||
|
||||
auto index = _children.getIndex(child);
|
||||
ssize_t index = _children.getIndex(child);
|
||||
if( index != CC_INVALID_INDEX )
|
||||
this->detachChild( child, index, cleanup );
|
||||
}
|
||||
|
@ -741,7 +742,7 @@ void Node::removeAllChildrenWithCleanup(bool cleanup)
|
|||
|
||||
}
|
||||
|
||||
void Node::detachChild(Node *child, int childIndex, bool doCleanup)
|
||||
void Node::detachChild(Node *child, ssize_t childIndex, bool doCleanup)
|
||||
{
|
||||
// IMPORTANT:
|
||||
// -1st do onExit
|
||||
|
@ -906,16 +907,17 @@ void Node::transform()
|
|||
updatePhysicsTransform();
|
||||
#endif
|
||||
|
||||
kmMat4 transfrom4x4;
|
||||
|
||||
// Convert 3x3 into 4x4 matrix
|
||||
CGAffineToGL(this->getNodeToParentTransform(), transfrom4x4.mat);
|
||||
kmMat4 transfrom4x4 = this->getNodeToParentTransform();
|
||||
|
||||
// Update Z vertex manually
|
||||
transfrom4x4.mat[14] = _vertexZ;
|
||||
|
||||
|
||||
kmGLMultMatrix( &transfrom4x4 );
|
||||
|
||||
// saves the MV matrix
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewTransform);
|
||||
|
||||
|
||||
// XXX: Expensive calls. Camera should be integrated into the cached affine matrix
|
||||
if ( _camera != NULL && !(_grid != NULL && _grid->isActive()) )
|
||||
|
@ -930,7 +932,6 @@ void Node::transform()
|
|||
if( translate )
|
||||
kmGLTranslatef(RENDER_IN_SUBPIXEL(-_anchorPointInPoints.x), RENDER_IN_SUBPIXEL(-_anchorPointInPoints.y), 0 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1055,7 +1056,7 @@ Action * Node::getActionByTag(int tag)
|
|||
return _actionManager->getActionByTag(tag, this);
|
||||
}
|
||||
|
||||
int Node::getNumberOfRunningActions() const
|
||||
ssize_t Node::getNumberOfRunningActions() const
|
||||
{
|
||||
return _actionManager->getNumberOfRunningActionsInTarget(this);
|
||||
}
|
||||
|
@ -1182,7 +1183,16 @@ void Node::update(float fDelta)
|
|||
}
|
||||
}
|
||||
|
||||
const AffineTransform& Node::getNodeToParentTransform() const
|
||||
AffineTransform Node::getNodeToParentAffineTransform() const
|
||||
{
|
||||
AffineTransform ret;
|
||||
kmMat4 ret4 = getNodeToParentTransform();
|
||||
GLToCGAffine(ret4.mat, &ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const kmMat4& Node::getNodeToParentTransform() const
|
||||
{
|
||||
if (_transformDirty)
|
||||
{
|
||||
|
@ -1226,29 +1236,34 @@ const AffineTransform& Node::getNodeToParentTransform() const
|
|||
|
||||
// Build Transform Matrix
|
||||
// Adjusted transform calculation for rotational skew
|
||||
_transform = AffineTransformMake( cy * _scaleX, sy * _scaleX,
|
||||
-sx * _scaleY, cx * _scaleY,
|
||||
x, y );
|
||||
_transform = { cy * _scaleX, sy * _scaleX, 0, 0,
|
||||
-sx * _scaleY, cx * _scaleY, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
x, y, 0, 1 };
|
||||
|
||||
// XXX: Try to inline skew
|
||||
// If skew is needed, apply skew and then anchor point
|
||||
if (needsSkewMatrix)
|
||||
{
|
||||
AffineTransform skewMatrix = AffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(_skewY)),
|
||||
tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1.0f,
|
||||
0.0f, 0.0f );
|
||||
_transform = AffineTransformConcat(skewMatrix, _transform);
|
||||
kmMat4 skewMatrix = { 1, tanf(CC_DEGREES_TO_RADIANS(_skewY)), 0, 0,
|
||||
tanf(CC_DEGREES_TO_RADIANS(_skewX)),1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1};
|
||||
|
||||
kmMat4Multiply(&_transform, &skewMatrix, &_transform);
|
||||
|
||||
// adjust anchor point
|
||||
if (!_anchorPointInPoints.equals(Point::ZERO))
|
||||
{
|
||||
_transform = AffineTransformTranslate(_transform, -_anchorPointInPoints.x, -_anchorPointInPoints.y);
|
||||
// XXX: Argh, kmMat needs a "translate" method
|
||||
_transform.mat[12] += -_anchorPointInPoints.x;
|
||||
_transform.mat[13] += -_anchorPointInPoints.y;
|
||||
}
|
||||
}
|
||||
|
||||
if (_additionalTransformDirty)
|
||||
{
|
||||
_transform = AffineTransformConcat(_transform, _additionalTransform);
|
||||
kmMat4Multiply(&_transform, &_transform, &_additionalTransform);
|
||||
_additionalTransformDirty = false;
|
||||
}
|
||||
|
||||
|
@ -1259,47 +1274,94 @@ const AffineTransform& Node::getNodeToParentTransform() const
|
|||
}
|
||||
|
||||
void Node::setAdditionalTransform(const AffineTransform& additionalTransform)
|
||||
{
|
||||
CGAffineToGL(additionalTransform, _additionalTransform.mat);
|
||||
_transformDirty = true;
|
||||
_additionalTransformDirty = true;
|
||||
}
|
||||
|
||||
void Node::setAdditionalTransform(const kmMat4& additionalTransform)
|
||||
{
|
||||
_additionalTransform = additionalTransform;
|
||||
_transformDirty = true;
|
||||
_additionalTransformDirty = true;
|
||||
}
|
||||
|
||||
const AffineTransform& Node::getParentToNodeTransform() const
|
||||
|
||||
AffineTransform Node::getParentToNodeAffineTransform() const
|
||||
{
|
||||
AffineTransform ret;
|
||||
kmMat4 ret4 = getParentToNodeTransform();
|
||||
|
||||
GLToCGAffine(ret4.mat,&ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const kmMat4& Node::getParentToNodeTransform() const
|
||||
{
|
||||
if ( _inverseDirty ) {
|
||||
_inverse = AffineTransformInvert(this->getNodeToParentTransform());
|
||||
kmMat4Inverse(&_inverse, &_transform);
|
||||
_inverseDirty = false;
|
||||
}
|
||||
|
||||
return _inverse;
|
||||
}
|
||||
|
||||
AffineTransform Node::getNodeToWorldTransform() const
|
||||
|
||||
AffineTransform Node::getNodeToWorldAffineTransform() const
|
||||
{
|
||||
AffineTransform t = this->getNodeToParentTransform();
|
||||
AffineTransform t = this->getNodeToParentAffineTransform();
|
||||
|
||||
for (Node *p = _parent; p != NULL; p = p->getParent())
|
||||
t = AffineTransformConcat(t, p->getNodeToParentTransform());
|
||||
t = AffineTransformConcat(t, p->getNodeToParentAffineTransform());
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
AffineTransform Node::getWorldToNodeTransform() const
|
||||
kmMat4 Node::getNodeToWorldTransform() const
|
||||
{
|
||||
return AffineTransformInvert(this->getNodeToWorldTransform());
|
||||
kmMat4 t = this->getNodeToParentTransform();
|
||||
|
||||
for (Node *p = _parent; p != NULL; p = p->getParent())
|
||||
kmMat4Multiply(&t, &t, &p->getNodeToParentTransform());
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
AffineTransform Node::getWorldToNodeAffineTransform() const
|
||||
{
|
||||
return AffineTransformInvert(this->getNodeToWorldAffineTransform());
|
||||
}
|
||||
|
||||
kmMat4 Node::getWorldToNodeTransform() const
|
||||
{
|
||||
kmMat4 tmp, tmp2;
|
||||
|
||||
tmp2 = this->getNodeToWorldTransform();
|
||||
kmMat4Inverse(&tmp, &tmp2);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
Point Node::convertToNodeSpace(const Point& worldPoint) const
|
||||
{
|
||||
Point ret = PointApplyAffineTransform(worldPoint, getWorldToNodeTransform());
|
||||
return ret;
|
||||
kmMat4 tmp = getWorldToNodeTransform();
|
||||
kmVec3 vec3 = {worldPoint.x, worldPoint.y, 0};
|
||||
kmVec3 ret;
|
||||
kmVec3Transform(&ret, &vec3, &tmp);
|
||||
Point p = {ret.x, ret.y };
|
||||
return p;
|
||||
}
|
||||
|
||||
Point Node::convertToWorldSpace(const Point& nodePoint) const
|
||||
{
|
||||
Point ret = PointApplyAffineTransform(nodePoint, getNodeToWorldTransform());
|
||||
return ret;
|
||||
kmMat4 tmp = getNodeToWorldTransform();
|
||||
kmVec3 vec3 = {nodePoint.x, nodePoint.y, 0};
|
||||
kmVec3 ret;
|
||||
kmVec3Transform(&ret, &vec3, &tmp);
|
||||
Point p = {ret.x, ret.y };
|
||||
return p;
|
||||
|
||||
}
|
||||
|
||||
Point Node::convertToNodeSpaceAR(const Point& worldPoint) const
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "CCProtocols.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
#include "CCVector.h"
|
||||
#include "kazmath/kazmath.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -620,7 +621,7 @@ public:
|
|||
*
|
||||
* @return The amount of children.
|
||||
*/
|
||||
int getChildrenCount() const;
|
||||
ssize_t getChildrenCount() const;
|
||||
|
||||
/**
|
||||
* Sets the parent node
|
||||
|
@ -1041,10 +1042,10 @@ public:
|
|||
*
|
||||
* @return The number of actions that are running plus the ones that are schedule to run
|
||||
*/
|
||||
int getNumberOfRunningActions() const;
|
||||
ssize_t getNumberOfRunningActions() const;
|
||||
|
||||
/** @deprecated Use getNumberOfRunningActions() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE int numberOfRunningActions() const { return getNumberOfRunningActions(); };
|
||||
CC_DEPRECATED_ATTRIBUTE ssize_t numberOfRunningActions() const { return getNumberOfRunningActions(); };
|
||||
|
||||
/// @} end of Actions
|
||||
|
||||
|
@ -1226,35 +1227,40 @@ public:
|
|||
* Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
|
||||
* The matrix is in Pixels.
|
||||
*/
|
||||
virtual const AffineTransform& getNodeToParentTransform() const;
|
||||
virtual const kmMat4& getNodeToParentTransform() const;
|
||||
virtual AffineTransform getNodeToParentAffineTransform() const;
|
||||
|
||||
/** @deprecated use getNodeToParentTransform() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform nodeToParentTransform() const { return getNodeToParentTransform(); }
|
||||
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform nodeToParentTransform() const { return getNodeToParentAffineTransform(); }
|
||||
|
||||
/**
|
||||
* Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
|
||||
* The matrix is in Pixels.
|
||||
*/
|
||||
virtual const AffineTransform& getParentToNodeTransform() const;
|
||||
virtual const kmMat4& getParentToNodeTransform() const;
|
||||
virtual AffineTransform getParentToNodeAffineTransform() const;
|
||||
|
||||
/** @deprecated Use getParentToNodeTransform() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform parentToNodeTransform() const { return getParentToNodeTransform(); }
|
||||
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform parentToNodeTransform() const { return getParentToNodeAffineTransform(); }
|
||||
|
||||
/**
|
||||
* Returns the world affine transform matrix. The matrix is in Pixels.
|
||||
*/
|
||||
virtual AffineTransform getNodeToWorldTransform() const;
|
||||
virtual kmMat4 getNodeToWorldTransform() const;
|
||||
virtual AffineTransform getNodeToWorldAffineTransform() const;
|
||||
|
||||
/** @deprecated Use getNodeToWorldTransform() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform nodeToWorldTransform() const { return getNodeToWorldTransform(); }
|
||||
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform nodeToWorldTransform() const { return getNodeToWorldAffineTransform(); }
|
||||
|
||||
/**
|
||||
* Returns the inverse world affine transform matrix. The matrix is in Pixels.
|
||||
*/
|
||||
virtual AffineTransform getWorldToNodeTransform() const;
|
||||
virtual kmMat4 getWorldToNodeTransform() const;
|
||||
virtual AffineTransform getWorldToNodeAffineTransform() const;
|
||||
|
||||
|
||||
/** @deprecated Use worldToNodeTransform() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform worldToNodeTransform() const { return getWorldToNodeTransform(); }
|
||||
CC_DEPRECATED_ATTRIBUTE inline virtual AffineTransform worldToNodeTransform() const { return getWorldToNodeAffineTransform(); }
|
||||
|
||||
/// @} end of Transformations
|
||||
|
||||
|
@ -1343,6 +1349,7 @@ public:
|
|||
@endcode
|
||||
*/
|
||||
void setAdditionalTransform(const AffineTransform& additionalTransform);
|
||||
void setAdditionalTransform(const kmMat4& additionalTransform);
|
||||
|
||||
/// @} end of Coordinate Converters
|
||||
|
||||
|
@ -1401,7 +1408,7 @@ protected:
|
|||
void insertChild(Node* child, int z);
|
||||
|
||||
/// Removes a child, call child->onExit(), do cleanup, remove it from children array.
|
||||
void detachChild(Node *child, int index, bool doCleanup);
|
||||
void detachChild(Node *child, ssize_t index, bool doCleanup);
|
||||
|
||||
/// Convert cocos2d coordinates to UI windows coordinate.
|
||||
Point convertToWindowSpace(const Point& nodePoint) const;
|
||||
|
@ -1426,9 +1433,10 @@ protected:
|
|||
Size _contentSize; ///< untransformed size of the node
|
||||
|
||||
// "cache" variables are allowed to be mutable
|
||||
mutable AffineTransform _additionalTransform; ///< transform
|
||||
mutable AffineTransform _transform; ///< transform
|
||||
mutable AffineTransform _inverse; ///< inverse transform
|
||||
mutable kmMat4 _additionalTransform; ///< transform
|
||||
mutable kmMat4 _transform; ///< transform
|
||||
mutable kmMat4 _inverse; ///< inverse transform
|
||||
kmMat4 _modelViewTransform; ///< ModelView transform of the Node.
|
||||
mutable bool _additionalTransformDirty; ///< The flag to check whether the additional transform is dirty
|
||||
mutable bool _transformDirty; ///< transform dirty flag
|
||||
mutable bool _inverseDirty; ///< inverse transform dirty flag
|
||||
|
|
|
@ -143,7 +143,7 @@ int NotificationCenter::removeAllObservers(Object *target)
|
|||
}
|
||||
|
||||
_observers->removeObjectsInArray(toRemove);
|
||||
return toRemove->count();
|
||||
return static_cast<int>(toRemove->count());
|
||||
}
|
||||
|
||||
void NotificationCenter::registerScriptObserver( Object *target, int handler,const char* name)
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
#include "platform/CCFileUtils.h"
|
||||
#include "kazmath/GL/matrix.h"
|
||||
#include "CCProfiling.h"
|
||||
#include "QuadCommand.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -401,18 +403,33 @@ void ParticleBatchNode::draw(void)
|
|||
return;
|
||||
}
|
||||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
// CC_NODE_DRAW_SETUP();
|
||||
//
|
||||
// GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
//
|
||||
// _textureAtlas->drawQuads();
|
||||
|
||||
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);
|
||||
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0,
|
||||
_vertexZ,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
shader,
|
||||
_blendFunc,
|
||||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
CC_PROFILER_STOP("CCParticleBatchNode - draw");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ParticleBatchNode::increaseAtlasCapacityTo(int quantity)
|
||||
void ParticleBatchNode::increaseAtlasCapacityTo(ssize_t quantity)
|
||||
{
|
||||
CCLOG("cocos2d: ParticleBatchNode: resizing TextureAtlas capacity from [%lu] to [%lu].",
|
||||
(long)_textureAtlas->getCapacity(),
|
||||
|
|
|
@ -129,7 +129,7 @@ public:
|
|||
|
||||
private:
|
||||
void updateAllAtlasIndexes();
|
||||
void increaseAtlasCapacityTo(int quantity);
|
||||
void increaseAtlasCapacityTo(ssize_t quantity);
|
||||
int searchNewPositionInChildrenForZ(int z);
|
||||
void getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z);
|
||||
int addChildHelper(ParticleSystem* child, int z, int aTag);
|
||||
|
|
|
@ -38,9 +38,13 @@ THE SOFTWARE.
|
|||
#include "CCNotificationCenter.h"
|
||||
#include "CCEventType.h"
|
||||
#include "CCConfiguration.h"
|
||||
#include "CustomCommand.h"
|
||||
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
#include "Renderer.h"
|
||||
#include "QuadCommand.h"
|
||||
#include "CustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -347,62 +351,104 @@ void ParticleSystemQuad::postStep()
|
|||
}
|
||||
|
||||
// overriding draw method
|
||||
//void ParticleSystemQuad::draw()
|
||||
//{
|
||||
// CCASSERT(!_batchNode,"draw should not be called when added to a particleBatchNode");
|
||||
//
|
||||
// CC_NODE_DRAW_SETUP();
|
||||
//
|
||||
// GL::bindTexture2D( _texture->getName() );
|
||||
// GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
//
|
||||
// CCASSERT( _particleIdx == _particleCount, "Abnormal error in particle quad");
|
||||
//
|
||||
// if (Configuration::getInstance()->supportsShareableVAO())
|
||||
// {
|
||||
// //
|
||||
// // Using VBO and VAO
|
||||
// //
|
||||
// GL::bindVAO(_VAOname);
|
||||
//
|
||||
//#if CC_REBIND_INDICES_BUFFER
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
//#endif
|
||||
//
|
||||
// glDrawElements(GL_TRIANGLES, (GLsizei) _particleIdx*6, GL_UNSIGNED_SHORT, 0);
|
||||
//
|
||||
//#if CC_REBIND_INDICES_BUFFER
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
//#endif
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //
|
||||
// // Using VBO without VAO
|
||||
// //
|
||||
//
|
||||
// #define kQuadSize sizeof(_quads[0].bl)
|
||||
//
|
||||
// GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
|
||||
//
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
// // vertices
|
||||
// glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices));
|
||||
// // colors
|
||||
// glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors));
|
||||
// // tex coords
|
||||
// glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords));
|
||||
//
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
//
|
||||
// glDrawElements(GL_TRIANGLES, (GLsizei) _particleIdx*6, GL_UNSIGNED_SHORT, 0);
|
||||
//
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
// }
|
||||
//
|
||||
// CC_INCREMENT_GL_DRAWS(1);
|
||||
// CHECK_GL_ERROR_DEBUG();
|
||||
//}
|
||||
|
||||
void ParticleSystemQuad::draw()
|
||||
{
|
||||
CCASSERT(!_batchNode,"draw should not be called when added to a particleBatchNode");
|
||||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
GL::bindTexture2D( _texture->getName() );
|
||||
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
|
||||
CCASSERT( _particleIdx == _particleCount, "Abnormal error in particle quad");
|
||||
|
||||
if (Configuration::getInstance()->supportsShareableVAO())
|
||||
//quad command
|
||||
if(_particleIdx > 0)
|
||||
{
|
||||
// //transform vertices
|
||||
// std::vector<V3F_C4B_T2F_Quad> drawQuads(_particleIdx);
|
||||
// memcpy(&drawQuads[0], _quads, sizeof(V3F_C4B_T2F_Quad) * _particleIdx);
|
||||
// AffineTransform worldTM = getNodeToWorldTransform();
|
||||
// for(int index = 0; index <_particleIdx; ++index)
|
||||
// {
|
||||
// V3F_C4B_T2F_Quad* quad = _quads + index;
|
||||
//
|
||||
// Using VBO and VAO
|
||||
// Point pt(0,0);
|
||||
// pt = PointApplyAffineTransform( Point(quad->bl.vertices.x, quad->bl.vertices.y), worldTM);
|
||||
// drawQuads[index].bl.vertices.x = pt.x;
|
||||
// drawQuads[index].bl.vertices.y = pt.y;
|
||||
//
|
||||
GL::bindVAO(_VAOname);
|
||||
|
||||
#if CC_REBIND_INDICES_BUFFER
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
#endif
|
||||
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei) _particleIdx*6, GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
#if CC_REBIND_INDICES_BUFFER
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// pt = PointApplyAffineTransform( Point(quad->br.vertices.x, quad->br.vertices.y), worldTM);
|
||||
// drawQuads[index].br.vertices.x = pt.x;
|
||||
// drawQuads[index].br.vertices.y = pt.y;
|
||||
//
|
||||
// Using VBO without VAO
|
||||
// pt = PointApplyAffineTransform( Point(quad->tl.vertices.x, quad->tl.vertices.y), worldTM);
|
||||
// drawQuads[index].tl.vertices.x = pt.x;
|
||||
// drawQuads[index].tl.vertices.y = pt.y;
|
||||
//
|
||||
// pt = PointApplyAffineTransform( Point(quad->tr.vertices.x, quad->tr.vertices.y), worldTM);
|
||||
// drawQuads[index].tr.vertices.x = pt.x;
|
||||
// drawQuads[index].tr.vertices.y = pt.y;
|
||||
//
|
||||
// }
|
||||
|
||||
#define kQuadSize sizeof(_quads[0].bl)
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
// vertices
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices));
|
||||
// colors
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors));
|
||||
// tex coords
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords));
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei) _particleIdx*6, GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
}
|
||||
|
||||
CC_INCREMENT_GL_DRAWS(1);
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
}
|
||||
|
||||
void ParticleSystemQuad::setTotalParticles(int tp)
|
||||
|
|
|
@ -108,6 +108,7 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual void draw() override;
|
||||
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -149,6 +150,7 @@ protected:
|
|||
|
||||
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
||||
|
||||
kmMat4 _transformMatrix;
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystemQuad);
|
||||
};
|
||||
|
|
|
@ -32,6 +32,9 @@ THE SOFTWARE.
|
|||
#include "CCDirector.h"
|
||||
#include "TransformUtils.h"
|
||||
#include "CCDrawingPrimitives.h"
|
||||
#include "Renderer.h"
|
||||
#include "CustomCommand.h"
|
||||
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
||||
|
@ -497,10 +500,8 @@ Point ProgressTimer::boundaryTexCoord(char index)
|
|||
return Point::ZERO;
|
||||
}
|
||||
|
||||
void ProgressTimer::draw(void)
|
||||
void ProgressTimer::onDraw()
|
||||
{
|
||||
if( ! _vertexData || ! _sprite)
|
||||
return;
|
||||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
|
@ -548,4 +549,16 @@ void ProgressTimer::draw(void)
|
|||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
void ProgressTimer::draw()
|
||||
{
|
||||
if( ! _vertexData || ! _sprite)
|
||||
return;
|
||||
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(ProgressTimer::onDraw, this);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
}
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -130,6 +130,8 @@ protected:
|
|||
/** Initializes a progress timer with the sprite as the shape the timer goes through */
|
||||
bool initWithSprite(Sprite* sp);
|
||||
|
||||
void onDraw();
|
||||
|
||||
Tex2F textureCoordFromAlphaPoint(Point alpha);
|
||||
Vertex2F vertexFromAlphaPoint(Point alpha);
|
||||
void updateProgress(void);
|
||||
|
|
|
@ -411,6 +411,7 @@ void RenderTexture::end()
|
|||
kmGLPopMatrix();
|
||||
}
|
||||
|
||||
//TODO find a better way to clear the screen, there is no need to rebind render buffer there.
|
||||
void RenderTexture::clear(float r, float g, float b, float a)
|
||||
{
|
||||
this->beginWithClear(r, g, b, a);
|
||||
|
|
|
@ -59,35 +59,35 @@ public:
|
|||
/** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888 */
|
||||
static RenderTexture * create(int w, int h);
|
||||
|
||||
/** starts grabbing */
|
||||
virtual /** starts grabbing */
|
||||
void begin();
|
||||
|
||||
/** starts rendering to the texture while clearing the texture first.
|
||||
This is more efficient then calling -clear first and then -begin */
|
||||
void beginWithClear(float r, float g, float b, float a);
|
||||
virtual void beginWithClear(float r, float g, float b, float a);
|
||||
|
||||
/** starts rendering to the texture while clearing the texture first.
|
||||
This is more efficient then calling -clear first and then -begin */
|
||||
void beginWithClear(float r, float g, float b, float a, float depthValue);
|
||||
virtual void beginWithClear(float r, float g, float b, float a, float depthValue);
|
||||
|
||||
/** starts rendering to the texture while clearing the texture first.
|
||||
This is more efficient then calling -clear first and then -begin */
|
||||
void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue);
|
||||
virtual void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue);
|
||||
|
||||
/** end is key word of lua, use other name to export to lua. */
|
||||
inline void endToLua(){ end();};
|
||||
|
||||
/** ends grabbing*/
|
||||
virtual /** ends grabbing*/
|
||||
void end();
|
||||
|
||||
/** clears the texture with a color */
|
||||
void clear(float r, float g, float b, float a);
|
||||
|
||||
/** clears the texture with a specified depth value */
|
||||
void clearDepth(float depthValue);
|
||||
virtual void clearDepth(float depthValue);
|
||||
|
||||
/** clears the texture with a specified stencil value */
|
||||
void clearStencil(int stencilValue);
|
||||
virtual void clearStencil(int stencilValue);
|
||||
/* creates a new Image from with the texture's data.
|
||||
Caller is responsible for releasing it by calling delete.
|
||||
*/
|
||||
|
@ -164,7 +164,7 @@ public:
|
|||
bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat);
|
||||
|
||||
protected:
|
||||
void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags);
|
||||
virtual void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags);
|
||||
|
||||
GLuint _FBO;
|
||||
GLuint _depthRenderBufffer;
|
||||
|
|
|
@ -677,7 +677,7 @@ unsigned int Scheduler::scheduleScriptFunc(unsigned int handler, float interval,
|
|||
|
||||
void Scheduler::unscheduleScriptEntry(unsigned int scheduleScriptEntryID)
|
||||
{
|
||||
for (int i = _scriptHandlerEntries.size() - 1; i >= 0; i--)
|
||||
for (ssize_t i = _scriptHandlerEntries.size() - 1; i >= 0; i--)
|
||||
{
|
||||
SchedulerScriptHandlerEntry* entry = _scriptHandlerEntries.at(i);
|
||||
if (entry->getEntryId() == (int)scheduleScriptEntryID)
|
||||
|
|
|
@ -33,6 +33,7 @@ NS_CC_BEGIN
|
|||
|
||||
enum {
|
||||
kShaderType_PositionTextureColor,
|
||||
kShaderType_PositionTextureColor_noMVP,
|
||||
kShaderType_PositionTextureColorAlphaTest,
|
||||
kShaderType_PositionColor,
|
||||
kShaderType_PositionTexture,
|
||||
|
@ -103,6 +104,11 @@ void ShaderCache::loadDefaultShaders()
|
|||
loadDefaultShader(p, kShaderType_PositionTextureColor);
|
||||
_programs.insert( std::make_pair( GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR, p ) );
|
||||
|
||||
// Position Texture Color without MVP shader
|
||||
p = new GLProgram();
|
||||
loadDefaultShader(p, kShaderType_PositionTextureColor_noMVP);
|
||||
_programs.insert( std::make_pair( GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP, p ) );
|
||||
|
||||
// Position Texture Color alpha test
|
||||
p = new GLProgram();
|
||||
loadDefaultShader(p, kShaderType_PositionTextureColorAlphaTest);
|
||||
|
@ -219,6 +225,15 @@ void ShaderCache::loadDefaultShader(GLProgram *p, int type)
|
|||
p->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
|
||||
|
||||
break;
|
||||
case kShaderType_PositionTextureColor_noMVP:
|
||||
p->initWithVertexShaderByteArray(ccPositionTextureColor_noMVP_vert, ccPositionTextureColor_noMVP_frag);
|
||||
|
||||
p->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
|
||||
p->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
|
||||
p->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
|
||||
|
||||
break;
|
||||
|
||||
case kShaderType_PositionTextureColorAlphaTest:
|
||||
p->initWithVertexShaderByteArray(ccPositionTextureColor_vert, ccPositionTextureColorAlphaTest_frag);
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@ THE SOFTWARE.
|
|||
#include "CCAffineTransform.h"
|
||||
#include "TransformUtils.h"
|
||||
#include "CCProfiling.h"
|
||||
#include "Renderer.h"
|
||||
#include "QuadCommand.h"
|
||||
// external
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
||||
|
@ -249,7 +251,7 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated)
|
|||
_quad.tr.colors = Color4B::WHITE;
|
||||
|
||||
// shader program
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
|
||||
|
||||
// update texture (calls updateBlendFunc)
|
||||
setTexture(texture);
|
||||
|
@ -522,7 +524,9 @@ void Sprite::updateTransform(void)
|
|||
else
|
||||
{
|
||||
CCASSERT( dynamic_cast<Sprite*>(_parent), "Logic error in Sprite. Parent must be a Sprite");
|
||||
_transformToBatch = AffineTransformConcat( getNodeToParentTransform() , static_cast<Sprite*>(_parent)->_transformToBatch );
|
||||
kmMat4 nodeToParent = getNodeToParentTransform();
|
||||
kmMat4 parentTransform = static_cast<Sprite*>(_parent)->_transformToBatch;
|
||||
kmMat4Multiply(&_transformToBatch, &nodeToParent, &parentTransform);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -536,13 +540,13 @@ void Sprite::updateTransform(void)
|
|||
|
||||
float x2 = x1 + size.width;
|
||||
float y2 = y1 + size.height;
|
||||
float x = _transformToBatch.tx;
|
||||
float y = _transformToBatch.ty;
|
||||
float x = _transformToBatch.mat[12];
|
||||
float y = _transformToBatch.mat[13];
|
||||
|
||||
float cr = _transformToBatch.a;
|
||||
float sr = _transformToBatch.b;
|
||||
float cr2 = _transformToBatch.d;
|
||||
float sr2 = -_transformToBatch.c;
|
||||
float cr = _transformToBatch.mat[0];
|
||||
float sr = _transformToBatch.mat[1];
|
||||
float cr2 = _transformToBatch.mat[5];
|
||||
float sr2 = -_transformToBatch.mat[4];
|
||||
float ax = x1 * cr - y1 * sr2 + x;
|
||||
float ay = x1 * sr + y1 * cr2 + y;
|
||||
|
||||
|
@ -595,19 +599,90 @@ void Sprite::updateTransform(void)
|
|||
|
||||
// draw
|
||||
|
||||
//void Sprite::draw(void)
|
||||
//{
|
||||
// CC_PROFILER_START_CATEGORY(kProfilerCategorySprite, "CCSprite - draw");
|
||||
//
|
||||
// CCASSERT(!_batchNode, "If Sprite is being rendered by SpriteBatchNode, Sprite#draw SHOULD NOT be called");
|
||||
//
|
||||
// CC_NODE_DRAW_SETUP();
|
||||
//
|
||||
// GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
//
|
||||
// GL::bindTexture2D( _texture->getName() );
|
||||
// GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
|
||||
//
|
||||
//#define kQuadSize sizeof(_quad.bl)
|
||||
//#ifdef EMSCRIPTEN
|
||||
// long offset = 0;
|
||||
// setGLBufferData(&_quad, 4 * kQuadSize, 0);
|
||||
//#else
|
||||
// long offset = (long)&_quad;
|
||||
//#endif // EMSCRIPTEN
|
||||
//
|
||||
// // vertex
|
||||
// int diff = offsetof( V3F_C4B_T2F, vertices);
|
||||
// glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));
|
||||
//
|
||||
// // texCoods
|
||||
// diff = offsetof( V3F_C4B_T2F, texCoords);
|
||||
// glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));
|
||||
//
|
||||
// // color
|
||||
// diff = offsetof( V3F_C4B_T2F, colors);
|
||||
// glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
|
||||
//
|
||||
//
|
||||
// glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
//
|
||||
// CHECK_GL_ERROR_DEBUG();
|
||||
//
|
||||
//
|
||||
//#if CC_SPRITE_DEBUG_DRAW == 1
|
||||
// // draw bounding box
|
||||
// Point vertices[4]={
|
||||
// Point(_quad.tl.vertices.x,_quad.tl.vertices.y),
|
||||
// Point(_quad.bl.vertices.x,_quad.bl.vertices.y),
|
||||
// Point(_quad.br.vertices.x,_quad.br.vertices.y),
|
||||
// Point(_quad.tr.vertices.x,_quad.tr.vertices.y),
|
||||
// };
|
||||
// ccDrawPoly(vertices, 4, true);
|
||||
//#elif CC_SPRITE_DEBUG_DRAW == 2
|
||||
// // draw texture box
|
||||
// Size s = this->getTextureRect().size;
|
||||
// Point offsetPix = this->getOffsetPosition();
|
||||
// Point vertices[4] = {
|
||||
// Point(offsetPix.x,offsetPix.y), Point(offsetPix.x+s.width,offsetPix.y),
|
||||
// Point(offsetPix.x+s.width,offsetPix.y+s.height), Point(offsetPix.x,offsetPix.y+s.height)
|
||||
// };
|
||||
// ccDrawPoly(vertices, 4, true);
|
||||
//#endif // CC_SPRITE_DEBUG_DRAW
|
||||
//
|
||||
// CC_INCREMENT_GL_DRAWS(1);
|
||||
//
|
||||
// CC_PROFILER_STOP_CATEGORY(kProfilerCategorySprite, "CCSprite - draw");
|
||||
//}
|
||||
|
||||
void Sprite::draw(void)
|
||||
{
|
||||
CC_PROFILER_START_CATEGORY(kProfilerCategorySprite, "CCSprite - draw");
|
||||
// updateQuadVertices();
|
||||
|
||||
CCASSERT(!_batchNode, "If Sprite is being rendered by SpriteBatchNode, Sprite#draw SHOULD NOT be called");
|
||||
kmMat4 mv;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
//TODO implement z order
|
||||
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
|
||||
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv);
|
||||
Renderer::getInstance()->addCommand(renderCommand);
|
||||
}
|
||||
|
||||
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
|
||||
GL::bindTexture2D( _texture->getName() );
|
||||
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
|
||||
void Sprite::updateQuadVertices()
|
||||
{
|
||||
|
||||
//#ifdef CC_USE_PHYSICS
|
||||
// updatePhysicsTransform();
|
||||
// setDirty(true);
|
||||
//#endif
|
||||
#define kQuadSize sizeof(_quad.bl)
|
||||
#ifdef EMSCRIPTEN
|
||||
long offset = 0;
|
||||
|
@ -616,47 +691,63 @@ void Sprite::draw(void)
|
|||
size_t offset = (size_t)&_quad;
|
||||
#endif // EMSCRIPTEN
|
||||
|
||||
// vertex
|
||||
int diff = offsetof( V3F_C4B_T2F, vertices);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));
|
||||
//TODO optimize the performance cache affineTransformation
|
||||
|
||||
// texCoods
|
||||
diff = offsetof( V3F_C4B_T2F, texCoords);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));
|
||||
// recalculate matrix only if it is dirty
|
||||
if(isDirty())
|
||||
{
|
||||
|
||||
// color
|
||||
diff = offsetof( V3F_C4B_T2F, colors);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
|
||||
// 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();
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
//
|
||||
// calculate the Quad based on the Affine Matrix
|
||||
//
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
Size size = _rect.size;
|
||||
|
||||
float x1 = _offsetPosition.x;
|
||||
float y1 = _offsetPosition.y;
|
||||
|
||||
#if CC_SPRITE_DEBUG_DRAW == 1
|
||||
// draw bounding box
|
||||
Point vertices[4]={
|
||||
Point(_quad.tl.vertices.x,_quad.tl.vertices.y),
|
||||
Point(_quad.bl.vertices.x,_quad.bl.vertices.y),
|
||||
Point(_quad.br.vertices.x,_quad.br.vertices.y),
|
||||
Point(_quad.tr.vertices.x,_quad.tr.vertices.y),
|
||||
};
|
||||
ccDrawPoly(vertices, 4, true);
|
||||
#elif CC_SPRITE_DEBUG_DRAW == 2
|
||||
// draw texture box
|
||||
Size s = this->getTextureRect().size;
|
||||
Point offsetPix = this->getOffsetPosition();
|
||||
Point vertices[4] = {
|
||||
Point(offsetPix.x,offsetPix.y), Point(offsetPix.x+s.width,offsetPix.y),
|
||||
Point(offsetPix.x+s.width,offsetPix.y+s.height), Point(offsetPix.x,offsetPix.y+s.height)
|
||||
};
|
||||
ccDrawPoly(vertices, 4, true);
|
||||
#endif // CC_SPRITE_DEBUG_DRAW
|
||||
float x2 = x1 + size.width;
|
||||
float y2 = y1 + size.height;
|
||||
float x = _transformToBatch.mat[12];
|
||||
float y = _transformToBatch.mat[13];
|
||||
|
||||
CC_INCREMENT_GL_DRAWS(1);
|
||||
float cr = _transformToBatch.mat[0];
|
||||
float sr = _transformToBatch.mat[1];
|
||||
float cr2 = _transformToBatch.mat[5];
|
||||
float sr2 = -_transformToBatch.mat[4];
|
||||
float ax = x1 * cr - y1 * sr2 + x;
|
||||
float ay = x1 * sr + y1 * cr2 + y;
|
||||
|
||||
CC_PROFILER_STOP_CATEGORY(kProfilerCategorySprite, "CCSprite - draw");
|
||||
float bx = x2 * cr - y1 * sr2 + x;
|
||||
float by = x2 * sr + y1 * cr2 + y;
|
||||
|
||||
float cx = x2 * cr - y2 * sr2 + x;
|
||||
float cy = x2 * sr + y2 * cr2 + y;
|
||||
|
||||
float dx = x1 * cr - y2 * sr2 + x;
|
||||
float dy = x1 * sr + y2 * cr2 + y;
|
||||
|
||||
_quad.bl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), _vertexZ );
|
||||
_quad.br.vertices = Vertex3F( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), _vertexZ );
|
||||
_quad.tl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), _vertexZ );
|
||||
_quad.tr.vertices = Vertex3F( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _vertexZ );
|
||||
|
||||
_recursiveDirty = false;
|
||||
setDirty(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Node overrides
|
||||
|
@ -821,7 +912,7 @@ void Sprite::setDirtyRecursively(bool bValue)
|
|||
|
||||
// XXX HACK: optimization
|
||||
#define SET_DIRTY_RECURSIVELY() { \
|
||||
if (_batchNode && ! _recursiveDirty) { \
|
||||
if (! _recursiveDirty) { \
|
||||
_recursiveDirty = true; \
|
||||
setDirty(true); \
|
||||
if ( _hasChildren) \
|
||||
|
@ -835,6 +926,12 @@ void Sprite::setPosition(const Point& pos)
|
|||
SET_DIRTY_RECURSIVELY();
|
||||
}
|
||||
|
||||
void Sprite::setPosition(float x, float y)
|
||||
{
|
||||
Node::setPosition(x, y);
|
||||
SET_DIRTY_RECURSIVELY();
|
||||
}
|
||||
|
||||
void Sprite::setRotation(float rotation)
|
||||
{
|
||||
Node::setRotation(rotation);
|
||||
|
@ -1052,7 +1149,7 @@ void Sprite::setSpriteFrame(SpriteFrame *spriteFrame)
|
|||
setTextureRect(spriteFrame->getRect(), _rectRotated, spriteFrame->getOriginalSize());
|
||||
}
|
||||
|
||||
void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex)
|
||||
void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, ssize_t frameIndex)
|
||||
{
|
||||
CCASSERT(animationName.size()>0, "CCSprite#setDisplayFrameWithAnimationName. animationName must not be NULL");
|
||||
|
||||
|
@ -1113,7 +1210,7 @@ void Sprite::setBatchNode(SpriteBatchNode *spriteBatchNode)
|
|||
} else {
|
||||
|
||||
// using batch
|
||||
_transformToBatch = AffineTransformIdentity;
|
||||
kmMat4Identity(&_transformToBatch);
|
||||
setTextureAtlas(_batchNode->getTextureAtlas()); // weak ref
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ THE SOFTWARE.
|
|||
#include "CCGLBufferedNode.h"
|
||||
#endif // EMSCRIPTEN
|
||||
#include "CCPhysicsBody.h"
|
||||
#include "kazmath/kazmath.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -257,7 +258,7 @@ public:
|
|||
* Changes the display frame with animation name and index.
|
||||
* The animation name will be get from the AnimationCache
|
||||
*/
|
||||
virtual void setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex);
|
||||
virtual void setDisplayFrameWithAnimationName(const std::string& animationName, ssize_t frameIndex);
|
||||
/// @}
|
||||
|
||||
|
||||
|
@ -291,13 +292,13 @@ public:
|
|||
/**
|
||||
* Returns the index used on the TextureAtlas.
|
||||
*/
|
||||
inline int getAtlasIndex(void) const { return _atlasIndex; }
|
||||
inline ssize_t getAtlasIndex(void) const { return _atlasIndex; }
|
||||
|
||||
/**
|
||||
* Sets the index used on the TextureAtlas.
|
||||
* @warning Don't modify this value unless you know what you are doing
|
||||
*/
|
||||
inline void setAtlasIndex(int atlasIndex) { _atlasIndex = atlasIndex; }
|
||||
inline void setAtlasIndex(ssize_t atlasIndex) { _atlasIndex = atlasIndex; }
|
||||
|
||||
/**
|
||||
* Returns the rect of the Sprite in points
|
||||
|
@ -403,6 +404,7 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual void setPosition(const Point& pos) override;
|
||||
virtual void setPosition(float x, float y) override;
|
||||
virtual void setRotation(float rotation) override;
|
||||
virtual void setRotationX(float rotationX) override;
|
||||
virtual void setRotationY(float rotationY) override;
|
||||
|
@ -422,6 +424,7 @@ public:
|
|||
virtual void setAnchorPoint(const Point& anchor) override;
|
||||
virtual void ignoreAnchorPointForPosition(bool value) override;
|
||||
virtual void setVisible(bool bVisible) override;
|
||||
virtual void updateQuadVertices();
|
||||
virtual void draw(void) override;
|
||||
/// @}
|
||||
|
||||
|
@ -537,14 +540,14 @@ protected:
|
|||
// Data used when the sprite is rendered using a SpriteSheet
|
||||
//
|
||||
TextureAtlas* _textureAtlas; /// SpriteBatchNode texture atlas (weak reference)
|
||||
int _atlasIndex; /// Absolute (real) Index on the SpriteSheet
|
||||
ssize_t _atlasIndex; /// Absolute (real) Index on the SpriteSheet
|
||||
SpriteBatchNode* _batchNode; /// Used batch node (weak reference)
|
||||
|
||||
bool _dirty; /// Whether the sprite needs to be updated
|
||||
bool _recursiveDirty; /// Whether all of the sprite's children needs to be updated
|
||||
bool _hasChildren; /// Whether the sprite contains children
|
||||
bool _shouldBeHidden; /// should not be drawn because one of the ancestors is not visible
|
||||
AffineTransform _transformToBatch;
|
||||
kmMat4 _transformToBatch;
|
||||
|
||||
//
|
||||
// Data used when the sprite is self-rendered
|
||||
|
|
|
@ -51,7 +51,7 @@ NS_CC_BEGIN
|
|||
* creation with Texture2D
|
||||
*/
|
||||
|
||||
SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, int capacity/* = DEFAULT_CAPACITY*/)
|
||||
SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, ssize_t capacity/* = DEFAULT_CAPACITY*/)
|
||||
{
|
||||
SpriteBatchNode *batchNode = new SpriteBatchNode();
|
||||
batchNode->initWithTexture(tex, capacity);
|
||||
|
@ -64,7 +64,7 @@ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, int capacity
|
|||
* creation with File Image
|
||||
*/
|
||||
|
||||
SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, int capacity/* = DEFAULT_CAPACITY*/)
|
||||
SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, ssize_t capacity/* = DEFAULT_CAPACITY*/)
|
||||
{
|
||||
SpriteBatchNode *batchNode = new SpriteBatchNode();
|
||||
batchNode->initWithFile(fileImage, capacity);
|
||||
|
@ -76,7 +76,7 @@ SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, int capacity/* =
|
|||
/*
|
||||
* init with Texture2D
|
||||
*/
|
||||
bool SpriteBatchNode::initWithTexture(Texture2D *tex, int capacity)
|
||||
bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity)
|
||||
{
|
||||
CCASSERT(capacity>=0, "Capacity must be >= 0");
|
||||
|
||||
|
@ -110,7 +110,7 @@ bool SpriteBatchNode::init()
|
|||
/*
|
||||
* init with FileImage
|
||||
*/
|
||||
bool SpriteBatchNode::initWithFile(const char* fileImage, int capacity)
|
||||
bool SpriteBatchNode::initWithFile(const char* fileImage, ssize_t capacity)
|
||||
{
|
||||
Texture2D *texture2D = Director::getInstance()->getTextureCache()->addImage(fileImage);
|
||||
return initWithTexture(texture2D, capacity);
|
||||
|
@ -215,7 +215,7 @@ void SpriteBatchNode::removeChild(Node *child, bool cleanup)
|
|||
Node::removeChild(sprite, cleanup);
|
||||
}
|
||||
|
||||
void SpriteBatchNode::removeChildAtIndex(int index, bool doCleanup)
|
||||
void SpriteBatchNode::removeChildAtIndex(ssize_t index, bool doCleanup)
|
||||
{
|
||||
CCASSERT(index>=0 && index < _children.size(), "Invalid index");
|
||||
removeChild(_children.at(index), doCleanup);
|
||||
|
@ -274,7 +274,7 @@ void SpriteBatchNode::sortAllChildren()
|
|||
child->sortAllChildren();
|
||||
});
|
||||
|
||||
int index=0;
|
||||
ssize_t index=0;
|
||||
|
||||
//fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
|
||||
// and at the same time reorder descendants and the quads to the right index
|
||||
|
@ -288,12 +288,12 @@ void SpriteBatchNode::sortAllChildren()
|
|||
}
|
||||
}
|
||||
|
||||
void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
||||
void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, ssize_t* curIndex)
|
||||
{
|
||||
auto& array = sprite->getChildren();
|
||||
auto count = array.size();
|
||||
|
||||
int oldIndex = 0;
|
||||
ssize_t oldIndex = 0;
|
||||
|
||||
if( count == 0 )
|
||||
{
|
||||
|
@ -354,7 +354,7 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
|
|||
}
|
||||
}
|
||||
|
||||
void SpriteBatchNode::swap(int oldIndex, int newIndex)
|
||||
void SpriteBatchNode::swap(ssize_t oldIndex, ssize_t newIndex)
|
||||
{
|
||||
CCASSERT(oldIndex>=0 && oldIndex < (int)_descendants.size() && newIndex >=0 && newIndex < (int)_descendants.size(), "Invalid index");
|
||||
|
||||
|
@ -406,9 +406,9 @@ void SpriteBatchNode::increaseAtlasCapacity(void)
|
|||
// if we're going beyond the current TextureAtlas's capacity,
|
||||
// all the previously initialized sprites will need to redo their texture coords
|
||||
// this is likely computationally expensive
|
||||
int quantity = (_textureAtlas->getCapacity() + 1) * 4 / 3;
|
||||
ssize_t quantity = (_textureAtlas->getCapacity() + 1) * 4 / 3;
|
||||
|
||||
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%d] to [%d].",
|
||||
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%zd] to [%zd].",
|
||||
_textureAtlas->getCapacity(),
|
||||
quantity);
|
||||
|
||||
|
@ -420,7 +420,7 @@ void SpriteBatchNode::increaseAtlasCapacity(void)
|
|||
}
|
||||
}
|
||||
|
||||
int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int index)
|
||||
ssize_t SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, ssize_t index)
|
||||
{
|
||||
CCASSERT(index>=0 && index < _children.size(), "Invalid index");
|
||||
|
||||
|
@ -452,7 +452,7 @@ int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int index)
|
|||
return index;
|
||||
}
|
||||
|
||||
int SpriteBatchNode::highestAtlasIndexInChild(Sprite *sprite)
|
||||
ssize_t SpriteBatchNode::highestAtlasIndexInChild(Sprite *sprite)
|
||||
{
|
||||
auto& children = sprite->getChildren();
|
||||
|
||||
|
@ -466,7 +466,7 @@ int SpriteBatchNode::highestAtlasIndexInChild(Sprite *sprite)
|
|||
}
|
||||
}
|
||||
|
||||
int SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
|
||||
ssize_t SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
|
||||
{
|
||||
auto& children = sprite->getChildren();
|
||||
|
||||
|
@ -480,7 +480,7 @@ int SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
|
|||
}
|
||||
}
|
||||
|
||||
int SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
|
||||
ssize_t SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
|
||||
{
|
||||
auto& siblings = sprite->getParent()->getChildren();
|
||||
auto childIndex = siblings.getIndex(sprite);
|
||||
|
@ -627,7 +627,7 @@ void SpriteBatchNode::setTexture(Texture2D *texture)
|
|||
// SpriteSheet Extension
|
||||
//implementation SpriteSheet (TMXTiledMapExtension)
|
||||
|
||||
void SpriteBatchNode::insertQuadFromSprite(Sprite *sprite, int index)
|
||||
void SpriteBatchNode::insertQuadFromSprite(Sprite *sprite, ssize_t index)
|
||||
{
|
||||
CCASSERT( sprite != NULL, "Argument must be non-NULL");
|
||||
CCASSERT( dynamic_cast<Sprite*>(sprite), "CCSpriteBatchNode only supports Sprites as children");
|
||||
|
@ -652,7 +652,7 @@ void SpriteBatchNode::insertQuadFromSprite(Sprite *sprite, int index)
|
|||
sprite->updateTransform();
|
||||
}
|
||||
|
||||
void SpriteBatchNode::updateQuadFromSprite(Sprite *sprite, int index)
|
||||
void SpriteBatchNode::updateQuadFromSprite(Sprite *sprite, ssize_t index)
|
||||
{
|
||||
CCASSERT(sprite != NULL, "Argument must be non-nil");
|
||||
CCASSERT(dynamic_cast<Sprite*>(sprite) != NULL, "CCSpriteBatchNode only supports Sprites as children");
|
||||
|
|
|
@ -68,13 +68,13 @@ public:
|
|||
/** creates a SpriteBatchNode with a texture2d and capacity of children.
|
||||
The capacity will be increased in 33% in runtime if it run out of space.
|
||||
*/
|
||||
static SpriteBatchNode* createWithTexture(Texture2D* tex, int capacity = DEFAULT_CAPACITY);
|
||||
static SpriteBatchNode* createWithTexture(Texture2D* tex, ssize_t capacity = DEFAULT_CAPACITY);
|
||||
|
||||
/** creates a SpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and capacity of children.
|
||||
The capacity will be increased in 33% in runtime if it run out of space.
|
||||
The file will be loaded using the TextureMgr.
|
||||
*/
|
||||
static SpriteBatchNode* create(const char* fileImage, int capacity = DEFAULT_CAPACITY);
|
||||
static SpriteBatchNode* create(const char* fileImage, ssize_t capacity = DEFAULT_CAPACITY);
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
|
@ -88,14 +88,14 @@ public:
|
|||
/** initializes a SpriteBatchNode with a texture2d and capacity of children.
|
||||
The capacity will be increased in 33% in runtime if it run out of space.
|
||||
*/
|
||||
bool initWithTexture(Texture2D *tex, int capacity);
|
||||
bool initWithTexture(Texture2D *tex, ssize_t capacity);
|
||||
/** initializes a SpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
|
||||
The capacity will be increased in 33% in runtime if it run out of space.
|
||||
The file will be loaded using the TextureMgr.
|
||||
* @js init
|
||||
* @lua init
|
||||
*/
|
||||
bool initWithFile(const char* fileImage, int capacity);
|
||||
bool initWithFile(const char* fileImage, ssize_t capacity);
|
||||
bool init();
|
||||
|
||||
/** returns the TextureAtlas object */
|
||||
|
@ -121,15 +121,15 @@ public:
|
|||
/** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
|
||||
@warning Removing a child from a SpriteBatchNode is very slow
|
||||
*/
|
||||
void removeChildAtIndex(int index, bool doCleanup);
|
||||
void removeChildAtIndex(ssize_t index, bool doCleanup);
|
||||
|
||||
void appendChild(Sprite* sprite);
|
||||
void removeSpriteFromAtlas(Sprite *sprite);
|
||||
|
||||
int rebuildIndexInOrder(Sprite *parent, int index);
|
||||
int highestAtlasIndexInChild(Sprite *sprite);
|
||||
int lowestAtlasIndexInChild(Sprite *sprite);
|
||||
int atlasIndexForChild(Sprite *sprite, int z);
|
||||
ssize_t rebuildIndexInOrder(Sprite *parent, ssize_t index);
|
||||
ssize_t highestAtlasIndexInChild(Sprite *sprite);
|
||||
ssize_t lowestAtlasIndexInChild(Sprite *sprite);
|
||||
ssize_t atlasIndexForChild(Sprite *sprite, int z);
|
||||
/* Sprites use this to start sortChildren, don't call this manually */
|
||||
void reorderBatch(bool reorder);
|
||||
|
||||
|
@ -137,7 +137,7 @@ public:
|
|||
// Overrides
|
||||
//
|
||||
// TextureProtocol
|
||||
virtual Texture2D* getTexture(void) const override;
|
||||
virtual Texture2D* getTexture() const override;
|
||||
virtual void setTexture(Texture2D *texture) override;
|
||||
/**
|
||||
*@code
|
||||
|
@ -151,9 +151,9 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual const BlendFunc& getBlendFunc(void) const override;
|
||||
virtual const BlendFunc& getBlendFunc() const override;
|
||||
|
||||
virtual void visit(void) 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);}
|
||||
virtual void addChild(Node * child, int zOrder, int tag) override;
|
||||
|
@ -170,19 +170,19 @@ protected:
|
|||
This method should be called only when you are dealing with very big AtlasSrite and when most of the Sprite won't be updated.
|
||||
For example: a tile map (TMXMap) or a label with lots of characters (LabelBMFont)
|
||||
*/
|
||||
void insertQuadFromSprite(Sprite *sprite, int index);
|
||||
void insertQuadFromSprite(Sprite *sprite, ssize_t index);
|
||||
/** Updates a quad at a certain index into the texture atlas. The Sprite won't be added into the children array.
|
||||
This method should be called only when you are dealing with very big AtlasSrite and when most of the Sprite won't be updated.
|
||||
For example: a tile map (TMXMap) or a label with lots of characters (LabelBMFont)
|
||||
*/
|
||||
void updateQuadFromSprite(Sprite *sprite, int index);
|
||||
void updateQuadFromSprite(Sprite *sprite, ssize_t index);
|
||||
/* This is the opposite of "addQuadFromSprite.
|
||||
It add the sprite to the children and descendants array, but it doesn't update add it to the texture atlas
|
||||
*/
|
||||
SpriteBatchNode * addSpriteWithoutQuad(Sprite *child, int z, int aTag);
|
||||
|
||||
void updateAtlasIndex(Sprite* sprite, int* curIndex);
|
||||
void swap(int oldIndex, int newIndex);
|
||||
void updateAtlasIndex(Sprite* sprite, ssize_t* curIndex);
|
||||
void swap(ssize_t oldIndex, ssize_t newIndex);
|
||||
void updateBlendFunc();
|
||||
|
||||
TextureAtlas *_textureAtlas;
|
||||
|
|
|
@ -340,8 +340,8 @@ Sprite * TMXLayer::getTileAt(const Point& pos)
|
|||
tile->setAnchorPoint(Point::ZERO);
|
||||
tile->setOpacity(_opacity);
|
||||
|
||||
unsigned int indexForZ = atlasIndexForExistantZ(z);
|
||||
this->addSpriteWithoutQuad(tile, indexForZ, z);
|
||||
ssize_t indexForZ = atlasIndexForExistantZ(z);
|
||||
this->addSpriteWithoutQuad(tile, static_cast<int>(indexForZ), z);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,7 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
|||
setupTileSprite(tile, pos, gid);
|
||||
|
||||
// get atlas index
|
||||
unsigned int indexForZ = atlasIndexForNewZ(static_cast<int>(z));
|
||||
ssize_t indexForZ = atlasIndexForNewZ(static_cast<int>(z));
|
||||
|
||||
// Optimization: add the quad without adding a child
|
||||
this->insertQuadFromSprite(tile, indexForZ);
|
||||
|
@ -393,7 +393,7 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
|||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (child)
|
||||
{
|
||||
int ai = sp->getAtlasIndex();
|
||||
ssize_t ai = sp->getAtlasIndex();
|
||||
if ( ai >= indexForZ )
|
||||
{
|
||||
sp->setAtlasIndex(ai+1);
|
||||
|
@ -416,7 +416,7 @@ Sprite * TMXLayer::updateTileForGID(unsigned int gid, const Point& pos)
|
|||
setupTileSprite(tile ,pos ,gid);
|
||||
|
||||
// get atlas index
|
||||
unsigned int indexForZ = atlasIndexForExistantZ(z);
|
||||
ssize_t indexForZ = atlasIndexForExistantZ(z);
|
||||
tile->setAtlasIndex(indexForZ);
|
||||
tile->setDirty(true);
|
||||
tile->updateTransform();
|
||||
|
@ -441,7 +441,7 @@ Sprite * TMXLayer::appendTileForGID(unsigned int gid, const Point& pos)
|
|||
// optimization:
|
||||
// The difference between appendTileForGID and insertTileforGID is that append is faster, since
|
||||
// it appends the tile at the end of the texture atlas
|
||||
unsigned int indexForZ = _atlasIndexArray->num;
|
||||
ssize_t indexForZ = _atlasIndexArray->num;
|
||||
|
||||
// don't add it using the "standard" way.
|
||||
insertQuadFromSprite(tile, indexForZ);
|
||||
|
@ -458,24 +458,24 @@ static inline int compareInts(const void * a, const void * b)
|
|||
return ((*(int*)a) - (*(int*)b));
|
||||
}
|
||||
|
||||
unsigned int TMXLayer::atlasIndexForExistantZ(unsigned int z)
|
||||
ssize_t TMXLayer::atlasIndexForExistantZ(unsigned int z)
|
||||
{
|
||||
int key=z;
|
||||
int *item = (int*)bsearch((void*)&key, (void*)&_atlasIndexArray->arr[0], _atlasIndexArray->num, sizeof(void*), compareInts);
|
||||
|
||||
CCASSERT(item, "TMX atlas index not found. Shall not happen");
|
||||
|
||||
int index = ((size_t)item - (size_t)_atlasIndexArray->arr) / sizeof(void*);
|
||||
ssize_t index = ((size_t)item - (size_t)_atlasIndexArray->arr) / sizeof(void*);
|
||||
return index;
|
||||
}
|
||||
|
||||
unsigned int TMXLayer::atlasIndexForNewZ(int z)
|
||||
ssize_t TMXLayer::atlasIndexForNewZ(int z)
|
||||
{
|
||||
// XXX: This can be improved with a sort of binary search
|
||||
int i=0;
|
||||
ssize_t i=0;
|
||||
for (i=0; i< _atlasIndexArray->num ; i++)
|
||||
{
|
||||
int val = (size_t) _atlasIndexArray->arr[i];
|
||||
ssize_t val = (size_t) _atlasIndexArray->arr[i];
|
||||
if (z < val)
|
||||
{
|
||||
break;
|
||||
|
@ -558,8 +558,8 @@ void TMXLayer::removeChild(Node* node, bool cleanup)
|
|||
|
||||
CCASSERT(_children.contains(sprite), "Tile does not belong to TMXLayer");
|
||||
|
||||
unsigned int atlasIndex = sprite->getAtlasIndex();
|
||||
unsigned int zz = (size_t)_atlasIndexArray->arr[atlasIndex];
|
||||
ssize_t atlasIndex = sprite->getAtlasIndex();
|
||||
ssize_t zz = (ssize_t)_atlasIndexArray->arr[atlasIndex];
|
||||
_tiles[zz] = 0;
|
||||
ccCArrayRemoveValueAtIndex(_atlasIndexArray, atlasIndex);
|
||||
SpriteBatchNode::removeChild(sprite, cleanup);
|
||||
|
@ -575,7 +575,7 @@ void TMXLayer::removeTileAt(const Point& pos)
|
|||
if (gid)
|
||||
{
|
||||
unsigned int z = (unsigned int)(pos.x + pos.y * _layerSize.width);
|
||||
unsigned int atlasIndex = atlasIndexForExistantZ(z);
|
||||
ssize_t atlasIndex = atlasIndexForExistantZ(z);
|
||||
|
||||
// remove tile from GID map
|
||||
_tiles[z] = 0;
|
||||
|
@ -598,7 +598,7 @@ void TMXLayer::removeTileAt(const Point& pos)
|
|||
Sprite* child = static_cast<Sprite*>(obj);
|
||||
if (child)
|
||||
{
|
||||
unsigned int ai = child->getAtlasIndex();
|
||||
ssize_t ai = child->getAtlasIndex();
|
||||
if ( ai >= atlasIndex )
|
||||
{
|
||||
child->setAtlasIndex(ai-1);
|
||||
|
@ -706,7 +706,7 @@ int TMXLayer::getVertexZForPos(const Point& pos)
|
|||
|
||||
std::string TMXLayer::getDescription() const
|
||||
{
|
||||
return StringUtils::format("<TMXLayer | tag = %d, size = %d,%d>", (int)_tag,_mapTileSize.width, (int)_mapTileSize.height);
|
||||
return StringUtils::format("<TMXLayer | tag = %d, size = %d,%d>", _tag, (int)_mapTileSize.width, (int)_mapTileSize.height);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -209,8 +209,8 @@ private:
|
|||
int getVertexZForPos(const Point& pos);
|
||||
|
||||
// index
|
||||
unsigned int atlasIndexForExistantZ(unsigned int z);
|
||||
unsigned int atlasIndexForNewZ(int z);
|
||||
ssize_t atlasIndexForExistantZ(unsigned int z);
|
||||
ssize_t atlasIndexForNewZ(int z);
|
||||
|
||||
protected:
|
||||
//! name of the layer
|
||||
|
|
|
@ -246,7 +246,7 @@ Value TMXTiledMap::getPropertiesForGID(int GID) const
|
|||
|
||||
std::string TMXTiledMap::getDescription() const
|
||||
{
|
||||
return StringUtils::format("<TMXTiledMap | Tag = %d, Layers = %d", _tag, _children.size());
|
||||
return StringUtils::format("<TMXTiledMap | Tag = %d, Layers = %zd", _tag, _children.size());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -74,12 +74,12 @@ TextureAtlas::~TextureAtlas()
|
|||
#endif
|
||||
}
|
||||
|
||||
int TextureAtlas::getTotalQuads() const
|
||||
ssize_t TextureAtlas::getTotalQuads() const
|
||||
{
|
||||
return _totalQuads;
|
||||
}
|
||||
|
||||
int TextureAtlas::getCapacity() const
|
||||
ssize_t TextureAtlas::getCapacity() const
|
||||
{
|
||||
return _capacity;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ void TextureAtlas::setQuads(V3F_C4B_T2F_Quad* quads)
|
|||
|
||||
// TextureAtlas - alloc & init
|
||||
|
||||
TextureAtlas * TextureAtlas::create(const char* file, int capacity)
|
||||
TextureAtlas * TextureAtlas::create(const char* file, ssize_t capacity)
|
||||
{
|
||||
TextureAtlas * textureAtlas = new TextureAtlas();
|
||||
if(textureAtlas && textureAtlas->initWithFile(file, capacity))
|
||||
|
@ -122,7 +122,7 @@ TextureAtlas * TextureAtlas::create(const char* file, int capacity)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, int capacity)
|
||||
TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, ssize_t capacity)
|
||||
{
|
||||
TextureAtlas * textureAtlas = new TextureAtlas();
|
||||
if (textureAtlas && textureAtlas->initWithTexture(texture, capacity))
|
||||
|
@ -134,7 +134,7 @@ TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, int capacity)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool TextureAtlas::initWithFile(const char * file, int capacity)
|
||||
bool TextureAtlas::initWithFile(const char * file, ssize_t capacity)
|
||||
{
|
||||
// retained in property
|
||||
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file);
|
||||
|
@ -150,7 +150,7 @@ bool TextureAtlas::initWithFile(const char * file, int capacity)
|
|||
}
|
||||
}
|
||||
|
||||
bool TextureAtlas::initWithTexture(Texture2D *texture, int capacity)
|
||||
bool TextureAtlas::initWithTexture(Texture2D *texture, ssize_t capacity)
|
||||
{
|
||||
CCASSERT(capacity>=0, "Capacity must be >= 0");
|
||||
|
||||
|
@ -224,7 +224,7 @@ void TextureAtlas::listenBackToForeground(Object *obj)
|
|||
|
||||
std::string TextureAtlas::getDescription() const
|
||||
{
|
||||
return String::createWithFormat("<TextureAtlas | totalQuads = %d>", _totalQuads)->getCString();
|
||||
return String::createWithFormat("<TextureAtlas | totalQuads = %zd>", _totalQuads)->getCString();
|
||||
}
|
||||
|
||||
|
||||
|
@ -317,7 +317,7 @@ void TextureAtlas::mapBuffers()
|
|||
|
||||
// TextureAtlas - Update, Insert, Move & Remove
|
||||
|
||||
void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, int index)
|
||||
void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, ssize_t index)
|
||||
{
|
||||
CCASSERT( index >= 0 && index < _capacity, "updateQuadWithTexture: Invalid index");
|
||||
|
||||
|
@ -330,7 +330,7 @@ void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, int index)
|
|||
|
||||
}
|
||||
|
||||
void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, int index)
|
||||
void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, ssize_t index)
|
||||
{
|
||||
CCASSERT( index>=0 && index<_capacity, "insertQuadWithTexture: Invalid index");
|
||||
|
||||
|
@ -354,7 +354,7 @@ void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, int index)
|
|||
|
||||
}
|
||||
|
||||
void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount)
|
||||
void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, ssize_t index, ssize_t amount)
|
||||
{
|
||||
CCASSERT(index>=0 && amount>=0 && index+amount<=_capacity, "insertQuadWithTexture: Invalid index + amount");
|
||||
|
||||
|
@ -375,7 +375,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount)
|
|||
|
||||
auto max = index + amount;
|
||||
int j = 0;
|
||||
for (int i = index; i < max ; i++)
|
||||
for (ssize_t i = index; i < max ; i++)
|
||||
{
|
||||
_quads[index] = quads[j];
|
||||
index++;
|
||||
|
@ -385,7 +385,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount)
|
|||
_dirty = true;
|
||||
}
|
||||
|
||||
void TextureAtlas::insertQuadFromIndex(int oldIndex, int newIndex)
|
||||
void TextureAtlas::insertQuadFromIndex(ssize_t oldIndex, ssize_t newIndex)
|
||||
{
|
||||
CCASSERT( newIndex >= 0 && newIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
||||
CCASSERT( oldIndex >= 0 && oldIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
||||
|
@ -414,7 +414,7 @@ void TextureAtlas::insertQuadFromIndex(int oldIndex, int newIndex)
|
|||
_dirty = true;
|
||||
}
|
||||
|
||||
void TextureAtlas::removeQuadAtIndex(int index)
|
||||
void TextureAtlas::removeQuadAtIndex(ssize_t index)
|
||||
{
|
||||
CCASSERT( index>=0 && index<_totalQuads, "removeQuadAtIndex: Invalid index");
|
||||
|
||||
|
@ -433,7 +433,7 @@ void TextureAtlas::removeQuadAtIndex(int index)
|
|||
_dirty = true;
|
||||
}
|
||||
|
||||
void TextureAtlas::removeQuadsAtIndex(int index, int amount)
|
||||
void TextureAtlas::removeQuadsAtIndex(ssize_t index, ssize_t amount)
|
||||
{
|
||||
CCASSERT(index>=0 && amount>=0 && index+amount<=_totalQuads, "removeQuadAtIndex: index + amount out of bounds");
|
||||
|
||||
|
@ -455,7 +455,7 @@ void TextureAtlas::removeAllQuads()
|
|||
}
|
||||
|
||||
// TextureAtlas - Resize
|
||||
bool TextureAtlas::resizeCapacity(int newCapacity)
|
||||
bool TextureAtlas::resizeCapacity(ssize_t newCapacity)
|
||||
{
|
||||
CCASSERT(newCapacity>=0, "capacity >= 0");
|
||||
if( newCapacity == _capacity )
|
||||
|
@ -529,13 +529,13 @@ bool TextureAtlas::resizeCapacity(int newCapacity)
|
|||
return true;
|
||||
}
|
||||
|
||||
void TextureAtlas::increaseTotalQuadsWith(int amount)
|
||||
void TextureAtlas::increaseTotalQuadsWith(ssize_t amount)
|
||||
{
|
||||
CCASSERT(amount>=0, "amount >= 0");
|
||||
_totalQuads += amount;
|
||||
}
|
||||
|
||||
void TextureAtlas::moveQuadsFromIndex(int oldIndex, int amount, int newIndex)
|
||||
void TextureAtlas::moveQuadsFromIndex(ssize_t oldIndex, ssize_t amount, ssize_t newIndex)
|
||||
{
|
||||
CCASSERT(oldIndex>=0 && amount>=0 && newIndex>=0, "values must be >= 0");
|
||||
CCASSERT(newIndex + amount <= _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
||||
|
@ -567,7 +567,7 @@ void TextureAtlas::moveQuadsFromIndex(int oldIndex, int amount, int newIndex)
|
|||
_dirty = true;
|
||||
}
|
||||
|
||||
void TextureAtlas::moveQuadsFromIndex(int index, int newIndex)
|
||||
void TextureAtlas::moveQuadsFromIndex(ssize_t index, ssize_t newIndex)
|
||||
{
|
||||
CCASSERT(index>=0 && newIndex>=0, "values must be >= 0");
|
||||
CCASSERT(newIndex + (_totalQuads - index) <= _capacity, "moveQuadsFromIndex move is out of bounds");
|
||||
|
@ -575,14 +575,14 @@ void TextureAtlas::moveQuadsFromIndex(int index, int newIndex)
|
|||
memmove(_quads + newIndex,_quads + index, (_totalQuads - index) * sizeof(_quads[0]));
|
||||
}
|
||||
|
||||
void TextureAtlas::fillWithEmptyQuadsFromIndex(int index, int amount)
|
||||
void TextureAtlas::fillWithEmptyQuadsFromIndex(ssize_t index, ssize_t amount)
|
||||
{
|
||||
CCASSERT(index>=0 && amount>=0, "values must be >= 0");
|
||||
V3F_C4B_T2F_Quad quad;
|
||||
memset(&quad, 0, sizeof(quad));
|
||||
|
||||
auto to = index + amount;
|
||||
for (int i = index ; i < to ; i++)
|
||||
for (ssize_t i = index ; i < to ; i++)
|
||||
{
|
||||
_quads[i] = quad;
|
||||
}
|
||||
|
@ -595,13 +595,13 @@ void TextureAtlas::drawQuads()
|
|||
this->drawNumberOfQuads(_totalQuads, 0);
|
||||
}
|
||||
|
||||
void TextureAtlas::drawNumberOfQuads(int numberOfQuads)
|
||||
void TextureAtlas::drawNumberOfQuads(ssize_t numberOfQuads)
|
||||
{
|
||||
CCASSERT(numberOfQuads>=0, "numberOfQuads must be >= 0");
|
||||
this->drawNumberOfQuads(numberOfQuads, 0);
|
||||
}
|
||||
|
||||
void TextureAtlas::drawNumberOfQuads(int numberOfQuads, int start)
|
||||
void TextureAtlas::drawNumberOfQuads(ssize_t numberOfQuads, ssize_t start)
|
||||
{
|
||||
CCASSERT(numberOfQuads>=0 && start>=0, "numberOfQuads and start must be >= 0");
|
||||
|
||||
|
|
|
@ -59,13 +59,13 @@ public:
|
|||
/** creates a TextureAtlas with an filename and with an initial capacity for Quads.
|
||||
* The TextureAtlas capacity can be increased in runtime.
|
||||
*/
|
||||
static TextureAtlas* create(const char* file , int capacity);
|
||||
static TextureAtlas* create(const char* file , ssize_t capacity);
|
||||
|
||||
/** creates a TextureAtlas with a previously initialized Texture2D object, and
|
||||
* with an initial capacity for n Quads.
|
||||
* The TextureAtlas capacity can be increased in runtime.
|
||||
*/
|
||||
static TextureAtlas* createWithTexture(Texture2D *texture, int capacity);
|
||||
static TextureAtlas* createWithTexture(Texture2D *texture, ssize_t capacity);
|
||||
/**
|
||||
* @js ctor
|
||||
*/
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
*
|
||||
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
||||
*/
|
||||
bool initWithFile(const char* file, int capacity);
|
||||
bool initWithFile(const char* file, ssize_t capacity);
|
||||
|
||||
/** initializes a TextureAtlas with a previously initialized Texture2D object, and
|
||||
* with an initial capacity for Quads.
|
||||
|
@ -89,43 +89,43 @@ public:
|
|||
*
|
||||
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
||||
*/
|
||||
bool initWithTexture(Texture2D *texture, int capacity);
|
||||
bool initWithTexture(Texture2D *texture, ssize_t capacity);
|
||||
|
||||
/** updates a Quad (texture, vertex and color) at a certain index
|
||||
* index must be between 0 and the atlas capacity - 1
|
||||
@since v0.8
|
||||
*/
|
||||
void updateQuad(V3F_C4B_T2F_Quad* quad, int index);
|
||||
void updateQuad(V3F_C4B_T2F_Quad* quad, ssize_t index);
|
||||
|
||||
/** Inserts a Quad (texture, vertex and color) at a certain index
|
||||
index must be between 0 and the atlas capacity - 1
|
||||
@since v0.8
|
||||
*/
|
||||
void insertQuad(V3F_C4B_T2F_Quad* quad, int index);
|
||||
void insertQuad(V3F_C4B_T2F_Quad* quad, ssize_t index);
|
||||
|
||||
/** Inserts a c array of quads at a given index
|
||||
index must be between 0 and the atlas capacity - 1
|
||||
this method doesn't enlarge the array when amount + index > totalQuads
|
||||
@since v1.1
|
||||
*/
|
||||
void insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount);
|
||||
void insertQuads(V3F_C4B_T2F_Quad* quads, ssize_t index, ssize_t amount);
|
||||
|
||||
/** Removes the quad that is located at a certain index and inserts it at a new index
|
||||
This operation is faster than removing and inserting in a quad in 2 different steps
|
||||
@since v0.7.2
|
||||
*/
|
||||
void insertQuadFromIndex(int fromIndex, int newIndex);
|
||||
void insertQuadFromIndex(ssize_t fromIndex, ssize_t newIndex);
|
||||
|
||||
/** removes a quad at a given index number.
|
||||
The capacity remains the same, but the total number of quads to be drawn is reduced in 1
|
||||
@since v0.7.2
|
||||
*/
|
||||
void removeQuadAtIndex(int index);
|
||||
void removeQuadAtIndex(ssize_t index);
|
||||
|
||||
/** removes a amount of quads starting from index
|
||||
@since 1.1
|
||||
*/
|
||||
void removeQuadsAtIndex(int index, int amount);
|
||||
void removeQuadsAtIndex(ssize_t index, ssize_t amount);
|
||||
/** removes all Quads.
|
||||
The TextureAtlas capacity remains untouched. No memory is freed.
|
||||
The total number of quads to be drawn will be 0
|
||||
|
@ -138,19 +138,19 @@ public:
|
|||
* It returns true if the resize was successful.
|
||||
* If it fails to resize the capacity it will return false with a new capacity of 0.
|
||||
*/
|
||||
bool resizeCapacity(int capacity);
|
||||
bool resizeCapacity(ssize_t capacity);
|
||||
|
||||
/**
|
||||
Used internally by ParticleBatchNode
|
||||
don't use this unless you know what you're doing
|
||||
@since 1.1
|
||||
*/
|
||||
void increaseTotalQuadsWith(int amount);
|
||||
void increaseTotalQuadsWith(ssize_t amount);
|
||||
|
||||
/** Moves an amount of quads from oldIndex at newIndex
|
||||
@since v1.1
|
||||
*/
|
||||
void moveQuadsFromIndex(int oldIndex, int amount, int newIndex);
|
||||
void moveQuadsFromIndex(ssize_t oldIndex, ssize_t amount, ssize_t newIndex);
|
||||
|
||||
/**
|
||||
Moves quads from index till totalQuads to the newIndex
|
||||
|
@ -158,26 +158,26 @@ public:
|
|||
This method doesn't enlarge the array if newIndex + quads to be moved > capacity
|
||||
@since 1.1
|
||||
*/
|
||||
void moveQuadsFromIndex(int index, int newIndex);
|
||||
void moveQuadsFromIndex(ssize_t index, ssize_t newIndex);
|
||||
|
||||
/**
|
||||
Ensures that after a realloc quads are still empty
|
||||
Used internally by ParticleBatchNode
|
||||
@since 1.1
|
||||
*/
|
||||
void fillWithEmptyQuadsFromIndex(int index, int amount);
|
||||
void fillWithEmptyQuadsFromIndex(ssize_t index, ssize_t amount);
|
||||
|
||||
/** draws n quads
|
||||
* n can't be greater than the capacity of the Atlas
|
||||
*/
|
||||
void drawNumberOfQuads(int n);
|
||||
void drawNumberOfQuads(ssize_t n);
|
||||
|
||||
/** draws n quads from an index (offset).
|
||||
n + start can't be greater than the capacity of the atlas
|
||||
|
||||
@since v1.0
|
||||
*/
|
||||
void drawNumberOfQuads(int numberOfQuads, int start);
|
||||
void drawNumberOfQuads(ssize_t numberOfQuads, ssize_t start);
|
||||
|
||||
/** draws all the Atlas's Quads
|
||||
*/
|
||||
|
@ -197,10 +197,10 @@ public:
|
|||
virtual std::string getDescription() const;
|
||||
|
||||
/** Gets the quantity of quads that are going to be drawn */
|
||||
int getTotalQuads() const;
|
||||
ssize_t getTotalQuads() const;
|
||||
|
||||
/** Gets the quantity of quads that can be stored with the current texture atlas size */
|
||||
int getCapacity() const;
|
||||
ssize_t getCapacity() const;
|
||||
|
||||
/** Gets the texture of the texture atlas */
|
||||
Texture2D* getTexture() const;
|
||||
|
@ -215,6 +215,8 @@ public:
|
|||
void setQuads(V3F_C4B_T2F_Quad* quads);
|
||||
|
||||
private:
|
||||
void renderCommand();
|
||||
|
||||
void setupIndices();
|
||||
void mapBuffers();
|
||||
void setupVBOandVAO();
|
||||
|
@ -226,9 +228,9 @@ protected:
|
|||
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
||||
bool _dirty; //indicates whether or not the array buffer of the VBO needs to be updated
|
||||
/** quantity of quads that are going to be drawn */
|
||||
int _totalQuads;
|
||||
ssize_t _totalQuads;
|
||||
/** quantity of quads that can be stored with the current texture atlas size */
|
||||
int _capacity;
|
||||
ssize_t _capacity;
|
||||
/** Texture of the texture atlas */
|
||||
Texture2D* _texture;
|
||||
/** Quads that are going to be rendered */
|
||||
|
|
|
@ -222,7 +222,7 @@ void TileMapAtlas::updateAtlasValueAt(const Point& pos, const Color3B& value, in
|
|||
quad->bl.colors = color;
|
||||
|
||||
_textureAtlas->setDirty(true);
|
||||
int totalQuads = _textureAtlas->getTotalQuads();
|
||||
ssize_t totalQuads = _textureAtlas->getTotalQuads();
|
||||
if (index + 1 > totalQuads) {
|
||||
_textureAtlas->increaseTotalQuadsWith(index + 1 - totalQuads);
|
||||
}
|
||||
|
|
|
@ -77,8 +77,7 @@ void TransitionProgress::onEnter()
|
|||
texture->setAnchorPoint(Point(0.5f,0.5f));
|
||||
|
||||
// render outScene to its texturebuffer
|
||||
texture->clear(0, 0, 0, 1);
|
||||
texture->begin();
|
||||
texture->beginWithClear(0, 0, 0, 1);
|
||||
_sceneToBeModified->visit();
|
||||
texture->end();
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
const int CC_INVALID_INDEX = -1;
|
||||
const ssize_t CC_INVALID_INDEX = -1;
|
||||
|
||||
/** Allocates and initializes a new array with specified capacity */
|
||||
ccArray* ccArrayNew(int capacity)
|
||||
ccArray* ccArrayNew(ssize_t capacity)
|
||||
{
|
||||
if (capacity == 0)
|
||||
capacity = 7;
|
||||
|
@ -68,11 +68,11 @@ void ccArrayDoubleCapacity(ccArray *arr)
|
|||
arr->arr = newArr;
|
||||
}
|
||||
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, int extra)
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, ssize_t extra)
|
||||
{
|
||||
while (arr->max < arr->num + extra)
|
||||
{
|
||||
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].",
|
||||
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%zd] to [%zd].",
|
||||
arr->max,
|
||||
arr->max*2);
|
||||
|
||||
|
@ -82,7 +82,7 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, int extra)
|
|||
|
||||
void ccArrayShrink(ccArray *arr)
|
||||
{
|
||||
int newSize = 0;
|
||||
ssize_t newSize = 0;
|
||||
|
||||
//only resize when necessary
|
||||
if (arr->max > arr->num && !(arr->num==0 && arr->max==1))
|
||||
|
@ -104,11 +104,11 @@ void ccArrayShrink(ccArray *arr)
|
|||
}
|
||||
|
||||
/** Returns index of first occurrence of object, CC_INVALID_INDEX if object not found. */
|
||||
int ccArrayGetIndexOfObject(ccArray *arr, Object* object)
|
||||
ssize_t ccArrayGetIndexOfObject(ccArray *arr, Object* object)
|
||||
{
|
||||
const auto arrNum = arr->num;
|
||||
Object** ptr = arr->arr;
|
||||
for (int i = 0; i < arrNum; ++i, ++ptr)
|
||||
for (ssize_t i = 0; i < arrNum; ++i, ++ptr)
|
||||
{
|
||||
if (*ptr == object)
|
||||
return i;
|
||||
|
@ -143,7 +143,7 @@ void ccArrayAppendObjectWithResize(ccArray *arr, Object* object)
|
|||
enough capacity. */
|
||||
void ccArrayAppendArray(ccArray *arr, ccArray *plusArr)
|
||||
{
|
||||
for (int i = 0; i < plusArr->num; i++)
|
||||
for (ssize_t i = 0; i < plusArr->num; i++)
|
||||
{
|
||||
ccArrayAppendObject(arr, plusArr->arr[i]);
|
||||
}
|
||||
|
@ -157,14 +157,14 @@ void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr)
|
|||
}
|
||||
|
||||
/** Inserts an object at index */
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, int index)
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, ssize_t index)
|
||||
{
|
||||
CCASSERT(index<=arr->num, "Invalid index. Out of bounds");
|
||||
CCASSERT(object != NULL, "Invalid parameter!");
|
||||
|
||||
ccArrayEnsureExtraCapacity(arr, 1);
|
||||
|
||||
int remaining = arr->num - index;
|
||||
ssize_t remaining = arr->num - index;
|
||||
if (remaining > 0)
|
||||
{
|
||||
memmove((void *)&arr->arr[index+1], (void *)&arr->arr[index], sizeof(Object*) * remaining );
|
||||
|
@ -176,7 +176,7 @@ void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, int index)
|
|||
}
|
||||
|
||||
/** Swaps two objects */
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, int index1, int index2)
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, ssize_t index1, ssize_t index2)
|
||||
{
|
||||
CCASSERT(index1>=0 && index1 < arr->num, "(1) Invalid index. Out of bounds");
|
||||
CCASSERT(index2>=0 && index2 < arr->num, "(2) Invalid index. Out of bounds");
|
||||
|
@ -198,7 +198,7 @@ void ccArrayRemoveAllObjects(ccArray *arr)
|
|||
|
||||
/** Removes object at specified index and pushes back all subsequent objects.
|
||||
Behavior undefined if index outside [0, num-1]. */
|
||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj/* = true*/)
|
||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, ssize_t index, bool bReleaseObj/* = true*/)
|
||||
{
|
||||
CCASSERT(arr && arr->num > 0 && index>=0 && index < arr->num, "Invalid index. Out of bounds");
|
||||
if (bReleaseObj)
|
||||
|
@ -208,7 +208,7 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj/* = tr
|
|||
|
||||
arr->num--;
|
||||
|
||||
int remaining = arr->num - index;
|
||||
ssize_t remaining = arr->num - index;
|
||||
if(remaining>0)
|
||||
{
|
||||
memmove((void *)&arr->arr[index], (void *)&arr->arr[index+1], remaining * sizeof(Object*));
|
||||
|
@ -218,7 +218,7 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj/* = tr
|
|||
/** Removes object at specified index and fills the gap with the last object,
|
||||
thereby avoiding the need to push back subsequent objects.
|
||||
Behavior undefined if index outside [0, num-1]. */
|
||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, int index)
|
||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, ssize_t index)
|
||||
{
|
||||
CC_SAFE_RELEASE(arr->arr[index]);
|
||||
auto last = --arr->num;
|
||||
|
@ -249,7 +249,7 @@ void ccArrayRemoveObject(ccArray *arr, Object* object, bool bReleaseObj/* = true
|
|||
first matching instance in arr will be removed. */
|
||||
void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||
{
|
||||
for (int i = 0; i < minusArr->num; i++)
|
||||
for (ssize_t i = 0; i < minusArr->num; i++)
|
||||
{
|
||||
ccArrayRemoveObject(arr, minusArr->arr[i]);
|
||||
}
|
||||
|
@ -259,9 +259,9 @@ void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
|||
matching instances in arr will be removed. */
|
||||
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||
{
|
||||
int back = 0;
|
||||
ssize_t back = 0;
|
||||
|
||||
for (int i = 0; i < arr->num; i++)
|
||||
for (ssize_t i = 0; i < arr->num; i++)
|
||||
{
|
||||
if (ccArrayContainsObject(minusArr, arr->arr[i]))
|
||||
{
|
||||
|
@ -281,7 +281,7 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
|||
// #pragma mark ccCArray for Values (c structures)
|
||||
|
||||
/** Allocates and initializes a new C array with specified capacity */
|
||||
ccCArray* ccCArrayNew(int capacity)
|
||||
ccCArray* ccCArrayNew(ssize_t capacity)
|
||||
{
|
||||
if (capacity == 0)
|
||||
{
|
||||
|
@ -316,15 +316,15 @@ void ccCArrayDoubleCapacity(ccCArray *arr)
|
|||
}
|
||||
|
||||
/** Increases array capacity such that max >= num + extra. */
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, int extra)
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, ssize_t extra)
|
||||
{
|
||||
ccArrayEnsureExtraCapacity((ccArray*)arr,extra);
|
||||
}
|
||||
|
||||
/** Returns index of first occurrence of value, CC_INVALID_INDEX if value not found. */
|
||||
int ccCArrayGetIndexOfValue(ccCArray *arr, void* value)
|
||||
ssize_t ccCArrayGetIndexOfValue(ccCArray *arr, void* value)
|
||||
{
|
||||
for(int i = 0; i < arr->num; i++)
|
||||
for(ssize_t i = 0; i < arr->num; i++)
|
||||
{
|
||||
if( arr->arr[i] == value )
|
||||
return i;
|
||||
|
@ -339,7 +339,7 @@ bool ccCArrayContainsValue(ccCArray *arr, void* value)
|
|||
}
|
||||
|
||||
/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, int index)
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, ssize_t index)
|
||||
{
|
||||
CCASSERT( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index");
|
||||
|
||||
|
@ -384,7 +384,7 @@ void ccCArrayAppendValueWithResize(ccCArray *arr, void* value)
|
|||
enough capacity. */
|
||||
void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr)
|
||||
{
|
||||
for( int i = 0; i < plusArr->num; i++)
|
||||
for( ssize_t i = 0; i < plusArr->num; i++)
|
||||
{
|
||||
ccCArrayAppendValue(arr, plusArr->arr[i]);
|
||||
}
|
||||
|
@ -407,9 +407,9 @@ void ccCArrayRemoveAllValues(ccCArray *arr)
|
|||
Behavior undefined if index outside [0, num-1].
|
||||
@since v0.99.4
|
||||
*/
|
||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, int index)
|
||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, ssize_t index)
|
||||
{
|
||||
for( int last = --arr->num; index < last; index++)
|
||||
for( ssize_t last = --arr->num; index < last; index++)
|
||||
{
|
||||
arr->arr[index] = arr->arr[index + 1];
|
||||
}
|
||||
|
@ -420,9 +420,9 @@ void ccCArrayRemoveValueAtIndex(ccCArray *arr, int index)
|
|||
Behavior undefined if index outside [0, num-1].
|
||||
@since v0.99.4
|
||||
*/
|
||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, int index)
|
||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, ssize_t index)
|
||||
{
|
||||
auto last = --arr->num;
|
||||
ssize_t last = --arr->num;
|
||||
arr->arr[index] = arr->arr[last];
|
||||
}
|
||||
|
||||
|
@ -443,7 +443,7 @@ void ccCArrayRemoveValue(ccCArray *arr, void* value)
|
|||
*/
|
||||
void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||
{
|
||||
for(int i = 0; i < minusArr->num; i++)
|
||||
for(ssize_t i = 0; i < minusArr->num; i++)
|
||||
{
|
||||
ccCArrayRemoveValue(arr, minusArr->arr[i]);
|
||||
}
|
||||
|
@ -454,9 +454,9 @@ void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
|||
*/
|
||||
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||
{
|
||||
int back = 0;
|
||||
ssize_t back = 0;
|
||||
|
||||
for(int i = 0; i < arr->num; i++)
|
||||
for(ssize_t i = 0; i < arr->num; i++)
|
||||
{
|
||||
if( ccCArrayContainsValue(minusArr, arr->arr[i]) )
|
||||
{
|
||||
|
|
|
@ -51,20 +51,20 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
extern const int CC_INVALID_INDEX;
|
||||
extern const ssize_t CC_INVALID_INDEX;
|
||||
|
||||
// Easy integration
|
||||
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
||||
__object__=__array__->arr[0]; for(int i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
|
||||
__object__=__array__->arr[0]; for(ssize_t i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
|
||||
|
||||
|
||||
typedef struct _ccArray {
|
||||
int num, max;
|
||||
ssize_t num, max;
|
||||
Object** arr;
|
||||
} ccArray;
|
||||
|
||||
/** Allocates and initializes a new array with specified capacity */
|
||||
ccArray* ccArrayNew(int capacity);
|
||||
ccArray* ccArrayNew(ssize_t capacity);
|
||||
|
||||
/** Frees array after removing all remaining objects. Silently ignores nil arr. */
|
||||
void ccArrayFree(ccArray*& arr);
|
||||
|
@ -73,13 +73,13 @@ void ccArrayFree(ccArray*& arr);
|
|||
void ccArrayDoubleCapacity(ccArray *arr);
|
||||
|
||||
/** Increases array capacity such that max >= num + extra. */
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, int extra);
|
||||
void ccArrayEnsureExtraCapacity(ccArray *arr, ssize_t extra);
|
||||
|
||||
/** shrinks the array so the memory footprint corresponds with the number of items */
|
||||
void ccArrayShrink(ccArray *arr);
|
||||
|
||||
/** Returns index of first occurrence of object, NSNotFound if object not found. */
|
||||
int ccArrayGetIndexOfObject(ccArray *arr, Object* object);
|
||||
ssize_t ccArrayGetIndexOfObject(ccArray *arr, Object* object);
|
||||
|
||||
/** Returns a Boolean value that indicates whether object is present in array. */
|
||||
bool ccArrayContainsObject(ccArray *arr, Object* object);
|
||||
|
@ -98,22 +98,22 @@ void ccArrayAppendArray(ccArray *arr, ccArray *plusArr);
|
|||
void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr);
|
||||
|
||||
/** Inserts an object at index */
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, int index);
|
||||
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, ssize_t index);
|
||||
|
||||
/** Swaps two objects */
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, int index1, int index2);
|
||||
void ccArraySwapObjectsAtIndexes(ccArray *arr, ssize_t index1, ssize_t index2);
|
||||
|
||||
/** Removes all objects from arr */
|
||||
void ccArrayRemoveAllObjects(ccArray *arr);
|
||||
|
||||
/** Removes object at specified index and pushes back all subsequent objects.
|
||||
Behavior undefined if index outside [0, num-1]. */
|
||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj = true);
|
||||
void ccArrayRemoveObjectAtIndex(ccArray *arr, ssize_t index, bool bReleaseObj = true);
|
||||
|
||||
/** Removes object at specified index and fills the gap with the last object,
|
||||
thereby avoiding the need to push back subsequent objects.
|
||||
Behavior undefined if index outside [0, num-1]. */
|
||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, int index);
|
||||
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, ssize_t index);
|
||||
|
||||
void ccArrayFastRemoveObject(ccArray *arr, Object* object);
|
||||
|
||||
|
@ -133,12 +133,12 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr);
|
|||
// #pragma mark ccCArray for Values (c structures)
|
||||
|
||||
typedef struct _ccCArray {
|
||||
int num, max;
|
||||
ssize_t num, max;
|
||||
void** arr;
|
||||
} ccCArray;
|
||||
|
||||
/** Allocates and initializes a new C array with specified capacity */
|
||||
ccCArray* ccCArrayNew(int capacity);
|
||||
ccCArray* ccCArrayNew(ssize_t capacity);
|
||||
|
||||
/** Frees C array after removing all remaining values. Silently ignores nil arr. */
|
||||
void ccCArrayFree(ccCArray *arr);
|
||||
|
@ -147,16 +147,16 @@ void ccCArrayFree(ccCArray *arr);
|
|||
void ccCArrayDoubleCapacity(ccCArray *arr);
|
||||
|
||||
/** Increases array capacity such that max >= num + extra. */
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, int extra);
|
||||
void ccCArrayEnsureExtraCapacity(ccCArray *arr, ssize_t extra);
|
||||
|
||||
/** Returns index of first occurrence of value, NSNotFound if value not found. */
|
||||
int ccCArrayGetIndexOfValue(ccCArray *arr, void* value);
|
||||
ssize_t ccCArrayGetIndexOfValue(ccCArray *arr, void* value);
|
||||
|
||||
/** Returns a Boolean value that indicates whether value is present in the C array. */
|
||||
bool ccCArrayContainsValue(ccCArray *arr, void* value);
|
||||
|
||||
/** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, int index);
|
||||
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, ssize_t index);
|
||||
|
||||
/** Appends an value. Behavior undefined if array doesn't have enough capacity. */
|
||||
void ccCArrayAppendValue(ccCArray *arr, void* value);
|
||||
|
@ -178,14 +178,14 @@ void ccCArrayRemoveAllValues(ccCArray *arr);
|
|||
Behavior undefined if index outside [0, num-1].
|
||||
@since v0.99.4
|
||||
*/
|
||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, int index);
|
||||
void ccCArrayRemoveValueAtIndex(ccCArray *arr, ssize_t index);
|
||||
|
||||
/** Removes value at specified index and fills the gap with the last value,
|
||||
thereby avoiding the need to push back subsequent values.
|
||||
Behavior undefined if index outside [0, num-1].
|
||||
@since v0.99.4
|
||||
*/
|
||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, int index);
|
||||
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, ssize_t index);
|
||||
|
||||
/** Searches for the first occurrence of value and removes it. If value is not found the function has no effect.
|
||||
@since v0.99.4
|
||||
|
|
|
@ -100,7 +100,7 @@ do { \
|
|||
CCASSERT(getShaderProgram(), "No shader program set for this node"); \
|
||||
{ \
|
||||
getShaderProgram()->use(); \
|
||||
getShaderProgram()->setUniformsForBuiltins(); \
|
||||
getShaderProgram()->setUniformsForBuiltins(_modelViewTransform); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* cocos2d for iPhone: http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2011 Ricardo Quesada
|
||||
* Copyright (c) 2012 Zynga Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
" \n\
|
||||
#ifdef GL_ES \n\
|
||||
precision lowp float; \n\
|
||||
#endif \n\
|
||||
\n\
|
||||
varying vec4 v_fragmentColor; \n\
|
||||
varying vec2 v_texCoord; \n\
|
||||
uniform sampler2D CC_Texture0; \n\
|
||||
\n\
|
||||
void main() \n\
|
||||
{ \n\
|
||||
gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord); \n\
|
||||
} \n\
|
||||
";
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* cocos2d for iPhone: http://www.cocos2d-iphone.org
|
||||
*
|
||||
* Copyright (c) 2011 Ricardo Quesada
|
||||
* Copyright (c) 2012 Zynga Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
" \n\
|
||||
attribute vec4 a_position; \n\
|
||||
attribute vec2 a_texCoord; \n\
|
||||
attribute vec4 a_color; \n\
|
||||
\n\
|
||||
#ifdef GL_ES \n\
|
||||
varying lowp vec4 v_fragmentColor; \n\
|
||||
varying mediump vec2 v_texCoord; \n\
|
||||
#else \n\
|
||||
varying vec4 v_fragmentColor; \n\
|
||||
varying vec2 v_texCoord; \n\
|
||||
#endif \n\
|
||||
\n\
|
||||
void main() \n\
|
||||
{ \n\
|
||||
gl_Position = a_position; \n\
|
||||
v_fragmentColor = a_color; \n\
|
||||
v_texCoord = a_texCoord; \n\
|
||||
} \n\
|
||||
";
|
|
@ -56,6 +56,12 @@ const GLchar * ccPositionTextureColor_frag =
|
|||
const GLchar * ccPositionTextureColor_vert =
|
||||
#include "ccShader_PositionTextureColor_vert.h"
|
||||
|
||||
//
|
||||
const GLchar * ccPositionTextureColor_noMVP_frag =
|
||||
#include "ccShader_PositionTextureColor_noMVP_frag.h"
|
||||
const GLchar * ccPositionTextureColor_noMVP_vert =
|
||||
#include "ccShader_PositionTextureColor_noMVP_vert.h"
|
||||
|
||||
//
|
||||
const GLchar * ccPositionTextureColorAlphaTest_frag =
|
||||
#include "ccShader_PositionTextureColorAlphaTest_frag.h"
|
||||
|
|
|
@ -50,6 +50,9 @@ extern CC_DLL const GLchar * ccPositionTextureA8Color_vert;
|
|||
extern CC_DLL const GLchar * ccPositionTextureColor_frag;
|
||||
extern CC_DLL const GLchar * ccPositionTextureColor_vert;
|
||||
|
||||
extern CC_DLL const GLchar * ccPositionTextureColor_noMVP_frag;
|
||||
extern CC_DLL const GLchar * ccPositionTextureColor_noMVP_vert;
|
||||
|
||||
extern CC_DLL const GLchar * ccPositionTextureColorAlphaTest_frag;
|
||||
|
||||
extern CC_DLL const GLchar * ccPositionTexture_uColor_frag;
|
||||
|
|
|
@ -317,6 +317,16 @@ struct BlendFunc
|
|||
const static BlendFunc ALPHA_NON_PREMULTIPLIED;
|
||||
//! Enables Additive blending. Uses {GL_SRC_ALPHA, GL_ONE}
|
||||
const static BlendFunc ADDITIVE;
|
||||
|
||||
bool const operator==(const BlendFunc &a)
|
||||
{
|
||||
return src == a.src && dst == a.dst;
|
||||
}
|
||||
|
||||
bool const operator<(const BlendFunc &a)
|
||||
{
|
||||
return src < a.src || (src < a.src && dst < a.dst);
|
||||
}
|
||||
};
|
||||
|
||||
// Label::VAlignment
|
||||
|
|
|
@ -35,9 +35,6 @@ THE SOFTWARE.
|
|||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
// prototype
|
||||
void swapAlphaChannel(unsigned int *pImageMemory, unsigned int numPixels);
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class BitmapDC
|
||||
|
@ -129,12 +126,6 @@ public:
|
|||
return getBitmapFromJavaShadowStroke( text, nWidth, nHeight, eAlignMask, pFontName, fontSize );
|
||||
}
|
||||
|
||||
// ARGB -> RGBA
|
||||
inline unsigned int swapAlpha(unsigned int value)
|
||||
{
|
||||
return ((value << 8 & 0xffffff00) | (value >> 24 & 0x000000ff));
|
||||
}
|
||||
|
||||
public:
|
||||
int _width;
|
||||
int _height;
|
||||
|
@ -228,9 +219,6 @@ bool Image::initWithStringShadowStroke(
|
|||
_renderFormat = Texture2D::PixelFormat::RGBA8888;
|
||||
_dataLen = _width * _height * 4;
|
||||
|
||||
// swap the alpha channel (ARGB to RGBA)
|
||||
swapAlphaChannel((unsigned int *)_data, (_width * _height) );
|
||||
|
||||
// ok
|
||||
bRet = true;
|
||||
|
||||
|
@ -241,19 +229,6 @@ bool Image::initWithStringShadowStroke(
|
|||
|
||||
NS_CC_END
|
||||
|
||||
// swap the alpha channel in an 32 bit image (from ARGB to RGBA)
|
||||
void swapAlphaChannel(unsigned int *pImageMemory, unsigned int numPixels)
|
||||
{
|
||||
for(int c = 0; c < numPixels; ++c, ++pImageMemory)
|
||||
{
|
||||
// copy the current pixel
|
||||
unsigned int currenPixel = (*pImageMemory);
|
||||
// swap channels and store back
|
||||
char *pSource = (char *) ¤Pixel;
|
||||
*pImageMemory = (pSource[0] << 24) | (pSource[3]<<16) | (pSource[2]<<8) | pSource[1];
|
||||
}
|
||||
}
|
||||
|
||||
// this method is called by Cocos2dxBitmap
|
||||
extern "C"
|
||||
{
|
||||
|
@ -268,17 +243,5 @@ extern "C"
|
|||
bitmapDC._height = height;
|
||||
bitmapDC._data = new unsigned char[size];
|
||||
env->GetByteArrayRegion(pixels, 0, size, (jbyte*)bitmapDC._data);
|
||||
|
||||
// swap data
|
||||
unsigned int *tempPtr = (unsigned int*)bitmapDC._data;
|
||||
unsigned int tempdata = 0;
|
||||
for (int i = 0; i < height; ++i)
|
||||
{
|
||||
for (int j = 0; j < width; ++j)
|
||||
{
|
||||
tempdata = *tempPtr;
|
||||
*tempPtr++ = bitmapDC.swapAlpha(tempdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/14/13.
|
||||
//
|
||||
|
||||
|
||||
#include "CCNewDrawNode.h"
|
||||
#include "QuadCommand.h"
|
||||
#include "Renderer.h"
|
||||
#include "CustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
NewDrawNode *NewDrawNode::create()
|
||||
{
|
||||
NewDrawNode* pRet = new NewDrawNode();
|
||||
if (pRet && pRet->init())
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
|
||||
return pRet;
|
||||
}
|
||||
|
||||
NewDrawNode::NewDrawNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewDrawNode::~NewDrawNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool NewDrawNode::init()
|
||||
{
|
||||
return DrawNode::init();
|
||||
}
|
||||
|
||||
void NewDrawNode::draw()
|
||||
{
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(NewDrawNode::onDraw, this);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void NewDrawNode::onDraw()
|
||||
{
|
||||
CC_NODE_DRAW_SETUP();
|
||||
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/14/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef __CCNewDrawNode_H_
|
||||
#define __CCNewDrawNode_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCDrawNode.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewDrawNode : public DrawNode
|
||||
{
|
||||
public:
|
||||
static NewDrawNode* create();
|
||||
|
||||
virtual bool init();
|
||||
|
||||
void draw();
|
||||
|
||||
void onDraw();
|
||||
|
||||
protected:
|
||||
NewDrawNode();
|
||||
virtual ~NewDrawNode();
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCNewDrawNode_H_
|
|
@ -0,0 +1,67 @@
|
|||
/****************************************************************************
|
||||
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 "CCNewLabelAtlas.h"
|
||||
#include "RenderCommand.h"
|
||||
#include "Renderer.h"
|
||||
#include "QuadCommand.h"
|
||||
#include "CCMenuItem.h"
|
||||
#include "Frustum.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCTextureAtlas.h"
|
||||
#include "CCShaderCache.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
void NewLabelAtlas::draw()
|
||||
{
|
||||
// LabelAtlas::draw();
|
||||
// _renderCommand.init(0, _vertexZ, _textureAtlas->getTexture()->getName(), _shaderProgram, _blendFunc,
|
||||
// _textureAtlas->getQuads(), _textureAtlas->getTotalQuads() );
|
||||
//
|
||||
// Renderer::getInstance()->addCommand(&_renderCommand);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,50 @@
|
|||
/****************************************************************************
|
||||
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 __CCNEWLABELATLAS_H_
|
||||
#define __CCNEWLABELATLAS_H_
|
||||
|
||||
#include "CCLabelAtlas.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "QuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewLabelAtlas : public LabelAtlas
|
||||
{
|
||||
|
||||
public:
|
||||
NewLabelAtlas() {}
|
||||
virtual ~NewLabelAtlas() {}
|
||||
|
||||
virtual void draw(void) override;
|
||||
|
||||
protected:
|
||||
QuadCommand _renderCommand;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(__CCNEWLABELATLAS_H_) */
|
|
@ -0,0 +1,6 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/22/13.
|
||||
//
|
||||
|
||||
|
||||
#include "CCNewParticleSystemQuad.h"
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/22/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef __CCNewParticleSystemQuad_H_
|
||||
#define __CCNewParticleSystemQuad_H_
|
||||
|
||||
#include "CCParticleSystemQuad.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewParticleSystemQuad : public ParticleSystemQuad
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCNewParticleSystemQuad_H_
|
|
@ -0,0 +1,295 @@
|
|||
//
|
||||
// Created by NiTe Luo on 12/2/13.
|
||||
//
|
||||
|
||||
|
||||
#include "CCNewRenderTexture.h"
|
||||
#include "CustomCommand.h"
|
||||
#include "Renderer.h"
|
||||
#include "GroupCommand.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 NULL;
|
||||
}
|
||||
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
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);
|
||||
Renderer::getInstance()->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({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);
|
||||
Renderer::getInstance()->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::getInstance()->addCommand(groupCommand);
|
||||
Renderer::getInstance()->pushGroup(groupCommand->getRenderQueueID());
|
||||
|
||||
CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beginCmd->init(0, _vertexZ);
|
||||
beginCmd->func = CC_CALLBACK_0(NewRenderTexture::onBegin, this);
|
||||
|
||||
Renderer::getInstance()->addCommand(beginCmd);
|
||||
}
|
||||
|
||||
void NewRenderTexture::end()
|
||||
{
|
||||
CustomCommand* endCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
endCmd->init(0, _vertexZ);
|
||||
endCmd->func = CC_CALLBACK_0(NewRenderTexture::onEnd, this);
|
||||
|
||||
Renderer::getInstance()->addCommand(endCmd);
|
||||
|
||||
Renderer::getInstance()->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);
|
||||
|
||||
Renderer::getInstance()->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
|
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// Created by NiTe Luo on 12/2/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#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_
|
|
@ -0,0 +1,150 @@
|
|||
//
|
||||
// CCNewSprite.cpp
|
||||
// cocos2d_libs
|
||||
//
|
||||
// Created by NiTe Luo on 10/31/13.
|
||||
//
|
||||
//
|
||||
|
||||
#include "CCNewSprite.h"
|
||||
#include "Renderer.h"
|
||||
#include "Frustum.h"
|
||||
#include "CCDirector.h"
|
||||
#include "QuadCommand.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 NULL;
|
||||
}
|
||||
|
||||
NewSprite* NewSprite::create(const char *filename)
|
||||
{
|
||||
NewSprite* sprite = new NewSprite();
|
||||
if(sprite && sprite->initWithFile(filename))
|
||||
{
|
||||
sprite->autorelease();
|
||||
return sprite;
|
||||
}
|
||||
CC_SAFE_DELETE(sprite);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Renderer::getInstance()->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);
|
||||
point = {newRect.getMaxX(), newRect.getMinY(), _vertexZ};
|
||||
aabb.expand(point);
|
||||
point = {newRect.getMinX(), newRect.getMaxY(), _vertexZ};
|
||||
aabb.expand(point);
|
||||
point = {newRect.getMaxX(), newRect.getMaxY(), _vertexZ};
|
||||
aabb.expand(point);
|
||||
|
||||
return Frustum::IntersectResult::OUTSIDE !=frustum->intersectAABB(aabb);
|
||||
}
|
||||
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// CCNewSprite.h
|
||||
// cocos2d_libs
|
||||
//
|
||||
// Created by NiTe Luo on 10/31/13.
|
||||
//
|
||||
//
|
||||
|
||||
#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);
|
||||
|
||||
NewSprite(void);
|
||||
~NewSprite();
|
||||
|
||||
virtual bool initWithTexture(Texture2D *texture, const Rect& rect, bool rotated);
|
||||
|
||||
virtual void updateQuadVertices();
|
||||
virtual void draw(void) override;
|
||||
|
||||
bool culling() const;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /* defined(__CCNEWSPRITE_H_) */
|
|
@ -0,0 +1,83 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/11/13.
|
||||
//
|
||||
|
||||
|
||||
#include "CCNewSpriteBatchNode.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "CCTextureCache.h"
|
||||
#include "CCSprite.h"
|
||||
#include "CCNewSprite.h"
|
||||
#include "QuadCommand.h"
|
||||
#include "Renderer.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);
|
||||
Renderer::getInstance()->addCommand(cmd);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/11/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#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);
|
||||
|
||||
NewSpriteBatchNode();
|
||||
virtual ~NewSpriteBatchNode();
|
||||
|
||||
bool init();
|
||||
|
||||
void draw(void);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCNewSpriteBatchNode_H_
|
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/11/13.
|
||||
//
|
||||
|
||||
|
||||
#include "CCNewTextureAtlas.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "CCDirector.h"
|
||||
#include "Renderer.h"
|
||||
#include "QuadCommand.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 NULL;
|
||||
}
|
||||
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
|
||||
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
|
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/11/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#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);
|
||||
|
||||
NewTextureAtlas();
|
||||
|
||||
virtual ~NewTextureAtlas();
|
||||
|
||||
void drawNumberOfQuads(long numberOfQuads, long start);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCNewTextureAtlas_H_
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/8/13.
|
||||
//
|
||||
|
||||
|
||||
#include "CustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
RenderCommandPool<CustomCommand> CustomCommand::_commandPool;
|
||||
|
||||
CustomCommand::CustomCommand()
|
||||
:RenderCommand()
|
||||
, _viewport(0)
|
||||
, _depth(0)
|
||||
, func(nullptr)
|
||||
{
|
||||
_type = CUSTOM_COMMAND;
|
||||
}
|
||||
|
||||
void CustomCommand::init(int viewport, int32_t depth)
|
||||
{
|
||||
_viewport = viewport;
|
||||
_depth = depth;
|
||||
}
|
||||
|
||||
CustomCommand::~CustomCommand()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int64_t CustomCommand::generateID()
|
||||
{
|
||||
_id = 0;
|
||||
|
||||
_id = (int64_t)_viewport << 61
|
||||
| (int64_t)1 << 60 // translucent
|
||||
| (int64_t)_depth << 36;
|
||||
|
||||
return _id;
|
||||
}
|
||||
|
||||
void CustomCommand::execute()
|
||||
{
|
||||
if(func)
|
||||
{
|
||||
func();
|
||||
}
|
||||
}
|
||||
|
||||
void CustomCommand::releaseToCommandPool()
|
||||
{
|
||||
getCommandPool().pushBackCommand(this);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/8/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef _CC_CUSTOMCOMMAND_H_
|
||||
#define _CC_CUSTOMCOMMAND_H_
|
||||
|
||||
#include "RenderCommand.h"
|
||||
#include "RenderCommandPool.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
using namespace std;
|
||||
|
||||
class CustomCommand : public RenderCommand
|
||||
{
|
||||
protected:
|
||||
CustomCommand();
|
||||
~CustomCommand();
|
||||
|
||||
public:
|
||||
void init(int viewport, int32_t depth);
|
||||
|
||||
// +----------+----------+-----+-----------------------------------+
|
||||
// | | | | | |
|
||||
// | ViewPort | Transluc | | Depth | |
|
||||
// | 3 bits | 1 bit | | 24 bits | |
|
||||
// +----------+----------+-----+----------------+------------------+
|
||||
virtual int64_t generateID();
|
||||
|
||||
void execute();
|
||||
|
||||
inline bool isTranslucent() { return true; }
|
||||
virtual void releaseToCommandPool() override;
|
||||
|
||||
public:
|
||||
function<void()> func;
|
||||
|
||||
protected:
|
||||
int _viewport;
|
||||
|
||||
int32_t _depth;
|
||||
|
||||
public:
|
||||
friend class RenderCommandPool<CustomCommand>;
|
||||
static RenderCommandPool<CustomCommand>& getCommandPool() { return _commandPool; }
|
||||
protected:
|
||||
static RenderCommandPool<CustomCommand> _commandPool;
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //_CC_CUSTOMCOMMAND_H_
|
|
@ -0,0 +1,390 @@
|
|||
#include "Frustum.h"
|
||||
#include <stdlib.h>
|
||||
#include "CCCommon.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
ViewTransform::ViewTransform()
|
||||
{
|
||||
_position = {0, 0, 0};
|
||||
_focus = {0, 0, -1};
|
||||
_up = {0, 1, 0 };
|
||||
_dirty = true;
|
||||
kmMat4Identity(&_matrix);
|
||||
}
|
||||
|
||||
ViewTransform::~ViewTransform()
|
||||
{
|
||||
}
|
||||
|
||||
void ViewTransform::Init(const kmVec3 &pos, const kmVec3 &focus, const kmVec3 &up)
|
||||
{
|
||||
_position = pos;
|
||||
_focus = focus;
|
||||
_up = up;
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
void ViewTransform::LazyAdjust() const
|
||||
{
|
||||
if(!_dirty) return;
|
||||
kmVec3Subtract(&_adjustDir, &_focus, &_position);
|
||||
kmVec3Normalize(&_adjustDir, &_adjustDir);
|
||||
|
||||
kmVec3Cross(&_adjustRight, &_adjustDir, &_up);
|
||||
kmVec3Normalize(&_adjustRight, &_adjustRight);
|
||||
|
||||
kmVec3Cross(&_adjustUp, &_adjustRight, &_adjustDir);
|
||||
kmVec3Normalize(&_adjustUp, &_adjustUp);
|
||||
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
const kmVec3& ViewTransform::getDirection() const
|
||||
{
|
||||
LazyAdjust();
|
||||
return _adjustDir;
|
||||
}
|
||||
|
||||
const kmVec3& ViewTransform::getRight() const
|
||||
{
|
||||
LazyAdjust();
|
||||
return _adjustRight;
|
||||
}
|
||||
|
||||
const kmVec3& ViewTransform::getUp() const
|
||||
{
|
||||
LazyAdjust();
|
||||
return _adjustUp;
|
||||
}
|
||||
|
||||
AABB::AABB(const kmVec3& min, const kmVec3& max)
|
||||
{
|
||||
_min = min;
|
||||
_max = max;
|
||||
if(_min.x > _max.x)
|
||||
{
|
||||
CCLOG("_min.x is greater than _max.x, it will be swapped!");
|
||||
float temp = _min.x; _min.x = _max.x; _max.x = temp;
|
||||
}
|
||||
if(_min.y > _max.y)
|
||||
{
|
||||
CCLOG("_min.y is greater than _max.y, it will be swapped!");
|
||||
float temp = _min.y; _min.y = _max.y; _max.y = temp;
|
||||
}
|
||||
if(_min.z > _max.z)
|
||||
{
|
||||
CCLOG("_min.z is greater than _max.z, it will be swapped!");
|
||||
float temp = _min.z; _min.z = _max.z; _max.z = temp;
|
||||
}
|
||||
}
|
||||
|
||||
AABB::~AABB()
|
||||
{
|
||||
}
|
||||
|
||||
kmVec3 AABB::getCenter() const
|
||||
{
|
||||
kmVec3 result;
|
||||
|
||||
kmVec3Add(&result, &_min, &_max);
|
||||
kmVec3Scale(&result, &result, 0.5f);
|
||||
return result;
|
||||
}
|
||||
|
||||
float AABB::getDimensionX() const
|
||||
{
|
||||
return _max.x - _min.x;
|
||||
}
|
||||
|
||||
float AABB::getDimensionY() const
|
||||
{
|
||||
return _max.y - _min.y;
|
||||
}
|
||||
|
||||
float AABB::getDimensionZ() const
|
||||
{
|
||||
return _max.z - _min.z;
|
||||
}
|
||||
|
||||
kmVec3 AABB::getPositivePoint(const kmVec3& direction) const
|
||||
{
|
||||
kmVec3 result = _max;
|
||||
if( direction.x < 0 ) result.x = _min.x;
|
||||
if( direction.y < 0 ) result.y = _min.y;
|
||||
if( direction.z < 0 ) result.z = _min.z;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const AABB& AABB::expand(const kmVec3& point)
|
||||
{
|
||||
if(point.x > _max.x) _max.x = point.x;
|
||||
if(point.y > _max.y) _max.y = point.y;
|
||||
if(point.z > _max.z) _max.z = point.z;
|
||||
|
||||
if(point.x < _min.x) _min.x = point.x;
|
||||
if(point.y < _min.y) _min.y = point.y;
|
||||
if(point.z < _min.z) _min.z = point.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
kmVec3 AABB::getNegativePoint(const kmVec3& direction) const
|
||||
{
|
||||
kmVec3 result = _min;
|
||||
if( direction.x < 0 ) result.x = _max.x;
|
||||
if( direction.y < 0 ) result.y = _max.y;
|
||||
if( direction.z < 0 ) result.z = _max.z;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Frustum::Frustum()
|
||||
{
|
||||
}
|
||||
|
||||
Frustum::~Frustum()
|
||||
{
|
||||
}
|
||||
|
||||
void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, float width, float height, float near, float far)
|
||||
{
|
||||
kmVec3 cc = view.getPosition();
|
||||
kmVec3 cDir = view.getDirection();
|
||||
kmVec3 cRight = view.getRight();
|
||||
kmVec3 cUp = view.getUp();
|
||||
|
||||
kmVec3Normalize(&cDir, &cDir);
|
||||
kmVec3Normalize(&cRight, &cRight);
|
||||
kmVec3Normalize(&cUp, &cUp);
|
||||
|
||||
//near
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
normal = cDir;
|
||||
kmVec3Scale(&point, &cDir, near);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::NEAR], &point, &normal);
|
||||
}
|
||||
|
||||
//far
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
kmVec3Scale(&normal, &cDir, -1);
|
||||
kmVec3Scale(&point, &cDir, far);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FAR], &point, &normal);
|
||||
}
|
||||
|
||||
//left
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
normal = cRight;
|
||||
kmVec3Scale(&point, &cRight, -width * 0.5);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::LEFT], &point, &normal);
|
||||
}
|
||||
|
||||
//right
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
kmVec3Scale(&normal, &cRight, -1);
|
||||
kmVec3Scale(&point, &cRight, width * 0.5);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::RIGHT], &point, &normal);
|
||||
}
|
||||
|
||||
//bottom
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
normal = cUp;
|
||||
kmVec3Scale(&point, &cUp, -height * 0.5);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::BOTTOM], &point, &normal);
|
||||
}
|
||||
|
||||
//top
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
kmVec3Scale(&normal, &cUp, -1);
|
||||
kmVec3Scale(&point, &cUp, height * 0.5);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::TOP], &point, &normal);
|
||||
}
|
||||
}
|
||||
|
||||
void Frustum::setupProjectionPerspective(const ViewTransform& view, float left, float right, float top, float bottom, float near, float far)
|
||||
{
|
||||
kmVec3 cc = view.getPosition();
|
||||
kmVec3 cDir = view.getDirection();
|
||||
kmVec3 cRight = view.getRight();
|
||||
kmVec3 cUp = view.getUp();
|
||||
|
||||
kmVec3Normalize(&cDir, &cDir);
|
||||
kmVec3Normalize(&cRight, &cRight);
|
||||
kmVec3Normalize(&cUp, &cUp);
|
||||
|
||||
kmVec3 nearCenter;
|
||||
kmVec3 farCenter;
|
||||
|
||||
kmVec3Scale(&nearCenter, &cDir, near);
|
||||
kmVec3Add(&nearCenter, &nearCenter, &cc);
|
||||
|
||||
kmVec3Scale(&farCenter, &cDir, far);
|
||||
kmVec3Add(&farCenter, &farCenter, &cc);
|
||||
|
||||
//near
|
||||
{
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::NEAR], &nearCenter, &cDir);
|
||||
}
|
||||
|
||||
//far
|
||||
{
|
||||
kmVec3 normal;
|
||||
kmVec3Scale(&normal, &cDir, -1);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FAR], &farCenter, &normal);
|
||||
}
|
||||
|
||||
//left
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3Scale(&point, &cRight, left);
|
||||
kmVec3Add(&point, &point, &nearCenter);
|
||||
|
||||
kmVec3 normal;
|
||||
kmVec3Subtract(&normal, &point, &cc);
|
||||
kmVec3Cross(&normal, &normal, &cUp);
|
||||
kmVec3Normalize(&normal, &normal);
|
||||
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::LEFT], &point, &normal);
|
||||
}
|
||||
|
||||
//right
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3Scale(&point, &cRight, right);
|
||||
kmVec3Add(&point, &point, &nearCenter);
|
||||
|
||||
kmVec3 normal;
|
||||
kmVec3Subtract(&normal, &point, &cc);
|
||||
kmVec3Cross(&normal, &cUp, &normal);
|
||||
kmVec3Normalize(&normal, &normal);
|
||||
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::RIGHT], &point, &normal);
|
||||
}
|
||||
|
||||
//bottom
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3Scale(&point, &cUp, bottom);
|
||||
kmVec3Add(&point, &point, &nearCenter);
|
||||
|
||||
kmVec3 normal;
|
||||
kmVec3Subtract(&normal, &point, &cc);
|
||||
kmVec3Cross(&normal, &cRight, &normal);
|
||||
kmVec3Normalize(&normal, &normal);
|
||||
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::BOTTOM], &point, &normal);
|
||||
}
|
||||
|
||||
//top
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3Scale(&point, &cUp, top);
|
||||
kmVec3Add(&point, &point, &nearCenter);
|
||||
|
||||
kmVec3 normal;
|
||||
kmVec3Subtract(&normal, &point, &cc);
|
||||
kmVec3Cross(&normal, &normal, &cRight);
|
||||
kmVec3Normalize(&normal, &normal);
|
||||
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::TOP], &point, &normal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Frustum::setupProjectionPerspectiveFov(const ViewTransform& view, float fov, float ratio, float near, float far)
|
||||
{
|
||||
float width = 2 * near * tan(fov * 0.5);
|
||||
float height = width/ratio;
|
||||
setupProjectionPerspective(view, -width/2, width/2, height/2, -height/2, near, far);
|
||||
}
|
||||
|
||||
void Frustum::setupFromMatrix(const kmMat4 &view, const kmMat4 &projection)
|
||||
{
|
||||
kmMat4 mvp;
|
||||
kmMat4Multiply(&mvp, &projection, &view);
|
||||
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::NEAR], &mvp, KM_PLANE_NEAR);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::FAR], &mvp, KM_PLANE_FAR);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::LEFT], &mvp, KM_PLANE_LEFT);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::RIGHT], &mvp, KM_PLANE_RIGHT);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::BOTTOM], &mvp, KM_PLANE_BOTTOM);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::TOP], &mvp, KM_PLANE_TOP);
|
||||
}
|
||||
|
||||
Frustum::IntersectResult Frustum::intersectPoint(const kmVec3 &point) const
|
||||
{
|
||||
int indexFirst = static_cast<int>(FrustumPlane::NEAR);
|
||||
int indexNumber = static_cast<int>(FrustumPlane::NUMBER);
|
||||
|
||||
for(int planeIndex = indexFirst; planeIndex < indexNumber; ++planeIndex)
|
||||
{
|
||||
if(kmPlaneDotCoord(&_frustumPlanes[static_cast<FrustumPlane>(planeIndex)], &point) < 0)
|
||||
return IntersectResult::OUTSIDE;
|
||||
}
|
||||
return IntersectResult::INSIDE;
|
||||
}
|
||||
|
||||
Frustum::IntersectResult Frustum::intersectAABB(const AABB& aabb) const
|
||||
{
|
||||
IntersectResult result = IntersectResult::INSIDE;
|
||||
int indexFirst = static_cast<int>(FrustumPlane::NEAR);
|
||||
int indexNumber = static_cast<int>(FrustumPlane::NUMBER);
|
||||
|
||||
for(int planeIndex = indexFirst; planeIndex < indexNumber; ++planeIndex)
|
||||
{
|
||||
kmPlane plane = _frustumPlanes[static_cast<FrustumPlane>(planeIndex)];
|
||||
kmVec3 normal = {plane.a, plane.b, plane.c};
|
||||
kmVec3Normalize(&normal, &normal);
|
||||
kmVec3 positivePoint = aabb.getPositivePoint(normal);
|
||||
kmVec3 negativePoint = aabb.getNegativePoint(normal);
|
||||
|
||||
if(kmPlaneDotCoord(&plane, &positivePoint) < 0)
|
||||
return IntersectResult::OUTSIDE;
|
||||
if(kmPlaneDotCoord(&plane, &negativePoint) < 0)
|
||||
result = IntersectResult::INTERSECT;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Frustum::IntersectResult Frustum::intersectSphere(const kmVec3& center, float radius) const
|
||||
{
|
||||
IntersectResult result = IntersectResult::INSIDE;
|
||||
int indexFirst = static_cast<int>(FrustumPlane::NEAR);
|
||||
int indexNumber = static_cast<int>(FrustumPlane::NUMBER);
|
||||
|
||||
for(int planeIndex = indexFirst; planeIndex < indexNumber; ++planeIndex)
|
||||
{
|
||||
kmPlane plane = _frustumPlanes[static_cast<FrustumPlane>(planeIndex)];
|
||||
kmVec3 normal = {plane.a, plane.b, plane.c};
|
||||
|
||||
float distance = kmPlaneDotCoord(&plane, ¢er);
|
||||
distance = distance / kmVec3Length(&normal);
|
||||
|
||||
if(distance < -radius) return IntersectResult::OUTSIDE;
|
||||
if(distance <= radius && distance >= -radius) result = IntersectResult::INTERSECT;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,96 @@
|
|||
#ifndef __CC_FRUSTUM_H__
|
||||
#define __CC_FRUSTUM_H__
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "math/kazmath/include/kazmath/kazmath.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class ViewTransform
|
||||
{
|
||||
public:
|
||||
ViewTransform();
|
||||
~ViewTransform();
|
||||
void Init(const kmVec3& pos, const kmVec3& focus, const kmVec3& up);
|
||||
|
||||
const kmVec3& getPosition() const { return _position; }
|
||||
const kmVec3& getFocus() const { return _focus; }
|
||||
const kmVec3& getDirection() const;
|
||||
const kmVec3& getRight() const;
|
||||
const kmVec3& getUp() const;
|
||||
|
||||
private:
|
||||
void LazyAdjust() const;
|
||||
private:
|
||||
kmVec3 _position;
|
||||
kmVec3 _focus;
|
||||
kmVec3 _up;
|
||||
|
||||
mutable bool _dirty;
|
||||
mutable kmMat4 _matrix;
|
||||
mutable kmVec3 _adjustDir;
|
||||
mutable kmVec3 _adjustRight;
|
||||
mutable kmVec3 _adjustUp;
|
||||
};
|
||||
|
||||
class AABB
|
||||
{
|
||||
public:
|
||||
AABB(const kmVec3& min, const kmVec3& max);
|
||||
~AABB();
|
||||
|
||||
kmVec3 getCenter() const;
|
||||
|
||||
float getDimensionX() const;
|
||||
float getDimensionY() const;
|
||||
float getDimensionZ() const;
|
||||
|
||||
kmVec3 getPositivePoint(const kmVec3& direction) const;
|
||||
kmVec3 getNegativePoint(const kmVec3& direction) const;
|
||||
|
||||
const AABB& expand(const kmVec3& point);
|
||||
private:
|
||||
kmVec3 _min;
|
||||
kmVec3 _max;
|
||||
};
|
||||
|
||||
class Frustum
|
||||
{
|
||||
public:
|
||||
enum class IntersectResult
|
||||
{
|
||||
OUTSIDE = 0,
|
||||
INTERSECT = 1,
|
||||
INSIDE = 2
|
||||
};
|
||||
public:
|
||||
Frustum();
|
||||
~Frustum();
|
||||
|
||||
void setupProjectionOrthogonal(const ViewTransform& view, float width, float height, float near, float far);
|
||||
void setupProjectionPerspective(const ViewTransform& view, float left, float right, float top, float bottom, float near, float far);
|
||||
void setupProjectionPerspectiveFov(const ViewTransform& view, float fov, float ratio, float near, float far);
|
||||
|
||||
void setupFromMatrix(const kmMat4& view, const kmMat4& projection);
|
||||
|
||||
IntersectResult intersectPoint(const kmVec3& point) const;
|
||||
IntersectResult intersectAABB(const AABB& aabb) const;
|
||||
IntersectResult intersectSphere(const kmVec3& center, float radius) const;
|
||||
|
||||
private:
|
||||
enum FrustumPlane
|
||||
{
|
||||
NEAR = 0,
|
||||
FAR = 1,
|
||||
BOTTOM = 2,
|
||||
TOP = 3,
|
||||
LEFT = 4,
|
||||
RIGHT = 5,
|
||||
NUMBER = 6
|
||||
};
|
||||
kmPlane _frustumPlanes[FrustumPlane::NUMBER];
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
|
@ -0,0 +1,106 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/13/13.
|
||||
//
|
||||
|
||||
|
||||
#include "GroupCommand.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
RenderCommandPool<GroupCommand> GroupCommand::_commandPool;
|
||||
|
||||
static GroupCommandManager* s_instance;
|
||||
GroupCommandManager *GroupCommandManager::getInstance()
|
||||
{
|
||||
if(!s_instance)
|
||||
{
|
||||
s_instance = new GroupCommandManager();
|
||||
if(!s_instance->init())
|
||||
{
|
||||
CC_SAFE_DELETE(s_instance);
|
||||
}
|
||||
}
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
GroupCommandManager::GroupCommandManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GroupCommandManager::~GroupCommandManager()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(s_instance);
|
||||
}
|
||||
|
||||
bool GroupCommandManager::init()
|
||||
{
|
||||
//0 is the default render group
|
||||
_groupMapping[0] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int GroupCommandManager::getGroupID()
|
||||
{
|
||||
//Reuse old id
|
||||
for(auto it = _groupMapping.begin(); it != _groupMapping.end(); ++it)
|
||||
{
|
||||
if(!it->second)
|
||||
{
|
||||
return it->first;
|
||||
}
|
||||
}
|
||||
|
||||
//Create new ID
|
||||
// int newID = _groupMapping.size();
|
||||
int newID = Renderer::getInstance()->createRenderQueue();
|
||||
_groupMapping[newID] = true;
|
||||
|
||||
return newID;
|
||||
}
|
||||
|
||||
void GroupCommandManager::releaseGroupID(int groupID)
|
||||
{
|
||||
_groupMapping[groupID] = false;
|
||||
}
|
||||
|
||||
GroupCommand::GroupCommand()
|
||||
:RenderCommand()
|
||||
, _viewport(0)
|
||||
, _depth(0)
|
||||
{
|
||||
_type = GROUP_COMMAND;
|
||||
_renderQueueID = GroupCommandManager::getInstance()->getGroupID();
|
||||
}
|
||||
|
||||
void GroupCommand::init(int viewport, int32_t depth)
|
||||
{
|
||||
_viewport = viewport;
|
||||
_depth = depth;
|
||||
GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID);
|
||||
_renderQueueID = GroupCommandManager::getInstance()->getGroupID();
|
||||
}
|
||||
|
||||
GroupCommand::~GroupCommand()
|
||||
{
|
||||
GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID);
|
||||
}
|
||||
|
||||
int64_t GroupCommand::generateID()
|
||||
{
|
||||
_id = 0;
|
||||
|
||||
_id = (int64_t)_viewport << 61
|
||||
| (int64_t)1 << 60 // translucent
|
||||
| (int64_t)_depth << 36;
|
||||
|
||||
return _id;
|
||||
}
|
||||
|
||||
void GroupCommand::releaseToCommandPool()
|
||||
{
|
||||
getCommandPool().pushBackCommand(this);
|
||||
}
|
||||
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/13/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef _CC_GROUPCOMMAND_H_
|
||||
#define _CC_GROUPCOMMAND_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "RenderCommand.h"
|
||||
#include "RenderCommandPool.h"
|
||||
#include <map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
using namespace std;
|
||||
|
||||
class GroupCommandManager : public Object
|
||||
{
|
||||
public:
|
||||
static GroupCommandManager* getInstance();
|
||||
|
||||
~GroupCommandManager();
|
||||
|
||||
bool init();
|
||||
|
||||
int getGroupID();
|
||||
void releaseGroupID(int groupID);
|
||||
|
||||
protected:
|
||||
GroupCommandManager();
|
||||
map<int, bool> _groupMapping;
|
||||
};
|
||||
|
||||
class GroupCommand : public RenderCommand
|
||||
{
|
||||
protected:
|
||||
GroupCommand();
|
||||
~GroupCommand();
|
||||
public:
|
||||
void init(int viewport, int32_t depth);
|
||||
|
||||
// +----------+----------+-----+-----------------------------------+
|
||||
// | | | | | |
|
||||
// | ViewPort | Transluc | | Depth | |
|
||||
// | 3 bits | 1 bit | | 24 bits | |
|
||||
// +----------+----------+-----+----------------+------------------+
|
||||
virtual int64_t generateID() override;
|
||||
|
||||
inline bool isTranslucent() {return true;}
|
||||
inline int getRenderQueueID() {return _renderQueueID;}
|
||||
virtual void releaseToCommandPool() override;
|
||||
|
||||
protected:
|
||||
int _viewport;
|
||||
int32_t _depth;
|
||||
int _renderQueueID;
|
||||
|
||||
public:
|
||||
friend class RenderCommandPool<GroupCommand>;
|
||||
static RenderCommandPool<GroupCommand>& getCommandPool() { return _commandPool; }
|
||||
protected:
|
||||
static RenderCommandPool<GroupCommand> _commandPool;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //_CC_GROUPCOMMAND_H_
|
|
@ -0,0 +1,87 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
#include "MaterialManager.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
using namespace std;
|
||||
|
||||
static MaterialManager* s_instance = 0;
|
||||
|
||||
MaterialManager *MaterialManager::getInstance()
|
||||
{
|
||||
if(!s_instance)
|
||||
{
|
||||
s_instance = new MaterialManager();
|
||||
if(!s_instance->init())
|
||||
{
|
||||
CC_SAFE_DELETE(s_instance);
|
||||
}
|
||||
}
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void MaterialManager::destroyInstance()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(s_instance);
|
||||
}
|
||||
|
||||
void MaterialManager::getMaterialID(GLuint textureID, GLuint shaderID, BlendFunc blendFunc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MaterialManager::registerTexture(GLuint textureID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MaterialManager::unregisterTexture(GLuint textureID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MaterialManager::registerShader(GLuint shaderID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MaterialManager::unregisterShader(GLuint shaderID)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MaterialManager::MaterialManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MaterialManager::~MaterialManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MaterialManager::init()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int MaterialManager::getTextureID(GLuint textureID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MaterialManager::getShaderID(GLuint shaderID)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MaterialManager::getBlendFuncID(GLint blendFunc)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef _CC_MATERIALMANAGER_H_
|
||||
#define _CC_MATERIALMANAGER_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "ccTypes.h"
|
||||
#include <map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
using namespace std;
|
||||
|
||||
class MaterialManager : public Object
|
||||
{
|
||||
public:
|
||||
static MaterialManager* getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
|
||||
void getMaterialID(GLuint textureID, GLuint shaderID, BlendFunc blendFunc);
|
||||
|
||||
void registerTexture(GLuint textureID);
|
||||
void unregisterTexture(GLuint textureID);
|
||||
|
||||
void registerShader(GLuint shaderID);
|
||||
void unregisterShader(GLuint shaderID);
|
||||
|
||||
protected:
|
||||
MaterialManager();
|
||||
virtual ~MaterialManager();
|
||||
|
||||
bool init();
|
||||
|
||||
int getTextureID(GLuint textureID);
|
||||
int getShaderID(GLuint shaderID);
|
||||
int getBlendFuncID(GLint blendFunc);
|
||||
|
||||
map<GLuint, int> _textureIDMapping;
|
||||
map<GLuint, int> _shaderIDMapping;
|
||||
map<BlendFunc, int> _blendFuncMapping;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //_CC_MATERIALMANAGER_H_
|
|
@ -0,0 +1,281 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/13/13.
|
||||
//
|
||||
|
||||
|
||||
#include "NewClippingNode.h"
|
||||
#include "GroupCommand.h"
|
||||
#include "Renderer.h"
|
||||
#include "CustomCommand.h"
|
||||
#include "CCShaderCache.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 = Renderer::getInstance();
|
||||
|
||||
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
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/13/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#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();
|
||||
|
||||
protected:
|
||||
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_
|
|
@ -0,0 +1,160 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
#include "QuadCommand.h"
|
||||
#include "ccGLStateCache.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
RenderCommandPool<QuadCommand> QuadCommand::_commandPool;
|
||||
|
||||
QuadCommand::QuadCommand()
|
||||
:RenderCommand()
|
||||
,_viewport(0)
|
||||
,_depth(0)
|
||||
,_textureID(0)
|
||||
,_blendType(BlendFunc::DISABLE)
|
||||
,_quadCount(0)
|
||||
,_capacity(0)
|
||||
{
|
||||
_type = QUAD_COMMAND;
|
||||
_shader = nullptr;
|
||||
_quad = nullptr;
|
||||
}
|
||||
|
||||
void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, int quadCount, const kmMat4 &mv)
|
||||
{
|
||||
_viewport = viewport;
|
||||
_depth = depth;
|
||||
_textureID = textureID;
|
||||
_blendType = blendType;
|
||||
_quadCount = quadCount;
|
||||
_shader = shader;
|
||||
|
||||
if(quadCount > _capacity ) {
|
||||
//TODO find a better way to manage quads, current way will result in memory be wasted
|
||||
// _quad = (V3F_C4B_T2F_Quad*)malloc(sizeof(V3F_C4B_T2F_Quad) * quadCount);
|
||||
_quad = (V3F_C4B_T2F_Quad*) realloc(_quad, sizeof(*quad) * quadCount );
|
||||
_capacity = quadCount;
|
||||
}
|
||||
|
||||
kmMat4 p, mvp;
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &p);
|
||||
|
||||
kmMat4Multiply(&mvp, &p, &mv);
|
||||
|
||||
|
||||
_quadCount = quadCount;
|
||||
memcpy(_quad, quad, sizeof(V3F_C4B_T2F_Quad) * quadCount);
|
||||
|
||||
for(int i=0; i<quadCount; ++i) {
|
||||
V3F_C4B_T2F_Quad *q = &_quad[i];
|
||||
|
||||
kmVec3 vec1, out1;
|
||||
vec1.x = q->bl.vertices.x;
|
||||
vec1.y = q->bl.vertices.y;
|
||||
vec1.z = q->bl.vertices.z;
|
||||
kmVec3TransformCoord(&out1, &vec1, &mvp);
|
||||
q->bl.vertices.x = out1.x;
|
||||
q->bl.vertices.y = out1.y;
|
||||
q->bl.vertices.z = out1.z;
|
||||
|
||||
kmVec3 vec2, out2;
|
||||
vec2.x = q->br.vertices.x;
|
||||
vec2.y = q->br.vertices.y;
|
||||
vec2.z = q->br.vertices.z;
|
||||
kmVec3TransformCoord(&out2, &vec2, &mvp);
|
||||
q->br.vertices.x = out2.x;
|
||||
q->br.vertices.y = out2.y;
|
||||
q->br.vertices.z = out2.z;
|
||||
|
||||
kmVec3 vec3, out3;
|
||||
vec3.x = q->tr.vertices.x;
|
||||
vec3.y = q->tr.vertices.y;
|
||||
vec3.z = q->tr.vertices.z;
|
||||
kmVec3TransformCoord(&out3, &vec3, &mvp);
|
||||
q->tr.vertices.x = out3.x;
|
||||
q->tr.vertices.y = out3.y;
|
||||
q->tr.vertices.z = out3.z;
|
||||
|
||||
kmVec3 vec4, out4;
|
||||
vec4.x = q->tl.vertices.x;
|
||||
vec4.y = q->tl.vertices.y;
|
||||
vec4.z = q->tl.vertices.z;
|
||||
kmVec3TransformCoord(&out4, &vec4, &mvp);
|
||||
q->tl.vertices.x = out4.x;
|
||||
q->tl.vertices.y = out4.y;
|
||||
q->tl.vertices.z = out4.z;
|
||||
}
|
||||
}
|
||||
|
||||
QuadCommand::~QuadCommand()
|
||||
{
|
||||
free(_quad);
|
||||
}
|
||||
|
||||
int64_t QuadCommand::generateID()
|
||||
{
|
||||
_id = 0;
|
||||
|
||||
//Generate Material ID
|
||||
//TODO fix shader ID generation
|
||||
CCASSERT(_shader->getProgram() < 64, "ShaderID is greater than 64");
|
||||
//TODO fix texture ID generation
|
||||
CCASSERT(_textureID < 1024, "TextureID is greater than 1024");
|
||||
|
||||
//TODO fix blend id generation
|
||||
int blendID = 0;
|
||||
if(_blendType == BlendFunc::DISABLE)
|
||||
{
|
||||
blendID = 0;
|
||||
}
|
||||
else if(_blendType == BlendFunc::ALPHA_PREMULTIPLIED)
|
||||
{
|
||||
blendID = 1;
|
||||
}
|
||||
else if(_blendType == BlendFunc::ALPHA_NON_PREMULTIPLIED)
|
||||
{
|
||||
blendID = 2;
|
||||
}
|
||||
else if(_blendType == BlendFunc::ADDITIVE)
|
||||
{
|
||||
blendID = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
blendID = 4;
|
||||
}
|
||||
|
||||
_materialID = (int32_t)_shader->getProgram() << 28
|
||||
| (int32_t)blendID << 24
|
||||
| (int32_t)_textureID << 14;
|
||||
|
||||
//Generate RenderCommandID
|
||||
_id = (int64_t)_viewport << 61
|
||||
| (int64_t)1 << 60 //translucent
|
||||
| (int64_t)_depth << 36;
|
||||
|
||||
return _id;
|
||||
}
|
||||
|
||||
void QuadCommand::useMaterial()
|
||||
{
|
||||
_shader->use();
|
||||
|
||||
_shader->setUniformsForBuiltins();
|
||||
|
||||
//Set texture
|
||||
GL::bindTexture2D(_textureID);
|
||||
|
||||
//set blend mode
|
||||
GL::blendFunc(_blendType.src, _blendType.dst);
|
||||
}
|
||||
|
||||
void QuadCommand::releaseToCommandPool()
|
||||
{
|
||||
getCommandPool().pushBackCommand(this);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,85 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef _CC_QUADCOMMAND_H_
|
||||
#define _CC_QUADCOMMAND_H_
|
||||
|
||||
#include "RenderCommand.h"
|
||||
#include "CCGLProgram.h"
|
||||
#include "RenderCommandPool.h"
|
||||
#include "kazmath.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#define CC_NO_TEXTURE 0
|
||||
|
||||
class QuadCommand : public RenderCommand
|
||||
{
|
||||
public:
|
||||
QuadCommand();
|
||||
~QuadCommand();
|
||||
|
||||
public:
|
||||
void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, int quadCount,
|
||||
const kmMat4& mv);
|
||||
|
||||
// +----------+----------+-----+-----------------------------------+
|
||||
// | | | | | |
|
||||
// | ViewPort | Transluc | | Depth | Material ID |
|
||||
// | 3 bits | 1 bit | | 24 bits | 24 bit2 |
|
||||
// +----------+----------+-----+----------------+------------------+
|
||||
virtual int64_t generateID();
|
||||
|
||||
void useMaterial();
|
||||
|
||||
//TODO use material to decide if it is translucent
|
||||
inline bool isTranslucent() { return true; }
|
||||
|
||||
inline int32_t getMaterialID() { return _materialID; }
|
||||
|
||||
inline GLuint getTextureID() { return _textureID; }
|
||||
|
||||
inline V3F_C4B_T2F_Quad* getQuad() { return _quad; }
|
||||
|
||||
inline int getQuadCount() { return _quadCount; }
|
||||
|
||||
inline GLProgram* getShader() { return _shader; }
|
||||
|
||||
inline BlendFunc getBlendType() { return _blendType; }
|
||||
|
||||
virtual void releaseToCommandPool() override;
|
||||
|
||||
protected:
|
||||
int32_t _materialID;
|
||||
|
||||
//Key Data
|
||||
int _viewport; /// Which view port it belongs to
|
||||
|
||||
//TODO use material to determine if it's translucent
|
||||
int32_t _depth;
|
||||
|
||||
//Maternal
|
||||
GLuint _textureID;
|
||||
|
||||
GLProgram* _shader;
|
||||
// GLuint _shaderID;
|
||||
|
||||
BlendFunc _blendType;
|
||||
|
||||
V3F_C4B_T2F_Quad* _quad;
|
||||
int _quadCount;
|
||||
int _capacity;
|
||||
|
||||
public:
|
||||
friend class RenderCommandPool<QuadCommand>;
|
||||
static RenderCommandPool<QuadCommand>& getCommandPool() { return _commandPool; }
|
||||
protected:
|
||||
static RenderCommandPool<QuadCommand> _commandPool;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //_CC_QUADCOMMAND_H_
|
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// Created by NiTe Luo on 10/31/13.
|
||||
//
|
||||
|
||||
|
||||
#include "RenderCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
RenderCommand::RenderCommand()
|
||||
{
|
||||
_id = 0;
|
||||
_type = UNKNOWN_COMMAND;
|
||||
}
|
||||
|
||||
RenderCommand::~RenderCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void printBits(size_t const size, void const * const ptr)
|
||||
{
|
||||
unsigned char *b = (unsigned char*) ptr;
|
||||
unsigned char byte;
|
||||
int i, j;
|
||||
|
||||
for (i=size-1;i>=0;i--)
|
||||
{
|
||||
for (j=7;j>=0;j--)
|
||||
{
|
||||
byte = b[i] & (1<<j);
|
||||
byte >>= j;
|
||||
printf("%u", byte);
|
||||
}
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
|
||||
void RenderCommand::printID()
|
||||
{
|
||||
printf("CommandID: ");
|
||||
printBits(sizeof(_id), &_id);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// Created by NiTe Luo on 10/31/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef __CCRENDERCOMMAND_H_
|
||||
#define __CCRENDERCOMMAND_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include <stdint.h>
|
||||
#include "ccTypes.h"
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
enum RenderCommandType
|
||||
{
|
||||
QUAD_COMMAND,
|
||||
CUSTOM_COMMAND,
|
||||
GROUP_COMMAND,
|
||||
UNKNOWN_COMMAND,
|
||||
};
|
||||
|
||||
//TODO make RenderCommand inherent from Object
|
||||
class RenderCommand
|
||||
{
|
||||
protected:
|
||||
RenderCommand();
|
||||
virtual ~RenderCommand();
|
||||
public:
|
||||
virtual int64_t generateID() = 0;
|
||||
|
||||
virtual /**
|
||||
* Get Render Command Id
|
||||
*/
|
||||
inline int64_t getID() { return _id; }
|
||||
|
||||
virtual inline RenderCommandType getType() { return _type; }
|
||||
virtual void releaseToCommandPool() =0;
|
||||
protected:
|
||||
void printID();
|
||||
|
||||
protected:
|
||||
//Generated IDs
|
||||
int64_t _id; /// used for sorting render commands
|
||||
RenderCommandType _type;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCRENDERCOMMAND_H_
|
|
@ -0,0 +1,84 @@
|
|||
//
|
||||
// RenderCommandPool.h
|
||||
// cocos2d_libs
|
||||
//
|
||||
// Created by Huabing on 11/28/13.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef __CC_RENDERCOMMANDPOOL_H__
|
||||
#define __CC_RENDERCOMMANDPOOL_H__
|
||||
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include "CCPlatformMacros.h"
|
||||
NS_CC_BEGIN
|
||||
|
||||
template <class T>
|
||||
class RenderCommandPool
|
||||
{
|
||||
public:
|
||||
RenderCommandPool()
|
||||
{
|
||||
}
|
||||
~RenderCommandPool()
|
||||
{
|
||||
// if( 0 != _usedPool.size())
|
||||
// {
|
||||
// CCLOG("All RenderCommand should not be used when Pool is released!");
|
||||
// }
|
||||
_freePool.clear();
|
||||
for (typename std::list<T*>::iterator iter = _allocatedPoolBlocks.begin(); iter != _allocatedPoolBlocks.end(); ++iter)
|
||||
{
|
||||
delete[] *iter;
|
||||
*iter = nullptr;
|
||||
}
|
||||
_allocatedPoolBlocks.clear();
|
||||
}
|
||||
|
||||
public:
|
||||
T* generateCommand()
|
||||
{
|
||||
T* result = nullptr;
|
||||
if(_freePool.empty())
|
||||
{
|
||||
AllocateCommands();
|
||||
}
|
||||
result = _freePool.front();
|
||||
_freePool.pop_front();
|
||||
//_usedPool.insert(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void pushBackCommand(T* ptr)
|
||||
{
|
||||
// if(_usedPool.find(ptr) == _usedPool.end())
|
||||
// {
|
||||
// CCLOG("push Back Wrong command!");
|
||||
// return;
|
||||
// }
|
||||
|
||||
_freePool.push_back(ptr);
|
||||
//_usedPool.erase(ptr);
|
||||
|
||||
}
|
||||
private:
|
||||
void AllocateCommands()
|
||||
{
|
||||
static const int COMMANDS_ALLOCATE_BLOCK_SIZE = 32;
|
||||
T* commands = new T[COMMANDS_ALLOCATE_BLOCK_SIZE];
|
||||
_allocatedPoolBlocks.push_back(commands);
|
||||
for(int index = 0; index < COMMANDS_ALLOCATE_BLOCK_SIZE; ++index)
|
||||
{
|
||||
_freePool.push_back(commands+index);
|
||||
}
|
||||
}
|
||||
private:
|
||||
std::list<T*> _allocatedPoolBlocks;
|
||||
std::list<T*> _freePool;
|
||||
//std::set<T*> _usedPool;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
#include "RenderMaterial.h"
|
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// Created by NiTe Luo on 11/6/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef __RenderMaterial_H_
|
||||
#define __RenderMaterial_H_
|
||||
|
||||
|
||||
class RenderMaterial
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //__RenderMaterial_H_
|
|
@ -0,0 +1,414 @@
|
|||
//
|
||||
// Created by NiTe Luo on 10/31/13.
|
||||
//
|
||||
|
||||
|
||||
#include "Renderer.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "ccGLStateCache.h"
|
||||
#include "CustomCommand.h"
|
||||
#include "QuadCommand.h"
|
||||
#include "GroupCommand.h"
|
||||
#include "CCConfiguration.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
using namespace std;
|
||||
|
||||
static Renderer* s_instance;
|
||||
|
||||
Renderer *Renderer::getInstance()
|
||||
{
|
||||
if(!s_instance)
|
||||
{
|
||||
s_instance = new Renderer();
|
||||
if(!s_instance->init())
|
||||
{
|
||||
CC_SAFE_DELETE(s_instance);
|
||||
}
|
||||
}
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void Renderer::destroyInstance()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(s_instance);
|
||||
}
|
||||
|
||||
Renderer::Renderer()
|
||||
:_lastMaterialID(0)
|
||||
,_numQuads(0)
|
||||
,_firstCommand(0)
|
||||
,_lastCommand(0)
|
||||
,_glViewAssigned(false)
|
||||
{
|
||||
_commandGroupStack.push(DEFAULT_RENDER_QUEUE);
|
||||
|
||||
RenderQueue defaultRenderQueue;
|
||||
_renderGroups.push_back(defaultRenderQueue);
|
||||
_renderStack.push({DEFAULT_RENDER_QUEUE, 0});
|
||||
}
|
||||
|
||||
Renderer::~Renderer()
|
||||
{
|
||||
_renderGroups.clear();
|
||||
|
||||
glDeleteBuffers(2, _buffersVBO);
|
||||
|
||||
if (Configuration::getInstance()->supportsShareableVAO())
|
||||
{
|
||||
glDeleteVertexArrays(1, &_quadVAO);
|
||||
GL::bindVAO(0);
|
||||
}
|
||||
}
|
||||
|
||||
bool Renderer::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Renderer::initGLView()
|
||||
{
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
// listen the event when app go to background
|
||||
NotificationCenter::getInstance()->addObserver(this,
|
||||
callfuncO_selector(Renderer::onBackToForeground),
|
||||
EVNET_COME_TO_FOREGROUND,
|
||||
NULL);
|
||||
#endif
|
||||
|
||||
setupIndices();
|
||||
|
||||
setupBuffer();
|
||||
|
||||
_glViewAssigned = true;
|
||||
}
|
||||
|
||||
void Renderer::onBackToForeground()
|
||||
{
|
||||
setupBuffer();
|
||||
}
|
||||
|
||||
void Renderer::setupIndices()
|
||||
{
|
||||
for( int i=0; i < VBO_SIZE; i++)
|
||||
{
|
||||
_indices[i*6+0] = (GLushort) (i*4+0);
|
||||
_indices[i*6+1] = (GLushort) (i*4+1);
|
||||
_indices[i*6+2] = (GLushort) (i*4+2);
|
||||
_indices[i*6+3] = (GLushort) (i*4+3);
|
||||
_indices[i*6+4] = (GLushort) (i*4+2);
|
||||
_indices[i*6+5] = (GLushort) (i*4+1);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::setupBuffer()
|
||||
{
|
||||
if(Configuration::getInstance()->supportsShareableVAO())
|
||||
{
|
||||
setupVBOAndVAO();
|
||||
}
|
||||
else
|
||||
{
|
||||
setupVBO();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::setupVBOAndVAO()
|
||||
{
|
||||
glGenVertexArrays(1, &_quadVAO);
|
||||
GL::bindVAO(_quadVAO);
|
||||
|
||||
glGenBuffers(2, &_buffersVBO[0]);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * VBO_SIZE, _quads, GL_DYNAMIC_DRAW);
|
||||
|
||||
// vertices
|
||||
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*) offsetof( V3F_C4B_T2F, vertices));
|
||||
|
||||
// colors
|
||||
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B_T2F), (GLvoid*) offsetof( V3F_C4B_T2F, colors));
|
||||
|
||||
// tex coords
|
||||
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORDS);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*) offsetof( V3F_C4B_T2F, texCoords));
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * VBO_SIZE * 6, _indices, GL_STATIC_DRAW);
|
||||
|
||||
// Must unbind the VAO before changing the element buffer.
|
||||
GL::bindVAO(0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
}
|
||||
|
||||
void Renderer::setupVBO()
|
||||
{
|
||||
glGenBuffers(2, &_buffersVBO[0]);
|
||||
|
||||
mapBuffers();
|
||||
}
|
||||
|
||||
void Renderer::mapBuffers()
|
||||
{
|
||||
// Avoid changing the element buffer for whatever VAO might be bound.
|
||||
GL::bindVAO(0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * VBO_SIZE, _quads, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * VBO_SIZE * 6, _indices, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
}
|
||||
|
||||
void Renderer::addCommand(RenderCommand* command)
|
||||
{
|
||||
command->generateID();
|
||||
_renderGroups[_commandGroupStack.top()].push_back(command);
|
||||
}
|
||||
|
||||
void Renderer::addCommand(RenderCommand* command, int renderQueue)
|
||||
{
|
||||
command->generateID();
|
||||
_renderGroups[renderQueue].push_back(command);
|
||||
}
|
||||
|
||||
void Renderer::pushGroup(int renderQueueID)
|
||||
{
|
||||
_commandGroupStack.push(renderQueueID);
|
||||
}
|
||||
|
||||
void Renderer::popGroup()
|
||||
{
|
||||
_commandGroupStack.pop();
|
||||
}
|
||||
|
||||
int Renderer::createRenderQueue()
|
||||
{
|
||||
RenderQueue newRenderQueue;
|
||||
_renderGroups.push_back(newRenderQueue);
|
||||
return (int)_renderGroups.size() - 1;
|
||||
}
|
||||
|
||||
bool compareRenderCommand(RenderCommand* a, RenderCommand* b)
|
||||
{
|
||||
return a->getID() < b->getID();
|
||||
}
|
||||
|
||||
void Renderer::render()
|
||||
{
|
||||
//Uncomment this once everything is rendered by new renderer
|
||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//TODO setup camera or MVP
|
||||
|
||||
if (_glViewAssigned)
|
||||
{
|
||||
//Process render commands
|
||||
//1. Sort render commands based on ID
|
||||
for (auto it = _renderGroups.begin(); it != _renderGroups.end(); ++it)
|
||||
{
|
||||
stable_sort((*it).begin(), (*it).end(), compareRenderCommand);
|
||||
}
|
||||
|
||||
while(!_renderStack.empty())
|
||||
{
|
||||
RenderQueue currRenderQueue = _renderGroups[_renderStack.top().renderQueueID];
|
||||
size_t len = currRenderQueue.size();
|
||||
|
||||
//Refresh the batch command index in case the renderStack has changed.
|
||||
_firstCommand = _lastCommand = _renderStack.top().currentIndex;
|
||||
|
||||
//Process RenderQueue
|
||||
for(size_t i = _renderStack.top().currentIndex; i < len; i++)
|
||||
{
|
||||
_renderStack.top().currentIndex = _lastCommand = i;
|
||||
auto command = currRenderQueue[i];
|
||||
|
||||
if(command->getType() == QUAD_COMMAND)
|
||||
{
|
||||
QuadCommand* cmd = static_cast<QuadCommand*>(command);
|
||||
|
||||
//Batch quads
|
||||
if(_numQuads + cmd->getQuadCount() > VBO_SIZE)
|
||||
{
|
||||
CCASSERT(cmd->getQuadCount() < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command");
|
||||
|
||||
//Draw batched quads if VBO is full
|
||||
drawBatchedQuads();
|
||||
}
|
||||
|
||||
memcpy(_quads + _numQuads, cmd->getQuad(), sizeof(V3F_C4B_T2F_Quad) * cmd->getQuadCount());
|
||||
_numQuads += cmd->getQuadCount();
|
||||
}
|
||||
else if(command->getType() == CUSTOM_COMMAND)
|
||||
{
|
||||
flush();
|
||||
CustomCommand* cmd = static_cast<CustomCommand*>(command);
|
||||
cmd->execute();
|
||||
}
|
||||
else if(command->getType() == GROUP_COMMAND)
|
||||
{
|
||||
flush();
|
||||
GroupCommand* cmd = static_cast<GroupCommand*>(command);
|
||||
|
||||
_renderStack.top().currentIndex = i + 1;
|
||||
|
||||
//push new renderQueue to renderStack
|
||||
_renderStack.push({cmd->getRenderQueueID(), 0});
|
||||
|
||||
//Exit current loop
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
//Draw the batched quads
|
||||
drawBatchedQuads();
|
||||
|
||||
currRenderQueue = _renderGroups[_renderStack.top().renderQueueID];
|
||||
len = currRenderQueue.size();
|
||||
//If pop the render stack if we already processed all the commands
|
||||
if(_renderStack.top().currentIndex + 1 >= len)
|
||||
{
|
||||
_renderStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO give command back to command pool
|
||||
for (size_t j = 0 ; j < _renderGroups.size(); j++)
|
||||
{
|
||||
for_each(_renderGroups[j].begin(), _renderGroups[j].end(), [](RenderCommand* cmd){ cmd->releaseToCommandPool(); });
|
||||
_renderGroups[j].clear();
|
||||
}
|
||||
|
||||
//Clear the stack incase gl view hasn't been initialized yet
|
||||
while(!_renderStack.empty())
|
||||
{
|
||||
_renderStack.pop();
|
||||
}
|
||||
_renderStack.push({DEFAULT_RENDER_QUEUE, 0});
|
||||
_firstCommand = _lastCommand = 0;
|
||||
_lastMaterialID = 0;
|
||||
}
|
||||
|
||||
void Renderer::drawBatchedQuads()
|
||||
{
|
||||
//TODO we can improve the draw performance by insert material switching command before hand.
|
||||
|
||||
int quadsToDraw = 0;
|
||||
int startQuad = 0;
|
||||
|
||||
//Upload buffer to VBO
|
||||
if(_numQuads <= 0)
|
||||
{
|
||||
_firstCommand = _lastCommand;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Configuration::getInstance()->supportsShareableVAO())
|
||||
{
|
||||
//Set VBO data
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * (_numQuads), NULL, GL_DYNAMIC_DRAW);
|
||||
void *buf = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||
memcpy(buf, _quads, sizeof(_quads[0])* (_numQuads));
|
||||
glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
//Bind VAO
|
||||
GL::bindVAO(_quadVAO);
|
||||
}
|
||||
else
|
||||
{
|
||||
#define kQuadSize sizeof(_quads[0].bl)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(_quads[0]) * _numQuads , _quads);
|
||||
|
||||
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
|
||||
|
||||
// vertices
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, vertices));
|
||||
|
||||
// colors
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, colors));
|
||||
|
||||
// tex coords
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, texCoords));
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
}
|
||||
|
||||
//Start drawing verties in batch
|
||||
for(size_t i = _firstCommand; i <= _lastCommand; i++)
|
||||
{
|
||||
RenderCommand* command = _renderGroups[_renderStack.top().renderQueueID][i];
|
||||
if (command->getType() == QUAD_COMMAND)
|
||||
{
|
||||
QuadCommand* cmd = static_cast<QuadCommand*>(command);
|
||||
if(_lastMaterialID != cmd->getMaterialID())
|
||||
{
|
||||
//Draw quads
|
||||
if(quadsToDraw > 0)
|
||||
{
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei) quadsToDraw*6, GL_UNSIGNED_SHORT, (GLvoid*) (startQuad*6*sizeof(_indices[0])) );
|
||||
CC_INCREMENT_GL_DRAWS(1);
|
||||
|
||||
startQuad += quadsToDraw;
|
||||
quadsToDraw = 0;
|
||||
}
|
||||
|
||||
//Use new material
|
||||
cmd->useMaterial();
|
||||
_lastMaterialID = cmd->getMaterialID();
|
||||
}
|
||||
|
||||
quadsToDraw += cmd->getQuadCount();
|
||||
}
|
||||
}
|
||||
|
||||
//Draw any remaining quad
|
||||
if(quadsToDraw > 0)
|
||||
{
|
||||
glDrawElements(GL_TRIANGLES, (GLsizei) quadsToDraw*6, GL_UNSIGNED_SHORT, (GLvoid*) (startQuad*6*sizeof(_indices[0])) );
|
||||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
if (Configuration::getInstance()->supportsShareableVAO())
|
||||
{
|
||||
//Unbind VAO
|
||||
GL::bindVAO(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
|
||||
_firstCommand = _lastCommand;
|
||||
_numQuads = 0;
|
||||
}
|
||||
|
||||
void Renderer::flush()
|
||||
{
|
||||
drawBatchedQuads();
|
||||
_lastMaterialID = 0;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,91 @@
|
|||
//
|
||||
// Created by NiTe Luo on 10/31/13.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef __CC_RENDERER_H_
|
||||
#define __CC_RENDERER_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "RenderCommand.h"
|
||||
#include "CCGLProgram.h"
|
||||
#include "CCGL.h"
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
|
||||
#define VBO_SIZE 10500
|
||||
#define DEFAULT_RENDER_QUEUE 0
|
||||
|
||||
NS_CC_BEGIN
|
||||
using namespace std;
|
||||
|
||||
typedef vector<RenderCommand*> RenderQueue;
|
||||
|
||||
struct RenderStackElement
|
||||
{
|
||||
int renderQueueID;
|
||||
size_t currentIndex;
|
||||
};
|
||||
|
||||
class Renderer : public Object
|
||||
{
|
||||
public:
|
||||
static Renderer* getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
//TODO manage GLView inside Render itself
|
||||
void initGLView();
|
||||
|
||||
//TODO support multiple viewport
|
||||
void addCommand(RenderCommand* command);
|
||||
void addCommand(RenderCommand* command, int renderQueue);
|
||||
void pushGroup(int renderQueueID);
|
||||
void popGroup();
|
||||
|
||||
int createRenderQueue();
|
||||
void render();
|
||||
|
||||
protected:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
bool init();
|
||||
|
||||
void setupIndices();
|
||||
//Setup VBO or VAO based on OpenGL extensions
|
||||
void setupBuffer();
|
||||
void setupVBOAndVAO();
|
||||
void setupVBO();
|
||||
void mapBuffers();
|
||||
|
||||
void drawBatchedQuads();
|
||||
//Draw the previews queued quads and flush previous context
|
||||
void flush();
|
||||
|
||||
void onBackToForeground();
|
||||
|
||||
protected:
|
||||
stack<int> _commandGroupStack;
|
||||
|
||||
stack<RenderStackElement> _renderStack;
|
||||
vector<RenderQueue> _renderGroups;
|
||||
|
||||
int _lastMaterialID;
|
||||
|
||||
size_t _firstCommand;
|
||||
size_t _lastCommand;
|
||||
|
||||
V3F_C4B_T2F_Quad _quads[VBO_SIZE];
|
||||
GLushort _indices[6 * VBO_SIZE];
|
||||
GLuint _quadVAO;
|
||||
GLuint _buffersVBO[2]; //0: vertex 1: indices
|
||||
|
||||
int _numQuads;
|
||||
|
||||
bool _glViewAssigned;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CC_RENDERER_H_
|
|
@ -45,6 +45,14 @@ Point __CCPointApplyAffineTransform(const Point& point, const AffineTransform& t
|
|||
return p;
|
||||
}
|
||||
|
||||
Point PointApplyTransform(const Point& point, const kmMat4& transform)
|
||||
{
|
||||
kmVec3 vec = {point.x, point.y, 0};
|
||||
kmVec3Transform(&vec, &vec, &transform);
|
||||
return Point(vec.x, vec.y);
|
||||
}
|
||||
|
||||
|
||||
Size __CCSizeApplyAffineTransform(const Size& size, const AffineTransform& t)
|
||||
{
|
||||
Size s;
|
||||
|
@ -82,6 +90,32 @@ Rect RectApplyAffineTransform(const Rect& rect, const AffineTransform& anAffineT
|
|||
return Rect(minX, minY, (maxX - minX), (maxY - minY));
|
||||
}
|
||||
|
||||
Rect RectApplyTransform(const Rect& rect, const kmMat4& transform)
|
||||
{
|
||||
float top = rect.getMinY();
|
||||
float left = rect.getMinX();
|
||||
float right = rect.getMaxX();
|
||||
float bottom = rect.getMaxY();
|
||||
|
||||
kmVec3 topLeft = {left, top};
|
||||
kmVec3 topRight = {right, top};
|
||||
kmVec3 bottomLeft = {left, bottom};
|
||||
kmVec3 bottomRight = {right, bottom};
|
||||
|
||||
kmVec3Transform(&topLeft, &topLeft, &transform);
|
||||
kmVec3Transform(&topRight, &topRight, &transform);
|
||||
kmVec3Transform(&bottomLeft, &bottomLeft, &transform);
|
||||
kmVec3Transform(&bottomRight, &bottomRight, &transform);
|
||||
|
||||
float minX = min(min(topLeft.x, topRight.x), min(bottomLeft.x, bottomRight.x));
|
||||
float maxX = max(max(topLeft.x, topRight.x), max(bottomLeft.x, bottomRight.x));
|
||||
float minY = min(min(topLeft.y, topRight.y), min(bottomLeft.y, bottomRight.y));
|
||||
float maxY = max(max(topLeft.y, topRight.y), max(bottomLeft.y, bottomRight.y));
|
||||
|
||||
return Rect(minX, minY, (maxX - minX), (maxY - minY));
|
||||
}
|
||||
|
||||
|
||||
AffineTransform AffineTransformTranslate(const AffineTransform& t, float tx, float ty)
|
||||
{
|
||||
return __CCAffineTransformMake(t.a, t.b, t.c, t.d, t.tx + t.a * tx + t.c * ty, t.ty + t.b * tx + t.d * ty);
|
||||
|
@ -115,6 +149,14 @@ AffineTransform AffineTransformConcat(const AffineTransform& t1, const AffineTra
|
|||
t1.tx * t2.b + t1.ty * t2.d + t2.ty); //ty
|
||||
}
|
||||
|
||||
kmMat4 TransformConcat(const kmMat4& t1, const kmMat4& t2)
|
||||
{
|
||||
kmMat4 ret;
|
||||
kmMat4Multiply(&ret, &t1, &t2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Return true if `t1' and `t2' are equal, false otherwise. */
|
||||
bool AffineTransformEqualToTransform(const AffineTransform& t1, const AffineTransform& t2)
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCGeometry.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "kazmath/kazmath.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -49,6 +50,9 @@ CC_DLL Size __CCSizeApplyAffineTransform(const Size& size, const AffineTransform
|
|||
CC_DLL AffineTransform AffineTransformMakeIdentity();
|
||||
CC_DLL Rect RectApplyAffineTransform(const Rect& rect, const AffineTransform& anAffineTransform);
|
||||
|
||||
CC_DLL Rect RectApplyTransform(const Rect& rect, const kmMat4& transform);
|
||||
CC_DLL Point PointApplyTransform(const Point& point, const kmMat4& transform);
|
||||
|
||||
CC_DLL AffineTransform AffineTransformTranslate(const AffineTransform& t, float tx, float ty);
|
||||
CC_DLL AffineTransform AffineTransformRotate(const AffineTransform& aTransform, float anAngle);
|
||||
CC_DLL AffineTransform AffineTransformScale(const AffineTransform& t, float sx, float sy);
|
||||
|
@ -56,6 +60,8 @@ CC_DLL AffineTransform AffineTransformConcat(const AffineTransform& t1, const Af
|
|||
CC_DLL bool AffineTransformEqualToTransform(const AffineTransform& t1, const AffineTransform& t2);
|
||||
CC_DLL AffineTransform AffineTransformInvert(const AffineTransform& t);
|
||||
|
||||
kmMat4 TransformConcat(const kmMat4& t1, const kmMat4& t2);
|
||||
|
||||
extern CC_DLL const AffineTransform AffineTransformIdentity;
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -196,11 +196,11 @@ bool __Array::initWithArray(__Array* otherArray)
|
|||
return true;
|
||||
}
|
||||
|
||||
int __Array::getIndexOfObject(Object* object) const
|
||||
ssize_t __Array::getIndexOfObject(Object* object) const
|
||||
{
|
||||
auto it = data.begin();
|
||||
|
||||
for (int i = 0; it != data.end(); ++it, ++i)
|
||||
for (ssize_t i = 0; it != data.end(); ++it, ++i)
|
||||
{
|
||||
if (it->get() == object)
|
||||
{
|
||||
|
@ -232,13 +232,13 @@ Object* __Array::getRandomObject()
|
|||
|
||||
bool __Array::containsObject(Object* object) const
|
||||
{
|
||||
auto i = this->getIndexOfObject(object);
|
||||
ssize_t i = this->getIndexOfObject(object);
|
||||
return (i >= 0);
|
||||
}
|
||||
|
||||
bool __Array::isEqualToArray(__Array* otherArray)
|
||||
{
|
||||
for (int i = 0; i < this->count(); ++i)
|
||||
for (ssize_t i = 0; i < this->count(); ++i)
|
||||
{
|
||||
if (!this->getObjectAtIndex(i)->isEqual(otherArray->getObjectAtIndex(i)))
|
||||
{
|
||||
|
@ -279,7 +279,7 @@ void __Array::removeObject(Object* object, bool releaseObj /* ignored */)
|
|||
data.erase(std::remove(data.begin(), data.end(), object));
|
||||
}
|
||||
|
||||
void __Array::removeObjectAtIndex(int index, bool releaseObj /* ignored */)
|
||||
void __Array::removeObjectAtIndex(ssize_t index, bool releaseObj /* ignored */)
|
||||
{
|
||||
auto obj = data[index];
|
||||
data.erase(data.begin() + index);
|
||||
|
@ -307,15 +307,15 @@ void __Array::fastRemoveObject(Object* object)
|
|||
|
||||
void __Array::exchangeObject(Object* object1, Object* object2)
|
||||
{
|
||||
auto idx1 = getIndexOfObject(object1);
|
||||
auto idx2 = getIndexOfObject(object2);
|
||||
ssize_t idx1 = getIndexOfObject(object1);
|
||||
ssize_t idx2 = getIndexOfObject(object2);
|
||||
|
||||
CCASSERT(idx1 >= 0 && idx2 >= 2, "invalid object index");
|
||||
|
||||
std::swap(data[idx1], data[idx2]);
|
||||
}
|
||||
|
||||
void __Array::exchangeObjectAtIndex(int index1, int index2)
|
||||
void __Array::exchangeObjectAtIndex(ssize_t index1, ssize_t index2)
|
||||
{
|
||||
std::swap(data[index1], data[index2]);
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ __Array* __Array::createWithArray(__Array* otherArray)
|
|||
return otherArray->clone();
|
||||
}
|
||||
|
||||
__Array* __Array::createWithCapacity(int capacity)
|
||||
__Array* __Array::createWithCapacity(ssize_t capacity)
|
||||
{
|
||||
CCASSERT(capacity>=0, "Invalid capacity");
|
||||
|
||||
|
@ -539,7 +539,7 @@ bool __Array::initWithObjects(Object* object, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool __Array::initWithCapacity(int capacity)
|
||||
bool __Array::initWithCapacity(ssize_t capacity)
|
||||
{
|
||||
CCASSERT(capacity>=0 && !data, "Array cannot be re-initialized");
|
||||
|
||||
|
@ -563,7 +563,7 @@ bool __Array::initWithArray(__Array* otherArray)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int __Array::getIndexOfObject(Object* object) const
|
||||
ssize_t __Array::getIndexOfObject(Object* object) const
|
||||
{
|
||||
return ccArrayGetIndexOfObject(data, object);
|
||||
}
|
||||
|
@ -614,13 +614,13 @@ void __Array::addObjectsFromArray(__Array* otherArray)
|
|||
ccArrayAppendArrayWithResize(data, otherArray->data);
|
||||
}
|
||||
|
||||
void __Array::insertObject(Object* object, int index)
|
||||
void __Array::insertObject(Object* object, ssize_t index)
|
||||
{
|
||||
CCASSERT(data, "Array not initialized");
|
||||
ccArrayInsertObjectAtIndex(data, object, index);
|
||||
}
|
||||
|
||||
void __Array::setObject(Object* object, int index)
|
||||
void __Array::setObject(Object* object, ssize_t index)
|
||||
{
|
||||
CCASSERT(index >= 0 && index < count(), "Invalid index");
|
||||
|
||||
|
@ -643,7 +643,7 @@ void __Array::removeObject(Object* object, bool releaseObj/* = true*/)
|
|||
ccArrayRemoveObject(data, object, releaseObj);
|
||||
}
|
||||
|
||||
void __Array::removeObjectAtIndex(int index, bool releaseObj)
|
||||
void __Array::removeObjectAtIndex(ssize_t index, bool releaseObj)
|
||||
{
|
||||
ccArrayRemoveObjectAtIndex(data, index, releaseObj);
|
||||
}
|
||||
|
@ -658,7 +658,7 @@ void __Array::removeAllObjects()
|
|||
ccArrayRemoveAllObjects(data);
|
||||
}
|
||||
|
||||
void __Array::fastRemoveObjectAtIndex(int index)
|
||||
void __Array::fastRemoveObjectAtIndex(ssize_t index)
|
||||
{
|
||||
ccArrayFastRemoveObjectAtIndex(data, index);
|
||||
}
|
||||
|
@ -685,12 +685,12 @@ void __Array::exchangeObject(Object* object1, Object* object2)
|
|||
ccArraySwapObjectsAtIndexes(data, index1, index2);
|
||||
}
|
||||
|
||||
void __Array::exchangeObjectAtIndex(int index1, int index2)
|
||||
void __Array::exchangeObjectAtIndex(ssize_t index1, ssize_t index2)
|
||||
{
|
||||
ccArraySwapObjectsAtIndexes(data, index1, index2);
|
||||
}
|
||||
|
||||
void __Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject/* = true*/)
|
||||
void __Array::replaceObjectAtIndex(ssize_t index, Object* object, bool releaseObject/* = true*/)
|
||||
{
|
||||
ccArrayInsertObjectAtIndex(data, object, index);
|
||||
ccArrayRemoveObjectAtIndex(data, index + 1);
|
||||
|
@ -701,10 +701,10 @@ void __Array::reverseObjects()
|
|||
if (data->num > 1)
|
||||
{
|
||||
// floorf(), since in the case of an even number, the number of swaps stays the same
|
||||
auto count = static_cast<int>(floorf(data->num/2.f));
|
||||
auto maxIndex = data->num - 1;
|
||||
auto count = static_cast<ssize_t>(floorf(data->num/2.f));
|
||||
ssize_t maxIndex = data->num - 1;
|
||||
|
||||
for (int i = 0; i < count ; ++i)
|
||||
for (ssize_t i = 0; i < count ; ++i)
|
||||
{
|
||||
ccArraySwapObjectsAtIndexes(data, i, maxIndex);
|
||||
--maxIndex;
|
||||
|
|
|
@ -250,7 +250,7 @@ public:
|
|||
/** Create an array with a default capacity
|
||||
* @js NA
|
||||
*/
|
||||
static __Array* createWithCapacity(int capacity);
|
||||
static __Array* createWithCapacity(ssize_t capacity);
|
||||
/** Create an array with from an existing array
|
||||
* @js NA
|
||||
*/
|
||||
|
@ -295,7 +295,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
bool initWithCapacity(int capacity);
|
||||
bool initWithCapacity(ssize_t capacity);
|
||||
/** Initializes an array with an existing array
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -307,7 +307,7 @@ public:
|
|||
/** Returns element count of the array
|
||||
* @js NA
|
||||
*/
|
||||
int count() const
|
||||
ssize_t count() const
|
||||
{
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
return data.size();
|
||||
|
@ -318,7 +318,7 @@ public:
|
|||
/** Returns capacity of the array
|
||||
* @js NA
|
||||
*/
|
||||
int capacity() const
|
||||
ssize_t capacity() const
|
||||
{
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
return data.capacity();
|
||||
|
@ -330,17 +330,17 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
int getIndexOfObject(Object* object) const;
|
||||
ssize_t getIndexOfObject(Object* object) const;
|
||||
/**
|
||||
* @js NA
|
||||
*/
|
||||
CC_DEPRECATED_ATTRIBUTE int indexOfObject(Object* object) const { return getIndexOfObject(object); }
|
||||
CC_DEPRECATED_ATTRIBUTE ssize_t indexOfObject(Object* object) const { return getIndexOfObject(object); }
|
||||
|
||||
/** Returns an element with a certain index
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
Object* getObjectAtIndex(int index)
|
||||
Object* getObjectAtIndex(ssize_t index)
|
||||
{
|
||||
CCASSERT(index>=0 && index < count(), "index out of range in getObjectAtIndex()");
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
|
@ -349,7 +349,7 @@ public:
|
|||
return data->arr[index];
|
||||
#endif
|
||||
}
|
||||
CC_DEPRECATED_ATTRIBUTE Object* objectAtIndex(int index) { return getObjectAtIndex(index); }
|
||||
CC_DEPRECATED_ATTRIBUTE Object* objectAtIndex(ssize_t index) { return getObjectAtIndex(index); }
|
||||
/** Returns the last element of the array
|
||||
* @js NA
|
||||
*/
|
||||
|
@ -401,17 +401,17 @@ public:
|
|||
/** Insert a certain object at a certain index
|
||||
* @js NA
|
||||
*/
|
||||
void insertObject(Object* object, int index);
|
||||
void insertObject(Object* object, ssize_t index);
|
||||
/** sets a certain object at a certain index
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void setObject(Object* object, int index);
|
||||
void setObject(Object* object, ssize_t index);
|
||||
/** sets a certain object at a certain index without retaining. Use it with caution
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void fastSetObject(Object* object, int index)
|
||||
void fastSetObject(Object* object, ssize_t index)
|
||||
{
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
setObject(object, index);
|
||||
|
@ -424,7 +424,7 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
void swap( int indexOne, int indexTwo )
|
||||
void swap( ssize_t indexOne, ssize_t indexTwo )
|
||||
{
|
||||
CCASSERT(indexOne >=0 && indexOne < count() && indexTwo >= 0 && indexTwo < count(), "Invalid indices");
|
||||
#if CC_USE_ARRAY_VECTOR
|
||||
|
@ -447,7 +447,7 @@ public:
|
|||
/** Remove an element with a certain index
|
||||
* @js NA
|
||||
*/
|
||||
void removeObjectAtIndex(int index, bool releaseObj = true);
|
||||
void removeObjectAtIndex(ssize_t index, bool releaseObj = true);
|
||||
/** Remove all elements
|
||||
* @js NA
|
||||
*/
|
||||
|
@ -463,7 +463,7 @@ public:
|
|||
/** Fast way to remove an element with a certain index
|
||||
* @js NA
|
||||
*/
|
||||
void fastRemoveObjectAtIndex(int index);
|
||||
void fastRemoveObjectAtIndex(ssize_t index);
|
||||
|
||||
// Rearranging Content
|
||||
|
||||
|
@ -474,12 +474,12 @@ public:
|
|||
/** Swap two elements with certain indexes
|
||||
* @js NA
|
||||
*/
|
||||
void exchangeObjectAtIndex(int index1, int index2);
|
||||
void exchangeObjectAtIndex(ssize_t index1, ssize_t index2);
|
||||
|
||||
/** Replace object at index with another object.
|
||||
* @js NA
|
||||
*/
|
||||
void replaceObjectAtIndex(int index, Object* object, bool releaseObject = true);
|
||||
void replaceObjectAtIndex(ssize_t index, Object* object, bool releaseObject = true);
|
||||
|
||||
/** Revers the array
|
||||
* @js NA
|
||||
|
|
|
@ -51,7 +51,7 @@ void AutoreleasePool::removeObject(Object* object)
|
|||
{
|
||||
for (unsigned int i = 0; i < object->_autoReleaseCount; ++i)
|
||||
{
|
||||
_managedObjectArray.erase(object, false);
|
||||
_managedObjectArray.eraseObject(object, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ void PoolManager::pop()
|
|||
return;
|
||||
}
|
||||
|
||||
int count = _releasePoolStack.size();
|
||||
ssize_t count = _releasePoolStack.size();
|
||||
|
||||
_curReleasePool->clear();
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public:
|
|||
}
|
||||
|
||||
/** Contructor with capacity */
|
||||
explicit Map<K, V>(int capacity)
|
||||
explicit Map<K, V>(ssize_t capacity)
|
||||
: _data()
|
||||
{
|
||||
CCLOGINFO("In the constructor with capacity of Map!");
|
||||
|
@ -99,19 +99,19 @@ public:
|
|||
}
|
||||
|
||||
/** Sets capacity of the map */
|
||||
void reserve(int capacity)
|
||||
void reserve(ssize_t capacity)
|
||||
{
|
||||
_data.reserve(capacity);
|
||||
}
|
||||
|
||||
/** Returns capacity of the map */
|
||||
size_t capacity() const
|
||||
ssize_t capacity() const
|
||||
{
|
||||
return _data.capacity();
|
||||
}
|
||||
|
||||
/** The number of elements in the map. */
|
||||
size_t size() const
|
||||
ssize_t size() const
|
||||
{
|
||||
return _data.size();
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ public:
|
|||
{
|
||||
if (!_data.empty())
|
||||
{
|
||||
int randIdx = rand() % _data.size();
|
||||
ssize_t randIdx = rand() % _data.size();
|
||||
return (_data.begin() + randIdx)->second;
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -72,7 +72,7 @@ public:
|
|||
}
|
||||
|
||||
/** Constructor with a capacity */
|
||||
explicit Vector<T>(int capacity)
|
||||
explicit Vector<T>(ssize_t capacity)
|
||||
: _data()
|
||||
{
|
||||
CCLOGINFO("In the default constructor with capacity of Vector.");
|
||||
|
@ -135,7 +135,7 @@ public:
|
|||
* If n is greater than the current vector capacity,
|
||||
* the function causes the container to reallocate its storage increasing its capacity to n (or greater).
|
||||
*/
|
||||
void reserve(int n)
|
||||
void reserve(ssize_t n)
|
||||
{
|
||||
_data.reserve(n);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ public:
|
|||
* It can be equal or greater, with the extra space allowing to accommodate for growth without the need to reallocate on each insertion.
|
||||
* @return The size of the currently allocated storage capacity in the vector, measured in terms of the number elements it can hold.
|
||||
*/
|
||||
int capacity() const
|
||||
ssize_t capacity() const
|
||||
{
|
||||
return _data.capacity();
|
||||
}
|
||||
|
@ -154,9 +154,9 @@ public:
|
|||
* @note This is the number of actual objects held in the vector, which is not necessarily equal to its storage capacity.
|
||||
* @return The number of elements in the container.
|
||||
*/
|
||||
int size() const
|
||||
ssize_t size() const
|
||||
{
|
||||
return static_cast<int>(_data.size());
|
||||
return _data.size();
|
||||
}
|
||||
|
||||
/** @brief Returns whether the vector is empty (i.e. whether its size is 0).
|
||||
|
@ -168,13 +168,13 @@ public:
|
|||
}
|
||||
|
||||
/** Returns the maximum number of elements that the vector can hold. */
|
||||
size_t max_size() const
|
||||
ssize_t max_size() const
|
||||
{
|
||||
return _data.max_size();
|
||||
}
|
||||
|
||||
/** Returns index of a certain object, return UINT_MAX if doesn't contain the object */
|
||||
int getIndex(T object) const
|
||||
ssize_t getIndex(T object) const
|
||||
{
|
||||
auto iter = std::find(_data.begin(), _data.end(), object);
|
||||
if (iter != _data.end())
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
}
|
||||
|
||||
/** Returns the element at position 'index' in the vector. */
|
||||
T at(int index) const
|
||||
T at(ssize_t index) const
|
||||
{
|
||||
CCASSERT( index >= 0 && index < size(), "index out of range in getObjectAtIndex()");
|
||||
return _data[index];
|
||||
|
@ -221,7 +221,7 @@ public:
|
|||
{
|
||||
if (!_data.empty())
|
||||
{
|
||||
int randIdx = rand() % _data.size();
|
||||
ssize_t randIdx = rand() % _data.size();
|
||||
return *(_data.begin() + randIdx);
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -236,11 +236,11 @@ public:
|
|||
/** Returns true if the two vectors are equal */
|
||||
bool equals(const Vector<T> &other)
|
||||
{
|
||||
size_t s = this->size();
|
||||
ssize_t s = this->size();
|
||||
if (s != other.size())
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < s; i++)
|
||||
for (ssize_t i = 0; i < s; i++)
|
||||
{
|
||||
if (!this->at(i)->isEqual(other.at(i)))
|
||||
{
|
||||
|
@ -279,7 +279,7 @@ public:
|
|||
* This causes an automatic reallocation of the allocated storage space
|
||||
* if -and only if- the new vector size surpasses the current vector capacity.
|
||||
*/
|
||||
void insert(int index, T object)
|
||||
void insert(ssize_t index, T object)
|
||||
{
|
||||
CCASSERT(index >= 0 && index <= size(), "Invalid index!");
|
||||
CCASSERT(object != nullptr, "The object should not be nullptr");
|
||||
|
@ -304,7 +304,7 @@ public:
|
|||
* @param object The object to be removed.
|
||||
* @param toRelease Whether to decrease the referece count of the deleted object.
|
||||
*/
|
||||
void erase(T object, bool toRelease = true)
|
||||
void eraseObject(T object, bool toRelease = true)
|
||||
{
|
||||
CCASSERT(object != nullptr, "The object should not be nullptr");
|
||||
auto iter = std::find(_data.begin(), _data.end(), object);
|
||||
|
@ -347,7 +347,7 @@ public:
|
|||
* @return An iterator pointing to the new location of the element that followed the last element erased by the function call.
|
||||
* This is the container end if the operation erased the last element in the sequence.
|
||||
*/
|
||||
iterator erase(int index)
|
||||
iterator erase(ssize_t index)
|
||||
{
|
||||
CCASSERT(!_data.empty() && index >=0 && index < size(), "Invalid index!");
|
||||
auto it = std::next( begin(), index );
|
||||
|
@ -371,8 +371,8 @@ public:
|
|||
/** Swap two elements */
|
||||
void swap(T object1, T object2)
|
||||
{
|
||||
auto idx1 = getIndex(object1);
|
||||
auto idx2 = getIndex(object2);
|
||||
ssize_t idx1 = getIndex(object1);
|
||||
ssize_t idx2 = getIndex(object2);
|
||||
|
||||
CCASSERT(idx1>=0 && idx2>=0, "invalid object index");
|
||||
|
||||
|
@ -380,7 +380,7 @@ public:
|
|||
}
|
||||
|
||||
/** Swap two elements with certain indexes */
|
||||
void swap(int index1, int index2)
|
||||
void swap(ssize_t index1, ssize_t index2)
|
||||
{
|
||||
CCASSERT(index1 >=0 && index1 < size() && index2 >= 0 && index2 < size(), "Invalid indices");
|
||||
|
||||
|
@ -388,7 +388,7 @@ public:
|
|||
}
|
||||
|
||||
/** Replace object at index with another object. */
|
||||
void replace(int index, T object)
|
||||
void replace(ssize_t index, T object)
|
||||
{
|
||||
CCASSERT(index >= 0 && index < size(), "Invalid index!");
|
||||
CCASSERT(object != nullptr, "The object should not be nullptr");
|
||||
|
|
|
@ -623,7 +623,7 @@ Object* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* chann
|
|||
|
||||
Vector<FiniteTimeAction*> actions;
|
||||
auto& keyframes = channel->getKeyframes();
|
||||
int numKeyframes = keyframes.size();
|
||||
ssize_t numKeyframes = keyframes.size();
|
||||
|
||||
for (long i = 0; i < numKeyframes; ++i)
|
||||
{
|
||||
|
@ -712,7 +712,7 @@ Object* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel)
|
|||
|
||||
Vector<FiniteTimeAction*> actions;
|
||||
auto& keyframes = channel->getKeyframes();
|
||||
int numKeyframes = keyframes.size();
|
||||
ssize_t numKeyframes = keyframes.size();
|
||||
|
||||
for (int i = 0; i < numKeyframes; ++i)
|
||||
{
|
||||
|
@ -753,7 +753,7 @@ Object* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel)
|
|||
void CCBAnimationManager::runAction(Node *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration)
|
||||
{
|
||||
auto& keyframes = pSeqProp->getKeyframes();
|
||||
int numKeyframes = keyframes.size();
|
||||
ssize_t numKeyframes = keyframes.size();
|
||||
|
||||
if (numKeyframes > 1)
|
||||
{
|
||||
|
@ -768,7 +768,7 @@ void CCBAnimationManager::runAction(Node *pNode, CCBSequenceProperty *pSeqProp,
|
|||
actions.pushBack(DelayTime::create(timeFirst));
|
||||
}
|
||||
|
||||
for (int i = 0; i < numKeyframes - 1; ++i)
|
||||
for (ssize_t i = 0; i < numKeyframes - 1; ++i)
|
||||
{
|
||||
CCBKeyframe *kf0 = keyframes.at(i);
|
||||
CCBKeyframe *kf1 = keyframes.at(i+1);
|
||||
|
|
|
@ -970,9 +970,9 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
|
|||
if (!ownerCallbackNames.empty() && !ownerCallbackNodes.empty())
|
||||
{
|
||||
CCASSERT(ownerCallbackNames.size() == ownerCallbackNodes.size(), "");
|
||||
int nCount = ownerCallbackNames.size();
|
||||
ssize_t nCount = ownerCallbackNames.size();
|
||||
|
||||
for (int i = 0 ; i < nCount; i++)
|
||||
for (ssize_t i = 0 ; i < nCount; i++)
|
||||
{
|
||||
pCCBReader->addOwnerCallbackName(ownerCallbackNames[i].asString());
|
||||
pCCBReader->addOwnerCallbackNode(ownerCallbackNodes.at(i));
|
||||
|
@ -984,9 +984,9 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
|
|||
if (!ownerOutletNames.empty() && !ownerOutletNodes.empty())
|
||||
{
|
||||
CCASSERT(ownerOutletNames.size() == ownerOutletNodes.size(), "");
|
||||
int nCount = ownerOutletNames.size();
|
||||
ssize_t nCount = ownerOutletNames.size();
|
||||
|
||||
for (int i = 0 ; i < nCount; i++)
|
||||
for (ssize_t i = 0 ; i < nCount; i++)
|
||||
{
|
||||
pCCBReader->addOwnerOutletName(ownerOutletNames.at(i).asString());
|
||||
pCCBReader->addOwnerOutletNode(ownerOutletNodes.at(i));
|
||||
|
|
|
@ -28,6 +28,9 @@ THE SOFTWARE.
|
|||
#include "cocostudio/CCDataReaderHelper.h"
|
||||
#include "cocostudio/CCDatas.h"
|
||||
#include "cocostudio/CCSkin.h"
|
||||
#include "QuadCommand.h"
|
||||
#include "Renderer.h"
|
||||
#include "GroupCommand.h"
|
||||
|
||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||
#include "Box2D/Box2D.h"
|
||||
|
@ -80,7 +83,6 @@ Armature *Armature::create(const char *name, Bone *parentBone)
|
|||
Armature::Armature()
|
||||
: _armatureData(nullptr)
|
||||
, _batchNode(nullptr)
|
||||
, _atlas(nullptr)
|
||||
, _parentBone(nullptr)
|
||||
, _armatureTransformDirty(true)
|
||||
, _animation(nullptr)
|
||||
|
@ -92,7 +94,6 @@ Armature::~Armature(void)
|
|||
{
|
||||
_boneDic.clear();
|
||||
_topBoneList.clear();
|
||||
_textureAtlasDic.clear();
|
||||
|
||||
CC_SAFE_DELETE(_animation);
|
||||
}
|
||||
|
@ -117,7 +118,6 @@ bool Armature::init(const char *name)
|
|||
|
||||
_boneDic.clear();
|
||||
_topBoneList.clear();
|
||||
_textureAtlasDic.clear();
|
||||
|
||||
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
||||
|
||||
|
@ -271,7 +271,7 @@ void Armature::removeBone(Bone *bone, bool recursion)
|
|||
|
||||
if (_topBoneList.contains(bone))
|
||||
{
|
||||
_topBoneList.erase(bone);
|
||||
_topBoneList.eraseObject(bone);
|
||||
}
|
||||
_boneDic.erase(bone->getName());
|
||||
removeChild(bone, true);
|
||||
|
@ -290,7 +290,7 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName)
|
|||
|
||||
if(bone->getParentBone())
|
||||
{
|
||||
bone->getParentBone()->getChildren().erase(bone);
|
||||
bone->getParentBone()->getChildren().eraseObject(bone);
|
||||
bone->setParentBone(nullptr);
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName)
|
|||
boneParent->addChildBone(bone);
|
||||
if (_topBoneList.contains(bone))
|
||||
{
|
||||
_topBoneList.erase(bone);
|
||||
_topBoneList.eraseObject(bone);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -318,7 +318,7 @@ const cocos2d::Map<std::string, Bone*>& Armature::getBoneDic() const
|
|||
return _boneDic;
|
||||
}
|
||||
|
||||
const AffineTransform& Armature::getNodeToParentTransform() const
|
||||
const kmMat4& Armature::getNodeToParentTransform() const
|
||||
{
|
||||
if (_transformDirty)
|
||||
{
|
||||
|
@ -366,29 +366,33 @@ const AffineTransform& Armature::getNodeToParentTransform() const
|
|||
|
||||
// Build Transform Matrix
|
||||
// Adjusted transform calculation for rotational skew
|
||||
_transform = AffineTransformMake( cy * _scaleX, sy * _scaleX,
|
||||
-sx * _scaleY, cx * _scaleY,
|
||||
x, y );
|
||||
_transform = { cy * _scaleX, sy * _scaleX, 0, 0,
|
||||
-sx * _scaleY, cx * _scaleY, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
x, y, 0, 1 };
|
||||
|
||||
// XXX: Try to inline skew
|
||||
// If skew is needed, apply skew and then anchor point
|
||||
if (needsSkewMatrix)
|
||||
{
|
||||
AffineTransform skewMatrix = AffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(_skewY)),
|
||||
tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1.0f,
|
||||
0.0f, 0.0f );
|
||||
_transform = AffineTransformConcat(skewMatrix, _transform);
|
||||
kmMat4 skewMatrix = { 1, tanf(CC_DEGREES_TO_RADIANS(_skewY)), 0, 0,
|
||||
tanf(CC_DEGREES_TO_RADIANS(_skewX)),1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1};
|
||||
_transform = TransformConcat(skewMatrix, _transform);
|
||||
|
||||
// adjust anchor point
|
||||
if (!_anchorPointInPoints.equals(Point::ZERO))
|
||||
{
|
||||
_transform = AffineTransformTranslate(_transform, -_anchorPointInPoints.x, -_anchorPointInPoints.y);
|
||||
// XXX: Argh, kmMat needs a "translate" method
|
||||
_transform.mat[12] += -_anchorPointInPoints.x;
|
||||
_transform.mat[13] += -_anchorPointInPoints.y;
|
||||
}
|
||||
}
|
||||
|
||||
if (_additionalTransformDirty)
|
||||
{
|
||||
_transform = AffineTransformConcat(_transform, _additionalTransform);
|
||||
_transform = TransformConcat(_transform, _additionalTransform);
|
||||
_additionalTransformDirty = false;
|
||||
}
|
||||
|
||||
|
@ -442,9 +446,9 @@ void Armature::draw()
|
|||
if (_parentBone == nullptr && _batchNode == nullptr)
|
||||
{
|
||||
CC_NODE_DRAW_SETUP();
|
||||
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||
}
|
||||
|
||||
|
||||
for (auto object : _children)
|
||||
{
|
||||
if (Bone *bone = dynamic_cast<Bone *>(object))
|
||||
|
@ -459,88 +463,36 @@ void Armature::draw()
|
|||
case CS_DISPLAY_SPRITE:
|
||||
{
|
||||
Skin *skin = static_cast<Skin *>(node);
|
||||
|
||||
TextureAtlas *textureAtlas = skin->getTextureAtlas();
|
||||
bool blendDirty = bone->isBlendDirty();
|
||||
if(_atlas != textureAtlas || blendDirty)
|
||||
{
|
||||
if (_atlas)
|
||||
{
|
||||
_atlas->drawQuads();
|
||||
_atlas->removeAllQuads();
|
||||
}
|
||||
}
|
||||
|
||||
_atlas = textureAtlas;
|
||||
if (_atlas->getCapacity() == _atlas->getTotalQuads() && !_atlas->resizeCapacity(_atlas->getCapacity() * 2))
|
||||
return;
|
||||
|
||||
skin->updateTransform();
|
||||
|
||||
bool blendDirty = bone->isBlendDirty();
|
||||
|
||||
if (blendDirty)
|
||||
{
|
||||
ccBlendFunc func = bone->getBlendFunc();
|
||||
ccGLBlendFunc(func.src, func.dst);
|
||||
|
||||
_atlas->drawQuads();
|
||||
_atlas->removeAllQuads();
|
||||
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||
|
||||
bone->setBlendDirty(false);
|
||||
skin->setBlendFunc(bone->getBlendFunc());
|
||||
}
|
||||
skin->draw();
|
||||
}
|
||||
break;
|
||||
case CS_DISPLAY_ARMATURE:
|
||||
{
|
||||
Armature *armature = static_cast<Armature *>(node);
|
||||
|
||||
TextureAtlas *textureAtlas = armature->getTextureAtlas();
|
||||
if(_atlas != textureAtlas)
|
||||
{
|
||||
if (_atlas)
|
||||
{
|
||||
_atlas->drawQuads();
|
||||
_atlas->removeAllQuads();
|
||||
}
|
||||
}
|
||||
armature->draw();
|
||||
_atlas = armature->getTextureAtlas();
|
||||
node->draw();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (_atlas)
|
||||
{
|
||||
_atlas->drawQuads();
|
||||
_atlas->removeAllQuads();
|
||||
}
|
||||
node->visit();
|
||||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(Node *node = dynamic_cast<Node *>(object))
|
||||
{
|
||||
if (_atlas)
|
||||
{
|
||||
_atlas->drawQuads();
|
||||
_atlas->removeAllQuads();
|
||||
}
|
||||
node->visit();
|
||||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||
}
|
||||
}
|
||||
|
||||
if(_atlas && !_batchNode && _parentBone == nullptr)
|
||||
{
|
||||
_atlas->drawQuads();
|
||||
_atlas->removeAllQuads();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -608,7 +560,7 @@ Rect Armature::getBoundingBox() const
|
|||
}
|
||||
}
|
||||
|
||||
return RectApplyAffineTransform(boundingBox, getNodeToParentTransform());
|
||||
return RectApplyTransform(boundingBox, getNodeToParentTransform());
|
||||
}
|
||||
|
||||
Bone *Armature::getBoneAtPoint(float x, float y) const
|
||||
|
@ -627,27 +579,6 @@ Bone *Armature::getBoneAtPoint(float x, float y) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
TextureAtlas *Armature::getTexureAtlasWithTexture(Texture2D *texture)
|
||||
{
|
||||
int key = texture->getName();
|
||||
|
||||
if (_parentBone && _parentBone->getArmature())
|
||||
{
|
||||
return _parentBone->getArmature()->getTexureAtlasWithTexture(texture);
|
||||
}
|
||||
else if (_batchNode)
|
||||
{
|
||||
_batchNode->getTexureAtlasWithTexture(texture);
|
||||
}
|
||||
|
||||
TextureAtlas *atlas = static_cast<TextureAtlas *>(_textureAtlasDic.at(key));
|
||||
if (atlas == nullptr)
|
||||
{
|
||||
atlas = TextureAtlas::createWithTexture(texture, 4);
|
||||
_textureAtlasDic.insert(key, atlas);
|
||||
}
|
||||
return atlas;
|
||||
}
|
||||
|
||||
void Armature::setParentBone(Bone *parentBone)
|
||||
{
|
||||
|
|
|
@ -161,7 +161,7 @@ public:
|
|||
virtual void update(float dt) override;
|
||||
virtual void draw() override;
|
||||
|
||||
virtual const cocos2d::AffineTransform& getNodeToParentTransform() const override;
|
||||
virtual const kmMat4& getNodeToParentTransform() const override;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
|
@ -184,7 +184,6 @@ public:
|
|||
|
||||
virtual bool getArmatureTransformDirty() const;
|
||||
|
||||
virtual cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture);
|
||||
|
||||
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||
virtual void setColliderFilter(ColliderFilter *filter);
|
||||
|
@ -196,14 +195,9 @@ public:
|
|||
virtual void setArmatureData(ArmatureData *armatureData) { _armatureData = armatureData; }
|
||||
virtual ArmatureData *getArmatureData() const { return _armatureData; }
|
||||
|
||||
virtual void setBatchNode(BatchNode *batchNode) { _batchNode = batchNode; }
|
||||
virtual BatchNode *getBatchNode() const { return _batchNode; }
|
||||
|
||||
virtual void setName(const std::string &name) { _name = name; }
|
||||
virtual const std::string &getName() const { return _name; }
|
||||
|
||||
virtual void setTextureAtlas(cocos2d::TextureAtlas *atlas) { _atlas = atlas; }
|
||||
virtual cocos2d::TextureAtlas *getTextureAtlas() const { return _atlas; }
|
||||
|
||||
virtual void setParentBone(Bone *parentBone);
|
||||
virtual Bone *getParentBone() const;
|
||||
|
@ -211,6 +205,9 @@ public:
|
|||
virtual void setVersion(float version) { _version = version; }
|
||||
virtual float getVersion() const { return _version; }
|
||||
|
||||
virtual void setBatchNode(BatchNode *batchNode) { _batchNode = batchNode; }
|
||||
virtual BatchNode *getBatchNode() const { return _batchNode; }
|
||||
|
||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||
virtual b2Fixture *getShapeList();
|
||||
/**
|
||||
|
@ -252,9 +249,10 @@ protected:
|
|||
|
||||
protected:
|
||||
ArmatureData *_armatureData;
|
||||
|
||||
BatchNode *_batchNode;
|
||||
|
||||
std::string _name;
|
||||
cocos2d::TextureAtlas *_atlas;
|
||||
Bone *_parentBone;
|
||||
float _version;
|
||||
|
||||
|
@ -270,8 +268,6 @@ protected:
|
|||
|
||||
ArmatureAnimation *_animation;
|
||||
|
||||
cocos2d::Map<GLuint, cocos2d::TextureAtlas*> _textureAtlasDic;
|
||||
|
||||
#if ENABLE_PHYSICS_BOX2D_DETECT
|
||||
b2Body *_body;
|
||||
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
|
||||
|
|
|
@ -26,6 +26,8 @@ THE SOFTWARE.
|
|||
#include "cocostudio/CCArmatureDefine.h"
|
||||
#include "cocostudio/CCArmature.h"
|
||||
#include "cocostudio/CCSkin.h"
|
||||
#include "Renderer.h"
|
||||
#include "GroupCommand.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
|
@ -44,14 +46,11 @@ BatchNode *BatchNode::create()
|
|||
}
|
||||
|
||||
BatchNode::BatchNode()
|
||||
: _atlas(nullptr)
|
||||
, _textureAtlasDic(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
BatchNode::~BatchNode()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_textureAtlasDic);
|
||||
}
|
||||
|
||||
bool BatchNode::init()
|
||||
|
@ -59,9 +58,6 @@ bool BatchNode::init()
|
|||
bool ret = Node::init();
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
||||
|
||||
CC_SAFE_DELETE(_textureAtlasDic);
|
||||
_textureAtlasDic = new Dictionary();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -82,23 +78,6 @@ void BatchNode::addChild(Node *child, int zOrder, int tag)
|
|||
if (armature != nullptr)
|
||||
{
|
||||
armature->setBatchNode(this);
|
||||
|
||||
const Map<std::string, Bone*>& map = armature->getBoneDic();
|
||||
for(auto element : map)
|
||||
{
|
||||
Bone *bone = element.second;
|
||||
|
||||
Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
||||
for(auto object : *displayList)
|
||||
{
|
||||
DecorativeDisplay *display = static_cast<DecorativeDisplay*>(object);
|
||||
|
||||
if (Skin *skin = dynamic_cast<Skin*>(display->getDisplay()))
|
||||
{
|
||||
skin->setTextureAtlas(getTexureAtlasWithTexture(skin->getTexture()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,23 +87,6 @@ void BatchNode::removeChild(Node* child, bool cleanup)
|
|||
if (armature != nullptr)
|
||||
{
|
||||
armature->setBatchNode(nullptr);
|
||||
|
||||
const Map<std::string, Bone*>& map = armature->getBoneDic();
|
||||
for(auto element : map)
|
||||
{
|
||||
Bone *bone = element.second;
|
||||
|
||||
Array *displayList = bone->getDisplayManager()->getDecorativeDisplayList();
|
||||
for(auto object : *displayList)
|
||||
{
|
||||
DecorativeDisplay *display = static_cast<DecorativeDisplay*>(object);
|
||||
|
||||
if (Skin *skin = dynamic_cast<Skin*>(display->getDisplay()))
|
||||
{
|
||||
skin->setTextureAtlas(armature->getTexureAtlasWithTexture(skin->getTexture()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Node::removeChild(child, cleanup);
|
||||
|
@ -168,38 +130,40 @@ void BatchNode::draw()
|
|||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
generateGroupCommand();
|
||||
|
||||
for(auto object : _children)
|
||||
{
|
||||
Armature *armature = dynamic_cast<Armature *>(object);
|
||||
if (armature)
|
||||
{
|
||||
if (_popGroupCommand)
|
||||
{
|
||||
generateGroupCommand();
|
||||
}
|
||||
|
||||
armature->visit();
|
||||
_atlas = armature->getTextureAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
Renderer::getInstance()->popGroup();
|
||||
_popGroupCommand = true;
|
||||
|
||||
((Node *)object)->visit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_atlas)
|
||||
void BatchNode::generateGroupCommand()
|
||||
{
|
||||
_atlas->drawQuads();
|
||||
_atlas->removeAllQuads();
|
||||
}
|
||||
}
|
||||
Renderer* renderer = Renderer::getInstance();
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0,_vertexZ);
|
||||
renderer->addCommand(groupCommand);
|
||||
|
||||
TextureAtlas *BatchNode::getTexureAtlasWithTexture(Texture2D *texture) const
|
||||
{
|
||||
int key = texture->getName();
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
|
||||
TextureAtlas *atlas = static_cast<TextureAtlas *>(_textureAtlasDic->objectForKey(key));
|
||||
if (atlas == nullptr)
|
||||
{
|
||||
atlas = CCTextureAtlas::createWithTexture(texture, 4);
|
||||
_textureAtlasDic->setObject(atlas, key);
|
||||
}
|
||||
return atlas;
|
||||
_popGroupCommand = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,10 +61,11 @@ public:
|
|||
*/
|
||||
void draw() override;
|
||||
|
||||
virtual cocos2d::TextureAtlas *getTexureAtlasWithTexture(cocos2d::Texture2D *texture) const;
|
||||
void setPopGroupCommand(bool pop) { _popGroupCommand = pop; }
|
||||
protected:
|
||||
cocos2d::TextureAtlas *_atlas;
|
||||
cocos2d::Dictionary *_textureAtlasDic;
|
||||
void generateGroupCommand();
|
||||
|
||||
bool _popGroupCommand;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -71,7 +71,8 @@ Bone::Bone()
|
|||
_tween = nullptr;
|
||||
_displayManager = nullptr;
|
||||
_ignoreMovementBoneData = false;
|
||||
_worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0);
|
||||
// _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0);
|
||||
kmMat4Identity(&_worldTransform);
|
||||
_boneTransformDirty = true;
|
||||
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
||||
_blendDirty = false;
|
||||
|
@ -222,7 +223,7 @@ void Bone::update(float delta)
|
|||
|
||||
if (_armatureParentBone)
|
||||
{
|
||||
_worldTransform = AffineTransformConcat(_worldTransform, _armature->getNodeToParentTransform());
|
||||
_worldTransform = TransformConcat(_worldTransform, _armature->getNodeToParentTransform());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,8 +241,8 @@ void Bone::applyParentTransform(Bone *parent)
|
|||
{
|
||||
float x = _worldInfo->x;
|
||||
float y = _worldInfo->y;
|
||||
_worldInfo->x = x * parent->_worldTransform.a + y * parent->_worldTransform.c + parent->_worldInfo->x;
|
||||
_worldInfo->y = x * parent->_worldTransform.b + y * parent->_worldTransform.d + parent->_worldInfo->y;
|
||||
_worldInfo->x = x * parent->_worldTransform.mat[0] + y * parent->_worldTransform.mat[4] + parent->_worldInfo->x;
|
||||
_worldInfo->y = x * parent->_worldTransform.mat[1] + y * parent->_worldTransform.mat[5] + parent->_worldInfo->y;
|
||||
_worldInfo->scaleX = _worldInfo->scaleX * parent->_worldInfo->scaleX;
|
||||
_worldInfo->scaleY = _worldInfo->scaleY * parent->_worldInfo->scaleY;
|
||||
_worldInfo->skewX = _worldInfo->skewX + parent->_worldInfo->skewX;
|
||||
|
@ -344,7 +345,7 @@ void Bone::removeChildBone(Bone *bone, bool recursion)
|
|||
|
||||
bone->getDisplayManager()->setCurrentDecorativeDisplay(nullptr);
|
||||
|
||||
_children.erase(bone);
|
||||
_children.eraseObject(bone);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,14 +398,14 @@ void Bone::setZOrder(int zOrder)
|
|||
Node::setZOrder(zOrder);
|
||||
}
|
||||
|
||||
AffineTransform Bone::getNodeToArmatureTransform() const
|
||||
kmMat4 Bone::getNodeToArmatureTransform() const
|
||||
{
|
||||
return _worldTransform;
|
||||
}
|
||||
|
||||
AffineTransform Bone::getNodeToWorldTransform() const
|
||||
kmMat4 Bone::getNodeToWorldTransform() const
|
||||
{
|
||||
return AffineTransformConcat(_worldTransform, _armature->getNodeToWorldTransform());
|
||||
return TransformConcat(_worldTransform, _armature->getNodeToWorldTransform());
|
||||
}
|
||||
|
||||
Node *Bone::getDisplayRenderNode()
|
||||
|
|
|
@ -153,8 +153,8 @@ public:
|
|||
virtual void setTransformDirty(bool dirty) { _boneTransformDirty = dirty; }
|
||||
virtual bool isTransformDirty() { return _boneTransformDirty; }
|
||||
|
||||
virtual cocos2d::AffineTransform getNodeToArmatureTransform() const;
|
||||
virtual cocos2d::AffineTransform getNodeToWorldTransform() const override;
|
||||
virtual kmMat4 getNodeToArmatureTransform() const;
|
||||
virtual kmMat4 getNodeToWorldTransform() const override;
|
||||
|
||||
Node *getDisplayRenderNode();
|
||||
DisplayType getDisplayRenderNodeType();
|
||||
|
@ -247,7 +247,7 @@ protected:
|
|||
bool _boneTransformDirty; //! Whether or not transform dirty
|
||||
|
||||
//! self Transform, use this to change display's state
|
||||
cocos2d::AffineTransform _worldTransform;
|
||||
kmMat4 _worldTransform;
|
||||
|
||||
BaseData *_worldInfo;
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ void ColliderDetector::removeContourData(ContourData *contourData)
|
|||
ColliderBody *body = (ColliderBody*)object;
|
||||
if (body && body->getContourData() == contourData)
|
||||
{
|
||||
_colliderBodyList.erase(body);
|
||||
_colliderBodyList.eraseObject(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ ColliderFilter *ColliderDetector::getColliderFilter()
|
|||
|
||||
Point helpPoint;
|
||||
|
||||
void ColliderDetector::updateTransform(AffineTransform &t)
|
||||
void ColliderDetector::updateTransform(kmMat4 &t)
|
||||
{
|
||||
if (!_active)
|
||||
{
|
||||
|
@ -364,7 +364,7 @@ void ColliderDetector::updateTransform(AffineTransform &t)
|
|||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
helpPoint.setPoint( vs.at(i).x, vs.at(i).y);
|
||||
helpPoint = PointApplyAffineTransform(helpPoint, t);
|
||||
helpPoint = PointApplyTransform(helpPoint, t);
|
||||
|
||||
|
||||
#if ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
|
||||
|
|
|
@ -155,7 +155,7 @@ public:
|
|||
void removeContourData(ContourData *contourData);
|
||||
void removeAll();
|
||||
|
||||
void updateTransform(cocos2d::AffineTransform &t);
|
||||
void updateTransform(kmMat4 &t);
|
||||
|
||||
void setActive(bool active);
|
||||
bool getActive();
|
||||
|
|
|
@ -110,12 +110,12 @@ void DisplayFactory::updateDisplay(Bone *bone, float dt, bool dirty)
|
|||
CC_BREAK_IF(!detector->getBody());
|
||||
#endif
|
||||
|
||||
AffineTransform displayTransform = display->getNodeToParentTransform();
|
||||
kmMat4 displayTransform = display->getNodeToParentTransform();
|
||||
Point anchorPoint = display->getAnchorPointInPoints();
|
||||
anchorPoint = PointApplyAffineTransform(anchorPoint, displayTransform);
|
||||
displayTransform.tx = anchorPoint.x;
|
||||
displayTransform.ty = anchorPoint.y;
|
||||
AffineTransform t = AffineTransformConcat(displayTransform, bone->getArmature()->getNodeToParentTransform());
|
||||
anchorPoint = PointApplyTransform(anchorPoint, displayTransform);
|
||||
displayTransform.mat[12] = anchorPoint.x;
|
||||
displayTransform.mat[13] = anchorPoint.y;
|
||||
kmMat4 t = TransformConcat(displayTransform, bone->getArmature()->getNodeToParentTransform());
|
||||
detector->updateTransform(t);
|
||||
}
|
||||
while (0);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue