Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ junit4 = "junit:junit:4.13.2"
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" }
lwjgl2 = "org.jmonkeyengine:lwjgl:2.9.5"
lwjgl3-awt = "org.jmonkeyengine:lwjgl3-awt:0.2.4"
lwjgl3-awt = "org.lwjglx:lwjgl3-awt:0.2.5"

lwjgl3-base = { module = "org.lwjgl:lwjgl", version.ref = "lwjgl3" }
lwjgl3-glfw = { module = "org.lwjgl:lwjgl-glfw", version.ref = "lwjgl3" }
Expand Down
15 changes: 11 additions & 4 deletions jme3-examples/src/main/java/jme3test/awt/TestCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.jme3.app.SimpleApplication;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;
import com.jme3.system.JmeSystem;
import com.jme3.system.Platform;
import com.jme3.util.JmeFormatter;
import java.awt.BorderLayout;
import java.awt.Canvas;
Expand All @@ -60,6 +62,7 @@ public class TestCanvas {
private static Container canvasPanel1, canvasPanel2;
private static Container currentPanel;
private static JTabbedPane tabbedPane;
private static boolean platformX11 = false;
private static final String appClass = "jme3test.post.TestRenderToTexture";

private static void createTabs(){
Expand Down Expand Up @@ -170,7 +173,7 @@ public void actionPerformed(ActionEvent e){
public void actionPerformed(ActionEvent e) {
currentPanel.remove(canvas);
app.stop(true);

createCanvas(appClass);
currentPanel.add(canvas, BorderLayout.CENTER);
frame.pack();
Expand All @@ -187,6 +190,10 @@ public void actionPerformed(ActionEvent ae) {
app.stop();
}
});

if (JmeSystem.getPlatform().getOs() == Platform.Os.Linux) {
frame.setTitle("Test - Platform " + (platformX11 ? "X11" : "XWayland"));
}
}

private static void createFrame(){
Expand All @@ -207,9 +214,9 @@ public void windowClosed(WindowEvent e) {
public static void createCanvas(String appClass){
AppSettings settings = new AppSettings(true);

// Note: Only for Linux and Wayland platforms, forces you to
// use XWayland (x11) with awt.
settings.setX11PlatformPreferred(true);
// Note: Only for Linux and Wayland platforms, select the
// XWayland or x11 platform (if possible).
settings.setX11PlatformPreferred(platformX11);
settings.setRenderer(AppSettings.LWJGL_OPENGL32);
settings.setWidth(640);
settings.setHeight(480);
Expand Down
92 changes: 49 additions & 43 deletions jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import org.lwjgl.opengl.awt.GLData;

import org.lwjgl.system.Configuration;
import org.lwjgl.system.Platform;

import static org.lwjgl.system.MemoryUtil.*;
import static com.jme3.system.lwjglx.LwjglxDefaultGLPlatform.*;
Expand Down Expand Up @@ -185,10 +184,10 @@ private class LwjglAWTGLCanvas extends Canvas {
/**
* Information object used to create the OpenGL context.
*/
private GLData data;
private final GLData data;

/** Effective data to initialize the context. */
private GLData effective;
private final GLData effective;

/**
* Constructor of the <code>LwjglAWTGLCanva</code> class where objects are
Expand All @@ -200,14 +199,35 @@ public LwjglAWTGLCanvas(GLData data) {
this.effective = new GLData();
this.context = NULL;
this.data = data;
}

/**
* Create the platform according to the operating system and user
* preferences.
*
* @param settings Backend configurations
*/
public void createPlatform(AppSettings settings) {
try {
platformCanvas = createLwjglxGLPlatform();
platformCanvas = createLwjglxGLPlatform(settings);
} catch (UnsupportedOperationException e) {
listener.handleError(e.getLocalizedMessage(), e);
}
}

/**
* Returns information about the controllers (names) that are being
* used.
*
* @return String
*/
public String getVideoDriver() {
if (platformCanvas == null) {
return "Unknown NULL";
}
return platformCanvas.getVideoDriver();
}

/**
* (non-Javadoc)
* @see java.awt.Component#addComponentListener(java.awt.event.ComponentListener)
Expand Down Expand Up @@ -464,33 +484,8 @@ protected String getCurrentVideoDriver() {
buffer.append("AWT|Swing (LWJGLX) GLv")
.append(canvas.data.majorVersion)
.append('.')
.append(canvas.data.minorVersion);

String driver = JmeSystem.isWaylandSession() ? "(XWayland|X11) GLX" : "X11 GLX";

Platform platform = Platform.get();
if (null == platform) {
buffer.append(" Unknown NULL");
} else {
switch (platform) {
case FREEBSD:
buffer.append(" FreeBSD ")
.append(driver);
break;
case LINUX:
buffer.append(" Linux ")
.append(driver);
break;
case MACOSX:
buffer.append(" MacOSX Cocoa NSGL");
break;
case WINDOWS:
buffer.append(" Win32 WGL");
break;
default:
break;
}
}
.append(canvas.data.minorVersion)
.append(' ').append(canvas.getVideoDriver());
return String.valueOf(buffer);
}

Expand Down Expand Up @@ -539,11 +534,13 @@ public void run() {
renderer.cleanup();
}

canvas.lock();
canvas.releaseContext();
canvas.deleteContext();
canvas.doDisposeCanvas();
canvas.context = NULL;
} finally {
canvas.unlock();
renderable.set(false);
lock.notifyAll();
}
Expand Down Expand Up @@ -705,19 +702,12 @@ protected void destroyContext() {
*/
@Override
protected void createContext(AppSettings settings) {
boolean linux = Platform.get() == Platform.LINUX
|| Platform.get() == Platform.FREEBSD;
if (!settings.isX11PlatformPreferred() && linux && JmeSystem.isWaylandSession()) {
LOGGER.log(Level.WARNING, "LWJGLX and AWT/Swing only work with X11, so XWayland will be used for GLX.");
}

// HACK: For LWJGLX to work in Wyland, it is necessary to use GLX via
// XWayland, so LWJGL must be forced to load GLX as a native API.
// This is because LWJGLX does not provide an EGL context.
if (linux && JmeSystem.isWaylandSession()) {
if (settings.isX11PlatformPreferred() && JmeSystem.isWaylandSession()) {
Configuration.OPENGL_CONTEXT_API.set("native");
LOGGER.log(Level.INFO, "The use of GLX is forced through XWayland (X11).");
}

canvas.createPlatform(settings);
RENDER_CONFIGS.computeIfAbsent(settings.getRenderer(), (t) -> {
return (data) -> {
data.majorVersion = 2;
Expand Down Expand Up @@ -761,7 +751,12 @@ protected void createContext(AppSettings settings) {
allowSwapBuffers = settings.isSwapBuffers();

canvas.createContext();
canvas.makeCurrent();
try {
canvas.lock();
canvas.makeCurrent();
} finally {
canvas.unlock();
}

SwingUtilities.invokeLater(() -> {
canvas.validate();
Expand Down Expand Up @@ -1070,7 +1065,8 @@ public void setSettings(AppSettings settings) {
StringBuilder buffer = new StringBuilder();
buffer.append("LWJGLX is not compatible with ANGLE/SDL or GLES, as it only supports the following:")
.append('\n').append(" * WGL | Windows")
.append('\n').append(" * GLX | Linux (X11/XWayland)")
.append('\n').append(" * GLX | Linux (X11)")
.append('\n').append(" * EGL | Linux (XWayland)")
.append('\n').append(" * CGL | MacOsX")
.append('\n').append(" * Therefore, version ")
.append(AppSettings.LWJGL_OPENGL32)
Expand All @@ -1079,6 +1075,16 @@ public void setSettings(AppSettings settings) {
LOGGER.log(Level.WARNING, String.valueOf(buffer));
settings.setRenderer(AppSettings.LWJGL_OPENGL32);
}

if (isGLInitAPI() && JmeSystem.isWaylandSession()
&& (getSettings().isX11PlatformPreferred() != settings.isX11PlatformPreferred())) {
LOGGER.log(Level.WARNING, " Platform Preferred: \n"
+ " * It is not possible to switch platforms at runtime (from GLX to EGL or vice versa)");

settings.setX11PlatformPreferred(
getSettings().isX11PlatformPreferred()
);
}
super.setSettings(settings);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2023 jMonkeyEngine
* Copyright (c) 2009-2026 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,8 +31,12 @@
*/
package com.jme3.system.lwjglx;

import org.lwjgl.system.Platform;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeSystem;

import java.util.concurrent.atomic.AtomicBoolean;

import org.lwjgl.system.Platform;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.Platform.*;

Expand All @@ -42,6 +46,11 @@
*/
public final class LwjglxDefaultGLPlatform {

/**
* A flag indicating that the GL API has been initialized or loaded.
*/
private static final AtomicBoolean CHECK_GL_INITAPI = new AtomicBoolean(false);

/**
* Detects if you are in a Wayland session.
*
Expand All @@ -61,6 +70,18 @@ public static boolean isWayland() {
return false;
}

/**
* Returns the value of the indicator signaling the load status of the GL
* API.
*
* @see #CHECK_GL_INITAPI
*
* @return boolean
*/
public static boolean isGLInitAPI() {
return CHECK_GL_INITAPI.get();
}

/**
* Returns the pointer to a {@code Display*} that uses X11.
*
Expand All @@ -80,17 +101,23 @@ public static long getX11Display(LwjglxGLPlatform platform) {
/**
* Returns a drawing platform based on the platform it is running on.
*
* @param settings AppSettings
*
* @return LwjglxGLPlatform
*
* @throws UnsupportedOperationException throws exception if platform is not
* supported
* supported
*/
public static LwjglxGLPlatform createLwjglxGLPlatform() throws UnsupportedOperationException {
public static LwjglxGLPlatform createLwjglxGLPlatform(AppSettings settings) throws UnsupportedOperationException {
CHECK_GL_INITAPI.set(true);
switch (Platform.get()) {
case WINDOWS:
return new Win32GLPlatform();
case FREEBSD:
case LINUX:
return new X11GLPlatform();
return JmeSystem.isWaylandSession() && !settings.isX11PlatformPreferred()
? new WaylandGLPlatform()
: new X11GLPlatform();
case MACOSX:
return new MacOSXGLPlatform();
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2023 jMonkeyEngine
* Copyright (c) 2009-2026 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -41,6 +41,13 @@
*/
public interface LwjglxGLPlatform extends PlatformGLCanvas {

/**
* Returns information about the controllers (names) that are being used.
*
* @return String
*/
String getVideoDriver();

/**
* Free the drawing surface.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2023 jMonkeyEngine
* Copyright (c) 2009-2026 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -42,6 +42,17 @@
*/
final class MacOSXGLPlatform extends PlatformMacOSXGLCanvas implements LwjglxGLPlatform {

/**
* (non-Javadoc)
* @see com.jme3.system.lwjglx.LwjglxGLPlatform#getVideoDriver()
*
* @return String
*/
@Override
public String getVideoDriver() {
return "MacOSX Cocoa NSGL";
}

/**
* (non-Javadoc)
* @see com.jme3.system.lwjglx.LwjglxGLPlatform#destroy()
Expand Down
Loading