diff options
author | Kenneth Russel <[email protected]> | 2008-12-20 08:58:00 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2008-12-20 08:58:00 +0000 |
commit | 6eda9476e8168bacdeb1854540d89bd9db0d5029 (patch) | |
tree | 692317f9924638836b16bf83a9cefe0c1047bb66 /src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java | |
parent | 14a94c810910f88d3b7214ae9be5027dc74df39f (diff) |
Factored out the remaining toolkit, and specifically AWT, dependencies
from GLDrawableFactory implementations into NativeWindowFactory
implementations. These dependencies were the up-front selection of the
GraphicsConfiguration and the locking and unlocking of the toolkit,
which are both currently needed only on X11 platforms due to how
OpenGL and the window system interact there. Added X11GraphicsDevice
and X11GraphicsConfiguration classes which are intended to be used by
Newt or potentially other third-party window toolkits. Unified the
separate NativeWindow and AWT GLDrawableFactory implementations in the
GLDrawableFactory class.
Exposed the toolkit locking mechanism through the NativeWindowFactory
and introduced the concept of a default NativeWindowFactory which is
used by the X11 drawable and context implementations. Removed
unnecessary toolkit locking calls from Mac OS X and Windows drawable
and context implementations.
Added a registration mechanism for new NativeWindowFactories, allowing
third parties to plug in new window toolkits orthogonally to the
OpenGL drawable and context code.
The public APIs for the NativeWindowFactory and the GLDrawableFactory,
in particular how they are fetched, changed as a result of these
refactorings. Updated all uses.
Fixed bug in X11OffscreenGLXDrawable introduced during last set of
changes.
Tested demos on Solaris, Mac OS X and Windows.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1824 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java')
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java | 348 |
1 files changed, 169 insertions, 179 deletions
diff --git a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java index f82653bcd..a13592d62 100644 --- a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java @@ -79,27 +79,22 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { } public void destroy() { - getFactoryImpl().lockToolkit(); - try { - NullWindow nw = (NullWindow) getNativeWindow(); - if (nw.getSurfaceHandle() != 0) { - // Must release DC and pbuffer - // NOTE that since the context is not current, glGetError() can - // not be called here, so we skip the use of any composable - // pipelines (see WindowsOnscreenWGLContext.makeCurrentImpl) - WGLExt wglExt = cachedWGLExt; - if (wglExt.wglReleasePbufferDC(buffer, nw.getSurfaceHandle()) == 0) { - throw new GLException("Error releasing pbuffer device context: error code " + WGL.GetLastError()); - } - nw.setSurfaceHandle(0); - if (!wglExt.wglDestroyPbuffer(buffer)) { - throw new GLException("Error destroying pbuffer: error code " + WGL.GetLastError()); - } - buffer = 0; - setChosenGLCapabilities(null); - } - } finally { - getFactoryImpl().unlockToolkit(); + NullWindow nw = (NullWindow) getNativeWindow(); + if (nw.getSurfaceHandle() != 0) { + // Must release DC and pbuffer + // NOTE that since the context is not current, glGetError() can + // not be called here, so we skip the use of any composable + // pipelines (see WindowsOnscreenWGLContext.makeCurrentImpl) + WGLExt wglExt = cachedWGLExt; + if (wglExt.wglReleasePbufferDC(buffer, nw.getSurfaceHandle()) == 0) { + throw new GLException("Error releasing pbuffer device context: error code " + WGL.GetLastError()); + } + nw.setSurfaceHandle(0); + if (!wglExt.wglDestroyPbuffer(buffer)) { + throw new GLException("Error destroying pbuffer: error code " + WGL.GetLastError()); + } + buffer = 0; + setChosenGLCapabilities(null); } super.destroy(); } @@ -151,185 +146,180 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { (capabilities.getPbufferFloatingPointBuffers() ? " [float]" : "")); } - getFactoryImpl().lockToolkit(); - try { - if (!glCapabilities2iattributes(capabilities, - iattributes, - wglExt, - true, - floatModeTmp)) { - throw new GLException("Pbuffer-related extensions not supported"); - } + if (!glCapabilities2iattributes(capabilities, + iattributes, + wglExt, + true, + floatModeTmp)) { + throw new GLException("Pbuffer-related extensions not supported"); + } - floatMode = floatModeTmp[0]; - boolean rtt = capabilities.getPbufferRenderToTexture(); - boolean rect = capabilities.getPbufferRenderToTextureRectangle(); - boolean useFloat = capabilities.getPbufferFloatingPointBuffers(); - boolean ati = false; + floatMode = floatModeTmp[0]; + boolean rtt = capabilities.getPbufferRenderToTexture(); + boolean rect = capabilities.getPbufferRenderToTextureRectangle(); + boolean useFloat = capabilities.getPbufferFloatingPointBuffers(); + boolean ati = false; - if (useFloat) { - ati = (floatMode == GLPbuffer.ATI_FLOAT); - } + if (useFloat) { + ati = (floatMode == GLPbuffer.ATI_FLOAT); + } - int[] pformats = new int[MAX_PFORMATS]; - int nformats; - int[] nformatsTmp = new int[1]; - if (!wglExt.wglChoosePixelFormat(parentHdc, - iattributes, 0, - fattributes, 0, - MAX_PFORMATS, - pformats, 0, - nformatsTmp, 0)) { - throw new GLException("pbuffer creation error: wglChoosePixelFormat() failed"); + int[] pformats = new int[MAX_PFORMATS]; + int nformats; + int[] nformatsTmp = new int[1]; + if (!wglExt.wglChoosePixelFormat(parentHdc, + iattributes, 0, + fattributes, 0, + MAX_PFORMATS, + pformats, 0, + nformatsTmp, 0)) { + throw new GLException("pbuffer creation error: wglChoosePixelFormat() failed"); + } + nformats = nformatsTmp[0]; + if (nformats <= 0) { + throw new GLException("pbuffer creation error: Couldn't find a suitable pixel format"); + } + + boolean haveMultisample = wglExt.isExtensionAvailable("WGL_ARB_multisample"); + + if (DEBUG) { + System.err.println("" + nformats + " suitable pixel formats found"); + // query pixel format + iattributes[0] = WGLExt.WGL_RED_BITS; + iattributes[1] = WGLExt.WGL_GREEN_BITS; + iattributes[2] = WGLExt.WGL_BLUE_BITS; + iattributes[3] = WGLExt.WGL_ALPHA_BITS; + iattributes[4] = WGLExt.WGL_DEPTH_BITS; + iattributes[5] = (useFloat ? (ati ? WGLExt.WGL_PIXEL_TYPE: WGLExt.WGL_FLOAT_COMPONENTS_NV) : WGLExt.WGL_RED_BITS); + iattributes[6] = (haveMultisample ? WGLExt.WGL_SAMPLE_BUFFERS: WGLExt.WGL_RED_BITS); + iattributes[7] = (haveMultisample ? WGLExt.WGL_SAMPLES: WGLExt.WGL_RED_BITS); + iattributes[8] = WGLExt.WGL_DRAW_TO_PBUFFER; + int[] ivalues = new int[9]; + for (int i = 0; i < nformats; i++) { + if (!wglExt.wglGetPixelFormatAttribiv(parentHdc, pformats[i], 0, 9, iattributes, 0, ivalues, 0)) { + throw new GLException("Error while querying pixel format " + pformats[i] + + "'s (index " + i + "'s) capabilities for debugging"); } - nformats = nformatsTmp[0]; - if (nformats <= 0) { - throw new GLException("pbuffer creation error: Couldn't find a suitable pixel format"); + System.err.print("pixel format " + pformats[i] + " (index " + i + "): "); + System.err.print( "r: " + ivalues[0]); + System.err.print(" g: " + ivalues[1]); + System.err.print(" b: " + ivalues[2]); + System.err.print(" a: " + ivalues[3]); + System.err.print(" depth: " + ivalues[4]); + if (haveMultisample) { + System.err.print(" multisample: " + ivalues[6]); } - - boolean haveMultisample = wglExt.isExtensionAvailable("WGL_ARB_multisample"); - - if (DEBUG) { - System.err.println("" + nformats + " suitable pixel formats found"); - // query pixel format - iattributes[0] = WGLExt.WGL_RED_BITS; - iattributes[1] = WGLExt.WGL_GREEN_BITS; - iattributes[2] = WGLExt.WGL_BLUE_BITS; - iattributes[3] = WGLExt.WGL_ALPHA_BITS; - iattributes[4] = WGLExt.WGL_DEPTH_BITS; - iattributes[5] = (useFloat ? (ati ? WGLExt.WGL_PIXEL_TYPE: WGLExt.WGL_FLOAT_COMPONENTS_NV) : WGLExt.WGL_RED_BITS); - iattributes[6] = (haveMultisample ? WGLExt.WGL_SAMPLE_BUFFERS: WGLExt.WGL_RED_BITS); - iattributes[7] = (haveMultisample ? WGLExt.WGL_SAMPLES: WGLExt.WGL_RED_BITS); - iattributes[8] = WGLExt.WGL_DRAW_TO_PBUFFER; - int[] ivalues = new int[9]; - for (int i = 0; i < nformats; i++) { - if (!wglExt.wglGetPixelFormatAttribiv(parentHdc, pformats[i], 0, 9, iattributes, 0, ivalues, 0)) { - throw new GLException("Error while querying pixel format " + pformats[i] + - "'s (index " + i + "'s) capabilities for debugging"); - } - System.err.print("pixel format " + pformats[i] + " (index " + i + "): "); - System.err.print( "r: " + ivalues[0]); - System.err.print(" g: " + ivalues[1]); - System.err.print(" b: " + ivalues[2]); - System.err.print(" a: " + ivalues[3]); - System.err.print(" depth: " + ivalues[4]); - if (haveMultisample) { - System.err.print(" multisample: " + ivalues[6]); - } - System.err.print(" samples: " + ivalues[7]); - if (useFloat) { - if (ati) { - if (ivalues[5] == WGLExt.WGL_TYPE_RGBA_FLOAT) { - System.err.print(" [ati float]"); - } else if (ivalues[5] != WGLExt.WGL_TYPE_RGBA) { - System.err.print(" [unknown pixel type " + ivalues[5] + "]"); - } - } else { - if (ivalues[5] != 0) { - System.err.print(" [float]"); - } - } + System.err.print(" samples: " + ivalues[7]); + if (useFloat) { + if (ati) { + if (ivalues[5] == WGLExt.WGL_TYPE_RGBA_FLOAT) { + System.err.print(" [ati float]"); + } else if (ivalues[5] != WGLExt.WGL_TYPE_RGBA) { + System.err.print(" [unknown pixel type " + ivalues[5] + "]"); } - - if (ivalues[8] != 0) { - System.err.print(" [pbuffer]"); + } else { + if (ivalues[5] != 0) { + System.err.print(" [float]"); } - System.err.println(); } } - long tmpBuffer = 0; - int whichFormat = -1; - // Loop is a workaround for bugs in NVidia's recent drivers - for (whichFormat = 0; whichFormat < nformats; whichFormat++) { - int format = pformats[whichFormat]; - - // Create the p-buffer. - niattribs = 0; - - if (rtt) { - iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FORMAT; - if (useFloat) { - iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FLOAT_RGB_NV; - } else { - iattributes[niattribs++] = WGLExt.WGL_TEXTURE_RGBA; - } + if (ivalues[8] != 0) { + System.err.print(" [pbuffer]"); + } + System.err.println(); + } + } - iattributes[niattribs++] = WGLExt.WGL_TEXTURE_TARGET; - iattributes[niattribs++] = rect ? WGLExt.WGL_TEXTURE_RECTANGLE_NV : WGLExt.WGL_TEXTURE_2D; + long tmpBuffer = 0; + int whichFormat = -1; + // Loop is a workaround for bugs in NVidia's recent drivers + for (whichFormat = 0; whichFormat < nformats; whichFormat++) { + int format = pformats[whichFormat]; - iattributes[niattribs++] = WGLExt.WGL_MIPMAP_TEXTURE; - iattributes[niattribs++] = GL.GL_FALSE; + // Create the p-buffer. + niattribs = 0; - iattributes[niattribs++] = WGLExt.WGL_PBUFFER_LARGEST; - iattributes[niattribs++] = GL.GL_FALSE; - } + if (rtt) { + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FORMAT; + if (useFloat) { + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_FLOAT_RGB_NV; + } else { + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_RGBA; + } - iattributes[niattribs++] = 0; + iattributes[niattribs++] = WGLExt.WGL_TEXTURE_TARGET; + iattributes[niattribs++] = rect ? WGLExt.WGL_TEXTURE_RECTANGLE_NV : WGLExt.WGL_TEXTURE_2D; - tmpBuffer = wglExt.wglCreatePbuffer(parentHdc, format, getWidth(), getHeight(), iattributes, 0); - if (tmpBuffer != 0) { - // Done - break; - } - } + iattributes[niattribs++] = WGLExt.WGL_MIPMAP_TEXTURE; + iattributes[niattribs++] = GL.GL_FALSE; - if (tmpBuffer == 0) { - throw new GLException("pbuffer creation error: wglCreatePbuffer() failed: tried " + nformats + - " pixel formats, last error was: " + wglGetLastError()); - } + iattributes[niattribs++] = WGLExt.WGL_PBUFFER_LARGEST; + iattributes[niattribs++] = GL.GL_FALSE; + } - // Get the device context. - long tmpHdc = wglExt.wglGetPbufferDC(tmpBuffer); - if (tmpHdc == 0) { - throw new GLException("pbuffer creation error: wglGetPbufferDC() failed"); - } + iattributes[niattribs++] = 0; - NullWindow nw = (NullWindow) getNativeWindow(); - // Set up instance variables - buffer = tmpBuffer; - nw.setSurfaceHandle(tmpHdc); - cachedWGLExt = wglExt; - cachedParentHdc = parentHdc; - - // Re-query chosen pixel format - { - niattribs = 0; - iattributes[niattribs++] = WGLExt.WGL_ACCELERATION; - iattributes[niattribs++] = WGLExt.WGL_RED_BITS; - iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS; - iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS; - iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS; - iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS; - iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS; - iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER; - iattributes[niattribs++] = WGLExt.WGL_STEREO; - iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS; - iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS; - iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS; - iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS; - iattributes[niattribs++] = (useFloat ? (ati ? WGLExt.WGL_PIXEL_TYPE: WGLExt.WGL_FLOAT_COMPONENTS_NV) : WGLExt.WGL_RED_BITS); - iattributes[niattribs++] = (haveMultisample ? WGLExt.WGL_SAMPLE_BUFFERS: WGLExt.WGL_RED_BITS); - iattributes[niattribs++] = (haveMultisample ? WGLExt.WGL_SAMPLES: WGLExt.WGL_RED_BITS); - iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_PBUFFER; - int[] ivalues = new int[niattribs]; - // FIXME: usually prefer to throw exceptions, but failure here is not critical - if (wglExt.wglGetPixelFormatAttribiv(parentHdc, pformats[whichFormat], 0, niattribs, iattributes, 0, ivalues, 0)) { - setChosenGLCapabilities(iattributes2GLCapabilities(iattributes, niattribs, ivalues, false)); - } - } + tmpBuffer = wglExt.wglCreatePbuffer(parentHdc, format, getWidth(), getHeight(), iattributes, 0); + if (tmpBuffer != 0) { + // Done + break; + } + } - // Determine the actual width and height we were able to create. - int[] tmp = new int[1]; - wglExt.wglQueryPbuffer( buffer, WGLExt.WGL_PBUFFER_WIDTH, tmp, 0 ); - width = tmp[0]; - wglExt.wglQueryPbuffer( buffer, WGLExt.WGL_PBUFFER_HEIGHT, tmp, 0 ); - height = tmp[0]; - nw.setSize(width, height); - } finally { - getFactoryImpl().unlockToolkit(); + if (tmpBuffer == 0) { + throw new GLException("pbuffer creation error: wglCreatePbuffer() failed: tried " + nformats + + " pixel formats, last error was: " + wglGetLastError()); } + // Get the device context. + long tmpHdc = wglExt.wglGetPbufferDC(tmpBuffer); + if (tmpHdc == 0) { + throw new GLException("pbuffer creation error: wglGetPbufferDC() failed"); + } + + NullWindow nw = (NullWindow) getNativeWindow(); + // Set up instance variables + buffer = tmpBuffer; + nw.setSurfaceHandle(tmpHdc); + cachedWGLExt = wglExt; + cachedParentHdc = parentHdc; + + // Re-query chosen pixel format + { + niattribs = 0; + iattributes[niattribs++] = WGLExt.WGL_ACCELERATION; + iattributes[niattribs++] = WGLExt.WGL_RED_BITS; + iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS; + iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS; + iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS; + iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS; + iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS; + iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER; + iattributes[niattribs++] = WGLExt.WGL_STEREO; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS; + iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS; + iattributes[niattribs++] = (useFloat ? (ati ? WGLExt.WGL_PIXEL_TYPE: WGLExt.WGL_FLOAT_COMPONENTS_NV) : WGLExt.WGL_RED_BITS); + iattributes[niattribs++] = (haveMultisample ? WGLExt.WGL_SAMPLE_BUFFERS: WGLExt.WGL_RED_BITS); + iattributes[niattribs++] = (haveMultisample ? WGLExt.WGL_SAMPLES: WGLExt.WGL_RED_BITS); + iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_PBUFFER; + int[] ivalues = new int[niattribs]; + // FIXME: usually prefer to throw exceptions, but failure here is not critical + if (wglExt.wglGetPixelFormatAttribiv(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.wglQueryPbuffer( buffer, WGLExt.WGL_PBUFFER_WIDTH, tmp, 0 ); + width = tmp[0]; + wglExt.wglQueryPbuffer( buffer, WGLExt.WGL_PBUFFER_HEIGHT, tmp, 0 ); + height = tmp[0]; + nw.setSize(width, height); + if (DEBUG) { System.err.println("Created pbuffer " + width + " x " + height); } |