mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into developConversion
This commit is contained in:
commit
f5f95399fd
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.
|
||||
|
|
|
@ -143,6 +143,7 @@ include_directories(
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/cocos
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/audio/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/2d
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/2d/renderer
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/2d/platform
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/base
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/physics
|
||||
|
@ -152,6 +153,7 @@ include_directories(
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/external
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/unzip
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/edtaa3func
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/include/chipmunk
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cocos/2d/platform/${PLATFORM_FOLDER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER}
|
||||
|
|
|
@ -1 +1 @@
|
|||
77ef9ee3921db604edd06a2cc0b9f9a89259a431
|
||||
4691fe42345db3f1c43fc39d5517fd5115fe0520
|
|
@ -1 +1 @@
|
|||
133130a8ae8d6597399a7de05ba9b63ee55f5e2d
|
||||
52a991e88e049cd371a153ee168260276a7ac664
|
|
@ -117,10 +117,27 @@ platform/CCEGLViewProtocol.cpp \
|
|||
platform/CCFileUtils.cpp \
|
||||
platform/CCSAXParser.cpp \
|
||||
platform/CCThread.cpp \
|
||||
renderer/CCNewDrawNode.cpp \
|
||||
renderer/CCNewLabelAtlas.cpp \
|
||||
renderer/CCNewParticleSystemQuad.cpp \
|
||||
renderer/CCNewRenderTexture.cpp \
|
||||
renderer/CCNewSprite.cpp \
|
||||
renderer/CCNewSpriteBatchNode.cpp \
|
||||
renderer/CCNewTextureAtlas.cpp \
|
||||
renderer/CCCustomCommand.cpp \
|
||||
renderer/CCFrustum.cpp \
|
||||
renderer/CCGroupCommand.cpp \
|
||||
renderer/CCMaterialManager.cpp \
|
||||
renderer/CCNewClippingNode.cpp \
|
||||
renderer/CCQuadCommand.cpp \
|
||||
renderer/CCRenderCommand.cpp \
|
||||
renderer/CCRenderer.cpp \
|
||||
renderer/CCRenderMaterial.cpp \
|
||||
../base/atitc.cpp \
|
||||
../base/CCAffineTransform.cpp \
|
||||
../base/CCArray.cpp \
|
||||
../base/CCAutoreleasePool.cpp \
|
||||
../base/CCConsole.cpp \
|
||||
../base/CCData.cpp \
|
||||
../base/CCDataVisitor.cpp \
|
||||
../base/CCDictionary.cpp \
|
||||
|
@ -132,7 +149,6 @@ platform/CCThread.cpp \
|
|||
../base/CCValue.cpp \
|
||||
../base/etc1.cpp \
|
||||
../base/s3tc.cpp \
|
||||
../base/CCConsole.cpp \
|
||||
../math/kazmath/src/aabb.c \
|
||||
../math/kazmath/src/mat3.c \
|
||||
../math/kazmath/src/mat4.c \
|
||||
|
@ -158,10 +174,12 @@ platform/CCThread.cpp \
|
|||
../physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp \
|
||||
../../external/tinyxml2/tinyxml2.cpp \
|
||||
../../external/unzip/ioapi.cpp \
|
||||
../../external/unzip/unzip.cpp
|
||||
../../external/unzip/unzip.cpp \
|
||||
../../external/edtaa3func/edtaa3func.cpp
|
||||
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
|
||||
$(LOCAL_PATH)/renderer \
|
||||
$(LOCAL_PATH)/../math/kazmath/include \
|
||||
platform/android \
|
||||
$(LOCAL_PATH)/../physics \
|
||||
|
@ -171,13 +189,15 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
|
|||
$(LOCAL_PATH)/../../external/chipmunk/include/chipmunk
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
|
||||
$(LOCAL_PATH)/renderer \
|
||||
$(LOCAL_PATH)/../math/kazmath/include \
|
||||
$(LOCAL_PATH)/platform/android \
|
||||
$(LOCAL_PATH)/../physics \
|
||||
$(LOCAL_PATH)/../base \
|
||||
$(LOCAL_PATH)/../../external/tinyxml2 \
|
||||
$(LOCAL_PATH)/../../external/unzip \
|
||||
$(LOCAL_PATH)/../../external/chipmunk/include/chipmunk
|
||||
$(LOCAL_PATH)/../../external/chipmunk/include/chipmunk \
|
||||
$(LOCAL_PATH)/../../external/edtaa3func
|
||||
|
||||
|
||||
LOCAL_LDLIBS := -lGLESv2 \
|
||||
|
|
|
@ -158,7 +158,7 @@ Vector<Node*> ActionManager::pauseAllRunningActions()
|
|||
|
||||
void ActionManager::resumeTargets(const Vector<Node*>& targetsToResume)
|
||||
{
|
||||
targetsToResume.forEach([this](Node* node){
|
||||
std::for_each(targetsToResume.begin(), targetsToResume.end(), [this](Node* node){
|
||||
this->resumeTarget(node);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ static void setProgram(Node *n, GLProgram *p)
|
|||
{
|
||||
n->setShaderProgram(p);
|
||||
|
||||
n->getChildren().forEach([p](Node* child){
|
||||
auto& children = n->getChildren();
|
||||
std::for_each(children.begin(), children.end(), [p](Node* child){
|
||||
setProgram(child, p);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 "CCRenderer.h"
|
||||
#include "renderer/CCFrustum.h"
|
||||
/**
|
||||
Position of the FPS
|
||||
|
||||
|
@ -134,7 +135,9 @@ bool Director::init(void)
|
|||
_winSizeInPoints = Size::ZERO;
|
||||
|
||||
_openGLView = nullptr;
|
||||
|
||||
|
||||
_cullingFrustum = new Frustum();
|
||||
|
||||
_contentScaleFactor = 1.0f;
|
||||
|
||||
// scheduler
|
||||
|
@ -146,7 +149,10 @@ bool Director::init(void)
|
|||
_eventDispatcher = new EventDispatcher();
|
||||
//init TextureCache
|
||||
initTextureCache();
|
||||
|
||||
|
||||
// Renderer
|
||||
_renderer = new Renderer;
|
||||
|
||||
// create autorelease pool
|
||||
PoolManager::sharedPoolManager()->push();
|
||||
|
||||
|
@ -166,7 +172,9 @@ Director::~Director(void)
|
|||
CC_SAFE_RELEASE(_scheduler);
|
||||
CC_SAFE_RELEASE(_actionManager);
|
||||
CC_SAFE_RELEASE(_eventDispatcher);
|
||||
|
||||
|
||||
delete _renderer;
|
||||
|
||||
// pop the autorelease pool
|
||||
PoolManager::sharedPoolManager()->pop();
|
||||
PoolManager::purgePoolManager();
|
||||
|
@ -257,7 +265,17 @@ 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 +293,8 @@ void Director::drawScene()
|
|||
showStats();
|
||||
}
|
||||
|
||||
_renderer->render();
|
||||
|
||||
kmGLPopMatrix();
|
||||
|
||||
_totalFrames++;
|
||||
|
@ -353,6 +373,8 @@ void Director::setOpenGLView(EGLView *openGLView)
|
|||
setGLDefaultValues();
|
||||
}
|
||||
|
||||
_renderer->initGLView();
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// _touchDispatcher->setDispatchEvents(true);
|
||||
|
@ -706,6 +728,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 +929,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);
|
||||
|
@ -1009,6 +1032,12 @@ void Director::setEventDispatcher(EventDispatcher* dispatcher)
|
|||
}
|
||||
}
|
||||
|
||||
Renderer* Director::getRenderer() const
|
||||
{
|
||||
return _renderer;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************
|
||||
* implementation of DisplayLinkDirector
|
||||
**************************************************/
|
||||
|
|
|
@ -55,6 +55,8 @@ class Scheduler;
|
|||
class ActionManager;
|
||||
class EventDispatcher;
|
||||
class TextureCache;
|
||||
class Frustum;
|
||||
class Renderer;
|
||||
|
||||
/**
|
||||
@brief Class that creates and handles the main Window and manages how
|
||||
|
@ -330,8 +332,13 @@ 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
|
||||
*/
|
||||
|
@ -361,7 +368,12 @@ public:
|
|||
@since v3.0
|
||||
*/
|
||||
void setEventDispatcher(EventDispatcher* dispatcher);
|
||||
|
||||
|
||||
/** Returns the Renderer
|
||||
@since v3.0
|
||||
*/
|
||||
Renderer* getRenderer() const;
|
||||
|
||||
/* Gets delta time since last tick to main loop */
|
||||
float getDeltaTime() const;
|
||||
|
||||
|
@ -388,16 +400,15 @@ protected:
|
|||
void initTextureCache();
|
||||
void destroyTextureCache();
|
||||
|
||||
protected:
|
||||
/** Scheduler associated with this director
|
||||
@since v2.0
|
||||
*/
|
||||
Scheduler* _scheduler;
|
||||
Scheduler *_scheduler;
|
||||
|
||||
/** ActionManager associated with this director
|
||||
@since v2.0
|
||||
*/
|
||||
ActionManager* _actionManager;
|
||||
ActionManager *_actionManager;
|
||||
|
||||
/** EventDispatcher associated with this director
|
||||
@since v3.0
|
||||
|
@ -408,7 +419,7 @@ protected:
|
|||
float _deltaTime;
|
||||
|
||||
/* The EGLView, where everything is rendered */
|
||||
EGLView *_openGLView;
|
||||
EGLView *_openGLView;
|
||||
|
||||
//texture cache belongs to this director
|
||||
TextureCache *_textureCache;
|
||||
|
@ -434,6 +445,8 @@ protected:
|
|||
unsigned int _totalFrames;
|
||||
unsigned int _frames;
|
||||
float _secondsPerFrame;
|
||||
|
||||
Frustum *_cullingFrustum;
|
||||
|
||||
/* The running scene */
|
||||
Scene *_runningScene;
|
||||
|
@ -443,7 +456,7 @@ protected:
|
|||
Scene *_nextScene;
|
||||
|
||||
/* If true, then "old" scene will receive the cleanup message */
|
||||
bool _sendCleanupToScene;
|
||||
bool _sendCleanupToScene;
|
||||
|
||||
/* scheduled scenes */
|
||||
Vector<Scene*> _scenesStack;
|
||||
|
@ -458,10 +471,10 @@ protected:
|
|||
Projection _projection;
|
||||
|
||||
/* window size in points */
|
||||
Size _winSizeInPoints;
|
||||
Size _winSizeInPoints;
|
||||
|
||||
/* content scale factor */
|
||||
float _contentScaleFactor;
|
||||
float _contentScaleFactor;
|
||||
|
||||
/* store the fps string */
|
||||
char *_FPS;
|
||||
|
@ -471,6 +484,8 @@ protected:
|
|||
|
||||
/* Projection protocol delegate */
|
||||
DirectorDelegate *_projectionDelegate;
|
||||
|
||||
Renderer *_renderer;
|
||||
|
||||
// EGLViewProtocol will recreate stats labels to fit visible rect
|
||||
friend class EGLViewProtocol;
|
||||
|
|
|
@ -27,15 +27,21 @@
|
|||
|
||||
#include "CCFontFNT.h"
|
||||
#include "CCFontFreeType.h"
|
||||
#include "edtaa3func.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
const int Font::DistanceMapSpread = 3;
|
||||
|
||||
const char * Font::_glyphASCII = "\"!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ ";
|
||||
|
||||
const char * Font::_glyphNEHE = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ";
|
||||
|
||||
|
||||
Font::Font() : _usedGlyphs(GlyphCollection::ASCII), _customGlyphs(nullptr)
|
||||
Font::Font() :
|
||||
_usedGlyphs(GlyphCollection::ASCII)
|
||||
, _customGlyphs(nullptr)
|
||||
,_distanceFieldEnabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -109,6 +115,164 @@ Font* Font::createWithFNT(const std::string& fntFilePath)
|
|||
return FontFNT::create(fntFilePath);
|
||||
}
|
||||
|
||||
unsigned char * Font::makeDistanceMap( unsigned char *img, unsigned int width, unsigned int height)
|
||||
{
|
||||
unsigned int pixelAmount = (width + 2 * DistanceMapSpread) * (height + 2 * DistanceMapSpread);
|
||||
|
||||
short * xdist = (short *) malloc( pixelAmount * sizeof(short) );
|
||||
short * ydist = (short *) malloc( pixelAmount * sizeof(short) );
|
||||
double * gx = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * gy = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * data = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * outside = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
double * inside = (double *) calloc( pixelAmount, sizeof(double) );
|
||||
unsigned int i,j;
|
||||
|
||||
// Convert img into double (data) rescale image levels between 0 and 1
|
||||
unsigned int outWidth = width + 2 * DistanceMapSpread;
|
||||
for (i = 0; i < width; ++i)
|
||||
{
|
||||
for (j = 0; j < height; ++j)
|
||||
{
|
||||
data[j * outWidth + DistanceMapSpread + i] = img[j * width + i] / 255.0;
|
||||
}
|
||||
}
|
||||
|
||||
width += 2 * DistanceMapSpread;
|
||||
height += 2 * DistanceMapSpread;
|
||||
|
||||
// Transform background (outside contour, in areas of 0's)
|
||||
computegradient( data, width, height, gx, gy);
|
||||
edtaa3(data, gx, gy, width, height, xdist, ydist, outside);
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
if( outside[i] < 0.0 )
|
||||
outside[i] = 0.0;
|
||||
|
||||
// Transform foreground (inside contour, in areas of 1's)
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
data[i] = 1 - data[i];
|
||||
computegradient( data, width, height, gx, gy);
|
||||
edtaa3(data, gx, gy, width, height, xdist, ydist, inside);
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
if( inside[i] < 0.0 )
|
||||
inside[i] = 0.0;
|
||||
|
||||
// The bipolar distance field is now outside-inside
|
||||
double dist;
|
||||
/* Single channel 8-bit output (bad precision and range, but simple) */
|
||||
unsigned char *out = (unsigned char *) malloc( pixelAmount * sizeof(unsigned char) );
|
||||
for( i=0; i < pixelAmount; i++)
|
||||
{
|
||||
dist = outside[i] - inside[i];
|
||||
dist = 128.0 - dist*16;
|
||||
if( dist < 0 ) dist = 0;
|
||||
if( dist > 255 ) dist = 255;
|
||||
out[i] = (unsigned char) dist;
|
||||
}
|
||||
/* Dual channel 16-bit output (more complicated, but good precision and range) */
|
||||
/*unsigned char *out = (unsigned char *) malloc( pixelAmount * 3 * sizeof(unsigned char) );
|
||||
for( i=0; i< pixelAmount; i++)
|
||||
{
|
||||
dist = outside[i] - inside[i];
|
||||
dist = 128.0 - dist*16;
|
||||
if( dist < 0.0 ) dist = 0.0;
|
||||
if( dist >= 256.0 ) dist = 255.999;
|
||||
// R channel is a copy of the original grayscale image
|
||||
out[3*i] = img[i];
|
||||
// G channel is fraction
|
||||
out[3*i + 1] = (unsigned char) ( 256 - (dist - floor(dist)* 256.0 ));
|
||||
// B channel is truncated integer part
|
||||
out[3*i + 2] = (unsigned char)dist;
|
||||
}*/
|
||||
|
||||
free( xdist );
|
||||
free( ydist );
|
||||
free( gx );
|
||||
free( gy );
|
||||
free( data );
|
||||
free( outside );
|
||||
free( inside );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void Font::setDistanceFieldEnabled(bool distanceFieldEnabled)
|
||||
{
|
||||
_distanceFieldEnabled = distanceFieldEnabled;
|
||||
}
|
||||
|
||||
bool Font::renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize)
|
||||
{
|
||||
unsigned char *sourceBitmap = 0;
|
||||
int sourceWidth = 0;
|
||||
int sourceHeight = 0;
|
||||
|
||||
sourceBitmap = getGlyphBitmap(charToRender, sourceWidth, sourceHeight);
|
||||
|
||||
if (!sourceBitmap)
|
||||
return false;
|
||||
|
||||
if (_distanceFieldEnabled)
|
||||
{
|
||||
unsigned char * out = makeDistanceMap(sourceBitmap,sourceWidth,sourceHeight);
|
||||
|
||||
int iX = posX;
|
||||
int iY = posY;
|
||||
|
||||
sourceWidth += 2 * DistanceMapSpread;
|
||||
sourceHeight += 2 * DistanceMapSpread;
|
||||
|
||||
for (int y = 0; y < sourceHeight; ++y)
|
||||
{
|
||||
int bitmap_y = y * sourceWidth;
|
||||
|
||||
for (int x = 0; x < sourceWidth; ++x)
|
||||
{
|
||||
/* Dual channel 16-bit output (more complicated, but good precision and range) */
|
||||
/*int index = (iX + ( iY * destSize )) * 3;
|
||||
int index2 = (bitmap_y + x)*3;
|
||||
destMemory[index] = out[index2];
|
||||
destMemory[index + 1] = out[index2 + 1];
|
||||
destMemory[index + 2] = out[index2 + 2];*/
|
||||
|
||||
//Single channel 8-bit output
|
||||
destMemory[iX + ( iY * destSize )] = out[bitmap_y + x];
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
||||
iX = posX;
|
||||
iY += 1;
|
||||
}
|
||||
free(out);
|
||||
return true;
|
||||
}
|
||||
|
||||
int iX = posX;
|
||||
int iY = posY;
|
||||
|
||||
for (int y = 0; y < sourceHeight; ++y)
|
||||
{
|
||||
int bitmap_y = y * sourceWidth;
|
||||
|
||||
for (int x = 0; x < sourceWidth; ++x)
|
||||
{
|
||||
unsigned char cTemp = sourceBitmap[bitmap_y + x];
|
||||
|
||||
// the final pixel
|
||||
destMemory[(iX + ( iY * destSize ) )] = cTemp;
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
||||
iX = posX;
|
||||
iY += 1;
|
||||
}
|
||||
|
||||
//everything good
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned short int * Font::getUTF16Text(const char *text, int &outNumLetters) const
|
||||
{
|
||||
unsigned short* utf16String = cc_utf8_to_utf16(text);
|
||||
|
|
|
@ -40,11 +40,16 @@ class FontAtlas;
|
|||
class CC_DLL Font : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
static const int DistanceMapSpread;
|
||||
// create the font
|
||||
static Font* createWithTTF(const std::string& fntName, int fontSize, GlyphCollection glyphs, const char *customGlyphs);
|
||||
static Font* createWithFNT(const std::string& fntFilePath);
|
||||
|
||||
static unsigned char * makeDistanceMap(unsigned char *img, unsigned int width, unsigned int height);
|
||||
void setDistanceFieldEnabled(bool distanceFieldEnabled);
|
||||
bool isDistanceFieldEnabled() const { return _distanceFieldEnabled;}
|
||||
bool renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize);
|
||||
|
||||
virtual FontAtlas *createFontAtlas() = 0;
|
||||
|
||||
virtual Size* getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const = 0;
|
||||
|
@ -76,7 +81,8 @@ protected:
|
|||
char * _customGlyphs;
|
||||
static const char * _glyphASCII;
|
||||
static const char * _glyphNEHE;
|
||||
|
||||
bool _distanceFieldEnabled;
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -21,12 +21,14 @@
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "CCFontAtlas.h"
|
||||
#include "CCFont.h"
|
||||
#include "CCFontFreeType.h"
|
||||
|
||||
#define PAGE_WIDTH 1024
|
||||
#define PAGE_HEIGHT 1024
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
FontAtlas::FontAtlas(Font &theFont) :
|
||||
|
@ -34,7 +36,8 @@ _font(&theFont),
|
|||
_currentPageData(nullptr)
|
||||
{
|
||||
_font->retain();
|
||||
|
||||
_makeDistanceMap = _font->isDistanceFieldEnabled();
|
||||
|
||||
FontFreeType* fontTTf = dynamic_cast<FontFreeType*>(_font);
|
||||
if (fontTTf && fontTTf->isDynamicGlyphCollection())
|
||||
{
|
||||
|
@ -45,7 +48,17 @@ _currentPageData(nullptr)
|
|||
_currentPageOrigX = 0;
|
||||
_currentPageOrigY = 0;
|
||||
_letterPadding = 5;
|
||||
_currentPageDataSize = (1024 * 1024 * 4);
|
||||
|
||||
if(_makeDistanceMap)
|
||||
{
|
||||
_commonLineHeight += 2 * Font::DistanceMapSpread;
|
||||
_letterPadding += 2 * Font::DistanceMapSpread;
|
||||
_currentPageDataSize = (PAGE_WIDTH * PAGE_HEIGHT * 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentPageDataSize = (PAGE_WIDTH * PAGE_HEIGHT * 1);
|
||||
}
|
||||
|
||||
_currentPageData = new unsigned char[_currentPageDataSize];
|
||||
memset(_currentPageData, 0, _currentPageDataSize);
|
||||
|
@ -97,16 +110,20 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
|
||||
FontFreeType* fontTTf = (FontFreeType*)_font;
|
||||
|
||||
std::vector<FontLetterDefinition> fontDefs;
|
||||
std::unordered_map<unsigned short, FontLetterDefinition> fontDefs;
|
||||
int length = cc_wcslen(utf16String);
|
||||
|
||||
//find out new letter
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
auto outIterator = _fontLetterDefinitions.find(utf16String[i]);
|
||||
|
||||
|
||||
if (outIterator == _fontLetterDefinitions.end())
|
||||
{
|
||||
{
|
||||
auto outIterator2 = fontDefs.find(utf16String[i]);
|
||||
if(outIterator2 != fontDefs.end())
|
||||
continue;
|
||||
|
||||
Rect tempRect;
|
||||
|
||||
FontLetterDefinition tempDef;
|
||||
|
@ -135,28 +152,30 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
tempDef.offsetY = tempRect.origin.y;
|
||||
tempDef.commonLineHeight = _currentPageLineHeight;
|
||||
|
||||
}
|
||||
fontDefs.push_back(tempDef);
|
||||
}
|
||||
fontDefs[utf16String[i]] = tempDef;
|
||||
}
|
||||
}
|
||||
|
||||
Size _pageContentSize = Size(PAGE_WIDTH,PAGE_HEIGHT);
|
||||
float scaleFactor = CC_CONTENT_SCALE_FACTOR();
|
||||
size_t newLetterCount = fontDefs.size();
|
||||
float glyphWidth;
|
||||
for (int i = 0; i < newLetterCount; ++i)
|
||||
Texture2D::PixelFormat pixelFormat = _makeDistanceMap ? Texture2D::PixelFormat::A8 : Texture2D::PixelFormat::A8;
|
||||
|
||||
for(auto it = fontDefs.begin(); it != fontDefs.end(); it++)
|
||||
{
|
||||
if (fontDefs[i].validDefinition)
|
||||
if(it->second.validDefinition)
|
||||
{
|
||||
_currentPageOrigX += _letterPadding;
|
||||
glyphWidth = fontDefs[i].width - _letterPadding;
|
||||
glyphWidth = it->second.width - _letterPadding;
|
||||
|
||||
if (_currentPageOrigX + glyphWidth > 1024)
|
||||
if (_currentPageOrigX + glyphWidth > PAGE_WIDTH)
|
||||
{
|
||||
_currentPageOrigY += _currentPageLineHeight;
|
||||
if(_currentPageOrigY >= 1024)
|
||||
_currentPageOrigX = 0;
|
||||
if(_currentPageOrigY >= PAGE_HEIGHT)
|
||||
{
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, Texture2D::PixelFormat::RGBA8888, 1024, 1024, Size(1024, 1024) );
|
||||
_currentPageOrigX = 0;
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, PAGE_WIDTH, PAGE_HEIGHT, _pageContentSize );
|
||||
_currentPageOrigY = 0;
|
||||
|
||||
delete []_currentPageData;
|
||||
|
@ -170,63 +189,25 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
tex->release();
|
||||
}
|
||||
}
|
||||
renderCharAt(fontDefs[i].letteCharUTF16,_currentPageOrigX,_currentPageOrigY,_currentPageData,1024);
|
||||
_font->renderCharAt(it->second.letteCharUTF16,_currentPageOrigX,_currentPageOrigY,_currentPageData,PAGE_WIDTH);
|
||||
|
||||
fontDefs[i].U = _currentPageOrigX - 1;
|
||||
fontDefs[i].V = _currentPageOrigY;
|
||||
fontDefs[i].textureID = _currentPage;
|
||||
it->second.U = _currentPageOrigX - 1;
|
||||
it->second.V = _currentPageOrigY;
|
||||
it->second.textureID = _currentPage;
|
||||
// take from pixels to points
|
||||
fontDefs[i].width = fontDefs[i].width / scaleFactor;
|
||||
fontDefs[i].height = fontDefs[i].height / scaleFactor;
|
||||
fontDefs[i].U = fontDefs[i].U / scaleFactor;
|
||||
fontDefs[i].V = fontDefs[i].V / scaleFactor;
|
||||
it->second.width = it->second.width / scaleFactor;
|
||||
it->second.height = it->second.height / scaleFactor;
|
||||
it->second.U = it->second.U / scaleFactor;
|
||||
it->second.V = it->second.V / scaleFactor;
|
||||
}
|
||||
else
|
||||
glyphWidth = 0;
|
||||
|
||||
this->addLetterDefinition(fontDefs[i]);
|
||||
_fontLetterDefinitions[it->second.letteCharUTF16] = it->second;
|
||||
_currentPageOrigX += glyphWidth;
|
||||
}
|
||||
if(newLetterCount > 0)
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, Texture2D::PixelFormat::RGBA8888, 1024, 1024, Size(1024, 1024) );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FontAtlas::renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize)
|
||||
{
|
||||
unsigned char *sourceBitmap = 0;
|
||||
int sourceWidth = 0;
|
||||
int sourceHeight = 0;
|
||||
|
||||
// get the glyph's bitmap
|
||||
sourceBitmap = _font->getGlyphBitmap(charToRender, sourceWidth, sourceHeight);
|
||||
|
||||
if (!sourceBitmap)
|
||||
return false;
|
||||
|
||||
int iX = posX;
|
||||
int iY = posY;
|
||||
|
||||
for (int y = 0; y < sourceHeight; ++y)
|
||||
{
|
||||
int bitmap_y = y * sourceWidth;
|
||||
|
||||
for (int x = 0; x < sourceWidth; ++x)
|
||||
{
|
||||
unsigned char cTemp = sourceBitmap[bitmap_y + x];
|
||||
|
||||
// the final pixel
|
||||
int iTemp = cTemp << 24 | cTemp << 16 | cTemp << 8 | cTemp;
|
||||
*(int*) &destMemory[(iX + ( iY * destSize ) ) * 4] = iTemp;
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
||||
iX = posX;
|
||||
iY += 1;
|
||||
}
|
||||
|
||||
//everything good
|
||||
if(fontDefs.size() > 0)
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, PAGE_WIDTH, PAGE_HEIGHT, _pageContentSize );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -248,6 +229,8 @@ float FontAtlas::getCommonLineHeight() const
|
|||
|
||||
void FontAtlas::setCommonLineHeight(float newHeight)
|
||||
{
|
||||
if(_makeDistanceMap)
|
||||
newHeight += 2 * Font::DistanceMapSpread;
|
||||
_commonLineHeight = newHeight;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,6 @@ public:
|
|||
const Font* getFont() const;
|
||||
|
||||
private:
|
||||
bool renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize);
|
||||
|
||||
void relaseTextures();
|
||||
std::unordered_map<int, Texture2D*> _atlasTextures;
|
||||
|
@ -89,6 +88,7 @@ private:
|
|||
float _currentPageOrigY;
|
||||
float _currentPageLineHeight;
|
||||
float _letterPadding;
|
||||
bool _makeDistanceMap;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -30,14 +30,14 @@ NS_CC_BEGIN
|
|||
|
||||
std::unordered_map<std::string, FontAtlas *> FontAtlasCache::_atlasMap;
|
||||
|
||||
FontAtlas * FontAtlasCache::getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs)
|
||||
FontAtlas * FontAtlasCache::getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
{
|
||||
std::string atlasName = generateFontName(fontFileName, size, glyphs);
|
||||
std::string atlasName = generateFontName(fontFileName, size, glyphs, useDistanceField);
|
||||
FontAtlas *tempAtlas = _atlasMap[atlasName];
|
||||
|
||||
if ( !tempAtlas )
|
||||
{
|
||||
tempAtlas = FontAtlasFactory::createAtlasFromTTF(fontFileName, size, glyphs, customGlyphs);
|
||||
tempAtlas = FontAtlasFactory::createAtlasFromTTF(fontFileName, size, glyphs, customGlyphs, useDistanceField);
|
||||
if (tempAtlas)
|
||||
_atlasMap[atlasName] = tempAtlas;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ FontAtlas * FontAtlasCache::getFontAtlasTTF(const char *fontFileName, int size,
|
|||
|
||||
FontAtlas * FontAtlasCache::getFontAtlasFNT(const char *fontFileName)
|
||||
{
|
||||
std::string atlasName = generateFontName(fontFileName, 0, GlyphCollection::CUSTOM);
|
||||
std::string atlasName = generateFontName(fontFileName, 0, GlyphCollection::CUSTOM,false);
|
||||
FontAtlas *tempAtlas = _atlasMap[atlasName];
|
||||
|
||||
if ( !tempAtlas )
|
||||
|
@ -68,7 +68,7 @@ FontAtlas * FontAtlasCache::getFontAtlasFNT(const char *fontFileName)
|
|||
return tempAtlas;
|
||||
}
|
||||
|
||||
std::string FontAtlasCache::generateFontName(const char *fontFileName, int size, GlyphCollection theGlyphs)
|
||||
std::string FontAtlasCache::generateFontName(const char *fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField)
|
||||
{
|
||||
std::string tempName(fontFileName);
|
||||
|
||||
|
@ -93,7 +93,8 @@ std::string FontAtlasCache::generateFontName(const char *fontFileName, int size,
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(useDistanceField)
|
||||
tempName.append("df");
|
||||
// std::to_string is not supported on android, using std::stringstream instead.
|
||||
std::stringstream ss;
|
||||
ss << size;
|
||||
|
|
|
@ -38,14 +38,14 @@ class CC_DLL FontAtlasCache
|
|||
|
||||
public:
|
||||
|
||||
static FontAtlas * getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs = 0);
|
||||
static FontAtlas * getFontAtlasTTF(const char *fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
static FontAtlas * getFontAtlasFNT(const char *fontFileName);
|
||||
|
||||
static bool releaseFontAtlas(FontAtlas *atlas);
|
||||
|
||||
private:
|
||||
|
||||
static std::string generateFontName(const char *fontFileName, int size, GlyphCollection theGlyphs);
|
||||
static std::string generateFontName(const char *fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField);
|
||||
static std::unordered_map<std::string, FontAtlas *> _atlasMap;
|
||||
};
|
||||
|
||||
|
|
|
@ -30,14 +30,19 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromTTF(const char* fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs)
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromTTF(const char* fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
{
|
||||
|
||||
Font *font = Font::createWithTTF(fntFilePath, fontSize, glyphs, customGlyphs);
|
||||
if (font)
|
||||
{
|
||||
font->setDistanceFieldEnabled(useDistanceField);
|
||||
return font->createFontAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FontAtlas * FontAtlasFactory::createAtlasFromFNT(const char* fntFilePath)
|
||||
|
@ -46,8 +51,7 @@ FontAtlas * FontAtlasFactory::createAtlasFromFNT(const char* fntFilePath)
|
|||
|
||||
if(font)
|
||||
{
|
||||
FontAtlas * atlas = font->createFontAtlas();
|
||||
return atlas;
|
||||
return font->createFontAtlas();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ class CC_DLL FontAtlasFactory
|
|||
|
||||
public:
|
||||
|
||||
static FontAtlas * createAtlasFromTTF(const char* fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs = 0);
|
||||
static FontAtlas * createAtlasFromTTF(const char* fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
static FontAtlas * createAtlasFromFNT(const char* fntFilePath);
|
||||
|
||||
private:
|
||||
|
|
|
@ -93,6 +93,8 @@ _letterPadding(5),
|
|||
_ttfData(nullptr),
|
||||
_dynamicGlyphCollection(dynamicGlyphCollection)
|
||||
{
|
||||
if(_distanceFieldEnabled)
|
||||
_letterPadding += 2 * DistanceMapSpread;
|
||||
}
|
||||
|
||||
bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
|
||||
|
@ -354,23 +356,21 @@ int FontFreeType::getFontMaxHeight() const
|
|||
return (static_cast<int>(_fontRef->size->metrics.height >> 6));
|
||||
}
|
||||
|
||||
unsigned char * FontFreeType::getGlyphBitmap(unsigned short theChar, int &outWidth, int &outHeight) const
|
||||
unsigned char * FontFreeType::getGlyphBitmap(unsigned short theChar, int &outWidth, int &outHeight) const
|
||||
{
|
||||
if (!_fontRef)
|
||||
return 0;
|
||||
|
||||
// get the ID to the char we need
|
||||
int glyphIndex = FT_Get_Char_Index(_fontRef, theChar);
|
||||
|
||||
if (!glyphIndex)
|
||||
return 0;
|
||||
|
||||
// load glyph infos
|
||||
if (FT_Load_Glyph(_fontRef, glyphIndex, FT_LOAD_DEFAULT))
|
||||
return 0;
|
||||
|
||||
if (FT_Render_Glyph( _fontRef->glyph, FT_RENDER_MODE_NORMAL ))
|
||||
return 0;
|
||||
if (_distanceFieldEnabled)
|
||||
{
|
||||
if (FT_Load_Char(_fontRef,theChar,FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT))
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FT_Load_Char(_fontRef,theChar,FT_LOAD_RENDER))
|
||||
return 0;
|
||||
}
|
||||
|
||||
outWidth = _fontRef->glyph->bitmap.width;
|
||||
outHeight = _fontRef->glyph->bitmap.rows;
|
||||
|
|
|
@ -71,7 +71,7 @@ private:
|
|||
static FT_Library _FTlibrary;
|
||||
static bool _FTInitialized;
|
||||
FT_Face _fontRef;
|
||||
const int _letterPadding;
|
||||
int _letterPadding;
|
||||
std::string _fontName;
|
||||
unsigned char* _ttfData;
|
||||
bool _dynamicGlyphCollection;
|
||||
|
|
|
@ -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";
|
||||
|
@ -54,6 +55,12 @@ const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR = "ShaderPositionTe
|
|||
const char* GLProgram::SHADER_NAME_POSITION_U_COLOR = "ShaderPosition_uColor";
|
||||
const char* GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR = "ShaderPositionLengthTextureColor";
|
||||
|
||||
const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL = "ShaderLabelNormol";
|
||||
const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW = "ShaderLabelGlow";
|
||||
const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE = "ShaderLabelOutline";
|
||||
const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW = "ShaderLabelShadow";
|
||||
|
||||
|
||||
// uniform names
|
||||
const char* GLProgram::UNIFORM_NAME_P_MATRIX = "CC_PMatrix";
|
||||
const char* GLProgram::UNIFORM_NAME_MV_MATRIX = "CC_MVMatrix";
|
||||
|
@ -234,8 +241,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 +331,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 +494,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 +504,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 +514,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 +524,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 +533,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 +543,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 +555,23 @@ void GLProgram::setUniformLocationWithMatrix4fv(GLint location, GLfloat* matrixA
|
|||
|
||||
void GLProgram::setUniformsForBuiltins()
|
||||
{
|
||||
kmMat4 matrixP;
|
||||
kmMat4 matrixMV;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV);
|
||||
|
||||
setUniformsForBuiltins(matrixMV);
|
||||
}
|
||||
|
||||
void GLProgram::setUniformsForBuiltins(const kmMat4 &matrixMV)
|
||||
{
|
||||
kmMat4 matrixP;
|
||||
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &matrixP);
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV);
|
||||
|
||||
|
||||
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 +579,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;
|
||||
|
@ -85,6 +87,11 @@ public:
|
|||
static const char* SHADER_NAME_POSITION_TEXTURE_A8_COLOR;
|
||||
static const char* SHADER_NAME_POSITION_U_COLOR;
|
||||
static const char* SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR;
|
||||
|
||||
static const char* SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL;
|
||||
static const char* SHADER_NAME_LABEL_DISTANCEFIELD_GLOW;
|
||||
static const char* SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE;
|
||||
static const char* SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW;
|
||||
|
||||
// uniform names
|
||||
static const char* UNIFORM_NAME_P_MATRIX;
|
||||
|
@ -190,25 +197,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 +234,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 +251,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
|
||||
|
|
|
@ -27,20 +27,28 @@
|
|||
#include "CCFontAtlasCache.h"
|
||||
#include "CCLabelTextFormatter.h"
|
||||
|
||||
#define DISTANCEFIELD_ATLAS_FONTSIZE 50
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Label* Label::createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs )
|
||||
Label* Label::createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField)
|
||||
{
|
||||
FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), fontSize, glyphs, customGlyphs);
|
||||
FontAtlas *tmpAtlas = nullptr;
|
||||
if(useDistanceField)
|
||||
tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), DISTANCEFIELD_ATLAS_FONTSIZE, glyphs, customGlyphs,true);
|
||||
else
|
||||
tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), fontSize, glyphs, customGlyphs,false);
|
||||
|
||||
if (!tmpAtlas)
|
||||
return nullptr;
|
||||
|
||||
// create the actual label
|
||||
Label* templabel = Label::createWithAtlas(tmpAtlas, alignment, lineSize);
|
||||
Label* templabel = Label::createWithAtlas(tmpAtlas, alignment, lineSize, useDistanceField,true);
|
||||
|
||||
if (templabel)
|
||||
{
|
||||
if(useDistanceField)
|
||||
templabel->setFontSize(fontSize);
|
||||
templabel->setText(label, lineSize, alignment, false);
|
||||
return templabel;
|
||||
}
|
||||
|
@ -71,9 +79,9 @@ Label* Label::createWithBMFont(const std::string& label, const std::string& bmfo
|
|||
return 0;
|
||||
}
|
||||
|
||||
Label* Label::createWithAtlas(FontAtlas *atlas, TextHAlignment alignment, int lineSize)
|
||||
Label* Label::createWithAtlas(FontAtlas *atlas, TextHAlignment alignment, int lineSize, bool useDistanceField,bool useA8Shader)
|
||||
{
|
||||
Label *ret = new Label(atlas, alignment);
|
||||
Label *ret = new Label(atlas, alignment, useDistanceField,useA8Shader);
|
||||
|
||||
if (!ret)
|
||||
return 0;
|
||||
|
@ -92,9 +100,10 @@ Label* Label::createWithAtlas(FontAtlas *atlas, TextHAlignment alignment, int li
|
|||
return ret;
|
||||
}
|
||||
|
||||
Label::Label(FontAtlas *atlas, TextHAlignment alignment)
|
||||
Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,bool useA8Shader)
|
||||
: _reusedLetter(nullptr)
|
||||
, _lineBreakWithoutSpaces(false)
|
||||
,_multilineEnable(true)
|
||||
, _alignment(alignment)
|
||||
, _currentUTF16String(0)
|
||||
, _originalUTF16String(0)
|
||||
|
@ -107,6 +116,8 @@ Label::Label(FontAtlas *atlas, TextHAlignment alignment)
|
|||
, _displayedOpacity(255)
|
||||
, _realOpacity(255)
|
||||
, _isOpacityModifyRGB(true)
|
||||
,_useDistanceField(useDistanceField)
|
||||
,_useA8Shader(useA8Shader)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -124,19 +135,31 @@ Label::~Label()
|
|||
|
||||
bool Label::init()
|
||||
{
|
||||
bool ret = true;
|
||||
if(_fontAtlas)
|
||||
{
|
||||
_reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0));
|
||||
_reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB);
|
||||
ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30);
|
||||
_reusedLetter->retain();
|
||||
return SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30);
|
||||
}
|
||||
if (_useDistanceField)
|
||||
setLabelEffect(LabelEffect::NORMAL,Color3B::BLACK);
|
||||
else if(_useA8Shader)
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR));
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Label::setString(const std::string &stringToRender)
|
||||
{
|
||||
_multilineEnable = true;
|
||||
setText(stringToRender, _width, TextHAlignment::CENTER, false);
|
||||
}
|
||||
|
||||
void Label::setString(const std::string &stringToRender,bool multilineEnable)
|
||||
{
|
||||
_multilineEnable = multilineEnable;
|
||||
setText(stringToRender, _width, TextHAlignment::CENTER, false);
|
||||
}
|
||||
|
||||
|
@ -221,20 +244,53 @@ void Label::setLineBreakWithoutSpace(bool breakWithoutSpace)
|
|||
|
||||
void Label::setScale(float scale)
|
||||
{
|
||||
if (_useDistanceField)
|
||||
{
|
||||
scale *= 1.0f * _fontSize / DISTANCEFIELD_ATLAS_FONTSIZE;
|
||||
}
|
||||
Node::setScale(scale);
|
||||
alignText();
|
||||
}
|
||||
|
||||
void Label::setScaleX(float scaleX)
|
||||
{
|
||||
if (_useDistanceField)
|
||||
{
|
||||
scaleX *= 1.0f * _fontSize / DISTANCEFIELD_ATLAS_FONTSIZE;
|
||||
}
|
||||
Node::setScaleX(scaleX);
|
||||
alignText();
|
||||
}
|
||||
|
||||
void Label::setScaleY(float scaleY)
|
||||
{
|
||||
if (_useDistanceField)
|
||||
{
|
||||
scaleY *= 1.0f * _fontSize / DISTANCEFIELD_ATLAS_FONTSIZE;
|
||||
}
|
||||
Node::setScaleY(scaleY);
|
||||
alignText();
|
||||
}
|
||||
|
||||
float Label::getScaleY() const
|
||||
{
|
||||
if (_useDistanceField)
|
||||
{
|
||||
return _scaleY / (1.0f * _fontSize / DISTANCEFIELD_ATLAS_FONTSIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _scaleY;
|
||||
}
|
||||
}
|
||||
|
||||
float Label::getScaleX() const
|
||||
{
|
||||
if (_useDistanceField)
|
||||
{
|
||||
return _scaleX / (1.0f * _fontSize / DISTANCEFIELD_ATLAS_FONTSIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _scaleX;
|
||||
}
|
||||
}
|
||||
|
||||
void Label::alignText()
|
||||
|
@ -243,14 +299,13 @@ void Label::alignText()
|
|||
_textureAtlas->removeAllQuads();
|
||||
_fontAtlas->prepareLetterDefinitions(_currentUTF16String);
|
||||
LabelTextFormatter::createStringSprites(this);
|
||||
if( LabelTextFormatter::multilineText(this) )
|
||||
if(_multilineEnable && LabelTextFormatter::multilineText(this) )
|
||||
LabelTextFormatter::createStringSprites(this);
|
||||
|
||||
LabelTextFormatter::alignText(this);
|
||||
|
||||
int strLen = cc_wcslen(_currentUTF16String);
|
||||
|
||||
_children.forEach([this, &strLen](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this,&strLen](Node* child){
|
||||
if (child)
|
||||
{
|
||||
int tag = child->getTag();
|
||||
|
@ -415,6 +470,69 @@ void Label::addChild(Node * child, int zOrder/* =0 */, int tag/* =0 */)
|
|||
CCASSERT(0, "addChild: is not supported on Label.");
|
||||
}
|
||||
|
||||
void Label::setLabelEffect(LabelEffect effect,const Color3B& effectColor)
|
||||
{
|
||||
if(_useDistanceField == false)
|
||||
return;
|
||||
|
||||
_currLabelEffect = effect;
|
||||
_effectColor = effectColor;
|
||||
|
||||
switch (_currLabelEffect)
|
||||
{
|
||||
case cocos2d::LabelEffect::NORMAL:
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL));
|
||||
break;
|
||||
case cocos2d::LabelEffect::OUTLINE:
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE));
|
||||
break;
|
||||
case cocos2d::LabelEffect::SHADOW:
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW));
|
||||
break;
|
||||
case cocos2d::LabelEffect::GLOW:
|
||||
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_uniformEffectColor = glGetUniformLocation(_shaderProgram->getProgram(), "v_effectColor");
|
||||
}
|
||||
|
||||
void Label::setFontSize(int fontSize)
|
||||
{
|
||||
_fontSize = fontSize;
|
||||
Node::setScale(1.0f*_fontSize/DISTANCEFIELD_ATLAS_FONTSIZE);
|
||||
}
|
||||
|
||||
void Label::draw()
|
||||
{
|
||||
CC_PROFILER_START("CCSpriteBatchNode - draw");
|
||||
|
||||
// Optimization: Fast Dispatch
|
||||
if( _textureAtlas->getTotalQuads() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
if (_useDistanceField && _currLabelEffect != LabelEffect::NORMAL)
|
||||
{
|
||||
_shaderProgram->setUniformLocationWith3f(_uniformEffectColor, _effectColor.r/255.0f,_effectColor.g/255.0f,_effectColor.b/255.0f);
|
||||
}
|
||||
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->updateTransform();
|
||||
});
|
||||
|
||||
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
|
||||
_textureAtlas->drawQuads();
|
||||
|
||||
CC_PROFILER_STOP("CCSpriteBatchNode - draw");
|
||||
}
|
||||
|
||||
///// PROTOCOL STUFF
|
||||
|
||||
Sprite * Label::getLetter(int ID)
|
||||
|
@ -434,7 +552,7 @@ Sprite * Label::getLetter(int ID)
|
|||
uvRect.origin.x = _lettersInfo[ID].def.U;
|
||||
uvRect.origin.y = _lettersInfo[ID].def.V;
|
||||
|
||||
sp = Sprite::createWithTexture(&_fontAtlas->getTexture(_lettersInfo[ID].def.textureID), uvRect);
|
||||
sp = Sprite::createWithTexture(&_fontAtlas->getTexture(_lettersInfo[ID].def.textureID),uvRect);
|
||||
sp->setBatchNode(this);
|
||||
sp->setAnchorPoint(Point(_lettersInfo[ID].def.anchorX, _lettersInfo[ID].def.anchorY));
|
||||
sp->setPosition(_lettersInfo[ID].position);
|
||||
|
@ -592,7 +710,7 @@ void Label::setOpacityModifyRGB(bool isOpacityModifyRGB)
|
|||
{
|
||||
_isOpacityModifyRGB = isOpacityModifyRGB;
|
||||
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this](Node* child){
|
||||
if (child)
|
||||
{
|
||||
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
|
||||
|
@ -634,9 +752,9 @@ void Label::updateDisplayedOpacity(GLubyte parentOpacity)
|
|||
{
|
||||
_displayedOpacity = _realOpacity * parentOpacity/255.0;
|
||||
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this](Node* child){
|
||||
Sprite *item = static_cast<Sprite*>( child );
|
||||
item->updateDisplayedOpacity(_displayedOpacity);
|
||||
item->updateDisplayedOpacity(_displayedOpacity);
|
||||
});
|
||||
|
||||
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
|
||||
|
@ -700,9 +818,9 @@ void Label::updateDisplayedColor(const Color3B& parentColor)
|
|||
_displayedColor.g = _realColor.g * parentColor.g/255.0;
|
||||
_displayedColor.b = _realColor.b * parentColor.b/255.0;
|
||||
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this](Node* child){
|
||||
Sprite *item = static_cast<Sprite*>( child );
|
||||
item->updateDisplayedColor(_displayedColor);
|
||||
item->updateDisplayedColor(_displayedColor);
|
||||
});
|
||||
|
||||
V3F_C4B_T2F_Quad *quads = _textureAtlas->getQuads();
|
||||
|
|
|
@ -40,6 +40,14 @@ enum class GlyphCollection {
|
|||
CUSTOM
|
||||
};
|
||||
|
||||
enum class LabelEffect {
|
||||
|
||||
NORMAL,
|
||||
OUTLINE,
|
||||
SHADOW,
|
||||
GLOW
|
||||
};
|
||||
|
||||
//fwd
|
||||
struct FontLetterDefinition;
|
||||
class FontAtlas;
|
||||
|
@ -51,19 +59,24 @@ class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public RGBAPr
|
|||
public:
|
||||
|
||||
// static create
|
||||
static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0);
|
||||
static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0, bool useDistanceField = false);
|
||||
|
||||
static Label* createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0);
|
||||
|
||||
bool setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment = TextHAlignment::LEFT, bool lineBreakWithoutSpaces = false);
|
||||
|
||||
void setLabelEffect(LabelEffect effect,const Color3B& effectColor);
|
||||
|
||||
virtual void setString(const std::string &stringToRender) override;
|
||||
void setString(const std::string &stringToRender,bool multilineEnable);
|
||||
virtual void setAlignment(TextHAlignment alignment);
|
||||
virtual void setWidth(float width);
|
||||
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
|
||||
virtual void setScale(float scale) override;
|
||||
virtual void setScaleX(float scaleX) override;
|
||||
virtual void setScaleY(float scaleY) override;
|
||||
virtual float getScaleX() const;
|
||||
virtual float getScaleY() const;
|
||||
|
||||
// RGBAProtocol
|
||||
virtual bool isOpacityModifyRGB() const override;
|
||||
|
@ -117,19 +130,22 @@ public:
|
|||
void addChild(Node * child, int zOrder=0, int tag=0) override;
|
||||
|
||||
virtual std::string getDescription() const override;
|
||||
virtual void draw(void) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @js NA
|
||||
*/
|
||||
Label(FontAtlas *atlas, TextHAlignment alignment);
|
||||
Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField = false,bool useA8Shader = false);
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
~Label();
|
||||
|
||||
static Label* createWithAtlas(FontAtlas *atlas, TextHAlignment alignment = TextHAlignment::LEFT, int lineSize = 0);
|
||||
static Label* createWithAtlas(FontAtlas *atlas, TextHAlignment alignment = TextHAlignment::LEFT, int lineSize = 0, bool useDistanceField = false,bool useA8Shader = false);
|
||||
|
||||
void setFontSize(int fontSize);
|
||||
|
||||
bool init();
|
||||
|
||||
|
@ -147,6 +163,7 @@ private:
|
|||
Sprite *_reusedLetter;
|
||||
std::vector<LetterInfo> _lettersInfo;
|
||||
|
||||
bool _multilineEnable;
|
||||
float _commonLineHeight;
|
||||
bool _lineBreakWithoutSpaces;
|
||||
float _width;
|
||||
|
@ -162,7 +179,15 @@ private:
|
|||
unsigned char _displayedOpacity;
|
||||
unsigned char _realOpacity;
|
||||
bool _isOpacityModifyRGB;
|
||||
|
||||
|
||||
bool _useDistanceField;
|
||||
bool _useA8Shader;
|
||||
int _fontSize;
|
||||
|
||||
LabelEffect _currLabelEffect;
|
||||
Color3B _effectColor;
|
||||
|
||||
GLuint _uniformEffectColor;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -747,7 +747,7 @@ void LabelBMFont::setString(unsigned short *newString, bool needUpdateLabel)
|
|||
CC_SAFE_DELETE_ARRAY(tmp);
|
||||
}
|
||||
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->setVisible(false);
|
||||
});
|
||||
|
||||
|
@ -823,7 +823,7 @@ void LabelBMFont::setOpacity(GLubyte opacity)
|
|||
void LabelBMFont::setOpacityModifyRGB(bool var)
|
||||
{
|
||||
_isOpacityModifyRGB = var;
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this](Node* child){
|
||||
if (child)
|
||||
{
|
||||
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(child);
|
||||
|
@ -843,7 +843,7 @@ void LabelBMFont::updateDisplayedOpacity(GLubyte parentOpacity)
|
|||
{
|
||||
_displayedOpacity = _realOpacity * parentOpacity/255.0f;
|
||||
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(),[this](Node* child){
|
||||
Sprite *item = static_cast<Sprite*>( child );
|
||||
item->updateDisplayedOpacity(_displayedOpacity);
|
||||
});
|
||||
|
@ -855,7 +855,7 @@ void LabelBMFont::updateDisplayedColor(const Color3B& parentColor)
|
|||
_displayedColor.g = _realColor.g * parentColor.g/255.0f;
|
||||
_displayedColor.b = _realColor.b * parentColor.b/255.0f;
|
||||
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(),[this](Node* child){
|
||||
Sprite *item = static_cast<Sprite*>( child );
|
||||
item->updateDisplayedColor(_displayedColor);
|
||||
});
|
||||
|
|
|
@ -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,8 +131,8 @@ 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;
|
||||
_vAlignment = vAlignment;
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
|
@ -58,7 +58,7 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel)
|
|||
std::vector<LetterInfo> *leterInfo = theLabel->getLettersInfo();
|
||||
int tIndex = 0;
|
||||
|
||||
for (int j = 0; j < strLen; j++)
|
||||
for (int j = 0; j+skip < strLen; j++)
|
||||
{
|
||||
LetterInfo* info = &leterInfo->at(j+skip);
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ THE SOFTWARE.
|
|||
#include "CCEventListenerAcceleration.h"
|
||||
#include "platform/CCDevice.h"
|
||||
#include "CCScene.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -505,7 +507,7 @@ void LayerRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
|
|||
|
||||
if (_cascadeOpacityEnabled)
|
||||
{
|
||||
_children.forEach([this](Node* obj){
|
||||
std::for_each(_children.begin(), _children.end(),[this](Node* obj){
|
||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
||||
if (item)
|
||||
{
|
||||
|
@ -523,7 +525,7 @@ void LayerRGBA::updateDisplayedColor(const Color3B& parentColor)
|
|||
|
||||
if (_cascadeColorEnabled)
|
||||
{
|
||||
_children.forEach([this](Node* obj){
|
||||
std::for_each(_children.begin(), _children.end(),[this](Node* obj){
|
||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(obj);
|
||||
if (item)
|
||||
{
|
||||
|
@ -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);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void LayerColor::onDraw()
|
||||
{
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
|
@ -942,7 +952,7 @@ LayerMultiplex::LayerMultiplex()
|
|||
|
||||
LayerMultiplex::~LayerMultiplex()
|
||||
{
|
||||
_layers.forEach([](Layer* layer){
|
||||
std::for_each(_layers.begin(), _layers.end(), [](Layer* layer){
|
||||
layer->cleanup();
|
||||
});
|
||||
}
|
||||
|
@ -1038,7 +1048,7 @@ bool LayerMultiplex::initWithArray(const Vector<Layer*>& arrayOfLayers)
|
|||
if (Layer::init())
|
||||
{
|
||||
_layers.reserve(arrayOfLayers.size());
|
||||
_layers.insert(arrayOfLayers);
|
||||
_layers.pushBack(arrayOfLayers);
|
||||
|
||||
_enabledLayer = 0;
|
||||
this->addChild(_layers.at(_enabledLayer));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -291,7 +291,7 @@ void Menu::alignItemsVerticallyWithPadding(float padding)
|
|||
{
|
||||
float height = -padding;
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
height += child->getContentSize().height * child->getScaleY() + padding;
|
||||
|
@ -300,7 +300,7 @@ void Menu::alignItemsVerticallyWithPadding(float padding)
|
|||
|
||||
float y = height / 2.0f;
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
child->setPosition(Point(0, y - child->getContentSize().height * child->getScaleY() / 2.0f));
|
||||
|
@ -317,7 +317,7 @@ void Menu::alignItemsHorizontally(void)
|
|||
void Menu::alignItemsHorizontallyWithPadding(float padding)
|
||||
{
|
||||
float width = -padding;
|
||||
_children.forEach([&](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
width += child->getContentSize().width * child->getScaleX() + padding;
|
||||
|
@ -326,7 +326,7 @@ void Menu::alignItemsHorizontallyWithPadding(float padding)
|
|||
|
||||
float x = -width / 2.0f;
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
child->setPosition(Point(x + child->getContentSize().width * child->getScaleX() / 2.0f, 0));
|
||||
|
@ -365,7 +365,7 @@ void Menu::alignItemsInColumnsWithArray(const ValueVector& rows)
|
|||
int columnsOccupied = 0;
|
||||
int rowColumns = 0;
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
CCASSERT(row < rows.size(), "");
|
||||
|
@ -401,7 +401,7 @@ void Menu::alignItemsInColumnsWithArray(const ValueVector& rows)
|
|||
float x = 0.0;
|
||||
float y = (float)(height / 2);
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
if (child)
|
||||
|
@ -469,7 +469,7 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
|
|||
int rowsOccupied = 0;
|
||||
int columnRows;
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
// check if too many menu items for the amount of rows/columns
|
||||
|
@ -511,7 +511,7 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
|
|||
float x = (float)(-width / 2);
|
||||
float y = 0.0;
|
||||
|
||||
_children.forEach([&](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&](Node* child){
|
||||
if (child)
|
||||
{
|
||||
if (columnRows == 0)
|
||||
|
|
|
@ -918,7 +918,7 @@ void MenuItemToggle::addSubItem(MenuItem *item)
|
|||
|
||||
MenuItemToggle::~MenuItemToggle()
|
||||
{
|
||||
_subItems.forEach([](MenuItem* item){
|
||||
std::for_each(_subItems.begin(), _subItems.end(), [](MenuItem* item){
|
||||
item->cleanup();
|
||||
});
|
||||
}
|
||||
|
@ -970,7 +970,7 @@ void MenuItemToggle::setEnabled(bool enabled)
|
|||
{
|
||||
MenuItem::setEnabled(enabled);
|
||||
|
||||
_subItems.forEach([&enabled](MenuItem* item){
|
||||
std::for_each(_subItems.begin(), _subItems.end(), [&enabled](MenuItem* item){
|
||||
item->setEnabled(enabled);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -575,7 +576,7 @@ void Node::cleanup()
|
|||
}
|
||||
|
||||
// timers
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->cleanup();
|
||||
});
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -938,7 +939,7 @@ void Node::onEnter()
|
|||
{
|
||||
_isTransitionFinished = false;
|
||||
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->onEnter();
|
||||
});
|
||||
|
||||
|
@ -959,7 +960,7 @@ void Node::onEnterTransitionDidFinish()
|
|||
{
|
||||
_isTransitionFinished = true;
|
||||
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->onEnterTransitionDidFinish();
|
||||
});
|
||||
|
||||
|
@ -974,7 +975,7 @@ void Node::onEnterTransitionDidFinish()
|
|||
|
||||
void Node::onExitTransitionDidStart()
|
||||
{
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->onExitTransitionDidStart();
|
||||
});
|
||||
|
||||
|
@ -1000,7 +1001,7 @@ void Node::onExit()
|
|||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
||||
}
|
||||
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->onExit();
|
||||
});
|
||||
}
|
||||
|
@ -1182,16 +1183,25 @@ void Node::update(float fDelta)
|
|||
}
|
||||
}
|
||||
|
||||
const AffineTransform& Node::getNodeToParentTransform() const
|
||||
AffineTransform Node::getNodeToParentAffineTransform() const
|
||||
{
|
||||
if (_transformDirty)
|
||||
AffineTransform ret;
|
||||
kmMat4 ret4 = getNodeToParentTransform();
|
||||
GLToCGAffine(ret4.mat, &ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const kmMat4& Node::getNodeToParentTransform() const
|
||||
{
|
||||
if (_transformDirty)
|
||||
{
|
||||
|
||||
// Translate values
|
||||
float x = _position.x;
|
||||
float y = _position.y;
|
||||
|
||||
if (_ignoreAnchorPointForPosition)
|
||||
if (_ignoreAnchorPointForPosition)
|
||||
{
|
||||
x += _anchorPointInPoints.x;
|
||||
y += _anchorPointInPoints.y;
|
||||
|
@ -1226,80 +1236,131 @@ 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 );
|
||||
kmScalar mat[] = { cy * _scaleX, sy * _scaleX, 0, 0,
|
||||
-sx * _scaleY, cx * _scaleY, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
x, y, 0, 1 };
|
||||
|
||||
kmMat4Fill(&_transform, mat);
|
||||
// XXX: Try to inline skew
|
||||
// If skew is needed, apply skew and then anchor point
|
||||
if (needsSkewMatrix)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
_transformDirty = false;
|
||||
}
|
||||
|
||||
|
||||
return _transform;
|
||||
}
|
||||
|
||||
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);
|
||||
return Point(ret.x, ret.y);
|
||||
}
|
||||
|
||||
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);
|
||||
return Point(ret.x, ret.y);
|
||||
|
||||
}
|
||||
|
||||
Point Node::convertToNodeSpaceAR(const Point& worldPoint) const
|
||||
|
@ -1350,7 +1411,7 @@ bool Node::updatePhysicsTransform()
|
|||
void Node::updateTransform()
|
||||
{
|
||||
// Recursively iterate over children
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->updateTransform();
|
||||
});
|
||||
}
|
||||
|
@ -1461,7 +1522,7 @@ void NodeRGBA::updateDisplayedOpacity(GLubyte parentOpacity)
|
|||
|
||||
if (_cascadeOpacityEnabled)
|
||||
{
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this](Node* child){
|
||||
RGBAProtocol* item = dynamic_cast<RGBAProtocol*>(child);
|
||||
if (item)
|
||||
{
|
||||
|
@ -1516,7 +1577,7 @@ void NodeRGBA::updateDisplayedColor(const Color3B& parentColor)
|
|||
|
||||
if (_cascadeColorEnabled)
|
||||
{
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this](Node* child){
|
||||
RGBAProtocol *item = dynamic_cast<RGBAProtocol*>(child);
|
||||
if (item)
|
||||
{
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "CCProtocols.h"
|
||||
#include "CCEventDispatcher.h"
|
||||
#include "CCVector.h"
|
||||
#include "kazmath/kazmath.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
#include "platform/CCFileUtils.h"
|
||||
#include "kazmath/GL/matrix.h"
|
||||
#include "CCProfiling.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -383,7 +385,7 @@ void ParticleBatchNode::removeChildAtIndex(int index, bool doCleanup)
|
|||
|
||||
void ParticleBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
|
||||
{
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
static_cast<ParticleSystem*>(child)->setBatchNode(nullptr);
|
||||
});
|
||||
|
||||
|
@ -401,12 +403,27 @@ 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);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
CC_PROFILER_STOP("CCParticleBatchNode - draw");
|
||||
}
|
||||
|
||||
|
@ -464,7 +481,7 @@ void ParticleBatchNode::updateAllAtlasIndexes()
|
|||
{
|
||||
int index = 0;
|
||||
|
||||
_children.forEach([&index](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&index](Node* child){
|
||||
ParticleSystem* partiSys = static_cast<ParticleSystem*>(child);
|
||||
partiSys->setAtlasIndex(index);
|
||||
index += partiSys->getTotalParticles();
|
||||
|
|
|
@ -38,6 +38,9 @@ THE SOFTWARE.
|
|||
#include "CCNotificationCenter.h"
|
||||
#include "CCEventType.h"
|
||||
#include "CCConfiguration.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "CCCustomCommand.h"
|
||||
|
||||
// extern
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
@ -347,62 +350,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)
|
||||
{
|
||||
//
|
||||
// Using VBO and VAO
|
||||
//
|
||||
GL::bindVAO(_VAOname);
|
||||
// //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;
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// }
|
||||
|
||||
#if CC_REBIND_INDICES_BUFFER
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
|
||||
#endif
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
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);
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform);
|
||||
Director::getInstance()->getRenderer()->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 "CCRenderer.h"
|
||||
#include "CCCustomCommand.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);
|
||||
Director::getInstance()->getRenderer()->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);
|
||||
|
@ -528,7 +529,7 @@ void RenderTexture::draw()
|
|||
//! make sure all children are drawn
|
||||
sortAllChildren();
|
||||
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this](Node* child){
|
||||
if (child != _sprite)
|
||||
{
|
||||
child->visit();
|
||||
|
|
|
@ -60,34 +60,34 @@ public:
|
|||
static RenderTexture * create(int w, int h);
|
||||
|
||||
/** starts grabbing */
|
||||
void begin();
|
||||
virtual 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*/
|
||||
void end();
|
||||
virtual 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;
|
||||
|
|
|
@ -145,7 +145,8 @@ void Scene::addChildToPhysicsWorld(Node* child)
|
|||
_physicsWorld->addBody(node->getPhysicsBody());
|
||||
}
|
||||
|
||||
node->getChildren().forEach([addToPhysicsWorldFunc](Node* n){
|
||||
auto& children = node->getChildren();
|
||||
std::for_each(children.begin(), children.end(), [addToPhysicsWorldFunc](Node* n){
|
||||
addToPhysicsWorldFunc(n);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -809,7 +809,7 @@ Vector<Object*> Scheduler::pauseAllTargetsWithMinPriority(int minPriority)
|
|||
|
||||
void Scheduler::resumeTargets(const Vector<Object*>& targetsToResume)
|
||||
{
|
||||
targetsToResume.forEach([this](Object* obj){
|
||||
std::for_each(targetsToResume.begin(), targetsToResume.end(), [this](Object* obj){
|
||||
this->resumeTarget(obj);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ NS_CC_BEGIN
|
|||
|
||||
enum {
|
||||
kShaderType_PositionTextureColor,
|
||||
kShaderType_PositionTextureColor_noMVP,
|
||||
kShaderType_PositionTextureColorAlphaTest,
|
||||
kShaderType_PositionColor,
|
||||
kShaderType_PositionTexture,
|
||||
|
@ -40,7 +41,10 @@ enum {
|
|||
kShaderType_PositionTextureA8Color,
|
||||
kShaderType_Position_uColor,
|
||||
kShaderType_PositionLengthTexureColor,
|
||||
|
||||
kShaderType_LabelDistanceFieldNormal,
|
||||
kShaderType_LabelDistanceFieldGlow,
|
||||
kShaderType_LabelDistanceFieldOutline,
|
||||
kShaderType_LabelDistanceFieldShadow,
|
||||
kShaderType_MAX,
|
||||
};
|
||||
|
||||
|
@ -103,6 +107,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);
|
||||
|
@ -149,6 +158,22 @@ void ShaderCache::loadDefaultShaders()
|
|||
p = new GLProgram();
|
||||
loadDefaultShader(p, kShaderType_PositionLengthTexureColor);
|
||||
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR, p) );
|
||||
|
||||
p = new GLProgram();
|
||||
loadDefaultShader(p, kShaderType_LabelDistanceFieldNormal);
|
||||
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL, p) );
|
||||
|
||||
p = new GLProgram();
|
||||
loadDefaultShader(p, kShaderType_LabelDistanceFieldGlow);
|
||||
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW, p) );
|
||||
|
||||
p = new GLProgram();
|
||||
loadDefaultShader(p, kShaderType_LabelDistanceFieldOutline);
|
||||
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE, p) );
|
||||
|
||||
p = new GLProgram();
|
||||
loadDefaultShader(p, kShaderType_LabelDistanceFieldShadow);
|
||||
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW, p) );
|
||||
}
|
||||
|
||||
void ShaderCache::reloadDefaultShaders()
|
||||
|
@ -206,6 +231,22 @@ void ShaderCache::reloadDefaultShaders()
|
|||
p = getProgram(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR);
|
||||
p->reset();
|
||||
loadDefaultShader(p, kShaderType_PositionLengthTexureColor);
|
||||
|
||||
p = getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL);
|
||||
p->reset();
|
||||
loadDefaultShader(p, kShaderType_LabelDistanceFieldNormal);
|
||||
|
||||
p = getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW);
|
||||
p->reset();
|
||||
loadDefaultShader(p, kShaderType_LabelDistanceFieldGlow);
|
||||
|
||||
p = getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE);
|
||||
p->reset();
|
||||
loadDefaultShader(p, kShaderType_LabelDistanceFieldOutline);
|
||||
|
||||
p = getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW);
|
||||
p->reset();
|
||||
loadDefaultShader(p, kShaderType_LabelDistanceFieldShadow);
|
||||
}
|
||||
|
||||
void ShaderCache::loadDefaultShader(GLProgram *p, int type)
|
||||
|
@ -219,6 +260,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);
|
||||
|
||||
|
@ -269,6 +319,38 @@ void ShaderCache::loadDefaultShader(GLProgram *p, int type)
|
|||
p->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
|
||||
p->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
|
||||
|
||||
break;
|
||||
case kShaderType_LabelDistanceFieldNormal:
|
||||
p->initWithVertexShaderByteArray(ccLabelDistanceFieldNormal_vert, ccLabelDistanceFieldNormal_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_LabelDistanceFieldGlow:
|
||||
p->initWithVertexShaderByteArray(ccLabelDistanceFieldGlow_vert, ccLabelDistanceFieldGlow_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_LabelDistanceFieldOutline:
|
||||
p->initWithVertexShaderByteArray(ccLabelDistanceFieldOutline_vert, ccLabelDistanceFieldOutline_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_LabelDistanceFieldShadow:
|
||||
p->initWithVertexShaderByteArray(ccLabelDistanceFieldShadow_vert, ccLabelDistanceFieldShadow_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;
|
||||
default:
|
||||
CCLOG("cocos2d: %s:%d, error shader type", __FUNCTION__, __LINE__);
|
||||
|
|
|
@ -44,6 +44,8 @@ THE SOFTWARE.
|
|||
#include "CCAffineTransform.h"
|
||||
#include "TransformUtils.h"
|
||||
#include "CCProfiling.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.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);
|
||||
|
@ -494,14 +496,14 @@ void Sprite::setTextureCoords(Rect rect)
|
|||
void Sprite::updateTransform(void)
|
||||
{
|
||||
CCASSERT(_batchNode, "updateTransform is only valid when Sprite is being rendered using an SpriteBatchNode");
|
||||
|
||||
|
||||
#ifdef CC_USE_PHYSICS
|
||||
if (updatePhysicsTransform())
|
||||
{
|
||||
setDirty(true);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
// recalculate matrix only if it is dirty
|
||||
if( isDirty() ) {
|
||||
|
||||
|
@ -511,7 +513,7 @@ void Sprite::updateTransform(void)
|
|||
_quad.br.vertices = _quad.tl.vertices = _quad.tr.vertices = _quad.bl.vertices = Vertex3F(0,0,0);
|
||||
_shouldBeHidden = true;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
_shouldBeHidden = false;
|
||||
|
||||
|
@ -519,10 +521,12 @@ void Sprite::updateTransform(void)
|
|||
{
|
||||
_transformToBatch = getNodeToParentTransform();
|
||||
}
|
||||
else
|
||||
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;
|
||||
|
||||
|
@ -566,14 +570,14 @@ void Sprite::updateTransform(void)
|
|||
{
|
||||
_textureAtlas->updateQuad(&_quad, _atlasIndex);
|
||||
}
|
||||
|
||||
|
||||
_recursiveDirty = false;
|
||||
setDirty(false);
|
||||
}
|
||||
|
||||
// MARMALADE CHANGED
|
||||
// recursively iterate over children
|
||||
/* if( _hasChildren )
|
||||
/* if( _hasChildren )
|
||||
{
|
||||
// MARMALADE: CHANGED TO USE Node*
|
||||
// NOTE THAT WE HAVE ALSO DEFINED virtual Node::updateTransform()
|
||||
|
@ -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();
|
||||
|
||||
GL::blendFunc( _blendFunc.src, _blendFunc.dst );
|
||||
//TODO implement z order
|
||||
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
|
||||
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv);
|
||||
Director::getInstance()->getRenderer()->addCommand(renderCommand);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
// color
|
||||
diff = offsetof( V3F_C4B_T2F, colors);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
|
||||
// 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 );
|
||||
// }
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
//TODO optimize this transformation, should use parent's transformation instead
|
||||
_transformToBatch = getNodeToWorldTransform();
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
//
|
||||
// calculate the Quad based on the Affine Matrix
|
||||
//
|
||||
|
||||
Size size = _rect.size;
|
||||
|
||||
#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 x1 = _offsetPosition.x;
|
||||
float y1 = _offsetPosition.y;
|
||||
|
||||
CC_INCREMENT_GL_DRAWS(1);
|
||||
float x2 = x1 + size.width;
|
||||
float y2 = y1 + size.height;
|
||||
float x = _transformToBatch.mat[12];
|
||||
float y = _transformToBatch.mat[13];
|
||||
|
||||
CC_PROFILER_STOP_CATEGORY(kProfilerCategorySprite, "CCSprite - draw");
|
||||
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;
|
||||
|
||||
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
|
||||
|
@ -726,7 +817,7 @@ void Sprite::removeAllChildrenWithCleanup(bool cleanup)
|
|||
{
|
||||
if (_batchNode)
|
||||
{
|
||||
_children.forEach([this](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this](Node* child){
|
||||
Sprite* sprite = dynamic_cast<Sprite*>(child);
|
||||
if (sprite)
|
||||
{
|
||||
|
@ -772,7 +863,7 @@ void Sprite::sortAllChildren()
|
|||
|
||||
if ( _batchNode)
|
||||
{
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->sortAllChildren();
|
||||
});
|
||||
}
|
||||
|
@ -809,7 +900,7 @@ void Sprite::setDirtyRecursively(bool bValue)
|
|||
// recursively set dirty
|
||||
if (_hasChildren)
|
||||
{
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
Sprite* sp = dynamic_cast<Sprite*>(child);
|
||||
if (sp)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
/// @}
|
||||
|
||||
|
@ -544,7 +547,7 @@ protected:
|
|||
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
|
||||
|
|
|
@ -270,7 +270,7 @@ void SpriteBatchNode::sortAllChildren()
|
|||
if (!_children.empty())
|
||||
{
|
||||
//first sort all children recursively based on zOrder
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->sortAllChildren();
|
||||
});
|
||||
|
||||
|
@ -278,7 +278,7 @@ void SpriteBatchNode::sortAllChildren()
|
|||
|
||||
//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
|
||||
_children.forEach([this, &index](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [this, &index](Node* child){
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
updateAtlasIndex(sp, &index);
|
||||
});
|
||||
|
@ -324,7 +324,7 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, ssize_t* curIndex)
|
|||
needNewIndex = false;
|
||||
}
|
||||
|
||||
array.forEach([&](Node* child){
|
||||
std::for_each(array.begin(), array.end(), [&](Node* child){
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (needNewIndex && sp->getZOrder() >= 0)
|
||||
{
|
||||
|
@ -390,7 +390,7 @@ void SpriteBatchNode::draw(void)
|
|||
|
||||
CC_NODE_DRAW_SETUP();
|
||||
|
||||
_children.forEach([](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [](Node* child){
|
||||
child->updateTransform();
|
||||
});
|
||||
|
||||
|
@ -426,7 +426,7 @@ ssize_t SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, ssize_t index)
|
|||
|
||||
auto& children = parent->getChildren();
|
||||
|
||||
children.forEach([this, &index](Node* child){
|
||||
std::for_each(children.begin(), children.end(), [this, &index](Node* child){
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (sp && (sp->getZOrder() < 0))
|
||||
{
|
||||
|
@ -441,7 +441,7 @@ ssize_t SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, ssize_t index)
|
|||
index++;
|
||||
}
|
||||
|
||||
children.forEach([this, &index](Node* child){
|
||||
std::for_each(children.begin(), children.end(), [this, &index](Node* child){
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (sp && (sp->getZOrder() >= 0))
|
||||
{
|
||||
|
@ -559,7 +559,8 @@ void SpriteBatchNode::appendChild(Sprite* sprite)
|
|||
_textureAtlas->insertQuad(&quad, index);
|
||||
|
||||
// add children recursively
|
||||
sprite->getChildren().forEach([this](Node* child){
|
||||
auto& children = sprite->getChildren();
|
||||
std::for_each(children.begin(), children.end(), [this](Node* child){
|
||||
appendChild(static_cast<Sprite*>(child));
|
||||
});
|
||||
}
|
||||
|
@ -586,7 +587,7 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
|||
|
||||
// remove children recursively
|
||||
auto& children = sprite->getChildren();
|
||||
children.forEach([this](Node* obj){
|
||||
std::for_each(children.begin(), children.end(), [this](Node* obj){
|
||||
Sprite* child = static_cast<Sprite*>(obj);
|
||||
if (child)
|
||||
{
|
||||
|
|
|
@ -389,7 +389,7 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
|||
|
||||
// update possible children
|
||||
|
||||
_children.forEach([&indexForZ](Node* child){
|
||||
std::for_each(_children.begin(), _children.end(), [&indexForZ](Node* child){
|
||||
Sprite* sp = static_cast<Sprite*>(child);
|
||||
if (child)
|
||||
{
|
||||
|
@ -594,7 +594,7 @@ void TMXLayer::removeTileAt(const Point& pos)
|
|||
_textureAtlas->removeQuadAtIndex(atlasIndex);
|
||||
|
||||
// update possible children
|
||||
_children.forEach([&atlasIndex](Node* obj){
|
||||
std::for_each(_children.begin(), _children.end(), [&atlasIndex](Node* obj){
|
||||
Sprite* child = static_cast<Sprite*>(obj);
|
||||
if (child)
|
||||
{
|
||||
|
|
|
@ -168,7 +168,8 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
|
|||
|
||||
int idx=0;
|
||||
|
||||
mapInfo->getLayers().forEach([&idx, this, &mapInfo](TMXLayerInfo* layerInfo){
|
||||
auto& layers = mapInfo->getLayers();
|
||||
std::for_each(layers.begin(), layers.end(), [&idx, this, &mapInfo](TMXLayerInfo* layerInfo){
|
||||
if (layerInfo && layerInfo->_visible)
|
||||
{
|
||||
TMXLayer *child = parseLayer(layerInfo, mapInfo);
|
||||
|
|
|
@ -88,8 +88,8 @@ bool TextPageDef::generatePageTexture(bool releasePageData)
|
|||
if (!_pageTexture)
|
||||
return false;
|
||||
|
||||
int dataLenght = (_width * _height * 4);
|
||||
bool textureCreated = _pageTexture->initWithData(_pageData, dataLenght, Texture2D::PixelFormat::RGBA8888, _width, _height, imageSize);
|
||||
int dataLenght = (_width * _height * 1);
|
||||
bool textureCreated = _pageTexture->initWithData(_pageData, dataLenght, Texture2D::PixelFormat::A8, _width, _height, imageSize);
|
||||
|
||||
// release the page data if requested
|
||||
if (releasePageData && textureCreated)
|
||||
|
@ -421,7 +421,7 @@ unsigned char * TextImage::renderGlyphData(TextPageDef *thePage)
|
|||
int pageHeight = thePage->getHeight();
|
||||
|
||||
// prepare memory and clean to 0
|
||||
int sizeInBytes = (pageWidth * pageHeight * 4);
|
||||
int sizeInBytes = (pageWidth * pageHeight * 1);
|
||||
unsigned char* data = new unsigned char[sizeInBytes];
|
||||
|
||||
if (!data)
|
||||
|
@ -443,7 +443,7 @@ unsigned char * TextImage::renderGlyphData(TextPageDef *thePage)
|
|||
for (int cglyph = 0; cglyph < numGlyphToRender; ++cglyph)
|
||||
{
|
||||
GlyphDef currGlyph = currentLine->getGlyphAt(cglyph);
|
||||
renderCharAt(currGlyph.getUTF8Letter(), origX, origY, data, pageWidth);
|
||||
_font->renderCharAt(currGlyph.getUTF8Letter(), origX, origY, data, pageWidth);
|
||||
origX += (currGlyph.getRect().size.width + _font->getLetterPadding());
|
||||
}
|
||||
}
|
||||
|
@ -462,47 +462,6 @@ unsigned char * TextImage::renderGlyphData(TextPageDef *thePage)
|
|||
return data;
|
||||
}
|
||||
|
||||
bool TextImage::renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize)
|
||||
{
|
||||
if (!_font)
|
||||
return false;
|
||||
|
||||
unsigned char *sourceBitmap = 0;
|
||||
int sourceWidth = 0;
|
||||
int sourceHeight = 0;
|
||||
|
||||
// get the glyph's bitmap
|
||||
sourceBitmap = _font->getGlyphBitmap(charToRender, sourceWidth, sourceHeight);
|
||||
|
||||
if (!sourceBitmap)
|
||||
return false;
|
||||
|
||||
int iX = posX;
|
||||
int iY = posY;
|
||||
|
||||
for (int y = 0; y < sourceHeight; ++y)
|
||||
{
|
||||
int bitmap_y = y * sourceWidth;
|
||||
|
||||
for (int x = 0; x < sourceWidth; ++x)
|
||||
{
|
||||
unsigned char cTemp = sourceBitmap[bitmap_y + x];
|
||||
|
||||
// the final pixel
|
||||
int iTemp = cTemp << 24 | cTemp << 16 | cTemp << 8 | cTemp;
|
||||
*(int*) &destMemory[(iX + ( iY * destSize ) ) * 4] = iTemp;
|
||||
|
||||
iX += 1;
|
||||
}
|
||||
|
||||
iX = posX;
|
||||
iY += 1;
|
||||
}
|
||||
|
||||
//everything good
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
||||
|
|
|
@ -197,7 +197,6 @@ private:
|
|||
|
||||
// glyph rendering
|
||||
unsigned char * renderGlyphData(TextPageDef *thePage);
|
||||
bool renderCharAt(unsigned short int charToRender, int posX, int posY, unsigned char *destMemory, int destSize);
|
||||
|
||||
std::map<unsigned short int, GlyphDef> _textGlyphs;
|
||||
TextFontPagesDef * _fontPages;
|
||||
|
|
|
@ -215,6 +215,8 @@ public:
|
|||
void setQuads(V3F_C4B_T2F_Quad* quads);
|
||||
|
||||
private:
|
||||
void renderCommand();
|
||||
|
||||
void setupIndices();
|
||||
void mapBuffers();
|
||||
void setupVBOandVAO();
|
||||
|
|
|
@ -112,7 +112,7 @@ void TextureCache::addImageAsync(const std::string &path, Object *target, SEL_Ca
|
|||
if (_asyncStructQueue == NULL)
|
||||
{
|
||||
_asyncStructQueue = new queue<AsyncStruct*>();
|
||||
_imageInfoQueue = new queue<ImageInfo*>();
|
||||
_imageInfoQueue = new deque<ImageInfo*>();
|
||||
|
||||
// create a new thread to load images
|
||||
_loadingThread = new std::thread(&TextureCache::loadImage, this);
|
||||
|
@ -170,17 +170,40 @@ void TextureCache::loadImage()
|
|||
_asyncStructQueueMutex.unlock();
|
||||
}
|
||||
|
||||
const char *filename = asyncStruct->filename.c_str();
|
||||
|
||||
// generate image
|
||||
Image *image = new Image();
|
||||
if (image && !image->initWithImageFileThreadSafe(filename))
|
||||
Image *image = nullptr;
|
||||
bool generateImage = false;
|
||||
|
||||
auto it = _textures.find(asyncStruct->filename);
|
||||
if( it == _textures.end() )
|
||||
{
|
||||
CC_SAFE_RELEASE(image);
|
||||
CCLOG("can not load %s", filename);
|
||||
continue;
|
||||
_imageInfoMutex.lock();
|
||||
ImageInfo *imageInfo;
|
||||
size_t pos = 0;
|
||||
size_t infoSize = _imageInfoQueue->size();
|
||||
for (; pos < infoSize; pos++)
|
||||
{
|
||||
imageInfo = (*_imageInfoQueue)[pos];
|
||||
if(imageInfo->asyncStruct->filename.compare(asyncStruct->filename))
|
||||
break;
|
||||
}
|
||||
_imageInfoMutex.unlock();
|
||||
if(infoSize > 0 && pos < infoSize)
|
||||
generateImage = true;
|
||||
}
|
||||
|
||||
if (generateImage)
|
||||
{
|
||||
const char *filename = asyncStruct->filename.c_str();
|
||||
// generate image
|
||||
image = new Image();
|
||||
if (image && !image->initWithImageFileThreadSafe(filename))
|
||||
{
|
||||
CC_SAFE_RELEASE(image);
|
||||
CCLOG("can not load %s", filename);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// generate image info
|
||||
ImageInfo *imageInfo = new ImageInfo();
|
||||
imageInfo->asyncStruct = asyncStruct;
|
||||
|
@ -188,7 +211,7 @@ void TextureCache::loadImage()
|
|||
|
||||
// put the image info into the queue
|
||||
_imageInfoMutex.lock();
|
||||
_imageInfoQueue->push(imageInfo);
|
||||
_imageInfoQueue->push_back(imageInfo);
|
||||
_imageInfoMutex.unlock();
|
||||
}
|
||||
|
||||
|
@ -204,7 +227,7 @@ void TextureCache::loadImage()
|
|||
void TextureCache::addImageAsyncCallBack(float dt)
|
||||
{
|
||||
// the image is generated in loading thread
|
||||
std::queue<ImageInfo*> *imagesQueue = _imageInfoQueue;
|
||||
std::deque<ImageInfo*> *imagesQueue = _imageInfoQueue;
|
||||
|
||||
_imageInfoMutex.lock();
|
||||
if (imagesQueue->empty())
|
||||
|
@ -214,7 +237,7 @@ void TextureCache::addImageAsyncCallBack(float dt)
|
|||
else
|
||||
{
|
||||
ImageInfo *imageInfo = imagesQueue->front();
|
||||
imagesQueue->pop();
|
||||
imagesQueue->pop_front();
|
||||
_imageInfoMutex.unlock();
|
||||
|
||||
AsyncStruct *asyncStruct = imageInfo->asyncStruct;
|
||||
|
@ -224,28 +247,40 @@ void TextureCache::addImageAsyncCallBack(float dt)
|
|||
SEL_CallFuncO selector = asyncStruct->selector;
|
||||
const char* filename = asyncStruct->filename.c_str();
|
||||
|
||||
// generate texture in render thread
|
||||
Texture2D *texture = new Texture2D();
|
||||
Texture2D *texture = nullptr;
|
||||
if (image)
|
||||
{
|
||||
// generate texture in render thread
|
||||
texture = new Texture2D();
|
||||
|
||||
texture->initWithImage(image);
|
||||
texture->initWithImage(image);
|
||||
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
// cache the texture file name
|
||||
VolatileTextureMgr::addImageTexture(texture, filename);
|
||||
// cache the texture file name
|
||||
VolatileTextureMgr::addImageTexture(texture, filename);
|
||||
#endif
|
||||
// cache the texture. retain it, since it is added in the map
|
||||
_textures.insert( std::make_pair(filename, texture) );
|
||||
texture->retain();
|
||||
|
||||
texture->autorelease();
|
||||
// cache the texture. retain it, since it is added in the map
|
||||
_textures.insert( std::make_pair(filename, texture) );
|
||||
texture->retain();
|
||||
|
||||
texture->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = _textures.find(asyncStruct->filename);
|
||||
if(it != _textures.end())
|
||||
texture = it->second;
|
||||
}
|
||||
|
||||
if (target && selector)
|
||||
{
|
||||
(target->*selector)(texture);
|
||||
target->release();
|
||||
}
|
||||
|
||||
image->release();
|
||||
if(image)
|
||||
{
|
||||
image->release();
|
||||
}
|
||||
delete asyncStruct;
|
||||
delete imageInfo;
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ protected:
|
|||
std::thread* _loadingThread;
|
||||
|
||||
std::queue<AsyncStruct*>* _asyncStructQueue;
|
||||
std::queue<ImageInfo*>* _imageInfoQueue;
|
||||
std::deque<ImageInfo*>* _imageInfoQueue;
|
||||
|
||||
std::mutex _asyncStructQueueMutex;
|
||||
std::mutex _imageInfoMutex;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -138,6 +138,23 @@ set(COCOS2D_SRC
|
|||
platform/CCThread.cpp
|
||||
platform/CCEGLViewProtocol.cpp
|
||||
platform/CCFileUtils.cpp
|
||||
../../external/edtaa3func/edtaa3func.cpp
|
||||
renderer/CCNewDrawNode.cpp
|
||||
renderer/CCNewLabelAtlas.cpp
|
||||
renderer/CCNewParticleSystemQuad.cpp
|
||||
renderer/CCNewRenderTexture.cpp
|
||||
renderer/CCNewSprite.cpp
|
||||
renderer/CCNewSpriteBatchNode.cpp
|
||||
renderer/CCNewTextureAtlas.cpp
|
||||
renderer/CCCustomCommand.cpp
|
||||
renderer/CCFrustum.cpp
|
||||
renderer/CCGroupCommand.cpp
|
||||
renderer/CCMaterialManager.cpp
|
||||
renderer/CCNewClippingNode.cpp
|
||||
renderer/CCQuadCommand.cpp
|
||||
renderer/CCRenderCommand.cpp
|
||||
renderer/CCRenderer.cpp
|
||||
renderer/CCRenderMaterial.cpp
|
||||
)
|
||||
|
||||
include(../physics/CMakeLists.txt)
|
||||
|
|
|
@ -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,24 @@
|
|||
" \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\
|
||||
vec4 color = texture2D(CC_Texture0, v_texCoord); \n\
|
||||
//the texture use dual channel 16-bit output for distance_map \n\
|
||||
//float dist = color.b+color.g/256.0; \n\
|
||||
// the texture use single channel 8-bit output for distance_map \n\
|
||||
float dist = color.a; \n\
|
||||
//todo:Implementation 'fwidth' for glsl 1.0 \n\
|
||||
//float width = fwidth(dist); \n\
|
||||
//assign width for constant will lead to a little bit fuzzy,it's temporary measure.\n\
|
||||
float width = 0.04; \n\
|
||||
float alpha = smoothstep(0.5-width, 0.5+width, dist); \n\
|
||||
gl_FragColor = vec4(v_fragmentColor.rgb,alpha); \n\
|
||||
} \n\
|
||||
";
|
|
@ -0,0 +1,24 @@
|
|||
" \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\
|
||||
uniform vec3 v_effectColor; \n\
|
||||
\n\
|
||||
void main() \n\
|
||||
{ \n\
|
||||
float dist = texture2D(CC_Texture0, v_texCoord).a; \n\
|
||||
//todo:Implementation 'fwidth' for glsl 1.0 \n\
|
||||
//float width = fwidth(dist); \n\
|
||||
//assign width for constant will lead to a little bit fuzzy,it's temporary measure.\n\
|
||||
float width = 0.04; \n\
|
||||
float alpha = smoothstep(0.5-width, 0.5+width, dist); \n\
|
||||
//glow \n\
|
||||
float mu = smoothstep(0.5, 1.0, sqrt(dist)); \n\
|
||||
vec3 rgb = v_effectColor*(1.0-alpha) + v_fragmentColor.rgb*alpha; \n\
|
||||
gl_FragColor = vec4(rgb, max(alpha,mu)); \n\
|
||||
} \n\
|
||||
";
|
|
@ -0,0 +1,24 @@
|
|||
" \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\
|
||||
uniform vec3 v_effectColor; \n\
|
||||
\n\
|
||||
void main() \n\
|
||||
{ \n\
|
||||
float dist = texture2D(CC_Texture0, v_texCoord).a; \n\
|
||||
//todo:Implementation 'fwidth' for glsl 1.0 \n\
|
||||
//float width = fwidth(dist); \n\
|
||||
//assign width for constant will lead to a little bit fuzzy,it's temporary measure.\n\
|
||||
float width = 0.04; \n\
|
||||
float alpha = smoothstep(0.5-width, 0.5+width, dist); \n\
|
||||
//outline \n\
|
||||
float mu = smoothstep(0.545-width, 0.545+width, dist); \n\
|
||||
vec3 rgb = v_effectColor*(1.0-mu) + v_fragmentColor.rgb*mu; \n\
|
||||
gl_FragColor = vec4(rgb, max(alpha,mu)); \n\
|
||||
} \n\
|
||||
";
|
|
@ -0,0 +1,34 @@
|
|||
" \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\
|
||||
uniform vec3 v_effectColor; \n\
|
||||
uniform vec2 v_shadowOffset; \n\
|
||||
\n\
|
||||
void main() \n\
|
||||
{ \n\
|
||||
float dist = texture2D(CC_Texture0, v_texCoord).a; \n\
|
||||
//todo:support for assign offset,but the shadow is limited by renderable area \n\
|
||||
vec2 offset = vec2(-0.0015,-0.0015); \n\
|
||||
float dist2 = texture2D(CC_Texture0, v_texCoord+offset).a; \n\
|
||||
//todo:Implementation 'fwidth' for glsl 1.0 \n\
|
||||
//float width = fwidth(dist); \n\
|
||||
//assign width for constant will lead to a little bit fuzzy,it's temporary measure.\n\
|
||||
float width = 0.04; \n\
|
||||
// If v is 1 then it's inside the Glyph; if it's 0 then it's outside \n\
|
||||
float v = smoothstep(0.5-width, 0.5+width, dist); \n\
|
||||
// If s is 1 then it's inside the shadow; if it's 0 then it's outside \n\
|
||||
float s = smoothstep(0.5-width, 0.5+width, dist2); \n\
|
||||
if(v == 1.0) gl_FragColor = vec4(v_fragmentColor.rgb,1.0); \n\
|
||||
else if(v == 0.0) gl_FragColor = vec4(v_effectColor,s); \n\
|
||||
else \n\
|
||||
{ \n\
|
||||
vec3 color = v_fragmentColor.rgb*v + v_effectColor*s*(1.0-v); \n\
|
||||
gl_FragColor = vec4(color,max(s,v)); \n\
|
||||
} \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 = CC_MVPMatrix * a_position; \n\
|
||||
v_fragmentColor = a_color; \n\
|
||||
v_texCoord = a_texCoord; \n\
|
||||
} \n\
|
||||
";
|
|
@ -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"
|
||||
|
@ -74,4 +80,24 @@ const GLchar * ccPositionColorLengthTexture_frag =
|
|||
const GLchar * ccPositionColorLengthTexture_vert =
|
||||
#include "ccShader_PositionColorLengthTexture_vert.h"
|
||||
|
||||
const GLchar * ccLabelDistanceFieldNormal_frag =
|
||||
#include "ccShader_Label_frag.h"
|
||||
const GLchar * ccLabelDistanceFieldNormal_vert =
|
||||
#include "ccShader_Label_vert.h"
|
||||
|
||||
const GLchar * ccLabelDistanceFieldGlow_frag =
|
||||
#include "ccShader_Label_frag_glow.h"
|
||||
const GLchar * ccLabelDistanceFieldGlow_vert =
|
||||
#include "ccShader_Label_vert.h"
|
||||
|
||||
const GLchar * ccLabelDistanceFieldOutline_frag =
|
||||
#include "ccShader_Label_frag_outline.h"
|
||||
const GLchar * ccLabelDistanceFieldOutline_vert =
|
||||
#include "ccShader_Label_vert.h"
|
||||
|
||||
const GLchar * ccLabelDistanceFieldShadow_frag =
|
||||
#include "ccShader_Label_frag_shadow.h"
|
||||
const GLchar * ccLabelDistanceFieldShadow_vert =
|
||||
#include "ccShader_Label_vert.h"
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -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;
|
||||
|
@ -58,6 +61,18 @@ extern CC_DLL const GLchar * ccPositionTexture_uColor_vert;
|
|||
extern CC_DLL const GLchar * ccPositionColorLengthTexture_frag;
|
||||
extern CC_DLL const GLchar * ccPositionColorLengthTexture_vert;
|
||||
|
||||
extern CC_DLL const GLchar * ccLabelDistanceFieldNormal_frag;
|
||||
extern CC_DLL const GLchar * ccLabelDistanceFieldNormal_vert;
|
||||
|
||||
extern CC_DLL const GLchar * ccLabelDistanceFieldGlow_frag;
|
||||
extern CC_DLL const GLchar * ccLabelDistanceFieldGlow_vert;
|
||||
|
||||
extern CC_DLL const GLchar * ccLabelDistanceFieldOutline_frag;
|
||||
extern CC_DLL const GLchar * ccLabelDistanceFieldOutline_vert;
|
||||
|
||||
extern CC_DLL const GLchar * ccLabelDistanceFieldShadow_frag;
|
||||
extern CC_DLL const GLchar * ccLabelDistanceFieldShadow_vert;
|
||||
|
||||
extern CC_DLL const GLchar * ccExSwitchMask_frag;
|
||||
|
||||
// end of shaders group
|
||||
|
|
|
@ -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 operator==(const BlendFunc &a) const
|
||||
{
|
||||
return src == a.src && dst == a.dst;
|
||||
}
|
||||
|
||||
bool operator<(const BlendFunc &a) const
|
||||
{
|
||||
return src < a.src || (src < a.src && dst < a.dst);
|
||||
}
|
||||
};
|
||||
|
||||
// Label::VAlignment
|
||||
|
|
|
@ -118,6 +118,25 @@ THE SOFTWARE.
|
|||
#include "CCParticleExamples.h"
|
||||
#include "CCParticleSystemQuad.h"
|
||||
|
||||
// new renderer
|
||||
#include "renderer/CCNewDrawNode.h"
|
||||
#include "renderer/CCNewLabelAtlas.h"
|
||||
#include "renderer/CCNewParticleSystemQuad.h"
|
||||
#include "renderer/CCNewRenderTexture.h"
|
||||
#include "renderer/CCNewSprite.h"
|
||||
#include "renderer/CCNewSpriteBatchNode.h"
|
||||
#include "renderer/CCNewTextureAtlas.h"
|
||||
#include "renderer/CCCustomCommand.h"
|
||||
#include "renderer/CCFrustum.h"
|
||||
#include "renderer/CCGroupCommand.h"
|
||||
#include "renderer/CCMaterialManager.h"
|
||||
#include "renderer/CCNewClippingNode.h"
|
||||
#include "renderer/CCQuadCommand.h"
|
||||
#include "renderer/CCRenderCommand.h"
|
||||
#include "renderer/CCRenderCommandPool.h"
|
||||
#include "renderer/CCRenderMaterial.h"
|
||||
#include "renderer/CCRenderer.h"
|
||||
|
||||
// physics
|
||||
#include "CCPhysicsBody.h"
|
||||
#include "CCPhysicsContact.h"
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
</PreBuildEvent>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
|
@ -120,7 +120,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
</Command>
|
||||
</PreBuildEvent>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>
|
||||
|
@ -162,6 +162,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\external\edtaa3func\edtaa3func.cpp" />
|
||||
<ClCompile Include="..\..\external\tinyxml2\tinyxml2.cpp" />
|
||||
<ClCompile Include="..\..\external\unzip\ioapi.cpp" />
|
||||
<ClCompile Include="..\..\external\unzip\unzip.cpp" />
|
||||
|
@ -316,11 +317,28 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClCompile Include="platform\win32\CCFileUtilsWin32.cpp" />
|
||||
<ClCompile Include="platform\win32\CCImage.cpp" />
|
||||
<ClCompile Include="platform\win32\CCStdC.cpp" />
|
||||
<ClCompile Include="renderer\CCCustomCommand.cpp" />
|
||||
<ClCompile Include="renderer\CCFrustum.cpp" />
|
||||
<ClCompile Include="renderer\CCGroupCommand.cpp" />
|
||||
<ClCompile Include="renderer\CCMaterialManager.cpp" />
|
||||
<ClCompile Include="renderer\CCNewClippingNode.cpp" />
|
||||
<ClCompile Include="renderer\CCNewDrawNode.cpp" />
|
||||
<ClCompile Include="renderer\CCNewLabelAtlas.cpp" />
|
||||
<ClCompile Include="renderer\CCNewParticleSystemQuad.cpp" />
|
||||
<ClCompile Include="renderer\CCNewRenderTexture.cpp" />
|
||||
<ClCompile Include="renderer\CCNewSprite.cpp" />
|
||||
<ClCompile Include="renderer\CCNewSpriteBatchNode.cpp" />
|
||||
<ClCompile Include="renderer\CCNewTextureAtlas.cpp" />
|
||||
<ClCompile Include="renderer\CCQuadCommand.cpp" />
|
||||
<ClCompile Include="renderer\CCRenderCommand.cpp" />
|
||||
<ClCompile Include="renderer\CCRenderer.cpp" />
|
||||
<ClCompile Include="renderer\CCRenderMaterial.cpp" />
|
||||
<ClCompile Include="TGAlib.cpp" />
|
||||
<ClCompile Include="TransformUtils.cpp" />
|
||||
<ClCompile Include="ZipUtils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\external\edtaa3func\edtaa3func.h" />
|
||||
<ClInclude Include="..\..\external\tinyxml2\tinyxml2.h" />
|
||||
<ClInclude Include="..\..\external\unzip\ioapi.h" />
|
||||
<ClInclude Include="..\..\external\unzip\unzip.h" />
|
||||
|
@ -511,6 +529,23 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
|
|||
<ClInclude Include="platform\win32\CCGL.h" />
|
||||
<ClInclude Include="platform\win32\CCPlatformDefine.h" />
|
||||
<ClInclude Include="platform\win32\CCStdC.h" />
|
||||
<ClInclude Include="renderer\CCCustomCommand.h" />
|
||||
<ClInclude Include="renderer\CCFrustum.h" />
|
||||
<ClInclude Include="renderer\CCGroupCommand.h" />
|
||||
<ClInclude Include="renderer\CCMaterialManager.h" />
|
||||
<ClInclude Include="renderer\CCNewClippingNode.h" />
|
||||
<ClInclude Include="renderer\CCNewDrawNode.h" />
|
||||
<ClInclude Include="renderer\CCNewLabelAtlas.h" />
|
||||
<ClInclude Include="renderer\CCNewParticleSystemQuad.h" />
|
||||
<ClInclude Include="renderer\CCNewRenderTexture.h" />
|
||||
<ClInclude Include="renderer\CCNewSprite.h" />
|
||||
<ClInclude Include="renderer\CCNewSpriteBatchNode.h" />
|
||||
<ClInclude Include="renderer\CCNewTextureAtlas.h" />
|
||||
<ClInclude Include="renderer\CCQuadCommand.h" />
|
||||
<ClInclude Include="renderer\CCRenderCommand.h" />
|
||||
<ClInclude Include="renderer\CCRenderCommandPool.h" />
|
||||
<ClInclude Include="renderer\CCRenderer.h" />
|
||||
<ClInclude Include="renderer\CCRenderMaterial.h" />
|
||||
<ClInclude Include="TGAlib.h" />
|
||||
<ClInclude Include="TransformUtils.h" />
|
||||
<ClInclude Include="uthash.h" />
|
||||
|
|
|
@ -109,6 +109,9 @@
|
|||
<Filter Include="base">
|
||||
<UniqueIdentifier>{aec8225f-81a7-4213-b97b-7004d5535398}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="renderer">
|
||||
<UniqueIdentifier>{cba0f362-878c-438b-ad0f-43d287516357}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\physics\CCPhysicsBody.cpp">
|
||||
|
@ -566,6 +569,57 @@
|
|||
<ClCompile Include="..\base\CCValue.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\external\edtaa3func\edtaa3func.cpp">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCCustomCommand.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCFrustum.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCGroupCommand.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCMaterialManager.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewClippingNode.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewDrawNode.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewLabelAtlas.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewParticleSystemQuad.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewRenderTexture.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewSprite.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewSpriteBatchNode.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCNewTextureAtlas.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCQuadCommand.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCRenderCommand.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCRenderer.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="renderer\CCRenderMaterial.cpp">
|
||||
<Filter>renderer</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\physics\CCPhysicsBody.h">
|
||||
|
@ -1143,5 +1197,59 @@
|
|||
<ClInclude Include="..\base\CCVector.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\external\edtaa3func\edtaa3func.h">
|
||||
<Filter>label_nodes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCCustomCommand.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCFrustum.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCGroupCommand.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCMaterialManager.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewClippingNode.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewDrawNode.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewLabelAtlas.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewParticleSystemQuad.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewRenderTexture.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewSprite.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewSpriteBatchNode.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCNewTextureAtlas.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCQuadCommand.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCRenderCommand.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCRenderCommandPool.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCRenderer.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="renderer\CCRenderMaterial.h">
|
||||
<Filter>renderer</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -7,7 +7,7 @@
|
|||
<PropertyGroup />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(EngineRoot)cocos\2d;$(EngineRoot)cocos\gui;$(EngineRoot)cocos\base;$(EngineRoot)cocos\physics;$(EngineRoot)cocos\math\kazmath\include;$(EngineRoot)cocos\2d\platform\win32;$(EngineRoot)external\glfw3\include\win32;$(EngineRoot)external\win32-specific\gles\include\OGLES</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(EngineRoot)cocos\2d;$(EngineRoot)cocos\2d\renderer;$(EngineRoot)cocos\gui;$(EngineRoot)cocos\base;$(EngineRoot)cocos\physics;$(EngineRoot)cocos\math\kazmath\include;$(EngineRoot)cocos\2d\platform\win32;$(EngineRoot)external\glfw3\include\win32;$(EngineRoot)external\win32-specific\gles\include\OGLES</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_VARIADIC_MAX=10;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/****************************************************************************
|
||||
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 "CCCustomCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
RenderCommandPool<CustomCommand> CustomCommand::_commandPool;
|
||||
|
||||
CustomCommand::CustomCommand()
|
||||
:RenderCommand()
|
||||
, _viewport(0)
|
||||
, _depth(0)
|
||||
, func(nullptr)
|
||||
{
|
||||
_type = RenderCommand::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,73 @@
|
|||
/****************************************************************************
|
||||
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 _CC_CUSTOMCOMMAND_H_
|
||||
#define _CC_CUSTOMCOMMAND_H_
|
||||
|
||||
#include "CCRenderCommand.h"
|
||||
#include "CCRenderCommandPool.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
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:
|
||||
std::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,415 @@
|
|||
/****************************************************************************
|
||||
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 "CCFrustum.h"
|
||||
#include "platform/CCCommon.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
ViewTransform::ViewTransform()
|
||||
{
|
||||
kmVec3Fill(&_position,0,0,0);
|
||||
kmVec3Fill(&_focus,0,0,-1);
|
||||
kmVec3Fill(&_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::FRUSTUM_NEAR], &point, &normal);
|
||||
}
|
||||
|
||||
//far
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
kmVec3Scale(&normal, &cDir, -1);
|
||||
kmVec3Scale(&point, &cDir, far);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_FAR], &point, &normal);
|
||||
}
|
||||
|
||||
//left
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
normal = cRight;
|
||||
kmVec3Scale(&point, &cRight, -width * 0.5);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_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::FRUSTUM_RIGHT], &point, &normal);
|
||||
}
|
||||
|
||||
//bottom
|
||||
{
|
||||
kmVec3 point;
|
||||
kmVec3 normal;
|
||||
normal = cUp;
|
||||
kmVec3Scale(&point, &cUp, -height * 0.5);
|
||||
kmVec3Add(&point, &point, &cc);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_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::FRUSTUM_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::FRUSTUM_NEAR], &nearCenter, &cDir);
|
||||
}
|
||||
|
||||
//far
|
||||
{
|
||||
kmVec3 normal;
|
||||
kmVec3Scale(&normal, &cDir, -1);
|
||||
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_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::FRUSTUM_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::FRUSTUM_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::FRUSTUM_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::FRUSTUM_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::FRUSTUM_NEAR], &mvp, KM_PLANE_NEAR);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::FRUSTUM_FAR], &mvp, KM_PLANE_FAR);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::FRUSTUM_LEFT], &mvp, KM_PLANE_LEFT);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::FRUSTUM_RIGHT], &mvp, KM_PLANE_RIGHT);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::FRUSTUM_BOTTOM], &mvp, KM_PLANE_BOTTOM);
|
||||
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::FRUSTUM_TOP], &mvp, KM_PLANE_TOP);
|
||||
}
|
||||
|
||||
Frustum::IntersectResult Frustum::intersectPoint(const kmVec3 &point) const
|
||||
{
|
||||
int indexFirst = static_cast<int>(FrustumPlane::FRUSTUM_NEAR);
|
||||
int indexNumber = static_cast<int>(FrustumPlane::FRUSTUM_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::FRUSTUM_NEAR);
|
||||
int indexNumber = static_cast<int>(FrustumPlane::FRUSTUM_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::FRUSTUM_NEAR);
|
||||
int indexNumber = static_cast<int>(FrustumPlane::FRUSTUM_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,120 @@
|
|||
/****************************************************************************
|
||||
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 __CC_FRUSTUM_H__
|
||||
#define __CC_FRUSTUM_H__
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#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
|
||||
{
|
||||
FRUSTUM_NEAR = 0,
|
||||
FRUSTUM_FAR = 1,
|
||||
FRUSTUM_BOTTOM = 2,
|
||||
FRUSTUM_TOP = 3,
|
||||
FRUSTUM_LEFT = 4,
|
||||
FRUSTUM_RIGHT = 5,
|
||||
FRUSTUM_NUMBER = 6
|
||||
};
|
||||
kmPlane _frustumPlanes[FrustumPlane::FRUSTUM_NUMBER];
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
|
@ -0,0 +1,127 @@
|
|||
/****************************************************************************
|
||||
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 "CCGroupCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCDirector.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 = Director::getInstance()->getRenderer()->createRenderQueue();
|
||||
_groupMapping[newID] = true;
|
||||
|
||||
return newID;
|
||||
}
|
||||
|
||||
void GroupCommandManager::releaseGroupID(int groupID)
|
||||
{
|
||||
_groupMapping[groupID] = false;
|
||||
}
|
||||
|
||||
GroupCommand::GroupCommand()
|
||||
:RenderCommand()
|
||||
, _viewport(0)
|
||||
, _depth(0)
|
||||
{
|
||||
_type = RenderCommand::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,86 @@
|
|||
/****************************************************************************
|
||||
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 _CC_GROUPCOMMAND_H_
|
||||
#define _CC_GROUPCOMMAND_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCRenderCommand.h"
|
||||
#include "CCRenderCommandPool.h"
|
||||
#include <unordered_map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class GroupCommandManager : public Object
|
||||
{
|
||||
public:
|
||||
static GroupCommandManager* getInstance();
|
||||
|
||||
~GroupCommandManager();
|
||||
|
||||
bool init();
|
||||
|
||||
int getGroupID();
|
||||
void releaseGroupID(int groupID);
|
||||
|
||||
protected:
|
||||
GroupCommandManager();
|
||||
std::unordered_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,107 @@
|
|||
/****************************************************************************
|
||||
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 "CCMaterialManager.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
using namespace std;
|
||||
|
||||
static MaterialManager* s_instance = nullptr;
|
||||
|
||||
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,68 @@
|
|||
/****************************************************************************
|
||||
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 _CC_MATERIALMANAGER_H_
|
||||
#define _CC_MATERIALMANAGER_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCObject.h"
|
||||
#include "ccTypes.h"
|
||||
#include <map>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
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);
|
||||
|
||||
std::map<GLuint, int> _textureIDMapping;
|
||||
std::map<GLuint, int> _shaderIDMapping;
|
||||
std::map<BlendFunc, int> _blendFuncMapping;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //_CC_MATERIALMANAGER_H_
|
|
@ -0,0 +1,301 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCNewClippingNode.h"
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
// store the current stencil layer (position in the stencil buffer),
|
||||
// this will allow nesting up to n ClippingNode,
|
||||
// where n is the number of bits of the stencil buffer.
|
||||
static GLint layer = -1;
|
||||
|
||||
static void setProgram(Node *n, GLProgram *p)
|
||||
{
|
||||
n->setShaderProgram(p);
|
||||
|
||||
for(const auto &child : n->getChildren())
|
||||
setProgram(child, p);
|
||||
}
|
||||
|
||||
NewClippingNode *NewClippingNode::create()
|
||||
{
|
||||
NewClippingNode* pRet = new NewClippingNode();
|
||||
if(pRet && pRet->init())
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
NewClippingNode *NewClippingNode::create(Node *pStencil)
|
||||
{
|
||||
NewClippingNode* pRet = new NewClippingNode();
|
||||
if(pRet && pRet->init(pStencil))
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
NewClippingNode::~NewClippingNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewClippingNode::NewClippingNode()
|
||||
:ClippingNode()
|
||||
{
|
||||
currentStencilEnabled = GL_FALSE;
|
||||
currentStencilWriteMask = ~0;
|
||||
currentStencilFunc = GL_ALWAYS;
|
||||
currentStencilRef = 0;
|
||||
currentStencilValueMask = ~0;
|
||||
currentStencilFail = GL_KEEP;
|
||||
currentStencilPassDepthFail = GL_KEEP;
|
||||
currentStencilPassDepthPass = GL_KEEP;
|
||||
currentDepthWriteMask = GL_TRUE;
|
||||
|
||||
currentAlphaTestEnabled = GL_FALSE;
|
||||
currentAlphaTestFunc = GL_ALWAYS;
|
||||
currentAlphaTestRef = 1;
|
||||
}
|
||||
|
||||
void NewClippingNode::visit()
|
||||
{
|
||||
//Add group command
|
||||
|
||||
Renderer* renderer = Director::getInstance()->getRenderer();
|
||||
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0,_vertexZ);
|
||||
renderer->addCommand(groupCommand);
|
||||
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
|
||||
CustomCommand* beforeVisitCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beforeVisitCmd->init(0,_vertexZ);
|
||||
beforeVisitCmd->func = CC_CALLBACK_0(NewClippingNode::beforeVisit, this);
|
||||
renderer->addCommand(beforeVisitCmd);
|
||||
|
||||
_stencil->visit();
|
||||
|
||||
CustomCommand* afterDrawStencilCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
afterDrawStencilCmd->init(0,_vertexZ);
|
||||
afterDrawStencilCmd->func = CC_CALLBACK_0(NewClippingNode::afterDrawStencil, this);
|
||||
renderer->addCommand(afterDrawStencilCmd);
|
||||
|
||||
Node::visit();
|
||||
|
||||
CustomCommand* afterVisitCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
afterVisitCmd->init(0,_vertexZ);
|
||||
afterVisitCmd->func = CC_CALLBACK_0(NewClippingNode::afterVisit, this);
|
||||
renderer->addCommand(afterVisitCmd);
|
||||
|
||||
renderer->popGroup();
|
||||
}
|
||||
|
||||
void NewClippingNode::beforeVisit()
|
||||
{
|
||||
///////////////////////////////////
|
||||
// INIT
|
||||
|
||||
// increment the current layer
|
||||
layer++;
|
||||
|
||||
// mask of the current layer (ie: for layer 3: 00000100)
|
||||
GLint mask_layer = 0x1 << layer;
|
||||
// mask of all layers less than the current (ie: for layer 3: 00000011)
|
||||
GLint mask_layer_l = mask_layer - 1;
|
||||
// mask of all layers less than or equal to the current (ie: for layer 3: 00000111)
|
||||
mask_layer_le = mask_layer | mask_layer_l;
|
||||
|
||||
// manually save the stencil state
|
||||
|
||||
currentStencilEnabled = glIsEnabled(GL_STENCIL_TEST);
|
||||
glGetIntegerv(GL_STENCIL_WRITEMASK, (GLint *)¤tStencilWriteMask);
|
||||
glGetIntegerv(GL_STENCIL_FUNC, (GLint *)¤tStencilFunc);
|
||||
glGetIntegerv(GL_STENCIL_REF, ¤tStencilRef);
|
||||
glGetIntegerv(GL_STENCIL_VALUE_MASK, (GLint *)¤tStencilValueMask);
|
||||
glGetIntegerv(GL_STENCIL_FAIL, (GLint *)¤tStencilFail);
|
||||
glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, (GLint *)¤tStencilPassDepthFail);
|
||||
glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, (GLint *)¤tStencilPassDepthPass);
|
||||
|
||||
// enable stencil use
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
// check for OpenGL error while enabling stencil test
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
// all bits on the stencil buffer are readonly, except the current layer bit,
|
||||
// this means that operation like glClear or glStencilOp will be masked with this value
|
||||
glStencilMask(mask_layer);
|
||||
|
||||
// manually save the depth test state
|
||||
|
||||
//currentDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
|
||||
glGetBooleanv(GL_DEPTH_WRITEMASK, ¤tDepthWriteMask);
|
||||
|
||||
// disable depth test while drawing the stencil
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
// disable update to the depth buffer while drawing the stencil,
|
||||
// as the stencil is not meant to be rendered in the real scene,
|
||||
// it should never prevent something else to be drawn,
|
||||
// only disabling depth buffer update should do
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
///////////////////////////////////
|
||||
// CLEAR STENCIL BUFFER
|
||||
|
||||
// manually clear the stencil buffer by drawing a fullscreen rectangle on it
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel in the fullscreen rectangle
|
||||
// never draw it into the frame buffer
|
||||
// if not in inverted mode: set the current layer value to 0 in the stencil buffer
|
||||
// if in inverted mode: set the current layer value to 1 in the stencil buffer
|
||||
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
|
||||
glStencilOp(!_inverted ? GL_ZERO : GL_REPLACE, GL_KEEP, GL_KEEP);
|
||||
|
||||
// draw a fullscreen solid rectangle to clear the stencil buffer
|
||||
//ccDrawSolidRect(Point::ZERO, ccpFromSize([[Director sharedDirector] winSize]), Color4F(1, 1, 1, 1));
|
||||
drawFullScreenQuadClearStencil();
|
||||
|
||||
///////////////////////////////////
|
||||
// DRAW CLIPPING STENCIL
|
||||
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel in the stencil node
|
||||
// never draw it into the frame buffer
|
||||
// if not in inverted mode: set the current layer value to 1 in the stencil buffer
|
||||
// if in inverted mode: set the current layer value to 0 in the stencil buffer
|
||||
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
|
||||
glStencilOp(!_inverted ? GL_REPLACE : GL_ZERO, GL_KEEP, GL_KEEP);
|
||||
|
||||
// enable alpha test only if the alpha threshold < 1,
|
||||
// indeed if alpha threshold == 1, every pixel will be drawn anyways
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// GLboolean currentAlphaTestEnabled = GL_FALSE;
|
||||
// GLenum currentAlphaTestFunc = GL_ALWAYS;
|
||||
// GLclampf currentAlphaTestRef = 1;
|
||||
#endif
|
||||
if (_alphaThreshold < 1) {
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// manually save the alpha test state
|
||||
currentAlphaTestEnabled = glIsEnabled(GL_ALPHA_TEST);
|
||||
glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint *)¤tAlphaTestFunc);
|
||||
glGetFloatv(GL_ALPHA_TEST_REF, ¤tAlphaTestRef);
|
||||
// enable alpha testing
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
// check for OpenGL error while enabling alpha test
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
// pixel will be drawn only if greater than an alpha threshold
|
||||
glAlphaFunc(GL_GREATER, _alphaThreshold);
|
||||
#else
|
||||
// since glAlphaTest do not exists in OES, use a shader that writes
|
||||
// pixel only if greater than an alpha threshold
|
||||
GLProgram *program = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
|
||||
GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
|
||||
// set our alphaThreshold
|
||||
program->use();
|
||||
program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
|
||||
// we need to recursively apply this shader to all the nodes in the stencil node
|
||||
// XXX: we should have a way to apply shader to all nodes without having to do this
|
||||
setProgram(_stencil, program);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//Draw _stencil
|
||||
}
|
||||
|
||||
void NewClippingNode::afterDrawStencil()
|
||||
{
|
||||
// restore alpha test state
|
||||
if (_alphaThreshold < 1)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
// manually restore the alpha test state
|
||||
glAlphaFunc(currentAlphaTestFunc, currentAlphaTestRef);
|
||||
if (!currentAlphaTestEnabled)
|
||||
{
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
}
|
||||
#else
|
||||
// XXX: we need to find a way to restore the shaders of the stencil node and its childs
|
||||
#endif
|
||||
}
|
||||
|
||||
// restore the depth test state
|
||||
glDepthMask(currentDepthWriteMask);
|
||||
//if (currentDepthTestEnabled) {
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
//}
|
||||
|
||||
///////////////////////////////////
|
||||
// DRAW CONTENT
|
||||
|
||||
// setup the stencil test func like this:
|
||||
// for each pixel of this node and its childs
|
||||
// if all layers less than or equals to the current are set to 1 in the stencil buffer
|
||||
// draw the pixel and keep the current layer in the stencil buffer
|
||||
// else
|
||||
// do not draw the pixel but keep the current layer in the stencil buffer
|
||||
glStencilFunc(GL_EQUAL, mask_layer_le, mask_layer_le);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
||||
|
||||
// draw (according to the stencil test func) this node and its childs
|
||||
}
|
||||
|
||||
|
||||
void NewClippingNode::afterVisit()
|
||||
{
|
||||
///////////////////////////////////
|
||||
// CLEANUP
|
||||
|
||||
// manually restore the stencil state
|
||||
glStencilFunc(currentStencilFunc, currentStencilRef, currentStencilValueMask);
|
||||
glStencilOp(currentStencilFail, currentStencilPassDepthFail, currentStencilPassDepthPass);
|
||||
glStencilMask(currentStencilWriteMask);
|
||||
if (!currentStencilEnabled)
|
||||
{
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
// we are done using this layer, decrement
|
||||
layer--;
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,71 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __NewClippingNode_H_
|
||||
#define __NewClippingNode_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCClippingNode.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewClippingNode : public ClippingNode
|
||||
{
|
||||
public:
|
||||
static NewClippingNode* create();
|
||||
static NewClippingNode* create(Node* pStencil);
|
||||
|
||||
virtual ~NewClippingNode();
|
||||
|
||||
virtual void visit() override;
|
||||
|
||||
protected:
|
||||
NewClippingNode();
|
||||
|
||||
void beforeVisit();
|
||||
void afterDrawStencil();
|
||||
void afterVisit();
|
||||
|
||||
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,79 @@
|
|||
/****************************************************************************
|
||||
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 "CCNewDrawNode.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "CCDirector.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);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
void NewDrawNode::onDraw()
|
||||
{
|
||||
CC_NODE_DRAW_SETUP();
|
||||
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,52 @@
|
|||
/****************************************************************************
|
||||
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 __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 "CCRenderCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "CCMenuItem.h"
|
||||
#include "CCFrustum.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);
|
||||
|
||||
Director::getInstance()->getRenderer()->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 "CCQuadCommand.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,26 @@
|
|||
/****************************************************************************
|
||||
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 "CCNewParticleSystemQuad.h"
|
|
@ -0,0 +1,39 @@
|
|||
/****************************************************************************
|
||||
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 __CCNewParticleSystemQuad_H_
|
||||
#define __CCNewParticleSystemQuad_H_
|
||||
|
||||
#include "CCParticleSystemQuad.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewParticleSystemQuad : public ParticleSystemQuad
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCNewParticleSystemQuad_H_
|
|
@ -0,0 +1,316 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "CCNewRenderTexture.h"
|
||||
#include "CCCustomCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCGroupCommand.h"
|
||||
#include "CCConfiguration.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
NewRenderTexture* NewRenderTexture::create(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat)
|
||||
{
|
||||
NewRenderTexture* pRet = new NewRenderTexture();
|
||||
|
||||
if(pRet && pRet->initWithWidthAndHeight(w, h, eFormat, uDepthStencilFormat))
|
||||
{
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
}
|
||||
CC_SAFE_DELETE(pRet);
|
||||
return 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);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
|
||||
//! make sure all children are drawn
|
||||
sortAllChildren();
|
||||
|
||||
for(const auto &child: _children)
|
||||
{
|
||||
if (child != _sprite)
|
||||
child->visit();
|
||||
}
|
||||
|
||||
//End will pop the current render group
|
||||
end();
|
||||
}
|
||||
}
|
||||
|
||||
void NewRenderTexture::beginWithClear(float r, float g, float b, float a)
|
||||
{
|
||||
beginWithClear(r, g, b, a, 0, 0, GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue)
|
||||
{
|
||||
beginWithClear(r, g, b, a, depthValue, 0, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue)
|
||||
{
|
||||
beginWithClear(r, g, b, a, depthValue, stencilValue, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags)
|
||||
{
|
||||
setClearColor(Color4F(r, g, b, a));
|
||||
|
||||
setClearDepth(depthValue);
|
||||
|
||||
setClearStencil(stencilValue);
|
||||
|
||||
setClearFlags(flags);
|
||||
|
||||
this->begin();
|
||||
|
||||
//clear screen
|
||||
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
clearCmd->init(0, _vertexZ);
|
||||
clearCmd->func = CC_CALLBACK_0(NewRenderTexture::onClear, this);
|
||||
Director::getInstance()->getRenderer()->addCommand(clearCmd);
|
||||
}
|
||||
|
||||
void NewRenderTexture::begin()
|
||||
{
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLPushMatrix();
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &_projectionMatrix);
|
||||
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLPushMatrix();
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
|
||||
|
||||
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
|
||||
groupCommand->init(0, _vertexZ);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(groupCommand);
|
||||
renderer->pushGroup(groupCommand->getRenderQueueID());
|
||||
|
||||
CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
beginCmd->init(0, _vertexZ);
|
||||
beginCmd->func = CC_CALLBACK_0(NewRenderTexture::onBegin, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(beginCmd);
|
||||
}
|
||||
|
||||
void NewRenderTexture::end()
|
||||
{
|
||||
CustomCommand* endCmd = CustomCommand::getCommandPool().generateCommand();
|
||||
endCmd->init(0, _vertexZ);
|
||||
endCmd->func = CC_CALLBACK_0(NewRenderTexture::onEnd, this);
|
||||
|
||||
Renderer *renderer = Director::getInstance()->getRenderer();
|
||||
renderer->addCommand(endCmd);
|
||||
renderer->popGroup();
|
||||
}
|
||||
|
||||
void NewRenderTexture::onBegin()
|
||||
{
|
||||
//
|
||||
kmGLGetMatrix(KM_GL_PROJECTION, &_oldProjMatrix);
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLLoadMatrix(&_projectionMatrix);
|
||||
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix);
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLLoadMatrix(&_transformMatrix);
|
||||
|
||||
Director *director = Director::getInstance();
|
||||
director->setProjection(director->getProjection());
|
||||
|
||||
const Size& texSize = _texture->getContentSizeInPixels();
|
||||
|
||||
// Calculate the adjustment ratios based on the old and new projections
|
||||
Size size = director->getWinSizeInPixels();
|
||||
float widthRatio = size.width / texSize.width;
|
||||
float heightRatio = size.height / texSize.height;
|
||||
|
||||
// Adjust the orthographic projection and viewport
|
||||
glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height);
|
||||
|
||||
|
||||
kmMat4 orthoMatrix;
|
||||
kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio,
|
||||
(float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
|
||||
kmGLMultMatrix(&orthoMatrix);
|
||||
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
|
||||
|
||||
//TODO move this to configration, so we don't check it every time
|
||||
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
|
||||
*/
|
||||
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
|
||||
{
|
||||
// -- bind a temporary texture so we can clear the render buffer without losing our texture
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0);
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void NewRenderTexture::onEnd()
|
||||
{
|
||||
Director *director = Director::getInstance();
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO);
|
||||
|
||||
// restore viewport
|
||||
director->setViewport();
|
||||
|
||||
//
|
||||
kmGLMatrixMode(KM_GL_PROJECTION);
|
||||
kmGLLoadMatrix(&_oldProjMatrix);
|
||||
|
||||
kmGLMatrixMode(KM_GL_MODELVIEW);
|
||||
kmGLLoadMatrix(&_oldTransMatrix);
|
||||
}
|
||||
|
||||
void NewRenderTexture::onClear()
|
||||
{
|
||||
// save clear color
|
||||
GLfloat oldClearColor[4] = {0.0f};
|
||||
GLfloat oldDepthClearValue = 0.0f;
|
||||
GLint oldStencilClearValue = 0;
|
||||
|
||||
// backup and set
|
||||
if (_clearFlags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor);
|
||||
glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a);
|
||||
}
|
||||
|
||||
if (_clearFlags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &oldDepthClearValue);
|
||||
glClearDepth(_clearDepth);
|
||||
}
|
||||
|
||||
if (_clearFlags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &oldStencilClearValue);
|
||||
glClearStencil(_clearStencil);
|
||||
}
|
||||
|
||||
// clear
|
||||
glClear(_clearFlags);
|
||||
|
||||
// restore
|
||||
if (_clearFlags & GL_COLOR_BUFFER_BIT)
|
||||
{
|
||||
glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[3]);
|
||||
}
|
||||
if (_clearFlags & GL_DEPTH_BUFFER_BIT)
|
||||
{
|
||||
glClearDepth(oldDepthClearValue);
|
||||
}
|
||||
if (_clearFlags & GL_STENCIL_BUFFER_BIT)
|
||||
{
|
||||
glClearStencil(oldStencilClearValue);
|
||||
}
|
||||
}
|
||||
|
||||
void NewRenderTexture::clearDepth(float depthValue)
|
||||
{
|
||||
setClearDepth(depthValue);
|
||||
|
||||
this->begin();
|
||||
|
||||
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0, _vertexZ);
|
||||
cmd->func = CC_CALLBACK_0(NewRenderTexture::onClearDepth, this);
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
|
||||
this->end();
|
||||
}
|
||||
|
||||
void NewRenderTexture::onClearDepth()
|
||||
{
|
||||
//! save old depth value
|
||||
GLfloat depthClearValue;
|
||||
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthClearValue);
|
||||
|
||||
glClearDepth(_clearDepth);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// restore clear color
|
||||
glClearDepth(depthClearValue);
|
||||
}
|
||||
|
||||
NewRenderTexture::NewRenderTexture()
|
||||
:RenderTexture()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewRenderTexture::~NewRenderTexture()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -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.
|
||||
****************************************************************************/
|
||||
|
||||
#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,166 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCNewSprite.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCFrustum.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCQuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#if CC_SPRITEBATCHNODE_RENDER_SUBPIXEL
|
||||
#define RENDER_IN_SUBPIXEL
|
||||
#else
|
||||
#define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__))
|
||||
#endif
|
||||
|
||||
NewSprite* NewSprite::create()
|
||||
{
|
||||
NewSprite* sprite = new NewSprite();
|
||||
if(sprite && sprite->init())
|
||||
{
|
||||
sprite->autorelease();
|
||||
return sprite;
|
||||
}
|
||||
CC_SAFE_DELETE(sprite);
|
||||
return 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;
|
||||
}
|
||||
|
||||
Director::getInstance()->getRenderer()->addCommand(renderCommand);
|
||||
}
|
||||
|
||||
bool NewSprite::culling() const
|
||||
{
|
||||
Frustum* frustum = Director::getInstance()->getFrustum();
|
||||
//TODO optimize this transformation, should use parent's transformation instead
|
||||
kmMat4 worldTM = getNodeToWorldTransform();
|
||||
//generate aabb
|
||||
|
||||
//
|
||||
// calculate the Quad based on the Affine Matrix
|
||||
//
|
||||
Rect newRect = RectApplyTransform(_rect, worldTM);
|
||||
|
||||
kmVec3 point = {newRect.getMinX(), newRect.getMinY(), _vertexZ};
|
||||
|
||||
AABB aabb(point,point);
|
||||
kmVec3Fill(&point,newRect.getMaxX(), newRect.getMinY(), _vertexZ);
|
||||
aabb.expand(point);
|
||||
kmVec3Fill(&point,newRect.getMinX(), newRect.getMaxY(), _vertexZ);
|
||||
aabb.expand(point);
|
||||
kmVec3Fill(&point,newRect.getMaxX(), newRect.getMaxY(), _vertexZ);
|
||||
aabb.expand(point);
|
||||
|
||||
return Frustum::IntersectResult::OUTSIDE !=frustum->intersectAABB(aabb);
|
||||
}
|
||||
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,55 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCNEWSPRITE_H_
|
||||
#define __CCNEWSPRITE_H_
|
||||
|
||||
#include "CCSprite.h"
|
||||
#include "CCPlatformMacros.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewSprite : public Sprite
|
||||
{
|
||||
|
||||
public:
|
||||
static NewSprite* create();
|
||||
static NewSprite* create(const char *filename);
|
||||
|
||||
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,102 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCNewSpriteBatchNode.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "CCTextureCache.h"
|
||||
#include "CCSprite.h"
|
||||
#include "CCNewSprite.h"
|
||||
#include "CCQuadCommand.h"
|
||||
#include "CCRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
NewSpriteBatchNode *NewSpriteBatchNode::createWithTexture(Texture2D *tex, int capacity)
|
||||
{
|
||||
NewSpriteBatchNode* batchNode = new NewSpriteBatchNode();
|
||||
batchNode->initWithTexture(tex, capacity);
|
||||
batchNode->autorelease();
|
||||
|
||||
return batchNode;
|
||||
}
|
||||
|
||||
NewSpriteBatchNode *NewSpriteBatchNode::create(const char *fileImage, long capacity)
|
||||
{
|
||||
NewSpriteBatchNode* batchNode = new NewSpriteBatchNode();
|
||||
batchNode->initWithFile(fileImage, capacity);
|
||||
batchNode->autorelease();
|
||||
|
||||
return batchNode;
|
||||
}
|
||||
|
||||
NewSpriteBatchNode::NewSpriteBatchNode()
|
||||
:SpriteBatchNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewSpriteBatchNode::~NewSpriteBatchNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool NewSpriteBatchNode::init()
|
||||
{
|
||||
Texture2D* texture = new Texture2D();
|
||||
texture->autorelease();
|
||||
return this->initWithTexture(texture, 0);
|
||||
}
|
||||
|
||||
void NewSpriteBatchNode::draw()
|
||||
{
|
||||
// Optimization: Fast Dispatch
|
||||
if( _textureAtlas->getTotalQuads() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(const auto &child: _children)
|
||||
child->updateTransform();
|
||||
|
||||
// arrayMakeObjectsPerformSelector(_children, updateTransform, NewSprite*);
|
||||
|
||||
auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP);
|
||||
|
||||
kmMat4 mv;
|
||||
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
|
||||
|
||||
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
|
||||
cmd->init(0,
|
||||
_vertexZ,
|
||||
_textureAtlas->getTexture()->getName(),
|
||||
shader,
|
||||
_blendFunc,
|
||||
_textureAtlas->getQuads(),
|
||||
_textureAtlas->getTotalQuads(),
|
||||
mv);
|
||||
Director::getInstance()->getRenderer()->addCommand(cmd);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,51 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCNewSpriteBatchNode_H_
|
||||
#define __CCNewSpriteBatchNode_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "CCSpriteBatchNode.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class NewSpriteBatchNode : public SpriteBatchNode
|
||||
{
|
||||
static const int DEFAULT_CAPACITY = 29;
|
||||
public:
|
||||
static NewSpriteBatchNode* createWithTexture(Texture2D* tex, int capacity = DEFAULT_CAPACITY);
|
||||
static NewSpriteBatchNode* create(const char* fileImage, long capacity = DEFAULT_CAPACITY);
|
||||
|
||||
NewSpriteBatchNode();
|
||||
virtual ~NewSpriteBatchNode();
|
||||
|
||||
bool init();
|
||||
|
||||
void draw(void);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCNewSpriteBatchNode_H_
|
|
@ -0,0 +1,77 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCNewTextureAtlas.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCRenderer.h"
|
||||
#include "CCQuadCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
NewTextureAtlas::NewTextureAtlas()
|
||||
:TextureAtlas()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewTextureAtlas::~NewTextureAtlas()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NewTextureAtlas *NewTextureAtlas::create(const char *file, long capacity)
|
||||
{
|
||||
NewTextureAtlas * textureAtlas = new NewTextureAtlas();
|
||||
if(textureAtlas && textureAtlas->initWithFile(file, capacity))
|
||||
{
|
||||
textureAtlas->autorelease();
|
||||
return textureAtlas;
|
||||
}
|
||||
CC_SAFE_DELETE(textureAtlas);
|
||||
return 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,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 __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,180 @@
|
|||
/****************************************************************************
|
||||
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 "CCQuadCommand.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 = RenderCommand::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, ssize_t 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,102 @@
|
|||
/****************************************************************************
|
||||
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 _CC_QUADCOMMAND_H_
|
||||
#define _CC_QUADCOMMAND_H_
|
||||
|
||||
#include "CCRenderCommand.h"
|
||||
#include "CCGLProgram.h"
|
||||
#include "CCRenderCommandPool.h"
|
||||
#include "kazmath/kazmath.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#define CC_NO_TEXTURE 0
|
||||
|
||||
class QuadCommand : public RenderCommand
|
||||
{
|
||||
public:
|
||||
static RenderCommandPool<QuadCommand>& getCommandPool() { return _commandPool; }
|
||||
|
||||
QuadCommand();
|
||||
~QuadCommand();
|
||||
|
||||
void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t 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() const { return true; }
|
||||
|
||||
inline int32_t getMaterialID() const { return _materialID; }
|
||||
|
||||
inline GLuint getTextureID() const { return _textureID; }
|
||||
|
||||
inline V3F_C4B_T2F_Quad* getQuad() const { return _quad; }
|
||||
|
||||
inline ssize_t getQuadCount() const { return _quadCount; }
|
||||
|
||||
inline GLProgram* getShader() const { return _shader; }
|
||||
|
||||
inline BlendFunc getBlendType() const { 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;
|
||||
ssize_t _quadCount;
|
||||
ssize_t _capacity;
|
||||
|
||||
friend class RenderCommandPool<QuadCommand>;
|
||||
|
||||
static RenderCommandPool<QuadCommand> _commandPool;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //_CC_QUADCOMMAND_H_
|
|
@ -0,0 +1,65 @@
|
|||
/****************************************************************************
|
||||
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 "CCRenderCommand.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
RenderCommand::RenderCommand()
|
||||
{
|
||||
_id = 0;
|
||||
_type = RenderCommand::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,70 @@
|
|||
/****************************************************************************
|
||||
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 __CCRENDERCOMMAND_H_
|
||||
#define __CCRENDERCOMMAND_H_
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include <stdint.h>
|
||||
#include "ccTypes.h"
|
||||
#include "kazmath/GL/matrix.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
//TODO make RenderCommand inherent from Object
|
||||
class RenderCommand
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Type
|
||||
{
|
||||
QUAD_COMMAND,
|
||||
CUSTOM_COMMAND,
|
||||
GROUP_COMMAND,
|
||||
UNKNOWN_COMMAND,
|
||||
};
|
||||
|
||||
virtual int64_t generateID() = 0;
|
||||
|
||||
/** Get Render Command Id */
|
||||
virtual inline int64_t getID() { return _id; }
|
||||
|
||||
virtual inline Type getType() { return _type; }
|
||||
virtual void releaseToCommandPool() =0;
|
||||
|
||||
protected:
|
||||
RenderCommand();
|
||||
virtual ~RenderCommand();
|
||||
|
||||
void printID();
|
||||
|
||||
//Generated IDs
|
||||
int64_t _id; /// used for sorting render commands
|
||||
Type _type;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCRENDERCOMMAND_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue