在javascript中内联webgl着色器代码 [英] Inline webgl shader code in javascript

查看:130
本文介绍了在javascript中内联webgl着色器代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用一些WebGL代码的简单Javascript库。我想在.js文件中内嵌着色器源代码,因为我的选择是将它们作为脚本标记包含在每个页面中,或者将它们作为单独的文件加载为AJAX。这些选项都不是特别模块化的。但是,由于javascript中缺少多行字符串,我对如何内联WebGL代码没有任何好的想法。有没有一种我没想到的方法?

I'm writing a simple Javascript library that makes use of some WebGL code. I'd like to include the shader sources inline in the .js file, because my alternatives are to include them as script tags in each page, or to have them as separate files which are loaded as AJAX. Neither of these options are particularly modular. However, due to the lack of multi-line strings in javascript, I don't have any good ideas for how to inline the WebGL code. Is there an approach I'm not thinking of?

推荐答案

我最终破解了这个: http://github.com/noteed/language-glsl/ 到代码压缩器,
通过替换所有实例在Language.GLSL.Pretty中使用 hsep vcat 。我得到一个文件中的着色器代码的单行版本,然后我可以粘贴到一个字符串中。当我发布这个时,我希望找到一个类似的解决方案。

I ended up hacking this: http://github.com/noteed/language-glsl/ into a code compactor, by replacing all instances of vcat with hsep in Language.GLSL.Pretty. I get a one-line version of the shader code I have in a file, that I can then just paste into a string. I was hoping to find a similar solution already done when I posted this.

这篇关于在javascript中内联webgl着色器代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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