diff options
author | Kenneth Russel <[email protected]> | 2005-10-24 19:21:03 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-10-24 19:21:03 +0000 |
commit | d6f9dbc493df725d3d574403549de142c5e1222a (patch) | |
tree | 8eb152b0627f8d1897a27c5204d6ce2efb4963e4 /src/net/java/games/jogl/impl/x11 | |
parent | 42843c3290d64c41c9c8a18b93f5ad3c00d35ddc (diff) |
Merged JSR-231 branch on to the main JOGL trunk. The main trunk now
contains the evolving JSR-231 Reference Implementation and the JSR-231
branch is permanently closed.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@401 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/impl/x11')
6 files changed, 0 insertions, 1534 deletions
diff --git a/src/net/java/games/jogl/impl/x11/X11GLContext.java b/src/net/java/games/jogl/impl/x11/X11GLContext.java deleted file mode 100644 index 53f44101f..000000000 --- a/src/net/java/games/jogl/impl/x11/X11GLContext.java +++ /dev/null @@ -1,410 +0,0 @@ -/* - * 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.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.*; - -public abstract class X11GLContext extends GLContext { - protected long display; - protected long drawable; - protected long visualID; - protected long context; - private boolean glXQueryExtensionsStringInitialized; - private boolean glXQueryExtensionsStringAvailable; - private static final Map/*<String, String>*/ functionNameMap; - private boolean isGLX13; - // 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(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(component, capabilities, chooser, shareWith); - } - - protected GL createGL() - { - return new X11GLImpl(this); - } - - protected String mapToRealGLFunctionName(String glFunctionName) { - String lookup = (String) functionNameMap.get(glFunctionName); - if (lookup != null) { - return lookup; - } - return glFunctionName; - } - - protected String mapToRealGLExtensionName(String glExtensionName) { - return glExtensionName; - } - - protected abstract boolean isOffscreen(); - - public int getOffscreenContextWidth() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextHeight() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public abstract int getOffscreenContextReadBuffer(); - - public abstract boolean offscreenImageNeedsVerticalFlip(); - - public synchronized void setRenderingThread(Thread currentThreadOrNull, Runnable initAction) { - this.willSetRenderingThread = false; - // FIXME: the JAWT on X11 grabs the AWT lock while the - // DrawingSurface is locked, which means that no other events can - // be processed. Currently we handle this by preventing the - // effects of setRenderingThread. We should figure out a better - // solution that is reasonably robust. Must file a bug to be fixed - // in the 1.5 JAWT. - } - - /** - * Creates and initializes an appropriate OpenGl context. Should only be - * called by {@link makeCurrent(Runnable)}. - */ - protected abstract void create(); - - public boolean isExtensionAvailable(String glExtensionName) { - if (glExtensionName.equals("GL_ARB_pbuffer") || - glExtensionName.equals("GL_ARB_pixel_format")) { - return isGLX13; - } - return super.isExtensionAvailable(glExtensionName); - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - boolean created = false; - if (context == 0) { - create(); - if (DEBUG) { - System.err.println("!!! Created GL context for " + getClass().getName()); - } - created = true; - } - if (drawable == 0) { - throw new GLException("Unable to make context current; drawable was null"); - } - - // FIXME: this cast to int would be wrong on 64-bit platforms - // where the argument type to glXMakeCurrent would change (should - // probably make GLXDrawable, and maybe XID, Opaque as long) - if (!GLX.glXMakeCurrent(display, (int) drawable, context)) { - throw new GLException("Error making context current"); - } - - if (created) { - resetGLFunctionAvailability(); - initAction.run(); - } - return true; - } - - protected synchronized void free() throws GLException { - if (!GLX.glXMakeCurrent(display, 0, 0)) { - throw new GLException("Error freeing OpenGL context"); - } - } - - protected void destroyImpl() throws GLException { - lockAWT(); - if (context != 0) { - GLX.glXDestroyContext(mostRecentDisplay, context); - if (DEBUG) { - System.err.println("!!! Destroyed OpenGL context " + context); - } - context = 0; - } - unlockAWT(); - } - - public abstract void swapBuffers() throws GLException; - - 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); - } - - protected void resetGLFunctionAvailability() { - super.resetGLFunctionAvailability(); - if (DEBUG) { - System.err.println("!!! Initializing OpenGL extension address table"); - } - resetProcAddressTable(getGLProcAddressTable()); - - if (!haveResetGLXProcAddressTable) { - resetProcAddressTable(GLX.getGLXProcAddressTable()); - } - - // Figure out whether we are running GLX version 1.3 or above and - // therefore have pbuffer support - if (display == 0) { - throw new GLException("Expected non-null DISPLAY for querying GLX version"); - } - int[] major = new int[1]; - int[] minor = new int[1]; - if (!GLX.glXQueryVersion(display, major, minor)) { - throw new GLException("glXQueryVersion failed"); - } - if (DEBUG) { - System.err.println("!!! GLX version: major " + major[0] + - ", minor " + minor[0]); - } - - // Work around bugs in ATI's Linux drivers where they report they - // only implement GLX version 1.2 but actually do support pbuffers - if (major[0] == 1 && minor[0] == 2) { - GL gl = getGL(); - String str = gl.glGetString(GL.GL_VENDOR); - if (str != null && str.indexOf("ATI") >= 0) { - isGLX13 = true; - return; - } - } - - isGLX13 = ((major[0] > 1) || (minor[0] > 2)); - } - - public GLProcAddressTable getGLProcAddressTable() { - if (glProcAddressTable == null) { - // FIXME: cache ProcAddressTables by capability bits so we can - // share them among contexts with the same capabilities - glProcAddressTable = new GLProcAddressTable(); - } - return glProcAddressTable; - } - - public synchronized String getPlatformExtensionsString() { - if (display == 0) { - throw new GLException("Context not current"); - } - if (!glXQueryExtensionsStringInitialized) { - glXQueryExtensionsStringAvailable = (dynamicLookupFunction("glXQueryExtensionsString") != 0); - glXQueryExtensionsStringInitialized = true; - } - if (glXQueryExtensionsStringAvailable) { - lockAWT(); - try { - String ret = GLX.glXQueryExtensionsString(display, GLX.DefaultScreen(display)); - if (DEBUG) { - System.err.println("!!! GLX extensions: " + ret); - } - return ret; - } finally { - unlockAWT(); - } - } else { - return ""; - } - } - - protected boolean isFunctionAvailable(String glFunctionName) - { - boolean available = super.isFunctionAvailable(glFunctionName); - - // Sanity check for implementations that use proc addresses for run-time - // linking: if the function IS available, then make sure there's a proc - // address for it if it's an extension or not part of the OpenGL 1.1 core - // (post GL 1.1 functions are run-time linked on windows). - assert(!available || - (getGLProcAddressTable().getAddressFor(mapToRealGLFunctionName(glFunctionName)) != 0 || - FunctionAvailabilityCache.isPartOfGLCore("1.1", mapToRealGLFunctionName(glFunctionName))) - ); - - return available; - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - protected JAWT getJAWT() { - return X11GLContextFactory.getJAWT(); - } - - protected XVisualInfo chooseVisual() { - if (!isOffscreen()) { - // The visual has already been chosen by the time we get here; - // it's specified by the GraphicsConfiguration of the - // GLCanvas. Fortunately, the JAWT supplies the visual ID for - // the component in a portable fashion, so all we have to do is - // use XGetVisualInfo with a VisualIDMask to get the - // corresponding XVisualInfo to pass into glXChooseVisual. - int[] count = new int[1]; - XVisualInfo template = new XVisualInfo(); - // FIXME: probably not 64-bit clean - template.visualid((int) visualID); - XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualIDMask, template, count); - if (infos == null || infos.length == 0) { - throw new GLException("Error while getting XVisualInfo for visual ID " + visualID); - } - // FIXME: the storage for the infos array is leaked (should - // clean it up somehow when we're done with the visual we're - // returning) - return infos[0]; - } else { - // It isn't clear to me whether we need this much code to handle - // the offscreen case, where we're creating a pixmap into which - // to render...this is what we (incorrectly) used to do for the - // onscreen case - - int screen = 0; // FIXME: provide way to specify this? - XVisualInfo vis = null; - int[] count = new int[1]; - XVisualInfo template = new XVisualInfo(); - template.screen(screen); - XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count); - if (infos == null) { - throw new GLException("Error while enumerating available XVisualInfos"); - } - GLCapabilities[] caps = new GLCapabilities[infos.length]; - for (int i = 0; i < infos.length; i++) { - caps[i] = X11GLContextFactory.xvi2GLCapabilities(display, infos[i]); - } - int chosen = chooser.chooseCapabilities(capabilities, caps, -1); - if (chosen < 0 || chosen >= caps.length) { - throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); - } - if (DEBUG) { - System.err.println("Chosen visual (" + chosen + "):"); - System.err.println(caps[chosen]); - } - vis = infos[chosen]; - if (vis == null) { - throw new GLException("GLCapabilitiesChooser chose an invalid visual"); - } - // FIXME: the storage for the infos array is leaked (should - // clean it up somehow when we're done with the visual we're - // returning) - - return vis; - } - } - - protected long createContext(XVisualInfo vis, boolean onscreen) { - X11GLContext other = (X11GLContext) GLContextShareSet.getShareContext(this); - long share = 0; - if (other != null) { - share = other.getContext(); - if (share == 0) { - throw new GLException("GLContextShareSet returned an invalid OpenGL context"); - } - } - long res = GLX.glXCreateContext(display, vis, share, onscreen); - if (res != 0) { - GLContextShareSet.contextCreated(this); - } - return res; - } - - // Helper routine for the overridden create() to call - protected void chooseVisualAndCreateContext(boolean onscreen) { - XVisualInfo vis = chooseVisual(); - context = createContext(vis, onscreen); - if (context == 0) { - throw new GLException("Unable to create OpenGL context"); - } - } - - protected long getContext() { - return context; - } - - // These synchronization primitives prevent the AWT from making - // requests from the X server asynchronously to this code. - protected void lockAWT() { - X11GLContextFactory.lockAWT(); - } - - protected void unlockAWT() { - X11GLContextFactory.unlockAWT(); - } -} diff --git a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java b/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java deleted file mode 100644 index a1b299478..000000000 --- a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java +++ /dev/null @@ -1,288 +0,0 @@ -/* - * 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.x11; - -import java.awt.Component; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class X11GLContextFactory extends GLContextFactory { - static { - NativeLibLoader.load(); - } - - private static final int MAX_ATTRIBS = 128; - - public GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GraphicsDevice device) { - int screen = X11SunJDKReflection.graphicsDeviceGetScreen(device); - // Until we have a rock-solid visual selection algorithm written - // in pure Java, we're going to provide the underlying window - // system's selection to the chooser as a hint - - int[] attribs = glCapabilities2AttribList(capabilities, isMultisampleAvailable()); - XVisualInfo[] infos = null; - GLCapabilities[] caps = null; - int recommendedIndex = -1; - lockAWT(); - try { - long display = getDisplayConnection(); - XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs); - int[] count = new int[1]; - XVisualInfo template = new XVisualInfo(); - template.screen(screen); - infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count); - if (infos == null) { - throw new GLException("Error while enumerating available XVisualInfos"); - } - caps = new GLCapabilities[infos.length]; - for (int i = 0; i < infos.length; i++) { - caps[i] = xvi2GLCapabilities(display, infos[i]); - // Attempt to find the visual chosen by glXChooseVisual - if (recommendedVis != null && recommendedVis.visualid() == infos[i].visualid()) { - recommendedIndex = i; - } - } - } finally { - unlockAWT(); - } - int chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); - if (chosen < 0 || chosen >= caps.length) { - throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); - } - XVisualInfo vis = infos[chosen]; - if (vis == null) { - throw new GLException("GLCapabilitiesChooser chose an invalid visual"); - } - // FIXME: need to look at glue code and see type of this field - long visualID = vis.visualid(); - // FIXME: the storage for the infos array, as well as that for the - // recommended visual, is leaked; should free them here with XFree() - - // Now figure out which GraphicsConfiguration corresponds to this - // visual by matching the visual ID - GraphicsConfiguration[] configs = device.getConfigurations(); - for (int i = 0; i < configs.length; i++) { - GraphicsConfiguration config = configs[i]; - if (config != null) { - if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) { - return config; - } - } - } - - // Either we weren't able to reflectively introspect on the - // X11GraphicsConfig or something went wrong in the steps above; - // we're going to return null without signaling an error condition - // in this case (although we should distinguish between the two - // and possibly report more of an error in the latter case) - return null; - } - - public GLContext createGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - if (component != null) { - return new X11OnscreenGLContext(component, capabilities, chooser, shareWith); - } else { - return new X11OffscreenGLContext(capabilities, chooser, shareWith); - } - } - - public static GLCapabilities xvi2GLCapabilities(long display, XVisualInfo info) { - int[] tmp = new int[1]; - int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp); - if (val == 0) { - // Visual does not support OpenGL - return null; - } - val = glXGetConfig(display, info, GLX.GLX_RGBA, tmp); - if (val == 0) { - // Visual does not support RGBA - return null; - } - GLCapabilities res = new GLCapabilities(); - res.setDoubleBuffered(glXGetConfig(display, info, GLX.GLX_DOUBLEBUFFER, tmp) != 0); - res.setStereo (glXGetConfig(display, info, GLX.GLX_STEREO, tmp) != 0); - // Note: use of hardware acceleration is determined by - // glXCreateContext, not by the XVisualInfo. Optimistically claim - // that all GLCapabilities have the capability to be hardware - // accelerated. - res.setHardwareAccelerated(true); - res.setDepthBits (glXGetConfig(display, info, GLX.GLX_DEPTH_SIZE, tmp)); - res.setStencilBits (glXGetConfig(display, info, GLX.GLX_STENCIL_SIZE, tmp)); - res.setRedBits (glXGetConfig(display, info, GLX.GLX_RED_SIZE, tmp)); - res.setGreenBits (glXGetConfig(display, info, GLX.GLX_GREEN_SIZE, tmp)); - res.setBlueBits (glXGetConfig(display, info, GLX.GLX_BLUE_SIZE, tmp)); - res.setAlphaBits (glXGetConfig(display, info, GLX.GLX_ALPHA_SIZE, tmp)); - res.setAccumRedBits (glXGetConfig(display, info, GLX.GLX_ACCUM_RED_SIZE, tmp)); - res.setAccumGreenBits(glXGetConfig(display, info, GLX.GLX_ACCUM_GREEN_SIZE, tmp)); - res.setAccumBlueBits (glXGetConfig(display, info, GLX.GLX_ACCUM_BLUE_SIZE, tmp)); - res.setAccumAlphaBits(glXGetConfig(display, info, GLX.GLX_ACCUM_ALPHA_SIZE, tmp)); - if (isMultisampleAvailable()) { - res.setSampleBuffers(glXGetConfig(display, info, GLX.GLX_SAMPLE_BUFFERS_ARB, tmp) != 0); - res.setNumSamples (glXGetConfig(display, info, GLX.GLX_SAMPLES_ARB, tmp)); - } - return res; - } - - public static int[] glCapabilities2AttribList(GLCapabilities caps, - boolean isMultisampleAvailable) { - int colorDepth = (caps.getRedBits() + - caps.getGreenBits() + - caps.getBlueBits()); - if (colorDepth < 15) { - throw new GLException("Bit depths < 15 (i.e., non-true-color) not supported"); - } - int[] res = new int[MAX_ATTRIBS]; - int idx = 0; - res[idx++] = GLX.GLX_RGBA; - if (caps.getDoubleBuffered()) { - res[idx++] = GLX.GLX_DOUBLEBUFFER; - } - if (caps.getStereo()) { - res[idx++] = GLX.GLX_STEREO; - } - res[idx++] = GLX.GLX_RED_SIZE; - res[idx++] = caps.getRedBits(); - res[idx++] = GLX.GLX_GREEN_SIZE; - res[idx++] = caps.getGreenBits(); - res[idx++] = GLX.GLX_BLUE_SIZE; - res[idx++] = caps.getBlueBits(); - res[idx++] = GLX.GLX_ALPHA_SIZE; - res[idx++] = caps.getAlphaBits(); - res[idx++] = GLX.GLX_DEPTH_SIZE; - res[idx++] = caps.getDepthBits(); - res[idx++] = GLX.GLX_STENCIL_SIZE; - res[idx++] = caps.getStencilBits(); - res[idx++] = GLX.GLX_ACCUM_RED_SIZE; - res[idx++] = caps.getAccumRedBits(); - res[idx++] = GLX.GLX_ACCUM_GREEN_SIZE; - res[idx++] = caps.getAccumGreenBits(); - res[idx++] = GLX.GLX_ACCUM_BLUE_SIZE; - res[idx++] = caps.getAccumBlueBits(); - if (isMultisampleAvailable && caps.getSampleBuffers()) { - res[idx++] = GL.GLX_SAMPLE_BUFFERS_ARB; - res[idx++] = GL.GL_TRUE; - res[idx++] = GL.GLX_SAMPLES_ARB; - res[idx++] = caps.getNumSamples(); - } - res[idx++] = 0; - return res; - } - - // JAWT access - private static JAWT jawt; - public static JAWT getJAWT() { - 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; - } - - public static void lockAWT() { - getJAWT().Lock(); - } - - public static void unlockAWT() { - getJAWT().Unlock(); - } - - // Display connection for use by visual selection algorithm and by all offscreen surfaces - private static long staticDisplay; - public static long getDisplayConnection() { - if (staticDisplay == 0) { - lockAWT(); - try { - staticDisplay = GLX.XOpenDisplay(null); - } finally { - unlockAWT(); - } - if (staticDisplay == 0) { - throw new GLException("Unable to open default display, needed for visual selection and offscreen surface handling"); - } - } - return staticDisplay; - } - - private static boolean checkedMultisample; - private static boolean multisampleAvailable; - public static boolean isMultisampleAvailable() { - if (!checkedMultisample) { - long display = getDisplayConnection(); - String exts = GLX.glXGetClientString(display, GLX.GLX_EXTENSIONS); - if (exts != null) { - multisampleAvailable = (exts.indexOf("GLX_ARB_multisample") >= 0); - } - checkedMultisample = true; - } - return multisampleAvailable; - } - - private static String glXGetConfigErrorCode(int err) { - switch (err) { - case GLX.GLX_NO_EXTENSION: return "GLX_NO_EXTENSION"; - case GLX.GLX_BAD_SCREEN: return "GLX_BAD_SCREEN"; - case GLX.GLX_BAD_ATTRIBUTE: return "GLX_BAD_ATTRIBUTE"; - case GLX.GLX_BAD_VISUAL: return "GLX_BAD_VISUAL"; - default: return "Unknown error code " + err; - } - } - - public static int glXGetConfig(long display, XVisualInfo info, int attrib, int[] tmp) { - if (display == 0) { - throw new GLException("No display connection"); - } - int res = GLX.glXGetConfig(display, info, attrib, tmp); - if (res != 0) { - throw new GLException("glXGetConfig failed: error code " + glXGetConfigErrorCode(res)); - } - return tmp[0]; - } -} diff --git a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java b/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java deleted file mode 100644 index 8f0aa06a5..000000000 --- a/src/net/java/games/jogl/impl/x11/X11OffscreenGLContext.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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.x11; - -import java.awt.image.BufferedImage; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class X11OffscreenGLContext extends X11GLContext { - private long pixmap; - private boolean isDoubleBuffered; - // Width and height of the underlying bitmap - private int width; - private int height; - - public X11OffscreenGLContext(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(null, capabilities, chooser, shareWith); - } - - protected GL createGL() - { - return new X11GLImpl(this); - } - - protected boolean isOffscreen() { - return true; - } - - public int getOffscreenContextWidth() { - return width; - } - - public int getOffscreenContextHeight() { - return height; - } - - public int getOffscreenContextPixelDataType() { - return GL.GL_UNSIGNED_BYTE; - } - - public int getOffscreenContextReadBuffer() { - if (isDoubleBuffered) { - return GL.GL_BACK; - } - return GL.GL_FRONT; - } - - public boolean offscreenImageNeedsVerticalFlip() { - // There doesn't seem to be a way to do this in the construction - // of the Pixmap or GLXPixmap - return true; - } - - public boolean canCreatePbufferContext() { - // For now say no - return false; - } - - public synchronized GLContext createPbufferContext(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 synchronized boolean makeCurrent(Runnable initAction) throws GLException { - display = X11GLContextFactory.getDisplayConnection(); - if (pendingOffscreenResize) { - if (pendingOffscreenWidth != width || pendingOffscreenHeight != height) { - if (context != 0) { - destroy(); - } - width = pendingOffscreenWidth; - height = pendingOffscreenHeight; - pendingOffscreenResize = false; - } - } - mostRecentDisplay = display; - return super.makeCurrent(initAction); - } - - public synchronized void swapBuffers() throws GLException { - } - - protected synchronized void free() throws GLException { - try { - super.free(); - } finally { - display = 0; - } - } - - protected void create() { - XVisualInfo vis = chooseVisual(); - int bitsPerPixel = vis.depth(); - - if (display == 0) { - throw new GLException("No active display"); - } - int screen = GLX.DefaultScreen(display); - pixmap = GLX.XCreatePixmap(display, (int) GLX.RootWindow(display, screen), width, height, bitsPerPixel); - if (pixmap == 0) { - throw new GLException("XCreatePixmap failed"); - } - drawable = GLX.glXCreateGLXPixmap(display, vis, pixmap); - if (drawable == 0) { - throw new GLException("glXCreateGLXPixmap failed"); - } - context = createContext(vis, false); - if (context == 0) { - throw new GLException("Unable to create OpenGL context"); - } - isDoubleBuffered = (X11GLContextFactory.glXGetConfig(display, vis, GLX.GLX_DOUBLEBUFFER, new int[1]) != 0); - } - - protected void destroyImpl() { - if (context != 0) { - super.destroyImpl(); - // Must destroy OpenGL context, pixmap and GLXPixmap - GLX.glXDestroyContext(display, context); - GLX.glXDestroyGLXPixmap(display, (int) drawable); - GLX.XFreePixmap(display, pixmap); - context = 0; - drawable = 0; - pixmap = 0; - GLContextShareSet.contextDestroyed(this); - } - } -} diff --git a/src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java b/src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java deleted file mode 100644 index 2fd340d79..000000000 --- a/src/net/java/games/jogl/impl/x11/X11OnscreenGLContext.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * 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.x11; - -import java.awt.Component; -import java.util.*; - -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class X11OnscreenGLContext extends X11GLContext { - // Variables for lockSurface/unlockSurface - private JAWT_DrawingSurface ds; - private JAWT_DrawingSurfaceInfo dsi; - private JAWT_X11DrawingSurfaceInfo x11dsi; - - // Variables for pbuffer support - List pbuffersToInstantiate = new ArrayList(); - - public X11OnscreenGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(component, capabilities, chooser, shareWith); - } - - protected GL createGL() - { - return new X11GLImpl(this); - } - - protected boolean isOffscreen() { - return false; - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - public boolean canCreatePbufferContext() { - // FIXME: should we gate this on GLX 1.3 being available? - return true; - } - - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - X11PbufferGLContext ctx = new X11PbufferGLContext(capabilities, initialWidth, initialHeight); - pbuffersToInstantiate.add(ctx); - return ctx; - } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - - public void setSwapInterval(int interval) { - GL gl = getGL(); - if (gl.isExtensionAvailable("GLX_SGI_swap_control")) { - gl.glXSwapIntervalSGI(interval); - } - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - try { - if (!lockSurface()) { - return false; - } - boolean ret = super.makeCurrent(initAction); - if (ret) { - // Instantiate any pending pbuffers - while (!pbuffersToInstantiate.isEmpty()) { - X11PbufferGLContext ctx = - (X11PbufferGLContext) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1); - ctx.createPbuffer(display, context, getGL()); - } - } - return ret; - } catch (RuntimeException e) { - try { - unlockSurface(); - } catch (Exception e2) { - // do nothing if unlockSurface throws - } - throw(e); - } - } - - protected synchronized void free() throws GLException { - try { - super.free(); - } finally { - unlockSurface(); - } - } - - public synchronized void swapBuffers() throws GLException { - // FIXME: this cast to int would be wrong on 64-bit platforms - // where the argument type to glXMakeCurrent would change (should - // probably make GLXDrawable, and maybe XID, Opaque as long) - GLX.glXSwapBuffers(display, (int) drawable); - } - - private boolean lockSurface() throws GLException { - if (drawable != 0) { - throw new GLException("Surface already locked"); - } - ds = getJAWT().GetDrawingSurface(component); - if (ds == null) { - // Widget not yet realized - return false; - } - int res = ds.Lock(); - if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { - throw new GLException("Unable to lock surface"); - } - // See whether the surface changed and if so destroy the old - // OpenGL context so it will be recreated - if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { - if (context != 0) { - GLX.glXDestroyContext(display, context); - context = 0; - } - } - dsi = ds.GetDrawingSurfaceInfo(); - if (dsi == null) { - // Widget not yet realized - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - return false; - } - x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo(); - display = x11dsi.display(); - drawable = x11dsi.drawable(); - visualID = x11dsi.visualID(); - if (display == 0 || drawable == 0) { - // Widget not yet realized - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - x11dsi = null; - display = 0; - drawable = 0; - visualID = 0; - return false; - } - mostRecentDisplay = display; - return true; - } - - private void unlockSurface() { - if (drawable == 0) { - throw new GLException("Surface already unlocked"); - } - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - x11dsi = null; - display = 0; - drawable = 0; - visualID = 0; - } - - protected void create() { - chooseVisualAndCreateContext(true); - } -} diff --git a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java b/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java deleted file mode 100644 index d9f18a760..000000000 --- a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * 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.x11; - -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class X11PbufferGLContext extends X11GLContext { - private static final boolean DEBUG = Debug.debug("X11PbufferGLContext"); - - private int initWidth; - private int initHeight; - - private long buffer; // GLXPbuffer - private GLXFBConfig fbConfig; - private int width; - private int height; - - // FIXME: kept around because we create the OpenGL context lazily to - // better integrate with the X11GLContext framework - private long parentContext; - - private static final int MAX_PFORMATS = 256; - private static final int MAX_ATTRIBS = 256; - - public X11PbufferGLContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { - super(null, capabilities, null, null); - this.initWidth = initialWidth; - this.initHeight = initialHeight; - if (initWidth <= 0 || initHeight <= 0) { - throw new GLException("Initial width and height of pbuffer must be positive (were (" + - initWidth + ", " + initHeight + "))"); - } - } - - public boolean canCreatePbufferContext() { - return false; - } - - public GLContext createPbufferContext(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"); - } - - public void releasePbufferFromTexture() { - // FIXME: figure out how to implement this - throw new GLException("Not yet implemented"); - } - - public void createPbuffer(long display, long parentContext, GL gl) { - if (display == 0) { - throw new GLException("Null display"); - } - - if (parentContext == 0) { - throw new GLException("Null parentContext"); - } - - if (capabilities.getOffscreenRenderToTexture()) { - throw new GLException("Render-to-texture pbuffers not supported yet on X11"); - } - - if (capabilities.getOffscreenRenderToTextureRectangle()) { - throw new GLException("Render-to-texture-rectangle pbuffers not supported yet on X11"); - } - - int[] iattributes = new int [2*MAX_ATTRIBS]; - float[] fattributes = new float[2*MAX_ATTRIBS]; - int nfattribs = 0; - int niattribs = 0; - - // Since we are trying to create a pbuffer, the GLXFBConfig we - // request (and subsequently use) must be "p-buffer capable". - iattributes[niattribs++] = GL.GLX_DRAWABLE_TYPE; - iattributes[niattribs++] = GL.GLX_PBUFFER_BIT; - - iattributes[niattribs++] = GL.GLX_RENDER_TYPE; - iattributes[niattribs++] = GL.GLX_RGBA_BIT; - - iattributes[niattribs++] = GLX.GLX_DOUBLEBUFFER; - if (capabilities.getDoubleBuffered()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - - iattributes[niattribs++] = GLX.GLX_DEPTH_SIZE; - iattributes[niattribs++] = capabilities.getDepthBits(); - - iattributes[niattribs++] = GLX.GLX_RED_SIZE; - iattributes[niattribs++] = capabilities.getRedBits(); - - iattributes[niattribs++] = GLX.GLX_GREEN_SIZE; - iattributes[niattribs++] = capabilities.getGreenBits(); - - iattributes[niattribs++] = GLX.GLX_BLUE_SIZE; - iattributes[niattribs++] = capabilities.getBlueBits(); - - iattributes[niattribs++] = GLX.GLX_ALPHA_SIZE; - iattributes[niattribs++] = capabilities.getAlphaBits(); - - if (capabilities.getStencilBits() > 0) { - iattributes[niattribs++] = GLX.GLX_STENCIL_SIZE; - iattributes[niattribs++] = capabilities.getStencilBits(); - } - - if (capabilities.getAccumRedBits() > 0 || - capabilities.getAccumGreenBits() > 0 || - capabilities.getAccumBlueBits() > 0) { - iattributes[niattribs++] = GLX.GLX_ACCUM_RED_SIZE; - iattributes[niattribs++] = capabilities.getAccumRedBits(); - iattributes[niattribs++] = GLX.GLX_ACCUM_GREEN_SIZE; - iattributes[niattribs++] = capabilities.getAccumGreenBits(); - iattributes[niattribs++] = GLX.GLX_ACCUM_BLUE_SIZE; - iattributes[niattribs++] = capabilities.getAccumBlueBits(); - } - - if (capabilities.getOffscreenFloatingPointBuffers()) { - if (!gl.isExtensionAvailable("GLX_NV_float_buffer")) { - throw new GLException("Floating-point pbuffers on X11 currently require NVidia hardware"); - } - iattributes[niattribs++] = GLX.GLX_FLOAT_COMPONENTS_NV; - iattributes[niattribs++] = GL.GL_TRUE; - } - - // FIXME: add FSAA support? Don't want to get into a situation - // where we have to retry the glXChooseFBConfig call if it fails - // due to a lack of an antialiased visual... - - iattributes[niattribs++] = 0; // null-terminate - - int screen = 0; // FIXME: provide way to specify this? - int[] nelementsTmp = new int[1]; - GLXFBConfig[] fbConfigs = GLX.glXChooseFBConfig(display, screen, iattributes, nelementsTmp); - if (fbConfigs == null || fbConfigs.length == 0 || fbConfigs[0] == null) { - throw new GLException("pbuffer creation error: glXChooseFBConfig() failed"); - } - // Note that we currently don't allow selection of anything but - // the first GLXFBConfig in the returned list - GLXFBConfig fbConfig = fbConfigs[0]; - int nelements = nelementsTmp[0]; - if (nelements <= 0) { - throw new GLException("pbuffer creation error: couldn't find a suitable frame buffer configuration"); - } - - if (DEBUG) { - System.err.println("Found " + fbConfigs.length + " matching GLXFBConfigs"); - System.err.println("Parameters of default one:"); - System.err.println("render type: 0x" + Integer.toHexString(queryFBConfig(display, fbConfig, GLX.GLX_RENDER_TYPE))); - System.err.println("rgba: " + ((queryFBConfig(display, fbConfig, GLX.GLX_RENDER_TYPE) & GLX.GLX_RGBA_BIT) != 0)); - System.err.println("r: " + queryFBConfig(display, fbConfig, GLX.GLX_RED_SIZE)); - System.err.println("g: " + queryFBConfig(display, fbConfig, GLX.GLX_GREEN_SIZE)); - System.err.println("b: " + queryFBConfig(display, fbConfig, GLX.GLX_BLUE_SIZE)); - System.err.println("a: " + queryFBConfig(display, fbConfig, GLX.GLX_ALPHA_SIZE)); - System.err.println("depth: " + queryFBConfig(display, fbConfig, GLX.GLX_DEPTH_SIZE)); - System.err.println("double buffered: " + queryFBConfig(display, fbConfig, GLX.GLX_DOUBLEBUFFER)); - } - - // Create the p-buffer. - niattribs = 0; - - iattributes[niattribs++] = GL.GLX_PBUFFER_WIDTH; - iattributes[niattribs++] = initWidth; - iattributes[niattribs++] = GL.GLX_PBUFFER_HEIGHT; - iattributes[niattribs++] = initHeight; - - iattributes[niattribs++] = 0; - - long tmpBuffer = GLX.glXCreatePbuffer(display, fbConfig, iattributes); - if (tmpBuffer == 0) { - // FIXME: query X error code for detail error message - throw new GLException("pbuffer creation error: glXCreatePbuffer() failed"); - } - - // Set up instance variables - this.display = display; - mostRecentDisplay = display; - this.parentContext = parentContext; - buffer = tmpBuffer; - this.fbConfig = fbConfig; - - // Determine the actual width and height we were able to create. - int[] tmp = new int[1]; - GLX.glXQueryDrawable(display, (int) buffer, GL.GLX_WIDTH, tmp); - width = tmp[0]; - GLX.glXQueryDrawable(display, (int) buffer, GL.GLX_HEIGHT, tmp); - height = tmp[0]; - - if (DEBUG) { - System.err.println("Created pbuffer " + width + " x " + height); - } - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - if (buffer == 0) { - // pbuffer not instantiated yet - return false; - } - - lockAWT(); - try { - boolean created = false; - if (context == 0) { - create(); - if (DEBUG) { - System.err.println("!!! Created GL context for " + getClass().getName()); - } - created = true; - } - - if (!GLX.glXMakeContextCurrent(display, buffer, buffer, context)) { - throw new GLException("Error making context current"); - } - - if (created) { - resetGLFunctionAvailability(); - initAction.run(); - } - return true; - } finally { - unlockAWT(); - } - } - - protected synchronized void free() throws GLException { - lockAWT(); - try { - if (!GLX.glXMakeContextCurrent(display, 0, 0, 0)) { - throw new GLException("Error freeing OpenGL context"); - } - } finally { - unlockAWT(); - } - } - - public void handleModeSwitch(long parentHdc, long parentHglrc) { - throw new GLException("Not yet implemented"); - } - - protected boolean isOffscreen() { - // FIXME: currently the only caller of this won't cause proper - // resizing of the pbuffer anyway. - return false; - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - protected void create() { - if (DEBUG) { - System.err.println("Creating context for pbuffer " + width + " x " + height); - } - - // Create a gl context for the p-buffer. - // FIXME: provide option to not share display lists with subordinate pbuffer? - context = GLX.glXCreateNewContext(display, fbConfig, GL.GLX_RGBA_TYPE, parentContext, true); - if (context == 0) { - throw new GLException("pbuffer creation error: glXCreateNewContext() failed"); - } - - if (DEBUG) { - System.err.println("Created context for pbuffer " + width + " x " + height); - } - } - - protected void destroyImpl() throws GLException { - lockAWT(); - try { - if (context != 0) { - super.destroyImpl(); - GLX.glXDestroyPbuffer(display, buffer); - buffer = 0; - } - } finally { - unlockAWT(); - } - } - - public void swapBuffers() throws GLException { - // FIXME: do we need to do anything if the pbuffer is double-buffered? - } - - public int getFloatingPointMode() { - // Floating-point pbuffers currently require NVidia hardware on X11 - return GLPbuffer.NV_FLOAT; - } - - private int queryFBConfig(long display, GLXFBConfig fbConfig, int attrib) { - int[] tmp = new int[1]; - if (GLX.glXGetFBConfigAttrib(display, fbConfig, attrib, tmp) != 0) { - throw new GLException("glXGetFBConfigAttrib failed"); - } - return tmp[0]; - } -} diff --git a/src/net/java/games/jogl/impl/x11/X11SunJDKReflection.java b/src/net/java/games/jogl/impl/x11/X11SunJDKReflection.java deleted file mode 100755 index 59208e5a9..000000000 --- a/src/net/java/games/jogl/impl/x11/X11SunJDKReflection.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.x11; - -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.lang.reflect.*; -import java.security.*; - -/** This class encapsulates the reflection routines necessary to peek - inside a few data structures in the AWT implementation on X11 for - the purposes of correctly enumerating the available visuals. */ - -public class X11SunJDKReflection { - private static Class x11GraphicsDeviceClass; - private static Method x11GraphicsDeviceGetScreenMethod; - private static Class x11GraphicsConfigClass; - private static Method x11GraphicsConfigGetVisualMethod; - private static boolean initted; - - static { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - try { - x11GraphicsDeviceClass = Class.forName("sun.awt.X11GraphicsDevice"); - x11GraphicsDeviceGetScreenMethod = x11GraphicsDeviceClass.getDeclaredMethod("getScreen", new Class[] {}); - x11GraphicsDeviceGetScreenMethod.setAccessible(true); - - x11GraphicsConfigClass = Class.forName("sun.awt.X11GraphicsConfig"); - x11GraphicsConfigGetVisualMethod = x11GraphicsConfigClass.getDeclaredMethod("getVisual", new Class[] {}); - x11GraphicsConfigGetVisualMethod.setAccessible(true); - initted = true; - } catch (Exception e) { - // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5 - } - return null; - } - }); - } - - public static int graphicsDeviceGetScreen(GraphicsDevice device) { - if (!initted) { - return 0; - } - - try { - return ((Integer) x11GraphicsDeviceGetScreenMethod.invoke(device, new Object[] {})).intValue(); - } catch (Exception e) { - return 0; - } - } - - public static int graphicsConfigurationGetVisualID(GraphicsConfiguration config) { - if (!initted) { - return 0; - } - - try { - return ((Integer) x11GraphicsConfigGetVisualMethod.invoke(config, new Object[] {})).intValue(); - } catch (Exception e) { - return 0; - } - } -} |