diff options
author | Kenneth Russel <[email protected]> | 2003-06-26 13:21:12 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2003-06-26 13:21:12 +0000 |
commit | 0a6e191eaebcc8edc2611dbedab6fd04a615fc2f (patch) | |
tree | 7f8a9b8e88a6bc6662827d3f092b943b1ea893fb /src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java | |
parent | 2b54833bb15d6cae356fa0c5777d11e152d774cb (diff) |
Initial Mac OS X port of Jogl by Gerard Ziemski and Kenneth Russell,
subsuming the previous prototype implementation (no GLCanvas support)
done by Marc Downie.
Added user's guide (HTML format) under doc/userguide/index.html.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@13 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java')
-rw-r--r-- | src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java | 152 |
1 files changed, 117 insertions, 35 deletions
diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java index bcb33e602..23367c045 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java @@ -45,23 +45,33 @@ import net.java.games.gluegen.opengl.*; // for PROCADDRESS_VAR_PREFIX import net.java.games.jogl.*; import net.java.games.jogl.impl.*; -public abstract class MacOSXGLContext extends GLContext { - - public MacOSXGLContext(Component component, GLCapabilities capabilities, GLCapabilitiesChooser chooser) { +public abstract class MacOSXGLContext extends GLContext +{ + private static JAWT jawt; + protected long nsContext; // NSOpenGLContext + + public MacOSXGLContext(Component component, GLCapabilities capabilities, GLCapabilitiesChooser chooser) + { super(component, capabilities, chooser); } - - protected GL createGL() + + protected String mapToRealGLFunctionName(String glFunctionName) { - return new MacOSXGLImpl(this); + return glFunctionName; } - - protected String mapToRealGLFunctionName(String glFunctionName) { + + protected String mapToRealGLExtensionName(String glFunctionName) + { return glFunctionName; } - - protected abstract boolean isOffscreen(); + + protected boolean isFunctionAvailable(String glFunctionName) + { + return super.isFunctionAvailable(glFunctionName); + } + protected abstract boolean isOffscreen(); + public abstract int getOffscreenContextBufferedImageType(); public abstract int getOffscreenContextReadBuffer(); @@ -69,42 +79,114 @@ public abstract class MacOSXGLContext extends GLContext { public abstract boolean offscreenImageNeedsVerticalFlip(); /** - * Creates and initializes an appropriate OpenGl context. Should only be + * Creates and initializes an appropriate OpenGl nsContext. Should only be * called by {@link makeCurrent(Runnable)}. */ protected abstract void create(); - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException + + protected abstract boolean makeCurrent(Runnable initAction) throws GLException; + + protected abstract void free() throws GLException; + + protected abstract void swapBuffers() throws GLException; + + + protected void resetGLFunctionAvailability() { - throw new RuntimeException(" FIXME: not implemented "); + super.resetGLFunctionAvailability(); + resetGLProcAddressTable(); } + + protected void resetGLProcAddressTable() + { + if (DEBUG) { + System.err.println("!!! Initializing OpenGL extension address table"); + } - protected synchronized void free() throws GLException { - throw new RuntimeException(" FIXME: not implemented "); - } - - protected abstract void swapBuffers() throws GLException; + net.java.games.jogl.impl.ProcAddressTable table = getGLProcAddressTable(); + + // if GL is no longer an interface, we'll have to re-implement the code + // below so it only iterates through gl methods (a non-interface might + // have constructors, custom methods, etc). For now we assume all methods + // will be gl methods. + GL gl = getGL(); + 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(GLEmitter.PROCADDRESS_VAR_PREFIX)) + { + // not a proc address variable + continue; + } + int startOfMethodName = GLEmitter.PROCADDRESS_VAR_PREFIX.length(); + String glFuncName = addressFieldName.substring(startOfMethodName); + try + { + java.lang.reflect.Field addressField = tableClass.getDeclaredField(addressFieldName); + assert(addressField.getType() == Long.TYPE); + // get the current value of the proc address variable in the table object + long oldProcAddress = addressField.getLong(table); + long newProcAddress = CGL.getProcAddress(glFuncName); + /* + System.err.println( + "!!! Address=" + (newProcAddress == 0 + ? "<NULL> " + : ("0x" + + Long.toHexString(newProcAddress))) + + "\tGL func: " + glFuncName); + */ + // set the current value of the proc address variable in the table object + addressField.setLong(gl, newProcAddress); + } catch (Exception e) { + throw new GLException( + "Cannot get GL proc address for method \"" + + glFuncName + "\": Couldn't get value of field \"" + addressFieldName + + "\" in class " + tableClass.getName(), e); + } + } - protected void resetGLFunctionAvailability() { - throw new RuntimeException(" FIXME: not implemented "); } - - protected void resetGLProcAddressTable() { - throw new RuntimeException(" FIXME: not implemented "); - } - - public net.java.games.jogl.impl.ProcAddressTable getGLProcAddressTable() { - throw new RuntimeException(" FIXME: not implemented "); + + public net.java.games.jogl.impl.ProcAddressTable getGLProcAddressTable() + { + if (glProcAddressTable == null) { + // FIXME: cache ProcAddressTables by capability bits so we can + // share them among contexts with the same capabilities + glProcAddressTable = + new net.java.games.jogl.impl.ProcAddressTable(); + } + return glProcAddressTable; } - - public String getPlatformExtensionsString() { - throw new RuntimeException(" FIXME: not implemented "); + + public String getPlatformExtensionsString() + { + return ""; } - - protected boolean isFunctionAvailable(String glFunctionName) + + //---------------------------------------------------------------------- + // Internals only below this point + // + + // Table that holds the addresses of the native C-language entry points for + // OpenGL functions. + private net.java.games.jogl.impl.ProcAddressTable glProcAddressTable; + + protected JAWT getJAWT() { - throw new RuntimeException(" FIXME: not implemented "); + if (jawt == null) + { + JAWT j = new JAWT(); + j.version(JAWTFactory.JAWT_VERSION_1_4); + if (!JAWTFactory.JAWT_GetAWT(j)) + { + throw new RuntimeException("Unable to initialize JAWT"); + } + jawt = j; + } + return jawt; } - } |