From 65d0e79ab95336bf5f9d14a3a304a69aa2880b37 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Tue, 6 Jul 2021 13:24:38 +0200 Subject: [PATCH] [orx-no-clear] convert to MPP --- build.gradle | 1 + orx-no-clear/build.gradle | 19 --- orx-no-clear/build.gradle.kts | 96 +++++++++++++++ .../{main => commonMain}/kotlin/NoClear.kt | 112 +++++++++--------- 4 files changed, 153 insertions(+), 75 deletions(-) delete mode 100644 orx-no-clear/build.gradle create mode 100644 orx-no-clear/build.gradle.kts rename orx-no-clear/src/{main => commonMain}/kotlin/NoClear.kt (94%) diff --git a/build.gradle b/build.gradle index aed2508d..9d5bd28d 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,7 @@ def multiplatformModules = [ "orx-fx", "orx-gradient-descent", "orx-image-fit", + "orx-no-clear", "orx-noise", "orx-parameters", "orx-shade-styles", diff --git a/orx-no-clear/build.gradle b/orx-no-clear/build.gradle deleted file mode 100644 index 3785da3b..00000000 --- a/orx-no-clear/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -sourceSets { - demo { - java { - srcDirs = ["src/demo/kotlin"] - compileClasspath += main.getCompileClasspath() - runtimeClasspath += main.getRuntimeClasspath() - } - } -} - -dependencies { - //implementation project(":orx-?") - - demoImplementation("org.openrndr:openrndr-application:$openrndrVersion") - demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion") - demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion") - demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion") - demoImplementation(sourceSets.getByName("main").output) -} \ No newline at end of file diff --git a/orx-no-clear/build.gradle.kts b/orx-no-clear/build.gradle.kts new file mode 100644 index 00000000..e9c28dfc --- /dev/null +++ b/orx-no-clear/build.gradle.kts @@ -0,0 +1,96 @@ +plugins { + kotlin("multiplatform") + kotlin("plugin.serialization") +} + +val kotlinxSerializationVersion: String by rootProject.extra +val kotestVersion: String by rootProject.extra +val junitJupiterVersion: String by rootProject.extra +val jvmTarget: String by rootProject.extra +val kotlinApiVersion: String by rootProject.extra +val openrndrVersion: String by rootProject.extra +val openrndrOS: String by rootProject.extra +val kluentVersion: String by rootProject.extra +val spekVersion: String by rootProject.extra + +kotlin { + jvm { + compilations { + val demo by creating { + defaultSourceSet { + kotlin.srcDir("src/demo") + dependencies { + implementation(project(":orx-camera")) + implementation("org.openrndr:openrndr-application:$openrndrVersion") + implementation("org.openrndr:openrndr-extensions:$openrndrVersion") + runtimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion") + runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion") + implementation(compilations["main"]!!.output.allOutputs) + } + } + } + } + compilations.all { + kotlinOptions.jvmTarget = jvmTarget + kotlinOptions.apiVersion = kotlinApiVersion + } + testRuns["test"].executionTask.configure { + useJUnitPlatform() + } + } + + js(IR) { + browser() + nodejs() + } + + + sourceSets { + @Suppress("UNUSED_VARIABLE") + val commonMain by getting { + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion") + implementation("org.openrndr:openrndr-application:$openrndrVersion") + implementation("org.openrndr:openrndr-math:$openrndrVersion") + implementation("org.openrndr:openrndr-shape:$openrndrVersion") + implementation("org.openrndr:openrndr-draw:$openrndrVersion") + } + } + @Suppress("UNUSED_VARIABLE") + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion") + implementation("io.kotest:kotest-assertions-core:$kotestVersion") + } + } + + @Suppress("UNUSED_VARIABLE") + val jvmMain by getting + + @Suppress("UNUSED_VARIABLE") + val jvmTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + implementation(kotlin("test-junit5")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion") + runtimeOnly("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion") + runtimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion") + implementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion") + implementation("org.amshove.kluent:kluent:$kluentVersion") + } + } + + @Suppress("UNUSED_VARIABLE") + val jsMain by getting + + @Suppress("UNUSED_VARIABLE") + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + } +} diff --git a/orx-no-clear/src/main/kotlin/NoClear.kt b/orx-no-clear/src/commonMain/kotlin/NoClear.kt similarity index 94% rename from orx-no-clear/src/main/kotlin/NoClear.kt rename to orx-no-clear/src/commonMain/kotlin/NoClear.kt index 314a241d..173aa5ba 100644 --- a/orx-no-clear/src/main/kotlin/NoClear.kt +++ b/orx-no-clear/src/commonMain/kotlin/NoClear.kt @@ -1,57 +1,57 @@ -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.math.Matrix44 - -class NoClear : Extension { - override var enabled: Boolean = true - private var renderTarget: RenderTarget? = null - - /** - * code-block to draw an optional custom backdrop - */ - var backdrop: (() -> Unit)? = null - - override fun beforeDraw(drawer: Drawer, program: Program) { - if (program.width > 0 && program.height > 0) { // only if the window is not minimised - if (renderTarget == null || renderTarget?.width != program.width || renderTarget?.height != program.height) { - renderTarget?.let { - it.colorBuffer(0).destroy() - it.detachColorBuffers() - it.destroy() - } - renderTarget = renderTarget(program.width, program.height) { - colorBuffer() - depthBuffer() - } - - renderTarget?.let { - drawer.withTarget(it) { - clear(program.backgroundColor ?: ColorRGBa.TRANSPARENT) - backdrop?.invoke() // draw custom backdrop - } - } - } - } - renderTarget?.bind() - } - - override fun afterDraw(drawer: Drawer, program: Program) { - renderTarget?.unbind() - - renderTarget?.let { - drawer.isolated { - drawer.ortho() - drawer.view = Matrix44.IDENTITY - drawer.model = Matrix44.IDENTITY - drawer.image(it.colorBuffer(0)) - } - } - } +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.math.Matrix44 + +class NoClear : Extension { + override var enabled: Boolean = true + private var renderTarget: RenderTarget? = null + + /** + * code-block to draw an optional custom backdrop + */ + var backdrop: (() -> Unit)? = null + + override fun beforeDraw(drawer: Drawer, program: Program) { + if (program.width > 0 && program.height > 0) { // only if the window is not minimised + if (renderTarget == null || renderTarget?.width != program.width || renderTarget?.height != program.height) { + renderTarget?.let { + it.colorBuffer(0).destroy() + it.detachColorAttachments() + it.destroy() + } + renderTarget = renderTarget(program.width, program.height) { + colorBuffer() + depthBuffer() + } + + renderTarget?.let { + drawer.withTarget(it) { + clear(program.backgroundColor ?: ColorRGBa.TRANSPARENT) + backdrop?.invoke() // draw custom backdrop + } + } + } + } + renderTarget?.bind() + } + + override fun afterDraw(drawer: Drawer, program: Program) { + renderTarget?.unbind() + + renderTarget?.let { + drawer.isolated { + drawer.ortho() + drawer.view = Matrix44.IDENTITY + drawer.model = Matrix44.IDENTITY + drawer.image(it.colorBuffer(0)) + } + } + } } \ No newline at end of file