[orx-compute-graph] Add compute graph code

This commit is contained in:
Edwin Jakobs
2022-01-09 10:51:21 +01:00
parent 9d08f859fa
commit 0858b8455c
11 changed files with 629 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
package org.openrndr.extra.computegraph.nodes
import org.openrndr.draw.ColorBuffer
import org.openrndr.draw.Filter
import org.openrndr.draw.createEquivalent
import org.openrndr.extra.computegraph.ComputeGraph
import org.openrndr.extra.computegraph.ComputeNode
import org.openrndr.extra.computegraph.withKey
fun <T : Filter> ComputeGraph.filterNode(
filter: T, input: ComputeNode, inputKey: String = "image", outputKey: String = "image",
config: ComputeNode.(f: Filter) -> Unit
): ComputeNode {
return node {
name = "filter-${filter::class.simpleName}"
inputs = filter.parameters
config(filter)
val inputImage by input.outputs.withKey<ColorBuffer>(inputKey)
var outputImage by outputs.withKey<ColorBuffer>(outputKey)
outputImage = inputImage.createEquivalent()
compute {
filter.apply(inputImage, outputImage)
}
dependOn(input)
}
}

View File

@@ -0,0 +1,29 @@
package org.openrndr.extra.computegraph.nodes
import org.openrndr.Program
import org.openrndr.draw.ColorBuffer
import org.openrndr.draw.isolatedWithTarget
import org.openrndr.draw.renderTarget
import org.openrndr.extra.computegraph.ComputeGraph
import org.openrndr.extra.computegraph.ComputeNode
import org.openrndr.extra.computegraph.withKey
import org.openrndr.extras.imageFit.imageFit
fun ComputeGraph.fitImageNode(program: Program, input: ComputeNode) : ComputeNode {
return node {
name = "fit-image"
val rt = renderTarget(program.width, program.height) {
colorBuffer()
}
val inputImage: ColorBuffer by input.outputs.withKey("image")
var outputImage:ColorBuffer by outputs.withKey("image")
outputImage = rt.colorBuffer(0)
compute {
program.drawer.isolatedWithTarget(rt) {
ortho(rt)
imageFit(inputImage, bounds)
}
}
dependOn(input)
}
}