//-----------------------------------------------------------------------------
void ProgramManager::destroyGpuProgram(GpuProgramPtr& gpuProgram)
{		
	const String& programName = gpuProgram->getName();
	ResourcePtr res			  = HighLevelGpuProgramManager::getSingleton().getByName(programName);	

	if (res.isNull() == false)
	{		
		HighLevelGpuProgramManager::getSingleton().remove(programName);
	}
}
Пример #2
0
const MaterialPtr &MaterialGenerator::getMaterial(Perm permutation)
{
	/// Check input validity
	size_t totalBits = bitNames.size();
	size_t totalPerms = 1<<totalBits;
	assert(permutation < totalPerms);

	/// Check if material/shader permutation already was generated
	MaterialMap::iterator i = mMaterials.find(permutation);
	if(i != mMaterials.end())
	{
		return i->second;
	}
	else
	{
		/// Create it
		MaterialPtr templ = getTemplateMaterial(permutation & matMask);
		GpuProgramPtr vs = getVertexShader(permutation & vsMask);
		GpuProgramPtr fs = getFragmentShader(permutation & fsMask);
		
		/// Create material name
		String name=materialBaseName;
		for(size_t bit=0; bit<totalBits; ++bit)
			if(permutation & (1<<bit))
				name += bitNames[bit];

		std::cerr << name << " " << vs->getName() << " " << fs->getName() << std::endl;
		/// Create material from template, and set shaders
		MaterialPtr mat = templ->clone(name);
		Technique *tech = mat->getTechnique(0);
		Pass *pass = tech->getPass(0);
		pass->setFragmentProgram(fs->getName());
		pass->setVertexProgram(vs->getName());
	
		/// And store it
		mMaterials[permutation] = mat;
		return mMaterials[permutation];
	}
}
Пример #3
0
	//-----------------------------------------------------------------------------------
	ShaderManager::~ShaderManager()
	{
		delete mShaderPiecesManager;
		mShaderPiecesManager = NULL;

		ShaderCacheMap::iterator it = mShaderCache.begin();
		ShaderCacheMap::iterator endIt = mShaderCache.end();
		for (; it != endIt; ++it)
		{
			GpuProgramPtr gpuPrg = it->second;
			HighLevelGpuProgramManager::getSingleton().unload(gpuPrg->getName());
			HighLevelGpuProgramManager::getSingleton().remove(gpuPrg->getName());
			gpuPrg.setNull();
		}
		mShaderCache.clear();
	}