aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/sun/opengl/impl/windows/wgl
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2009-07-24 17:22:11 +0200
committerMichael Bien <[email protected]>2009-07-24 17:22:11 +0200
commit2a8e9876ca4567de3b08813c280d006f9b2c32e6 (patch)
treea44911062f30e557255162772c9b5fa64d1ad59a /src/jogl/classes/com/sun/opengl/impl/windows/wgl
parent801df10c0ee6ac6da81f1eb770dbc8a7ff7c5e38 (diff)
parent0906140a18690a9dced8dec12dfdd8cf4c95a4df (diff)
Merge branch 'master' of ssh://[email protected]/jogl~jogl-git
Diffstat (limited to 'src/jogl/classes/com/sun/opengl/impl/windows/wgl')
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java4
-rwxr-xr-xsrc/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLContext.java57
-rwxr-xr-xsrc/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java24
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java8
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java48
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java26
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawable.java53
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java6
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java94
-rw-r--r--src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java279
10 files changed, 365 insertions, 234 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java
index 62388173c..f1e9483cd 100644
--- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java
+++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java
@@ -47,7 +47,7 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable {
private long hwnd, hdc;
public WindowsDummyWGLDrawable(GLDrawableFactory factory) {
- super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(null, false)), true);
+ super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(null, true, true)), true);
// All entries to CreateDummyWindow must synchronize on one object
// to avoid accidentally registering the dummy window class twice
synchronized (WindowsDummyWGLDrawable.class) {
@@ -59,7 +59,7 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable {
// Choose a (hopefully hardware-accelerated) OpenGL pixel format for this device context
GLCapabilities caps = new GLCapabilities(null);
caps.setDepthBits(16);
- PIXELFORMATDESCRIPTOR pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps, true);
+ PIXELFORMATDESCRIPTOR pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps);
int pixelFormat = WGL.ChoosePixelFormat(hdc, pfd);
if ((pixelFormat == 0) ||
(!WGL.SetPixelFormat(hdc, pixelFormat, pfd))) {
diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLContext.java
index b42a54104..b9fc80156 100755
--- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLContext.java
+++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLContext.java
@@ -44,19 +44,16 @@ import java.util.*;
import javax.media.opengl.*;
import javax.media.nativewindow.*;
import com.sun.opengl.impl.*;
+import com.sun.nativewindow.impl.NullWindow;
public class WindowsExternalWGLContext extends WindowsWGLContext {
private boolean firstMakeCurrent = true;
private boolean created = true;
private GLContext lastContext;
- public WindowsExternalWGLContext(AbstractGraphicsScreen absScreen) {
- // FIXME: figure out how to hook back in the Java 2D / JOGL bridge
- super(null, null);
- hglrc = WGL.wglGetCurrentContext();
- if (hglrc == 0) {
- throw new GLException("Error: attempted to make an external GLContext without a drawable/context current");
- }
+ private WindowsExternalWGLContext(Drawable drawable, long hglrc) {
+ super(drawable, null);
+ this.hglrc = hglrc;
if (DEBUG) {
System.err.println(getThreadName() + ": !!! Created external OpenGL context " + toHexString(hglrc) + " for " + this);
}
@@ -64,6 +61,29 @@ public class WindowsExternalWGLContext extends WindowsWGLContext {
setGLFunctionAvailability(false);
}
+ protected static WindowsExternalWGLContext create(GLDrawableFactory factory, GLProfile glp) {
+ long hdc = WGL.wglGetCurrentDC();
+ if (0==hdc) {
+ throw new GLException("Error: attempted to make an external GLDrawable without a drawable current");
+ }
+ long hglrc = WGL.wglGetCurrentContext();
+ if (hglrc == 0) {
+ throw new GLException("Error: attempted to make an external GLContext without a context current");
+ }
+ int pfdID = WGL.GetPixelFormat(hdc);
+ if (pfdID == 0) {
+ throw new GLException("Error: attempted to make an external GLContext without a valid pixelformat");
+ }
+
+ AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault();
+ WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfiguration.create(glp, aScreen, hdc, pfdID, true, true);
+
+ NullWindow nw = new NullWindow(cfg);
+ nw.setSurfaceHandle(hdc);
+
+ return new WindowsExternalWGLContext(new Drawable(factory, nw), hglrc);
+ }
+
public int makeCurrent() throws GLException {
// Save last context if necessary to allow external GLContexts to
// talk to other GLContexts created by this library
@@ -100,4 +120,27 @@ public class WindowsExternalWGLContext extends WindowsWGLContext {
public boolean isCreated() {
return created;
}
+
+ // Need to provide the display connection to extension querying APIs
+ static class Drawable extends WindowsWGLDrawable {
+ Drawable(GLDrawableFactory factory, NativeWindow comp) {
+ super(factory, comp, true);
+ }
+
+ public GLContext createContext(GLContext shareWith) {
+ throw new GLException("Should not call this");
+ }
+
+ public int getWidth() {
+ throw new GLException("Should not call this");
+ }
+
+ public int getHeight() {
+ throw new GLException("Should not call this");
+ }
+
+ public void setSize(int width, int height) {
+ throw new GLException("Should not call this");
+ }
+ }
}
diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java
index 164216c2d..706675893 100755
--- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java
+++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java
@@ -46,20 +46,32 @@ import com.sun.nativewindow.impl.NullWindow;
public class WindowsExternalWGLDrawable extends WindowsWGLDrawable {
- public WindowsExternalWGLDrawable(GLDrawableFactory factory, NativeWindow component) {
+ private WindowsExternalWGLDrawable(GLDrawableFactory factory, NativeWindow component) {
super(factory, component, true);
}
- public static WindowsExternalWGLDrawable create(GLDrawableFactory factory, AbstractGraphicsScreen absScreen) {
+ protected static WindowsExternalWGLDrawable create(GLDrawableFactory factory, GLProfile glp) {
long hdc = WGL.wglGetCurrentDC();
- NullWindow nw = new NullWindow(WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(absScreen, false));
- nw.setSurfaceHandle(hdc);
- if (nw.getSurfaceHandle() == 0) {
- throw new GLException("Error: attempted to make an external GLDrawable without a drawable/context current");
+ if (0==hdc) {
+ throw new GLException("Error: attempted to make an external GLDrawable without a drawable current");
+ }
+ int pfdID = WGL.GetPixelFormat(hdc);
+ if (pfdID == 0) {
+ throw new GLException("Error: attempted to make an external GLContext without a valid pixelformat");
}
+
+ AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault();
+ WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfiguration.create(glp, aScreen, hdc, pfdID, true, true);
+
+ NullWindow nw = new NullWindow(cfg);
+ nw.setSurfaceHandle(hdc);
+
+ // cfg.updateGraphicsConfiguration(factory, nw);
+
return new WindowsExternalWGLDrawable(factory, nw);
}
+
public GLContext createContext(GLContext shareWith) {
return new WindowsWGLContext(this, shareWith);
}
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 dc9d66073..ecd4e1685 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, true)), true);
+ super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(requestedCapabilities, chooser, absScreen, false, false)), true);
((NullWindow) getNativeWindow()).setSize(width, height);
create();
}
@@ -111,7 +111,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable {
throw new GLException("Error selecting bitmap into new device context");
}
- config.updateGraphicsConfiguration(getFactory(), nw, true);
+ config.updateGraphicsConfiguration(getFactory(), nw);
}
public void destroy() {
@@ -126,4 +126,8 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable {
nw.setSurfaceHandle(0);
}
}
+
+ public void swapBuffers() throws GLException {
+ }
+
}
diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java
index 31925589b..395ccf7d2 100644
--- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java
+++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java
@@ -44,15 +44,6 @@ import javax.media.opengl.*;
import com.sun.opengl.impl.*;
public class WindowsOnscreenWGLDrawable extends WindowsWGLDrawable {
- private static final boolean PROFILING = Debug.debug("WindowsOnscreenWGLDrawable.profiling");
- private static final int PROFILING_TICKS = 200;
- private int profilingLockSurfaceTicks;
- private long profilingLockSurfaceTime;
- private int profilingUnlockSurfaceTicks;
- private long profilingUnlockSurfaceTime;
- private int profilingSwapBuffersTicks;
- private long profilingSwapBuffersTime;
-
protected WindowsOnscreenWGLDrawable(GLDrawableFactory factory, NativeWindow component) {
super(factory, component, false);
}
@@ -69,43 +60,4 @@ public class WindowsOnscreenWGLDrawable extends WindowsWGLDrawable {
return component.getHeight();
}
- public void swapBuffers() throws GLException {
- boolean didLock = false;
-
- try {
- if ( !isSurfaceLocked() ) {
- // Usually the surface shall be locked within [makeCurrent .. swap .. release]
- if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) {
- return;
- }
- didLock = true;
- }
-
- long startTime = 0;
- if (PROFILING) {
- startTime = System.currentTimeMillis();
- }
-
- if (!WGL.SwapBuffers(getNativeWindow().getSurfaceHandle()) && (WGL.GetLastError() != 0)) {
- throw new GLException("Error swapping buffers");
- }
-
- if (PROFILING) {
- long endTime = System.currentTimeMillis();
- profilingSwapBuffersTime += (endTime - startTime);
- int ticks = PROFILING_TICKS;
- if (++profilingSwapBuffersTicks == ticks) {
- System.err.println("SwapBuffers calls: " + profilingSwapBuffersTime + " ms / " + ticks + " calls (" +
- ((float) profilingSwapBuffersTime / (float) ticks) + " ms/call)");
- profilingSwapBuffersTime = 0;
- profilingSwapBuffersTicks = 0;
- }
- }
- } finally {
- if (didLock) {
- unlockSurface();
- }
- }
- }
-
}
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 2d996ca40..6a03406f9 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, true) ), true);
+ requestedCapabilities, chooser, absScreen, false, true) ), true);
if (width <= 0 || height <= 0) {
throw new GLException("Width and height of pbuffer must be positive (were (" +
width + ", " + height + "))");
@@ -108,20 +108,6 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
}
public void swapBuffers() throws GLException {
- // FIXME: this doesn't make sense any more because we don't have
- // access to our OpenGL context here
- /*
- // FIXME: do we need to do anything if the pbuffer is double-buffered?
- // For now, just grab the pixels for the render-to-texture support.
- if (rtt && !hasRTT) {
- if (DEBUG) {
- System.err.println("Copying pbuffer data to GL_TEXTURE_2D state");
- }
-
- GL gl = getGL();
- gl.glCopyTexSubImage2D(textureTarget, 0, 0, 0, 0, 0, width, height);
- }
- */
}
private void createPbuffer(long parentHdc, WGLExt wglExt) {
@@ -301,18 +287,24 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_PBUFFER_ARB;
int[] ivalues = new int[niattribs];
if (wglExt.wglGetPixelFormatAttribivARB(parentHdc, pformats[whichFormat], 0, niattribs, iattributes, 0, ivalues, 0)) {
- GLCapabilities newCaps = WindowsWGLGraphicsConfiguration.AttribList2GLCapabilities(glProfile, iattributes, niattribs, ivalues, false);
+ GLCapabilities newCaps = WindowsWGLGraphicsConfiguration.AttribList2GLCapabilities(glProfile, iattributes, niattribs, ivalues, true, false, true);
PIXELFORMATDESCRIPTOR pfd = WindowsWGLGraphicsConfiguration.createPixelFormatDescriptor();
if (WGL.DescribePixelFormat(parentHdc, pformats[whichFormat], pfd.size(), pfd) == 0) {
throw new GLException("Unable to describe pixel format " + pformats[whichFormat]);
}
+ if(newCaps.isOnscreen()) {
+ throw new GLException("Error: Selected Onscreen Caps for PBuffer: "+newCaps);
+ }
config.setCapsPFD(newCaps, pfd, pformats[whichFormat]);
} else {
PIXELFORMATDESCRIPTOR pfd = WindowsWGLGraphicsConfiguration.createPixelFormatDescriptor();
if (WGL.DescribePixelFormat(parentHdc, pformats[whichFormat], pfd.size(), pfd) == 0) {
throw new GLException("Unable to describe pixel format " + pformats[whichFormat]);
}
- GLCapabilities newCaps = WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(glProfile, pfd);
+ GLCapabilities newCaps = WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(glProfile, pfd, false, true);
+ if(newCaps.isOnscreen()) {
+ throw new GLException("Error: Selected Onscreen Caps for PBuffer: "+newCaps);
+ }
config.setCapsPFD(newCaps, pfd, pformats[whichFormat]);
}
}
diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawable.java
index 464cfbcc2..3017d258b 100644
--- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawable.java
+++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawable.java
@@ -46,6 +46,15 @@ import com.sun.gluegen.runtime.DynamicLookupHelper;
public abstract class WindowsWGLDrawable extends GLDrawableImpl {
private static final int MAX_SET_PIXEL_FORMAT_FAIL_COUNT = 5;
+ private static final boolean PROFILING = Debug.debug("WindowsWGLDrawable.profiling");
+ private static final int PROFILING_TICKS = 200;
+ private int profilingLockSurfaceTicks;
+ private long profilingLockSurfaceTime;
+ private int profilingUnlockSurfaceTicks;
+ private long profilingUnlockSurfaceTime;
+ private int profilingSwapBuffersTicks;
+ private long profilingSwapBuffersTime;
+
public WindowsWGLDrawable(GLDrawableFactory factory, NativeWindow comp, boolean realized) {
super(factory, comp, realized);
@@ -64,7 +73,7 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl {
try {
NativeWindow nativeWindow = getNativeWindow();
WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)nativeWindow.getGraphicsConfiguration().getNativeGraphicsConfiguration();
- config.updateGraphicsConfiguration(getFactory(), nativeWindow, false);
+ config.updateGraphicsConfiguration(getFactory(), nativeWindow);
if (DEBUG) {
System.err.println("!!! WindowsWGLDrawable.setRealized(true): "+config);
}
@@ -73,6 +82,48 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl {
}
}
+ public void swapBuffers() throws GLException {
+ GLCapabilities caps = (GLCapabilities)getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ if (caps.getDoubleBuffered()) {
+ boolean didLock = false;
+
+ try {
+ if ( !isSurfaceLocked() ) {
+ // Usually the surface shall be locked within [makeCurrent .. swap .. release]
+ if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) {
+ return;
+ }
+ didLock = true;
+ }
+
+ long startTime = 0;
+ if (PROFILING) {
+ startTime = System.currentTimeMillis();
+ }
+
+ if (!WGL.SwapBuffers(getNativeWindow().getSurfaceHandle()) && (WGL.GetLastError() != 0)) {
+ throw new GLException("Error swapping buffers");
+ }
+
+ if (PROFILING) {
+ long endTime = System.currentTimeMillis();
+ profilingSwapBuffersTime += (endTime - startTime);
+ int ticks = PROFILING_TICKS;
+ if (++profilingSwapBuffersTicks == ticks) {
+ System.err.println("SwapBuffers calls: " + profilingSwapBuffersTime + " ms / " + ticks + " calls (" +
+ ((float) profilingSwapBuffersTime / (float) ticks) + " ms/call)");
+ profilingSwapBuffersTime = 0;
+ profilingSwapBuffersTicks = 0;
+ }
+ }
+ } finally {
+ if (didLock) {
+ unlockSurface();
+ }
+ }
+ }
+ }
+
public DynamicLookupHelper getDynamicLookupHelper() {
return (WindowsWGLDrawableFactory) getFactoryImpl() ;
}
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 1c5c54b14..4d965e52b 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
@@ -166,8 +166,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
public GLContext createExternalGLContext() {
- AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault();
- return new WindowsExternalWGLContext(aScreen);
+ return WindowsExternalWGLContext.create(this, null);
}
public boolean canCreateExternalGLDrawable() {
@@ -175,8 +174,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements
}
public GLDrawable createExternalGLDrawable() {
- AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault();
- return WindowsExternalWGLDrawable.create(this, aScreen);
+ return WindowsExternalWGLDrawable.create(this, null);
}
public void loadOpenGL32Library() {
diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java
index 8b721824e..1a8d45465 100644
--- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java
+++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfiguration.java
@@ -58,12 +58,27 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
this.pixelfmtID = pixelfmtID;
}
+ public static WindowsWGLGraphicsConfiguration create(GLProfile glp, AbstractGraphicsScreen screen, long hdc, int pfdID, boolean onscreen, boolean usePBuffer) {
+ PIXELFORMATDESCRIPTOR pfd = createPixelFormatDescriptor();
+ if (WGL.DescribePixelFormat(hdc, pfdID, pfd.size(), pfd) == 0) {
+ throw new GLException("Unable to describe pixel format " + pfdID);
+ }
+ if(null==glp) {
+ glp = GLProfile.getDefault();
+ }
+ GLCapabilities caps = PFD2GLCapabilities(glp, pfd, onscreen, usePBuffer);
+ WindowsWGLGraphicsConfiguration cfg = new WindowsWGLGraphicsConfiguration(screen, caps, caps, pfd, pfdID, new DefaultGLCapabilitiesChooser());
+ cfg.setCapsPFD(caps, pfd, pfdID);
+
+ return cfg;
+ }
+
public Object clone() {
return super.clone();
}
- protected void updateGraphicsConfiguration(GLDrawableFactory factory, NativeWindow nativeWindow, boolean useOffScreen) {
- WindowsWGLGraphicsConfigurationFactory.updateGraphicsConfiguration(chooser, factory, nativeWindow, useOffScreen);
+ protected void updateGraphicsConfiguration(GLDrawableFactory factory, NativeWindow nativeWindow) {
+ WindowsWGLGraphicsConfigurationFactory.updateGraphicsConfiguration(chooser, factory, nativeWindow);
}
protected void setCapsPFD(GLCapabilities caps, PIXELFORMATDESCRIPTOR pfd, int pfdID) {
// FIXME: setScreen ( .. )
@@ -236,20 +251,67 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
return true;
}
+ public static final int WINDOW_BIT = 1 << 0 ;
+ public static final int BITMAP_BIT = 1 << 1 ;
+ public static final int PBUFFER_BIT = 1 << 2 ;
+
+ public static int WGLConfig2DrawableTypeBits(int[] iattribs,
+ int niattribs,
+ int[] iresults) {
+ int val = 0;
+
+ for (int i = 0; i < niattribs; i++) {
+ int attr = iattribs[i];
+ switch (attr) {
+ case WGLExt.WGL_DRAW_TO_WINDOW_ARB:
+ if(iresults[i] == GL.GL_TRUE) val |= WINDOW_BIT;
+ break;
+ case WGLExt.WGL_DRAW_TO_BITMAP_ARB:
+ if(iresults[i] == GL.GL_TRUE) val |= BITMAP_BIT;
+ break;
+ case WGLExt.WGL_DRAW_TO_PBUFFER_ARB:
+ if(iresults[i] == GL.GL_TRUE) val |= PBUFFER_BIT;
+ break;
+ }
+ }
+ return val;
+ }
+
+ public static boolean WGLConfigDrawableTypeVerify(int val, boolean onscreen, boolean usePBuffer) {
+ boolean res;
+
+ if ( onscreen ) {
+ res = ( 0 != (val & WINDOW_BIT) ) ;
+ } else {
+ res = ( 0 != (val & BITMAP_BIT) ) || usePBuffer ;
+ }
+ if ( usePBuffer ) {
+ res = res && ( 0 != (val & PBUFFER_BIT) ) ;
+ }
+
+ return res;
+ }
public static GLCapabilities AttribList2GLCapabilities(GLProfile glp, int[] iattribs,
int niattribs,
int[] iresults,
- boolean requireRenderToWindow) {
+ boolean relaxed, boolean onscreen, boolean usePBuffer) {
GLCapabilities res = new GLCapabilities(glp);
+ int drawableTypeBits = WGLConfig2DrawableTypeBits(iattribs, niattribs, iresults);
+ if(WGLConfigDrawableTypeVerify(drawableTypeBits, onscreen, usePBuffer)) {
+ res.setOnscreen(onscreen);
+ res.setPBuffer(usePBuffer);
+ } else if(relaxed) {
+ res.setOnscreen( 0 != (drawableTypeBits & WINDOW_BIT) );
+ res.setPBuffer ( 0 != (drawableTypeBits & PBUFFER_BIT) );
+ } else {
+ return null;
+ }
+
for (int i = 0; i < niattribs; i++) {
int attr = iattribs[i];
switch (attr) {
case WGLExt.WGL_DRAW_TO_WINDOW_ARB:
- if (requireRenderToWindow && iresults[i] != GL.GL_TRUE) {
- return null;
- }
- break;
-
+ case WGLExt.WGL_DRAW_TO_BITMAP_ARB:
case WGLExt.WGL_DRAW_TO_PBUFFER_ARB:
break;
@@ -342,7 +404,7 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
// PIXELFORMAT
- public static GLCapabilities PFD2GLCapabilities(GLProfile glp, PIXELFORMATDESCRIPTOR pfd) {
+ public static GLCapabilities PFD2GLCapabilities(GLProfile glp, PIXELFORMATDESCRIPTOR pfd, boolean onscreen, boolean usePBuffer) {
if ((pfd.dwFlags() & WGL.PFD_SUPPORT_OPENGL) == 0) {
return null;
}
@@ -359,8 +421,10 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
res.setStencilBits (pfd.cStencilBits());
res.setDoubleBuffered((pfd.dwFlags() & WGL.PFD_DOUBLEBUFFER) != 0);
res.setStereo ((pfd.dwFlags() & WGL.PFD_STEREO) != 0);
- res.setHardwareAccelerated(((pfd.dwFlags() & WGL.PFD_GENERIC_FORMAT) == 0) ||
- ((pfd.dwFlags() & WGL.PFD_GENERIC_ACCELERATED) != 0));
+ res.setHardwareAccelerated( ((pfd.dwFlags() & WGL.PFD_GENERIC_FORMAT) == 0) ||
+ ((pfd.dwFlags() & WGL.PFD_GENERIC_ACCELERATED) != 0) );
+ res.setOnscreen ( onscreen && ((pfd.dwFlags() & WGL.PFD_DRAW_TO_WINDOW) != 0) );
+ res.setPBuffer ( usePBuffer );
/* FIXME: Missing ??
if (GLXUtil.isMultisampleAvailable()) {
res.setSampleBuffers(glXGetFBConfig(display, fbcfg, GLX.GLX_SAMPLE_BUFFERS, tmp, 0) != 0);
@@ -374,7 +438,7 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
return res;
}
- public static PIXELFORMATDESCRIPTOR GLCapabilities2PFD(GLCapabilities caps, boolean offscreen) {
+ public static PIXELFORMATDESCRIPTOR GLCapabilities2PFD(GLCapabilities caps) {
int colorDepth = (caps.getRedBits() +
caps.getGreenBits() +
caps.getBlueBits());
@@ -387,10 +451,10 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio
if (caps.getDoubleBuffered()) {
pfdFlags |= WGL.PFD_DOUBLEBUFFER;
}
- if (offscreen) {
- pfdFlags |= WGL.PFD_DRAW_TO_BITMAP;
- } else {
+ if (caps.isOnscreen()) {
pfdFlags |= WGL.PFD_DRAW_TO_WINDOW;
+ } else {
+ pfdFlags |= WGL.PFD_DRAW_TO_BITMAP;
}
if (caps.getStereo()) {
pfdFlags |= WGL.PFD_STEREO;
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 df8081f05..f5974dc61 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
@@ -54,29 +54,42 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities,
CapabilitiesChooser chooser,
AbstractGraphicsScreen absScreen) {
- return chooseGraphicsConfigurationStatic((GLCapabilities)capabilities, chooser, absScreen, false);
+ GLCapabilities caps = (GLCapabilities)capabilities;
+ return chooseGraphicsConfigurationStatic(caps, chooser, absScreen, caps.isOnscreen(), caps.isPBuffer());
}
- protected static WindowsWGLGraphicsConfiguration createDefaultGraphicsConfiguration(AbstractGraphicsScreen absScreen, boolean useOffScreen) {
+ 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);
+ }
+
if(null==absScreen) {
absScreen = DefaultGraphicsScreen.createScreenDevice(0);
}
- return new WindowsWGLGraphicsConfiguration(absScreen, caps, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps, useOffScreen), -1, null);
+ return new WindowsWGLGraphicsConfiguration(absScreen, caps, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps), -1, null);
}
protected static WindowsWGLGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilities caps,
CapabilitiesChooser chooser,
- AbstractGraphicsScreen absScreen, boolean useOffScreen) {
+ AbstractGraphicsScreen absScreen,
+ boolean onscreen, boolean usePBuffer) {
if(null==absScreen) {
absScreen = DefaultGraphicsScreen.createScreenDevice(0);
}
- return new WindowsWGLGraphicsConfiguration(absScreen, caps, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps, useOffScreen), -1,
+ caps.setOnscreen (onscreen);
+ caps.setPBuffer (usePBuffer);
+ if(!onscreen) {
+ caps.setDoubleBuffered(false);
+ }
+ return new WindowsWGLGraphicsConfiguration(absScreen, caps, caps, WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(caps), -1,
(GLCapabilitiesChooser)chooser);
}
protected static void updateGraphicsConfiguration(CapabilitiesChooser chooser,
- GLDrawableFactory factory, NativeWindow nativeWindow, boolean useOffScreen) {
+ GLDrawableFactory factory, NativeWindow nativeWindow) {
if (nativeWindow == null) {
throw new IllegalArgumentException("NativeWindow is null");
}
@@ -88,6 +101,8 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration) nativeWindow.getGraphicsConfiguration().getNativeGraphicsConfiguration();
GLCapabilities capabilities = (GLCapabilities) config.getRequestedCapabilities();
+ boolean onscreen = capabilities.isOnscreen();
+ boolean usePBuffer = capabilities.isPBuffer();
GLProfile glProfile = capabilities.getGLProfile();
long hdc = nativeWindow.getSurfaceHandle();
@@ -98,10 +113,11 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
}
PIXELFORMATDESCRIPTOR pfd = null;
- int pixelFormat = 0;
+ int pixelFormat = -1;
+ boolean pixelFormatSet = false;
GLCapabilities chosenCaps = null;
- if (!useOffScreen) {
+ if (onscreen) {
if ((pixelFormat = WGL.GetPixelFormat(hdc)) != 0) {
// Pixelformat already set by either
// - a previous updateGraphicsConfiguration() call on the same HDC,
@@ -111,14 +127,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
System.err.println("!!!! NOTE: pixel format already chosen for HDC: 0x" + Long.toHexString(hdc)+
", pixelformat "+WGL.GetPixelFormat(hdc));
}
- pfd = WindowsWGLGraphicsConfiguration.createPixelFormatDescriptor();
- if (WGL.DescribePixelFormat(hdc, pixelFormat, pfd.size(), pfd) == 0) {
- // FIXME: should this just be a warning? Not really critical...
- throw new GLException("Unable to describe pixel format " + pixelFormat +
- " of window set by Java2D/OpenGL pipeline");
- }
- config.setCapsPFD(WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(glProfile, pfd), pfd, pixelFormat);
- return;
+ pixelFormatSet = true;
}
GLCapabilities[] availableCaps = null;
@@ -129,15 +138,13 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
WindowsWGLDrawable dummyDrawable = null;
GLContextImpl dummyContext = null;
WGLExt dummyWGLExt = null;
- if (capabilities.getSampleBuffers()) {
- dummyDrawable = new WindowsDummyWGLDrawable(factory);
- dummyContext = (GLContextImpl) dummyDrawable.createContext(null);
- if (dummyContext != null) {
- dummyContext.makeCurrent();
- dummyWGLExt = (WGLExt) dummyContext.getPlatformGLExtensions();
- }
+ dummyDrawable = new WindowsDummyWGLDrawable(factory);
+ dummyContext = (GLContextImpl) dummyDrawable.createContext(null);
+ if (dummyContext != null) {
+ dummyContext.makeCurrent();
+ dummyWGLExt = (WGLExt) dummyContext.getPlatformGLExtensions();
}
- int recommendedPixelFormat = -1;
+ int recommendedPixelFormat = pixelFormat - 1;
boolean haveWGLChoosePixelFormatARB = false;
boolean haveWGLARBMultisample = false;
boolean gotAvailableCaps = false;
@@ -151,100 +158,103 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
int[] iresults = new int [2*WindowsWGLGraphicsConfiguration.MAX_ATTRIBS];
float[] fattributes = new float[1];
- if(WindowsWGLGraphicsConfiguration.GLCapabilities2AttribList(capabilities,
- iattributes,
- dummyWGLExt,
- false,
- null)) {
- int[] pformats = new int[WindowsWGLGraphicsConfiguration.MAX_PFORMATS];
- int[] numFormatsTmp = new int[1];
- if (dummyWGLExt.wglChoosePixelFormatARB(hdc,
- iattributes, 0,
- fattributes, 0,
- WindowsWGLGraphicsConfiguration.MAX_PFORMATS,
- pformats, 0,
- numFormatsTmp, 0)) {
- numFormats = numFormatsTmp[0];
- if (numFormats > 0) {
- // Remove one-basing of pixel format (added on later)
- recommendedPixelFormat = pformats[0] - 1;
+ if(pixelFormat<=0) {
+ if(WindowsWGLGraphicsConfiguration.GLCapabilities2AttribList(capabilities,
+ iattributes,
+ dummyWGLExt,
+ false,
+ null)) {
+ int[] pformats = new int[WindowsWGLGraphicsConfiguration.MAX_PFORMATS];
+ int[] numFormatsTmp = new int[1];
+ if (dummyWGLExt.wglChoosePixelFormatARB(hdc,
+ iattributes, 0,
+ fattributes, 0,
+ WindowsWGLGraphicsConfiguration.MAX_PFORMATS,
+ pformats, 0,
+ numFormatsTmp, 0)) {
+ numFormats = numFormatsTmp[0];
+ if (recommendedPixelFormat<=0 && numFormats > 0) {
+ // Remove one-basing of pixel format (added on later)
+ recommendedPixelFormat = pformats[0] - 1;
+ if (DEBUG) {
+ System.err.println(getThreadName() + ": Used wglChoosePixelFormatARB to recommend pixel format " + recommendedPixelFormat);
+ }
+ }
+ } else {
if (DEBUG) {
- System.err.println(getThreadName() + ": Used wglChoosePixelFormatARB to recommend pixel format " + recommendedPixelFormat);
+ System.err.println(getThreadName() + ": wglChoosePixelFormatARB failed: " + WGL.GetLastError() );
+ Thread.dumpStack();
}
}
- } else {
if (DEBUG) {
- System.err.println(getThreadName() + ": wglChoosePixelFormatARB failed: " + WGL.GetLastError() );
- Thread.dumpStack();
- }
- }
- if (DEBUG) {
- if (recommendedPixelFormat < 0) {
- System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format");
- if (capabilities.getSampleBuffers()) {
- System.err.print(" for multisampled GLCapabilities");
+ if (recommendedPixelFormat < 0) {
+ System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format");
+ if (capabilities.getSampleBuffers()) {
+ System.err.print(" for multisampled GLCapabilities");
+ }
+ System.err.println();
}
- System.err.println();
}
}
+ }
- // Produce a list of GLCapabilities to give to the
- // GLCapabilitiesChooser.
- // Use wglGetPixelFormatAttribivARB instead of
- // DescribePixelFormat to get higher-precision information
- // about the pixel format (should make the GLCapabilities
- // more precise as well...i.e., remove the
- // "HardwareAccelerated" bit, which is basically
- // meaningless, and put in whether it can render to a
- // window, to a pbuffer, or to a pixmap)
- int niattribs = 0;
- iattributes[0] = WGLExt.WGL_NUMBER_PIXEL_FORMATS_ARB;
- if (dummyWGLExt.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, 0, iresults, 0)) {
- numFormats = iresults[0];
+ // Produce a list of GLCapabilities to give to the
+ // GLCapabilitiesChooser.
+ // Use wglGetPixelFormatAttribivARB instead of
+ // DescribePixelFormat to get higher-precision information
+ // about the pixel format (should make the GLCapabilities
+ // more precise as well...i.e., remove the
+ // "HardwareAccelerated" bit, which is basically
+ // meaningless, and put in whether it can render to a
+ // window, to a pbuffer, or to a pixmap)
+ int niattribs = 0;
+ iattributes[0] = WGLExt.WGL_NUMBER_PIXEL_FORMATS_ARB;
+ if (dummyWGLExt.wglGetPixelFormatAttribivARB(hdc, 0, 0, 1, iattributes, 0, iresults, 0)) {
+ numFormats = iresults[0];
- if (DEBUG) {
- System.err.println("wglGetPixelFormatAttribivARB reported WGL_NUMBER_PIXEL_FORMATS = " + numFormats);
- }
+ if (DEBUG) {
+ System.err.println("wglGetPixelFormatAttribivARB reported WGL_NUMBER_PIXEL_FORMATS = " + numFormats);
+ }
- // Should we be filtering out the pixel formats which aren't
- // applicable, as we are doing here?
- // We don't have enough information in the GLCapabilities to
- // represent those that aren't...
- iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCELERATION_ARB;
- iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB;
- iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB;
- iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB;
- iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB;
- iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB;
- if (haveWGLARBMultisample) {
- iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB;
- iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB;
- }
+ // Should we be filtering out the pixel formats which aren't
+ // applicable, as we are doing here?
+ // We don't have enough information in the GLCapabilities to
+ // represent those that aren't...
+ iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_ACCELERATION_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_SUPPORT_OPENGL_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_DEPTH_BITS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_STENCIL_BITS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_DOUBLE_BUFFER_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_STEREO_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_RED_BITS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_GREEN_BITS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_BLUE_BITS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_ALPHA_BITS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_ACCUM_RED_BITS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_ACCUM_GREEN_BITS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_ACCUM_BLUE_BITS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_ACCUM_ALPHA_BITS_ARB;
+ if (haveWGLARBMultisample) {
+ iattributes[niattribs++] = WGLExt.WGL_SAMPLE_BUFFERS_ARB;
+ iattributes[niattribs++] = WGLExt.WGL_SAMPLES_ARB;
+ }
- availableCaps = new GLCapabilities[numFormats];
- for (int i = 0; i < numFormats; i++) {
- if (!dummyWGLExt.wglGetPixelFormatAttribivARB(hdc, i+1, 0, niattribs, iattributes, 0, iresults, 0)) {
- throw new GLException("Error getting pixel format attributes for pixel format " + (i + 1) + " of device context");
- }
- availableCaps[i] = WindowsWGLGraphicsConfiguration.AttribList2GLCapabilities(glProfile, iattributes, niattribs, iresults, true);
- }
- gotAvailableCaps = true;
- } else {
- long lastErr = WGL.GetLastError();
- // Intel Extreme graphics fails with a zero error code
- if (lastErr != 0) {
- throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB: error code " + WGL.GetLastError());
+ availableCaps = new GLCapabilities[numFormats];
+ for (int i = 0; i < numFormats; i++) {
+ if (!dummyWGLExt.wglGetPixelFormatAttribivARB(hdc, i+1, 0, niattribs, iattributes, 0, iresults, 0)) {
+ throw new GLException("Error getting pixel format attributes for pixel format " + (i + 1) + " of device context");
}
+ availableCaps[i] = WindowsWGLGraphicsConfiguration.AttribList2GLCapabilities(glProfile, iattributes, niattribs, iresults,
+ pixelFormatSet, onscreen, usePBuffer);
+ }
+ gotAvailableCaps = true;
+ } else {
+ long lastErr = WGL.GetLastError();
+ // Intel Extreme graphics fails with a zero error code
+ if (lastErr != 0) {
+ throw new GLException("Unable to enumerate pixel formats of window using wglGetPixelFormatAttribivARB: error code " + WGL.GetLastError());
}
}
}
@@ -264,7 +274,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
System.err.println(getThreadName() + ": Using ChoosePixelFormat because no wglChoosePixelFormatARB");
}
}
- pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(capabilities, !useOffScreen);
+ pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(capabilities);
recommendedPixelFormat = WGL.ChoosePixelFormat(hdc, pfd);
if (DEBUG) {
System.err.println(getThreadName() + ": Recommended pixel format = " + recommendedPixelFormat);
@@ -282,7 +292,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
if (WGL.DescribePixelFormat(hdc, 1 + i, pfd.size(), pfd) == 0) {
throw new GLException("Error describing pixel format " + (1 + i) + " of device context");
}
- availableCaps[i] = WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(glProfile, pfd);
+ availableCaps[i] = WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(glProfile, pfd, onscreen, usePBuffer);
}
}
@@ -291,22 +301,24 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
// chooseCapabilities call, but for the time being, assume they
// won't be changed
- if(null!=chooser) {
- // Supply information to chooser
- try {
- pixelFormat = chooser.chooseCapabilities(capabilities, availableCaps, recommendedPixelFormat);
- } catch (NativeWindowException e) {
- throw new GLException(e);
+ if(pixelFormat<=0) {
+ if(null!=chooser) {
+ // Supply information to chooser
+ try {
+ pixelFormat = chooser.chooseCapabilities(capabilities, availableCaps, recommendedPixelFormat);
+ } catch (NativeWindowException e) {
+ throw new GLException(e);
+ }
+ } else {
+ pixelFormat = recommendedPixelFormat;
}
- } else {
- pixelFormat = recommendedPixelFormat;
- }
- if ((pixelFormat < 0) || (pixelFormat >= numFormats)) {
- throw new GLException("Invalid result " + pixelFormat +
- " from GLCapabilitiesChooser (should be between 0 and " +
- (numFormats - 1) + ")");
+ if ((pixelFormat < 0) || (pixelFormat >= numFormats)) {
+ throw new GLException("Invalid result " + pixelFormat +
+ " from GLCapabilitiesChooser (should be between 0 and " +
+ (numFormats - 1) + ")");
+ }
+ pixelFormat += 1; // one-base the index
}
- pixelFormat += 1; // one-base the index
chosenCaps = availableCaps[pixelFormat-1];
if (DEBUG) {
System.err.println(getThreadName() + ": Chosen pixel format (" + pixelFormat + "):");
@@ -319,17 +331,20 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
// For now, use ChoosePixelFormat for offscreen surfaces until
// we figure out how to properly choose an offscreen-
// compatible pixel format
- pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(capabilities, !useOffScreen);
+ pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(capabilities);
pixelFormat = WGL.ChoosePixelFormat(hdc, pfd);
}
- if (!WGL.SetPixelFormat(hdc, pixelFormat, pfd)) {
- long lastError = WGL.GetLastError();
- if (DEBUG) {
- System.err.println(getThreadName() + ": SetPixelFormat failed: current context = " + WGL.wglGetCurrentContext() +
- ", current DC = " + WGL.wglGetCurrentDC());
- System.err.println(getThreadName() + ": GetPixelFormat(hdc " + toHexString(hdc) + ") returns " + WGL.GetPixelFormat(hdc));
- }
- throw new GLException("Unable to set pixel format " + pixelFormat + " for device context " + toHexString(hdc) + ": error code " + lastError);
+ if(!pixelFormatSet) {
+ if (!WGL.SetPixelFormat(hdc, pixelFormat, pfd)) {
+ long lastError = WGL.GetLastError();
+ if (DEBUG) {
+ System.err.println(getThreadName() + ": SetPixelFormat failed: current context = " + WGL.wglGetCurrentContext() +
+ ", current DC = " + WGL.wglGetCurrentDC());
+ System.err.println(getThreadName() + ": GetPixelFormat(hdc " + toHexString(hdc) + ") returns " + WGL.GetPixelFormat(hdc));
+ }
+ throw new GLException("Unable to set pixel format " + pixelFormat + " for device context " + toHexString(hdc) + ": error code " + lastError);
+ }
+ pixelFormatSet=true;
}
// Reuse the previously-constructed GLCapabilities because it
// turns out that using DescribePixelFormat on some pixel formats
@@ -338,7 +353,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
if (chosenCaps != null) {
capabilities = chosenCaps;
} else {
- capabilities = WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(glProfile, pfd);
+ capabilities = WindowsWGLGraphicsConfiguration.PFD2GLCapabilities(glProfile, pfd, onscreen, usePBuffer);
}
config.setCapsPFD(capabilities, pfd, pixelFormat);
}