7777
7878import static org .lwjgl .system .MemoryUtil .*;
7979import static com .jme3 .system .lwjglx .LwjglxDefaultGLPlatform .*;
80+ import org .lwjgl .system .Platform ;
8081
8182/**
8283 * Class <code>LwjglCanvas</code> that integrates <a href="https://github.com/LWJGLX/lwjgl3-awt">LWJGLX</a>
@@ -116,47 +117,53 @@ public class LwjglCanvas extends LwjglWindow implements JmeCanvasContext, Runnab
116117
117118 /*
118119 Register the different versions.
120+
121+ The 'COMPATIBILITY' profile is used for operational reasons on different
122+ platforms.
123+
124+ see the discussion:
125+ https://github.com/jMonkeyEngine/jmonkeyengine/pull/2153#issuecomment-1860913192
119126 */
120127 static {
121128 RENDER_CONFIGS .put (AppSettings .LWJGL_OPENGL32 , (data ) -> {
122129 data .majorVersion = 3 ;
123130 data .minorVersion = 2 ;
124- data .profile = GLData .Profile .CORE ;
131+ data .profile = GLData .Profile .COMPATIBILITY ;
125132 });
126133 RENDER_CONFIGS .put (AppSettings .LWJGL_OPENGL33 , (data ) -> {
127134 data .majorVersion = 3 ;
128135 data .minorVersion = 3 ;
129- data .profile = GLData .Profile .CORE ;
136+ data .profile = GLData .Profile .COMPATIBILITY ;
130137 });
131138 RENDER_CONFIGS .put (AppSettings .LWJGL_OPENGL40 , (data ) -> {
132139 data .majorVersion = 4 ;
133140 data .minorVersion = 0 ;
134- data .profile = GLData .Profile .CORE ;
141+ data .profile = GLData .Profile .COMPATIBILITY ;
135142 });
136143 RENDER_CONFIGS .put (AppSettings .LWJGL_OPENGL41 , (data ) -> {
137144 data .majorVersion = 4 ;
138145 data .minorVersion = 1 ;
139- data .profile = GLData .Profile .CORE ;
146+ data .profile = GLData .Profile .COMPATIBILITY ;
140147 });
141148 RENDER_CONFIGS .put (AppSettings .LWJGL_OPENGL42 , (data ) -> {
142149 data .majorVersion = 4 ;
143150 data .minorVersion = 2 ;
144- data .profile = GLData .Profile .CORE ;
151+ data .profile = GLData .Profile .COMPATIBILITY ;
145152 });
146153 RENDER_CONFIGS .put (AppSettings .LWJGL_OPENGL43 , (data ) -> {
147154 data .majorVersion = 4 ;
148155 data .minorVersion = 3 ;
149- data .profile = GLData .Profile .CORE ;
156+ data .profile = GLData .Profile .COMPATIBILITY ;
150157 });
151158 RENDER_CONFIGS .put (AppSettings .LWJGL_OPENGL44 , (data ) -> {
152159 data .majorVersion = 4 ;
153160 data .minorVersion = 4 ;
154- data .profile = GLData .Profile .CORE ;
161+ data .profile = GLData .Profile .COMPATIBILITY ;
155162 });
156163 RENDER_CONFIGS .put (AppSettings .LWJGL_OPENGL45 , (data ) -> {
157164 data .majorVersion = 4 ;
158165 data .minorVersion = 5 ;
159- data .profile = GLData .Profile .CORE ;
166+ data .profile = GLData .Profile .COMPATIBILITY ;
160167 });
161168 }
162169
@@ -452,6 +459,47 @@ public void componentResized(ComponentEvent e) {
452459 });
453460 }
454461
462+ /**
463+ * Returns the GL context handler.
464+ *
465+ * @return String
466+ */
467+ @ Override
468+ protected String getCurrentVideoDriver () {
469+ StringBuilder buffer = new StringBuilder ();
470+ buffer .append ("AWT|Swing (LWJGLX) GLv" )
471+ .append (canvas .data .majorVersion )
472+ .append ('.' )
473+ .append (canvas .data .minorVersion );
474+
475+ String driver = isWayland () ? "(XWayland|X11) GLX" : "X11 GLX" ;
476+
477+ Platform platform = Platform .get ();
478+ if (null == platform ) {
479+ buffer .append (" Unknown NULL" );
480+ } else {
481+ switch (platform ) {
482+ case FREEBSD :
483+ buffer .append (" FreeBSD " )
484+ .append (driver );
485+ break ;
486+ case LINUX :
487+ buffer .append (" Linux " )
488+ .append (driver );
489+ break ;
490+ case MACOSX :
491+ buffer .append (" MacOSX Cocoa NSGL" );
492+ break ;
493+ case WINDOWS :
494+ buffer .append (" Win32 WGL" );
495+ break ;
496+ default :
497+ break ;
498+ }
499+ }
500+ return String .valueOf (buffer );
501+ }
502+
455503 /**
456504 * Check if the canvas is displayed, that is, if it has a parent that has set it up.
457505 * <p>
@@ -688,7 +736,7 @@ protected void createContext(AppSettings settings) {
688736 }
689737
690738 glData .alphaSize = settings .getAlphaBits ();
691- glData .sRGB = settings .isGammaCorrection () && ! useAuxFramebufferSrgb ();
739+ glData .sRGB = settings .isGammaCorrection (); // Not compatible with very old devices
692740
693741 glData .depthSize = settings .getDepthBits ();
694742 glData .stencilSize = settings .getStencilBits ();
@@ -697,7 +745,11 @@ protected void createContext(AppSettings settings) {
697745
698746 glData .debug = settings .isGraphicsDebug ();
699747 glData .api = GLData .API .GL ;
700- glData .forwardCompatible = true ;
748+
749+ /* This is done to prevent the context from breaking in Windows,
750+ * since the 'CORE' profile causes rendering failures (black screen).
751+ */
752+ glData .forwardCompatible = false ;
701753
702754 allowSwapBuffers = settings .isSwapBuffers ();
703755
@@ -766,7 +818,7 @@ public JoyInput getJoyInput() {
766818 /** (non-Javadoc) */
767819 @ Override protected void showWindow () { }
768820 /** (non-Javadoc) */
769- @ Override protected void setWindowIcon (final AppSettings settings ) { }
821+ @ Override protected void setWindowIcon (final AppSettings settings ) { }
770822 /**(non-Javadoc) */
771823 @ Override public Vector2f getWindowContentScale (Vector2f store ) {
772824 return store == null ? new Vector2f () : store ;
@@ -1005,4 +1057,26 @@ public int getPrimaryDisplay() {
10051057 public Canvas getCanvas () {
10061058 return canvas ;
10071059 }
1060+
1061+ /**
1062+ * {@inheritDoc}
1063+ * @param settings AppSettings
1064+ */
1065+ @ Override
1066+ public void setSettings (AppSettings settings ) {
1067+ if (settings .getRenderer ().equals (AppSettings .ANGLE_GLES3 )) {
1068+ StringBuilder buffer = new StringBuilder ();
1069+ buffer .append ("LWJGX is not compatible with ANGLE/SDL or GLES, as it only supports the following:" )
1070+ .append ('\n' ).append (" * WGL | Windows" )
1071+ .append ('\n' ).append (" * GLX | Linux (X11/XWayland)" )
1072+ .append ('\n' ).append (" * CGL | MacOsX" )
1073+ .append ('\n' ).append (" * Therefore, version " )
1074+ .append (AppSettings .LWJGL_OPENGL32 )
1075+ .append ("(3.2) will be used for the GL context." );
1076+
1077+ LOGGER .log (Level .WARNING , String .valueOf (buffer ));
1078+ settings .setRenderer (AppSettings .LWJGL_OPENGL32 );
1079+ }
1080+ super .setSettings (settings );
1081+ }
10081082}
0 commit comments