Exemplo n.º 1
0
	void UiManager::resizeTexture(const QSize &aSize, const Ogre::MaterialPtr &aMaterial, const Ogre::TexturePtr &aTexture)
	{
		assert(!aMaterial.isNull());
		assert(!aTexture.isNull());
		
		// get the smallest power of two dimension that is at least as large as the new UI size
		Ogre::uint newTexWidth = nextHigherPowerOfTwo(aSize.width());
		Ogre::uint newTexHeight = nextHigherPowerOfTwo(aSize.height());
	
		if (!aTexture.isNull())
		{
			std::string txtrName = aTexture->getName();
			
			// remove the old texture
			aTexture->unload();
			aMaterial->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
			Ogre::TextureManager::getSingleton().remove(aTexture->getHandle());
	
			Ogre::TexturePtr newTxtr = Ogre::TextureManager::getSingleton().createManual(
					txtrName, "General", Ogre::TEX_TYPE_2D, newTexWidth, newTexHeight, 0, Ogre::PF_A8R8G8B8,
					Ogre::TU_DYNAMIC_WRITE_ONLY);
	
			// add the new texture
			Ogre::TextureUnitState* txtrUstate = aMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(txtrName);
	
			// adjust it to stay aligned and scaled to the window
			Ogre::Real txtrUScale = (Ogre::Real)newTexWidth / aSize.width();
			Ogre::Real txtrVScale = (Ogre::Real)newTexHeight / aSize.height();
			txtrUstate->setTextureScale(txtrUScale, txtrVScale);
			txtrUstate->setTextureScroll((1 / txtrUScale) / 2 - 0.5, (1 / txtrVScale) / 2 - 0.5);
		}
	}
Exemplo n.º 2
0
Icon* IconManager::getIcon(int, EmberEntity* entity)
{

	std::string key = "entity_" + entity->getId();
	if (mIconStore.hasIcon(key)) {
		return mIconStore.getIcon(key);
	} else {
		IconActionCreator actionCreator(*entity);
		std::unique_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(*entity, actionCreator, &EmberOgre::getSingleton().getWorld()->getView()));
		std::string modelName;
		if (modelMapping.get()) {
			modelMapping->initialize();
			modelName = actionCreator.getModelName();
		}
		//if there's no model defined for this use the placeholder model
		if (modelName == "") {
			modelName = "placeholder";
		}
		Ogre::ResourcePtr modelDefPtr = Model::ModelDefinitionManager::getSingleton().getByName(modelName);
		if (!modelDefPtr.isNull()) {
			Model::ModelDefinition* modelDef = static_cast<Model::ModelDefinition*> (modelDefPtr.get());
			const std::string& iconPath(modelDef->getIconPath());
			if (iconPath != "") {

				Ogre::TexturePtr texPtr;
				try {
					if (Ogre::TextureManager::getSingleton().resourceExists(iconPath)) {
						texPtr = static_cast<Ogre::TexturePtr> (Ogre::TextureManager::getSingleton().getByName(iconPath));
						//try to load it to make sure that's it a working image
						texPtr->load();
					}
					if (texPtr.isNull()) {
						texPtr = Ogre::TextureManager::getSingleton().load(iconPath, "Gui");
					}
				} catch (...) {
					S_LOG_WARNING("Error when trying to load the icon " << iconPath <<". The icon will be rendered dynamically.");
					texPtr.setNull();
				}
				if (!texPtr.isNull()) {
					Icon* icon = mIconStore.createIcon(key, texPtr);
					return icon;
				}
			}
		}
		Icon* icon = mIconStore.createIcon(key);
		if (icon) {
			//update the model preview window
			// 				Model::Model* model = Model::Model::createModel(mIconRenderer.getRenderContext()->getSceneManager(), modelName);
			render(*icon, modelName);
			// 				mIconRenderer.getRenderContext()->getSceneManager()->destroyMovableObject(model);
		}
		return icon;
	}

	return 0;
}
Exemplo n.º 3
0
bool PersonShape::createMaterial( const std::string& image_name,
                                  const std::string& resource_group)
{
  if (image_name == "default")
  {
    material_ = Ogre::MaterialManager::getSingleton().create( "default",
                                                              Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
    material_->setCullingMode(Ogre::CULL_NONE);
    return true;
  }
  material_ = Ogre::MaterialManager::getSingleton().load( image_name, resource_group );
  material_->setCullingMode(Ogre::CULL_NONE);
  if( material_.isNull() )
    return false;

  Ogre::Pass* first_pass = material_->getTechnique(0)->getPass(0);

  if( first_pass->getNumTextureUnitStates() == 0 )
  {
    Ogre::TextureUnitState* texture_unit = first_pass->createTextureUnitState();
    Ogre::TexturePtr texture
        = Ogre::TextureManager::getSingleton().load( image_name, resource_group );
    if( texture.isNull() )
      return false;
#if (OGRE_VERSION_MINOR >=8)
    texture_unit->setTexture( texture ); // or setTextureName if Ogre 1.8?
#else
    texture_unit->setTextureName( texture->getName());
#endif
  }
  return true;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
Ogre::TexturePtr Simple::updateShadowTexture(Ogre::MaterialPtr material, const TerrainPageShadow* terrainPageShadow)
{
	//we need an unique name for our alpha texture
	std::stringstream shadowTextureNameSS;
	shadowTextureNameSS << material->getName() << "_shadow";
	const Ogre::String shadowTextureName(shadowTextureNameSS.str());

	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.getAlphaTextureSize(), mPage.getAlphaTextureSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY);
	}

	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;
}
Exemplo n.º 6
0
//!
//! Processes the node's input data to generate the node's output image.
//!
void BadPrintingNode::processOutputImage ()
{
    // obtain input image
    Ogre::TexturePtr inputTexture = getTextureValue("Input Map");
    if (inputTexture.isNull()) {
        //disable compositor (now that the input texture name was set)
        if (m_compositor)
            m_compositor->setEnabled(false);

        //render and set output
        m_renderTexture->getBuffer()->getRenderTarget()->update();
        setValue("Image", m_defaultTexture);
        Log::warning("No input image connected.", "BadPrintingNode::processOutputImage");
    }
    else if (!m_renderTexture.isNull()) {
        //resize render texture
        size_t width = inputTexture->getWidth();
        size_t height = inputTexture->getHeight();
        resizeRenderTexture(width, height);
        
        //enable compositor (now that the input texture name was set)
        if (m_compositor)
            m_compositor->setEnabled(true);

        m_renderTexture->getBuffer()->getRenderTarget()->update();
        setValue("Image", m_renderTexture);
    }
}
Exemplo n.º 7
0
void video_display(VideoState *is)
{
  VideoPicture *vp;

  vp = &is->pictq[is->pictq_rindex];

  if (is->video_st->codec->width != 0 && is->video_st->codec->height != 0)
  {
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton ().getByName("VideoTexture");
    if (texture.isNull () || texture->getWidth() != is->video_st->codec->width || texture->getHeight() != is->video_st->codec->height)
    {
      Ogre::TextureManager::getSingleton ().remove ("VideoTexture");
      texture = Ogre::TextureManager::getSingleton().createManual(
                  "VideoTexture",
                  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                  Ogre::TEX_TYPE_2D,
                  is->video_st->codec->width, is->video_st->codec->height,
                  0,
                  Ogre::PF_BYTE_RGBA,
                  Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
    }
    Ogre::PixelBox pb(is->video_st->codec->width, is->video_st->codec->height, 1, Ogre::PF_BYTE_RGBA, vp->data);
    Ogre::HardwarePixelBufferSharedPtr buffer = texture->getBuffer();
    buffer->blitFromMemory(pb);
  }

  free(vp->data);
}
Exemplo n.º 8
0
void EC_ChatBubble::Refresh()
{
    if (renderer_.expired() || !billboardSet_ || !billboard_)
        return;

    // If no messages in the log, hide the chat bubble.
    if (messages_.isEmpty())
    {
        billboardSet_->setVisible(false);
        return;
    }
    else
        billboardSet_->setVisible(true);

    // Get image buffer and texture
    QImage buffer = GetChatBubblePixmap().toImage();
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
    if (buffer.isNull() || texture.isNull())
        return;

    // Check texture size
    if ((int)texture->getWidth() != buffer.width() || (int)texture->getHeight() != buffer.height())
    {
        texture->freeInternalResources();
        texture->setWidth(buffer.width());
        texture->setHeight(buffer.height());
        texture->createInternalResources();
    }

    // Update texture buffer
    Ogre::Box update_box(0,0, buffer.width(), buffer.height());
    Ogre::PixelBox pixel_box(update_box, Ogre::PF_A8R8G8B8, (void*)buffer.bits());
    if (!texture->getBuffer().isNull())
        texture->getBuffer()->blitFromMemory(pixel_box, update_box);
}
void BaseApp::onCursorChange(const std::string &name)
{
	if (!mCursorManager->cursorChanged(name))
		return;  // the cursor manager doesn't want any more info about this cursor
	//  See if we can get the information we need out of the cursor resource
	ResourceImageSetPointerFix* imgSetPtr = dynamic_cast<ResourceImageSetPointerFix*>(MyGUI::PointerManager::getInstance().getByName(name));
	if (imgSetPtr != NULL)
	{
		MyGUI::ResourceImageSet* imgSet = imgSetPtr->getImageSet();
		std::string tex_name = imgSet->getIndexInfo(0,0).texture;
		Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().getByName(tex_name);

		//  everything looks good, send it to the cursor manager
		if (!tex.isNull())
		{
			Uint8 size_x = imgSetPtr->getSize().width;
			Uint8 size_y = imgSetPtr->getSize().height;
			Uint8 left = imgSetPtr->getTexturePosition().left;
			Uint8 top = imgSetPtr->getTexturePosition().top;
			Uint8 hotspot_x = imgSetPtr->getHotSpot().left;
			Uint8 hotspot_y = imgSetPtr->getHotSpot().top;

			mCursorManager->receiveCursorInfo(name, tex, left, top, size_x, size_y, hotspot_x, hotspot_y);
		}
	}
}
Exemplo n.º 10
0
TexturePair AssetsManager::showTexture(const std::string textureName)
{
	// 	if (!mOgreCEGUITexture) {
	// 		S_LOG_WARNING("You must first create a valid OgreCEGUITexture instance.");
	// 		return;
	// 	}
	if (Ogre::TextureManager::getSingleton().resourceExists(textureName)) {
		Ogre::TexturePtr texturePtr = static_cast<Ogre::TexturePtr>(Ogre::TextureManager::getSingleton().getByName(textureName));
		if (!texturePtr.isNull()) {
			if (!texturePtr->isLoaded()) {
				try {
					texturePtr->load();
				} catch (...) {
					S_LOG_WARNING("Error when loading " << textureName << ". This texture will not be shown.");
					return TexturePair();
				}
			}
			std::string textureName(texturePtr->getName());
			std::string imageSetName(textureName + "_AssetsManager");

			return createTextureImage(texturePtr, imageSetName);
			// 			mOgreCEGUITexture->setOgreTexture(texturePtr);
		}
	}
	return TexturePair();

}
Exemplo n.º 11
0
    void UpdateLegacyMaterials(const std::string& texture_name)
    {
        Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
        Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
        
        Ogre::TexturePtr tex = tm.getByName(texture_name);
        bool has_alpha = false;
        if (!tex.isNull())
            if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
                has_alpha = true;

        for (uint i = 0; i < MAX_MATERIAL_VARIATIONS; ++i)
        {
            std::string material_name = texture_name + MaterialSuffix[i];
            Ogre::MaterialPtr material = mm.getByName(material_name);
            
            if (!material.get())
                continue;
            
            Ogre::MaterialPtr base_material;
            if (!has_alpha)
                base_material = mm.getByName(BaseMaterials[i]);
            else
                base_material = mm.getByName(AlphaBaseMaterials[i]);
            if (!base_material.get())
            {
                OgreRenderingModule::LogError("Could not find " + MaterialSuffix[i] + " base material for " + texture_name);
                continue;
            }
            
            base_material->copyDetailsTo(material);
            SetTextureUnitOnMaterial(material, texture_name, 0);
        }
    }
Exemplo n.º 12
0
void SimpleRenderContext::createImage(const std::string& prefix)
{

    if (mWidth == 0 || mHeight == 0) {
        throw Exception("Height and width of the image can't be 0.");
    }

    Ogre::Real aspectRatio = static_cast<float>(mWidth) / static_cast<float>(mHeight);

    S_LOG_VERBOSE("Setting aspect ratio of camera to " << aspectRatio);
    mCamera->setAspectRatio(aspectRatio);

    //the width and height needs to be multipes of 2
    mWidth = Ogre::Bitwise::firstPO2From(mWidth);
    mHeight = Ogre::Bitwise::firstPO2From(mHeight);

    //first, create a RenderTexture to which the Ogre renderer should render the image
    S_LOG_VERBOSE("Creating new rendertexture " << (prefix + "_SimpleRenderContextRenderTexture") << " with w:" << mWidth << " h:" << mHeight);
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(prefix + "_SimpleRenderContextRenderTexture", "Gui", Ogre::TEX_TYPE_2D, mWidth, mHeight, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET, &mResourceLoader);
    if (texture.isNull()) {
        S_LOG_WARNING("Could not create a texture.");
        return;
    }

    setTexture(texture);
}
Exemplo n.º 13
0
	void UiManager::setViewSize(const Ogre::TexturePtr &aTexture)
	{
		// make sure that the view size matches the texture size
		if (!aTexture.isNull() && !isViewSizeMatching(aTexture))
		{
			mWidgetView->setGeometry(QRect(0, 0, aTexture->getWidth(), aTexture->getHeight()));
		}
	}
Exemplo n.º 14
0
    void CreateLegacyMaterials(const std::string& texture_name, bool update)
    {
        Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
        Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
        
        Ogre::TexturePtr tex = tm.getByName(texture_name);
        bool has_alpha = false;
        if (!tex.isNull())
        {
            if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
                has_alpha = true;
        }
        
        // Early out: if texture does not yet exist and materials have already been created once
        if (((tex.isNull()) || (!update)) && (!mm.getByName(texture_name).isNull()))
            return;
        
        for (uint i = 0; i < MAX_MATERIAL_VARIATIONS; ++i)
        {
            const std::string& base_material_name = BaseMaterials[i];
            const std::string& alpha_base_material_name = AlphaBaseMaterials[i];
            
            std::string material_name = texture_name + MaterialSuffix[i];
            Ogre::MaterialPtr material = mm.getByName(material_name);

            if (!material.get())
            {
                material = mm.create(material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
                assert(material.get());
            }
            
            Ogre::MaterialPtr base_material;
            if (!has_alpha)
                base_material = mm.getByName(base_material_name);
            else
                base_material = mm.getByName(alpha_base_material_name);
            if (!base_material.get())
            {
                OgreRenderingModule::LogError("Could not find " + MaterialSuffix[i] + " base material for " + texture_name);
                return;
            }

            base_material->copyDetailsTo(material);
            SetTextureUnitOnMaterial(material, texture_name, 0);
        }
    }
Exemplo n.º 15
0
    //-----------------------------------------------------------------------
    //                          l o a d F r o m F i l e
    //-----------------------------------------------------------------------
    void TGTexture::loadFromFile(const TGString& filename, const TGString& resourceGroup)
    {
        using namespace Ogre;

        // unload old ogre texture
        freeOgreTexture();

        // create / load a new ogre texture from the specified image
        try
        {
            TextureManager& textureManager = TextureManager::getSingleton();

            // see if texture already exists
            Ogre::TexturePtr ogreTexture = (Ogre::TexturePtr)textureManager.getByName(filename.c_str());

            if (!ogreTexture.isNull())
            {
                // texture already exists, so create a 'linked' texture (ensures texture is not destroyed twice)
                m_ogre_texture = ogreTexture;
                m_isLinked = true;
            }
            // texture does not already exist, so load it in
            else
            {
                String orpGroup;
                if (resourceGroup.empty())
                {
                    const String& defGrp = "";
                    orpGroup = defGrp.empty() ? Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str() : defGrp;
                }
                else
                {
                    orpGroup = resourceGroup;
                }

                m_ogre_texture = TextureManager::getSingleton().load(filename.c_str(), orpGroup.c_str(), TEX_TYPE_2D, 0, 1.0f);
                m_isLinked = false;
            }

        }
        catch(Ogre::Exception e)
        {
            throw Ogre::Exception(0,"Failed to create Texture object from file '" + filename + "'. Additional Information:\n" + e.getFullDescription().c_str(),"TGTexture");
        }

        // if we got a pointer cache some details
        if (!m_ogre_texture.isNull())
        {
            m_width		= m_ogre_texture->getWidth();
            m_height	= m_ogre_texture->getHeight();
        }
        // no texture from image so throw.
        else
        {
            throw Ogre::Exception(0,"Failed to create Texture object from file '" + filename + "'.  Ogre returned a NULL pointer.","TGTexture");
        }

    }
Exemplo n.º 16
0
 MyGUI::IntSize ImageButton::getRequestedSize()
 {
     Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(mImageNormal);
     if (texture.isNull())
     {
         std::cerr << "ImageButton: can't find " << mImageNormal << std::endl;
         return MyGUI::IntSize(0,0);
     }
     return MyGUI::IntSize (texture->getWidth(), texture->getHeight());
 }
Exemplo n.º 17
0
void EC_WidgetCanvas::Update()
{
    if (framework->IsHeadless())
        return;

    if (!widget_.data() || texture_name_.empty())
        return;
    if (widget_->width() <= 0 || widget_->height() <= 0)
        return;

    try
    {
        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
        if (texture.isNull())
            return;

        if (buffer_.size() != widget_->size())
            buffer_ = QImage(widget_->size(), QImage::Format_ARGB32_Premultiplied);
        if (buffer_.width() <= 0 || buffer_.height() <= 0)
            return;

        QPainter painter(&buffer_);
        widget_->render(&painter);

        // Set texture to material
        if (update_internals_ && !material_name_.empty())
        {
            Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(material_name_);
            if (material.isNull())
                return;
            // Just for good measure, this is done once in the ctor already if everything went well.
            OgreRenderer::SetTextureUnitOnMaterial(material, texture_name_);
            UpdateSubmeshes();
            update_internals_ = false;
        }

        if ((int)texture->getWidth() != buffer_.width() || (int)texture->getHeight() != buffer_.height())
        {
            texture->freeInternalResources();
            texture->setWidth(buffer_.width());
            texture->setHeight(buffer_.height());
            texture->createInternalResources();
        }

        Blit(buffer_, texture);
    }
    catch (Ogre::Exception &e) // inherits std::exception
    {
        LogError("Exception occurred while blitting texture data from memory: " + std::string(e.what()));
    }
    catch (...)
    {
        LogError("Unknown exception occurred while blitting texture data from memory.");
    }
}
Exemplo n.º 18
0
void EC_WidgetCanvas::Update(QImage buffer)
{
    if (framework->IsHeadless())
        return;
    if (buffer.width() <= 0 || buffer.height() <= 0)
        return;

    if (buffer.format() != QImage::Format_ARGB32 && buffer.format() != QImage::Format_ARGB32_Premultiplied)
    {
        LogWarning("EC_WidgetCanvas::Update(QImage buffer): Input format needs to be Format_ARGB32 or Format_ARGB32_Premultiplied, preforming auto conversion!");
        buffer = buffer.convertToFormat(QImage::Format_ARGB32);
        if (buffer.isNull())
        {
            LogError("-- Auto conversion failed, not updating!");
            return;
        }
    }

    try
    {
        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texture_name_);
        if (texture.isNull())
            return;

        // Set texture to material if need be
        if (update_internals_ && !material_name_.empty())
        {
            Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(material_name_);
            if (material.isNull())
                return;
            // Just for good measure, this is done once in the ctor already if everything went well.
            OgreRenderer::SetTextureUnitOnMaterial(material, texture_name_);
            UpdateSubmeshes();
            update_internals_ = false;
        }

        if ((int)texture->getWidth() != buffer.width() || (int)texture->getHeight() != buffer.height())
        {
            texture->freeInternalResources();
            texture->setWidth(buffer.width());
            texture->setHeight(buffer.height());
            texture->createInternalResources();
        }

        Blit(buffer, texture);
    }
    catch (Ogre::Exception &e) // inherits std::exception
    {
        LogError("Exception occurred while blitting texture data from memory: " + std::string(e.what()));
    }
    catch (...)
    {
        LogError("Unknown exception occurred while blitting texture data from memory.");
    }
}
Exemplo n.º 19
0
void TreeLoader2D::setColorMap(Ogre::TexturePtr map, MapChannel channel)
{
  if (colorMap) {
    colorMap->unload();
    colorMap = NULL;
  }
  if (map.isNull() == false) {
    colorMap = ColorMap::load(map, channel);
    colorMap->setFilter(colorMapFilter);
  }
}
Exemplo n.º 20
0
void EC_RttTarget::PrepareRtt()
{
    if (!ViewEnabled())
        return;

    //\todo XXX reconfig via AttributeUpdated when these change
    int x = width.Get();
    int y = height.Get();

    // Get the camera ec
    EC_Camera *ec_camera = ParentEntity()->GetComponent<EC_Camera>().get();
    if (!ec_camera)
    {
        LogInfo("No camera for rtt.");
        return; //XXX note: doesn't reschedule, so won't start working if cam added afterwards
    }

    ec_camera->GetCamera()->setAspectRatio(Ogre::Real(x) / Ogre::Real(y));

    Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().getByName(textureName.Get().toStdString());
    if (tex.isNull())
    {
        tex = Ogre::TextureManager::getSingleton().createManual(textureName.Get().toStdString(),
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, x, y, 0,
            Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
    }

    Ogre::RenderTexture *render_texture = tex->getBuffer()->getRenderTarget();
    if (render_texture)
    {
        render_texture->removeAllViewports();
        Ogre::Viewport *vp = 0;
        vp = render_texture->addViewport(ec_camera->GetCamera());
        // Exclude ui overlays
        vp->setOverlaysEnabled(false);
        // Exclude highlight mesh from rendering
        vp->setVisibilityMask(0x2);

        render_texture->update(false);
        tex->getBuffer()->getRenderTarget()->setAutoUpdated(false); 
    }
    else
        LogError("render target texture getting failed.");

    //create material to show the texture
    material_name_ = textureName.Get().toStdString() + "_mat"; //renderer_.lock()->GetUniqueObjectName("EC_BillboardWidget_mat");
    OgreRenderer::CloneMaterial("HoveringText", material_name_); //would LitTextured be the right thing? XXX \todo
    Ogre::MaterialManager &material_manager = Ogre::MaterialManager::getSingleton();
    Ogre::MaterialPtr material = material_manager.getByName(material_name_);
    OgreRenderer::SetTextureUnitOnMaterial(material, textureName.Get().toStdString());
}
Exemplo n.º 21
0
 Ogre::MaterialPtr GetOrCreateLegacyMaterial(const std::string& texture_name, uint variation)
 {
     if (variation >= MAX_MATERIAL_VARIATIONS)
     {
         OgreRenderingModule::LogWarning("Requested suffix for non-existing material variation " + ToString<uint>(variation));
         variation = 0;
     }
     const std::string& suffix = MaterialSuffix[variation];
     
     Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
     Ogre::MaterialManager &mm = Ogre::MaterialManager::getSingleton();
     
     std::string material_name = texture_name + suffix;
     Ogre::MaterialPtr material = mm.getByName(material_name);
     
     if (!material.get())
     {
         material = mm.create(material_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
         assert(material.get());
     }
     else
         return material;
     
     Ogre::TexturePtr tex = tm.getByName(texture_name);
     bool has_alpha = false;
     if (!tex.isNull())
     {
         // As far as the legacy materials are concerned, DXT1 is not alpha
         if (tex->getFormat() == Ogre::PF_DXT1)
             has_alpha = false;
         else if (Ogre::PixelUtil::hasAlpha(tex->getFormat()))
             has_alpha = true;
     }
     
     Ogre::MaterialPtr base_material;
     if (!has_alpha)
         base_material = mm.getByName(BaseMaterials[variation]);
     else
         base_material = mm.getByName(AlphaBaseMaterials[variation]);
     if (!base_material.get())
     {
         OgreRenderingModule::LogError("Could not find " + MaterialSuffix[variation] + " base material for " + texture_name);
         return Ogre::MaterialPtr();
     }
     
     base_material->copyDetailsTo(material);
     SetTextureUnitOnMaterial(material, texture_name, 0);
     
     return material;
 }
Exemplo n.º 22
0
bool RocketInterface::LoadTexture(Rocket::Core::TextureHandle& textureHandle,
                                  Rocket::Core::Vector2i& textureDimensions,
                                  const Rocket::Core::String& source)
{
    Ogre::TextureManager* tm = Ogre::TextureManager::getSingletonPtr();
    Ogre::TexturePtr texture = tm->getByName(Ogre::String(source.CString()));

    if (texture.isNull())
    {
        texture = tm->load(
            Ogre::String(source.CString()), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
            Ogre::TEX_TYPE_2D, 0, 1.0f, false, Ogre::PF_UNKNOWN, true);
    }

    if (texture.isNull())
        return false;

    textureDimensions.x = texture->getWidth();
    textureDimensions.y = texture->getHeight();

    textureHandle = reinterpret_cast<Rocket::Core::TextureHandle>(new RocketOgreTexture(texture));
    return true;
}
Exemplo n.º 23
0
int GUIHelper::getTextureHeight(const Ogre::String &materialName)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName);
	if(mat.isNull() || /*!mat->getTechnique(0) ||
			!mat->getTechnique(0)->getPass(0) ||*/
			!mat->getTechnique(0)->getPass(0)->getTextureUnitState(0))
		return -1;

	Ogre::TexturePtr text = Ogre::TextureManager::getSingleton().getByName(
			mat->getTechnique(0)->getPass(0)->getTextureUnitState(
					0)->getTextureName());
	if(text.isNull()) return -1;
	return text->getHeight();
}
Exemplo n.º 24
0
/****************************************************************************
**
** Copyright (C) 2016 - 2017
**
** This file is part of the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

#include "constants.h"
#include "texturelayer.h"
#include "OgreHlmsPbs.h"
#include "OgreHlmsManager.h"
#include "OgreLogManager.h"
#include "OgreStringConverter.h"
#include <fstream>
#include <ctime>

//****************************************************************************/
TextureLayer::TextureLayer(void) :
    mTextureOnWhichIsPaintedWidth(0),
    mTextureOnWhichIsPaintedHeight(0),
    mTextureOnWhichIsPaintedHasAlpha(false),
    mNumMipMaps(0),
    mTextureTypeDefined(false),
    mMaxSequence(0)
{
    mTextureType = Ogre::PBSM_DIFFUSE;
    mDatablockId = "";
    mTextureFileName = "";
}

//****************************************************************************/
TextureLayer::~TextureLayer(void)
{
}

//****************************************************************************/
void TextureLayer::setDatablockIdAndTexture (const Ogre::IdString& datablockId,
                                             Ogre::PbsTextureTypes textureType,
                                             const Ogre::String& textureFileName)
{
    mDatablockId = datablockId;
    mTextureType = textureType;
    mTextureFileName = textureFileName;
    mTextureTypeDefined = true;

    // Load the texture as image; assume it can be loaded, because it was already loaded as part of the material
    setFirstTextureGeneration();

    // Create the pixelbox of the original texture; this MUST be a separate image
    mOriginalTexture.load(textureFileName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    mPixelboxOriginalTexture = mOriginalTexture.getPixelBox(0, 0);

    // Debug texture
    //Ogre::LogManager::getSingleton().logMessage("Debug texture: " + textureFileName);
    //Ogre::LogManager::getSingleton().logMessage("Depth: " + Ogre::StringConverter::toString(mOriginalTexture.getDepth()));
    //Ogre::LogManager::getSingleton().logMessage("Pixel format: " + Ogre::StringConverter::toString(mOriginalTexture.getFormat()));
    //Ogre::LogManager::getSingleton().logMessage("Alpha: " + Ogre::StringConverter::toString(mOriginalTexture.getHasAlpha()));
    //Ogre::LogManager::getSingleton().logMessage("Height: " + Ogre::StringConverter::toString(mOriginalTexture.getHeight()));
    //Ogre::LogManager::getSingleton().logMessage("Number of faces: " + Ogre::StringConverter::toString(mOriginalTexture.getNumFaces()));
    //Ogre::LogManager::getSingleton().logMessage("Number of mipmaps: " + Ogre::StringConverter::toString(mOriginalTexture.getNumMipmaps()));
    //Ogre::LogManager::getSingleton().logMessage("Width: " + Ogre::StringConverter::toString(mOriginalTexture.getWidth()));
}

//****************************************************************************/
void TextureLayer::blitTexture (void)
{
    /* Always get the actual pointers, because they may change. That is the reason why the datablock pointer cannot be cached.
     * The same seems to apply to the texture pointer.
     */
    Ogre::HlmsDatablock* datablock;
    Ogre::HlmsPbsDatablock* datablockPbs;
    Ogre::TexturePtr texture;
    Ogre::HlmsManager* hlmsManager = Ogre::Root::getSingletonPtr()->getHlmsManager();
    Ogre::HlmsPbs* hlmsPbs = static_cast<Ogre::HlmsPbs*>(hlmsManager->getHlms(Ogre::HLMS_PBS));
    datablock = hlmsPbs->getDatablock(mDatablockId);
    if (!datablock)
        return;

    datablockPbs = static_cast<Ogre::HlmsPbsDatablock*>(datablock);
    try
    {
        // Get texture on GPU
        if (!datablockPbs->getTexture(mTextureType).isNull())
        {
            texture = datablockPbs->getTexture(mTextureType); // TextureType MUST exist, otherwise the application crashes
            mNumMipMaps = texture->getNumMipmaps();
        }
    }
    catch (Ogre::Exception e){}

    if (texture.isNull())
        return;

    Ogre::uint8 maxMipMaps = mNumMipMaps + 1; // Increase with one, because there is always one image to blit
    maxMipMaps = maxMipMaps > PAINT_MAX_MIP_MAPS ? PAINT_MAX_MIP_MAPS : maxMipMaps; // Just paint a few mipmaps (not all)
    Ogre::Image textureOnWhichIsPaintedScaled = mTextureOnWhichIsPainted; // Temporary image must be used, otherwise painting doesn't work
    size_t w = mTextureOnWhichIsPaintedWidth;
    size_t h = mTextureOnWhichIsPaintedHeight;
    Ogre::v1::HardwarePixelBuffer* buffer;
    for (Ogre::uint8 i = 0; i < maxMipMaps; ++i)
    {
        buffer = texture->getBuffer(0, i).getPointer();
        buffer->blitFromMemory(textureOnWhichIsPaintedScaled.getPixelBox(0, 0), Ogre::Box(0, 0, 0, w, h, 1));
        w*=0.5f; // Mipmaps always are half of the previous one
        h*=0.5f;
        if (w < 1.0f || h < 1.0f)
            break; // Stop when the mipmaps are too small

        textureOnWhichIsPaintedScaled.resize(w, h);

    }
    textureOnWhichIsPaintedScaled.freeMemory();
}
Exemplo n.º 25
0
 ITexture* getTexture(const std::string& _name)
 {
     MapTexture::const_iterator item = mTextures.find(_name);
     if (item == mTextures.end())
     {
         Ogre::TexturePtr texture = (Ogre::TexturePtr)Ogre::TextureManager::getSingleton().getByName(_name);
         if (!texture.isNull())
         {
             ITexture* result = createTexture(_name);
             static_cast<OgreTexture*>(result)->setOgreTexture(texture);
             return result;
         }
         return nullptr;
     }
     return item->second;
 }
Exemplo n.º 26
0
 Ogre::TexturePtr GetLocalTexture(const std::string& name)
 {
     Ogre::TextureManager& manager = Ogre::TextureManager::getSingleton();
     
     Ogre::TexturePtr tex = manager.getByName(name);
     if (tex.isNull())
     {
         try
         {
             manager.load(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
             tex = manager.getByName(name);
         }
         catch(...) {}
     }
     
     return tex;
 }
Exemplo n.º 27
0
	void UiManager::renderIntoTexture(const Ogre::TexturePtr &aTexture)
	{
		assert(!aTexture.isNull());
		assert(isViewSizeMatching(aTexture));
		
		Ogre::HardwarePixelBufferSharedPtr hwBuffer = aTexture->getBuffer(0, 0);
		hwBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
		
		const Ogre::PixelBox &pb = hwBuffer->getCurrentLock();
		
		// render into texture buffer
		QImage textureImg((uchar *)pb.data, pb.getWidth(), pb.getHeight(), QImage::Format_ARGB32);
		textureImg.fill(0);
		
		QPainter painter(&textureImg);
		mWidgetView->render(&painter, QRect(QPoint(0, 0), mWidgetView->size()), QRect(QPoint(0, 0), mWidgetView->size()));
		
		hwBuffer->unlock();
	}
Exemplo n.º 28
0
EC_WidgetCanvas::EC_WidgetCanvas(Scene *scene) :
    IComponent(scene),
    widget_(0),
    update_internals_(false),
    mesh_hooked_(false),
    refresh_timer_(0),
    update_interval_msec_(0),
    material_name_(""),
    texture_name_("")
{
    if (framework->IsHeadless())
        return;
	
	if (framework->Renderer())
    {
        // Create texture
        texture_name_ = framework->Renderer()->GetUniqueObjectName("EC_3DCanvas_tex");
        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual(
            texture_name_, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
            Ogre::TEX_TYPE_2D, 1, 1, 0, Ogre::PF_A8R8G8B8, 
            Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
        if (texture.isNull())
        {
            LogError("EC_WidgetCanvas: Could not create texture for usage!");
            return;
        }

        // Create material: Make sure we have one tech with one pass with one texture unit.
        // Don't use our lit textured templates here as emissive will not work there as it has vertex etc programs in it.
        material_name_ = framework->Renderer()->GetUniqueObjectName("EC_3DCanvas_mat");
        Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(material_name_, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
        if (material->getNumTechniques() == 0)
            material->createTechnique();
        if (material->getTechnique(0) && 
            material->getTechnique(0)->getNumPasses() == 0)
            material->getTechnique(0)->createPass();
        if (material->getTechnique(0)->getPass(0) && 
            material->getTechnique(0)->getPass(0)->getNumTextureUnitStates() == 0)
            material->getTechnique(0)->getPass(0)->createTextureUnitState(texture_name_);        
    }

    connect(this, SIGNAL(ParentEntitySet()), SLOT(ParentEntitySet()), Qt::UniqueConnection);
}
Exemplo n.º 29
0
bool RocketInterface::GenerateTexture(Rocket::Core::TextureHandle& textureHandle,
                                      const Rocket::Core::byte* source,
                                      const Rocket::Core::Vector2i& dimensions)
{
    static int id = 1;

    Ogre::DataStreamPtr stream(OGRE_NEW Ogre::MemoryDataStream(
        (void*)source, dimensions.x * dimensions.y * sizeof(unsigned int)));
    Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().loadRawData(
        Rocket::Core::String(16, "%d", id++).CString(),
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, stream,
        (Ogre::ushort)dimensions.x, (Ogre::ushort)dimensions.y, Ogre::PF_A8B8G8R8,
        Ogre::TEX_TYPE_2D, 0);

    if (texture.isNull())
        return false;

    textureHandle = reinterpret_cast<Rocket::Core::TextureHandle>(new RocketOgreTexture(texture));
    return true;
}
Exemplo n.º 30
0
	ITexture* OgreRenderManager::getTexture(const std::string& _name)
	{
		MapTexture::const_iterator item = mTextures.find(_name);
		if (item == mTextures.end())
		{
#if (OGRE_VERSION < MYGUI_DEFINE_VERSION(1, 9, 0))
			Ogre::TexturePtr texture = (Ogre::TexturePtr)Ogre::TextureManager::getSingleton().getByName(_name);
#else
			Ogre::TexturePtr texture = (Ogre::TexturePtr)Ogre::TextureManager::getSingleton().getByName(_name).staticCast<Ogre::Texture>();
#endif
			if (!texture.isNull())
			{
				ITexture* result = createTexture(_name);
				static_cast<OgreTexture*>(result)->setOgreTexture(texture);
				return result;
			}
			return nullptr;
		}
		return item->second;
	}