@@ -12,23 +12,6 @@ import org.openrndr.extra.parameters.BooleanParameter
12
12
import org.openrndr.extra.parameters.Description
13
13
import kotlin.jvm.JvmRecord
14
14
15
- fun RenderTarget.deepDestroy () {
16
- val cbcopy = colorAttachments.map { it }
17
- val dbcopy = depthBuffer
18
- detachDepthBuffer()
19
- detachColorAttachments()
20
- cbcopy.forEach {
21
- when (it) {
22
- is ColorBufferAttachment -> it.colorBuffer.destroy()
23
- is CubemapAttachment -> it.cubemap.destroy()
24
- is ArrayTextureAttachment -> it.arrayTexture.destroy()
25
- is ArrayCubemapAttachment -> it.arrayCubemap.destroy()
26
- else -> {}
27
- }
28
- }
29
- dbcopy?.destroy()
30
- destroy()
31
- }
32
15
33
16
enum class LayerType {
34
17
LAYER ,
@@ -185,7 +168,7 @@ open class Layer internal constructor(
185
168
private fun createLayerTarget (
186
169
activeRenderTarget : RenderTarget , drawer : Drawer , bufferMultisample : BufferMultisample
187
170
) {
188
- layerTarget?.deepDestroy ()
171
+ layerTarget?.destroy ()
189
172
layerTarget = renderTarget(
190
173
activeRenderTarget.width, activeRenderTarget.height,
191
174
activeRenderTarget.contentScale, bufferMultisample
@@ -348,37 +331,31 @@ class ColorBufferCache(val width: Int, val height: Int) {
348
331
}
349
332
}
350
333
351
- class Composite : Layer (LayerType .LAYER ) {
352
-
334
+ class Composite (val session : Session ? ) : Layer(LayerType .LAYER ), AutoCloseable {
353
335
private var cache = ColorBufferCache (RenderTarget .active.width, RenderTarget .active.height)
354
336
fun draw (drawer : Drawer ) {
355
337
338
+ session?.push()
356
339
if (cache.width != RenderTarget .active.width || cache.height != RenderTarget .active.height) {
357
340
cache.destroy()
358
341
cache = ColorBufferCache (RenderTarget .active.width, RenderTarget .active.height)
359
342
}
360
-
361
343
drawLayer(drawer, cache)
344
+ session?.pop()
345
+ }
346
+
347
+ override fun close () {
348
+ session?.close()
362
349
}
363
350
}
364
351
365
352
/* *
366
353
* create a layered composition
367
354
*/
368
- fun compose (function : Layer .() -> Unit ): Composite {
369
- val root = Composite ()
355
+ fun compose (function : Composite .() -> Unit ): Composite {
356
+ val session = Session .active.fork()
357
+ val root = Composite (session)
370
358
root.function()
359
+ session.pop()
371
360
return root
372
- }
373
-
374
- class Compositor : Extension {
375
- override var enabled: Boolean = true
376
- var composite = Composite ()
377
-
378
- override fun afterDraw (drawer : Drawer , program : Program ) {
379
- drawer.isolated {
380
- drawer.defaults()
381
- composite.draw(drawer)
382
- }
383
- }
384
- }
361
+ }
0 commit comments