我找不到任何明确说明这一点的地方,但我可以这样做:
unsigned int someUniform = 0;
unsigned int anotherUniform = 0;
glUseProgram(1);
someUniform = glGetUniformLocation(1, "uniformLocation");
glUniform3f(someUniform, 1, 1, 1);
glUseProgram(2);
anotherUniform = glGetUniformLocation(2, "anotherUniform");
glUniform3f(anotherUniform, 1, 1, 1);
在下一帧中,我只是调用:
glUseProgram(1);
glUniform3f(someUniform, 1, 1, 1);
glUseProgram(2);
glUniform3f(anotherUniform, 1, 1, 1);
我测试了一下,它确实保持不变,但我只有两个程序,我不认为我称之为复杂。
我是否需要每帧都获取uniformLocation,还是可以一次找到它的位置并确保它始终相同?