aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java10
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java12
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java3
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java49
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java21
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java11
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java22
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java81
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLCanvas.java101
9 files changed, 182 insertions, 128 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java
index 690e0466b..702d66fce 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXAWTCGLGraphicsConfigurationFactory.java
@@ -100,11 +100,6 @@ public class MacOSXAWTCGLGraphicsConfigurationFactory extends GraphicsConfigurat
}
GraphicsConfiguration gc = device.getDefaultConfiguration();
- capsChosen = (GLCapabilitiesImmutable) AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsChosen, gc);
- if(DEBUG) {
- System.err.println("AWT Colormodel compatible: "+capsChosen);
- }
-
MacOSXCGLGraphicsConfiguration macConfig = (MacOSXCGLGraphicsConfiguration)
GraphicsConfigurationFactory.getFactory(macDevice).chooseGraphicsConfiguration(capsChosen,
capsRequested,
@@ -114,7 +109,8 @@ public class MacOSXAWTCGLGraphicsConfigurationFactory extends GraphicsConfigurat
throw new GLException("Unable to choose a GraphicsConfiguration: "+capsChosen+",\n\t"+chooser+"\n\t"+macScreen);
}
- // FIXME: we have nothing to match .. so choose the default
- return new AWTGraphicsConfiguration(awtScreen, macConfig.getChosenCapabilities(), macConfig.getRequestedCapabilities(), gc, macConfig);
+ // We have nothing to match .. so choose the default
+ return new AWTGraphicsConfiguration(awtScreen, macConfig.getChosenCapabilities(), macConfig.getRequestedCapabilities(),
+ gc, macConfig);
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java
index 751ae5380..842096e55 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java
@@ -51,6 +51,7 @@ import javax.media.opengl.GLProfile;
import com.jogamp.nativewindow.impl.windows.GDI;
import com.jogamp.nativewindow.impl.windows.PIXELFORMATDESCRIPTOR;
+import com.jogamp.opengl.impl.GLContextImpl;
import javax.media.opengl.GLCapabilitiesImmutable;
public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
@@ -62,14 +63,14 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
public WindowsPbufferWGLDrawable(GLDrawableFactory factory, NativeSurface target,
WindowsWGLDrawable dummyDrawable,
- WGLExt wglExt) {
+ WindowsWGLContext sharedCtx) {
super(factory, target, true);
if (DEBUG) {
System.out.println("Pbuffer config: " + getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration());
}
- createPbuffer(dummyDrawable.getNativeSurface().getSurfaceHandle(), wglExt);
+ createPbuffer(dummyDrawable.getNativeSurface().getSurfaceHandle(), sharedCtx);
if (DEBUG) {
System.err.println("Created pbuffer " + this);
@@ -126,12 +127,13 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
}
}
- private void createPbuffer(long parentHdc, WGLExt wglExt) {
+ private void createPbuffer(long parentHdc, WindowsWGLContext sharedCtx) {
int[] iattributes = new int [2*WindowsWGLGraphicsConfiguration.MAX_ATTRIBS];
float[] fattributes = new float[1];
int[] floatModeTmp = new int[1];
int niattribs = 0;
int width, height;
+ WGLExt wglExt = sharedCtx.getWGLExt();
WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration) getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable)config.getRequestedCapabilities();
@@ -144,7 +146,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
if(!WindowsWGLGraphicsConfiguration.GLCapabilities2AttribList(capabilities,
iattributes,
- wglExt,
+ sharedCtx,
true,
floatModeTmp)){
throw new GLException("Pbuffer-related extensions not supported");
@@ -176,7 +178,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
throw new GLException("pbuffer creation error: Couldn't find a suitable pixel format");
}
- boolean haveMultisample = wglExt.isExtensionAvailable("WGL_ARB_multisample");
+ boolean haveMultisample = sharedCtx.isExtensionAvailable("WGL_ARB_multisample");
if (DEBUG) {
System.err.println("" + nformats + " suitable pixel formats found");
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java
index 51c5875cc..2e29e9c83 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java
@@ -257,10 +257,9 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
synchronized(sr.context) {
sr.context.makeCurrent();
try {
- WGLExt wglExt = sr.context.getWGLExt();
GLDrawableImpl pbufferDrawable = new WindowsPbufferWGLDrawable(WindowsWGLDrawableFactory.this, target,
sr.drawable,
- wglExt);
+ sr.context);
returnList.add(pbufferDrawable);
} finally {
sr.context.release();
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java
index f714c7719..c01072a6f 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java
@@ -107,7 +107,7 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
}
/** Update config - after having a valid and current context */
- protected void updateCapabilitiesByWGL(GLContextImpl context) {
+ protected void updateCapabilitiesByWGL(WindowsWGLContext context) {
if(choosenByWGLPixelFormat) return; // already done ..
GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable) getRequestedCapabilities();
@@ -115,12 +115,11 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
boolean usePBuffer = capabilities.isPBuffer();
GLProfile glp = capabilities.getGLProfile();
- WGLExt wglExt = (WGLExt) context.getPlatformGLExtensions();
GLDrawable drawable = context.getGLDrawable();
NativeSurface ns = drawable.getNativeSurface();
long hdc = ns.getSurfaceHandle();
- GLCapabilitiesImmutable[] caps = HDC2GLCapabilities(wglExt, hdc, getPixelFormatID(), glp, true, onscreen, usePBuffer);
+ GLCapabilitiesImmutable[] caps = HDC2GLCapabilities(context, hdc, getPixelFormatID(), glp, true, onscreen, usePBuffer);
if(null!=caps && null!=caps[0]) {
setCapsPFD(caps[0], getPixelFormat(), getPixelFormatID(), true);
}
@@ -145,19 +144,17 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
public int getPixelFormatID() { return pixelfmtID; }
public boolean isChoosenByWGL() { return choosenByWGLPixelFormat; }
- private static int haveWGLChoosePixelFormatARB = -1;
- private static int haveWGLARBMultisample = -1;
-
- public static GLCapabilitiesImmutable[] HDC2GLCapabilities(WGLExt wglExt, long hdc, int pfdIDOnly,
+ public static GLCapabilitiesImmutable[] HDC2GLCapabilities(WindowsWGLContext sharedCtx, long hdc, int pfdIDOnly,
GLProfile glp, boolean relaxed, boolean onscreen, boolean usePBuffer) {
- if(haveWGLChoosePixelFormatARB<0) {
- haveWGLChoosePixelFormatARB = wglExt.isExtensionAvailable("WGL_ARB_pixel_format")?1:0;
- }
- if(haveWGLARBMultisample<0) {
- haveWGLARBMultisample = wglExt.isExtensionAvailable("WGL_ARB_multisample")?1:0;
+ boolean haveWGLChoosePixelFormatARB = sharedCtx.isExtensionAvailable("WGL_ARB_pixel_format");
+ boolean haveWGLARBMultisample = sharedCtx.isExtensionAvailable("WGL_ARB_multisample");
+ if(DEBUG) {
+ System.err.println("HDC2GLCapabilities: ARB_pixel_format: "+haveWGLChoosePixelFormatARB);
+ System.err.println("HDC2GLCapabilities: ARB_multisample : "+haveWGLARBMultisample);
}
- if (0==haveWGLChoosePixelFormatARB) {
+
+ if (!haveWGLChoosePixelFormatARB) {
return null;
}
@@ -176,6 +173,7 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
int[] iattributes = new int [2*MAX_ATTRIBS];
int[] iresults = new int [2*MAX_ATTRIBS];
+ WGLExt wglExt = sharedCtx.getWGLExt();
iattributes[0] = WGLExt.WGL_NUMBER_PIXEL_FORMATS_ARB;
if (wglExt.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, 0, iresults, 0)) {
numFormats = iresults[0];
@@ -208,7 +206,7 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB;
iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB;
iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB;
- if (1==haveWGLARBMultisample) {
+ if (haveWGLARBMultisample) {
iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB;
iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB;
}
@@ -242,10 +240,17 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
public static boolean GLCapabilities2AttribList(GLCapabilitiesImmutable caps,
int[] iattributes,
- WGLExt wglExt,
+ GLContextImpl sharedCtx,
boolean pbuffer,
int[] floatMode) throws GLException {
- if (!wglExt.isExtensionAvailable("WGL_ARB_pixel_format")) {
+ boolean haveWGLChoosePixelFormatARB = sharedCtx.isExtensionAvailable("WGL_ARB_pixel_format");
+ boolean haveWGLARBMultisample = sharedCtx.isExtensionAvailable("WGL_ARB_multisample");
+ if(DEBUG) {
+ System.err.println("HDC2GLCapabilities: ARB_pixel_format: "+haveWGLChoosePixelFormatARB);
+ System.err.println("HDC2GLCapabilities: ARB_multisample : "+haveWGLARBMultisample);
+ }
+
+ if (!haveWGLChoosePixelFormatARB) {
return false;
}
@@ -306,13 +311,11 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
iattributes[niattribs++] = caps.getAccumAlphaBits();
}
- if (wglExt.isExtensionAvailable("WGL_ARB_multisample")) {
- if (caps.getSampleBuffers()) {
+ if (caps.getSampleBuffers() && haveWGLARBMultisample) {
iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB;
iattributes[niattribs++] = GL.GL_TRUE;
iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB;
iattributes[niattribs++] = caps.getNumSamples();
- }
}
boolean rtt = caps.getPbufferRenderToTexture();
@@ -326,19 +329,19 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
}
if (rect) {
- if (!wglExt.isExtensionAvailable("GL_NV_texture_rectangle")) {
+ if (!sharedCtx.isExtensionAvailable("GL_NV_texture_rectangle")) {
throw new GLException("Render-to-texture-rectangle requires GL_NV_texture_rectangle extension");
}
}
if (useFloat) {
- if (!wglExt.isExtensionAvailable("WGL_ATI_pixel_format_float") &&
- !wglExt.isExtensionAvailable("WGL_NV_float_buffer")) {
+ if (!sharedCtx.isExtensionAvailable("WGL_ATI_pixel_format_float") &&
+ !sharedCtx.isExtensionAvailable("WGL_NV_float_buffer")) {
throw new GLException("Floating-point pbuffers not supported by this hardware");
}
// Prefer NVidia extension over ATI
- if (wglExt.isExtensionAvailable("WGL_NV_float_buffer")) {
+ if (sharedCtx.isExtensionAvailable("WGL_NV_float_buffer")) {
ati = false;
floatMode[0] = GLPbuffer.NV_FLOAT;
} else {
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
index 46b169343..4989d86a2 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
@@ -179,18 +179,21 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
if(WindowsWGLGraphicsConfiguration.GLCapabilities2AttribList(capabilities,
iattributes,
- wglExt,
+ sharedContext,
false,
null)) {
int[] pformats = new int[WindowsWGLGraphicsConfiguration.MAX_PFORMATS];
int[] numFormatsTmp = new int[1];
if (wglExt.wglChoosePixelFormatARB(hdc,
- iattributes, 0,
- fattributes, 0,
- WindowsWGLGraphicsConfiguration.MAX_PFORMATS,
- pformats, 0,
- numFormatsTmp, 0)) {
+ iattributes, 0,
+ fattributes, 0,
+ WindowsWGLGraphicsConfiguration.MAX_PFORMATS,
+ pformats, 0,
+ numFormatsTmp, 0)) {
numFormats = numFormatsTmp[0];
+ if (DEBUG) {
+ System.err.println(getThreadName() + ": NumFormats (wglChoosePixelFormatARB) " + numFormats);
+ }
if (recommendedPixelFormat<=0 && numFormats > 0) {
recommendedPixelFormat = pformats[0];
if (DEBUG) {
@@ -215,7 +218,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
}
}
- availableCaps = WindowsWGLGraphicsConfiguration.HDC2GLCapabilities(wglExt, hdc, -1, glProfile, pixelFormatSet, onscreen, usePBuffer);
+ availableCaps = WindowsWGLGraphicsConfiguration.HDC2GLCapabilities(sharedContext, hdc, -1, glProfile, pixelFormatSet, onscreen, usePBuffer);
gotAvailableCaps = null!=availableCaps ;
choosenBywGLPixelFormat = gotAvailableCaps ;
} else if (DEBUG) {
@@ -243,6 +246,10 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
throw new GLException("Unable to enumerate pixel formats of window " +
toHexString(hdc) + " for GLCapabilitiesChooser (LastError: "+GDI.GetLastError()+")");
}
+ if (DEBUG) {
+ System.err.println(getThreadName() + ": NumFormats (DescribePixelFormat) " + numFormats);
+ }
+
availableCaps = new GLCapabilitiesImmutable[numFormats];
for (int i = 0; i < numFormats; i++) {
if (GDI.DescribePixelFormat(hdc, 1 + i, pfd.size(), pfd) == 0) {
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java
index 363881ef0..da4f2113d 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/awt/WindowsAWTWGLGraphicsConfigurationFactory.java
@@ -93,11 +93,6 @@ public class WindowsAWTWGLGraphicsConfigurationFactory extends GraphicsConfigura
System.err.println("WindowsAWTWGLGraphicsConfigurationFactory: got "+absScreen);
}
GraphicsConfiguration gc = device.getDefaultConfiguration();
- capsChosen = AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsChosen, gc);
- if(DEBUG) {
- System.err.println("AWT Colormodel compatible: "+capsChosen);
- }
-
WindowsGraphicsDevice winDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
DefaultGraphicsScreen winScreen = new DefaultGraphicsScreen(winDevice, awtScreen.getIndex());
if(DEBUG) {
@@ -116,7 +111,9 @@ public class WindowsAWTWGLGraphicsConfigurationFactory extends GraphicsConfigura
if(DEBUG) {
System.err.println("WindowsAWTWGLGraphicsConfigurationFactory: chosen "+winConfig);
}
-
- return new AWTGraphicsConfiguration(awtScreen, winConfig.getChosenCapabilities(), winConfig.getRequestedCapabilities(), gc, winConfig);
+
+ // We have nothing to match .. so choose the default
+ return new AWTGraphicsConfiguration(awtScreen, winConfig.getChosenCapabilities(), winConfig.getRequestedCapabilities(),
+ gc, winConfig);
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java
index 1b20040b0..d3f9f378f 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java
@@ -176,6 +176,28 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac
return res;
}
+ protected static X11GLXGraphicsConfiguration fetchGraphicsConfigurationFBConfig(X11GraphicsScreen x11Screen, int fbID, GLProfile glp) {
+ AbstractGraphicsDevice absDevice = x11Screen.getDevice();
+ long display = absDevice.getHandle();
+ int screen = x11Screen.getIndex();
+
+ long fbcfg = X11GLXGraphicsConfiguration.glXFBConfigID2FBConfig(display, screen, fbID);
+ if( !X11GLXGraphicsConfiguration.GLXFBConfigValid( display, fbcfg ) ) {
+ if(DEBUG) {
+ System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("+x11Screen+","+toHexString(fbID)+"): fbcfg: "+toHexString(fbcfg));
+ }
+ return null;
+ }
+ XVisualInfo visualInfo = GLX.glXGetVisualFromFBConfig(display, fbcfg);
+ if (visualInfo==null) {
+ System.err.println("X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetVisualFromFBConfig ("+x11Screen+", "+toHexString(fbcfg)+")");
+ return null;
+ }
+ GLCapabilitiesImmutable caps = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(glp, display, fbcfg, true, true, true, GLXUtil.isMultisampleAvailable(display));
+ return new X11GLXGraphicsConfiguration(x11Screen, caps, caps, new DefaultGLCapabilitiesChooser(), visualInfo, fbcfg, fbID);
+
+ }
+
private static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig(GLCapabilitiesImmutable capsChosen,
GLCapabilitiesImmutable capsReq,
GLCapabilitiesChooser chooser,
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java
index 03955b439..cf5b1a650 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java
@@ -43,6 +43,8 @@ import javax.media.opengl.*;
import com.jogamp.opengl.impl.*;
import com.jogamp.nativewindow.impl.jawt.x11.*;
import com.jogamp.nativewindow.impl.x11.*;
+import com.jogamp.opengl.impl.x11.glx.X11GLXGraphicsConfigurationFactory;
+import java.awt.image.ColorModel;
public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfigurationFactory {
protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration");
@@ -83,12 +85,11 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfiguration
System.err.println("X11AWTGLXGraphicsConfigurationFactory: got "+absScreen);
}
- GraphicsConfiguration gc;
- X11GraphicsConfiguration x11Config;
-
long displayHandle = X11SunJDKReflection.graphicsDeviceGetDisplay(device);
+ boolean owner = false;
if(0==displayHandle) {
displayHandle = X11Util.createDisplay(null);
+ owner = true;
if(DEBUG) {
System.err.println("X11AWTGLXGraphicsConfigurationFactory: using a thread local X11 display");
}
@@ -96,47 +97,81 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfiguration
if(DEBUG) {
System.err.println("X11AWTGLXGraphicsConfigurationFactory: using AWT X11 display 0x"+Long.toHexString(displayHandle));
}
- String name = X11Util.XDisplayString(displayHandle);
- displayHandle = X11Util.createDisplay(name);
+ /**
+ * May cause an exception at X11 Display destruction,
+ * so reuse AWT's display for now, which seems to work nicely.
+ String name = X11Util.XDisplayString(displayHandle);
+ displayHandle = X11Util.createDisplay(name);
+ owner = true;
+ */
}
((AWTGraphicsDevice)awtScreen.getDevice()).setSubType(NativeWindowFactory.TYPE_X11, displayHandle);
X11GraphicsDevice x11Device = new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT);
- x11Device.setCloseDisplay(true);
+ x11Device.setCloseDisplay(owner);
X11GraphicsScreen x11Screen = new X11GraphicsScreen(x11Device, awtScreen.getIndex());
if(DEBUG) {
System.err.println("X11AWTGLXGraphicsConfigurationFactory: made "+x11Screen);
}
-
- gc = device.getDefaultConfiguration();
- capsChosen = AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsChosen, gc);
- if(DEBUG) {
- System.err.println("AWT Colormodel compatible: "+capsChosen);
- }
GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(x11Device);
- x11Config = (X11GraphicsConfiguration)factory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, x11Screen);
+ GraphicsConfiguration[] configs = device.getConfigurations();
+
+ //
+ // Match the X11/GL Visual with AWT:
+ // - choose a config AWT agnostic and then
+ // - try to find the visual within the GraphicsConfiguration
+ //
+ // The resulting GraphicsConfiguration has to be 'forced' on the AWT native peer,
+ // ie. returned by GLCanvas's getGraphicsConfiguration() befor call by super.addNotify().
+ //
+ X11GraphicsConfiguration x11Config = (X11GraphicsConfiguration) factory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, x11Screen);
if (x11Config == null) {
- throw new GLException("Unable to choose a GraphicsConfiguration: "+capsChosen+",\n\t"+chooser+"\n\t"+x11Screen);
+ throw new GLException("Unable to choose a GraphicsConfiguration (1): "+capsChosen+",\n\t"+chooser+"\n\t"+x11Screen);
}
-
long visualID = x11Config.getVisualID();
- // Now figure out which GraphicsConfiguration corresponds to this
- // visual by matching the visual ID
- GraphicsConfiguration[] configs = device.getConfigurations();
for (int i = 0; i < configs.length; i++) {
- GraphicsConfiguration config = configs[i];
- if (config != null) {
- if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) {
- return new AWTGraphicsConfiguration(awtScreen, x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(),
- config, x11Config);
+ GraphicsConfiguration gc = configs[i];
+ if (gc != null) {
+ if (X11SunJDKReflection.graphicsConfigurationGetVisualID(gc) == visualID) {
+ if(DEBUG) {
+ System.err.println("Found matching AWT visual: 0x"+Long.toHexString(visualID) +" -> "+x11Config);
+ }
+ return new AWTGraphicsConfiguration(awtScreen,
+ x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(),
+ gc, x11Config);
}
}
}
+
+ // try again using an AWT Colormodel compatible configuration
+ GraphicsConfiguration gc = device.getDefaultConfiguration();
+ capsChosen = AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsChosen, gc);
+ x11Config = (X11GraphicsConfiguration) factory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, x11Screen);
+ if (x11Config == null) {
+ throw new GLException("Unable to choose a GraphicsConfiguration (2): "+capsChosen+",\n\t"+chooser+"\n\t"+x11Screen);
+ }
+ visualID = x11Config.getVisualID();
+ for (int i = 0; i < configs.length; i++) {
+ gc = configs[i];
+ if (gc != null) {
+ if (X11SunJDKReflection.graphicsConfigurationGetVisualID(gc) == visualID) {
+ if(DEBUG) {
+ System.err.println("Found matching default AWT visual: 0x"+Long.toHexString(visualID) +" -> "+x11Config);
+ }
+ return new AWTGraphicsConfiguration(awtScreen,
+ x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(),
+ gc, x11Config);
+ }
+ }
+ }
+
// Either we weren't able to reflectively introspect on the
// X11GraphicsConfig or something went wrong in the steps above;
// Let's take the default configuration as used on Windows and MacOSX then ..
if(DEBUG) {
System.err.println("!!! Using default configuration");
}
+
+ gc = device.getDefaultConfiguration();
return new AWTGraphicsConfiguration(awtScreen, x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(), gc, x11Config);
}
}
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index dba041f8d..b20a4ff13 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -94,10 +94,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
private boolean sendReshape = false;
// copy of the cstr args ..
- private GLCapabilitiesImmutable capabilities;
private GLCapabilitiesChooser chooser;
private GLContext shareWith;
- private GraphicsDevice device;
/** Creates a new GLCanvas component with a default set of OpenGL
capabilities, using the default OpenGL capabilities selection
@@ -133,31 +131,54 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
GLContext shareWith,
GraphicsDevice device) {
/*
- * Workaround for Xinerama, always pass null so we can detect whether
- * super.getGraphicsConfiguration() is returning the Canvas' GC (null),
- * or an ancestor component's GC (non-null) in the overridden version
- * below.
+ * Determination of the native window is made in 'super.addNotify()',
+ * which creates the native peer using AWT's GraphicsConfiguration.
+ * GraphicsConfiguration is returned by this class overwritten
+ * 'getGraphicsConfiguration()', which returns our OpenGL compatible
+ * 'chosen' GraphicsConfiguration.
*/
super();
if(null==capsReqUser) {
- capabilities = new GLCapabilities(defaultGLProfile);
+ capsReqUser = new GLCapabilities(defaultGLProfile);
} else {
// don't allow the user to change data
- capabilities = (GLCapabilitiesImmutable) capsReqUser.cloneMutable();
+ capsReqUser = (GLCapabilitiesImmutable) capsReqUser.cloneMutable();
}
- glProfile = capabilities.getGLProfile();
+ if(null==device) {
+ GraphicsConfiguration gc = super.getGraphicsConfiguration();
+ if(null!=gc) {
+ device = gc.getDevice();
+ }
+ }
+
+ this.glProfile = capsReqUser.getGLProfile();
this.chooser = chooser;
- this.shareWith=shareWith;
- this.device = device;
+ this.shareWith = shareWith;
+
+ /*
+ * Save the 'chosen' GraphicsConfiguration for use in getGraphicsConfiguration().
+ */
+ awtConfig = chooseGraphicsConfiguration(capsReqUser, capsReqUser, chooser, device);
+ if(null==awtConfig) {
+ throw new GLException("Error: NULL AWTGraphicsConfiguration");
+ }
+ chosen = awtConfig.getGraphicsConfiguration();
+
+ if (!Beans.isDesignTime()) {
+ // no lock required, since this resource ain't available yet
+ drawable = GLDrawableFactory.getFactory(glProfile).createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig));
+ context = (GLContextImpl) drawable.createContext(shareWith);
+ context.setSynchronized(true);
+ }
}
protected interface DestroyMethod {
public void destroyMethod();
}
- protected final static Object addClosingListener(Component c, final DestroyMethod d) {
+ protected final static Object addClosingListener(Component c, final DestroyMethod d) {
WindowAdapter cl = null;
Window w = getWindow(c);
if(null!=w) {
@@ -303,6 +324,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
private Object closingListenerLock = new Object();
public void display() {
+ if(!drawable.isRealized()) {
+ return; // not yet available ..
+ }
maybeDoSingleThreadedWorkaround(displayOnEventDispatchThreadAction,
displayAction);
if(null==closingListener) {
@@ -416,49 +440,18 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
Exception ex1 = new Exception(Thread.currentThread().getName()+" - Info: addNotify - start");
ex1.printStackTrace();
}
+ // 'super.addNotify()' determines the GraphicsConfiguration,
+ // while calling this class's overriden 'getGraphicsConfiguration()' method.
+ // Then it creates the native peer.
+ // Hence we chose the proper GraphicsConfiguration beforehand (see constructor).
super.addNotify();
+
if (!Beans.isDesignTime()) {
+ // no lock required, since this resource ain't available yet
disableBackgroundErase();
-
- if(null==device) {
- GraphicsConfiguration gc = super.getGraphicsConfiguration();
- if(null!=gc) {
- device = gc.getDevice();
- }
- }
-
- /*
- * Save the chosen capabilities for use in getGraphicsConfiguration().
- */
- NativeWindowFactory.getDefaultToolkitLock().lock();
- try {
- awtConfig = chooseGraphicsConfiguration(capabilities, capabilities, chooser, device);
- if(DEBUG) {
- System.err.println(Thread.currentThread().getName()+" - Created Config: "+awtConfig);
- }
- if(null!=awtConfig) {
- // update ..
- chosen = awtConfig.getGraphicsConfiguration();
-
- }
- if(null==awtConfig) {
- throw new GLException("Error: AWTGraphicsConfiguration is null");
- }
- // awtConfig.getScreen().getDevice().lock();
- try {
- drawable = GLDrawableFactory.getFactory(glProfile).createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig));
- context = (GLContextImpl) drawable.createContext(shareWith);
- context.setSynchronized(true);
- drawable.setRealized(true);
- } finally {
- // awtConfig.getScreen().getDevice().unlock();
- }
- } finally {
- NativeWindowFactory.getDefaultToolkitLock().unlock();
- }
-
+ drawable.setRealized(true);
if(DEBUG) {
- System.err.println(Thread.currentThread().getName()+" - Created Drawable: "+drawable);
+ System.err.println(Thread.currentThread().getName()+" - Realized Drawable: "+drawable);
}
}
if(DEBUG) {
@@ -785,9 +778,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(device, AbstractGraphicsDevice.DEFAULT_UNIT);
AWTGraphicsConfiguration config = (AWTGraphicsConfiguration)
- GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capsChosen,
- capsRequested,
- chooser, aScreen);
+ GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(capsChosen,
+ capsRequested,
+ chooser, aScreen);
if (config == null) {
throw new GLException("Error: Couldn't fetch AWTGraphicsConfiguration");
}