diff options
author | Sven Gothel <[email protected]> | 2012-02-13 23:17:56 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-02-13 23:17:56 +0100 |
commit | 0da7eeff106c1a2bf9e730c504a09e38360f141e (patch) | |
tree | 3af86256e48a5fbda6b362aebf457e11fcb71538 /src/jogl | |
parent | 5aff72256a49af51c002a07526174b23cc040b6e (diff) |
Enhance ExtensionAvailabilityCache ; Expose extension count in GLContext (and clean up)
- GLContext
- Expose isFunctionAvailable(), isExtensionAvailable(),
getPlatformExtensionCount(), getGLExtensionCount()
- sort methods a bit
ExtensionAvailabilityCache:
- Favor StringBuilder instead of StringBuffer (faster)
- Resuse set's
- Hold dedicated counts of extensions, platform and GL
Diffstat (limited to 'src/jogl')
8 files changed, 150 insertions, 106 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/JoglVersion.java b/src/jogl/classes/com/jogamp/opengl/JoglVersion.java index bf7eb0770..40790e770 100644 --- a/src/jogl/classes/com/jogamp/opengl/JoglVersion.java +++ b/src/jogl/classes/com/jogamp/opengl/JoglVersion.java @@ -123,29 +123,29 @@ public class JoglVersion extends JogampVersion { .append(device.getType()).append(", connection ").append(device.getConnection()).append("]: ").append(Platform.getNewline()); GLProfile.glAvailabilityToString(device, sb, "\t", 1); sb.append(Platform.getNewline()); - sb.append("Swap Interval ").append(gl.getSwapInterval()); + sb.append("Swap Interval ").append(gl.getSwapInterval()); sb.append(Platform.getNewline()); - sb.append("GL Profile ").append(gl.getGLProfile()); + sb.append("GL Profile ").append(gl.getGLProfile()); sb.append(Platform.getNewline()); - sb.append("CTX VERSION ").append(gl.getContext().getGLVersion()); + sb.append("CTX VERSION ").append(gl.getContext().getGLVersion()); sb.append(Platform.getNewline()); - sb.append("GL ").append(gl); + sb.append("GL ").append(gl); sb.append(Platform.getNewline()); - sb.append("GL_VENDOR ").append(gl.glGetString(GL.GL_VENDOR)); + sb.append("GL_VENDOR ").append(gl.glGetString(GL.GL_VENDOR)); sb.append(Platform.getNewline()); - sb.append("GL_RENDERER ").append(gl.glGetString(GL.GL_RENDERER)); + sb.append("GL_RENDERER ").append(gl.glGetString(GL.GL_RENDERER)); sb.append(Platform.getNewline()); - sb.append("GL_VERSION ").append(gl.glGetString(GL.GL_VERSION)); + sb.append("GL_VERSION ").append(gl.glGetString(GL.GL_VERSION)); sb.append(Platform.getNewline()); - sb.append("GL_EXTENSIONS "); + sb.append("GL_EXTENSIONS ").append(ctx.getGLExtensionCount()); sb.append(Platform.getNewline()); - sb.append(" ").append(ctx.getGLExtensionsString()); + sb.append(" ").append(ctx.getGLExtensionsString()); sb.append(Platform.getNewline()); - sb.append("GLX_EXTENSIONS"); + sb.append("GLX_EXTENSIONS ").append(ctx.getPlatformExtensionCount()); sb.append(Platform.getNewline()); - sb.append(" ").append(ctx.getPlatformExtensionsString()); + sb.append(" ").append(ctx.getPlatformExtensionsString()); sb.append(Platform.getNewline()); - sb.append("GLSL ").append(gl.hasGLSL()).append(", shader-compiler: ").append(gl.isFunctionAvailable("glCompileShader")); + sb.append("GLSL ").append(gl.hasGLSL()).append(", shader-compiler: ").append(gl.isFunctionAvailable("glCompileShader")); sb.append(Platform.getNewline()); sb.append(VersionUtil.SEPERATOR); diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 0cf92fb14..41acf3e37 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -426,12 +426,43 @@ public abstract class GLContext { return sb; } + /** + * Returns true if the specified OpenGL core- or extension-function can be + * successfully called using this GL context given the current host (OpenGL + * <i>client</i>) and display (OpenGL <i>server</i>) configuration. + * + * See {@link GL#isFunctionAvailable(String)} for more details. + * + * @param glFunctionName the name of the OpenGL function (e.g., use + * "glPolygonOffsetEXT" or "glPolygonOffset" to check if the {@link + * javax.media.opengl.GL#glPolygonOffset(float,float)} is available). + */ + public abstract boolean isFunctionAvailable(String glFunctionName); + + /** + * Returns true if the specified OpenGL extension can be + * successfully called using this GL context given the current host (OpenGL + * <i>client</i>) and display (OpenGL <i>server</i>) configuration. + * + * See {@link GL#isExtensionAvailable(String)} for more details. + * + * @param glExtensionName the name of the OpenGL extension (e.g., + * "GL_VERTEX_PROGRAM_ARB"). + */ + public abstract boolean isExtensionAvailable(String glExtensionName); + + /** Returns the number of platform extensions */ + public abstract int getPlatformExtensionCount(); + /** Returns a non-null (but possibly empty) string containing the space-separated list of available platform-dependent (e.g., WGL, GLX) extensions. Can only be called while this context is current. */ public abstract String getPlatformExtensionsString(); + /** Returns the number of OpenGL extensions */ + public abstract int getGLExtensionCount(); + /** Returns a non-null (but possibly empty) string containing the space-separated list of available extensions. Can only be called while this context is current. @@ -440,14 +471,6 @@ public abstract class GLContext { */ public abstract String getGLExtensionsString(); - public final int getGLVersionMajor() { return ctxMajorVersion; } - public final int getGLVersionMinor() { return ctxMinorVersion; } - public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); } - public final boolean isGLCoreProfile() { return ( 0 != ( CTX_PROFILE_CORE & ctxOptions ) ); } - public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); } - public final boolean isGLDebugEnabled() { return ( 0 != ( CTX_OPTION_DEBUG & ctxOptions ) ); } - public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); } - /** * @return Additional context creation flags, supported: {@link GLContext#CTX_OPTION_DEBUG}. */ @@ -510,6 +533,27 @@ public abstract class GLContext { return ctxVersionString; } + public final int getGLVersionMajor() { return ctxMajorVersion; } + public final int getGLVersionMinor() { return ctxMinorVersion; } + public final boolean isGLCompatibilityProfile() { return ( 0 != ( CTX_PROFILE_COMPAT & ctxOptions ) ); } + public final boolean isGLCoreProfile() { return ( 0 != ( CTX_PROFILE_CORE & ctxOptions ) ); } + public final boolean isGLForwardCompatible() { return ( 0 != ( CTX_OPTION_FORWARD & ctxOptions ) ); } + public final boolean isGLDebugEnabled() { return ( 0 != ( CTX_OPTION_DEBUG & ctxOptions ) ); } + public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); } + + /** + * @return true if this context is an ES2 context or implements + * the extension <code>GL_ARB_ES2_compatibility</code>, otherwise false + */ + public final boolean isGLES2Compatible() { + return 0 != ( ctxOptions & CTX_IMPL_ES2_COMPAT ) ; + } + + public final boolean hasGLSL() { + return isGL2ES2() ; + } + + public final boolean isGL4bc() { return ctxMajorVersion>=4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED) && 0 != (ctxOptions & CTX_PROFILE_COMPAT); @@ -560,18 +604,6 @@ public abstract class GLContext { return isGL2GL3() || isGLES2() ; } - /** - * @return true if this context is an ES2 context or implements - * the extension <code>GL_ARB_ES2_compatibility</code>, otherwise false - */ - public final boolean isGLES2Compatible() { - return 0 != ( ctxOptions & CTX_IMPL_ES2_COMPAT ) ; - } - - public final boolean hasGLSL() { - return isGL2ES2() ; - } - public final void setSwapInterval(int interval) { if (!isCurrent()) { throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this); diff --git a/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java b/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java index 41366c9a8..55dd0fe11 100644 --- a/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java +++ b/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java @@ -51,7 +51,6 @@ import java.util.*; */ final class ExtensionAvailabilityCache { protected static final boolean DEBUG = GLContextImpl.DEBUG; - private static final boolean DEBUG_AVAILABILITY = Debug.isPropertyDefined("jogl.debug.ExtensionAvailabilityCache", true); ExtensionAvailabilityCache(GLContextImpl context) { @@ -67,8 +66,12 @@ final class ExtensionAvailabilityCache { if(DEBUG) { System.out.println("ExtensionAvailabilityCache: Flush availability OpenGL "+context.getGLVersion()); } - availableExtensionCache.clear(); initialized = false; + glExtensions = null; + glExtensionCount = 0; + glXExtensions = null; + glXExtensionCount = 0; + availableExtensionCache.clear(); } /** @@ -83,8 +86,9 @@ final class ExtensionAvailabilityCache { return initialized && !availableExtensionCache.isEmpty() ; } - final int getSize() { - return initialized ? availableExtensionCache.size() : 0 ; + final int getTotalExtensionCount() { + initAvailableExtensions(); + return availableExtensionCache.size(); } final boolean isExtensionAvailable(String glExtensionName) { @@ -92,11 +96,21 @@ final class ExtensionAvailabilityCache { return availableExtensionCache.contains(mapGLExtensionName(glExtensionName)); } + final int getPlatformExtensionCount() { + initAvailableExtensions(); + return glXExtensionCount; + } + final String getPlatformExtensionsString() { initAvailableExtensions(); return glXExtensions; } + final int getGLExtensionCount() { + initAvailableExtensions(); + return glExtensionCount; + } + final String getGLExtensionsString() { initAvailableExtensions(); if(DEBUG) { @@ -133,62 +147,71 @@ final class ExtensionAvailabilityCache { ", use "+ ( useGetStringi ? "glGetStringi" : "glGetString" ) ); } - StringBuffer sb = new StringBuffer(); + HashSet<String> glExtensionSet = new HashSet<String>(gl.isGLES() ? 50 : 320); // far less gl extension expected on mobile if(useGetStringi) { GL2GL3 gl2gl3 = gl.getGL2GL3(); - int[] numExtensions = { 0 } ; - gl2gl3.glGetIntegerv(GL2GL3.GL_NUM_EXTENSIONS, numExtensions, 0); - for (int i = 0; i < numExtensions[0]; i++) { - sb.append(gl2gl3.glGetStringi(GL.GL_EXTENSIONS, i)); - if(i < numExtensions[0]) { - sb.append(" "); - } + final int count; + { + int[] val = { 0 } ; + gl2gl3.glGetIntegerv(GL2GL3.GL_NUM_EXTENSIONS, val, 0); + count = val[0]; } - if (DEBUG) { - System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL_EXTENSIONS: "+numExtensions[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==numExtensions[0]) { + if(0==count || sb.length()==0) { // fall back .. useGetStringi=false; + } else { + glExtensions = sb.toString(); } } if(!useGetStringi) { - sb.append(gl.glGetString(GL.GL_EXTENSIONS)); + glExtensions = gl.glGetString(GL.GL_EXTENSIONS); + if(null != glExtensions) { + StringTokenizer tok = new StringTokenizer(glExtensions); + while (tok.hasMoreTokens()) { + glExtensionSet.add(tok.nextToken().trim()); + } + } + } + glExtensionCount = glExtensionSet.size(); + if (DEBUG) { + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL_EXTENSIONS: "+glExtensionCount); } - glExtensions = sb.toString(); // Platform Extensions + HashSet<String> glXExtensionSet = new HashSet<String>(50); { - // unify platform extension .. might have duplicates - HashSet<String> platformSet = new HashSet<String>(50); + // unify platform extension .. might have duplicates StringTokenizer tok = new StringTokenizer(context.getPlatformExtensionsStringImpl().toString()); while (tok.hasMoreTokens()) { - platformSet.add(tok.nextToken().trim()); + glXExtensionSet.add(tok.nextToken().trim()); } - final StringBuffer sb2 = new StringBuffer(); - for(Iterator<String> iter = platformSet.iterator(); iter.hasNext(); ) { - sb2.append(iter.next()).append(" "); + final StringBuilder sb = new StringBuilder(); + for(Iterator<String> iter = glXExtensionSet.iterator(); iter.hasNext(); ) { + sb.append(iter.next()); + if(iter.hasNext()) { + sb.append(" "); + } } - glXExtensions = sb2.toString(); - } - sb.append(" "); - sb.append(glXExtensions); - - String allAvailableExtensions = sb.toString(); - if (DEBUG_AVAILABILITY) { - System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL vendor: " + gl.glGetString(GL.GL_VENDOR)); - } - StringTokenizer tok = new StringTokenizer(allAvailableExtensions); - while (tok.hasMoreTokens()) { - String availableExt = tok.nextToken().trim(); - availableExt = availableExt.intern(); - availableExtensionCache.add(availableExt); - if (DEBUG_AVAILABILITY) { - System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Available: " + availableExt); - } + glXExtensions = sb.toString(); + glXExtensionCount = glXExtensionSet.size(); } + + availableExtensionCache.addAll(glExtensionSet); + availableExtensionCache.addAll(glXExtensionSet); + if (DEBUG) { - System.err.println(getThreadName() + ":ExtensionAvailabilityCache: ALL EXTENSIONS: "+availableExtensionCache.size()); + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GLX_EXTENSIONS: "+glXExtensionCount); + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL vendor: " + gl.glGetString(GL.GL_VENDOR)); + System.err.println(getThreadName() + ":ExtensionAvailabilityCache: ALL EXTENSIONS: "+availableExtensionCache.size()); } if(!context.isGLES()) { @@ -227,7 +250,9 @@ final class ExtensionAvailabilityCache { private boolean initialized = false; private String glExtensions = null; + private int glExtensionCount = 0; private String glXExtensions = null; + private int glXExtensionCount = 0; private HashSet<String> availableExtensionCache = new HashSet<String>(50); private GLContextImpl context; diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 7766214b4..f33c2bdb1 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -996,7 +996,7 @@ public abstract class GLContextImpl extends GLContext { if(null != eCache) { extensionAvailability = eCache; if(DEBUG) { - System.err.println(getThreadName() + ": !!! GLContext GL ExtensionAvailabilityCache reusing key("+contextFQN+") -> "+toHexString(eCache.hashCode()) + " - entries: "+eCache.getSize()); + System.err.println(getThreadName() + ": !!! GLContext GL ExtensionAvailabilityCache reusing key("+contextFQN+") -> "+toHexString(eCache.hashCode()) + " - entries: "+eCache.getTotalExtensionCount()); } } else { extensionAvailability = new ExtensionAvailabilityCache(this); @@ -1004,7 +1004,7 @@ public abstract class GLContextImpl extends GLContext { synchronized(mappedContextTypeObjectLock) { mappedExtensionAvailabilityCache.put(contextFQN, extensionAvailability); if(DEBUG) { - System.err.println(getThreadName() + ": !!! GLContext GL ExtensionAvailabilityCache mapping key("+contextFQN+") -> "+toHexString(extensionAvailability.hashCode()) + " - entries: "+extensionAvailability.getSize()); + System.err.println(getThreadName() + ": !!! GLContext GL ExtensionAvailabilityCache mapping key("+contextFQN+") -> "+toHexString(extensionAvailability.hashCode()) + " - entries: "+extensionAvailability.getTotalExtensionCount()); } } } @@ -1047,19 +1047,8 @@ public abstract class GLContextImpl extends GLContext { */ protected abstract void updateGLXProcAddressTable(); - protected abstract StringBuffer getPlatformExtensionsStringImpl(); + protected abstract StringBuilder getPlatformExtensionsStringImpl(); - /** - * Returns true if the specified OpenGL core- or extension-function can be - * successfully called using this GL context given the current host (OpenGL - * <i>client</i>) and display (OpenGL <i>server</i>) configuration. - * - * See {@link GL#isFunctionAvailable(String)} for more details. - * - * @param glFunctionName the name of the OpenGL function (e.g., use - * "glPolygonOffsetEXT" or "glPolygonOffset" to check if the {@link - * javax.media.opengl.GL#glPolygonOffset(float,float)} is available). - */ public final boolean isFunctionAvailable(String glFunctionName) { // Check GL 1st (cached) ProcAddressTable pTable = getGLProcAddressTable(); // null if ctx not created once @@ -1098,16 +1087,6 @@ public abstract class GLContextImpl extends GLContext { return false; } - /** - * Returns true if the specified OpenGL extension can be - * successfully called using this GL context given the current host (OpenGL - * <i>client</i>) and display (OpenGL <i>server</i>) configuration. - * - * See {@link GL#isExtensionAvailable(String)} for more details. - * - * @param glExtensionName the name of the OpenGL extension (e.g., - * "GL_VERTEX_PROGRAM_ARB"). - */ public boolean isExtensionAvailable(String glExtensionName) { if(null!=extensionAvailability) { return extensionAvailability.isExtensionAvailable(mapToRealGLExtensionName(glExtensionName)); @@ -1115,6 +1094,10 @@ public abstract class GLContextImpl extends GLContext { return false; } + public final int getPlatformExtensionCount() { + return null != extensionAvailability ? extensionAvailability.getPlatformExtensionCount() : 0; + } + public final String getPlatformExtensionsString() { if(null!=extensionAvailability) { return extensionAvailability.getPlatformExtensionsString(); @@ -1122,6 +1105,10 @@ public abstract class GLContextImpl extends GLContext { return null; } + public final int getGLExtensionCount() { + return null != extensionAvailability ? extensionAvailability.getGLExtensionCount() : 0; + } + public final String getGLExtensionsString() { if(null!=extensionAvailability) { return extensionAvailability.getGLExtensionsString(); @@ -1135,7 +1122,7 @@ public abstract class GLContextImpl extends GLContext { } return false; } - + protected static String getContextFQN(AbstractGraphicsDevice device, int major, int minor, int ctxProfileBits) { ctxProfileBits &= ~GLContext.CTX_IMPL_ES2_COMPAT ; // remove non-key value 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 60766a57d..24095c749 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java @@ -248,8 +248,8 @@ public abstract class EGLContext extends GLContextImpl { } } - protected final StringBuffer getPlatformExtensionsStringImpl() { - StringBuffer sb = new StringBuffer(); + protected final StringBuilder getPlatformExtensionsStringImpl() { + StringBuilder sb = new StringBuilder(); if (!eglQueryStringInitialized) { eglQueryStringAvailable = getDrawableImpl().getGLDynamicLookupHelper().dynamicLookupFunction("eglQueryString") != 0; diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index 1503aa73d..279a5b9d7 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -322,8 +322,8 @@ public abstract class MacOSXCGLContext extends GLContextImpl } } - protected final StringBuffer getPlatformExtensionsStringImpl() { - return new StringBuffer(); + protected final StringBuilder getPlatformExtensionsStringImpl() { + return new StringBuilder(); } public boolean isExtensionAvailable(String glExtensionName) { diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java index b2be87f4f..66c203a44 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java @@ -421,8 +421,8 @@ public class WindowsWGLContext extends GLContextImpl { } } - protected final StringBuffer getPlatformExtensionsStringImpl() { - StringBuffer sb = new StringBuffer(); + protected final StringBuilder getPlatformExtensionsStringImpl() { + StringBuilder sb = new StringBuilder(); if (!wglGetExtensionsStringEXTInitialized) { wglGetExtensionsStringEXTAvailable = (WGL.wglGetProcAddress("wglGetExtensionsStringEXT") != 0); diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java index 9b154af95..d8813ed7f 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java @@ -465,8 +465,8 @@ public abstract class X11GLXContext extends GLContextImpl { } } - protected final StringBuffer getPlatformExtensionsStringImpl() { - StringBuffer sb = new StringBuffer(); + protected final StringBuilder getPlatformExtensionsStringImpl() { + StringBuilder sb = new StringBuilder(); if (DEBUG) { System.err.println("!!! GLX Version client version "+ GLXUtil.getClientVersionNumber()+ ", server: "+ |