In OpenGL v1, like 20 years ago, there was a function glTexSubImage2D, which allowed you to upload a portion of pixel data (e.g. a sub rectangle within a larger rectangle), up to a texture, but not the whole size of the texture. ie say your texture is 1024x1024, you could upload just a 256x256 portion of it.
In Unity, this has never been implemented. The scenario I need it for is where I have a large amount of texture data representing a game environment, I want to make changes to some stuff on the CPU side, and upload the changes efficiently. Problem is, since Apply() only uploads the âwhole textureâ, the textures therefore have to be quite small, which massively ramps up the draw calls. So now you have a grid of small textures. Yes the upload speed is now âokayâ but at the expense of draw calls hiking up.
The ideal is that the textures remain larger and fewer (or even just one large texture), and then an equivalent to glTexSubImage2D is used to upload only a small rectangle from a main memory buffer into a position in the texture. Sort of similar to CopyTexture but between the cpu and gpu over the graphics bus.
Why hasnât this been implemented STILL after all these years, and is there any way to do this in Unity at all?
There should be a nice easy command such as:
Texture2D.Apply(x,y,width,height);
Which allows you to specify where in the texture the upload will end up, and the size of the operation. And additionallyâŚ
Texture2D.Apply(sourcex,sourcey,destx,desty,width,height);
Which now lets you select where in the main-memory (is readable memory buffer) to pull pixels from and where to write to plus the size of the op.
This would greatly help with performance in this kind of scenario. Is there any way to do this or anything close to it?