ResourcePtr ResourceManager::clone(const ResourcePtr &src) { uint32_t unCloneID = (++mCloneID); ResourcePtr res = src->clone(); if (res != nullptr) { res->mCloneID = unCloneID; auto i = mResourceCache.find(src->getName()); if (i != mResourceCache.end()) { Resources &resources = i->second; resources.insert(ResPairValue(unCloneID, res)); } else { T3D_ASSERT(0); } } return res; }
void MeshSerializerTests::getResourceFullPath(const ResourcePtr& resource, String& outPath) { ResourceGroupManager& resourceGroupMgr = ResourceGroupManager::getSingleton(); String group = resource->getGroup(); String name = resource->getName(); FileInfo* info = NULL; FileInfoListPtr locPtr = resourceGroupMgr.listResourceFileInfo(group); FileInfoList::iterator it, itEnd; it = locPtr->begin(); itEnd = locPtr->end(); for (; it != itEnd; it++) { if (stricmp(name.c_str(), it->filename.c_str()) == 0) { info = &*it; break; } } if(!info) { outPath = name; return; } outPath = info->archive->getName(); if (outPath[outPath .size()-1] != '/' && outPath[outPath .size()-1] != '\\') { outPath += '/'; } outPath += info->path; if (outPath[outPath .size()-1] != '/' && outPath[outPath .size()-1] != '\\') { outPath += '/'; } outPath += info->filename; assert(info->archive->getType() == "FileSystem"); }
bool Font::loadFromFontFile(const ResourcePtr& resource, uint32 size, bool bold, bool italic) { bool result = mFace->load(resource); if(result) { mGlyphs.resize(mFace->face->num_glyphs); for(int i = 0; i < mFace->face->num_glyphs; ++i) { mGlyphs[i].size = mFontSize; mGlyphs[i].face = &mFace->face; } mEnableShadow = false; mEnableStroke = false; mShadowXOffset = 0; mShadowYOffset = 0; mStrokeWidth = 0; mFontSize = size; if(bold) { this->setFTStyle(FT_STYLE_FLAG_BOLD); } if(italic) { this->setFTStyle(FT_STYLE_FLAG_ITALIC); } mFontName = resource->getName(); } return result; }
bool load(const ResourcePtr& resource) { if(!Font::FTLibrary::Instance().library) return false; if(face) { FT_Done_Face(face); } if(resource && resource->getResourceStream()) { font_data = resource->getResourceStream()->readIntoMemory(); if(FT_New_Memory_Face(Font::FTLibrary::Instance().library, static_cast<MemoryStream*>(font_data.get())->data(), font_data->size(), 0, &face)) { return false; } FT_Select_Charmap(face, FT_ENCODING_UNICODE); return true; } else { if(FT_New_Face(Font::FTLibrary::Instance().library, string::WStringToString(resource->getName()).c_str(), 0, &face)) { return false; } return true; } return false; }
void ControllerUI::LoadingBar::ResourceLoadStarted(ResourcePtr resource) { if (!OgreClient::Singleton->RenderWindow->isClosed()) { Content->setText(resource->getName()); Content->setProgress(Content->getProgress() + stepSizeContent); // render a frame to update (not yet in apploop) OgreClient::Singleton->Root->renderOneFrame(); ::Ogre::WindowEventUtilities::messagePump(); } };
//----------------------------------------------------------------------- void ResourceManager::addImpl( ResourcePtr& res ) { OGRE_LOCK_AUTO_MUTEX std::pair<ResourceMap::iterator, bool> result = mResources.insert( ResourceMap::value_type( res->getName(), res ) ); if (!result.second) { OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Resource with the name " + res->getName() + " already exists.", "ResourceManager::add"); } std::pair<ResourceHandleMap::iterator, bool> resultHandle = mResourcesByHandle.insert( ResourceHandleMap::value_type( res->getHandle(), res ) ); if (!resultHandle.second) { OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Resource with the handle " + StringConverter::toString((long) (res->getHandle())) + " already exists.", "ResourceManager::add"); } }
//----------------------------------------------------------------------- void ResourceManager::removeImpl(const ResourcePtr& res ) { OgreAssert(res, "attempting to remove nullptr"); OGRE_LOCK_AUTO_MUTEX; if(ResourceGroupManager::getSingleton().isResourceGroupInGlobalPool(res->getGroup())) { ResourceMap::iterator nameIt = mResources.find(res->getName()); if (nameIt != mResources.end()) { mResources.erase(nameIt); } } else { ResourceWithGroupMap::iterator groupIt = mResourcesWithGroup.find(res->getGroup()); if (groupIt != mResourcesWithGroup.end()) { ResourceMap::iterator nameIt = groupIt->second.find(res->getName()); if (nameIt != groupIt->second.end()) { groupIt->second.erase(nameIt); } if (groupIt->second.empty()) { mResourcesWithGroup.erase(groupIt); } } } ResourceHandleMap::iterator handleIt = mResourcesByHandle.find(res->getHandle()); if (handleIt != mResourcesByHandle.end()) { mResourcesByHandle.erase(handleIt); } // Tell resource group manager ResourceGroupManager::getSingleton()._notifyResourceRemoved(res); }
bool ConfigParserXmlImpl::open(ResourcePtr resource) { StreamPtr dataStream = resource->getResourceStream()->readIntoMemory(); if(dataStream) { if(!mDocument) { mDocument = new pugi::xml_document; } bool result = mDocument->load_buffer((void*)static_cast<MemoryStream*>(dataStream.get())->data(), dataStream->size(), pugi::encoding_wchar); if(result) { mName = resource->getName(); mCurrNode = mDocument->root(); return result; } } return false; }
//----------------------------------------------------------------------- void ResourceManager::removeImpl( ResourcePtr& res ) { OGRE_LOCK_AUTO_MUTEX ResourceMap::iterator nameIt = mResources.find(res->getName()); if (nameIt != mResources.end()) { mResources.erase(nameIt); } ResourceHandleMap::iterator handleIt = mResourcesByHandle.find(res->getHandle()); if (handleIt != mResourcesByHandle.end()) { mResourcesByHandle.erase(handleIt); } // Tell resource group manager ResourceGroupManager::getSingleton()._notifyResourceRemoved(res); }
bool CgDxShader::initialize(D3D11GraphicDevice* device, const ResourcePtr& resource, const ShaderDesc& desc) { mDesc = desc; mDevice = device; StreamPtr stream = resource->readIntoMemory(); if(!stream) return false; MemoryStream* memStream = ((MemoryStream*)stream.get()); std::string content(memStream->data(), memStream->data() + memStream->size()); CGprofile profile = _d3d_feature_level_to_cgprofile(device->getDeviceFeatureLevel(), desc.type); mProgram = cgCreateProgram(mContext, CG_SOURCE, content.c_str(), profile, desc.entry.c_str(), cgD3D11GetOptimalOptions(profile)); if(_check_error(mContext, resource->getName().c_str()) && D3D11Debug::CHECK_RESULT( cgD3D11LoadProgram(mProgram, 0))) { return true; } return false; }
void LogoState::resourceLoadStarted(const ResourcePtr& resource) { mLoadingCommentElement->setCaption(resource->getName()); mLoadingCommentElement->getCaption(); updateLogoState(); }
void ResourceGroupLoadingBarSection::resourceLoadStarted(const ResourcePtr& resource) { mSection.setCaption(resource->getName()); }
void BaseGame::resourceLoadStarted(const ResourcePtr& resource) { assert(m_textRenderer); m_textRenderer->SetText(m_loadingTxtName, resource->getName()); m_renderWnd->update(); }
bool Font::loadFromConfigFile(const ResourcePtr& resource) { ConfigParserPtr config = ConfigParser::MakeParser(resource); if(config) return deserialize(config); else { log_error(L"ukn::Font::loadFromResource: invalid resource ptr, with resource name" + resource->getName()); } return false; }
/// Shadows config //--------------------------------------------------------------------------------------------------- void App::changeShadows() { QTimer ti; ti.update(); /// time // get settings bool enabled = pSet->shadow_type != 0; bool bDepth = pSet->shadow_type >= 2; bool bSoft = pSet->shadow_type == 3; pSet->shadow_size = std::max(0,std::min(ciShadowNumSizes-1, pSet->shadow_size)); int fTex = /*2048*/ ciShadowSizesA[pSet->shadow_size], fTex2 = fTex/2; int num = /*3*/ pSet->shadow_count; // disable 4 shadow textures (does not work because no texcoord's left in shader) if (num == 4) num = 3; TerrainMaterialGeneratorB::SM2Profile* matProfile = 0; if (mTerrainGlobals) { matProfile = (TerrainMaterialGeneratorB::SM2Profile*) mTerrainGlobals->getDefaultMaterialGenerator()->getActiveProfile(); if (matProfile) { matProfile->setReceiveDynamicShadowsEnabled(enabled); matProfile->setReceiveDynamicShadowsLowLod(true); matProfile->setGlobalColourMapEnabled(false); matProfile->setLayerSpecularMappingEnabled(pSet->ter_mtr >= 1); // ter mtr matProfile->setLayerNormalMappingEnabled( pSet->ter_mtr >= 2); matProfile->setLayerParallaxMappingEnabled(pSet->ter_mtr >= 3); } } if (!enabled) { mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); /*return;*/ } else { // General scene setup //mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED); mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED); mSceneMgr->setShadowFarDistance(pSet->shadow_dist); // 3000 mSceneMgr->setShadowTextureCountPerLightType(Light::LT_DIRECTIONAL, num); if (mPSSMSetup.isNull()) { // shadow camera setup PSSMShadowCameraSetup* pssmSetup = new PSSMShadowCameraSetup(); #ifndef ROAD_EDITOR pssmSetup->setSplitPadding(mSplitMgr->mCameras.front()->getNearClipDistance()); //pssmSetup->setSplitPadding(10); pssmSetup->calculateSplitPoints(num, mSplitMgr->mCameras.front()->getNearClipDistance(), mSceneMgr->getShadowFarDistance()); #else pssmSetup->setSplitPadding(mCamera->getNearClipDistance()); //pssmSetup->setSplitPadding(10); pssmSetup->calculateSplitPoints(num, mCamera->getNearClipDistance(), mSceneMgr->getShadowFarDistance()); #endif for (int i=0; i < num; ++i) { //int size = i==0 ? fTex : fTex2; const Real cAdjfA[5] = {2, 1, 0.5, 0.25, 0.125}; pssmSetup->setOptimalAdjustFactor(i, cAdjfA[std::min(i, 4)]); } materialFactory->setPSSMCameraSetup(pssmSetup); mPSSMSetup.bind(pssmSetup); } mSceneMgr->setShadowCameraSetup(mPSSMSetup); mSceneMgr->setShadowTextureCount(num); for (int i=0; i < num; ++i) { int size = i==0 ? fTex : fTex2; PixelFormat pf; if (bDepth && !bSoft) pf = PF_FLOAT32_R; else if (bSoft) pf = PF_FLOAT16_RGB; else pf = PF_X8B8G8R8; mSceneMgr->setShadowTextureConfig(i, size, size, pf); } mSceneMgr->setShadowTextureSelfShadow(bDepth ? true : false); //-? mSceneMgr->setShadowCasterRenderBackFaces((bDepth && !bSoft) ? true : false); String shadowCasterMat; if (bDepth && !bSoft) shadowCasterMat = "PSSM/shadow_caster"; else if (bSoft) shadowCasterMat = "PSVSM/shadow_caster"; else shadowCasterMat = StringUtil::BLANK; mSceneMgr->setShadowTextureCasterMaterial(shadowCasterMat); if (matProfile && terrain) { matProfile->setReceiveDynamicShadowsDepth(bDepth); matProfile->setReceiveDynamicShadowsPSSM(static_cast<PSSMShadowCameraSetup*>(mPSSMSetup.get())); MaterialPtr mtr = matProfile->generateForCompositeMap(terrain); //LogO(mtr->getBestTechnique()->getPass(0)->getTextureUnitState(0)->getName()); //LogO(String("Ter mtr: ") + mtr->getName()); } } materialFactory->setTerrain(terrain); materialFactory->setNumShadowTex(num); materialFactory->setShadows(pSet->shadow_type != 0); materialFactory->setShadowsDepth(bDepth); materialFactory->setShadowsSoft(bSoft); materialFactory->generate(); #if 0 // shadow tex overlay // add the overlay elements to show the shadow maps: // init overlay elements OverlayManager& mgr = OverlayManager::getSingleton(); Overlay* overlay; // destroy if already exists if (overlay = mgr.getByName("DebugOverlay")) mgr.destroy(overlay); overlay = mgr.create("DebugOverlay"); TexturePtr tex; for (size_t i = 0; i < 2; ++i) { //TexturePtr tex = mSceneMgr->getShadowTexture(i); if (i == 0) tex = TextureManager::getSingleton().getByName("PlaneReflection"); else tex = TextureManager::getSingleton().getByName("PlaneRefraction"); // Set up a debug panel to display the shadow if (MaterialManager::getSingleton().resourceExists("Ogre/DebugTexture" + toStr(i))) MaterialManager::getSingleton().remove("Ogre/DebugTexture" + toStr(i)); MaterialPtr debugMat = MaterialManager::getSingleton().create( "Ogre/DebugTexture" + toStr(i), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(tex->getName()); t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); OverlayContainer* debugPanel; // destroy container if exists try { if (debugPanel = static_cast<OverlayContainer*>( mgr.getOverlayElement("Ogre/DebugTexPanel" + toStr(i) ))) mgr.destroyOverlayElement(debugPanel); } catch (Ogre::Exception&) {} debugPanel = (OverlayContainer*) (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugTexPanel" + StringConverter::toString(i))); debugPanel->_setPosition(0.8, i*0.25); debugPanel->_setDimensions(0.2, 0.24); debugPanel->setMaterialName(debugMat->getName()); debugPanel->show(); overlay->add2D(debugPanel); overlay->show(); } #endif // ------------------- update the paged-geom materials // grass is not cloned, just need to set new shader parameters if (grass) { GrassLoader *grassLoader = static_cast<GrassLoader*>(grass->getPageLoader()); for (std::list<GrassLayer*>::iterator it= grassLoader->getLayerList().begin(); it != grassLoader->getLayerList().end(); ++it) { GrassLayer* layer = (*it); layer->applyShader(); } } // trees are more complicated since they are cloned //!todo this doesn't work (tree material does not update immediately) if(trees) { trees->reloadGeometry(); std::vector<ResourcePtr> reosurceToDelete; ResourceManager::ResourceMapIterator it = MaterialManager::getSingleton().getResourceIterator(); while (it.hasMoreElements()) { ResourcePtr material = it.getNext(); String materialName = material->getName(); std::string::size_type pos =materialName.find("BatchMat|"); if( pos != std::string::npos ) { reosurceToDelete.push_back(material); } } for(int i=0;i<reosurceToDelete.size();i++) { MaterialManager::getSingleton().remove(reosurceToDelete[i]); } } UpdPSSMMaterials(); ti.update(); /// time float dt = ti.dt * 1000.f; LogO(String("::: Time Shadows: ") + toStr(dt) + " ms"); }
//----------------------------------------------------------------------- void ResourceManager::addImpl( ResourcePtr& res ) { OGRE_LOCK_AUTO_MUTEX std::pair<ResourceMap::iterator, bool> result; if(ResourceGroupManager::getSingleton().isResourceGroupInGlobalPool(res->getGroup())) { result = mResources.insert( ResourceMap::value_type( res->getName(), res ) ); } else { ResourceWithGroupMap::iterator itGroup = mResourcesWithGroup.find(res->getGroup()); // we will create the group if it doesn't exists in our list if( itGroup == mResourcesWithGroup.end()) { ResourceMap dummy; mResourcesWithGroup.insert( ResourceWithGroupMap::value_type( res->getGroup(), dummy ) ); itGroup = mResourcesWithGroup.find(res->getGroup()); } result = itGroup->second.insert( ResourceMap::value_type( res->getName(), res ) ); } if (!result.second) { // Attempt to resolve the collision if(ResourceGroupManager::getSingleton().getLoadingListener()) { if(ResourceGroupManager::getSingleton().getLoadingListener()->resourceCollision(res.get(), this)) { // Try to do the addition again, no seconds attempts to resolve collisions are allowed std::pair<ResourceMap::iterator, bool> insertResult; if(ResourceGroupManager::getSingleton().isResourceGroupInGlobalPool(res->getGroup())) { insertResult = mResources.insert( ResourceMap::value_type( res->getName(), res ) ); } else { ResourceWithGroupMap::iterator itGroup = mResourcesWithGroup.find(res->getGroup()); insertResult = itGroup->second.insert( ResourceMap::value_type( res->getName(), res ) ); } if (!insertResult.second) { OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Resource with the name " + res->getName() + " already exists.", "ResourceManager::add"); } std::pair<ResourceHandleMap::iterator, bool> resultHandle = mResourcesByHandle.insert( ResourceHandleMap::value_type( res->getHandle(), res ) ); if (!resultHandle.second) { OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Resource with the handle " + StringConverter::toString((long) (res->getHandle())) + " already exists.", "ResourceManager::add"); } } } } else { // Insert the handle std::pair<ResourceHandleMap::iterator, bool> resultHandle = mResourcesByHandle.insert( ResourceHandleMap::value_type( res->getHandle(), res ) ); if (!resultHandle.second) { OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Resource with the handle " + StringConverter::toString((long) (res->getHandle())) + " already exists.", "ResourceManager::add"); } } }
void LoadingBar::resourceLoadStarted(const ResourcePtr& resource) { mLoadingCommentElement->setCaption(resource->getName()); mWindow->update(); }