-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package utils | ||
|
||
import org.jetbrains.skiko.GraphicsApi | ||
import org.jetbrains.skiko.OS | ||
import org.jetbrains.skiko.hostOs | ||
|
||
object Renderer { | ||
|
||
// private const val RENDER_API_KEY = "skiko.renderApi" | ||
|
||
// fun setRender() { | ||
// when(SystemTools.getOS()) { | ||
// OsWindows, OsLinux -> { | ||
// System.setProperty(RENDER_API_KEY, "OPENGL") | ||
// } | ||
// OsMac -> { | ||
// | ||
// } | ||
// } | ||
// } | ||
|
||
internal fun parseRenderApi(text: String?): GraphicsApi { | ||
return when (text) { | ||
"SOFTWARE_COMPAT" -> GraphicsApi.SOFTWARE_COMPAT | ||
"SOFTWARE_FAST", "DIRECT_SOFTWARE", "SOFTWARE" -> GraphicsApi.SOFTWARE_FAST | ||
"OPENGL" -> GraphicsApi.OPENGL | ||
"DIRECT3D" -> { | ||
if (hostOs == OS.Windows) GraphicsApi.DIRECT3D | ||
else throw UnsupportedOperationException("$hostOs does not support DirectX rendering API.") | ||
} | ||
"METAL" -> { | ||
if (hostOs == OS.MacOS) GraphicsApi.METAL | ||
else throw UnsupportedOperationException("$hostOs does not support Metal rendering API.") | ||
} | ||
else -> bestRenderApiForCurrentOS() | ||
} | ||
} | ||
|
||
private fun bestRenderApiForCurrentOS(): GraphicsApi { | ||
return when (hostOs) { | ||
OS.MacOS -> GraphicsApi.METAL | ||
OS.Linux -> GraphicsApi.OPENGL | ||
OS.Windows -> GraphicsApi.DIRECT3D | ||
OS.JS, OS.Ios -> TODO("commonize me") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package utils | ||
|
||
import java.util.* | ||
|
||
object SystemTools { | ||
|
||
fun getOS(): OS { | ||
val os = System.getProperty("os.name").lowercase(Locale.getDefault()) | ||
return when { | ||
os.contains("window") -> OsWindows | ||
os.contains("nix") || os.contains("nux") || os.contains("aix") -> OsLinux | ||
os.contains("os x") || os.contains("mac") -> OsMac | ||
else -> throw UnsupportedOperationException("Operating system $os is not supported") | ||
} | ||
} | ||
|
||
} | ||
|
||
sealed interface OS | ||
object OsWindows : OS | ||
object OsLinux : OS | ||
object OsMac : OS |