16 Bit int to save uniform location

Hello,

to prevent glGetUniformLocation calls for every uniform and every frame, I want to save the uniform location to an unsigned int (after checking for -1 error). It would be very convenient to save this location as 16 Bit wide integer. The OpenGL specification tells me that the return value is 32 Bit wide. Now my question: Is it (very) problematic to use a 16 Bit unsigned int to do this? Do more than 2^16 uniform location even get used (by a rather small app)? Is it possible that the returned int is bigger than 2^16 despite “free” locations < 2^16?

Thanks!

Implementations are free to pick locations in what ever way they want, so yes it’s possible to get large values. In practice the location will usually be some kind of index or offset into storage for uniforms, hence a smallish number. That being said, consider what kind of micro optimization you are doing by using only 16 bit, how many shaders and uniforms do you expect to have? How much memory does this save you? Is it worth your time to even worry about it? :wink: :wink: