What is the maximum number of textures?

I have a scenario where I need to create possibly 4096 Alpha8 textures. … in total they will consume about 64mb. Video ram permitting, is there a limit to how many textures are allowed? Does OpenGL/DirectX have a limit? Does Unity impose a limit? And perhaps more importantly, is this many textures supported on various graphics hardware?

there is no max limit (ok potentially the limit of int or short but you won’t have 64k parallel ones).

on the desktop it will work for sure.
just keep in mind that you can’t draw them all at the same time as 4000 drawcalls are 3000+ more than you can reasonable use even on the desktop (anywhere else its even lower)

Hmm ok thanks. Yes the drawcalls is not a problem I’m only showing about 250-300 onscreen. I might not actually need 4096, but having that many allows them to be small enough to do a SetPixels() and Apply() on one texture every frame … haven’t tested it for speed yet but hopefully it’s fast enough … would be similar to glTexSubImage2D() in OpenGL I guess, each texture is only 128x128 8-bit which is only 16k per frame, hopefully fast enough.

Bear in mind that textures will use ~35% more VRAM than the basic texture if mipmaps are enabled. With 128x128 textures you probably won’t need them, so disable them to avoid using additional VRAM per texture.

it does not use subimage if we go by the behavior
alter a pixel = whole texture is reuploaded

Regarding mipmaps, yes, I won’t be using them.

Regarding changing textures, yah, I fiddled with Texture2D.ReadPixels and it seems, judging mainly by the slow speed, seems that each time you do a ReadPixels it does like the OpenGL glReadPixels(), reading from the backbuffer, across the graphics bus, into main memory. Then when you call Apply(), it then does the equivalent of glTexSubImage2D(), uploading across the graphics bus from main memory to the texture, except that it uploads the entire texture not just a portion.

To make it faster then, I’m trying to just keep the working copy of the textures in main memory (textures you create procedurally are readable anyway), and then only upload the changes (ie avoid the download). Still haven’t tested it yet, things to do.

I can certainly see the benefit of RenderTextures after being restricted to this slow stuff.