lwjgl2-arm64/src/java/org/lwjgl/test/openal/SourceLimitTest.java

166 lines
4.8 KiB
Java
Raw Normal View History

2004-06-12 22:28:34 +02:00
/*
* Copyright (c) 2002-2004 LWJGL Project
2003-08-17 18:58:19 +02:00
* All rights reserved.
2004-06-12 22:28:34 +02:00
*
2003-08-17 18:58:19 +02:00
* Redistribution and use in source and binary forms, with or without
2004-06-12 22:28:34 +02:00
* modification, are permitted provided that the following conditions are
2003-08-17 18:58:19 +02:00
* met:
2004-06-12 22:28:34 +02:00
*
* * Redistributions of source code must retain the above copyright
2003-08-17 18:58:19 +02:00
* 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.
*
2004-06-12 22:28:34 +02:00
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
2003-08-17 18:58:19 +02:00
* from this software without specific prior written permission.
2004-06-12 22:28:34 +02:00
*
2003-08-17 18:58:19 +02:00
* 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
2004-06-12 22:28:34 +02:00
* 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
2003-08-17 18:58:19 +02:00
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2004-06-12 22:28:34 +02:00
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2003-08-17 18:58:19 +02:00
* 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.test.openal;
2004-02-08 21:41:00 +01:00
import java.nio.IntBuffer;
2004-07-22 16:27:07 +02:00
import org.lwjgl.BufferUtils;
2004-02-26 22:51:58 +01:00
import org.lwjgl.openal.AL10;
2003-08-17 18:58:19 +02:00
import org.lwjgl.openal.OpenALException;
/**
*
* Simple test for testing the number of available sources
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
2006-03-23 20:32:21 +01:00
* $Id$
2003-08-17 18:58:19 +02:00
*/
public class SourceLimitTest extends BasicTest {
/** Sources to create */
protected int sourcesToCreate = 64;
/**
* Creates an instance of SourceLimitTest
*/
public SourceLimitTest() {
super();
}
/**
* Runs the actual test, using supplied arguments
*/
protected void execute(String[] args) {
//parse 1st arg to sourcecount
if (args.length > 0) {
try {
sourcesToCreate = Integer.parseInt(args[0]);
} catch (NumberFormatException nfe) {
System.out.println(
"Unable to parse parameter to integer. Defaulting to 64 sources.");
}
}
System.out.print("Creating " + sourcesToCreate + " in one go...");
try {
CreateAllSources();
} catch(OpenALException oale) {
2004-12-08 22:02:50 +01:00
oale.printStackTrace();
2003-08-17 18:58:19 +02:00
}
System.out.print("Creating " + sourcesToCreate + " one at a time...");
try {
CreateSourcesStep();
} catch(Exception e) {
2004-12-08 22:02:50 +01:00
e.printStackTrace();
2003-08-17 18:58:19 +02:00
}
//shutdown
alExit();
}
/**
* Tests the creation of n sources in on go
*/
protected void CreateAllSources() {
int lastError;
//make bytbuffer that can hold sourcesToCreate sources
2004-07-22 16:27:07 +02:00
IntBuffer sources = BufferUtils.createIntBuffer(sourcesToCreate);
2003-08-17 18:58:19 +02:00
//Create sourcesToCreate sources in one fell swoop
2005-05-12 17:44:22 +02:00
try {
sources.position(0).limit(sourcesToCreate);
AL10.alGenSources(sources);
//delete sources
sources.position(0).limit(sourcesToCreate);
AL10.alDeleteSources(sources);
System.out.println("created " + sourcesToCreate + " sources successfully!");
} catch (OpenALException oale) {
System.out.println("Unable to create " + sourcesToCreate + " sources");
2003-08-17 18:58:19 +02:00
}
}
/**
* Tests if n sources can be created one at a time
*/
protected void CreateSourcesStep() {
int lastError;
int sourcesCreated = 0;
//make bytbuffer that can hold sourcesToCreate sources
IntBuffer[] sources = new IntBuffer[sourcesToCreate];
2005-05-12 17:44:22 +02:00
//create the sources
try {
for (int i = 0; i < sourcesToCreate; i++) {
sources[i] = BufferUtils.createIntBuffer(1);
sources[i].position(0).limit(1);
AL10.alGenSources(sources[i]);
if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
break;
}
sourcesCreated++;
2003-08-17 18:58:19 +02:00
}
2005-05-12 17:44:22 +02:00
} catch (OpenALException oale) {
System.out.println("failed to create source: " + (sourcesCreated + 1));
2003-08-17 18:58:19 +02:00
}
2005-05-12 17:44:22 +02:00
//delete allocated sources
2003-08-17 18:58:19 +02:00
for (int i = 0; i < sourcesCreated; i++) {
//delete buffers and sources
2005-05-12 17:44:22 +02:00
sources[i].position(0).limit(1);
2004-02-26 22:51:58 +01:00
AL10.alDeleteSources(sources[i]);
2003-08-17 18:58:19 +02:00
}
2005-05-12 17:44:22 +02:00
if(sourcesCreated != sourcesToCreate) {
System.out.println("created " + sourcesCreated + " sources before failing");
} else {
System.out.println("created " + sourcesCreated + " sources successfully!");
}
2003-08-17 18:58:19 +02:00
}
/**
* main entry point
*
* @param args String array containing arguments
*/
public static void main(String[] args) {
SourceLimitTest sourceLimitTest = new SourceLimitTest();
sourceLimitTest.execute(args);
System.exit(0);
2003-08-17 18:58:19 +02:00
}
2004-12-08 22:02:50 +01:00
}