aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2005-08-17 19:36:57 +0000
committerKenneth Russel <[email protected]>2005-08-17 19:36:57 +0000
commit08d7112b2948724e63881bf0cd5bb6d5f000248a (patch)
tree42e750b3f156ec942cbc1848d6f417342aa0fd6e
parent44120bea6928fded325a8100c9f4117b385964b6 (diff)
Added GLDrawableFactory.createExternalGLContext,
canCreateExternalGLDrawable and createExternalGLDrawable, needed for interacting with third-party libraries which use OpenGL. Need to have the addition of these methods approved by the expert group. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@347 232f8b59-042b-4e1e-8c03-345bb8c30851
-rw-r--r--src/net/java/games/jogl/GLDrawableFactory.java65
-rwxr-xr-xsrc/net/java/games/jogl/impl/macosx/MacOSXGLDrawableFactory.java14
-rwxr-xr-xsrc/net/java/games/jogl/impl/windows/WindowsExternalGLContext.java76
-rwxr-xr-xsrc/net/java/games/jogl/impl/windows/WindowsExternalGLDrawable.java69
-rwxr-xr-xsrc/net/java/games/jogl/impl/windows/WindowsGLDrawableFactory.java12
-rwxr-xr-xsrc/net/java/games/jogl/impl/x11/X11ExternalGLContext.java82
-rwxr-xr-xsrc/net/java/games/jogl/impl/x11/X11ExternalGLDrawable.java212
-rwxr-xr-xsrc/net/java/games/jogl/impl/x11/X11GLDrawableFactory.java12
8 files changed, 542 insertions, 0 deletions
diff --git a/src/net/java/games/jogl/GLDrawableFactory.java b/src/net/java/games/jogl/GLDrawableFactory.java
index a8211dedd..4b1d28124 100644
--- a/src/net/java/games/jogl/GLDrawableFactory.java
+++ b/src/net/java/games/jogl/GLDrawableFactory.java
@@ -240,4 +240,69 @@ public abstract class GLDrawableFactory {
int initialWidth,
int initialHeight,
GLContext shareWith);
+
+ //----------------------------------------------------------------------
+ // Methods for interacting with third-party OpenGL libraries
+
+ /**
+ * <P> Creates a GLContext object representing an existing OpenGL
+ * context in an external (third-party) OpenGL-based library. This
+ * GLContext object may be used to draw into this preexisting
+ * context using its {@link GL} and {@link GLU} objects. New
+ * contexts created through {@link GLDrawable}s may share textures
+ * and display lists with this external context. </P>
+ *
+ * <P> The underlying OpenGL context must be current on the current
+ * thread at the time this method is called. The user is responsible
+ * for the maintenance of the underlying OpenGL context; calls to
+ * <code>makeCurrent</code> and <code>release</code> on the returned
+ * GLContext object have no effect. If the underlying OpenGL context
+ * is destroyed, the <code>destroy</code> method should be called on
+ * the <code>GLContext</code>. A new <code>GLContext</code> object
+ * should be created for each newly-created underlying OpenGL
+ * context.
+ */
+ public abstract GLContext createExternalGLContext();
+
+ /**
+ * Returns true if it is possible to create an external GLDrawable
+ * object via {@link #createExternalGLDrawable}.
+ */
+ public abstract boolean canCreateExternalGLDrawable();
+
+ /**
+ * <P> Creates a {@link GLDrawable} object representing an existing
+ * OpenGL drawable in an external (third-party) OpenGL-based
+ * library. This GLDrawable object may be used to create new,
+ * fully-functional {@link GLContext}s on the OpenGL drawable. This
+ * is useful when interoperating with a third-party OpenGL-based
+ * library and it is essential to not perturb the state of the
+ * library's existing context, even to the point of not sharing
+ * textures or display lists with that context. </P>
+ *
+ * <P> An underlying OpenGL context must be current on the desired
+ * drawable and the current thread at the time this method is
+ * called. The user is responsible for the maintenance of the
+ * underlying drawable. If one or more contexts are created on the
+ * drawable using {@link GLDrawable#createContext}, and the drawable
+ * is deleted by the third-party library, the user is responsible
+ * for calling {@link GLContext#destroy} on these contexts. </P>
+ *
+ * <P> Calls to <code>setSize</code>, <code>getWidth</code> and
+ * <code>getHeight</code> are illegal on the returned GLDrawable. If
+ * these operations are required by the user, they must be performed
+ * by the third-party library. </P>
+ *
+ * <P> It is legal to create both an external GLContext and
+ * GLDrawable representing the same third-party OpenGL entities.
+ * This can be used, for example, to query current state information
+ * using the external GLContext and then create and set up new
+ * GLContexts using the external GLDrawable. </P>
+ *
+ * <P> This functionality may not be available on all platforms and
+ * {@link #canCreateExternalGLDrawable} should be called first to
+ * see if it is present. For example, on X11 platforms, this API
+ * requires the presence of GLX 1.3 or later.
+ */
+ public abstract GLDrawable createExternalGLDrawable();
}
diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLDrawableFactory.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLDrawableFactory.java
index 4935da0b2..019e0c30d 100755
--- a/src/net/java/games/jogl/impl/macosx/MacOSXGLDrawableFactory.java
+++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLDrawableFactory.java
@@ -102,6 +102,20 @@ public class MacOSXGLDrawableFactory extends GLDrawableFactoryImpl {
return (GLPbuffer) returnList.get(0);
}
+ public GLContext createExternalGLContext() {
+ // FIXME
+ throw new GLException("Not yet implemented");
+ }
+
+ public boolean canCreateExternalGLDrawable() {
+ return false;
+ }
+
+ public GLDrawable createExternalGLDrawable() {
+ // FIXME
+ throw new GLException("Not yet implemented");
+ }
+
public long dynamicLookupFunction(String glFuncName) {
return CGL.getProcAddress(glFuncName);
}
diff --git a/src/net/java/games/jogl/impl/windows/WindowsExternalGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsExternalGLContext.java
new file mode 100755
index 000000000..642052c8c
--- /dev/null
+++ b/src/net/java/games/jogl/impl/windows/WindowsExternalGLContext.java
@@ -0,0 +1,76 @@
+/*
+ * 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.windows;
+
+import java.nio.*;
+import java.util.*;
+import net.java.games.jogl.*;
+import net.java.games.jogl.impl.*;
+
+public class WindowsExternalGLContext extends WindowsGLContext {
+ private boolean firstMakeCurrent = true;
+ private boolean created = true;
+
+ public WindowsExternalGLContext() {
+ super(null, null);
+ hglrc = WGL.wglGetCurrentContext();
+ GLContextShareSet.contextCreated(this);
+ resetGLFunctionAvailability();
+ }
+
+ protected int makeCurrentImpl() throws GLException {
+ if (firstMakeCurrent) {
+ return CONTEXT_CURRENT_NEW;
+ }
+ return CONTEXT_CURRENT;
+ }
+
+ protected void releaseImpl() throws GLException {
+ }
+
+ protected void destroyImpl() throws GLException {
+ created = false;
+ GLContextShareSet.contextDestroyed(this);
+ }
+
+ public boolean isCreated() {
+ return created;
+ }
+}
diff --git a/src/net/java/games/jogl/impl/windows/WindowsExternalGLDrawable.java b/src/net/java/games/jogl/impl/windows/WindowsExternalGLDrawable.java
new file mode 100755
index 000000000..a93489872
--- /dev/null
+++ b/src/net/java/games/jogl/impl/windows/WindowsExternalGLDrawable.java
@@ -0,0 +1,69 @@
+/*
+ * 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.windows;
+
+import net.java.games.jogl.*;
+import net.java.games.jogl.impl.*;
+
+public class WindowsExternalGLDrawable extends WindowsGLDrawable {
+ public WindowsExternalGLDrawable() {
+ super(null, new GLCapabilities(), null);
+ hdc = WGL.wglGetCurrentDC();
+ }
+
+ public GLContext createContext(GLContext shareWith) {
+ return new WindowsGLContext(this, shareWith);
+ }
+
+ public void setSize(int newWidth, int newHeight) {
+ throw new GLException("Should not call this");
+ }
+
+ public int getWidth() {
+ throw new GLException("Should not call this");
+ }
+
+ public int getHeight() {
+ throw new GLException("Should not call this");
+ }
+
+ public void destroy() {
+ }
+}
diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLDrawableFactory.java b/src/net/java/games/jogl/impl/windows/WindowsGLDrawableFactory.java
index d3c176fa8..8e97d5e0c 100755
--- a/src/net/java/games/jogl/impl/windows/WindowsGLDrawableFactory.java
+++ b/src/net/java/games/jogl/impl/windows/WindowsGLDrawableFactory.java
@@ -217,6 +217,18 @@ public class WindowsGLDrawableFactory extends GLDrawableFactoryImpl {
return (GLPbuffer) returnList.get(0);
}
+ public GLContext createExternalGLContext() {
+ return new WindowsExternalGLContext();
+ }
+
+ public boolean canCreateExternalGLDrawable() {
+ return true;
+ }
+
+ public GLDrawable createExternalGLDrawable() {
+ return new WindowsExternalGLDrawable();
+ }
+
public long dynamicLookupFunction(String glFuncName) {
long res = WGL.wglGetProcAddress(glFuncName);
if (res == 0) {
diff --git a/src/net/java/games/jogl/impl/x11/X11ExternalGLContext.java b/src/net/java/games/jogl/impl/x11/X11ExternalGLContext.java
new file mode 100755
index 000000000..5de4228d2
--- /dev/null
+++ b/src/net/java/games/jogl/impl/x11/X11ExternalGLContext.java
@@ -0,0 +1,82 @@
+/*
+ * 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 X11ExternalGLContext extends X11GLContext {
+ private boolean firstMakeCurrent = true;
+ private boolean created = true;
+
+ public X11ExternalGLContext() {
+ super(null, null);
+ lockAWT();
+ try {
+ context = GLX.glXGetCurrentContext();
+ } finally {
+ unlockAWT();
+ }
+ GLContextShareSet.contextCreated(this);
+ resetGLFunctionAvailability();
+ }
+
+ protected void create() {
+ }
+
+ protected int makeCurrentImpl() throws GLException {
+ if (firstMakeCurrent) {
+ return CONTEXT_CURRENT_NEW;
+ }
+ return CONTEXT_CURRENT;
+ }
+
+ protected void releaseImpl() throws GLException {
+ }
+
+ protected void destroyImpl() throws GLException {
+ created = false;
+ GLContextShareSet.contextDestroyed(this);
+ }
+
+ public boolean isCreated() {
+ return created;
+ }
+}
diff --git a/src/net/java/games/jogl/impl/x11/X11ExternalGLDrawable.java b/src/net/java/games/jogl/impl/x11/X11ExternalGLDrawable.java
new file mode 100755
index 000000000..93b172f99
--- /dev/null
+++ b/src/net/java/games/jogl/impl/x11/X11ExternalGLDrawable.java
@@ -0,0 +1,212 @@
+/*
+ * 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 X11ExternalGLDrawable extends X11GLDrawable {
+ private int fbConfigID;
+ private int renderType;
+ private int screen;
+ private long readDrawable;
+
+ public X11ExternalGLDrawable() {
+ super(null, null, null);
+ lockAWT();
+ try {
+ display = GLX.glXGetCurrentDisplay();
+ drawable = GLX.glXGetCurrentDrawable();
+ readDrawable = GLX.glXGetCurrentReadDrawable();
+
+ // Need GLXFBConfig ID in order to properly create new contexts
+ // on this drawable
+ long context = GLX.glXGetCurrentContext();
+ int[] val = new int[1];
+ GLX.glXQueryContext(display, context, GLX.GLX_FBCONFIG_ID, val, 0);
+ fbConfigID = val[0];
+ renderType = GLX.GLX_RGBA_TYPE;
+ GLX.glXQueryContext(display, context, GLX.GLX_RENDER_TYPE, val, 0);
+ if ((val[0] & GLX.GLX_RGBA_BIT) == 0) {
+ if (DEBUG) {
+ System.err.println("X11ExternalGLDrawable: WARNING: forcing GLX_RGBA_TYPE for newly created contexts");
+ }
+ }
+ GLX.glXQueryContext(display, context, GLX.GLX_SCREEN, val, 0);
+ screen = val[0];
+ } finally {
+ unlockAWT();
+ }
+ }
+
+ public GLContext createContext(GLContext shareWith) {
+ return new Context(shareWith);
+ }
+
+ public void setSize(int newWidth, int newHeight) {
+ throw new GLException("Should not call this");
+ }
+
+ public int getWidth() {
+ throw new GLException("Should not call this");
+ }
+
+ public int getHeight() {
+ throw new GLException("Should not call this");
+ }
+
+ public void destroy() {
+ }
+
+ class Context extends X11GLContext {
+ Context(GLContext shareWith) {
+ super(X11ExternalGLDrawable.this, shareWith);
+ this.drawable = drawable;
+ }
+
+ protected int makeCurrentImpl() throws GLException {
+ if (drawable.getDrawable() == 0) {
+ // parent drawable not properly initialized
+ // FIXME: signal error?
+ if (DEBUG) {
+ System.err.println("parent drawable not properly initialized");
+ }
+ return CONTEXT_NOT_CURRENT;
+ }
+
+ // Note that we have to completely override makeCurrentImpl
+ // because the underlying makeCurrent call differs from the norm
+ lockAWT();
+ try {
+ boolean created = false;
+ if (context == 0) {
+ create();
+ if (DEBUG) {
+ System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName());
+ }
+ created = true;
+ }
+
+ if (!GLX.glXMakeContextCurrent(drawable.getDisplay(),
+ drawable.getDrawable(),
+ readDrawable,
+ context)) {
+ throw new GLException("Error making context current");
+ } else {
+ mostRecentDisplay = drawable.getDisplay();
+ if (DEBUG && VERBOSE) {
+ System.err.println(getThreadName() + ": glXMakeCurrent(display " + toHexString(drawable.getDisplay()) +
+ ", drawable " + toHexString(drawable.getDrawable()) +
+ ", context " + toHexString(context) + ") succeeded");
+ }
+ }
+
+ if (created) {
+ resetGLFunctionAvailability();
+ return CONTEXT_CURRENT_NEW;
+ }
+ return CONTEXT_CURRENT;
+ } finally {
+ unlockAWT();
+ }
+ }
+
+ protected void releaseImpl() throws GLException {
+ lockAWT();
+ try {
+ if (!GLX.glXMakeContextCurrent(drawable.getDisplay(), 0, 0, 0)) {
+ throw new GLException("Error freeing OpenGL context");
+ }
+ } finally {
+ unlockAWT();
+ }
+ }
+
+ protected void create() {
+ // We already have the GLXFBConfig ID for the context. All we
+ // need to do is use it to choose the GLXFBConfig and then
+ // create a context with it.
+ int[] iattributes = new int[] {
+ GLX.GLX_FBCONFIG_ID,
+ fbConfigID,
+ 0,
+ 0
+ };
+ float[] fattributes = new float[0];
+ int[] nelementsTmp = new int[1];
+ GLXFBConfig[] fbConfigs = GLX.glXChooseFBConfig(display, screen, iattributes, 0, nelementsTmp, 0);
+ int nelements = nelementsTmp[0];
+ if (nelements <= 0) {
+ throw new GLException("context creation error: couldn't find a suitable frame buffer configuration");
+ }
+ if (nelements != 1) {
+ throw new GLException("context creation error: shouldn't get more than one GLXFBConfig");
+ }
+ // Note that we currently don't allow selection of anything but
+ // the first GLXFBConfig in the returned list (there should be only one)
+ GLXFBConfig fbConfig = fbConfigs[0];
+ // Create a gl context for the drawable
+ 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");
+ }
+ }
+ // FIXME: how to determine "direct" bit?
+ context = GLX.glXCreateNewContext(display, fbConfig, renderType, share, true);
+ if (context == 0) {
+ String detail = " display=" + toHexString(display) +
+ " fbconfig=" + fbConfig +
+ " fbconfigID=" + toHexString(fbConfigID) +
+ " renderType=" + toHexString(renderType) +
+ " share=" + toHexString(share);
+ throw new GLException("context creation error: glXCreateNewContext() failed: " + detail);
+ }
+ GLContextShareSet.contextCreated(this);
+
+ if (DEBUG) {
+ System.err.println("Created context " + toHexString(context) +
+ " for GLXDrawable " + toHexString(drawable.getDrawable()));
+ }
+ }
+ }
+}
diff --git a/src/net/java/games/jogl/impl/x11/X11GLDrawableFactory.java b/src/net/java/games/jogl/impl/x11/X11GLDrawableFactory.java
index e2dcff91c..01050468d 100755
--- a/src/net/java/games/jogl/impl/x11/X11GLDrawableFactory.java
+++ b/src/net/java/games/jogl/impl/x11/X11GLDrawableFactory.java
@@ -230,6 +230,18 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl {
return (GLPbuffer) returnList.get(0);
}
+ public GLContext createExternalGLContext() {
+ return new X11ExternalGLContext();
+ }
+
+ public boolean canCreateExternalGLDrawable() {
+ return canCreateGLPbuffer(null, 0, 0);
+ }
+
+ public GLDrawable createExternalGLDrawable() {
+ return new X11ExternalGLDrawable();
+ }
+
public long dynamicLookupFunction(String glFuncName) {
long res = 0;
if (!isLinuxAMD64) {