2012-03-16 13:42:53 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2011 Ricardo Quesada
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-03-16 13:42:53 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2012-03-16 13:42:53 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2014-05-10 09:39:25 +08:00
|
|
|
#ifndef __CCGLPROGRAMCACHE_H__
|
|
|
|
#define __CCGLPROGRAMCACHE_H__
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2014-02-20 10:53:49 +08:00
|
|
|
|
2013-09-07 13:55:11 +08:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2012-03-12 15:22:03 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class GLProgram;
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup shaders
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-05-10 09:39:25 +08:00
|
|
|
/** GLProgramCache
|
|
|
|
Singleton that stores manages GLProgram objects (shaders)
|
2012-03-12 15:22:03 +08:00
|
|
|
@since v2.0
|
|
|
|
*/
|
2014-05-10 09:39:25 +08:00
|
|
|
class CC_DLL GLProgramCache : public Ref
|
2012-03-12 15:22:03 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2014-05-10 09:39:25 +08:00
|
|
|
GLProgramCache();
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-10 09:39:25 +08:00
|
|
|
~GLProgramCache();
|
2013-07-12 06:24:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** returns the shared instance */
|
2014-05-10 09:39:25 +08:00
|
|
|
static GLProgramCache* getInstance();
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** purges the cache. It releases the retained instance. */
|
2013-07-12 06:24:23 +08:00
|
|
|
static void destroyInstance();
|
|
|
|
|
|
|
|
/** @deprecated Use getInstance() instead */
|
2014-05-10 09:39:25 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static GLProgramCache* sharedShaderCache();
|
2013-07-12 06:24:23 +08:00
|
|
|
|
|
|
|
/** @deprecated Use destroyInstance() instead */
|
|
|
|
CC_DEPRECATED_ATTRIBUTE static void purgeSharedShaderCache();
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** loads the default shaders */
|
2014-05-10 09:39:25 +08:00
|
|
|
void loadDefaultGLPrograms();
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void loadDefaultShaders() { loadDefaultGLPrograms(); }
|
|
|
|
|
2012-04-17 17:55:26 +08:00
|
|
|
/** reload the default shaders */
|
2014-05-10 09:39:25 +08:00
|
|
|
void reloadDefaultGLPrograms();
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void reloadDefaultShaders() { reloadDefaultGLPrograms(); }
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns a GL program for a given key
|
|
|
|
*/
|
2014-05-10 09:39:25 +08:00
|
|
|
GLProgram * getGLProgram(const std::string &key);
|
|
|
|
CC_DEPRECATED_ATTRIBUTE GLProgram * getProgram(const std::string &key) { return getGLProgram(key); }
|
|
|
|
CC_DEPRECATED_ATTRIBUTE GLProgram * programForKey(const std::string &key){ return getGLProgram(key); }
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** adds a GLProgram to the cache for a given name */
|
2014-05-10 09:39:25 +08:00
|
|
|
void addGLProgram(GLProgram* program, const std::string &key);
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void addProgram(GLProgram* program, const std::string &key) { addGLProgram(program, key); }
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
private:
|
2012-04-19 14:35:52 +08:00
|
|
|
bool init();
|
2014-05-10 09:39:25 +08:00
|
|
|
void loadDefaultGLProgram(GLProgram *program, int type);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2013-09-07 13:55:11 +08:00
|
|
|
// Dictionary* _programs;
|
|
|
|
std::unordered_map<std::string, GLProgram*> _programs;
|
2012-03-12 15:22:03 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of shaders group
|
|
|
|
/// @}
|
|
|
|
|
2012-03-12 15:22:03 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2014-05-10 09:39:25 +08:00
|
|
|
#endif /* __CCGLPROGRAMCACHE_H__ */
|