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:
Ioannis Tsakpinis 2010-09-28 21:11:35 +00:00
parent d17e13f24b
commit a8bcb7fd25
211 changed files with 7927 additions and 6549 deletions

111
build.xml
View File

@ -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" />
@ -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 &#169; 2002-2009 lwjgl.org. All Rights Reserved.</i>]]></bottom>

View File

@ -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">

View File

@ -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");
}

View File

@ -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;
}
/**

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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());

View File

@ -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) + ")";
}
}

View File

@ -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;

View File

@ -45,7 +45,7 @@ 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();
@ -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);
}

View File

@ -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.*;
/**
*
@ -104,12 +105,12 @@ public class Game {
// 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());
}
@ -175,19 +176,19 @@ public class Game {
* 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();
}
}

View File

@ -72,11 +72,11 @@ 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;

View File

@ -39,7 +39,8 @@ 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
@ -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;
@ -169,13 +170,12 @@ public class Game {
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;
@ -224,18 +224,18 @@ public class Game {
}
// 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();
@ -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);
}
@ -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();
@ -462,15 +460,13 @@ 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();
}
@ -479,8 +475,8 @@ public class Game {
// 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,8 +493,7 @@ 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();
}
@ -557,7 +552,7 @@ public class Game {
}
/**
* @param key_left
* @param direction
* @return
*/
private boolean hasInput(int direction) {
@ -590,7 +585,7 @@ public class 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);
}

View File

@ -81,11 +81,11 @@ public class GameApplet extends Applet {
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();
}

View File

@ -49,7 +49,7 @@ 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

View File

@ -113,7 +113,7 @@ public class SoundManager {
/**
* Initializes the SoundManager
*
* @param sources Number of sources to create
* @param channels Number of channels to create
*/
public void initialize(int channels) {
try {

View File

@ -33,7 +33,7 @@ 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
@ -56,7 +56,7 @@ 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) {
@ -96,32 +96,32 @@ public class 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();
}
}

View File

@ -31,7 +31,7 @@
*/
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
@ -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);
}
/**

View File

@ -53,7 +53,8 @@ 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
@ -70,7 +71,7 @@ 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;
@ -83,8 +84,6 @@ public class TextureLoader {
/**
* 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),
@ -108,7 +107,7 @@ public class TextureLoader {
* @return A new texture ID
*/
private int createTextureID() {
GL11.glGenTextures(textureIDBuffer);
glGenTextures(textureIDBuffer);
return textureIDBuffer.get(0);
}
@ -120,17 +119,17 @@ 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);
@ -154,42 +153,42 @@ public class TextureLoader {
int dstPixelFormat,
int minFilter,
int magFilter) throws IOException {
int srcPixelFormat = 0;
int srcPixelFormat;
// create the texture ID for this texture
int textureID = createTextureID();
Texture texture = new Texture(target,textureID);
// bind this texture
GL11.glBindTexture(target, textureID);
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 == GL11.GL_TEXTURE_2D) {
GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter);
if (target == GL_TEXTURE_2D) {
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilter);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilter);
}
// produce a texture from the byte buffer
GL11.glTexImage2D(target,
glTexImage2D(target,
0,
dstPixelFormat,
get2Fold(bufferedImage.getWidth()),
get2Fold(bufferedImage.getHeight()),
0,
srcPixelFormat,
GL11.GL_UNSIGNED_BYTE,
GL_UNSIGNED_BYTE,
textureBuffer );
return texture;
@ -201,7 +200,7 @@ public class TextureLoader {
* @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;
@ -217,7 +216,7 @@ public class TextureLoader {
* @return A buffer containing the data
*/
private ByteBuffer convertImageData(BufferedImage bufferedImage,Texture texture) {
ByteBuffer imageBuffer = null;
ByteBuffer imageBuffer;
WritableRaster raster;
BufferedImage texImage;

View File

@ -44,21 +44,21 @@ public interface 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
@ -67,7 +67,7 @@ public interface Controller {
* @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
@ -75,27 +75,27 @@ public interface Controller {
* @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
@ -103,7 +103,7 @@ public interface Controller {
* @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
@ -111,14 +111,14 @@ public interface Controller {
* @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.
*
* @return The number of axes available on this controller.
*/
public int getAxisCount();
int getAxisCount();
/**
* Get the name that's given to the specified axis
@ -126,7 +126,7 @@ public interface Controller {
* @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
@ -137,7 +137,7 @@ public interface Controller {
* @param index The index of axis to be read
* @return The value from the specified axis.
*/
public float getAxisValue(int index);
float getAxisValue(int index);
/**
* Get the value from the X axis if there is one. If no X axis is
@ -145,21 +145,21 @@ public interface Controller {
*
* @return The value from the X axis
*/
public float getXAxisValue();
float getXAxisValue();
/**
* Get the dead zone for the X axis.
*
* @return The dead zone for the X axis
*/
public float getXAxisDeadZone();
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);
void setXAxisDeadZone(float zone);
/**
* Get the value from the Y axis if there is one. If no Y axis is
@ -167,21 +167,21 @@ public interface Controller {
*
* @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
@ -189,21 +189,21 @@ public interface Controller {
*
* @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
@ -211,21 +211,21 @@ public interface Controller {
*
* @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
@ -233,21 +233,21 @@ public interface Controller {
*
* @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
@ -255,19 +255,19 @@ public interface Controller {
*
* @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);
}

View File

@ -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;

View File

@ -44,12 +44,12 @@ import org.lwjgl.LWJGLException;
*/
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;
@ -69,21 +69,15 @@ public class Controllers {
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);
}
@ -99,15 +93,15 @@ public class 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);
}
}
}
@ -119,7 +113,7 @@ public class Controllers {
* @return The controller requested
*/
public static Controller getController(int index) {
return (Controller) controllers.get(index);
return controllers.get(index);
}
/**
@ -159,7 +153,7 @@ public class Controllers {
return false;
}
event = (ControllerEvent) events.remove(0);
event = events.remove(0);
return event != null;
}

View File

@ -63,7 +63,7 @@ public class Cursor {
private final CursorElement[] cursors;
/** Index into list of cursors */
private int index = 0;
private int index;
private boolean destroyed;
@ -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;
}

View File

@ -34,6 +34,8 @@ 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;
@ -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 */
@ -84,19 +86,19 @@ class JInputController implements Controller {
* @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);
}
}
@ -107,31 +109,31 @@ class JInputController implements Controller {
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;
}
@ -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();
}
/*
@ -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();
}
/*

View File

@ -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++;
}
}
@ -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;
}
/**
@ -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;

View File

@ -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;
@ -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;
@ -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;
}
}
@ -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;
}
/**

View File

@ -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) {

View File

@ -47,10 +47,10 @@ 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;
@ -65,15 +65,13 @@ 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;
@ -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) {

View File

@ -57,10 +57,10 @@ import org.lwjgl.LWJGLException;
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;
@ -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.
@ -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,13 +202,13 @@ 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
@ -228,7 +228,7 @@ public final class ALC10 {
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
@ -252,14 +252,14 @@ public final class ALC10 {
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
@ -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,12 +324,12 @@ 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
@ -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,7 +362,7 @@ 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
@ -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,7 +398,7 @@ 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
@ -415,7 +415,7 @@ 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) {

View File

@ -96,7 +96,7 @@ 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;
}

View File

@ -55,7 +55,7 @@ public final class ALCcontext {
final long context;
/** Whether this context is valid */
private boolean valid = false;
private boolean valid;
/**
* Creates a new instance of ALCcontext

View File

@ -54,10 +54,10 @@ public final class ALCdevice {
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();
private final HashMap<Long, ALCcontext> contexts = new HashMap<Long, ALCcontext>();
/**
* Creates a new instance of ALCdevice
@ -86,7 +86,7 @@ public final class ALCdevice {
*/
void addContext(ALCcontext context) {
synchronized (contexts) {
contexts.put(new Long(context.context), context);
contexts.put(context.context, context);
}
}
@ -97,7 +97,7 @@ public final class ALCdevice {
*/
void removeContext(ALCcontext context) {
synchronized (contexts) {
contexts.remove(new Long(context.context));
contexts.remove(context.context);
}
}
@ -107,10 +107,8 @@ 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();
}

View File

@ -31,6 +31,9 @@
*/
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);
}
}

View File

@ -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);
}
}

View File

@ -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(); }
};

View File

@ -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);
}

View File

@ -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.
*

View File

@ -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));
}
}

View File

@ -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; }

View File

@ -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; }

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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 )

View File

@ -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;
}
}

View File

@ -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() )

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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;
}
}

View File

@ -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; }

View File

@ -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();

View 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);
}

View 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);
}
}

View 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);
}
};
}

View File

@ -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) + ")");
}
}

View File

@ -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 {

View File

@ -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;

View File

@ -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 {

View File

@ -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();

View File

@ -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();

View File

@ -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();
}
});

View File

@ -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;
}

View File

@ -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 ] ---------

View File

@ -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);
}

View File

@ -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);

View File

@ -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() {

View File

@ -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);

View File

@ -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 :

View File

@ -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;

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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);

View File

@ -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();
@ -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();
}
});
@ -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;
}

View File

@ -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;

View File

@ -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 static final 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_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_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_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 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_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) {

View File

@ -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;

View File

@ -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,13 +203,11 @@ 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) {
@ -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())

View File

@ -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);

View File

@ -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);

View File

@ -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 {

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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.
@ -45,14 +48,14 @@ public final class 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;

View File

@ -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;

View File

@ -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");

View File

@ -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 static final 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 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 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_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;
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 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;
final static int SM_CXCURSOR = 13;
final static int SM_CYCURSOR = 14;
final static int SM_CMOUSEBUTTONS = 43;
final static int SM_MOUSEWHEELPRESENT = 75;
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 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;
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 int ICON_SMALL = 0;
private final static int ICON_BIG = 1;
private static final int ICON_SMALL = 0;
private static final int ICON_BIG = 1;
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 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;
@ -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;
@ -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 */

View File

@ -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;

View File

@ -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,17 +279,17 @@ 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
@ -298,29 +298,29 @@ final class WindowsKeycodes {
/*
* 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) {

View File

@ -40,10 +40,10 @@ 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();

View File

@ -49,13 +49,13 @@ 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 =
@ -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() )
@ -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 );

View File

@ -125,14 +125,14 @@ public class DisplayTest {
// 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) {

View File

@ -37,6 +37,8 @@ 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!
@ -53,10 +55,10 @@ public class WindowCreationTest {
/** 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,10 +67,10 @@ 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
@ -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;

View File

@ -37,7 +37,7 @@ import java.awt.Canvas;
public class AppletLoaderTest extends Applet {
Test test = null;
Test test;
public void destroy() {
super.destroy();

View File

@ -8,13 +8,14 @@ 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 */
@ -24,22 +25,22 @@ public class GearsApplet extends Applet {
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;
/**
@ -105,11 +106,11 @@ public class GearsApplet extends Applet {
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();
}
@ -144,7 +145,7 @@ public class GearsApplet extends Applet {
} 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;
}
@ -195,33 +196,33 @@ public class GearsApplet extends Applet {
}
public void drawLoop() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GL11.glPushMatrix();
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);
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);
GL11.glPushMatrix();
GL11.glTranslatef(-3.0f, -2.0f, 0.0f);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glCallList(gear1);
GL11.glPopMatrix();
glPushMatrix();
glTranslatef(-3.0f, -2.0f, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glCallList(gear1);
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();
glPushMatrix();
glTranslatef(3.1f, -2.0f, 0.0f);
glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
glCallList(gear2);
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();
glPushMatrix();
glTranslatef(-3.1f, 4.2f, 0.0f);
glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
glCallList(gear3);
glPopMatrix();
GL11.glPopMatrix();
glPopMatrix();
}
protected void initGL() {
@ -237,56 +238,56 @@ public class GearsApplet extends Applet {
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();
glEndList();
gear2 = GL11.glGenLists(1);
GL11.glNewList(gear2, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, green);
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();
glEndList();
gear3 = GL11.glGenLists(1);
GL11.glNewList(gear3, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, blue);
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();
}
}

View File

@ -39,12 +39,13 @@ 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);
@ -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;

View File

@ -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;

View File

@ -33,34 +33,35 @@ package org.lwjgl.test.applet;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
public class Speed extends AWTGLCanvas implements Test {
private float angle = 0;
private float angle;
private long startTime = System.currentTimeMillis() + 5000;
private long fps = 0;
private long fps;
public Speed() throws LWJGLException {
}
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;
@ -77,7 +78,7 @@ public class Speed extends AWTGLCanvas implements Test {
} else {
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
startTime = System.currentTimeMillis() + 5000;
System.out.println(fps + " frames in " + (float) (timeUsed / 1000f) + " seconds = "
System.out.println(fps + " frames in " + timeUsed / 1000f + " seconds = "
+ (fps / (timeUsed / 1000f)));
fps = 0;
}

View File

@ -33,6 +33,6 @@ package org.lwjgl.test.applet;
public interface Test {
public void start();
public void stop();
void start();
void stop();
}

View File

@ -31,13 +31,14 @@
*/
package org.lwjgl.test.glu.tessellation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLUtessellatorCallbackAdapter;
import static org.lwjgl.opengl.GL11.*;
public class TessCallback extends GLUtessellatorCallbackAdapter {
public void begin(int type) {
GL11.glBegin(type);
glBegin(type);
}
public void combine(double[] coords, Object[] data, float[] weight, Object[] outData) {
@ -68,13 +69,13 @@ public class TessCallback extends GLUtessellatorCallbackAdapter {
}
public void end() {
GL11.glEnd();
glEnd();
}
public void vertex(Object vertexData) {
VertexData vertex = (VertexData) vertexData;
GL11.glVertex3d(vertex.data[0], vertex.data[1], vertex.data[2]);
GL11.glColor3d(vertex.data[3], vertex.data[4], vertex.data[5]);
glVertex3d(vertex.data[0], vertex.data[1], vertex.data[2]);
glColor3d(vertex.data[3], vertex.data[4], vertex.data[5]);
}
}

View File

@ -33,30 +33,31 @@ package org.lwjgl.test.glu.tessellation;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.glu.GLUtessellator;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public class TessellationTest {
private GLUtessellator tesselator;
void init()
{
// Create a new tessellation object
tesselator = GLU.gluNewTess();
tesselator = gluNewTess();
// Set callback functions
TessCallback callback = new TessCallback();
tesselator.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
tesselator.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
tesselator.gluTessCallback(GLU.GLU_TESS_END, callback);
tesselator.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
tesselator.gluTessCallback(GLU_TESS_VERTEX, callback);
tesselator.gluTessCallback(GLU_TESS_BEGIN, callback);
tesselator.gluTessCallback(GLU_TESS_END, callback);
tesselator.gluTessCallback(GLU_TESS_COMBINE, callback);
}
void setWindingRule(int windingRule)
{
// Set the winding rule
tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, windingRule);
tesselator.gluTessProperty(GLU_TESS_WINDING_RULE, windingRule);
}
void renderContour(double obj_data[][], int num_vertices)
@ -100,24 +101,24 @@ public class TessellationTest {
Display.create();
Display.setVSyncEnabled(true);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glClearDepth(1);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL11.glViewport(0,0,width,height);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
glViewport(0,0,width,height);
glMatrixMode(GL_MODELVIEW);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, width, height, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
}
private void loop() {
@ -133,9 +134,9 @@ public class TessellationTest {
}
private void render() {
GL11.glTranslatef(150,125,0);
glTranslatef(150,125,0);
GL11.glScalef(50,50,1);
glScalef(50,50,1);
// first polygon: a star-5 vertices and color information
double star[][] = { {0.6f, -0.1f, 0f, 1.0f, 1.0f, 1.0f},
{1.35f, 1.4f, 0f, 1.0f, 1.0f, 1.0f},
@ -157,7 +158,7 @@ public class TessellationTest {
// render the first polygon: the textured star
// set winding rule to positive
setWindingRule(GLU.GLU_TESS_WINDING_POSITIVE);
setWindingRule(GLU_TESS_WINDING_POSITIVE);
beginPolygon();
beginContour();
renderContour(star, 5);
@ -166,9 +167,9 @@ public class TessellationTest {
// render the second polygon: triangle cut out of a quad
GL11.glTranslatef(-2,0,0);
glTranslatef(-2,0,0);
// set winding rule to odd
setWindingRule(GLU.GLU_TESS_WINDING_ODD);
setWindingRule(GLU_TESS_WINDING_ODD);
// begin the new polygon
beginPolygon();
beginContour();

View File

@ -40,8 +40,9 @@ 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 org.lwjgl.util.glu.GLU;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
*
@ -54,12 +55,12 @@ import org.lwjgl.util.glu.GLU;
public class HWCursorTest {
/** The native cursor */
private static Cursor[] cursor = null;
private static Cursor[] cursors;
/** The mouse cursor position */
private static int mouse_x;
private static int mouse_y;
private static int mouse_btn = 0;
private static int mouse_btn;
/**
* Executes the test
@ -119,7 +120,7 @@ public class HWCursorTest {
System.exit(0);
}
cursor = new Cursor[3];
cursors = new Cursor[3];
int cursorImageCount = 1;
int cursorWidth = Math.min(64, Cursor.getMaxCursorSize());
@ -138,7 +139,7 @@ public class HWCursorTest {
}
}
cursorImages.flip();
cursor[0] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
cursors[0] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
// ----------------------------------
// Create 3 piece animation
@ -179,7 +180,7 @@ public class HWCursorTest {
cursorDelays.flip();
cursorImages.flip();
cursor[1] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
cursors[1] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
// ----------------------------------
@ -207,10 +208,10 @@ public class HWCursorTest {
}
cursorImages.flip();
cursorDelays.flip();
cursor[2] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
cursors[2] = new Cursor(cursorWidth, cursorHeight, cursorWidth/2, cursorHeight/2, cursorImageCount, cursorImages, cursorDelays);
// ----------------------------------
Mouse.setNativeCursor(cursor[0]);
Mouse.setNativeCursor(cursors[0]);
}
/**
@ -249,23 +250,23 @@ public class HWCursorTest {
*/
private void render() {
//clear background
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
// draw white quad
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(mouse_x, mouse_y, 0);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
glTranslatef(mouse_x, mouse_y, 0);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
{
GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glVertex2i(-50, -50);
GL11.glColor3f(0.0f, 1.0f, 0.0f); GL11.glVertex2i(50, -50);
GL11.glColor3f(0.0f, 0.0f, 1.0f); GL11.glVertex2i(50, 50);
GL11.glColor3f(1.0f, 0.0f, 1.0f); GL11.glVertex2i(-50, 50);
glColor3f(1.0f, 0.0f, 0.0f); glVertex2i(-50, -50);
glColor3f(0.0f, 1.0f, 0.0f); glVertex2i(50, -50);
glColor3f(0.0f, 0.0f, 1.0f); glVertex2i(50, 50);
glColor3f(1.0f, 0.0f, 1.0f); glVertex2i(-50, 50);
}
GL11.glEnd();
glEnd();
}
GL11.glPopMatrix();
glPopMatrix();
}
private void processMouse() {
@ -295,8 +296,8 @@ public class HWCursorTest {
e.printStackTrace();
System.exit(1);
}
for(int i=0; i<cursor.length; i++) {
cursor[i].destroy();
for ( Cursor aCursor : cursors ) {
aCursor.destroy();
}
Display.setFullscreen(true);
@ -317,8 +318,8 @@ public class HWCursorTest {
e.printStackTrace();
System.exit(1);
}
for(int i=0; i<cursor.length; i++) {
cursor[i].destroy();
for ( Cursor cursor : cursors ) {
cursor.destroy();
}
Display.setFullscreen(false);
glInit();
@ -350,7 +351,7 @@ public class HWCursorTest {
private void switchCursor() {
try {
Mouse.setNativeCursor(cursor[mouse_btn]);
Mouse.setNativeCursor(cursors[mouse_btn]);
} catch (Exception e) {
e.printStackTrace();
}
@ -366,8 +367,8 @@ public class HWCursorTest {
e.printStackTrace();
System.exit(1);
}
for(int i=0; i<cursor.length; i++) {
cursor[i].destroy();
for ( Cursor cursor : cursors ) {
cursor.destroy();
}
Display.destroy();
}
@ -377,15 +378,15 @@ public class HWCursorTest {
*/
private void glInit() {
// Go into orthographic projection mode.
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
//set clear color to black
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//sync frame (only works on windows)
Display.setVSyncEnabled(true);

View File

@ -34,9 +34,10 @@ package org.lwjgl.test.input;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.glu.GLU;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* <br>
@ -105,13 +106,13 @@ public class KeyboardTest {
}
private void initializeOpenGL() {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
public void executeTest() {
@ -209,20 +210,20 @@ public class KeyboardTest {
}
private void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
GL11.glBegin(GL11.GL_POLYGON);
glBegin(GL_POLYGON);
{
float color = 1.0f;
GL11.glColor3f(color, color, color);
glColor3f(color, color, color);
GL11.glVertex2f(position.x + 0.0f, position.y + 0.0f);
GL11.glVertex2f(position.x + 0.0f, position.y + 30.0f);
GL11.glVertex2f(position.x + 40.0f, position.y + 30.0f);
GL11.glVertex2f(position.x + 60.0f, position.y + 15.f);
GL11.glVertex2f(position.x + 40.0f, position.y + 0.0f);
glVertex2f(position.x + 0.0f, position.y + 0.0f);
glVertex2f(position.x + 0.0f, position.y + 30.0f);
glVertex2f(position.x + 40.0f, position.y + 30.0f);
glVertex2f(position.x + 60.0f, position.y + 15.f);
glVertex2f(position.x + 40.0f, position.y + 0.0f);
}
GL11.glEnd();
glEnd();
}
/**

View File

@ -35,9 +35,10 @@ import org.lwjgl.Sys;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector2f;
import static org.lwjgl.opengl.GL11.*;
/**
* <br>
* Mouse test
@ -91,15 +92,15 @@ public class MouseCreationTest {
}
private void initializeOpenGL() {
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// 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());
}
public void executeTest() {
@ -182,9 +183,9 @@ public class MouseCreationTest {
}
private void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
GL11.glBegin(GL11.GL_POLYGON);
glBegin(GL_POLYGON);
{
float color = 1.0f;
int buttonDown = 0;
@ -195,15 +196,15 @@ public class MouseCreationTest {
break;
}
}
GL11.glColor3f(color, color, color);
glColor3f(color, color, color);
GL11.glVertex2f(position.x + 0.0f, position.y + 0.0f);
GL11.glVertex2f(position.x + 0.0f, position.y + 30.0f);
GL11.glVertex2f(position.x + 40.0f, position.y + 30.0f);
GL11.glVertex2f(position.x + 60.0f, position.y + 15.f);
GL11.glVertex2f(position.x + 40.0f, position.y + 0.0f);
glVertex2f(position.x + 0.0f, position.y + 0.0f);
glVertex2f(position.x + 0.0f, position.y + 30.0f);
glVertex2f(position.x + 40.0f, position.y + 30.0f);
glVertex2f(position.x + 60.0f, position.y + 15.f);
glVertex2f(position.x + 40.0f, position.y + 0.0f);
}
GL11.glEnd();
glEnd();
}
/**

View File

@ -35,11 +35,12 @@ 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 org.lwjgl.util.glu.GLU;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector3f;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* <br>
* Mouse test
@ -53,7 +54,7 @@ public class MouseTest {
private int direction;
/** Last button pressed */
private int lastButton = 0;
private int lastButton;
/** Last direction we scrolled in */
private int lastScrollDirection = -1;
@ -68,14 +69,14 @@ public class MouseTest {
private Vector2f triangleSize = new Vector2f(120, 100);
/** Triangle color */
private Vector3f triangleColor[] = new Vector3f[] {
private Vector3f triangleColors[] = new Vector3f[] {
new Vector3f(1,1,1),
new Vector3f(1,0,0),
new Vector3f(0,1,0),
new Vector3f(0,0,1)
};
private Vector3f quadColor[] = new Vector3f[] {
private Vector3f quadColors[] = new Vector3f[] {
new Vector3f(1,1,1),
new Vector3f(1,0,0),
new Vector3f(0,1,0),
@ -91,7 +92,7 @@ public class MouseTest {
};
/** Whether the test is closing */
private boolean closing = false;
private boolean closing;
/** Fullscreen or not */
public static final boolean FULLSCREEN = false;
@ -148,13 +149,13 @@ public class MouseTest {
*
*/
private void initializeOpenGL() {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
/**
@ -299,19 +300,19 @@ public class MouseTest {
case -1:
break;
case 1:
triangleColor[direction].y = 1;
triangleColors[direction].y = 1;
break;
case 2:
triangleColor[direction].z = 1;
triangleColors[direction].z = 1;
break;
case 3:
triangleColor[direction].x = 1;
triangleColor[direction].y = 1;
triangleColor[direction].z = 1;
triangleColors[direction].x = 1;
triangleColors[direction].y = 1;
triangleColors[direction].z = 1;
break;
case 0: // fall through
default:
triangleColor[direction].x = 1;
triangleColors[direction].x = 1;
break;
}
}
@ -334,9 +335,9 @@ public class MouseTest {
}
// update colors
quadColor[lastScrollDirection].x = (float) Math.random();
quadColor[lastScrollDirection].y = (float) Math.random();
quadColor[lastScrollDirection].z = (float) Math.random();
quadColors[lastScrollDirection].x = (float) Math.random();
quadColors[lastScrollDirection].y = (float) Math.random();
quadColors[lastScrollDirection].z = (float) Math.random();
}
/**
@ -362,17 +363,17 @@ public class MouseTest {
private void logic() {
// "we fade to black"
// ===========================================
for(int i=0; i<triangleColor.length; i++) {
triangleColor[i].x -= 0.01;
triangleColor[i].y -= 0.01;
triangleColor[i].z -= 0.01;
}
for ( Vector3f color : triangleColors ) {
color.x -= 0.01;
color.y -= 0.01;
color.z -= 0.01;
}
for(int i=0; i<quadColor.length; i++) {
quadColor[i].x -= 0.01;
quadColor[i].y -= 0.01;
quadColor[i].z -= 0.01;
}
for ( Vector3f color : quadColors ) {
color.x -= 0.01;
color.y -= 0.01;
color.z -= 0.01;
}
// -------------------------------------------
}
@ -380,38 +381,38 @@ public class MouseTest {
* Render our triangles
*/
private void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
// for each triangle, render it at position, rotating degrees for each
for(int i=0; i<triangles.length; i++) {
GL11.glPushMatrix(); {
GL11.glTranslatef(triangles[i].x, triangles[i].y, 0);
GL11.glRotatef(i*90, 0, 0, 1);
glPushMatrix(); {
glTranslatef(triangles[i].x, triangles[i].y, 0);
glRotatef(i*90, 0, 0, 1);
GL11.glColor3f(triangleColor[i].x, triangleColor[i].y, triangleColor[i].z);
glColor3f(triangleColors[i].x, triangleColors[i].y, triangleColors[i].z);
GL11.glBegin(GL11.GL_TRIANGLES); {
GL11.glVertex2f(0, triangleSize.y);
GL11.glVertex2f(-triangleSize.x, -triangleSize.y);
GL11.glVertex2f(+triangleSize.x, -triangleSize.y);
glBegin(GL_TRIANGLES); {
glVertex2f(0, triangleSize.y);
glVertex2f(-triangleSize.x, -triangleSize.y);
glVertex2f(+triangleSize.x, -triangleSize.y);
}
GL11.glEnd();
glEnd();
}
GL11.glPopMatrix();
glPopMatrix();
}
// paint quad in the middle (yes, wasting cpu cycles by not precalculating)
GL11.glBegin(GL11.GL_QUADS); {
GL11.glColor3f(quadColor[0].x, quadColor[0].y, quadColor[0].z);
GL11.glVertex2f(WINDOW_WIDTH/2-triangleSize.x, WINDOW_HEIGHT/2-triangleSize.x);
GL11.glColor3f(quadColor[1].x, quadColor[1].y, quadColor[1].z);
GL11.glVertex2f(WINDOW_WIDTH/2+triangleSize.x, WINDOW_HEIGHT/2-triangleSize.x);
GL11.glColor3f(quadColor[2].x, quadColor[2].y, quadColor[2].z);
GL11.glVertex2f(WINDOW_WIDTH/2+triangleSize.x, WINDOW_HEIGHT/2+triangleSize.x);
GL11.glColor3f(quadColor[3].x, quadColor[3].y, quadColor[3].z);
GL11.glVertex2f(WINDOW_WIDTH/2-triangleSize.x, WINDOW_HEIGHT/2+triangleSize.x);
glBegin(GL_QUADS); {
glColor3f(quadColors[0].x, quadColors[0].y, quadColors[0].z);
glVertex2f(WINDOW_WIDTH/2-triangleSize.x, WINDOW_HEIGHT/2-triangleSize.x);
glColor3f(quadColors[1].x, quadColors[1].y, quadColors[1].z);
glVertex2f(WINDOW_WIDTH/2+triangleSize.x, WINDOW_HEIGHT/2-triangleSize.x);
glColor3f(quadColors[2].x, quadColors[2].y, quadColors[2].z);
glVertex2f(WINDOW_WIDTH/2+triangleSize.x, WINDOW_HEIGHT/2+triangleSize.x);
glColor3f(quadColors[3].x, quadColors[3].y, quadColors[3].z);
glVertex2f(WINDOW_WIDTH/2-triangleSize.x, WINDOW_HEIGHT/2+triangleSize.x);
}
GL11.glEnd();
glEnd();
}
/**

View File

@ -49,7 +49,7 @@ import org.lwjgl.input.Controllers;
* @author Kevin Glass
*/
public class TestControllers extends JPanel {
public static int total = 0;
public static int total;
private JTextField[] values;
private JTextField[] names;

View File

@ -52,7 +52,7 @@ public abstract class BasicTest {
/**
* Creates an instance of PlayTest
*/
public BasicTest() {
protected BasicTest() {
try {
AL.create();

View File

@ -110,15 +110,15 @@ public class OpenALInfo {
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MINOR_VERSION, (IntBuffer) version.position(1));
checkForErrors();
System.out.println("ALC version: " + (int)version.get(0) + "." + (int)version.get(1));
System.out.println("ALC version: " + version.get(0) + "." + version.get(1));
System.out.println("ALC extensions:");
String[] extensions = ALC10.alcGetString(device, ALC10.ALC_EXTENSIONS).split(" ");
for(int i=0; i<extensions.length; i++) {
if(extensions[i].trim().length() == 0) {
for ( String extension : extensions ) {
if ( extension.trim().length() == 0 ) {
continue;
}
System.out.println(" " + extensions[i]);
System.out.println(" " + extension);
}
checkForErrors();
}
@ -129,11 +129,11 @@ public class OpenALInfo {
System.out.println("OpenAL version string: " + AL10.alGetString(AL10.AL_VERSION));
System.out.println("AL extensions:");
String[] extensions = AL10.alGetString(AL10.AL_EXTENSIONS).split(" ");
for(int i=0; i<extensions.length; i++) {
if(extensions[i].trim().length() == 0) {
for ( String extension : extensions ) {
if ( extension.trim().length() == 0 ) {
continue;
}
System.out.println(" " + extensions[i]);
System.out.println(" " + extension);
}
checkForErrors();
}
@ -160,46 +160,39 @@ public class OpenALInfo {
}
System.out.println("Supported filters: ");
HashMap filters = new HashMap();
filters.put("Low-pass", new Integer(EFX10.AL_FILTER_LOWPASS));
filters.put("High-pass", new Integer(EFX10.AL_FILTER_HIGHPASS));
filters.put("Band-pass", new Integer(EFX10.AL_FILTER_BANDPASS));
HashMap<String, Integer> filters = new HashMap<String, Integer>();
filters.put("Low-pass", EFX10.AL_FILTER_LOWPASS);
filters.put("High-pass", EFX10.AL_FILTER_HIGHPASS);
filters.put("Band-pass", EFX10.AL_FILTER_BANDPASS);
Set entries = filters.entrySet();
for(Iterator i = entries.iterator(); i.hasNext();) {
Map.Entry entry = (Entry) i.next();
int value = ((Integer)entry.getValue()).intValue();
String key = (String) entry.getKey();
if(EFXUtil.isFilterSupported(value)) {
System.out.println(" " + key);
}
}
Set<Entry<String, Integer>> entries = filters.entrySet();
for ( final Entry<String, Integer> entry : entries ) {
String key = entry.getKey();
if ( EFXUtil.isFilterSupported(entry.getValue()) )
System.out.println(" " + entry.getKey());
}
System.out.println("Supported effects: ");
HashMap effects = new HashMap();
effects.put("EAX Reverb", new Integer(EFX10.AL_EFFECT_EAXREVERB));
effects.put("Reverb", new Integer(EFX10.AL_EFFECT_REVERB));
effects.put("Chorus", new Integer(EFX10.AL_EFFECT_CHORUS));
effects.put("Distortion", new Integer(EFX10.AL_EFFECT_DISTORTION));
effects.put("Echo", new Integer(EFX10.AL_EFFECT_ECHO));
effects.put("Flanger", new Integer(EFX10.AL_EFFECT_FLANGER));
effects.put("Frequency Shifter", new Integer(EFX10.AL_EFFECT_FREQUENCY_SHIFTER));
effects.put("Vocal Morpher", new Integer(EFX10.AL_EFFECT_VOCAL_MORPHER));
effects.put("Pitch Shifter", new Integer(EFX10.AL_EFFECT_PITCH_SHIFTER));
effects.put("Ring Modulator", new Integer(EFX10.AL_EFFECT_RING_MODULATOR));
effects.put("Autowah", new Integer(EFX10.AL_EFFECT_AUTOWAH));
effects.put("Compressor", new Integer(EFX10.AL_EFFECT_COMPRESSOR));
effects.put("Equalizer", new Integer(EFX10.AL_EFFECT_EQUALIZER));
HashMap<String, Integer> effects = new HashMap<String, Integer>();
effects.put("EAX Reverb", EFX10.AL_EFFECT_EAXREVERB);
effects.put("Reverb", EFX10.AL_EFFECT_REVERB);
effects.put("Chorus", EFX10.AL_EFFECT_CHORUS);
effects.put("Distortion", EFX10.AL_EFFECT_DISTORTION);
effects.put("Echo", EFX10.AL_EFFECT_ECHO);
effects.put("Flanger", EFX10.AL_EFFECT_FLANGER);
effects.put("Frequency Shifter", EFX10.AL_EFFECT_FREQUENCY_SHIFTER);
effects.put("Vocal Morpher", EFX10.AL_EFFECT_VOCAL_MORPHER);
effects.put("Pitch Shifter", EFX10.AL_EFFECT_PITCH_SHIFTER);
effects.put("Ring Modulator", EFX10.AL_EFFECT_RING_MODULATOR);
effects.put("Autowah", EFX10.AL_EFFECT_AUTOWAH);
effects.put("Compressor", EFX10.AL_EFFECT_COMPRESSOR);
effects.put("Equalizer", EFX10.AL_EFFECT_EQUALIZER);
entries = effects.entrySet();
for(Iterator i = entries.iterator(); i.hasNext();) {
Map.Entry entry = (Entry) i.next();
int value = ((Integer)entry.getValue()).intValue();
String key = (String) entry.getKey();
if(EFXUtil.isEffectSupported(value)) {
System.out.println(" " + key);
}
}
for ( final Entry<String, Integer> entry : entries ) {
if ( EFXUtil.isEffectSupported(entry.getValue()) )
System.out.println(" " + entry.getKey());
}
}
private void printDevices(int which, String kind) {
@ -207,8 +200,8 @@ public class OpenALInfo {
checkForErrors();
System.out.println("Available " + kind + " devices: ");
for(int i=0; i<devices.length; i++) {
System.out.println(" " + devices[i]);
for ( String device : devices ) {
System.out.println(" " + device);
}
}

View File

@ -39,12 +39,13 @@ import org.lwjgl.LWJGLUtil;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.openal.AL;
import org.lwjgl.openal.AL10;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.WaveData;
import static org.lwjgl.openal.AL10.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* <br>
* This test demonstrates OpenAL positioning Based on the example by Chad Armstrong
@ -75,10 +76,10 @@ public class PositionTest extends BasicTest {
public static final int RIGHT = 2;
/** Whether the demo is done */
private boolean finished = false;
private boolean finished;
/** Whether in pause mode */
private boolean pauseMode = false;
private boolean pauseMode;
// OpenAL stuff
// ===================================================
@ -160,14 +161,14 @@ public class PositionTest extends BasicTest {
// =====================================================
LWJGLUtil.log("Setting up OpenGL");
GL11.glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(50.0f, (float) WINDOW_WIDTH / WINDOW_HEIGHT, 0.0f, 50.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glTranslatef(0.0f, 0.0f, -6.6f);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50.0f, (float) WINDOW_WIDTH / WINDOW_HEIGHT, 0.0f, 50.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -6.6f);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glut = this.new GLUT();
Display.setVSyncEnabled(true);
@ -177,17 +178,17 @@ public class PositionTest extends BasicTest {
// =====================================================
LWJGLUtil.log("Setting up OpenAL");
AL10.alListener(AL10.AL_POSITION, listenerPosition);
AL10.alListener(AL10.AL_VELOCITY, listenerVelocity);
AL10.alListener(AL10.AL_ORIENTATION, listenerOrientation);
alListener(AL_POSITION, listenerPosition);
alListener(AL_VELOCITY, listenerVelocity);
alListener(AL_ORIENTATION, listenerOrientation);
// creating buffers
LWJGLUtil.log("Creating buffers");
AL10.alGenBuffers(soundBuffers);
alGenBuffers(soundBuffers);
soundBuffers.rewind();
// creating sources
AL10.alGenSources(soundSources);
alGenSources(soundSources);
soundSources.rewind();
// load sound files (left, center, right).wav
@ -195,33 +196,33 @@ public class PositionTest extends BasicTest {
LWJGLUtil.log("Loading left.wav");
WaveData left = WaveData.create("left.wav");
AL10.alBufferData(soundBuffers.get(LEFT), left.format, left.data, left.samplerate);
AL10.alSourcef(soundSources.get(LEFT), AL10.AL_PITCH, 1.0f);
AL10.alSourcef(soundSources.get(LEFT), AL10.AL_GAIN, 1.0f);
AL10.alSource(soundSources.get(LEFT), AL10.AL_POSITION, leftPosition);
AL10.alSource(soundSources.get(LEFT), AL10.AL_VELOCITY, leftVelocity);
AL10.alSourcei(soundSources.get(LEFT), AL10.AL_BUFFER, soundBuffers.get(LEFT));
AL10.alSourcei(soundSources.get(LEFT), AL10.AL_LOOPING, AL10.AL_TRUE);
alBufferData(soundBuffers.get(LEFT), left.format, left.data, left.samplerate);
alSourcef(soundSources.get(LEFT), AL_PITCH, 1.0f);
alSourcef(soundSources.get(LEFT), AL_GAIN, 1.0f);
alSource(soundSources.get(LEFT), AL_POSITION, leftPosition);
alSource(soundSources.get(LEFT), AL_VELOCITY, leftVelocity);
alSourcei(soundSources.get(LEFT), AL_BUFFER, soundBuffers.get(LEFT));
alSourcei(soundSources.get(LEFT), AL_LOOPING, AL_TRUE);
LWJGLUtil.log("Loading center.wav");
WaveData center = WaveData.create("center.wav");
AL10.alBufferData(soundBuffers.get(CENTER), center.format, center.data, center.samplerate);
AL10.alSourcef(soundSources.get(CENTER), AL10.AL_PITCH, 1.0f);
AL10.alSourcef(soundSources.get(CENTER), AL10.AL_GAIN, 1.0f);
AL10.alSource(soundSources.get(CENTER), AL10.AL_POSITION, centerPosition);
AL10.alSource(soundSources.get(CENTER), AL10.AL_VELOCITY, centerVelocity);
AL10.alSourcei(soundSources.get(CENTER), AL10.AL_BUFFER, soundBuffers.get(CENTER));
AL10.alSourcei(soundSources.get(CENTER), AL10.AL_LOOPING, AL10.AL_TRUE);
alBufferData(soundBuffers.get(CENTER), center.format, center.data, center.samplerate);
alSourcef(soundSources.get(CENTER), AL_PITCH, 1.0f);
alSourcef(soundSources.get(CENTER), AL_GAIN, 1.0f);
alSource(soundSources.get(CENTER), AL_POSITION, centerPosition);
alSource(soundSources.get(CENTER), AL_VELOCITY, centerVelocity);
alSourcei(soundSources.get(CENTER), AL_BUFFER, soundBuffers.get(CENTER));
alSourcei(soundSources.get(CENTER), AL_LOOPING, AL_TRUE);
LWJGLUtil.log("Loading right.wav");
WaveData right = WaveData.create("right.wav");
AL10.alBufferData(soundBuffers.get(RIGHT), right.format, right.data, right.samplerate);
AL10.alSourcef(soundSources.get(RIGHT), AL10.AL_PITCH, 1.0f);
AL10.alSourcef(soundSources.get(RIGHT), AL10.AL_GAIN, 1.0f);
AL10.alSource(soundSources.get(RIGHT), AL10.AL_POSITION, rightPosition);
AL10.alSource(soundSources.get(RIGHT), AL10.AL_VELOCITY, rightVelocity);
AL10.alSourcei(soundSources.get(RIGHT), AL10.AL_BUFFER, soundBuffers.get(RIGHT));
AL10.alSourcei(soundSources.get(RIGHT), AL10.AL_LOOPING, AL10.AL_TRUE);
alBufferData(soundBuffers.get(RIGHT), right.format, right.data, right.samplerate);
alSourcef(soundSources.get(RIGHT), AL_PITCH, 1.0f);
alSourcef(soundSources.get(RIGHT), AL_GAIN, 1.0f);
alSource(soundSources.get(RIGHT), AL_POSITION, rightPosition);
alSource(soundSources.get(RIGHT), AL_VELOCITY, rightVelocity);
alSourcei(soundSources.get(RIGHT), AL_BUFFER, soundBuffers.get(RIGHT));
alSourcei(soundSources.get(RIGHT), AL_LOOPING, AL_TRUE);
LWJGLUtil.log("Soundfiles loaded successfully");
// -----------------------------------------------------
@ -287,11 +288,11 @@ public class PositionTest extends BasicTest {
* Starts playing the sounds at different times
*/
private void startSounds() {
AL10.alSourcePlay(soundSources.get(LEFT));
alSourcePlay(soundSources.get(LEFT));
pause(300);
AL10.alSourcePlay(soundSources.get(CENTER));
alSourcePlay(soundSources.get(CENTER));
pause(500);
AL10.alSourcePlay(soundSources.get(RIGHT));
alSourcePlay(soundSources.get(RIGHT));
}
/**
@ -303,7 +304,7 @@ public class PositionTest extends BasicTest {
// if requesting pause, and not paused - pause and stop sound
if(paused && !pauseMode) {
pauseMode = true;
AL10.alSourcePause(soundSources);
alSourcePause(soundSources);
System.out.println("pauseMode = true");
}
@ -330,17 +331,17 @@ public class PositionTest extends BasicTest {
// Test for play
// ============================================
if (Keyboard.isKeyDown(Keyboard.KEY_1)) {
AL10.alSourcePlay(soundSources.get(LEFT));
alSourcePlay(soundSources.get(LEFT));
LWJGLUtil.log("Playing left.wav");
}
if (Keyboard.isKeyDown(Keyboard.KEY_2)) {
AL10.alSourcePlay(soundSources.get(CENTER));
alSourcePlay(soundSources.get(CENTER));
LWJGLUtil.log("Playing center.wav");
}
if (Keyboard.isKeyDown(Keyboard.KEY_3)) {
AL10.alSourcePlay(soundSources.get(RIGHT));
alSourcePlay(soundSources.get(RIGHT));
LWJGLUtil.log("Playing right.wav");
}
// --------------------------------------------
@ -348,17 +349,17 @@ public class PositionTest extends BasicTest {
// Test for stop
// ============================================
if (Keyboard.isKeyDown(Keyboard.KEY_4)) {
AL10.alSourceStop(soundSources.get(LEFT));
alSourceStop(soundSources.get(LEFT));
LWJGLUtil.log("Stopped left.wav");
}
if (Keyboard.isKeyDown(Keyboard.KEY_5)) {
AL10.alSourceStop(soundSources.get(CENTER));
alSourceStop(soundSources.get(CENTER));
LWJGLUtil.log("Stopped center.wav");
}
if (Keyboard.isKeyDown(Keyboard.KEY_6)) {
AL10.alSourceStop(soundSources.get(RIGHT));
alSourceStop(soundSources.get(RIGHT));
LWJGLUtil.log("Stopped right.wav");
}
// --------------------------------------------
@ -367,12 +368,12 @@ public class PositionTest extends BasicTest {
// ============================================
if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
listenerPosition.put(0, listenerPosition.get(0) - 0.1f);
AL10.alListener(AL10.AL_POSITION, listenerPosition);
alListener(AL_POSITION, listenerPosition);
}
if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
listenerPosition.put(0, listenerPosition.get(0) + 0.1f);
AL10.alListener(AL10.AL_POSITION, listenerPosition);
alListener(AL_POSITION, listenerPosition);
}
if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
@ -381,7 +382,7 @@ public class PositionTest extends BasicTest {
} else {
listenerPosition.put(2, listenerPosition.get(2) - 0.1f);
}
AL10.alListener(AL10.AL_POSITION, listenerPosition);
alListener(AL_POSITION, listenerPosition);
}
if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
@ -390,7 +391,7 @@ public class PositionTest extends BasicTest {
} else {
listenerPosition.put(2, listenerPosition.get(2) + 0.1f);
}
AL10.alListener(AL10.AL_POSITION, listenerPosition);
alListener(AL_POSITION, listenerPosition);
}
// --------------------------------------------
@ -405,7 +406,7 @@ public class PositionTest extends BasicTest {
listenerPosition.put(2, listenerPosition.get(2) + 0.1f);
}
AL10.alListener(AL10.AL_POSITION, listenerPosition);
alListener(AL_POSITION, listenerPosition);
// empty mouse buffer
while(Mouse.next());
@ -415,48 +416,48 @@ public class PositionTest extends BasicTest {
* Render the scene
*/
private void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
{
GL11.glRotatef(20.0f, 1.0f, 1.0f, 0.0f);
glRotatef(20.0f, 1.0f, 1.0f, 0.0f);
// left
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(leftPosition.get(0), leftPosition.get(1), leftPosition.get(2));
GL11.glColor3f(1.0f, 0.0f, 0.0f);
glTranslatef(leftPosition.get(0), leftPosition.get(1), leftPosition.get(2));
glColor3f(1.0f, 0.0f, 0.0f);
glut.glutWireCube(0.5f);
}
GL11.glPopMatrix();
glPopMatrix();
// center
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(centerPosition.get(0), centerPosition.get(1), centerPosition.get(2));
GL11.glColor3f(0.0f, 0.0f, 1.0f);
glTranslatef(centerPosition.get(0), centerPosition.get(1), centerPosition.get(2));
glColor3f(0.0f, 0.0f, 1.0f);
glut.glutWireCube(0.5f);
}
GL11.glPopMatrix();
glPopMatrix();
// right
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(rightPosition.get(0), rightPosition.get(1), rightPosition.get(2));
GL11.glColor3f(0.0f, 1.0f, 0.0f);
glTranslatef(rightPosition.get(0), rightPosition.get(1), rightPosition.get(2));
glColor3f(0.0f, 1.0f, 0.0f);
glut.glutWireCube(0.5f);
}
GL11.glPopMatrix();
glPopMatrix();
// listener
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(listenerPosition.get(0), listenerPosition.get(1), listenerPosition.get(2));
GL11.glColor3f(1.0f, 1.0f, 1.0f);
glTranslatef(listenerPosition.get(0), listenerPosition.get(1), listenerPosition.get(2));
glColor3f(1.0f, 1.0f, 1.0f);
glut.glutSolidCube(0.5f);
}
GL11.glPopMatrix();
glPopMatrix();
}
GL11.glPopMatrix();
glPopMatrix();
}
/**
@ -464,9 +465,9 @@ public class PositionTest extends BasicTest {
*/
private void shutdown() {
LWJGLUtil.log("Shutting down OpenAL");
AL10.alSourceStop(soundSources);
AL10.alDeleteSources(soundSources);
AL10.alDeleteBuffers(soundBuffers);
alSourceStop(soundSources);
alDeleteSources(soundSources);
alDeleteBuffers(soundBuffers);
AL.destroy();
LWJGLUtil.log("Shutting down Window");
@ -521,11 +522,11 @@ public class PositionTest extends BasicTest {
float v[][] = new float[8][3];
public void glutWireCube(float size) {
drawBox(size, GL11.GL_LINE_LOOP);
drawBox(size, GL_LINE_LOOP);
}
public void glutSolidCube(float size) {
drawBox(size, GL11.GL_QUADS);
drawBox(size, GL_QUADS);
}
private void drawBox(float size, int type) {
@ -538,13 +539,13 @@ public class PositionTest extends BasicTest {
v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2;
for (int i = 5; i >= 0; i--) {
GL11.glBegin(type);
GL11.glNormal3f(n[i][0], n[i][1], n[i][2]);
GL11.glVertex3f(v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2]);
GL11.glVertex3f(v[faces[i][1]][0], v[faces[i][1]][1], v[faces[i][1]][2]);
GL11.glVertex3f(v[faces[i][2]][0], v[faces[i][2]][1], v[faces[i][2]][2]);
GL11.glVertex3f(v[faces[i][3]][0], v[faces[i][3]][1], v[faces[i][3]][2]);
GL11.glEnd();
glBegin(type);
glNormal3f(n[i][0], n[i][1], n[i][2]);
glVertex3f(v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2]);
glVertex3f(v[faces[i][1]][0], v[faces[i][1]][1], v[faces[i][1]][2]);
glVertex3f(v[faces[i][2]][0], v[faces[i][2]][1], v[faces[i][2]][2]);
glVertex3f(v[faces[i][3]][0], v[faces[i][3]][1], v[faces[i][3]][2]);
glEnd();
}
}

View File

@ -62,6 +62,7 @@ public class HelloOpenCL {
printPlatformInfo(platform, "CL_PLATFORM_VERSION", CL_PLATFORM_VERSION);
printPlatformInfo(platform, "CL_PLATFORM_NAME", CL_PLATFORM_NAME);
printPlatformInfo(platform, "CL_PLATFORM_VENDOR", CL_PLATFORM_VENDOR);
printPlatformInfo(platform, "CL_PLATFORM_EXTENSIONS", CL_PLATFORM_EXTENSIONS);
System.out.println("");
final PointerBuffer ctxProps = BufferUtils.createPointerBuffer(3);

View File

@ -38,9 +38,7 @@ import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opencl.*;
import org.lwjgl.opencl.api.Filter;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.Drawable;
import org.lwjgl.opengl.*;
import org.lwjgl.util.Color;
import org.lwjgl.util.ReadableColor;
@ -51,6 +49,9 @@ import java.util.List;
import static java.lang.Math.*;
import static org.lwjgl.opencl.CL10.*;
import static org.lwjgl.opencl.CL10GL.*;
import static org.lwjgl.opencl.KHRGLEvent.*;
import static org.lwjgl.opengl.ARBCLEvent.*;
import static org.lwjgl.opengl.ARBSync.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
import static org.lwjgl.opengl.GL15.*;
@ -133,8 +134,8 @@ public class DemoFractal {
private final PointerBuffer kernel2DGlobalWorkSize;
private int width = 0;
private int height = 0;
private int width;
private int height;
private double minX = -2f;
private double minY = -1.2f;
@ -161,6 +162,18 @@ public class DemoFractal {
private boolean run = true;
// EVENT SYNCING
private final PointerBuffer syncBuffer = BufferUtils.createPointerBuffer(1);
private boolean syncGLtoCL; // true if we can make GL wait on events generated from CL queues.
private CLEvent[] clEvents;
private GLSync[] clSyncs;
private boolean syncCLtoGL; // true if we can make CL wait on sync objects generated from GL.
private GLSync glSync;
private CLEvent glEvent;
public DemoFractal(int width, int height) {
kernel2DGlobalWorkSize = BufferUtils.createPointerBuffer(2);
@ -294,10 +307,10 @@ public class DemoFractal {
public void init() {
try {
CL.create();
Display.setDisplayMode(new DisplayMode(width, height));
Display.setTitle("OpenCL Fractal Demo");
Display.create();
CL.create();
} catch (LWJGLException e) {
throw new RuntimeException(e);
}
@ -342,7 +355,7 @@ public class DemoFractal {
if ( devices == null ) {
devices = platform.getDevices(CL_DEVICE_TYPE_CPU, glSharingFilter);
if ( devices == null )
throw new RuntimeException("No OpenCL devices found.");
throw new RuntimeException("No OpenCL devices found with KHR_gl_sharing support.");
}
// Create the context
@ -371,13 +384,13 @@ public class DemoFractal {
for ( int i = 0; i < slices; i++ ) {
colorMapBuffer[i] = BufferUtils.createIntBuffer(32 * 2);
colorMap[i] = clCreateBuffer(clContext, CL_MEM_READ_ONLY, colorMapBuffer[i].capacity() * 4, null);
colorMap[i].checkNull();
colorMap[i].checkValid();
initColorMap(colorMapBuffer[i], 32, Color.BLUE, Color.GREEN, Color.RED);
// create command queue and upload color map buffer on each used device
queues[i] = clCreateCommandQueue(clContext, devices.get(i), CL_QUEUE_PROFILING_ENABLE, null);
queues[i].checkNull();
queues[i].checkValid();
clEnqueueWriteBuffer(queues[i], colorMap[i], CL_TRUE, 0, colorMapBuffer[i], null, null); // blocking upload
}
@ -399,6 +412,39 @@ public class DemoFractal {
programs = new CLProgram[all64bit ? 1 : slices];
buildPrograms();
final ContextCapabilities caps = GLContext.getCapabilities();
System.out.println("OpenGL caps.OpenGL32 = " + caps.OpenGL32);
System.out.println("OpenGL caps.GL_ARB_sync = " + caps.GL_ARB_sync);
System.out.println("OpenGL caps.GL_ARB_cl_event = " + caps.GL_ARB_cl_event);
for ( int i = 0; i < devices.size(); i++ ) {
System.out.println("Device #" + (i + 1) + " supports KHR_gl_event = " + CLCapabilities.getDeviceCapabilities(devices.get(i)).CL_KHR_gl_event);
}
// Detect GLtoCL synchronization method
syncGLtoCL = caps.GL_ARB_cl_event; // GL3.2 or ARB_sync implied
if ( syncGLtoCL ) {
clEvents = new CLEvent[slices];
clSyncs = new GLSync[slices];
System.out.println("GL to CL sync: Using OpenCL events");
} else
System.out.println("GL to CL sync: Using clFinish");
// Detect CLtoGL synchronization method
syncCLtoGL = caps.OpenGL32 || caps.GL_ARB_sync;
if ( syncCLtoGL ) {
for ( CLDevice device : devices ) {
if ( !CLCapabilities.getDeviceCapabilities(device).CL_KHR_gl_event ) {
syncCLtoGL = false;
break;
}
}
}
if ( syncCLtoGL ) {
System.out.println("CL to GL sync: Using OpenGL sync objects");
} else
System.out.println("CL to GL sync: Using glFinish");
}
private void createPrograms() throws IOException {
@ -531,7 +577,6 @@ public class DemoFractal {
// init kernel with constants
kernels[i] = clCreateKernel(programs[min(i, programs.length)], "mandelbrot", null);
}
}
// init kernels with constants
@ -549,8 +594,14 @@ public class DemoFractal {
// rendering cycle
public void display() {
// make sure GL does not use our objects before we start computeing
glFinish();
// TODO: Need to clean-up events, test when ARB_cl_events & KHR_gl_event are implemented.
// make sure GL does not use our objects before we start computing
if ( syncCLtoGL ) {
for ( final CLCommandQueue queue : queues )
clEnqueueWaitForEvents(queue, glEvent);
} else
glFinish();
if ( !buffersInitialized ) {
initPBO();
@ -597,14 +648,18 @@ public class DemoFractal {
null,
null, null);
clEnqueueReleaseGLObjects(queues[i], pboBuffers[i], null, null);
clEnqueueReleaseGLObjects(queues[i], pboBuffers[i], null, syncBuffer);
if ( syncGLtoCL ) {
clEvents[i] = queues[i].getCLEvent(syncBuffer.get(0));
clSyncs[i] = glCreateSyncFromCLeventARB(queues[i].getParent(), clEvents[i], 0);
}
}
// block until done (important: finish before doing further gl work)
for ( int i = 0; i < slices; i++ ) {
clFinish(queues[i]);
if ( !syncGLtoCL ) {
for ( int i = 0; i < slices; i++ )
clFinish(queues[i]);
}
}
// OpenGL
@ -612,6 +667,11 @@ public class DemoFractal {
private void render() {
glClear(GL_COLOR_BUFFER_BIT);
if ( syncGLtoCL ) {
for ( int i = 0; i < slices; i++ )
glWaitSync(clSyncs[i], 0, 0);
}
//draw slices
int sliceWidth = width / slices;
@ -626,6 +686,12 @@ public class DemoFractal {
}
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
if ( syncCLtoGL ) {
glSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
glEvent = clCreateEventFromGLsyncKHR(clContext, glSync, null);
}
//draw info text
/*
textRenderer.beginRendering(width, height, false);
@ -647,20 +713,6 @@ public class DemoFractal {
*/
}
public void reshape(int x, int y, int width, int height) {
if ( this.width == width && this.height == height )
return;
this.width = width;
this.height = height;
initPBO();
setKernelConstants();
initView(width, height);
}
private static boolean isDoubleFPAvailable(CLDevice device) {
final CLDeviceCapabilities caps = CLCapabilities.getDeviceCapabilities(device);
return caps.CL_KHR_fp64 || caps.CL_AMD_fp64;

View File

@ -36,10 +36,11 @@ 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 org.lwjgl.util.glu.GLU;
import org.lwjgl.util.vector.Vector2f;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
*
* Tests switching between windowed and fullscreen
@ -145,23 +146,23 @@ public class FullScreenWindowedTest {
}
private void render() {
//clear background
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
// draw white quad
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(quadPosition.x, quadPosition.y, 0);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
glTranslatef(quadPosition.x, quadPosition.y, 0);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
{
GL11.glVertex2i(-50, -50);
GL11.glVertex2i(50, -50);
GL11.glVertex2i(50, 50);
GL11.glVertex2i(-50, 50);
glVertex2i(-50, -50);
glVertex2i(50, -50);
glVertex2i(50, 50);
glVertex2i(-50, 50);
}
GL11.glEnd();
glEnd();
}
GL11.glPopMatrix();
glPopMatrix();
}
/**
* Processes keyboard input
@ -246,9 +247,9 @@ public class FullScreenWindowedTest {
*/
private DisplayMode findDisplayMode(int width, int height, int bpp) throws LWJGLException {
DisplayMode[] modes = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++) {
if (modes[i].getWidth() == width && modes[i].getHeight() == height && modes[i].getBitsPerPixel() >= bpp && modes[i].getFrequency() <= 60) {
return modes[i];
for ( DisplayMode mode : modes ) {
if ( mode.getWidth() == width && mode.getHeight() == height && mode.getBitsPerPixel() >= bpp && mode.getFrequency() <= 60 ) {
return mode;
}
}
return Display.getDesktopDisplayMode();
@ -258,14 +259,14 @@ public class FullScreenWindowedTest {
*/
private void glInit() {
// Go into orthographic projection mode.
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, mode.getWidth(), 0, mode.getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, mode.getWidth(), mode.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, mode.getWidth(), 0, mode.getHeight());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, mode.getWidth(), mode.getHeight());
//set clear color to black
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//sync frame (only works on windows)
Display.setVSyncEnabled(true);
}

View File

@ -41,12 +41,13 @@ 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.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import static org.lwjgl.opengl.ARBTransposeMatrix.*;
import static org.lwjgl.opengl.GL11.*;
/**
* <p>
* This is the OpenGL "standard" Gears demo, originally by Brian Paul
@ -61,7 +62,7 @@ public class Gears {
private float view_roty = 30.0f;
private float view_rotz = 0.0f;
private float view_rotz;
private int gear1;
@ -69,7 +70,7 @@ public class Gears {
private int gear3;
private float angle = 0.0f;
private float angle;
public static void main(String[] args) {
new Gears().execute();
@ -110,32 +111,32 @@ public class Gears {
while (!Display.isCloseRequested()) {
angle += 2.0f;
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | 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);
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);
GL11.glPushMatrix();
GL11.glTranslatef(-3.0f, -2.0f, 0.0f);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glCallList(gear1);
GL11.glPopMatrix();
glPushMatrix();
glTranslatef(-3.0f, -2.0f, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glCallList(gear1);
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();
glPushMatrix();
glTranslatef(3.1f, -2.0f, 0.0f);
glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
glCallList(gear2);
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();
glPushMatrix();
glTranslatef(-3.1f, 4.2f, 0.0f);
glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
glCallList(gear3);
glPopMatrix();
GL11.glPopMatrix();
glPopMatrix();
Display.update();
if (startTime > System.currentTimeMillis()) {
@ -143,7 +144,7 @@ public class Gears {
} else {
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
startTime = System.currentTimeMillis() + 5000;
System.out.println(fps + " frames in " + (float) (timeUsed / 1000f) + " seconds = "
System.out.println(fps + " frames in " + timeUsed / 1000f + " seconds = "
+ (fps / (timeUsed / 1000f)));
fps = 0;
}
@ -172,58 +173,58 @@ public class Gears {
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();
glEndList();
gear2 = GL11.glGenLists(1);
GL11.glNewList(gear2, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, green);
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();
glEndList();
gear3 = GL11.glGenLists(1);
GL11.glNewList(gear3, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, blue);
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();
glEndList();
GL11.glEnable(GL11.GL_NORMALIZE);
glEnable(GL_NORMALIZE);
GL11.glMatrixMode(GL11.GL_PROJECTION);
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) 300 / (float) 300;
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);
}
/**
@ -248,95 +249,95 @@ public class Gears {
da = 2.0f * (float) Math.PI / teeth / 4.0f;
GL11.glShadeModel(GL11.GL_FLAT);
glShadeModel(GL_FLAT);
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
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();
}
}

View File

@ -39,12 +39,13 @@ import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.Pbuffer;
import org.lwjgl.opengl.PixelFormat;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.vector.Vector2f;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
*
* Tests Pbuffers
@ -189,25 +190,25 @@ public class PbufferTest {
}
// Pbuffer rendering
//clear background
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
// draw white quad
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(quadPosition.x, quadPosition.y, 0);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
glTranslatef(quadPosition.x, quadPosition.y, 0);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
{
GL11.glVertex2i(-50, -50);
GL11.glVertex2i(50, -50);
GL11.glVertex2i(50, 50);
GL11.glVertex2i(-50, 50);
glVertex2i(-50, -50);
glVertex2i(50, -50);
glVertex2i(50, 50);
glVertex2i(-50, 50);
}
GL11.glEnd();
glEnd();
}
GL11.glPopMatrix();
GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 0, 0, 512, 512, 0);
glPopMatrix();
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 512, 512, 0);
try {
Display.makeCurrent();
} catch (LWJGLException e) {
@ -215,34 +216,34 @@ public class PbufferTest {
}
// OpenGL window rendering
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
// draw white quad
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(quadPosition.x, quadPosition.y, 0);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glColor3f(1.0f, 1.0f, 0.0f);
GL11.glBegin(GL11.GL_QUADS);
glTranslatef(quadPosition.x, quadPosition.y, 0);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glColor3f(1.0f, 1.0f, 0.0f);
glBegin(GL_QUADS);
{
GL11.glTexCoord2f(0f, 0f);
GL11.glVertex2i(-50, -50);
GL11.glTexCoord2f(1f, 0f);
GL11.glVertex2i(50, -50);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex2i(50, 50);
GL11.glTexCoord2f(0f, 1f);
GL11.glVertex2i(-50, 50);
glTexCoord2f(0f, 0f);
glVertex2i(-50, -50);
glTexCoord2f(1f, 0f);
glVertex2i(50, -50);
glTexCoord2f(1f, 1f);
glVertex2i(50, 50);
glTexCoord2f(0f, 1f);
glVertex2i(-50, 50);
}
GL11.glEnd();
glEnd();
}
GL11.glPopMatrix();
glPopMatrix();
}
private void initPbuffer() {
try {
pbuffer.makeCurrent();
initGLState(256, 256, 0.5f);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_handle);
glBindTexture(GL_TEXTURE_2D, tex_handle);
Display.makeCurrent();
} catch (Exception e) {
e.printStackTrace();
@ -321,7 +322,7 @@ public class PbufferTest {
private void destroyTexture() {
IntBuffer buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
buffer.put(0, tex_handle);
GL11.glDeleteTextures(buffer);
glDeleteTextures(buffer);
}
/**
@ -343,26 +344,23 @@ public class PbufferTest {
*/
private DisplayMode findDisplayMode(int width, int height, int bpp) throws LWJGLException {
DisplayMode[] modes = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++) {
if (modes[i].getWidth() == width
&& modes[i].getHeight() == height
&& modes[i].getBitsPerPixel() >= bpp) {
return modes[i];
}
}
for ( DisplayMode mode : modes ) {
if ( mode.getWidth() == width && mode.getHeight() == height && mode.getBitsPerPixel() >= bpp )
return mode;
}
return null;
}
private void initGLState(int width, int height, float color) {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, mode.getWidth(), 0, mode.getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, mode.getWidth(), 0, mode.getHeight());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, width, height);
//set clear color to black
GL11.glClearColor(color, color, color, 0.0f);
glClearColor(color, color, color, 0.0f);
}
/**
@ -372,17 +370,17 @@ public class PbufferTest {
//sync frame (only works on windows)
Display.setVSyncEnabled(true);
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
GL11.glEnable(GL11.GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_TEXTURE_2D);
// Create shared texture
IntBuffer buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
GL11.glGenTextures(buffer);
glGenTextures(buffer);
tex_handle = buffer.get(0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_handle);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, tex_handle);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
initGLState(mode.getWidth(), mode.getHeight(), 0f);
}

View File

@ -37,6 +37,9 @@ import org.lwjgl.opengl.*;
import java.util.Random;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL32.*;
/** @author spasi <spasi@users.sourceforge.net> */
public final class SyncTest {
@ -85,7 +88,7 @@ public final class SyncTest {
System.out.println("\n---------\n");
final String version = GL11.glGetString(GL11.GL_VERSION);
final String version = glGetString(GL_VERSION);
System.out.println("GL Version: " + version);
System.out.println("ARB_sync: " + GLContext.getCapabilities().GL_ARB_sync);
@ -99,39 +102,39 @@ public final class SyncTest {
Random rand = new Random(System.currentTimeMillis());
for ( int i = 0; i < clears; i++ ) {
GL11.glClearColor(rand.nextFloat(), rand.nextFloat(), rand.nextFloat(), 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClearColor(rand.nextFloat(), rand.nextFloat(), rand.nextFloat(), 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
GLSync sync = GL32.glFenceSync(GL32.GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
GLSync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
System.out.println("\nWaiting on fence...");
long time = Sys.getTime();
int status = GL32.glClientWaitSync(sync, 0, timeout < 0 ? GL32.GL_TIMEOUT_IGNORED : timeout * 1000 * 1000);
int status = glClientWaitSync(sync, 0, timeout < 0 ? GL_TIMEOUT_IGNORED : timeout * 1000 * 1000);
System.out.println("\nFence sync complete after: " + ((Sys.getTime() - time) / (double)Sys.getTimerResolution()) + " seconds.");
System.out.print("\nWait Status: ");
switch ( status ) {
case GL32.GL_ALREADY_SIGNALED:
case GL_ALREADY_SIGNALED:
System.out.println("ALREADY_SIGNALED");
break;
case GL32.GL_CONDITION_SATISFIED:
case GL_CONDITION_SATISFIED:
System.out.println("CONDITION_SATISFIED");
break;
case GL32.GL_TIMEOUT_EXPIRED:
case GL_TIMEOUT_EXPIRED:
System.out.println("TIMEOUT_EXPIRED");
break;
case GL32.GL_WAIT_FAILED:
case GL_WAIT_FAILED:
System.out.println("WAIT_FAILED");
break;
default:
System.out.println("Unexpected wait status: 0x" + Integer.toHexString(status));
}
System.out.println("Sync Status: " + (GL32.glGetSync(sync, GL32.GL_SYNC_STATUS) == GL32.GL_UNSIGNALED ? "UNSIGNALED" : "SIGNALED"));
System.out.println("Sync Status: " + (glGetSync(sync, GL_SYNC_STATUS) == GL_UNSIGNALED ? "UNSIGNALED" : "SIGNALED"));
GL32.glDeleteSync(sync);
glDeleteSync(sync);
int error = GL11.glGetError();
int error = glGetError();
if ( error != 0 )
System.out.println("\nTest failed with OpenGL error: " + error);
else
@ -141,8 +144,7 @@ public final class SyncTest {
private static DisplayMode chooseMode(DisplayMode[] modes, int width, int height) {
DisplayMode bestMode = null;
for ( int i = 0; i < modes.length; i++ ) {
DisplayMode mode = modes[i];
for ( DisplayMode mode : modes ) {
if ( mode.getWidth() == width && mode.getHeight() == height && mode.getFrequency() <= 85 ) {
if ( bestMode == null || (mode.getBitsPerPixel() >= bestMode.getBitsPerPixel() && mode.getFrequency() > bestMode.getFrequency()) )
bestMode = mode;

View File

@ -49,13 +49,14 @@ import java.nio.IntBuffer;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.ARBBufferObject;
import org.lwjgl.opengl.ARBVertexBufferObject;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.util.glu.GLU;
import static org.lwjgl.opengl.ARBBufferObject.*;
import static org.lwjgl.opengl.ARBVertexBufferObject.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public final class VBOIndexTest {
@ -105,11 +106,11 @@ public final class VBOIndexTest {
private static int buffer_id;
private static int indices_buffer_id;
private static FloatBuffer vertices;
private static ByteBuffer mapped_buffer = null;
private static FloatBuffer mapped_float_buffer = null;
private static ByteBuffer mapped_buffer;
private static FloatBuffer mapped_float_buffer;
private static IntBuffer indices;
private static ByteBuffer mapped_indices_buffer = null;
private static IntBuffer mapped_indices_int_buffer = null;
private static ByteBuffer mapped_indices_buffer;
private static IntBuffer mapped_indices_int_buffer;
public static void main(String[] arguments) {
try {
@ -161,21 +162,21 @@ public final class VBOIndexTest {
* All rendering is done in here
*/
private static void render() {
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);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);
glRotatef(angle, 0, 0, 1.0f);
ByteBuffer new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
ARBBufferObject.GL_WRITE_ONLY_ARB,
ByteBuffer new_mapped_buffer = glMapBufferARB(GL_ARRAY_BUFFER_ARB,
GL_WRITE_ONLY_ARB,
mapped_buffer);
if ( new_mapped_buffer != mapped_buffer )
mapped_float_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
mapped_buffer = new_mapped_buffer;
new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB,
ARBBufferObject.GL_WRITE_ONLY_ARB,
new_mapped_buffer = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
GL_WRITE_ONLY_ARB,
mapped_indices_buffer);
if ( new_mapped_buffer != mapped_indices_buffer )
mapped_indices_int_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asIntBuffer();
@ -188,11 +189,11 @@ public final class VBOIndexTest {
mapped_indices_int_buffer.rewind();
indices.rewind();
mapped_indices_int_buffer.put(indices);
if ( ARBBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB) &&
ARBBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB) ) {
GL11.glDrawElements(GL11.GL_QUADS, 4, GL11.GL_UNSIGNED_INT, 0);
if ( glUnmapBufferARB(GL_ARRAY_BUFFER_ARB) &&
glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB) ) {
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, 0);
}
GL11.glPopMatrix();
glPopMatrix();
}
/**
@ -202,32 +203,32 @@ public final class VBOIndexTest {
System.out.println("Timer resolution: " + Sys.getTimerResolution());
// Go into orthographic projection mode.
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
if ( !GLContext.getCapabilities().GL_ARB_vertex_buffer_object ) {
System.out.println("ARB VBO not supported!");
System.exit(1);
}
IntBuffer int_buffer = ByteBuffer.allocateDirect(8).order(ByteOrder.nativeOrder()).asIntBuffer();
ARBBufferObject.glGenBuffersARB(int_buffer);
glGenBuffersARB(int_buffer);
buffer_id = int_buffer.get(0);
indices_buffer_id = int_buffer.get(1);
ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer_id);
ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indices_buffer_id);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer_id);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indices_buffer_id);
vertices = ByteBuffer.allocateDirect(2 * 4 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
vertices.put(-50).put(-50).put(50).put(-50).put(50).put(50).put(-50).put(50);
vertices.rewind();
indices = ByteBuffer.allocateDirect(4 * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
indices.put(0).put(1).put(2).put(3);
indices.rewind();
ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 2 * 4 * 4, ARBBufferObject.GL_STREAM_DRAW_ARB);
ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, 4 * 4, ARBBufferObject.GL_STREAM_DRAW_ARB);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 2 * 4 * 4, GL_STREAM_DRAW_ARB);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 4 * 4, GL_STREAM_DRAW_ARB);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, 0);
}
/**
@ -237,7 +238,7 @@ public final class VBOIndexTest {
IntBuffer int_buffer = ByteBuffer.allocateDirect(8).order(ByteOrder.nativeOrder()).asIntBuffer();
int_buffer.put(0, buffer_id);
int_buffer.put(1, indices_buffer_id);
ARBBufferObject.glDeleteBuffersARB(int_buffer);
glDeleteBuffersARB(int_buffer);
Display.destroy();
}
}

View File

@ -48,13 +48,14 @@ import java.nio.FloatBuffer;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.ARBBufferObject;
import org.lwjgl.opengl.ARBVertexBufferObject;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.util.glu.GLU;
import static org.lwjgl.opengl.ARBBufferObject.*;
import static org.lwjgl.opengl.ARBVertexBufferObject.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public final class VBOTest {
@ -103,8 +104,8 @@ public final class VBOTest {
private static float angle;
private static int buffer_id;
private static FloatBuffer vertices;
private static ByteBuffer mapped_buffer = null;
private static FloatBuffer mapped_float_buffer = null;
private static ByteBuffer mapped_buffer;
private static FloatBuffer mapped_float_buffer;
public static void main(String[] arguments) {
try {
@ -156,12 +157,12 @@ public final class VBOTest {
* All rendering is done in here
*/
private static void render() {
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);
ByteBuffer new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
ARBBufferObject.GL_WRITE_ONLY_ARB,
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);
glRotatef(angle, 0, 0, 1.0f);
ByteBuffer new_mapped_buffer = glMapBufferARB(GL_ARRAY_BUFFER_ARB,
GL_WRITE_ONLY_ARB,
mapped_buffer);
if ( new_mapped_buffer != mapped_buffer )
mapped_float_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
@ -169,9 +170,9 @@ public final class VBOTest {
mapped_float_buffer.rewind();
vertices.rewind();
mapped_float_buffer.put(vertices);
if ( ARBBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB) )
GL11.glDrawArrays(GL11.GL_QUADS, 0, 4);
GL11.glPopMatrix();
if ( glUnmapBufferARB(GL_ARRAY_BUFFER_ARB) )
glDrawArrays(GL_QUADS, 0, 4);
glPopMatrix();
}
/**
@ -180,30 +181,30 @@ public final class VBOTest {
private static void init() throws Exception {
System.out.println("Timer resolution: " + Sys.getTimerResolution());
// Go into orthographic projection mode.
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
if ( !GLContext.getCapabilities().GL_ARB_vertex_buffer_object ) {
System.out.println("ARB VBO not supported!");
System.exit(1);
}
buffer_id = ARBBufferObject.glGenBuffersARB();
ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer_id);
buffer_id = glGenBuffersARB();
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer_id);
vertices = ByteBuffer.allocateDirect(2 * 4 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
vertices.put(-50).put(-50).put(50).put(-50).put(50).put(50).put(-50).put(50);
ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 2 * 4 * 4, ARBBufferObject.GL_STREAM_DRAW_ARB);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 2 * 4 * 4, GL_STREAM_DRAW_ARB);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, 0);
}
/**
* Cleanup
*/
private static void cleanup() {
ARBBufferObject.glDeleteBuffersARB(buffer_id);
glDeleteBuffersARB(buffer_id);
Display.destroy();
}
}

View File

@ -37,6 +37,9 @@ import org.lwjgl.opengl.*;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL32.*;
/**
* Tests the ARB_create_context extension through the use of the ContextAttribs class.
*
@ -112,11 +115,11 @@ public final class VersionTest {
System.out.println("Requested " + ca);
final String version = GL11.glGetString(GL11.GL_VERSION);
final String version = glGetString(GL_VERSION);
boolean deprecated = false;
try {
GL11.glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
deprecated = true;
} catch (Throwable t) {}
@ -129,10 +132,10 @@ public final class VersionTest {
final boolean coreProfile;
if ( 3 < majorVersion || (majorVersion == 3 && 2 <= minorVersion) ) {
final int profileMask = GL11.glGetInteger(GL32.GL_CONTEXT_PROFILE_MASK);
final int profileMask = glGetInteger(GL_CONTEXT_PROFILE_MASK);
compatibilityProfile = (profileMask & GL32.GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0;
coreProfile = (profileMask & GL32.GL_CONTEXT_CORE_PROFILE_BIT) != 0;
compatibilityProfile = (profileMask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) != 0;
coreProfile = (profileMask & GL_CONTEXT_CORE_PROFILE_BIT) != 0;
} else {
compatibilityProfile = false;
coreProfile = false;
@ -215,8 +218,7 @@ public final class VersionTest {
private static DisplayMode chooseMode(DisplayMode[] modes, int width, int height) {
DisplayMode bestMode = null;
for ( int i = 0; i < modes.length; i++ ) {
DisplayMode mode = modes[i];
for ( DisplayMode mode : modes ) {
if ( mode.getWidth() == width && mode.getHeight() == height && mode.getFrequency() <= 85 ) {
if ( bestMode == null || (mode.getBitsPerPixel() >= bestMode.getBitsPerPixel() && mode.getFrequency() > bestMode.getFrequency()) )
bestMode = mode;

View File

@ -41,11 +41,12 @@ 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.AWTGLCanvas;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import static org.lwjgl.opengl.ARBTransposeMatrix.*;
import static org.lwjgl.opengl.GL11.*;
/**
* <p>
* AWT version of the gears demo
@ -63,7 +64,7 @@ public class AWTGears extends Frame {
private float view_roty = 30.0f;
private float view_rotz = 0.0f;
private float view_rotz;
private int gear1;
@ -71,7 +72,7 @@ public class AWTGears extends Frame {
private int gear3;
private float angle = 0.0f;
private float angle;
/**
* C'tor
@ -104,58 +105,58 @@ public class AWTGears extends Frame {
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();
glEndList();
gear2 = GL11.glGenLists(1);
GL11.glNewList(gear2, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, green);
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();
glEndList();
gear3 = GL11.glGenLists(1);
GL11.glNewList(gear3, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, blue);
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();
glEndList();
GL11.glEnable(GL11.GL_NORMALIZE);
glEnable(GL_NORMALIZE);
GL11.glMatrixMode(GL11.GL_PROJECTION);
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) 300 / (float) 300;
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);
}
/**
@ -180,96 +181,96 @@ public class AWTGears extends Frame {
da = 2.0f * (float) Math.PI / teeth / 4.0f;
GL11.glShadeModel(GL11.GL_FLAT);
glShadeModel(GL_FLAT);
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
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();
}
public static void main(String[] args) throws LWJGLException {

View File

@ -35,12 +35,13 @@ import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ARBTransposeMatrix;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.test.applet.Test;
import static org.lwjgl.opengl.ARBTransposeMatrix.*;
import static org.lwjgl.opengl.GL11.*;
/**
* <p>
* AWT version of the gears demo
@ -55,7 +56,7 @@ public class AWTGearsCanvas extends AWTGLCanvas implements Test {
private float view_roty = 30.0f;
private float view_rotz = 0.0f;
private float view_rotz;
private int gear1;
@ -63,10 +64,10 @@ public class AWTGearsCanvas extends AWTGLCanvas implements Test {
private int gear3;
private float angle = 0.0f;
private float angle;
long startTime = 0;
long fps = 0;
long startTime;
long fps;
int current_width;
int current_height;
@ -89,34 +90,34 @@ public class AWTGearsCanvas extends AWTGLCanvas implements Test {
if (getWidth() != current_width || getHeight() != current_height) {
current_width = getWidth();
current_height = getHeight();
GL11.glViewport(0, 0, current_width, current_height);
glViewport(0, 0, current_width, current_height);
}
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | 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);
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);
GL11.glPushMatrix();
GL11.glTranslatef(-3.0f, -2.0f, 0.0f);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glCallList(gear1);
GL11.glPopMatrix();
glPushMatrix();
glTranslatef(-3.0f, -2.0f, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glCallList(gear1);
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();
glPushMatrix();
glTranslatef(3.1f, -2.0f, 0.0f);
glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
glCallList(gear2);
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();
glPushMatrix();
glTranslatef(-3.1f, 4.2f, 0.0f);
glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
glCallList(gear3);
glPopMatrix();
GL11.glPopMatrix();
glPopMatrix();
swapBuffers();
repaint();
} catch (LWJGLException e) {
@ -127,7 +128,7 @@ public class AWTGearsCanvas extends AWTGLCanvas implements Test {
} else {
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
startTime = System.currentTimeMillis() + 5000;
System.out.println(fps + " frames in " + (float) (timeUsed / 1000f) + " seconds = "
System.out.println(fps + " frames in " + timeUsed / 1000f + " seconds = "
+ (fps / (timeUsed / 1000f)));
fps = 0;
}
@ -144,57 +145,57 @@ public class AWTGearsCanvas extends AWTGLCanvas implements Test {
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();
glEndList();
gear2 = GL11.glGenLists(1);
GL11.glNewList(gear2, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, green);
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();
glEndList();
gear3 = GL11.glGenLists(1);
GL11.glNewList(gear3, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, blue);
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();
glEndList();
GL11.glEnable(GL11.GL_NORMALIZE);
glEnable(GL_NORMALIZE);
GL11.glMatrixMode(GL11.GL_PROJECTION);
glMatrixMode(GL_PROJECTION);
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) 300 / (float) 300;
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);
}
/**
@ -219,96 +220,96 @@ public class AWTGearsCanvas extends AWTGLCanvas implements Test {
da = 2.0f * (float) Math.PI / teeth / 4.0f;
GL11.glShadeModel(GL11.GL_FLAT);
glShadeModel(GL_FLAT);
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
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();
}
/*

View File

@ -38,8 +38,9 @@ import java.awt.event.WindowEvent;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* <p>
@ -71,21 +72,21 @@ public class AWTTest extends Frame {
if (getWidth() != current_width || getHeight() != current_height) {
current_width = getWidth();
current_height = getHeight();
GL11.glViewport(0, 0, current_width, current_height);
glViewport(0, 0, current_width, current_height);
}
GL11.glViewport(0, 0, getWidth(), getHeight());
GL11.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0.0f, (float) getWidth(), 0.0f, (float) getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glColor3f(1f, 1f, 0f);
GL11.glTranslatef(getWidth() / 2.0f, getHeight() / 2.0f, 0.0f);
GL11.glRotatef(angle, 0f, 0f, 1.0f);
GL11.glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
GL11.glPopMatrix();
glViewport(0, 0, getWidth(), getHeight());
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, (float) getWidth(), 0.0f, (float) getHeight());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glColor3f(1f, 1f, 0f);
glTranslatef(getWidth() / 2.0f, getHeight() / 2.0f, 0.0f);
glRotatef(angle, 0f, 0f, 1.0f);
glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
glPopMatrix();
swapBuffers();
repaint();
} catch (LWJGLException e) {
@ -102,20 +103,20 @@ public class AWTTest extends Frame {
if (getWidth() != current_width || getHeight() != current_height) {
current_width = getWidth();
current_height = getHeight();
GL11.glViewport(0, 0, current_width, current_height);
glViewport(0, 0, current_width, current_height);
}
GL11.glViewport(0, 0, getWidth(), getHeight());
GL11.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0.0f, (float) getWidth(), 0.0f, (float) getHeight());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glTranslatef(getWidth() / 2.0f, getHeight() / 2.0f, 0.0f);
GL11.glRotatef(2*angle, 0f, 0f, -1.0f);
GL11.glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
GL11.glPopMatrix();
glViewport(0, 0, getWidth(), getHeight());
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, (float) getWidth(), 0.0f, (float) getHeight());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(getWidth() / 2.0f, getHeight() / 2.0f, 0.0f);
glRotatef(2*angle, 0f, 0f, -1.0f);
glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
glPopMatrix();
swapBuffers();
repaint();
} catch (LWJGLException e) {

View File

@ -51,11 +51,12 @@ import java.util.Hashtable;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ARBTransposeMatrix;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import static org.lwjgl.opengl.ARBTransposeMatrix.*;
import static org.lwjgl.opengl.GL11.*;
/**
* <p>
* </p>
@ -72,13 +73,13 @@ public class DemoBox extends Frame {
private Panel selectionPanel;
/** Hashtable of demos */
private Hashtable selectableDemos;
private Hashtable<String, Demo> selectableDemos;
/**
* Creates a new demo box instance
*/
public DemoBox() {
selectableDemos = new Hashtable();
selectableDemos = new Hashtable<String, Demo>();
selectableDemos.put("default", new NullDemoBox());
selectableDemos.put("clear_color", new ClearColorDemoBox());
selectableDemos.put("gears", new GearsDemoBox());
@ -182,7 +183,7 @@ public class DemoBox extends Frame {
*/
protected void demoSelected(String demo) {
System.out.println("Selecting demo: " + demo);
demoCanvas.setActiveDemo((Demo) selectableDemos.get(demo));
demoCanvas.setActiveDemo(selectableDemos.get(demo));
}
/**
@ -199,10 +200,10 @@ public class DemoBox extends Frame {
* Interface for a demo
*/
public interface Demo {
public boolean isInitialized();
public boolean initialize();
public void render();
public void destroy();
boolean isInitialized();
boolean initialize();
void render();
void destroy();
}
/**
@ -222,14 +223,14 @@ public class DemoBox extends Frame {
/** Render thread */
private Thread renderThread;
public DemoBoxGLCanvas(DemoBox parent) throws LWJGLException {
private DemoBoxGLCanvas(DemoBox parent) throws LWJGLException {
super();
this.parent = parent;
}
// FPS
long startTime = 0;
long fps = 0;
long startTime;
long fps;
protected void paintGL() {
synchronized (this) {
@ -295,7 +296,7 @@ public class DemoBox extends Frame {
}
}
public DemoBoxGLCanvas() throws LWJGLException {
private DemoBoxGLCanvas() throws LWJGLException {
super();
}
@ -346,8 +347,8 @@ public class DemoBox extends Frame {
}
public 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;
@ -378,12 +379,12 @@ public class DemoBox extends Frame {
}
public boolean initialize() {
GL11.glClearColor(0, 0, 0, 1f);
glClearColor(0, 0, 0, 1f);
return true;
}
public void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
}
public void destroy() {
@ -402,7 +403,7 @@ public class DemoBox extends Frame {
private float view_roty = 30.0f;
private float view_rotz = 0.0f;
private float view_rotz;
private int gear1;
@ -410,7 +411,7 @@ public class DemoBox extends Frame {
private int gear3;
private float angle = 0.0f;
private float angle;
public boolean isInitialized() {
return initialized;
@ -427,90 +428,90 @@ public class DemoBox extends Frame {
green.flip();
blue.flip();
GL11.glClearColor(0, 0, 0, 1f);
glClearColor(0, 0, 0, 1f);
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();
glEndList();
gear2 = GL11.glGenLists(1);
GL11.glNewList(gear2, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, green);
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();
glEndList();
gear3 = GL11.glGenLists(1);
GL11.glNewList(gear3, GL11.GL_COMPILE);
GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, blue);
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();
glEndList();
GL11.glEnable(GL11.GL_NORMALIZE);
glEnable(GL_NORMALIZE);
GL11.glMatrixMode(GL11.GL_PROJECTION);
glMatrixMode(GL_PROJECTION);
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) 300 / (float) 300;
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);
return initialized = true;
}
public void render() {
angle += 2.0f;
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | 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);
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);
GL11.glPushMatrix();
GL11.glTranslatef(-3.0f, -2.0f, 0.0f);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glCallList(gear1);
GL11.glPopMatrix();
glPushMatrix();
glTranslatef(-3.0f, -2.0f, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glCallList(gear1);
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();
glPushMatrix();
glTranslatef(3.1f, -2.0f, 0.0f);
glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
glCallList(gear2);
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();
glPushMatrix();
glTranslatef(-3.1f, 4.2f, 0.0f);
glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
glCallList(gear3);
glPopMatrix();
GL11.glPopMatrix();
glPopMatrix();
}
/**
@ -535,102 +536,102 @@ public class DemoBox extends Frame {
da = 2.0f * (float) Math.PI / teeth / 4.0f;
GL11.glShadeModel(GL11.GL_FLAT);
glShadeModel(GL_FLAT);
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
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();
}
public void destroy() {
GL11.glDeleteLists(gear1, 1);
GL11.glDeleteLists(gear2, 1);
GL11.glDeleteLists(gear3, 1);
glDeleteLists(gear1, 1);
glDeleteLists(gear2, 1);
glDeleteLists(gear3, 1);
initialized = false;
}
}

View File

@ -41,8 +41,9 @@ import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* <p>
@ -53,7 +54,7 @@ import org.lwjgl.util.glu.GLU;
* $Id$
*/
public class DisplayParentTest extends Frame {
boolean killswitch = false;
boolean killswitch;
public DisplayParentTest() throws LWJGLException {
setTitle("LWJGL Display Parent Test");
setSize(640, 320);
@ -90,18 +91,18 @@ public class DisplayParentTest extends Frame {
continue;
}
GL11.glViewport(0, 0, width, height);
GL11.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0.0f, (float) width, 0.0f, (float) height);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glTranslatef(width / 2.0f, height / 2.0f, 0.0f);
GL11.glRotatef(2*angle, 0f, 0f, -1.0f);
GL11.glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
GL11.glPopMatrix();
glViewport(0, 0, width, height);
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, (float) width, 0.0f, (float) height);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(width / 2.0f, height / 2.0f, 0.0f);
glRotatef(2*angle, 0f, 0f, -1.0f);
glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
glPopMatrix();
Display.update();
while(Keyboard.next()) {
// closing on ESCAPE

View File

@ -36,11 +36,13 @@ import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.*;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.glu.Sphere;
import java.nio.FloatBuffer;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* A test of loading textures in a background thread. This can be achieved in 2 ways:
* <br>
@ -85,15 +87,15 @@ public final class BackgroundLoadTest {
else {
handleIO();
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderObject();
Util.checkGLError();
// Restore camera position.
GL11.glPopMatrix();
GL11.glPushMatrix();
glPopMatrix();
glPushMatrix();
}
Display.update();
@ -131,59 +133,59 @@ public final class BackgroundLoadTest {
kill(e.getMessage());
}
GL11.glViewport(0, 0, displayMode.getWidth(), displayMode.getHeight());
glViewport(0, 0, displayMode.getWidth(), displayMode.getHeight());
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45, displayMode.getWidth() / (float)displayMode.getHeight(), 1.0f, 10.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, displayMode.getWidth() / (float)displayMode.getHeight(), 1.0f, 10.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Setup camera position.
GL11.glTranslatef(0.0f, 0.0f, -4.0f);
GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
GL11.glPushMatrix();
glTranslatef(0.0f, 0.0f, -4.0f);
glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
glPushMatrix();
GL11.glClearDepth(1.0f);
GL11.glDepthFunc(GL11.GL_LEQUAL);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
GL11.glFrontFace(GL11.GL_CCW);
GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
glFrontFace(GL_CCW);
glPolygonMode(GL_FRONT, GL_FILL);
GL11.glCullFace(GL11.GL_BACK);
GL11.glEnable(GL11.GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.0f);
GL11.glEnable(GL11.GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glEnable(GL_ALPHA_TEST);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND);
GL11.glShadeModel(GL11.GL_SMOOTH);
glShadeModel(GL_SMOOTH);
final FloatBuffer vectorBuffer = BufferUtils.createFloatBuffer(4);
vectorBuffer.clear();
vectorBuffer.put(0, 1.0f).put(1, 1.0f).put(2, 1.0f).put(3, 1.0f);
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, vectorBuffer);
glLight(GL_LIGHT0, GL_DIFFUSE, vectorBuffer);
vectorBuffer.put(0, 1.0f).put(1, 1.0f).put(2, 1.0f).put(3, 1.0f);
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, vectorBuffer);
glLight(GL_LIGHT0, GL_AMBIENT, vectorBuffer);
vectorBuffer.put(0, 1.0f).put(1, 1.0f).put(2, 0.5f).put(3, 1.0f);
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, vectorBuffer);
glLight(GL_LIGHT0, GL_SPECULAR, vectorBuffer);
vectorBuffer.put(0, -1.0f / 3.0f).put(1, 1.0f / 3.0f).put(2, 1.0f / 3.0f).put(3, 0.0f); // Infinite
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, vectorBuffer);
glLight(GL_LIGHT0, GL_POSITION, vectorBuffer);
vectorBuffer.put(0, 0.2f).put(1, 0.2f).put(2, 0.2f).put(3, 1.0f);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, vectorBuffer);
glLightModel(GL_LIGHT_MODEL_AMBIENT, vectorBuffer);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
sphere = new Sphere();
@ -222,31 +224,30 @@ public final class BackgroundLoadTest {
}
static void renderObject() {
GL11.glColor3f(1.0f, 1.0f, 1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
int texID = backgroundLoader.getTexID();
if ( texID == 0 ) {
sphere.setTextureFlag(false);
GL11.glDisable(GL11.GL_TEXTURE_2D);
glDisable(GL_TEXTURE_2D);
} else {
sphere.setTextureFlag(true);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texID);
}
sphere.draw(1.0f, 32, 32);
if ( texID != 0 ) { // Unbind so we can update from the background thread.
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
GL11.glDisable(GL11.GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
}
}
private static DisplayMode chooseMode(DisplayMode[] modes, int width, int height) {
DisplayMode bestMode = null;
for ( int i = 0; i < modes.length; i++ ) {
DisplayMode mode = modes[i];
for ( DisplayMode mode : modes ) {
if ( mode.getWidth() == width && mode.getHeight() == height && mode.getFrequency() <= 85 ) {
if ( bestMode == null || (mode.getBitsPerPixel() >= bestMode.getBitsPerPixel() && mode.getFrequency() > bestMode.getFrequency()) )
bestMode = mode;

View File

@ -40,12 +40,13 @@ package org.lwjgl.test.opengl.multithread;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Drawable;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Color;
import org.lwjgl.util.ReadableColor;
import java.nio.ByteBuffer;
import static org.lwjgl.opengl.GL11.*;
abstract class BackgroundLoader {
private static final int WIDTH = 32;
@ -97,14 +98,14 @@ abstract class BackgroundLoader {
// Create a "dummy" texture while we wait for texture IO
createCheckerTexture(Color.RED, Color.WHITE, 2);
texID = GL11.glGenTextures();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, WIDTH, HEIGHT, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, texture);
texID = glGenTextures();
glBindTexture(GL_TEXTURE_2D, texID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}
System.out.println("** Dummy texture created **");
@ -128,13 +129,13 @@ abstract class BackgroundLoader {
else
createGradientTexture(Color.GREEN, Color.YELLOW);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, WIDTH, HEIGHT, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, texture);
glBindTexture(GL_TEXTURE_2D, texID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
glBindTexture(GL_TEXTURE_2D, 0);
System.out.println("** Created new gradient texture **");

View File

@ -38,12 +38,13 @@ import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.Pbuffer;
import org.lwjgl.opengl.PixelFormat;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.vector.Vector2f;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* <p/>
* Tests Pbuffers
@ -215,25 +216,25 @@ public final class PbufferTest {
texRenderer.enable();
// Clear the background
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
// Draw quad with gradient
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(quadPosition.x * texScaleX, quadPosition.y * texScaleY, 0);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
glTranslatef(quadPosition.x * texScaleX, quadPosition.y * texScaleY, 0);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
{
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex2i(-QUAD_SIZE, -QUAD_SIZE);
GL11.glVertex2i(QUAD_SIZE, -QUAD_SIZE);
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex2i(QUAD_SIZE, QUAD_SIZE);
GL11.glVertex2i(-QUAD_SIZE, QUAD_SIZE);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2i(-QUAD_SIZE, -QUAD_SIZE);
glVertex2i(QUAD_SIZE, -QUAD_SIZE);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2i(QUAD_SIZE, QUAD_SIZE);
glVertex2i(-QUAD_SIZE, QUAD_SIZE);
}
GL11.glEnd();
glEnd();
}
GL11.glPopMatrix();
glPopMatrix();
// Refresh the texture
texRenderer.updateTexture();
@ -247,28 +248,28 @@ public final class PbufferTest {
throw new RuntimeException(e);
}
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);
// draw white quad
GL11.glPushMatrix();
glPushMatrix();
{
GL11.glTranslatef(quadPosition.x, quadPosition.y, 0);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
glTranslatef(quadPosition.x, quadPosition.y, 0);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
{
GL11.glTexCoord2f(0f, 0f);
GL11.glVertex2i(-QUAD_SIZE, -QUAD_SIZE);
GL11.glTexCoord2f(1f, 0f);
GL11.glVertex2i(QUAD_SIZE, -QUAD_SIZE);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex2i(QUAD_SIZE, QUAD_SIZE);
GL11.glTexCoord2f(0f, 1f);
GL11.glVertex2i(-QUAD_SIZE, QUAD_SIZE);
glTexCoord2f(0f, 0f);
glVertex2i(-QUAD_SIZE, -QUAD_SIZE);
glTexCoord2f(1f, 0f);
glVertex2i(QUAD_SIZE, -QUAD_SIZE);
glTexCoord2f(1f, 1f);
glVertex2i(QUAD_SIZE, QUAD_SIZE);
glTexCoord2f(0f, 1f);
glVertex2i(-QUAD_SIZE, QUAD_SIZE);
}
GL11.glEnd();
glEnd();
}
GL11.glPopMatrix();
glPopMatrix();
}
/**
@ -334,7 +335,7 @@ public final class PbufferTest {
// Destroy texture
IntBuffer buffer = BufferUtils.createIntBuffer(1);
buffer.put(0, texID);
GL11.glDeleteTextures(buffer);
glDeleteTextures(buffer);
texRenderer.destroy();
Display.destroy();
@ -351,27 +352,24 @@ public final class PbufferTest {
*/
private DisplayMode findDisplayMode(int width, int height, int bpp) throws LWJGLException {
DisplayMode[] modes = Display.getAvailableDisplayModes();
for ( int i = 0; i < modes.length; i++ ) {
if ( modes[i].getWidth() == width
&& modes[i].getHeight() == height
&& modes[i].getBitsPerPixel() >= bpp ) {
return modes[i];
}
for ( DisplayMode mode : modes ) {
if ( mode.getWidth() == width && mode.getHeight() == height && mode.getBitsPerPixel() >= bpp )
return mode;
}
return null;
}
static void initGLState(int width, int height, float color) {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, width, 0, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glViewport(0, 0, width, height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, width, height);
//set clear color
GL11.glClearColor(color, color, color, 0.0f);
glClearColor(color, color, color, 0.0f);
}
/**
@ -383,18 +381,18 @@ public final class PbufferTest {
// Create shared texture
IntBuffer buffer = BufferUtils.createIntBuffer(1);
GL11.glGenTextures(buffer);
glGenTextures(buffer);
texID = buffer.get(0);
GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
GL11.glEnable(GL11.GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
glBindTexture(GL_TEXTURE_2D, texID);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
initGLState(mode.getWidth(), mode.getHeight(), 0.0f);
}

View File

@ -33,10 +33,11 @@ package org.lwjgl.test.opengl.pbuffers;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.Pbuffer;
import org.lwjgl.opengl.PixelFormat;
import static org.lwjgl.opengl.GL11.*;
final class UniqueRenderer extends TextureRenderer {
UniqueRenderer(final int width, final int height, final int texID) {
@ -53,7 +54,7 @@ final class UniqueRenderer extends TextureRenderer {
pbuffer.makeCurrent();
PbufferTest.initGLState(width, height, 0.5f);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
glBindTexture(GL_TEXTURE_2D, texID);
Display.makeCurrent();
} catch (LWJGLException e) {
@ -66,7 +67,7 @@ final class UniqueRenderer extends TextureRenderer {
public void updateTexture() {
// Copy the pbuffer contents to the texture.
GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 0, 0, width, height, 0);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, width, height, 0);
}
}

View File

@ -33,11 +33,12 @@ package org.lwjgl.test.opengl.pbuffers;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.Pbuffer;
import org.lwjgl.opengl.PixelFormat;
import org.lwjgl.opengl.RenderTexture;
import static org.lwjgl.opengl.GL11.*;
final class UniqueRendererRTT extends TextureRenderer {
UniqueRendererRTT(final int width, final int height, final int texID) {
@ -56,7 +57,7 @@ final class UniqueRendererRTT extends TextureRenderer {
pbuffer.makeCurrent();
PbufferTest.initGLState(width, height, 0.5f);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
glBindTexture(GL_TEXTURE_2D, texID);
Display.makeCurrent();
} catch (LWJGLException e) {

View File

@ -38,15 +38,17 @@
package org.lwjgl.test.opengl.shaders;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.ARBProgram;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.GL11;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import static org.lwjgl.opengl.ARBProgram.*;
import static org.lwjgl.opengl.ARBShaderObjects.*;
import static org.lwjgl.opengl.GL11.*;
abstract class Shader {
protected static ByteBuffer fileBuffer = BufferUtils.createByteBuffer(1024 * 10);
@ -62,13 +64,11 @@ abstract class Shader {
String shader = null;
try {
ClassLoader loader = ShadersTest.class.getClassLoader();
InputStream inputStream = loader.getResourceAsStream("org/lwjgl/test/opengl/shaders/" + file);
InputStream source = ShadersTest.class.getResourceAsStream(file);
if ( source == null ) // dev-mode
source = new FileInputStream("src/java/org/lwjgl/test/opengl/shaders/" + file);
if ( inputStream == null )
ShadersTest.kill("A shader source file could not be found: " + file);
BufferedInputStream stream = new BufferedInputStream(inputStream);
BufferedInputStream stream = new BufferedInputStream(source);
byte character;
while ( (character = (byte)stream.read()) != -1 )
@ -91,8 +91,8 @@ abstract class Shader {
}
protected static void checkProgramError(String programFile, String programSource) {
if ( GL11.glGetError() == GL11.GL_INVALID_OPERATION ) {
final int errorPos = GL11.glGetInteger(ARBProgram.GL_PROGRAM_ERROR_POSITION_ARB);
if ( glGetError() == GL_INVALID_OPERATION ) {
final int errorPos = glGetInteger(GL_PROGRAM_ERROR_POSITION_ARB);
int lineStart = 0;
int lineEnd = -1;
for ( int i = 0; i < programSource.length(); i++ ) {
@ -111,12 +111,12 @@ abstract class Shader {
ShadersTest.kill("Low-level program error in file: " + programFile
+ "\n\tError line: " + programSource.substring(lineStart, lineEnd)
+ "\n\tError message: " + GL11.glGetString(ARBProgram.GL_PROGRAM_ERROR_STRING_ARB));
+ "\n\tError message: " + glGetString(GL_PROGRAM_ERROR_STRING_ARB));
}
}
protected static int getUniformLocation(int ID, String name) {
final int location = ARBShaderObjects.glGetUniformLocationARB(ID, name);
final int location = glGetUniformLocationARB(ID, name);
if ( location == -1 )
throw new IllegalArgumentException("The uniform \"" + name + "\" does not exist in the Shader Program.");
@ -125,24 +125,24 @@ abstract class Shader {
}
protected static void printShaderObjectInfoLog(String file, int ID) {
final int logLength = ARBShaderObjects.glGetObjectParameteriARB(ID, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB);
final int logLength = glGetObjectParameteriARB(ID, GL_OBJECT_INFO_LOG_LENGTH_ARB);
if ( logLength <= 1 )
return;
System.out.println("\nInfo Log of Shader Object: " + file);
System.out.println("--------------------------");
System.out.println(ARBShaderObjects.glGetInfoLogARB(ID, logLength));
System.out.println(glGetInfoLogARB(ID, logLength));
}
protected static void printShaderProgramInfoLog(int ID) {
final int logLength = ARBShaderObjects.glGetObjectParameteriARB(ID, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB);
final int logLength = glGetObjectParameteriARB(ID, GL_OBJECT_INFO_LOG_LENGTH_ARB);
if ( logLength <= 1 )
return;
System.out.println("\nShader Program Info Log: ");
System.out.println("--------------------------");
System.out.println(ARBShaderObjects.glGetInfoLogARB(ID, logLength));
System.out.println(glGetInfoLogARB(ID, logLength));
}
}

View File

@ -39,9 +39,10 @@
package org.lwjgl.test.opengl.shaders;
import org.lwjgl.opengl.ARBFragmentProgram;
import org.lwjgl.opengl.ARBProgram;
import org.lwjgl.opengl.ARBVertexProgram;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.ARBProgram.*;
import static org.lwjgl.opengl.GL11.*;
final class ShaderFP extends Shader {
@ -60,10 +61,10 @@ final class ShaderFP extends Shader {
vpFile = vpShaderFile;
vpSource = getShaderText(vpShaderFile);
vpID = ARBProgram.glGenProgramsARB();
vpID = glGenProgramsARB();
ARBProgram.glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, vpID);
ARBProgram.glProgramStringARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, ARBProgram.GL_PROGRAM_FORMAT_ASCII_ARB, vpSource);
glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, vpID);
glProgramStringARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, vpSource);
checkProgramError(vpFile, vpSource);
@ -71,37 +72,37 @@ final class ShaderFP extends Shader {
fpFile = fpShaderFile;
fpSource = getShaderText(fpShaderFile);
fpID = ARBProgram.glGenProgramsARB();
fpID = glGenProgramsARB();
ARBProgram.glBindProgramARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, fpID);
ARBProgram.glProgramStringARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, ARBProgram.GL_PROGRAM_FORMAT_ASCII_ARB, fpSource);
glBindProgramARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, fpID);
glProgramStringARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, fpSource);
checkProgramError(fpFile, fpSource);
}
void render() {
GL11.glEnable(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB);
ARBProgram.glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, vpID);
glEnable(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB);
glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, vpID);
GL11.glEnable(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB);
ARBProgram.glBindProgramARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, fpID);
glEnable(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB);
glBindProgramARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, fpID);
ARBProgram.glProgramLocalParameter4fARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, 0,
ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f, 0.0f, 0.0f);
glProgramLocalParameter4fARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, 0,
ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f, 0.0f, 0.0f);
ARBProgram.glProgramLocalParameter4fARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, 0,
ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f,
-ShadersTest.getDisplayWidth() * 0.5f, -ShadersTest.getDisplayHeight() * 0.5f);
glProgramLocalParameter4fARB(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB, 0,
ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f,
-ShadersTest.getDisplayWidth() * 0.5f, -ShadersTest.getDisplayHeight() * 0.5f);
ShadersTest.renderObject();
GL11.glDisable(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB);
GL11.glDisable(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB);
glDisable(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB);
glDisable(ARBFragmentProgram.GL_FRAGMENT_PROGRAM_ARB);
}
void cleanup() {
ARBProgram.glDeleteProgramsARB(vpID);
ARBProgram.glDeleteProgramsARB(fpID);
glDeleteProgramsARB(vpID);
glDeleteProgramsARB(fpID);
}
}

View File

@ -38,10 +38,10 @@
package org.lwjgl.test.opengl.shaders;
import org.lwjgl.opengl.ARBFragmentShader;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.ARBVertexShader;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.ARBFragmentShader.*;
import static org.lwjgl.opengl.ARBShaderObjects.*;
import static org.lwjgl.opengl.ARBVertexShader.*;
import static org.lwjgl.opengl.GL11.*;
final class ShaderFSH extends Shader {
@ -64,64 +64,64 @@ final class ShaderFSH extends Shader {
this.vshFile = vshFile;
vshSource = getShaderText(vshFile);
vshID = ARBShaderObjects.glCreateShaderObjectARB(ARBVertexShader.GL_VERTEX_SHADER_ARB);
ARBShaderObjects.glShaderSourceARB(vshID, vshSource);
ARBShaderObjects.glCompileShaderARB(vshID);
vshID = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
glShaderSourceARB(vshID, vshSource);
glCompileShaderARB(vshID);
printShaderObjectInfoLog(this.vshFile, vshID);
if ( ARBShaderObjects.glGetObjectParameteriARB(vshID, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE )
if ( glGetObjectParameteriARB(vshID, GL_OBJECT_COMPILE_STATUS_ARB) == GL_FALSE )
ShadersTest.kill("A compilation error occured in a vertex shader.");
// Initialize the fragment shader.
this.fshFile = fshFile;
fshSource = getShaderText(fshFile);
fshID = ARBShaderObjects.glCreateShaderObjectARB(ARBFragmentShader.GL_FRAGMENT_SHADER_ARB);
ARBShaderObjects.glShaderSourceARB(fshID, fshSource);
ARBShaderObjects.glCompileShaderARB(fshID);
fshID = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
glShaderSourceARB(fshID, fshSource);
glCompileShaderARB(fshID);
printShaderObjectInfoLog(this.fshFile, fshID);
if ( ARBShaderObjects.glGetObjectParameteriARB(fshID, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE )
if ( glGetObjectParameteriARB(fshID, GL_OBJECT_COMPILE_STATUS_ARB) == GL_FALSE )
ShadersTest.kill("A compilation error occured in a fragment shader.");
// Initialize the shader program.
programID = ARBShaderObjects.glCreateProgramObjectARB();
programID = glCreateProgramObjectARB();
ARBShaderObjects.glAttachObjectARB(programID, vshID);
ARBShaderObjects.glAttachObjectARB(programID, fshID);
glAttachObjectARB(programID, vshID);
glAttachObjectARB(programID, fshID);
ARBShaderObjects.glLinkProgramARB(programID);
glLinkProgramARB(programID);
printShaderProgramInfoLog(programID);
if ( ARBShaderObjects.glGetObjectParameteriARB(programID, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE )
if ( glGetObjectParameteriARB(programID, GL_OBJECT_LINK_STATUS_ARB) == GL_FALSE )
ShadersTest.kill("A linking error occured in a shader program.");
uniformLocation = getUniformLocation(programID, "UNIFORMS");
}
void render() {
ARBShaderObjects.glUseProgramObjectARB(programID);
glUseProgramObjectARB(programID);
ARBShaderObjects.glUniform4fARB(uniformLocation,
ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f,
-ShadersTest.getDisplayWidth() * 0.5f, -ShadersTest.getDisplayHeight() * 0.5f);
glUniform4fARB(uniformLocation,
ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f,
-ShadersTest.getDisplayWidth() * 0.5f, -ShadersTest.getDisplayHeight() * 0.5f);
ShadersTest.renderObject();
ARBShaderObjects.glUseProgramObjectARB(0);
glUseProgramObjectARB(0);
}
void cleanup() {
ARBShaderObjects.glDetachObjectARB(programID, vshID);
ARBShaderObjects.glDetachObjectARB(programID, fshID);
glDetachObjectARB(programID, vshID);
glDetachObjectARB(programID, fshID);
ARBShaderObjects.glDeleteObjectARB(vshID);
ARBShaderObjects.glDeleteObjectARB(fshID);
glDeleteObjectARB(vshID);
glDeleteObjectARB(fshID);
ARBShaderObjects.glDeleteObjectARB(programID);
glDeleteObjectARB(programID);
}
}

View File

@ -43,6 +43,11 @@ import org.lwjgl.opengl.*;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import static org.lwjgl.opengl.ARBUniformBufferObject.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
final class ShaderUNI extends Shader {
final String file;
@ -64,52 +69,52 @@ final class ShaderUNI extends Shader {
file = shaderFile;
source = getShaderText(shaderFile);
shaderID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
GL20.glShaderSource(shaderID, source);
GL20.glCompileShader(shaderID);
shaderID = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shaderID, source);
glCompileShader(shaderID);
printShaderObjectInfoLog(file, shaderID);
if ( GL20.glGetShader(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE )
if ( glGetShader(shaderID, GL_COMPILE_STATUS) == GL_FALSE )
ShadersTest.kill("A compilation error occured in a vertex shader.");
programID = GL20.glCreateProgram();
programID = glCreateProgram();
GL20.glAttachShader(programID, shaderID);
GL20.glLinkProgram(programID);
glAttachShader(programID, shaderID);
glLinkProgram(programID);
printShaderProgramInfoLog(programID);
if ( GL20.glGetProgram(programID, GL20.GL_LINK_STATUS) == GL11.GL_FALSE )
if ( glGetProgram(programID, GL_LINK_STATUS) == GL_FALSE )
ShadersTest.kill("A linking error occured in a shader program.");
final String[] uniformNames = { "uniformA", "uniformB" };
// Get uniform block index and data size
final int blockIndex = ARBUniformBufferObject.glGetUniformBlockIndex(programID, "test");
final int blockSize = ARBUniformBufferObject.glGetActiveUniformBlock(programID, blockIndex, ARBUniformBufferObject.GL_UNIFORM_BLOCK_DATA_SIZE);
final int blockIndex = glGetUniformBlockIndex(programID, "test");
final int blockSize = glGetActiveUniformBlock(programID, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE);
System.out.println("blockSize = " + blockSize);
// Create uniform buffer object and allocate a ByteBuffer
bufferID = GL15.glGenBuffers();
GL15.glBindBuffer(ARBUniformBufferObject.GL_UNIFORM_BUFFER, bufferID);
GL15.glBufferData(ARBUniformBufferObject.GL_UNIFORM_BUFFER, blockSize, GL15.GL_DYNAMIC_DRAW);
bufferID = glGenBuffers();
glBindBuffer(GL_UNIFORM_BUFFER, bufferID);
glBufferData(GL_UNIFORM_BUFFER, blockSize, GL_DYNAMIC_DRAW);
buffer = BufferUtils.createFloatBuffer(blockSize);
// Attach UBO and associate uniform block to binding point 0
ARBUniformBufferObject.glBindBufferBase(ARBUniformBufferObject.GL_UNIFORM_BUFFER, 0, bufferID);
ARBUniformBufferObject.glUniformBlockBinding(programID, blockIndex, 0);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, bufferID);
glUniformBlockBinding(programID, blockIndex, 0);
// Get uniform information
IntBuffer indexes = BufferUtils.createIntBuffer(uniformNames.length);
IntBuffer params = BufferUtils.createIntBuffer(uniformNames.length);
ARBUniformBufferObject.glGetUniformIndices(programID, uniformNames, indexes);
glGetUniformIndices(programID, uniformNames, indexes);
uniformA_index = indexes.get(0);
uniformB_index = indexes.get(1);
ARBUniformBufferObject.glGetActiveUniforms(programID, indexes, ARBUniformBufferObject.GL_UNIFORM_OFFSET, params);
glGetActiveUniforms(programID, indexes, GL_UNIFORM_OFFSET, params);
uniformA_offset = params.get(0);
uniformB_offset = params.get(1);
@ -123,7 +128,7 @@ final class ShaderUNI extends Shader {
}
void render() {
GL20.glUseProgram(programID);
glUseProgram(programID);
//* -- std140 layout
// Uniform A
@ -131,34 +136,34 @@ final class ShaderUNI extends Shader {
// Uniform B - str140 alignment at 16 bytes
buffer.put(4, 0.0f).put(5, 0.7f).put(6, 0.0f);
GL15.glBindBuffer(ARBUniformBufferObject.GL_UNIFORM_BUFFER, bufferID);
GL15.glBufferData(ARBUniformBufferObject.GL_UNIFORM_BUFFER, buffer, GL15.GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, bufferID);
glBufferData(GL_UNIFORM_BUFFER, buffer, GL_DYNAMIC_DRAW);
//*/
/* -- non-std140 layout
// Uniform A
buffer.put(ShadersTest.getSin()).put(ShadersTest.getSpecularity() * 8.0f);
buffer.flip();
GL15.glBufferSubData(ARBUniformBufferObject.GL_UNIFORM_BUFFER, uniformA_offset, buffer);
glBufferSubData(GL_UNIFORM_BUFFER, uniformA_offset, buffer);
// Uniform B
buffer.clear();
buffer.put(0.0f).put(0.7f).put(0.0f);
buffer.flip();
GL15.glBufferSubData(ARBUniformBufferObject.GL_UNIFORM_BUFFER, uniformB_offset, buffer);
glBufferSubData(GL_UNIFORM_BUFFER, uniformB_offset, buffer);
//*/
ShadersTest.renderObject();
GL20.glUseProgram(0);
glUseProgram(0);
}
void cleanup() {
GL15.glDeleteBuffers(bufferID);
glDeleteBuffers(bufferID);
GL20.glDetachShader(programID, shaderID);
glDetachShader(programID, shaderID);
GL20.glDeleteShader(shaderID);
GL20.glDeleteProgram(programID);
glDeleteShader(shaderID);
glDeleteProgram(programID);
}
}

View File

@ -38,9 +38,8 @@
package org.lwjgl.test.opengl.shaders;
import org.lwjgl.opengl.ARBProgram;
import org.lwjgl.opengl.ARBVertexProgram;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.ARBVertexProgram.*;
import static org.lwjgl.opengl.GL11.*;
final class ShaderVP extends Shader {
@ -53,28 +52,28 @@ final class ShaderVP extends Shader {
file = shaderFile;
source = getShaderText(shaderFile);
ID = ARBProgram.glGenProgramsARB();
ID = glGenProgramsARB();
ARBProgram.glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, ID);
ARBProgram.glProgramStringARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, ARBProgram.GL_PROGRAM_FORMAT_ASCII_ARB, source);
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ID);
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, source);
checkProgramError(file, source);
}
void render() {
GL11.glEnable(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB);
ARBProgram.glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, ID);
glEnable(GL_VERTEX_PROGRAM_ARB);
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ID);
ARBProgram.glProgramLocalParameter4fARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, 0,
ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f, 0.0f, 0.0f);
glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 0,
ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f, 0.0f, 0.0f);
ShadersTest.renderObject();
GL11.glDisable(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB);
glDisable(GL_VERTEX_PROGRAM_ARB);
}
void cleanup() {
ARBProgram.glDeleteProgramsARB(ID);
glDeleteProgramsARB(ID);
}
}

View File

@ -38,9 +38,9 @@
package org.lwjgl.test.opengl.shaders;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.ARBVertexShader;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.ARBShaderObjects.*;
import static org.lwjgl.opengl.ARBVertexShader.*;
import static org.lwjgl.opengl.GL11.*;
final class ShaderVSH extends Shader {
@ -56,43 +56,43 @@ final class ShaderVSH extends Shader {
file = shaderFile;
source = getShaderText(shaderFile);
shaderID = ARBShaderObjects.glCreateShaderObjectARB(ARBVertexShader.GL_VERTEX_SHADER_ARB);
ARBShaderObjects.glShaderSourceARB(shaderID, source);
ARBShaderObjects.glCompileShaderARB(shaderID);
shaderID = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
glShaderSourceARB(shaderID, source);
glCompileShaderARB(shaderID);
printShaderObjectInfoLog(file, shaderID);
if ( ARBShaderObjects.glGetObjectParameteriARB(shaderID, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB) == GL11.GL_FALSE )
if ( glGetObjectParameteriARB(shaderID, GL_OBJECT_COMPILE_STATUS_ARB) == GL_FALSE )
ShadersTest.kill("A compilation error occured in a vertex shader.");
programID = ARBShaderObjects.glCreateProgramObjectARB();
programID = glCreateProgramObjectARB();
ARBShaderObjects.glAttachObjectARB(programID, shaderID);
ARBShaderObjects.glLinkProgramARB(programID);
glAttachObjectARB(programID, shaderID);
glLinkProgramARB(programID);
printShaderProgramInfoLog(programID);
if ( ARBShaderObjects.glGetObjectParameteriARB(programID, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE )
if ( glGetObjectParameteriARB(programID, GL_OBJECT_LINK_STATUS_ARB) == GL_FALSE )
ShadersTest.kill("A linking error occured in a shader program.");
uniformLocation = getUniformLocation(programID, "UNIFORMS");
}
void render() {
ARBShaderObjects.glUseProgramObjectARB(programID);
glUseProgramObjectARB(programID);
ARBShaderObjects.glUniform2fARB(uniformLocation, ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f);
glUniform2fARB(uniformLocation, ShadersTest.getSin(), ShadersTest.getSpecularity() * 8.0f);
ShadersTest.renderObject();
ARBShaderObjects.glUseProgramObjectARB(0);
glUseProgramObjectARB(0);
}
void cleanup() {
ARBShaderObjects.glDetachObjectARB(programID, shaderID);
glDetachObjectARB(programID, shaderID);
ARBShaderObjects.glDeleteObjectARB(shaderID);
ARBShaderObjects.glDeleteObjectARB(programID);
glDeleteObjectARB(shaderID);
glDeleteObjectARB(programID);
}
}

View File

@ -46,9 +46,11 @@ import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.*;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.glu.Sphere;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public final class ShadersTest {
private static DisplayMode displayMode;
@ -94,7 +96,7 @@ public final class ShadersTest {
handleIO();
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if ( shader != null )
shader.render();
@ -102,8 +104,8 @@ public final class ShadersTest {
renderObject();
// Restore camera position.
GL11.glPopMatrix();
GL11.glPushMatrix();
glPopMatrix();
glPushMatrix();
}
Display.update();
@ -178,65 +180,65 @@ public final class ShadersTest {
argsError();
}
GL11.glViewport(0, 0, displayMode.getWidth(), displayMode.getHeight());
glViewport(0, 0, displayMode.getWidth(), displayMode.getHeight());
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45, displayMode.getWidth() / (float)displayMode.getHeight(), 1.0f, 10.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, displayMode.getWidth() / (float)displayMode.getHeight(), 1.0f, 10.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Setup camera position.
GL11.glTranslatef(0.0f, 0.0f, -4.0f);
GL11.glRotatef(15.0f, 1.0f, 0.0f, 0.0f);
GL11.glPushMatrix();
glTranslatef(0.0f, 0.0f, -4.0f);
glRotatef(15.0f, 1.0f, 0.0f, 0.0f);
glPushMatrix();
GL11.glClearDepth(1.0f);
GL11.glDepthFunc(GL11.GL_LEQUAL);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
GL11.glFrontFace(GL11.GL_CCW);
GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
glFrontFace(GL_CCW);
glPolygonMode(GL_FRONT, GL_FILL);
GL11.glCullFace(GL11.GL_BACK);
GL11.glEnable(GL11.GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
GL11.glAlphaFunc(GL11.GL_NOTEQUAL, 0.0f);
GL11.glEnable(GL11.GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL, 0.0f);
glEnable(GL_ALPHA_TEST);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
// Setup lighting for when we have fixed function fragment rendering.
GL11.glShadeModel(GL11.GL_SMOOTH);
glShadeModel(GL_SMOOTH);
if ( shader == null ) {
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
vectorBuffer.clear();
vectorBuffer.put(1.0f).put(1.0f).put(1.0f).put(1.0f);
vectorBuffer.clear();
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, vectorBuffer);
glLight(GL_LIGHT0, GL_DIFFUSE, vectorBuffer);
vectorBuffer.put(1.0f).put(1.0f).put(1.0f).put(1.0f);
vectorBuffer.clear();
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, vectorBuffer);
glLight(GL_LIGHT0, GL_AMBIENT, vectorBuffer);
vectorBuffer.put(1.0f).put(1.0f).put(0.5f).put(1.0f);
vectorBuffer.clear();
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, vectorBuffer);
glLight(GL_LIGHT0, GL_SPECULAR, vectorBuffer);
vectorBuffer.put(-1.0f / 3.0f).put(1.0f / 3.0f).put(1.0f / 3.0f).put(0.0f); // Infinite
vectorBuffer.clear();
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, vectorBuffer);
glLight(GL_LIGHT0, GL_POSITION, vectorBuffer);
vectorBuffer.put(0.2f).put(0.2f).put(0.2f).put(1.0f);
vectorBuffer.clear();
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, vectorBuffer);
glLightModel(GL_LIGHT_MODEL_AMBIENT, vectorBuffer);
sphere = new Sphere();
}
@ -283,15 +285,14 @@ public final class ShadersTest {
}
static void renderObject() {
GL11.glColor3b((byte)255, (byte)255, (byte)255);
glColor3b((byte)255, (byte)255, (byte)255);
sphere.draw(1.0f, 32, 32);
}
private static DisplayMode chooseMode(DisplayMode[] modes, int width, int height) {
DisplayMode bestMode = null;
for ( int i = 0; i < modes.length; i++ ) {
DisplayMode mode = modes[i];
for ( DisplayMode mode : modes ) {
if ( mode.getWidth() == width && mode.getHeight() == height && mode.getFrequency() <= 85 ) {
if ( bestMode == null || (mode.getBitsPerPixel() >= bestMode.getBitsPerPixel() && mode.getFrequency() > bestMode.getFrequency()) )
bestMode = mode;

View File

@ -72,12 +72,12 @@ public final class Display {
if (LWJGLUtil.DEBUG || DEBUG) {
System.out.println("Available screen modes:");
for (int i = 0; i < modes.length; i ++) {
System.out.println(modes[i]);
for ( DisplayMode mode : modes ) {
System.out.println(mode);
}
}
ArrayList matches = new ArrayList(modes.length);
ArrayList<DisplayMode> matches = new ArrayList<DisplayMode>(modes.length);
for (int i = 0; i < modes.length; i ++) {
assert modes[i] != null : ""+i+" "+modes.length;
@ -108,8 +108,8 @@ public final class Display {
matches.toArray(ret);
if (LWJGLUtil.DEBUG && DEBUG) {
System.out.println("Filtered screen modes:");
for (int i = 0; i < ret.length; i ++) {
System.out.println(ret[i]);
for ( DisplayMode mode : ret ) {
System.out.println(mode);
}
}
@ -159,20 +159,20 @@ public final class Display {
}
}
class Sorter implements Comparator {
class Sorter implements Comparator<DisplayMode> {
final FieldAccessor[] field;
final FieldAccessor[] accessors;
Sorter() {
field = new FieldAccessor[param.length];
for (int i = 0; i < field.length; i ++) {
accessors = new FieldAccessor[param.length];
for (int i = 0; i < accessors.length; i ++) {
int idx = param[i].indexOf('=');
if (idx > 0) {
field[i] = new FieldAccessor(param[i].substring(0, idx), 0, Integer.parseInt(param[i].substring(idx + 1, param[i].length())), true);
accessors[i] = new FieldAccessor(param[i].substring(0, idx), 0, Integer.parseInt(param[i].substring(idx + 1, param[i].length())), true);
} else if (param[i].charAt(0) == '-') {
field[i] = new FieldAccessor(param[i].substring(1), -1, 0, false);
accessors[i] = new FieldAccessor(param[i].substring(1), -1, 0, false);
} else {
field[i] = new FieldAccessor(param[i], 1, 0, false);
accessors[i] = new FieldAccessor(param[i], 1, 0, false);
}
}
}
@ -180,36 +180,33 @@ public final class Display {
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Object o1, Object o2) {
DisplayMode dm1 = (DisplayMode) o1;
DisplayMode dm2 = (DisplayMode) o2;
public int compare(DisplayMode dm1, DisplayMode dm2) {
for ( FieldAccessor accessor : accessors ) {
int f1 = accessor.getInt(dm1);
int f2 = accessor.getInt(dm2);
for (int i = 0; i < field.length; i ++) {
int f1 = field[i].getInt(dm1);
int f2 = field[i].getInt(dm2);
if (field[i].usePreferred && f1 != f2) {
if (f1 == field[i].preferred)
if ( accessor.usePreferred && f1 != f2 ) {
if ( f1 == accessor.preferred )
return -1;
else if (f2 == field[i].preferred)
else if ( f2 == accessor.preferred )
return 1;
else {
// Score according to the difference between the values
int absf1 = Math.abs(f1 - field[i].preferred);
int absf2 = Math.abs(f2 - field[i].preferred);
if (absf1 < absf2)
int absf1 = Math.abs(f1 - accessor.preferred);
int absf2 = Math.abs(f2 - accessor.preferred);
if ( absf1 < absf2 )
return -1;
else if (absf1 > absf2)
else if ( absf1 > absf2 )
return 1;
else
continue;
}
} else if (f1 < f2)
return field[i].order;
else if (f1 == f2)
} else if ( f1 < f2 )
return accessor.order;
else if ( f1 == f2 )
continue;
else
return -field[i].order;
return -accessor.order;
}
return 0;
@ -222,19 +219,19 @@ public final class Display {
// Try them out in the appropriate order
if (LWJGLUtil.DEBUG || DEBUG) {
System.out.println("Sorted display modes:");
for (int i = 0; i < dm.length; i ++) {
System.out.println(dm[i]);
for ( DisplayMode aDm : dm ) {
System.out.println(aDm);
}
}
for (int i = 0; i < dm.length; i ++) {
for ( DisplayMode aDm : dm ) {
try {
if (LWJGLUtil.DEBUG || DEBUG)
System.out.println("Attempting to set displaymode: "+dm[i]);
org.lwjgl.opengl.Display.setDisplayMode(dm[i]);
return dm[i];
if ( LWJGLUtil.DEBUG || DEBUG )
System.out.println("Attempting to set displaymode: " + aDm);
org.lwjgl.opengl.Display.setDisplayMode(aDm);
return aDm;
} catch (Exception e) {
if (LWJGLUtil.DEBUG || DEBUG) {
System.out.println("Failed to set display mode to "+dm[i]);
if ( LWJGLUtil.DEBUG || DEBUG ) {
System.out.println("Failed to set display mode to " + aDm);
e.printStackTrace();
}
}

View File

@ -45,101 +45,101 @@ public interface ReadableColor {
* Return the red component (0..255)
* @return int
*/
public int getRed();
int getRed();
/**
* Return the red component (0..255)
* @return int
*/
public int getGreen();
int getGreen();
/**
* Return the red component (0..255)
* @return int
*/
public int getBlue();
int getBlue();
/**
* Return the red component (0..255)
* @return int
*/
public int getAlpha();
int getAlpha();
/**
* Return the red component
* @return int
*/
public byte getRedByte();
byte getRedByte();
/**
* Return the red component
* @return int
*/
public byte getGreenByte();
byte getGreenByte();
/**
* Return the red component
* @return int
*/
public byte getBlueByte();
byte getBlueByte();
/**
* Return the red component
* @return int
*/
public byte getAlphaByte();
byte getAlphaByte();
/**
* Write the RGBA color directly out to a ByteBuffer
* @param dest the buffer to write to
*/
public void writeRGBA(ByteBuffer dest);
void writeRGBA(ByteBuffer dest);
/**
* Write the RGB color directly out to a ByteBuffer
* @param dest the buffer to write to
*/
public void writeRGB(ByteBuffer dest);
void writeRGB(ByteBuffer dest);
/**
* Write the ABGR color directly out to a ByteBuffer
* @param dest the buffer to write to
*/
public void writeABGR(ByteBuffer dest);
void writeABGR(ByteBuffer dest);
/**
* Write the BGR color directly out to a ByteBuffer
* @param dest the buffer to write to
*/
public void writeBGR(ByteBuffer dest);
void writeBGR(ByteBuffer dest);
/**
* Write the BGRA color directly out to a ByteBuffer
* @param dest the buffer to write to
*/
public void writeBGRA(ByteBuffer dest);
void writeBGRA(ByteBuffer dest);
/**
* Write the ARGB color directly out to a ByteBuffer
* @param dest the buffer to write to
*/
public void writeARGB(ByteBuffer dest);
void writeARGB(ByteBuffer dest);
/*
* Some standard colors
*/
public static final ReadableColor RED = new Color(255, 0, 0);
public static final ReadableColor ORANGE = new Color(255, 128, 0);
public static final ReadableColor YELLOW = new Color(255, 255, 0);
public static final ReadableColor GREEN = new Color(0, 255, 0);
public static final ReadableColor CYAN = new Color(0, 255, 255);
public static final ReadableColor BLUE = new Color(0, 0, 255);
public static final ReadableColor PURPLE = new Color(255, 0, 255);
public static final ReadableColor WHITE = new Color(255, 255, 255);
public static final ReadableColor BLACK = new Color(0, 0, 0);
public static final ReadableColor LTGREY = new Color(192, 192, 192);
public static final ReadableColor DKGREY = new Color(64, 64, 64);
public static final ReadableColor GREY = new Color(128, 128, 128);
ReadableColor RED = new Color(255, 0, 0);
ReadableColor ORANGE = new Color(255, 128, 0);
ReadableColor YELLOW = new Color(255, 255, 0);
ReadableColor GREEN = new Color(0, 255, 0);
ReadableColor CYAN = new Color(0, 255, 255);
ReadableColor BLUE = new Color(0, 0, 255);
ReadableColor PURPLE = new Color(255, 0, 255);
ReadableColor WHITE = new Color(255, 255, 255);
ReadableColor BLACK = new Color(0, 0, 0);
ReadableColor LTGREY = new Color(192, 192, 192);
ReadableColor DKGREY = new Color(64, 64, 64);
ReadableColor GREY = new Color(128, 128, 128);

View File

@ -43,18 +43,18 @@ public interface ReadableDimension {
* Get the width
* @return int
*/
public int getWidth();
int getWidth();
/**
* Get the height
* @return int
*/
public int getHeight();
int getHeight();
/**
* Copy this ReadableDimension into a destination Dimension
* @param dest The destination
*/
public void getSize(WritableDimension dest);
void getSize(WritableDimension dest);
}

View File

@ -42,16 +42,16 @@ public interface ReadablePoint {
/**
* @return int
*/
public int getX();
int getX();
/**
* @return int
*/
public int getY();
int getY();
/**
* Copy this ReadablePoint into a destination Point
* @param dest The destination Point, or null, to create a new Point
*/
public void getLocation(WritablePoint dest);
void getLocation(WritablePoint dest);
}

View File

@ -43,6 +43,6 @@ public interface ReadableRectangle extends ReadableDimension, ReadablePoint {
* Copy this readable rectangle's bounds into a destination Rectangle
* @param dest The destination Rectangle, or null, to create a new Rectangle
*/
public void getBounds(WritableRectangle dest);
void getBounds(WritableRectangle dest);
}

View File

@ -44,6 +44,6 @@ public interface Renderable {
/**
* "Render" this thing. This will involve calls to the GL.
*/
public void render();
void render();
}

View File

@ -51,7 +51,7 @@ public class Timer {
// Every so often we will re-query the timer resolution
private static final int QUERY_INTERVAL = 50; // in calls to tick()
private static int queryCount = 0;
private static int queryCount;
// Globally keeps track of time for all instances of Timer
private static long currentTime;

View File

@ -43,84 +43,84 @@ public interface WritableColor {
/**
* Set a color
*/
public void set(int r, int g, int b, int a);
void set(int r, int g, int b, int a);
/**
* Set a color
*/
public void set(byte r, byte g, byte b, byte a);
void set(byte r, byte g, byte b, byte a);
/**
* Set a color
*/
public void set(int r, int g, int b);
void set(int r, int g, int b);
/**
* Set a color
*/
public void set(byte r, byte g, byte b);
void set(byte r, byte g, byte b);
/**
* Set the Red component
*/
public void setRed(int red);
void setRed(int red);
/**
* Set the Green component
*/
public void setGreen(int green);
void setGreen(int green);
/**
* Set the Blue component
*/
public void setBlue(int blue);
void setBlue(int blue);
/**
* Set the Alpha component
*/
public void setAlpha(int alpha);
void setAlpha(int alpha);
/**
* Set the Red component
*/
public void setRed(byte red);
void setRed(byte red);
/**
* Set the Green component
*/
public void setGreen(byte green);
void setGreen(byte green);
/**
* Set the Blue component
*/
public void setBlue(byte blue);
void setBlue(byte blue);
/**
* Set the Alpha component
*/
public void setAlpha(byte alpha);
void setAlpha(byte alpha);
/**
* Read a color from a byte buffer
* @param src The source buffer
*/
public void readRGBA(ByteBuffer src);
void readRGBA(ByteBuffer src);
/**
* Read a color from a byte buffer
* @param src The source buffer
*/
public void readRGB(ByteBuffer src);
void readRGB(ByteBuffer src);
/**
* Read a color from a byte buffer
* @param src The source buffer
*/
public void readARGB(ByteBuffer src);
void readARGB(ByteBuffer src);
/**
* Read a color from a byte buffer
* @param src The source buffer
*/
public void readBGRA(ByteBuffer src);
void readBGRA(ByteBuffer src);
/**
* Read a color from a byte buffer
* @param src The source buffer
*/
public void readBGR(ByteBuffer src);
void readBGR(ByteBuffer src);
/**
* Read a color from a byte buffer
* @param src The source buffer
*/
public void readABGR(ByteBuffer src);
void readABGR(ByteBuffer src);
/**
* Set this color's color by copying another color
* @param src The source color
*/
public void setColor(ReadableColor src);
void setColor(ReadableColor src);
}

View File

@ -39,16 +39,16 @@ package org.lwjgl.util;
*/
public interface WritableDimension {
public void setSize(int w, int h);
public void setSize(ReadableDimension d);
void setSize(int w, int h);
void setSize(ReadableDimension d);
/**
* Sets the height.
* @param height The height to set
*/
public void setHeight(int height);
void setHeight(int height);
/**
* Sets the width.
* @param width The width to set
*/
public void setWidth(int width);
void setWidth(int width);
}

View File

@ -38,8 +38,8 @@ package org.lwjgl.util;
* $Id$
*/
public interface WritablePoint {
public void setLocation(int x, int y);
public void setLocation(ReadablePoint p);
public void setX(int x);
public void setY(int y);
void setLocation(int x, int y);
void setLocation(ReadablePoint p);
void setX(int x);
void setY(int y);
}

View File

@ -46,18 +46,18 @@ public interface WritableRectangle extends WritablePoint, WritableDimension {
* @param width Width of rectangle
* @param height Height of rectangle
*/
public void setBounds(int x, int y, int width, int height);
void setBounds(int x, int y, int width, int height);
/**
* Sets the bounds of the rectangle
* @param location
* @param size
*/
public void setBounds(ReadablePoint location, ReadableDimension size);
void setBounds(ReadablePoint location, ReadableDimension size);
/**
* Sets the bounds of the rectangle
* @param src
*/
public void setBounds(ReadableRectangle src);
void setBounds(ReadableRectangle src);
}

View File

@ -56,15 +56,15 @@ import java.util.StringTokenizer;
public class XPMFile {
/** Array of bytes (RGBA) */
private byte bytes[] = null;
private byte bytes[];
private final static int WIDTH = 0;
private static final int WIDTH = 0;
private final static int HEIGHT = 1;
private static final int HEIGHT = 1;
private final static int NUMBER_OF_COLORS = 2;
private static final int NUMBER_OF_COLORS = 2;
private final static int CHARACTERS_PER_PIXEL = 3;
private static final int CHARACTERS_PER_PIXEL = 3;
private static int[] format = new int[4];
@ -128,14 +128,14 @@ public class XPMFile {
try {
LineNumberReader reader = new LineNumberReader(
new InputStreamReader(is));
HashMap colors = new HashMap();
HashMap<String, Integer> colors = new HashMap<String, Integer>();
format = parseFormat(nextLineOfInterest(reader));
// setup color mapping
for (int i = 0; i < format[NUMBER_OF_COLORS]; i++) {
Object[] colorDefinition = parseColor(nextLineOfInterest(reader));
colors.put(colorDefinition[0], colorDefinition[1]);
colors.put((String)colorDefinition[0], (Integer)colorDefinition[1]);
}
// read actual image (convert to RGBA)
@ -158,7 +158,7 @@ public class XPMFile {
* @throws IOException
* If any IO exceptions occurs while reading file
*/
private String nextLineOfInterest(LineNumberReader reader)
private static String nextLineOfInterest(LineNumberReader reader)
throws IOException {
String ret;
do {
@ -175,7 +175,7 @@ public class XPMFile {
* String to parse
* @return Array specifying width, height, colors, characters per pixel
*/
private int[] parseFormat(String format) {
private static int[] parseFormat(String format) {
// format should look like this:
// 16 16 122 2
@ -197,7 +197,7 @@ public class XPMFile {
* Line to parse
* @return Array containing a key (String) and a color (Integer)
*/
private Object[] parseColor(String line) {
private static Object[] parseColor(String line) {
// line should look like this:
// # c #0A0A0A
@ -211,7 +211,7 @@ public class XPMFile {
String color = line.substring(format[CHARACTERS_PER_PIXEL] + 4);
// we always assume type is color, and supplied as #<r><g><b>
return new Object[] { key, new Integer(Integer.parseInt(color, 16)) };
return new Object[] { key, Integer.parseInt(color, 16) };
}
/**
@ -226,7 +226,7 @@ public class XPMFile {
* @param index
* current index into lines, we've reached
*/
private void parseImageLine(String line, int[] format, HashMap colors,
private void parseImageLine(String line, int[] format, HashMap<String, Integer> colors,
int index) {
// offset for next line
int offset = index * 4 * format[WIDTH];
@ -238,10 +238,10 @@ public class XPMFile {
.substring(
i * format[CHARACTERS_PER_PIXEL],
(i * format[CHARACTERS_PER_PIXEL] + format[CHARACTERS_PER_PIXEL]));
Integer color = (Integer) colors.get(key);
bytes[offset + (i * 4)] = (byte) ((color.intValue() & 0x00ff0000) >> 16);
bytes[offset + ((i * 4) + 1)] = (byte) ((color.intValue() & 0x0000ff00) >> 8);
bytes[offset + ((i * 4) + 2)] = (byte) ((color.intValue() & 0x000000ff) >> 0); // looks
int color = colors.get(key);
bytes[offset + (i * 4)] = (byte) ((color & 0x00ff0000) >> 16);
bytes[offset + ((i * 4) + 1)] = (byte) ((color & 0x0000ff00) >> 8);
bytes[offset + ((i * 4) + 2)] = (byte) ((color & 0x000000ff) >> 0); // looks
// better
// :)
bytes[offset + ((i * 4) + 3)] = (byte) 0xff; // always 0xff alpha

View File

@ -218,7 +218,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
protected boolean prependHost;
/** Used to store file names with lastModified time */
protected HashMap filesLastModified;
protected HashMap<String, Long> filesLastModified;
/** Sizes of files to download */
protected int[] fileSizes;
@ -233,10 +233,10 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
protected int state = STATE_INIT;
/** whether lzma is supported */
protected boolean lzmaSupported = false;
protected boolean lzmaSupported;
/** whether pack200 is supported */
protected boolean pack200Supported = false;
protected boolean pack200Supported;
/** generic error message to display on error */
protected String[] genericErrorMessage = { "An error occured while loading the applet.",
@ -252,7 +252,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
"the applet to continue the loading process."};
/** have natives been loaded by another instance of this applet */
static protected boolean natives_loaded = false;
protected static boolean natives_loaded;
/*
* @see java.applet.Applet#init()
@ -262,9 +262,9 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
// sanity check
String[] requiredArgs = {"al_main", "al_logo", "al_progressbar", "al_jars"};
for(int i=0; i<requiredArgs.length; i++) {
if(getParameter(requiredArgs[i]) == null) {
fatalErrorOccured("missing required applet parameter: " + requiredArgs[i], null);
for ( String requiredArg : requiredArgs ) {
if ( getParameter(requiredArg) == null ) {
fatalErrorOccured("missing required applet parameter: " + requiredArg, null);
return;
}
}
@ -313,7 +313,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
* @param exception Exception to make stacktrace of
* @return Stacktrace of exception in the form of a string
*/
private String generateStacktrace(Exception exception) {
private static String generateStacktrace(Exception exception) {
Writer result = new StringWriter();
PrintWriter printWriter = new PrintWriter(result);
exception.printStackTrace(printWriter);
@ -681,8 +681,8 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
loadJarURLs();
// get path where applet will be stored
String path = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws Exception {
String path = AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
public String run() throws Exception {
// we append the code base to avoid naming collisions with al_title
String codebase = "";
@ -810,9 +810,10 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
* @return the hashmap containing the files names and lastModified times
* @throws Exception if it fails to read hashmap
*/
protected HashMap readCacheFile(File file) throws Exception {
@SuppressWarnings("unchecked")
protected HashMap<String, Long> readCacheFile(File file) throws Exception {
ObjectInputStream dis = new ObjectInputStream(new FileInputStream(file));
HashMap hashMap = (HashMap)dis.readObject();
HashMap<String, Long> hashMap = (HashMap<String, Long>)dis.readObject();
dis.close();
return hashMap;
}
@ -824,7 +825,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
* @param filesLastModified the hashmap containing files names and lastModified times
* @throws Exception if it fails to write file
*/
protected void writeCacheFile(File file, HashMap filesLastModified) throws Exception {
protected void writeCacheFile(File file, HashMap<String, Long> filesLastModified) throws Exception {
ObjectOutputStream dos = new ObjectOutputStream(new FileOutputStream(file));
dos.writeObject(filesLastModified);
dos.close();
@ -867,7 +868,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
// add permission for downloaded jars to access host they were from
perms.add(new SocketPermission(host, SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION));
}
else if (codesource.getLocation().getProtocol().equals("file")) {
else if ( "file".equals(codesource.getLocation().getProtocol()) ) {
// if running locally add file permission
String path = codesource.getLocation().getFile().replace('/', File.separatorChar);
perms.add(new FilePermission(path, SecurityConstants.FILE_READ_ACTION));
@ -987,7 +988,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
*/
protected void getJarInfo(File dir) throws Exception {
filesLastModified = new HashMap();
filesLastModified = new HashMap<String, Long>();
// store file sizes and mark which files not to download
fileSizes = new int[urlList.length];
@ -1017,7 +1018,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
if (cacheEnabled && lastModified != 0 &&
filesLastModified.containsKey(fileName)) {
long savedLastModified = ((Long)filesLastModified.get(fileName)).longValue();
long savedLastModified = filesLastModified.get(fileName);
// if lastModifed time is the same, don't redownload
if (savedLastModified == lastModified) {
@ -1030,7 +1031,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
}
// put key and value in the hashmap
filesLastModified.put(fileName, new Long(lastModified));
filesLastModified.put(fileName, lastModified);
// update progress bar
percentage = 5 + (int)(10 * i/(float)urlList.length);
@ -1198,7 +1199,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
* Extract LZMA File
* @param in Input path to pack file
* @param out output path to resulting file
* @throws exception if any errors occur
* @throws Exception if any errors occur
*/
protected void extractLZMA(String in, String out) throws Exception {
@ -1206,9 +1207,9 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
FileInputStream fileInputHandle = new FileInputStream(f);
// use reflection to avoid hard dependency
Class clazz = Class.forName( "LZMA.LzmaInputStream" );
Constructor constructor = clazz.getDeclaredConstructor( new Class[] {InputStream.class} );
InputStream inputHandle = (InputStream) constructor.newInstance( new Object[] {fileInputHandle} );
Class<?> clazz = Class.forName( "LZMA.LzmaInputStream" );
Constructor constructor = clazz.getDeclaredConstructor(InputStream.class);
InputStream inputHandle = (InputStream) constructor.newInstance(fileInputHandle);
OutputStream outputHandle;
outputHandle = new FileOutputStream(out);
@ -1235,7 +1236,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
* Extract Pack File
* @param in Input path to pack file
* @param out output path to resulting file
* @throws exception if any errors occur
* @throws Exception if any errors occur
*/
protected void extractPack(String in, String out) throws Exception {
File f = new File(in);
@ -1254,7 +1255,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
* Extract all jars from any lzma/pack files
*
* @param path output path
* @throws exception if any errors occur
* @throws Exception if any errors occur
*/
protected void extractJars(String path) throws Exception {
state = STATE_EXTRACTING_PACKAGES;
@ -1499,7 +1500,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
/**
* Retrieves the color
*
* @param color Color to load
* @param param Color to load
* @param defaultColor Default color to use if no color to load
* @return Color to use
*/

View File

@ -98,8 +98,8 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
private void validateType(MethodDeclaration method, Class<?extends Annotation> annotation_type, Class type) {
Class[] valid_types = type_map.getValidAnnotationTypes(type);
for (int i = 0; i < valid_types.length; i++)
if (valid_types[i].equals(annotation_type))
for ( Class valid_type : valid_types )
if ( valid_type.equals(annotation_type) )
return;
throw new RuntimeException(type + " is annotated with invalid native type " + annotation_type +
" in method " + method);

View File

@ -42,5 +42,5 @@ import java.lang.annotation.Target;
@Target(ElementType.PARAMETER)
public @interface Helper {
boolean passToNative() default false;
}

View File

@ -116,7 +116,7 @@ public class JavaMethodsGenerator {
private static boolean generateParametersJava(PrintWriter writer, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, boolean native_stub, final boolean printTypes, Mode mode) {
boolean first_parameter = true;
for (ParameterDeclaration param : method.getParameters()) {
if ( native_stub && param.getAnnotation(Helper.class) != null )
if ( native_stub && (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
continue;
final Constant constant_annotation = param.getAnnotation(Constant.class);
if ( constant_annotation != null && constant_annotation.isNative() )
@ -555,7 +555,7 @@ public class JavaMethodsGenerator {
private static boolean printMethodCallArguments(PrintWriter writer, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode) {
boolean first_parameter = true;
for ( ParameterDeclaration param : method.getParameters() ) {
if ( param.getAnnotation(Result.class) != null || param.getAnnotation(Helper.class) != null )
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
continue;
final Constant constant_annotation = param.getAnnotation(Constant.class);

View File

@ -70,7 +70,7 @@ public class NativeMethodStubsGenerator {
private static void generateParameters(PrintWriter writer, Collection<ParameterDeclaration> params, Mode mode) {
for (ParameterDeclaration param : params) {
if ( param.getAnnotation(Helper.class) != null || param.getAnnotation(Result.class) != null )
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
continue;
final Constant constant_annotation = param.getAnnotation(Constant.class);
if ( constant_annotation == null || !constant_annotation.isNative() )

View File

@ -86,7 +86,7 @@ public class RegisterStubsGenerator {
Collection<ParameterDeclaration> params = method.getParameters();
String signature = "(";
for (ParameterDeclaration param : params) {
if ( param.getAnnotation(Helper.class) != null || param.getAnnotation(Result.class) != null )
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
continue;
final Constant constant_annotation = param.getAnnotation(Constant.class);

View File

@ -169,18 +169,29 @@ public class Utils {
}
public static void printDocComment(PrintWriter writer, Declaration decl) {
final String overloadsComment;
if ( (decl instanceof MethodDeclaration) && decl.getAnnotation(Alternate.class) != null )
overloadsComment = "Overloads " + decl.getAnnotation(Alternate.class).value() + ".";
else
overloadsComment = null;
String doc_comment = decl.getDocComment();
if (doc_comment != null) {
final String tab = decl instanceof InterfaceDeclaration ? "" : "\t";
writer.println(tab + "/**");
if ( overloadsComment != null ) {
writer.println("\t * " + overloadsComment);
writer.println("\t * <p>");
}
final StringTokenizer doc_lines = new StringTokenizer(doc_comment, "\n", true);
boolean lastWasNL = false;
while (doc_lines.hasMoreTokens()) {
final String t = doc_lines.nextToken();
if ( "\n".equals(t) ) {
if ( lastWasNL )
writer.println(tab + " *");
writer.println(tab + " * <p>");
lastWasNL = true;
} else {
writer.println(tab + " * " + t);
@ -189,8 +200,8 @@ public class Utils {
}
writer.println(tab + " */");
} else if ( (decl instanceof MethodDeclaration) && decl.getAnnotation(Alternate.class) != null )
writer.println("\t/** Overloads " + decl.getAnnotation(Alternate.class).value() + " */");
} else if ( overloadsComment != null )
writer.println("\t/** " + overloadsComment + " */");
}
public static AnnotationMirror getParameterAutoAnnotation(ParameterDeclaration param) {

View File

@ -49,8 +49,6 @@ import com.sun.mirror.declaration.TypeDeclaration;
*/
public class CLCapabilitiesGenerator {
private static final String SUPPORTED_EXTS = "supported_extensions";
static void generateClassPrologue(final PrintWriter writer) {
writer.println("public final class " + CLGeneratorProcessorFactory.CLCAPS_CLASS_NAME + " {");
writer.println();
@ -60,14 +58,15 @@ public class CLCapabilitiesGenerator {
final Alias alias_annotation = d.getAnnotation(Alias.class);
final boolean aliased = alias_annotation != null && alias_annotation.postfix().length() > 0;
boolean first = true;
boolean foundNative = false;
for ( final MethodDeclaration method : d.getMethods() ) {
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
continue;
if ( first ) {
writer.println("\t// " + d.getSimpleName());
first = false;
if ( !foundNative ) {
//writer.println("\t// " + d.getSimpleName());
writer.println("\tstatic final boolean " + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + ";");
foundNative = true;
}
writer.print("\tstatic final long " + Utils.getFunctionAddressName(d, method) + " = CL.getFunctionAddress(");
@ -76,11 +75,12 @@ public class CLCapabilitiesGenerator {
else
writer.println("\"" + Utils.getFunctionAddressName(d, method) + "\");");
}
if ( foundNative )
writer.println();
}
static void generateConstructor(final PrintWriter writer, final Collection<TypeDeclaration> interface_decls) {
writer.println("\tprivate static final Set<String> " + SUPPORTED_EXTS + " = new HashSet<String>();");
writer.println();
writer.println("\tprivate " + CLGeneratorProcessorFactory.CLCAPS_CLASS_NAME + "() {}");
writer.println();
writer.println("\tstatic {");
@ -89,25 +89,20 @@ public class CLCapabilitiesGenerator {
if ( d.getMethods().isEmpty() )
continue;
writer.println("\t\tif ( " + getExtensionSupportedName(d.getSimpleName()) + "() )");
writer.println("\t\t\t" + SUPPORTED_EXTS + ".add(\"" + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + "\");");
//writer.println("\t\tif ( " + getExtensionSupportedName(d.getSimpleName()) + "() )");
//writer.println("\t\t\t" + SUPPORTED_EXTS + ".add(\"" + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + "\");");
writer.println("\t\t" + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + " = " + getExtensionSupportedName(d.getSimpleName()) + "();");
}
writer.println("\t}\n");
}
static void generateExtensionSupported(final PrintWriter writer) {
writer.println("\tstatic boolean isExtensionSupported(final String name) {\n" +
"\t\treturn " + SUPPORTED_EXTS + ".contains(name);\n" +
"\t}\n");
}
static void generateExtensionChecks(final PrintWriter writer, final InterfaceDeclaration d) {
Iterator<? extends MethodDeclaration> methods = d.getMethods().iterator();
if ( !methods.hasNext() )
return;
writer.println("\tstatic boolean " + getExtensionSupportedName(d.getSimpleName()) + "() {");
writer.println("\tprivate static boolean " + getExtensionSupportedName(d.getSimpleName()) + "() {");
writer.println("\t\treturn ");
boolean first = true;
@ -141,11 +136,23 @@ public class CLCapabilitiesGenerator {
public static void generateCapabilitiesGetters(final PrintWriter writer) {
writer.println("\tpublic static CLPlatformCapabilities getPlatformCapabilities(final CLPlatform platform) {\n" +
"\t\treturn CLPlatformImpl.getCapabilities(platform);\n" +
"\t\tplatform.checkValid();\n" +
"\n" +
"\t\tCLPlatformCapabilities caps = (CLPlatformCapabilities)platform.getCapabilities();\n" +
"\t\tif ( caps == null )\n" +
"\t\t\tplatform.setCapabilities(caps = new CLPlatformCapabilities(platform));\n" +
"\n" +
"\t\treturn caps;\n" +
"\t}\n");
writer.println("\tpublic static CLDeviceCapabilities getDeviceCapabilities(final CLDevice device) {\n" +
"\t\treturn CLDeviceImpl.getCapabilities(device);\n" +
"\t\tdevice.checkValid();\n" +
"\n" +
"\t\tCLDeviceCapabilities caps = (CLDeviceCapabilities)device.getCapabilities();\n" +
"\t\tif ( caps == null )\n" +
"\t\t\tdevice.setCapabilities(caps = new CLDeviceCapabilities(device));\n" +
"\n" +
"\t\treturn caps;\n" +
"\t}\n");
}

View File

@ -122,8 +122,6 @@ public class CLGeneratorProcessorFactory implements AnnotationProcessorFactory,
writer.println();
writer.println("package org.lwjgl.opencl;");
writer.println();
writer.println("import java.util.*;");
writer.println();
}
private void generateCLCapabilitiesSource() throws IOException {
@ -146,8 +144,6 @@ public class CLGeneratorProcessorFactory implements AnnotationProcessorFactory,
CLCapabilitiesGenerator.generateCapabilitiesGetters(writer);
CLCapabilitiesGenerator.generateExtensionSupported(writer);
for ( final TypeDeclaration template : templates )
CLCapabilitiesGenerator.generateExtensionChecks(writer, (InterfaceDeclaration)template);
@ -158,6 +154,8 @@ public class CLGeneratorProcessorFactory implements AnnotationProcessorFactory,
private void generateCLPDCapabilitiesSource(final Class<? extends Annotation> capsType, final String capsName, final Class<? extends PointerWrapper> objectType, final String objectName) throws IOException {
final PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opencl", new File(capsName + ".java"), null);
printHeader(writer);
writer.println("import java.util.*;");
writer.println();
CLPDCapabilitiesGenerator.generateClassPrologue(writer, capsName);
@ -173,7 +171,7 @@ public class CLGeneratorProcessorFactory implements AnnotationProcessorFactory,
CLPDCapabilitiesGenerator.generateGetters(writer);
CLPDCapabilitiesGenerator.generateToString(writer, templates, capsType, capsName, objectType, objectName);
CLPDCapabilitiesGenerator.generateToString(writer, templates, capsType);
writer.println("}");
writer.close();

View File

@ -81,7 +81,6 @@ public class CLPDCapabilitiesGenerator {
final Class<? extends PointerWrapper> objectType, final String objectName) {
writer.println("\tpublic " + capsName + "(final " + objectType.getSimpleName() + ' ' + objectName + ") {");
final String methodName = Character.toUpperCase(objectName.charAt(0)) + objectName.substring(1);
writer.println("\t\tfinal String extensionList = " + objectName + ".getInfoString(CL10.CL_" + objectName.toUpperCase() + "_EXTENSIONS);\n" +
"\t\tfinal String version = " + objectName + ".getInfoString(CL10.CL_" + objectName.toUpperCase() + "_VERSION);\n" +
"\t\tif ( !version.startsWith(\"OpenCL \") )\n" +
@ -107,9 +106,11 @@ public class CLPDCapabilitiesGenerator {
if ( t.getAnnotation(capsType) == null )
continue;
writer.print("\t\t" + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()) + " = extensions.contains(\"" + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()).toLowerCase() + "\")");
final String extName = CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName());
writer.print("\t\t" + extName + " = extensions.contains(\"" + extName.toLowerCase() + "\")");
if ( !t.getMethods().isEmpty() )
writer.print(" && CLCapabilities.is" + t.getSimpleName() + "Supported()");
writer.print(" && CLCapabilities." + extName);
writer.println(";");
}
@ -126,7 +127,7 @@ public class CLPDCapabilitiesGenerator {
writer.println("\t}\n");
}
public static void generateToString(final PrintWriter writer, final Collection<TypeDeclaration> templates, final Class<? extends Annotation> capsType, final String capsName, final Class<? extends PointerWrapper> objectType, final String objectName) {
public static void generateToString(final PrintWriter writer, final Collection<TypeDeclaration> templates, final Class<? extends Annotation> capsType) {
writer.println("\tpublic String toString() {");
writer.println("\t\tfinal StringBuilder buf = new StringBuilder();\n");

View File

@ -73,7 +73,7 @@ public class GLCapabilitiesGenerator {
public static void generateInitializerPrologue(PrintWriter writer) {
writer.println("\t" + Utils.CONTEXT_CAPS_CLASS_NAME + "(boolean forwardCompatible) throws LWJGLException {");
writer.println("\t\tSet " + CACHED_EXTS_VAR_NAME + " = " + ALL_INIT_METHOD_NAME + "(forwardCompatible);");
writer.println("\t\tSet<String> " + CACHED_EXTS_VAR_NAME + " = " + ALL_INIT_METHOD_NAME + "(forwardCompatible);");
}
private static String translateFieldName(String interface_name) {
@ -124,7 +124,7 @@ public class GLCapabilitiesGenerator {
}
public static void generateInitStubsPrologue(PrintWriter writer, boolean context_specific) {
writer.println("\tprivate Set " + ALL_INIT_METHOD_NAME + "(boolean forwardCompatible) throws LWJGLException {");
writer.println("\tprivate Set<String> " + ALL_INIT_METHOD_NAME + "(boolean forwardCompatible) throws LWJGLException {");
// Load the basic pointers we need to detect OpenGL version and supported extensions.
writer.println("\t\tglGetError = GLContext.getFunctionAddress(\"glGetError\");");
@ -137,7 +137,7 @@ public class GLCapabilitiesGenerator {
// Get the supported extensions set.
writer.println("\t\tGLContext.setCapabilities(this);");
writer.println("\t\tSet " + CACHED_EXTS_VAR_NAME + " = new HashSet(256);");
writer.println("\t\tSet<String> " + CACHED_EXTS_VAR_NAME + " = new HashSet<String>(256);");
writer.println("\t\tint " + PROFILE_MASK_VAR_NAME + " = GLContext.getSupportedExtensions(" + CACHED_EXTS_VAR_NAME + ");");
// Force forward compatible mode when OpenGL version is 3.1 or higher and ARB_compatibility is not available.
@ -230,7 +230,7 @@ public class GLCapabilitiesGenerator {
if ( dependent != null ) {
if ( deprecated )
writer.print(",");
writer.print("Set supported_extensions");
writer.print("Set<String> supported_extensions");
}
Alias alias_annotation = d.getAnnotation(Alias.class);

View File

@ -156,7 +156,7 @@ public class GLGeneratorProcessorFactory implements AnnotationProcessorFactory,
for (TypeDeclaration typedecl : interface_decls) {
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
String simple_name = interface_decl.getSimpleName();
if (simple_name.equals("GL11"))
if ( "GL11".equals(simple_name) )
continue;
GLCapabilitiesGenerator.generateInitStubs(writer, interface_decl, context_specific);
}

View File

@ -68,8 +68,8 @@ import com.sun.mirror.util.DeclarationFilter;
* $Id: ReferencesGeneratorProcessorFactory.java 3237 2009-09-08 15:07:15Z spasi $
*/
public class GLReferencesGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
private final static String REFERENCES_CLASS_NAME = "References";
private final static String REFERENCES_PARAMETER_NAME = "references";
private static final String REFERENCES_CLASS_NAME = "References";
private static final String REFERENCES_PARAMETER_NAME = "references";
private static boolean first_round = true;

View File

@ -31,7 +31,8 @@
*/
package org.lwjgl.util.glu;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* Cylinder.java
@ -80,20 +81,20 @@ public class Cylinder extends Quadric {
float x, y, z, nz, nsign;
int i, j;
if (super.orientation == GLU.GLU_INSIDE) {
if (super.orientation == GLU_INSIDE) {
nsign = -1.0f;
} else {
nsign = 1.0f;
}
da = 2.0f * GLU.PI / slices;
da = 2.0f * PI / slices;
dr = (topRadius - baseRadius) / stacks;
dz = height / stacks;
nz = (baseRadius - topRadius) / height;
// Z component of normal vectors
if (super.drawStyle == GLU.GLU_POINT) {
GL11.glBegin(GL11.GL_POINTS);
if (super.drawStyle == GLU_POINT) {
glBegin(GL_POINTS);
for (i = 0; i < slices; i++) {
x = cos((i * da));
y = sin((i * da));
@ -102,61 +103,61 @@ public class Cylinder extends Quadric {
z = 0.0f;
r = baseRadius;
for (j = 0; j <= stacks; j++) {
GL11.glVertex3f((x * r), (y * r), z);
glVertex3f((x * r), (y * r), z);
z += dz;
r += dr;
}
}
GL11.glEnd();
} else if (super.drawStyle == GLU.GLU_LINE || super.drawStyle == GLU.GLU_SILHOUETTE) {
glEnd();
} else if (super.drawStyle == GLU_LINE || super.drawStyle == GLU_SILHOUETTE) {
// Draw rings
if (super.drawStyle == GLU.GLU_LINE) {
if (super.drawStyle == GLU_LINE) {
z = 0.0f;
r = baseRadius;
for (j = 0; j <= stacks; j++) {
GL11.glBegin(GL11.GL_LINE_LOOP);
glBegin(GL_LINE_LOOP);
for (i = 0; i < slices; i++) {
x = cos((i * da));
y = sin((i * da));
normal3f(x * nsign, y * nsign, nz * nsign);
GL11.glVertex3f((x * r), (y * r), z);
glVertex3f((x * r), (y * r), z);
}
GL11.glEnd();
glEnd();
z += dz;
r += dr;
}
} else {
// draw one ring at each end
if (baseRadius != 0.0) {
GL11.glBegin(GL11.GL_LINE_LOOP);
glBegin(GL_LINE_LOOP);
for (i = 0; i < slices; i++) {
x = cos((i * da));
y = sin((i * da));
normal3f(x * nsign, y * nsign, nz * nsign);
GL11.glVertex3f((x * baseRadius), (y * baseRadius), 0.0f);
glVertex3f((x * baseRadius), (y * baseRadius), 0.0f);
}
GL11.glEnd();
GL11.glBegin(GL11.GL_LINE_LOOP);
glEnd();
glBegin(GL_LINE_LOOP);
for (i = 0; i < slices; i++) {
x = cos((i * da));
y = sin((i * da));
normal3f(x * nsign, y * nsign, nz * nsign);
GL11.glVertex3f((x * topRadius), (y * topRadius), height);
glVertex3f((x * topRadius), (y * topRadius), height);
}
GL11.glEnd();
glEnd();
}
}
// draw length lines
GL11.glBegin(GL11.GL_LINES);
glBegin(GL_LINES);
for (i = 0; i < slices; i++) {
x = cos((i * da));
y = sin((i * da));
normal3f(x * nsign, y * nsign, nz * nsign);
GL11.glVertex3f((x * baseRadius), (y * baseRadius), 0.0f);
GL11.glVertex3f((x * topRadius), (y * topRadius), (height));
glVertex3f((x * baseRadius), (y * baseRadius), 0.0f);
glVertex3f((x * topRadius), (y * topRadius), (height));
}
GL11.glEnd();
} else if (super.drawStyle == GLU.GLU_FILL) {
glEnd();
} else if (super.drawStyle == GLU_FILL) {
float ds = 1.0f / slices;
float dt = 1.0f / stacks;
float t = 0.0f;
@ -164,7 +165,7 @@ public class Cylinder extends Quadric {
r = baseRadius;
for (j = 0; j < stacks; j++) {
float s = 0.0f;
GL11.glBegin(GL11.GL_QUAD_STRIP);
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= slices; i++) {
if (i == slices) {
x = sin(0.0f);
@ -176,21 +177,21 @@ public class Cylinder extends Quadric {
if (nsign == 1.0f) {
normal3f((x * nsign), (y * nsign), (nz * nsign));
TXTR_COORD(s, t);
GL11.glVertex3f((x * r), (y * r), z);
glVertex3f((x * r), (y * r), z);
normal3f((x * nsign), (y * nsign), (nz * nsign));
TXTR_COORD(s, t + dt);
GL11.glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz));
glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz));
} else {
normal3f(x * nsign, y * nsign, nz * nsign);
TXTR_COORD(s, t);
GL11.glVertex3f((x * r), (y * r), z);
glVertex3f((x * r), (y * r), z);
normal3f(x * nsign, y * nsign, nz * nsign);
TXTR_COORD(s, t + dt);
GL11.glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz));
glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz));
}
s += ds;
} // for slices
GL11.glEnd();
glEnd();
r += dr;
t += dt;
z += dz;

View File

@ -31,7 +31,8 @@
*/
package org.lwjgl.util.glu;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* Disk.java
@ -72,20 +73,20 @@ public class Disk extends Quadric {
float da, dr;
/* Normal vectors */
if (super.normals != GLU.GLU_NONE) {
if (super.orientation == GLU.GLU_OUTSIDE) {
GL11.glNormal3f(0.0f, 0.0f, +1.0f);
if (super.normals != GLU_NONE) {
if (super.orientation == GLU_OUTSIDE) {
glNormal3f(0.0f, 0.0f, +1.0f);
}
else {
GL11.glNormal3f(0.0f, 0.0f, -1.0f);
glNormal3f(0.0f, 0.0f, -1.0f);
}
}
da = 2.0f * GLU.PI / slices;
da = 2.0f * PI / slices;
dr = (outerRadius - innerRadius) / loops;
switch (super.drawStyle) {
case GLU.GLU_FILL:
case GLU_FILL:
{
/* texture of a gluDisk is a cut out of the texture unit square
* x, y in [-outerRadius, +outerRadius]; s, t in [0, 1]
@ -97,9 +98,9 @@ public class Disk extends Quadric {
int l;
for (l = 0; l < loops; l++) {
float r2 = r1 + dr;
if (super.orientation == GLU.GLU_OUTSIDE) {
if (super.orientation == GLU_OUTSIDE) {
int s;
GL11.glBegin(GL11.GL_QUAD_STRIP);
glBegin(GL_QUAD_STRIP);
for (s = 0; s <= slices; s++) {
float a;
if (s == slices)
@ -109,15 +110,15 @@ public class Disk extends Quadric {
sa = sin(a);
ca = cos(a);
TXTR_COORD(0.5f + sa * r2 / dtc, 0.5f + ca * r2 / dtc);
GL11.glVertex2f(r2 * sa, r2 * ca);
glVertex2f(r2 * sa, r2 * ca);
TXTR_COORD(0.5f + sa * r1 / dtc, 0.5f + ca * r1 / dtc);
GL11.glVertex2f(r1 * sa, r1 * ca);
glVertex2f(r1 * sa, r1 * ca);
}
GL11.glEnd();
glEnd();
}
else {
int s;
GL11.glBegin(GL11.GL_QUAD_STRIP);
glBegin(GL_QUAD_STRIP);
for (s = slices; s >= 0; s--) {
float a;
if (s == slices)
@ -127,47 +128,47 @@ public class Disk extends Quadric {
sa = sin(a);
ca = cos(a);
TXTR_COORD(0.5f - sa * r2 / dtc, 0.5f + ca * r2 / dtc);
GL11.glVertex2f(r2 * sa, r2 * ca);
glVertex2f(r2 * sa, r2 * ca);
TXTR_COORD(0.5f - sa * r1 / dtc, 0.5f + ca * r1 / dtc);
GL11.glVertex2f(r1 * sa, r1 * ca);
glVertex2f(r1 * sa, r1 * ca);
}
GL11.glEnd();
glEnd();
}
r1 = r2;
}
break;
}
case GLU.GLU_LINE:
case GLU_LINE:
{
int l, s;
/* draw loops */
for (l = 0; l <= loops; l++) {
float r = innerRadius + l * dr;
GL11.glBegin(GL11.GL_LINE_LOOP);
glBegin(GL_LINE_LOOP);
for (s = 0; s < slices; s++) {
float a = s * da;
GL11.glVertex2f(r * sin(a), r * cos(a));
glVertex2f(r * sin(a), r * cos(a));
}
GL11.glEnd();
glEnd();
}
/* draw spokes */
for (s = 0; s < slices; s++) {
float a = s * da;
float x = sin(a);
float y = cos(a);
GL11.glBegin(GL11.GL_LINE_STRIP);
glBegin(GL_LINE_STRIP);
for (l = 0; l <= loops; l++) {
float r = innerRadius + l * dr;
GL11.glVertex2f(r * x, r * y);
glVertex2f(r * x, r * y);
}
GL11.glEnd();
glEnd();
}
break;
}
case GLU.GLU_POINT:
case GLU_POINT:
{
int s;
GL11.glBegin(GL11.GL_POINTS);
glBegin(GL_POINTS);
for (s = 0; s < slices; s++) {
float a = s * da;
float x = sin(a);
@ -175,33 +176,33 @@ public class Disk extends Quadric {
int l;
for (l = 0; l <= loops; l++) {
float r = innerRadius * l * dr;
GL11.glVertex2f(r * x, r * y);
glVertex2f(r * x, r * y);
}
}
GL11.glEnd();
glEnd();
break;
}
case GLU.GLU_SILHOUETTE:
case GLU_SILHOUETTE:
{
if (innerRadius != 0.0) {
float a;
GL11.glBegin(GL11.GL_LINE_LOOP);
for (a = 0.0f; a < 2.0 * GLU.PI; a += da) {
glBegin(GL_LINE_LOOP);
for (a = 0.0f; a < 2.0 * PI; a += da) {
float x = innerRadius * sin(a);
float y = innerRadius * cos(a);
GL11.glVertex2f(x, y);
glVertex2f(x, y);
}
GL11.glEnd();
glEnd();
}
{
float a;
GL11.glBegin(GL11.GL_LINE_LOOP);
for (a = 0; a < 2.0f * GLU.PI; a += da) {
glBegin(GL_LINE_LOOP);
for (a = 0; a < 2.0f * PI; a += da) {
float x = outerRadius * sin(a);
float y = outerRadius * cos(a);
GL11.glVertex2f(x, y);
glVertex2f(x, y);
}
GL11.glEnd();
glEnd();
}
break;
}

View File

@ -35,10 +35,11 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.Util;
import org.lwjgl.util.glu.tessellation.GLUtessellatorImpl;
import static org.lwjgl.opengl.GL11.*;
/**
* GLU.java
*
@ -266,7 +267,7 @@ public class GLU {
float bottom,
float top) {
GL11.glOrtho(left, right, bottom, top, -1.0, 1.0);
glOrtho(left, right, bottom, top, -1.0, 1.0);
}
/**
@ -412,11 +413,11 @@ public class GLU {
public static String gluErrorString(int error_code) {
switch (error_code) {
case GLU.GLU_INVALID_ENUM:
case GLU_INVALID_ENUM:
return "Invalid enum (glu)";
case GLU.GLU_INVALID_VALUE:
case GLU_INVALID_VALUE:
return "Invalid value (glu)";
case GLU.GLU_OUT_OF_MEMORY:
case GLU_OUT_OF_MEMORY:
return "Out of memory (glu)";
default:
return Util.translateGLErrorString(error_code);

View File

@ -34,39 +34,39 @@ package org.lwjgl.util.glu;
public interface GLUtessellator {
public abstract void gluDeleteTess();
void gluDeleteTess();
public abstract void gluTessProperty(int which, double value);
void gluTessProperty(int which, double value);
/* Returns tessellator property */
public abstract void gluGetTessProperty(int which, double[] value,
void gluGetTessProperty(int which, double[] value,
int value_offset); /* gluGetTessProperty() */
public abstract void gluTessNormal(double x, double y, double z);
void gluTessNormal(double x, double y, double z);
public abstract void gluTessCallback(int which,
void gluTessCallback(int which,
GLUtessellatorCallback aCallback);
public abstract void gluTessVertex(double[] coords, int coords_offset,
void gluTessVertex(double[] coords, int coords_offset,
Object vertexData);
public abstract void gluTessBeginPolygon(Object data);
void gluTessBeginPolygon(Object data);
public abstract void gluTessBeginContour();
void gluTessBeginContour();
public abstract void gluTessEndContour();
void gluTessEndContour();
public abstract void gluTessEndPolygon();
void gluTessEndPolygon();
/*******************************************************/
/* Obsolete calls -- for backward compatibility */
public abstract void gluBeginPolygon();
void gluBeginPolygon();
/*ARGSUSED*/
public abstract void gluNextContour(int type);
void gluNextContour(int type);
public abstract void gluEndPolygon();
void gluEndPolygon();
}

View File

@ -112,7 +112,7 @@ public interface GLUtessellatorCallback {
* @see #end end
* @see #begin begin
*/
public void begin(int type);
void begin(int type);
/**
* The same as the {@link #begin begin} callback method except that
@ -131,7 +131,7 @@ public interface GLUtessellatorCallback {
* @see #endData endData
* @see #begin begin
*/
public void beginData(int type, Object polygonData);
void beginData(int type, Object polygonData);
/**
@ -158,7 +158,7 @@ public interface GLUtessellatorCallback {
* @see GLU#gluTessCallback gluTessCallback
* @see #edgeFlagData edgeFlagData
*/
public void edgeFlag(boolean boundaryEdge);
void edgeFlag(boolean boundaryEdge);
/**
@ -175,7 +175,7 @@ public interface GLUtessellatorCallback {
* @see GLU#gluTessCallback gluTessCallback
* @see #edgeFlag edgeFlag
*/
public void edgeFlagData(boolean boundaryEdge, Object polygonData);
void edgeFlagData(boolean boundaryEdge, Object polygonData);
/**
@ -195,7 +195,7 @@ public interface GLUtessellatorCallback {
* @see GLU#gluTessCallback gluTessCallback
* @see #vertexData vertexData
*/
public void vertex(Object vertexData);
void vertex(Object vertexData);
/**
@ -213,7 +213,7 @@ public interface GLUtessellatorCallback {
* @see GLU#gluTessCallback gluTessCallback
* @see #vertex vertex
*/
public void vertexData(Object vertexData, Object polygonData);
void vertexData(Object vertexData, Object polygonData);
/**
@ -225,7 +225,7 @@ public interface GLUtessellatorCallback {
* @see #begin begin
* @see #endData endData
*/
public void end();
void end();
/**
@ -241,7 +241,7 @@ public interface GLUtessellatorCallback {
* @see #beginData beginData
* @see #end end
*/
public void endData(Object polygonData);
void endData(Object polygonData);
/**
@ -308,8 +308,8 @@ public interface GLUtessellatorCallback {
* @see GLU#gluTessCallback gluTessCallback
* @see #combineData combineData
*/
public void combine(double[] coords, Object[] data,
float[] weight, Object[] outData);
void combine(double[] coords, Object[] data,
float[] weight, Object[] outData);
/**
@ -332,9 +332,9 @@ public interface GLUtessellatorCallback {
* @see GLU#gluTessCallback gluTessCallback
* @see #combine combine
*/
public void combineData(double[] coords, Object[] data,
float[] weight, Object[] outData,
Object polygonData);
void combineData(double[] coords, Object[] data,
float[] weight, Object[] outData,
Object polygonData);
/**
@ -365,7 +365,7 @@ public interface GLUtessellatorCallback {
* @see GLU#gluTessCallback gluTessCallback
* @see #errorData errorData
*/
public void error(int errnum);
void error(int errnum);
/**
@ -382,7 +382,7 @@ public interface GLUtessellatorCallback {
* @see GLU#gluTessCallback gluTessCallback
* @see #error error
*/
public void errorData(int errnum, Object polygonData);
void errorData(int errnum, Object polygonData);
//void mesh(com.sun.opengl.impl.tessellator.GLUmesh mesh);
}

View File

@ -34,7 +34,9 @@ package org.lwjgl.util.glu;
import java.nio.ByteBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* MipMap.java
@ -60,13 +62,13 @@ public class MipMap extends Util {
public static int gluBuild2DMipmaps(final int target,
final int components, final int width, final int height,
final int format, final int type, final ByteBuffer data) {
if ( width < 1 || height < 1 ) return GLU.GLU_INVALID_VALUE;
if ( width < 1 || height < 1 ) return GLU_INVALID_VALUE;
final int bpp = bytesPerPixel(format, type);
if ( bpp == 0 )
return GLU.GLU_INVALID_ENUM;
return GLU_INVALID_ENUM;
final int maxSize = glGetIntegerv(GL11.GL_MAX_TEXTURE_SIZE);
final int maxSize = glGetIntegerv(GL_MAX_TEXTURE_SIZE);
int w = nearestPower(width);
if ( w > maxSize )
@ -80,10 +82,10 @@ public class MipMap extends Util {
PixelStoreState pss = new PixelStoreState();
// set pixel packing
GL11.glPixelStorei(GL11.GL_PACK_ROW_LENGTH, 0);
GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
GL11.glPixelStorei(GL11.GL_PACK_SKIP_ROWS, 0);
GL11.glPixelStorei(GL11.GL_PACK_SKIP_PIXELS, 0);
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_SKIP_ROWS, 0);
glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
ByteBuffer image;
int retVal = 0;
@ -99,10 +101,10 @@ public class MipMap extends Util {
}
/* set pixel unpacking */
GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, 0);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, 0);
GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
} else {
image = data;
}
@ -114,13 +116,13 @@ public class MipMap extends Util {
while ( !done ) {
if (image != data) {
/* set pixel unpacking */
GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, 0);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, 0);
GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
}
GL11.glTexImage2D(target, level, components, w, h, 0, format, type, image);
glTexImage2D(target, level, components, w, h, 0, format, type, image);
if ( w == 1 && h == 1 )
break;
@ -177,7 +179,7 @@ public class MipMap extends Util {
final int components = compPerPix(format);
if ( components == -1 )
return GLU.GLU_INVALID_ENUM;
return GLU_INVALID_ENUM;
int i, j, k;
float[] tempIn, tempOut;
@ -191,26 +193,26 @@ public class MipMap extends Util {
// Determine bytes per input type
switch ( typein ) {
case GL11.GL_UNSIGNED_BYTE:
case GL_UNSIGNED_BYTE:
sizein = 1;
break;
case GL11.GL_FLOAT:
case GL_FLOAT:
sizein = 4;
break;
default:
return GL11.GL_INVALID_ENUM;
return GL_INVALID_ENUM;
}
// Determine bytes per output type
switch ( typeOut ) {
case GL11.GL_UNSIGNED_BYTE:
case GL_UNSIGNED_BYTE:
sizeout = 1;
break;
case GL11.GL_FLOAT:
case GL_FLOAT:
sizeout = 4;
break;
default:
return GL11.GL_INVALID_ENUM;
return GL_INVALID_ENUM;
}
// Get glPixelStore state
@ -228,7 +230,7 @@ public class MipMap extends Util {
rowstride = pss.unpackAlignment / sizein * ceil(components * rowlen * sizein, pss.unpackAlignment);
switch ( typein ) {
case GL11.GL_UNSIGNED_BYTE:
case GL_UNSIGNED_BYTE:
k = 0;
dataIn.rewind();
for ( i = 0; i < heightIn; i++ ) {
@ -238,7 +240,7 @@ public class MipMap extends Util {
}
}
break;
case GL11.GL_FLOAT:
case GL_FLOAT:
k = 0;
dataIn.rewind();
for ( i = 0; i < heightIn; i++ )
@ -252,7 +254,7 @@ public class MipMap extends Util {
}
break;
default:
return GLU.GLU_INVALID_ENUM;
return GLU_INVALID_ENUM;
}
// Do scaling
@ -321,7 +323,7 @@ public class MipMap extends Util {
rowstride = pss.packAlignment / sizeout * ceil(components * rowlen * sizeout, pss.packAlignment);
switch ( typeOut ) {
case GL11.GL_UNSIGNED_BYTE:
case GL_UNSIGNED_BYTE:
k = 0;
for ( i = 0; i < heightOut; i++ ) {
int ubptr = i * rowstride + pss.packSkipRows * rowstride + pss.packSkipPixels * components;
@ -331,7 +333,7 @@ public class MipMap extends Util {
}
}
break;
case GL11.GL_FLOAT:
case GL_FLOAT:
k = 0;
for ( i = 0; i < heightOut; i++ ) {
int fptr = 4 * (i * rowstride + pss.unpackSkipRows * rowstride + pss.unpackSkipPixels * components);
@ -343,7 +345,7 @@ public class MipMap extends Util {
}
break;
default:
return GLU.GLU_INVALID_ENUM;
return GLU_INVALID_ENUM;
}
return 0;

View File

@ -31,7 +31,8 @@
*/
package org.lwjgl.util.glu;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* PartialDisk.java
@ -127,9 +128,9 @@ public class PartialDisk extends Quadric {
/* Cache is the vertex locations cache */
angleOffset = startAngle / 180.0f * GLU.PI;
angleOffset = startAngle / 180.0f * PI;
for (i = 0; i <= slices; i++) {
angle = angleOffset + ((GLU.PI * sweepAngle) / 180.0f) * i / slices;
angle = angleOffset + ((PI * sweepAngle) / 180.0f) * i / slices;
sinCache[i] = sin(angle);
cosCache[i] = cos(angle);
}
@ -140,54 +141,54 @@ public class PartialDisk extends Quadric {
}
switch (super.normals) {
case GLU.GLU_FLAT :
case GLU.GLU_SMOOTH :
if (super.orientation == GLU.GLU_OUTSIDE) {
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
case GLU_FLAT :
case GLU_SMOOTH :
if (super.orientation == GLU_OUTSIDE) {
glNormal3f(0.0f, 0.0f, 1.0f);
} else {
GL11.glNormal3f(0.0f, 0.0f, -1.0f);
glNormal3f(0.0f, 0.0f, -1.0f);
}
break;
default :
case GLU.GLU_NONE :
case GLU_NONE :
break;
}
switch (super.drawStyle) {
case GLU.GLU_FILL :
case GLU_FILL :
if (innerRadius == .0f) {
finish = loops - 1;
/* Triangle strip for inner polygons */
GL11.glBegin(GL11.GL_TRIANGLE_FAN);
glBegin(GL_TRIANGLE_FAN);
if (super.textureFlag) {
GL11.glTexCoord2f(0.5f, 0.5f);
glTexCoord2f(0.5f, 0.5f);
}
GL11.glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
radiusLow = outerRadius - deltaRadius * ((float) (loops - 1) / loops);
if (super.textureFlag) {
texLow = radiusLow / outerRadius / 2;
}
if (super.orientation == GLU.GLU_OUTSIDE) {
if (super.orientation == GLU_OUTSIDE) {
for (i = slices; i >= 0; i--) {
if (super.textureFlag) {
GL11.glTexCoord2f(
glTexCoord2f(
texLow * sinCache[i] + 0.5f,
texLow * cosCache[i] + 0.5f);
}
GL11.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
}
} else {
for (i = 0; i <= slices; i++) {
if (super.textureFlag) {
GL11.glTexCoord2f(
glTexCoord2f(
texLow * sinCache[i] + 0.5f,
texLow * cosCache[i] + 0.5f);
}
GL11.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
}
}
GL11.glEnd();
glEnd();
} else {
finish = loops;
}
@ -199,49 +200,49 @@ public class PartialDisk extends Quadric {
texHigh = radiusHigh / outerRadius / 2;
}
GL11.glBegin(GL11.GL_QUAD_STRIP);
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= slices; i++) {
if (super.orientation == GLU.GLU_OUTSIDE) {
if (super.orientation == GLU_OUTSIDE) {
if (super.textureFlag) {
GL11.glTexCoord2f(
glTexCoord2f(
texLow * sinCache[i] + 0.5f,
texLow * cosCache[i] + 0.5f);
}
GL11.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
if (super.textureFlag) {
GL11.glTexCoord2f(
glTexCoord2f(
texHigh * sinCache[i] + 0.5f,
texHigh * cosCache[i] + 0.5f);
}
GL11.glVertex3f(
glVertex3f(
radiusHigh * sinCache[i],
radiusHigh * cosCache[i],
0.0f);
} else {
if (super.textureFlag) {
GL11.glTexCoord2f(
glTexCoord2f(
texHigh * sinCache[i] + 0.5f,
texHigh * cosCache[i] + 0.5f);
}
GL11.glVertex3f(
glVertex3f(
radiusHigh * sinCache[i],
radiusHigh * cosCache[i],
0.0f);
if (super.textureFlag) {
GL11.glTexCoord2f(
glTexCoord2f(
texLow * sinCache[i] + 0.5f,
texLow * cosCache[i] + 0.5f);
}
GL11.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
}
}
GL11.glEnd();
glEnd();
}
break;
case GLU.GLU_POINT :
GL11.glBegin(GL11.GL_POINTS);
case GLU_POINT :
glBegin(GL_POINTS);
for (i = 0; i < slices2; i++) {
sintemp = sinCache[i];
costemp = cosCache[i];
@ -251,26 +252,26 @@ public class PartialDisk extends Quadric {
if (super.textureFlag) {
texLow = radiusLow / outerRadius / 2;
GL11.glTexCoord2f(
glTexCoord2f(
texLow * sinCache[i] + 0.5f,
texLow * cosCache[i] + 0.5f);
}
GL11.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f);
glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f);
}
}
GL11.glEnd();
glEnd();
break;
case GLU.GLU_LINE :
case GLU_LINE :
if (innerRadius == outerRadius) {
GL11.glBegin(GL11.GL_LINE_STRIP);
glBegin(GL_LINE_STRIP);
for (i = 0; i <= slices; i++) {
if (super.textureFlag) {
GL11.glTexCoord2f(sinCache[i] / 2 + 0.5f, cosCache[i] / 2 + 0.5f);
glTexCoord2f(sinCache[i] / 2 + 0.5f, cosCache[i] / 2 + 0.5f);
}
GL11.glVertex3f(innerRadius * sinCache[i], innerRadius * cosCache[i], 0.0f);
glVertex3f(innerRadius * sinCache[i], innerRadius * cosCache[i], 0.0f);
}
GL11.glEnd();
glEnd();
break;
}
for (j = 0; j <= loops; j++) {
@ -279,21 +280,21 @@ public class PartialDisk extends Quadric {
texLow = radiusLow / outerRadius / 2;
}
GL11.glBegin(GL11.GL_LINE_STRIP);
glBegin(GL_LINE_STRIP);
for (i = 0; i <= slices; i++) {
if (super.textureFlag) {
GL11.glTexCoord2f(
glTexCoord2f(
texLow * sinCache[i] + 0.5f,
texLow * cosCache[i] + 0.5f);
}
GL11.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
}
GL11.glEnd();
glEnd();
}
for (i = 0; i < slices2; i++) {
sintemp = sinCache[i];
costemp = cosCache[i];
GL11.glBegin(GL11.GL_LINE_STRIP);
glBegin(GL_LINE_STRIP);
for (j = 0; j <= loops; j++) {
radiusLow = outerRadius - deltaRadius * ((float) j / loops);
if (super.textureFlag) {
@ -301,33 +302,33 @@ public class PartialDisk extends Quadric {
}
if (super.textureFlag) {
GL11.glTexCoord2f(
glTexCoord2f(
texLow * sinCache[i] + 0.5f,
texLow * cosCache[i] + 0.5f);
}
GL11.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f);
glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f);
}
GL11.glEnd();
glEnd();
}
break;
case GLU.GLU_SILHOUETTE :
case GLU_SILHOUETTE :
if (sweepAngle < 360.0f) {
for (i = 0; i <= slices; i += slices) {
sintemp = sinCache[i];
costemp = cosCache[i];
GL11.glBegin(GL11.GL_LINE_STRIP);
glBegin(GL_LINE_STRIP);
for (j = 0; j <= loops; j++) {
radiusLow = outerRadius - deltaRadius * ((float) j / loops);
if (super.textureFlag) {
texLow = radiusLow / outerRadius / 2;
GL11.glTexCoord2f(
glTexCoord2f(
texLow * sinCache[i] + 0.5f,
texLow * cosCache[i] + 0.5f);
}
GL11.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f);
glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f);
}
GL11.glEnd();
glEnd();
}
}
for (j = 0; j <= loops; j += loops) {
@ -336,16 +337,16 @@ public class PartialDisk extends Quadric {
texLow = radiusLow / outerRadius / 2;
}
GL11.glBegin(GL11.GL_LINE_STRIP);
glBegin(GL_LINE_STRIP);
for (i = 0; i <= slices; i++) {
if (super.textureFlag) {
GL11.glTexCoord2f(
glTexCoord2f(
texLow * sinCache[i] + 0.5f,
texLow * cosCache[i] + 0.5f);
}
GL11.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
}
GL11.glEnd();
glEnd();
if (innerRadius == outerRadius)
break;
}

View File

@ -31,7 +31,7 @@
*/
package org.lwjgl.util.glu;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
/**
* PixelStoreState.java
@ -60,25 +60,25 @@ class PixelStoreState extends Util {
}
public void load() {
unpackRowLength = glGetIntegerv(GL11.GL_UNPACK_ROW_LENGTH);
unpackAlignment = glGetIntegerv(GL11.GL_UNPACK_ALIGNMENT);
unpackSkipRows = glGetIntegerv(GL11.GL_UNPACK_SKIP_ROWS);
unpackSkipPixels = glGetIntegerv(GL11.GL_UNPACK_SKIP_PIXELS);
packRowLength = glGetIntegerv(GL11.GL_PACK_ROW_LENGTH);
packAlignment = glGetIntegerv(GL11.GL_PACK_ALIGNMENT);
packSkipRows = glGetIntegerv(GL11.GL_PACK_SKIP_ROWS);
packSkipPixels = glGetIntegerv(GL11.GL_PACK_SKIP_PIXELS);
unpackRowLength = glGetIntegerv(GL_UNPACK_ROW_LENGTH);
unpackAlignment = glGetIntegerv(GL_UNPACK_ALIGNMENT);
unpackSkipRows = glGetIntegerv(GL_UNPACK_SKIP_ROWS);
unpackSkipPixels = glGetIntegerv(GL_UNPACK_SKIP_PIXELS);
packRowLength = glGetIntegerv(GL_PACK_ROW_LENGTH);
packAlignment = glGetIntegerv(GL_PACK_ALIGNMENT);
packSkipRows = glGetIntegerv(GL_PACK_SKIP_ROWS);
packSkipPixels = glGetIntegerv(GL_PACK_SKIP_PIXELS);
}
public void save() {
GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, unpackRowLength);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, unpackAlignment);
GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, unpackSkipRows);
GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
GL11.glPixelStorei(GL11.GL_PACK_ROW_LENGTH, packRowLength);
GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, packAlignment);
GL11.glPixelStorei(GL11.GL_PACK_SKIP_ROWS, packSkipRows);
GL11.glPixelStorei(GL11.GL_PACK_SKIP_PIXELS, packSkipPixels);
glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
glPixelStorei(GL_UNPACK_ALIGNMENT, unpackAlignment);
glPixelStorei(GL_UNPACK_SKIP_ROWS, unpackSkipRows);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
glPixelStorei(GL_PACK_ROW_LENGTH, packRowLength);
glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);
glPixelStorei(GL_PACK_SKIP_ROWS, packSkipRows);
glPixelStorei(GL_PACK_SKIP_PIXELS, packSkipPixels);
}
}

View File

@ -37,6 +37,8 @@ import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
/**
* Project.java
* <p/>
@ -213,7 +215,7 @@ public class Project extends Util {
matrix.put(3 * 4 + 2, -2 * zNear * zFar / deltaZ);
matrix.put(3 * 4 + 3, 0);
GL11.glMultMatrix(matrix);
glMultMatrix(matrix);
}
/**
@ -273,8 +275,8 @@ public class Project extends Util {
matrix.put(1 * 4 + 2, -forward[1]);
matrix.put(2 * 4 + 2, -forward[2]);
GL11.glMultMatrix(matrix);
GL11.glTranslatef(-eyex, -eyey, -eyez);
glMultMatrix(matrix);
glTranslatef(-eyex, -eyey, -eyez);
}
/**
@ -401,10 +403,10 @@ public class Project extends Util {
}
/* Translate and scale the picked region to the entire window */
GL11.glTranslatef(
glTranslatef(
(viewport.get(viewport.position() + 2) - 2 * (x - viewport.get(viewport.position() + 0))) / deltaX,
(viewport.get(viewport.position() + 3) - 2 * (y - viewport.get(viewport.position() + 1))) / deltaY,
0);
GL11.glScalef(viewport.get(viewport.position() + 2) / deltaX, viewport.get(viewport.position() + 3) / deltaY, 1.0f);
glScalef(viewport.get(viewport.position() + 2) / deltaX, viewport.get(viewport.position() + 3) / deltaY, 1.0f);
}
}

View File

@ -31,7 +31,8 @@
*/
package org.lwjgl.util.glu;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* Quadric.java
@ -53,10 +54,10 @@ public class Quadric {
public Quadric() {
super();
drawStyle = GLU.GLU_FILL;
orientation = GLU.GLU_OUTSIDE;
drawStyle = GLU_FILL;
orientation = GLU_OUTSIDE;
textureFlag = false;
normals = GLU.GLU_SMOOTH;
normals = GLU_SMOOTH;
}
/**
@ -75,7 +76,7 @@ public class Quadric {
y /= mag;
z /= mag;
}
GL11.glNormal3f(x, y, z);
glNormal3f(x, y, z);
}
/**
@ -183,7 +184,7 @@ public class Quadric {
}
protected void TXTR_COORD(float x, float y) {
if (textureFlag) GL11.glTexCoord2f(x,y);
if (textureFlag) glTexCoord2f(x,y);
}

View File

@ -31,6 +31,8 @@
*/
package org.lwjgl.util.glu;
import static org.lwjgl.util.glu.GLU.*;
/**
* Registry.java
*
@ -51,9 +53,9 @@ public class Registry extends Util {
*/
public static String gluGetString(int name) {
if (name == GLU.GLU_VERSION) {
if (name == GLU_VERSION) {
return versionString;
} else if (name == GLU.GLU_EXTENSIONS) {
} else if (name == GLU_EXTENSIONS) {
return extensionString;
}
return null;

View File

@ -31,8 +31,8 @@
*/
package org.lwjgl.util.glu;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
/**
* Sphere.java
@ -75,34 +75,34 @@ public class Sphere extends Quadric {
boolean normals;
float nsign;
normals = super.normals != GLU.GLU_NONE;
normals = super.normals != GLU_NONE;
if (super.orientation == GLU.GLU_INSIDE) {
if (super.orientation == GLU_INSIDE) {
nsign = -1.0f;
} else {
nsign = 1.0f;
}
drho = GLU.PI / stacks;
dtheta = 2.0f * GLU.PI / slices;
drho = PI / stacks;
dtheta = 2.0f * PI / slices;
if (super.drawStyle == GLU.GLU_FILL) {
if (super.drawStyle == GLU_FILL) {
if (!super.textureFlag) {
// draw +Z end as a triangle fan
GL11.glBegin(GL11.GL_TRIANGLE_FAN);
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f(0.0f, 0.0f, nsign * radius);
glBegin(GL_TRIANGLE_FAN);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, nsign * radius);
for (j = 0; j <= slices; j++) {
theta = (j == slices) ? 0.0f : j * dtheta;
x = -sin(theta) * sin(drho);
y = cos(theta) * sin(drho);
z = nsign * cos(drho);
if (normals) {
GL11.glNormal3f(x * nsign, y * nsign, z * nsign);
glNormal3f(x * nsign, y * nsign, z * nsign);
}
GL11.glVertex3f(x * radius, y * radius, z * radius);
glVertex3f(x * radius, y * radius, z * radius);
}
GL11.glEnd();
glEnd();
}
ds = 1.0f / slices;
@ -119,7 +119,7 @@ public class Sphere extends Quadric {
// draw intermediate stacks as quad strips
for (i = imin; i < imax; i++) {
rho = i * drho;
GL11.glBegin(GL11.GL_QUAD_STRIP);
glBegin(GL_QUAD_STRIP);
s = 0.0f;
for (j = 0; j <= slices; j++) {
theta = (j == slices) ? 0.0f : j * dtheta;
@ -127,30 +127,30 @@ public class Sphere extends Quadric {
y = cos(theta) * sin(rho);
z = nsign * cos(rho);
if (normals) {
GL11.glNormal3f(x * nsign, y * nsign, z * nsign);
glNormal3f(x * nsign, y * nsign, z * nsign);
}
TXTR_COORD(s, t);
GL11.glVertex3f(x * radius, y * radius, z * radius);
glVertex3f(x * radius, y * radius, z * radius);
x = -sin(theta) * sin(rho + drho);
y = cos(theta) * sin(rho + drho);
z = nsign * cos(rho + drho);
if (normals) {
GL11.glNormal3f(x * nsign, y * nsign, z * nsign);
glNormal3f(x * nsign, y * nsign, z * nsign);
}
TXTR_COORD(s, t - dt);
s += ds;
GL11.glVertex3f(x * radius, y * radius, z * radius);
glVertex3f(x * radius, y * radius, z * radius);
}
GL11.glEnd();
glEnd();
t -= dt;
}
if (!super.textureFlag) {
// draw -Z end as a triangle fan
GL11.glBegin(GL11.GL_TRIANGLE_FAN);
GL11.glNormal3f(0.0f, 0.0f, -1.0f);
GL11.glVertex3f(0.0f, 0.0f, -radius * nsign);
rho = GLU.PI - drho;
glBegin(GL_TRIANGLE_FAN);
glNormal3f(0.0f, 0.0f, -1.0f);
glVertex3f(0.0f, 0.0f, -radius * nsign);
rho = PI - drho;
s = 1.0f;
for (j = slices; j >= 0; j--) {
theta = (j == slices) ? 0.0f : j * dtheta;
@ -158,56 +158,56 @@ public class Sphere extends Quadric {
y = cos(theta) * sin(rho);
z = nsign * cos(rho);
if (normals)
GL11.glNormal3f(x * nsign, y * nsign, z * nsign);
glNormal3f(x * nsign, y * nsign, z * nsign);
s -= ds;
GL11.glVertex3f(x * radius, y * radius, z * radius);
glVertex3f(x * radius, y * radius, z * radius);
}
GL11.glEnd();
glEnd();
}
} else if (
super.drawStyle == GLU.GLU_LINE
|| super.drawStyle == GLU.GLU_SILHOUETTE) {
super.drawStyle == GLU_LINE
|| super.drawStyle == GLU_SILHOUETTE) {
// draw stack lines
for (i = 1;
i < stacks;
i++) { // stack line at i==stacks-1 was missing here
rho = i * drho;
GL11.glBegin(GL11.GL_LINE_LOOP);
glBegin(GL_LINE_LOOP);
for (j = 0; j < slices; j++) {
theta = j * dtheta;
x = cos(theta) * sin(rho);
y = sin(theta) * sin(rho);
z = cos(rho);
if (normals)
GL11.glNormal3f(x * nsign, y * nsign, z * nsign);
GL11.glVertex3f(x * radius, y * radius, z * radius);
glNormal3f(x * nsign, y * nsign, z * nsign);
glVertex3f(x * radius, y * radius, z * radius);
}
GL11.glEnd();
glEnd();
}
// draw slice lines
for (j = 0; j < slices; j++) {
theta = j * dtheta;
GL11.glBegin(GL11.GL_LINE_STRIP);
glBegin(GL_LINE_STRIP);
for (i = 0; i <= stacks; i++) {
rho = i * drho;
x = cos(theta) * sin(rho);
y = sin(theta) * sin(rho);
z = cos(rho);
if (normals)
GL11.glNormal3f(x * nsign, y * nsign, z * nsign);
GL11.glVertex3f(x * radius, y * radius, z * radius);
glNormal3f(x * nsign, y * nsign, z * nsign);
glVertex3f(x * radius, y * radius, z * radius);
}
GL11.glEnd();
glEnd();
}
} else if (super.drawStyle == GLU.GLU_POINT) {
} else if (super.drawStyle == GLU_POINT) {
// top and bottom-most points
GL11.glBegin(GL11.GL_POINTS);
glBegin(GL_POINTS);
if (normals)
GL11.glNormal3f(0.0f, 0.0f, nsign);
GL11.glVertex3f(0.0f, 0.0f, radius);
glNormal3f(0.0f, 0.0f, nsign);
glVertex3f(0.0f, 0.0f, radius);
if (normals)
GL11.glNormal3f(0.0f, 0.0f, -nsign);
GL11.glVertex3f(0.0f, 0.0f, -radius);
glNormal3f(0.0f, 0.0f, -nsign);
glVertex3f(0.0f, 0.0f, -radius);
// loop over stacks
for (i = 1; i < stacks - 1; i++) {
@ -218,11 +218,11 @@ public class Sphere extends Quadric {
y = sin(theta) * sin(rho);
z = cos(rho);
if (normals)
GL11.glNormal3f(x * nsign, y * nsign, z * nsign);
GL11.glVertex3f(x * radius, y * radius, z * radius);
glNormal3f(x * nsign, y * nsign, z * nsign);
glVertex3f(x * radius, y * radius, z * radius);
}
}
GL11.glEnd();
glEnd();
}
}

View File

@ -34,8 +34,9 @@ package org.lwjgl.util.glu;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
/**
* Util.java
@ -110,22 +111,22 @@ public class Util {
protected static int compPerPix(int format) {
/* Determine number of components per pixel */
switch ( format ) {
case GL11.GL_COLOR_INDEX:
case GL11.GL_STENCIL_INDEX:
case GL11.GL_DEPTH_COMPONENT:
case GL11.GL_RED:
case GL11.GL_GREEN:
case GL11.GL_BLUE:
case GL11.GL_ALPHA:
case GL11.GL_LUMINANCE:
case GL_COLOR_INDEX:
case GL_STENCIL_INDEX:
case GL_DEPTH_COMPONENT:
case GL_RED:
case GL_GREEN:
case GL_BLUE:
case GL_ALPHA:
case GL_LUMINANCE:
return 1;
case GL11.GL_LUMINANCE_ALPHA:
case GL_LUMINANCE_ALPHA:
return 2;
case GL11.GL_RGB:
case GL12.GL_BGR:
case GL_RGB:
case GL_BGR:
return 3;
case GL11.GL_RGBA:
case GL12.GL_BGRA:
case GL_RGBA:
case GL_BGRA:
return 4;
default :
return -1;
@ -173,25 +174,25 @@ public class Util {
int n, m;
switch ( format ) {
case GL11.GL_COLOR_INDEX:
case GL11.GL_STENCIL_INDEX:
case GL11.GL_DEPTH_COMPONENT:
case GL11.GL_RED:
case GL11.GL_GREEN:
case GL11.GL_BLUE:
case GL11.GL_ALPHA:
case GL11.GL_LUMINANCE:
case GL_COLOR_INDEX:
case GL_STENCIL_INDEX:
case GL_DEPTH_COMPONENT:
case GL_RED:
case GL_GREEN:
case GL_BLUE:
case GL_ALPHA:
case GL_LUMINANCE:
n = 1;
break;
case GL11.GL_LUMINANCE_ALPHA:
case GL_LUMINANCE_ALPHA:
n = 2;
break;
case GL11.GL_RGB:
case GL12.GL_BGR:
case GL_RGB:
case GL_BGR:
n = 3;
break;
case GL11.GL_RGBA:
case GL12.GL_BGRA:
case GL_RGBA:
case GL_BGRA:
n = 4;
break;
default :
@ -199,28 +200,28 @@ public class Util {
}
switch ( type ) {
case GL11.GL_UNSIGNED_BYTE:
case GL_UNSIGNED_BYTE:
m = 1;
break;
case GL11.GL_BYTE:
case GL_BYTE:
m = 1;
break;
case GL11.GL_BITMAP:
case GL_BITMAP:
m = 1;
break;
case GL11.GL_UNSIGNED_SHORT:
case GL_UNSIGNED_SHORT:
m = 2;
break;
case GL11.GL_SHORT:
case GL_SHORT:
m = 2;
break;
case GL11.GL_UNSIGNED_INT:
case GL_UNSIGNED_INT:
m = 4;
break;
case GL11.GL_INT:
case GL_INT:
m = 4;
break;
case GL11.GL_FLOAT:
case GL_FLOAT:
m = 4;
break;
default :
@ -239,7 +240,7 @@ public class Util {
*/
protected static int glGetIntegerv(int what) {
scratch.rewind();
GL11.glGetInteger(what, scratch);
glGetInteger(what, scratch);
return scratch.get();
}

View File

@ -99,7 +99,7 @@ class GLUhalfEdge {
public int winding; /* change in winding number when crossing */
public boolean first;
public GLUhalfEdge(boolean first) {
GLUhalfEdge(boolean first) {
this.first = first;
}
}

View File

@ -84,11 +84,12 @@
*/
package org.lwjgl.util.glu.tessellation;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.glu.GLUtessellator;
import org.lwjgl.util.glu.GLUtessellatorCallback;
import org.lwjgl.util.glu.GLUtessellatorCallbackAdapter;
import static org.lwjgl.util.glu.GLU.*;
public class GLUtessellatorImpl implements GLUtessellator {
public static final int TESS_MAX_CACHE = 100;
@ -163,7 +164,7 @@ public class GLUtessellatorImpl implements GLUtessellator {
normal[2] = 0;
relTolerance = GLU_TESS_DEFAULT_TOLERANCE;
windingRule = GLU.GLU_TESS_WINDING_ODD;
windingRule = GLU_TESS_WINDING_ODD;
flagBoundary = false;
boundaryOnly = false;
@ -189,7 +190,7 @@ public class GLUtessellatorImpl implements GLUtessellator {
}
}
static public GLUtessellator gluNewTess()
public static GLUtessellator gluNewTess()
{
return new GLUtessellatorImpl();
}
@ -217,18 +218,18 @@ public class GLUtessellatorImpl implements GLUtessellator {
*/
if (state < newState) {
if (state == TessState.T_DORMANT) {
callErrorOrErrorData(GLU.GLU_TESS_MISSING_BEGIN_POLYGON);
callErrorOrErrorData(GLU_TESS_MISSING_BEGIN_POLYGON);
gluTessBeginPolygon(null);
} else if (state == TessState.T_IN_POLYGON) {
callErrorOrErrorData(GLU.GLU_TESS_MISSING_BEGIN_CONTOUR);
callErrorOrErrorData(GLU_TESS_MISSING_BEGIN_CONTOUR);
gluTessBeginContour();
}
} else {
if (state == TessState.T_IN_CONTOUR) {
callErrorOrErrorData(GLU.GLU_TESS_MISSING_END_CONTOUR);
callErrorOrErrorData(GLU_TESS_MISSING_END_CONTOUR);
gluTessEndContour();
} else if (state == TessState.T_IN_POLYGON) {
callErrorOrErrorData(GLU.GLU_TESS_MISSING_END_POLYGON);
callErrorOrErrorData(GLU_TESS_MISSING_END_POLYGON);
/* gluTessEndPolygon( tess ) is too much work! */
makeDormant();
}
@ -242,61 +243,61 @@ public class GLUtessellatorImpl implements GLUtessellator {
public void gluTessProperty(int which, double value) {
switch (which) {
case GLU.GLU_TESS_TOLERANCE:
case GLU_TESS_TOLERANCE:
if (value < 0.0 || value > 1.0) break;
relTolerance = value;
return;
case GLU.GLU_TESS_WINDING_RULE:
case GLU_TESS_WINDING_RULE:
int windingRule = (int) value;
if (windingRule != value) break; /* not an integer */
switch (windingRule) {
case GLU.GLU_TESS_WINDING_ODD:
case GLU.GLU_TESS_WINDING_NONZERO:
case GLU.GLU_TESS_WINDING_POSITIVE:
case GLU.GLU_TESS_WINDING_NEGATIVE:
case GLU.GLU_TESS_WINDING_ABS_GEQ_TWO:
case GLU_TESS_WINDING_ODD:
case GLU_TESS_WINDING_NONZERO:
case GLU_TESS_WINDING_POSITIVE:
case GLU_TESS_WINDING_NEGATIVE:
case GLU_TESS_WINDING_ABS_GEQ_TWO:
this.windingRule = windingRule;
return;
default:
break;
}
case GLU.GLU_TESS_BOUNDARY_ONLY:
case GLU_TESS_BOUNDARY_ONLY:
boundaryOnly = (value != 0);
return;
default:
callErrorOrErrorData(GLU.GLU_INVALID_ENUM);
callErrorOrErrorData(GLU_INVALID_ENUM);
return;
}
callErrorOrErrorData(GLU.GLU_INVALID_VALUE);
callErrorOrErrorData(GLU_INVALID_VALUE);
}
/* Returns tessellator property */
public void gluGetTessProperty(int which, double[] value, int value_offset) {
switch (which) {
case GLU.GLU_TESS_TOLERANCE:
case GLU_TESS_TOLERANCE:
/* tolerance should be in range [0..1] */
assert (0.0 <= relTolerance && relTolerance <= 1.0);
value[value_offset] = relTolerance;
break;
case GLU.GLU_TESS_WINDING_RULE:
assert (windingRule == GLU.GLU_TESS_WINDING_ODD ||
windingRule == GLU.GLU_TESS_WINDING_NONZERO ||
windingRule == GLU.GLU_TESS_WINDING_POSITIVE ||
windingRule == GLU.GLU_TESS_WINDING_NEGATIVE ||
windingRule == GLU.GLU_TESS_WINDING_ABS_GEQ_TWO);
case GLU_TESS_WINDING_RULE:
assert (windingRule == GLU_TESS_WINDING_ODD ||
windingRule == GLU_TESS_WINDING_NONZERO ||
windingRule == GLU_TESS_WINDING_POSITIVE ||
windingRule == GLU_TESS_WINDING_NEGATIVE ||
windingRule == GLU_TESS_WINDING_ABS_GEQ_TWO);
value[value_offset] = windingRule;
break;
case GLU.GLU_TESS_BOUNDARY_ONLY:
case GLU_TESS_BOUNDARY_ONLY:
assert (boundaryOnly == true || boundaryOnly == false);
value[value_offset] = boundaryOnly ? 1 : 0;
break;
default:
value[value_offset] = 0.0;
callErrorOrErrorData(GLU.GLU_INVALID_ENUM);
callErrorOrErrorData(GLU_INVALID_ENUM);
break;
}
} /* gluGetTessProperty() */
@ -309,55 +310,55 @@ public class GLUtessellatorImpl implements GLUtessellator {
public void gluTessCallback(int which, GLUtessellatorCallback aCallback) {
switch (which) {
case GLU.GLU_TESS_BEGIN:
case GLU_TESS_BEGIN:
callBegin = aCallback == null ? NULL_CB : aCallback;
return;
case GLU.GLU_TESS_BEGIN_DATA:
case GLU_TESS_BEGIN_DATA:
callBeginData = aCallback == null ? NULL_CB : aCallback;
return;
case GLU.GLU_TESS_EDGE_FLAG:
case GLU_TESS_EDGE_FLAG:
callEdgeFlag = aCallback == null ? NULL_CB : aCallback;
/* If the client wants boundary edges to be flagged,
* we render everything as separate triangles (no strips or fans).
*/
flagBoundary = aCallback != null;
return;
case GLU.GLU_TESS_EDGE_FLAG_DATA:
case GLU_TESS_EDGE_FLAG_DATA:
callEdgeFlagData = callBegin = aCallback == null ? NULL_CB : aCallback;
/* If the client wants boundary edges to be flagged,
* we render everything as separate triangles (no strips or fans).
*/
flagBoundary = (aCallback != null);
return;
case GLU.GLU_TESS_VERTEX:
case GLU_TESS_VERTEX:
callVertex = aCallback == null ? NULL_CB : aCallback;
return;
case GLU.GLU_TESS_VERTEX_DATA:
case GLU_TESS_VERTEX_DATA:
callVertexData = aCallback == null ? NULL_CB : aCallback;
return;
case GLU.GLU_TESS_END:
case GLU_TESS_END:
callEnd = aCallback == null ? NULL_CB : aCallback;
return;
case GLU.GLU_TESS_END_DATA:
case GLU_TESS_END_DATA:
callEndData = aCallback == null ? NULL_CB : aCallback;
return;
case GLU.GLU_TESS_ERROR:
case GLU_TESS_ERROR:
callError = aCallback == null ? NULL_CB : aCallback;
return;
case GLU.GLU_TESS_ERROR_DATA:
case GLU_TESS_ERROR_DATA:
callErrorData = aCallback == null ? NULL_CB : aCallback;
return;
case GLU.GLU_TESS_COMBINE:
case GLU_TESS_COMBINE:
callCombine = aCallback == null ? NULL_CB : aCallback;
return;
case GLU.GLU_TESS_COMBINE_DATA:
case GLU_TESS_COMBINE_DATA:
callCombineData = aCallback == null ? NULL_CB : aCallback;
return;
// case GLU_TESS_MESH:
// callMesh = aCallback == null ? NULL_CB : aCallback;
// return;
default:
callErrorOrErrorData(GLU.GLU_INVALID_ENUM);
callErrorOrErrorData(GLU_INVALID_ENUM);
return;
}
}
@ -440,25 +441,25 @@ public class GLUtessellatorImpl implements GLUtessellator {
if (flushCacheOnNextVertex) {
if (!flushCache()) {
callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY);
callErrorOrErrorData(GLU_OUT_OF_MEMORY);
return;
}
lastEdge = null;
}
for (i = 0; i < 3; ++i) {
x = coords[i+coords_offset];
if (x < -GLU.GLU_TESS_MAX_COORD) {
x = -GLU.GLU_TESS_MAX_COORD;
if (x < -GLU_TESS_MAX_COORD) {
x = -GLU_TESS_MAX_COORD;
tooLarge = true;
}
if (x > GLU.GLU_TESS_MAX_COORD) {
x = GLU.GLU_TESS_MAX_COORD;
if (x > GLU_TESS_MAX_COORD) {
x = GLU_TESS_MAX_COORD;
tooLarge = true;
}
clamped[i] = x;
}
if (tooLarge) {
callErrorOrErrorData(GLU.GLU_TESS_COORD_TOO_LARGE);
callErrorOrErrorData(GLU_TESS_COORD_TOO_LARGE);
}
if (mesh == null) {
@ -467,13 +468,13 @@ public class GLUtessellatorImpl implements GLUtessellator {
return;
}
if (!flushCache()) {
callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY);
callErrorOrErrorData(GLU_OUT_OF_MEMORY);
return;
}
}
if (!addVertex(clamped, vertexData)) {
callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY);
callErrorOrErrorData(GLU_OUT_OF_MEMORY);
}
}
@ -597,7 +598,7 @@ public class GLUtessellatorImpl implements GLUtessellator {
mesh = null;
} catch (Exception e) {
e.printStackTrace();
callErrorOrErrorData(GLU.GLU_OUT_OF_MEMORY);
callErrorOrErrorData(GLU_OUT_OF_MEMORY);
}
}

View File

@ -90,7 +90,7 @@ class Normal {
private Normal() {
}
static boolean SLANTED_SWEEP = false;
static boolean SLANTED_SWEEP;
static double S_UNIT_X; /* Pre-normalized */
static double S_UNIT_Y;
private static final boolean TRUE_PROJECT = false;

View File

@ -96,7 +96,7 @@ abstract class PriorityQ {
int node;
}
public static interface Leq {
public interface Leq {
boolean leq(Object key1, Object key2);
}

View File

@ -95,7 +95,7 @@ class PriorityQHeap extends PriorityQ {
PriorityQ.Leq leq;
/* really __gl_pqHeapNewPriorityQ */
public PriorityQHeap(PriorityQ.Leq leq) {
PriorityQHeap(PriorityQ.Leq leq) {
size = 0;
max = PriorityQ.INIT_SIZE;
nodes = new PriorityQ.PQnode[PriorityQ.INIT_SIZE + 1];

View File

@ -93,7 +93,7 @@ class PriorityQSort extends PriorityQ {
boolean initialized;
PriorityQ.Leq leq;
public PriorityQSort(PriorityQ.Leq leq) {
PriorityQSort(PriorityQ.Leq leq) {
heap = new PriorityQHeap(leq);
keys = new Object[PriorityQ.INIT_SIZE];

View File

@ -84,8 +84,8 @@
*/
package org.lwjgl.util.glu.tessellation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
class Render {
private static final boolean USE_OPTIMIZED_CODE_PATH = false;
@ -102,10 +102,10 @@ class Render {
* primitive is able to use the most triangles.
*/
private static class FaceCount {
public FaceCount() {
private FaceCount() {
}
public FaceCount(long size, GLUhalfEdge eStart, renderCallBack render) {
private FaceCount(long size, GLUhalfEdge eStart, renderCallBack render) {
this.size = size;
this.eStart = eStart;
this.render = render;
@ -116,7 +116,7 @@ class Render {
renderCallBack render;
};
private static interface renderCallBack {
private interface renderCallBack {
void render(GLUtessellatorImpl tess, GLUhalfEdge e, long size);
}
@ -166,7 +166,7 @@ class Render {
*/
GLUhalfEdge e = fOrig.anEdge;
FaceCount max = new FaceCount();
FaceCount newFace = new FaceCount();
FaceCount newFace;
max.size = 1;
max.eStart = e;
@ -329,7 +329,7 @@ class Render {
int newState;
int edgeState = -1; /* force edge state output for first vertex */
tess.callBeginOrBeginData(GL11.GL_TRIANGLES);
tess.callBeginOrBeginData(GL_TRIANGLES);
for (; f != null; f = f.trail) {
/* Loop once for each edge (there will always be 3 edges) */
@ -360,7 +360,7 @@ class Render {
* edge "e". The fan *should* contain exactly "size" triangles
* (otherwise we've goofed up somewhere).
*/
tess.callBeginOrBeginData(GL11.GL_TRIANGLE_FAN);
tess.callBeginOrBeginData(GL_TRIANGLE_FAN);
tess.callVertexOrVertexData( e.Org.data);
tess.callVertexOrVertexData( e.Sym.Org.data);
@ -382,7 +382,7 @@ class Render {
* edge "e". The strip *should* contain exactly "size" triangles
* (otherwise we've goofed up somewhere).
*/
tess.callBeginOrBeginData(GL11.GL_TRIANGLE_STRIP);
tess.callBeginOrBeginData(GL_TRIANGLE_STRIP);
tess.callVertexOrVertexData( e.Org.data);
tess.callVertexOrVertexData( e.Sym.Org.data);
@ -416,7 +416,7 @@ class Render {
for (f = mesh.fHead.next; f != mesh.fHead; f = f.next) {
if (f.inside) {
tess.callBeginOrBeginData(GL11.GL_LINE_LOOP);
tess.callBeginOrBeginData(GL_LINE_LOOP);
e = f.anEdge;
do {
tess.callVertexOrVertexData( e.Org.data);
@ -555,22 +555,22 @@ class Render {
} else {
/* Make sure we do the right thing for each winding rule */
switch (tess.windingRule) {
case GLU.GLU_TESS_WINDING_ODD:
case GLU.GLU_TESS_WINDING_NONZERO:
case GLU_TESS_WINDING_ODD:
case GLU_TESS_WINDING_NONZERO:
break;
case GLU.GLU_TESS_WINDING_POSITIVE:
case GLU_TESS_WINDING_POSITIVE:
if (sign < 0) return true;
break;
case GLU.GLU_TESS_WINDING_NEGATIVE:
case GLU_TESS_WINDING_NEGATIVE:
if (sign > 0) return true;
break;
case GLU.GLU_TESS_WINDING_ABS_GEQ_TWO:
case GLU_TESS_WINDING_ABS_GEQ_TWO:
return true;
}
tess.callBeginOrBeginData( tess.boundaryOnly ? GL11.GL_LINE_LOOP
: (tess.cacheCount > 3) ? GL11.GL_TRIANGLE_FAN
: GL11.GL_TRIANGLES);
tess.callBeginOrBeginData( tess.boundaryOnly ? GL_LINE_LOOP
: (tess.cacheCount > 3) ? GL_TRIANGLE_FAN
: GL_TRIANGLES);
tess.callVertexOrVertexData( v[0].data);
if (sign > 0) {

View File

@ -84,7 +84,7 @@
*/
package org.lwjgl.util.glu.tessellation;
import org.lwjgl.util.glu.GLU;
import static org.lwjgl.util.glu.GLU.*;
class Sweep {
private Sweep() {
@ -270,15 +270,15 @@ class Sweep {
static boolean IsWindingInside(GLUtessellatorImpl tess, int n) {
switch (tess.windingRule) {
case GLU.GLU_TESS_WINDING_ODD:
case GLU_TESS_WINDING_ODD:
return (n & 1) != 0;
case GLU.GLU_TESS_WINDING_NONZERO:
case GLU_TESS_WINDING_NONZERO:
return (n != 0);
case GLU.GLU_TESS_WINDING_POSITIVE:
case GLU_TESS_WINDING_POSITIVE:
return (n > 0);
case GLU.GLU_TESS_WINDING_NEGATIVE:
case GLU_TESS_WINDING_NEGATIVE:
return (n < 0);
case GLU.GLU_TESS_WINDING_ABS_GEQ_TWO:
case GLU_TESS_WINDING_ABS_GEQ_TWO:
return (n >= 2) || (n <= -2);
}
/*LINTED*/
@ -457,7 +457,7 @@ class Sweep {
* but the user has not provided the callback necessary to handle
* generated intersection points.
*/
tess.callErrorOrErrorData(GLU.GLU_TESS_NEED_COMBINE_CALLBACK);
tess.callErrorOrErrorData(GLU_TESS_NEED_COMBINE_CALLBACK);
tess.fatalError = true;
}
}
@ -1143,7 +1143,7 @@ class Sweep {
* input contour and the maximum tolerance of 1.0, no merging will be
* done with coordinates larger than 3 * GLU_TESS_MAX_COORD).
*/
private static final double SENTINEL_COORD = (4.0 * GLU.GLU_TESS_MAX_COORD);
private static final double SENTINEL_COORD = (4.0 * GLU_TESS_MAX_COORD);
static void AddSentinel(GLUtessellatorImpl tess, double t)
/*

View File

@ -38,7 +38,7 @@ import net.java.games.input.Component;
* @author elias
*/
final class KeyMap {
public final static Component.Identifier.Key map(int lwjgl_key_code) {
public static Component.Identifier.Key map(int lwjgl_key_code) {
switch (lwjgl_key_code) {
case Keyboard.KEY_ESCAPE:
return Component.Identifier.Key.ESCAPE;

View File

@ -49,15 +49,14 @@ import java.lang.reflect.Modifier;
* @author elias
*/
final class LWJGLKeyboard extends Keyboard {
protected LWJGLKeyboard() {
LWJGLKeyboard() {
super("LWJGLKeyboard", createComponents(), new Controller[]{}, new Rumbler[]{});
}
private final static Component[] createComponents() {
List components = new ArrayList();
private static Component[] createComponents() {
List<Key> components = new ArrayList<Key>();
Field[] vkey_fields = org.lwjgl.input.Keyboard.class.getFields();
for (int i = 0; i < vkey_fields.length; i++) {
Field vkey_field = vkey_fields[i];
for ( Field vkey_field : vkey_fields ) {
try {
if (Modifier.isStatic(vkey_field.getModifiers()) && vkey_field.getType() == int.class &&
vkey_field.getName().startsWith("KEY_")) {
@ -70,21 +69,20 @@ final class LWJGLKeyboard extends Keyboard {
throw new RuntimeException(e);
}
}
return (Component[])components.toArray(new Component[]{});
return components.toArray(new Component[components.size()]);
}
public final synchronized void pollDevice() throws IOException {
public synchronized void pollDevice() throws IOException {
if (!org.lwjgl.input.Keyboard.isCreated())
return;
org.lwjgl.input.Keyboard.poll();
Component[] components = getComponents();
for (int i = 0; i < components.length; i++) {
Key key = (Key)components[i];
for ( Component component : getComponents() ) {
Key key = (Key)component;
key.update();
}
}
protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
protected synchronized boolean getNextDeviceEvent(Event event) throws IOException {
if (!org.lwjgl.input.Keyboard.isCreated())
return false;
if (!org.lwjgl.input.Keyboard.next())
@ -104,28 +102,28 @@ final class LWJGLKeyboard extends Keyboard {
}
private final static class Key extends AbstractComponent {
private static final class Key extends AbstractComponent {
private final int lwjgl_key;
private float value;
public Key(Component.Identifier.Key key_id, int lwjgl_key) {
Key(Component.Identifier.Key key_id, int lwjgl_key) {
super(key_id.getName(), key_id);
this.lwjgl_key = lwjgl_key;
}
public final void update() {
public void update() {
this.value = org.lwjgl.input.Keyboard.isKeyDown(lwjgl_key) ? 1 : 0;
}
protected final float poll() {
protected float poll() {
return value;
}
public final boolean isRelative() {
public boolean isRelative() {
return false;
}
public final boolean isAnalog() {
public boolean isAnalog() {
return false;
}
}

View File

@ -44,19 +44,19 @@ import net.java.games.input.Rumbler;
* @author elias
*/
final class LWJGLMouse extends Mouse {
private final static int EVENT_X = 1;
private final static int EVENT_Y = 2;
private final static int EVENT_WHEEL = 3;
private final static int EVENT_BUTTON = 4;
private final static int EVENT_DONE = 5;
private static final int EVENT_X = 1;
private static final int EVENT_Y = 2;
private static final int EVENT_WHEEL = 3;
private static final int EVENT_BUTTON = 4;
private static final int EVENT_DONE = 5;
private int event_state = EVENT_DONE;
protected LWJGLMouse() {
LWJGLMouse() {
super("LWJGLMouse", createComponents(), new Controller[]{}, new Rumbler[]{});
}
private final static Component[] createComponents() {
private static Component[] createComponents() {
return new Component[]{new Axis(Component.Identifier.Axis.X),
new Axis(Component.Identifier.Axis.Y),
new Axis(Component.Identifier.Axis.Z),
@ -65,7 +65,7 @@ final class LWJGLMouse extends Mouse {
new Button(Component.Identifier.Button.RIGHT)};
}
public final synchronized void pollDevice() throws IOException {
public synchronized void pollDevice() throws IOException {
if (!org.lwjgl.input.Mouse.isCreated())
return;
org.lwjgl.input.Mouse.poll();
@ -73,7 +73,7 @@ final class LWJGLMouse extends Mouse {
setButtonState(i);
}
private final Button map(int lwjgl_button) {
private Button map(int lwjgl_button) {
switch (lwjgl_button) {
case 0:
return (Button)getLeft();
@ -86,13 +86,13 @@ final class LWJGLMouse extends Mouse {
}
}
private final void setButtonState(int lwjgl_button) {
private void setButtonState(int lwjgl_button) {
Button button = map(lwjgl_button);
if (button != null)
button.setValue(org.lwjgl.input.Mouse.isButtonDown(lwjgl_button) ? 1 : 0);
}
protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
protected synchronized boolean getNextDeviceEvent(Event event) throws IOException {
if (!org.lwjgl.input.Mouse.isCreated())
return false;
while (true) {
@ -147,44 +147,44 @@ final class LWJGLMouse extends Mouse {
}
}
final static class Axis extends AbstractComponent {
public Axis(Component.Identifier.Axis axis_id) {
static final class Axis extends AbstractComponent {
Axis(Component.Identifier.Axis axis_id) {
super(axis_id.getName(), axis_id);
}
public final boolean isRelative() {
public boolean isRelative() {
return true;
}
protected final float poll() throws IOException {
protected float poll() throws IOException {
return 0;
}
public final boolean isAnalog() {
public boolean isAnalog() {
return true;
}
}
final static class Button extends AbstractComponent {
static final class Button extends AbstractComponent {
private float value;
public Button(Component.Identifier.Button button_id) {
Button(Component.Identifier.Button button_id) {
super(button_id.getName(), button_id);
}
protected final void setValue(float value) {
void setValue(float value) {
this.value = value;
}
protected final float poll() throws IOException {
protected float poll() throws IOException {
return value;
}
public final boolean isRelative() {
public boolean isRelative() {
return false;
}
public final boolean isAnalog() {
public boolean isAnalog() {
return false;
}
}

View File

@ -48,7 +48,7 @@ public abstract class Matrix implements Serializable {
/**
* Constructor for Matrix.
*/
public Matrix() {
protected Matrix() {
super();
}

View File

@ -313,7 +313,7 @@ public class Matrix2f extends Matrix implements Serializable {
* Returns a string representation of this matrix
*/
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(m00).append(' ').append(m10).append(' ').append('\n');
buf.append(m01).append(' ').append(m11).append(' ').append('\n');
return buf.toString();

View File

@ -354,7 +354,7 @@ public class Matrix3f extends Matrix implements Serializable {
* Returns a string representation of this matrix
*/
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(m00).append(' ').append(m10).append(' ').append(m20).append(' ').append('\n');
buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append('\n');
buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append('\n');

View File

@ -56,7 +56,7 @@ public class Matrix4f extends Matrix implements Serializable {
* Returns a string representation of this matrix
*/
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append(m00).append(' ').append(m10).append(' ').append(m20).append(' ').append(m30).append('\n');
buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append(m31).append('\n');
buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append(m32).append('\n');

View File

@ -454,7 +454,7 @@ public class Quaternion extends Vector implements ReadableVector4f {
* The destination quaternion, or null if a new quaternion is to be created
* @return q
*/
public final static Quaternion setFromMatrix(Matrix4f m, Quaternion q) {
public static Quaternion setFromMatrix(Matrix4f m, Quaternion q) {
return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20,
m.m21, m.m22);
}
@ -480,7 +480,7 @@ public class Quaternion extends Vector implements ReadableVector4f {
* The destination quaternion, or null if a new quaternion is to be created
* @return q
*/
public static final Quaternion setFromMatrix(Matrix3f m, Quaternion q) {
public static Quaternion setFromMatrix(Matrix3f m, Quaternion q) {
return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20,
m.m21, m.m22);
}

View File

@ -40,15 +40,15 @@ public interface ReadableVector {
/**
* @return the length of the vector
*/
public float length();
float length();
/**
* @return the length squared of the vector
*/
public float lengthSquared();
float lengthSquared();
/**
* Store this vector in a FloatBuffer
* @param buf The buffer to store it in, at the current position
* @return this
*/
public Vector store(FloatBuffer buf);
Vector store(FloatBuffer buf);
}

View File

@ -38,9 +38,9 @@ public interface ReadableVector2f extends ReadableVector {
/**
* @return x
*/
public float getX();
float getX();
/**
* @return y
*/
public float getY();
float getY();
}

View File

@ -38,5 +38,5 @@ public interface ReadableVector3f extends ReadableVector2f {
/**
* @return z
*/
public float getZ();
float getZ();
}

View File

@ -39,6 +39,6 @@ public interface ReadableVector4f extends ReadableVector3f {
/**
* @return w
*/
public float getW();
float getW();
}

View File

@ -47,7 +47,7 @@ public abstract class Vector implements Serializable, ReadableVector {
/**
* Constructor for Vector.
*/
public Vector() {
protected Vector() {
super();
}

View File

@ -247,7 +247,7 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer sb = new StringBuffer(64);
StringBuilder sb = new StringBuilder(64);
sb.append("Vector2f[");
sb.append(x);

View File

@ -288,7 +288,7 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer sb = new StringBuffer(64);
StringBuilder sb = new StringBuilder(64);
sb.append("Vector3f[");
sb.append(x);

View File

@ -43,19 +43,19 @@ public interface WritableVector2f {
* Set the X value
* @param x
*/
public void setX(float x);
void setX(float x);
/**
* Set the Y value
* @param y
*/
public void setY(float y);
void setY(float y);
/**
* Set the X,Y values
* @param x
* @param y
*/
public void set(float x, float y);
void set(float x, float y);
}

View File

@ -43,7 +43,7 @@ public interface WritableVector3f extends WritableVector2f {
* Set the Z value
* @param z
*/
public void setZ(float z);
void setZ(float z);
/**
* Set the X,Y,Z values
@ -51,6 +51,6 @@ public interface WritableVector3f extends WritableVector2f {
* @param y
* @param z
*/
public void set(float x, float y, float z);
void set(float x, float y, float z);
}

View File

@ -43,7 +43,7 @@ public interface WritableVector4f extends WritableVector3f {
* Set the W value
* @param w
*/
public void setW(float w);
void setW(float w);
/**
* Set the X,Y,Z,W values
@ -52,6 +52,6 @@ public interface WritableVector4f extends WritableVector3f {
* @param z
* @param w
*/
public void set(float x, float y, float z, float w);
void set(float x, float y, float z, float w);
}

View File

@ -70,5 +70,3 @@ typedef cl_bitfield cl_mem_migration_flags_ext;
// -----------------[ Convenience typedefs ]-----------------
typedef void cl_void;
//typedef char cl_char;
//typedef unsigned char cl_uchar;

View File

@ -34,6 +34,14 @@
#include "org_lwjgl_opencl_CL.h"
#include "extcl.h"
JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_nCreate(JNIEnv *env, jclass clazz, jstring oclPath) {
extcl_LoadLibrary(env, oclPath);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_nDestroy(JNIEnv *env, jclass clazz) {
extcl_UnloadLibrary();
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CL_getFunctionAddress(JNIEnv *env, jclass clazz, jstring function_name) {
jlong address_jlong;
char *function_name_pointer = GetStringNativeChars(env, function_name);
@ -43,12 +51,8 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CL_getFunctionAddress(JNIEnv *env,
return address_jlong;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_nCreate(JNIEnv *env, jclass clazz, jstring oclPath) {
extcl_LoadLibrary(env, oclPath);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_nDestroy(JNIEnv *env, jclass clazz) {
extcl_UnloadLibrary();
JNIEXPORT jobject JNICALL Java_org_lwjgl_opencl_CL_getHostBuffer(JNIEnv *env, jclass clazz, jlong address, jint size) {
return safeNewBuffer(env, (void *)(intptr_t)address, size);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_resetNativeStubs(JNIEnv *env, jclass clazz, jclass cl_class) {

View File

@ -40,6 +40,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_nDestroy
JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CL_getFunctionAddress
(JNIEnv *, jclass, jstring);
/*
* Class: org_lwjgl_opencl_CL
* Method: getHostBuffer
* Signature: (JI)Ljava/nio/ByteBuffer;
*/
JNIEXPORT jobject JNICALL Java_org_lwjgl_opencl_CL_getHostBuffer
(JNIEnv *, jclass, jlong, jint);
/*
* Class: org_lwjgl_opencl_CL
* Method: resetNativeStubs

View File

@ -0,0 +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
* 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.util.generator.opencl.CLPlatformExtension;
@CLPlatformExtension
public interface AMD_event_callback {
// Not implemented
}

View File

@ -358,6 +358,10 @@ public interface CL10 {
/* Platform API */
@Code(
javaBeforeNative = "\t\tif ( num_platforms == null ) num_platforms = APIUtil.getBufferInt();",
javaAfterNative = "\t\tif ( __result == CL_SUCCESS && platforms != null ) CLPlatform.registerCLPlatforms(platforms, num_platforms);"
)
@cl_int
int clGetPlatformIDs(@AutoSize(value = "platforms", canBeNull = true) @cl_uint int num_entries,
@OutParameter @Check(canBeNull = true) @NativeType("cl_platform_id") PointerBuffer platforms,
@ -370,8 +374,13 @@ public interface CL10 {
@OutParameter @Check(canBeNull = true) @cl_void ByteBuffer param_value,
@OutParameter @Check(value = "1", canBeNull = true) @NativeType("size_t") PointerBuffer param_value_size_ret);
@Code(
javaBeforeNative = "\t\telse\n" +
"\t\t\tnum_devices = APIUtil.getBufferInt();",
javaAfterNative = "\t\tif ( __result == CL_SUCCESS && devices != null ) platform.registerCLDevices(devices, num_devices);"
)
@cl_int
int clGetDeviceIDs(@PointerWrapper(value = "cl_platform_id", canBeNull = true) CLPlatform platform,
int clGetDeviceIDs(@PointerWrapper("cl_platform_id") CLPlatform platform,
@NativeType("cl_device_type") long device_type,
@AutoSize(value = "devices", canBeNull = true) @cl_uint int num_entries,
@OutParameter @Check(canBeNull = true) @NativeType("cl_device_id") PointerBuffer devices,
@ -384,6 +393,7 @@ public interface CL10 {
@OutParameter @Check(canBeNull = true) @cl_void ByteBuffer param_value,
@OutParameter @Check(value = "1", canBeNull = true) @NativeType("size_t") PointerBuffer param_value_size_ret);
/** LWJGL requires CL_CONTEXT_PLATFORM to be present in the cl_context_properties buffer. */
@Code(
tryBlock = true,
// Create a GlobalRef to the callback object.
@ -392,14 +402,15 @@ public interface CL10 {
javaFinally = "\t\t\tCallbackUtil.registerCallback(__result, user_data);"
)
@Check(value = "errcode_ret", canBeNull = true)
@PointerWrapper("cl_context")
CLContext clCreateContext(@NullTerminated @Check(canBeNull = true) @Const @NativeType("cl_context_properties") PointerBuffer properties,
@PointerWrapper(value = "cl_context", params = "APIUtil.getCLPlatform(properties)")
CLContext clCreateContext(@NullTerminated @Check("3") @Const @NativeType("cl_context_properties") PointerBuffer properties,
@AutoSize("devices") @cl_uint int num_devices,
@Check("1") @Const @NativeType("cl_device_id") PointerBuffer devices,
@PointerWrapper(value = "cl_create_context_callback", canBeNull = true) CLContextCallback pfn_notify,
@Constant("user_data") @PointerWrapper("void *") long user_data,
@OutParameter @Check(value = "1", canBeNull = true) @cl_int IntBuffer errcode_ret);
/** LWJGL requires CL_CONTEXT_PLATFORM to be present in the cl_context_properties buffer. */
@Alternate("clCreateContext")
@Code(
tryBlock = true,
@ -409,14 +420,15 @@ public interface CL10 {
javaFinally = "\t\t\tCallbackUtil.registerCallback(__result, user_data);"
)
@Check(value = "errcode_ret", canBeNull = true)
@PointerWrapper("cl_context")
CLContext clCreateContext(@NullTerminated @Check(canBeNull = true) @Const @NativeType("cl_context_properties") PointerBuffer properties,
@PointerWrapper(value = "cl_context", params = "APIUtil.getCLPlatform(properties)")
CLContext clCreateContext(@NullTerminated @Check("3") @Const @NativeType("cl_context_properties") PointerBuffer properties,
@Constant("1") @cl_uint int num_devices,
@Constant(value = "APIUtil.getBufferPointer().put(0, device).getBuffer(), 0", keepParam = true) CLDevice device,
@PointerWrapper(value = "cl_create_context_callback", canBeNull = true) CLContextCallback pfn_notify,
@Constant("user_data") @PointerWrapper("void *") long user_data,
@OutParameter @Check(value = "1", canBeNull = true) @cl_int IntBuffer errcode_ret);
/** LWJGL requires CL_CONTEXT_PLATFORM to be present in the cl_context_properties buffer. */
@Code(
tryBlock = true,
// Create a GlobalRef to the callback object.
@ -425,8 +437,8 @@ public interface CL10 {
javaFinally = "\t\t\tCallbackUtil.registerCallback(__result, user_data);"
)
@Check(value = "errcode_ret", canBeNull = true)
@PointerWrapper("cl_context")
CLContext clCreateContextFromType(@NullTerminated @Check(canBeNull = true) @Const @NativeType("cl_context_properties") PointerBuffer properties,
@PointerWrapper(value = "cl_context", params = "APIUtil.getCLPlatform(properties)")
CLContext clCreateContextFromType(@NullTerminated @Check("3") @Const @NativeType("cl_context_properties") PointerBuffer properties,
@NativeType("cl_device_type") long device_type,
@PointerWrapper(value = "cl_create_context_callback", canBeNull = true) CLContextCallback pfn_notify,
@Constant("user_data") @PointerWrapper("void *") long user_data,
@ -443,6 +455,10 @@ public interface CL10 {
@cl_int
int clReleaseContext(@PointerWrapper("cl_context") CLContext context);
@Code(
javaBeforeNative = "\t\tif ( param_name == CL_CONTEXT_DEVICES && param_value_size_ret == null ) param_value_size_ret = APIUtil.getBufferPointer();",
javaAfterNative = "\t\tif ( param_name == CL_CONTEXT_DEVICES && __result == CL_SUCCESS && param_value != null ) context.getParent().registerCLDevices(param_value, param_value_size_ret);"
)
@cl_int
int clGetContextInfo(@PointerWrapper("cl_context") CLContext context,
@NativeType("cl_context_info") int param_name,
@ -883,6 +899,47 @@ public interface CL10 {
@OutParameter @Check(canBeNull = true) @cl_void ByteBuffer param_value,
@OutParameter @Check(value = "1", canBeNull = true) @NativeType("size_t") PointerBuffer param_value_size_ret);
/**
* This method can be used to get program binaries. The binary for each device (in the
* order returned by <code>CL_PROGRAM_DEVICES</code>) will be written sequentially to
* the <code>param_value</code> buffer. The buffer size must be big enough to hold
* all the binaries, as returned by <code>CL_PROGRAM_BINARY_SIZES</code>.
*
* @param program the program
* @param param_value the buffers where the binaries will be written to.
* @param param_value_size_ret optional size result
*
* @return the error code
*/
@Alternate(value = "clGetProgramInfo", nativeAlt = true)
@cl_int
int clGetProgramInfo2(@PointerWrapper("cl_program") CLProgram program,
@Constant("CL_PROGRAM_BINARIES") @NativeType("cl_program_info") int param_name,
@Constant("sizes.remaining() * PointerBuffer.getPointerSize()") @size_t long param_value_size,
@Helper(passToNative = true) @Check("1") @Const @NativeType("size_t") PointerBuffer sizes,
@OutParameter @Check("APIUtil.getSize(sizes)") @PointerArray(value = "param_value_size", lengths = "sizes") @NativeType("cl_uchar") ByteBuffer param_value,
@OutParameter @Check(value = "1", canBeNull = true) @NativeType("size_t") PointerBuffer param_value_size_ret);
/**
* This method can be used to get program binaries. The binary for each device (in the
* order returned by <code>CL_PROGRAM_DEVICES</code>) will be written to the corresponding
* slot of the <code>param_value</code> array. The size of each buffer must be big enough to
* hold the corresponding binary, as returned by <code>CL_PROGRAM_BINARY_SIZES</code>.
*
* @param program the program
* @param param_value the buffers where the binaries will be written to.
* @param param_value_size_ret optional size result
*
* @return the error code
*/
@Alternate(value = "clGetProgramInfo", nativeAlt = true)
@cl_int
int clGetProgramInfo3(@PointerWrapper("cl_program") CLProgram program,
@Constant("CL_PROGRAM_BINARIES") @NativeType("cl_program_info") int param_name,
@Constant("param_value.length * PointerBuffer.getPointerSize()") @size_t long param_value_size,
@PointerArray("param_value_size") @NativeType("cl_uchar") ByteBuffer[] param_value,
@OutParameter @Check(value = "1", canBeNull = true) @NativeType("size_t") PointerBuffer param_value_size_ret);
@cl_int
int clGetProgramBuildInfo(@PointerWrapper("cl_program") CLProgram program,
@PointerWrapper("cl_device_id") CLDevice device,
@ -950,7 +1007,7 @@ public interface CL10 {
@cl_int
int clGetKernelWorkGroupInfo(@PointerWrapper("cl_kernel") CLKernel kernel,
@PointerWrapper(value = "cl_device_id", canBeNull = true) CLKernel device,
@PointerWrapper(value = "cl_device_id", canBeNull = true) CLDevice device,
@NativeType("cl_kernel_work_group_info") int param_name,
@AutoSize(value = "param_value", canBeNull = true) @size_t long param_value_size,
@OutParameter @Check(canBeNull = true) @cl_void ByteBuffer param_value,
@ -1023,7 +1080,13 @@ public interface CL10 {
@OutParameter @Check(value = "1", canBeNull = true) @NativeType("cl_event") PointerBuffer event);
@cl_int
int clWaitForEvents(@AutoSize("event_list") @cl_uint int num_events, @Check("1") @Const @NativeType("cl_event") PointerBuffer event_list);
int clWaitForEvents(@AutoSize("event_list") @cl_uint int num_events,
@Check("1") @Const @NativeType("cl_event") PointerBuffer event_list);
@Alternate("clWaitForEvents")
@cl_int
int clWaitForEvents(@Constant("1") @cl_uint int num_events,
@Constant(value = "APIUtil.getBufferPointer().put(0, event).getBuffer(), 0", keepParam = true) CLEvent event);
@cl_int
int clGetEventInfo(@PointerWrapper("cl_event") CLEvent event,

View File

@ -0,0 +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
* 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.util.generator.opencl.CLPlatformExtension;
@CLPlatformExtension
public interface KHR_d3d10_sharing {
// Not implemented
}

View File

@ -49,6 +49,7 @@ public interface KHR_icd {
/** Returned by clGetPlatformIDs when no platforms are found */
int CL_PLATFORM_NOT_FOUND_KHR = -1001;
@Optional(reason = "AMD Stream does not expose this (version tested: 2.2)")
@cl_int
int clIcdGetPlatformIDsKHR(@AutoSize(value = "platforms", canBeNull = true) @cl_uint int num_entries,
@OutParameter @Check(canBeNull = true) @NativeType("cl_platform_id") PointerBuffer platforms,

View File

@ -91,13 +91,13 @@ public interface ARB_sync {
void glWaitSync(@PointerWrapper("GLsync") GLSync sync, @GLbitfield int flags, @GLuint64 long timeout);
@Reuse("GL32")
@StripPostfix(value = "params", postfix = "64")
@StripPostfix("params")
void glGetInteger64v(@GLenum int pname, @OutParameter @Check("1") @GLint64 LongBuffer params);
@Reuse("GL32")
@Alternate("glGetInteger64v")
@GLreturn("params")
@StripPostfix(value = "params", postfix = "64")
@StripPostfix("params")
void glGetInteger64v2(@GLenum int pname, @OutParameter @GLint64 LongBuffer params);
@Reuse("GL32")

View File

@ -309,21 +309,21 @@ public interface GL32 {
void glWaitSync(@PointerWrapper("GLsync") GLSync sync, @GLbitfield int flags, @GLuint64 long timeout);
@StripPostfix(value = "data", postfix = "64")
@StripPostfix("data")
void glGetInteger64v(@GLenum int pname, @OutParameter @Check("1") @GLint64 LongBuffer data);
@Alternate("glGetInteger64v")
@GLreturn("data")
@StripPostfix(value = "data", postfix = "64")
@StripPostfix("data")
void glGetInteger64v2(@GLenum int pname, @OutParameter @GLint64 LongBuffer data);
@StripPostfix(value = "data", postfix = "64")
@StripPostfix("data")
@Optional(reason = "NV's 3.2 implementation does not expose this (last driver checked: 19?.??)")
void glGetInteger64i_v(@GLenum int value, @GLuint int index, @OutParameter @Check("4") @GLint64 LongBuffer data);
@Alternate("glGetInteger64i_v")
@GLreturn("data")
@StripPostfix(value = "data", postfix = "64")
@StripPostfix("data")
void glGetInteger64i_v2(@GLenum int value, @GLuint int index, @OutParameter @GLint64 LongBuffer data);
@StripPostfix("values")