diff options
author | Sven Gothel <[email protected]> | 2012-01-09 03:51:35 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-01-09 03:51:35 +0100 |
commit | c49d29784986b1945343b9a90b5e0c9f3d95d937 (patch) | |
tree | 96f7b12b4e230555b199235a7981ff82e3203f37 /src/jogl/classes/jogamp/opengl/windows/wgl | |
parent | 9e61d4529143ff3f6de15ce55f8e8747f67a86c9 (diff) |
Dispatch the '5' GDI/WGL functions and allow using their 'wgl' variants. GDI is the default.
The following 5 GDI functions have their 'wgl' counterparts
which 'shall' being used in case the OpenGL DLL is being loaded dynamically.
(So reads the documentation & FAQ).
This seems to be required only in case the std. opengl32.dll is not being used.
This use case is called GDI/ICD.
If using a non std. OpenGL DLL, is called MCD.
We dynamically load the OpenGL DLL and fetch the address pointer.
Since we generally use the std. opengl32.dll, our use of the GDI callbacks
seems to be legal. However, to test using the 'wgl' method WGLUtil is introduced.
You can test using the 'wgl' variants
by defining the property: 'jogl.windows.useWGLVersionOf5WGLGDIFuncSet'.
In case you have troubles, ie crashes within pixelformat setup etc,
it might be interesting if this may impact your behavior.
- ChoosePixelFormat(long, PIXELFORMATDESCRIPTOR)
- DescribePixelFormat(long, int, int, PIXELFORMATDESCRIPTOR)
- GetPixelFormat(long)
- SetPixelFormat(long, int, PIXELFORMATDESCRIPTOR)
- SwapBuffers(long)
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/windows/wgl')
7 files changed, 115 insertions, 21 deletions
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WGLUtil.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WGLUtil.java new file mode 100644 index 000000000..845d749ba --- /dev/null +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WGLUtil.java @@ -0,0 +1,95 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.opengl.windows.wgl; + +import java.security.AccessController; + +import jogamp.nativewindow.windows.GDI; +import jogamp.nativewindow.windows.PIXELFORMATDESCRIPTOR; +import jogamp.opengl.Debug; + +public class WGLUtil { + /** + * Switch to use the <code>wgl</code> variants of {@link jogamp.opengl.windows.wgl.WGL} + * to replace the following 5 GDI based functions (see below). + * <p> + * Disabled per default. + * </p> + * <p> + * You can enable it by defining the property <code>jogl.windows.useWGLVersionOf5WGLGDIFuncSet</code>. + * </p> + * + * @see jogamp.nativewindow.windows.GDI#ChoosePixelFormat(long, PIXELFORMATDESCRIPTOR) + * @see jogamp.nativewindow.windows.GDI#DescribePixelFormat(long, int, int, PIXELFORMATDESCRIPTOR) + * @see jogamp.nativewindow.windows.GDI#GetPixelFormat(long) + * @see jogamp.nativewindow.windows.GDI#SetPixelFormat(long, int, PIXELFORMATDESCRIPTOR) + * @see jogamp.nativewindow.windows.GDI#SwapBuffers(long) + */ + public static final boolean USE_WGLVersion_Of_5WGLGDIFuncSet; + + static { + USE_WGLVersion_Of_5WGLGDIFuncSet = Debug.isPropertyDefined("jogl.windows.useWGLVersionOf5WGLGDIFuncSet", true, AccessController.getContext()); + System.err.println("USE_WGLVersion_Of_5WGLGDIFuncSet: "+USE_WGLVersion_Of_5WGLGDIFuncSet); + } + + public static int ChoosePixelFormat(long hdc, PIXELFORMATDESCRIPTOR pfd) { + if(USE_WGLVersion_Of_5WGLGDIFuncSet) { + return WGL.wglChoosePixelFormat(hdc, pfd); + } else { + return GDI.ChoosePixelFormat(hdc, pfd); + } + } + public static int DescribePixelFormat(long hdc, int pfdid, int pfdSize, PIXELFORMATDESCRIPTOR pfd) { + if(USE_WGLVersion_Of_5WGLGDIFuncSet) { + return WGL.wglDescribePixelFormat(hdc, pfdid, pfdSize, pfd); + } else { + return GDI.DescribePixelFormat(hdc, pfdid, pfdSize, pfd); + } + } + public static int GetPixelFormat(long hdc) { + if(USE_WGLVersion_Of_5WGLGDIFuncSet) { + return WGL.wglGetPixelFormat(hdc); + } else { + return GDI.GetPixelFormat(hdc); + } + } + public static boolean SetPixelFormat(long hdc, int pfdid, PIXELFORMATDESCRIPTOR pfd) { + if(USE_WGLVersion_Of_5WGLGDIFuncSet) { + return WGL.wglSetPixelFormat(hdc, pfdid, pfd); + } else { + return GDI.SetPixelFormat(hdc, pfdid, pfd); + } + } + public static boolean SwapBuffers(long hdc) { + if(USE_WGLVersion_Of_5WGLGDIFuncSet) { + return WGL.wglSwapBuffers(hdc); + } else { + return GDI.SwapBuffers(hdc); + } + } +} diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java index f33dd21b0..b183ad59f 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java @@ -85,7 +85,7 @@ public class WindowsExternalWGLContext extends WindowsWGLContext { } AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); WindowsWGLGraphicsConfiguration cfg; - final int pfdID = GDI.GetPixelFormat(hdc); + final int pfdID = WGLUtil.GetPixelFormat(hdc); if (0 == pfdID) { // This could have happened if the HDC was released right after the GL ctx made current (SWT), // WinXP-32bit will not be able to use this HDC afterwards. diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java index ede504735..1e5991821 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java @@ -63,7 +63,7 @@ public class WindowsExternalWGLDrawable extends WindowsWGLDrawable { if (0==hdc) { throw new GLException("Error: attempted to make an external GLDrawable without a drawable current, werr " + GDI.GetLastError()); } - int pfdID = GDI.GetPixelFormat(hdc); + int pfdID = WGLUtil.GetPixelFormat(hdc); if (pfdID == 0) { throw new GLException("Error: attempted to make an external GLContext without a valid pixelformat, werr " + GDI.GetLastError()); } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLDrawable.java index 4f34c946a..6ad330ccc 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsOnscreenWGLDrawable.java @@ -42,7 +42,6 @@ package jogamp.opengl.windows.wgl; import javax.media.nativewindow.*; import javax.media.opengl.*; -import jogamp.opengl.*; public class WindowsOnscreenWGLDrawable extends WindowsWGLDrawable { protected WindowsOnscreenWGLDrawable(GLDrawableFactory factory, NativeSurface component) { diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawable.java index 2e0f6b848..b96e0cd9b 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawable.java @@ -77,22 +77,22 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { protected final void swapBuffersImpl() { // single-buffer is already filtered out @ GLDrawableImpl#swapBuffers() - long startTime = 0; + final long t0; if (PROFILING) { - startTime = System.currentTimeMillis(); + t0 = System.currentTimeMillis(); + } else { + t0 = 0; } - if (!GDI.SwapBuffers(getHandle()) && (GDI.GetLastError() != GDI.ERROR_SUCCESS)) { + if (!WGLUtil.SwapBuffers(getHandle()) && (GDI.GetLastError() != GDI.ERROR_SUCCESS)) { throw new GLException("Error swapping buffers"); } if (PROFILING) { - long endTime = System.currentTimeMillis(); - profilingSwapBuffersTime += (endTime - startTime); - int ticks = PROFILING_TICKS; - if (++profilingSwapBuffersTicks == ticks) { - System.err.println("SwapBuffers calls: " + profilingSwapBuffersTime + " ms / " + ticks + " calls (" + - ((float) profilingSwapBuffersTime / (float) ticks) + " ms/call)"); + profilingSwapBuffersTime += System.currentTimeMillis() - t0; + if (++profilingSwapBuffersTicks == PROFILING_TICKS) { + System.err.println("SwapBuffers calls: " + profilingSwapBuffersTime + " ms / " + PROFILING_TICKS + " calls (" + + ((float) profilingSwapBuffersTime / (float) PROFILING_TICKS) + " ms/call)"); profilingSwapBuffersTime = 0; profilingSwapBuffersTicks = 0; } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java index 2fcded885..d6788f1c9 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java @@ -161,7 +161,7 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio throw new GLException("Error: HDC is null"); } - if (!GDI.SetPixelFormat(hdc, caps.getPFDID(), caps.getPFD())) { + if (!WGLUtil.SetPixelFormat(hdc, caps.getPFDID(), caps.getPFD())) { throw new GLException("Unable to set pixel format " + caps + " for device context " + toHexString(hdc) + ": error code " + GDI.GetLastError()); @@ -610,7 +610,7 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio } PIXELFORMATDESCRIPTOR pfd = createPixelFormatDescriptor(); - if (GDI.DescribePixelFormat(hdc, pfdID, PIXELFORMATDESCRIPTOR.size(), pfd) == 0) { + if (WGLUtil.DescribePixelFormat(hdc, pfdID, PIXELFORMATDESCRIPTOR.size(), pfd) == 0) { // remove displayable bits, since pfdID is non displayable drawableTypeBits = drawableTypeBits & ~(GLGraphicsConfigurationUtil.WINDOW_BIT | GLGraphicsConfigurationUtil.BITMAP_BIT); if( 0 == drawableTypeBits ) { @@ -629,7 +629,7 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio // static int[] wglAllGDIPFIDs(long hdc) { - int numFormats = GDI.DescribePixelFormat(hdc, 1, 0, null); + int numFormats = WGLUtil.DescribePixelFormat(hdc, 1, 0, null); if (numFormats == 0) { throw new GLException("DescribePixelFormat: No formats - HDC 0x" + Long.toHexString(hdc) + ", LastError: " + GDI.GetLastError()); @@ -736,7 +736,7 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio pfd.setNSize((short) PIXELFORMATDESCRIPTOR.size()); pfd.setNVersion((short) 1); if(0 != hdc && 1 <= pfdID) { - if (GDI.DescribePixelFormat(hdc, pfdID, PIXELFORMATDESCRIPTOR.size(), pfd) == 0) { + if (WGLUtil.DescribePixelFormat(hdc, pfdID, PIXELFORMATDESCRIPTOR.size(), pfd) == 0) { // Accelerated pixel formats that are non displayable if(DEBUG) { System.err.println("Info: Non displayable pixel format " + pfdID + " of device context: error code " + GDI.GetLastError()); diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index edcaa4a24..f02520136 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -200,8 +200,8 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat // set PFD if not set yet int pfdID = -1; boolean set = false; - if ( 1 > ( pfdID = GDI.GetPixelFormat(hdc) ) ) { - if (!GDI.SetPixelFormat(hdc, config.getPixelFormatID(), config.getPixelFormat())) { + if ( 1 > ( pfdID = WGLUtil.GetPixelFormat(hdc) ) ) { + if (!WGLUtil.SetPixelFormat(hdc, config.getPixelFormatID(), config.getPixelFormat())) { throw new GLException("Unable to set pixel format " + config.getPixelFormatID() + " for device context " + toHexString(hdc) + ": error code " + GDI.GetLastError()); @@ -311,7 +311,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat WGLGLCapabilities pixelFormatCaps = null; // chosen or preset PFD ID's caps boolean pixelFormatSet = false; // indicates a preset PFD ID [caps] - final int presetPFDID = extHDC ? -1 : GDI.GetPixelFormat(hdc) ; + final int presetPFDID = extHDC ? -1 : WGLUtil.GetPixelFormat(hdc) ; if ( 1 <= presetPFDID ) { // Pixelformat already set by either // - a previous preselectGraphicsConfiguration() call on the same HDC, @@ -433,7 +433,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat WGLGLCapabilities pixelFormatCaps = null; // chosen or preset PFD ID's caps boolean pixelFormatSet = false; // indicates a preset PFD ID [caps] - if ( !extHDC && 1 <= ( pfdID = GDI.GetPixelFormat(hdc) ) ) { + if ( !extHDC && 1 <= ( pfdID = WGLUtil.GetPixelFormat(hdc) ) ) { // Pixelformat already set by either // - a previous preselectGraphicsConfiguration() call on the same HDC, // - the graphics driver, copying the HDC's pixelformat to the new one, @@ -457,7 +457,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as preferred choice PIXELFORMATDESCRIPTOR pfd = WindowsWGLGraphicsConfiguration.createPixelFormatDescriptor(); pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(capsChosen, pfd); - pfdID = GDI.ChoosePixelFormat(hdc, pfd); + pfdID = WGLUtil.ChoosePixelFormat(hdc, pfd); int recommendedIndex = -1 ; if( 1 <= pfdID ) { // seek index .. |