Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions jme3-examples/src/main/java/jme3test/awt/TestCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public static void createCanvas(String appClass){
// Note: Only for Linux and Wayland platforms, forces you to
// use XWayland (x11) with awt.
settings.setX11PlatformPreferred(true);
settings.setRenderer(AppSettings.LWJGL_OPENGL32);
settings.setWidth(640);
settings.setHeight(480);

Expand Down
99 changes: 87 additions & 12 deletions jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

import static org.lwjgl.system.MemoryUtil.*;
import static com.jme3.system.lwjglx.LwjglxDefaultGLPlatform.*;
import org.lwjgl.system.Platform;

/**
* Class <code>LwjglCanvas</code> that integrates <a href="https://github.com/LWJGLX/lwjgl3-awt">LWJGLX</a>
Expand All @@ -100,7 +101,8 @@
* <pre><code>
* ....
* AppSettings settings = new AppSettings(true);
* settings.setGammaCorrection(false);
* settings.setGammaCorrection(true);
* settings.setRenderer(AppSettings.LWJGL_OPENGL32);
* ...
* </code></pre>
*
Expand All @@ -116,47 +118,53 @@ public class LwjglCanvas extends LwjglWindow implements JmeCanvasContext, Runnab

/*
Register the different versions.

The 'COMPATIBILITY' profile is used for operational reasons on different
platforms.

see the discussion:
https://github.com/jMonkeyEngine/jmonkeyengine/pull/2153#issuecomment-1860913192
*/
static {
RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL32, (data) -> {
data.majorVersion = 3;
data.minorVersion = 2;
data.profile = GLData.Profile.CORE;
data.profile = GLData.Profile.COMPATIBILITY;
});
RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL33, (data) -> {
data.majorVersion = 3;
data.minorVersion = 3;
data.profile = GLData.Profile.CORE;
data.profile = GLData.Profile.COMPATIBILITY;
});
RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL40, (data) -> {
data.majorVersion = 4;
data.minorVersion = 0;
data.profile = GLData.Profile.CORE;
data.profile = GLData.Profile.COMPATIBILITY;
});
RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL41, (data) -> {
data.majorVersion = 4;
data.minorVersion = 1;
data.profile = GLData.Profile.CORE;
data.profile = GLData.Profile.COMPATIBILITY;
});
RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL42, (data) -> {
data.majorVersion = 4;
data.minorVersion = 2;
data.profile = GLData.Profile.CORE;
data.profile = GLData.Profile.COMPATIBILITY;
});
RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL43, (data) -> {
data.majorVersion = 4;
data.minorVersion = 3;
data.profile = GLData.Profile.CORE;
data.profile = GLData.Profile.COMPATIBILITY;
});
RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL44, (data) -> {
data.majorVersion = 4;
data.minorVersion = 4;
data.profile = GLData.Profile.CORE;
data.profile = GLData.Profile.COMPATIBILITY;
});
RENDER_CONFIGS.put(AppSettings.LWJGL_OPENGL45, (data) -> {
data.majorVersion = 4;
data.minorVersion = 5;
data.profile = GLData.Profile.CORE;
data.profile = GLData.Profile.COMPATIBILITY;
});
}

Expand Down Expand Up @@ -452,6 +460,47 @@ public void componentResized(ComponentEvent e) {
});
}

/**
* Returns the GL context handler.
*
* @return String
*/
@Override
protected String getCurrentVideoDriver() {
StringBuilder buffer = new StringBuilder();
buffer.append("AWT|Swing (LWJGLX) GLv")
.append(canvas.data.majorVersion)
.append('.')
.append(canvas.data.minorVersion);

String driver = isWayland() ? "(XWayland|X11) GLX" : "X11 GLX";
Comment thread
JNightRider marked this conversation as resolved.

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;
}
}
return String.valueOf(buffer);
}

/**
* Check if the canvas is displayed, that is, if it has a parent that has set it up.
* <p>
Expand Down Expand Up @@ -688,7 +737,7 @@ protected void createContext(AppSettings settings) {
}

glData.alphaSize = settings.getAlphaBits();
glData.sRGB = settings.isGammaCorrection() && !useAuxFramebufferSrgb();
glData.sRGB = settings.isGammaCorrection(); // Not compatible with very old devices
Comment thread
JNightRider marked this conversation as resolved.

glData.depthSize = settings.getDepthBits();
glData.stencilSize = settings.getStencilBits();
Expand All @@ -697,7 +746,11 @@ protected void createContext(AppSettings settings) {

glData.debug = settings.isGraphicsDebug();
glData.api = GLData.API.GL;
glData.forwardCompatible = true;

/* This is done to prevent the context from breaking in Windows,
* since the 'CORE' profile causes rendering failures (black screen).
*/
glData.forwardCompatible = false;

allowSwapBuffers = settings.isSwapBuffers();

Expand Down Expand Up @@ -766,7 +819,7 @@ public JoyInput getJoyInput() {
/** (non-Javadoc) */
@Override protected void showWindow() { }
/** (non-Javadoc) */
@Override protected void setWindowIcon(final AppSettings settings) { }
@Override protected void setWindowIcon(final AppSettings settings) { }
/**(non-Javadoc) */
@Override public Vector2f getWindowContentScale(Vector2f store) {
return store == null ? new Vector2f() : store;
Expand Down Expand Up @@ -1005,4 +1058,26 @@ public int getPrimaryDisplay() {
public Canvas getCanvas() {
return canvas;
}

/**
* {@inheritDoc}
* @param settings AppSettings
*/
@Override
public void setSettings(AppSettings settings) {
if (settings.getRenderer().equals(AppSettings.ANGLE_GLES3)) {
StringBuilder buffer = new StringBuilder();
buffer.append("LWJGX 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(" * CGL | MacOsX")
.append('\n').append(" * Therefore, version ")
.append(AppSettings.LWJGL_OPENGL32)
.append("(3.2) will be used for the GL context.");

LOGGER.log(Level.WARNING, String.valueOf(buffer));
settings.setRenderer(AppSettings.LWJGL_OPENGL32);
}
Comment thread
JNightRider marked this conversation as resolved.
super.setSettings(settings);
}
}
20 changes: 10 additions & 10 deletions jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java
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 @@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.jme3.system.lwjgl;

import com.jme3.input.JoyInput;
Expand All @@ -55,28 +54,27 @@
import com.jme3.util.LWJGLBufferAllocator.ConcurrentLWJGLBufferAllocator;
import com.jme3.util.LWJGLSaferAllocMemoryAllocator;

import static com.jme3.util.LWJGLBufferAllocator.PROPERTY_CONCURRENT_BUFFER_ALLOCATOR;
import java.nio.IntBuffer;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.lwjgl.Version;
import org.lwjgl.opengl.ARBDebugOutput;
import org.lwjgl.opengl.ARBFramebufferObject;
import org.lwjgl.opengl.EXTFramebufferMultisample;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;

import static org.lwjgl.opengl.GL.createCapabilities;
import static org.lwjgl.opengl.GL11.glGetInteger;
import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.opengles.GLES;
import org.lwjgl.opengles.GLES30;
import org.lwjgl.opengles.GLESCapabilities;
import static org.lwjgl.sdl.SDLVideo.*;
import org.lwjgl.system.Configuration;
import org.lwjgl.system.MemoryStack;

import static org.lwjgl.opengl.GL.createCapabilities;
import static org.lwjgl.opengl.GL11.glGetInteger;
import static com.jme3.util.LWJGLBufferAllocator.PROPERTY_CONCURRENT_BUFFER_ALLOCATOR;

/**
* A LWJGL implementation of a graphics context.
Expand Down Expand Up @@ -149,11 +147,13 @@ public void setSystemListener(final SystemListener listener) {

protected void printContextInitInfo() {
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, "LWJGL {0} context running on thread {1}\n * Video backend: SDL {2}",
APIUtil.toArray(Version.getVersion(), Thread.currentThread().getName(), SDL_GetCurrentVideoDriver()));
logger.log(Level.INFO, "LWJGL {0} context running on thread {1}\n * Video backend: {2}",
APIUtil.toArray(Version.getVersion(), Thread.currentThread().getName(), getCurrentVideoDriver()));
}
}

protected abstract String getCurrentVideoDriver();
Comment thread
JNightRider marked this conversation as resolved.

protected int determineMaxSamples() {
final GLCapabilities capabilities = org.lwjgl.opengl.GL.getCapabilities();
if (capabilities.GL_ARB_framebuffer_object) {
Expand Down
35 changes: 20 additions & 15 deletions jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@
*/
package com.jme3.system.lwjgl;

import static org.lwjgl.egl.EXTPlatformWayland.EGL_PLATFORM_WAYLAND_EXT;
import static org.lwjgl.egl.EXTPlatformX11.EGL_PLATFORM_X11_EXT;
import static org.lwjgl.sdl.SDLError.*;
import static org.lwjgl.sdl.SDLEvents.*;
import static org.lwjgl.sdl.SDLHints.*;
import static org.lwjgl.sdl.SDLInit.*;
import static org.lwjgl.sdl.SDLKeyboard.*;
import static org.lwjgl.sdl.SDLMouse.*;
import static org.lwjgl.sdl.SDLPixels.*;
import static org.lwjgl.sdl.SDLSurface.*;
import static org.lwjgl.sdl.SDLStdinc.SDL_setenv_unsafe;
import static org.lwjgl.sdl.SDLVideo.*;
import static org.lwjgl.system.MemoryUtil.NULL;

import com.jme3.app.Application;
import com.jme3.asset.AssetManager;
import com.jme3.input.JoyInput;
Expand Down Expand Up @@ -75,6 +61,8 @@
import com.jme3.ui.Picture;
import com.jme3.util.BufferUtils;
import com.jme3.util.SafeArrayList;
import com.jme3.renderer.opengl.GLRenderer;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
Expand All @@ -85,14 +73,26 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.lwjgl.Version;
import org.lwjgl.sdl.SDL_DisplayMode;
import org.lwjgl.sdl.SDL_Event;
import org.lwjgl.sdl.SDL_Surface;
import org.lwjgl.sdl.SDLStdinc;
import org.lwjgl.system.Configuration;
import org.lwjgl.system.MemoryStack;
import com.jme3.renderer.opengl.GLRenderer;

import static org.lwjgl.egl.EXTPlatformWayland.EGL_PLATFORM_WAYLAND_EXT;
import static org.lwjgl.egl.EXTPlatformX11.EGL_PLATFORM_X11_EXT;
import static org.lwjgl.sdl.SDLError.*;
import static org.lwjgl.sdl.SDLEvents.*;
import static org.lwjgl.sdl.SDLHints.*;
import static org.lwjgl.sdl.SDLInit.*;
import static org.lwjgl.sdl.SDLPixels.*;
import static org.lwjgl.sdl.SDLSurface.*;
import static org.lwjgl.sdl.SDLStdinc.SDL_setenv_unsafe;
import static org.lwjgl.sdl.SDLVideo.*;
import static org.lwjgl.system.MemoryUtil.NULL;

/**
* SDL3-backed window/context implementation for LWJGL 3.4+.
Expand Down Expand Up @@ -243,6 +243,11 @@ private static void disableNvidiaThreadedOptimizations() {
}
}

@Override
protected String getCurrentVideoDriver() {
return "SDL " + SDL_GetCurrentVideoDriver();
}

@Override
public JmeContext.Type getType() {
return type;
Expand Down