mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-01-06 08:49:56 +01:00
Ported codebase to Java 1.5.
Misc OpenCL fixes and API improvements. Changed fractal demo to use events/sync objects instead of cl/glFinish for synchronization. (untested)
This commit is contained in:
parent
d17e13f24b
commit
a8bcb7fd25
117
build.xml
117
build.xml
|
|
@ -16,74 +16,88 @@
|
|||
<!-- Initialize build -->
|
||||
<!-- ================================================================== -->
|
||||
<target name="-initialize">
|
||||
<mkdir dir="${lwjgl.bin}" taskname="initialiazing bin folder" />
|
||||
<mkdir dir="${lwjgl.bin}/lwjgl" taskname="initialiazing bin folder" />
|
||||
<mkdir dir="${lwjgl.lib}" taskname="initialiazing lib folder" />
|
||||
<mkdir dir="${lwjgl.dist}" taskname="initialiazing dist folder" />
|
||||
<mkdir dir="${lwjgl.docs}/javadoc" taskname="initialiazing docs folder" />
|
||||
<mkdir dir="${lwjgl.res}" taskname="initialiazing res folder" />
|
||||
<mkdir dir="${lwjgl.temp}" taskname="initialiazing temp folder" />
|
||||
<mkdir dir="${lwjgl.temp}/jar" taskname="initialiazing temp/jar folder" />
|
||||
<mkdir dir="${lwjgl.temp}/doc" taskname="initialiazing temp/doc folder" />
|
||||
<mkdir dir="${lwjgl.temp}/res" taskname="initialiazing temp/res folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native" taskname="initialiazing temp/native folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/windows" taskname="initialiazing temp/windows folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/linux" taskname="initialiazing temp/linux folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/macosx" taskname="initialiazing temp/macosx folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/solaris" taskname="initialiazing temp/solaris folder" />
|
||||
<mkdir dir="${lwjgl.bin}" taskname="initialiazing bin folder" />
|
||||
<mkdir dir="${lwjgl.bin}/lwjgl" taskname="initialiazing native bin folder" />
|
||||
<mkdir dir="${lwjgl.lib}" taskname="initialiazing lib folder" />
|
||||
<mkdir dir="${lwjgl.dist}" taskname="initialiazing dist folder" />
|
||||
<mkdir dir="${lwjgl.docs}/javadoc" taskname="initialiazing docs folder" />
|
||||
<mkdir dir="${lwjgl.res}" taskname="initialiazing res folder" />
|
||||
<mkdir dir="${lwjgl.temp}" taskname="initialiazing temp folder" />
|
||||
<mkdir dir="${lwjgl.temp}/jar" taskname="initialiazing temp/jar folder" />
|
||||
<mkdir dir="${lwjgl.temp}/doc" taskname="initialiazing temp/doc folder" />
|
||||
<mkdir dir="${lwjgl.temp}/res" taskname="initialiazing temp/res folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native" taskname="initialiazing temp/native folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/windows" taskname="initialiazing temp/windows folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/linux" taskname="initialiazing temp/linux folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/macosx" taskname="initialiazing temp/macosx folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/solaris" taskname="initialiazing temp/solaris folder" />
|
||||
</target>
|
||||
|
||||
<!-- Cleans up any files created during the execution of this script -->
|
||||
<target name="clean" description="Cleans the directories controlled by this ant script" depends="clean-generated">
|
||||
<delete dir="${lwjgl.temp}" quiet="true" failonerror="false" taskname="cleaning temp folder" />
|
||||
<delete dir="${lwjgl.docs}/javadoc" quiet="true" failonerror="false" taskname="cleaning javadoc folder" />
|
||||
<delete dir="${lwjgl.bin}" quiet="true" failonerror="false" taskname="cleaning bin folder" />
|
||||
<!-- Delete java classes only to avoid unnecessary native recompilation -->
|
||||
<delete dir="${lwjgl.bin}/org" quiet="true" failonerror="false" taskname="cleaning bin folder" />
|
||||
</target>
|
||||
|
||||
<!-- Useful when we need to force native recompilation -->
|
||||
<target name="clean-native" description="Cleans bin folder's native directory" depends="clean-generated-native">
|
||||
<delete dir="${lwjgl.bin}/lwjgl" quiet="true" failonerror="false" taskname="cleaning native bin folder" />
|
||||
<mkdir dir="${lwjgl.bin}/lwjgl" taskname="initialiazing native bin folder" />
|
||||
</target>
|
||||
|
||||
<target name="clean-all" depends="clean, clean-generated-native" description="Cleans all directories controlled by this ant script">
|
||||
<delete dir="${lwjgl.bin}/lwjgl" quiet="true" failonerror="false" taskname="cleaning native bin folder" />
|
||||
</target>
|
||||
|
||||
<!-- Creates a distribution of LWJGL -->
|
||||
<target name="release" description="Creates a distribution of LWJGL using supplied native binaries">
|
||||
<!-- Warn user -->
|
||||
<echo message="Before running the release target, please manually compile all platforms and place required files in ${lwjgl.lib}/windows, ${lwjgl.lib}/linux and ${lwjgl.lib}/macosx${line.separator}Missing files will result in a successfull built, but with incomplete release zips"/>
|
||||
<input
|
||||
message="All data in the ${lwjgl.dist} folder will be deleted. Continue? "
|
||||
validargs="yes,no"
|
||||
addproperty="do.delete"
|
||||
/>
|
||||
<condition property="do.abort">
|
||||
<equals arg1="no" arg2="${do.delete}"/>
|
||||
</condition>
|
||||
<fail if="do.abort">Build aborted by user.</fail>
|
||||
<input
|
||||
message="All data in the ${lwjgl.dist} folder will be deleted. Continue? "
|
||||
validargs="yes,no"
|
||||
addproperty="do.delete"
|
||||
/>
|
||||
<condition property="do.abort">
|
||||
<equals arg1="no" arg2="${do.delete}"/>
|
||||
</condition>
|
||||
<fail if="do.abort">Build aborted by user.</fail>
|
||||
|
||||
<!-- prepare -->
|
||||
<delete dir="${lwjgl.dist}" quiet="true" failonerror="false" />
|
||||
<antcall target="clean" />
|
||||
<antcall target="-initialize" />
|
||||
<!-- prepare -->
|
||||
<delete dir="${lwjgl.dist}" quiet="true" failonerror="false" />
|
||||
<antcall target="clean" />
|
||||
<antcall target="-initialize" />
|
||||
|
||||
<!-- compile and create debug jars -->
|
||||
<antcall target="generate-debug" />
|
||||
<antcall target="compile" />
|
||||
<antcall target="-createdebugjars" />
|
||||
|
||||
<!-- compile and create jars -->
|
||||
<antcall target="generate-debug"/>
|
||||
<antcall target="compile" />
|
||||
<antcall target="-createdebugjars" />
|
||||
<!-- Generator will skip all templates if we don't clean -->
|
||||
<delete dir="${lwjgl.bin}" quiet="true" failonerror="false" taskname="cleaning bin folder" />
|
||||
<mkdir dir="${lwjgl.bin}" taskname="initialiazing bin folder" />
|
||||
<antcall target="generate-all"/>
|
||||
<antcall target="compile" />
|
||||
<antcall target="-createjars" />
|
||||
<antcall target="-jars_NoDEP" />
|
||||
<antcall target="javadoc" />
|
||||
<antcall target="applet-release" />
|
||||
<delete dir="${lwjgl.bin}/org" quiet="true" failonerror="false" taskname="cleaning bin folder" />
|
||||
|
||||
<!-- copy resources to res folder -->
|
||||
<copy todir="${lwjgl.temp}/res">
|
||||
<fileset dir="res"/>
|
||||
</copy>
|
||||
<!-- compile and create jars -->
|
||||
<antcall target="generate-all" />
|
||||
<antcall target="compile" />
|
||||
<antcall target="-createjars" />
|
||||
|
||||
<!-- copy docs -->
|
||||
<antcall target="-jars_NoDEP" />
|
||||
<antcall target="javadoc" />
|
||||
<antcall target="applet-release" />
|
||||
|
||||
<!-- copy resources to res folder -->
|
||||
<copy todir="${lwjgl.temp}/res">
|
||||
<fileset dir="res"/>
|
||||
</copy>
|
||||
|
||||
<!-- copy docs -->
|
||||
<copy todir="${lwjgl.temp}/doc">
|
||||
<fileset dir="${lwjgl.docs}">
|
||||
<patternset refid="lwjgl-docs.fileset" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</copy>
|
||||
|
||||
<!-- create distribution from files in libs/ and temp/ -->
|
||||
<antcall target="-distribution_javadoc" />
|
||||
|
|
@ -219,7 +233,7 @@
|
|||
<class name="org.lwjgl.opengl.LinuxContextImplementation" />
|
||||
<class name="org.lwjgl.opengl.LinuxCanvasImplementation" />
|
||||
</javah>
|
||||
|
||||
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/windows" force="yes">
|
||||
<class name="org.lwjgl.opengl.WindowsKeyboard" />
|
||||
<class name="org.lwjgl.opengl.WindowsPbufferPeerInfo" />
|
||||
|
|
@ -231,7 +245,7 @@
|
|||
<class name="org.lwjgl.opengl.WindowsDisplayPeerInfo" />
|
||||
<class name="org.lwjgl.opengl.WindowsContextImplementation" />
|
||||
</javah>
|
||||
|
||||
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/macosx" force="yes">
|
||||
<class name="org.lwjgl.MacOSXSysImplementation" />
|
||||
<class name="org.lwjgl.opengl.MacOSXMouseEventQueue" />
|
||||
|
|
@ -241,7 +255,7 @@
|
|||
<class name="org.lwjgl.opengl.MacOSXDisplay" />
|
||||
<class name="org.lwjgl.opengl.MacOSXContextImplementation" />
|
||||
</javah>
|
||||
|
||||
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}" force="yes">
|
||||
<class name="org.lwjgl.opengl.AWTSurfaceLock" />
|
||||
<class name="org.lwjgl.DefaultSysImplementation" />
|
||||
|
|
@ -342,6 +356,7 @@
|
|||
<!-- Compiles the Java source code -->
|
||||
<target name="compile" description="Compiles the java source code" depends="-initialize">
|
||||
<javac debug="yes" destdir="${lwjgl.bin}" source="1.5" target="1.5" classpath="${lwjgl.lib}/jinput.jar:${lwjgl.lib}/AppleJavaExtensions.jar" taskname="core">
|
||||
<!--<compilerarg value="-Xlint:unchecked"/>-->
|
||||
<src path="${lwjgl.src}/java/"/>
|
||||
<src path="${lwjgl.src}/generated/"/>
|
||||
<include name="org/lwjgl/*.java"/>
|
||||
|
|
@ -493,7 +508,7 @@
|
|||
|
||||
<!-- Creates the Javadoc -->
|
||||
<target name="javadoc" description="Creates javadoc from java source code">
|
||||
<javadoc destdir="${lwjgl.docs}/javadoc" classpath="${lwjgl.lib}/jinput.jar" author="true" version="true" use="true" source="1.4" windowtitle="LWJGL API" useexternalfile="true">
|
||||
<javadoc destdir="${lwjgl.docs}/javadoc" classpath="${lwjgl.lib}/jinput.jar" author="true" version="true" use="true" source="1.5" windowtitle="LWJGL API" useexternalfile="true">
|
||||
<fileset refid="lwjgl.javadoc.fileset" />
|
||||
<doctitle><![CDATA[<h1>Lightweight Java Game Toolkit</h1>]]></doctitle>
|
||||
<bottom><![CDATA[<i>Copyright © 2002-2009 lwjgl.org. All Rights Reserved.</i>]]></bottom>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
<project name="generator">
|
||||
|
||||
<!-- clean the generated files -->
|
||||
<target name="clean-generated" description="Deletes the generated java and native source">
|
||||
<target name="clean-generated" description="Deletes the generated java source">
|
||||
<delete quiet="true" failonerror="false">
|
||||
<fileset dir="${lwjgl.src}/generated" includes="**"/>
|
||||
<fileset dir="${lwjgl.src.native}/generated" includes="**"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="clean-generated-native" description="Deletes the generated native source">
|
||||
<delete quiet="true" failonerror="false">
|
||||
<fileset dir="${lwjgl.src.native}/generated" includes="**"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<!-- Compiles the Java generator source code -->
|
||||
<target name="generators" description="Compiles the native method generators">
|
||||
<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/util/generator/**.java" source="1.5" target="1.5" taskname="generator">
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ public class BufferChecks {
|
|||
}
|
||||
|
||||
public static void checkArray(Object[] array) {
|
||||
if ( LWJGLUtil.CHECKS && array == null )
|
||||
if ( LWJGLUtil.CHECKS && (array == null || array.length == 0) )
|
||||
throw new IllegalArgumentException("Invalid array");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ public class LWJGLUtil {
|
|||
*/
|
||||
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();
|
||||
List<String> possible_paths = new ArrayList<String>();
|
||||
|
||||
String classloader_path = getPathFromClassLoader(libname, classloader);
|
||||
if (classloader_path != null) {
|
||||
|
|
@ -346,18 +346,17 @@ public class LWJGLUtil {
|
|||
possible_paths.add(classloader_path);
|
||||
}
|
||||
|
||||
for (int i = 0; i < platform_lib_names.length; i++) {
|
||||
String platform_lib_name = platform_lib_names[i];
|
||||
for ( String platform_lib_name : platform_lib_names ) {
|
||||
String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader);
|
||||
if (lwjgl_classloader_path != null) {
|
||||
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);
|
||||
+ File.separator + platform_lib_name);
|
||||
}
|
||||
|
||||
// add Installer path
|
||||
String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath");
|
||||
if (alternative_path != null) {
|
||||
if ( alternative_path != null ) {
|
||||
possible_paths.add(alternative_path + File.separator + platform_lib_name);
|
||||
}
|
||||
|
||||
|
|
@ -365,7 +364,7 @@ public class LWJGLUtil {
|
|||
String java_library_path = getPrivilegedProperty("java.library.path");
|
||||
|
||||
StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator);
|
||||
while (st.hasMoreTokens()) {
|
||||
while ( st.hasMoreTokens() ) {
|
||||
String path = st.nextToken();
|
||||
possible_paths.add(path + File.separator + platform_lib_name);
|
||||
}
|
||||
|
|
@ -379,15 +378,13 @@ public class LWJGLUtil {
|
|||
}
|
||||
|
||||
//create needed string array
|
||||
String[] paths = new String[possible_paths.size()];
|
||||
possible_paths.toArray(paths);
|
||||
return paths;
|
||||
return possible_paths.toArray(new String[possible_paths.size()]);
|
||||
}
|
||||
|
||||
static void execPrivileged(final String[] cmd_array) throws Exception {
|
||||
try {
|
||||
Process process = (Process)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
Process process = AccessController.doPrivileged(new PrivilegedExceptionAction<Process>() {
|
||||
public Process run() throws Exception {
|
||||
return Runtime.getRuntime().exec(cmd_array);
|
||||
}
|
||||
});
|
||||
|
|
@ -401,8 +398,8 @@ public class LWJGLUtil {
|
|||
}
|
||||
|
||||
private static String getPrivilegedProperty(final String property_name) {
|
||||
return (String)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return System.getProperty(property_name);
|
||||
}
|
||||
});
|
||||
|
|
@ -422,16 +419,15 @@ public class LWJGLUtil {
|
|||
private static String getPathFromClassLoader(final String libname, final ClassLoader classloader) {
|
||||
try {
|
||||
log("getPathFromClassLoader: searching for: " + libname);
|
||||
Class c = classloader.getClass();
|
||||
Class<?> c = classloader.getClass();
|
||||
while (c != null) {
|
||||
final Class clazz = c;
|
||||
final Class<?> clazz = c;
|
||||
try {
|
||||
return (String)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
Method findLibrary = clazz.getDeclaredMethod("findLibrary", new Class[]{String.class});
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
|
||||
public String run() throws Exception {
|
||||
Method findLibrary = clazz.getDeclaredMethod("findLibrary", String.class);
|
||||
findLibrary.setAccessible(true);
|
||||
Object[] arguments = new Object[] {libname};
|
||||
String path = (String)findLibrary.invoke(classloader, arguments);
|
||||
String path = (String)findLibrary.invoke(classloader, libname);
|
||||
return path;
|
||||
}
|
||||
});
|
||||
|
|
@ -450,12 +446,12 @@ public class LWJGLUtil {
|
|||
* Gets a boolean property as a privileged action.
|
||||
*/
|
||||
private static boolean getPrivilegedBoolean(final String property_name) {
|
||||
Boolean value = (Boolean)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return new Boolean(Boolean.getBoolean(property_name));
|
||||
Boolean value = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
public Boolean run() {
|
||||
return Boolean.getBoolean(property_name);
|
||||
}
|
||||
});
|
||||
return value.booleanValue();
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ package org.lwjgl;
|
|||
* $Id$
|
||||
*/
|
||||
final class LinuxSysImplementation extends J2SESysImplementation {
|
||||
private final static int JNI_VERSION = 19;
|
||||
private static final int JNI_VERSION = 19;
|
||||
|
||||
static {
|
||||
java.awt.Toolkit.getDefaultToolkit(); // This will make sure libjawt.so is loaded
|
||||
|
|
@ -55,8 +55,7 @@ final class LinuxSysImplementation extends J2SESysImplementation {
|
|||
|
||||
String[] browsers = {"xdg-open", "firefox", "mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"};
|
||||
|
||||
for (int i = 0; i < browsers.length; i ++) {
|
||||
final String browser = browsers[i];
|
||||
for ( final String browser : browsers ) {
|
||||
try {
|
||||
LWJGLUtil.execPrivileged(new String[] { browser, url });
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ import com.apple.eio.FileManager;
|
|||
* $Id$
|
||||
*/
|
||||
final class MacOSXSysImplementation extends J2SESysImplementation {
|
||||
private final static int JNI_VERSION = 19;
|
||||
private static final int JNI_VERSION = 19;
|
||||
|
||||
static {
|
||||
// Make sure AWT is properly initialized. This avoids hangs on Mac OS X 10.3
|
||||
|
|
|
|||
|
|
@ -49,16 +49,16 @@ import java.nio.ByteOrder;
|
|||
* $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 static final int INITIAL_BUFFER_SIZE = 1;
|
||||
|
||||
private final static ThreadLocal thread_buffer = new ThreadLocal() {
|
||||
protected Object initialValue() {
|
||||
private static final ThreadLocal<CachedBuffers> thread_buffer = new ThreadLocal<CachedBuffers>() {
|
||||
protected CachedBuffers initialValue() {
|
||||
return new CachedBuffers(INITIAL_BUFFER_SIZE);
|
||||
}
|
||||
};
|
||||
|
||||
private static CachedBuffers getCachedBuffers(int minimum_byte_size) {
|
||||
CachedBuffers buffers = (CachedBuffers)thread_buffer.get();
|
||||
CachedBuffers buffers = thread_buffer.get();
|
||||
int current_byte_size = buffers.byte_buffer.capacity();
|
||||
if (minimum_byte_size > current_byte_size) {
|
||||
buffers = new CachedBuffers(minimum_byte_size);
|
||||
|
|
@ -378,7 +378,7 @@ public final class NondirectBufferWrapper {
|
|||
return direct_buffer;
|
||||
}
|
||||
|
||||
private final static class CachedBuffers {
|
||||
private static final class CachedBuffers {
|
||||
private final ByteBuffer byte_buffer;
|
||||
private final ShortBuffer short_buffer_big;
|
||||
private final IntBuffer int_buffer_big;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class PointerBuffer implements Comparable {
|
|||
boolean is64 = false;
|
||||
try {
|
||||
Method m = Class.forName("org.lwjgl.Sys").getDeclaredMethod("is64Bit", (Class[])null);
|
||||
is64 = ((Boolean)m.invoke(null, (Object[])null)).booleanValue();
|
||||
is64 = (Boolean)m.invoke(null, (Object[])null);
|
||||
} catch (Throwable t) {
|
||||
// ignore
|
||||
} finally {
|
||||
|
|
@ -63,10 +63,22 @@ public class PointerBuffer implements Comparable {
|
|||
protected final IntBuffer view32;
|
||||
protected final LongBuffer view64;
|
||||
|
||||
/**
|
||||
* Creates a new PointerBuffer with the specified capacity.
|
||||
*
|
||||
* @param capacity the PointerBuffer size, in number of pointers
|
||||
*/
|
||||
public PointerBuffer(final int capacity) {
|
||||
this(BufferUtils.createByteBuffer(capacity * getPointerSize()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PointerBuffer using the specified ByteBuffer as its pointer
|
||||
* data source. This is useful for users that do their own memory management
|
||||
* over a big ByteBuffer, instead of allocating many small ones.
|
||||
*
|
||||
* @param source the source buffer
|
||||
*/
|
||||
public PointerBuffer(final ByteBuffer source) {
|
||||
if ( !source.isDirect() )
|
||||
throw new IllegalArgumentException("ByteBuffer is not direct");
|
||||
|
|
@ -91,6 +103,11 @@ public class PointerBuffer implements Comparable {
|
|||
return pointers;
|
||||
}
|
||||
|
||||
/** Returns true if the underlying architecture is 64bit. */
|
||||
public static boolean is64Bit() {
|
||||
return is64Bit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pointer size in bytes, based on the underlying architecture.
|
||||
*
|
||||
|
|
@ -769,7 +786,7 @@ public class PointerBuffer implements Comparable {
|
|||
* @return A summary string
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(48);
|
||||
StringBuilder sb = new StringBuilder(48);
|
||||
sb.append(getClass().getName());
|
||||
sb.append("[pos=");
|
||||
sb.append(position());
|
||||
|
|
|
|||
|
|
@ -44,16 +44,30 @@ public abstract class PointerWrapperAbstract implements PointerWrapper {
|
|||
this.pointer = pointer;
|
||||
}
|
||||
|
||||
public final boolean isNull() {
|
||||
return pointer == 0;
|
||||
/**
|
||||
* Returns true if this object represents a valid pointer.
|
||||
* The pointer might be invalid because it is NULL or because
|
||||
* some other action has deleted the object that this pointer
|
||||
* represents.
|
||||
*
|
||||
* @return true if the pointer is valid
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return pointer != 0;
|
||||
}
|
||||
|
||||
public final void checkNull() {
|
||||
if ( LWJGLUtil.DEBUG && pointer == 0 )
|
||||
throw new IllegalStateException("This pointer is null.");
|
||||
/**
|
||||
* Checks if the pointer is valid and throws an IllegalStateException if
|
||||
* it is not. This method is a NO-OP, unless the org.lwjgl.util.Debug
|
||||
* property has been set to true.
|
||||
*/
|
||||
public final void checkValid() {
|
||||
if ( LWJGLUtil.DEBUG && !isValid() )
|
||||
throw new IllegalStateException("This pointer is not valid.");
|
||||
}
|
||||
|
||||
public long getPointer() {
|
||||
public final long getPointer() {
|
||||
checkValid();
|
||||
return pointer;
|
||||
}
|
||||
|
||||
|
|
@ -72,4 +86,7 @@ public abstract class PointerWrapperAbstract implements PointerWrapper {
|
|||
return (int)(pointer ^ (pointer >>> 32));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + " pointer (0x" + Long.toHexString(pointer) + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ public final class Sys {
|
|||
private static final boolean is64Bit;
|
||||
|
||||
private static void doLoadLibrary(final String lib_name) {
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
String library_path = System.getProperty("org.lwjgl.librarypath");
|
||||
if (library_path != null) {
|
||||
|
|
@ -215,22 +215,22 @@ public final class Sys {
|
|||
// Attempt to use Webstart if we have it available
|
||||
try {
|
||||
// Lookup the javax.jnlp.BasicService object
|
||||
final Class serviceManagerClass = Class.forName("javax.jnlp.ServiceManager");
|
||||
Method lookupMethod = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
return serviceManagerClass.getMethod("lookup", new Class[] {String.class});
|
||||
final Class<?> serviceManagerClass = Class.forName("javax.jnlp.ServiceManager");
|
||||
Method lookupMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||
public Method run() throws Exception {
|
||||
return serviceManagerClass.getMethod("lookup", String.class);
|
||||
}
|
||||
});
|
||||
Object basicService = lookupMethod.invoke(serviceManagerClass, new Object[] {"javax.jnlp.BasicService"});
|
||||
final Class basicServiceClass = Class.forName("javax.jnlp.BasicService");
|
||||
Method showDocumentMethod = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
return basicServiceClass.getMethod("showDocument", new Class[] {URL.class});
|
||||
final Class<?> basicServiceClass = Class.forName("javax.jnlp.BasicService");
|
||||
Method showDocumentMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||
public Method run() throws Exception {
|
||||
return basicServiceClass.getMethod("showDocument", URL.class);
|
||||
}
|
||||
});
|
||||
try {
|
||||
Boolean ret = (Boolean) showDocumentMethod.invoke(basicService, new Object[] {new URL(url)});
|
||||
return ret.booleanValue();
|
||||
Boolean ret = (Boolean)showDocumentMethod.invoke(basicService, new URL(url));
|
||||
return ret;
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace(System.err);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -45,12 +45,12 @@ import org.lwjgl.opengl.Display;
|
|||
* $Id$
|
||||
*/
|
||||
final class WindowsSysImplementation extends DefaultSysImplementation {
|
||||
private final static int JNI_VERSION = 23;
|
||||
private static final int JNI_VERSION = 23;
|
||||
|
||||
static {
|
||||
Sys.initialize();
|
||||
}
|
||||
|
||||
|
||||
public int getRequiredJNIVersion() {
|
||||
return JNI_VERSION;
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ final class WindowsSysImplementation extends DefaultSysImplementation {
|
|||
}
|
||||
private static native long nGetTime();
|
||||
|
||||
public final boolean has64Bit() {
|
||||
public boolean has64Bit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -75,19 +75,17 @@ final class WindowsSysImplementation extends DefaultSysImplementation {
|
|||
* public
|
||||
*/
|
||||
try {
|
||||
Long hwnd_obj = (Long)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation", null);
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<Long>() {
|
||||
public Long run() throws Exception {
|
||||
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation");
|
||||
getImplementation_method.setAccessible(true);
|
||||
Object display_impl = getImplementation_method.invoke(null, null);
|
||||
Class WindowsDisplay_class = Class.forName("org.lwjgl.opengl.WindowsDisplay");
|
||||
Method getHwnd_method = WindowsDisplay_class.getDeclaredMethod("getHwnd", null);
|
||||
Object display_impl = getImplementation_method.invoke(null);
|
||||
Class<?> WindowsDisplay_class = Class.forName("org.lwjgl.opengl.WindowsDisplay");
|
||||
Method getHwnd_method = WindowsDisplay_class.getDeclaredMethod("getHwnd");
|
||||
getHwnd_method.setAccessible(true);
|
||||
Long hwnd = (Long)getHwnd_method.invoke(display_impl, null);
|
||||
return hwnd;
|
||||
return (Long)getHwnd_method.invoke(display_impl);
|
||||
}
|
||||
});
|
||||
return hwnd_obj.longValue();
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -35,7 +35,8 @@ import org.lwjgl.Sys;
|
|||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.openal.AL;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -46,24 +47,24 @@ import org.lwjgl.opengl.GL11;
|
|||
* $Id$
|
||||
*/
|
||||
public class Game {
|
||||
|
||||
|
||||
/** Game title */
|
||||
public static final String GAME_TITLE = "My Game";
|
||||
|
||||
|
||||
/** Desired frame time */
|
||||
private static final int FRAMERATE = 60;
|
||||
|
||||
|
||||
/** Exit the game */
|
||||
private static boolean finished;
|
||||
|
||||
|
||||
/** A rotating square! */
|
||||
private static float angle;
|
||||
|
||||
|
||||
/**
|
||||
* No constructor needed - this class is static
|
||||
*/
|
||||
private Game() {}
|
||||
|
||||
|
||||
/**
|
||||
* Application init
|
||||
* @param args Commandline args
|
||||
|
|
@ -78,10 +79,10 @@ public class Game {
|
|||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the game
|
||||
* @throws Exception if init fails
|
||||
|
|
@ -94,25 +95,25 @@ public class Game {
|
|||
|
||||
// Enable vsync if we can
|
||||
Display.setVSyncEnabled(true);
|
||||
|
||||
|
||||
Display.create();
|
||||
|
||||
|
||||
// Start up the sound system
|
||||
AL.create();
|
||||
|
||||
|
||||
// TODO: Load in your textures etc here
|
||||
|
||||
|
||||
// Put the window into orthographic projection mode with 1:1 pixel ratio.
|
||||
// We haven't used GLU here to do this to avoid an unnecessary dependency.
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glOrtho(0.0, Display.getDisplayMode().getWidth(), 0.0, Display.getDisplayMode().getHeight(), -1.0, 1.0);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0.0, Display.getDisplayMode().getWidth(), 0.0, Display.getDisplayMode().getHeight(), -1.0, 1.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs the game (the "main loop")
|
||||
*/
|
||||
|
|
@ -120,7 +121,7 @@ public class Game {
|
|||
while (!finished) {
|
||||
// Always call Window.update(), all the time
|
||||
Display.update();
|
||||
|
||||
|
||||
if (Display.isCloseRequested()) {
|
||||
// Check for O/S close requests
|
||||
finished = true;
|
||||
|
|
@ -144,7 +145,7 @@ public class Game {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do any game-specific cleanup
|
||||
*/
|
||||
|
|
@ -153,11 +154,11 @@ public class Game {
|
|||
|
||||
// Stop the sound
|
||||
AL.destroy();
|
||||
|
||||
|
||||
// Close the window
|
||||
Display.destroy();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do all calculations, handle input, etc.
|
||||
*/
|
||||
|
|
@ -170,24 +171,24 @@ public class Game {
|
|||
// TODO: all your game logic goes here.
|
||||
angle += 2.0f % 360;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the current frame
|
||||
*/
|
||||
private static void render() {
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
// TODO: all your rendering goes here
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);
|
||||
GL11.glRotatef(angle, 0, 0, 1.0f);
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glVertex2i(-50, -50);
|
||||
GL11.glVertex2i(50, -50);
|
||||
GL11.glVertex2i(50, 50);
|
||||
GL11.glVertex2i(-50, 50);
|
||||
GL11.glEnd();
|
||||
GL11.glPopMatrix();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glPushMatrix();
|
||||
glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);
|
||||
glRotatef(angle, 0, 0, 1.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2i(-50, -50);
|
||||
glVertex2i(50, -50);
|
||||
glVertex2i(50, 50);
|
||||
glVertex2i(-50, 50);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -37,13 +37,13 @@ import java.awt.Rectangle;
|
|||
* An entity represents any element that appears in the game. The
|
||||
* entity is responsible for resolving collisions and movement
|
||||
* based on a set of properties defined either by subclass or externally.
|
||||
*
|
||||
*
|
||||
* Note that doubles are used for positions. This may seem strange
|
||||
* given that pixels locations are integers. However, using double means
|
||||
* that an entity can move a partial pixel. It doesn't of course mean that
|
||||
* they will be display half way through a pixel but allows us not lose
|
||||
* accuracy as we move.
|
||||
*
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
public abstract class Entity {
|
||||
|
|
@ -71,12 +71,12 @@ public abstract class Entity {
|
|||
|
||||
/**
|
||||
* Construct a entity based on a sprite image and a location.
|
||||
*
|
||||
* @param ref The reference to the image to be displayed for this entity
|
||||
*
|
||||
* @param sprite The reference to the image to be displayed for this entity
|
||||
* @param x The initial x location of this entity
|
||||
* @param y The initial y location of this entity
|
||||
*/
|
||||
public Entity(Sprite sprite, int x, int y) {
|
||||
protected Entity(Sprite sprite, int x, int y) {
|
||||
this.sprite = sprite;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
|
@ -85,7 +85,7 @@ public abstract class Entity {
|
|||
/**
|
||||
* Request that this entity move itself based on a certain ammount
|
||||
* of time passing.
|
||||
*
|
||||
*
|
||||
* @param delta The ammount of time that has passed in milliseconds
|
||||
*/
|
||||
public void move(long delta) {
|
||||
|
|
@ -96,7 +96,7 @@ public abstract class Entity {
|
|||
|
||||
/**
|
||||
* Set the horizontal speed of this entity
|
||||
*
|
||||
*
|
||||
* @param dx The horizontal speed of this entity (pixels/sec)
|
||||
*/
|
||||
public void setHorizontalMovement(float dx) {
|
||||
|
|
@ -105,7 +105,7 @@ public abstract class Entity {
|
|||
|
||||
/**
|
||||
* Set the vertical speed of this entity
|
||||
*
|
||||
*
|
||||
* @param dy The vertical speed of this entity (pixels/sec)
|
||||
*/
|
||||
public void setVerticalMovement(float dy) {
|
||||
|
|
@ -114,7 +114,7 @@ public abstract class Entity {
|
|||
|
||||
/**
|
||||
* Get the horizontal speed of this entity
|
||||
*
|
||||
*
|
||||
* @return The horizontal speed of this entity (pixels/sec)
|
||||
*/
|
||||
public float getHorizontalMovement() {
|
||||
|
|
@ -123,7 +123,7 @@ public abstract class Entity {
|
|||
|
||||
/**
|
||||
* Get the vertical speed of this entity
|
||||
*
|
||||
*
|
||||
* @return The vertical speed of this entity (pixels/sec)
|
||||
*/
|
||||
public float getVerticalMovement() {
|
||||
|
|
@ -146,7 +146,7 @@ public abstract class Entity {
|
|||
|
||||
/**
|
||||
* Get the x location of this entity
|
||||
*
|
||||
*
|
||||
* @return The x location of this entity
|
||||
*/
|
||||
public int getX() {
|
||||
|
|
@ -155,7 +155,7 @@ public abstract class Entity {
|
|||
|
||||
/**
|
||||
* Get the y location of this entity
|
||||
*
|
||||
*
|
||||
* @return The y location of this entity
|
||||
*/
|
||||
public int getY() {
|
||||
|
|
@ -164,7 +164,7 @@ public abstract class Entity {
|
|||
|
||||
/**
|
||||
* Check if this entity collised with another.
|
||||
*
|
||||
*
|
||||
* @param other The other entity to check collision against
|
||||
* @return True if the entities collide with each other
|
||||
*/
|
||||
|
|
@ -177,7 +177,7 @@ public abstract class Entity {
|
|||
|
||||
/**
|
||||
* Notification that this entity collided with another.
|
||||
*
|
||||
*
|
||||
* @param other The entity with which this entity collided.
|
||||
*/
|
||||
public abstract void collidedWith(Entity other);
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -39,32 +39,33 @@ import org.lwjgl.input.Keyboard;
|
|||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/**
|
||||
* The main hook of our game. This class with both act as a manager
|
||||
* for the display and central mediator for the game logic.
|
||||
*
|
||||
* for the display and central mediator for the game logic.
|
||||
*
|
||||
* Display management will consist of a loop that cycles round all
|
||||
* entities in the game asking them to move and then drawing them
|
||||
* in the appropriate place. With the help of an inner class it
|
||||
* will also allow the player to control the main ship.
|
||||
*
|
||||
*
|
||||
* As a mediator it will be informed when entities within our game
|
||||
* detect events (e.g. alient killed, played died) and will take
|
||||
* appropriate game actions.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* NOTE:<br>
|
||||
* This game is a LWJGLized implementation of the Space Invaders game by Kevin
|
||||
* Glass. The original implementation is renderer agnostic and supports other
|
||||
* Glass. The original implementation is renderer agnostic and supports other
|
||||
* OpenGL implementations as well as Java2D. This version has been made specific
|
||||
* for LWJGL, and has added input control as well as sound (which the original doesn't,
|
||||
* for LWJGL, and has added input control as well as sound (which the original doesn't,
|
||||
* at the time of writing).
|
||||
* You can find the original article here:<br>
|
||||
* <a href="http://www.cokeandcode.com/" target="_blank">http://www.cokeandcode.com</a>
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Kevin Glass
|
||||
* @author Brian Matzon
|
||||
*/
|
||||
|
|
@ -83,10 +84,10 @@ public class Game {
|
|||
private TextureLoader textureLoader;
|
||||
|
||||
/** The list of all the entities that exist in our game */
|
||||
private ArrayList entities = new ArrayList();
|
||||
private ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||
|
||||
/** The list of entities that need to be removed from the game this loop */
|
||||
private ArrayList removeList = new ArrayList();
|
||||
private ArrayList<Entity> removeList = new ArrayList<Entity>();
|
||||
|
||||
/** The entity representing the player */
|
||||
private ShipEntity ship;
|
||||
|
|
@ -113,7 +114,7 @@ public class Game {
|
|||
private float moveSpeed = 300;
|
||||
|
||||
/** The time at which last fired a shot */
|
||||
private long lastFire = 0;
|
||||
private long lastFire;
|
||||
|
||||
/** The interval between our players shot (ms) */
|
||||
private long firingInterval = 500;
|
||||
|
|
@ -125,16 +126,16 @@ public class Game {
|
|||
private boolean waitingForKeyPress = true;
|
||||
|
||||
/** True if game logic needs to be applied this loop, normally as a result of a game event */
|
||||
private boolean logicRequiredThisLoop = false;
|
||||
private boolean logicRequiredThisLoop;
|
||||
|
||||
/** The time at which the last rendering looped started from the point of view of the game logic */
|
||||
private long lastLoopTime = getTime();
|
||||
|
||||
/** True if the fire key has been released */
|
||||
private boolean fireHasBeenReleased = false;
|
||||
private boolean fireHasBeenReleased;
|
||||
|
||||
/** The time since the last record of fps */
|
||||
private long lastFpsTime = 0;
|
||||
private long lastFpsTime;
|
||||
|
||||
/** The recorded fps */
|
||||
private int fps;
|
||||
|
|
@ -167,15 +168,14 @@ public class Game {
|
|||
|
||||
/** Mouse movement on x axis */
|
||||
private int mouseX;
|
||||
|
||||
|
||||
/** Is this an application or applet */
|
||||
private static boolean isApplication = false;
|
||||
private static boolean isApplication;
|
||||
|
||||
/**
|
||||
* Construct our game and set it running.
|
||||
* @param fullscreen
|
||||
*
|
||||
* @param renderingType The type of rendering to use (should be one of the contansts from ResourceFactory)
|
||||
*
|
||||
*/
|
||||
public Game(boolean fullscreen) {
|
||||
this.fullscreen = fullscreen;
|
||||
|
|
@ -184,7 +184,7 @@ public class Game {
|
|||
|
||||
/**
|
||||
* Get the high resolution time in milliseconds
|
||||
*
|
||||
*
|
||||
* @return The high resolution time in milliseconds
|
||||
*/
|
||||
public static long getTime() {
|
||||
|
|
@ -196,8 +196,8 @@ public class Game {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sleep for a fixed number of milliseconds.
|
||||
*
|
||||
* Sleep for a fixed number of milliseconds.
|
||||
*
|
||||
* @param duration The amount of time in milliseconds to sleep for
|
||||
*/
|
||||
public static void sleep(long duration) {
|
||||
|
|
@ -217,25 +217,25 @@ public class Game {
|
|||
Display.setTitle(WINDOW_TITLE);
|
||||
Display.setFullscreen(fullscreen);
|
||||
Display.create();
|
||||
|
||||
|
||||
// grab the mouse, dont want that hideous cursor when we're playing!
|
||||
if (isApplication) {
|
||||
if (isApplication) {
|
||||
Mouse.setGrabbed(true);
|
||||
}
|
||||
|
||||
// enable textures since we're going to use these for our sprites
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// disable the OpenGL depth test since we're rendering 2D graphics
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glLoadIdentity();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
GL11.glOrtho(0, width, height, 0, -1, 1);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glViewport(0, 0, width, height);
|
||||
glOrtho(0, width, height, 0, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
textureLoader = new TextureLoader();
|
||||
|
||||
|
|
@ -289,7 +289,7 @@ public class Game {
|
|||
"height=" + height,
|
||||
"freq=" + 60,
|
||||
"bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel()
|
||||
});
|
||||
});
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -341,7 +341,7 @@ public class Game {
|
|||
/**
|
||||
* Remove an entity from the game. The entity removed will
|
||||
* no longer move or be drawn.
|
||||
*
|
||||
*
|
||||
* @param entity The entity that should be removed
|
||||
*/
|
||||
public void removeEntity(Entity entity) {
|
||||
|
|
@ -349,7 +349,7 @@ public class Game {
|
|||
}
|
||||
|
||||
/**
|
||||
* Notification that the player has died.
|
||||
* Notification that the player has died.
|
||||
*/
|
||||
public void notifyDeath() {
|
||||
if (!waitingForKeyPress) {
|
||||
|
|
@ -382,10 +382,8 @@ public class Game {
|
|||
|
||||
// if there are still some aliens left then they all need to get faster, so
|
||||
// speed up all the existing aliens
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
Entity entity = (Entity) entities.get(i);
|
||||
|
||||
if (entity instanceof AlienEntity) {
|
||||
for ( Entity entity : entities ) {
|
||||
if ( entity instanceof AlienEntity ) {
|
||||
// speed up by 2%
|
||||
entity.setHorizontalMovement(entity.getHorizontalMovement() * 1.02f);
|
||||
}
|
||||
|
|
@ -396,7 +394,7 @@ public class Game {
|
|||
|
||||
/**
|
||||
* Attempt to fire a shot from the player. Its called "try"
|
||||
* since we must first check that the player can fire at this
|
||||
* since we must first check that the player can fire at this
|
||||
* point, i.e. has he/she waited long enough between shots
|
||||
*/
|
||||
public void tryToFire() {
|
||||
|
|
@ -421,9 +419,9 @@ public class Game {
|
|||
private void gameLoop() {
|
||||
while (Game.gameRunning) {
|
||||
// clear screen
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glLoadIdentity();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
// let subsystem paint
|
||||
frameRendering();
|
||||
|
|
@ -431,7 +429,7 @@ public class Game {
|
|||
// update window contents
|
||||
Display.update();
|
||||
}
|
||||
|
||||
|
||||
// clean up
|
||||
soundManager.destroy();
|
||||
Display.destroy();
|
||||
|
|
@ -462,25 +460,23 @@ public class Game {
|
|||
|
||||
// cycle round asking each entity to move itself
|
||||
if (!waitingForKeyPress && !soundManager.isPlayingSound()) {
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
Entity entity = (Entity) entities.get(i);
|
||||
for ( Entity entity : entities ) {
|
||||
entity.move(delta);
|
||||
}
|
||||
}
|
||||
|
||||
// cycle round drawing all the entities we have in the game
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
Entity entity = (Entity) entities.get(i);
|
||||
for ( Entity entity : entities ) {
|
||||
entity.draw();
|
||||
}
|
||||
|
||||
// brute force collisions, compare every entity against
|
||||
// every other entity. If any of them collide notify
|
||||
// every other entity. If any of them collide notify
|
||||
// both entities that the collision has occured
|
||||
for (int p = 0; p < entities.size(); p++) {
|
||||
for (int s = p + 1; s < entities.size(); s++) {
|
||||
Entity me = (Entity) entities.get(p);
|
||||
Entity him = (Entity) entities.get(s);
|
||||
Entity me = entities.get(p);
|
||||
Entity him = entities.get(s);
|
||||
|
||||
if (me.collidesWith(him)) {
|
||||
me.collidedWith(him);
|
||||
|
|
@ -497,21 +493,20 @@ public class Game {
|
|||
// be resolved, cycle round every entity requesting that
|
||||
// their personal logic should be considered.
|
||||
if (logicRequiredThisLoop) {
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
Entity entity = (Entity) entities.get(i);
|
||||
for ( Entity entity : entities ) {
|
||||
entity.doLogic();
|
||||
}
|
||||
|
||||
logicRequiredThisLoop = false;
|
||||
}
|
||||
|
||||
// if we're waiting for an "any key" press then draw the
|
||||
// current message
|
||||
// if we're waiting for an "any key" press then draw the
|
||||
// current message
|
||||
if (waitingForKeyPress) {
|
||||
message.draw(325, 250);
|
||||
}
|
||||
|
||||
// resolve the movemfent of the ship. First assume the ship
|
||||
// resolve the movemfent of the ship. First assume the ship
|
||||
// isn't moving. If either cursor key is pressed then
|
||||
// update the movement appropraitely
|
||||
ship.setHorizontalMovement(0);
|
||||
|
|
@ -557,23 +552,23 @@ public class Game {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param key_left
|
||||
* @param direction
|
||||
* @return
|
||||
*/
|
||||
private boolean hasInput(int direction) {
|
||||
switch(direction) {
|
||||
case Keyboard.KEY_LEFT:
|
||||
return
|
||||
return
|
||||
Keyboard.isKeyDown(Keyboard.KEY_LEFT) ||
|
||||
mouseX < 0;
|
||||
|
||||
|
||||
case Keyboard.KEY_RIGHT:
|
||||
return
|
||||
return
|
||||
Keyboard.isKeyDown(Keyboard.KEY_RIGHT) ||
|
||||
mouseX > 0;
|
||||
|
||||
|
||||
case Keyboard.KEY_SPACE:
|
||||
return
|
||||
return
|
||||
Keyboard.isKeyDown(Keyboard.KEY_SPACE) ||
|
||||
Mouse.isButtonDown(0);
|
||||
}
|
||||
|
|
@ -584,18 +579,18 @@ public class Game {
|
|||
* The entry point into the game. We'll simply create an
|
||||
* instance of class which will start the display and game
|
||||
* loop.
|
||||
*
|
||||
*
|
||||
* @param argv The arguments that are passed into our game
|
||||
*/
|
||||
public static void main(String argv[]) {
|
||||
isApplication = true;
|
||||
System.out.println("Use -fullscreen for fullscreen mode");
|
||||
new Game((argv.length > 0 && argv[0].equalsIgnoreCase("-fullscreen"))).execute();
|
||||
new Game((argv.length > 0 && "-fullscreen".equalsIgnoreCase(argv[0]))).execute();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public void execute() {
|
||||
gameLoop();
|
||||
|
|
@ -604,7 +599,7 @@ public class Game {
|
|||
/**
|
||||
* Create or get a sprite which displays the image that is pointed
|
||||
* to in the classpath by "ref"
|
||||
*
|
||||
*
|
||||
* @param ref A reference to the image to load
|
||||
* @return A sprite that can be drawn onto the current graphics context.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -8,27 +8,27 @@ import org.lwjgl.LWJGLException;
|
|||
import org.lwjgl.opengl.Display;
|
||||
|
||||
public class GameApplet extends Applet {
|
||||
|
||||
|
||||
/** The Canvas where the LWJGL Display is added */
|
||||
Canvas display_parent;
|
||||
|
||||
|
||||
/** Thread which runs the main game loop */
|
||||
Thread gameThread;
|
||||
|
||||
|
||||
/** The Game instance */
|
||||
Game game;
|
||||
|
||||
|
||||
/**
|
||||
* Once the Canvas is created its add notify method will call this method to
|
||||
* Once the Canvas is created its add notify method will call this method to
|
||||
* start the LWJGL Display and game loop in another thread.
|
||||
*/
|
||||
public void startLWJGL() {
|
||||
gameThread = new Thread() {
|
||||
public void run() {
|
||||
|
||||
|
||||
try {
|
||||
Display.setParent(display_parent);
|
||||
|
||||
|
||||
} catch (LWJGLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -39,8 +39,8 @@ public class GameApplet extends Applet {
|
|||
};
|
||||
gameThread.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tell game loop to stop running, after which the LWJGL Display will be destoryed.
|
||||
* The main thread will wait for the Display.destroy() to complete
|
||||
|
|
@ -55,15 +55,15 @@ public class GameApplet extends Applet {
|
|||
}
|
||||
|
||||
public void start() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Applet Destroy method will remove the canvas, before canvas is destroyed it will notify
|
||||
* Applet Destroy method will remove the canvas, before canvas is destroyed it will notify
|
||||
* stopLWJGL() to stop main game loop and to destroy the Display
|
||||
*/
|
||||
public void destroy() {
|
||||
|
|
@ -71,21 +71,21 @@ public class GameApplet extends Applet {
|
|||
super.destroy();
|
||||
System.out.println("Clear up");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
|
||||
* in another thread. It will also stop the game loop and destroy the display on canvas removal when
|
||||
* in another thread. It will also stop the game loop and destroy the display on canvas removal when
|
||||
* applet is destroyed.
|
||||
*/
|
||||
public void init() {
|
||||
setLayout(new BorderLayout());
|
||||
try {
|
||||
display_parent = new Canvas() {
|
||||
public final void addNotify() {
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
startLWJGL();
|
||||
}
|
||||
public final void removeNotify() {
|
||||
public void removeNotify() {
|
||||
stopLWJGL();
|
||||
super.removeNotify();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -33,7 +33,7 @@ package org.lwjgl.examples.spaceinvaders;
|
|||
|
||||
/**
|
||||
* An entity representing a shot fired by the player's ship
|
||||
*
|
||||
*
|
||||
* @author Kevin Glass
|
||||
* @author Brian Matzon
|
||||
*/
|
||||
|
|
@ -49,11 +49,11 @@ public class ShotEntity extends Entity {
|
|||
private Game game;
|
||||
|
||||
/** True if this shot has been "used", i.e. its hit something */
|
||||
private boolean used = false;
|
||||
private boolean used;
|
||||
|
||||
/**
|
||||
* Create a new shot from the player
|
||||
*
|
||||
*
|
||||
* @param game The game in which the shot has been created
|
||||
* @param sprite The sprite representing this shot
|
||||
* @param x The initial x location of the shot
|
||||
|
|
@ -68,7 +68,7 @@ public class ShotEntity extends Entity {
|
|||
|
||||
/**
|
||||
* Reinitializes this entity, for reuse
|
||||
*
|
||||
*
|
||||
* @param x new x coordinate
|
||||
* @param y new y coordinate
|
||||
*/
|
||||
|
|
@ -80,7 +80,7 @@ public class ShotEntity extends Entity {
|
|||
|
||||
/**
|
||||
* Request that this shot moved based on time elapsed
|
||||
*
|
||||
*
|
||||
* @param delta The time that has elapsed since last move
|
||||
*/
|
||||
public void move(long delta) {
|
||||
|
|
@ -96,7 +96,7 @@ public class ShotEntity extends Entity {
|
|||
/**
|
||||
* Notification that this shot has collided with another
|
||||
* entity
|
||||
*
|
||||
*
|
||||
* @param other The other entity with which we've collided
|
||||
*/
|
||||
public void collidedWith(Entity other) {
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -54,22 +54,22 @@ public class SoundManager {
|
|||
|
||||
/** We support at most 256 buffers*/
|
||||
private int[] buffers = new int[256];
|
||||
|
||||
|
||||
/** Number of sources is limited tby user (and hardware) */
|
||||
private int[] sources;
|
||||
|
||||
|
||||
/** Our internal scratch buffer */
|
||||
private IntBuffer scratchBuffer = BufferUtils.createIntBuffer(256);
|
||||
|
||||
|
||||
/** Whether we're running in no sound mode */
|
||||
private boolean soundOutput;
|
||||
|
||||
|
||||
/** Current index in our buffers */
|
||||
private int bufferIndex;
|
||||
|
||||
|
||||
/** Current index in our source list */
|
||||
private int sourceIndex;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new SoundManager
|
||||
*/
|
||||
|
|
@ -78,13 +78,13 @@ public class SoundManager {
|
|||
|
||||
/**
|
||||
* Plays a sound effect
|
||||
* @param buffer Buffer index to play gotten from addSound
|
||||
* @param buffer Buffer index to play gotten from addSound
|
||||
*/
|
||||
public void playEffect(int buffer) {
|
||||
if(soundOutput) {
|
||||
// make sure we never choose last channel, since it is used for special sounds
|
||||
int channel = sources[(sourceIndex++ % (sources.length-1))];
|
||||
|
||||
|
||||
// link buffer and source, and play it
|
||||
AL10.alSourcei(channel, AL10.AL_BUFFER, buffers[buffer]);
|
||||
AL10.alSourcePlay(channel);
|
||||
|
|
@ -101,7 +101,7 @@ public class SoundManager {
|
|||
AL10.alSourcePlay(sources[sources.length-1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether a sound is playing on last source
|
||||
* @return true if a source is playing right now on source n
|
||||
|
|
@ -109,27 +109,27 @@ public class SoundManager {
|
|||
public boolean isPlayingSound() {
|
||||
return AL10.alGetSourcei(sources[sources.length-1], AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the SoundManager
|
||||
*
|
||||
* @param sources Number of sources to create
|
||||
*
|
||||
* @param channels Number of channels to create
|
||||
*/
|
||||
public void initialize(int channels) {
|
||||
try {
|
||||
AL.create();
|
||||
|
||||
|
||||
// allocate sources
|
||||
scratchBuffer.limit(channels);
|
||||
AL10.alGenSources(scratchBuffer);
|
||||
scratchBuffer.rewind();
|
||||
scratchBuffer.get(sources = new int[channels]);
|
||||
|
||||
|
||||
// could we allocate all channels?
|
||||
if(AL10.alGetError() != AL10.AL_NO_ERROR) {
|
||||
throw new LWJGLException("Unable to allocate " + channels + " sources");
|
||||
}
|
||||
|
||||
|
||||
// we have sound
|
||||
soundOutput = true;
|
||||
} catch (LWJGLException le) {
|
||||
|
|
@ -137,10 +137,10 @@ public class SoundManager {
|
|||
System.out.println("Sound disabled");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a sound to the Sound Managers pool
|
||||
*
|
||||
*
|
||||
* @param path Path to file to load
|
||||
* @return index into SoundManagers buffer list
|
||||
*/
|
||||
|
|
@ -149,26 +149,26 @@ public class SoundManager {
|
|||
scratchBuffer.rewind().position(0).limit(1);
|
||||
AL10.alGenBuffers(scratchBuffer);
|
||||
buffers[bufferIndex] = scratchBuffer.get(0);
|
||||
|
||||
|
||||
// load wave data from buffer
|
||||
WaveData wavefile = WaveData.create("spaceinvaders/" + path);
|
||||
|
||||
// copy to buffers
|
||||
AL10.alBufferData(buffers[bufferIndex], wavefile.format, wavefile.data, wavefile.samplerate);
|
||||
|
||||
|
||||
// unload file again
|
||||
wavefile.dispose();
|
||||
|
||||
wavefile.dispose();
|
||||
|
||||
// return index for this sound
|
||||
return bufferIndex++;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destroy this SoundManager
|
||||
*/
|
||||
public void destroy() {
|
||||
if(soundOutput) {
|
||||
|
||||
|
||||
// stop playing sounds
|
||||
scratchBuffer.position(0).limit(sources.length);
|
||||
scratchBuffer.put(sources).flip();
|
||||
|
|
@ -176,12 +176,12 @@ public class SoundManager {
|
|||
|
||||
// destroy sources
|
||||
AL10.alDeleteSources(scratchBuffer);
|
||||
|
||||
|
||||
// destroy buffers
|
||||
scratchBuffer.position(0).limit(bufferIndex);
|
||||
scratchBuffer.put(buffers, 0, bufferIndex).flip();
|
||||
AL10.alDeleteBuffers(scratchBuffer);
|
||||
|
||||
|
||||
// destory OpenAL
|
||||
AL.destroy();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -33,12 +33,12 @@ package org.lwjgl.examples.spaceinvaders;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/**
|
||||
* Implementation of sprite that uses an OpenGL quad and a texture
|
||||
* to render a given image to the screen.
|
||||
*
|
||||
*
|
||||
* @author Kevin Glass
|
||||
* @author Brian Matzon
|
||||
*/
|
||||
|
|
@ -55,8 +55,8 @@ public class Sprite {
|
|||
|
||||
/**
|
||||
* Create a new sprite from a specified image.
|
||||
*
|
||||
* @param window The window in which the sprite will be displayed
|
||||
*
|
||||
* @param loader the texture loader to use
|
||||
* @param ref A reference to the image on which this sprite should be based
|
||||
*/
|
||||
public Sprite(TextureLoader loader, String ref) {
|
||||
|
|
@ -72,7 +72,7 @@ public class Sprite {
|
|||
|
||||
/**
|
||||
* Get the width of this sprite in pixels
|
||||
*
|
||||
*
|
||||
* @return The width of this sprite in pixels
|
||||
*/
|
||||
public int getWidth() {
|
||||
|
|
@ -81,7 +81,7 @@ public class Sprite {
|
|||
|
||||
/**
|
||||
* Get the height of this sprite in pixels
|
||||
*
|
||||
*
|
||||
* @return The height of this sprite in pixels
|
||||
*/
|
||||
public int getHeight() {
|
||||
|
|
@ -90,38 +90,38 @@ public class Sprite {
|
|||
|
||||
/**
|
||||
* Draw the sprite at the specified location
|
||||
*
|
||||
*
|
||||
* @param x The x location at which to draw this sprite
|
||||
* @param y The y location at which to draw this sprite
|
||||
*/
|
||||
public void draw(int x, int y) {
|
||||
// store the current model matrix
|
||||
GL11.glPushMatrix();
|
||||
glPushMatrix();
|
||||
|
||||
// bind to the appropriate texture for this sprite
|
||||
texture.bind();
|
||||
|
||||
// translate to the right location and prepare to draw
|
||||
GL11.glTranslatef(x, y, 0);
|
||||
glTranslatef(x, y, 0);
|
||||
|
||||
// draw a quad textured to match the sprite
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
glBegin(GL_QUADS);
|
||||
{
|
||||
GL11.glTexCoord2f(0, 0);
|
||||
GL11.glVertex2f(0, 0);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2f(0, 0);
|
||||
|
||||
GL11.glTexCoord2f(0, texture.getHeight());
|
||||
GL11.glVertex2f(0, height);
|
||||
glTexCoord2f(0, texture.getHeight());
|
||||
glVertex2f(0, height);
|
||||
|
||||
GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
|
||||
GL11.glVertex2f(width, height);
|
||||
glTexCoord2f(texture.getWidth(), texture.getHeight());
|
||||
glVertex2f(width, height);
|
||||
|
||||
GL11.glTexCoord2f(texture.getWidth(), 0);
|
||||
GL11.glVertex2f(width, 0);
|
||||
glTexCoord2f(texture.getWidth(), 0);
|
||||
glVertex2f(width, 0);
|
||||
}
|
||||
GL11.glEnd();
|
||||
glEnd();
|
||||
|
||||
// restore the model view matrix to prevent contamination
|
||||
GL11.glPopMatrix();
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +1,43 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.examples.spaceinvaders;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/**
|
||||
* A texture to be bound within OpenGL. This object is responsible for
|
||||
* A texture to be bound within OpenGL. This object is responsible for
|
||||
* keeping track of a given OpenGL texture and for calculating the
|
||||
* texturing mapping coordinates of the full image.
|
||||
*
|
||||
*
|
||||
* Since textures need to be powers of 2 the actual texture may be
|
||||
* considerably bigged that the source image and hence the texture
|
||||
* mapping coordinates need to be adjusted to matchup drawing the
|
||||
|
|
@ -75,7 +75,7 @@ public class Texture {
|
|||
/**
|
||||
* Create a new texture
|
||||
*
|
||||
* @param target The GL target
|
||||
* @param target The GL target
|
||||
* @param textureID The GL texture ID
|
||||
*/
|
||||
public Texture(int target, int textureID) {
|
||||
|
|
@ -85,11 +85,9 @@ public class Texture {
|
|||
|
||||
/**
|
||||
* Bind the specified GL context to a texture
|
||||
*
|
||||
* @param gl The GL context to bind to
|
||||
*/
|
||||
public void bind() {
|
||||
GL11.glBindTexture(target, textureID);
|
||||
glBindTexture(target, textureID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -121,7 +119,7 @@ public class Texture {
|
|||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the width of the original image
|
||||
*
|
||||
* @return The width of the original image
|
||||
|
|
@ -149,7 +147,7 @@ public class Texture {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the height of this texture
|
||||
* Set the height of this texture
|
||||
*
|
||||
* @param texHeight The height of the texture
|
||||
*/
|
||||
|
|
@ -159,7 +157,7 @@ public class Texture {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the width of this texture
|
||||
* Set the width of this texture
|
||||
*
|
||||
* @param texWidth The width of the texture
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -53,14 +53,15 @@ import java.util.Hashtable;
|
|||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/**
|
||||
* A utility class to load textures for OpenGL. This source is based
|
||||
* on a texture that can be found in the Java Gaming (www.javagaming.org)
|
||||
* Wiki. It has been simplified slightly for explicit 2D graphics use.
|
||||
*
|
||||
* OpenGL uses a particular image format. Since the images that are
|
||||
*
|
||||
* OpenGL uses a particular image format. Since the images that are
|
||||
* loaded from disk may not match this format this loader introduces
|
||||
* a intermediate image which the source image is copied into. In turn,
|
||||
* this image is used as source for the OpenGL texture.
|
||||
|
|
@ -70,21 +71,19 @@ import org.lwjgl.opengl.GL11;
|
|||
*/
|
||||
public class TextureLoader {
|
||||
/** The table of textures that have been loaded in this loader */
|
||||
private HashMap table = new HashMap();
|
||||
private HashMap<String, Texture> table = new HashMap<String, Texture>();
|
||||
|
||||
/** The colour model including alpha for the GL image */
|
||||
private ColorModel glAlphaColorModel;
|
||||
|
||||
|
||||
/** The colour model for the GL image */
|
||||
private ColorModel glColorModel;
|
||||
|
||||
|
||||
/** Scratch buffer for texture ID's */
|
||||
private IntBuffer textureIDBuffer = BufferUtils.createIntBuffer(1);
|
||||
|
||||
/**
|
||||
private IntBuffer textureIDBuffer = BufferUtils.createIntBuffer(1);
|
||||
|
||||
/**
|
||||
* Create a new texture loader based on the game panel
|
||||
*
|
||||
* @param gl The GL content in which the textures should be loaded
|
||||
*/
|
||||
public TextureLoader() {
|
||||
glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
|
||||
|
|
@ -93,7 +92,7 @@ public class TextureLoader {
|
|||
false,
|
||||
ComponentColorModel.TRANSLUCENT,
|
||||
DataBuffer.TYPE_BYTE);
|
||||
|
||||
|
||||
glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
|
||||
new int[] {8,8,8,0},
|
||||
false,
|
||||
|
|
@ -101,17 +100,17 @@ public class TextureLoader {
|
|||
ComponentColorModel.OPAQUE,
|
||||
DataBuffer.TYPE_BYTE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new texture ID
|
||||
* Create a new texture ID
|
||||
*
|
||||
* @return A new texture ID
|
||||
*/
|
||||
private int createTextureID() {
|
||||
GL11.glGenTextures(textureIDBuffer);
|
||||
glGenTextures(textureIDBuffer);
|
||||
return textureIDBuffer.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a texture
|
||||
*
|
||||
|
|
@ -120,23 +119,23 @@ public class TextureLoader {
|
|||
* @throws IOException Indicates a failure to access the resource
|
||||
*/
|
||||
public Texture getTexture(String resourceName) throws IOException {
|
||||
Texture tex = (Texture) table.get(resourceName);
|
||||
|
||||
Texture tex = table.get(resourceName);
|
||||
|
||||
if (tex != null) {
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
||||
tex = getTexture(resourceName,
|
||||
GL11.GL_TEXTURE_2D, // target
|
||||
GL11.GL_RGBA, // dst pixel format
|
||||
GL11.GL_LINEAR, // min filter (unused)
|
||||
GL11.GL_LINEAR);
|
||||
|
||||
GL_TEXTURE_2D, // target
|
||||
GL_RGBA, // dst pixel format
|
||||
GL_LINEAR, // min filter (unused)
|
||||
GL_LINEAR);
|
||||
|
||||
table.put(resourceName,tex);
|
||||
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a texture into OpenGL from a image reference on
|
||||
* disk.
|
||||
|
|
@ -149,66 +148,66 @@ public class TextureLoader {
|
|||
* @return The loaded texture
|
||||
* @throws IOException Indicates a failure to access the resource
|
||||
*/
|
||||
public Texture getTexture(String resourceName,
|
||||
int target,
|
||||
int dstPixelFormat,
|
||||
int minFilter,
|
||||
int magFilter) throws IOException {
|
||||
int srcPixelFormat = 0;
|
||||
|
||||
// create the texture ID for this texture
|
||||
int textureID = createTextureID();
|
||||
Texture texture = new Texture(target,textureID);
|
||||
|
||||
// bind this texture
|
||||
GL11.glBindTexture(target, textureID);
|
||||
|
||||
BufferedImage bufferedImage = loadImage(resourceName);
|
||||
public Texture getTexture(String resourceName,
|
||||
int target,
|
||||
int dstPixelFormat,
|
||||
int minFilter,
|
||||
int magFilter) throws IOException {
|
||||
int srcPixelFormat;
|
||||
|
||||
// create the texture ID for this texture
|
||||
int textureID = createTextureID();
|
||||
Texture texture = new Texture(target,textureID);
|
||||
|
||||
// bind this texture
|
||||
glBindTexture(target, textureID);
|
||||
|
||||
BufferedImage bufferedImage = loadImage(resourceName);
|
||||
texture.setWidth(bufferedImage.getWidth());
|
||||
texture.setHeight(bufferedImage.getHeight());
|
||||
|
||||
|
||||
if (bufferedImage.getColorModel().hasAlpha()) {
|
||||
srcPixelFormat = GL11.GL_RGBA;
|
||||
srcPixelFormat = GL_RGBA;
|
||||
} else {
|
||||
srcPixelFormat = GL11.GL_RGB;
|
||||
srcPixelFormat = GL_RGB;
|
||||
}
|
||||
|
||||
// convert that image into a byte buffer of texture data
|
||||
ByteBuffer textureBuffer = convertImageData(bufferedImage,texture);
|
||||
|
||||
if (target == GL_TEXTURE_2D) {
|
||||
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilter);
|
||||
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilter);
|
||||
}
|
||||
|
||||
// convert that image into a byte buffer of texture data
|
||||
ByteBuffer textureBuffer = convertImageData(bufferedImage,texture);
|
||||
|
||||
if (target == GL11.GL_TEXTURE_2D) {
|
||||
GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
|
||||
GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter);
|
||||
}
|
||||
|
||||
// produce a texture from the byte buffer
|
||||
GL11.glTexImage2D(target,
|
||||
0,
|
||||
dstPixelFormat,
|
||||
get2Fold(bufferedImage.getWidth()),
|
||||
get2Fold(bufferedImage.getHeight()),
|
||||
0,
|
||||
srcPixelFormat,
|
||||
GL11.GL_UNSIGNED_BYTE,
|
||||
textureBuffer );
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
glTexImage2D(target,
|
||||
0,
|
||||
dstPixelFormat,
|
||||
get2Fold(bufferedImage.getWidth()),
|
||||
get2Fold(bufferedImage.getHeight()),
|
||||
0,
|
||||
srcPixelFormat,
|
||||
GL_UNSIGNED_BYTE,
|
||||
textureBuffer );
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the closest greater power of 2 to the fold number
|
||||
*
|
||||
*
|
||||
* @param fold The target number
|
||||
* @return The power of 2
|
||||
*/
|
||||
private int get2Fold(int fold) {
|
||||
private static int get2Fold(int fold) {
|
||||
int ret = 2;
|
||||
while (ret < fold) {
|
||||
ret *= 2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the buffered image to a texture
|
||||
*
|
||||
|
|
@ -216,14 +215,14 @@ public class TextureLoader {
|
|||
* @param texture The texture to store the data into
|
||||
* @return A buffer containing the data
|
||||
*/
|
||||
private ByteBuffer convertImageData(BufferedImage bufferedImage,Texture texture) {
|
||||
ByteBuffer imageBuffer = null;
|
||||
private ByteBuffer convertImageData(BufferedImage bufferedImage,Texture texture) {
|
||||
ByteBuffer imageBuffer;
|
||||
WritableRaster raster;
|
||||
BufferedImage texImage;
|
||||
|
||||
|
||||
int texWidth = 2;
|
||||
int texHeight = 2;
|
||||
|
||||
|
||||
// find the closest power of 2 for the width and height
|
||||
// of the produced texture
|
||||
while (texWidth < bufferedImage.getWidth()) {
|
||||
|
|
@ -232,10 +231,10 @@ public class TextureLoader {
|
|||
while (texHeight < bufferedImage.getHeight()) {
|
||||
texHeight *= 2;
|
||||
}
|
||||
|
||||
|
||||
texture.setTextureHeight(texHeight);
|
||||
texture.setTextureWidth(texWidth);
|
||||
|
||||
|
||||
// create a raster that can be used by OpenGL as a source
|
||||
// for a texture
|
||||
if (bufferedImage.getColorModel().hasAlpha()) {
|
||||
|
|
@ -245,41 +244,41 @@ public class TextureLoader {
|
|||
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,texWidth,texHeight,3,null);
|
||||
texImage = new BufferedImage(glColorModel,raster,false,new Hashtable());
|
||||
}
|
||||
|
||||
|
||||
// copy the source image into the produced image
|
||||
Graphics g = texImage.getGraphics();
|
||||
g.setColor(new Color(0f,0f,0f,0f));
|
||||
g.fillRect(0,0,texWidth,texHeight);
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
|
||||
// build a byte buffer from the temporary image
|
||||
// that be used by OpenGL to produce a texture.
|
||||
byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer()).getData();
|
||||
|
||||
imageBuffer = ByteBuffer.allocateDirect(data.length);
|
||||
imageBuffer.order(ByteOrder.nativeOrder());
|
||||
imageBuffer.put(data, 0, data.length);
|
||||
// build a byte buffer from the temporary image
|
||||
// that be used by OpenGL to produce a texture.
|
||||
byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer()).getData();
|
||||
|
||||
imageBuffer = ByteBuffer.allocateDirect(data.length);
|
||||
imageBuffer.order(ByteOrder.nativeOrder());
|
||||
imageBuffer.put(data, 0, data.length);
|
||||
imageBuffer.flip();
|
||||
|
||||
return imageBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
return imageBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a given resource as a buffered image
|
||||
*
|
||||
*
|
||||
* @param ref The location of the resource to load
|
||||
* @return The loaded buffered image
|
||||
* @throws IOException Indicates a failure to find a resource
|
||||
*/
|
||||
private BufferedImage loadImage(String ref) throws IOException {
|
||||
private BufferedImage loadImage(String ref) throws IOException {
|
||||
URL url = TextureLoader.class.getClassLoader().getResource(ref);
|
||||
|
||||
|
||||
if (url == null) {
|
||||
throw new IOException("Cannot find: " + ref);
|
||||
}
|
||||
|
||||
BufferedImage bufferedImage = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(ref)));
|
||||
|
||||
|
||||
BufferedImage bufferedImage = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(ref)));
|
||||
|
||||
return bufferedImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -35,239 +35,239 @@ package org.lwjgl.input;
|
|||
* A game controller of some sort that will provide input. The controller
|
||||
* presents buttons and axes. Buttons are either pressed or not pressed. Axis
|
||||
* provide analogue values.
|
||||
*
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
public interface Controller {
|
||||
/**
|
||||
* Get the name assigned to this controller.
|
||||
*
|
||||
*
|
||||
* @return The name assigned to this controller
|
||||
*/
|
||||
public String getName();
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get the index of this controller in the collection
|
||||
*
|
||||
*
|
||||
* @return The index of this controller in the collection
|
||||
*/
|
||||
public int getIndex();
|
||||
|
||||
int getIndex();
|
||||
|
||||
/**
|
||||
* Retrieve the number of buttons available on this controller
|
||||
*
|
||||
*
|
||||
* @return The number of butotns available on this controller
|
||||
*/
|
||||
public int getButtonCount();
|
||||
|
||||
int getButtonCount();
|
||||
|
||||
/**
|
||||
* Get the name of the specified button. Be warned, often this is
|
||||
* Get the name of the specified button. Be warned, often this is
|
||||
* as exciting as "Button X"
|
||||
*
|
||||
*
|
||||
* @param index The index of the button whose name should be retrieved
|
||||
* @return The name of the button requested
|
||||
*/
|
||||
public String getButtonName(int index);
|
||||
|
||||
String getButtonName(int index);
|
||||
|
||||
/**
|
||||
* Check if a button is currently pressed
|
||||
*
|
||||
*
|
||||
* @param index The button to check
|
||||
* @return True if the button is currently pressed
|
||||
*/
|
||||
public boolean isButtonPressed(int index);
|
||||
|
||||
boolean isButtonPressed(int index);
|
||||
|
||||
/**
|
||||
* Poll the controller for new data. This will also update
|
||||
* events
|
||||
*/
|
||||
public void poll();
|
||||
|
||||
/**
|
||||
void poll();
|
||||
|
||||
/**
|
||||
* Get the X-Axis value of the POV on this controller
|
||||
*
|
||||
*
|
||||
* @return The X-Axis value of the POV on this controller
|
||||
*/
|
||||
public float getPovX();
|
||||
|
||||
/**
|
||||
float getPovX();
|
||||
|
||||
/**
|
||||
* Get the Y-Axis value of the POV on this controller
|
||||
*
|
||||
*
|
||||
* @return The Y-Axis value of the POV on this controller
|
||||
*/
|
||||
public float getPovY();
|
||||
|
||||
float getPovY();
|
||||
|
||||
/**
|
||||
* Get the dead zone for a specified axis
|
||||
*
|
||||
*
|
||||
* @param index The index of the axis for which to retrieve the dead zone
|
||||
* @return The dead zone for the specified axis
|
||||
*/
|
||||
public float getDeadZone(int index);
|
||||
|
||||
float getDeadZone(int index);
|
||||
|
||||
/**
|
||||
* Set the dead zone for the specified axis
|
||||
*
|
||||
*
|
||||
* @param index The index of hte axis for which to set the dead zone
|
||||
* @param zone The dead zone to use for the specified axis
|
||||
*/
|
||||
public void setDeadZone(int index,float zone);
|
||||
|
||||
void setDeadZone(int index,float zone);
|
||||
|
||||
/**
|
||||
* Retrieve the number of axes available on this controller.
|
||||
*
|
||||
* Retrieve the number of axes available on this controller.
|
||||
*
|
||||
* @return The number of axes available on this controller.
|
||||
*/
|
||||
public int getAxisCount();
|
||||
|
||||
int getAxisCount();
|
||||
|
||||
/**
|
||||
* Get the name that's given to the specified axis
|
||||
*
|
||||
*
|
||||
* @param index The index of the axis whose name should be retrieved
|
||||
* @return The name of the specified axis.
|
||||
*/
|
||||
public String getAxisName(int index);
|
||||
|
||||
String getAxisName(int index);
|
||||
|
||||
/**
|
||||
* Retrieve the value thats currently available on a specified axis. The
|
||||
* value will always be between 1.0 and -1.0 and will calibrate as values
|
||||
* are passed read. It may be useful to get the player to wiggle the joystick
|
||||
* from side to side to get the calibration right.
|
||||
*
|
||||
* from side to side to get the calibration right.
|
||||
*
|
||||
* @param index The index of axis to be read
|
||||
* @return The value from the specified axis.
|
||||
*/
|
||||
public float getAxisValue(int index);
|
||||
|
||||
/**
|
||||
* Get the value from the X axis if there is one. If no X axis is
|
||||
* defined a zero value will be returned.
|
||||
*
|
||||
* @return The value from the X axis
|
||||
*/
|
||||
public float getXAxisValue();
|
||||
|
||||
/**
|
||||
* Get the dead zone for the X axis.
|
||||
*
|
||||
* @return The dead zone for the X axis
|
||||
*/
|
||||
public float getXAxisDeadZone();
|
||||
|
||||
/**
|
||||
* Set the dead zone for the X axis
|
||||
*
|
||||
* @param zone The dead zone to use for the X axis
|
||||
*/
|
||||
public void setXAxisDeadZone(float zone);
|
||||
float getAxisValue(int index);
|
||||
|
||||
/**
|
||||
* Get the value from the Y axis if there is one. If no Y axis is
|
||||
* Get the value from the X axis if there is one. If no X axis is
|
||||
* defined a zero value will be returned.
|
||||
*
|
||||
*
|
||||
* @return The value from the X axis
|
||||
*/
|
||||
float getXAxisValue();
|
||||
|
||||
/**
|
||||
* Get the dead zone for the X axis.
|
||||
*
|
||||
* @return The dead zone for the X axis
|
||||
*/
|
||||
float getXAxisDeadZone();
|
||||
|
||||
/**
|
||||
* Set the dead zone for the X axis
|
||||
*
|
||||
* @param zone The dead zone to use for the X axis
|
||||
*/
|
||||
void setXAxisDeadZone(float zone);
|
||||
|
||||
/**
|
||||
* Get the value from the Y axis if there is one. If no Y axis is
|
||||
* defined a zero value will be returned.
|
||||
*
|
||||
* @return The value from the Y axis
|
||||
*/
|
||||
public float getYAxisValue();
|
||||
|
||||
float getYAxisValue();
|
||||
|
||||
/**
|
||||
* Get the dead zone for the Y axis.
|
||||
*
|
||||
*
|
||||
* @return The dead zone for the Y axis
|
||||
*/
|
||||
public float getYAxisDeadZone();
|
||||
float getYAxisDeadZone();
|
||||
|
||||
/**
|
||||
* Set the dead zone for the Y axis
|
||||
*
|
||||
*
|
||||
* @param zone The dead zone to use for the Y axis
|
||||
*/
|
||||
public void setYAxisDeadZone(float zone);
|
||||
|
||||
void setYAxisDeadZone(float zone);
|
||||
|
||||
/**
|
||||
* Get the value from the Z axis if there is one. If no Z axis is
|
||||
* Get the value from the Z axis if there is one. If no Z axis is
|
||||
* defined a zero value will be returned.
|
||||
*
|
||||
*
|
||||
* @return The value from the Z axis
|
||||
*/
|
||||
public float getZAxisValue();
|
||||
|
||||
float getZAxisValue();
|
||||
|
||||
/**
|
||||
* Get the dead zone for the Z axis.
|
||||
*
|
||||
*
|
||||
* @return The dead zone for the Z axis
|
||||
*/
|
||||
public float getZAxisDeadZone();
|
||||
float getZAxisDeadZone();
|
||||
|
||||
/**
|
||||
* Set the dead zone for the Z axis
|
||||
*
|
||||
*
|
||||
* @param zone The dead zone to use for the Z axis
|
||||
*/
|
||||
public void setZAxisDeadZone(float zone);
|
||||
|
||||
void setZAxisDeadZone(float zone);
|
||||
|
||||
/**
|
||||
* Get the value from the RX axis if there is one. If no RX axis is
|
||||
* Get the value from the RX axis if there is one. If no RX axis is
|
||||
* defined a zero value will be returned.
|
||||
*
|
||||
*
|
||||
* @return The value from the RX axis
|
||||
*/
|
||||
public float getRXAxisValue();
|
||||
|
||||
float getRXAxisValue();
|
||||
|
||||
/**
|
||||
* Get the dead zone for the RX axis.
|
||||
*
|
||||
*
|
||||
* @return The dead zone for the RX axis
|
||||
*/
|
||||
public float getRXAxisDeadZone();
|
||||
float getRXAxisDeadZone();
|
||||
|
||||
/**
|
||||
* Set the dead zone for the RX axis
|
||||
*
|
||||
*
|
||||
* @param zone The dead zone to use for the RX axis
|
||||
*/
|
||||
public void setRXAxisDeadZone(float zone);
|
||||
|
||||
void setRXAxisDeadZone(float zone);
|
||||
|
||||
/**
|
||||
* Get the value from the RY axis if there is one. If no RY axis is
|
||||
* Get the value from the RY axis if there is one. If no RY axis is
|
||||
* defined a zero value will be returned.
|
||||
*
|
||||
*
|
||||
* @return The value from the RY axis
|
||||
*/
|
||||
public float getRYAxisValue();
|
||||
|
||||
float getRYAxisValue();
|
||||
|
||||
/**
|
||||
* Get the dead zone for the RY axis.
|
||||
*
|
||||
*
|
||||
* @return The dead zone for the RY axis
|
||||
*/
|
||||
public float getRYAxisDeadZone();
|
||||
float getRYAxisDeadZone();
|
||||
|
||||
/**
|
||||
* Set the dead zone for the RY axis
|
||||
*
|
||||
*
|
||||
* @param zone The dead zone to use for the RY axis
|
||||
*/
|
||||
public void setRYAxisDeadZone(float zone);
|
||||
|
||||
void setRYAxisDeadZone(float zone);
|
||||
|
||||
/**
|
||||
* Get the value from the RZ axis if there is one. If no RZ axis is
|
||||
* Get the value from the RZ axis if there is one. If no RZ axis is
|
||||
* defined a zero value will be returned.
|
||||
*
|
||||
*
|
||||
* @return The value from the RZ axis
|
||||
*/
|
||||
public float getRZAxisValue();
|
||||
|
||||
float getRZAxisValue();
|
||||
|
||||
/**
|
||||
* Get the dead zone for the RZ axis.
|
||||
*
|
||||
*
|
||||
* @return The dead zone for the RZ axis
|
||||
*/
|
||||
public float getRZAxisDeadZone();
|
||||
float getRZAxisDeadZone();
|
||||
|
||||
/**
|
||||
* Set the dead zone for the RZ axis
|
||||
*
|
||||
*
|
||||
* @param zone The dead zone to use for the RZ axis
|
||||
*/
|
||||
public void setRZAxisDeadZone(float zone);
|
||||
void setRZAxisDeadZone(float zone);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -33,7 +33,7 @@ package org.lwjgl.input;
|
|||
|
||||
/**
|
||||
* An event occuring on a controller.
|
||||
*
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
class ControllerEvent {
|
||||
|
|
@ -45,7 +45,7 @@ class ControllerEvent {
|
|||
public static final int POVX = 3;
|
||||
/** Indicates the event was caused by a pov Y */
|
||||
public static final int POVY = 4;
|
||||
|
||||
|
||||
/** The controller generating the event */
|
||||
private Controller source;
|
||||
/** The index of the input (axis or button) that generated the event */
|
||||
|
|
@ -58,10 +58,10 @@ class ControllerEvent {
|
|||
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
|
||||
|
|
@ -69,7 +69,7 @@ class ControllerEvent {
|
|||
* @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,long timeStamp, int type,int index,boolean xaxis,boolean yaxis) {
|
||||
ControllerEvent(Controller source,long timeStamp, int type,int index,boolean xaxis,boolean yaxis) {
|
||||
this.source = source;
|
||||
this.timeStamp = timeStamp;
|
||||
this.type = type;
|
||||
|
|
@ -77,38 +77,38 @@ class ControllerEvent {
|
|||
this.xaxis = xaxis;
|
||||
this.yaxis = yaxis;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public Controller getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the index of the control generating this event
|
||||
*
|
||||
*
|
||||
* @return The index of the control generating this event
|
||||
*/
|
||||
public int getControlIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if this event was generated by a button
|
||||
*
|
||||
*
|
||||
* @return True if this event was generated by a button
|
||||
*/
|
||||
public boolean isButton() {
|
||||
|
|
@ -117,7 +117,7 @@ class ControllerEvent {
|
|||
|
||||
/**
|
||||
* Check if this event was generated by a axis
|
||||
*
|
||||
*
|
||||
* @return True if this event was generated by a axis
|
||||
*/
|
||||
public boolean isAxis() {
|
||||
|
|
@ -126,25 +126,25 @@ class ControllerEvent {
|
|||
|
||||
/**
|
||||
* Check if this event was generated by a pov
|
||||
*
|
||||
*
|
||||
* @return True if this event was generated by a pov
|
||||
*/
|
||||
public boolean isPovY() {
|
||||
return type == POVY;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Check if this event was generated by a pov
|
||||
*
|
||||
*
|
||||
* @return True if this event was generated by a pov
|
||||
*/
|
||||
public boolean isPovX() {
|
||||
return type == POVX;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if this event was caused by the X axis
|
||||
*
|
||||
*
|
||||
* @return True if this event was caused by the X axis
|
||||
*/
|
||||
public boolean isXAxis() {
|
||||
|
|
@ -153,13 +153,13 @@ class ControllerEvent {
|
|||
|
||||
/**
|
||||
* Check if this event was caused by the Y axis
|
||||
*
|
||||
*
|
||||
* @return True if this event was caused by the Y axis
|
||||
*/
|
||||
public boolean isYAxis() {
|
||||
return yaxis;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -39,98 +39,92 @@ import org.lwjgl.LWJGLException;
|
|||
|
||||
/**
|
||||
* The collection of controllers currently connected.
|
||||
*
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
public class Controllers {
|
||||
/** The controllers available */
|
||||
private static ArrayList controllers = new ArrayList();
|
||||
private static ArrayList<JInputController> controllers = new ArrayList<JInputController>();
|
||||
/** The number of controllers */
|
||||
private static int controllerCount;
|
||||
|
||||
|
||||
/** The current list of events */
|
||||
private static ArrayList events = new ArrayList();
|
||||
private static ArrayList<ControllerEvent> events = new ArrayList<ControllerEvent>();
|
||||
/** The current event */
|
||||
private static ControllerEvent event;
|
||||
|
||||
|
||||
/** Whether controllers were created */
|
||||
private static boolean created;
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the controllers collection
|
||||
*
|
||||
*
|
||||
* @throws LWJGLException Indicates a failure to initialise the controller library.
|
||||
*/
|
||||
public static void create() throws LWJGLException {
|
||||
if (created)
|
||||
return;
|
||||
|
||||
|
||||
try {
|
||||
ControllerEnvironment env = ControllerEnvironment.getDefaultEnvironment();
|
||||
|
||||
|
||||
net.java.games.input.Controller[] found = env.getControllers();
|
||||
ArrayList lollers = new ArrayList();
|
||||
for (int i=0;i<found.length;i++) {
|
||||
net.java.games.input.Controller c = found[i];
|
||||
|
||||
if ((!c.getType().equals(net.java.games.input.Controller.Type.KEYBOARD)) &&
|
||||
(!c.getType().equals(net.java.games.input.Controller.Type.MOUSE))) {
|
||||
ArrayList<net.java.games.input.Controller> lollers = new ArrayList<net.java.games.input.Controller>();
|
||||
for ( net.java.games.input.Controller c : found ) {
|
||||
if ( (!c.getType().equals(net.java.games.input.Controller.Type.KEYBOARD)) &&
|
||||
(!c.getType().equals(net.java.games.input.Controller.Type.MOUSE)) ) {
|
||||
lollers.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
int length = lollers.size();
|
||||
|
||||
for (int i=0;i<length;i++) {
|
||||
net.java.games.input.Controller c = (net.java.games.input.Controller) lollers.get(i);
|
||||
|
||||
|
||||
for ( net.java.games.input.Controller c : lollers ) {
|
||||
createController(c);
|
||||
}
|
||||
|
||||
|
||||
created = true;
|
||||
} catch (Throwable e) {
|
||||
throw new LWJGLException("Failed to initialise controllers",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility to create a controller based on its potential sub-controllers
|
||||
*
|
||||
*
|
||||
* @param c The controller to add
|
||||
*/
|
||||
private static void createController(net.java.games.input.Controller c) {
|
||||
net.java.games.input.Controller[] sub = c.getControllers();
|
||||
if (sub.length == 0) {
|
||||
net.java.games.input.Controller[] subControllers = c.getControllers();
|
||||
if (subControllers.length == 0) {
|
||||
JInputController controller = new JInputController(controllerCount,c);
|
||||
|
||||
|
||||
controllers.add(controller);
|
||||
controllerCount++;
|
||||
} else {
|
||||
for (int i=0;i<sub.length;i++) {
|
||||
createController(sub[i]);
|
||||
for ( net.java.games.input.Controller sub : subControllers ) {
|
||||
createController(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a controller from the collection
|
||||
*
|
||||
*
|
||||
* @param index The index of the controller to retrieve
|
||||
* @return The controller requested
|
||||
*/
|
||||
public static Controller getController(int index) {
|
||||
return (Controller) controllers.get(index);
|
||||
return controllers.get(index);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a count of the number of controllers
|
||||
*
|
||||
*
|
||||
* @return The number of controllers available
|
||||
*/
|
||||
public static int getControllerCount() {
|
||||
return controllers.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Poll the controllers available. This will both update their state
|
||||
* and generate events that must be cleared.
|
||||
|
|
@ -140,17 +134,17 @@ public class Controllers {
|
|||
getController(i).poll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear any events stored for the controllers in this set
|
||||
*/
|
||||
public static void clearEvents() {
|
||||
events.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move to the next event that has been stored.
|
||||
*
|
||||
*
|
||||
* @return True if there is still an event to process
|
||||
*/
|
||||
public static boolean next() {
|
||||
|
|
@ -158,19 +152,19 @@ public class Controllers {
|
|||
event = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
event = (ControllerEvent) events.remove(0);
|
||||
|
||||
|
||||
event = events.remove(0);
|
||||
|
||||
return event != null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return True if Controllers has been created
|
||||
*/
|
||||
public static boolean isCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys any resources used by the controllers
|
||||
*/
|
||||
|
|
@ -185,35 +179,35 @@ public class Controllers {
|
|||
// for (int i=0;i<controllers.size();i++) {
|
||||
// //
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // cleanup
|
||||
// event = null;
|
||||
// events.clear();
|
||||
// controllers.clear();
|
||||
// controllerCount = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the source of the current event
|
||||
*
|
||||
*
|
||||
* @return The source of the current event
|
||||
*/
|
||||
public static Controller getEventSource() {
|
||||
return event.getSource();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the index of the control that caused the current event
|
||||
*
|
||||
*
|
||||
* @return The index of the control that cause the current event
|
||||
*/
|
||||
public static int getEventControlIndex() {
|
||||
return event.getControlIndex();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the current event was caused by a button
|
||||
*
|
||||
*
|
||||
* @return True if the current event was caused by a button
|
||||
*/
|
||||
public static boolean isEventButton() {
|
||||
|
|
@ -222,16 +216,16 @@ public class Controllers {
|
|||
|
||||
/**
|
||||
* Check if the current event was caused by a axis
|
||||
*
|
||||
*
|
||||
* @return True if the current event was caused by a axis
|
||||
*/
|
||||
public static boolean isEventAxis() {
|
||||
return event.isAxis();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the current event was caused by movement on the x-axis
|
||||
*
|
||||
*
|
||||
* @return True if the current event was cause by movement on the x-axis
|
||||
*/
|
||||
public static boolean isEventXAxis() {
|
||||
|
|
@ -240,43 +234,43 @@ public class Controllers {
|
|||
|
||||
/**
|
||||
* Check if the current event was caused by movement on the y-axis
|
||||
*
|
||||
*
|
||||
* @return True if the current event was caused by movement on the y-axis
|
||||
*/
|
||||
public static boolean isEventYAxis() {
|
||||
return event.isYAxis();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the current event was cause by the POV x-axis
|
||||
*
|
||||
*
|
||||
* @return True if the current event was caused by the POV x-axis
|
||||
*/
|
||||
public static boolean isEventPovX() {
|
||||
return event.isPovX();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the current event was cause by the POV x-axis
|
||||
*
|
||||
*
|
||||
* @return True if the current event was caused by the POV x-axis
|
||||
*/
|
||||
public static boolean isEventPovY() {
|
||||
return event.isPovY();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
static void addEvent(ControllerEvent event) {
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -61,12 +61,12 @@ public class Cursor {
|
|||
|
||||
/** First element to display */
|
||||
private final CursorElement[] cursors;
|
||||
|
||||
|
||||
/** Index into list of cursors */
|
||||
private int index = 0;
|
||||
private int index;
|
||||
|
||||
private boolean destroyed;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new Cursor, with the given parameters. Mouse must have been created before you can create
|
||||
* Cursor objects. Cursor images are in ARGB format, but only one bit transparancy is guaranteed to be supported.
|
||||
|
|
@ -81,7 +81,7 @@ public class Cursor {
|
|||
* @param images A buffer containing the images. The origin is at the lower left corner, like OpenGL.
|
||||
* @param delays An int buffer of animation frame delays, if numImages is greater than 1, else null
|
||||
* @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 {
|
||||
synchronized (OpenGLPackageAccess.global_lock) {
|
||||
if ((getCapabilities() & CURSOR_ONE_BIT_TRANSPARENCY) == 0)
|
||||
|
|
@ -100,8 +100,8 @@ public class Cursor {
|
|||
|
||||
Sys.initialize();
|
||||
|
||||
// Hmm
|
||||
yHotspot = height - 1 - yHotspot;
|
||||
// Hmm
|
||||
yHotspot = height - 1 - yHotspot;
|
||||
|
||||
// create cursor (or cursors if multiple images supplied)
|
||||
cursors = createCursors(width, height, xHotspot, yHotspot, numImages, images, delays);
|
||||
|
|
@ -162,14 +162,14 @@ public class Cursor {
|
|||
// create copy and flip images to match ogl
|
||||
IntBuffer images_copy = BufferUtils.createIntBuffer(images.remaining());
|
||||
flipImages(width, height, numImages, images, images_copy);
|
||||
|
||||
|
||||
// Win32 doesn't (afaik) allow for animation based cursors, except when they're
|
||||
// in the .ani format, which we don't support.
|
||||
// The cursor animation was therefor developed using java side time tracking.
|
||||
// unfortunately X flickers when changing cursor. We therefore check for either
|
||||
// Win32 or X and do accordingly. This hasn't been implemented on Mac, but we
|
||||
// might want to split it into a X/Win/Mac cursor if it gets too cluttered
|
||||
|
||||
|
||||
CursorElement[] cursors;
|
||||
switch (LWJGLUtil.getPlatform()) {
|
||||
case LWJGLUtil.PLATFORM_MACOSX:
|
||||
|
|
@ -178,7 +178,7 @@ public class Cursor {
|
|||
// create our cursor elements
|
||||
cursors = new CursorElement[numImages];
|
||||
for(int i=0; i<numImages; i++) {
|
||||
|
||||
|
||||
// iterate through the images, and make sure that the pixels are either 0xffxxxxxx or 0x00000000
|
||||
int size = width * height;
|
||||
for(int j=0; j<size; j++) {
|
||||
|
|
@ -188,7 +188,7 @@ public class Cursor {
|
|||
images_copy.put(index, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
|
|
@ -208,13 +208,13 @@ public class Cursor {
|
|||
throw new RuntimeException("Unknown OS");
|
||||
}
|
||||
return cursors;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flips the images so they're oriented according to opengl
|
||||
*
|
||||
*
|
||||
* @param width Width of image
|
||||
* @param height Height of images
|
||||
* @param height Height of images
|
||||
* @param numImages How many images to flip
|
||||
* @param images Source images
|
||||
* @param images_copy Destination images
|
||||
|
|
@ -228,7 +228,7 @@ public class Cursor {
|
|||
|
||||
/**
|
||||
* @param width Width of image
|
||||
* @param height Height of images
|
||||
* @param height Height of images
|
||||
* @param start_index index into source buffer to copy to
|
||||
* @param images Source images
|
||||
* @param images_copy Destination images
|
||||
|
|
@ -245,8 +245,8 @@ public class Cursor {
|
|||
images_copy.put(index2, temp_pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the native handle associated with the cursor object.
|
||||
*/
|
||||
|
|
@ -254,12 +254,12 @@ public class Cursor {
|
|||
checkValid();
|
||||
return cursors[index].cursorHandle;
|
||||
}
|
||||
|
||||
|
||||
private void checkValid() {
|
||||
if (destroyed)
|
||||
throw new IllegalStateException("The cursor is destroyed");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destroy the native cursor. If the cursor is current,
|
||||
* the current native cursor is set to null (the default
|
||||
|
|
@ -276,8 +276,8 @@ public class Cursor {
|
|||
// ignore
|
||||
}
|
||||
}
|
||||
for(int i=0; i<cursors.length; i++) {
|
||||
Mouse.getImplementation().destroyCursor(cursors[i].cursorHandle);
|
||||
for ( CursorElement cursor : cursors ) {
|
||||
Mouse.getImplementation().destroyCursor(cursor.cursorHandle);
|
||||
}
|
||||
destroyed = true;
|
||||
}
|
||||
|
|
@ -300,24 +300,24 @@ public class Cursor {
|
|||
return cursors.length > 1 && cursors[index].timeout < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes to the next cursor
|
||||
/**
|
||||
* Changes to the next cursor
|
||||
*/
|
||||
protected void nextCursor() {
|
||||
checkValid();
|
||||
index = ++index % cursors.length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A single cursor element, used when animating
|
||||
*/
|
||||
private static class CursorElement {
|
||||
/** Handle to cursor */
|
||||
final Object cursorHandle;
|
||||
|
||||
|
||||
/** How long a delay this element should have */
|
||||
final long delay;
|
||||
|
||||
|
||||
/** Absolute time this element times out */
|
||||
long timeout;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -34,13 +34,15 @@ package org.lwjgl.input;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import net.java.games.input.Component;
|
||||
import net.java.games.input.Component.Identifier.Axis;
|
||||
import net.java.games.input.Component.Identifier.Button;
|
||||
import net.java.games.input.Event;
|
||||
import net.java.games.input.EventQueue;
|
||||
|
||||
/**
|
||||
* A wrapper round a JInput controller that attempts to make the interface
|
||||
* more useable.
|
||||
*
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
class JInputController implements Controller {
|
||||
|
|
@ -49,11 +51,11 @@ class JInputController implements Controller {
|
|||
/** The index that has been assigned to this controller */
|
||||
private int index;
|
||||
/** The Buttons that have been detected on the JInput controller */
|
||||
private ArrayList buttons = new ArrayList();
|
||||
private ArrayList<Component> buttons = new ArrayList<Component>();
|
||||
/** The Axes that have been detected on the JInput controller */
|
||||
private ArrayList axes = new ArrayList();
|
||||
private ArrayList<Component> axes = new ArrayList<Component>();
|
||||
/** The POVs that have been detected on the JInput controller */
|
||||
private ArrayList pov = new ArrayList();
|
||||
private ArrayList<Component> pov = new ArrayList<Component>();
|
||||
/** The state of the buttons last check */
|
||||
private boolean[] buttonState;
|
||||
/** The values that were read from the pov last check */
|
||||
|
|
@ -76,72 +78,72 @@ class JInputController implements Controller {
|
|||
private int ryaxis = -1;
|
||||
/** The index of the RZ axis or -1 if no RZ axis is defined */
|
||||
private int rzaxis = -1;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new controller that wraps round a JInput controller and hopefully
|
||||
* makes it easier to use.
|
||||
*
|
||||
*
|
||||
* @param index The index this controller has been assigned to
|
||||
* @param target The target JInput controller this class is wrapping
|
||||
*/
|
||||
public JInputController(int index,net.java.games.input.Controller target) {
|
||||
JInputController(int index,net.java.games.input.Controller target) {
|
||||
this.target = target;
|
||||
this.index = index;
|
||||
|
||||
|
||||
Component[] sourceAxes = target.getComponents();
|
||||
|
||||
for (int i=0;i<sourceAxes.length;i++) {
|
||||
if (sourceAxes[i].getIdentifier() instanceof Component.Identifier.Button) {
|
||||
buttons.add(sourceAxes[i]);
|
||||
} else if (sourceAxes[i].getIdentifier().equals(Component.Identifier.Axis.POV)) {
|
||||
pov.add(sourceAxes[i]);
|
||||
|
||||
for ( Component sourceAxis : sourceAxes ) {
|
||||
if ( sourceAxis.getIdentifier() instanceof Button ) {
|
||||
buttons.add(sourceAxis);
|
||||
} else if ( sourceAxis.getIdentifier().equals(Axis.POV) ) {
|
||||
pov.add(sourceAxis);
|
||||
} else {
|
||||
axes.add(sourceAxes[i]);
|
||||
axes.add(sourceAxis);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
buttonState = new boolean[buttons.size()];
|
||||
povValues = new float[pov.size()];
|
||||
axesValue = new float[axes.size()];
|
||||
int buttonsCount = 0;
|
||||
int axesCount = 0;
|
||||
|
||||
|
||||
// initialise the state
|
||||
for (int i=0;i<sourceAxes.length;i++) {
|
||||
if (sourceAxes[i].getIdentifier() instanceof Component.Identifier.Button) {
|
||||
buttonState[buttonsCount] = sourceAxes[i].getPollData() != 0;
|
||||
for ( Component sourceAxis : sourceAxes ) {
|
||||
if ( sourceAxis.getIdentifier() instanceof Button ) {
|
||||
buttonState[buttonsCount] = sourceAxis.getPollData() != 0;
|
||||
buttonsCount++;
|
||||
} else if (sourceAxes[i].getIdentifier().equals(Component.Identifier.Axis.POV)) {
|
||||
} else if ( sourceAxis.getIdentifier().equals(Axis.POV) ) {
|
||||
// no account for POV yet
|
||||
// pov.add(sourceAxes[i]);
|
||||
} else {
|
||||
axesValue[axesCount] = sourceAxes[i].getPollData();
|
||||
if (sourceAxes[i].getIdentifier().equals(Component.Identifier.Axis.X)) {
|
||||
axesValue[axesCount] = sourceAxis.getPollData();
|
||||
if ( sourceAxis.getIdentifier().equals(Axis.X) ) {
|
||||
xaxis = axesCount;
|
||||
}
|
||||
if (sourceAxes[i].getIdentifier().equals(Component.Identifier.Axis.Y)) {
|
||||
if ( sourceAxis.getIdentifier().equals(Axis.Y) ) {
|
||||
yaxis = axesCount;
|
||||
}
|
||||
if (sourceAxes[i].getIdentifier().equals(Component.Identifier.Axis.Z)) {
|
||||
if ( sourceAxis.getIdentifier().equals(Axis.Z) ) {
|
||||
zaxis = axesCount;
|
||||
}
|
||||
if (sourceAxes[i].getIdentifier().equals(Component.Identifier.Axis.RX)) {
|
||||
if ( sourceAxis.getIdentifier().equals(Axis.RX) ) {
|
||||
rxaxis = axesCount;
|
||||
}
|
||||
if (sourceAxes[i].getIdentifier().equals(Component.Identifier.Axis.RY)) {
|
||||
if ( sourceAxis.getIdentifier().equals(Axis.RY) ) {
|
||||
ryaxis = axesCount;
|
||||
}
|
||||
if (sourceAxes[i].getIdentifier().equals(Component.Identifier.Axis.RZ)) {
|
||||
if ( sourceAxis.getIdentifier().equals(Axis.RZ) ) {
|
||||
rzaxis = axesCount;
|
||||
}
|
||||
|
||||
|
||||
axesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
axesMax = new float[axes.size()];
|
||||
deadZones = new float[axes.size()];
|
||||
|
||||
|
||||
for (int i=0;i<axesMax.length;i++) {
|
||||
axesMax[i] = 1.0f;
|
||||
deadZones[i] = 0.05f;
|
||||
|
|
@ -174,9 +176,7 @@ class JInputController implements Controller {
|
|||
* @see org.lwjgl.input.Controller#getButtonName(int)
|
||||
*/
|
||||
public String getButtonName(int index) {
|
||||
Component button = (Component) buttons.get(index);
|
||||
|
||||
return button.getName();
|
||||
return buttons.get(index).getName();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -191,10 +191,10 @@ class JInputController implements Controller {
|
|||
*/
|
||||
public void poll() {
|
||||
target.poll();
|
||||
|
||||
|
||||
Event event = new Event();
|
||||
EventQueue queue = target.getEventQueue();
|
||||
|
||||
|
||||
while (queue.getNextEvent(event)) {
|
||||
// handle button event
|
||||
if (buttons.contains(event.getComponent())) {
|
||||
|
|
@ -205,7 +205,7 @@ class JInputController implements Controller {
|
|||
// fire button pressed event
|
||||
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.BUTTON,buttonIndex,false,false));
|
||||
}
|
||||
|
||||
|
||||
// handle pov events
|
||||
if (pov.contains(event.getComponent())) {
|
||||
Component povComponent = event.getComponent();
|
||||
|
|
@ -221,13 +221,13 @@ class JInputController implements Controller {
|
|||
Controllers.addEvent(new ControllerEvent(this,event.getNanos(),ControllerEvent.POVY,0,false,false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
|
|
@ -238,7 +238,7 @@ class JInputController implements Controller {
|
|||
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
|
||||
|
|
@ -260,9 +260,7 @@ class JInputController implements Controller {
|
|||
* @see org.lwjgl.input.Controller#getAxisName(int)
|
||||
*/
|
||||
public String getAxisName(int index) {
|
||||
Component axis = (Component) axes.get(index);
|
||||
|
||||
return axis.getName();
|
||||
return axes.get(index).getName();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -279,7 +277,7 @@ class JInputController implements Controller {
|
|||
if (xaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getAxisValue(xaxis);
|
||||
}
|
||||
|
||||
|
|
@ -290,7 +288,7 @@ class JInputController implements Controller {
|
|||
if (yaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getAxisValue(yaxis);
|
||||
}
|
||||
|
||||
|
|
@ -301,7 +299,7 @@ class JInputController implements Controller {
|
|||
if (xaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getDeadZone(xaxis);
|
||||
}
|
||||
|
||||
|
|
@ -312,7 +310,7 @@ class JInputController implements Controller {
|
|||
if (yaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getDeadZone(yaxis);
|
||||
}
|
||||
|
||||
|
|
@ -351,7 +349,7 @@ class JInputController implements Controller {
|
|||
if (zaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getAxisValue(zaxis);
|
||||
}
|
||||
|
||||
|
|
@ -362,7 +360,7 @@ class JInputController implements Controller {
|
|||
if (zaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getDeadZone(zaxis);
|
||||
}
|
||||
|
||||
|
|
@ -380,7 +378,7 @@ class JInputController implements Controller {
|
|||
if (rxaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getAxisValue(rxaxis);
|
||||
}
|
||||
|
||||
|
|
@ -391,7 +389,7 @@ class JInputController implements Controller {
|
|||
if (rxaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getDeadZone(rxaxis);
|
||||
}
|
||||
|
||||
|
|
@ -409,7 +407,7 @@ class JInputController implements Controller {
|
|||
if (ryaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getAxisValue(ryaxis);
|
||||
}
|
||||
|
||||
|
|
@ -420,7 +418,7 @@ class JInputController implements Controller {
|
|||
if (ryaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getDeadZone(ryaxis);
|
||||
}
|
||||
|
||||
|
|
@ -438,7 +436,7 @@ class JInputController implements Controller {
|
|||
if (rzaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getAxisValue(rzaxis);
|
||||
}
|
||||
|
||||
|
|
@ -449,7 +447,7 @@ class JInputController implements Controller {
|
|||
if (rzaxis == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return getDeadZone(rzaxis);
|
||||
}
|
||||
|
||||
|
|
@ -467,20 +465,20 @@ class JInputController implements Controller {
|
|||
if (pov.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
float value = povValues[0];
|
||||
|
||||
if ((value == Component.POV.DOWN_LEFT) ||
|
||||
|
||||
if ((value == Component.POV.DOWN_LEFT) ||
|
||||
(value == Component.POV.UP_LEFT) ||
|
||||
(value == Component.POV.LEFT)) {
|
||||
return -1;
|
||||
}
|
||||
if ((value == Component.POV.DOWN_RIGHT) ||
|
||||
if ((value == Component.POV.DOWN_RIGHT) ||
|
||||
(value == Component.POV.UP_RIGHT) ||
|
||||
(value == Component.POV.RIGHT)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -491,22 +489,22 @@ class JInputController implements Controller {
|
|||
if (pov.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
float value = povValues[0];
|
||||
|
||||
if ((value == Component.POV.DOWN_LEFT) ||
|
||||
|
||||
if ((value == Component.POV.DOWN_LEFT) ||
|
||||
(value == Component.POV.DOWN_RIGHT) ||
|
||||
(value == Component.POV.DOWN)) {
|
||||
return 1;
|
||||
}
|
||||
if ((value == Component.POV.UP_LEFT) ||
|
||||
if ((value == Component.POV.UP_LEFT) ||
|
||||
(value == Component.POV.UP_RIGHT) ||
|
||||
(value == Component.POV.UP)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -217,25 +217,25 @@ public class Keyboard {
|
|||
|
||||
/** Key names */
|
||||
private static final String[] keyName = new String[255];
|
||||
private static final Map keyMap = new HashMap(253);
|
||||
private static final Map<String, Integer> keyMap = new HashMap<String, Integer>(253);
|
||||
private static int counter;
|
||||
|
||||
static {
|
||||
// Use reflection to find out key names
|
||||
Field[] field = Keyboard.class.getFields();
|
||||
Field[] fields = Keyboard.class.getFields();
|
||||
try {
|
||||
for (int i = 0; i < field.length; i++) {
|
||||
if (Modifier.isStatic(field[i].getModifiers())
|
||||
&& Modifier.isPublic(field[i].getModifiers())
|
||||
&& Modifier.isFinal(field[i].getModifiers())
|
||||
&& field[i].getType().equals(int.class)
|
||||
&& field[i].getName().startsWith("KEY_")) {
|
||||
for ( Field field : fields ) {
|
||||
if ( Modifier.isStatic(field.getModifiers())
|
||||
&& Modifier.isPublic(field.getModifiers())
|
||||
&& Modifier.isFinal(field.getModifiers())
|
||||
&& field.getType().equals(int.class)
|
||||
&& field.getName().startsWith("KEY_") ) {
|
||||
|
||||
int key = field[i].getInt(null);
|
||||
String name = field[i].getName().substring(4);
|
||||
int key = field.getInt(null);
|
||||
String name = field.getName().substring(4);
|
||||
keyName[key] = name;
|
||||
keyMap.put(name, new Integer(key));
|
||||
counter ++;
|
||||
keyMap.put(name, key);
|
||||
counter++;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -355,7 +355,7 @@ public class Keyboard {
|
|||
* Polls the keyboard for its current state. Access the polled values using the
|
||||
* <code>isKeyDown</code> method.
|
||||
* By using this method, it is possible to "miss" keyboard keys if you don't
|
||||
* poll fast enough.
|
||||
* poll fast enough.
|
||||
*
|
||||
* To use buffered values, you have to call <code>next</code> for each event you
|
||||
* want to read. You can query which key caused the event by using
|
||||
|
|
@ -426,11 +426,11 @@ public class Keyboard {
|
|||
* @param keyName The key name
|
||||
*/
|
||||
public static synchronized int getKeyIndex(String keyName) {
|
||||
Integer ret = (Integer) keyMap.get(keyName);
|
||||
Integer ret = keyMap.get(keyName);
|
||||
if (ret == null)
|
||||
return KEY_NONE;
|
||||
else
|
||||
return ret.intValue();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -531,7 +531,7 @@ public class Keyboard {
|
|||
* Please note that the key code returned is NOT valid against the
|
||||
* current keyboard layout. To get the actual character pressed call
|
||||
* getEventCharacter
|
||||
*
|
||||
*
|
||||
* @return The key from the current event
|
||||
*/
|
||||
public static int getEventKey() {
|
||||
|
|
@ -576,7 +576,7 @@ public class Keyboard {
|
|||
}
|
||||
}
|
||||
|
||||
private final static class KeyEvent {
|
||||
private static final class KeyEvent {
|
||||
/** The current keyboard character being examined */
|
||||
private int character;
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public class Mouse {
|
|||
private static String[] buttonName;
|
||||
|
||||
/** hashmap of button names, for fast lookup */
|
||||
private static final Map buttonMap = new HashMap(16);
|
||||
private static final Map<String, Integer> buttonMap = new HashMap<String, Integer>(16);
|
||||
|
||||
/** Lazy initialization */
|
||||
private static boolean initialized;
|
||||
|
|
@ -135,9 +135,9 @@ public class Mouse {
|
|||
private static boolean isGrabbed;
|
||||
|
||||
private static InputImplementation implementation;
|
||||
|
||||
|
||||
/** Whether we need cursor animation emulation */
|
||||
private static final boolean emulateCursorAnimation = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS ||
|
||||
private static final boolean emulateCursorAnimation = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS ||
|
||||
LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX;
|
||||
|
||||
private static final boolean allowNegativeMouseCoords = getPrivilegedBoolean("org.lwjgl.input.Mouse.allowNegativeMouseCoords");
|
||||
|
|
@ -213,7 +213,7 @@ public class Mouse {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static initialization
|
||||
*/
|
||||
|
|
@ -224,7 +224,7 @@ public class Mouse {
|
|||
buttonName = new String[16];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
buttonName[i] = "BUTTON" + i;
|
||||
buttonMap.put(buttonName[i], new Integer(i));
|
||||
buttonMap.put(buttonName[i], i);
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
|
|
@ -308,7 +308,7 @@ public class Mouse {
|
|||
* Polls the mouse for its current state. Access the polled values using the
|
||||
* get<value> methods.
|
||||
* By using this method, it is possible to "miss" mouse click events if you don't
|
||||
* poll fast enough.
|
||||
* poll fast enough.
|
||||
*
|
||||
* To use buffered values, you have to call <code>next</code> for each event you
|
||||
* want to read. You can query which button caused the event by using
|
||||
|
|
@ -401,11 +401,11 @@ public class Mouse {
|
|||
*/
|
||||
public static int getButtonIndex(String buttonName) {
|
||||
synchronized (OpenGLPackageAccess.global_lock) {
|
||||
Integer ret = (Integer) buttonMap.get(buttonName);
|
||||
Integer ret = buttonMap.get(buttonName);
|
||||
if (ret == null)
|
||||
return -1;
|
||||
else
|
||||
return ret.intValue();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -626,13 +626,13 @@ public class Mouse {
|
|||
// store location mouse was grabbed
|
||||
grab_x = x;
|
||||
grab_y = y;
|
||||
}
|
||||
}
|
||||
else if (!grab && grabbed) {
|
||||
// move mouse back to location it was grabbed before ungrabbing
|
||||
if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0)
|
||||
implementation.setCursorPosition(grab_x, grab_y);
|
||||
}
|
||||
|
||||
|
||||
implementation.grabMouse(grab);
|
||||
// Get latest values from native side
|
||||
poll();
|
||||
|
|
@ -663,12 +663,12 @@ public class Mouse {
|
|||
|
||||
/** Gets a boolean property as a privileged action. */
|
||||
static boolean getPrivilegedBoolean(final String property_name) {
|
||||
Boolean value = (Boolean)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return new Boolean(Boolean.getBoolean(property_name));
|
||||
Boolean value = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
public Boolean run() {
|
||||
return Boolean.getBoolean(property_name);
|
||||
}
|
||||
});
|
||||
return value.booleanValue();
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -45,11 +45,11 @@ import java.security.PrivilegedActionException;
|
|||
* package through (privileged) reflection.
|
||||
*/
|
||||
final class OpenGLPackageAccess {
|
||||
final static Object global_lock;
|
||||
static final Object global_lock;
|
||||
|
||||
static {
|
||||
try {
|
||||
global_lock = AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
global_lock = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws Exception {
|
||||
Field lock_field = Class.forName("org.lwjgl.opengl.GlobalLock").getDeclaredField("lock");
|
||||
lock_field.setAccessible(true);
|
||||
|
|
@ -66,11 +66,11 @@ final class OpenGLPackageAccess {
|
|||
* public
|
||||
*/
|
||||
try {
|
||||
return (InputImplementation)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation", null);
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<InputImplementation>() {
|
||||
public InputImplementation run() throws Exception {
|
||||
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation");
|
||||
getImplementation_method.setAccessible(true);
|
||||
return getImplementation_method.invoke(null, null);
|
||||
return (InputImplementation)getImplementation_method.invoke(null);
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -47,14 +47,14 @@ import org.lwjgl.Sys;
|
|||
*/
|
||||
public final class AL {
|
||||
/** ALCdevice instance. */
|
||||
protected static ALCdevice device;
|
||||
static ALCdevice device;
|
||||
|
||||
/** Current ALCcontext. */
|
||||
protected static ALCcontext context;
|
||||
static ALCcontext context;
|
||||
|
||||
/** Have we been created? */
|
||||
private static boolean created;
|
||||
|
||||
|
||||
static {
|
||||
Sys.initialize();
|
||||
}
|
||||
|
|
@ -64,16 +64,14 @@ public final class AL {
|
|||
|
||||
/**
|
||||
* Native method to create AL instance
|
||||
*
|
||||
* @param oalPaths Array of strings containing paths to search for OpenAL library
|
||||
*
|
||||
* @param oalPath Path to search for OpenAL library
|
||||
*/
|
||||
private static native void nCreate(String oalPath) throws LWJGLException;
|
||||
|
||||
|
||||
/**
|
||||
* Native method to create AL instance from the Mac OS X 10.4 OpenAL framework.
|
||||
* It is only defined in the Mac OS X native library.
|
||||
*
|
||||
* @param oalPaths Array of strings containing paths to search for OpenAL library
|
||||
*/
|
||||
private static native void nCreateDefault() throws LWJGLException;
|
||||
|
||||
|
|
@ -81,36 +79,36 @@ public final class AL {
|
|||
* Native method the destroy the AL
|
||||
*/
|
||||
private static native void nDestroy();
|
||||
|
||||
|
||||
/**
|
||||
* @return true if AL has been created
|
||||
*/
|
||||
public static boolean isCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an OpenAL instance. Using this constructor will cause OpenAL to
|
||||
* open the device using supplied device argument, and create a context using the context values
|
||||
* supplied.
|
||||
*
|
||||
* supplied.
|
||||
*
|
||||
* @param deviceArguments Arguments supplied to native device
|
||||
* @param contextFrequency Frequency for mixing output buffer, in units of Hz (Common values include 11025, 22050, and 44100).
|
||||
* @param contextRefresh Refresh intervalls, in units of Hz.
|
||||
* @param contextSynchronized Flag, indicating a synchronous context.*
|
||||
*/
|
||||
public static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized)
|
||||
* @param contextSynchronized Flag, indicating a synchronous context.*
|
||||
*/
|
||||
public static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized)
|
||||
throws LWJGLException {
|
||||
create(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param openDevice Whether to automatically open the device
|
||||
* @see #create(String, int, int, boolean)
|
||||
*/
|
||||
public static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized, boolean openDevice)
|
||||
throws LWJGLException {
|
||||
|
||||
|
||||
if (created)
|
||||
throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time.");
|
||||
String libname;
|
||||
|
|
@ -133,14 +131,14 @@ public final class AL {
|
|||
}
|
||||
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++) {
|
||||
for ( String oalPath : oalPaths ) {
|
||||
try {
|
||||
nCreate(oalPaths[i]);
|
||||
nCreate(oalPath);
|
||||
created = true;
|
||||
init(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, openDevice);
|
||||
break;
|
||||
} catch (LWJGLException e) {
|
||||
LWJGLUtil.log("Failed to load " + oalPaths[i] + ": " + e.getMessage());
|
||||
LWJGLUtil.log("Failed to load " + oalPath + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (!created && LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) {
|
||||
|
|
@ -157,18 +155,18 @@ public final class AL {
|
|||
try {
|
||||
AL10.initNativeStubs();
|
||||
ALC10.initNativeStubs();
|
||||
|
||||
|
||||
if(openDevice) {
|
||||
device = ALC10.alcOpenDevice(deviceArguments);
|
||||
if (device == null) {
|
||||
throw new LWJGLException("Could not open ALC device");
|
||||
}
|
||||
|
||||
|
||||
if (contextFrequency == -1) {
|
||||
context = ALC10.alcCreateContext(device, null);
|
||||
} else {
|
||||
context = ALC10.alcCreateContext(device,
|
||||
ALCcontext.createAttributeList(contextFrequency, contextRefresh,
|
||||
ALCcontext.createAttributeList(contextFrequency, contextRefresh,
|
||||
contextSynchronized ? ALC10.ALC_TRUE : ALC10.ALC_FALSE));
|
||||
}
|
||||
ALC10.alcMakeContextCurrent(context);
|
||||
|
|
@ -177,7 +175,7 @@ public final class AL {
|
|||
destroy();
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
ALC11.initialize();
|
||||
|
||||
// Load EFX10 native stubs if ALC_EXT_EFX is supported.
|
||||
|
|
@ -197,7 +195,7 @@ public final class AL {
|
|||
* open the default device, and create a context using default values.
|
||||
* This method used to use default values that the OpenAL implementation
|
||||
* chose but this produces unexpected results on some systems; so now
|
||||
* it defaults to 44100Hz mixing @ 60Hz refresh.
|
||||
* it defaults to 44100Hz mixing @ 60Hz refresh.
|
||||
*/
|
||||
public static void create() throws LWJGLException {
|
||||
create(null, 44100, 60, false);
|
||||
|
|
@ -228,7 +226,7 @@ public final class AL {
|
|||
}
|
||||
|
||||
private static native void resetNativeStubs(Class clazz);
|
||||
|
||||
|
||||
/**
|
||||
* @return handle to the default AL context.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -39,7 +39,7 @@ import org.lwjgl.BufferChecks;
|
|||
import org.lwjgl.LWJGLException;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* ALC introduces the notion of a Device. A Device can be, depending on the
|
||||
* implementation, a hardware device, or a daemon/OS service/actual server. This
|
||||
|
|
@ -49,19 +49,19 @@ import org.lwjgl.LWJGLException;
|
|||
* implementation, which has to map the available backends to unique device
|
||||
* specifiers (represented as strings).
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Brian Matzon <brian@matzon.dk>
|
||||
* @version $Revision: 2286 $
|
||||
* $Id: ALC.java 2286 2006-03-23 19:32:21 +0000 (to, 23 mar 2006) matzon $
|
||||
*/
|
||||
public final class ALC10 {
|
||||
|
||||
|
||||
/** List of active contexts */
|
||||
static HashMap contexts = new HashMap();
|
||||
|
||||
static final HashMap<Long, ALCcontext> contexts = new HashMap<Long, ALCcontext>();
|
||||
|
||||
/** List of active devices */
|
||||
static HashMap devices = new HashMap();
|
||||
|
||||
static final HashMap<Long, ALCdevice> devices = new HashMap<Long, ALCdevice>();
|
||||
|
||||
/** Bad value */
|
||||
public static final int ALC_INVALID = 0;
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ public final class ALC10 {
|
|||
/** Minor version query. */
|
||||
public static final int ALC_MINOR_VERSION = 0x1001;
|
||||
|
||||
/**
|
||||
/**
|
||||
* The size required for the zero-terminated attributes list, for the current context.
|
||||
**/
|
||||
public static final int ALC_ATTRIBUTES_SIZE = 0x1002;
|
||||
|
|
@ -116,7 +116,7 @@ public final class ALC10 {
|
|||
public static final int ALC_INVALID_CONTEXT = 0xA002;
|
||||
|
||||
/**
|
||||
* A function was called at inappropriate time, or in an inappropriate way,
|
||||
* A function was called at inappropriate time, or in an inappropriate way,
|
||||
* causing an illegal state. This can be an incompatible ALenum, object ID,
|
||||
* and/or function.
|
||||
*/
|
||||
|
|
@ -129,24 +129,24 @@ public final class ALC10 {
|
|||
public static final int ALC_INVALID_VALUE = 0xA004;
|
||||
|
||||
/**
|
||||
* A function could not be completed, because there is not enough
|
||||
* A function could not be completed, because there is not enough
|
||||
* memory available.
|
||||
*/
|
||||
public static final int ALC_OUT_OF_MEMORY = 0xA005;
|
||||
|
||||
|
||||
static native void initNativeStubs() throws LWJGLException;
|
||||
|
||||
|
||||
/**
|
||||
* The application can obtain certain strings from ALC.
|
||||
*
|
||||
*
|
||||
* <code>ALC_DEFAULT_DEVICE_SPECIFIER</code> - The specifer string for the default device
|
||||
* <code>ALC_DEVICE_SPECIFIER</code> - The specifer string for the device
|
||||
* <code>ALC_DEVICE_SPECIFIER</code> - The specifer string for the device
|
||||
* <code>ALC_EXTENSIONS</code> - The extensions string for diagnostics and printing.
|
||||
*
|
||||
* In addition, printable error message strings are provided for all valid error tokens,
|
||||
* including <code>ALC_NO_ERROR</code>,<code>ALC_INVALID_DEVICE</code>, <code>ALC_INVALID_CONTEXT</code>,
|
||||
* <code>ALC_INVALID_ENUM</code>, <code>ALC_INVALID_VALUE</code>.
|
||||
*
|
||||
*
|
||||
* @param pname Property to get
|
||||
* @return String property from device
|
||||
*/
|
||||
|
|
@ -156,7 +156,7 @@ public final class ALC10 {
|
|||
Util.checkALCError(device);
|
||||
return result;
|
||||
}
|
||||
native static String nalcGetString(long device, int pname);
|
||||
static native String nalcGetString(long device, int pname);
|
||||
|
||||
/**
|
||||
* The application can query ALC for information using an integer query function.
|
||||
|
|
@ -164,11 +164,11 @@ public final class ALC10 {
|
|||
* device will generate an <code>ALC_INVALID_DEVICE</code> error. The application has to
|
||||
* specify the size of the destination buffer provided. A <code>null</code> destination or a zero
|
||||
* size parameter will cause ALC to ignore the query.
|
||||
*
|
||||
*
|
||||
* <code>ALC_MAJOR_VERSION</code> - Major version query.
|
||||
* <code>ALC_MINOR_VERSION</code> - Minor version query.
|
||||
* <code>ALC_ATTRIBUTES_SIZE</code> - The size required for the zero-terminated attributes list,
|
||||
* for the current context. <code>null</code> is an invalid device. <code>null</code> (no current context
|
||||
* <code>ALC_ATTRIBUTES_SIZE</code> - The size required for the zero-terminated attributes list,
|
||||
* for the current context. <code>null</code> is an invalid device. <code>null</code> (no current context
|
||||
* for the specified device) is legal.
|
||||
* <code>ALC_ALL_ATTRIBUTES</code> - Expects a destination of <code>ALC_CURRENT_ATTRIBUTES_SIZE</code>,
|
||||
* and provides the attribute list for the current context of the specified device.
|
||||
|
|
@ -183,7 +183,7 @@ public final class ALC10 {
|
|||
nalcGetIntegerv(getDevice(device), pname, integerdata.remaining(), integerdata, integerdata.position());
|
||||
Util.checkALCError(device);
|
||||
}
|
||||
native static void nalcGetIntegerv(long device, int pname, int size, Buffer integerdata, int offset);
|
||||
static native void nalcGetIntegerv(long device, int pname, int size, Buffer integerdata, int offset);
|
||||
|
||||
/**
|
||||
* The <code>alcOpenDevice</code> function allows the application (i.e. the client program) to
|
||||
|
|
@ -202,18 +202,18 @@ public final class ALC10 {
|
|||
if(device_address != 0) {
|
||||
ALCdevice device = new ALCdevice(device_address);
|
||||
synchronized (ALC10.devices) {
|
||||
devices.put(new Long(device_address), device);
|
||||
devices.put(device_address, device);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
native static long nalcOpenDevice(String devicename);
|
||||
static native long nalcOpenDevice(String devicename);
|
||||
|
||||
/**
|
||||
* The <code>alcCloseDevice</code> function allows the application (i.e. the client program) to
|
||||
* disconnect from a device (i.e. the server).
|
||||
*
|
||||
*
|
||||
* If deviceHandle is <code>null</code> or invalid, an <code>ALC_INVALID_DEVICE</code> error will be
|
||||
* generated. Once closed, a deviceHandle is invalid.
|
||||
*
|
||||
|
|
@ -226,15 +226,15 @@ public final class ALC10 {
|
|||
devices.remove(new Long(device.device));
|
||||
}
|
||||
return result;
|
||||
|
||||
|
||||
}
|
||||
native static boolean nalcCloseDevice(long device);
|
||||
static native boolean nalcCloseDevice(long device);
|
||||
|
||||
/**
|
||||
* A context is created using <code>alcCreateContext</code>. The device parameter has to be a valid
|
||||
* device. The attribute list can be <code>null</code>, or a zero terminated list of integer pairs
|
||||
* composed of valid ALC attribute tokens and requested values.
|
||||
*
|
||||
*
|
||||
* Context creation will fail if the application requests attributes that, by themselves,
|
||||
* can not be provided. Context creation will fail if the combination of specified
|
||||
* attributes can not be provided. Context creation will fail if a specified attribute, or
|
||||
|
|
@ -248,25 +248,25 @@ public final class ALC10 {
|
|||
public static ALCcontext alcCreateContext(ALCdevice device, IntBuffer attrList) {
|
||||
long context_address = nalcCreateContext(getDevice(device), attrList);
|
||||
Util.checkALCError(device);
|
||||
|
||||
|
||||
if(context_address != 0) {
|
||||
ALCcontext context = new ALCcontext(context_address);
|
||||
synchronized (ALC10.contexts) {
|
||||
contexts.put(new Long(context_address), context);
|
||||
contexts.put(context_address, context);
|
||||
device.addContext(context);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
native static long nalcCreateContext(long device, IntBuffer attrList);
|
||||
static native long nalcCreateContext(long device, IntBuffer attrList);
|
||||
|
||||
/**
|
||||
* To make a Context current with respect to AL Operation (state changes by issueing
|
||||
* commands), <code>alcMakeContextCurrent</code> is used. The context parameter can be <code>null</code>
|
||||
* or a valid context pointer. The operation will apply to the device that the context
|
||||
* was created for.
|
||||
*
|
||||
*
|
||||
* For each OS process (usually this means for each application), only one context can
|
||||
* be current at any given time. All AL commands apply to the current context.
|
||||
* Commands that affect objects shared among contexts (e.g. buffers) have side effects
|
||||
|
|
@ -278,7 +278,7 @@ public final class ALC10 {
|
|||
public static int alcMakeContextCurrent(ALCcontext context) {
|
||||
return nalcMakeContextCurrent(getContext(context));
|
||||
}
|
||||
native static int nalcMakeContextCurrent(long context);
|
||||
static native int nalcMakeContextCurrent(long context);
|
||||
|
||||
/**
|
||||
* The current context is the only context accessible to state changes by AL commands
|
||||
|
|
@ -294,7 +294,7 @@ public final class ALC10 {
|
|||
public static void alcProcessContext(ALCcontext context) {
|
||||
nalcProcessContext(getContext(context));
|
||||
}
|
||||
native static void nalcProcessContext(long context);
|
||||
static native void nalcProcessContext(long context);
|
||||
|
||||
/**
|
||||
* The application can query for, and obtain an handle to, the current context for the
|
||||
|
|
@ -307,12 +307,12 @@ public final class ALC10 {
|
|||
long context_address = nalcGetCurrentContext();
|
||||
if(context_address != 0) {
|
||||
synchronized (ALC10.contexts) {
|
||||
context = (ALCcontext) ALC10.contexts.get(new Long(context_address));
|
||||
context = ALC10.contexts.get(context_address);
|
||||
}
|
||||
}
|
||||
return context;
|
||||
}
|
||||
native static long nalcGetCurrentContext();
|
||||
static native long nalcGetCurrentContext();
|
||||
|
||||
/**
|
||||
* The application can query for, and obtain an handle to, the device of a given context.
|
||||
|
|
@ -324,19 +324,19 @@ public final class ALC10 {
|
|||
long device_address = nalcGetContextsDevice(getContext(context));
|
||||
if (device_address != 0) {
|
||||
synchronized (ALC10.devices) {
|
||||
device = (ALCdevice) ALC10.devices.get(new Long(device_address));
|
||||
device = ALC10.devices.get(device_address);
|
||||
}
|
||||
}
|
||||
return device;
|
||||
}
|
||||
native static long nalcGetContextsDevice(long context);
|
||||
}
|
||||
static native long nalcGetContextsDevice(long context);
|
||||
|
||||
/**
|
||||
* The application can suspend any context from processing (including the current
|
||||
* one). To indicate that a context should be suspended from processing (i.e. that
|
||||
* internal execution state like offset increments is not supposed to be changed), the
|
||||
* application has to use <code>alcSuspendContext</code>.
|
||||
*
|
||||
*
|
||||
* Repeated calls to <code>alcSuspendContext</code> are legal, and do not affect a context that is
|
||||
* already marked as suspended. The default state of a context created by
|
||||
* <code>alcCreateContext</code> is that it is marked as suspended.
|
||||
|
|
@ -346,7 +346,7 @@ public final class ALC10 {
|
|||
public static void alcSuspendContext(ALCcontext context) {
|
||||
nalcSuspendContext(getContext(context));
|
||||
}
|
||||
native static void nalcSuspendContext(long context);
|
||||
static native void nalcSuspendContext(long context);
|
||||
|
||||
/**
|
||||
* The correct way to destroy a context is to first release it using <code>alcMakeCurrent</code> and
|
||||
|
|
@ -362,15 +362,15 @@ public final class ALC10 {
|
|||
context.setInvalid();
|
||||
}
|
||||
}
|
||||
native static void nalcDestroyContext(long context);
|
||||
static native void nalcDestroyContext(long context);
|
||||
|
||||
/**
|
||||
* ALC uses the same conventions and mechanisms as AL for error handling. In
|
||||
* particular, ALC does not use conventions derived from X11 (GLX) or Windows
|
||||
* (WGL). The <code>alcGetError</code> function can be used to query ALC errors.
|
||||
*
|
||||
*
|
||||
* Error conditions are specific to the device.
|
||||
*
|
||||
*
|
||||
* ALC_NO_ERROR - The device handle or specifier does name an accessible driver/server.
|
||||
* <code>ALC_INVALID_DEVICE</code> - The Context argument does not name a valid context.
|
||||
* <code>ALC_INVALID_CONTEXT</code> - The Context argument does not name a valid context.
|
||||
|
|
@ -382,7 +382,7 @@ public final class ALC10 {
|
|||
public static int alcGetError(ALCdevice device) {
|
||||
return nalcGetError(getDevice(device));
|
||||
}
|
||||
native static int nalcGetError(long device);
|
||||
static native int nalcGetError(long device);
|
||||
|
||||
/**
|
||||
* Verify that a given extension is available for the current context and the device it
|
||||
|
|
@ -398,13 +398,13 @@ public final class ALC10 {
|
|||
Util.checkALCError(device);
|
||||
return result;
|
||||
}
|
||||
native static boolean nalcIsExtensionPresent(long device, String extName);
|
||||
static native boolean nalcIsExtensionPresent(long device, String extName);
|
||||
|
||||
/**
|
||||
* Enumeration/token values are device independend, but tokens defined for
|
||||
* extensions might not be present for a given device. But only the tokens defined
|
||||
* by the AL core are guaranteed. Availability of extension tokens dependends on the ALC extension.
|
||||
*
|
||||
*
|
||||
* Specifying a <code>null</code> name parameter will cause an <code>ALC_INVALID_VALUE</code> error.
|
||||
*
|
||||
* @param enumName name of enum to find
|
||||
|
|
@ -415,8 +415,8 @@ public final class ALC10 {
|
|||
Util.checkALCError(device);
|
||||
return result;
|
||||
}
|
||||
native static int nalcGetEnumValue(long device, String enumName);
|
||||
|
||||
static native int nalcGetEnumValue(long device, String enumName);
|
||||
|
||||
static long getDevice(ALCdevice device) {
|
||||
if(device != null) {
|
||||
Util.checkALCValidDevice(device);
|
||||
|
|
@ -424,13 +424,13 @@ public final class ALC10 {
|
|||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
|
||||
static long getContext(ALCcontext context) {
|
||||
if(context != null) {
|
||||
Util.checkALCValidContext(context);
|
||||
return context.context;
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -41,33 +41,33 @@ import org.lwjgl.LWJGLUtil;
|
|||
|
||||
/**
|
||||
* <p>
|
||||
* The ALC11 class implements features in OpenAL 1.1, specifically
|
||||
* The ALC11 class implements features in OpenAL 1.1, specifically
|
||||
* ALC methods and properties.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Brian Matzon <brian@matzon.dk>
|
||||
* @see ALC10
|
||||
* @version $Revision: 2286 $
|
||||
* $Id: ALC.java 2286 2006-03-23 19:32:21 +0000 (to, 23 mar 2006) matzon $
|
||||
*/
|
||||
public final class ALC11 {
|
||||
|
||||
|
||||
public static final int ALC_DEFAULT_ALL_DEVICES_SPECIFIER = 0x1012;
|
||||
public static final int ALC_ALL_DEVICES_SPECIFIER = 0x1013;
|
||||
|
||||
|
||||
public static final int ALC_CAPTURE_DEVICE_SPECIFIER = 0x310;
|
||||
public static final int ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER = 0x311;
|
||||
public static final int ALC_CAPTURE_SAMPLES = 0x312;
|
||||
|
||||
|
||||
public static final int ALC_MONO_SOURCES = 0x1010;
|
||||
public static final int ALC_STEREO_SOURCES = 0x1011;
|
||||
|
||||
|
||||
/**
|
||||
* The alcCaptureOpenDevice function allows the application to connect to a capture
|
||||
* device. To obtain a list of all available capture devices, use getCaptureDevices a list of all
|
||||
* capture devices will be returned. Retrieving ALC_CAPTURE_DEVICE_SPECIFIER with a valid capture device specified will result
|
||||
* in the name of that device being returned as a single string.
|
||||
*
|
||||
*
|
||||
* If the function returns null, then no sound driver/device has been found, or the
|
||||
* requested format could not be fulfilled.
|
||||
* The "deviceName" argument is a string that requests a certain device or
|
||||
|
|
@ -82,9 +82,9 @@ public final class ALC11 {
|
|||
* implementation will set up a buffer of at least the requested size.
|
||||
* Specifying a compressed or extension-supplied format may result in failure, even if the
|
||||
* extension is supplied for rendering.
|
||||
*
|
||||
*
|
||||
* <i>LWJGL SPECIFIC: the actual created device is managed internally in lwjgl</i>
|
||||
*
|
||||
*
|
||||
* @param devicename Name of device to open for capture
|
||||
* @param frequency Frequency of samples to capture
|
||||
* @param format Format of samples to capture
|
||||
|
|
@ -96,18 +96,18 @@ public final class ALC11 {
|
|||
if(device_address != 0) {
|
||||
ALCdevice device = new ALCdevice(device_address);
|
||||
synchronized (ALC10.devices) {
|
||||
ALC10.devices.put(new Long(device_address), device);
|
||||
ALC10.devices.put(device_address, device);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static native long nalcCaptureOpenDevice( String devicename, int frequency, int format, int buffersize);
|
||||
|
||||
|
||||
/**
|
||||
* The alcCaptureCloseDevice function allows the application to disconnect from a capture
|
||||
* device.
|
||||
*
|
||||
*
|
||||
* The return code will be true or false, indicating success or failure. If
|
||||
* the device is null or invalid, an ALC_INVALID_DEVICE error will be generated.
|
||||
* Once closed, a capture device is invalid.
|
||||
|
|
@ -126,7 +126,7 @@ public final class ALC11 {
|
|||
/**
|
||||
* Once a capture device has been opened via alcCaptureOpenDevice, it is made to start
|
||||
* recording audio via the alcCaptureStart entry point:
|
||||
*
|
||||
*
|
||||
* Once started, the device will record audio to an internal ring buffer, the size of which was
|
||||
* specified when opening the device.
|
||||
* The application may query the capture device to discover how much data is currently
|
||||
|
|
@ -137,7 +137,7 @@ public final class ALC11 {
|
|||
nalcCaptureStart(ALC10.getDevice(device));
|
||||
}
|
||||
static native void nalcCaptureStart(long device);
|
||||
|
||||
|
||||
/**
|
||||
* If the application doesn't need to capture more audio for an amount of time, they can halt
|
||||
* the device without closing it via the alcCaptureStop entry point.
|
||||
|
|
@ -153,11 +153,11 @@ public final class ALC11 {
|
|||
/**
|
||||
* When the application feels there are enough samples available to process, it can obtain
|
||||
* them from the AL via the alcCaptureSamples entry point.
|
||||
*
|
||||
*
|
||||
* The "buffer" argument specifies an application-allocated buffer that can contain at least
|
||||
* "samples" sample frames. The implementation may defer conversion and resampling until
|
||||
* this point. Requesting more sample frames than are currently available is an error.
|
||||
*
|
||||
*
|
||||
* @param buffer Buffer to store samples in
|
||||
* @param samples Number of samples to request
|
||||
*/
|
||||
|
|
@ -165,9 +165,9 @@ public final class ALC11 {
|
|||
nalcCaptureSamples(ALC10.getDevice(device), buffer, buffer.position(), samples);
|
||||
}
|
||||
static native void nalcCaptureSamples(long device, ByteBuffer buffer, int position, int samples );
|
||||
|
||||
|
||||
static native void initNativeStubs() throws LWJGLException;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes ALC11, including any extensions
|
||||
* @return true if initialization was successfull
|
||||
|
|
@ -178,18 +178,18 @@ public final class ALC11 {
|
|||
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MAJOR_VERSION, ib);
|
||||
ib.position(1);
|
||||
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MINOR_VERSION, ib);
|
||||
|
||||
|
||||
int major = ib.get(0);
|
||||
int minor = ib.get(1);
|
||||
|
||||
// checking for version 1.x+
|
||||
|
||||
// checking for version 1.x+
|
||||
if(major >= 1) {
|
||||
|
||||
|
||||
// checking for version 1.1+
|
||||
if(major > 1 || minor >= 1) {
|
||||
ALC11.initNativeStubs();
|
||||
AL11.initNativeStubs();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (LWJGLException le) {
|
||||
LWJGLUtil.log("failed to initialize ALC11: " + le);
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -37,7 +37,7 @@ import org.lwjgl.BufferUtils;
|
|||
|
||||
/**
|
||||
* The ALCcontext class represents a context opened in OpenAL space.
|
||||
*
|
||||
*
|
||||
* All operations of the AL core API affect a current AL context. Within the scope of AL,
|
||||
* the ALC is implied - it is not visible as a handle or function parameter. Only one AL
|
||||
* Context per process can be current at a time. Applications maintaining multiple AL
|
||||
|
|
@ -53,13 +53,13 @@ public final class ALCcontext {
|
|||
|
||||
/** Address of actual context */
|
||||
final long context;
|
||||
|
||||
|
||||
/** Whether this context is valid */
|
||||
private boolean valid = false;
|
||||
|
||||
/**
|
||||
* Creates a new instance of ALCcontext
|
||||
*
|
||||
private boolean valid;
|
||||
|
||||
/**
|
||||
* Creates a new instance of ALCcontext
|
||||
*
|
||||
* @param context address of actual context
|
||||
*/
|
||||
ALCcontext(long context) {
|
||||
|
|
@ -97,19 +97,19 @@ public final class ALCcontext {
|
|||
|
||||
return attribList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Marks this context as invalid
|
||||
*
|
||||
*/
|
||||
void setInvalid() {
|
||||
valid = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this context is still valid
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -36,7 +36,7 @@ import java.util.Iterator;
|
|||
|
||||
/**
|
||||
* The ALCdevice class represents a device opened in OpenAL space.
|
||||
*
|
||||
*
|
||||
* ALC introduces the notion of a Device. A Device can be, depending on the
|
||||
* implementation, a hardware device, or a daemon/OS service/actual server. This
|
||||
* mechanism also permits different drivers (and hardware) to coexist within the same
|
||||
|
|
@ -49,18 +49,18 @@ import java.util.Iterator;
|
|||
* $Id$
|
||||
*/
|
||||
public final class ALCdevice {
|
||||
|
||||
|
||||
/** Address of actual device */
|
||||
final long device;
|
||||
|
||||
|
||||
/** Whether this device is valid */
|
||||
private boolean valid = false;
|
||||
|
||||
private boolean valid;
|
||||
|
||||
/** List of contexts belonging to the device */
|
||||
private HashMap contexts = new HashMap();
|
||||
|
||||
/**
|
||||
* Creates a new instance of ALCdevice
|
||||
private final HashMap<Long, ALCcontext> contexts = new HashMap<Long, ALCcontext>();
|
||||
|
||||
/**
|
||||
* Creates a new instance of ALCdevice
|
||||
*
|
||||
* @param device address of actual device
|
||||
*/
|
||||
|
|
@ -68,7 +68,7 @@ public final class ALCdevice {
|
|||
this.device = device;
|
||||
this.valid = true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
|
|
@ -78,28 +78,28 @@ public final class ALCdevice {
|
|||
}
|
||||
return super.equals(device);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a context to the device
|
||||
*
|
||||
*
|
||||
* @param context context to add to the list of contexts for this device
|
||||
*/
|
||||
void addContext(ALCcontext context) {
|
||||
synchronized (contexts) {
|
||||
contexts.put(new Long(context.context), context);
|
||||
contexts.put(context.context, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove context associated with device
|
||||
*
|
||||
*
|
||||
* @param context Context to disassociate with device
|
||||
*/
|
||||
void removeContext(ALCcontext context) {
|
||||
synchronized (contexts) {
|
||||
contexts.remove(new Long(context.context));
|
||||
}
|
||||
}
|
||||
contexts.remove(context.context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks this device and all of its contexts invalid
|
||||
|
|
@ -107,14 +107,12 @@ public final class ALCdevice {
|
|||
void setInvalid() {
|
||||
valid = false;
|
||||
synchronized (contexts) {
|
||||
for(Iterator i = contexts.values().iterator(); i.hasNext();) {
|
||||
ALCcontext context = (ALCcontext) i.next();
|
||||
for ( ALCcontext context : contexts.values() )
|
||||
context.setInvalid();
|
||||
}
|
||||
}
|
||||
contexts.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this device is still valid
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,36 +1,39 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2010 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.openal;
|
||||
|
||||
import static org.lwjgl.openal.AL10.*;
|
||||
import static org.lwjgl.openal.EFX10.*;
|
||||
|
||||
/**
|
||||
* Utility class for the OpenAL extension ALC_EXT_EFX. Provides functions to check for the extension
|
||||
* and support of various effects and filters.
|
||||
|
|
@ -62,7 +65,7 @@ public final class EFXUtil {
|
|||
if (!AL.isCreated()) {
|
||||
throw new OpenALException("OpenAL has not been created.");
|
||||
}
|
||||
return ALC10.alcIsExtensionPresent(AL.getDevice(), EFX10.ALC_EXT_EFX_NAME);
|
||||
return ALC10.alcIsExtensionPresent(AL.getDevice(), ALC_EXT_EFX_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -78,20 +81,20 @@ public final class EFXUtil {
|
|||
public static boolean isEffectSupported(final int effectType) {
|
||||
// Make sure type is a real effect.
|
||||
switch (effectType) {
|
||||
case EFX10.AL_EFFECT_NULL:
|
||||
case EFX10.AL_EFFECT_EAXREVERB:
|
||||
case EFX10.AL_EFFECT_REVERB:
|
||||
case EFX10.AL_EFFECT_CHORUS:
|
||||
case EFX10.AL_EFFECT_DISTORTION:
|
||||
case EFX10.AL_EFFECT_ECHO:
|
||||
case EFX10.AL_EFFECT_FLANGER:
|
||||
case EFX10.AL_EFFECT_FREQUENCY_SHIFTER:
|
||||
case EFX10.AL_EFFECT_VOCAL_MORPHER:
|
||||
case EFX10.AL_EFFECT_PITCH_SHIFTER:
|
||||
case EFX10.AL_EFFECT_RING_MODULATOR:
|
||||
case EFX10.AL_EFFECT_AUTOWAH:
|
||||
case EFX10.AL_EFFECT_COMPRESSOR:
|
||||
case EFX10.AL_EFFECT_EQUALIZER:
|
||||
case AL_EFFECT_NULL:
|
||||
case AL_EFFECT_EAXREVERB:
|
||||
case AL_EFFECT_REVERB:
|
||||
case AL_EFFECT_CHORUS:
|
||||
case AL_EFFECT_DISTORTION:
|
||||
case AL_EFFECT_ECHO:
|
||||
case AL_EFFECT_FLANGER:
|
||||
case AL_EFFECT_FREQUENCY_SHIFTER:
|
||||
case AL_EFFECT_VOCAL_MORPHER:
|
||||
case AL_EFFECT_PITCH_SHIFTER:
|
||||
case AL_EFFECT_RING_MODULATOR:
|
||||
case AL_EFFECT_AUTOWAH:
|
||||
case AL_EFFECT_COMPRESSOR:
|
||||
case AL_EFFECT_EQUALIZER:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown or invalid effect type: " + effectType);
|
||||
|
|
@ -113,10 +116,10 @@ public final class EFXUtil {
|
|||
public static boolean isFilterSupported(final int filterType) {
|
||||
// Make sure type is a real filter.
|
||||
switch (filterType) {
|
||||
case EFX10.AL_FILTER_NULL:
|
||||
case EFX10.AL_FILTER_LOWPASS:
|
||||
case EFX10.AL_FILTER_HIGHPASS:
|
||||
case EFX10.AL_FILTER_BANDPASS:
|
||||
case AL_FILTER_NULL:
|
||||
case AL_FILTER_LOWPASS:
|
||||
case AL_FILTER_HIGHPASS:
|
||||
case AL_FILTER_BANDPASS:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown or invalid filter type: " + filterType);
|
||||
|
|
@ -148,54 +151,54 @@ public final class EFXUtil {
|
|||
if (isEfxSupported()) {
|
||||
|
||||
// Try to create object in order to check AL's response.
|
||||
AL10.alGetError();
|
||||
alGetError();
|
||||
int genError;
|
||||
int testObject = 0;
|
||||
try {
|
||||
switch (objectType) { // Create object based on type
|
||||
case EFFECT:
|
||||
testObject = EFX10.alGenEffects();
|
||||
testObject = alGenEffects();
|
||||
break;
|
||||
case FILTER:
|
||||
testObject = EFX10.alGenFilters();
|
||||
testObject = alGenFilters();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid objectType: " + objectType);
|
||||
}
|
||||
genError = AL10.alGetError();
|
||||
genError = alGetError();
|
||||
} catch (final OpenALException debugBuildException) {
|
||||
// Hack because OpenALException hides the original error code (short of parsing the
|
||||
// error message String which would break if it gets changed).
|
||||
if (debugBuildException.getMessage().contains("AL_OUT_OF_MEMORY")) {
|
||||
genError = AL10.AL_OUT_OF_MEMORY;
|
||||
genError = AL_OUT_OF_MEMORY;
|
||||
} else {
|
||||
genError = AL10.AL_INVALID_OPERATION;
|
||||
genError = AL_INVALID_OPERATION;
|
||||
}
|
||||
}
|
||||
|
||||
if (genError == AL10.AL_NO_ERROR) {
|
||||
if (genError == AL_NO_ERROR) {
|
||||
// Successfully created, now try to set type.
|
||||
AL10.alGetError();
|
||||
alGetError();
|
||||
int setError;
|
||||
try {
|
||||
switch (objectType) { // Set based on object type
|
||||
case EFFECT:
|
||||
EFX10.alEffecti(testObject, EFX10.AL_EFFECT_TYPE, typeValue);
|
||||
alEffecti(testObject, AL_EFFECT_TYPE, typeValue);
|
||||
break;
|
||||
case FILTER:
|
||||
EFX10.alFilteri(testObject, EFX10.AL_FILTER_TYPE, typeValue);
|
||||
alFilteri(testObject, AL_FILTER_TYPE, typeValue);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid objectType: " + objectType);
|
||||
}
|
||||
setError = AL10.alGetError();
|
||||
setError = alGetError();
|
||||
} catch (final OpenALException debugBuildException) {
|
||||
// Hack because OpenALException hides the original error code (short of parsing
|
||||
// the error message String which would break when it gets changed).
|
||||
setError = AL10.AL_INVALID_VALUE;
|
||||
setError = AL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (setError == AL10.AL_NO_ERROR) {
|
||||
if (setError == AL_NO_ERROR) {
|
||||
supported = true;
|
||||
}
|
||||
|
||||
|
|
@ -203,10 +206,10 @@ public final class EFXUtil {
|
|||
try {
|
||||
switch (objectType) { // Set based on object type
|
||||
case EFFECT:
|
||||
EFX10.alDeleteEffects(testObject);
|
||||
alDeleteEffects(testObject);
|
||||
break;
|
||||
case FILTER:
|
||||
EFX10.alDeleteFilters(testObject);
|
||||
alDeleteFilters(testObject);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid objectType: " + objectType);
|
||||
|
|
@ -215,7 +218,7 @@ public final class EFXUtil {
|
|||
// Don't care about cleanup errors.
|
||||
}
|
||||
|
||||
} else if (genError == AL10.AL_OUT_OF_MEMORY) {
|
||||
} else if (genError == AL_OUT_OF_MEMORY) {
|
||||
throw new OpenALException(genError);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ import java.nio.charset.Charset;
|
|||
import java.nio.charset.CharsetEncoder;
|
||||
import java.util.*;
|
||||
|
||||
import static org.lwjgl.opencl.CL10.*;
|
||||
|
||||
/**
|
||||
* Utility class for OpenCL API calls.
|
||||
* TODO: Remove useless stuff
|
||||
|
|
@ -81,28 +83,6 @@ final class APIUtil {
|
|||
|
||||
private static final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();
|
||||
|
||||
private static final ObjectDestructor<CLDevice> DESTRUCTOR_CLSubDevice = new ObjectDestructor<CLDevice>() {
|
||||
public void release(final CLDevice object) { EXTDeviceFission.clReleaseDeviceEXT(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLMem> DESTRUCTOR_CLMem = new ObjectDestructor<CLMem>() {
|
||||
public void release(final CLMem object) { CL10.clReleaseMemObject(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLCommandQueue> DESTRUCTOR_CLCommandQueue = new ObjectDestructor<CLCommandQueue>() {
|
||||
public void release(final CLCommandQueue object) { CL10.clReleaseCommandQueue(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLSampler> DESTRUCTOR_CLSampler = new ObjectDestructor<CLSampler>() {
|
||||
public void release(final CLSampler object) { CL10.clReleaseSampler(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLProgram> DESTRUCTOR_CLProgram = new ObjectDestructor<CLProgram>() {
|
||||
public void release(final CLProgram object) { CL10.clReleaseProgram(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLKernel> DESTRUCTOR_CLKernel = new ObjectDestructor<CLKernel>() {
|
||||
public void release(final CLKernel object) { CL10.clReleaseKernel(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLEvent> DESTRUCTOR_CLEvent = new ObjectDestructor<CLEvent>() {
|
||||
public void release(final CLEvent object) { CL10.clReleaseEvent(object); }
|
||||
};
|
||||
|
||||
private APIUtil() {
|
||||
}
|
||||
|
||||
|
|
@ -285,8 +265,8 @@ final class APIUtil {
|
|||
|
||||
static int getTotalLength(final CharSequence[] strings) {
|
||||
int length = 0;
|
||||
for ( int i = 0; i < strings.length; i++ )
|
||||
length += strings[i].length();
|
||||
for ( CharSequence string : strings )
|
||||
length += string.length();
|
||||
|
||||
return length;
|
||||
}
|
||||
|
|
@ -302,8 +282,8 @@ final class APIUtil {
|
|||
final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
|
||||
|
||||
final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
|
||||
for ( int i = 0; i < strings.length; i++ ) {
|
||||
infiniteSeq.setString(strings[i]);
|
||||
for ( CharSequence string : strings ) {
|
||||
infiniteSeq.setString(string);
|
||||
encoder.encode(infiniteSeq.buffer, buffer, true);
|
||||
}
|
||||
infiniteSeq.clear();
|
||||
|
|
@ -323,8 +303,8 @@ final class APIUtil {
|
|||
final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
|
||||
|
||||
final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
|
||||
for ( int i = 0; i < strings.length; i++ ) {
|
||||
infiniteSeq.setString(strings[i]);
|
||||
for ( CharSequence string : strings ) {
|
||||
infiniteSeq.setString(string);
|
||||
encoder.encode(infiniteSeq.buffer, buffer, true);
|
||||
buffer.put((byte)0);
|
||||
}
|
||||
|
|
@ -344,8 +324,8 @@ final class APIUtil {
|
|||
static PointerBuffer getLengths(final CharSequence[] strings) {
|
||||
PointerBuffer buffer = getLengths(strings.length);
|
||||
|
||||
for ( int i = 0; i < strings.length; i++ )
|
||||
buffer.put(strings[i].length());
|
||||
for ( CharSequence string : strings )
|
||||
buffer.put(string.length());
|
||||
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
|
|
@ -359,13 +339,13 @@ final class APIUtil {
|
|||
* @return the buffer lengths in a PointerBuffer
|
||||
*/
|
||||
static PointerBuffer getLengths(final ByteBuffer[] buffers) {
|
||||
PointerBuffer buffer = getLengths(buffers.length);
|
||||
PointerBuffer lengths = getLengths(buffers.length);
|
||||
|
||||
for ( int i = 0; i < buffers.length; i++ )
|
||||
buffer.put(buffers[i].remaining());
|
||||
for ( ByteBuffer buffer : buffers )
|
||||
lengths.put(buffer.remaining());
|
||||
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
lengths.flip();
|
||||
return lengths;
|
||||
}
|
||||
|
||||
static int getSize(final PointerBuffer lengths) {
|
||||
|
|
@ -376,6 +356,10 @@ final class APIUtil {
|
|||
return (int)size;
|
||||
}
|
||||
|
||||
static String toHexString(final int value) {
|
||||
return "0x" + Integer.toHexString(value).toUpperCase();
|
||||
}
|
||||
|
||||
static void getClassTokens(final Class[] tokenClasses, final Map<Integer, String> target, final TokenFilter filter) {
|
||||
getClassTokens(Arrays.asList(tokenClasses), target, filter);
|
||||
}
|
||||
|
|
@ -393,7 +377,7 @@ final class APIUtil {
|
|||
continue;
|
||||
|
||||
if ( target.containsKey(value) ) // Print colliding tokens in their hex representation.
|
||||
target.put(value, "0x" + Integer.toHexString(value).toUpperCase());
|
||||
target.put(value, toHexString(value));
|
||||
else
|
||||
target.put(value, field.getName());
|
||||
} catch (IllegalAccessException e) {
|
||||
|
|
@ -404,108 +388,6 @@ final class APIUtil {
|
|||
}
|
||||
}
|
||||
|
||||
static ByteBuffer getNativeKernelArgs(final long user_func_ref, final CLMem[] clMems, final long[] sizes) {
|
||||
final ByteBuffer args = getBufferByte(8 + 4 + (clMems == null ? 0 : clMems.length * (4 + PointerBuffer.getPointerSize())));
|
||||
|
||||
args.putLong(0, user_func_ref);
|
||||
if ( clMems == null )
|
||||
args.putInt(8, 0);
|
||||
else {
|
||||
args.putInt(8, clMems.length);
|
||||
int byteIndex = 12;
|
||||
for ( int i = 0; i < clMems.length; i++ ) {
|
||||
if ( LWJGLUtil.DEBUG && !clMems[i].isValid() )
|
||||
throw new IllegalArgumentException("An invalid CLMem object was specified.");
|
||||
args.putInt(byteIndex, (int)sizes[i]); // CLMem size
|
||||
byteIndex += (4 + PointerBuffer.getPointerSize()); // Skip size and make room for the pointer
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all sub-devices created from the specified CLDevice.
|
||||
*
|
||||
* @param device the CLDevice to clear
|
||||
*/
|
||||
static void releaseObjects(final CLDevice device) {
|
||||
// Release objects only if we're about to hit 0.
|
||||
if ( device.getReferenceCount() > 1 )
|
||||
return;
|
||||
|
||||
releaseObjects(device.getSubCLDeviceRegistry(), DESTRUCTOR_CLSubDevice);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all objects contained in the specified CLContext.
|
||||
*
|
||||
* @param context the CLContext to clear
|
||||
*/
|
||||
static void releaseObjects(final CLContext context) {
|
||||
// Release objects only if we're about to hit 0.
|
||||
if ( context.getReferenceCount() > 1 )
|
||||
return;
|
||||
|
||||
releaseObjects(context.getCLEventRegistry(), DESTRUCTOR_CLEvent);
|
||||
releaseObjects(context.getCLProgramRegistry(), DESTRUCTOR_CLProgram);
|
||||
releaseObjects(context.getCLSamplerRegistry(), DESTRUCTOR_CLSampler);
|
||||
releaseObjects(context.getCLMemRegistry(), DESTRUCTOR_CLMem);
|
||||
releaseObjects(context.getCLCommandQueueRegistry(), DESTRUCTOR_CLCommandQueue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all objects contained in the specified CLProgram.
|
||||
*
|
||||
* @param program the CLProgram to clear
|
||||
*/
|
||||
static void releaseObjects(final CLProgram program) {
|
||||
// Release objects only if we're about to hit 0.
|
||||
if ( program.getReferenceCount() > 1 )
|
||||
return;
|
||||
|
||||
releaseObjects(program.getCLKernelRegistry(), DESTRUCTOR_CLKernel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all objects contained in the specified CLCommandQueue.
|
||||
*
|
||||
* @param queue the CLCommandQueue to clear
|
||||
*/
|
||||
static void releaseObjects(final CLCommandQueue queue) {
|
||||
// Release objects only if we're about to hit 0.
|
||||
if ( queue.getReferenceCount() > 1 )
|
||||
return;
|
||||
|
||||
releaseObjects(queue.getCLEventRegistry(), DESTRUCTOR_CLEvent);
|
||||
}
|
||||
|
||||
static Set<String> getExtensions(final String extensionList) {
|
||||
final Set<String> extensions = new HashSet<String>();
|
||||
|
||||
final StringTokenizer tokenizer = new StringTokenizer(extensionList);
|
||||
while ( tokenizer.hasMoreTokens() )
|
||||
extensions.add(tokenizer.nextToken());
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
private static <T extends CLObjectChild> void releaseObjects(final CLObjectRegistry<T> registry, final ObjectDestructor<T> destructor) {
|
||||
if ( registry.isEmpty() )
|
||||
return;
|
||||
|
||||
for ( final T object : registry.getAll() ) {
|
||||
while ( object.isValid() )
|
||||
destructor.release(object);
|
||||
}
|
||||
}
|
||||
|
||||
private interface ObjectDestructor<T extends CLObjectChild> {
|
||||
|
||||
void release(T object);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A mutable CharSequence with very large initial length. We can wrap this in a re-usable CharBuffer for decoding.
|
||||
* We cannot subclass CharBuffer because of {@link java.nio.CharBuffer#toString(int,int)}.
|
||||
|
|
@ -577,4 +459,161 @@ final class APIUtil {
|
|||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
---------------------------------------------------------------------------
|
||||
OPENCL API UTILITIES BELOW
|
||||
---------------------------------------------------------------------------
|
||||
------------------------------------------------------------------------ */
|
||||
|
||||
static Set<String> getExtensions(final String extensionList) {
|
||||
final Set<String> extensions = new HashSet<String>();
|
||||
|
||||
final StringTokenizer tokenizer = new StringTokenizer(extensionList);
|
||||
while ( tokenizer.hasMoreTokens() )
|
||||
extensions.add(tokenizer.nextToken());
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
static CLPlatform getCLPlatform(final PointerBuffer properties) {
|
||||
long platformID = 0;
|
||||
|
||||
final int keys = properties.remaining() / 2;
|
||||
for ( int k = 0; k < keys; k++ ) {
|
||||
final long key = properties.get(k << 1);
|
||||
if ( key == 0 )
|
||||
break;
|
||||
|
||||
if ( key == 0x1084 ) { // CL_CONTEXT_PLATFORM
|
||||
platformID = properties.get((k << 1) + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( platformID == 0 )
|
||||
throw new IllegalArgumentException("Could not find CL_CONTEXT_PLATFORM in cl_context_properties.");
|
||||
|
||||
final CLPlatform platform = CLPlatform.getCLPlatform(platformID);
|
||||
if ( platform == null )
|
||||
throw new IllegalStateException("Could not find a valid CLPlatform. Make sure clGetPlatformIDs has been used before creating a CLContext.");
|
||||
|
||||
return platform;
|
||||
}
|
||||
|
||||
static ByteBuffer getNativeKernelArgs(final long user_func_ref, final CLMem[] clMems, final long[] sizes) {
|
||||
final ByteBuffer args = getBufferByte(8 + 4 + (clMems == null ? 0 : clMems.length * (4 + PointerBuffer.getPointerSize())));
|
||||
|
||||
args.putLong(0, user_func_ref);
|
||||
if ( clMems == null )
|
||||
args.putInt(8, 0);
|
||||
else {
|
||||
args.putInt(8, clMems.length);
|
||||
int byteIndex = 12;
|
||||
for ( int i = 0; i < clMems.length; i++ ) {
|
||||
if ( LWJGLUtil.DEBUG && !clMems[i].isValid() )
|
||||
throw new IllegalArgumentException("An invalid CLMem object was specified.");
|
||||
args.putInt(byteIndex, (int)sizes[i]); // CLMem size
|
||||
byteIndex += (4 + PointerBuffer.getPointerSize()); // Skip size and make room for the pointer
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Releases all sub-devices created from the specified CLDevice.
|
||||
*
|
||||
* @param device the CLDevice to clear
|
||||
*/
|
||||
static void releaseObjects(final CLDevice device) {
|
||||
// Release objects only if we're about to hit 0.
|
||||
if ( device.getReferenceCount() > 1 )
|
||||
return;
|
||||
|
||||
releaseObjects(device.getSubCLDeviceRegistry(), DESTRUCTOR_CLSubDevice);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all objects contained in the specified CLContext.
|
||||
*
|
||||
* @param context the CLContext to clear
|
||||
*/
|
||||
static void releaseObjects(final CLContext context) {
|
||||
// Release objects only if we're about to hit 0.
|
||||
if ( context.getReferenceCount() > 1 )
|
||||
return;
|
||||
|
||||
releaseObjects(context.getCLEventRegistry(), DESTRUCTOR_CLEvent);
|
||||
releaseObjects(context.getCLProgramRegistry(), DESTRUCTOR_CLProgram);
|
||||
releaseObjects(context.getCLSamplerRegistry(), DESTRUCTOR_CLSampler);
|
||||
releaseObjects(context.getCLMemRegistry(), DESTRUCTOR_CLMem);
|
||||
releaseObjects(context.getCLCommandQueueRegistry(), DESTRUCTOR_CLCommandQueue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all objects contained in the specified CLProgram.
|
||||
*
|
||||
* @param program the CLProgram to clear
|
||||
*/
|
||||
static void releaseObjects(final CLProgram program) {
|
||||
// Release objects only if we're about to hit 0.
|
||||
if ( program.getReferenceCount() > 1 )
|
||||
return;
|
||||
|
||||
releaseObjects(program.getCLKernelRegistry(), DESTRUCTOR_CLKernel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases all objects contained in the specified CLCommandQueue.
|
||||
*
|
||||
* @param queue the CLCommandQueue to clear
|
||||
*/
|
||||
static void releaseObjects(final CLCommandQueue queue) {
|
||||
// Release objects only if we're about to hit 0.
|
||||
if ( queue.getReferenceCount() > 1 )
|
||||
return;
|
||||
|
||||
releaseObjects(queue.getCLEventRegistry(), DESTRUCTOR_CLEvent);
|
||||
}
|
||||
|
||||
private static <T extends CLObjectChild> void releaseObjects(final CLObjectRegistry<T> registry, final ObjectDestructor<T> destructor) {
|
||||
if ( registry.isEmpty() )
|
||||
return;
|
||||
|
||||
for ( final T object : registry.getAll() ) {
|
||||
while ( object.isValid() )
|
||||
destructor.release(object);
|
||||
}
|
||||
}
|
||||
|
||||
private static final ObjectDestructor<CLDevice> DESTRUCTOR_CLSubDevice = new ObjectDestructor<CLDevice>() {
|
||||
public void release(final CLDevice object) { EXTDeviceFission.clReleaseDeviceEXT(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLMem> DESTRUCTOR_CLMem = new ObjectDestructor<CLMem>() {
|
||||
public void release(final CLMem object) { CL10.clReleaseMemObject(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLCommandQueue> DESTRUCTOR_CLCommandQueue = new ObjectDestructor<CLCommandQueue>() {
|
||||
public void release(final CLCommandQueue object) { CL10.clReleaseCommandQueue(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLSampler> DESTRUCTOR_CLSampler = new ObjectDestructor<CLSampler>() {
|
||||
public void release(final CLSampler object) { CL10.clReleaseSampler(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLProgram> DESTRUCTOR_CLProgram = new ObjectDestructor<CLProgram>() {
|
||||
public void release(final CLProgram object) { CL10.clReleaseProgram(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLKernel> DESTRUCTOR_CLKernel = new ObjectDestructor<CLKernel>() {
|
||||
public void release(final CLKernel object) { CL10.clReleaseKernel(object); }
|
||||
};
|
||||
private static final ObjectDestructor<CLEvent> DESTRUCTOR_CLEvent = new ObjectDestructor<CLEvent>() {
|
||||
public void release(final CLEvent object) { CL10.clReleaseEvent(object); }
|
||||
};
|
||||
|
||||
private interface ObjectDestructor<T extends CLObjectChild> {
|
||||
|
||||
void release(T object);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ public final class APPLEContextLoggingUtil {
|
|||
public static final CLContextCallback STD_ERR_CALLBACK;
|
||||
|
||||
static {
|
||||
if ( CLCapabilities.isExtensionSupported("CL_APPLE_ContextLoggingFunctions") ) {
|
||||
if ( CLCapabilities.CL_APPLE_ContextLoggingFunctions ) {
|
||||
SYSTEM_LOG_CALLBACK = new CLContextCallback(CallbackUtil.getLogMessageToSystemLogAPPLE()) {
|
||||
protected void handleMessage(final String errinfo, final ByteBuffer private_info) { throw new UnsupportedOperationException(); }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ import org.lwjgl.LWJGLException;
|
|||
import org.lwjgl.LWJGLUtil;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* LWJGL users must use this class to initialize OpenCL
|
||||
* before using any other class in the org.lwjgl.opencl package.
|
||||
|
|
@ -99,13 +101,13 @@ public final class CL {
|
|||
|
||||
final String[] oclPaths = LWJGLUtil.getLibraryPaths(libname, library_names, CL.class.getClassLoader());
|
||||
LWJGLUtil.log("Found " + oclPaths.length + " OpenCL paths");
|
||||
for ( int i = 0; i < oclPaths.length; i++ ) {
|
||||
for ( String oclPath : oclPaths ) {
|
||||
try {
|
||||
nCreate(oclPaths[i]);
|
||||
nCreate(oclPath);
|
||||
created = true;
|
||||
break;
|
||||
} catch (LWJGLException e) {
|
||||
LWJGLUtil.log("Failed to load " + oclPaths[i] + ": " + e.getMessage());
|
||||
LWJGLUtil.log("Failed to load " + oclPath + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +120,7 @@ public final class CL {
|
|||
if ( !created )
|
||||
throw new LWJGLException("Could not locate OpenCL library.");
|
||||
|
||||
if ( !CLCapabilities.isExtensionSupported("OpenCL10") )
|
||||
if ( !CLCapabilities.OpenCL10 )
|
||||
throw new RuntimeException("OpenCL 1.0 not supported.");
|
||||
}
|
||||
|
||||
|
|
@ -133,8 +135,8 @@ public final class CL {
|
|||
* @return the function pointer address
|
||||
*/
|
||||
static long getFunctionAddress(String[] aliases) {
|
||||
for ( int i = 0; i < aliases.length; i++ ) {
|
||||
long address = getFunctionAddress(aliases[i]);
|
||||
for ( String aliase : aliases ) {
|
||||
long address = getFunctionAddress(aliase);
|
||||
if ( address != 0 )
|
||||
return address;
|
||||
}
|
||||
|
|
@ -143,6 +145,8 @@ public final class CL {
|
|||
|
||||
static native long getFunctionAddress(String name);
|
||||
|
||||
static native ByteBuffer getHostBuffer(final long address, final int size);
|
||||
|
||||
private static native void resetNativeStubs(Class clazz);
|
||||
|
||||
}
|
||||
|
|
@ -31,8 +31,6 @@
|
|||
*/
|
||||
package org.lwjgl.opencl;
|
||||
|
||||
import org.lwjgl.PointerWrapperAbstract;
|
||||
|
||||
/**
|
||||
* Instances of this class can be used to receive OpenCL program build notifications.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ import org.lwjgl.PointerBuffer;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static org.lwjgl.opencl.CL10.*;
|
||||
import static org.lwjgl.opencl.CL11.*;
|
||||
|
||||
/**
|
||||
* Utility class that provides runtime checks for OpenCL method calls.
|
||||
* TODO: Revisit this when Java 7.0 is released, there will be new Buffer API with 64bit indices/sizes.
|
||||
|
|
@ -202,25 +205,25 @@ final class CLChecks {
|
|||
*/
|
||||
private static int getChannelCount(final int channelOrder) {
|
||||
switch ( channelOrder ) {
|
||||
case CL10.CL_R:
|
||||
case CL10.CL_A:
|
||||
case CL10.CL_INTENSITY:
|
||||
case CL10.CL_LUMINANCE:
|
||||
case CL11.CL_Rx:
|
||||
case CL_R:
|
||||
case CL_A:
|
||||
case CL_INTENSITY:
|
||||
case CL_LUMINANCE:
|
||||
case CL_Rx:
|
||||
return 1;
|
||||
case CL10.CL_RG:
|
||||
case CL10.CL_RA:
|
||||
case CL11.CL_RGx:
|
||||
case CL_RG:
|
||||
case CL_RA:
|
||||
case CL_RGx:
|
||||
return 2;
|
||||
case CL10.CL_RGB:
|
||||
case CL11.CL_RGBx:
|
||||
case CL_RGB:
|
||||
case CL_RGBx:
|
||||
return 3;
|
||||
case CL10.CL_RGBA:
|
||||
case CL10.CL_BGRA:
|
||||
case CL10.CL_ARGB:
|
||||
case CL_RGBA:
|
||||
case CL_BGRA:
|
||||
case CL_ARGB:
|
||||
return 4;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid cl_channel_order specified: 0x" + Integer.toHexString(channelOrder).toUpperCase());
|
||||
throw new IllegalArgumentException("Invalid cl_channel_order specified: " + APIUtil.toHexString(channelOrder));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,26 +236,26 @@ final class CLChecks {
|
|||
*/
|
||||
private static int getChannelSize(final int channelType) {
|
||||
switch ( channelType ) {
|
||||
case CL10.CL_SNORM_INT8:
|
||||
case CL10.CL_UNORM_INT8:
|
||||
case CL10.CL_SIGNED_INT8:
|
||||
case CL10.CL_UNSIGNED_INT8:
|
||||
case CL_SNORM_INT8:
|
||||
case CL_UNORM_INT8:
|
||||
case CL_SIGNED_INT8:
|
||||
case CL_UNSIGNED_INT8:
|
||||
return 1;
|
||||
case CL10.CL_SNORM_INT16:
|
||||
case CL10.CL_UNORM_INT16:
|
||||
case CL10.CL_UNORM_SHORT_565:
|
||||
case CL10.CL_UNORM_SHORT_555:
|
||||
case CL10.CL_SIGNED_INT16:
|
||||
case CL10.CL_UNSIGNED_INT16:
|
||||
case CL10.CL_HALF_FLOAT:
|
||||
case CL_SNORM_INT16:
|
||||
case CL_UNORM_INT16:
|
||||
case CL_UNORM_SHORT_565:
|
||||
case CL_UNORM_SHORT_555:
|
||||
case CL_SIGNED_INT16:
|
||||
case CL_UNSIGNED_INT16:
|
||||
case CL_HALF_FLOAT:
|
||||
return 2;
|
||||
case CL10.CL_UNORM_INT_101010:
|
||||
case CL10.CL_SIGNED_INT32:
|
||||
case CL10.CL_UNSIGNED_INT32:
|
||||
case CL10.CL_FLOAT:
|
||||
case CL_UNORM_INT_101010:
|
||||
case CL_SIGNED_INT32:
|
||||
case CL_UNSIGNED_INT32:
|
||||
case CL_FLOAT:
|
||||
return 4;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid cl_channel_type specified: 0x" + Integer.toHexString(channelType).toUpperCase());
|
||||
throw new IllegalArgumentException("Invalid cl_channel_type specified: " + APIUtil.toHexString(channelType));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ import org.lwjgl.PointerBuffer;
|
|||
*/
|
||||
public final class CLCommandQueue extends CLObjectChild<CLContext> {
|
||||
|
||||
private static final InfoUtil<CLCommandQueue> util = CLPlatform.getInfoUtilInstance(CLCommandQueue.class, "CL_COMMAND_QUEUE_UTIL");
|
||||
|
||||
private final CLDevice device;
|
||||
|
||||
private final CLObjectRegistry<CLEvent> clEvents;
|
||||
|
|
@ -71,6 +73,19 @@ public final class CLCommandQueue extends CLObjectChild<CLContext> {
|
|||
return clEvents.getObject(id);
|
||||
}
|
||||
|
||||
// ---------------[ UTILITY METHODS ]---------------
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getInfoInt(int param_name) {
|
||||
return util.getInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||
|
||||
CLObjectRegistry<CLEvent> getCLEventRegistry() { return clEvents; }
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
package org.lwjgl.opencl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -39,7 +40,9 @@ import java.util.Map;
|
|||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
public final class CLContext extends CLObject {
|
||||
public final class CLContext extends CLObjectChild<CLPlatform> {
|
||||
|
||||
private static final CLContextUtil util = (CLContextUtil)CLPlatform.getInfoUtilInstance(CLContext.class, "CL_CONTEXT_UTIL");
|
||||
|
||||
private final CLObjectRegistry<CLCommandQueue> clCommandQueues;
|
||||
private final CLObjectRegistry<CLMem> clMems;
|
||||
|
|
@ -48,13 +51,16 @@ public final class CLContext extends CLObject {
|
|||
private final CLObjectRegistry<CLEvent> clEvents;
|
||||
|
||||
/** Global registry for build callbacks. */
|
||||
static Map<Long, CLProgram> clProgramsGlobal = new HashMap<Long, CLProgram>();
|
||||
static final Map<Long, CLProgram> clProgramsGlobal = new HashMap<Long, CLProgram>();
|
||||
|
||||
/** Global registry for event callbacks. */
|
||||
static Map<Long, CLEvent> clEventsGlobal = new HashMap<Long, CLEvent>();
|
||||
static final Map<Long, CLEvent> clEventsGlobal = new HashMap<Long, CLEvent>();
|
||||
|
||||
CLContext(final long pointer) {
|
||||
super(pointer);
|
||||
CLContext(final long pointer, final CLPlatform platform) {
|
||||
super(pointer, platform);
|
||||
|
||||
// We do not need to register the context with the platform,
|
||||
// there is no API that returns cl_context, except clCreateContext.
|
||||
|
||||
if ( isValid() ) {
|
||||
clCommandQueues = new CLObjectRegistry<CLCommandQueue>();
|
||||
|
|
@ -116,6 +122,35 @@ public final class CLContext extends CLObject {
|
|||
*/
|
||||
public CLEvent getCLEvent(final long id) { return clEvents.getObject(id); }
|
||||
|
||||
// ---------------[ UTILITY METHODS ]---------------
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getInfoInt(int param_name) {
|
||||
return util.getInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of devices in context.
|
||||
*
|
||||
* @return the list of devices
|
||||
*/
|
||||
public List<CLDevice> getInfoDevices() {
|
||||
return util.getInfoDevices(this);
|
||||
}
|
||||
|
||||
/** CLContext utility methods interface. */
|
||||
interface CLContextUtil extends InfoUtil<CLContext> {
|
||||
|
||||
List<CLDevice> getInfoDevices(CLContext context);
|
||||
|
||||
}
|
||||
|
||||
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||
|
||||
CLObjectRegistry<CLCommandQueue> getCLCommandQueueRegistry() { return clCommandQueues; }
|
||||
|
|
|
|||
|
|
@ -40,14 +40,15 @@ import org.lwjgl.PointerBuffer;
|
|||
*/
|
||||
public final class CLDevice extends CLObjectChild<CLDevice> {
|
||||
|
||||
private static final CLDeviceImpl impl = (CLDeviceImpl)CLPlatform.getClassInstance("org.lwjgl.opencl.CLDeviceImpl");
|
||||
private static final InfoUtil<CLDevice> util = CLPlatform.getInfoUtilInstance(CLDevice.class, "CL_DEVICE_UTIL");
|
||||
|
||||
private final CLPlatform platform;
|
||||
private final CLObjectRegistry<CLDevice> subCLDevices;
|
||||
|
||||
private Object caps;
|
||||
|
||||
public CLDevice(final long pointer) {
|
||||
this(pointer, null);
|
||||
CLDevice(final long pointer, final CLPlatform platform) {
|
||||
this(pointer, null, platform);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -57,22 +58,27 @@ public final class CLDevice extends CLObjectChild<CLDevice> {
|
|||
* @param parent the parent CLDevice
|
||||
*/
|
||||
CLDevice(final long pointer, final CLDevice parent) {
|
||||
this(pointer, parent, parent.getPlatform());
|
||||
}
|
||||
|
||||
CLDevice(final long pointer, final CLDevice parent, final CLPlatform platform) {
|
||||
super(pointer, parent);
|
||||
|
||||
if ( isValid() ) {
|
||||
subCLDevices = new CLObjectRegistry<CLDevice>();
|
||||
this.platform = platform;
|
||||
platform.getCLDeviceRegistry().registerObject(this);
|
||||
|
||||
this.subCLDevices = new CLObjectRegistry<CLDevice>();
|
||||
if ( parent != null )
|
||||
parent.subCLDevices.registerObject(this);
|
||||
} else
|
||||
subCLDevices = null;
|
||||
} else {
|
||||
this.platform = null;
|
||||
this.subCLDevices = null;
|
||||
}
|
||||
}
|
||||
|
||||
void setCapabilities(final Object caps) {
|
||||
this.caps = caps;
|
||||
}
|
||||
|
||||
Object getCapabilities() {
|
||||
return caps;
|
||||
public CLPlatform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,6 +90,85 @@ public final class CLDevice extends CLObjectChild<CLDevice> {
|
|||
*/
|
||||
public CLDevice getSubCLDevice(final long id) { return subCLDevices.getObject(id); }
|
||||
|
||||
// ---------------[ UTILITY METHODS ]---------------
|
||||
|
||||
/**
|
||||
* Returns the value of the specified String parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public String getInfoString(int param_name) {
|
||||
return util.getInfoString(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getInfoInt(int param_name) {
|
||||
return util.getInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boolean value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public boolean getInfoBoolean(int param_name) {
|
||||
return util.getInfoInt(this, param_name) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size_t value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getInfoSize(int param_name) {
|
||||
return util.getInfoSize(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of size_t values of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter values
|
||||
*/
|
||||
public long[] getInfoSizeArray(int param_name) {
|
||||
return util.getInfoSizeArray(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long value of the specified parameter. Can be used
|
||||
* for both cl_ulong and cl_bitfield parameters.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getInfoLong(int param_name) {
|
||||
return util.getInfoLong(this, param_name);
|
||||
}
|
||||
|
||||
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||
|
||||
void setCapabilities(final Object caps) {
|
||||
this.caps = caps;
|
||||
}
|
||||
|
||||
Object getCapabilities() {
|
||||
return caps;
|
||||
}
|
||||
|
||||
int retain() {
|
||||
if ( getParent() == null )
|
||||
return getReferenceCount(); // NO-OP, root devices cannot be retained
|
||||
|
|
@ -118,74 +203,4 @@ public final class CLDevice extends CLObjectChild<CLDevice> {
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------[ HELPER METHODS ]---------------
|
||||
|
||||
/**
|
||||
* Returns the value of the specified String parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public String getInfoString(int param_name) {
|
||||
return impl.getInfoString(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getInfoInt(int param_name) {
|
||||
return impl.getInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boolean value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public boolean getInfoBoolean(int param_name) {
|
||||
return impl.getInfoInt(this, param_name) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size_t value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getInfoSize(int param_name) {
|
||||
return impl.getInfoSize(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long value of the specified parameter. Can be used
|
||||
* for both cl_ulong and cl_bitfield parameters.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getInfoLong(int param_name) {
|
||||
return impl.getInfoLong(this, param_name);
|
||||
}
|
||||
|
||||
/** CLDevice helper methods implementation interface. */
|
||||
interface CLDeviceImpl {
|
||||
|
||||
String getInfoString(CLDevice device, int param_name);
|
||||
|
||||
int getInfoInt(CLDevice device, int param_name);
|
||||
|
||||
long getInfoSize(CLDevice device, int param_name);
|
||||
|
||||
long getInfoLong(CLDevice device, int param_name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2010 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.opencl;
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static org.lwjgl.opencl.CL10.*;
|
||||
|
||||
/**
|
||||
* Implementation of CLDevice helper methods.
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
final class CLDeviceImpl implements CLDevice.CLDeviceImpl {
|
||||
|
||||
CLDeviceImpl() {
|
||||
}
|
||||
|
||||
static CLDeviceCapabilities getCapabilities(final CLDevice device) {
|
||||
device.checkValid();
|
||||
|
||||
CLDeviceCapabilities caps = (CLDeviceCapabilities)device.getCapabilities();
|
||||
if ( caps == null )
|
||||
device.setCapabilities(caps = new CLDeviceCapabilities(device));
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
private static int getInfoBytes(final CLDevice device, final int param_name) {
|
||||
final PointerBuffer bytes = APIUtil.getBufferPointer();
|
||||
clGetDeviceInfo(device, param_name, null, bytes);
|
||||
return (int)bytes.get(0);
|
||||
}
|
||||
|
||||
public String getInfoString(final CLDevice device, final int param_name) {
|
||||
device.checkValid();
|
||||
|
||||
final int bytes = getInfoBytes(device, param_name);
|
||||
|
||||
final ByteBuffer versionBuffer = APIUtil.getBufferByte(bytes);
|
||||
clGetDeviceInfo(device, param_name, versionBuffer, null);
|
||||
|
||||
versionBuffer.limit(bytes - 1); // Exclude null-termination
|
||||
return APIUtil.getString(versionBuffer);
|
||||
}
|
||||
|
||||
public int getInfoInt(final CLDevice device, final int param_name) {
|
||||
device.checkValid();
|
||||
|
||||
final ByteBuffer versionBuffer = APIUtil.getBufferByte(4);
|
||||
clGetDeviceInfo(device, param_name, versionBuffer, null);
|
||||
|
||||
return versionBuffer.getInt(0);
|
||||
}
|
||||
|
||||
public long getInfoSize(final CLDevice device, final int param_name) {
|
||||
device.checkValid();
|
||||
|
||||
final PointerBuffer pointerBuffer = APIUtil.getBufferPointer();
|
||||
clGetDeviceInfo(device, param_name, pointerBuffer.getBuffer(), null);
|
||||
|
||||
return pointerBuffer.get(0);
|
||||
}
|
||||
|
||||
public long getInfoLong(final CLDevice device, final int param_name) {
|
||||
device.checkValid();
|
||||
|
||||
final ByteBuffer versionBuffer = APIUtil.getBufferByte(8);
|
||||
clGetDeviceInfo(device, param_name, versionBuffer, null);
|
||||
|
||||
return versionBuffer.getLong(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +38,8 @@ package org.lwjgl.opencl;
|
|||
*/
|
||||
public final class CLEvent extends CLObjectChild<CLContext> {
|
||||
|
||||
private static final CLEventUtil util = (CLEventUtil)CLPlatform.getInfoUtilInstance(CLEvent.class, "CL_EVENT_UTIL");
|
||||
|
||||
private final CLCommandQueue queue;
|
||||
|
||||
CLEvent(final long pointer, final CLContext context) {
|
||||
|
|
@ -70,6 +72,42 @@ public final class CLEvent extends CLObjectChild<CLContext> {
|
|||
return queue;
|
||||
}
|
||||
|
||||
// ---------------[ UTILITY METHODS ]---------------
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getInfoInt(final int param_name) {
|
||||
return util.getInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
// clGetEventProfilingInfo methods
|
||||
|
||||
/**
|
||||
* Returns the long value of the specified parameter. Can be used
|
||||
* for both cl_ulong and cl_bitfield parameters.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getProfilingInfoLong(int param_name) {
|
||||
return util.getProfilingInfoLong(this, param_name);
|
||||
}
|
||||
|
||||
/** CLEvent utility methods interface. */
|
||||
interface CLEventUtil extends InfoUtil<CLEvent> {
|
||||
|
||||
long getProfilingInfoLong(CLEvent event, int param_name);
|
||||
|
||||
}
|
||||
|
||||
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||
|
||||
int release() {
|
||||
try {
|
||||
return super.release();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import org.lwjgl.PointerWrapper;
|
|||
*/
|
||||
public final class CLKernel extends CLObjectChild<CLProgram> {
|
||||
|
||||
private static final CLKernelImpl impl = (CLKernelImpl)CLPlatform.getClassInstance("org.lwjgl.opencl.CLKernelImpl");
|
||||
private static final CLKernelUtil util = (CLKernelUtil)CLPlatform.getInfoUtilInstance(CLKernel.class, "CL_KERNEL_UTIL");
|
||||
|
||||
CLKernel(final long pointer, final CLProgram program) {
|
||||
super(pointer, program);
|
||||
|
|
@ -48,6 +48,195 @@ public final class CLKernel extends CLObjectChild<CLProgram> {
|
|||
program.getCLKernelRegistry().registerObject(this);
|
||||
}
|
||||
|
||||
// ---------------[ UTILITY METHODS ]---------------
|
||||
|
||||
// clSetKernelArg methods
|
||||
|
||||
/**
|
||||
* Sets a kernel argument at the specified index to the specified
|
||||
* byte value.
|
||||
*
|
||||
* @param index the argument index
|
||||
* @param value the argument value
|
||||
*
|
||||
* @return this CLKernel object
|
||||
*/
|
||||
public CLKernel setArg(final int index, final byte value) {
|
||||
util.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a kernel argument at the specified index to the specified
|
||||
* byte value.
|
||||
*
|
||||
* @param index the argument index
|
||||
* @param value the argument value
|
||||
*
|
||||
* @return this CLKernel object
|
||||
*/
|
||||
public CLKernel setArg(final int index, final short value) {
|
||||
util.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a kernel argument at the specified index to the specified
|
||||
* int value.
|
||||
*
|
||||
* @param index the argument index
|
||||
* @param value the argument value
|
||||
*
|
||||
* @return this CLKernel object
|
||||
*/
|
||||
public CLKernel setArg(final int index, final int value) {
|
||||
util.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a kernel argument at the specified index to the specified
|
||||
* long value.
|
||||
*
|
||||
* @param index the argument index
|
||||
* @param value the argument value
|
||||
*
|
||||
* @return this CLKernel object
|
||||
*/
|
||||
public CLKernel setArg(final int index, final long value) {
|
||||
util.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a kernel argument at the specified index to the specified
|
||||
* float value.
|
||||
*
|
||||
* @param index the argument index
|
||||
* @param value the argument value
|
||||
*
|
||||
* @return this CLKernel object
|
||||
*/
|
||||
public CLKernel setArg(final int index, final float value) {
|
||||
util.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a kernel argument at the specified index to the specified
|
||||
* double value.
|
||||
*
|
||||
* @param index the argument index
|
||||
* @param value the argument value
|
||||
*
|
||||
* @return this CLKernel object
|
||||
*/
|
||||
public CLKernel setArg(final int index, final double value) {
|
||||
util.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a kernel argument at the specified index to the specified
|
||||
* pointer value.
|
||||
*
|
||||
* @param index the argument index
|
||||
* @param value the argument value
|
||||
*
|
||||
* @return this CLKernel object
|
||||
*/
|
||||
public CLKernel setArg(final int index, final PointerWrapper value) {
|
||||
util.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
// clGetKernelInfo methods
|
||||
|
||||
/**
|
||||
* Returns the String value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public String getInfoString(final int param_name) {
|
||||
return util.getInfoString(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getInfoInt(final int param_name) {
|
||||
return util.getInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
// clGetKernelWorkGroupInfo methods
|
||||
|
||||
/**
|
||||
* Returns the size_t value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getWorkGroupInfoSize(final CLDevice device, int param_name) {
|
||||
return util.getWorkGroupInfoSize(this, device, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of size_t values of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter values
|
||||
*/
|
||||
public long[] getWorkGroupInfoSizeArray(final CLDevice device, int param_name) {
|
||||
return util.getWorkGroupInfoSizeArray(this, device, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long value of the specified parameter. Can be used
|
||||
* for both cl_ulong and cl_bitfield parameters.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getWorkGroupInfoLong(final CLDevice device, int param_name) {
|
||||
return util.getWorkGroupInfoLong(this, device, param_name);
|
||||
}
|
||||
|
||||
/** CLKernel utility methods interface. */
|
||||
interface CLKernelUtil extends InfoUtil<CLKernel> {
|
||||
|
||||
void setArg(CLKernel kernel, int index, byte value);
|
||||
|
||||
void setArg(CLKernel kernel, int index, short value);
|
||||
|
||||
void setArg(CLKernel kernel, int index, int value);
|
||||
|
||||
void setArg(CLKernel kernel, int index, long value);
|
||||
|
||||
void setArg(CLKernel kernel, int index, float value);
|
||||
|
||||
void setArg(CLKernel kernel, int index, double value);
|
||||
|
||||
void setArg(CLKernel kernel, int index, PointerWrapper pointer);
|
||||
|
||||
long getWorkGroupInfoSize(CLKernel kernel, CLDevice device, int param_name);
|
||||
|
||||
long[] getWorkGroupInfoSizeArray(CLKernel kernel, CLDevice device, int param_name);
|
||||
|
||||
long getWorkGroupInfoLong(CLKernel kernel, CLDevice device, int param_name);
|
||||
|
||||
}
|
||||
|
||||
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||
|
||||
int release() {
|
||||
try {
|
||||
return super.release();
|
||||
|
|
@ -57,57 +246,4 @@ public final class CLKernel extends CLObjectChild<CLProgram> {
|
|||
}
|
||||
}
|
||||
|
||||
public CLKernel setArg(final int index, final byte value) {
|
||||
impl.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CLKernel setArg(final int index, final short value) {
|
||||
impl.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CLKernel setArg(final int index, final int value) {
|
||||
impl.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CLKernel setArg(final int index, final long value) {
|
||||
impl.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CLKernel setArg(final int index, final float value) {
|
||||
impl.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CLKernel setArg(final int index, final double value) {
|
||||
impl.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CLKernel setArg(final int index, final PointerWrapper value) {
|
||||
impl.setArg(this, index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
interface CLKernelImpl {
|
||||
|
||||
void setArg(CLKernel clKernel, int index, byte value);
|
||||
|
||||
void setArg(CLKernel clKernel, int index, short value);
|
||||
|
||||
void setArg(CLKernel clKernel, int index, int value);
|
||||
|
||||
void setArg(CLKernel clKernel, int index, long value);
|
||||
|
||||
void setArg(CLKernel clKernel, int index, float value);
|
||||
|
||||
void setArg(CLKernel clKernel, int index, double value);
|
||||
|
||||
void setArg(CLKernel clKernel, int index, PointerWrapper pointer);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -31,6 +31,8 @@
|
|||
*/
|
||||
package org.lwjgl.opencl;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* This class is a wrapper around a cl_mem pointer.
|
||||
*
|
||||
|
|
@ -38,12 +40,155 @@ package org.lwjgl.opencl;
|
|||
*/
|
||||
public final class CLMem extends CLObjectChild<CLContext> {
|
||||
|
||||
private static final CLMemUtil util = (CLMemUtil)CLPlatform.getInfoUtilInstance(CLMem.class, "CL_MEM_UTIL");
|
||||
|
||||
CLMem(final long pointer, final CLContext context) {
|
||||
super(pointer, context);
|
||||
if ( isValid() )
|
||||
context.getCLMemRegistry().registerObject(this);
|
||||
}
|
||||
|
||||
// ---------------[ UTILITY METHODS ]---------------
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getInfoInt(int param_name) {
|
||||
return util.getInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size_t value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getInfoSize(int param_name) {
|
||||
return util.getInfoSize(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long value of the specified parameter. Can be used
|
||||
* for both cl_ulong and cl_bitfield parameters.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getInfoLong(int param_name) {
|
||||
return util.getInfoLong(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a direct ByteBuffer instance that points to the host
|
||||
* memory that backs this CLMem object. Applicable only to CLMem
|
||||
* objects that were created with the CL_MEM_USE_HOST_PTR flag.
|
||||
*
|
||||
* @return the host memory ByteBuffer
|
||||
*/
|
||||
public ByteBuffer getInfoHostBuffer() {
|
||||
return util.getInfoHostBuffer(this);
|
||||
}
|
||||
|
||||
// clGetImageInfo methods
|
||||
|
||||
/**
|
||||
* Returns the size_t value of the specified parameter. Applicable to image objects only.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getImageInfoSize(int param_name) {
|
||||
return util.getImageInfoSize(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image channel order. Applicable to image objects only.
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getImageChannelOrder() {
|
||||
return util.getImageInfoFormat(this, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image channel type. Applicable to image objects only.
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getImageChannelType() {
|
||||
return util.getImageInfoFormat(this, 1);
|
||||
}
|
||||
|
||||
// clGetGLObjectInfo methods
|
||||
|
||||
/**
|
||||
* Returns the GL object type. Applicable to CLMem objects
|
||||
* that have been created GL objects only.
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getGLObjectType() {
|
||||
return util.getGLObjectType(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GL object name. Applicable to CLMem objects
|
||||
* that have been created GL objects only.
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getGLObjectName() {
|
||||
return util.getGLObjectName(this);
|
||||
}
|
||||
|
||||
// clGetGLTextureInfo methods
|
||||
|
||||
/**
|
||||
* Returns the int value of the specified parameter. Applicable to CLMem objects
|
||||
* that have been created by GL textures only.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getGLTextureInfoInt(int param_name) {
|
||||
return util.getGLTextureInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
/** CLMem utility methods interface. */
|
||||
interface CLMemUtil extends InfoUtil<CLMem> {
|
||||
|
||||
ByteBuffer getInfoHostBuffer(CLMem mem);
|
||||
|
||||
long getImageInfoSize(CLMem mem, int param_name);
|
||||
|
||||
int getImageInfoFormat(CLMem mem, int index);
|
||||
|
||||
int getGLObjectType(CLMem mem);
|
||||
|
||||
int getGLObjectName(CLMem mem);
|
||||
|
||||
int getGLTextureInfoInt(CLMem mem, int param_name);
|
||||
|
||||
}
|
||||
|
||||
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||
|
||||
/**
|
||||
* Sub-buffer factory. clCreateSubBuffer may return an existing CLMem.
|
||||
*
|
||||
* @param pointer the sub-buffer id
|
||||
* @param context the context in which the sub-buffer was created
|
||||
*
|
||||
* @return the CLMem that represents the sub-buffer
|
||||
*/
|
||||
static CLMem create(final long pointer, final CLContext context) {
|
||||
CLMem clMem = context.getCLMemRegistry().getObject(pointer);
|
||||
if ( clMem == null )
|
||||
|
|
|
|||
|
|
@ -31,58 +31,21 @@
|
|||
*/
|
||||
package org.lwjgl.opencl;
|
||||
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
import org.lwjgl.PointerWrapperAbstract;
|
||||
|
||||
/**
|
||||
* Base class for all retainable OpenCL objects.
|
||||
* Base class for all OpenCL objects.
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
abstract class CLObject extends PointerWrapperAbstract {
|
||||
|
||||
private int refCount;
|
||||
|
||||
CLObject(final long pointer) {
|
||||
protected CLObject(final long pointer) {
|
||||
super(pointer);
|
||||
|
||||
if ( pointer != 0 )
|
||||
this.refCount = 1;
|
||||
}
|
||||
|
||||
public final int getReferenceCount() {
|
||||
return refCount;
|
||||
}
|
||||
|
||||
public final boolean isValid() {
|
||||
return refCount > 0;
|
||||
}
|
||||
|
||||
public final long getPointer() {
|
||||
checkValid();
|
||||
return super.getPointer();
|
||||
}
|
||||
|
||||
final long getPointerUnsafe() {
|
||||
return super.getPointer();
|
||||
}
|
||||
|
||||
int retain() {
|
||||
checkValid();
|
||||
//System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount + 1));
|
||||
return ++refCount;
|
||||
}
|
||||
|
||||
int release() {
|
||||
checkValid();
|
||||
//System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount - 1));
|
||||
return --refCount;
|
||||
}
|
||||
|
||||
final void checkValid() {
|
||||
checkNull();
|
||||
if ( LWJGLUtil.DEBUG && refCount == 0 )
|
||||
throw new IllegalStateException("This CL object is invalid.");
|
||||
return pointer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -38,11 +38,11 @@ import org.lwjgl.LWJGLUtil;
|
|||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
abstract class CLObjectChild<P extends CLObject> extends CLObject {
|
||||
abstract class CLObjectChild<P extends CLObject> extends CLObjectRetainable {
|
||||
|
||||
private final P parent;
|
||||
|
||||
CLObjectChild(final long pointer, final P parent) {
|
||||
protected CLObjectChild(final long pointer, final P parent) {
|
||||
super(pointer);
|
||||
|
||||
if ( LWJGLUtil.DEBUG && parent != null && !parent.isValid() )
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package org.lwjgl.opencl;
|
||||
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A CLContextObject container.
|
||||
* A CLObjectChild container.
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
|
|
@ -37,8 +39,10 @@ class CLObjectRegistry<T extends CLObjectChild> {
|
|||
final Map<Long, T> map = getMap();
|
||||
final Long key = object.getPointer();
|
||||
|
||||
if ( !map.containsKey(key) )
|
||||
getMap().put(object.getPointer(), object);
|
||||
if ( LWJGLUtil.DEBUG && map.containsKey(key) )
|
||||
throw new IllegalStateException("Duplicate object found: " + object.getClass() + " - " + key);
|
||||
|
||||
getMap().put(object.getPointer(), object);
|
||||
}
|
||||
|
||||
void unregisterObject(final T object) {
|
||||
|
|
|
|||
|
|
@ -31,47 +31,40 @@
|
|||
*/
|
||||
package org.lwjgl.opencl;
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.PointerWrapper;
|
||||
|
||||
import static org.lwjgl.opencl.CL10.*;
|
||||
|
||||
/**
|
||||
* Implementation of CLKernel helper methods.
|
||||
* Base class for all retainable OpenCL objects.
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
final class CLKernelImpl implements CLKernel.CLKernelImpl {
|
||||
abstract class CLObjectRetainable extends CLObject {
|
||||
|
||||
CLKernelImpl() {
|
||||
private int refCount;
|
||||
|
||||
protected CLObjectRetainable(final long pointer) {
|
||||
super(pointer);
|
||||
|
||||
if ( super.isValid() )
|
||||
this.refCount = 1;
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel clKernel, final int index, final byte value) {
|
||||
clSetKernelArg(clKernel, index, 1, APIUtil.getBufferByte(1).put(0, value));
|
||||
public final int getReferenceCount() {
|
||||
return refCount;
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel clKernel, final int index, final short value) {
|
||||
clSetKernelArg(clKernel, index, 2, APIUtil.getBufferShort().put(0, value));
|
||||
public final boolean isValid() {
|
||||
return refCount > 0;
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel clKernel, final int index, final int value) {
|
||||
clSetKernelArg(clKernel, index, 4, APIUtil.getBufferInt().put(0, value));
|
||||
int retain() {
|
||||
checkValid();
|
||||
//System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount + 1));
|
||||
return ++refCount;
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel clKernel, final int index, final long value) {
|
||||
clSetKernelArg(clKernel, index, 8, APIUtil.getBufferLong().put(0, value));
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel clKernel, final int index, final float value) {
|
||||
clSetKernelArg(clKernel, index, 4, APIUtil.getBufferFloat().put(0, value));
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel clKernel, final int index, final double value) {
|
||||
clSetKernelArg(clKernel, index, 8, APIUtil.getBufferDouble().put(0, value));
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel clKernel, final int index, final PointerWrapper pointer) {
|
||||
clSetKernelArg(clKernel, index, PointerBuffer.getPointerSize(), APIUtil.getBufferPointer().put(0, pointer).getBuffer());
|
||||
int release() {
|
||||
checkValid();
|
||||
//System.out.println(getClass().getSimpleName() + " REF COUNT: " + pointer + " - " + (refCount - 1));
|
||||
return --refCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -31,26 +31,144 @@
|
|||
*/
|
||||
package org.lwjgl.opencl;
|
||||
|
||||
import org.lwjgl.PointerWrapperAbstract;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.opencl.api.Filter;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.lang.Math.*;
|
||||
|
||||
/**
|
||||
* This class is a wrapper around a cl_platform_id pointer.
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
public final class CLPlatform extends PointerWrapperAbstract {
|
||||
public final class CLPlatform extends CLObject {
|
||||
|
||||
private static final CLPlatformImpl impl = (CLPlatformImpl)getClassInstance("org.lwjgl.opencl.CLPlatformImpl");
|
||||
private static final CLPlatformUtil util = (CLPlatformUtil)getInfoUtilInstance(CLPlatform.class, "CL_PLATFORM_UTIL");
|
||||
|
||||
private static final Map<Long, CLPlatform> clPlatforms = new HashMap<Long, CLPlatform>();
|
||||
|
||||
private final CLObjectRegistry<CLDevice> clDevices;
|
||||
|
||||
/** Global registry for build callbacks. */
|
||||
static final Map<Long, CLDevice> clDevicesGlobal = new HashMap<Long, CLDevice>();
|
||||
|
||||
private Object caps;
|
||||
|
||||
public CLPlatform(final long pointer) {
|
||||
CLPlatform(final long pointer) {
|
||||
super(pointer);
|
||||
|
||||
if ( isValid() ) {
|
||||
clPlatforms.put(pointer, this);
|
||||
clDevices = new CLObjectRegistryGlobal<CLDevice>(clDevicesGlobal);
|
||||
} else
|
||||
clDevices = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a CLPlatform with the specified id.
|
||||
*
|
||||
* @param id the platform object id
|
||||
*
|
||||
* @return the CLPlatform object
|
||||
*/
|
||||
public static CLPlatform getCLPlatform(final long id) { return clPlatforms.get(id); }
|
||||
|
||||
/**
|
||||
* Returns a CLDevice that is available on this platform.
|
||||
*
|
||||
* @param id the device object id
|
||||
*
|
||||
* @return the CLDevice object
|
||||
*/
|
||||
public CLDevice getCLDevice(final long id) { return clDevices.getObject(id); }
|
||||
|
||||
// ---------------[ UTILITY METHODS ]---------------
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T extends CLObject> InfoUtil<T> getInfoUtilInstance(final Class<T> clazz, final String fieldName) {
|
||||
InfoUtil<T> instance = null;
|
||||
try {
|
||||
final Class<?> infoUtil = Class.forName("org.lwjgl.opencl.InfoUtilFactory");
|
||||
instance = (InfoUtil<T>)infoUtil.getDeclaredField(fieldName).get(null);
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all the available platforms.
|
||||
*
|
||||
* @return the available platforms
|
||||
*/
|
||||
public static List<CLPlatform> getPlatforms() {
|
||||
return getPlatforms(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the available platforms, filtered by the specified filter.
|
||||
*
|
||||
* @param filter the platform filter
|
||||
*
|
||||
* @return the available platforms
|
||||
*/
|
||||
public static List<CLPlatform> getPlatforms(final Filter<CLPlatform> filter) {
|
||||
return util.getPlatforms(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the String value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public String getInfoString(int param_name) {
|
||||
return util.getInfoString(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the available devices on this platform that
|
||||
* match the specified type.
|
||||
*
|
||||
* @param device_type the device type
|
||||
*
|
||||
* @return the available devices
|
||||
*/
|
||||
public List<CLDevice> getDevices(final int device_type) {
|
||||
return getDevices(device_type, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the available devices on this platform that
|
||||
* match the specified type, filtered by the specified filter.
|
||||
*
|
||||
* @param device_type the device type
|
||||
* @param filter the device filter
|
||||
*
|
||||
* @return the available devices
|
||||
*/
|
||||
public List<CLDevice> getDevices(final int device_type, final Filter<CLDevice> filter) {
|
||||
return util.getDevices(this, device_type, filter);
|
||||
}
|
||||
|
||||
/** CLPlatform utility methods interface. */
|
||||
interface CLPlatformUtil extends InfoUtil<CLPlatform> {
|
||||
|
||||
List<CLPlatform> getPlatforms(Filter<CLPlatform> filter);
|
||||
|
||||
List<CLDevice> getDevices(CLPlatform platform, int device_type, final Filter<CLDevice> filter);
|
||||
|
||||
}
|
||||
|
||||
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||
|
||||
void setCapabilities(final Object caps) {
|
||||
this.caps = caps;
|
||||
}
|
||||
|
|
@ -59,46 +177,57 @@ public final class CLPlatform extends PointerWrapperAbstract {
|
|||
return caps;
|
||||
}
|
||||
|
||||
// ---------------[ HELPER METHODS ]---------------
|
||||
/**
|
||||
* Called from clGetPlatformIDs to register new platforms.
|
||||
*
|
||||
* @param platforms a buffer containing CLPlatform pointers.
|
||||
*/
|
||||
static void registerCLPlatforms(final PointerBuffer platforms, final IntBuffer num_platforms) {
|
||||
if ( platforms == null )
|
||||
return;
|
||||
|
||||
static Object getClassInstance(final String className) {
|
||||
Object instance = null;
|
||||
try {
|
||||
instance = Class.forName(className).newInstance();
|
||||
} finally {
|
||||
return instance;
|
||||
final int pos = platforms.position();
|
||||
final int count = min(num_platforms.get(0), platforms.remaining()); // We can't depend on .remaining()
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
final long id = platforms.get(pos + i);
|
||||
if ( !clPlatforms.containsKey(id) )
|
||||
new CLPlatform(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<CLPlatform> getPlatforms() {
|
||||
return getPlatforms(null);
|
||||
CLObjectRegistry<CLDevice> getCLDeviceRegistry() { return clDevices; }
|
||||
|
||||
static CLDevice getCLDeviceGlobal(final long id) { return clDevicesGlobal.get(id); }
|
||||
|
||||
/**
|
||||
* Called from <code>clGetDeviceIDs</code> to register new devices.
|
||||
*
|
||||
* @param devices a buffer containing CLDevice pointers.
|
||||
*/
|
||||
void registerCLDevices(final PointerBuffer devices, final IntBuffer num_devices) {
|
||||
final int pos = devices.position();
|
||||
final int count = min(num_devices.get(num_devices.position()), devices.remaining()); // We can't depend on .remaining()
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
final long id = devices.get(pos + i);
|
||||
if ( !clDevices.hasObject(id) )
|
||||
new CLDevice(devices.get(pos + i), this);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<CLPlatform> getPlatforms(final Filter<CLPlatform> filter) {
|
||||
return impl.getPlatforms(filter);
|
||||
}
|
||||
|
||||
public String getInfoString(int param_name) {
|
||||
return impl.getInfoString(this, param_name);
|
||||
}
|
||||
|
||||
public List<CLDevice> getDevices(final int device_type) {
|
||||
return getDevices(device_type, null);
|
||||
}
|
||||
|
||||
public List<CLDevice> getDevices(final int device_type, final Filter<CLDevice> filter) {
|
||||
return impl.getDevices(this, device_type, filter);
|
||||
}
|
||||
|
||||
/** CLPlatform helper methods implementation interface. */
|
||||
interface CLPlatformImpl {
|
||||
|
||||
List<CLPlatform> getPlatforms(Filter<CLPlatform> filter);
|
||||
|
||||
String getInfoString(CLPlatform platform, int param_name);
|
||||
|
||||
List<CLDevice> getDevices(CLPlatform platform, int device_type, final Filter<CLDevice> filter);
|
||||
|
||||
/**
|
||||
* Called from <code>clGetContextInfo</code> to register new devices.
|
||||
*
|
||||
* @param devices a buffer containing CLDevice pointers.
|
||||
*/
|
||||
void registerCLDevices(final ByteBuffer devices, final PointerBuffer num_devices) {
|
||||
final int pos = devices.position();
|
||||
final int count = min((int)num_devices.get(num_devices.position()), devices.remaining()) / PointerBuffer.getPointerSize(); // We can't depend on .remaining()
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
final int offset = pos + (i * PointerBuffer.getPointerSize());
|
||||
final long id = PointerBuffer.is64Bit() ? devices.getLong(offset) : devices.getInt(offset);
|
||||
if ( !clDevices.hasObject(id) )
|
||||
new CLDevice(devices.get(pos + i), this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2010 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.opencl;
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.opencl.api.Filter;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.opencl.CL10.*;
|
||||
|
||||
/**
|
||||
* Implementation of CLPlatform helper methods.
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
final class CLPlatformImpl implements CLPlatform.CLPlatformImpl {
|
||||
|
||||
CLPlatformImpl() {
|
||||
}
|
||||
|
||||
static CLPlatformCapabilities getCapabilities(final CLPlatform platform) {
|
||||
platform.checkNull();
|
||||
|
||||
CLPlatformCapabilities caps = (CLPlatformCapabilities)platform.getCapabilities();
|
||||
if ( caps == null )
|
||||
platform.setCapabilities(caps = new CLPlatformCapabilities(platform));
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
public List<CLPlatform> getPlatforms(final Filter<CLPlatform> filter) {
|
||||
final IntBuffer numBuffer = APIUtil.getBufferInt();
|
||||
clGetPlatformIDs(null, numBuffer);
|
||||
|
||||
final int num_platforms = numBuffer.get(0);
|
||||
if ( num_platforms == 0 )
|
||||
return null;
|
||||
|
||||
final PointerBuffer platformIDs = APIUtil.getBufferPointer(num_platforms);
|
||||
clGetPlatformIDs(platformIDs, null);
|
||||
|
||||
final List<CLPlatform> platforms = new ArrayList<CLPlatform>(num_platforms);
|
||||
for ( int i = 0; i < num_platforms; i++ ) {
|
||||
final CLPlatform platform = new CLPlatform(platformIDs.get(i));
|
||||
if ( filter == null || filter.accept(platform) )
|
||||
platforms.add(platform);
|
||||
}
|
||||
|
||||
return platforms.size() == 0 ? null : platforms;
|
||||
}
|
||||
|
||||
public String getInfoString(final CLPlatform platform, final int param_name) {
|
||||
platform.checkNull();
|
||||
|
||||
final PointerBuffer bytes = APIUtil.getBufferPointer();
|
||||
clGetPlatformInfo(platform, param_name, null, bytes);
|
||||
|
||||
final ByteBuffer versionBuffer = APIUtil.getBufferByte((int)bytes.get(0));
|
||||
clGetPlatformInfo(platform, param_name, versionBuffer, null);
|
||||
|
||||
versionBuffer.limit((int)bytes.get(0) - 1); // Exclude null-termination
|
||||
return APIUtil.getString(versionBuffer);
|
||||
}
|
||||
|
||||
public List<CLDevice> getDevices(final CLPlatform platform, final int device_type, final Filter<CLDevice> filter) {
|
||||
platform.checkNull();
|
||||
|
||||
final IntBuffer numBuffer = APIUtil.getBufferInt();
|
||||
clGetDeviceIDs(platform, device_type, null, numBuffer);
|
||||
|
||||
final int num_devices = numBuffer.get(0);
|
||||
if ( num_devices == 0 )
|
||||
return null;
|
||||
|
||||
final PointerBuffer deviceIDs = APIUtil.getBufferPointer(num_devices);
|
||||
clGetDeviceIDs(platform, device_type, deviceIDs, null);
|
||||
|
||||
final List<CLDevice> devices = new ArrayList<CLDevice>(num_devices);
|
||||
for ( int i = 0; i < num_devices; i++ ) {
|
||||
final CLDevice device = new CLDevice(deviceIDs.get(i));
|
||||
if ( filter == null || filter.accept(device) )
|
||||
devices.add(device);
|
||||
}
|
||||
|
||||
return devices.size() == 0 ? null : devices;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ package org.lwjgl.opencl;
|
|||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* This class is a wrapper around a cl_program pointer.
|
||||
|
|
@ -42,6 +42,8 @@ import java.io.Serializable;
|
|||
*/
|
||||
public final class CLProgram extends CLObjectChild<CLContext> {
|
||||
|
||||
private static final CLProgramUtil util = (CLProgramUtil)CLPlatform.getInfoUtilInstance(CLProgram.class, "CL_PROGRAM_UTIL");
|
||||
|
||||
private final CLObjectRegistry<CLKernel> clKernels;
|
||||
|
||||
CLProgram(final long pointer, final CLContext context) {
|
||||
|
|
@ -65,6 +67,119 @@ public final class CLProgram extends CLObjectChild<CLContext> {
|
|||
return clKernels.getObject(id);
|
||||
}
|
||||
|
||||
// ---------------[ UTILITY METHODS ]---------------
|
||||
|
||||
/**
|
||||
* Returns the String value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public String getInfoString(final int param_name) {
|
||||
return util.getInfoString(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getInfoInt(final int param_name) {
|
||||
return util.getInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of size_t values of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter values
|
||||
*/
|
||||
public long[] getInfoSizeArray(final int param_name) {
|
||||
return util.getInfoSizeArray(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of CLDevices associated with this program.
|
||||
*
|
||||
* @return the array of devices
|
||||
*/
|
||||
public CLDevice[] getInfoDevices() {
|
||||
return util.getInfoDevices(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the program binaries for all devices associated with program,
|
||||
* written sequentially in the target ByteBuffer. If the <code>target</code>
|
||||
* parameter is null, a new ByteBuffer will be allocated. If not, the
|
||||
* target ByteBuffer must be big enough to hold the program binaries, as
|
||||
* returned by CL_PROGRAM_BINARY_SIZES.
|
||||
*
|
||||
* @param target the target ByteBuffer array.
|
||||
*
|
||||
* @return the array of devices
|
||||
*/
|
||||
public ByteBuffer getInfoBinaries(final ByteBuffer target) {
|
||||
return util.getInfoBinaries(this, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the program binaries for all devices associated with program,
|
||||
* as a ByteBuffer array. If the <code>target</code> parameter is null,
|
||||
* a new ByteBuffer array will be allocated. If not, the target ByteBuffers
|
||||
* must be big enough to hold the program binaries, as returned by
|
||||
* CL_PROGRAM_BINARY_SIZES.
|
||||
*
|
||||
* @param target the target ByteBuffer array.
|
||||
*
|
||||
* @return the array of devices
|
||||
*/
|
||||
public ByteBuffer[] getInfoBinaries(final ByteBuffer[] target) {
|
||||
return util.getInfoBinaries(this, target);
|
||||
}
|
||||
|
||||
// clGetProgramBuildInfo methods
|
||||
|
||||
/**
|
||||
* Returns the String value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public String getBuildInfoString(final CLDevice device, final int param_name) {
|
||||
return util.getBuildInfoString(this, device, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getBuildInfoInt(final CLDevice device, final int param_name) {
|
||||
return util.getBuildInfoInt(this, device, param_name);
|
||||
}
|
||||
|
||||
/** CLProgram utility methods interface. */
|
||||
interface CLProgramUtil extends InfoUtil<CLProgram> {
|
||||
|
||||
CLDevice[] getInfoDevices(CLProgram program);
|
||||
|
||||
ByteBuffer getInfoBinaries(CLProgram program, ByteBuffer target);
|
||||
|
||||
ByteBuffer[] getInfoBinaries(CLProgram program, ByteBuffer[] target);
|
||||
|
||||
String getBuildInfoString(CLProgram program, final CLDevice device, int param_name);
|
||||
|
||||
int getBuildInfoInt(CLProgram program, final CLDevice device, int param_name);
|
||||
|
||||
}
|
||||
|
||||
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||
|
||||
CLObjectRegistry<CLKernel> getCLKernelRegistry() { return clKernels; }
|
||||
|
|
|
|||
|
|
@ -38,12 +38,41 @@ package org.lwjgl.opencl;
|
|||
*/
|
||||
public final class CLSampler extends CLObjectChild<CLContext> {
|
||||
|
||||
private static final InfoUtil<CLSampler> util = CLPlatform.getInfoUtilInstance(CLSampler.class, "CL_SAMPLER_UTIL");
|
||||
|
||||
CLSampler(final long pointer, final CLContext context) {
|
||||
super(pointer, context);
|
||||
if ( isValid() )
|
||||
context.getCLSamplerRegistry().registerObject(this);
|
||||
}
|
||||
|
||||
// ---------------[ UTILITY METHODS ]---------------
|
||||
|
||||
/**
|
||||
* Returns the integer value of the specified parameter.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public int getInfoInt(int param_name) {
|
||||
return util.getInfoInt(this, param_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the long value of the specified parameter. Can be used
|
||||
* for both cl_ulong and cl_bitfield parameters.
|
||||
*
|
||||
* @param param_name the parameter
|
||||
*
|
||||
* @return the parameter value
|
||||
*/
|
||||
public long getInfoLong(int param_name) {
|
||||
return util.getInfoLong(this, param_name);
|
||||
}
|
||||
|
||||
// -------[ IMPLEMENTATION STUFF BELOW ]-------
|
||||
|
||||
int release() {
|
||||
try {
|
||||
return super.release();
|
||||
|
|
|
|||
51
src/java/org/lwjgl/opencl/InfoUtil.java
Normal file
51
src/java/org/lwjgl/opencl/InfoUtil.java
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2010 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.opencl;
|
||||
|
||||
/**
|
||||
* Base interface for information utility classes.
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
interface InfoUtil<T extends CLObject> {
|
||||
|
||||
int getInfoInt(final T object, final int param_name);
|
||||
|
||||
long getInfoSize(final T object, final int param_name);
|
||||
|
||||
long[] getInfoSizeArray(final T object, final int param_name);
|
||||
|
||||
long getInfoLong(final T object, final int param_name);
|
||||
|
||||
String getInfoString(final T object, final int param_name);
|
||||
|
||||
}
|
||||
134
src/java/org/lwjgl/opencl/InfoUtilAbstract.java
Normal file
134
src/java/org/lwjgl/opencl/InfoUtilAbstract.java
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2010 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.opencl;
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static org.lwjgl.opencl.CL10.*;
|
||||
|
||||
/**
|
||||
* Base implementation of information utility classes.
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
abstract class InfoUtilAbstract<T extends CLObject> implements InfoUtil<T> {
|
||||
|
||||
protected InfoUtilAbstract() {
|
||||
}
|
||||
|
||||
protected abstract int getInfo(T object, int param_name, ByteBuffer param_value, PointerBuffer param_value_size_ret);
|
||||
|
||||
// Optional
|
||||
|
||||
protected int getInfoSizeArraySize(final T object, final int param_name) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
protected PointerBuffer getSizesBuffer(final T object, final int param_name) {
|
||||
final int size = getInfoSizeArraySize(object, param_name);
|
||||
|
||||
final PointerBuffer buffer = APIUtil.getBufferPointer(size);
|
||||
buffer.limit(size);
|
||||
|
||||
getInfo(object, param_name, buffer.getBuffer(), null);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public int getInfoInt(final T object, final int param_name) {
|
||||
object.checkValid();
|
||||
|
||||
final ByteBuffer buffer = APIUtil.getBufferByte(4);
|
||||
getInfo(object, param_name, buffer, null);
|
||||
|
||||
return buffer.getInt(0);
|
||||
}
|
||||
|
||||
public long getInfoSize(final T object, final int param_name) {
|
||||
object.checkValid();
|
||||
|
||||
final PointerBuffer buffer = APIUtil.getBufferPointer();
|
||||
getInfo(object, param_name, buffer.getBuffer(), null);
|
||||
|
||||
return buffer.get(0);
|
||||
}
|
||||
|
||||
public long[] getInfoSizeArray(final T object, final int param_name) {
|
||||
object.checkValid();
|
||||
|
||||
final int size = getInfoSizeArraySize(object, param_name);
|
||||
final PointerBuffer buffer = APIUtil.getBufferPointer(size);
|
||||
|
||||
getInfo(object, param_name, buffer.getBuffer(), null);
|
||||
|
||||
final long[] array = new long[size];
|
||||
for ( int i = 0; i < size; i++ )
|
||||
array[i] = buffer.get(i);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public long getInfoLong(final T object, final int param_name) {
|
||||
object.checkValid();
|
||||
|
||||
final ByteBuffer buffer = APIUtil.getBufferByte(8);
|
||||
getInfo(object, param_name, buffer, null);
|
||||
|
||||
return buffer.getLong(0);
|
||||
}
|
||||
|
||||
public String getInfoString(final T object, final int param_name) {
|
||||
object.checkValid();
|
||||
|
||||
final int bytes = getSizeRet(object, param_name);
|
||||
if ( bytes == 0 )
|
||||
return "";
|
||||
|
||||
final ByteBuffer buffer = APIUtil.getBufferByte(bytes);
|
||||
getInfo(object, param_name, buffer, null);
|
||||
|
||||
buffer.limit(bytes - 1); // Exclude null-termination
|
||||
return APIUtil.getString(buffer);
|
||||
}
|
||||
|
||||
protected final int getSizeRet(final T object, final int param_name) {
|
||||
final PointerBuffer bytes = APIUtil.getBufferPointer();
|
||||
final int errcode = getInfo(object, param_name, null, bytes);
|
||||
if ( errcode != CL_SUCCESS )
|
||||
throw new IllegalArgumentException("Invalid parameter specified: " + APIUtil.toHexString(param_name));
|
||||
|
||||
return (int)bytes.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
450
src/java/org/lwjgl/opencl/InfoUtilFactory.java
Normal file
450
src/java/org/lwjgl/opencl/InfoUtilFactory.java
Normal file
|
|
@ -0,0 +1,450 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2010 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.opencl;
|
||||
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.opencl.api.Filter;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.opencl.CL10.*;
|
||||
import static org.lwjgl.opencl.CL10GL.*;
|
||||
import static org.lwjgl.opencl.CL11.*;
|
||||
|
||||
/**
|
||||
* This class contains concrete InfoUtil implementations for our CLObject
|
||||
* class. The public CLObject classes are grabbing these via reflection,
|
||||
* so that they can be compiled for the generator.
|
||||
*
|
||||
* @author Spasi
|
||||
* @since 28 Óåð 2010
|
||||
*/
|
||||
final class InfoUtilFactory {
|
||||
|
||||
private InfoUtilFactory() {}
|
||||
|
||||
static final InfoUtil<CLCommandQueue> CL_COMMAND_QUEUE_UTIL = new InfoUtilAbstract<CLCommandQueue>() {
|
||||
protected int getInfo(final CLCommandQueue object, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
|
||||
return clGetCommandQueueInfo(object, param_name, param_value, null);
|
||||
}
|
||||
};
|
||||
|
||||
static final CLContext.CLContextUtil CL_CONTEXT_UTIL = new CLContextUtil();
|
||||
private static final class CLContextUtil extends InfoUtilAbstract<CLContext> implements CLContext.CLContextUtil {
|
||||
|
||||
protected int getInfo(final CLContext context, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
|
||||
return clGetContextInfo(context, param_name, param_value, param_value_size_ret);
|
||||
}
|
||||
|
||||
public List<CLDevice> getInfoDevices(final CLContext context) {
|
||||
context.checkValid();
|
||||
|
||||
final int num_devices;
|
||||
|
||||
if ( CLCapabilities.getPlatformCapabilities(context.getParent()).OpenCL11 )
|
||||
num_devices = getInfoInt(context, CL_CONTEXT_NUM_DEVICES);
|
||||
else {
|
||||
final PointerBuffer size_ret = APIUtil.getBufferPointer();
|
||||
clGetContextInfo(context, CL_CONTEXT_DEVICES, null, size_ret);
|
||||
num_devices = (int)(size_ret.get(0) / PointerBuffer.getPointerSize());
|
||||
}
|
||||
|
||||
final PointerBuffer deviceIDs = APIUtil.getBufferPointer(num_devices);
|
||||
clGetContextInfo(context, CL_CONTEXT_DEVICES, deviceIDs.getBuffer(), null);
|
||||
|
||||
final List<CLDevice> devices = new ArrayList<CLDevice>(num_devices);
|
||||
for ( int i = 0; i < num_devices; i++ )
|
||||
devices.add(context.getParent().getCLDevice(deviceIDs.get(i)));
|
||||
|
||||
return devices.size() == 0 ? null : devices;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final InfoUtil<CLDevice> CL_DEVICE_UTIL = new CLDeviceUtil();
|
||||
private static final class CLDeviceUtil extends InfoUtilAbstract<CLDevice> {
|
||||
|
||||
protected int getInfo(final CLDevice device, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
|
||||
return clGetDeviceInfo(device, param_name, param_value, param_value_size_ret);
|
||||
}
|
||||
|
||||
protected int getInfoSizeArraySize(final CLDevice device, final int param_name) {
|
||||
switch ( param_name ) {
|
||||
case CL_DEVICE_MAX_WORK_ITEM_SIZES:
|
||||
return getInfoInt(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported parameter: " + APIUtil.toHexString(param_name));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final CLEvent.CLEventUtil CL_EVENT_UTIL = new CLEventUtil();
|
||||
private static final class CLEventUtil extends InfoUtilAbstract<CLEvent> implements CLEvent.CLEventUtil {
|
||||
|
||||
protected int getInfo(final CLEvent event, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
|
||||
return clGetEventInfo(event, param_name, param_value, param_value_size_ret);
|
||||
}
|
||||
|
||||
public long getProfilingInfoLong(final CLEvent event, final int param_name) {
|
||||
event.checkValid();
|
||||
|
||||
final ByteBuffer buffer = APIUtil.getBufferByte(8);
|
||||
clGetEventProfilingInfo(event, param_name, buffer, null);
|
||||
|
||||
return buffer.getLong(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final CLKernel.CLKernelUtil CL_KERNEL_UTIL = new CLKernelUtil();
|
||||
private static final class CLKernelUtil extends InfoUtilAbstract<CLKernel> implements CLKernel.CLKernelUtil {
|
||||
|
||||
public void setArg(final CLKernel kernel, final int index, final byte value) {
|
||||
clSetKernelArg(kernel, index, 1, APIUtil.getBufferByte(1).put(0, value));
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel kernel, final int index, final short value) {
|
||||
clSetKernelArg(kernel, index, 2, APIUtil.getBufferShort().put(0, value));
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel kernel, final int index, final int value) {
|
||||
clSetKernelArg(kernel, index, 4, APIUtil.getBufferInt().put(0, value));
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel kernel, final int index, final long value) {
|
||||
clSetKernelArg(kernel, index, 8, APIUtil.getBufferLong().put(0, value));
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel kernel, final int index, final float value) {
|
||||
clSetKernelArg(kernel, index, 4, APIUtil.getBufferFloat().put(0, value));
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel kernel, final int index, final double value) {
|
||||
clSetKernelArg(kernel, index, 8, APIUtil.getBufferDouble().put(0, value));
|
||||
}
|
||||
|
||||
public void setArg(final CLKernel kernel, final int index, final PointerWrapper pointer) {
|
||||
clSetKernelArg(kernel, index, PointerBuffer.getPointerSize(), APIUtil.getBufferPointer().put(0, pointer).getBuffer());
|
||||
}
|
||||
|
||||
protected int getInfo(final CLKernel kernel, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
|
||||
return clGetKernelInfo(kernel, param_name, param_value, param_value_size_ret);
|
||||
}
|
||||
|
||||
public long getWorkGroupInfoSize(final CLKernel kernel, final CLDevice device, final int param_name) {
|
||||
device.checkValid();
|
||||
|
||||
final PointerBuffer buffer = APIUtil.getBufferPointer();
|
||||
clGetKernelWorkGroupInfo(kernel, device, param_name, buffer.getBuffer(), null);
|
||||
|
||||
return buffer.get(0);
|
||||
}
|
||||
|
||||
public long[] getWorkGroupInfoSizeArray(final CLKernel kernel, final CLDevice device, final int param_name) {
|
||||
device.checkValid();
|
||||
|
||||
final int size;
|
||||
switch ( param_name ) {
|
||||
case CL_KERNEL_WORK_GROUP_SIZE:
|
||||
size = 3;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported parameter: " + APIUtil.toHexString(param_name));
|
||||
}
|
||||
|
||||
final PointerBuffer buffer = APIUtil.getBufferPointer(size);
|
||||
|
||||
clGetKernelWorkGroupInfo(kernel, device, param_name, buffer.getBuffer(), null);
|
||||
|
||||
final long[] array = new long[size];
|
||||
for ( int i = 0; i < size; i++ )
|
||||
array[i] = buffer.get(i);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public long getWorkGroupInfoLong(final CLKernel kernel, final CLDevice device, final int param_name) {
|
||||
device.checkValid();
|
||||
|
||||
final ByteBuffer buffer = APIUtil.getBufferByte(8);
|
||||
clGetKernelWorkGroupInfo(kernel, device, param_name, buffer, null);
|
||||
|
||||
return buffer.getLong(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final CLMem.CLMemUtil CL_MEM_UTIL = new CLMemUtil();
|
||||
private static final class CLMemUtil extends InfoUtilAbstract<CLMem> implements CLMem.CLMemUtil {
|
||||
|
||||
protected int getInfo(final CLMem mem, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
|
||||
return clGetMemObjectInfo(mem, param_name, param_value, param_value_size_ret);
|
||||
}
|
||||
|
||||
public ByteBuffer getInfoHostBuffer(final CLMem mem) {
|
||||
mem.checkValid();
|
||||
|
||||
if ( LWJGLUtil.DEBUG ) {
|
||||
final long mem_flags = getInfoLong(mem, CL_MEM_FLAGS);
|
||||
if ( (mem_flags & CL_MEM_USE_HOST_PTR) != CL_MEM_USE_HOST_PTR )
|
||||
throw new IllegalArgumentException("The specified CLMem object does not use host memory.");
|
||||
}
|
||||
|
||||
final long size = getInfoSize(mem, CL_MEM_SIZE);
|
||||
if ( size == 0 )
|
||||
return null;
|
||||
|
||||
final long address = getInfoSize(mem, CL_MEM_HOST_PTR);
|
||||
|
||||
return CL.getHostBuffer(address, (int)size);
|
||||
}
|
||||
|
||||
public long getImageInfoSize(final CLMem mem, final int param_name) {
|
||||
mem.checkValid();
|
||||
|
||||
final PointerBuffer buffer = APIUtil.getBufferPointer();
|
||||
clGetImageInfo(mem, param_name, buffer.getBuffer(), null);
|
||||
|
||||
return buffer.get(0);
|
||||
}
|
||||
|
||||
public int getImageInfoFormat(final CLMem mem, final int index) {
|
||||
mem.checkValid();
|
||||
|
||||
final ByteBuffer format = APIUtil.getBufferByte(2 * 4);
|
||||
|
||||
clGetImageInfo(mem, CL_IMAGE_FORMAT, format, null);
|
||||
|
||||
return format.getInt(index << 2);
|
||||
}
|
||||
|
||||
public int getGLObjectType(final CLMem mem) {
|
||||
mem.checkValid();
|
||||
|
||||
final IntBuffer buffer = APIUtil.getBufferInt();
|
||||
clGetGLObjectInfo(mem, buffer, null);
|
||||
|
||||
return buffer.get(0);
|
||||
}
|
||||
|
||||
public int getGLObjectName(final CLMem mem) {
|
||||
mem.checkValid();
|
||||
|
||||
final IntBuffer buffer = APIUtil.getBufferInt();
|
||||
clGetGLObjectInfo(mem, null, buffer);
|
||||
|
||||
return buffer.get(0);
|
||||
}
|
||||
|
||||
public int getGLTextureInfoInt(final CLMem mem, final int param_name) {
|
||||
mem.checkValid();
|
||||
|
||||
final ByteBuffer buffer = APIUtil.getBufferByte(4);
|
||||
clGetGLTextureInfo(mem, param_name, buffer, null);
|
||||
|
||||
return buffer.getInt(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final CLPlatform.CLPlatformUtil CL_PLATFORM_UTIL = new CLPlatformUtil();
|
||||
private static final class CLPlatformUtil extends InfoUtilAbstract<CLPlatform> implements CLPlatform.CLPlatformUtil {
|
||||
|
||||
protected int getInfo(final CLPlatform platform, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
|
||||
return clGetPlatformInfo(platform, param_name, param_value, param_value_size_ret);
|
||||
}
|
||||
|
||||
public List<CLPlatform> getPlatforms(final Filter<CLPlatform> filter) {
|
||||
final IntBuffer numBuffer = APIUtil.getBufferInt();
|
||||
clGetPlatformIDs(null, numBuffer);
|
||||
|
||||
final int num_platforms = numBuffer.get(0);
|
||||
if ( num_platforms == 0 )
|
||||
return null;
|
||||
|
||||
final PointerBuffer platformIDs = APIUtil.getBufferPointer(num_platforms);
|
||||
clGetPlatformIDs(platformIDs, null);
|
||||
|
||||
final List<CLPlatform> platforms = new ArrayList<CLPlatform>(num_platforms);
|
||||
for ( int i = 0; i < num_platforms; i++ ) {
|
||||
final CLPlatform platform = CLPlatform.getCLPlatform(platformIDs.get(i));
|
||||
if ( filter == null || filter.accept(platform) )
|
||||
platforms.add(platform);
|
||||
}
|
||||
|
||||
return platforms.size() == 0 ? null : platforms;
|
||||
}
|
||||
|
||||
public List<CLDevice> getDevices(final CLPlatform platform, final int device_type, final Filter<CLDevice> filter) {
|
||||
platform.checkValid();
|
||||
|
||||
final IntBuffer numBuffer = APIUtil.getBufferInt();
|
||||
clGetDeviceIDs(platform, device_type, null, numBuffer);
|
||||
|
||||
final int num_devices = numBuffer.get(0);
|
||||
if ( num_devices == 0 )
|
||||
return null;
|
||||
|
||||
final PointerBuffer deviceIDs = APIUtil.getBufferPointer(num_devices);
|
||||
clGetDeviceIDs(platform, device_type, deviceIDs, null);
|
||||
|
||||
final List<CLDevice> devices = new ArrayList<CLDevice>(num_devices);
|
||||
for ( int i = 0; i < num_devices; i++ ) {
|
||||
final CLDevice device = platform.getCLDevice(deviceIDs.get(i));
|
||||
if ( filter == null || filter.accept(device) )
|
||||
devices.add(device);
|
||||
}
|
||||
|
||||
return devices.size() == 0 ? null : devices;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final CLProgram.CLProgramUtil CL_PROGRAM_UTIL = new CLProgramUtil();
|
||||
private static final class CLProgramUtil extends InfoUtilAbstract<CLProgram> implements CLProgram.CLProgramUtil {
|
||||
|
||||
protected int getInfo(final CLProgram program, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
|
||||
return clGetProgramInfo(program, param_name, param_value, param_value_size_ret);
|
||||
}
|
||||
|
||||
protected int getInfoSizeArraySize(final CLProgram program, final int param_name) {
|
||||
switch ( param_name ) {
|
||||
case CL_PROGRAM_BINARY_SIZES:
|
||||
return getInfoInt(program, CL_PROGRAM_NUM_DEVICES);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported parameter: " + APIUtil.toHexString(param_name));
|
||||
}
|
||||
}
|
||||
|
||||
public CLDevice[] getInfoDevices(final CLProgram program) {
|
||||
program.checkValid();
|
||||
|
||||
final int size = getInfoInt(program, CL_PROGRAM_NUM_DEVICES);
|
||||
final PointerBuffer buffer = APIUtil.getBufferPointer(size);
|
||||
|
||||
clGetProgramInfo(program, CL_PROGRAM_DEVICES, buffer.getBuffer(), null);
|
||||
|
||||
final CLPlatform platform = program.getParent().getParent();
|
||||
final CLDevice[] array = new CLDevice[size];
|
||||
for ( int i = 0; i < size; i++ )
|
||||
array[i] = platform.getCLDevice(buffer.get(i));
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public ByteBuffer getInfoBinaries(final CLProgram program, ByteBuffer target) {
|
||||
program.checkValid();
|
||||
|
||||
final PointerBuffer sizes = getSizesBuffer(program, CL_PROGRAM_BINARY_SIZES);
|
||||
|
||||
int totalSize = 0;
|
||||
for ( int i = 0; i < sizes.limit(); i++ )
|
||||
totalSize += sizes.get(i);
|
||||
|
||||
if ( target == null )
|
||||
target = BufferUtils.createByteBuffer(totalSize);
|
||||
else if ( LWJGLUtil.DEBUG )
|
||||
BufferChecks.checkBuffer(target, totalSize);
|
||||
|
||||
clGetProgramInfo(program, sizes, target, null);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
public ByteBuffer[] getInfoBinaries(final CLProgram program, ByteBuffer[] target) {
|
||||
program.checkValid();
|
||||
|
||||
if ( target == null ) {
|
||||
final PointerBuffer sizes = getSizesBuffer(program, CL_PROGRAM_BINARY_SIZES);
|
||||
|
||||
target = new ByteBuffer[sizes.remaining()];
|
||||
for ( int i = 0; i < sizes.remaining(); i++ )
|
||||
target[i] = BufferUtils.createByteBuffer((int)sizes.get(0));
|
||||
} else if ( LWJGLUtil.DEBUG ) {
|
||||
final PointerBuffer sizes = getSizesBuffer(program, CL_PROGRAM_BINARY_SIZES);
|
||||
|
||||
if ( target.length < sizes.remaining() )
|
||||
throw new IllegalArgumentException("The target array is not big enough: " + sizes.remaining() + " buffers are required.");
|
||||
|
||||
for ( int i = 0; i < target.length; i++ )
|
||||
BufferChecks.checkBuffer(target[i], (int)sizes.get(i));
|
||||
}
|
||||
|
||||
clGetProgramInfo(program, target, null);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
public String getBuildInfoString(final CLProgram program, final CLDevice device, final int param_name) {
|
||||
program.checkValid();
|
||||
|
||||
final int bytes = getBuildSizeRet(program, device, param_name);
|
||||
if ( bytes == 0 )
|
||||
throw new IllegalArgumentException("Invalid parameter specified: " + APIUtil.toHexString(param_name));
|
||||
|
||||
final ByteBuffer buffer = APIUtil.getBufferByte(bytes);
|
||||
clGetProgramBuildInfo(program, device, param_name, buffer, null);
|
||||
|
||||
buffer.limit(bytes - 1); // Exclude null-termination
|
||||
return APIUtil.getString(buffer);
|
||||
}
|
||||
|
||||
public int getBuildInfoInt(final CLProgram program, final CLDevice device, final int param_name) {
|
||||
program.checkValid();
|
||||
|
||||
final ByteBuffer buffer = APIUtil.getBufferByte(4);
|
||||
clGetProgramBuildInfo(program, device, param_name, buffer, null);
|
||||
|
||||
return buffer.getInt(0);
|
||||
}
|
||||
|
||||
private static int getBuildSizeRet(final CLProgram program, final CLDevice device, final int param_name) {
|
||||
final PointerBuffer bytes = APIUtil.getBufferPointer();
|
||||
final int errcode = clGetProgramBuildInfo(program, device, param_name, null, bytes);
|
||||
|
||||
return errcode == CL_SUCCESS ? (int)bytes.get(0) : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final InfoUtil<CLSampler> CL_SAMPLER_UTIL = new InfoUtilAbstract<CLSampler>() {
|
||||
protected int getInfo(final CLSampler sampler, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) {
|
||||
return clGetSamplerInfo(sampler, param_name, param_value, param_value_size_ret);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ public final class Util {
|
|||
String errname = CL_ERROR_TOKENS.get(errcode);
|
||||
if ( errname == null )
|
||||
errname = "UNKNOWN";
|
||||
throw new OpenCLException("Error Code: " + errname + " (0x" + Integer.toHexString(errcode).toUpperCase() + ")");
|
||||
throw new OpenCLException("Error Code: " + errname + " (" + APIUtil.toHexString(errcode) + ")");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -58,6 +58,19 @@ public final class AMDDebugOutputCallback extends PointerWrapperAbstract {
|
|||
GL_DEBUG_CATEGORY_APPLICATION_AMD = 0x914F,
|
||||
GL_DEBUG_CATEGORY_OTHER_AMD = 0x9150;
|
||||
|
||||
private static final long CALLBACK_POINTER;
|
||||
|
||||
static {
|
||||
long pointer = 0;
|
||||
try {
|
||||
// Call reflectively so that we can compile this class for the Generator.
|
||||
pointer = (Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackAMD").invoke(null);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
CALLBACK_POINTER = pointer;
|
||||
}
|
||||
|
||||
private final Handler handler;
|
||||
|
||||
/**
|
||||
|
|
@ -129,7 +142,7 @@ public final class AMDDebugOutputCallback extends PointerWrapperAbstract {
|
|||
* @param handler the callback handler
|
||||
*/
|
||||
public AMDDebugOutputCallback(final Handler handler) {
|
||||
super(getFunctionPointer());
|
||||
super(CALLBACK_POINTER);
|
||||
|
||||
this.handler = handler;
|
||||
}
|
||||
|
|
@ -138,15 +151,6 @@ public final class AMDDebugOutputCallback extends PointerWrapperAbstract {
|
|||
return handler;
|
||||
}
|
||||
|
||||
private static long getFunctionPointer() {
|
||||
try {
|
||||
// Call reflectively so that we can compile this class for the Generator.
|
||||
return ((Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackAMD", null).invoke(null, null)).longValue();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getCause() != null ? e.getCause() : e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Implementations of this interface can be used to receive AMD_debug_output notifications. */
|
||||
public interface Handler {
|
||||
|
||||
|
|
|
|||
|
|
@ -45,24 +45,24 @@ final class APIUtil {
|
|||
|
||||
private static final int BUFFERS_SIZE = 32;
|
||||
|
||||
private static final ThreadLocal arrayTL = new ThreadLocal() {
|
||||
protected Object initialValue() { return new char[INITIAL_BUFFER_SIZE]; }
|
||||
private static final ThreadLocal<char[]> arrayTL = new ThreadLocal<char[]>() {
|
||||
protected char[] initialValue() { return new char[INITIAL_BUFFER_SIZE]; }
|
||||
};
|
||||
|
||||
private static final ThreadLocal bufferTL = new ThreadLocal() {
|
||||
protected Object initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); }
|
||||
private static final ThreadLocal<ByteBuffer> bufferTL = new ThreadLocal<ByteBuffer>() {
|
||||
protected ByteBuffer initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); }
|
||||
};
|
||||
|
||||
private static final ThreadLocal lengthsTL = new ThreadLocal() {
|
||||
protected Object initialValue() { return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); }
|
||||
private static final ThreadLocal<IntBuffer> lengthsTL = new ThreadLocal<IntBuffer>() {
|
||||
protected IntBuffer initialValue() { return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); }
|
||||
};
|
||||
|
||||
private static final ThreadLocal infiniteSeqTL = new ThreadLocal() {
|
||||
protected Object initialValue() { return new InfiniteCharSequence(); }
|
||||
private static final ThreadLocal<InfiniteCharSequence> infiniteSeqTL = new ThreadLocal<InfiniteCharSequence>() {
|
||||
protected InfiniteCharSequence initialValue() { return new InfiniteCharSequence(); }
|
||||
};
|
||||
|
||||
private static final ThreadLocal buffersTL = new ThreadLocal() {
|
||||
protected Object initialValue() { return new Buffers(); }
|
||||
private static final ThreadLocal<Buffers> buffersTL = new ThreadLocal<Buffers>() {
|
||||
protected Buffers initialValue() { return new Buffers(); }
|
||||
};
|
||||
|
||||
private static CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();
|
||||
|
|
@ -71,7 +71,7 @@ final class APIUtil {
|
|||
}
|
||||
|
||||
private static char[] getArray(final int size) {
|
||||
char[] array = (char[])arrayTL.get();
|
||||
char[] array = arrayTL.get();
|
||||
|
||||
if ( array.length < size ) {
|
||||
int sizeNew = array.length << 1;
|
||||
|
|
@ -86,7 +86,7 @@ final class APIUtil {
|
|||
}
|
||||
|
||||
static ByteBuffer getBufferByte(final int size) {
|
||||
ByteBuffer buffer = (ByteBuffer)bufferTL.get();
|
||||
ByteBuffer buffer = bufferTL.get();
|
||||
|
||||
if ( buffer.capacity() < size ) {
|
||||
int sizeNew = buffer.capacity() << 1;
|
||||
|
|
@ -102,7 +102,7 @@ final class APIUtil {
|
|||
}
|
||||
|
||||
private static ByteBuffer getBufferByteOffset(final int size) {
|
||||
ByteBuffer buffer = (ByteBuffer)bufferTL.get();
|
||||
ByteBuffer buffer = bufferTL.get();
|
||||
|
||||
if ( buffer.capacity() < size ) {
|
||||
int sizeNew = buffer.capacity() << 1;
|
||||
|
|
@ -120,22 +120,22 @@ final class APIUtil {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
static ShortBuffer getBufferShort() { return ((Buffers)buffersTL.get()).shorts; }
|
||||
static ShortBuffer getBufferShort() { return buffersTL.get().shorts; }
|
||||
|
||||
static IntBuffer getBufferInt() { return ((Buffers)buffersTL.get()).ints; }
|
||||
static IntBuffer getBufferInt() { return buffersTL.get().ints; }
|
||||
|
||||
static LongBuffer getBufferLong() { return ((Buffers)buffersTL.get()).longs; }
|
||||
static LongBuffer getBufferLong() { return buffersTL.get().longs; }
|
||||
|
||||
static FloatBuffer getBufferFloat() { return ((Buffers)buffersTL.get()).floats; }
|
||||
static FloatBuffer getBufferFloat() { return buffersTL.get().floats; }
|
||||
|
||||
static DoubleBuffer getBufferDouble() { return ((Buffers)buffersTL.get()).doubles; }
|
||||
static DoubleBuffer getBufferDouble() { return buffersTL.get().doubles; }
|
||||
|
||||
static IntBuffer getLengths() {
|
||||
return getLengths(1);
|
||||
}
|
||||
|
||||
static IntBuffer getLengths(final int size) {
|
||||
IntBuffer lengths = (IntBuffer)lengthsTL.get();
|
||||
IntBuffer lengths = lengthsTL.get();
|
||||
|
||||
if ( lengths.capacity() < size ) {
|
||||
int sizeNew = lengths.capacity();
|
||||
|
|
@ -151,7 +151,7 @@ final class APIUtil {
|
|||
}
|
||||
|
||||
private static InfiniteCharSequence getInfiniteSeq() {
|
||||
return (InfiniteCharSequence)infiniteSeqTL.get();
|
||||
return infiniteSeqTL.get();
|
||||
}
|
||||
|
||||
private static void encode(final ByteBuffer buffer, final CharSequence string) {
|
||||
|
|
@ -229,8 +229,8 @@ final class APIUtil {
|
|||
|
||||
static int getTotalLength(final CharSequence[] strings) {
|
||||
int length = 0;
|
||||
for ( int i = 0; i < strings.length; i++ )
|
||||
length += strings[i].length();
|
||||
for ( CharSequence string : strings )
|
||||
length += string.length();
|
||||
|
||||
return length;
|
||||
}
|
||||
|
|
@ -246,8 +246,8 @@ final class APIUtil {
|
|||
final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
|
||||
|
||||
final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
|
||||
for ( int i = 0; i < strings.length; i++ ) {
|
||||
infiniteSeq.setString(strings[i]);
|
||||
for ( CharSequence string : strings ) {
|
||||
infiniteSeq.setString(string);
|
||||
encoder.encode(infiniteSeq.buffer, buffer, true);
|
||||
}
|
||||
infiniteSeq.clear();
|
||||
|
|
@ -267,8 +267,8 @@ final class APIUtil {
|
|||
final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
|
||||
|
||||
final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
|
||||
for ( int i = 0; i < strings.length; i++ ) {
|
||||
infiniteSeq.setString(strings[i]);
|
||||
for ( CharSequence string : strings ) {
|
||||
infiniteSeq.setString(string);
|
||||
encoder.encode(infiniteSeq.buffer, buffer, true);
|
||||
buffer.put((byte)0);
|
||||
}
|
||||
|
|
@ -288,8 +288,8 @@ final class APIUtil {
|
|||
static IntBuffer getLengths(final CharSequence[] strings) {
|
||||
IntBuffer buffer = getLengths(strings.length);
|
||||
|
||||
for ( int i = 0; i < strings.length; i++ )
|
||||
buffer.put(strings[i].length());
|
||||
for ( CharSequence string : strings )
|
||||
buffer.put(string.length());
|
||||
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
|
|
|
|||
|
|
@ -67,6 +67,19 @@ public final class ARBDebugOutputCallback extends PointerWrapperAbstract {
|
|||
GL_DEBUG_TYPE_PERFORMANCE_ARB = 0x8250,
|
||||
GL_DEBUG_TYPE_OTHER_ARB = 0x8251;
|
||||
|
||||
private static final long CALLBACK_POINTER;
|
||||
|
||||
static {
|
||||
long pointer = 0;
|
||||
try {
|
||||
// Call reflectively so that we can compile this class for the Generator.
|
||||
pointer = (Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackARB").invoke(null);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
CALLBACK_POINTER = pointer;
|
||||
}
|
||||
|
||||
private final Handler handler;
|
||||
|
||||
/**
|
||||
|
|
@ -156,7 +169,7 @@ public final class ARBDebugOutputCallback extends PointerWrapperAbstract {
|
|||
* @param handler the callback handler
|
||||
*/
|
||||
public ARBDebugOutputCallback(final Handler handler) {
|
||||
super(getFunctionPointer());
|
||||
super(CALLBACK_POINTER);
|
||||
|
||||
this.handler = handler;
|
||||
}
|
||||
|
|
@ -165,15 +178,6 @@ public final class ARBDebugOutputCallback extends PointerWrapperAbstract {
|
|||
return handler;
|
||||
}
|
||||
|
||||
private static long getFunctionPointer() {
|
||||
try {
|
||||
// Call reflectively so that we can compile this class for the Generator.
|
||||
return ((Long)Class.forName("org.lwjgl.opengl.CallbackUtil").getDeclaredMethod("getDebugOutputCallbackARB", null).invoke(null, null)).longValue();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getCause() != null ? e.getCause() : e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Implementations of this interface can be used to receive ARB_debug_output notifications. */
|
||||
public interface Handler {
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListe
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final static AWTCanvasImplementation implementation;
|
||||
private static final AWTCanvasImplementation implementation;
|
||||
private boolean update_context;
|
||||
private Object SYNC_LOCK = new Object();
|
||||
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ import org.lwjgl.LWJGLUtil;
|
|||
*/
|
||||
final class AWTSurfaceLock {
|
||||
|
||||
private final static int WAIT_DELAY_MILLIS = 100;
|
||||
private static final int WAIT_DELAY_MILLIS = 100;
|
||||
|
||||
private final ByteBuffer lock_buffer;
|
||||
|
||||
private boolean firstLockSucceeded = false;
|
||||
private boolean firstLockSucceeded;
|
||||
|
||||
AWTSurfaceLock() {
|
||||
lock_buffer = createHandle();
|
||||
|
|
@ -83,13 +83,11 @@ final class AWTSurfaceLock {
|
|||
return lockAndInitHandle(lock_buffer, component);
|
||||
else
|
||||
try {
|
||||
final Object result = AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
|
||||
public Object run() throws LWJGLException {
|
||||
return Boolean.valueOf(lockAndInitHandle(lock_buffer, component));
|
||||
firstLockSucceeded = AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
|
||||
public Boolean run() throws LWJGLException {
|
||||
return lockAndInitHandle(lock_buffer, component);
|
||||
}
|
||||
});
|
||||
firstLockSucceeded = ((Boolean) result).booleanValue();
|
||||
return firstLockSucceeded;
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (LWJGLException) e.getException();
|
||||
|
|
|
|||
|
|
@ -87,12 +87,11 @@ final class AWTUtil {
|
|||
|
||||
public static Robot createRobot(final Component component) {
|
||||
try {
|
||||
Robot robot = (Robot)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<Robot>() {
|
||||
public Robot run() throws Exception {
|
||||
return new Robot(component.getGraphicsConfiguration().getDevice());
|
||||
}
|
||||
});
|
||||
return robot;
|
||||
} catch (PrivilegedActionException e) {
|
||||
LWJGLUtil.log("Got exception while creating robot: " + e.getCause());
|
||||
return null;
|
||||
|
|
@ -112,8 +111,8 @@ final class AWTUtil {
|
|||
try {
|
||||
final GraphicsConfiguration config = component.getGraphicsConfiguration();
|
||||
if (config != null) {
|
||||
PointerInfo pointer_info = (PointerInfo)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
PointerInfo pointer_info = AccessController.doPrivileged(new PrivilegedExceptionAction<PointerInfo>() {
|
||||
public PointerInfo run() throws Exception {
|
||||
return MouseInfo.getPointerInfo();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -34,12 +34,16 @@ package org.lwjgl.opengl;
|
|||
import java.nio.Buffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL13.*;
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
|
||||
class BaseReferences {
|
||||
|
||||
int elementArrayBuffer;
|
||||
int arrayBuffer;
|
||||
Buffer[] glVertexAttribPointer_buffer;
|
||||
Buffer[] glTexCoordPointer_buffer;
|
||||
final Buffer[] glVertexAttribPointer_buffer;
|
||||
final Buffer[] glTexCoordPointer_buffer;
|
||||
int glClientActiveTexture;
|
||||
|
||||
int pixelPackBuffer;
|
||||
|
|
@ -50,16 +54,16 @@ class BaseReferences {
|
|||
BaseReferences(ContextCapabilities caps) {
|
||||
int max_vertex_attribs;
|
||||
if (caps.OpenGL20 || caps.GL_ARB_vertex_shader)
|
||||
max_vertex_attribs = GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_ATTRIBS_ARB);
|
||||
max_vertex_attribs = glGetInteger(GL_MAX_VERTEX_ATTRIBS);
|
||||
else
|
||||
max_vertex_attribs = 0;
|
||||
glVertexAttribPointer_buffer = new Buffer[max_vertex_attribs];
|
||||
|
||||
int max_texture_units;
|
||||
if (caps.OpenGL20)
|
||||
max_texture_units = GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS);
|
||||
max_texture_units = glGetInteger(GL_MAX_TEXTURE_IMAGE_UNITS);
|
||||
else if (caps.OpenGL13 || caps.GL_ARB_multitexture)
|
||||
max_texture_units = GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS);
|
||||
max_texture_units = glGetInteger(GL_MAX_TEXTURE_UNITS);
|
||||
else
|
||||
max_texture_units = 1;
|
||||
glTexCoordPointer_buffer = new Buffer[max_texture_units];
|
||||
|
|
@ -79,7 +83,7 @@ class BaseReferences {
|
|||
}
|
||||
|
||||
void copy(BaseReferences references, int mask) {
|
||||
if ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {
|
||||
if ( (mask & GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {
|
||||
this.elementArrayBuffer = references.elementArrayBuffer;
|
||||
this.arrayBuffer = references.arrayBuffer;
|
||||
this.glClientActiveTexture = references.glClientActiveTexture;
|
||||
|
|
@ -89,7 +93,7 @@ class BaseReferences {
|
|||
this.indirectBuffer = references.indirectBuffer;
|
||||
}
|
||||
|
||||
if ( (mask & GL11.GL_CLIENT_PIXEL_STORE_BIT) != 0 ) {
|
||||
if ( (mask & GL_CLIENT_PIXEL_STORE_BIT) != 0 ) {
|
||||
this.pixelPackBuffer = references.pixelPackBuffer;
|
||||
this.pixelUnpackBuffer = references.pixelUnpackBuffer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ import java.util.Map;
|
|||
final class CallbackUtil {
|
||||
|
||||
/** Context -> Long */
|
||||
private static final Map contextUserParamsARB = new HashMap();
|
||||
private static final Map<Context, Long> contextUserParamsARB = new HashMap<Context, Long>();
|
||||
/** Context -> Long */
|
||||
private static final Map contextUserParamsAMD = new HashMap();
|
||||
private static final Map<Context, Long> contextUserParamsAMD = new HashMap<Context, Long>();
|
||||
|
||||
private CallbackUtil() {}
|
||||
|
||||
|
|
@ -84,19 +84,19 @@ final class CallbackUtil {
|
|||
*
|
||||
* @param userParam the global reference pointer
|
||||
*/
|
||||
private static void registerContextCallback(final long userParam, final Map contextUserData) {
|
||||
private static void registerContextCallback(final long userParam, final Map<Context, Long> contextUserData) {
|
||||
Context context = Context.getCurrentContext();
|
||||
if ( context == null ) {
|
||||
deleteGlobalRef(userParam);
|
||||
throw new IllegalStateException("No context is current.");
|
||||
}
|
||||
|
||||
final Long userParam_old = (Long)contextUserData.remove(context);
|
||||
final Long userParam_old = contextUserData.remove(context);
|
||||
if ( userParam_old != null )
|
||||
deleteGlobalRef(userParam_old.longValue());
|
||||
deleteGlobalRef(userParam_old);
|
||||
|
||||
if ( userParam != 0 )
|
||||
contextUserData.put(context, new Long(userParam));
|
||||
contextUserData.put(context, userParam);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -105,13 +105,13 @@ final class CallbackUtil {
|
|||
* @param context the Context to unregister
|
||||
*/
|
||||
static void unregisterCallbacks(final Context context) {
|
||||
Long userParam = (Long)contextUserParamsARB.remove(context);
|
||||
Long userParam = contextUserParamsARB.remove(context);
|
||||
if ( userParam != null )
|
||||
deleteGlobalRef(userParam.longValue());
|
||||
deleteGlobalRef(userParam);
|
||||
|
||||
userParam = (Long)contextUserParamsAMD.remove(context);
|
||||
userParam = contextUserParamsAMD.remove(context);
|
||||
if ( userParam != null )
|
||||
deleteGlobalRef(userParam.longValue());
|
||||
deleteGlobalRef(userParam);
|
||||
}
|
||||
|
||||
// --------- [ ARB_debug_output ] ---------
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ import org.lwjgl.opencl.KHRGLSharing;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/**
|
||||
* <p/>
|
||||
* Context encapsulates an OpenGL context.
|
||||
|
|
@ -57,7 +59,7 @@ final class Context {
|
|||
private static final ContextImplementation implementation;
|
||||
|
||||
/** The current Context */
|
||||
private static final ThreadLocal current_context_local = new ThreadLocal();
|
||||
private static final ThreadLocal<Context> current_context_local = new ThreadLocal<Context>();
|
||||
|
||||
/** Handle to the native GL rendering context */
|
||||
private final ByteBuffer handle;
|
||||
|
|
@ -101,7 +103,7 @@ final class Context {
|
|||
}
|
||||
|
||||
static Context getCurrentContext() {
|
||||
return (Context)current_context_local.get();
|
||||
return current_context_local.get();
|
||||
}
|
||||
|
||||
/** Create a context with the specified peer info and shared context */
|
||||
|
|
@ -248,14 +250,14 @@ final class Context {
|
|||
return;
|
||||
destroy_requested = true;
|
||||
boolean was_current = isCurrent();
|
||||
int error = GL11.GL_NO_ERROR;
|
||||
int error = GL_NO_ERROR;
|
||||
if ( was_current ) {
|
||||
if ( GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGL11 )
|
||||
error = GL11.glGetError();
|
||||
error = glGetError();
|
||||
releaseCurrentContext();
|
||||
}
|
||||
checkDestroy();
|
||||
if ( was_current && error != GL11.GL_NO_ERROR )
|
||||
if ( was_current && error != GL_NO_ERROR )
|
||||
throw new OpenGLException(error);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -304,7 +304,7 @@ public final class ContextAttribs {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(32);
|
||||
StringBuilder sb = new StringBuilder(32);
|
||||
|
||||
sb.append("ContextAttribs:");
|
||||
sb.append(" Version=").append(majorVersion).append('.').append(minorVersion);
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ import java.security.PrivilegedAction;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public final class Display {
|
||||
|
||||
private static final Thread shutdown_hook = new Thread() {
|
||||
|
|
@ -114,9 +116,9 @@ public final class Display {
|
|||
private static boolean parent_resized;
|
||||
|
||||
/** Initial Background Color of Display */
|
||||
private static float r = 0, g = 0, b = 0;
|
||||
private static float r, g, b;
|
||||
|
||||
private static ComponentListener component_listener = new ComponentAdapter() {
|
||||
private static final ComponentListener component_listener = new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
synchronized ( GlobalLock.lock ) {
|
||||
parent_resized = true;
|
||||
|
|
@ -201,7 +203,7 @@ public final class Display {
|
|||
}
|
||||
|
||||
// We'll use a HashSet to filter out the duplicated modes
|
||||
HashSet modes = new HashSet(unfilteredModes.length);
|
||||
HashSet<DisplayMode> modes = new HashSet<DisplayMode>(unfilteredModes.length);
|
||||
|
||||
modes.addAll(Arrays.asList(unfilteredModes));
|
||||
DisplayMode[] filteredModes = new DisplayMode[modes.size()];
|
||||
|
|
@ -638,7 +640,7 @@ public final class Display {
|
|||
* Swap the display buffers. This method is called from update(), and should normally not be called by
|
||||
* the application.
|
||||
*
|
||||
* @throws OpenGLException if an OpenGL error has occured since the last call to GL11.glGetError()
|
||||
* @throws OpenGLException if an OpenGL error has occured since the last call to glGetError()
|
||||
*/
|
||||
public static void swapBuffers() throws LWJGLException {
|
||||
synchronized ( GlobalLock.lock ) {
|
||||
|
|
@ -731,7 +733,7 @@ public final class Display {
|
|||
}
|
||||
|
||||
private static void removeShutdownHook() {
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
Runtime.getRuntime().removeShutdownHook(shutdown_hook);
|
||||
return null;
|
||||
|
|
@ -740,7 +742,7 @@ public final class Display {
|
|||
}
|
||||
|
||||
private static void registerShutdownHook() {
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
Runtime.getRuntime().addShutdownHook(shutdown_hook);
|
||||
return null;
|
||||
|
|
@ -903,9 +905,9 @@ public final class Display {
|
|||
|
||||
private static void initContext() {
|
||||
// set background clear color
|
||||
GL11.glClearColor(r, g, b, 1.0f);
|
||||
glClearColor(r, g, b, 1.0f);
|
||||
// Clear window to avoid the desktop "showing through"
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -915,12 +917,11 @@ public final class Display {
|
|||
|
||||
/** Gets a boolean property as a privileged action. */
|
||||
static boolean getPrivilegedBoolean(final String property_name) {
|
||||
Boolean value = (Boolean)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return new Boolean(Boolean.getBoolean(property_name));
|
||||
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
|
||||
public Boolean run() {
|
||||
return Boolean.getBoolean(property_name);
|
||||
}
|
||||
});
|
||||
return value.booleanValue();
|
||||
}
|
||||
|
||||
private static void initControls() {
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ public final class DisplayMode {
|
|||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(32);
|
||||
StringBuilder sb = new StringBuilder(32);
|
||||
sb.append(width);
|
||||
sb.append(" x ");
|
||||
sb.append(height);
|
||||
|
|
|
|||
|
|
@ -32,11 +32,18 @@
|
|||
package org.lwjgl.opengl;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
||||
import static org.lwjgl.opengl.ARBBufferObject.*;
|
||||
import static org.lwjgl.opengl.ATIVertexArrayObject.*;
|
||||
import static org.lwjgl.opengl.EXTAbgr.*;
|
||||
import static org.lwjgl.opengl.EXTBgra.*;
|
||||
import static org.lwjgl.opengl.EXTDirectStateAccess.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL15.*;
|
||||
|
||||
/**
|
||||
* A class to check buffer boundaries in GL methods. Many GL
|
||||
* methods read data from the GL into a native Buffer at its current position. If there is unsufficient space in the buffer when
|
||||
|
|
@ -61,19 +68,19 @@ class GLChecks {
|
|||
}
|
||||
|
||||
static int getBufferObjectSize(ContextCapabilities caps, int buffer_enum) {
|
||||
return GL15.glGetBufferParameter(buffer_enum, GL15.GL_BUFFER_SIZE);
|
||||
return glGetBufferParameter(buffer_enum, GL_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
static int getBufferObjectSizeARB(ContextCapabilities caps, int buffer_enum) {
|
||||
return ARBBufferObject.glGetBufferParameterARB(buffer_enum, ARBBufferObject.GL_BUFFER_SIZE_ARB);
|
||||
return glGetBufferParameterARB(buffer_enum, GL_BUFFER_SIZE_ARB);
|
||||
}
|
||||
|
||||
static int getBufferObjectSizeATI(ContextCapabilities caps, int buffer) {
|
||||
return ATIVertexArrayObject.glGetObjectBufferATI(buffer, ATIVertexArrayObject.GL_OBJECT_BUFFER_SIZE_ATI);
|
||||
return glGetObjectBufferATI(buffer, GL_OBJECT_BUFFER_SIZE_ATI);
|
||||
}
|
||||
|
||||
static int getNamedBufferObjectSize(ContextCapabilities caps, int buffer) {
|
||||
return EXTDirectStateAccess.glGetNamedBufferParameterEXT(buffer, GL15.GL_BUFFER_SIZE);
|
||||
return glGetNamedBufferParameterEXT(buffer, GL_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
/** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
|
||||
|
|
@ -193,17 +200,17 @@ class GLChecks {
|
|||
private static int calculateBytesPerPixel(int format, int type) {
|
||||
int bpe;
|
||||
switch ( type ) {
|
||||
case GL11.GL_UNSIGNED_BYTE:
|
||||
case GL11.GL_BYTE:
|
||||
case GL_UNSIGNED_BYTE:
|
||||
case GL_BYTE:
|
||||
bpe = 1;
|
||||
break;
|
||||
case GL11.GL_UNSIGNED_SHORT:
|
||||
case GL11.GL_SHORT:
|
||||
case GL_UNSIGNED_SHORT:
|
||||
case GL_SHORT:
|
||||
bpe = 2;
|
||||
break;
|
||||
case GL11.GL_UNSIGNED_INT:
|
||||
case GL11.GL_INT:
|
||||
case GL11.GL_FLOAT:
|
||||
case GL_UNSIGNED_INT:
|
||||
case GL_INT:
|
||||
case GL_FLOAT:
|
||||
bpe = 4;
|
||||
break;
|
||||
default :
|
||||
|
|
@ -213,21 +220,21 @@ class GLChecks {
|
|||
}
|
||||
int epp;
|
||||
switch ( format ) {
|
||||
case GL11.GL_LUMINANCE:
|
||||
case GL11.GL_ALPHA:
|
||||
case GL_LUMINANCE:
|
||||
case GL_ALPHA:
|
||||
epp = 1;
|
||||
break;
|
||||
|
||||
case GL11.GL_LUMINANCE_ALPHA:
|
||||
case GL_LUMINANCE_ALPHA:
|
||||
epp = 2;
|
||||
break;
|
||||
case GL11.GL_RGB:
|
||||
case EXTBgra.GL_BGR_EXT:
|
||||
case GL_RGB:
|
||||
case GL_BGR_EXT:
|
||||
epp = 3;
|
||||
break;
|
||||
case GL11.GL_RGBA:
|
||||
case EXTAbgr.GL_ABGR_EXT:
|
||||
case EXTBgra.GL_BGRA_EXT:
|
||||
case GL_RGBA:
|
||||
case GL_ABGR_EXT:
|
||||
case GL_BGRA_EXT:
|
||||
epp = 4;
|
||||
break;
|
||||
default :
|
||||
|
|
|
|||
|
|
@ -31,18 +31,20 @@
|
|||
*/
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.IntBuffer;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.*;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
import static org.lwjgl.opengl.GL32.*;
|
||||
|
||||
/**
|
||||
* <p/>
|
||||
* Manages GL contexts. Before any rendering is done by a LWJGL system, a call should be made to GLContext.useContext() with a
|
||||
|
|
@ -60,7 +62,7 @@ import java.util.*;
|
|||
public final class GLContext {
|
||||
|
||||
/** Maps threads to their current context's ContextCapabilities, if any */
|
||||
private final static ThreadLocal current_capabilities = new ThreadLocal();
|
||||
private static final ThreadLocal<ContextCapabilities> current_capabilities = new ThreadLocal<ContextCapabilities>();
|
||||
|
||||
/**
|
||||
* The getCapabilities() method is a potential hot spot in any LWJGL application, since
|
||||
|
|
@ -92,13 +94,13 @@ public final class GLContext {
|
|||
* Simple lock-free cache of CapabilitesEntryCache to avoid allocating more than one
|
||||
* cache entry per thread
|
||||
*/
|
||||
private final static ThreadLocal thread_cache_entries = new ThreadLocal();
|
||||
private static final ThreadLocal<CapabilitiesCacheEntry> thread_cache_entries = new ThreadLocal<CapabilitiesCacheEntry>();
|
||||
|
||||
/**
|
||||
* The weak mapping from context Object instances to ContextCapabilities. Used
|
||||
* to avoid recreating a ContextCapabilities every time a context is made current.
|
||||
*/
|
||||
private final static Map capability_cache = new WeakHashMap();
|
||||
private static final Map<Object, ContextCapabilities> capability_cache = new WeakHashMap<Object, ContextCapabilities>();
|
||||
|
||||
/** Reference count of the native opengl implementation library */
|
||||
private static int gl_ref_count;
|
||||
|
|
@ -127,7 +129,7 @@ public final class GLContext {
|
|||
}
|
||||
|
||||
private static ContextCapabilities getThreadLocalCapabilities() {
|
||||
return ((ContextCapabilities)current_capabilities.get());
|
||||
return current_capabilities.get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -139,7 +141,7 @@ public final class GLContext {
|
|||
static void setCapabilities(ContextCapabilities capabilities) {
|
||||
current_capabilities.set(capabilities);
|
||||
|
||||
CapabilitiesCacheEntry thread_cache_entry = (CapabilitiesCacheEntry)thread_cache_entries.get();
|
||||
CapabilitiesCacheEntry thread_cache_entry = thread_cache_entries.get();
|
||||
if ( thread_cache_entry == null ) {
|
||||
thread_cache_entry = new CapabilitiesCacheEntry();
|
||||
thread_cache_entries.set(thread_cache_entry);
|
||||
|
|
@ -155,8 +157,8 @@ public final class GLContext {
|
|||
* with a name dependent on the current platform
|
||||
*/
|
||||
static long getPlatformSpecificFunctionAddress(String function_prefix, String[] os_prefixes, String[] os_function_prefixes, String function) {
|
||||
String os_name = (String)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
String os_name = AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
});
|
||||
|
|
@ -177,8 +179,8 @@ public final class GLContext {
|
|||
* @return the function pointer address
|
||||
*/
|
||||
static long getFunctionAddress(String[] aliases) {
|
||||
for ( int i = 0; i < aliases.length; i++ ) {
|
||||
long address = getFunctionAddress(aliases[i]);
|
||||
for ( String alias : aliases ) {
|
||||
long address = getFunctionAddress(alias);
|
||||
if ( address != 0 )
|
||||
return address;
|
||||
}
|
||||
|
|
@ -195,10 +197,10 @@ public final class GLContext {
|
|||
*
|
||||
* @return the context profile mask, will be 0 for any version < 3.2
|
||||
*/
|
||||
static int getSupportedExtensions(final Set supported_extensions) {
|
||||
static int getSupportedExtensions(final Set<String> supported_extensions) {
|
||||
// Detect OpenGL version first
|
||||
|
||||
final String version = GL11.glGetString(GL11.GL_VERSION);
|
||||
final String version = glGetString(GL_VERSION);
|
||||
if ( version == null )
|
||||
throw new IllegalStateException("glGetString(GL_VERSION) returned null - possibly caused by missing current context.");
|
||||
|
||||
|
|
@ -224,8 +226,7 @@ public final class GLContext {
|
|||
|
||||
for ( int major = 1; major <= GL_VERSIONS.length; major++ ) {
|
||||
int[] minors = GL_VERSIONS[major - 1];
|
||||
for ( int i = 0; i < minors.length; i++ ) {
|
||||
int minor = minors[i];
|
||||
for ( int minor : minors ) {
|
||||
if ( major < majorVersion || (major == majorVersion && minor <= minorVersion) )
|
||||
supported_extensions.add("OpenGL" + Integer.toString(major) + Integer.toString(minor));
|
||||
}
|
||||
|
|
@ -235,7 +236,7 @@ public final class GLContext {
|
|||
|
||||
if ( majorVersion < 3 ) {
|
||||
// Parse EXTENSIONS string
|
||||
final String extensions_string = GL11.glGetString(GL11.GL_EXTENSIONS);
|
||||
final String extensions_string = glGetString(GL_EXTENSIONS);
|
||||
if ( extensions_string == null )
|
||||
throw new IllegalStateException("glGetString(GL_EXTENSIONS) returned null - is there a context current?");
|
||||
|
||||
|
|
@ -244,24 +245,20 @@ public final class GLContext {
|
|||
supported_extensions.add(tokenizer.nextToken());
|
||||
} else {
|
||||
// Use forward compatible indexed EXTENSIONS
|
||||
final IntBuffer buffer = BufferUtils.createIntBuffer(16);
|
||||
GL11.glGetInteger(GL30.GL_NUM_EXTENSIONS, buffer);
|
||||
final int extensionCount = buffer.get(0);
|
||||
final int extensionCount = glGetInteger(GL_NUM_EXTENSIONS);
|
||||
|
||||
for ( int i = 0; i < extensionCount; i++ )
|
||||
supported_extensions.add(GL30.glGetStringi(GL11.GL_EXTENSIONS, i));
|
||||
supported_extensions.add(glGetStringi(GL_EXTENSIONS, i));
|
||||
|
||||
// Get the context profile mask for versions >= 3.2
|
||||
if ( 3 < majorVersion || 2 <= minorVersion ) {
|
||||
Util.checkGLError(); // Make sure we have no errors up to this point
|
||||
|
||||
GL11.glGetInteger(GL32.GL_CONTEXT_PROFILE_MASK, buffer);
|
||||
|
||||
try {
|
||||
profileMask = glGetInteger(GL_CONTEXT_PROFILE_MASK);
|
||||
// Retrieving GL_CONTEXT_PROFILE_MASK may generate an INVALID_OPERATION error on certain implementations, ignore.
|
||||
// Happens on pre10.1 ATI drivers, when ContextAttribs.withProfileCompatibility is not used
|
||||
Util.checkGLError();
|
||||
profileMask = buffer.get(0);
|
||||
} catch (OpenGLException e) {
|
||||
LWJGLUtil.log("Failed to retrieve CONTEXT_PROFILE_MASK");
|
||||
}
|
||||
|
|
@ -275,14 +272,14 @@ public final class GLContext {
|
|||
* Helper method to ContextCapabilities. It will try to initialize the native stubs,
|
||||
* and remove the given extension name from the extension set if the initialization fails.
|
||||
*/
|
||||
static void initNativeStubs(final Class extension_class, Set supported_extensions, String ext_name) {
|
||||
static void initNativeStubs(final Class<?> extension_class, Set supported_extensions, String ext_name) {
|
||||
resetNativeStubs(extension_class);
|
||||
if ( supported_extensions.contains(ext_name) ) {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws Exception {
|
||||
Method init_stubs_method = extension_class.getDeclaredMethod("initNativeStubs", null);
|
||||
init_stubs_method.invoke(null, null);
|
||||
Method init_stubs_method = extension_class.getDeclaredMethod("initNativeStubs");
|
||||
init_stubs_method.invoke(null);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
|
@ -341,7 +338,7 @@ public final class GLContext {
|
|||
did_auto_load = true;
|
||||
}
|
||||
try {
|
||||
ContextCapabilities capabilities = (ContextCapabilities)capability_cache.get(context);
|
||||
ContextCapabilities capabilities = capability_cache.get(context);
|
||||
if ( capabilities == null ) {
|
||||
/*
|
||||
* The capabilities object registers itself as current. This behaviour is caused
|
||||
|
|
@ -385,7 +382,7 @@ public final class GLContext {
|
|||
/** Native method to clear native stub bindings */
|
||||
static native void resetNativeStubs(Class clazz);
|
||||
|
||||
private final static class CapabilitiesCacheEntry {
|
||||
private static final class CapabilitiesCacheEntry {
|
||||
|
||||
Thread owner;
|
||||
ContextCapabilities capabilities;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
*/
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/**
|
||||
* <p/>
|
||||
* GLU constants.
|
||||
|
|
@ -52,7 +54,7 @@ public interface GLUConstants {
|
|||
int GLU_EXTENSIONS = 100801;
|
||||
|
||||
/* Boolean */
|
||||
int GLU_TRUE = GL11.GL_TRUE;
|
||||
int GLU_FALSE = GL11.GL_FALSE;
|
||||
int GLU_TRUE = GL_TRUE;
|
||||
int GLU_FALSE = GL_FALSE;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -36,5 +36,5 @@ package org.lwjgl.opengl;
|
|||
* synchronize access to Display.
|
||||
*/
|
||||
final class GlobalLock {
|
||||
final static Object lock = new Object();
|
||||
static final Object lock = new Object();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,13 +50,13 @@ import org.lwjgl.LWJGLUtil;
|
|||
final class LinuxCanvasImplementation implements AWTCanvasImplementation {
|
||||
static int getScreenFromDevice(final GraphicsDevice device) throws LWJGLException {
|
||||
try {
|
||||
Method getScreen_method = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
return device.getClass().getMethod("getScreen", null);
|
||||
Method getScreen_method = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||
public Method run() throws Exception {
|
||||
return device.getClass().getMethod("getScreen");
|
||||
}
|
||||
});
|
||||
Integer screen = (Integer)getScreen_method.invoke(device, null);
|
||||
return screen.intValue();
|
||||
Integer screen = (Integer)getScreen_method.invoke(device);
|
||||
return screen;
|
||||
} catch (Exception e) {
|
||||
throw new LWJGLException(e);
|
||||
}
|
||||
|
|
@ -64,13 +64,13 @@ final class LinuxCanvasImplementation implements AWTCanvasImplementation {
|
|||
|
||||
private static int getVisualIDFromConfiguration(final GraphicsConfiguration configuration) throws LWJGLException {
|
||||
try {
|
||||
Method getVisual_method = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
return configuration.getClass().getMethod("getVisual", null);
|
||||
Method getVisual_method = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||
public Method run() throws Exception {
|
||||
return configuration.getClass().getMethod("getVisual");
|
||||
}
|
||||
});
|
||||
Integer visual = (Integer)getVisual_method.invoke(configuration, null);
|
||||
return visual.intValue();
|
||||
Integer visual = (Integer)getVisual_method.invoke(configuration);
|
||||
return visual;
|
||||
} catch (Exception e) {
|
||||
throw new LWJGLException(e);
|
||||
}
|
||||
|
|
@ -90,10 +90,10 @@ final class LinuxCanvasImplementation implements AWTCanvasImplementation {
|
|||
int screen = getScreenFromDevice(device);
|
||||
int visual_id_matching_format = findVisualIDFromFormat(screen, pixel_format);
|
||||
GraphicsConfiguration[] configurations = device.getConfigurations();
|
||||
for (int i = 0; i < configurations.length; i++) {
|
||||
int visual_id = getVisualIDFromConfiguration(configurations[i]);
|
||||
if (visual_id == visual_id_matching_format)
|
||||
return configurations[i];
|
||||
for ( GraphicsConfiguration configuration : configurations ) {
|
||||
int visual_id = getVisualIDFromConfiguration(configuration);
|
||||
if ( visual_id == visual_id_matching_format )
|
||||
return configuration;
|
||||
}
|
||||
} catch (LWJGLException e) {
|
||||
LWJGLUtil.log("Got exception while trying to determine configuration: " + e);
|
||||
|
|
|
|||
|
|
@ -54,32 +54,31 @@ import org.lwjgl.opengl.XRandR.Screen;
|
|||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
final class LinuxDisplay implements DisplayImplementation {
|
||||
/* X11 constants */
|
||||
public final static int CurrentTime = 0;
|
||||
public final static int GrabSuccess = 0;
|
||||
public final static int AutoRepeatModeOff = 0;
|
||||
public final static int AutoRepeatModeOn = 1;
|
||||
public final static int AutoRepeatModeDefault = 2;
|
||||
public final static int None = 0;
|
||||
public static final int CurrentTime = 0;
|
||||
public static final int GrabSuccess = 0;
|
||||
public static final int AutoRepeatModeOff = 0;
|
||||
public static final int AutoRepeatModeOn = 1;
|
||||
public static final int AutoRepeatModeDefault = 2;
|
||||
public static final int None = 0;
|
||||
|
||||
private final static int KeyPressMask = 1 << 0;
|
||||
private final static int KeyReleaseMask = 1 << 1;
|
||||
private final static int ButtonPressMask = 1 << 2;
|
||||
private final static int ButtonReleaseMask = 1 << 3;
|
||||
private static final int KeyPressMask = 1 << 0;
|
||||
private static final int KeyReleaseMask = 1 << 1;
|
||||
private static final int ButtonPressMask = 1 << 2;
|
||||
private static final int ButtonReleaseMask = 1 << 3;
|
||||
|
||||
private final static int NotifyAncestor = 0;
|
||||
private final static int NotifyNonlinear = 3;
|
||||
private final static int NotifyPointer = 5;
|
||||
private final static int NotifyPointerRoot = 6;
|
||||
private final static int NotifyDetailNone = 7;
|
||||
private static final int NotifyAncestor = 0;
|
||||
private static final int NotifyNonlinear = 3;
|
||||
private static final int NotifyPointer = 5;
|
||||
private static final int NotifyPointerRoot = 6;
|
||||
private static final int NotifyDetailNone = 7;
|
||||
|
||||
private final static int SetModeInsert = 0;
|
||||
private final static int SaveSetRoot = 1;
|
||||
private final static int SaveSetUnmap = 1;
|
||||
private static final int SetModeInsert = 0;
|
||||
private static final int SaveSetRoot = 1;
|
||||
private static final int SaveSetUnmap = 1;
|
||||
|
||||
/** Window mode enum */
|
||||
private static final int FULLSCREEN_LEGACY = 1;
|
||||
|
|
@ -99,7 +98,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
private static long current_window;
|
||||
private static long saved_error_handler;
|
||||
|
||||
private static int display_connection_usage_count = 0;
|
||||
private static int display_connection_usage_count;
|
||||
|
||||
/** Event buffer */
|
||||
private final LinuxEvent event_buffer = new LinuxEvent();
|
||||
|
|
@ -120,7 +119,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
/** Saved mode to restore with */
|
||||
private DisplayMode saved_mode;
|
||||
private DisplayMode current_mode;
|
||||
|
||||
|
||||
private Screen[] savedXrandrConfig;
|
||||
|
||||
private boolean keyboard_grabbed;
|
||||
|
|
@ -369,7 +368,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
static native int nUngrabPointer(long display);
|
||||
|
||||
private boolean isFullscreen() {
|
||||
private static boolean isFullscreen() {
|
||||
return current_window_mode == FULLSCREEN_LEGACY || current_window_mode == FULLSCREEN_NETWM;
|
||||
}
|
||||
|
||||
|
|
@ -397,7 +396,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
private static native void nDefineCursor(long display, long window, long cursor_handle);
|
||||
|
||||
private boolean isLegacyFullscreen() {
|
||||
private static boolean isLegacyFullscreen() {
|
||||
return current_window_mode == FULLSCREEN_LEGACY;
|
||||
}
|
||||
|
||||
|
|
@ -544,7 +543,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
try {
|
||||
if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 )
|
||||
{
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
XRandR.setConfiguration( savedXrandrConfig );
|
||||
return null;
|
||||
|
|
@ -607,7 +606,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
}
|
||||
|
||||
private void setGammaRampOnTmpDisplay(ByteBuffer native_gamma) throws LWJGLException {
|
||||
private static void setGammaRampOnTmpDisplay(ByteBuffer native_gamma) throws LWJGLException {
|
||||
incDisplay();
|
||||
try {
|
||||
nSetGammaRamp(getDisplay(), getDefaultScreen(), native_gamma);
|
||||
|
|
@ -644,8 +643,8 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
throw new LWJGLException("No modes available");
|
||||
switch (current_displaymode_extension) {
|
||||
case XRANDR:
|
||||
savedXrandrConfig = (Screen[])AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
savedXrandrConfig = AccessController.doPrivileged(new PrivilegedAction<Screen[]>() {
|
||||
public Screen[] run() {
|
||||
return XRandR.getConfiguration();
|
||||
}
|
||||
});
|
||||
|
|
@ -872,10 +871,10 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
|
||||
private void checkInput() {
|
||||
if (parent == null) return;
|
||||
|
||||
|
||||
if (parent_focus != parent.hasFocus()) {
|
||||
parent_focus = parent.hasFocus();
|
||||
|
||||
|
||||
if (parent_focus) {
|
||||
setInputFocusUnsafe(current_window);
|
||||
}
|
||||
|
|
@ -892,7 +891,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
if (focused == got_focus || focus_detail == NotifyDetailNone || focus_detail == NotifyPointer || focus_detail == NotifyPointerRoot)
|
||||
return;
|
||||
focused = got_focus;
|
||||
|
||||
|
||||
if (focused) {
|
||||
acquireInput();
|
||||
}
|
||||
|
|
@ -902,7 +901,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
static native long nGetInputFocus(long display);
|
||||
|
||||
private void setInputFocusUnsafe(long window) {
|
||||
private static void setInputFocusUnsafe(long window) {
|
||||
try {
|
||||
setInputFocus(getDisplay(), window, CurrentTime);
|
||||
sync(getDisplay(), false);
|
||||
|
|
@ -923,7 +922,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
try {
|
||||
if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 )
|
||||
{
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
XRandR.setConfiguration( savedXrandrConfig );
|
||||
return null;
|
||||
|
|
@ -1088,7 +1087,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
incDisplay();
|
||||
try {
|
||||
long cursor = nCreateCursor(getDisplay(), width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1);
|
||||
return new Long(cursor);
|
||||
return cursor;
|
||||
} catch (LWJGLException e) {
|
||||
decDisplay();
|
||||
throw e;
|
||||
|
|
@ -1099,7 +1098,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
private static long getCursorHandle(Object cursor_handle) {
|
||||
return cursor_handle != null ? ((Long)cursor_handle).longValue() : None;
|
||||
return cursor_handle != null ? (Long)cursor_handle : None;
|
||||
}
|
||||
|
||||
public void destroyCursor(Object cursorHandle) {
|
||||
|
|
@ -1215,12 +1214,12 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
try {
|
||||
incDisplay();
|
||||
try {
|
||||
for (int i=0;i<icons.length;i++) {
|
||||
int size = icons[i].limit() / 4;
|
||||
for ( ByteBuffer icon : icons ) {
|
||||
int size = icon.limit() / 4;
|
||||
int dimension = (int)Math.sqrt(size);
|
||||
if (dimension > 0) {
|
||||
ByteBuffer icon_rgb = convertIcon(icons[i], dimension, dimension);
|
||||
ByteBuffer icon_mask = convertIconMask(icons[i], dimension, dimension);
|
||||
if ( dimension > 0 ) {
|
||||
ByteBuffer icon_rgb = convertIcon(icon, dimension, dimension);
|
||||
ByteBuffer icon_mask = convertIconMask(icon, dimension, dimension);
|
||||
nSetWindowIcon(getDisplay(), getWindow(), icon_rgb, icon_rgb.capacity(), icon_mask, icon_mask.capacity(), dimension, dimension);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1272,7 +1271,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
if ( Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.nocompiz_lfs") )
|
||||
return;
|
||||
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
try {
|
||||
// Check if Compiz is active
|
||||
|
|
@ -1291,9 +1290,9 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
private static final String KEY = "/org/freedesktop/compiz/workarounds/allscreens/legacy_fullscreen";
|
||||
|
||||
public boolean hasLegacyFullscreenSupport() throws LWJGLException {
|
||||
final List output = Compiz.run(new String[] {
|
||||
final List output = Compiz.run(
|
||||
"dbus-send", "--print-reply", "--type=method_call", "--dest=org.freedesktop.compiz", KEY, "org.freedesktop.compiz.get"
|
||||
});
|
||||
);
|
||||
|
||||
if ( output == null || output.size() < 2 )
|
||||
throw new LWJGLException("Invalid Dbus reply.");
|
||||
|
|
@ -1311,9 +1310,9 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public void setLegacyFullscreenSupport(final boolean state) throws LWJGLException {
|
||||
if ( Compiz.run(new String[] {
|
||||
if ( Compiz.run(
|
||||
"dbus-send", "--type=method_call", "--dest=org.freedesktop.compiz", KEY, "org.freedesktop.compiz.set", "boolean:" + Boolean.toString(state)
|
||||
}) == null )
|
||||
) == null )
|
||||
throw new LWJGLException("Failed to apply Compiz LFS workaround.");
|
||||
}
|
||||
};
|
||||
|
|
@ -1377,7 +1376,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
if ( !applyFix )
|
||||
return;
|
||||
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
try {
|
||||
provider.setLegacyFullscreenSupport(enabled);
|
||||
|
|
@ -1389,8 +1388,8 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
});
|
||||
}
|
||||
|
||||
private static List run(final String[] command) throws LWJGLException {
|
||||
final List output = new ArrayList();
|
||||
private static List<String> run(final String... command) throws LWJGLException {
|
||||
final List<String> output = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
final Process p = Runtime.getRuntime().exec(command);
|
||||
|
|
@ -1417,13 +1416,12 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
private static boolean isProcessActive(final String processName) throws LWJGLException {
|
||||
final List output = run(new String[] { "ps", "-C", processName });
|
||||
final List<String> output = run(new String[] { "ps", "-C", processName });
|
||||
if ( output == null )
|
||||
return false;
|
||||
|
||||
for ( Iterator iter = output.iterator(); iter.hasNext(); ) {
|
||||
final String line = (String)iter.next();
|
||||
if ( line.contains(processName) );
|
||||
for ( final String line : output ) {
|
||||
if ( line.contains(processName) )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,17 +41,17 @@ import java.nio.ByteBuffer;
|
|||
* $Id: LinuxPeerInfo.java 2286 2006-03-23 19:32:21Z matzon $
|
||||
*/
|
||||
final class LinuxEvent {
|
||||
public final static int FocusIn = 9;
|
||||
public final static int FocusOut = 10;
|
||||
public final static int KeyPress = 2;
|
||||
public final static int KeyRelease = 3;
|
||||
public final static int ButtonPress = 4;
|
||||
public final static int ButtonRelease = 5;
|
||||
public final static int MotionNotify = 6;
|
||||
public final static int UnmapNotify = 18;
|
||||
public final static int MapNotify = 19;
|
||||
public final static int Expose = 12;
|
||||
public final static int ClientMessage = 33;
|
||||
public static final int FocusIn = 9;
|
||||
public static final int FocusOut = 10;
|
||||
public static final int KeyPress = 2;
|
||||
public static final int KeyRelease = 3;
|
||||
public static final int ButtonPress = 4;
|
||||
public static final int ButtonRelease = 5;
|
||||
public static final int MotionNotify = 6;
|
||||
public static final int UnmapNotify = 18;
|
||||
public static final int MapNotify = 19;
|
||||
public static final int Expose = 12;
|
||||
public static final int ClientMessage = 33;
|
||||
|
||||
private final ByteBuffer event_buffer;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,111 +38,111 @@ package org.lwjgl.opengl;
|
|||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
final class LinuxKeycodes {
|
||||
public final static int XK_Kanji = 0xff21;
|
||||
public static final int XK_Kanji = 0xff21;
|
||||
|
||||
public final static int XK_ISO_Left_Tab = 0xfe20;
|
||||
|
||||
public final static int XK_dead_grave = 0xfe50;
|
||||
public final static int XK_dead_acute = 0xfe51;
|
||||
public final static int XK_dead_circumflex = 0xfe52;
|
||||
public final static int XK_dead_tilde = 0xfe53;
|
||||
public final static int XK_dead_macron = 0xfe54;
|
||||
public final static int XK_dead_breve = 0xfe55;
|
||||
public final static int XK_dead_abovedot = 0xfe56;
|
||||
public final static int XK_dead_diaeresis = 0xfe57;
|
||||
public final static int XK_dead_abovering = 0xfe58;
|
||||
public final static int XK_dead_doubleacute = 0xfe59;
|
||||
public final static int XK_dead_caron = 0xfe5a;
|
||||
public final static int XK_dead_cedilla = 0xfe5b;
|
||||
public final static int XK_dead_ogonek = 0xfe5c;
|
||||
public final static int XK_dead_iota = 0xfe5d;
|
||||
public final static int XK_dead_voiced_sound = 0xfe5e;
|
||||
public final static int XK_dead_semivoiced_sound = 0xfe5f;
|
||||
public final static int XK_dead_belowdot = 0xfe60;
|
||||
public final static int XK_dead_hook = 0xfe61;
|
||||
public final static int XK_dead_horn = 0xfe62;
|
||||
public static final int XK_ISO_Left_Tab = 0xfe20;
|
||||
|
||||
public final static int XK_BackSpace = 0xff08;
|
||||
public final static int XK_Tab = 0xff09;
|
||||
public final static int XK_Linefeed = 0xff0a;
|
||||
public final static int XK_Clear = 0xff0b;
|
||||
public final static int XK_Return = 0xff0d;
|
||||
public final static int XK_Pause = 0xff13;
|
||||
public final static int XK_Scroll_Lock = 0xff14;
|
||||
public final static int XK_Sys_Req = 0xff15;
|
||||
public final static int XK_Escape = 0xff1b;
|
||||
public final static int XK_Delete = 0xffff;
|
||||
public static final int XK_dead_grave = 0xfe50;
|
||||
public static final int XK_dead_acute = 0xfe51;
|
||||
public static final int XK_dead_circumflex = 0xfe52;
|
||||
public static final int XK_dead_tilde = 0xfe53;
|
||||
public static final int XK_dead_macron = 0xfe54;
|
||||
public static final int XK_dead_breve = 0xfe55;
|
||||
public static final int XK_dead_abovedot = 0xfe56;
|
||||
public static final int XK_dead_diaeresis = 0xfe57;
|
||||
public static final int XK_dead_abovering = 0xfe58;
|
||||
public static final int XK_dead_doubleacute = 0xfe59;
|
||||
public static final int XK_dead_caron = 0xfe5a;
|
||||
public static final int XK_dead_cedilla = 0xfe5b;
|
||||
public static final int XK_dead_ogonek = 0xfe5c;
|
||||
public static final int XK_dead_iota = 0xfe5d;
|
||||
public static final int XK_dead_voiced_sound = 0xfe5e;
|
||||
public static final int XK_dead_semivoiced_sound = 0xfe5f;
|
||||
public static final int XK_dead_belowdot = 0xfe60;
|
||||
public static final int XK_dead_hook = 0xfe61;
|
||||
public static final int XK_dead_horn = 0xfe62;
|
||||
|
||||
public final static int XK_Home = 0xff50;
|
||||
public final static int XK_Left = 0xff51;
|
||||
public final static int XK_Up = 0xff52;
|
||||
public final static int XK_Right = 0xff53;
|
||||
public final static int XK_Down = 0xff54;
|
||||
public final static int XK_Prior = 0xff55;
|
||||
public final static int XK_Page_Up = 0xff55;
|
||||
public final static int XK_Next = 0xff56;
|
||||
public final static int XK_Page_Down = 0xff56;
|
||||
public final static int XK_End = 0xff57;
|
||||
public final static int XK_Begin = 0xff58;
|
||||
public static final int XK_BackSpace = 0xff08;
|
||||
public static final int XK_Tab = 0xff09;
|
||||
public static final int XK_Linefeed = 0xff0a;
|
||||
public static final int XK_Clear = 0xff0b;
|
||||
public static final int XK_Return = 0xff0d;
|
||||
public static final int XK_Pause = 0xff13;
|
||||
public static final int XK_Scroll_Lock = 0xff14;
|
||||
public static final int XK_Sys_Req = 0xff15;
|
||||
public static final int XK_Escape = 0xff1b;
|
||||
public static final int XK_Delete = 0xffff;
|
||||
|
||||
public static final int XK_Home = 0xff50;
|
||||
public static final int XK_Left = 0xff51;
|
||||
public static final int XK_Up = 0xff52;
|
||||
public static final int XK_Right = 0xff53;
|
||||
public static final int XK_Down = 0xff54;
|
||||
public static final int XK_Prior = 0xff55;
|
||||
public static final int XK_Page_Up = 0xff55;
|
||||
public static final int XK_Next = 0xff56;
|
||||
public static final int XK_Page_Down = 0xff56;
|
||||
public static final int XK_End = 0xff57;
|
||||
public static final int XK_Begin = 0xff58;
|
||||
|
||||
|
||||
/* Misc functions */
|
||||
|
||||
public final static int XK_Select = 0xff60;
|
||||
public final static int XK_Print = 0xff61;
|
||||
public final static int XK_Execute = 0xff62;
|
||||
public final static int XK_Insert = 0xff63;
|
||||
public final static int XK_Undo = 0xff65;
|
||||
public final static int XK_Redo = 0xff66;
|
||||
public final static int XK_Menu = 0xff67;
|
||||
public final static int XK_Find = 0xff68;
|
||||
public final static int XK_Cancel = 0xff69;
|
||||
public final static int XK_Help = 0xff6a;
|
||||
public final static int XK_Break = 0xff6b;
|
||||
public final static int XK_Mode_switch = 0xff7e;
|
||||
public final static int XK_script_switch = 0xff7e;
|
||||
public final static int XK_Num_Lock = 0xff7f;
|
||||
public static final int XK_Select = 0xff60;
|
||||
public static final int XK_Print = 0xff61;
|
||||
public static final int XK_Execute = 0xff62;
|
||||
public static final int XK_Insert = 0xff63;
|
||||
public static final int XK_Undo = 0xff65;
|
||||
public static final int XK_Redo = 0xff66;
|
||||
public static final int XK_Menu = 0xff67;
|
||||
public static final int XK_Find = 0xff68;
|
||||
public static final int XK_Cancel = 0xff69;
|
||||
public static final int XK_Help = 0xff6a;
|
||||
public static final int XK_Break = 0xff6b;
|
||||
public static final int XK_Mode_switch = 0xff7e;
|
||||
public static final int XK_script_switch = 0xff7e;
|
||||
public static final int XK_Num_Lock = 0xff7f;
|
||||
|
||||
/* Keypad functions, keypad numbers cleverly chosen to map to ASCII */
|
||||
|
||||
public final static int XK_KP_Space = 0xff80;
|
||||
public final static int XK_KP_Tab = 0xff89;
|
||||
public final static int XK_KP_Enter = 0xff8d;
|
||||
public final static int XK_KP_F1 = 0xff91;
|
||||
public final static int XK_KP_F2 = 0xff92;
|
||||
public final static int XK_KP_F3 = 0xff93;
|
||||
public final static int XK_KP_F4 = 0xff94;
|
||||
public final static int XK_KP_Home = 0xff95;
|
||||
public final static int XK_KP_Left = 0xff96;
|
||||
public final static int XK_KP_Up = 0xff97;
|
||||
public final static int XK_KP_Right = 0xff98;
|
||||
public final static int XK_KP_Down = 0xff99;
|
||||
public final static int XK_KP_Prior = 0xff9a;
|
||||
public final static int XK_KP_Page_Up = 0xff9a;
|
||||
public final static int XK_KP_Next = 0xff9b;
|
||||
public final static int XK_KP_Page_Down = 0xff9b;
|
||||
public final static int XK_KP_End = 0xff9c;
|
||||
public final static int XK_KP_Begin = 0xff9d;
|
||||
public final static int XK_KP_Insert = 0xff9e;
|
||||
public final static int XK_KP_Delete = 0xff9f;
|
||||
public final static int XK_KP_Equal = 0xffbd;
|
||||
public final static int XK_KP_Multiply = 0xffaa;
|
||||
public final static int XK_KP_Add = 0xffab;
|
||||
public final static int XK_KP_Separator = 0xffac;
|
||||
public final static int XK_KP_Subtract = 0xffad;
|
||||
public final static int XK_KP_Decimal = 0xffae;
|
||||
public final static int XK_KP_Divide = 0xffaf;
|
||||
public static final int XK_KP_Space = 0xff80;
|
||||
public static final int XK_KP_Tab = 0xff89;
|
||||
public static final int XK_KP_Enter = 0xff8d;
|
||||
public static final int XK_KP_F1 = 0xff91;
|
||||
public static final int XK_KP_F2 = 0xff92;
|
||||
public static final int XK_KP_F3 = 0xff93;
|
||||
public static final int XK_KP_F4 = 0xff94;
|
||||
public static final int XK_KP_Home = 0xff95;
|
||||
public static final int XK_KP_Left = 0xff96;
|
||||
public static final int XK_KP_Up = 0xff97;
|
||||
public static final int XK_KP_Right = 0xff98;
|
||||
public static final int XK_KP_Down = 0xff99;
|
||||
public static final int XK_KP_Prior = 0xff9a;
|
||||
public static final int XK_KP_Page_Up = 0xff9a;
|
||||
public static final int XK_KP_Next = 0xff9b;
|
||||
public static final int XK_KP_Page_Down = 0xff9b;
|
||||
public static final int XK_KP_End = 0xff9c;
|
||||
public static final int XK_KP_Begin = 0xff9d;
|
||||
public static final int XK_KP_Insert = 0xff9e;
|
||||
public static final int XK_KP_Delete = 0xff9f;
|
||||
public static final int XK_KP_Equal = 0xffbd;
|
||||
public static final int XK_KP_Multiply = 0xffaa;
|
||||
public static final int XK_KP_Add = 0xffab;
|
||||
public static final int XK_KP_Separator = 0xffac;
|
||||
public static final int XK_KP_Subtract = 0xffad;
|
||||
public static final int XK_KP_Decimal = 0xffae;
|
||||
public static final int XK_KP_Divide = 0xffaf;
|
||||
|
||||
public final static int XK_KP_0 = 0xffb0;
|
||||
public final static int XK_KP_1 = 0xffb1;
|
||||
public final static int XK_KP_2 = 0xffb2;
|
||||
public final static int XK_KP_3 = 0xffb3;
|
||||
public final static int XK_KP_4 = 0xffb4;
|
||||
public final static int XK_KP_5 = 0xffb5;
|
||||
public final static int XK_KP_6 = 0xffb6;
|
||||
public final static int XK_KP_7 = 0xffb7;
|
||||
public final static int XK_KP_8 = 0xffb8;
|
||||
public final static int XK_KP_9 = 0xffb9;
|
||||
public static final int XK_KP_0 = 0xffb0;
|
||||
public static final int XK_KP_1 = 0xffb1;
|
||||
public static final int XK_KP_2 = 0xffb2;
|
||||
public static final int XK_KP_3 = 0xffb3;
|
||||
public static final int XK_KP_4 = 0xffb4;
|
||||
public static final int XK_KP_5 = 0xffb5;
|
||||
public static final int XK_KP_6 = 0xffb6;
|
||||
public static final int XK_KP_7 = 0xffb7;
|
||||
public static final int XK_KP_8 = 0xffb8;
|
||||
public static final int XK_KP_9 = 0xffb9;
|
||||
|
||||
|
||||
|
||||
|
|
@ -153,285 +153,285 @@ final class LinuxKeycodes {
|
|||
* We've not found a keyboard with more than 35 function keys total.
|
||||
*/
|
||||
|
||||
public final static int XK_F1 = 0xffbe;
|
||||
public final static int XK_F2 = 0xffbf;
|
||||
public final static int XK_F3 = 0xffc0;
|
||||
public final static int XK_F4 = 0xffc1;
|
||||
public final static int XK_F5 = 0xffc2;
|
||||
public final static int XK_F6 = 0xffc3;
|
||||
public final static int XK_F7 = 0xffc4;
|
||||
public final static int XK_F8 = 0xffc5;
|
||||
public final static int XK_F9 = 0xffc6;
|
||||
public final static int XK_F10 = 0xffc7;
|
||||
public final static int XK_F11 = 0xffc8;
|
||||
public final static int XK_L1 = 0xffc8;
|
||||
public final static int XK_F12 = 0xffc9;
|
||||
public final static int XK_L2 = 0xffc9;
|
||||
public final static int XK_F13 = 0xffca;
|
||||
public final static int XK_L3 = 0xffca;
|
||||
public final static int XK_F14 = 0xffcb;
|
||||
public final static int XK_L4 = 0xffcb;
|
||||
public final static int XK_F15 = 0xffcc;
|
||||
public final static int XK_L5 = 0xffcc;
|
||||
public final static int XK_F16 = 0xffcd;
|
||||
public final static int XK_L6 = 0xffcd;
|
||||
public final static int XK_F17 = 0xffce;
|
||||
public final static int XK_L7 = 0xffce;
|
||||
public final static int XK_F18 = 0xffcf;
|
||||
public final static int XK_L8 = 0xffcf;
|
||||
public final static int XK_F19 = 0xffd0;
|
||||
public final static int XK_L9 = 0xffd0;
|
||||
public final static int XK_F20 = 0xffd1;
|
||||
public final static int XK_L10 = 0xffd1;
|
||||
public final static int XK_F21 = 0xffd2;
|
||||
public final static int XK_R1 = 0xffd2;
|
||||
public final static int XK_F22 = 0xffd3;
|
||||
public final static int XK_R2 = 0xffd3;
|
||||
public final static int XK_F23 = 0xffd4;
|
||||
public final static int XK_R3 = 0xffd4;
|
||||
public final static int XK_F24 = 0xffd5;
|
||||
public final static int XK_R4 = 0xffd5;
|
||||
public final static int XK_F25 = 0xffd6;
|
||||
public final static int XK_R5 = 0xffd6;
|
||||
public final static int XK_F26 = 0xffd7;
|
||||
public final static int XK_R6 = 0xffd7;
|
||||
public final static int XK_F27 = 0xffd8;
|
||||
public final static int XK_R7 = 0xffd8;
|
||||
public final static int XK_F28 = 0xffd9;
|
||||
public final static int XK_R8 = 0xffd9;
|
||||
public final static int XK_F29 = 0xffda;
|
||||
public final static int XK_R9 = 0xffda;
|
||||
public final static int XK_F30 = 0xffdb;
|
||||
public final static int XK_R10 = 0xffdb;
|
||||
public final static int XK_F31 = 0xffdc;
|
||||
public final static int XK_R11 = 0xffdc;
|
||||
public final static int XK_F32 = 0xffdd;
|
||||
public final static int XK_R12 = 0xffdd;
|
||||
public final static int XK_F33 = 0xffde;
|
||||
public final static int XK_R13 = 0xffde;
|
||||
public final static int XK_F34 = 0xffdf;
|
||||
public final static int XK_R14 = 0xffdf;
|
||||
public final static int XK_F35 = 0xffe0;
|
||||
public final static int XK_R15 = 0xffe0;
|
||||
public static final int XK_F1 = 0xffbe;
|
||||
public static final int XK_F2 = 0xffbf;
|
||||
public static final int XK_F3 = 0xffc0;
|
||||
public static final int XK_F4 = 0xffc1;
|
||||
public static final int XK_F5 = 0xffc2;
|
||||
public static final int XK_F6 = 0xffc3;
|
||||
public static final int XK_F7 = 0xffc4;
|
||||
public static final int XK_F8 = 0xffc5;
|
||||
public static final int XK_F9 = 0xffc6;
|
||||
public static final int XK_F10 = 0xffc7;
|
||||
public static final int XK_F11 = 0xffc8;
|
||||
public static final int XK_L1 = 0xffc8;
|
||||
public static final int XK_F12 = 0xffc9;
|
||||
public static final int XK_L2 = 0xffc9;
|
||||
public static final int XK_F13 = 0xffca;
|
||||
public static final int XK_L3 = 0xffca;
|
||||
public static final int XK_F14 = 0xffcb;
|
||||
public static final int XK_L4 = 0xffcb;
|
||||
public static final int XK_F15 = 0xffcc;
|
||||
public static final int XK_L5 = 0xffcc;
|
||||
public static final int XK_F16 = 0xffcd;
|
||||
public static final int XK_L6 = 0xffcd;
|
||||
public static final int XK_F17 = 0xffce;
|
||||
public static final int XK_L7 = 0xffce;
|
||||
public static final int XK_F18 = 0xffcf;
|
||||
public static final int XK_L8 = 0xffcf;
|
||||
public static final int XK_F19 = 0xffd0;
|
||||
public static final int XK_L9 = 0xffd0;
|
||||
public static final int XK_F20 = 0xffd1;
|
||||
public static final int XK_L10 = 0xffd1;
|
||||
public static final int XK_F21 = 0xffd2;
|
||||
public static final int XK_R1 = 0xffd2;
|
||||
public static final int XK_F22 = 0xffd3;
|
||||
public static final int XK_R2 = 0xffd3;
|
||||
public static final int XK_F23 = 0xffd4;
|
||||
public static final int XK_R3 = 0xffd4;
|
||||
public static final int XK_F24 = 0xffd5;
|
||||
public static final int XK_R4 = 0xffd5;
|
||||
public static final int XK_F25 = 0xffd6;
|
||||
public static final int XK_R5 = 0xffd6;
|
||||
public static final int XK_F26 = 0xffd7;
|
||||
public static final int XK_R6 = 0xffd7;
|
||||
public static final int XK_F27 = 0xffd8;
|
||||
public static final int XK_R7 = 0xffd8;
|
||||
public static final int XK_F28 = 0xffd9;
|
||||
public static final int XK_R8 = 0xffd9;
|
||||
public static final int XK_F29 = 0xffda;
|
||||
public static final int XK_R9 = 0xffda;
|
||||
public static final int XK_F30 = 0xffdb;
|
||||
public static final int XK_R10 = 0xffdb;
|
||||
public static final int XK_F31 = 0xffdc;
|
||||
public static final int XK_R11 = 0xffdc;
|
||||
public static final int XK_F32 = 0xffdd;
|
||||
public static final int XK_R12 = 0xffdd;
|
||||
public static final int XK_F33 = 0xffde;
|
||||
public static final int XK_R13 = 0xffde;
|
||||
public static final int XK_F34 = 0xffdf;
|
||||
public static final int XK_R14 = 0xffdf;
|
||||
public static final int XK_F35 = 0xffe0;
|
||||
public static final int XK_R15 = 0xffe0;
|
||||
|
||||
/* Modifiers */
|
||||
|
||||
public final static int XK_Shift_L = 0xffe1;
|
||||
public final static int XK_Shift_R = 0xffe2;
|
||||
public final static int XK_Control_L = 0xffe3;
|
||||
public final static int XK_Control_R = 0xffe4;
|
||||
public final static int XK_Caps_Lock = 0xffe5;
|
||||
public final static int XK_Shift_Lock = 0xffe6;
|
||||
public static final int XK_Shift_L = 0xffe1;
|
||||
public static final int XK_Shift_R = 0xffe2;
|
||||
public static final int XK_Control_L = 0xffe3;
|
||||
public static final int XK_Control_R = 0xffe4;
|
||||
public static final int XK_Caps_Lock = 0xffe5;
|
||||
public static final int XK_Shift_Lock = 0xffe6;
|
||||
|
||||
public final static int XK_Meta_L = 0xffe7;
|
||||
public final static int XK_Meta_R = 0xffe8;
|
||||
public final static int XK_Alt_L = 0xffe9;
|
||||
public final static int XK_Alt_R = 0xffea;
|
||||
public final static int XK_Super_L = 0xffeb;
|
||||
public final static int XK_Super_R = 0xffec;
|
||||
public final static int XK_Hyper_L = 0xffed;
|
||||
public final static int XK_Hyper_R = 0xffee;
|
||||
public final static int XK_space = 0x0020;
|
||||
public final static int XK_exclam = 0x0021;
|
||||
public final static int XK_quotedbl = 0x0022;
|
||||
public final static int XK_numbersign = 0x0023;
|
||||
public final static int XK_dollar = 0x0024;
|
||||
public final static int XK_percent = 0x0025;
|
||||
public final static int XK_ampersand = 0x0026;
|
||||
public final static int XK_apostrophe = 0x0027;
|
||||
public final static int XK_quoteright = 0x0027;
|
||||
public final static int XK_parenleft = 0x0028;
|
||||
public final static int XK_parenright = 0x0029;
|
||||
public final static int XK_asterisk = 0x002a;
|
||||
public final static int XK_plus = 0x002b;
|
||||
public final static int XK_comma = 0x002c;
|
||||
public final static int XK_minus = 0x002d;
|
||||
public final static int XK_period = 0x002e;
|
||||
public final static int XK_slash = 0x002f;
|
||||
public static final int XK_Meta_L = 0xffe7;
|
||||
public static final int XK_Meta_R = 0xffe8;
|
||||
public static final int XK_Alt_L = 0xffe9;
|
||||
public static final int XK_Alt_R = 0xffea;
|
||||
public static final int XK_Super_L = 0xffeb;
|
||||
public static final int XK_Super_R = 0xffec;
|
||||
public static final int XK_Hyper_L = 0xffed;
|
||||
public static final int XK_Hyper_R = 0xffee;
|
||||
public static final int XK_space = 0x0020;
|
||||
public static final int XK_exclam = 0x0021;
|
||||
public static final int XK_quotedbl = 0x0022;
|
||||
public static final int XK_numbersign = 0x0023;
|
||||
public static final int XK_dollar = 0x0024;
|
||||
public static final int XK_percent = 0x0025;
|
||||
public static final int XK_ampersand = 0x0026;
|
||||
public static final int XK_apostrophe = 0x0027;
|
||||
public static final int XK_quoteright = 0x0027;
|
||||
public static final int XK_parenleft = 0x0028;
|
||||
public static final int XK_parenright = 0x0029;
|
||||
public static final int XK_asterisk = 0x002a;
|
||||
public static final int XK_plus = 0x002b;
|
||||
public static final int XK_comma = 0x002c;
|
||||
public static final int XK_minus = 0x002d;
|
||||
public static final int XK_period = 0x002e;
|
||||
public static final int XK_slash = 0x002f;
|
||||
|
||||
public final static int XK_0 = 0x0030;
|
||||
public final static int XK_1 = 0x0031;
|
||||
public final static int XK_2 = 0x0032;
|
||||
public final static int XK_3 = 0x0033;
|
||||
public final static int XK_4 = 0x0034;
|
||||
public final static int XK_5 = 0x0035;
|
||||
public final static int XK_6 = 0x0036;
|
||||
public final static int XK_7 = 0x0037;
|
||||
public final static int XK_8 = 0x0038;
|
||||
public final static int XK_9 = 0x0039;
|
||||
public final static int XK_colon = 0x003a;
|
||||
public final static int XK_semicolon = 0x003b;
|
||||
public final static int XK_less = 0x003c;
|
||||
public final static int XK_equal = 0x003d;
|
||||
public final static int XK_greater = 0x003e;
|
||||
public final static int XK_question = 0x003f;
|
||||
public final static int XK_at = 0x0040;
|
||||
public final static int XK_A = 0x0041;
|
||||
public final static int XK_B = 0x0042;
|
||||
public final static int XK_C = 0x0043;
|
||||
public final static int XK_D = 0x0044;
|
||||
public final static int XK_E = 0x0045;
|
||||
public final static int XK_F = 0x0046;
|
||||
public final static int XK_G = 0x0047;
|
||||
public final static int XK_H = 0x0048;
|
||||
public final static int XK_I = 0x0049;
|
||||
public final static int XK_J = 0x004a;
|
||||
public final static int XK_K = 0x004b;
|
||||
public final static int XK_L = 0x004c;
|
||||
public final static int XK_M = 0x004d;
|
||||
public final static int XK_N = 0x004e;
|
||||
public final static int XK_O = 0x004f;
|
||||
public final static int XK_P = 0x0050;
|
||||
public final static int XK_Q = 0x0051;
|
||||
public final static int XK_R = 0x0052;
|
||||
public final static int XK_S = 0x0053;
|
||||
public final static int XK_T = 0x0054;
|
||||
public final static int XK_U = 0x0055;
|
||||
public final static int XK_V = 0x0056;
|
||||
public final static int XK_W = 0x0057;
|
||||
public final static int XK_X = 0x0058;
|
||||
public final static int XK_Y = 0x0059;
|
||||
public final static int XK_Z = 0x005a;
|
||||
public final static int XK_bracketleft = 0x005b;
|
||||
public final static int XK_backslash = 0x005c;
|
||||
public final static int XK_bracketright = 0x005d;
|
||||
public final static int XK_asciicircum = 0x005e;
|
||||
public final static int XK_underscore = 0x005f;
|
||||
public final static int XK_grave = 0x0060;
|
||||
public final static int XK_quoteleft = 0x0060;
|
||||
public final static int XK_a = 0x0061;
|
||||
public final static int XK_b = 0x0062;
|
||||
public final static int XK_c = 0x0063;
|
||||
public final static int XK_d = 0x0064;
|
||||
public final static int XK_e = 0x0065;
|
||||
public final static int XK_f = 0x0066;
|
||||
public final static int XK_g = 0x0067;
|
||||
public final static int XK_h = 0x0068;
|
||||
public final static int XK_i = 0x0069;
|
||||
public final static int XK_j = 0x006a;
|
||||
public final static int XK_k = 0x006b;
|
||||
public final static int XK_l = 0x006c;
|
||||
public final static int XK_m = 0x006d;
|
||||
public final static int XK_n = 0x006e;
|
||||
public final static int XK_o = 0x006f;
|
||||
public final static int XK_p = 0x0070;
|
||||
public final static int XK_q = 0x0071;
|
||||
public final static int XK_r = 0x0072;
|
||||
public final static int XK_s = 0x0073;
|
||||
public final static int XK_t = 0x0074;
|
||||
public final static int XK_u = 0x0075;
|
||||
public final static int XK_v = 0x0076;
|
||||
public final static int XK_w = 0x0077;
|
||||
public final static int XK_x = 0x0078;
|
||||
public final static int XK_y = 0x0079;
|
||||
public final static int XK_z = 0x007a;
|
||||
public final static int XK_braceleft = 0x007b;
|
||||
public final static int XK_bar = 0x007c;
|
||||
public final static int XK_braceright = 0x007d;
|
||||
public final static int XK_asciitilde = 0x007e;
|
||||
public static final int XK_0 = 0x0030;
|
||||
public static final int XK_1 = 0x0031;
|
||||
public static final int XK_2 = 0x0032;
|
||||
public static final int XK_3 = 0x0033;
|
||||
public static final int XK_4 = 0x0034;
|
||||
public static final int XK_5 = 0x0035;
|
||||
public static final int XK_6 = 0x0036;
|
||||
public static final int XK_7 = 0x0037;
|
||||
public static final int XK_8 = 0x0038;
|
||||
public static final int XK_9 = 0x0039;
|
||||
public static final int XK_colon = 0x003a;
|
||||
public static final int XK_semicolon = 0x003b;
|
||||
public static final int XK_less = 0x003c;
|
||||
public static final int XK_equal = 0x003d;
|
||||
public static final int XK_greater = 0x003e;
|
||||
public static final int XK_question = 0x003f;
|
||||
public static final int XK_at = 0x0040;
|
||||
public static final int XK_A = 0x0041;
|
||||
public static final int XK_B = 0x0042;
|
||||
public static final int XK_C = 0x0043;
|
||||
public static final int XK_D = 0x0044;
|
||||
public static final int XK_E = 0x0045;
|
||||
public static final int XK_F = 0x0046;
|
||||
public static final int XK_G = 0x0047;
|
||||
public static final int XK_H = 0x0048;
|
||||
public static final int XK_I = 0x0049;
|
||||
public static final int XK_J = 0x004a;
|
||||
public static final int XK_K = 0x004b;
|
||||
public static final int XK_L = 0x004c;
|
||||
public static final int XK_M = 0x004d;
|
||||
public static final int XK_N = 0x004e;
|
||||
public static final int XK_O = 0x004f;
|
||||
public static final int XK_P = 0x0050;
|
||||
public static final int XK_Q = 0x0051;
|
||||
public static final int XK_R = 0x0052;
|
||||
public static final int XK_S = 0x0053;
|
||||
public static final int XK_T = 0x0054;
|
||||
public static final int XK_U = 0x0055;
|
||||
public static final int XK_V = 0x0056;
|
||||
public static final int XK_W = 0x0057;
|
||||
public static final int XK_X = 0x0058;
|
||||
public static final int XK_Y = 0x0059;
|
||||
public static final int XK_Z = 0x005a;
|
||||
public static final int XK_bracketleft = 0x005b;
|
||||
public static final int XK_backslash = 0x005c;
|
||||
public static final int XK_bracketright = 0x005d;
|
||||
public static final int XK_asciicircum = 0x005e;
|
||||
public static final int XK_underscore = 0x005f;
|
||||
public static final int XK_grave = 0x0060;
|
||||
public static final int XK_quoteleft = 0x0060;
|
||||
public static final int XK_a = 0x0061;
|
||||
public static final int XK_b = 0x0062;
|
||||
public static final int XK_c = 0x0063;
|
||||
public static final int XK_d = 0x0064;
|
||||
public static final int XK_e = 0x0065;
|
||||
public static final int XK_f = 0x0066;
|
||||
public static final int XK_g = 0x0067;
|
||||
public static final int XK_h = 0x0068;
|
||||
public static final int XK_i = 0x0069;
|
||||
public static final int XK_j = 0x006a;
|
||||
public static final int XK_k = 0x006b;
|
||||
public static final int XK_l = 0x006c;
|
||||
public static final int XK_m = 0x006d;
|
||||
public static final int XK_n = 0x006e;
|
||||
public static final int XK_o = 0x006f;
|
||||
public static final int XK_p = 0x0070;
|
||||
public static final int XK_q = 0x0071;
|
||||
public static final int XK_r = 0x0072;
|
||||
public static final int XK_s = 0x0073;
|
||||
public static final int XK_t = 0x0074;
|
||||
public static final int XK_u = 0x0075;
|
||||
public static final int XK_v = 0x0076;
|
||||
public static final int XK_w = 0x0077;
|
||||
public static final int XK_x = 0x0078;
|
||||
public static final int XK_y = 0x0079;
|
||||
public static final int XK_z = 0x007a;
|
||||
public static final int XK_braceleft = 0x007b;
|
||||
public static final int XK_bar = 0x007c;
|
||||
public static final int XK_braceright = 0x007d;
|
||||
public static final int XK_asciitilde = 0x007e;
|
||||
|
||||
public final static int XK_nobreakspace = 0x00a0;
|
||||
public final static int XK_exclamdown = 0x00a1;
|
||||
public final static int XK_cent = 0x00a2;
|
||||
public final static int XK_sterling = 0x00a3;
|
||||
public final static int XK_currency = 0x00a4;
|
||||
public final static int XK_yen = 0x00a5;
|
||||
public final static int XK_brokenbar = 0x00a6;
|
||||
public final static int XK_section = 0x00a7;
|
||||
public final static int XK_diaeresis = 0x00a8;
|
||||
public final static int XK_copyright = 0x00a9;
|
||||
public final static int XK_ordfeminine = 0x00aa;
|
||||
public final static int XK_guillemotleft = 0x00ab;
|
||||
public final static int XK_notsign = 0x00ac;
|
||||
public final static int XK_hyphen = 0x00ad;
|
||||
public final static int XK_registered = 0x00ae;
|
||||
public final static int XK_macron = 0x00af;
|
||||
public final static int XK_degree = 0x00b0;
|
||||
public final static int XK_plusminus = 0x00b1;
|
||||
public final static int XK_twosuperior = 0x00b2;
|
||||
public final static int XK_threesuperior = 0x00b3;
|
||||
public final static int XK_acute = 0x00b4;
|
||||
public final static int XK_mu = 0x00b5;
|
||||
public final static int XK_paragraph = 0x00b6;
|
||||
public final static int XK_periodcentered = 0x00b7;
|
||||
public final static int XK_cedilla = 0x00b8;
|
||||
public final static int XK_onesuperior = 0x00b9;
|
||||
public final static int XK_masculine = 0x00ba;
|
||||
public final static int XK_guillemotright = 0x00bb;
|
||||
public final static int XK_onequarter = 0x00bc;
|
||||
public final static int XK_onehalf = 0x00bd;
|
||||
public final static int XK_threequarters = 0x00be;
|
||||
public final static int XK_questiondown = 0x00bf;
|
||||
public final static int XK_Agrave = 0x00c0;
|
||||
public final static int XK_Aacute = 0x00c1;
|
||||
public final static int XK_Acircumflex = 0x00c2;
|
||||
public final static int XK_Atilde = 0x00c3;
|
||||
public final static int XK_Adiaeresis = 0x00c4;
|
||||
public final static int XK_Aring = 0x00c5;
|
||||
public final static int XK_AE = 0x00c6;
|
||||
public final static int XK_Ccedilla = 0x00c7;
|
||||
public final static int XK_Egrave = 0x00c8;
|
||||
public final static int XK_Eacute = 0x00c9;
|
||||
public final static int XK_Ecircumflex = 0x00ca;
|
||||
public final static int XK_Ediaeresis = 0x00cb;
|
||||
public final static int XK_Igrave = 0x00cc;
|
||||
public final static int XK_Iacute = 0x00cd;
|
||||
public final static int XK_Icircumflex = 0x00ce;
|
||||
public final static int XK_Idiaeresis = 0x00cf;
|
||||
public final static int XK_ETH = 0x00d0;
|
||||
public final static int XK_Eth = 0x00d0;
|
||||
public final static int XK_Ntilde = 0x00d1;
|
||||
public final static int XK_Ograve = 0x00d2;
|
||||
public final static int XK_Oacute = 0x00d3;
|
||||
public final static int XK_Ocircumflex = 0x00d4;
|
||||
public final static int XK_Otilde = 0x00d5;
|
||||
public final static int XK_Odiaeresis = 0x00d6;
|
||||
public final static int XK_multiply = 0x00d7;
|
||||
public final static int XK_Oslash = 0x00d8;
|
||||
public final static int XK_Ooblique = 0x00d8;
|
||||
public final static int XK_Ugrave = 0x00d9;
|
||||
public final static int XK_Uacute = 0x00da;
|
||||
public final static int XK_Ucircumflex = 0x00db;
|
||||
public final static int XK_Udiaeresis = 0x00dc;
|
||||
public final static int XK_Yacute = 0x00dd;
|
||||
public final static int XK_THORN = 0x00de;
|
||||
public final static int XK_Thorn = 0x00de;
|
||||
public final static int XK_ssharp = 0x00df;
|
||||
public final static int XK_agrave = 0x00e0;
|
||||
public final static int XK_aacute = 0x00e1;
|
||||
public final static int XK_acircumflex = 0x00e2;
|
||||
public final static int XK_atilde = 0x00e3;
|
||||
public final static int XK_adiaeresis = 0x00e4;
|
||||
public final static int XK_aring = 0x00e5;
|
||||
public final static int XK_ae = 0x00e6;
|
||||
public final static int XK_ccedilla = 0x00e7;
|
||||
public final static int XK_egrave = 0x00e8;
|
||||
public final static int XK_eacute = 0x00e9;
|
||||
public final static int XK_ecircumflex = 0x00ea;
|
||||
public final static int XK_ediaeresis = 0x00eb;
|
||||
public final static int XK_igrave = 0x00ec;
|
||||
public final static int XK_iacute = 0x00ed;
|
||||
public final static int XK_icircumflex = 0x00ee;
|
||||
public final static int XK_idiaeresis = 0x00ef;
|
||||
public final static int XK_eth = 0x00f0;
|
||||
public final static int XK_ntilde = 0x00f1;
|
||||
public final static int XK_ograve = 0x00f2;
|
||||
public final static int XK_oacute = 0x00f3;
|
||||
public final static int XK_ocircumflex = 0x00f4;
|
||||
public final static int XK_otilde = 0x00f5;
|
||||
public final static int XK_odiaeresis = 0x00f6;
|
||||
public final static int XK_division = 0x00f7;
|
||||
public final static int XK_oslash = 0x00f8;
|
||||
public final static int XK_ooblique = 0x00f8;
|
||||
public final static int XK_ugrave = 0x00f9;
|
||||
public final static int XK_uacute = 0x00fa;
|
||||
public final static int XK_ucircumflex = 0x00fb;
|
||||
public final static int XK_udiaeresis = 0x00fc;
|
||||
public final static int XK_yacute = 0x00fd;
|
||||
public final static int XK_thorn = 0x00fe;
|
||||
public final static int XK_ydiaeresis = 0x00ff;
|
||||
public static final int XK_nobreakspace = 0x00a0;
|
||||
public static final int XK_exclamdown = 0x00a1;
|
||||
public static final int XK_cent = 0x00a2;
|
||||
public static final int XK_sterling = 0x00a3;
|
||||
public static final int XK_currency = 0x00a4;
|
||||
public static final int XK_yen = 0x00a5;
|
||||
public static final int XK_brokenbar = 0x00a6;
|
||||
public static final int XK_section = 0x00a7;
|
||||
public static final int XK_diaeresis = 0x00a8;
|
||||
public static final int XK_copyright = 0x00a9;
|
||||
public static final int XK_ordfeminine = 0x00aa;
|
||||
public static final int XK_guillemotleft = 0x00ab;
|
||||
public static final int XK_notsign = 0x00ac;
|
||||
public static final int XK_hyphen = 0x00ad;
|
||||
public static final int XK_registered = 0x00ae;
|
||||
public static final int XK_macron = 0x00af;
|
||||
public static final int XK_degree = 0x00b0;
|
||||
public static final int XK_plusminus = 0x00b1;
|
||||
public static final int XK_twosuperior = 0x00b2;
|
||||
public static final int XK_threesuperior = 0x00b3;
|
||||
public static final int XK_acute = 0x00b4;
|
||||
public static final int XK_mu = 0x00b5;
|
||||
public static final int XK_paragraph = 0x00b6;
|
||||
public static final int XK_periodcentered = 0x00b7;
|
||||
public static final int XK_cedilla = 0x00b8;
|
||||
public static final int XK_onesuperior = 0x00b9;
|
||||
public static final int XK_masculine = 0x00ba;
|
||||
public static final int XK_guillemotright = 0x00bb;
|
||||
public static final int XK_onequarter = 0x00bc;
|
||||
public static final int XK_onehalf = 0x00bd;
|
||||
public static final int XK_threequarters = 0x00be;
|
||||
public static final int XK_questiondown = 0x00bf;
|
||||
public static final int XK_Agrave = 0x00c0;
|
||||
public static final int XK_Aacute = 0x00c1;
|
||||
public static final int XK_Acircumflex = 0x00c2;
|
||||
public static final int XK_Atilde = 0x00c3;
|
||||
public static final int XK_Adiaeresis = 0x00c4;
|
||||
public static final int XK_Aring = 0x00c5;
|
||||
public static final int XK_AE = 0x00c6;
|
||||
public static final int XK_Ccedilla = 0x00c7;
|
||||
public static final int XK_Egrave = 0x00c8;
|
||||
public static final int XK_Eacute = 0x00c9;
|
||||
public static final int XK_Ecircumflex = 0x00ca;
|
||||
public static final int XK_Ediaeresis = 0x00cb;
|
||||
public static final int XK_Igrave = 0x00cc;
|
||||
public static final int XK_Iacute = 0x00cd;
|
||||
public static final int XK_Icircumflex = 0x00ce;
|
||||
public static final int XK_Idiaeresis = 0x00cf;
|
||||
public static final int XK_ETH = 0x00d0;
|
||||
public static final int XK_Eth = 0x00d0;
|
||||
public static final int XK_Ntilde = 0x00d1;
|
||||
public static final int XK_Ograve = 0x00d2;
|
||||
public static final int XK_Oacute = 0x00d3;
|
||||
public static final int XK_Ocircumflex = 0x00d4;
|
||||
public static final int XK_Otilde = 0x00d5;
|
||||
public static final int XK_Odiaeresis = 0x00d6;
|
||||
public static final int XK_multiply = 0x00d7;
|
||||
public static final int XK_Oslash = 0x00d8;
|
||||
public static final int XK_Ooblique = 0x00d8;
|
||||
public static final int XK_Ugrave = 0x00d9;
|
||||
public static final int XK_Uacute = 0x00da;
|
||||
public static final int XK_Ucircumflex = 0x00db;
|
||||
public static final int XK_Udiaeresis = 0x00dc;
|
||||
public static final int XK_Yacute = 0x00dd;
|
||||
public static final int XK_THORN = 0x00de;
|
||||
public static final int XK_Thorn = 0x00de;
|
||||
public static final int XK_ssharp = 0x00df;
|
||||
public static final int XK_agrave = 0x00e0;
|
||||
public static final int XK_aacute = 0x00e1;
|
||||
public static final int XK_acircumflex = 0x00e2;
|
||||
public static final int XK_atilde = 0x00e3;
|
||||
public static final int XK_adiaeresis = 0x00e4;
|
||||
public static final int XK_aring = 0x00e5;
|
||||
public static final int XK_ae = 0x00e6;
|
||||
public static final int XK_ccedilla = 0x00e7;
|
||||
public static final int XK_egrave = 0x00e8;
|
||||
public static final int XK_eacute = 0x00e9;
|
||||
public static final int XK_ecircumflex = 0x00ea;
|
||||
public static final int XK_ediaeresis = 0x00eb;
|
||||
public static final int XK_igrave = 0x00ec;
|
||||
public static final int XK_iacute = 0x00ed;
|
||||
public static final int XK_icircumflex = 0x00ee;
|
||||
public static final int XK_idiaeresis = 0x00ef;
|
||||
public static final int XK_eth = 0x00f0;
|
||||
public static final int XK_ntilde = 0x00f1;
|
||||
public static final int XK_ograve = 0x00f2;
|
||||
public static final int XK_oacute = 0x00f3;
|
||||
public static final int XK_ocircumflex = 0x00f4;
|
||||
public static final int XK_otilde = 0x00f5;
|
||||
public static final int XK_odiaeresis = 0x00f6;
|
||||
public static final int XK_division = 0x00f7;
|
||||
public static final int XK_oslash = 0x00f8;
|
||||
public static final int XK_ooblique = 0x00f8;
|
||||
public static final int XK_ugrave = 0x00f9;
|
||||
public static final int XK_uacute = 0x00fa;
|
||||
public static final int XK_ucircumflex = 0x00fb;
|
||||
public static final int XK_udiaeresis = 0x00fc;
|
||||
public static final int XK_yacute = 0x00fd;
|
||||
public static final int XK_thorn = 0x00fe;
|
||||
public static final int XK_ydiaeresis = 0x00ff;
|
||||
|
||||
public final static int XK_ISO_Level3_Shift = 0xfe03;
|
||||
public static final int XK_ISO_Level3_Shift = 0xfe03;
|
||||
|
||||
public static int mapKeySymToLWJGLKeyCode(long keysym) {
|
||||
switch ((int)keysym) {
|
||||
|
|
|
|||
|
|
@ -49,14 +49,14 @@ final class LinuxMouse {
|
|||
private static final int WHEEL_SCALE = 120;
|
||||
|
||||
/* X11 constants */
|
||||
private final static int Button1 = 1;
|
||||
private final static int Button2 = 2;
|
||||
private final static int Button3 = 3;
|
||||
private final static int Button4 = 4;
|
||||
private final static int Button5 = 5;
|
||||
private static final int Button1 = 1;
|
||||
private static final int Button2 = 2;
|
||||
private static final int Button3 = 3;
|
||||
private static final int Button4 = 4;
|
||||
private static final int Button5 = 5;
|
||||
|
||||
private final static int ButtonPress = 4;
|
||||
private final static int ButtonRelease = 5;
|
||||
private static final int ButtonPress = 4;
|
||||
private static final int ButtonRelease = 5;
|
||||
|
||||
private final long display;
|
||||
private final long window;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ import com.apple.eawt.Application;
|
|||
import com.apple.eawt.ApplicationAdapter;
|
||||
import com.apple.eawt.ApplicationEvent;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
final class MacOSXDisplay implements DisplayImplementation {
|
||||
private static final int PBUFFER_HANDLE_SIZE = 24;
|
||||
private static final int GAMMA_LENGTH = 256;
|
||||
|
|
@ -75,7 +77,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
|
||||
MacOSXDisplay() {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws Exception {
|
||||
Application.getApplication().addApplicationListener(new ApplicationAdapter() {
|
||||
public void handleQuit(ApplicationEvent event) {
|
||||
|
|
@ -126,7 +128,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
canvas_listener = null;
|
||||
}
|
||||
if (frame != null) {
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
if (MacOSXFrame.getDevice().getFullScreenWindow() == frame)
|
||||
MacOSXFrame.getDevice().setFullScreenWindow(null);
|
||||
|
|
@ -154,18 +156,19 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
return null;
|
||||
}
|
||||
|
||||
private boolean equals(java.awt.DisplayMode awt_mode, DisplayMode mode) {
|
||||
private static boolean equals(java.awt.DisplayMode awt_mode, DisplayMode mode) {
|
||||
return awt_mode.getWidth() == mode.getWidth() && awt_mode.getHeight() == mode.getHeight()
|
||||
&& awt_mode.getBitDepth() == mode.getBitsPerPixel() && awt_mode.getRefreshRate() == mode.getFrequency();
|
||||
}
|
||||
|
||||
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
|
||||
java.awt.DisplayMode[] awt_modes = MacOSXFrame.getDevice().getDisplayModes();
|
||||
for (int i = 0; i < awt_modes.length; i++)
|
||||
if (equals(awt_modes[i], mode)) {
|
||||
requested_mode = awt_modes[i];
|
||||
for ( java.awt.DisplayMode awt_mode : awt_modes ) {
|
||||
if (equals(awt_mode, mode)) {
|
||||
requested_mode = awt_mode;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new LWJGLException(mode + " is not supported");
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +181,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
|
||||
private native void restoreGamma();
|
||||
|
||||
private DisplayMode createLWJGLDisplayMode(java.awt.DisplayMode awt_mode) {
|
||||
private static DisplayMode createLWJGLDisplayMode(java.awt.DisplayMode awt_mode) {
|
||||
int bit_depth;
|
||||
int refresh_rate;
|
||||
int awt_bit_depth = awt_mode.getBitDepth();
|
||||
|
|
@ -200,17 +203,15 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
|
||||
public DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
|
||||
java.awt.DisplayMode[] awt_modes = MacOSXFrame.getDevice().getDisplayModes();
|
||||
List modes = new ArrayList();
|
||||
for (int i = 0; i < awt_modes.length; i++)
|
||||
if (awt_modes[i].getBitDepth() >= 16)
|
||||
modes.add(createLWJGLDisplayMode(awt_modes[i]));
|
||||
DisplayMode[] mode_list = new DisplayMode[modes.size()];
|
||||
modes.toArray(mode_list);
|
||||
return mode_list;
|
||||
List<DisplayMode> modes = new ArrayList<DisplayMode>();
|
||||
for ( java.awt.DisplayMode awt_mode : awt_modes )
|
||||
if ( awt_mode.getBitDepth() >= 16 )
|
||||
modes.add(createLWJGLDisplayMode(awt_mode));
|
||||
return modes.toArray(new DisplayMode[modes.size()]);
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
if (frame != null)
|
||||
if (frame != null)
|
||||
frame.setTitle(title);
|
||||
}
|
||||
|
||||
|
|
@ -247,7 +248,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
}
|
||||
}
|
||||
|
||||
private final static IntBuffer current_viewport = BufferUtils.createIntBuffer(16);
|
||||
private static final IntBuffer current_viewport = BufferUtils.createIntBuffer(16);
|
||||
public void update() {
|
||||
boolean should_update = canvas_listener.syncShouldUpdateContext();
|
||||
/*
|
||||
|
|
@ -282,8 +283,8 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
if (should_update) {
|
||||
drawable.context.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));
|
||||
glGetInteger(GL_VIEWPORT, current_viewport);
|
||||
glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3));
|
||||
}
|
||||
if (frame != null && mouse_queue != null) {
|
||||
if (frame.syncShouldReleaseCursor())
|
||||
|
|
@ -432,7 +433,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
public boolean isBufferLost(PeerInfo handle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format,
|
||||
IntBuffer pixelFormatCaps,
|
||||
IntBuffer pBufferAttribs) throws LWJGLException {
|
||||
|
|
@ -466,30 +467,30 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
public int setIcon(ByteBuffer[] icons) {
|
||||
/* int size = 0;
|
||||
int biggest = -1;
|
||||
|
||||
|
||||
for (int i=0;i<icons.length;i++) {
|
||||
if (icons[i].remaining() > size) {
|
||||
biggest = i;
|
||||
size = icons[i].remaining();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (biggest == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int width;
|
||||
int height;
|
||||
|
||||
|
||||
IntBuffer biggest_icon = icons[biggest].asIntBuffer();
|
||||
int[] imageData = new int[biggest_icon.remaining()];
|
||||
width = height = (int) Math.sqrt(imageData.length);
|
||||
biggest_icon.get(imageData);
|
||||
|
||||
|
||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
img.setRGB(0, 0, width, height, imageData, 0, width);
|
||||
frame.setIconImage(img);
|
||||
|
||||
|
||||
return 1;*/
|
||||
// Don't use any icon, since Mac OS X windows don't have window icons
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ import org.lwjgl.LWJGLException;
|
|||
* $Id$
|
||||
*/
|
||||
final class MacOSXDisplayPeerInfo extends MacOSXCanvasPeerInfo {
|
||||
private boolean locked = false;
|
||||
private boolean locked;
|
||||
|
||||
MacOSXDisplayPeerInfo(PixelFormat pixel_format, boolean support_pbuffer) throws LWJGLException {
|
||||
super(pixel_format, support_pbuffer);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ import org.lwjgl.LWJGLException;
|
|||
final class MacOSXFrame extends Frame implements WindowListener, ComponentListener {
|
||||
|
||||
private static final long serialVersionUID = -5823294716668988777L;
|
||||
|
||||
|
||||
private final MacOSXGLCanvas canvas;
|
||||
private boolean close_requested;
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
|
|||
setUndecorated(fullscreen || undecorated);
|
||||
if ( fullscreen ) {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws Exception {
|
||||
getDevice().setFullScreenWindow(MacOSXFrame.this);
|
||||
getDevice().setDisplayMode(requested_mode);
|
||||
|
|
@ -110,7 +110,7 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
|
|||
Insets insets = getInsets();
|
||||
setBounds(x, y, width + insets.left + insets.right, height + insets.top + insets.bottom);
|
||||
}
|
||||
|
||||
|
||||
public Rectangle syncGetBounds() {
|
||||
synchronized ( this ) {
|
||||
return bounds;
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ abstract class PeerInfo {
|
|||
doLockAndInitHandle();
|
||||
}
|
||||
|
||||
public synchronized final void unlock() throws LWJGLException {
|
||||
public final synchronized void unlock() throws LWJGLException {
|
||||
if (lock_count <= 0)
|
||||
throw new IllegalStateException("PeerInfo not locked!");
|
||||
if (Thread.currentThread() != locking_thread)
|
||||
|
|
@ -71,7 +71,7 @@ abstract class PeerInfo {
|
|||
protected abstract void doLockAndInitHandle() throws LWJGLException;
|
||||
protected abstract void doUnlock() throws LWJGLException;
|
||||
|
||||
public synchronized final ByteBuffer lockAndGetHandle() throws LWJGLException {
|
||||
public final synchronized ByteBuffer lockAndGetHandle() throws LWJGLException {
|
||||
Thread this_thread = Thread.currentThread();
|
||||
while (locking_thread != null && locking_thread != this_thread) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
*/
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
class ReferencesStack {
|
||||
private References[] references_stack;
|
||||
private int stack_pos;
|
||||
|
|
@ -44,7 +46,7 @@ class ReferencesStack {
|
|||
if (pos == references_stack.length) {
|
||||
growStack();
|
||||
}
|
||||
references_stack[pos].copy(references_stack[pos - 1], GL11.GL_ALL_CLIENT_ATTRIB_BITS);
|
||||
references_stack[pos].copy(references_stack[pos - 1], GL_ALL_CLIENT_ATTRIB_BITS);
|
||||
}
|
||||
|
||||
public References popState(int mask) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ import java.nio.IntBuffer;
|
|||
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/** This class represents the state necessary for render-to-texture. */
|
||||
public final class RenderTexture {
|
||||
|
||||
|
|
@ -214,13 +216,13 @@ public final class RenderTexture {
|
|||
|
||||
if ( useRGB ) {
|
||||
pixelFormatCaps.put(isRectangle ? WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV : WGL_BIND_TO_TEXTURE_RGB_ARB);
|
||||
pixelFormatCaps.put(GL11.GL_TRUE);
|
||||
pixelFormatCaps.put(GL_TRUE);
|
||||
|
||||
pBufferAttribs.put(WGL_TEXTURE_FORMAT_ARB);
|
||||
pBufferAttribs.put(WGL_TEXTURE_RGB_ARB);
|
||||
} else if ( useRGBA ) {
|
||||
pixelFormatCaps.put(isRectangle ? WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV : WGL_BIND_TO_TEXTURE_RGBA_ARB);
|
||||
pixelFormatCaps.put(GL11.GL_TRUE);
|
||||
pixelFormatCaps.put(GL_TRUE);
|
||||
|
||||
pBufferAttribs.put(WGL_TEXTURE_FORMAT_ARB);
|
||||
pBufferAttribs.put(WGL_TEXTURE_RGBA_ARB);
|
||||
|
|
@ -228,7 +230,7 @@ public final class RenderTexture {
|
|||
|
||||
if ( useDepth ) {
|
||||
pixelFormatCaps.put(isRectangle ? WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV : WGL_BIND_TO_TEXTURE_DEPTH_NV);
|
||||
pixelFormatCaps.put(GL11.GL_TRUE);
|
||||
pixelFormatCaps.put(GL_TRUE);
|
||||
|
||||
pBufferAttribs.put(WGL_DEPTH_TEXTURE_FORMAT_NV);
|
||||
pBufferAttribs.put(WGL_TEXTURE_DEPTH_COMPONENT_NV);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@
|
|||
*/
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
import static org.lwjgl.opengl.GL15.*;
|
||||
import static org.lwjgl.opengl.GL21.*;
|
||||
import static org.lwjgl.opengl.GL40.*;
|
||||
|
||||
final class StateTracker {
|
||||
private ReferencesStack references_stack;
|
||||
private final StateStack attrib_stack;
|
||||
|
|
@ -78,19 +82,19 @@ final class StateTracker {
|
|||
static void bindBuffer(ContextCapabilities caps, int target, int buffer) {
|
||||
ReferencesStack references_stack = getReferencesStack(caps);
|
||||
switch(target) {
|
||||
case GL15.GL_ELEMENT_ARRAY_BUFFER:
|
||||
case GL_ELEMENT_ARRAY_BUFFER:
|
||||
references_stack.getReferences().elementArrayBuffer = buffer;
|
||||
break;
|
||||
case GL15.GL_ARRAY_BUFFER:
|
||||
case GL_ARRAY_BUFFER:
|
||||
references_stack.getReferences().arrayBuffer = buffer;
|
||||
break;
|
||||
case GL21.GL_PIXEL_PACK_BUFFER:
|
||||
case GL_PIXEL_PACK_BUFFER:
|
||||
references_stack.getReferences().pixelPackBuffer = buffer;
|
||||
break;
|
||||
case GL21.GL_PIXEL_UNPACK_BUFFER:
|
||||
case GL_PIXEL_UNPACK_BUFFER:
|
||||
references_stack.getReferences().pixelUnpackBuffer = buffer;
|
||||
break;
|
||||
case GL40.GL_DRAW_INDIRECT_BUFFER:
|
||||
case GL_DRAW_INDIRECT_BUFFER:
|
||||
references_stack.getReferences().indirectBuffer = buffer;
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@
|
|||
*/
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
import static org.lwjgl.opengl.ARBImaging.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
|
||||
/**
|
||||
* Simple utility class.
|
||||
|
|
@ -43,16 +46,16 @@ public final class Util {
|
|||
/** No c'tor */
|
||||
private Util() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws OpenGLException if GL11.glGetError() returns anything else than GL11.GL_NO_ERROR
|
||||
* Throws OpenGLException if glGetError() returns anything else than GL_NO_ERROR
|
||||
*
|
||||
*/
|
||||
public static void checkGLError() throws OpenGLException {
|
||||
if ( ContextCapabilities.DEBUG && GLContext.getCapabilities().tracker.isBeginEnd() ) // Do not call GetError inside a Begin/End pair.
|
||||
return;
|
||||
int err = GL11.glGetError();
|
||||
if ( err != GL11.GL_NO_ERROR ) {
|
||||
int err = glGetError();
|
||||
if ( err != GL_NO_ERROR ) {
|
||||
throw new OpenGLException(err);
|
||||
}
|
||||
}
|
||||
|
|
@ -62,23 +65,23 @@ public final class Util {
|
|||
*/
|
||||
public static String translateGLErrorString(int error_code) {
|
||||
switch (error_code) {
|
||||
case GL11.GL_NO_ERROR:
|
||||
case GL_NO_ERROR:
|
||||
return "No error";
|
||||
case GL11.GL_INVALID_ENUM:
|
||||
case GL_INVALID_ENUM:
|
||||
return "Invalid enum";
|
||||
case GL11.GL_INVALID_VALUE:
|
||||
case GL_INVALID_VALUE:
|
||||
return "Invalid value";
|
||||
case GL11.GL_INVALID_OPERATION:
|
||||
case GL_INVALID_OPERATION:
|
||||
return "Invalid operation";
|
||||
case GL11.GL_STACK_OVERFLOW:
|
||||
case GL_STACK_OVERFLOW:
|
||||
return "Stack overflow";
|
||||
case GL11.GL_STACK_UNDERFLOW:
|
||||
case GL_STACK_UNDERFLOW:
|
||||
return "Stack underflow";
|
||||
case GL11.GL_OUT_OF_MEMORY:
|
||||
case GL_OUT_OF_MEMORY:
|
||||
return "Out of memory";
|
||||
case ARBImaging.GL_TABLE_TOO_LARGE:
|
||||
case GL_TABLE_TOO_LARGE:
|
||||
return "Table too large";
|
||||
case EXTFramebufferObject.GL_INVALID_FRAMEBUFFER_OPERATION_EXT:
|
||||
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
||||
return "Invalid framebuffer operation";
|
||||
default:
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ final class WindowsAWTGLCanvasPeerInfo extends WindowsPeerInfo {
|
|||
private final Canvas component;
|
||||
private final AWTSurfaceLock awt_surface = new AWTSurfaceLock();
|
||||
private final PixelFormat pixel_format;
|
||||
private boolean has_pixel_format= false;
|
||||
private boolean has_pixel_format;
|
||||
|
||||
WindowsAWTGLCanvasPeerInfo(Canvas component, PixelFormat pixel_format) {
|
||||
this.component = component;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ final class WindowsCanvasImplementation implements AWTCanvasImplementation {
|
|||
static {
|
||||
// Make sure the awt stuff is properly initialised (the jawt library in particular)
|
||||
Toolkit.getDefaultToolkit();
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
try {
|
||||
System.loadLibrary("jawt");
|
||||
|
|
|
|||
|
|
@ -51,87 +51,87 @@ import org.lwjgl.input.Keyboard;
|
|||
import org.lwjgl.input.Mouse;
|
||||
|
||||
final class WindowsDisplay implements DisplayImplementation {
|
||||
private final static int GAMMA_LENGTH = 256;
|
||||
|
||||
private final static int WM_CANCELMODE = 0x001F;
|
||||
private final static int WM_MOUSEMOVE = 0x0200;
|
||||
private final static int WM_LBUTTONDOWN = 0x0201;
|
||||
private final static int WM_LBUTTONUP = 0x0202;
|
||||
private final static int WM_LBUTTONDBLCLK = 0x0203;
|
||||
private final static int WM_RBUTTONDOWN = 0x0204;
|
||||
private final static int WM_RBUTTONUP = 0x0205;
|
||||
private final static int WM_RBUTTONDBLCLK = 0x0206;
|
||||
private final static int WM_MBUTTONDOWN = 0x0207;
|
||||
private final static int WM_MBUTTONUP = 0x0208;
|
||||
private final static int WM_MBUTTONDBLCLK = 0x0209;
|
||||
private final static int WM_MOUSEWHEEL = 0x020A;
|
||||
private final static int WM_CAPTURECHANGED = 0x0215;
|
||||
private final static int WM_MOUSELEAVE = 0x02A3;
|
||||
private final static int WM_KEYDOWN = 256;
|
||||
private final static int WM_KEYUP = 257;
|
||||
private final static int WM_SYSKEYUP = 261;
|
||||
private final static int WM_SYSKEYDOWN = 260;
|
||||
private final static int WM_SYSCHAR = 262;
|
||||
private final static int WM_CHAR = 258;
|
||||
private final static int WM_SETICON = 0x0080;
|
||||
private static final int GAMMA_LENGTH = 256;
|
||||
|
||||
private final static int WM_QUIT = 0x0012;
|
||||
private final static int WM_SYSCOMMAND = 0x0112;
|
||||
private final static int WM_PAINT = 0x000F;
|
||||
private final static int WM_KILLFOCUS = 8;
|
||||
private final static int WM_SETFOCUS = 7;
|
||||
private static final int WM_CANCELMODE = 0x001F;
|
||||
private static final int WM_MOUSEMOVE = 0x0200;
|
||||
private static final int WM_LBUTTONDOWN = 0x0201;
|
||||
private static final int WM_LBUTTONUP = 0x0202;
|
||||
private static final int WM_LBUTTONDBLCLK = 0x0203;
|
||||
private static final int WM_RBUTTONDOWN = 0x0204;
|
||||
private static final int WM_RBUTTONUP = 0x0205;
|
||||
private static final int WM_RBUTTONDBLCLK = 0x0206;
|
||||
private static final int WM_MBUTTONDOWN = 0x0207;
|
||||
private static final int WM_MBUTTONUP = 0x0208;
|
||||
private static final int WM_MBUTTONDBLCLK = 0x0209;
|
||||
private static final int WM_MOUSEWHEEL = 0x020A;
|
||||
private static final int WM_CAPTURECHANGED = 0x0215;
|
||||
private static final int WM_MOUSELEAVE = 0x02A3;
|
||||
private static final int WM_KEYDOWN = 256;
|
||||
private static final int WM_KEYUP = 257;
|
||||
private static final int WM_SYSKEYUP = 261;
|
||||
private static final int WM_SYSKEYDOWN = 260;
|
||||
private static final int WM_SYSCHAR = 262;
|
||||
private static final int WM_CHAR = 258;
|
||||
private static final int WM_SETICON = 0x0080;
|
||||
|
||||
private final static int SC_SIZE = 0xF000;
|
||||
private final static int SC_MOVE = 0xF010;
|
||||
private final static int SC_MINIMIZE = 0xF020;
|
||||
private final static int SC_MAXIMIZE = 0xF030;
|
||||
private final static int SC_NEXTWINDOW = 0xF040;
|
||||
private final static int SC_PREVWINDOW = 0xF050;
|
||||
private final static int SC_CLOSE = 0xF060;
|
||||
private final static int SC_VSCROLL = 0xF070;
|
||||
private final static int SC_HSCROLL = 0xF080;
|
||||
private final static int SC_MOUSEMENU = 0xF090;
|
||||
private final static int SC_KEYMENU = 0xF100;
|
||||
private final static int SC_ARRANGE = 0xF110;
|
||||
private final static int SC_RESTORE = 0xF120;
|
||||
private final static int SC_TASKLIST = 0xF130;
|
||||
private final static int SC_SCREENSAVE = 0xF140;
|
||||
private final static int SC_HOTKEY = 0xF150;
|
||||
private final static int SC_DEFAULT = 0xF160;
|
||||
private final static int SC_MONITORPOWER = 0xF170;
|
||||
private final static int SC_CONTEXTHELP = 0xF180;
|
||||
private final static int SC_SEPARATOR = 0xF00F;
|
||||
private static final int WM_QUIT = 0x0012;
|
||||
private static final int WM_SYSCOMMAND = 0x0112;
|
||||
private static final int WM_PAINT = 0x000F;
|
||||
private static final int WM_KILLFOCUS = 8;
|
||||
private static final int WM_SETFOCUS = 7;
|
||||
|
||||
final static int SM_CXCURSOR = 13;
|
||||
final static int SM_CYCURSOR = 14;
|
||||
final static int SM_CMOUSEBUTTONS = 43;
|
||||
final static int SM_MOUSEWHEELPRESENT = 75;
|
||||
private static final int SC_SIZE = 0xF000;
|
||||
private static final int SC_MOVE = 0xF010;
|
||||
private static final int SC_MINIMIZE = 0xF020;
|
||||
private static final int SC_MAXIMIZE = 0xF030;
|
||||
private static final int SC_NEXTWINDOW = 0xF040;
|
||||
private static final int SC_PREVWINDOW = 0xF050;
|
||||
private static final int SC_CLOSE = 0xF060;
|
||||
private static final int SC_VSCROLL = 0xF070;
|
||||
private static final int SC_HSCROLL = 0xF080;
|
||||
private static final int SC_MOUSEMENU = 0xF090;
|
||||
private static final int SC_KEYMENU = 0xF100;
|
||||
private static final int SC_ARRANGE = 0xF110;
|
||||
private static final int SC_RESTORE = 0xF120;
|
||||
private static final int SC_TASKLIST = 0xF130;
|
||||
private static final int SC_SCREENSAVE = 0xF140;
|
||||
private static final int SC_HOTKEY = 0xF150;
|
||||
private static final int SC_DEFAULT = 0xF160;
|
||||
private static final int SC_MONITORPOWER = 0xF170;
|
||||
private static final int SC_CONTEXTHELP = 0xF180;
|
||||
private static final int SC_SEPARATOR = 0xF00F;
|
||||
|
||||
private final static int SIZE_RESTORED = 0;
|
||||
private final static int SIZE_MINIMIZED = 1;
|
||||
private final static int SIZE_MAXIMIZED = 2;
|
||||
private final static int WM_SIZE = 0x0005;
|
||||
private final static int WM_ACTIVATE = 0x0006;
|
||||
private final static int WA_INACTIVE = 0;
|
||||
private final static int WA_ACTIVE = 1;
|
||||
private final static int WA_CLICKACTIVE = 2;
|
||||
private final static int SW_SHOWMINNOACTIVE = 7;
|
||||
private final static int SW_SHOWDEFAULT = 10;
|
||||
private final static int SW_RESTORE = 9;
|
||||
static final int SM_CXCURSOR = 13;
|
||||
static final int SM_CYCURSOR = 14;
|
||||
static final int SM_CMOUSEBUTTONS = 43;
|
||||
static final int SM_MOUSEWHEELPRESENT = 75;
|
||||
|
||||
private final static int ICON_SMALL = 0;
|
||||
private final static int ICON_BIG = 1;
|
||||
private static final int SIZE_RESTORED = 0;
|
||||
private static final int SIZE_MINIMIZED = 1;
|
||||
private static final int SIZE_MAXIMIZED = 2;
|
||||
private static final int WM_SIZE = 0x0005;
|
||||
private static final int WM_ACTIVATE = 0x0006;
|
||||
private static final int WA_INACTIVE = 0;
|
||||
private static final int WA_ACTIVE = 1;
|
||||
private static final int WA_CLICKACTIVE = 2;
|
||||
private static final int SW_SHOWMINNOACTIVE = 7;
|
||||
private static final int SW_SHOWDEFAULT = 10;
|
||||
private static final int SW_RESTORE = 9;
|
||||
|
||||
private final static IntBuffer rect_buffer = BufferUtils.createIntBuffer(4);
|
||||
private final static Rect rect = new Rect();
|
||||
private final static Rect rect2 = new Rect();
|
||||
private static final int ICON_SMALL = 0;
|
||||
private static final int ICON_BIG = 1;
|
||||
|
||||
private static final IntBuffer rect_buffer = BufferUtils.createIntBuffer(4);
|
||||
private static final Rect rect = new Rect();
|
||||
private static final Rect rect2 = new Rect();
|
||||
private static WindowsDisplay current_display;
|
||||
|
||||
private static boolean cursor_clipped;
|
||||
private WindowsDisplayPeerInfo peer_info;
|
||||
private Object current_cursor;
|
||||
private Canvas parent;
|
||||
private static boolean hasParent = false;
|
||||
private static boolean hasParent;
|
||||
|
||||
private WindowsKeyboard keyboard;
|
||||
private WindowsMouse mouse;
|
||||
|
|
@ -156,8 +156,8 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
private long large_icon;
|
||||
|
||||
private int captureMouse = -1;
|
||||
private boolean trackingMouse = false;
|
||||
private boolean mouseInside = false;
|
||||
private boolean trackingMouse;
|
||||
private boolean mouseInside;
|
||||
|
||||
WindowsDisplay() {
|
||||
current_display = this;
|
||||
|
|
@ -378,7 +378,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
String driver = getAdapter();
|
||||
if (driver != null) {
|
||||
String[] drivers = driver.split(",");
|
||||
if(drivers.length>0) {
|
||||
if(drivers.length>0) {
|
||||
WindowsFileVersion version = nGetVersion(drivers[0] + ".dll");
|
||||
if (version != null)
|
||||
return version.toString();
|
||||
|
|
@ -664,19 +664,19 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
|
||||
int small_icon_size = 16;
|
||||
int large_icon_size = 32;
|
||||
for (int i=0;i<icons.length;i++) {
|
||||
int size = icons[i].limit() / 4;
|
||||
for ( ByteBuffer icon : icons ) {
|
||||
int size = icon.limit() / 4;
|
||||
|
||||
if ((((int) Math.sqrt(size)) == small_icon_size) && (!done_small)) {
|
||||
if ( (((int)Math.sqrt(size)) == small_icon_size) && (!done_small) ) {
|
||||
freeSmallIcon();
|
||||
small_icon = createIcon(small_icon_size, small_icon_size, icons[i].asIntBuffer());
|
||||
small_icon = createIcon(small_icon_size, small_icon_size, icon.asIntBuffer());
|
||||
sendMessage(hwnd, WM_SETICON, ICON_SMALL, small_icon);
|
||||
used++;
|
||||
done_small = true;
|
||||
}
|
||||
if ((((int) Math.sqrt(size)) == large_icon_size) && (!done_large)) {
|
||||
if ( (((int)Math.sqrt(size)) == large_icon_size) && (!done_large) ) {
|
||||
freeLargeIcon();
|
||||
large_icon = createIcon(large_icon_size, large_icon_size, icons[i].asIntBuffer());
|
||||
large_icon = createIcon(large_icon_size, large_icon_size, icon.asIntBuffer());
|
||||
sendMessage(hwnd, WM_SETICON, ICON_BIG, large_icon);
|
||||
used++;
|
||||
done_large = true;
|
||||
|
|
@ -692,20 +692,20 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
private void handleMouseButton(int button, int state, long millis) {
|
||||
if (mouse != null) {
|
||||
mouse.handleMouseButton((byte)button, (byte)state, millis);
|
||||
|
||||
|
||||
// need to capture?
|
||||
if (captureMouse == -1 && button != -1 && state == 1) {
|
||||
captureMouse = button;
|
||||
nSetCapture(hwnd);
|
||||
}
|
||||
|
||||
|
||||
// done with capture?
|
||||
if(captureMouse != -1 && button == captureMouse && state == 0) {
|
||||
captureMouse = -1;
|
||||
nReleaseCapture();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (parent != null && !isFocused) {
|
||||
setFocus(getHwnd());
|
||||
}
|
||||
|
|
@ -720,10 +720,10 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
mouse.handleMouseMoved(x, y, millis, shouldGrab());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static native long nSetCapture(long hwnd);
|
||||
private static native boolean nReleaseCapture();
|
||||
|
||||
|
||||
private void handleMouseScrolled(int amount, long millis) {
|
||||
if (mouse != null)
|
||||
mouse.handleMouseScrolled(amount, millis);
|
||||
|
|
@ -747,7 +747,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
int scan_code = (int)((lParam >>> 16) & 0xFF);
|
||||
if (keyboard != null) {
|
||||
keyboard.handleKey((int)wParam, scan_code, extended != 0, state, millis, repeat);
|
||||
|
||||
|
||||
if(captureMouse != -1 && keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
|
||||
nReleaseCapture();
|
||||
captureMouse = -1;
|
||||
|
|
@ -869,7 +869,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
// Set key state to pressed
|
||||
long fake_lparam = lParam & ~(1 << 31);
|
||||
// Set key previous state to released
|
||||
fake_lparam = fake_lparam & ~(1 << 30);
|
||||
fake_lparam &= ~(1 << 30);
|
||||
handleKeyButton(wParam, fake_lparam, millis);
|
||||
}
|
||||
/* Fall through */
|
||||
|
|
@ -923,7 +923,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
public int getHeight() {
|
||||
return Display.getDisplayMode().getHeight();
|
||||
}
|
||||
|
||||
|
||||
private int firstMouseButtonDown() {
|
||||
for(int i=0; i<Mouse.getButtonCount(); i++) {
|
||||
if(Mouse.isButtonDown(i)) {
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ import org.lwjgl.LWJGLException;
|
|||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
final class WindowsKeyboard {
|
||||
private final static int MAPVK_VK_TO_VSC = 0;
|
||||
private static final int MAPVK_VK_TO_VSC = 0;
|
||||
|
||||
private final static int BUFFER_SIZE = 50;
|
||||
private static final int BUFFER_SIZE = 50;
|
||||
|
||||
private final long hwnd;
|
||||
private final ByteBuffer keyboard_state;
|
||||
|
|
|
|||
|
|
@ -38,177 +38,177 @@ package org.lwjgl.opengl;
|
|||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
final class WindowsKeycodes {
|
||||
public final static int VK_LBUTTON = 0x01;
|
||||
public final static int VK_RBUTTON = 0x02;
|
||||
public final static int VK_CANCEL = 0x03;
|
||||
public final static int VK_MBUTTON = 0x04; /* NOT contiguous with L & RBUTTON */
|
||||
public static final int VK_LBUTTON = 0x01;
|
||||
public static final int VK_RBUTTON = 0x02;
|
||||
public static final int VK_CANCEL = 0x03;
|
||||
public static final int VK_MBUTTON = 0x04; /* NOT contiguous with L & RBUTTON */
|
||||
|
||||
public final static int VK_XBUTTON1 = 0x05; /* NOT contiguous with L & RBUTTON */
|
||||
public final static int VK_XBUTTON2 = 0x06; /* NOT contiguous with L & RBUTTON */
|
||||
public static final int VK_XBUTTON1 = 0x05; /* NOT contiguous with L & RBUTTON */
|
||||
public static final int VK_XBUTTON2 = 0x06; /* NOT contiguous with L & RBUTTON */
|
||||
|
||||
/*
|
||||
* 0x07 : unassigned
|
||||
*/
|
||||
|
||||
public final static int VK_BACK = 0x08;
|
||||
public final static int VK_TAB = 0x09;
|
||||
public static final int VK_BACK = 0x08;
|
||||
public static final int VK_TAB = 0x09;
|
||||
|
||||
/*
|
||||
* 0x0A - 0x0B : reserved
|
||||
*/
|
||||
|
||||
public final static int VK_CLEAR = 0x0C;
|
||||
public final static int VK_RETURN = 0x0D;
|
||||
public static final int VK_CLEAR = 0x0C;
|
||||
public static final int VK_RETURN = 0x0D;
|
||||
|
||||
public final static int VK_SHIFT = 0x10;
|
||||
public final static int VK_CONTROL = 0x11;
|
||||
public final static int VK_MENU = 0x12;
|
||||
public final static int VK_PAUSE = 0x13;
|
||||
public final static int VK_CAPITAL = 0x14;
|
||||
public static final int VK_SHIFT = 0x10;
|
||||
public static final int VK_CONTROL = 0x11;
|
||||
public static final int VK_MENU = 0x12;
|
||||
public static final int VK_PAUSE = 0x13;
|
||||
public static final int VK_CAPITAL = 0x14;
|
||||
|
||||
public final static int VK_KANA = 0x15;
|
||||
public final static int VK_HANGEUL = 0x15; /* old name - should be here for compatibility */
|
||||
public final static int VK_HANGUL = 0x15;
|
||||
public final static int VK_JUNJA = 0x17;
|
||||
public final static int VK_FINAL = 0x18;
|
||||
public final static int VK_HANJA = 0x19;
|
||||
public final static int VK_KANJI = 0x19;
|
||||
public static final int VK_KANA = 0x15;
|
||||
public static final int VK_HANGEUL = 0x15; /* old name - should be here for compatibility */
|
||||
public static final int VK_HANGUL = 0x15;
|
||||
public static final int VK_JUNJA = 0x17;
|
||||
public static final int VK_FINAL = 0x18;
|
||||
public static final int VK_HANJA = 0x19;
|
||||
public static final int VK_KANJI = 0x19;
|
||||
|
||||
public final static int VK_ESCAPE = 0x1B;
|
||||
public static final int VK_ESCAPE = 0x1B;
|
||||
|
||||
public final static int VK_CONVERT = 0x1C;
|
||||
public final static int VK_NONCONVERT = 0x1D;
|
||||
public final static int VK_ACCEPT = 0x1E;
|
||||
public final static int VK_MODECHANGE = 0x1F;
|
||||
public static final int VK_CONVERT = 0x1C;
|
||||
public static final int VK_NONCONVERT = 0x1D;
|
||||
public static final int VK_ACCEPT = 0x1E;
|
||||
public static final int VK_MODECHANGE = 0x1F;
|
||||
|
||||
public final static int VK_SPACE = 0x20;
|
||||
public final static int VK_PRIOR = 0x21;
|
||||
public final static int VK_NEXT = 0x22;
|
||||
public final static int VK_END = 0x23;
|
||||
public final static int VK_HOME = 0x24;
|
||||
public final static int VK_LEFT = 0x25;
|
||||
public final static int VK_UP = 0x26;
|
||||
public final static int VK_RIGHT = 0x27;
|
||||
public final static int VK_DOWN = 0x28;
|
||||
public final static int VK_SELECT = 0x29;
|
||||
public final static int VK_PRINT = 0x2A;
|
||||
public final static int VK_EXECUTE = 0x2B;
|
||||
public final static int VK_SNAPSHOT = 0x2C;
|
||||
public final static int VK_INSERT = 0x2D;
|
||||
public final static int VK_DELETE = 0x2E;
|
||||
public final static int VK_HELP = 0x2F;
|
||||
public static final int VK_SPACE = 0x20;
|
||||
public static final int VK_PRIOR = 0x21;
|
||||
public static final int VK_NEXT = 0x22;
|
||||
public static final int VK_END = 0x23;
|
||||
public static final int VK_HOME = 0x24;
|
||||
public static final int VK_LEFT = 0x25;
|
||||
public static final int VK_UP = 0x26;
|
||||
public static final int VK_RIGHT = 0x27;
|
||||
public static final int VK_DOWN = 0x28;
|
||||
public static final int VK_SELECT = 0x29;
|
||||
public static final int VK_PRINT = 0x2A;
|
||||
public static final int VK_EXECUTE = 0x2B;
|
||||
public static final int VK_SNAPSHOT = 0x2C;
|
||||
public static final int VK_INSERT = 0x2D;
|
||||
public static final int VK_DELETE = 0x2E;
|
||||
public static final int VK_HELP = 0x2F;
|
||||
/*
|
||||
* VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
|
||||
* 0x40 : unassigned
|
||||
* VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)
|
||||
*/
|
||||
public final static int VK_0 = 0x30;
|
||||
public final static int VK_1 = 0x31;
|
||||
public final static int VK_2 = 0x32;
|
||||
public final static int VK_3 = 0x33;
|
||||
public final static int VK_4 = 0x34;
|
||||
public final static int VK_5 = 0x35;
|
||||
public final static int VK_6 = 0x36;
|
||||
public final static int VK_7 = 0x37;
|
||||
public final static int VK_8 = 0x38;
|
||||
public final static int VK_9 = 0x39;
|
||||
public static final int VK_0 = 0x30;
|
||||
public static final int VK_1 = 0x31;
|
||||
public static final int VK_2 = 0x32;
|
||||
public static final int VK_3 = 0x33;
|
||||
public static final int VK_4 = 0x34;
|
||||
public static final int VK_5 = 0x35;
|
||||
public static final int VK_6 = 0x36;
|
||||
public static final int VK_7 = 0x37;
|
||||
public static final int VK_8 = 0x38;
|
||||
public static final int VK_9 = 0x39;
|
||||
|
||||
public final static int VK_A = 0x41;
|
||||
public final static int VK_B = 0x42;
|
||||
public final static int VK_C = 0x43;
|
||||
public final static int VK_D = 0x44;
|
||||
public final static int VK_E = 0x45;
|
||||
public final static int VK_F = 0x46;
|
||||
public final static int VK_G = 0x47;
|
||||
public final static int VK_H = 0x48;
|
||||
public final static int VK_I = 0x49;
|
||||
public final static int VK_J = 0x4A;
|
||||
public final static int VK_K = 0x4B;
|
||||
public final static int VK_L = 0x4C;
|
||||
public final static int VK_M = 0x4D;
|
||||
public final static int VK_N = 0x4E;
|
||||
public final static int VK_O = 0x4F;
|
||||
public final static int VK_P = 0x50;
|
||||
public final static int VK_Q = 0x51;
|
||||
public final static int VK_R = 0x52;
|
||||
public final static int VK_S = 0x53;
|
||||
public final static int VK_T = 0x54;
|
||||
public final static int VK_U = 0x55;
|
||||
public final static int VK_V = 0x56;
|
||||
public final static int VK_W = 0x57;
|
||||
public final static int VK_X = 0x58;
|
||||
public final static int VK_Y = 0x59;
|
||||
public final static int VK_Z = 0x5A;
|
||||
public static final int VK_A = 0x41;
|
||||
public static final int VK_B = 0x42;
|
||||
public static final int VK_C = 0x43;
|
||||
public static final int VK_D = 0x44;
|
||||
public static final int VK_E = 0x45;
|
||||
public static final int VK_F = 0x46;
|
||||
public static final int VK_G = 0x47;
|
||||
public static final int VK_H = 0x48;
|
||||
public static final int VK_I = 0x49;
|
||||
public static final int VK_J = 0x4A;
|
||||
public static final int VK_K = 0x4B;
|
||||
public static final int VK_L = 0x4C;
|
||||
public static final int VK_M = 0x4D;
|
||||
public static final int VK_N = 0x4E;
|
||||
public static final int VK_O = 0x4F;
|
||||
public static final int VK_P = 0x50;
|
||||
public static final int VK_Q = 0x51;
|
||||
public static final int VK_R = 0x52;
|
||||
public static final int VK_S = 0x53;
|
||||
public static final int VK_T = 0x54;
|
||||
public static final int VK_U = 0x55;
|
||||
public static final int VK_V = 0x56;
|
||||
public static final int VK_W = 0x57;
|
||||
public static final int VK_X = 0x58;
|
||||
public static final int VK_Y = 0x59;
|
||||
public static final int VK_Z = 0x5A;
|
||||
|
||||
public final static int VK_LWIN = 0x5B;
|
||||
public final static int VK_RWIN = 0x5C;
|
||||
public final static int VK_APPS = 0x5D;
|
||||
public static final int VK_LWIN = 0x5B;
|
||||
public static final int VK_RWIN = 0x5C;
|
||||
public static final int VK_APPS = 0x5D;
|
||||
/*
|
||||
* 0x5E : reserved;
|
||||
*/
|
||||
|
||||
public final static int VK_SLEEP = 0x5F;
|
||||
public static final int VK_SLEEP = 0x5F;
|
||||
|
||||
public final static int VK_NUMPAD0 = 0x60;
|
||||
public final static int VK_NUMPAD1 = 0x61;
|
||||
public final static int VK_NUMPAD2 = 0x62;
|
||||
public final static int VK_NUMPAD3 = 0x63;
|
||||
public final static int VK_NUMPAD4 = 0x64;
|
||||
public final static int VK_NUMPAD5 = 0x65;
|
||||
public final static int VK_NUMPAD6 = 0x66;
|
||||
public final static int VK_NUMPAD7 = 0x67;
|
||||
public final static int VK_NUMPAD8 = 0x68;
|
||||
public final static int VK_NUMPAD9 = 0x69;
|
||||
public final static int VK_MULTIPLY = 0x6A;
|
||||
public final static int VK_ADD = 0x6B;
|
||||
public final static int VK_SEPARATOR = 0x6C;
|
||||
public final static int VK_SUBTRACT = 0x6D;
|
||||
public final static int VK_DECIMAL = 0x6E;
|
||||
public final static int VK_DIVIDE = 0x6F;
|
||||
public final static int VK_F1 = 0x70;
|
||||
public final static int VK_F2 = 0x71;
|
||||
public final static int VK_F3 = 0x72;
|
||||
public final static int VK_F4 = 0x73;
|
||||
public final static int VK_F5 = 0x74;
|
||||
public final static int VK_F6 = 0x75;
|
||||
public final static int VK_F7 = 0x76;
|
||||
public final static int VK_F8 = 0x77;
|
||||
public final static int VK_F9 = 0x78;
|
||||
public final static int VK_F10 = 0x79;
|
||||
public final static int VK_F11 = 0x7A;
|
||||
public final static int VK_F12 = 0x7B;
|
||||
public final static int VK_F13 = 0x7C;
|
||||
public final static int VK_F14 = 0x7D;
|
||||
public final static int VK_F15 = 0x7E;
|
||||
public final static int VK_F16 = 0x7F;
|
||||
public final static int VK_F17 = 0x80;
|
||||
public final static int VK_F18 = 0x81;
|
||||
public final static int VK_F19 = 0x82;
|
||||
public final static int VK_F20 = 0x83;
|
||||
public final static int VK_F21 = 0x84;
|
||||
public final static int VK_F22 = 0x85;
|
||||
public final static int VK_F23 = 0x86;
|
||||
public final static int VK_F24 = 0x87;
|
||||
public static final int VK_NUMPAD0 = 0x60;
|
||||
public static final int VK_NUMPAD1 = 0x61;
|
||||
public static final int VK_NUMPAD2 = 0x62;
|
||||
public static final int VK_NUMPAD3 = 0x63;
|
||||
public static final int VK_NUMPAD4 = 0x64;
|
||||
public static final int VK_NUMPAD5 = 0x65;
|
||||
public static final int VK_NUMPAD6 = 0x66;
|
||||
public static final int VK_NUMPAD7 = 0x67;
|
||||
public static final int VK_NUMPAD8 = 0x68;
|
||||
public static final int VK_NUMPAD9 = 0x69;
|
||||
public static final int VK_MULTIPLY = 0x6A;
|
||||
public static final int VK_ADD = 0x6B;
|
||||
public static final int VK_SEPARATOR = 0x6C;
|
||||
public static final int VK_SUBTRACT = 0x6D;
|
||||
public static final int VK_DECIMAL = 0x6E;
|
||||
public static final int VK_DIVIDE = 0x6F;
|
||||
public static final int VK_F1 = 0x70;
|
||||
public static final int VK_F2 = 0x71;
|
||||
public static final int VK_F3 = 0x72;
|
||||
public static final int VK_F4 = 0x73;
|
||||
public static final int VK_F5 = 0x74;
|
||||
public static final int VK_F6 = 0x75;
|
||||
public static final int VK_F7 = 0x76;
|
||||
public static final int VK_F8 = 0x77;
|
||||
public static final int VK_F9 = 0x78;
|
||||
public static final int VK_F10 = 0x79;
|
||||
public static final int VK_F11 = 0x7A;
|
||||
public static final int VK_F12 = 0x7B;
|
||||
public static final int VK_F13 = 0x7C;
|
||||
public static final int VK_F14 = 0x7D;
|
||||
public static final int VK_F15 = 0x7E;
|
||||
public static final int VK_F16 = 0x7F;
|
||||
public static final int VK_F17 = 0x80;
|
||||
public static final int VK_F18 = 0x81;
|
||||
public static final int VK_F19 = 0x82;
|
||||
public static final int VK_F20 = 0x83;
|
||||
public static final int VK_F21 = 0x84;
|
||||
public static final int VK_F22 = 0x85;
|
||||
public static final int VK_F23 = 0x86;
|
||||
public static final int VK_F24 = 0x87;
|
||||
|
||||
/*
|
||||
* 0x88 - 0x8F : unassigned;
|
||||
*/
|
||||
|
||||
public final static int VK_NUMLOCK = 0x90;
|
||||
public final static int VK_SCROLL = 0x91;
|
||||
public static final int VK_NUMLOCK = 0x90;
|
||||
public static final int VK_SCROLL = 0x91;
|
||||
|
||||
/*
|
||||
* NEC PC-9800 kbd definitions
|
||||
*/
|
||||
public final static int VK_OEM_NEC_EQUAL = 0x92; // '=' key on numpad
|
||||
public static final int VK_OEM_NEC_EQUAL = 0x92; // '=' key on numpad
|
||||
/*
|
||||
* Fujitsu/OASYS kbd definitions
|
||||
*/
|
||||
public final static int VK_OEM_FJ_JISHO = 0x92; // 'Dictionary' key
|
||||
public final static int VK_OEM_FJ_MASSHOU = 0x93; // 'Unregister word' key
|
||||
public final static int VK_OEM_FJ_TOUROKU = 0x94; // 'Register word' key
|
||||
public final static int VK_OEM_FJ_LOYA = 0x95; // 'Left OYAYUBI' key
|
||||
public final static int VK_OEM_FJ_ROYA = 0x96; // 'Right OYAYUBI' key
|
||||
public static final int VK_OEM_FJ_JISHO = 0x92; // 'Dictionary' key
|
||||
public static final int VK_OEM_FJ_MASSHOU = 0x93; // 'Unregister word' key
|
||||
public static final int VK_OEM_FJ_TOUROKU = 0x94; // 'Register word' key
|
||||
public static final int VK_OEM_FJ_LOYA = 0x95; // 'Left OYAYUBI' key
|
||||
public static final int VK_OEM_FJ_ROYA = 0x96; // 'Right OYAYUBI' key
|
||||
|
||||
/*
|
||||
* 0x97 - 0x9F : unassigned
|
||||
|
|
@ -219,44 +219,44 @@ final class WindowsKeycodes {
|
|||
* Used only as parameters to GetAsyncKeyState() and GetKeyState().
|
||||
* No other API or message will distinguish left and right keys in this way.
|
||||
*/
|
||||
public final static int VK_LSHIFT = 0xA0;
|
||||
public final static int VK_RSHIFT = 0xA1;
|
||||
public final static int VK_LCONTROL = 0xA2;
|
||||
public final static int VK_RCONTROL = 0xA3;
|
||||
public final static int VK_LMENU = 0xA4;
|
||||
public final static int VK_RMENU = 0xA5;
|
||||
public static final int VK_LSHIFT = 0xA0;
|
||||
public static final int VK_RSHIFT = 0xA1;
|
||||
public static final int VK_LCONTROL = 0xA2;
|
||||
public static final int VK_RCONTROL = 0xA3;
|
||||
public static final int VK_LMENU = 0xA4;
|
||||
public static final int VK_RMENU = 0xA5;
|
||||
|
||||
public final static int VK_BROWSER_BACK = 0xA6;
|
||||
public final static int VK_BROWSER_FORWARD = 0xA7;
|
||||
public final static int VK_BROWSER_REFRESH = 0xA8;
|
||||
public final static int VK_BROWSER_STOP = 0xA9;
|
||||
public final static int VK_BROWSER_SEARCH = 0xAA;
|
||||
public final static int VK_BROWSER_FAVORITES = 0xAB;
|
||||
public final static int VK_BROWSER_HOME = 0xAC;
|
||||
public static final int VK_BROWSER_BACK = 0xA6;
|
||||
public static final int VK_BROWSER_FORWARD = 0xA7;
|
||||
public static final int VK_BROWSER_REFRESH = 0xA8;
|
||||
public static final int VK_BROWSER_STOP = 0xA9;
|
||||
public static final int VK_BROWSER_SEARCH = 0xAA;
|
||||
public static final int VK_BROWSER_FAVORITES = 0xAB;
|
||||
public static final int VK_BROWSER_HOME = 0xAC;
|
||||
|
||||
public final static int VK_VOLUME_MUTE = 0xAD;
|
||||
public final static int VK_VOLUME_DOWN = 0xAE;
|
||||
public final static int VK_VOLUME_UP = 0xAF;
|
||||
public final static int VK_MEDIA_NEXT_TRACK = 0xB0;
|
||||
public final static int VK_MEDIA_PREV_TRACK = 0xB1;
|
||||
public final static int VK_MEDIA_STOP = 0xB2;
|
||||
public final static int VK_MEDIA_PLAY_PAUSE = 0xB3;
|
||||
public final static int VK_LAUNCH_MAIL = 0xB4;
|
||||
public final static int VK_LAUNCH_MEDIA_SELECT = 0xB5;
|
||||
public final static int VK_LAUNCH_APP1 = 0xB6;
|
||||
public final static int VK_LAUNCH_APP2 = 0xB7;
|
||||
public static final int VK_VOLUME_MUTE = 0xAD;
|
||||
public static final int VK_VOLUME_DOWN = 0xAE;
|
||||
public static final int VK_VOLUME_UP = 0xAF;
|
||||
public static final int VK_MEDIA_NEXT_TRACK = 0xB0;
|
||||
public static final int VK_MEDIA_PREV_TRACK = 0xB1;
|
||||
public static final int VK_MEDIA_STOP = 0xB2;
|
||||
public static final int VK_MEDIA_PLAY_PAUSE = 0xB3;
|
||||
public static final int VK_LAUNCH_MAIL = 0xB4;
|
||||
public static final int VK_LAUNCH_MEDIA_SELECT = 0xB5;
|
||||
public static final int VK_LAUNCH_APP1 = 0xB6;
|
||||
public static final int VK_LAUNCH_APP2 = 0xB7;
|
||||
|
||||
/*
|
||||
* 0xB8 - 0xB9 : reserved
|
||||
*/
|
||||
|
||||
public final static int VK_OEM_1 = 0xBA; // ';:' for US
|
||||
public final static int VK_OEM_PLUS = 0xBB; // '+' any country
|
||||
public final static int VK_OEM_COMMA = 0xBC; // ',' any country
|
||||
public final static int VK_OEM_MINUS = 0xBD; // '-' any country
|
||||
public final static int VK_OEM_PERIOD = 0xBE; // '.' any country
|
||||
public final static int VK_OEM_2 = 0xBF; // '/?' for US
|
||||
public final static int VK_OEM_3 = 0xC0; // '`~' for US
|
||||
public static final int VK_OEM_1 = 0xBA; // ';:' for US
|
||||
public static final int VK_OEM_PLUS = 0xBB; // '+' any country
|
||||
public static final int VK_OEM_COMMA = 0xBC; // ',' any country
|
||||
public static final int VK_OEM_MINUS = 0xBD; // '-' any country
|
||||
public static final int VK_OEM_PERIOD = 0xBE; // '.' any country
|
||||
public static final int VK_OEM_2 = 0xBF; // '/?' for US
|
||||
public static final int VK_OEM_3 = 0xC0; // '`~' for US
|
||||
|
||||
/*
|
||||
* 0xC1 - 0xD7 : reserved
|
||||
|
|
@ -266,11 +266,11 @@ final class WindowsKeycodes {
|
|||
* 0xD8 - 0xDA : unassigned
|
||||
*/
|
||||
|
||||
public final static int VK_OEM_4 = 0xDB; // '[{' for US
|
||||
public final static int VK_OEM_5 = 0xDC; // '\|' for US
|
||||
public final static int VK_OEM_6 = 0xDD; // ']}' for US
|
||||
public final static int VK_OEM_7 = 0xDE; // ''"' for US
|
||||
public final static int VK_OEM_8 = 0xDF;
|
||||
public static final int VK_OEM_4 = 0xDB; // '[{' for US
|
||||
public static final int VK_OEM_5 = 0xDC; // '\|' for US
|
||||
public static final int VK_OEM_6 = 0xDD; // ']}' for US
|
||||
public static final int VK_OEM_7 = 0xDE; // ''"' for US
|
||||
public static final int VK_OEM_8 = 0xDF;
|
||||
|
||||
/*
|
||||
* 0xE0 : reserved
|
||||
|
|
@ -279,48 +279,48 @@ final class WindowsKeycodes {
|
|||
/*
|
||||
* Various extended or enhanced keyboards
|
||||
*/
|
||||
public final static int VK_OEM_AX = 0xE1; // 'AX' key on Japanese AX kbd
|
||||
public final static int VK_OEM_102 = 0xE2; // "<>" or "\|" on RT 102-key kbd.
|
||||
public final static int VK_ICO_HELP = 0xE3; // Help key on ICO
|
||||
public final static int VK_ICO_00 = 0xE4; // 00 key on ICO
|
||||
public static final int VK_OEM_AX = 0xE1; // 'AX' key on Japanese AX kbd
|
||||
public static final int VK_OEM_102 = 0xE2; // "<>" or "\|" on RT 102-key kbd.
|
||||
public static final int VK_ICO_HELP = 0xE3; // Help key on ICO
|
||||
public static final int VK_ICO_00 = 0xE4; // 00 key on ICO
|
||||
|
||||
public final static int VK_PROCESSKEY = 0xE5;
|
||||
public static final int VK_PROCESSKEY = 0xE5;
|
||||
|
||||
public final static int VK_ICO_CLEAR = 0xE6;
|
||||
public static final int VK_ICO_CLEAR = 0xE6;
|
||||
|
||||
|
||||
public final static int VK_PACKET = 0xE7;
|
||||
public static final int VK_PACKET = 0xE7;
|
||||
|
||||
/*
|
||||
* 0xE8 : unassigned
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Nokia/Ericsson definitions
|
||||
*/
|
||||
public final static int VK_OEM_RESET = 0xE9;
|
||||
public final static int VK_OEM_JUMP = 0xEA;
|
||||
public final static int VK_OEM_PA1 = 0xEB;
|
||||
public final static int VK_OEM_PA2 = 0xEC;
|
||||
public final static int VK_OEM_PA3 = 0xED;
|
||||
public final static int VK_OEM_WSCTRL = 0xEE;
|
||||
public final static int VK_OEM_CUSEL = 0xEF;
|
||||
public final static int VK_OEM_ATTN = 0xF0;
|
||||
public final static int VK_OEM_FINISH = 0xF1;
|
||||
public final static int VK_OEM_COPY = 0xF2;
|
||||
public final static int VK_OEM_AUTO = 0xF3;
|
||||
public final static int VK_OEM_ENLW = 0xF4;
|
||||
public final static int VK_OEM_BACKTAB = 0xF5;
|
||||
public static final int VK_OEM_RESET = 0xE9;
|
||||
public static final int VK_OEM_JUMP = 0xEA;
|
||||
public static final int VK_OEM_PA1 = 0xEB;
|
||||
public static final int VK_OEM_PA2 = 0xEC;
|
||||
public static final int VK_OEM_PA3 = 0xED;
|
||||
public static final int VK_OEM_WSCTRL = 0xEE;
|
||||
public static final int VK_OEM_CUSEL = 0xEF;
|
||||
public static final int VK_OEM_ATTN = 0xF0;
|
||||
public static final int VK_OEM_FINISH = 0xF1;
|
||||
public static final int VK_OEM_COPY = 0xF2;
|
||||
public static final int VK_OEM_AUTO = 0xF3;
|
||||
public static final int VK_OEM_ENLW = 0xF4;
|
||||
public static final int VK_OEM_BACKTAB = 0xF5;
|
||||
|
||||
public final static int VK_ATTN = 0xF6;
|
||||
public final static int VK_CRSEL = 0xF7;
|
||||
public final static int VK_EXSEL = 0xF8;
|
||||
public final static int VK_EREOF = 0xF9;
|
||||
public final static int VK_PLAY = 0xFA;
|
||||
public final static int VK_ZOOM = 0xFB;
|
||||
public final static int VK_NONAME = 0xFC;
|
||||
public final static int VK_PA1 = 0xFD;
|
||||
public final static int VK_OEM_CLEAR = 0xFE;
|
||||
public static final int VK_ATTN = 0xF6;
|
||||
public static final int VK_CRSEL = 0xF7;
|
||||
public static final int VK_EXSEL = 0xF8;
|
||||
public static final int VK_EREOF = 0xF9;
|
||||
public static final int VK_PLAY = 0xFA;
|
||||
public static final int VK_ZOOM = 0xFB;
|
||||
public static final int VK_NONAME = 0xFC;
|
||||
public static final int VK_PA1 = 0xFD;
|
||||
public static final int VK_OEM_CLEAR = 0xFE;
|
||||
|
||||
public static int mapVirtualKeyToLWJGLCode(int virt_key) {
|
||||
switch (virt_key) {
|
||||
|
|
|
|||
|
|
@ -40,15 +40,15 @@ import org.lwjgl.LWJGLException;
|
|||
import org.lwjgl.Sys;
|
||||
|
||||
final class WindowsRegistry {
|
||||
final static int HKEY_CLASSES_ROOT = 1;
|
||||
final static int HKEY_CURRENT_USER = 2;
|
||||
final static int HKEY_LOCAL_MACHINE = 3;
|
||||
final static int HKEY_USERS = 4;
|
||||
static final int HKEY_CLASSES_ROOT = 1;
|
||||
static final int HKEY_CURRENT_USER = 2;
|
||||
static final int HKEY_LOCAL_MACHINE = 3;
|
||||
static final int HKEY_USERS = 4;
|
||||
|
||||
static {
|
||||
Sys.initialize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Query the registry value specified by the root key, subkey, value tuple
|
||||
*/
|
||||
|
|
@ -64,6 +64,6 @@ final class WindowsRegistry {
|
|||
}
|
||||
return nQueryRegistrationKey(root_key, subkey, value);
|
||||
}
|
||||
|
||||
|
||||
private static native String nQueryRegistrationKey(int root_key, String subkey, String value) throws LWJGLException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,20 +42,20 @@ import org.lwjgl.LWJGLUtil;
|
|||
/**
|
||||
* Utility for working with the xrandr commmand-line utility. Assumes
|
||||
* xrandr v1.2 or higher.
|
||||
*
|
||||
*
|
||||
* @author ryanm
|
||||
*/
|
||||
public class XRandR
|
||||
{
|
||||
private static Screen[] current;
|
||||
|
||||
private static Map /* <String, Screen[]> */screens;
|
||||
private static Map<String, Screen[]> screens;
|
||||
|
||||
private static void populate()
|
||||
{
|
||||
if( screens == null )
|
||||
{
|
||||
screens = new HashMap/* <String, Screen[]> */();
|
||||
screens = new HashMap<String, Screen[]>();
|
||||
|
||||
// ProcessBuilder pb = new ProcessBuilder( "xrandr", "-q" );
|
||||
// pb.redirectErrorStream();
|
||||
|
|
@ -64,8 +64,8 @@ public class XRandR
|
|||
// Process p= pb.start();
|
||||
Process p = Runtime.getRuntime().exec( new String[] { "xrandr", "-q" } );
|
||||
|
||||
List/* <Screen> */currentList = new ArrayList/* <Screen> */();
|
||||
List/* <Screen> */possibles = new ArrayList/* <Screen> */();
|
||||
List<Screen> currentList = new ArrayList<Screen>();
|
||||
List<Screen> possibles = new ArrayList<Screen>();
|
||||
String name = null;
|
||||
|
||||
BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
|
||||
|
|
@ -75,7 +75,7 @@ public class XRandR
|
|||
line = line.trim();
|
||||
String[] sa = line.split( "\\s+" );
|
||||
|
||||
if( sa[ 1 ].equals( "connected" ) )
|
||||
if( "connected".equals(sa[1]) )
|
||||
{
|
||||
// found a new screen block
|
||||
if( name != null )
|
||||
|
|
@ -97,7 +97,7 @@ public class XRandR
|
|||
|
||||
screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) );
|
||||
|
||||
current = (Screen[]) currentList.toArray(new Screen[currentList.size()]);
|
||||
current = currentList.toArray(new Screen[currentList.size()]);
|
||||
}
|
||||
catch( Throwable e )
|
||||
{
|
||||
|
|
@ -116,7 +116,7 @@ public class XRandR
|
|||
{
|
||||
populate();
|
||||
|
||||
return (Screen[]) current.clone();
|
||||
return current.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -125,42 +125,34 @@ public class XRandR
|
|||
* @throws IllegalArgumentException
|
||||
* if no screens are specified
|
||||
*/
|
||||
public static void setConfiguration( Screen[]/* ... */screens )
|
||||
public static void setConfiguration(Screen... screens)
|
||||
{
|
||||
if( screens.length == 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "Must specify at least one screen" );
|
||||
}
|
||||
|
||||
List/* <String> */cmd = new ArrayList/* <String> */();
|
||||
List<String> cmd = new ArrayList<String>();
|
||||
cmd.add( "xrandr" );
|
||||
|
||||
// switch off those in the current set not in the new set
|
||||
for( int i = 0; i < current.length; i++ )
|
||||
{
|
||||
for ( Screen screen : current ) {
|
||||
boolean found = false;
|
||||
for( int j = 0; j < screens.length; j++ )
|
||||
{
|
||||
if( screens[ j ].name.equals( current[ i ].name ) )
|
||||
{
|
||||
for ( Screen screen1 : screens ) {
|
||||
if ( screen1.name.equals(screen.name) ) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !found )
|
||||
{
|
||||
cmd.add( "--output" );
|
||||
cmd.add( current[ i ].name );
|
||||
cmd.add( "--off" );
|
||||
if ( !found ) {
|
||||
cmd.add("--output");
|
||||
cmd.add(screen.name);
|
||||
cmd.add("--off");
|
||||
}
|
||||
}
|
||||
|
||||
// set up new set
|
||||
for( int i = 0; i < screens.length; i++ )
|
||||
{
|
||||
screens[ i ].getArgs( cmd );
|
||||
}
|
||||
for ( Screen screen : screens )
|
||||
screen.getArgs(cmd);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -168,7 +160,7 @@ public class XRandR
|
|||
// pb.redirectErrorStream();
|
||||
// Process p = pb.start();
|
||||
Process p =
|
||||
Runtime.getRuntime().exec( ( String[] ) cmd.toArray( new String[ cmd.size() ] ) );
|
||||
Runtime.getRuntime().exec( cmd.toArray( new String[ cmd.size() ] ) );
|
||||
// no output is expected, but check anyway
|
||||
BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
|
||||
String line;
|
||||
|
|
@ -191,7 +183,7 @@ public class XRandR
|
|||
public static String[] getScreenNames()
|
||||
{
|
||||
populate();
|
||||
return ( String[] ) screens.keySet().toArray( new String[ screens.size() ] );
|
||||
return screens.keySet().toArray( new String[ screens.size() ] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -203,7 +195,7 @@ public class XRandR
|
|||
{
|
||||
populate();
|
||||
// clone the array to prevent held copies being altered
|
||||
return (Screen[]) ((Screen[]) screens.get(name)).clone();
|
||||
return screens.get(name).clone();
|
||||
}
|
||||
|
||||
private static final Pattern SCREEN_PATTERN1 =
|
||||
|
|
@ -214,7 +206,7 @@ public class XRandR
|
|||
/**
|
||||
* Parses a screen configuration and adds it to the list if it's
|
||||
* valid.
|
||||
*
|
||||
*
|
||||
* @param list
|
||||
* the list to add the Screen to if it's valid
|
||||
* @param name
|
||||
|
|
@ -223,7 +215,7 @@ public class XRandR
|
|||
* config string, format either widthxheight or
|
||||
* widthxheight+xPos+yPos
|
||||
*/
|
||||
private static void parseScreen( List /* <Screen> */list, String name, String what )
|
||||
private static void parseScreen( List<Screen> list, String name, String what )
|
||||
{
|
||||
Matcher m = SCREEN_PATTERN1.matcher( what );
|
||||
if( !m.matches() )
|
||||
|
|
@ -254,7 +246,7 @@ public class XRandR
|
|||
/**
|
||||
* Encapsulates the configuration of a monitor. Resolution is
|
||||
* fixed, position is mutable
|
||||
*
|
||||
*
|
||||
* @author ryanm
|
||||
*/
|
||||
public static class Screen implements Cloneable
|
||||
|
|
@ -277,12 +269,12 @@ public class XRandR
|
|||
/**
|
||||
* Position on the x-axis, in pixels
|
||||
*/
|
||||
public int xPos = 0;
|
||||
public int xPos;
|
||||
|
||||
/**
|
||||
* Position on the y-axis, in pixels
|
||||
*/
|
||||
public int yPos = 0;
|
||||
public int yPos;
|
||||
|
||||
private Screen( String name, int width, int height, int xPos, int yPos )
|
||||
{
|
||||
|
|
@ -293,7 +285,7 @@ public class XRandR
|
|||
this.yPos = yPos;
|
||||
}
|
||||
|
||||
private void getArgs( List/* <String> */argList )
|
||||
private void getArgs( List<String> argList )
|
||||
{
|
||||
argList.add( "--output" );
|
||||
argList.add( name );
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -44,13 +44,13 @@ import org.lwjgl.opengl.DisplayMode;
|
|||
* $Id$
|
||||
*/
|
||||
public class DisplayTest {
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new DisplayTest
|
||||
*/
|
||||
public DisplayTest() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs the tests
|
||||
*/
|
||||
|
|
@ -58,31 +58,31 @@ public class DisplayTest {
|
|||
currentTest();
|
||||
queryModesTest();
|
||||
setDisplayModeTest();
|
||||
setDisplayConfigurationTest();
|
||||
setDisplayConfigurationTest();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints some info about the current mode
|
||||
*/
|
||||
private void currentTest() {
|
||||
System.out.println("==== Test Current ====");
|
||||
|
||||
|
||||
System.out.println("Info about current:");
|
||||
System.out.println("Graphics card: " + Display.getAdapter() + ", version: " + Display.getVersion());
|
||||
System.out.println("Resolution: " +
|
||||
Display.getDisplayMode().getWidth() + "x" +
|
||||
Display.getDisplayMode().getHeight() + "x" +
|
||||
Display.getDisplayMode().getBitsPerPixel() + "@" +
|
||||
System.out.println("Resolution: " +
|
||||
Display.getDisplayMode().getWidth() + "x" +
|
||||
Display.getDisplayMode().getHeight() + "x" +
|
||||
Display.getDisplayMode().getBitsPerPixel() + "@" +
|
||||
Display.getDisplayMode().getFrequency() + "Hz");
|
||||
System.out.println("---- Test Current ----");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests querying for modes
|
||||
*/
|
||||
private void queryModesTest() throws LWJGLException {
|
||||
DisplayMode[] modes = null;
|
||||
|
||||
|
||||
System.out.println("==== Test query ====");
|
||||
System.out.println("Retrieving available displaymodes");
|
||||
modes = Display.getAvailableDisplayModes();
|
||||
|
|
@ -92,7 +92,7 @@ public class DisplayTest {
|
|||
System.out.println("FATAL: unable to find any modes!");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
// write some info
|
||||
System.out.println("Found " + modes.length + " modes");
|
||||
System.out.println("The first 5 are:");
|
||||
|
|
@ -104,42 +104,42 @@ public class DisplayTest {
|
|||
}
|
||||
System.out.println("---- Test query ----");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tests setting display modes
|
||||
*/
|
||||
private void setDisplayModeTest() throws LWJGLException {
|
||||
DisplayMode mode = null;
|
||||
DisplayMode[] modes = null;
|
||||
|
||||
|
||||
System.out.println("==== Test setDisplayMode ====");
|
||||
System.out.println("Retrieving available displaymodes");
|
||||
modes = Display.getAvailableDisplayModes();
|
||||
|
||||
|
||||
// no modes check
|
||||
if (modes == null) {
|
||||
System.out.println("FATAL: unable to find any modes!");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
// find a mode
|
||||
System.out.print("Looking for 640x480...");
|
||||
for(int i=0; i<modes.length;i++) {
|
||||
if (modes[i].getWidth() == 640 &&
|
||||
modes[i].getHeight() == 480) {
|
||||
mode = modes[i];
|
||||
System.out.println("found!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for ( DisplayMode mode1 : modes ) {
|
||||
if ( mode1.getWidth() == 640 &&
|
||||
mode1.getHeight() == 480 ) {
|
||||
mode = mode1;
|
||||
System.out.println("found!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// no mode check
|
||||
if (mode == null) {
|
||||
System.out.println("error\nFATAL: Unable to find basic mode.");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
// change to mode, and wait a bit
|
||||
System.out.print("Changing to mode...");
|
||||
try {
|
||||
|
|
@ -151,13 +151,13 @@ public class DisplayTest {
|
|||
System.exit(-1);
|
||||
}
|
||||
System.out.println("done");
|
||||
|
||||
System.out.println("Resolution: " +
|
||||
Display.getDisplayMode().getWidth() + "x" +
|
||||
Display.getDisplayMode().getHeight() + "x" +
|
||||
Display.getDisplayMode().getBitsPerPixel() + "@" +
|
||||
|
||||
System.out.println("Resolution: " +
|
||||
Display.getDisplayMode().getWidth() + "x" +
|
||||
Display.getDisplayMode().getHeight() + "x" +
|
||||
Display.getDisplayMode().getBitsPerPixel() + "@" +
|
||||
Display.getDisplayMode().getFrequency() + "Hz");
|
||||
|
||||
|
||||
pause(5000);
|
||||
|
||||
// reset
|
||||
|
|
@ -168,34 +168,34 @@ public class DisplayTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("done");
|
||||
|
||||
System.out.println("---- Test setDisplayMode ----");
|
||||
|
||||
System.out.println("---- Test setDisplayMode ----");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the DisplayConfiguration
|
||||
*/
|
||||
private void setDisplayConfigurationTest() {
|
||||
System.out.println("==== Test setDisplayConfigurationTest ====");
|
||||
|
||||
|
||||
System.out.println("Testing normal setting");
|
||||
changeConfig(1.0f, 0f, 1f);
|
||||
|
||||
|
||||
System.out.println("Testing gamma settings");
|
||||
changeConfig(5.0f, 0f, 1f);
|
||||
changeConfig(0.5f, 0f, 1f);
|
||||
|
||||
|
||||
System.out.println("Testing brightness settings");
|
||||
changeConfig(1.0f, -1.0f, 1f);
|
||||
changeConfig(1.0f, -0.5f, 1f);
|
||||
changeConfig(1.0f, 0.5f, 1f);
|
||||
changeConfig(1.0f, 1.0f, 1f);
|
||||
|
||||
|
||||
System.out.println("Testing contrast settings");
|
||||
changeConfig(1.0f, 0f, 0f);
|
||||
changeConfig(1.0f, 0f, 0.5f);
|
||||
changeConfig(1.0f, 0f, 10000.0f);
|
||||
|
||||
|
||||
System.out.print("resetting...");
|
||||
try {
|
||||
Display.setFullscreen(false);
|
||||
|
|
@ -203,13 +203,13 @@ public class DisplayTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("done");
|
||||
|
||||
|
||||
System.out.println("---- Test setDisplayConfigurationTest ----");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Changes the Displat configuration
|
||||
*
|
||||
*
|
||||
* @param gamma gamma value to change to
|
||||
* @param brightness brightness value to change to
|
||||
* @param contrast contrast value to change to
|
||||
|
|
@ -226,7 +226,7 @@ public class DisplayTest {
|
|||
|
||||
/**
|
||||
* Pause current thread for a specified time
|
||||
*
|
||||
*
|
||||
* @param time milliseconds to sleep
|
||||
*/
|
||||
private void pause(long time) {
|
||||
|
|
@ -238,11 +238,11 @@ public class DisplayTest {
|
|||
} catch (InterruptedException inte) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Sys class, and serves as basic usage test
|
||||
*
|
||||
*
|
||||
* @param args ignored
|
||||
*/
|
||||
public static void main(String[] args) throws LWJGLException {
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -37,26 +37,28 @@ import org.lwjgl.opengl.Display;
|
|||
import org.lwjgl.opengl.DisplayMode;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
/**
|
||||
* Small class for testing that the Window is creatable
|
||||
* If this class can't run, LWJGL wont work!
|
||||
*
|
||||
*
|
||||
* @author Brian Matzon <brian@matzon.dk>
|
||||
*/
|
||||
public class WindowCreationTest {
|
||||
|
||||
/** Locatable modes */
|
||||
private DisplayMode[] located_modes;
|
||||
|
||||
|
||||
/** Fixed selectable modes */
|
||||
private DisplayMode[] fixed_modes = new DisplayMode[10];
|
||||
|
||||
|
||||
|
||||
/** Window position x */
|
||||
private int window_x = 0;
|
||||
private int window_x;
|
||||
|
||||
/** Window position y */
|
||||
private int window_y = 0;
|
||||
private int window_y;
|
||||
|
||||
/** Color being cleared to */
|
||||
private float color = 0f;
|
||||
|
|
@ -65,13 +67,13 @@ public class WindowCreationTest {
|
|||
private int direction = 1;
|
||||
|
||||
/** Whether we're running */
|
||||
private boolean running = false;
|
||||
private boolean running;
|
||||
|
||||
/** Whether we're in fullscreen mode */
|
||||
private boolean fullscreen = false;
|
||||
|
||||
private boolean fullscreen;
|
||||
|
||||
/**
|
||||
* Initializes the test
|
||||
* Initializes the test
|
||||
* @return true if initialization was successfull
|
||||
*/
|
||||
public boolean initialize() {
|
||||
|
|
@ -79,16 +81,16 @@ public class WindowCreationTest {
|
|||
// get available modes, and print out
|
||||
located_modes = Display.getAvailableDisplayModes();
|
||||
System.out.println("Found " + located_modes.length + " display modes");
|
||||
|
||||
|
||||
// get 640x480, 800x600, 1024x768 modes
|
||||
findFixedModes();
|
||||
|
||||
// create default windowed display 640*480 @ 100, 100
|
||||
setDefaultDisplayMode();
|
||||
|
||||
|
||||
window_x = window_y = 100;
|
||||
Display.setLocation(window_x, window_y);
|
||||
|
||||
|
||||
Display.create();
|
||||
return true;
|
||||
} catch (LWJGLException le) {
|
||||
|
|
@ -96,7 +98,7 @@ public class WindowCreationTest {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/** Locate fixed modes */
|
||||
private void findFixedModes() {
|
||||
// get 640*480 modes
|
||||
|
|
@ -151,7 +153,7 @@ public class WindowCreationTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Handles the input
|
||||
* Handles the input
|
||||
*/
|
||||
private void handleInput() {
|
||||
while (Keyboard.next()) {
|
||||
|
|
@ -165,14 +167,14 @@ public class WindowCreationTest {
|
|||
if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
|
||||
running = false;
|
||||
}
|
||||
|
||||
|
||||
// check for listing of modes
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_L) {
|
||||
for(int i=0;i<fixed_modes.length; i++) {
|
||||
System.out.println("[" + i + "]: " + fixed_modes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check for display mode
|
||||
// ================================
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_0) { setMode(0); }
|
||||
|
|
@ -181,7 +183,7 @@ public class WindowCreationTest {
|
|||
if (Keyboard.getEventKey() == Keyboard.KEY_3) { setMode(3); }
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_4) { setMode(4); }
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_5) { setMode(5); }
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_6) { setMode(6); }
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_6) { setMode(6); }
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_7) { setMode(7); }
|
||||
if (Keyboard.getEventKey() == Keyboard.KEY_8) { setMode(8); }
|
||||
// --------------------------------
|
||||
|
|
@ -232,13 +234,13 @@ public class WindowCreationTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setMode(int mode) {
|
||||
if(fixed_modes[mode] == null) {
|
||||
System.out.println("Unable to set mode. Not valid: " + mode);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Display.setDisplayMode(fixed_modes[mode]);
|
||||
} catch (LWJGLException le) {
|
||||
|
|
@ -251,8 +253,8 @@ public class WindowCreationTest {
|
|||
*
|
||||
*/
|
||||
private void render() {
|
||||
GL11.glClearColor(color, color, color, 1f);
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
glClearColor(color, color, color, 1f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
color += direction * .05f;
|
||||
|
||||
|
|
@ -267,19 +269,19 @@ public class WindowCreationTest {
|
|||
|
||||
/**
|
||||
* Main entry point
|
||||
*
|
||||
*
|
||||
* @param args ignored params to app
|
||||
*/
|
||||
public static void main(String[] args) throws LWJGLException {
|
||||
|
||||
|
||||
System.out.println("The following keys are available:\n" +
|
||||
"ESCAPE:\t\tExit test\n" +
|
||||
"ESCAPE:\t\tExit test\n" +
|
||||
"ARROW Keys:\tMove window when in non-fullscreen mode\n" +
|
||||
"L:\t\tList selectable display modes\n" +
|
||||
"0-8:\t\tSelection of display modes\n" +
|
||||
"0-8:\t\tSelection of display modes\n" +
|
||||
"F:\t\tToggle fullscreen\n" +
|
||||
"SHIFT-F:\tToggle fullscreen with Display.destroy()/create() cycle");
|
||||
|
||||
|
||||
WindowCreationTest wct = new WindowCreationTest();
|
||||
if (wct.initialize()) {
|
||||
wct.execute();
|
||||
|
|
@ -304,9 +306,9 @@ public class WindowCreationTest {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a specific display mode
|
||||
|
||||
/**
|
||||
* Gets a specific display mode
|
||||
*/
|
||||
private DisplayMode getDisplayMode(int width, int height, int bpp, int freq) {
|
||||
DisplayMode[] dm = null;
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -36,8 +36,8 @@ import java.awt.BorderLayout;
|
|||
import java.awt.Canvas;
|
||||
|
||||
public class AppletLoaderTest extends Applet {
|
||||
|
||||
Test test = null;
|
||||
|
||||
Test test;
|
||||
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
|
|
@ -57,7 +57,7 @@ public class AppletLoaderTest extends Applet {
|
|||
|
||||
public void init() {
|
||||
System.out.println("*** init ***");
|
||||
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
try {
|
||||
test = (Test) Class.forName(getParameter("test")).newInstance();
|
||||
|
|
|
|||
|
|
@ -8,42 +8,43 @@ import org.lwjgl.BufferUtils;
|
|||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
import org.lwjgl.Sys;
|
||||
import org.lwjgl.opengl.ARBTransposeMatrix;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GLContext;
|
||||
|
||||
import static org.lwjgl.opengl.ARBTransposeMatrix.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class GearsApplet extends Applet {
|
||||
|
||||
|
||||
/** The Canvas where the LWJGL Display is added */
|
||||
Canvas display_parent;
|
||||
|
||||
|
||||
/** Thread which runs the main game loop */
|
||||
Thread gameThread;
|
||||
|
||||
|
||||
/** is the game loop running */
|
||||
boolean running = false;
|
||||
|
||||
boolean running;
|
||||
|
||||
/** variables used to rotate the view */
|
||||
private float view_rotx = 20.0f;
|
||||
private float view_roty = 30.0f;
|
||||
private float view_rotz = 0.0f;
|
||||
|
||||
private float view_rotz;
|
||||
|
||||
private int gear1;
|
||||
private int gear2;
|
||||
private int gear3;
|
||||
private float angle;
|
||||
|
||||
boolean keyDown = false;
|
||||
|
||||
|
||||
boolean keyDown;
|
||||
|
||||
private int prevMouseX, prevMouseY;
|
||||
private boolean mouseButtonDown = false;
|
||||
|
||||
|
||||
private boolean mouseButtonDown;
|
||||
|
||||
|
||||
/**
|
||||
* Once the Canvas is created its add notify method will call this method to
|
||||
* Once the Canvas is created its add notify method will call this method to
|
||||
* start the LWJGL Display and game loop in another thread.
|
||||
*/
|
||||
public void startLWJGL() {
|
||||
|
|
@ -63,8 +64,8 @@ public class GearsApplet extends Applet {
|
|||
};
|
||||
gameThread.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tell game loop to stop running, after which the LWJGL Display will be destoryed.
|
||||
* The main thread will wait for the Display.destroy() to complete
|
||||
|
|
@ -79,15 +80,15 @@ public class GearsApplet extends Applet {
|
|||
}
|
||||
|
||||
public void start() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Applet Destroy method will remove the canvas, before canvas is destroyed it will notify
|
||||
* Applet Destroy method will remove the canvas, before canvas is destroyed it will notify
|
||||
* stopLWJGL() to stop main game loop and to destroy the Display
|
||||
*/
|
||||
public void destroy() {
|
||||
|
|
@ -95,21 +96,21 @@ public class GearsApplet extends Applet {
|
|||
super.destroy();
|
||||
System.out.println("Clear up");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
|
||||
* in another thread. It will also stop the game loop and destroy the display on canvas removal when
|
||||
* in another thread. It will also stop the game loop and destroy the display on canvas removal when
|
||||
* applet is destroyed.
|
||||
*/
|
||||
public void init() {
|
||||
setLayout(new BorderLayout());
|
||||
try {
|
||||
display_parent = new Canvas() {
|
||||
public final void addNotify() {
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
startLWJGL();
|
||||
}
|
||||
public final void removeNotify() {
|
||||
public void removeNotify() {
|
||||
stopLWJGL();
|
||||
super.removeNotify();
|
||||
}
|
||||
|
|
@ -133,22 +134,22 @@ public class GearsApplet extends Applet {
|
|||
|
||||
while(running) {
|
||||
angle += 2.0f;
|
||||
|
||||
|
||||
// draw the gears
|
||||
drawLoop();
|
||||
|
||||
|
||||
Display.update();
|
||||
|
||||
|
||||
if (startTime > System.currentTimeMillis()) {
|
||||
fps++;
|
||||
} else {
|
||||
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
|
||||
startTime = System.currentTimeMillis() + 5000;
|
||||
System.out.println(fps + " frames 2 in " + (float) (timeUsed / 1000f) + " seconds = "
|
||||
System.out.println(fps + " frames 2 in " + timeUsed / 1000f + " seconds = "
|
||||
+ (fps / (timeUsed / 1000f)));
|
||||
fps = 0;
|
||||
}
|
||||
|
||||
|
||||
if (Mouse.isButtonDown(0)) {
|
||||
if (!mouseButtonDown) {
|
||||
prevMouseX = Mouse.getX();
|
||||
|
|
@ -159,25 +160,25 @@ public class GearsApplet extends Applet {
|
|||
else {
|
||||
mouseButtonDown = false;
|
||||
}
|
||||
|
||||
|
||||
if (mouseButtonDown) {
|
||||
int x = Mouse.getX();
|
||||
int y = Mouse.getY();
|
||||
|
||||
|
||||
float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)display_parent.getWidth());
|
||||
float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)display_parent.getHeight());
|
||||
|
||||
|
||||
prevMouseX = x;
|
||||
prevMouseY = y;
|
||||
|
||||
|
||||
view_rotx += thetaX;
|
||||
view_roty += thetaY;
|
||||
}
|
||||
|
||||
|
||||
// F Key Pressed (i.e. released)
|
||||
if (keyDown && !Keyboard.isKeyDown(Keyboard.KEY_F)) {
|
||||
keyDown = false;
|
||||
|
||||
|
||||
try {
|
||||
if (Display.isFullscreen()) {
|
||||
Display.setFullscreen(false);
|
||||
|
|
@ -190,38 +191,38 @@ public class GearsApplet extends Applet {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Display.destroy();
|
||||
}
|
||||
|
||||
|
||||
public void drawLoop() {
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
|
||||
GL11.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
|
||||
GL11.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
|
||||
GL11.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(-3.0f, -2.0f, 0.0f);
|
||||
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
|
||||
GL11.glCallList(gear1);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(3.1f, -2.0f, 0.0f);
|
||||
GL11.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
|
||||
GL11.glCallList(gear2);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(-3.1f, 4.2f, 0.0f);
|
||||
GL11.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
|
||||
GL11.glCallList(gear3);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glPopMatrix();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
|
||||
glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.0f, -2.0f, 0.0f);
|
||||
glRotatef(angle, 0.0f, 0.0f, 1.0f);
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(3.1f, -2.0f, 0.0f);
|
||||
glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.1f, 4.2f, 0.0f);
|
||||
glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
protected void initGL() {
|
||||
|
|
@ -231,62 +232,62 @@ public class GearsApplet extends Applet {
|
|||
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();
|
||||
|
||||
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos);
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_LIGHT0);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
glLight(GL_LIGHT0, GL_POSITION, pos);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* make the gears */
|
||||
gear1 = GL11.glGenLists(1);
|
||||
GL11.glNewList(gear1, GL11.GL_COMPILE);
|
||||
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
|
||||
GL11.glEndList();
|
||||
|
||||
gear2 = GL11.glGenLists(1);
|
||||
GL11.glNewList(gear2, GL11.GL_COMPILE);
|
||||
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, green);
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
|
||||
gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
|
||||
GL11.glEndList();
|
||||
|
||||
gear3 = GL11.glGenLists(1);
|
||||
GL11.glNewList(gear3, GL11.GL_COMPILE);
|
||||
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, blue);
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
|
||||
gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
|
||||
GL11.glEndList();
|
||||
GL11.glEnable(GL11.GL_NORMALIZE);
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
|
||||
glEndList();
|
||||
glEnable(GL_NORMALIZE);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
||||
System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName());
|
||||
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));
|
||||
System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
|
||||
System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
|
||||
System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
|
||||
System.err.println();
|
||||
System.err.println("glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix);
|
||||
|
||||
|
||||
if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
|
||||
// --- not using extensions
|
||||
GL11.glLoadIdentity();
|
||||
glLoadIdentity();
|
||||
} else {
|
||||
// --- using extensions
|
||||
final FloatBuffer identityTranspose = BufferUtils.createFloatBuffer(16).put(
|
||||
new float[] { 1, 0, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 1, 0, 0, 0, 0, 1});
|
||||
identityTranspose.flip();
|
||||
ARBTransposeMatrix.glLoadTransposeMatrixARB(identityTranspose);
|
||||
glLoadTransposeMatrixARB(identityTranspose);
|
||||
}
|
||||
float h = (float) display_parent.getHeight() / (float) display_parent.getWidth();
|
||||
GL11.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glTranslatef(0.0f, 0.0f, -40.0f);
|
||||
glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0f, 0.0f, -40.0f);
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
running = false;
|
||||
|
|
@ -313,92 +314,92 @@ public class GearsApplet extends Applet {
|
|||
r1 = outer_radius - tooth_depth / 2.0f;
|
||||
r2 = outer_radius + tooth_depth / 2.0f;
|
||||
da = 2.0f * (float) Math.PI / teeth / 4.0f;
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
|
||||
glShadeModel(GL_FLAT);
|
||||
glNormal3f(0.0f, 0.0f, 1.0f);
|
||||
/* draw front face */
|
||||
GL11.glBegin(GL11.GL_QUAD_STRIP);
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
|
||||
glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
|
||||
if (i < teeth) {
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da),
|
||||
glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da),
|
||||
width * 0.5f);
|
||||
}
|
||||
}
|
||||
GL11.glEnd();
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
glBegin(GL_QUADS);
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + 2.0f * da), r2 * (float) Math.sin(angle + 2.0f * da), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
|
||||
glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
|
||||
glVertex3f(r2 * (float) Math.cos(angle + 2.0f * da), r2 * (float) Math.sin(angle + 2.0f * da), width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f);
|
||||
}
|
||||
GL11.glEnd();
|
||||
glEnd();
|
||||
|
||||
/* draw back face */
|
||||
GL11.glBegin(GL11.GL_QUAD_STRIP);
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
|
||||
glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
|
||||
glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
|
||||
}
|
||||
GL11.glEnd();
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
glBegin(GL_QUADS);
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
|
||||
glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
|
||||
glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
|
||||
}
|
||||
GL11.glEnd();
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
GL11.glBegin(GL11.GL_QUAD_STRIP);
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f);
|
||||
u = r2 * (float) Math.cos(angle + da) - r1 * (float) Math.cos(angle);
|
||||
v = r2 * (float) Math.sin(angle + da) - r1 * (float) Math.sin(angle);
|
||||
len = (float) Math.sqrt(u * u + v * v);
|
||||
u /= len;
|
||||
v /= len;
|
||||
GL11.glNormal3f(v, -u, 0.0f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
|
||||
GL11.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), width * 0.5f);
|
||||
GL11.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
|
||||
glNormal3f(v, -u, 0.0f);
|
||||
glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f);
|
||||
glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f);
|
||||
glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
|
||||
glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), width * 0.5f);
|
||||
glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f);
|
||||
u = r1 * (float) Math.cos(angle + 3 * da) - r2 * (float) Math.cos(angle + 2 * da);
|
||||
v = r1 * (float) Math.sin(angle + 3 * da) - r2 * (float) Math.sin(angle + 2 * da);
|
||||
GL11.glNormal3f(v, -u, 0.0f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
|
||||
GL11.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
|
||||
glNormal3f(v, -u, 0.0f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f);
|
||||
glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f);
|
||||
}
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), width * 0.5f);
|
||||
GL11.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), -width * 0.5f);
|
||||
GL11.glEnd();
|
||||
glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), width * 0.5f);
|
||||
glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), -width * 0.5f);
|
||||
glEnd();
|
||||
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
/* draw inside radius cylinder */
|
||||
GL11.glBegin(GL11.GL_QUAD_STRIP);
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0f * (float) Math.PI / teeth;
|
||||
GL11.glNormal3f(-(float) Math.cos(angle), -(float) Math.sin(angle), 0.0f);
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
|
||||
GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
|
||||
glNormal3f(-(float) Math.cos(angle), -(float) Math.sin(angle), 0.0f);
|
||||
glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f);
|
||||
glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f);
|
||||
}
|
||||
GL11.glEnd();
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -39,26 +39,27 @@ import org.lwjgl.openal.AL;
|
|||
import org.lwjgl.openal.AL10;
|
||||
import org.lwjgl.opengl.AWTGLCanvas;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.WaveData;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class OpenAL extends AWTGLCanvas implements Test {
|
||||
|
||||
float angle = 0;
|
||||
|
||||
float angle;
|
||||
|
||||
// create 1 buffer and 1 source
|
||||
IntBuffer buffers = BufferUtils.createIntBuffer(1);
|
||||
IntBuffer sources = BufferUtils.createIntBuffer(1);
|
||||
IntBuffer sources = BufferUtils.createIntBuffer(1);
|
||||
|
||||
public OpenAL() throws LWJGLException {
|
||||
|
||||
|
||||
try {
|
||||
AL.create();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Unable to create OpenAL.\nPlease make sure that OpenAL is available on this system. Exception: " + e);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Thread t = new Thread() {
|
||||
|
||||
public void run() {
|
||||
|
|
@ -75,7 +76,7 @@ public class OpenAL extends AWTGLCanvas implements Test {
|
|||
|
||||
private void playOpenAL() {
|
||||
int lastError;
|
||||
|
||||
|
||||
// al generate buffers and sources
|
||||
buffers.position(0).limit(1);
|
||||
AL10.alGenBuffers(buffers);
|
||||
|
|
@ -88,37 +89,37 @@ public class OpenAL extends AWTGLCanvas implements Test {
|
|||
if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
|
||||
exit(lastError);
|
||||
}
|
||||
|
||||
|
||||
// load wave data from buffer
|
||||
WaveData wavefile = WaveData.create(getClass().getClassLoader().getResourceAsStream("Footsteps.wav"));
|
||||
|
||||
//copy to buffers
|
||||
AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate);
|
||||
|
||||
|
||||
//unload file again
|
||||
wavefile.dispose();
|
||||
|
||||
wavefile.dispose();
|
||||
|
||||
if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
|
||||
exit(lastError);
|
||||
}
|
||||
}
|
||||
|
||||
//set up source input
|
||||
AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
|
||||
if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
|
||||
exit(lastError);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//lets loop the sound
|
||||
AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
|
||||
if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
|
||||
exit(lastError);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//play source 0
|
||||
AL10.alSourcePlay(sources.get(0));
|
||||
if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
|
||||
exit(lastError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void exit(int error) {
|
||||
|
|
@ -126,22 +127,22 @@ public class OpenAL extends AWTGLCanvas implements Test {
|
|||
}
|
||||
|
||||
public void paintGL() {
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glOrtho(0, 640, 0, 480, 1, -1);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glMatrixMode(GL_PROJECTION_MATRIX);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, 640, 0, 480, 1, -1);
|
||||
glMatrixMode(GL_MODELVIEW_MATRIX);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(320, 240, 0.0f);
|
||||
GL11.glRotatef(angle, 0, 0, 1.0f);
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glVertex2i(-50, -50);
|
||||
GL11.glVertex2i(50, -50);
|
||||
GL11.glVertex2i(50, 50);
|
||||
GL11.glVertex2i(-50, 50);
|
||||
GL11.glEnd();
|
||||
GL11.glPopMatrix();
|
||||
glPushMatrix();
|
||||
glTranslatef(320, 240, 0.0f);
|
||||
glRotatef(angle, 0, 0, 1.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2i(-50, -50);
|
||||
glVertex2i(50, -50);
|
||||
glVertex2i(50, 50);
|
||||
glVertex2i(-50, 50);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
|
||||
angle += 1;
|
||||
|
||||
|
|
@ -152,31 +153,31 @@ public class OpenAL extends AWTGLCanvas implements Test {
|
|||
}
|
||||
|
||||
public void start() {
|
||||
playOpenAL();
|
||||
playOpenAL();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
int lastError;
|
||||
|
||||
|
||||
//stop source 0
|
||||
AL10.alSourceStop(sources.get(0));
|
||||
if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
|
||||
exit(lastError);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//delete buffers and sources
|
||||
sources.position(0).limit(1);
|
||||
AL10.alDeleteSources(sources);
|
||||
if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
|
||||
exit(lastError);
|
||||
}
|
||||
|
||||
|
||||
buffers.position(0).limit(1);
|
||||
AL10.alDeleteBuffers(buffers);
|
||||
if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
|
||||
exit(lastError);
|
||||
}
|
||||
|
||||
|
||||
AL.destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2002-2008 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
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
*
|
||||
* * 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
|
||||
* * 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
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -35,11 +35,12 @@ import org.lwjgl.LWJGLException;
|
|||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.AWTGLCanvas;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class OpenGL extends AWTGLCanvas implements Test {
|
||||
|
||||
float angle = 0;
|
||||
float angle;
|
||||
float x;
|
||||
float y;
|
||||
|
||||
|
|
@ -47,28 +48,28 @@ public class OpenGL extends AWTGLCanvas implements Test {
|
|||
}
|
||||
|
||||
public void initGL() {
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX);
|
||||
GL11.glLoadIdentity();
|
||||
GL11.glOrtho(0, 640, 0, 480, 1, -1);
|
||||
glMatrixMode(GL_PROJECTION_MATRIX);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, 640, 0, 480, 1, -1);
|
||||
x = 320;
|
||||
y = 240;
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX);
|
||||
glMatrixMode(GL_MODELVIEW_MATRIX);
|
||||
setVSyncEnabled(true);
|
||||
}
|
||||
|
||||
public void paintGL() {
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(x, y, 0.0f);
|
||||
GL11.glRotatef(angle, 0, 0, 1.0f);
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glVertex2i(-50, -50);
|
||||
GL11.glVertex2i(50, -50);
|
||||
GL11.glVertex2i(50, 50);
|
||||
GL11.glVertex2i(-50, 50);
|
||||
GL11.glEnd();
|
||||
GL11.glPopMatrix();
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, 0.0f);
|
||||
glRotatef(angle, 0, 0, 1.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2i(-50, -50);
|
||||
glVertex2i(50, -50);
|
||||
glVertex2i(50, 50);
|
||||
glVertex2i(-50, 50);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
|
||||
angle += 1;
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue