diff options
author | Sven Gothel <[email protected]> | 2009-10-05 02:54:59 -0700 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-10-05 02:54:59 -0700 |
commit | 76bf2e5a7f23def0a3bf2b688791b593ecb283ab (patch) | |
tree | 84b7b2a25cc38450dc83a78d1f1ed165195a599e /src/jogl/classes/com/sun/opengl/impl/windows | |
parent | 59257476777104ff3f117d87a8205161cb800abf (diff) |
GLDrawableFactory Cleanup (-> On- Offscreen and PBuffer)
- Base all PBuffer/Offscreen GLDrawable creators on
a prev. created 'NativeWindow + SurfaceChangeable' instance.
Simplifies implementation path.
This also removes the almost cyclic referencing of
GLWindow -> OffscreenWindow
GLWindow -> Drawable -> NullWindow -> OffscreenWindow
Now it is just
GLWindow -> OffscreenWindow
GLWindow -> Drawable -> OffscreenWindow
- createGLDrawable() shall be used for all types now,
especially if you want to pass the offscreen NativeWindow
and benefit from the surfaceChangedListener etc ..
- Add public createOffscreenDrawable(..)
- EGLDrawable:
- Query surface only if not 0
- [re]create surface only if needed,
using 'ownEGL*' flag for destruction only.
Diffstat (limited to 'src/jogl/classes/com/sun/opengl/impl/windows')
3 files changed, 29 insertions, 69 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 a3e5f6da4..35fbcc6f5 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 @@ -48,14 +48,8 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { private long origbitmap; private long hbitmap; - public WindowsOffscreenWGLDrawable(GLDrawableFactory factory, - AbstractGraphicsScreen absScreen, - GLCapabilities requestedCapabilities, - GLCapabilitiesChooser chooser, - int width, - int height) { - super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(requestedCapabilities, chooser, absScreen)), true); - ((NullWindow) getNativeWindow()).setSize(width, height); + public WindowsOffscreenWGLDrawable(GLDrawableFactory factory, NativeWindow target) { + super(factory, target, true); create(); } @@ -94,7 +88,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { System.out.println("LastError: " + WGL.GetLastError()); throw new GLException("Error creating device context for offscreen OpenGL context"); } - nw.setSurfaceHandle(hdc); + ((SurfaceChangeable)nw).setSurfaceHandle(hdc); hbitmap = WGL.CreateDIBSection(hdc, info, WGL.DIB_RGB_COLORS, 0, 0, 0); if (hbitmap == 0) { @@ -115,7 +109,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { } public void destroy() { - NullWindow nw = (NullWindow) getNativeWindow(); + NativeWindow nw = getNativeWindow(); if (nw.getSurfaceHandle() != 0) { // Must destroy bitmap and device context WGL.SelectObject(nw.getSurfaceHandle(), origbitmap); @@ -123,7 +117,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { WGL.DeleteDC(nw.getSurfaceHandle()); origbitmap = 0; hbitmap = 0; - nw.setSurfaceHandle(0); + ((SurfaceChangeable)nw).setSurfaceHandle(0); } } 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 41a4e3877..798eafad3 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 @@ -42,7 +42,6 @@ package com.sun.opengl.impl.windows.wgl; import javax.media.opengl.*; import javax.media.nativewindow.*; import com.sun.opengl.impl.*; -import com.sun.nativewindow.impl.NullWindow; public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { private long cachedParentHdc; @@ -52,28 +51,20 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { private int floatMode; - public WindowsPbufferWGLDrawable(GLDrawableFactory factory, - AbstractGraphicsScreen absScreen, - GLCapabilities requestedCapabilities, - final GLCapabilitiesChooser chooser, - int width, - int height, + public WindowsPbufferWGLDrawable(GLDrawableFactory factory, NativeWindow target, WindowsWGLDrawable dummyDrawable, WGLExt wglExt) { - super(factory, new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( - requestedCapabilities, chooser, absScreen) ), true); - if (width <= 0 || height <= 0) { - throw new GLException("Width and height of pbuffer must be positive (were (" + - width + ", " + height + "))"); - } - NullWindow nw = (NullWindow) getNativeWindow(); - nw.setSize(width, height); + super(factory, target, true); if (DEBUG) { - System.out.println("Pbuffer caps: " + requestedCapabilities); + System.out.println("Pbuffer config: " + getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration()); } createPbuffer(dummyDrawable.getNativeWindow().getSurfaceHandle(), wglExt); + + if (DEBUG) { + System.err.println("Created pbuffer " + this); + } } public GLContext createContext(GLContext shareWith) { @@ -81,7 +72,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { } public void destroy() { - NullWindow nw = (NullWindow) getNativeWindow(); + NativeWindow nw = getNativeWindow(); if (nw.getSurfaceHandle() != 0) { // Must release DC and pbuffer // NOTE that since the context is not current, glGetError() can @@ -91,7 +82,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { if (wglExt.wglReleasePbufferDCARB(buffer, nw.getSurfaceHandle()) == 0) { throw new GLException("Error releasing pbuffer device context: error code " + WGL.GetLastError()); } - nw.setSurfaceHandle(0); + ((SurfaceChangeable)nw).setSurfaceHandle(0); if (!wglExt.wglDestroyPbufferARB(buffer)) { throw new GLException("Error destroying pbuffer: error code " + WGL.GetLastError()); } @@ -261,10 +252,10 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { throw new GLException("pbuffer creation error: wglGetPbufferDC() failed"); } - NullWindow nw = (NullWindow) getNativeWindow(); + NativeWindow nw = getNativeWindow(); // Set up instance variables buffer = tmpBuffer; - nw.setSurfaceHandle(tmpHdc); + ((SurfaceChangeable)nw).setSurfaceHandle(tmpHdc); cachedWGLExt = wglExt; cachedParentHdc = parentHdc; @@ -320,11 +311,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { width = tmp[0]; wglExt.wglQueryPbufferARB( buffer, WGLExt.WGL_PBUFFER_HEIGHT_ARB, tmp, 0 ); height = tmp[0]; - nw.setSize(width, height); - - if (DEBUG) { - System.err.println("Created pbuffer " + width + " x " + height); - } + ((SurfaceChangeable)nw).setSize(width, height); } private static String wglGetLastError() { 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 9137e4c7b..af65861b9 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 @@ -46,6 +46,7 @@ import javax.media.opengl.*; import com.sun.opengl.impl.*; import com.sun.nativewindow.impl.NWReflection; import com.sun.gluegen.runtime.DynamicLookupHelper; +import com.sun.nativewindow.impl.NullWindow; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements DynamicLookupHelper { private static final boolean VERBOSE = Debug.verbose(); @@ -78,15 +79,8 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements return new WindowsOnscreenWGLDrawable(this, target); } - public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, - GLCapabilitiesChooser chooser, - int width, - int height) { - AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(); - capabilities.setDoubleBuffered(false); // FIXME - capabilities.setOnscreen(false); - capabilities.setPBuffer(false); - return new WindowsOffscreenWGLDrawable(this, aScreen, capabilities, chooser, width, height); + protected GLDrawableImpl createOffscreenDrawable(NativeWindow target) { + return new WindowsOffscreenWGLDrawable(this, target); } private boolean pbufferSupportInitialized = false; @@ -124,17 +118,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements return canCreateGLPbuffer; } - public GLDrawableImpl createGLPbufferDrawable(final GLCapabilities capabilities, - final GLCapabilitiesChooser chooser, - final int initialWidth, - final int initialHeight) { - if (!canCreateGLPbuffer()) { - throw new GLException("Pbuffer support not available with current graphics card"); - } - capabilities.setDoubleBuffered(false); // FIXME - capabilities.setOnscreen(false); - capabilities.setPBuffer(true); - final GLCapabilities caps = capabilities; + protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeWindow target) { final List returnList = new ArrayList(); final GLDrawableFactory factory = this; Runnable r = new Runnable() { @@ -148,10 +132,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements dummyContext.makeCurrent(); WGLExt dummyWGLExt = dummyContext.getWGLExt(); try { - AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(); - GLDrawableImpl pbufferDrawable = new WindowsPbufferWGLDrawable(factory, aScreen, caps, chooser, - initialWidth, - initialHeight, + GLDrawableImpl pbufferDrawable = new WindowsPbufferWGLDrawable(factory, target, dummyDrawable, dummyWGLExt); returnList.add(pbufferDrawable); @@ -169,16 +150,14 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl implements return (GLDrawableImpl) returnList.get(0); } - public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, - final GLCapabilitiesChooser chooser, - final int initialWidth, - final int initialHeight, - final GLContext shareWith) { - GLDrawableImpl pbufferDrawable = createGLPbufferDrawable( - capabilities, chooser, initialWidth, initialHeight); - return new GLPbufferImpl(pbufferDrawable, shareWith); + protected NativeWindow createOffscreenWindow(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(); + NullWindow nw = new NullWindow(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( + capabilities, chooser, screen) ); + nw.setSize(width, height); + return nw; } - + public GLContext createExternalGLContext() { return WindowsExternalWGLContext.create(this, null); } |