2012-03-16 13:42:53 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-03-16 13:42:53 +08:00
|
|
|
Copyright (c) 2011 Ricardo Quesada
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
#ifndef __CCSHADERCACHE_H__
|
|
|
|
#define __CCSHADERCACHE_H__
|
|
|
|
|
2013-09-07 13:55:11 +08:00
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "cocoa/CCDictionary.h"
|
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
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** ShaderCache
|
2012-03-12 15:22:03 +08:00
|
|
|
Singleton that stores manages GL shaders
|
|
|
|
@since v2.0
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL ShaderCache : public Object
|
2012-03-12 15:22:03 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:13:12 +08:00
|
|
|
ShaderCache();
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~ShaderCache();
|
2013-07-12 06:24:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** returns the shared instance */
|
2013-07-12 06:24:23 +08:00
|
|
|
static ShaderCache* 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 */
|
|
|
|
CC_DEPRECATED_ATTRIBUTE static ShaderCache* sharedShaderCache();
|
|
|
|
|
|
|
|
/** @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 */
|
|
|
|
void loadDefaultShaders();
|
2012-04-17 17:55:26 +08:00
|
|
|
|
|
|
|
/** reload the default shaders */
|
|
|
|
void reloadDefaultShaders();
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** returns a GL program for a given key */
|
2013-09-07 13:55:11 +08:00
|
|
|
GLProgram * programForKey(const std::string &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 */
|
2013-09-07 13:55:11 +08:00
|
|
|
void addProgram(GLProgram* program, const std::string &key);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
private:
|
2012-04-19 14:35:52 +08:00
|
|
|
bool init();
|
2013-06-20 14:13:12 +08:00
|
|
|
void loadDefaultShader(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
|
|
|
|
|
|
|
|
#endif /* __CCSHADERCACHE_H__ */
|