diff options
Diffstat (limited to 'src/net/java/games/jogl/impl/GLContext.java')
-rw-r--r-- | src/net/java/games/jogl/impl/GLContext.java | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/net/java/games/jogl/impl/GLContext.java b/src/net/java/games/jogl/impl/GLContext.java index 98b1c6065..eb7d21988 100644 --- a/src/net/java/games/jogl/impl/GLContext.java +++ b/src/net/java/games/jogl/impl/GLContext.java @@ -42,6 +42,7 @@ package net.java.games.jogl.impl; import java.awt.Component; import java.awt.EventQueue; import net.java.games.jogl.*; +import net.java.games.gluegen.runtime.*; public abstract class GLContext { protected static final boolean DEBUG = false; @@ -75,8 +76,10 @@ public abstract class GLContext { // All GLU interfaces eventually route calls down to gluRoot. It can be // static because GLU it doesn't actually need to own context, it just makes // GL calls and assumes some context is active. - protected static final GLU gluRoot = new GLUImpl(); - protected static GLU glu = gluRoot; // this is the context's GLU interface + protected static final GLUProcAddressTable gluProcAddressTable = new GLUProcAddressTable(); + protected static final GLU gluRoot = new GLUImpl(gluProcAddressTable); + protected static boolean haveResetGLUProcAddressTable; + protected GLU glu = gluRoot; // this is the context's GLU interface protected Thread renderingThread; protected Runnable deferredReshapeAction; @@ -282,6 +285,13 @@ public abstract class GLContext { */ protected void resetGLFunctionAvailability() { functionAvailability.flush(); + if (!haveResetGLUProcAddressTable) { + if (DEBUG) { + System.err.println("!!! Initializing GLU extension address table"); + } + resetProcAddressTable(gluProcAddressTable); + haveResetGLUProcAddressTable = true; // Only need to do this once globally + } } /** @@ -391,6 +401,40 @@ public abstract class GLContext { conditions cause a GLException to be thrown. */ protected abstract void swapBuffers() throws GLException; + /** 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); + } + } + } + + /** Dynamically looks up the given function. */ + protected abstract long dynamicLookupFunction(String glFuncName); + //---------------------------------------------------------------------- // Internals only below this point // |