diff options
author | Chien Yang <[email protected]> | 2004-10-15 23:33:45 +0000 |
---|---|---|
committer | Chien Yang <[email protected]> | 2004-10-15 23:33:45 +0000 |
commit | 14b52db7ab4c4be2bd39ff944cec056c291f999a (patch) | |
tree | 3bf6c274a97828b9ca4cd28de6ed602dfeac9af3 /src/classes | |
parent | cdf24368541b18e5ffc56f5c9449310e874f4a2f (diff) |
Issue number: 4, 28, 71 and 76
Windows OpenGL only : This fix will use hardware Pbuffer for offScreenBuffer rendering if the graphics hardware support it, else BitMap is use as a fallback.
1) Fixed issue 4 - Speed of OffScreen Canvas3D
2) Fixed issue 28 - Combine Mode & Missing Texture in OffScreen snapshot on Win/XP
3) Fixed issue 71 - OGL: OffScreen canvas ignore GraphicsConfigTemplate under windows.
4) Fixed issue 76 - OffScreen rendering should use Pbuffer on Windows / OpenGL
5) Cleanup native ChoosePixelFormat code.
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@56 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/classes')
4 files changed, 111 insertions, 15 deletions
diff --git a/src/classes/share/javax/media/j3d/Canvas3D.java b/src/classes/share/javax/media/j3d/Canvas3D.java index eb979e6..50ee073 100644 --- a/src/classes/share/javax/media/j3d/Canvas3D.java +++ b/src/classes/share/javax/media/j3d/Canvas3D.java @@ -559,13 +559,27 @@ public class Canvas3D extends Canvas { // the visual id. int vid = 0; - // Fix for issue 20. + + // fbConfig is a pointer to the fbConfig object that is associated with + // the GraphicsConfiguration object used to create this Canvas. + // + // For Unix : Fix for issue 20. // The fbConfig is only used when running X11. It contains a pointer // to the native GLXFBConfig structure list, since in some cases the visual id // alone isn't sufficient for the native OpenGL renderer (e.g., when using // Solaris OpenGL with Xinerama mode disabled). + // + // For Windows : Fix for issue 76. This is use as a holder of the + // PixelFormat structure ( see also gldef.h ) to allow value such + // as offScreen's pixelformat, and ARB function pointers to be stored. long fbConfig = 0; + // offScreenBufferInfo is a pointer to additional information about the + // offScreenBuffer in this Canvas. + // + // For Windows : Fix for issue 76. + long offScreenBufferInfo = 0; + // fbConfigTable is a static hashtable which allows getBestConfiguration() // in NativeConfigTemplate3D to map a GraphicsConfiguration to the pointer // to the actual GLXFBConfig that glXChooseFBConfig() returns. The Canvas3D @@ -812,7 +826,7 @@ public class Canvas3D extends Canvas { native static void destroyContext(long display, int window, long context); // This is the native for creating offscreen buffer - native int createOffScreenBuffer(long ctx, long display, int window, long fbConfig, int width, int height); + native int createOffScreenBuffer(long ctx, long display, int vid, long fbConfig, int width, int height); native void destroyOffScreenBuffer(long ctx, long display, long fbConfig, int window); @@ -1117,7 +1131,7 @@ public class Canvas3D extends Canvas { this.offScreen = offScreen; this.graphicsConfiguration = graphicsConfiguration; - // Needed for Win32 only. + // Needed for Win32 only. vid = nativeWSobj.getCanvasVid(graphicsConfiguration); // Fix for issue 20. @@ -1127,15 +1141,16 @@ public class Canvas3D extends Canvas { if ((fbConfigObject != null) && (fbConfigObject instanceof Long)) { fbConfig = ((Long)fbConfigObject).longValue(); - // System.out.println("Canvas3D creation FBConfig = " + fbConfig); - + /* System.out.println("Canvas3D creation FBConfig = " + fbConfig + + " offScreen is " + offScreen ); + */ + // This check is needed for Unix and Win-ogl only. fbConfig should + // remain as -1, default value, for D3D case. if (fbConfig == 0) { throw new IllegalArgumentException (J3dI18N.getString("Canvas3D23")); } } - - if (offScreen) { screen = new Screen3D(graphicsConfiguration, offScreen); @@ -3388,7 +3403,7 @@ public class Canvas3D extends Canvas { // inside the native code after setting the various // fields in this object createQueryContext(screen.display, window, vid, - fbConfig, offScreen, 10, 10); + fbConfig, offScreen, 1, 1); } /** diff --git a/src/classes/share/javax/media/j3d/Renderer.java b/src/classes/share/javax/media/j3d/Renderer.java index 12b4dce..cd47249 100644 --- a/src/classes/share/javax/media/j3d/Renderer.java +++ b/src/classes/share/javax/media/j3d/Renderer.java @@ -450,7 +450,7 @@ class Renderer extends J3dThread { canvas.window = canvas.createOffScreenBuffer(canvas.ctx, canvas.screen.display, - canvas.window, + canvas.vid, canvas.fbConfig, canvas.offScreenCanvasSize.width, canvas.offScreenCanvasSize.height); diff --git a/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java index 997aaee..2759ea5 100644 --- a/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java +++ b/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java @@ -19,6 +19,7 @@ import sun.awt.Win32GraphicsConfig; import java.awt.GraphicsConfigTemplate; class NativeConfigTemplate3D { + private final static boolean debug = false; NativeConfigTemplate3D() { VirtualUniverse.createMC(); @@ -40,7 +41,12 @@ class NativeConfigTemplate3D { * selects the proper visual */ native int - choosePixelFormat(long ctx, int screen, int[] attrList); + choosePixelFormat(long ctx, int screen, int[] attrList, long[] pFormatInfo); + + // Native method to free an PixelFormatInfo struct. This is static since it + // may need to be called to clean up the Canvas3D fbConfigTable after the + // NativeConfigTemplate3D has been disposed of. + static native void freePixelFormatInfo(long pFormatInfo); // Native methods to return whether a particular attribute is available native boolean isStereoAvailable(long ctx, long display, int screen, int pixelFormat); @@ -58,6 +64,17 @@ class NativeConfigTemplate3D { Win32GraphicsDevice gd = (Win32GraphicsDevice)((Win32GraphicsConfig)gc[0]).getDevice(); + /* Not ready to enforce ARB extension in J3D1.3.2, but will likely to + do so in J3D 1.4. + System.out.println("getBestConfiguration : Checking WGL ARB support\n"); + + if (!NativeScreenInfo.isWglARB()) { + Thread.dumpStack(); + System.out.println("getBestConfiguration : WGL ARB support fail\n"); + return null; + } + */ + // holds the list of attributes to be tramslated // for glxChooseVisual call int attrList[] = new int[NUM_ITEMS]; @@ -72,12 +89,40 @@ class NativeConfigTemplate3D { attrList[ANTIALIASING] = template.getSceneAntialiasing(); NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); int screen = nativeScreenInfo.getScreen(); - int pixelFormat = choosePixelFormat(0, screen, attrList); - if (pixelFormat == -1) { + + long[] pFormatInfo = new long[1]; + + /* Deliberately set this to -1. pFormatInfo is not use in + D3D, so this value will be unchange in the case of D3D. + In the case of OGL, the return value should be 0 or a + positive valid address. + */ + pFormatInfo[0] = -1; + + int pixelFormat = choosePixelFormat(0, screen, attrList, pFormatInfo); + if (debug) { + System.out.println(" choosePixelFormat() returns " + pixelFormat); + System.out.println(" pFormatInfo is " + pFormatInfo[0]); + System.out.println(); + } + + if (pixelFormat < 0) { // current mode don't support the minimum config return null; } - return new J3dGraphicsConfig(gd, pixelFormat); + + GraphicsConfiguration gc1 = new J3dGraphicsConfig(gd, pixelFormat); + // We need to cache the offScreen pixelformat that glXChoosePixelFormat() + // returns, since this is not cached with J3dGraphicsConfig and there + // are no public constructors to allow us to extend it. + synchronized (Canvas3D.fbConfigTable) { + if (Canvas3D.fbConfigTable.get(gc1) == null) + Canvas3D.fbConfigTable.put(gc1, new Long(pFormatInfo[0])); + else + freePixelFormatInfo(pFormatInfo[0]); + } + + return gc1; } /** @@ -90,6 +135,17 @@ class NativeConfigTemplate3D { Win32GraphicsDevice gd = (Win32GraphicsDevice)((Win32GraphicsConfig) gc).getDevice(); + /* Not ready to enforce ARB extension in J3D1.3.2, but will likely to + do so in J3D 1.4. + System.out.println("isGraphicsConfigSupported : Checking WGL ARB support\n"); + + if (!NativeScreenInfo.isWglARB()) { + Thread.dumpStack(); + System.out.println("isGraphicsConfigSupported : WGL ARB support fail\n"); + return false; + } + */ + // holds the list of attributes to be tramslated // for glxChooseVisual call int attrList[] = new int[NUM_ITEMS]; @@ -106,9 +162,16 @@ class NativeConfigTemplate3D { NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); int screen = nativeScreenInfo.getScreen(); - int pixelFormat = choosePixelFormat(0, screen, attrList); + long[] pFormatInfo = new long[1]; + + int pixelFormat = choosePixelFormat(0, screen, attrList, pFormatInfo); + if (debug) { + System.out.println(" choosePixelFormat() returns " + pixelFormat); + System.out.println(" pFormatInfo is " + pFormatInfo[0]); + System.out.println(); + } - if (pixelFormat == -1) { + if (pixelFormat < 0) { // current mode don't support the minimum config return false; } else return true; diff --git a/src/classes/win32/javax/media/j3d/NativeScreenInfo.java b/src/classes/win32/javax/media/j3d/NativeScreenInfo.java index 43ee7e5..ef539ec 100644 --- a/src/classes/win32/javax/media/j3d/NativeScreenInfo.java +++ b/src/classes/win32/javax/media/j3d/NativeScreenInfo.java @@ -19,6 +19,24 @@ class NativeScreenInfo { private int display = 0; private int screen = 0; + + private static boolean wglARBChecked = false; + private static boolean isWglARB; + + private native static boolean queryWglARB(); + + // This method will return true if wglGetExtensionsStringARB is supported, + // else return false + synchronized static boolean isWglARB() { + + if (!wglARBChecked) { + // Query for wglGetExtensionsStringARB support. + isWglARB = queryWglARB(); + wglARBChecked = true; + } + return isWglARB; + } + NativeScreenInfo(GraphicsDevice graphicsDevice) { // Get the screen number screen = ((sun.awt.Win32GraphicsDevice)graphicsDevice).getScreen(); |