コード例 #1
0
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];
    }
}
コード例 #2
0
ファイル: main.cpp プロジェクト: ozw1z5rd/ozw1z5rd-lab
 void cleanupContent()
 {
     // get rid of the shared pointers before shutting down ogre or exceptions occure
     std::cout << "Imposto i servizi per gli shader di texture\n";
     mActiveFragmentProgram.setNull();
     mActiveFragmentParameters.setNull();
     mActiveVertexProgram.setNull();
     mActiveVertexParameters.setNull();
     mActiveMaterial.setNull();
     std::cout << "Impostazione terminata\n";
 }
コード例 #3
0
	virtual Ogre::GpuProgramPtr generateVertexShader(Perm permutation)
	{
        Ogre::String programName = "DeferredShading/post/";

		if (permutation & LightMaterialGenerator::MI_DIRECTIONAL)
		{
			programName += "vs";
		}
		else
		{
			programName += "LightMaterial_vs";
		}

		Ogre::GpuProgramPtr ptr = Ogre::HighLevelGpuProgramManager::getSingleton().getByName(programName);
		assert(!ptr.isNull());
		return ptr;
	}
コード例 #4
0
ファイル: mainwindow.cpp プロジェクト: ironsteel/QtOME
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());
}
コード例 #5
0
ファイル: Terrain.cpp プロジェクト: gitrider/wxsj2
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;
}
コード例 #6
0
ファイル: gkDebugScreen.cpp プロジェクト: guozanhua/github
void gkDebugScreen::initialize()
{
	if (m_isInit)
		return;

	try
	{

		m_font = new gkBuiltinFont;
		Ogre::FontPtr fp = Ogre::FontManager::getSingleton().create("<gkBuiltin/Font>", GK_BUILTIN_GROUP, true, m_font);
		fp->load();

#define  FONT_MATERIAL 1
#if FONT_MATERIAL

#ifndef OGREKIT_USE_OLD
		gkString ShareMaterail = "Examples/BumpMapping/MultiLight";
		static int Use_Init_Once = 0;
		if(Use_Init_Once < 2)
		{
			Ogre::FileInfoListPtr fileInfoList =
				Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
				"",
				"*.material");

			for (Ogre::FileInfoList::const_iterator cit=fileInfoList->begin();
				cit != fileInfoList->end();
				++cit) {
					const Ogre::String& name = cit->filename;
					const Ogre::String& basename = cit->basename;
					Ogre::String sType = cit->archive->getType();
					Ogre::String sPath = cit->archive->getName();
					if (sType=="Zip" || sType=="FileSystem") { 
						Ogre::DataStreamPtr pData=
							Ogre::ResourceGroupManager::getSingleton().openResource(
							basename,"");
						Ogre::MaterialManager::getSingleton().parseScript(
							pData, "");
						Ogre::MaterialManager::getSingleton().load(basename,"");
					}
			}
			Use_Init_Once++;
		}	
#endif

		Ogre::MaterialPtr ShareMaterailPtr = Ogre::MaterialManager::getSingleton().getByName(ShareMaterail, "");
		if (!ShareMaterailPtr.isNull())
		{
			ShareMaterailPtr->load();
			//ShareMaterailPtr->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("textureCount",1);
		}

		Ogre::MaterialPtr oma = Ogre::MaterialManager::getSingleton().getByName("Fonts/<gkBuiltin/Font>");

		if (!oma.isNull())
		{
			Ogre::Pass* pass1 = oma->getTechnique(0)->getPass(0);

			Ogre::GpuProgramPtr vsPtr = Ogre::HighLevelGpuProgramManager::getSingleton().getByName("FixVs");

			if (vsPtr.isNull())
			{
				LogManager::getSingleton().logMessage("GpuProgramPtr NULL");
			}

			gkString VertexProgramName = "FixVs";
			gkString FragmentProgramName ="FixPs";

			if (pass1)
			{
				pass1->setVertexProgram(VertexProgramName);
				pass1->setFragmentProgram(FragmentProgramName);
				Ogre::GpuProgramParametersSharedPtr vsParams = pass1->getVertexProgramParameters();
				vsParams->copyMatchingNamedConstantsFrom(*ShareMaterailPtr->getTechnique(0)->getPass(0)->getVertexProgramParameters().get());
				Ogre::GpuProgramParametersSharedPtr psParams = pass1->getFragmentProgramParameters();
				psParams->copyMatchingNamedConstantsFrom(*ShareMaterailPtr->getTechnique(0)->getPass(0)->getFragmentProgramParameters().get());
				//psParams->setNamedConstant("textureCount",1);
				//psParams->setNamedConstant("AlphaValue",0.0f);
				//vsParams->setNamedConstant("lightOpen",0);
				LogManager::getSingleton().logMessage("set font es2.0");
			}
		}
#endif

		Ogre::OverlayManager& mgr = Ogre::OverlayManager::getSingleton();
		m_over  = mgr.create("<gkBuiltin/gkDebugScreen>");
		m_ele   = mgr.createOverlayElement("TextArea", "<gkBuiltin/gkDebugScreen/TextArea>");

		Ogre::OverlayContainer* cont = (Ogre::OverlayContainer*)mgr.createOverlayElement("BorderPanel", "<gkBuiltin/gkDebugScreen/Containter>");
		cont->setMetricsMode(Ogre::GMM_PIXELS);
		cont->setVerticalAlignment(Ogre::GVA_TOP);

		const gkVector2& dims = gkWindowSystem::getSingleton().getMouse()->winsize;

		m_ele->setMetricsMode(Ogre::GMM_PIXELS);
		m_ele->setVerticalAlignment(Ogre::GVA_TOP);
		m_ele->setPosition(0, 0);
		m_ele->setDimensions(dims.x, dims.y);

		Ogre::TextAreaOverlayElement* textArea = static_cast<Ogre::TextAreaOverlayElement*>(m_ele);
		textArea->setFontName("<gkBuiltin/Font>");
		textArea->setCharHeight(SCREEN_SIZE);
		textArea->setColour(Ogre::ColourValue::White);

		m_over->setZOrder(500);
		cont->addChild(m_ele);
		m_over->add2D(cont);
	}
	catch (Ogre::Exception& e)
	{
		gkPrintf("%s", e.getDescription().c_str());
		return;
	}


	m_isInit = true;
	gConsole = this;
}
コード例 #7
0
bool OgreMaterialProperties::CreateProperties()
{
    Ogre::MaterialPtr matPtr = material_->GetMaterial();
    if (matPtr.isNull())
        return false;

    // Material
    Ogre::Material::TechniqueIterator tIter = matPtr->getTechniqueIterator();
    while(tIter.hasMoreElements())
    {
        // Technique
        Ogre::Technique *tech = tIter.getNext();
        Ogre::Technique::PassIterator pIter = tech->getPassIterator();
        while(pIter.hasMoreElements())
        {
            // Pass
            Ogre::Pass *pass = pIter.getNext();
            if (!pass)
                continue;

            if(pass->hasVertexProgram())
            {
                // Vertex program
                const Ogre::GpuProgramPtr &verProg = pass->getVertexProgram();
                if (!verProg.isNull())
                {
                    Ogre::GpuProgramParametersSharedPtr verPtr = pass->getVertexProgramParameters();
                    if (verPtr->hasNamedParameters())
                    {
                        // Named parameters (constants)
                        Ogre::GpuConstantDefinitionIterator mapIter = verPtr->getConstantDefinitionIterator();
                        while(mapIter.hasMoreElements())
                        {
                            QString paramName = mapIter.peekNextKey().c_str();
                            const Ogre::GpuConstantDefinition &paramDef  = mapIter.getNext();

                            // Filter names that end with '[0]'
                            int found = paramName.indexOf("[0]");
                            if (found != -1)
                                continue;

                            // Ignore auto parameters
                            bool is_auto_param = false;
                            Ogre::GpuProgramParameters::AutoConstantIterator autoConstIter = verPtr->getAutoConstantIterator();
                            while(autoConstIter.hasMoreElements())
                            {
                                Ogre::GpuProgramParameters::AutoConstantEntry autoConstEnt = autoConstIter.getNext();
                                if (autoConstEnt.physicalIndex == paramDef.physicalIndex)
                                {
                                    is_auto_param = true;
                                    break;
                                }
                            }

                            if (is_auto_param)
                                continue;

                            if (!paramDef.isFloat())
                                continue;

                            size_t count = paramDef.elementSize * paramDef.arraySize;
                            QVector<float> paramValue;
                            QVector<float>::iterator iter;
                            paramValue.resize(count);
                            verPtr->_readRawConstants(paramDef.physicalIndex, count, &*paramValue.begin());

                            QTextStream vector_string;
                            QString string;
                            vector_string.setString(&string, QIODevice::WriteOnly);

                            for(iter = paramValue.begin(); iter != paramValue.end(); ++iter)
                                vector_string << *iter << " ";

                            // Add QPROPERTY. Add to "VP" to the end of the parameter name in order to identify VP parameters.
                            QMap<QString, QVariant> typeValuePair;
                            typeValuePair[GpuConstantTypeToString(paramDef.constType)] = *vector_string.string();
                            setProperty(paramName.append(" VP").toLatin1(), QVariant(typeValuePair));
                        }
                    }
                }
            }

            if(pass->hasFragmentProgram())
            {
                // Fragment program
                const Ogre::GpuProgramPtr fragProg = pass->getFragmentProgram();
                if (!fragProg.isNull())
                {
                    Ogre::GpuProgramParametersSharedPtr fragPtr = pass->getFragmentProgramParameters();
                    if (!fragPtr.isNull())
                    {
                        if (fragPtr->hasNamedParameters())
                        {
                            // Named parameters (constants)
                            Ogre::GpuConstantDefinitionIterator mapIter = fragPtr->getConstantDefinitionIterator();
                            while(mapIter.hasMoreElements())
                            {
                                QString paramName = mapIter.peekNextKey().c_str();
                                const Ogre::GpuConstantDefinition &paramDef  = mapIter.getNext();

                                // Filter names that end with '[0]'
                                int found = paramName.indexOf("[0]");
                                if (found != -1)
                                    continue;

                                // Ignore auto parameters
                                bool is_auto_param = false;
                                Ogre::GpuProgramParameters::AutoConstantIterator autoConstIter = fragPtr->getAutoConstantIterator();
                                while(autoConstIter.hasMoreElements())
                                {
                                    Ogre::GpuProgramParameters::AutoConstantEntry autoConstEnt = autoConstIter.getNext();
                                    if (autoConstEnt.physicalIndex == paramDef.physicalIndex)
                                    {
                                        is_auto_param = true;
                                        break;
                                    }
                                }

                                if (is_auto_param)
                                    continue;

                                if (!paramDef.isFloat())
                                    continue;

                                size_t count = paramDef.elementSize * paramDef.arraySize;
                                QVector<float> paramValue;
                                QVector<float>::iterator iter;
                                paramValue.resize(count);

                                fragPtr->_readRawConstants(paramDef.physicalIndex, count, &*paramValue.begin());

                                QTextStream vector_string;
                                QString string;
                                vector_string.setString(&string, QIODevice::WriteOnly);

                                for(iter = paramValue.begin(); iter != paramValue.end(); ++iter)
                                    vector_string << *iter << " ";

                                // Add QPROPERTY. Add to " FP" to the end of the parameter name in order to identify FP parameters
                                TypeValuePair typeValuePair;
                                typeValuePair[GpuConstantTypeToString(paramDef.constType)] = *vector_string.string();
                                setProperty(paramName.append(" FP").toLatin1(), QVariant(typeValuePair));
                            }
                        }
                    }
                }
            }

            Ogre::Pass::TextureUnitStateIterator texIter = pass->getTextureUnitStateIterator();
            while(texIter.hasMoreElements())
            {
                // Texture units
                const Ogre::TextureUnitState *tu = texIter.getNext();
                
                // Don't insert tu's with empty texture names (i.e. shadowMap)
                // add to " TU" to the end of the parameter name in order to identify texture units.
                if(tu->getTextureName().size() > 0)
                {
                    QString tuName(tu->getName().c_str());

                    // Add QPROPERTY
                    TypeValuePair typeValuePair;
                    typeValuePair[TextureTypeToString(tu->getTextureType())] = tu->getTextureName().c_str();
                    setProperty(tuName.append(" TU").toLatin1(), typeValuePair);
                }
            }
        }
    }

    return true;
}