virtual GpuProgramPtr generateFragmentShader(Perm permutation) { /// Create shader if (mMasterSource.empty()) { DataStreamPtr ptrMasterSource = ResourceGroupManager::getSingleton().openResource( "DeferredShading/post/LightMaterial_ps.cg" , ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); assert(ptrMasterSource.isNull()==false); mMasterSource = ptrMasterSource->getAsString(); } assert(mMasterSource.empty()==false); // Create name String name = mBaseName+StringConverter::toString(permutation)+"_ps"; // Create shader object HighLevelGpuProgramPtr ptrProgram = HighLevelGpuProgramManager::getSingleton().createProgram( name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "cg", GPT_FRAGMENT_PROGRAM); ptrProgram->setSource(mMasterSource); ptrProgram->setParameter("entry_point","main"); ptrProgram->setParameter("profiles","ps_2_x arbfp1"); // set up the preprocessor defines // Important to do this before any call to get parameters, i.e. before the program gets loaded ptrProgram->setParameter("compile_arguments", getPPDefines(permutation)); setUpBaseParameters(ptrProgram->getDefaultParameters()); return GpuProgramPtr(ptrProgram); }
virtual GpuProgramPtr generateFragmentShader(Perm permutation) { /// Create shader if (mMasterSource.empty()) { DataStreamPtr ptrMasterSource; if(GpuProgramManager::getSingleton().isSyntaxSupported("glsles")) ptrMasterSource = ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsles", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); else ptrMasterSource = ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsl", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); assert(ptrMasterSource.isNull()==false); mMasterSource = ptrMasterSource->getAsString(); } assert(mMasterSource.empty()==false); // Create name String name = mBaseName+StringConverter::toString(permutation)+"_ps"; // Create shader object HighLevelGpuProgramPtr ptrProgram; if(GpuProgramManager::getSingleton().isSyntaxSupported("glsles")) { ptrProgram = HighLevelGpuProgramManager::getSingleton().createProgram(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsles", GPT_FRAGMENT_PROGRAM); ptrProgram->setParameter("profiles", "glsles"); } else { ptrProgram = HighLevelGpuProgramManager::getSingleton().createProgram(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "glsl", GPT_FRAGMENT_PROGRAM); ptrProgram->setParameter("profiles", "glsl150"); } ptrProgram->setSource(mMasterSource); // set up the preprocessor defines // Important to do this before any call to get parameters, i.e. before the program gets loaded ptrProgram->setParameter("preprocessor_defines", getPPDefines(permutation)); setUpBaseParameters(ptrProgram->getDefaultParameters()); // Bind samplers GpuProgramParametersSharedPtr params = ptrProgram->getDefaultParameters(); int numSamplers = 0; params->setNamedConstant("Tex0", (int)numSamplers++); params->setNamedConstant("Tex1", (int)numSamplers++); if(permutation & LightMaterialGenerator::MI_SHADOW_CASTER) params->setNamedConstant("ShadowTex", (int)numSamplers++); return GpuProgramPtr(ptrProgram); }
void zzzSndSystem::LoadSounds() { //read xml & load sets DataStreamPtr data = ResourceGroupManager::getSingleton().openResource("sounds.xml"); String str = data->getAsString(); TiXmlDocument doc; doc.Parse(str.c_str()); if (!doc.Error()) { TiXmlNode* node; node=doc.FirstChild(); node=node->FirstChild(); for (;node!=0;node=node->NextSibling()) { if (node->Type() == TiXmlNode::ELEMENT) { //get params String name = ""; String file = ""; if (strcmp(node->Value(), "sound") == 0) { TiXmlAttribute* att = node->ToElement()->FirstAttribute(); while (att) { if (strcmp(att->Name(), "name") == 0) { name = att->Value(); } else if (strcmp(att->Name(), "file") == 0) { file = att->Value(); } att = att->Next(); } if (name.length() > 0) { SND->LoadSound(name, file); } } } } } else { throw Exception(Exception::ERR_FILE_NOT_FOUND, std::string(doc.ErrorDesc()) + " : particles.xml", __FUNCTION__); } }
//----------------------------------------------------------------------------- void D3D11GpuProgram::loadImpl(void) { // Normal load-from-source approach if (mLoadFromFile) { // find & load source code DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource( mFilename, mGroup, true, this); mSource = stream->getAsString(); } // Call polymorphic load loadFromSource(); }
//--------------------------------------------------------------------------- void HighLevelGpuProgram::loadHighLevelImpl(void) { if (mLoadFromFile) { // find & load source code DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource( mFilename, mGroup, true, this); mSource = stream->getAsString(); } loadFromSource(); }
//----------------------------------------------------------------------------- void GpuProgram::loadImpl(void) { if (mLoadFromFile) { // find & load source code DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource( mFilename, mGroup, true, this); mSource = stream->getAsString(); } // Call polymorphic load try { loadFromSource(); if (!mDefaultParams.isNull()) { // Keep a reference to old ones to copy GpuProgramParametersSharedPtr savedParams = mDefaultParams; // reset params to stop them being referenced in the next create mDefaultParams.setNull(); // Create new params mDefaultParams = createParameters(); // Copy old (matching) values across // Don't use copyConstantsFrom since program may be different mDefaultParams->copyMatchingNamedConstantsFrom(*savedParams.get()); } } catch (const Exception&) { StringStream ss; ss << "Gpu program " << mName << " encountered an error " << "during loading and is thus not supported."; mCompileErrorMessage = ss.str(); // will already have been logged LogManager::getSingleton().stream() << mCompileErrorMessage; mCompileError = true; } }
bool LuaScript::LoadTextFile ( const String& fileName, String& text, const String& resourceGroupName ) { //Open the file try { DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource(fileName, resourceGroupName); if (stream.isNull()) return false; //Get the text file contents text = stream->getAsString(); return true; } catch (...) { return false; } }
STDMETHOD(Open)(D3D10_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pByteLen ) { // find & load source code DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource( String(pFileName), mProgram->getGroup(), true, mProgram); String source = stream->getAsString(); // copy into separate c-string // Note - must NOT copy the null terminator, otherwise this will terminate // the entire program string! *pByteLen = static_cast<UINT>(source.length()); char* pChar = new char[*pByteLen]; memcpy(pChar, source.c_str(), *pByteLen); *ppData = pChar; return S_OK; }
//Implementation--------------------------------------------------------------- void OgreMaxUtilities::LoadXmlDocument(const String& fileName, TiXmlDocument& document, const String& resourceGroupName) { //Open the file DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource(fileName, resourceGroupName); if (stream.isNull()) { StringUtil::StrStreamType errorMessage; errorMessage << "Could not open XML file: " << fileName; OGRE_EXCEPT ( Exception::ERR_FILE_NOT_FOUND, errorMessage.str(), "OgreMaxUtilities::LoadXmlDocument" ); } //Get the file contents String data = stream->getAsString(); //Parse the XML document document.Parse(data.c_str()); stream.setNull(); if (document.Error()) { StringUtil::StrStreamType errorMessage; errorMessage << "There was an error with the XML file: " << fileName; OGRE_EXCEPT ( Exception::ERR_INVALID_STATE, errorMessage.str(), "OgreMaxUtilities::LoadXmlDocument" ); } }
//----------------------------------------------------------------------- String CgProgram::resolveCgIncludes(const String& inSource, Resource* resourceBeingLoaded, const String& fileName) { String outSource; // output will be at least this big outSource.reserve(inSource.length()); size_t startMarker = 0; size_t i = inSource.find("#include"); while (i != String::npos) { size_t includePos = i; size_t afterIncludePos = includePos + 8; size_t newLineBefore = inSource.rfind("\n", includePos); // check we're not in a comment size_t lineCommentIt = inSource.rfind("//", includePos); if (lineCommentIt != String::npos) { if (newLineBefore == String::npos || lineCommentIt > newLineBefore) { // commented i = inSource.find("#include", afterIncludePos); continue; } } size_t blockCommentIt = inSource.rfind("/*", includePos); if (blockCommentIt != String::npos) { size_t closeCommentIt = inSource.rfind("*/", includePos); if (closeCommentIt == String::npos || closeCommentIt < blockCommentIt) { // commented i = inSource.find("#include", afterIncludePos); continue; } } // find following newline (or EOF) size_t newLineAfter = inSource.find("\n", afterIncludePos); // find include file string container String endDelimeter = "\""; size_t startIt = inSource.find("\"", afterIncludePos); if (startIt == String::npos || startIt > newLineAfter) { // try <> startIt = inSource.find("<", afterIncludePos); if (startIt == String::npos || startIt > newLineAfter) { OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Badly formed #include directive (expected \" or <) in file " + fileName + ": " + inSource.substr(includePos, newLineAfter-includePos), "CgProgram::preprocessor"); } else { endDelimeter = ">"; } } size_t endIt = inSource.find(endDelimeter, startIt+1); if (endIt == String::npos || endIt <= startIt) { OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Badly formed #include directive (expected " + endDelimeter + ") in file " + fileName + ": " + inSource.substr(includePos, newLineAfter-includePos), "CgProgram::preprocessor"); } // extract filename String filename(inSource.substr(startIt+1, endIt-startIt-1)); // open included file DataStreamPtr resource = ResourceGroupManager::getSingleton(). openResource(filename, resourceBeingLoaded->getGroup(), resourceBeingLoaded); // replace entire include directive line // copy up to just before include if (newLineBefore != String::npos && newLineBefore >= startMarker) outSource.append(inSource.substr(startMarker, newLineBefore-startMarker+1)); size_t lineCount = 0; size_t lineCountPos = 0; // Count the line number of #include statement lineCountPos = outSource.find('\n'); while(lineCountPos != String::npos) { lineCountPos = outSource.find('\n', lineCountPos+1); lineCount++; } // Add #line to the start of the included file to correct the line count outSource.append("#line 1 \"" + filename + "\"\n"); outSource.append(resource->getAsString()); // Add #line to the end of the included file to correct the line count outSource.append("\n#line " + Ogre::StringConverter::toString(lineCount) + "\"" + fileName + "\"\n"); startMarker = newLineAfter; if (startMarker != String::npos) i = inSource.find("#include", startMarker); else i = String::npos; } // copy any remaining characters outSource.append(inSource.substr(startMarker)); return outSource; }
void DotSceneLoader::parseDotScene(const String &SceneName, const String &groupName, SceneManager *yourSceneMgr, SceneNode *pAttachNode, const String &sPrependNode) { // set up shared object values m_sGroupName = groupName; mSceneMgr = yourSceneMgr; m_sPrependNode = sPrependNode; staticObjects.clear(); dynamicObjects.clear(); TiXmlDocument *XMLDoc = 0; TiXmlElement *XMLRoot; try { // Strip the path Ogre::String basename, path; Ogre::StringUtil::splitFilename(SceneName, basename, path); DataStreamPtr pStream = ResourceGroupManager::getSingleton(). openResource( basename, groupName ); //DataStreamPtr pStream = ResourceGroupManager::getSingleton(). // openResource( SceneName, groupName ); String data = pStream->getAsString(); // Open the .scene File XMLDoc = new TiXmlDocument(); XMLDoc->Parse( data.c_str() ); pStream->close(); pStream.setNull(); if( XMLDoc->Error() ) { //We'll just log, and continue on gracefully LogManager::getSingleton().logMessage("[DotSceneLoader] The TiXmlDocument reported an error"); delete XMLDoc; return; } } catch(...) { //We'll just log, and continue on gracefully LogManager::getSingleton().logMessage("[DotSceneLoader] Error creating TiXmlDocument"); delete XMLDoc; return; } // Validate the File XMLRoot = XMLDoc->RootElement(); if( String( XMLRoot->Value()) != "scene" ) { LogManager::getSingleton().logMessage( "[DotSceneLoader] Error: Invalid .scene File. Missing <scene>" ); delete XMLDoc; return; } // figure out where to attach any nodes we create mAttachNode = pAttachNode; if(!mAttachNode) mAttachNode = mSceneMgr->getRootSceneNode(); // Process the scene processScene(XMLRoot); // Close the XML File delete XMLDoc; }
void LuaManager::parseScript(DataStreamPtr& stream, const String&) { currentFileName = stream->getName(); doString(stream->getAsString()); }
void BillboardSystem::Initialize() { //create node bnode = GSYS->GetSceneMgr()->getRootSceneNode()->createChildSceneNode("BillboardSystemNode"); //read xml & load sets DataStreamPtr data = ResourceGroupManager::getSingleton().openResource("billboards.xml"); String str = data->getAsString(); TiXmlDocument doc; doc.Parse(str.c_str()); if (!doc.Error()) { TiXmlNode* node; node=doc.FirstChild(); node=node->FirstChild(); for (;node!=0;node=node->NextSibling()) { if (node->Type() == TiXmlNode::ELEMENT) { //get params String name = ""; String material = ""; int type = 0; int poolsize = 0; float width = 0; float height = 0; if (strcmp(node->Value(), "billboard") == 0) { TiXmlAttribute* att = node->ToElement()->FirstAttribute(); while (att) { if (strcmp(att->Name(), "name") == 0) { name = att->Value(); } else if (strcmp(att->Name(), "type") == 0) { type = StringConverter::parseInt(att->Value()); } else if (strcmp(att->Name(), "poolsize") == 0) { poolsize = StringConverter::parseInt(att->Value()); } else if (strcmp(att->Name(), "material") == 0) { material = att->Value(); } else if (strcmp(att->Name(), "width") == 0) { width = StringConverter::parseReal(att->Value()); } else if (strcmp(att->Name(), "height") == 0) { height = StringConverter::parseReal(att->Value()); } att = att->Next(); } //add set if (name.length() > 0) { BillboardNodeSet* bset = new BillboardNodeSet(poolsize); bset->set = GSYS->GetSceneMgr()->createBillboardSet(name, poolsize); bset->set->setMaterialName(material); bset->set->setDefaultDimensions(width, height); bset->set->setBillboardType((BillboardType)type); bset->set->setRenderQueueGroup(RENDER_QUEUE_SKIES_LATE); AxisAlignedBox aabInf;aabInf.setInfinite();; bset->set->setBounds(aabInf, 1024); bnode->attachObject(bset->set); //create billboard buffer for (int i=0;i<poolsize;i++) { BillboardNode* bbnode = new BillboardNode(); bset->buffer.push_back(bbnode); } //finally add sets[name] = bset; } } } } } else { throw Exception(Exception::ERR_FILE_NOT_FOUND, std::string(doc.ErrorDesc()) + " : billboards.xml", __FUNCTION__); } }
int main() { using namespace Orz; SystemPtr system(new SystemList<boost::mpl::list<OgreGraphicsManager, CEGUIManager, OISInputManager, FmodSoundManager, PluginsManager, SingleChipManager, EventWorldUpdate> >()); LogicConfiger::LogicFacadePtr logic(new LogicConfiger::LogicFacade()); //LogicConfiger::ConfigerPtr logic(new LogicConfiger::Configer()); CEGUIManager::getSingleton().mouseEvent(false); CEGUIManager::getSingleton().keyEvent(true); LogicConfiger::ManualBuilder builder; //boost::shared_ptr<LogicConfigerManualLoader> loader(new LogicConfigerManualLoader()); builder.addPlugin("Model_Base"); #ifdef _NetWheelDirector builder.addPlugin("NetWheelDirector"); #endif #ifdef _MyWheelDirector builder.addPlugin("MyWheelDirector"); #endif #ifdef _WheelAnimal2 builder.addPlugin("WheelAnimal2Model"); #endif //builder.addPlugin("CodingComponent"); //builder.addPlugin("MyJobComponent"); builder.setTheater("TheaterBase","main"); /* NameValueList p; p["XML_FILE"] = VariantData<std::string>::set(std::string("UnitTest.xml"));*/ builder.addDirector("WheelDirector","wheel"); builder.setActiveDirector("wheel"); //Orz::DirectorPtr dp = GameFactories::getInstance().createDirector("WheelDirector", "director", &p); logic->building(builder); //SystemInterface::getSingleton().setParame<std::string>("AomiUI_MediaDirectory", std::string("..\\..\\media\\animalUI")); SystemInterface::getSingleton().setParame<bool>("SILENT", true); SystemInterface::getSingleton().setParame<bool>("OGRE_NO_OUT", true); //SystemInterface::getSingleton().setParame<bool>("w32_mouse", true); //SystemInterface::getSingleton().setParame<bool>("CEGUI_LOGO", true); //try //{ if(system->init()) { using namespace Ogre; DataStreamPtr pStream; pStream = ResourceGroupManager::getSingleton().openResource( "sc.xml", "xml" ); using namespace rapidxml; String data = pStream->getAsString(); xml_document<> doc; doc.parse<0>(&data[0]); rapidxml::xml_node<> *node = doc.first_node("single-chips"); Orz::SingleChipManager::getSingleton().loadXML(node); if(logic->load(EventWorld::Parameter().multiThread(false).fixedStep(false))) { system->run(); logic->unload(); } system->shutdown(); } //} //catch(std::exception & e) //{ // std::cout<<e.what(); // ORZ_LOG_CRITICAL_MESSAGE(e.what()); //} }
void DotSceneLoader::parseDotScene(const String &SceneName, const String &groupName, SceneManager *yourSceneMgr, CPhysicsManager *pPhysicsManager, SceneNode *pAttachNode, const String &sPrependNode) { cleanup(); Ogre::LogManager::getSingleton().logMessage("Loading dot scene: " + SceneName); // set up shared object values m_sGroupName = groupName; mSceneMgr = yourSceneMgr; m_pPhysicsManager = pPhysicsManager; m_sPrependNode = sPrependNode; mStaticSceneNode = pAttachNode->createChildSceneNode(sPrependNode + "StaticSceneNode"); XMLDocument *XMLDoc = 0; XMLElement *XMLRoot; try { // Strip the path Ogre::String basename, path; Ogre::StringUtil::splitFilename(SceneName, basename, path); // Do not look in other groups but the given one DataStreamPtr pStream = ResourceGroupManager::getSingleton(). openResource( basename, groupName, false ); //DataStreamPtr pStream = ResourceGroupManager::getSingleton(). // openResource( SceneName, groupName ); String data = pStream->getAsString(); // Open the .scene File XMLDoc = new XMLDocument(); XMLDoc->Parse( data.c_str() ); pStream->close(); pStream.setNull(); if( XMLDoc->Error() ) { //We'll just log, and continue on gracefully LogManager::getSingleton().logMessage("[DotSceneLoader] The TiXmlDocument reported an error"); delete XMLDoc; return; } } catch(...) { //We'll just log, and continue on gracefully LogManager::getSingleton().logMessage("[DotSceneLoader] Error creating TiXmlDocument"); delete XMLDoc; return; } // Validate the File XMLRoot = XMLDoc->RootElement(); if( String( XMLRoot->Value()) != "scene" ) { LogManager::getSingleton().logMessage( "[DotSceneLoader] Error: Invalid .scene File. Missing <scene>" ); delete XMLDoc; return; } // figure out where to attach any nodes we create mAttachNode = pAttachNode; if(!mAttachNode) mAttachNode = mSceneMgr->getRootSceneNode(); // Process the scene processScene(XMLRoot); /*for (auto &m : m_mStaticGeometryMap) { m.second->build(); }*/ /*for (auto &s : mStaticObjects) { for (auto &cb : m_lCallbacks){ cb->staticObjectAdded(s); } } // remove static geometry entities destroySceneNode(mStaticSceneNode);*/ // apply manually material data // =============================== // dont cull grass auto mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("CS_Grass")); if (!mat.isNull() && mat->getBestTechnique()) { mat->getBestTechnique()->setCullingMode(Ogre::CullingMode::CULL_NONE); } // make water transparent, add textures mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName("Water")); if (!mat.isNull() && mat->getBestTechnique()) { mat->getBestTechnique()->setCullingMode(Ogre::CullingMode::CULL_NONE); mat->getBestTechnique()->getPass(0)->setDepthCheckEnabled(true); mat->getBestTechnique()->getPass(0)->setDepthWriteEnabled(false); mat->getBestTechnique()->getPass(0)->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE); mat->getBestTechnique()->getPass(0)->getTextureUnitState(0)->setTransformAnimation( Ogre::TextureUnitState::TT_TRANSLATE_U, Ogre::WFT_SINE, 0, 0.25, 0, 0.125); mat->getBestTechnique()->getPass(0)->getTextureUnitState(0)->setColourOperation(Ogre::LBO_MODULATE); mat->getBestTechnique()->getPass(0)->getTextureUnitState(1)->setTransformAnimation( Ogre::TextureUnitState::TT_TRANSLATE_V, Ogre::WFT_SINE, 0.1, 0.25, 0.1, 0.125); mat->getBestTechnique()->getPass(0)->getTextureUnitState(1)->setTextureRotate(Ogre::Degree(90)); mat->getBestTechnique()->getPass(0)->getTextureUnitState(1)->setColourOperation(Ogre::LBO_MODULATE); mat->getBestTechnique()->getPass(0)->setDiffuse(1, 1, 1, 0.8); } /*for (auto &m : m_lEntityBufferMap) { mSceneMgr->destroyEntity(m.second); }*/ // Close the XML File delete XMLDoc; // remove callbacks m_lCallbacks.clear(); cleanup(); }