diff options
Diffstat (limited to 'src/jogl/classes/jogamp')
10 files changed, 96 insertions, 86 deletions
diff --git a/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java b/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java index 55dd0fe11..a4fb1147c 100644 --- a/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java +++ b/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java @@ -52,20 +52,15 @@ import java.util.*; final class ExtensionAvailabilityCache { protected static final boolean DEBUG = GLContextImpl.DEBUG; - ExtensionAvailabilityCache(GLContextImpl context) - { - this.context = context; + ExtensionAvailabilityCache() { + flush(); } /** - * Flush the cache. The cache will be rebuilt lazily as calls to {@link - * #isExtensionAvailable(String)} are received. + * Flush the cache. */ final void flush() { - if(DEBUG) { - System.out.println("ExtensionAvailabilityCache: Flush availability OpenGL "+context.getGLVersion()); - } initialized = false; glExtensions = null; glExtensionCount = 0; @@ -75,11 +70,11 @@ final class ExtensionAvailabilityCache { } /** - * Flush the cache and rebuild the cache. + * Flush and rebuild the cache. */ - final void reset() { + final void reset(GLContextImpl context) { flush(); - initAvailableExtensions(); + initAvailableExtensions(context); } final boolean isInitialized() { @@ -87,45 +82,52 @@ final class ExtensionAvailabilityCache { } final int getTotalExtensionCount() { - initAvailableExtensions(); + validateInitialization(); return availableExtensionCache.size(); } final boolean isExtensionAvailable(String glExtensionName) { - initAvailableExtensions(); + validateInitialization(); return availableExtensionCache.contains(mapGLExtensionName(glExtensionName)); } final int getPlatformExtensionCount() { - initAvailableExtensions(); + validateInitialization(); return glXExtensionCount; } final String getPlatformExtensionsString() { - initAvailableExtensions(); + validateInitialization(); return glXExtensions; } final int getGLExtensionCount() { - initAvailableExtensions(); + validateInitialization(); return glExtensionCount; } final String getGLExtensionsString() { - initAvailableExtensions(); + validateInitialization(); if(DEBUG) { System.err.println("ExtensionAvailabilityCache: getGLExtensions() called"); } return glExtensions; } - private final void initAvailableExtensions() { - GL gl = context.getGL(); - // if hash is empty (meaning it was flushed), pre-cache it with the list - // of extensions that are in the GL_EXTENSIONS string - if (availableExtensionCache.isEmpty() || !initialized) { + private final void validateInitialization() { + if (!isInitialized()) { + throw new InternalError("ExtensionAvailabilityCache not initialized!"); + } + } + private final void initAvailableExtensions(GLContextImpl context) { + GL gl = context.getGL(); + // if hash is empty (meaning it was flushed), pre-cache it with the list + // of extensions that are in the GL_EXTENSIONS string + if (isInitialized()) { + throw new InternalError("ExtensionAvailabilityCache already initialized!"); + } if (DEBUG) { - System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Pre-caching init "+gl+", OpenGL "+context.getGLVersion()); + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Pre-caching init "+gl+", OpenGL "+context.getGLVersion()); } boolean useGetStringi = false; @@ -134,43 +136,43 @@ final class ExtensionAvailabilityCache { // on GL2 platforms the function might be available, but not working. if ( context.isGL3() ) { if ( ! context.isFunctionAvailable("glGetStringi") ) { - if(DEBUG) { - System.err.println("GLContext: GL >= 3.1 usage, but no glGetStringi"); - } + if(DEBUG) { + System.err.println("GLContext: GL >= 3.1 usage, but no glGetStringi"); + } } else { useGetStringi = true; } } if (DEBUG) { - System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Pre-caching extension availability OpenGL "+context.getGLVersion()+ - ", use "+ ( useGetStringi ? "glGetStringi" : "glGetString" ) ); + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Pre-caching extension availability OpenGL "+context.getGLVersion()+ + ", use "+ ( useGetStringi ? "glGetStringi" : "glGetString" ) ); } HashSet<String> glExtensionSet = new HashSet<String>(gl.isGLES() ? 50 : 320); // far less gl extension expected on mobile if(useGetStringi) { - GL2GL3 gl2gl3 = gl.getGL2GL3(); - final int count; - { - int[] val = { 0 } ; - gl2gl3.glGetIntegerv(GL2GL3.GL_NUM_EXTENSIONS, val, 0); - count = val[0]; - } - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < count; i++) { - if(i > 0) { - sb.append(" "); - } - final String ext = gl2gl3.glGetStringi(GL.GL_EXTENSIONS, i); - glExtensionSet.add(ext); - sb.append(ext); - } - if(0==count || sb.length()==0) { - // fall back .. - useGetStringi=false; - } else { - glExtensions = sb.toString(); - } + GL2GL3 gl2gl3 = gl.getGL2GL3(); + final int count; + { + int[] val = { 0 } ; + gl2gl3.glGetIntegerv(GL2GL3.GL_NUM_EXTENSIONS, val, 0); + count = val[0]; + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < count; i++) { + if(i > 0) { + sb.append(" "); + } + final String ext = gl2gl3.glGetStringi(GL.GL_EXTENSIONS, i); + glExtensionSet.add(ext); + sb.append(ext); + } + if(0==count || sb.length()==0) { + // fall back .. + useGetStringi=false; + } else { + glExtensions = sb.toString(); + } } if(!useGetStringi) { glExtensions = gl.glGetString(GL.GL_EXTENSIONS); @@ -183,9 +185,10 @@ final class ExtensionAvailabilityCache { } glExtensionCount = glExtensionSet.size(); if (DEBUG) { - System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL_EXTENSIONS: "+glExtensionCount); + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL_EXTENSIONS: "+glExtensionCount+ + ", used "+ ( useGetStringi ? "glGetStringi" : "glGetString" ) ); } - + // Platform Extensions HashSet<String> glXExtensionSet = new HashSet<String>(50); { @@ -204,10 +207,10 @@ final class ExtensionAvailabilityCache { glXExtensions = sb.toString(); glXExtensionCount = glXExtensionSet.size(); } - + availableExtensionCache.addAll(glExtensionSet); availableExtensionCache.addAll(glXExtensionSet); - + if (DEBUG) { System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GLX_EXTENSIONS: "+glXExtensionCount); System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL vendor: " + gl.glGetString(GL.GL_VENDOR)); @@ -218,11 +221,11 @@ final class ExtensionAvailabilityCache { int major[] = new int[] { context.getGLVersionMajor() }; int minor[] = new int[] { context.getGLVersionMinor() }; while (GLContext.isValidGLVersion(major[0], minor[0])) { - availableExtensionCache.add("GL_VERSION_" + major[0] + "_" + minor[0]); - if (DEBUG) { - System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Added GL_VERSION_" + major[0] + "_" + minor[0] + " to known extensions"); - } - if(!GLContext.decrementGLVersion(major, minor)) break; + availableExtensionCache.add("GL_VERSION_" + major[0] + "_" + minor[0]); + if (DEBUG) { + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Added GL_VERSION_" + major[0] + "_" + minor[0] + " to known extensions"); + } + if(!GLContext.decrementGLVersion(major, minor)) break; } } @@ -231,7 +234,6 @@ final class ExtensionAvailabilityCache { availableExtensionCache.add("<INTERNAL_DUMMY_PLACEHOLDER>"); initialized = true; - } } // FIXME: hack to re-enable GL_NV_vertex_array_range extension after @@ -254,7 +256,6 @@ final class ExtensionAvailabilityCache { private String glXExtensions = null; private int glXExtensionCount = 0; private HashSet<String> availableExtensionCache = new HashSet<String>(50); - private GLContextImpl context; static String getThreadName() { return Thread.currentThread().getName(); diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index f33c2bdb1..1924ba409 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -666,7 +666,7 @@ public abstract class GLContextImpl extends GLContext { private final void createContextARBMapVersionsAvailable(int reqMajor, boolean compat) { long _context; int reqProfile = compat ? CTX_PROFILE_COMPAT : CTX_PROFILE_CORE ; - int ctp = CTX_IS_ARB_CREATED | CTX_PROFILE_CORE | CTX_OPTION_ANY; // default + int ctp = CTX_IS_ARB_CREATED | CTX_PROFILE_CORE; // default if(compat) { ctp &= ~CTX_PROFILE_CORE ; ctp |= CTX_PROFILE_COMPAT ; @@ -697,7 +697,6 @@ public abstract class GLContextImpl extends GLContext { if(0==_context && !compat) { ctp &= ~CTX_PROFILE_COMPAT ; ctp |= CTX_PROFILE_CORE ; - ctp &= ~CTX_OPTION_ANY ; ctp |= CTX_OPTION_FORWARD ; _context = createContextARBVersions(0, true, ctp, /* max */ majorMax, minorMax, @@ -708,7 +707,6 @@ public abstract class GLContextImpl extends GLContext { ctp &= ~CTX_PROFILE_CORE ; ctp |= CTX_PROFILE_COMPAT ; ctp &= ~CTX_OPTION_FORWARD ; - ctp |= CTX_OPTION_ANY ; _context = createContextARBVersions(0, true, ctp, /* max */ majorMax, minorMax, /* min */ majorMin, minorMin, @@ -796,7 +794,7 @@ public abstract class GLContextImpl extends GLContext { * If major==0 && minor == 0 : Use GL_VERSION * Otherwise .. don't touch .. */ - private final void setContextVersion(int major, int minor, int ctp) { + private final void setContextVersion(int major, int minor, int ctp, boolean setVersionString) { if (0==ctp) { throw new GLException("Invalid GL Version "+major+"."+minor+", ctp "+toHexString(ctp)); } @@ -808,7 +806,9 @@ public abstract class GLContextImpl extends GLContext { ctxMajorVersion = major; ctxMinorVersion = minor; ctxOptions = ctp; - ctxVersionString = getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, getGL().glGetString(GL.GL_VERSION)); + if(setVersionString) { + ctxVersionString = getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, getGL().glGetString(GL.GL_VERSION)); + } return; } @@ -831,7 +831,9 @@ public abstract class GLContextImpl extends GLContext { ctxMajorVersion = 3; ctxMinorVersion = 0; } - ctxVersionString = getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, versionStr); + if(setVersionString) { + ctxVersionString = getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, versionStr); + } return; } } @@ -951,7 +953,9 @@ public abstract class GLContextImpl extends GLContext { AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration(); AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); - ctxProfileBits |= drawable.getChosenGLCapabilities().getHardwareAccelerated() ? GLContext.CTX_IMPL_ACCEL_HARD : GLContext.CTX_IMPL_ACCEL_SOFT; + if(!drawable.getChosenGLCapabilities().getHardwareAccelerated()) { + ctxProfileBits |= GLContext.CTX_IMPL_ACCEL_SOFT; + } contextFQN = getContextFQN(adevice, major, minor, ctxProfileBits); if (DEBUG) { System.err.println(getThreadName() + ": !!! Context FQN: "+contextFQN+" - "+GLContext.getGLVersion(major, minor, ctxProfileBits, null)); @@ -985,7 +989,7 @@ public abstract class GLContextImpl extends GLContext { } } } - + // // Update ExtensionAvailabilityCache // @@ -999,8 +1003,9 @@ public abstract class GLContextImpl extends GLContext { System.err.println(getThreadName() + ": !!! GLContext GL ExtensionAvailabilityCache reusing key("+contextFQN+") -> "+toHexString(eCache.hashCode()) + " - entries: "+eCache.getTotalExtensionCount()); } } else { - extensionAvailability = new ExtensionAvailabilityCache(this); - extensionAvailability.reset(); + extensionAvailability = new ExtensionAvailabilityCache(); + setContextVersion(major, minor, ctxProfileBits, false); // pre-set of GL version, required for extension cache usage + extensionAvailability.reset(this); synchronized(mappedContextTypeObjectLock) { mappedExtensionAvailabilityCache.put(contextFQN, extensionAvailability); if(DEBUG) { @@ -1013,15 +1018,17 @@ public abstract class GLContextImpl extends GLContext { } // - // Set GL Version + // Set GL Version (complete w/ version string) // - setContextVersion(major, minor, ctxProfileBits); + setContextVersion(major, minor, ctxProfileBits, true); } protected final void removeCachedVersion(int major, int minor, int ctxProfileBits) { AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration(); AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); - ctxProfileBits |= drawable.getChosenGLCapabilities().getHardwareAccelerated() ? GLContext.CTX_IMPL_ACCEL_HARD : GLContext.CTX_IMPL_ACCEL_SOFT; + if(!drawable.getChosenGLCapabilities().getHardwareAccelerated()) { + ctxProfileBits |= GLContext.CTX_IMPL_ACCEL_SOFT; + } contextFQN = getContextFQN(adevice, major, minor, ctxProfileBits); if (DEBUG) { System.err.println(getThreadName() + ": !!! RM Context FQN: "+contextFQN+" - "+GLContext.getGLVersion(major, minor, ctxProfileBits, null)); @@ -1041,7 +1048,7 @@ public abstract class GLContextImpl extends GLContext { } } } - + /** * Updates the platform's 'GLX' function cache */ @@ -1124,7 +1131,9 @@ public abstract class GLContextImpl extends GLContext { } protected static String getContextFQN(AbstractGraphicsDevice device, int major, int minor, int ctxProfileBits) { - ctxProfileBits &= ~GLContext.CTX_IMPL_ES2_COMPAT ; // remove non-key value + // remove non-key values + ctxProfileBits &= ~( GLContext.CTX_OPTION_DEBUG | GLContext.CTX_IMPL_ES2_COMPAT ) ; + return device.getUniqueID() + "-" + toHexString(composeBits(major, minor, ctxProfileBits)); } diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java index 24095c749..e1473e541 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java @@ -205,7 +205,7 @@ public abstract class EGLContext extends GLContextImpl { throw new GLException("Error making context 0x" + Long.toHexString(contextHandle) + " current: error code " + EGL.eglGetError()); } - int ctp = CTX_PROFILE_ES|CTX_OPTION_ANY; + int ctp = CTX_PROFILE_ES; int major; if(glProfile.usesNativeGLES2()) { ctp |= CTX_IMPL_ES2_COMPAT; diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java index 796a4311b..ff60a5262 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java @@ -45,7 +45,7 @@ public class EGLExternalContext extends EGLContext { public EGLExternalContext(AbstractGraphicsScreen screen) { super(null, null); GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, CTX_IS_ARB_CREATED|CTX_PROFILE_ES|CTX_OPTION_ANY); + setGLFunctionAvailability(false, 0, 0, CTX_IS_ARB_CREATED|CTX_PROFILE_ES); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java index 6ce2d7ba7..0e54b09ec 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java @@ -64,7 +64,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext { drawable.registerContext(this); this.contextHandle = handle; GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java index 70416d1f4..f41400d83 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/awt/MacOSXJava2DCGLContext.java @@ -97,7 +97,7 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL } return false; } - setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT); // use GL_VERSION contextHandle = ctx; return true; } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java index b183ad59f..b09a038d8 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLContext.java @@ -65,7 +65,7 @@ public class WindowsExternalWGLContext extends WindowsWGLContext { System.err.println(getThreadName() + ": !!! Created external OpenGL context " + toHexString(ctx) + " for " + this); } GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT); // use GL_VERSION getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java index 66c203a44..6fc5ab8d0 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java @@ -296,7 +296,7 @@ public class WindowsWGLContext extends GLContextImpl { if (!WGL.wglMakeCurrent(drawable.getHandle(), temp_ctx)) { throw new GLException("Error making temp context current: 0x" + toHexString(temp_ctx) + ", werr: "+GDI.GetLastError()); } - setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT); // use GL_VERSION boolean isCreateContextAttribsARBAvailable = isFunctionAvailable("wglCreateContextAttribsARB"); WGL.wglMakeCurrent(0, 0); // release temp context diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java index 4a949ea74..6334799c0 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java @@ -53,7 +53,7 @@ public class X11ExternalGLXContext extends X11GLXContext { super(drawable, null); this.contextHandle = ctx; GLContextShareSet.contextCreated(this); - setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); + setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT); getGLStateTracker().setEnabled(false); // external context usage can't track state in Java } diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java index d8813ed7f..0225c4284 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java @@ -220,7 +220,7 @@ public abstract class X11GLXContext extends GLContextImpl { if( !ctBwdCompat && ctFwdCompat ) { flags |= GLX.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; } - if( ctDebug) { + if( ctDebug ) { flags |= GLX.GLX_CONTEXT_DEBUG_BIT_ARB; } attribs.put(ctx_arb_attribs_idx_flags + 1, flags); @@ -305,7 +305,7 @@ public abstract class X11GLXContext extends GLContextImpl { if (!glXMakeContextCurrent(display, drawable.getHandle(), drawableRead.getHandle(), contextHandle)) { throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(contextHandle)+", drawable "+drawable); } - setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT); // use GL_VERSION isDirect = GLX.glXIsDirect(display, contextHandle); if (DEBUG) { System.err.println(getThreadName() + ": createContextImpl: OK (old-1) share "+share+", direct "+isDirect+"/"+direct); @@ -335,7 +335,7 @@ public abstract class X11GLXContext extends GLContextImpl { if (!glXMakeContextCurrent(display, drawable.getHandle(), drawableRead.getHandle(), temp_ctx)) { throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(temp_ctx)+", drawable "+drawable); } - setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION + setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT); // use GL_VERSION boolean isCreateContextAttribsARBAvailable = isFunctionAvailable("glXCreateContextAttribsARB"); glXMakeContextCurrent(display, 0, 0, 0); // release temp context |