summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-10-24 17:08:25 +0200
committerSven Gothel <[email protected]>2012-10-24 17:08:25 +0200
commit0f198907181396c5aab545f621098ed2f210003a (patch)
tree260679d4dfa99f05d9c1dc8fd12de3301847e8d8 /src
parentf2661adf587390a61cbb7fe2e3377da2d57672a7 (diff)
GLContext: Produce and expose GLSL version as VersionNumber and version string (for shader programs)
Uses GL_SHADING_LANGUAGE_VERSION and parses it via VersionNumber, as well as having a static fallback using the GL context version. The value is valid and can be retrieved after ctx has been made current once.
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/javax/media/opengl/GLContext.java75
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextImpl.java18
2 files changed, 92 insertions, 1 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java
index 63470ccd3..ddb222bfe 100644
--- a/src/jogl/classes/javax/media/opengl/GLContext.java
+++ b/src/jogl/classes/javax/media/opengl/GLContext.java
@@ -52,6 +52,7 @@ import jogamp.opengl.Debug;
import jogamp.opengl.GLContextImpl;
import com.jogamp.common.os.Platform;
+import com.jogamp.common.util.VersionNumber;
import com.jogamp.common.util.locks.LockFactory;
import com.jogamp.common.util.locks.RecursiveLock;
import com.jogamp.opengl.GLExtensions;
@@ -159,6 +160,7 @@ public abstract class GLContext {
protected int ctxMinorVersion;
protected int ctxOptions;
protected String ctxVersionString;
+ protected VersionNumber ctxGLSLVersion;
private int currentSwapInterval;
protected GLRendererQuirks glRendererQuirks;
@@ -174,6 +176,7 @@ public abstract class GLContext {
ctxMinorVersion=-1;
ctxOptions=0;
ctxVersionString=null;
+ ctxGLSLVersion=null;
attachedObjects.clear();
contextHandle=0;
currentSwapInterval = -1;
@@ -629,6 +632,78 @@ public abstract class GLContext {
public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); }
/**
+ * Returns the matching GLSL version number, queried by this context GL
+ * via {@link GL2ES2#GL_SHADING_LANGUAGE_VERSION} if &ge; ES2.0 or GL2.0,
+ * otherwise a static match is being utilized.
+ * <p>
+ * The context must have been current once, otherwise <code>null</code> is returned.
+ * </p>
+ * <p>
+ * Examples w/ <code>major.minor</code>:
+ * <pre>
+ * 1.00 (ES2.0), 1.10 (GL2.0), 1.20 (GL2.1), 1.50 GL(3.2),
+ * 3.30 (GL3.3), 4.40 (GL4.0)
+ * </pre >
+ * </p>
+ * <p>
+ * <i>Matching</i> could also refer to the maximum GLSL version usable by this context
+ * since <i>normal</i> GL implementations are capable of using a lower GLSL version as well.
+ * The latter is not true on OSX w/ a GL3 context.
+ * </p>
+ *
+ * @param GLSL version number if context has been made current at least once, otherwise <code>null</code>.
+ *
+ * @see #getGLVersionMajor()
+ * @see #getGLVersionMinor()
+ */
+ public final VersionNumber getGLSLVersionNumber() {
+ return ctxGLSLVersion;
+ }
+
+ /**
+ * Returns the GLSL version string as to be used in a shader program, including a terminating newline '\n',
+ * i.e.:
+ * <pre>
+ * #version 110
+ * </pre>
+ * <p>
+ * If context has not been made current, <code>null</code> is returned.
+ * </p>
+ * @see #getGLSLVersionNumber()
+ */
+ public final String getGLSLVersionString() {
+ if(null == ctxGLSLVersion) {
+ return null;
+ }
+ final int minor = ctxGLSLVersion.getMinor();
+ return "#version " + ctxGLSLVersion.getMajor() + ( minor < 10 ? "0"+minor : minor ) + "\n" ;
+ }
+
+ protected static final void getStaticGLSLVersionNumber(int glMajorVersion, int glMinorVersion, int ctxOptions, int[] res) {
+ if( 0 != ( CTX_PROFILE_ES & ctxOptions ) ) {
+ res[0] = 1; res[1] = 0; // ES 2.0 -> GLSL 1.00
+ } else if( 1 == glMajorVersion ) {
+ res[0] = 1; res[0] = 10; // GL 1.x -> GLSL 1.10
+ } else if( 2 == glMajorVersion ) {
+ res[0] = 1;
+ switch ( glMinorVersion ) {
+ case 0: res[1] = 10; break; // GL 2.0 -> GLSL 1.10
+ default: res[1] = 20; break; // GL 2.1 -> GLSL 1.20
+ }
+ } else if( 3 == glMajorVersion && 2 >= glMajorVersion ) {
+ res[0] = 1;
+ switch ( glMinorVersion ) {
+ case 0: res[1] = 30; break; // GL 3.0 -> GLSL 1.30
+ case 1: res[1] = 40; break; // GL 3.1 -> GLSL 1.40
+ default: res[1] = 50; break; // GL 3.2 -> GLSL 1.50
+ }
+ } else { // >= 3.3
+ res[0] = glMajorVersion; // GL M.N -> GLSL M.N
+ res[1] = glMinorVersion * 10;
+ }
+ }
+
+ /**
* @return true if this context is an ES2 context or implements
* the extension <code>GL_ARB_ES2_compatibility</code>, otherwise false
*/
diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
index 249dc9c62..d2e0bb407 100644
--- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
@@ -60,6 +60,7 @@ import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLContext;
@@ -971,7 +972,22 @@ public abstract class GLContextImpl extends GLContext {
ctxMinorVersion = minor;
ctxOptions = ctp;
if(setVersionString) {
- ctxVersionString = getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, getGL().glGetString(GL.GL_VERSION));
+ ctxVersionString = getGLVersion(ctxMajorVersion, ctxMinorVersion, ctxOptions, gl.glGetString(GL.GL_VERSION));
+ ctxGLSLVersion = null;
+ if(ctxMajorVersion >= 2) { // >= ES2 || GL2.0
+ final String glslVersion = gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION);
+ if( null != glslVersion ) {
+ ctxGLSLVersion = new VersionNumber(glslVersion, ".");
+ if( ctxGLSLVersion.getMajor() < 1 ) {
+ ctxGLSLVersion = null; // failed ..
+ }
+ }
+ }
+ if( null == ctxGLSLVersion ){
+ final int[] sver = new int[2];
+ getStaticGLSLVersionNumber(ctxMajorVersion, ctxMinorVersion, ctxOptions, sver);
+ ctxGLSLVersion = new VersionNumber(sver[0], sver[1], 0);
+ }
}
}