aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/impl/windows
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-04-17 01:32:26 +0200
committerSven Gothel <[email protected]>2010-04-17 01:32:26 +0200
commit8778a3d70f8d57bc4f9142a3f59ea59754f08c1d (patch)
tree29a0c7fe341fcabf217cba8a0c9774d77b3cb169 /src/jogl/classes/com/jogamp/opengl/impl/windows
parent60da84a5ca8fa5e74e995ad0343c8967ba9463a5 (diff)
JOGL GL4 preperation (cont):
- Cont. on Context creation refactoring (bb028021be2714e66d9b1062298a3e308c649c56) - Added Windows/WGL implementation - Added efficienct sharedContext usage if ARB is available, ie no more temp context has to be created. - Added more GLProfile GL4* code ..
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/impl/windows')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java239
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java33
2 files changed, 155 insertions, 117 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java
index 7f9459a48..95706a7a1 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java
@@ -122,48 +122,123 @@ public class WindowsWGLContext extends GLContextImpl {
protected Map/*<String, String>*/ getExtensionNameMap() { return extensionNameMap; }
- protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) {
- return 0; // FIXME
+ protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) {
+ WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl();
+ WGLExt wglExt;
+ if(null==factory.getSharedContext()) {
+ wglExt = getWGLExt();
+ } else {
+ wglExt = factory.getSharedContext().getWGLExt();
+ }
+
+ boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ;
+ boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ;
+ boolean ctDebug = 0 != ( CTX_OPTION_DEBUG & ctp ) ;
+
+ long _context=0;
+
+ int attribs[] = {
+ /* 0 */ WGLExt.WGL_CONTEXT_MAJOR_VERSION_ARB, major,
+ /* 2 */ WGLExt.WGL_CONTEXT_MINOR_VERSION_ARB, minor,
+ /* 4 */ WGLExt.WGL_CONTEXT_LAYER_PLANE_ARB, WGLExt.WGL_CONTEXT_LAYER_PLANE_ARB, // default
+ /* 6 */ WGLExt.WGL_CONTEXT_FLAGS_ARB, 0,
+ /* 8 */ 0, 0,
+ /* 10 */ 0
+ };
+
+ if ( major > 3 || major == 3 && minor >= 2 ) {
+ // FIXME: Verify with a None drawable binding (default framebuffer)
+ attribs[8+0] = WGLExt.WGL_CONTEXT_PROFILE_MASK_ARB;
+ if( ctBwdCompat ) {
+ attribs[8+1] = WGLExt.WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
+ } else {
+ attribs[8+1] = WGLExt.WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
+ }
+ }
+
+ if ( major >= 3 ) {
+ if( !ctBwdCompat && ctFwdCompat ) {
+ attribs[6+1] |= WGLExt.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
+ }
+ if( ctDebug) {
+ attribs[6+1] |= WGLExt.WGL_CONTEXT_DEBUG_BIT_ARB;
+ }
+ }
+
+ _context = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), share, attribs, 0);
+ if(0==_context) {
+ if(DEBUG) {
+ System.err.println("WindowsWGLContext.createContextARB couldn't create "+getGLVersion(null, major, minor, ctp, "@creation"));
+ }
+ } else {
+ // In contrast to GLX no verification with a drawable binding, ie default framebuffer, is necessary,
+ // if no 3.2 is available creation fails already!
+ // Nevertheless .. we do it ..
+ if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), _context)) {
+ if(DEBUG) {
+ System.err.println("WindowsWGLContext.createContextARB couldn't make current "+getGLVersion(null, major, minor, ctp, "@creation"));
+ }
+ WGL.wglMakeCurrent(0, 0);
+ WGL.wglDeleteContext(_context);
+ _context = 0;
+ }
}
+ return _context;
+ }
/**
* Creates and initializes an appropriate OpenGL context. Should only be
* called by {@link #makeCurrentImpl()}.
*/
protected void create() {
- GLCapabilities glCaps = drawable.getChosenGLCapabilities();
- if(DEBUG) {
- System.err.println("WindowsWGLContext.create got "+glCaps);
+ if(0!=context) {
+ throw new GLException("context is not null: "+context);
}
+ WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl();
+ GLCapabilities glCaps = drawable.getChosenGLCapabilities();
if (drawable.getNativeWindow().getSurfaceHandle() == 0) {
throw new GLException("Internal error: attempted to create OpenGL context without an associated drawable");
}
// Windows can set up sharing of display lists after creation time
WindowsWGLContext other = (WindowsWGLContext) GLContextShareSet.getShareContext(this);
- long hglrc2 = 0;
+ long share = 0;
if (other != null) {
- hglrc2 = other.getHGLRC();
- if (hglrc2 == 0) {
+ share = other.getHGLRC();
+ if (share == 0) {
throw new GLException("GLContextShareSet returned an invalid OpenGL context");
}
}
- // To use WGL_ARB_create_context, we have to make a temp context current,
- // so we are able to use GetProcAddress
- long temp_hglrc = WGL.wglCreateContext(drawable.getNativeWindow().getSurfaceHandle());
- if (DEBUG) {
- System.err.println(getThreadName() + ": !!! Created temp OpenGL context " + toHexString(temp_hglrc) + " for " + this + ", device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) + ", not yet sharing");
+ int minor[] = new int[1];
+ int major[] = new int[1];
+ int ctp[] = new int[1];
+ boolean createContextARBTried = false;
+
+ // utilize the shared context's GLXExt in case it was using the ARB method and it already exists
+ if(null!=factory.getSharedContext() && factory.getSharedContext().isCreatedWithARBMethod()) {
+ if(DEBUG) {
+ System.err.println("WindowsWGLContext.createContext using shared Context: "+factory.getSharedContext());
+ }
+ hglrc = createContextARB(share, true, major, minor, ctp);
+ createContextARBTried = true;
}
- if (temp_hglrc == 0) {
- throw new GLException("Unable to create temp OpenGL context for device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle()));
- } else {
+
+ long temp_hglrc = 0;
+ if(0==hglrc) {
+ // To use WGL_ARB_create_context, we have to make a temp context current,
+ // so we are able to use GetProcAddress
+ temp_hglrc = WGL.wglCreateContext(drawable.getNativeWindow().getSurfaceHandle());
+ if (temp_hglrc == 0) {
+ throw new GLException("Unable to create temp OpenGL context for device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle()));
+ }
if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), temp_hglrc)) {
throw new GLException("Error making temp context current: 0x" + Integer.toHexString(WGL.GetLastError()));
}
setGLFunctionAvailability(true, 0, 0, 0);
- if( !isFunctionAvailable("wglCreateContextAttribsARB") ||
+ if( createContextARBTried ||
+ !isFunctionAvailable("wglCreateContextAttribsARB") ||
!isExtensionAvailable("WGL_ARB_create_context") ) {
if(glCaps.getGLProfile().isGL3()) {
WGL.wglMakeCurrent(0, 0);
@@ -173,111 +248,51 @@ public class WindowsWGLContext extends GLContextImpl {
// continue with temp context for GL < 3.0
hglrc = temp_hglrc;
- if(DEBUG) {
- System.err.println("WindowsWGLContext.create done (old ctx < 3.0 - no WGL_ARB_create_context) 0x"+Long.toHexString(hglrc));
- }
- } else {
- WGLExt wglExt = getWGLExt();
+ return;
+ }
+ hglrc = createContextARB(share, true, major, minor, ctp);
+ createContextARBTried=true;
+ }
+
+ if(0!=hglrc) {
+ share = 0; // mark as shared ..
- // preset with default values
- int attribs[] = {
- /* 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
- };
+ // need to update the GL func table ..
+ setGLFunctionAvailability(true, major[0], minor[0], ctp[0]);
- if(glCaps.getGLProfile().isGL3()) {
- // Try >= 3.2 core first !
- // In contrast to GLX no verify with a None drawable binding (default framebuffer) is necessary,
- // if no 3.2 is available creation fails already!
- attribs[0+1] = 3;
- attribs[2+1] = 2;
- 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) {
- System.err.println("WindowsWGLContext.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;
- 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) {
- System.err.println("WindowsWGLContext.createContext >= 3.2 available 0x"+Long.toHexString(hglrc));
- }
- }
- if(0==hglrc) {
- // 3.1 or 3.0 ..
- hglrc = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), hglrc2, attribs, 0);
- if(DEBUG) {
- if(0==hglrc) {
- System.err.println("WindowsWGLContext.createContext couldn't create >= 3.0 context - fallback");
- } else {
- System.err.println("WindowsWGLContext.createContext >= 3.0 available 0x"+Long.toHexString(hglrc));
- }
- }
- }
+ WGL.wglMakeCurrent(0, 0);
+ WGL.wglDeleteContext(temp_hglrc);
- if(0==hglrc) {
- if(glCaps.getGLProfile().isGL3()) {
- 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: 0x" + Integer.toHexString(WGL.GetLastError()));
- }
- updateGLProcAddressTable(0, 0, 0);
- 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 ..
- WGL.wglMakeCurrent(0, 0);
- WGL.wglDeleteContext(temp_hglrc);
-
- if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) {
- throw new GLException("Error making new context current: 0x" + Integer.toHexString(WGL.GetLastError()));
- }
- updateGLProcAddressTable(0, 0, 0);
- if(DEBUG) {
- System.err.println("WindowsWGLContext.create done (new ctx >= 3.0) 0x"+Long.toHexString(hglrc));
- }
- }
+ if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) {
+ throw new GLException("Cannot make previous verified context current: 0x" + Integer.toHexString(WGL.GetLastError()));
+ }
+ } else {
+ if(glCaps.getGLProfile().isGL3()) {
+ WGL.wglMakeCurrent(0, 0);
+ WGL.wglDeleteContext(temp_hglrc);
+ throw new GLException("WindowsWGLContext.createContext failed, but context > GL2 requested "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation")+", ");
+ }
+ if(DEBUG) {
+ System.err.println("WindowsWGLContext.createContext failed, fall back to !ARB context "+getGLVersion(null, major[0], minor[0], ctp[0], "@creation"));
+ }
+
+ // continue with temp context for GL < 3.0
+ hglrc = temp_hglrc;
+ if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) {
+ WGL.wglMakeCurrent(0, 0);
+ WGL.wglDeleteContext(hglrc);
+ throw new GLException("Error making old context current: 0x" + Integer.toHexString(WGL.GetLastError()));
}
}
- if(0!=hglrc2) {
- if (!WGL.wglShareLists(hglrc2, hglrc)) {
- throw new GLException("wglShareLists(" + toHexString(hglrc2) +
+
+ if(0!=share) {
+ if (!WGL.wglShareLists(share, hglrc)) {
+ throw new GLException("wglShareLists(" + toHexString(share) +
", " + toHexString(hglrc) + ") failed: error code 0x" +
Integer.toHexString(WGL.GetLastError()));
}
}
GLContextShareSet.contextCreated(this);
- WGL.wglMakeCurrent(0, 0); // release immediatly to gain from ARB/EXT wglMakeContextCurrent(draw, read, ctx)!
- if (DEBUG) {
- System.err.println(getThreadName() + ": !!! Created OpenGL context " + toHexString(hglrc) + " for " + this + ", device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) + ", sharing with " + toHexString(hglrc2));
- }
}
protected int makeCurrentImpl() throws GLException {
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java
index e3938f9fe..bc99338ab 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java
@@ -77,13 +77,22 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
WindowsWGLContext sharedContext=null;
boolean canCreateGLPbuffer = false;
+ // package private ..
+ final WindowsWGLContext getSharedContext() {
+ validate();
+ return sharedContext;
+ }
+
void initShared() {
if(null==sharedDrawable) {
sharedDrawable = new WindowsDummyWGLDrawable(this, null);
- sharedContext = (WindowsWGLContext) sharedDrawable.createContext(null);
- sharedContext.makeCurrent();
- canCreateGLPbuffer = sharedContext.getGL().isExtensionAvailable("GL_ARB_pbuffer");
- sharedContext.release();
+ WindowsWGLContext _sharedContext = (WindowsWGLContext) sharedDrawable.createContext(null);
+ {
+ _sharedContext.makeCurrent();
+ canCreateGLPbuffer = _sharedContext.getGL().isExtensionAvailable("GL_ARB_pbuffer");
+ _sharedContext.release();
+ }
+ _sharedContext = _sharedContext;
if (DEBUG) {
System.err.println("!!! SharedContext: "+sharedContext+", pbuffer supported "+canCreateGLPbuffer);
}
@@ -115,20 +124,30 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
if (target == null) {
throw new IllegalArgumentException("Null target");
}
+ initShared();
return new WindowsOnscreenWGLDrawable(this, target);
}
protected GLDrawableImpl createOffscreenDrawable(NativeWindow target) {
+ validate();
+ if (target == null) {
+ throw new IllegalArgumentException("Null target");
+ }
+ initShared();
return new WindowsOffscreenWGLDrawable(this, target);
}
public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) {
validate();
- initShared();
+ initShared(); // setup canCreateGLPBuffer
return canCreateGLPbuffer;
}
protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) {
+ validate();
+ if (target == null) {
+ throw new IllegalArgumentException("Null target");
+ }
initShared();
final List returnList = new ArrayList();
final GLDrawableFactory factory = this;
@@ -160,6 +179,8 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) {
+ validate();
+ initShared();
AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault();
NullWindow nw = new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
capabilities, chooser, screen) );
@@ -169,6 +190,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
public GLContext createExternalGLContext() {
validate();
+ initShared();
return WindowsExternalWGLContext.create(this, null);
}
@@ -179,6 +201,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
public GLDrawable createExternalGLDrawable() {
validate();
+ initShared();
return WindowsExternalWGLDrawable.create(this, null);
}