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) return random.item(sources)
} }
static parseUniforms (shader) { match (shader, regex, group = 1) {
let names = [] let matches = []
let result = shader.match(/uniform \w+ \w+(?=;)/gm) let match
if (result) { while (match = regex.exec(shader)) {
result.forEach((v) => names.push(v.split(' ').pop())) matches.push(match[group])
} }
return names return matches
} }
static parseAttributes (shader) { static parseUniforms (shader, group = 1) {
let names = [] /* Todo: Parse their individual data types into categories. */
let result = shader.match(/attribute \w+ \w+(?=;)/gm) return match(shader, /uniform .+? (\w+)(?=[\[;])/gm, group)
if (result) {
result.forEach((v) => names.push(v.split(' ').pop()))
}
return names
} }
static parseFrag (shader) { static parseAttributes (shader, group = 1) {
return shader.match(/(gl_Frag[^[ =]+)/gm) 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 () { static randomBitmask () {