fix #10242, reload shader when light number changed

This commit is contained in:
yangxiao 2015-07-15 11:36:53 +08:00
parent 8ab1dce2a0
commit 69e79ed164
3 changed files with 30 additions and 0 deletions

View File

@ -26,6 +26,7 @@ THE SOFTWARE.
#include "base/CCConfiguration.h"
#include "platform/CCFileUtils.h"
#include "renderer/CCGLProgramCache.h"
NS_CC_BEGIN
@ -366,6 +367,9 @@ void Configuration::loadConfigFile(const std::string& filename)
_animate3DQuality = (Animate3DQuality)_valueDict[name].asInt();
else
_valueDict[name] = Value((int)_animate3DQuality);
if (GLProgramCache::isInstanceCreated())
GLProgramCache::getInstance()->reloadDefaultGLProgramsRelativeToLights();
}
NS_CC_END

View File

@ -80,6 +80,11 @@ GLProgramCache* GLProgramCache::getInstance()
return _sharedGLProgramCache;
}
bool GLProgramCache::isInstanceCreated()
{
return _sharedGLProgramCache != 0;
}
void GLProgramCache::destroyInstance()
{
CC_SAFE_RELEASE_NULL(_sharedGLProgramCache);
@ -395,6 +400,21 @@ void GLProgramCache::reloadDefaultGLPrograms()
loadDefaultGLProgram(p, kShaderType_CameraClear);
}
void GLProgramCache::reloadDefaultGLProgramsRelativeToLights()
{
GLProgram *p = getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL);
p->reset();
loadDefaultGLProgram(p, kShaderType_3DPositionNormal);
p = getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE);
p->reset();
loadDefaultGLProgram(p, kShaderType_3DPositionNormalTex);
p = getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE);
p->reset();
loadDefaultGLProgram(p, kShaderType_3DSkinPositionNormalTex);
}
void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type)
{
switch (type) {

View File

@ -63,6 +63,9 @@ public:
/** returns the shared instance */
static GLProgramCache* getInstance();
/** Is the GLProgrameCache instance created? */
static bool isInstanceCreated();
/** purges the cache. It releases the retained instance. */
static void destroyInstance();
@ -90,6 +93,9 @@ public:
/** adds a GLProgram to the cache for a given name */
void addGLProgram(GLProgram* program, const std::string &key);
CC_DEPRECATED_ATTRIBUTE void addProgram(GLProgram* program, const std::string &key) { addGLProgram(program, key); }
/** reload default programs these are relative to light */
void reloadDefaultGLProgramsRelativeToLights();
private:
/**