Added orx-filter-extension
- Bumped version to 0.0.11
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
A growing library of assorted data structures, algorithms and utilities.
|
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-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-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-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
|
- `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 {}`:
|
You can then add any of the ORX artefacts to your `dependencies {}`:
|
||||||
```
|
```
|
||||||
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:
|
For example if you want to use the `orx-no-clear` artifact one would use:
|
||||||
```
|
```
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.github.openrndr.orx:orx-no-clear:v0.0.9'
|
compile 'com.github.openrndr.orx:orx-no-clear:v0.0.11'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ plugins {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group 'org.openrndr.extra'
|
group 'org.openrndr.extra'
|
||||||
version '0.0.10'
|
version '0.0.11'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
21
orx-filter-extension/README.md
Normal file
21
orx-filter-extension/README.md
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
61
orx-filter-extension/src/main/kotlin/FilterExtension.kt
Normal file
61
orx-filter-extension/src/main/kotlin/FilterExtension.kt
Normal 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)
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
rootProject.name = 'orx'
|
rootProject.name = 'orx'
|
||||||
|
|
||||||
include 'orx-compositor',
|
include 'orx-compositor',
|
||||||
|
'orx-filter-extension',
|
||||||
'orx-integral-image',
|
'orx-integral-image',
|
||||||
'orx-jumpflood',
|
'orx-jumpflood',
|
||||||
'orx-kdtree',
|
'orx-kdtree',
|
||||||
'orx-no-clear'
|
'orx-no-clear'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user