summaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl')
-rw-r--r--src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java68
1 files changed, 38 insertions, 30 deletions
diff --git a/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java b/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java
index 8d3d207ee..fd59ecfd4 100644
--- a/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java
+++ b/src/jogl/classes/jogamp/opengl/ExtensionAvailabilityCache.java
@@ -40,11 +40,14 @@
package jogamp.opengl;
-import javax.media.opengl.*;
+import java.util.HashMap;
+import java.util.StringTokenizer;
-import com.jogamp.common.util.VersionNumber;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GLContext;
-import java.util.*;
+import com.jogamp.common.util.VersionNumber;
/**
* A utility object intended to be used by implementations to act as a cache
@@ -80,7 +83,7 @@ final class ExtensionAvailabilityCache {
}
final boolean isInitialized() {
- return initialized && !availableExtensionCache.isEmpty() ;
+ return initialized;
}
final int getTotalExtensionCount() {
@@ -90,7 +93,7 @@ final class ExtensionAvailabilityCache {
final boolean isExtensionAvailable(String glExtensionName) {
validateInitialization();
- return availableExtensionCache.contains(glExtensionName);
+ return null != availableExtensionCache.get(glExtensionName);
}
final int getPlatformExtensionCount() {
@@ -151,7 +154,6 @@ final class ExtensionAvailabilityCache {
", 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;
@@ -162,57 +164,63 @@ final class ExtensionAvailabilityCache {
}
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( null == availableExtensionCache.put(ext, ext) ) {
+ // new one
+ if( 0 < i ) {
+ sb.append(" ");
+ }
+ sb.append(ext);
+ }
}
if(0==count || sb.length()==0) {
// fall back ..
useGetStringi=false;
} else {
glExtensions = sb.toString();
+ glExtensionCount = count;
}
}
if(!useGetStringi) {
glExtensions = gl.glGetString(GL.GL_EXTENSIONS);
if(null != glExtensions) {
- StringTokenizer tok = new StringTokenizer(glExtensions);
+ final StringTokenizer tok = new StringTokenizer(glExtensions);
+ int count = 0;
while (tok.hasMoreTokens()) {
- glExtensionSet.add(tok.nextToken().trim());
+ final String ext = tok.nextToken().trim();
+ if( null == availableExtensionCache.put(ext, ext) ) {
+ count++;
+ }
}
+ glExtensionCount = count;
}
}
- glExtensionCount = glExtensionSet.size();
if (DEBUG) {
System.err.println(getThreadName() + ":ExtensionAvailabilityCache: GL_EXTENSIONS: "+glExtensionCount+
", used "+ ( useGetStringi ? "glGetStringi" : "glGetString" ) );
}
// Platform Extensions
- HashSet<String> glXExtensionSet = new HashSet<String>(50);
{
// unify platform extension .. might have duplicates
- StringTokenizer tok = new StringTokenizer(context.getPlatformExtensionsStringImpl().toString());
- while (tok.hasMoreTokens()) {
- glXExtensionSet.add(tok.nextToken().trim());
- }
final StringBuilder sb = new StringBuilder();
- for(Iterator<String> iter = glXExtensionSet.iterator(); iter.hasNext(); ) {
- sb.append(iter.next());
- if(iter.hasNext()) {
- sb.append(" ");
+ final StringTokenizer tok = new StringTokenizer(context.getPlatformExtensionsStringImpl().toString());
+ int count = 0;
+ while (tok.hasMoreTokens()) {
+ final String ext = tok.nextToken().trim();
+ if( null == availableExtensionCache.put(ext, ext) ) {
+ // new one
+ if( 0 < count ) {
+ sb.append(" ");
+ }
+ sb.append(ext);
+ count++;
}
}
glXExtensions = sb.toString();
- glXExtensionCount = glXExtensionSet.size();
+ glXExtensionCount = count;
}
- 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));
@@ -225,7 +233,7 @@ final class ExtensionAvailabilityCache {
int minor[] = new int[] { version.getMinor() };
do{
final String GL_XX_VERSION = ( context.isGLES() ? "GL_ES_VERSION_" : "GL_VERSION_" ) + major[0] + "_" + minor[0];
- availableExtensionCache.add(GL_XX_VERSION);
+ availableExtensionCache.put(GL_XX_VERSION, GL_XX_VERSION);
if (DEBUG) {
System.err.println(getThreadName() + ":ExtensionAvailabilityCache: Added "+GL_XX_VERSION+" to known extensions");
}
@@ -233,7 +241,7 @@ final class ExtensionAvailabilityCache {
// put a dummy var in here so that the cache is no longer empty even if
// no extensions are in the GL_EXTENSIONS string
- availableExtensionCache.add("<INTERNAL_DUMMY_PLACEHOLDER>");
+ availableExtensionCache.put("<INTERNAL_DUMMY_PLACEHOLDER>", "<INTERNAL_DUMMY_PLACEHOLDER>");
initialized = true;
}
@@ -247,7 +255,7 @@ final class ExtensionAvailabilityCache {
private int glExtensionCount = 0;
private String glXExtensions = null;
private int glXExtensionCount = 0;
- private final HashSet<String> availableExtensionCache = new HashSet<String>(50);
+ private final HashMap<String, String> availableExtensionCache = new HashMap<String, String>(100);
static String getThreadName() { return Thread.currentThread().getName(); }