[orx-no-clear] Add multisampling support (#235)

This commit is contained in:
Vechro
2022-06-09 14:23:22 +03:00
committed by GitHub
parent 82ad35bd42
commit ac5b414f17

View File

@@ -3,15 +3,13 @@ package org.openrndr.extra.noclear
import org.openrndr.Extension
import org.openrndr.Program
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.Drawer
import org.openrndr.draw.RenderTarget
import org.openrndr.draw.isolated
import org.openrndr.draw.renderTarget
import org.openrndr.draw.*
import org.openrndr.math.Matrix44
class NoClear : Extension {
class NoClear(val multisample: BufferMultisample = BufferMultisample.Disabled) : Extension {
override var enabled: Boolean = true
private var renderTarget: RenderTarget? = null
private var resolvedColorBuffer: ColorBuffer? = null
/**
* code-block to draw an optional custom backdrop
@@ -26,11 +24,17 @@ class NoClear : Extension {
it.detachColorAttachments()
it.destroy()
}
renderTarget = renderTarget(program.width, program.height, program.window.contentScale) {
renderTarget = renderTarget(program.width, program.height, program.window.contentScale, multisample) {
colorBuffer()
depthBuffer()
}
if (multisample != BufferMultisample.Disabled) {
resolvedColorBuffer?.destroy()
resolvedColorBuffer = colorBuffer(program.width, program.height, program.window.contentScale)
}
renderTarget?.let {
drawer.withTarget(it) {
clear(program.backgroundColor ?: ColorRGBa.TRANSPARENT)
@@ -50,7 +54,12 @@ class NoClear : Extension {
drawer.ortho()
drawer.view = Matrix44.IDENTITY
drawer.model = Matrix44.IDENTITY
drawer.image(it.colorBuffer(0))
if (multisample != BufferMultisample.Disabled) {
it.colorBuffer(0).copyTo(resolvedColorBuffer!!)
drawer.image(resolvedColorBuffer!!)
} else {
drawer.image(it.colorBuffer(0))
}
}
}
}