Page 1 of 1

Converting pixeldata to ITexture?

Posted: Fri Nov 05, 2010 12:42 pm
by Kernle 32DLL
Hi there,

I'm kind of stuck with something: I want to create an ITexture from pixel data (aka bytearray, or byte pointer, etc.). As described here, I could create an IImage first, and load an ITexture from it then. However, this has 2 disadvantages. First, it’s a waste of memory, and second it doesn't work with threads in OpenGL (at least addTexture fails when used in a thread, and Irrlicht was initialized with OpenGL)

So, any better ideas?

So long,
Kernle

Re: Converting pixeldata to ITexture?

Posted: Fri Nov 05, 2010 12:56 pm
by slavik262
Kernle 32DLL wrote:First, it’s a waste of memory.
False. If you drop the IImage as soon as you've created the texture from it, it will delete itself and you'll get the memory back. See IReferenceCounted, a base class of IImage (and most other classes in Irrlicht) which implements reference counting.
Kernle 32DLL wrote:and second it doesn't work with threads in OpenGL (at least addTexture fails when used in a thread, and Irrlicht was initialized with OpenGL)
Generally speaking, you can't perform ops which involve the GPU (such as loading/unloading textures, vertex buffers, rendering, etc.) in multiple threads. This isn't unique to Irrlicht - you'll find this to be the case pretty much anywhere. It's a DirectX and OpenGL problem (though IIRC DX11 is beginning to implement real multi-threaded rendering).

Posted: Fri Nov 05, 2010 3:55 pm
by hybrid
There's no problem with locking the texture and writing into it directly, though. The code should be largely the same, whether writing to image or texture.

Posted: Sun Nov 07, 2010 2:47 pm
by Kernle 32DLL
Tested it, and it fails just the same, this time while creating the texture (I dont even get to the locking part :/)

Seems like I have to drop that Threading idea, dang it :/

So long,
Kernle

Posted: Sun Nov 07, 2010 8:22 pm
by hybrid
Oh yeah, I didn't mean the threading. Just the basic workflow for creating and writing the texture.

Posted: Sun Nov 07, 2010 9:27 pm
by Kernle 32DLL
Okay, thanks for the info anway ;)