diff options
Diffstat (limited to 'src/jogl/classes/com/sun/opengl/impl')
3 files changed, 173 insertions, 35 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/ExtensionAvailabilityCache.java b/src/jogl/classes/com/sun/opengl/impl/ExtensionAvailabilityCache.java index eee308088..7931f791b 100644 --- a/src/jogl/classes/com/sun/opengl/impl/ExtensionAvailabilityCache.java +++ b/src/jogl/classes/com/sun/opengl/impl/ExtensionAvailabilityCache.java @@ -65,7 +65,25 @@ public final class ExtensionAvailabilityCache { */ public void flush() { + if(DEBUG) { + System.out.println("ExtensionAvailabilityCache: Flush availability OpenGL "+majorVersion+"."+minorVersion); + } availableExtensionCache.clear(); + initialized = false; + majorVersion = 1; + minorVersion = 0; + } + + /** + * Flush the cache and rebuild the cache. + */ + public void reset() { + flush(); + initAvailableExtensions(); + } + + public boolean isInitialized() { + return initialized && !availableExtensionCache.isEmpty() ; } public boolean isExtensionAvailable(String glExtensionName) { @@ -73,19 +91,101 @@ public final class ExtensionAvailabilityCache { return availableExtensionCache.contains(mapGLExtensionName(glExtensionName)); } - protected void initAvailableExtensions() { + public String getPlatformExtensionsString() { + initAvailableExtensions(); + return glXExtensions; + } + + public String getGLExtensions() { + initAvailableExtensions(); + if(DEBUG) { + System.err.println("ExtensionAvailabilityCache: getGLExtensions() called"); + } + return glExtensions; + } + + public int getMajorVersion() { + initAvailableExtensions(); + return majorVersion; + } + + public int getMinorVersion() { + initAvailableExtensions(); + return minorVersion; + } + + private void initAvailableExtensions() { // 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()) { + if (availableExtensionCache.isEmpty() || !initialized) { GL gl = context.getGL(); + if (DEBUG) { - System.err.println("!!! Pre-caching extension availability"); + System.err.println("ExtensionAvailabilityCache: Pre-caching init "+gl+", GL_VERSION "+gl.glGetString(GL.GL_VERSION)); + } + + // Set version + Version version = new Version(gl.glGetString(GL.GL_VERSION)); + if (version.isValid()) { + majorVersion = version.getMajor(); + minorVersion = version.getMinor(); + + if( !gl.isGL3() && + ( majorVersion > 3 || + ( majorVersion == 3 && minorVersion >= 1 ) ) ) { + // downsize version to 3.0 in case we are not using GL3 (3.1) + majorVersion = 3; + minorVersion = 0; + } } - String allAvailableExtensions = - gl.glGetString(GL.GL_EXTENSIONS) + " " + context.getPlatformExtensionsString(); + + boolean useGetStringi = false; + + if ( majorVersion > 3 || + ( majorVersion == 3 && minorVersion >= 0 ) || + gl.isGL3() ) { + if ( ! gl.isGL2GL3() ) { + if(DEBUG) { + System.err.println("ExtensionAvailabilityCache: GL >= 3.1 usage, but no GL2GL3 interface: "+gl.getClass().getName()); + } + } else if ( ! gl.isFunctionAvailable("glGetStringi") ) { + if(DEBUG) { + System.err.println("ExtensionAvailabilityCache: GL >= 3.1 usage, but no glGetStringi"); + } + } else { + useGetStringi = true; + } + } + if (DEBUG) { - System.err.println("!!! Available extensions: " + allAvailableExtensions); - System.err.println("!!! GL vendor: " + gl.glGetString(GL.GL_VENDOR)); + System.err.println("ExtensionAvailabilityCache: Pre-caching extension availability OpenGL "+majorVersion+"."+minorVersion+ + ", use "+ ( useGetStringi ? "glGetStringi" : "glGetString" ) ); + } + + StringBuffer sb = new StringBuffer(); + 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(gl2gl3.GL_EXTENSIONS, i)); + if(i < numExtensions[0]) { + sb.append(" "); + } + } + } else { + sb.append(gl.glGetString(GL.GL_EXTENSIONS)); + } + glExtensions = sb.toString(); + glXExtensions = context.getPlatformExtensionsString(); + + sb.append(" "); + sb.append(glXExtensions); + + String allAvailableExtensions = sb.toString(); + if (DEBUG_AVAILABILITY) { + System.err.println("ExtensionAvailabilityCache: Available extensions: " + allAvailableExtensions); + System.err.println("ExtensionAvailabilityCache: GL vendor: " + gl.glGetString(GL.GL_VENDOR)); } StringTokenizer tok = new StringTokenizer(allAvailableExtensions); while (tok.hasMoreTokens()) { @@ -93,42 +193,53 @@ public final class ExtensionAvailabilityCache { availableExt = availableExt.intern(); availableExtensionCache.add(availableExt); if (DEBUG_AVAILABILITY) { - System.err.println("!!! Available: " + availableExt); + System.err.println("ExtensionAvailabilityCache: Available: " + availableExt); } } // Put GL version strings in the table as well - Version version = new Version(gl.glGetString(GL.GL_VERSION)); - if (version.isValid()) { - int major = version.getMajor(); - int minor = version.getMinor(); - // FIXME: this needs to be adjusted when the major rev changes - // beyond the known ones - while (major > 0) { - while (minor >= 0) { - availableExtensionCache.add("GL_VERSION_" + major + "_" + minor); - if (DEBUG) { - System.err.println("!!! Added GL_VERSION_" + major + "_" + minor + " to known extensions"); - } - --minor; + // FIXME: this needs to be adjusted when the major rev changes + // beyond the known ones + int major = majorVersion; + int minor = minorVersion; + while (major > 0) { + while (minor >= 0) { + availableExtensionCache.add("GL_VERSION_" + major + "_" + minor); + if (DEBUG) { + System.err.println("ExtensionAvailabilityCache: Added GL_VERSION_" + major + "_" + minor + " to known extensions"); } + --minor; + } - switch (major) { - case 2: - // Restart loop at version 1.5 - minor = 5; - break; - case 1: - break; + switch (major) { + case 2: + if(gl.isGL3() && major==2) { + // GL3 is a GL 3.1 forward compatible context, + // hence no 2.0, 1.0 - 1.5 GL versions are supported. + major=0; + } else { + // make sure 2.0 is added .. + minor = 0; + availableExtensionCache.add("GL_VERSION_" + major + "_" + minor); + if (DEBUG) { + System.err.println("ExtensionAvailabilityCache: Added GL_VERSION_" + major + "_" + minor + " to known extensions"); + } } - - --major; + // Restart loop at version 1.5 + minor = 5; + break; + case 1: + break; } + + --major; } // 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>"); + + initialized = true; } } @@ -146,6 +257,11 @@ public final class ExtensionAvailabilityCache { // Internals only below this point // + private boolean initialized = false; + private int majorVersion = 1; + private int minorVersion = 0; + private String glExtensions = null; + private String glXExtensions = null; private HashSet availableExtensionCache = new HashSet(50); private GLContextImpl context; @@ -236,7 +352,7 @@ public final class ExtensionAvailabilityCache { { // FIXME: refactor desktop OpenGL dependencies and make this // class work properly for OpenGL ES - System.err.println("FunctionAvailabilityCache.Version.<init>: "+e); + System.err.println("ExtensionAvailabilityCache: FunctionAvailabilityCache.Version.<init>: "+e); major = 1; minor = 0; /* diff --git a/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java index fa7e1ade7..16eb934bd 100644 --- a/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java +++ b/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java @@ -228,7 +228,7 @@ public abstract class GLContextImpl extends GLContext { return gl; } - public void setGL(GL gl) { + public GL setGL(GL gl) { if(DEBUG) { String sgl1 = (null!=this.gl)?this.gl.getClass().toString()+", "+this.gl.toString():new String("<null>"); String sgl2 = (null!=gl)?gl.getClass().toString()+", "+gl.toString():new String("<null>"); @@ -236,6 +236,7 @@ public abstract class GLContextImpl extends GLContext { e.printStackTrace(); } this.gl = gl; + return gl; } public abstract Object getPlatformGLExtensions(); @@ -354,7 +355,6 @@ public abstract class GLContextImpl extends GLContext { if(null==this.gl) { throw new GLException("setGLFunctionAvailability not called yet"); } - extensionAvailability.flush(); if (DEBUG) { System.err.println(getThreadName() + ": !!! Initializing OpenGL extension address table for " + this); } @@ -364,6 +364,8 @@ public abstract class GLContextImpl extends GLContext { // share them among contexts with the same capabilities } resetProcAddressTable(getGLProcAddressTable()); + + extensionAvailability.reset(); } /** @@ -426,6 +428,26 @@ public abstract class GLContextImpl extends GLContext { return extensionAvailability.isExtensionAvailable(mapToRealGLExtensionName(glExtensionName)); } + public String getPlatformExtensionsString() { + return extensionAvailability.getPlatformExtensionsString(); + } + + public String getGLExtensions() { + return extensionAvailability.getGLExtensions(); + } + + public int getMajorVersion() { + return extensionAvailability.getMajorVersion(); + } + + public int getMinorVersion() { + return extensionAvailability.getMinorVersion(); + } + + public boolean isExtensionCacheInitialized() { + return extensionAvailability.isInitialized(); + } + /** Indicates which floating-point pbuffer implementation is in use. Returns one of GLPbuffer.APPLE_FLOAT, GLPbuffer.ATI_FLOAT, or GLPbuffer.NV_FLOAT. */ diff --git a/src/jogl/classes/com/sun/opengl/impl/GLPbufferImpl.java b/src/jogl/classes/com/sun/opengl/impl/GLPbufferImpl.java index e414fbc8e..8aba26fc6 100644 --- a/src/jogl/classes/com/sun/opengl/impl/GLPbufferImpl.java +++ b/src/jogl/classes/com/sun/opengl/impl/GLPbufferImpl.java @@ -129,8 +129,8 @@ public class GLPbufferImpl implements GLPbuffer { return getContext().getGL(); } - public void setGL(GL gl) { - getContext().setGL(gl); + public GL setGL(GL gl) { + return getContext().setGL(gl); } public void setAutoSwapBufferMode(boolean onOrOff) { |