Built-in webgl shader code in javascript

I am writing a simple Javascript library that uses some WebGL code. I would like to include the inline shader sources in the .js file because my alternatives should include them as script tags on each page or have them as separate files that load as AJAX. None of these options are particularly modular. However, due to the lack of multi-line strings in javascript, I have no good ideas on how to embed WebGL code. Is there an approach that I don't think about?

+5
source share
4 answers

I ended up hacking this: http://github.com/noteed/language-glsl/ into code compaction, replacing all instances vcatwith hsepin in Language.GLSL.Pretty. I get a single line version of the shader code that I have in the file, which can then be inserted into a line. I was hoping to find a similar solution already made when I posted this.

+1
source

Use one line per line and then combine them, for example.

var shader = [
   "// line1 ",
   "// line2 ",
].join('\n');

PS A common problem has been discussed here before; see Creating multi-line strings in JavaScript

+3
source

NetBeans :

var shader = 
"firstLine\n\
secondLine\n\
thirdLine";

, .

0

JavaScript , IE, 2009 .

var shader = `
code
goes
here
`;
0

All Articles