Ejemplo n.º 1
0
// ***************************************************************************
void			CMaterial::flushTextures (IDriver &driver, uint selectedTexture)
{
	// For each textures
	for (uint tex=0; tex<IDRV_MAT_MAXTEXTURES; tex++)
	{
		// Texture exist ?
		if (_Textures[tex])
		{
			// Select the good texture
			_Textures[tex]->selectTexture (selectedTexture);

			// Force setup texture
			driver.setupTexture (*_Textures[tex]);
		}
	}

	// If Lightmap material
	if(_ShaderType==LightMap)
	{
		// For each lightmap
		for (uint lmap=0; lmap<_LightMaps.size(); lmap++)
		{
			// Texture exist?
			if(_LightMaps[lmap].Texture)
			{
				// Force setup texture
				driver.setupTexture (*_LightMaps[lmap].Texture);
			}
		}
	}

}
Ejemplo n.º 2
0
//***************************************************************************************************************
void				CFlareShape::flushTextures (IDriver &driver, uint selectedTexture)
{
	// Flush each texture
	for (uint tex=0; tex<MaxFlareNum; tex++)
	{
		if (_Tex[tex] != NULL)
		{
			// Select the good texture
			_Tex[tex]->selectTexture (selectedTexture);

			// Flush texture
			driver.setupTexture (*_Tex[tex]);
		}
	}
}
Ejemplo n.º 3
0
///===========================================================================
void CParticleSystemShape::flushTextures(IDriver &driver, uint selectedTexture)
{
	// if textures are already flushed, no-op
	if (!_CachedTex.empty()) return;
	if (_SharedSystem)
	{
		_SharedSystem->enumTexs(_CachedTex, driver);
	}
	else
	{
		s_PSSMutex.enter();

		// must create an instance just to flush the textures
		CParticleSystem *myInstance = NULL;

		#ifdef PS_FAST_ALLOC
			nlassert(PSBlockAllocator == NULL);
			NLMISC::CContiguousBlockAllocator blockAllocator;
			PSBlockAllocator = &blockAllocator;
			blockAllocator.init(300000); // we release memory just after, and we don't want to fragment the memory, so provide large enough mem
		#endif
		// serialize from the memory stream
		if (!_ParticleSystemProto.isReading()) // we must be sure that we are reading the stream
		{
			_ParticleSystemProto.invert();
		}
		_ParticleSystemProto.resetPtrTable();
		_ParticleSystemProto.seek(0, NLMISC::IStream::begin);
		_ParticleSystemProto.serialPtr(myInstance); // instanciate the system
		#ifdef PS_FAST_ALLOC
			_NumBytesWanted = blockAllocator.getNumAllocatedBytes(); // next allocation will be fast because we know how much memory to allocate
		#endif
		myInstance->enumTexs(_CachedTex, driver);
		// tmp
		/*
		#ifdef NL_DEBUG
			for(uint k = 0; k < myInstance->getNbProcess(); ++k)
			{
				CPSLocated *loc = (CPSLocated *) myInstance->getProcess(k);
				for(uint l = 0; l < loc->getNbBoundObjects(); ++l)
				{
					if (dynamic_cast<CPSCentralGravity *>(loc->getBoundObject(l)))
					{
						nlwarning("PS %s uses central gravity", myInstance->getName().c_str());
						break;
					}
				}
			}
		#endif */
		// sort the process inside the fx
		myInstance->getSortingByEmitterPrecedence(_ProcessOrder);
		delete myInstance;
		#ifdef PS_FAST_ALLOC
			PSBlockAllocator = NULL;
		#endif
		s_PSSMutex.leave();
	}
	for(uint k = 0; k < _CachedTex.size(); ++k)
	{
		//nlinfo(_CachedTex[k]->getShareName().c_str());
		if (_CachedTex[k])
		{
			_CachedTex[k]->setTextureCategory(CPSTextureCategory::get());
			driver.setupTexture(*_CachedTex[k]);
		}
	}
}
Ejemplo n.º 4
0
//*******************************************************************************
void CWaterEnvMap::init(uint cubeMapSize, uint projection2DSize, TGlobalAnimationTime updateTime, IDriver &driver)
{
	// Allocate cube map
	// a cubic texture with no sharing allowed
	class CTextureCubeUnshared : public CTextureCube
	{
	public:
		virtual bool supportSharing() const {return false;}
		virtual uint32 getWidth(uint32 numMipMap = 0) const
		{
			nlassert(numMipMap == 0);
			return Size;
		}
		virtual uint32 getHeight(uint32 numMipMap = 0) const
		{
			nlassert(numMipMap == 0);
			return Size;
		}
		uint32 Size;
	};
	// a 2D testure
	class CTexture2DUnshared : public CTextureBlank
	{
	public:
		virtual bool supportSharing() const {return false;}
		virtual uint32 getWidth(uint32 numMipMap = 0) const
		{
			nlassert(numMipMap == 0);
			return Size;
		}
		virtual uint32 getHeight(uint32 numMipMap = 0) const
		{
			nlassert(numMipMap == 0);
			return Size;
		}
		uint32 Size;
	};
	nlassert(cubeMapSize > 0);
	nlassert(NLMISC::isPowerOf2(cubeMapSize));
	nlassert(projection2DSize > 0);
	nlassert(NLMISC::isPowerOf2(projection2DSize));
	CTextureCubeUnshared *envCubic = new CTextureCubeUnshared;
	_EnvCubic = envCubic;
	_EnvCubic->setRenderTarget(true); // we will render to the texture
	_EnvCubic->setWrapS(ITexture::Clamp);
	_EnvCubic->setWrapT(ITexture::Clamp);
	_EnvCubic->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
	CTexture2DUnshared *tb = new CTexture2DUnshared;
	tb->resize(cubeMapSize, cubeMapSize); // Unfortunately,  must allocate memory in order for the driver to figure out the size
	                                      // that it needs to allocate for the texture, though its datas are never used (it is a render target)
	tb->Size = cubeMapSize;
	tb->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
	for(uint k = 0; k < 6; ++k)
	{
		_EnvCubic->setTexture((CTextureCube::TFace) k, tb);
		_EnvCubic->getTexture((CTextureCube::TFace) k)->setRenderTarget(true);
	}
	envCubic->Size = cubeMapSize;
	// setup the texture to force the driver to allocate vram for it
	driver.setupTexture(*_EnvCubic);
	tb->reset();
	// Allocate projection 2D map
	CTexture2DUnshared *env2D = new CTexture2DUnshared;
	_Env2D = env2D;
	_Env2D->resize(projection2DSize, projection2DSize);
	env2D->Size = projection2DSize;
	_Env2D->setWrapS(ITexture::Clamp);
	_Env2D->setWrapT(ITexture::Clamp);
	_Env2D->setRenderTarget(true); // we will render to the texture
	_Env2D->setFilterMode(ITexture::Linear, ITexture::LinearMipMapOff);
	driver.setupTexture(*_Env2D); // allocate vram
	_Env2D->reset();
	_UpdateTime = updateTime;
	_LastRenderTime = -1;
	invalidate();
	_NumRenderedFaces = 0;
	_EnvCubicSize = cubeMapSize;
	_Env2DSize = projection2DSize;
}