Added orx-filter-extension

- Bumped version to 0.0.11
This commit is contained in:
Edwin Jakobs
2018-11-10 12:55:00 +01:00
parent 72c71eb812
commit 5d46c2ad02
5 changed files with 89 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
A growing library of assorted data structures, algorithms and utilities.
- [`orx-compositor`](orx-compositor/README.md), a simple toolkit to make composite (layered) images
- [`orx-filter-extension`](orx-filter-extension/README.md), Program extension method that provides Filter based `extend()`
- [`orx-integral-image`](orx-integral-image/README.md), a CPU-based implementation for integral images (summed area tables)
- `orx-jumpflood`, a filter/shader based implementation of the jump flood algorithm for finding fast approximate (directional) distance fields
- `orx-kdtree`, a kd-tree implementation for fast nearest point searches
@@ -23,13 +24,13 @@ repositories {
You can then add any of the ORX artefacts to your `dependencies {}`:
```
dependencies {
compile 'com.github.openrndr.orx:<orx-artifact>:v0.0.9'
compile 'com.github.openrndr.orx:<orx-artifact>:v0.0.11'
}
```
For example if you want to use the `orx-no-clear` artifact one would use:
```
dependencies {
compile 'com.github.openrndr.orx:orx-no-clear:v0.0.9'
compile 'com.github.openrndr.orx:orx-no-clear:v0.0.11'
}
```

View File

@@ -4,7 +4,7 @@ plugins {
allprojects {
group 'org.openrndr.extra'
version '0.0.10'
version '0.0.11'
}
repositories {

View File

@@ -0,0 +1,21 @@
# orx-filter-extension
Provides extension methods for Program that can be used to provide Filters to the `extend()` mechanism
##### API
```kotlin
fun <F : Filter> Program.extend(filter: F, configuration: F.() -> Unit = {}): Extension
```
##### Usage
```kotlin
fun main() = application {
program {
extend(FXAA()) {
// this function is executed every frame
}
}
}
```

View File

@@ -0,0 +1,61 @@
package org.openrndr.extra.filterextension
import org.openrndr.Extension
import org.openrndr.Program
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
/**
* Extends the [Program] with a [Filter]. This is achieved by wrapping the Filter in an Extension.
*/
fun <F : Filter> Program.extend(filter: F, configuration: F.() -> Unit = {}): Extension {
val filterExtension = object : Extension {
override var enabled: Boolean = true
var renderTarget: RenderTarget? = null
var filtered: ColorBuffer? = null
override fun beforeDraw(drawer: Drawer, program: Program) {
if (renderTarget == null || renderTarget?.width != program.width || renderTarget?.height != program.height) {
renderTarget?.let {
it.colorBuffer(0).destroy()
it.detachColorBuffers()
it.destroy()
}
filtered?.destroy()
renderTarget = renderTarget(program.width, program.height) {
colorBuffer()
depthBuffer()
}
filtered = colorBuffer(program.width, program.height)
renderTarget?.let {
drawer.withTarget(it) {
background(program.backgroundColor ?: ColorRGBa.TRANSPARENT)
}
}
}
renderTarget?.bind()
}
override fun afterDraw(drawer: Drawer, program: Program) {
renderTarget?.unbind()
filter.configuration()
renderTarget?.let {
filtered?.let { filtered ->
drawer.isolated {
drawer.ortho()
filter.apply(it.colorBuffer(0), filtered)
drawer.image(filtered)
}
}
}
}
}
return extend(filterExtension)
}

View File

@@ -1,8 +1,11 @@
rootProject.name = 'orx'
include 'orx-compositor',
'orx-filter-extension',
'orx-integral-image',
'orx-jumpflood',
'orx-kdtree',
'orx-no-clear'