Fix regex for parsing uniforms, attributes, varyings

This commit is contained in:
Christoph Diehl 2018-05-10 08:56:29 +02:00
parent 6079e9b428
commit 60a7b65cdf
No known key found for this signature in database
GPG Key ID: 799CE5B68FEF404A
1 changed files with 33 additions and 15 deletions

View File

@ -57,26 +57,44 @@ class webgl extends make {
return random.item(sources)
}
static parseUniforms (shader) {
let names = []
let result = shader.match(/uniform \w+ \w+(?=;)/gm)
if (result) {
result.forEach((v) => names.push(v.split(' ').pop()))
match (shader, regex, group = 1) {
let matches = []
let match
while (match = regex.exec(shader)) {
matches.push(match[group])
}
return names
return matches
}
static parseAttributes (shader) {
let names = []
let result = shader.match(/attribute \w+ \w+(?=;)/gm)
if (result) {
result.forEach((v) => names.push(v.split(' ').pop()))
}
return names
static parseUniforms (shader, group = 1) {
/* Todo: Parse their individual data types into categories. */
return match(shader, /uniform .+? (\w+)(?=[\[;])/gm, group)
}
static parseFrag (shader) {
return shader.match(/(gl_Frag[^[ =]+)/gm)
static parseAttributes (shader, group = 1) {
return match(shader, /attribute .+? (\w+)(?=;)/gm, group)
}
static parseVaryings (shader, group = 1) {
return match(shader, /varying .+? (\w+)(?=;)/gm, group)
}
static parseFragDatav2 (shader, group = 1) {
// #version 200
return match(shader, /(gl_Frag[^[ =]+)/gm, group)
}
static parseFragDatav3 (shader, group = 1) {
// #version 300
return match(shader, /out .+? (\w+)(?=[\[;])/gm, group)
}
static parseFrag (shader, group = 1) {
let matches = parseFragDatav2(shader)
if (matches.length) {
return matches
}
return parseFragDatav3(shader)
}
static randomBitmask () {