[orx-no-clear] Add multisampling support (#235)
This commit is contained in:
@@ -3,15 +3,13 @@ package org.openrndr.extra.noclear
|
|||||||
import org.openrndr.Extension
|
import org.openrndr.Extension
|
||||||
import org.openrndr.Program
|
import org.openrndr.Program
|
||||||
import org.openrndr.color.ColorRGBa
|
import org.openrndr.color.ColorRGBa
|
||||||
import org.openrndr.draw.Drawer
|
import org.openrndr.draw.*
|
||||||
import org.openrndr.draw.RenderTarget
|
|
||||||
import org.openrndr.draw.isolated
|
|
||||||
import org.openrndr.draw.renderTarget
|
|
||||||
import org.openrndr.math.Matrix44
|
import org.openrndr.math.Matrix44
|
||||||
|
|
||||||
class NoClear : Extension {
|
class NoClear(val multisample: BufferMultisample = BufferMultisample.Disabled) : Extension {
|
||||||
override var enabled: Boolean = true
|
override var enabled: Boolean = true
|
||||||
private var renderTarget: RenderTarget? = null
|
private var renderTarget: RenderTarget? = null
|
||||||
|
private var resolvedColorBuffer: ColorBuffer? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* code-block to draw an optional custom backdrop
|
* code-block to draw an optional custom backdrop
|
||||||
@@ -26,11 +24,17 @@ class NoClear : Extension {
|
|||||||
it.detachColorAttachments()
|
it.detachColorAttachments()
|
||||||
it.destroy()
|
it.destroy()
|
||||||
}
|
}
|
||||||
renderTarget = renderTarget(program.width, program.height, program.window.contentScale) {
|
|
||||||
|
renderTarget = renderTarget(program.width, program.height, program.window.contentScale, multisample) {
|
||||||
colorBuffer()
|
colorBuffer()
|
||||||
depthBuffer()
|
depthBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (multisample != BufferMultisample.Disabled) {
|
||||||
|
resolvedColorBuffer?.destroy()
|
||||||
|
resolvedColorBuffer = colorBuffer(program.width, program.height, program.window.contentScale)
|
||||||
|
}
|
||||||
|
|
||||||
renderTarget?.let {
|
renderTarget?.let {
|
||||||
drawer.withTarget(it) {
|
drawer.withTarget(it) {
|
||||||
clear(program.backgroundColor ?: ColorRGBa.TRANSPARENT)
|
clear(program.backgroundColor ?: ColorRGBa.TRANSPARENT)
|
||||||
@@ -50,8 +54,13 @@ class NoClear : Extension {
|
|||||||
drawer.ortho()
|
drawer.ortho()
|
||||||
drawer.view = Matrix44.IDENTITY
|
drawer.view = Matrix44.IDENTITY
|
||||||
drawer.model = Matrix44.IDENTITY
|
drawer.model = Matrix44.IDENTITY
|
||||||
|
if (multisample != BufferMultisample.Disabled) {
|
||||||
|
it.colorBuffer(0).copyTo(resolvedColorBuffer!!)
|
||||||
|
drawer.image(resolvedColorBuffer!!)
|
||||||
|
} else {
|
||||||
drawer.image(it.colorBuffer(0))
|
drawer.image(it.colorBuffer(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user