Add intermediate cache for ApproximateGaussianBlur
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
package org.openrndr.extra.fx.blur
|
package org.openrndr.extra.fx.blur
|
||||||
|
|
||||||
import org.openrndr.draw.ColorBuffer
|
import org.openrndr.draw.*
|
||||||
import org.openrndr.draw.Filter
|
|
||||||
import org.openrndr.draw.Shader
|
|
||||||
import org.openrndr.draw.colorBuffer
|
|
||||||
import org.openrndr.extra.fx.filterFragmentCode
|
import org.openrndr.extra.fx.filterFragmentCode
|
||||||
|
|
||||||
import org.openrndr.math.Vector2
|
import org.openrndr.math.Vector2
|
||||||
@@ -14,6 +11,9 @@ import org.openrndr.math.Vector2
|
|||||||
class ApproximateGaussianBlur : Filter(Shader.createFromCode(Filter.filterVertexCode,
|
class ApproximateGaussianBlur : Filter(Shader.createFromCode(Filter.filterVertexCode,
|
||||||
filterFragmentCode("blur/approximate-gaussian-blur.frag"))) {
|
filterFragmentCode("blur/approximate-gaussian-blur.frag"))) {
|
||||||
|
|
||||||
|
data class ColorBufferDescription(val width:Int, val height:Int, val contentScale:Double, val format:ColorFormat, val type:ColorType)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* blur sample window, default value is 5
|
* blur sample window, default value is 5
|
||||||
*/
|
*/
|
||||||
@@ -35,7 +35,8 @@ class ApproximateGaussianBlur : Filter(Shader.createFromCode(Filter.filterVertex
|
|||||||
var gain: Double by parameters
|
var gain: Double by parameters
|
||||||
|
|
||||||
|
|
||||||
private var intermediate: ColorBuffer? = null
|
private var intermediateCache = mutableMapOf<ColorBufferDescription, ColorBuffer>()
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
window = 5
|
window = 5
|
||||||
@@ -45,14 +46,9 @@ class ApproximateGaussianBlur : Filter(Shader.createFromCode(Filter.filterVertex
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
|
override fun apply(source: Array<ColorBuffer>, target: Array<ColorBuffer>) {
|
||||||
intermediate?.let {
|
val intermediateDescription = ColorBufferDescription(target[0].width, target[0].height, target[0].contentScale, target[0].format, target[0].type)
|
||||||
if (it.width != target[0].width || it.height != target[0].height) {
|
val intermediate = intermediateCache.getOrPut(intermediateDescription) {
|
||||||
intermediate = null
|
colorBuffer(target[0].width, target[0].height, target[0].contentScale, target[0].format, target[0].type)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (intermediate == null) {
|
|
||||||
intermediate = colorBuffer(target[0].width, target[0].height, target[0].contentScale, target[0].format, target[0].type)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
intermediate?.let {
|
intermediate?.let {
|
||||||
|
|||||||
Reference in New Issue
Block a user