void GenesisTexture::createManual(int _width, int _height, TextureUsage _usage, PixelFormat _format)
	{
		m_width = _width;
		m_height = _height;
		mOriginalUsage = _usage;
		setFormat(_format);
		RenderBase::PixelFormat::Code wj_format = FormatMyGuiToWj(_format);

		GPtr<RenderBase::Texture> tex = RenderBase::Texture::Create();
		tex->Setup();

		// set type
		RenderBase::Texture::Type texType = RenderBase::Texture::Texture2D;

		tex->SetType( texType );

		tex->SetWidth( _width );
		tex->SetHeight( _height );
		tex->SetDepth( 1);
		tex->SetNumMipLevels( 1 );
		tex->SetPixelFormat( wj_format );

		tex->SetUsage(UsageMyGuiToWj(_usage));
		//tex->SetUsage(RenderBase::RenderResource::UsageDynamic);
		tex->SetAccess(RenderBase::RenderResource::AccessWrite);


		// dummy
		tex->SetSkippedMips( 0 );
		tex->SetUnitIndex( 0 );

		//tex->SetTexturePath();

		if (m_texStream)
		{
			m_texStream = NULL;
		}
		m_texStream = IO::MemoryStream::Create();
		m_texStream->SetAccessMode( IO::Stream::WriteAccess );
		if( m_texStream->Open() )
		{
			m_texStream->SetSize(m_width * m_height * mNumElemBytes);
			tex->SetStream( m_texStream.upcast<IO::Stream>() );
			m_texStream->Close();
			//m_texStream->SetAccessMode( IO::Stream::ReadAccess );
			m_texHandle = Graphic::GraphicSystem::Instance()->CreateTexture(tex);

			GenesisTextureMgr::Instance()->AddManualTexture(this);
			m_bManualCreate = true;
		}
		else
		{
			m_texHandle = NULL;
			m_width = 0;
			m_height = 0;
			mOriginalUsage = TextureUsage::Default;
			mOriginalFormat = PixelFormat::Unknow;
		}
	}
	void GenesisTextureMgr::ReLoadManualTextures() const
	{
		SizeT nCount = m_ManualTextures.Size();

		for (IndexT i = 0; i < nCount; ++i)
		{

			GenesisTexture* pTex = m_ManualTextures[i];

			SizeT width  = pTex->getWidth();
			SizeT height = pTex->getHeight();

			RenderBase::PixelFormat::Code wj_format = GenesisTexture::FormatMyGuiToWj(pTex->getFormat());

			GPtr<RenderBase::Texture> tex = RenderBase::Texture::Create();
			tex->Setup();

			// set type
			RenderBase::Texture::Type texType = RenderBase::Texture::Texture2D;

			tex->SetType( texType );

			tex->SetWidth( width );
			tex->SetHeight( height );
			tex->SetDepth( 1);
			tex->SetNumMipLevels( 1 );
			tex->SetPixelFormat( wj_format );

			tex->SetAccess(RenderBase::RenderResource::AccessWrite);

			// dummy
			tex->SetSkippedMips( 0 );
			tex->SetUnitIndex( 0 );

			tex->SetStream( pTex->GetBuffer().upcast<IO::Stream>() );

			Graphic::GraphicSystem::Instance()->UpdateTexture(pTex->GetTextureHandle(), tex);
		}
	}
	GPtr<RenderBase::Texture> _BuildTextureData(const GPtr<Resources::ImageRes>& image, GPtr<IO::MemoryStream>& memStream)
	{
		n_assert(image.isvalid());

		if ( !image.isvalid() )
		{
			return GPtr<RenderBase::Texture>();
		}

		if ( !image->Validata() )
		{
			return GPtr<RenderBase::Texture>();
		}

		GPtr<RenderBase::Texture> tex = RenderBase::Texture::Create();
		tex->Setup();

		// set type
		RenderBase::Texture::Type texType = RenderBase::Texture::InvalidType;

		if ( image->GetNumFace() == 1 )
		{
			if ( image->GetDepth() == 1)
			{
				texType = RenderBase::Texture::Texture2D; 
			}
			else
			{
				n_assert( image->GetDepth() > 1);
				texType = RenderBase::Texture::Texture3D; 
			}
		}
		else 
		{
			n_assert( image->GetNumFace() > 1);
			texType = RenderBase::Texture::TextureCube;
		}
		n_assert( texType != RenderBase::Texture::InvalidType)
			tex->SetType( texType );

		tex->SetWidth( image->GetWidth() );
		tex->SetHeight( image->GetHeight() );
		tex->SetDepth( image->GetDepth() );
		tex->SetNumMipLevels( image->GetMipMapLevel() + 1 );
		tex->SetPixelFormat( image->GetPixelFormat() );

		// dummy
		tex->SetSkippedMips( 0 );
		tex->SetUnitIndex( 0 );

		n_assert( image->GetResourceId().IsValid() );
		tex->SetTexturePath(image->GetResourceId());

		const GPtr<ImageData>& imageData = image->GetImageData();
		n_assert( imageData.isvalid() );
		if (memStream)
		{	
			memStream = NULL;
		}
		memStream = IO::MemoryStream::Create();

		memStream->SetAccessMode( IO::Stream::ReadWriteAccess );
		if( memStream->Open() )
		{
			memStream->Write( imageData->Ptr(), imageData->Size() );
			tex->SetStream( memStream.upcast<IO::Stream>() );
			memStream->Close();
			return tex;
		}

		return GPtr<RenderBase::Texture>();
	}