将着色器源与应用程序捆绑在一起?

发布于 2024-11-05 04:11:44 字数 244 浏览 1 评论 0原文

我只是想知道如何将我的 GLSL 着色器源文件(对于 OpenGL ES(iOs)/OpenGL with GLUT (Mac/Windows))与我的应用程序捆绑在一起。作为纯文本文件,我的软件的每个用户都可以轻松更改它们,并且我担心未定义的行为...... 在 iOS 上,我只需为我的着色器使用 XCodes“复制捆绑资源”(然后从应用程序捆绑中检索它们) - Visual Studio 是否有类似的可能性?

或者是否有更好的跨平台方式来做到这一点?

I've just wondering how to bundle my GLSL shader source files (for OpenGL ES(iOs)/OpenGL with GLUT (Mac/Windows)) with my application. As pure text files, they would be easily changeable by every user of my software and I'm afraid of undefined behavior...
On iOS I simply use XCodes "Copy Bundle Ressources" for my shaders (and retrieve them then from the Application Bundle) - is there a similiar possibility with Visual Studio?

Or ist there even a better cross plattform way, to do so?

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

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

发布评论

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

评论(2

睡美人的小仙女 2024-11-12 04:11:44

GLSL 着色器是纯文本文件(或文本片段,无论您想以何种方式查看)。没有任何方法(除了对着色器进行数字签名并在签名不匹配时拒绝运行)来阻止用户在文本编辑器中随意修改着色器。 (当然,您可以通过对它们进行 rot13 编码或将它们全部放入 .zip 文件并将 .zip 文件重命名为其他文件来使它们变得不可读,这不会阻止有人决心找到您的着色器这样做,但是它可能会阻止 90% 的普通用户。)

但话又说回来,如果人们确实编辑了您的着色器并导致未定义的行为......对他们来说运气不好。您知道,有一部分人感到强烈要求编辑人类可读和可编辑的所有内容。好吧,如果他们破坏了安装,那是他们的问题。你无法阻止人们变得愚蠢。

最新版本的 OpenGL 上有着色器二进制扩展,但它的使用方式并不能解决您的问题。它只是作为一种缓存机制来加快后续运行的编译/链接时间。它不适合分发“着色器二进制文件”。

GLSL shaders are pure text files (or text snippets, whatever way you want to look at it). There is no way (apart from digitally signing your shaders and refusing to run if the signature does not match) to prevent a user from trivially modifying your shaders in a text editor. (Of course you could make them kind of unreadable by rot13-encoding them or by putting them all into a .zip file and renaming the .zip file to something else, this will not prevent someone determined to find your shaders from doing so, but it will probably deter 90% of the average users.)

But then again, if people do edit your shaders and that results in undefined behaviour... bad luck for them. You know, there is a certain faction of people who feels urged to edit everything that is human readable and editable. Fine, it's their problem if they break their install. You can't prevent people from being stupid.

There is the shader binary extension on recent versions of OpenGL, but it is not intended to be used in a way that would solve your problem. It is merely intended as a caching mechanism to speed up compile/link times on subsequent runs. It is not suited to distribute "shader binaries".

浅忆流年 2024-11-12 04:11:44

正如您所知,即使在 OSX 上,着色器也是“纯文本”,应用程序包也是一个普通目录,其中包含放置着色器的 Resource/ 文件夹。

Just so you know, even on OSX the shaders are in "pure text", the application bundle is a normal directory that includes a Resource/ folder where your shaders are placed.

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