Inline webgl shader code in javascript

故事扮演 提交于 2019-12-04 08:47:44
Stefan Haustein

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

JavaScript has had multiline strings in all browsers except IE since about 2009.

var shader = `
code
goes
here
`;

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!