//-----------------------------------------------------------------------
    void TextureUnitState::setTexture( const TexturePtr& texPtr)
    {
        if (!texPtr)
        {
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
                "Texture Pointer is empty.",
                "TextureUnitState::setTexture");
        }

        setContentType(CONTENT_NAMED);
        mTextureLoadFailed = false;

        if (texPtr->getTextureType() == TEX_TYPE_CUBE_MAP)
        {
            // delegate to cubic texture implementation
            setCubicTexture(&texPtr, true);
            return;
        }
        
        if (texPtr->getTextureType() == TEX_TYPE_EXTERNAL_OES || texPtr->getTextureType() == TEX_TYPE_2D_RECT)
        {
            setTextureAddressingMode( TAM_CLAMP );
        }

        mFramePtrs.resize(1);
        mFramePtrs[0] = texPtr;

        mCurrentFrame = 0;
        mCubic = false;

        // Load immediately ?
        if (isLoaded())
        {
            _load(); // reload
        }
        // Tell parent to recalculate hash
        if( Pass::getHashFunction() == Pass::getBuiltinHashFunction( Pass::MIN_TEXTURE_CHANGE ) )
        {
            mParent->_dirtyHash();
        }
    }
	//-----------------------------------------------------------------------
	void TextureUnitState::setTexture( const TexturePtr& texPtr)
	{
		if (texPtr.isNull())
		{
			OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
				"Texture Pointer is empty.",
				"TextureUnitState::setTexture");
		}

		setContentType(CONTENT_NAMED);
		mTextureLoadFailed = false;

		if (texPtr->getTextureType() == TEX_TYPE_CUBE_MAP)
		{
			// delegate to cubic texture implementation
			setCubicTexture(&texPtr, true);
		}
		else
		{
			mFrames.resize(1);
			mFramePtrs.resize(1);
			mFrames[0] = texPtr->getName();
			mFramePtrs[0] = texPtr;
			// defer load until used, so don't grab pointer yet
			mCurrentFrame = 0;
			mCubic = false;
			mTextureType = texPtr->getTextureType();

			// Load immediately ?
			if (isLoaded())
			{
				_load(); // reload
			}
			// Tell parent to recalculate hash
			if( Pass::getHashFunction() == Pass::getBuiltinHashFunction( Pass::MIN_TEXTURE_CHANGE ) )
			{
				mParent->_dirtyHash();
			}
		}
	}
Beispiel #3
0
	ProceduralManualObject* createProceduralParticleSystem()
	{
		particleSystem = static_cast<ProceduralManualObject*>
			(mSceneMgr->createMovableObject("ParticleGSEntity", ProceduralManualObjectFactory::FACTORY_TYPE_NAME));
		particleSystem->setMaterial("Ogre/ParticleGS/Display");

		//Generate the geometry that will seed the particle system
		ManualObject* particleSystemSeed = mSceneMgr->createManualObject("ParticleSeed");
		//This needs to be the initial launcher particle
		particleSystemSeed->begin("Ogre/ParticleGS/Display", RenderOperation::OT_POINT_LIST);
		particleSystemSeed->position(0,0,0); //Position
		particleSystemSeed->textureCoord(1); //Timer
		particleSystemSeed->textureCoord(0); //Type
		particleSystemSeed->textureCoord(0,0,0); //Velocity
		particleSystemSeed->end();

		//Generate the RenderToBufferObject
		RenderToVertexBufferSharedPtr r2vbObject = 
			HardwareBufferManager::getSingleton().createRenderToVertexBuffer();
		r2vbObject->setRenderToBufferMaterialName("Ogre/ParticleGS/Generate");
		
		//Apply the random texture
		TexturePtr randomTexture = RandomTools::generateRandomVelocityTexture();
		r2vbObject->getRenderToBufferMaterial()->getTechnique(0)->getPass(0)->
			getTextureUnitState("RandomTexture")->setTextureName(
			randomTexture->getName(), randomTexture->getTextureType());

		r2vbObject->setOperationType(RenderOperation::OT_POINT_LIST);
		r2vbObject->setMaxVertexCount(16000);
		r2vbObject->setResetsEveryUpdate(false);
		VertexDeclaration* vertexDecl = r2vbObject->getVertexDeclaration();
		size_t offset = 0;
		offset += vertexDecl->addElement(0, offset, VET_FLOAT3, VES_POSITION).getSize(); //Position
		offset += vertexDecl->addElement(0, offset, VET_FLOAT1, VES_TEXTURE_COORDINATES, 0).getSize(); //Timer
		offset += vertexDecl->addElement(0, offset, VET_FLOAT1, VES_TEXTURE_COORDINATES, 1).getSize(); //Type
		offset += vertexDecl->addElement(0, offset, VET_FLOAT3, VES_TEXTURE_COORDINATES, 2).getSize(); //Velocity
		
		//Bind the two together
		particleSystem->setRenderToVertexBuffer(r2vbObject);
		particleSystem->setManualObject(particleSystemSeed);

		//Set bounds
		AxisAlignedBox aabb;
		aabb.setMinimum(-100,-100,-100);
		aabb.setMaximum(100,100,100);
		particleSystem->setBoundingBox(aabb);
		
		return particleSystem;
	}
    //-----------------------------------------------------------------------------------
    RenderTarget* CompositorPass::calculateRenderTarget( size_t rtIndex,
                                                         const CompositorChannel &source )
    {
        RenderTarget *retVal;

        if( !source.isMrt() && !source.textures.empty() &&
            source.textures[0]->getTextureType() > TEX_TYPE_2D )
        {
            //Who had the bright idea of handling Cubemaps differently
            //than 3D textures is a mystery. Anyway, deal with it.
            TexturePtr texturePtr = source.textures[0];

            if( rtIndex >= texturePtr->getDepth() && rtIndex >= texturePtr->getNumFaces() )
            {
                size_t maxRTs = std::max<size_t>( source.textures[0]->getDepth(),
                                                    source.textures[0]->getNumFaces() );
                OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
                        "Compositor pass is asking for a 3D/Cubemap/2D_array texture with "
                        "more faces/depth/slices than what's been supplied (Asked for slice '" +
                        StringConverter::toString( rtIndex ) + "', RT has '" +
                        StringConverter::toString( maxRTs ) + "')",
                        "CompositorPass::calculateRenderTarget" );
            }

            /*//If goes out bounds, will reference the last slice/face
            rtIndex = std::min( rtIndex, std::max( source.textures[0]->getDepth(),
                                                    source.textures[0]->getNumFaces() ) - 1 );*/

            TextureType textureType = texturePtr->getTextureType();
            size_t face = textureType == TEX_TYPE_CUBE_MAP ? rtIndex : 0;
            size_t slice= textureType != TEX_TYPE_CUBE_MAP ? rtIndex : 0;
            retVal = texturePtr->getBuffer( face )->getRenderTarget( slice );
        }
        else
        {
            retVal = source.target;
        }

        return retVal;
    }
void TextureToolWindow::updateControls(String texName)
{
    try
    {
        bool exists = TextureManager::getSingleton().resourceExists(texName);
        if (!exists)
        {
            mTxt->setCaption(convertToMyGUIString("Texture not found:\n" + texName));
            mBtnSavePNG->setEnabled(false);
            return;
        }

        TexturePtr tex = TextureManager::getSingleton().getByName(texName);
        if (tex.isNull())
        {
            mTxt->setCaption(convertToMyGUIString("Error loading texture:\n" + texName));
            mBtnSavePNG->setEnabled(false);
            return;
        }

        String str = "#aa0000" + texName + "#000000\n";
        str += "#00aa00res: #000000" + TOSTRING(tex->getWidth()) + " x " + TOSTRING(tex->getHeight()) + " pixels\n";
        str += "#00aa00size: #000000" + formatBytes(tex->getSize()) + "\n";
        str += "#00aa00format: #000000" + PixelUtil::getFormatName(tex->getFormat()) + "\n";
        if (tex->getNumFaces() > 1)
            str += "#00aa00faces: #000000" + TOSTRING(tex->getNumFaces()) + "\n";
        if (tex->getFSAA() > 0)
            str += "#00aa00FSAA: #000000" + TOSTRING(tex->getFSAA()) + "\n";
        if (tex->getNumMipmaps() > 0)
            str += "#00aa00mipmaps: #000000" + TOSTRING(tex->getNumMipmaps()) + "\n";

        String typeStr = "";
        switch (tex->getTextureType())
        {
        case TEX_TYPE_1D: typeStr = "1D";
            break;
        case TEX_TYPE_2D: typeStr = "2D";
            break;
        case TEX_TYPE_3D: typeStr = "3D";
            break;
        case TEX_TYPE_CUBE_MAP: typeStr = "Cube Map";
            break;
        }
        str += "#00aa00type: #000000" + typeStr + "\n";

        String usageStr = "";
        if (tex->getUsage() & TU_STATIC)
            usageStr += "static,\n";
        if (tex->getUsage() & TU_DYNAMIC)
            usageStr += "dynamic,\n";
        if (tex->getUsage() & TU_WRITE_ONLY)
            usageStr += "write only,\n";
        if (tex->getUsage() & TU_STATIC_WRITE_ONLY)
            usageStr += "static write only,\n";
        if (tex->getUsage() & TU_DYNAMIC_WRITE_ONLY)
            usageStr += "dynamic write only,\n";
        if (tex->getUsage() & TU_DYNAMIC_WRITE_ONLY_DISCARDABLE)
            usageStr += "dynamic write only discardable,\n";
        if (tex->getUsage() & TU_AUTOMIPMAP)
            usageStr += "automipmap,\n";
        if (tex->getUsage() & TU_RENDERTARGET)
            usageStr += "rendertarget,\n";
        if (tex->getUsage() & TU_DEFAULT)
            usageStr += "default\n";

        str += "#00aa00usage: #000000" + usageStr + "\n";
        if (tex->getDepth() > 1)
            str += "#00aa00depth: #000000" + TOSTRING(tex->getDepth()) + "\n";

        mTxt->setCaption(convertToMyGUIString(str));
        mImage->setImageTexture(texName);
        mBtnSavePNG->setEnabled(true);
    }
    catch (Exception& e)
    {
        UTFString str = "Exception while opening texture:" + e.getFullDescription();
        RoR::App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_MSGTYPE_INFO, str, "error.png");
    }
}