aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2009-08-03 13:18:17 -0700
committerSven Gothel <[email protected]>2009-08-03 13:18:17 -0700
commit33c4fbf49ff5d91925d3653dd5d5f034825954e7 (patch)
treea604f5bf2d384733ca9671ce5c78325b8f5ed774 /src
parent733d54f7e2977c20e373eba50b9cd16966a4fb77 (diff)
Doc: OpenGL 3.1 .. 3.2 profile clarification
GLX_ARB_create_context: Add 3.2 context WGL_ARB_create_context: Add 3.2 context Add: Trying to use 3.2 core profile creation for GL3, disabled by default. (Disabled per default due to a freezing JVM on Linux _after_ the Java main thread and Hotspot finishes.) Experimental: You may try '3.2 core profile creation' setting the java system property 'jogl.GLContext.3_2'.
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java1
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLContext.java81
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java76
3 files changed, 108 insertions, 50 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java
index 16eb934bd..d1a35b1b6 100644
--- a/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java
+++ b/src/jogl/classes/com/sun/opengl/impl/GLContextImpl.java
@@ -61,6 +61,7 @@ public abstract class GLContextImpl extends GLContext {
// platforms anyway in particular with the disabling of the
// GLWorkerThread which we found to be necessary in 1.0 beta 4.
protected boolean optimizationEnabled = Debug.isPropertyDefined("jogl.GLContext.optimize", true);
+ protected boolean tryGLContext3_2 = Debug.isPropertyDefined("jogl.GLContext.3_2", true);
// Cache of the functions that are available to be called at the current
// moment in time
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 6d810ed39..008dd6ac2 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
@@ -154,13 +154,9 @@ public class WindowsWGLContext extends GLContextImpl {
if( !isFunctionAvailable("wglCreateContextAttribsARB") ||
!isExtensionAvailable("WGL_ARB_create_context") ) {
if(glCaps.getGLProfile().isGL3()) {
- if (!WGL.wglMakeCurrent(0, 0)) {
- throw new GLException("Error freeing temp OpenGL context: " + WGL.GetLastError());
- }
- if (!WGL.wglDeleteContext(temp_hglrc)) {
- throw new GLException("Unable to delete OpenGL context");
- }
- throw new GLException("Unable to create OpenGL 3.1 context (no WGL_ARB_create_context)");
+ WGL.wglMakeCurrent(0, 0);
+ WGL.wglDeleteContext(temp_hglrc);
+ throw new GLException("Unable to create OpenGL >= 3.1 context (no WGL_ARB_create_context)");
}
// continue with temp context for GL < 3.0
@@ -173,44 +169,71 @@ public class WindowsWGLContext extends GLContextImpl {
// preset with default values
int attribs[] = {
- WGLExt.WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
- WGLExt.WGL_CONTEXT_MINOR_VERSION_ARB, 0,
- WGLExt.WGL_CONTEXT_FLAGS_ARB, 0,
- 0
+ /* 0 */ WGLExt.WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
+ /* 2 */ WGLExt.WGL_CONTEXT_MINOR_VERSION_ARB, 0,
+ /* 4 */ WGLExt.WGL_CONTEXT_FLAGS_ARB, 0 /* WGLExt.WGL_CONTEXT_DEBUG_BIT_ARB */,
+ /* 6 */ 0, 0,
+ /* 8 */ 0
};
if(glCaps.getGLProfile().isGL3()) {
- attribs[1] |= 3;
- attribs[3] |= 1;
- // attribs[5] |= WGLExt.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB ; // NVidia WGL driver doesn't support this one ..
- // attribs[5] |= WGLExt.WGL_CONTEXT_DEBUG_BIT_ARB ;
+ if(tryGLContext3_2) {
+ // Try >= 3.2 core first !
+ // and verify with a None drawable binding (default framebuffer)
+ 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;
+ hglrc = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), hglrc2, attribs, 0);
+ if(0!=hglrc) {
+ if (!WGL.wglMakeCurrent(0, hglrc)) {
+ if(DEBUG) {
+ System.err.println("WindowsWGLContext.createContext couldn't make >= 3.2 core context current - fallback");
+ }
+ WGL.wglMakeCurrent(0, 0);
+ WGL.wglDeleteContext(hglrc);
+ hglrc = 0;
+ } else if(DEBUG) {
+ System.err.println("WindowsWGLContext.createContext >= 3.2 available 0x"+Long.toHexString(hglrc));
+ }
+ }
+ }
+ if(0==hglrc) {
+ if(tryGLContext3_2 && DEBUG) {
+ System.err.println("WindowsWGLContext.createContext couldn't create >= 3.2 core context");
+ }
+ // 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;
+ attribs[6+0] = 0;
+ attribs[6+1] = 0;
+ }
+ }
+ if(0==hglrc) {
+ // 3.1 or 3.0 ..
+ hglrc = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), hglrc2, attribs, 0);
}
- hglrc = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), hglrc2, attribs, 0);
if(0==hglrc) {
if(glCaps.getGLProfile().isGL3()) {
- if (!WGL.wglMakeCurrent(0, 0)) {
- throw new GLException("Error freeing temp OpenGL context: " + WGL.GetLastError());
- }
- if (!WGL.wglDeleteContext(temp_hglrc)) {
- throw new GLException("Unable to delete OpenGL context");
- }
- throw new GLException("Unable to create OpenGL 3.1 context (have WGL_ARB_create_context)");
+ WGL.wglMakeCurrent(0, 0);
+ WGL.wglDeleteContext(temp_hglrc);
+ throw new GLException("Unable to create OpenGL >= 3.1 context (have WGL_ARB_create_context)");
}
// continue with temp context for GL < 3.0
hglrc = temp_hglrc;
+ if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) {
+ throw new GLException("Error making old context current: " + WGL.GetLastError());
+ }
if(DEBUG) {
System.err.println("WindowsWGLContext.create done (old ctx < 3.0 - no 3.0) 0x"+Long.toHexString(hglrc));
}
} else {
hglrc2 = 0; // mark as shared ..
- if (!WGL.wglMakeCurrent(0, 0)) {
- throw new GLException("Error freeing temp OpenGL context: " + WGL.GetLastError());
- }
- if (!WGL.wglDeleteContext(temp_hglrc)) {
- throw new GLException("Unable to delete temp OpenGL context");
- }
+ WGL.wglMakeCurrent(0, 0);
+ WGL.wglDeleteContext(temp_hglrc);
if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) {
throw new GLException("Error making new context current: " + WGL.GetLastError());
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 da1548d0d..6513fbe29 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
@@ -142,7 +142,7 @@ public abstract class X11GLXContext extends GLContextImpl {
if(config.getFBConfigID()<0) {
// not able to use FBConfig
if(glCaps.getGLProfile().isGL3()) {
- throw new GLException("Unable to create OpenGL 3.1 context");
+ throw new GLException("Unable to create OpenGL >= 3.1 context");
}
context = GLX.glXCreateContext(display, config.getXVisualInfo(), share, direct);
if (context == 0) {
@@ -178,11 +178,9 @@ public abstract class X11GLXContext extends GLContextImpl {
if( !isFunctionAvailable("glXCreateContextAttribsARB") ||
!isExtensionAvailable("GLX_ARB_create_context") ) {
if(glCaps.getGLProfile().isGL3()) {
- if (!GLX.glXMakeContextCurrent(display, 0, 0, 0)) {
- throw new GLException("Error freeing temp OpenGL context");
- }
+ GLX.glXMakeContextCurrent(display, 0, 0, 0);
GLX.glXDestroyContext(display, temp_context);
- throw new GLException("Unable to create OpenGL 3.1 context (no GLX_ARB_create_context)");
+ throw new GLException("Unable to create OpenGL >= 3.1 context (no GLX_ARB_create_context)");
}
// continue with temp context for GL < 3.0
@@ -195,38 +193,74 @@ public abstract class X11GLXContext extends GLContextImpl {
// preset with default values
int attribs[] = {
- GLX.GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
- GLX.GLX_CONTEXT_MINOR_VERSION_ARB, 0,
- GLX.GLX_CONTEXT_FLAGS_ARB, 0,
- GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE,
- 0
+ /* 0 */ GLX.GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+ /* 2 */ GLX.GLX_CONTEXT_MINOR_VERSION_ARB, 0,
+ /* 4 */ GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_TYPE,
+ /* 6 */ GLX.GLX_CONTEXT_FLAGS_ARB, 0 /* GLX.GLX_CONTEXT_DEBUG_BIT_ARB */,
+ /* 8 */ 0, 0,
+ /* 10 */ 0
};
if(glCaps.getGLProfile().isGL3()) {
- attribs[1] |= 3;
- attribs[3] |= 1;
- attribs[5] |= GLX.GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB /* | GLX.GLX_CONTEXT_DEBUG_BIT_ARB */;
+ if(tryGLContext3_2) {
+ // Try >= 3.2 core first
+ // and verify with a None drawable binding (default framebuffer)
+ attribs[0+1] = 3;
+ attribs[2+1] = 2;
+ 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) {
+ if (!GLX.glXMakeContextCurrent(display, 0, 0, context)) {
+ if(DEBUG) {
+ System.err.println("X11GLXContext.createContext couldn't make >= 3.2 core context current - fallback");
+ }
+ GLX.glXMakeContextCurrent(display, 0, 0, 0);
+ GLX.glXDestroyContext(display, context);
+ context = 0;
+ } else if(DEBUG) {
+ System.err.println("X11GLXContext.createContext >= 3.2 available 0x"+Long.toHexString(context));
+ }
+ }
+ }
+ if(0==context) {
+ if(tryGLContext3_2 && DEBUG) {
+ System.err.println("X11GLXContext.createContext couldn't create >= 3.2 core context - fallback");
+ }
+ // 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;
+ attribs[8+0] = 0;
+ attribs[8+1] = 0;
+ }
+ }
+ if(0==context) {
+ // 3.1 or 3.0 ..
+ context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0);
}
- context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0);
if(0==context) {
if(glCaps.getGLProfile().isGL3()) {
- if (!GLX.glXMakeContextCurrent(display, 0, 0, 0)) {
- throw new GLException("Error freeing temp OpenGL context");
- }
+ GLX.glXMakeContextCurrent(display, 0, 0, 0);
GLX.glXDestroyContext(display, temp_context);
- throw new GLException("Unable to create OpenGL 3.1 context (have GLX_ARB_create_context)");
+ throw new GLException("Unable to create OpenGL >= 3.1 context (have GLX_ARB_create_context)");
}
// continue with temp context for GL < 3.0
context = temp_context;
+ if (!GLX.glXMakeContextCurrent(display,
+ drawable.getNativeWindow().getSurfaceHandle(),
+ drawable.getNativeWindow().getSurfaceHandle(),
+ context)) {
+ throw new GLException("Error making context (old) current: display 0x"+Long.toHexString(display)+", context 0x"+Long.toHexString(context)+", drawable "+drawable);
+ }
if(DEBUG) {
System.err.println("X11GLXContext.createContext done (old ctx < 3.0 - no 3.0) 0x"+Long.toHexString(context));
}
} else {
- if (!GLX.glXMakeContextCurrent(display, 0, 0, 0)) {
- throw new GLException("Error freeing temp OpenGL context");
- }
+ GLX.glXMakeContextCurrent(display, 0, 0, 0);
GLX.glXDestroyContext(display, temp_context);
// need to update the GL func table ..