aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2005-07-18 22:15:42 +0000
committerKenneth Russel <[email protected]>2005-07-18 22:15:42 +0000
commit8f5492988de9fddf61623b7274915c777ad3a97d (patch)
tree79528bb981dbaa88f2f970d555b2fb06b7f8335a /src/net/java/games/jogl/impl/x11/X11GLContextFactory.java
parent5e36587af91f43faff49f4ff61c40cf084bae298 (diff)
Moved support for instantiating GLPbuffers from X11OnscreenGLContext
to X11GLContextFactory. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@327 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/impl/x11/X11GLContextFactory.java')
-rw-r--r--src/net/java/games/jogl/impl/x11/X11GLContextFactory.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java b/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java
index 78d03a28a..109f74e44 100644
--- a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java
+++ b/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java
@@ -40,12 +40,18 @@
package net.java.games.jogl.impl.x11;
import java.awt.Component;
+import java.awt.EventQueue;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
import net.java.games.jogl.*;
import net.java.games.jogl.impl.*;
public class X11GLContextFactory extends GLContextFactory {
+ private static final boolean DEBUG = Debug.debug("X11GLContextFactory");
+
static {
NativeLibLoader.load();
}
@@ -137,6 +143,72 @@ public class X11GLContextFactory extends GLContextFactory {
return new X11OffscreenGLDrawable(capabilities, chooser);
}
+ private boolean pbufferSupportInitialized = false;
+ private boolean canCreateGLPbuffer = false;
+ public boolean canCreateGLPbuffer(GLCapabilities capabilities,
+ int initialWidth,
+ int initialHeight) {
+ if (!pbufferSupportInitialized) {
+ Runnable r = new Runnable() {
+ public void run() {
+ long display = getDisplayConnection();
+ lockAWT();
+ try {
+ int[] major = new int[1];
+ int[] minor = new int[1];
+ if (!GLX.glXQueryVersion(display, major, 0, minor, 0)) {
+ throw new GLException("glXQueryVersion failed");
+ }
+ if (DEBUG) {
+ System.err.println("!!! GLX version: major " + major[0] +
+ ", minor " + minor[0]);
+ }
+
+ int screen = 0; // FIXME: provide way to specify this?
+
+ // 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) {
+ String str = GLX.glXQueryServerString(display, screen, GLX.GLX_VENDOR);
+ if (str != null && str.indexOf("ATI") >= 0) {
+ canCreateGLPbuffer = true;
+ }
+ } else {
+ canCreateGLPbuffer = ((major[0] > 1) || (minor[0] > 2));
+ }
+
+ pbufferSupportInitialized = true;
+ } finally {
+ unlockAWT();
+ }
+ }
+ };
+ maybeDoSingleThreadedWorkaround(r);
+ }
+ return canCreateGLPbuffer;
+ }
+
+ public GLPbuffer createGLPbuffer(final GLCapabilities capabilities,
+ final int initialWidth,
+ final int initialHeight,
+ final GLContext shareWith) {
+ if (!canCreateGLPbuffer(capabilities, initialWidth, initialHeight)) {
+ throw new GLException("Pbuffer support not available with current graphics card");
+ }
+ final List returnList = new ArrayList();
+ Runnable r = new Runnable() {
+ public void run() {
+ X11PbufferGLDrawable pbufferDrawable = new X11PbufferGLDrawable(capabilities,
+ initialWidth,
+ initialHeight);
+ GLPbufferImpl pbuffer = new GLPbufferImpl(pbufferDrawable, shareWith);
+ returnList.add(pbuffer);
+ }
+ };
+ maybeDoSingleThreadedWorkaround(r);
+ return (GLPbuffer) returnList.get(0);
+ }
+
public static GLCapabilities xvi2GLCapabilities(long display, XVisualInfo info) {
int[] tmp = new int[1];
int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp, 0);
@@ -292,4 +364,18 @@ public class X11GLContextFactory extends GLContextFactory {
}
return tmp[tmp_offset];
}
+
+ private void maybeDoSingleThreadedWorkaround(Runnable action) {
+ if (SingleThreadedWorkaround.doWorkaround() && !EventQueue.isDispatchThread()) {
+ try {
+ EventQueue.invokeAndWait(action);
+ } catch (InvocationTargetException e) {
+ throw new GLException(e.getTargetException());
+ } catch (InterruptedException e) {
+ throw new GLException(e);
+ }
+ } else {
+ action.run();
+ }
+ }
}