const Ogre::MaterialPtr& MaterialGenerator::GetMaterial(Perm permutation)
{
    // Check if material/shader permutation already was generated
    MaterialMap::iterator i = mMaterials.find(permutation);
    if (i != mMaterials.end())
    {
        return i->second;
    }
    else
    {
        // Create it
        Ogre::MaterialPtr templ = GetTemplateMaterial(permutation & mMatMask);
        Ogre::GpuProgramPtr vs = GetVertexShader(permutation & mVsMask);
        Ogre::GpuProgramPtr fs = GetFragmentShader(permutation & mFsMask);

        // Create material name
        string name = mMaterialBaseName + Ogre::StringConverter::toString(permutation);

        // Create material from template, and set shaders
        Ogre::MaterialPtr mat = templ->clone(name);
        Ogre::Technique* tech = mat->getTechnique(0);
        Ogre::Pass* pass = tech->getPass(0);
        pass->setFragmentProgram(fs->getName());
        pass->setVertexProgram(vs->getName());

        // And store it
        mMaterials[permutation] = mat;
        return mMaterials[permutation];
    }
}
Example #2
0
void MainWindow::applyMaterial()
{
    ui->logPanel->clear();
    Ogre::GpuProgramPtr vProgram;
    Ogre::GpuProgramPtr fProgram;
    if (!ui->VP->getShaderName().isEmpty()) {
         vProgram =
                Ogre::GpuProgramManager::getSingleton().getByName(ui->VP->getShaderName().toStdString());
        Ogre::LogManager::getSingleton().logMessage(vProgram->getName());
        vProgram->setSource(ui->VP->text().toStdString());
        vProgram->reload();
    }

    if (!ui->FP->getShaderName().isEmpty()) {
        fProgram =
                Ogre::GpuProgramManager::getSingleton().getByName(ui->FP->getShaderName().toStdString());
        fProgram->setSource(ui->FP->text().toStdString());
        fProgram->reload();
    }

    QString mat = this->removeWhiteSpaceCharacters();

    if (mat.isEmpty()) {
        return ;
    }

    ui->OgreWidget->setMaterial(mat.toStdString(), currMatName.toStdString());
}
Example #3
0
bool
Terrain::_checkFogProgramName(const Ogre::GpuProgramPtr& program, Ogre::FogMode oldFogMode, Ogre::FogMode newFogMode,Ogre::String& newProgramName) const
{
    const Ogre::String& programName = program->getName();

    TerrainData::FogReplacements::const_iterator itfr, itfrend;
    itfrend = mData->mSupportedFogReplacements.end();
    for (itfr = mData->mSupportedFogReplacements.begin(); itfr != itfrend; ++itfr)
    {
        if (programName == itfr->programNames[oldFogMode])
        {
            newProgramName = itfr->programNames[newFogMode];
            return true;
        }
    }

    return false;
}