Texture2D.Apply () optimizaton question...

Hi !!!

I need to modify a texture once per frame using several Texture2D.SetPixel () methods (cannot use Texture2D.SetPixels () due to my subsystem implementation).

My question is: it is better to call the Texture2D.Apply () function to a texture modified with the Texture2D.SetPixel () or to alternate 2 different textures by assigning one or other (however modified with Texture2D.SetPixel () ) in the void OnGui () function?

Maybe this question could sound a bit strange but the point is that I don’t know how the Texture2D.SetPixel () and the Texture2D.Apply () functions work.
I presume that the Texture2D.SetPixel () function will change the pixel value in the texture that is stored in the RAM while the Texture2D.Aplly () function will take the texture stored in the RAM and store it in the VRAM.

If the things is as I said switching 2 textures will be useless because it could be the same as to do a texture2D.Apply ().

Can someone please tell me how these 2 funtion works?

THANKS !!! :slight_smile:

Apply() uploads the texture to VRAM. If you don’t do this, then none of your changes will be visible. Apply() is pretty slow, so you want to do it as little as possible.

–Eric

In my application I need to update 4 textures 5 times per second and I need to apply this changes on screen. I need to use the Texture2D.Apply () function to do that.

My question was: it is slower the Apply or the texture switching?
I think that these are the same 'cause I think that switching a Texture2D with another one in a GameObject will call an Apply function to move the texture from RAM to VRAM.

I don’t believe that is the case. I think switching between Textures would be faster. I’d have to test it, though. Try doing a bunch of that, see which is faster?

Only the first time the texture is used. (Which one thing that can cause “hiccups” that you see in games sometimes.) If you need to update that texture too, then yes, it won’t make any difference.

–Eric

I suspected it.

Thanks Eric5h5 !!