一般如何使用着色器制服?

发布于 2024-07-26 11:40:31 字数 93 浏览 2 评论 0原文

着色器可以有许多不同的统一名称+属性。 如何制作一个在一般情况下工作的系统,以便我不必事先知道每个着色器制服的名称并将其硬编码为代码来获取其位置。 我使用OpenGL。

Shaders can have lots of different uniform names + attributes. How can I make a system which works in general case so that I do not have to know each shader uniform's name beforehand and hardcode it to code to get its location. I use OpenGL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愚人国度 2024-08-02 11:40:31

不幸的是,在某些时候,您需要知道着色器中的统一名称是什么,以及它们所指的是什么......这是没有办法解决的。

大多数图形/游戏引擎按惯例工作 - 某些制服由引擎设置,着色器根据需要使用它们。 有些会添加配置,因此每个着色器都可以指定它需要什么制服,但通常情况下,名称仍然按惯例完成。

Unfortunately, at some point, you'll need to know what the uniform names in the shader are, and what they refer to... there's just no way around that.

Most graphics/game engines work by convention - certain uniforms are set by the engine, and shaders use them as needed. Some will add configuration, so each shader can specify what uniforms it requires, but typically, the names are still done by convention.

巷雨优美回忆 2024-08-02 11:40:31

使用命名约定,或自行解析着色器字符串以获取类型、符号和可选存储说明符。 前一种选择将责任归于着色器程序员,而后一种解决方案将负担归于应用程序程序员。
通过使用扩展 GL _ ARB 可以使此类代码更加优雅和高效_uniform_buffer_object,在OpenGL 3.1中提升为核心

Use a naming convention, or parse the shader string yourself to get the type, symbol and optional storage specifier. The former option puts a responsibility on the shader programmer, while the latter solution puts the burden on the application programmer.
Such code can be made a lot more elegant and efficient by using the extension GL _ ARB _ uniform _ buffer _ object, which was promoted to core in OpenGL 3.1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文