diff options
author | Sven Gothel <[email protected]> | 2009-10-03 01:18:34 -0700 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-10-03 01:18:34 -0700 |
commit | cf4c403733363a0e0e06079d85ddae91399696ab (patch) | |
tree | fc32b0cef12f1472130ab7ed6e571c2d2df28c7a /src/jogl/classes/com/sun/opengl/impl/windows/wgl | |
parent | 1304fcd939bea7ea804d2fef22a942848b02a20b (diff) |
Offscreen/PBuffer capabilities cleanup ; Generic read drawable support
Diffstat (limited to 'src/jogl/classes/com/sun/opengl/impl/windows/wgl')
5 files changed, 67 insertions, 31 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java index 71d82e784..a3e5f6da4 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java @@ -54,7 +54,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { GLCapabilitiesChooser chooser, int width, int height) { - super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(requestedCapabilities, chooser, absScreen, false, false)), true); + super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(requestedCapabilities, chooser, absScreen)), true); ((NullWindow) getNativeWindow()).setSize(width, height); create(); } @@ -128,6 +128,9 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { } protected void swapBuffersImpl() { + if(DEBUG) { + System.err.println("unhandled swapBuffersImpl() called for: "+this); + } } } diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java index 20a891414..41a4e3877 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java @@ -61,7 +61,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { WindowsWGLDrawable dummyDrawable, WGLExt wglExt) { super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( - requestedCapabilities, chooser, absScreen, false, true) ), true); + requestedCapabilities, chooser, absScreen) ), true); if (width <= 0 || height <= 0) { throw new GLException("Width and height of pbuffer must be positive (were (" + width + ", " + height + "))"); @@ -108,6 +108,9 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { } protected void swapBuffersImpl() { + if(DEBUG) { + System.err.println("unhandled swapBuffersImpl() called for: "+this); + } } private void createPbuffer(long parentHdc, WGLExt wglExt) { 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 9a3860ae2..b07cd6046 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 @@ -47,10 +47,12 @@ import com.sun.opengl.impl.*; import com.sun.gluegen.runtime.ProcAddressTable; public class WindowsWGLContext extends GLContextImpl { - protected WindowsWGLDrawable drawable; protected long hglrc; private boolean wglGetExtensionsStringEXTInitialized; private boolean wglGetExtensionsStringEXTAvailable; + private boolean wglMakeContextCurrentInitialized; + private boolean wglMakeContextCurrentARBAvailable; + private boolean wglMakeContextCurrentEXTAvailable; private static final Map/*<String, String>*/ functionNameMap; private static final Map/*<String, String>*/ extensionNameMap; private WGLExt wglExt; @@ -69,12 +71,16 @@ public class WindowsWGLContext extends GLContextImpl { } // FIXME: figure out how to hook back in the Java 2D / JOGL bridge - public WindowsWGLContext(WindowsWGLDrawable drawable, - GLContext shareWith) { - super(drawable.getGLProfile(), shareWith); - this.drawable = drawable; + public WindowsWGLContext(GLDrawableImpl drawable, GLDrawableImpl drawableRead, + GLContext shareWith) { + super(drawable, drawableRead, shareWith); } + public WindowsWGLContext(GLDrawableImpl drawable, + GLContext shareWith) { + this(drawable, null, shareWith); + } + public Object getPlatformGLExtensions() { return getWGLExt(); } @@ -86,6 +92,21 @@ public class WindowsWGLContext extends GLContextImpl { return wglExt; } + public boolean wglMakeContextCurrent(long hDrawDC, long hReadDC, long hglrc) { + WGLExt wglExt = getWGLExt(); + if (!wglMakeContextCurrentInitialized) { + wglMakeContextCurrentARBAvailable = (WGL.wglGetProcAddress("wglMakeContextCurrentARB") != 0); + wglMakeContextCurrentEXTAvailable = (WGL.wglGetProcAddress("wglMakeContextCurrentEXT") != 0); + wglMakeContextCurrentInitialized = true; + } + if(wglMakeContextCurrentARBAvailable) { + return wglExt.wglMakeContextCurrentARB(hDrawDC, hReadDC, hglrc); + } else if(wglMakeContextCurrentEXTAvailable) { + return wglExt.wglMakeContextCurrentEXT(hDrawDC, hReadDC, hglrc); + } + return WGL.wglMakeCurrent(hDrawDC, hglrc); + } + public final ProcAddressTable getPlatformExtProcAddressTable() { return getWGLExtProcAddressTable(); } @@ -94,10 +115,6 @@ public class WindowsWGLContext extends GLContextImpl { return wglExtProcAddressTable; } - public GLDrawable getGLDrawable() { - return drawable; - } - protected String mapToRealGLFunctionName(String glFunctionName) { String lookup = (String) functionNameMap.get(glFunctionName); if (lookup != null) { @@ -146,7 +163,7 @@ public class WindowsWGLContext extends GLContextImpl { if (temp_hglrc == 0) { throw new GLException("Unable to create temp OpenGL context for device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle())); } else { - if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), temp_hglrc)) { + if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), temp_hglrc)) { throw new GLException("Error making temp context current: 0x" + Integer.toHexString(WGL.GetLastError())); } setGLFunctionAvailability(true); @@ -154,7 +171,7 @@ public class WindowsWGLContext extends GLContextImpl { if( !isFunctionAvailable("wglCreateContextAttribsARB") || !isExtensionAvailable("WGL_ARB_create_context") ) { if(glCaps.getGLProfile().isGL3()) { - WGL.wglMakeCurrent(0, 0); + wglMakeContextCurrent(0, 0, 0); WGL.wglDeleteContext(temp_hglrc); throw new GLException("Unable to create OpenGL >= 3.1 context (no WGL_ARB_create_context)"); } @@ -213,14 +230,14 @@ public class WindowsWGLContext extends GLContextImpl { if(0==hglrc) { if(glCaps.getGLProfile().isGL3()) { - WGL.wglMakeCurrent(0, 0); + wglMakeContextCurrent(0, 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)) { + if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) { throw new GLException("Error making old context current: 0x" + Integer.toHexString(WGL.GetLastError())); } if(DEBUG) { @@ -228,10 +245,10 @@ public class WindowsWGLContext extends GLContextImpl { } } else { hglrc2 = 0; // mark as shared .. - WGL.wglMakeCurrent(0, 0); + wglMakeContextCurrent(0, 0, 0); WGL.wglDeleteContext(temp_hglrc); - if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) { + if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) { throw new GLException("Error making new context current: 0x" + Integer.toHexString(WGL.GetLastError())); } updateGLProcAddressTable(); @@ -271,7 +288,7 @@ public class WindowsWGLContext extends GLContextImpl { } if (WGL.wglGetCurrentContext() != hglrc) { - if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), hglrc)) { + if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) { throw new GLException("Error making context current: 0x" + Integer.toHexString(WGL.GetLastError())); } else { if (DEBUG && VERBOSE) { @@ -294,7 +311,7 @@ public class WindowsWGLContext extends GLContextImpl { } protected void releaseImpl() throws GLException { - if (!WGL.wglMakeCurrent(0, 0)) { + if (!wglMakeContextCurrent(0, 0, 0)) { throw new GLException("Error freeing OpenGL context: 0x" + Integer.toHexString(WGL.GetLastError())); } } @@ -335,6 +352,12 @@ public class WindowsWGLContext extends GLContextImpl { if (DEBUG) { System.err.println(getThreadName() + ": !!! Initializing WGL extension address table for " + this); } + wglGetExtensionsStringEXTInitialized=false; + wglGetExtensionsStringEXTAvailable=false; + wglMakeContextCurrentInitialized=false; + wglMakeContextCurrentARBAvailable=false; + wglMakeContextCurrentEXTAvailable=false; + if (wglExtProcAddressTable == null) { // FIXME: cache ProcAddressTables by capability bits so we can // share them among contexts with the same capabilities diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index d91cc0126..8feb36d25 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -83,6 +83,8 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements int width, int height) { AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(); + capabilities.setOnscreen(false); + capabilities.setPBuffer(false); return new WindowsOffscreenWGLDrawable(this, aScreen, capabilities, chooser, width, height); } @@ -128,6 +130,9 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements if (!canCreateGLPbuffer()) { throw new GLException("Pbuffer support not available with current graphics card"); } + capabilities.setOnscreen(false); + capabilities.setPBuffer(true); + final GLCapabilities caps = capabilities; final List returnList = new ArrayList(); final GLDrawableFactory factory = this; Runnable r = new Runnable() { @@ -142,7 +147,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements WGLExt dummyWGLExt = dummyContext.getWGLExt(); try { AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(); - GLDrawableImpl pbufferDrawable = new WindowsPbufferWGLDrawable(factory, aScreen, capabilities, chooser, + GLDrawableImpl pbufferDrawable = new WindowsPbufferWGLDrawable(factory, aScreen, caps, chooser, initialWidth, initialHeight, dummyDrawable, diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index a7d7be349..3fd96e7bc 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -55,36 +55,38 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) { GLCapabilities caps = (GLCapabilities)capabilities; - return chooseGraphicsConfigurationStatic(caps, chooser, absScreen, caps.isOnscreen(), caps.isPBuffer()); + return chooseGraphicsConfigurationStatic(caps, chooser, absScreen); } protected static WindowsWGLGraphicsConfiguration createDefaultGraphicsConfiguration(AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) { GLCapabilities caps = new GLCapabilities(null); caps.setOnscreen (onscreen); caps.setPBuffer (usePBuffer); - if(!onscreen) { - caps.setDoubleBuffered(false); + + GLCapabilities caps2 = (GLCapabilities) caps.clone(); + if(!caps2.isOnscreen()) { + // OFFSCREEN !DOUBLE_BUFFER + caps2.setDoubleBuffered(false); } if(null==absScreen) { absScreen = DefaultGraphicsScreen.createScreenDevice(0); } - return new WindowsWGLGraphicsConfiguration(absScreen, caps, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps), -1, null); + return new WindowsWGLGraphicsConfiguration(absScreen, caps2, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps2), -1, null); } protected static WindowsWGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilities caps, CapabilitiesChooser chooser, - AbstractGraphicsScreen absScreen, - boolean onscreen, boolean usePBuffer) { + AbstractGraphicsScreen absScreen) { if(null==absScreen) { absScreen = DefaultGraphicsScreen.createScreenDevice(0); } - caps.setOnscreen (onscreen); - caps.setPBuffer (usePBuffer); - if(!onscreen) { - caps.setDoubleBuffered(false); + GLCapabilities caps2 = (GLCapabilities) caps.clone(); + if(!caps2.isOnscreen()) { + // OFFSCREEN !DOUBLE_BUFFER + caps2.setDoubleBuffered(false); } - return new WindowsWGLGraphicsConfiguration(absScreen, caps, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps), -1, + return new WindowsWGLGraphicsConfiguration(absScreen, caps2, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps2), -1, (GLCapabilitiesChooser)chooser); } |