Are glGetUniformLocation
and glGetAttribLocation
time consuming?
Which way is better?
glGetAttribLocation
or glGetUniformLocation
every time I need it ?Which way is better?
Think about it. No matter how fast glGetUniformLocation
and glGetAttribLocation
are, they cannot be faster than just fetching a variable. So if you are concerned about performance, then use the method that is always faster.
According to my tests, fetching such locations took about 100~200 times the amount of time that it takes for a single glDrawElements
call. This is only an estimate based on System.nanoTime()
, but I think it's save to say that it's worth storing them in variables on initialization.
Whether on Android or iPhone, for an opengl surface you will have methods like: onSurfaceCreated and onSurfaceChanged, get into the habit of fetching uniforms and attributes here in these 2 methods.
The only way you can make rendering faster (which will soon become your priority when your code crosses 1000 lines of code) is by only having gluseprogram, glbindbuffer, texture binds and other binds inside onDrawFrame method, always cache variables inside onSurfaceCreated and onSurfaceChanged
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With