diff options
author | Kenneth Russel <[email protected]> | 2006-11-19 20:51:57 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2006-11-19 20:51:57 +0000 |
commit | a303cd13ff62f94a0459978735620e37d72bbb77 (patch) | |
tree | 32b580af4e878d479890c12b8eae9c98e10a4874 /src/classes/com/sun/opengl/impl/windows | |
parent | bf82eceb6f78d5ee6e4c0f9f02590d2a58e647d3 (diff) |
Fixed Issue 213: Expose GLCaps from GLDrawable
Added getChosenGLCapabilities() to the GLDrawable interface.
Implemented on Windows, Unix and Mac OS X platforms with various
techniques. Attempts to provide correct answers in all cases, even
when the GLCapabilitiesChooser mechanism is not supported. Required
addition of new platform-specific Java code in most cases to either
re-convert existing PIXELFORMATDESCRIPTORS / XVisualInfos, or to query
the pixel format or visual chosen for drawables like pbuffers for
which the chooser mechanism is not (yet) implemented. Tested on
Windows, Solaris/x86, and Mac OS X with on-screen, off-screen and
pbuffer drawables. (Full support for the Java2D/JOGL bridge is not yet
in place; the answer returned from the GLJPanel in this case is
currently the default GLCapabilities, and it is likely that "external"
GLDrawables will return null.)
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@989 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/impl/windows')
5 files changed, 66 insertions, 10 deletions
diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java index e5b8b6424..1efc1c759 100644 --- a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawable.java @@ -78,13 +78,20 @@ public abstract class WindowsGLDrawable extends GLDrawableImpl { PIXELFORMATDESCRIPTOR pfd = null; int pixelFormat = 0; if (onscreen) { - if (WGL.GetPixelFormat(hdc) != 0) { + if ((pixelFormat = WGL.GetPixelFormat(hdc)) != 0) { // The Java2D/OpenGL pipeline probably already set a pixel // format for this canvas. if (DEBUG) { System.err.println("NOTE: pixel format already chosen (by Java2D/OpenGL pipeline?) for window: " + WGL.GetPixelFormat(hdc)); } + pfd = newPixelFormatDescriptor(); + if (WGL.DescribePixelFormat(hdc, pixelFormat, pfd.size(), pfd) == 0) { + // FIXME: should this just be a warning? Not really critical... + throw new GLException("Unable to describe pixel format " + pixelFormat + + " of window set by Java2D/OpenGL pipeline"); + } + setChosenGLCapabilities(pfd2GLCapabilities(pfd)); pixelFormatChosen = true; return; } @@ -280,6 +287,7 @@ public abstract class WindowsGLDrawable extends GLDrawableImpl { } throw new GLException("Unable to set pixel format " + pixelFormat + " for device context " + toHexString(hdc) + ": error code " + lastError); } + setChosenGLCapabilities(pfd2GLCapabilities(pfd)); pixelFormatChosen = true; } @@ -518,10 +526,13 @@ public abstract class WindowsGLDrawable extends GLDrawableImpl { int attr = iattribs[i]; switch (attr) { case WGLExt.WGL_DRAW_TO_WINDOW_ARB: - if (iresults[i] != GL.GL_TRUE) + if (requireRenderToWindow && iresults[i] != GL.GL_TRUE) return null; break; + case WGLExt.WGL_DRAW_TO_PBUFFER_ARB: + break; + case WGLExt.WGL_ACCELERATION_ARB: res.setHardwareAccelerated(iresults[i] == WGLExt.WGL_FULL_ACCELERATION_ARB); break; @@ -548,8 +559,17 @@ public abstract class WindowsGLDrawable extends GLDrawableImpl { break; case WGLExt.WGL_PIXEL_TYPE_ARB: - if (iresults[i] != WGLExt.WGL_TYPE_RGBA_ARB) - return null; + // Fail softly with unknown results here + if (iresults[i] == WGLExt.WGL_TYPE_RGBA_ARB || + iresults[i] == WGLExt.WGL_TYPE_RGBA_FLOAT_ATI) { + res.setPbufferFloatingPointBuffers(true); + } + break; + + case WGLExt.WGL_FLOAT_COMPONENTS_NV: + if (iresults[i] != 0) { + res.setPbufferFloatingPointBuffers(true); + } break; case WGLExt.WGL_RED_BITS_ARB: diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java index 1c77d5b04..6e1b4ca99 100644 --- a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java @@ -118,6 +118,9 @@ public class WindowsGLDrawableFactory extends GLDrawableFactoryImpl { }; maybeDoSingleThreadedWorkaround(r); } + if (DEBUG) { + System.err.println("WindowsGLDrawableFactory.canCreateGLPbuffer() = " + canCreateGLPbuffer); + } return canCreateGLPbuffer; } diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java index 4fe9c93b2..474c71598 100644 --- a/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsOffscreenGLDrawable.java @@ -128,6 +128,7 @@ public class WindowsOffscreenGLDrawable extends WindowsGLDrawable { origbitmap = 0; hbitmap = 0; hdc = 0; + setChosenGLCapabilities(null); } } } diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java index 41f959482..5f74998e5 100644 --- a/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsOnscreenGLDrawable.java @@ -96,6 +96,7 @@ public class WindowsOnscreenGLDrawable extends WindowsGLDrawable { this.realized = realized; if (!realized) { // Assume heavyweight widget was destroyed + setChosenGLCapabilities(null); pixelFormatChosen = false; } } diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLDrawable.java index 0dddddddd..4f87eaecf 100644 --- a/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsPbufferGLDrawable.java @@ -96,6 +96,7 @@ public class WindowsPbufferGLDrawable extends WindowsGLDrawable { throw new GLException("Error destroying pbuffer: error code " + WGL.GetLastError()); } buffer = 0; + setChosenGLCapabilities(null); } } @@ -198,8 +199,8 @@ public class WindowsPbufferGLDrawable extends WindowsGLDrawable { iattributes[3] = WGLExt.WGL_ALPHA_BITS_ARB; iattributes[4] = WGLExt.WGL_DEPTH_BITS_ARB; iattributes[5] = (useFloat ? (ati ? WGLExt.WGL_PIXEL_TYPE_ARB : WGLExt.WGL_FLOAT_COMPONENTS_NV) : WGLExt.WGL_RED_BITS_ARB); - iattributes[6] = WGLExt.WGL_SAMPLE_BUFFERS_EXT; - iattributes[7] = WGLExt.WGL_SAMPLES_EXT; + iattributes[6] = WGLExt.WGL_SAMPLE_BUFFERS_ARB; + iattributes[7] = WGLExt.WGL_SAMPLES_ARB; iattributes[8] = WGLExt.WGL_DRAW_TO_PBUFFER_ARB; int[] ivalues = new int[9]; for (int i = 0; i < nformats; i++) { @@ -237,9 +238,9 @@ public class WindowsPbufferGLDrawable extends WindowsGLDrawable { } long tmpBuffer = 0; - int whichFormat = 0; + int whichFormat = -1; // Loop is a workaround for bugs in NVidia's recent drivers - do { + for (whichFormat = 0; whichFormat < nformats; whichFormat++) { int format = pformats[whichFormat]; // Create the p-buffer. @@ -266,8 +267,11 @@ public class WindowsPbufferGLDrawable extends WindowsGLDrawable { iattributes[niattribs++] = 0; tmpBuffer = wglExt.wglCreatePbufferARB(parentHdc, format, initWidth, initHeight, iattributes, 0); - ++whichFormat; - } while ((tmpBuffer == 0) && (whichFormat < nformats)); + if (tmpBuffer != 0) { + // Done + break; + } + } if (tmpBuffer == 0) { throw new GLException("pbuffer creation error: wglCreatePbufferARB() failed: tried " + nformats + @@ -285,6 +289,33 @@ public class WindowsPbufferGLDrawable extends WindowsGLDrawable { hdc = tmpHdc; cachedWGLExt = wglExt; + // Re-query chosen pixel format + { + niattribs = 0; + iattributes[niattribs++] = WGLExt.WGL_ACCELERATION_ARB; + iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB; + iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB; + iattributes[niattribs++] = (useFloat ? (ati ? WGLExt.WGL_PIXEL_TYPE_ARB : WGLExt.WGL_FLOAT_COMPONENTS_NV) : WGLExt.WGL_RED_BITS_ARB); + iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB; + iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB; + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_PBUFFER_ARB; + int[] ivalues = new int[niattribs]; + // FIXME: usually prefer to throw exceptions, but failure here is not critical + if (wglExt.wglGetPixelFormatAttribivARB(parentHdc, pformats[whichFormat], 0, niattribs, iattributes, 0, ivalues, 0)) { + setChosenGLCapabilities(iattributes2GLCapabilities(iattributes, niattribs, ivalues, false)); + } + } + // Determine the actual width and height we were able to create. int[] tmp = new int[1]; wglExt.wglQueryPbufferARB( buffer, WGLExt.WGL_PBUFFER_WIDTH_ARB, tmp, 0 ); |