diff options
Diffstat (limited to 'src/classes/share')
-rw-r--r-- | src/classes/share/javax/media/j3d/MasterControl.java | 39 | ||||
-rw-r--r-- | src/classes/share/javax/media/j3d/NativePipeline.java | 39 | ||||
-rw-r--r-- | src/classes/share/javax/media/j3d/Pipeline.java | 51 |
3 files changed, 111 insertions, 18 deletions
diff --git a/src/classes/share/javax/media/j3d/MasterControl.java b/src/classes/share/javax/media/j3d/MasterControl.java index af3d717..418e325 100644 --- a/src/classes/share/javax/media/j3d/MasterControl.java +++ b/src/classes/share/javax/media/j3d/MasterControl.java @@ -720,15 +720,23 @@ class MasterControl { static void loadLibraries() { assert !librariesLoaded; - // Set global flags indicating whether we are running on Windows or MacOS - String osName = getProperty("os.name"); - isWindowsOs = osName != null && osName.startsWith("Windows"); - isMacOs = osName != null && osName.startsWith("Mac"); - -//KCR: System.err.println("MasterControl.loadLibraries()"); -//KCR: System.err.println(" osName = \"" + osName + "\"" + -//KCR: ", isWindowsOs = " + isWindowsOs + -//KCR: ", isMacOs = " + isMacOs); + // Get platform system properties + String osName = getProperty("os.name").toLowerCase(); + String sunArchDataModel = getProperty("sun.arch.data.model"); + + // Set global flags based on platform architecture + isMacOs = osName != null && osName.startsWith("mac"); + isWindowsOs = osName != null && osName.startsWith("windows"); + boolean isWindowsVista = isWindowsOs && osName.indexOf("vista") != -1; + boolean is64Bit = (sunArchDataModel != null) && sunArchDataModel.equals("64"); + +// System.err.println("MasterControl.loadLibraries()"); +// System.err.println(" osName [lower-case] = \"" + osName + "\"" + +// ", sunArchDataModel = " + sunArchDataModel); +// System.err.println(" is64Bit = " + is64Bit + +// ", isWindowsOs = " + isWindowsOs + +// ", isMacOs = " + isMacOs + +// ", isWindowsVista = " + isWindowsVista); // Initialize the Pipeline object associated with the // renderer specified by the "j3d.rend" system property. @@ -741,11 +749,13 @@ class MasterControl { Pipeline.Type pipelineType = isMacOs ? Pipeline.Type.JOGL : Pipeline.Type.NATIVE_OGL; - String rendStr = getProperty("j3d.rend"); + final String rendStr = getProperty("j3d.rend"); + boolean nativeOglRequested = false; if (rendStr == null) { // Use default pipeline } else if (rendStr.equals("ogl") && !isMacOs) { pipelineType = Pipeline.Type.NATIVE_OGL; + nativeOglRequested = true; } else if (rendStr.equals("d3d") && isWindowsOs) { pipelineType = Pipeline.Type.NATIVE_D3D; } else if (rendStr.equals("jogl")) { @@ -757,7 +767,14 @@ class MasterControl { // Use default pipeline } -//KCR: System.err.println(" using " + pipelineType + " pipeline"); + // Issue 452 : if we are on 32-bit Windows, then check whether we + // can and should use OpenGL. Note that we can't do this on 64-bit + // Windows until we have a 64-bit D3D pipeline. + if (isWindowsOs && !is64Bit && pipelineType == Pipeline.Type.NATIVE_OGL) { + if (!Pipeline.useNativeOgl(isWindowsVista, nativeOglRequested)) { + pipelineType = Pipeline.Type.NATIVE_D3D; + } + } // Construct the singleton Pipeline instance Pipeline.createPipeline(pipelineType); diff --git a/src/classes/share/javax/media/j3d/NativePipeline.java b/src/classes/share/javax/media/j3d/NativePipeline.java index 63f7e42..97a478a 100644 --- a/src/classes/share/javax/media/j3d/NativePipeline.java +++ b/src/classes/share/javax/media/j3d/NativePipeline.java @@ -49,7 +49,32 @@ class NativePipeline extends Pipeline { * class, we can create one statically. */ private static NativeConfigTemplate3D nativeTemplate = new NativeConfigTemplate3D(); - + + // Flag indicating that the ogl-chk library has been loaded + private static boolean oglChkLibraryLoaded = false; + + // Method to return the vendor string for the native OpenGL pipeline. + // If the native library cannot be loaded, or if GL_VERSION < 1.2 + // then null is returned. + static String getSupportedOglVendor() { + if (!oglChkLibraryLoaded) { + try { + loadLibrary("j3dcore-ogl-chk"); + } catch (RuntimeException ex) { + System.err.println(ex); + return null; + } catch (Error ex) { + System.err.println(ex); + return null; + } + oglChkLibraryLoaded = true; + } + return getSupportedOglVendorNative(); + } + + // Native method to return the vendor string + private static native String getSupportedOglVendorNative(); + /** * Constructor for singleton NativePipeline instance */ @@ -110,7 +135,7 @@ class NativePipeline extends Pipeline { } } } - + /** * Returns true if the Cg library is loaded and available. Note that this * does not necessarily mean that Cg is supported by the graphics card. @@ -118,7 +143,7 @@ class NativePipeline extends Pipeline { boolean isCgLibraryAvailable() { return cgLibraryAvailable; } - + /** * Returns true if the GLSL library is loaded and available. Note that this * does not necessarily mean that GLSL is supported by the graphics card. @@ -126,11 +151,11 @@ class NativePipeline extends Pipeline { boolean isGLSLLibraryAvailable() { return glslLibraryAvailable; } - + /** * Load the specified native library. */ - private void loadLibrary(String libName) { + private static void loadLibrary(String libName) { final String libraryName = libName; java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { @@ -140,7 +165,7 @@ class NativePipeline extends Pipeline { } }); } - + /** * Parse the specified System properties containing a PATH and return an * array of Strings, where each element is an absolute filename consisting of @@ -3313,5 +3338,5 @@ class NativePipeline extends Pipeline { void freeDrawingSurfaceNative(Object o) { DrawingSurfaceObjectAWT.freeDrawingSurface(o); } - + } diff --git a/src/classes/share/javax/media/j3d/Pipeline.java b/src/classes/share/javax/media/j3d/Pipeline.java index e33516c..dd413ef 100644 --- a/src/classes/share/javax/media/j3d/Pipeline.java +++ b/src/classes/share/javax/media/j3d/Pipeline.java @@ -43,6 +43,57 @@ abstract class Pipeline { } /** + * Method to check whether the native OpenGL library can and should be used + * on Windows. We will use D3D if OpenGL is unavailable or undesirable. + */ + static boolean useNativeOgl(boolean isWindowsVista, boolean nativeOglRequested) { + // Get the OpenGL vendor string. + String vendorString = NativePipeline.getSupportedOglVendor(); + + // A null vendor string means OpenGL 1.2+ support unavailable. + if (vendorString == null) { + return false; + } + + // If OGL was explicitly requested, we will use it + if (nativeOglRequested) { + return true; + } + + // Check OS type and vendor string to see whether OGL is preferred + return preferOgl(isWindowsVista, vendorString); + } + + // Returns a flag inticating whether the specified vendor prefers OpenGL. + private static boolean preferOgl(boolean isWindowsVista, String vendorString) { + // We prefer OpenGL on all Windows/XP cards + if (!isWindowsVista) { + return true; + } + + // List of vendors for which we will prefer to use D3D on Windows Vista + // This must be all lower case. + final String[] vistaD3dList = { + "microsoft", + "ati", + // TODO: add the following if Intel's OpenGL driver turns out to be buggy on Vista + // "intel", + }; + final String lcVendorString = vendorString.toLowerCase(); + + // If we are running on Windows Vista, we will check the vendor string + // against the list of vendors that prefer D3D on Vista, and return true + // *unless* the vendor is in that list. + for (int i = 0; i < vistaD3dList.length; i++) { + if (lcVendorString.startsWith(vistaD3dList[i])) { + return false; + } + } + + return true; + } + + /** * Initialize the Pipeline. Called exactly once by * MasterControl.loadLibraries() to create the singleton * Pipeline object. |