summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/egl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/egl')
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLContext.java37
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java28
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java70
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java24
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java18
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java204
6 files changed, 257 insertions, 124 deletions
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
index 9028f4377..dcef1cd3d 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
@@ -37,6 +37,7 @@
package jogamp.opengl.egl;
import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
import java.util.Map;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
@@ -48,6 +49,7 @@ import javax.media.opengl.GLProfile;
import jogamp.opengl.GLContextImpl;
import jogamp.opengl.GLDrawableImpl;
+import com.jogamp.common.nio.Buffers;
import com.jogamp.gluegen.runtime.ProcAddressTable;
import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver;
@@ -160,7 +162,7 @@ public abstract class EGLContext extends GLContextImpl {
try {
// might be unavailable on EGL < 1.2
if(!EGL.eglBindAPI(EGL.EGL_OPENGL_ES_API)) {
- throw new GLException("eglBindAPI to ES failed , error 0x"+Integer.toHexString(EGL.eglGetError()));
+ throw new GLException("Catched: eglBindAPI to ES failed , error 0x"+Integer.toHexString(EGL.eglGetError()));
}
} catch (GLException glex) {
if (DEBUG) {
@@ -175,18 +177,22 @@ public abstract class EGLContext extends GLContextImpl {
}
}
- int[] contextAttrs = new int[] {
- EGL.EGL_CONTEXT_CLIENT_VERSION, -1,
- EGL.EGL_NONE
- };
- if (glProfile.usesNativeGLES2()) {
- contextAttrs[1] = 2;
- } else if (glProfile.usesNativeGLES1()) {
- contextAttrs[1] = 1;
- } else {
- throw new GLException("Error creating OpenGL context - invalid GLProfile: "+glProfile);
+ final IntBuffer contextAttrsNIO;
+ {
+ final int[] contextAttrs = new int[] {
+ EGL.EGL_CONTEXT_CLIENT_VERSION, -1,
+ EGL.EGL_NONE
+ };
+ if (glProfile.usesNativeGLES2()) {
+ contextAttrs[1] = 2;
+ } else if (glProfile.usesNativeGLES1()) {
+ contextAttrs[1] = 1;
+ } else {
+ throw new GLException("Error creating OpenGL context - invalid GLProfile: "+glProfile);
+ }
+ contextAttrsNIO = Buffers.newDirectIntBuffer(contextAttrs);
}
- contextHandle = EGL.eglCreateContext(eglDisplay, eglConfig, shareWithHandle, contextAttrs, 0);
+ contextHandle = EGL.eglCreateContext(eglDisplay, eglConfig, shareWithHandle, contextAttrsNIO);
if (contextHandle == 0) {
throw new GLException("Error creating OpenGL context: eglDisplay "+toHexString(eglDisplay)+
", eglConfig "+config+", "+glProfile+", shareWith "+toHexString(shareWithHandle)+", error "+toHexString(EGL.eglGetError()));
@@ -277,6 +283,13 @@ public abstract class EGLContext extends GLContextImpl {
public abstract void releasePbufferFromTexture();
+ protected static String toHexString(int hex) {
+ return GLContext.toHexString(hex);
+ }
+ protected static String toHexString(long hex) {
+ return GLContext.toHexString(hex);
+ }
+
//----------------------------------------------------------------------
// Currently unimplemented stuff
//
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
index 207a8e674..e09400c09 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLDisplayUtil.java
@@ -30,6 +30,9 @@ package jogamp.opengl.egl;
import java.nio.IntBuffer;
+import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindowFactory;
+
import jogamp.opengl.Debug;
import com.jogamp.common.util.LongIntHashMap;
@@ -55,7 +58,30 @@ public class EGLDisplayUtil {
}
public static long eglGetDisplay(long nativeDisplay_id) {
- return EGL.eglGetDisplay(nativeDisplay_id);
+ final long eglDisplay = EGL.eglGetDisplay(nativeDisplay_id);
+ if(DEBUG) {
+ System.err.println("EGLDisplayUtil.eglGetDisplay(): eglDisplay("+EGLContext.toHexString(nativeDisplay_id)+"): "+
+ EGLContext.toHexString(eglDisplay)+
+ ", "+((EGL.EGL_NO_DISPLAY != eglDisplay)?"OK":"Failed"));
+ }
+ return eglDisplay;
+ }
+
+ public static long eglGetDisplay(NativeSurface surface, boolean allowFallBackToDefault) {
+ final long nDisplay;
+ if( NativeWindowFactory.TYPE_WINDOWS.equals(NativeWindowFactory.getNativeWindowType(false)) ) {
+ nDisplay = surface.getSurfaceHandle(); // don't even ask ..
+ } else {
+ nDisplay = surface.getDisplayHandle(); // 0 == EGL.EGL_DEFAULT_DISPLAY
+ }
+ long eglDisplay = EGLDisplayUtil.eglGetDisplay(nDisplay);
+ if (eglDisplay == EGL.EGL_NO_DISPLAY && nDisplay != EGL.EGL_DEFAULT_DISPLAY && allowFallBackToDefault) {
+ if(DEBUG) {
+ System.err.println("EGLDisplayUtil.eglGetDisplay(): Fall back to EGL_DEFAULT_DISPLAY");
+ }
+ eglDisplay = EGLDisplayUtil.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
+ }
+ return eglDisplay;
}
public static synchronized boolean eglInitialize(long eglDisplay, int[] major, int major_offset, int[] minor, int minor_offset) {
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java
index 5c73b822c..32055c5e0 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawable.java
@@ -36,6 +36,8 @@
package jogamp.opengl.egl;
+import jogamp.nativewindow.NativeVisualID;
+import jogamp.nativewindow.NativeVisualID.NVIDType;
import jogamp.opengl.GLDynamicLookupHelper;
import jogamp.opengl.GLDrawableImpl;
@@ -113,6 +115,13 @@ public abstract class EGLDrawable extends GLDrawableImpl {
}
}
+ @Override
+ protected final void updateHandle() {
+ if(ownEGLSurface) {
+ recreateSurface();
+ }
+ }
+
protected void setRealizedImpl() {
if (realized) {
AbstractGraphicsConfiguration aConfig = surface.getGraphicsConfiguration();
@@ -141,9 +150,8 @@ public abstract class EGLDrawable extends GLDrawableImpl {
System.err.println(getThreadName() + ": setSurface re-using component's EGLSurface: handle "+toHexString(eglSurface));
}
} else {
- // EGLSurface is ours ..
+ // EGLSurface is ours - subsequent updateHandle() will issue recreateSurface();
ownEGLSurface=true;
- recreateSurface();
}
} else {
throw new GLException("EGLGraphicsDevice hold by non EGLGraphicsConfiguration: "+aConfig);
@@ -157,43 +165,44 @@ public abstract class EGLDrawable extends GLDrawableImpl {
// EGLSurface is ours ..
ownEGLSurface=true;
- long nDisplay=0;
- if( NativeWindowFactory.TYPE_WINDOWS.equals(NativeWindowFactory.getNativeWindowType(false)) ) {
- nDisplay = surface.getSurfaceHandle(); // don't even ask ..
- } else {
- nDisplay = aDevice.getHandle(); // 0 == EGL.EGL_DEFAULT_DISPLAY
- }
- eglDisplay = EGLDisplayUtil.eglGetDisplay(nDisplay);
+ eglDisplay = EGLDisplayUtil.eglGetDisplay(surface, true);
if (eglDisplay == EGL.EGL_NO_DISPLAY) {
- if(DEBUG) {
- System.err.println(getThreadName() + ": eglDisplay("+toHexString(nDisplay)+" <surfaceHandle>): failed, using EGL_DEFAULT_DISPLAY");
- }
- nDisplay = EGL.EGL_DEFAULT_DISPLAY;
- eglDisplay = EGLDisplayUtil.eglGetDisplay(nDisplay);
- }
- if (eglDisplay == EGL.EGL_NO_DISPLAY) {
- throw new GLException("Failed to created EGL display: nhandle "+toHexString(nDisplay)+", "+aDevice+", error "+toHexString(EGL.eglGetError()));
- } else if(DEBUG) {
- System.err.println(getThreadName() + ": eglDisplay("+toHexString(nDisplay)+"): "+toHexString(eglDisplay));
+ throw new GLException("Failed to created EGL display: "+surface+", "+aDevice+", error "+toHexString(EGL.eglGetError()));
}
if (!EGLDisplayUtil.eglInitialize(eglDisplay, null, null)) {
throw new GLException("eglInitialize failed"+", error "+Integer.toHexString(EGL.eglGetError()));
}
EGLGraphicsDevice e = new EGLGraphicsDevice(eglDisplay, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
- DefaultGraphicsScreen s = new DefaultGraphicsScreen(e, aConfig.getScreen().getIndex());
- // use the original requested Capabilities, ignore previously chosen ones (x11,win32,..) - they are not fit
+ AbstractGraphicsScreen s = new DefaultGraphicsScreen(e, aConfig.getScreen().getIndex());
final GLCapabilitiesImmutable capsRequested = (GLCapabilitiesImmutable) aConfig.getRequestedCapabilities();
- eglConfig = (EGLGraphicsConfiguration) GraphicsConfigurationFactory.getFactory(e).chooseGraphicsConfiguration(
- capsRequested, capsRequested, null, s);
- if (null == eglConfig) {
- throw new GLException("Couldn't create EGLGraphicsConfiguration from "+s);
- } else if(DEBUG) {
- System.err.println(getThreadName() + ": Chosen eglConfig: "+eglConfig);
+ if(aConfig instanceof EGLGraphicsConfiguration) {
+ eglConfig = new EGLGraphicsConfiguration(s, (EGLGLCapabilities)aConfig.getChosenCapabilities(), capsRequested, null);
+ if(DEBUG) {
+ System.err.println(getThreadName() + ": Reusing chosenCaps: "+eglConfig);
+ }
+ } else {
+ final int nativeVisualID;
+ {
+ final GLCapabilitiesImmutable capsChosen = (GLCapabilitiesImmutable) aConfig.getChosenCapabilities();
+ if(capsChosen instanceof NativeVisualID) {
+ nativeVisualID = ((NativeVisualID)capsChosen).getVisualID(NVIDType.NATIVE_ID);
+ } else {
+ nativeVisualID = -1;
+ }
+ }
+ eglConfig = EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
+ capsRequested, capsRequested, null, s, nativeVisualID);
+
+ if (null == eglConfig) {
+ throw new GLException("Couldn't create EGLGraphicsConfiguration from "+s);
+ } else if(DEBUG) {
+ System.err.println(getThreadName() + ": Chosen eglConfig: "+eglConfig);
+ }
}
- recreateSurface();
+ // subsequent updateHandle() will issue recreateSurface();
}
if(DEBUG) {
- System.err.println(getThreadName() + ": EGLDrawable.setRealized(true): END: ownDisplay "+ownEGLDisplay+", ownSurface "+ownEGLSurface+" - "+this);
+ System.err.println(getThreadName() + ": EGLDrawable.setRealized(true): END: ownDisplay "+ownEGLDisplay+", ownSurface "+ownEGLSurface);
}
} else if (ownEGLSurface && eglSurface != EGL.EGL_NO_SURFACE) {
if(DEBUG) {
@@ -205,9 +214,6 @@ public abstract class EGLDrawable extends GLDrawableImpl {
}
eglSurface = EGL.EGL_NO_SURFACE;
if (ownEGLDisplay && EGL.EGL_NO_DISPLAY!=eglDisplay) {
- if(DEBUG) {
- System.err.println(getThreadName() + ": EGLDrawable.setRealized(false): eglTerminate: "+toHexString(eglDisplay));
- }
EGLDisplayUtil.eglTerminate(eglDisplay);
}
eglDisplay=EGL.EGL_NO_DISPLAY;
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java b/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java
index bd5eb1b99..cc7d267b0 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLGLCapabilities.java
@@ -33,7 +33,9 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
-public class EGLGLCapabilities extends GLCapabilities {
+import jogamp.nativewindow.NativeVisualID;
+
+public class EGLGLCapabilities extends GLCapabilities implements NativeVisualID {
final long eglcfg;
final int eglcfgid;
final int renderableType;
@@ -74,6 +76,7 @@ public class EGLGLCapabilities extends GLCapabilities {
" with EGL-RenderableType["+renderableTypeToString(null, renderableType)+"]");
}
this.renderableType = renderableType;
+ this.nativeVisualID = -1;
}
public Object cloneMutable() {
@@ -94,6 +97,21 @@ public class EGLGLCapabilities extends GLCapabilities {
final public void setNativeVisualID(int vid) { nativeVisualID=vid; }
final public int getNativeVisualID() { return nativeVisualID; }
+ final public int getVisualID(NVIDType type) {
+ switch(type) {
+ case GEN_ID:
+ // fall through intended
+ case EGL_ConfigID:
+ return getEGLConfigID();
+ case NATIVE_ID:
+ // fall through intended
+ case EGL_NativeVisualID:
+ return getNativeVisualID();
+ default:
+ throw new IllegalArgumentException("Invalid type <"+type+">");
+ }
+ }
+
public static boolean isCompatible(GLProfile glp, int renderableType) {
if(null == glp) {
return true;
@@ -147,8 +165,8 @@ public class EGLGLCapabilities extends GLCapabilities {
if(null == sink) {
sink = new StringBuffer();
}
- sink.append("0x").append(Long.toHexString(eglcfgid)).append(": ");
- sink.append("vid 0x").append(Integer.toHexString(nativeVisualID)).append(", ");
+ sink.append("egl cfg 0x").append(Integer.toHexString(eglcfgid));
+ sink.append(", vid 0x").append(Integer.toHexString(nativeVisualID)).append(": ");
super.toString(sink);
sink.append(", [");
renderableTypeToString(sink, renderableType);
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java
index 2f486140f..99e8d1338 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfiguration.java
@@ -50,15 +50,13 @@ import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
import jogamp.nativewindow.MutableGraphicsConfiguration;
-import jogamp.opengl.Debug;
import jogamp.opengl.GLGraphicsConfigurationUtil;
import com.jogamp.common.nio.Buffers;
import com.jogamp.common.nio.PointerBuffer;
public class EGLGraphicsConfiguration extends MutableGraphicsConfiguration implements Cloneable {
- protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration");
-
+
public final long getNativeConfig() {
return ((EGLGLCapabilities)capabilitiesChosen).getEGLConfig();
}
@@ -275,11 +273,15 @@ public class EGLGraphicsConfiguration extends MutableGraphicsConfiguration imple
attrs[idx++] = EGL.EGL_BLUE_SIZE;
attrs[idx++] = caps.getBlueBits();
- attrs[idx++] = EGL.EGL_ALPHA_SIZE;
- attrs[idx++] = caps.getAlphaBits() > 0 ? caps.getAlphaBits() : EGL.EGL_DONT_CARE;
-
- attrs[idx++] = EGL.EGL_STENCIL_SIZE;
- attrs[idx++] = caps.getStencilBits() > 0 ? caps.getStencilBits() : EGL.EGL_DONT_CARE;
+ if(caps.getAlphaBits()>0) {
+ attrs[idx++] = EGL.EGL_ALPHA_SIZE;
+ attrs[idx++] = caps.getAlphaBits();
+ }
+
+ if(caps.getStencilBits()>0) {
+ attrs[idx++] = EGL.EGL_STENCIL_SIZE;
+ attrs[idx++] = caps.getStencilBits();
+ }
attrs[idx++] = EGL.EGL_DEPTH_SIZE;
attrs[idx++] = caps.getDepthBits();
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java
index ceeebe60b..831dceac2 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLGraphicsConfigurationFactory.java
@@ -40,6 +40,7 @@ import javax.media.nativewindow.CapabilitiesChooser;
import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.nativewindow.DefaultGraphicsScreen;
import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.NativeWindowFactory;
import javax.media.nativewindow.egl.EGLGraphicsDevice;
import javax.media.opengl.GLCapabilities;
@@ -52,8 +53,11 @@ import javax.media.opengl.GLDrawableFactory;
import com.jogamp.common.nio.Buffers;
import com.jogamp.common.nio.PointerBuffer;
+import jogamp.nativewindow.NativeVisualID;
+import jogamp.nativewindow.NativeVisualID.NVIDType;
import jogamp.opengl.GLGraphicsConfigurationFactory;
import jogamp.opengl.GLGraphicsConfigurationUtil;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -68,11 +72,24 @@ import java.nio.IntBuffer;
public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory {
static EGLGLCapabilities.EglCfgIDComparator EglCfgIDComparator = new EGLGLCapabilities.EglCfgIDComparator();
-
+ static GraphicsConfigurationFactory nativeGraphicsConfigurationFactory = null;
+
static void registerFactory() {
+ GraphicsConfigurationFactory eglFactory = new EGLGraphicsConfigurationFactory();
+
+ // become the pre-selector for X11/.. to match the native visual id w/ EGL, if native ES is selected
+ final String nwType = NativeWindowFactory.getNativeWindowType(false);
+ if(NativeWindowFactory.TYPE_X11 == nwType) {
+ nativeGraphicsConfigurationFactory = GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, eglFactory);
+ } /* else if(NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false)) {
+ nativeGraphicsConfigurationFactory = GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.windows.WindowsGraphicsDevice.class, eglFactory);
+ } else if(NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false)) {
+ } */
+
// become the selector for KD/EGL ..
- GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.egl.EGLGraphicsDevice.class, new EGLGraphicsConfigurationFactory());
+ GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.egl.EGLGraphicsDevice.class, eglFactory);
}
+
private EGLGraphicsConfigurationFactory() {
}
@@ -86,6 +103,7 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact
if (! (capsChosen instanceof GLCapabilitiesImmutable) ) {
throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - chosen");
}
+ final GLCapabilitiesImmutable glCapsChosen = (GLCapabilitiesImmutable) capsChosen;
if (! (capsRequested instanceof GLCapabilitiesImmutable) ) {
throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects - requested");
@@ -96,10 +114,48 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact
throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilitiesChooser objects");
}
- return chooseGraphicsConfigurationStatic((GLCapabilitiesImmutable) capsChosen,
- (GLCapabilitiesImmutable) capsRequested,
- (GLCapabilitiesChooser) chooser,
- absScreen, -1);
+ AbstractGraphicsDevice absDevice = absScreen.getDevice();
+ if(null==absDevice) {
+ throw new GLException("Null AbstractGraphicsDevice");
+ }
+
+ AbstractGraphicsConfiguration cfg = null;
+
+ if( absDevice instanceof EGLGraphicsDevice ) {
+ cfg = chooseGraphicsConfigurationStatic((GLCapabilitiesImmutable) capsChosen,
+ (GLCapabilitiesImmutable) capsRequested,
+ (GLCapabilitiesChooser) chooser,
+ absScreen, -1);
+ } else {
+ // handle non native cases (X11, ..)
+ if(null == nativeGraphicsConfigurationFactory) {
+ throw new InternalError("Native GraphicsConfigurationFactory is null, but call issued for device: "+absDevice+" of type "+absDevice.getClass().getSimpleName());
+ }
+
+ if(glCapsChosen.getGLProfile().usesNativeGLES()) {
+ if(DEBUG) {
+ System.err.println("EGLGraphicsConfigurationFactory.choose..: Handle native device "+absDevice.getClass().getSimpleName());
+ }
+ cfg = chooseGraphicsConfigurationStatic((GLCapabilitiesImmutable) capsChosen,
+ (GLCapabilitiesImmutable) capsRequested,
+ (GLCapabilitiesChooser) chooser,
+ absScreen, -1);
+ if(null == cfg || 0>=((NativeVisualID)cfg.getChosenCapabilities()).getVisualID(NVIDType.NATIVE_ID)) {
+ cfg = null;
+ if(DEBUG) {
+ System.err.println("EGLGraphicsConfigurationFactory.choose..: No native visual ID, fallback ..");
+ }
+ }
+ }
+ if(null == cfg) {
+ // fwd to native config factory (only X11 for now)
+ if(DEBUG) {
+ System.err.println("EGLGraphicsConfigurationFactory.choose..: Delegate to "+nativeGraphicsConfigurationFactory.getClass().getSimpleName());
+ }
+ cfg = nativeGraphicsConfigurationFactory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, absScreen);
+ }
+ }
+ return cfg;
}
protected static List<GLCapabilitiesImmutable> getAvailableCapabilities(EGLDrawableFactory factory, AbstractGraphicsDevice device) {
@@ -147,79 +203,91 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact
throw new GLException("Null AbstractGraphicsScreen");
}
AbstractGraphicsDevice absDevice = absScreen.getDevice();
-
- if(null==absDevice || !(absDevice instanceof EGLGraphicsDevice)) {
- throw new GLException("GraphicsDevice must be a valid EGLGraphicsDevice");
+ if(null==absDevice) {
+ throw new GLException("Null AbstractGraphicsDevice");
}
- long eglDisplay = absDevice.getHandle();
-
- if (eglDisplay == EGL.EGL_NO_DISPLAY) {
- throw new GLException("Invalid EGL display: "+absDevice);
+
+ final long eglDisplay;
+ final boolean ownEGLDisplay;
+ if( !(absDevice instanceof EGLGraphicsDevice) ) {
+ eglDisplay = EGLDisplayUtil.eglGetDisplay(absDevice.getHandle());
+ if (eglDisplay == EGL.EGL_NO_DISPLAY) {
+ throw new GLException("Could not get EGL display from: "+absDevice);
+ }
+ if (!EGLDisplayUtil.eglInitialize(eglDisplay, null, null)) {
+ throw new GLException("eglInitialize failed eglDisplay 0x"+Long.toHexString(eglDisplay)+", "+absDevice+", error 0x"+Integer.toHexString(EGL.eglGetError()));
+ }
+ ownEGLDisplay = true;
+ } else {
+ eglDisplay = absDevice.getHandle();
+ if (eglDisplay == EGL.EGL_NO_DISPLAY) {
+ throw new GLException("Invalid EGL display: "+absDevice);
+ }
+ ownEGLDisplay = false;
}
EGLDrawableFactory factory = (EGLDrawableFactory) GLDrawableFactory.getEGLFactory();
capsChosen = GLGraphicsConfigurationUtil.fixGLCapabilities( capsChosen, factory.canCreateGLPbuffer(absDevice) );
GLProfile glp = capsChosen.getGLProfile();
+ GLCapabilities fixedCaps;
EGLGraphicsConfiguration res = eglChooseConfig(eglDisplay, capsChosen, capsReq, chooser, absScreen, nativeVisualID);
- if(null!=res) {
- return res;
- }
- if(DEBUG) {
- System.err.println("eglChooseConfig failed with given capabilities "+capsChosen);
- }
-
- // Last try .. add a fixed embedded profile [ATI, Nokia, Intel, ..]
- //
- // rgb888 - d16, s4
- GLCapabilities fixedCaps = new GLCapabilities(glp);
- fixedCaps.setRedBits(8);
- fixedCaps.setGreenBits(8);
- fixedCaps.setBlueBits(8);
- fixedCaps.setDepthBits(16);
- fixedCaps.setSampleBuffers(true);
- fixedCaps.setNumSamples(4);
- if(DEBUG) {
- System.err.println("trying fixed caps (1): "+fixedCaps);
- }
- res = eglChooseConfig(eglDisplay, fixedCaps, capsReq, chooser, absScreen, nativeVisualID);
- if(null!=res) {
- return res;
+ if(null==res) {
+ if(DEBUG) {
+ System.err.println("eglChooseConfig failed with given capabilities "+capsChosen);
+ }
+
+ // Last try .. add a fixed embedded profile [ATI, Nokia, Intel, ..]
+ //
+ // rgb888 - d16, s4
+ fixedCaps = new GLCapabilities(glp);
+ fixedCaps.setRedBits(8);
+ fixedCaps.setGreenBits(8);
+ fixedCaps.setBlueBits(8);
+ fixedCaps.setDepthBits(16);
+ fixedCaps.setSampleBuffers(true);
+ fixedCaps.setNumSamples(4);
+ if(DEBUG) {
+ System.err.println("trying fixed caps (1): "+fixedCaps);
+ }
+ res = eglChooseConfig(eglDisplay, fixedCaps, capsReq, chooser, absScreen, nativeVisualID);
+ }
+ if(null==res) {
+ //
+ // rgb565 - d16, s0
+ fixedCaps = new GLCapabilities(glp);
+ fixedCaps.setRedBits(5);
+ fixedCaps.setGreenBits(6);
+ fixedCaps.setBlueBits(5);
+ fixedCaps.setDepthBits(16);
+ if(DEBUG) {
+ System.err.println("trying fixed caps (2): "+fixedCaps);
+ }
+ res = eglChooseConfig(eglDisplay, fixedCaps, capsReq, chooser, absScreen, nativeVisualID);
+ }
+ if(null==res) {
+ //
+ // rgb565 - d16, s4
+ fixedCaps = new GLCapabilities(glp);
+ fixedCaps.setRedBits(5);
+ fixedCaps.setGreenBits(6);
+ fixedCaps.setBlueBits(5);
+ fixedCaps.setDepthBits(16);
+ fixedCaps.setSampleBuffers(true);
+ fixedCaps.setNumSamples(4);
+ if(DEBUG) {
+ System.err.println("trying fixed caps (3): "+fixedCaps);
+ }
+ res = eglChooseConfig(eglDisplay, fixedCaps, capsReq, chooser, absScreen, nativeVisualID);
}
-
- //
- // rgb565 - d16, s0
- fixedCaps = new GLCapabilities(glp);
- fixedCaps.setRedBits(5);
- fixedCaps.setGreenBits(6);
- fixedCaps.setBlueBits(5);
- fixedCaps.setDepthBits(16);
- if(DEBUG) {
- System.err.println("trying fixed caps (2): "+fixedCaps);
- }
- res = eglChooseConfig(eglDisplay, fixedCaps, capsReq, chooser, absScreen, nativeVisualID);
- if(null!=res) {
- return res;
- }
-
- //
- // rgb565 - d16, s4
- fixedCaps = new GLCapabilities(glp);
- fixedCaps.setRedBits(5);
- fixedCaps.setGreenBits(6);
- fixedCaps.setBlueBits(5);
- fixedCaps.setDepthBits(16);
- fixedCaps.setSampleBuffers(true);
- fixedCaps.setNumSamples(4);
- if(DEBUG) {
- System.err.println("trying fixed caps (3): "+fixedCaps);
+ if(null==res) {
+ throw new GLException("Graphics configuration failed [direct caps, eglGetConfig/chooser and fixed-caps(1-3)]");
}
- res = eglChooseConfig(eglDisplay, fixedCaps, capsReq, chooser, absScreen, nativeVisualID);
- if(null!=res) {
- return res;
+ if(ownEGLDisplay) {
+ EGLDisplayUtil.eglTerminate(eglDisplay);
}
- throw new GLException("Graphics configuration failed [direct caps, eglGetConfig/chooser and fixed-caps(1-3)]");
+ return res;
}
static EGLGraphicsConfiguration eglChooseConfig(long eglDisplay,
@@ -244,7 +312,7 @@ public class EGLGraphicsConfigurationFactory extends GLGraphicsConfigurationFact
}
if (DEBUG) {
System.err.println("EGLGraphicsConfiguration.eglChooseConfig: eglChooseConfig maxConfigs: "+numConfigs.get(0));
- System.err.println("EGLGraphicsConfiguration.eglChooseConfig: eglDisplay "+toHexString(eglDisplay)+", "+capsChosen);
+ System.err.println("EGLGraphicsConfiguration.eglChooseConfig: eglDisplay "+toHexString(eglDisplay)+", "+capsChosen+", nativeVisualID "+toHexString(nativeVisualID));
}
final IntBuffer attrs = Buffers.newDirectIntBuffer(EGLGraphicsConfiguration.GLCapabilities2AttribList(capsChosen));