First procedural texture

I’ve finally managed to apply a simple procedural texture. Everything is a little bit green, but it’s a progress :=D

There’s been some difficulties with threads while working with procedural textures, similar to this. We have different threads in a game to manage different tasks, so textures need to be generated in the same thread with graphics driver.

Here is the code that DIDN’T WORK:

ITexture	* IrrlichtFactory::generateTexture( const std::string &type )
{
	IImage *img = m_Driver->createImage(ECF_A8R8G8B8, dimension2d<u32>(128, 128));

	ITexture *texture = 0;

	doSyncOperation(
		*m_Io,
		boost::bind(
		static_cast<ITexture*(IVideoDriver::*)(const io::path& ,  IImage* , void* )>(&IVideoDriver::addTexture),
		m_Driver, "texture", img, (void*)0), texture);

		/*insert some data into texture...*/

		return texture;
}

The whole process of adding the texture to the driver and inserting texture data into texture needs to be done in the same thread. Here I’ve experimented with IImage and dimension2d – there is really no difference which approach to use.

Here is the code that DID WORK:

ITexture	* IrrlichtFactory::generateTexture( const std::string &type )
{
	ITexture *texture = 0;

	doSyncOperation(
		*m_Io,
		boost::bind(&IrrlichtFactory::doGenerateTexture, this, type),
		texture);

	return texture;
}

ITexture	* IrrlichtFactory::doGenerateTexture( const std::string &type )
{
	ITexture *texture = m_Driver->addTexture(dimension2d<u32>(128,128), "texture", ECF_A8R8G8B8);

	/* insert some texture data... */

	return texture;
}

The method doOperation is too complex to be laid out in detail here, but it performs a synchronous operation on another thread, and returns the result to calling thread.

About Freya

Senior Software Engineer developing all kinds of stuff.
This entry was posted in coding, progress, screenshots, texture and tagged , , , , , , . Bookmark the permalink.