Is it worth caching glsl uniform location in code?

对着背影说爱祢 提交于 2019-12-01 16:33:28

问题


I would like to have ability to set uniforms via their actual names in the shader

myProgram.uniform3fv("uniformVector", 0.0f, 0.1f, 1.0f);

do I have to cache locations in some form of a map?

std::map<std::string, unsigned int> // or unordered_map 

or maybe OpenGL (on desktop) caches this anyway, so I would not have any performance difference?


回答1:


The OpenGL specification defines functionality, not performance. So there's no way to know how any particular OpenGL implementation will store the list of active uniforms or how fast glGetUniformLocation will be, relative to std::map performance.

So really, it's up to you. If you want consistent, known performance, do it yourself. If you want to take a chance on the vagaries of the OpenGL implementation, then query it whenever you want. Personally, I'd say ditch names and go with locations. That way you get maximum performance.



来源:https://stackoverflow.com/questions/14724324/is-it-worth-caching-glsl-uniform-location-in-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!