void MeshResourceMarker::reset() { //destroy entity if (entity_) { context_->getSceneManager()->destroyEntity( entity_ ); entity_ = 0; } // destroy all the materials we've created S_MaterialPtr::iterator it; for ( it = materials_.begin(); it!=materials_.end(); it++ ) { Ogre::MaterialPtr material = *it; if (!material.isNull()) { for (size_t i = 0; i < material->getNumTechniques(); ++i) { Ogre::Technique* t = material->getTechnique(i); // hack hack hack, really need to do a shader-based way of picking, rather than // creating a texture for each object if (t->getSchemeName() == "Pick") { Ogre::TextureManager::getSingleton().remove(t->getPass(0)->getTextureUnitState(0)->getTextureName()); } } material->unload(); Ogre::MaterialManager::getSingleton().remove(material->getName()); } } materials_.clear(); }
//copied from ogre sample browser Ogre::Technique* gkMaterialLoader::handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, const Ogre::Renderable* rend) { #ifdef OGREKIT_USE_RTSHADER_SYSTEM Ogre::RTShader::ShaderGenerator* shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingletonPtr(); GK_ASSERT(shaderGenerator); Ogre::Technique* generatedTech = 0; if (schemeName == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME) { bool techniqueCreated; techniqueCreated = shaderGenerator->createShaderBasedTechnique( originalMaterial->getName(), Ogre::MaterialManager::DEFAULT_SCHEME_NAME, schemeName); if (techniqueCreated) { shaderGenerator->validateMaterial(schemeName, originalMaterial->getName()); Ogre::Material::TechniqueIterator itTech = originalMaterial->getTechniqueIterator(); while (itTech.hasMoreElements()) { Ogre::Technique* curTech = itTech.getNext(); if (curTech->getSchemeName() == schemeName) { generatedTech = curTech; break; } } } } if (!generatedTech) { gkLogMessage("Material: " << schemeName << " isn't found."); } else { gkLogMessage("Material: " << schemeName << " is found."); } return generatedTech; #else return 0; #endif }
/** This class demonstrates basic usage of the RTShader system. It sub class the material manager listener class and when a target scheme callback is invoked with the shader generator scheme it tries to create an equivalent shader based technique based on the default technique of the given material. */ Ogre::Technique* MaterialMgrListener::handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, const Ogre::Renderable* rend) { Ogre::Technique* generatedTech = NULL; // Case this is the default shader generator scheme. if (schemeName == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME) { bool techniqueCreated; // Create shader generated technique for this material. techniqueCreated = mShaderGenerator->createShaderBasedTechnique( originalMaterial->getName(), Ogre::MaterialManager::DEFAULT_SCHEME_NAME, schemeName); // Case technique registration succeeded. if (techniqueCreated) { // Force creating the shaders for the generated technique. mShaderGenerator->validateMaterial(schemeName, originalMaterial->getName()); // Grab the generated technique. Ogre::Material::TechniqueIterator itTech = originalMaterial->getTechniqueIterator(); while (itTech.hasMoreElements()) { Ogre::Technique* curTech = itTech.getNext(); if (curTech->getSchemeName() == schemeName) { generatedTech = curTech; break; } } } } return generatedTech; }