OpenGL - Should I store attributes / uniform locations?

What time is glGetUniformLocation and glGetAttribLocation ?

Which way is better?

  • Call glGetAttribLocation or glGetUniformLocation every time I need it?
  • Store locations in variables and use them if necessary?
+7
source share
3 answers

Whether on Android or iPhone, for an opengl surface you will have methods such as: onSurfaceCreated and onSurfaceChanged , get used to gaining shape and attributes here in these two methods.

The only way to speed up rendering (which will soon become your priority when your code crosses 1000 lines of code) is just gluseprogram, glbindbuffer, texture binding and other bindings inside the onDrawFrame method, always cache variables inside onSurfaceCreated and onSurfaceChanged

+5
source

Which way is better?

Think about it. No matter how fast glGetUniformLocation and glGetAttribLocation , they cannot be faster than just fetching a variable. Therefore, if you are concerned about performance, use a method that is always faster.

+8
source

According to my tests, sampling such places took about 100 ~ 200 times the time it takes for one glDrawElements call. This is only an estimate based on System.nanoTime() , but I think it’s a little economical to say that it is worth storing them in variables during initialization.

+3
source

All Articles