From 5195b582560838723333d24d1e1e5c2658ab184d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D1=82=D0=B5=D0=BD=D0=B3=D0=B0=D1=83=D1=8D=D1=80=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=94=D0=BC=D0=B8=D1=82?= =?UTF-8?q?=D1=80=D0=B8=D0=B5=D0=B2=D0=B8=D1=87?= Date: Tue, 17 Dec 2024 19:23:59 +0300 Subject: [PATCH] Added checking for macOS in GLInteropType.kt --- gradle.properties | 2 +- .../kotlin/com/huskerdev/openglfx/GLFXInfo.kt | 2 +- .../openglfx/internal/GLInteropType.kt | 32 +++++++++++++------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9ae3fc7..77cce78 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ projectName=openglfx -version=4.1.5 +version=4.1.6 kotlinVersion=2.0.20 graplVersion=2.3.2 diff --git a/modules/core/kotlin/com/huskerdev/openglfx/GLFXInfo.kt b/modules/core/kotlin/com/huskerdev/openglfx/GLFXInfo.kt index 055525d..f672dde 100644 --- a/modules/core/kotlin/com/huskerdev/openglfx/GLFXInfo.kt +++ b/modules/core/kotlin/com/huskerdev/openglfx/GLFXInfo.kt @@ -3,6 +3,6 @@ package com.huskerdev.openglfx // Generated with gradle class GLFXInfo { companion object { - const val VERSION = "4.1.5" + const val VERSION = "4.1.6" } } \ No newline at end of file diff --git a/modules/core/kotlin/com/huskerdev/openglfx/internal/GLInteropType.kt b/modules/core/kotlin/com/huskerdev/openglfx/internal/GLInteropType.kt index 120a176..789c587 100644 --- a/modules/core/kotlin/com/huskerdev/openglfx/internal/GLInteropType.kt +++ b/modules/core/kotlin/com/huskerdev/openglfx/internal/GLInteropType.kt @@ -1,6 +1,7 @@ package com.huskerdev.openglfx.internal import com.huskerdev.grapl.core.platform.OS +import com.huskerdev.grapl.core.platform.Platform import com.huskerdev.grapl.gl.GLContext import com.huskerdev.openglfx.GLExecutor import com.huskerdev.openglfx.GLExecutor.Companion.glBindTexture @@ -61,27 +62,40 @@ enum class GLInteropType { companion object { val auto: GLInteropType by lazy { val pipeline = GraphicsPipeline.getPipeline().javaClass.canonicalName.split(".")[3] - val oldContext = GLContext.current() - val tmpContext = GLContext.create() - tmpContext.makeCurrent() - val extensions = tmpContext.getExtensions() - val hasMemoryObjectExt = "GL_EXT_memory_object" in extensions && ("GL_EXT_memory_object_win32" in extensions || "GL_EXT_memory_object_fd" in extensions) + var hasWGLNVInteropExt = false + var hasMemoryObjectExt = false + + // Create temporary context to fetch extension information (not on macOS) + if(Platform.os != OS.MacOS) { + val oldContext = GLContext.current() + val tmpContext = GLContext.create() + tmpContext.makeCurrent() + + // Get info + val extensions = tmpContext.getExtensions() + hasWGLNVInteropExt = tmpContext.hasFunction("wglDXOpenDeviceNV") && tmpContext.hasFunction("wglDXLockObjectsNV") + hasMemoryObjectExt = "GL_EXT_memory_object" in extensions && ("GL_EXT_memory_object_win32" in extensions || "GL_EXT_memory_object_fd" in extensions) - val type = when (com.huskerdev.grapl.core.platform.Platform.os) { + // Clear temporary context + tmpContext.delete() + oldContext.makeCurrent() + } + + val type = when (Platform.os) { OS.Windows -> { if(pipeline == "d3d" && hasMemoryObjectExt && isDXGISupported()) ExternalObjectsWinD3D else if(pipeline == "es2" && hasMemoryObjectExt) ExternalObjectsWinES - else if(pipeline == "d3d" && tmpContext.hasFunction("wglDXOpenDeviceNV") && tmpContext.hasFunction("wglDXLockObjectsNV")) + else if(pipeline == "d3d" && hasWGLNVInteropExt) WGLDXInterop else Blit } OS.Linux -> { - if (pipeline == "es2" && "GL_EXT_memory_object" in extensions && "GL_EXT_memory_object_fd" in extensions) + if (pipeline == "es2" && hasMemoryObjectExt) ExternalObjectsFd else Blit @@ -95,8 +109,6 @@ enum class GLInteropType { } OS.Other -> throw UnsupportedOperationException("Unsupported OS") } - tmpContext.delete() - oldContext.makeCurrent() type }