admin管理员组文章数量:1323714
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?
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?
Share Improve this question asked Jun 19, 2012 at 19:13 EdwardEdward 1,8261 gold badge16 silver badges33 bronze badges4 Answers
Reset to default 4JavaScript has had multiline strings in all browsers except IE since about 2009.
var shader = `
code
goes
here
`;
Use a single string per line and then join them together, e.g.
var shader = [
"// line1 ",
"// line2 ",
].join('\n');
P.S. The general problem was discussed here before, see Creating multiline strings in JavaScript
I ended up hacking this: http://github./noteed/language-glsl/ into a code pactor,
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.
This is the way NetBeans handle the case:
var shader =
"firstLine\n\
secondLine\n\
thirdLine";
I found this way more efficient for editing than having to create an array item for each line.
本文标签: Inline webgl shader code in javascriptStack Overflow
版权声明:本文标题:Inline webgl shader code in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742126964a2421986.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论