summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-02-13 23:17:56 +0100
committerSven Gothel <[email protected]>2012-02-13 23:17:56 +0100
commit0da7eeff106c1a2bf9e730c504a09e38360f141e (patch)
tree3af86256e48a5fbda6b362aebf457e11fcb71538 /src/jogl/classes/jogamp
parent5aff72256a49af51c002a07526174b23cc040b6e (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/classes/jogamp')
-rw-r--r--src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java107
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextImpl.java37
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLContext.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java4
6 files changed, 86 insertions, 74 deletions
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: "+