tags:

views:

193

answers:

1

Hi!

It's well known that uniform and attributes are registers in GPU. And my question is what happens when different program bound? Does standard guarantee that previously set uniforms and/or attribute pointers will be reloaded or I need to reload them manually in any case? I want to create caching system. It seems for me that attributes are not reloaded (yes?) when program rebound and what about uniforms? Does GL ES driver reload their values for me?

Thanks.

+1  A: 

No, this is not well-known that uniforms and attributes are registers in the GPU. In fact, it is at least in one widely-employed OpenGL ES 2.0 GPU wrong.

A uniform is zero unless explicitly initialized. The uniform values are states that follows the program object. In other words, if you set a uniform on given program object, you CAN depend on the value being preserved across uses of the same program object, but you can not depend on a uniform at a given location being preserved across multiple program objects. In fact, an OpenGL ES implementation that does this, is in violation of the spec. This is not undefined behavior.

Attribute pointers are global context-state, and you CAN depend on these to be preserved between calls to the same OpenGL ES context. The same goes for current attribute values (set through the glVertexAttribute*-functions)

kusma
I found in OpenGL ES specification that "Uniforms are program object-specific state. They retain their values once loaded, and their values are restored whenever a program object is used, as long as the program object has not been re-linked". So I can left it unchanged if it's value remains the same.About attributes. My experimenting says different: if I skip glVertxAttribPointer when pointer and buffer are the same, visually I get something wrong or even black screen. But glGetError still OK.
demi
The part about uniforms is basically what I said. About attributes, are you sure the attributes you try to reuse have the same attribute locations? If not, you could try to use glBindAttribLocation before linking the program to make sure.
kusma
I wish I could +1 twice. one for the correct answer, 1 for the "registers" tidbit. Which GPU are you aware of that does not do it, btw ?
Bahbar
I'm not at liberty to tell, sorry.
kusma