- Home /
Is Texture.apply() for Unity == glTexSubImage2D on native side on Unity
I have a texture in Unity which I will modify frequently. Now there are two options:
I can make changes to texture by calling setPixels and then call Texture2D.apply. I think the apply actually copies the data from CPU to GPU.
One option is I can modify the texture in native code by getting the texture native handle and modifying it using glTexSubImage2D functions.
Now I read the apply copies only the changed pixels to GPU not full texture but I really doubt if its possible. but if it is true does this mean that calling Texture2D.apply == glTexSubImage2Din terms of performance.
If not, what should I use if I need good performance. I actually dont want to go to native side as I will have to manage the native code on for different graphics APIs supported by Unity like opengl, DX etc
Answer by landon912 · May 29, 2017 at 03:06 AM
I do not have a definitive answer.
First off, on OpenGL platforms it's likely that Texture2D.Apply() is roughly equivalent to glTexSubImage2D().
Secondly, glTexSubImage2D does allow you to only update portions of the image, but these are continuous subsections. You can't only update pixels that have changed. I'm not sure, but I would believe Unity likely tries to take advantage of this when possible.
However, there are a few different methods that Unity could be using in some circumstances. Such as PBO's.
Overall, why worry about this unless it becomes an actual performance bottleneck?