Ejemplo n.º 1
0
bool ShadowUpdateTask::executeTaskInMainThread()
{
	if (!mPageGeometries.empty()) {
		auto pageGeometry = mPageGeometries.back();
		mPageGeometries.pop_back();
		auto& page = pageGeometry->getPage();
		if (page.getSurface()) {
			auto shadow = page.getSurface()->getShadow();
			if (shadow) {
				auto& shadowTextureName = shadow->getShadowTextureName();
				if (!shadowTextureName.empty()) {
					Ogre::TexturePtr texture = Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(shadowTextureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
					if (texture) {
						Ogre::Image ogreImage;
						shadow->loadIntoImage(ogreImage);

						texture->loadImage(ogreImage);

						//blit the whole image to the hardware buffer
						Ogre::PixelBox sourceBox(ogreImage.getPixelBox());
						//blit for each mipmap
						for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) {
							Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i));
							hardwareBuffer->blitFromMemory(sourceBox);
						}
					}
				}
			}
		}
	}
	return mPageGeometries.empty();
}
Ejemplo n.º 2
0
Ogre::TexturePtr Simple::updateShadowTexture(Ogre::MaterialPtr material, const TerrainPageShadow* terrainPageShadow, std::set<std::string>& managedTextures) const
{
	auto shadowTextureName = getShadowTextureName(material);

	Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(shadowTextureName));
	if (texture.isNull()) {
		texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(shadowTextureName, "General", Ogre::TEX_TYPE_2D, mPage.getBlendMapSize(), mPage.getBlendMapSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY);
		managedTextures.insert(texture->getName());
	}

	Ogre::Image ogreImage;
	terrainPageShadow->loadIntoImage(ogreImage);

	texture->loadImage(ogreImage);

	//blit the whole image to the hardware buffer
	Ogre::PixelBox sourceBox(ogreImage.getPixelBox());
	//blit for each mipmap
	for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) {
		Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i));
		hardwareBuffer->blitFromMemory(sourceBox);
	}

	return texture;
}
Ejemplo n.º 3
0
void ShadowUpdateTask::executeTaskInBackgroundThread(Tasks::TaskExecutionContext& context)
{
	for (auto& pageGeometry : mPageGeometries) {
		auto& page = pageGeometry->getPage();
		if (page.getSurface()) {
			auto shadow = page.getSurface()->getShadow();
			if (shadow) {
				auto& shadowTextureName = shadow->getShadowTextureName();
				if (!shadowTextureName.empty()) {
					pageGeometry->repopulate(true);
					shadow->setLightDirection(mLightDirection);
					shadow->updateShadow(*pageGeometry.get());
				}
			}
		}
	}
}