2012-03-16 13:42:53 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
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__
|
|
|
|
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "cocoa/CCDictionary.h"
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class CCGLProgram;
|
|
|
|
|
|
|
|
/** CCShaderCache
|
|
|
|
Singleton that stores manages GL shaders
|
|
|
|
@since v2.0
|
|
|
|
*/
|
2012-03-14 14:55:17 +08:00
|
|
|
class CC_DLL CCShaderCache : public CCObject
|
2012-03-12 15:22:03 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-04-19 14:35:52 +08:00
|
|
|
CCShaderCache();
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual ~CCShaderCache();
|
|
|
|
/** returns the shared instance */
|
|
|
|
static CCShaderCache* sharedShaderCache();
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** purges the cache. It releases the retained instance. */
|
|
|
|
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 */
|
|
|
|
CCGLProgram * programForKey(const char* key);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** adds a CCGLProgram to the cache for a given name */
|
|
|
|
void addProgram(CCGLProgram* program, const char* key);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
private:
|
2012-04-19 14:35:52 +08:00
|
|
|
bool init();
|
2012-04-17 17:55:26 +08:00
|
|
|
void loadDefaultShader(CCGLProgram *program, int type);
|
2012-03-12 15:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDictionary* m_pPrograms;
|
2012-03-12 15:22:03 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* __CCSHADERCACHE_H__ */
|