aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-11-28 03:54:00 +0100
committerSven Gothel <[email protected]>2010-11-28 03:54:00 +0100
commit597007fc23fbf86e036629b6c6b157e0e0506715 (patch)
tree688dd4c70e76dd23df399a3e008e31a7412dc9aa /src/jogl/classes/com/jogamp/opengl/impl/windows/wgl
parent0c9eb947a2ffabba2c10799f6ea50756a2749702 (diff)
JOGL: Proper handling of Read Drawable Support (if not supported), add query.
Read Drawable feature reflects the make context current API having a seperate read drawable next to the write drawable (default). glXMakeContextCurrent(write, read, ..) On X11 a ready drawable is only supported for GLX >= 1.3, on Windows only if extension WGL_ARB_make_current_read is available, on EGL it's always supported, on OSX not at all. API cleanup GLContext: changes: setGLDrawableRead(GLDrawable) -> setGLReadDrawable(GLDrawable) new: isGLReadDrawableAvailable() new: getGLExtensionsString(); Access qualifier cleanup. GLContextImpl: GLVersionNumber moved out.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/impl/windows/wgl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java72
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java35
2 files changed, 68 insertions, 39 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 2735389e8..53badb25e 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
@@ -59,8 +59,8 @@ import javax.media.opengl.GLCapabilitiesImmutable;
public class WindowsWGLContext extends GLContextImpl {
- private static final Map/*<String, String>*/ functionNameMap;
- private static final Map/*<String, String>*/ extensionNameMap;
+ static final Map/*<String, String>*/ functionNameMap;
+ static final Map/*<String, String>*/ extensionNameMap;
private boolean wglGetExtensionsStringEXTInitialized;
private boolean wglGetExtensionsStringEXTAvailable;
private boolean wglMakeContextCurrentInitialized;
@@ -81,14 +81,9 @@ public class WindowsWGLContext extends GLContextImpl {
}
// FIXME: figure out how to hook back in the Java 2D / JOGL bridge
- public WindowsWGLContext(GLDrawableImpl drawable, GLDrawableImpl drawableRead,
- GLContext shareWith) {
- super(drawable, drawableRead, shareWith);
- }
-
- public WindowsWGLContext(GLDrawableImpl drawable,
- GLContext shareWith) {
- this(drawable, null, shareWith);
+ WindowsWGLContext(GLDrawableImpl drawable,
+ GLContext shareWith) {
+ super(drawable, shareWith);
}
protected void resetState() {
@@ -111,20 +106,30 @@ public class WindowsWGLContext extends GLContextImpl {
return wglExt;
}
+ public final boolean isGLReadDrawableAvailable() {
+ if(!wglMakeContextCurrentInitialized && null != getWGLExtProcAddressTable()) {
+ WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl();
+ AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
+ AbstractGraphicsDevice device = config.getScreen().getDevice();
+ WindowsWGLDrawableFactory.SharedResource sr = factory.getOrCreateShared(device);
+ if(null != sr) {
+ wglMakeContextCurrentAvailable = factory.isReadDrawableAvailable(device);
+ wglMakeContextCurrentInitialized=true;
+ }
+ }
+ return wglMakeContextCurrentAvailable;
+ }
+
private final boolean wglMakeContextCurrent(long hDrawDC, long hReadDC, long ctx) {
boolean ok = false;
- WGLExt _wglExt = getWGLExt();
- if (!wglMakeContextCurrentInitialized) {
- wglMakeContextCurrentAvailable = isFunctionAvailable("wglMakeContextCurrent");
- wglMakeContextCurrentInitialized = true;
- if(DEBUG) {
- System.err.println("WindowsWGLContext.wglMakeContextCurrent: "+wglMakeContextCurrentAvailable);
- }
- }
if(wglMakeContextCurrentAvailable) {
- ok = _wglExt.wglMakeContextCurrent(hDrawDC, hReadDC, ctx);
- } else {
+ // needs initilized WGL ProcAddress table
+ ok = getWGLExt().wglMakeContextCurrent(hDrawDC, hReadDC, ctx);
+ } else if ( hDrawDC == hReadDC ) {
ok = WGL.wglMakeCurrent(hDrawDC, ctx);
+ } else {
+ // should not happen due to 'isGLReadDrawableAvailable()' query in GLContextImpl
+ throw new InternalError("Given readDrawable but no driver support");
}
if(!ok && 0==hDrawDC && 0==hReadDC) {
// Some GPU's falsely fails with a zero error code (success),
@@ -147,7 +152,7 @@ public class WindowsWGLContext extends GLContextImpl {
protected Map/*<String, String>*/ getExtensionNameMap() { return extensionNameMap; }
protected void destroyContextARBImpl(long context) {
- wglMakeContextCurrent(0, 0, 0);
+ WGL.wglMakeCurrent(0, 0);
WGL.wglDeleteContext(context);
}
@@ -156,11 +161,11 @@ public class WindowsWGLContext extends GLContextImpl {
AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
AbstractGraphicsDevice device = config.getScreen().getDevice();
WindowsWGLContext sharedContext = (WindowsWGLContext) factory.getOrCreateSharedContextImpl(device);
- WGLExt wglExt;
+ WGLExt _wglExt;
if(null==sharedContext) {
- wglExt = getWGLExt();
+ _wglExt = getWGLExt();
} else {
- wglExt = sharedContext.getWGLExt();
+ _wglExt = sharedContext.getWGLExt();
}
boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ;
@@ -202,7 +207,7 @@ public class WindowsWGLContext extends GLContextImpl {
}
try {
- ctx = wglExt.wglCreateContextAttribsARB(drawable.getHandle(), share, attribs, 0);
+ ctx = _wglExt.wglCreateContextAttribsARB(drawable.getHandle(), share, attribs, 0);
} catch (RuntimeException re) {
if(DEBUG) {
Throwable t = new Throwable("Info: WindowWGLContext.createContextARBImpl wglCreateContextAttribsARB failed with "+getGLVersion(major, minor, ctp, "@creation"), re);
@@ -211,7 +216,8 @@ public class WindowsWGLContext extends GLContextImpl {
}
if(0!=ctx) {
- if (!wglMakeContextCurrent(drawable.getHandle(), drawableRead.getHandle(), ctx)) {
+ // cannot use wglMakeContextCurrent since WGLExt ProcAddressTable is not ready yet.
+ if( !WGL.wglMakeCurrent(drawable.getHandle(), ctx) ) {
if(DEBUG) {
System.err.println("WindowsWGLContext.createContextARB couldn't make current "+getGLVersion(major, minor, ctp, "@creation"));
}
@@ -242,6 +248,8 @@ public class WindowsWGLContext extends GLContextImpl {
WindowsWGLContext sharedContext = (WindowsWGLContext) factory.getOrCreateSharedContextImpl(device);
GLCapabilitiesImmutable glCaps = drawable.getChosenGLCapabilities();
+ isGLReadDrawableAvailable(); // trigger setup wglMakeContextCurrentAvailable
+
// Windows can set up sharing of display lists after creation time
WindowsWGLContext other = (WindowsWGLContext) GLContextShareSet.getShareContext(this);
long share = 0;
@@ -302,12 +310,12 @@ public class WindowsWGLContext extends GLContextImpl {
if(0!=contextHandle) {
share = 0; // mark as shared thx to the ARB create method
- if(0!=temp_ctx) {
- WGL.wglMakeCurrent(0, 0);
+ WGL.wglMakeCurrent(0, 0); // the ARB create method used WGL.wglMakeCurrent(0, 0)
+ if(0!=temp_ctx) {
WGL.wglDeleteContext(temp_ctx);
- if (!wglMakeContextCurrent(drawable.getHandle(), drawableRead.getHandle(), contextHandle)) {
- throw new GLException("Cannot make previous verified context current: 0x" + toHexString(contextHandle) + ", werr: " + GDI.GetLastError());
- }
+ }
+ if (!wglMakeContextCurrent(drawable.getHandle(), drawableRead.getHandle(), contextHandle)) {
+ throw new GLException("Cannot make previous verified context current: 0x" + toHexString(contextHandle) + ", werr: " + GDI.GetLastError());
}
} else {
if(glCaps.getGLProfile().isGL3()) {
@@ -345,7 +353,7 @@ public class WindowsWGLContext extends GLContextImpl {
if (!wglMakeContextCurrent(drawable.getHandle(), drawableRead.getHandle(), contextHandle)) {
throw new GLException("Error making context current: 0x" + toHexString(contextHandle) + ", werr: " + GDI.GetLastError() + ", " + this);
} else {
- if (DEBUG && (VERBOSE || newCreated)) {
+ if (DEBUG && newCreated) {
System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + toHexString(drawable.getHandle()) +
", contextHandle " + toHexString(contextHandle) + ") succeeded");
}
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 0180b6c87..99e78b184 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
@@ -113,12 +113,18 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
private WindowsDummyWGLDrawable drawable;
private WindowsWGLContext context;
private boolean canCreateGLPbuffer;
+ private boolean readDrawableAvailable;
- SharedResource(WindowsDummyWGLDrawable draw, WindowsWGLContext ctx, boolean canPbuffer) {
+ SharedResource(WindowsDummyWGLDrawable draw, WindowsWGLContext ctx, boolean readBufferAvail, boolean canPbuffer) {
drawable = draw;
context = ctx;
canCreateGLPbuffer = canPbuffer;
+ readDrawableAvailable = readBufferAvail;
}
+ WindowsWGLContext getContext() { return context; }
+ boolean canCreateGLPbuffer() { return canCreateGLPbuffer; }
+ boolean isReadDrawableAvailable() { return readDrawableAvailable; }
+
}
HashMap/*<connection, SharedResource>*/ sharedMap = new HashMap();
WindowsGraphicsDevice defaultDevice;
@@ -146,7 +152,11 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
}
}
- private final SharedResource getOrCreateShared(AbstractGraphicsDevice device) {
+ final static String GL_ARB_pbuffer = "GL_ARB_pbuffer";
+ final static String WGL_ARB_make_current_read = "WGL_ARB_make_current_read";
+ final static String wglMakeContextCurrent = "wglMakeContextCurrent";
+
+ protected final SharedResource getOrCreateShared(AbstractGraphicsDevice device) {
String connection = device.getConnection();
SharedResource sr;
synchronized(sharedMap) {
@@ -159,14 +169,17 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
WindowsDummyWGLDrawable sharedDrawable = WindowsDummyWGLDrawable.create(this, null);
WindowsWGLContext ctx = (WindowsWGLContext) sharedDrawable.createContext(null);
ctx.makeCurrent();
- boolean canCreateGLPbuffer = ctx.getGL().isExtensionAvailable("GL_ARB_pbuffer");
+ boolean canCreateGLPbuffer = ctx.getGL().isExtensionAvailable(GL_ARB_pbuffer);
+ boolean readDrawableAvailable = ctx.isExtensionAvailable(WGL_ARB_make_current_read) &&
+ ctx.isFunctionAvailable(wglMakeContextCurrent);
ctx.release();
- sr = new SharedResource(sharedDrawable, ctx, canCreateGLPbuffer);
+ sr = new SharedResource(sharedDrawable, ctx, readDrawableAvailable, canCreateGLPbuffer);
synchronized(sharedMap) {
sharedMap.put(device.getConnection(), sr);
}
if (DEBUG) {
- System.err.println("!!! SharedContext: "+ctx+", pbuffer supported "+canCreateGLPbuffer);
+ System.err.println("!!! SharedContext: "+ctx+", pbuffer supported "+canCreateGLPbuffer+
+ ", readDrawable supported "+readDrawableAvailable);
}
} catch (Throwable t) {
@@ -181,7 +194,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) {
SharedResource sr = getOrCreateShared(device);
if(null!=sr) {
- return sr.context;
+ return sr.getContext();
}
return null;
}
@@ -232,10 +245,18 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
return new WindowsOffscreenWGLDrawable(this, target);
}
+ public final boolean isReadDrawableAvailable(AbstractGraphicsDevice device) {
+ SharedResource sr = getOrCreateShared((null!=device)?device:defaultDevice);
+ if(null!=sr) {
+ return sr.isReadDrawableAvailable();
+ }
+ return false;
+ }
+
public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) {
SharedResource sr = getOrCreateShared((null!=device)?device:defaultDevice);
if(null!=sr) {
- return sr.canCreateGLPbuffer;
+ return sr.canCreateGLPbuffer();
}
return false;
}