Browse Source

wl|support for changing the platform

wil 2 months ago
parent
commit
db482cf8b2

+ 34 - 1
jme3-core/src/main/java/com/jme3/system/AppSettings.java

@@ -214,7 +214,7 @@ public final class AppSettings extends HashMap<String, Object> {
      * @see AppSettings#setAudioRenderer(java.lang.String)
      */
     public static final String LWJGL_OPENAL = "LWJGL";
-
+    
     /**
      * Use the Android MediaPlayer / SoundPool based renderer for Android audio capabilities.
      * <p>
@@ -295,6 +295,7 @@ public final class AppSettings extends HashMap<String, Object> {
         defaults.put("UseRetinaFrameBuffer", false);
         defaults.put("WindowYPosition", 0);
         defaults.put("WindowXPosition", 0);
+        defaults.put("NativePlatform", true);
         //  defaults.put("Icons", null);
     }
 
@@ -1507,4 +1508,36 @@ public final class AppSettings extends HashMap<String, Object> {
     public void setDisplay(int mon) {
         putInteger("Display", mon);
     }
+
+    /**
+     * Sets the native platform to be used to create the GL context.
+     * 
+     * <p>
+     * This only affects Linux distributions or derivatives that use a Wayland session in conjunction 
+     * with X11 via the XWayland bridge, which enables or disables GLX for window positioning and/or 
+     * icon configuration.
+     * </p>
+     *
+     * <p>
+     * <strong>NOTE:</strong> Note that disabling this option uses GLX (native X11) instead of EGL (native WL).
+     * </p>
+     * 
+     * @param nplaf true when using EGL (native), otherwise false if you want to enable GLX
+     */
+    public void setNativePlatform(boolean nplaf) {
+        put("NativePlatform", nplaf);
+    }
+    
+    /**
+     * Gets what type of platform is being used.
+     * 
+     * <p>
+     * Only valid on Linux distributions or derivatives that support Wayland, where it indicates whether GLX or EGL is enabled.
+     * </p>
+     * 
+     * @return returns true if used in EGL (native), otherwise false if GLX is enabled
+     */
+    public boolean isNativePlatform() {
+        return getBoolean("NativePlatform");
+    }
 }

+ 13 - 1
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java

@@ -273,7 +273,19 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
                     }
                 }
         );
-
+                
+        if (glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) {
+            
+            /*
+             * Change the platform GLFW uses to enable GLX on Wayland as long as you 
+             * have XWayland (X11 compatibility)
+             */
+            if (!settings.isNativePlatform() && glfwPlatformSupported(GLFW_PLATFORM_X11)) {
+                glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
+            }
+            
+        }
+        
         if (!glfwInit()) {
             throw new IllegalStateException("Unable to initialize GLFW");
         }