Esempio n. 1
0
 Ogre::MaterialPtr GetOrCreateLegacyMaterial(const std::string& texture_name, uint variation)
 {
     if (variation >= MAX_MATERIAL_VARIATIONS)
     {
         OgreRenderingModule::LogWarning("Requested suffix for non-existing material variation " + ToString<uint>(variation));
         variation = 0;
     }
     const std::string& suffix = MaterialSuffix[variation];
     
     Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
     Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
     
     std::string material_name = texture_name + suffix;
     Ogre::MaterialPtr material = mm.getByName(material_name);
     
     if (!material.get())
     {
         material = mm.create(material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
         assert(material.get());
     }
     else
         return material;
     
     Ogre::TexturePtr tex = tm.getByName(texture_name);
     bool has_alpha = false;
     if (!tex.isNull())
     {
         // As far as the legacy materials are concerned, DXT1 is not alpha
         if (tex->getFormat() == Ogre::PF_DXT1)
             has_alpha = false;
         else if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
             has_alpha = true;
     }
     
     Ogre::MaterialPtr base_material;
     if (!has_alpha)
         base_material = mm.getByName(BaseMaterials[variation]);
     else
         base_material = mm.getByName(AlphaBaseMaterials[variation]);
     if (!base_material.get())
     {
         OgreRenderingModule::LogError("Could not find " + MaterialSuffix[variation] + " base material for " + texture_name);
         return Ogre::MaterialPtr();
     }
     
     base_material->copyDetailsTo(material);
     SetTextureUnitOnMaterial(material, texture_name, 0);
     
     return material;
 }
Esempio n. 2
0
    void UpdateLegacyMaterials(const std::string& texture_name)
    {
        Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
        Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
        
        Ogre::TexturePtr tex = tm.getByName(texture_name);
        bool has_alpha = false;
        if (!tex.isNull())
            if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
                has_alpha = true;

        for (uint i = 0; i < MAX_MATERIAL_VARIATIONS; ++i)
        {
            std::string material_name = texture_name + MaterialSuffix[i];
            Ogre::MaterialPtr material = mm.getByName(material_name);
            
            if (!material.get())
                continue;
            
            Ogre::MaterialPtr base_material;
            if (!has_alpha)
                base_material = mm.getByName(BaseMaterials[i]);
            else
                base_material = mm.getByName(AlphaBaseMaterials[i]);
            if (!base_material.get())
            {
                OgreRenderingModule::LogError("Could not find " + MaterialSuffix[i] + " base material for " + texture_name);
                continue;
            }
            
            base_material->copyDetailsTo(material);
            SetTextureUnitOnMaterial(material, texture_name, 0);
        }
    }
Esempio n. 3
0
    void CreateLegacyMaterials(const std::string& texture_name, bool update)
    {
        Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
        Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
        
        Ogre::TexturePtr tex = tm.getByName(texture_name);
        bool has_alpha = false;
        if (!tex.isNull())
        {
            if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
                has_alpha = true;
        }
        
        // Early out: if texture does not yet exist and materials have already been created once
        if (((tex.isNull()) || (!update)) && (!mm.getByName(texture_name).isNull()))
            return;
        
        for (uint i = 0; i < MAX_MATERIAL_VARIATIONS; ++i)
        {
            const std::string& base_material_name = BaseMaterials[i];
            const std::string& alpha_base_material_name = AlphaBaseMaterials[i];
            
            std::string material_name = texture_name + MaterialSuffix[i];
            Ogre::MaterialPtr material = mm.getByName(material_name);

            if (!material.get())
            {
                material = mm.create(material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
                assert(material.get());
            }
            
            Ogre::MaterialPtr base_material;
            if (!has_alpha)
                base_material = mm.getByName(base_material_name);
            else
                base_material = mm.getByName(alpha_base_material_name);
            if (!base_material.get())
            {
                OgreRenderingModule::LogError("Could not find " + MaterialSuffix[i] + " base material for " + texture_name);
                return;
            }

            base_material->copyDetailsTo(material);
            SetTextureUnitOnMaterial(material, texture_name, 0);
        }
    }