Pass a String to the shader directive parser functions instead of Shader
This commit is contained in:
parent
6c1ec9ed2c
commit
885cfbf3bc
2 changed files with 9 additions and 9 deletions
|
@ -34,13 +34,13 @@ func inject_step_uniform(shader_code: String) -> Shader:
|
||||||
func update() -> Array: # returns error messages (strings)
|
func update() -> Array: # returns error messages (strings)
|
||||||
# inject STEP uniform & get number of steps
|
# inject STEP uniform & get number of steps
|
||||||
var shader: Shader = inject_step_uniform(Filesystem.shader_code)
|
var shader: Shader = inject_step_uniform(Filesystem.shader_code)
|
||||||
var step: int = ShaderDirectiveParser.parse_steps_directive(shader)
|
var step: int = ShaderDirectiveParser.parse_steps_directive(shader.code)
|
||||||
# validate shader
|
# validate shader
|
||||||
if not validate_shader_compilation(shader):
|
if not validate_shader_compilation(shader):
|
||||||
return ["Shader compilation failed!"]
|
return ["Shader compilation failed!"]
|
||||||
var errors = []
|
var errors = []
|
||||||
# load texture(s) from //!load directive -> TEXTURE
|
# load texture(s) from //!load directive -> TEXTURE
|
||||||
var m = ShaderDirectiveParser.parse_load_directive(shader)
|
var m = ShaderDirectiveParser.parse_load_directive(shader.code)
|
||||||
if len(m) < 1:
|
if len(m) < 1:
|
||||||
errors.append("Didn't find a load directive!")
|
errors.append("Didn't find a load directive!")
|
||||||
return errors
|
return errors
|
||||||
|
@ -55,7 +55,7 @@ func update() -> Array: # returns error messages (strings)
|
||||||
return errors
|
return errors
|
||||||
# ... from //!load+ directives
|
# ... from //!load+ directives
|
||||||
Filesystem.clear_additional_images()
|
Filesystem.clear_additional_images()
|
||||||
for n in ShaderDirectiveParser.parse_load_additional_directive(shader):
|
for n in ShaderDirectiveParser.parse_load_additional_directive(shader.code):
|
||||||
err = Filesystem.load_additional_image(n[1], Filesystem.get_absolute_path(n[2]))
|
err = Filesystem.load_additional_image(n[1], Filesystem.get_absolute_path(n[2]))
|
||||||
if err != "":
|
if err != "":
|
||||||
errors.append(err)
|
errors.append(err)
|
||||||
|
|
|
@ -4,20 +4,20 @@ var _load_regex: RegEx = RegEx.create_from_string(r'\/\/!load\s(.*)')
|
||||||
var _load_additional_regex: RegEx = RegEx.create_from_string(r'\/\/!load\+\s(\w*)\s(.*)')
|
var _load_additional_regex: RegEx = RegEx.create_from_string(r'\/\/!load\+\s(\w*)\s(.*)')
|
||||||
var _iterate_regex: RegEx = RegEx.create_from_string(r'\/\/!steps\s([0-9]+)\s*')
|
var _iterate_regex: RegEx = RegEx.create_from_string(r'\/\/!steps\s([0-9]+)\s*')
|
||||||
|
|
||||||
func parse_load_directive(shader: Shader) -> PackedStringArray:
|
func parse_load_directive(shader_code: String) -> PackedStringArray:
|
||||||
var regex_match = self._load_regex.search(shader.code)
|
var regex_match = self._load_regex.search(shader_code)
|
||||||
if regex_match == null:
|
if regex_match == null:
|
||||||
return []
|
return []
|
||||||
return regex_match.strings
|
return regex_match.strings
|
||||||
|
|
||||||
func parse_load_additional_directive(shader: Shader) -> Array[PackedStringArray]:
|
func parse_load_additional_directive(shader_code: String) -> Array[PackedStringArray]:
|
||||||
var results : Array[PackedStringArray] = []
|
var results : Array[PackedStringArray] = []
|
||||||
for m in self._load_additional_regex.search_all(shader.code):
|
for m in self._load_additional_regex.search_all(shader_code):
|
||||||
results.append(m.strings)
|
results.append(m.strings)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
func parse_steps_directive(shader: Shader) -> int:
|
func parse_steps_directive(shader_code: String) -> int:
|
||||||
var regex_match = self._iterate_regex.search(shader.code)
|
var regex_match = self._iterate_regex.search(shader_code)
|
||||||
if regex_match == null:
|
if regex_match == null:
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue