diff options
author | Michael Bien <[email protected]> | 2010-11-18 17:10:55 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-11-18 17:10:55 +0100 |
commit | fe5e7b022f6f86b16ba15165f8cdeafccaad4b2b (patch) | |
tree | 646e254c86ad90e0c4971eb63a16532e9fad8693 /src | |
parent | 8c9f3bb33732346fab0112b4a2e177b13f4e8087 (diff) | |
parent | 96af6c9bf2d683115996214cd895f9f9ef7ceea6 (diff) |
Merge branch 'master' of github.com:sgothel/jogl
Diffstat (limited to 'src')
20 files changed, 654 insertions, 209 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 47e81d0e9..f2016a23c 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -95,10 +95,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 @@ -134,31 +132,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) { @@ -304,6 +325,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) { @@ -417,49 +441,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) { @@ -786,9 +779,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"); } diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java index f3c228a5d..09dfc856d 100644 --- a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java +++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java @@ -89,8 +89,6 @@ public class TestAWT01GLn extends UITestCase { glCanvas.addGLEventListener(new Gears()); - glCanvas.display(); // one in process display - try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -100,6 +98,9 @@ public class TestAWT01GLn extends UITestCase { t.printStackTrace(); Assume.assumeNoException(t); } + + glCanvas.display(); // one in process display + Animator animator = new Animator(glCanvas); animator.start(); diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java index 03d4f37bf..a32dc90dc 100644 --- a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java +++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java @@ -86,8 +86,8 @@ public class TestSwingAWT01GLn extends UITestCase { glCanvas[0].addGLEventListener(new Gears()); window.add(glCanvas[0]); window.setSize(512, 512); - glCanvas[0].display(); window.setVisible(true); + glCanvas[0].display(); } }; diff --git a/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleChooser01.java b/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleChooser01.java new file mode 100644 index 000000000..7dcde18c9 --- /dev/null +++ b/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleChooser01.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.test.junit.jogl.caps; + +import javax.media.opengl.DefaultGLCapabilitiesChooser; +import javax.media.opengl.GLCapabilitiesImmutable; + +class MultisampleChooser01 extends DefaultGLCapabilitiesChooser { + + public int chooseCapabilities(GLCapabilitiesImmutable desired, GLCapabilitiesImmutable[] available, int windowSystemRecommendedChoice) { + boolean anyHaveSampleBuffers = false; + for (int i = 0; i < available.length; i++) { + GLCapabilitiesImmutable caps = available[i]; + if (caps != null && caps.getSampleBuffers()) { + anyHaveSampleBuffers = true; + break; + } + } + int selection = super.chooseCapabilities(desired, available, windowSystemRecommendedChoice); + if (!anyHaveSampleBuffers) { + System.err.println("WARNING: antialiasing will be disabled because none of the available pixel formats had it to offer"); + } else { + if (!available[selection].getSampleBuffers()) { + System.err.println("WARNING: antialiasing will be disabled because the DefaultGLCapabilitiesChooser didn't supply it"); + } + } + return selection; + } +} diff --git a/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleDemo01.java b/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleDemo01.java new file mode 100644 index 000000000..e399de0bc --- /dev/null +++ b/src/junit/com/jogamp/test/junit/jogl/caps/MultisampleDemo01.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.test.junit.jogl.caps; + +import com.jogamp.opengl.impl.x11.glx.GLX; +import com.jogamp.opengl.impl.x11.glx.X11GLXGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GL; +import javax.media.opengl.GL2; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLPipelineFactory; + +class MultisampleDemo01 implements GLEventListener { + + static boolean glDebug = false; + static boolean glTrace = false; + + boolean multisample; + + public MultisampleDemo01(boolean multisample) { + this.multisample = multisample; + } + + public void init(GLAutoDrawable drawable) { + AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + System.err.println(); + System.err.println("Info: " + config); + System.err.println(); + if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(false))) { + X11GLXGraphicsConfiguration x11config = (X11GLXGraphicsConfiguration) config; + long display = drawable.getNativeSurface().getDisplayHandle(); + int[] foo = new int[1]; + GLX.glXGetFBConfigAttrib(display, x11config.getFBConfig(), GLX.GLX_SAMPLES, foo, 0); + System.out.println("GLX_SAMPLES " + foo[0]); + GLX.glXGetFBConfigAttrib(display, x11config.getFBConfig(), GLX.GLX_SAMPLE_BUFFERS, foo, 0); + System.out.println("GLX_SAMPLE_BUFFERS " + foo[0]); + } + GL _gl = drawable.getGL(); + if (glDebug) { + try { + // Debug .. + _gl = _gl.getContext().setGL(GLPipelineFactory.create("javax.media.opengl.Debug", GL2.class, _gl, null)); + if (glTrace) { + // Trace .. + _gl = _gl.getContext().setGL(GLPipelineFactory.create("javax.media.opengl.Trace", GL2.class, _gl, new Object[]{System.err})); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + GL2 gl = _gl.getGL2(); + if (multisample) { + gl.glEnable(GL.GL_MULTISAMPLE); + } + gl.glClearColor(0, 0, 0, 0); + // gl.glEnable(GL.GL_DEPTH_TEST); + // gl.glDepthFunc(GL.GL_LESS); + gl.glMatrixMode(GL2ES1.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glMatrixMode(GL2ES1.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(-1, 1, -1, 1, -1, 1); + if (multisample) { + gl.glDisable(GL.GL_MULTISAMPLE); + } + } + + public void dispose(GLAutoDrawable drawable) { + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + if (multisample) { + gl.glEnable(GL.GL_MULTISAMPLE); + } + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + int numSteps = 20; + double increment = Math.PI / numSteps; + double radius = 1; + gl.glBegin(GL.GL_LINES); + for (int i = numSteps - 1; i >= 0; i--) { + gl.glVertex3d(radius * Math.cos(i * increment), radius * Math.sin(i * increment), 0); + gl.glVertex3d(-1.0 * radius * Math.cos(i * increment), -1.0 * radius * Math.sin(i * increment), 0); + } + gl.glEnd(); + if (multisample) { + gl.glDisable(GL.GL_MULTISAMPLE); + } + } + + // Unused routines + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } +} diff --git a/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleAWT.java b/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleAWT.java new file mode 100755 index 000000000..c6e7f08fa --- /dev/null +++ b/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleAWT.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.test.junit.jogl.caps; + +import com.jogamp.test.junit.util.MiscUtils; +import java.awt.*; +import javax.media.opengl.*; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.test.junit.util.UITestCase; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; +import org.junit.Test; + + +public class TestMultisampleAWT extends UITestCase { + static long durationPerTest = 500; // ms + private GLCanvas canvas; + + public static void main(String[] args) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atoi(args[++i], 500); + } + } + System.out.println("durationPerTest: "+durationPerTest); + String tstname = TestMultisampleAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + + @Test + public void testMultiSampleAA4() throws InterruptedException { + testMultiSampleAAImpl(4); + } + + // @Test + public void testMultiSampleNone() throws InterruptedException { + testMultiSampleAAImpl(0); + } + + private void testMultiSampleAAImpl(int samples) throws InterruptedException { + GLCapabilities caps = new GLCapabilities(null); + GLCapabilitiesChooser chooser = new MultisampleChooser01(); + + if(samples>0) { + caps.setSampleBuffers(true); + caps.setNumSamples(samples); + } + // turns out we need to have alpha, + // otherwise no AA will be visible. + caps.setAlphaBits(1); + + /** + * whatever I tried here (passing and preconfig GraphicsConfiguration) + * either it just didn't picked up .. or the context couldn't be made current. + * + GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + GraphicsConfiguration gc = AWTGraphicsConfiguration.getAWTGraphicsConfiguration(caps, gd); + + AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(gd, AbstractGraphicsDevice.DEFAULT_UNIT); + AWTGraphicsConfiguration config = (AWTGraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class).chooseGraphicsConfiguration(caps, caps, + chooser, aScreen); + canvas = new GLCanvas(caps, chooser, null, gd, config.getGraphicsConfiguration(), config); */ + canvas = new GLCanvas(caps, chooser, null, null); + canvas.addGLEventListener(new MultisampleDemo01(samples>0?true:false)); + + Frame frame = new Frame("Multi Samples "+samples); + frame.setLayout(new BorderLayout()); + canvas.setSize(512, 512); + frame.add(canvas, BorderLayout.CENTER); + frame.pack(); + frame.setVisible(true); + frame.setLocation(0, 0); + canvas.requestFocus(); + + Thread.sleep(durationPerTest); + + frame.dispose(); + } +} diff --git a/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleNEWT.java b/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleNEWT.java new file mode 100755 index 000000000..c060828ec --- /dev/null +++ b/src/junit/com/jogamp/test/junit/jogl/caps/TestMultisampleNEWT.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.test.junit.jogl.caps; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.test.junit.util.MiscUtils; +import javax.media.opengl.*; +import org.junit.Test; + +public class TestMultisampleNEWT { + static long durationPerTest = 500; // ms + private GLWindow window; + + public static void main(String[] args) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atoi(args[++i], 500); + } + } + System.out.println("durationPerTest: "+durationPerTest); + String tstname = TestMultisampleNEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + + @Test + public void testMultiSampleAA4() throws InterruptedException { + testMultiSampleAAImpl(4); + } + + // @Test + public void testMultiSampleNone() throws InterruptedException { + testMultiSampleAAImpl(0); + } + + private void testMultiSampleAAImpl(int samples) throws InterruptedException { + GLCapabilities caps = new GLCapabilities(null); + GLCapabilitiesChooser chooser = new MultisampleChooser01(); + + if(samples>0) { + caps.setSampleBuffers(true); + caps.setNumSamples(4); + } + // turns out we need to have alpha, + // otherwise no AA will be visible. + caps.setAlphaBits(1); + + window = GLWindow.create(caps); + window.setCapabilitiesChooser(chooser); + window.addGLEventListener(new MultisampleDemo01(samples>0?true:false)); + window.setSize(512, 512); + window.setVisible(true); + window.setPosition(0, 0); + window.requestFocus(); + + GLCapabilitiesImmutable capsChosen0 = window.getChosenGLCapabilities(); + + Thread.sleep(durationPerTest); + + window.destroy(); + } + +} diff --git a/src/junit/com/jogamp/test/junit/util/MiscUtils.java b/src/junit/com/jogamp/test/junit/util/MiscUtils.java index 672bb7de0..bb2abcd87 100644 --- a/src/junit/com/jogamp/test/junit/util/MiscUtils.java +++ b/src/junit/com/jogamp/test/junit/util/MiscUtils.java @@ -32,8 +32,7 @@ package com.jogamp.test.junit.util; import java.lang.reflect.*; public class MiscUtils { - @Deprecated - public static int str2int(String str, int def) { + public static int atoi(String str, int def) { try { return Integer.parseInt(str); } catch (Exception ex) { diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java index f511c7082..fc5607707 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -39,16 +40,20 @@ package com.jogamp.nativewindow.impl.jawt.macosx; -import com.jogamp.nativewindow.impl.*; -import com.jogamp.nativewindow.impl.jawt.*; +import java.security.AccessController; +import java.security.PrivilegedAction; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; - -import javax.media.nativewindow.*; -import java.security.*; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; import javax.media.nativewindow.util.Point; +import com.jogamp.nativewindow.impl.jawt.JAWT; +import com.jogamp.nativewindow.impl.jawt.JAWTFactory; +import com.jogamp.nativewindow.impl.jawt.JAWTWindow; +import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurface; +import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurfaceInfo; + public class MacOSXJAWTWindow extends JAWTWindow { public MacOSXJAWTWindow(Object comp, AbstractGraphicsConfiguration config) { @@ -63,13 +68,13 @@ public class MacOSXJAWTWindow extends JAWTWindow { ds = JAWT.getJAWT().GetDrawingSurface(component); if (ds == null) { // Widget not yet realized - unlockSurface(); + unlockSurfaceImpl(); return NativeWindow.LOCK_SURFACE_NOT_READY; } int res = ds.Lock(); dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ; if (!dsLocked) { - unlockSurface(); + unlockSurfaceImpl(); throw new NativeWindowException("Unable to lock surface"); } // See whether the surface changed and if so destroy the old @@ -91,19 +96,19 @@ public class MacOSXJAWTWindow extends JAWTWindow { dsi = ds.GetDrawingSurfaceInfo(); } if (dsi == null) { - unlockSurface(); + unlockSurfaceImpl(); return NativeWindow.LOCK_SURFACE_NOT_READY; } firstLock = false; macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo(); if (macosxdsi == null) { - unlockSurface(); + unlockSurfaceImpl(); return NativeWindow.LOCK_SURFACE_NOT_READY; } drawable = macosxdsi.getCocoaViewRef(); if (drawable == 0) { - unlockSurface(); + unlockSurfaceImpl(); return NativeWindow.LOCK_SURFACE_NOT_READY; } else { updateBounds(dsi.getBounds()); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java index 14d6eebcd..d7cd55f9a 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java @@ -40,6 +40,11 @@ package com.jogamp.nativewindow.impl.jawt.windows; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Point; + import com.jogamp.nativewindow.impl.jawt.JAWT; import com.jogamp.nativewindow.impl.jawt.JAWTFactory; import com.jogamp.nativewindow.impl.jawt.JAWTWindow; @@ -47,16 +52,8 @@ import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurface; import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurfaceInfo; import com.jogamp.nativewindow.impl.windows.GDI; -import javax.media.nativewindow.AbstractGraphicsConfiguration; -import javax.media.nativewindow.NativeWindow; -import javax.media.nativewindow.NativeWindowException; -import javax.media.nativewindow.util.Point; - public class WindowsJAWTWindow extends JAWTWindow { - public static final boolean PROFILING = false; // FIXME - public static final int PROFILING_TICKS = 600; // FIXME - public WindowsJAWTWindow(Object comp, AbstractGraphicsConfiguration config) { super(comp, config); } @@ -71,20 +68,16 @@ public class WindowsJAWTWindow extends JAWTWindow { protected int lockSurfaceImpl() throws NativeWindowException { int ret = NativeWindow.LOCK_SUCCESS; - long startTime; - if (PROFILING) { - startTime = System.currentTimeMillis(); - } ds = JAWT.getJAWT().GetDrawingSurface(component); if (ds == null) { // Widget not yet realized - unlockSurface(); + unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } int res = ds.Lock(); dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ; if (!dsLocked) { - unlockSurface(); + unlockSurfaceImpl(); throw new NativeWindowException("Unable to lock surface"); } // See whether the surface changed and if so destroy the old @@ -97,40 +90,27 @@ public class WindowsJAWTWindow extends JAWTWindow { } dsi = ds.GetDrawingSurfaceInfo(); if (dsi == null) { - unlockSurface(); + unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo(); if (win32dsi == null) { - unlockSurface(); + unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } windowHandle = win32dsi.getHandle(); drawable = win32dsi.getHdc(); if (windowHandle == 0 || drawable == 0) { - unlockSurface(); + unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } else { updateBounds(dsi.getBounds()); } - if (PROFILING) { - long endTime = System.currentTimeMillis(); - profilingLockSurfaceTime += (endTime - startTime); - if (++profilingLockSurfaceTicks == PROFILING_TICKS) { - System.err.println("LockSurface calls: " + profilingLockSurfaceTime + " ms / " + PROFILING_TICKS + " calls (" + - ((float) profilingLockSurfaceTime / (float) PROFILING_TICKS) + " ms/call)"); - profilingLockSurfaceTime = 0; - profilingLockSurfaceTicks = 0; - } - } return ret; } protected void unlockSurfaceImpl() throws NativeWindowException { long startTime = 0; - if (PROFILING) { - startTime = System.currentTimeMillis(); - } if(null!=ds) { if (null!=dsi) { ds.FreeDrawingSurfaceInfo(dsi); @@ -143,16 +123,6 @@ public class WindowsJAWTWindow extends JAWTWindow { ds = null; dsi = null; win32dsi = null; - if (PROFILING) { - long endTime = System.currentTimeMillis(); - profilingUnlockSurfaceTime += (endTime - startTime); - if (++profilingUnlockSurfaceTicks == PROFILING_TICKS) { - System.err.println("UnlockSurface calls: " + profilingUnlockSurfaceTime + " ms / " + PROFILING_TICKS + " calls (" + - ((float) profilingUnlockSurfaceTime / (float) PROFILING_TICKS) + " ms/call)"); - profilingUnlockSurfaceTime = 0; - profilingUnlockSurfaceTicks = 0; - } - } } public long getWindowHandle() { @@ -168,10 +138,6 @@ public class WindowsJAWTWindow extends JAWTWindow { private boolean dsLocked; private JAWT_DrawingSurfaceInfo dsi; private JAWT_Win32DrawingSurfaceInfo win32dsi; - private long profilingLockSurfaceTime = 0; - private int profilingLockSurfaceTicks = 0; - private long profilingUnlockSurfaceTime = 0; - private int profilingUnlockSurfaceTicks = 0; // lifetime: valid after lock, forever until invalidate protected long windowHandle; diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java index 1324bd199..f87558dbc 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java @@ -37,12 +37,6 @@ package com.jogamp.nativewindow.impl.jawt.x11; -import com.jogamp.nativewindow.impl.jawt.JAWT; -import com.jogamp.nativewindow.impl.jawt.JAWTFactory; -import com.jogamp.nativewindow.impl.jawt.JAWTWindow; -import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurface; -import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurfaceInfo; -import com.jogamp.nativewindow.impl.x11.X11Util; import javax.media.nativewindow.AbstractGraphicsConfiguration; import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.AbstractGraphicsScreen; @@ -52,6 +46,13 @@ import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.awt.AWTGraphicsDevice; import javax.media.nativewindow.util.Point; +import com.jogamp.nativewindow.impl.jawt.JAWT; +import com.jogamp.nativewindow.impl.jawt.JAWTFactory; +import com.jogamp.nativewindow.impl.jawt.JAWTWindow; +import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurface; +import com.jogamp.nativewindow.impl.jawt.JAWT_DrawingSurfaceInfo; +import com.jogamp.nativewindow.impl.x11.X11Util; + public class X11JAWTWindow extends JAWTWindow { public X11JAWTWindow(Object comp, AbstractGraphicsConfiguration config) { @@ -90,13 +91,13 @@ public class X11JAWTWindow extends JAWTWindow { ds = JAWT.getJAWT().GetDrawingSurface(component); if (ds == null) { // Widget not yet realized - unlockSurface(); + unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } int res = ds.Lock(); dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ; if (!dsLocked) { - unlockSurface(); + unlockSurfaceImpl(); throw new NativeWindowException("Unable to lock surface"); } // See whether the surface changed and if so destroy the old @@ -109,17 +110,17 @@ public class X11JAWTWindow extends JAWTWindow { } dsi = ds.GetDrawingSurfaceInfo(); if (dsi == null) { - unlockSurface(); + unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo(); if (x11dsi == null) { - unlockSurface(); + unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } drawable = x11dsi.getDrawable(); if (drawable == 0) { - unlockSurface(); + unlockSurfaceImpl(); return LOCK_SURFACE_NOT_READY; } else { updateBounds(dsi.getBounds()); diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java index 41051ab46..c3d10de10 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java @@ -44,7 +44,6 @@ import javax.media.nativewindow.*; import java.awt.Component; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; -import java.awt.Transparency; import java.awt.image.ColorModel; import javax.media.nativewindow.AbstractGraphicsConfiguration; import com.jogamp.nativewindow.impl.Debug; @@ -125,14 +124,8 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple */ public static CapabilitiesImmutable setupCapabilitiesRGBABits(CapabilitiesImmutable capabilitiesIn, GraphicsConfiguration gc) { Capabilities capabilities = (Capabilities) capabilitiesIn.cloneMutable(); - - int cmTransparency = capabilities.isBackgroundOpaque()?Transparency.OPAQUE:Transparency.TRANSLUCENT; - ColorModel cm = gc.getColorModel(cmTransparency); - if(null==cm && !capabilities.isBackgroundOpaque()) { - capabilities.setBackgroundOpaque(true); - cmTransparency = Transparency.OPAQUE; - cm = gc.getColorModel(cmTransparency); - } + + ColorModel cm = gc.getColorModel(); if(null==cm) { throw new NativeWindowException("Could not determine AWT ColorModel"); } |