Added LWJGLUtil.getPlatform to encapsulate platform detection. Added FreeBSD as an alias to Linux.

This commit is contained in:
Elias Naur 2005-04-09 17:35:37 +00:00
parent 24c3017d68
commit 0e6c9aa0cd
11 changed files with 784 additions and 738 deletions

View File

@ -49,37 +49,59 @@ import java.util.StringTokenizer;
* @version $Revision$
*/
public class LWJGLUtil {
public static final int PLATFORM_LINUX = 1;
public static final int PLATFORM_MACOSX = 2;
public static final int PLATFORM_WINDOWS = 3;
/** Debug flag. */
/** Debug flag. */
public static final boolean DEBUG = Boolean.getBoolean("org.lwjgl.util.Debug");
/**
* Locates the paths required by a library.
*
* @param libNames List of library names to look for, in the form of Local Library name, Platform library name.
* At least 6 names must be passed. 2 for each supported platform in the following order: Windows, Linux, MacOSX.
* @param classloader The classloader to ask for librariy paths
* @return Paths to located libraries, if any
*/
public static String[] getLibraryPaths(String[] libNames, ClassLoader classloader) throws LWJGLException {
* Get the current platform
*/
public static int getPlatform() {
String osName = System.getProperty("os.name");
if (osName.startsWith("Windows")) {
return PLATFORM_WINDOWS;
} else if (osName.startsWith("Linux") || osName.startsWith("FreeBSD")) {
return PLATFORM_LINUX;
} else if (osName.startsWith("Mac OS X")) {
return PLATFORM_MACOSX;
} else {
throw new LinkageError("Unknown platform: " + osName);
}
}
/**
* Locates the paths required by a library.
*
* @param libNames List of library names to look for, in the form of Local Library name, Platform library name.
* At least 6 names must be passed. 2 for each supported platform in the following order: Windows, Linux, MacOSX.
* @param classloader The classloader to ask for librariy paths
* @return Paths to located libraries, if any
*/
public static String[] getLibraryPaths(String[] libNames, ClassLoader classloader) throws LWJGLException {
// need to pass path of possible locations of IL to native side
List possible_paths = new ArrayList();
String osName = System.getProperty("os.name");
String libname;
String platform_lib_name;
if (osName.startsWith("Win")) {
libname = libNames[0];
platform_lib_name = libNames[1];
} else if (osName.startsWith("Lin")) {
libname = libNames[2];
platform_lib_name = libNames[3];
} else if (osName.startsWith("Mac")) {
libname = libNames[4];
platform_lib_name = libNames[5];
} else {
throw new LWJGLException("Unknown platform: " + osName);
switch (getPlatform()) {
case PLATFORM_WINDOWS:
libname = libNames[0];
platform_lib_name = libNames[1];
break;
case PLATFORM_LINUX:
libname = libNames[2];
platform_lib_name = libNames[3];
break;
case PLATFORM_MACOSX:
libname = libNames[4];
platform_lib_name = libNames[5];
break;
default:
throw new LWJGLException("Unknown platform: " + getPlatform());
}
// Add all possible paths from java.library.path
@ -95,7 +117,7 @@ public class LWJGLUtil {
possible_paths.add(classloader_path);
}
String lwjgl_classloader_path = LWJGLUtil.getPathFromClassLoader("lwjgl", classloader);
String lwjgl_classloader_path = LWJGLUtil.getPathFromClassLoader("lwjgl", classloader);
if (lwjgl_classloader_path != null) {
LWJGLUtil.log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path);
possible_paths.add(lwjgl_classloader_path.substring(0, lwjgl_classloader_path.lastIndexOf(File.separator))
@ -120,7 +142,7 @@ public class LWJGLUtil {
* locate it.
*
* @param libname Name of library to search for
* @param classloader Classloader to use
* @param classloader Classloader to use
* @return Absolute path to library if found, otherwise null
*/
public static String getPathFromClassLoader(String libname, ClassLoader classloader) {

View File

@ -53,9 +53,6 @@ public final class Sys {
/** The native library name */
private static final String LIBRARY_NAME = "lwjgl";
/** OS Name */
private final static String OS_NAME = System.getProperty("os.name");
/** The implementation instance to delegate platform specific behavior to */
private final static SysImplementation implementation;
@ -71,14 +68,19 @@ public final class Sys {
private static SysImplementation createImplementation() {
String class_name;
if (OS_NAME.startsWith("Linux")) {
class_name = "org.lwjgl.LinuxSysImplementation";
} else if (OS_NAME.startsWith("Windows")) {
class_name = "org.lwjgl.Win32SysImplementation";
} else if (OS_NAME.startsWith("Mac")) {
class_name = "org.lwjgl.MacOSXSysImplementation";
} else
throw new IllegalStateException("The platform " + OS_NAME + " is not supported");
switch (LWJGLUtil.getPlatform()) {
case LWJGLUtil.PLATFORM_LINUX:
class_name = "org.lwjgl.LinuxSysImplementation";
break;
case LWJGLUtil.PLATFORM_WINDOWS:
class_name = "org.lwjgl.Win32SysImplementation";
break;
case LWJGLUtil.PLATFORM_MACOSX:
class_name = "org.lwjgl.MacOSXSysImplementation";
break;
default:
throw new IllegalStateException("Unsupported platform");
}
try {
Class impl_class = Class.forName(class_name);
return (SysImplementation)impl_class.newInstance();

View File

@ -300,7 +300,7 @@ public class IL {
public static final int IL_SEEK_CUR = 1;
public static final int IL_SEEK_END = 2;
public static final int IL_EOF = -1;
/** Have we been created? */
protected static boolean created;
@ -311,8 +311,8 @@ public class IL {
public static native boolean ilApplyProfile(String InProfile, String OutProfile);
public static native void ilBindImage(int image);
public static native boolean ilBlit(int Source, int DestX, int DestY,
int DestZ, int SrcX, int SrcY, int SrcZ,
int Width, int Height, int Depth);
int DestZ, int SrcX, int SrcY, int SrcZ,
int Width, int Height, int Depth);
public static native void ilClearColour(float Red, float Green, float Blue, float Alpha);
public static native boolean ilClearImage();
public static native int ilCloneCurImage();
@ -321,15 +321,15 @@ public class IL {
public static native boolean ilConvertPal(int DestFormat);
public static native boolean ilCopyImage(int Src);
public static int ilCopyPixels( int XOff, int YOff, int ZOff,
int Width, int Height, int Depth,
int Format, int Type, ByteBuffer Data) {
int Width, int Height, int Depth,
int Format, int Type, ByteBuffer Data) {
BufferChecks.checkDirect(Data);
return nilCopyPixels(XOff, YOff, ZOff, Width, Height, Depth, Format, Type, Data, Data.position());
}
private static native int nilCopyPixels(int XOff, int YOff, int ZOff, int Width,
int Height, int Depth, int Format,
int Type, ByteBuffer Data, int data_offset);
int Height, int Depth, int Format,
int Type, ByteBuffer Data, int data_offset);
public static native int ilCreateSubImage(int Type, int Num);
public static native boolean ilDefaultImage();
@ -352,14 +352,14 @@ public class IL {
public static native void ilModAlpha(int AlphaValue);
public static native void ilSetAlpha(int AlphaValue);
public static native boolean ilGetBoolean(int Mode);
public static void ilGetBooleanv(int mode, ByteBuffer param) {
nilGetBooleanv(mode, param, param.position());
}
private static native void nilGetBooleanv(int mode, ByteBuffer param, int position);
public static void ilGetIntegerv(int mode, IntBuffer param) {
nilGetIntegerv(mode, param, param.position());
}
private static native void nilGetIntegerv(int mode, IntBuffer param, int position);
public static void ilGetBooleanv(int mode, ByteBuffer param) {
nilGetBooleanv(mode, param, param.position());
}
private static native void nilGetBooleanv(int mode, ByteBuffer param, int position);
public static void ilGetIntegerv(int mode, IntBuffer param) {
nilGetIntegerv(mode, param, param.position());
}
private static native void nilGetIntegerv(int mode, IntBuffer param, int position);
public static native ByteBuffer ilGetData();
public static native int ilGetError();
@ -416,24 +416,24 @@ public class IL {
public static native boolean ilSetDuration(int Duration);
public static native void ilSetInteger(int Mode, int Param);
public static void ilSetPixels( int XOff, int YOff, int ZOff, int Width,
int Height, int Depth, int Format, int Type, ByteBuffer Data) {
int Height, int Depth, int Format, int Type, ByteBuffer Data) {
BufferChecks.checkDirect(Data);
nilSetPixels(XOff, YOff, ZOff, Width, Height, Depth, Format, Type, Data, Data.position());
}
private static native void nilSetPixels(int XOff, int YOff, int ZOff, int Width,
int Height, int Depth, int Format,
int Type, ByteBuffer Data, int data_offset);
int Height, int Depth, int Format,
int Type, ByteBuffer Data, int data_offset);
public static native void ilSetString(int Mode, String string);
public static native void ilShutDown();
public static boolean ilTexImage( int Width, int Height, int Depth, byte Bpp,
int Format, int Type, ByteBuffer Data) {
int Format, int Type, ByteBuffer Data) {
BufferChecks.checkDirect(Data);
return nilTexImage(Width, Height, Depth, Bpp, Format, Type, Data, Data.position());
}
private static native boolean nilTexImage(int Width, int Height, int Depth, byte Bpp,
int Format, int Type, ByteBuffer Data, int data_offset);
int Format, int Type, ByteBuffer Data, int data_offset);
public static native boolean ilTypeFunc(int Mode);
public static native boolean ilLoadData(String FileName, int Width, int Height, int Depth, byte Bpp);
@ -446,7 +446,7 @@ public class IL {
int Depth, byte Bpp);
public static native boolean ilSaveData(String FileName);
/**
* Loads an image from the specified url
*
@ -524,12 +524,12 @@ public class IL {
byte[] buffer = new byte[4096];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedInputStream buf = new BufferedInputStream(stream);
try {
while((lastRead = buf.read(buffer, 0, buffer.length)) != -1) {
baos.write(buffer, 0, lastRead);
}
buffer = baos.toByteArray();
ByteBuffer lump = ByteBuffer.allocateDirect(buffer.length);
lump.put(buffer);
@ -542,12 +542,12 @@ public class IL {
return result;
}
// public static native int ilGetDXTCData(ILvoid *Buffer, int BufferSize, int DXTCFormat);
// public static native boolean ilIsValidF(int Type, ILHANDLE File);
// public static native boolean ilLoadF(int Type, ILHANDLE File);
// public static native boolean ilLoadDataF(ILHANDLE File, int Width, int Height, int Depth, ILubyte Bpp);
// public static native int ilSaveF(int Type, ILHANDLE File);
// public static native boolean ilLoadDataF(ILHANDLE File, int Width, int Height, int Depth, ILubyte Bpp);
// public static native int ilSaveF(int Type, ILHANDLE File);
// public static native void ilRegisterFormat(int Format);
// public static native boolean ilRegisterLoad(String Ext, IL_LOADPROC Load);
// public static native boolean ilRegisterMipNum(int Num);
@ -587,9 +587,9 @@ public class IL {
}
String[] illPaths = LWJGLUtil.getLibraryPaths(new String[]{
"DevIL", "DevIL.dll",
"IL", "libIL.so",
"IL", "IL"}, IL.class.getClassLoader());
"DevIL", "DevIL.dll",
"IL", "libIL.so",
"IL", "IL"}, IL.class.getClassLoader());
nCreate(illPaths);
created = true;
@ -597,14 +597,14 @@ public class IL {
IL.initNativeStubs();
IL.ilInit();
// We need to initialize everything in one fell swoop on mac
if(System.getProperty("os.name").startsWith("Mac")) {
ILU.initNativeStubs();
ILU.setCreated(true);
// We need to initialize everything in one fell swoop on mac
if(LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) {
ILU.initNativeStubs();
ILU.setCreated(true);
ILUT.initNativeStubs();
ILUT.setCreated(true);
}
ILUT.initNativeStubs();
ILUT.setCreated(true);
}
created = true;
} catch (LWJGLException e) {
@ -619,16 +619,16 @@ public class IL {
public static void destroy() {
resetNativeStubs(IL.class);
// We need to destroy everything on mac in one go
if(System.getProperty("os.name").startsWith("Mac")) {
ILU.resetNativeStubs(ILU.class);
ILU.nDestroy();
ILU.setCreated(false);
// We need to destroy everything on mac in one go
if(LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) {
ILU.resetNativeStubs(ILU.class);
ILU.nDestroy();
ILU.setCreated(false);
ILUT.resetNativeStubs(ILUT.class);
ILUT.nDestroy();
ILUT.setCreated(false);
}
ILUT.resetNativeStubs(ILUT.class);
ILUT.nDestroy();
ILUT.setCreated(false);
}
if (created) {
nDestroy();

View File

@ -55,182 +55,182 @@ import org.lwjgl.LWJGLUtil;
* @version $Revision$
*/
public class ILU {
public static final int ILU_FILTER = 0x2600;
public static final int ILU_NEAREST = 0x2601;
public static final int ILU_LINEAR = 0x2602;
public static final int ILU_BILINEAR = 0x2603;
public static final int ILU_SCALE_BOX = 0x2604;
public static final int ILU_SCALE_TRIANGLE = 0x2605;
public static final int ILU_SCALE_BELL = 0x2606;
public static final int ILU_SCALE_BSPLINE = 0x2607;
public static final int ILU_SCALE_LANCZOS3 = 0x2608;
public static final int ILU_SCALE_MITCHELL = 0x2609;
// Error types
public static final int ILU_INVALID_ENUM = 0x0501;
public static final int ILU_OUT_OF_MEMORY = 0x0502;
public static final int ILU_INTERNAL_ERROR = 0x0504;
public static final int ILU_INVALID_VALUE = 0x0505;
public static final int ILU_ILLEGAL_OPERATION = 0x0506;
public static final int ILU_INVALID_PARAM = 0x0509;
// Values
public static final int ILU_PLACEMENT = 0x0700;
public static final int ILU_LOWER_LEFT = 0x0701;
public static final int ILU_LOWER_RIGHT = 0x0702;
public static final int ILU_UPPER_LEFT = 0x0703;
public static final int ILU_UPPER_RIGHT = 0x0704;
public static final int ILU_CENTER = 0x0705;
public static final int ILU_CONVOLUTION_MATRIX = 0x0710;
public static final int ILU_VERSION_NUM = IL.IL_VERSION_NUM;
public static final int ILU_VENDOR = IL.IL_VENDOR;
public static final int ILU_FILTER = 0x2600;
public static final int ILU_NEAREST = 0x2601;
public static final int ILU_LINEAR = 0x2602;
public static final int ILU_BILINEAR = 0x2603;
public static final int ILU_SCALE_BOX = 0x2604;
public static final int ILU_SCALE_TRIANGLE = 0x2605;
public static final int ILU_SCALE_BELL = 0x2606;
public static final int ILU_SCALE_BSPLINE = 0x2607;
public static final int ILU_SCALE_LANCZOS3 = 0x2608;
public static final int ILU_SCALE_MITCHELL = 0x2609;
/** Have we been created? */
protected static boolean created;
// Error types
public static final int ILU_INVALID_ENUM = 0x0501;
public static final int ILU_OUT_OF_MEMORY = 0x0502;
public static final int ILU_INTERNAL_ERROR = 0x0504;
public static final int ILU_INVALID_VALUE = 0x0505;
public static final int ILU_ILLEGAL_OPERATION = 0x0506;
public static final int ILU_INVALID_PARAM = 0x0509;
/**
* @return true if ILU has been created
*/
public static boolean isCreated() {
return created;
}
// Values
public static final int ILU_PLACEMENT = 0x0700;
public static final int ILU_LOWER_LEFT = 0x0701;
public static final int ILU_LOWER_RIGHT = 0x0702;
public static final int ILU_UPPER_LEFT = 0x0703;
public static final int ILU_UPPER_RIGHT = 0x0704;
public static final int ILU_CENTER = 0x0705;
public static final int ILU_CONVOLUTION_MATRIX = 0x0710;
public static final int ILU_VERSION_NUM = IL.IL_VERSION_NUM;
public static final int ILU_VENDOR = IL.IL_VENDOR;
public static native boolean iluAlienify();
public static native boolean iluBlurAvg(int iter);
public static native boolean iluBlurGaussian(int iter);
public static native boolean iluBuildMipmaps();
public static native int iluColoursUsed();
public static native boolean iluCompareImage(int comp);
public static native boolean iluContrast(float contrast);
public static native boolean iluCrop(int xOff, int yOff, int zOff, int width, int height, int depth);
public static native void iluDeleteImage(int id);
public static native boolean iluEdgeDetectE();
public static native boolean iluEdgeDetectP();
public static native boolean iluEdgeDetectS();
public static native boolean iluEmboss();
public static native boolean iluEnlargeCanvas(int width, int height, int depth);
public static native boolean iluEnlargeImage(float xDim, float yDim, float zDim);
public static native boolean iluEqualize();
public static native String iluErrorString(int error);
public static native boolean iluFlipImage();
public static native boolean iluGammaCorrect(float gamma);
public static native int iluGenImage();
public static native void iluGetImageInfo(ILinfo info);
public static native int iluGetInteger(int mode);
public static void iluGetIntegerv(int mode, IntBuffer param) {
BufferChecks.checkDirect(param);
niluGetIntegerv(mode, param, param.position());
}
private static native void niluGetIntegerv(int mode, IntBuffer param, int param_offset);
public static native String iluGetString(int stringName);
public static native void iluImageParameter(int pName, int param);
private static native void iluInit();
public static native boolean iluInvertAlpha();
public static native int iluLoadImage(String fileName);
public static native boolean iluMirror();
public static native boolean iluNegative();
public static native boolean iluNoisify(float tolerance);
public static native boolean iluPixelize(int pixSize);
public static native boolean iluReplaceColour(byte red, byte green, byte blue, float tolerance);
public static native boolean iluRotate(float angle);
public static native boolean iluSaturate1f(float saturation);
public static native boolean iluSaturate4f(float r, float g, float b, float saturation);
public static native boolean iluScale(int width, int height, int depth);
public static native boolean iluScaleColours(float r, float g, float b);
public static native boolean iluSharpen(float factor, int iter);
public static native boolean iluSwapColours();
public static native boolean iluWave(float angle);
/** Have we been created? */
protected static boolean created;
// public static native void iluRegionfv(ILpointf points[], int n);
// public static native void iluRegioniv(ILpointi points[], int n);
// public static native boolean iluRotate3D(float x, float y, float z, float Angle);
/* DevIL lib allows both spellings of colour. We support that too */
// ========================================================================
public static void iluColorsUsed() {
iluColoursUsed();
}
public static void iluSwapColors() {
iluSwapColours();
}
public static void iluReplaceColor(byte red, byte green, byte blue, float tolerance) {
iluReplaceColour(red, green, blue, tolerance);
}
public static void iluScaleColors(float r, float g, float b) {
iluScaleColours(r, g, b);
}
// ------------------------------------------------------------------------
/**
* Creates a new instance of ILU. Cannot be created unless IL has been created.
*/
public static void create() throws LWJGLException {
if(!IL.isCreated()) {
throw new LWJGLException("Cannot create ILU without having created IL instance");
}
/**
* @return true if ILU has been created
*/
public static boolean isCreated() {
return created;
}
// We need to do nothing when running on mac, since all is loaded in IL
if(System.getProperty("os.name").startsWith("Mac")) {
return;
}
public static native boolean iluAlienify();
public static native boolean iluBlurAvg(int iter);
public static native boolean iluBlurGaussian(int iter);
public static native boolean iluBuildMipmaps();
public static native int iluColoursUsed();
public static native boolean iluCompareImage(int comp);
public static native boolean iluContrast(float contrast);
public static native boolean iluCrop(int xOff, int yOff, int zOff, int width, int height, int depth);
public static native void iluDeleteImage(int id);
public static native boolean iluEdgeDetectE();
public static native boolean iluEdgeDetectP();
public static native boolean iluEdgeDetectS();
public static native boolean iluEmboss();
public static native boolean iluEnlargeCanvas(int width, int height, int depth);
public static native boolean iluEnlargeImage(float xDim, float yDim, float zDim);
public static native boolean iluEqualize();
public static native String iluErrorString(int error);
public static native boolean iluFlipImage();
public static native boolean iluGammaCorrect(float gamma);
public static native int iluGenImage();
public static native void iluGetImageInfo(ILinfo info);
public static native int iluGetInteger(int mode);
public static void iluGetIntegerv(int mode, IntBuffer param) {
BufferChecks.checkDirect(param);
niluGetIntegerv(mode, param, param.position());
}
private static native void niluGetIntegerv(int mode, IntBuffer param, int param_offset);
public static native String iluGetString(int stringName);
public static native void iluImageParameter(int pName, int param);
private static native void iluInit();
public static native boolean iluInvertAlpha();
public static native int iluLoadImage(String fileName);
public static native boolean iluMirror();
public static native boolean iluNegative();
public static native boolean iluNoisify(float tolerance);
public static native boolean iluPixelize(int pixSize);
public static native boolean iluReplaceColour(byte red, byte green, byte blue, float tolerance);
public static native boolean iluRotate(float angle);
public static native boolean iluSaturate1f(float saturation);
public static native boolean iluSaturate4f(float r, float g, float b, float saturation);
public static native boolean iluScale(int width, int height, int depth);
public static native boolean iluScaleColours(float r, float g, float b);
public static native boolean iluSharpen(float factor, int iter);
public static native boolean iluSwapColours();
public static native boolean iluWave(float angle);
String[] iluPaths = LWJGLUtil.getLibraryPaths(new String[]{
"ILU", "ILU.dll",
"ILU", "libILU.so",
"ILU", "ILU"}, ILU.class.getClassLoader());
nCreate(iluPaths);
created = true;
// public static native void iluRegionfv(ILpointf points[], int n);
// public static native void iluRegioniv(ILpointi points[], int n);
// public static native boolean iluRotate3D(float x, float y, float z, float Angle);
try {
ILU.initNativeStubs();
ILU.iluInit();
created = true;
} catch (LWJGLException e) {
destroy();
throw e;
}
}
/* DevIL lib allows both spellings of colour. We support that too */
// ========================================================================
public static void iluColorsUsed() {
iluColoursUsed();
}
public static void iluSwapColors() {
iluSwapColours();
}
public static void iluReplaceColor(byte red, byte green, byte blue, float tolerance) {
iluReplaceColour(red, green, blue, tolerance);
}
public static void iluScaleColors(float r, float g, float b) {
iluScaleColours(r, g, b);
}
// ------------------------------------------------------------------------
static native void initNativeStubs() throws LWJGLException;
static native void resetNativeStubs(Class clazz);
/**
* Exit cleanly by calling destroy.
*/
public static void destroy() {
// We need to do nothing when running on mac, since all is destroyed in IL
if(System.getProperty("os.name").startsWith("Mac")) {
return;
}
resetNativeStubs(ILU.class);
if (created) {
nDestroy();
}
created = false;
/**
* Creates a new instance of ILU. Cannot be created unless IL has been created.
*/
public static void create() throws LWJGLException {
if(!IL.isCreated()) {
throw new LWJGLException("Cannot create ILU without having created IL instance");
}
/**
* Native method to create ILU instance
*
* @param iluPaths Array of strings containing paths to search for ILU library
*/
protected static native void nCreate(String[] iluPaths) throws LWJGLException;
// We need to do nothing when running on mac, since all is loaded in IL
if(LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) {
return;
}
/**
* Native method the destroy the ILU
*/
static native void nDestroy();
String[] iluPaths = LWJGLUtil.getLibraryPaths(new String[]{
"ILU", "ILU.dll",
"ILU", "libILU.so",
"ILU", "ILU"}, ILU.class.getClassLoader());
nCreate(iluPaths);
created = true;
/**
* Forcefully set created. Used internally by mac platform since
* it loads ilu/ilut in IL and needs to mark them as created
* @param created value to set created to
*/
static void setCreated(boolean created) {
ILU.created = created;
}
try {
ILU.initNativeStubs();
ILU.iluInit();
created = true;
} catch (LWJGLException e) {
destroy();
throw e;
}
}
static native void initNativeStubs() throws LWJGLException;
static native void resetNativeStubs(Class clazz);
/**
* Exit cleanly by calling destroy.
*/
public static void destroy() {
// We need to do nothing when running on mac, since all is destroyed in IL
if(LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) {
return;
}
resetNativeStubs(ILU.class);
if (created) {
nDestroy();
}
created = false;
}
/**
* Native method to create ILU instance
*
* @param iluPaths Array of strings containing paths to search for ILU library
*/
protected static native void nCreate(String[] iluPaths) throws LWJGLException;
/**
* Native method the destroy the ILU
*/
static native void nDestroy();
/**
* Forcefully set created. Used internally by mac platform since
* it loads ilu/ilut in IL and needs to mark them as created
* @param created value to set created to
*/
static void setCreated(boolean created) {
ILU.created = created;
}
}

View File

@ -55,146 +55,146 @@ import org.lwjgl.LWJGLUtil;
*/
public class ILUT {
// Attribute Bits
public static final int ILUT_OPENGL_BIT = 0x00000001;
public static final int ILUT_ALL_ATTRIB_BITS = 0x000FFFFF;
// Attribute Bits
public static final int ILUT_OPENGL_BIT = 0x00000001;
public static final int ILUT_ALL_ATTRIB_BITS = 0x000FFFFF;
// Error Types
public static final int ILUT_INVALID_ENUM = 0x0501;
public static final int ILUT_OUT_OF_MEMORY = 0x0502;
public static final int ILUT_INVALID_VALUE = 0x0505;
public static final int ILUT_ILLEGAL_OPERATION = 0x0506;
public static final int ILUT_INVALID_PARAM = 0x0509;
public static final int ILUT_COULD_NOT_OPEN_FILE = 0x050A;
public static final int ILUT_STACK_OVERFLOW = 0x050E;
public static final int ILUT_STACK_UNDERFLOW = 0x050F;
public static final int ILUT_BAD_DIMENSIONS = 0x0511;
public static final int ILUT_NOT_SUPPORTED = 0x0550;
// Error Types
public static final int ILUT_INVALID_ENUM = 0x0501;
public static final int ILUT_OUT_OF_MEMORY = 0x0502;
public static final int ILUT_INVALID_VALUE = 0x0505;
public static final int ILUT_ILLEGAL_OPERATION = 0x0506;
public static final int ILUT_INVALID_PARAM = 0x0509;
public static final int ILUT_COULD_NOT_OPEN_FILE = 0x050A;
public static final int ILUT_STACK_OVERFLOW = 0x050E;
public static final int ILUT_STACK_UNDERFLOW = 0x050F;
public static final int ILUT_BAD_DIMENSIONS = 0x0511;
public static final int ILUT_NOT_SUPPORTED = 0x0550;
// State Definitions
public static final int ILUT_PALETTE_MODE = 0x0600;
public static final int ILUT_OPENGL_CONV = 0x0610;
public static final int ILUT_MAXTEX_WIDTH = 0x0630;
public static final int ILUT_MAXTEX_HEIGHT = 0x0631;
public static final int ILUT_MAXTEX_DEPTH = 0x0632;
public static final int ILUT_GL_USE_S3TC = 0x0634;
public static final int ILUT_GL_GEN_S3TC = 0x0635;
public static final int ILUT_GL_AUTODETECT_TEXTURE_TARGET = 0x0807;
// State Definitions
public static final int ILUT_PALETTE_MODE = 0x0600;
public static final int ILUT_OPENGL_CONV = 0x0610;
public static final int ILUT_MAXTEX_WIDTH = 0x0630;
public static final int ILUT_MAXTEX_HEIGHT = 0x0631;
public static final int ILUT_MAXTEX_DEPTH = 0x0632;
public static final int ILUT_GL_USE_S3TC = 0x0634;
public static final int ILUT_GL_GEN_S3TC = 0x0635;
public static final int ILUT_GL_AUTODETECT_TEXTURE_TARGET = 0x0807;
// The different rendering api's...more to be added later?
public static final int ILUT_OPENGL = 0;
public static final int ILUT_VENDOR = IL.IL_VENDOR;
public static final int ILUT_VERSION_NUM = IL.IL_VERSION_NUM;
/** Have we been created? */
protected static boolean created;
public static native boolean ilutRenderer(int renderer);
public static native boolean ilutDisable(int mode);
public static native boolean ilutEnable(int mode);
public static native boolean ilutGetBoolean(int mode);
public static native int ilutGetInteger(int mode);
public static native void ilutGetBooleanv(int mode, ByteBuffer param);
public static native void ilutGetIntegerv(int mode, IntBuffer Param);
public static native String ilutGetString(int stringName);
private static native void ilutInit();
public static native boolean ilutIsDisabled(int mode);
public static native boolean ilutIsEnabled(int mode);
public static native void ilutPopAttrib();
public static native void ilutPushAttrib(int bits);
public static native void ilutSetInteger(int Mode, int param);
// The different rendering api's...more to be added later?
public static final int ILUT_OPENGL = 0;
public static final int ILUT_VENDOR = IL.IL_VENDOR;
public static final int ILUT_VERSION_NUM = IL.IL_VERSION_NUM;
/** Have we been created? */
protected static boolean created;
public static native boolean ilutRenderer(int renderer);
public static native boolean ilutDisable(int mode);
public static native boolean ilutEnable(int mode);
public static native boolean ilutGetBoolean(int mode);
public static native int ilutGetInteger(int mode);
public static native void ilutGetBooleanv(int mode, ByteBuffer param);
public static native void ilutGetIntegerv(int mode, IntBuffer Param);
public static native String ilutGetString(int stringName);
private static native void ilutInit();
public static native boolean ilutIsDisabled(int mode);
public static native boolean ilutIsEnabled(int mode);
public static native void ilutPopAttrib();
public static native void ilutPushAttrib(int bits);
public static native void ilutSetInteger(int Mode, int param);
// ImageLib Utility Toolkit's OpenGL Functions
public static native int ilutGLBindTexImage();
public static native int ilutGLBindMipmaps();
public static native boolean ilutGLBuildMipmaps();
public static native int ilutGLLoadImage(String fileName);
public static native boolean ilutGLScreen();
public static native boolean ilutGLScreenie();
public static native boolean ilutGLSaveImage(String fileName, int texID);
public static native boolean ilutGLSetTex(int texID);
public static native boolean ilutGLTexImage(int level);
/**
* @return true if ILUT has been created
*/
public static boolean isCreated() {
return created;
}
/**
* Creates a new instance of ILUT. Cannot be created unless IL has been created.
*/
public static void create() throws LWJGLException {
if(!IL.isCreated()) {
throw new LWJGLException("Cannot create ILUT without having created IL instance");
}
// ImageLib Utility Toolkit's OpenGL Functions
public static native int ilutGLBindTexImage();
public static native int ilutGLBindMipmaps();
public static native boolean ilutGLBuildMipmaps();
public static native int ilutGLLoadImage(String fileName);
public static native boolean ilutGLScreen();
public static native boolean ilutGLScreenie();
public static native boolean ilutGLSaveImage(String fileName, int texID);
public static native boolean ilutGLSetTex(int texID);
public static native boolean ilutGLTexImage(int level);
// We need to do nothing when running on mac, since all is loaded in IL
if(System.getProperty("os.name").startsWith("Mac")) {
return;
}
/**
* @return true if ILUT has been created
*/
public static boolean isCreated() {
return created;
}
String[] ilutPaths = LWJGLUtil.getLibraryPaths(new String[]{
"ILUT", "ILUT.dll",
"ILUT", "libILUT.so",
"ILUT", "IL"}, ILU.class.getClassLoader());
nCreate(ilutPaths);
created = true;
try {
ILUT.initNativeStubs();
ILUT.ilutInit();
created = true;
} catch (LWJGLException e) {
destroy();
throw e;
}
}
static native void initNativeStubs() throws LWJGLException;
static native void resetNativeStubs(Class clazz);
/**
* Exit cleanly by calling destroy.
*/
public static void destroy() {
// We need to do nothing when running on mac, since all is destroyed in IL
if(System.getProperty("os.name").startsWith("Mac")) {
return;
}
resetNativeStubs(ILUT.class);
if (created) {
nDestroy();
}
created = false;
/**
* Creates a new instance of ILUT. Cannot be created unless IL has been created.
*/
public static void create() throws LWJGLException {
if(!IL.isCreated()) {
throw new LWJGLException("Cannot create ILUT without having created IL instance");
}
/**
* Native method to create ILUT instance
*
* @param ilutPaths Array of strings containing paths to search for ILUT library
*/
protected static native void nCreate(String[] ilutPaths) throws LWJGLException;
// We need to do nothing when running on mac, since all is loaded in IL
if(LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) {
return;
}
/**
* Native method the destroy the ILUT
*/
protected static native void nDestroy();
String[] ilutPaths = LWJGLUtil.getLibraryPaths(new String[]{
"ILUT", "ILUT.dll",
"ILUT", "libILUT.so",
"ILUT", "IL"}, ILU.class.getClassLoader());
nCreate(ilutPaths);
created = true;
/**
* Forcefully set created. Used internally by mac platform since
* it loads ilu/ilut in IL and needs to mark them as created
* @param created value to set created to
*/
static void setCreated(boolean created) {
ILUT.created = created;
}
try {
ILUT.initNativeStubs();
ILUT.ilutInit();
created = true;
} catch (LWJGLException e) {
destroy();
throw e;
}
}
static native void initNativeStubs() throws LWJGLException;
static native void resetNativeStubs(Class clazz);
/**
* Exit cleanly by calling destroy.
*/
public static void destroy() {
// We need to do nothing when running on mac, since all is destroyed in IL
if(LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) {
return;
}
resetNativeStubs(ILUT.class);
if (created) {
nDestroy();
}
created = false;
}
/**
* Native method to create ILUT instance
*
* @param ilutPaths Array of strings containing paths to search for ILUT library
*/
protected static native void nCreate(String[] ilutPaths) throws LWJGLException;
/**
* Native method the destroy the ILUT
*/
protected static native void nDestroy();
/**
* Forcefully set created. Used internally by mac platform since
* it loads ilu/ilut in IL and needs to mark them as created
* @param created value to set created to
*/
static void setCreated(boolean created) {
ILUT.created = created;
}
}

View File

@ -47,360 +47,364 @@ import org.lwjgl.LWJGLUtil;
* @version $Revision$
*/
public class FMOD {
/** Array of hashmaps for callbacks */
private static HashMap[] callbacks = new HashMap[17];
/** FMOD System level clear dsp unit */
static FSoundDSPUnit fmodClearUnit;
/** FMOD System level clip and copy dsp unit */
static FSoundDSPUnit fmodClipAndCopyUnit;
/** FMOD System level music dsp unit */
static FSoundDSPUnit fmodMusicUnit;
/** FMOD System level sound effects dsp unit */
static FSoundDSPUnit fmodSFXUnit;
/** FMOD System level FFT dsp unit */
static FSoundDSPUnit fmodFFTUnit;
/** FMOD System level FFT buffer */
static FloatBuffer fmodFFTBuffer;
/** Type defining the music callback entries in callback hashmap array */
public static final int FMUSIC_INSTCALLBACK = 0;
/** Type defining the music callback entries in callback hashmap array */
public static final int FMUSIC_ORDERCALLBACK = 1;
/** Type defining the music callback entries in callback hashmap array */
public static final int FMUSIC_ROWCALLBACK = 2;
private static HashMap[] callbacks = new HashMap[17];
/** Type defining the music callback entries in callback hashmap array */
public static final int FMUSIC_ZXXCALLBACK = 3;
/** Type defining the dsp callback entries in callback hashmap array */
public static final int FSOUND_DSPCALLBACK = 4;
/** Type defining the stream callback entries in callback hashmap array */
public static final int FSOUND_STREAMCALLBACK = 5;
/** Type defining the alloc callback entries in callback hashmap array */
public static final int FSOUND_ALLOCCALLBACK = 6;
/** Type defining the realloc callback entries in callback hashmap array */
public static final int FSOUND_REALLOCCALLBACK = 7;
/** Type defining the free callback entries in callback hashmap array */
public static final int FSOUND_FREECALLBACK = 8;
/** Type defining the open callback entries in callback hashmap array */
public static final int FSOUND_OPENCALLBACK = 9;
/** Type defining the close callback entries in callback hashmap array */
public static final int FSOUND_CLOSECALLBACK = 10;
/** Type defining the metadata callback entries in callback hashmap array */
public static final int FSOUND_METADATACALLBACK = 11;
/** Type defining the read callback entries in callback hashmap array */
public static final int FSOUND_READCALLBACK = 12;
/** Type defining the seek callback entries in callback hashmap array */
public static final int FSOUND_SEEKCALLBACK = 13;
/** Type defining the tell callback entries in callback hashmap array */
public static final int FSOUND_TELLCALLBACK = 14;
/** Type defining the "end" callback entries in callback hashmap array */
public static final int FSOUND_ENDCALLBACK = 15;
/** Type defining the "sync" callback entries in callback hashmap array */
public static final int FSOUND_SYNCCALLBACK = 16;
/** FMOD System level clear dsp unit */
static FSoundDSPUnit fmodClearUnit;
/** Have we been created? */
protected static boolean created;
/** FMOD System level clip and copy dsp unit */
static FSoundDSPUnit fmodClipAndCopyUnit;
/** No errors */
public static final int FMOD_ERR_NONE = 0;
/** FMOD System level music dsp unit */
static FSoundDSPUnit fmodMusicUnit;
/** Cannot call this command after FSOUND_Init. Call FSOUND_Close first. */
public static final int FMOD_ERR_BUSY = 1;
/** FMOD System level sound effects dsp unit */
static FSoundDSPUnit fmodSFXUnit;
/** This command failed because FSOUND_Init was not called */
public static final int FMOD_ERR_UNINITIALIZED = 2;
/** FMOD System level FFT dsp unit */
static FSoundDSPUnit fmodFFTUnit;
/** Error initializing output device. */
public static final int FMOD_ERR_INIT = 3;
/** FMOD System level FFT buffer */
static FloatBuffer fmodFFTBuffer;
/** Error initializing output device, but more specifically, the output device is already in use and cannot be reused. */
public static final int FMOD_ERR_ALLOCATED = 4;
/** Type defining the music callback entries in callback hashmap array */
public static final int FMUSIC_INSTCALLBACK = 0;
/** Playing the sound failed. */
public static final int FMOD_ERR_PLAY = 5;
/** Type defining the music callback entries in callback hashmap array */
public static final int FMUSIC_ORDERCALLBACK = 1;
/** Soundcard does not support the features needed for this soundsystem (16bit stereo output) */
public static final int FMOD_ERR_OUTPUT_FORMAT = 6;
/** Type defining the music callback entries in callback hashmap array */
public static final int FMUSIC_ROWCALLBACK = 2;
/** Error setting cooperative level for hardware. */
public static final int FMOD_ERR_COOPERATIVELEVEL = 7;
/** Type defining the music callback entries in callback hashmap array */
public static final int FMUSIC_ZXXCALLBACK = 3;
/** Error creating hardware sound buffer. */
public static final int FMOD_ERR_CREATEBUFFER = 8;
/** File not found */
public static final int FMOD_ERR_FILE_NOTFOUND = 9;
/** Type defining the dsp callback entries in callback hashmap array */
public static final int FSOUND_DSPCALLBACK = 4;
/** Unknown file format */
public static final int FMOD_ERR_FILE_FORMAT = 10;
/** Type defining the stream callback entries in callback hashmap array */
public static final int FSOUND_STREAMCALLBACK = 5;
/** Error loading file */
public static final int FMOD_ERR_FILE_BAD = 11;
/** Type defining the alloc callback entries in callback hashmap array */
public static final int FSOUND_ALLOCCALLBACK = 6;
/** Not enough memory */
public static final int FMOD_ERR_MEMORY = 12;
/** Type defining the realloc callback entries in callback hashmap array */
public static final int FSOUND_REALLOCCALLBACK = 7;
/** The version number of this file format is not supported */
public static final int FMOD_ERR_VERSION = 13;
/** Type defining the free callback entries in callback hashmap array */
public static final int FSOUND_FREECALLBACK = 8;
/** An invalid parameter was passed to this function */
public static final int FMOD_ERR_INVALID_PARAM = 14;
/** Type defining the open callback entries in callback hashmap array */
public static final int FSOUND_OPENCALLBACK = 9;
/** Tried to use an EAX command on a non EAX enabled channel or output. */
public static final int FMOD_ERR_NO_EAX = 15;
/** Type defining the close callback entries in callback hashmap array */
public static final int FSOUND_CLOSECALLBACK = 10;
/** Failed to allocate a new channel */
public static final int FMOD_ERR_CHANNEL_ALLOC = 17;
/** Type defining the metadata callback entries in callback hashmap array */
public static final int FSOUND_METADATACALLBACK = 11;
/** Recording is not supported on this machine */
public static final int FMOD_ERR_RECORD = 18;
/** Type defining the read callback entries in callback hashmap array */
public static final int FSOUND_READCALLBACK = 12;
/** Required Mediaplayer codec is not installed */
public static final int FMOD_ERR_MEDIAPLAYER = 19;
/** Type defining the seek callback entries in callback hashmap array */
public static final int FSOUND_SEEKCALLBACK = 13;
/** An error occured trying to open the specified CD device */
public static final int FMOD_ERR_CDDEVICE = 20;
/** Whether we have been initialized */
private static boolean initialized;
/** The native JNI library name */
private static String JNI_LIBRARY_NAME = "lwjgl-fmod3";
/** The native library name on win32 */
private static String FMOD_WIN32_LIBRARY_NAME = "fmod";
/** The native library name on win32 */
private static String FMOD_LINUX_LIBRARY_NAME = "fmod";
/** Type defining the tell callback entries in callback hashmap array */
public static final int FSOUND_TELLCALLBACK = 14;
/** The native library name on win32 */
private static String FMOD_OSX_LIBRARY_NAME = "fmod";
/** Type defining the "end" callback entries in callback hashmap array */
public static final int FSOUND_ENDCALLBACK = 15;
/** Version of FMOD */
public static final String VERSION = "0.96";
static {
initialize();
}
/**
* Initializes the FMOD binding
*/
static void initialize() {
if (initialized) {
return;
}
initialized = true;
System.loadLibrary(JNI_LIBRARY_NAME);
// check for mismatch
String nativeVersion = getNativeLibraryVersion();
if (!nativeVersion.equals(VERSION)) {
throw new LinkageError(
"Version mismatch: jar version is '" + VERSION +
/** Type defining the "sync" callback entries in callback hashmap array */
public static final int FSOUND_SYNCCALLBACK = 16;
/** Have we been created? */
protected static boolean created;
/** No errors */
public static final int FMOD_ERR_NONE = 0;
/** Cannot call this command after FSOUND_Init. Call FSOUND_Close first. */
public static final int FMOD_ERR_BUSY = 1;
/** This command failed because FSOUND_Init was not called */
public static final int FMOD_ERR_UNINITIALIZED = 2;
/** Error initializing output device. */
public static final int FMOD_ERR_INIT = 3;
/** Error initializing output device, but more specifically, the output device is already in use and cannot be reused. */
public static final int FMOD_ERR_ALLOCATED = 4;
/** Playing the sound failed. */
public static final int FMOD_ERR_PLAY = 5;
/** Soundcard does not support the features needed for this soundsystem (16bit stereo output) */
public static final int FMOD_ERR_OUTPUT_FORMAT = 6;
/** Error setting cooperative level for hardware. */
public static final int FMOD_ERR_COOPERATIVELEVEL = 7;
/** Error creating hardware sound buffer. */
public static final int FMOD_ERR_CREATEBUFFER = 8;
/** File not found */
public static final int FMOD_ERR_FILE_NOTFOUND = 9;
/** Unknown file format */
public static final int FMOD_ERR_FILE_FORMAT = 10;
/** Error loading file */
public static final int FMOD_ERR_FILE_BAD = 11;
/** Not enough memory */
public static final int FMOD_ERR_MEMORY = 12;
/** The version number of this file format is not supported */
public static final int FMOD_ERR_VERSION = 13;
/** An invalid parameter was passed to this function */
public static final int FMOD_ERR_INVALID_PARAM = 14;
/** Tried to use an EAX command on a non EAX enabled channel or output. */
public static final int FMOD_ERR_NO_EAX = 15;
/** Failed to allocate a new channel */
public static final int FMOD_ERR_CHANNEL_ALLOC = 17;
/** Recording is not supported on this machine */
public static final int FMOD_ERR_RECORD = 18;
/** Required Mediaplayer codec is not installed */
public static final int FMOD_ERR_MEDIAPLAYER = 19;
/** An error occured trying to open the specified CD device */
public static final int FMOD_ERR_CDDEVICE = 20;
/** Whether we have been initialized */
private static boolean initialized;
/** The native JNI library name */
private static String JNI_LIBRARY_NAME = "lwjgl-fmod3";
/** The native library name on win32 */
private static String FMOD_WIN32_LIBRARY_NAME = "fmod";
/** The native library name on win32 */
private static String FMOD_LINUX_LIBRARY_NAME = "fmod";
/** The native library name on win32 */
private static String FMOD_OSX_LIBRARY_NAME = "fmod";
/** Version of FMOD */
public static final String VERSION = "0.96";
static {
initialize();
}
/**
* Initializes the FMOD binding
*/
static void initialize() {
if (initialized) {
return;
}
initialized = true;
System.loadLibrary(JNI_LIBRARY_NAME);
// check for mismatch
String nativeVersion = getNativeLibraryVersion();
if (!nativeVersion.equals(VERSION)) {
throw new LinkageError(
"Version mismatch: jar version is '" + VERSION +
"', native libary version is '" + nativeVersion + "'");
}
// Initialize callback hashmaps
for(int i=0; i<callbacks.length; i++) {
callbacks[i] = new HashMap();
}
}
/**
* Return the version of the native library
*/
private static native String getNativeLibraryVersion();
/**
* @return true if AL has been created
*/
public static boolean isCreated() {
return created;
}
/**
* Creates an FMOD instance.
*/
public static void create() throws FMODException {
if (created) {
return;
}
// create, passing potential locations for native fmod library
nCreate(constructFMODSearchPaths());
created = true;
}
/**
* Retrieves an array of strings, with potential locations for
* the native fmod library
}
// Initialize callback hashmaps
for(int i=0; i<callbacks.length; i++) {
callbacks[i] = new HashMap();
}
}
/**
* Return the version of the native library
*/
private static native String getNativeLibraryVersion();
/**
* @return true if AL has been created
*/
public static boolean isCreated() {
return created;
}
/**
* Creates an FMOD instance.
*/
public static void create() throws FMODException {
if (created) {
return;
}
// create, passing potential locations for native fmod library
nCreate(constructFMODSearchPaths());
created = true;
}
/**
* Retrieves an array of strings, with potential locations for
* the native fmod library
* @return array of strings, with potential locations for the native fmod library
*/
private static String[] constructFMODSearchPaths() {
// miscellaneous values
String libpath = System.getProperty("java.library.path");
String seperator = System.getProperty("path.separator");
String osName = System.getProperty("os.name");
// miscellaneous values
String libpath = System.getProperty("java.library.path");
String seperator = System.getProperty("path.separator");
// determine os library name
String dllName = FMOD_WIN32_LIBRARY_NAME;
if (osName.startsWith("Mac OS")) {
dllName = FMOD_OSX_LIBRARY_NAME;
} else if (osName.startsWith("Linux")) {
dllName = FMOD_LINUX_LIBRARY_NAME;
}
String jwsPath = getPathFromJWS(dllName);
LWJGLUtil.log("getPathFromJWS: Paths found: " + jwsPath);
if (jwsPath != null) {
libpath += seperator
+ jwsPath.substring(0, jwsPath.lastIndexOf(File.separator));
}
// split, and rebuild library path to path + dll
StringTokenizer st = new StringTokenizer(libpath, seperator);
String[] paths = new String[st.countTokens() + 1];
// determine os library name
String dllName = FMOD_WIN32_LIBRARY_NAME;
switch (LWJGLUtil.getPlatform()) {
case LWJGLUtil.PLATFORM_MACOSX:
dllName = FMOD_OSX_LIBRARY_NAME;
break;
case LWJGLUtil.PLATFORM_LINUX:
dllName = FMOD_LINUX_LIBRARY_NAME;
break;
default:
throw new LinkageError("Unsupported platform");
}
//build paths
for (int i = 0; i < paths.length - 1; i++) {
paths[i] = st.nextToken() + File.separator;
}
for(int i=0 ; i<paths.length; i++) {
LWJGLUtil.log("Will search " + paths[i] + " for " + dllName);
}
String jwsPath = getPathFromJWS(dllName);
LWJGLUtil.log("getPathFromJWS: Paths found: " + jwsPath);
if (jwsPath != null) {
libpath += seperator
+ jwsPath.substring(0, jwsPath.lastIndexOf(File.separator));
}
//add cwd path
paths[paths.length - 1] = dllName;
// split, and rebuild library path to path + dll
StringTokenizer st = new StringTokenizer(libpath, seperator);
String[] paths = new String[st.countTokens() + 1];
//build paths
for (int i = 0; i < paths.length - 1; i++) {
paths[i] = st.nextToken() + File.separator;
}
for(int i=0 ; i<paths.length; i++) {
LWJGLUtil.log("Will search " + paths[i] + " for " + dllName);
}
//add cwd path
paths[paths.length - 1] = dllName;
return paths;
}
/**
* Native method to create FMOD instance
*/
protected static native void nCreate(String[] paths);
/**
* Exit cleanly by calling destroy.
*/
public static void destroy() {
if(!created) {
return;
}
created = false;
nDestroy();
}
/**
* Tries to locate FMOD from the JWS Library path
* This method exists because FMOD is loaded from native code, and as such
* is exempt from JWS library loading rutines. FMOD therefore always fails.
* We therefore invoke the protected method of the JWS classloader to see if it can
* locate it.
*
* @param libname Name of library to search for
* @return Absolute path to library if found, otherwise null
*/
private static String getPathFromJWS(String libname) {
try {
LWJGLUtil.log("getPathFromJWS: searching for: " + libname);
Object o = FMOD.class.getClassLoader();
Class c = o.getClass();
Method findLibrary =
c.getMethod("findLibrary", new Class[] { String.class });
Object[] arguments = new Object[] { libname };
return (String) findLibrary.invoke(o, arguments);
* Native method to create FMOD instance
*/
protected static native void nCreate(String[] paths);
} catch (Exception e) {
LWJGLUtil.log("Failure locating FMOD using classloader:" + e);
}
return null;
}
/**
* Exit cleanly by calling destroy.
*/
public static void destroy() {
if(!created) {
return;
}
/**
* Native method the destroy the FMOD
*/
protected static native void nDestroy();
/**
* Registers a callback by its handle
*
* @param handle Handle to native object being monitored
* @param callbackHandler Object to register as the call back handler
*/
static void registerCallback(int type, long handle, Object handled, Object callbackHandler) {
Long callbackID = new Long(handle);
ArrayList callbackList = (ArrayList) callbacks[type].get(callbackID);
created = false;
nDestroy();
}
if (callbackList == null ) {
if (callbackHandler == null) {
LWJGLUtil.log("No callbackhandlers registered for handle: " + handle);
} else {
callbackList = new ArrayList();
callbacks[type].put(callbackID, callbackList);
}
}
// are we going to add or remove from the list?
if(callbackHandler == null) {
callbacks[type].remove(callbackID);
} else {
callbackList.add(new FMOD.WrappedCallback(handled, callbackHandler));
}
}
/**
* Retrieves a call back handler by its native handle
* @param handle Handle to native object being monitored
* @return Call back handler, or null if no such handler
*/
static ArrayList getCallbacks(int type, long handle) {
return (ArrayList) callbacks[type].get(new Long(handle));
}
/**
* Tries to locate FMOD from the JWS Library path
* This method exists because FMOD is loaded from native code, and as such
* is exempt from JWS library loading rutines. FMOD therefore always fails.
* We therefore invoke the protected method of the JWS classloader to see if it can
* locate it.
*
* @param libname Name of library to search for
* @return Absolute path to library if found, otherwise null
*/
private static String getPathFromJWS(String libname) {
try {
LWJGLUtil.log("getPathFromJWS: searching for: " + libname);
Object o = FMOD.class.getClassLoader();
Class c = o.getClass();
Method findLibrary =
c.getMethod("findLibrary", new Class[] { String.class });
Object[] arguments = new Object[] { libname };
return (String) findLibrary.invoke(o, arguments);
/**
* Retrieves the errorcode desription for specified code
*
* @param errorcode errorcode to lookup
* @return Description of errorcode
*/
public static native String FMOD_ErrorString(int errorcode);
/**
* Wrapper class for a callback handler, and the object associated
*/
static class WrappedCallback {
Object handled;
Object callback;
WrappedCallback(Object handled, Object callback) {
this.handled = handled;
this.callback = callback;
}
}
} catch (Exception e) {
LWJGLUtil.log("Failure locating FMOD using classloader:" + e);
}
return null;
}
/**
* Native method the destroy the FMOD
*/
protected static native void nDestroy();
/**
* Registers a callback by its handle
*
* @param handle Handle to native object being monitored
* @param callbackHandler Object to register as the call back handler
*/
static void registerCallback(int type, long handle, Object handled, Object callbackHandler) {
Long callbackID = new Long(handle);
ArrayList callbackList = (ArrayList) callbacks[type].get(callbackID);
if (callbackList == null ) {
if (callbackHandler == null) {
LWJGLUtil.log("No callbackhandlers registered for handle: " + handle);
} else {
callbackList = new ArrayList();
callbacks[type].put(callbackID, callbackList);
}
}
// are we going to add or remove from the list?
if(callbackHandler == null) {
callbacks[type].remove(callbackID);
} else {
callbackList.add(new FMOD.WrappedCallback(handled, callbackHandler));
}
}
/**
* Retrieves a call back handler by its native handle
* @param handle Handle to native object being monitored
* @return Call back handler, or null if no such handler
*/
static ArrayList getCallbacks(int type, long handle) {
return (ArrayList) callbacks[type].get(new Long(handle));
}
/**
* Retrieves the errorcode desription for specified code
*
* @param errorcode errorcode to lookup
* @return Description of errorcode
*/
public static native String FMOD_ErrorString(int errorcode);
/**
* Wrapper class for a callback handler, and the object associated
*/
static class WrappedCallback {
Object handled;
Object callback;
WrappedCallback(Object handled, Object callback) {
this.handled = handled;
this.callback = callback;
}
}
}

View File

@ -36,6 +36,7 @@ import java.nio.IntBuffer;
import org.lwjgl.BufferChecks;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
@ -155,27 +156,31 @@ public class Cursor {
// Win32 or X and do accordingly. This hasn't been implemented on Mac, but we
// might want to split it into a X/Win/Mac cursor if it gets too cluttered
String osName = System.getProperty("os.name", "");
CursorElement[] cursors;
if (osName.startsWith("Win") || osName.startsWith("Mac")) {
// create our cursor elements
cursors = new CursorElement[numImages];
for(int i=0; i<numImages; i++) {
Object handle = Display.getImplementation().createCursor(width, height, xHotspot, yHotspot, 1, images_copy, null);
long delay = (delays != null) ? delays.get(i) : 0;
long timeout = System.currentTimeMillis();
cursors[i] = new CursorElement(handle, delay, timeout);
// offset to next image
images_copy.position(width*height*(i+1));
}
} else if (osName.startsWith("Lin")) {
// create our cursor elements
Object handle = Display.getImplementation().createCursor(width, height, xHotspot, yHotspot, numImages, images_copy, delays);
CursorElement cursor_element = new CursorElement(handle, -1, -1);
cursors = new CursorElement[]{cursor_element};
} else {
throw new RuntimeException("Unknown OS");
switch (LWJGLUtil.getPlatform()) {
case LWJGLUtil.PLATFORM_MACOSX:
/* Fall through */
case LWJGLUtil.PLATFORM_WINDOWS:
// create our cursor elements
cursors = new CursorElement[numImages];
for(int i=0; i<numImages; i++) {
Object handle = Display.getImplementation().createCursor(width, height, xHotspot, yHotspot, 1, images_copy, null);
long delay = (delays != null) ? delays.get(i) : 0;
long timeout = System.currentTimeMillis();
cursors[i] = new CursorElement(handle, delay, timeout);
// offset to next image
images_copy.position(width*height*(i+1));
}
break;
case LWJGLUtil.PLATFORM_LINUX:
// create our cursor elements
Object handle = Display.getImplementation().createCursor(width, height, xHotspot, yHotspot, numImages, images_copy, delays);
CursorElement cursor_element = new CursorElement(handle, -1, -1);
cursors = new CursorElement[]{cursor_element};
break;
default:
throw new RuntimeException("Unknown OS");
}
return cursors;
}

View File

@ -129,7 +129,7 @@ public class Mouse {
private static boolean isGrabbed;
/** Whether we're running windows - which need to manually update cursor animation */
private static final boolean isWindows = System.getProperty("os.name").startsWith("Win");
private static final boolean isWindows = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS;
/**
* Mouse cannot be constructed.

View File

@ -37,6 +37,7 @@ import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.Sys;
import java.awt.Point;
@ -61,15 +62,19 @@ public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener,
static {
Sys.initialize();
String class_name;
String OS_NAME = System.getProperty("os.name");
if (OS_NAME.startsWith("Linux")) {
class_name = "org.lwjgl.opengl.LinuxCanvasImplementation";
} else if (OS_NAME.startsWith("Windows")) {
class_name = "org.lwjgl.opengl.Win32CanvasImplementation";
} else if (OS_NAME.startsWith("Mac")) {
class_name = "org.lwjgl.opengl.MacOSXCanvasImplementation";
} else
throw new IllegalStateException("The platform " + OS_NAME + " is not supported");
switch (LWJGLUtil.getPlatform()) {
case LWJGLUtil.PLATFORM_LINUX:
class_name = "org.lwjgl.opengl.LinuxCanvasImplementation";
break;
case LWJGLUtil.PLATFORM_WINDOWS:
class_name = "org.lwjgl.opengl.Win32CanvasImplementation";
break;
case LWJGLUtil.PLATFORM_MACOSX:
class_name = "org.lwjgl.opengl.MacOSXCanvasImplementation";
break;
default:
throw new IllegalStateException("Unsupported platform");
}
try {
Class impl_class = Class.forName(class_name);
implementation = (AWTCanvasImplementation)impl_class.newInstance();

View File

@ -74,15 +74,19 @@ final class Context {
static {
Sys.initialize();
String class_name;
String OS_NAME = System.getProperty("os.name");
if (OS_NAME.startsWith("Linux")) {
class_name = "org.lwjgl.opengl.LinuxContextImplementation";
} else if (OS_NAME.startsWith("Windows")) {
class_name = "org.lwjgl.opengl.Win32ContextImplementation";
} else if (OS_NAME.startsWith("Mac")) {
class_name = "org.lwjgl.opengl.MacOSXContextImplementation";
} else
throw new IllegalStateException("The platform " + OS_NAME + " is not supported");
switch (LWJGLUtil.getPlatform()) {
case LWJGLUtil.PLATFORM_LINUX:
class_name = "org.lwjgl.opengl.LinuxContextImplementation";
break;
case LWJGLUtil.PLATFORM_WINDOWS:
class_name = "org.lwjgl.opengl.Win32ContextImplementation";
break;
case LWJGLUtil.PLATFORM_MACOSX:
class_name = "org.lwjgl.opengl.MacOSXContextImplementation";
break;
default:
throw new IllegalStateException("Unsupported platform");
}
try {
Class impl_class = Class.forName(class_name);
implementation = (ContextImplementation)impl_class.newInstance();

View File

@ -127,15 +127,19 @@ public final class Display {
private static DisplayImplementation createDisplayImplementation() {
String class_name;
String os_name = System.getProperty("os.name");
if (os_name.startsWith("Linux")) {
class_name = "org.lwjgl.opengl.LinuxDisplay";
} else if (os_name.startsWith("Windows")) {
class_name = "org.lwjgl.opengl.Win32Display";
} else if (os_name.startsWith("Mac")) {
class_name = "org.lwjgl.opengl.MacOSXDisplay";
} else
throw new IllegalStateException("The platform " + os_name + " is not supported");
switch (LWJGLUtil.getPlatform()) {
case LWJGLUtil.PLATFORM_LINUX:
class_name = "org.lwjgl.opengl.LinuxDisplay";
break;
case LWJGLUtil.PLATFORM_WINDOWS:
class_name = "org.lwjgl.opengl.Win32Display";
break;
case LWJGLUtil.PLATFORM_MACOSX:
class_name = "org.lwjgl.opengl.MacOSXDisplay";
break;
default:
throw new IllegalStateException("Unsupported platform");
}
try {
Class display_class = Class.forName(class_name);
return (DisplayImplementation)display_class.newInstance();