2019-08-17 17:35:48 +02:00
|
|
|
tool
|
2019-08-25 23:27:07 +02:00
|
|
|
extends MMGenTexture
|
2019-07-31 20:53:00 +02:00
|
|
|
class_name MMGenBuffer
|
2019-08-17 17:35:48 +02:00
|
|
|
|
2019-08-25 23:27:07 +02:00
|
|
|
"""
|
|
|
|
Texture generator buffers, that render their input in a specific resolution and provide the result as output.
|
2019-10-20 16:22:06 +02:00
|
|
|
This is useful when using generators that sample their inputs several times (such as convolutions)
|
2019-08-25 23:27:07 +02:00
|
|
|
"""
|
2019-08-18 16:28:50 +02:00
|
|
|
|
2019-09-14 09:14:27 +02:00
|
|
|
var updated : bool = false
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _ready() -> void:
|
2019-08-17 17:35:48 +02:00
|
|
|
if !parameters.has("size"):
|
2019-10-21 23:58:14 +02:00
|
|
|
parameters.size = 9
|
2019-08-17 17:35:48 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_type() -> String:
|
2019-08-17 17:35:48 +02:00
|
|
|
return "buffer"
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_type_name() -> String:
|
2019-08-17 17:35:48 +02:00
|
|
|
return "Buffer"
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_parameter_defs() -> Array:
|
2019-10-20 20:16:48 +02:00
|
|
|
return [ { name="size", type="size", first=4, last=12, default=4 } ]
|
2019-08-17 17:35:48 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_input_defs() -> Array:
|
2019-08-18 16:28:50 +02:00
|
|
|
return [ { name="in", type="rgba" } ]
|
2019-10-20 16:22:06 +02:00
|
|
|
|
|
|
|
func get_output_defs() -> Array:
|
2019-09-11 07:53:06 +02:00
|
|
|
return [ { type="rgba" } ]
|
2019-08-17 17:35:48 +02:00
|
|
|
|
2019-09-22 22:17:26 +02:00
|
|
|
func source_changed(input_port_index : int):
|
2019-09-14 09:14:27 +02:00
|
|
|
updated = false
|
2019-09-22 22:17:26 +02:00
|
|
|
.source_changed(input_port_index)
|
2019-09-14 09:14:27 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -> Dictionary:
|
2019-08-18 16:28:50 +02:00
|
|
|
var source = get_source(0)
|
2019-09-14 09:14:27 +02:00
|
|
|
if source != null and !updated:
|
2019-10-21 23:58:14 +02:00
|
|
|
var result = source.generator.render(source.output_index, context.renderer, pow(2, parameters.size))
|
2019-10-05 11:04:50 +02:00
|
|
|
while result is GDScriptFunctionState:
|
|
|
|
result = yield(result, "completed")
|
|
|
|
result.copy_to_texture(texture)
|
|
|
|
result.release()
|
|
|
|
texture.flags = 0
|
|
|
|
updated = true
|
2019-08-25 23:27:07 +02:00
|
|
|
var rv = ._get_shader_code(uv, output_index, context)
|
|
|
|
while rv is GDScriptFunctionState:
|
|
|
|
rv = yield(rv, "completed")
|
|
|
|
return rv
|
2019-09-09 22:00:18 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _serialize(data: Dictionary) -> Dictionary:
|
2019-09-09 22:00:18 +02:00
|
|
|
data.type = "buffer"
|
|
|
|
return data
|