mirror of https://github.com/axmolengine/axmol.git
Merge branch '#develop' into #4551
Conflicts: samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters
This commit is contained in:
commit
bdfde89ef8
1
AUTHORS
1
AUTHORS
|
@ -560,6 +560,7 @@ Developers:
|
|||
Nako Sung (nakosung)
|
||||
Fixing a bug that wrong logic when pass an empty std::vector to WebSocket::init.
|
||||
Exposing cc.RemoveSelf to JS.
|
||||
exposed AssetsManager to javascript and added multiple-assetsManager support
|
||||
|
||||
dotsquid
|
||||
Fixed the crash caused by improper deletion of VBOs and VAO in ParticleSystemQuad.
|
||||
|
|
|
@ -34,8 +34,10 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "support/zip_support/unzip.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
@ -81,6 +83,7 @@ AssetsManager::AssetsManager(const char* packageUrl/* =NULL */, const char* vers
|
|||
, _connectionTimeout(0)
|
||||
, _delegate(NULL)
|
||||
, _isDownloading(false)
|
||||
, _shouldDeleteDelegateWhenExit(false)
|
||||
{
|
||||
checkStoragePath();
|
||||
_schedule = new Helper();
|
||||
|
@ -92,6 +95,10 @@ AssetsManager::~AssetsManager()
|
|||
{
|
||||
_schedule->release();
|
||||
}
|
||||
if (_shouldDeleteDelegateWhenExit)
|
||||
{
|
||||
delete _delegate;
|
||||
}
|
||||
}
|
||||
|
||||
void AssetsManager::checkStoragePath()
|
||||
|
@ -102,6 +109,26 @@ void AssetsManager::checkStoragePath()
|
|||
}
|
||||
}
|
||||
|
||||
// Multiple key names
|
||||
static std::string keyWithHash( const char* prefix, const std::string& url )
|
||||
{
|
||||
char buf[256];
|
||||
sprintf(buf,"%s%zd",prefix,std::hash<std::string>()(url));
|
||||
return buf;
|
||||
}
|
||||
|
||||
// hashed version
|
||||
std::string AssetsManager::keyOfVersion() const
|
||||
{
|
||||
return keyWithHash(KEY_OF_VERSION,_packageUrl);
|
||||
}
|
||||
|
||||
// hashed version
|
||||
std::string AssetsManager::keyOfDownloadedVersion() const
|
||||
{
|
||||
return keyWithHash(KEY_OF_DOWNLOADED_VERSION,_packageUrl);
|
||||
}
|
||||
|
||||
static size_t getVersionCode(void *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
string *version = (string*)userdata;
|
||||
|
@ -140,7 +167,7 @@ bool AssetsManager::checkUpdate()
|
|||
return false;
|
||||
}
|
||||
|
||||
string recordedVersion = UserDefault::getInstance()->getStringForKey(KEY_OF_VERSION);
|
||||
string recordedVersion = UserDefault::getInstance()->getStringForKey(keyOfVersion().c_str());
|
||||
if (recordedVersion == _version)
|
||||
{
|
||||
sendErrorMessage(ErrorCode::NO_NEW_VERSION);
|
||||
|
@ -212,7 +239,7 @@ void AssetsManager::update()
|
|||
}
|
||||
|
||||
// Is package already downloaded?
|
||||
_downloadedVersion = UserDefault::getInstance()->getStringForKey(KEY_OF_DOWNLOADED_VERSION);
|
||||
_downloadedVersion = UserDefault::getInstance()->getStringForKey(keyOfDownloadedVersion().c_str());
|
||||
|
||||
auto t = std::thread(&AssetsManager::downloadAndUncompress, this);
|
||||
t.detach();
|
||||
|
@ -469,12 +496,12 @@ void AssetsManager::setVersionFileUrl(const char *versionFileUrl)
|
|||
|
||||
string AssetsManager::getVersion()
|
||||
{
|
||||
return UserDefault::getInstance()->getStringForKey(KEY_OF_VERSION);
|
||||
return UserDefault::getInstance()->getStringForKey(keyOfVersion().c_str());
|
||||
}
|
||||
|
||||
void AssetsManager::deleteVersion()
|
||||
{
|
||||
UserDefault::getInstance()->setStringForKey(KEY_OF_VERSION, "");
|
||||
UserDefault::getInstance()->setStringForKey(keyOfVersion().c_str(), "");
|
||||
}
|
||||
|
||||
void AssetsManager::setDelegate(AssetsManagerDelegateProtocol *delegate)
|
||||
|
@ -549,7 +576,7 @@ void AssetsManager::Helper::update(float dt)
|
|||
|
||||
break;
|
||||
case ASSETSMANAGER_MESSAGE_RECORD_DOWNLOADED_VERSION:
|
||||
UserDefault::getInstance()->setStringForKey(KEY_OF_DOWNLOADED_VERSION,
|
||||
UserDefault::getInstance()->setStringForKey(((AssetsManager*)msg->obj)->keyOfDownloadedVersion().c_str(),
|
||||
((AssetsManager*)msg->obj)->_version.c_str());
|
||||
UserDefault::getInstance()->flush();
|
||||
|
||||
|
@ -585,10 +612,10 @@ void AssetsManager::Helper::handleUpdateSucceed(Message *msg)
|
|||
AssetsManager* manager = (AssetsManager*)msg->obj;
|
||||
|
||||
// Record new version code.
|
||||
UserDefault::getInstance()->setStringForKey(KEY_OF_VERSION, manager->_version.c_str());
|
||||
UserDefault::getInstance()->setStringForKey(manager->keyOfVersion().c_str(), manager->_version.c_str());
|
||||
|
||||
// Unrecord downloaded version code.
|
||||
UserDefault::getInstance()->setStringForKey(KEY_OF_DOWNLOADED_VERSION, "");
|
||||
UserDefault::getInstance()->setStringForKey(manager->keyOfDownloadedVersion().c_str(), "");
|
||||
UserDefault::getInstance()->flush();
|
||||
|
||||
// Set resource search path.
|
||||
|
@ -604,4 +631,69 @@ void AssetsManager::Helper::handleUpdateSucceed(Message *msg)
|
|||
if (manager) manager->_delegate->onSuccess();
|
||||
}
|
||||
|
||||
AssetsManager* AssetsManager::create(const char* packageUrl, const char* versionFileUrl, const char* storagePath, ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback )
|
||||
{
|
||||
class DelegateProtocolImpl : public AssetsManagerDelegateProtocol
|
||||
{
|
||||
public :
|
||||
DelegateProtocolImpl(ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback)
|
||||
: errorCallback(errorCallback), progressCallback(progressCallback), successCallback(successCallback)
|
||||
{}
|
||||
|
||||
virtual void onError(AssetsManager::ErrorCode errorCode) { errorCallback(int(errorCode)); }
|
||||
virtual void onProgress(int percent) { progressCallback(percent); }
|
||||
virtual void onSuccess() { successCallback(); }
|
||||
|
||||
private :
|
||||
ErrorCallback errorCallback;
|
||||
ProgressCallback progressCallback;
|
||||
SuccessCallback successCallback;
|
||||
};
|
||||
|
||||
auto* manager = new AssetsManager(packageUrl,versionFileUrl,storagePath);
|
||||
auto* delegate = new DelegateProtocolImpl(errorCallback,progressCallback,successCallback);
|
||||
manager->setDelegate(delegate);
|
||||
manager->_shouldDeleteDelegateWhenExit = true;
|
||||
manager->autorelease();
|
||||
return manager;
|
||||
}
|
||||
|
||||
void AssetsManager::createStoragePath()
|
||||
{
|
||||
// Remove downloaded files
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
||||
DIR *dir = NULL;
|
||||
|
||||
dir = opendir (_storagePath.c_str());
|
||||
if (!dir)
|
||||
{
|
||||
mkdir(_storagePath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
}
|
||||
#else
|
||||
if ((GetFileAttributesA(_storagePath.c_str())) == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
CreateDirectoryA(_storagePath.c_str(), 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void AssetsManager::destroyStoragePath()
|
||||
{
|
||||
// Delete recorded version codes.
|
||||
deleteVersion();
|
||||
|
||||
// Remove downloaded files
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
||||
string command = "rm -r ";
|
||||
// Path may include space.
|
||||
command += "\"" + _storagePath + "\"";
|
||||
system(command.c_str());
|
||||
#else
|
||||
string command = "rd /s /q ";
|
||||
// Path may include space.
|
||||
command += "\"" + _storagePath + "\"";
|
||||
system(command.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_CC_EXT_END;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define __AssetsManager__
|
||||
|
||||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
@ -41,7 +41,7 @@ class AssetsManagerDelegateProtocol;
|
|||
* The updated package should be a zip file. And there should be a file named
|
||||
* version in the server, which contains version code.
|
||||
*/
|
||||
class AssetsManager
|
||||
class AssetsManager : public Node
|
||||
{
|
||||
public:
|
||||
enum class ErrorCode
|
||||
|
@ -77,6 +77,14 @@ public:
|
|||
|
||||
virtual ~AssetsManager();
|
||||
|
||||
typedef std::function<void(int)> ErrorCallback;
|
||||
typedef std::function<void(int)> ProgressCallback;
|
||||
typedef std::function<void(void)> SuccessCallback;
|
||||
|
||||
/* @brief To access within scripting environment
|
||||
*/
|
||||
static AssetsManager* create(const char* packageUrl, const char* versionFileUrl, const char* storagePath, ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback );
|
||||
|
||||
/* @brief Check out if there is a new version resource.
|
||||
* You may use this method before updating, then let user determine whether
|
||||
* he wants to update resources.
|
||||
|
@ -138,7 +146,7 @@ public:
|
|||
/* downloadAndUncompress is the entry of a new thread
|
||||
*/
|
||||
friend int assetsManagerProgressFunc(void *, double, double, double, double);
|
||||
|
||||
|
||||
protected:
|
||||
bool downLoad();
|
||||
void checkStoragePath();
|
||||
|
@ -172,6 +180,15 @@ private:
|
|||
std::list<Message*> *_messageQueue;
|
||||
std::mutex _messageQueueMutex;
|
||||
};
|
||||
|
||||
private:
|
||||
/** @brief Initializes storage path.
|
||||
*/
|
||||
void createStoragePath();
|
||||
|
||||
/** @brief Destroys storage path.
|
||||
*/
|
||||
void destroyStoragePath();
|
||||
|
||||
private:
|
||||
//! The path to store downloaded resources.
|
||||
|
@ -185,13 +202,18 @@ private:
|
|||
|
||||
std::string _downloadedVersion;
|
||||
|
||||
CURL *_curl;
|
||||
void *_curl;
|
||||
|
||||
Helper *_schedule;
|
||||
unsigned int _connectionTimeout;
|
||||
|
||||
AssetsManagerDelegateProtocol *_delegate; // weak reference
|
||||
AssetsManagerDelegateProtocol *_delegate;
|
||||
|
||||
bool _isDownloading;
|
||||
bool _shouldDeleteDelegateWhenExit;
|
||||
|
||||
std::string keyOfVersion() const;
|
||||
std::string keyOfDownloadedVersion() const;
|
||||
};
|
||||
|
||||
class AssetsManagerDelegateProtocol
|
||||
|
|
|
@ -81,4 +81,6 @@
|
|||
|
||||
#include "CCDeprecated-ext.h"
|
||||
|
||||
#include "AssetsManager/AssetsManager.h"
|
||||
|
||||
#endif /* __COCOS2D_EXT_H__ */
|
||||
|
|
|
@ -85,8 +85,6 @@ UpdateLayer::UpdateLayer()
|
|||
|
||||
UpdateLayer::~UpdateLayer()
|
||||
{
|
||||
AssetsManager *pAssetsManager = getAssetsManager();
|
||||
CC_SAFE_DELETE(pAssetsManager);
|
||||
}
|
||||
|
||||
void UpdateLayer::update(cocos2d::Object *pSender)
|
||||
|
@ -94,7 +92,7 @@ void UpdateLayer::update(cocos2d::Object *pSender)
|
|||
pProgressLabel->setString("");
|
||||
|
||||
// update resources
|
||||
getAssetsManager()->update();
|
||||
pAssetsManager->update();
|
||||
|
||||
isUpdateItemClicked = true;
|
||||
}
|
||||
|
@ -116,7 +114,7 @@ void UpdateLayer::reset(cocos2d::Object *pSender)
|
|||
system(command.c_str());
|
||||
#endif
|
||||
// Delete recorded version codes.
|
||||
getAssetsManager()->deleteVersion();
|
||||
pAssetsManager->deleteVersion();
|
||||
|
||||
createDownloadedDir();
|
||||
}
|
||||
|
@ -141,6 +139,15 @@ bool UpdateLayer::init()
|
|||
{
|
||||
Layer::init();
|
||||
|
||||
/** Creates assets manager */
|
||||
pAssetsManager = new AssetsManager("https://raw.github.com/minggo/AssetsManagerTest/master/package.zip",
|
||||
"https://raw.github.com/minggo/AssetsManagerTest/master/version",
|
||||
pathToSave.c_str());
|
||||
pAssetsManager->setDelegate(this);
|
||||
pAssetsManager->setConnectionTimeout(3);
|
||||
addChild(pAssetsManager);
|
||||
pAssetsManager->release();
|
||||
|
||||
createDownloadedDir();
|
||||
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
@ -164,22 +171,6 @@ bool UpdateLayer::init()
|
|||
return true;
|
||||
}
|
||||
|
||||
AssetsManager* UpdateLayer::getAssetsManager()
|
||||
{
|
||||
static AssetsManager *pAssetsManager = NULL;
|
||||
|
||||
if (! pAssetsManager)
|
||||
{
|
||||
pAssetsManager = new AssetsManager("https://raw.github.com/minggo/AssetsManagerTest/master/package.zip",
|
||||
"https://raw.github.com/minggo/AssetsManagerTest/master/version",
|
||||
pathToSave.c_str());
|
||||
pAssetsManager->setDelegate(this);
|
||||
pAssetsManager->setConnectionTimeout(3);
|
||||
}
|
||||
|
||||
return pAssetsManager;
|
||||
}
|
||||
|
||||
void UpdateLayer::createDownloadedDir()
|
||||
{
|
||||
pathToSave = FileUtils::getInstance()->getWritablePath();
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
virtual void onSuccess();
|
||||
|
||||
private:
|
||||
cocos2d::extension::AssetsManager* getAssetsManager();
|
||||
cocos2d::extension::AssetsManager* pAssetsManager;
|
||||
void createDownloadedDir();
|
||||
|
||||
cocos2d::MenuItemFont *pItemEnter;
|
||||
|
|
|
@ -102,6 +102,7 @@ Classes/RotateWorldTest/RotateWorldTest.cpp \
|
|||
Classes/SceneTest/SceneTest.cpp \
|
||||
Classes/SchedulerTest/SchedulerTest.cpp \
|
||||
Classes/ShaderTest/ShaderTest.cpp \
|
||||
Classes/ShaderTest/ShaderTest2.cpp \
|
||||
Classes/SpineTest/SpineTest.cpp \
|
||||
Classes/SpriteTest/SpriteTest.cpp \
|
||||
Classes/TextInputTest/TextInputTest.cpp \
|
||||
|
|
|
@ -0,0 +1,550 @@
|
|||
#include "ShaderTest2.h"
|
||||
#include "ShaderTest.h"
|
||||
#include "../testResource.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
namespace ShaderTest2
|
||||
{
|
||||
static std::function<Layer*()> createFunctions[] =
|
||||
{
|
||||
CL(NormalSpriteTest),
|
||||
CL(GreyScaleSpriteTest),
|
||||
CL(BlurSpriteTest),
|
||||
CL(NoiseSpriteTest),
|
||||
CL(EdgeDetectionSpriteTest),
|
||||
CL(BloomSpriteTest),
|
||||
CL(CelShadingSpriteTest)
|
||||
};
|
||||
|
||||
static unsigned int TEST_CASE_COUNT = sizeof(ShaderTest2::createFunctions) / sizeof(ShaderTest2::createFunctions[0]);
|
||||
|
||||
static int sceneIdx=-1;
|
||||
Layer* createTest(int index)
|
||||
{
|
||||
auto layer = (createFunctions[index])();;
|
||||
|
||||
if (layer)
|
||||
{
|
||||
layer->autorelease();
|
||||
}
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
Layer* nextAction();
|
||||
Layer* backAction();
|
||||
Layer* restartAction();
|
||||
|
||||
Layer* nextAction()
|
||||
{
|
||||
sceneIdx++;
|
||||
sceneIdx = sceneIdx % TEST_CASE_COUNT;
|
||||
|
||||
return createTest(sceneIdx);
|
||||
}
|
||||
|
||||
Layer* backAction()
|
||||
{
|
||||
sceneIdx--;
|
||||
if( sceneIdx < 0 )
|
||||
sceneIdx = TEST_CASE_COUNT -1;
|
||||
|
||||
return createTest(sceneIdx);
|
||||
}
|
||||
|
||||
Layer* restartAction()
|
||||
{
|
||||
return createTest(sceneIdx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ShaderTestDemo2::ShaderTestDemo2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ShaderTestDemo2::backCallback(Object* sender)
|
||||
{
|
||||
auto s = new ShaderTestScene2();
|
||||
s->addChild( ShaderTest2::backAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ShaderTestDemo2::nextCallback(Object* sender)
|
||||
{
|
||||
auto s = new ShaderTestScene2();//CCScene::create();
|
||||
s->addChild( ShaderTest2::nextAction() );
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ShaderTestDemo2::restartCallback(Object* sender)
|
||||
{
|
||||
auto s = new ShaderTestScene2();
|
||||
s->addChild(ShaderTest2::restartAction());
|
||||
|
||||
Director::getInstance()->replaceScene(s);
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ShaderTestScene2::runThisTest()
|
||||
{
|
||||
auto layer = ShaderTest2::nextAction();
|
||||
addChild(layer);
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
template <class spriteType>
|
||||
class ShaderSpriteCreator
|
||||
{
|
||||
public:
|
||||
static spriteType* createSprite(const char* pszFileName)
|
||||
{
|
||||
spriteType* pRet = new spriteType();
|
||||
if (pRet && pRet->initWithFile(pszFileName))
|
||||
{
|
||||
pRet->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(pRet);
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
};
|
||||
|
||||
class ShaderSprite : public Sprite
|
||||
{
|
||||
public:
|
||||
ShaderSprite();
|
||||
~ShaderSprite();
|
||||
|
||||
bool initWithTexture(Texture2D* texture, const Rect& rect);
|
||||
void draw();
|
||||
void initProgram();
|
||||
void listenBackToForeground(Object *obj);
|
||||
|
||||
protected:
|
||||
virtual void buildCustomUniforms() = 0;
|
||||
virtual void setCustomUniforms() = 0;
|
||||
protected:
|
||||
std::string _fragSourceFile;
|
||||
|
||||
};
|
||||
|
||||
ShaderSprite::ShaderSprite()
|
||||
{
|
||||
}
|
||||
|
||||
ShaderSprite::~ShaderSprite()
|
||||
{
|
||||
NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
}
|
||||
|
||||
void ShaderSprite::listenBackToForeground(Object *obj)
|
||||
{
|
||||
setShaderProgram(NULL);
|
||||
initProgram();
|
||||
}
|
||||
|
||||
bool ShaderSprite::initWithTexture(Texture2D* texture, const Rect& rect)
|
||||
{
|
||||
if( Sprite::initWithTexture(texture, rect) )
|
||||
{
|
||||
NotificationCenter::getInstance()->addObserver(this,
|
||||
callfuncO_selector(ShaderSprite::listenBackToForeground),
|
||||
EVNET_COME_TO_FOREGROUND,
|
||||
NULL);
|
||||
|
||||
this->initProgram();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ShaderSprite::initProgram()
|
||||
{
|
||||
GLchar * fragSource = (GLchar*) String::createWithContentsOfFile(
|
||||
FileUtils::getInstance()->fullPathForFilename(_fragSourceFile.c_str()).c_str())->getCString();
|
||||
auto pProgram = new GLProgram();
|
||||
pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource);
|
||||
setShaderProgram(pProgram);
|
||||
pProgram->release();
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
|
||||
getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
|
||||
getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
getShaderProgram()->link();
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
getShaderProgram()->updateUniforms();
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
|
||||
buildCustomUniforms();
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
}
|
||||
|
||||
void ShaderSprite::draw()
|
||||
{
|
||||
GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
|
||||
BlendFunc blend = getBlendFunc();
|
||||
GL::blendFunc(blend.src, blend.dst);
|
||||
|
||||
getShaderProgram()->use();
|
||||
getShaderProgram()->setUniformsForBuiltins();
|
||||
setCustomUniforms();
|
||||
|
||||
GL::bindTexture2D( getTexture()->getName());
|
||||
|
||||
//
|
||||
// Attributes
|
||||
//
|
||||
#define kQuadSize sizeof(_quad.bl)
|
||||
long offset = (long)&_quad;
|
||||
|
||||
// vertex
|
||||
int diff = offsetof( V3F_C4B_T2F, vertices);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));
|
||||
|
||||
// texCoods
|
||||
diff = offsetof( V3F_C4B_T2F, texCoords);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));
|
||||
|
||||
// color
|
||||
diff = offsetof( V3F_C4B_T2F, colors);
|
||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
|
||||
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
CC_INCREMENT_GL_DRAWS(1);
|
||||
}
|
||||
|
||||
class NormalSprite : public ShaderSprite, public ShaderSpriteCreator<NormalSprite>
|
||||
{
|
||||
public:
|
||||
NormalSprite();
|
||||
protected:
|
||||
virtual void buildCustomUniforms();
|
||||
virtual void setCustomUniforms();
|
||||
};
|
||||
|
||||
NormalSprite::NormalSprite()
|
||||
{
|
||||
_fragSourceFile = "Shaders/example_normal.fsh";
|
||||
}
|
||||
|
||||
void NormalSprite::buildCustomUniforms()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NormalSprite::setCustomUniforms()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class GreyScaleSprite : public ShaderSprite, public ShaderSpriteCreator<GreyScaleSprite>
|
||||
{
|
||||
public:
|
||||
GreyScaleSprite();
|
||||
protected:
|
||||
virtual void buildCustomUniforms();
|
||||
virtual void setCustomUniforms();
|
||||
};
|
||||
|
||||
GreyScaleSprite::GreyScaleSprite()
|
||||
{
|
||||
_fragSourceFile = "Shaders/example_greyScale.fsh";
|
||||
}
|
||||
|
||||
void GreyScaleSprite::buildCustomUniforms()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GreyScaleSprite::setCustomUniforms()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class BlurSprite : public ShaderSprite, public ShaderSpriteCreator<BlurSprite>
|
||||
{
|
||||
public:
|
||||
BlurSprite();
|
||||
void setBlurSize(float f);
|
||||
protected:
|
||||
virtual void buildCustomUniforms();
|
||||
virtual void setCustomUniforms();
|
||||
protected:
|
||||
Point blur_;
|
||||
GLfloat sub_[4];
|
||||
|
||||
GLuint blurLocation;
|
||||
GLuint subLocation;
|
||||
};
|
||||
|
||||
BlurSprite::BlurSprite()
|
||||
{
|
||||
_fragSourceFile = "Shaders/example_Blur.fsh";
|
||||
}
|
||||
|
||||
void BlurSprite::buildCustomUniforms()
|
||||
{
|
||||
auto s = getTexture()->getContentSizeInPixels();
|
||||
|
||||
blur_ = Point(1/s.width, 1/s.height);
|
||||
sub_[0] = sub_[1] = sub_[2] = sub_[3] = 0;
|
||||
|
||||
subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract");
|
||||
blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize");
|
||||
}
|
||||
|
||||
void BlurSprite::setCustomUniforms()
|
||||
{
|
||||
|
||||
getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y);
|
||||
getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1);
|
||||
}
|
||||
|
||||
void BlurSprite::setBlurSize(float f)
|
||||
{
|
||||
auto s = getTexture()->getContentSizeInPixels();
|
||||
|
||||
blur_ = Point(1/s.width, 1/s.height);
|
||||
blur_ = blur_ * f;
|
||||
}
|
||||
|
||||
class NoiseSprite : public ShaderSprite, public ShaderSpriteCreator<NoiseSprite>
|
||||
{
|
||||
public:
|
||||
NoiseSprite();
|
||||
|
||||
private:
|
||||
GLfloat _resolution[2];
|
||||
GLuint _resolutionLoc;
|
||||
protected:
|
||||
virtual void buildCustomUniforms();
|
||||
virtual void setCustomUniforms();
|
||||
};
|
||||
|
||||
NoiseSprite::NoiseSprite()
|
||||
{
|
||||
_fragSourceFile = "Shaders/example_Noisy.fsh";
|
||||
}
|
||||
|
||||
void NoiseSprite::buildCustomUniforms()
|
||||
{
|
||||
_resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution");
|
||||
}
|
||||
|
||||
void NoiseSprite::setCustomUniforms()
|
||||
{
|
||||
_resolution[0] = getTexture()->getContentSizeInPixels().width;
|
||||
_resolution[1] = getTexture()->getContentSizeInPixels().height;
|
||||
|
||||
getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1);
|
||||
}
|
||||
|
||||
class EdgeDetectionSprite : public ShaderSprite, public ShaderSpriteCreator<EdgeDetectionSprite>
|
||||
{
|
||||
public:
|
||||
EdgeDetectionSprite();
|
||||
|
||||
private:
|
||||
GLfloat _resolution[2];
|
||||
GLuint _resolutionLoc;
|
||||
protected:
|
||||
virtual void buildCustomUniforms();
|
||||
virtual void setCustomUniforms();
|
||||
};
|
||||
|
||||
EdgeDetectionSprite::EdgeDetectionSprite()
|
||||
{
|
||||
_fragSourceFile = "Shaders/example_edgeDetection.fsh";
|
||||
}
|
||||
|
||||
void EdgeDetectionSprite::buildCustomUniforms()
|
||||
{
|
||||
_resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution");
|
||||
}
|
||||
|
||||
void EdgeDetectionSprite::setCustomUniforms()
|
||||
{
|
||||
_resolution[0] = getTexture()->getContentSizeInPixels().width;
|
||||
_resolution[1] = getTexture()->getContentSizeInPixels().height;
|
||||
|
||||
getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1);
|
||||
}
|
||||
|
||||
class BloomSprite : public ShaderSprite, public ShaderSpriteCreator<BloomSprite>
|
||||
{
|
||||
public:
|
||||
BloomSprite();
|
||||
|
||||
private:
|
||||
GLfloat _resolution[2];
|
||||
GLuint _resolutionLoc;
|
||||
protected:
|
||||
virtual void buildCustomUniforms();
|
||||
virtual void setCustomUniforms();
|
||||
};
|
||||
|
||||
BloomSprite::BloomSprite()
|
||||
{
|
||||
_fragSourceFile = "Shaders/example_bloom.fsh";
|
||||
}
|
||||
|
||||
void BloomSprite::buildCustomUniforms()
|
||||
{
|
||||
_resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution");
|
||||
}
|
||||
|
||||
void BloomSprite::setCustomUniforms()
|
||||
{
|
||||
_resolution[0] = getTexture()->getContentSizeInPixels().width;
|
||||
_resolution[1] = getTexture()->getContentSizeInPixels().height;
|
||||
|
||||
getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1);
|
||||
}
|
||||
|
||||
class CelShadingSprite : public ShaderSprite, public ShaderSpriteCreator<CelShadingSprite>
|
||||
{
|
||||
public:
|
||||
CelShadingSprite();
|
||||
|
||||
private:
|
||||
GLfloat _resolution[2];
|
||||
GLuint _resolutionLoc;
|
||||
protected:
|
||||
virtual void buildCustomUniforms();
|
||||
virtual void setCustomUniforms();
|
||||
};
|
||||
|
||||
CelShadingSprite::CelShadingSprite()
|
||||
{
|
||||
_fragSourceFile = "Shaders/example_celShading.fsh";
|
||||
}
|
||||
|
||||
void CelShadingSprite::buildCustomUniforms()
|
||||
{
|
||||
_resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution");
|
||||
}
|
||||
|
||||
void CelShadingSprite::setCustomUniforms()
|
||||
{
|
||||
_resolution[0] = getTexture()->getContentSizeInPixels().width;
|
||||
_resolution[1] = getTexture()->getContentSizeInPixels().height;
|
||||
|
||||
getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1);
|
||||
}
|
||||
|
||||
NormalSpriteTest::NormalSpriteTest()
|
||||
{
|
||||
if (ShaderTestDemo2::init())
|
||||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
NormalSprite* sprite = NormalSprite::createSprite("Images/powered.png");
|
||||
sprite->setPosition(Point(s.width/2, s.height/2));
|
||||
addChild(sprite);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GreyScaleSpriteTest::GreyScaleSpriteTest()
|
||||
{
|
||||
if (ShaderTestDemo2::init())
|
||||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
GreyScaleSprite* sprite = GreyScaleSprite::createSprite("Images/powered.png");
|
||||
sprite->setPosition(Point(s.width * 0.75, s.height/2));
|
||||
auto sprite2 = Sprite::create("Images/powered.png");
|
||||
sprite2->setPosition(Point(s.width * 0.25, s.height/2));
|
||||
addChild(sprite);
|
||||
addChild(sprite2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BlurSpriteTest::BlurSpriteTest()
|
||||
{
|
||||
if (ShaderTestDemo2::init())
|
||||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
BlurSprite* sprite = BlurSprite::createSprite("Images/powered.png");
|
||||
sprite->setPosition(Point(s.width * 0.75, s.height/2));
|
||||
auto sprite2 = Sprite::create("Images/powered.png");
|
||||
sprite2->setPosition(Point(s.width * 0.25, s.height/2));
|
||||
addChild(sprite);
|
||||
addChild(sprite2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NoiseSpriteTest::NoiseSpriteTest()
|
||||
{
|
||||
if (ShaderTestDemo2::init())
|
||||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
NoiseSprite* sprite = NoiseSprite::createSprite("Images/powered.png");
|
||||
sprite->setPosition(Point(s.width * 0.75, s.height/2));
|
||||
auto sprite2 = Sprite::create("Images/powered.png");
|
||||
sprite2->setPosition(Point(s.width * 0.25, s.height/2));
|
||||
addChild(sprite);
|
||||
addChild(sprite2);
|
||||
}
|
||||
}
|
||||
|
||||
EdgeDetectionSpriteTest::EdgeDetectionSpriteTest()
|
||||
{
|
||||
if (ShaderTestDemo2::init())
|
||||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
EdgeDetectionSprite* sprite = EdgeDetectionSprite::createSprite("Images/powered.png");
|
||||
sprite->setPosition(Point(s.width * 0.75, s.height/2));
|
||||
auto sprite2 = Sprite::create("Images/powered.png");
|
||||
sprite2->setPosition(Point(s.width * 0.25, s.height/2));
|
||||
addChild(sprite);
|
||||
addChild(sprite2);
|
||||
}
|
||||
}
|
||||
|
||||
BloomSpriteTest::BloomSpriteTest()
|
||||
{
|
||||
if (ShaderTestDemo2::init())
|
||||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
BloomSprite* sprite = BloomSprite::createSprite("Images/stone.png");
|
||||
sprite->setPosition(Point(s.width * 0.75, s.height/2));
|
||||
auto sprite2 = Sprite::create("Images/stone.png");
|
||||
sprite2->setPosition(Point(s.width * 0.25, s.height/2));
|
||||
addChild(sprite);
|
||||
addChild(sprite2);
|
||||
}
|
||||
}
|
||||
|
||||
CelShadingSpriteTest::CelShadingSpriteTest()
|
||||
{
|
||||
if (ShaderTestDemo2::init())
|
||||
{
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
CelShadingSprite* sprite = CelShadingSprite::createSprite("Images/stone.png");
|
||||
sprite->setPosition(Point(s.width * 0.75, s.height/2));
|
||||
auto sprite2 = Sprite::create("Images/stone.png");
|
||||
sprite2->setPosition(Point(s.width * 0.25, s.height/2));
|
||||
addChild(sprite);
|
||||
addChild(sprite2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
#ifndef _SHADER_TEST2_H_
|
||||
#define _SHADER_TEST2_H_
|
||||
#include "../testBasic.h"
|
||||
#include "cocos-ext.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
class ShaderTestDemo2 : public BaseTest
|
||||
{
|
||||
public:
|
||||
ShaderTestDemo2(void);
|
||||
virtual std::string title() { return "Shader Sprite!";}
|
||||
void restartCallback(Object* sender);
|
||||
void nextCallback(Object* sender);
|
||||
void backCallback(Object* sender);
|
||||
|
||||
CREATE_FUNC(ShaderTestDemo2);
|
||||
};
|
||||
|
||||
class ShaderTestScene2 : public TestScene
|
||||
{
|
||||
public:
|
||||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
|
||||
|
||||
class NormalSpriteTest : public ShaderTestDemo2
|
||||
{
|
||||
public:
|
||||
NormalSpriteTest();
|
||||
|
||||
virtual std::string subtitle() {return "NormalSpriteTest";}
|
||||
};
|
||||
|
||||
class GreyScaleSpriteTest : public ShaderTestDemo2
|
||||
{
|
||||
public:
|
||||
GreyScaleSpriteTest();
|
||||
|
||||
virtual std::string subtitle() {return "GreyScaleSpriteTest";}
|
||||
};
|
||||
|
||||
class BlurSpriteTest : public ShaderTestDemo2
|
||||
{
|
||||
public:
|
||||
BlurSpriteTest();
|
||||
|
||||
virtual std::string subtitle() {return "BlurSpriteTest";}
|
||||
};
|
||||
|
||||
class NoiseSpriteTest : public ShaderTestDemo2
|
||||
{
|
||||
public:
|
||||
NoiseSpriteTest();
|
||||
virtual std::string subtitle() {return "NoiseSpriteTest";}
|
||||
};
|
||||
|
||||
class EdgeDetectionSpriteTest : public ShaderTestDemo2
|
||||
{
|
||||
public:
|
||||
EdgeDetectionSpriteTest();
|
||||
virtual std::string subtitle() {return "EdgeDetectionSpriteTest";}
|
||||
};
|
||||
|
||||
class BloomSpriteTest : public ShaderTestDemo2
|
||||
{
|
||||
public:
|
||||
BloomSpriteTest();
|
||||
virtual std::string subtitle() {return "BloomSpriteTest";}
|
||||
};
|
||||
|
||||
class CelShadingSpriteTest : public ShaderTestDemo2
|
||||
{
|
||||
public:
|
||||
CelShadingSpriteTest();
|
||||
virtual std::string subtitle() {return "CelShadingSpriteTest";}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -70,6 +70,7 @@ struct {
|
|||
{ "SceneTest", [](){return new SceneTestScene();} },
|
||||
{ "SchedulerTest", [](){return new SchedulerTestScene(); } },
|
||||
{ "ShaderTest", []() { return new ShaderTestScene(); } },
|
||||
{ "ShaderTestSprite", []() { return new ShaderTestScene2(); } },
|
||||
{ "SpineTest", []() { return new SpineTestScene(); } },
|
||||
{ "SpriteTest", [](){return new SpriteTestScene(); } },
|
||||
{ "TextInputTest", [](){return new TextInputTestScene(); } },
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "TextureCacheTest/TextureCacheTest.h"
|
||||
#include "NodeTest/NodeTest.h"
|
||||
#include "ShaderTest/ShaderTest.h"
|
||||
#include "ShaderTest/ShaderTest2.h"
|
||||
#include "ExtensionsTest/ExtensionsTest.h"
|
||||
#include "MutiTouchTest/MutiTouchTest.h"
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
b42f9d96ee0eba96dc53ef311c3b9b273f4456b8
|
|
@ -86,6 +86,7 @@ SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \
|
|||
../Classes/SceneTest/SceneTest.cpp \
|
||||
../Classes/SchedulerTest/SchedulerTest.cpp \
|
||||
../Classes/ShaderTest/ShaderTest.cpp \
|
||||
../Classes/ShaderTest/ShaderTest2.cpp \
|
||||
../Classes/SpriteTest/SpriteTest.cpp \
|
||||
../Classes/TextInputTest/TextInputTest.cpp \
|
||||
../Classes/Texture2dTest/Texture2dTest.cpp \
|
||||
|
|
|
@ -159,6 +159,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O
|
|||
<ClCompile Include="..\Classes\FileUtilsTest\FileUtilsTest.cpp" />
|
||||
<ClCompile Include="..\Classes\LabelTest\LabelTestNew.cpp" />
|
||||
<ClCompile Include="..\Classes\PerformanceTest\PerformanceAllocTest.cpp" />
|
||||
<ClCompile Include="..\Classes\ShaderTest\ShaderTest2.cpp" />
|
||||
<ClCompile Include="..\Classes\SpineTest\SpineTest.cpp" />
|
||||
<ClCompile Include="..\Classes\TexturePackerEncryptionTest\TextureAtlasEncryptionTest.cpp" />
|
||||
<ClCompile Include="..\Classes\VisibleRect.cpp" />
|
||||
|
@ -270,6 +271,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O
|
|||
<ClInclude Include="..\Classes\ExtensionsTest\TableViewTest\TableViewTestScene.h" />
|
||||
<ClInclude Include="..\Classes\FileUtilsTest\FileUtilsTest.h" />
|
||||
<ClInclude Include="..\Classes\LabelTest\LabelTestNew.h" />
|
||||
<ClInclude Include="..\Classes\ShaderTest\ShaderTest2.h" />
|
||||
<ClInclude Include="..\Classes\SpineTest\SpineTest.h" />
|
||||
<ClInclude Include="..\Classes\TexturePackerEncryptionTest\TextureAtlasEncryptionTest.h" />
|
||||
<ClInclude Include="..\Classes\VisibleRect.h" />
|
||||
|
|
|
@ -1 +1 @@
|
|||
31e7d97ef047e37760172c75d2346bed591c821a
|
||||
43537780264e3717000859c697ef9b6504da6ce3
|
|
@ -1 +1 @@
|
|||
Subproject commit f966a8fc67e1a388b167c8b56279ff3e444b3351
|
||||
Subproject commit d94972074fcba0d2595b974d52d721e1eaee5da5
|
|
@ -13,7 +13,7 @@ android_flags = -D_SIZE_T_DEFINED_
|
|||
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
|
||||
clang_flags = -nostdinc -x c++ -std=c++11
|
||||
|
||||
cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/extensions
|
||||
cocos_headers = -I%(cocosdir)s/cocos2dx/include -I%(cocosdir)s/cocos2dx/platform -I%(cocosdir)s/cocos2dx/platform/android -I%(cocosdir)s/cocos2dx -I%(cocosdir)s/cocos2dx/kazmath/include -I%(cocosdir)s/extensions
|
||||
cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT
|
||||
|
||||
cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
|
||||
|
@ -26,7 +26,7 @@ headers = %(cocosdir)s/extensions/cocos-ext.h
|
|||
|
||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
||||
# expression, it will be enclosed in "^$", like this: "^Menu*$".
|
||||
classes = CCBReader.* CCBAnimationManager.* Scale9Sprite Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$
|
||||
classes = AssetsManager.* CCBReader.* CCBAnimationManager.* Scale9Sprite Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$
|
||||
|
||||
# what should we skip? in the format ClassName::[function function]
|
||||
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
|
||||
|
@ -43,6 +43,8 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC
|
|||
*::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV],
|
||||
EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler],
|
||||
TableView::[create (g|s)etDataSource$ (g|s)etDelegate],
|
||||
AssetsManager::[setDelegate],
|
||||
AssetsManagerDelegateProtocol::[*],
|
||||
Control::[removeHandleOfControlEvent addHandleOfControlEvent],
|
||||
ControlUtils::[*],
|
||||
ControlSwitchSprite::[*]
|
||||
|
|
Loading…
Reference in New Issue