void ResourceGroupReloader::UpdateMaterialRenderableVisitor::visit(
	Ogre::Renderable *rend, Ogre::ushort lodIndex, bool isDebug, Ogre::Any *pAny)
{
	const Ogre::MaterialPtr mat = rend->getMaterial();
	if(!mat.isNull())
	{
		std::string newMatName = mat->getName();
		Ogre::MaterialPtr newMat = Ogre::MaterialManager::getSingleton().getByName(newMatName);
		if(newMat.isNull())
		{
			// this can happen if there was error during the reloading of the material.
			// in that case, we keep the ancient one.
			// Ice::Log::Instance().LogMessage(newMatName+" : new material is null!");
			return;
		}

		// unfortunately, the renderable gives access only to a const MaterialPtr.
		// and there is no 'setMaterial' or 'setMaterialName' method on renderables.
		// so I have to try to down cast with known classes...
		{   
			Ogre::SubEntity* lRend = dynamic_cast<Ogre::SubEntity*>(rend);
			if(lRend){lRend->setMaterialName(newMatName);return;} 
		}
		{
			Ogre::SimpleRenderable* lRend = dynamic_cast<Ogre::SimpleRenderable*>(rend);
			if(lRend){lRend->setMaterial(newMatName);return;} 
		}
		{
			Ogre::ShadowRenderable* lRend = dynamic_cast<Ogre::ShadowRenderable*>(rend);
			if(lRend){lRend->setMaterial(newMat);return;} 
		}
		{   
			Ogre::BillboardChain* lRend = dynamic_cast<Ogre::BillboardChain*>(rend);
			if(lRend){lRend->setMaterialName(newMatName);return;} 
		}
		{   
			Ogre::BillboardSet* lRend = dynamic_cast<Ogre::BillboardSet*>(rend);
			if(lRend){lRend->setMaterialName(newMatName);return;} 
		}
		{   
			Ogre::OverlayElement* lRend = dynamic_cast<Ogre::OverlayElement*>(rend);
			if(lRend){lRend->setMaterialName(newMatName);return;} 
		}
	}else{
		// was there for debug...
		// Ice::Log::Instance().LogMessage("material of renderable is null!");
	}
}
Esempio n. 2
0
 void ReplaceTextureOnMaterial(Ogre::MaterialPtr material, const std::string& original_name, const std::string& texture_name)
 {
     if (material.isNull())
         return;
     
     Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton();
     Ogre::TexturePtr tex = tm.getByName(texture_name);
     
     Ogre::Material::TechniqueIterator iter = material->getTechniqueIterator();
     while(iter.hasMoreElements())
     {
         Ogre::Technique *tech = iter.getNext();
         assert(tech);
         Ogre::Technique::PassIterator passIter = tech->getPassIterator();
         while(passIter.hasMoreElements())
         {
             Ogre::Pass *pass = passIter.getNext();
             
             Ogre::Pass::TextureUnitStateIterator texIter = pass->getTextureUnitStateIterator();
             
             while(texIter.hasMoreElements())
             {
                 Ogre::TextureUnitState *texUnit = texIter.getNext();
                 if (texUnit->getTextureName() == original_name)
                 {
                     if (tex.get())
                         texUnit->setTextureName(texture_name);
                     else
                         texUnit->setTextureName("TextureMissing.png");
                 }
             }
         }
     }
 }
Esempio n. 3
0
/**
 * Destroy / unload the memory of a material
 * @param	mat		MaterialName
 */
void GUIHelper::destroyMaterial(const Ogre::String &matName)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(matName);
	if(mat.isNull()) return;

	Ogre::Material::TechniqueIterator tit = mat->getTechniqueIterator();
	while(tit.hasMoreElements()){
		Ogre::Technique *t = tit.peekNext();
		ASSERT(t);
		Ogre::Technique::PassIterator pit = t->getPassIterator();
		while(pit.hasMoreElements()){
			Ogre::Pass *pass = pit.peekNext();
			ASSERT(pass);
			Ogre::Pass::TextureUnitStateIterator tuit =
					pass->getTextureUnitStateIterator();

			while(tuit.hasMoreElements()){
				Ogre::TextureUnitState *tus = tuit.peekNext();
				ASSERT(tus);
				const Ogre::String &textName = tus->getTextureName();
				Ogre::TextureManager::getSingleton().unload(textName);
				Ogre::TextureManager::getSingleton().remove(textName);

				tuit.moveNext();
			}
			pit.moveNext();
		}

		tit.moveNext();
	}

	Ogre::MaterialManager::getSingleton().unload(matName);
	Ogre::MaterialManager::getSingleton().remove(matName);
}
Esempio n. 4
0
/* Loads the app */
void ImgShowerApp::load(void)
{
	Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();

	if(!mContainer){
		// Create a panel
		mContainer = static_cast<Ogre::OverlayContainer*>(
			overlayManager.createOverlayElement("Panel", "ImgShowerAppPanel"));
		mContainer->setMetricsMode(Ogre::GMM_RELATIVE);
		mContainer->setPosition(0, 0);
		mContainer->setDimensions(1, 1);
		mContainer->setMaterialName(mOverlayName); // Optional background material
		// Ensures that the material exists
#ifdef DEBUG
		Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(
				mOverlayName,Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
		ASSERT(!mat.isNull());
#endif

	}

	if(!mOverlay){
		// Create an overlay, and add the panel
		mOverlay = overlayManager.create("ImgShowerAppOverlay");
		mOverlay->add2D(mContainer);
		mOverlay->show();
	}

	// extracted from http://www.ogre3d.org/tikiwiki/Creating+Overlays+via+Code

}
Esempio n. 5
0
Ogre::MaterialPtr Renderer::GetMaterialCopy(const String& originalName, const String& newName)
{
    Ogre::MaterialPtr material = GetMaterial(originalName);
    if (material.isNull())
        return material;
    return material->clone(newName);
}
Esempio n. 6
0
void EC_Sky::CreateSky()
{
    if (!ViewEnabled())
        return;

    if (world_.expired())
        return;

    QString currentMaterial = materialRef.Get().ref;

    Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(currentMaterial.toStdString().c_str());
    //Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(framework->Asset()->LookupAssetRefToStorage(materialRef.Get().ref).toStdString().c_str());
    if (materialPtr.isNull())
    {
        LogError("Could not get SkyBox material : " + currentMaterial.toStdString());
        return;
    }

    materialPtr->setReceiveShadows(false);

    try
    {
        world_.lock()->GetSceneManager()->setSkyBox(true, currentMaterial.toStdString().c_str(), distance.Get(),
            drawFirst.Get(), orientation.Get());
    }
    catch(Ogre::Exception& e)
    {
        LogError("Could not set SkyBox: " + std::string(e.what()));
    }
}
Esempio n. 7
0
	gkString createOrRetrieveHaloMaterial(const gkString& baseMatName)
	{
		gkString matName = DEFAULT_HALO_MAT;

		try
		{
			gkString haloMatName = baseMatName + ".halo";
			Ogre::MaterialManager& mmgr = Ogre::MaterialManager::getSingleton();
		
			if (mmgr.resourceExists(haloMatName))
				matName = haloMatName;
			else
			{
				Ogre::MaterialPtr baseMat = mmgr.getByName(baseMatName);
				if (!baseMat.isNull())
				{
					Ogre::MaterialPtr mat = mmgr.create(haloMatName, baseMat->getGroup());
					baseMat->copyDetailsTo(mat);
					Ogre::Pass *pass = mat->getTechnique(0)->getPass(0);

					pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
					pass->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 150);
					pass->setDepthWriteEnabled(false);
					Ogre::TextureUnitState* tu = pass->createTextureUnitState(HALO_IMAGE_NAME);	

					matName = haloMatName;
				}
			}		
		}
		catch(Ogre::Exception& e)
		{
			gkLogMessage("gkParticleManager: " << e.getDescription());
		}
		return matName;
	}
Esempio n. 8
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);
		}
	}
Esempio n. 9
0
void SponsorsState::enter(const MainMachineInfo &info)
{
	// load the fader state
	ASSERT(!mFader);
	Ogre::OverlayManager &om = Ogre::OverlayManager::getSingleton();
	mFader = om.getByName("FaderOverlay");
	ASSERT(mFader);
	Ogre::PanelOverlayElement *panel = static_cast<Ogre::PanelOverlayElement *>(
					mFader->getChild("FaderOverlay/Background"));
	ASSERT(panel);
	Ogre::MaterialPtr mat = panel->getMaterial();
	ASSERT(!mat.isNull());
	mTexture = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0);
	mTexture->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL,
						Ogre::LBS_TEXTURE, 0);
	ASSERT(mTexture);

	// load the  sponsors Overlay
	ASSERT(!mOverlay);
	mOverlay = om.getByName("SponsorsOverlay");
	ASSERT(mOverlay);
	mOverlay->setZOrder(mFader->getZOrder() - 1);	// put behind it

	mState = STATE_FADE_IN;
}
void MeshResourceMarker::reset()
{
  //destroy entity
  if (entity_)
  {
    context_->getSceneManager()->destroyEntity( entity_ );
    entity_ = 0;
  }

  // destroy all the materials we've created
  S_MaterialPtr::iterator it;
  for ( it = materials_.begin(); it!=materials_.end(); it++ )
  {
    Ogre::MaterialPtr material = *it;
    if (!material.isNull())
    {
      for (size_t i = 0; i < material->getNumTechniques(); ++i)
      {
        Ogre::Technique* t = material->getTechnique(i);
        // hack hack hack, really need to do a shader-based way of picking, rather than
        // creating a texture for each object
        if (t->getSchemeName() == "Pick")
        {
          Ogre::TextureManager::getSingleton().remove(t->getPass(0)->getTextureUnitState(0)->getTextureName());
        }
      }

      material->unload();
      Ogre::MaterialManager::getSingleton().remove(material->getName());
    }
  }
  materials_.clear();
}
Esempio n. 11
0
StringVector EC_OgreSky::GetMaterialTextureNames()
{
    StringVector texture_names;
    Ogre::MaterialPtr skyMaterial;
    switch(type_)
    {
    case OgreRenderer::SKYTYPE_BOX:
        skyMaterial = Ogre::MaterialManager::getSingleton().getByName(skyBoxParameters.material);
        break;
    case OgreRenderer::SKYTYPE_DOME:
        skyMaterial = Ogre::MaterialManager::getSingleton().getByName(skyDomeParameters.material);
        break;
    case OgreRenderer::SKYTYPE_PLANE:
        skyMaterial = Ogre::MaterialManager::getSingleton().getByName(skyPlaneParameters.material);
        break;
    }

    if (!skyMaterial.isNull())
    {
        Ogre::TextureUnitState *texture_state = skyMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0);
        if (texture_state)
            for(uint i = 0; i < texture_state->getNumFrames(); i++)
                texture_names.push_back(texture_state->getFrameTextureName(i));
        //Ogre::String textures = texture_state->getTextureName();
        //texture_names = Ogre::StringConverter::parseStringVector(textures);
    }
    return texture_names;
}
Esempio n. 12
0
Ogre::MaterialPtr SkeletonDebug::GetAxesMaterial()
{
    Ogre::String matName = "SkeletonDebug/AxesMat";

    Ogre::MaterialPtr mAxisMatPtr =
        Ogre::MaterialManager::getSingleton().getByName(matName);

    if (mAxisMatPtr.isNull())
    {
        mAxisMatPtr = Ogre::MaterialManager::getSingleton().create(
            matName, Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);

        // First pass for axes that are partially within the model (shows transparency)
        Ogre::Pass* p = mAxisMatPtr->getTechnique(0)->getPass(0);
        p->setLightingEnabled(false);
        p->setPolygonModeOverrideable(false);
        p->setVertexColourTracking(Ogre::TVC_AMBIENT);
        p->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        p->setCullingMode(Ogre::CULL_NONE);
        p->setDepthWriteEnabled(false);
        p->setDepthCheckEnabled(false);

        // Second pass for the portion of the axis that is outside the model (solid colour)
        Ogre::Pass* p2 = mAxisMatPtr->getTechnique(0)->createPass();
        p2->setLightingEnabled(false);
        p2->setPolygonModeOverrideable(false);
        p2->setVertexColourTracking(Ogre::TVC_AMBIENT);
        p2->setCullingMode(Ogre::CULL_NONE);
        p2->setDepthWriteEnabled(false);
    }

    return mAxisMatPtr;
}
Esempio n. 13
0
void MeshResourceMarker::reset()
{
  //destroy entity
  if (entity_)
  {
    context_->getSceneManager()->destroyEntity(entity_);
    entity_ = 0;
  }


  // destroy all the materials we've created
  S_MaterialPtr::iterator it;
  for (it = materials_.begin(); it != materials_.end(); it++)
  {
    Ogre::MaterialPtr material = *it;
    if (!material.isNull())
    {
      material->unload();
      Ogre::MaterialManager::getSingleton().remove(material->getName());
    }
  }
  materials_.clear();
  // the actual passes are deleted by the material
  color_tint_passes_.clear();
}
Esempio n. 14
0
Fade::Fade() :
mTime(1.0f),
mType(FADE_IN),
mTexture(0),
mAccumTime(0)
{
	if(!mOverlay){
		// create the shared overlay
		mOverlay = Ogre::OverlayManager::getSingleton().create("sFadeOv");
		mOverlay->show();
	}

	// create the element
	mElement = Ogre::OverlayManager::getSingleton().createOverlayElement(
			"Panel", "FdE" + Ogre::StringConverter::toString(mICounter));

	// Set the material
	mElement->setMaterialName("FaderMaterial");
	Ogre::MaterialPtr mat = mElement->getMaterial();
	ASSERT(!mat.isNull());
	mTexture = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0);
	mTexture->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL,
						Ogre::LBS_TEXTURE, 0);
	ASSERT(mTexture);

	mElement->show();

	++mICounter;
}
Esempio n. 15
0
void EC_WidgetCanvas::SetSelfIllumination(bool illuminating)
{
    if (material_name_.empty())
        return;

    Ogre::ColourValue emissiveColor;
    if (illuminating)
        emissiveColor = Ogre::ColourValue(1.0f, 1.0f, 1.0f, 1.0f);
    else
        emissiveColor = Ogre::ColourValue(0.0f, 0.0f, 0.0f, 0.0f);

    Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(material_name_);
    if (!material.isNull())
    {
        Ogre::Material::TechniqueIterator iter = material->getTechniqueIterator();
        while(iter.hasMoreElements())
        {
            Ogre::Technique *tech = iter.getNext();
            if (!tech)
                continue;
            Ogre::Technique::PassIterator passIter = tech->getPassIterator();
            while(passIter.hasMoreElements())
            {
                Ogre::Pass *pass = passIter.getNext();
                if (pass)
                    pass->setSelfIllumination(emissiveColor);
            }
        }
    }
}
Esempio n. 16
0
void EC_SkyBox::CreateSky()
{
    if (!ViewEnabled())
        return;

    if (renderer_.expired())
        return;

    QString currentMaterial = materialRef.Get().ref;

    Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(currentMaterial.toStdString().c_str());
    if (materialPtr.isNull())
    {
        LogError("Could not get SkyBox material : " + currentMaterial.toStdString());
        return;
    }

    materialPtr->setReceiveShadows(false);

    try
    {
        //RexTypes::Vector3 v = angleAxisAttr.Get();
        //Ogre::Quaternion rotation(Ogre::Degree(90.0), Ogre::Vector3(1, 0, 0));
        Quaternion o = orientation.Get();
        renderer_.lock()->GetSceneManager()->setSkyBox(true, currentMaterial.toStdString().c_str(), distance.Get(),
            drawFirst.Get(), Ogre::Quaternion(o.w, o.x, o.y, o.z));
    }
    catch(Ogre::Exception& e)
    {
        LogError("Could not set SkyBox: " + std::string(e.what()));
    }
}
	//-----------------------------------------------------------------------
	void PrimitiveShapeSet::rotateTexture(Ogre::Real speed)
	{
		// Get the material and rotate it, assume the material is loaded already, otherwise skip.
		Ogre::MaterialPtr material = getMaterial();
		if (material.isNull())
			return;

		Ogre::TextureUnitState::EffectMap::const_iterator it;
		unsigned short numberOfTechniques = material->getNumTechniques();
		for (unsigned short u = 0; u < numberOfTechniques; ++u)
		{
			Ogre::Technique* technique = material->getTechnique(u);
			unsigned short numberOfPasses = technique->getNumPasses();
			for (unsigned short v = 0; v < numberOfPasses; ++v)
			{
				Ogre::Pass* pass = technique->getPass(v);
				unsigned short numberOfTextureUnitStates = pass->getNumTextureUnitStates();
				for (unsigned short w = 0; w < numberOfTextureUnitStates; ++w)
				{
					// Set the rotation if not already available.
					// This can only be done once! Changing the rotationspeed or removing the rotation
					// and resetting it doesn´t seem to work.
					Ogre::TextureUnitState* textureUnitState = pass->getTextureUnitState(w);
					it = textureUnitState->getEffects().find(Ogre::TextureUnitState::ET_ROTATE);
					if (it == textureUnitState->getEffects().end())
					{
						textureUnitState->setRotateAnimation(speed);
					}
				}
			}
		}
	}
Esempio n. 18
0
   AxisRenderable::AxisRenderable(int lineCount,Ogre::Camera* camera,Ogre::Viewport* viewport) 
   {
        // Disable cast shadows by default
        mCastShadows = false;

      mPrevAxisGizmoSelAxis = -1;
      mCamera = camera;
      mViewport = viewport;

      m_max_line_count = m_line_count  = lineCount;
      m_line_count = 0;

      mLength = 200;
      mProjectDistance = mCamera->getFarClipDistance();
      m_local = false;
      m_locked_data = 0;
      //m_locked_buffer = 0;
      mRenderOp.vertexData = new Ogre::VertexData();
      m_radius = 0;

      mRenderOp.indexData = 0;
      mRenderOp.vertexData->vertexCount = m_line_count*2;
      mRenderOp.vertexData->vertexStart = 0;

      mRenderOp.operationType = Ogre::RenderOperation::OT_LINE_LIST; 
      mRenderOp.useIndexes = false; 

      Ogre::VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
      Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;

      decl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
      decl->addElement(0, 3*sizeof(Ogre::Real), Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);

      Ogre::HardwareVertexBufferSharedPtr vbuf = 
         Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
         decl->getVertexSize(0),
         2*m_max_line_count,
         Ogre::HardwareBuffer::HBU_WRITE_ONLY);

      bind->setBinding(0, vbuf);

      // Obtain the pure colour material
      Ogre::MaterialPtr pureColourMaterial = createPureColourMaterial(Ogre::ColourValue(1,1,0));

      Ogre::String realName = pureColourMaterial->getName() + "_NoDepthBuffer";
      Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(realName);
      if (material.isNull())
      {
          // Clone to avoid confuse somewhere else that using the same material
          material = pureColourMaterial->clone(realName);
          material->setDepthCheckEnabled(false);
          material->setDepthWriteEnabled(false);
      }

      setMaterial(material->getName());

      mBox.setExtents(-10,-10,-10,10,10,10);
      setQueryFlags(0);
   }
Esempio n. 19
0
 Foundation::ResourcePtr CreateResourceFromMaterial(Ogre::MaterialPtr material)
 {
     assert(!material.isNull());
     OgreMaterialResource* res = new OgreMaterialResource(material->getName());
     res->SetMaterial(material);
     Foundation::ResourcePtr res_ptr(res);
     return res_ptr;
 }
Esempio n. 20
0
std::string AssetsManager::materialAsText(Ogre::MaterialPtr material)
{
	if (material.isNull()) {
		return "";
	}
	Ogre::MaterialSerializer serializer;
	serializer.queueForExport(material, true, false);
	return serializer.getQueuedAsString();
}
Esempio n. 21
0
void gkMaterialLoader::setAlphaRejectValue(const gkString& materialName, unsigned char value)
{
	if (!Ogre::MaterialManager::getSingleton().resourceExists(materialName))
		return;

	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName);
	GK_ASSERT(!mat.isNull() && mat->getTechnique(0) && mat->getTechnique(0)->getPass(0));

	mat->getTechnique(0)->getPass(0)->setAlphaRejectValue(value);	
}
Esempio n. 22
0
RexTypes::RexAssetID EC_OgreSky::GetSkyPlaneTextureID() const
{
    RexTypes::RexAssetID textureID = "";
    Ogre::MaterialPtr skyMaterial = Ogre::MaterialManager::getSingleton().getByName(skyPlaneParameters.material);
    if (!skyMaterial.isNull())
    {
         textureID = skyMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getFrameTextureName(0);
    }
    return textureID;
}
Esempio n. 23
0
QString OgreMaterialProperties::ToString()
{
    Ogre::MaterialPtr matPtr = ToOgreMaterial();
    if (matPtr.isNull())
        return "";

    Ogre::MaterialSerializer serializer;
    serializer.queueForExport(matPtr, true, false);
    return QString(serializer.getQueuedAsString().c_str());
}
Esempio n. 24
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.");
    }
}
Esempio n. 25
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.");
    }
}
Esempio n. 26
0
void gkMaterialLoader::setAlphaRejectSettings(const gkString& materialName, gkCompareFunction func, 
	unsigned char value, bool alphaToCoverageEnabled)
{
	if (!Ogre::MaterialManager::getSingleton().resourceExists(materialName))
		return;

	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName);
	GK_ASSERT(!mat.isNull() && mat->getTechnique(0) && mat->getTechnique(0)->getPass(0));

	mat->getTechnique(0)->getPass(0)->setAlphaRejectSettings((Ogre::CompareFunction)func, value, alphaToCoverageEnabled);	
}
Esempio n. 27
0
RexTypes::RexAssetID EC_OgreSky::GetSkyBoxTextureID(uint texuture_index) const
{
    if(texuture_index >= 6) texuture_index = 5;
    RexTypes::RexAssetID textureID = "";
    Ogre::MaterialPtr skyMaterial = Ogre::MaterialManager::getSingleton().getByName(skyBoxParameters.material);
    if (!skyMaterial.isNull())
    {
         textureID = skyMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getFrameTextureName(texuture_index);
    }
    return textureID;
}
	//------------------------------------------------------
	void MaterialService::addWorldMaterialTemplate(unsigned int idx, const Ogre::MaterialPtr& material) {
		assert(!material.isNull());

		mTemplateMaterials.insert(make_pair(idx, material));

		TextureDimensions2D dimensions;

		dimensions.first = 64;
		dimensions.second = 64;

		if (material->getNumTechniques() > 0) {
			Pass *shadPass = material->getTechnique(0)->getPass(0);

			if (shadPass->getNumTextureUnitStates() > 0) {
				TextureUnitState* tus = shadPass->getTextureUnitState(0);

				try {
					// ensure the material is loaded before getting the dimensions
					material->escalateLoading();

					// This is stupid, but can happen - the getTextureDimensions seems buggy in this regard
					if (tus->getNumFrames() <= 0) {
						LOG_ERROR("MaterialService: Error getting texture dimensions (Mat. %s) : Zero frame count!", material->getName().c_str());
					} else {
						dimensions = tus->getTextureDimensions();

						// register the scale
						std::pair<float, float> tscale;

						tscale.first = tus->getTextureUScale();
						tscale.second = tus->getTextureVScale();

						// register the texture scale...
						setWRTextureScale(idx, tscale);

						// reset the scale back, it is canceled out by the fact we UV map with different txt dimensions
						tus->setTextureUScale(1.0f);
						tus->setTextureVScale(1.0f);

						dimensions.first = static_cast<unsigned int> (tscale.first * dimensions.first);
						dimensions.second = static_cast<unsigned int> (tscale.second * dimensions.second);
					}
				} catch (Ogre::Exception &e) {
					// Nothing, just log it could not be done
					LOG_ERROR("MaterialService: Error getting texture dimensions : %s", e.getFullDescription().c_str());
				}
			}
		}

		LOG_INFO("MaterialService: Registered a WR template material %u - %s", idx, material->getName().c_str());

		// insert
		mTextureDimensionMap.insert(make_pair(idx, dimensions));
	}
Ogre::MaterialPtr EmberTerrainProfile::getOrCreateMaterialClone(Ogre::MaterialPtr templateMaterial, const std::string& suffix)
{
    std::string name = templateMaterial->getName() + suffix;

    Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(name);
    if (!mat.isNull()) {
        return mat;
    }

    return templateMaterial->clone(name);
}
Esempio n. 30
0
void EC_OgreSky::SetSkyDomeMaterialTexture(const char *texture_name)
{
    type_ = SKYTYPE_DOME;

    Ogre::MaterialPtr skyMaterial = Ogre::MaterialManager::getSingleton().getByName(skyDomeParameters.material);
    if (!skyMaterial.isNull())
    {
        skyMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(texture_name);
        skyMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
        CreateSky();
    }
}