diff options
author | Kenneth Russel <[email protected]> | 2005-10-24 19:21:03 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-10-24 19:21:03 +0000 |
commit | d6f9dbc493df725d3d574403549de142c5e1222a (patch) | |
tree | 8eb152b0627f8d1897a27c5204d6ce2efb4963e4 /src/net/java/games/jogl/impl/windows | |
parent | 42843c3290d64c41c9c8a18b93f5ad3c00d35ddc (diff) |
Merged JSR-231 branch on to the main JOGL trunk. The main trunk now
contains the evolving JSR-231 Reference Implementation and the JSR-231
branch is permanently closed.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@401 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/impl/windows')
5 files changed, 0 insertions, 2011 deletions
diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsGLContext.java deleted file mode 100644 index e838c68aa..000000000 --- a/src/net/java/games/jogl/impl/windows/WindowsGLContext.java +++ /dev/null @@ -1,717 +0,0 @@ -/* - * 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.awt.Component; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.Rectangle; -import java.util.*; -import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public abstract class WindowsGLContext extends GLContext { - private static JAWT jawt; - protected long hglrc; - protected long hdc; - private boolean wglGetExtensionsStringEXTInitialized; - private boolean wglGetExtensionsStringEXTAvailable; - private static final Map/*<String, String>*/ functionNameMap; - private static final Map/*<String, String>*/ extensionNameMap; - // Table that holds the addresses of the native C-language entry points for - // OpenGL functions. - private GLProcAddressTable glProcAddressTable; - // Handle to GLU32.dll - private long hglu32; - private boolean haveWGLARBPbuffer = true; - - private static final int MAX_PFORMATS = 256; - private static final int MAX_ATTRIBS = 256; - - static { - functionNameMap = new HashMap(); - functionNameMap.put("glAllocateMemoryNV", "wglAllocateMemoryNV"); - functionNameMap.put("glFreeMemoryNV", "wglFreeMemoryNV"); - - extensionNameMap = new HashMap(); - extensionNameMap.put("GL_ARB_pbuffer", "WGL_ARB_pbuffer"); - extensionNameMap.put("GL_ARB_pixel_format", "WGL_ARB_pixel_format"); - } - - public WindowsGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(component, capabilities, chooser, shareWith); - } - - protected GL createGL() - { - return new WindowsGLImpl(this); - } - - protected String mapToRealGLFunctionName(String glFunctionName) { - String lookup = (String) functionNameMap.get(glFunctionName); - if (lookup != null) { - return lookup; - } - return glFunctionName; - } - - protected String mapToRealGLExtensionName(String glExtensionName) { - String lookup = (String) extensionNameMap.get(glExtensionName); - if (lookup != null) { - return lookup; - } - return glExtensionName; - } - - protected abstract boolean isOffscreen(); - - public int getOffscreenContextWidth() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextHeight() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public abstract int getOffscreenContextReadBuffer(); - - public abstract boolean offscreenImageNeedsVerticalFlip(); - - /** - * Creates and initializes an appropriate OpenGL context. Should only be - * called by {@link #makeCurrent(Runnable)}. - */ - protected abstract void create(); - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - boolean created = false; - if (hglrc == 0) { - create(); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName()); - } - created = true; - } - - boolean skipMakeCurrent = false; - if (NO_FREE) { - if (WGL.wglGetCurrentContext() == hglrc) { - if (DEBUG && VERBOSE) { - System.err.println(getThreadName() + ": skipping wglMakeCurrent because context already current"); - } - skipMakeCurrent = true; - } - } - - if (!skipMakeCurrent) { - if (!WGL.wglMakeCurrent(hdc, hglrc)) { - throw new GLException("Error making context current: " + WGL.GetLastError()); - } else { - if (DEBUG && VERBOSE) { - System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + hdcToString(hdc) + - ", hglrc " + hdcToString(hglrc) + ") succeeded"); - } - } - } - - if (created) { - resetGLFunctionAvailability(); - haveWGLARBPbuffer = (isExtensionAvailable("WGL_ARB_pbuffer") && - isExtensionAvailable("WGL_ARB_pixel_format")); - // Windows can set up sharing of display lists after creation time - WindowsGLContext other = (WindowsGLContext) GLContextShareSet.getShareContext(this); - if (other != null) { - long hglrc2 = other.getHGLRC(); - if (hglrc2 == 0) { - throw new GLException("GLContextShareSet returned an invalid OpenGL context"); - } - if (!WGL.wglShareLists(hglrc2, hglrc)) { - throw new GLException("wglShareLists(0x" + Long.toHexString(hglrc2) + - ", 0x" + Long.toHexString(hglrc) + ") failed: error code " + - WGL.GetLastError()); - } - } - GLContextShareSet.contextCreated(this); - - initAction.run(); - } - return true; - } - - protected synchronized void free() throws GLException { - if (!NO_FREE) { - if (!WGL.wglMakeCurrent(0, 0)) { - throw new GLException("Error freeing OpenGL context: " + WGL.GetLastError()); - } - } - } - - protected void destroyImpl() throws GLException { - if (hglrc != 0) { - if (!WGL.wglDeleteContext(hglrc)) { - throw new GLException("Unable to delete OpenGL context"); - } - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Destroyed OpenGL context " + hglrc); - } - hglrc = 0; - } - } - - public abstract void swapBuffers() throws GLException; - - protected long dynamicLookupFunction(String glFuncName) { - long res = WGL.wglGetProcAddress(glFuncName); - if (res == 0) { - // GLU routines aren't known to the OpenGL function lookup - if (hglu32 == 0) { - hglu32 = WGL.LoadLibraryA("GLU32"); - if (hglu32 == 0) { - throw new GLException("Error loading GLU32.DLL"); - } - } - res = WGL.GetProcAddress(hglu32, glFuncName); - } - return res; - } - - public boolean isCreated() { - return (hglrc != 0); - } - - protected void resetGLFunctionAvailability() { - super.resetGLFunctionAvailability(); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Initializing OpenGL extension address table"); - } - resetProcAddressTable(getGLProcAddressTable()); - } - - public GLProcAddressTable getGLProcAddressTable() { - if (glProcAddressTable == null) { - // FIXME: cache ProcAddressTables by capability bits so we can - // share them among contexts with the same capabilities - glProcAddressTable = new GLProcAddressTable(); - } - return glProcAddressTable; - } - - public String getPlatformExtensionsString() { - if (!wglGetExtensionsStringEXTInitialized) { - wglGetExtensionsStringEXTAvailable = (WGL.wglGetProcAddress("wglGetExtensionsStringEXT") != 0); - wglGetExtensionsStringEXTInitialized = true; - } - if (wglGetExtensionsStringEXTAvailable) { - return gl.wglGetExtensionsStringEXT(); - } else { - return ""; - } - } - - protected boolean isFunctionAvailable(String glFunctionName) - { - boolean available = super.isFunctionAvailable(glFunctionName); - - // Sanity check for implementations that use proc addresses for run-time - // linking: if the function IS available, then make sure there's a proc - // address for it if it's an extension or not part of the OpenGL 1.1 core - // (post GL 1.1 functions are run-time linked on windows). - assert(!available || - (getGLProcAddressTable().getAddressFor(mapToRealGLFunctionName(glFunctionName)) != 0 || - FunctionAvailabilityCache.isPartOfGLCore("1.1", mapToRealGLFunctionName(glFunctionName))) - ); - - return available; - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - protected JAWT getJAWT() { - if (jawt == null) { - JAWT j = new JAWT(); - j.version(JAWTFactory.JAWT_VERSION_1_4); - if (!JAWTFactory.JAWT_GetAWT(j)) { - throw new RuntimeException("Unable to initialize JAWT"); - } - jawt = j; - } - return jawt; - } - - // Helper routine for the overridden create() to call - protected void choosePixelFormatAndCreateContext(boolean onscreen) { - PIXELFORMATDESCRIPTOR pfd = null; - int pixelFormat = 0; - if (onscreen) { - GLCapabilities[] availableCaps = null; - int numFormats = 0; - pfd = newPixelFormatDescriptor(); - GraphicsConfiguration config = component.getGraphicsConfiguration(); - GraphicsDevice device = config.getDevice(); - // Produce a recommended pixel format selection for the GLCapabilitiesChooser. - // Use wglChoosePixelFormatARB if user requested multisampling and if we have it available - GL dummyGL = null; - if (capabilities.getSampleBuffers()) { - dummyGL = WindowsGLContextFactory.getDummyGL(device); - } - int recommendedPixelFormat = -1; - boolean haveWGLChoosePixelFormatARB = false; - boolean haveWGLARBMultisample = false; - if (dummyGL != null) { - String availableWGLExtensions = WindowsGLContextFactory.getDummyGLExtensions(device); - if (availableWGLExtensions.indexOf("WGL_ARB_pixel_format") >= 0) { - haveWGLChoosePixelFormatARB = true; - if (availableWGLExtensions.indexOf("WGL_ARB_multisample") >= 0) { - haveWGLARBMultisample = true; - } - } - } - Rectangle rect = config.getBounds(); - long dc = 0; - long rc = 0; - boolean freeWGLC = false; - if( dummyGL != null ) { - dc = WindowsGLContextFactory.getDummyGLContext( device ).hdc; - rc = WindowsGLContextFactory.getDummyGLContext( device ).hglrc; - if( !WGL.wglMakeCurrent( dc, rc ) ) { - System.err.println(getThreadName() + ": Error Making WGLC Current: " + WGL.GetLastError() ); - } else { - freeWGLC = true; - } - } - // Fallback path for older cards, in particular Intel Extreme motherboard graphics - boolean gotAvailableCaps = false; - if (dummyGL != null && haveWGLChoosePixelFormatARB) { - int[] iattributes = new int [2 * MAX_ATTRIBS]; - int[] iresults = new int [2 * MAX_ATTRIBS]; - float[] fattributes = new float[2 * MAX_ATTRIBS]; - int niattribs = 0; - int nfattribs = 0; - iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - iattributes[niattribs++] = GL.WGL_DRAW_TO_WINDOW_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_TYPE_RGBA_ARB; - iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; - if (capabilities.getDoubleBuffered()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - iattributes[niattribs++] = GL.WGL_STEREO_ARB; - if (capabilities.getStereo()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; - iattributes[niattribs++] = capabilities.getDepthBits(); - iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; - iattributes[niattribs++] = capabilities.getRedBits(); - iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; - iattributes[niattribs++] = capabilities.getGreenBits(); - iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; - iattributes[niattribs++] = capabilities.getBlueBits(); - iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; - iattributes[niattribs++] = capabilities.getAlphaBits(); - iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; - iattributes[niattribs++] = capabilities.getStencilBits(); - if (capabilities.getAccumRedBits() > 0 || - capabilities.getAccumGreenBits() > 0 || - capabilities.getAccumBlueBits() > 0 || - capabilities.getAccumAlphaBits() > 0) { - iattributes[niattribs++] = GL.WGL_ACCUM_BITS_ARB; - iattributes[niattribs++] = (capabilities.getAccumRedBits() + - capabilities.getAccumGreenBits() + - capabilities.getAccumBlueBits() + - capabilities.getAccumAlphaBits()); - iattributes[niattribs++] = GL.WGL_ACCUM_RED_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumRedBits(); - iattributes[niattribs++] = GL.WGL_ACCUM_GREEN_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumGreenBits(); - iattributes[niattribs++] = GL.WGL_ACCUM_BLUE_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumBlueBits(); - iattributes[niattribs++] = GL.WGL_ACCUM_ALPHA_BITS_ARB; - iattributes[niattribs++] = capabilities.getAccumAlphaBits(); - } - if (haveWGLARBMultisample) { - if (capabilities.getSampleBuffers()) { - iattributes[niattribs++] = GL.WGL_SAMPLE_BUFFERS_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - iattributes[niattribs++] = GL.WGL_SAMPLES_ARB; - iattributes[niattribs++] = capabilities.getNumSamples(); - } - } - - int[] pformats = new int[MAX_PFORMATS]; - int[] numFormatsTmp = new int[1]; - if (dummyGL.wglChoosePixelFormatARB(hdc, - iattributes, - fattributes, - MAX_PFORMATS, - pformats, - numFormatsTmp)) { - numFormats = numFormatsTmp[0]; - if (numFormats > 0) { - // Remove one-basing of pixel format (added on later) - recommendedPixelFormat = pformats[0] - 1; - if (DEBUG) { - System.err.println(getThreadName() + ": Used wglChoosePixelFormatARB to recommend pixel format " + recommendedPixelFormat); - } - } - } else { - if (DEBUG) { - System.err.println(getThreadName() + ": wglChoosePixelFormatARB failed: " + WGL.GetLastError() ); - Thread.dumpStack(); - } - } - if (DEBUG) { - if (recommendedPixelFormat < 0) { - System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format"); - if (capabilities.getSampleBuffers()) { - System.err.print(" for multisampled GLCapabilities"); - } - System.err.println(); - } - } - - // Produce a list of GLCapabilities to give to the - // GLCapabilitiesChooser. - // Use wglGetPixelFormatAttribivARB instead of - // DescribePixelFormat to get higher-precision information - // about the pixel format (should make the GLCapabilities - // more precise as well...i.e., remove the - // "HardwareAccelerated" bit, which is basically - // meaningless, and put in whether it can render to a - // window, to a pbuffer, or to a pixmap) - niattribs = 0; - iattributes[0] = GL.WGL_NUMBER_PIXEL_FORMATS_ARB; - if (dummyGL.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, iresults)) { - numFormats = iresults[0]; - // Should we be filtering out the pixel formats which aren't - // applicable, as we are doing here? - // We don't have enough information in the GLCapabilities to - // represent those that aren't... - iattributes[niattribs++] = GL.WGL_DRAW_TO_WINDOW_ARB; - iattributes[niattribs++] = GL.WGL_ACCELERATION_ARB; - iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; - iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; - iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; - iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; - iattributes[niattribs++] = GL.WGL_STEREO_ARB; - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; - iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; - iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_RED_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_GREEN_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_BLUE_BITS_ARB; - iattributes[niattribs++] = GL.WGL_ACCUM_ALPHA_BITS_ARB; - if (haveWGLARBMultisample) { - iattributes[niattribs++] = GL.WGL_SAMPLE_BUFFERS_ARB; - iattributes[niattribs++] = GL.WGL_SAMPLES_ARB; - } - - availableCaps = new GLCapabilities[numFormats]; - for (int i = 0; i < numFormats; i++) { - if (!dummyGL.wglGetPixelFormatAttribivARB(hdc, i+1, 0, niattribs, iattributes, iresults)) { - throw new GLException("Error getting pixel format attributes for pixel format " + (i + 1) + " of device context"); - } - availableCaps[i] = iattributes2GLCapabilities(iattributes, iresults, niattribs, true); - } - if( freeWGLC ) { - WGL.wglMakeCurrent( 0, 0 ); - } - gotAvailableCaps = true; - } else { - int lastErr = WGL.GetLastError(); - // Intel Extreme graphics fails with a zero error code - if (lastErr != 0) { - throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB: error code " + WGL.GetLastError()); - } - } - } - - if (!gotAvailableCaps) { - if (DEBUG) { - if (!capabilities.getSampleBuffers()) { - System.err.println(getThreadName() + ": Using ChoosePixelFormat because multisampling not requested"); - } else { - System.err.println(getThreadName() + ": Using ChoosePixelFormat because no wglChoosePixelFormatARB: dummyGL = " + dummyGL); - } - } - pfd = glCapabilities2PFD(capabilities, onscreen); - // Remove one-basing of pixel format (added on later) - recommendedPixelFormat = WGL.ChoosePixelFormat(hdc, pfd) - 1; - - numFormats = WGL.DescribePixelFormat(hdc, 1, 0, null); - if (numFormats == 0) { - throw new GLException("Unable to enumerate pixel formats of window for GLCapabilitiesChooser"); - } - availableCaps = new GLCapabilities[numFormats]; - for (int i = 0; i < numFormats; i++) { - if (WGL.DescribePixelFormat(hdc, 1 + i, pfd.size(), pfd) == 0) { - throw new GLException("Error describing pixel format " + (1 + i) + " of device context"); - } - availableCaps[i] = pfd2GLCapabilities(pfd); - } - } - - // Supply information to chooser - pixelFormat = chooser.chooseCapabilities(capabilities, availableCaps, recommendedPixelFormat); - if ((pixelFormat < 0) || (pixelFormat >= numFormats)) { - throw new GLException("Invalid result " + pixelFormat + - " from GLCapabilitiesChooser (should be between 0 and " + - (numFormats - 1) + ")"); - } - if (DEBUG) { - System.err.println(getThreadName() + ": Chosen pixel format (" + pixelFormat + "):"); - System.err.println(availableCaps[pixelFormat]); - } - pixelFormat += 1; // one-base the index - if (WGL.DescribePixelFormat(hdc, pixelFormat, pfd.size(), pfd) == 0) { - throw new GLException("Error re-describing the chosen pixel format: " + WGL.GetLastError()); - } - } else { - // For now, use ChoosePixelFormat for offscreen surfaces until - // we figure out how to properly choose an offscreen- - // compatible pixel format - pfd = glCapabilities2PFD(capabilities, onscreen); - pixelFormat = WGL.ChoosePixelFormat(hdc, pfd); - } - if (!WGL.SetPixelFormat(hdc, pixelFormat, pfd)) { - int lastError = WGL.GetLastError(); - if (DEBUG) { - System.err.println(getThreadName() + ": SetPixelFormat failed: current context = " + WGL.wglGetCurrentContext() + - ", current DC = " + WGL.wglGetCurrentDC()); - System.err.println(getThreadName() + ": GetPixelFormat(hdc " + hdcToString(hdc) + ") returns " + WGL.GetPixelFormat(hdc)); - } - throw new GLException("Unable to set pixel format " + pixelFormat + " for device context " + hdcToString(hdc) + ": error code " + lastError); - } - hglrc = WGL.wglCreateContext(hdc); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Created OpenGL context " + hglrc + " for device context " + hdcToString(hdc) + " using pixel format " + pixelFormat); - } - if (hglrc == 0) { - throw new GLException("Unable to create OpenGL context"); - } - } - - protected long getHGLRC() { - return hglrc; - } - - static PIXELFORMATDESCRIPTOR glCapabilities2PFD(GLCapabilities caps, boolean onscreen) { - int colorDepth = (caps.getRedBits() + - caps.getGreenBits() + - caps.getBlueBits()); - if (colorDepth < 15) { - throw new GLException("Bit depths < 15 (i.e., non-true-color) not supported"); - } - PIXELFORMATDESCRIPTOR pfd = newPixelFormatDescriptor(); - int pfdFlags = (WGL.PFD_SUPPORT_OPENGL | - WGL.PFD_GENERIC_ACCELERATED); - if (caps.getDoubleBuffered()) { - pfdFlags |= WGL.PFD_DOUBLEBUFFER; - } - if (onscreen) { - pfdFlags |= WGL.PFD_DRAW_TO_WINDOW; - } else { - pfdFlags |= WGL.PFD_DRAW_TO_BITMAP; - } - pfd.dwFlags(pfdFlags); - pfd.iPixelType((byte) WGL.PFD_TYPE_RGBA); - pfd.cColorBits((byte) colorDepth); - pfd.cRedBits ((byte) caps.getRedBits()); - pfd.cGreenBits((byte) caps.getGreenBits()); - pfd.cBlueBits ((byte) caps.getBlueBits()); - pfd.cAlphaBits((byte) caps.getAlphaBits()); - int accumDepth = (caps.getAccumRedBits() + - caps.getAccumGreenBits() + - caps.getAccumBlueBits()); - pfd.cAccumBits ((byte) accumDepth); - pfd.cAccumRedBits ((byte) caps.getAccumRedBits()); - pfd.cAccumGreenBits((byte) caps.getAccumGreenBits()); - pfd.cAccumBlueBits ((byte) caps.getAccumBlueBits()); - pfd.cAccumAlphaBits((byte) caps.getAccumAlphaBits()); - pfd.cDepthBits((byte) caps.getDepthBits()); - pfd.cStencilBits((byte) caps.getStencilBits()); - pfd.iLayerType((byte) WGL.PFD_MAIN_PLANE); - return pfd; - } - - static PIXELFORMATDESCRIPTOR newPixelFormatDescriptor() { - PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR(); - pfd.nSize((short) pfd.size()); - pfd.nVersion((short) 1); - return pfd; - } - - static GLCapabilities pfd2GLCapabilities(PIXELFORMATDESCRIPTOR pfd) { - if ((pfd.dwFlags() & WGL.PFD_SUPPORT_OPENGL) == 0) { - return null; - } - GLCapabilities res = new GLCapabilities(); - res.setRedBits (pfd.cRedBits()); - res.setGreenBits (pfd.cGreenBits()); - res.setBlueBits (pfd.cBlueBits()); - res.setAlphaBits (pfd.cAlphaBits()); - res.setAccumRedBits (pfd.cAccumRedBits()); - res.setAccumGreenBits(pfd.cAccumGreenBits()); - res.setAccumBlueBits (pfd.cAccumBlueBits()); - res.setAccumAlphaBits(pfd.cAccumAlphaBits()); - res.setDepthBits (pfd.cDepthBits()); - res.setStencilBits (pfd.cStencilBits()); - res.setDoubleBuffered((pfd.dwFlags() & WGL.PFD_DOUBLEBUFFER) != 0); - res.setStereo ((pfd.dwFlags() & WGL.PFD_STEREO) != 0); - res.setHardwareAccelerated(((pfd.dwFlags() & WGL.PFD_GENERIC_FORMAT) == 0) || - ((pfd.dwFlags() & WGL.PFD_GENERIC_ACCELERATED) != 0)); - return res; - } - - static GLCapabilities iattributes2GLCapabilities(int[] iattribs, - int[] iresults, - int niattribs, - boolean requireRenderToWindow) { - GLCapabilities res = new GLCapabilities(); - for (int i = 0; i < niattribs; i++) { - switch (iattribs[i]) { - case GL.WGL_DRAW_TO_WINDOW_ARB: - if (iresults[i] != GL.GL_TRUE) - return null; - break; - - case GL.WGL_ACCELERATION_ARB: - res.setHardwareAccelerated(iresults[i] == GL.WGL_FULL_ACCELERATION_ARB); - break; - - case GL.WGL_SUPPORT_OPENGL_ARB: - if (iresults[i] != GL.GL_TRUE) - return null; - break; - - case GL.WGL_DEPTH_BITS_ARB: - res.setDepthBits(iresults[i]); - break; - - case GL.WGL_STENCIL_BITS_ARB: - res.setStencilBits(iresults[i]); - break; - - case GL.WGL_DOUBLE_BUFFER_ARB: - res.setDoubleBuffered(iresults[i] == GL.GL_TRUE); - break; - - case GL.WGL_STEREO_ARB: - res.setStereo(iresults[i] == GL.GL_TRUE); - break; - - case GL.WGL_PIXEL_TYPE_ARB: - if (iresults[i] != GL.WGL_TYPE_RGBA_ARB) - return null; - break; - - case GL.WGL_RED_BITS_ARB: - res.setRedBits(iresults[i]); - break; - - case GL.WGL_GREEN_BITS_ARB: - res.setGreenBits(iresults[i]); - break; - - case GL.WGL_BLUE_BITS_ARB: - res.setBlueBits(iresults[i]); - break; - - case GL.WGL_ALPHA_BITS_ARB: - res.setAlphaBits(iresults[i]); - break; - - case GL.WGL_ACCUM_RED_BITS_ARB: - res.setAccumRedBits(iresults[i]); - break; - - case GL.WGL_ACCUM_GREEN_BITS_ARB: - res.setAccumGreenBits(iresults[i]); - break; - - case GL.WGL_ACCUM_BLUE_BITS_ARB: - res.setAccumBlueBits(iresults[i]); - break; - - case GL.WGL_ACCUM_ALPHA_BITS_ARB: - res.setAccumAlphaBits(iresults[i]); - break; - - case GL.WGL_SAMPLE_BUFFERS_ARB: - res.setSampleBuffers(iresults[i] == GL.GL_TRUE); - break; - - case GL.WGL_SAMPLES_ARB: - res.setNumSamples(iresults[i]); - break; - - default: - throw new GLException("Unknown pixel format attribute " + iattribs[i]); - } - } - return res; - } - - protected static String hdcToString(long hdc) { - return "0x" + Long.toHexString(hdc); - } - - protected boolean haveWGLARBPbuffer() { - return haveWGLARBPbuffer; - } -} diff --git a/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java b/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java deleted file mode 100644 index dd6f8daca..000000000 --- a/src/net/java/games/jogl/impl/windows/WindowsGLContextFactory.java +++ /dev/null @@ -1,361 +0,0 @@ -/* - * 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.awt.Component; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.Rectangle; -import java.io.File; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.Collection; -import java.util.Iterator; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class WindowsGLContextFactory extends GLContextFactory { - private static final boolean DEBUG = Debug.debug("WindowsGLContextFactory"); - private static final boolean VERBOSE = Debug.verbose(); - - // On Windows we want to be able to use some extension routines like - // wglChoosePixelFormatARB during the creation of the user's first - // GLContext. However, this and other routines' function pointers - // aren't loaded by the driver until the first OpenGL context is - // created. The standard way of working around this chicken-and-egg - // problem is to create a dummy window, show it, send it a paint - // message, create an OpenGL context, fetch the needed function - // pointers, and then destroy the dummy window and context. It turns - // out that ATI cards need the dummy context to be current while - // wglChoosePixelFormatARB is called, so we cache the extension - // strings the dummy context reports as being available. - private static Map/*<GraphicsDevice, GL>*/ dummyContextMap = new HashMap(); - private static Map/*<GraphicsDevice, String>*/ dummyExtensionsMap = new HashMap(); - private static Set/*<GraphicsDevice >*/ pendingContextSet = new HashSet(); - - public WindowsGLContextFactory() { - AccessController.doPrivileged( new PrivilegedAction() { - public Object run() { - Runtime.getRuntime().addShutdownHook( new ShutdownHook() ); - - // Test for whether we should enable the single-threaded - // workaround for ATI cards. It appears that if we make any - // OpenGL context current on more than one thread on ATI cards - // on Windows then we see random failures like the inability - // to create more OpenGL contexts, or having just the next - // OpenGL SetPixelFormat operation fail with a GetNextError() - // code of 0 (but subsequent ones on subsequently-created - // windows succeed). These kinds of failures are obviously due - // to bugs in ATI's OpenGL drivers. Through trial and error it - // was found that specifying - // -DJOGL_SINGLE_THREADED_WORKAROUND=true on the command line - // caused these problems to completely disappear. Therefore at - // least on Windows we try to enable the single-threaded - // workaround before creating any OpenGL contexts. In the - // future, if problems are encountered on other platforms and - // -DJOGL_SINGLE_THREADED_WORKAROUND=true works around them, - // we may want to implement a workaround like this on other - // platforms. - - // The algorithm here is to try to find the system directory - // (assuming it is on the same drive as TMPDIR, exposed - // through the system property java.io.tmpdir) and see whether - // a known file in the ATI drivers is present; if it is, we - // enable the single-threaded workaround. - - // If any path down this code fails, we simply bail out -- we - // don't go to great lengths to figure out if the ATI drivers - // are present. We could add more checks here in the future if - // these appear to be insufficient. - - String tmpDirProp = System.getProperty("java.io.tmpdir"); - if (tmpDirProp != null) { - File file = new File(tmpDirProp); - if (file.isAbsolute()) { - File parent = null; - do { - parent = file.getParentFile(); - if (parent != null) { - file = parent; - } - } while (parent != null); - // Now the file contains just the drive letter - file = new File(new File(new File(file, "windows"), "system32"), "atioglxx.dll"); - if (file.exists()) { - SingleThreadedWorkaround.shouldDoWorkaround(); - } - } - } - - return( null ); - } - }); - } - - public GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GraphicsDevice device) { - return null; - } - - public GLContext createGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - if (component != null) { - return new WindowsOnscreenGLContext(component, capabilities, chooser, shareWith); - } else { - return new WindowsOffscreenGLContext(capabilities, chooser, shareWith); - } - } - - // Return cached GL context - public static WindowsGLContext getDummyGLContext( final GraphicsDevice device ) { - checkForDummyContext( device ); - NativeWindowStruct nws = (NativeWindowStruct) dummyContextMap.get(device); - return nws.getWindowsContext(); - } - - // Return cached extension string - public static String getDummyGLExtensions(final GraphicsDevice device) { - checkForDummyContext( device ); - String exts = (String) dummyExtensionsMap.get(device); - return (exts == null) ? "" : exts; - } - - // Return cached GL function pointers - public static GL getDummyGL(final GraphicsDevice device) { - checkForDummyContext( device ); - NativeWindowStruct nws = (NativeWindowStruct) dummyContextMap.get(device); - return( nws.getWindowsContext().getGL() ); - } - - /* - * Locate a cached native window, if one doesn't exist create one amd - * cache it. - */ - private static void checkForDummyContext( final GraphicsDevice device ) { - if (!pendingContextSet.contains(device) && !dummyContextMap.containsKey( device ) ) { - if (DEBUG) { - System.err.println("WindowsGLContextFactory.checkForDummyContext() called on thread " + - Thread.currentThread().getName()); - } - - pendingContextSet.add(device); - GraphicsConfiguration config = device.getDefaultConfiguration(); - Rectangle rect = config.getBounds(); - GLCapabilities caps = new GLCapabilities(); - caps.setDepthBits( 16 ); - // Create a context that we use to query pixel formats - WindowsOnscreenGLContext context = new WindowsOnscreenGLContext( null, caps, null, null ); - // Start a native thread and grab native screen resources from the thread - NativeWindowThread nwt = new NativeWindowThread( rect ); - nwt.start(); - long hWnd = 0; - long tempHDC = 0; - while( (hWnd = nwt.getHWND()) == 0 || (tempHDC = nwt.getHDC()) == 0 ) { - Thread.yield(); - } - // Choose a hardware accelerated pixel format - PIXELFORMATDESCRIPTOR pfd = context.glCapabilities2PFD( caps, true ); - int pixelFormat = WGL.ChoosePixelFormat( tempHDC, pfd ); - if( pixelFormat == 0 ) { - System.err.println("Pixel Format is Zero"); - pendingContextSet.remove(device); - return; - } - // Set the hardware accelerated pixel format - if (!WGL.SetPixelFormat(tempHDC, pixelFormat, pfd)) { - System.err.println("SetPixelFormat Failed"); - pendingContextSet.remove( device ); - return; - } - // Create a rendering context - long tempHGLRC = WGL.wglCreateContext( tempHDC ); - if( hWnd == 0 || tempHDC == 0 || tempHGLRC == 0 ) { - pendingContextSet.remove( device ); - return; - } - // Store native handles for later use - NativeWindowStruct nws = new NativeWindowStruct(); - nws.setHWND( hWnd ); - nws.setWindowsContext( context ); - nws.setWindowThread( nwt ); - long currentHDC = WGL.wglGetCurrentDC(); - long currentHGLRC = WGL.wglGetCurrentContext(); - // Make the new hardware accelerated context current - if( !WGL.wglMakeCurrent( tempHDC, tempHGLRC ) ) { - pendingContextSet.remove( device ); - return; - } - // Grab function pointers - context.hdc = tempHDC; - context.hglrc = tempHGLRC; - context.resetGLFunctionAvailability(); - context.createGL(); - pendingContextSet.remove( device ); - dummyContextMap.put( device, nws ); - String availableGLExtensions = ""; - String availableWGLExtensions = ""; - String availableEXTExtensions = ""; - try { - availableWGLExtensions = context.getGL().wglGetExtensionsStringARB( currentHDC ); - } catch( GLException e ) { - } - try { - availableEXTExtensions = context.getGL().wglGetExtensionsStringEXT(); - } catch( GLException e ) { - } - availableGLExtensions = context.getGL().glGetString( GL.GL_EXTENSIONS ); - dummyExtensionsMap.put(device, availableGLExtensions + " " + availableEXTExtensions + " " + availableWGLExtensions); - WGL.wglMakeCurrent( currentHDC, currentHGLRC ); - } - } - - /* - * This class stores handles to native resources that need to be destroyed - * at JVM shutdown. - */ - static class NativeWindowStruct { - private long HWND; - private WindowsGLContext windowsContext; - private Thread windowThread; - - public NativeWindowStruct() { - } - - public long getHDC() { - return( windowsContext.hdc ); - } - - public long getHGLRC() { - return( windowsContext.hglrc ); - } - - public void setHWND( long hwnd ) { - HWND = hwnd; - } - - public long getHWND() { - return( HWND ); - } - - public void setWindowsContext( WindowsGLContext context ) { - windowsContext = context; - } - - public WindowsGLContext getWindowsContext() { - return( windowsContext ); - } - - public void setWindowThread( Thread thread ) { - windowThread = thread; - } - - public Thread getWindowThread() { - return( windowThread ); - } - } - - /* - * Native HWDN and HDC handles must be created and destroyed on the same - * thread. - */ - - static class NativeWindowThread extends Thread { - private long HWND = 0; - private long HDC = 0; - private Rectangle rectangle; - - public NativeWindowThread( Rectangle rect ) { - rectangle = rect; - } - - public synchronized long getHWND() { - return( HWND ); - } - - public synchronized long getHDC() { - return( HDC ); - } - - public void run() { - // Create a native window and device context - synchronized (WindowsGLContextFactory.class) { - HWND = WGL.CreateDummyWindow( rectangle.x, rectangle.y, rectangle.width, rectangle.height ); - } - HDC = WGL.GetDC( HWND ); - - // Start the message pump at shutdown - WGL.NativeEventLoop(); - } - } - - /* - * This class is registered with the JVM to destroy all cached redering - * contexts, device contexts, and window handles. - */ - - class ShutdownHook extends Thread { - public void run() { - // Collect all saved screen resources - Collection c = dummyContextMap.values(); - Iterator iter = c.iterator(); - while( iter.hasNext() ) { - // NativeWindowStruct holds refs to native resources that need to be destroyed - NativeWindowStruct struct = (NativeWindowStruct)iter.next(); - // Restart native window threads to respond to window closing events - synchronized( struct.getWindowThread() ) { - struct.getWindowThread().notifyAll(); - } - // Destroy OpenGL rendering context - if( !WGL.wglDeleteContext( struct.getHGLRC() ) ) { - System.err.println( "Error Destroying NativeWindowStruct RC: " + WGL.GetLastError() ); - } - // Send context handles to native method for deletion - WGL.DestroyDummyWindow( struct.getHWND(), struct.getHDC() ); - } - } - } -} diff --git a/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java deleted file mode 100644 index c70607da7..000000000 --- a/src/net/java/games/jogl/impl/windows/WindowsOffscreenGLContext.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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.awt.image.BufferedImage; -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class WindowsOffscreenGLContext extends WindowsGLContext { - private long origbitmap; - private long hbitmap; - // Width and height of the underlying bitmap - private int width; - private int height; - - public WindowsOffscreenGLContext(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(null, capabilities, chooser, shareWith); - } - - protected GL createGL() - { - return new WindowsGLImpl(this); - } - - protected boolean isOffscreen() { - return true; - } - - public int getOffscreenContextWidth() { - return width; - } - - public int getOffscreenContextHeight() { - return height; - } - - public int getOffscreenContextPixelDataType() { - return GL.GL_UNSIGNED_BYTE; - } - - public int getOffscreenContextReadBuffer() { - // On Windows these contexts are always single-buffered - return GL.GL_FRONT; - } - - public boolean offscreenImageNeedsVerticalFlip() { - // We can take care of this in the DIB creation (see below) - return false; - } - - public boolean canCreatePbufferContext() { - // For now say no - return false; - } - - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - if (pendingOffscreenResize) { - if (pendingOffscreenWidth != width || pendingOffscreenHeight != height) { - if (hglrc != 0) { - destroyImpl(); - } - width = pendingOffscreenWidth; - height = pendingOffscreenHeight; - pendingOffscreenResize = false; - } - } - return super.makeCurrent(initAction); - } - - protected void destroyImpl() { - if (hglrc != 0) { - super.destroyImpl(); - // Must destroy OpenGL context, bitmap and device context - WGL.SelectObject(hdc, origbitmap); - WGL.DeleteObject(hbitmap); - WGL.DeleteDC(hdc); - origbitmap = 0; - hbitmap = 0; - hdc = 0; - } - } - - public synchronized void swapBuffers() throws GLException { - } - - protected void create() { - BITMAPINFO info = new BITMAPINFO(); - BITMAPINFOHEADER header = info.bmiHeader(); - int bitsPerPixel = (capabilities.getRedBits() + - capabilities.getGreenBits() + - capabilities.getBlueBits()); - header.biSize(header.size()); - header.biWidth(width); - // NOTE: negating the height causes the DIB to be in top-down row - // order rather than bottom-up; ends up being correct during pixel - // readback - header.biHeight(-1 * height); - header.biPlanes((short) 1); - header.biBitCount((short) bitsPerPixel); - header.biXPelsPerMeter(0); - header.biYPelsPerMeter(0); - header.biClrUsed(0); - header.biClrImportant(0); - header.biCompression(WGL.BI_RGB); - header.biSizeImage(width * height * bitsPerPixel / 8); - - hdc = WGL.CreateCompatibleDC(0); - if (hdc == 0) { - System.out.println("LastError: " + WGL.GetLastError()); - throw new GLException("Error creating device context for offscreen OpenGL context"); - } - hbitmap = WGL.CreateDIBSection(hdc, info, WGL.DIB_RGB_COLORS, 0, 0, 0); - if (hbitmap == 0) { - throw new GLException("Error creating offscreen bitmap of width " + width + - ", height " + height); - } - if ((origbitmap = WGL.SelectObject(hdc, hbitmap)) == 0) { - throw new GLException("Error selecting bitmap into new device context"); - } - - choosePixelFormatAndCreateContext(false); - } -} diff --git a/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java deleted file mode 100644 index 0dc1818fb..000000000 --- a/src/net/java/games/jogl/impl/windows/WindowsOnscreenGLContext.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * 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.awt.Component; -import java.util.*; - -import net.java.games.jogl.*; -import net.java.games.jogl.impl.*; - -public class WindowsOnscreenGLContext extends WindowsGLContext { - // Variables for lockSurface/unlockSurface - JAWT_DrawingSurface ds; - JAWT_DrawingSurfaceInfo dsi; - JAWT_Win32DrawingSurfaceInfo win32dsi; - - // Variables for pbuffer support - List pbuffersToInstantiate = new ArrayList(); - - public WindowsOnscreenGLContext(Component component, - GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - GLContext shareWith) { - super(component, capabilities, chooser, shareWith); - } - - public void invokeGL(Runnable runnable, boolean isReshape, Runnable initAction) throws GLException { - // Unfortunately, invokeGL can be called with the AWT tree lock - // held, and the Windows onscreen implementation of - // choosePixelFormatAndCreateContext calls - // Component.getGraphicsConfiguration(), which grabs the tree - // lock. To avoid deadlock we have to lock the tree lock before - // grabbing the GLContext's lock if we're going to create an - // OpenGL context during this call. This code might not be - // completely correct, and we might need to uniformly grab the AWT - // tree lock, which might become a performance issue... - if (hglrc == 0) { - synchronized(component.getTreeLock()) { - super.invokeGL(runnable, isReshape, initAction); - } - } else { - super.invokeGL(runnable, isReshape, initAction); - } - } - - protected GL createGL() - { - return new WindowsGLImpl(this); - } - - protected boolean isOffscreen() { - return false; - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - public boolean canCreatePbufferContext() { - return haveWGLARBPbuffer(); - } - - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - WindowsPbufferGLContext ctx = new WindowsPbufferGLContext(capabilities, initialWidth, initialHeight); - pbuffersToInstantiate.add(ctx); - return ctx; - } - - public void bindPbufferToTexture() { - throw new GLException("Should not call this"); - } - - public void releasePbufferFromTexture() { - throw new GLException("Should not call this"); - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - try { - if (!lockSurface()) { - return false; - } - boolean ret = super.makeCurrent(initAction); - if (ret) { - // Instantiate any pending pbuffers - while (!pbuffersToInstantiate.isEmpty()) { - WindowsPbufferGLContext ctx = - (WindowsPbufferGLContext) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1); - ctx.createPbuffer(hdc, hglrc); - } - } - return ret; - } catch (RuntimeException e) { - try { - unlockSurface(); - } catch (Exception e2) { - // do nothing if unlockSurface throws - } - throw(e); - } - } - - protected synchronized void free() throws GLException { - try { - super.free(); - } finally { - unlockSurface(); - } - } - - public synchronized void swapBuffers() throws GLException { - if (!WGL.SwapBuffers(hdc) && (WGL.GetLastError() != 0)) { - throw new GLException("Error swapping buffers"); - } - } - - private boolean lockSurface() throws GLException { - if (hdc != 0) { - throw new GLException("Surface already locked"); - } - ds = getJAWT().GetDrawingSurface(component); - if (ds == null) { - // Widget not yet realized - return false; - } - int res = ds.Lock(); - if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { - throw new GLException("Unable to lock surface"); - } - // See whether the surface changed and if so destroy the old - // OpenGL context so it will be recreated (NOTE: removeNotify - // should handle this case, but it may be possible that race - // conditions can cause this code to be triggered -- should test - // more) - if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { - if (hglrc != 0) { - if (!WGL.wglDeleteContext(hglrc)) { - throw new GLException("Unable to delete old GL context after surface changed"); - } - GLContextShareSet.contextDestroyed(this); - if (DEBUG) { - System.err.println(getThreadName() + ": !!! Destroyed OpenGL context " + hglrc + " due to JAWT_LOCK_SURFACE_CHANGED"); - } - hglrc = 0; - } - } - dsi = ds.GetDrawingSurfaceInfo(); - if (dsi == null) { - // Widget not yet realized - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - return false; - } - win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo(); - hdc = win32dsi.hdc(); - if (hdc == 0) { - // Widget not yet realized - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - win32dsi = null; - return false; - } - return true; - } - - private void unlockSurface() { - if (hdc == 0) { - throw new GLException("Surface already unlocked"); - } - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - win32dsi = null; - hdc = 0; - } - - protected void create() { - choosePixelFormatAndCreateContext(true); - } -} diff --git a/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java b/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java deleted file mode 100644 index 1d5d78296..000000000 --- a/src/net/java/games/jogl/impl/windows/WindowsPbufferGLContext.java +++ /dev/null @@ -1,529 +0,0 @@ -/* - * 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 WindowsPbufferGLContext extends WindowsGLContext { - private static final boolean DEBUG = Debug.debug("WindowsPbufferGLContext"); - - private int initWidth; - private int initHeight; - - private long buffer; // pbuffer handle - private int width; - private int height; - - // FIXME: kept around because we create the OpenGL context lazily to - // better integrate with the WindowsGLContext framework - private long parentHglrc; - - private static final int MAX_PFORMATS = 256; - private static final int MAX_ATTRIBS = 256; - - // State for render-to-texture and render-to-texture-rectangle support - private boolean created; - private boolean rtt; // render-to-texture? - private boolean hasRTT; // render-to-texture extension available? - private boolean rect; // render-to-texture-rectangle? - private int textureTarget; // e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_NV - private int texture; // actual texture object - private int floatMode; - - public WindowsPbufferGLContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { - super(null, capabilities, null, null); - this.initWidth = initialWidth; - this.initHeight = initialHeight; - if (initWidth <= 0 || initHeight <= 0) { - throw new GLException("Initial width and height of pbuffer must be positive (were (" + - initWidth + ", " + initHeight + "))"); - } - - if (DEBUG) { - System.out.println("Pbuffer caps on init: " + capabilities + - (capabilities.getOffscreenRenderToTexture() ? " [rtt]" : "") + - (capabilities.getOffscreenRenderToTextureRectangle() ? " [rect]" : "") + - (capabilities.getOffscreenFloatingPointBuffers() ? " [float]" : "")); - } - } - - public boolean canCreatePbufferContext() { - return false; - } - - public GLContext createPbufferContext(GLCapabilities capabilities, - int initialWidth, - int initialHeight) { - throw new GLException("Not supported"); - } - - public void bindPbufferToTexture() { - if (!rtt) { - throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + - "specified in its GLCapabilities"); - } - GL gl = getGL(); - gl.glBindTexture(textureTarget, texture); - if (rtt && hasRTT) { - if (!gl.wglBindTexImageARB(buffer, GL.WGL_FRONT_LEFT_ARB)) { - throw new GLException("Binding of pbuffer to texture failed: " + wglGetLastError()); - } - } - // Note that if the render-to-texture extension is not supported, - // we perform a glCopyTexImage2D in swapBuffers(). - } - - public void releasePbufferFromTexture() { - if (!rtt) { - throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + - "specified in its GLCapabilities"); - } - if (rtt && hasRTT) { - GL gl = getGL(); - if (!gl.wglReleaseTexImageARB(buffer, GL.WGL_FRONT_LEFT_ARB)) { - throw new GLException("Releasing of pbuffer from texture failed: " + wglGetLastError()); - } - } - } - - public void createPbuffer(long parentHdc, long parentHglrc) { - GL gl = getGL(); - // Must initally grab OpenGL function pointers while parent's - // context is current because otherwise we don't have the wgl - // extensions available to us - resetGLFunctionAvailability(); - - int[] iattributes = new int [2*MAX_ATTRIBS]; - float[] fattributes = new float[2*MAX_ATTRIBS]; - int nfattribs = 0; - int niattribs = 0; - - if (DEBUG) { - System.out.println("Pbuffer caps: " + capabilities + - (capabilities.getOffscreenRenderToTexture() ? " [rtt]" : "") + - (capabilities.getOffscreenRenderToTextureRectangle() ? " [rect]" : "") + - (capabilities.getOffscreenFloatingPointBuffers() ? " [float]" : "")); - } - - rtt = capabilities.getOffscreenRenderToTexture(); - rect = capabilities.getOffscreenRenderToTextureRectangle(); - boolean useFloat = capabilities.getOffscreenFloatingPointBuffers(); - boolean ati = false; - - // Since we are trying to create a pbuffer, the pixel format we - // request (and subsequently use) must be "p-buffer capable". - iattributes[niattribs++] = GL.WGL_DRAW_TO_PBUFFER_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - - if (rtt && !rect) { - throw new GLException("Render-to-texture-rectangle requires render-to-texture to be specified"); - } - - if (rect) { - if (!gl.isExtensionAvailable("GL_NV_texture_rectangle")) { - throw new GLException("Render-to-texture-rectangle requires GL_NV_texture_rectangle extension"); - } - } - - if (useFloat) { - if (!gl.isExtensionAvailable("WGL_ATI_pixel_format_float") && - !gl.isExtensionAvailable("WGL_NV_float_buffer")) { - throw new GLException("Floating-point pbuffers not supported by this hardware"); - } - - // Prefer NVidia extension over ATI - if (gl.isExtensionAvailable("WGL_NV_float_buffer")) { - ati = false; - floatMode = GLPbuffer.NV_FLOAT; - } else { - ati = true; - floatMode = GLPbuffer.ATI_FLOAT; - } - if (DEBUG) { - System.err.println("Using " + (ati ? "ATI" : "NVidia") + " floating-point extension"); - } - } - - if (useFloat && ati) { - if (rtt) { - throw new GLException("Render-to-floating-point-texture not supported on ATI hardware"); - } else { - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_TYPE_RGBA_FLOAT_ATI; - } - } else { - if (!rtt) { - // Currently we don't support non-truecolor visuals in the - // GLCapabilities, so we don't offer the option of making - // color-index pbuffers. - iattributes[niattribs++] = GL.WGL_PIXEL_TYPE_ARB; - iattributes[niattribs++] = GL.WGL_TYPE_RGBA_ARB; - } - } - - iattributes[niattribs++] = GL.WGL_DOUBLE_BUFFER_ARB; - if (capabilities.getDoubleBuffered()) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - - iattributes[niattribs++] = GL.WGL_DEPTH_BITS_ARB; - iattributes[niattribs++] = capabilities.getDepthBits(); - - iattributes[niattribs++] = GL.WGL_RED_BITS_ARB; - iattributes[niattribs++] = capabilities.getRedBits(); - - iattributes[niattribs++] = GL.WGL_GREEN_BITS_ARB; - iattributes[niattribs++] = capabilities.getGreenBits(); - - iattributes[niattribs++] = GL.WGL_BLUE_BITS_ARB; - iattributes[niattribs++] = capabilities.getBlueBits(); - - iattributes[niattribs++] = GL.WGL_ALPHA_BITS_ARB; - iattributes[niattribs++] = capabilities.getAlphaBits(); - - iattributes[niattribs++] = GL.WGL_STENCIL_BITS_ARB; - if (capabilities.getStencilBits() > 0) { - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = GL.GL_FALSE; - } - - if (capabilities.getAccumRedBits() > 0 || - capabilities.getAccumGreenBits() > 0 || - capabilities.getAccumBlueBits() > 0) { - iattributes[niattribs++] = GL.WGL_ACCUM_BITS_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - } - - if (useFloat && !ati) { - iattributes[niattribs++] = GL.WGL_FLOAT_COMPONENTS_NV; - iattributes[niattribs++] = GL.GL_TRUE; - } - - if (rtt) { - if (useFloat) { - assert(!ati); - if (!rect) { - throw new GLException("Render-to-floating-point-texture only supported on NVidia hardware with render-to-texture-rectangle"); - } - iattributes[niattribs++] = GL.WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV; - iattributes[niattribs++] = GL.GL_TRUE; - } else { - iattributes[niattribs++] = rect ? GL.WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV : GL.WGL_BIND_TO_TEXTURE_RGB_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - } - } - - iattributes[niattribs++] = GL.WGL_SUPPORT_OPENGL_ARB; - iattributes[niattribs++] = GL.GL_TRUE; - - int[] pformats = new int[MAX_PFORMATS]; - int nformats; - int[] nformatsTmp = new int[1]; - if (!gl.wglChoosePixelFormatARB(parentHdc, - iattributes, - fattributes, - MAX_PFORMATS, - pformats, - nformatsTmp)) { - throw new GLException("pbuffer creation error: wglChoosePixelFormatARB() failed"); - } - nformats = nformatsTmp[0]; - if (nformats <= 0) { - throw new GLException("pbuffer creation error: Couldn't find a suitable pixel format"); - } - - if (DEBUG) { - System.err.println("" + nformats + " suitable pixel formats found"); - // query pixel format - iattributes[0] = GL.WGL_RED_BITS_ARB; - iattributes[1] = GL.WGL_GREEN_BITS_ARB; - iattributes[2] = GL.WGL_BLUE_BITS_ARB; - iattributes[3] = GL.WGL_ALPHA_BITS_ARB; - iattributes[4] = GL.WGL_DEPTH_BITS_ARB; - iattributes[5] = (useFloat ? (ati ? GL.WGL_PIXEL_TYPE_ARB : GL.WGL_FLOAT_COMPONENTS_NV) : GL.WGL_RED_BITS_ARB); - iattributes[6] = GL.WGL_SAMPLE_BUFFERS_EXT; - iattributes[7] = GL.WGL_SAMPLES_EXT; - iattributes[8] = GL.WGL_DRAW_TO_PBUFFER_ARB; - int[] ivalues = new int[9]; - for (int i = 0; i < nformats; i++) { - if (!gl.wglGetPixelFormatAttribivARB(parentHdc, pformats[i], 0, 9, iattributes, ivalues)) { - 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]); - System.err.print(" multisample: " + ivalues[6]); - System.err.print(" samples: " + ivalues[7]); - if (useFloat) { - if (ati) { - if (ivalues[5] == GL.WGL_TYPE_RGBA_FLOAT_ATI) { - System.err.print(" [ati float]"); - } else if (ivalues[5] != GL.WGL_TYPE_RGBA_ARB) { - System.err.print(" [unknown pixel type " + ivalues[5] + "]"); - } - } else { - if (ivalues[5] != 0) { - System.err.print(" [float]"); - } - } - } - - if (ivalues[8] != 0) { - System.err.print(" [pbuffer]"); - } - System.err.println(); - } - } - - long tmpBuffer = 0; - int whichFormat = 0; - // Loop is a workaround for bugs in NVidia's recent drivers - do { - int format = pformats[whichFormat]; - - // Create the p-buffer. - niattribs = 0; - - if (rtt) { - iattributes[niattribs++] = GL.WGL_TEXTURE_FORMAT_ARB; - if (useFloat) { - iattributes[niattribs++] = GL.WGL_TEXTURE_FLOAT_RGB_NV; - } else { - iattributes[niattribs++] = GL.WGL_TEXTURE_RGBA_ARB; - } - - iattributes[niattribs++] = GL.WGL_TEXTURE_TARGET_ARB; - iattributes[niattribs++] = rect ? GL.WGL_TEXTURE_RECTANGLE_NV : GL.WGL_TEXTURE_2D_ARB; - - iattributes[niattribs++] = GL.WGL_MIPMAP_TEXTURE_ARB; - iattributes[niattribs++] = GL.GL_FALSE; - - iattributes[niattribs++] = GL.WGL_PBUFFER_LARGEST_ARB; - iattributes[niattribs++] = GL.GL_FALSE; - } - - iattributes[niattribs++] = 0; - - tmpBuffer = gl.wglCreatePbufferARB(parentHdc, format, initWidth, initHeight, iattributes); - ++whichFormat; - } while ((tmpBuffer == 0) && (whichFormat < nformats)); - - if (tmpBuffer == 0) { - throw new GLException("pbuffer creation error: wglCreatePbufferARB() failed: tried " + nformats + - " pixel formats, last error was: " + wglGetLastError()); - } - - // Get the device context. - long tmpHdc = gl.wglGetPbufferDCARB(tmpBuffer); - if (tmpHdc == 0) { - throw new GLException("pbuffer creation error: wglGetPbufferDCARB() failed"); - } - - this.parentHglrc = parentHglrc; - - // Set up instance variables - buffer = tmpBuffer; - hdc = tmpHdc; - - // Determine the actual width and height we were able to create. - int[] tmp = new int[1]; - gl.wglQueryPbufferARB( buffer, GL.WGL_PBUFFER_WIDTH_ARB, tmp ); - width = tmp[0]; - gl.wglQueryPbufferARB( buffer, GL.WGL_PBUFFER_HEIGHT_ARB, tmp ); - height = tmp[0]; - - if (DEBUG) { - System.err.println("Created pbuffer " + width + " x " + height); - } - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { - created = false; - - if (buffer == 0) { - // pbuffer not instantiated yet - if (DEBUG) { - System.err.println("pbuffer not instantiated yet"); - } - return false; - } - - boolean res = super.makeCurrent(initAction); - if (DEBUG) { - System.err.println("super.makeCurrent() = " + res + ", created = " + created); - } - if (created) { - // Initialize render-to-texture support if requested - rtt = capabilities.getOffscreenRenderToTexture(); - rect = capabilities.getOffscreenRenderToTextureRectangle(); - - if (rtt) { - if (DEBUG) { - System.err.println("Initializing render-to-texture support"); - } - - if (!gl.isExtensionAvailable("WGL_ARB_render_texture")) { - System.err.println("WindowsPbufferGLContext: WARNING: WGL_ARB_render_texture extension not " + - "supported; implementing render_to_texture support using slow texture readback"); - } else { - hasRTT = true; - GL gl = getGL(); - - if (rect && !gl.isExtensionAvailable("GL_NV_texture_rectangle")) { - System.err.println("WindowsPbufferGLContext: WARNING: GL_NV_texture_rectangle extension not " + - "supported; skipping requested render_to_texture_rectangle support for pbuffer"); - rect = false; - } - if (rect) { - if (DEBUG) { - System.err.println(" Using render-to-texture-rectangle"); - } - textureTarget = GL.GL_TEXTURE_RECTANGLE_NV; - } else { - if (DEBUG) { - System.err.println(" Using vanilla render-to-texture"); - } - textureTarget = GL.GL_TEXTURE_2D; - } - int[] tmp = new int[1]; - gl.glGenTextures(1, tmp); - texture = tmp[0]; - gl.glBindTexture(textureTarget, texture); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); - gl.glCopyTexImage2D(textureTarget, 0, GL.GL_RGB, 0, 0, width, height, 0); - } - } - } - return res; - } - - public void handleModeSwitch(long parentHdc, long parentHglrc) { - throw new GLException("Not yet implemented"); - } - - protected boolean isOffscreen() { - // FIXME: currently the only caller of this won't cause proper - // resizing of the pbuffer anyway. - return false; - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - protected void create() { - created = true; - // Create a gl context for the p-buffer. - hglrc = WGL.wglCreateContext(hdc); - if (hglrc == 0) { - throw new GLException("pbuffer creation error: wglCreateContext() failed"); - } - - // FIXME: provide option to not share display lists with subordinate pbuffer? - if (!WGL.wglShareLists(parentHglrc, hglrc)) { - throw new GLException("pbuffer: wglShareLists() failed"); - } - } - - protected void destroyImpl() throws GLException { - if (hglrc != 0) { - super.destroyImpl(); - // 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 - GL gl = createGL(); - if (gl.wglReleasePbufferDCARB(buffer, hdc) == 0) { - throw new GLException("Error releasing pbuffer device context: error code " + WGL.GetLastError()); - } - hdc = 0; - if (!gl.wglDestroyPbufferARB(buffer)) { - throw new GLException("Error destroying pbuffer: error code " + WGL.GetLastError()); - } - buffer = 0; - } - } - - public void swapBuffers() throws GLException { - // FIXME: do we need to do anything if the pbuffer is double-buffered? - // For now, just grab the pixels for the render-to-texture support. - if (rtt && !hasRTT) { - if (DEBUG) { - System.err.println("Copying pbuffer data to GL_TEXTURE_2D state"); - } - - GL gl = getGL(); - gl.glCopyTexSubImage2D(textureTarget, 0, 0, 0, 0, 0, width, height); - } - } - - public int getFloatingPointMode() { - return floatMode; - } - - private String wglGetLastError() { - int err = WGL.GetLastError(); - String detail = null; - switch (err) { - case WGL.ERROR_INVALID_PIXEL_FORMAT: detail = "ERROR_INVALID_PIXEL_FORMAT"; break; - case WGL.ERROR_NO_SYSTEM_RESOURCES: detail = "ERROR_NO_SYSTEM_RESOURCES"; break; - case WGL.ERROR_INVALID_DATA: detail = "ERROR_INVALID_DATA"; break; - case WGL.ERROR_PROC_NOT_FOUND: detail = "ERROR_PROC_NOT_FOUND"; break; - case WGL.ERROR_INVALID_WINDOW_HANDLE:detail = "ERROR_INVALID_WINDOW_HANDLE"; break; - default: detail = "(Unknown error code " + err + ")"; break; - } - return detail; - } -} |