diff options
author | Kenneth Russel <[email protected]> | 2005-07-19 01:53:36 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-07-19 01:53:36 +0000 |
commit | 74adb7cc4ba59369964b562e3c84988f63025296 (patch) | |
tree | 0a850c1110afa161eeadb930c4035eb310b79f84 /src/net/java/games | |
parent | b01ac27a7d6ae4863490537e1ba8749795cd84de (diff) |
Added workaround for problem loading JAWT library on X11 platforms
before the AWT toolkit had been loaded. Added check for
jogl.gljpanel.nosw system property to diagnose problems with pbuffer
support. Fixed bootstrapping problem with GLX where its function
pointer table needed to be initialized before the first OpenGL context
was created in the case where a pbuffer was the first thing created.
Moved helper functions for resetting proc address table and dynamic
function lookup to GLDrawableFactoryImpl from GLContextImpl.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@331 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games')
10 files changed, 110 insertions, 89 deletions
diff --git a/src/net/java/games/jogl/GLJPanel.java b/src/net/java/games/jogl/GLJPanel.java index c7024928e..c094c8946 100644 --- a/src/net/java/games/jogl/GLJPanel.java +++ b/src/net/java/games/jogl/GLJPanel.java @@ -110,6 +110,8 @@ public final class GLJPanel extends JPanel implements GLAutoDrawable { // Implementation using pbuffers private static boolean hardwareAccelerationDisabled = Debug.isPropertyDefined("jogl.gljpanel.nohw"); + private static boolean softwareRenderingDisabled = + Debug.isPropertyDefined("jogl.gljpanel.nosw"); private GLPbuffer pbuffer; private int pbufferWidth = 256; private int pbufferHeight = 256; @@ -423,20 +425,28 @@ public final class GLJPanel extends JPanel implements GLAutoDrawable { isInitialized = true; return; } catch (GLException e) { + if (DEBUG) { + e.printStackTrace(); + System.err.println("GLJPanel: Falling back on software rendering because of problems creating pbuffer"); + } hardwareAccelerationDisabled = true; } } else { - if (VERBOSE) { + if (DEBUG) { System.err.println("GLJPanel: Falling back on software rendering because no pbuffer support"); } - // If the heavyweight reports that it can't create an - // offscreen drawable (pbuffer), don't try again the next - // time, and fall through to the software rendering path + // If the factory reports that it can't create a pbuffer, + // don't try again the next time, and fall through to the + // software rendering path hardwareAccelerationDisabled = true; } } + if (softwareRenderingDisabled) { + throw new GLException("Fallback to software rendering disabled by user"); + } + // Fall-through path: create an offscreen context instead offscreenDrawable = GLDrawableFactoryImpl.getFactoryImpl().createOffscreenDrawable(offscreenCaps, chooser); offscreenDrawable.setSize(Math.max(1, panelWidth), Math.max(1, panelHeight)); diff --git a/src/net/java/games/jogl/impl/GLContextImpl.java b/src/net/java/games/jogl/impl/GLContextImpl.java index 6094d6795..8e29633c7 100755 --- a/src/net/java/games/jogl/impl/GLContextImpl.java +++ b/src/net/java/games/jogl/impl/GLContextImpl.java @@ -183,37 +183,9 @@ public abstract class GLContextImpl extends GLContext { /** Helper routine which resets a ProcAddressTable generated by the GLEmitter by looking up anew all of its function pointers. */ protected void resetProcAddressTable(Object table) { - Class tableClass = table.getClass(); - java.lang.reflect.Field[] fields = tableClass.getDeclaredFields(); - - for (int i = 0; i < fields.length; ++i) { - String addressFieldName = fields[i].getName(); - if (!addressFieldName.startsWith(ProcAddressHelper.PROCADDRESS_VAR_PREFIX)) { - // not a proc address variable - continue; - } - int startOfMethodName = ProcAddressHelper.PROCADDRESS_VAR_PREFIX.length(); - String glFuncName = addressFieldName.substring(startOfMethodName); - try { - java.lang.reflect.Field addressField = tableClass.getDeclaredField(addressFieldName); - assert(addressField.getType() == Long.TYPE); - long newProcAddress = dynamicLookupFunction(glFuncName); - // set the current value of the proc address variable in the table object - addressField.setLong(table, newProcAddress); - if (DEBUG) { - // System.err.println(glFuncName + " = 0x" + Long.toHexString(newProcAddress)); - } - } catch (Exception e) { - throw new GLException("Cannot get GL proc address for method \"" + - glFuncName + "\": Couldn't set value of field \"" + addressFieldName + - "\" in class " + tableClass.getName(), e); - } - } + GLDrawableFactoryImpl.getFactoryImpl().resetProcAddressTable(table); } - /** Dynamically looks up the given function. */ - protected abstract long dynamicLookupFunction(String glFuncName); - /** Indicates whether the underlying OpenGL context has been created. This is used to manage sharing of display lists and textures between contexts. */ diff --git a/src/net/java/games/jogl/impl/GLDrawableFactoryImpl.java b/src/net/java/games/jogl/impl/GLDrawableFactoryImpl.java index be246db4e..b8c6a126c 100755 --- a/src/net/java/games/jogl/impl/GLDrawableFactoryImpl.java +++ b/src/net/java/games/jogl/impl/GLDrawableFactoryImpl.java @@ -42,6 +42,7 @@ package net.java.games.jogl.impl; import java.awt.Component; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; +import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX import net.java.games.jogl.*; /** Extends GLDrawableFactory with a few methods for handling @@ -56,6 +57,37 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { public abstract GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, GLCapabilitiesChooser chooser); + /** Helper routine which resets a ProcAddressTable generated by the + GLEmitter by looking up anew all of its function pointers. */ + public void resetProcAddressTable(Object table) { + Class tableClass = table.getClass(); + java.lang.reflect.Field[] fields = tableClass.getDeclaredFields(); + + for (int i = 0; i < fields.length; ++i) { + String addressFieldName = fields[i].getName(); + if (!addressFieldName.startsWith(ProcAddressHelper.PROCADDRESS_VAR_PREFIX)) { + // not a proc address variable + continue; + } + int startOfMethodName = ProcAddressHelper.PROCADDRESS_VAR_PREFIX.length(); + String glFuncName = addressFieldName.substring(startOfMethodName); + try { + java.lang.reflect.Field addressField = tableClass.getDeclaredField(addressFieldName); + assert(addressField.getType() == Long.TYPE); + long newProcAddress = dynamicLookupFunction(glFuncName); + // set the current value of the proc address variable in the table object + addressField.setLong(table, newProcAddress); + } catch (Exception e) { + throw new GLException("Cannot get GL proc address for method \"" + + glFuncName + "\": Couldn't set value of field \"" + addressFieldName + + "\" in class " + tableClass.getName(), e); + } + } + } + + /** Dynamically looks up the given function. */ + public abstract long dynamicLookupFunction(String glFuncName); + public static GLDrawableFactoryImpl getFactoryImpl() { return (GLDrawableFactoryImpl) getFactory(); } diff --git a/src/net/java/games/jogl/impl/NativeLibLoader.java b/src/net/java/games/jogl/impl/NativeLibLoader.java index 54d37f6ce..31fec96a2 100644 --- a/src/net/java/games/jogl/impl/NativeLibLoader.java +++ b/src/net/java/games/jogl/impl/NativeLibLoader.java @@ -39,6 +39,7 @@ package net.java.games.jogl.impl; +import java.awt.Toolkit; import java.security.*; public class NativeLibLoader { @@ -60,6 +61,10 @@ public class NativeLibLoader { boolean isOSX = System.getProperty("os.name").equals("Mac OS X"); if (!isOSX) { try { + // On X11 systems, toolkit must be loaded before + // trying to resolve JAWT in order for libmawt.so to + // be found properly + Toolkit.getDefaultToolkit(); System.loadLibrary("jawt"); } catch (UnsatisfiedLinkError e) { // Accessibility technologies load JAWT themselves; safe to continue diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java index f6b7cebf1..039194f9a 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java @@ -41,7 +41,6 @@ package net.java.games.jogl.impl.macosx; import java.awt.Component; import java.util.*; -import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX import net.java.games.jogl.*; import net.java.games.jogl.impl.*; @@ -169,10 +168,6 @@ public abstract class MacOSXGLContext extends GLContextImpl } } - protected long dynamicLookupFunction(String glFuncName) { - return CGL.getProcAddress(glFuncName); - } - public boolean isCreated() { return (nsContext != 0); } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLDrawableFactory.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLDrawableFactory.java index 7c703e542..4935da0b2 100755 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLDrawableFactory.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLDrawableFactory.java @@ -102,6 +102,10 @@ public class MacOSXGLDrawableFactory extends GLDrawableFactoryImpl { return (GLPbuffer) returnList.get(0); } + public long dynamicLookupFunction(String glFuncName) { + return CGL.getProcAddress(glFuncName); + } + private void maybeDoSingleThreadedWorkaround(Runnable action) { if (SingleThreadedWorkaround.doWorkaround() && !EventQueue.isDispatchThread()) { try { diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java index 1c0365571..532483c68 100644 --- a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java +++ b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java @@ -40,7 +40,6 @@ package net.java.games.jogl.impl.windows; import java.util.*; -import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX import net.java.games.jogl.*; import net.java.games.jogl.impl.*; @@ -54,8 +53,6 @@ public class WindowsGLContext extends GLContextImpl { // Table that holds the addresses of the native C-language entry points for // OpenGL functions. private GLProcAddressTable glProcAddressTable; - // Handle to GLU32.dll - private long hglu32; static { functionNameMap = new HashMap(); @@ -184,21 +181,6 @@ public class WindowsGLContext extends GLContextImpl { } } - protected long dynamicLookupFunction(String glFuncName) { - long res = WGL.wglGetProcAddress(glFuncName); - if (res == 0) { - // GLU routines aren't known to the OpenGL function lookup - if (hglu32 == 0) { - hglu32 = WGL.LoadLibraryA("GLU32"); - if (hglu32 == 0) { - throw new GLException("Error loading GLU32.DLL"); - } - } - res = WGL.GetProcAddress(hglu32, glFuncName); - } - return res; - } - public boolean isCreated() { return (hglrc != 0); } diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLDrawableFactory.java b/src/net/java/games/jogl/impl/windows/WindowsGLDrawableFactory.java index ebaf80394..b29bcf157 100755 --- a/src/net/java/games/jogl/impl/windows/WindowsGLDrawableFactory.java +++ b/src/net/java/games/jogl/impl/windows/WindowsGLDrawableFactory.java @@ -57,6 +57,10 @@ public class WindowsGLDrawableFactory extends GLDrawableFactoryImpl { private static final boolean DEBUG = Debug.debug("WindowsGLDrawableFactory"); private static final boolean VERBOSE = Debug.verbose(); + // Handle to GLU32.dll + // FIXME: this should go away once we delete support for the C GLU library + private long hglu32; + static { NativeLibLoader.load(); @@ -213,6 +217,21 @@ public class WindowsGLDrawableFactory extends GLDrawableFactoryImpl { return (GLPbuffer) returnList.get(0); } + public long dynamicLookupFunction(String glFuncName) { + long res = WGL.wglGetProcAddress(glFuncName); + if (res == 0) { + // GLU routines aren't known to the OpenGL function lookup + if (hglu32 == 0) { + hglu32 = WGL.LoadLibraryA("GLU32"); + if (hglu32 == 0) { + throw new GLException("Error loading GLU32.DLL"); + } + } + res = WGL.GetProcAddress(hglu32, glFuncName); + } + return res; + } + static String wglGetLastError() { int err = WGL.GetLastError(); String detail = null; diff --git a/src/net/java/games/jogl/impl/x11/X11GLContext.java b/src/net/java/games/jogl/impl/x11/X11GLContext.java index 15c1c8733..97f1b3593 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11GLContext.java @@ -40,9 +40,7 @@ package net.java.games.jogl.impl.x11; import java.awt.Component; -import java.security.*; import java.util.*; -import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX import net.java.games.jogl.*; import net.java.games.jogl.impl.*; @@ -55,30 +53,16 @@ public abstract class X11GLContext extends GLContextImpl { // Table that holds the addresses of the native C-language entry points for // OpenGL functions. private GLProcAddressTable glProcAddressTable; - private static boolean haveResetGLXProcAddressTable; // Cache the most recent value of the "display" variable (which we // only guarantee to be valid in between makeCurrent / free pairs) // so that we can implement displayImpl() (which must be done when // the context is not current) protected long mostRecentDisplay; - // There is currently a bug on Linux/AMD64 distributions in glXGetProcAddressARB - protected static boolean isLinuxAMD64; static { functionNameMap = new HashMap(); functionNameMap.put("glAllocateMemoryNV", "glXAllocateMemoryNV"); functionNameMap.put("glFreeMemoryNV", "glXFreeMemoryNV"); - - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String os = System.getProperty("os.name").toLowerCase(); - String arch = System.getProperty("os.arch").toLowerCase(); - if (os.startsWith("linux") && arch.equals("amd64")) { - isLinuxAMD64 = true; - } - return null; - } - }); } public X11GLContext(X11GLDrawable drawable, @@ -180,18 +164,6 @@ public abstract class X11GLContext extends GLContextImpl { unlockAWT(); } - protected long dynamicLookupFunction(String glFuncName) { - long res = 0; - if (!isLinuxAMD64) { - res = GLX.glXGetProcAddressARB(glFuncName); - } - if (res == 0) { - // GLU routines aren't known to the OpenGL function lookup - res = GLX.dlsym(glFuncName); - } - return res; - } - public boolean isCreated() { return (context != 0); } @@ -202,10 +174,6 @@ public abstract class X11GLContext extends GLContextImpl { System.err.println("!!! Initializing OpenGL extension address table"); } resetProcAddressTable(getGLProcAddressTable()); - - if (!haveResetGLXProcAddressTable) { - resetProcAddressTable(GLX.getGLXProcAddressTable()); - } } public GLProcAddressTable getGLProcAddressTable() { @@ -222,7 +190,8 @@ public abstract class X11GLContext extends GLContextImpl { throw new GLException("Context not current"); } if (!glXQueryExtensionsStringInitialized) { - glXQueryExtensionsStringAvailable = (dynamicLookupFunction("glXQueryExtensionsString") != 0); + glXQueryExtensionsStringAvailable = + (GLDrawableFactoryImpl.getFactoryImpl().dynamicLookupFunction("glXQueryExtensionsString") != 0); glXQueryExtensionsStringInitialized = true; } if (glXQueryExtensionsStringAvailable) { diff --git a/src/net/java/games/jogl/impl/x11/X11GLDrawableFactory.java b/src/net/java/games/jogl/impl/x11/X11GLDrawableFactory.java index 2db572f6d..49db6230c 100755 --- a/src/net/java/games/jogl/impl/x11/X11GLDrawableFactory.java +++ b/src/net/java/games/jogl/impl/x11/X11GLDrawableFactory.java @@ -44,6 +44,7 @@ import java.awt.EventQueue; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.lang.reflect.InvocationTargetException; +import java.security.*; import java.util.ArrayList; import java.util.List; import net.java.games.jogl.*; @@ -52,8 +53,28 @@ import net.java.games.jogl.impl.*; public class X11GLDrawableFactory extends GLDrawableFactoryImpl { private static final boolean DEBUG = Debug.debug("X11GLDrawableFactory"); + // There is currently a bug on Linux/AMD64 distributions in glXGetProcAddressARB + private static boolean isLinuxAMD64; + static { NativeLibLoader.load(); + + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String os = System.getProperty("os.name").toLowerCase(); + String arch = System.getProperty("os.arch").toLowerCase(); + if (os.startsWith("linux") && arch.equals("amd64")) { + isLinuxAMD64 = true; + } + return null; + } + }); + } + + public X11GLDrawableFactory() { + // Must initialize GLX support eagerly in case a pbuffer is the + // first thing instantiated + resetProcAddressTable(GLX.getGLXProcAddressTable()); } private static final int MAX_ATTRIBS = 128; @@ -209,6 +230,18 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl { return (GLPbuffer) returnList.get(0); } + public long dynamicLookupFunction(String glFuncName) { + long res = 0; + if (!isLinuxAMD64) { + res = GLX.glXGetProcAddressARB(glFuncName); + } + if (res == 0) { + // GLU routines aren't known to the OpenGL function lookup + res = GLX.dlsym(glFuncName); + } + return res; + } + public static GLCapabilities xvi2GLCapabilities(long display, XVisualInfo info) { int[] tmp = new int[1]; int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp, 0); |