From 606fbe8b3f4c420f1c4faecf4f49276e054543a0 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 9 Dec 2019 07:12:56 +0100 Subject: Bug 1156: NEWT WindowDriver: Handle case with requested CapabilitiesImmutable not being GLCapabilitiesImmutable --- .../classes/com/jogamp/opengl/GLCapabilities.java | 10 ++++++++++ .../opengl/egl/EGLGraphicsConfigurationFactory.java | 19 +++++++++++++++++++ .../jogamp/newt/driver/egl/gbm/WindowDriver.java | 4 ++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/jogl/classes/com/jogamp/opengl/GLCapabilities.java b/src/jogl/classes/com/jogamp/opengl/GLCapabilities.java index 02aa47119..411951851 100644 --- a/src/jogl/classes/com/jogamp/opengl/GLCapabilities.java +++ b/src/jogl/classes/com/jogamp/opengl/GLCapabilities.java @@ -98,6 +98,16 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil } } + /** + * Copies all {@link CapabilitiesImmutable} values + * from source into this instance. + * @return this instance + */ + public GLCapabilities copyFrom(final CapabilitiesImmutable source) { + super.copyFrom(source); + return this; + } + /** * Copies all {@link GLCapabilitiesImmutable} values * from source into this instance. diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java index 1d9a9732d..02bbafc95 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java @@ -219,6 +219,25 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact return availableCaps; } + /** + * Returns a {@link GLCapabilitiesImmutable} based on the given {@link CapabilitiesImmutable}. + *

+ * If the given {@code caps} is an instance of {@link GLCapabilitiesImmutable}, same reference will be returned, + * otherwise a new {@link GLCapabilitiesImmutable} using the default EGL GLProfile will be created and all + * given {@link CapabilitiesImmutable} values copied into. + *

+ * @param caps + * @return immutable {@link GLCapabilitiesImmutable} either identical to {@code caps} or a new instance, see above. + */ + public static final GLCapabilitiesImmutable castOrCopyImmutable(final CapabilitiesImmutable caps) { + if ( caps instanceof GLCapabilitiesImmutable ) { + return (GLCapabilitiesImmutable)caps; + } else { + final GLCapabilities glCapsReq = new GLCapabilities( GLProfile.getDefault( GLDrawableFactory.getEGLFactory().getDefaultDevice() ) ); + return glCapsReq.copyFrom(caps); + } + } + /** * Called mainly by {@link #chooseGraphicsConfigurationImpl(CapabilitiesImmutable, CapabilitiesImmutable, CapabilitiesChooser, AbstractGraphicsScreen, int)} * @param capsChosen the intermediate chosen capabilities to be refined by this implementation, may be equal to capsRequested diff --git a/src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java index 6d9940b95..a3af050c5 100644 --- a/src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java @@ -125,8 +125,9 @@ public class WindowDriver extends WindowImpl { throw new GLException("Caught: eglBindAPI to "+(ctDesktopGL ? "ES" : "GL")+" failed , error "+toHexString(EGL.eglGetError())); } + final GLCapabilitiesImmutable glCapsReq = EGLGraphicsConfigurationFactory.castOrCopyImmutable(capsRequested); final EGLGraphicsConfiguration eglConfig = EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( - (GLCapabilitiesImmutable)capsRequested, (GLCapabilitiesImmutable)capsRequested, (GLCapabilitiesChooser)capabilitiesChooser, + glCapsReq, glCapsReq, (GLCapabilitiesChooser)capabilitiesChooser, aScreen, nativeVisualID, !capsRequested.isBackgroundOpaque()); if (eglConfig == null) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); @@ -137,7 +138,6 @@ public class WindowDriver extends WindowImpl { if (nativeWindowHandle == 0) { throw new NativeWindowException("Error creating egl window: "+eglConfig); } - setGraphicsConfiguration(eglConfig); setWindowHandle(nativeWindowHandle); if (0 == getWindowHandle()) { throw new NativeWindowException("Error native Window Handle is null"); -- cgit v1.2.3