void CCoherentUISystem::ChangeEntityDiffuseTextureForMaterial( CCoherentViewListener* pViewListener, const char* entityName, const char* materialName )
    {
        IMaterial* pMaterial = gEnv->p3DEngine->GetMaterialManager()->FindMaterial( materialName );
        IEntity* pEntity = gEnv->pEntitySystem->FindEntityByName( entityName );

        if ( pEntity && !pMaterial )
        {
            pMaterial = pEntity->GetMaterial();
        }

        if ( pMaterial )
        {
            STexSamplerRT& sampler = pMaterial->GetShaderItem().m_pShaderResources->GetTexture( EFTT_DIFFUSE )->m_Sampler;

            // Create a new texture and scrap the old one
            void* pD3DTextureDst = NULL;
            ITexture* pCryTex = gD3DSystem->CreateTexture(
                                    &pD3DTextureDst,
                                    sampler.m_pITex->GetWidth(),
                                    sampler.m_pITex->GetHeight(),
                                    1,
                                    eTF_A8R8G8B8,
                                    FT_USAGE_DYNAMIC
                                );

            int oldTextureID = sampler.m_pITex->GetTextureID();
            gEnv->pRenderer->RemoveTexture( oldTextureID );
            sampler.m_pITex = pCryTex;
            pCryTex->AddRef();

            pViewListener->SetTexture( pD3DTextureDst, pCryTex->GetTextureID() );
        }
    }
예제 #2
0
/*
*	Creates a render target
*	Param _kfWidth  : The width of the render terget
*	Param _kfHeight : The height of th erender target
*	Param _keFMT	: The render targets format
*	Return : ITexture, The render target
*/
ITexture* CDX9TextureManager::CreateRenderTarget( CAssetId& _rAssetId,const uint32 _kuWidth, const uint32 _kuHeight, const ESurfaceFormat _keFMT, const bool _bWriteOnly  )
{

	// Check if the render target has already been created.
	ITexture* pRenderTarget = NULL;
	pRenderTarget = GetAssetById( _rAssetId );
	if( pRenderTarget )
	{
		pRenderTarget->AddRef( );
		return pRenderTarget;
	}

	static const D3DFORMAT pFormats[] = 
	{
		D3DFMT_R32F,
		D3DFMT_X8R8G8B8,
		D3DFMT_D16,
	};

	
	// Do we want to crate a depth stencile?
	if( _keFMT == SF_uDepth )
	{
		// Create a depth stencile texture
		IDirect3DSurface9* pSurface = NULL;
		if( FAILED( CDX9Renderer::GetDevice( )->CreateDepthStencilSurface( _kuWidth, _kuHeight, pFormats[_keFMT], D3DMULTISAMPLE_NONE, 0, !_bWriteOnly, &pSurface, 0 ) ) )
		{
			// no
			// assert
			return NULL;
		}
		return new CDX9Texture( pSurface, CDX9Renderer::GetDevice( ), true );
	}

	// Create a render target

	IDirect3DTexture9* pTexture = NULL;
	//NOTE: The 0 may need to be a 1
	if( FAILED( CDX9Renderer::GetDevice( )->CreateTexture( _kuWidth, _kuHeight, 0, D3DUSAGE_RENDERTARGET, pFormats[_keFMT], D3DPOOL_DEFAULT, &pTexture, 0 ) ) )
	{
		// no 
		// assert
		assert_now( "Failed to texture!" );
		return NULL;
	}

	return new CDX9Texture( pTexture, CDX9Renderer::GetDevice( ) ) ;
}