From: <ma...@us...> - 2006-07-02 21:51:28
|
Revision: 2408 Author: matzon Date: 2006-07-02 14:51:22 -0700 (Sun, 02 Jul 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2408&view=rev Log Message: ----------- preliminary applet support Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/applet/ trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java Added: trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java 2006-07-02 21:51:22 UTC (rev 2408) @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2006 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.applet; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileFilter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; + +/** + * <p> + * + * </p> + * @author Brian Matzon <br...@ma...> + * @version $Revision$ + * $Id$ + */ +public class LWJGLInstaller { + + /** + * Files to install for each supported platform + * @see org.lwjgl.LWJGLUtil#getPlatform() + */ + public static final String[][] PLATFORM_FILES = { + { "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "openal", "fmod", "IL", "ILU", "ILUT", "jinput-osx"}, + { "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "openal", "fmod", "IL", "ILU", "ILUT", "jinput-linux"}, + { "lwjgl", "lwjgl-fmod3", "lwjgl-devil", "OpenAL32", "fmod", "DevIL", "ILU", "ILUT", "jinput-dx8", "jinput-raw"} + }; + + /** Whether the installer has been called */ + public static boolean installed; + + /** Whether to hook uninstall rutine. Must be called prior to installation */ + public static boolean disableUninstall = false; + + /** Directory that was installed into */ + public static String installDirectory; + + /** Buffer used when copying files */ + private static final byte[] COPY_BUFFER = new byte[4096]; + + private LWJGLInstaller() { + /* Unused */ + } + + /** + * Create a temporary installation of LWJGL. + * This will extract the relevant native files (for the platform) into + * the users temp directory, and instruct the LWJGL subsystem to load its + * native files from there. + * The files required by the installer, are gotten from the classloader via its + * getResource command, and are assumed to in the path: /native/<win32|linux|macosx>/ + * Any call to this method will also add a shutdown hook to the uninstall of the libraries + * Note: Due to the nature of native libraries, we cannot actually uninstall the currently + * loaded files, but rather the "last" installed. This means that the most recent install of LWJGL + * will always be present in the users temp dir. + * + * @see java.lang.ClassLoader#getResource(String) + * @return true if the installation was successfull + */ + public static boolean tempInstall() throws LWJGLException { + // only need to install once + if (installed) { + return true; + } + + // libraries to validate and install + String[] libraries = PLATFORM_FILES[LWJGLUtil.getPlatform() - 1]; + + // Validate the certificates of the native files + validateCertificates(); + + // install shutdown installer hook + if(!disableUninstall) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + LWJGLInstaller.uninstall(); + } + }); + return null; + } + }); + } + + // create a temporary dir for the native files + String user_temp_dir = getPriveledgedString("java.io.tmpdir"); + String path = createTemporaryDir(user_temp_dir); + if(path == null) { + throw new LWJGLException("Failed creation of temporary directory in " + user_temp_dir); + } + + // extract natives + for (int i = 0; i < libraries.length; i++) { + String library = System.mapLibraryName(libraries[i]); + if(!extract(library, path)) { + LWJGLUtil.log("Failed extract of " + library + " to " + path); + uninstall(); + return false; + } + } + + installDirectory = path; + return installed = true; + } + + /** + * Validates the certificates of the native libraries. + * When installing native libraries, it is imperative that we also check the certficates. + * The reson for this, is that a user may inject a malicious jar to the classpath + * before the "real" LWJGL jar, containing native libraries with unwanted code. + * By forcing all the native libraries to have the same certificate as the signed + * installer, we can also be sure that the native libraries indeed are correct. + * @throws LWJGLException If we encounter a certificate mismatch + */ + private static void validateCertificates() throws LWJGLException { + /* TODO */ + } + + /** + * Extracts a file in the classpath to a specified dir + * + * @param file File to extract + * @param path Path to extract to + * @return true if the file was extracted successdully + */ + private static boolean extract(final String file, final String path) throws LWJGLException { + return (Boolean) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + // check for existing file, and get out + File out = new File(path + File.separator + file); + if (out.exists()) { + return false; + } + + // create the new file and copy it to its destination + try { + out.createNewFile(); + String in = "/native/" + LWJGLUtil.getPlatformName() + "/" + file; + OutputStream os = new BufferedOutputStream(new FileOutputStream(out)); + InputStream is = new BufferedInputStream(getClass().getResourceAsStream(in)); + + // Sanity check + // =========================================== + if (os == null) { + LWJGLUtil.log("Unable to write to outputstream at " + out.getAbsolutePath()); + return false; + } + + if (is == null) { + LWJGLUtil.log("Unable to read classpath inputstream from " + in); + return false; + } + // ------------------------------------------- + + // copy the actual file + copyFile(is, os); + } catch (IOException ioe) { + LWJGLUtil.log("Exception while extracting " + file + ": " + ioe.getMessage()); + return false; + } + return true; + } + }); + } + + /** + * Copies an inputstream to an outputstream + * @param is InputStream to read from + * @param os OutputStream to write to + * @throws IOException if the copy process fail in any way + */ + static void copyFile(InputStream is, OutputStream os) throws IOException { + int len; + while ((len = is.read(COPY_BUFFER)) > 0) { + os.write(COPY_BUFFER, 0, len); + } + is.close(); + os.close(); + } + + /** + * Creates the temporary dir to store lwjgl files in. + * The temporary dir will be created in the users temp dir and + * called 'lwjgl-' and appended System.currentTimeMillis(). A watermark file + * called '.lwjglinstaller' will also be created in the directory. + * @return Name of temp directory or null if directory creation failed + */ + static String createTemporaryDir(final String user_temp_dir) { + return (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + // create the temp directory + File tempDir = new File(user_temp_dir + File.separator + "lwjgl-" + System.currentTimeMillis()); + if(!tempDir.mkdir()) { + return null; + } + + // add the watermark file + // TODO: Write some info to the file ? + try { + File watermark = new File(tempDir.getAbsolutePath() + File.separator + ".lwjglinstaller"); + watermark.createNewFile(); + } catch (IOException ioe) { + return null; + } + return tempDir.getAbsolutePath(); + } + }); + } + + + /** + * Gets a property as a privileged action. + */ + private static String getPriveledgedString(final String property) { + return (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty(property); + } + }); + } + + /** + * Uninstalls any PREVIOUS installations + * We cannot uninstall the current installation, since the files are locked + * by the VM. + */ + private static void uninstall() { + LWJGLUtil.log("running LWJGL uninstaller"); + + // locate all installer dirs and uninstall them + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String temp = System.getProperty("java.io.tmpdir"); + File tempDir = new File(temp); + File[] files = tempDir.listFiles(new FileFilter() { + + /* + * @see java.io.FileFilter#accept(java.io.File) + */ + public boolean accept(File pathname) { + return pathname.getAbsolutePath().indexOf("lwjgl") != -1 && isInstallDirectory(pathname); + } + + /** + * Checks whether the specified directory is an install directory. + * This is done by checking for the watermark file + * @param directory Directory to check + * @return true if the directory is an install directory + */ + private boolean isInstallDirectory(File directory) { + File installFile = new File(directory.getAbsolutePath() + File.separator + ".lwjglinstaller"); + return installFile.exists(); + } + + }); + + // uninstall each of the dirs + for (int i = 0; i < files.length; i++) { + uninstall(files[i]); + } + return null; + } + }); + } + + /** + * Uninstall LWJGL from a directory. This deletes all the files in the directory + * and deletes the directory too. + * @param file directory to uninstall LWJGL from + */ + private static void uninstall(File file) { + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + files[i].delete(); + } + file.delete(); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-07-03 10:22:25
|
Revision: 2418 Author: elias_naur Date: 2006-07-03 03:21:44 -0700 (Mon, 03 Jul 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2418&view=rev Log Message: ----------- Made sure no dependency from core LWJGL to LWJGLInstaller exists Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -42,7 +42,6 @@ import java.util.List; import java.util.StringTokenizer; -import org.lwjgl.applet.LWJGLInstaller; /** * <p> @@ -280,7 +279,7 @@ * @return the current platform type */ public static int getPlatform() { - String osName = System.getProperty("os.name"); + String osName = getPrivilegedProperty("os.name"); if (osName.startsWith("Windows")) { return PLATFORM_WINDOWS; @@ -358,16 +357,13 @@ } // add Installer path - if (LWJGLInstaller.installed) { - possible_paths.add(LWJGLInstaller.installDirectory + File.separator + platform_lib_name); + String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath"); + if (alternative_path != null) { + possible_paths.add(alternative_path + File.separator + platform_lib_name); } // Add all possible paths from java.library.path - String java_library_path = (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty("java.library.path"); - } - }); + String java_library_path = getPrivilegedProperty("java.library.path"); StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator); while (st.hasMoreTokens()) { @@ -376,11 +372,7 @@ } //add current path - String current_dir = (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty("user.dir"); - } - }); + String current_dir = getPrivilegedProperty("user.dir"); possible_paths.add(current_dir + File.separator + platform_lib_name); //add pure library (no path, let OS search) @@ -393,6 +385,14 @@ return paths; } + private static String getPrivilegedProperty(final String property_name) { + return (String)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty(property_name); + } + }); + } + /** * Tries to locate named library from the current ClassLoader * This method exists because native libraries are loaded from native code, and as such @@ -460,7 +460,7 @@ * specific code and will not work for any other platform. */ public static boolean isMacOSXEqualsOrBetterThan(int major_required, int minor_required) { - String os_version = System.getProperty("os.version"); + String os_version = getPrivilegedProperty("os.version"); StringTokenizer version_tokenizer = new StringTokenizer(os_version, "."); int major; int minor; Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -39,7 +39,6 @@ import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; -import org.lwjgl.applet.LWJGLInstaller; import org.lwjgl.input.Mouse; /** @@ -58,31 +57,28 @@ /** The implementation instance to delegate platform specific behavior to */ private final static SysImplementation implementation; - /** - * utility loadlibrary to load the native library using elevated priviledges - * @param name Name of library to load, or full path if usingPath is true - * @param usingPath true if using the full path to the native - */ - private static void loadLibrary(final String name, final boolean usingPath) { + private static void loadLibrary(final String lib_name) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - if(usingPath) { - System.load(name); + String library_path = System.getProperty("org.lwjgl.librarypath"); + if (library_path != null) { + System.load(library_path + File.separator + + System.mapLibraryName(lib_name)); } else { - System.loadLibrary(name); + System.loadLibrary(lib_name); } return null; } }); - } - + } + static { implementation = createImplementation(); String[] library_names = implementation.getNativeLibraryNames(); UnsatisfiedLinkError last_load_error = null; for (int i = 0; i < library_names.length; i++) { try { - loadLibrary(library_names[i], false); + loadLibrary(library_names[i]); last_load_error = null; break; } catch (UnsatisfiedLinkError e) { @@ -90,19 +86,6 @@ } } - // failed normal loading - check installer - if (last_load_error != null && LWJGLInstaller.installed) { - for (int i = 0; i < library_names.length; i++) { - try { - loadLibrary(LWJGLInstaller.installDirectory + File.separator + System.mapLibraryName(library_names[i]), true); - last_load_error = null; - break; - } catch (UnsatisfiedLinkError e) { - last_load_error = e; - } - } - } - // check for error if (last_load_error != null) { throw last_load_error; Modified: trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -41,8 +41,8 @@ import java.io.OutputStream; import java.security.AccessController; import java.security.PrivilegedAction; +import java.security.PrivilegedExceptionAction; -import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; /** @@ -71,9 +71,6 @@ /** Whether to hook uninstall rutine. Must be called prior to installation */ public static boolean disableUninstall = false; - /** Directory that was installed into */ - public static String installDirectory; - /** Buffer used when copying files */ private static final byte[] COPY_BUFFER = new byte[4096]; @@ -94,53 +91,55 @@ * will always be present in the users temp dir. * * @see java.lang.ClassLoader#getResource(String) - * @return true if the installation was successfull */ - public static boolean tempInstall() throws LWJGLException { + public static void tempInstall() throws Exception { // only need to install once if (installed) { - return true; + return; } - - // libraries to validate and install - String[] libraries = PLATFORM_FILES[LWJGLUtil.getPlatform() - 1]; - - // Validate the certificates of the native files - validateCertificates(); - // install shutdown installer hook - if(!disableUninstall) { + try { + // libraries to validate and install + String[] libraries = PLATFORM_FILES[LWJGLUtil.getPlatform() - 1]; + + // Validate the certificates of the native files + validateCertificates(); + + // install shutdown installer hook + if(!disableUninstall) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + uninstall(); + } + }); + return null; + } + }); + } + + // create a temporary dir for the native files + String user_temp_dir = getPriviledgedString("java.io.tmpdir"); + final String path = createTemporaryDir(user_temp_dir); + + // extract natives + for (int i = 0; i < libraries.length; i++) { + String library = System.mapLibraryName(libraries[i]); + extract(library, path); + } + AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - Runtime.getRuntime().addShutdownHook(new Thread() { - public void run() { - LWJGLInstaller.uninstall(); - } - }); + System.setProperty("org.lwjgl.librarypath", path); return null; } }); + } catch (Exception e) { + LWJGLUtil.log("Failed extraction e = " + e.getMessage()); + uninstall(); + throw e; } - - // create a temporary dir for the native files - String user_temp_dir = getPriviledgedString("java.io.tmpdir"); - String path = createTemporaryDir(user_temp_dir); - if(path == null) { - throw new LWJGLException("Failed creation of temporary directory in " + user_temp_dir); - } - - // extract natives - for (int i = 0; i < libraries.length; i++) { - String library = System.mapLibraryName(libraries[i]); - if(!extract(library, path)) { - LWJGLUtil.log("Failed extract of " + library + " to " + path); - uninstall(); - return false; - } - } - - installDirectory = path; - return installed = true; } /** @@ -150,9 +149,9 @@ * before the "real" LWJGL jar, containing native libraries with unwanted code. * By forcing all the native libraries to have the same certificate as the signed * installer, we can also be sure that the native libraries indeed are correct. - * @throws LWJGLException If we encounter a certificate mismatch + * @throws Exception If we encounter a certificate mismatch */ - private static void validateCertificates() throws LWJGLException { + private static void validateCertificates() throws Exception { /* TODO */ } @@ -161,15 +160,14 @@ * * @param file File to extract * @param path Path to extract to - * @return true if the file was extracted successdully */ - private static boolean extract(final String file, final String path) throws LWJGLException { - return (Boolean) AccessController.doPrivileged(new PrivilegedAction() { + private static void extract(final String file, final String path) { + AccessController.doPrivileged(new PrivilegedAction() { public Object run() { // check for existing file, and get out File out = new File(path + File.separator + file); if (out.exists()) { - return false; + return null; } // create the new file and copy it to its destination @@ -183,12 +181,12 @@ // =========================================== if (os == null) { LWJGLUtil.log("Unable to write to outputstream at " + out.getAbsolutePath()); - return false; + return null; } if (is == null) { LWJGLUtil.log("Unable to read classpath inputstream from " + in); - return false; + return null; } // ------------------------------------------- @@ -196,9 +194,9 @@ copyFile(is, os); } catch (IOException ioe) { LWJGLUtil.log("Exception while extracting " + file + ": " + ioe.getMessage()); - return false; + return null; } - return true; + return null; } }); } @@ -225,23 +223,19 @@ * called '.lwjglinstaller' will also be created in the directory. * @return Name of temp directory or null if directory creation failed */ - static String createTemporaryDir(final String user_temp_dir) { - return (String) AccessController.doPrivileged(new PrivilegedAction() { + static String createTemporaryDir(final String user_temp_dir) throws Exception { + return (String) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() { // create the temp directory File tempDir = new File(user_temp_dir + File.separator + "lwjgl-" + System.currentTimeMillis()); if(!tempDir.mkdir()) { - return null; + throw new IOException("Failed to create directory: " + tempDir); } // add the watermark file // TODO: Write some info to the file ? - try { - File watermark = new File(tempDir.getAbsolutePath() + File.separator + ".lwjglinstaller"); - watermark.createNewFile(); - } catch (IOException ioe) { - return null; - } + File watermark = new File(tempDir.getAbsolutePath() + File.separator + ".lwjglinstaller"); + watermark.createNewFile(); return tempDir.getAbsolutePath(); } }); Modified: trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -37,7 +37,6 @@ import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; -import org.lwjgl.applet.LWJGLInstaller; /** * <p> @@ -56,30 +55,23 @@ /** Version of IL */ public static final String VERSION = "1.0beta2"; - /** - * utility loadlibrary to load the native library using elevated priviledges - * @param name Name of library to load, or full path if usingPath is true - * @param usingPath true if using the full path to the native - */ - private static void loadLibrary(final String name, final boolean usingPath) { + private static void loadLibrary(final String lib_name) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - if(usingPath) { - System.load(name); + String library_path = System.getProperty("org.lwjgl.librarypath"); + if (library_path != null) { + System.load(library_path + File.separator + + System.mapLibraryName(lib_name)); } else { - System.loadLibrary(name); + System.loadLibrary(lib_name); } return null; } }); - } - + } + static { - if (LWJGLInstaller.installed) { - loadLibrary(LWJGLInstaller.installDirectory + File.separator + System.mapLibraryName(JNI_LIBRARY_NAME), true); - } else { - loadLibrary(JNI_LIBRARY_NAME, false); - } + loadLibrary(JNI_LIBRARY_NAME); // check for mismatch String nativeVersion = getNativeLibraryVersion(); Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -41,7 +41,6 @@ import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; -import org.lwjgl.applet.LWJGLInstaller; /** * <br> @@ -209,11 +208,7 @@ } initialized = true; - if (LWJGLInstaller.installed) { - loadLibrary(LWJGLInstaller.installDirectory + File.separator + System.mapLibraryName(JNI_LIBRARY_NAME), true); - } else { - loadLibrary(JNI_LIBRARY_NAME, false); - } + loadLibrary(JNI_LIBRARY_NAME); // check for mismatch String nativeVersion = getNativeLibraryVersion(); @@ -229,13 +224,15 @@ } } - private static void loadLibrary(final String name, final boolean usingPath) { + private static void loadLibrary(final String lib_name) { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - if(usingPath) { - System.load(name); + String library_path = System.getProperty("org.lwjgl.librarypath"); + if (library_path != null) { + System.load(library_path + File.separator + + System.mapLibraryName(lib_name)); } else { - System.loadLibrary(name); + System.loadLibrary(lib_name); } return null; } Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java 2006-07-02 22:45:56 UTC (rev 2417) +++ trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java 2006-07-03 10:21:44 UTC (rev 2418) @@ -44,19 +44,16 @@ Test test = null; - @Override public void destroy() { super.destroy(); System.out.println("*** destroy ***"); } - @Override public void start() { super.start(); System.out.println("*** start ***"); } - @Override public void stop() { super.stop(); System.out.println("*** stop ***"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-07-03 10:28:47
|
Revision: 2419 Author: elias_naur Date: 2006-07-03 03:28:32 -0700 (Mon, 03 Jul 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2419&view=rev Log Message: ----------- Removed multiple library names support from Sys.java, it is not needed anymore Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/DefaultSysImplementation.java trunk/LWJGL/src/java/org/lwjgl/MacOSXSysImplementation.java trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/SysImplementation.java trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/DefaultSysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/DefaultSysImplementation.java 2006-07-03 10:21:44 UTC (rev 2418) +++ trunk/LWJGL/src/java/org/lwjgl/DefaultSysImplementation.java 2006-07-03 10:28:32 UTC (rev 2419) @@ -39,13 +39,6 @@ * $Id$ */ abstract class DefaultSysImplementation implements SysImplementation { - /** The native library name */ - protected static final String LIBRARY_NAME = "lwjgl"; - - public String[] getNativeLibraryNames() { - return new String[]{LIBRARY_NAME}; - } - public native String getNativeLibraryVersion(); public native void setDebug(boolean debug); Modified: trunk/LWJGL/src/java/org/lwjgl/MacOSXSysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/MacOSXSysImplementation.java 2006-07-03 10:21:44 UTC (rev 2418) +++ trunk/LWJGL/src/java/org/lwjgl/MacOSXSysImplementation.java 2006-07-03 10:28:32 UTC (rev 2419) @@ -42,37 +42,6 @@ * $Id$ */ class MacOSXSysImplementation extends J2SESysImplementation { - public String[] getNativeLibraryNames() { - /* If we're on 10.4, fine, we'll just try the default library name. For - * earlier versions of Mac OS X, try the legacy library first. - * - * Having a kludge like this is unfortunate, but necessary for the following reasons: - * 1. We need two libraries to support Mac OS X 10.2, 10.3 and 10.4. We could - * cover 10.2, 10.3 and 10.4 with one gcc 3 compiled library, but then we - * loose intel mac support. Instead, we'll distribute two versions of the lwjgl - * native library, the default and a legacy one. - * 2. The default library will be universal ('fat') with both intel and powerpc support - * compiled in. This requires gcc 4, and makes the library unusable on Mac OS X 10.3 - * and earlier (actually 10.3.9 has the required gcc 4 libraries, but we'll ignore that). - * We could still choose to load the default library first, and the legacy one later, - * but a bug in the Mac OS X java implementation forces a java program to exit - * if the loaded library has a missing dependency (The correct behaviour is to throw - * an UnsatisfiedLinkError, like on linux and windows). - * 3. If the LWJGL program is launched with an intelligent ClassLoader, this issue can be avoided - * altogether, and the legacy library naming can be avoided too. For example, when - * using webstart, one can supply two nativelib references, one for Mac OS X 10.4 - * (the default library), and one for earlier Mac OS X (the legacy library). This is the - * preferred way to deploy the libraries. The legacy naming is for the users that don't want to - * mess around with libraries and classloaders. They can simply make sure that lwjgl.jar - * is in the classpath and that both the default library and the legacy library is in the native - * library path (java.library.path). - */ - if (LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 4)) - return super.getNativeLibraryNames(); - else - return new String[]{LIBRARY_NAME + "-legacy", LIBRARY_NAME}; - } - public boolean openURL(String url) { try { Method openURL_method = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() { Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-07-03 10:21:44 UTC (rev 2418) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-07-03 10:28:32 UTC (rev 2419) @@ -50,8 +50,10 @@ * $Id$ */ public final class Sys { + /** The native library name */ + private static final String JNI_LIBRARY_NAME = "lwjgl"; - /** Current version of library */ + /** Current version of library */ private static final String VERSION = "1.0beta2"; /** The implementation instance to delegate platform specific behavior to */ @@ -74,23 +76,8 @@ static { implementation = createImplementation(); - String[] library_names = implementation.getNativeLibraryNames(); - UnsatisfiedLinkError last_load_error = null; - for (int i = 0; i < library_names.length; i++) { - try { - loadLibrary(library_names[i]); - last_load_error = null; - break; - } catch (UnsatisfiedLinkError e) { - last_load_error = e; - } - } + loadLibrary(JNI_LIBRARY_NAME); - // check for error - if (last_load_error != null) { - throw last_load_error; - } - String native_version = implementation.getNativeLibraryVersion(); if (!native_version.equals(getVersion())) throw new LinkageError("Version mismatch: jar version is '" + getVersion() + Modified: trunk/LWJGL/src/java/org/lwjgl/SysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/SysImplementation.java 2006-07-03 10:21:44 UTC (rev 2418) +++ trunk/LWJGL/src/java/org/lwjgl/SysImplementation.java 2006-07-03 10:28:32 UTC (rev 2419) @@ -42,12 +42,6 @@ */ interface SysImplementation { /** - * Return an array of possible library names. later names - * tried last. - */ - public String[] getNativeLibraryNames(); - - /** * Return the version of the native library */ public String getNativeLibraryVersion(); Modified: trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java 2006-07-03 10:21:44 UTC (rev 2418) +++ trunk/LWJGL/src/java/org/lwjgl/applet/LWJGLInstaller.java 2006-07-03 10:28:32 UTC (rev 2419) @@ -225,7 +225,7 @@ */ static String createTemporaryDir(final String user_temp_dir) throws Exception { return (String) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() { + public Object run() throws Exception { // create the temp directory File tempDir = new File(user_temp_dir + File.separator + "lwjgl-" + System.currentTimeMillis()); if(!tempDir.mkdir()) { Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java 2006-07-03 10:21:44 UTC (rev 2418) +++ trunk/LWJGL/src/java/org/lwjgl/test/applet/AppletTest.java 2006-07-03 10:28:32 UTC (rev 2419) @@ -65,7 +65,7 @@ try { LWJGLInstaller.tempInstall(); - } catch (LWJGLException le) { + } catch (Exception le) { /* screwed */ le.printStackTrace(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-10-08 09:05:29
|
Revision: 2580 http://svn.sourceforge.net/java-game-lib/?rev=2580&view=rev Author: elias_naur Date: 2006-10-08 02:05:16 -0700 (Sun, 08 Oct 2006) Log Message: ----------- Made Display.getImplementation package private, and made the input.* packages access it through reflection. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/input/Cursor.java trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/input/Cursor.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Cursor.java 2006-09-28 21:53:18 UTC (rev 2579) +++ trunk/LWJGL/src/java/org/lwjgl/input/Cursor.java 2006-10-08 09:05:16 UTC (rev 2580) @@ -38,7 +38,7 @@ import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; import org.lwjgl.Sys; -import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.DisplayImplementation; /** * @@ -115,7 +115,7 @@ * @return the maximum size of a native cursor */ public static int getMinCursorSize() { - return Display.getImplementation().getMinCursorSize(); + return Mouse.getImplementation().getMinCursorSize(); } /** @@ -126,7 +126,7 @@ * @return the maximum size of a native cursor */ public static int getMaxCursorSize() { - return Display.getImplementation().getMaxCursorSize(); + return Mouse.getImplementation().getMaxCursorSize(); } /** @@ -138,7 +138,7 @@ * @return A bit mask with native cursor capabilities. */ public static int getCapabilities() { - return Display.getImplementation().getNativeCursorCapabilities(); + return Mouse.getImplementation().getNativeCursorCapabilities(); } /** @@ -164,7 +164,7 @@ // create our cursor elements cursors = new CursorElement[numImages]; for(int i=0; i<numImages; i++) { - Object handle = Display.getImplementation().createCursor(width, height, xHotspot, yHotspot, 1, images_copy, null); + Object handle = Mouse.getImplementation().createCursor(width, height, xHotspot, yHotspot, 1, images_copy, null); long delay = (delays != null) ? delays.get(i) : 0; long timeout = System.currentTimeMillis(); cursors[i] = new CursorElement(handle, delay, timeout); @@ -175,7 +175,7 @@ break; case LWJGLUtil.PLATFORM_LINUX: // create our cursor elements - Object handle = Display.getImplementation().createCursor(width, height, xHotspot, yHotspot, numImages, images_copy, delays); + Object handle = Mouse.getImplementation().createCursor(width, height, xHotspot, yHotspot, numImages, images_copy, delays); CursorElement cursor_element = new CursorElement(handle, -1, -1); cursors = new CursorElement[]{cursor_element}; break; @@ -251,7 +251,7 @@ } } for(int i=0; i<cursors.length; i++) { - Display.getImplementation().destroyCursor(cursors[i].cursorHandle); + Mouse.getImplementation().destroyCursor(cursors[i].cursorHandle); } destroyed = true; } Modified: trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-09-28 21:53:18 UTC (rev 2579) +++ trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-10-08 09:05:16 UTC (rev 2580) @@ -42,6 +42,7 @@ import org.lwjgl.LWJGLException; import org.lwjgl.Sys; import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.DisplayImplementation; /** * <br> @@ -263,6 +264,8 @@ /** One time initialization */ private static boolean initialized; + private static DisplayImplementation implementation; + /** * Keyboard cannot be constructed. */ @@ -292,7 +295,8 @@ initialize(); if (created) return; - Display.getImplementation().createKeyboard(); + implementation = Mouse.getImplementation(); + implementation.createKeyboard(); created = true; readBuffer = ByteBuffer.allocate(EVENT_SIZE*BUFFER_SIZE); reset(); @@ -321,7 +325,7 @@ if (!created) return; created = false; - Display.getImplementation().destroyKeyboard(); + implementation.destroyKeyboard(); reset(); } @@ -346,13 +350,13 @@ public static void poll() { if (!created) throw new IllegalStateException("Keyboard must be created before you can poll the device"); - Display.getImplementation().pollKeyboard(keyDownBuffer); + implementation.pollKeyboard(keyDownBuffer); read(); } private static void read() { readBuffer.compact(); - Display.getImplementation().readKeyboard(readBuffer); + implementation.readKeyboard(readBuffer); readBuffer.flip(); } @@ -376,7 +380,7 @@ /* public static int isStateKeySet(int key) { if (!created) throw new IllegalStateException("Keyboard must be created before you can query key state"); - return Display.getImplementation().isStateKeySet(key); + return implementation.isStateKeySet(key); } */ /** Modified: trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-09-28 21:53:18 UTC (rev 2579) +++ trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-10-08 09:05:16 UTC (rev 2580) @@ -40,8 +40,15 @@ import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; import org.lwjgl.Sys; +import org.lwjgl.opengl.DisplayImplementation; import org.lwjgl.opengl.Display; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; + + /** * <br> * A raw Mouse interface. This can be used to poll the current state of the @@ -126,6 +133,8 @@ private static final int BUFFER_SIZE = 50; private static boolean isGrabbed; + + private static DisplayImplementation implementation; /** Whether we're running windows - which need to manually update cursor animation */ private static final boolean isWindows = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS; @@ -163,10 +172,10 @@ currentCursor = cursor; if (isCreated()) { if (currentCursor != null) { - Display.getImplementation().setNativeCursor(currentCursor.getHandle()); + implementation.setNativeCursor(currentCursor.getHandle()); currentCursor.setTimeout(); } else { - Display.getImplementation().setNativeCursor(null); + implementation.setNativeCursor(null); } } return oldCursor; @@ -187,7 +196,7 @@ x = event_x = new_x; y = event_y = new_y; if (!isGrabbed() && (Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0) - Display.getImplementation().setCursorPosition(x, y); + implementation.setCursorPosition(x, y); } /** @@ -211,6 +220,23 @@ readBuffer.position(readBuffer.limit()); } + static DisplayImplementation getImplementation() { + /* Use reflection since we can't make Display.getImplementation + * public + */ + try { + return (DisplayImplementation)AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception{ + Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation", null); + getImplementation_method.setAccessible(true); + return getImplementation_method.invoke(null, null); + } + }); + } catch (PrivilegedActionException e) { + throw new Error(e); + } + } + /** * "Create" the mouse. The display must first have been created. * Initially, the mouse is not grabbed and the delta values are reported @@ -224,12 +250,13 @@ if (!initialized) initialize(); if (created) return; - Display.getImplementation().createMouse(); - hasWheel = Display.getImplementation().hasWheel(); + implementation = getImplementation(); + implementation.createMouse(); + hasWheel = implementation.hasWheel(); created = true; // set mouse buttons - buttonCount = Display.getImplementation().getButtonCount(); + buttonCount = implementation.getButtonCount(); buttons = BufferUtils.createByteBuffer(buttonCount); coord_buffer = BufferUtils.createIntBuffer(3); if (currentCursor != null) @@ -255,7 +282,7 @@ buttons = null; coord_buffer = null; - Display.getImplementation().destroyMouse(); + implementation.destroyMouse(); } /** @@ -281,7 +308,7 @@ */ public static void poll() { if (!created) throw new IllegalStateException("Mouse must be created before you can poll it"); - Display.getImplementation().pollMouse(coord_buffer, buttons); + implementation.pollMouse(coord_buffer, buttons); /* If we're grabbed, poll returns mouse deltas, if not it returns absolute coordinates */ int poll_coord1 = coord_buffer.get(0); @@ -308,7 +335,7 @@ private static void read() { readBuffer.compact(); - Display.getImplementation().readMouse(readBuffer); + implementation.readMouse(readBuffer); readBuffer.flip(); } @@ -527,7 +554,7 @@ public static void setGrabbed(boolean grab) { isGrabbed = grab; if (isCreated()) { - Display.getImplementation().grabMouse(isGrabbed); + implementation.grabMouse(isGrabbed); resetMouse(); } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2006-09-28 21:53:18 UTC (rev 2579) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2006-10-08 09:05:16 UTC (rev 2580) @@ -718,7 +718,7 @@ GL11.glViewport(0, 0, current_mode.getWidth(), current_mode.getHeight()); } - public static DisplayImplementation getImplementation() { + static DisplayImplementation getImplementation() { return display_impl; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-10-20 10:42:56
|
Revision: 2584 http://svn.sourceforge.net/java-game-lib/?rev=2584&view=rev Author: elias_naur Date: 2006-10-20 03:42:43 -0700 (Fri, 20 Oct 2006) Log Message: ----------- Don't repaint() from a separate thread in AWT demos. This results in a smoother rendering. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTGears.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java 2006-10-11 20:26:35 UTC (rev 2583) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java 2006-10-20 10:42:43 UTC (rev 2584) @@ -51,12 +51,12 @@ } protected void doLockAndInitHandle() throws LWJGLException { - int screen = -1; - try { + int screen = 0;//-1; +/* try { screen = LinuxCanvasImplementation.getScreenFromDevice(canvas.getGraphicsConfiguration().getDevice()); } catch (LWJGLException e) { LWJGLUtil.log("Got exception while trying to determine screen: " + e); - } + }*/ nInitHandle(screen, awt_surface.lockAndGetHandle(canvas), getHandle()); } private static native void nInitHandle(int screen, ByteBuffer surface_buffer, ByteBuffer peer_info_handle) throws LWJGLException; Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTGears.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTGears.java 2006-10-11 20:26:35 UTC (rev 2583) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTGears.java 2006-10-20 10:42:43 UTC (rev 2584) @@ -116,6 +116,7 @@ GL11.glPopMatrix(); swapBuffers(); + repaint(); } catch (LWJGLException e) { throw new RuntimeException(e); } @@ -139,17 +140,6 @@ }); setResizable(true); setVisible(true); - - new Thread() { - { - setDaemon(true); - } - public void run() { - for (;;) { - canvas0.repaint(); - } - } - }.start(); } private void setup() { Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTTest.java 2006-10-11 20:26:35 UTC (rev 2583) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTTest.java 2006-10-20 10:42:43 UTC (rev 2584) @@ -53,7 +53,7 @@ /** AWT GL canvas */ private AWTGLCanvas canvas0, canvas1; - private float angle; + private volatile float angle; /** * C'tor @@ -80,6 +80,7 @@ GL11.glRectf(-50.0f, -50.0f, 50.0f, 50.0f); GL11.glPopMatrix(); swapBuffers(); + repaint(); } catch (LWJGLException e) { throw new RuntimeException(e); } @@ -89,6 +90,7 @@ add(canvas1 = new AWTGLCanvas() { public void paintGL() { try { + angle += 1.0f; makeCurrent(); GL11.glViewport(0, 0, getWidth(), getHeight()); GL11.glClearColor(0.0f, 1.0f, 0.0f, 1.0f); @@ -103,6 +105,7 @@ GL11.glRectf(-50.0f, -50.0f, 50.0f, 50.0f); GL11.glPopMatrix(); swapBuffers(); + repaint(); } catch (LWJGLException e) { throw new RuntimeException(e); } @@ -117,24 +120,6 @@ }); setResizable(true); setVisible(true); - - new Thread() { - { - setDaemon(true); - } - public void run() { - for (;;) { - angle += 1.0f; - canvas0.repaint(); - canvas1.repaint(); - try { - sleep(20); - } catch (InterruptedException e) { - break; - } - } - } - }.start(); } public static void main(String[] args) throws LWJGLException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-11-10 13:52:27
|
Revision: 2639 http://svn.sourceforge.net/java-game-lib/?rev=2639&view=rev Author: elias_naur Date: 2006-11-10 05:52:18 -0800 (Fri, 10 Nov 2006) Log Message: ----------- Remove AWTInputAdapter.update() and let users poll() Mouse and Keyboard directly Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTCanvasInputImplementation.java trunk/LWJGL/src/java/org/lwjgl/opengl/AWTInputAdapter.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTInput.java trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXAWTInput.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTInputAdapterTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AWTCanvasInputImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTCanvasInputImplementation.java 2006-11-10 11:44:00 UTC (rev 2638) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/AWTCanvasInputImplementation.java 2006-11-10 13:52:18 UTC (rev 2639) @@ -41,7 +41,6 @@ */ interface AWTCanvasInputImplementation extends InputImplementation { void processInput(PeerInfo peer_info); - void update(); void init(); void destroy(); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AWTInputAdapter.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTInputAdapter.java 2006-11-10 11:44:00 UTC (rev 2638) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/AWTInputAdapter.java 2006-11-10 13:52:18 UTC (rev 2639) @@ -94,11 +94,4 @@ awt_input = null; } } - - public static synchronized void update() { - if (awt_input == null) - throw new IllegalStateException("You need to create() the adapter."); - awt_input.update(); - Display.pollDevices(); - } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTInput.java 2006-11-10 11:44:00 UTC (rev 2638) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTInput.java 2006-11-10 13:52:18 UTC (rev 2639) @@ -132,6 +132,7 @@ checkFocus(); if (!input_grabbed && shouldGrab()) grabInput(new_window); + update(); } finally { LinuxDisplay.unlockAWT(); } @@ -150,20 +151,15 @@ return !input_released && isGrabbed(); } - public synchronized void update() { - LinuxDisplay.lockAWT(); - try { - while (LinuxEvent.getPending(display) > 0) { - event.nextEvent(display); - if (shouldGrab()) { - long event_window = event.getWindow(); - boolean processed = event.filterEvent(event_window) || - cached_mouse.filterEvent(isGrabbed(), shouldGrab(), event)/* || - cached_keyboard.filterEvent(event)*/; - } + private void update() { + while (LinuxEvent.getPending(display) > 0) { + event.nextEvent(display); + if (shouldGrab()) { + long event_window = event.getWindow(); + boolean processed = event.filterEvent(event_window) || + cached_mouse.filterEvent(isGrabbed(), shouldGrab(), event);/* || + cached_keyboard.filterEvent(event) */ } - } finally { - LinuxDisplay.unlockAWT(); } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXAWTInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXAWTInput.java 2006-11-10 11:44:00 UTC (rev 2638) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXAWTInput.java 2006-11-10 13:52:18 UTC (rev 2639) @@ -63,7 +63,4 @@ public void destroy() { } - - public void update() { - } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java 2006-11-10 11:44:00 UTC (rev 2638) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java 2006-11-10 13:52:18 UTC (rev 2639) @@ -129,9 +129,6 @@ } } - public void update() { - } - public synchronized void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons) { if (isGrabbed()) { if (cached_mouse != null) Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTInputAdapterTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTInputAdapterTest.java 2006-11-10 11:44:00 UTC (rev 2638) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTInputAdapterTest.java 2006-11-10 13:52:18 UTC (rev 2639) @@ -140,11 +140,12 @@ + (fps / (timeUsed / 1000f))); fps = 0; } - AWTInputAdapter.update(); + Mouse.poll(); while (Mouse.next()) { view_roty += Mouse.getEventDX()*.1; view_rotx -= Mouse.getEventDY()*.1; } + Keyboard.poll(); while (Keyboard.next()) { if (Keyboard.getEventKeyState()) { switch (Keyboard.getEventKey()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kev...@us...> - 2006-11-17 08:08:22
|
Revision: 2648 http://svn.sourceforge.net/java-game-lib/?rev=2648&view=rev Author: kevglass Date: 2006-11-17 00:08:21 -0800 (Fri, 17 Nov 2006) Log Message: ----------- Updated Controllers event queue to make use of the new JInput event queue, including adding getEventNanoseconds() to the Controllers interface. TestControllers against Logitech pad on Win32 confirms that no behaviour changes are evident. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/input/ControllerEvent.java trunk/LWJGL/src/java/org/lwjgl/input/Controllers.java trunk/LWJGL/src/java/org/lwjgl/input/JInputController.java trunk/LWJGL/src/java/org/lwjgl/test/input/TestControllers.java Modified: trunk/LWJGL/src/java/org/lwjgl/input/ControllerEvent.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/ControllerEvent.java 2006-11-17 07:17:12 UTC (rev 2647) +++ trunk/LWJGL/src/java/org/lwjgl/input/ControllerEvent.java 2006-11-17 08:08:21 UTC (rev 2648) @@ -25,18 +25,22 @@ private boolean xaxis; /** True if this event was caused by the y axis */ private boolean yaxis; + /** The time stamp of this event */ + private long timeStamp; /** * Create a new event * * @param source The source of the event + * @param timeStamp The time stamp given for this event * @param type The type of control generating this event * @param index The index of the input that generated the event * @param xaxis True if this event was caused by the x-axis * @param yaxis True if this event was caused by the y-axis */ - public ControllerEvent(Controller source,int type,int index,boolean xaxis,boolean yaxis) { + public ControllerEvent(Controller source,long timeStamp, int type,int index,boolean xaxis,boolean yaxis) { this.source = source; + this.timeStamp = timeStamp; this.type = type; this.index = index; this.xaxis = xaxis; @@ -44,6 +48,16 @@ } /** + * Get the time stamp given for this event. As with nanoTime() + * this value means nothing other than giving ordering + * + * @return The time stamp given for this event + */ + public long getTimeStamp() { + return timeStamp; + } + + /** * Get the controller that generated this event * * @return The controller that generated this event Modified: trunk/LWJGL/src/java/org/lwjgl/input/Controllers.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Controllers.java 2006-11-17 07:17:12 UTC (rev 2647) +++ trunk/LWJGL/src/java/org/lwjgl/input/Controllers.java 2006-11-17 08:08:21 UTC (rev 2648) @@ -235,6 +235,15 @@ } /** + * Get the timestamp assigned to the current event + * + * @return The timestamp assigned ot the current event + */ + public static long getEventNanoseconds() { + return event.getTimeStamp(); + } + + /** * Add an event to the stack of events that have been caused * * @param event The event to add to the list Modified: trunk/LWJGL/src/java/org/lwjgl/input/JInputController.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/JInputController.java 2006-11-17 07:17:12 UTC (rev 2647) +++ trunk/LWJGL/src/java/org/lwjgl/input/JInputController.java 2006-11-17 08:08:21 UTC (rev 2648) @@ -3,6 +3,8 @@ import java.util.ArrayList; import net.java.games.input.Component; +import net.java.games.input.Event; +import net.java.games.input.EventQueue; /** * A wrapper round a JInput controller that attempts to make the interface @@ -159,68 +161,60 @@ public void poll() { target.poll(); - // read buttons to update events - for (int i=0;i<getButtonCount();i++) { - Component button = (Component) buttons.get(i); - - float data = button.getPollData(); + Event event = new Event(); + EventQueue queue = target.getEventQueue(); + + while (queue.getNextEvent(event)) { + // handle button event + if (buttons.contains(event.getComponent())) { + Component button = event.getComponent(); + int buttonIndex = buttons.indexOf(button); + buttonState[buttonIndex] = event.getValue() != 0; - if (buttonState[i] != (data != 0)) { // fire button pressed event - Controllers.addEvent(new ControllerEvent(this,ControllerEvent.BUTTON,i,false,false)); + Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.BUTTON,buttonIndex,false,false)); } - buttonState[i] = data != 0; - } - - // read povs to update events - for (int i=0;i<pov.size();i++) { - Component p = (Component) pov.get(i); - - float data = p.getPollData(); - - if (povValues[i] != data) { + // handle pov events + if (pov.contains(event.getComponent())) { + Component povComponent = event.getComponent(); + int povIndex = pov.indexOf(povComponent); float prevX = getPovX(); float prevY = getPovY(); - - povValues[i] = data; - + povValues[povIndex] = event.getValue(); + if (prevX != getPovX()) { - Controllers.addEvent(new ControllerEvent(this,ControllerEvent.POVX,0,false,false)); + Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.POVX,0,false,false)); } if (prevY != getPovY()) { - Controllers.addEvent(new ControllerEvent(this,ControllerEvent.POVY,0,false,false)); + Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.POVY,0,false,false)); } } - povValues[i] = data; - } - - // read axis to update events - for (int i=0;i<getAxisCount();i++) { - Component axis = (Component) axes.get(i); - - float value = axis.getPollData(); - - // fixed dead zone since most axis don't report it :( - if (Math.abs(value) < deadZones[i]) { - value = 0; - } - if (Math.abs(value) < axis.getDeadZone()) { - value = 0; - } - if (Math.abs(value) > axesMax[i]) { - axesMax[i] = Math.abs(value); - } - - // normalize the value based on maximum value read in the past - value /= axesMax[i]; - - if (axesValue[i] != value) { + // handle axis updates + if (axes.contains(event.getComponent())) { + Component axis = event.getComponent(); + int axisIndex = axes.indexOf(axis); + float value = axis.getPollData(); + + // fixed dead zone since most axis don't report it :( + if (Math.abs(value) < deadZones[axisIndex]) { + value = 0; + } + if (Math.abs(value) < axis.getDeadZone()) { + value = 0; + } + if (Math.abs(value) > axesMax[axisIndex]) { + axesMax[axisIndex] = Math.abs(value); + } + + // normalize the value based on maximum value read in the past + value /= axesMax[axisIndex]; // fire event - Controllers.addEvent(new ControllerEvent(this,ControllerEvent.AXIS,i,i == xaxis,i == yaxis)); + Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.AXIS,axisIndex, + axisIndex == xaxis,axisIndex == yaxis)); + axesValue[axisIndex] = value; } - axesValue[i] = value; } } Modified: trunk/LWJGL/src/java/org/lwjgl/test/input/TestControllers.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/input/TestControllers.java 2006-11-17 07:17:12 UTC (rev 2647) +++ trunk/LWJGL/src/java/org/lwjgl/test/input/TestControllers.java 2006-11-17 08:08:21 UTC (rev 2648) @@ -142,6 +142,7 @@ while (Controllers.next()) { System.out.println("Event Fired: "); + System.out.println("\t"+Controllers.getEventNanoseconds()); System.out.println("\t"+Controllers.getEventSource()+":"+Controllers.getEventControlIndex()+":"+Controllers.isEventButton()); System.out.println("\t"+Controllers.isEventXAxis()+":"+Controllers.isEventYAxis()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-11-19 16:24:21
|
Revision: 2663 http://svn.sourceforge.net/java-game-lib/?rev=2663&view=rev Author: elias_naur Date: 2006-11-19 08:24:18 -0800 (Sun, 19 Nov 2006) Log Message: ----------- AWTInputAdapter.destroy() now destroys the Keyboard and Mouse to mimic the behaviour of Display.destroy() more closely. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTInputAdapter.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTInputAdapterTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AWTInputAdapter.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTInputAdapter.java 2006-11-19 13:33:45 UTC (rev 2662) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/AWTInputAdapter.java 2006-11-19 16:24:18 UTC (rev 2663) @@ -92,6 +92,8 @@ if (awt_input != null) { awt_input.destroy(); awt_input = null; + Mouse.destroy(); + Keyboard.destroy(); } } } Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTInputAdapterTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTInputAdapterTest.java 2006-11-19 13:33:45 UTC (rev 2662) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/AWTInputAdapterTest.java 2006-11-19 16:24:18 UTC (rev 2663) @@ -140,18 +140,25 @@ + (fps / (timeUsed / 1000f))); fps = 0; } - Mouse.poll(); - while (Mouse.next()) { - view_roty += Mouse.getEventDX()*.1; - view_rotx -= Mouse.getEventDY()*.1; + if (Mouse.isCreated()) { + Mouse.poll(); + while (Mouse.next()) { + view_roty += Mouse.getEventDX()*.1; + view_rotx -= Mouse.getEventDY()*.1; + } } - Keyboard.poll(); - while (Keyboard.next()) { + if (Keyboard.isCreated()) { + Keyboard.poll(); + } + while (Keyboard.isCreated() && Keyboard.next()) { if (Keyboard.getEventKeyState()) { switch (Keyboard.getEventKey()) { case Keyboard.KEY_ESCAPE: System.exit(0); break; + case Keyboard.KEY_H: + AWTInputAdapter.destroy(); + break; case Keyboard.KEY_G: Mouse.setGrabbed(!Mouse.isGrabbed()); break; @@ -162,14 +169,16 @@ if (Keyboard.getEventCharacter() != Keyboard.CHAR_NONE) System.out.println("Typed: " + Keyboard.getEventCharacter()); } - if (Keyboard.isKeyDown(Keyboard.KEY_UP)) - view_rotx -= .1; - else if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) - view_rotx += .1; - if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) - view_roty -= .1; - else if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) - view_roty += .1; + if (Keyboard.isCreated()) { + if (Keyboard.isKeyDown(Keyboard.KEY_UP)) + view_rotx -= .1; + else if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) + view_rotx += .1; + if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) + view_roty -= .1; + else if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) + view_roty += .1; + } } }); addWindowListener(new WindowAdapter() { @@ -225,7 +234,7 @@ GL11.glMatrixMode(GL11.GL_PROJECTION); - System.err.println("Use the arrow keys and the mouse to rotate the gears. Press 'G' to toggle mouse grabbing."); + System.err.println("Use the arrow keys and the mouse to rotate the gears. Press 'G' to toggle mouse grabbing. Press 'H' to destroy the AWTInputAdapter."); System.err.println("GL_VENDOR: " + GL11.glGetString(GL11.GL_VENDOR)); System.err.println("GL_RENDERER: " + GL11.glGetString(GL11.GL_RENDERER)); System.err.println("GL_VERSION: " + GL11.glGetString(GL11.GL_VERSION)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-11-19 21:41:37
|
Revision: 2665 http://svn.sourceforge.net/java-game-lib/?rev=2665&view=rev Author: elias_naur Date: 2006-11-19 13:41:34 -0800 (Sun, 19 Nov 2006) Log Message: ----------- Make sure that Mouse.destroy ungrabs the cursor Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java trunk/LWJGL/src/java/org/lwjgl/opengl/AbstractAWTInput.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTInput.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXAWTInput.java trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java Modified: trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-11-19 21:15:51 UTC (rev 2664) +++ trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-11-19 21:41:34 UTC (rev 2665) @@ -296,7 +296,7 @@ created = false; buttons = null; coord_buffer = null; - + implementation.destroyMouse(); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AbstractAWTInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/AbstractAWTInput.java 2006-11-19 21:15:51 UTC (rev 2664) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/AbstractAWTInput.java 2006-11-19 21:41:34 UTC (rev 2665) @@ -84,10 +84,6 @@ public synchronized void destroy() { canvas.setInput(null); canvas = null; - if (mouse_queue != null) - mouse_queue.unregister(); - if (keyboard_queue != null) - keyboard_queue.unregister(); } public final int getWidth() { @@ -115,8 +111,11 @@ return new MouseEventQueue(getCanvas()); } - public void destroyMouse() { - mouse_queue.unregister(); + public synchronized void destroyMouse() { + if (mouse_queue != null) { + mouse_queue.unregister(); + mouse_queue = null; + } } public int getNativeCursorCapabilities() { @@ -145,8 +144,10 @@ } public synchronized void destroyKeyboard() { - if (keyboard_queue != null) + if (keyboard_queue != null) { keyboard_queue.unregister(); + keyboard_queue = null; + } } public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTInput.java 2006-11-19 21:15:51 UTC (rev 2664) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxAWTInput.java 2006-11-19 21:41:34 UTC (rev 2665) @@ -137,6 +137,11 @@ LinuxDisplay.unlockAWT(); } } + + public void destroyMouse() { + ungrabInputLocked(); + super.destroyMouse(); + } private void checkFocus() { if (getCanvas().isFocusOwner()) { @@ -148,7 +153,7 @@ } private boolean shouldGrab() { - return !input_released && isGrabbed(); + return !input_released && isGrabbed() && getMouseEventQueue() != null; } private void update() { Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-11-19 21:15:51 UTC (rev 2664) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-11-19 21:41:34 UTC (rev 2665) @@ -348,7 +348,7 @@ } private boolean shouldGrab() { - return !input_released && grab; + return !input_released && grab && mouse != null; } private void updatePointerGrab() { @@ -715,6 +715,7 @@ public void destroyMouse() { mouse = null; + updateInputGrab(); } public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons) { Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java 2006-11-19 21:15:51 UTC (rev 2664) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java 2006-11-19 21:41:34 UTC (rev 2665) @@ -194,7 +194,7 @@ private static native void nWarpCursor(long display, long window, int x, int y); private void handlePointerMotion(boolean grab, boolean warp_pointer, long millis, long root_window, int x_root, int y_root, int x, int y) { - doHandlePointerMotion(grab, warp_pointer, root_window, x_root, y_root, x, y, millis*1000000); + doHandlePointerMotion(grab, warp_pointer, root_window, x_root, y_root, x, y, millis*1000000); } private void handleButton(boolean grab, int button, byte state, long nanos) { @@ -256,7 +256,7 @@ } } - private void resetCursor(int x, int y) { + private void resetCursor(int x, int y) { last_x = x; last_y = transformY(y); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXAWTInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXAWTInput.java 2006-11-19 21:15:51 UTC (rev 2664) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXAWTInput.java 2006-11-19 21:41:34 UTC (rev 2665) @@ -60,4 +60,10 @@ ((MacOSXMouseEventQueue)getMouseEventQueue()).warpCursor(); had_focus = has_focus; } + + public synchronized void destroyMouse() { + if (getMouseEventQueue() != null) + getMouseEventQueue().setGrabbed(false); + super.destroyMouse(); + } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-11-19 21:15:51 UTC (rev 2664) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-11-19 21:41:34 UTC (rev 2665) @@ -299,8 +299,10 @@ } public void destroyMouse() { - if (mouse_queue != null) + if (mouse_queue != null) { + mouse_queue.setGrabbed(false); mouse_queue.unregister(); + } this.mouse_queue = null; } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java 2006-11-19 21:15:51 UTC (rev 2664) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java 2006-11-19 21:41:34 UTC (rev 2665) @@ -64,12 +64,12 @@ blank_cursor = AWTUtil.createCursor(w, h, 0, 0, 1, BufferUtils.createIntBuffer(w*h), null); } - public synchronized void destroy() { - super.destroy(); + public synchronized void destroyMouse() { if (cached_mouse != null) { grab(false); cached_mouse.destroy(); } + super.destroyMouse(); } public synchronized void processInput(PeerInfo peer_info) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-11-20 19:28:54
|
Revision: 2674 http://svn.sourceforge.net/java-game-lib/?rev=2674&view=rev Author: elias_naur Date: 2006-11-20 11:28:50 -0800 (Mon, 20 Nov 2006) Log Message: ----------- Made LWJGLUtil.getPathFromClassLoader private Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java trunk/LWJGL/src/java/org/lwjgl/openal/AL.java Modified: trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2006-11-20 09:26:44 UTC (rev 2673) +++ trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2006-11-20 19:28:50 UTC (rev 2674) @@ -404,7 +404,7 @@ * @param classloader Classloader to use * @return Absolute path to library if found, otherwise null */ - public static String getPathFromClassLoader(final String libname, final ClassLoader classloader) { + private static String getPathFromClassLoader(final String libname, final ClassLoader classloader) { try { log("getPathFromClassLoader: searching for: " + libname); Class c = classloader.getClass(); Modified: trunk/LWJGL/src/java/org/lwjgl/openal/AL.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/openal/AL.java 2006-11-20 09:26:44 UTC (rev 2673) +++ trunk/LWJGL/src/java/org/lwjgl/openal/AL.java 2006-11-20 19:28:50 UTC (rev 2674) @@ -122,6 +122,7 @@ try { nCreate(oalPaths[i]); created = true; + init(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, openDevice); break; } catch (LWJGLException e) { LWJGLUtil.log("Failed to load " + oalPaths[i] + ": " + e.getMessage()); @@ -131,10 +132,13 @@ // Try to load OpenAL from the framework instead nCreateDefault(); created = true; + init(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, openDevice); } if (!created) throw new LWJGLException("Could not locate OpenAL library."); + } + private static void init(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized, boolean openDevice) throws LWJGLException { try { AL10.initNativeStubs(); ALC.initNativeStubs(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-11-20 20:07:32
|
Revision: 2675 http://svn.sourceforge.net/java-game-lib/?rev=2675&view=rev Author: elias_naur Date: 2006-11-20 12:07:29 -0800 (Mon, 20 Nov 2006) Log Message: ----------- Made LWJGLUtil.getLibraryPaths support multiple library names. Now AL.create on linux tries both libopenal.so and libopenal.so.0, which is the name of the system library Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java trunk/LWJGL/src/java/org/lwjgl/openal/AL.java Modified: trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2006-11-20 19:28:50 UTC (rev 2674) +++ trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2006-11-20 20:07:29 UTC (rev 2675) @@ -315,73 +315,68 @@ /** * Locates the paths required by a library. * - * @param libNames List of library names to look for, in the form of Local Library name, Platform library name. - * At least 6 names must be passed. 2 for each supported platform in the following order: Windows, Linux, MacOSX. + * @param libName Local Library Name to search the classloader with ("openal"). + * @param platform_lib_name The native library name ("libopenal.so") * @param classloader The classloader to ask for library paths * @return Paths to located libraries, if any */ - public static String[] getLibraryPaths(String[] libNames, ClassLoader classloader) throws LWJGLException { + public static String[] getLibraryPaths(String libname, String platform_lib_name, ClassLoader classloader) { + return getLibraryPaths(libname, new String[]{platform_lib_name}, classloader); + } + + /** + * Locates the paths required by a library. + * + * @param libName Local Library Name to search the classloader with ("openal"). + * @param platform_lib_names The list of possible library names ("libopenal.so") + * @param classloader The classloader to ask for library paths + * @return Paths to located libraries, if any + */ + public static String[] getLibraryPaths(String libname, String[] platform_lib_names, ClassLoader classloader) { // need to pass path of possible locations of library to native side List possible_paths = new ArrayList(); - String libname; - String platform_lib_name; - switch (getPlatform()) { - case PLATFORM_WINDOWS: - libname = libNames[0]; - platform_lib_name = libNames[1]; - break; - case PLATFORM_LINUX: - libname = libNames[2]; - platform_lib_name = libNames[3]; - break; - case PLATFORM_MACOSX: - libname = libNames[4]; - platform_lib_name = libNames[5]; - break; - default: - throw new LWJGLException("Unknown platform: " + getPlatform()); - } - String classloader_path = getPathFromClassLoader(libname, classloader); if (classloader_path != null) { log("getPathFromClassLoader: Path found: " + classloader_path); possible_paths.add(classloader_path); } - String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader); - if (lwjgl_classloader_path != null) { - log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path); - possible_paths.add(lwjgl_classloader_path.substring(0, lwjgl_classloader_path.lastIndexOf(File.separator)) - + File.separator + platform_lib_name); - } - - // add Installer path - String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath"); - if (alternative_path != null) { - possible_paths.add(alternative_path + File.separator + platform_lib_name); - } + for (int i = 0; i < platform_lib_names.length; i++) { + String platform_lib_name = platform_lib_names[i]; + String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader); + if (lwjgl_classloader_path != null) { + log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path); + possible_paths.add(lwjgl_classloader_path.substring(0, lwjgl_classloader_path.lastIndexOf(File.separator)) + + File.separator + platform_lib_name); + } - // Add all possible paths from java.library.path - String java_library_path = getPrivilegedProperty("java.library.path"); - - StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator); - while (st.hasMoreTokens()) { - String path = st.nextToken(); - possible_paths.add(path + File.separator + platform_lib_name); - } + // add Installer path + String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath"); + if (alternative_path != null) { + possible_paths.add(alternative_path + File.separator + platform_lib_name); + } - //add current path - String current_dir = getPrivilegedProperty("user.dir"); - possible_paths.add(current_dir + File.separator + platform_lib_name); + // Add all possible paths from java.library.path + String java_library_path = getPrivilegedProperty("java.library.path"); - //add pure library (no path, let OS search) - possible_paths.add(platform_lib_name); + StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator); + while (st.hasMoreTokens()) { + String path = st.nextToken(); + possible_paths.add(path + File.separator + platform_lib_name); + } + //add current path + String current_dir = getPrivilegedProperty("user.dir"); + possible_paths.add(current_dir + File.separator + platform_lib_name); + + //add pure library (no path, let OS search) + possible_paths.add(platform_lib_name); + } + //create needed string array String[] paths = new String[possible_paths.size()]; possible_paths.toArray(paths); - return paths; } Modified: trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2006-11-20 19:28:50 UTC (rev 2674) +++ trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2006-11-20 20:07:29 UTC (rev 2675) @@ -94,10 +94,25 @@ private static native int getNativeLibraryVersion(); static void createIL() throws LWJGLException { - String[] illPaths = LWJGLUtil.getLibraryPaths(new String[]{ - "DevIL", "DevIL.dll", - "IL", "libIL.so", - "IL", "libIL.dylib"}, IL.class.getClassLoader()); + String libname; + String platform_libname; + switch (LWJGLUtil.getPlatform()) { + case LWJGLUtil.PLATFORM_WINDOWS: + libname = "DevIL"; + platform_libname = "DevIL.dll"; + break; + case LWJGLUtil.PLATFORM_LINUX: + libname = "IL"; + platform_libname = "libIL.so"; + break; + case LWJGLUtil.PLATFORM_MACOSX: + libname = "IL"; + platform_libname = "libIL.dylib"; + break; + default: + throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform()); + } + String[] illPaths = LWJGLUtil.getLibraryPaths(libname, platform_libname, IL.class.getClassLoader()); ILNative.nCreateIL(illPaths); try { @@ -124,10 +139,22 @@ static native void nDestroyILU(); static void createILU() throws LWJGLException { - String[] iluPaths = LWJGLUtil.getLibraryPaths(new String[]{ - "ILU", "ILU.dll", - "ILU", "libILU.so", - "ILU", "libILU.dylib"}, ILU.class.getClassLoader()); + String libname; + switch (LWJGLUtil.getPlatform()) { + case LWJGLUtil.PLATFORM_WINDOWS: + libname = "ILU.dll"; + break; + case LWJGLUtil.PLATFORM_LINUX: + libname = "libILU.so"; + break; + case LWJGLUtil.PLATFORM_MACOSX: + libname = "libILU.dylib"; + break; + default: + throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform()); + } + + String[] iluPaths = LWJGLUtil.getLibraryPaths("ILU", libname, ILU.class.getClassLoader()); ILNative.nCreateILU(iluPaths); try { @@ -153,10 +180,21 @@ static native void nDestroyILUT(); static void createILUT() throws LWJGLException { - String[] ilutPaths = LWJGLUtil.getLibraryPaths(new String[]{ - "ILUT", "ILUT.dll", - "ILUT", "libILUT.so", - "ILUT", "libILUT.dylib"}, ILUT.class.getClassLoader()); + String libname; + switch (LWJGLUtil.getPlatform()) { + case LWJGLUtil.PLATFORM_WINDOWS: + libname = "ILUT.dll"; + break; + case LWJGLUtil.PLATFORM_LINUX: + libname = "libILUT.so"; + break; + case LWJGLUtil.PLATFORM_MACOSX: + libname = "libILUT.dylib"; + break; + default: + throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform()); + } + String[] ilutPaths = LWJGLUtil.getLibraryPaths("ILUT", libname, ILUT.class.getClassLoader()); ILNative.nCreateILUT(ilutPaths); try { Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2006-11-20 19:28:50 UTC (rev 2674) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2006-11-20 20:07:29 UTC (rev 2675) @@ -263,11 +263,21 @@ } try { - String[] fmodPaths = LWJGLUtil.getLibraryPaths(new String[]{ - "fmod", "fmod.dll", - "fmod", "libfmod.so", - "fmod", "static-ignored"}, - FMOD.class.getClassLoader()); + String libname; + switch (LWJGLUtil.getPlatform()) { + case LWJGLUtil.PLATFORM_WINDOWS: + libname = "fmod.dll"; + break; + case LWJGLUtil.PLATFORM_LINUX: + libname = "libfmod.so"; + break; + case LWJGLUtil.PLATFORM_MACOSX: + libname = "static-ignored"; + break; + default: + throw new FMODException("Unknown platform: " + LWJGLUtil.getPlatform()); + } + String[] fmodPaths = LWJGLUtil.getLibraryPaths("fmod", libname, FMOD.class.getClassLoader()); LWJGLUtil.log("Found " + fmodPaths.length + " FMOD paths"); nCreate(fmodPaths); created = true; Modified: trunk/LWJGL/src/java/org/lwjgl/openal/AL.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/openal/AL.java 2006-11-20 19:28:50 UTC (rev 2674) +++ trunk/LWJGL/src/java/org/lwjgl/openal/AL.java 2006-11-20 20:07:29 UTC (rev 2675) @@ -113,10 +113,25 @@ if (created) throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time."); - String[] oalPaths = LWJGLUtil.getLibraryPaths(new String[]{ - "OpenAL32", "OpenAL32.dll", - "openal", "libopenal.so", - "openal", "openal.dylib"}, AL.class.getClassLoader()); + String libname; + String[] library_names; + switch (LWJGLUtil.getPlatform()) { + case LWJGLUtil.PLATFORM_WINDOWS: + libname = "OpenAL32"; + library_names = new String[]{"OpenAL32.dll"}; + break; + case LWJGLUtil.PLATFORM_LINUX: + libname = "openal"; + library_names = new String[]{"libopenal.so", "libopenal.so.0"}; + break; + case LWJGLUtil.PLATFORM_MACOSX: + libname = "openal"; + library_names = new String[]{"openal.dylib"}; + break; + default: + throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform()); + } + String[] oalPaths = LWJGLUtil.getLibraryPaths(libname, library_names, AL.class.getClassLoader()); LWJGLUtil.log("Found " + oalPaths.length + " OpenAL paths"); for (int i = 0; i < oalPaths.length; i++) { try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-11-24 14:53:03
|
Revision: 2678 http://svn.sourceforge.net/java-game-lib/?rev=2678&view=rev Author: elias_naur Date: 2006-11-24 06:53:01 -0800 (Fri, 24 Nov 2006) Log Message: ----------- Make sure that the cursor position doesn't jump when switching grab mode Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-11-24 12:05:46 UTC (rev 2677) +++ trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-11-24 14:53:01 UTC (rev 2678) @@ -570,6 +570,10 @@ isGrabbed = grab; if (isCreated()) { implementation.grabMouse(isGrabbed); + // Get latest values from native side + poll(); + event_x = x; + event_y = y; resetMouse(); } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java 2006-11-24 12:05:46 UTC (rev 2677) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java 2006-11-24 14:53:01 UTC (rev 2678) @@ -37,7 +37,9 @@ import java.awt.Cursor; import java.awt.Component; +import java.awt.GraphicsDevice; import java.awt.Dimension; +import java.awt.IllegalComponentStateException; import java.awt.Point; import java.awt.Rectangle; import java.awt.Robot; @@ -106,12 +108,75 @@ } } + private static int transformY(Component component, int y) { + return component.getHeight() - 1 - y; + } + + /** + * Use reflection to access the JDK 1.5 pointer location, if possible and + * only if the given component is on the same screen as the cursor. Return + * null otherwise. + */ + private static Point getPointerLocation(final Component component) { + try { + final Class MouseInfo_class = Class.forName("java.awt.MouseInfo"); + final Method getPointerInfo_method = MouseInfo_class.getMethod("getPointerInfo", null); + final Class PointerInfo_class = Class.forName("java.awt.PointerInfo"); + final Method getDevice_method = PointerInfo_class.getMethod("getDevice", null); + final Method getLocation_method = PointerInfo_class.getMethod("getLocation", null); + return (Point)AccessController.doPrivileged(new PrivilegedExceptionAction() { + public final Object run() throws Exception { + Object pointer_info = getPointerInfo_method.invoke(null, null); + GraphicsDevice device = (GraphicsDevice)getDevice_method.invoke(pointer_info, null); + if (device == component.getGraphicsConfiguration().getDevice()) { + return (Point)getLocation_method.invoke(pointer_info, null); + } else + return null; + } + }); + } catch (PrivilegedActionException e) { + LWJGLUtil.log("Failed to query pointer location: " + e.getCause()); + } catch (NoSuchMethodException e) { + LWJGLUtil.log("Failed to query pointer location: " + e); + } catch (IllegalAccessException e) { + LWJGLUtil.log("Failed to query pointer location: " + e); + } catch (ClassNotFoundException e) { + LWJGLUtil.log("Failed to query pointer location: " + e); + } + return null; + } + + /** + * Use the 1.5 API to get the cursor position relative to the component. Return null + * if it fails (JDK <= 1.4). + */ + public static Point getCursorPosition(Component component) { + try { + Point pointer_location = getPointerLocation(component); + if (pointer_location != null) { + Point location = component.getLocationOnScreen(); + pointer_location.translate(-location.x, -location.y); + pointer_location.move(pointer_location.x, transformY(component, pointer_location.y)); + return pointer_location; + } + } catch (IllegalComponentStateException e) { + LWJGLUtil.log("Failed to set cursor position: " + e); + } catch (NoClassDefFoundError e) { // Not JDK 1.5 + LWJGLUtil.log("Failed to query cursor position: " + e); + } + return null; + } + public static void setCursorPosition(Component component, Robot robot, int x, int y) { if (robot != null) { - Point location = component.getLocationOnScreen(); - int transformed_x = location.x + x; - int transformed_y = location.y + component.getHeight() - 1 - y; - robot.mouseMove(transformed_x, transformed_y); + try { + Point location = component.getLocationOnScreen(); + int transformed_x = location.x + x; + int transformed_y = location.y + transformY(component, y); + robot.mouseMove(transformed_x, transformed_y); + } catch (IllegalComponentStateException e) { + LWJGLUtil.log("Failed to set cursor position: " + e); + } } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java 2006-11-24 12:05:46 UTC (rev 2677) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxMouse.java 2006-11-24 14:53:01 UTC (rev 2678) @@ -173,7 +173,15 @@ public void changeGrabbed(boolean grab, boolean warp_pointer) { reset(); long root_window = nQueryPointer(display, window, query_pointer_buffer); - doHandlePointerMotion(grab, warp_pointer, root_window, query_pointer_buffer.get(0), query_pointer_buffer.get(1), query_pointer_buffer.get(2), query_pointer_buffer.get(3), last_event_nanos); + + int root_x = query_pointer_buffer.get(0); + int root_y = query_pointer_buffer.get(1); + int win_x = query_pointer_buffer.get(2); + int win_y = query_pointer_buffer.get(3); + // Pretend that the cursor never moved + last_x = win_x; + last_y = transformY(win_y); + doHandlePointerMotion(grab, warp_pointer, root_window, root_x, root_y, win_x, win_y, last_event_nanos); } public int getButtonCount() { Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java 2006-11-24 12:05:46 UTC (rev 2677) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java 2006-11-24 14:53:01 UTC (rev 2678) @@ -42,6 +42,7 @@ import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.Component; +import java.awt.Point; import java.nio.ByteBuffer; import java.nio.IntBuffer; @@ -112,6 +113,11 @@ protected void resetCursorToCenter() { clearEvents(); accum_dx = accum_dy = 0; + Point cursor_location = AWTUtil.getCursorPosition(component); + if (cursor_location != null) { + last_x = cursor_location.x; + last_y = cursor_location.y; + } } private void putMouseEvent(byte button, byte state, int dz, long nanos) { Modified: trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java 2006-11-24 12:05:46 UTC (rev 2677) +++ trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java 2006-11-24 14:53:01 UTC (rev 2678) @@ -242,6 +242,8 @@ if(Mouse.getEventButton() != -1 && Mouse.getEventButtonState()) { lastButton = Mouse.getEventButton(); } + if (Mouse.getEventDX() != 0 || Mouse.getEventDY() != 0) + System.out.println("Mouse.getEventDX() = " + Mouse.getEventDX() + " | Mouse.getEventDY() = " + Mouse.getEventDY()); } updateState(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-12-20 19:24:26
|
Revision: 2701 http://svn.sourceforge.net/java-game-lib/?rev=2701&view=rev Author: elias_naur Date: 2006-12-20 11:24:25 -0800 (Wed, 20 Dec 2006) Log Message: ----------- Fix VBO tests and bump Sys native JNI library version Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOIndexTest.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-12-20 19:23:35 UTC (rev 2700) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-12-20 19:24:25 UTC (rev 2701) @@ -57,7 +57,7 @@ private static final String VERSION = "1.0-rc1"; /** Current version of the JNI library */ - static final int JNI_VERSION = 6; + static final int JNI_VERSION = 7; /** The implementation instance to delegate platform specific behavior to */ private final static SysImplementation implementation; Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOIndexTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOIndexTest.java 2006-12-20 19:23:35 UTC (rev 2700) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOIndexTest.java 2006-12-20 19:24:25 UTC (rev 2701) @@ -169,7 +169,6 @@ ByteBuffer new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, ARBBufferObject.GL_WRITE_ONLY_ARB, - 2 * 4 * 4, mapped_buffer); if ( new_mapped_buffer != mapped_buffer ) mapped_float_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); @@ -177,7 +176,6 @@ new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, ARBBufferObject.GL_WRITE_ONLY_ARB, - 4 * 4, mapped_indices_buffer); if ( new_mapped_buffer != mapped_indices_buffer ) mapped_indices_int_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asIntBuffer(); Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOTest.java 2006-12-20 19:23:35 UTC (rev 2700) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/VBOTest.java 2006-12-20 19:24:25 UTC (rev 2701) @@ -163,7 +163,6 @@ GL11.glRotatef(angle, 0, 0, 1.0f); ByteBuffer new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, ARBBufferObject.GL_WRITE_ONLY_ARB, - 2 * 4 * 4, mapped_buffer); if ( new_mapped_buffer != mapped_buffer ) mapped_float_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-01-17 12:58:41
|
Revision: 2730 http://svn.sourceforge.net/java-game-lib/?rev=2730&view=rev Author: elias_naur Date: 2007-01-17 04:58:38 -0800 (Wed, 17 Jan 2007) Log Message: ----------- Remove the rest of the implementation reflection Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/opengl/AWTGLCanvas.java trunk/LWJGL/src/java/org/lwjgl/opengl/Context.java trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2007-01-17 12:49:20 UTC (rev 2729) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2007-01-17 12:58:38 UTC (rev 2730) @@ -108,7 +108,6 @@ } private static SysImplementation createImplementation() { - String class_name; switch (LWJGLUtil.getPlatform()) { case LWJGLUtil.PLATFORM_LINUX: return new LinuxSysImplementation(); Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AWTGLCanvas.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTGLCanvas.java 2007-01-17 12:49:20 UTC (rev 2729) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/AWTGLCanvas.java 2007-01-17 12:58:38 UTC (rev 2730) @@ -86,30 +86,20 @@ static { Sys.initialize(); - String class_name; + implementation = createImplementation(); + } + + private static AWTCanvasImplementation createImplementation() { switch (LWJGLUtil.getPlatform()) { case LWJGLUtil.PLATFORM_LINUX: - class_name = "org.lwjgl.opengl.LinuxCanvasImplementation"; - break; + return new LinuxCanvasImplementation(); case LWJGLUtil.PLATFORM_WINDOWS: - class_name = "org.lwjgl.opengl.WindowsCanvasImplementation"; - break; + return new WindowsCanvasImplementation(); case LWJGLUtil.PLATFORM_MACOSX: - class_name = "org.lwjgl.opengl.MacOSXCanvasImplementation"; - break; + return new MacOSXCanvasImplementation(); default: throw new IllegalStateException("Unsupported platform"); } - try { - Class impl_class = Class.forName(class_name); - implementation = (AWTCanvasImplementation)impl_class.newInstance(); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } } /** Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Context.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Context.java 2007-01-17 12:49:20 UTC (rev 2729) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Context.java 2007-01-17 12:58:38 UTC (rev 2730) @@ -73,30 +73,20 @@ static { Sys.initialize(); - String class_name; + implementation = createImplementation(); + } + + private static ContextImplementation createImplementation() { switch (LWJGLUtil.getPlatform()) { case LWJGLUtil.PLATFORM_LINUX: - class_name = "org.lwjgl.opengl.LinuxContextImplementation"; - break; + return new LinuxContextImplementation(); case LWJGLUtil.PLATFORM_WINDOWS: - class_name = "org.lwjgl.opengl.WindowsContextImplementation"; - break; + return new WindowsContextImplementation(); case LWJGLUtil.PLATFORM_MACOSX: - class_name = "org.lwjgl.opengl.MacOSXContextImplementation"; - break; + return new MacOSXContextImplementation(); default: throw new IllegalStateException("Unsupported platform"); } - try { - Class impl_class = Class.forName(class_name); - implementation = (ContextImplementation)impl_class.newInstance(); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } } PeerInfo getPeerInfo() { Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2007-01-17 12:49:20 UTC (rev 2729) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2007-01-17 12:58:38 UTC (rev 2730) @@ -133,30 +133,16 @@ } private static DisplayImplementation createDisplayImplementation() { - String class_name; switch (LWJGLUtil.getPlatform()) { case LWJGLUtil.PLATFORM_LINUX: - class_name = "org.lwjgl.opengl.LinuxDisplay"; - break; + return new LinuxDisplay(); case LWJGLUtil.PLATFORM_WINDOWS: - class_name = "org.lwjgl.opengl.WindowsDisplay"; - break; + return new WindowsDisplay(); case LWJGLUtil.PLATFORM_MACOSX: - class_name = "org.lwjgl.opengl.MacOSXDisplay"; - break; + return new MacOSXDisplay(); default: throw new IllegalStateException("Unsupported platform"); } - try { - Class display_class = Class.forName(class_name); - return (DisplayImplementation)display_class.newInstance(); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-01-22 09:24:08
|
Revision: 2731 http://svn.sourceforge.net/java-game-lib/?rev=2731&view=rev Author: elias_naur Date: 2007-01-22 01:24:06 -0800 (Mon, 22 Jan 2007) Log Message: ----------- Changed version to RC2 Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2007-01-17 12:58:38 UTC (rev 2730) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2007-01-22 09:24:06 UTC (rev 2731) @@ -54,7 +54,7 @@ private static final String JNI_LIBRARY_NAME = "lwjgl"; /** Current version of library */ - private static final String VERSION = "1.0-rc1"; + private static final String VERSION = "1.0-rc2"; /** Current version of the JNI library */ static final int JNI_VERSION = 8; Modified: trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2007-01-17 12:58:38 UTC (rev 2730) +++ trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2007-01-22 09:24:06 UTC (rev 2731) @@ -53,7 +53,7 @@ private static String JNI_LIBRARY_NAME = "lwjgl-devil"; /** Version of IL */ - static final String VERSION = "1.0-rc1"; + static final String VERSION = "1.0-rc2"; /** Current version of the JNI library */ static final int JNI_VERSION = 2; Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2007-01-17 12:58:38 UTC (rev 2730) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2007-01-22 09:24:06 UTC (rev 2731) @@ -193,7 +193,7 @@ private static String JNI_LIBRARY_NAME = "lwjgl-fmod3"; /** Version of FMOD */ - private static final String VERSION = "1.0-rc1"; + private static final String VERSION = "1.0-rc2"; /** Current version of the JNI library */ static final int JNI_VERSION = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-02-12 12:18:36
|
Revision: 2739 http://svn.sourceforge.net/java-game-lib/?rev=2739&view=rev Author: elias_naur Date: 2007-02-12 04:18:26 -0800 (Mon, 12 Feb 2007) Log Message: ----------- Make the rest of LWJGL thread safe. No attempt have been done to make the locking minimal. Instead, one global lock is shared by Display, Mouse, Keyboard and Cursor. The lock surrounds all public methods. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/input/Cursor.java trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/input/OpenGLPackageAccess.java trunk/LWJGL/src/java/org/lwjgl/opengl/GlobalLock.java Modified: trunk/LWJGL/src/java/org/lwjgl/input/Cursor.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Cursor.java 2007-02-08 22:00:51 UTC (rev 2738) +++ trunk/LWJGL/src/java/org/lwjgl/input/Cursor.java 2007-02-12 12:18:26 UTC (rev 2739) @@ -83,27 +83,29 @@ * @throws LWJGLException if the cursor could not be created for any reason */ public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { - if ((getCapabilities() & CURSOR_ONE_BIT_TRANSPARENCY) == 0) - throw new LWJGLException("Native cursors not supported"); - BufferChecks.checkBuffer(images, width*height*numImages); - if (!Mouse.isCreated()) - throw new IllegalStateException("Mouse must be created before creating cursor objects"); - if (width*height*numImages > images.remaining()) - throw new IllegalArgumentException("width*height*numImages > images.remaining()"); - if (delays != null && numImages > delays.remaining()) - BufferChecks.checkBuffer(delays, numImages); - if (xHotspot >= width || xHotspot < 0) - throw new IllegalArgumentException("xHotspot > width || xHotspot < 0"); - if (yHotspot >= height || yHotspot < 0) - throw new IllegalArgumentException("yHotspot > height || yHotspot < 0"); - - Sys.initialize(); - - // Hmm - yHotspot = height - 1 - yHotspot; - - // create cursor (or cursors if multiple images supplied) - cursors = createCursors(width, height, xHotspot, yHotspot, numImages, images, delays); + synchronized (OpenGLPackageAccess.global_lock) { + if ((getCapabilities() & CURSOR_ONE_BIT_TRANSPARENCY) == 0) + throw new LWJGLException("Native cursors not supported"); + BufferChecks.checkBuffer(images, width*height*numImages); + if (!Mouse.isCreated()) + throw new IllegalStateException("Mouse must be created before creating cursor objects"); + if (width*height*numImages > images.remaining()) + throw new IllegalArgumentException("width*height*numImages > images.remaining()"); + if (delays != null && numImages > delays.remaining()) + BufferChecks.checkBuffer(delays, numImages); + if (xHotspot >= width || xHotspot < 0) + throw new IllegalArgumentException("xHotspot > width || xHotspot < 0"); + if (yHotspot >= height || yHotspot < 0) + throw new IllegalArgumentException("yHotspot > height || yHotspot < 0"); + + Sys.initialize(); + + // Hmm + yHotspot = height - 1 - yHotspot; + + // create cursor (or cursors if multiple images supplied) + cursors = createCursors(width, height, xHotspot, yHotspot, numImages, images, delays); + } } /** @@ -114,9 +116,11 @@ * @return the maximum size of a native cursor */ public static int getMinCursorSize() { - if (!Mouse.isCreated()) - throw new IllegalStateException("Mouse must be created."); - return Mouse.getImplementation().getMinCursorSize(); + synchronized (OpenGLPackageAccess.global_lock) { + if (!Mouse.isCreated()) + throw new IllegalStateException("Mouse must be created."); + return Mouse.getImplementation().getMinCursorSize(); + } } /** @@ -127,9 +131,11 @@ * @return the maximum size of a native cursor */ public static int getMaxCursorSize() { - if (!Mouse.isCreated()) - throw new IllegalStateException("Mouse must be created."); - return Mouse.getImplementation().getMaxCursorSize(); + synchronized (OpenGLPackageAccess.global_lock) { + if (!Mouse.isCreated()) + throw new IllegalStateException("Mouse must be created."); + return Mouse.getImplementation().getMaxCursorSize(); + } } /** @@ -141,10 +147,12 @@ * @return A bit mask with native cursor capabilities. */ public static int getCapabilities() { - if (Mouse.getImplementation() != null) - return Mouse.getImplementation().getNativeCursorCapabilities(); - else - return Mouse.createImplementation().getNativeCursorCapabilities(); + synchronized (OpenGLPackageAccess.global_lock) { + if (Mouse.getImplementation() != null) + return Mouse.getImplementation().getNativeCursorCapabilities(); + else + return OpenGLPackageAccess.createImplementation().getNativeCursorCapabilities(); + } } /** @@ -247,19 +255,21 @@ * OS cursor) */ public void destroy() { - if (destroyed) - return; - if (Mouse.getNativeCursor() == this) { - try { - Mouse.setNativeCursor(null); - } catch (LWJGLException e) { - // ignore + synchronized (OpenGLPackageAccess.global_lock) { + if (destroyed) + return; + if (Mouse.getNativeCursor() == this) { + try { + Mouse.setNativeCursor(null); + } catch (LWJGLException e) { + // ignore + } } + for(int i=0; i<cursors.length; i++) { + Mouse.getImplementation().destroyCursor(cursors[i].cursorHandle); + } + destroyed = true; } - for(int i=0; i<cursors.length; i++) { - Mouse.getImplementation().destroyCursor(cursors[i].cursorHandle); - } - destroyed = true; } /** Modified: trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2007-02-08 22:00:51 UTC (rev 2738) +++ trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2007-02-12 12:18:26 UTC (rev 2739) @@ -307,9 +307,11 @@ * @throws LWJGLException if the keyboard could not be created for any reason */ public static synchronized void create() throws LWJGLException { - if (!Display.isCreated()) throw new IllegalStateException("Display must be created."); + synchronized (OpenGLPackageAccess.global_lock) { + if (!Display.isCreated()) throw new IllegalStateException("Display must be created."); - create(Mouse.createImplementation()); + create(OpenGLPackageAccess.createImplementation()); + } } private static void reset() { @@ -325,18 +327,22 @@ * @return true if the keyboard has been created */ public static synchronized boolean isCreated() { - return created; + synchronized (OpenGLPackageAccess.global_lock) { + return created; + } } /** * "Destroy" the keyboard */ public static synchronized void destroy() { - if (!created) - return; - created = false; - implementation.destroyKeyboard(); - reset(); + synchronized (OpenGLPackageAccess.global_lock) { + if (!created) + return; + created = false; + implementation.destroyKeyboard(); + reset(); + } } /** @@ -358,10 +364,12 @@ * @see org.lwjgl.input.Keyboard#getEventCharacter() */ public static synchronized void poll() { - if (!created) - throw new IllegalStateException("Keyboard must be created before you can poll the device"); - implementation.pollKeyboard(keyDownBuffer); - read(); + synchronized (OpenGLPackageAccess.global_lock) { + if (!created) + throw new IllegalStateException("Keyboard must be created before you can poll the device"); + implementation.pollKeyboard(keyDownBuffer); + read(); + } } private static void read() { @@ -376,9 +384,11 @@ * @return true if the key is down according to the last poll() */ public static synchronized boolean isKeyDown(int key) { - if (!created) - throw new IllegalStateException("Keyboard must be created before you can query key state"); - return keyDownBuffer.get(key) != 0; + synchronized (OpenGLPackageAccess.global_lock) { + if (!created) + throw new IllegalStateException("Keyboard must be created before you can query key state"); + return keyDownBuffer.get(key) != 0; + } } /** @@ -419,9 +429,11 @@ * @return the number of keyboard events */ public static synchronized int getNumKeyboardEvents() { - if (!created) - throw new IllegalStateException("Keyboard must be created before you can read events"); - return readBuffer.remaining()/EVENT_SIZE; + synchronized (OpenGLPackageAccess.global_lock) { + if (!created) + throw new IllegalStateException("Keyboard must be created before you can read events"); + return readBuffer.remaining()/EVENT_SIZE; + } } /** @@ -436,17 +448,19 @@ * @return true if a keyboard event was read, false otherwise */ public static synchronized boolean next() { - if (!created) - throw new IllegalStateException("Keyboard must be created before you can read events"); + synchronized (OpenGLPackageAccess.global_lock) { + if (!created) + throw new IllegalStateException("Keyboard must be created before you can read events"); - if (readBuffer.hasRemaining()) { - eventKey = readBuffer.getInt() & 0xFF; - eventState = readBuffer.get() != 0; - eventCharacter = readBuffer.getInt(); - eventNanos = readBuffer.getLong(); - return true; - } else { - return false; + if (readBuffer.hasRemaining()) { + eventKey = readBuffer.getInt() & 0xFF; + eventState = readBuffer.get() != 0; + eventCharacter = readBuffer.getInt(); + eventNanos = readBuffer.getLong(); + return true; + } else { + return false; + } } } @@ -454,14 +468,18 @@ * @return Number of keys on this keyboard */ public static synchronized int getKeyCount() { - return keyCount; + synchronized (OpenGLPackageAccess.global_lock) { + return keyCount; + } } /** * @return The character from the current event */ public static synchronized char getEventCharacter() { - return (char)eventCharacter; + synchronized (OpenGLPackageAccess.global_lock) { + return (char)eventCharacter; + } } /** @@ -472,7 +490,9 @@ * @return The key from the current event */ public static synchronized int getEventKey() { - return eventKey; + synchronized (OpenGLPackageAccess.global_lock) { + return eventKey; + } } /** @@ -482,7 +502,9 @@ * @return True if key was down, or false if released */ public static synchronized boolean getEventKeyState() { - return eventState; + synchronized (OpenGLPackageAccess.global_lock) { + return eventState; + } } /** @@ -493,6 +515,8 @@ * @return The time in nanoseconds of the current event */ public static synchronized long getEventNanoseconds() { - return eventNanos; + synchronized (OpenGLPackageAccess.global_lock) { + return eventNanos; + } } } Modified: trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2007-02-08 22:00:51 UTC (rev 2738) +++ trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2007-02-12 12:18:26 UTC (rev 2739) @@ -43,12 +43,7 @@ import org.lwjgl.opengl.Display; import org.lwjgl.opengl.InputImplementation; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedExceptionAction; -import java.security.PrivilegedActionException; - /** * <br> * A raw Mouse interface. This can be used to poll the current state of the @@ -152,7 +147,9 @@ * @return the currently bound native cursor, if any. */ public static synchronized Cursor getNativeCursor() { - return currentCursor; + synchronized (OpenGLPackageAccess.global_lock) { + return currentCursor; + } } /** @@ -167,19 +164,21 @@ * @throws LWJGLException if the cursor could not be set for any reason */ public static synchronized Cursor setNativeCursor(Cursor cursor) throws LWJGLException { - if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) == 0) - throw new IllegalStateException("Mouse doesn't support native cursors"); - Cursor oldCursor = currentCursor; - currentCursor = cursor; - if (isCreated()) { - if (currentCursor != null) { - implementation.setNativeCursor(currentCursor.getHandle()); - currentCursor.setTimeout(); - } else { - implementation.setNativeCursor(null); + synchronized (OpenGLPackageAccess.global_lock) { + if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) == 0) + throw new IllegalStateException("Mouse doesn't support native cursors"); + Cursor oldCursor = currentCursor; + currentCursor = cursor; + if (isCreated()) { + if (currentCursor != null) { + implementation.setNativeCursor(currentCursor.getHandle()); + currentCursor.setTimeout(); + } else { + implementation.setNativeCursor(null); + } } + return oldCursor; } - return oldCursor; } /** @@ -192,12 +191,14 @@ * to the window origin. */ public static synchronized void setCursorPosition(int new_x, int new_y) { - if (!isCreated()) - throw new IllegalStateException("Mouse is not created"); - x = event_x = new_x; - y = event_y = new_y; - if (!isGrabbed() && (Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0) - implementation.setCursorPosition(x, y); + synchronized (OpenGLPackageAccess.global_lock) { + if (!isCreated()) + throw new IllegalStateException("Mouse is not created"); + x = event_x = new_x; + y = event_y = new_y; + if (!isGrabbed() && (Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0) + implementation.setCursorPosition(x, y); + } } /** @@ -225,23 +226,6 @@ return implementation; } - static InputImplementation createImplementation() { - /* Use reflection since we can't make Display.getImplementation - * public - */ - try { - return (InputImplementation)AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation", null); - getImplementation_method.setAccessible(true); - return getImplementation_method.invoke(null, null); - } - }); - } catch (PrivilegedActionException e) { - throw new Error(e); - } - } - /** * "Create" the mouse with the given custom implementation. This is used * reflectively by AWTInputAdapter. @@ -277,28 +261,34 @@ * @throws LWJGLException if the mouse could not be created for any reason */ public static synchronized void create() throws LWJGLException { - if (!Display.isCreated()) throw new IllegalStateException("Display must be created."); + synchronized (OpenGLPackageAccess.global_lock) { + if (!Display.isCreated()) throw new IllegalStateException("Display must be created."); - create(createImplementation()); + create(OpenGLPackageAccess.createImplementation()); + } } /** * @return true if the mouse has been created */ public static synchronized boolean isCreated() { - return created; + synchronized (OpenGLPackageAccess.global_lock) { + return created; + } } /** * "Destroy" the mouse. */ public static synchronized void destroy() { - if (!created) return; - created = false; - buttons = null; - coord_buffer = null; - - implementation.destroyMouse(); + synchronized (OpenGLPackageAccess.global_lock) { + if (!created) return; + created = false; + buttons = null; + coord_buffer = null; + + implementation.destroyMouse(); + } } /** @@ -323,30 +313,32 @@ * @see org.lwjgl.input.Mouse#getDWheel() */ public static synchronized void poll() { - if (!created) throw new IllegalStateException("Mouse must be created before you can poll it"); - implementation.pollMouse(coord_buffer, buttons); + synchronized (OpenGLPackageAccess.global_lock) { + if (!created) throw new IllegalStateException("Mouse must be created before you can poll it"); + implementation.pollMouse(coord_buffer, buttons); - /* If we're grabbed, poll returns mouse deltas, if not it returns absolute coordinates */ - int poll_coord1 = coord_buffer.get(0); - int poll_coord2 = coord_buffer.get(1); - /* The wheel is always relative */ - int poll_dwheel = coord_buffer.get(2); + /* If we're grabbed, poll returns mouse deltas, if not it returns absolute coordinates */ + int poll_coord1 = coord_buffer.get(0); + int poll_coord2 = coord_buffer.get(1); + /* The wheel is always relative */ + int poll_dwheel = coord_buffer.get(2); - if (isGrabbed()) { - dx += poll_coord1; - dy += poll_coord2; - x += poll_coord1; - y += poll_coord2; - } else { - dx = poll_coord1 - x; - dy = poll_coord2 - y; - x = poll_coord1; - y = poll_coord2; + if (isGrabbed()) { + dx += poll_coord1; + dy += poll_coord2; + x += poll_coord1; + y += poll_coord2; + } else { + dx = poll_coord1 - x; + dy = poll_coord2 - y; + x = poll_coord1; + y = poll_coord2; + } + x = Math.min(implementation.getWidth() - 1, Math.max(0, x)); + y = Math.min(implementation.getHeight() - 1, Math.max(0, y)); + dwheel += poll_dwheel; + read(); } - x = Math.min(implementation.getWidth() - 1, Math.max(0, x)); - y = Math.min(implementation.getHeight() - 1, Math.max(0, y)); - dwheel += poll_dwheel; - read(); } private static void read() { @@ -362,11 +354,13 @@ * @return true if the specified button is down */ public static synchronized boolean isButtonDown(int button) { - if (!created) throw new IllegalStateException("Mouse must be created before you can poll the button state"); - if (button >= buttonCount || button < 0) - return false; - else - return buttons.get(button) == 1; + synchronized (OpenGLPackageAccess.global_lock) { + if (!created) throw new IllegalStateException("Mouse must be created before you can poll the button state"); + if (button >= buttonCount || button < 0) + return false; + else + return buttons.get(button) == 1; + } } /** @@ -375,10 +369,12 @@ * @return a String with the button's human readable name in it or null if the button is unnamed */ public static synchronized String getButtonName(int button) { - if (button >= buttonName.length || button < 0) - return null; - else - return buttonName[button]; + synchronized (OpenGLPackageAccess.global_lock) { + if (button >= buttonName.length || button < 0) + return null; + else + return buttonName[button]; + } } /** @@ -386,11 +382,13 @@ * @param buttonName The button name */ public static synchronized int getButtonIndex(String buttonName) { - Integer ret = (Integer) buttonMap.get(buttonName); - if (ret == null) - return -1; - else - return ret.intValue(); + synchronized (OpenGLPackageAccess.global_lock) { + Integer ret = (Integer) buttonMap.get(buttonName); + if (ret == null) + return -1; + else + return ret.intValue(); + } } /** @@ -403,37 +401,41 @@ * @return true if a mouse event was read, false otherwise */ public static synchronized boolean next() { - if (!created) throw new IllegalStateException("Mouse must be created before you can read events"); - if (readBuffer.hasRemaining()) { - eventButton = readBuffer.get(); - eventState = readBuffer.get() != 0; - if (isGrabbed()) { - event_dx = readBuffer.getInt(); - event_dy = readBuffer.getInt(); - event_x += event_dx; - event_y += event_dy; - } else { - int new_event_x = readBuffer.getInt(); - int new_event_y = readBuffer.getInt(); - event_dx = new_event_x - event_x; - event_dy = new_event_y - event_y; - event_x = new_event_x; - event_y = new_event_y; - } - event_x = Math.min(implementation.getWidth() - 1, Math.max(0, event_x)); - event_y = Math.min(implementation.getHeight() - 1, Math.max(0, event_y)); - event_dwheel = readBuffer.getInt(); - event_nanos = readBuffer.getLong(); - return true; - } else - return false; + synchronized (OpenGLPackageAccess.global_lock) { + if (!created) throw new IllegalStateException("Mouse must be created before you can read events"); + if (readBuffer.hasRemaining()) { + eventButton = readBuffer.get(); + eventState = readBuffer.get() != 0; + if (isGrabbed()) { + event_dx = readBuffer.getInt(); + event_dy = readBuffer.getInt(); + event_x += event_dx; + event_y += event_dy; + } else { + int new_event_x = readBuffer.getInt(); + int new_event_y = readBuffer.getInt(); + event_dx = new_event_x - event_x; + event_dy = new_event_y - event_y; + event_x = new_event_x; + event_y = new_event_y; + } + event_x = Math.min(implementation.getWidth() - 1, Math.max(0, event_x)); + event_y = Math.min(implementation.getHeight() - 1, Math.max(0, event_y)); + event_dwheel = readBuffer.getInt(); + event_nanos = readBuffer.getLong(); + return true; + } else + return false; + } } /** * @return Current events button. Returns -1 if no button state was changed */ public static synchronized int getEventButton() { - return eventButton; + synchronized (OpenGLPackageAccess.global_lock) { + return eventButton; + } } /** @@ -441,42 +443,54 @@ * @return Current events button state. */ public static synchronized boolean getEventButtonState() { - return eventState; + synchronized (OpenGLPackageAccess.global_lock) { + return eventState; + } } /** * @return Current events delta x. Only valid when the mouse is grabbed. */ public static synchronized int getEventDX() { - return event_dx; + synchronized (OpenGLPackageAccess.global_lock) { + return event_dx; + } } /** * @return Current events delta y. Only valid when the mouse is grabbed. */ public static synchronized int getEventDY() { - return event_dy; + synchronized (OpenGLPackageAccess.global_lock) { + return event_dy; + } } /** * @return Current events absolute x. Only valid when the mouse is not grabbed. */ public static synchronized int getEventX() { - return event_x; + synchronized (OpenGLPackageAccess.global_lock) { + return event_x; + } } /** * @return Current events absolute y. Only valid when the mouse is not grabbed. */ public static synchronized int getEventY() { - return event_y; + synchronized (OpenGLPackageAccess.global_lock) { + return event_y; + } } /** * @return Current events delta z */ public static synchronized int getEventDWheel() { - return event_dwheel; + synchronized (OpenGLPackageAccess.global_lock) { + return event_dwheel; + } } /** @@ -488,7 +502,9 @@ * @return The time in nanoseconds of the current event */ public static synchronized long getEventNanoseconds() { - return event_nanos; + synchronized (OpenGLPackageAccess.global_lock) { + return event_nanos; + } } /** @@ -498,7 +514,9 @@ * @return Absolute x axis position of mouse */ public static synchronized int getX() { - return x; + synchronized (OpenGLPackageAccess.global_lock) { + return x; + } } /** @@ -508,55 +526,69 @@ * @return Absolute y axis position of mouse */ public static synchronized int getY() { - return y; + synchronized (OpenGLPackageAccess.global_lock) { + return y; + } } /** * @return Movement on the x axis since last time getDX() was called. Only valid when the mouse is grabbed. */ public static synchronized int getDX() { - int result = dx; - dx = 0; - return result; + synchronized (OpenGLPackageAccess.global_lock) { + int result = dx; + dx = 0; + return result; + } } /** * @return Movement on the y axis since last time getDY() was called. Only valid when the mouse is grabbed. */ public static synchronized int getDY() { - int result = dy; - dy = 0; - return result; + synchronized (OpenGLPackageAccess.global_lock) { + int result = dy; + dy = 0; + return result; + } } /** * @return Movement of the wheel since last time getDWheel() was called */ public static synchronized int getDWheel() { - int result = dwheel; - dwheel = 0; - return result; + synchronized (OpenGLPackageAccess.global_lock) { + int result = dwheel; + dwheel = 0; + return result; + } } /** * @return Number of buttons on this mouse */ public static synchronized int getButtonCount() { - return buttonCount; + synchronized (OpenGLPackageAccess.global_lock) { + return buttonCount; + } } /** * @return Whether or not this mouse has wheel support */ public static synchronized boolean hasWheel() { - return hasWheel; + synchronized (OpenGLPackageAccess.global_lock) { + return hasWheel; + } } /** * @return whether or not the mouse has grabbed the cursor */ public static synchronized boolean isGrabbed() { - return isGrabbed; + synchronized (OpenGLPackageAccess.global_lock) { + return isGrabbed; + } } /** @@ -568,14 +600,16 @@ * @param grab whether the mouse should be grabbed */ public static synchronized void setGrabbed(boolean grab) { - isGrabbed = grab; - if (isCreated()) { - implementation.grabMouse(isGrabbed); - // Get latest values from native side - poll(); - event_x = x; - event_y = y; - resetMouse(); + synchronized (OpenGLPackageAccess.global_lock) { + isGrabbed = grab; + if (isCreated()) { + implementation.grabMouse(isGrabbed); + // Get latest values from native side + poll(); + event_x = x; + event_y = y; + resetMouse(); + } } } @@ -585,12 +619,14 @@ * shouldn't be called otherwise */ public static synchronized void updateCursor() { - if (emulateCursorAnimation && currentCursor != null && currentCursor.hasTimedOut()) { - currentCursor.nextCursor(); - try { - setNativeCursor(currentCursor); - } catch (LWJGLException e) { - if (LWJGLUtil.DEBUG) e.printStackTrace(); + synchronized (OpenGLPackageAccess.global_lock) { + if (emulateCursorAnimation && currentCursor != null && currentCursor.hasTimedOut()) { + currentCursor.nextCursor(); + try { + setNativeCursor(currentCursor); + } catch (LWJGLException e) { + if (LWJGLUtil.DEBUG) e.printStackTrace(); + } } } } Added: trunk/LWJGL/src/java/org/lwjgl/input/OpenGLPackageAccess.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/OpenGLPackageAccess.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/input/OpenGLPackageAccess.java 2007-02-12 12:18:26 UTC (rev 2739) @@ -0,0 +1,49 @@ +package org.lwjgl.input; + +import org.lwjgl.opengl.InputImplementation; +import org.lwjgl.opengl.Display; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; + +/** + * This class contains utilities for accessing the org.lwjgl.opengl + * package through (privileged) reflection. + */ +final class OpenGLPackageAccess { + final static Object global_lock; + + static { + try { + global_lock = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Field lock_field = Class.forName("org.lwjgl.opengl.GlobalLock").getDeclaredField("lock"); + lock_field.setAccessible(true); + return lock_field.get(null); + } + }); + } catch (PrivilegedActionException e) { + throw new Error(e); + } + } + + static InputImplementation createImplementation() { + /* Use reflection since we can't make Display.getImplementation + * public + */ + try { + return (InputImplementation)AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation", null); + getImplementation_method.setAccessible(true); + return getImplementation_method.invoke(null, null); + } + }); + } catch (PrivilegedActionException e) { + throw new Error(e); + } + } +} Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2007-02-08 22:00:51 UTC (rev 2738) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2007-02-12 12:18:26 UTC (rev 2739) @@ -102,6 +102,9 @@ private static PeerInfo peer_info; private static Context context; + /** The Drawable instance that tracks the current Display context */ + private final static Drawable drawable; + private static boolean window_created = false; static { @@ -113,23 +116,22 @@ } catch (LWJGLException e) { throw new RuntimeException(e); } + drawable = new Drawable() { + public Context getContext() { + synchronized (GlobalLock.lock) { + return isCreated() ? context : null; + } + } + }; } /** * Fetch the Drawable from the Display. * - * @return the Drawable corresponding to the Display context, or null if display is - * not created. + * @return the Drawable corresponding to the Display context */ public static Drawable getDrawable() { - if (context != null) { - return new Drawable() { - public Context getContext() { - return context; - } - }; - } else - return null; + return drawable; } private static DisplayImplementation createDisplayImplementation() { @@ -167,22 +169,24 @@ * @return an array of all display modes the system reckons it can handle. */ public static DisplayMode[] getAvailableDisplayModes() throws LWJGLException { - DisplayMode[] unfilteredModes = display_impl.getAvailableDisplayModes(); + synchronized (GlobalLock.lock) { + DisplayMode[] unfilteredModes = display_impl.getAvailableDisplayModes(); - if (unfilteredModes == null) { - return new DisplayMode[0]; - } + if (unfilteredModes == null) { + return new DisplayMode[0]; + } - // We'll use a HashSet to filter out the duplicated modes - HashSet modes = new HashSet(unfilteredModes.length); + // We'll use a HashSet to filter out the duplicated modes + HashSet modes = new HashSet(unfilteredModes.length); - modes.addAll(Arrays.asList(unfilteredModes)); - DisplayMode[] filteredModes = new DisplayMode[modes.size()]; - modes.toArray(filteredModes); + modes.addAll(Arrays.asList(unfilteredModes)); + DisplayMode[] filteredModes = new DisplayMode[modes.size()]; + modes.toArray(filteredModes); - LWJGLUtil.log("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes"); + LWJGLUtil.log("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes"); - return filteredModes; + return filteredModes; + } } /** @@ -190,7 +194,9 @@ * @return The current display mode */ public static DisplayMode getDisplayMode() { - return current_mode; + synchronized (GlobalLock.lock) { + return current_mode; + } } /** @@ -204,24 +210,26 @@ * @throws LWJGLException if the display mode could not be set */ public static void setDisplayMode(DisplayMode mode) throws LWJGLException { - if (mode == null) - throw new NullPointerException("mode must be non-null"); - current_mode = mode; - if (isCreated()) { - destroyWindow(); - // If mode is not fullscreen capable, make sure we are in windowed mode - if (!mode.isFullscreen()) - resetFullscreen(); - try { - if (fullscreen) - switchDisplayMode(); - createWindow(); - makeCurrent(); - } catch (LWJGLException e) { - destroyContext(); - destroyPeerInfo(); - display_impl.resetDisplayMode(); - throw e; + synchronized (GlobalLock.lock) { + if (mode == null) + throw new NullPointerException("mode must be non-null"); + current_mode = mode; + if (isCreated()) { + destroyWindow(); + // If mode is not fullscreen capable, make sure we are in windowed mode + if (!mode.isFullscreen()) + resetFullscreen(); + try { + if (fullscreen) + switchDisplayMode(); + createWindow(); + makeCurrent(); + } catch (LWJGLException e) { + destroyContext(); + destroyPeerInfo(); + display_impl.resetDisplayMode(); + throw e; + } } } } @@ -304,35 +312,37 @@ * @param contrast The contrast, larger than 0.0. */ public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws LWJGLException { - if (!isCreated()) { - throw new LWJGLException("Display not yet created."); + synchronized (GlobalLock.lock) { + if (!isCreated()) { + throw new LWJGLException("Display not yet created."); + } + if (brightness < -1.0f || brightness > 1.0f) + throw new IllegalArgumentException("Invalid brightness value"); + if (contrast < 0.0f) + throw new IllegalArgumentException("Invalid contrast value"); + int rampSize = display_impl.getGammaRampLength(); + if (rampSize == 0) { + throw new LWJGLException("Display configuration not supported"); + } + FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize); + for (int i = 0; i < rampSize; i++) { + float intensity = (float)i/(rampSize - 1); + // apply gamma + float rampEntry = (float)java.lang.Math.pow(intensity, gamma); + // apply brightness + rampEntry += brightness; + // apply contrast + rampEntry = (rampEntry - 0.5f)*contrast + 0.5f; + // Clamp entry to [0, 1] + if (rampEntry > 1.0f) + rampEntry = 1.0f; + else if (rampEntry < 0.0f) + rampEntry = 0.0f; + gammaRamp.put(i, rampEntry); + } + display_impl.setGammaRamp(gammaRamp); + LWJGLUtil.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast); } - if (brightness < -1.0f || brightness > 1.0f) - throw new IllegalArgumentException("Invalid brightness value"); - if (contrast < 0.0f) - throw new IllegalArgumentException("Invalid contrast value"); - int rampSize = display_impl.getGammaRampLength(); - if (rampSize == 0) { - throw new LWJGLException("Display configuration not supported"); - } - FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize); - for (int i = 0; i < rampSize; i++) { - float intensity = (float)i/(rampSize - 1); - // apply gamma - float rampEntry = (float)java.lang.Math.pow(intensity, gamma); - // apply brightness - rampEntry += brightness; - // apply contrast - rampEntry = (rampEntry - 0.5f)*contrast + 0.5f; - // Clamp entry to [0, 1] - if (rampEntry > 1.0f) - rampEntry = 1.0f; - else if (rampEntry < 0.0f) - rampEntry = 0.0f; - gammaRamp.put(i, rampEntry); - } - display_impl.setGammaRamp(gammaRamp); - LWJGLUtil.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast); } /** @@ -342,14 +352,16 @@ * @param fps The desired frame rate, in frames per second */ public static void sync3(int fps) { - float frameTime = 1.0f / (fps > 1 ? fps - 1 : 1); - timeNow = Sys.getTime(); - while (timeNow > timeThen && (float) (timeNow - timeThen) / (float) Sys.getTimerResolution() < frameTime) { - // This is a system-friendly way of allowing other stuff to use CPU if it wants to - Thread.yield(); + synchronized (GlobalLock.lock) { + float frameTime = 1.0f / (fps > 1 ? fps - 1 : 1); timeNow = Sys.getTime(); + while (timeNow > timeThen && (float) (timeNow - timeThen) / (float) Sys.getTimerResolution() < frameTime) { + // This is a system-friendly way of allowing other stuff to use CPU if it wants to + Thread.yield(); + timeNow = Sys.getTime(); + } + timeThen = timeNow; } - timeThen = timeNow; } private static long timeLate; @@ -360,20 +372,22 @@ * @param fps The desired frame rate, in frames per second */ public static void sync2(int fps) { - long gapTo = Sys.getTimerResolution() / fps + timeThen; - timeNow = Sys.getTime(); - - while (gapTo > timeNow + timeLate) { - Thread.yield(); + synchronized (GlobalLock.lock) { + long gapTo = Sys.getTimerResolution() / fps + timeThen; timeNow = Sys.getTime(); - } - if (gapTo < timeNow) - timeLate = timeNow - gapTo; - else - timeLate = 0; + while (gapTo > timeNow + timeLate) { + Thread.yield(); + timeNow = Sys.getTime(); + } - timeThen = timeNow; + if (gapTo < timeNow) + timeLate = timeNow - gapTo; + else + timeLate = 0; + + timeThen = timeNow; + } } /** @@ -382,23 +396,25 @@ * @param fps The desired frame rate, in frames per second */ public static void sync(int fps) { - long gapTo = Sys.getTimerResolution() / fps + timeThen; - timeNow = Sys.getTime(); + synchronized (GlobalLock.lock) { + long gapTo = Sys.getTimerResolution() / fps + timeThen; + timeNow = Sys.getTime(); - while (gapTo > timeNow + timeLate) { - try { - Thread.sleep(1); - } catch (InterruptedException e) { + while (gapTo > timeNow + timeLate) { + try { + Thread.sleep(1); + } catch (InterruptedException e) { + } + timeNow = Sys.getTime(); } - timeNow = Sys.getTime(); - } - if (gapTo < timeNow) - timeLate = timeNow - gapTo; - else - timeLate = 0; + if (gapTo < timeNow) + timeLate = timeNow - gapTo; + else + timeLate = 0; - timeThen = timeNow; + timeThen = timeNow; + } } /** @@ -420,13 +436,17 @@ * @return the title of the window */ public static String getTitle() { - return title; + synchronized (GlobalLock.lock) { + return title; + } } private static void resetFullscreen() { - if (Display.fullscreen) { - Display.fullscreen = false; - display_impl.resetDisplayMode(); + synchronized (GlobalLock.lock) { + if (Display.fullscreen) { + Display.fullscreen = false; + display_impl.resetDisplayMode(); + } } } @@ -442,24 +462,26 @@ * from getAvailableDisplayModes() or if the mode switch fails. */ public static void setFullscreen(boolean fullscreen) throws LWJGLException { - if (Display.fullscreen != fullscreen) { - Display.fullscreen = fullscreen; - if (!isCreated()) - return; - destroyWindow(); - try { - if (fullscreen) { - switchDisplayMode(); - } else { + synchronized (GlobalLock.lock) { + if (Display.fullscreen != fullscreen) { + Display.fullscreen = fullscreen; + if (!isCreated()) + return; + destroyWindow(); + try { + if (fullscreen) { + switchDisplayMode(); + } else { + display_impl.resetDisplayMode(); + } + createWindow(); + makeCurrent(); + } catch (LWJGLException e) { + destroyContext(); + destroyPeerInfo(); display_impl.resetDisplayMode(); + throw e; } - createWindow(); - makeCurrent(); - } catch (LWJGLException e) { - destroyContext(); - destroyPeerInfo(); - display_impl.resetDisplayMode(); - throw e; } } } @@ -468,7 +490,9 @@ * @return whether the Display is in fullscreen mode */ public static boolean isFullscreen() { - return fullscreen; + synchronized (GlobalLock.lock) { + return fullscreen; + } } /** @@ -476,42 +500,50 @@ * @param newTitle The new window title */ public static void setTitle(String newTitle) { - if (newTitle == null) { - newTitle = ""; + synchronized (GlobalLock.lock) { + if (newTitle == null) { + newTitle = ""; + } + title = newTitle; + if (isCreated()) + display_impl.setTitle(title); } - title = newTitle; - if (isCreated()) - display_impl.setTitle(title); } /** * @return true if the user or operating system has asked the window to close */ public static boolean isCloseRequested() { - if (!isCreated()) - throw new IllegalStateException("Cannot determine close requested state of uncreated window"); - display_impl.update(); - return display_impl.isCloseRequested(); + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Cannot determine close requested state of uncreated window"); + display_impl.update(); + return display_impl.isCloseRequested(); + } } /** * @return true if the window is visible, false if not */ public static boolean isVisible() { - if (!isCreated()) - throw new IllegalStateException("Cannot determine minimized state of uncreated window"); - display_impl.update(); - return display_impl.isVisible(); + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Cannot determine minimized state of uncreated window"); + display_impl.update(); + return display_impl.isVisible(); + } } /** * @return true if window is active, that is, the foreground display of the operating system. */ public static boolean isActive() { - if (!isCreated()) - throw new IllegalStateException("Cannot determine focused state of uncreated window"); - display_impl.update(); - return display_impl.isActive(); + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Cannot determine focused state of uncreated window"); + display_impl.update(); + return display_impl.isActive(); + } } /** @@ -525,10 +557,12 @@ * and needs to repaint itself */ public static boolean isDirty() { - if (!isCreated()) - throw new IllegalStateException("Cannot determine dirty state of uncreated window"); - display_impl.update(); - return display_impl.isDirty(); + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Cannot determine dirty state of uncreated window"); + display_impl.update(); + return display_impl.isDirty(); + } } /** @@ -537,10 +571,12 @@ * the application. */ public static void processMessages() { - if (!isCreated()) - throw new IllegalStateException("Display not created"); + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display not created"); - display_impl.update(); + display_impl.update(); + } } /** @@ -549,11 +585,13 @@ * @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError() */ public static void swapBuffers() throws LWJGLException { - if (!isCreated()) - throw new IllegalStateException("Display not created"); + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display not created"); - Util.checkGLError(); - Context.swapBuffers(); + Util.checkGLError(); + Context.swapBuffers(); + } } /** @@ -562,20 +600,22 @@ * @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError() */ public static void update() { - if (!isCreated()) - throw new IllegalStateException("Display not created"); + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display not created"); - // We paint only when the window is visible or dirty - if (isVisible() || isDirty()) { - try { - swapBuffers(); - } catch (LWJGLException e) { - throw new RuntimeException(e); + // We paint only when the window is visible or dirty + if (isVisible() || isDirty()) { + try { + swapBuffers(); + } catch (LWJGLException e) { + throw new RuntimeException(e); + } } + + processMessages(); + pollDevices(); } - - processMessages(); - pollDevices(); } static void pollDevices() { @@ -600,10 +640,12 @@ * @throws LWJGLException If the context could not be released */ public static void releaseContext() throws LWJGLException { - if (!isCreated()) - throw new IllegalStateException("Display is not created"); - if (context.isCurrent()) - Context.releaseCurrentContext(); + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display is not created"); + if (context.isCurrent()) + Context.releaseCurrentContext(); + } } /** @@ -612,9 +654,11 @@ * @throws LWJGLException If the context could not be made current */ public static void makeCurrent() throws LWJGLException { - if (!isCreated()) - throw new IllegalStateException("Display is not created"); - context.makeCurrent(); + synchronized (GlobalLock.lock) { + if (!isCreated()) + throw new IllegalStateException("Display is not created"); + context.makeCurrent(); + } } /** @@ -629,7 +673,9 @@ * @throws LWJGLException */ public static void create() throws LWJGLException { - create(new PixelFormat()); + synchronized (GlobalLock.lock) { + create(new PixelFormat()); + } } /** @@ -645,7 +691,9 @@ * @throws LWJGLException */ public static void create(PixelFormat pixel_format) throws LWJGLException { - create(pixel_format, null); + synchronized (GlobalLock.lock) { + create(pixel_format, null); + } } private static void removeShutdownHook() { @@ -680,38 +728,40 @@ * @throws LWJGLException */ public static void create(PixelFormat pixel_format, Drawable shared_drawable) throws LWJGLException { - if (isCreated()) - throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time."); - if (pixel_format == null) - throw new NullPointerException("pixel_format cannot be null"); - removeShutdownHook(); - registerShutdownHook(); - if (fullscreen) - switchDisplayMode(); - try { - peer_info = display_impl.createPeerInfo(pixel_format); + synchronized (GlobalLock.lock) { + if (isCreated()) + throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time."); + if (pixel_format == null) + throw new NullPointerException("pixel_format cannot be null"); + removeShutdownHook(); + registerShutdownHook(); + if (fullscreen) + switchDisplayMode(); try { - createWindow(); + peer_info = display_impl.createPeerInfo(pixel_format); try { - context = new Context(peer_info, shared_drawable != null ? shared_drawable.getContext() : null); + createWindow(); try { - makeCurrent(); - initContext(); + context = new Context(peer_info, shared_drawable != null ? shared_drawable.getContext() : null); + try { + makeCurrent(); + initContext(); + } catch (LWJGLException e) { + destroyContext(); + throw e; + } } catch (LWJGLException e) { - destroyContext(); + destroyWindow(); throw e; } } catch (LWJGLException e) { - destroyWindow(); + destroyPeerInfo(); throw e; } } catch (LWJGLException e) { - destroyPeerInfo(); + display_impl.resetDisplayMode(); throw e; } - } catch (LWJGLException e) { - display_impl.resetDisplayMode(); - throw e; } } @@ -779,17 +829,19 @@ * regardless of whether the Display was the current rendering context. */ public static void destroy() { - if (!isCreated()) { - return; + synchronized (GlobalLock.lock) { + if (!isCreated()) { + return; + } + + destroyWindow(); + destroyContext(); + destroyPeerInfo(); + x = y = -1; + cached_icons = null; + reset(); + removeShutdownHook(); } - - destroyWindow(); - destroyContext(); - destroyPeerInfo(); - x = y = -1; - cached_icons = null; - reset(); - removeShutdownHook(); } private static void destroyPeerInfo() { @@ -819,7 +871,7 @@ /** * @return the unique Display context (or null, if the Display has not been created) */ - public static Context getContext() { + private static Context getContext() { return context; } @@ -827,7 +879,9 @@ * @return true if the window's native peer has been created */ public static boolean isCreated() { - return window_created; + synchronized (GlobalLock.lock) { + return window_created; + } } /** @@ -840,9 +894,11 @@ * @param sync true to synchronize; false to ignore synchronization */ public static void setSwapInterval(int value) { - swap_interval = value; - if (isCreated()) - Context.setSwapInterval(swap_interval); + synchronized (GlobalLock.lock) { + swap_interval = value; + if (isCreated()) + Context.setSwapInterval(swap_interval); + } } @@ -852,7 +908,9 @@ * @param sync true to synchronize; false to ignore synchronization */ public static void setVSyncEnabled(boolean sync) { - setSwapInterval(sync ? 1 : 0); + synchronized (GlobalLock.lock) { + setSwapInterval(sync ? 1 : 0); + } } /** @@ -864,19 +922,21 @@ * @param x The new window location on the x axis * @param y The new window location on the y axis */ - public static void setLocation(int x, int y) { - if (fullscreen) { - return; - } + public static void setLocation(int new_x, int new_y) { + synchronized (GlobalLock.lock) { + if (fullscreen) { + return; + } - // offset if already created - if(isCreated()) { - display_impl.reshape(x, y, current_mode.getWidth(), current_mode.getHeight()); + // cache position + x = new_x; + y = new_y; + + // offset if already created + if(isCreated()) { + display_impl.reshape(x, y, current_mode.getWidth(), current_mode.getHeight()); + } } - - // cache position - Display.x = x; - Display.y = y; } /** @@ -885,7 +945,9 @@ * @return a String */ public static String getAdapter() { - return display_impl.getAdapter(); + synchronized (GlobalLock.lock) { + return display_impl.getAdapter(); + } } /** @@ -894,7 +956,9 @@ * @return a String */ public static String getVersion() { - return display_impl.getVersion(); + synchronized (GlobalLock.lock) { + return display_impl.getVersion(); + } } @@ -915,22 +979,23 @@ * @return number of icons used, or 0 if display hasn't been created */ public static int setIcon(ByteBuffer[] icons) { - - // make deep copy so we dont rely on the supplied buffers later on - // don't recache! - if(cached_icons != icons) { - cached_icons = new ByteBuffer[icons.length]; - for(int i=0;i<icons.length; i++) { - cached_icons[i] = BufferUtils.createByteBuffer(icons[i].capacity()); - cached_icons[i].put(icons[i]); - cached_icons[i].flip(); + synchronized (GlobalLock.lock) { + // make deep copy so we dont rely on the supplied buffers later on + // don't recache! + if(cached_icons != icons) { + cached_icons = new ByteBuffer[icons.length]; + for(int i=0;i<icons.length; i++) { + cached_icons[i] = BufferUtils.createByteBuffer(icons[i].capacity()); + cached_icons[i].put(icons[i]); + cached_icons[i].flip(); + } } + + if(Display.isCreated()) { + return display_impl.setIcon(cached_icons); + } else { + return 0; + } } - - if(Display.isCreated()) { - return display_impl.setIcon(cached_icons); - } else { - return 0; - } } } Added: trunk/LWJGL/src/java/org/lwjgl/opengl/GlobalLock.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/GlobalLock.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/GlobalLock.java 2007-02-12 12:18:26 UTC (rev 2739) @@ -0,0 +1,9 @@ +package org.lwjgl.opengl; + +/** + * This class contains the global lock that LWJGL will use to + * synchronize access to Display. + */ +final class GlobalLock { + final static Object lock = new Object(); +} Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2007-02-08 22:00:51 UTC (rev 2738) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2007-02-12 12:18:26 UTC (rev 2739) @@ -247,13 +247,13 @@ */ if (Display.isFullscreen() && (frame.getCanvas().syncCanvasPainted() || should_update)) { try { - MacOSXContextImplementation.resetView(Display.getContext().getPeerInfo(), Display.getContext()); + MacOSXContextImplementation.resetView(Display.getDrawable().getContext().getPeerInfo(), Display.getDrawable().getContext()); } catch (LWJGLException e) { LWJGLUtil.log("Failed to reset context: " + e); } } if (should_update) { - Display.getContext().update(); + Display.getDrawable().getContext().update(); /* This is necessary to make sure the context won't "forget" about the view size */ GL11.glGetInteger(GL11.GL_VIEWPORT, current_viewport); GL11.glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3)); Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-02-08 22:00:51 UTC (rev 2738) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-02-12 12:18:26 UTC (rev 2739) @@ -304,8 +304,8 @@ * is maximized helps some gfx recover from fullscreen */ try { - if (Display.getContext() != null && Display.getContext().isCurrent()) - Display.getContext().makeCurrent(); + if (Display.getDrawable().getContext() != null && Display.getDrawable().getContext().isCurrent()) + Display.getDrawable().getContext().makeCurrent(); } catch (LWJGLException e) { LWJGLUtil.log("Exception occurred while trying to make context current: " + e); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-04-11 16:13:08
|
Revision: 2762 http://svn.sourceforge.net/java-game-lib/?rev=2762&view=rev Author: elias_naur Date: 2007-04-11 09:13:05 -0700 (Wed, 11 Apr 2007) Log Message: ----------- Moved null check from generated code to BufferChecks and removed unused buffer checks Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java Modified: trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2007-04-08 21:33:35 UTC (rev 2761) +++ trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2007-04-11 16:13:05 UTC (rev 2762) @@ -124,23 +124,6 @@ /** * Helper methods to ensure a buffer is direct (and, implicitly, non-null). */ - public static void checkDirectBuffer(Buffer buf) { - if (buf instanceof FloatBuffer) - checkDirect((FloatBuffer)buf); - else if (buf instanceof ByteBuffer) - checkDirect((ByteBuffer)buf); - else if (buf instanceof ShortBuffer) - checkDirect((ShortBuffer)buf); - else if (buf instanceof IntBuffer) - checkDirect((IntBuffer)buf); - else if (buf instanceof LongBuffer) - checkDirect((LongBuffer)buf); - else if (buf instanceof DoubleBuffer) - checkDirect((DoubleBuffer)buf); - else - throw new IllegalStateException("Unsupported buffer type"); - } - public static void checkDirect(ByteBuffer buf) { if (!buf.isDirect()) { throw new IllegalArgumentException("ByteBuffer is not direct"); @@ -231,36 +214,41 @@ } /** - * Helper methods to ensure a buffer is big enough to receive data from a - * glGet* operation. To avoid unnecessarily complex buffer size checking - * we've just set the bar artificially high and insist that any receiving - * buffer has at least 4 remaining(). - * - * @param buf - * The buffer to check - * @throws IllegalArgumentException + * Helper methods to ensure a buffer is direct, has a minimum size or null. */ - public static void checkBuffer(ByteBuffer buf) { - checkBuffer(buf, DEFAULT_BUFFER_SIZE); + public static void checkBufferOrNull(ByteBuffer buf, int size) { + if (buf != null) { + checkBuffer(buf, size); + } } - public static void checkBuffer(ShortBuffer buf) { - checkBuffer(buf, DEFAULT_BUFFER_SIZE); + public static void checkBufferOrNull(ShortBuffer buf, int size) { + if (buf != null) { + checkBuffer(buf, size); + } } - public static void checkBuffer(IntBuffer buf) { - checkBuffer(buf, DEFAULT_BUFFER_SIZE); + public static void checkBufferOrNull(IntBuffer buf, int size) { + if (buf != null) { + checkBuffer(buf, size); + } } - public static void checkBuffer(LongBuffer buf) { - checkBuffer(buf, DEFAULT_BUFFER_SIZE); + public static void checkBufferOrNull(LongBuffer buf, int size) { + if (buf != null) { + checkBuffer(buf, size); + } } - public static void checkBuffer(FloatBuffer buf) { - checkBuffer(buf, DEFAULT_BUFFER_SIZE); + public static void checkBufferOrNull(FloatBuffer buf, int size) { + if (buf != null) { + checkBuffer(buf, size); + } } - public static void checkBuffer(DoubleBuffer buf) { - checkBuffer(buf, DEFAULT_BUFFER_SIZE); + public static void checkBufferOrNull(DoubleBuffer buf, int size) { + if (buf != null) { + checkBuffer(buf, size); + } } } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2007-04-08 21:33:35 UTC (rev 2761) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2007-04-11 16:13:05 UTC (rev 2762) @@ -437,15 +437,16 @@ } private static void printParameterCheck(PrintWriter writer, String name, String check_value, boolean can_be_null, boolean null_terminated) { - if (can_be_null) { - writer.println("\t\tif (" + name + " != null)"); - writer.print("\t"); - } writer.print("\t\tBufferChecks.check"); if (check_value != null && !"".equals(check_value) ) { - writer.print("Buffer(" + name + ", " + check_value); + writer.print("Buffer"); + if (can_be_null) + writer.print("OrNull"); + writer.print("(" + name + ", " + check_value); } else { writer.print("Direct"); + if (can_be_null) + writer.print("OrNull"); writer.print("(" + name); } writer.println(");"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-04-11 17:30:15
|
Revision: 2763 http://svn.sourceforge.net/java-game-lib/?rev=2763&view=rev Author: elias_naur Date: 2007-04-11 10:30:13 -0700 (Wed, 11 Apr 2007) Log Message: ----------- Added support for non-direct buffers for all functions that doesn't cache the buffer address at the native side (e.g. glVertexPointer). Reasons: 1. We can now support calls like "glLight(..., ..., FloatBuffer.wrap(new float[] {...}));" without worrying about running out of direct memory heap, since both the FloatBuffer and the array are allocated on the java heap. Future JVMs with stack allocation support could improve this even further. 2. We avoid getting in the way of users that doesn't (yet) know why direct buffers are important. Obviously, we'd like direct support for arrays, but non-direct buffers are a nice compromise that avoids the API bloat that results when almost all functions gain an overloaded versions that take arrays instead of buffers. Notes: 1. Non-direct buffer support should not affect the performance in the direct buffer case, since the non-direct buffer code path is only activated when the isDirect() check fails, and we were already checking isDirect() for sanity checking. 2. When using non-direct buffers, the buffer contents (remaining() bytes) are copied to a resizable ThreadLocal cached direct buffer (which is resized as needed) and used instead of the non-direct buffer. Thus, performance of non-direct buffers is lower than direct buffers. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/Gears.java trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java Modified: trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2007-04-11 16:13:05 UTC (rev 2762) +++ trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2007-04-11 17:30:13 UTC (rev 2763) @@ -43,6 +43,8 @@ * <p>A class to check buffer boundaries in general. If there is unsufficient space * in the buffer when the call is made then a buffer overflow would otherwise * occur and cause unexpected behaviour, a crash, or worse, a security risk. + * + * Internal class, don't use. * </p> * @author cix_foo <ci...@us...> * @author elias_naur <eli...@us...> @@ -177,7 +179,7 @@ * The minimum buffer size * @throws IllegalArgumentException */ - private static void checkBufferSize(Buffer buf, int size) { + public static void checkBufferSize(Buffer buf, int size) { if (buf.remaining() < size) { throwBufferSizeException(buf, size); } Added: trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java 2007-04-11 17:30:13 UTC (rev 2763) @@ -0,0 +1,301 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl; + +import java.nio.ByteBuffer; +import java.nio.ShortBuffer; +import java.nio.IntBuffer; +import java.nio.FloatBuffer; +import java.nio.LongBuffer; +import java.nio.DoubleBuffer; +import java.nio.ByteOrder; + +/** + * Utility class to cache thread local direct buffers so when we are passed a non-direct buffer, + * we can put its contents into a cached direct buffer and use that at the native side instead. + * + * Internal class, don't use. + * @author elias_naur <eli...@us...> + * @version $Revision: 2762 $ + * $Id: BufferChecks.java 2762 2007-04-11 16:13:05Z elias_naur $ + */ +public final class NondirectBufferWrapper { + private final static int INITIAL_BUFFER_SIZE = 1; + + private final static ThreadLocal thread_buffer = new ThreadLocal() { + protected final Object initialValue() { + return new CachedBuffers(INITIAL_BUFFER_SIZE); + } + }; + + private static CachedBuffers getCachedBuffers(int minimum_byte_size) { + CachedBuffers buffers = (CachedBuffers)thread_buffer.get(); + int current_byte_size = buffers.byte_buffer.capacity(); + if (minimum_byte_size > current_byte_size) { + buffers = new CachedBuffers(minimum_byte_size); + thread_buffer.set(buffers); + } + return buffers; + } + + public static ByteBuffer wrapBufferOrNull(ByteBuffer buf, int size) { + if (buf != null) + return wrapBuffer(buf, size); + return buf; + } + + public static ShortBuffer wrapBufferOrNull(ShortBuffer buf, int size) { + if (buf != null) + return wrapBuffer(buf, size); + return buf; + } + + public static IntBuffer wrapBufferOrNull(IntBuffer buf, int size) { + if (buf != null) + return wrapBuffer(buf, size); + return buf; + } + + public static LongBuffer wrapBufferOrNull(LongBuffer buf, int size) { + if (buf != null) + return wrapBuffer(buf, size); + return buf; + } + + public static FloatBuffer wrapBufferOrNull(FloatBuffer buf, int size) { + if (buf != null) + return wrapBuffer(buf, size); + return buf; + } + + public static DoubleBuffer wrapBufferOrNull(DoubleBuffer buf, int size) { + if (buf != null) + return wrapBuffer(buf, size); + return buf; + } + + public static ByteBuffer wrapBuffer(ByteBuffer buf, int size) { + BufferChecks.checkBufferSize(buf, size); + return wrapDirect(buf); + } + + public static ShortBuffer wrapBuffer(ShortBuffer buf, int size) { + BufferChecks.checkBufferSize(buf, size); + return wrapDirect(buf); + } + + public static IntBuffer wrapBuffer(IntBuffer buf, int size) { + BufferChecks.checkBufferSize(buf, size); + return wrapDirect(buf); + } + + public static LongBuffer wrapBuffer(LongBuffer buf, int size) { + BufferChecks.checkBufferSize(buf, size); + return wrapDirect(buf); + } + + public static FloatBuffer wrapBuffer(FloatBuffer buf, int size) { + BufferChecks.checkBufferSize(buf, size); + return wrapDirect(buf); + } + + public static DoubleBuffer wrapBuffer(DoubleBuffer buf, int size) { + BufferChecks.checkBufferSize(buf, size); + return wrapDirect(buf); + } + + public static ByteBuffer wrapDirectOrNull(ByteBuffer buffer) { + if (buffer != null) + return wrapDirect(buffer); + return buffer; + } + + public static ShortBuffer wrapDirectOrNull(ShortBuffer buffer) { + if (buffer != null) + return wrapDirect(buffer); + return buffer; + } + + public static FloatBuffer wrapDirectOrNull(FloatBuffer buffer) { + if (buffer != null) + return wrapDirect(buffer); + return buffer; + } + + public static IntBuffer wrapDirectOrNull(IntBuffer buffer) { + if (buffer != null) + return wrapDirect(buffer); + return buffer; + } + + public static LongBuffer wrapDirectOrNull(LongBuffer buffer) { + if (buffer != null) + return wrapDirect(buffer); + return buffer; + } + + public static DoubleBuffer wrapDirectOrNull(DoubleBuffer buffer) { + if (buffer != null) + return wrapDirect(buffer); + return buffer; + } + + public static ByteBuffer wrapDirect(ByteBuffer buffer) { + if (!buffer.isDirect()) + return doWrap(buffer); + return buffer; + } + + public static ShortBuffer wrapDirect(ShortBuffer buffer) { + if (!buffer.isDirect()) + return doWrap(buffer); + return buffer; + } + + public static FloatBuffer wrapDirect(FloatBuffer buffer) { + if (!buffer.isDirect()) + return doWrap(buffer); + return buffer; + } + + public static IntBuffer wrapDirect(IntBuffer buffer) { + if (!buffer.isDirect()) + return doWrap(buffer); + return buffer; + } + + public static LongBuffer wrapDirect(LongBuffer buffer) { + if (!buffer.isDirect()) + return doWrap(buffer); + return buffer; + } + + public static DoubleBuffer wrapDirect(DoubleBuffer buffer) { + if (!buffer.isDirect()) + return doWrap(buffer); + return buffer; + } + + private static ByteBuffer doWrap(ByteBuffer buffer) { + ByteBuffer direct_buffer = getCachedBuffers(buffer.remaining()).byte_buffer; + direct_buffer.clear(); + int saved_position = buffer.position(); + direct_buffer.put(buffer); + buffer.position(saved_position); + direct_buffer.flip(); + return direct_buffer; + } + + private static ShortBuffer doWrap(ShortBuffer buffer) { + CachedBuffers buffers = getCachedBuffers(buffer.remaining()*2); + ShortBuffer direct_buffer = buffer.order() == ByteOrder.LITTLE_ENDIAN ? buffers.short_buffer_little : buffers.short_buffer_big; + direct_buffer.clear(); + int saved_position = buffer.position(); + direct_buffer.put(buffer); + buffer.position(saved_position); + direct_buffer.flip(); + return direct_buffer; + } + + private static FloatBuffer doWrap(FloatBuffer buffer) { + CachedBuffers buffers = getCachedBuffers(buffer.remaining()*4); + FloatBuffer direct_buffer = buffer.order() == ByteOrder.LITTLE_ENDIAN ? buffers.float_buffer_little : buffers.float_buffer_big; + direct_buffer.clear(); + int saved_position = buffer.position(); + direct_buffer.put(buffer); + buffer.position(saved_position); + direct_buffer.flip(); + return direct_buffer; + } + + private static IntBuffer doWrap(IntBuffer buffer) { + CachedBuffers buffers = getCachedBuffers(buffer.remaining()*4); + IntBuffer direct_buffer = buffer.order() == ByteOrder.LITTLE_ENDIAN ? buffers.int_buffer_little : buffers.int_buffer_big; + direct_buffer.clear(); + int saved_position = buffer.position(); + direct_buffer.put(buffer); + buffer.position(saved_position); + direct_buffer.flip(); + return direct_buffer; + } + + private static LongBuffer doWrap(LongBuffer buffer) { + CachedBuffers buffers = getCachedBuffers(buffer.remaining()*8); + LongBuffer direct_buffer = buffer.order() == ByteOrder.LITTLE_ENDIAN ? buffers.long_buffer_little : buffers.long_buffer_big; + direct_buffer.clear(); + int saved_position = buffer.position(); + direct_buffer.put(buffer); + buffer.position(saved_position); + direct_buffer.flip(); + return direct_buffer; + } + + private static DoubleBuffer doWrap(DoubleBuffer buffer) { + CachedBuffers buffers = getCachedBuffers(buffer.remaining()*8); + DoubleBuffer direct_buffer = buffer.order() == ByteOrder.LITTLE_ENDIAN ? buffers.double_buffer_little : buffers.double_buffer_big; + direct_buffer.clear(); + int saved_position = buffer.position(); + direct_buffer.put(buffer); + buffer.position(saved_position); + direct_buffer.flip(); + return direct_buffer; + } + + private final static class CachedBuffers { + private final ByteBuffer byte_buffer; + private final ShortBuffer short_buffer_big; + private final IntBuffer int_buffer_big; + private final FloatBuffer float_buffer_big; + private final LongBuffer long_buffer_big; + private final DoubleBuffer double_buffer_big; + private final ShortBuffer short_buffer_little; + private final IntBuffer int_buffer_little; + private final FloatBuffer float_buffer_little; + private final LongBuffer long_buffer_little; + private final DoubleBuffer double_buffer_little; + + private CachedBuffers(int size) { + this.byte_buffer = ByteBuffer.allocateDirect(size); + this.short_buffer_big = byte_buffer.asShortBuffer(); + this.int_buffer_big = byte_buffer.asIntBuffer(); + this.float_buffer_big = byte_buffer.asFloatBuffer(); + this.long_buffer_big = byte_buffer.asLongBuffer(); + this.double_buffer_big = byte_buffer.asDoubleBuffer(); + this.byte_buffer.order(ByteOrder.LITTLE_ENDIAN); + this.short_buffer_little = byte_buffer.asShortBuffer(); + this.int_buffer_little = byte_buffer.asIntBuffer(); + this.float_buffer_little = byte_buffer.asFloatBuffer(); + this.long_buffer_little = byte_buffer.asLongBuffer(); + this.double_buffer_little = byte_buffer.asDoubleBuffer(); + } + } +} Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/Gears.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/Gears.java 2007-04-11 16:13:05 UTC (rev 2762) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/Gears.java 2007-04-11 17:30:13 UTC (rev 2763) @@ -156,18 +156,14 @@ Display.setLocation((Display.getDisplayMode().getWidth() - 300) / 2, (Display.getDisplayMode().getHeight() - 300) / 2); Display.setDisplayMode(new DisplayMode(300, 300)); - Display.setTitle("Gears"); + Display.setTitle("Gears"); Display.create(); // setup ogl - FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f}); - FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f}); - FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] { 0.0f, 0.8f, 0.2f, 1.0f}); - FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] { 0.2f, 0.2f, 1.0f, 1.0f}); - pos.flip(); - red.flip(); - green.flip(); - blue.flip(); + FloatBuffer pos = FloatBuffer.wrap(new float[] { 5.0f, 5.0f, 10.0f, 0.0f}); + FloatBuffer red = FloatBuffer.wrap(new float[] { 0.8f, 0.1f, 0.0f, 1.0f}); + FloatBuffer green = FloatBuffer.wrap(new float[] { 0.0f, 0.8f, 0.2f, 1.0f}); + FloatBuffer blue = FloatBuffer.wrap(new float[] { 0.2f, 0.2f, 1.0f, 1.0f}); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos); GL11.glEnable(GL11.GL_CULL_FACE); Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java 2007-04-11 16:13:05 UTC (rev 2762) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java 2007-04-11 17:30:13 UTC (rev 2763) @@ -171,6 +171,7 @@ java_writer.println(); java_writer.println("import org.lwjgl.LWJGLException;"); java_writer.println("import org.lwjgl.BufferChecks;"); + java_writer.println("import org.lwjgl.NondirectBufferWrapper;"); java_writer.println("import java.nio.*;"); java_writer.println(); java_writer.print("public "); Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2007-04-11 16:13:05 UTC (rev 2762) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2007-04-11 17:30:13 UTC (rev 2763) @@ -425,7 +425,8 @@ } boolean null_terminated = param.getAnnotation(NullTerminated.class) != null; if (Buffer.class.isAssignableFrom(java_type)) { - printParameterCheck(writer, param.getSimpleName(), check_value, can_be_null, null_terminated); + boolean indirect_buffer_allowed = param.getAnnotation(CachedReference.class) == null; + printParameterCheck(writer, param.getSimpleName(), check_value, can_be_null, null_terminated, indirect_buffer_allowed); } else if (String.class.equals(java_type)) { if (!can_be_null) writer.println("\t\tBufferChecks.checkNotNull(" + param.getSimpleName() + ");"); @@ -433,11 +434,14 @@ } } if (method.getAnnotation(CachedResult.class) != null) - printParameterCheck(writer, Utils.CACHED_BUFFER_NAME, null, true, false); + printParameterCheck(writer, Utils.CACHED_BUFFER_NAME, null, true, false, false); } - private static void printParameterCheck(PrintWriter writer, String name, String check_value, boolean can_be_null, boolean null_terminated) { - writer.print("\t\tBufferChecks.check"); + private static void printParameterCheck(PrintWriter writer, String name, String check_value, boolean can_be_null, boolean null_terminated, boolean indirect_buffer_allowed) { + if (indirect_buffer_allowed) + writer.print("\t\t" + name + " = NondirectBufferWrapper.wrap"); + else + writer.print("\t\tBufferChecks.check"); if (check_value != null && !"".equals(check_value) ) { writer.print("Buffer"); if (can_be_null) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-04-15 19:43:37
|
Revision: 2768 http://svn.sourceforge.net/java-game-lib/?rev=2768&view=rev Author: elias_naur Date: 2007-04-15 12:43:35 -0700 (Sun, 15 Apr 2007) Log Message: ----------- Move null parameter checks from check classes to the generated classes, since calculateImageSize assumes the buffer being non-null Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java Modified: trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2007-04-15 19:33:03 UTC (rev 2767) +++ trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2007-04-15 19:43:35 UTC (rev 2768) @@ -85,45 +85,6 @@ } /** - * Helper methods to ensure a buffer is direct or null. - */ - public static void checkDirectOrNull(ByteBuffer buf) { - if (buf != null) { - checkDirect(buf); - } - } - - public static void checkDirectOrNull(ShortBuffer buf) { - if (buf != null) { - checkDirect(buf); - } - } - - public static void checkDirectOrNull(IntBuffer buf) { - if (buf != null) { - checkDirect(buf); - } - } - - public static void checkDirectOrNull(LongBuffer buf) { - if (buf != null) { - checkDirect(buf); - } - } - - public static void checkDirectOrNull(FloatBuffer buf) { - if (buf != null) { - checkDirect(buf); - } - } - - public static void checkDirectOrNull(DoubleBuffer buf) { - if (buf != null) { - checkDirect(buf); - } - } - - /** * Helper methods to ensure a buffer is direct (and, implicitly, non-null). */ public static void checkDirect(ByteBuffer buf) { @@ -214,43 +175,4 @@ checkBufferSize(buf, size); checkDirect(buf); } - - /** - * Helper methods to ensure a buffer is direct, has a minimum size or null. - */ - public static void checkBufferOrNull(ByteBuffer buf, int size) { - if (buf != null) { - checkBuffer(buf, size); - } - } - - public static void checkBufferOrNull(ShortBuffer buf, int size) { - if (buf != null) { - checkBuffer(buf, size); - } - } - - public static void checkBufferOrNull(IntBuffer buf, int size) { - if (buf != null) { - checkBuffer(buf, size); - } - } - - public static void checkBufferOrNull(LongBuffer buf, int size) { - if (buf != null) { - checkBuffer(buf, size); - } - } - - public static void checkBufferOrNull(FloatBuffer buf, int size) { - if (buf != null) { - checkBuffer(buf, size); - } - } - - public static void checkBufferOrNull(DoubleBuffer buf, int size) { - if (buf != null) { - checkBuffer(buf, size); - } - } } Modified: trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java 2007-04-15 19:33:03 UTC (rev 2767) +++ trunk/LWJGL/src/java/org/lwjgl/NondirectBufferWrapper.java 2007-04-15 19:43:35 UTC (rev 2768) @@ -67,42 +67,6 @@ return buffers; } - public static ByteBuffer wrapBufferOrNull(ByteBuffer buf, int size) { - if (buf != null) - return wrapBuffer(buf, size); - return buf; - } - - public static ShortBuffer wrapBufferOrNull(ShortBuffer buf, int size) { - if (buf != null) - return wrapBuffer(buf, size); - return buf; - } - - public static IntBuffer wrapBufferOrNull(IntBuffer buf, int size) { - if (buf != null) - return wrapBuffer(buf, size); - return buf; - } - - public static LongBuffer wrapBufferOrNull(LongBuffer buf, int size) { - if (buf != null) - return wrapBuffer(buf, size); - return buf; - } - - public static FloatBuffer wrapBufferOrNull(FloatBuffer buf, int size) { - if (buf != null) - return wrapBuffer(buf, size); - return buf; - } - - public static DoubleBuffer wrapBufferOrNull(DoubleBuffer buf, int size) { - if (buf != null) - return wrapBuffer(buf, size); - return buf; - } - public static ByteBuffer wrapBuffer(ByteBuffer buf, int size) { BufferChecks.checkBufferSize(buf, size); return wrapDirect(buf); @@ -133,42 +97,6 @@ return wrapDirect(buf); } - public static ByteBuffer wrapDirectOrNull(ByteBuffer buffer) { - if (buffer != null) - return wrapDirect(buffer); - return buffer; - } - - public static ShortBuffer wrapDirectOrNull(ShortBuffer buffer) { - if (buffer != null) - return wrapDirect(buffer); - return buffer; - } - - public static FloatBuffer wrapDirectOrNull(FloatBuffer buffer) { - if (buffer != null) - return wrapDirect(buffer); - return buffer; - } - - public static IntBuffer wrapDirectOrNull(IntBuffer buffer) { - if (buffer != null) - return wrapDirect(buffer); - return buffer; - } - - public static LongBuffer wrapDirectOrNull(LongBuffer buffer) { - if (buffer != null) - return wrapDirect(buffer); - return buffer; - } - - public static DoubleBuffer wrapDirectOrNull(DoubleBuffer buffer) { - if (buffer != null) - return wrapDirect(buffer); - return buffer; - } - public static ByteBuffer wrapDirect(ByteBuffer buffer) { if (!buffer.isDirect()) return doWrap(buffer); Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2007-04-15 19:33:03 UTC (rev 2767) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2007-04-15 19:43:35 UTC (rev 2768) @@ -438,20 +438,18 @@ } private static void printParameterCheck(PrintWriter writer, String name, String check_value, boolean can_be_null, boolean null_terminated, boolean indirect_buffer_allowed) { + if (can_be_null) { + writer.println("\t\tif (" + name + " != null)"); + writer.print("\t"); + } if (indirect_buffer_allowed) writer.print("\t\t" + name + " = NondirectBufferWrapper.wrap"); else writer.print("\t\tBufferChecks.check"); if (check_value != null && !"".equals(check_value) ) { - writer.print("Buffer"); - if (can_be_null) - writer.print("OrNull"); - writer.print("(" + name + ", " + check_value); + writer.print("Buffer(" + name + ", " + check_value); } else { - writer.print("Direct"); - if (can_be_null) - writer.print("OrNull"); - writer.print("(" + name); + writer.print("Direct(" + name); } writer.println(");"); if (null_terminated) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-04-29 19:38:15
|
Revision: 2811 http://svn.sourceforge.net/java-game-lib/?rev=2811&view=rev Author: elias_naur Date: 2007-04-29 12:38:04 -0700 (Sun, 29 Apr 2007) Log Message: ----------- Removed Util.glGetInteger convenience method since it is not thread safe Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/Util.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/Shader.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Util.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Util.java 2007-04-29 11:06:40 UTC (rev 2810) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Util.java 2007-04-29 19:38:04 UTC (rev 2811) @@ -43,9 +43,6 @@ */ public final class Util { - - private static final IntBuffer int_buffer = BufferUtils.createIntBuffer(16); - /** No c'tor */ private Util() { } @@ -56,16 +53,4 @@ throw new OpenGLException(err); } } - - /** - * Obtain a GL integer value from the driver - * - * @param gl_enum The GL value you want - * - * @return the integer value - */ - public static int glGetInteger(int gl_enum) { - GL11.glGetInteger(gl_enum, int_buffer); - return int_buffer.get(0); - } } Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/Shader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/Shader.java 2007-04-29 11:06:40 UTC (rev 2810) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/Shader.java 2007-04-29 19:38:04 UTC (rev 2811) @@ -51,6 +51,7 @@ abstract class Shader { + private static final IntBuffer int_buffer = BufferUtils.createIntBuffer(16); protected static IntBuffer programBuffer = BufferUtils.createIntBuffer(1); protected static ByteBuffer fileBuffer = BufferUtils.createByteBuffer(1024 * 10); @@ -61,6 +62,18 @@ abstract void cleanup(); + /** + * Obtain a GL integer value from the driver + * + * @param gl_enum The GL value you want + * + * @return the integer value + */ + public static int glGetInteger(int gl_enum) { + GL11.glGetInteger(gl_enum, int_buffer); + return int_buffer.get(0); + } + protected static ByteBuffer getShaderText(String file) { ByteBuffer shader = null; @@ -99,7 +112,7 @@ final byte[] bytes = new byte[programSource.capacity()]; programSource.get(bytes); - final int errorPos = Util.glGetInteger(ARBProgram.GL_PROGRAM_ERROR_POSITION_ARB); + final int errorPos = glGetInteger(ARBProgram.GL_PROGRAM_ERROR_POSITION_ARB); int lineStart = 0; int lineEnd = -1; for ( int i = 0; i < bytes.length; i++ ) { @@ -185,4 +198,4 @@ System.out.println(new String(charArray, 0, logLength)); } -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-05-13 22:01:50
|
Revision: 2818 http://svn.sourceforge.net/java-game-lib/?rev=2818&view=rev Author: elias_naur Date: 2007-05-13 15:01:48 -0700 (Sun, 13 May 2007) Log Message: ----------- Implemented Keyboard.enableRepeatEvents(), Keyboard.areRepeatEventsEnabled() and Keyboard.isEventRepeat() to control repeat event reporting. Added repeat key test to KeyboardTest Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java trunk/LWJGL/src/java/org/lwjgl/test/input/KeyboardTest.java Modified: trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2007-05-13 21:11:53 UTC (rev 2817) +++ trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2007-05-13 22:01:48 UTC (rev 2818) @@ -57,7 +57,7 @@ */ public class Keyboard { /** Internal use - event size in bytes */ - public static final int EVENT_SIZE = 4 + 1 + 4 + 8; + public static final int EVENT_SIZE = 4 + 1 + 4 + 8 + 1; /** * The special character meaning that no @@ -239,6 +239,9 @@ /** Has the keyboard been created? */ private static boolean created; + /** Are repeat events enabled? */ + private static boolean repeat_enabled; + /** The keys status from the last poll */ private static final ByteBuffer keyDownBuffer = BufferUtils.createByteBuffer(KEYBOARD_SIZE); @@ -249,18 +252,12 @@ */ private static ByteBuffer readBuffer; - /** The current keyboard character being examined */ - private static int eventCharacter; + /** current event */ + private static KeyEvent current_event = new KeyEvent(); - /** The current keyboard event key being examined */ - private static int eventKey; + /** scratch event */ + private static KeyEvent tmp_event = new KeyEvent(); - /** The current state of the key being examined in the event queue */ - private static boolean eventState; - - /** The current event time */ - private static long eventNanos; - /** One time initialization */ private static boolean initialized; @@ -318,9 +315,7 @@ readBuffer.limit(0); for (int i = 0; i < keyDownBuffer.remaining(); i++) keyDownBuffer.put(i, (byte)0); - eventCharacter = 0; - eventKey = 0; - eventState = false; + current_event.reset(); } /** @@ -432,7 +427,12 @@ synchronized (OpenGLPackageAccess.global_lock) { if (!created) throw new IllegalStateException("Keyboard must be created before you can read events"); - return readBuffer.remaining()/EVENT_SIZE; + int old_position = readBuffer.position(); + int num_events = 0; + while (readNext(tmp_event) && (!tmp_event.repeat || repeat_enabled)) + num_events++; + readBuffer.position(old_position); + return num_events; } } @@ -452,19 +452,48 @@ if (!created) throw new IllegalStateException("Keyboard must be created before you can read events"); - if (readBuffer.hasRemaining()) { - eventKey = readBuffer.getInt() & 0xFF; - eventState = readBuffer.get() != 0; - eventCharacter = readBuffer.getInt(); - eventNanos = readBuffer.getLong(); - return true; - } else { - return false; - } + boolean result; + while ((result = readNext(current_event)) && current_event.repeat && !repeat_enabled) + ; + return result; } } /** + * Controls whether repeat events are reported or not. If repeat events + * are enabled, key down events are reported when a key is pressed and held for + * a OS dependent amount of time. To distinguish a repeat event from a normal event, + * use isRepeatEvent(). + * + * @see org.lwjgl.input.Keyboard#getEventKey() + */ + public static synchronized void enableRepeatEvents(boolean enable) { + repeat_enabled = enable; + } + + /** + * Check whether repeat events are currently reported or not. + * + * @return true is repeat events are reported, false if not. + * @see org.lwjgl.input.Keyboard#getEventKey() + */ + public static synchronized boolean areRepeatEventsEnabled() { + return repeat_enabled; + } + + private static boolean readNext(KeyEvent event) { + if (readBuffer.hasRemaining()) { + event.key = readBuffer.getInt() & 0xFF; + event.state = readBuffer.get() != 0; + event.character = readBuffer.getInt(); + event.nanos = readBuffer.getLong(); + event.repeat = readBuffer.get() == 1; + return true; + } else + return false; + } + + /** * @return Number of keys on this keyboard */ public static synchronized int getKeyCount() { @@ -478,7 +507,7 @@ */ public static synchronized char getEventCharacter() { synchronized (OpenGLPackageAccess.global_lock) { - return (char)eventCharacter; + return (char)current_event.character; } } @@ -491,7 +520,7 @@ */ public static synchronized int getEventKey() { synchronized (OpenGLPackageAccess.global_lock) { - return eventKey; + return current_event.key; } } @@ -503,7 +532,7 @@ */ public static synchronized boolean getEventKeyState() { synchronized (OpenGLPackageAccess.global_lock) { - return eventState; + return current_event.state; } } @@ -516,7 +545,42 @@ */ public static synchronized long getEventNanoseconds() { synchronized (OpenGLPackageAccess.global_lock) { - return eventNanos; + return current_event.nanos; } } + + /** + * @see org.lwjgl.input.Keyboard#enableRepeatEvents() + * @return true if the current event is a repeat event, false if + * the current event is not a repeat even or if repeat events are disabled. + */ + public static synchronized boolean isRepeatEvent() { + synchronized (OpenGLPackageAccess.global_lock) { + return current_event.repeat; + } + } + + private final static class KeyEvent { + /** The current keyboard character being examined */ + private int character; + + /** The current keyboard event key being examined */ + private int key; + + /** The current state of the key being examined in the event queue */ + private boolean state; + + /** The current event time */ + private long nanos; + + /** Is the current event a repeated event? */ + private boolean repeat; + + private void reset() { + character = 0; + key = 0; + state = false; + repeat = false; + } + } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java 2007-05-13 21:11:53 UTC (rev 2817) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java 2007-05-13 22:01:48 UTC (rev 2818) @@ -264,9 +264,9 @@ //component.removeKeyListener(this); } - private void putKeyboardEvent(int key_code, byte state, int character, long nanos) { + private void putKeyboardEvent(int key_code, byte state, int character, long nanos, boolean repeat) { event.clear(); - event.putInt(key_code).put(state).putInt(character).putLong(nanos); + event.putInt(key_code).put(state).putInt(character).putLong(nanos).put(repeat ? (byte)1 : (byte)0); event.flip(); putEvent(event); } @@ -287,15 +287,16 @@ if (character == KeyEvent.CHAR_UNDEFINED) character = Keyboard.CHAR_NONE; if (state == 1) { + boolean repeat = false; if (has_deferred_event) { if ((nanos == deferred_nanos && deferred_key_code == key_code && deferred_key_location == key_location)) { has_deferred_event = false; - return; // Ignore repeated key down, key up event pair - } - flushDeferredEvent(); + repeat = true; // Repeat event + } else + flushDeferredEvent(); } - putKeyEvent(key_code, key_location, state, character, nanos); + putKeyEvent(key_code, key_location, state, character, nanos, repeat); } else { flushDeferredEvent(); has_deferred_event = true; @@ -309,19 +310,19 @@ private void flushDeferredEvent() { if (has_deferred_event) { - putKeyEvent(deferred_key_code, deferred_key_location, deferred_key_state, deferred_character, deferred_nanos); + putKeyEvent(deferred_key_code, deferred_key_location, deferred_key_state, deferred_character, deferred_nanos, false); has_deferred_event = false; } } - private void putKeyEvent(int key_code, int key_location, byte state, int character, long nanos) { + private void putKeyEvent(int key_code, int key_location, byte state, int character, long nanos, boolean repeat) { int key_code_mapped = getMappedKeyCode(key_code, key_location); /* Ignore repeating presses */ if ( key_states[key_code_mapped] == state ) - return; + repeat = true; key_states[key_code_mapped] = state; int key_int_char = character & 0xffff; - putKeyboardEvent(key_code_mapped, state, key_int_char, nanos); + putKeyboardEvent(key_code_mapped, state, key_int_char, nanos, repeat); } private int getMappedKeyCode(int key_code, int position) { Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java 2007-05-13 21:11:53 UTC (rev 2817) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxKeyboard.java 2007-05-13 22:01:48 UTC (rev 2818) @@ -75,7 +75,7 @@ private final CharBuffer char_buffer = CharBuffer.allocate(KEYBOARD_BUFFER_SIZE); // Deferred key released event, to detect key repeat - private boolean has_deferred_event = true; + private boolean has_deferred_event; private int deferred_keycode; private int deferred_event_keycode; private long deferred_nanos; @@ -169,9 +169,9 @@ keyDownBuffer.position(old_position); } - private void putKeyboardEvent(int keycode, byte state, int ch, long nanos) { + private void putKeyboardEvent(int keycode, byte state, int ch, long nanos, boolean repeat) { tmp_event.clear(); - tmp_event.putInt(keycode).put(state).putInt(ch).putLong(nanos); + tmp_event.putInt(keycode).put(state).putInt(ch).putLong(nanos).put(repeat ? (byte)1 : (byte)0); tmp_event.flip(); event_queue.putEvent(tmp_event); } @@ -211,20 +211,20 @@ return lookupStringISO88591(event_ptr, translation_buffer); } - private void translateEvent(long event_ptr, int keycode, byte key_state, long nanos) { + private void translateEvent(long event_ptr, int keycode, byte key_state, long nanos, boolean repeat) { int num_chars, i; int ch; num_chars = lookupString(event_ptr, temp_translation_buffer); if (num_chars > 0) { ch = temp_translation_buffer[0]; - putKeyboardEvent(keycode, key_state, ch, nanos); + putKeyboardEvent(keycode, key_state, ch, nanos, repeat); for (i = 1; i < num_chars; i++) { ch = temp_translation_buffer[i]; - putKeyboardEvent(0, (byte)0, ch, nanos); + putKeyboardEvent(0, (byte)0, ch, nanos, repeat); } } else { - putKeyboardEvent(keycode, key_state, 0, nanos); + putKeyboardEvent(keycode, key_state, 0, nanos, repeat); } } @@ -305,14 +305,15 @@ key_down_buffer[keycode] = key_state; long nanos = millis*1000000; if (event_type == LinuxEvent.KeyPress) { + boolean repeat = false; if (has_deferred_event) { if (nanos == deferred_nanos && event_keycode == deferred_event_keycode) { has_deferred_event = false; - return; // Repeated event, ignore it - } - flushDeferredEvent(); + repeat = true; // Repeated event + } else + flushDeferredEvent(); } - translateEvent(event_ptr, keycode, key_state, nanos); + translateEvent(event_ptr, keycode, key_state, nanos, repeat); } else { flushDeferredEvent(); has_deferred_event = true; @@ -325,7 +326,7 @@ private void flushDeferredEvent() { if (has_deferred_event) { - putKeyboardEvent(deferred_keycode, deferred_key_state, 0, deferred_nanos); + putKeyboardEvent(deferred_keycode, deferred_key_state, 0, deferred_nanos, false); has_deferred_event = false; } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-05-13 21:11:53 UTC (rev 2817) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-05-13 22:01:48 UTC (rev 2818) @@ -608,12 +608,11 @@ private void handleKeyButton(long wParam, long lParam, long millis) { byte previous_state = (byte)((lParam >>> 30) & 0x1); byte state = (byte)(1 - ((lParam >>> 31) & 0x1)); - if (state == previous_state) - return; // Auto-repeat message + boolean repeat = state == previous_state; // Repeat message byte extended = (byte)((lParam >>> 24) & 0x1); int scan_code = (int)((lParam >>> 16) & 0xFF); if (keyboard != null) - keyboard.handleKey((int)wParam, scan_code, extended != 0, state, millis); + keyboard.handleKey((int)wParam, scan_code, extended != 0, state, millis, repeat); } private static int transformY(long hwnd, int y) { Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2007-05-13 21:11:53 UTC (rev 2817) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2007-05-13 22:01:48 UTC (rev 2818) @@ -63,6 +63,7 @@ private byte retained_state; private int retained_char; private long retained_millis; + private boolean retained_repeat; public WindowsKeyboard(long hwnd) throws LWJGLException { this.hwnd = hwnd; @@ -97,9 +98,9 @@ private static native int GetKeyboardState(ByteBuffer lpKeyState); private static native int GetKeyState(int virt_key); - private void putEvent(int keycode, byte state, int ch, long millis) { + private void putEvent(int keycode, byte state, int ch, long millis, boolean repeat) { tmp_event.clear(); - tmp_event.putInt(keycode).put(state).putInt(ch).putLong(millis*1000000); + tmp_event.putInt(keycode).put(state).putInt(ch).putLong(millis*1000000).put(repeat ? (byte)1 : (byte)0); tmp_event.flip(); event_queue.putEvent(tmp_event); } @@ -144,11 +145,11 @@ private void flushRetained() { if (has_retained_event) { has_retained_event = false; - putEvent(retained_key_code, retained_state, retained_char, retained_millis); + putEvent(retained_key_code, retained_state, retained_char, retained_millis, retained_repeat); } } - public void handleKey(int virt_key, int scan_code, boolean extended, byte event_state, long millis) { + public void handleKey(int virt_key, int scan_code, boolean extended, byte event_state, long millis, boolean repeat) { virt_key = translateExtended(virt_key, scan_code, event_state, extended); flushRetained(); has_retained_event = true; @@ -159,12 +160,13 @@ retained_state = event_state; retained_millis = millis; retained_char = 0; + retained_repeat = repeat; // translate(virt_key, event_state, millis*1000000); } public void handleChar(int event_char, long millis) { if (!has_retained_event) { - putEvent(0, (byte)0, event_char, millis); + putEvent(0, (byte)0, event_char, millis, false); } else retained_char = event_char; } Modified: trunk/LWJGL/src/java/org/lwjgl/test/input/KeyboardTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/input/KeyboardTest.java 2007-05-13 21:11:53 UTC (rev 2817) +++ trunk/LWJGL/src/java/org/lwjgl/test/input/KeyboardTest.java 2007-05-13 22:01:48 UTC (rev 2818) @@ -152,7 +152,11 @@ System.out.println("Pressed:" + Keyboard.getEventKeyState()); System.out.println("Key character code: " + character_code); System.out.println("Key character: " + Keyboard.getEventCharacter()); + System.out.println("Repeat event: " + Keyboard.isRepeatEvent()); + if (Keyboard.getEventKey() == Keyboard.KEY_R && Keyboard.getEventKeyState()) { + Keyboard.enableRepeatEvents(!Keyboard.areRepeatEventsEnabled()); + } if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-06-06 12:07:53
|
Revision: 2843 http://svn.sourceforge.net/java-game-lib/?rev=2843&view=rev Author: elias_naur Date: 2007-06-06 05:07:45 -0700 (Wed, 06 Jun 2007) Log Message: ----------- Don't use GL13 and ARB_vertex_shader constants in BaseReferences if they're not supported Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java trunk/LWJGL/src/java/org/lwjgl/util/generator/ContextGeneratorProcessorFactory.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java 2007-06-06 09:01:09 UTC (rev 2842) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java 2007-06-06 12:07:45 UTC (rev 2843) @@ -46,11 +46,21 @@ BaseReferences(ContextCapabilities caps) { IntBuffer temp = caps.scratch_int_buffer; - GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_ATTRIBS_ARB, temp); - glVertexAttribPointer_buffer = new Buffer[temp.get(0)]; + int max_vertex_attribs; + if (caps.GL_ARB_vertex_shader) { + GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_ATTRIBS_ARB, temp); + max_vertex_attribs = temp.get(0); + } else + max_vertex_attribs = 0; + glVertexAttribPointer_buffer = new Buffer[max_vertex_attribs]; - GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS, temp); - glTexCoordPointer_buffer = new Buffer[temp.get(0)]; + int max_texture_units; + if (caps.OpenGL13) { + GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS, temp); + max_texture_units = temp.get(0); + } else + max_texture_units = 0; + glTexCoordPointer_buffer = new Buffer[max_texture_units]; } void clear() { Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/ContextGeneratorProcessorFactory.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/ContextGeneratorProcessorFactory.java 2007-06-06 09:01:09 UTC (rev 2842) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/ContextGeneratorProcessorFactory.java 2007-06-06 12:07:45 UTC (rev 2843) @@ -168,6 +168,7 @@ if (Utils.isFinal(interface_decl)) ContextCapabilitiesGenerator.generateInitializer(writer, interface_decl); } + writer.println("\t\ttracker = new StateTracker();"); writer.println("\t}"); writer.println("}"); writer.close(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2007-06-29 22:11:34
|
Revision: 2856 http://svn.sourceforge.net/java-game-lib/?rev=2856&view=rev Author: elias_naur Date: 2007-06-29 15:11:31 -0700 (Fri, 29 Jun 2007) Log Message: ----------- Merge Windows and Linux privileged Runtime.exec usage into a method in LWJGLUtil. Linux: Added the recent freedesktop.org standard xdg-open script to the list of possible URL handlers. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java trunk/LWJGL/src/java/org/lwjgl/LinuxSysImplementation.java trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java Modified: trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2007-06-20 08:58:26 UTC (rev 2855) +++ trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2007-06-29 22:11:31 UTC (rev 2856) @@ -380,6 +380,22 @@ return paths; } + static void execPrivileged(final String[] cmd_array) throws Exception { + try { + Process process = (Process)AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + return Runtime.getRuntime().exec(cmd_array); + } + }); + // Close unused streams to make sure the child process won't hang + process.getInputStream().close(); + process.getOutputStream().close(); + process.getErrorStream().close(); + } catch (PrivilegedActionException e) { + throw (Exception)e.getCause(); + } + } + private static String getPrivilegedProperty(final String property_name) { return (String)AccessController.doPrivileged(new PrivilegedAction() { public Object run() { Modified: trunk/LWJGL/src/java/org/lwjgl/LinuxSysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/LinuxSysImplementation.java 2007-06-20 08:58:26 UTC (rev 2855) +++ trunk/LWJGL/src/java/org/lwjgl/LinuxSysImplementation.java 2007-06-29 22:11:31 UTC (rev 2856) @@ -32,8 +32,6 @@ package org.lwjgl; import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; /** * @@ -50,19 +48,14 @@ // Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it // right anyway. - String[] browsers = {"firefox", "mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"}; + String[] browsers = {"xdg-open", "firefox", "mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"}; for (int i = 0; i < browsers.length; i ++) { final String browser = browsers[i]; try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Runtime.getRuntime().exec(new String[] { browser, url }); - return null; - } - }); + LWJGLUtil.execPrivileged(new String[] { browser, url }); return true; - } catch (PrivilegedActionException e) { + } catch (Exception e) { // Ignore e.printStackTrace(System.err); } Modified: trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java 2007-06-20 08:58:26 UTC (rev 2855) +++ trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java 2007-06-29 22:11:31 UTC (rev 2856) @@ -32,8 +32,6 @@ package org.lwjgl; import java.security.AccessController; -import java.security.PrivilegedExceptionAction; -import java.security.PrivilegedActionException; /** * <p> @@ -56,15 +54,10 @@ public boolean openURL(final String url) { try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", url}); - return null; - } - }); + LWJGLUtil.execPrivileged(new String[]{"rundll32", "url.dll,FileProtocolHandler", url}); return true; - } catch (PrivilegedActionException e) { - LWJGLUtil.log("Failed to open url (" + url + "): " + e.getCause().getMessage()); + } catch (Exception e) { + LWJGLUtil.log("Failed to open url (" + url + "): " + e.getMessage()); return false; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2007-08-05 20:51:15
|
Revision: 2866 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=2866&view=rev Author: matzon Date: 2007-08-05 13:51:11 -0700 (Sun, 05 Aug 2007) Log Message: ----------- tagging 1.1.1 Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2007-07-30 05:22:46 UTC (rev 2865) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2007-08-05 20:51:11 UTC (rev 2866) @@ -54,7 +54,7 @@ private static final String JNI_LIBRARY_NAME = "lwjgl"; /** Current version of library */ - private static final String VERSION = "1.1"; + private static final String VERSION = "1.1.1"; /** Current version of the JNI library */ static final int JNI_VERSION = 11; Modified: trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2007-07-30 05:22:46 UTC (rev 2865) +++ trunk/LWJGL/src/java/org/lwjgl/devil/ILNative.java 2007-08-05 20:51:11 UTC (rev 2866) @@ -53,7 +53,7 @@ private static String JNI_LIBRARY_NAME = "lwjgl-devil"; /** Version of IL */ - static final String VERSION = "1.1"; + static final String VERSION = "1.1.1"; /** Current version of the JNI library */ static final int JNI_VERSION = 2; Modified: trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2007-07-30 05:22:46 UTC (rev 2865) +++ trunk/LWJGL/src/java/org/lwjgl/fmod3/FMOD.java 2007-08-05 20:51:11 UTC (rev 2866) @@ -193,7 +193,7 @@ private static String JNI_LIBRARY_NAME = "lwjgl-fmod3"; /** Version of FMOD */ - private static final String VERSION = "1.1"; + private static final String VERSION = "1.1.1"; /** Current version of the JNI library */ static final int JNI_VERSION = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cap...@us...> - 2007-08-22 23:11:05
|
Revision: 2882 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=2882&view=rev Author: captainjester Date: 2007-08-22 16:11:02 -0700 (Wed, 22 Aug 2007) Log Message: ----------- First commit of Direct3D extension. Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/d3d/ trunk/LWJGL/src/java/org/lwjgl/d3d/Context.java trunk/LWJGL/src/java/org/lwjgl/d3d/ContextImplementation.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DAdapterIdentifier9.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DBox.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DCaps9.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DClipStatus9.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DColorValue.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDeviceCreationParameters.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymode.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymodeEx.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymodeFilter.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DGammaRamp.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DIndexBufferDesc.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLight9.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLockedBox.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLockedRect.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DMaterial9.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DMatrix.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DPShaderCaps2_0.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DPresentParameters.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DPresentStats.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DRasterStatus.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DRectPatchInfo.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DRegionData.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DRegionDataHeader.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DSsurfaceDesc.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DSurfaceDesc.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DTriPatchInfo.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DUtil.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DVShaderCaps2_0.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DVector.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DVertexBufferDesc.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DVertexElement9.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DViewport9.java trunk/LWJGL/src/java/org/lwjgl/d3d/D3DVolumeDesc.java trunk/LWJGL/src/java/org/lwjgl/d3d/Direct3DConstants.java trunk/LWJGL/src/java/org/lwjgl/d3d/Display.java trunk/LWJGL/src/java/org/lwjgl/d3d/DisplayImplementation.java trunk/LWJGL/src/java/org/lwjgl/d3d/DisplayMode.java trunk/LWJGL/src/java/org/lwjgl/d3d/Drawable.java trunk/LWJGL/src/java/org/lwjgl/d3d/EventQueue.java trunk/LWJGL/src/java/org/lwjgl/d3d/GUID.java trunk/LWJGL/src/java/org/lwjgl/d3d/GlobalLock.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3D9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3D9Ex.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DBaseTexture9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DCubeTexture9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DDevice9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DDevice9Ex.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DIndexBuffer9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DPixelShader9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DQuery9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DResource9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DStateBlock9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DSurface9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DSwapChain9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DSwapChain9Ex.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DTexture9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DVertexBuffer9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DVertexDeclaration9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DVertexShader9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DVolume9.java trunk/LWJGL/src/java/org/lwjgl/d3d/IDirect3DVolumeTexture9.java trunk/LWJGL/src/java/org/lwjgl/d3d/InputImplementation.java trunk/LWJGL/src/java/org/lwjgl/d3d/LUID.java trunk/LWJGL/src/java/org/lwjgl/d3d/NewDisplay.java trunk/LWJGL/src/java/org/lwjgl/d3d/PaletteEntry.java trunk/LWJGL/src/java/org/lwjgl/d3d/PeerInfo.java trunk/LWJGL/src/java/org/lwjgl/d3d/PixelFormat.java trunk/LWJGL/src/java/org/lwjgl/d3d/Point.java trunk/LWJGL/src/java/org/lwjgl/d3d/Rectangle.java trunk/LWJGL/src/java/org/lwjgl/d3d/RegionData.java trunk/LWJGL/src/java/org/lwjgl/d3d/RegionDataHeader.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsContextImplementation.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsDirectInput.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsDirectInput3.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsDirectInput8.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsDirectInputDevice.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsDirectInputDevice3.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsDirectInputDevice8.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsDirectInputDeviceObjectCallback.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsDisplay.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsDisplayPeerInfo.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsFileVersion.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsKeyboard.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsKeycodes.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsMouse.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsPeerInfo.java trunk/LWJGL/src/java/org/lwjgl/d3d/WindowsRegistry.java Added: trunk/LWJGL/src/java/org/lwjgl/d3d/Context.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/Context.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/Context.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.Sys; + +/** + * <p/> + * Context encapsulates an OpenGL context. + * <p/> + * + * This class is thread-safe. + * + * @author elias_naur <eli...@us...> + * @version $Revision: 2730 $ + * $Id: Context.java 2730 2007-01-17 12:58:38Z elias_naur $ + */ +final class Context { + /** + * The platform specific implementation of context methods + */ + private final static ContextImplementation implementation; + + /** The current Context */ + private final static ThreadLocal current_context_local = new ThreadLocal(); + + /** + * Handle to the native GL rendering context + */ + private final ByteBuffer handle; + private final PeerInfo peer_info; + + /** Whether the context has been destroyed */ + private boolean destroyed; + + private boolean destroy_requested; + + /** The thread that has this context current, or null. */ + private Thread thread; + + static { + Sys.initialize(); + implementation = createImplementation(); + } + + private static ContextImplementation createImplementation() { + switch (LWJGLUtil.getPlatform()) { + case LWJGLUtil.PLATFORM_WINDOWS: + return new WindowsContextImplementation(); + default: + throw new IllegalStateException("Unsupported platform"); + } + } + + PeerInfo getPeerInfo() { + return peer_info; + } + + static Context getCurrentContext() { + return (Context)current_context_local.get(); + } + + /** + * Create a context with the specified peer info and shared context + */ + public Context(PeerInfo peer_info, Context shared_context) throws LWJGLException { + Context context_lock = shared_context != null ? shared_context : this; + // If shared_context is not null, synchronize on it to make sure it is not deleted + // while this context is created. Otherwise, simply synchronize on ourself to avoid NPE + synchronized (context_lock) { + if (shared_context != null && shared_context.destroyed) + throw new IllegalArgumentException("Shared context is destroyed"); +// GLContext.loadOpenGLLibrary(); + try { + this.peer_info = peer_info; + this.handle = implementation.create(peer_info, shared_context != null ? shared_context.handle : null); + } catch (LWJGLException e) { +// GLContext.unloadOpenGLLibrary(); + throw e; + } + } + } + + /** + * Release the current context (if any). After this call, no context is current. + */ + public static void releaseCurrentContext() throws LWJGLException { + Context current_context = getCurrentContext(); + if (current_context != null) { + implementation.releaseCurrentContext(); +// GLContext.useContext(null); + current_context_local.set(null); + synchronized (current_context) { + current_context.thread = null; + current_context.checkDestroy(); + } + } + } + + /** + * Release the context from its drawable. This is necessary on some platforms, + * like Mac OS X, where binding the context to a drawable and binding the context + * for rendering are two distinct actions and where calling releaseDrawable + * on every releaseCurrentContext results in artifacts. + */ + public synchronized void releaseDrawable() throws LWJGLException { + if (destroyed) + throw new IllegalStateException("Context is destroyed"); + implementation.releaseDrawable(getHandle()); + } + + /** + * Update the context. Should be called whenever it's drawable is moved or resized + */ + public synchronized void update() { + if (destroyed) + throw new IllegalStateException("Context is destroyed"); + implementation.update(getHandle()); + } + + /** + * Swap the buffers on the current context. Only valid for double-buffered contexts + */ + public static void swapBuffers(PeerInfo peerInfo) throws LWJGLException { + implementation.swapBuffers(peerInfo); + } + + private boolean canAccess() { + return thread == null || Thread.currentThread() == thread; + } + + private void checkAccess() { + if (!canAccess()) + throw new IllegalStateException("From thread " + Thread.currentThread() + ": " + thread + " already has the context current"); + } + + /** + * Make the context current + */ + public synchronized void makeCurrent() throws LWJGLException { + checkAccess(); + if (destroyed) + throw new IllegalStateException("Context is destroyed"); + thread = Thread.currentThread(); + current_context_local.set(this); + implementation.makeCurrent(peer_info, handle); +// GLContext.useContext(this); + } + + ByteBuffer getHandle() { + return handle; + } + + /** + * Query whether the context is current + */ + public synchronized boolean isCurrent() throws LWJGLException { + if (destroyed) + throw new IllegalStateException("Context is destroyed"); + return implementation.isCurrent(handle); + } + + private void checkDestroy() { + if (!destroyed && destroy_requested) { + try { + releaseDrawable(); + implementation.destroy(peer_info, handle); + destroyed = true; + thread = null; +// GLContext.unloadOpenGLLibrary(); + } catch (LWJGLException e) { + LWJGLUtil.log("Exception occurred while destroying context: " + e); + } + } + } + + /** + * Set the buffer swap interval. This call is a best-attempt at changing + * the monitor swap interval, which is the minimum periodicity of color buffer swaps, + * measured in video frame periods, and is not guaranteed to be successful. + * + * A video frame period is the time required to display a full frame of video data. + * + * @param sync true to synchronize; false to ignore synchronization + */ + public static void setSwapInterval(int value) { + implementation.setSwapInterval(value); + } + + + /** + * Destroy the context. This method behaves the same as destroy() with the extra + * requirement that the context must be either current to the current thread or not + * current at all. + */ + public synchronized void forceDestroy() throws LWJGLException { + checkAccess(); + destroy(); + } + + /** + * Request destruction of the Context. If the context is current, no context will be current after this call. + * The context is destroyed when no thread has it current. + */ + public synchronized void destroy() throws LWJGLException { + if (destroyed) + return; + destroy_requested = true; + boolean was_current = isCurrent(); +// int error = GL11.GL_NO_ERROR; + if (was_current) { +// if (GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGL11) +// error = GL11.glGetError(); + releaseCurrentContext(); + } + checkDestroy(); +// if (was_current && error != GL11.GL_NO_ERROR) +// throw new OpenGLException(error); + } +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/ContextImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/ContextImplementation.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/ContextImplementation.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +import org.lwjgl.LWJGLException; + +/** + * <p/> + * Context implementation interface. + * <p/> + * + * @author elias_naur <eli...@us...> + * @version $Revision: 2356 $ + * $Id: ContextImplementation.java 2356 2006-06-07 06:35:52Z elias_naur $ + */ +interface ContextImplementation { + /** + * Create a context. + */ + public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException; + + /** + * Swap the buffers of the current context. Only valid for double-buffered contexts. + */ + public void swapBuffers(PeerInfo peerInfo) throws LWJGLException; + + /** + * Release the context from its drawable, if any. + */ + public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException; + + /** + * Release the current context (if any). After this call, no context is current. + */ + public void releaseCurrentContext() throws LWJGLException; + + /** + * Update the context. Should be called whenever it's drawable is moved or resized + */ + public void update(ByteBuffer context_handle); + + /** + * Query whether the context is current + */ + public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException; + + /** + * Query whether the context is current + */ + public boolean isCurrent(ByteBuffer handle) throws LWJGLException; + + public void setSwapInterval(int value); + + /** + * Destroys the Context. + */ + public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException; +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DAdapterIdentifier9.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DAdapterIdentifier9.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DAdapterIdentifier9.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,81 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DAdapterIdentifier9 { + public byte Driver[] = new byte[Direct3DConstants.MAX_DEVICE_IDENTIFIER_STRING];//512 char [MAX_DEVICE_IDENTIFIER_STRING] + public byte Description[] = new byte[Direct3DConstants.MAX_DEVICE_IDENTIFIER_STRING];//512 char [MAX_DEVICE_IDENTIFIER_STRING] + public byte DeviceName[] = new byte[32]; //32 char [32] + public long DriverVersion; //8 LARGE_INTEGER + public long VendorId; //4 DWORD + public long DeviceId; //4 DWORD + public long SubSysId; //4 DWORD + public long Revision; //4 DWORD + public GUID DeviceIdentifier = new GUID(); //16 GUID + public long WHQLLevel; //4 DWORD + private static final int D3D_ADAPTER_IDENTIFIER_BYTE_SIZE = 1100; + private ByteBuffer buffer; + + public D3DAdapterIdentifier9() { + buffer = ByteBuffer.allocateDirect(D3D_ADAPTER_IDENTIFIER_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.put(Driver); + buffer.put(Description); + buffer.put(DeviceName); + buffer.putLong(DriverVersion); + buffer.putInt((int)VendorId); + buffer.putInt((int)DeviceId); + buffer.putInt((int)SubSysId); + buffer.putInt((int)Revision); + buffer.putInt((int)DeviceIdentifier.Data1); + buffer.putShort(DeviceIdentifier.Data2); + buffer.putShort(DeviceIdentifier.Data3); + buffer.put(DeviceIdentifier.Data4); + buffer.putInt((int)WHQLLevel); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + buffer.get(Driver); + buffer.get(Description); + buffer.get(DeviceName); + DriverVersion = buffer.getLong(); + VendorId = buffer.getInt(); + DeviceId = buffer.getInt(); + SubSysId = buffer.getInt(); + Revision = buffer.getInt(); + DeviceIdentifier.Data1 = buffer.getInt(); + DeviceIdentifier.Data2 = buffer.getShort(); + DeviceIdentifier.Data3 = buffer.getShort(); + buffer.get(DeviceIdentifier.Data4); + WHQLLevel = buffer.getInt(); + } + + public String toString() { + return + "\n Driver = " + new String(Driver) + + "\n Description = " + new String(Description) + + "\n DeviceName = " + new String(DeviceName) + + "\nDriverVersion = " + DriverVersion + + "\n VendorId = " + VendorId + + "\n DeviceId = " + DeviceId + + "\n SubSysId = " + SubSysId + + "\n Revision = " + Revision + + "\n WHQLLevel = " + WHQLLevel + + DeviceIdentifier; + } +} \ No newline at end of file Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DBox.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DBox.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DBox.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,10 @@ +package org.lwjgl.d3d; + +public class D3DBox { + public int Left; //UINT + public int Top; //UINT + public int Right; //UINT + public int Bottom; //UINT + public int Front; //UINT + public int Back; //UINT +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DCaps9.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DCaps9.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DCaps9.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,327 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DCaps9 { + public int DeviceType; //4 D3DDEVTYPE + public int AdapterOrdinal; //4 UINT + public long Caps; //4 DWORD + public long Caps2; //4 DWORD + public long Caps3; //4 DWORD + public long PresentationIntervals; //4 DWORD + public long CursorCaps; //4 DWORD + public long DevCaps; //4 DWORD + public long PrimitiveMiscCaps; //4 DWORD + public long RasterCaps; //4 DWORD + public long ZCmpCaps; //4 DWORD + public long SrcBlendCaps; //4 DWORD + public long DestBlendCaps; //4 DWORD + public long AlphaCmpCaps; //4 DWORD + public long ShadeCaps; //4 DWORD + public long TextureCaps; //4 DWORD + public long TextureFilterCaps; //4 DWORD + public long CubeTextureFilterCaps; //4 DWORD + public long VolumeTextureFilterCaps; //4 DWORD + public long TextureAddressCaps; //4 DWORD + public long VolumeTextureAddressCaps; //4 DWORD + public long LineCaps; //4 DWORD + public long MaxTextureWidth; //4 DWORD + public long MaxTextureHeight; //4 DWORD + public long MaxVolumeExtent; //4 DWORD + public long MaxTextureRepeat; //4 DWORD + public long MaxTextureAspectRatio; //4 DWORD + public long MaxAnisotropy; //4 DWORD + public float MaxVertexW; //4 + public float GuardBandLeft; //4 + public float GuardBandTop; //4 + public float GuardBandRight; //4 + public float GuardBandBottom; //4 + public float ExtentsAdjust; //4 + public long StencilCaps; //4 DWORD + public long FVFCaps; //4 DWORD + public long TextureOpCaps; //4 DWORD + public long MaxTextureBlendStages; //4 DWORD + public long MaxSimultaneousTextures; //4 DWORD + public long VertexProcessingCaps; //4 DWORD + public long MaxActiveLights; //4 DWORD + public long MaxUserClipPlanes; //4 DWORD + public long MaxVertexBlendMatrices; //4 DWORD + public long MaxVertexBlendMatrixIndex; //4 DWORD + public float MaxPointSize; //4 + public long MaxPrimitiveCount; //4 DWORD + public long MaxVertexIndex; //4 DWORD + public long MaxStreams; //4 DWORD + public long MaxStreamStride; //4 DWORD + public long VertexShaderVersion; //4 DWORD + public long MaxVertexShaderConst; //4 DWORD + public long PixelShaderVersion; //4 DWORD + public float PixelShader1xMaxValue; //4 + public long DevCaps2; //4 DWORD + public float MaxNpatchTessellationLevel; //4 + public long Reserved5; //4 DWORD + public int MasterAdapterOrdinal; //4 UINT + public int AdapterOrdinalInGroup; //4 UINT + public int NumberOfAdaptersInGroup; //4 UINT + public long DeclTypes; //4 DWORD + public long NumSimultaneousRTs; //4 DWORD + public long StretchRectFilterCaps; //4 DWORD + public D3DVShaderCaps2_0 VS20Caps = new D3DVShaderCaps2_0(); //16 D3DVSHADERCAPS2_0 + public D3DPShaderCaps2_0 D3DPSHADERCAPS2_0 = new D3DPShaderCaps2_0(); //20 D3DPSHADERCAPS2_0 + public long VertexTextureFilterCaps; //4 DWORD + public long MaxVShaderInstructionsExecuted; //4 DWORD + public long MaxPShaderInstructionsExecuted; //4 DWORD + public long MaxVertexShader30InstructionSlots; //4 DWORD + public long MaxPixelShader30InstructionSlots; //4 DWORD + private static final int D3D_CAPS_BYTE_SIZE = 304; + + private ByteBuffer buffer; + + public D3DCaps9() { + buffer = ByteBuffer.allocateDirect(D3D_CAPS_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(DeviceType); + buffer.putInt(AdapterOrdinal); + buffer.putInt((int)Caps); + buffer.putInt((int)Caps2); + buffer.putInt((int)Caps3); + buffer.putInt((int)PresentationIntervals); + buffer.putInt((int)CursorCaps); + buffer.putInt((int)DevCaps); + buffer.putInt((int)PrimitiveMiscCaps); + buffer.putInt((int)RasterCaps); + buffer.putInt((int)ZCmpCaps); + buffer.putInt((int)SrcBlendCaps); + buffer.putInt((int)DestBlendCaps); + buffer.putInt((int)AlphaCmpCaps); + buffer.putInt((int)ShadeCaps); + buffer.putInt((int)TextureCaps); + buffer.putInt((int)TextureFilterCaps); + buffer.putInt((int)CubeTextureFilterCaps); + buffer.putInt((int)VolumeTextureFilterCaps); + buffer.putInt((int)TextureAddressCaps); + buffer.putInt((int)VolumeTextureAddressCaps); + buffer.putInt((int)LineCaps); + buffer.putInt((int)MaxTextureWidth); + buffer.putInt((int)MaxTextureHeight); + buffer.putInt((int)MaxVolumeExtent); + buffer.putInt((int)MaxTextureRepeat); + buffer.putInt((int)MaxTextureAspectRatio); + buffer.putInt((int)MaxAnisotropy); + buffer.putFloat(MaxVertexW); + buffer.putFloat(GuardBandLeft); + buffer.putFloat(GuardBandTop); + buffer.putFloat(GuardBandRight); + buffer.putFloat(GuardBandBottom); + buffer.putFloat(ExtentsAdjust); + buffer.putInt((int)StencilCaps); + buffer.putInt((int)FVFCaps); + buffer.putInt((int)TextureOpCaps); + buffer.putInt((int)MaxTextureBlendStages); + buffer.putInt((int)MaxSimultaneousTextures); + buffer.putInt((int)VertexProcessingCaps); + buffer.putInt((int)MaxActiveLights); + buffer.putInt((int)MaxUserClipPlanes); + buffer.putInt((int)MaxVertexBlendMatrices); + buffer.putInt((int)MaxVertexBlendMatrixIndex); + buffer.putFloat(MaxPointSize); + buffer.putInt((int)MaxPrimitiveCount); + buffer.putInt((int)MaxVertexIndex); + buffer.putInt((int)MaxStreams); + buffer.putInt((int)MaxStreamStride); + buffer.putInt((int)VertexShaderVersion); + buffer.putInt((int)MaxVertexShaderConst); + buffer.putInt((int)PixelShaderVersion); + buffer.putFloat(PixelShader1xMaxValue); + buffer.putInt((int)DevCaps2); + buffer.putFloat(MaxNpatchTessellationLevel); + buffer.putInt((int)Reserved5); + buffer.putInt(MasterAdapterOrdinal); + buffer.putInt(AdapterOrdinalInGroup); + buffer.putInt(NumberOfAdaptersInGroup); + buffer.putInt((int)DeclTypes); + buffer.putInt((int)NumSimultaneousRTs); + buffer.putInt((int)StretchRectFilterCaps); + buffer.putInt((int)VS20Caps.Caps); + buffer.putInt(VS20Caps.DynamicFlowControlDepth); + buffer.putInt(VS20Caps.NumTemps); + buffer.putInt(VS20Caps.StaticFlowControlDepth); + buffer.putInt((int)D3DPSHADERCAPS2_0.Caps); + buffer.putInt(D3DPSHADERCAPS2_0.DynamicFlowControlDepth); + buffer.putInt(D3DPSHADERCAPS2_0.NumTemps); + buffer.putInt(D3DPSHADERCAPS2_0.StaticFlowControlDepth); + buffer.putInt(D3DPSHADERCAPS2_0.NumInstructionSlots); + buffer.putInt((int)VertexTextureFilterCaps); + buffer.putInt((int)MaxVShaderInstructionsExecuted); + buffer.putInt((int)MaxPShaderInstructionsExecuted); + buffer.putInt((int)MaxVertexShader30InstructionSlots); + buffer.putInt((int)MaxPixelShader30InstructionSlots); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + DeviceType = buffer.getInt(); + AdapterOrdinal = buffer.getInt(); + Caps = buffer.getInt(); + Caps2 = buffer.getInt(); + Caps3 = buffer.getInt(); + PresentationIntervals = buffer.getInt(); + CursorCaps = buffer.getInt(); + DevCaps = buffer.getInt(); + PrimitiveMiscCaps = buffer.getInt(); + RasterCaps = buffer.getInt(); + ZCmpCaps = buffer.getInt(); + SrcBlendCaps = buffer.getInt(); + DestBlendCaps = buffer.getInt(); + AlphaCmpCaps = buffer.getInt(); + ShadeCaps = buffer.getInt(); + TextureCaps = buffer.getInt(); + TextureFilterCaps = buffer.getInt(); + CubeTextureFilterCaps = buffer.getInt(); + VolumeTextureFilterCaps = buffer.getInt(); + TextureAddressCaps = buffer.getInt(); + VolumeTextureAddressCaps = buffer.getInt(); + LineCaps = buffer.getInt(); + MaxTextureWidth = buffer.getInt(); + MaxTextureHeight = buffer.getInt(); + MaxVolumeExtent = buffer.getInt(); + MaxTextureRepeat = buffer.getInt(); + MaxTextureAspectRatio = buffer.getInt(); + MaxAnisotropy = buffer.getInt(); + MaxVertexW = buffer.getFloat(); + GuardBandLeft = buffer.getFloat(); + GuardBandTop = buffer.getFloat(); + GuardBandRight = buffer.getFloat(); + GuardBandBottom = buffer.getFloat(); + ExtentsAdjust = buffer.getFloat(); + StencilCaps = buffer.getInt(); + FVFCaps = buffer.getInt(); + TextureOpCaps = buffer.getInt(); + MaxTextureBlendStages = buffer.getInt(); + MaxSimultaneousTextures = buffer.getInt(); + VertexProcessingCaps = buffer.getInt(); + MaxActiveLights = buffer.getInt(); + MaxUserClipPlanes = buffer.getInt(); + MaxVertexBlendMatrices = buffer.getInt(); + MaxVertexBlendMatrixIndex = buffer.getInt(); + MaxPointSize = buffer.getFloat(); + MaxPrimitiveCount = buffer.getInt(); + MaxVertexIndex = buffer.getInt(); + MaxStreams = buffer.getInt(); + MaxStreamStride = buffer.getInt(); + VertexShaderVersion = buffer.getInt(); + MaxVertexShaderConst = buffer.getInt(); + PixelShaderVersion = buffer.getInt(); + PixelShader1xMaxValue = buffer.getFloat(); + DevCaps2 = buffer.getInt(); + MaxNpatchTessellationLevel = buffer.getFloat(); + Reserved5 = buffer.getInt(); + MasterAdapterOrdinal = buffer.getInt(); + AdapterOrdinalInGroup = buffer.getInt(); + NumberOfAdaptersInGroup = buffer.getInt(); + DeclTypes = buffer.getInt(); + NumSimultaneousRTs = buffer.getInt(); + StretchRectFilterCaps = buffer.getInt(); + VS20Caps.Caps = buffer.getInt(); + VS20Caps.DynamicFlowControlDepth = buffer.getInt(); + VS20Caps.NumTemps = buffer.getInt(); + VS20Caps.StaticFlowControlDepth = buffer.getInt(); + D3DPSHADERCAPS2_0.Caps = buffer.getInt(); + D3DPSHADERCAPS2_0.DynamicFlowControlDepth = buffer.getInt(); + D3DPSHADERCAPS2_0.NumTemps = buffer.getInt(); + D3DPSHADERCAPS2_0.StaticFlowControlDepth = buffer.getInt(); + D3DPSHADERCAPS2_0.NumInstructionSlots = buffer.getInt(); + VertexTextureFilterCaps = buffer.getInt(); + MaxVShaderInstructionsExecuted = buffer.getInt(); + MaxPShaderInstructionsExecuted = buffer.getInt(); + MaxVertexShader30InstructionSlots = buffer.getInt() & 0x00000000ffffffffL; + MaxPixelShader30InstructionSlots = buffer.getInt(); + } + + public String toString() { + return + "\n DeviceType = " + DeviceType + + "\n AdapterOrdinal = " + AdapterOrdinal + + "\n Caps = " + Caps + + "\n Caps2 = " + Caps2 + + "\n Caps3 = " + Caps3 + + "\n PresentationIntervals = " + PresentationIntervals + + "\n CursorCaps = " + CursorCaps + + "\n DevCaps = " + DevCaps + + "\n PrimitiveMiscCaps = " + PrimitiveMiscCaps + + "\n RasterCaps = " + RasterCaps + + "\n ZCmpCaps = " + ZCmpCaps + + "\n SrcBlendCaps = " + SrcBlendCaps + + "\n DestBlendCaps = " + DestBlendCaps + + "\n AlphaCmpCaps = " + AlphaCmpCaps + + "\n ShadeCaps = " + ShadeCaps + + "\n TextureCaps = " + TextureCaps + + "\n TextureFilterCaps = " + TextureFilterCaps + + "\n CubeTextureFilterCaps = " + CubeTextureFilterCaps + + "\n VolumeTextureFilterCaps = " + VolumeTextureFilterCaps + + "\n TextureAddressCaps = " + TextureAddressCaps + + "\n VolumeTextureAddressCaps = " + VolumeTextureAddressCaps + + "\n LineCaps = " + LineCaps + + "\n MaxTextureWidth = " + MaxTextureWidth + + "\n MaxTextureHeight = " + MaxTextureHeight + + "\n MaxVolumeExtent = " + MaxVolumeExtent + + "\n MaxTextureRepeat = " + MaxTextureRepeat + + "\n MaxTextureAspectRatio = " + MaxTextureAspectRatio + + "\n MaxAnisotropy = " + MaxAnisotropy + + "\n MaxVertexW = " + MaxVertexW + + "\n GuardBandLeft = " + GuardBandLeft + + "\n GuardBandTop = " + GuardBandTop + + "\n GuardBandRight = " + GuardBandRight + + "\n GuardBandBottom = " + GuardBandBottom + + "\n ExtentsAdjust = " + ExtentsAdjust + + "\n StencilCaps = " + StencilCaps + + "\n FVFCaps = " + FVFCaps + + "\n TextureOpCaps = " + TextureOpCaps + + "\n MaxTextureBlendStages = " + MaxTextureBlendStages + + "\n MaxSimultaneousTextures = " + MaxSimultaneousTextures + + "\n VertexProcessingCaps = " + VertexProcessingCaps + + "\n MaxActiveLights = " + MaxActiveLights + + "\n MaxUserClipPlanes = " + MaxUserClipPlanes + + "\n MaxVertexBlendMatrices = " + MaxVertexBlendMatrices + + "\n MaxVertexBlendMatrixIndex = " + MaxVertexBlendMatrixIndex + + "\n MaxPointSize = " + MaxPointSize + + "\n MaxPrimitiveCount = " + MaxPrimitiveCount + + "\n MaxVertexIndex = " + MaxVertexIndex + + "\n MaxStreams = " + MaxStreams + + "\n MaxStreamStride = " + MaxStreamStride + + "\n VertexShaderVersion = " + VertexShaderVersion + + "\n MaxVertexShaderConst = " + MaxVertexShaderConst + + "\n PixelShaderVersion = " + PixelShaderVersion + + "\n PixelShader1xMaxValue = " + PixelShader1xMaxValue + + "\n DevCaps2 = " + DevCaps2 + + "\n MaxNpatchTessellationLevel = " + MaxNpatchTessellationLevel + + "\n Reserved5 = " + Reserved5 + + "\n MasterAdapterOrdinal = " + MasterAdapterOrdinal + + "\n AdapterOrdinalInGroup = " + AdapterOrdinalInGroup + + "\n NumberOfAdaptersInGroup = " + NumberOfAdaptersInGroup + + "\n DeclTypes = " + DeclTypes + + "\n NumSimultaneousRTs = " + NumSimultaneousRTs + + "\n StretchRectFilterCaps = " + StretchRectFilterCaps + + VS20Caps.toString() + + D3DPSHADERCAPS2_0.toString() + + "\n VertexTextureFilterCaps = " + VertexTextureFilterCaps + + "\n MaxVShaderInstructionsExecuted = " + MaxVShaderInstructionsExecuted + + "\n MaxPShaderInstructionsExecuted = " + MaxPShaderInstructionsExecuted + + "\nMaxVertexShader30InstructionSlots = " + MaxVertexShader30InstructionSlots + + "\n MaxPixelShader30InstructionSlots = " + MaxPixelShader30InstructionSlots; + } +} \ No newline at end of file Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DClipStatus9.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DClipStatus9.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DClipStatus9.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,42 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DClipStatus9 { + public long ClipUnion; //4 DWORD + public long ClipIntersection; //4 DWORD + private static final int D3D_CLIP_STATUS_BYTE_SIZE = 8; + + private ByteBuffer buffer; + + public D3DClipStatus9() { + buffer = ByteBuffer.allocateDirect(D3D_CLIP_STATUS_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt((int)ClipUnion); + buffer.putInt((int)ClipIntersection); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + ClipUnion = buffer.getInt(); + ClipIntersection = buffer.getInt(); + } + public String toString() { + return + "\n ClipUnion = " + ClipUnion + + "\nClipIntersection = " + ClipIntersection; + } +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DColorValue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DColorValue.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DColorValue.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,44 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DColorValue { + public float r; + public float g; + public float b; + public float a; + + private static final int D3D_COLOR_VALUE_BYTE_SIZE = 16; + private ByteBuffer buffer; + + public D3DColorValue() { + buffer = ByteBuffer.allocateDirect(D3D_COLOR_VALUE_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putFloat(r); + buffer.putFloat(g); + buffer.putFloat(b); + buffer.putFloat(a); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + r = buffer.getFloat(); + g = buffer.getFloat(); + b = buffer.getFloat(); + a = buffer.getFloat(); + } +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDeviceCreationParameters.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDeviceCreationParameters.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDeviceCreationParameters.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,50 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DDeviceCreationParameters { + public int AdapterOrdinal; //4 UINT + public int DeviceType; //4 D3DDEVTYPE + public long hFocusWindow; //4 HWND + public long BehaviorFlags; //4 DWORD + private static final int D3D_CREATION_PARAMETERS_STATUS_BYTE_SIZE = 16; + + private ByteBuffer buffer; + + public D3DDeviceCreationParameters() { + buffer = ByteBuffer.allocateDirect(D3D_CREATION_PARAMETERS_STATUS_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(AdapterOrdinal); + buffer.putInt(DeviceType); + buffer.putInt((int)hFocusWindow); + buffer.putInt((int)BehaviorFlags); + + return buffer; + } + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + AdapterOrdinal = buffer.getInt(); + DeviceType = buffer.getInt(); + hFocusWindow = buffer.getInt(); + BehaviorFlags = buffer.getInt(); + } + public String toString() { + return + "\nAdapterOrdinal = " + AdapterOrdinal + + "\n DeviceType = " + DeviceType + + "\n hFocusWindow = " + hFocusWindow + + "\n BehaviorFlags = " + BehaviorFlags; + } +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymode.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymode.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymode.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,51 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DDisplaymode { + public int Width; //4 UINT + public int Height; //4 UINT + public int RefreshRate; //4 UINT + public int Format; //4 D3DFORMAT + private static final int D3D_DISPLAYMODE_BYTE_SIZE = 16; + private ByteBuffer buffer; + + public D3DDisplaymode() { + buffer = ByteBuffer.allocateDirect(D3D_DISPLAYMODE_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putInt(Width); + buffer.putInt(Height); + buffer.putInt(RefreshRate); + buffer.putInt(Format); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + Width = buffer.getInt(); + Height = buffer.getInt(); + RefreshRate = buffer.getInt(); + Format = buffer.getInt(); + } + + public String toString() { + return + "\n width = " + Width + + "\n height = " + Height + + "\nrefreshRate = " + RefreshRate + + "\n format = " + Format; + } +} \ No newline at end of file Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymodeEx.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymodeEx.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymodeEx.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,11 @@ +package org.lwjgl.d3d; + +public class D3DDisplaymodeEx { + public int Size; //UINT + public int Width; //UINT + public int Height; //UINT + public int RefreshRate; //UINT + public int Format; //D3DFORMAT + public int ScanLineOrdering; //D3DSCANLINEORDERING + +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymodeFilter.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymodeFilter.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DDisplaymodeFilter.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,8 @@ +package org.lwjgl.d3d; + +public class D3DDisplaymodeFilter { + public int Size; //UINT + public int Format; //D3DFORMAT + public int ScanLineOrdering; //D3DSCANLINEORDERING + +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DGammaRamp.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DGammaRamp.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DGammaRamp.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,51 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.ShortBuffer; + +public class D3DGammaRamp { + private ByteBuffer redForNative = ByteBuffer.allocateDirect(512).order(ByteOrder.nativeOrder()); //2 WORD + private ByteBuffer greenForNative = ByteBuffer.allocateDirect(512).order(ByteOrder.nativeOrder()); //2 WORD + private ByteBuffer blueForNative = ByteBuffer.allocateDirect(512).order(ByteOrder.nativeOrder()); //2 WORD + public ShortBuffer red = redForNative.asShortBuffer(); + public ShortBuffer green = greenForNative.asShortBuffer(); + public ShortBuffer blue = blueForNative.asShortBuffer(); + + private static final int D3D_GAMMA_RAMP_BYTE_SIZE = 1536; + private ByteBuffer buffer; + + public D3DGammaRamp() { + buffer = ByteBuffer.allocateDirect(D3D_GAMMA_RAMP_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + redForNative.rewind(); + buffer.put(redForNative); + greenForNative.rewind(); + buffer.put(greenForNative); + blueForNative.rewind(); + buffer.put(blueForNative); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + byte temp[] = new byte[512]; + buffer.get(temp); + redForNative.put(temp); + buffer.get(temp); + greenForNative.put(temp); + buffer.get(temp); + blueForNative.put(temp); + } +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DIndexBufferDesc.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DIndexBufferDesc.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DIndexBufferDesc.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,9 @@ +package org.lwjgl.d3d; + +public class D3DIndexBufferDesc { + public int Format; //D3DFORMAT + public int Type; //D3DRESOURCETYPE + public long Usage; //DWORD + public int Pool; //D3DPOOL + public int Size; //UINT +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLight9.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLight9.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLight9.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,78 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DLight9 { + public int Type; //2 D3DLIGHTTYPE + public D3DColorValue Diffuse; //16 D3DCOLORVALUE + public D3DColorValue Specular; //16 D3DCOLORVALUE + public D3DColorValue Ambient; //16 D3DCOLORVALUE + public D3DVector Position; //12 D3DVECTOR + public D3DVector Direction; //12 D3DVECTOR + public float Range; //4 + public float Falloff; //4 + public float Attenuation0; //4 + public float Attenuation1; //4 + public float Attenuation2; //4 + public float Theta; //4 + public float Phi; //4 + + private static final int D3D_LIGHT_BYTE_SIZE = 102; + private ByteBuffer buffer; + + public D3DLight9() { + buffer = ByteBuffer.allocateDirect(D3D_LIGHT_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.putShort((short)Type); + buffer.put(Diffuse.getBuffer()); + buffer.put(Specular.getBuffer()); + buffer.put(Ambient.getBuffer()); + buffer.put(Position.getBuffer()); + buffer.put(Direction.getBuffer()); + buffer.putFloat(Range); + buffer.putFloat(Falloff); + buffer.putFloat(Attenuation1); + buffer.putFloat(Attenuation1); + buffer.putFloat(Attenuation2); + buffer.putFloat(Theta); + buffer.putFloat(Phi); + buffer.rewind(); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + Type = buffer.getShort(); + byte temp[] = new byte[16]; + buffer.get(temp); + Diffuse.setBuffer(Diffuse.getEmptyBuffer().put(temp)); + buffer.get(temp); + Specular.setBuffer(Specular.getEmptyBuffer().put(temp)); + buffer.get(temp); + Ambient.setBuffer(Ambient.getEmptyBuffer().put(temp)); + temp = new byte[12]; + buffer.get(temp); + Position.setBuffer(Position.getEmptyBuffer().put(temp)); + buffer.get(temp); + Direction.setBuffer(Direction.getEmptyBuffer().put(temp)); + Range = buffer.getFloat(); + Falloff = buffer.getFloat(); + Attenuation1 = buffer.getFloat(); + Attenuation1 = buffer.getFloat(); + Attenuation2 = buffer.getFloat(); + Theta = buffer.getFloat(); + Phi = buffer.getFloat(); + } +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLockedBox.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLockedBox.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLockedBox.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,9 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +public class D3DLockedBox { + public int RowPitch; + public int SlicePitch; + public ByteBuffer pBits; +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLockedRect.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLockedRect.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DLockedRect.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,9 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; + +public class D3DLockedRect { + int Pitch; + public ByteBuffer pBits; //void * + +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DMaterial9.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DMaterial9.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DMaterial9.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,51 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DMaterial9 { + public D3DColorValue Diffuse; //16 + public D3DColorValue Ambient; //16 + public D3DColorValue Specular; //16 + public D3DColorValue Emissive; //16 + public float Power; //4 + + private static final int D3D_MATERIAL_BYTE_SIZE = 68; + private ByteBuffer buffer; + + public D3DMaterial9() { + buffer = ByteBuffer.allocateDirect(D3D_MATERIAL_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + buffer.put(Diffuse.getBuffer()); + buffer.put(Ambient.getBuffer()); + buffer.put(Specular.getBuffer()); + buffer.put(Emissive.getBuffer()); + buffer.putFloat(Power); + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + byte temp[] = new byte[16]; + buffer.get(temp); + Diffuse.setBuffer(Diffuse.getEmptyBuffer().put(temp)); + buffer.get(temp); + Ambient.setBuffer(Ambient.getEmptyBuffer().put(temp)); + buffer.get(temp); + Specular.setBuffer(Specular.getEmptyBuffer().put(temp)); + buffer.get(temp); + Emissive.setBuffer(Emissive.getEmptyBuffer().put(temp)); + Power = buffer.getFloat(); + } +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DMatrix.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DMatrix.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DMatrix.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,42 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +public class D3DMatrix { + public float m[][] = new float[4][4]; + + private static final int D3D_MATRIX_BYTE_SIZE = 64; + private ByteBuffer buffer; + + public D3DMatrix() { + buffer = ByteBuffer.allocateDirect(D3D_MATRIX_BYTE_SIZE); + buffer.order(ByteOrder.nativeOrder()); + buffer.clear(); + } + + public ByteBuffer getEmptyBuffer() { + buffer.rewind(); + + return buffer; + } + + public ByteBuffer getBuffer() { + buffer.rewind(); + FloatBuffer temp = buffer.asFloatBuffer(); + for(int i=0;i<4;i++) { + temp.put(m[i]); + } + + return buffer; + } + + public void setBuffer(ByteBuffer buffer) { + buffer.rewind(); + FloatBuffer temp = buffer.asFloatBuffer(); + for(int i=0;i<4;i++) { + temp.get(m[i]); + } + } +} Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DPShaderCaps2_0.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DPShaderCaps2_0.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DPShaderCaps2_0.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,18 @@ +package org.lwjgl.d3d; + +public class D3DPShaderCaps2_0 { + public long Caps; //4 DWORD + public int DynamicFlowControlDepth; //4 INT + public int NumTemps; //4 INT + public int StaticFlowControlDepth; //4 INT + public int NumInstructionSlots; //4 INT + + public String toString() { + return + "\n Caps = " + Caps + + "\nDynamicFlowControlDepth = " + DynamicFlowControlDepth + + "\n NumTemps = " + NumTemps + + "\n StaticFlowControlDepth = " + StaticFlowControlDepth + + "\n NumInstructionSlots = " + NumInstructionSlots; + } +} \ No newline at end of file Added: trunk/LWJGL/src/java/org/lwjgl/d3d/D3DPresentParameters.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/d3d/D3DPresentParameters.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/d3d/D3DPresentParameters.java 2007-08-22 23:11:02 UTC (rev 2882) @@ -0,0 +1,88 @@ +package org.lwjgl.d3d; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +public class D3DPresentParameters { + public int BackBufferWidth; //4 UINT + public int BackBufferHeight; //4 UINT + public int BackBufferFormat; //4 D3DFORMAT + public int BackBufferCount; //4 UINT + public int MultiSampleType; //4 D3DMULTISAMPLE_TYPE + public int MultiSampleQuality; //4 DWORD + public int SwapEffect; //4 D3DSWAPEFFECT + public long hDeviceWindow; //4 HWND + public boolean Windowed; //4 + public boolean EnableAutoDepthStencil; //4 + public int AutoDepthStencilFormat; //4 D3DFORMAT + public long Flags; //4 DWORD + public int FullScreen_RefreshRateInHz; //4 UINT + public int PresentationInterval; //4 UI... [truncated message content] |