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; }
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; }
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 ¶mDef = 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 ¶mDef = 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; }