From e0ed09f8e2df570a9542f606a133c8fde074cbfe Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Thu, 26 Mar 2015 16:33:55 +0100
Subject: Bug 1150 - Fix GLContextImpl.createImpl(..) NoARBCreateContext and
 '!ARB GL >= 3.1' issues

This fix solves the described issues below.

Test cases added for onscreen and offscreen drawables,
the latter includes Window's bitmap special case.

GLContextImpl.createImpl(..): Fix NoARBCreateContext and '!ARB GL >= 3.1' issues:
=================================================================================
GLContextImpl.createImpl(..) implementation of X11GLXContext and WindowsWGLContext
wrongly handles the case of NoARBCreateContext.
Here the !ARB created context shall allow GL >= 3.1,
since ARB context creation is disabled and 'no mix' can occur.

The latter was already intended due to failure criteris 'createContextARBTried'
in:
  if( glCaps.getGLProfile().isGL3() && createContextARBTried ) {
     failure("createImpl ctx !ARB but ARB is used, profile > GL2 requested");
  }

Further, WindowsWGLContext treats glCaps.isBitmap()
within the 'createContextARBTried=true' case, but it shall never
tried using the ARB context creation method.
This even lead to the issue of creating a 1.1 context,
but having the ProcAddressTable being still on the GL > 2 cached table.
This is due to 'setGLFunctionAvailability(..)'.

Ensure 'setGLFunctionAvailability(..)' is functional
====================================================

Caller shall either throws an exception if method returns false
or issues a state reset.

In case 'setGLFunctionAvailability(..)' throws an exception itself,
the states are no issue.
---
 src/jogl/classes/jogamp/opengl/egl/EGLContext.java | 34 ++++++++++++++--------
 1 file changed, 22 insertions(+), 12 deletions(-)

(limited to 'src/jogl/classes/jogamp/opengl/egl/EGLContext.java')

diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
index 9d7ad64f9..b6a05aeeb 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
@@ -51,6 +51,7 @@ import jogamp.opengl.GLContextImpl;
 import jogamp.opengl.GLDrawableImpl;
 import jogamp.opengl.egl.EGLExtImpl;
 import jogamp.opengl.egl.EGLExtProcAddressTable;
+import jogamp.opengl.windows.wgl.WindowsWGLContext;
 
 import com.jogamp.common.ExceptionUtils;
 import com.jogamp.common.nio.Buffers;
@@ -310,16 +311,25 @@ public class EGLContext extends GLContextImpl {
         final AbstractGraphicsDevice device = config.getScreen().getDevice();
         final GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
         final GLProfile glp = glCaps.getGLProfile();
-
-        contextHandle = createContextARB(shareWithHandle, true);
-        if (DEBUG) {
-            if( 0 != contextHandle ) {
-                System.err.println(getThreadName() + ": EGLContext.createImpl: OK (ARB) on eglDevice "+device+
-                        ", eglConfig "+config+", "+glp+", shareWith "+toHexString(shareWithHandle)+", error "+toHexString(EGL.eglGetError()));
-            } else {
-                System.err.println(getThreadName() + ": EGLContext.createImpl: NOT OK (ARB) - creation failed on eglDevice "+device+
-                        ", eglConfig "+config+", "+glp+", shareWith "+toHexString(shareWithHandle)+", error "+toHexString(EGL.eglGetError()));
+        final boolean createContextARBAvailable = isCreateContextARBAvail(device);
+        if(DEBUG) {
+            System.err.println(getThreadName() + ": EGLContext.createImpl: START "+glCaps+", share "+toHexString(shareWithHandle));
+            System.err.println(getThreadName() + ": Use ARB[avail["+getCreateContextARBAvailStr(device)+
+                    "] -> "+createContextARBAvailable+"]]");
+        }
+        if( createContextARBAvailable ) {
+            contextHandle = createContextARB(shareWithHandle, true);
+            if (DEBUG) {
+                if( 0 != contextHandle ) {
+                    System.err.println(getThreadName() + ": createImpl: OK (ARB) on eglDevice "+device+
+                            ", eglConfig "+config+", "+glp+", shareWith "+toHexString(shareWithHandle)+", error "+toHexString(EGL.eglGetError()));
+                } else {
+                    System.err.println(getThreadName() + ": createImpl: NOT OK (ARB) - creation failed on eglDevice "+device+
+                            ", eglConfig "+config+", "+glp+", shareWith "+toHexString(shareWithHandle)+", error "+toHexString(EGL.eglGetError()));
+                }
             }
+        } else {
+            contextHandle = 0;
         }
         if( 0 == contextHandle ) {
             if( !glp.isGLES() ) {
@@ -339,18 +349,18 @@ public class EGLContext extends GLContextImpl {
                 EGL.eglMakeCurrent(drawable.getNativeSurface().getDisplayHandle(), EGL.EGL_NO_SURFACE, EGL.EGL_NO_SURFACE, EGL.EGL_NO_CONTEXT);
                 EGL.eglDestroyContext(drawable.getNativeSurface().getDisplayHandle(), contextHandle);
                 contextHandle = 0;
-                throw new InternalError("setGLFunctionAvailability !strictMatch failed");
+                throw new GLException("setGLFunctionAvailability !strictMatch failed");
             }
         }
         if (DEBUG) {
-            System.err.println(getThreadName() + ": EGLContext.createImpl: Created OpenGL context 0x" +
+            System.err.println(getThreadName() + ": createImpl: Created OpenGL context 0x" +
                                Long.toHexString(contextHandle) +
                                ",\n\twrite surface 0x" + Long.toHexString(drawable.getHandle()) +
                                ",\n\tread  surface 0x" + Long.toHexString(drawableRead.getHandle())+
                                ",\n\t"+this+
                                ",\n\tsharing with 0x" + Long.toHexString(shareWithHandle));
         }
-        return 0 != contextHandle;
+        return true;
     }
 
     @Override
-- 
cgit v1.2.3