Game Development Community

Building Textures in engine and applying to a sprite

by Jonathan Brockman · in Torque 2D Professional · 11/14/2014 (8:34 am) · 3 replies

Hello!

So, our my quest to optimize, we have decided to move our lightmap and LOS stuff into the engine. We currently render light levels and FOVS usign a composite sprite of varying alpha values. This works, but is tremendously slow, especially when we want to refresh the whole thing (day/night cycles).

So, my desire it to generate a lightmap texture in engine, and then apply as a single sprite, with alpha values already calculated.

I have generated the texture, and it exists as a bitmapPNG, though I can not figure out how to convert this into a useable asset that I can apply to a sprite without writing to the hard drive and then reading it right back (which is not an option).

Can anyone give me some pointers?

#1
11/14/2014 (2:06 pm)
I think you're going to have to add a method to ImageAsset to supplement setImageFile() that takes a texture instead of a file name (perhaps take a TextureHandle and set mImageTextureHandle directly?). Then, create your asset and add it to the manager using addPrivateAsset() - this does not create the .asset.taml file on disk. This should let you use the generated image without writing anything out.
#2
11/19/2014 (5:35 am)
Hey Richard,

Yeah, that's exactly what I ended up doing. The only downside is I need to regenerate the image quite frequently and I'm encountering a crash if I tell the engine to persist the image so I can modify it, though I haven't looked too closely at that yet.

That said, it is an order of magnitude faster then the old way, so I am quite pleased!
#3
11/21/2014 (12:49 pm)
Sweet! Does it not like adding it as a private asset? Private assets were intended to provide a "scratch pad" asset for use in asset editors - a left-over from 3SS.

Or - what if you load a "blank" image from disk so that the resource manager has a properly added texture object and work in that?

Just thinking out loud....