From a8bcb7fd25c6fe6028d08babbbf64c58c336c264 Mon Sep 17 00:00:00 2001 From: Ioannis Tsakpinis Date: Tue, 28 Sep 2010 21:11:35 +0000 Subject: [PATCH] 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) --- build.xml | 117 +-- platform_build/build-generator.xml | 9 +- src/java/org/lwjgl/BufferChecks.java | 2 +- src/java/org/lwjgl/LWJGLUtil.java | 46 +- .../org/lwjgl/LinuxSysImplementation.java | 5 +- .../org/lwjgl/MacOSXSysImplementation.java | 2 +- .../org/lwjgl/NondirectBufferWrapper.java | 10 +- src/java/org/lwjgl/PointerBuffer.java | 21 +- .../org/lwjgl/PointerWrapperAbstract.java | 29 +- src/java/org/lwjgl/Sys.java | 22 +- .../org/lwjgl/WindowsSysImplementation.java | 22 +- src/java/org/lwjgl/examples/Game.java | 103 +-- .../lwjgl/examples/spaceinvaders/Entity.java | 54 +- .../lwjgl/examples/spaceinvaders/Game.java | 151 ++-- .../examples/spaceinvaders/GameApplet.java | 34 +- .../examples/spaceinvaders/ShotEntity.java | 38 +- .../examples/spaceinvaders/SoundManager.java | 76 +- .../lwjgl/examples/spaceinvaders/Sprite.java | 66 +- .../lwjgl/examples/spaceinvaders/Texture.java | 44 +- .../examples/spaceinvaders/TextureLoader.java | 217 +++--- src/java/org/lwjgl/input/Controller.java | 242 +++--- src/java/org/lwjgl/input/ControllerEvent.java | 68 +- src/java/org/lwjgl/input/Controllers.java | 146 ++-- src/java/org/lwjgl/input/Cursor.java | 78 +- .../org/lwjgl/input/JInputController.java | 158 ++-- src/java/org/lwjgl/input/Keyboard.java | 34 +- src/java/org/lwjgl/input/Mouse.java | 28 +- .../org/lwjgl/input/OpenGLPackageAccess.java | 38 +- src/java/org/lwjgl/openal/AL.java | 78 +- src/java/org/lwjgl/openal/ALC10.java | 124 +-- src/java/org/lwjgl/openal/ALC11.java | 72 +- src/java/org/lwjgl/openal/ALCcontext.java | 48 +- src/java/org/lwjgl/openal/ALCdevice.java | 70 +- src/java/org/lwjgl/openal/EFXUtil.java | 99 +-- src/java/org/lwjgl/opencl/APIUtil.java | 315 ++++---- .../lwjgl/opencl/APPLEContextLoggingUtil.java | 2 +- src/java/org/lwjgl/opencl/CL.java | 16 +- .../lwjgl/opencl/CLBuildProgramCallback.java | 2 - src/java/org/lwjgl/opencl/CLChecks.java | 63 +- src/java/org/lwjgl/opencl/CLCommandQueue.java | 15 + src/java/org/lwjgl/opencl/CLContext.java | 45 +- src/java/org/lwjgl/opencl/CLDevice.java | 179 +++-- src/java/org/lwjgl/opencl/CLDeviceImpl.java | 104 --- src/java/org/lwjgl/opencl/CLEvent.java | 38 + src/java/org/lwjgl/opencl/CLKernel.java | 244 ++++-- src/java/org/lwjgl/opencl/CLMem.java | 145 ++++ src/java/org/lwjgl/opencl/CLObject.java | 43 +- src/java/org/lwjgl/opencl/CLObjectChild.java | 4 +- .../org/lwjgl/opencl/CLObjectRegistry.java | 10 +- ...ernelImpl.java => CLObjectRetainable.java} | 49 +- src/java/org/lwjgl/opencl/CLPlatform.java | 205 ++++- src/java/org/lwjgl/opencl/CLPlatformImpl.java | 121 --- src/java/org/lwjgl/opencl/CLProgram.java | 117 ++- src/java/org/lwjgl/opencl/CLSampler.java | 29 + src/java/org/lwjgl/opencl/InfoUtil.java | 51 ++ .../org/lwjgl/opencl/InfoUtilAbstract.java | 134 ++++ .../org/lwjgl/opencl/InfoUtilFactory.java | 450 +++++++++++ src/java/org/lwjgl/opencl/Util.java | 2 +- .../lwjgl/opengl/AMDDebugOutputCallback.java | 24 +- src/java/org/lwjgl/opengl/APIUtil.java | 56 +- .../lwjgl/opengl/ARBDebugOutputCallback.java | 24 +- src/java/org/lwjgl/opengl/AWTGLCanvas.java | 2 +- src/java/org/lwjgl/opengl/AWTSurfaceLock.java | 12 +- src/java/org/lwjgl/opengl/AWTUtil.java | 9 +- src/java/org/lwjgl/opengl/BaseReferences.java | 18 +- src/java/org/lwjgl/opengl/CallbackUtil.java | 20 +- src/java/org/lwjgl/opengl/Context.java | 12 +- src/java/org/lwjgl/opengl/ContextAttribs.java | 2 +- src/java/org/lwjgl/opengl/Display.java | 25 +- src/java/org/lwjgl/opengl/DisplayMode.java | 2 +- src/java/org/lwjgl/opengl/GLChecks.java | 47 +- src/java/org/lwjgl/opengl/GLContext.java | 55 +- src/java/org/lwjgl/opengl/GLUConstants.java | 6 +- src/java/org/lwjgl/opengl/GlobalLock.java | 28 +- .../opengl/LinuxCanvasImplementation.java | 28 +- src/java/org/lwjgl/opengl/LinuxDisplay.java | 100 ++- src/java/org/lwjgl/opengl/LinuxEvent.java | 22 +- src/java/org/lwjgl/opengl/LinuxKeycodes.java | 732 +++++++++--------- src/java/org/lwjgl/opengl/LinuxMouse.java | 14 +- src/java/org/lwjgl/opengl/MacOSXDisplay.java | 51 +- .../lwjgl/opengl/MacOSXDisplayPeerInfo.java | 2 +- src/java/org/lwjgl/opengl/MacOSXFrame.java | 6 +- src/java/org/lwjgl/opengl/PeerInfo.java | 4 +- .../org/lwjgl/opengl/ReferencesStack.java | 4 +- src/java/org/lwjgl/opengl/RenderTexture.java | 8 +- src/java/org/lwjgl/opengl/StateTracker.java | 14 +- src/java/org/lwjgl/opengl/Util.java | 29 +- .../opengl/WindowsAWTGLCanvasPeerInfo.java | 2 +- .../opengl/WindowsCanvasImplementation.java | 2 +- src/java/org/lwjgl/opengl/WindowsDisplay.java | 172 ++-- .../org/lwjgl/opengl/WindowsKeyboard.java | 4 +- .../org/lwjgl/opengl/WindowsKeycodes.java | 394 +++++----- .../org/lwjgl/opengl/WindowsRegistry.java | 12 +- src/java/org/lwjgl/opengl/XRandR.java | 64 +- src/java/org/lwjgl/test/DisplayTest.java | 122 +-- .../org/lwjgl/test/WindowCreationTest.java | 86 +- .../lwjgl/test/applet/AppletLoaderTest.java | 32 +- .../org/lwjgl/test/applet/GearsApplet.java | 297 +++---- src/java/org/lwjgl/test/applet/OpenAL.java | 105 +-- src/java/org/lwjgl/test/applet/OpenGL.java | 61 +- src/java/org/lwjgl/test/applet/Speed.java | 67 +- src/java/org/lwjgl/test/applet/Test.java | 30 +- .../test/glu/tessellation/TessCallback.java | 15 +- .../glu/tessellation/TessellationTest.java | 93 +-- .../org/lwjgl/test/input/HWCursorTest.java | 201 ++--- .../org/lwjgl/test/input/KeyboardTest.java | 71 +- .../lwjgl/test/input/MouseCreationTest.java | 109 +-- src/java/org/lwjgl/test/input/MouseTest.java | 225 +++--- .../org/lwjgl/test/input/TestControllers.java | 62 +- src/java/org/lwjgl/test/openal/BasicTest.java | 48 +- .../org/lwjgl/test/openal/OpenALInfo.java | 149 ++-- .../org/lwjgl/test/openal/PositionTest.java | 237 +++--- .../org/lwjgl/test/opencl/HelloOpenCL.java | 1 + .../org/lwjgl/test/opencl/gl/DemoFractal.java | 112 ++- .../test/opengl/FullScreenWindowedTest.java | 81 +- src/java/org/lwjgl/test/opengl/Gears.java | 215 ++--- .../org/lwjgl/test/opengl/PbufferTest.java | 136 ++-- src/java/org/lwjgl/test/opengl/SyncTest.java | 30 +- .../org/lwjgl/test/opengl/VBOIndexTest.java | 69 +- src/java/org/lwjgl/test/opengl/VBOTest.java | 55 +- .../org/lwjgl/test/opengl/VersionTest.java | 16 +- .../org/lwjgl/test/opengl/awt/AWTGears.java | 171 ++-- .../lwjgl/test/opengl/awt/AWTGearsCanvas.java | 233 +++--- .../org/lwjgl/test/opengl/awt/AWTTest.java | 63 +- .../org/lwjgl/test/opengl/awt/DemoBox.java | 285 +++---- .../test/opengl/awt/DisplayParentTest.java | 35 +- .../multithread/BackgroundLoadTest.java | 81 +- .../opengl/multithread/BackgroundLoader.java | 25 +- .../test/opengl/pbuffers/PbufferTest.java | 104 ++- .../test/opengl/pbuffers/UniqueRenderer.java | 7 +- .../opengl/pbuffers/UniqueRendererRTT.java | 5 +- .../org/lwjgl/test/opengl/shaders/Shader.java | 34 +- .../lwjgl/test/opengl/shaders/ShaderFP.java | 43 +- .../lwjgl/test/opengl/shaders/ShaderFSH.java | 54 +- .../lwjgl/test/opengl/shaders/ShaderUNI.java | 59 +- .../lwjgl/test/opengl/shaders/ShaderVP.java | 23 +- .../lwjgl/test/opengl/shaders/ShaderVSH.java | 34 +- .../test/opengl/shaders/ShadersTest.java | 71 +- src/java/org/lwjgl/util/Display.java | 139 ++-- src/java/org/lwjgl/util/ReadableColor.java | 108 +-- .../org/lwjgl/util/ReadableDimension.java | 36 +- src/java/org/lwjgl/util/ReadablePoint.java | 36 +- .../org/lwjgl/util/ReadableRectangle.java | 30 +- src/java/org/lwjgl/util/Renderable.java | 36 +- src/java/org/lwjgl/util/Timer.java | 60 +- src/java/org/lwjgl/util/WritableColor.java | 64 +- .../org/lwjgl/util/WritableDimension.java | 34 +- src/java/org/lwjgl/util/WritablePoint.java | 34 +- .../org/lwjgl/util/WritableRectangle.java | 38 +- src/java/org/lwjgl/util/XPMFile.java | 72 +- .../org/lwjgl/util/applet/AppletLoader.java | 585 +++++++------- .../util/generator/GeneratorVisitor.java | 4 +- src/java/org/lwjgl/util/generator/Helper.java | 2 +- .../util/generator/JavaMethodsGenerator.java | 4 +- .../generator/NativeMethodStubsGenerator.java | 2 +- .../generator/RegisterStubsGenerator.java | 4 +- src/java/org/lwjgl/util/generator/Utils.java | 17 +- .../opencl/CLCapabilitiesGenerator.java | 45 +- .../opencl/CLGeneratorProcessorFactory.java | 8 +- .../opencl/CLPDCapabilitiesGenerator.java | 9 +- .../opengl/GLCapabilitiesGenerator.java | 10 +- .../opengl/GLGeneratorProcessorFactory.java | 2 +- ...GLReferencesGeneratorProcessorFactory.java | 4 +- src/java/org/lwjgl/util/glu/Cylinder.java | 89 +-- src/java/org/lwjgl/util/glu/Disk.java | 107 +-- src/java/org/lwjgl/util/glu/GLU.java | 13 +- .../org/lwjgl/util/glu/GLUtessellator.java | 26 +- .../util/glu/GLUtessellatorCallback.java | 30 +- src/java/org/lwjgl/util/glu/MipMap.java | 76 +- src/java/org/lwjgl/util/glu/PartialDisk.java | 153 ++-- .../org/lwjgl/util/glu/PixelStoreState.java | 60 +- src/java/org/lwjgl/util/glu/Project.java | 52 +- src/java/org/lwjgl/util/glu/Quadric.java | 63 +- src/java/org/lwjgl/util/glu/Registry.java | 30 +- src/java/org/lwjgl/util/glu/Sphere.java | 116 +-- src/java/org/lwjgl/util/glu/Util.java | 101 +-- .../util/glu/tessellation/GLUhalfEdge.java | 2 +- .../glu/tessellation/GLUtessellatorImpl.java | 97 +-- .../lwjgl/util/glu/tessellation/Normal.java | 2 +- .../util/glu/tessellation/PriorityQ.java | 2 +- .../util/glu/tessellation/PriorityQHeap.java | 2 +- .../util/glu/tessellation/PriorityQSort.java | 2 +- .../lwjgl/util/glu/tessellation/Render.java | 36 +- .../lwjgl/util/glu/tessellation/Sweep.java | 16 +- src/java/org/lwjgl/util/jinput/KeyMap.java | 28 +- .../org/lwjgl/util/jinput/LWJGLKeyboard.java | 62 +- .../org/lwjgl/util/jinput/LWJGLMouse.java | 74 +- src/java/org/lwjgl/util/vector/Matrix.java | 50 +- src/java/org/lwjgl/util/vector/Matrix2f.java | 134 ++-- src/java/org/lwjgl/util/vector/Matrix3f.java | 92 +-- src/java/org/lwjgl/util/vector/Matrix4f.java | 166 ++-- .../org/lwjgl/util/vector/Quaternion.java | 90 +-- .../org/lwjgl/util/vector/ReadableVector.java | 32 +- .../lwjgl/util/vector/ReadableVector2f.java | 30 +- .../lwjgl/util/vector/ReadableVector3f.java | 28 +- .../lwjgl/util/vector/ReadableVector4f.java | 30 +- src/java/org/lwjgl/util/vector/Vector.java | 42 +- src/java/org/lwjgl/util/vector/Vector2f.java | 30 +- src/java/org/lwjgl/util/vector/Vector3f.java | 34 +- .../lwjgl/util/vector/WritableVector2f.java | 38 +- .../lwjgl/util/vector/WritableVector3f.java | 34 +- .../lwjgl/util/vector/WritableVector4f.java | 34 +- src/native/common/extcl_types.h | 2 - src/native/common/org_lwjgl_opencl_CL.c | 16 +- src/native/common/org_lwjgl_opencl_CL.h | 8 + .../org/lwjgl/opencl/AMD_event_callback.java | 39 + src/templates/org/lwjgl/opencl/CL10.java | 81 +- .../org/lwjgl/opencl/KHR_d3d10_sharing.java | 39 + src/templates/org/lwjgl/opencl/KHR_icd.java | 1 + src/templates/org/lwjgl/opengl/ARB_sync.java | 4 +- src/templates/org/lwjgl/opengl/GL32.java | 8 +- 211 files changed, 7927 insertions(+), 6549 deletions(-) delete mode 100644 src/java/org/lwjgl/opencl/CLDeviceImpl.java rename src/java/org/lwjgl/opencl/{CLKernelImpl.java => CLObjectRetainable.java} (53%) delete mode 100644 src/java/org/lwjgl/opencl/CLPlatformImpl.java create mode 100644 src/java/org/lwjgl/opencl/InfoUtil.java create mode 100644 src/java/org/lwjgl/opencl/InfoUtilAbstract.java create mode 100644 src/java/org/lwjgl/opencl/InfoUtilFactory.java create mode 100644 src/templates/org/lwjgl/opencl/AMD_event_callback.java create mode 100644 src/templates/org/lwjgl/opencl/KHR_d3d10_sharing.java diff --git a/build.xml b/build.xml index c4dd46d7..0f0cfc71 100644 --- a/build.xml +++ b/build.xml @@ -16,74 +16,88 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + + + + + + + + + + + + - - - - - Build aborted by user. + + + + + Build aborted by user. - - - - + + + + + + + + + - - - - - - - - - - - - + - - - - + + + + - + + + + + + + + + + - + @@ -219,7 +233,7 @@ - + @@ -231,7 +245,7 @@ - + @@ -241,7 +255,7 @@ - + @@ -342,6 +356,7 @@ + @@ -493,7 +508,7 @@ - + Lightweight Java Game Toolkit]]> Copyright © 2002-2009 lwjgl.org. All Rights Reserved.]]> diff --git a/platform_build/build-generator.xml b/platform_build/build-generator.xml index 1f2e1fdd..50a9f4eb 100644 --- a/platform_build/build-generator.xml +++ b/platform_build/build-generator.xml @@ -1,13 +1,18 @@ - + - + + + + + + diff --git a/src/java/org/lwjgl/BufferChecks.java b/src/java/org/lwjgl/BufferChecks.java index 27b35904..86a64896 100644 --- a/src/java/org/lwjgl/BufferChecks.java +++ b/src/java/org/lwjgl/BufferChecks.java @@ -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"); } diff --git a/src/java/org/lwjgl/LWJGLUtil.java b/src/java/org/lwjgl/LWJGLUtil.java index abbf0d6f..fb70a3c5 100644 --- a/src/java/org/lwjgl/LWJGLUtil.java +++ b/src/java/org/lwjgl/LWJGLUtil.java @@ -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 possible_paths = new ArrayList(); 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() { + 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() { + 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() { + 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() { + public Boolean run() { + return Boolean.getBoolean(property_name); } }); - return value.booleanValue(); + return value; } /** diff --git a/src/java/org/lwjgl/LinuxSysImplementation.java b/src/java/org/lwjgl/LinuxSysImplementation.java index cccd697c..3669bbc2 100644 --- a/src/java/org/lwjgl/LinuxSysImplementation.java +++ b/src/java/org/lwjgl/LinuxSysImplementation.java @@ -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; diff --git a/src/java/org/lwjgl/MacOSXSysImplementation.java b/src/java/org/lwjgl/MacOSXSysImplementation.java index 7c99fe6a..1bb6c6b7 100644 --- a/src/java/org/lwjgl/MacOSXSysImplementation.java +++ b/src/java/org/lwjgl/MacOSXSysImplementation.java @@ -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 diff --git a/src/java/org/lwjgl/NondirectBufferWrapper.java b/src/java/org/lwjgl/NondirectBufferWrapper.java index 5b73e2e0..72825e32 100644 --- a/src/java/org/lwjgl/NondirectBufferWrapper.java +++ b/src/java/org/lwjgl/NondirectBufferWrapper.java @@ -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 thread_buffer = new ThreadLocal() { + 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; diff --git a/src/java/org/lwjgl/PointerBuffer.java b/src/java/org/lwjgl/PointerBuffer.java index b541d86f..b731e263 100644 --- a/src/java/org/lwjgl/PointerBuffer.java +++ b/src/java/org/lwjgl/PointerBuffer.java @@ -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()); diff --git a/src/java/org/lwjgl/PointerWrapperAbstract.java b/src/java/org/lwjgl/PointerWrapperAbstract.java index 2f718bd7..7652cc1b 100644 --- a/src/java/org/lwjgl/PointerWrapperAbstract.java +++ b/src/java/org/lwjgl/PointerWrapperAbstract.java @@ -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) + ")"; + } } \ No newline at end of file diff --git a/src/java/org/lwjgl/Sys.java b/src/java/org/lwjgl/Sys.java index 59ba4f23..0fb85dcc 100644 --- a/src/java/org/lwjgl/Sys.java +++ b/src/java/org/lwjgl/Sys.java @@ -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() { 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() { + 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() { + 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; diff --git a/src/java/org/lwjgl/WindowsSysImplementation.java b/src/java/org/lwjgl/WindowsSysImplementation.java index 60744412..b54a3cf6 100644 --- a/src/java/org/lwjgl/WindowsSysImplementation.java +++ b/src/java/org/lwjgl/WindowsSysImplementation.java @@ -45,12 +45,12 @@ import org.lwjgl.opengl.Display; * $Id$ */ final class WindowsSysImplementation extends DefaultSysImplementation { - private final static int JNI_VERSION = 23; + private static final int JNI_VERSION = 23; static { Sys.initialize(); } - + public int getRequiredJNIVersion() { return JNI_VERSION; } @@ -64,7 +64,7 @@ final class WindowsSysImplementation extends DefaultSysImplementation { } private static native long nGetTime(); - public final boolean has64Bit() { + public boolean has64Bit() { return true; } @@ -75,19 +75,17 @@ final class WindowsSysImplementation extends DefaultSysImplementation { * public */ try { - Long hwnd_obj = (Long)AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation", null); + return AccessController.doPrivileged(new PrivilegedExceptionAction() { + 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); } diff --git a/src/java/org/lwjgl/examples/Game.java b/src/java/org/lwjgl/examples/Game.java index 625973b6..926b86ce 100644 --- a/src/java/org/lwjgl/examples/Game.java +++ b/src/java/org/lwjgl/examples/Game.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -35,7 +35,8 @@ import org.lwjgl.Sys; import org.lwjgl.input.Keyboard; import org.lwjgl.openal.AL; import org.lwjgl.opengl.Display; -import org.lwjgl.opengl.GL11; + +import static org.lwjgl.opengl.GL11.*; /** * @@ -46,24 +47,24 @@ import org.lwjgl.opengl.GL11; * $Id$ */ public class Game { - + /** Game title */ public static final String GAME_TITLE = "My Game"; - + /** Desired frame time */ private static final int FRAMERATE = 60; - + /** Exit the game */ private static boolean finished; - + /** A rotating square! */ private static float angle; - + /** * No constructor needed - this class is static */ private Game() {} - + /** * Application init * @param args Commandline args @@ -78,10 +79,10 @@ public class Game { } finally { cleanup(); } - + System.exit(0); } - + /** * Initialise the game * @throws Exception if init fails @@ -94,25 +95,25 @@ public class Game { // Enable vsync if we can Display.setVSyncEnabled(true); - + Display.create(); - + // Start up the sound system AL.create(); - + // TODO: Load in your textures etc here - + // Put the window into orthographic projection mode with 1:1 pixel ratio. // We haven't used GLU here to do this to avoid an unnecessary dependency. - GL11.glMatrixMode(GL11.GL_PROJECTION); - GL11.glLoadIdentity(); - GL11.glOrtho(0.0, Display.getDisplayMode().getWidth(), 0.0, Display.getDisplayMode().getHeight(), -1.0, 1.0); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - GL11.glLoadIdentity(); - GL11.glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight()); - + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0.0, Display.getDisplayMode().getWidth(), 0.0, Display.getDisplayMode().getHeight(), -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight()); + } - + /** * Runs the game (the "main loop") */ @@ -120,7 +121,7 @@ public class Game { while (!finished) { // Always call Window.update(), all the time Display.update(); - + if (Display.isCloseRequested()) { // Check for O/S close requests finished = true; @@ -144,7 +145,7 @@ public class Game { } } } - + /** * Do any game-specific cleanup */ @@ -153,11 +154,11 @@ public class Game { // Stop the sound AL.destroy(); - + // Close the window Display.destroy(); } - + /** * Do all calculations, handle input, etc. */ @@ -170,24 +171,24 @@ public class Game { // TODO: all your game logic goes here. angle += 2.0f % 360; } - + /** * Render the current frame */ private static void render() { - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // TODO: all your rendering goes here - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); - GL11.glPushMatrix(); - GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f); - GL11.glRotatef(angle, 0, 0, 1.0f); - GL11.glBegin(GL11.GL_QUADS); - GL11.glVertex2i(-50, -50); - GL11.glVertex2i(50, -50); - GL11.glVertex2i(50, 50); - GL11.glVertex2i(-50, 50); - GL11.glEnd(); - GL11.glPopMatrix(); + glClear(GL_COLOR_BUFFER_BIT); + glPushMatrix(); + glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f); + glRotatef(angle, 0, 0, 1.0f); + glBegin(GL_QUADS); + glVertex2i(-50, -50); + glVertex2i(50, -50); + glVertex2i(50, 50); + glVertex2i(-50, 50); + glEnd(); + glPopMatrix(); } } diff --git a/src/java/org/lwjgl/examples/spaceinvaders/Entity.java b/src/java/org/lwjgl/examples/spaceinvaders/Entity.java index ca9e09bb..85d6dad5 100644 --- a/src/java/org/lwjgl/examples/spaceinvaders/Entity.java +++ b/src/java/org/lwjgl/examples/spaceinvaders/Entity.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -37,13 +37,13 @@ import java.awt.Rectangle; * An entity represents any element that appears in the game. The * entity is responsible for resolving collisions and movement * based on a set of properties defined either by subclass or externally. - * + * * Note that doubles are used for positions. This may seem strange * given that pixels locations are integers. However, using double means * that an entity can move a partial pixel. It doesn't of course mean that * they will be display half way through a pixel but allows us not lose * accuracy as we move. - * + * * @author Kevin Glass */ public abstract class Entity { @@ -71,12 +71,12 @@ public abstract class Entity { /** * Construct a entity based on a sprite image and a location. - * - * @param ref The reference to the image to be displayed for this entity + * + * @param sprite The reference to the image to be displayed for this entity * @param x The initial x location of this entity * @param y The initial y location of this entity */ - public Entity(Sprite sprite, int x, int y) { + protected Entity(Sprite sprite, int x, int y) { this.sprite = sprite; this.x = x; this.y = y; @@ -85,7 +85,7 @@ public abstract class Entity { /** * Request that this entity move itself based on a certain ammount * of time passing. - * + * * @param delta The ammount of time that has passed in milliseconds */ public void move(long delta) { @@ -96,7 +96,7 @@ public abstract class Entity { /** * Set the horizontal speed of this entity - * + * * @param dx The horizontal speed of this entity (pixels/sec) */ public void setHorizontalMovement(float dx) { @@ -105,7 +105,7 @@ public abstract class Entity { /** * Set the vertical speed of this entity - * + * * @param dy The vertical speed of this entity (pixels/sec) */ public void setVerticalMovement(float dy) { @@ -114,7 +114,7 @@ public abstract class Entity { /** * Get the horizontal speed of this entity - * + * * @return The horizontal speed of this entity (pixels/sec) */ public float getHorizontalMovement() { @@ -123,7 +123,7 @@ public abstract class Entity { /** * Get the vertical speed of this entity - * + * * @return The vertical speed of this entity (pixels/sec) */ public float getVerticalMovement() { @@ -146,7 +146,7 @@ public abstract class Entity { /** * Get the x location of this entity - * + * * @return The x location of this entity */ public int getX() { @@ -155,7 +155,7 @@ public abstract class Entity { /** * Get the y location of this entity - * + * * @return The y location of this entity */ public int getY() { @@ -164,7 +164,7 @@ public abstract class Entity { /** * Check if this entity collised with another. - * + * * @param other The other entity to check collision against * @return True if the entities collide with each other */ @@ -177,7 +177,7 @@ public abstract class Entity { /** * Notification that this entity collided with another. - * + * * @param other The entity with which this entity collided. */ public abstract void collidedWith(Entity other); diff --git a/src/java/org/lwjgl/examples/spaceinvaders/Game.java b/src/java/org/lwjgl/examples/spaceinvaders/Game.java index 051dba49..02deb132 100644 --- a/src/java/org/lwjgl/examples/spaceinvaders/Game.java +++ b/src/java/org/lwjgl/examples/spaceinvaders/Game.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -39,32 +39,33 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; -import org.lwjgl.opengl.GL11; + +import static org.lwjgl.opengl.GL11.*; /** * The main hook of our game. This class with both act as a manager - * for the display and central mediator for the game logic. - * + * for the display and central mediator for the game logic. + * * Display management will consist of a loop that cycles round all * entities in the game asking them to move and then drawing them * in the appropriate place. With the help of an inner class it * will also allow the player to control the main ship. - * + * * As a mediator it will be informed when entities within our game * detect events (e.g. alient killed, played died) and will take * appropriate game actions. - * + * *

* NOTE:
* This game is a LWJGLized implementation of the Space Invaders game by Kevin - * Glass. The original implementation is renderer agnostic and supports other + * Glass. The original implementation is renderer agnostic and supports other * OpenGL implementations as well as Java2D. This version has been made specific - * for LWJGL, and has added input control as well as sound (which the original doesn't, + * for LWJGL, and has added input control as well as sound (which the original doesn't, * at the time of writing). * You can find the original article here:
* http://www.cokeandcode.com *

- * + * * @author Kevin Glass * @author Brian Matzon */ @@ -83,10 +84,10 @@ public class Game { private TextureLoader textureLoader; /** The list of all the entities that exist in our game */ - private ArrayList entities = new ArrayList(); + private ArrayList entities = new ArrayList(); /** The list of entities that need to be removed from the game this loop */ - private ArrayList removeList = new ArrayList(); + private ArrayList removeList = new ArrayList(); /** The entity representing the player */ private ShipEntity ship; @@ -113,7 +114,7 @@ public class Game { private float moveSpeed = 300; /** The time at which last fired a shot */ - private long lastFire = 0; + private long lastFire; /** The interval between our players shot (ms) */ private long firingInterval = 500; @@ -125,16 +126,16 @@ public class Game { private boolean waitingForKeyPress = true; /** True if game logic needs to be applied this loop, normally as a result of a game event */ - private boolean logicRequiredThisLoop = false; + private boolean logicRequiredThisLoop; /** The time at which the last rendering looped started from the point of view of the game logic */ private long lastLoopTime = getTime(); /** True if the fire key has been released */ - private boolean fireHasBeenReleased = false; + private boolean fireHasBeenReleased; /** The time since the last record of fps */ - private long lastFpsTime = 0; + private long lastFpsTime; /** The recorded fps */ private int fps; @@ -167,15 +168,14 @@ public class Game { /** Mouse movement on x axis */ private int mouseX; - + /** Is this an application or applet */ - private static boolean isApplication = false; + private static boolean isApplication; /** * Construct our game and set it running. * @param fullscreen - * - * @param renderingType The type of rendering to use (should be one of the contansts from ResourceFactory) + * */ public Game(boolean fullscreen) { this.fullscreen = fullscreen; @@ -184,7 +184,7 @@ public class Game { /** * Get the high resolution time in milliseconds - * + * * @return The high resolution time in milliseconds */ public static long getTime() { @@ -196,8 +196,8 @@ public class Game { } /** - * Sleep for a fixed number of milliseconds. - * + * Sleep for a fixed number of milliseconds. + * * @param duration The amount of time in milliseconds to sleep for */ public static void sleep(long duration) { @@ -217,25 +217,25 @@ public class Game { Display.setTitle(WINDOW_TITLE); Display.setFullscreen(fullscreen); Display.create(); - + // grab the mouse, dont want that hideous cursor when we're playing! - if (isApplication) { + if (isApplication) { Mouse.setGrabbed(true); } // enable textures since we're going to use these for our sprites - GL11.glEnable(GL11.GL_TEXTURE_2D); + glEnable(GL_TEXTURE_2D); // disable the OpenGL depth test since we're rendering 2D graphics - GL11.glDisable(GL11.GL_DEPTH_TEST); + glDisable(GL_DEPTH_TEST); - GL11.glMatrixMode(GL11.GL_PROJECTION); - GL11.glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); - GL11.glOrtho(0, width, height, 0, -1, 1); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - GL11.glLoadIdentity(); - GL11.glViewport(0, 0, width, height); + glOrtho(0, width, height, 0, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0, 0, width, height); textureLoader = new TextureLoader(); @@ -289,7 +289,7 @@ public class Game { "height=" + height, "freq=" + 60, "bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel() - }); + }); return true; } catch (Exception e) { e.printStackTrace(); @@ -341,7 +341,7 @@ public class Game { /** * Remove an entity from the game. The entity removed will * no longer move or be drawn. - * + * * @param entity The entity that should be removed */ public void removeEntity(Entity entity) { @@ -349,7 +349,7 @@ public class Game { } /** - * Notification that the player has died. + * Notification that the player has died. */ public void notifyDeath() { if (!waitingForKeyPress) { @@ -382,10 +382,8 @@ public class Game { // if there are still some aliens left then they all need to get faster, so // speed up all the existing aliens - for (int i = 0; i < entities.size(); i++) { - Entity entity = (Entity) entities.get(i); - - if (entity instanceof AlienEntity) { + for ( Entity entity : entities ) { + if ( entity instanceof AlienEntity ) { // speed up by 2% entity.setHorizontalMovement(entity.getHorizontalMovement() * 1.02f); } @@ -396,7 +394,7 @@ public class Game { /** * Attempt to fire a shot from the player. Its called "try" - * since we must first check that the player can fire at this + * since we must first check that the player can fire at this * point, i.e. has he/she waited long enough between shots */ public void tryToFire() { @@ -421,9 +419,9 @@ public class Game { private void gameLoop() { while (Game.gameRunning) { // clear screen - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - GL11.glLoadIdentity(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); // let subsystem paint frameRendering(); @@ -431,7 +429,7 @@ public class Game { // update window contents Display.update(); } - + // clean up soundManager.destroy(); Display.destroy(); @@ -462,25 +460,23 @@ public class Game { // cycle round asking each entity to move itself if (!waitingForKeyPress && !soundManager.isPlayingSound()) { - for (int i = 0; i < entities.size(); i++) { - Entity entity = (Entity) entities.get(i); + for ( Entity entity : entities ) { entity.move(delta); } } // cycle round drawing all the entities we have in the game - for (int i = 0; i < entities.size(); i++) { - Entity entity = (Entity) entities.get(i); + for ( Entity entity : entities ) { entity.draw(); } // brute force collisions, compare every entity against - // every other entity. If any of them collide notify + // every other entity. If any of them collide notify // both entities that the collision has occured for (int p = 0; p < entities.size(); p++) { for (int s = p + 1; s < entities.size(); s++) { - Entity me = (Entity) entities.get(p); - Entity him = (Entity) entities.get(s); + Entity me = entities.get(p); + Entity him = entities.get(s); if (me.collidesWith(him)) { me.collidedWith(him); @@ -497,21 +493,20 @@ public class Game { // be resolved, cycle round every entity requesting that // their personal logic should be considered. if (logicRequiredThisLoop) { - for (int i = 0; i < entities.size(); i++) { - Entity entity = (Entity) entities.get(i); + for ( Entity entity : entities ) { entity.doLogic(); } logicRequiredThisLoop = false; } - // if we're waiting for an "any key" press then draw the - // current message + // if we're waiting for an "any key" press then draw the + // current message if (waitingForKeyPress) { message.draw(325, 250); } - // resolve the movemfent of the ship. First assume the ship + // resolve the movemfent of the ship. First assume the ship // isn't moving. If either cursor key is pressed then // update the movement appropraitely ship.setHorizontalMovement(0); @@ -557,23 +552,23 @@ public class Game { } /** - * @param key_left + * @param direction * @return */ private boolean hasInput(int direction) { switch(direction) { case Keyboard.KEY_LEFT: - return + return Keyboard.isKeyDown(Keyboard.KEY_LEFT) || mouseX < 0; - + case Keyboard.KEY_RIGHT: - return + return Keyboard.isKeyDown(Keyboard.KEY_RIGHT) || mouseX > 0; - + case Keyboard.KEY_SPACE: - return + return Keyboard.isKeyDown(Keyboard.KEY_SPACE) || Mouse.isButtonDown(0); } @@ -584,18 +579,18 @@ public class Game { * The entry point into the game. We'll simply create an * instance of class which will start the display and game * loop. - * + * * @param argv The arguments that are passed into our game */ public static void main(String argv[]) { isApplication = true; System.out.println("Use -fullscreen for fullscreen mode"); - new Game((argv.length > 0 && argv[0].equalsIgnoreCase("-fullscreen"))).execute(); + new Game((argv.length > 0 && "-fullscreen".equalsIgnoreCase(argv[0]))).execute(); System.exit(0); } /** - * + * */ public void execute() { gameLoop(); @@ -604,7 +599,7 @@ public class Game { /** * Create or get a sprite which displays the image that is pointed * to in the classpath by "ref" - * + * * @param ref A reference to the image to load * @return A sprite that can be drawn onto the current graphics context. */ diff --git a/src/java/org/lwjgl/examples/spaceinvaders/GameApplet.java b/src/java/org/lwjgl/examples/spaceinvaders/GameApplet.java index a1ac0ccb..0e2d0165 100644 --- a/src/java/org/lwjgl/examples/spaceinvaders/GameApplet.java +++ b/src/java/org/lwjgl/examples/spaceinvaders/GameApplet.java @@ -8,27 +8,27 @@ import org.lwjgl.LWJGLException; import org.lwjgl.opengl.Display; public class GameApplet extends Applet { - + /** The Canvas where the LWJGL Display is added */ Canvas display_parent; - + /** Thread which runs the main game loop */ Thread gameThread; - + /** The Game instance */ Game game; - + /** - * Once the Canvas is created its add notify method will call this method to + * Once the Canvas is created its add notify method will call this method to * start the LWJGL Display and game loop in another thread. */ public void startLWJGL() { gameThread = new Thread() { public void run() { - + try { Display.setParent(display_parent); - + } catch (LWJGLException e) { e.printStackTrace(); } @@ -39,8 +39,8 @@ public class GameApplet extends Applet { }; gameThread.start(); } - - + + /** * Tell game loop to stop running, after which the LWJGL Display will be destoryed. * The main thread will wait for the Display.destroy() to complete @@ -55,15 +55,15 @@ public class GameApplet extends Applet { } public void start() { - + } public void stop() { - + } - + /** - * Applet Destroy method will remove the canvas, before canvas is destroyed it will notify + * Applet Destroy method will remove the canvas, before canvas is destroyed it will notify * stopLWJGL() to stop main game loop and to destroy the Display */ public void destroy() { @@ -71,21 +71,21 @@ public class GameApplet extends Applet { super.destroy(); System.out.println("Clear up"); } - + /** * initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop - * in another thread. It will also stop the game loop and destroy the display on canvas removal when + * in another thread. It will also stop the game loop and destroy the display on canvas removal when * applet is destroyed. */ public void init() { setLayout(new BorderLayout()); try { display_parent = new Canvas() { - public final void addNotify() { + public void addNotify() { super.addNotify(); startLWJGL(); } - public final void removeNotify() { + public void removeNotify() { stopLWJGL(); super.removeNotify(); } diff --git a/src/java/org/lwjgl/examples/spaceinvaders/ShotEntity.java b/src/java/org/lwjgl/examples/spaceinvaders/ShotEntity.java index eceafb06..7e1a12d3 100644 --- a/src/java/org/lwjgl/examples/spaceinvaders/ShotEntity.java +++ b/src/java/org/lwjgl/examples/spaceinvaders/ShotEntity.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -33,7 +33,7 @@ package org.lwjgl.examples.spaceinvaders; /** * An entity representing a shot fired by the player's ship - * + * * @author Kevin Glass * @author Brian Matzon */ @@ -49,11 +49,11 @@ public class ShotEntity extends Entity { private Game game; /** True if this shot has been "used", i.e. its hit something */ - private boolean used = false; + private boolean used; /** * Create a new shot from the player - * + * * @param game The game in which the shot has been created * @param sprite The sprite representing this shot * @param x The initial x location of the shot @@ -68,7 +68,7 @@ public class ShotEntity extends Entity { /** * Reinitializes this entity, for reuse - * + * * @param x new x coordinate * @param y new y coordinate */ @@ -80,7 +80,7 @@ public class ShotEntity extends Entity { /** * Request that this shot moved based on time elapsed - * + * * @param delta The time that has elapsed since last move */ public void move(long delta) { @@ -96,7 +96,7 @@ public class ShotEntity extends Entity { /** * Notification that this shot has collided with another * entity - * + * * @param other The other entity with which we've collided */ public void collidedWith(Entity other) { diff --git a/src/java/org/lwjgl/examples/spaceinvaders/SoundManager.java b/src/java/org/lwjgl/examples/spaceinvaders/SoundManager.java index 2dc3d29b..292630db 100644 --- a/src/java/org/lwjgl/examples/spaceinvaders/SoundManager.java +++ b/src/java/org/lwjgl/examples/spaceinvaders/SoundManager.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -54,22 +54,22 @@ public class SoundManager { /** We support at most 256 buffers*/ private int[] buffers = new int[256]; - + /** Number of sources is limited tby user (and hardware) */ private int[] sources; - + /** Our internal scratch buffer */ private IntBuffer scratchBuffer = BufferUtils.createIntBuffer(256); - + /** Whether we're running in no sound mode */ private boolean soundOutput; - + /** Current index in our buffers */ private int bufferIndex; - + /** Current index in our source list */ private int sourceIndex; - + /** * Creates a new SoundManager */ @@ -78,13 +78,13 @@ public class SoundManager { /** * Plays a sound effect - * @param buffer Buffer index to play gotten from addSound + * @param buffer Buffer index to play gotten from addSound */ public void playEffect(int buffer) { if(soundOutput) { // make sure we never choose last channel, since it is used for special sounds int channel = sources[(sourceIndex++ % (sources.length-1))]; - + // link buffer and source, and play it AL10.alSourcei(channel, AL10.AL_BUFFER, buffers[buffer]); AL10.alSourcePlay(channel); @@ -101,7 +101,7 @@ public class SoundManager { AL10.alSourcePlay(sources[sources.length-1]); } } - + /** * Whether a sound is playing on last source * @return true if a source is playing right now on source n @@ -109,27 +109,27 @@ public class SoundManager { public boolean isPlayingSound() { return AL10.alGetSourcei(sources[sources.length-1], AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING; } - + /** * Initializes the SoundManager - * - * @param sources Number of sources to create + * + * @param channels Number of channels to create */ public void initialize(int channels) { try { AL.create(); - + // allocate sources scratchBuffer.limit(channels); AL10.alGenSources(scratchBuffer); scratchBuffer.rewind(); scratchBuffer.get(sources = new int[channels]); - + // could we allocate all channels? if(AL10.alGetError() != AL10.AL_NO_ERROR) { throw new LWJGLException("Unable to allocate " + channels + " sources"); } - + // we have sound soundOutput = true; } catch (LWJGLException le) { @@ -137,10 +137,10 @@ public class SoundManager { System.out.println("Sound disabled"); } } - + /** * Adds a sound to the Sound Managers pool - * + * * @param path Path to file to load * @return index into SoundManagers buffer list */ @@ -149,26 +149,26 @@ public class SoundManager { scratchBuffer.rewind().position(0).limit(1); AL10.alGenBuffers(scratchBuffer); buffers[bufferIndex] = scratchBuffer.get(0); - + // load wave data from buffer WaveData wavefile = WaveData.create("spaceinvaders/" + path); // copy to buffers AL10.alBufferData(buffers[bufferIndex], wavefile.format, wavefile.data, wavefile.samplerate); - + // unload file again - wavefile.dispose(); - + wavefile.dispose(); + // return index for this sound return bufferIndex++; } - + /** * Destroy this SoundManager */ public void destroy() { if(soundOutput) { - + // stop playing sounds scratchBuffer.position(0).limit(sources.length); scratchBuffer.put(sources).flip(); @@ -176,12 +176,12 @@ public class SoundManager { // destroy sources AL10.alDeleteSources(scratchBuffer); - + // destroy buffers scratchBuffer.position(0).limit(bufferIndex); scratchBuffer.put(buffers, 0, bufferIndex).flip(); AL10.alDeleteBuffers(scratchBuffer); - + // destory OpenAL AL.destroy(); } diff --git a/src/java/org/lwjgl/examples/spaceinvaders/Sprite.java b/src/java/org/lwjgl/examples/spaceinvaders/Sprite.java index 845346c7..9a082a40 100644 --- a/src/java/org/lwjgl/examples/spaceinvaders/Sprite.java +++ b/src/java/org/lwjgl/examples/spaceinvaders/Sprite.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -33,12 +33,12 @@ package org.lwjgl.examples.spaceinvaders; import java.io.IOException; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; /** * Implementation of sprite that uses an OpenGL quad and a texture * to render a given image to the screen. - * + * * @author Kevin Glass * @author Brian Matzon */ @@ -55,8 +55,8 @@ public class Sprite { /** * Create a new sprite from a specified image. - * - * @param window The window in which the sprite will be displayed + * + * @param loader the texture loader to use * @param ref A reference to the image on which this sprite should be based */ public Sprite(TextureLoader loader, String ref) { @@ -72,7 +72,7 @@ public class Sprite { /** * Get the width of this sprite in pixels - * + * * @return The width of this sprite in pixels */ public int getWidth() { @@ -81,7 +81,7 @@ public class Sprite { /** * Get the height of this sprite in pixels - * + * * @return The height of this sprite in pixels */ public int getHeight() { @@ -90,38 +90,38 @@ public class Sprite { /** * Draw the sprite at the specified location - * + * * @param x The x location at which to draw this sprite * @param y The y location at which to draw this sprite */ public void draw(int x, int y) { // store the current model matrix - GL11.glPushMatrix(); + glPushMatrix(); // bind to the appropriate texture for this sprite texture.bind(); // translate to the right location and prepare to draw - GL11.glTranslatef(x, y, 0); + glTranslatef(x, y, 0); // draw a quad textured to match the sprite - GL11.glBegin(GL11.GL_QUADS); + glBegin(GL_QUADS); { - GL11.glTexCoord2f(0, 0); - GL11.glVertex2f(0, 0); + glTexCoord2f(0, 0); + glVertex2f(0, 0); - GL11.glTexCoord2f(0, texture.getHeight()); - GL11.glVertex2f(0, height); + glTexCoord2f(0, texture.getHeight()); + glVertex2f(0, height); - GL11.glTexCoord2f(texture.getWidth(), texture.getHeight()); - GL11.glVertex2f(width, height); + glTexCoord2f(texture.getWidth(), texture.getHeight()); + glVertex2f(width, height); - GL11.glTexCoord2f(texture.getWidth(), 0); - GL11.glVertex2f(width, 0); + glTexCoord2f(texture.getWidth(), 0); + glVertex2f(width, 0); } - GL11.glEnd(); + glEnd(); // restore the model view matrix to prevent contamination - GL11.glPopMatrix(); + glPopMatrix(); } } \ No newline at end of file diff --git a/src/java/org/lwjgl/examples/spaceinvaders/Texture.java b/src/java/org/lwjgl/examples/spaceinvaders/Texture.java index 05031726..f3cde23d 100644 --- a/src/java/org/lwjgl/examples/spaceinvaders/Texture.java +++ b/src/java/org/lwjgl/examples/spaceinvaders/Texture.java @@ -1,43 +1,43 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.examples.spaceinvaders; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; /** - * A texture to be bound within OpenGL. This object is responsible for + * A texture to be bound within OpenGL. This object is responsible for * keeping track of a given OpenGL texture and for calculating the * texturing mapping coordinates of the full image. - * + * * Since textures need to be powers of 2 the actual texture may be * considerably bigged that the source image and hence the texture * mapping coordinates need to be adjusted to matchup drawing the @@ -75,7 +75,7 @@ public class Texture { /** * Create a new texture * - * @param target The GL target + * @param target The GL target * @param textureID The GL texture ID */ public Texture(int target, int textureID) { @@ -85,11 +85,9 @@ public class Texture { /** * Bind the specified GL context to a texture - * - * @param gl The GL context to bind to */ public void bind() { - GL11.glBindTexture(target, textureID); + glBindTexture(target, textureID); } /** @@ -121,7 +119,7 @@ public class Texture { return height; } - /** + /** * Get the width of the original image * * @return The width of the original image @@ -149,7 +147,7 @@ public class Texture { } /** - * Set the height of this texture + * Set the height of this texture * * @param texHeight The height of the texture */ @@ -159,7 +157,7 @@ public class Texture { } /** - * Set the width of this texture + * Set the width of this texture * * @param texWidth The width of the texture */ diff --git a/src/java/org/lwjgl/examples/spaceinvaders/TextureLoader.java b/src/java/org/lwjgl/examples/spaceinvaders/TextureLoader.java index 8a744840..8c2c498e 100644 --- a/src/java/org/lwjgl/examples/spaceinvaders/TextureLoader.java +++ b/src/java/org/lwjgl/examples/spaceinvaders/TextureLoader.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -53,14 +53,15 @@ import java.util.Hashtable; import javax.imageio.ImageIO; import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.GL11; + +import static org.lwjgl.opengl.GL11.*; /** * A utility class to load textures for OpenGL. This source is based * on a texture that can be found in the Java Gaming (www.javagaming.org) * Wiki. It has been simplified slightly for explicit 2D graphics use. - * - * OpenGL uses a particular image format. Since the images that are + * + * OpenGL uses a particular image format. Since the images that are * loaded from disk may not match this format this loader introduces * a intermediate image which the source image is copied into. In turn, * this image is used as source for the OpenGL texture. @@ -70,21 +71,19 @@ import org.lwjgl.opengl.GL11; */ public class TextureLoader { /** The table of textures that have been loaded in this loader */ - private HashMap table = new HashMap(); + private HashMap table = new HashMap(); /** The colour model including alpha for the GL image */ private ColorModel glAlphaColorModel; - + /** The colour model for the GL image */ private ColorModel glColorModel; - + /** Scratch buffer for texture ID's */ - private IntBuffer textureIDBuffer = BufferUtils.createIntBuffer(1); - - /** + private IntBuffer textureIDBuffer = BufferUtils.createIntBuffer(1); + + /** * Create a new texture loader based on the game panel - * - * @param gl The GL content in which the textures should be loaded */ public TextureLoader() { glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), @@ -93,7 +92,7 @@ public class TextureLoader { false, ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE); - + glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {8,8,8,0}, false, @@ -101,17 +100,17 @@ public class TextureLoader { ComponentColorModel.OPAQUE, DataBuffer.TYPE_BYTE); } - + /** - * Create a new texture ID + * Create a new texture ID * * @return A new texture ID */ private int createTextureID() { - GL11.glGenTextures(textureIDBuffer); + glGenTextures(textureIDBuffer); return textureIDBuffer.get(0); - } - + } + /** * Load a texture * @@ -120,23 +119,23 @@ public class TextureLoader { * @throws IOException Indicates a failure to access the resource */ public Texture getTexture(String resourceName) throws IOException { - Texture tex = (Texture) table.get(resourceName); - + Texture tex = table.get(resourceName); + if (tex != null) { return tex; } - + tex = getTexture(resourceName, - GL11.GL_TEXTURE_2D, // target - GL11.GL_RGBA, // dst pixel format - GL11.GL_LINEAR, // min filter (unused) - GL11.GL_LINEAR); - + GL_TEXTURE_2D, // target + GL_RGBA, // dst pixel format + GL_LINEAR, // min filter (unused) + GL_LINEAR); + table.put(resourceName,tex); - + return tex; } - + /** * Load a texture into OpenGL from a image reference on * disk. @@ -149,66 +148,66 @@ public class TextureLoader { * @return The loaded texture * @throws IOException Indicates a failure to access the resource */ - public Texture getTexture(String resourceName, - int target, - int dstPixelFormat, - int minFilter, - int magFilter) throws IOException { - int srcPixelFormat = 0; - - // create the texture ID for this texture - int textureID = createTextureID(); - Texture texture = new Texture(target,textureID); - - // bind this texture - GL11.glBindTexture(target, textureID); - - BufferedImage bufferedImage = loadImage(resourceName); + public Texture getTexture(String resourceName, + int target, + int dstPixelFormat, + int minFilter, + int magFilter) throws IOException { + int srcPixelFormat; + + // create the texture ID for this texture + int textureID = createTextureID(); + Texture texture = new Texture(target,textureID); + + // bind this texture + glBindTexture(target, textureID); + + BufferedImage bufferedImage = loadImage(resourceName); texture.setWidth(bufferedImage.getWidth()); texture.setHeight(bufferedImage.getHeight()); - + if (bufferedImage.getColorModel().hasAlpha()) { - srcPixelFormat = GL11.GL_RGBA; + srcPixelFormat = GL_RGBA; } else { - srcPixelFormat = GL11.GL_RGB; + srcPixelFormat = GL_RGB; + } + + // convert that image into a byte buffer of texture data + ByteBuffer textureBuffer = convertImageData(bufferedImage,texture); + + if (target == GL_TEXTURE_2D) { + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilter); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilter); } - // convert that image into a byte buffer of texture data - ByteBuffer textureBuffer = convertImageData(bufferedImage,texture); - - if (target == GL11.GL_TEXTURE_2D) { - GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter); - GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter); - } - // produce a texture from the byte buffer - GL11.glTexImage2D(target, - 0, - dstPixelFormat, - get2Fold(bufferedImage.getWidth()), - get2Fold(bufferedImage.getHeight()), - 0, - srcPixelFormat, - GL11.GL_UNSIGNED_BYTE, - textureBuffer ); - - return texture; - } - + glTexImage2D(target, + 0, + dstPixelFormat, + get2Fold(bufferedImage.getWidth()), + get2Fold(bufferedImage.getHeight()), + 0, + srcPixelFormat, + GL_UNSIGNED_BYTE, + textureBuffer ); + + return texture; + } + /** * Get the closest greater power of 2 to the fold number - * + * * @param fold The target number * @return The power of 2 */ - private int get2Fold(int fold) { + private static int get2Fold(int fold) { int ret = 2; while (ret < fold) { ret *= 2; } return ret; - } - + } + /** * Convert the buffered image to a texture * @@ -216,14 +215,14 @@ public class TextureLoader { * @param texture The texture to store the data into * @return A buffer containing the data */ - private ByteBuffer convertImageData(BufferedImage bufferedImage,Texture texture) { - ByteBuffer imageBuffer = null; + private ByteBuffer convertImageData(BufferedImage bufferedImage,Texture texture) { + ByteBuffer imageBuffer; WritableRaster raster; BufferedImage texImage; - + int texWidth = 2; int texHeight = 2; - + // find the closest power of 2 for the width and height // of the produced texture while (texWidth < bufferedImage.getWidth()) { @@ -232,10 +231,10 @@ public class TextureLoader { while (texHeight < bufferedImage.getHeight()) { texHeight *= 2; } - + texture.setTextureHeight(texHeight); texture.setTextureWidth(texWidth); - + // create a raster that can be used by OpenGL as a source // for a texture if (bufferedImage.getColorModel().hasAlpha()) { @@ -245,41 +244,41 @@ public class TextureLoader { raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,texWidth,texHeight,3,null); texImage = new BufferedImage(glColorModel,raster,false,new Hashtable()); } - + // copy the source image into the produced image Graphics g = texImage.getGraphics(); g.setColor(new Color(0f,0f,0f,0f)); g.fillRect(0,0,texWidth,texHeight); g.drawImage(bufferedImage,0,0,null); - - // build a byte buffer from the temporary image - // that be used by OpenGL to produce a texture. - byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer()).getData(); - imageBuffer = ByteBuffer.allocateDirect(data.length); - imageBuffer.order(ByteOrder.nativeOrder()); - imageBuffer.put(data, 0, data.length); + // build a byte buffer from the temporary image + // that be used by OpenGL to produce a texture. + byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer()).getData(); + + imageBuffer = ByteBuffer.allocateDirect(data.length); + imageBuffer.order(ByteOrder.nativeOrder()); + imageBuffer.put(data, 0, data.length); imageBuffer.flip(); - - return imageBuffer; - } - - /** + + return imageBuffer; + } + + /** * Load a given resource as a buffered image - * + * * @param ref The location of the resource to load * @return The loaded buffered image * @throws IOException Indicates a failure to find a resource */ - private BufferedImage loadImage(String ref) throws IOException { + private BufferedImage loadImage(String ref) throws IOException { URL url = TextureLoader.class.getClassLoader().getResource(ref); - + if (url == null) { throw new IOException("Cannot find: " + ref); } - - BufferedImage bufferedImage = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(ref))); - + + BufferedImage bufferedImage = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(ref))); + return bufferedImage; - } + } } diff --git a/src/java/org/lwjgl/input/Controller.java b/src/java/org/lwjgl/input/Controller.java index 4d2c3f47..2721ff64 100644 --- a/src/java/org/lwjgl/input/Controller.java +++ b/src/java/org/lwjgl/input/Controller.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -35,239 +35,239 @@ package org.lwjgl.input; * A game controller of some sort that will provide input. The controller * presents buttons and axes. Buttons are either pressed or not pressed. Axis * provide analogue values. - * + * * @author Kevin Glass */ public interface Controller { /** * Get the name assigned to this controller. - * + * * @return The name assigned to this controller */ - public String getName(); + String getName(); /** * Get the index of this controller in the collection - * + * * @return The index of this controller in the collection */ - public int getIndex(); - + int getIndex(); + /** * Retrieve the number of buttons available on this controller - * + * * @return The number of butotns available on this controller */ - public int getButtonCount(); - + int getButtonCount(); + /** - * Get the name of the specified button. Be warned, often this is + * Get the name of the specified button. Be warned, often this is * as exciting as "Button X" - * + * * @param index The index of the button whose name should be retrieved * @return The name of the button requested */ - public String getButtonName(int index); - + String getButtonName(int index); + /** * Check if a button is currently pressed - * + * * @param index The button to check * @return True if the button is currently pressed */ - public boolean isButtonPressed(int index); - + boolean isButtonPressed(int index); + /** * Poll the controller for new data. This will also update * events */ - public void poll(); - - /** + void poll(); + + /** * Get the X-Axis value of the POV on this controller - * + * * @return The X-Axis value of the POV on this controller */ - public float getPovX(); - - /** + float getPovX(); + + /** * Get the Y-Axis value of the POV on this controller - * + * * @return The Y-Axis value of the POV on this controller */ - public float getPovY(); - + float getPovY(); + /** * Get the dead zone for a specified axis - * + * * @param index The index of the axis for which to retrieve the dead zone * @return The dead zone for the specified axis */ - public float getDeadZone(int index); - + float getDeadZone(int index); + /** * Set the dead zone for the specified axis - * + * * @param index The index of hte axis for which to set the dead zone * @param zone The dead zone to use for the specified axis */ - public void setDeadZone(int index,float zone); - + void setDeadZone(int index,float zone); + /** - * Retrieve the number of axes available on this controller. - * + * Retrieve the number of axes available on this controller. + * * @return The number of axes available on this controller. */ - public int getAxisCount(); - + int getAxisCount(); + /** * Get the name that's given to the specified axis - * + * * @param index The index of the axis whose name should be retrieved * @return The name of the specified axis. */ - public String getAxisName(int index); - + String getAxisName(int index); + /** * Retrieve the value thats currently available on a specified axis. The * value will always be between 1.0 and -1.0 and will calibrate as values * are passed read. It may be useful to get the player to wiggle the joystick - * from side to side to get the calibration right. - * + * from side to side to get the calibration right. + * * @param index The index of axis to be read * @return The value from the specified axis. */ - public float getAxisValue(int index); - - /** - * Get the value from the X axis if there is one. If no X axis is - * defined a zero value will be returned. - * - * @return The value from the X axis - */ - public float getXAxisValue(); - - /** - * Get the dead zone for the X axis. - * - * @return The dead zone for the X axis - */ - public float getXAxisDeadZone(); - - /** - * Set the dead zone for the X axis - * - * @param zone The dead zone to use for the X axis - */ - public void setXAxisDeadZone(float zone); + float getAxisValue(int index); /** - * Get the value from the Y axis if there is one. If no Y axis is + * Get the value from the X axis if there is one. If no X axis is * defined a zero value will be returned. - * + * + * @return The value from the X axis + */ + float getXAxisValue(); + + /** + * Get the dead zone for the X axis. + * + * @return The dead zone for the X axis + */ + float getXAxisDeadZone(); + + /** + * Set the dead zone for the X axis + * + * @param zone The dead zone to use for the X axis + */ + void setXAxisDeadZone(float zone); + + /** + * Get the value from the Y axis if there is one. If no Y axis is + * defined a zero value will be returned. + * * @return The value from the Y axis */ - public float getYAxisValue(); - + float getYAxisValue(); + /** * Get the dead zone for the Y axis. - * + * * @return The dead zone for the Y axis */ - public float getYAxisDeadZone(); + float getYAxisDeadZone(); /** * Set the dead zone for the Y axis - * + * * @param zone The dead zone to use for the Y axis */ - public void setYAxisDeadZone(float zone); - + void setYAxisDeadZone(float zone); + /** - * Get the value from the Z axis if there is one. If no Z axis is + * Get the value from the Z axis if there is one. If no Z axis is * defined a zero value will be returned. - * + * * @return The value from the Z axis */ - public float getZAxisValue(); - + float getZAxisValue(); + /** * Get the dead zone for the Z axis. - * + * * @return The dead zone for the Z axis */ - public float getZAxisDeadZone(); + float getZAxisDeadZone(); /** * Set the dead zone for the Z axis - * + * * @param zone The dead zone to use for the Z axis */ - public void setZAxisDeadZone(float zone); - + void setZAxisDeadZone(float zone); + /** - * Get the value from the RX axis if there is one. If no RX axis is + * Get the value from the RX axis if there is one. If no RX axis is * defined a zero value will be returned. - * + * * @return The value from the RX axis */ - public float getRXAxisValue(); - + float getRXAxisValue(); + /** * Get the dead zone for the RX axis. - * + * * @return The dead zone for the RX axis */ - public float getRXAxisDeadZone(); + float getRXAxisDeadZone(); /** * Set the dead zone for the RX axis - * + * * @param zone The dead zone to use for the RX axis */ - public void setRXAxisDeadZone(float zone); - + void setRXAxisDeadZone(float zone); + /** - * Get the value from the RY axis if there is one. If no RY axis is + * Get the value from the RY axis if there is one. If no RY axis is * defined a zero value will be returned. - * + * * @return The value from the RY axis */ - public float getRYAxisValue(); - + float getRYAxisValue(); + /** * Get the dead zone for the RY axis. - * + * * @return The dead zone for the RY axis */ - public float getRYAxisDeadZone(); + float getRYAxisDeadZone(); /** * Set the dead zone for the RY axis - * + * * @param zone The dead zone to use for the RY axis */ - public void setRYAxisDeadZone(float zone); - + void setRYAxisDeadZone(float zone); + /** - * Get the value from the RZ axis if there is one. If no RZ axis is + * Get the value from the RZ axis if there is one. If no RZ axis is * defined a zero value will be returned. - * + * * @return The value from the RZ axis */ - public float getRZAxisValue(); - + float getRZAxisValue(); + /** * Get the dead zone for the RZ axis. - * + * * @return The dead zone for the RZ axis */ - public float getRZAxisDeadZone(); + float getRZAxisDeadZone(); /** * Set the dead zone for the RZ axis - * + * * @param zone The dead zone to use for the RZ axis */ - public void setRZAxisDeadZone(float zone); + void setRZAxisDeadZone(float zone); } diff --git a/src/java/org/lwjgl/input/ControllerEvent.java b/src/java/org/lwjgl/input/ControllerEvent.java index 824036af..e0b114af 100644 --- a/src/java/org/lwjgl/input/ControllerEvent.java +++ b/src/java/org/lwjgl/input/ControllerEvent.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -33,7 +33,7 @@ package org.lwjgl.input; /** * An event occuring on a controller. - * + * * @author Kevin Glass */ class ControllerEvent { @@ -45,7 +45,7 @@ class ControllerEvent { public static final int POVX = 3; /** Indicates the event was caused by a pov Y */ public static final int POVY = 4; - + /** The controller generating the event */ private Controller source; /** The index of the input (axis or button) that generated the event */ @@ -58,10 +58,10 @@ class ControllerEvent { private boolean yaxis; /** The time stamp of this event */ private long timeStamp; - + /** * Create a new event - * + * * @param source The source of the event * @param timeStamp The time stamp given for this event * @param type The type of control generating this event @@ -69,7 +69,7 @@ class ControllerEvent { * @param xaxis True if this event was caused by the x-axis * @param yaxis True if this event was caused by the y-axis */ - public ControllerEvent(Controller source,long timeStamp, int type,int index,boolean xaxis,boolean yaxis) { + ControllerEvent(Controller source,long timeStamp, int type,int index,boolean xaxis,boolean yaxis) { this.source = source; this.timeStamp = timeStamp; this.type = type; @@ -77,38 +77,38 @@ class ControllerEvent { this.xaxis = xaxis; this.yaxis = yaxis; } - + /** * Get the time stamp given for this event. As with nanoTime() * this value means nothing other than giving ordering - * + * * @return The time stamp given for this event */ public long getTimeStamp() { return timeStamp; } - + /** * Get the controller that generated this event - * + * * @return The controller that generated this event */ public Controller getSource() { return source; } - + /** * Get the index of the control generating this event - * + * * @return The index of the control generating this event */ public int getControlIndex() { return index; } - + /** * Check if this event was generated by a button - * + * * @return True if this event was generated by a button */ public boolean isButton() { @@ -117,7 +117,7 @@ class ControllerEvent { /** * Check if this event was generated by a axis - * + * * @return True if this event was generated by a axis */ public boolean isAxis() { @@ -126,25 +126,25 @@ class ControllerEvent { /** * Check if this event was generated by a pov - * + * * @return True if this event was generated by a pov */ public boolean isPovY() { return type == POVY; } /** - * + * * Check if this event was generated by a pov - * + * * @return True if this event was generated by a pov */ public boolean isPovX() { return type == POVX; } - + /** * Check if this event was caused by the X axis - * + * * @return True if this event was caused by the X axis */ public boolean isXAxis() { @@ -153,13 +153,13 @@ class ControllerEvent { /** * Check if this event was caused by the Y axis - * + * * @return True if this event was caused by the Y axis */ public boolean isYAxis() { return yaxis; } - + /* * @see java.lang.Object#toString() */ diff --git a/src/java/org/lwjgl/input/Controllers.java b/src/java/org/lwjgl/input/Controllers.java index 13bca38b..15a80c26 100644 --- a/src/java/org/lwjgl/input/Controllers.java +++ b/src/java/org/lwjgl/input/Controllers.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -39,98 +39,92 @@ import org.lwjgl.LWJGLException; /** * The collection of controllers currently connected. - * + * * @author Kevin Glass */ public class Controllers { /** The controllers available */ - private static ArrayList controllers = new ArrayList(); + private static ArrayList controllers = new ArrayList(); /** The number of controllers */ private static int controllerCount; - + /** The current list of events */ - private static ArrayList events = new ArrayList(); + private static ArrayList events = new ArrayList(); /** The current event */ private static ControllerEvent event; - + /** Whether controllers were created */ private static boolean created; - + /** * Initialise the controllers collection - * + * * @throws LWJGLException Indicates a failure to initialise the controller library. */ public static void create() throws LWJGLException { if (created) return; - + try { ControllerEnvironment env = ControllerEnvironment.getDefaultEnvironment(); - + net.java.games.input.Controller[] found = env.getControllers(); - ArrayList lollers = new ArrayList(); - for (int i=0;i lollers = new ArrayList(); + 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 1 && cursors[index].timeout < System.currentTimeMillis(); } - /** - * Changes to the next cursor + /** + * Changes to the next cursor */ protected void nextCursor() { checkValid(); index = ++index % cursors.length; } - + /** * A single cursor element, used when animating */ private static class CursorElement { /** Handle to cursor */ final Object cursorHandle; - + /** How long a delay this element should have */ final long delay; - + /** Absolute time this element times out */ long timeout; diff --git a/src/java/org/lwjgl/input/JInputController.java b/src/java/org/lwjgl/input/JInputController.java index 2bf740d2..04e4aa53 100644 --- a/src/java/org/lwjgl/input/JInputController.java +++ b/src/java/org/lwjgl/input/JInputController.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -34,13 +34,15 @@ package org.lwjgl.input; import java.util.ArrayList; import net.java.games.input.Component; +import net.java.games.input.Component.Identifier.Axis; +import net.java.games.input.Component.Identifier.Button; import net.java.games.input.Event; import net.java.games.input.EventQueue; /** * A wrapper round a JInput controller that attempts to make the interface * more useable. - * + * * @author Kevin Glass */ class JInputController implements Controller { @@ -49,11 +51,11 @@ class JInputController implements Controller { /** The index that has been assigned to this controller */ private int index; /** The Buttons that have been detected on the JInput controller */ - private ArrayList buttons = new ArrayList(); + private ArrayList buttons = new ArrayList(); /** The Axes that have been detected on the JInput controller */ - private ArrayList axes = new ArrayList(); + private ArrayList axes = new ArrayList(); /** The POVs that have been detected on the JInput controller */ - private ArrayList pov = new ArrayList(); + private ArrayList pov = new ArrayList(); /** The state of the buttons last check */ private boolean[] buttonState; /** The values that were read from the pov last check */ @@ -76,72 +78,72 @@ class JInputController implements Controller { private int ryaxis = -1; /** The index of the RZ axis or -1 if no RZ axis is defined */ private int rzaxis = -1; - + /** * Create a new controller that wraps round a JInput controller and hopefully * makes it easier to use. - * + * * @param index The index this controller has been assigned to * @param target The target JInput controller this class is wrapping */ - public JInputController(int index,net.java.games.input.Controller target) { + JInputController(int index,net.java.games.input.Controller target) { this.target = target; this.index = index; - + Component[] sourceAxes = target.getComponents(); - - for (int i=0;i axesMax[axisIndex]) { axesMax[axisIndex] = Math.abs(value); } - + // normalize the value based on maximum value read in the past value /= axesMax[axisIndex]; // fire event @@ -260,9 +260,7 @@ class JInputController implements Controller { * @see org.lwjgl.input.Controller#getAxisName(int) */ public String getAxisName(int index) { - Component axis = (Component) axes.get(index); - - return axis.getName(); + return axes.get(index).getName(); } /* @@ -279,7 +277,7 @@ class JInputController implements Controller { if (xaxis == -1) { return 0; } - + return getAxisValue(xaxis); } @@ -290,7 +288,7 @@ class JInputController implements Controller { if (yaxis == -1) { return 0; } - + return getAxisValue(yaxis); } @@ -301,7 +299,7 @@ class JInputController implements Controller { if (xaxis == -1) { return 0; } - + return getDeadZone(xaxis); } @@ -312,7 +310,7 @@ class JInputController implements Controller { if (yaxis == -1) { return 0; } - + return getDeadZone(yaxis); } @@ -351,7 +349,7 @@ class JInputController implements Controller { if (zaxis == -1) { return 0; } - + return getAxisValue(zaxis); } @@ -362,7 +360,7 @@ class JInputController implements Controller { if (zaxis == -1) { return 0; } - + return getDeadZone(zaxis); } @@ -380,7 +378,7 @@ class JInputController implements Controller { if (rxaxis == -1) { return 0; } - + return getAxisValue(rxaxis); } @@ -391,7 +389,7 @@ class JInputController implements Controller { if (rxaxis == -1) { return 0; } - + return getDeadZone(rxaxis); } @@ -409,7 +407,7 @@ class JInputController implements Controller { if (ryaxis == -1) { return 0; } - + return getAxisValue(ryaxis); } @@ -420,7 +418,7 @@ class JInputController implements Controller { if (ryaxis == -1) { return 0; } - + return getDeadZone(ryaxis); } @@ -438,7 +436,7 @@ class JInputController implements Controller { if (rzaxis == -1) { return 0; } - + return getAxisValue(rzaxis); } @@ -449,7 +447,7 @@ class JInputController implements Controller { if (rzaxis == -1) { return 0; } - + return getDeadZone(rzaxis); } @@ -467,20 +465,20 @@ class JInputController implements Controller { if (pov.size() == 0) { return 0; } - + float value = povValues[0]; - - if ((value == Component.POV.DOWN_LEFT) || + + if ((value == Component.POV.DOWN_LEFT) || (value == Component.POV.UP_LEFT) || (value == Component.POV.LEFT)) { return -1; } - if ((value == Component.POV.DOWN_RIGHT) || + if ((value == Component.POV.DOWN_RIGHT) || (value == Component.POV.UP_RIGHT) || (value == Component.POV.RIGHT)) { return 1; } - + return 0; } @@ -491,22 +489,22 @@ class JInputController implements Controller { if (pov.size() == 0) { return 0; } - + float value = povValues[0]; - - if ((value == Component.POV.DOWN_LEFT) || + + if ((value == Component.POV.DOWN_LEFT) || (value == Component.POV.DOWN_RIGHT) || (value == Component.POV.DOWN)) { return 1; } - if ((value == Component.POV.UP_LEFT) || + if ((value == Component.POV.UP_LEFT) || (value == Component.POV.UP_RIGHT) || (value == Component.POV.UP)) { return -1; } - + return 0; } - - + + } diff --git a/src/java/org/lwjgl/input/Keyboard.java b/src/java/org/lwjgl/input/Keyboard.java index 01450074..6719d0de 100644 --- a/src/java/org/lwjgl/input/Keyboard.java +++ b/src/java/org/lwjgl/input/Keyboard.java @@ -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 keyMap = new HashMap(253); private static int counter; static { // Use reflection to find out key names - Field[] field = Keyboard.class.getFields(); + Field[] fields = Keyboard.class.getFields(); try { - for (int i = 0; i < field.length; i++) { - if (Modifier.isStatic(field[i].getModifiers()) - && Modifier.isPublic(field[i].getModifiers()) - && Modifier.isFinal(field[i].getModifiers()) - && field[i].getType().equals(int.class) - && field[i].getName().startsWith("KEY_")) { + for ( Field field : fields ) { + if ( Modifier.isStatic(field.getModifiers()) + && Modifier.isPublic(field.getModifiers()) + && Modifier.isFinal(field.getModifiers()) + && field.getType().equals(int.class) + && field.getName().startsWith("KEY_") ) { - int key = field[i].getInt(null); - String name = field[i].getName().substring(4); + int key = field.getInt(null); + String name = field.getName().substring(4); keyName[key] = name; - keyMap.put(name, new Integer(key)); - counter ++; + keyMap.put(name, key); + counter++; } } @@ -355,7 +355,7 @@ public class Keyboard { * Polls the keyboard for its current state. Access the polled values using the * isKeyDown method. * By using this method, it is possible to "miss" keyboard keys if you don't - * poll fast enough. + * poll fast enough. * * To use buffered values, you have to call next for each event you * want to read. You can query which key caused the event by using @@ -426,11 +426,11 @@ public class Keyboard { * @param keyName The key name */ public static synchronized int getKeyIndex(String keyName) { - Integer ret = (Integer) keyMap.get(keyName); + Integer ret = keyMap.get(keyName); if (ret == null) return KEY_NONE; else - return ret.intValue(); + return ret; } /** @@ -531,7 +531,7 @@ public class Keyboard { * Please note that the key code returned is NOT valid against the * current keyboard layout. To get the actual character pressed call * getEventCharacter - * + * * @return The key from the current event */ public static int getEventKey() { @@ -576,7 +576,7 @@ public class Keyboard { } } - private final static class KeyEvent { + private static final class KeyEvent { /** The current keyboard character being examined */ private int character; diff --git a/src/java/org/lwjgl/input/Mouse.java b/src/java/org/lwjgl/input/Mouse.java index 68e02ecb..ed0e2298 100644 --- a/src/java/org/lwjgl/input/Mouse.java +++ b/src/java/org/lwjgl/input/Mouse.java @@ -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 buttonMap = new HashMap(16); /** Lazy initialization */ private static boolean initialized; @@ -135,9 +135,9 @@ public class Mouse { private static boolean isGrabbed; private static InputImplementation implementation; - + /** Whether we need cursor animation emulation */ - private static final boolean emulateCursorAnimation = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS || + private static final boolean emulateCursorAnimation = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS || LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX; private static final boolean allowNegativeMouseCoords = getPrivilegedBoolean("org.lwjgl.input.Mouse.allowNegativeMouseCoords"); @@ -213,7 +213,7 @@ public class Mouse { } } } - + /** * Static initialization */ @@ -224,7 +224,7 @@ public class Mouse { buttonName = new String[16]; for (int i = 0; i < 16; i++) { buttonName[i] = "BUTTON" + i; - buttonMap.put(buttonName[i], new Integer(i)); + buttonMap.put(buttonName[i], i); } initialized = true; @@ -308,7 +308,7 @@ public class Mouse { * Polls the mouse for its current state. Access the polled values using the * get methods. * By using this method, it is possible to "miss" mouse click events if you don't - * poll fast enough. + * poll fast enough. * * To use buffered values, you have to call next for each event you * want to read. You can query which button caused the event by using @@ -401,11 +401,11 @@ public class Mouse { */ public static int getButtonIndex(String buttonName) { synchronized (OpenGLPackageAccess.global_lock) { - Integer ret = (Integer) buttonMap.get(buttonName); + Integer ret = buttonMap.get(buttonName); if (ret == null) return -1; else - return ret.intValue(); + return ret; } } @@ -626,13 +626,13 @@ public class Mouse { // store location mouse was grabbed grab_x = x; grab_y = y; - } + } else if (!grab && grabbed) { // move mouse back to location it was grabbed before ungrabbing if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0) implementation.setCursorPosition(grab_x, grab_y); } - + implementation.grabMouse(grab); // Get latest values from native side poll(); @@ -663,12 +663,12 @@ public class Mouse { /** Gets a boolean property as a privileged action. */ static boolean getPrivilegedBoolean(final String property_name) { - Boolean value = (Boolean)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return new Boolean(Boolean.getBoolean(property_name)); + Boolean value = AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + return Boolean.getBoolean(property_name); } }); - return value.booleanValue(); + return value; } /** diff --git a/src/java/org/lwjgl/input/OpenGLPackageAccess.java b/src/java/org/lwjgl/input/OpenGLPackageAccess.java index c4cb7920..fc21336c 100644 --- a/src/java/org/lwjgl/input/OpenGLPackageAccess.java +++ b/src/java/org/lwjgl/input/OpenGLPackageAccess.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -45,11 +45,11 @@ import java.security.PrivilegedActionException; * package through (privileged) reflection. */ final class OpenGLPackageAccess { - final static Object global_lock; + static final Object global_lock; static { try { - global_lock = AccessController.doPrivileged(new PrivilegedExceptionAction() { + global_lock = AccessController.doPrivileged(new PrivilegedExceptionAction() { 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() { + 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) { diff --git a/src/java/org/lwjgl/openal/AL.java b/src/java/org/lwjgl/openal/AL.java index 7ad452b1..86f0ac48 100644 --- a/src/java/org/lwjgl/openal/AL.java +++ b/src/java/org/lwjgl/openal/AL.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -47,14 +47,14 @@ import org.lwjgl.Sys; */ public final class AL { /** ALCdevice instance. */ - protected static ALCdevice device; + static ALCdevice device; /** Current ALCcontext. */ - protected static ALCcontext context; + static ALCcontext context; /** Have we been created? */ private static boolean created; - + static { Sys.initialize(); } @@ -64,16 +64,14 @@ public final class AL { /** * Native method to create AL instance - * - * @param oalPaths Array of strings containing paths to search for OpenAL library + * + * @param oalPath Path to search for OpenAL library */ private static native void nCreate(String oalPath) throws LWJGLException; - + /** * Native method to create AL instance from the Mac OS X 10.4 OpenAL framework. * It is only defined in the Mac OS X native library. - * - * @param oalPaths Array of strings containing paths to search for OpenAL library */ private static native void nCreateDefault() throws LWJGLException; @@ -81,36 +79,36 @@ public final class AL { * Native method the destroy the AL */ private static native void nDestroy(); - + /** * @return true if AL has been created */ public static boolean isCreated() { return created; - } - + } + /** * Creates an OpenAL instance. Using this constructor will cause OpenAL to * open the device using supplied device argument, and create a context using the context values - * supplied. - * + * supplied. + * * @param deviceArguments Arguments supplied to native device * @param contextFrequency Frequency for mixing output buffer, in units of Hz (Common values include 11025, 22050, and 44100). * @param contextRefresh Refresh intervalls, in units of Hz. - * @param contextSynchronized Flag, indicating a synchronous context.* - */ - public static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized) + * @param contextSynchronized Flag, indicating a synchronous context.* + */ + public static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized) throws LWJGLException { create(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, true); } - + /** * @param openDevice Whether to automatically open the device * @see #create(String, int, int, boolean) */ public static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized, boolean openDevice) throws LWJGLException { - + if (created) throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time."); String libname; @@ -133,14 +131,14 @@ public final class AL { } String[] oalPaths = LWJGLUtil.getLibraryPaths(libname, library_names, AL.class.getClassLoader()); LWJGLUtil.log("Found " + oalPaths.length + " OpenAL paths"); - for (int i = 0; i < oalPaths.length; i++) { + for ( String oalPath : oalPaths ) { try { - nCreate(oalPaths[i]); + nCreate(oalPath); created = true; init(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, openDevice); break; } catch (LWJGLException e) { - LWJGLUtil.log("Failed to load " + oalPaths[i] + ": " + e.getMessage()); + LWJGLUtil.log("Failed to load " + oalPath + ": " + e.getMessage()); } } if (!created && LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) { @@ -157,18 +155,18 @@ public final class AL { try { AL10.initNativeStubs(); ALC10.initNativeStubs(); - + if(openDevice) { device = ALC10.alcOpenDevice(deviceArguments); if (device == null) { throw new LWJGLException("Could not open ALC device"); } - + if (contextFrequency == -1) { context = ALC10.alcCreateContext(device, null); } else { context = ALC10.alcCreateContext(device, - ALCcontext.createAttributeList(contextFrequency, contextRefresh, + ALCcontext.createAttributeList(contextFrequency, contextRefresh, contextSynchronized ? ALC10.ALC_TRUE : ALC10.ALC_FALSE)); } ALC10.alcMakeContextCurrent(context); @@ -177,7 +175,7 @@ public final class AL { destroy(); throw e; } - + ALC11.initialize(); // Load EFX10 native stubs if ALC_EXT_EFX is supported. @@ -197,7 +195,7 @@ public final class AL { * open the default device, and create a context using default values. * This method used to use default values that the OpenAL implementation * chose but this produces unexpected results on some systems; so now - * it defaults to 44100Hz mixing @ 60Hz refresh. + * it defaults to 44100Hz mixing @ 60Hz refresh. */ public static void create() throws LWJGLException { create(null, 44100, 60, false); @@ -228,7 +226,7 @@ public final class AL { } private static native void resetNativeStubs(Class clazz); - + /** * @return handle to the default AL context. */ diff --git a/src/java/org/lwjgl/openal/ALC10.java b/src/java/org/lwjgl/openal/ALC10.java index 45f81b80..d60a5ade 100644 --- a/src/java/org/lwjgl/openal/ALC10.java +++ b/src/java/org/lwjgl/openal/ALC10.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -39,7 +39,7 @@ import org.lwjgl.BufferChecks; import org.lwjgl.LWJGLException; /** - * + * *

* ALC introduces the notion of a Device. A Device can be, depending on the * implementation, a hardware device, or a daemon/OS service/actual server. This @@ -49,19 +49,19 @@ import org.lwjgl.LWJGLException; * implementation, which has to map the available backends to unique device * specifiers (represented as strings). *

- * + * * @author Brian Matzon * @version $Revision: 2286 $ * $Id: ALC.java 2286 2006-03-23 19:32:21 +0000 (to, 23 mar 2006) matzon $ */ public final class ALC10 { - + /** List of active contexts */ - static HashMap contexts = new HashMap(); - + static final HashMap contexts = new HashMap(); + /** List of active devices */ - static HashMap devices = new HashMap(); - + static final HashMap devices = new HashMap(); + /** Bad value */ public static final int ALC_INVALID = 0; @@ -80,7 +80,7 @@ public final class ALC10 { /** Minor version query. */ public static final int ALC_MINOR_VERSION = 0x1001; - /** + /** * The size required for the zero-terminated attributes list, for the current context. **/ public static final int ALC_ATTRIBUTES_SIZE = 0x1002; @@ -116,7 +116,7 @@ public final class ALC10 { public static final int ALC_INVALID_CONTEXT = 0xA002; /** - * A function was called at inappropriate time, or in an inappropriate way, + * A function was called at inappropriate time, or in an inappropriate way, * causing an illegal state. This can be an incompatible ALenum, object ID, * and/or function. */ @@ -129,24 +129,24 @@ public final class ALC10 { public static final int ALC_INVALID_VALUE = 0xA004; /** - * A function could not be completed, because there is not enough + * A function could not be completed, because there is not enough * memory available. */ public static final int ALC_OUT_OF_MEMORY = 0xA005; - + static native void initNativeStubs() throws LWJGLException; - + /** * The application can obtain certain strings from ALC. - * + * * ALC_DEFAULT_DEVICE_SPECIFIER - The specifer string for the default device - * ALC_DEVICE_SPECIFIER - The specifer string for the device + * ALC_DEVICE_SPECIFIER - The specifer string for the device * ALC_EXTENSIONS - The extensions string for diagnostics and printing. * * In addition, printable error message strings are provided for all valid error tokens, * including ALC_NO_ERROR,ALC_INVALID_DEVICE, ALC_INVALID_CONTEXT, * ALC_INVALID_ENUM, ALC_INVALID_VALUE. - * + * * @param pname Property to get * @return String property from device */ @@ -156,7 +156,7 @@ public final class ALC10 { Util.checkALCError(device); return result; } - native static String nalcGetString(long device, int pname); + static native String nalcGetString(long device, int pname); /** * The application can query ALC for information using an integer query function. @@ -164,11 +164,11 @@ public final class ALC10 { * device will generate an ALC_INVALID_DEVICE error. The application has to * specify the size of the destination buffer provided. A null destination or a zero * size parameter will cause ALC to ignore the query. - * + * * ALC_MAJOR_VERSION - Major version query. * ALC_MINOR_VERSION - Minor version query. - * ALC_ATTRIBUTES_SIZE - The size required for the zero-terminated attributes list, - * for the current context. null is an invalid device. null (no current context + * ALC_ATTRIBUTES_SIZE - The size required for the zero-terminated attributes list, + * for the current context. null is an invalid device. null (no current context * for the specified device) is legal. * ALC_ALL_ATTRIBUTES - Expects a destination of ALC_CURRENT_ATTRIBUTES_SIZE, * and provides the attribute list for the current context of the specified device. @@ -183,7 +183,7 @@ public final class ALC10 { nalcGetIntegerv(getDevice(device), pname, integerdata.remaining(), integerdata, integerdata.position()); Util.checkALCError(device); } - native static void nalcGetIntegerv(long device, int pname, int size, Buffer integerdata, int offset); + static native void nalcGetIntegerv(long device, int pname, int size, Buffer integerdata, int offset); /** * The alcOpenDevice function allows the application (i.e. the client program) to @@ -202,18 +202,18 @@ public final class ALC10 { if(device_address != 0) { ALCdevice device = new ALCdevice(device_address); synchronized (ALC10.devices) { - devices.put(new Long(device_address), device); + devices.put(device_address, device); } return device; } return null; } - native static long nalcOpenDevice(String devicename); + static native long nalcOpenDevice(String devicename); /** * The alcCloseDevice function allows the application (i.e. the client program) to * disconnect from a device (i.e. the server). - * + * * If deviceHandle is null or invalid, an ALC_INVALID_DEVICE error will be * generated. Once closed, a deviceHandle is invalid. * @@ -226,15 +226,15 @@ public final class ALC10 { devices.remove(new Long(device.device)); } return result; - + } - native static boolean nalcCloseDevice(long device); + static native boolean nalcCloseDevice(long device); /** * A context is created using alcCreateContext. The device parameter has to be a valid * device. The attribute list can be null, or a zero terminated list of integer pairs * composed of valid ALC attribute tokens and requested values. - * + * * Context creation will fail if the application requests attributes that, by themselves, * can not be provided. Context creation will fail if the combination of specified * attributes can not be provided. Context creation will fail if a specified attribute, or @@ -248,25 +248,25 @@ public final class ALC10 { public static ALCcontext alcCreateContext(ALCdevice device, IntBuffer attrList) { long context_address = nalcCreateContext(getDevice(device), attrList); Util.checkALCError(device); - + if(context_address != 0) { ALCcontext context = new ALCcontext(context_address); synchronized (ALC10.contexts) { - contexts.put(new Long(context_address), context); + contexts.put(context_address, context); device.addContext(context); } return context; } return null; } - native static long nalcCreateContext(long device, IntBuffer attrList); + static native long nalcCreateContext(long device, IntBuffer attrList); /** * To make a Context current with respect to AL Operation (state changes by issueing * commands), alcMakeContextCurrent is used. The context parameter can be null * or a valid context pointer. The operation will apply to the device that the context * was created for. - * + * * For each OS process (usually this means for each application), only one context can * be current at any given time. All AL commands apply to the current context. * Commands that affect objects shared among contexts (e.g. buffers) have side effects @@ -278,7 +278,7 @@ public final class ALC10 { public static int alcMakeContextCurrent(ALCcontext context) { return nalcMakeContextCurrent(getContext(context)); } - native static int nalcMakeContextCurrent(long context); + static native int nalcMakeContextCurrent(long context); /** * The current context is the only context accessible to state changes by AL commands @@ -294,7 +294,7 @@ public final class ALC10 { public static void alcProcessContext(ALCcontext context) { nalcProcessContext(getContext(context)); } - native static void nalcProcessContext(long context); + static native void nalcProcessContext(long context); /** * The application can query for, and obtain an handle to, the current context for the @@ -307,12 +307,12 @@ public final class ALC10 { long context_address = nalcGetCurrentContext(); if(context_address != 0) { synchronized (ALC10.contexts) { - context = (ALCcontext) ALC10.contexts.get(new Long(context_address)); + context = ALC10.contexts.get(context_address); } } return context; } - native static long nalcGetCurrentContext(); + static native long nalcGetCurrentContext(); /** * The application can query for, and obtain an handle to, the device of a given context. @@ -324,19 +324,19 @@ public final class ALC10 { long device_address = nalcGetContextsDevice(getContext(context)); if (device_address != 0) { synchronized (ALC10.devices) { - device = (ALCdevice) ALC10.devices.get(new Long(device_address)); + device = ALC10.devices.get(device_address); } } return device; - } - native static long nalcGetContextsDevice(long context); + } + static native long nalcGetContextsDevice(long context); /** * The application can suspend any context from processing (including the current * one). To indicate that a context should be suspended from processing (i.e. that * internal execution state like offset increments is not supposed to be changed), the * application has to use alcSuspendContext. - * + * * Repeated calls to alcSuspendContext are legal, and do not affect a context that is * already marked as suspended. The default state of a context created by * alcCreateContext is that it is marked as suspended. @@ -346,7 +346,7 @@ public final class ALC10 { public static void alcSuspendContext(ALCcontext context) { nalcSuspendContext(getContext(context)); } - native static void nalcSuspendContext(long context); + static native void nalcSuspendContext(long context); /** * The correct way to destroy a context is to first release it using alcMakeCurrent and @@ -362,15 +362,15 @@ public final class ALC10 { context.setInvalid(); } } - native static void nalcDestroyContext(long context); + static native void nalcDestroyContext(long context); /** * ALC uses the same conventions and mechanisms as AL for error handling. In * particular, ALC does not use conventions derived from X11 (GLX) or Windows * (WGL). The alcGetError function can be used to query ALC errors. - * + * * Error conditions are specific to the device. - * + * * ALC_NO_ERROR - The device handle or specifier does name an accessible driver/server. * ALC_INVALID_DEVICE - The Context argument does not name a valid context. * ALC_INVALID_CONTEXT - The Context argument does not name a valid context. @@ -382,7 +382,7 @@ public final class ALC10 { public static int alcGetError(ALCdevice device) { return nalcGetError(getDevice(device)); } - native static int nalcGetError(long device); + static native int nalcGetError(long device); /** * Verify that a given extension is available for the current context and the device it @@ -398,13 +398,13 @@ public final class ALC10 { Util.checkALCError(device); return result; } - native static boolean nalcIsExtensionPresent(long device, String extName); + static native boolean nalcIsExtensionPresent(long device, String extName); /** * Enumeration/token values are device independend, but tokens defined for * extensions might not be present for a given device. But only the tokens defined * by the AL core are guaranteed. Availability of extension tokens dependends on the ALC extension. - * + * * Specifying a null name parameter will cause an ALC_INVALID_VALUE error. * * @param enumName name of enum to find @@ -415,8 +415,8 @@ public final class ALC10 { Util.checkALCError(device); return result; } - native static int nalcGetEnumValue(long device, String enumName); - + static native int nalcGetEnumValue(long device, String enumName); + static long getDevice(ALCdevice device) { if(device != null) { Util.checkALCValidDevice(device); @@ -424,13 +424,13 @@ public final class ALC10 { } return 0L; } - + static long getContext(ALCcontext context) { if(context != null) { Util.checkALCValidContext(context); return context.context; } return 0L; - } + } } diff --git a/src/java/org/lwjgl/openal/ALC11.java b/src/java/org/lwjgl/openal/ALC11.java index 8aff08d0..ad461298 100644 --- a/src/java/org/lwjgl/openal/ALC11.java +++ b/src/java/org/lwjgl/openal/ALC11.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -41,33 +41,33 @@ import org.lwjgl.LWJGLUtil; /** *

- * The ALC11 class implements features in OpenAL 1.1, specifically + * The ALC11 class implements features in OpenAL 1.1, specifically * ALC methods and properties. *

- * + * * @author Brian Matzon * @see ALC10 * @version $Revision: 2286 $ * $Id: ALC.java 2286 2006-03-23 19:32:21 +0000 (to, 23 mar 2006) matzon $ */ public final class ALC11 { - + public static final int ALC_DEFAULT_ALL_DEVICES_SPECIFIER = 0x1012; public static final int ALC_ALL_DEVICES_SPECIFIER = 0x1013; - + public static final int ALC_CAPTURE_DEVICE_SPECIFIER = 0x310; public static final int ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER = 0x311; public static final int ALC_CAPTURE_SAMPLES = 0x312; - + public static final int ALC_MONO_SOURCES = 0x1010; public static final int ALC_STEREO_SOURCES = 0x1011; - + /** * The alcCaptureOpenDevice function allows the application to connect to a capture * device. To obtain a list of all available capture devices, use getCaptureDevices a list of all * capture devices will be returned. Retrieving ALC_CAPTURE_DEVICE_SPECIFIER with a valid capture device specified will result * in the name of that device being returned as a single string. - * + * * If the function returns null, then no sound driver/device has been found, or the * requested format could not be fulfilled. * The "deviceName" argument is a string that requests a certain device or @@ -82,9 +82,9 @@ public final class ALC11 { * implementation will set up a buffer of at least the requested size. * Specifying a compressed or extension-supplied format may result in failure, even if the * extension is supplied for rendering. - * + * * LWJGL SPECIFIC: the actual created device is managed internally in lwjgl - * + * * @param devicename Name of device to open for capture * @param frequency Frequency of samples to capture * @param format Format of samples to capture @@ -96,18 +96,18 @@ public final class ALC11 { if(device_address != 0) { ALCdevice device = new ALCdevice(device_address); synchronized (ALC10.devices) { - ALC10.devices.put(new Long(device_address), device); + ALC10.devices.put(device_address, device); } return device; } return null; } static native long nalcCaptureOpenDevice( String devicename, int frequency, int format, int buffersize); - + /** * The alcCaptureCloseDevice function allows the application to disconnect from a capture * device. - * + * * The return code will be true or false, indicating success or failure. If * the device is null or invalid, an ALC_INVALID_DEVICE error will be generated. * Once closed, a capture device is invalid. @@ -126,7 +126,7 @@ public final class ALC11 { /** * Once a capture device has been opened via alcCaptureOpenDevice, it is made to start * recording audio via the alcCaptureStart entry point: - * + * * Once started, the device will record audio to an internal ring buffer, the size of which was * specified when opening the device. * The application may query the capture device to discover how much data is currently @@ -137,7 +137,7 @@ public final class ALC11 { nalcCaptureStart(ALC10.getDevice(device)); } static native void nalcCaptureStart(long device); - + /** * If the application doesn't need to capture more audio for an amount of time, they can halt * the device without closing it via the alcCaptureStop entry point. @@ -153,11 +153,11 @@ public final class ALC11 { /** * When the application feels there are enough samples available to process, it can obtain * them from the AL via the alcCaptureSamples entry point. - * + * * The "buffer" argument specifies an application-allocated buffer that can contain at least * "samples" sample frames. The implementation may defer conversion and resampling until * this point. Requesting more sample frames than are currently available is an error. - * + * * @param buffer Buffer to store samples in * @param samples Number of samples to request */ @@ -165,9 +165,9 @@ public final class ALC11 { nalcCaptureSamples(ALC10.getDevice(device), buffer, buffer.position(), samples); } static native void nalcCaptureSamples(long device, ByteBuffer buffer, int position, int samples ); - + static native void initNativeStubs() throws LWJGLException; - + /** * Initializes ALC11, including any extensions * @return true if initialization was successfull @@ -178,18 +178,18 @@ public final class ALC11 { ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MAJOR_VERSION, ib); ib.position(1); ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MINOR_VERSION, ib); - + int major = ib.get(0); int minor = ib.get(1); - - // checking for version 1.x+ + + // checking for version 1.x+ if(major >= 1) { - + // checking for version 1.1+ if(major > 1 || minor >= 1) { ALC11.initNativeStubs(); AL11.initNativeStubs(); - } + } } } catch (LWJGLException le) { LWJGLUtil.log("failed to initialize ALC11: " + le); diff --git a/src/java/org/lwjgl/openal/ALCcontext.java b/src/java/org/lwjgl/openal/ALCcontext.java index 52441ac2..2d99d4c1 100644 --- a/src/java/org/lwjgl/openal/ALCcontext.java +++ b/src/java/org/lwjgl/openal/ALCcontext.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -37,7 +37,7 @@ import org.lwjgl.BufferUtils; /** * The ALCcontext class represents a context opened in OpenAL space. - * + * * All operations of the AL core API affect a current AL context. Within the scope of AL, * the ALC is implied - it is not visible as a handle or function parameter. Only one AL * Context per process can be current at a time. Applications maintaining multiple AL @@ -53,13 +53,13 @@ public final class ALCcontext { /** Address of actual context */ final long context; - + /** Whether this context is valid */ - private boolean valid = false; - - /** - * Creates a new instance of ALCcontext - * + private boolean valid; + + /** + * Creates a new instance of ALCcontext + * * @param context address of actual context */ ALCcontext(long context) { @@ -97,19 +97,19 @@ public final class ALCcontext { return attribList; } - + /** * Marks this context as invalid * */ void setInvalid() { valid = false; - } - + } + /** * @return true if this context is still valid */ public boolean isValid() { return valid; - } + } } diff --git a/src/java/org/lwjgl/openal/ALCdevice.java b/src/java/org/lwjgl/openal/ALCdevice.java index c98bbaaf..73bc98fc 100644 --- a/src/java/org/lwjgl/openal/ALCdevice.java +++ b/src/java/org/lwjgl/openal/ALCdevice.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -36,7 +36,7 @@ import java.util.Iterator; /** * The ALCdevice class represents a device opened in OpenAL space. - * + * * ALC introduces the notion of a Device. A Device can be, depending on the * implementation, a hardware device, or a daemon/OS service/actual server. This * mechanism also permits different drivers (and hardware) to coexist within the same @@ -49,18 +49,18 @@ import java.util.Iterator; * $Id$ */ public final class ALCdevice { - + /** Address of actual device */ final long device; - + /** Whether this device is valid */ - private boolean valid = false; - + private boolean valid; + /** List of contexts belonging to the device */ - private HashMap contexts = new HashMap(); - - /** - * Creates a new instance of ALCdevice + private final HashMap contexts = new HashMap(); + + /** + * Creates a new instance of ALCdevice * * @param device address of actual device */ @@ -68,7 +68,7 @@ public final class ALCdevice { this.device = device; this.valid = true; } - + /* * @see java.lang.Object#equals(java.lang.Object) */ @@ -78,28 +78,28 @@ public final class ALCdevice { } return super.equals(device); } - + /** * Adds a context to the device - * + * * @param context context to add to the list of contexts for this device */ void addContext(ALCcontext context) { synchronized (contexts) { - contexts.put(new Long(context.context), context); + contexts.put(context.context, context); } } - + /** * Remove context associated with device - * + * * @param context Context to disassociate with device */ void removeContext(ALCcontext context) { synchronized (contexts) { - contexts.remove(new Long(context.context)); - } - } + contexts.remove(context.context); + } + } /** * Marks this device and all of its contexts invalid @@ -107,14 +107,12 @@ public final class ALCdevice { void setInvalid() { valid = false; synchronized (contexts) { - for(Iterator i = contexts.values().iterator(); i.hasNext();) { - ALCcontext context = (ALCcontext) i.next(); + for ( ALCcontext context : contexts.values() ) context.setInvalid(); - } } contexts.clear(); - } - + } + /** * @return true if this device is still valid */ diff --git a/src/java/org/lwjgl/openal/EFXUtil.java b/src/java/org/lwjgl/openal/EFXUtil.java index 1c14959c..bf1c23b2 100644 --- a/src/java/org/lwjgl/openal/EFXUtil.java +++ b/src/java/org/lwjgl/openal/EFXUtil.java @@ -1,36 +1,39 @@ -/* +/* * Copyright (c) 2002-2010 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.openal; +import static org.lwjgl.openal.AL10.*; +import static org.lwjgl.openal.EFX10.*; + /** * Utility class for the OpenAL extension ALC_EXT_EFX. Provides functions to check for the extension * and support of various effects and filters. @@ -62,7 +65,7 @@ public final class EFXUtil { if (!AL.isCreated()) { throw new OpenALException("OpenAL has not been created."); } - return ALC10.alcIsExtensionPresent(AL.getDevice(), EFX10.ALC_EXT_EFX_NAME); + return ALC10.alcIsExtensionPresent(AL.getDevice(), ALC_EXT_EFX_NAME); } /** @@ -78,20 +81,20 @@ public final class EFXUtil { public static boolean isEffectSupported(final int effectType) { // Make sure type is a real effect. switch (effectType) { - case EFX10.AL_EFFECT_NULL: - case EFX10.AL_EFFECT_EAXREVERB: - case EFX10.AL_EFFECT_REVERB: - case EFX10.AL_EFFECT_CHORUS: - case EFX10.AL_EFFECT_DISTORTION: - case EFX10.AL_EFFECT_ECHO: - case EFX10.AL_EFFECT_FLANGER: - case EFX10.AL_EFFECT_FREQUENCY_SHIFTER: - case EFX10.AL_EFFECT_VOCAL_MORPHER: - case EFX10.AL_EFFECT_PITCH_SHIFTER: - case EFX10.AL_EFFECT_RING_MODULATOR: - case EFX10.AL_EFFECT_AUTOWAH: - case EFX10.AL_EFFECT_COMPRESSOR: - case EFX10.AL_EFFECT_EQUALIZER: + case AL_EFFECT_NULL: + case AL_EFFECT_EAXREVERB: + case AL_EFFECT_REVERB: + case AL_EFFECT_CHORUS: + case AL_EFFECT_DISTORTION: + case AL_EFFECT_ECHO: + case AL_EFFECT_FLANGER: + case AL_EFFECT_FREQUENCY_SHIFTER: + case AL_EFFECT_VOCAL_MORPHER: + case AL_EFFECT_PITCH_SHIFTER: + case AL_EFFECT_RING_MODULATOR: + case AL_EFFECT_AUTOWAH: + case AL_EFFECT_COMPRESSOR: + case AL_EFFECT_EQUALIZER: break; default: throw new IllegalArgumentException("Unknown or invalid effect type: " + effectType); @@ -113,10 +116,10 @@ public final class EFXUtil { public static boolean isFilterSupported(final int filterType) { // Make sure type is a real filter. switch (filterType) { - case EFX10.AL_FILTER_NULL: - case EFX10.AL_FILTER_LOWPASS: - case EFX10.AL_FILTER_HIGHPASS: - case EFX10.AL_FILTER_BANDPASS: + case AL_FILTER_NULL: + case AL_FILTER_LOWPASS: + case AL_FILTER_HIGHPASS: + case AL_FILTER_BANDPASS: break; default: throw new IllegalArgumentException("Unknown or invalid filter type: " + filterType); @@ -148,54 +151,54 @@ public final class EFXUtil { if (isEfxSupported()) { // Try to create object in order to check AL's response. - AL10.alGetError(); + alGetError(); int genError; int testObject = 0; try { switch (objectType) { // Create object based on type case EFFECT: - testObject = EFX10.alGenEffects(); + testObject = alGenEffects(); break; case FILTER: - testObject = EFX10.alGenFilters(); + testObject = alGenFilters(); break; default: throw new IllegalArgumentException("Invalid objectType: " + objectType); } - genError = AL10.alGetError(); + genError = alGetError(); } catch (final OpenALException debugBuildException) { // Hack because OpenALException hides the original error code (short of parsing the // error message String which would break if it gets changed). if (debugBuildException.getMessage().contains("AL_OUT_OF_MEMORY")) { - genError = AL10.AL_OUT_OF_MEMORY; + genError = AL_OUT_OF_MEMORY; } else { - genError = AL10.AL_INVALID_OPERATION; + genError = AL_INVALID_OPERATION; } } - if (genError == AL10.AL_NO_ERROR) { + if (genError == AL_NO_ERROR) { // Successfully created, now try to set type. - AL10.alGetError(); + alGetError(); int setError; try { switch (objectType) { // Set based on object type case EFFECT: - EFX10.alEffecti(testObject, EFX10.AL_EFFECT_TYPE, typeValue); + alEffecti(testObject, AL_EFFECT_TYPE, typeValue); break; case FILTER: - EFX10.alFilteri(testObject, EFX10.AL_FILTER_TYPE, typeValue); + alFilteri(testObject, AL_FILTER_TYPE, typeValue); break; default: throw new IllegalArgumentException("Invalid objectType: " + objectType); } - setError = AL10.alGetError(); + setError = alGetError(); } catch (final OpenALException debugBuildException) { // Hack because OpenALException hides the original error code (short of parsing // the error message String which would break when it gets changed). - setError = AL10.AL_INVALID_VALUE; + setError = AL_INVALID_VALUE; } - if (setError == AL10.AL_NO_ERROR) { + if (setError == AL_NO_ERROR) { supported = true; } @@ -203,10 +206,10 @@ public final class EFXUtil { try { switch (objectType) { // Set based on object type case EFFECT: - EFX10.alDeleteEffects(testObject); + alDeleteEffects(testObject); break; case FILTER: - EFX10.alDeleteFilters(testObject); + alDeleteFilters(testObject); break; default: throw new IllegalArgumentException("Invalid objectType: " + objectType); @@ -215,7 +218,7 @@ public final class EFXUtil { // Don't care about cleanup errors. } - } else if (genError == AL10.AL_OUT_OF_MEMORY) { + } else if (genError == AL_OUT_OF_MEMORY) { throw new OpenALException(genError); } } diff --git a/src/java/org/lwjgl/opencl/APIUtil.java b/src/java/org/lwjgl/opencl/APIUtil.java index e53edf87..76bdf098 100644 --- a/src/java/org/lwjgl/opencl/APIUtil.java +++ b/src/java/org/lwjgl/opencl/APIUtil.java @@ -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 DESTRUCTOR_CLSubDevice = new ObjectDestructor() { - public void release(final CLDevice object) { EXTDeviceFission.clReleaseDeviceEXT(object); } - }; - private static final ObjectDestructor DESTRUCTOR_CLMem = new ObjectDestructor() { - public void release(final CLMem object) { CL10.clReleaseMemObject(object); } - }; - private static final ObjectDestructor DESTRUCTOR_CLCommandQueue = new ObjectDestructor() { - public void release(final CLCommandQueue object) { CL10.clReleaseCommandQueue(object); } - }; - private static final ObjectDestructor DESTRUCTOR_CLSampler = new ObjectDestructor() { - public void release(final CLSampler object) { CL10.clReleaseSampler(object); } - }; - private static final ObjectDestructor DESTRUCTOR_CLProgram = new ObjectDestructor() { - public void release(final CLProgram object) { CL10.clReleaseProgram(object); } - }; - private static final ObjectDestructor DESTRUCTOR_CLKernel = new ObjectDestructor() { - public void release(final CLKernel object) { CL10.clReleaseKernel(object); } - }; - private static final ObjectDestructor DESTRUCTOR_CLEvent = new ObjectDestructor() { - 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 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 getExtensions(final String extensionList) { - final Set extensions = new HashSet(); - - final StringTokenizer tokenizer = new StringTokenizer(extensionList); - while ( tokenizer.hasMoreTokens() ) - extensions.add(tokenizer.nextToken()); - - return extensions; - } - - private static void releaseObjects(final CLObjectRegistry registry, final ObjectDestructor destructor) { - if ( registry.isEmpty() ) - return; - - for ( final T object : registry.getAll() ) { - while ( object.isValid() ) - destructor.release(object); - } - } - - private interface ObjectDestructor { - - 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 getExtensions(final String extensionList) { + final Set extensions = new HashSet(); + + 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 void releaseObjects(final CLObjectRegistry registry, final ObjectDestructor destructor) { + if ( registry.isEmpty() ) + return; + + for ( final T object : registry.getAll() ) { + while ( object.isValid() ) + destructor.release(object); + } + } + + private static final ObjectDestructor DESTRUCTOR_CLSubDevice = new ObjectDestructor() { + public void release(final CLDevice object) { EXTDeviceFission.clReleaseDeviceEXT(object); } + }; + private static final ObjectDestructor DESTRUCTOR_CLMem = new ObjectDestructor() { + public void release(final CLMem object) { CL10.clReleaseMemObject(object); } + }; + private static final ObjectDestructor DESTRUCTOR_CLCommandQueue = new ObjectDestructor() { + public void release(final CLCommandQueue object) { CL10.clReleaseCommandQueue(object); } + }; + private static final ObjectDestructor DESTRUCTOR_CLSampler = new ObjectDestructor() { + public void release(final CLSampler object) { CL10.clReleaseSampler(object); } + }; + private static final ObjectDestructor DESTRUCTOR_CLProgram = new ObjectDestructor() { + public void release(final CLProgram object) { CL10.clReleaseProgram(object); } + }; + private static final ObjectDestructor DESTRUCTOR_CLKernel = new ObjectDestructor() { + public void release(final CLKernel object) { CL10.clReleaseKernel(object); } + }; + private static final ObjectDestructor DESTRUCTOR_CLEvent = new ObjectDestructor() { + public void release(final CLEvent object) { CL10.clReleaseEvent(object); } + }; + + private interface ObjectDestructor { + + void release(T object); + + } + } \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/APPLEContextLoggingUtil.java b/src/java/org/lwjgl/opencl/APPLEContextLoggingUtil.java index f69284d6..9f62741e 100644 --- a/src/java/org/lwjgl/opencl/APPLEContextLoggingUtil.java +++ b/src/java/org/lwjgl/opencl/APPLEContextLoggingUtil.java @@ -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(); } }; diff --git a/src/java/org/lwjgl/opencl/CL.java b/src/java/org/lwjgl/opencl/CL.java index 981d6c19..794da740 100644 --- a/src/java/org/lwjgl/opencl/CL.java +++ b/src/java/org/lwjgl/opencl/CL.java @@ -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); } \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java b/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java index 0da9c7b0..40563572 100644 --- a/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java +++ b/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java @@ -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. * diff --git a/src/java/org/lwjgl/opencl/CLChecks.java b/src/java/org/lwjgl/opencl/CLChecks.java index c1606fff..26d9365d 100644 --- a/src/java/org/lwjgl/opencl/CLChecks.java +++ b/src/java/org/lwjgl/opencl/CLChecks.java @@ -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)); } } diff --git a/src/java/org/lwjgl/opencl/CLCommandQueue.java b/src/java/org/lwjgl/opencl/CLCommandQueue.java index f972b00e..f4e02ed1 100644 --- a/src/java/org/lwjgl/opencl/CLCommandQueue.java +++ b/src/java/org/lwjgl/opencl/CLCommandQueue.java @@ -40,6 +40,8 @@ import org.lwjgl.PointerBuffer; */ public final class CLCommandQueue extends CLObjectChild { + private static final InfoUtil util = CLPlatform.getInfoUtilInstance(CLCommandQueue.class, "CL_COMMAND_QUEUE_UTIL"); + private final CLDevice device; private final CLObjectRegistry clEvents; @@ -71,6 +73,19 @@ public final class CLCommandQueue extends CLObjectChild { 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 getCLEventRegistry() { return clEvents; } diff --git a/src/java/org/lwjgl/opencl/CLContext.java b/src/java/org/lwjgl/opencl/CLContext.java index d36c9466..369dfdf2 100644 --- a/src/java/org/lwjgl/opencl/CLContext.java +++ b/src/java/org/lwjgl/opencl/CLContext.java @@ -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 { + + private static final CLContextUtil util = (CLContextUtil)CLPlatform.getInfoUtilInstance(CLContext.class, "CL_CONTEXT_UTIL"); private final CLObjectRegistry clCommandQueues; private final CLObjectRegistry clMems; @@ -48,13 +51,16 @@ public final class CLContext extends CLObject { private final CLObjectRegistry clEvents; /** Global registry for build callbacks. */ - static Map clProgramsGlobal = new HashMap(); + static final Map clProgramsGlobal = new HashMap(); /** Global registry for event callbacks. */ - static Map clEventsGlobal = new HashMap(); + static final Map clEventsGlobal = new HashMap(); - 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(); @@ -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 getInfoDevices() { + return util.getInfoDevices(this); + } + + /** CLContext utility methods interface. */ + interface CLContextUtil extends InfoUtil { + + List getInfoDevices(CLContext context); + + } + // -------[ IMPLEMENTATION STUFF BELOW ]------- CLObjectRegistry getCLCommandQueueRegistry() { return clCommandQueues; } diff --git a/src/java/org/lwjgl/opencl/CLDevice.java b/src/java/org/lwjgl/opencl/CLDevice.java index a978b1c1..b9130bf8 100644 --- a/src/java/org/lwjgl/opencl/CLDevice.java +++ b/src/java/org/lwjgl/opencl/CLDevice.java @@ -40,14 +40,15 @@ import org.lwjgl.PointerBuffer; */ public final class CLDevice extends CLObjectChild { - private static final CLDeviceImpl impl = (CLDeviceImpl)CLPlatform.getClassInstance("org.lwjgl.opencl.CLDeviceImpl"); + private static final InfoUtil util = CLPlatform.getInfoUtilInstance(CLDevice.class, "CL_DEVICE_UTIL"); + private final CLPlatform platform; private final CLObjectRegistry 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 { * @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(); + this.platform = platform; + platform.getCLDeviceRegistry().registerObject(this); + + this.subCLDevices = new CLObjectRegistry(); 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 { */ 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 { } } - // ---------------[ 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); - } - } \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/CLDeviceImpl.java b/src/java/org/lwjgl/opencl/CLDeviceImpl.java deleted file mode 100644 index 26e5d15a..00000000 --- a/src/java/org/lwjgl/opencl/CLDeviceImpl.java +++ /dev/null @@ -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); - } -} \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/CLEvent.java b/src/java/org/lwjgl/opencl/CLEvent.java index d5dc6b13..9e98acd6 100644 --- a/src/java/org/lwjgl/opencl/CLEvent.java +++ b/src/java/org/lwjgl/opencl/CLEvent.java @@ -38,6 +38,8 @@ package org.lwjgl.opencl; */ public final class CLEvent extends CLObjectChild { + 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 { 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 { + + long getProfilingInfoLong(CLEvent event, int param_name); + + } + + // -------[ IMPLEMENTATION STUFF BELOW ]------- + int release() { try { return super.release(); diff --git a/src/java/org/lwjgl/opencl/CLKernel.java b/src/java/org/lwjgl/opencl/CLKernel.java index 6b272260..83525f61 100644 --- a/src/java/org/lwjgl/opencl/CLKernel.java +++ b/src/java/org/lwjgl/opencl/CLKernel.java @@ -40,7 +40,7 @@ import org.lwjgl.PointerWrapper; */ public final class CLKernel extends CLObjectChild { - 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 { 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 { + + 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 { } } - 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); - - } - } \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/CLMem.java b/src/java/org/lwjgl/opencl/CLMem.java index e94cf7da..1e3f2fb0 100644 --- a/src/java/org/lwjgl/opencl/CLMem.java +++ b/src/java/org/lwjgl/opencl/CLMem.java @@ -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 { + 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 { + + 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 ) diff --git a/src/java/org/lwjgl/opencl/CLObject.java b/src/java/org/lwjgl/opencl/CLObject.java index 3377456c..72fc9c32 100644 --- a/src/java/org/lwjgl/opencl/CLObject.java +++ b/src/java/org/lwjgl/opencl/CLObject.java @@ -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; } } \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/CLObjectChild.java b/src/java/org/lwjgl/opencl/CLObjectChild.java index c3b8b219..bebefd16 100644 --- a/src/java/org/lwjgl/opencl/CLObjectChild.java +++ b/src/java/org/lwjgl/opencl/CLObjectChild.java @@ -38,11 +38,11 @@ import org.lwjgl.LWJGLUtil; * * @author Spasi */ -abstract class CLObjectChild

extends CLObject { +abstract class CLObjectChild

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() ) diff --git a/src/java/org/lwjgl/opencl/CLObjectRegistry.java b/src/java/org/lwjgl/opencl/CLObjectRegistry.java index 0641983e..4c35419d 100644 --- a/src/java/org/lwjgl/opencl/CLObjectRegistry.java +++ b/src/java/org/lwjgl/opencl/CLObjectRegistry.java @@ -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 { final Map 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) { diff --git a/src/java/org/lwjgl/opencl/CLKernelImpl.java b/src/java/org/lwjgl/opencl/CLObjectRetainable.java similarity index 53% rename from src/java/org/lwjgl/opencl/CLKernelImpl.java rename to src/java/org/lwjgl/opencl/CLObjectRetainable.java index fc2f3695..7c6b4a9b 100644 --- a/src/java/org/lwjgl/opencl/CLKernelImpl.java +++ b/src/java/org/lwjgl/opencl/CLObjectRetainable.java @@ -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; } } \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/CLPlatform.java b/src/java/org/lwjgl/opencl/CLPlatform.java index 65880a15..35f70e5a 100644 --- a/src/java/org/lwjgl/opencl/CLPlatform.java +++ b/src/java/org/lwjgl/opencl/CLPlatform.java @@ -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 clPlatforms = new HashMap(); + + private final CLObjectRegistry clDevices; + + /** Global registry for build callbacks. */ + static final Map clDevicesGlobal = new HashMap(); private Object caps; - public CLPlatform(final long pointer) { + CLPlatform(final long pointer) { super(pointer); + + if ( isValid() ) { + clPlatforms.put(pointer, this); + clDevices = new CLObjectRegistryGlobal(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 InfoUtil getInfoUtilInstance(final Class clazz, final String fieldName) { + InfoUtil instance = null; + try { + final Class infoUtil = Class.forName("org.lwjgl.opencl.InfoUtilFactory"); + instance = (InfoUtil)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 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 getPlatforms(final Filter 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 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 getDevices(final int device_type, final Filter filter) { + return util.getDevices(this, device_type, filter); + } + + /** CLPlatform utility methods interface. */ + interface CLPlatformUtil extends InfoUtil { + + List getPlatforms(Filter filter); + + List getDevices(CLPlatform platform, int device_type, final Filter 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 getPlatforms() { - return getPlatforms(null); + CLObjectRegistry getCLDeviceRegistry() { return clDevices; } + + static CLDevice getCLDeviceGlobal(final long id) { return clDevicesGlobal.get(id); } + + /** + * Called from clGetDeviceIDs 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 getPlatforms(final Filter filter) { - return impl.getPlatforms(filter); - } - - public String getInfoString(int param_name) { - return impl.getInfoString(this, param_name); - } - - public List getDevices(final int device_type) { - return getDevices(device_type, null); - } - - public List getDevices(final int device_type, final Filter filter) { - return impl.getDevices(this, device_type, filter); - } - - /** CLPlatform helper methods implementation interface. */ - interface CLPlatformImpl { - - List getPlatforms(Filter filter); - - String getInfoString(CLPlatform platform, int param_name); - - List getDevices(CLPlatform platform, int device_type, final Filter filter); - + /** + * Called from clGetContextInfo 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); + } } } \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/CLPlatformImpl.java b/src/java/org/lwjgl/opencl/CLPlatformImpl.java deleted file mode 100644 index 967a0b4e..00000000 --- a/src/java/org/lwjgl/opencl/CLPlatformImpl.java +++ /dev/null @@ -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 getPlatforms(final Filter 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 platforms = new ArrayList(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 getDevices(final CLPlatform platform, final int device_type, final Filter 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 devices = new ArrayList(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; - } - -} \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/CLProgram.java b/src/java/org/lwjgl/opencl/CLProgram.java index f50d4e56..57bf853f 100644 --- a/src/java/org/lwjgl/opencl/CLProgram.java +++ b/src/java/org/lwjgl/opencl/CLProgram.java @@ -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 { + private static final CLProgramUtil util = (CLProgramUtil)CLPlatform.getInfoUtilInstance(CLProgram.class, "CL_PROGRAM_UTIL"); + private final CLObjectRegistry clKernels; CLProgram(final long pointer, final CLContext context) { @@ -65,6 +67,119 @@ public final class CLProgram extends CLObjectChild { 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 target + * 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 target 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 { + + 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 getCLKernelRegistry() { return clKernels; } diff --git a/src/java/org/lwjgl/opencl/CLSampler.java b/src/java/org/lwjgl/opencl/CLSampler.java index 2b25d674..6408b669 100644 --- a/src/java/org/lwjgl/opencl/CLSampler.java +++ b/src/java/org/lwjgl/opencl/CLSampler.java @@ -38,12 +38,41 @@ package org.lwjgl.opencl; */ public final class CLSampler extends CLObjectChild { + private static final InfoUtil 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(); diff --git a/src/java/org/lwjgl/opencl/InfoUtil.java b/src/java/org/lwjgl/opencl/InfoUtil.java new file mode 100644 index 00000000..c7cc060e --- /dev/null +++ b/src/java/org/lwjgl/opencl/InfoUtil.java @@ -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 { + + 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); + +} \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/InfoUtilAbstract.java b/src/java/org/lwjgl/opencl/InfoUtilAbstract.java new file mode 100644 index 00000000..b28d457e --- /dev/null +++ b/src/java/org/lwjgl/opencl/InfoUtilAbstract.java @@ -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 implements InfoUtil { + + 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); + } + +} \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/InfoUtilFactory.java b/src/java/org/lwjgl/opencl/InfoUtilFactory.java new file mode 100644 index 00000000..d73726ca --- /dev/null +++ b/src/java/org/lwjgl/opencl/InfoUtilFactory.java @@ -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 CL_COMMAND_QUEUE_UTIL = new InfoUtilAbstract() { + 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 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 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 devices = new ArrayList(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 CL_DEVICE_UTIL = new CLDeviceUtil(); + private static final class CLDeviceUtil extends InfoUtilAbstract { + + 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 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 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 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 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 getPlatforms(final Filter 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 platforms = new ArrayList(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 getDevices(final CLPlatform platform, final int device_type, final Filter 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 devices = new ArrayList(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 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 CL_SAMPLER_UTIL = new InfoUtilAbstract() { + 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); + } + }; + +} \ No newline at end of file diff --git a/src/java/org/lwjgl/opencl/Util.java b/src/java/org/lwjgl/opencl/Util.java index 848b5357..dd300823 100644 --- a/src/java/org/lwjgl/opencl/Util.java +++ b/src/java/org/lwjgl/opencl/Util.java @@ -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) + ")"); } } \ No newline at end of file diff --git a/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java b/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java index 1146839c..4fcaa653 100644 --- a/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java +++ b/src/java/org/lwjgl/opengl/AMDDebugOutputCallback.java @@ -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 { diff --git a/src/java/org/lwjgl/opengl/APIUtil.java b/src/java/org/lwjgl/opengl/APIUtil.java index d3584317..526cbd5e 100644 --- a/src/java/org/lwjgl/opengl/APIUtil.java +++ b/src/java/org/lwjgl/opengl/APIUtil.java @@ -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 arrayTL = new ThreadLocal() { + 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 bufferTL = new ThreadLocal() { + 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 lengthsTL = new ThreadLocal() { + 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 infiniteSeqTL = new ThreadLocal() { + protected InfiniteCharSequence initialValue() { return new InfiniteCharSequence(); } }; - private static final ThreadLocal buffersTL = new ThreadLocal() { - protected Object initialValue() { return new Buffers(); } + private static final ThreadLocal buffersTL = new ThreadLocal() { + 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; diff --git a/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java b/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java index 2602d5b2..e1b02dd5 100644 --- a/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java +++ b/src/java/org/lwjgl/opengl/ARBDebugOutputCallback.java @@ -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 { diff --git a/src/java/org/lwjgl/opengl/AWTGLCanvas.java b/src/java/org/lwjgl/opengl/AWTGLCanvas.java index d5e433d8..2a694881 100644 --- a/src/java/org/lwjgl/opengl/AWTGLCanvas.java +++ b/src/java/org/lwjgl/opengl/AWTGLCanvas.java @@ -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(); diff --git a/src/java/org/lwjgl/opengl/AWTSurfaceLock.java b/src/java/org/lwjgl/opengl/AWTSurfaceLock.java index 8d5927ee..d2450ce9 100644 --- a/src/java/org/lwjgl/opengl/AWTSurfaceLock.java +++ b/src/java/org/lwjgl/opengl/AWTSurfaceLock.java @@ -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() { + public Boolean run() throws LWJGLException { + return lockAndInitHandle(lock_buffer, component); } }); - firstLockSucceeded = ((Boolean) result).booleanValue(); return firstLockSucceeded; } catch (PrivilegedActionException e) { throw (LWJGLException) e.getException(); diff --git a/src/java/org/lwjgl/opengl/AWTUtil.java b/src/java/org/lwjgl/opengl/AWTUtil.java index 11855231..2e81cea2 100644 --- a/src/java/org/lwjgl/opengl/AWTUtil.java +++ b/src/java/org/lwjgl/opengl/AWTUtil.java @@ -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() { + 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() { + public PointerInfo run() throws Exception { return MouseInfo.getPointerInfo(); } }); diff --git a/src/java/org/lwjgl/opengl/BaseReferences.java b/src/java/org/lwjgl/opengl/BaseReferences.java index 7058cce6..e2fa56d5 100644 --- a/src/java/org/lwjgl/opengl/BaseReferences.java +++ b/src/java/org/lwjgl/opengl/BaseReferences.java @@ -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; } diff --git a/src/java/org/lwjgl/opengl/CallbackUtil.java b/src/java/org/lwjgl/opengl/CallbackUtil.java index 728ece3e..0c938e75 100644 --- a/src/java/org/lwjgl/opengl/CallbackUtil.java +++ b/src/java/org/lwjgl/opengl/CallbackUtil.java @@ -42,9 +42,9 @@ import java.util.Map; final class CallbackUtil { /** Context -> Long */ - private static final Map contextUserParamsARB = new HashMap(); + private static final Map contextUserParamsARB = new HashMap(); /** Context -> Long */ - private static final Map contextUserParamsAMD = new HashMap(); + private static final Map contextUserParamsAMD = new HashMap(); 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 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 ] --------- diff --git a/src/java/org/lwjgl/opengl/Context.java b/src/java/org/lwjgl/opengl/Context.java index fa9d0074..d0147cae 100644 --- a/src/java/org/lwjgl/opengl/Context.java +++ b/src/java/org/lwjgl/opengl/Context.java @@ -40,6 +40,8 @@ import org.lwjgl.opencl.KHRGLSharing; import java.nio.ByteBuffer; import java.nio.IntBuffer; +import static org.lwjgl.opengl.GL11.*; + /** *

* 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 current_context_local = new ThreadLocal(); /** 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); } diff --git a/src/java/org/lwjgl/opengl/ContextAttribs.java b/src/java/org/lwjgl/opengl/ContextAttribs.java index c87e39ff..552a1bbb 100644 --- a/src/java/org/lwjgl/opengl/ContextAttribs.java +++ b/src/java/org/lwjgl/opengl/ContextAttribs.java @@ -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); diff --git a/src/java/org/lwjgl/opengl/Display.java b/src/java/org/lwjgl/opengl/Display.java index e90db80c..d3f7042c 100644 --- a/src/java/org/lwjgl/opengl/Display.java +++ b/src/java/org/lwjgl/opengl/Display.java @@ -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 modes = new HashSet(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() { 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() { 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() { + public Boolean run() { + return Boolean.getBoolean(property_name); } }); - return value.booleanValue(); } private static void initControls() { diff --git a/src/java/org/lwjgl/opengl/DisplayMode.java b/src/java/org/lwjgl/opengl/DisplayMode.java index 372e2ed5..822c15d3 100644 --- a/src/java/org/lwjgl/opengl/DisplayMode.java +++ b/src/java/org/lwjgl/opengl/DisplayMode.java @@ -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); diff --git a/src/java/org/lwjgl/opengl/GLChecks.java b/src/java/org/lwjgl/opengl/GLChecks.java index e06654b0..3bcf6e6f 100644 --- a/src/java/org/lwjgl/opengl/GLChecks.java +++ b/src/java/org/lwjgl/opengl/GLChecks.java @@ -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 : diff --git a/src/java/org/lwjgl/opengl/GLContext.java b/src/java/org/lwjgl/opengl/GLContext.java index c3f0d591..c363b731 100644 --- a/src/java/org/lwjgl/opengl/GLContext.java +++ b/src/java/org/lwjgl/opengl/GLContext.java @@ -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.*; + /** *

* 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 current_capabilities = new ThreadLocal(); /** * 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 thread_cache_entries = new ThreadLocal(); /** * 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 capability_cache = new WeakHashMap(); /** 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() { + 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 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() { 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; diff --git a/src/java/org/lwjgl/opengl/GLUConstants.java b/src/java/org/lwjgl/opengl/GLUConstants.java index e836796d..ac93f9ee 100644 --- a/src/java/org/lwjgl/opengl/GLUConstants.java +++ b/src/java/org/lwjgl/opengl/GLUConstants.java @@ -31,6 +31,8 @@ */ package org.lwjgl.opengl; +import static org.lwjgl.opengl.GL11.*; + /** *

* 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; } diff --git a/src/java/org/lwjgl/opengl/GlobalLock.java b/src/java/org/lwjgl/opengl/GlobalLock.java index a834f014..0dc7c5ee 100644 --- a/src/java/org/lwjgl/opengl/GlobalLock.java +++ b/src/java/org/lwjgl/opengl/GlobalLock.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -36,5 +36,5 @@ package org.lwjgl.opengl; * synchronize access to Display. */ final class GlobalLock { - final static Object lock = new Object(); + static final Object lock = new Object(); } diff --git a/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java b/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java index 27b199a7..cdd44e79 100644 --- a/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java +++ b/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java @@ -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() { + 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() { + 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); diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index 67216928..3ccf3262 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -54,32 +54,31 @@ import org.lwjgl.opengl.XRandR.Screen; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; final class LinuxDisplay implements DisplayImplementation { /* X11 constants */ - public final static int CurrentTime = 0; - public final static int GrabSuccess = 0; - public final static int AutoRepeatModeOff = 0; - public final static int AutoRepeatModeOn = 1; - public final static int AutoRepeatModeDefault = 2; - public final static int None = 0; + public static final int CurrentTime = 0; + public static final int GrabSuccess = 0; + public static final int AutoRepeatModeOff = 0; + public static final int AutoRepeatModeOn = 1; + public static final int AutoRepeatModeDefault = 2; + public static final int None = 0; - private final static int KeyPressMask = 1 << 0; - private final static int KeyReleaseMask = 1 << 1; - private final static int ButtonPressMask = 1 << 2; - private final static int ButtonReleaseMask = 1 << 3; + private static final int KeyPressMask = 1 << 0; + private static final int KeyReleaseMask = 1 << 1; + private static final int ButtonPressMask = 1 << 2; + private static final int ButtonReleaseMask = 1 << 3; - private final static int NotifyAncestor = 0; - private final static int NotifyNonlinear = 3; - private final static int NotifyPointer = 5; - private final static int NotifyPointerRoot = 6; - private final static int NotifyDetailNone = 7; + private static final int NotifyAncestor = 0; + private static final int NotifyNonlinear = 3; + private static final int NotifyPointer = 5; + private static final int NotifyPointerRoot = 6; + private static final int NotifyDetailNone = 7; - private final static int SetModeInsert = 0; - private final static int SaveSetRoot = 1; - private final static int SaveSetUnmap = 1; + private static final int SetModeInsert = 0; + private static final int SaveSetRoot = 1; + private static final int SaveSetUnmap = 1; /** Window mode enum */ private static final int FULLSCREEN_LEGACY = 1; @@ -99,7 +98,7 @@ final class LinuxDisplay implements DisplayImplementation { private static long current_window; private static long saved_error_handler; - private static int display_connection_usage_count = 0; + private static int display_connection_usage_count; /** Event buffer */ private final LinuxEvent event_buffer = new LinuxEvent(); @@ -120,7 +119,7 @@ final class LinuxDisplay implements DisplayImplementation { /** Saved mode to restore with */ private DisplayMode saved_mode; private DisplayMode current_mode; - + private Screen[] savedXrandrConfig; private boolean keyboard_grabbed; @@ -369,7 +368,7 @@ final class LinuxDisplay implements DisplayImplementation { } static native int nUngrabPointer(long display); - private boolean isFullscreen() { + private static boolean isFullscreen() { return current_window_mode == FULLSCREEN_LEGACY || current_window_mode == FULLSCREEN_NETWM; } @@ -397,7 +396,7 @@ final class LinuxDisplay implements DisplayImplementation { } private static native void nDefineCursor(long display, long window, long cursor_handle); - private boolean isLegacyFullscreen() { + private static boolean isLegacyFullscreen() { return current_window_mode == FULLSCREEN_LEGACY; } @@ -544,7 +543,7 @@ final class LinuxDisplay implements DisplayImplementation { try { if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 ) { - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction() { 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() { + public Screen[] run() { return XRandR.getConfiguration(); } }); @@ -872,10 +871,10 @@ final class LinuxDisplay implements DisplayImplementation { private void checkInput() { if (parent == null) return; - + if (parent_focus != parent.hasFocus()) { parent_focus = parent.hasFocus(); - + if (parent_focus) { setInputFocusUnsafe(current_window); } @@ -892,7 +891,7 @@ final class LinuxDisplay implements DisplayImplementation { if (focused == got_focus || focus_detail == NotifyDetailNone || focus_detail == NotifyPointer || focus_detail == NotifyPointerRoot) return; focused = got_focus; - + if (focused) { acquireInput(); } @@ -902,7 +901,7 @@ final class LinuxDisplay implements DisplayImplementation { } static native long nGetInputFocus(long display); - private void setInputFocusUnsafe(long window) { + private static void setInputFocusUnsafe(long window) { try { setInputFocus(getDisplay(), window, CurrentTime); sync(getDisplay(), false); @@ -923,7 +922,7 @@ final class LinuxDisplay implements DisplayImplementation { try { if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 ) { - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction() { 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 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() { 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() { 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 run(final String... command) throws LWJGLException { + final List output = new ArrayList(); 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 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; } diff --git a/src/java/org/lwjgl/opengl/LinuxEvent.java b/src/java/org/lwjgl/opengl/LinuxEvent.java index a29b76ec..96fbc40e 100644 --- a/src/java/org/lwjgl/opengl/LinuxEvent.java +++ b/src/java/org/lwjgl/opengl/LinuxEvent.java @@ -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; diff --git a/src/java/org/lwjgl/opengl/LinuxKeycodes.java b/src/java/org/lwjgl/opengl/LinuxKeycodes.java index 9542d087..c57cbd06 100644 --- a/src/java/org/lwjgl/opengl/LinuxKeycodes.java +++ b/src/java/org/lwjgl/opengl/LinuxKeycodes.java @@ -38,111 +38,111 @@ package org.lwjgl.opengl; import org.lwjgl.input.Keyboard; final class LinuxKeycodes { - public final static int XK_Kanji = 0xff21; + public static final int XK_Kanji = 0xff21; - public final static int XK_ISO_Left_Tab = 0xfe20; - - public final static int XK_dead_grave = 0xfe50; - public final static int XK_dead_acute = 0xfe51; - public final static int XK_dead_circumflex = 0xfe52; - public final static int XK_dead_tilde = 0xfe53; - public final static int XK_dead_macron = 0xfe54; - public final static int XK_dead_breve = 0xfe55; - public final static int XK_dead_abovedot = 0xfe56; - public final static int XK_dead_diaeresis = 0xfe57; - public final static int XK_dead_abovering = 0xfe58; - public final static int XK_dead_doubleacute = 0xfe59; - public final static int XK_dead_caron = 0xfe5a; - public final static int XK_dead_cedilla = 0xfe5b; - public final static int XK_dead_ogonek = 0xfe5c; - public final static int XK_dead_iota = 0xfe5d; - public final static int XK_dead_voiced_sound = 0xfe5e; - public final static int XK_dead_semivoiced_sound = 0xfe5f; - public final static int XK_dead_belowdot = 0xfe60; - public final static int XK_dead_hook = 0xfe61; - public final static int XK_dead_horn = 0xfe62; + public static final int XK_ISO_Left_Tab = 0xfe20; - public final static int XK_BackSpace = 0xff08; - public final static int XK_Tab = 0xff09; - public final static int XK_Linefeed = 0xff0a; - public final static int XK_Clear = 0xff0b; - public final static int XK_Return = 0xff0d; - public final static int XK_Pause = 0xff13; - public final static int XK_Scroll_Lock = 0xff14; - public final static int XK_Sys_Req = 0xff15; - public final static int XK_Escape = 0xff1b; - public final static int XK_Delete = 0xffff; + public static final int XK_dead_grave = 0xfe50; + public static final int XK_dead_acute = 0xfe51; + public static final int XK_dead_circumflex = 0xfe52; + public static final int XK_dead_tilde = 0xfe53; + public static final int XK_dead_macron = 0xfe54; + public static final int XK_dead_breve = 0xfe55; + public static final int XK_dead_abovedot = 0xfe56; + public static final int XK_dead_diaeresis = 0xfe57; + public static final int XK_dead_abovering = 0xfe58; + public static final int XK_dead_doubleacute = 0xfe59; + public static final int XK_dead_caron = 0xfe5a; + public static final int XK_dead_cedilla = 0xfe5b; + public static final int XK_dead_ogonek = 0xfe5c; + public static final int XK_dead_iota = 0xfe5d; + public static final int XK_dead_voiced_sound = 0xfe5e; + public static final int XK_dead_semivoiced_sound = 0xfe5f; + public static final int XK_dead_belowdot = 0xfe60; + public static final int XK_dead_hook = 0xfe61; + public static final int XK_dead_horn = 0xfe62; - public final static int XK_Home = 0xff50; - public final static int XK_Left = 0xff51; - public final static int XK_Up = 0xff52; - public final static int XK_Right = 0xff53; - public final static int XK_Down = 0xff54; - public final static int XK_Prior = 0xff55; - public final static int XK_Page_Up = 0xff55; - public final static int XK_Next = 0xff56; - public final static int XK_Page_Down = 0xff56; - public final static int XK_End = 0xff57; - public final static int XK_Begin = 0xff58; + public static final int XK_BackSpace = 0xff08; + public static final int XK_Tab = 0xff09; + public static final int XK_Linefeed = 0xff0a; + public static final int XK_Clear = 0xff0b; + public static final int XK_Return = 0xff0d; + public static final int XK_Pause = 0xff13; + public static final int XK_Scroll_Lock = 0xff14; + public static final int XK_Sys_Req = 0xff15; + public static final int XK_Escape = 0xff1b; + public static final int XK_Delete = 0xffff; + + public static final int XK_Home = 0xff50; + public static final int XK_Left = 0xff51; + public static final int XK_Up = 0xff52; + public static final int XK_Right = 0xff53; + public static final int XK_Down = 0xff54; + public static final int XK_Prior = 0xff55; + public static final int XK_Page_Up = 0xff55; + public static final int XK_Next = 0xff56; + public static final int XK_Page_Down = 0xff56; + public static final int XK_End = 0xff57; + public static final int XK_Begin = 0xff58; /* Misc functions */ - public final static int XK_Select = 0xff60; - public final static int XK_Print = 0xff61; - public final static int XK_Execute = 0xff62; - public final static int XK_Insert = 0xff63; - public final static int XK_Undo = 0xff65; - public final static int XK_Redo = 0xff66; - public final static int XK_Menu = 0xff67; - public final static int XK_Find = 0xff68; - public final static int XK_Cancel = 0xff69; - public final static int XK_Help = 0xff6a; - public final static int XK_Break = 0xff6b; - public final static int XK_Mode_switch = 0xff7e; - public final static int XK_script_switch = 0xff7e; - public final static int XK_Num_Lock = 0xff7f; + public static final int XK_Select = 0xff60; + public static final int XK_Print = 0xff61; + public static final int XK_Execute = 0xff62; + public static final int XK_Insert = 0xff63; + public static final int XK_Undo = 0xff65; + public static final int XK_Redo = 0xff66; + public static final int XK_Menu = 0xff67; + public static final int XK_Find = 0xff68; + public static final int XK_Cancel = 0xff69; + public static final int XK_Help = 0xff6a; + public static final int XK_Break = 0xff6b; + public static final int XK_Mode_switch = 0xff7e; + public static final int XK_script_switch = 0xff7e; + public static final int XK_Num_Lock = 0xff7f; /* Keypad functions, keypad numbers cleverly chosen to map to ASCII */ - public final static int XK_KP_Space = 0xff80; - public final static int XK_KP_Tab = 0xff89; - public final static int XK_KP_Enter = 0xff8d; - public final static int XK_KP_F1 = 0xff91; - public final static int XK_KP_F2 = 0xff92; - public final static int XK_KP_F3 = 0xff93; - public final static int XK_KP_F4 = 0xff94; - public final static int XK_KP_Home = 0xff95; - public final static int XK_KP_Left = 0xff96; - public final static int XK_KP_Up = 0xff97; - public final static int XK_KP_Right = 0xff98; - public final static int XK_KP_Down = 0xff99; - public final static int XK_KP_Prior = 0xff9a; - public final static int XK_KP_Page_Up = 0xff9a; - public final static int XK_KP_Next = 0xff9b; - public final static int XK_KP_Page_Down = 0xff9b; - public final static int XK_KP_End = 0xff9c; - public final static int XK_KP_Begin = 0xff9d; - public final static int XK_KP_Insert = 0xff9e; - public final static int XK_KP_Delete = 0xff9f; - public final static int XK_KP_Equal = 0xffbd; - public final static int XK_KP_Multiply = 0xffaa; - public final static int XK_KP_Add = 0xffab; - public final static int XK_KP_Separator = 0xffac; - public final static int XK_KP_Subtract = 0xffad; - public final static int XK_KP_Decimal = 0xffae; - public final static int XK_KP_Divide = 0xffaf; + public static final int XK_KP_Space = 0xff80; + public static final int XK_KP_Tab = 0xff89; + public static final int XK_KP_Enter = 0xff8d; + public static final int XK_KP_F1 = 0xff91; + public static final int XK_KP_F2 = 0xff92; + public static final int XK_KP_F3 = 0xff93; + public static final int XK_KP_F4 = 0xff94; + public static final int XK_KP_Home = 0xff95; + public static final int XK_KP_Left = 0xff96; + public static final int XK_KP_Up = 0xff97; + public static final int XK_KP_Right = 0xff98; + public static final int XK_KP_Down = 0xff99; + public static final int XK_KP_Prior = 0xff9a; + public static final int XK_KP_Page_Up = 0xff9a; + public static final int XK_KP_Next = 0xff9b; + public static final int XK_KP_Page_Down = 0xff9b; + public static final int XK_KP_End = 0xff9c; + public static final int XK_KP_Begin = 0xff9d; + public static final int XK_KP_Insert = 0xff9e; + public static final int XK_KP_Delete = 0xff9f; + public static final int XK_KP_Equal = 0xffbd; + public static final int XK_KP_Multiply = 0xffaa; + public static final int XK_KP_Add = 0xffab; + public static final int XK_KP_Separator = 0xffac; + public static final int XK_KP_Subtract = 0xffad; + public static final int XK_KP_Decimal = 0xffae; + public static final int XK_KP_Divide = 0xffaf; - public final static int XK_KP_0 = 0xffb0; - public final static int XK_KP_1 = 0xffb1; - public final static int XK_KP_2 = 0xffb2; - public final static int XK_KP_3 = 0xffb3; - public final static int XK_KP_4 = 0xffb4; - public final static int XK_KP_5 = 0xffb5; - public final static int XK_KP_6 = 0xffb6; - public final static int XK_KP_7 = 0xffb7; - public final static int XK_KP_8 = 0xffb8; - public final static int XK_KP_9 = 0xffb9; + public static final int XK_KP_0 = 0xffb0; + public static final int XK_KP_1 = 0xffb1; + public static final int XK_KP_2 = 0xffb2; + public static final int XK_KP_3 = 0xffb3; + public static final int XK_KP_4 = 0xffb4; + public static final int XK_KP_5 = 0xffb5; + public static final int XK_KP_6 = 0xffb6; + public static final int XK_KP_7 = 0xffb7; + public static final int XK_KP_8 = 0xffb8; + public static final int XK_KP_9 = 0xffb9; @@ -153,285 +153,285 @@ final class LinuxKeycodes { * We've not found a keyboard with more than 35 function keys total. */ - public final static int XK_F1 = 0xffbe; - public final static int XK_F2 = 0xffbf; - public final static int XK_F3 = 0xffc0; - public final static int XK_F4 = 0xffc1; - public final static int XK_F5 = 0xffc2; - public final static int XK_F6 = 0xffc3; - public final static int XK_F7 = 0xffc4; - public final static int XK_F8 = 0xffc5; - public final static int XK_F9 = 0xffc6; - public final static int XK_F10 = 0xffc7; - public final static int XK_F11 = 0xffc8; - public final static int XK_L1 = 0xffc8; - public final static int XK_F12 = 0xffc9; - public final static int XK_L2 = 0xffc9; - public final static int XK_F13 = 0xffca; - public final static int XK_L3 = 0xffca; - public final static int XK_F14 = 0xffcb; - public final static int XK_L4 = 0xffcb; - public final static int XK_F15 = 0xffcc; - public final static int XK_L5 = 0xffcc; - public final static int XK_F16 = 0xffcd; - public final static int XK_L6 = 0xffcd; - public final static int XK_F17 = 0xffce; - public final static int XK_L7 = 0xffce; - public final static int XK_F18 = 0xffcf; - public final static int XK_L8 = 0xffcf; - public final static int XK_F19 = 0xffd0; - public final static int XK_L9 = 0xffd0; - public final static int XK_F20 = 0xffd1; - public final static int XK_L10 = 0xffd1; - public final static int XK_F21 = 0xffd2; - public final static int XK_R1 = 0xffd2; - public final static int XK_F22 = 0xffd3; - public final static int XK_R2 = 0xffd3; - public final static int XK_F23 = 0xffd4; - public final static int XK_R3 = 0xffd4; - public final static int XK_F24 = 0xffd5; - public final static int XK_R4 = 0xffd5; - public final static int XK_F25 = 0xffd6; - public final static int XK_R5 = 0xffd6; - public final static int XK_F26 = 0xffd7; - public final static int XK_R6 = 0xffd7; - public final static int XK_F27 = 0xffd8; - public final static int XK_R7 = 0xffd8; - public final static int XK_F28 = 0xffd9; - public final static int XK_R8 = 0xffd9; - public final static int XK_F29 = 0xffda; - public final static int XK_R9 = 0xffda; - public final static int XK_F30 = 0xffdb; - public final static int XK_R10 = 0xffdb; - public final static int XK_F31 = 0xffdc; - public final static int XK_R11 = 0xffdc; - public final static int XK_F32 = 0xffdd; - public final static int XK_R12 = 0xffdd; - public final static int XK_F33 = 0xffde; - public final static int XK_R13 = 0xffde; - public final static int XK_F34 = 0xffdf; - public final static int XK_R14 = 0xffdf; - public final static int XK_F35 = 0xffe0; - public final static int XK_R15 = 0xffe0; + public static final int XK_F1 = 0xffbe; + public static final int XK_F2 = 0xffbf; + public static final int XK_F3 = 0xffc0; + public static final int XK_F4 = 0xffc1; + public static final int XK_F5 = 0xffc2; + public static final int XK_F6 = 0xffc3; + public static final int XK_F7 = 0xffc4; + public static final int XK_F8 = 0xffc5; + public static final int XK_F9 = 0xffc6; + public static final int XK_F10 = 0xffc7; + public static final int XK_F11 = 0xffc8; + public static final int XK_L1 = 0xffc8; + public static final int XK_F12 = 0xffc9; + public static final int XK_L2 = 0xffc9; + public static final int XK_F13 = 0xffca; + public static final int XK_L3 = 0xffca; + public static final int XK_F14 = 0xffcb; + public static final int XK_L4 = 0xffcb; + public static final int XK_F15 = 0xffcc; + public static final int XK_L5 = 0xffcc; + public static final int XK_F16 = 0xffcd; + public static final int XK_L6 = 0xffcd; + public static final int XK_F17 = 0xffce; + public static final int XK_L7 = 0xffce; + public static final int XK_F18 = 0xffcf; + public static final int XK_L8 = 0xffcf; + public static final int XK_F19 = 0xffd0; + public static final int XK_L9 = 0xffd0; + public static final int XK_F20 = 0xffd1; + public static final int XK_L10 = 0xffd1; + public static final int XK_F21 = 0xffd2; + public static final int XK_R1 = 0xffd2; + public static final int XK_F22 = 0xffd3; + public static final int XK_R2 = 0xffd3; + public static final int XK_F23 = 0xffd4; + public static final int XK_R3 = 0xffd4; + public static final int XK_F24 = 0xffd5; + public static final int XK_R4 = 0xffd5; + public static final int XK_F25 = 0xffd6; + public static final int XK_R5 = 0xffd6; + public static final int XK_F26 = 0xffd7; + public static final int XK_R6 = 0xffd7; + public static final int XK_F27 = 0xffd8; + public static final int XK_R7 = 0xffd8; + public static final int XK_F28 = 0xffd9; + public static final int XK_R8 = 0xffd9; + public static final int XK_F29 = 0xffda; + public static final int XK_R9 = 0xffda; + public static final int XK_F30 = 0xffdb; + public static final int XK_R10 = 0xffdb; + public static final int XK_F31 = 0xffdc; + public static final int XK_R11 = 0xffdc; + public static final int XK_F32 = 0xffdd; + public static final int XK_R12 = 0xffdd; + public static final int XK_F33 = 0xffde; + public static final int XK_R13 = 0xffde; + public static final int XK_F34 = 0xffdf; + public static final int XK_R14 = 0xffdf; + public static final int XK_F35 = 0xffe0; + public static final int XK_R15 = 0xffe0; /* Modifiers */ - public final static int XK_Shift_L = 0xffe1; - public final static int XK_Shift_R = 0xffe2; - public final static int XK_Control_L = 0xffe3; - public final static int XK_Control_R = 0xffe4; - public final static int XK_Caps_Lock = 0xffe5; - public final static int XK_Shift_Lock = 0xffe6; + public static final int XK_Shift_L = 0xffe1; + public static final int XK_Shift_R = 0xffe2; + public static final int XK_Control_L = 0xffe3; + public static final int XK_Control_R = 0xffe4; + public static final int XK_Caps_Lock = 0xffe5; + public static final int XK_Shift_Lock = 0xffe6; - public final static int XK_Meta_L = 0xffe7; - public final static int XK_Meta_R = 0xffe8; - public final static int XK_Alt_L = 0xffe9; - public final static int XK_Alt_R = 0xffea; - public final static int XK_Super_L = 0xffeb; - public final static int XK_Super_R = 0xffec; - public final static int XK_Hyper_L = 0xffed; - public final static int XK_Hyper_R = 0xffee; - public final static int XK_space = 0x0020; - public final static int XK_exclam = 0x0021; - public final static int XK_quotedbl = 0x0022; - public final static int XK_numbersign = 0x0023; - public final static int XK_dollar = 0x0024; - public final static int XK_percent = 0x0025; - public final static int XK_ampersand = 0x0026; - public final static int XK_apostrophe = 0x0027; - public final static int XK_quoteright = 0x0027; - public final static int XK_parenleft = 0x0028; - public final static int XK_parenright = 0x0029; - public final static int XK_asterisk = 0x002a; - public final static int XK_plus = 0x002b; - public final static int XK_comma = 0x002c; - public final static int XK_minus = 0x002d; - public final static int XK_period = 0x002e; - public final static int XK_slash = 0x002f; + public static final int XK_Meta_L = 0xffe7; + public static final int XK_Meta_R = 0xffe8; + public static final int XK_Alt_L = 0xffe9; + public static final int XK_Alt_R = 0xffea; + public static final int XK_Super_L = 0xffeb; + public static final int XK_Super_R = 0xffec; + public static final int XK_Hyper_L = 0xffed; + public static final int XK_Hyper_R = 0xffee; + public static final int XK_space = 0x0020; + public static final int XK_exclam = 0x0021; + public static final int XK_quotedbl = 0x0022; + public static final int XK_numbersign = 0x0023; + public static final int XK_dollar = 0x0024; + public static final int XK_percent = 0x0025; + public static final int XK_ampersand = 0x0026; + public static final int XK_apostrophe = 0x0027; + public static final int XK_quoteright = 0x0027; + public static final int XK_parenleft = 0x0028; + public static final int XK_parenright = 0x0029; + public static final int XK_asterisk = 0x002a; + public static final int XK_plus = 0x002b; + public static final int XK_comma = 0x002c; + public static final int XK_minus = 0x002d; + public static final int XK_period = 0x002e; + public static final int XK_slash = 0x002f; - public final static int XK_0 = 0x0030; - public final static int XK_1 = 0x0031; - public final static int XK_2 = 0x0032; - public final static int XK_3 = 0x0033; - public final static int XK_4 = 0x0034; - public final static int XK_5 = 0x0035; - public final static int XK_6 = 0x0036; - public final static int XK_7 = 0x0037; - public final static int XK_8 = 0x0038; - public final static int XK_9 = 0x0039; - public final static int XK_colon = 0x003a; - public final static int XK_semicolon = 0x003b; - public final static int XK_less = 0x003c; - public final static int XK_equal = 0x003d; - public final static int XK_greater = 0x003e; - public final static int XK_question = 0x003f; - public final static int XK_at = 0x0040; - public final static int XK_A = 0x0041; - public final static int XK_B = 0x0042; - public final static int XK_C = 0x0043; - public final static int XK_D = 0x0044; - public final static int XK_E = 0x0045; - public final static int XK_F = 0x0046; - public final static int XK_G = 0x0047; - public final static int XK_H = 0x0048; - public final static int XK_I = 0x0049; - public final static int XK_J = 0x004a; - public final static int XK_K = 0x004b; - public final static int XK_L = 0x004c; - public final static int XK_M = 0x004d; - public final static int XK_N = 0x004e; - public final static int XK_O = 0x004f; - public final static int XK_P = 0x0050; - public final static int XK_Q = 0x0051; - public final static int XK_R = 0x0052; - public final static int XK_S = 0x0053; - public final static int XK_T = 0x0054; - public final static int XK_U = 0x0055; - public final static int XK_V = 0x0056; - public final static int XK_W = 0x0057; - public final static int XK_X = 0x0058; - public final static int XK_Y = 0x0059; - public final static int XK_Z = 0x005a; - public final static int XK_bracketleft = 0x005b; - public final static int XK_backslash = 0x005c; - public final static int XK_bracketright = 0x005d; - public final static int XK_asciicircum = 0x005e; - public final static int XK_underscore = 0x005f; - public final static int XK_grave = 0x0060; - public final static int XK_quoteleft = 0x0060; - public final static int XK_a = 0x0061; - public final static int XK_b = 0x0062; - public final static int XK_c = 0x0063; - public final static int XK_d = 0x0064; - public final static int XK_e = 0x0065; - public final static int XK_f = 0x0066; - public final static int XK_g = 0x0067; - public final static int XK_h = 0x0068; - public final static int XK_i = 0x0069; - public final static int XK_j = 0x006a; - public final static int XK_k = 0x006b; - public final static int XK_l = 0x006c; - public final static int XK_m = 0x006d; - public final static int XK_n = 0x006e; - public final static int XK_o = 0x006f; - public final static int XK_p = 0x0070; - public final static int XK_q = 0x0071; - public final static int XK_r = 0x0072; - public final static int XK_s = 0x0073; - public final static int XK_t = 0x0074; - public final static int XK_u = 0x0075; - public final static int XK_v = 0x0076; - public final static int XK_w = 0x0077; - public final static int XK_x = 0x0078; - public final static int XK_y = 0x0079; - public final static int XK_z = 0x007a; - public final static int XK_braceleft = 0x007b; - public final static int XK_bar = 0x007c; - public final static int XK_braceright = 0x007d; - public final static int XK_asciitilde = 0x007e; + public static final int XK_0 = 0x0030; + public static final int XK_1 = 0x0031; + public static final int XK_2 = 0x0032; + public static final int XK_3 = 0x0033; + public static final int XK_4 = 0x0034; + public static final int XK_5 = 0x0035; + public static final int XK_6 = 0x0036; + public static final int XK_7 = 0x0037; + public static final int XK_8 = 0x0038; + public static final int XK_9 = 0x0039; + public static final int XK_colon = 0x003a; + public static final int XK_semicolon = 0x003b; + public static final int XK_less = 0x003c; + public static final int XK_equal = 0x003d; + public static final int XK_greater = 0x003e; + public static final int XK_question = 0x003f; + public static final int XK_at = 0x0040; + public static final int XK_A = 0x0041; + public static final int XK_B = 0x0042; + public static final int XK_C = 0x0043; + public static final int XK_D = 0x0044; + public static final int XK_E = 0x0045; + public static final int XK_F = 0x0046; + public static final int XK_G = 0x0047; + public static final int XK_H = 0x0048; + public static final int XK_I = 0x0049; + public static final int XK_J = 0x004a; + public static final int XK_K = 0x004b; + public static final int XK_L = 0x004c; + public static final int XK_M = 0x004d; + public static final int XK_N = 0x004e; + public static final int XK_O = 0x004f; + public static final int XK_P = 0x0050; + public static final int XK_Q = 0x0051; + public static final int XK_R = 0x0052; + public static final int XK_S = 0x0053; + public static final int XK_T = 0x0054; + public static final int XK_U = 0x0055; + public static final int XK_V = 0x0056; + public static final int XK_W = 0x0057; + public static final int XK_X = 0x0058; + public static final int XK_Y = 0x0059; + public static final int XK_Z = 0x005a; + public static final int XK_bracketleft = 0x005b; + public static final int XK_backslash = 0x005c; + public static final int XK_bracketright = 0x005d; + public static final int XK_asciicircum = 0x005e; + public static final int XK_underscore = 0x005f; + public static final int XK_grave = 0x0060; + public static final int XK_quoteleft = 0x0060; + public static final int XK_a = 0x0061; + public static final int XK_b = 0x0062; + public static final int XK_c = 0x0063; + public static final int XK_d = 0x0064; + public static final int XK_e = 0x0065; + public static final int XK_f = 0x0066; + public static final int XK_g = 0x0067; + public static final int XK_h = 0x0068; + public static final int XK_i = 0x0069; + public static final int XK_j = 0x006a; + public static final int XK_k = 0x006b; + public static final int XK_l = 0x006c; + public static final int XK_m = 0x006d; + public static final int XK_n = 0x006e; + public static final int XK_o = 0x006f; + public static final int XK_p = 0x0070; + public static final int XK_q = 0x0071; + public static final int XK_r = 0x0072; + public static final int XK_s = 0x0073; + public static final int XK_t = 0x0074; + public static final int XK_u = 0x0075; + public static final int XK_v = 0x0076; + public static final int XK_w = 0x0077; + public static final int XK_x = 0x0078; + public static final int XK_y = 0x0079; + public static final int XK_z = 0x007a; + public static final int XK_braceleft = 0x007b; + public static final int XK_bar = 0x007c; + public static final int XK_braceright = 0x007d; + public static final int XK_asciitilde = 0x007e; - public final static int XK_nobreakspace = 0x00a0; - public final static int XK_exclamdown = 0x00a1; - public final static int XK_cent = 0x00a2; - public final static int XK_sterling = 0x00a3; - public final static int XK_currency = 0x00a4; - public final static int XK_yen = 0x00a5; - public final static int XK_brokenbar = 0x00a6; - public final static int XK_section = 0x00a7; - public final static int XK_diaeresis = 0x00a8; - public final static int XK_copyright = 0x00a9; - public final static int XK_ordfeminine = 0x00aa; - public final static int XK_guillemotleft = 0x00ab; - public final static int XK_notsign = 0x00ac; - public final static int XK_hyphen = 0x00ad; - public final static int XK_registered = 0x00ae; - public final static int XK_macron = 0x00af; - public final static int XK_degree = 0x00b0; - public final static int XK_plusminus = 0x00b1; - public final static int XK_twosuperior = 0x00b2; - public final static int XK_threesuperior = 0x00b3; - public final static int XK_acute = 0x00b4; - public final static int XK_mu = 0x00b5; - public final static int XK_paragraph = 0x00b6; - public final static int XK_periodcentered = 0x00b7; - public final static int XK_cedilla = 0x00b8; - public final static int XK_onesuperior = 0x00b9; - public final static int XK_masculine = 0x00ba; - public final static int XK_guillemotright = 0x00bb; - public final static int XK_onequarter = 0x00bc; - public final static int XK_onehalf = 0x00bd; - public final static int XK_threequarters = 0x00be; - public final static int XK_questiondown = 0x00bf; - public final static int XK_Agrave = 0x00c0; - public final static int XK_Aacute = 0x00c1; - public final static int XK_Acircumflex = 0x00c2; - public final static int XK_Atilde = 0x00c3; - public final static int XK_Adiaeresis = 0x00c4; - public final static int XK_Aring = 0x00c5; - public final static int XK_AE = 0x00c6; - public final static int XK_Ccedilla = 0x00c7; - public final static int XK_Egrave = 0x00c8; - public final static int XK_Eacute = 0x00c9; - public final static int XK_Ecircumflex = 0x00ca; - public final static int XK_Ediaeresis = 0x00cb; - public final static int XK_Igrave = 0x00cc; - public final static int XK_Iacute = 0x00cd; - public final static int XK_Icircumflex = 0x00ce; - public final static int XK_Idiaeresis = 0x00cf; - public final static int XK_ETH = 0x00d0; - public final static int XK_Eth = 0x00d0; - public final static int XK_Ntilde = 0x00d1; - public final static int XK_Ograve = 0x00d2; - public final static int XK_Oacute = 0x00d3; - public final static int XK_Ocircumflex = 0x00d4; - public final static int XK_Otilde = 0x00d5; - public final static int XK_Odiaeresis = 0x00d6; - public final static int XK_multiply = 0x00d7; - public final static int XK_Oslash = 0x00d8; - public final static int XK_Ooblique = 0x00d8; - public final static int XK_Ugrave = 0x00d9; - public final static int XK_Uacute = 0x00da; - public final static int XK_Ucircumflex = 0x00db; - public final static int XK_Udiaeresis = 0x00dc; - public final static int XK_Yacute = 0x00dd; - public final static int XK_THORN = 0x00de; - public final static int XK_Thorn = 0x00de; - public final static int XK_ssharp = 0x00df; - public final static int XK_agrave = 0x00e0; - public final static int XK_aacute = 0x00e1; - public final static int XK_acircumflex = 0x00e2; - public final static int XK_atilde = 0x00e3; - public final static int XK_adiaeresis = 0x00e4; - public final static int XK_aring = 0x00e5; - public final static int XK_ae = 0x00e6; - public final static int XK_ccedilla = 0x00e7; - public final static int XK_egrave = 0x00e8; - public final static int XK_eacute = 0x00e9; - public final static int XK_ecircumflex = 0x00ea; - public final static int XK_ediaeresis = 0x00eb; - public final static int XK_igrave = 0x00ec; - public final static int XK_iacute = 0x00ed; - public final static int XK_icircumflex = 0x00ee; - public final static int XK_idiaeresis = 0x00ef; - public final static int XK_eth = 0x00f0; - public final static int XK_ntilde = 0x00f1; - public final static int XK_ograve = 0x00f2; - public final static int XK_oacute = 0x00f3; - public final static int XK_ocircumflex = 0x00f4; - public final static int XK_otilde = 0x00f5; - public final static int XK_odiaeresis = 0x00f6; - public final static int XK_division = 0x00f7; - public final static int XK_oslash = 0x00f8; - public final static int XK_ooblique = 0x00f8; - public final static int XK_ugrave = 0x00f9; - public final static int XK_uacute = 0x00fa; - public final static int XK_ucircumflex = 0x00fb; - public final static int XK_udiaeresis = 0x00fc; - public final static int XK_yacute = 0x00fd; - public final static int XK_thorn = 0x00fe; - public final static int XK_ydiaeresis = 0x00ff; + public static final int XK_nobreakspace = 0x00a0; + public static final int XK_exclamdown = 0x00a1; + public static final int XK_cent = 0x00a2; + public static final int XK_sterling = 0x00a3; + public static final int XK_currency = 0x00a4; + public static final int XK_yen = 0x00a5; + public static final int XK_brokenbar = 0x00a6; + public static final int XK_section = 0x00a7; + public static final int XK_diaeresis = 0x00a8; + public static final int XK_copyright = 0x00a9; + public static final int XK_ordfeminine = 0x00aa; + public static final int XK_guillemotleft = 0x00ab; + public static final int XK_notsign = 0x00ac; + public static final int XK_hyphen = 0x00ad; + public static final int XK_registered = 0x00ae; + public static final int XK_macron = 0x00af; + public static final int XK_degree = 0x00b0; + public static final int XK_plusminus = 0x00b1; + public static final int XK_twosuperior = 0x00b2; + public static final int XK_threesuperior = 0x00b3; + public static final int XK_acute = 0x00b4; + public static final int XK_mu = 0x00b5; + public static final int XK_paragraph = 0x00b6; + public static final int XK_periodcentered = 0x00b7; + public static final int XK_cedilla = 0x00b8; + public static final int XK_onesuperior = 0x00b9; + public static final int XK_masculine = 0x00ba; + public static final int XK_guillemotright = 0x00bb; + public static final int XK_onequarter = 0x00bc; + public static final int XK_onehalf = 0x00bd; + public static final int XK_threequarters = 0x00be; + public static final int XK_questiondown = 0x00bf; + public static final int XK_Agrave = 0x00c0; + public static final int XK_Aacute = 0x00c1; + public static final int XK_Acircumflex = 0x00c2; + public static final int XK_Atilde = 0x00c3; + public static final int XK_Adiaeresis = 0x00c4; + public static final int XK_Aring = 0x00c5; + public static final int XK_AE = 0x00c6; + public static final int XK_Ccedilla = 0x00c7; + public static final int XK_Egrave = 0x00c8; + public static final int XK_Eacute = 0x00c9; + public static final int XK_Ecircumflex = 0x00ca; + public static final int XK_Ediaeresis = 0x00cb; + public static final int XK_Igrave = 0x00cc; + public static final int XK_Iacute = 0x00cd; + public static final int XK_Icircumflex = 0x00ce; + public static final int XK_Idiaeresis = 0x00cf; + public static final int XK_ETH = 0x00d0; + public static final int XK_Eth = 0x00d0; + public static final int XK_Ntilde = 0x00d1; + public static final int XK_Ograve = 0x00d2; + public static final int XK_Oacute = 0x00d3; + public static final int XK_Ocircumflex = 0x00d4; + public static final int XK_Otilde = 0x00d5; + public static final int XK_Odiaeresis = 0x00d6; + public static final int XK_multiply = 0x00d7; + public static final int XK_Oslash = 0x00d8; + public static final int XK_Ooblique = 0x00d8; + public static final int XK_Ugrave = 0x00d9; + public static final int XK_Uacute = 0x00da; + public static final int XK_Ucircumflex = 0x00db; + public static final int XK_Udiaeresis = 0x00dc; + public static final int XK_Yacute = 0x00dd; + public static final int XK_THORN = 0x00de; + public static final int XK_Thorn = 0x00de; + public static final int XK_ssharp = 0x00df; + public static final int XK_agrave = 0x00e0; + public static final int XK_aacute = 0x00e1; + public static final int XK_acircumflex = 0x00e2; + public static final int XK_atilde = 0x00e3; + public static final int XK_adiaeresis = 0x00e4; + public static final int XK_aring = 0x00e5; + public static final int XK_ae = 0x00e6; + public static final int XK_ccedilla = 0x00e7; + public static final int XK_egrave = 0x00e8; + public static final int XK_eacute = 0x00e9; + public static final int XK_ecircumflex = 0x00ea; + public static final int XK_ediaeresis = 0x00eb; + public static final int XK_igrave = 0x00ec; + public static final int XK_iacute = 0x00ed; + public static final int XK_icircumflex = 0x00ee; + public static final int XK_idiaeresis = 0x00ef; + public static final int XK_eth = 0x00f0; + public static final int XK_ntilde = 0x00f1; + public static final int XK_ograve = 0x00f2; + public static final int XK_oacute = 0x00f3; + public static final int XK_ocircumflex = 0x00f4; + public static final int XK_otilde = 0x00f5; + public static final int XK_odiaeresis = 0x00f6; + public static final int XK_division = 0x00f7; + public static final int XK_oslash = 0x00f8; + public static final int XK_ooblique = 0x00f8; + public static final int XK_ugrave = 0x00f9; + public static final int XK_uacute = 0x00fa; + public static final int XK_ucircumflex = 0x00fb; + public static final int XK_udiaeresis = 0x00fc; + public static final int XK_yacute = 0x00fd; + public static final int XK_thorn = 0x00fe; + public static final int XK_ydiaeresis = 0x00ff; - public final static int XK_ISO_Level3_Shift = 0xfe03; + public static final int XK_ISO_Level3_Shift = 0xfe03; public static int mapKeySymToLWJGLKeyCode(long keysym) { switch ((int)keysym) { diff --git a/src/java/org/lwjgl/opengl/LinuxMouse.java b/src/java/org/lwjgl/opengl/LinuxMouse.java index 407d9268..7383ec1d 100644 --- a/src/java/org/lwjgl/opengl/LinuxMouse.java +++ b/src/java/org/lwjgl/opengl/LinuxMouse.java @@ -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; diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index ea58d0e3..eaccaee2 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -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() { 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() { public Object run() { if (MacOSXFrame.getDevice().getFullScreenWindow() == frame) MacOSXFrame.getDevice().setFullScreenWindow(null); @@ -154,18 +156,19 @@ final class MacOSXDisplay implements DisplayImplementation { return null; } - private boolean equals(java.awt.DisplayMode awt_mode, DisplayMode mode) { + private static boolean equals(java.awt.DisplayMode awt_mode, DisplayMode mode) { return awt_mode.getWidth() == mode.getWidth() && awt_mode.getHeight() == mode.getHeight() && awt_mode.getBitDepth() == mode.getBitsPerPixel() && awt_mode.getRefreshRate() == mode.getFrequency(); } public void switchDisplayMode(DisplayMode mode) throws LWJGLException { java.awt.DisplayMode[] awt_modes = MacOSXFrame.getDevice().getDisplayModes(); - for (int i = 0; i < awt_modes.length; i++) - if (equals(awt_modes[i], mode)) { - requested_mode = awt_modes[i]; + for ( java.awt.DisplayMode awt_mode : awt_modes ) { + if (equals(awt_mode, mode)) { + requested_mode = awt_mode; return; } + } throw new LWJGLException(mode + " is not supported"); } @@ -178,7 +181,7 @@ final class MacOSXDisplay implements DisplayImplementation { private native void restoreGamma(); - private DisplayMode createLWJGLDisplayMode(java.awt.DisplayMode awt_mode) { + private static DisplayMode createLWJGLDisplayMode(java.awt.DisplayMode awt_mode) { int bit_depth; int refresh_rate; int awt_bit_depth = awt_mode.getBitDepth(); @@ -200,17 +203,15 @@ final class MacOSXDisplay implements DisplayImplementation { public DisplayMode[] getAvailableDisplayModes() throws LWJGLException { java.awt.DisplayMode[] awt_modes = MacOSXFrame.getDevice().getDisplayModes(); - List modes = new ArrayList(); - for (int i = 0; i < awt_modes.length; i++) - if (awt_modes[i].getBitDepth() >= 16) - modes.add(createLWJGLDisplayMode(awt_modes[i])); - DisplayMode[] mode_list = new DisplayMode[modes.size()]; - modes.toArray(mode_list); - return mode_list; + List modes = new ArrayList(); + for ( java.awt.DisplayMode awt_mode : awt_modes ) + if ( awt_mode.getBitDepth() >= 16 ) + modes.add(createLWJGLDisplayMode(awt_mode)); + return modes.toArray(new DisplayMode[modes.size()]); } public void setTitle(String title) { - if (frame != null) + if (frame != null) frame.setTitle(title); } @@ -247,7 +248,7 @@ final class MacOSXDisplay implements DisplayImplementation { } } - private final static IntBuffer current_viewport = BufferUtils.createIntBuffer(16); + private static final IntBuffer current_viewport = BufferUtils.createIntBuffer(16); public void update() { boolean should_update = canvas_listener.syncShouldUpdateContext(); /* @@ -282,8 +283,8 @@ final class MacOSXDisplay implements DisplayImplementation { if (should_update) { drawable.context.update(); /* This is necessary to make sure the context won't "forget" about the view size */ - GL11.glGetInteger(GL11.GL_VIEWPORT, current_viewport); - GL11.glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3)); + glGetInteger(GL_VIEWPORT, current_viewport); + glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3)); } if (frame != null && mouse_queue != null) { if (frame.syncShouldReleaseCursor()) @@ -432,7 +433,7 @@ final class MacOSXDisplay implements DisplayImplementation { public boolean isBufferLost(PeerInfo handle) { return false; } - + public PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format, IntBuffer pixelFormatCaps, IntBuffer pBufferAttribs) throws LWJGLException { @@ -466,30 +467,30 @@ final class MacOSXDisplay implements DisplayImplementation { public int setIcon(ByteBuffer[] icons) { /* int size = 0; int biggest = -1; - + for (int i=0;i size) { biggest = i; size = icons[i].remaining(); } } - + if (biggest == -1) { return 0; } - + int width; int height; - + IntBuffer biggest_icon = icons[biggest].asIntBuffer(); int[] imageData = new int[biggest_icon.remaining()]; width = height = (int) Math.sqrt(imageData.length); biggest_icon.get(imageData); - + BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); img.setRGB(0, 0, width, height, imageData, 0, width); frame.setIconImage(img); - + return 1;*/ // Don't use any icon, since Mac OS X windows don't have window icons return 0; diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplayPeerInfo.java b/src/java/org/lwjgl/opengl/MacOSXDisplayPeerInfo.java index 4cd7af28..1d92d78e 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplayPeerInfo.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplayPeerInfo.java @@ -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); diff --git a/src/java/org/lwjgl/opengl/MacOSXFrame.java b/src/java/org/lwjgl/opengl/MacOSXFrame.java index e2585227..502b16c9 100644 --- a/src/java/org/lwjgl/opengl/MacOSXFrame.java +++ b/src/java/org/lwjgl/opengl/MacOSXFrame.java @@ -56,7 +56,7 @@ import org.lwjgl.LWJGLException; final class MacOSXFrame extends Frame implements WindowListener, ComponentListener { private static final long serialVersionUID = -5823294716668988777L; - + private final MacOSXGLCanvas canvas; private boolean close_requested; @@ -78,7 +78,7 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen setUndecorated(fullscreen || undecorated); if ( fullscreen ) { try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { + AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { getDevice().setFullScreenWindow(MacOSXFrame.this); getDevice().setDisplayMode(requested_mode); @@ -110,7 +110,7 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen Insets insets = getInsets(); setBounds(x, y, width + insets.left + insets.right, height + insets.top + insets.bottom); } - + public Rectangle syncGetBounds() { synchronized ( this ) { return bounds; diff --git a/src/java/org/lwjgl/opengl/PeerInfo.java b/src/java/org/lwjgl/opengl/PeerInfo.java index 98d919aa..95e04fae 100644 --- a/src/java/org/lwjgl/opengl/PeerInfo.java +++ b/src/java/org/lwjgl/opengl/PeerInfo.java @@ -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 { diff --git a/src/java/org/lwjgl/opengl/ReferencesStack.java b/src/java/org/lwjgl/opengl/ReferencesStack.java index fbb5c7cf..30893d66 100644 --- a/src/java/org/lwjgl/opengl/ReferencesStack.java +++ b/src/java/org/lwjgl/opengl/ReferencesStack.java @@ -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) { diff --git a/src/java/org/lwjgl/opengl/RenderTexture.java b/src/java/org/lwjgl/opengl/RenderTexture.java index 212dafbf..b9c8ab10 100644 --- a/src/java/org/lwjgl/opengl/RenderTexture.java +++ b/src/java/org/lwjgl/opengl/RenderTexture.java @@ -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); diff --git a/src/java/org/lwjgl/opengl/StateTracker.java b/src/java/org/lwjgl/opengl/StateTracker.java index 47a1ed66..8aeb5b1b 100644 --- a/src/java/org/lwjgl/opengl/StateTracker.java +++ b/src/java/org/lwjgl/opengl/StateTracker.java @@ -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; diff --git a/src/java/org/lwjgl/opengl/Util.java b/src/java/org/lwjgl/opengl/Util.java index 49cc59ba..8efa1c02 100644 --- a/src/java/org/lwjgl/opengl/Util.java +++ b/src/java/org/lwjgl/opengl/Util.java @@ -31,6 +31,9 @@ */ package org.lwjgl.opengl; +import static org.lwjgl.opengl.ARBImaging.*; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL30.*; /** * Simple utility class. @@ -43,16 +46,16 @@ public final class Util { /** No c'tor */ private Util() { } - + /** - * Throws OpenGLException if GL11.glGetError() returns anything else than GL11.GL_NO_ERROR + * Throws OpenGLException if glGetError() returns anything else than GL_NO_ERROR * */ public static void checkGLError() throws OpenGLException { if ( ContextCapabilities.DEBUG && GLContext.getCapabilities().tracker.isBeginEnd() ) // Do not call GetError inside a Begin/End pair. return; - int err = GL11.glGetError(); - if ( err != GL11.GL_NO_ERROR ) { + int err = glGetError(); + if ( err != GL_NO_ERROR ) { throw new OpenGLException(err); } } @@ -62,23 +65,23 @@ public final class Util { */ public static String translateGLErrorString(int error_code) { switch (error_code) { - case GL11.GL_NO_ERROR: + case GL_NO_ERROR: return "No error"; - case GL11.GL_INVALID_ENUM: + case GL_INVALID_ENUM: return "Invalid enum"; - case GL11.GL_INVALID_VALUE: + case GL_INVALID_VALUE: return "Invalid value"; - case GL11.GL_INVALID_OPERATION: + case GL_INVALID_OPERATION: return "Invalid operation"; - case GL11.GL_STACK_OVERFLOW: + case GL_STACK_OVERFLOW: return "Stack overflow"; - case GL11.GL_STACK_UNDERFLOW: + case GL_STACK_UNDERFLOW: return "Stack underflow"; - case GL11.GL_OUT_OF_MEMORY: + case GL_OUT_OF_MEMORY: return "Out of memory"; - case ARBImaging.GL_TABLE_TOO_LARGE: + case GL_TABLE_TOO_LARGE: return "Table too large"; - case EXTFramebufferObject.GL_INVALID_FRAMEBUFFER_OPERATION_EXT: + case GL_INVALID_FRAMEBUFFER_OPERATION: return "Invalid framebuffer operation"; default: return null; diff --git a/src/java/org/lwjgl/opengl/WindowsAWTGLCanvasPeerInfo.java b/src/java/org/lwjgl/opengl/WindowsAWTGLCanvasPeerInfo.java index c3d3feff..289c1209 100644 --- a/src/java/org/lwjgl/opengl/WindowsAWTGLCanvasPeerInfo.java +++ b/src/java/org/lwjgl/opengl/WindowsAWTGLCanvasPeerInfo.java @@ -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; diff --git a/src/java/org/lwjgl/opengl/WindowsCanvasImplementation.java b/src/java/org/lwjgl/opengl/WindowsCanvasImplementation.java index a738d6df..052fd5ef 100644 --- a/src/java/org/lwjgl/opengl/WindowsCanvasImplementation.java +++ b/src/java/org/lwjgl/opengl/WindowsCanvasImplementation.java @@ -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() { public Object run() { try { System.loadLibrary("jawt"); diff --git a/src/java/org/lwjgl/opengl/WindowsDisplay.java b/src/java/org/lwjgl/opengl/WindowsDisplay.java index 6a32c3c8..2c4546b6 100644 --- a/src/java/org/lwjgl/opengl/WindowsDisplay.java +++ b/src/java/org/lwjgl/opengl/WindowsDisplay.java @@ -51,87 +51,87 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; final class WindowsDisplay implements DisplayImplementation { - private final static int GAMMA_LENGTH = 256; - - private final static int WM_CANCELMODE = 0x001F; - private final static int WM_MOUSEMOVE = 0x0200; - private final static int WM_LBUTTONDOWN = 0x0201; - private final static int WM_LBUTTONUP = 0x0202; - private final static int WM_LBUTTONDBLCLK = 0x0203; - private final static int WM_RBUTTONDOWN = 0x0204; - private final static int WM_RBUTTONUP = 0x0205; - private final static int WM_RBUTTONDBLCLK = 0x0206; - private final static int WM_MBUTTONDOWN = 0x0207; - private final static int WM_MBUTTONUP = 0x0208; - private final static int WM_MBUTTONDBLCLK = 0x0209; - private final static int WM_MOUSEWHEEL = 0x020A; - private final static int WM_CAPTURECHANGED = 0x0215; - private final static int WM_MOUSELEAVE = 0x02A3; - private final static int WM_KEYDOWN = 256; - private final static int WM_KEYUP = 257; - private final static int WM_SYSKEYUP = 261; - private final static int WM_SYSKEYDOWN = 260; - private final static int WM_SYSCHAR = 262; - private final static int WM_CHAR = 258; - private final static int WM_SETICON = 0x0080; + private static final int GAMMA_LENGTH = 256; - private final static int WM_QUIT = 0x0012; - private final static int WM_SYSCOMMAND = 0x0112; - private final static int WM_PAINT = 0x000F; - private final static int WM_KILLFOCUS = 8; - private final static int WM_SETFOCUS = 7; + private static final int WM_CANCELMODE = 0x001F; + private static final int WM_MOUSEMOVE = 0x0200; + private static final int WM_LBUTTONDOWN = 0x0201; + private static final int WM_LBUTTONUP = 0x0202; + private static final int WM_LBUTTONDBLCLK = 0x0203; + private static final int WM_RBUTTONDOWN = 0x0204; + private static final int WM_RBUTTONUP = 0x0205; + private static final int WM_RBUTTONDBLCLK = 0x0206; + private static final int WM_MBUTTONDOWN = 0x0207; + private static final int WM_MBUTTONUP = 0x0208; + private static final int WM_MBUTTONDBLCLK = 0x0209; + private static final int WM_MOUSEWHEEL = 0x020A; + private static final int WM_CAPTURECHANGED = 0x0215; + private static final int WM_MOUSELEAVE = 0x02A3; + private static final int WM_KEYDOWN = 256; + private static final int WM_KEYUP = 257; + private static final int WM_SYSKEYUP = 261; + private static final int WM_SYSKEYDOWN = 260; + private static final int WM_SYSCHAR = 262; + private static final int WM_CHAR = 258; + private static final int WM_SETICON = 0x0080; - private final static int SC_SIZE = 0xF000; - private final static int SC_MOVE = 0xF010; - private final static int SC_MINIMIZE = 0xF020; - private final static int SC_MAXIMIZE = 0xF030; - private final static int SC_NEXTWINDOW = 0xF040; - private final static int SC_PREVWINDOW = 0xF050; - private final static int SC_CLOSE = 0xF060; - private final static int SC_VSCROLL = 0xF070; - private final static int SC_HSCROLL = 0xF080; - private final static int SC_MOUSEMENU = 0xF090; - private final static int SC_KEYMENU = 0xF100; - private final static int SC_ARRANGE = 0xF110; - private final static int SC_RESTORE = 0xF120; - private final static int SC_TASKLIST = 0xF130; - private final static int SC_SCREENSAVE = 0xF140; - private final static int SC_HOTKEY = 0xF150; - private final static int SC_DEFAULT = 0xF160; - private final static int SC_MONITORPOWER = 0xF170; - private final static int SC_CONTEXTHELP = 0xF180; - private final static int SC_SEPARATOR = 0xF00F; + private static final int WM_QUIT = 0x0012; + private static final int WM_SYSCOMMAND = 0x0112; + private static final int WM_PAINT = 0x000F; + private static final int WM_KILLFOCUS = 8; + private static final int WM_SETFOCUS = 7; - final static int SM_CXCURSOR = 13; - final static int SM_CYCURSOR = 14; - final static int SM_CMOUSEBUTTONS = 43; - final static int SM_MOUSEWHEELPRESENT = 75; + private static final int SC_SIZE = 0xF000; + private static final int SC_MOVE = 0xF010; + private static final int SC_MINIMIZE = 0xF020; + private static final int SC_MAXIMIZE = 0xF030; + private static final int SC_NEXTWINDOW = 0xF040; + private static final int SC_PREVWINDOW = 0xF050; + private static final int SC_CLOSE = 0xF060; + private static final int SC_VSCROLL = 0xF070; + private static final int SC_HSCROLL = 0xF080; + private static final int SC_MOUSEMENU = 0xF090; + private static final int SC_KEYMENU = 0xF100; + private static final int SC_ARRANGE = 0xF110; + private static final int SC_RESTORE = 0xF120; + private static final int SC_TASKLIST = 0xF130; + private static final int SC_SCREENSAVE = 0xF140; + private static final int SC_HOTKEY = 0xF150; + private static final int SC_DEFAULT = 0xF160; + private static final int SC_MONITORPOWER = 0xF170; + private static final int SC_CONTEXTHELP = 0xF180; + private static final int SC_SEPARATOR = 0xF00F; - private final static int SIZE_RESTORED = 0; - private final static int SIZE_MINIMIZED = 1; - private final static int SIZE_MAXIMIZED = 2; - private final static int WM_SIZE = 0x0005; - private final static int WM_ACTIVATE = 0x0006; - private final static int WA_INACTIVE = 0; - private final static int WA_ACTIVE = 1; - private final static int WA_CLICKACTIVE = 2; - private final static int SW_SHOWMINNOACTIVE = 7; - private final static int SW_SHOWDEFAULT = 10; - private final static int SW_RESTORE = 9; + static final int SM_CXCURSOR = 13; + static final int SM_CYCURSOR = 14; + static final int SM_CMOUSEBUTTONS = 43; + static final int SM_MOUSEWHEELPRESENT = 75; - private final static int ICON_SMALL = 0; - private final static int ICON_BIG = 1; + private static final int SIZE_RESTORED = 0; + private static final int SIZE_MINIMIZED = 1; + private static final int SIZE_MAXIMIZED = 2; + private static final int WM_SIZE = 0x0005; + private static final int WM_ACTIVATE = 0x0006; + private static final int WA_INACTIVE = 0; + private static final int WA_ACTIVE = 1; + private static final int WA_CLICKACTIVE = 2; + private static final int SW_SHOWMINNOACTIVE = 7; + private static final int SW_SHOWDEFAULT = 10; + private static final int SW_RESTORE = 9; - private final static IntBuffer rect_buffer = BufferUtils.createIntBuffer(4); - private final static Rect rect = new Rect(); - private final static Rect rect2 = new Rect(); + private static final int ICON_SMALL = 0; + private static final int ICON_BIG = 1; + + private static final IntBuffer rect_buffer = BufferUtils.createIntBuffer(4); + private static final Rect rect = new Rect(); + private static final Rect rect2 = new Rect(); private static WindowsDisplay current_display; private static boolean cursor_clipped; private WindowsDisplayPeerInfo peer_info; private Object current_cursor; private Canvas parent; - private static boolean hasParent = false; + private static boolean hasParent; private WindowsKeyboard keyboard; private WindowsMouse mouse; @@ -156,8 +156,8 @@ final class WindowsDisplay implements DisplayImplementation { private long large_icon; private int captureMouse = -1; - private boolean trackingMouse = false; - private boolean mouseInside = false; + private boolean trackingMouse; + private boolean mouseInside; WindowsDisplay() { current_display = this; @@ -378,7 +378,7 @@ final class WindowsDisplay implements DisplayImplementation { String driver = getAdapter(); if (driver != null) { String[] drivers = driver.split(","); - if(drivers.length>0) { + if(drivers.length>0) { WindowsFileVersion version = nGetVersion(drivers[0] + ".dll"); if (version != null) return version.toString(); @@ -664,19 +664,19 @@ final class WindowsDisplay implements DisplayImplementation { int small_icon_size = 16; int large_icon_size = 32; - for (int i=0;i>> 16) & 0xFF); if (keyboard != null) { keyboard.handleKey((int)wParam, scan_code, extended != 0, state, millis, repeat); - + if(captureMouse != -1 && keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { nReleaseCapture(); captureMouse = -1; @@ -869,7 +869,7 @@ final class WindowsDisplay implements DisplayImplementation { // Set key state to pressed long fake_lparam = lParam & ~(1 << 31); // Set key previous state to released - fake_lparam = fake_lparam & ~(1 << 30); + fake_lparam &= ~(1 << 30); handleKeyButton(wParam, fake_lparam, millis); } /* Fall through */ @@ -923,7 +923,7 @@ final class WindowsDisplay implements DisplayImplementation { public int getHeight() { return Display.getDisplayMode().getHeight(); } - + private int firstMouseButtonDown() { for(int i=0; i" or "\|" on RT 102-key kbd. - public final static int VK_ICO_HELP = 0xE3; // Help key on ICO - public final static int VK_ICO_00 = 0xE4; // 00 key on ICO +public static final int VK_OEM_AX = 0xE1; // 'AX' key on Japanese AX kbd + public static final int VK_OEM_102 = 0xE2; // "<>" or "\|" on RT 102-key kbd. + public static final int VK_ICO_HELP = 0xE3; // Help key on ICO + public static final int VK_ICO_00 = 0xE4; // 00 key on ICO - public final static int VK_PROCESSKEY = 0xE5; + public static final int VK_PROCESSKEY = 0xE5; - public final static int VK_ICO_CLEAR = 0xE6; + public static final int VK_ICO_CLEAR = 0xE6; - public final static int VK_PACKET = 0xE7; + public static final int VK_PACKET = 0xE7; /* * 0xE8 : unassigned */ - + /* * Nokia/Ericsson definitions */ - public final static int VK_OEM_RESET = 0xE9; - public final static int VK_OEM_JUMP = 0xEA; - public final static int VK_OEM_PA1 = 0xEB; - public final static int VK_OEM_PA2 = 0xEC; - public final static int VK_OEM_PA3 = 0xED; - public final static int VK_OEM_WSCTRL = 0xEE; - public final static int VK_OEM_CUSEL = 0xEF; - public final static int VK_OEM_ATTN = 0xF0; - public final static int VK_OEM_FINISH = 0xF1; - public final static int VK_OEM_COPY = 0xF2; - public final static int VK_OEM_AUTO = 0xF3; - public final static int VK_OEM_ENLW = 0xF4; - public final static int VK_OEM_BACKTAB = 0xF5; +public static final int VK_OEM_RESET = 0xE9; + public static final int VK_OEM_JUMP = 0xEA; + public static final int VK_OEM_PA1 = 0xEB; + public static final int VK_OEM_PA2 = 0xEC; + public static final int VK_OEM_PA3 = 0xED; + public static final int VK_OEM_WSCTRL = 0xEE; + public static final int VK_OEM_CUSEL = 0xEF; + public static final int VK_OEM_ATTN = 0xF0; + public static final int VK_OEM_FINISH = 0xF1; + public static final int VK_OEM_COPY = 0xF2; + public static final int VK_OEM_AUTO = 0xF3; + public static final int VK_OEM_ENLW = 0xF4; + public static final int VK_OEM_BACKTAB = 0xF5; - public final static int VK_ATTN = 0xF6; - public final static int VK_CRSEL = 0xF7; - public final static int VK_EXSEL = 0xF8; - public final static int VK_EREOF = 0xF9; - public final static int VK_PLAY = 0xFA; - public final static int VK_ZOOM = 0xFB; - public final static int VK_NONAME = 0xFC; - public final static int VK_PA1 = 0xFD; - public final static int VK_OEM_CLEAR = 0xFE; + public static final int VK_ATTN = 0xF6; + public static final int VK_CRSEL = 0xF7; + public static final int VK_EXSEL = 0xF8; + public static final int VK_EREOF = 0xF9; + public static final int VK_PLAY = 0xFA; + public static final int VK_ZOOM = 0xFB; + public static final int VK_NONAME = 0xFC; + public static final int VK_PA1 = 0xFD; + public static final int VK_OEM_CLEAR = 0xFE; public static int mapVirtualKeyToLWJGLCode(int virt_key) { switch (virt_key) { diff --git a/src/java/org/lwjgl/opengl/WindowsRegistry.java b/src/java/org/lwjgl/opengl/WindowsRegistry.java index f84e6820..50e8635c 100644 --- a/src/java/org/lwjgl/opengl/WindowsRegistry.java +++ b/src/java/org/lwjgl/opengl/WindowsRegistry.java @@ -40,15 +40,15 @@ import org.lwjgl.LWJGLException; import org.lwjgl.Sys; final class WindowsRegistry { - final static int HKEY_CLASSES_ROOT = 1; - final static int HKEY_CURRENT_USER = 2; - final static int HKEY_LOCAL_MACHINE = 3; - final static int HKEY_USERS = 4; + static final int HKEY_CLASSES_ROOT = 1; + static final int HKEY_CURRENT_USER = 2; + static final int HKEY_LOCAL_MACHINE = 3; + static final int HKEY_USERS = 4; static { Sys.initialize(); } - + /** * Query the registry value specified by the root key, subkey, value tuple */ @@ -64,6 +64,6 @@ final class WindowsRegistry { } return nQueryRegistrationKey(root_key, subkey, value); } - + private static native String nQueryRegistrationKey(int root_key, String subkey, String value) throws LWJGLException; } diff --git a/src/java/org/lwjgl/opengl/XRandR.java b/src/java/org/lwjgl/opengl/XRandR.java index 24e263ae..f09af931 100644 --- a/src/java/org/lwjgl/opengl/XRandR.java +++ b/src/java/org/lwjgl/opengl/XRandR.java @@ -42,20 +42,20 @@ import org.lwjgl.LWJGLUtil; /** * Utility for working with the xrandr commmand-line utility. Assumes * xrandr v1.2 or higher. - * + * * @author ryanm */ public class XRandR { private static Screen[] current; - private static Map /* */screens; + private static Map screens; private static void populate() { if( screens == null ) { - screens = new HashMap/* */(); + screens = new HashMap(); // 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/* */currentList = new ArrayList/* */(); - List/* */possibles = new ArrayList/* */(); + List currentList = new ArrayList(); + List possibles = new ArrayList(); 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/* */cmd = new ArrayList/* */(); + List cmd = new ArrayList(); cmd.add( "xrandr" ); // switch off those in the current set not in the new set - for( int i = 0; i < current.length; i++ ) - { + for ( Screen screen : current ) { boolean found = false; - for( int j = 0; j < screens.length; j++ ) - { - if( screens[ j ].name.equals( current[ i ].name ) ) - { + for ( Screen screen1 : screens ) { + if ( screen1.name.equals(screen.name) ) { found = true; break; } } - if( !found ) - { - cmd.add( "--output" ); - cmd.add( current[ i ].name ); - cmd.add( "--off" ); + if ( !found ) { + cmd.add("--output"); + cmd.add(screen.name); + cmd.add("--off"); } } // set up new set - for( int i = 0; i < screens.length; i++ ) - { - screens[ i ].getArgs( cmd ); - } + for ( Screen screen : screens ) + screen.getArgs(cmd); try { @@ -168,7 +160,7 @@ public class XRandR // pb.redirectErrorStream(); // Process p = pb.start(); Process p = - Runtime.getRuntime().exec( ( String[] ) cmd.toArray( new String[ cmd.size() ] ) ); + Runtime.getRuntime().exec( cmd.toArray( new String[ cmd.size() ] ) ); // no output is expected, but check anyway BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); String line; @@ -191,7 +183,7 @@ public class XRandR public static String[] getScreenNames() { populate(); - return ( String[] ) screens.keySet().toArray( new String[ screens.size() ] ); + return screens.keySet().toArray( new String[ screens.size() ] ); } /** @@ -203,7 +195,7 @@ public class XRandR { populate(); // clone the array to prevent held copies being altered - return (Screen[]) ((Screen[]) screens.get(name)).clone(); + return screens.get(name).clone(); } private static final Pattern SCREEN_PATTERN1 = @@ -214,7 +206,7 @@ public class XRandR /** * Parses a screen configuration and adds it to the list if it's * valid. - * + * * @param list * the list to add the Screen to if it's valid * @param name @@ -223,7 +215,7 @@ public class XRandR * config string, format either widthxheight or * widthxheight+xPos+yPos */ - private static void parseScreen( List /* */list, String name, String what ) + private static void parseScreen( List list, String name, String what ) { Matcher m = SCREEN_PATTERN1.matcher( what ); if( !m.matches() ) @@ -254,7 +246,7 @@ public class XRandR /** * Encapsulates the configuration of a monitor. Resolution is * fixed, position is mutable - * + * * @author ryanm */ public static class Screen implements Cloneable @@ -277,12 +269,12 @@ public class XRandR /** * Position on the x-axis, in pixels */ - public int xPos = 0; + public int xPos; /** * Position on the y-axis, in pixels */ - public int yPos = 0; + public int yPos; private Screen( String name, int width, int height, int xPos, int yPos ) { @@ -293,7 +285,7 @@ public class XRandR this.yPos = yPos; } - private void getArgs( List/* */argList ) + private void getArgs( List argList ) { argList.add( "--output" ); argList.add( name ); diff --git a/src/java/org/lwjgl/test/DisplayTest.java b/src/java/org/lwjgl/test/DisplayTest.java index b1c2d6f5..0534d141 100644 --- a/src/java/org/lwjgl/test/DisplayTest.java +++ b/src/java/org/lwjgl/test/DisplayTest.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -44,13 +44,13 @@ import org.lwjgl.opengl.DisplayMode; * $Id$ */ public class DisplayTest { - + /** * Creates a new DisplayTest */ public DisplayTest() { } - + /** * Runs the tests */ @@ -58,31 +58,31 @@ public class DisplayTest { currentTest(); queryModesTest(); setDisplayModeTest(); - setDisplayConfigurationTest(); + setDisplayConfigurationTest(); } - + /** * Prints some info about the current mode */ private void currentTest() { System.out.println("==== Test Current ===="); - + System.out.println("Info about current:"); System.out.println("Graphics card: " + Display.getAdapter() + ", version: " + Display.getVersion()); - System.out.println("Resolution: " + - Display.getDisplayMode().getWidth() + "x" + - Display.getDisplayMode().getHeight() + "x" + - Display.getDisplayMode().getBitsPerPixel() + "@" + + System.out.println("Resolution: " + + Display.getDisplayMode().getWidth() + "x" + + Display.getDisplayMode().getHeight() + "x" + + Display.getDisplayMode().getBitsPerPixel() + "@" + Display.getDisplayMode().getFrequency() + "Hz"); System.out.println("---- Test Current ----"); } - + /** * Tests querying for modes */ private void queryModesTest() throws LWJGLException { DisplayMode[] modes = null; - + System.out.println("==== Test query ===="); System.out.println("Retrieving available displaymodes"); modes = Display.getAvailableDisplayModes(); @@ -92,7 +92,7 @@ public class DisplayTest { System.out.println("FATAL: unable to find any modes!"); System.exit(-1); } - + // write some info System.out.println("Found " + modes.length + " modes"); System.out.println("The first 5 are:"); @@ -104,42 +104,42 @@ public class DisplayTest { } System.out.println("---- Test query ----"); } - - + + /** * Tests setting display modes */ private void setDisplayModeTest() throws LWJGLException { DisplayMode mode = null; DisplayMode[] modes = null; - + System.out.println("==== Test setDisplayMode ===="); System.out.println("Retrieving available displaymodes"); modes = Display.getAvailableDisplayModes(); - + // no modes check if (modes == null) { System.out.println("FATAL: unable to find any modes!"); System.exit(-1); } - + // find a mode System.out.print("Looking for 640x480..."); - for(int i=0; i */ public class WindowCreationTest { /** Locatable modes */ private DisplayMode[] located_modes; - + /** Fixed selectable modes */ private DisplayMode[] fixed_modes = new DisplayMode[10]; - + /** Window position x */ - private int window_x = 0; + private int window_x; /** Window position y */ - private int window_y = 0; + private int window_y; /** Color being cleared to */ private float color = 0f; @@ -65,13 +67,13 @@ public class WindowCreationTest { private int direction = 1; /** Whether we're running */ - private boolean running = false; + private boolean running; /** Whether we're in fullscreen mode */ - private boolean fullscreen = false; - + private boolean fullscreen; + /** - * Initializes the test + * Initializes the test * @return true if initialization was successfull */ public boolean initialize() { @@ -79,16 +81,16 @@ public class WindowCreationTest { // get available modes, and print out located_modes = Display.getAvailableDisplayModes(); System.out.println("Found " + located_modes.length + " display modes"); - + // get 640x480, 800x600, 1024x768 modes findFixedModes(); // create default windowed display 640*480 @ 100, 100 setDefaultDisplayMode(); - + window_x = window_y = 100; Display.setLocation(window_x, window_y); - + Display.create(); return true; } catch (LWJGLException le) { @@ -96,7 +98,7 @@ public class WindowCreationTest { } return false; } - + /** Locate fixed modes */ private void findFixedModes() { // get 640*480 modes @@ -151,7 +153,7 @@ public class WindowCreationTest { } /** - * Handles the input + * Handles the input */ private void handleInput() { while (Keyboard.next()) { @@ -165,14 +167,14 @@ public class WindowCreationTest { if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { running = false; } - + // check for listing of modes if (Keyboard.getEventKey() == Keyboard.KEY_L) { for(int i=0;i System.currentTimeMillis()) { fps++; } else { long timeUsed = 5000 + (startTime - System.currentTimeMillis()); startTime = System.currentTimeMillis() + 5000; - System.out.println(fps + " frames 2 in " + (float) (timeUsed / 1000f) + " seconds = " + System.out.println(fps + " frames 2 in " + timeUsed / 1000f + " seconds = " + (fps / (timeUsed / 1000f))); fps = 0; } - + if (Mouse.isButtonDown(0)) { if (!mouseButtonDown) { prevMouseX = Mouse.getX(); @@ -159,25 +160,25 @@ public class GearsApplet extends Applet { else { mouseButtonDown = false; } - + if (mouseButtonDown) { int x = Mouse.getX(); int y = Mouse.getY(); - + float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)display_parent.getWidth()); float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)display_parent.getHeight()); - + prevMouseX = x; prevMouseY = y; - + view_rotx += thetaX; view_roty += thetaY; } - + // F Key Pressed (i.e. released) if (keyDown && !Keyboard.isKeyDown(Keyboard.KEY_F)) { keyDown = false; - + try { if (Display.isFullscreen()) { Display.setFullscreen(false); @@ -190,38 +191,38 @@ public class GearsApplet extends Applet { } } } - + Display.destroy(); } - + public void drawLoop() { - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); - - GL11.glPushMatrix(); - - GL11.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); - GL11.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); - GL11.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); - - GL11.glPushMatrix(); - GL11.glTranslatef(-3.0f, -2.0f, 0.0f); - GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f); - GL11.glCallList(gear1); - GL11.glPopMatrix(); - - GL11.glPushMatrix(); - GL11.glTranslatef(3.1f, -2.0f, 0.0f); - GL11.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); - GL11.glCallList(gear2); - GL11.glPopMatrix(); - - GL11.glPushMatrix(); - GL11.glTranslatef(-3.1f, 4.2f, 0.0f); - GL11.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); - GL11.glCallList(gear3); - GL11.glPopMatrix(); - - GL11.glPopMatrix(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); + glRotatef(view_roty, 0.0f, 1.0f, 0.0f); + glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); + + glPushMatrix(); + glTranslatef(-3.0f, -2.0f, 0.0f); + glRotatef(angle, 0.0f, 0.0f, 1.0f); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1f, -2.0f, 0.0f); + glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1f, 4.2f, 0.0f); + glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); } protected void initGL() { @@ -231,62 +232,62 @@ public class GearsApplet extends Applet { FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f}); FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] { 0.0f, 0.8f, 0.2f, 1.0f}); FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] { 0.2f, 0.2f, 1.0f, 1.0f}); - + pos.flip(); red.flip(); green.flip(); blue.flip(); - - GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos); - GL11.glEnable(GL11.GL_CULL_FACE); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_LIGHT0); - GL11.glEnable(GL11.GL_DEPTH_TEST); + + glLight(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); /* make the gears */ - gear1 = GL11.glGenLists(1); - GL11.glNewList(gear1, GL11.GL_COMPILE); - GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red); + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); gear(1.0f, 4.0f, 1.0f, 20, 0.7f); - GL11.glEndList(); - - gear2 = GL11.glGenLists(1); - GL11.glNewList(gear2, GL11.GL_COMPILE); - GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, green); + glEndList(); + + gear2 = glGenLists(1); + glNewList(gear2, GL_COMPILE); + glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); gear(0.5f, 2.0f, 2.0f, 10, 0.7f); - GL11.glEndList(); - - gear3 = GL11.glGenLists(1); - GL11.glNewList(gear3, GL11.GL_COMPILE); - GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, blue); + glEndList(); + + gear3 = glGenLists(1); + glNewList(gear3, GL_COMPILE); + glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); gear(1.3f, 2.0f, 0.5f, 10, 0.7f); - GL11.glEndList(); - GL11.glEnable(GL11.GL_NORMALIZE); - GL11.glMatrixMode(GL11.GL_PROJECTION); - + glEndList(); + glEnable(GL_NORMALIZE); + glMatrixMode(GL_PROJECTION); + System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName()); - System.err.println("GL_VENDOR: " + GL11.glGetString(GL11.GL_VENDOR)); - System.err.println("GL_RENDERER: " + GL11.glGetString(GL11.GL_RENDERER)); - System.err.println("GL_VERSION: " + GL11.glGetString(GL11.GL_VERSION)); + System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR)); + System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER)); + System.err.println("GL_VERSION: " + glGetString(GL_VERSION)); System.err.println(); System.err.println("glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix); - + if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) { // --- not using extensions - GL11.glLoadIdentity(); + glLoadIdentity(); } else { // --- using extensions final FloatBuffer identityTranspose = BufferUtils.createFloatBuffer(16).put( new float[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}); identityTranspose.flip(); - ARBTransposeMatrix.glLoadTransposeMatrixARB(identityTranspose); + glLoadTransposeMatrixARB(identityTranspose); } float h = (float) display_parent.getHeight() / (float) display_parent.getWidth(); - GL11.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - GL11.glLoadIdentity(); - GL11.glTranslatef(0.0f, 0.0f, -40.0f); + glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -40.0f); } catch (Exception e) { System.err.println(e); running = false; @@ -313,92 +314,92 @@ public class GearsApplet extends Applet { r1 = outer_radius - tooth_depth / 2.0f; r2 = outer_radius + tooth_depth / 2.0f; da = 2.0f * (float) Math.PI / teeth / 4.0f; - GL11.glShadeModel(GL11.GL_FLAT); - GL11.glNormal3f(0.0f, 0.0f, 1.0f); + glShadeModel(GL_FLAT); + glNormal3f(0.0f, 0.0f, 1.0f); /* draw front face */ - GL11.glBegin(GL11.GL_QUAD_STRIP); + glBegin(GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) { angle = i * 2.0f * (float) Math.PI / teeth; - GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f); - GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f); + glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f); if (i < teeth) { - GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f); - GL11.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), + glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f); } } - GL11.glEnd(); + glEnd(); /* draw front sides of teeth */ - GL11.glBegin(GL11.GL_QUADS); + glBegin(GL_QUADS); for (i = 0; i < teeth; i++) { angle = i * 2.0f * (float) Math.PI / teeth; - GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f); - GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f); - GL11.glVertex3f(r2 * (float) Math.cos(angle + 2.0f * da), r2 * (float) Math.sin(angle + 2.0f * da), width * 0.5f); - GL11.glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f); + glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f); + glVertex3f(r2 * (float) Math.cos(angle + 2.0f * da), r2 * (float) Math.sin(angle + 2.0f * da), width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle + 3.0f * da), r1 * (float) Math.sin(angle + 3.0f * da), width * 0.5f); } - GL11.glEnd(); + glEnd(); /* draw back face */ - GL11.glBegin(GL11.GL_QUAD_STRIP); + glBegin(GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) { angle = i * 2.0f * (float) Math.PI / teeth; - GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f); - GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f); - GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f); - GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f); + glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f); + glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f); } - GL11.glEnd(); + glEnd(); /* draw back sides of teeth */ - GL11.glBegin(GL11.GL_QUADS); + glBegin(GL_QUADS); for (i = 0; i < teeth; i++) { angle = i * 2.0f * (float) Math.PI / teeth; - GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f); - GL11.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f); - GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f); - GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f); + glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f); + glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f); } - GL11.glEnd(); + glEnd(); /* draw outward faces of teeth */ - GL11.glBegin(GL11.GL_QUAD_STRIP); + glBegin(GL_QUAD_STRIP); for (i = 0; i < teeth; i++) { angle = i * 2.0f * (float) Math.PI / teeth; - GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f); - GL11.glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle), r1 * (float) Math.sin(angle), -width * 0.5f); u = r2 * (float) Math.cos(angle + da) - r1 * (float) Math.cos(angle); v = r2 * (float) Math.sin(angle + da) - r1 * (float) Math.sin(angle); len = (float) Math.sqrt(u * u + v * v); u /= len; v /= len; - GL11.glNormal3f(v, -u, 0.0f); - GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f); - GL11.glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f); - GL11.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f); - GL11.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), width * 0.5f); - GL11.glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f); + glNormal3f(v, -u, 0.0f); + glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), width * 0.5f); + glVertex3f(r2 * (float) Math.cos(angle + da), r2 * (float) Math.sin(angle + da), -width * 0.5f); + glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f); + glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), width * 0.5f); + glVertex3f(r2 * (float) Math.cos(angle + 2 * da), r2 * (float) Math.sin(angle + 2 * da), -width * 0.5f); u = r1 * (float) Math.cos(angle + 3 * da) - r2 * (float) Math.cos(angle + 2 * da); v = r1 * (float) Math.sin(angle + 3 * da) - r2 * (float) Math.sin(angle + 2 * da); - GL11.glNormal3f(v, -u, 0.0f); - GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), width * 0.5f); - GL11.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f); - GL11.glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f); + glNormal3f(v, -u, 0.0f); + glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), width * 0.5f); + glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1 * (float) Math.sin(angle + 3 * da), -width * 0.5f); + glNormal3f((float) Math.cos(angle), (float) Math.sin(angle), 0.0f); } - GL11.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), width * 0.5f); - GL11.glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), -width * 0.5f); - GL11.glEnd(); + glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), width * 0.5f); + glVertex3f(r1 * (float) Math.cos(0), r1 * (float) Math.sin(0), -width * 0.5f); + glEnd(); - GL11.glShadeModel(GL11.GL_SMOOTH); + glShadeModel(GL_SMOOTH); /* draw inside radius cylinder */ - GL11.glBegin(GL11.GL_QUAD_STRIP); + glBegin(GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) { angle = i * 2.0f * (float) Math.PI / teeth; - GL11.glNormal3f(-(float) Math.cos(angle), -(float) Math.sin(angle), 0.0f); - GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f); - GL11.glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f); + glNormal3f(-(float) Math.cos(angle), -(float) Math.sin(angle), 0.0f); + glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), -width * 0.5f); + glVertex3f(r0 * (float) Math.cos(angle), r0 * (float) Math.sin(angle), width * 0.5f); } - GL11.glEnd(); + glEnd(); } } \ No newline at end of file diff --git a/src/java/org/lwjgl/test/applet/OpenAL.java b/src/java/org/lwjgl/test/applet/OpenAL.java index 778900c7..4ce774db 100644 --- a/src/java/org/lwjgl/test/applet/OpenAL.java +++ b/src/java/org/lwjgl/test/applet/OpenAL.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -39,26 +39,27 @@ import org.lwjgl.openal.AL; import org.lwjgl.openal.AL10; import org.lwjgl.opengl.AWTGLCanvas; import org.lwjgl.opengl.Display; -import org.lwjgl.opengl.GL11; import org.lwjgl.util.WaveData; +import static org.lwjgl.opengl.GL11.*; + public class OpenAL extends AWTGLCanvas implements Test { - float angle = 0; - + float angle; + // create 1 buffer and 1 source IntBuffer buffers = BufferUtils.createIntBuffer(1); - IntBuffer sources = BufferUtils.createIntBuffer(1); + IntBuffer sources = BufferUtils.createIntBuffer(1); public OpenAL() throws LWJGLException { - + try { AL.create(); } catch (Exception e) { System.out.println("Unable to create OpenAL.\nPlease make sure that OpenAL is available on this system. Exception: " + e); return; - } - + } + Thread t = new Thread() { public void run() { @@ -75,7 +76,7 @@ public class OpenAL extends AWTGLCanvas implements Test { private void playOpenAL() { int lastError; - + // al generate buffers and sources buffers.position(0).limit(1); AL10.alGenBuffers(buffers); @@ -88,37 +89,37 @@ public class OpenAL extends AWTGLCanvas implements Test { if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) { exit(lastError); } - + // load wave data from buffer WaveData wavefile = WaveData.create(getClass().getClassLoader().getResourceAsStream("Footsteps.wav")); //copy to buffers AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate); - + //unload file again - wavefile.dispose(); - + wavefile.dispose(); + if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) { exit(lastError); - } + } //set up source input AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0)); if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) { exit(lastError); - } - + } + //lets loop the sound AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE); if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) { exit(lastError); - } - + } + //play source 0 AL10.alSourcePlay(sources.get(0)); if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) { exit(lastError); - } + } } private void exit(int error) { @@ -126,22 +127,22 @@ public class OpenAL extends AWTGLCanvas implements Test { } public void paintGL() { - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); - GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX); - GL11.glLoadIdentity(); - GL11.glOrtho(0, 640, 0, 480, 1, -1); - GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX); + glClear(GL_COLOR_BUFFER_BIT); + glMatrixMode(GL_PROJECTION_MATRIX); + glLoadIdentity(); + glOrtho(0, 640, 0, 480, 1, -1); + glMatrixMode(GL_MODELVIEW_MATRIX); - GL11.glPushMatrix(); - GL11.glTranslatef(320, 240, 0.0f); - GL11.glRotatef(angle, 0, 0, 1.0f); - GL11.glBegin(GL11.GL_QUADS); - GL11.glVertex2i(-50, -50); - GL11.glVertex2i(50, -50); - GL11.glVertex2i(50, 50); - GL11.glVertex2i(-50, 50); - GL11.glEnd(); - GL11.glPopMatrix(); + glPushMatrix(); + glTranslatef(320, 240, 0.0f); + glRotatef(angle, 0, 0, 1.0f); + glBegin(GL_QUADS); + glVertex2i(-50, -50); + glVertex2i(50, -50); + glVertex2i(50, 50); + glVertex2i(-50, 50); + glEnd(); + glPopMatrix(); angle += 1; @@ -152,31 +153,31 @@ public class OpenAL extends AWTGLCanvas implements Test { } public void start() { - playOpenAL(); + playOpenAL(); } public void stop() { int lastError; - + //stop source 0 AL10.alSourceStop(sources.get(0)); if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) { exit(lastError); - } - + } + //delete buffers and sources sources.position(0).limit(1); AL10.alDeleteSources(sources); if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) { exit(lastError); } - + buffers.position(0).limit(1); AL10.alDeleteBuffers(buffers); if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) { exit(lastError); } - + AL.destroy(); } } diff --git a/src/java/org/lwjgl/test/applet/OpenGL.java b/src/java/org/lwjgl/test/applet/OpenGL.java index 88284c27..59d3dbc3 100644 --- a/src/java/org/lwjgl/test/applet/OpenGL.java +++ b/src/java/org/lwjgl/test/applet/OpenGL.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -35,11 +35,12 @@ import org.lwjgl.LWJGLException; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.AWTGLCanvas; -import org.lwjgl.opengl.GL11; + +import static org.lwjgl.opengl.GL11.*; public class OpenGL extends AWTGLCanvas implements Test { - float angle = 0; + float angle; float x; float y; @@ -47,28 +48,28 @@ public class OpenGL extends AWTGLCanvas implements Test { } public void initGL() { - GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX); - GL11.glLoadIdentity(); - GL11.glOrtho(0, 640, 0, 480, 1, -1); + glMatrixMode(GL_PROJECTION_MATRIX); + glLoadIdentity(); + glOrtho(0, 640, 0, 480, 1, -1); x = 320; y = 240; - GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX); + glMatrixMode(GL_MODELVIEW_MATRIX); setVSyncEnabled(true); } public void paintGL() { - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); - GL11.glPushMatrix(); - GL11.glTranslatef(x, y, 0.0f); - GL11.glRotatef(angle, 0, 0, 1.0f); - GL11.glBegin(GL11.GL_QUADS); - GL11.glVertex2i(-50, -50); - GL11.glVertex2i(50, -50); - GL11.glVertex2i(50, 50); - GL11.glVertex2i(-50, 50); - GL11.glEnd(); - GL11.glPopMatrix(); + glPushMatrix(); + glTranslatef(x, y, 0.0f); + glRotatef(angle, 0, 0, 1.0f); + glBegin(GL_QUADS); + glVertex2i(-50, -50); + glVertex2i(50, -50); + glVertex2i(50, 50); + glVertex2i(-50, 50); + glEnd(); + glPopMatrix(); angle += 1; diff --git a/src/java/org/lwjgl/test/applet/Speed.java b/src/java/org/lwjgl/test/applet/Speed.java index 3c42ed7c..87317da8 100644 --- a/src/java/org/lwjgl/test/applet/Speed.java +++ b/src/java/org/lwjgl/test/applet/Speed.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -33,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,10 +78,10 @@ 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; - } + } } public void start() { diff --git a/src/java/org/lwjgl/test/applet/Test.java b/src/java/org/lwjgl/test/applet/Test.java index 35a79f10..18bea65b 100644 --- a/src/java/org/lwjgl/test/applet/Test.java +++ b/src/java/org/lwjgl/test/applet/Test.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -33,6 +33,6 @@ package org.lwjgl.test.applet; public interface Test { - public void start(); - public void stop(); + void start(); + void stop(); } diff --git a/src/java/org/lwjgl/test/glu/tessellation/TessCallback.java b/src/java/org/lwjgl/test/glu/tessellation/TessCallback.java index 15253d39..31024543 100644 --- a/src/java/org/lwjgl/test/glu/tessellation/TessCallback.java +++ b/src/java/org/lwjgl/test/glu/tessellation/TessCallback.java @@ -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) { @@ -49,7 +50,7 @@ public class TessCallback extends GLUtessellatorCallbackAdapter { combined[3] = 1; combined[4] = 1; combined[5] = 1; - + outData[i] = new VertexData(combined); } // vertex[0] = coords[0]; @@ -66,15 +67,15 @@ public class TessCallback extends GLUtessellatorCallbackAdapter { // // *dataOut = vertex; } - + 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]); } } diff --git a/src/java/org/lwjgl/test/glu/tessellation/TessellationTest.java b/src/java/org/lwjgl/test/glu/tessellation/TessellationTest.java index c3b57002..e6e84600 100644 --- a/src/java/org/lwjgl/test/glu/tessellation/TessellationTest.java +++ b/src/java/org/lwjgl/test/glu/tessellation/TessellationTest.java @@ -33,32 +33,33 @@ 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(); - + // Create a new tessellation object + 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) { for (int x = 0; x < num_vertices; x++) //loop through the vertices @@ -66,7 +67,7 @@ public class TessellationTest { tesselator.gluTessVertex(obj_data[x], 0, new VertexData(obj_data[x])); //store the vertex } } - + void beginPolygon() { tesselator.gluTessBeginPolygon(null); @@ -76,7 +77,7 @@ public class TessellationTest { { tesselator.gluTessEndPolygon(); } - + void beginContour() { tesselator.gluTessBeginContour(); @@ -86,7 +87,7 @@ public class TessellationTest { { tesselator.gluTessEndContour(); } - + void end() { tesselator.gluDeleteTess(); @@ -95,47 +96,47 @@ public class TessellationTest { private void createDisplay() throws LWJGLException { int width = 300; int height = 300; - + Display.setDisplayMode(new DisplayMode(width,height)); 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); - - GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - GL11.glClearDepth(1); - - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - - GL11.glViewport(0,0,width,height); - GL11.glMatrixMode(GL11.GL_MODELVIEW); + glEnable(GL_TEXTURE_2D); + glShadeModel(GL_SMOOTH); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); - GL11.glMatrixMode(GL11.GL_PROJECTION); - GL11.glLoadIdentity(); - GL11.glOrtho(0, width, height, 0, 1, -1); - GL11.glMatrixMode(GL11.GL_MODELVIEW); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClearDepth(1); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glViewport(0,0,width,height); + glMatrixMode(GL_MODELVIEW); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, height, 0, 1, -1); + glMatrixMode(GL_MODELVIEW); } - + private void loop() { while (true) { render(); Display.update(); Display.sync(100); - + if (Display.isCloseRequested()) { System.exit(0); } } } - + private void render() { - GL11.glTranslatef(150,125,0); - - GL11.glScalef(50,50,1); + glTranslatef(150,125,0); + + 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}, @@ -148,16 +149,16 @@ public class TessellationTest { {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; - + //second polygon: a triangle-3 vertices; second contour double tri[][] = {{0.3f, 0.3f, 0.0f, 0.0f, 0.0f, 0.0f}, {0.7f, 0.3f, 0.0f, 0.0f, 0.0f, 0.0f}, {0.5f, 0.7f, 0.0f, 0.0f, 0.0f, 0.0f} }; // 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(); @@ -181,13 +182,13 @@ public class TessellationTest { // delete the tess object end(); } - + private void start() throws LWJGLException { createDisplay(); init(); loop(); } - + public static void main(String[] argv) throws LWJGLException { TessellationTest test = new TessellationTest(); test.start(); diff --git a/src/java/org/lwjgl/test/input/HWCursorTest.java b/src/java/org/lwjgl/test/input/HWCursorTest.java index 9289fe99..a52d8162 100644 --- a/src/java/org/lwjgl/test/input/HWCursorTest.java +++ b/src/java/org/lwjgl/test/input/HWCursorTest.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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.*; /** * @@ -52,26 +53,26 @@ import org.lwjgl.util.glu.GLU; * $Id$ */ 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 */ public void execute() { initialize(); - + mainLoop(); - + cleanup(); } - + /** * Sets the display mode for fullscreen mode */ @@ -85,15 +86,15 @@ public class HWCursorTest { "height=" + 480, "freq=" + 60, "bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel() - }); + }); return true; } catch (Exception e) { e.printStackTrace(); } - + return false; - } - + } + /** * Initializes the test */ @@ -102,32 +103,32 @@ public class HWCursorTest { // start of in windowed mode setDisplayMode(); Display.create(); - + glInit(); - + initNativeCursors(); - + } catch (Exception e) { e.printStackTrace(); System.exit(-1); } } - + private static void initNativeCursors() throws Exception { if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) == 0) { System.out.println("No HW cursor support!"); System.exit(0); } - - cursor = new Cursor[3]; - + + cursors = new Cursor[3]; + int cursorImageCount = 1; int cursorWidth = Math.min(64, Cursor.getMaxCursorSize()); int cursorHeight = cursorWidth; IntBuffer cursorImages; IntBuffer cursorDelays; - - + + // Create a single cursor // ================================== cursorImages = ByteBuffer.allocateDirect(cursorWidth*cursorHeight*cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer(); @@ -138,32 +139,32 @@ 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 // ================================== cursorImageCount = 3; cursorImages = ByteBuffer.allocateDirect(cursorWidth*cursorHeight*cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer(); cursorDelays = ByteBuffer.allocateDirect(cursorImageCount*4).order(ByteOrder.nativeOrder()).asIntBuffer(); for(int i=0; i= 0 && button < 3 && Mouse.getEventButtonState()) { @@ -280,14 +281,14 @@ public class HWCursorTest { } } } - + /** * Processes keyboard input */ private void processKeyboard() { //check for fullscreen key if (Keyboard.isKeyDown(Keyboard.KEY_F)) { - + try { try { Mouse.setNativeCursor(null); @@ -295,19 +296,19 @@ public class HWCursorTest { e.printStackTrace(); System.exit(1); } - for(int i=0; i @@ -69,7 +70,7 @@ public class KeyboardTest { System.exit(-1); } } - + /** * Sets the display mode for fullscreen mode */ @@ -83,14 +84,14 @@ public class KeyboardTest { "height=" + 480, "freq=" + 60, "bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel() - }); + }); return true; } catch (Exception e) { e.printStackTrace(); } return false; - } + } private void setupDisplay(boolean fullscreen) { try { @@ -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() { @@ -159,7 +160,7 @@ public class KeyboardTest { System.out.println("Key character code: 0x" + Integer.toHexString(character_code)); System.out.println("Key character: " + Keyboard.getEventCharacter()); System.out.println("Repeat event: " + Keyboard.isRepeatEvent()); - + if (Keyboard.getEventKey() == Keyboard.KEY_R && Keyboard.getEventKeyState()) { Keyboard.enableRepeatEvents(!Keyboard.areRepeatEventsEnabled()); } @@ -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(); } /** diff --git a/src/java/org/lwjgl/test/input/MouseCreationTest.java b/src/java/org/lwjgl/test/input/MouseCreationTest.java index a5d69b3c..e38ff24c 100644 --- a/src/java/org/lwjgl/test/input/MouseCreationTest.java +++ b/src/java/org/lwjgl/test/input/MouseCreationTest.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -35,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.*; + /** *
* Mouse test @@ -49,7 +50,7 @@ import org.lwjgl.util.vector.Vector2f; public class MouseCreationTest { /** position of quad to draw */ private Vector2f position = new Vector2f(320.0f, 240.0f); - + /** Creates a new instance of MouseTest */ public MouseCreationTest() { } @@ -65,9 +66,9 @@ public class MouseCreationTest { System.exit(-1); } - initializeOpenGL(); + initializeOpenGL(); } - + /** * Sets the display mode for fullscreen mode */ @@ -81,32 +82,32 @@ public class MouseCreationTest { "height=" + 480, "freq=" + 60, "bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel() - }); + }); return true; } catch (Exception e) { e.printStackTrace(); } return false; - } - + } + 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() { initialize(false); System.out.println("Test ready:\n"); - + // windowed mode System.out.println("=========== WINDOWED MODE =============="); for(int i=0; i<2; i++) { @@ -114,12 +115,12 @@ public class MouseCreationTest { wiggleMouse(); System.out.println(""); } - + // recreate display in fullscreen mode System.out.print("Destroying display..."); - + System.out.println("success"); - + System.out.print("Entering fullscreen mode..."); try { Display.destroy(); @@ -128,8 +129,8 @@ public class MouseCreationTest { e.printStackTrace(); } System.out.println("success"); - - + + // fullscreen mode System.out.println("=========== FULLSCREEN MODE =============="); for(int i=0; i<2; i++) { @@ -137,7 +138,7 @@ public class MouseCreationTest { wiggleMouse(); System.out.println(""); } - + System.out.println("Test completed successfully!"); System.out.print("Shutting down..."); Display.destroy(); @@ -149,27 +150,27 @@ public class MouseCreationTest { long statustime = Sys.getTime(); long endtime = Sys.getTime() + Sys.getTimerResolution() * 5; - + while (Sys.getTime() < endtime) { Display.update(); // empty mouse buffer while(Mouse.next()); - + position.x += Mouse.getDX(); position.y += Mouse.getDY(); - + if(position.x<0) { position.x = 0; } else if (position.x>640-60) { position.x = 640-60; } - + if(position.y < 0) { position.y = 0; } else if (position.y>480-30) { position.y = 480-30; - } + } render(); @@ -180,30 +181,30 @@ public class MouseCreationTest { } System.out.println("thank you"); } - - private void render() { - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); - GL11.glBegin(GL11.GL_POLYGON); + private void render() { + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_POLYGON); { float color = 1.0f; int buttonDown = 0; - + for(int i=0;i * Mouse test @@ -51,39 +52,39 @@ import org.lwjgl.util.vector.Vector3f; public class MouseTest { /** Direction mouse has moved */ private int direction; - + /** Last button pressed */ - private int lastButton = 0; - + private int lastButton; + /** Last direction we scrolled in */ private int lastScrollDirection = -1; - + /** Width of window */ private static int WINDOW_WIDTH = 640; - + /** Height of window */ private static int WINDOW_HEIGHT = 640; - + /** Triangle size */ 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), new Vector3f(0,0,1) }; - + /** Triangles to paint */ - private Vector2f[] triangles = { + private Vector2f[] triangles = { new Vector2f(WINDOW_WIDTH/2, WINDOW_HEIGHT - triangleSize.y), new Vector2f(triangleSize.y, WINDOW_HEIGHT/2), new Vector2f(WINDOW_WIDTH/2, triangleSize.y), @@ -91,11 +92,11 @@ public class MouseTest { }; /** Whether the test is closing */ - private boolean closing = false; - + private boolean closing; + /** Fullscreen or not */ public static final boolean FULLSCREEN = false; - + /** Creates a new instance of MouseTest */ public MouseTest() { } @@ -107,7 +108,7 @@ public class MouseTest { setupMouse(); setupKeyboard(); } - + /** * Setup display */ @@ -123,16 +124,16 @@ public class MouseTest { System.exit(-1); } - initializeOpenGL(); + initializeOpenGL(); } - + /** * Sets the display mode for fullscreen mode */ protected boolean setDisplayMode() { // get modes DisplayMode dm = new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT); - + try { Display.setDisplayMode(dm); return true; @@ -141,20 +142,20 @@ public class MouseTest { } return false; - } + } /** * Initializes OpenGL * */ 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); } /** @@ -173,7 +174,7 @@ public class MouseTest { */ private void setupMouse() { } - + /** * Creates the keyboard */ @@ -187,19 +188,19 @@ public class MouseTest { // while not exiting while (!closing) { handleWindow(); - + // secondary check if(!closing) { - + // poll and check keyboard and mouse handleKeyboard(); handleMouse(); - + // pause and continue if minimized if(!Display.isVisible()) { if(Display.isDirty()) { render(); - } + } pause(100); continue; } @@ -214,7 +215,7 @@ public class MouseTest { /** * Pauses the current thread for a specified time - * + * * @param time milliseconds to pause */ private void pause(long time) { @@ -232,16 +233,16 @@ public class MouseTest { Display.update(); closing = Display.isCloseRequested(); } - + /** * handles the mouse */ private void handleMouse() { readBufferedMouse(); - + Display.setTitle("x: " + Mouse.getX() + ", y: " + Mouse.getY() + ", [0]: " + Mouse.isButtonDown(0) + ", [1]: " + Mouse.isButtonDown(1) + ", [2]: " + Mouse.isButtonDown(2) + ", inside: " + Mouse.isInsideWindow()); } - + /** * reads a mouse in buffered mode */ @@ -251,11 +252,11 @@ public class MouseTest { if(Mouse.getEventButton() != -1 && Mouse.getEventButtonState()) { lastButton = Mouse.getEventButton(); } - } - + } + updateState(); } - + /** * Updates our "model" * @@ -266,31 +267,31 @@ public class MouseTest { int dx = Mouse.getDX(); int dy = Mouse.getDY(); int dw = Mouse.getDWheel(); - - + + // get out if no movement if (dx == dy && dx == 0 && dw == 0) { return; } - + // determine direction moved // ============================ if(dx > 0) { direction = 3; } - + if(dx < 0) { direction = 1; } - + if(dy > 0) { direction = 0; } - + if(dy < 0) { direction = 2; } - + // ---------------------------- if(direction > -1) { @@ -299,23 +300,23 @@ 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; } } - + // get direction to update in if (dw > 0) { lastScrollDirection++; @@ -324,7 +325,7 @@ public class MouseTest { } else if (dw == 0) { return; } - + // over/underflow if(lastScrollDirection < 0) { lastScrollDirection = 3; @@ -334,84 +335,84 @@ 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(); } - + /** * Handles the keyboard */ private void handleKeyboard() { - + while(Keyboard.next()) { // closing on ESCAPE if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState()) { closing = true; } - + if(Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState()) { Mouse.setGrabbed(!Mouse.isGrabbed()); } } } - + /** * Does the "model logic" */ private void logic() { // "we fade to black" // =========================================== - for(int i=0; i filters = new HashMap(); + 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 ( final Entry 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 effects = new HashMap(); + 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 entry : entries ) { + if ( EFXUtil.isEffectSupported(entry.getValue()) ) + System.out.println(" " + entry.getKey()); + } } - + private void printDevices(int which, String kind) { String[] devices = ALC10.alcGetString(null, which).split("\0"); checkForErrors(); - + System.out.println("Available " + kind + " devices: "); - for(int i=0; i - * This test demonstrates OpenAL positioning Based on the example by Chad Armstrong + * This test demonstrates OpenAL positioning Based on the example by Chad Armstrong * (http://www.edenwaith.com/products/pige/tutorials/openal.php) - * + * * @author Brian Matzon * @version $Revision$ * $Id$ @@ -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,37 +196,37 @@ 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"); // ----------------------------------------------------- - + Mouse.setGrabbed(true); } @@ -260,7 +261,7 @@ public class PositionTest extends BasicTest { // allow window to process internal messages Display.update(); - + // render and paint if !minimized and not dirty if(Display.isVisible()) { render(); @@ -268,10 +269,10 @@ public class PositionTest extends BasicTest { // sleeeeeep pause(100); } - + // act on pause mode paused(!(Display.isVisible() || Display.isActive())); - + // start sound after first paint, since we don't want // the delay before something is painted on the screen if (firstRun && !pauseMode) { @@ -282,37 +283,37 @@ 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)); } - + /** * Handles any changes in pause mode - * + * * @param paused Which pause mode to enter */ private void paused(boolean paused) { // 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"); - } - + } + // else go out of pause mode and start sounds else if(!paused && pauseMode) { pauseMode = false; startSounds(); System.out.println("pauseMode = false"); - } + } } /** @@ -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,10 +391,10 @@ public class PositionTest extends BasicTest { } else { listenerPosition.put(2, listenerPosition.get(2) + 0.1f); } - AL10.alListener(AL10.AL_POSITION, listenerPosition); + alListener(AL_POSITION, listenerPosition); } // -------------------------------------------- - + // Test for movement with Mouse // ============================================ listenerPosition.put(0, listenerPosition.get(0) + (0.01f * Mouse.getDX())); @@ -404,9 +405,9 @@ public class PositionTest extends BasicTest { if (Mouse.isButtonDown(1)) { 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"); @@ -475,7 +476,7 @@ public class PositionTest extends BasicTest { /** * main entry point - * + * * @param args * String array containing arguments */ @@ -487,7 +488,7 @@ public class PositionTest extends BasicTest { /** * Minute implementation of GLUT:
COPYRIGHT: - * + * * The OpenGL Utility Toolkit distribution for Win32 (Windows NT & Windows * 95) contains source code modified from the original source code for GLUT * version 3.3 which was developed by Mark J. Kilgard. The original source @@ -496,7 +497,7 @@ public class PositionTest extends BasicTest { * freely distributable without licensing fees. It is provided without * guarantee or warrantee expressed or implied. It was ported with the * permission of Mark J. Kilgard by Nate Robins. - * + * * THIS SOURCE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. @@ -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(); } } diff --git a/src/java/org/lwjgl/test/opencl/HelloOpenCL.java b/src/java/org/lwjgl/test/opencl/HelloOpenCL.java index 76c5725c..f92e35db 100644 --- a/src/java/org/lwjgl/test/opencl/HelloOpenCL.java +++ b/src/java/org/lwjgl/test/opencl/HelloOpenCL.java @@ -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); diff --git a/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java b/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java index 1bc646fd..a4629e44 100644 --- a/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java +++ b/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java @@ -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; diff --git a/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java b/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java index 14bdbe4a..532ecdfb 100644 --- a/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java +++ b/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -36,14 +36,15 @@ 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 - * + * * @author Brian Matzon * @version $Revision$ * $Id$ @@ -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 @@ -235,7 +236,7 @@ public class FullScreenWindowedTest { /** * Retrieves a displaymode, if one such is available - * + * * @param width * Required width * @param height @@ -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); } diff --git a/src/java/org/lwjgl/test/opengl/Gears.java b/src/java/org/lwjgl/test/opengl/Gears.java index 1f789dce..1bb99e09 100644 --- a/src/java/org/lwjgl/test/opengl/Gears.java +++ b/src/java/org/lwjgl/test/opengl/Gears.java @@ -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.*; + /** *

* 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(); @@ -77,7 +78,7 @@ public class Gears { } /** - * + * */ private void execute() { try { @@ -94,14 +95,14 @@ public class Gears { } /** - * + * */ private void destroy() { Display.destroy(); } /** - * + * */ private void loop() { long startTime = System.currentTimeMillis() + 5000; @@ -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; } @@ -151,7 +152,7 @@ public class Gears { } /** - * + * */ private void init() throws LWJGLException { // create Window of size 300x300 @@ -166,64 +167,64 @@ public class Gears { FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f}); FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] { 0.0f, 0.8f, 0.2f, 1.0f}); FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] { 0.2f, 0.2f, 1.0f, 1.0f}); - + pos.flip(); red.flip(); green.flip(); blue.flip(); - GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos); - GL11.glEnable(GL11.GL_CULL_FACE); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_LIGHT0); - GL11.glEnable(GL11.GL_DEPTH_TEST); + glLight(GL_LIGHT0, GL_POSITION, pos); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_DEPTH_TEST); /* make the gears */ - gear1 = GL11.glGenLists(1); - GL11.glNewList(gear1, GL11.GL_COMPILE); - GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red); + gear1 = glGenLists(1); + glNewList(gear1, GL_COMPILE); + glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); gear(1.0f, 4.0f, 1.0f, 20, 0.7f); - GL11.glEndList(); + 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(); } } diff --git a/src/java/org/lwjgl/test/opengl/PbufferTest.java b/src/java/org/lwjgl/test/opengl/PbufferTest.java index 2d6c426a..c4e572bc 100644 --- a/src/java/org/lwjgl/test/opengl/PbufferTest.java +++ b/src/java/org/lwjgl/test/opengl/PbufferTest.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -39,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); } /** @@ -371,18 +369,18 @@ public class PbufferTest { private void glInit() { //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); } diff --git a/src/java/org/lwjgl/test/opengl/SyncTest.java b/src/java/org/lwjgl/test/opengl/SyncTest.java index cc8cd875..7746729f 100644 --- a/src/java/org/lwjgl/test/opengl/SyncTest.java +++ b/src/java/org/lwjgl/test/opengl/SyncTest.java @@ -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 */ 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; diff --git a/src/java/org/lwjgl/test/opengl/VBOIndexTest.java b/src/java/org/lwjgl/test/opengl/VBOIndexTest.java index 5d8cbb3c..315878f4 100644 --- a/src/java/org/lwjgl/test/opengl/VBOIndexTest.java +++ b/src/java/org/lwjgl/test/opengl/VBOIndexTest.java @@ -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(); } } diff --git a/src/java/org/lwjgl/test/opengl/VBOTest.java b/src/java/org/lwjgl/test/opengl/VBOTest.java index 61f5f69d..f79dd8d2 100644 --- a/src/java/org/lwjgl/test/opengl/VBOTest.java +++ b/src/java/org/lwjgl/test/opengl/VBOTest.java @@ -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(); } } diff --git a/src/java/org/lwjgl/test/opengl/VersionTest.java b/src/java/org/lwjgl/test/opengl/VersionTest.java index 87d3de40..41c55f38 100644 --- a/src/java/org/lwjgl/test/opengl/VersionTest.java +++ b/src/java/org/lwjgl/test/opengl/VersionTest.java @@ -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; diff --git a/src/java/org/lwjgl/test/opengl/awt/AWTGears.java b/src/java/org/lwjgl/test/opengl/awt/AWTGears.java index bae3ce27..c27d8c0d 100644 --- a/src/java/org/lwjgl/test/opengl/awt/AWTGears.java +++ b/src/java/org/lwjgl/test/opengl/awt/AWTGears.java @@ -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.*; + /** *

* AWT version of the gears demo @@ -55,15 +56,15 @@ import org.lwjgl.opengl.GLContext; * $Id$ */ public class AWTGears extends Frame { - + /** AWT GL canvas */ private AWTGLCanvas canvas0; - + 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; @@ -71,7 +72,7 @@ public class AWTGears extends Frame { private int gear3; - private float angle = 0.0f; + private float angle; /** * C'tor @@ -92,7 +93,7 @@ public class AWTGears extends Frame { pack(); setVisible(true); } - + private void setup() { // setup ogl FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f}); @@ -104,60 +105,60 @@ 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); } - + /** * Draw a gear wheel. You'll probably want to call this function when * building a display list since we do a lot of trig here. @@ -180,97 +181,97 @@ 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 { new AWTGears(); diff --git a/src/java/org/lwjgl/test/opengl/awt/AWTGearsCanvas.java b/src/java/org/lwjgl/test/opengl/awt/AWTGearsCanvas.java index c6dbb9aa..24b0bbb3 100644 --- a/src/java/org/lwjgl/test/opengl/awt/AWTGearsCanvas.java +++ b/src/java/org/lwjgl/test/opengl/awt/AWTGearsCanvas.java @@ -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.*; + /** *

* AWT version of the gears demo @@ -50,12 +51,12 @@ import org.lwjgl.test.applet.Test; * $Id$ */ public class AWTGearsCanvas extends AWTGLCanvas implements Test { - + 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; @@ -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; @@ -78,45 +79,45 @@ public class AWTGearsCanvas extends AWTGLCanvas implements Test { } public void paintGL() { - + if(startTime == 0) { setup(); startTime = System.currentTimeMillis() + 5000; } - + try { angle += 2.0f; 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); - - GL11.glPushMatrix(); - GL11.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); - GL11.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); - GL11.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); - - GL11.glPushMatrix(); - GL11.glTranslatef(-3.0f, -2.0f, 0.0f); - GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f); - GL11.glCallList(gear1); - GL11.glPopMatrix(); - - GL11.glPushMatrix(); - GL11.glTranslatef(3.1f, -2.0f, 0.0f); - GL11.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); - GL11.glCallList(gear2); - GL11.glPopMatrix(); - - GL11.glPushMatrix(); - GL11.glTranslatef(-3.1f, 4.2f, 0.0f); - GL11.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); - GL11.glCallList(gear3); - GL11.glPopMatrix(); - - GL11.glPopMatrix(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); + glRotatef(view_roty, 0.0f, 1.0f, 0.0f); + glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); + + glPushMatrix(); + glTranslatef(-3.0f, -2.0f, 0.0f); + glRotatef(angle, 0.0f, 0.0f, 1.0f); + glCallList(gear1); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(3.1f, -2.0f, 0.0f); + glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); + glCallList(gear2); + glPopMatrix(); + + glPushMatrix(); + glTranslatef(-3.1f, 4.2f, 0.0f); + glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); + glCallList(gear3); + glPopMatrix(); + + glPopMatrix(); swapBuffers(); repaint(); } catch (LWJGLException e) { @@ -127,12 +128,12 @@ 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; - } + } } - + private void setup() { // setup ogl FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f}); @@ -144,59 +145,59 @@ 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); } - + /** * Draw a gear wheel. You'll probably want to call this function when * building a display list since we do a lot of trig here. @@ -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(); } /* diff --git a/src/java/org/lwjgl/test/opengl/awt/AWTTest.java b/src/java/org/lwjgl/test/opengl/awt/AWTTest.java index 0795eb6b..109f5560 100644 --- a/src/java/org/lwjgl/test/opengl/awt/AWTTest.java +++ b/src/java/org/lwjgl/test/opengl/awt/AWTTest.java @@ -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.*; /** *

@@ -53,7 +54,7 @@ public class AWTTest extends Frame { /** AWT GL canvas */ private AWTGLCanvas canvas0, canvas1; - + private volatile float angle; /** @@ -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,27 +103,27 @@ 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) { throw new RuntimeException(e); } } - }); + }); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); diff --git a/src/java/org/lwjgl/test/opengl/awt/DemoBox.java b/src/java/org/lwjgl/test/opengl/awt/DemoBox.java index 9604b4b3..fc9860bb 100644 --- a/src/java/org/lwjgl/test/opengl/awt/DemoBox.java +++ b/src/java/org/lwjgl/test/opengl/awt/DemoBox.java @@ -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.*; + /** *

*

@@ -72,13 +73,13 @@ public class DemoBox extends Frame { private Panel selectionPanel; /** Hashtable of demos */ - private Hashtable selectableDemos; + private Hashtable selectableDemos; /** * Creates a new demo box instance */ public DemoBox() { - selectableDemos = new Hashtable(); + selectableDemos = new Hashtable(); selectableDemos.put("default", new NullDemoBox()); selectableDemos.put("clear_color", new ClearColorDemoBox()); selectableDemos.put("gears", new GearsDemoBox()); @@ -160,7 +161,7 @@ public class DemoBox extends Frame { //demoSelected(demos.getSelectedItem()); return true; } - + public void updateFPS(float fps) { if(fps != -1) { setTitle("LWJGL - Demo Box (FPS: " + fps + ")"); @@ -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,20 +200,20 @@ 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(); } /** - * + * */ private class DemoBoxGLCanvas extends AWTGLCanvas implements Runnable { /** Parent demo box */ DemoBox parent; - + /** Currently active demo */ Demo activeDemo; @@ -221,15 +222,15 @@ 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; + this.parent = parent; } // FPS - long startTime = 0; - long fps = 0; + long startTime; + long fps; protected void paintGL() { synchronized (this) { @@ -243,20 +244,20 @@ public class DemoBox extends Frame { parent.updateFPS(-1); } } - + if (activeDemo != null) { - + if(!activeDemo.isInitialized()) { activeDemo.initialize(); } - + activeDemo.render(); try { swapBuffers(); } catch (LWJGLException le) { le.printStackTrace(); } - + if (startTime > System.currentTimeMillis()) { fps++; } else { @@ -264,7 +265,7 @@ public class DemoBox extends Frame { startTime = System.currentTimeMillis() + 5000; parent.updateFPS((fps / (timeUsed / 1000f))); fps = 0; - } + } } } } @@ -295,7 +296,7 @@ public class DemoBox extends Frame { } } - public DemoBoxGLCanvas() throws LWJGLException { + private DemoBoxGLCanvas() throws LWJGLException { super(); } @@ -330,13 +331,13 @@ public class DemoBox extends Frame { // Demo box demo // ======================================================== public class ClearColorDemoBox implements Demo { - + private boolean initialized; int direction = 1; float color; - + public boolean isInitialized() { return initialized; } @@ -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; @@ -370,20 +371,20 @@ public class DemoBox extends Frame { // Demo box demo // ======================================================== public class NullDemoBox implements Demo { - + private boolean initialized; - + public boolean isInitialized() { return initialized; } 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() { @@ -391,18 +392,18 @@ public class DemoBox extends Frame { } } // -------------------------------------------------------- - + // Demo box demo // ======================================================== public class GearsDemoBox implements Demo { - + private boolean initialized; - + 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; @@ -410,8 +411,8 @@ public class DemoBox extends Frame { private int gear3; - private float angle = 0.0f; - + private float angle; + public boolean isInitialized() { return initialized; } @@ -426,93 +427,93 @@ public class DemoBox extends Frame { red.flip(); green.flip(); blue.flip(); - - GL11.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); + glClearColor(0, 0, 0, 1f); + + 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(); } - + /** * Draw a gear wheel. You'll probably want to call this function when * building a display list since we do a lot of trig here. @@ -535,104 +536,104 @@ 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; } } - // -------------------------------------------------------- + // -------------------------------------------------------- } diff --git a/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java b/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java index 753e7f43..4cde8e93 100644 --- a/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java +++ b/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java @@ -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.*; /** *

@@ -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); @@ -85,23 +86,23 @@ public class DisplayParentTest extends Frame { width = Display.getDisplayMode().getWidth(); height = Display.getDisplayMode().getHeight(); } - + if(width < 1 || height < 1) { 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 diff --git a/src/java/org/lwjgl/test/opengl/multithread/BackgroundLoadTest.java b/src/java/org/lwjgl/test/opengl/multithread/BackgroundLoadTest.java index d24a29b2..bf2326cf 100644 --- a/src/java/org/lwjgl/test/opengl/multithread/BackgroundLoadTest.java +++ b/src/java/org/lwjgl/test/opengl/multithread/BackgroundLoadTest.java @@ -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: *
@@ -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; diff --git a/src/java/org/lwjgl/test/opengl/multithread/BackgroundLoader.java b/src/java/org/lwjgl/test/opengl/multithread/BackgroundLoader.java index 56e5cebf..2e7a3978 100644 --- a/src/java/org/lwjgl/test/opengl/multithread/BackgroundLoader.java +++ b/src/java/org/lwjgl/test/opengl/multithread/BackgroundLoader.java @@ -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 **"); diff --git a/src/java/org/lwjgl/test/opengl/pbuffers/PbufferTest.java b/src/java/org/lwjgl/test/opengl/pbuffers/PbufferTest.java index 95e09274..572e02e4 100644 --- a/src/java/org/lwjgl/test/opengl/pbuffers/PbufferTest.java +++ b/src/java/org/lwjgl/test/opengl/pbuffers/PbufferTest.java @@ -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.*; + /** *

* 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); } diff --git a/src/java/org/lwjgl/test/opengl/pbuffers/UniqueRenderer.java b/src/java/org/lwjgl/test/opengl/pbuffers/UniqueRenderer.java index 24fe7f18..e0d8aadd 100644 --- a/src/java/org/lwjgl/test/opengl/pbuffers/UniqueRenderer.java +++ b/src/java/org/lwjgl/test/opengl/pbuffers/UniqueRenderer.java @@ -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); } } diff --git a/src/java/org/lwjgl/test/opengl/pbuffers/UniqueRendererRTT.java b/src/java/org/lwjgl/test/opengl/pbuffers/UniqueRendererRTT.java index 9195b6cb..6ea04d97 100644 --- a/src/java/org/lwjgl/test/opengl/pbuffers/UniqueRendererRTT.java +++ b/src/java/org/lwjgl/test/opengl/pbuffers/UniqueRendererRTT.java @@ -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) { diff --git a/src/java/org/lwjgl/test/opengl/shaders/Shader.java b/src/java/org/lwjgl/test/opengl/shaders/Shader.java index 26497d86..7f281e04 100644 --- a/src/java/org/lwjgl/test/opengl/shaders/Shader.java +++ b/src/java/org/lwjgl/test/opengl/shaders/Shader.java @@ -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)); } } diff --git a/src/java/org/lwjgl/test/opengl/shaders/ShaderFP.java b/src/java/org/lwjgl/test/opengl/shaders/ShaderFP.java index ea99701d..0488a82d 100644 --- a/src/java/org/lwjgl/test/opengl/shaders/ShaderFP.java +++ b/src/java/org/lwjgl/test/opengl/shaders/ShaderFP.java @@ -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); } } \ No newline at end of file diff --git a/src/java/org/lwjgl/test/opengl/shaders/ShaderFSH.java b/src/java/org/lwjgl/test/opengl/shaders/ShaderFSH.java index a90b917c..1c1f74a2 100644 --- a/src/java/org/lwjgl/test/opengl/shaders/ShaderFSH.java +++ b/src/java/org/lwjgl/test/opengl/shaders/ShaderFSH.java @@ -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); } } \ No newline at end of file diff --git a/src/java/org/lwjgl/test/opengl/shaders/ShaderUNI.java b/src/java/org/lwjgl/test/opengl/shaders/ShaderUNI.java index a50278ca..2ffe40ae 100644 --- a/src/java/org/lwjgl/test/opengl/shaders/ShaderUNI.java +++ b/src/java/org/lwjgl/test/opengl/shaders/ShaderUNI.java @@ -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); } } \ No newline at end of file diff --git a/src/java/org/lwjgl/test/opengl/shaders/ShaderVP.java b/src/java/org/lwjgl/test/opengl/shaders/ShaderVP.java index 024eac4f..a57aab3c 100644 --- a/src/java/org/lwjgl/test/opengl/shaders/ShaderVP.java +++ b/src/java/org/lwjgl/test/opengl/shaders/ShaderVP.java @@ -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); } } \ No newline at end of file diff --git a/src/java/org/lwjgl/test/opengl/shaders/ShaderVSH.java b/src/java/org/lwjgl/test/opengl/shaders/ShaderVSH.java index 3130154a..62ccb78b 100644 --- a/src/java/org/lwjgl/test/opengl/shaders/ShaderVSH.java +++ b/src/java/org/lwjgl/test/opengl/shaders/ShaderVSH.java @@ -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); } } \ No newline at end of file diff --git a/src/java/org/lwjgl/test/opengl/shaders/ShadersTest.java b/src/java/org/lwjgl/test/opengl/shaders/ShadersTest.java index e7a977e0..ffcbeb47 100644 --- a/src/java/org/lwjgl/test/opengl/shaders/ShadersTest.java +++ b/src/java/org/lwjgl/test/opengl/shaders/ShadersTest.java @@ -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; diff --git a/src/java/org/lwjgl/util/Display.java b/src/java/org/lwjgl/util/Display.java index 1407fe4d..b1c70a22 100644 --- a/src/java/org/lwjgl/util/Display.java +++ b/src/java/org/lwjgl/util/Display.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -47,13 +47,13 @@ import org.lwjgl.opengl.DisplayMode; * $Id$ */ public final class Display { - + private static final boolean DEBUG = false; - + /** * Determine the available display modes that match the specified minimum and maximum criteria. * If any given criterium is specified as -1 then it is ignored. - * + * * @param minWidth the minimum display resolution in pixels * @param minHeight the minimum display resolution in pixels * @param maxWidth the maximum display resolution in pixels @@ -69,15 +69,15 @@ public final class Display { { // First get the available display modes DisplayMode[] modes = org.lwjgl.opengl.Display.getAvailableDisplayModes(); - + 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 matches = new ArrayList(modes.length); for (int i = 0; i < modes.length; i ++) { assert modes[i] != null : ""+i+" "+modes.length; @@ -103,19 +103,19 @@ public final class Display { } matches.add(modes[i]); } - + DisplayMode[] ret = new DisplayMode[matches.size()]; 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); } } - + return ret; } - + /** * Create the display by choosing from a list of display modes based on an order of preference. * You must supply a list of allowable display modes, probably by calling getAvailableDisplayModes(), @@ -130,7 +130,7 @@ public final class Display { * @see org.lwjgl.opengl.DisplayMode */ public static DisplayMode setDisplayMode(DisplayMode[] dm, final String[] param) throws Exception { - + class FieldAccessor { final String fieldName; final int order; @@ -158,89 +158,86 @@ public final class Display { throw new IllegalArgumentException("Unknown field "+fieldName); } } - - class Sorter implements Comparator { - - final FieldAccessor[] field; - + + class Sorter implements Comparator { + + 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); } } } - + /** * @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; - - 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) + public int compare(DisplayMode dm1, DisplayMode dm2) { + for ( FieldAccessor accessor : accessors ) { + int f1 = accessor.getInt(dm1); + int f2 = accessor.getInt(dm2); + + 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; } } - + // Sort the display modes Arrays.sort(dm, new Sorter()); - + // 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(); } } } - + throw new Exception("Failed to set display mode."); } - + } diff --git a/src/java/org/lwjgl/util/ReadableColor.java b/src/java/org/lwjgl/util/ReadableColor.java index 0bc13d2e..9371cc87 100644 --- a/src/java/org/lwjgl/util/ReadableColor.java +++ b/src/java/org/lwjgl/util/ReadableColor.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -45,102 +45,102 @@ 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); + - } diff --git a/src/java/org/lwjgl/util/ReadableDimension.java b/src/java/org/lwjgl/util/ReadableDimension.java index 92cce7f3..cb38a0a9 100644 --- a/src/java/org/lwjgl/util/ReadableDimension.java +++ b/src/java/org/lwjgl/util/ReadableDimension.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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); } diff --git a/src/java/org/lwjgl/util/ReadablePoint.java b/src/java/org/lwjgl/util/ReadablePoint.java index 50d0b01c..a256459d 100644 --- a/src/java/org/lwjgl/util/ReadablePoint.java +++ b/src/java/org/lwjgl/util/ReadablePoint.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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); } diff --git a/src/java/org/lwjgl/util/ReadableRectangle.java b/src/java/org/lwjgl/util/ReadableRectangle.java index fa9141bf..cced54f2 100644 --- a/src/java/org/lwjgl/util/ReadableRectangle.java +++ b/src/java/org/lwjgl/util/ReadableRectangle.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -38,11 +38,11 @@ package org.lwjgl.util; * $Id$ */ 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); } diff --git a/src/java/org/lwjgl/util/Renderable.java b/src/java/org/lwjgl/util/Renderable.java index f6f06e26..fcb73ea7 100644 --- a/src/java/org/lwjgl/util/Renderable.java +++ b/src/java/org/lwjgl/util/Renderable.java @@ -1,49 +1,49 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.util; /** - * + * * Simple interface to things that can be Rendered. - * + * * @author $Author$ * @version $Revision$ * $Id$ */ public interface Renderable { - + /** * "Render" this thing. This will involve calls to the GL. */ - public void render(); - + void render(); + } diff --git a/src/java/org/lwjgl/util/Timer.java b/src/java/org/lwjgl/util/Timer.java index 33dc413a..df148e91 100644 --- a/src/java/org/lwjgl/util/Timer.java +++ b/src/java/org/lwjgl/util/Timer.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -39,7 +39,7 @@ import org.lwjgl.Sys; * All Timers created are updated simultaneously by calling the static method * tick(). This ensures that within a single iteration of a game loop that * all timers are updated consistently with each other. - * + * * @author cix_foo * @version $Revision$ * $Id$ @@ -48,27 +48,27 @@ public class Timer { // Record the timer resolution on classload private static long resolution = Sys.getTimerResolution(); - + // 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 + // Globally keeps track of time for all instances of Timer private static long currentTime; - + // When the timer was started private long startTime; - + // The last time recorded by getTime() private long lastTime; // Whether the timer is paused private boolean paused; - + static { tick(); } - + /** * Constructs a timer. The timer will be reset to 0.0 and resumed immediately. */ @@ -76,7 +76,7 @@ public class Timer { reset(); resume(); } - + /** * @return the time in seconds, as a float */ @@ -93,17 +93,17 @@ public class Timer { public boolean isPaused() { return paused; } - + /** * Pause the timer. Whilst paused the time will not change for this timer * when tick() is called. - * + * * @see #resume() */ public void pause() { paused = true; } - + /** * Reset the timer. Equivalent to set(0.0f); * @see #set(float) @@ -111,7 +111,7 @@ public class Timer { public void reset() { set(0.0f); } - + /** * Resume the timer. * @see #pause() @@ -120,7 +120,7 @@ public class Timer { paused = false; startTime = currentTime - lastTime; } - + /** * Set the time of this timer * @param newTime the new time, in seconds @@ -130,7 +130,7 @@ public class Timer { startTime = currentTime - newTimeInTicks; lastTime = newTimeInTicks; } - + /** * Get the next time update from the system's hires timer. This method should * be called once per main loop iteration; all timers are updated simultaneously @@ -138,7 +138,7 @@ public class Timer { */ public static void tick() { currentTime = Sys.getTime(); - + // Periodically refresh the timer resolution: queryCount ++; if (queryCount > QUERY_INTERVAL) { @@ -146,7 +146,7 @@ public class Timer { resolution = Sys.getTimerResolution(); } } - + /** * Debug output. */ diff --git a/src/java/org/lwjgl/util/WritableColor.java b/src/java/org/lwjgl/util/WritableColor.java index 6960698b..a1fb49ca 100644 --- a/src/java/org/lwjgl/util/WritableColor.java +++ b/src/java/org/lwjgl/util/WritableColor.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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); } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/WritableDimension.java b/src/java/org/lwjgl/util/WritableDimension.java index c08a6068..5e049769 100644 --- a/src/java/org/lwjgl/util/WritableDimension.java +++ b/src/java/org/lwjgl/util/WritableDimension.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -39,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); } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/WritablePoint.java b/src/java/org/lwjgl/util/WritablePoint.java index 9ec9b2c8..6a398cb0 100644 --- a/src/java/org/lwjgl/util/WritablePoint.java +++ b/src/java/org/lwjgl/util/WritablePoint.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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); } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/WritableRectangle.java b/src/java/org/lwjgl/util/WritableRectangle.java index 1a9e0b07..2b1da168 100644 --- a/src/java/org/lwjgl/util/WritableRectangle.java +++ b/src/java/org/lwjgl/util/WritableRectangle.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -38,7 +38,7 @@ package org.lwjgl.util; * $Id$ */ public interface WritableRectangle extends WritablePoint, WritableDimension { - + /** * Sets the bounds of the rectangle * @param x Position of rectangle on x axis @@ -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); } diff --git a/src/java/org/lwjgl/util/XPMFile.java b/src/java/org/lwjgl/util/XPMFile.java index 7a598edb..9b71de0d 100644 --- a/src/java/org/lwjgl/util/XPMFile.java +++ b/src/java/org/lwjgl/util/XPMFile.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -46,7 +46,7 @@ import java.util.StringTokenizer; *

* NOTE: This simple XPM reader does not support extensions nor hotspots *

- * + * * @author Brian Matzon * @author Jos Hirth * @version $Revision$ @@ -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]; @@ -76,7 +76,7 @@ public class XPMFile { /** * Loads the XPM file - * + * * @param file * path to file * @return XPMFile loaded, or exception @@ -89,7 +89,7 @@ public class XPMFile { /** * Loads the XPM file - * + * * @param is * InputStream to read file from * @return XPMFile loaded, or exception @@ -128,14 +128,14 @@ public class XPMFile { try { LineNumberReader reader = new LineNumberReader( new InputStreamReader(is)); - HashMap colors = new HashMap(); + HashMap colors = new HashMap(); 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) @@ -151,14 +151,14 @@ public class XPMFile { /** * Finds the next interesting line of text. - * + * * @param reader * The LineNumberReader to read from * @return The next interesting String (with stripped quotes) * @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 { @@ -170,12 +170,12 @@ public class XPMFile { /** * Parses the format of the xpm file given a format string - * + * * @param format * 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 @@ -192,12 +192,12 @@ public class XPMFile { /** * Given a line defining a color/pixel, parses this into an array containing * a key and a color - * + * * @param line * 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,12 +211,12 @@ public class XPMFile { String color = line.substring(format[CHARACTERS_PER_PIXEL] + 4); // we always assume type is color, and supplied as # - return new Object[] { key, new Integer(Integer.parseInt(color, 16)) }; + return new Object[] { key, Integer.parseInt(color, 16) }; } /** * Parses an Image line into its byte values - * + * * @param line * Line of chars to parse * @param format @@ -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 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 diff --git a/src/java/org/lwjgl/util/applet/AppletLoader.java b/src/java/org/lwjgl/util/applet/AppletLoader.java index 9c063dd0..ef68ba3b 100644 --- a/src/java/org/lwjgl/util/applet/AppletLoader.java +++ b/src/java/org/lwjgl/util/applet/AppletLoader.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -88,7 +88,7 @@ import sun.security.util.SecurityConstants; * while the relevant jars (generic and native) are downloaded from a specified source. *

*

- * The downloaded jars are extracted to the users temporary directory - and if enabled, cached for + * The downloaded jars are extracted to the users temporary directory - and if enabled, cached for * faster loading in future uses. *

*

@@ -108,7 +108,7 @@ import sun.security.util.SecurityConstants; *

* Additionally the following parameters can be supplied to tweak the behaviour of the AppletLoader. *

    - *
  • al_version - [int or float] Version of deployment. If this is specified, the jars will be cached and + *
  • al_version - [int or float] Version of deployment. If this is specified, the jars will be cached and * reused if the version matches. If version doesn't match all of the files are reloaded.
  • *
  • al_cache - [boolean] Whether to use cache system. Default: true.
  • *
  • al_debug - [boolean] Whether to enable debug mode. Default: false.
  • @@ -129,159 +129,159 @@ import sun.security.util.SecurityConstants; * $Id$ */ public class AppletLoader extends Applet implements Runnable, AppletStub { - + /** initializing */ public static final int STATE_INIT = 1; - + /** determining which packages that are required */ public static final int STATE_DETERMINING_PACKAGES = 2; - + /** checking for already downloaded files */ public static final int STATE_CHECKING_CACHE = 3; - + /** downloading packages */ public static final int STATE_DOWNLOADING = 4; - + /** extracting packages */ public static final int STATE_EXTRACTING_PACKAGES = 5; - + /** updating the classpath */ public static final int STATE_UPDATING_CLASSPATH = 6; - + /** switching to real applet */ public static final int STATE_SWITCHING_APPLET = 7; /** initializing real applet */ public static final int STATE_INITIALIZE_REAL_APPLET = 8; - + /** stating real applet */ public static final int STATE_START_REAL_APPLET = 9; - + /** done */ public static final int STATE_DONE = 10; - + /** used to calculate length of progress bar */ protected int percentage; /** current size of download in bytes */ - protected int currentSizeDownload; + protected int currentSizeDownload; /** total size of download in bytes */ - protected int totalSizeDownload; + protected int totalSizeDownload; /** current size of extracted in bytes */ - protected int currentSizeExtract; + protected int currentSizeExtract; /** total size of extracted in bytes */ - protected int totalSizeExtract; - + protected int totalSizeExtract; + /** logo to be shown while loading */ protected Image logo, logoBuffer; /** progressbar to render while loading */ protected Image progressbar, progressbarBuffer; - + /** offscreen image used */ protected Image offscreen; - + /** set to true while painting is done */ protected boolean painting; - + /** background color of applet */ protected Color bgColor = Color.white; /** color to write foreground in */ - protected Color fgColor = Color.black; + protected Color fgColor = Color.black; /** urls of the jars to download */ protected URL[] urlList; - + /** classLoader used to add downloaded jars to the classpath */ protected ClassLoader classLoader; - + /** actual thread that does the loading */ protected Thread loaderThread; - + /** animation thread that renders our load screen while loading */ protected Thread animationThread; /** applet to load after all downloads are complete */ protected Applet lwjglApplet; - + /** whether a fatal error occured */ protected boolean fatalError; - + /** whether we're running in debug mode */ protected boolean debugMode; - + /** whether to prepend host to cache path */ protected boolean prependHost; - + /** Used to store file names with lastModified time */ - protected HashMap filesLastModified; - + protected HashMap filesLastModified; + /** Sizes of files to download */ protected int[] fileSizes; - + /** whether to use caching system, only download files that have changed */ protected boolean cacheEnabled; - + /** String to display as a subtask */ protected String subtaskMessage = ""; /** state of applet loader */ 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.", "Please contact support to resolve this issue.", ""}; - + /** whether a certificate refused error occured */ protected boolean certificateRefused; - + /** error message to display if user refuses to accept certicate*/ protected String[] certificateRefusedMessage = { "Permissions for Applet Refused.", "Please accept the permissions dialog to allow", "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() */ public void init() { state = STATE_INIT; - + // sanity check String[] requiredArgs = {"al_main", "al_logo", "al_progressbar", "al_jars"}; - for(int i=0; i 0) { @@ -290,7 +290,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { if (getParameter("al_progressbar").length() > 0) { progressbar = getImage(getParameter("al_progressbar")); } - + // check for lzma support try { Class.forName("LZMA.LzmaInputStream"); @@ -298,14 +298,14 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { } catch (Throwable e) { /* no lzma support */ } - + // check pack200 support try { java.util.jar.Pack200.class.getSimpleName(); pack200Supported = true; } catch (Throwable e) { /* no pack200 support */ - } + } } /** @@ -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); @@ -332,7 +332,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { loaderThread = new Thread(this); loaderThread.setName("AppletLoader.loaderThread"); loaderThread.start(); - + animationThread = new Thread() { public void run() { while(loaderThread != null) { @@ -347,7 +347,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { } } } - + /* * @see java.applet.Applet#stop() */ @@ -356,7 +356,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { lwjglApplet.stop(); } } - + /* * @see java.applet.Applet#destroy() */ @@ -365,33 +365,33 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { lwjglApplet.destroy(); } } - + /** * Clean up resources */ protected void cleanUp() { progressbar = null; logo = null; - + logoBuffer = null; progressbarBuffer = null; - + offscreen = null; } - + /** * Retrieves the applet that has been loaded. Useful for liveconnect. */ public Applet getApplet() { return lwjglApplet; } - + /** - * Transfers the call of AppletResize from the stub to the lwjglApplet. + * Transfers the call of AppletResize from the stub to the lwjglApplet. */ public void appletResize(int width, int height) { resize(width, height); - } + } /* * @see java.awt.Container#update(java.awt.Graphics) @@ -399,7 +399,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { public final void update(Graphics g) { paint(g); } - + /* * @see java.awt.Container#paint(java.awt.Graphics) */ @@ -408,23 +408,23 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { if(state == STATE_DONE) { return; } - + // create offscreen if missing if (offscreen == null) { offscreen = createImage(getWidth(), getHeight()); - + // create buffers for animated gifs if (logo != null) { logoBuffer = createImage(logo.getWidth(null), logo.getHeight(null)); - // add image observer, it will notify when next animated gif frame is ready + // add image observer, it will notify when next animated gif frame is ready offscreen.getGraphics().drawImage(logo, 0, 0, this); // in case image is not animated fill image buffer once imageUpdate(logo, ImageObserver.FRAMEBITS, 0, 0, 0, 0); } - + if (progressbar != null) { progressbarBuffer = createImage(progressbar.getWidth(null), progressbar.getHeight(null)); - // add image observer, it will notify when next animated gif frame is ready + // add image observer, it will notify when next animated gif frame is ready offscreen.getGraphics().drawImage(progressbar, 0, 0, this); // in case image is not animated fill image buffer once imageUpdate(progressbar, ImageObserver.FRAMEBITS, 0, 0, 0, 0); @@ -445,38 +445,38 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { // if we had a failure of some sort, notify the user if (fatalError) { String[] errorMessage = (certificateRefused) ? certificateRefusedMessage : genericErrorMessage; - + for(int i=0; i 0) { messageX = (offscreen.getWidth(null) - fm.stringWidth(subtaskMessage)) / 2; @@ -489,54 +489,54 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { og.clipRect(x-progressbar.getWidth(null)/2, 0, barSize, offscreen.getHeight(null)); og.drawImage(progressbarBuffer, x-progressbar.getWidth(null)/2, y-progressbar.getHeight(null)/2, this); } - + painting = false; } - + og.dispose(); - + // finally draw it all centred g.drawImage(offscreen, (getWidth() - offscreen.getWidth(null))/2, (getHeight() - offscreen.getHeight(null))/2, null); } - + /** - * When an animated gif frame is ready to be drawn the ImageObserver + * When an animated gif frame is ready to be drawn the ImageObserver * will call this method. - * - * The Image frame is copied into a buffer, which is then drawn. + * + * The Image frame is copied into a buffer, which is then drawn. * This is done to prevent image tearing on gif animations. */ public boolean imageUpdate(Image img, int flag, int x, int y, int width, int height) { - + // finish with this ImageObserver if (state == STATE_DONE) return false; - + // if image frame is ready to be drawn and is currently not being painted if (flag == ImageObserver.FRAMEBITS && !painting) { Image buffer; - + // select which buffer to fill if (img == logo) buffer = logoBuffer; else buffer = progressbarBuffer; - + Graphics g = buffer.getGraphics(); - + // clear background on buffer g.setColor(bgColor); g.fillRect(0, 0, buffer.getWidth(null), buffer.getHeight(null)); - + // buffer background is cleared, so draw logo under progressbar if (img == progressbar && logo != null) { - g.drawImage(logoBuffer, progressbar.getWidth(null)/2-logo.getWidth(null)/2, + g.drawImage(logoBuffer, progressbar.getWidth(null)/2-logo.getWidth(null)/2, progressbar.getHeight(null)/2-logo.getHeight(null)/2, null); } - + g.drawImage(img, 0, 0, this); g.dispose(); - + repaint(); } - + return true; } @@ -569,7 +569,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { return "unknown state"; } } - + /** * Trims the passed file string based on the available capabilities * @param file string of files to be trimmed @@ -579,10 +579,10 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { if (!pack200Supported) { file = file.replaceAll(".pack", ""); } - + if (!lzmaSupported) { file = file.replaceAll(".lzma", ""); - } + } return file; } @@ -593,16 +593,16 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { */ protected void loadJarURLs() throws Exception { state = STATE_DETERMINING_PACKAGES; - + // jars to load String jarList = getParameter("al_jars"); - + jarList = trimExtensionByCapabilities(jarList); - + StringTokenizer jar = new StringTokenizer(jarList, ", "); int jarCount = jar.countTokens() + 1; - + urlList = new URL[jarCount]; URL path = getCodeBase(); @@ -615,33 +615,33 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { // native jar url String osName = System.getProperty("os.name"); String nativeJar = null; - + if (osName.startsWith("Win")) { - + // check if arch specific natives have been specified if (System.getProperty("os.arch").endsWith("64")) { nativeJar = getParameter("al_windows64"); } else { nativeJar = getParameter("al_windows32"); } - + if (nativeJar == null) { nativeJar = getParameter("al_windows"); } - + } else if (osName.startsWith("Linux")) { - + // check if arch specific natives have been specified if (System.getProperty("os.arch").endsWith("64")) { nativeJar = getParameter("al_linux64"); } else { nativeJar = getParameter("al_linux32"); } - + if (nativeJar == null) { nativeJar = getParameter("al_linux"); } - + } else if (osName.startsWith("Mac")) { nativeJar = getParameter("al_mac"); } else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) { @@ -662,7 +662,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { /** * 4 steps - * + * * 1) check version of applet and decide whether to download jars * 2) download the jars * 3) extract natives @@ -671,7 +671,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { */ public void run() { state = STATE_CHECKING_CACHE; - + percentage = 5; try { @@ -679,11 +679,11 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { // parse the urls for the jars into the url list 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() { + public String run() throws Exception { + // we append the code base to avoid naming collisions with al_title String codebase = ""; if(prependHost) { @@ -696,23 +696,23 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { return System.getProperty("java.io.tmpdir") + File.separator + codebase + getParameter("al_title") + File.separator; } }); - + File dir = new File(path); // create directory if (!dir.exists()) { dir.mkdirs(); } - + File versionFile = new File(dir, "version"); - + // if specified applet version already available don't download anything boolean versionAvailable = false; // version of applet String version = getParameter("al_version"); float latestVersion = 0; - + // if applet version specifed, check if you have latest version of applet if (version != null) { @@ -724,7 +724,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { if (latestVersion != readVersionFile(versionFile)) { versionAvailable = true; percentage = 90; - + if(debugMode) { System.out.println("Loading Cached Applet Version " + latestVersion); } @@ -737,10 +737,10 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { if (!versionAvailable) { // get jars file sizes and check cache getJarInfo(dir); // 5-15% - + // downloads jars from the server downloadJars(path); // 15-55% - + // Extract Pack and LZMA files extractJars(path); // 55-65% @@ -752,7 +752,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { percentage = 90; writeVersionFile(versionFile, latestVersion); } - + // save file names with last modified info once downloaded successfully writeCacheFile(new File(dir, "cache"), filesLastModified); } @@ -778,7 +778,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { /** * read the current version file - * + * * @param file the file to read * @return the version value of saved file * @throws Exception if it fails to read value @@ -792,7 +792,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { /** * write out version file of applet - * + * * @param file the file to write out to * @param version the version of the applet as a float * @throws Exception if it fails to write file @@ -802,29 +802,30 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { dos.writeFloat(version); dos.close(); } - + /** * read the current cache file - * + * * @param file the file to read * @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 readCacheFile(File file) throws Exception { ObjectInputStream dis = new ObjectInputStream(new FileInputStream(file)); - HashMap hashMap = (HashMap)dis.readObject(); + HashMap hashMap = (HashMap)dis.readObject(); dis.close(); return hashMap; } /** * write out cache file of applet - * + * * @param file the file to write out to * @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 filesLastModified) throws Exception { ObjectOutputStream dos = new ObjectOutputStream(new FileOutputStream(file)); dos.writeObject(filesLastModified); dos.close(); @@ -834,108 +835,108 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { * Edits the ClassPath at runtime to include the jars * that have just been downloaded and then adds the * lwjgl natives folder property. - * + * * @param path location where applet is stored * @throws Exception if it fails to add classpath */ protected void updateClassPath(String path) throws Exception { - + state = STATE_UPDATING_CLASSPATH; - + percentage = 95; - + URL[] urls = new URL[urlList.length]; - + for (int i = 0; i < urlList.length; i++) { urls[i] = new URL("file:" + path + getJarName(urlList[i])); } - + // add downloaded jars to the classpath with required permissions classLoader = new URLClassLoader(urls) { protected PermissionCollection getPermissions (CodeSource codesource) { PermissionCollection perms = null; - + try { // getPermissions from original classloader is important as it checks for signed jars and shows any security dialogs needed Method method = SecureClassLoader.class.getDeclaredMethod("getPermissions", new Class[] { CodeSource.class }); method.setAccessible(true); perms = (PermissionCollection)method.invoke(getClass().getClassLoader(), new Object[] {codesource}); - + String host = getCodeBase().getHost(); - + if (host != null && (host.length() > 0)) { // 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)); } - + } catch (Exception e) { e.printStackTrace(); } - + return perms; } }; - + debug_sleep(2000); - + // unload natives loaded by a previous instance of this lwjgl applet unloadNatives(path); - + // add natives files path to native class path System.setProperty("org.lwjgl.librarypath", path + "natives"); // Make sure jinput knows about the new path too System.setProperty("net.java.games.input.librarypath", path + "natives"); - + // set the library path, useful for non lwjgl natives System.setProperty("java.library.path", path + "natives"); - + // mark natives as loaded natives_loaded = true; } - + /** * Unload natives loaded by a different classloader. - * - * Due to limitations of the jvm, native files can only - * be loaded once and only be used by the classloader + * + * Due to limitations of the jvm, native files can only + * be loaded once and only be used by the classloader * they were loaded from. - * + * * Due to the way applets on plugin1 work, one jvm must - * be used for all applets. We need to use multiple - * classloaders in the same jvm due to LWJGL's static - * nature. I order to solve this we simply remove the - * natives from a previous classloader allowing a new + * be used for all applets. We need to use multiple + * classloaders in the same jvm due to LWJGL's static + * nature. I order to solve this we simply remove the + * natives from a previous classloader allowing a new * classloader to use those natives in the same jvm. - * + * * This method will only attempt to unload natives from a * previous classloader if it detects that the natives have * been loaded in the same jvm. - * + * * @param nativePath directory where natives are stored */ private void unloadNatives(String nativePath) { - + // check whether natives have been loaded into this jvm if (!natives_loaded) { return; } - + try { Field field = ClassLoader.class.getDeclaredField("loadedLibraryNames"); field.setAccessible(true); Vector libs = (Vector) field.get(getClass().getClassLoader()); - + String path = new File(nativePath).getCanonicalPath(); - + for (int i = 0; i < libs.size(); i++) { String s = (String) libs.get(i); - + // if a native from the nativePath directory is loaded, unload it if (s.startsWith(path)) { libs.remove(i); @@ -952,10 +953,10 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { * using AppletStub and initialise and start it */ protected void switchApplet() throws Exception { - + state = STATE_SWITCHING_APPLET; percentage = 100; - + debug_sleep(2000); Class appletClass = classLoader.loadClass(getParameter("al_main")); @@ -974,33 +975,33 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { state = STATE_START_REAL_APPLET; lwjglApplet.start(); } - + /** * This method will get the files sizes of the files to download. * It wil further get the lastModified time of files * and save it in a hashmap, if cache is enabled it will mark * those files that have not changed since last download to not * redownloaded. - * + * * @param dir - location to read cache file from * @throws Exception - if fails to get infomation */ protected void getJarInfo(File dir) throws Exception { - - filesLastModified = new HashMap(); - + + filesLastModified = new HashMap(); + // store file sizes and mark which files not to download fileSizes = new int[urlList.length]; - + URLConnection urlconnection; - + File cacheFile = new File(dir, "cache"); - + // if cache file exists, load it if (cacheFile.exists()) { filesLastModified = readCacheFile(cacheFile); } - + // calculate total size of jars to download for (int i = 0; i < urlList.length; i++) { urlconnection = urlList[i].openConnection(); @@ -1008,85 +1009,85 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { if (urlconnection instanceof HttpURLConnection) { ((HttpURLConnection) urlconnection).setRequestMethod("HEAD"); } - + fileSizes[i] = urlconnection.getContentLength(); - + long lastModified = urlconnection.getLastModified(); String fileName = getFileName(urlList[i]); - - - if (cacheEnabled && lastModified != 0 && + + + 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) { fileSizes[i] = -2; // mark it to not redownload } } - + if (fileSizes[i] >= 0) { totalSizeDownload += fileSizes[i]; } - + // 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); } } - + /** * Will download the jars from the server using the list of urls * in urlList, while at the same time updating progress bar - * + * * @param path location of the directory to save to * @throws Exception if download fails */ protected void downloadJars(String path) throws Exception { - + state = STATE_DOWNLOADING; URLConnection urlconnection; - + int initialPercentage = percentage = 15; // download each jar byte buffer[] = new byte[65536]; for (int i = 0; i < urlList.length; i++) { - + // skip file if marked as -2 (already downloaded and not changed) if (fileSizes[i] == -2) continue; - + int unsuccessfulAttempts = 0; int maxUnsuccessfulAttempts = 3; boolean downloadFile = true; - + // download the jar a max of 3 times while(downloadFile) { downloadFile = false; - + debug_sleep(2000); - + urlconnection = urlList[i].openConnection(); - + if (urlconnection instanceof HttpURLConnection) { urlconnection.setRequestProperty("Cache-Control", "no-cache"); urlconnection.connect(); } - + String currentFile = getFileName(urlList[i]); InputStream inputstream = getJarInputStream(currentFile, urlconnection); FileOutputStream fos = new FileOutputStream(path + currentFile); - - + + int bufferSize; long downloadStartTime = System.currentTimeMillis(); int downloadedAmount = 0; int fileSize = 0; String downloadSpeedMessage = ""; - + while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1) { debug_sleep(10); fos.write(buffer, 0, bufferSize); @@ -1094,7 +1095,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { fileSize += bufferSize; percentage = initialPercentage + ((currentSizeDownload * 45) / totalSizeDownload); subtaskMessage = "Retrieving: " + currentFile + " " + ((currentSizeDownload * 100) / totalSizeDownload) + "%"; - + downloadedAmount += bufferSize; long timeLapse = System.currentTimeMillis() - downloadStartTime; // update only if a second or more has passed @@ -1110,13 +1111,13 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { // reset start time downloadStartTime = System.currentTimeMillis(); } - + subtaskMessage += downloadSpeedMessage; } - + inputstream.close(); fos.close(); - + // download complete, verify if it was successful if (urlconnection instanceof HttpURLConnection) { if (fileSize == fileSizes[i]) { @@ -1151,8 +1152,8 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { */ protected InputStream getJarInputStream(final String currentFile, final URLConnection urlconnection) throws Exception { final InputStream[] is = new InputStream[1]; - - // try to get the input stream 3 times. + + // try to get the input stream 3 times. // Wait at most 5 seconds before interrupting the thread for (int j = 0; j < 3 && is[0] == null; j++) { Thread t = new Thread() { @@ -1166,7 +1167,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { }; t.setName("JarInputStreamThread"); t.start(); - + int iterationCount = 0; while(is[0] == null && iterationCount++ < 5) { try { @@ -1175,7 +1176,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { /* ignored */ } } - + if(is[0] == null) { try { t.interrupt(); @@ -1185,36 +1186,36 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { } } } - + if(is[0] == null) { throw new Exception("Unable to get input stream for " + currentFile); } - + return is[0]; } - + /** * 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 { - + File f = new File(in); 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); - + byte [] buffer = new byte [1<<14]; - + int ret = inputHandle.read(buffer); while (ret >= 1) { outputHandle.write(buffer,0,ret); @@ -1226,58 +1227,58 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { outputHandle = null; inputHandle = null; - + // delete LZMA file, as it is no longer needed f.delete(); } - + /** * 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 { + protected void extractPack(String in, String out) throws Exception { File f = new File(in); FileOutputStream fostream = new FileOutputStream(out); JarOutputStream jostream = new JarOutputStream(fostream); - + Pack200.Unpacker unpacker = Pack200.newUnpacker(); unpacker.unpack(f, jostream); jostream.close(); - + // delete pack file as its no longer needed f.delete(); } - + /** * 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; - + float increment = (float) 10.0 / urlList.length; // extract all lzma and pack.lzma files for (int i = 0; i < urlList.length; i++) { - + // if file has not changed, skip it if (fileSizes[i] == -2) continue; - + percentage = 55 + (int) (increment * (i+1)); String filename = getFileName(urlList[i]); - + if (filename.endsWith(".pack.lzma")) { subtaskMessage = "Extracting: " + filename + " to " + filename.replaceAll(".lzma", ""); debug_sleep(1000); extractLZMA(path + filename, path + filename.replaceAll(".lzma", "")); - + subtaskMessage = "Extracting: " + filename.replaceAll(".lzma", "") + " to " + filename.replaceAll(".pack.lzma", ""); debug_sleep(1000); extractPack(path + filename.replaceAll(".lzma", ""), path + filename.replaceAll(".pack.lzma", "")); - } + } else if (filename.endsWith(".pack")) { subtaskMessage = "Extracting: " + filename + " to " + filename.replace(".pack", ""); debug_sleep(1000); @@ -1289,13 +1290,13 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { extractLZMA(path + filename, path + filename.replace(".lzma", "")); } } - } + } /** * This method will extract all file from the native jar and extract them * to the subdirectory called "natives" in the local path, will also check - * to see if the native jar files is signed properly - * + * to see if the native jar files is signed properly + * * @param path base folder containing all downloaded jars * @throws Exception if it fails to extract files */ @@ -1305,21 +1306,21 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { if (fileSizes[fileSizes.length-1] == -2) { return; } - + state = STATE_EXTRACTING_PACKAGES; - + int initialPercentage = percentage; // get name of jar file with natives from urlList, it will be the last url String nativeJar = getJarName(urlList[urlList.length - 1]); - // get the current certificate to compare against native files + // get the current certificate to compare against native files Certificate[] certificate = AppletLoader.class.getProtectionDomain().getCodeSource().getCertificates(); - + // workaround for bug where cached applet loader does not have certificates!? if (certificate == null) { URL location = AppletLoader.class.getProtectionDomain().getCodeSource().getLocation(); - + // manually load the certificate JarURLConnection jurl = (JarURLConnection) (new URL("jar:" + location.toString() + "!/org/lwjgl/util/applet/AppletLoader.class").openConnection()); jurl.setDefaultUseCaches(true); @@ -1337,7 +1338,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { // get list of files in jar Enumeration entities = jarFile.entries(); - + totalSizeExtract = 0; // calculate the size of the files to extract for progress bar @@ -1360,7 +1361,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { // extract all files from the jar while (entities.hasMoreElements()) { JarEntry entry = (JarEntry) entities.nextElement(); - + // skip directories and anything in directories // conveniently ignores the manifest if (entry.isDirectory() || entry.getName().indexOf('/') != -1) { @@ -1375,7 +1376,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { continue; // unable to delete file, it is in use, skip extracting it } } - + debug_sleep(1000); InputStream in = jarFile.getInputStream(jarFile.getEntry(entry.getName())); @@ -1403,7 +1404,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { subtaskMessage = ""; jarFile.close(); - + // delete native jar as it is no longer needed File f = new File(path + nativeJar); f.delete(); @@ -1411,7 +1412,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { /** * Validates the certificate chain for a single file - * + * * @param ownCerts Chain of certificates to check against * @param native_certs Chain of certificates to check */ @@ -1428,29 +1429,29 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { } } } - + /** * Get Image from path provided - * + * * @param s location of the image * @return the Image file */ protected Image getImage(String s) { try { URL url = Thread.currentThread().getContextClassLoader().getResource("/"+s); - + // if image not found in jar, look outside it if (url == null) { url = new URL(getCodeBase(), s); } - + Image image = super.getImage(url); - + // wait for image to load MediaTracker tracker = new MediaTracker(this); tracker.addImage(image, 0); tracker.waitForAll(); - + // if no errors return image if (!tracker.isErrorAny()) { return image; @@ -1458,16 +1459,16 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { } catch (Exception e) { /* */ } - + // show error as image could not be loaded fatalErrorOccured("Unable to load logo and progressbar images", null); return null; } - + /** * Get jar name from URL. - * + * * @param url Get jar file name from this url * @return file name as string */ @@ -1483,11 +1484,11 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { } return fileName.substring(fileName.lastIndexOf('/') + 1); - } - + } + /** * Get file name portion of URL. - * + * * @param url Get file name from this url * @return file name as string */ @@ -1495,41 +1496,41 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { String fileName = url.getFile(); return fileName.substring(fileName.lastIndexOf('/') + 1); } - + /** * 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 */ protected Color getColor(String param, Color defaultColor) { String color = getParameter(param); - + if (color == null) return defaultColor; - + // Check if RGB format if (color.indexOf(",") != -1) { StringTokenizer st = new StringTokenizer(color, ","); - + // We've got three components for the color try { - return new Color(Integer.parseInt(st.nextToken().trim()), - Integer.parseInt(st.nextToken().trim()), + return new Color(Integer.parseInt(st.nextToken().trim()), + Integer.parseInt(st.nextToken().trim()), Integer.parseInt(st.nextToken().trim())); } catch (Exception e) { // failed to parse return defaultColor; } } - + // Check & decode if the color is in hexadecimal color format (i.e. #808000) try { return Color.decode(color); } catch (NumberFormatException e) { // ignore exception } - + // Get the color by name if it exists try { return (Color)Color.class.getField(color).get(null); @@ -1537,7 +1538,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { return defaultColor; } } - + /** * Retrieves the boolean value for the applet * @param name Name of parameter @@ -1551,10 +1552,10 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { } return defaultValue; } - + /** * Sets the state of the loaded and prints some debug information - * + * * @param error Error message to print */ protected void fatalErrorOccured(String error, Exception e) { @@ -1567,7 +1568,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { } repaint(); } - + /** * Utility method for sleeping * Will only really sleep if debug has been enabled @@ -1578,7 +1579,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { sleep(ms); } } - + /** * Utility method for sleeping * @param ms milliseconds to sleep @@ -1589,6 +1590,6 @@ public class AppletLoader extends Applet implements Runnable, AppletStub { } catch (Exception e) { /* ignored */ } - } - + } + } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/generator/GeneratorVisitor.java b/src/java/org/lwjgl/util/generator/GeneratorVisitor.java index 8c28287d..70467e02 100644 --- a/src/java/org/lwjgl/util/generator/GeneratorVisitor.java +++ b/src/java/org/lwjgl/util/generator/GeneratorVisitor.java @@ -98,8 +98,8 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor { private void validateType(MethodDeclaration method, Class 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); diff --git a/src/java/org/lwjgl/util/generator/Helper.java b/src/java/org/lwjgl/util/generator/Helper.java index b2795256..708c75db 100644 --- a/src/java/org/lwjgl/util/generator/Helper.java +++ b/src/java/org/lwjgl/util/generator/Helper.java @@ -42,5 +42,5 @@ import java.lang.annotation.Target; @Target(ElementType.PARAMETER) public @interface Helper { - + boolean passToNative() default false; } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java b/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java index 860ee6ce..fa091789 100644 --- a/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java +++ b/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java @@ -116,7 +116,7 @@ public class JavaMethodsGenerator { private static boolean generateParametersJava(PrintWriter writer, MethodDeclaration method, Map 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 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); diff --git a/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java b/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java index dfbc4c49..d06cb1f4 100644 --- a/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java +++ b/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java @@ -70,7 +70,7 @@ public class NativeMethodStubsGenerator { private static void generateParameters(PrintWriter writer, Collection 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() ) diff --git a/src/java/org/lwjgl/util/generator/RegisterStubsGenerator.java b/src/java/org/lwjgl/util/generator/RegisterStubsGenerator.java index bdd3299d..5733b7dc 100644 --- a/src/java/org/lwjgl/util/generator/RegisterStubsGenerator.java +++ b/src/java/org/lwjgl/util/generator/RegisterStubsGenerator.java @@ -86,9 +86,9 @@ public class RegisterStubsGenerator { Collection 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); if ( constant_annotation != null && constant_annotation.isNative() ) continue; diff --git a/src/java/org/lwjgl/util/generator/Utils.java b/src/java/org/lwjgl/util/generator/Utils.java index 45610136..ec29e3b1 100644 --- a/src/java/org/lwjgl/util/generator/Utils.java +++ b/src/java/org/lwjgl/util/generator/Utils.java @@ -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 *

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

    "); 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) { diff --git a/src/java/org/lwjgl/util/generator/opencl/CLCapabilitiesGenerator.java b/src/java/org/lwjgl/util/generator/opencl/CLCapabilitiesGenerator.java index 77247aab..fabeb1fa 100644 --- a/src/java/org/lwjgl/util/generator/opencl/CLCapabilitiesGenerator.java +++ b/src/java/org/lwjgl/util/generator/opencl/CLCapabilitiesGenerator.java @@ -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 interface_decls) { - writer.println("\tprivate static final Set " + SUPPORTED_EXTS + " = new HashSet();"); - 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 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"); } diff --git a/src/java/org/lwjgl/util/generator/opencl/CLGeneratorProcessorFactory.java b/src/java/org/lwjgl/util/generator/opencl/CLGeneratorProcessorFactory.java index b5bba949..d881fc1b 100644 --- a/src/java/org/lwjgl/util/generator/opencl/CLGeneratorProcessorFactory.java +++ b/src/java/org/lwjgl/util/generator/opencl/CLGeneratorProcessorFactory.java @@ -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 capsType, final String capsName, final Class 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(); diff --git a/src/java/org/lwjgl/util/generator/opencl/CLPDCapabilitiesGenerator.java b/src/java/org/lwjgl/util/generator/opencl/CLPDCapabilitiesGenerator.java index c697755b..0c298660 100644 --- a/src/java/org/lwjgl/util/generator/opencl/CLPDCapabilitiesGenerator.java +++ b/src/java/org/lwjgl/util/generator/opencl/CLPDCapabilitiesGenerator.java @@ -81,7 +81,6 @@ public class CLPDCapabilitiesGenerator { final Class 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 templates, final Class capsType, final String capsName, final Class objectType, final String objectName) { + public static void generateToString(final PrintWriter writer, final Collection templates, final Class capsType) { writer.println("\tpublic String toString() {"); writer.println("\t\tfinal StringBuilder buf = new StringBuilder();\n"); diff --git a/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java b/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java index a3928327..18543af3 100644 --- a/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java +++ b/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java @@ -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 " + 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 " + 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 " + CACHED_EXTS_VAR_NAME + " = new HashSet(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 supported_extensions"); } Alias alias_annotation = d.getAnnotation(Alias.class); @@ -313,7 +313,7 @@ public class GLCapabilitiesGenerator { 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; diff --git a/src/java/org/lwjgl/util/generator/opengl/GLGeneratorProcessorFactory.java b/src/java/org/lwjgl/util/generator/opengl/GLGeneratorProcessorFactory.java index 6e5dbea4..db50e48a 100644 --- a/src/java/org/lwjgl/util/generator/opengl/GLGeneratorProcessorFactory.java +++ b/src/java/org/lwjgl/util/generator/opengl/GLGeneratorProcessorFactory.java @@ -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); } diff --git a/src/java/org/lwjgl/util/generator/opengl/GLReferencesGeneratorProcessorFactory.java b/src/java/org/lwjgl/util/generator/opengl/GLReferencesGeneratorProcessorFactory.java index f306603e..bf87e236 100644 --- a/src/java/org/lwjgl/util/generator/opengl/GLReferencesGeneratorProcessorFactory.java +++ b/src/java/org/lwjgl/util/generator/opengl/GLReferencesGeneratorProcessorFactory.java @@ -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; diff --git a/src/java/org/lwjgl/util/glu/Cylinder.java b/src/java/org/lwjgl/util/glu/Cylinder.java index f4d8543b..f720092a 100644 --- a/src/java/org/lwjgl/util/glu/Cylinder.java +++ b/src/java/org/lwjgl/util/glu/Cylinder.java @@ -1,42 +1,43 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.util.glu; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.util.glu.GLU.*; /** * Cylinder.java - * - * + * + * * Created 23-dec-2003 * @author Erik Duijs */ @@ -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; diff --git a/src/java/org/lwjgl/util/glu/Disk.java b/src/java/org/lwjgl/util/glu/Disk.java index e0a76f9b..18a2b9df 100644 --- a/src/java/org/lwjgl/util/glu/Disk.java +++ b/src/java/org/lwjgl/util/glu/Disk.java @@ -1,42 +1,43 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.util.glu; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.util.glu.GLU.*; /** * Disk.java - * - * + * + * * Created 23-dec-2003 * @author Erik Duijs */ @@ -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; } diff --git a/src/java/org/lwjgl/util/glu/GLU.java b/src/java/org/lwjgl/util/glu/GLU.java index c7e62714..e1b1c132 100644 --- a/src/java/org/lwjgl/util/glu/GLU.java +++ b/src/java/org/lwjgl/util/glu/GLU.java @@ -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,17 +413,17 @@ 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); } } - + public static GLUtessellator gluNewTess() { return new GLUtessellatorImpl(); } diff --git a/src/java/org/lwjgl/util/glu/GLUtessellator.java b/src/java/org/lwjgl/util/glu/GLUtessellator.java index c07c6e4e..521ee04c 100644 --- a/src/java/org/lwjgl/util/glu/GLUtessellator.java +++ b/src/java/org/lwjgl/util/glu/GLUtessellator.java @@ -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(); } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/glu/GLUtessellatorCallback.java b/src/java/org/lwjgl/util/glu/GLUtessellatorCallback.java index 3f3413fe..0f913f77 100644 --- a/src/java/org/lwjgl/util/glu/GLUtessellatorCallback.java +++ b/src/java/org/lwjgl/util/glu/GLUtessellatorCallback.java @@ -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); } diff --git a/src/java/org/lwjgl/util/glu/MipMap.java b/src/java/org/lwjgl/util/glu/MipMap.java index 698371fc..a8a7665c 100644 --- a/src/java/org/lwjgl/util/glu/MipMap.java +++ b/src/java/org/lwjgl/util/glu/MipMap.java @@ -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); - } - - GL11.glTexImage2D(target, level, components, w, h, 0, format, type, image); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); + } + + 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; + 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; + 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++ ) @@ -250,9 +252,9 @@ public class MipMap extends Util { fptr += 4; } } - break; + 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,19 +333,19 @@ 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); - + for ( j = 0; j < widthOut * components; j++ ) { dataOut.putFloat(fptr, tempOut[k++]); fptr += 4; } } - break; + break; default: - return GLU.GLU_INVALID_ENUM; + return GLU_INVALID_ENUM; } return 0; diff --git a/src/java/org/lwjgl/util/glu/PartialDisk.java b/src/java/org/lwjgl/util/glu/PartialDisk.java index 0347eca4..e811436e 100644 --- a/src/java/org/lwjgl/util/glu/PartialDisk.java +++ b/src/java/org/lwjgl/util/glu/PartialDisk.java @@ -1,44 +1,45 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.util.glu; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.util.glu.GLU.*; /** * PartialDisk.java - * - * + * + * * Created 23-dec-2003 - * + * * @author Erik Duijs */ public class PartialDisk extends Quadric { @@ -58,18 +59,18 @@ public class PartialDisk extends Quadric { * through startAngle + sweepAngle is included (where 0 degrees is along * the +y axis, 90 degrees along the +x axis, 180 along the -y axis, and * 270 along the -x axis). - * + * * The partial disk has a radius of outerRadius, and contains a concentric * circular hole with a radius of innerRadius. If innerRadius is zero, then * no hole is generated. The partial disk is subdivided around the z axis * into slices (like pizza slices), and also about the z axis into rings * (as specified by slices and loops, respectively). - * + * * With respect to orientation, the +z side of the partial disk is * considered to be outside (see gluQuadricOrientation). This means that if * the orientation is set to GLU.GLU_OUTSIDE, then any normals generated point * along the +z axis. Otherwise, they point along the -z axis. - * + * * If texturing is turned on (with gluQuadricTexture), texture coordinates * are generated linearly such that where r=outerRadius, the value at (r, 0, 0) * is (1, 0.5), at (0, r, 0) it is (0.5, 1), at (-r, 0, 0) it is (0, 0.5), @@ -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; } diff --git a/src/java/org/lwjgl/util/glu/PixelStoreState.java b/src/java/org/lwjgl/util/glu/PixelStoreState.java index 6efbe500..3e6612ac 100644 --- a/src/java/org/lwjgl/util/glu/PixelStoreState.java +++ b/src/java/org/lwjgl/util/glu/PixelStoreState.java @@ -1,37 +1,37 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.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); } } diff --git a/src/java/org/lwjgl/util/glu/Project.java b/src/java/org/lwjgl/util/glu/Project.java index 151dcb8e..a3005c6a 100644 --- a/src/java/org/lwjgl/util/glu/Project.java +++ b/src/java/org/lwjgl/util/glu/Project.java @@ -1,31 +1,31 @@ /* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -37,12 +37,14 @@ import java.nio.IntBuffer; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; + /** * Project.java *

    *

    * Created 11-jan-2004 - * + * * @author Erik Duijs */ public class Project extends Util { @@ -76,7 +78,7 @@ public class Project extends Util { /** * Method __gluMultMatrixVecf - * + * * @param finalMatrix * @param in * @param out @@ -95,7 +97,7 @@ public class Project extends Util { /** * @param src * @param inverse - * + * * @return */ private static boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) { @@ -185,7 +187,7 @@ public class Project extends Util { /** * Method gluPerspective. - * + * * @param fovy * @param aspect * @param zNear @@ -213,12 +215,12 @@ 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); } /** * Method gluLookAt - * + * * @param eyex * @param eyey * @param eyez @@ -273,13 +275,13 @@ 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); } /** * Method gluProject - * + * * @param objx * @param objy * @param objz @@ -328,7 +330,7 @@ public class Project extends Util { /** * Method gluUnproject - * + * * @param winx * @param winy * @param winz @@ -383,7 +385,7 @@ public class Project extends Util { /** * Method gluPickMatrix - * + * * @param x * @param y * @param deltaX @@ -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); } } diff --git a/src/java/org/lwjgl/util/glu/Quadric.java b/src/java/org/lwjgl/util/glu/Quadric.java index 3f4c6520..3bbbf6e0 100644 --- a/src/java/org/lwjgl/util/glu/Quadric.java +++ b/src/java/org/lwjgl/util/glu/Quadric.java @@ -1,62 +1,63 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.util.glu; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.util.glu.GLU.*; /** * Quadric.java - * - * + * + * * Created 22-dec-2003 * @author Erik Duijs */ public class Quadric { - + protected int drawStyle; protected int orientation; protected boolean textureFlag; protected int normals; - + /** * Constructor for 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; } /** @@ -68,18 +69,18 @@ public class Quadric { */ protected void normal3f(float x, float y, float z) { float mag; - + mag = (float)Math.sqrt(x * x + y * y + z * z); if (mag > 0.00001F) { x /= mag; y /= mag; z /= mag; } - GL11.glNormal3f(x, y, z); + glNormal3f(x, y, z); } /** - * specifies the draw style for quadrics. + * specifies the draw style for quadrics. * * The legal values are as follows: * @@ -93,7 +94,7 @@ public class Quadric { * separating coplanar faces will not be drawn. * * GLU.POINT: Quadrics are rendered as a set of points. - * + * * @param drawStyle The drawStyle to set */ public void setDrawStyle(int drawStyle) { @@ -110,7 +111,7 @@ public class Quadric { * * GLU.SMOOTH: One normal is generated for every vertex of a quadric. This * is the default. - * + * * @param normals The normals to set */ public void setNormals(int normals) { @@ -127,7 +128,7 @@ public class Quadric { * * Note that the interpretation of outward and inward depends on the quadric * being drawn. - * + * * @param orientation The orientation to set */ public void setOrientation(int orientation) { @@ -142,13 +143,13 @@ public class Quadric { * * The manner in which texture coordinates are generated depends upon the * specific quadric rendered. - * + * * @param textureFlag The textureFlag to set */ public void setTextureFlag(boolean textureFlag) { this.textureFlag = textureFlag; } - + /** * Returns the drawStyle. @@ -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); } diff --git a/src/java/org/lwjgl/util/glu/Registry.java b/src/java/org/lwjgl/util/glu/Registry.java index a472dcca..41505673 100644 --- a/src/java/org/lwjgl/util/glu/Registry.java +++ b/src/java/org/lwjgl/util/glu/Registry.java @@ -1,36 +1,38 @@ /* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.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; diff --git a/src/java/org/lwjgl/util/glu/Sphere.java b/src/java/org/lwjgl/util/glu/Sphere.java index fcc60abe..4e335167 100644 --- a/src/java/org/lwjgl/util/glu/Sphere.java +++ b/src/java/org/lwjgl/util/glu/Sphere.java @@ -1,38 +1,38 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.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(); } } diff --git a/src/java/org/lwjgl/util/glu/Util.java b/src/java/org/lwjgl/util/glu/Util.java index ea45d123..10cbb3fe 100644 --- a/src/java/org/lwjgl/util/glu/Util.java +++ b/src/java/org/lwjgl/util/glu/Util.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -34,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(); } diff --git a/src/java/org/lwjgl/util/glu/tessellation/GLUhalfEdge.java b/src/java/org/lwjgl/util/glu/tessellation/GLUhalfEdge.java index c329b18a..65824c63 100644 --- a/src/java/org/lwjgl/util/glu/tessellation/GLUhalfEdge.java +++ b/src/java/org/lwjgl/util/glu/tessellation/GLUhalfEdge.java @@ -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; } } diff --git a/src/java/org/lwjgl/util/glu/tessellation/GLUtessellatorImpl.java b/src/java/org/lwjgl/util/glu/tessellation/GLUtessellatorImpl.java index b08b044b..dbbad30e 100644 --- a/src/java/org/lwjgl/util/glu/tessellation/GLUtessellatorImpl.java +++ b/src/java/org/lwjgl/util/glu/tessellation/GLUtessellatorImpl.java @@ -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); } } diff --git a/src/java/org/lwjgl/util/glu/tessellation/Normal.java b/src/java/org/lwjgl/util/glu/tessellation/Normal.java index b207fc20..334081a7 100644 --- a/src/java/org/lwjgl/util/glu/tessellation/Normal.java +++ b/src/java/org/lwjgl/util/glu/tessellation/Normal.java @@ -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; diff --git a/src/java/org/lwjgl/util/glu/tessellation/PriorityQ.java b/src/java/org/lwjgl/util/glu/tessellation/PriorityQ.java index a93f283c..92bee823 100644 --- a/src/java/org/lwjgl/util/glu/tessellation/PriorityQ.java +++ b/src/java/org/lwjgl/util/glu/tessellation/PriorityQ.java @@ -96,7 +96,7 @@ abstract class PriorityQ { int node; } - public static interface Leq { + public interface Leq { boolean leq(Object key1, Object key2); } diff --git a/src/java/org/lwjgl/util/glu/tessellation/PriorityQHeap.java b/src/java/org/lwjgl/util/glu/tessellation/PriorityQHeap.java index 550e86f1..2a177cb8 100644 --- a/src/java/org/lwjgl/util/glu/tessellation/PriorityQHeap.java +++ b/src/java/org/lwjgl/util/glu/tessellation/PriorityQHeap.java @@ -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]; diff --git a/src/java/org/lwjgl/util/glu/tessellation/PriorityQSort.java b/src/java/org/lwjgl/util/glu/tessellation/PriorityQSort.java index b5f0834f..c8c54ed3 100644 --- a/src/java/org/lwjgl/util/glu/tessellation/PriorityQSort.java +++ b/src/java/org/lwjgl/util/glu/tessellation/PriorityQSort.java @@ -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]; diff --git a/src/java/org/lwjgl/util/glu/tessellation/Render.java b/src/java/org/lwjgl/util/glu/tessellation/Render.java index aa9bec96..efc4c431 100644 --- a/src/java/org/lwjgl/util/glu/tessellation/Render.java +++ b/src/java/org/lwjgl/util/glu/tessellation/Render.java @@ -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) { diff --git a/src/java/org/lwjgl/util/glu/tessellation/Sweep.java b/src/java/org/lwjgl/util/glu/tessellation/Sweep.java index 7d35cedf..82bb6255 100644 --- a/src/java/org/lwjgl/util/glu/tessellation/Sweep.java +++ b/src/java/org/lwjgl/util/glu/tessellation/Sweep.java @@ -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) /* diff --git a/src/java/org/lwjgl/util/jinput/KeyMap.java b/src/java/org/lwjgl/util/jinput/KeyMap.java index eec1675f..e619e9d0 100644 --- a/src/java/org/lwjgl/util/jinput/KeyMap.java +++ b/src/java/org/lwjgl/util/jinput/KeyMap.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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; diff --git a/src/java/org/lwjgl/util/jinput/LWJGLKeyboard.java b/src/java/org/lwjgl/util/jinput/LWJGLKeyboard.java index f024b528..f1eb0a6d 100644 --- a/src/java/org/lwjgl/util/jinput/LWJGLKeyboard.java +++ b/src/java/org/lwjgl/util/jinput/LWJGLKeyboard.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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 components = new ArrayList(); 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; } } diff --git a/src/java/org/lwjgl/util/jinput/LWJGLMouse.java b/src/java/org/lwjgl/util/jinput/LWJGLMouse.java index bb9ec9c7..31b65aac 100644 --- a/src/java/org/lwjgl/util/jinput/LWJGLMouse.java +++ b/src/java/org/lwjgl/util/jinput/LWJGLMouse.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -44,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; } } diff --git a/src/java/org/lwjgl/util/vector/Matrix.java b/src/java/org/lwjgl/util/vector/Matrix.java index 23a1411b..4346d562 100644 --- a/src/java/org/lwjgl/util/vector/Matrix.java +++ b/src/java/org/lwjgl/util/vector/Matrix.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -48,7 +48,7 @@ public abstract class Matrix implements Serializable { /** * Constructor for Matrix. */ - public Matrix() { + protected Matrix() { super(); } @@ -57,41 +57,41 @@ public abstract class Matrix implements Serializable { * @return this */ public abstract Matrix setIdentity(); - + /** * Invert this matrix * @return this */ public abstract Matrix invert(); - + /** * Load from a float buffer. The buffer stores the matrix in column major * (OpenGL) order. - * + * * @param buf A float buffer to read from * @return this */ public abstract Matrix load(FloatBuffer buf); - + /** * Load from a float buffer. The buffer stores the matrix in row major * (mathematical) order. - * + * * @param buf A float buffer to read from * @return this */ public abstract Matrix loadTranspose(FloatBuffer buf); - + /** * Negate this matrix * @return this */ public abstract Matrix negate(); - + /** * Store this matrix in a float buffer. The matrix is stored in column @@ -100,7 +100,7 @@ public abstract class Matrix implements Serializable { * @return this */ public abstract Matrix store(FloatBuffer buf); - + /** * Store this matrix in a float buffer. The matrix is stored in row @@ -109,21 +109,21 @@ public abstract class Matrix implements Serializable { * @return this */ public abstract Matrix storeTranspose(FloatBuffer buf); - + /** * Transpose this matrix * @return this */ public abstract Matrix transpose(); - + /** * Set this matrix to 0. * @return this */ public abstract Matrix setZero(); - + /** * @return the determinant of the matrix diff --git a/src/java/org/lwjgl/util/vector/Matrix2f.java b/src/java/org/lwjgl/util/vector/Matrix2f.java index b374e282..894b4b94 100644 --- a/src/java/org/lwjgl/util/vector/Matrix2f.java +++ b/src/java/org/lwjgl/util/vector/Matrix2f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -44,25 +44,25 @@ import java.nio.FloatBuffer; */ public class Matrix2f extends Matrix implements Serializable { - + private static final long serialVersionUID = 1L; public float m00, m01, m10, m11; - + /** * Constructor for Matrix2f. The matrix is initialised to the identity. */ public Matrix2f() { setIdentity(); } - + /** * Constructor */ public Matrix2f(Matrix2f src) { load(src); } - + /** * Load from another matrix * @param src The source matrix @@ -71,7 +71,7 @@ public class Matrix2f extends Matrix implements Serializable { public Matrix2f load(Matrix2f src) { return load(src, this); } - + /** * Copy the source matrix to the destination matrix. * @param src The source matrix @@ -81,49 +81,49 @@ public class Matrix2f extends Matrix implements Serializable { public static Matrix2f load(Matrix2f src, Matrix2f dest) { if (dest == null) dest = new Matrix2f(); - + dest.m00 = src.m00; dest.m01 = src.m01; dest.m10 = src.m10; dest.m11 = src.m11; - + return dest; } - + /** * Load from a float buffer. The buffer stores the matrix in column major * (OpenGL) order. - * + * * @param buf A float buffer to read from * @return this */ public Matrix load(FloatBuffer buf) { - + m00 = buf.get(); m01 = buf.get(); m10 = buf.get(); m11 = buf.get(); - + return this; } - + /** * Load from a float buffer. The buffer stores the matrix in row major * (mathematical) order. - * + * * @param buf A float buffer to read from * @return this */ public Matrix loadTranspose(FloatBuffer buf) { - + m00 = buf.get(); m10 = buf.get(); m01 = buf.get(); m11 = buf.get(); - + return this; - } - + } + /** * Store this matrix in a float buffer. The matrix is stored in column * major (openGL) order. @@ -136,7 +136,7 @@ public class Matrix2f extends Matrix implements Serializable { buf.put(m11); return this; } - + /** * Store this matrix in a float buffer. The matrix is stored in row * major (maths) order. @@ -148,10 +148,10 @@ public class Matrix2f extends Matrix implements Serializable { buf.put(m01); buf.put(m11); return this; - } - - - + } + + + /** * Add two matrices together and place the result in a third matrix. * @param left The left source matrix @@ -162,14 +162,14 @@ public class Matrix2f extends Matrix implements Serializable { public static Matrix2f add(Matrix2f left, Matrix2f right, Matrix2f dest) { if (dest == null) dest = new Matrix2f(); - + dest.m00 = left.m00 + right.m00; dest.m01 = left.m01 + right.m01; dest.m10 = left.m10 + right.m10; dest.m11 = left.m11 + right.m11; - - return dest; - } + + return dest; + } /** * Subtract the right matrix from the left and place the result in a third matrix. @@ -181,14 +181,14 @@ public class Matrix2f extends Matrix implements Serializable { public static Matrix2f sub(Matrix2f left, Matrix2f right, Matrix2f dest) { if (dest == null) dest = new Matrix2f(); - + dest.m00 = left.m00 - right.m00; dest.m01 = left.m01 - right.m01; dest.m10 = left.m10 - right.m10; dest.m11 = left.m11 - right.m11; - - return dest; - } + + return dest; + } /** * Multiply the right matrix by the left and place the result in a third matrix. @@ -200,23 +200,23 @@ public class Matrix2f extends Matrix implements Serializable { public static Matrix2f mul(Matrix2f left, Matrix2f right, Matrix2f dest) { if (dest == null) dest = new Matrix2f(); - + float m00 = left.m00 * right.m00 + left.m10 * right.m01; float m01 = left.m01 * right.m00 + left.m11 * right.m01; float m10 = left.m00 * right.m10 + left.m10 * right.m11; float m11 = left.m01 * right.m10 + left.m11 * right.m11; - + dest.m00 = m00; dest.m01 = m01; dest.m10 = m10; dest.m11 = m11; - - return dest; + + return dest; } - + /** * Transform a Vector by a matrix and return the result in a destination - * vector. + * vector. * @param left The left matrix * @param right The right vector * @param dest The destination vector, or null if a new one is to be created @@ -225,16 +225,16 @@ public class Matrix2f extends Matrix implements Serializable { public static Vector2f transform(Matrix2f left, Vector2f right, Vector2f dest) { if (dest == null) dest = new Vector2f(); - + float x = left.m00 * right.x + left.m10 * right.y; float y = left.m01 * right.x + left.m11 * right.y; - + dest.x = x; dest.y = y; - return dest; + return dest; } - + /** * Transpose this matrix * @return this @@ -242,7 +242,7 @@ public class Matrix2f extends Matrix implements Serializable { public Matrix transpose() { return transpose(this); } - + /** * Transpose this matrix and place the result in another matrix. * @param dest The destination matrix or null if a new matrix is to be created @@ -250,7 +250,7 @@ public class Matrix2f extends Matrix implements Serializable { */ public Matrix2f transpose(Matrix2f dest) { return transpose(this, dest); - } + } /** * Transpose the source matrix and place the result in the destination matrix. @@ -267,7 +267,7 @@ public class Matrix2f extends Matrix implements Serializable { dest.m01 = m01; dest.m10 = m10; - + return dest; } @@ -278,7 +278,7 @@ public class Matrix2f extends Matrix implements Serializable { public Matrix invert() { return invert(this, this); } - + /** * Invert the source matrix and place the result in the destination matrix. * @param src The source matrix to be inverted @@ -289,7 +289,7 @@ public class Matrix2f extends Matrix implements Serializable { /* *inv(A) = 1/det(A) * adj(A); */ - + float determinant = src.determinant(); if (determinant != 0) { if (dest == null) @@ -299,7 +299,7 @@ public class Matrix2f extends Matrix implements Serializable { float t01 = -src.m01*determinant_inv; float t11 = src.m00*determinant_inv; float t10 = -src.m10*determinant_inv; - + dest.m00 = t00; dest.m01 = t01; dest.m10 = t10; @@ -313,12 +313,12 @@ 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(); } - + /** * Negate this matrix * @return this @@ -326,7 +326,7 @@ public class Matrix2f extends Matrix implements Serializable { public Matrix negate() { return negate(this); } - + /** * Negate this matrix and stash the result in another matrix. * @param dest The destination matrix, or null if a new matrix is to be created @@ -335,7 +335,7 @@ public class Matrix2f extends Matrix implements Serializable { public Matrix2f negate(Matrix2f dest) { return negate(this, this); } - + /** * Negate the source matrix and stash the result in the destination matrix. * @param src The source matrix to be negated @@ -345,12 +345,12 @@ public class Matrix2f extends Matrix implements Serializable { public static Matrix2f negate(Matrix2f src, Matrix2f dest) { if (dest == null) dest = new Matrix2f(); - + dest.m00 = -src.m00; dest.m01 = -src.m01; dest.m10 = -src.m10; dest.m11 = -src.m11; - + return dest; } @@ -374,7 +374,7 @@ public class Matrix2f extends Matrix implements Serializable { src.m11 = 1.0f; return src; } - + /** * Set this matrix to 0. * @return this @@ -390,7 +390,7 @@ public class Matrix2f extends Matrix implements Serializable { src.m11 = 0.0f; return src; } - + /* (non-Javadoc) * @see org.lwjgl.vector.Matrix#determinant() */ diff --git a/src/java/org/lwjgl/util/vector/Matrix3f.java b/src/java/org/lwjgl/util/vector/Matrix3f.java index 4f4162e0..3d3128c3 100644 --- a/src/java/org/lwjgl/util/vector/Matrix3f.java +++ b/src/java/org/lwjgl/util/vector/Matrix3f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -37,7 +37,7 @@ import java.nio.FloatBuffer; /** * * Holds a 3x3 matrix. - * + * * @author cix_foo * @version $Revision$ * $Id$ @@ -64,7 +64,7 @@ public class Matrix3f extends Matrix implements Serializable { super(); setIdentity(); } - + /** * Load from another matrix * @param src The source matrix @@ -73,7 +73,7 @@ public class Matrix3f extends Matrix implements Serializable { public Matrix3f load(Matrix3f src) { return load(src, this); } - + /** * Copy source matrix to destination matrix * @param src The source matrix @@ -96,16 +96,16 @@ public class Matrix3f extends Matrix implements Serializable { return dest; } - + /** * Load from a float buffer. The buffer stores the matrix in column major * (OpenGL) order. - * + * * @param buf A float buffer to read from * @return this */ public Matrix load(FloatBuffer buf) { - + m00 = buf.get(); m01 = buf.get(); m02 = buf.get(); @@ -115,19 +115,19 @@ public class Matrix3f extends Matrix implements Serializable { m20 = buf.get(); m21 = buf.get(); m22 = buf.get(); - + return this; } - + /** * Load from a float buffer. The buffer stores the matrix in row major * (maths) order. - * + * * @param buf A float buffer to read from * @return this */ public Matrix loadTranspose(FloatBuffer buf) { - + m00 = buf.get(); m10 = buf.get(); m20 = buf.get(); @@ -137,10 +137,10 @@ public class Matrix3f extends Matrix implements Serializable { m02 = buf.get(); m12 = buf.get(); m22 = buf.get(); - + return this; - } - + } + /** * Store this matrix in a float buffer. The matrix is stored in column * major (openGL) order. @@ -158,7 +158,7 @@ public class Matrix3f extends Matrix implements Serializable { buf.put(m22); return this; } - + /** * Store this matrix in a float buffer. The matrix is stored in row * major (maths) order. @@ -175,7 +175,7 @@ public class Matrix3f extends Matrix implements Serializable { buf.put(m12); buf.put(m22); return this; - } + } /** * Add two matrices together and place the result in a third matrix. @@ -270,7 +270,7 @@ public class Matrix3f extends Matrix implements Serializable { /** * Transform a Vector by a matrix and return the result in a destination - * vector. + * vector. * @param left The left matrix * @param right The right vector * @param dest The destination vector, or null if a new one is to be created @@ -316,16 +316,16 @@ public class Matrix3f extends Matrix implements Serializable { */ public static Matrix3f transpose(Matrix3f src, Matrix3f dest) { if (dest == null) - dest = new Matrix3f(); - float m00 = src.m00; - float m01 = src.m10; - float m02 = src.m20; - float m10 = src.m01; - float m11 = src.m11; - float m12 = src.m21; - float m20 = src.m02; - float m21 = src.m12; - float m22 = src.m22; + dest = new Matrix3f(); + float m00 = src.m00; + float m01 = src.m10; + float m02 = src.m20; + float m10 = src.m01; + float m11 = src.m11; + float m12 = src.m21; + float m20 = src.m02; + float m21 = src.m12; + float m22 = src.m22; dest.m00 = m00; dest.m01 = m01; @@ -336,7 +336,7 @@ public class Matrix3f extends Matrix implements Serializable { dest.m20 = m20; dest.m21 = m21; dest.m22 = m22; - return dest; + return dest; } /** @@ -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'); @@ -377,7 +377,7 @@ public class Matrix3f extends Matrix implements Serializable { */ public static Matrix3f invert(Matrix3f src, Matrix3f dest) { float determinant = src.determinant(); - + if (determinant != 0) { if (dest == null) dest = new Matrix3f(); @@ -385,12 +385,12 @@ public class Matrix3f extends Matrix implements Serializable { * * inv(A) = 1/det(A) * adj(T), where adj(T) = transpose(Conjugate Matrix) * - * m00 m01 m02 + * m00 m01 m02 * m10 m11 m12 - * m20 m21 m22 + * m20 m21 m22 */ float determinant_inv = 1f/determinant; - + // get the conjugate matrix float t00 = src.m11 * src.m22 - src.m12* src.m21; float t01 = - src.m10 * src.m22 + src.m12 * src.m20; @@ -463,7 +463,7 @@ public class Matrix3f extends Matrix implements Serializable { public Matrix setIdentity() { return setIdentity(this); } - + /** * Set the matrix to be the identity matrix. * @param m The matrix to be set to the identity diff --git a/src/java/org/lwjgl/util/vector/Matrix4f.java b/src/java/org/lwjgl/util/vector/Matrix4f.java index e4c4e789..acfa7700 100644 --- a/src/java/org/lwjgl/util/vector/Matrix4f.java +++ b/src/java/org/lwjgl/util/vector/Matrix4f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -43,7 +43,7 @@ public class Matrix4f extends Matrix implements Serializable { private static final long serialVersionUID = 1L; public float m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33; - + /** * Construct a new matrix, initialized to the identity. */ @@ -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'); @@ -71,7 +71,7 @@ public class Matrix4f extends Matrix implements Serializable { public Matrix setIdentity() { return setIdentity(this); } - + /** * Set the given matrix to be the identity matrix. * @param m The matrix to set to the identity @@ -94,7 +94,7 @@ public class Matrix4f extends Matrix implements Serializable { m.m31 = 0.0f; m.m32 = 0.0f; m.m33 = 1.0f; - + return m; } @@ -128,7 +128,7 @@ public class Matrix4f extends Matrix implements Serializable { m.m31 = 0.0f; m.m32 = 0.0f; m.m33 = 0.0f; - + return m; } @@ -140,7 +140,7 @@ public class Matrix4f extends Matrix implements Serializable { public Matrix4f load(Matrix4f src) { return load(src, this); } - + /** * Copy the source matrix to the destination matrix * @param src The source matrix @@ -166,19 +166,19 @@ public class Matrix4f extends Matrix implements Serializable { dest.m31 = src.m31; dest.m32 = src.m32; dest.m33 = src.m33; - + return dest; } - + /** * Load from a float buffer. The buffer stores the matrix in column major * (OpenGL) order. - * + * * @param buf A float buffer to read from * @return this */ public Matrix load(FloatBuffer buf) { - + m00 = buf.get(); m01 = buf.get(); m02 = buf.get(); @@ -195,19 +195,19 @@ public class Matrix4f extends Matrix implements Serializable { m31 = buf.get(); m32 = buf.get(); m33 = buf.get(); - + return this; } - + /** * Load from a float buffer. The buffer stores the matrix in row major * (maths) order. - * + * * @param buf A float buffer to read from * @return this */ public Matrix loadTranspose(FloatBuffer buf) { - + m00 = buf.get(); m10 = buf.get(); m20 = buf.get(); @@ -224,10 +224,10 @@ public class Matrix4f extends Matrix implements Serializable { m13 = buf.get(); m23 = buf.get(); m33 = buf.get(); - + return this; - } - + } + /** * Store this matrix in a float buffer. The matrix is stored in column * major (openGL) order. @@ -252,7 +252,7 @@ public class Matrix4f extends Matrix implements Serializable { buf.put(m33); return this; } - + /** * Store this matrix in a float buffer. The matrix is stored in row * major (maths) order. @@ -276,9 +276,9 @@ public class Matrix4f extends Matrix implements Serializable { buf.put(m23); buf.put(m33); return this; - } - - + } + + /** * Add two matrices together and place the result in a third matrix. * @param left The left source matrix @@ -289,7 +289,7 @@ public class Matrix4f extends Matrix implements Serializable { public static Matrix4f add(Matrix4f left, Matrix4f right, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); - + dest.m00 = left.m00 + right.m00; dest.m01 = left.m01 + right.m01; dest.m02 = left.m02 + right.m02; @@ -307,8 +307,8 @@ public class Matrix4f extends Matrix implements Serializable { dest.m32 = left.m32 + right.m32; dest.m33 = left.m33 + right.m33; - return dest; - } + return dest; + } /** * Subtract the right matrix from the left and place the result in a third matrix. @@ -320,7 +320,7 @@ public class Matrix4f extends Matrix implements Serializable { public static Matrix4f sub(Matrix4f left, Matrix4f right, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); - + dest.m00 = left.m00 - right.m00; dest.m01 = left.m01 - right.m01; dest.m02 = left.m02 - right.m02; @@ -337,9 +337,9 @@ public class Matrix4f extends Matrix implements Serializable { dest.m31 = left.m31 - right.m31; dest.m32 = left.m32 - right.m32; dest.m33 = left.m33 - right.m33; - - return dest; - } + + return dest; + } /** * Multiply the right matrix by the left and place the result in a third matrix. @@ -388,10 +388,10 @@ public class Matrix4f extends Matrix implements Serializable { return dest; } - + /** * Transform a Vector by a matrix and return the result in a destination - * vector. + * vector. * @param left The left matrix * @param right The right vector * @param dest The destination vector, or null if a new one is to be created @@ -411,9 +411,9 @@ public class Matrix4f extends Matrix implements Serializable { dest.z = z; dest.w = w; - return dest; + return dest; } - + /** * Transpose this matrix * @return this @@ -421,7 +421,7 @@ public class Matrix4f extends Matrix implements Serializable { public Matrix transpose() { return transpose(this); } - + /** * Translate this matrix * @param vec The vector to translate by @@ -430,7 +430,7 @@ public class Matrix4f extends Matrix implements Serializable { public Matrix4f translate(Vector2f vec) { return translate(vec, this); } - + /** * Translate this matrix * @param vec The vector to translate by @@ -473,7 +473,7 @@ public class Matrix4f extends Matrix implements Serializable { dest.m23 = src.m23 * vec.z; return dest; } - + /** * Rotates the matrix around the given axis the specified angle * @param angle the angle, in radians. @@ -494,7 +494,7 @@ public class Matrix4f extends Matrix implements Serializable { public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) { return rotate(angle, axis, this, dest); } - + /** * Rotates the source matrix around the given axis the specified angle and * put the result in the destination matrix. @@ -572,15 +572,15 @@ public class Matrix4f extends Matrix implements Serializable { public static Matrix4f translate(Vector3f vec, Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); - + dest.m30 += src.m00 * vec.x + src.m10 * vec.y + src.m20 * vec.z; dest.m31 += src.m01 * vec.x + src.m11 * vec.y + src.m21 * vec.z; dest.m32 += src.m02 * vec.x + src.m12 * vec.y + src.m22 * vec.z; dest.m33 += src.m03 * vec.x + src.m13 * vec.y + src.m23 * vec.z; - + return dest; } - + /** * Translate this matrix and stash the result in another matrix * @param vec The vector to translate by @@ -590,7 +590,7 @@ public class Matrix4f extends Matrix implements Serializable { public Matrix4f translate(Vector2f vec, Matrix4f dest) { return translate(vec, this, dest); } - + /** * Translate the source matrix and stash the result in the destination matrix * @param vec The vector to translate by @@ -601,14 +601,14 @@ public class Matrix4f extends Matrix implements Serializable { public static Matrix4f translate(Vector2f vec, Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); - + dest.m30 += src.m00 * vec.x + src.m10 * vec.y; dest.m31 += src.m01 * vec.x + src.m11 * vec.y; dest.m32 += src.m02 * vec.x + src.m12 * vec.y; dest.m33 += src.m03 * vec.x + src.m13 * vec.y; - + return dest; - } + } /** * Transpose this matrix and place the result in another matrix @@ -618,7 +618,7 @@ public class Matrix4f extends Matrix implements Serializable { public Matrix4f transpose(Matrix4f dest) { return transpose(this, dest); } - + /** * Transpose the source matrix and place the result in the destination matrix * @param src The source matrix @@ -626,24 +626,24 @@ public class Matrix4f extends Matrix implements Serializable { * @return the transposed matrix */ public static Matrix4f transpose(Matrix4f src, Matrix4f dest) { - if (dest == null) - dest = new Matrix4f(); - float m00 = src.m00; - float m01 = src.m10; - float m02 = src.m20; - float m03 = src.m30; - float m10 = src.m01; - float m11 = src.m11; - float m12 = src.m21; - float m13 = src.m31; - float m20 = src.m02; - float m21 = src.m12; - float m22 = src.m22; - float m23 = src.m32; - float m30 = src.m03; - float m31 = src.m13; - float m32 = src.m23; - float m33 = src.m33; + if (dest == null) + dest = new Matrix4f(); + float m00 = src.m00; + float m01 = src.m10; + float m02 = src.m20; + float m03 = src.m30; + float m10 = src.m01; + float m11 = src.m11; + float m12 = src.m21; + float m13 = src.m31; + float m20 = src.m02; + float m21 = src.m12; + float m22 = src.m22; + float m23 = src.m32; + float m30 = src.m03; + float m31 = src.m13; + float m32 = src.m23; + float m33 = src.m33; dest.m00 = m00; dest.m01 = m01; @@ -692,7 +692,7 @@ public class Matrix4f extends Matrix implements Serializable { - m11 * m20 * m32); return f; } - + /** * Calculate the determinant of a 3x3 matrix * @return result @@ -702,7 +702,7 @@ public class Matrix4f extends Matrix implements Serializable { float t10, float t11, float t12, float t20, float t21, float t22) { - return t00 * (t11 * t22 - t12 * t21) + return t00 * (t11 * t22 - t12 * t21) + t01 * (t12 * t20 - t10 * t22) + t02 * (t10 * t21 - t11 * t20); } @@ -723,7 +723,7 @@ public class Matrix4f extends Matrix implements Serializable { */ public static Matrix4f invert(Matrix4f src, Matrix4f dest) { float determinant = src.determinant(); - + if (determinant != 0) { /* * m00 m01 m02 m03 @@ -734,7 +734,7 @@ public class Matrix4f extends Matrix implements Serializable { if (dest == null) dest = new Matrix4f(); float determinant_inv = 1f/determinant; - + // first row float t00 = determinant3x3(src.m11, src.m12, src.m13, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33); float t01 = -determinant3x3(src.m10, src.m12, src.m13, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33); @@ -755,7 +755,7 @@ public class Matrix4f extends Matrix implements Serializable { float t31 = determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m20, src.m22, src.m23); float t32 = -determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m20, src.m21, src.m23); float t33 = determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m20, src.m21, src.m22); - + // transpose and divide by the determinant dest.m00 = t00*determinant_inv; dest.m11 = t11*determinant_inv; @@ -777,7 +777,7 @@ public class Matrix4f extends Matrix implements Serializable { } else return null; } - + /** * Negate this matrix * @return this @@ -785,7 +785,7 @@ public class Matrix4f extends Matrix implements Serializable { public Matrix negate() { return negate(this); } - + /** * Negate this matrix and place the result in a destination matrix. * @param dest The destination matrix, or null if a new matrix is to be created @@ -794,7 +794,7 @@ public class Matrix4f extends Matrix implements Serializable { public Matrix4f negate(Matrix4f dest) { return negate(this, this); } - + /** * Negate this matrix and place the result in a destination matrix. * @param src The source matrix diff --git a/src/java/org/lwjgl/util/vector/Quaternion.java b/src/java/org/lwjgl/util/vector/Quaternion.java index 18783e8a..99d21b27 100644 --- a/src/java/org/lwjgl/util/vector/Quaternion.java +++ b/src/java/org/lwjgl/util/vector/Quaternion.java @@ -1,40 +1,40 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.lwjgl.util.vector; /** - * + * * Quaternions for LWJGL! - * + * * @author fbi * @version $Revision$ * $Id$ @@ -57,7 +57,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * C'tor - * + * * @param src */ public Quaternion(ReadableVector4f src) { @@ -66,7 +66,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * C'tor - * + * */ public Quaternion(float x, float y, float z, float w) { set(x, y, z, w); @@ -74,7 +74,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /* * (non-Javadoc) - * + * * @see org.lwjgl.util.vector.WritableVector2f#set(float, float) */ public void set(float x, float y) { @@ -84,7 +84,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /* * (non-Javadoc) - * + * * @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float) */ public void set(float x, float y, float z) { @@ -95,7 +95,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /* * (non-Javadoc) - * + * * @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, * float) */ @@ -108,7 +108,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Load from another Vector4f - * + * * @param src * The source vector * @return this @@ -128,7 +128,7 @@ public class Quaternion extends Vector implements ReadableVector4f { public Quaternion setIdentity() { return setIdentity(this); } - + /** * Set the given quaternion to the multiplication identity. * @param q The quaternion @@ -151,7 +151,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Normalise the source quaternion and place the result in another quaternion. - * + * * @param src * The source quaternion * @param dest @@ -172,7 +172,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Normalise this quaternion and place the result in another quaternion. - * + * * @param dest * The destination quaternion, or null if a new quaternion is to be * created @@ -184,7 +184,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * The dot product of two quaternions - * + * * @param left * The LHS quat * @param right @@ -198,7 +198,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Calculate the conjugate of this quaternion and put it into the given one - * + * * @param dest * The quaternion which should be set to the conjugate of this * quaternion @@ -209,7 +209,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Calculate the conjugate of this quaternion and put it into the given one - * + * * @param src * The source quaternion * @param dest @@ -248,13 +248,13 @@ public class Quaternion extends Vector implements ReadableVector4f { /* * (non-Javadoc) - * + * * @see org.lwjgl.vector.Vector#scale(float) */ public Vector scale(float scale) { return scale(scale, this, this); } - + /** * Scale the source quaternion by scale and put the result in the destination * @param scale The amount to scale by @@ -300,7 +300,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Set X - * + * * @param x */ public final void setX(float x) { @@ -309,7 +309,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Set Y - * + * * @param y */ public final void setY(float y) { @@ -318,7 +318,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Set Z - * + * * @param z */ public void setZ(float z) { @@ -327,7 +327,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /* * (Overrides) - * + * * @see org.lwjgl.vector.ReadableVector3f#getZ() */ public float getZ() { @@ -336,7 +336,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Set W - * + * * @param w */ public void setW(float w) { @@ -345,7 +345,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /* * (Overrides) - * + * * @see org.lwjgl.vector.ReadableVector3f#getW() */ public float getW() { @@ -360,7 +360,7 @@ public class Quaternion extends Vector implements ReadableVector4f { * Sets the value of this quaternion to the quaternion product of * quaternions left and right (this = left * right). Note that this is safe * for aliasing (e.g. this can be left or right). - * + * * @param left * the first quaternion * @param right @@ -380,11 +380,11 @@ public class Quaternion extends Vector implements ReadableVector4f { } /** - * + * * Multiplies quaternion left by the inverse of quaternion right and places * the value into this quaternion. The value of both argument quaternions is * preservered (this = left * right^-1). - * + * * @param left * the left quaternion * @param right @@ -415,7 +415,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Sets the value of this quaternion to the equivalent rotation of the * Axis-Angle argument. - * + * * @param a1 * the axis-angle: (x,y,z) is the axis and w is the angle */ @@ -435,7 +435,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Sets the value of this quaternion using the rotational component of the * passed matrix. - * + * * @param m * The matrix * @return this @@ -447,14 +447,14 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Sets the value of the source quaternion using the rotational component of the * passed matrix. - * + * * @param m * The source matrix * @param q * 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); } @@ -462,7 +462,7 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Sets the value of this quaternion using the rotational component of the * passed matrix. - * + * * @param m * The source matrix */ @@ -473,14 +473,14 @@ public class Quaternion extends Vector implements ReadableVector4f { /** * Sets the value of the source quaternion using the rotational component of the * passed matrix. - * + * * @param m * The source matrix * @param q * 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); } diff --git a/src/java/org/lwjgl/util/vector/ReadableVector.java b/src/java/org/lwjgl/util/vector/ReadableVector.java index 61abdb65..7690fe7d 100644 --- a/src/java/org/lwjgl/util/vector/ReadableVector.java +++ b/src/java/org/lwjgl/util/vector/ReadableVector.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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); } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/vector/ReadableVector2f.java b/src/java/org/lwjgl/util/vector/ReadableVector2f.java index 686ace55..2342bce8 100644 --- a/src/java/org/lwjgl/util/vector/ReadableVector2f.java +++ b/src/java/org/lwjgl/util/vector/ReadableVector2f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -38,9 +38,9 @@ public interface ReadableVector2f extends ReadableVector { /** * @return x */ - public float getX(); + float getX(); /** * @return y */ - public float getY(); + float getY(); } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/vector/ReadableVector3f.java b/src/java/org/lwjgl/util/vector/ReadableVector3f.java index 53ae9feb..5f77f5ac 100644 --- a/src/java/org/lwjgl/util/vector/ReadableVector3f.java +++ b/src/java/org/lwjgl/util/vector/ReadableVector3f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -38,5 +38,5 @@ public interface ReadableVector3f extends ReadableVector2f { /** * @return z */ - public float getZ(); + float getZ(); } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/vector/ReadableVector4f.java b/src/java/org/lwjgl/util/vector/ReadableVector4f.java index d7adeba3..5dee3e3b 100644 --- a/src/java/org/lwjgl/util/vector/ReadableVector4f.java +++ b/src/java/org/lwjgl/util/vector/ReadableVector4f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -35,10 +35,10 @@ package org.lwjgl.util.vector; * @author foo */ public interface ReadableVector4f extends ReadableVector3f { - + /** * @return w */ - public float getW(); + float getW(); } diff --git a/src/java/org/lwjgl/util/vector/Vector.java b/src/java/org/lwjgl/util/vector/Vector.java index f223c173..465969c6 100644 --- a/src/java/org/lwjgl/util/vector/Vector.java +++ b/src/java/org/lwjgl/util/vector/Vector.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -47,7 +47,7 @@ public abstract class Vector implements Serializable, ReadableVector { /** * Constructor for Vector. */ - public Vector() { + protected Vector() { super(); } @@ -57,26 +57,26 @@ public abstract class Vector implements Serializable, ReadableVector { public final float length() { return (float) Math.sqrt(lengthSquared()); } - + /** * @return the length squared of the vector */ public abstract float lengthSquared(); - + /** * Load this vector from a FloatBuffer * @param buf The buffer to load it from, at the current position * @return this */ - public abstract Vector load(FloatBuffer buf); + public abstract Vector load(FloatBuffer buf); /** * Negate a vector * @return this */ public abstract Vector negate(); - + /** * Normalise this vector @@ -90,14 +90,14 @@ public abstract class Vector implements Serializable, ReadableVector { } else throw new IllegalStateException("Zero length vector"); } - + /** * Store this vector in a FloatBuffer * @param buf The buffer to store it in, at the current position * @return this */ - public abstract Vector store(FloatBuffer buf); + public abstract Vector store(FloatBuffer buf); /** @@ -105,7 +105,7 @@ public abstract class Vector implements Serializable, ReadableVector { * @param scale The scale factor * @return this */ - public abstract Vector scale(float scale); + public abstract Vector scale(float scale); diff --git a/src/java/org/lwjgl/util/vector/Vector2f.java b/src/java/org/lwjgl/util/vector/Vector2f.java index 920063f9..2dfb811f 100644 --- a/src/java/org/lwjgl/util/vector/Vector2f.java +++ b/src/java/org/lwjgl/util/vector/Vector2f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -37,7 +37,7 @@ import java.nio.FloatBuffer; /** * * Holds a 2-tuple vector. - * + * * @author cix_foo * @version $Revision$ * $Id$ @@ -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); diff --git a/src/java/org/lwjgl/util/vector/Vector3f.java b/src/java/org/lwjgl/util/vector/Vector3f.java index 51d9d0cd..580778b6 100644 --- a/src/java/org/lwjgl/util/vector/Vector3f.java +++ b/src/java/org/lwjgl/util/vector/Vector3f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -37,7 +37,7 @@ import java.nio.FloatBuffer; /** * * Holds a 3-tuple vector. - * + * * @author cix_foo * @version $Revision$ * $Id$ @@ -155,7 +155,7 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f, /** * The cross product of two vectors. - * + * * @param left The LHS vector * @param right The RHS vector * @param dest The destination result, or null if a new vector is to be created @@ -177,7 +177,7 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f, ); return dest; - } + } @@ -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); diff --git a/src/java/org/lwjgl/util/vector/WritableVector2f.java b/src/java/org/lwjgl/util/vector/WritableVector2f.java index 375fcb16..a664a43b 100644 --- a/src/java/org/lwjgl/util/vector/WritableVector2f.java +++ b/src/java/org/lwjgl/util/vector/WritableVector2f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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); + } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/vector/WritableVector3f.java b/src/java/org/lwjgl/util/vector/WritableVector3f.java index 7297661f..f626f370 100644 --- a/src/java/org/lwjgl/util/vector/WritableVector3f.java +++ b/src/java/org/lwjgl/util/vector/WritableVector3f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -43,14 +43,14 @@ 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 * @param x * @param y * @param z */ - public void set(float x, float y, float z); - + void set(float x, float y, float z); + } \ No newline at end of file diff --git a/src/java/org/lwjgl/util/vector/WritableVector4f.java b/src/java/org/lwjgl/util/vector/WritableVector4f.java index 26fc5a42..ac8d3af8 100644 --- a/src/java/org/lwjgl/util/vector/WritableVector4f.java +++ b/src/java/org/lwjgl/util/vector/WritableVector4f.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2008 LWJGL Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -43,8 +43,8 @@ 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 * @param x @@ -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); + } \ No newline at end of file diff --git a/src/native/common/extcl_types.h b/src/native/common/extcl_types.h index f3b7220a..042307c4 100644 --- a/src/native/common/extcl_types.h +++ b/src/native/common/extcl_types.h @@ -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; diff --git a/src/native/common/org_lwjgl_opencl_CL.c b/src/native/common/org_lwjgl_opencl_CL.c index 04d22793..ab342844 100644 --- a/src/native/common/org_lwjgl_opencl_CL.c +++ b/src/native/common/org_lwjgl_opencl_CL.c @@ -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) { diff --git a/src/native/common/org_lwjgl_opencl_CL.h b/src/native/common/org_lwjgl_opencl_CL.h index 6ba4c5c7..21fac166 100644 --- a/src/native/common/org_lwjgl_opencl_CL.h +++ b/src/native/common/org_lwjgl_opencl_CL.h @@ -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 diff --git a/src/templates/org/lwjgl/opencl/AMD_event_callback.java b/src/templates/org/lwjgl/opencl/AMD_event_callback.java new file mode 100644 index 00000000..909d6518 --- /dev/null +++ b/src/templates/org/lwjgl/opencl/AMD_event_callback.java @@ -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 +} \ No newline at end of file diff --git a/src/templates/org/lwjgl/opencl/CL10.java b/src/templates/org/lwjgl/opencl/CL10.java index d39a0d2f..bcdcfb8b 100644 --- a/src/templates/org/lwjgl/opencl/CL10.java +++ b/src/templates/org/lwjgl/opencl/CL10.java @@ -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 CL_PROGRAM_DEVICES) will be written sequentially to + * the param_value buffer. The buffer size must be big enough to hold + * all the binaries, as returned by CL_PROGRAM_BINARY_SIZES. + * + * @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 CL_PROGRAM_DEVICES) will be written to the corresponding + * slot of the param_value array. The size of each buffer must be big enough to + * hold the corresponding binary, as returned by CL_PROGRAM_BINARY_SIZES. + * + * @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, diff --git a/src/templates/org/lwjgl/opencl/KHR_d3d10_sharing.java b/src/templates/org/lwjgl/opencl/KHR_d3d10_sharing.java new file mode 100644 index 00000000..cc915301 --- /dev/null +++ b/src/templates/org/lwjgl/opencl/KHR_d3d10_sharing.java @@ -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 +} \ No newline at end of file diff --git a/src/templates/org/lwjgl/opencl/KHR_icd.java b/src/templates/org/lwjgl/opencl/KHR_icd.java index fe233e44..0c33fc94 100644 --- a/src/templates/org/lwjgl/opencl/KHR_icd.java +++ b/src/templates/org/lwjgl/opencl/KHR_icd.java @@ -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, diff --git a/src/templates/org/lwjgl/opengl/ARB_sync.java b/src/templates/org/lwjgl/opengl/ARB_sync.java index bc3278ad..ebb35725 100644 --- a/src/templates/org/lwjgl/opengl/ARB_sync.java +++ b/src/templates/org/lwjgl/opengl/ARB_sync.java @@ -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") diff --git a/src/templates/org/lwjgl/opengl/GL32.java b/src/templates/org/lwjgl/opengl/GL32.java index 8a1c80e4..e2229cc2 100644 --- a/src/templates/org/lwjgl/opengl/GL32.java +++ b/src/templates/org/lwjgl/opengl/GL32.java @@ -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")