[orx-view-box] Configure and activate the viewbox rendertarget on creation

This commit is contained in:
Edwin Jakobs
2023-01-20 10:58:19 +01:00
parent 4eeb7e4e07
commit b89312276a

View File

@@ -184,7 +184,7 @@ class ViewBox(
extensions.add(functionExtension) extensions.add(functionExtension)
} }
override fun draw() { fun configureRenderTarget(): RenderTarget {
val widthCeil = ceil(clientArea.width).toInt() val widthCeil = ceil(clientArea.width).toInt()
val heightCeil = ceil(clientArea.height).toInt() val heightCeil = ceil(clientArea.height).toInt()
@@ -225,6 +225,11 @@ class ViewBox(
) )
} }
} }
return renderTarget ?: error("could not create a render target")
}
override fun draw() {
configureRenderTarget()
if (viewBoxReconfigured || shouldDraw()) { if (viewBoxReconfigured || shouldDraw()) {
program.drawer.isolatedWithTarget(renderTarget!!) { program.drawer.isolatedWithTarget(renderTarget!!) {
@@ -271,6 +276,9 @@ fun Program.viewBox(
f: ViewBox.() -> Unit = {} f: ViewBox.() -> Unit = {}
): ViewBox { ): ViewBox {
val viewBox = ViewBox(this, area, translateMouse, translateKeyboard, colorType, contentScale, multisample) val viewBox = ViewBox(this, area, translateMouse, translateKeyboard, colorType, contentScale, multisample)
viewBox.f() val rt = viewBox.configureRenderTarget()
drawer.isolatedWithTarget(rt) {
viewBox.f()
}
return viewBox return viewBox
} }