├── .gitignore ├── gradle ├── secring.gpg ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── libs.versions.toml ├── gradle.properties ├── .github ├── resources │ ├── logo.png │ └── boosty.svg ├── ISSUE_TEMPLATE │ ├── question.md │ ├── feature_request.md │ └── bug_report.md └── workflows │ └── maven_publish.yml ├── modules ├── lwjgl2 │ ├── libs │ │ ├── x86 │ │ │ ├── lwjgl.dll │ │ │ ├── liblwjgl.so │ │ │ └── liblwjgl.dylib │ │ ├── x64 │ │ │ ├── lwjgl64.dll │ │ │ ├── liblwjgl.dylib │ │ │ └── liblwjgl64.so │ │ └── arm64 │ │ │ └── liblwjgl.dylib │ ├── build.gradle.kts │ └── kotlin │ │ └── com │ │ └── huskerdev │ │ └── openglfx │ │ └── lwjgl2 │ │ └── LWJGL2Executor.kt ├── jogl │ ├── kotlin │ │ └── com │ │ │ └── huskerdev │ │ │ └── openglfx │ │ │ └── jogl │ │ │ ├── events │ │ │ ├── JOGLEvent.kt │ │ │ ├── JOGLDisposeEvent.kt │ │ │ ├── JOGLInitializeEvent.kt │ │ │ ├── JOGLReshapeEvent.kt │ │ │ └── JOGLRenderEvent.kt │ │ │ └── JOGLFXExecutor.kt │ └── build.gradle.kts ├── core │ ├── kotlin │ │ └── com │ │ │ └── huskerdev │ │ │ └── openglfx │ │ │ ├── GLFXInfo.kt │ │ │ ├── canvas │ │ │ └── events │ │ │ │ ├── GLDisposeEvent.kt │ │ │ │ ├── GLInitializeEvent.kt │ │ │ │ ├── GLReshapeEvent.kt │ │ │ │ └── GLRenderEvent.kt │ │ │ ├── internal │ │ │ ├── FPSCounter.kt │ │ │ ├── platforms │ │ │ │ ├── MemoryObjects.kt │ │ │ │ ├── macos │ │ │ │ │ └── IOSurface.kt │ │ │ │ ├── win │ │ │ │ │ ├── WGLDX.kt │ │ │ │ │ └── D3D9.kt │ │ │ │ └── VkExtMemory.kt │ │ │ ├── shaders │ │ │ │ ├── FXAAShader.kt │ │ │ │ └── PassthroughShader.kt │ │ │ ├── canvas │ │ │ │ ├── BlitCanvas.kt │ │ │ │ ├── IOSurfaceCanvas.kt │ │ │ │ ├── WGLDXInteropCanvas.kt │ │ │ │ ├── ExternalObjectsCanvasD3D.kt │ │ │ │ └── ExternalObjectsCanvasES2.kt │ │ │ ├── GLFXUtils.kt │ │ │ ├── GLInteropType.kt │ │ │ └── Framebuffer.kt │ │ │ └── image │ │ │ └── GLImageManager.kt │ ├── native │ │ ├── macos │ │ │ ├── openglfx-macos.h │ │ │ └── iosurface.cpp │ │ ├── linux │ │ │ └── openglfx-linux.h │ │ ├── shared │ │ │ ├── utils.cpp │ │ │ └── memory-objects.cpp │ │ ├── include │ │ │ ├── vk_video │ │ │ │ ├── vulkan_video_codecs_common.h │ │ │ │ ├── vulkan_video_codec_h265std_decode.h │ │ │ │ ├── vulkan_video_codec_h264std_decode.h │ │ │ │ └── vulkan_video_codec_av1std_decode.h │ │ │ └── vulkan │ │ │ │ ├── vulkan_vi.h │ │ │ │ ├── vulkan_ios.h │ │ │ │ ├── vulkan_macos.h │ │ │ │ ├── vulkan_xlib_xrandr.h │ │ │ │ ├── vulkan_wayland.h │ │ │ │ ├── vulkan_xlib.h │ │ │ │ ├── vulkan.h │ │ │ │ ├── vulkan_directfb.h │ │ │ │ ├── vulkan_xcb.h │ │ │ │ ├── vulkan_ggp.h │ │ │ │ ├── vk_platform.h │ │ │ │ ├── vulkan_screen.h │ │ │ │ ├── vulkan_metal.h │ │ │ │ └── vulkan_android.h │ │ ├── build.gradle.kts │ │ └── win │ │ │ ├── wgldx.cpp │ │ │ ├── dx9.cpp │ │ │ └── openglfx-windows.h │ └── build.gradle.kts ├── libgdx │ ├── kotlin │ │ └── com │ │ │ └── huskerdev │ │ │ └── openglfx │ │ │ └── libgdx │ │ │ ├── events │ │ │ ├── LibGDXEvent.kt │ │ │ ├── LibGDXDisposeEvent.kt │ │ │ ├── LibGDXInitializeEvent.kt │ │ │ ├── LibGDXReshapeEvent.kt │ │ │ └── LibGDXRenderEvent.kt │ │ │ ├── internal │ │ │ ├── OGLFXCanvas.kt │ │ │ ├── OGLFXClipboard.kt │ │ │ ├── FXPixmapImage.kt │ │ │ ├── OGLFXApplication.kt │ │ │ └── OGLFXGraphics.kt │ │ │ ├── LibGDXExecutor.kt │ │ │ ├── LibGDXCanvas.kt │ │ │ └── OGLFXApplicationConfiguration.kt │ └── build.gradle.kts └── lwjgl │ ├── kotlin │ └── com │ │ └── huskerdev │ │ └── openglfx │ │ └── lwjgl │ │ └── LWJGLExecutor.kt │ └── build.gradle.kts ├── plugins ├── native │ ├── src │ │ └── main │ │ │ └── kotlin │ │ │ └── com │ │ │ └── huskerdev │ │ │ └── plugins │ │ │ └── compilation │ │ │ ├── types │ │ │ ├── Arch.kt │ │ │ ├── OutputType.kt │ │ │ └── Platform.kt │ │ │ ├── utils │ │ │ ├── Execute.kt │ │ │ └── WinUtils.kt │ │ │ └── NativeExtension.kt │ └── build.gradle.kts ├── properties │ ├── src │ │ └── main │ │ │ └── kotlin │ │ │ └── com │ │ │ └── huskerdev │ │ │ └── plugins │ │ │ └── properties │ │ │ ├── PropertiesExtension.kt │ │ │ └── PropertiesPlugin.kt │ └── build.gradle.kts ├── utils │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── huskerdev │ │ └── openglfx │ │ └── plugins │ │ └── utils │ │ └── UtilsPlugin.kt ├── moduleInfo │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── huskerdev │ │ └── plugins │ │ └── moduleinfo │ │ ├── ModuleInfoExtension.kt │ │ └── ModuleInfoPlugin.kt └── maven │ ├── build.gradle.kts │ └── src │ └── main │ └── kotlin │ └── com │ └── huskerdev │ └── plugins │ └── maven │ └── MavenPlugin.kt ├── settings.gradle.kts ├── gradlew.bat └── gradlew /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle/ 2 | **/build/ 3 | /.idea/ 4 | /plugins/native/.gradle/ 5 | -------------------------------------------------------------------------------- /gradle/secring.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/gradle/secring.gpg -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=4.2.2 2 | 3 | kotlin.code.style=official 4 | signing.keyId=4358B6E0 5 | -------------------------------------------------------------------------------- /.github/resources/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/.github/resources/logo.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /modules/lwjgl2/libs/x86/lwjgl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/modules/lwjgl2/libs/x86/lwjgl.dll -------------------------------------------------------------------------------- /modules/lwjgl2/libs/x64/lwjgl64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/modules/lwjgl2/libs/x64/lwjgl64.dll -------------------------------------------------------------------------------- /modules/lwjgl2/libs/x86/liblwjgl.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/modules/lwjgl2/libs/x86/liblwjgl.so -------------------------------------------------------------------------------- /modules/lwjgl2/libs/x64/liblwjgl.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/modules/lwjgl2/libs/x64/liblwjgl.dylib -------------------------------------------------------------------------------- /modules/lwjgl2/libs/x64/liblwjgl64.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/modules/lwjgl2/libs/x64/liblwjgl64.so -------------------------------------------------------------------------------- /modules/lwjgl2/libs/x86/liblwjgl.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/modules/lwjgl2/libs/x86/liblwjgl.dylib -------------------------------------------------------------------------------- /modules/lwjgl2/libs/arm64/liblwjgl.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/husker-dev/openglfx/HEAD/modules/lwjgl2/libs/arm64/liblwjgl.dylib -------------------------------------------------------------------------------- /plugins/native/src/main/kotlin/com/huskerdev/plugins/compilation/types/Arch.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.compilation.types 2 | 3 | enum class Arch { 4 | X86, 5 | X64, 6 | ARM64 7 | } -------------------------------------------------------------------------------- /modules/jogl/kotlin/com/huskerdev/openglfx/jogl/events/JOGLEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.jogl.events 2 | 3 | import com.jogamp.opengl.GL3 4 | 5 | interface JOGLEvent{ 6 | val gl: GL3 7 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Something to ask 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | **I have a question*** 11 | [text here] 12 | -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/GLFXInfo.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx 2 | 3 | // Generated with gradle 4 | class GLFXInfo { 5 | companion object { 6 | const val VERSION = "4.2.2" 7 | } 8 | } -------------------------------------------------------------------------------- /plugins/native/src/main/kotlin/com/huskerdev/plugins/compilation/types/OutputType.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.compilation.types 2 | 3 | enum class OutputType { 4 | SHARED, 5 | EXECUTABLE, 6 | STATIC 7 | } -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/events/LibGDXEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.events 2 | 3 | import com.badlogic.gdx.Application 4 | 5 | interface LibGDXEvent { 6 | val application: Application 7 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe your feature** 11 | [text here] 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/internal/OGLFXCanvas.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.internal 2 | 3 | import com.huskerdev.openglfx.canvas.GLCanvas 4 | 5 | class OGLFXCanvas(val canvas: GLCanvas) { 6 | 7 | val graphics = OGLFXGraphics(canvas) 8 | } -------------------------------------------------------------------------------- /modules/core/native/macos/openglfx-macos.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENGLFX_MACOS_H 2 | #define OPENGLFX_MACOS_H 3 | 4 | #include 5 | 6 | #define jni_win_iosurface(returnType, fun) extern "C" JNIEXPORT returnType JNICALL Java_com_huskerdev_openglfx_internal_platforms_macos_IOSurface_##fun 7 | 8 | #endif -------------------------------------------------------------------------------- /modules/core/native/linux/openglfx-linux.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENGLFX_LINUX_H 2 | #define OPENGLFX_LINUX_H 3 | 4 | #include 5 | #include 6 | 7 | #define jni_linux_vkextmemory(returnType, fun) extern "C" JNIEXPORT returnType JNICALL Java_com_huskerdev_openglfx_internal_platforms_linux_VkExtMemory_##fun 8 | 9 | #endif -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/events/LibGDXDisposeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.events 2 | 3 | import com.badlogic.gdx.Application 4 | import com.huskerdev.openglfx.canvas.events.GLDisposeEvent 5 | 6 | class LibGDXDisposeEvent( 7 | override val application: Application 8 | ): GLDisposeEvent(ANY), LibGDXEvent -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/events/LibGDXInitializeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.events 2 | 3 | import com.badlogic.gdx.Application 4 | import com.huskerdev.openglfx.canvas.events.GLInitializeEvent 5 | 6 | class LibGDXInitializeEvent( 7 | override val application: Application 8 | ): GLInitializeEvent(ANY), LibGDXEvent -------------------------------------------------------------------------------- /modules/core/native/shared/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "openglfx.h" 2 | 3 | 4 | jni_utils(jobject, createDirectBuffer)(JNIEnv* env, jobject, jint size) { 5 | return env->NewDirectByteBuffer(new char[size], size); 6 | } 7 | 8 | jni_utils(void, cleanDirectBuffer)(JNIEnv* env, jobject, jobject directBuffer) { 9 | char* buffer = (char*)env->GetDirectBufferAddress(directBuffer); 10 | delete[] buffer; 11 | } -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/events/LibGDXReshapeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.events 2 | 3 | import com.badlogic.gdx.Application 4 | import com.huskerdev.openglfx.canvas.events.GLReshapeEvent 5 | 6 | class LibGDXReshapeEvent( 7 | override val application: Application, 8 | width: Int, 9 | height: Int 10 | ): GLReshapeEvent(ANY, width, height), LibGDXEvent -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | [text here] 12 | 13 | **To Reproduce** 14 | [text here] 15 | 16 | **Screenshots** 17 | [delete if don't have one] 18 | 19 | **Environment:** 20 | - OS: [text here] 21 | - openglfx version: [text here] 22 | -------------------------------------------------------------------------------- /modules/jogl/kotlin/com/huskerdev/openglfx/jogl/events/JOGLDisposeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.jogl.events 2 | 3 | import com.huskerdev.openglfx.canvas.events.GLDisposeEvent 4 | import com.jogamp.opengl.GL3 5 | import javafx.beans.NamedArg 6 | import javafx.event.EventType 7 | 8 | class JOGLDisposeEvent ( 9 | override val gl: GL3, 10 | @NamedArg("eventType") eventType: EventType 11 | ): GLDisposeEvent(eventType), JOGLEvent -------------------------------------------------------------------------------- /plugins/properties/src/main/kotlin/com/huskerdev/plugins/properties/PropertiesExtension.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.properties 2 | 3 | import java.io.File 4 | 5 | open class PropertiesExtension { 6 | var name: String? = null 7 | var srcDir: File? = null 8 | var classpath: String? = null 9 | 10 | var fields: Map = hashMapOf() 11 | 12 | fun field(name: String, value: Any){ 13 | fields += name to value 14 | } 15 | } -------------------------------------------------------------------------------- /modules/lwjgl/kotlin/com/huskerdev/openglfx/lwjgl/LWJGLExecutor.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.lwjgl 2 | 3 | import com.huskerdev.openglfx.GLExecutor 4 | import org.lwjgl.opengl.GL 5 | 6 | 7 | class LWJGLExecutor: GLExecutor() { 8 | 9 | companion object { 10 | @JvmField val LWJGL_MODULE = LWJGLExecutor() 11 | } 12 | 13 | override fun initGLFunctions() { 14 | super.initGLFunctions() 15 | GL.createCapabilities() 16 | } 17 | } -------------------------------------------------------------------------------- /modules/jogl/kotlin/com/huskerdev/openglfx/jogl/events/JOGLInitializeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.jogl.events 2 | 3 | import com.huskerdev.openglfx.canvas.events.GLInitializeEvent 4 | import com.jogamp.opengl.GL3 5 | import javafx.beans.NamedArg 6 | import javafx.event.EventType 7 | 8 | class JOGLInitializeEvent( 9 | override val gl: GL3, 10 | @NamedArg("eventType") eventType: EventType 11 | ): GLInitializeEvent(eventType), JOGLEvent -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/events/LibGDXRenderEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.events 2 | 3 | import com.badlogic.gdx.Application 4 | import com.huskerdev.openglfx.canvas.events.GLRenderEvent 5 | 6 | class LibGDXRenderEvent( 7 | override val application: Application, 8 | fps: Int, 9 | delta: Double, 10 | width: Int, 11 | height: Int, 12 | fbo: Int): GLRenderEvent(ANY, fps, delta, width, height, fbo), LibGDXEvent -------------------------------------------------------------------------------- /modules/jogl/kotlin/com/huskerdev/openglfx/jogl/events/JOGLReshapeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.jogl.events 2 | 3 | import com.huskerdev.openglfx.canvas.events.GLReshapeEvent 4 | import com.jogamp.opengl.GL3 5 | import javafx.beans.NamedArg 6 | import javafx.event.EventType 7 | 8 | class JOGLReshapeEvent( 9 | override val gl: GL3, 10 | @NamedArg("eventType") eventType: EventType, 11 | width: Int, 12 | height: Int 13 | ): GLReshapeEvent(eventType, width, height), JOGLEvent -------------------------------------------------------------------------------- /modules/lwjgl2/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.huskerdev.openglfx.plugins.utils.* 2 | 3 | plugins { 4 | alias(libs.plugins.kotlin.jvm) 5 | id("utils") 6 | id("maven") 7 | id("module-info") 8 | } 9 | 10 | configureKotlinProject() 11 | 12 | dependencies { 13 | compileOnly(*expandFXPlatforms(libs.bundles.javafx)) 14 | api(project(":modules:core")) 15 | 16 | compileOnly(libs.lwjgl2) 17 | } 18 | 19 | pom { 20 | name = "$rootName-lwjgl2" 21 | description = "$rootName lwjgl2 module" 22 | } 23 | -------------------------------------------------------------------------------- /modules/lwjgl2/kotlin/com/huskerdev/openglfx/lwjgl2/LWJGL2Executor.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.lwjgl2 2 | 3 | import com.huskerdev.grapl.gl.GLContext 4 | import com.huskerdev.openglfx.GLExecutor 5 | 6 | class LWJGL2Executor: GLExecutor() { 7 | 8 | companion object { 9 | @JvmField val LWJGL2_MODULE = LWJGL2Executor() 10 | } 11 | 12 | override fun initGLFunctions() { 13 | super.initGLFunctions() 14 | org.lwjgl.opengl.GLContext.useContext(GLContext.current().handle) 15 | } 16 | } -------------------------------------------------------------------------------- /plugins/utils/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | `java-gradle-plugin` 4 | } 5 | 6 | group = "com.huskerdev.openglfx.plugins.utils" 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0") 14 | } 15 | 16 | gradlePlugin { 17 | plugins { 18 | plugins.create("utils") { 19 | id = name 20 | implementationClass = "com.huskerdev.openglfx.plugins.utils.UtilsPlugin" 21 | } 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /plugins/native/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | `java-gradle-plugin` 4 | } 5 | 6 | group = "com.huskerdev.openglfx.plugins.compilation" 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0") 14 | } 15 | 16 | gradlePlugin { 17 | plugins { 18 | plugins.create("native-compilation") { 19 | id = name 20 | implementationClass = "com.huskerdev.plugins.compilation.NativePlugin" 21 | } 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /plugins/properties/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | `java-gradle-plugin` 4 | } 5 | 6 | group = "com.huskerdev.openglfx.plugins.properties" 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0") 14 | } 15 | 16 | gradlePlugin { 17 | plugins { 18 | plugins.create("properties") { 19 | id = name 20 | implementationClass = "com.huskerdev.plugins.properties.PropertiesPlugin" 21 | } 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /modules/jogl/kotlin/com/huskerdev/openglfx/jogl/events/JOGLRenderEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.jogl.events 2 | 3 | import com.huskerdev.openglfx.canvas.events.GLRenderEvent 4 | import com.jogamp.opengl.GL3 5 | import javafx.beans.NamedArg 6 | import javafx.event.EventType 7 | 8 | class JOGLRenderEvent( 9 | override val gl: GL3, 10 | @NamedArg("eventType") eventType: EventType, 11 | fps: Int, 12 | delta: Double, 13 | width: Int, 14 | height: Int, 15 | fbo: Int 16 | ): GLRenderEvent(eventType, fps, delta, width, height, fbo), JOGLEvent -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "openglfx" 2 | 3 | pluginManagement { 4 | includeBuild("plugins/utils") 5 | includeBuild("plugins/maven") 6 | includeBuild("plugins/properties") 7 | includeBuild("plugins/moduleInfo") 8 | includeBuild("plugins/native") 9 | } 10 | 11 | plugins { 12 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.10.0" 13 | } 14 | 15 | include ( 16 | "modules:core", 17 | "modules:core:native", 18 | "modules:jogl", 19 | "modules:libgdx", 20 | "modules:lwjgl", 21 | "modules:lwjgl2" 22 | ) 23 | 24 | -------------------------------------------------------------------------------- /plugins/moduleInfo/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | `java-gradle-plugin` 4 | } 5 | 6 | group = "com.huskerdev.openglfx.plugins.moduleinfo" 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0") 14 | 15 | implementation("org.ow2.asm:asm:9.5") 16 | } 17 | 18 | gradlePlugin { 19 | plugins { 20 | plugins.create("module-info") { 21 | id = name 22 | implementationClass = "com.huskerdev.plugins.moduleinfo.ModuleInfoPlugin" 23 | } 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/canvas/events/GLDisposeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.canvas.events 2 | 3 | import javafx.beans.NamedArg 4 | import javafx.event.Event 5 | import javafx.event.EventType 6 | 7 | open class GLDisposeEvent( 8 | @NamedArg("eventType") eventType: EventType 9 | ) : Event(eventType) { 10 | 11 | companion object { 12 | private const val serialVersionUID = 20220503L 13 | 14 | /** 15 | * Common supertype for all event types. 16 | */ 17 | @JvmStatic 18 | val ANY: EventType = EventType(Event.ANY, "GL_DISPOSE") 19 | } 20 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/canvas/events/GLInitializeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.canvas.events 2 | 3 | import javafx.beans.NamedArg 4 | import javafx.event.Event 5 | import javafx.event.EventType 6 | 7 | 8 | open class GLInitializeEvent( 9 | @NamedArg("eventType") eventType: EventType 10 | ) : Event(eventType) { 11 | 12 | companion object { 13 | private const val serialVersionUID = 20220503L 14 | 15 | /** 16 | * Common supertype for all event types. 17 | */ 18 | @JvmStatic 19 | val ANY: EventType = EventType(Event.ANY, "GL_INITIALIZE") 20 | } 21 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/canvas/events/GLReshapeEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.canvas.events 2 | 3 | import javafx.beans.NamedArg 4 | import javafx.event.Event 5 | import javafx.event.EventType 6 | 7 | 8 | open class GLReshapeEvent( 9 | @NamedArg("eventType") eventType: EventType, 10 | @JvmField val width: Int, 11 | @JvmField val height: Int 12 | ) : Event(eventType) { 13 | 14 | companion object { 15 | private const val serialVersionUID = 20220503L 16 | 17 | /** 18 | * Common supertype for all event types. 19 | */ 20 | @JvmStatic 21 | val ANY: EventType = EventType(Event.ANY, "GL_RESHAPE") 22 | } 23 | } -------------------------------------------------------------------------------- /plugins/maven/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | `java-gradle-plugin` 4 | } 5 | 6 | group = "com.huskerdev.openglfx.plugins.maven" 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0") 14 | 15 | implementation("com.fasterxml.jackson.core:jackson-databind:2.19.0") 16 | implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.19.0") 17 | 18 | implementation("io.gitee.pkmer:central-publisher:1.1.1") 19 | } 20 | 21 | gradlePlugin { 22 | plugins { 23 | plugins.create("maven") { 24 | id = name 25 | implementationClass = "com.huskerdev.plugins.maven.MavenPlugin" 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/canvas/events/GLRenderEvent.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.canvas.events 2 | 3 | import javafx.beans.NamedArg 4 | import javafx.event.Event 5 | import javafx.event.EventType 6 | 7 | 8 | open class GLRenderEvent( 9 | @NamedArg("eventType") eventType: EventType, 10 | @JvmField val fps: Int, 11 | @JvmField val delta: Double, 12 | @JvmField val width: Int, 13 | @JvmField val height: Int, 14 | @JvmField val fbo: Int, 15 | ) : Event(eventType) { 16 | 17 | companion object { 18 | private const val serialVersionUID = 20220503L 19 | 20 | /** 21 | * Common supertype for all event types. 22 | */ 23 | @JvmStatic 24 | val ANY: EventType = EventType(Event.ANY, "GL_RENDER") 25 | } 26 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/FPSCounter.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal 2 | 3 | class FPSCounter { 4 | 5 | // Delta 6 | private var lastDeltaTime = System.nanoTime() 7 | var delta = 0.0 8 | private set 9 | 10 | // Fps 11 | private var lastFpsTime = System.nanoTime() 12 | private var countedFps = 0 13 | var currentFps = 0 14 | private set 15 | 16 | var frameId = 0L 17 | private set 18 | 19 | internal fun update(){ 20 | val now = System.nanoTime() 21 | delta = (now - lastDeltaTime) / 1000000000.0 22 | lastDeltaTime = now 23 | 24 | countedFps++ 25 | frameId++ 26 | if(now - lastFpsTime >= 1000000000) { 27 | currentFps = countedFps 28 | countedFps = 0 29 | lastFpsTime = now 30 | } 31 | 32 | } 33 | } -------------------------------------------------------------------------------- /modules/core/native/include/vk_video/vulkan_video_codecs_common.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODECS_COMMON_H_ 2 | #define VULKAN_VIDEO_CODECS_COMMON_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codecs_common is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codecs_common 1 24 | #if !defined(VK_NO_STDINT_H) 25 | #include 26 | #endif 27 | 28 | #define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \ 29 | ((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch))) 30 | 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /modules/core/native/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.huskerdev.openglfx.plugins.utils.* 2 | import com.huskerdev.plugins.compilation.* 3 | 4 | 5 | plugins { 6 | id("utils") 7 | id("native-compilation") 8 | id("maven") 9 | id("module-info") 10 | } 11 | 12 | compilation { 13 | baseName = "lib" 14 | classpath = "com.huskerdev.openglfx.natives.$shortOSName" 15 | 16 | includeDirs = arrayListOf(file("shared"), file("include")) 17 | 18 | windows { 19 | libs = arrayListOf("user32", "gdi32", "d3d9") 20 | } 21 | macos { 22 | frameworks = arrayListOf("Cocoa", "IOSurface", "OpenGL") 23 | } 24 | } 25 | 26 | pom { 27 | name = "$rootName-natives-core-$shortOSName" 28 | description = "$rootName core module (natives for $shortOSName)" 29 | } 30 | 31 | moduleInfo { 32 | name = "$rootName.natives.core.$shortOSName" 33 | opens = arrayListOf( 34 | "com.huskerdev.openglfx.natives.$shortOSName" 35 | ) 36 | } 37 | 38 | -------------------------------------------------------------------------------- /plugins/moduleInfo/src/main/kotlin/com/huskerdev/plugins/moduleinfo/ModuleInfoExtension.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.moduleinfo 2 | 3 | @Suppress("unused") 4 | open class ModuleInfoExtension { 5 | var name: String = "" 6 | var open: Boolean = false 7 | 8 | var exports: ArrayList = arrayListOf() 9 | var opens: ArrayList = arrayListOf() 10 | var requires: ArrayList = arrayListOf() 11 | var requiresTransitive: ArrayList = arrayListOf() 12 | var requiresStatic: ArrayList = arrayListOf() 13 | 14 | fun exports(vararg elements: String) = 15 | exports.addAll(elements) 16 | 17 | fun opens(vararg elements: String) = 18 | opens.addAll(elements) 19 | 20 | fun requires(vararg elements: String) = 21 | requires.addAll(elements) 22 | 23 | fun requiresTransitive(vararg elements: String) = 24 | requiresTransitive.addAll(elements) 25 | 26 | fun requiresStatic(vararg elements: String) = 27 | requiresStatic.addAll(elements) 28 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/platforms/MemoryObjects.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.platforms 2 | 3 | import com.huskerdev.openglfx.internal.GLFXUtils 4 | 5 | const val GL_HANDLE_TYPE_D3D11_IMAGE_KMT_EXT = 0x958C 6 | const val GL_HANDLE_TYPE_OPAQUE_FD_EXT = 0x9586 7 | 8 | class MemoryObjects { 9 | companion object { 10 | @JvmStatic external fun nLoadFunctions() 11 | @JvmStatic external fun glCreateMemoryObjectsEXT(): Int 12 | @JvmStatic external fun glDeleteMemoryObjectsEXT(memoryObject: Int) 13 | @JvmStatic external fun glTextureStorageMem2DEXT(texture: Int, levels: Int, internalFormat: Int, width: Int, height: Int, memory: Int, offset: Long) 14 | 15 | @JvmStatic external fun glImportMemoryWin32HandleEXT(memory: Int, size: Long, handleType: Int, handle: Long) 16 | @JvmStatic external fun glImportMemoryFdEXT(memory: Int, size: Long, handleType: Int, fd: Int) 17 | 18 | init { 19 | GLFXUtils.loadLibrary() 20 | nLoadFunctions() 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /modules/libgdx/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.huskerdev.openglfx.plugins.utils.* 2 | 3 | plugins { 4 | alias(libs.plugins.kotlin.jvm) 5 | id("utils") 6 | id("maven") 7 | id("module-info") 8 | } 9 | 10 | configureKotlinProject() 11 | 12 | dependencies { 13 | compileOnly(*expandFXPlatforms(libs.bundles.javafx)) 14 | api(project(":modules:core")) 15 | 16 | compileOnly(libs.gdx) 17 | compileOnly(libs.gdx.backend.lwjgl3) 18 | compileOnly(variantOf(libs.gdx.platform){ classifier("natives-desktop") }) 19 | } 20 | 21 | pom { 22 | name = "$rootName-libgdx" 23 | description = "$rootName libgdx module" 24 | } 25 | 26 | moduleInfo { 27 | name = "$rootName.libgdx" 28 | requiresTransitive = arrayListOf( 29 | "openglfx" 30 | ) 31 | requires = arrayListOf( 32 | "org.lwjgl", 33 | "org.lwjgl.opengl", 34 | "javafx.controls" 35 | ) 36 | exports = arrayListOf( 37 | "com.huskerdev.openglfx.libgdx", 38 | "com.huskerdev.openglfx.libgdx.events", 39 | "com.huskerdev.openglfx.libgdx.internal" 40 | ) 41 | } -------------------------------------------------------------------------------- /modules/jogl/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.huskerdev.openglfx.plugins.utils.* 2 | 3 | plugins { 4 | alias(libs.plugins.kotlin.jvm) 5 | id("utils") 6 | id("maven") 7 | id("module-info") 8 | } 9 | 10 | repositories { 11 | maven("https://jogamp.org/deployment/maven/") 12 | } 13 | 14 | configureKotlinProject() 15 | 16 | dependencies { 17 | api(project(":modules:core")) 18 | compileOnly(*expandFXPlatforms(libs.bundles.javafx)) 19 | 20 | compileOnly(libs.gluegen) 21 | compileOnly(libs.jogl) 22 | 23 | arrayOf("linux-amd64", "linux-aarch64", "macosx-universal", "windows-amd64").forEach { 24 | compileOnly(variantOf(libs.gluegen){ classifier("natives-$it") }) 25 | compileOnly(variantOf(libs.jogl){ classifier("natives-$it") }) 26 | } 27 | } 28 | 29 | pom { 30 | name = "$rootName-jogl" 31 | description = "$rootName jogl module" 32 | } 33 | 34 | moduleInfo { 35 | name = "$rootName.jogl" 36 | requiresTransitive = arrayListOf( 37 | "openglfx" 38 | ) 39 | exports = arrayListOf( 40 | "com.huskerdev.openglfx.jogl", 41 | "com.huskerdev.openglfx.jogl.events" 42 | ) 43 | } -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/internal/OGLFXClipboard.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.internal 2 | 3 | import com.badlogic.gdx.utils.Clipboard 4 | import javafx.application.Platform 5 | import javafx.scene.input.DataFormat 6 | import java.util.concurrent.CompletableFuture 7 | import java.util.function.Supplier 8 | 9 | class OGLFXClipboard: Clipboard { 10 | 11 | private fun runAndWaitFX(action: Supplier): T { 12 | if (Platform.isFxApplicationThread()) 13 | return action.get() 14 | 15 | val future = CompletableFuture() 16 | Platform.runLater { 17 | future.complete(action.get()) 18 | } 19 | return future.get() 20 | } 21 | 22 | override fun hasContents(): Boolean = 23 | getContents().isNotEmpty() 24 | 25 | override fun getContents(): String = runAndWaitFX { 26 | javafx.scene.input.Clipboard.getSystemClipboard().string 27 | } 28 | 29 | override fun setContents(content: String): Unit = runAndWaitFX { 30 | javafx.scene.input.Clipboard.getSystemClipboard().setContent( 31 | mapOf(DataFormat.PLAIN_TEXT to content) 32 | ) 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /modules/lwjgl/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.huskerdev.openglfx.plugins.utils.* 2 | 3 | plugins { 4 | alias(libs.plugins.kotlin.jvm) 5 | id("utils") 6 | id("maven") 7 | id("module-info") 8 | } 9 | 10 | configureKotlinProject() 11 | 12 | dependencies { 13 | compileOnly(*expandFXPlatforms(libs.bundles.javafx)) 14 | api(project(":modules:core")) 15 | 16 | compileOnly(platform(libs.lwjgl.bom)) 17 | compileOnly(libs.lwjgl) 18 | compileOnly(libs.lwjgl.opengl) 19 | 20 | arrayOf("linux", "linux-arm64", "macos", "macos-arm64", "windows", "windows-x86", "windows-arm64").forEach { 21 | compileOnly(variantOf(libs.lwjgl){ classifier("natives-$it") }) 22 | compileOnly(variantOf(libs.lwjgl.opengl){ classifier("natives-$it") }) 23 | } 24 | } 25 | 26 | pom { 27 | name = "$rootName-lwjgl" 28 | description = "$rootName lwjgl module" 29 | } 30 | 31 | moduleInfo { 32 | name = "$rootName.lwjgl" 33 | requiresTransitive = arrayListOf( 34 | "openglfx" 35 | ) 36 | requires = arrayListOf( 37 | "org.lwjgl", 38 | "org.lwjgl.opengl" 39 | ) 40 | exports = arrayListOf( 41 | "com.huskerdev.openglfx.lwjgl" 42 | ) 43 | } -------------------------------------------------------------------------------- /plugins/native/src/main/kotlin/com/huskerdev/plugins/compilation/types/Platform.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.compilation.types 2 | 3 | import com.huskerdev.plugins.compilation.AbstractPlatformConfiguration 4 | import com.huskerdev.plugins.compilation.NativeExtension 5 | import org.gradle.internal.os.OperatingSystem 6 | 7 | enum class Platform( 8 | val shortName: String, 9 | val condition: (OperatingSystem) -> Boolean, 10 | val configGetter: (NativeExtension) -> AbstractPlatformConfiguration, 11 | val compiler: Compiler, 12 | val defaultArch: Array, 13 | val staticExt: String, 14 | val sharedExt: String, 15 | val executableExt: String 16 | ) { 17 | WINDOWS( 18 | "win", 19 | { it.isWindows }, 20 | { it.windows }, 21 | Compiler.CL, 22 | arrayOf(Arch.X64, Arch.X86), 23 | ".lib", ".dll", ".exe" 24 | ), 25 | LINUX( 26 | "linux", 27 | { it.isLinux }, 28 | { it.linux }, 29 | Compiler.GCC, 30 | arrayOf(Arch.X64, Arch.X86), 31 | ".a", ".so", "" 32 | ), 33 | MACOS( 34 | "macos", 35 | { it.isMacOsX }, 36 | { it.macos }, 37 | Compiler.CLANG, 38 | arrayOf(Arch.X64, Arch.ARM64), 39 | ".a", ".dylib", "" 40 | ) 41 | } -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/LibGDXExecutor.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx 2 | 3 | import com.huskerdev.openglfx.GLExecutor 4 | import com.huskerdev.openglfx.canvas.GLCanvas 5 | import com.huskerdev.openglfx.libgdx.events.LibGDXDisposeEvent 6 | import com.huskerdev.openglfx.libgdx.events.LibGDXInitializeEvent 7 | import com.huskerdev.openglfx.libgdx.events.LibGDXRenderEvent 8 | import com.huskerdev.openglfx.libgdx.events.LibGDXReshapeEvent 9 | import org.lwjgl.opengl.GL 10 | 11 | class LibGDXExecutor: GLExecutor() { 12 | 13 | companion object { 14 | val LIBGDX_MODULE = LibGDXExecutor() 15 | } 16 | 17 | override fun createRenderEvent(canvas: GLCanvas, currentFps: Int, delta: Double, width: Int, height: Int, fbo: Int) = 18 | LibGDXRenderEvent((canvas as LibGDXCanvas).application, currentFps, delta, width, height, fbo) 19 | 20 | override fun createReshapeEvent(canvas: GLCanvas, width: Int, height: Int) = 21 | LibGDXReshapeEvent((canvas as LibGDXCanvas).application, width, height) 22 | 23 | override fun createInitEvent(canvas: GLCanvas) = 24 | LibGDXInitializeEvent((canvas as LibGDXCanvas).application) 25 | 26 | override fun createDisposeEvent(canvas: GLCanvas) = 27 | LibGDXDisposeEvent((canvas as LibGDXCanvas).application) 28 | 29 | override fun initGLFunctions() { 30 | super.initGLFunctions() 31 | GL.createCapabilities() 32 | } 33 | } -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_vi.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VI_H_ 2 | #define VULKAN_VI_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_NN_vi_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_NN_vi_surface 1 24 | #define VK_NN_VI_SURFACE_SPEC_VERSION 1 25 | #define VK_NN_VI_SURFACE_EXTENSION_NAME "VK_NN_vi_surface" 26 | typedef VkFlags VkViSurfaceCreateFlagsNN; 27 | typedef struct VkViSurfaceCreateInfoNN { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkViSurfaceCreateFlagsNN flags; 31 | void* window; 32 | } VkViSurfaceCreateInfoNN; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateViSurfaceNN)(VkInstance instance, const VkViSurfaceCreateInfoNN* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN( 38 | VkInstance instance, 39 | const VkViSurfaceCreateInfoNN* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_ios.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_IOS_H_ 2 | #define VULKAN_IOS_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_MVK_ios_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_MVK_ios_surface 1 24 | #define VK_MVK_IOS_SURFACE_SPEC_VERSION 3 25 | #define VK_MVK_IOS_SURFACE_EXTENSION_NAME "VK_MVK_ios_surface" 26 | typedef VkFlags VkIOSSurfaceCreateFlagsMVK; 27 | typedef struct VkIOSSurfaceCreateInfoMVK { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkIOSSurfaceCreateFlagsMVK flags; 31 | const void* pView; 32 | } VkIOSSurfaceCreateInfoMVK; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateIOSSurfaceMVK)(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK( 38 | VkInstance instance, 39 | const VkIOSSurfaceCreateInfoMVK* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /plugins/native/src/main/kotlin/com/huskerdev/plugins/compilation/utils/Execute.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.compilation.utils 2 | 3 | import org.gradle.api.GradleException 4 | import org.gradle.internal.os.OperatingSystem 5 | import java.io.BufferedReader 6 | import java.io.File 7 | import java.io.InputStreamReader 8 | 9 | fun execute(command: Array, envPath: String, directory: File){ 10 | val commandStr = command.joinToString("\n") { 11 | it.split("\n").joinToString(" ") { it.trim() } 12 | } 13 | println(commandStr) 14 | 15 | val file: File 16 | if(OperatingSystem.current().isWindows){ 17 | file = File(directory, "script.bat") 18 | file.writeText(commandStr) 19 | }else { 20 | file = File(directory, "script.sh") 21 | file.writeText("#!/bin/sh\n$commandStr") 22 | Runtime.getRuntime().exec("chmod +x ${file.absolutePath}").waitFor() 23 | } 24 | 25 | val builder = ProcessBuilder(file.absolutePath) 26 | .directory(directory) 27 | .redirectErrorStream(true) 28 | builder.environment()["Path"] = envPath 29 | 30 | val process = builder.start() 31 | val r = BufferedReader(InputStreamReader(process.inputStream)) 32 | var line = r.readLine() 33 | while (line != null) { 34 | println(line) 35 | line = r.readLine() 36 | } 37 | 38 | val result = process.waitFor() 39 | file.delete() 40 | if(result != 0) 41 | throw GradleException("Execution of '${file.absolutePath}' finished with exit code: ${process.exitValue()}") 42 | } -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_macos.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_MACOS_H_ 2 | #define VULKAN_MACOS_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_MVK_macos_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_MVK_macos_surface 1 24 | #define VK_MVK_MACOS_SURFACE_SPEC_VERSION 3 25 | #define VK_MVK_MACOS_SURFACE_EXTENSION_NAME "VK_MVK_macos_surface" 26 | typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; 27 | typedef struct VkMacOSSurfaceCreateInfoMVK { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkMacOSSurfaceCreateFlagsMVK flags; 31 | const void* pView; 32 | } VkMacOSSurfaceCreateInfoMVK; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateMacOSSurfaceMVK)(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK( 38 | VkInstance instance, 39 | const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_xlib_xrandr.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_XRANDR_H_ 2 | #define VULKAN_XLIB_XRANDR_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_EXT_acquire_xlib_display is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_EXT_acquire_xlib_display 1 24 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_SPEC_VERSION 1 25 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME "VK_EXT_acquire_xlib_display" 26 | typedef VkResult (VKAPI_PTR *PFN_vkAcquireXlibDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, VkDisplayKHR display); 27 | typedef VkResult (VKAPI_PTR *PFN_vkGetRandROutputDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, RROutput rrOutput, VkDisplayKHR* pDisplay); 28 | 29 | #ifndef VK_NO_PROTOTYPES 30 | VKAPI_ATTR VkResult VKAPI_CALL vkAcquireXlibDisplayEXT( 31 | VkPhysicalDevice physicalDevice, 32 | Display* dpy, 33 | VkDisplayKHR display); 34 | 35 | VKAPI_ATTR VkResult VKAPI_CALL vkGetRandROutputDisplayEXT( 36 | VkPhysicalDevice physicalDevice, 37 | Display* dpy, 38 | RROutput rrOutput, 39 | VkDisplayKHR* pDisplay); 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /modules/core/native/win/wgldx.cpp: -------------------------------------------------------------------------------- 1 | #include "openglfx-windows.h" 2 | 3 | 4 | 5 | jni_win_wgldx(jlong, wglDXOpenDeviceNV)(JNIEnv* env, jobject, jlong dxDevice) { 6 | checkWGLFunctions(); 7 | return (jlong)wglDXOpenDeviceNV((void*)dxDevice); 8 | } 9 | 10 | jni_win_wgldx(jboolean, wglDXCloseDeviceNV)(JNIEnv* env, jobject, jlong hDevice) { 11 | checkWGLFunctions(); 12 | return (jboolean)wglDXCloseDeviceNV((HANDLE)hDevice); 13 | } 14 | 15 | jni_win_wgldx(jlong, wglDXRegisterObjectNV)(JNIEnv* env, jobject, jlong device, jlong dxResource, jint name, jint type, jint access) { 16 | checkWGLFunctions(); 17 | return (jlong)wglDXRegisterObjectNV((HANDLE)device, (void*)dxResource, name, type, access); 18 | } 19 | 20 | jni_win_wgldx(jboolean, wglDXSetResourceShareHandleNV)(JNIEnv* env, jobject, jlong dxResource, jlong shareHandle) { 21 | checkWGLFunctions(); 22 | return (jboolean)wglDXSetResourceShareHandleNV((void*)dxResource, (HANDLE)shareHandle); 23 | } 24 | 25 | jni_win_wgldx(jboolean, wglDXUnregisterObjectNV)(JNIEnv* env, jobject, jlong device, jlong object) { 26 | checkWGLFunctions(); 27 | return (jboolean)wglDXUnregisterObjectNV((HANDLE)device, (HANDLE)object); 28 | } 29 | 30 | jni_win_wgldx(jboolean, wglDXLockObjectsNV)(JNIEnv* env, jobject, jlong handle, jlong textureHandle) { 31 | checkWGLFunctions(); 32 | return wglDXLockObjectsNV((HANDLE)handle, 1, (HANDLE*)&textureHandle); 33 | } 34 | 35 | jni_win_wgldx(jboolean, wglDXUnlockObjectsNV)(JNIEnv* env, jobject, jlong handle, jlong textureHandle) { 36 | checkWGLFunctions(); 37 | return wglDXUnlockObjectsNV((HANDLE)handle, 1, (HANDLE*)&textureHandle); 38 | } -------------------------------------------------------------------------------- /modules/core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.huskerdev.openglfx.plugins.utils.* 2 | import com.huskerdev.plugins.maven.silentApi 3 | 4 | 5 | plugins { 6 | alias(libs.plugins.kotlin.jvm) 7 | id("utils") 8 | id("maven") 9 | id("properties") 10 | id("module-info") 11 | } 12 | 13 | configureKotlinProject() 14 | 15 | dependencies { 16 | compileOnly(*expandFXPlatforms(libs.bundles.javafx)) 17 | api(libs.grapl.gl) 18 | 19 | silentApi("$group:$rootName-natives-core-win:$version") 20 | silentApi("$group:$rootName-natives-core-linux:$version") 21 | silentApi("$group:$rootName-natives-core-macos:$version") 22 | } 23 | 24 | pom { 25 | name = rootName 26 | description = "$rootName core module" 27 | } 28 | 29 | properties { 30 | name = "GLFXInfo" 31 | classpath = "com.huskerdev.openglfx" 32 | srcDir = file("kotlin") 33 | 34 | field("VERSION", version) 35 | } 36 | 37 | moduleInfo { 38 | name = rootName 39 | requiresTransitive( 40 | "kotlin.stdlib", 41 | "grapl.gl", 42 | "grapl", 43 | ) 44 | requires( 45 | "javafx.base", 46 | "javafx.graphics" 47 | ) 48 | exports( 49 | "com.huskerdev.openglfx", 50 | "com.huskerdev.openglfx.canvas", 51 | "com.huskerdev.openglfx.canvas.events", 52 | "com.huskerdev.openglfx.image", 53 | "com.huskerdev.openglfx.internal", 54 | "com.huskerdev.openglfx.internal.canvas", 55 | "com.huskerdev.openglfx.internal.platforms", 56 | "com.huskerdev.openglfx.internal.platforms.win", 57 | "com.huskerdev.openglfx.internal.platforms.macos", 58 | "com.huskerdev.openglfx.internal.shaders" 59 | ) 60 | } 61 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | 3 | kotlin = "2.1.0" 4 | pkmerboot-central-publisher = "1.1.1" 5 | 6 | javafx = "17.0.2" 7 | grapl = "2.3.13" 8 | jogl = "2.5.0" 9 | libgdx = "1.12.0" 10 | lwjgl = "3.3.2" 11 | lwjgl2 = "2.9.3" 12 | 13 | [libraries] 14 | 15 | javafx-base = { module = "org.openjfx:javafx-base", version.ref = "javafx" } 16 | javafx-controls = { module = "org.openjfx:javafx-controls", version.ref = "javafx" } 17 | javafx-graphics = { module = "org.openjfx:javafx-graphics", version.ref = "javafx" } 18 | 19 | grapl-gl = { module = "com.huskerdev:grapl-gl", version.ref = "grapl" } 20 | 21 | gluegen = { module = "org.jogamp.gluegen:gluegen-rt", version.ref = "jogl" } 22 | jogl = { module = "org.jogamp.jogl:jogl-all", version.ref = "jogl" } 23 | 24 | gdx = { module = "com.badlogicgames.gdx:gdx", version.ref = "libgdx" } 25 | gdx-backend-lwjgl3 = { module = "com.badlogicgames.gdx:gdx-backend-lwjgl3", version.ref = "libgdx" } 26 | gdx-platform = { module = "com.badlogicgames.gdx:gdx-platform", version.ref = "libgdx" } 27 | 28 | lwjgl-bom = { module = "org.lwjgl:lwjgl-bom", version.ref = "lwjgl" } 29 | lwjgl = { module = "org.lwjgl:lwjgl" } 30 | lwjgl-opengl = { module = "org.lwjgl:lwjgl-opengl" } 31 | 32 | lwjgl2 = { module = "org.lwjgl.lwjgl:lwjgl", version.ref = "lwjgl2" } 33 | 34 | 35 | [bundles] 36 | javafx = ["javafx-base", "javafx-controls", "javafx-graphics"] 37 | 38 | [plugins] 39 | kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } 40 | pkmerboot-central-publisher = { id = "io.gitee.pkmer.pkmerboot-central-publisher", version.ref = "pkmerboot-central-publisher" } 41 | 42 | -------------------------------------------------------------------------------- /plugins/native/src/main/kotlin/com/huskerdev/plugins/compilation/NativeExtension.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.compilation 2 | 3 | import com.huskerdev.plugins.compilation.types.Arch 4 | import com.huskerdev.plugins.compilation.types.OutputType 5 | import java.io.File 6 | 7 | @Suppress("unused") 8 | open class NativeExtension: AbstractPlatformConfiguration() { 9 | var baseName: String = "" 10 | var version: String = "" 11 | var classpath: String = "" 12 | 13 | var type: OutputType = OutputType.SHARED 14 | var jdk: File? = null 15 | 16 | var windows = WindowsConfiguration() 17 | var linux = LinuxConfiguration() 18 | var macos = MacosConfiguration() 19 | 20 | fun windows(block: WindowsConfiguration.() -> Unit) = 21 | windows.apply(block) 22 | 23 | fun linux(block: LinuxConfiguration.() -> Unit) = 24 | linux.apply(block) 25 | 26 | fun macos(block: MacosConfiguration.() -> Unit) = 27 | macos.apply(block) 28 | } 29 | 30 | @Suppress("unused") 31 | open class AbstractPlatformConfiguration { 32 | var jvmInclude: File? = null 33 | var includeDirs: ArrayList = arrayListOf() 34 | var srcDirs: ArrayList = arrayListOf() 35 | var libDirs: ArrayList = arrayListOf() 36 | var libs: ArrayList = arrayListOf() 37 | var architectures: ArrayList = arrayListOf() 38 | 39 | fun include(dir: File) { 40 | includeDirs.add(dir) 41 | } 42 | 43 | fun src(dir: File) { 44 | srcDirs.add(dir) 45 | } 46 | } 47 | 48 | open class WindowsConfiguration: AbstractPlatformConfiguration() { 49 | var varsDir: String? = null 50 | var sdkDir: String? = null 51 | var useDXSdk: Boolean = false 52 | } 53 | 54 | open class MacosConfiguration: AbstractPlatformConfiguration() { 55 | var frameworks: ArrayList = arrayListOf() 56 | } 57 | 58 | open class LinuxConfiguration: AbstractPlatformConfiguration() { 59 | var pkgConfig: String? = null 60 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/platforms/macos/IOSurface.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.platforms.macos 2 | 3 | import com.huskerdev.grapl.gl.GLContext 4 | import com.huskerdev.openglfx.* 5 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindTexture 6 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenTextures 7 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetInteger 8 | import com.huskerdev.openglfx.GL_BGRA 9 | import com.huskerdev.openglfx.GL_RGBA 10 | import com.huskerdev.openglfx.GL_TEXTURE_RECTANGLE 11 | import com.huskerdev.openglfx.GL_UNSIGNED_INT_8_8_8_8_REV 12 | 13 | internal class IOSurface(val width: Int, val height: Int) { 14 | 15 | companion object { 16 | @JvmStatic private external fun nCreateIOSurface(width: Int, height: Int): Long 17 | @JvmStatic private external fun nReleaseIOSurface(ioSurfaceRef: Long) 18 | @JvmStatic private external fun nCGLTexImageIOSurface2D( 19 | ctx: Long, target: Int, internalFormat: Int, 20 | width: Int, height: Int, format: Int, type: Int, 21 | ioSurfaceRef: Long, plane: Int): Int 22 | @JvmStatic private external fun nIOSurfaceLock(ioSurfaceRef: Long) 23 | @JvmStatic private external fun nIOSurfaceUnlock(ioSurfaceRef: Long) 24 | } 25 | 26 | private val handle = nCreateIOSurface(width, height) 27 | 28 | fun createBoundTexture(): Int { 29 | val oldTexture = glGetInteger(GL_TEXTURE_BINDING_2D) 30 | val texture = glGenTextures() 31 | glBindTexture(GL_TEXTURE_RECTANGLE, texture) 32 | nCGLTexImageIOSurface2D( 33 | GLContext.current().handle, 34 | GL_TEXTURE_RECTANGLE, 35 | GL_RGBA, 36 | width, height, 37 | GL_BGRA, 38 | GL_UNSIGNED_INT_8_8_8_8_REV, 39 | handle, 0) 40 | glBindTexture(GL_TEXTURE_BINDING_2D, oldTexture) 41 | return texture 42 | } 43 | 44 | fun lock() = nIOSurfaceLock(handle) 45 | 46 | fun unlock() = nIOSurfaceUnlock(handle) 47 | 48 | fun dispose() = nReleaseIOSurface(handle) 49 | } -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_wayland.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_WAYLAND_H_ 2 | #define VULKAN_WAYLAND_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_wayland_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_wayland_surface 1 24 | #define VK_KHR_WAYLAND_SURFACE_SPEC_VERSION 6 25 | #define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "VK_KHR_wayland_surface" 26 | typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; 27 | typedef struct VkWaylandSurfaceCreateInfoKHR { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkWaylandSurfaceCreateFlagsKHR flags; 31 | struct wl_display* display; 32 | struct wl_surface* surface; 33 | } VkWaylandSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateWaylandSurfaceKHR)(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct wl_display* display); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR( 40 | VkInstance instance, 41 | const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | struct wl_display* display); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_xlib.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_H_ 2 | #define VULKAN_XLIB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_xlib_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_xlib_surface 1 24 | #define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6 25 | #define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface" 26 | typedef VkFlags VkXlibSurfaceCreateFlagsKHR; 27 | typedef struct VkXlibSurfaceCreateInfoKHR { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkXlibSurfaceCreateFlagsKHR flags; 31 | Display* dpy; 32 | Window window; 33 | } VkXlibSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( 40 | VkInstance instance, 41 | const VkXlibSurfaceCreateInfoKHR* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | Display* dpy, 49 | VisualID visualID); 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_H_ 2 | #define VULKAN_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | #include "vk_platform.h" 11 | #include "vulkan_core.h" 12 | 13 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 14 | #include "vulkan_android.h" 15 | #endif 16 | 17 | #ifdef VK_USE_PLATFORM_FUCHSIA 18 | #include 19 | #include "vulkan_fuchsia.h" 20 | #endif 21 | 22 | #ifdef VK_USE_PLATFORM_IOS_MVK 23 | #include "vulkan_ios.h" 24 | #endif 25 | 26 | 27 | #ifdef VK_USE_PLATFORM_MACOS_MVK 28 | #include "vulkan_macos.h" 29 | #endif 30 | 31 | #ifdef VK_USE_PLATFORM_METAL_EXT 32 | #include "vulkan_metal.h" 33 | #endif 34 | 35 | #ifdef VK_USE_PLATFORM_VI_NN 36 | #include "vulkan_vi.h" 37 | #endif 38 | 39 | 40 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 41 | #include "vulkan_wayland.h" 42 | #endif 43 | 44 | 45 | #ifdef VK_USE_PLATFORM_WIN32_KHR 46 | #include 47 | #include "vulkan_win32.h" 48 | #endif 49 | 50 | 51 | #ifdef VK_USE_PLATFORM_XCB_KHR 52 | #include 53 | #include "vulkan_xcb.h" 54 | #endif 55 | 56 | 57 | #ifdef VK_USE_PLATFORM_XLIB_KHR 58 | #include 59 | #include "vulkan_xlib.h" 60 | #endif 61 | 62 | 63 | #ifdef VK_USE_PLATFORM_DIRECTFB_EXT 64 | #include 65 | #include "vulkan_directfb.h" 66 | #endif 67 | 68 | 69 | #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT 70 | #include 71 | #include 72 | #include "vulkan_xlib_xrandr.h" 73 | #endif 74 | 75 | 76 | #ifdef VK_USE_PLATFORM_GGP 77 | #include 78 | #include "vulkan_ggp.h" 79 | #endif 80 | 81 | 82 | #ifdef VK_USE_PLATFORM_SCREEN_QNX 83 | #include 84 | #include "vulkan_screen.h" 85 | #endif 86 | 87 | 88 | #ifdef VK_USE_PLATFORM_SCI 89 | #include 90 | #include 91 | #include "vulkan_sci.h" 92 | #endif 93 | 94 | 95 | #ifdef VK_ENABLE_BETA_EXTENSIONS 96 | #include "vulkan_beta.h" 97 | #endif 98 | 99 | #endif // VULKAN_H_ 100 | -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_directfb.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_DIRECTFB_H_ 2 | #define VULKAN_DIRECTFB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_EXT_directfb_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_EXT_directfb_surface 1 24 | #define VK_EXT_DIRECTFB_SURFACE_SPEC_VERSION 1 25 | #define VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME "VK_EXT_directfb_surface" 26 | typedef VkFlags VkDirectFBSurfaceCreateFlagsEXT; 27 | typedef struct VkDirectFBSurfaceCreateInfoEXT { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkDirectFBSurfaceCreateFlagsEXT flags; 31 | IDirectFB* dfb; 32 | IDirectFBSurface* surface; 33 | } VkDirectFBSurfaceCreateInfoEXT; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateDirectFBSurfaceEXT)(VkInstance instance, const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceDirectFBPresentationSupportEXT)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, IDirectFB* dfb); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT( 40 | VkInstance instance, 41 | const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceDirectFBPresentationSupportEXT( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | IDirectFB* dfb); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /plugins/properties/src/main/kotlin/com/huskerdev/plugins/properties/PropertiesPlugin.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.properties 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import java.io.File 6 | import java.math.BigDecimal 7 | 8 | @Suppress("unused") 9 | class PropertiesPlugin: Plugin { 10 | override fun apply(project: Project) { 11 | val config = project.extensions.create("properties", PropertiesExtension::class.java) 12 | 13 | project.afterEvaluate { 14 | createFile(config) 15 | } 16 | 17 | project.tasks.register("generatePropertyFile") { 18 | doFirst { 19 | createFile(config) 20 | } 21 | } 22 | project.tasks.getByName("compileJava").dependsOn( 23 | project.tasks.getByName("generatePropertyFile") 24 | ) 25 | } 26 | 27 | private fun createFile(config: PropertiesExtension){ 28 | if(config.name == null || 29 | config.classpath == null || 30 | config.srcDir == null 31 | ) return 32 | val file = File(config.srcDir, "${config.classpath!!.replace(".", "/")}/${config.name}.kt") 33 | file.parentFile.mkdirs() 34 | 35 | val content = config.fields.map { entry -> 36 | var field = "" 37 | 38 | field += "const val ${entry.key} = " 39 | field += if(entry.value is Int || entry.value is Double || entry.value is BigDecimal || entry.value is Boolean) 40 | entry.value 41 | else if(entry.value is Float) 42 | "${entry.value}f" 43 | else if(entry.value is Long) 44 | "${entry.value}L" 45 | else "\"${entry.value}\"" 46 | field 47 | } 48 | 49 | file.writeText(""" 50 | package ${config.classpath} 51 | 52 | // Generated with gradle 53 | class ${config.name} { 54 | companion object { 55 | ${content.joinToString("\n ")} 56 | } 57 | } 58 | """.trimIndent()) 59 | } 60 | } -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_xcb.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XCB_H_ 2 | #define VULKAN_XCB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_xcb_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_xcb_surface 1 24 | #define VK_KHR_XCB_SURFACE_SPEC_VERSION 6 25 | #define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface" 26 | typedef VkFlags VkXcbSurfaceCreateFlagsKHR; 27 | typedef struct VkXcbSurfaceCreateInfoKHR { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkXcbSurfaceCreateFlagsKHR flags; 31 | xcb_connection_t* connection; 32 | xcb_window_t window; 33 | } VkXcbSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( 40 | VkInstance instance, 41 | const VkXcbSurfaceCreateInfoKHR* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | xcb_connection_t* connection, 49 | xcb_visualid_t visual_id); 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/platforms/win/WGLDX.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.platforms.win 2 | 3 | import com.huskerdev.openglfx.internal.GLFXUtils 4 | 5 | 6 | class WGLDX { 7 | companion object { 8 | const val WGL_ACCESS_WRITE_DISCARD_NV = 0x2 9 | 10 | init { 11 | GLFXUtils.loadLibrary() 12 | } 13 | 14 | @JvmStatic private external fun wglDXOpenDeviceNV(dxDevice: Long): Long 15 | @JvmStatic private external fun wglDXCloseDeviceNV(hDevice: Long): Boolean 16 | @JvmStatic private external fun wglDXRegisterObjectNV(device: Long, dxResource: Long, name: Int, type: Int, access: Int): Long 17 | @JvmStatic private external fun wglDXSetResourceShareHandleNV(dxResource: Long, shareHandle: Long): Boolean 18 | @JvmStatic private external fun wglDXUnregisterObjectNV(device: Long, obj: Long): Boolean 19 | @JvmStatic private external fun wglDXLockObjectsNV(interopHandle: Long, sharedTextureHandle: Long): Boolean 20 | @JvmStatic private external fun wglDXUnlockObjectsNV(interopHandle: Long, sharedTextureHandle: Long): Boolean 21 | 22 | internal fun linkShareHandle(dxResource: Long, shareHandle: Long) = 23 | wglDXSetResourceShareHandleNV(dxResource, shareHandle) 24 | 25 | fun isSupported() = true 26 | } 27 | 28 | class Device( 29 | d3d9Device: D3D9.Device 30 | ){ 31 | val handle = wglDXOpenDeviceNV(d3d9Device.handle) 32 | 33 | fun registerObject(dxResource: Long, name: Int, type: Int, access: Int) = 34 | Object(this, wglDXRegisterObjectNV(handle, dxResource, name, type, access)) 35 | 36 | fun release() = 37 | wglDXCloseDeviceNV(handle) 38 | } 39 | 40 | 41 | class Object( 42 | val device: Device, 43 | val handle: Long 44 | ) { 45 | fun lock() = 46 | wglDXLockObjectsNV(device.handle, handle) 47 | 48 | fun unlock() = 49 | wglDXUnlockObjectsNV(device.handle, handle) 50 | 51 | fun release() = 52 | wglDXUnregisterObjectNV(device.handle, handle) 53 | } 54 | } -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_ggp.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_GGP_H_ 2 | #define VULKAN_GGP_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_GGP_stream_descriptor_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_GGP_stream_descriptor_surface 1 24 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_SPEC_VERSION 1 25 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_EXTENSION_NAME "VK_GGP_stream_descriptor_surface" 26 | typedef VkFlags VkStreamDescriptorSurfaceCreateFlagsGGP; 27 | typedef struct VkStreamDescriptorSurfaceCreateInfoGGP { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkStreamDescriptorSurfaceCreateFlagsGGP flags; 31 | GgpStreamDescriptor streamDescriptor; 32 | } VkStreamDescriptorSurfaceCreateInfoGGP; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateStreamDescriptorSurfaceGGP)(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateStreamDescriptorSurfaceGGP( 38 | VkInstance instance, 39 | const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | 45 | // VK_GGP_frame_token is a preprocessor guard. Do not pass it to API calls. 46 | #define VK_GGP_frame_token 1 47 | #define VK_GGP_FRAME_TOKEN_SPEC_VERSION 1 48 | #define VK_GGP_FRAME_TOKEN_EXTENSION_NAME "VK_GGP_frame_token" 49 | typedef struct VkPresentFrameTokenGGP { 50 | VkStructureType sType; 51 | const void* pNext; 52 | GgpFrameToken frameToken; 53 | } VkPresentFrameTokenGGP; 54 | 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/platforms/VkExtMemory.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.platforms 2 | 3 | 4 | class VkExtMemory{ 5 | 6 | @Suppress("unused") 7 | companion object { 8 | @JvmStatic private external fun nLoadFunctions() 9 | @JvmStatic private external fun nCreateVk(): LongArray 10 | @JvmStatic private external fun nCreateExternalImage(device: Long, physicalDevice: Long, width: Int, height: Int): LongArray 11 | @JvmStatic private external fun nFreeImage(device: Long, image: Long, memory: Long) 12 | @JvmStatic private external fun nDestroyVkDevice(device: Long) 13 | @JvmStatic private external fun nDestroyVkInstance(instance: Long) 14 | 15 | @JvmStatic private external fun vkGetMemoryFdKHR(device: Long, memory: Long): Int 16 | @JvmStatic private external fun vkGetMemoryWin32HandleKHR(device: Long, memory: Long): Long 17 | 18 | init { 19 | nLoadFunctions() 20 | } 21 | 22 | fun createVk() = 23 | nCreateVk().run { Vk(this[0], this[1], this[2]) } 24 | } 25 | 26 | data class Vk( 27 | val vkInstance: Long, 28 | val vkPhysicalDevice: Long, 29 | val vkDevice: Long 30 | ){ 31 | fun createExternalImage(width: Int, height: Int) = 32 | nCreateExternalImage(vkDevice, vkPhysicalDevice, width, height) 33 | .run { ExternalImage(this@Vk, width, height, this[0], this[1], this[2]) } 34 | 35 | fun destroy() { 36 | nDestroyVkDevice(vkDevice) 37 | nDestroyVkInstance(vkInstance) 38 | } 39 | } 40 | 41 | data class ExternalImage( 42 | val vk: Vk, 43 | val width: Int, 44 | val height: Int, 45 | val vkImage: Long, 46 | val vkDeviceMemory: Long, 47 | val size: Long 48 | ) { 49 | fun dispose() = 50 | nFreeImage(vk.vkDevice, vkImage, vkDeviceMemory) 51 | 52 | fun createMemoryFd() = 53 | vkGetMemoryFdKHR(vk.vkDevice, vkDeviceMemory) 54 | 55 | fun getMemoryWin32Handle() = 56 | vkGetMemoryWin32HandleKHR(vk.vkDevice, vkDeviceMemory) 57 | } 58 | } -------------------------------------------------------------------------------- /modules/core/native/macos/iosurface.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Nikita Shtengauer on 20.11.2023. 3 | // 4 | 5 | #include "openglfx-macos.h" 6 | 7 | #include 8 | #include 9 | 10 | 11 | 12 | 13 | jni_win_iosurface(jlong, nCreateIOSurface)(JNIEnv *, jobject, jint width, jint height) { 14 | int bytes = 4; 15 | CFStringRef keys[3]{ 16 | kIOSurfaceWidth, kIOSurfaceHeight, kIOSurfaceBytesPerElement 17 | }; 18 | CFNumberRef values[3]{ 19 | CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &width), 20 | CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &height), 21 | CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &bytes) 22 | }; 23 | 24 | CFDictionaryRef dictionary = CFDictionaryCreate( 25 | nullptr, 26 | (const void **) keys, (const void **) values, 3, 27 | &kCFCopyStringDictionaryKeyCallBacks, 28 | &kCFTypeDictionaryValueCallBacks); 29 | IOSurfaceRef ioSurfaceRef = IOSurfaceCreate(dictionary); 30 | CFRelease(dictionary); 31 | return (jlong) ioSurfaceRef; 32 | } 33 | 34 | jni_win_iosurface(void, nReleaseIOSurface)(JNIEnv *, jobject, jlong ioSurfaceRef) { 35 | CFRelease((IOSurfaceRef) ioSurfaceRef); 36 | } 37 | 38 | jni_win_iosurface(jint, nCGLTexImageIOSurface2D)(JNIEnv *, jobject, 39 | jlong ctx, jint target, jint internalFormat, jint width, jint height, jint format, 40 | jint type, 41 | jlong ioSurfaceRef, jint plane) { 42 | return (jint) CGLTexImageIOSurface2D( 43 | (CGLContextObj) ctx, 44 | (GLenum) target, (GLenum) internalFormat, 45 | (GLsizei) width, (GLsizei) height, 46 | (GLenum) format, (GLenum) type, 47 | (IOSurfaceRef) ioSurfaceRef, (GLuint) plane); 48 | } 49 | 50 | jni_win_iosurface(void, nIOSurfaceLock)(JNIEnv *, jobject, jlong ioSurfaceRef) { 51 | IOSurfaceLock((IOSurfaceRef) ioSurfaceRef, kIOSurfaceLockReadOnly, nullptr); 52 | } 53 | 54 | jni_win_iosurface(void, nIOSurfaceUnlock)(JNIEnv *, jobject, jlong ioSurfaceRef) { 55 | IOSurfaceUnlock((IOSurfaceRef) ioSurfaceRef, kIOSurfaceLockReadOnly, nullptr); 56 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/platforms/win/D3D9.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.platforms.win 2 | 3 | import com.huskerdev.openglfx.internal.GLFXUtils 4 | import com.sun.glass.ui.Screen 5 | 6 | class D3D9 { 7 | @Suppress("unused") 8 | companion object { 9 | @JvmStatic private external fun nGetDeviceFromAdapter(screenOrdinal: Int): Long 10 | 11 | @JvmStatic private external fun nCreateDeviceEx(): Long 12 | @JvmStatic private external fun nReleaseDevice(device: Long) 13 | 14 | @JvmStatic private external fun nCreateTexture(device: Long, width: Int, height: Int, shareHandle: Long): LongArray 15 | @JvmStatic private external fun nReleaseTexture(handle: Long) 16 | 17 | 18 | @JvmStatic external fun nStretchRect(device: Long, src: Long, dst: Long) 19 | @JvmStatic external fun nGetTexture(device: Long, stage: Int): Long 20 | 21 | @JvmStatic external fun nGetSurface(texture: Long, level: Int): Long 22 | @JvmStatic external fun nReleaseSurface(surface: Long): Long 23 | 24 | init { 25 | GLFXUtils.loadLibrary() 26 | } 27 | } 28 | 29 | 30 | data class Device( 31 | val handle: Long = nCreateDeviceEx() 32 | ) { 33 | companion object { 34 | val jfx: Device by lazy { 35 | Device(nGetDeviceFromAdapter(Screen.getMainScreen().adapterOrdinal)) 36 | } 37 | } 38 | 39 | fun createTexture(width: Int, height: Int, shareHandle: Long = 0) = 40 | nCreateTexture(handle, width, height, shareHandle).run { 41 | Texture(width, height, this[0], this[1]) 42 | } 43 | 44 | fun stretchRect(src: Surface, dst: Surface) = 45 | nStretchRect(handle, src.handle, dst.handle) 46 | 47 | fun getTexture(stage: Int) = 48 | nGetTexture(handle, stage) 49 | 50 | fun release() = 51 | nReleaseDevice(handle) 52 | } 53 | 54 | data class Texture( 55 | val width: Int, 56 | val height: Int, 57 | val handle: Long, 58 | val sharedHandle: Long 59 | ) { 60 | fun release() = 61 | nReleaseTexture(handle) 62 | 63 | fun getSurfaceLevel(level: Int) = 64 | Surface(nGetSurface(handle, level)) 65 | } 66 | 67 | data class Surface( 68 | val handle: Long 69 | ) { 70 | fun release() = 71 | nReleaseSurface(handle) 72 | } 73 | } -------------------------------------------------------------------------------- /.github/resources/boosty.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | -------------------------------------------------------------------------------- /modules/core/native/shared/memory-objects.cpp: -------------------------------------------------------------------------------- 1 | #include "openglfx.h" 2 | 3 | 4 | typedef void (*glCreateMemoryObjectsEXTPtr)(GLsizei n, GLuint* memoryObjects); 5 | typedef void (*glDeleteMemoryObjectsEXTPtr)(GLsizei n, const GLuint* memoryObjects); 6 | typedef void (*glImportMemoryWin32HandleEXTPtr)(GLuint memory, unsigned long size, GLenum handleType, void* handle); 7 | typedef void (*glTextureStorageMem2DEXTPtr)(jint texture, jint levels, jint internalFormat, jint width, jint height, jint memory, jlong offset); 8 | typedef void (*glImportMemoryFdEXTPtr)(GLuint memory, unsigned long size, GLenum handleType, GLint fd); 9 | 10 | 11 | static glCreateMemoryObjectsEXTPtr glCreateMemoryObjectsEXT; 12 | static glDeleteMemoryObjectsEXTPtr glDeleteMemoryObjectsEXT; 13 | static glTextureStorageMem2DEXTPtr glTextureStorageMem2DEXT; 14 | static glImportMemoryWin32HandleEXTPtr glImportMemoryWin32HandleEXT; 15 | static glImportMemoryFdEXTPtr glImportMemoryFdEXT; 16 | 17 | 18 | jni_memoryObjects(void, nLoadFunctions)(JNIEnv* env, jobject) { 19 | glCreateMemoryObjectsEXT = (glCreateMemoryObjectsEXTPtr)a_GetProcAddress("glCreateMemoryObjectsEXT"); 20 | glDeleteMemoryObjectsEXT = (glDeleteMemoryObjectsEXTPtr)a_GetProcAddress("glDeleteMemoryObjectsEXT"); 21 | glTextureStorageMem2DEXT = (glTextureStorageMem2DEXTPtr)a_GetProcAddress("glTextureStorageMem2DEXT"); 22 | glImportMemoryWin32HandleEXT = (glImportMemoryWin32HandleEXTPtr)a_GetProcAddress("glImportMemoryWin32HandleEXT"); 23 | glImportMemoryFdEXT = (glImportMemoryFdEXTPtr)a_GetProcAddress("glImportMemoryFdEXT"); 24 | } 25 | 26 | jni_memoryObjects(jint, glCreateMemoryObjectsEXT)(JNIEnv* env, jobject) { 27 | GLuint res; 28 | glCreateMemoryObjectsEXT(1, &res); 29 | return (jint)res; 30 | } 31 | 32 | jni_memoryObjects(void, glDeleteMemoryObjectsEXT)(JNIEnv* env, jobject, jint memoryObject) { 33 | glDeleteMemoryObjectsEXT(1, (const GLuint*)&memoryObject); 34 | } 35 | 36 | jni_memoryObjects(void, glImportMemoryWin32HandleEXT)(JNIEnv* env, jobject, jint memory, jlong size, jint handleType, jlong handle) { 37 | glImportMemoryWin32HandleEXT(memory, size, handleType, (void*)handle); 38 | } 39 | 40 | jni_memoryObjects(void, glTextureStorageMem2DEXT)(JNIEnv* env, jobject, jint texture, jint levels, jint internalFormat, jint width, jint height, jint memory, jlong offset) { 41 | glTextureStorageMem2DEXT(texture, levels, internalFormat, width, height, memory, offset); 42 | } 43 | 44 | jni_memoryObjects(void, glImportMemoryFdEXT)(JNIEnv* env, jobject, jint memory, jlong size, jint handleType, jint fd) { 45 | glImportMemoryFdEXT(memory, size, handleType, fd); 46 | } 47 | -------------------------------------------------------------------------------- /plugins/utils/src/main/kotlin/com/huskerdev/openglfx/plugins/utils/UtilsPlugin.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.plugins.utils 2 | 3 | import org.gradle.api.Action 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.Project 6 | import org.gradle.api.artifacts.ExternalModuleDependencyBundle 7 | import org.gradle.api.artifacts.dsl.DependencyHandler 8 | import org.gradle.api.file.DuplicatesStrategy 9 | import org.gradle.api.plugins.ExtraPropertiesExtension 10 | import org.gradle.api.plugins.JavaPluginExtension 11 | import org.gradle.api.provider.Provider 12 | import org.gradle.api.publish.maven.MavenPom 13 | import org.gradle.api.tasks.SourceSetContainer 14 | import org.gradle.jvm.tasks.Jar 15 | import org.gradle.kotlin.dsl.get 16 | import org.gradle.kotlin.dsl.getByName 17 | import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension 18 | import kotlin.collections.flatMap 19 | 20 | @Suppress("unused") 21 | class UtilsPlugin: Plugin { 22 | override fun apply(project: Project) = Unit 23 | } 24 | 25 | 26 | fun Project.configureKotlinProject(){ 27 | sourceSets["main"].java.srcDir("kotlin") 28 | sourceSets["main"].resources.srcDir("resources") 29 | sourceSets["test"].resources.srcDir("test") 30 | 31 | kotlin { 32 | jvmToolchain(11) 33 | } 34 | java { 35 | withJavadocJar() 36 | withSourcesJar() 37 | } 38 | 39 | project.tasks.getByName("jar", Jar::class) 40 | .duplicatesStrategy = DuplicatesStrategy.EXCLUDE 41 | 42 | this.dependencies.add("api", "org.jetbrains.kotlin:kotlin-stdlib-jdk8") 43 | } 44 | 45 | fun expandFXPlatforms(modules: Provider) = 46 | modules.get().flatMap { lib -> 47 | listOf("linux", "linux-aarch64", "mac", "mac-aarch64", "win").map { 48 | "${lib.module}:${lib.version}:$it" 49 | } 50 | }.toTypedArray() 51 | 52 | fun DependencyHandler.compileOnly(vararg deps: String) { 53 | deps.forEach { 54 | add("compileOnly", it) 55 | } 56 | } 57 | 58 | fun Project.pom(block: Action){ 59 | this.extensions.getByType(ExtraPropertiesExtension::class.java) 60 | .set("pom", block) 61 | } 62 | 63 | val Project.rootName 64 | get() = rootProject.name 65 | 66 | private val Project.sourceSets 67 | get() = extensions.getByType(SourceSetContainer::class.java) 68 | 69 | private fun Project.kotlin(block: KotlinJvmProjectExtension.() -> Unit) = 70 | extensions.getByType(KotlinJvmProjectExtension::class.java).apply(block) 71 | 72 | private fun Project.java(block: JavaPluginExtension.() -> Unit) = 73 | extensions.getByType(JavaPluginExtension::class.java).apply(block) 74 | 75 | -------------------------------------------------------------------------------- /plugins/native/src/main/kotlin/com/huskerdev/plugins/compilation/utils/WinUtils.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.compilation.utils 2 | 3 | import org.gradle.api.GradleException 4 | import java.io.File 5 | 6 | data class VSType( 7 | val rootDrive: File, 8 | val type: String, 9 | val version: String, 10 | val file: File 11 | ) { 12 | override fun toString() = 13 | file.toString() 14 | } 15 | 16 | fun findVCVarsDir(): String{ 17 | val vcPath = arrayListOf() 18 | for(root in File.listRoots()){ 19 | for(path in arrayOf( 20 | "Microsoft Visual Studio", 21 | "Program Files/Microsoft Visual Studio", 22 | "Program Files (x86)/Microsoft Visual Studio" 23 | )){ 24 | for(type in arrayOf("Community", "Enterprise")){ 25 | for(version in arrayOf("2022", "2019")){ 26 | val file = File(root, "$path/$version/$type") 27 | if(file.exists()) 28 | vcPath.add(VSType(root, type, version, file)) 29 | } 30 | } 31 | } 32 | } 33 | if(vcPath.isEmpty()) 34 | throw GradleException("Cant find Visual Studio directory") 35 | vcPath.sortedBy { it.file.toString() } 36 | return File(vcPath.last().file, "VC/Auxiliary/Build").absolutePath 37 | } 38 | 39 | fun findWinSDKDir(): String{ 40 | for(root in File.listRoots()){ 41 | for(path in arrayOf( 42 | "Windows Kits", 43 | "Program Files/Windows Kits", 44 | "Program Files (x86)/Windows Kits", 45 | )){ 46 | val file = File(root, "$path/10") 47 | if(file.exists()) 48 | return file.absolutePath 49 | } 50 | } 51 | throw GradleException("Cant find any Windows SDK 10") 52 | } 53 | 54 | fun findWinSDKVersion(): String{ 55 | for(dir in File(findWinSDKDir(), "Lib").listFiles()) 56 | if(File(dir, "um").exists() && File(dir, "ucrt").exists()) 57 | return dir.name 58 | throw GradleException("Cant find any version of Windows SDK 10") 59 | } 60 | 61 | fun findDXSDKDir(): String{ 62 | for(root in File.listRoots()){ 63 | for(path in arrayOf( 64 | "Program Files", 65 | "Program Files (x86)", 66 | )){ 67 | val children = File(root, path).listFiles() 68 | if(children != null){ 69 | for(child in children){ 70 | if(child.name.contains("Microsoft DirectX SDK")) 71 | return child.absolutePath 72 | } 73 | } 74 | } 75 | } 76 | throw GradleException("Cant find any DirectX SDK") 77 | } -------------------------------------------------------------------------------- /modules/core/native/include/vk_video/vulkan_video_codec_h265std_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codec_h265std_decode is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codec_h265std_decode 1 24 | #include "vulkan_video_codec_h265std.h" 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 27 | 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 29 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h265_decode" 30 | #define STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE 8 31 | typedef struct StdVideoDecodeH265PictureInfoFlags { 32 | uint32_t IrapPicFlag : 1; 33 | uint32_t IdrPicFlag : 1; 34 | uint32_t IsReference : 1; 35 | uint32_t short_term_ref_pic_set_sps_flag : 1; 36 | } StdVideoDecodeH265PictureInfoFlags; 37 | 38 | typedef struct StdVideoDecodeH265PictureInfo { 39 | StdVideoDecodeH265PictureInfoFlags flags; 40 | uint8_t sps_video_parameter_set_id; 41 | uint8_t pps_seq_parameter_set_id; 42 | uint8_t pps_pic_parameter_set_id; 43 | uint8_t NumDeltaPocsOfRefRpsIdx; 44 | int32_t PicOrderCntVal; 45 | uint16_t NumBitsForSTRefPicSetInSlice; 46 | uint16_t reserved; 47 | uint8_t RefPicSetStCurrBefore[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 48 | uint8_t RefPicSetStCurrAfter[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 49 | uint8_t RefPicSetLtCurr[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 50 | } StdVideoDecodeH265PictureInfo; 51 | 52 | typedef struct StdVideoDecodeH265ReferenceInfoFlags { 53 | uint32_t used_for_long_term_reference : 1; 54 | uint32_t unused_for_reference : 1; 55 | } StdVideoDecodeH265ReferenceInfoFlags; 56 | 57 | typedef struct StdVideoDecodeH265ReferenceInfo { 58 | StdVideoDecodeH265ReferenceInfoFlags flags; 59 | int32_t PicOrderCntVal; 60 | } StdVideoDecodeH265ReferenceInfo; 61 | 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/LibGDXCanvas.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx 2 | 3 | import com.badlogic.gdx.Application 4 | import com.badlogic.gdx.ApplicationAdapter 5 | import com.huskerdev.grapl.gl.GLContext 6 | import com.huskerdev.grapl.gl.GLProfile 7 | import com.huskerdev.openglfx.canvas.GLCanvas 8 | import com.huskerdev.openglfx.internal.GLInteropType 9 | import com.huskerdev.openglfx.libgdx.LibGDXExecutor.Companion.LIBGDX_MODULE 10 | import com.huskerdev.openglfx.libgdx.internal.OGLFXApplication 11 | import kotlin.Boolean 12 | 13 | class LibGDXCanvas( 14 | val adapter: ApplicationAdapter, 15 | val configuration: OGLFXApplicationConfiguration = OGLFXApplicationConfiguration(), 16 | flipY: Boolean = Defaults.FLIP_Y, 17 | msaa: Int = Defaults.MSAA, 18 | fps: Double = Defaults.FPS, 19 | swapBuffers: Int = Defaults.SWAP_BUFFERS, 20 | interopType: GLInteropType = Defaults.INTEROP_TYPE, 21 | profile: GLProfile = Defaults.PROFILE, 22 | glDebug: Boolean = Defaults.DEBUG, 23 | shareWith: GLContext? = Defaults.SHARE_WITH, 24 | majorVersion: Int = Defaults.MAJOR_VERSION, 25 | minorVersion: Int = Defaults.MINOR_VERSION, 26 | externalWindow: Boolean = Defaults.EXTERNAL_WINDOW, 27 | ): GLCanvas( 28 | LIBGDX_MODULE, 29 | flipY, msaa, fps, swapBuffers, interopType, 30 | profile, glDebug, shareWith, majorVersion, minorVersion, externalWindow 31 | ) { 32 | private val invokeLater = arrayListOf() 33 | lateinit var application: Application 34 | private set 35 | 36 | init { 37 | focusTraversableProperty().set(true) 38 | } 39 | 40 | override fun fireRenderEvent(fbo: Int) { 41 | super.fireRenderEvent(fbo) 42 | synchronized(invokeLater){ 43 | invokeLater.forEach { it.run() } 44 | invokeLater.clear() 45 | } 46 | adapter.render() 47 | } 48 | 49 | override fun fireReshapeEvent(width: Int, height: Int) { 50 | super.fireReshapeEvent(width, height) 51 | adapter.resize(width, height) 52 | } 53 | 54 | override fun fireInitEvent() { 55 | if(!::application.isInitialized) { 56 | application = OGLFXApplication(configuration, this) 57 | adapter.create() 58 | } 59 | super.fireInitEvent() 60 | } 61 | 62 | override fun fireDisposeEvent() { 63 | if(::application.isInitialized) 64 | adapter.dispose() 65 | super.fireDisposeEvent() 66 | } 67 | 68 | fun invokeLater(runnable: Runnable){ 69 | synchronized(invokeLater){ 70 | invokeLater.add(runnable) 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /modules/jogl/kotlin/com/huskerdev/openglfx/jogl/JOGLFXExecutor.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.jogl 2 | 3 | import com.huskerdev.grapl.gl.GLContext 4 | import com.huskerdev.openglfx.GLExecutor 5 | import com.huskerdev.openglfx.canvas.GLCanvas 6 | import com.huskerdev.openglfx.canvas.events.GLDisposeEvent 7 | import com.huskerdev.openglfx.canvas.events.GLInitializeEvent 8 | import com.huskerdev.openglfx.canvas.events.GLRenderEvent 9 | import com.huskerdev.openglfx.canvas.events.GLReshapeEvent 10 | import com.huskerdev.openglfx.jogl.events.JOGLDisposeEvent 11 | import com.huskerdev.openglfx.jogl.events.JOGLInitializeEvent 12 | import com.huskerdev.openglfx.jogl.events.JOGLRenderEvent 13 | import com.huskerdev.openglfx.jogl.events.JOGLReshapeEvent 14 | import com.jogamp.opengl.GL3 15 | import com.jogamp.opengl.GLProfile 16 | import jogamp.opengl.GLDrawableFactoryImpl 17 | 18 | @JvmField @Suppress("unused") 19 | val JOGL_MODULE = JOGLExecutor() 20 | 21 | class JOGLExecutor: GLExecutor() { 22 | 23 | private val gl = hashMapOf() 24 | 25 | override fun createRenderEvent(canvas: GLCanvas, currentFps: Int, delta: Double, width: Int, height: Int, fbo: Int): GLRenderEvent { 26 | checkInit(canvas) 27 | return JOGLRenderEvent(gl[canvas]!!, GLRenderEvent.ANY, currentFps, delta, width, height, fbo) 28 | } 29 | 30 | override fun createReshapeEvent(canvas: GLCanvas, width: Int, height: Int): GLReshapeEvent { 31 | checkInit(canvas) 32 | return JOGLReshapeEvent(gl[canvas]!!, GLReshapeEvent.ANY, width, height) 33 | } 34 | 35 | override fun createInitEvent(canvas: GLCanvas): GLInitializeEvent { 36 | checkInit(canvas) 37 | return JOGLInitializeEvent(gl[canvas]!!, GLInitializeEvent.ANY) 38 | } 39 | 40 | override fun createDisposeEvent(canvas: GLCanvas): GLDisposeEvent { 41 | val gl = gl.remove(canvas) 42 | return JOGLDisposeEvent(gl!!, GLDisposeEvent.ANY) 43 | } 44 | 45 | private fun checkInit(canvas: GLCanvas){ 46 | if(!gl.containsKey(canvas)){ 47 | // https://github.com/husker-dev/openglfx/issues/22 48 | // 'java.awt.headless' is used to prevent lock on macOS, when JOGL 49 | // tries to initialize using AWT classes 50 | val originalHeadless = System.getProperty("java.awt.headless") 51 | val ctx = GLContext.current() 52 | 53 | System.setProperty("java.awt.headless", "true") 54 | val factory = GLDrawableFactoryImpl.getFactory(GLProfile.getDefaultDevice()) 55 | ctx.makeCurrent() 56 | gl[canvas] = factory.createExternalGLContext().gl.gL3 57 | if(originalHeadless != null) 58 | System.setProperty("java.awt.headless", originalHeadless) 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/image/GLImageManager.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.image 2 | 3 | import com.huskerdev.openglfx.* 4 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindFramebuffer 5 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindTexture 6 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenTextures 7 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetInteger 8 | import com.huskerdev.openglfx.GLExecutor.Companion.glReadPixels 9 | import com.huskerdev.openglfx.GLExecutor.Companion.glTexImage2D 10 | import com.huskerdev.openglfx.internal.Framebuffer 11 | import javafx.scene.image.Image 12 | import javafx.scene.image.PixelBuffer 13 | import javafx.scene.image.PixelFormat 14 | import javafx.scene.image.WritableImage 15 | import java.nio.ByteBuffer 16 | 17 | 18 | class GLImageManager { 19 | companion object { 20 | 21 | @JvmStatic 22 | fun toGL(image: Image, x: Int, y: Int, width: Int, height: Int): Framebuffer { 23 | val buffer = ByteBuffer.allocateDirect(width * height * 4) 24 | image.pixelReader.getPixels(x, y, width, height, PixelFormat.getByteBgraPreInstance(), buffer, width * 4) 25 | 26 | val texture = glGenTextures() 27 | glBindTexture(GL_TEXTURE_2D, texture) 28 | glTexImage2D( 29 | GL_TEXTURE_2D, 0, 30 | GL_RGBA, width, height, 0, 31 | GL_BGRA, 32 | GL_UNSIGNED_BYTE, buffer) 33 | 34 | return Framebuffer.Default(width, height, texture = texture) 35 | } 36 | 37 | @JvmStatic 38 | fun fromGL(fbo: Int, x: Int, y: Int, width: Int, height: Int): Image { 39 | val oldDrawBuffer = glGetInteger(GL_DRAW_FRAMEBUFFER_BINDING) 40 | val oldReadBuffer = glGetInteger(GL_READ_FRAMEBUFFER_BINDING) 41 | 42 | glBindFramebuffer(GL_FRAMEBUFFER, fbo) 43 | val buffer = ByteBuffer.allocateDirect(width * height * 4) 44 | glReadPixels(x, y, width, height, 45 | GL_BGRA, 46 | GL_UNSIGNED_INT_8_8_8_8_REV, buffer) 47 | 48 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDrawBuffer) 49 | glBindFramebuffer(GL_READ_FRAMEBUFFER, oldReadBuffer) 50 | 51 | return WritableImage(PixelBuffer(width, height, buffer, PixelFormat.getByteBgraPreInstance())) 52 | } 53 | 54 | @JvmStatic 55 | fun toGL(image: Image) = 56 | toGL(image, 0, 0, image.width.toInt(), image.height.toInt()) 57 | @JvmStatic 58 | fun toGL(image: Image, width: Int, height: Int) = 59 | toGL(image, 0, 0, width, height) 60 | @JvmStatic 61 | fun fromGL(fbo: Int, width: Int, height: Int) = 62 | fromGL(fbo, 0, 0, width, height) 63 | } 64 | } -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/OGLFXApplicationConfiguration.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx 2 | 3 | import com.badlogic.gdx.Files.FileType 4 | import com.badlogic.gdx.Preferences 5 | 6 | // Adaptation of Lwjgl3ApplicationConfiguration 7 | class OGLFXApplicationConfiguration { 8 | 9 | companion object { 10 | var errorStream = System.err 11 | 12 | fun copy(config: OGLFXApplicationConfiguration): OGLFXApplicationConfiguration { 13 | val copy = OGLFXApplicationConfiguration() 14 | copy.set(config) 15 | return copy 16 | } 17 | } 18 | 19 | /** Whether to disable audio or not. If set to true, the returned audio class instances like {@link Audio} or {@link Music} 20 | * will be mock implementations. */ 21 | var disableAudio = false 22 | 23 | /** The maximum amount of threads to use for network requests. Default is {@link Integer#MAX_VALUE}. */ 24 | var maxNetThreads = Int.MAX_VALUE 25 | 26 | internal var audioDeviceSimultaneousSources = 16 27 | internal var audioDeviceBufferSize = 512 28 | internal var audioDeviceBufferCount = 9 29 | 30 | internal var preferencesDirectory = ".prefs/" 31 | internal var preferencesFileType = FileType.External 32 | 33 | /** Sets the audio device configuration. 34 | * 35 | * @param simultaneousSources the maximum amount of sources that can be played simultaneously (default 16) 36 | * @param bufferSize the audio device buffer size in samples (default 512) 37 | * @param bufferCount the audio device buffer count (default 9) */ 38 | fun setAudioConfig(simultaneousSources: Int, bufferSize: Int, bufferCount: Int) { 39 | audioDeviceSimultaneousSources = simultaneousSources 40 | audioDeviceBufferSize = bufferSize 41 | audioDeviceBufferCount = bufferCount 42 | } 43 | 44 | /** Sets the directory where [Preferences] will be stored, as well as the file type to be used to store them. Defaults to 45 | * "$USER_HOME/.prefs/" and [FileType.External]. */ 46 | fun setPreferencesConfig(preferencesDirectory: String, preferencesFileType: FileType) { 47 | this.preferencesDirectory = preferencesDirectory 48 | this.preferencesFileType = preferencesFileType 49 | } 50 | 51 | fun set(config: OGLFXApplicationConfiguration){ 52 | this.disableAudio = config.disableAudio 53 | this.maxNetThreads = config.maxNetThreads 54 | 55 | this.audioDeviceSimultaneousSources = config.audioDeviceSimultaneousSources 56 | this.audioDeviceBufferSize = config.audioDeviceBufferSize 57 | this.audioDeviceBufferCount = config.audioDeviceBufferCount 58 | 59 | this.preferencesDirectory = config.preferencesDirectory 60 | this.preferencesFileType = config.preferencesFileType 61 | } 62 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/shaders/FXAAShader.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.shaders 2 | 3 | internal class FXAAShader: PassthroughShader( 4 | fragmentSource = """ 5 | #define FXAA_SPAN_MAX 8.0 6 | #define FXAA_REDUCE_MUL (1.0/FXAA_SPAN_MAX) 7 | #define FXAA_REDUCE_MIN (1.0/128.0) 8 | #define FXAA_SUBPIX_SHIFT (1.0/4.0) 9 | 10 | vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 texSize) { 11 | vec2 rcpFrame = 1. / texSize.xy; 12 | vec2 uv2 = fragCoord / texSize.xy; 13 | vec4 uv = vec4(uv2, uv2 - (rcpFrame * (0.5 + FXAA_SUBPIX_SHIFT))); 14 | 15 | vec3 rgbNW = texture2D(tex, uv.zw).rgb; 16 | vec3 rgbNE = texture2D(tex, uv.zw + vec2(1,0)*rcpFrame.xy).rgb; 17 | vec3 rgbSW = texture2D(tex, uv.zw + vec2(0,1)*rcpFrame.xy).rgb; 18 | vec3 rgbSE = texture2D(tex, uv.zw + vec2(1,1)*rcpFrame.xy).rgb; 19 | vec3 rgbM = texture2D(tex, uv.xy).rgb; 20 | 21 | vec3 luma = vec3(0.299, 0.587, 0.114); 22 | float lumaNW = dot(rgbNW, luma); 23 | float lumaNE = dot(rgbNE, luma); 24 | float lumaSW = dot(rgbSW, luma); 25 | float lumaSE = dot(rgbSE, luma); 26 | float lumaM = dot(rgbM, luma); 27 | 28 | float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); 29 | float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); 30 | 31 | vec2 dir; 32 | dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); 33 | dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); 34 | 35 | float dirReduce = max( 36 | (lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), 37 | FXAA_REDUCE_MIN); 38 | float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce); 39 | 40 | dir = min(vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX), 41 | max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), 42 | dir * rcpDirMin)) * rcpFrame.xy; 43 | 44 | vec4 rgbA = (1.0/2.0) * ( 45 | texture2D(tex, uv.xy + dir * (1.0/3.0 - 0.5)).rgba + 46 | texture2D(tex, uv.xy + dir * (2.0/3.0 - 0.5)).rgba); 47 | vec4 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * ( 48 | texture2D(tex, uv.xy + dir * (0.0/3.0 - 0.5)).rgba + 49 | texture2D(tex, uv.xy + dir * (3.0/3.0 - 0.5)).rgba); 50 | 51 | float lumaB = dot(rgbB.rgb, luma); 52 | 53 | if((lumaB < lumaMin) || (lumaB > lumaMax)) return rgbA; 54 | return rgbB; 55 | } 56 | 57 | uniform sampler2D texture; 58 | uniform vec2 size; 59 | 60 | void main() { 61 | gl_FragColor = fxaa(texture, gl_FragCoord.xy, size); 62 | } 63 | """.trimIndent() 64 | ) -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /modules/core/native/include/vk_video/vulkan_video_codec_h264std_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codec_h264std_decode is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codec_h264std_decode 1 24 | #include "vulkan_video_codec_h264std.h" 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 27 | 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 29 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h264_decode" 30 | #define STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE 2 31 | 32 | typedef enum StdVideoDecodeH264FieldOrderCount { 33 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_TOP = 0, 34 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_BOTTOM = 1, 35 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_INVALID = 0x7FFFFFFF, 36 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_MAX_ENUM = 0x7FFFFFFF 37 | } StdVideoDecodeH264FieldOrderCount; 38 | typedef struct StdVideoDecodeH264PictureInfoFlags { 39 | uint32_t field_pic_flag : 1; 40 | uint32_t is_intra : 1; 41 | uint32_t IdrPicFlag : 1; 42 | uint32_t bottom_field_flag : 1; 43 | uint32_t is_reference : 1; 44 | uint32_t complementary_field_pair : 1; 45 | } StdVideoDecodeH264PictureInfoFlags; 46 | 47 | typedef struct StdVideoDecodeH264PictureInfo { 48 | StdVideoDecodeH264PictureInfoFlags flags; 49 | uint8_t seq_parameter_set_id; 50 | uint8_t pic_parameter_set_id; 51 | uint8_t reserved1; 52 | uint8_t reserved2; 53 | uint16_t frame_num; 54 | uint16_t idr_pic_id; 55 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 56 | } StdVideoDecodeH264PictureInfo; 57 | 58 | typedef struct StdVideoDecodeH264ReferenceInfoFlags { 59 | uint32_t top_field_flag : 1; 60 | uint32_t bottom_field_flag : 1; 61 | uint32_t used_for_long_term_reference : 1; 62 | uint32_t is_non_existing : 1; 63 | } StdVideoDecodeH264ReferenceInfoFlags; 64 | 65 | typedef struct StdVideoDecodeH264ReferenceInfo { 66 | StdVideoDecodeH264ReferenceInfoFlags flags; 67 | uint16_t FrameNum; 68 | uint16_t reserved; 69 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 70 | } StdVideoDecodeH264ReferenceInfo; 71 | 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /.github/workflows/maven_publish.yml: -------------------------------------------------------------------------------- 1 | name: Maven Central publishing 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | linux: 8 | runs-on: ubuntu-22.04 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: actions/setup-java@v4 12 | with: 13 | distribution: 'temurin' 14 | java-version: '17' 15 | 16 | - name: "Importing GPG key" 17 | run: | 18 | sudo gpg --batch --passphrase ${{ secrets.GPG_PASSPHRASE }} --import gradle/secring.gpg 19 | 20 | - name: "Install build dependencies" 21 | run: | 22 | sudo dpkg --add-architecture i386 23 | sudo apt-get update 24 | sudo apt-get install g++-multilib 25 | 26 | - name: "Prepare" 27 | run: | 28 | chmod +x ./gradlew 29 | 30 | - name: "Building and publishing" 31 | run: > 32 | ./gradlew publishToMavenCentralPortal 33 | -Dorg.gradle.jvmargs=-Xmx4096M 34 | -Dorg.gradle.project.signing.password=${{ secrets.GPG_PASSPHRASE }} 35 | -Dorg.gradle.project.signing.secretKeyRingFile=${{ github.workspace }}/gradle/secring.gpg 36 | -Dorg.gradle.project.ossrhUsername=${{ secrets.SONATYPE_USERNAME }} 37 | -Dorg.gradle.project.ossrhPassword=${{ secrets.SONATYPE_PASSWORD }} 38 | 39 | windows: 40 | runs-on: windows-latest 41 | steps: 42 | - uses: actions/checkout@v4 43 | - uses: actions/setup-java@v4 44 | with: 45 | distribution: 'temurin' 46 | java-version: '17' 47 | 48 | - name: "Importing GPG key" 49 | run: | 50 | gpg --batch --passphrase ${{ secrets.GPG_PASSPHRASE }} --import gradle/secring.gpg 51 | 52 | - name: "Building and publishing" 53 | run: > 54 | ./gradlew publishNatives 55 | "-Dorg.gradle.project.signing.password=${{ secrets.GPG_PASSPHRASE }}" 56 | "-Dorg.gradle.project.signing.secretKeyRingFile=${{ github.workspace }}/gradle/secring.gpg" 57 | "-Dorg.gradle.project.ossrhUsername=${{ secrets.SONATYPE_USERNAME }}" 58 | "-Dorg.gradle.project.ossrhPassword=${{ secrets.SONATYPE_PASSWORD }}" 59 | 60 | macos: 61 | runs-on: macos-latest 62 | steps: 63 | - uses: actions/checkout@v4 64 | - uses: actions/setup-java@v4 65 | with: 66 | distribution: 'temurin' 67 | java-version: '17' 68 | 69 | - name: "Importing GPG key" 70 | run: | 71 | gpg --batch --passphrase ${{ secrets.GPG_PASSPHRASE }} --import gradle/secring.gpg 72 | 73 | - name: "Prepare" 74 | run: | 75 | chmod +x ./gradlew 76 | 77 | - name: "Building and publishing" 78 | run: > 79 | ./gradlew publishNatives 80 | -Dorg.gradle.project.signing.password=${{ secrets.GPG_PASSPHRASE }} 81 | -Dorg.gradle.project.signing.secretKeyRingFile=${{ github.workspace }}/gradle/secring.gpg 82 | -Dorg.gradle.project.ossrhUsername=${{ secrets.SONATYPE_USERNAME }} 83 | -Dorg.gradle.project.ossrhPassword=${{ secrets.SONATYPE_PASSWORD }} 84 | -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/internal/FXPixmapImage.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.internal 2 | 3 | import com.badlogic.gdx.graphics.Pixmap 4 | import javafx.scene.image.PixelFormat 5 | import javafx.scene.image.PixelReader 6 | import javafx.scene.image.WritableImage 7 | import javafx.scene.image.WritablePixelFormat 8 | import javafx.scene.paint.Color 9 | import java.nio.Buffer 10 | import java.nio.ByteBuffer 11 | import java.nio.IntBuffer 12 | 13 | 14 | class FXPixmapImage(pixmap: Pixmap): WritableImage(object: PixelReader { 15 | 16 | override fun getPixelFormat() = PixelFormat.getIntArgbInstance() 17 | 18 | override fun getArgb(x: Int, y: Int) = when(pixmap.format){ 19 | Pixmap.Format.Alpha, Pixmap.Format.Intensity, Pixmap.Format.LuminanceAlpha -> 20 | 0x00ffffff or (pixmap.getPixel(x, y) shl 24) 21 | Pixmap.Format.RGB888 -> 22 | pixmap.getPixel(x, y) or 0xff000000.toInt() 23 | Pixmap.Format.RGBA8888 -> { 24 | pixmap.getPixel(x, y) shr 8 or(pixmap.getPixel(x, y) shl 24) 25 | } 26 | Pixmap.Format.RGB565, Pixmap.Format.RGBA4444, null -> TODO() 27 | } 28 | 29 | override fun getColor(x: Int, y: Int): Color { 30 | val intColor = getArgb(x, y) 31 | return Color( 32 | (intColor shr 16 and 0x000000ff) / 255.0, 33 | (intColor shr 8 and 0x000000ff) / 255.0, 34 | (intColor and 0x000000ff) / 255.0, 35 | (intColor shr 24 and 0x000000ff) / 255.0) 36 | } 37 | 38 | override fun getPixels( 39 | x: Int, 40 | y: Int, 41 | w: Int, 42 | h: Int, 43 | pixelformat: WritablePixelFormat?, 44 | buffer: T, 45 | scanlineStride: Int 46 | ) { 47 | TODO("Not yet implemented") 48 | } 49 | 50 | override fun getPixels( 51 | x: Int, 52 | y: Int, 53 | w: Int, 54 | h: Int, 55 | pixelformat: WritablePixelFormat?, 56 | buffer: ByteArray, 57 | offset: Int, 58 | scanlineStride: Int 59 | ) { 60 | var index = offset 61 | for(xi in x until w){ 62 | for(yi in y until h){ 63 | val color = getColor(xi, yi) 64 | buffer[index++] = (color.opacity * 255).toInt().toByte() 65 | buffer[index++] = (color.red * 255).toInt().toByte() 66 | buffer[index++] = (color.green * 255).toInt().toByte() 67 | buffer[index++] = (color.blue * 255).toInt().toByte() 68 | } 69 | } 70 | } 71 | 72 | override fun getPixels( 73 | x: Int, 74 | y: Int, 75 | w: Int, 76 | h: Int, 77 | pixelformat: WritablePixelFormat?, 78 | buffer: IntArray, 79 | offset: Int, 80 | scanlineStride: Int 81 | ) { 82 | var index = offset 83 | for(xi in x until w){ 84 | for(yi in y until h){ 85 | buffer[index++] = getArgb(x, y) 86 | } 87 | } 88 | } 89 | }, pixmap.width, pixmap.height) -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright 2014-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | 11 | #ifndef VK_PLATFORM_H_ 12 | #define VK_PLATFORM_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif // __cplusplus 18 | 19 | /* 20 | *************************************************************************************************** 21 | * Platform-specific directives and type declarations 22 | *************************************************************************************************** 23 | */ 24 | 25 | /* Platform-specific calling convention macros. 26 | * 27 | * Platforms should define these so that Vulkan clients call Vulkan commands 28 | * with the same calling conventions that the Vulkan implementation expects. 29 | * 30 | * VKAPI_ATTR - Placed before the return type in function declarations. 31 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 32 | * VKAPI_CALL - Placed after the return type in function declarations. 33 | * Useful for MSVC-style calling convention syntax. 34 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 35 | * 36 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 37 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 38 | */ 39 | #if defined(_WIN32) 40 | // On Windows, Vulkan commands use the stdcall convention 41 | #define VKAPI_ATTR 42 | #define VKAPI_CALL __stdcall 43 | #define VKAPI_PTR VKAPI_CALL 44 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 45 | #error "Vulkan is not supported for the 'armeabi' NDK ABI" 46 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 47 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 48 | // calling convention, i.e. float parameters are passed in registers. This 49 | // is true even if the rest of the application passes floats on the stack, 50 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 51 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 52 | #define VKAPI_CALL 53 | #define VKAPI_PTR VKAPI_ATTR 54 | #else 55 | // On other platforms, use the default calling convention 56 | #define VKAPI_ATTR 57 | #define VKAPI_CALL 58 | #define VKAPI_PTR 59 | #endif 60 | 61 | #if !defined(VK_NO_STDDEF_H) 62 | #include 63 | #endif // !defined(VK_NO_STDDEF_H) 64 | 65 | #if !defined(VK_NO_STDINT_H) 66 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 67 | typedef signed __int8 int8_t; 68 | typedef unsigned __int8 uint8_t; 69 | typedef signed __int16 int16_t; 70 | typedef unsigned __int16 uint16_t; 71 | typedef signed __int32 int32_t; 72 | typedef unsigned __int32 uint32_t; 73 | typedef signed __int64 int64_t; 74 | typedef unsigned __int64 uint64_t; 75 | #else 76 | #include 77 | #endif 78 | #endif // !defined(VK_NO_STDINT_H) 79 | 80 | #ifdef __cplusplus 81 | } // extern "C" 82 | #endif // __cplusplus 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /plugins/moduleInfo/src/main/kotlin/com/huskerdev/plugins/moduleinfo/ModuleInfoPlugin.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.moduleinfo 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import org.gradle.api.tasks.Copy 6 | import org.gradle.api.tasks.SourceSetContainer 7 | import org.gradle.jvm.tasks.Jar 8 | import org.objectweb.asm.* 9 | import org.objectweb.asm.Opcodes 10 | import java.io.File 11 | 12 | @Suppress("unused") 13 | class ModuleInfoPlugin: Plugin { 14 | override fun apply(project: Project) { 15 | val config = project.extensions.create("moduleInfo", ModuleInfoExtension::class.java) 16 | config.name = "unnamed" 17 | config.open = false 18 | 19 | project.tasks.register("createModuleInfo") { 20 | doFirst { 21 | val classWriter = ClassWriter(0) 22 | classWriter.visit(Opcodes.V9, Opcodes.ACC_MODULE, "module-info", null, null, null) 23 | 24 | val moduleVisitor = classWriter.visitModule( 25 | config.name, 26 | if(config.open) Opcodes.ACC_OPEN else 0, 27 | null) 28 | moduleVisitor.visitRequire("java.base", 0, null) 29 | 30 | config.requires.forEach { 31 | moduleVisitor.visitRequire(it, 0, null) 32 | } 33 | config.requiresTransitive.forEach { 34 | moduleVisitor.visitRequire(it, Opcodes.ACC_TRANSITIVE, null) 35 | } 36 | config.requiresStatic.forEach { 37 | moduleVisitor.visitRequire(it, Opcodes.ACC_STATIC_PHASE, null) 38 | } 39 | config.exports.forEach { 40 | moduleVisitor.visitExport(it.replace(".", "/"), 0) 41 | } 42 | config.opens.forEach { 43 | moduleVisitor.visitOpen(it.replace(".", "/"), 0) 44 | } 45 | 46 | moduleVisitor.visitEnd() 47 | classWriter.visitEnd() 48 | 49 | project.moduleInfoBuildDir.mkdirs() 50 | File(project.moduleInfoBuildDir, "module-info.class").writeBytes(classWriter.toByteArray()) 51 | } 52 | } 53 | 54 | project.tasks.register("packModuleInfo", Copy::class.java) { 55 | group = "build" 56 | 57 | dependsOn("createModuleInfo") 58 | 59 | from(project.moduleInfoBuildDir) 60 | into(project.sourceSets.getByName("main").output.resourcesDir!!) 61 | } 62 | 63 | project.tasks.getByName("jar").dependsOn("packModuleInfo") 64 | project.tasks.getByName("javadoc").mustRunAfter("packModuleInfo") 65 | 66 | project.afterEvaluate { 67 | project.tasks.named("jar", Jar::class.java) { 68 | manifest { 69 | attributes(mapOf("Automatic-Module-Name" to config.name)) 70 | } 71 | } 72 | } 73 | } 74 | 75 | 76 | private val Project.moduleInfoBuildDir 77 | get() = File(layout.buildDirectory.get().asFile, "moduleinfo") 78 | 79 | private val Project.sourceSets 80 | get() = extensions.getByType(SourceSetContainer::class.java) 81 | 82 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/canvas/BlitCanvas.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.canvas 2 | 3 | import com.huskerdev.openglfx.* 4 | import com.huskerdev.openglfx.canvas.GLCanvas 5 | import com.huskerdev.openglfx.internal.GLFXUtils 6 | import com.huskerdev.openglfx.internal.NGGLCanvas 7 | 8 | import com.huskerdev.openglfx.internal.Framebuffer 9 | import com.sun.prism.Graphics 10 | import com.sun.prism.PixelFormat 11 | 12 | 13 | import com.sun.prism.Texture 14 | import java.nio.ByteBuffer 15 | import java.util.concurrent.atomic.AtomicBoolean 16 | 17 | 18 | open class BlitCanvas( 19 | canvas: GLCanvas 20 | ) : NGGLCanvas(canvas) { 21 | 22 | override fun onRenderThreadInit() = Unit 23 | override fun onRenderThreadEnd() = Unit 24 | override fun createSwapBuffer() = BlitSwapBuffer() 25 | 26 | protected inner class BlitSwapBuffer: SwapBuffer() { 27 | private lateinit var fbo: Framebuffer 28 | private lateinit var interopFBO: Framebuffer.Default 29 | private lateinit var dataBuffer: ByteBuffer 30 | 31 | private lateinit var fxTexture: Texture 32 | private var contentChanged = false 33 | 34 | private val shouldUpdateBinding = AtomicBoolean() 35 | 36 | override fun render(width: Int, height: Int): Framebuffer { 37 | if(checkFramebufferSize(width, height)) 38 | canvas.fireReshapeEvent(width, height) 39 | 40 | fbo.bindFramebuffer() 41 | canvas.fireRenderEvent(fbo.id) 42 | fbo.blitTo(interopFBO) 43 | 44 | interopFBO.readPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, dataBuffer) 45 | contentChanged = true 46 | 47 | return fbo 48 | } 49 | 50 | private fun checkFramebufferSize(width: Int, height: Int): Boolean{ 51 | if(!this::fbo.isInitialized || fbo.width != width || fbo.height != height){ 52 | dispose() 53 | 54 | dataBuffer = GLFXUtils.createDirectBuffer(width * height * 4) 55 | interopFBO = Framebuffer.Default(width, height) 56 | fbo = createFramebufferForRender(width, height) 57 | 58 | shouldUpdateBinding.set(true) 59 | return true 60 | } 61 | return false 62 | } 63 | 64 | override fun getTextureForDisplay(g: Graphics): Texture { 65 | val width = fbo.width 66 | val height = fbo.height 67 | 68 | if(shouldUpdateBinding.getAndSet(false)){ 69 | disposeFXResources() 70 | 71 | fxTexture = GLFXUtils.createPermanentFXTexture(width, height) 72 | } 73 | 74 | if(contentChanged) { 75 | contentChanged = false 76 | fxTexture.update( 77 | dataBuffer, PixelFormat.BYTE_BGRA_PRE, 78 | 0, 0, 79 | 0, 0, 80 | width, height, 81 | width * 4, true 82 | ) 83 | } 84 | 85 | return fxTexture 86 | } 87 | 88 | override fun dispose() { 89 | if (this::fbo.isInitialized) fbo.delete() 90 | if (this::interopFBO.isInitialized) interopFBO.delete() 91 | if (this::dataBuffer.isInitialized) GLFXUtils.cleanDirectBuffer(dataBuffer) 92 | } 93 | 94 | override fun disposeFXResources() { 95 | if (this::fxTexture.isInitialized) fxTexture.dispose() 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /modules/core/native/win/dx9.cpp: -------------------------------------------------------------------------------- 1 | #include "openglfx-windows.h" 2 | 3 | #include 4 | 5 | 6 | extern "C"{ 7 | typedef jlong (*nGetContextPtr) (JNIEnv *jEnv, jclass, jint adapterOrdinal); 8 | typedef jlong (*nGetDevicePtr) (JNIEnv *jEnv, jclass, jlong context); 9 | 10 | static nGetContextPtr nGetContext; 11 | static nGetDevicePtr nGetDevice; 12 | } 13 | 14 | jni_win_d3d9(jlong, nGetDeviceFromAdapter)(JNIEnv* env, jclass obj, jint adapterOrdinal) { 15 | HMODULE module = GetModuleHandleA("prism_d3d.dll"); 16 | nGetContext = (nGetContextPtr)GetProcAddress(module, "Java_com_sun_prism_d3d_D3DResourceFactory_nGetContext"); 17 | nGetDevice = (nGetDevicePtr)GetProcAddress(module, "Java_com_sun_prism_d3d_D3DResourceFactory_nGetDevice"); 18 | 19 | return nGetDevice(env, obj, nGetContext(env, obj, adapterOrdinal)); 20 | } 21 | 22 | jni_win_d3d9(jlong, nCreateDeviceEx)(JNIEnv* env, jobject) { 23 | IDirect3D9Ex* direct3D = NULL; 24 | Direct3DCreate9Ex(D3D_SDK_VERSION, &direct3D); 25 | 26 | D3DPRESENT_PARAMETERS pp = {}; 27 | pp.Windowed = TRUE; 28 | pp.SwapEffect = D3DSWAPEFFECT_DISCARD; 29 | pp.hDeviceWindow = NULL; 30 | pp.BackBufferCount = 1; 31 | pp.BackBufferWidth = 1; 32 | pp.BackBufferHeight = 1; 33 | 34 | IDirect3DDevice9Ex* device = NULL; 35 | direct3D->CreateDeviceEx( 36 | D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 37 | NULL, 38 | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, 39 | &pp, NULL, &device); 40 | 41 | return (jlong)device; 42 | } 43 | 44 | jni_win_d3d9(void, nReleaseDevice)(JNIEnv* env, jobject, jlong _device) { 45 | IDirect3DDevice9Ex* device = (IDirect3DDevice9Ex*)_device; 46 | device->Release(); 47 | } 48 | 49 | jni_win_d3d9(jlongArray, nCreateTexture)(JNIEnv* env, jobject, jlong _device, jint width, jint height, jlong _shareHandle) { 50 | IDirect3DDevice9Ex* device = (IDirect3DDevice9Ex*)_device; 51 | 52 | // It is important to set NULL 53 | IDirect3DTexture9* texture = NULL; 54 | HANDLE sharedHandle = (HANDLE)_shareHandle; 55 | device->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, &sharedHandle); 56 | 57 | return createLongArray(env, { (jlong)texture, (jlong)sharedHandle }); 58 | } 59 | 60 | jni_win_d3d9(void, nReleaseTexture)(JNIEnv* env, jobject, jlong handle) { 61 | IDirect3DTexture9* texture = (IDirect3DTexture9*)handle; 62 | texture->Release(); 63 | } 64 | 65 | jni_win_d3d9(void, nReleaseSurface)(JNIEnv* env, jobject, jlong _surface) { 66 | IDirect3DSurface9* surface = (IDirect3DSurface9*)_surface; 67 | surface->Release(); 68 | } 69 | 70 | jni_win_d3d9(void, nStretchRect)(JNIEnv* env, jobject, jlong _device, jlong _src, jlong _dst) { 71 | IDirect3DDevice9Ex* device = (IDirect3DDevice9Ex*)_device; 72 | 73 | IDirect3DSurface9* src = (IDirect3DSurface9*)_src; 74 | IDirect3DSurface9* dst = (IDirect3DSurface9*)_dst; 75 | 76 | device->StretchRect(src, NULL, dst, NULL, D3DTEXF_NONE); 77 | } 78 | 79 | jni_win_d3d9(jlong, nGetTexture)(JNIEnv* env, jobject, jlong _device, jint stage) { 80 | IDirect3DDevice9Ex* device = (IDirect3DDevice9Ex*)_device; 81 | IDirect3DBaseTexture9* texture = 0; 82 | device->GetTexture(stage, &texture); 83 | return (jlong)texture; 84 | } 85 | 86 | 87 | jni_win_d3d9(jlong, nGetSurface)(JNIEnv* env, jobject, jlong _texture, jint level) { 88 | IDirect3DTexture9* texture = (IDirect3DTexture9*)_texture; 89 | IDirect3DSurface9* surface = 0; 90 | texture->GetSurfaceLevel(0, &surface); 91 | return (jlong)surface; 92 | } 93 | -------------------------------------------------------------------------------- /modules/core/native/win/openglfx-windows.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENGLFX_WINDOWS_H 2 | #define OPENGLFX_WINDOWS_H 3 | 4 | #include 5 | 6 | 7 | #define jni_win(returnType, fun) extern "C" JNIEXPORT returnType JNICALL Java_com_huskerdev_openglfx_internal_platforms_win_WGLFunctions_##fun 8 | #define jni_win_d3d9(returnType, fun) extern "C" JNIEXPORT returnType JNICALL Java_com_huskerdev_openglfx_internal_platforms_win_D3D9_##fun 9 | #define jni_win_wgldx(returnType, fun) extern "C" JNIEXPORT returnType JNICALL Java_com_huskerdev_openglfx_internal_platforms_win_WGLDX_##fun 10 | #define jni_win_dxgi(returnType, fun) extern "C" JNIEXPORT returnType JNICALL Java_com_huskerdev_openglfx_internal_platforms_win_DXGI_##fun 11 | 12 | 13 | typedef HGLRC (*wglCreateContextPtr)(HDC); 14 | typedef HGLRC (*wglGetCurrentContextPtr)(); 15 | typedef BOOL (*wglDeleteContextPtr)(HGLRC); 16 | typedef BOOL (*wglMakeCurrentPtr)(HDC, HGLRC); 17 | 18 | typedef HANDLE (*wglDXOpenDeviceNVPtr)(void* dxDevice); 19 | typedef BOOL (*wglDXCloseDeviceNVPtr)(HANDLE hDevice); 20 | typedef HANDLE (*wglDXRegisterObjectNVPtr)(HANDLE hDevice, void* dxObject, GLuint name, GLenum type, GLenum access); 21 | typedef BOOL (*wglDXSetResourceShareHandleNVPtr)(void* dxObject, HANDLE shareHandle); 22 | typedef BOOL (*wglDXUnregisterObjectNVPtr)(HANDLE hDevice, HANDLE hObject); 23 | typedef BOOL (*wglDXLockObjectsNVPtr)(HANDLE hDevice, GLint count, HANDLE* hObjects); 24 | typedef BOOL (*wglDXUnlockObjectsNVPtr)(HANDLE hDevice, GLint count, HANDLE* hObjects); 25 | 26 | 27 | static wglDXOpenDeviceNVPtr wglDXOpenDeviceNV; 28 | static wglDXCloseDeviceNVPtr wglDXCloseDeviceNV; 29 | static wglDXRegisterObjectNVPtr wglDXRegisterObjectNV; 30 | static wglDXSetResourceShareHandleNVPtr wglDXSetResourceShareHandleNV; 31 | static wglDXUnregisterObjectNVPtr wglDXUnregisterObjectNV; 32 | static wglDXLockObjectsNVPtr wglDXLockObjectsNV; 33 | static wglDXUnlockObjectsNVPtr wglDXUnlockObjectsNV; 34 | 35 | static bool functionsLoaded = false; 36 | 37 | static void loadWGLFunctions(){ 38 | wglDXOpenDeviceNV = (wglDXOpenDeviceNVPtr)a_GetProcAddress("wglDXOpenDeviceNV"); 39 | wglDXCloseDeviceNV = (wglDXCloseDeviceNVPtr)a_GetProcAddress("wglDXCloseDeviceNV"); 40 | wglDXRegisterObjectNV = (wglDXRegisterObjectNVPtr)a_GetProcAddress("wglDXRegisterObjectNV"); 41 | wglDXSetResourceShareHandleNV = (wglDXSetResourceShareHandleNVPtr)a_GetProcAddress("wglDXSetResourceShareHandleNV"); 42 | wglDXUnregisterObjectNV = (wglDXUnregisterObjectNVPtr)a_GetProcAddress("wglDXUnregisterObjectNV"); 43 | wglDXLockObjectsNV = (wglDXLockObjectsNVPtr)a_GetProcAddress("wglDXLockObjectsNV"); 44 | wglDXUnlockObjectsNV = (wglDXUnlockObjectsNVPtr)a_GetProcAddress("wglDXUnlockObjectsNV"); 45 | 46 | } 47 | 48 | static void checkWGLFunctions(){ 49 | if(functionsLoaded) 50 | return; 51 | functionsLoaded = true; 52 | 53 | wglCreateContextPtr _wglCreateContext = (wglCreateContextPtr)a_GetProcAddress("wglCreateContext"); 54 | wglGetCurrentContextPtr _wglGetCurrentContext = (wglGetCurrentContextPtr)a_GetProcAddress("wglGetCurrentContext"); 55 | wglDeleteContextPtr _wglDeleteContext = (wglDeleteContextPtr)a_GetProcAddress("wglDeleteContext"); 56 | wglMakeCurrentPtr _wglMakeCurrent = (wglMakeCurrentPtr)a_GetProcAddress("wglMakeCurrent"); 57 | 58 | if(_wglGetCurrentContext() != NULL){ 59 | loadWGLFunctions(); 60 | return; 61 | } 62 | 63 | WNDCLASS wc = {}; 64 | wc.lpfnWndProc = DefWindowProc; 65 | wc.hInstance = GetModuleHandle(NULL); 66 | wc.lpszClassName = "nvdx-tmp"; 67 | RegisterClass(&wc); 68 | 69 | PIXELFORMATDESCRIPTOR pfd = {}; 70 | pfd.nVersion = 1; 71 | pfd.iPixelType = PFD_TYPE_RGBA; 72 | pfd.cColorBits = 24; 73 | pfd.cDepthBits = 32; 74 | pfd.nSize = sizeof(pfd); 75 | 76 | HWND hwnd = CreateWindow( 77 | "nvdx-tmp", "", 78 | WS_OVERLAPPEDWINDOW, 79 | 0, 0, 100, 100, 80 | NULL, NULL, GetModuleHandle(NULL), NULL); 81 | HDC dc = GetDC(hwnd); 82 | 83 | int pixel_format = ChoosePixelFormat(dc, &pfd); 84 | SetPixelFormat(dc, pixel_format, &pfd); 85 | 86 | HGLRC rc = _wglCreateContext(dc); 87 | _wglMakeCurrent(dc, rc); 88 | 89 | loadWGLFunctions(); 90 | 91 | _wglDeleteContext(rc); 92 | ReleaseDC(hwnd, dc); 93 | DestroyWindow(hwnd); 94 | } 95 | 96 | #endif -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/canvas/IOSurfaceCanvas.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.canvas 2 | 3 | import com.huskerdev.openglfx.GLExecutor.Companion.glDisable 4 | import com.huskerdev.openglfx.GLExecutor.Companion.glEnable 5 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetInteger 6 | import com.huskerdev.openglfx.GL_SCISSOR_TEST 7 | import com.huskerdev.openglfx.GL_TEXTURE_RECTANGLE 8 | import com.huskerdev.openglfx.canvas.GLCanvas 9 | import com.huskerdev.openglfx.internal.Framebuffer 10 | import com.huskerdev.openglfx.internal.GLFXUtils 11 | import com.huskerdev.openglfx.internal.GLFXUtils.Companion.fetchGLTexId 12 | import com.huskerdev.openglfx.internal.NGGLCanvas 13 | import com.huskerdev.openglfx.internal.platforms.macos.IOSurface 14 | import com.sun.prism.Graphics 15 | import com.sun.prism.Texture 16 | import java.util.concurrent.atomic.AtomicBoolean 17 | 18 | open class IOSurfaceCanvas( 19 | canvas: GLCanvas 20 | ) : NGGLCanvas(canvas) { 21 | 22 | override fun onRenderThreadInit() = Unit 23 | override fun onRenderThreadEnd() = Unit 24 | override fun createSwapBuffer() = IOSurfaceSwapBuffer() 25 | 26 | 27 | protected inner class IOSurfaceSwapBuffer: SwapBuffer(){ 28 | private lateinit var fbo: Framebuffer 29 | private lateinit var interopFBO: Framebuffer.Default 30 | private lateinit var ioSurface: IOSurface 31 | 32 | private lateinit var fxTexture: Texture 33 | private lateinit var fxTextureFBO: Framebuffer 34 | private lateinit var fxInteropFBO: Framebuffer 35 | 36 | private val shouldUpdateBinding = AtomicBoolean() 37 | 38 | override fun render(width: Int, height: Int): Framebuffer { 39 | if(checkFramebufferSize(width, height)) 40 | canvas.fireReshapeEvent(width, height) 41 | 42 | fbo.bindFramebuffer() 43 | canvas.fireRenderEvent(fbo.id) 44 | 45 | ioSurface.lock() 46 | fbo.blitTo(interopFBO) 47 | ioSurface.unlock() 48 | 49 | return fbo 50 | } 51 | 52 | private fun checkFramebufferSize(width: Int, height: Int): Boolean { 53 | if(!::ioSurface.isInitialized || ioSurface.width != width || ioSurface.height != height){ 54 | dispose() 55 | 56 | ioSurface = IOSurface(width, height) 57 | interopFBO = Framebuffer.Default(width, height, 58 | texture = ioSurface.createBoundTexture(), 59 | textureType = GL_TEXTURE_RECTANGLE) 60 | 61 | fbo = createFramebufferForRender(width, height) 62 | 63 | shouldUpdateBinding.set(true) 64 | return true 65 | } 66 | return false 67 | } 68 | 69 | override fun getTextureForDisplay(g: Graphics): Texture { 70 | val width = ioSurface.width 71 | val height = ioSurface.height 72 | 73 | if(shouldUpdateBinding.getAndSet(false)){ 74 | disposeFXResources() 75 | 76 | fxTexture = GLFXUtils.createPermanentFXTexture(width, height) 77 | fxTextureFBO = Framebuffer.Default(width, height, 78 | texture = fetchGLTexId(fxTexture, g)) 79 | 80 | fxInteropFBO = Framebuffer.Default(width, height, 81 | texture = ioSurface.createBoundTexture(), 82 | textureType = GL_TEXTURE_RECTANGLE) 83 | } 84 | 85 | ioSurface.lock() 86 | 87 | val scissorTestEnabled = glGetInteger(GL_SCISSOR_TEST) != 0 88 | glDisable(GL_SCISSOR_TEST) 89 | fxInteropFBO.blitTo(fxTextureFBO) 90 | if (scissorTestEnabled) { 91 | glEnable(GL_SCISSOR_TEST) 92 | } 93 | ioSurface.unlock() 94 | 95 | return fxTexture 96 | } 97 | 98 | override fun dispose() { 99 | if(::ioSurface.isInitialized) ioSurface.dispose() 100 | if(::interopFBO.isInitialized) interopFBO.delete() 101 | if(::fbo.isInitialized) fbo.delete() 102 | } 103 | 104 | override fun disposeFXResources() { 105 | if(::fxTexture.isInitialized) fxTexture.dispose() 106 | if(::fxTextureFBO.isInitialized) fxTextureFBO.delete() 107 | if(::fxInteropFBO.isInitialized) fxInteropFBO.delete() 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_screen.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_SCREEN_H_ 2 | #define VULKAN_SCREEN_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_QNX_screen_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_QNX_screen_surface 1 24 | #define VK_QNX_SCREEN_SURFACE_SPEC_VERSION 1 25 | #define VK_QNX_SCREEN_SURFACE_EXTENSION_NAME "VK_QNX_screen_surface" 26 | typedef VkFlags VkScreenSurfaceCreateFlagsQNX; 27 | typedef struct VkScreenSurfaceCreateInfoQNX { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkScreenSurfaceCreateFlagsQNX flags; 31 | struct _screen_context* context; 32 | struct _screen_window* window; 33 | } VkScreenSurfaceCreateInfoQNX; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateScreenSurfaceQNX)(VkInstance instance, const VkScreenSurfaceCreateInfoQNX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceScreenPresentationSupportQNX)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct _screen_window* window); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateScreenSurfaceQNX( 40 | VkInstance instance, 41 | const VkScreenSurfaceCreateInfoQNX* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceScreenPresentationSupportQNX( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | struct _screen_window* window); 49 | #endif 50 | 51 | 52 | // VK_QNX_external_memory_screen_buffer is a preprocessor guard. Do not pass it to API calls. 53 | #define VK_QNX_external_memory_screen_buffer 1 54 | #define VK_QNX_EXTERNAL_MEMORY_SCREEN_BUFFER_SPEC_VERSION 1 55 | #define VK_QNX_EXTERNAL_MEMORY_SCREEN_BUFFER_EXTENSION_NAME "VK_QNX_external_memory_screen_buffer" 56 | typedef struct VkScreenBufferPropertiesQNX { 57 | VkStructureType sType; 58 | void* pNext; 59 | VkDeviceSize allocationSize; 60 | uint32_t memoryTypeBits; 61 | } VkScreenBufferPropertiesQNX; 62 | 63 | typedef struct VkScreenBufferFormatPropertiesQNX { 64 | VkStructureType sType; 65 | void* pNext; 66 | VkFormat format; 67 | uint64_t externalFormat; 68 | uint64_t screenUsage; 69 | VkFormatFeatureFlags formatFeatures; 70 | VkComponentMapping samplerYcbcrConversionComponents; 71 | VkSamplerYcbcrModelConversion suggestedYcbcrModel; 72 | VkSamplerYcbcrRange suggestedYcbcrRange; 73 | VkChromaLocation suggestedXChromaOffset; 74 | VkChromaLocation suggestedYChromaOffset; 75 | } VkScreenBufferFormatPropertiesQNX; 76 | 77 | typedef struct VkImportScreenBufferInfoQNX { 78 | VkStructureType sType; 79 | const void* pNext; 80 | struct _screen_buffer* buffer; 81 | } VkImportScreenBufferInfoQNX; 82 | 83 | typedef struct VkExternalFormatQNX { 84 | VkStructureType sType; 85 | void* pNext; 86 | uint64_t externalFormat; 87 | } VkExternalFormatQNX; 88 | 89 | typedef struct VkPhysicalDeviceExternalMemoryScreenBufferFeaturesQNX { 90 | VkStructureType sType; 91 | void* pNext; 92 | VkBool32 screenBufferImport; 93 | } VkPhysicalDeviceExternalMemoryScreenBufferFeaturesQNX; 94 | 95 | typedef VkResult (VKAPI_PTR *PFN_vkGetScreenBufferPropertiesQNX)(VkDevice device, const struct _screen_buffer* buffer, VkScreenBufferPropertiesQNX* pProperties); 96 | 97 | #ifndef VK_NO_PROTOTYPES 98 | VKAPI_ATTR VkResult VKAPI_CALL vkGetScreenBufferPropertiesQNX( 99 | VkDevice device, 100 | const struct _screen_buffer* buffer, 101 | VkScreenBufferPropertiesQNX* pProperties); 102 | #endif 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /modules/core/native/include/vk_video/vulkan_video_codec_av1std_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_AV1STD_DECODE_H_ 2 | #define VULKAN_VIDEO_CODEC_AV1STD_DECODE_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codec_av1std_decode is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codec_av1std_decode 1 24 | #include "vulkan_video_codec_av1std.h" 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 27 | 28 | #define VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_API_VERSION_1_0_0 29 | #define VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_av1_decode" 30 | typedef struct StdVideoDecodeAV1PictureInfoFlags { 31 | uint32_t error_resilient_mode : 1; 32 | uint32_t disable_cdf_update : 1; 33 | uint32_t use_superres : 1; 34 | uint32_t render_and_frame_size_different : 1; 35 | uint32_t allow_screen_content_tools : 1; 36 | uint32_t is_filter_switchable : 1; 37 | uint32_t force_integer_mv : 1; 38 | uint32_t frame_size_override_flag : 1; 39 | uint32_t buffer_removal_time_present_flag : 1; 40 | uint32_t allow_intrabc : 1; 41 | uint32_t frame_refs_short_signaling : 1; 42 | uint32_t allow_high_precision_mv : 1; 43 | uint32_t is_motion_mode_switchable : 1; 44 | uint32_t use_ref_frame_mvs : 1; 45 | uint32_t disable_frame_end_update_cdf : 1; 46 | uint32_t allow_warped_motion : 1; 47 | uint32_t reduced_tx_set : 1; 48 | uint32_t reference_select : 1; 49 | uint32_t skip_mode_present : 1; 50 | uint32_t delta_q_present : 1; 51 | uint32_t delta_lf_present : 1; 52 | uint32_t delta_lf_multi : 1; 53 | uint32_t segmentation_enabled : 1; 54 | uint32_t segmentation_update_map : 1; 55 | uint32_t segmentation_temporal_update : 1; 56 | uint32_t segmentation_update_data : 1; 57 | uint32_t UsesLr : 1; 58 | uint32_t usesChromaLr : 1; 59 | uint32_t apply_grain : 1; 60 | uint32_t reserved : 3; 61 | } StdVideoDecodeAV1PictureInfoFlags; 62 | 63 | typedef struct StdVideoDecodeAV1PictureInfo { 64 | StdVideoDecodeAV1PictureInfoFlags flags; 65 | StdVideoAV1FrameType frame_type; 66 | uint32_t current_frame_id; 67 | uint8_t OrderHint; 68 | uint8_t primary_ref_frame; 69 | uint8_t refresh_frame_flags; 70 | uint8_t reserved1; 71 | StdVideoAV1InterpolationFilter interpolation_filter; 72 | StdVideoAV1TxMode TxMode; 73 | uint8_t delta_q_res; 74 | uint8_t delta_lf_res; 75 | uint8_t SkipModeFrame[STD_VIDEO_AV1_SKIP_MODE_FRAMES]; 76 | uint8_t coded_denom; 77 | uint8_t reserved2[3]; 78 | uint8_t OrderHints[STD_VIDEO_AV1_NUM_REF_FRAMES]; 79 | uint32_t expectedFrameId[STD_VIDEO_AV1_NUM_REF_FRAMES]; 80 | const StdVideoAV1TileInfo* pTileInfo; 81 | const StdVideoAV1Quantization* pQuantization; 82 | const StdVideoAV1Segmentation* pSegmentation; 83 | const StdVideoAV1LoopFilter* pLoopFilter; 84 | const StdVideoAV1CDEF* pCDEF; 85 | const StdVideoAV1LoopRestoration* pLoopRestoration; 86 | const StdVideoAV1GlobalMotion* pGlobalMotion; 87 | const StdVideoAV1FilmGrain* pFilmGrain; 88 | } StdVideoDecodeAV1PictureInfo; 89 | 90 | typedef struct StdVideoDecodeAV1ReferenceInfoFlags { 91 | uint32_t disable_frame_end_update_cdf : 1; 92 | uint32_t segmentation_enabled : 1; 93 | uint32_t reserved : 30; 94 | } StdVideoDecodeAV1ReferenceInfoFlags; 95 | 96 | typedef struct StdVideoDecodeAV1ReferenceInfo { 97 | StdVideoDecodeAV1ReferenceInfoFlags flags; 98 | uint8_t frame_type; 99 | uint8_t RefFrameSignBias; 100 | uint8_t OrderHint; 101 | uint8_t SavedOrderHints[STD_VIDEO_AV1_NUM_REF_FRAMES]; 102 | } StdVideoDecodeAV1ReferenceInfo; 103 | 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/shaders/PassthroughShader.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.shaders 2 | 3 | import com.huskerdev.openglfx.* 4 | import com.huskerdev.openglfx.GLExecutor.Companion.glAttachShader 5 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindBuffer 6 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindFramebuffer 7 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindTexture 8 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindVertexArray 9 | import com.huskerdev.openglfx.GLExecutor.Companion.glBufferData 10 | import com.huskerdev.openglfx.GLExecutor.Companion.glCompileShader 11 | import com.huskerdev.openglfx.GLExecutor.Companion.glCreateProgram 12 | import com.huskerdev.openglfx.GLExecutor.Companion.glCreateShader 13 | import com.huskerdev.openglfx.GLExecutor.Companion.glDeleteShader 14 | import com.huskerdev.openglfx.GLExecutor.Companion.glDrawArrays 15 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenBuffers 16 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenVertexArrays 17 | import com.huskerdev.openglfx.GLExecutor.Companion.glLinkProgram 18 | import com.huskerdev.openglfx.GLExecutor.Companion.glShaderSource 19 | import com.huskerdev.openglfx.GLExecutor.Companion.glVertexAttribPointer 20 | import com.huskerdev.openglfx.GLExecutor.Companion.glEnableVertexAttribArray 21 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetAttribLocation 22 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetShaderInfoLog 23 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetShaderi 24 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetUniformLocation 25 | import com.huskerdev.openglfx.GLExecutor.Companion.glUniform2f 26 | import com.huskerdev.openglfx.GLExecutor.Companion.glUseProgram 27 | import com.huskerdev.openglfx.internal.Framebuffer 28 | import java.nio.ByteBuffer 29 | import java.nio.ByteOrder 30 | 31 | internal open class PassthroughShader( 32 | vertexSource: String = """ 33 | attribute vec4 position; 34 | 35 | void main() { 36 | gl_Position = position; 37 | } 38 | """.trimIndent(), 39 | fragmentSource: String = """ 40 | uniform sampler2D texture; 41 | uniform vec2 size; 42 | 43 | void main() { 44 | gl_FragColor = texture2D(texture, gl_FragCoord.xy / size); 45 | } 46 | """.trimIndent() 47 | ) { 48 | private val program: Int 49 | private val vao: Int 50 | private val positionLoc: Int 51 | private val sizeLoc: Int 52 | 53 | init { 54 | val vertex = glCreateShader(GL_VERTEX_SHADER) 55 | glShaderSource(vertex, vertexSource) 56 | glCompileShader(vertex) 57 | if(glGetShaderi(vertex, GL_COMPILE_STATUS) == 0) 58 | throw Exception("Compilation error in vertex shader: \n ${glGetShaderInfoLog(vertex)}") 59 | 60 | val fragment = glCreateShader(GL_FRAGMENT_SHADER) 61 | glShaderSource(fragment, fragmentSource) 62 | glCompileShader(fragment) 63 | if(glGetShaderi(fragment, GL_COMPILE_STATUS) == 0) 64 | throw Exception("Compilation error in fragment shader: \n ${glGetShaderInfoLog(fragment)}") 65 | 66 | program = glCreateProgram() 67 | glAttachShader(program, vertex) 68 | glAttachShader(program, fragment) 69 | glLinkProgram(program) 70 | glDeleteShader(vertex) 71 | glDeleteShader(fragment) 72 | 73 | positionLoc = glGetAttribLocation(program, "position") 74 | sizeLoc = glGetUniformLocation(program, "size") 75 | 76 | vao = glGenVertexArrays() 77 | glBindVertexArray(vao) 78 | 79 | val vbo = glGenBuffers() 80 | glBindBuffer(GL_ARRAY_BUFFER, vbo) 81 | glBufferData( 82 | GL_ARRAY_BUFFER, 83 | floatBuffer(floatArrayOf(-1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f)), 84 | GL_STATIC_DRAW 85 | ) 86 | 87 | glVertexAttribPointer(positionLoc, 2, GL_FLOAT, false, 0, 0) 88 | glEnableVertexAttribArray(positionLoc) 89 | 90 | glBindVertexArray(0) 91 | } 92 | 93 | private fun floatBuffer(array: FloatArray) = 94 | ByteBuffer.allocateDirect(array.size * Float.SIZE_BYTES) 95 | .order(ByteOrder.nativeOrder()) 96 | .asFloatBuffer() 97 | .put(array) 98 | 99 | fun apply(source: Framebuffer.Default, target: Framebuffer) = 100 | apply(source.texture, target) 101 | 102 | fun apply(sourceTexture: Int, target: Framebuffer){ 103 | glUseProgram(program) 104 | glUniform2f(sizeLoc, target.width.toFloat(), target.height.toFloat()) 105 | 106 | glBindTexture(GL_TEXTURE_2D, sourceTexture) 107 | glBindFramebuffer(GL_FRAMEBUFFER, target.id) 108 | 109 | glBindVertexArray(vao) 110 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4) 111 | } 112 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/canvas/WGLDXInteropCanvas.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.canvas 2 | 3 | import com.huskerdev.openglfx.GL_TEXTURE_2D 4 | import com.huskerdev.openglfx.canvas.GLCanvas 5 | import com.huskerdev.openglfx.internal.GLFXUtils 6 | import com.huskerdev.openglfx.internal.NGGLCanvas 7 | import com.huskerdev.openglfx.internal.Framebuffer 8 | import com.huskerdev.openglfx.internal.GLFXUtils.Companion.fetchDXTexHandle 9 | import com.huskerdev.openglfx.internal.platforms.win.* 10 | import com.huskerdev.openglfx.internal.platforms.win.WGLDX.Companion.WGL_ACCESS_WRITE_DISCARD_NV 11 | import com.sun.prism.Graphics 12 | import com.sun.prism.Texture 13 | import java.util.concurrent.atomic.AtomicBoolean 14 | 15 | 16 | open class WGLDXInteropCanvas( 17 | canvas: GLCanvas 18 | ): NGGLCanvas(canvas) { 19 | 20 | private lateinit var d3d9Device: D3D9.Device 21 | private lateinit var interopDevice: WGLDX.Device 22 | 23 | override fun onRenderThreadInit() { 24 | d3d9Device = D3D9.Device() 25 | interopDevice = WGLDX.Device(d3d9Device) 26 | } 27 | 28 | override fun onRenderThreadEnd() { 29 | interopDevice.release() 30 | d3d9Device.release() 31 | } 32 | 33 | override fun createSwapBuffer() = NVDXInteropSwapBuffer() 34 | 35 | 36 | protected inner class NVDXInteropSwapBuffer: SwapBuffer(){ 37 | private lateinit var fbo: Framebuffer 38 | private lateinit var interopFBO: Framebuffer.Default 39 | private lateinit var interopObject: WGLDX.Object 40 | 41 | private lateinit var texture: Texture 42 | 43 | private lateinit var sharedD3DTexture0: D3D9.Texture 44 | private lateinit var sharedD3DTexture: D3D9.Texture 45 | private lateinit var sharedD3DTextureSurface: D3D9.Surface 46 | 47 | private lateinit var fxD3DTexture: D3D9.Texture 48 | private lateinit var fxD3DTextureSurface: D3D9.Surface 49 | 50 | private val shouldUpdateBinding = AtomicBoolean() 51 | 52 | override fun render(width: Int, height: Int): Framebuffer { 53 | if(checkFramebufferSize(width, height, d3d9Device, interopDevice)) 54 | canvas.fireReshapeEvent(width, height) 55 | 56 | fbo.bindFramebuffer() 57 | canvas.fireRenderEvent(fbo.id) 58 | 59 | interopObject.lock() 60 | fbo.blitTo(interopFBO) 61 | interopObject.unlock() 62 | return fbo 63 | } 64 | 65 | private fun checkFramebufferSize(width: Int, height: Int, device: D3D9.Device, interopDevice: WGLDX.Device): Boolean{ 66 | if(!this::fbo.isInitialized || fbo.width != width || fbo.height != height){ 67 | dispose() 68 | 69 | fbo = createFramebufferForRender(width, height) 70 | 71 | interopFBO = Framebuffer.Default(width, height) 72 | interopFBO.bindFramebuffer() 73 | 74 | sharedD3DTexture0 = device.createTexture(width, height) 75 | WGLDX.linkShareHandle(sharedD3DTexture0.handle, sharedD3DTexture0.sharedHandle) 76 | 77 | interopObject = interopDevice.registerObject( 78 | sharedD3DTexture0.handle, 79 | interopFBO.texture, 80 | GL_TEXTURE_2D, 81 | WGL_ACCESS_WRITE_DISCARD_NV 82 | ) 83 | 84 | shouldUpdateBinding.set(true) 85 | return true 86 | } 87 | return false 88 | } 89 | 90 | override fun getTextureForDisplay(g: Graphics): Texture { 91 | val width = sharedD3DTexture0.width 92 | val height = sharedD3DTexture0.height 93 | 94 | if(shouldUpdateBinding.getAndSet(false)){ 95 | disposeFXResources() 96 | 97 | sharedD3DTexture = D3D9.Device.jfx.createTexture(width, height, sharedD3DTexture0.sharedHandle) 98 | sharedD3DTextureSurface = sharedD3DTexture.getSurfaceLevel(0) 99 | 100 | texture = GLFXUtils.createPermanentFXTexture(width, height) 101 | fxD3DTexture = D3D9.Texture(width, height, fetchDXTexHandle(texture, g), 0) 102 | fxD3DTextureSurface = fxD3DTexture.getSurfaceLevel(0) 103 | } 104 | 105 | D3D9.Device.jfx.stretchRect(sharedD3DTextureSurface, fxD3DTextureSurface) 106 | 107 | return texture 108 | } 109 | 110 | override fun dispose() { 111 | if (this::interopObject.isInitialized) interopObject.release() 112 | if (this::fbo.isInitialized) fbo.delete() 113 | if (this::interopFBO.isInitialized) interopFBO.delete() 114 | if (this::sharedD3DTexture0.isInitialized) sharedD3DTexture0.release() 115 | } 116 | 117 | override fun disposeFXResources() { 118 | if (this::sharedD3DTextureSurface.isInitialized) sharedD3DTextureSurface.release() 119 | if (this::sharedD3DTexture.isInitialized) sharedD3DTexture.release() 120 | if (this::fxD3DTextureSurface.isInitialized) fxD3DTextureSurface.release() 121 | if (this::fxD3DTexture.isInitialized) fxD3DTexture.release() 122 | if (this::texture.isInitialized) texture.dispose() 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/internal/OGLFXApplication.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.internal 2 | 3 | import com.badlogic.gdx.* 4 | import com.badlogic.gdx.backends.lwjgl3.* 5 | import com.badlogic.gdx.backends.lwjgl3.audio.OpenALLwjgl3Audio 6 | import com.badlogic.gdx.backends.lwjgl3.audio.mock.MockAudio 7 | import com.badlogic.gdx.utils.Clipboard 8 | import com.badlogic.gdx.utils.ObjectMap 9 | import com.huskerdev.openglfx.libgdx.LibGDXCanvas 10 | import com.huskerdev.openglfx.libgdx.OGLFXApplicationConfiguration 11 | import java.io.File 12 | 13 | class OGLFXApplication( 14 | private val config: OGLFXApplicationConfiguration, 15 | val canvas: LibGDXCanvas 16 | ): Application { 17 | companion object { 18 | init { 19 | Lwjgl3NativesLoader.load() 20 | } 21 | } 22 | 23 | private val preferences = ObjectMap() 24 | 25 | private val audio: Audio 26 | private val files: Files 27 | private val net: Net 28 | private val clipboard: Clipboard 29 | private val graphics: Graphics 30 | private val input: Input 31 | private var logger: ApplicationLogger 32 | private var logLevel = Application.LOG_INFO 33 | 34 | private val defaultListener = object: ApplicationListener{ 35 | override fun create() = canvas.fireInitEvent() 36 | override fun resize(width: Int, height: Int) = canvas.fireReshapeEvent(width, height) 37 | override fun render() = canvas.fireRenderEvent(0) 38 | override fun dispose() = canvas.fireDisposeEvent() 39 | override fun pause() {} 40 | override fun resume() {} 41 | } 42 | 43 | init { 44 | logger = Lwjgl3ApplicationLogger() 45 | 46 | this.audio = if (!config.disableAudio) { 47 | try { 48 | OpenALLwjgl3Audio( 49 | config.audioDeviceSimultaneousSources, 50 | config.audioDeviceBufferCount, 51 | config.audioDeviceBufferSize 52 | ) 53 | } catch (t: Throwable) { 54 | log("OGLFXApplication", "Couldn't initialize audio, disabling audio", t) 55 | MockAudio() 56 | } 57 | } else MockAudio() 58 | 59 | files = Lwjgl3Files() 60 | net = Lwjgl3Net(Lwjgl3ApplicationConfiguration().apply { setMaxNetThreads(config.maxNetThreads) }) 61 | clipboard = OGLFXClipboard() 62 | graphics = OGLFXGraphics(canvas) 63 | input = OGLFXInput(canvas) 64 | 65 | Gdx.app = this 66 | Gdx.audio = audio 67 | Gdx.files = files 68 | Gdx.net = net 69 | Gdx.graphics = graphics 70 | Gdx.input = input 71 | } 72 | 73 | override fun getApplicationListener() = defaultListener 74 | 75 | override fun getGraphics() = graphics 76 | override fun getAudio() = audio 77 | override fun getInput() = input 78 | override fun getFiles() = files 79 | override fun getNet() = net 80 | 81 | override fun debug(tag: String?, message: String?) { 82 | if (logLevel >= Application.LOG_DEBUG) logger.debug(tag, message) 83 | } 84 | 85 | override fun debug(tag: String?, message: String?, exception: Throwable?) { 86 | if (logLevel >= Application.LOG_DEBUG) logger.debug(tag, message, exception) 87 | } 88 | 89 | override fun log(tag: String?, message: String?) { 90 | if (logLevel >= Application.LOG_INFO) logger.log(tag, message) 91 | } 92 | 93 | override fun log(tag: String?, message: String?, exception: Throwable?) { 94 | if (logLevel >= Application.LOG_INFO) logger.log(tag, message, exception) 95 | } 96 | 97 | override fun error(tag: String?, message: String?) { 98 | if (logLevel >= Application.LOG_ERROR) logger.error(tag, message) 99 | } 100 | 101 | override fun error(tag: String?, message: String?, exception: Throwable?) { 102 | if (logLevel >= Application.LOG_ERROR) logger.error(tag, message, exception) 103 | } 104 | 105 | override fun setLogLevel(logLevel: Int) { 106 | this.logLevel = logLevel 107 | } 108 | 109 | override fun getLogLevel() = logLevel 110 | 111 | override fun setApplicationLogger(applicationLogger: ApplicationLogger) { 112 | logger = applicationLogger 113 | } 114 | 115 | override fun getApplicationLogger() = logger 116 | 117 | override fun getType() = Application.ApplicationType.Desktop 118 | 119 | override fun getVersion() = 1 120 | 121 | override fun getJavaHeap() = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() 122 | 123 | override fun getNativeHeap() = javaHeap 124 | 125 | override fun getPreferences(name: String): Preferences = 126 | if (preferences.containsKey(name)) { 127 | preferences.get(name) 128 | } else { 129 | val prefs = Lwjgl3Preferences(Lwjgl3FileHandle(File(config.preferencesDirectory, name), config.preferencesFileType)) 130 | preferences.put(name, prefs) 131 | prefs 132 | } 133 | 134 | override fun getClipboard() = clipboard 135 | 136 | override fun postRunnable(runnable: Runnable) = 137 | canvas.invokeLater(runnable) 138 | 139 | override fun exit() {} 140 | 141 | override fun addLifecycleListener(listener: LifecycleListener?) { 142 | 143 | } 144 | 145 | override fun removeLifecycleListener(listener: LifecycleListener?) { 146 | 147 | } 148 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/GLFXUtils.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal 2 | 3 | import com.huskerdev.grapl.core.platform.Platform 4 | import com.huskerdev.openglfx.* 5 | import com.huskerdev.openglfx.GLExecutor.Companion.glActiveTexture 6 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetInteger 7 | import com.huskerdev.openglfx.internal.platforms.win.D3D9 8 | import com.sun.prism.Graphics 9 | import com.sun.prism.GraphicsPipeline 10 | import com.sun.prism.PixelFormat 11 | import com.sun.prism.Texture 12 | import javafx.scene.Node 13 | import java.lang.reflect.Field 14 | import java.nio.ByteBuffer 15 | import java.util.concurrent.atomic.AtomicBoolean 16 | import java.util.function.Consumer 17 | 18 | 19 | class GLFXUtils { 20 | 21 | companion object { 22 | @JvmStatic external fun createDirectBuffer(size: Int): ByteBuffer 23 | @JvmStatic external fun cleanDirectBuffer(buffer: ByteBuffer) 24 | 25 | private val initialized = AtomicBoolean() 26 | 27 | private val unsafeClass by lazy { 28 | Class.forName("sun.misc.Unsafe") 29 | } 30 | private val unsafe by lazy { 31 | unsafeClass.getDeclaredField("theUnsafe").apply { trySetAccessible() }[null] 32 | } 33 | 34 | 35 | fun loadLibrary() { 36 | if(initialized.getAndSet(true)) 37 | return 38 | Platform.loadLibraryFromResources("com/huskerdev/openglfx/natives", "lib", GLFXInfo.VERSION) 39 | 40 | // Uses modules 41 | if (System.getProperty("openglfx.disable.exports", "false") == "false" && 42 | ModuleLayer.boot().findModule("javafx.graphics").isPresent 43 | ){ 44 | arrayOf( 45 | "com.sun.prism", 46 | "com.sun.javafx.scene.layout", 47 | "com.sun.javafx.scene", 48 | "com.sun.javafx.sg.prism", 49 | "com.sun.scenario", 50 | "com.sun.javafx.tk", 51 | "com.sun.glass.ui" 52 | ).forEach { 53 | addExports("javafx.graphics", it, GLFXUtils::class.java.module) 54 | } 55 | } 56 | } 57 | 58 | private fun addExports(module: String, pkg: String, currentModule: Module) { 59 | try { 60 | val moduleOpt = ModuleLayer.boot().findModule(module) 61 | val addOpensMethodImpl = Module::class.java.getDeclaredMethod("implAddExports", String::class.java, Module::class.java) 62 | 63 | @Suppress("unused") 64 | class OffsetProvider(val first: Int) 65 | 66 | val firstFieldOffset = unsafeClass.getDeclaredMethod("objectFieldOffset", Field::class.java) 67 | .invoke(unsafe, OffsetProvider::class.java.getDeclaredField("first")) 68 | 69 | unsafeClass.getDeclaredMethod("putBooleanVolatile", Object::class.java, Long::class.java, Boolean::class.java) 70 | .invoke(unsafe, addOpensMethodImpl, firstFieldOffset, true) 71 | 72 | addOpensMethodImpl.invoke(moduleOpt.get(), pkg, currentModule) 73 | } catch (e: Throwable) { 74 | System.err.println("Could not add exports: $module/$pkg to ${currentModule.name}") 75 | e.printStackTrace() 76 | } 77 | } 78 | 79 | val pipeline: String 80 | get() { 81 | if(GraphicsPipeline.getPipeline() == null) 82 | throw UnsupportedOperationException("Could not detect pipeline, make sure to initialize JavaFX") 83 | return GraphicsPipeline.getPipeline().javaClass.canonicalName.split(".")[3] 84 | } 85 | 86 | fun getDPI(node: Node) = 87 | if(node.scene == null || node.scene.window == null) 88 | 1.0 89 | else 90 | node.scene.window.outputScaleY 91 | 92 | fun createPermanentFXTexture(width: Int, height: Int): Texture { 93 | val texture = GraphicsPipeline.getDefaultResourceFactory() 94 | .createTexture( 95 | PixelFormat.BYTE_BGRA_PRE, Texture.Usage.DYNAMIC, Texture.WrapMode.CLAMP_TO_EDGE, 96 | width, height 97 | ) 98 | texture.makePermanent() 99 | return texture 100 | } 101 | 102 | fun createPermanentFXRTTexture(width: Int, height: Int): Texture { 103 | val texture = GraphicsPipeline.getDefaultResourceFactory() 104 | .createRTTexture( 105 | width, height, Texture.WrapMode.CLAMP_TO_EDGE, 106 | ) 107 | texture.makePermanent() 108 | return texture 109 | } 110 | 111 | fun fetchGLTexId(texture: Texture, g: Graphics): Int{ 112 | g.drawTexture(texture, 0f, 0f, 0f, 0f) 113 | val oldActiveTexture = glGetInteger(GL_ACTIVE_TEXTURE) 114 | glActiveTexture(GL_TEXTURE0) 115 | val textureId = glGetInteger(GL_TEXTURE_BINDING_2D) 116 | if (oldActiveTexture != GL_TEXTURE_2D) { 117 | glActiveTexture(oldActiveTexture) 118 | } 119 | return textureId 120 | } 121 | 122 | fun fetchDXTexHandle(texture: Texture, g: Graphics): Long{ 123 | g.drawTexture(texture, 0f, 0f, 0f, 0f) 124 | return D3D9.Device.jfx.getTexture(0) 125 | } 126 | 127 | fun List>.dispatchConsumer(event: T) { 128 | if(isNotEmpty()) forEach { it.accept(event) } 129 | } 130 | } 131 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/canvas/ExternalObjectsCanvasD3D.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.canvas 2 | 3 | import com.huskerdev.openglfx.* 4 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindTexture 5 | import com.huskerdev.openglfx.GLExecutor.Companion.glFinish 6 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenTextures 7 | import com.huskerdev.openglfx.GL_TEXTURE_2D 8 | import com.huskerdev.openglfx.canvas.GLCanvas 9 | import com.huskerdev.openglfx.internal.GLFXUtils 10 | import com.huskerdev.openglfx.internal.NGGLCanvas 11 | 12 | import com.huskerdev.openglfx.internal.Framebuffer 13 | import com.huskerdev.openglfx.internal.GLFXUtils.Companion.fetchDXTexHandle 14 | import com.huskerdev.openglfx.internal.platforms.GL_HANDLE_TYPE_D3D11_IMAGE_KMT_EXT 15 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glCreateMemoryObjectsEXT 16 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glDeleteMemoryObjectsEXT 17 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glImportMemoryWin32HandleEXT 18 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glTextureStorageMem2DEXT 19 | import com.huskerdev.openglfx.internal.platforms.win.D3D9 20 | import com.sun.prism.Graphics 21 | 22 | import com.sun.prism.Texture 23 | import java.util.concurrent.atomic.AtomicBoolean 24 | 25 | 26 | open class ExternalObjectsCanvasD3D( 27 | canvas: GLCanvas 28 | ) : NGGLCanvas(canvas) { 29 | 30 | private lateinit var d3d9Device: D3D9.Device 31 | 32 | override fun onRenderThreadInit() { 33 | d3d9Device = D3D9.Device() 34 | } 35 | 36 | override fun onRenderThreadEnd() = 37 | d3d9Device.release() 38 | 39 | override fun createSwapBuffer() = ExternalObjectsSwapBuffer() 40 | 41 | 42 | protected inner class ExternalObjectsSwapBuffer: SwapBuffer() { 43 | private lateinit var fbo: Framebuffer 44 | private lateinit var interopFBO: Framebuffer.Default 45 | private var memoryObj = 0 46 | 47 | private lateinit var texture: Texture 48 | 49 | private lateinit var sharedD3DTexture0: D3D9.Texture 50 | private lateinit var sharedD3DTexture: D3D9.Texture 51 | private lateinit var sharedD3DTextureSurface: D3D9.Surface 52 | 53 | private lateinit var fxD3DTexture: D3D9.Texture 54 | private lateinit var fxD3DTextureSurface: D3D9.Surface 55 | 56 | private val shouldUpdateBinding = AtomicBoolean() 57 | 58 | override fun render(width: Int, height: Int): Framebuffer { 59 | if(checkFramebufferSize(width, height)) 60 | canvas.fireReshapeEvent(width, height) 61 | 62 | fbo.bindFramebuffer() 63 | canvas.fireRenderEvent(fbo.id) 64 | fbo.blitTo(interopFBO) 65 | glFinish() 66 | 67 | return fbo 68 | } 69 | 70 | private fun checkFramebufferSize(width: Int, height: Int): Boolean{ 71 | if(!this::fbo.isInitialized || fbo.width != width || fbo.height != height){ 72 | dispose() 73 | 74 | sharedD3DTexture0 = d3d9Device.createTexture(width, height) 75 | 76 | memoryObj = glCreateMemoryObjectsEXT() 77 | glImportMemoryWin32HandleEXT(memoryObj, 0, GL_HANDLE_TYPE_D3D11_IMAGE_KMT_EXT, sharedD3DTexture0.sharedHandle) 78 | 79 | val sharedTexture = glGenTextures() 80 | glBindTexture(GL_TEXTURE_2D, sharedTexture) 81 | glTextureStorageMem2DEXT(sharedTexture, 1, GL_BGRA, width, height, memoryObj, 0) 82 | 83 | interopFBO = Framebuffer.Default(width, height, texture = sharedTexture) 84 | fbo = createFramebufferForRender(width, height) 85 | 86 | shouldUpdateBinding.set(true) 87 | return true 88 | } 89 | return false 90 | } 91 | 92 | override fun getTextureForDisplay(g: Graphics): Texture { 93 | val width = sharedD3DTexture0.width 94 | val height = sharedD3DTexture0.height 95 | 96 | if(shouldUpdateBinding.getAndSet(false)){ 97 | disposeFXResources() 98 | 99 | sharedD3DTexture = D3D9.Device.jfx.createTexture(width, height, sharedD3DTexture0.sharedHandle) 100 | sharedD3DTextureSurface = sharedD3DTexture.getSurfaceLevel(0) 101 | 102 | texture = GLFXUtils.createPermanentFXRTTexture(width, height) 103 | fxD3DTexture = D3D9.Texture(width, height, fetchDXTexHandle(texture, g), 0) 104 | fxD3DTextureSurface = fxD3DTexture.getSurfaceLevel(0) 105 | } 106 | 107 | D3D9.Device.jfx.stretchRect(sharedD3DTextureSurface, fxD3DTextureSurface) 108 | 109 | return texture 110 | } 111 | 112 | override fun dispose() { 113 | if (this::fbo.isInitialized) fbo.delete() 114 | if (this::interopFBO.isInitialized) interopFBO.delete() 115 | if (this::sharedD3DTexture0.isInitialized) sharedD3DTexture0.release() 116 | if (memoryObj != 0) glDeleteMemoryObjectsEXT(memoryObj) 117 | } 118 | 119 | override fun disposeFXResources() { 120 | if (this::sharedD3DTextureSurface.isInitialized) sharedD3DTextureSurface.release() 121 | if (this::sharedD3DTexture.isInitialized) sharedD3DTexture.release() 122 | if (this::fxD3DTextureSurface.isInitialized) fxD3DTextureSurface.release() 123 | if (this::fxD3DTexture.isInitialized) fxD3DTexture.release() 124 | if (this::texture.isInitialized) texture.dispose() 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/GLInteropType.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal 2 | 3 | import com.huskerdev.grapl.core.platform.OS 4 | import com.huskerdev.grapl.core.platform.Platform 5 | import com.huskerdev.grapl.gl.GLContext 6 | import com.huskerdev.openglfx.GLExecutor 7 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindTexture 8 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenTextures 9 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetError 10 | import com.huskerdev.openglfx.GL_BGRA 11 | import com.huskerdev.openglfx.GL_TEXTURE_2D 12 | import com.huskerdev.openglfx.internal.platforms.GL_HANDLE_TYPE_D3D11_IMAGE_KMT_EXT 13 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glCreateMemoryObjectsEXT 14 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glImportMemoryWin32HandleEXT 15 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glTextureStorageMem2DEXT 16 | import com.huskerdev.openglfx.internal.platforms.win.D3D9 17 | 18 | enum class GLInteropType { 19 | /** 20 | * Reads pixels by 'glBlitFramebuffer' and then creates JavaFX image. 21 | * 22 | * - Supported platforms: **All** 23 | */ 24 | Blit, 25 | 26 | /** 27 | * Uses WGL_NV_DX_interop extension to convert GL framebuffer to DirectX 9 textures. 28 | * 29 | * - Supported platforms: **Windows** 30 | */ 31 | WGLDXInterop, 32 | 33 | /** 34 | * Creates shared object between GL and DirectX 35 | * 36 | * - Supported platforms: **Windows** 37 | */ 38 | ExternalObjectsD3D, 39 | 40 | /** 41 | * Creates shared object between two GL context using Vulkan proxy 42 | * 43 | * - Supported platforms: **Windows** 44 | */ 45 | ExternalObjectsESWin, 46 | 47 | /** 48 | * Creates shared object between two GL context using Vulkan proxy 49 | * 50 | * - Supported platforms: **Linux** 51 | */ 52 | ExternalObjectsESLinux, 53 | 54 | /** 55 | * Creates memory block in VRAM that can be used in different OpenGL contexts. 56 | * 57 | * - Supported platforms: **macOS** 58 | */ 59 | IOSurface; 60 | 61 | companion object { 62 | val auto: GLInteropType by lazy { 63 | 64 | val pipeline = GLFXUtils.pipeline 65 | 66 | var hasWGLNVInteropExt = false 67 | var hasMemoryObjectExt = false 68 | 69 | // Create temporary context to fetch extension information (not on macOS) 70 | if(Platform.os != OS.MacOS) { 71 | val oldContext = GLContext.current() 72 | val tmpContext = GLContext.create() 73 | tmpContext.makeCurrent() 74 | 75 | // Get info 76 | val extensions = tmpContext.getExtensions() 77 | hasWGLNVInteropExt = tmpContext.hasFunction("wglDXOpenDeviceNV") && tmpContext.hasFunction("wglDXLockObjectsNV") 78 | hasMemoryObjectExt = "GL_EXT_memory_object" in extensions && ("GL_EXT_memory_object_win32" in extensions || "GL_EXT_memory_object_fd" in extensions) 79 | 80 | // Clear temporary context 81 | tmpContext.delete() 82 | oldContext.makeCurrent() 83 | } 84 | 85 | val type = when (Platform.os) { 86 | OS.Windows -> { 87 | if(pipeline == "d3d" && hasMemoryObjectExt && isDXGISupported()) 88 | ExternalObjectsD3D 89 | else if(pipeline == "es2" && hasMemoryObjectExt) 90 | ExternalObjectsESWin 91 | else if(pipeline == "d3d" && hasWGLNVInteropExt) 92 | WGLDXInterop 93 | else 94 | Blit 95 | } 96 | 97 | OS.Linux -> { 98 | if (pipeline == "es2" && hasMemoryObjectExt) 99 | ExternalObjectsESLinux 100 | else 101 | Blit 102 | } 103 | 104 | OS.MacOS -> { 105 | if(pipeline == "es2") 106 | IOSurface 107 | else 108 | Blit 109 | } 110 | OS.Other -> throw UnsupportedOperationException("Unsupported OS") 111 | } 112 | type 113 | } 114 | 115 | /** 116 | * Check if `glImportMemoryWin32HandleEXT` works, so we can use this interop 117 | */ 118 | private fun isDXGISupported(): Boolean{ 119 | // Create GL context and D3D9 device 120 | val oldContext = GLContext.current() 121 | val tmpContext = GLContext.create() 122 | tmpContext.makeCurrent() 123 | GLExecutor.loadBasicFunctionPointers() 124 | val d3d9 = D3D9.Device() 125 | 126 | // Simulate real interop process 127 | val texture = d3d9.createTexture(10, 10) 128 | val memoryObj = glCreateMemoryObjectsEXT() 129 | glImportMemoryWin32HandleEXT(memoryObj, 0, GL_HANDLE_TYPE_D3D11_IMAGE_KMT_EXT, texture.sharedHandle) 130 | 131 | val sharedTexture = glGenTextures() 132 | glBindTexture(GL_TEXTURE_2D, sharedTexture) 133 | glTextureStorageMem2DEXT(sharedTexture, 1, GL_BGRA, 10, 10, memoryObj, 0) 134 | 135 | // Check for errors 136 | val supported = glGetError() == 0 137 | 138 | // Release 139 | texture.release() 140 | tmpContext.delete() 141 | 142 | oldContext.makeCurrent() 143 | return supported 144 | } 145 | } 146 | } -------------------------------------------------------------------------------- /modules/libgdx/kotlin/com/huskerdev/openglfx/libgdx/internal/OGLFXGraphics.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.libgdx.internal 2 | 3 | import com.badlogic.gdx.AbstractGraphics 4 | import com.badlogic.gdx.Application 5 | import com.badlogic.gdx.Gdx 6 | import com.badlogic.gdx.Graphics 7 | import com.badlogic.gdx.Graphics.DisplayMode 8 | import com.badlogic.gdx.backends.lwjgl3.Lwjgl3GL32 9 | import com.badlogic.gdx.graphics.* 10 | import com.badlogic.gdx.graphics.Cursor.SystemCursor.* 11 | import com.badlogic.gdx.graphics.glutils.GLVersion 12 | import com.huskerdev.openglfx.canvas.GLCanvas 13 | import javafx.scene.ImageCursor 14 | import javafx.stage.Screen 15 | 16 | class OGLFXGraphics(val canvas: GLCanvas): AbstractGraphics() { 17 | private var gl20: GL20? = null 18 | private var gl30: GL30? = null 19 | private var gl31: GL31? = null 20 | private var gl32: GL32? = null 21 | 22 | init { 23 | gl32 = Lwjgl3GL32() 24 | gl31 = gl32 25 | gl30 = gl32 26 | gl20 = gl32 27 | 28 | Gdx.gl32 = gl32 29 | Gdx.gl31 = gl31 30 | Gdx.gl30 = gl30 31 | Gdx.gl20 = gl20 32 | Gdx.gl = Gdx.gl32 33 | } 34 | 35 | override fun isGL30Available() = true 36 | override fun isGL31Available() = true 37 | override fun isGL32Available() = true 38 | 39 | override fun getGL20() = gl20 40 | override fun getGL30() = gl30 41 | override fun getGL31() = gl31 42 | override fun getGL32() = gl32 43 | 44 | override fun setGL20(gl20: GL20?) { this.gl20 = gl20 } 45 | override fun setGL30(gl30: GL30?) { this.gl30 = gl30 } 46 | override fun setGL31(gl31: GL31?) { this.gl31 = gl31 } 47 | override fun setGL32(gl32: GL32?) { this.gl32 = gl32 } 48 | 49 | override fun getWidth() = canvas.width.toInt() 50 | override fun getHeight() = canvas.height.toInt() 51 | override fun getBackBufferWidth() = canvas.scaledWidth 52 | override fun getBackBufferHeight() = canvas.scaledHeight 53 | 54 | override fun getSafeInsetLeft() = 0 55 | override fun getSafeInsetTop() = 0 56 | override fun getSafeInsetBottom() = 0 57 | override fun getSafeInsetRight() = 0 58 | 59 | override fun getFrameId() = canvas.fpsCounter.frameId 60 | override fun getDeltaTime() = canvas.fpsCounter.delta.toFloat() 61 | override fun getFramesPerSecond() = canvas.fpsCounter.currentFps 62 | 63 | override fun getType() = Graphics.GraphicsType.LWJGL3 64 | 65 | override fun getGLVersion() = GLVersion(Application.ApplicationType.Desktop, "3.0 GL", 66 | "openglfx", "openglfx") 67 | 68 | override fun getPpiX() = 96f 69 | override fun getPpiY() = 96f 70 | 71 | override fun getPpcX() = 96f 72 | override fun getPpcY() = 96f 73 | 74 | override fun supportsDisplayModeChange() = false 75 | 76 | override fun getPrimaryMonitor() = FXMonitorWrapper(Screen.getPrimary()) 77 | 78 | override fun getMonitor(): Graphics.Monitor { 79 | val stage = canvas.scene.window 80 | return FXMonitorWrapper(Screen.getScreensForRectangle(stage.x, stage.y, stage.width, stage.height)[0]) 81 | } 82 | 83 | override fun getMonitors(): Array { 84 | val stage = canvas.scene.window 85 | return Screen.getScreensForRectangle(stage.x, stage.y, stage.width, stage.height) 86 | .map { FXMonitorWrapper(it) }.toTypedArray() 87 | } 88 | 89 | override fun getDisplayModes() = arrayOf(getDisplayMode()) 90 | override fun getDisplayModes(monitor: Graphics.Monitor?) = arrayOf(getDisplayMode()) 91 | override fun getDisplayMode() = object: DisplayMode(canvas.scaledWidth, canvas.scaledHeight, 0, 32) {} 92 | override fun getDisplayMode(monitor: Graphics.Monitor?) = getDisplayMode() 93 | 94 | override fun setFullscreenMode(displayMode: DisplayMode?) = false 95 | override fun setWindowedMode(width: Int, height: Int) = false 96 | override fun setTitle(title: String?) {} 97 | override fun setUndecorated(undecorated: Boolean) {} 98 | override fun setResizable(resizable: Boolean) {} 99 | override fun setVSync(vsync: Boolean) {} 100 | override fun setForegroundFPS(fps: Int) {} 101 | 102 | override fun getBufferFormat() = 103 | Graphics.BufferFormat(32, 32, 32, 32, 32, 32, 16, false) 104 | 105 | override fun supportsExtension(extension: String?) = true 106 | 107 | override fun setContinuousRendering(isContinuous: Boolean) { 108 | canvas.fps = 0.0 109 | } 110 | 111 | override fun isContinuousRendering() = canvas.fps == 0.0 112 | 113 | override fun requestRendering() { 114 | canvas.repaint() 115 | } 116 | 117 | override fun isFullscreen() = false 118 | 119 | override fun newCursor(pixmap: Pixmap, xHotspot: Int, yHotspot: Int) = 120 | FXCursorWrapper(pixmap, xHotspot, yHotspot) 121 | 122 | override fun setCursor(cursor: Cursor?) { 123 | canvas.cursor = if(cursor != null) (cursor as FXCursorWrapper).imageCursor else null 124 | } 125 | 126 | override fun setSystemCursor(systemCursor: Cursor.SystemCursor) { 127 | canvas.cursor = when(systemCursor) { 128 | Arrow, Ibeam, NotAllowed, None -> javafx.scene.Cursor.DEFAULT 129 | Crosshair -> javafx.scene.Cursor.CROSSHAIR 130 | Hand -> javafx.scene.Cursor.HAND 131 | HorizontalResize -> javafx.scene.Cursor.H_RESIZE 132 | VerticalResize -> javafx.scene.Cursor.V_RESIZE 133 | NWSEResize -> javafx.scene.Cursor.NW_RESIZE 134 | NESWResize -> javafx.scene.Cursor.NE_RESIZE 135 | AllResize -> javafx.scene.Cursor.MOVE 136 | } 137 | } 138 | 139 | class FXCursorWrapper(pixmap: Pixmap, xHotspot: Int, yHotspot: Int) : Cursor { 140 | val imageCursor = ImageCursor(FXPixmapImage(pixmap), xHotspot.toDouble(), yHotspot.toDouble()) 141 | override fun dispose() {} 142 | } 143 | 144 | class FXMonitorWrapper internal constructor(screen: Screen) : 145 | Graphics.Monitor(screen.bounds.width.toInt(), screen.bounds.height.toInt(), "Unnamed screen") 146 | 147 | } -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/canvas/ExternalObjectsCanvasES2.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal.canvas 2 | 3 | import com.huskerdev.openglfx.* 4 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindTexture 5 | import com.huskerdev.openglfx.GLExecutor.Companion.glFinish 6 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenTextures 7 | import com.huskerdev.openglfx.canvas.GLCanvas 8 | import com.huskerdev.openglfx.internal.GLFXUtils 9 | import com.huskerdev.openglfx.internal.NGGLCanvas 10 | 11 | import com.huskerdev.openglfx.internal.Framebuffer 12 | import com.huskerdev.openglfx.internal.GLFXUtils.Companion.fetchGLTexId 13 | import com.huskerdev.openglfx.internal.platforms.GL_HANDLE_TYPE_D3D11_IMAGE_KMT_EXT 14 | import com.huskerdev.openglfx.internal.platforms.GL_HANDLE_TYPE_OPAQUE_FD_EXT 15 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glCreateMemoryObjectsEXT 16 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glDeleteMemoryObjectsEXT 17 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glImportMemoryFdEXT 18 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glImportMemoryWin32HandleEXT 19 | import com.huskerdev.openglfx.internal.platforms.MemoryObjects.Companion.glTextureStorageMem2DEXT 20 | import com.huskerdev.openglfx.internal.platforms.VkExtMemory 21 | import com.sun.prism.Graphics 22 | 23 | import com.sun.prism.Texture 24 | import java.util.concurrent.atomic.AtomicBoolean 25 | 26 | 27 | abstract class ExternalObjectsCanvasES2( 28 | canvas: GLCanvas 29 | ) : NGGLCanvas(canvas) { 30 | 31 | private val vk = VkExtMemory.createVk() 32 | 33 | override fun onRenderThreadInit() = Unit 34 | override fun onRenderThreadEnd() = 35 | vk.destroy() 36 | 37 | override fun createSwapBuffer() = ExternalObjectsSwapBuffer() 38 | 39 | abstract fun importMemory(memoryObject: Int, size: Long, externalImage: VkExtMemory.ExternalImage) 40 | 41 | 42 | open class Win( 43 | canvas: GLCanvas 44 | ): ExternalObjectsCanvasES2(canvas) { 45 | override fun importMemory(memoryObject: Int, size: Long, externalImage: VkExtMemory.ExternalImage) = 46 | glImportMemoryWin32HandleEXT(memoryObject, size, GL_HANDLE_TYPE_D3D11_IMAGE_KMT_EXT, externalImage.getMemoryWin32Handle()) 47 | } 48 | 49 | open class Linux( 50 | canvas: GLCanvas 51 | ): ExternalObjectsCanvasES2(canvas) { 52 | override fun importMemory(memoryObject: Int, size: Long, externalImage: VkExtMemory.ExternalImage) = 53 | glImportMemoryFdEXT(memoryObject, size, GL_HANDLE_TYPE_OPAQUE_FD_EXT, externalImage.createMemoryFd()) 54 | } 55 | 56 | 57 | protected inner class ExternalObjectsSwapBuffer: SwapBuffer() { 58 | private lateinit var fbo: Framebuffer 59 | private lateinit var interopFBO: Framebuffer.Default 60 | private lateinit var externalImage: VkExtMemory.ExternalImage 61 | private var memoryObj = 0 62 | 63 | private lateinit var fxTexture: Texture 64 | private var fxTextureId = 0 65 | private lateinit var fxInteropFbo: Framebuffer 66 | private var fxMemoryObj = 0 67 | 68 | private val shouldUpdateBinding = AtomicBoolean() 69 | 70 | override fun render(width: Int, height: Int): Framebuffer { 71 | if(checkFramebufferSize(width, height)) 72 | canvas.fireReshapeEvent(width, height) 73 | 74 | fbo.bindFramebuffer() 75 | canvas.fireRenderEvent(fbo.id) 76 | fbo.blitTo(interopFBO) 77 | 78 | glFinish() 79 | return fbo 80 | } 81 | 82 | private fun checkFramebufferSize(width: Int, height: Int): Boolean{ 83 | if(!this::fbo.isInitialized || fbo.width != width || fbo.height != height){ 84 | dispose() 85 | 86 | externalImage = vk.createExternalImage(width, height) 87 | 88 | memoryObj = glCreateMemoryObjectsEXT() 89 | importMemory(memoryObj, externalImage.size, externalImage) 90 | 91 | val sharedTexture = glGenTextures() 92 | glBindTexture(GL_TEXTURE_2D, sharedTexture) 93 | glTextureStorageMem2DEXT(sharedTexture, 1, GL_RGBA8, width, height, memoryObj, 0) 94 | 95 | interopFBO = Framebuffer.Default(width, height, texture = sharedTexture) 96 | fbo = createFramebufferForRender(width, height) 97 | 98 | shouldUpdateBinding.set(true) 99 | return true 100 | } 101 | return false 102 | } 103 | 104 | override fun getTextureForDisplay(g: Graphics): Texture { 105 | val width = fbo.width 106 | val height = fbo.height 107 | 108 | if(shouldUpdateBinding.getAndSet(false)){ 109 | disposeFXResources() 110 | 111 | fxTexture = GLFXUtils.createPermanentFXTexture(width, height) 112 | fxTextureId = fetchGLTexId(fxTexture, g) 113 | 114 | fxMemoryObj = glCreateMemoryObjectsEXT() 115 | importMemory(fxMemoryObj, externalImage.size, externalImage) 116 | 117 | val sharedTexture = glGenTextures() 118 | glBindTexture(GL_TEXTURE_2D, sharedTexture) 119 | glTextureStorageMem2DEXT(sharedTexture, 1, GL_RGBA8, width, height, fxMemoryObj, 0) 120 | 121 | fxInteropFbo = Framebuffer.Default(width, height, texture = sharedTexture) 122 | } 123 | 124 | fxInteropFbo.copyToTexture(fxTextureId) 125 | 126 | return fxTexture 127 | } 128 | 129 | override fun dispose() { 130 | if (this::fbo.isInitialized) fbo.delete() 131 | if (this::interopFBO.isInitialized) interopFBO.delete() 132 | if (memoryObj != 0) glDeleteMemoryObjectsEXT(memoryObj) 133 | if (this::externalImage.isInitialized) externalImage.dispose() 134 | } 135 | 136 | override fun disposeFXResources() { 137 | if (this::fxTexture.isInitialized) fxTexture.dispose() 138 | if (this::fxInteropFbo.isInitialized) fxInteropFbo.delete() 139 | if (fxMemoryObj != 0) glDeleteMemoryObjectsEXT(fxMemoryObj) 140 | } 141 | } 142 | } -------------------------------------------------------------------------------- /plugins/maven/src/main/kotlin/com/huskerdev/plugins/maven/MavenPlugin.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.plugins.maven 2 | 3 | 4 | import com.fasterxml.jackson.databind.node.ArrayNode 5 | import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper 6 | import io.gitee.pkmer.enums.PublishingType 7 | import io.gitee.pkmer.extension.PkmerBootPluginExtension 8 | import org.gradle.api.Action 9 | import org.gradle.api.Plugin 10 | import org.gradle.api.Project 11 | import org.gradle.api.attributes.Usage 12 | import org.gradle.api.component.AdhocComponentWithVariants 13 | import org.gradle.api.component.SoftwareComponent 14 | import org.gradle.api.plugins.ExtraPropertiesExtension 15 | import org.gradle.api.publish.PublishingExtension 16 | import org.gradle.api.publish.maven.MavenPom 17 | import org.gradle.api.publish.maven.MavenPublication 18 | import org.gradle.api.publish.maven.tasks.PublishToMavenRepository 19 | import org.gradle.api.publish.tasks.GenerateModuleMetadata 20 | import org.gradle.kotlin.dsl.DependencyHandlerScope 21 | import org.gradle.kotlin.dsl.get 22 | import org.gradle.plugins.signing.SigningExtension 23 | 24 | private const val customConfiguration = "silentApi" 25 | private const val publicationName = "mavenJava" 26 | 27 | @Suppress("unused") 28 | class MavenPlugin: Plugin { 29 | 30 | override fun apply(project: Project) { 31 | project.pluginManager.apply("maven-publish") 32 | project.pluginManager.apply("signing") 33 | project.pluginManager.apply("io.gitee.pkmer.pkmerboot-central-publisher") 34 | 35 | val component = if(project.plugins.hasPlugin("java-platform")) 36 | project.components["javaPlatform"] else 37 | project.components["java"] 38 | 39 | addCustomConfiguration(project, customConfiguration, component) 40 | 41 | project.afterEvaluate { 42 | project.publishing { 43 | publications { 44 | create(publicationName, MavenPublication::class.java) { 45 | from(component) 46 | project.configurePom(pom) 47 | artifactId = pom.name.getOrElse("") 48 | groupId = project.group.toString() 49 | } 50 | } 51 | repositories { 52 | maven { 53 | name = "Local" 54 | url = project.uri(project.layout.buildDirectory.dir("repos/bundles")) 55 | } 56 | } 57 | } 58 | } 59 | 60 | project.signing { 61 | setRequired { 62 | project.gradle.taskGraph.allTasks.any { it is PublishToMavenRepository } 63 | } 64 | if(project.hasProperty("ossrhUsername")) 65 | sign(project.publishing.publications) 66 | } 67 | 68 | project.pkmerBoot { 69 | sonatypeMavenCentral{ 70 | stagingRepository.set(project.layout.buildDirectory.dir("repos/bundles")) 71 | 72 | username.set(project.properties["ossrhUsername"].toString()) 73 | password.set(project.properties["ossrhPassword"].toString()) 74 | 75 | publishingType.set(PublishingType.USER_MANAGED) 76 | } 77 | } 78 | } 79 | 80 | 81 | /** 82 | * Creates custom configuration to include in .pom 83 | */ 84 | private fun addCustomConfiguration(project: Project, name: String, component: SoftwareComponent){ 85 | val silentApi = project.configurations.create(name) { 86 | attributes { 87 | attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-api")) 88 | } 89 | } 90 | 91 | component as AdhocComponentWithVariants 92 | component.addVariantsFromConfiguration(silentApi) { 93 | mapToMavenScope("compile") 94 | } 95 | 96 | // Edit .module file, generated by gradle - adding pomOnlyCompile dependencies to apiElements 97 | project.tasks.withType(GenerateModuleMetadata::class.java) { 98 | doLast { 99 | val moduleJson = jacksonObjectMapper().readTree(outputFile.get().asFile.readText()) 100 | val variants = moduleJson["variants"] as ArrayNode 101 | 102 | val apiElements = variants.first { it["name"].asText() == "apiElements" } 103 | val runtimeElements = variants.first { it["name"].asText() == "runtimeElements" } 104 | val customVariant = variants.first { it["name"].asText() == name } 105 | 106 | if(customVariant.has("dependencies")) { 107 | val apiDeps = apiElements["dependencies"] as ArrayNode 108 | val runtimeDeps = runtimeElements["dependencies"] as ArrayNode 109 | val customDeps = customVariant["dependencies"] as ArrayNode 110 | 111 | apiDeps.addAll(customDeps) 112 | runtimeDeps.addAll(customDeps) 113 | variants.remove(variants.indexOf(customVariant)) 114 | 115 | val text = jacksonObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(moduleJson) 116 | outputFile.get().asFile.writeText(text) 117 | } 118 | } 119 | } 120 | } 121 | } 122 | 123 | @Suppress("unchecked_cast") 124 | private fun Project.configurePom(pom: MavenPom) { 125 | val projects = arrayListOf(this) 126 | 127 | while(projects.last().parent != null) 128 | projects += projects.last().parent!! 129 | 130 | projects.reversed().forEach { 131 | if(it.ext.has("pom")) 132 | (it.ext["pom"] as Action).execute(pom) 133 | } 134 | } 135 | 136 | private val Project.ext 137 | get() = this.extensions.getByType(ExtraPropertiesExtension::class.java) 138 | 139 | private val Project.publishing 140 | get() = project.extensions.findByType(PublishingExtension::class.java)!! 141 | 142 | private fun Project.publishing(block: PublishingExtension.() -> Unit) = 143 | publishing.apply(block) 144 | 145 | private fun Project.pkmerBoot(block: PkmerBootPluginExtension.() -> Unit) = 146 | project.extensions.getByType(PkmerBootPluginExtension::class.java).apply(block) 147 | 148 | private fun Project.signing(block: SigningExtension.() -> Unit) = 149 | project.extensions.getByType(SigningExtension::class.java).apply(block) 150 | 151 | fun DependencyHandlerScope.silentApi(string: String) = 152 | add(customConfiguration, string) 153 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_metal.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_METAL_H_ 2 | #define VULKAN_METAL_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_EXT_metal_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_EXT_metal_surface 1 24 | #ifdef __OBJC__ 25 | @class CAMetalLayer; 26 | #else 27 | typedef void CAMetalLayer; 28 | #endif 29 | 30 | #define VK_EXT_METAL_SURFACE_SPEC_VERSION 1 31 | #define VK_EXT_METAL_SURFACE_EXTENSION_NAME "VK_EXT_metal_surface" 32 | typedef VkFlags VkMetalSurfaceCreateFlagsEXT; 33 | typedef struct VkMetalSurfaceCreateInfoEXT { 34 | VkStructureType sType; 35 | const void* pNext; 36 | VkMetalSurfaceCreateFlagsEXT flags; 37 | const CAMetalLayer* pLayer; 38 | } VkMetalSurfaceCreateInfoEXT; 39 | 40 | typedef VkResult (VKAPI_PTR *PFN_vkCreateMetalSurfaceEXT)(VkInstance instance, const VkMetalSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 41 | 42 | #ifndef VK_NO_PROTOTYPES 43 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT( 44 | VkInstance instance, 45 | const VkMetalSurfaceCreateInfoEXT* pCreateInfo, 46 | const VkAllocationCallbacks* pAllocator, 47 | VkSurfaceKHR* pSurface); 48 | #endif 49 | 50 | 51 | // VK_EXT_metal_objects is a preprocessor guard. Do not pass it to API calls. 52 | #define VK_EXT_metal_objects 1 53 | #ifdef __OBJC__ 54 | @protocol MTLDevice; 55 | typedef __unsafe_unretained id MTLDevice_id; 56 | #else 57 | typedef void* MTLDevice_id; 58 | #endif 59 | 60 | #ifdef __OBJC__ 61 | @protocol MTLCommandQueue; 62 | typedef __unsafe_unretained id MTLCommandQueue_id; 63 | #else 64 | typedef void* MTLCommandQueue_id; 65 | #endif 66 | 67 | #ifdef __OBJC__ 68 | @protocol MTLBuffer; 69 | typedef __unsafe_unretained id MTLBuffer_id; 70 | #else 71 | typedef void* MTLBuffer_id; 72 | #endif 73 | 74 | #ifdef __OBJC__ 75 | @protocol MTLTexture; 76 | typedef __unsafe_unretained id MTLTexture_id; 77 | #else 78 | typedef void* MTLTexture_id; 79 | #endif 80 | 81 | typedef struct __IOSurface* IOSurfaceRef; 82 | #ifdef __OBJC__ 83 | @protocol MTLSharedEvent; 84 | typedef __unsafe_unretained id MTLSharedEvent_id; 85 | #else 86 | typedef void* MTLSharedEvent_id; 87 | #endif 88 | 89 | #define VK_EXT_METAL_OBJECTS_SPEC_VERSION 2 90 | #define VK_EXT_METAL_OBJECTS_EXTENSION_NAME "VK_EXT_metal_objects" 91 | 92 | typedef enum VkExportMetalObjectTypeFlagBitsEXT { 93 | VK_EXPORT_METAL_OBJECT_TYPE_METAL_DEVICE_BIT_EXT = 0x00000001, 94 | VK_EXPORT_METAL_OBJECT_TYPE_METAL_COMMAND_QUEUE_BIT_EXT = 0x00000002, 95 | VK_EXPORT_METAL_OBJECT_TYPE_METAL_BUFFER_BIT_EXT = 0x00000004, 96 | VK_EXPORT_METAL_OBJECT_TYPE_METAL_TEXTURE_BIT_EXT = 0x00000008, 97 | VK_EXPORT_METAL_OBJECT_TYPE_METAL_IOSURFACE_BIT_EXT = 0x00000010, 98 | VK_EXPORT_METAL_OBJECT_TYPE_METAL_SHARED_EVENT_BIT_EXT = 0x00000020, 99 | VK_EXPORT_METAL_OBJECT_TYPE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF 100 | } VkExportMetalObjectTypeFlagBitsEXT; 101 | typedef VkFlags VkExportMetalObjectTypeFlagsEXT; 102 | typedef struct VkExportMetalObjectCreateInfoEXT { 103 | VkStructureType sType; 104 | const void* pNext; 105 | VkExportMetalObjectTypeFlagBitsEXT exportObjectType; 106 | } VkExportMetalObjectCreateInfoEXT; 107 | 108 | typedef struct VkExportMetalObjectsInfoEXT { 109 | VkStructureType sType; 110 | const void* pNext; 111 | } VkExportMetalObjectsInfoEXT; 112 | 113 | typedef struct VkExportMetalDeviceInfoEXT { 114 | VkStructureType sType; 115 | const void* pNext; 116 | MTLDevice_id mtlDevice; 117 | } VkExportMetalDeviceInfoEXT; 118 | 119 | typedef struct VkExportMetalCommandQueueInfoEXT { 120 | VkStructureType sType; 121 | const void* pNext; 122 | VkQueue queue; 123 | MTLCommandQueue_id mtlCommandQueue; 124 | } VkExportMetalCommandQueueInfoEXT; 125 | 126 | typedef struct VkExportMetalBufferInfoEXT { 127 | VkStructureType sType; 128 | const void* pNext; 129 | VkDeviceMemory memory; 130 | MTLBuffer_id mtlBuffer; 131 | } VkExportMetalBufferInfoEXT; 132 | 133 | typedef struct VkImportMetalBufferInfoEXT { 134 | VkStructureType sType; 135 | const void* pNext; 136 | MTLBuffer_id mtlBuffer; 137 | } VkImportMetalBufferInfoEXT; 138 | 139 | typedef struct VkExportMetalTextureInfoEXT { 140 | VkStructureType sType; 141 | const void* pNext; 142 | VkImage image; 143 | VkImageView imageView; 144 | VkBufferView bufferView; 145 | VkImageAspectFlagBits plane; 146 | MTLTexture_id mtlTexture; 147 | } VkExportMetalTextureInfoEXT; 148 | 149 | typedef struct VkImportMetalTextureInfoEXT { 150 | VkStructureType sType; 151 | const void* pNext; 152 | VkImageAspectFlagBits plane; 153 | MTLTexture_id mtlTexture; 154 | } VkImportMetalTextureInfoEXT; 155 | 156 | typedef struct VkExportMetalIOSurfaceInfoEXT { 157 | VkStructureType sType; 158 | const void* pNext; 159 | VkImage image; 160 | IOSurfaceRef ioSurface; 161 | } VkExportMetalIOSurfaceInfoEXT; 162 | 163 | typedef struct VkImportMetalIOSurfaceInfoEXT { 164 | VkStructureType sType; 165 | const void* pNext; 166 | IOSurfaceRef ioSurface; 167 | } VkImportMetalIOSurfaceInfoEXT; 168 | 169 | typedef struct VkExportMetalSharedEventInfoEXT { 170 | VkStructureType sType; 171 | const void* pNext; 172 | VkSemaphore semaphore; 173 | VkEvent event; 174 | MTLSharedEvent_id mtlSharedEvent; 175 | } VkExportMetalSharedEventInfoEXT; 176 | 177 | typedef struct VkImportMetalSharedEventInfoEXT { 178 | VkStructureType sType; 179 | const void* pNext; 180 | MTLSharedEvent_id mtlSharedEvent; 181 | } VkImportMetalSharedEventInfoEXT; 182 | 183 | typedef void (VKAPI_PTR *PFN_vkExportMetalObjectsEXT)(VkDevice device, VkExportMetalObjectsInfoEXT* pMetalObjectsInfo); 184 | 185 | #ifndef VK_NO_PROTOTYPES 186 | VKAPI_ATTR void VKAPI_CALL vkExportMetalObjectsEXT( 187 | VkDevice device, 188 | VkExportMetalObjectsInfoEXT* pMetalObjectsInfo); 189 | #endif 190 | 191 | #ifdef __cplusplus 192 | } 193 | #endif 194 | 195 | #endif 196 | -------------------------------------------------------------------------------- /modules/core/native/include/vulkan/vulkan_android.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_ANDROID_H_ 2 | #define VULKAN_ANDROID_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2024 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_android_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_android_surface 1 24 | struct ANativeWindow; 25 | #define VK_KHR_ANDROID_SURFACE_SPEC_VERSION 6 26 | #define VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "VK_KHR_android_surface" 27 | typedef VkFlags VkAndroidSurfaceCreateFlagsKHR; 28 | typedef struct VkAndroidSurfaceCreateInfoKHR { 29 | VkStructureType sType; 30 | const void* pNext; 31 | VkAndroidSurfaceCreateFlagsKHR flags; 32 | struct ANativeWindow* window; 33 | } VkAndroidSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateAndroidSurfaceKHR)(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | 37 | #ifndef VK_NO_PROTOTYPES 38 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR( 39 | VkInstance instance, 40 | const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, 41 | const VkAllocationCallbacks* pAllocator, 42 | VkSurfaceKHR* pSurface); 43 | #endif 44 | 45 | 46 | // VK_ANDROID_external_memory_android_hardware_buffer is a preprocessor guard. Do not pass it to API calls. 47 | #define VK_ANDROID_external_memory_android_hardware_buffer 1 48 | struct AHardwareBuffer; 49 | #define VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_SPEC_VERSION 5 50 | #define VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME "VK_ANDROID_external_memory_android_hardware_buffer" 51 | typedef struct VkAndroidHardwareBufferUsageANDROID { 52 | VkStructureType sType; 53 | void* pNext; 54 | uint64_t androidHardwareBufferUsage; 55 | } VkAndroidHardwareBufferUsageANDROID; 56 | 57 | typedef struct VkAndroidHardwareBufferPropertiesANDROID { 58 | VkStructureType sType; 59 | void* pNext; 60 | VkDeviceSize allocationSize; 61 | uint32_t memoryTypeBits; 62 | } VkAndroidHardwareBufferPropertiesANDROID; 63 | 64 | typedef struct VkAndroidHardwareBufferFormatPropertiesANDROID { 65 | VkStructureType sType; 66 | void* pNext; 67 | VkFormat format; 68 | uint64_t externalFormat; 69 | VkFormatFeatureFlags formatFeatures; 70 | VkComponentMapping samplerYcbcrConversionComponents; 71 | VkSamplerYcbcrModelConversion suggestedYcbcrModel; 72 | VkSamplerYcbcrRange suggestedYcbcrRange; 73 | VkChromaLocation suggestedXChromaOffset; 74 | VkChromaLocation suggestedYChromaOffset; 75 | } VkAndroidHardwareBufferFormatPropertiesANDROID; 76 | 77 | typedef struct VkImportAndroidHardwareBufferInfoANDROID { 78 | VkStructureType sType; 79 | const void* pNext; 80 | struct AHardwareBuffer* buffer; 81 | } VkImportAndroidHardwareBufferInfoANDROID; 82 | 83 | typedef struct VkMemoryGetAndroidHardwareBufferInfoANDROID { 84 | VkStructureType sType; 85 | const void* pNext; 86 | VkDeviceMemory memory; 87 | } VkMemoryGetAndroidHardwareBufferInfoANDROID; 88 | 89 | typedef struct VkExternalFormatANDROID { 90 | VkStructureType sType; 91 | void* pNext; 92 | uint64_t externalFormat; 93 | } VkExternalFormatANDROID; 94 | 95 | typedef struct VkAndroidHardwareBufferFormatProperties2ANDROID { 96 | VkStructureType sType; 97 | void* pNext; 98 | VkFormat format; 99 | uint64_t externalFormat; 100 | VkFormatFeatureFlags2 formatFeatures; 101 | VkComponentMapping samplerYcbcrConversionComponents; 102 | VkSamplerYcbcrModelConversion suggestedYcbcrModel; 103 | VkSamplerYcbcrRange suggestedYcbcrRange; 104 | VkChromaLocation suggestedXChromaOffset; 105 | VkChromaLocation suggestedYChromaOffset; 106 | } VkAndroidHardwareBufferFormatProperties2ANDROID; 107 | 108 | typedef VkResult (VKAPI_PTR *PFN_vkGetAndroidHardwareBufferPropertiesANDROID)(VkDevice device, const struct AHardwareBuffer* buffer, VkAndroidHardwareBufferPropertiesANDROID* pProperties); 109 | typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryAndroidHardwareBufferANDROID)(VkDevice device, const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, struct AHardwareBuffer** pBuffer); 110 | 111 | #ifndef VK_NO_PROTOTYPES 112 | VKAPI_ATTR VkResult VKAPI_CALL vkGetAndroidHardwareBufferPropertiesANDROID( 113 | VkDevice device, 114 | const struct AHardwareBuffer* buffer, 115 | VkAndroidHardwareBufferPropertiesANDROID* pProperties); 116 | 117 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryAndroidHardwareBufferANDROID( 118 | VkDevice device, 119 | const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, 120 | struct AHardwareBuffer** pBuffer); 121 | #endif 122 | 123 | 124 | // VK_ANDROID_external_format_resolve is a preprocessor guard. Do not pass it to API calls. 125 | #define VK_ANDROID_external_format_resolve 1 126 | #define VK_ANDROID_EXTERNAL_FORMAT_RESOLVE_SPEC_VERSION 1 127 | #define VK_ANDROID_EXTERNAL_FORMAT_RESOLVE_EXTENSION_NAME "VK_ANDROID_external_format_resolve" 128 | typedef struct VkPhysicalDeviceExternalFormatResolveFeaturesANDROID { 129 | VkStructureType sType; 130 | void* pNext; 131 | VkBool32 externalFormatResolve; 132 | } VkPhysicalDeviceExternalFormatResolveFeaturesANDROID; 133 | 134 | typedef struct VkPhysicalDeviceExternalFormatResolvePropertiesANDROID { 135 | VkStructureType sType; 136 | void* pNext; 137 | VkBool32 nullColorAttachmentWithExternalFormatResolve; 138 | VkChromaLocation externalFormatResolveChromaOffsetX; 139 | VkChromaLocation externalFormatResolveChromaOffsetY; 140 | } VkPhysicalDeviceExternalFormatResolvePropertiesANDROID; 141 | 142 | typedef struct VkAndroidHardwareBufferFormatResolvePropertiesANDROID { 143 | VkStructureType sType; 144 | void* pNext; 145 | VkFormat colorAttachmentFormat; 146 | } VkAndroidHardwareBufferFormatResolvePropertiesANDROID; 147 | 148 | 149 | #ifdef __cplusplus 150 | } 151 | #endif 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /modules/core/kotlin/com/huskerdev/openglfx/internal/Framebuffer.kt: -------------------------------------------------------------------------------- 1 | package com.huskerdev.openglfx.internal 2 | 3 | import com.huskerdev.openglfx.* 4 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindFramebuffer 5 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindRenderbuffer 6 | import com.huskerdev.openglfx.GLExecutor.Companion.glBindTexture 7 | import com.huskerdev.openglfx.GLExecutor.Companion.glBlitFramebuffer 8 | import com.huskerdev.openglfx.GLExecutor.Companion.glCopyTexSubImage2D 9 | import com.huskerdev.openglfx.GLExecutor.Companion.glDeleteFramebuffers 10 | import com.huskerdev.openglfx.GLExecutor.Companion.glDeleteRenderbuffers 11 | import com.huskerdev.openglfx.GLExecutor.Companion.glDeleteTextures 12 | import com.huskerdev.openglfx.GLExecutor.Companion.glFramebufferRenderbuffer 13 | import com.huskerdev.openglfx.GLExecutor.Companion.glFramebufferTexture2D 14 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenFramebuffers 15 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenRenderbuffers 16 | import com.huskerdev.openglfx.GLExecutor.Companion.glGenTextures 17 | import com.huskerdev.openglfx.GLExecutor.Companion.glGetInteger 18 | import com.huskerdev.openglfx.GLExecutor.Companion.glReadPixels 19 | import com.huskerdev.openglfx.GLExecutor.Companion.glRenderbufferStorage 20 | import com.huskerdev.openglfx.GLExecutor.Companion.glRenderbufferStorageMultisample 21 | import com.huskerdev.openglfx.GLExecutor.Companion.glTexImage2D 22 | import com.huskerdev.openglfx.GLExecutor.Companion.glTexParameteri 23 | import java.nio.ByteBuffer 24 | import kotlin.math.min 25 | 26 | abstract class Framebuffer( 27 | val width: Int, 28 | val height: Int 29 | ) { 30 | 31 | var id: Int = 0 32 | var depthRenderbuffer: Int = 0 33 | 34 | class Default( 35 | width: Int, 36 | height: Int, 37 | texture: Int = -1, 38 | textureType: Int = GL_TEXTURE_2D, 39 | textureCreationFormat: Int = GL_RGBA // Used when texture is -1 40 | ): Framebuffer(width, height){ 41 | val texture: Int 42 | 43 | init { 44 | val oldDrawBuffer = glGetInteger(GL_DRAW_FRAMEBUFFER_BINDING) 45 | val oldReadBuffer = glGetInteger(GL_READ_FRAMEBUFFER_BINDING) 46 | 47 | id = glGenFramebuffers() 48 | glBindFramebuffer(GL_FRAMEBUFFER, id) 49 | 50 | if(texture == -1) { 51 | this.texture = glGenTextures() 52 | glBindTexture(textureType, this.texture) 53 | glTexImage2D( 54 | textureType, 0, 55 | textureCreationFormat, width, height, 0, 56 | textureCreationFormat, GL_UNSIGNED_BYTE, null) 57 | glTexParameteri(textureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST) 58 | }else { 59 | this.texture = texture 60 | glBindTexture(textureType, this.texture) 61 | } 62 | 63 | glFramebufferTexture2D( 64 | GL_FRAMEBUFFER, 65 | GL_COLOR_ATTACHMENT0, textureType, this.texture, 0) 66 | 67 | depthRenderbuffer = glGenRenderbuffers() 68 | glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer) 69 | glRenderbufferStorage( 70 | GL_RENDERBUFFER, 71 | GL_DEPTH_COMPONENT, width, height) 72 | glFramebufferRenderbuffer( 73 | GL_FRAMEBUFFER, 74 | GL_DEPTH_ATTACHMENT, 75 | GL_RENDERBUFFER, depthRenderbuffer) 76 | 77 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDrawBuffer) 78 | glBindFramebuffer(GL_READ_FRAMEBUFFER, oldReadBuffer) 79 | } 80 | 81 | fun readPixels(x: Int, y: Int, width: Int, height: Int, format: Int, type: Int, targetBuffer: ByteBuffer){ 82 | val oldReadBuffer = glGetInteger(GL_READ_FRAMEBUFFER_BINDING) 83 | 84 | glBindFramebuffer(GL_READ_FRAMEBUFFER, id) 85 | glReadPixels(x, y, width, height, format, type, targetBuffer) 86 | glBindFramebuffer(GL_READ_FRAMEBUFFER, oldReadBuffer) 87 | } 88 | 89 | override fun delete() { 90 | super.delete() 91 | glDeleteTextures(texture) 92 | } 93 | } 94 | 95 | class MultiSampled( 96 | width: Int, 97 | height: Int, 98 | requestedSamples: Int 99 | ): Framebuffer( 100 | width, height 101 | ) { 102 | val samples: Int = min(glGetInteger(GL_MAX_SAMPLES), requestedSamples) 103 | val colorRenderBuffer: Int 104 | 105 | init { 106 | id = glGenFramebuffers() 107 | glBindFramebuffer(GL_FRAMEBUFFER, id) 108 | 109 | depthRenderbuffer = glGenRenderbuffers() 110 | glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer) 111 | glRenderbufferStorageMultisample( 112 | GL_RENDERBUFFER, this.samples, 113 | GL_DEPTH_COMPONENT, width, height) 114 | glFramebufferRenderbuffer( 115 | GL_FRAMEBUFFER, 116 | GL_DEPTH_ATTACHMENT, 117 | GL_RENDERBUFFER, depthRenderbuffer) 118 | 119 | colorRenderBuffer = glGenRenderbuffers() 120 | glBindRenderbuffer(GL_RENDERBUFFER, colorRenderBuffer) 121 | glRenderbufferStorageMultisample( 122 | GL_RENDERBUFFER, this.samples, 123 | GL_RGBA8, width, height) 124 | glFramebufferRenderbuffer( 125 | GL_FRAMEBUFFER, 126 | GL_COLOR_ATTACHMENT0, 127 | GL_RENDERBUFFER, colorRenderBuffer) 128 | 129 | glBindFramebuffer(GL_FRAMEBUFFER, 0) 130 | } 131 | 132 | override fun delete() { 133 | super.delete() 134 | glDeleteRenderbuffers(colorRenderBuffer) 135 | } 136 | } 137 | 138 | 139 | fun bindFramebuffer(){ 140 | glBindFramebuffer(GL_FRAMEBUFFER, id) 141 | } 142 | 143 | fun blitTo(fbo: Int){ 144 | val oldDrawBuffer = glGetInteger(GL_DRAW_FRAMEBUFFER_BINDING) 145 | val oldReadBuffer = glGetInteger(GL_READ_FRAMEBUFFER_BINDING) 146 | 147 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo) 148 | glBindFramebuffer(GL_READ_FRAMEBUFFER, id) 149 | glBlitFramebuffer( 150 | 0, 0, width, height, 151 | 0, 0, width, height, 152 | GL_COLOR_BUFFER_BIT, GL_NEAREST 153 | ) 154 | 155 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDrawBuffer) 156 | glBindFramebuffer(GL_READ_FRAMEBUFFER, oldReadBuffer) 157 | } 158 | 159 | fun blitTo(fbo: Framebuffer) = blitTo(fbo.id) 160 | 161 | fun copyToTexture(texture: Int){ 162 | val oldReadBuffer = glGetInteger(GL_READ_FRAMEBUFFER_BINDING) 163 | glBindFramebuffer(GL_READ_FRAMEBUFFER, id) 164 | 165 | glBindTexture(GL_TEXTURE_2D, texture) 166 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height) 167 | 168 | glBindFramebuffer(GL_READ_FRAMEBUFFER, oldReadBuffer) 169 | } 170 | 171 | open fun delete(){ 172 | glDeleteFramebuffers(id) 173 | glDeleteRenderbuffers(depthRenderbuffer) 174 | } 175 | } --------------------------------------------------------------------------------