Example #1
0
void CCShaderCache::reloadDefaultShaders()
{
    // reset all programs and reload them
    
    // Position Texture Color shader
    CCGLProgram *p = programForKey(kCCShader_PositionTextureColor);    
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionTextureColor);

    // Position Texture Color alpha test
    p = programForKey(kCCShader_PositionTextureColorAlphaTest);
    p->reset();    
    loadDefaultShader(p, kCCShaderType_PositionTextureColorAlphaTest);
    
    //
    // Position, Color shader
    //
    p = programForKey(kCCShader_PositionColor);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionColor);
    
    //
    // Position Texture shader
    //
    p = programForKey(kCCShader_PositionTexture);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionTexture);
    
    //
    // Position, Texture attribs, 1 Color as uniform shader
    //
    p = programForKey(kCCShader_PositionTexture_uColor);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionTexture_uColor);
    
    //
    // Position Texture A8 Color shader
    //
    p = programForKey(kCCShader_PositionTextureA8Color);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionTextureA8Color);
    
    //
    // Position and 1 color passed as a uniform (to simulate glColor4ub )
    //
    p = programForKey(kCCShader_Position_uColor);
    p->reset();
    loadDefaultShader(p, kCCShaderType_Position_uColor);
    
    //
	// Position, Legth(TexCoords, Color (used by Draw Node basically )
	//
    p = programForKey(kCCShader_PositionLengthTexureColor);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionLengthTexureColor);
    
    p = programForKey(kCCShader_PositionTextureColorMask);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionTextureColorMask);
}
void ShaderManager::loadShader(const char* key, const GLchar* vertexShader, const GLchar* fragShader)
{
	CCGLProgram * ccProgram = CCShaderCache::sharedShaderCache()->programForKey(key);
	if (ccProgram == NULL)
	{
		ccProgram = new CCGLProgram();
		ccProgram->autorelease();
		CCShaderCache::sharedShaderCache()->addProgram(ccProgram, key);
	}
	else
	{
		ccProgram->reset();
	}
	ccProgram->initWithVertexShaderByteArray(vertexShader, fragShader);
	CHECK_GL_ERROR_DEBUG();

	ccProgram->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);  
	ccProgram->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);  
	ccProgram->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
	CHECK_GL_ERROR_DEBUG();  

	// 自定义着色器链接  
	ccProgram->link();  
	CHECK_GL_ERROR_DEBUG();  

	// 设置移动、缩放、旋转矩阵  
	ccProgram->updateUniforms();
	CHECK_GL_ERROR_DEBUG();
}
Example #3
0
static int tolua_CCGLProgram_CCGLProgram_reset00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isusertype(tolua_S,1,"CCGLProgram",0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  CCGLProgram* self = (CCGLProgram*)  tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'reset'", NULL);
#endif
  {
   self->reset();
  }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'reset'.",&tolua_err);
 return 0;
#endif
}
Example #4
0
/**
@brief 
@param
*/
void CShaderManager::reloadAllGLProgram()
{
	CCShaderCache::sharedShaderCache()->reloadDefaultShaders();

	size_t size = m_vecGLPrograme.size();
	for( size_t i = 0; i < size; ++i )
	{
		CCGLProgram * pProgram = CCShaderCache::sharedShaderCache()->programForKey(m_vecGLPrograme[i].c_str());
		if( pProgram )
		{
			pProgram->reset();
			loadGLProgram( pProgram, m_vecGLPrograme[i].c_str() );
		}
	}
}
Example #5
0
void CCShaderCache::reloadDefaultShaders()
{
    // reset all programs and reload them
    
    // Position Texture Color shader
    CCGLProgram *p = programForKey(kCCShader_PositionTextureColor);    
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionTextureColor);

    // Position Texture Color alpha test
    p = programForKey(kCCShader_PositionTextureColorAlphaTest);
    p->reset();    
    loadDefaultShader(p, kCCShaderType_PositionTextureColorAlphaTest);
    
    //
    // Position, Color shader
    //
    p = programForKey(kCCShader_PositionColor);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionColor);
    
    //
    // Position Texture shader
    //
    p = programForKey(kCCShader_PositionTexture);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionTexture);
    
    //
    // Position, Texture attribs, 1 Color as uniform shader
    //
    p = programForKey(kCCShader_PositionTexture_uColor);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionTexture_uColor);
    
    //
    // Position Texture A8 Color shader
    //
    p = programForKey(kCCShader_PositionTextureA8Color);
    p->reset();
    loadDefaultShader(p, kCCShaderType_PositionTextureA8Color);
    
    //
    // Position and 1 color passed as a uniform (to similate glColor4ub )
    //
    p = programForKey(kCCShader_Position_uColor);
    p->reset();
    loadDefaultShader(p, kCCShaderType_Position_uColor);  
}
Example #6
0
bool Assets::reloadCustomShaders()
{
    CCLOG("reload custom shaders");
    CCGLProgram *shader = CCShaderCache::sharedShaderCache()->programForKey(settings::kShader_PositionTexture_uColor_uTime);
    shader->reset();
    shader->initWithVertexShaderFilename("shaders/shader_PositionTexture_uColor_uTime.vsh", "shaders/shader_PositionTexture_uColor_uTime.fsh");
    shader->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
    shader->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
    shader->link();
    shader->updateUniforms();

    /// TODO

    CHECK_GL_ERROR_DEBUG();

    return true;
}