diff options
Diffstat (limited to 'src/net/java/games')
15 files changed, 351 insertions, 569 deletions
diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java index 56fba2900..d0ea429a4 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java @@ -75,18 +75,6 @@ public abstract class MacOSXGLContext extends GLContextImpl return glExtensionName; } - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - protected boolean create() { return create(false, false); } @@ -233,6 +221,36 @@ public abstract class MacOSXGLContext extends GLContextImpl return super.isExtensionAvailable(glExtensionName); } + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public boolean canCreatePbufferContext() { + return false; + } + + public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, + int initialWidth, + int initialHeight) { + throw new GLException("Not supported"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + //---------------------------------------------------------------------- // Internals only below this point // diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java index c6ac894b1..797ba2459 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java @@ -61,12 +61,4 @@ public class MacOSXOffscreenGLContext extends MacOSXPbufferGLContext public boolean offscreenImageNeedsVerticalFlip() { return true; } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java index a8ffcf8ec..6dd2c4b4a 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java @@ -55,14 +55,6 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { this.drawable = drawable; } - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - public boolean canCreatePbufferContext() { return true; } @@ -75,14 +67,6 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { return buf; } - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - protected int makeCurrentImpl() throws GLException { try { int lockRes = drawable.lockSurface(); diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java index 02e5c1ead..b9d8dbf52 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java @@ -34,16 +34,6 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { this.drawable = drawable; } - public boolean canCreatePbufferContext() { - return false; - } - - public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - public void bindPbufferToTexture() { GL gl = getGL(); gl.glBindTexture(textureTarget, texture); diff --git a/src/net/java/games/jogl/impl/windows/WindowsDummyGLDrawable.java b/src/net/java/games/jogl/impl/windows/WindowsDummyGLDrawable.java new file mode 100755 index 000000000..95c378c7c --- /dev/null +++ b/src/net/java/games/jogl/impl/windows/WindowsDummyGLDrawable.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. 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 net.java.games.jogl.impl.windows; + +import net.java.games.jogl.*; +import net.java.games.jogl.impl.*; + +public class WindowsDummyGLDrawable extends WindowsGLDrawable { + private long hwnd; + + public WindowsDummyGLDrawable() { + super(null, new GLCapabilities(), null); + // All entries to CreateDummyWindow must synchronize on one object + // to avoid accidentally registering the dummy window class twice + synchronized (WindowsDummyGLDrawable.class) { + hwnd = WGL.CreateDummyWindow(0, 0, 1, 1); + } + hdc = WGL.GetDC(hwnd); + // Choose a (hopefully hardware-accelerated) OpenGL pixel format for this device context + GLCapabilities caps = new GLCapabilities(); + caps.setDepthBits(16); + PIXELFORMATDESCRIPTOR pfd = glCapabilities2PFD(caps, true); + int pixelFormat = WGL.ChoosePixelFormat(hdc, pfd); + if ((pixelFormat == 0) || + (!WGL.SetPixelFormat(hdc, pixelFormat, pfd))) { + destroy(); + } + } + + public void setSize(int width, int height) { + } + + public int getWidth() { + return 1; + } + + public int getHeight() { + return 1; + } + + public GLContext createContext(GLContext shareWith) { + if (hdc == 0) { + // Construction failed + return null; + } + return new WindowsGLContext(this, shareWith); + } + + public void destroy() { + if (hdc != 0) { + WGL.ReleaseDC(hwnd, hdc); + hdc = 0; + } + if (hwnd != 0) { + WGL.ShowWindow(hwnd, WGL.SW_HIDE); + WGL.DestroyWindow(hwnd); + hwnd = 0; + } + } +} diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java index 44f2894eb..fccd0bf70 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java +++ b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java @@ -44,7 +44,7 @@ import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX import net.java.games.jogl.*; import net.java.games.jogl.impl.*; -public abstract class WindowsGLContext extends GLContextImpl { +public class WindowsGLContext extends GLContextImpl { protected WindowsGLDrawable drawable; protected long hglrc; private boolean wglGetExtensionsStringEXTInitialized; @@ -95,14 +95,6 @@ public abstract class WindowsGLContext extends GLContextImpl { return glExtensionName; } - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public abstract int getOffscreenContextReadBuffer(); - - public abstract boolean offscreenImageNeedsVerticalFlip(); - /** * Creates and initializes an appropriate OpenGL context. Should only be * called by {@link #makeCurrentImpl()}. @@ -259,6 +251,36 @@ public abstract class WindowsGLContext extends GLContextImpl { return available; } + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public boolean canCreatePbufferContext() { + return false; + } + + public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, + int initialWidth, + int initialHeight) { + throw new GLException("Not supported"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + //---------------------------------------------------------------------- // Internals only below this point // diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java b/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java index d99554fcf..fb03b8702 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java +++ b/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java @@ -81,8 +81,6 @@ public class WindowsGLContextFactory extends GLContextFactory { public WindowsGLContextFactory() { AccessController.doPrivileged( new PrivilegedAction() { public Object run() { - Runtime.getRuntime().addShutdownHook( new ShutdownHook() ); - // Test for whether we should enable the single-threaded // workaround for ATI cards. It appears that if we make any // OpenGL context current on more than one thread on ATI cards @@ -161,235 +159,6 @@ public class WindowsGLContextFactory extends GLContextFactory { return new WindowsOffscreenGLDrawable(capabilities, chooser); } - // Return cached GL drawable - public static WindowsGLDrawable getDummyGLDrawable( final GraphicsDevice device ) { - checkForDummyContext( device ); - NativeWindowStruct nws = (NativeWindowStruct) dummyContextMap.get(device); - return nws.getWindowsDrawable(); - } - - // Return cached GL context - public static WindowsGLContext getDummyGLContext( final GraphicsDevice device ) { - checkForDummyContext( device ); - NativeWindowStruct nws = (NativeWindowStruct) dummyContextMap.get(device); - return nws.getWindowsContext(); - } - - // Return cached extension string - public static String getDummyGLExtensions(final GraphicsDevice device) { - checkForDummyContext( device ); - String exts = (String) dummyExtensionsMap.get(device); - return (exts == null) ? "" : exts; - } - - // Return cached GL function pointers - public static GL getDummyGL(final GraphicsDevice device) { - checkForDummyContext( device ); - NativeWindowStruct nws = (NativeWindowStruct) dummyContextMap.get(device); - return( nws.getWindowsContext().getGL() ); - } - - /* - * Locate a cached native window, if one doesn't exist create one amd - * cache it. - */ - private static void checkForDummyContext( final GraphicsDevice device ) { - if (!pendingContextSet.contains(device) && !dummyContextMap.containsKey( device ) ) { - if (DEBUG) { - System.err.println("WindowsGLContextFactory.checkForDummyContext() called on thread " + - Thread.currentThread().getName()); - } - - pendingContextSet.add(device); - GraphicsConfiguration config = device.getDefaultConfiguration(); - Rectangle rect = config.getBounds(); - GLCapabilities caps = new GLCapabilities(); - caps.setDepthBits( 16 ); - // Create a context that we use to query pixel formats - - WindowsOnscreenGLDrawable drawable = new WindowsOnscreenGLDrawable(null, caps, null); - WindowsOnscreenGLContext context = new WindowsOnscreenGLContext( drawable, null ); - // Start a native thread and grab native screen resources from the thread - NativeWindowThread nwt = new NativeWindowThread( rect ); - nwt.start(); - long hWnd = 0; - long tempHDC = 0; - while( (hWnd = nwt.getHWND()) == 0 || (tempHDC = nwt.getHDC()) == 0 ) { - Thread.yield(); - } - // Choose a hardware accelerated pixel format - PIXELFORMATDESCRIPTOR pfd = drawable.glCapabilities2PFD( caps, true ); - int pixelFormat = WGL.ChoosePixelFormat( tempHDC, pfd ); - if( pixelFormat == 0 ) { - System.err.println("Pixel Format is Zero"); - pendingContextSet.remove(device); - return; - } - // Set the hardware accelerated pixel format - if (!WGL.SetPixelFormat(tempHDC, pixelFormat, pfd)) { - System.err.println("SetPixelFormat Failed"); - pendingContextSet.remove( device ); - return; - } - // Create a rendering context - long tempHGLRC = WGL.wglCreateContext( tempHDC ); - if( hWnd == 0 || tempHDC == 0 || tempHGLRC == 0 ) { - pendingContextSet.remove( device ); - return; - } - // Store native handles for later use - NativeWindowStruct nws = new NativeWindowStruct(); - nws.setHWND( hWnd ); - nws.setWindowsDrawable( drawable ); - nws.setWindowsContext( context ); - nws.setWindowThread( nwt ); - long currentHDC = WGL.wglGetCurrentDC(); - long currentHGLRC = WGL.wglGetCurrentContext(); - // Make the new hardware accelerated context current - if( !WGL.wglMakeCurrent( tempHDC, tempHGLRC ) ) { - pendingContextSet.remove( device ); - return; - } - // Grab function pointers - drawable.hdc = tempHDC; - context.hglrc = tempHGLRC; - context.resetGLFunctionAvailability(); - context.createGL(); - pendingContextSet.remove( device ); - dummyContextMap.put( device, nws ); - String availableGLExtensions = ""; - String availableWGLExtensions = ""; - String availableEXTExtensions = ""; - try { - availableWGLExtensions = context.getGL().wglGetExtensionsStringARB( currentHDC ); - } catch( GLException e ) { - } - try { - availableEXTExtensions = context.getGL().wglGetExtensionsStringEXT(); - } catch( GLException e ) { - } - availableGLExtensions = context.getGL().glGetString( GL.GL_EXTENSIONS ); - dummyExtensionsMap.put(device, availableGLExtensions + " " + availableEXTExtensions + " " + availableWGLExtensions); - WGL.wglMakeCurrent( currentHDC, currentHGLRC ); - } - } - - /* - * This class stores handles to native resources that need to be destroyed - * at JVM shutdown. - */ - static class NativeWindowStruct { - private long HWND; - private WindowsGLDrawable windowsDrawable; - private WindowsGLContext windowsContext; - private Thread windowThread; - - public NativeWindowStruct() { - } - - public long getHDC() { - return( windowsDrawable.hdc ); - } - - public long getHGLRC() { - return( windowsContext.hglrc ); - } - - public void setHWND( long hwnd ) { - HWND = hwnd; - } - - public long getHWND() { - return( HWND ); - } - - public void setWindowsDrawable( WindowsGLDrawable drawable ) { - windowsDrawable = drawable; - } - - public void setWindowsContext( WindowsGLContext context ) { - windowsContext = context; - } - - public WindowsGLDrawable getWindowsDrawable() { - return( windowsDrawable ); - } - - public WindowsGLContext getWindowsContext() { - return( windowsContext ); - } - - public void setWindowThread( Thread thread ) { - windowThread = thread; - } - - public Thread getWindowThread() { - return( windowThread ); - } - } - - /* - * Native HWDN and HDC handles must be created and destroyed on the same - * thread. - */ - - static class NativeWindowThread extends Thread { - private long HWND = 0; - private long HDC = 0; - private Rectangle rectangle; - - public NativeWindowThread( Rectangle rect ) { - rectangle = rect; - } - - public synchronized long getHWND() { - return( HWND ); - } - - public synchronized long getHDC() { - return( HDC ); - } - - public void run() { - // Create a native window and device context - synchronized (WindowsGLContextFactory.class) { - HWND = WGL.CreateDummyWindow( rectangle.x, rectangle.y, rectangle.width, rectangle.height ); - } - HDC = WGL.GetDC( HWND ); - - // Start the message pump at shutdown - WGL.NativeEventLoop(); - } - } - - /* - * This class is registered with the JVM to destroy all cached redering - * contexts, device contexts, and window handles. - */ - - class ShutdownHook extends Thread { - public void run() { - // Collect all saved screen resources - Collection c = dummyContextMap.values(); - Iterator iter = c.iterator(); - while( iter.hasNext() ) { - // NativeWindowStruct holds refs to native resources that need to be destroyed - NativeWindowStruct struct = (NativeWindowStruct)iter.next(); - // Restart native window threads to respond to window closing events - synchronized( struct.getWindowThread() ) { - struct.getWindowThread().notifyAll(); - } - // Destroy OpenGL rendering context - if( !WGL.wglDeleteContext( struct.getHGLRC() ) ) { - System.err.println( "Error Destroying NativeWindowStruct RC: " + WGL.GetLastError() ); - } - // Send context handles to native method for deletion - WGL.DestroyDummyWindow( struct.getHWND(), struct.getHDC() ); - } - } - } - - static String wglGetLastError() { int err = WGL.GetLastError(); String detail = null; diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLDrawable.java b/src/net/java/games/jogl/impl/windows/WindowsGLDrawable.java index 42e83c05d..840dd2183 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsGLDrawable.java +++ b/src/net/java/games/jogl/impl/windows/WindowsGLDrawable.java @@ -92,195 +92,189 @@ public abstract class WindowsGLDrawable extends GLDrawableImpl { GraphicsDevice device = config.getDevice(); // Produce a recommended pixel format selection for the GLCapabilitiesChooser. // Use wglChoosePixelFormatARB if user requested multisampling and if we have it available - GL dummyGL = null; + WindowsGLDrawable dummyDrawable = null; + GLContext dummyContext = null; + GL dummyGL = null; if (capabilities.getSampleBuffers()) { - dummyGL = WindowsGLContextFactory.getDummyGL(device); - } + dummyDrawable = new WindowsDummyGLDrawable(); + dummyContext = dummyDrawable.createContext(null); + if (dummyContext != null) { + dummyContext.makeCurrent(); + dummyGL = dummyContext.getGL(); + } + } int recommendedPixelFormat = -1; boolean haveWGLChoosePixelFormatARB = false; boolean haveWGLARBMultisample = false; - if (dummyGL != null) { - String availableWGLExtensions = WindowsGLContextFactory.getDummyGLExtensions(device); - if (availableWGLExtensions.indexOf("WGL_ARB_pixel_format") >= 0) { - haveWGLChoosePixelFormatARB = true; - if (availableWGLExtensions.indexOf("WGL_ARB_multisample") >= 0) { - haveWGLARBMultisample = true; - } - } - } - long dc = 0; - long rc = 0; - boolean freeWGLC = false; - if( dummyGL != null ) { - dc = WindowsGLContextFactory.getDummyGLDrawable( device ).hdc; - rc = WindowsGLContextFactory.getDummyGLContext( device ).hglrc; - if( !WGL.wglMakeCurrent( dc, rc ) ) { - System.err.println(getThreadName() + ": Error Making WGLC Current: " + WGL.GetLastError() ); - } else { - freeWGLC = true; - } - } - // Fallback path for older cards, in particular Intel Extreme motherboard graphics boolean gotAvailableCaps = false; - if (dummyGL != null && haveWGLChoosePixelFormatARB) { - int[] iattributes = new int [2 * MAX_ATTRIBS]; - int[] iresults = new int [2 * MAX_ATTRIBS]; - float[] fattributes = new float[2 * MAX_ATTRIBS]; - int niattribs = 0; - int nfattribs = 0; - iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - iattributes[niattribs++] = GL.WGL_DRAW_TO_WINDOW_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_TYPE_RGBA_ARB; - iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; - if (capabilities.getDoubleBuffered()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - iattributes[niattribs++] = GL.WGL_STEREO_ARB; - if (capabilities.getStereo()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; - iattributes[niattribs++] = capabilities.getDepthBits(); - iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; - iattributes[niattribs++] = capabilities.getRedBits(); - iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; - iattributes[niattribs++] = capabilities.getGreenBits(); - iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; - iattributes[niattribs++] = capabilities.getBlueBits(); - iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; - iattributes[niattribs++] = capabilities.getAlphaBits(); - iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; - iattributes[niattribs++] = capabilities.getStencilBits(); - if (capabilities.getAccumRedBits() > 0 || - capabilities.getAccumGreenBits() > 0 || - capabilities.getAccumBlueBits() > 0 || - capabilities.getAccumAlphaBits() > 0) { - iattributes[niattribs++] = GL.WGL_ACCUM_BITS_ARB; - iattributes[niattribs++] = (capabilities.getAccumRedBits() + - capabilities.getAccumGreenBits() + - capabilities.getAccumBlueBits() + - capabilities.getAccumAlphaBits()); - iattributes[niattribs++] = GL.WGL_ACCUM_RED_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumRedBits(); - iattributes[niattribs++] = GL.WGL_ACCUM_GREEN_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumGreenBits(); - iattributes[niattribs++] = GL.WGL_ACCUM_BLUE_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumBlueBits(); - iattributes[niattribs++] = GL.WGL_ACCUM_ALPHA_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumAlphaBits(); - } - if (haveWGLARBMultisample) { - if (capabilities.getSampleBuffers()) { - iattributes[niattribs++] = GL.WGL_SAMPLE_BUFFERS_ARB; + if (dummyGL != null) { + haveWGLChoosePixelFormatARB = dummyGL.isExtensionAvailable("WGL_ARB_pixel_format"); + haveWGLARBMultisample = dummyGL.isExtensionAvailable("WGL_ARB_multisample"); + + try { + if (haveWGLChoosePixelFormatARB) { + int[] iattributes = new int [2 * MAX_ATTRIBS]; + int[] iresults = new int [2 * MAX_ATTRIBS]; + float[] fattributes = new float[2 * MAX_ATTRIBS]; + int niattribs = 0; + int nfattribs = 0; + iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; iattributes[niattribs++] = GL.GL_TRUE; - iattributes[niattribs++] = GL.WGL_SAMPLES_ARB; - iattributes[niattribs++] = capabilities.getNumSamples(); - } - } + iattributes[niattribs++] = GL.WGL_DRAW_TO_WINDOW_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = GL.WGL_TYPE_RGBA_ARB; + iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; + if (capabilities.getDoubleBuffered()) { + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = GL.GL_FALSE; + } + iattributes[niattribs++] = GL.WGL_STEREO_ARB; + if (capabilities.getStereo()) { + iattributes[niattribs++] = GL.GL_TRUE; + } else { + iattributes[niattribs++] = GL.GL_FALSE; + } + iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; + iattributes[niattribs++] = capabilities.getDepthBits(); + iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; + iattributes[niattribs++] = capabilities.getRedBits(); + iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; + iattributes[niattribs++] = capabilities.getGreenBits(); + iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; + iattributes[niattribs++] = capabilities.getBlueBits(); + iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; + iattributes[niattribs++] = capabilities.getAlphaBits(); + iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; + iattributes[niattribs++] = capabilities.getStencilBits(); + if (capabilities.getAccumRedBits() > 0 || + capabilities.getAccumGreenBits() > 0 || + capabilities.getAccumBlueBits() > 0 || + capabilities.getAccumAlphaBits() > 0) { + iattributes[niattribs++] = GL.WGL_ACCUM_BITS_ARB; + iattributes[niattribs++] = (capabilities.getAccumRedBits() + + capabilities.getAccumGreenBits() + + capabilities.getAccumBlueBits() + + capabilities.getAccumAlphaBits()); + iattributes[niattribs++] = GL.WGL_ACCUM_RED_BITS_ARB; + iattributes[niattribs++] = capabilities.getAccumRedBits(); + iattributes[niattribs++] = GL.WGL_ACCUM_GREEN_BITS_ARB; + iattributes[niattribs++] = capabilities.getAccumGreenBits(); + iattributes[niattribs++] = GL.WGL_ACCUM_BLUE_BITS_ARB; + iattributes[niattribs++] = capabilities.getAccumBlueBits(); + iattributes[niattribs++] = GL.WGL_ACCUM_ALPHA_BITS_ARB; + iattributes[niattribs++] = capabilities.getAccumAlphaBits(); + } + if (haveWGLARBMultisample) { + if (capabilities.getSampleBuffers()) { + iattributes[niattribs++] = GL.WGL_SAMPLE_BUFFERS_ARB; + iattributes[niattribs++] = GL.GL_TRUE; + iattributes[niattribs++] = GL.WGL_SAMPLES_ARB; + iattributes[niattribs++] = capabilities.getNumSamples(); + } + } - int[] pformats = new int[MAX_PFORMATS]; - int[] numFormatsTmp = new int[1]; - if (dummyGL.wglChoosePixelFormatARB(hdc, - iattributes, 0, - fattributes, 0, - MAX_PFORMATS, - pformats, 0, - numFormatsTmp, 0)) { - numFormats = numFormatsTmp[0]; - if (numFormats > 0) { - // Remove one-basing of pixel format (added on later) - recommendedPixelFormat = pformats[0] - 1; - if (DEBUG) { - System.err.println(getThreadName() + ": Used wglChoosePixelFormatARB to recommend pixel format " + recommendedPixelFormat); + int[] pformats = new int[MAX_PFORMATS]; + int[] numFormatsTmp = new int[1]; + if (dummyGL.wglChoosePixelFormatARB(hdc, + iattributes, 0, + fattributes, 0, + MAX_PFORMATS, + pformats, 0, + numFormatsTmp, 0)) { + numFormats = numFormatsTmp[0]; + if (numFormats > 0) { + // Remove one-basing of pixel format (added on later) + recommendedPixelFormat = pformats[0] - 1; + if (DEBUG) { + System.err.println(getThreadName() + ": Used wglChoosePixelFormatARB to recommend pixel format " + recommendedPixelFormat); + } + } + } else { + if (DEBUG) { + System.err.println(getThreadName() + ": wglChoosePixelFormatARB failed: " + WGL.GetLastError() ); + Thread.dumpStack(); + } } - } - } else { - if (DEBUG) { - System.err.println(getThreadName() + ": wglChoosePixelFormatARB failed: " + WGL.GetLastError() ); - Thread.dumpStack(); - } - } - if (DEBUG) { - if (recommendedPixelFormat < 0) { - System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format"); - if (capabilities.getSampleBuffers()) { - System.err.print(" for multisampled GLCapabilities"); + if (DEBUG) { + if (recommendedPixelFormat < 0) { + System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format"); + if (capabilities.getSampleBuffers()) { + System.err.print(" for multisampled GLCapabilities"); + } + System.err.println(); + } } - System.err.println(); - } - } - - // Produce a list of GLCapabilities to give to the - // GLCapabilitiesChooser. - // Use wglGetPixelFormatAttribivARB instead of - // DescribePixelFormat to get higher-precision information - // about the pixel format (should make the GLCapabilities - // more precise as well...i.e., remove the - // "HardwareAccelerated" bit, which is basically - // meaningless, and put in whether it can render to a - // window, to a pbuffer, or to a pixmap) - niattribs = 0; - iattributes[0] = GL.WGL_NUMBER_PIXEL_FORMATS_ARB; - if (dummyGL.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, 0, iresults, 0)) { - numFormats = iresults[0]; - // Should we be filtering out the pixel formats which aren't - // applicable, as we are doing here? - // We don't have enough information in the GLCapabilities to - // represent those that aren't... - iattributes[niattribs++] = GL.WGL_DRAW_TO_WINDOW_ARB; - iattributes[niattribs++] = GL.WGL_ACCELERATION_ARB; - iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; - iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; - iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; - iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; - iattributes[niattribs++] = GL.WGL_STEREO_ARB; - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; - iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; - iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_RED_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_GREEN_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_BLUE_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_ALPHA_BITS_ARB; - if (haveWGLARBMultisample) { - iattributes[niattribs++] = GL.WGL_SAMPLE_BUFFERS_ARB; - iattributes[niattribs++] = GL.WGL_SAMPLES_ARB; - } - availableCaps = new GLCapabilities[numFormats]; - for (int i = 0; i < numFormats; i++) { - if (!dummyGL.wglGetPixelFormatAttribivARB(hdc, i+1, 0, niattribs, iattributes, 0, iresults, 0)) { - throw new GLException("Error getting pixel format attributes for pixel format " + (i + 1) + " of device context"); + // Produce a list of GLCapabilities to give to the + // GLCapabilitiesChooser. + // Use wglGetPixelFormatAttribivARB instead of + // DescribePixelFormat to get higher-precision information + // about the pixel format (should make the GLCapabilities + // more precise as well...i.e., remove the + // "HardwareAccelerated" bit, which is basically + // meaningless, and put in whether it can render to a + // window, to a pbuffer, or to a pixmap) + niattribs = 0; + iattributes[0] = GL.WGL_NUMBER_PIXEL_FORMATS_ARB; + if (dummyGL.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, 0, iresults, 0)) { + numFormats = iresults[0]; + // Should we be filtering out the pixel formats which aren't + // applicable, as we are doing here? + // We don't have enough information in the GLCapabilities to + // represent those that aren't... + iattributes[niattribs++] = GL.WGL_DRAW_TO_WINDOW_ARB; + iattributes[niattribs++] = GL.WGL_ACCELERATION_ARB; + iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; + iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; + iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; + iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; + iattributes[niattribs++] = GL.WGL_STEREO_ARB; + iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; + iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; + iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; + iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; + iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; + iattributes[niattribs++] = GL.WGL_ACCUM_RED_BITS_ARB; + iattributes[niattribs++] = GL.WGL_ACCUM_GREEN_BITS_ARB; + iattributes[niattribs++] = GL.WGL_ACCUM_BLUE_BITS_ARB; + iattributes[niattribs++] = GL.WGL_ACCUM_ALPHA_BITS_ARB; + if (haveWGLARBMultisample) { + iattributes[niattribs++] = GL.WGL_SAMPLE_BUFFERS_ARB; + iattributes[niattribs++] = GL.WGL_SAMPLES_ARB; + } + + availableCaps = new GLCapabilities[numFormats]; + for (int i = 0; i < numFormats; i++) { + if (!dummyGL.wglGetPixelFormatAttribivARB(hdc, i+1, 0, niattribs, iattributes, 0, iresults, 0)) { + throw new GLException("Error getting pixel format attributes for pixel format " + (i + 1) + " of device context"); + } + availableCaps[i] = iattributes2GLCapabilities(iattributes, iresults, niattribs, true); + } + gotAvailableCaps = true; + } else { + int lastErr = WGL.GetLastError(); + // Intel Extreme graphics fails with a zero error code + if (lastErr != 0) { + throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB: error code " + WGL.GetLastError()); + } } - availableCaps[i] = iattributes2GLCapabilities(iattributes, iresults, niattribs, true); - } - if( freeWGLC ) { - WGL.wglMakeCurrent( 0, 0 ); - } - gotAvailableCaps = true; - } else { - int lastErr = WGL.GetLastError(); - // Intel Extreme graphics fails with a zero error code - if (lastErr != 0) { - throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB: error code " + WGL.GetLastError()); } + } finally { + dummyContext.release(); + dummyContext.destroy(); + dummyDrawable.destroy(); } } + // Fallback path for older cards, in particular Intel Extreme motherboard graphics if (!gotAvailableCaps) { if (DEBUG) { if (!capabilities.getSampleBuffers()) { System.err.println(getThreadName() + ": Using ChoosePixelFormat because multisampling not requested"); } else { - System.err.println(getThreadName() + ": Using ChoosePixelFormat because no wglChoosePixelFormatARB: dummyGL = " + dummyGL); + System.err.println(getThreadName() + ": Using ChoosePixelFormat because no wglChoosePixelFormatARB"); } } pfd = glCapabilities2PFD(capabilities, onscreen); diff --git a/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java index a2fae5971..2eb0edcd5 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java +++ b/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java @@ -61,23 +61,4 @@ public class WindowsOffscreenGLContext extends WindowsGLContext { // We can take care of this in the DIB creation (see below) return false; } - - public boolean canCreatePbufferContext() { - // For now say no - return false; - } - - public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } } diff --git a/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java index c71f35ff0..15de59df8 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java +++ b/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java @@ -55,14 +55,6 @@ public class WindowsOnscreenGLContext extends WindowsGLContext { this.drawable = drawable; } - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - public boolean canCreatePbufferContext() { return haveWGLARBPbuffer(); } @@ -75,14 +67,6 @@ public class WindowsOnscreenGLContext extends WindowsGLContext { return buf; } - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - protected int makeCurrentImpl() throws GLException { try { int lockRes = drawable.lockSurface(); diff --git a/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java index ca2f4aaa9..98956f259 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java +++ b/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java @@ -57,16 +57,6 @@ public class WindowsPbufferGLContext extends WindowsGLContext { this.drawable = drawable; } - public boolean canCreatePbufferContext() { - return false; - } - - public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - public void bindPbufferToTexture() { if (!rtt) { throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + @@ -160,14 +150,6 @@ public class WindowsPbufferGLContext extends WindowsGLContext { return res; } - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - public int getFloatingPointMode() { return drawable.getFloatingPointMode(); } diff --git a/src/net/java/games/jogl/impl/x11/X11GLContext.java b/src/net/java/games/jogl/impl/x11/X11GLContext.java index a43def0b8..f00e75ce2 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11GLContext.java @@ -105,14 +105,6 @@ public abstract class X11GLContext extends GLContextImpl { return glExtensionName; } - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public abstract int getOffscreenContextReadBuffer(); - - public abstract boolean offscreenImageNeedsVerticalFlip(); - /** Helper routine which usually just turns around and calls * createContext (except for pbuffers, which use a different context * creation mechanism). Should only be called by {@link @@ -302,6 +294,36 @@ public abstract class X11GLContext extends GLContextImpl { return super.isExtensionAvailable(glExtensionName); } + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextReadBuffer() { + throw new GLException("Should not call this"); + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public boolean canCreatePbufferContext() { + return false; + } + + public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, + int initialWidth, + int initialHeight) { + throw new GLException("Not supported"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + //---------------------------------------------------------------------- // Internals only below this point // diff --git a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java b/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java index 4397c72d8..fcf734825 100644 --- a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java @@ -68,25 +68,6 @@ public class X11OffscreenGLContext extends X11GLContext { return true; } - public boolean canCreatePbufferContext() { - // For now say no - return false; - } - - public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - protected void create() { createContext(false); } diff --git a/src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java b/src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java index 1828f8378..7a661e9e3 100644 --- a/src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java @@ -55,14 +55,6 @@ public class X11OnscreenGLContext extends X11GLContext { this.drawable = drawable; } - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - public boolean canCreatePbufferContext() { return isExtensionAvailable("GL_ARB_pbuffer"); } @@ -75,14 +67,6 @@ public class X11OnscreenGLContext extends X11GLContext { return buf; } - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - protected int makeCurrentImpl() throws GLException { try { int lockRes = drawable.lockSurface(); diff --git a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java b/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java index bebbdb91c..0d89c96df 100644 --- a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java @@ -51,16 +51,6 @@ public class X11PbufferGLContext extends X11GLContext { this.drawable = drawable; } - public boolean canCreatePbufferContext() { - return false; - } - - public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - public void bindPbufferToTexture() { // FIXME: figure out how to implement this throw new GLException("Not yet implemented"); @@ -128,14 +118,6 @@ public class X11PbufferGLContext extends X11GLContext { } } - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - public int getFloatingPointMode() { return drawable.getFloatingPointMode(); } |