From 372767d3faa62d6e95dd8e9ad5c3105bf9614f3d Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sun, 18 Oct 2009 07:59:08 -0700
Subject: Add OpenGL 3.x compatibility profile GL3bc, where 'bc' is not a
 religious remark, but simply means 'backward compatible' :)

GL3bc := GL2 + GL3,
hence the interface does not define any new values or methods.

Moved GL3's 3.1 part from gl3.h to gl3ext.h,
so it can be included in gl3bc.c, besides gl2.h.
---
 .../opengl/impl/windows/wgl/WindowsWGLContext.java | 18 +++++++--
 .../com/sun/opengl/impl/x11/glx/X11GLXContext.java | 18 +++++++--
 src/jogl/classes/javax/media/opengl/GLBase.java    | 20 ++++++++--
 src/jogl/classes/javax/media/opengl/GLProfile.java | 43 ++++++++++++++++++----
 4 files changed, 82 insertions(+), 17 deletions(-)

(limited to 'src/jogl/classes')

diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java
index 418336e3f..497e9f03b 100644
--- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java
+++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java
@@ -202,8 +202,18 @@ public class WindowsWGLContext extends GLContextImpl {
                 // if no 3.2 is available creation fails already!
                 attribs[0+1]  = 3;
                 attribs[2+1]  = 2;
-                attribs[6+0]  = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB;
-                attribs[6+1]  = WGLExt.WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
+                if(glCaps.getGLProfile().isGL3bc()) {
+                    attribs[6+0]  = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB;
+                    attribs[6+1]  = WGLExt.WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
+                }
+                /**
+                 * don't stricten requirements any further, even compatible would be fine
+                 *
+                 } else {
+                    attribs[6+0]  = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB;
+                    attribs[6+1]  = WGLExt.WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
+                 } 
+                 */
                 hglrc = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), hglrc2, attribs, 0); 
                 if(0==hglrc) {
                     if(DEBUG) {
@@ -212,7 +222,9 @@ public class WindowsWGLContext extends GLContextImpl {
                     // Try >= 3.1 forward compatible - last resort for GL3 !
                     attribs[0+1]  = 3;
                     attribs[2+1]  = 1;
-                    attribs[4+1] |= WGLExt.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
+                    if(!glCaps.getGLProfile().isGL3bc()) {
+                        attribs[4+1] |= WGLExt.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
+                    }
                     attribs[6+0]  = 0;
                     attribs[6+1]  = 0;
                 } else if(DEBUG) {
diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java
index 84f32d43e..330d0a473 100644
--- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java
+++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java
@@ -205,8 +205,18 @@ public abstract class X11GLXContext extends GLContextImpl {
                     // and verify with a None drawable binding (default framebuffer)
                     attribs[0+1]  = 3;
                     attribs[2+1]  = 2;
-                    // FIXME NV Bug: attribs[8+0]  = GLX.GLX_CONTEXT_PROFILE_MASK_ARB;
-                    // FIXME NV Bug: attribs[8+1]  = GLX.GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
+                    if(glCaps.getGLProfile().isGL3bc()) {
+                        attribs[8+0]  = GLX.GLX_CONTEXT_PROFILE_MASK_ARB;
+                        attribs[8+1]  = GLX.GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
+                    }
+                    /**
+                     * don't stricten requirements any further, even compatible would be fine
+                     *
+                     } else {
+                        attribs[8+0]  = GLX.GLX_CONTEXT_PROFILE_MASK_ARB;
+                        attribs[8+1]  = GLX.GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
+                     } 
+                     */
 
                     context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0);
                     if(0!=context) {
@@ -232,7 +242,9 @@ public abstract class X11GLXContext extends GLContextImpl {
                         // Try >= 3.1 forward compatible - last resort for GL3 !
                         attribs[0+1]  = 3;
                         attribs[2+1]  = 1;
-                        attribs[6+1] |= GLX.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
+                        if(!glCaps.getGLProfile().isGL3bc()) {
+                            attribs[6+1] |= GLX.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
+                        }
                         attribs[8+0]  = 0;
                         attribs[8+1]  = 0;
                     }
diff --git a/src/jogl/classes/javax/media/opengl/GLBase.java b/src/jogl/classes/javax/media/opengl/GLBase.java
index 92498077b..be5a6dc4f 100644
--- a/src/jogl/classes/javax/media/opengl/GLBase.java
+++ b/src/jogl/classes/javax/media/opengl/GLBase.java
@@ -64,9 +64,16 @@ public interface GLBase {
   public boolean isGL();
 
   /**
-   * Indicates whether this GL object conforms to the GL3 profile.
-   * The GL3 profile reflects OpenGL versions greater or equal 3.1
-   * @return whether this GL object conforms to the GL3 profile
+   * Indicates whether this GL object conforms to the GL3 compatibility profile.
+   * The GL3 compatibility profile merges the GL2 profile and GL3 core profile.
+   * @return whether this GL object conforms to the GL3 compatibility profile
+   */
+  public boolean isGL3bc();
+
+  /**
+   * Indicates whether this GL object conforms to the GL3 core profile.
+   * The GL3 core profile reflects OpenGL versions greater or equal 3.1
+   * @return whether this GL object conforms to the GL3 core profile
    */
   public boolean isGL3();
 
@@ -123,6 +130,13 @@ public interface GLBase {
    */
   public GL getGL() throws GLException;
 
+  /**
+   * Casts this object to the GL3bc interface.
+   * @return this object cast to the GL3bc interface
+   * @throws GLException if this GLObject is not a GL3bc implementation
+   */
+  public GL3bc getGL3bc() throws GLException;
+
   /**
    * Casts this object to the GL3 interface.
    * @return this object cast to the GL3 interface
diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java
index a63136944..69cdd3f24 100644
--- a/src/jogl/classes/javax/media/opengl/GLProfile.java
+++ b/src/jogl/classes/javax/media/opengl/GLProfile.java
@@ -60,7 +60,11 @@ public class GLProfile implements Cloneable {
     // Public (user-visible) profiles
     //
 
-    /** The desktop OpenGL profile 3.x, with x >= 1 */
+    /** The desktop OpenGL compatibility profile 3.x, with x >= 1, ie GL2 plus GL3.<br>
+        <code>bc</code> stands for backward compatibility. */
+    public static final String GL3bc = "GL3bc";
+
+    /** The desktop OpenGL core profile 3.x, with x >= 1 */
     public static final String GL3   = "GL3";
 
     /** The desktop OpenGL profile 1.x up to 3.0 */
@@ -84,12 +88,12 @@ public class GLProfile implements Cloneable {
     /** 
      * All GL Profiles in the order of default detection: GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL3
      */
-    public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL3 };
+    public static final String[] GL_PROFILE_LIST_ALL = new String[] { GL2, GL2ES2, GL2ES1, GLES2, GLES1, GL2GL3, GL3bc, GL3 };
 
     /**
      * All GL2ES2 Profiles in the order of default detection: GL2ES2, GL2, GLES2, GL3
      */
-    public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GLES2, GL3 };
+    public static final String[] GL_PROFILE_LIST_GL2ES2 = new String[] { GL2ES2, GL2, GLES2, GL3bc, GL3 };
 
     /**
      * All GL2ES1 Profiles in the order of default detection: GL2ES1, GL2, GLES1
@@ -187,7 +191,9 @@ public class GLProfile implements Cloneable {
     }
 
     private static final String getGLImplBaseClassName(String profileImpl) {
-        if(GL3.equals(profileImpl)) {
+        if(GL3bc.equals(profileImpl)) {
+            return "com.sun.opengl.impl.gl3.GL3bc";
+        } else if(GL3.equals(profileImpl)) {
             return "com.sun.opengl.impl.gl3.GL3";
         } else if(GL2.equals(profileImpl)) {
             return "com.sun.opengl.impl.gl2.GL2";
@@ -246,9 +252,14 @@ public class GLProfile implements Cloneable {
         return profileImpl;
     }
 
+    /** Indicates whether this profile is capable of GL3bc. */
+    public final boolean isGL3bc() {
+        return GL3bc.equals(profile);
+    }
+
     /** Indicates whether this profile is capable of GL3. */
     public final boolean isGL3() {
-        return GL3.equals(profile);
+        return isGL3bc() || GL3.equals(profile);
     }
 
     /** Indicates whether this profile is capable of GL2. */
@@ -301,9 +312,14 @@ public class GLProfile implements Cloneable {
         return GL2.equals(profileImpl) || GL2ES12.equals(profileImpl) ;
     }
 
+    /** Indicates whether this profile uses the native desktop OpenGL GL3bc implementations. */
+    public final boolean usesNativeGL3bc() {
+        return GL3bc.equals(profileImpl);
+    }
+
     /** Indicates whether this profile uses the native desktop OpenGL GL3 implementations. */
     public final boolean usesNativeGL3() {
-        return GL3.equals(profileImpl);
+        return usesNativeGL3bc() || GL3.equals(profileImpl);
     }
 
     /** Indicates whether this profile uses the native desktop OpenGL GL2 or GL3 implementations. */
@@ -623,6 +639,7 @@ public class GLProfile implements Cloneable {
     private static final boolean isAWTAvailable;
     private static final boolean isAWTJOGLAvailable;
 
+    private static final boolean hasGL3bcImpl;
     private static final boolean hasGL3Impl;
     private static final boolean hasGL2Impl;
     private static final boolean hasGL2ES12Impl;
@@ -698,6 +715,7 @@ public class GLProfile implements Cloneable {
         }
 
         // FIXME: check for real GL3 availability .. ?
+        hasGL3bcImpl   = hasDesktopGL && NWReflection.isClassAvailable("com.sun.opengl.impl.gl3.GL3bcImpl");
         hasGL3Impl     = hasDesktopGL && NWReflection.isClassAvailable("com.sun.opengl.impl.gl3.GL3Impl");
         hasGL2Impl     = hasDesktopGL && NWReflection.isClassAvailable("com.sun.opengl.impl.gl2.GL2Impl");
 
@@ -743,6 +761,7 @@ public class GLProfile implements Cloneable {
             System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory);
             System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12);
             System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL);
+            System.err.println("GLProfile.static hasGL3bcImpl "+hasGL3bcImpl);
             System.err.println("GLProfile.static hasGL3Impl "+hasGL3Impl);
             System.err.println("GLProfile.static hasGL2Impl "+hasGL2Impl);
             System.err.println("GLProfile.static hasGL2ES12Impl "+hasGL2ES12Impl);
@@ -811,11 +830,19 @@ public class GLProfile implements Cloneable {
                 return GL2;
             } else if(hasGL3Impl) {
                 return GL3;
+            } else if(hasGL3bcImpl) {
+                return GL3bc;
             } else if(hasGLES2Impl) {
                 return GLES2;
             }
-        } else if(GL3.equals(profile) && hasGL3Impl) {
-            return GL3;
+        } else if(GL3bc.equals(profile) && hasGL3bcImpl) {
+            return GL3bc;
+        } else if(GL3.equals(profile)) {
+            if(hasGL3Impl) {
+                return GL3;
+            } else if(hasGL3bcImpl) {
+                return GL3bc;
+            }
         } else if(GL2.equals(profile) && hasGL2Impl) {
             return GL2;
         } else if(GL2GL3.equals(profile) && hasGL2Impl) {
-- 
cgit v1.2.3