Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/openal
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22082
Modified Files:
AL.java ALC.java
Log Message:
support for ALC_ENUMERATION_EXT using LWJGL specific method: AL.getImplementations
Index: AL.java
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/openal/AL.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- AL.java 16 Jan 2006 19:35:09 -0000 1.49
+++ AL.java 2 Feb 2006 22:33:41 -0000 1.50
@@ -31,6 +31,8 @@
*/
package org.lwjgl.openal;
+import java.util.Vector;
+
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.Sys;
@@ -52,7 +54,7 @@
/** Have we been created? */
private static boolean created;
-
+
static {
Sys.initialize();
}
@@ -96,8 +98,17 @@
* @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)
+ 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)
+ static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized, boolean openDevice)
throws LWJGLException {
if (created)
@@ -128,18 +139,20 @@
AL10.initNativeStubs();
ALC.initNativeStubs();
- device = ALC.alcOpenDevice(deviceArguments);
- if (device == null)
- throw new LWJGLException("Could not open ALC device");
-
- if (contextFrequency == -1) {
- context = ALC.alcCreateContext(device.device, null);
- } else {
- context = ALC.alcCreateContext(device.device,
- ALCcontext.createAttributeList(contextFrequency, contextRefresh,
- contextSynchronized ? ALC.ALC_TRUE : ALC.ALC_FALSE));
+ if(openDevice) {
+ device = ALC.alcOpenDevice(deviceArguments);
+ if (device == null)
+ throw new LWJGLException("Could not open ALC device");
+
+ if (contextFrequency == -1) {
+ context = ALC.alcCreateContext(device.device, null);
+ } else {
+ context = ALC.alcCreateContext(device.device,
+ ALCcontext.createAttributeList(contextFrequency, contextRefresh,
+ contextSynchronized ? ALC.ALC_TRUE : ALC.ALC_FALSE));
+ }
+ ALC.alcMakeContextCurrent(context.context);
}
- ALC.alcMakeContextCurrent(context.context);
} catch (LWJGLException e) {
destroy();
throw e;
@@ -189,4 +202,41 @@
public static Object getContext() {
return context;
}
+
+ /**
+ *
+ * @return
+ */
+ public static String[] getImplementations() throws LWJGLException, OpenALException {
+ if(AL.isCreated()) {
+ throw new OpenALException("Cannot enumerate devices if AL has already been created");
+ }
+
+ Vector availableDevices = new Vector();
+
+ try {
+ // init
+ create(null, 44100, 60, false, false);
+
+ // check for extension
+ if(!ALC.alcIsExtensionPresent("ALC_ENUMERATION_EXT")) {
+ throw new OpenALException("ALC_ENUMERATION_EXT extension not available");
+ }
+
+ // get list of published devices
+ String[] publishedDevices = ALC.ngetImplementations();
+
+ // run through them and verify
+ for (int i = 0; i < publishedDevices.length; i++) {
+ availableDevices.add(publishedDevices[i]);
+ }
+ } finally {
+ destroy();
+ }
+
+ String[] available = new String[availableDevices.size()];
+ availableDevices.copyInto(available);
+
+ return available;
+ }
}
Index: ALC.java
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/openal/ALC.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- ALC.java 4 May 2005 20:59:41 -0000 1.28
+++ ALC.java 2 Feb 2006 22:33:41 -0000 1.29
@@ -148,6 +148,13 @@
}
static native void initNativeStubs() throws LWJGLException;
+
+ static long getDevice() {
+ if(AL.device != null) {
+ return AL.device.device;
+ }
+ return 0L;
+ }
/**
* The application can obtain certain strings from ALC.
@@ -164,7 +171,8 @@
* @return String property from device
*/
public static String alcGetString(int pname) {
- String result = nalcGetString(AL.device.device, pname);
+ String result;
+ result = nalcGetString(getDevice(), pname);
Util.checkALCError();
return result;
}
@@ -192,7 +200,7 @@
*/
public static void alcGetInteger(int pname, IntBuffer integerdata) {
BufferChecks.checkDirect(integerdata);
- nalcGetIntegerv(AL.device.device, pname, integerdata.remaining(), integerdata, integerdata.position());
+ nalcGetIntegerv(getDevice(), pname, integerdata.remaining(), integerdata, integerdata.position());
Util.checkALCError();
}
private native static void nalcGetIntegerv(long device, int pname, int size, Buffer integerdata, int offset);
@@ -333,7 +341,7 @@
* @return Errorcode from ALC statemachine
*/
public static int alcGetError() {
- return nalcGetError(AL.device.device);
+ return nalcGetError(getDevice());
}
private native static int nalcGetError(long device);
@@ -347,7 +355,7 @@
* @return true if extension is available, false if not
*/
public static boolean alcIsExtensionPresent(String extName) {
- boolean result = nalcIsExtensionPresent(AL.device.device, extName);
+ boolean result = nalcIsExtensionPresent(getDevice(), extName);
Util.checkALCError();
return result;
}
@@ -364,9 +372,11 @@
* @return value of enumeration
*/
public static int alcGetEnumValue(String enumName) {
- int result = nalcGetEnumValue(AL.device.device, enumName);
+ int result = nalcGetEnumValue(getDevice(), enumName);
Util.checkALCError();
return result;
}
private native static int nalcGetEnumValue(long device, String enumName);
+
+ static native String[] ngetImplementations();
}
|