diff options
author | Kenneth Russel <[email protected]> | 2004-04-20 00:54:26 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2004-04-20 00:54:26 +0000 |
commit | 2ee2b7b51e3e82553e7dc17fe1a04e8cec5be8bf (patch) | |
tree | 53998aa0ec7a8566d52dcabf89992d861213d675 /src | |
parent | bebb33d0f10c4d75f2bc3c48c82f4f4f1278ee7c (diff) |
Added full-scene antialiasing (FSAA) support
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@111 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src')
3 files changed, 61 insertions, 43 deletions
diff --git a/src/net/java/games/jogl/impl/x11/X11GLContext.java b/src/net/java/games/jogl/impl/x11/X11GLContext.java index f1de46d5a..e3bb4ce72 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11GLContext.java @@ -290,47 +290,33 @@ public abstract class X11GLContext extends GLContext { int screen = 0; // FIXME: provide way to specify this? XVisualInfo vis = null; - if (chooser == null) { - // Note: this code path isn't taken any more now that the - // DefaultGLCapabilitiesChooser is present. However, it is being - // left in place for debugging purposes. - int[] attribs = X11GLContextFactory.glCapabilities2AttribList(capabilities); - vis = GLX.glXChooseVisual(display, screen, attribs); - if (vis == null) { - throw new GLException("Unable to find matching visual"); - } - if (DEBUG) { - System.err.println("Chosen visual from glXChooseVisual:"); - System.err.println(X11GLContextFactory.xvi2GLCapabilities(display, vis)); - } - } else { - 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) + 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; } } diff --git a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java b/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java index 817a41017..3582d51d9 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java +++ b/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java @@ -50,6 +50,8 @@ public class X11GLContextFactory extends GLContextFactory { NativeLibLoader.load(); } + private static final int MAX_ATTRIBS = 128; + public GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, GLCapabilitiesChooser chooser, GraphicsDevice device) { @@ -57,7 +59,8 @@ public class X11GLContextFactory extends GLContextFactory { // 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); + + int[] attribs = glCapabilities2AttribList(capabilities, isMultisampleAvailable()); long display = getDisplayConnection(); XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs); int recommendedIndex = -1; @@ -150,17 +153,22 @@ public class X11GLContextFactory extends GLContextFactory { 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) { + 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[22]; + int[] res = new int[MAX_ATTRIBS]; int idx = 0; res[idx++] = GLX.GLX_RGBA; if (caps.getDoubleBuffered()) { @@ -187,6 +195,12 @@ public class X11GLContextFactory extends GLContextFactory { 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; } @@ -203,6 +217,20 @@ public class X11GLContextFactory extends GLContextFactory { 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"; diff --git a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java b/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java index 454628734..ccbba8b92 100644 --- a/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11PbufferGLContext.java @@ -166,6 +166,10 @@ public class X11PbufferGLContext extends X11GLContext { iattributes[niattribs++] = capabilities.getAccumBlueBits(); } + // 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? |