Fix OpenAL context creation

This commit is contained in:
Raven Szewczyk committed 2023-01-14 22:24:42 +00:00
1 parent 25d7beec82
commit 1b9ef21b10
3 files changed
+28 -8

No files matched your search

+21 -5
View File
@@ -1,6 +1,8 @@
package org.lwjglx.openal;
import java.nio.IntBuffer;
import org.lwjgl.openal.ALC10;
import org.lwjgl.openal.ALCCapabilities;
import org.lwjglx.BufferUtils;
import org.lwjglx.LWJGLException;
import org.lwjglx.Sys;
@@ -8,6 +10,7 @@ import org.lwjglx.Sys;
public class AL {
static ALCdevice alcDevice;
static ALCcontext alcContext;
private static boolean created = false;
@@ -16,8 +19,6 @@ public class AL {
}
public static void create() throws LWJGLException {
AL.create();
IntBuffer attribs = BufferUtils.createIntBuffer(16);
attribs.put(org.lwjgl.openal.ALC10.ALC_FREQUENCY);
@@ -32,9 +33,22 @@ public class AL {
attribs.put(0);
attribs.flip();
long contextHandle = org.lwjgl.openal.ALC10.alcCreateContext(AL.getDevice().device, attribs);
String defaultDevice = org.lwjgl.openal.ALC10.alcGetString(0, ALC10.ALC_DEFAULT_DEVICE_SPECIFIER);
alcDevice = new ALCdevice(contextHandle);
long deviceHandle = org.lwjgl.openal.ALC10.alcOpenDevice(defaultDevice);
alcDevice = new ALCdevice(deviceHandle);
final ALCCapabilities deviceCaps = org.lwjgl.openal.ALC.createCapabilities(deviceHandle);
long contextHandle = org.lwjgl.openal.ALC10.alcCreateContext(AL.getDevice().device, attribs);
alcContext = new ALCcontext(contextHandle);
if (deviceCaps.ALC_EXT_thread_local_context) {
org.lwjgl.openal.EXTThreadLocalContext.alcSetThreadContext(contextHandle);
} else {
org.lwjgl.openal.ALC10.alcMakeContextCurrent(contextHandle);
}
org.lwjgl.openal.AL.createCapabilities(deviceCaps);
created = true;
}
@@ -44,7 +58,9 @@ public class AL {
}
public static void destroy() {
AL.destroy();
org.lwjgl.openal.ALC10.alcDestroyContext(alcContext.context);
org.lwjgl.openal.ALC10.alcCloseDevice(alcDevice.device);
alcContext = null;
alcDevice = null;
created = false;
}