diff options
author | Sven Gothel <[email protected]> | 2010-06-04 05:21:32 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-06-04 05:21:32 +0200 |
commit | 4512900ddcb9ce9a498411d257b1b6d6010ec006 (patch) | |
tree | ae9878c82cda41920f46ea639178f7d951d5af8f /src/jogl/classes/com/jogamp/opengl/impl/windows/wgl | |
parent | 6bbf70d2f4a06b8aa0b100d83ed9aca6dd80040e (diff) |
JOGL: Unify library loading (impl and binding), incl. lookup ; GLAutoDrawable: dispose() calls only with created context.
- Using the EGL approach of DynamicLookupHelper,
now generalized in abstract GLDynamicLookupHelper,
DesktopGLDynamicLookupHelper and EGLGLDynamicLookupHelper.
The implementation of these are self contained.
- Sharing common code.
- Unifying implementation and binding loading,
as well as the function lookup within the impl libs.
- Removed DRIHack, since its no more required
due to the new DesktopGLDynamicLookupHelper.
- Removed compile time link to GL and GLU libs
- Removed redundant library OS functions from X11/WGL
bindings, GlueGen's common code is being used now.
- GLAutoDrawable: dispose() calls only with created context.
This cleans up stack traces in case of eventual bugs,
where context creation is not successful.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/impl/windows/wgl')
4 files changed, 100 insertions, 53 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index e52c585de..3ecd3bdbc 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -243,8 +243,8 @@ public class WindowsWGLContext extends GLContextImpl { setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); if( createContextARBTried || - !isFunctionAvailable("wglCreateContextAttribsARB") || - !isExtensionAvailable("WGL_ARB_create_context") ) { + !isFunctionAvailable("wglCreateContextAttribsARB") /* || + !isExtensionAvailable("WGL_ARB_create_context") */ ) { // unresolved case where client version is 1.4 without this extension if(glCaps.getGLProfile().isGL3()) { WGL.wglMakeCurrent(0, 0); WGL.wglDeleteContext(temp_ctx); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java index 43c1ff5e0..274390b2c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawable.java @@ -39,7 +39,6 @@ package com.jogamp.opengl.impl.windows.wgl; -import com.jogamp.common.os.DynamicLookupHelper; import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.impl.*; @@ -119,8 +118,8 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { } } - public DynamicLookupHelper getDynamicLookupHelper() { - return (WindowsWGLDrawableFactory) getFactoryImpl() ; + public GLDynamicLookupHelper getGLDynamicLookupHelper() { + return WindowsWGLDynamicLookupHelper.getWindowsWGLDynamicLookupHelper(); } protected static String getThreadName() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index d2eb98bdf..8072ad2de 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -39,7 +39,6 @@ package com.jogamp.opengl.impl.windows.wgl; -import com.jogamp.common.os.DynamicLookupHelper; import java.nio.*; import java.util.*; import javax.media.nativewindow.*; @@ -50,15 +49,12 @@ import com.jogamp.common.util.*; import com.jogamp.opengl.impl.*; import com.jogamp.nativewindow.impl.NullWindow; -public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { +public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { private static final boolean VERBOSE = Debug.verbose(); - // Handle to GLU32.dll - // FIXME: this should go away once we delete support for the C GLU library - private long hglu32; - - // Handle to core OpenGL32.dll - private long hopengl32; + public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) { + return WindowsWGLDynamicLookupHelper.getWindowsWGLDynamicLookupHelper(); + } public WindowsWGLDrawableFactory() { super(); @@ -66,13 +62,12 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements // Register our GraphicsConfigurationFactory implementations // The act of constructing them causes them to be registered new WindowsWGLGraphicsConfigurationFactory(); + WindowsWGLDynamicLookupHelper.getWindowsWGLDynamicLookupHelper(); // setup and load .. try { ReflectionUtil.createInstance("com.jogamp.opengl.impl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory", new Object[] {}); } catch (JogampRuntimeException jre) { /* n/a .. */ } - loadOpenGL32Library(); - try { sharedDrawable = new WindowsDummyWGLDrawable(this, null); WindowsWGLContext ctx = (WindowsWGLContext) sharedDrawable.createContext(null); @@ -194,44 +189,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements return WindowsExternalWGLDrawable.create(this, null); } - public void loadOpenGL32Library() { - if (hopengl32 == 0) { - hopengl32 = WGL.LoadLibraryA("OpenGL32"); - if (DEBUG) { - if (hopengl32 == 0) { - System.err.println("WindowsWGLDrawableFactory: Could not load OpenGL32.dll - maybe an embedded device"); - } - } - } - } - - public void loadGLULibrary() { - if (hglu32 == 0) { - hglu32 = WGL.LoadLibraryA("GLU32"); - if (hglu32 == 0) { - throw new GLException("Error loading GLU32.DLL"); - } - } - } - - public long dynamicLookupFunction(String glFuncName) { - long res = WGL.wglGetProcAddress(glFuncName); - if (res == 0) { - // It may happen that a driver doesn't return the OpenGL32 core function pointer - // with wglGetProcAddress (e.g. NVidia GL 3.1) - hence we have to look harder. - if (hopengl32 != 0) { - res = WGL.GetProcAddress(hopengl32, glFuncName); - } - } - if (res == 0) { - // GLU routines aren't known to the OpenGL function lookup - if (hglu32 != 0) { - res = WGL.GetProcAddress(hglu32, glFuncName); - } - } - return res; - } - static String wglGetLastError() { long err = WGL.GetLastError(); String detail = null; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDynamicLookupHelper.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDynamicLookupHelper.java new file mode 100644 index 000000000..d0b0acaa3 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDynamicLookupHelper.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2010, Sven Gothel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of Sven Gothel nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 Sven Gothel 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. + */ + +package com.jogamp.opengl.impl.windows.wgl; + +import com.jogamp.opengl.impl.*; +import com.jogamp.common.os.DynamicLookupHelper; +import com.jogamp.common.os.NativeLibrary; +import com.jogamp.common.os.Platform; +import java.util.*; +import java.security.*; +import javax.media.opengl.GLException; + +public class WindowsWGLDynamicLookupHelper extends DesktopGLDynamicLookupHelper { + private static final WindowsWGLDynamicLookupHelper windowsWGLDynamicLookupHelper; + + static { + WindowsWGLDynamicLookupHelper tmp = null; + try { + tmp = new WindowsWGLDynamicLookupHelper(); + } catch (GLException gle) { + if(DEBUG) { + gle.printStackTrace(); + } + } + windowsWGLDynamicLookupHelper = tmp; + } + + public static WindowsWGLDynamicLookupHelper getWindowsWGLDynamicLookupHelper() { + return windowsWGLDynamicLookupHelper; + } + + protected WindowsWGLDynamicLookupHelper() { + super(); + } + + public synchronized void loadGLULibrary() { + if(null==gluLib) { + List/*<String>*/ gluLibNames = new ArrayList(); + gluLibNames.add("GLU32"); + gluLib = loadFirstAvailable(gluLibNames, null, false); + if(null != gluLib) { + glLibraries.add(gluLib); + } + } + } + NativeLibrary gluLib = null; + + protected final List/*<String>*/ getGLLibNames() { + List/*<String>*/ glesLibNames = new ArrayList(); + glesLibNames.add("OpenGL32"); + return glesLibNames; + } + + protected final List/*<String>*/ getGLXLibNames() { + return null; + } + + protected final String getGLXGetProcAddressFuncName() { + return "wglGetProcAddress" ; + } + + protected long dynamicLookupFunctionOnGLX(long glxGetProcAddressHandle, String glFuncName) { + return WGL.wglGetProcAddress(glFuncName); + } +} + |