Skip to content

Commit

Permalink
Added checking for macOS in GLInteropType.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
Штенгауэр Никита Дмитриевич committed Dec 17, 2024
1 parent 21060e0 commit 5195b58
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
projectName=openglfx
version=4.1.5
version=4.1.6

kotlinVersion=2.0.20
graplVersion=2.3.2
Expand Down
2 changes: 1 addition & 1 deletion modules/core/kotlin/com/huskerdev/openglfx/GLFXInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -95,8 +109,6 @@ enum class GLInteropType {
}
OS.Other -> throw UnsupportedOperationException("Unsupported OS")
}
tmpContext.delete()
oldContext.makeCurrent()
type
}

Expand Down

0 comments on commit 5195b58

Please sign in to comment.