Merge branch 'develop' into Array

Conflicts:
	cocos/scripting/auto-generated
	tools/bindings-generator
This commit is contained in:
yinkaile 2013-12-18 22:03:16 +08:00
commit 026811ca59
151 changed files with 5070 additions and 1267 deletions

View File

@ -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}

View File

@ -1 +1 @@
e4898923edd8b218b9dc8b238b747331ad601585
4691fe42345db3f1c43fc39d5517fd5115fe0520

View File

@ -1 +1 @@
6824f39ae1cedec2e43627c2637f672203c4a460
52a991e88e049cd371a153ee168260276a7ac664

View File

@ -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 \

View File

@ -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);
});
}

View File

@ -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);
});
}

View File

@ -61,8 +61,8 @@ THE SOFTWARE.
#include "CCConfiguration.h"
#include "CCEventDispatcher.h"
#include "CCFontFreeType.h"
#include "Renderer.h"
#include "renderer/Frustum.h"
#include "CCRenderer.h"
#include "renderer/CCFrustum.h"
/**
Position of the FPS
@ -149,7 +149,10 @@ bool Director::init(void)
_eventDispatcher = new EventDispatcher();
//init TextureCache
initTextureCache();
// Renderer
_renderer = new Renderer;
// create autorelease pool
PoolManager::sharedPoolManager()->push();
@ -169,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();
@ -288,7 +293,7 @@ void Director::drawScene()
showStats();
}
Renderer::getInstance()->render();
_renderer->render();
kmGLPopMatrix();
@ -368,7 +373,7 @@ void Director::setOpenGLView(EGLView *openGLView)
setGLDefaultValues();
}
Renderer::getInstance()->initGLView();
_renderer->initGLView();
CHECK_GL_ERROR_DEBUG();
@ -1027,6 +1032,12 @@ void Director::setEventDispatcher(EventDispatcher* dispatcher)
}
}
Renderer* Director::getRenderer() const
{
return _renderer;
}
/***************************************************
* implementation of DisplayLinkDirector
**************************************************/

View File

@ -56,6 +56,7 @@ class ActionManager;
class EventDispatcher;
class TextureCache;
class Frustum;
class Renderer;
/**
@brief Class that creates and handles the main Window and manages how
@ -338,7 +339,6 @@ public:
Frustum* getFrustum() const { return _cullingFrustum; }
public:
/** Gets the Scheduler associated with this director
@since v2.0
*/
@ -368,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;
@ -395,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
@ -415,7 +419,7 @@ protected:
float _deltaTime;
/* The EGLView, where everything is rendered */
EGLView *_openGLView;
EGLView *_openGLView;
//texture cache belongs to this director
TextureCache *_textureCache;
@ -442,7 +446,7 @@ protected:
unsigned int _frames;
float _secondsPerFrame;
Frustum* _cullingFrustum;
Frustum *_cullingFrustum;
/* The running scene */
Scene *_runningScene;
@ -452,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;
@ -467,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;
@ -480,6 +484,8 @@ protected:
/* Projection protocol delegate */
DirectorDelegate *_projectionDelegate;
Renderer *_renderer;
// EGLViewProtocol will recreate stats labels to fit visible rect
friend class EGLViewProtocol;

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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;

View File

@ -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;
};

View File

@ -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
{

View File

@ -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:

View File

@ -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;

View File

@ -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;

View File

@ -55,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";

View File

@ -87,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;

View File

@ -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();

View File

@ -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;
};

View File

@ -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);
});

View File

@ -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);

View File

@ -43,8 +43,8 @@ THE SOFTWARE.
#include "CCEventListenerAcceleration.h"
#include "platform/CCDevice.h"
#include "CCScene.h"
#include "CustomCommand.h"
#include "Renderer.h"
#include "CCCustomCommand.h"
#include "CCRenderer.h"
NS_CC_BEGIN
@ -507,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)
{
@ -525,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)
{
@ -704,7 +704,7 @@ void LayerColor::draw()
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(LayerColor::onDraw, this);
Renderer::getInstance()->addCommand(cmd);
Director::getInstance()->getRenderer()->addCommand(cmd);
}
void LayerColor::onDraw()
@ -952,7 +952,7 @@ LayerMultiplex::LayerMultiplex()
LayerMultiplex::~LayerMultiplex()
{
_layers.forEach([](Layer* layer){
std::for_each(_layers.begin(), _layers.end(), [](Layer* layer){
layer->cleanup();
});
}
@ -1048,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));

View File

@ -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)

View File

@ -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);
});
}

View File

@ -576,7 +576,7 @@ void Node::cleanup()
}
// timers
_children.forEach([](Node* child){
std::for_each(_children.begin(), _children.end(), [](Node* child){
child->cleanup();
});
}
@ -939,7 +939,7 @@ void Node::onEnter()
{
_isTransitionFinished = false;
_children.forEach([](Node* child){
std::for_each(_children.begin(), _children.end(), [](Node* child){
child->onEnter();
});
@ -960,7 +960,7 @@ void Node::onEnterTransitionDidFinish()
{
_isTransitionFinished = true;
_children.forEach([](Node* child){
std::for_each(_children.begin(), _children.end(), [](Node* child){
child->onEnterTransitionDidFinish();
});
@ -975,7 +975,7 @@ void Node::onEnterTransitionDidFinish()
void Node::onExitTransitionDidStart()
{
_children.forEach([](Node* child){
std::for_each(_children.begin(), _children.end(), [](Node* child){
child->onExitTransitionDidStart();
});
@ -1001,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();
});
}
@ -1236,11 +1236,12 @@ const kmMat4& Node::getNodeToParentTransform() const
// Build Transform Matrix
// Adjusted transform calculation for rotational skew
_transform = { cy * _scaleX, sy * _scaleX, 0, 0,
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)
@ -1349,8 +1350,7 @@ Point Node::convertToNodeSpace(const Point& worldPoint) const
kmVec3 vec3 = {worldPoint.x, worldPoint.y, 0};
kmVec3 ret;
kmVec3Transform(&ret, &vec3, &tmp);
Point p = {ret.x, ret.y };
return p;
return Point(ret.x, ret.y);
}
Point Node::convertToWorldSpace(const Point& nodePoint) const
@ -1359,8 +1359,7 @@ Point Node::convertToWorldSpace(const Point& nodePoint) const
kmVec3 vec3 = {nodePoint.x, nodePoint.y, 0};
kmVec3 ret;
kmVec3Transform(&ret, &vec3, &tmp);
Point p = {ret.x, ret.y };
return p;
return Point(ret.x, ret.y);
}
@ -1412,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();
});
}
@ -1523,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)
{
@ -1578,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)
{

View File

@ -42,8 +42,8 @@
#include "platform/CCFileUtils.h"
#include "kazmath/GL/matrix.h"
#include "CCProfiling.h"
#include "QuadCommand.h"
#include "Renderer.h"
#include "CCQuadCommand.h"
#include "CCRenderer.h"
NS_CC_BEGIN
@ -385,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);
});
@ -423,7 +423,7 @@ void ParticleBatchNode::draw(void)
_textureAtlas->getQuads(),
_textureAtlas->getTotalQuads(),
mv);
Renderer::getInstance()->addCommand(cmd);
Director::getInstance()->getRenderer()->addCommand(cmd);
CC_PROFILER_STOP("CCParticleBatchNode - draw");
}
@ -481,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();

View File

@ -38,13 +38,12 @@ THE SOFTWARE.
#include "CCNotificationCenter.h"
#include "CCEventType.h"
#include "CCConfiguration.h"
#include "CustomCommand.h"
#include "CCRenderer.h"
#include "CCQuadCommand.h"
#include "CCCustomCommand.h"
// extern
#include "kazmath/GL/matrix.h"
#include "Renderer.h"
#include "QuadCommand.h"
#include "CustomCommand.h"
NS_CC_BEGIN
@ -446,7 +445,7 @@ void ParticleSystemQuad::draw()
QuadCommand* cmd = QuadCommand::getCommandPool().generateCommand();
cmd->init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform);
Renderer::getInstance()->addCommand(cmd);
Director::getInstance()->getRenderer()->addCommand(cmd);
}
}

View File

@ -32,8 +32,8 @@ THE SOFTWARE.
#include "CCDirector.h"
#include "TransformUtils.h"
#include "CCDrawingPrimitives.h"
#include "Renderer.h"
#include "CustomCommand.h"
#include "CCRenderer.h"
#include "CCCustomCommand.h"
// extern
#include "kazmath/GL/matrix.h"
@ -557,7 +557,7 @@ void ProgressTimer::draw()
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(ProgressTimer::onDraw, this);
Renderer::getInstance()->addCommand(cmd);
Director::getInstance()->getRenderer()->addCommand(cmd);
}

View File

@ -529,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();

View File

@ -59,8 +59,8 @@ public:
/** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888 */
static RenderTexture * create(int w, int h);
virtual /** starts grabbing */
void begin();
/** starts grabbing */
virtual void begin();
/** starts rendering to the texture while clearing the texture first.
This is more efficient then calling -clear first and then -begin */
@ -77,8 +77,8 @@ public:
/** end is key word of lua, use other name to export to lua. */
inline void endToLua(){ end();};
virtual /** ends grabbing*/
void end();
/** ends grabbing*/
virtual void end();
/** clears the texture with a color */
void clear(float r, float g, float b, float a);

View File

@ -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);
});
};

View File

@ -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);
});
}

View File

@ -41,7 +41,10 @@ enum {
kShaderType_PositionTextureA8Color,
kShaderType_Position_uColor,
kShaderType_PositionLengthTexureColor,
kShaderType_LabelDistanceFieldNormal,
kShaderType_LabelDistanceFieldGlow,
kShaderType_LabelDistanceFieldOutline,
kShaderType_LabelDistanceFieldShadow,
kShaderType_MAX,
};
@ -155,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()
@ -212,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)
@ -284,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__);

View File

@ -44,8 +44,8 @@ THE SOFTWARE.
#include "CCAffineTransform.h"
#include "TransformUtils.h"
#include "CCProfiling.h"
#include "Renderer.h"
#include "QuadCommand.h"
#include "CCRenderer.h"
#include "CCQuadCommand.h"
// external
#include "kazmath/GL/matrix.h"
@ -673,7 +673,7 @@ void Sprite::draw(void)
//TODO implement z order
QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand();
renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv);
Renderer::getInstance()->addCommand(renderCommand);
Director::getInstance()->getRenderer()->addCommand(renderCommand);
}
void Sprite::updateQuadVertices()
@ -817,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)
{
@ -863,7 +863,7 @@ void Sprite::sortAllChildren()
if ( _batchNode)
{
_children.forEach([](Node* child){
std::for_each(_children.begin(), _children.end(), [](Node* child){
child->sortAllChildren();
});
}
@ -900,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)
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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\
";

View File

@ -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\
";

View File

@ -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\
";

View File

@ -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\
";

View File

@ -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\
";

View File

@ -80,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

View File

@ -61,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

View File

@ -318,12 +318,12 @@ struct BlendFunc
//! Enables Additive blending. Uses {GL_SRC_ALPHA, GL_ONE}
const static BlendFunc ADDITIVE;
bool const operator==(const BlendFunc &a)
bool operator==(const BlendFunc &a) const
{
return src == a.src && dst == a.dst;
}
bool const operator<(const BlendFunc &a)
bool operator<(const BlendFunc &a) const
{
return src < a.src || (src < a.src && dst < a.dst);
}

View File

@ -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"

View File

@ -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" />

View File

@ -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>

View File

@ -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>

View File

@ -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

View File

@ -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_

View File

@ -1,14 +1,39 @@
#include "Frustum.h"
/****************************************************************************
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>
#include "CCCommon.h"
NS_CC_BEGIN
ViewTransform::ViewTransform()
{
_position = {0, 0, 0};
_focus = {0, 0, -1};
_up = {0, 1, 0 };
kmVec3Fill(&_position,0,0,0);
kmVec3Fill(&_focus,0,0,-1);
kmVec3Fill(&_up,0,1,0);
_dirty = true;
kmMat4Identity(&_matrix);
}
@ -166,7 +191,7 @@ void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, floa
normal = cDir;
kmVec3Scale(&point, &cDir, near);
kmVec3Add(&point, &point, &cc);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::NEAR], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_NEAR], &point, &normal);
}
//far
@ -176,7 +201,7 @@ void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, floa
kmVec3Scale(&normal, &cDir, -1);
kmVec3Scale(&point, &cDir, far);
kmVec3Add(&point, &point, &cc);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FAR], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_FAR], &point, &normal);
}
//left
@ -186,7 +211,7 @@ void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, floa
normal = cRight;
kmVec3Scale(&point, &cRight, -width * 0.5);
kmVec3Add(&point, &point, &cc);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::LEFT], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_LEFT], &point, &normal);
}
//right
@ -196,7 +221,7 @@ void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, floa
kmVec3Scale(&normal, &cRight, -1);
kmVec3Scale(&point, &cRight, width * 0.5);
kmVec3Add(&point, &point, &cc);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::RIGHT], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_RIGHT], &point, &normal);
}
//bottom
@ -206,7 +231,7 @@ void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, floa
normal = cUp;
kmVec3Scale(&point, &cUp, -height * 0.5);
kmVec3Add(&point, &point, &cc);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::BOTTOM], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_BOTTOM], &point, &normal);
}
//top
@ -216,7 +241,7 @@ void Frustum::setupProjectionOrthogonal(const cocos2d::ViewTransform &view, floa
kmVec3Scale(&normal, &cUp, -1);
kmVec3Scale(&point, &cUp, height * 0.5);
kmVec3Add(&point, &point, &cc);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::TOP], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_TOP], &point, &normal);
}
}
@ -242,14 +267,14 @@ void Frustum::setupProjectionPerspective(const ViewTransform& view, float left,
//near
{
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::NEAR], &nearCenter, &cDir);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_NEAR], &nearCenter, &cDir);
}
//far
{
kmVec3 normal;
kmVec3Scale(&normal, &cDir, -1);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FAR], &farCenter, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_FAR], &farCenter, &normal);
}
//left
@ -263,7 +288,7 @@ void Frustum::setupProjectionPerspective(const ViewTransform& view, float left,
kmVec3Cross(&normal, &normal, &cUp);
kmVec3Normalize(&normal, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::LEFT], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_LEFT], &point, &normal);
}
//right
@ -277,7 +302,7 @@ void Frustum::setupProjectionPerspective(const ViewTransform& view, float left,
kmVec3Cross(&normal, &cUp, &normal);
kmVec3Normalize(&normal, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::RIGHT], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_RIGHT], &point, &normal);
}
//bottom
@ -291,7 +316,7 @@ void Frustum::setupProjectionPerspective(const ViewTransform& view, float left,
kmVec3Cross(&normal, &cRight, &normal);
kmVec3Normalize(&normal, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::BOTTOM], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_BOTTOM], &point, &normal);
}
//top
@ -305,7 +330,7 @@ void Frustum::setupProjectionPerspective(const ViewTransform& view, float left,
kmVec3Cross(&normal, &normal, &cRight);
kmVec3Normalize(&normal, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::TOP], &point, &normal);
kmPlaneFromPointNormal(&_frustumPlanes[FrustumPlane::FRUSTUM_TOP], &point, &normal);
}
}
@ -322,18 +347,18 @@ void Frustum::setupFromMatrix(const kmMat4 &view, const kmMat4 &projection)
kmMat4 mvp;
kmMat4Multiply(&mvp, &projection, &view);
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::NEAR], &mvp, KM_PLANE_NEAR);
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::FAR], &mvp, KM_PLANE_FAR);
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::LEFT], &mvp, KM_PLANE_LEFT);
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::RIGHT], &mvp, KM_PLANE_RIGHT);
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::BOTTOM], &mvp, KM_PLANE_BOTTOM);
kmMat4ExtractPlane(&_frustumPlanes[FrustumPlane::TOP], &mvp, KM_PLANE_TOP);
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::NEAR);
int indexNumber = static_cast<int>(FrustumPlane::NUMBER);
int indexFirst = static_cast<int>(FrustumPlane::FRUSTUM_NEAR);
int indexNumber = static_cast<int>(FrustumPlane::FRUSTUM_NUMBER);
for(int planeIndex = indexFirst; planeIndex < indexNumber; ++planeIndex)
{
@ -346,8 +371,8 @@ Frustum::IntersectResult Frustum::intersectPoint(const kmVec3 &point) const
Frustum::IntersectResult Frustum::intersectAABB(const AABB& aabb) const
{
IntersectResult result = IntersectResult::INSIDE;
int indexFirst = static_cast<int>(FrustumPlane::NEAR);
int indexNumber = static_cast<int>(FrustumPlane::NUMBER);
int indexFirst = static_cast<int>(FrustumPlane::FRUSTUM_NEAR);
int indexNumber = static_cast<int>(FrustumPlane::FRUSTUM_NUMBER);
for(int planeIndex = indexFirst; planeIndex < indexNumber; ++planeIndex)
{
@ -369,8 +394,8 @@ Frustum::IntersectResult Frustum::intersectAABB(const AABB& aabb) const
Frustum::IntersectResult Frustum::intersectSphere(const kmVec3& center, float radius) const
{
IntersectResult result = IntersectResult::INSIDE;
int indexFirst = static_cast<int>(FrustumPlane::NEAR);
int indexNumber = static_cast<int>(FrustumPlane::NUMBER);
int indexFirst = static_cast<int>(FrustumPlane::FRUSTUM_NEAR);
int indexNumber = static_cast<int>(FrustumPlane::FRUSTUM_NUMBER);
for(int planeIndex = indexFirst; planeIndex < indexNumber; ++planeIndex)
{

View File

@ -1,8 +1,32 @@
/****************************************************************************
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 "math/kazmath/include/kazmath/kazmath.h"
#include "kazmath/kazmath.h"
NS_CC_BEGIN
@ -80,15 +104,15 @@ public:
private:
enum FrustumPlane
{
NEAR = 0,
FAR = 1,
BOTTOM = 2,
TOP = 3,
LEFT = 4,
RIGHT = 5,
NUMBER = 6
FRUSTUM_NEAR = 0,
FRUSTUM_FAR = 1,
FRUSTUM_BOTTOM = 2,
FRUSTUM_TOP = 3,
FRUSTUM_LEFT = 4,
FRUSTUM_RIGHT = 5,
FRUSTUM_NUMBER = 6
};
kmPlane _frustumPlanes[FrustumPlane::NUMBER];
kmPlane _frustumPlanes[FrustumPlane::FRUSTUM_NUMBER];
};
NS_CC_END

View File

@ -1,10 +1,31 @@
//
// Created by NiTe Luo on 11/13/13.
//
/****************************************************************************
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 "GroupCommand.h"
#include "Renderer.h"
#include "CCGroupCommand.h"
#include "CCRenderer.h"
#include "CCDirector.h"
NS_CC_BEGIN
RenderCommandPool<GroupCommand> GroupCommand::_commandPool;
@ -53,7 +74,7 @@ int GroupCommandManager::getGroupID()
//Create new ID
// int newID = _groupMapping.size();
int newID = Renderer::getInstance()->createRenderQueue();
int newID = Director::getInstance()->getRenderer()->createRenderQueue();
_groupMapping[newID] = true;
return newID;
@ -69,7 +90,7 @@ GroupCommand::GroupCommand()
, _viewport(0)
, _depth(0)
{
_type = GROUP_COMMAND;
_type = RenderCommand::Type::GROUP_COMMAND;
_renderQueueID = GroupCommandManager::getInstance()->getGroupID();
}

View File

@ -1,19 +1,37 @@
//
// Created by NiTe Luo on 11/13/13.
//
/****************************************************************************
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 "RenderCommand.h"
#include "RenderCommandPool.h"
#include <map>
#include "CCRenderCommand.h"
#include "CCRenderCommandPool.h"
#include <unordered_map>
NS_CC_BEGIN
using namespace std;
class GroupCommandManager : public Object
{
@ -29,7 +47,7 @@ public:
protected:
GroupCommandManager();
map<int, bool> _groupMapping;
std::unordered_map<int, bool> _groupMapping;
};
class GroupCommand : public RenderCommand

View File

@ -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

View File

@ -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_

View File

@ -1,13 +1,33 @@
//
// Created by NiTe Luo on 11/13/13.
//
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
#include "NewClippingNode.h"
#include "GroupCommand.h"
#include "Renderer.h"
#include "CustomCommand.h"
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
@ -79,7 +99,7 @@ void NewClippingNode::visit()
{
//Add group command
Renderer* renderer = Renderer::getInstance();
Renderer* renderer = Director::getInstance()->getRenderer();
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
groupCommand->init(0,_vertexZ);

View File

@ -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_

View File

@ -1,12 +1,32 @@
//
// Created by NiTe Luo on 11/14/13.
//
/****************************************************************************
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 "QuadCommand.h"
#include "Renderer.h"
#include "CustomCommand.h"
#include "CCQuadCommand.h"
#include "CCRenderer.h"
#include "CCCustomCommand.h"
#include "CCDirector.h"
NS_CC_BEGIN
@ -45,7 +65,7 @@ void NewDrawNode::draw()
CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand();
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(NewDrawNode::onDraw, this);
Renderer::getInstance()->addCommand(cmd);
Director::getInstance()->getRenderer()->addCommand(cmd);
}
void NewDrawNode::onDraw()

View File

@ -1,8 +1,26 @@
//
// Created by NiTe Luo on 11/14/13.
//
/****************************************************************************
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_

View File

@ -24,11 +24,11 @@
#include "CCNewLabelAtlas.h"
#include "RenderCommand.h"
#include "Renderer.h"
#include "QuadCommand.h"
#include "CCRenderCommand.h"
#include "CCRenderer.h"
#include "CCQuadCommand.h"
#include "CCMenuItem.h"
#include "Frustum.h"
#include "CCFrustum.h"
#include "CCDirector.h"
#include "CCTextureAtlas.h"
#include "CCShaderCache.h"
@ -60,7 +60,7 @@ void NewLabelAtlas::draw()
_textureAtlas->getTotalQuads(),
mv);
Renderer::getInstance()->addCommand(cmd);
Director::getInstance()->getRenderer()->addCommand(cmd);
}

View File

@ -28,7 +28,7 @@
#include "CCLabelAtlas.h"
#include "CCPlatformMacros.h"
#include "QuadCommand.h"
#include "CCQuadCommand.h"
NS_CC_BEGIN

View File

@ -1,6 +1,26 @@
//
// Created by NiTe Luo on 11/22/13.
//
/****************************************************************************
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"

View File

@ -1,8 +1,26 @@
//
// Created by NiTe Luo on 11/22/13.
//
/****************************************************************************
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_

View File

@ -1,12 +1,32 @@
//
// Created by NiTe Luo on 12/2/13.
//
/****************************************************************************
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 "CustomCommand.h"
#include "Renderer.h"
#include "GroupCommand.h"
#include "CCCustomCommand.h"
#include "CCRenderer.h"
#include "CCGroupCommand.h"
#include "CCConfiguration.h"
#include "CCDirector.h"
@ -62,7 +82,7 @@ void NewRenderTexture::draw()
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
clearCmd->init(0, _vertexZ);
clearCmd->func = CC_CALLBACK_0(NewRenderTexture::onClear, this);
Renderer::getInstance()->addCommand(clearCmd);
Director::getInstance()->getRenderer()->addCommand(clearCmd);
//! make sure all children are drawn
sortAllChildren();
@ -95,7 +115,7 @@ void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float
void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags)
{
setClearColor({r, g, b, a});
setClearColor(Color4F(r, g, b, a));
setClearDepth(depthValue);
@ -109,7 +129,7 @@ void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float
CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand();
clearCmd->init(0, _vertexZ);
clearCmd->func = CC_CALLBACK_0(NewRenderTexture::onClear, this);
Renderer::getInstance()->addCommand(clearCmd);
Director::getInstance()->getRenderer()->addCommand(clearCmd);
}
void NewRenderTexture::begin()
@ -125,14 +145,15 @@ void NewRenderTexture::begin()
GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand();
groupCommand->init(0, _vertexZ);
Renderer::getInstance()->addCommand(groupCommand);
Renderer::getInstance()->pushGroup(groupCommand->getRenderQueueID());
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);
Renderer::getInstance()->addCommand(beginCmd);
Director::getInstance()->getRenderer()->addCommand(beginCmd);
}
void NewRenderTexture::end()
@ -141,9 +162,9 @@ void NewRenderTexture::end()
endCmd->init(0, _vertexZ);
endCmd->func = CC_CALLBACK_0(NewRenderTexture::onEnd, this);
Renderer::getInstance()->addCommand(endCmd);
Renderer::getInstance()->popGroup();
Renderer *renderer = Director::getInstance()->getRenderer();
renderer->addCommand(endCmd);
renderer->popGroup();
}
void NewRenderTexture::onBegin()
@ -263,7 +284,7 @@ void NewRenderTexture::clearDepth(float depthValue)
cmd->init(0, _vertexZ);
cmd->func = CC_CALLBACK_0(NewRenderTexture::onClearDepth, this);
Renderer::getInstance()->addCommand(cmd);
Director::getInstance()->getRenderer()->addCommand(cmd);
this->end();
}

View File

@ -1,8 +1,26 @@
//
// Created by NiTe Luo on 12/2/13.
//
/****************************************************************************
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_

View File

@ -1,16 +1,32 @@
//
// CCNewSprite.cpp
// cocos2d_libs
//
// Created by NiTe Luo on 10/31/13.
//
//
/****************************************************************************
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 "Renderer.h"
#include "Frustum.h"
#include "CCRenderer.h"
#include "CCFrustum.h"
#include "CCDirector.h"
#include "QuadCommand.h"
#include "CCQuadCommand.h"
NS_CC_BEGIN
@ -118,7 +134,7 @@ void NewSprite::draw(void)
return;
}
Renderer::getInstance()->addCommand(renderCommand);
Director::getInstance()->getRenderer()->addCommand(renderCommand);
}
bool NewSprite::culling() const
@ -136,11 +152,11 @@ bool NewSprite::culling() const
kmVec3 point = {newRect.getMinX(), newRect.getMinY(), _vertexZ};
AABB aabb(point,point);
point = {newRect.getMaxX(), newRect.getMinY(), _vertexZ};
kmVec3Fill(&point,newRect.getMaxX(), newRect.getMinY(), _vertexZ);
aabb.expand(point);
point = {newRect.getMinX(), newRect.getMaxY(), _vertexZ};
kmVec3Fill(&point,newRect.getMinX(), newRect.getMaxY(), _vertexZ);
aabb.expand(point);
point = {newRect.getMaxX(), newRect.getMaxY(), _vertexZ};
kmVec3Fill(&point,newRect.getMaxX(), newRect.getMaxY(), _vertexZ);
aabb.expand(point);
return Frustum::IntersectResult::OUTSIDE !=frustum->intersectAABB(aabb);

View File

@ -1,10 +1,26 @@
//
// CCNewSprite.h
// cocos2d_libs
//
// Created by NiTe Luo on 10/31/13.
//
//
/****************************************************************************
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_

View File

@ -1,7 +1,26 @@
//
// Created by NiTe Luo on 11/11/13.
//
/****************************************************************************
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"
@ -9,8 +28,8 @@
#include "CCTextureCache.h"
#include "CCSprite.h"
#include "CCNewSprite.h"
#include "QuadCommand.h"
#include "Renderer.h"
#include "CCQuadCommand.h"
#include "CCRenderer.h"
NS_CC_BEGIN
@ -77,7 +96,7 @@ void NewSpriteBatchNode::draw()
_textureAtlas->getQuads(),
_textureAtlas->getTotalQuads(),
mv);
Renderer::getInstance()->addCommand(cmd);
Director::getInstance()->getRenderer()->addCommand(cmd);
}
NS_CC_END

View File

@ -1,8 +1,26 @@
//
// Created by NiTe Luo on 11/11/13.
//
/****************************************************************************
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_

View File

@ -1,13 +1,32 @@
//
// Created by NiTe Luo on 11/11/13.
//
/****************************************************************************
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 "Renderer.h"
#include "QuadCommand.h"
#include "CCRenderer.h"
#include "CCQuadCommand.h"
NS_CC_BEGIN

View File

@ -1,7 +1,26 @@
//
// Created by NiTe Luo on 11/11/13.
//
/****************************************************************************
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_

View File

@ -1,9 +1,29 @@
//
// Created by NiTe Luo on 11/6/13.
//
/****************************************************************************
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 "QuadCommand.h"
#include "CCQuadCommand.h"
#include "ccGLStateCache.h"
NS_CC_BEGIN
@ -18,12 +38,12 @@ QuadCommand::QuadCommand()
,_quadCount(0)
,_capacity(0)
{
_type = QUAD_COMMAND;
_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, int quadCount, const kmMat4 &mv)
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;

View File

@ -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_

View File

@ -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

View File

@ -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_

View File

@ -1,10 +1,27 @@
//
// RenderCommandPool.h
// cocos2d_libs
//
// Created by Huabing on 11/28/13.
//
//
/****************************************************************************
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_RENDERCOMMANDPOOL_H__
#define __CC_RENDERCOMMANDPOOL_H__
@ -35,8 +52,7 @@ public:
}
_allocatedPoolBlocks.clear();
}
public:
T* generateCommand()
{
T* result = nullptr;
@ -73,7 +89,7 @@ private:
_freePool.push_back(commands+index);
}
}
private:
std::list<T*> _allocatedPoolBlocks;
std::list<T*> _freePool;
//std::set<T*> _usedPool;

View File

@ -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 "CCRenderMaterial.h"

View File

@ -0,0 +1,36 @@
/****************************************************************************
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 __RenderMaterial_H_
#define __RenderMaterial_H_
class RenderMaterial
{
};
#endif //__RenderMaterial_H_

View File

@ -1,38 +1,43 @@
//
// Created by NiTe Luo on 10/31/13.
//
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
#include "Renderer.h"
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 "CCRenderer.h"
#include "CCShaderCache.h"
#include "ccGLStateCache.h"
#include "CustomCommand.h"
#include "QuadCommand.h"
#include "GroupCommand.h"
#include "CCCustomCommand.h"
#include "CCQuadCommand.h"
#include "CCGroupCommand.h"
#include "CCConfiguration.h"
#include "CCNotificationCenter.h"
#include "CCEventType.h"
#include <algorithm> // for std::stable_sort
NS_CC_BEGIN
using namespace std;
static Renderer* s_instance;
Renderer *Renderer::getInstance()
{
if(!s_instance)
{
s_instance = new Renderer();
if(!s_instance->init())
{
CC_SAFE_DELETE(s_instance);
}
}
return s_instance;
}
void Renderer::destroyInstance()
{
CC_SAFE_RELEASE_NULL(s_instance);
}
#define DEFAULT_RENDER_QUEUE 0
Renderer::Renderer()
:_lastMaterialID(0)
@ -45,7 +50,8 @@ Renderer::Renderer()
RenderQueue defaultRenderQueue;
_renderGroups.push_back(defaultRenderQueue);
_renderStack.push({DEFAULT_RENDER_QUEUE, 0});
RenderStackElement elelment = {DEFAULT_RENDER_QUEUE, 0};
_renderStack.push(elelment);
}
Renderer::~Renderer()
@ -61,11 +67,6 @@ Renderer::~Renderer()
}
}
bool Renderer::init()
{
return true;
}
void Renderer::initGLView()
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
@ -83,14 +84,15 @@ void Renderer::initGLView()
_glViewAssigned = true;
}
void Renderer::onBackToForeground()
void Renderer::onBackToForeground(Object* obj)
{
CC_UNUSED_PARAM(obj);
setupBuffer();
}
void Renderer::setupIndices()
{
for( int i=0; i < VBO_SIZE; i++)
for( int i=0; i < vbo_size; i++)
{
_indices[i*6+0] = (GLushort) (i*4+0);
_indices[i*6+1] = (GLushort) (i*4+1);
@ -121,7 +123,7 @@ void Renderer::setupVBOAndVAO()
glGenBuffers(2, &_buffersVBO[0]);
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * VBO_SIZE, _quads, GL_DYNAMIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * vbo_size, _quads, GL_DYNAMIC_DRAW);
// vertices
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
@ -136,7 +138,7 @@ void Renderer::setupVBOAndVAO()
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*) offsetof( V3F_C4B_T2F, texCoords));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * VBO_SIZE * 6, _indices, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * vbo_size * 6, _indices, GL_STATIC_DRAW);
// Must unbind the VAO before changing the element buffer.
GL::bindVAO(0);
@ -159,11 +161,11 @@ void Renderer::mapBuffers()
GL::bindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * VBO_SIZE, _quads, GL_DYNAMIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * vbo_size, _quads, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * VBO_SIZE * 6, _indices, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * vbo_size * 6, _indices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
CHECK_GL_ERROR_DEBUG();
@ -216,7 +218,7 @@ void Renderer::render()
//1. Sort render commands based on ID
for (auto it = _renderGroups.begin(); it != _renderGroups.end(); ++it)
{
stable_sort((*it).begin(), (*it).end(), compareRenderCommand);
std::stable_sort((*it).begin(), (*it).end(), compareRenderCommand);
}
while(!_renderStack.empty())
@ -232,30 +234,33 @@ void Renderer::render()
{
_renderStack.top().currentIndex = _lastCommand = i;
auto command = currRenderQueue[i];
auto commandType = command->getType();
if(command->getType() == QUAD_COMMAND)
if(commandType == RenderCommand::Type::QUAD_COMMAND)
{
QuadCommand* cmd = static_cast<QuadCommand*>(command);
ssize_t cmdQuadCount = cmd->getQuadCount();
//Batch quads
if(_numQuads + cmd->getQuadCount() > VBO_SIZE)
if(_numQuads + cmdQuadCount > vbo_size)
{
CCASSERT(cmd->getQuadCount() < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command");
CCASSERT(cmdQuadCount < vbo_size, "VBO is not big enough for quad data, please break the quad data down or use customized render command");
//Draw batched quads if VBO is full
drawBatchedQuads();
}
memcpy(_quads + _numQuads, cmd->getQuad(), sizeof(V3F_C4B_T2F_Quad) * cmd->getQuadCount());
_numQuads += cmd->getQuadCount();
memcpy(_quads + _numQuads, cmd->getQuad(), sizeof(V3F_C4B_T2F_Quad) * cmdQuadCount);
_numQuads += cmdQuadCount;
}
else if(command->getType() == CUSTOM_COMMAND)
else if(commandType == RenderCommand::Type::CUSTOM_COMMAND)
{
flush();
CustomCommand* cmd = static_cast<CustomCommand*>(command);
cmd->execute();
}
else if(command->getType() == GROUP_COMMAND)
else if(commandType == RenderCommand::Type::GROUP_COMMAND)
{
flush();
GroupCommand* cmd = static_cast<GroupCommand*>(command);
@ -263,7 +268,8 @@ void Renderer::render()
_renderStack.top().currentIndex = i + 1;
//push new renderQueue to renderStack
_renderStack.push({cmd->getRenderQueueID(), 0});
RenderStackElement element = {cmd->getRenderQueueID(), 0};
_renderStack.push(element);
//Exit current loop
break;
@ -299,7 +305,8 @@ void Renderer::render()
{
_renderStack.pop();
}
_renderStack.push({DEFAULT_RENDER_QUEUE, 0});
RenderStackElement element = {DEFAULT_RENDER_QUEUE, 0};
_renderStack.push(element);
_firstCommand = _lastCommand = 0;
_lastMaterialID = 0;
}
@ -358,7 +365,7 @@ void Renderer::drawBatchedQuads()
for(size_t i = _firstCommand; i <= _lastCommand; i++)
{
RenderCommand* command = _renderGroups[_renderStack.top().renderQueueID][i];
if (command->getType() == QUAD_COMMAND)
if (command->getType() == RenderCommand::Type::QUAD_COMMAND)
{
QuadCommand* cmd = static_cast<QuadCommand*>(command);
if(_lastMaterialID != cmd->getMaterialID())

View File

@ -0,0 +1,103 @@
/****************************************************************************
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_RENDERER_H_
#define __CC_RENDERER_H_
#include "CCPlatformMacros.h"
#include "CCRenderCommand.h"
#include "CCGLProgram.h"
#include "CCGL.h"
#include <vector>
#include <stack>
NS_CC_BEGIN
typedef std::vector<RenderCommand*> RenderQueue;
struct RenderStackElement
{
int renderQueueID;
size_t currentIndex;
};
class Renderer : public Object
{
public:
static const int vbo_size = 65536 / 6;
Renderer();
~Renderer();
//TODO manage GLView inside Render itself
void initGLView();
//TODO support multiple viewport
void addCommand(RenderCommand* command);
void addCommand(RenderCommand* command, int renderQueue);
void pushGroup(int renderQueueID);
void popGroup();
int createRenderQueue();
void render();
protected:
void setupIndices();
//Setup VBO or VAO based on OpenGL extensions
void setupBuffer();
void setupVBOAndVAO();
void setupVBO();
void mapBuffers();
void drawBatchedQuads();
//Draw the previews queued quads and flush previous context
void flush();
void onBackToForeground(Object* obj);
std::stack<int> _commandGroupStack;
std::stack<RenderStackElement> _renderStack;
std::vector<RenderQueue> _renderGroups;
int _lastMaterialID;
size_t _firstCommand;
size_t _lastCommand;
V3F_C4B_T2F_Quad _quads[vbo_size];
GLushort _indices[6 * vbo_size];
GLuint _quadVAO;
GLuint _buffersVBO[2]; //0: vertex 1: indices
int _numQuads;
bool _glViewAssigned;
};
NS_CC_END
#endif //__CC_RENDERER_H_

View File

@ -1,55 +0,0 @@
//
// Created by NiTe Luo on 11/8/13.
//
#include "CustomCommand.h"
NS_CC_BEGIN
RenderCommandPool<CustomCommand> CustomCommand::_commandPool;
CustomCommand::CustomCommand()
:RenderCommand()
, _viewport(0)
, _depth(0)
, func(nullptr)
{
_type = CUSTOM_COMMAND;
}
void CustomCommand::init(int viewport, int32_t depth)
{
_viewport = viewport;
_depth = depth;
}
CustomCommand::~CustomCommand()
{
}
int64_t CustomCommand::generateID()
{
_id = 0;
_id = (int64_t)_viewport << 61
| (int64_t)1 << 60 // translucent
| (int64_t)_depth << 36;
return _id;
}
void CustomCommand::execute()
{
if(func)
{
func();
}
}
void CustomCommand::releaseToCommandPool()
{
getCommandPool().pushBackCommand(this);
}
NS_CC_END

View File

@ -1,55 +0,0 @@
//
// Created by NiTe Luo on 11/8/13.
//
#ifndef _CC_CUSTOMCOMMAND_H_
#define _CC_CUSTOMCOMMAND_H_
#include "RenderCommand.h"
#include "RenderCommandPool.h"
NS_CC_BEGIN
using namespace std;
class CustomCommand : public RenderCommand
{
protected:
CustomCommand();
~CustomCommand();
public:
void init(int viewport, int32_t depth);
// +----------+----------+-----+-----------------------------------+
// | | | | | |
// | ViewPort | Transluc | | Depth | |
// | 3 bits | 1 bit | | 24 bits | |
// +----------+----------+-----+----------------+------------------+
virtual int64_t generateID();
void execute();
inline bool isTranslucent() { return true; }
virtual void releaseToCommandPool() override;
public:
function<void()> func;
protected:
int _viewport;
int32_t _depth;
public:
friend class RenderCommandPool<CustomCommand>;
static RenderCommandPool<CustomCommand>& getCommandPool() { return _commandPool; }
protected:
static RenderCommandPool<CustomCommand> _commandPool;
};
NS_CC_END
#endif //_CC_CUSTOMCOMMAND_H_

View File

@ -1,87 +0,0 @@
//
// Created by NiTe Luo on 11/6/13.
//
#include "MaterialManager.h"
NS_CC_BEGIN
using namespace std;
static MaterialManager* s_instance = 0;
MaterialManager *MaterialManager::getInstance()
{
if(!s_instance)
{
s_instance = new MaterialManager();
if(!s_instance->init())
{
CC_SAFE_DELETE(s_instance);
}
}
return s_instance;
}
void MaterialManager::destroyInstance()
{
CC_SAFE_RELEASE_NULL(s_instance);
}
void MaterialManager::getMaterialID(GLuint textureID, GLuint shaderID, BlendFunc blendFunc)
{
}
void MaterialManager::registerTexture(GLuint textureID)
{
}
void MaterialManager::unregisterTexture(GLuint textureID)
{
}
void MaterialManager::registerShader(GLuint shaderID)
{
}
void MaterialManager::unregisterShader(GLuint shaderID)
{
}
MaterialManager::MaterialManager()
{
}
MaterialManager::~MaterialManager()
{
}
bool MaterialManager::init()
{
return false;
}
int MaterialManager::getTextureID(GLuint textureID)
{
return 0;
}
int MaterialManager::getShaderID(GLuint shaderID)
{
return 0;
}
int MaterialManager::getBlendFuncID(GLint blendFunc)
{
return 0;
}
NS_CC_END

View File

@ -1,50 +0,0 @@
//
// Created by NiTe Luo on 11/6/13.
//
#ifndef _CC_MATERIALMANAGER_H_
#define _CC_MATERIALMANAGER_H_
#include "CCPlatformMacros.h"
#include "CCObject.h"
#include "ccTypes.h"
#include <map>
NS_CC_BEGIN
using namespace std;
class MaterialManager : public Object
{
public:
static MaterialManager* getInstance();
static void destroyInstance();
void getMaterialID(GLuint textureID, GLuint shaderID, BlendFunc blendFunc);
void registerTexture(GLuint textureID);
void unregisterTexture(GLuint textureID);
void registerShader(GLuint shaderID);
void unregisterShader(GLuint shaderID);
protected:
MaterialManager();
virtual ~MaterialManager();
bool init();
int getTextureID(GLuint textureID);
int getShaderID(GLuint shaderID);
int getBlendFuncID(GLint blendFunc);
map<GLuint, int> _textureIDMapping;
map<GLuint, int> _shaderIDMapping;
map<BlendFunc, int> _blendFuncMapping;
};
NS_CC_END
#endif //_CC_MATERIALMANAGER_H_

View File

@ -1,53 +0,0 @@
//
// Created by NiTe Luo on 11/13/13.
//
#ifndef __NewClippingNode_H_
#define __NewClippingNode_H_
#include "CCPlatformMacros.h"
#include "CCClippingNode.h"
NS_CC_BEGIN
class NewClippingNode : public ClippingNode
{
public:
static NewClippingNode* create();
static NewClippingNode* create(Node* pStencil);
virtual ~NewClippingNode();
virtual void visit() override;
protected:
NewClippingNode();
void beforeVisit();
void afterDrawStencil();
void afterVisit();
protected:
GLboolean currentStencilEnabled;
GLuint currentStencilWriteMask;
GLenum currentStencilFunc;
GLint currentStencilRef;
GLuint currentStencilValueMask;
GLenum currentStencilFail;
GLenum currentStencilPassDepthFail;
GLenum currentStencilPassDepthPass;
GLboolean currentDepthWriteMask;
GLboolean currentAlphaTestEnabled;
GLenum currentAlphaTestFunc;
GLclampf currentAlphaTestRef;
GLint mask_layer_le;
};
NS_CC_END
#endif //__NewClippingNode_H_

View File

@ -1,85 +0,0 @@
//
// Created by NiTe Luo on 11/6/13.
//
#ifndef _CC_QUADCOMMAND_H_
#define _CC_QUADCOMMAND_H_
#include "RenderCommand.h"
#include "CCGLProgram.h"
#include "RenderCommandPool.h"
#include "kazmath.h"
NS_CC_BEGIN
#define CC_NO_TEXTURE 0
class QuadCommand : public RenderCommand
{
public:
QuadCommand();
~QuadCommand();
public:
void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, int quadCount,
const kmMat4& mv);
// +----------+----------+-----+-----------------------------------+
// | | | | | |
// | ViewPort | Transluc | | Depth | Material ID |
// | 3 bits | 1 bit | | 24 bits | 24 bit2 |
// +----------+----------+-----+----------------+------------------+
virtual int64_t generateID();
void useMaterial();
//TODO use material to decide if it is translucent
inline bool isTranslucent() { return true; }
inline int32_t getMaterialID() { return _materialID; }
inline GLuint getTextureID() { return _textureID; }
inline V3F_C4B_T2F_Quad* getQuad() { return _quad; }
inline int getQuadCount() { return _quadCount; }
inline GLProgram* getShader() { return _shader; }
inline BlendFunc getBlendType() { return _blendType; }
virtual void releaseToCommandPool() override;
protected:
int32_t _materialID;
//Key Data
int _viewport; /// Which view port it belongs to
//TODO use material to determine if it's translucent
int32_t _depth;
//Maternal
GLuint _textureID;
GLProgram* _shader;
// GLuint _shaderID;
BlendFunc _blendType;
V3F_C4B_T2F_Quad* _quad;
int _quadCount;
int _capacity;
public:
friend class RenderCommandPool<QuadCommand>;
static RenderCommandPool<QuadCommand>& getCommandPool() { return _commandPool; }
protected:
static RenderCommandPool<QuadCommand> _commandPool;
};
NS_CC_END
#endif //_CC_QUADCOMMAND_H_

View File

@ -1,45 +0,0 @@
//
// Created by NiTe Luo on 10/31/13.
//
#include "RenderCommand.h"
NS_CC_BEGIN
RenderCommand::RenderCommand()
{
_id = 0;
_type = UNKNOWN_COMMAND;
}
RenderCommand::~RenderCommand()
{
}
void printBits(size_t const size, void const * const ptr)
{
unsigned char *b = (unsigned char*) ptr;
unsigned char byte;
int i, j;
for (i=size-1;i>=0;i--)
{
for (j=7;j>=0;j--)
{
byte = b[i] & (1<<j);
byte >>= j;
printf("%u", byte);
}
}
puts("");
}
void RenderCommand::printID()
{
printf("CommandID: ");
printBits(sizeof(_id), &_id);
printf("\n");
}
NS_CC_END

View File

@ -1,52 +0,0 @@
//
// Created by NiTe Luo on 10/31/13.
//
#ifndef __CCRENDERCOMMAND_H_
#define __CCRENDERCOMMAND_H_
#include "CCPlatformMacros.h"
#include <stdint.h>
#include "ccTypes.h"
#include "kazmath/GL/matrix.h"
NS_CC_BEGIN
enum RenderCommandType
{
QUAD_COMMAND,
CUSTOM_COMMAND,
GROUP_COMMAND,
UNKNOWN_COMMAND,
};
//TODO make RenderCommand inherent from Object
class RenderCommand
{
protected:
RenderCommand();
virtual ~RenderCommand();
public:
virtual int64_t generateID() = 0;
virtual /**
* Get Render Command Id
*/
inline int64_t getID() { return _id; }
virtual inline RenderCommandType getType() { return _type; }
virtual void releaseToCommandPool() =0;
protected:
void printID();
protected:
//Generated IDs
int64_t _id; /// used for sorting render commands
RenderCommandType _type;
};
NS_CC_END
#endif //__CCRENDERCOMMAND_H_

View File

@ -1,6 +0,0 @@
//
// Created by NiTe Luo on 11/6/13.
//
#include "RenderMaterial.h"

View File

@ -1,17 +0,0 @@
//
// Created by NiTe Luo on 11/6/13.
//
#ifndef __RenderMaterial_H_
#define __RenderMaterial_H_
class RenderMaterial
{
};
#endif //__RenderMaterial_H_

Some files were not shown because too many files have changed in this diff Show More