From 05ad8604b58f355890f0e3804906c7e8d598edfa Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Tue, 3 Aug 2004 17:50:18 +0000 Subject: Bug fix from user GKW on the JOGL forums for problems reported by users in JOGL 1.1 betas where the code path for wglChoosePixelFormatARB (supporting full-scene antialiasing) was failing on older cards. The old drivers expect an OpenGL context to be current while the wglChoosePixelFormatARB and associated calls are being made, even though the documentation explicitly states that this is not necessary. GKW's fix creates a native window synchronously (independent of the AWT) and associates an OpenGL context with it which is used to choose pixel formats for other windows on the same GraphicsDevice. Upon VM shutdown, a native message pump is started which causes proper disposal of the native window and its OpenGL contexts. There is currently no bug ID associated with this fix, although it may be a component of completely addressing several open bugs. Also includes a bug fix from GKW and kbr for: Issue 98: Just 1st frame rendering on ATI Radeon This was a race condition between JOGL's automatic discovery that the ATI_WORKAROUND was needed and the creation of the first GLCanvas and associated Animator. The need for disabling the setRenderingThread optimization was computed too late, incorrectly locking out other threads (in particular, the AWT event queue thread) from performing rendering of the component. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@144 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../games/jogl/impl/windows/WindowsGLContext.java | 36 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'src/net/java/games/jogl/impl/windows/WindowsGLContext.java') diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java index 0dd05f7ba..eed383794 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java +++ b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java @@ -40,7 +40,9 @@ package net.java.games.jogl.impl.windows; import java.awt.Component; +import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; +import java.awt.Rectangle; import java.util.*; import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX import net.java.games.jogl.*; @@ -138,7 +140,7 @@ public abstract class WindowsGLContext extends GLContext { } if (!WGL.wglMakeCurrent(hdc, hglrc)) { - throw new GLException("Error making context current"); + throw new GLException("Error making context current: " + WGL.GetLastError()); } if (created) { @@ -164,7 +166,7 @@ public abstract class WindowsGLContext extends GLContext { protected synchronized void free() throws GLException { if (!WGL.wglMakeCurrent(0, 0)) { - throw new GLException("Error freeing OpenGL context"); + throw new GLException("Error freeing OpenGL context: " + WGL.GetLastError()); } } @@ -270,10 +272,11 @@ public abstract class WindowsGLContext extends GLContext { GLCapabilities[] availableCaps = null; int numFormats = 0; pfd = newPixelFormatDescriptor(); - GraphicsDevice device = component.getGraphicsConfiguration().getDevice(); + GraphicsConfiguration config = component.getGraphicsConfiguration(); + GraphicsDevice device = config.getDevice(); // Produce a recommended pixel format selection for the GLCapabilitiesChooser. // Try to use wglChoosePixelFormatARB if we have it available - GL dummyGL = WindowsGLContextFactory.getDummyGLContext(device); + GL dummyGL = WindowsGLContextFactory.getDummyGL(device); int recommendedPixelFormat = -1; boolean haveWGLChoosePixelFormatARB = false; boolean haveWGLARBMultisample = false; @@ -286,6 +289,19 @@ public abstract class WindowsGLContext extends GLContext { } } } + Rectangle rect = config.getBounds(); + long dc = 0; + long rc = 0; + boolean freeWGLC = false; + if( dummyGL != null ) { + dc = WindowsGLContextFactory.getDummyGLContext( device ).hdc; + rc = WindowsGLContextFactory.getDummyGLContext( device ).hglrc; + if( !WGL.wglMakeCurrent( dc, rc ) ) { + System.err.println("Error Making WGLC Current: " + WGL.GetLastError() ); + } else { + freeWGLC = true; + } + } if (dummyGL != null && haveWGLChoosePixelFormatARB) { int[] iattributes = new int [2 * MAX_ATTRIBS]; int[] iresults = new int [2 * MAX_ATTRIBS]; @@ -365,6 +381,11 @@ public abstract class WindowsGLContext extends GLContext { System.err.println("Used wglChoosePixelFormatARB to recommend pixel format " + recommendedPixelFormat); } } + } else { + if (DEBUG) { + System.err.println("wglChoosePixelFormatARB failed: " + WGL.GetLastError() ); + Thread.dumpStack(); + } } if (DEBUG) { if (recommendedPixelFormat < 0) { @@ -388,7 +409,7 @@ public abstract class WindowsGLContext extends GLContext { niattribs = 0; iattributes[0] = GL.WGL_NUMBER_PIXEL_FORMATS_ARB; if (!dummyGL.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, iresults)) { - throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB"); + throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB: " + WGL.GetLastError()); } numFormats = iresults[0]; // Should we be filtering out the pixel formats which aren't @@ -423,6 +444,9 @@ public abstract class WindowsGLContext extends GLContext { } availableCaps[i] = iattributes2GLCapabilities(iattributes, iresults, niattribs, true); } + if( freeWGLC ) { + WGL.wglMakeCurrent( 0, 0 ); + } } else { if (DEBUG) { System.err.println("Using ChoosePixelFormat because no wglChoosePixelFormatARB: dummyGL = " + dummyGL); @@ -456,7 +480,7 @@ public abstract class WindowsGLContext extends GLContext { } pixelFormat += 1; // one-base the index if (WGL.DescribePixelFormat(hdc, pixelFormat, pfd.size(), pfd) == 0) { - throw new GLException("Error re-describing the chosen pixel format"); + throw new GLException("Error re-describing the chosen pixel format: " + WGL.GetLastError()); } } else { // For now, use ChoosePixelFormat for offscreen surfaces until -- cgit v1.2.3