-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a49078a
commit a8a1a36
Showing
36 changed files
with
1,095 additions
and
335 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,33 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.jetbrains.kotlin.jvm' version '1.5.21' | ||
id 'org.jetbrains.kotlin.jvm' version '1.6.10' | ||
} | ||
|
||
group 'com.husker' | ||
version '1.1' | ||
|
||
repositories { | ||
mavenCentral() | ||
allprojects { | ||
version = "2.0" | ||
} | ||
|
||
sourceSets { | ||
main { | ||
resources { | ||
srcDirs "src/main/resources" | ||
} | ||
} | ||
} | ||
group 'com.husker.openglfx' | ||
|
||
jar{ | ||
java { | ||
exclude 'com/husker/test/**' | ||
} | ||
} | ||
subprojects { | ||
apply plugin: 'java' | ||
apply plugin: 'maven' | ||
|
||
dependencies { | ||
implementation fileTree("libs") | ||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib" | ||
task sourcesJar(type: Jar, dependsOn: classes) { | ||
classifier = 'sources' | ||
from sourceSets.main.allSource | ||
} | ||
|
||
implementation "org.openjfx:javafx-base:16:win" | ||
implementation "org.openjfx:javafx-controls:16:win" | ||
implementation "org.openjfx:javafx-graphics:16:win" | ||
implementation "org.openjfx:javafx-swing:16:win" | ||
task javadocJar(type: Jar, dependsOn: javadoc) { | ||
classifier = 'javadoc' | ||
from javadoc.destinationDir | ||
} | ||
|
||
implementation 'org.jogamp.jogl:jogl-all-main:2.3.2' | ||
implementation 'org.jogamp.gluegen:gluegen-rt-main:2.3.2' | ||
artifacts { | ||
archives sourcesJar | ||
archives javadocJar | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' | ||
} | ||
|
||
group 'com.husker' | ||
version '2.0' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib" | ||
|
||
implementation "org.openjfx:javafx-base:16:win" | ||
implementation "org.openjfx:javafx-controls:16:win" | ||
implementation "org.openjfx:javafx-graphics:16:win" | ||
implementation "org.openjfx:javafx-swing:16:win" | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/kotlin/com/husker/openglfx/FXGLEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.husker.openglfx | ||
|
||
|
||
interface FXGLEventListener { | ||
|
||
fun display() | ||
fun reshape(width: Float, height: Float) | ||
fun init() | ||
fun dispose() | ||
} |
11 changes: 11 additions & 0 deletions
11
core/src/main/kotlin/com/husker/openglfx/FXGLInitializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.husker.openglfx | ||
|
||
abstract class FXGLInitializer { | ||
|
||
abstract val name: String | ||
abstract val supportsDirect: Boolean | ||
abstract val supportsUniversal: Boolean | ||
|
||
abstract fun createDirect(): OpenGLCanvas | ||
abstract fun createUniversal(): OpenGLCanvas | ||
} |
135 changes: 135 additions & 0 deletions
135
core/src/main/kotlin/com/husker/openglfx/OpenGLCanvas.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.husker.openglfx | ||
|
||
|
||
import com.husker.openglfx.utils.FXUtils | ||
import com.husker.openglfx.utils.RegionAccessorObject | ||
import com.husker.openglfx.utils.RegionAccessorOverrider | ||
|
||
import com.sun.javafx.sg.prism.NGRegion | ||
import com.sun.prism.Graphics | ||
import javafx.scene.layout.Pane | ||
|
||
enum class DirectDrawPolicy { | ||
NEVER, | ||
IF_AVAILABLE, | ||
ALWAYS | ||
} | ||
|
||
abstract class OpenGLCanvas: Pane() { | ||
|
||
companion object{ | ||
init{ | ||
RegionAccessorOverrider.overwrite(object: RegionAccessorObject<OpenGLCanvas>(){ | ||
override fun doCreatePeer(node: OpenGLCanvas) = NGOpenGLCanvas(node) | ||
}) | ||
} | ||
|
||
@JvmOverloads | ||
@JvmStatic | ||
fun create( | ||
initializer: FXGLInitializer, | ||
directDrawPolicy: DirectDrawPolicy = DirectDrawPolicy.NEVER | ||
): OpenGLCanvas { | ||
val isES2 = FXUtils.pipelineName == "es2" | ||
return when(directDrawPolicy) { | ||
DirectDrawPolicy.NEVER -> { | ||
if(!initializer.supportsUniversal) | ||
throw UnsupportedOperationException("${initializer.name} doesn't support universal rendering") | ||
initializer.createUniversal() | ||
} | ||
DirectDrawPolicy.ALWAYS -> { | ||
if(!initializer.supportsDirect) | ||
throw UnsupportedOperationException("${initializer.name} doesn't support direct rendering") | ||
if(!isES2) | ||
throw UnsupportedOperationException("Direct rendering only supports ES2 JavaFX pipeline (current: ${FXUtils.pipelineName})") | ||
initializer.createDirect() | ||
} | ||
DirectDrawPolicy.IF_AVAILABLE -> { | ||
if(initializer.supportsDirect && isES2) initializer.createDirect() | ||
else initializer.createUniversal() | ||
} | ||
} | ||
} | ||
} | ||
|
||
private var onInit: Runnable? = null | ||
private var onRender: Runnable? = null | ||
private var onReshape: Runnable? = null | ||
private var onDispose: Runnable? = null | ||
|
||
private var initialized = false | ||
|
||
protected val dpi: Double | ||
get() = scene.window.outputScaleX | ||
|
||
protected val scaledWidth: Double | ||
get() = width * dpi | ||
|
||
protected val scaledHeight: Double | ||
get() = height * dpi | ||
|
||
fun onNGRender(listener: Runnable){ | ||
onRender = listener | ||
} | ||
|
||
fun onReshape(listener: Runnable){ | ||
onReshape = listener | ||
} | ||
|
||
fun onInitialize(listener: Runnable){ | ||
onInit = listener | ||
initialized = false | ||
} | ||
|
||
fun onDispose(listener: Runnable){ | ||
onDispose = listener | ||
} | ||
|
||
protected abstract fun onNGRender(g: Graphics) | ||
protected abstract fun repaint() | ||
|
||
protected open fun fireRenderEvent() { | ||
checkInitialization() | ||
onRender?.run() | ||
} | ||
|
||
protected open fun fireReshapeEvent() { | ||
checkInitialization() | ||
onReshape?.run() | ||
} | ||
|
||
protected open fun fireInitEvent() = checkInitialization() | ||
|
||
protected open fun fireDisposeEvent() { | ||
checkInitialization() | ||
onDispose?.run() | ||
} | ||
|
||
private fun checkInitialization(){ | ||
if(!initialized){ | ||
initialized = true | ||
onInit?.run() | ||
} | ||
} | ||
|
||
private class NGOpenGLCanvas(val canvas: OpenGLCanvas): NGRegion() { | ||
|
||
init{ | ||
/* | ||
NodeUtils.onWindowReady(canvas){ | ||
object: AnimationTimer(){ | ||
override fun handle(p: Long) { | ||
//NodeHelper.markDirty(canvas, DirtyBits.NODE_GEOMETRY) | ||
} | ||
}.start() | ||
} | ||
*/ | ||
} | ||
|
||
override fun renderContent(g: Graphics) { | ||
canvas.onNGRender(g) | ||
super.renderContent(g) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.husker.openglfx.utils | ||
|
||
|
||
import com.sun.prism.GraphicsPipeline | ||
import javafx.scene.Node | ||
import javafx.scene.Scene | ||
|
||
class FXUtils { | ||
companion object { | ||
|
||
val pipelineName: String | ||
get() = GraphicsPipeline.getPipeline().javaClass.canonicalName.split(".")[3] | ||
|
||
fun onWindowReady(node: Node, listener: () -> Unit){ | ||
if(node.scene != null) | ||
processScene(node.scene, listener) | ||
else node.sceneProperty().addListener { _, _, _ -> processScene(node.scene, listener) } | ||
} | ||
|
||
private fun processScene(scene: Scene, listener: () -> Unit){ | ||
if(scene.window != null) | ||
listener.invoke() | ||
else scene.windowProperty().addListener { _, _, _ -> listener.invoke() } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.