值得在代码中缓存glsl统一位置吗? [英] Is it worth caching glsl uniform location in code?

查看:103
本文介绍了值得在代码中缓存glsl统一位置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够通过着色器中的实际名称设置制服

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 

或者也许OpenGL(在桌面上)仍然可以缓存,所以我不会有任何性能差异吗?

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

推荐答案

OpenGL规范定义功能而不是性能.因此,没有办法知道任何特定的OpenGL实现如何存储活动制服列表或相对于std::map性能glGetUniformLocation有多快.

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.

实际上,这取决于您.如果您要获得一致的,已知的性能,请自己进行.如果您想尝试一下OpenGL实现的各种变化,请随时进行查询.就个人而言,我会说出沟渠的名字,然后加上位置.这样,您可以获得最佳性能.

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.

这篇关于值得在代码中缓存glsl统一位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆