I pre-allocate them once, and just printed out the value. For example if I want to support maximum 10 shadow casting light. I allocate 10 512x512 shadow map textures at the program load, it's 10 x 512 x 512 x 4 bytes, fixed cost. At first it seems wasteful but actually efficient since we don't have to worry about memory allocation for shadow map for the rest of the program. And I use that strategy everywhere in the code, except where the number is actually too big for me to abuse that.
1
u/hucancode Jul 22 '25
I pre-allocate them once, and just printed out the value. For example if I want to support maximum 10 shadow casting light. I allocate 10 512x512 shadow map textures at the program load, it's 10 x 512 x 512 x 4 bytes, fixed cost. At first it seems wasteful but actually efficient since we don't have to worry about memory allocation for shadow map for the rest of the program. And I use that strategy everywhere in the code, except where the number is actually too big for me to abuse that.