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

@@ -6,6 +6,9 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.MinecraftForge;
public class ClientProxy extends CommonProxy {
static final String javaVersion = "Java: " + System.getProperty("java.version");
static final String lwjglVersion = "LWJGL: " + org.lwjgl.Version.getVersion();
@Override
public void registerF3Handler() {
MinecraftForge.EVENT_BUS.register(this);
@@ -14,8 +17,10 @@ public class ClientProxy extends CommonProxy {
@SubscribeEvent
@SuppressWarnings("unused") // event handler
public void onRenderGameOverlayTextEvent(RenderGameOverlayEvent.Text event) {
if (Minecraft.getMinecraft().gameSettings.showDebugInfo && event.type == RenderGameOverlayEvent.ElementType.TEXT) {
event.right.add(Math.min(3, event.right.size()), "LWJGL version: " + org.lwjgl.Version.getVersion());
if (Minecraft.getMinecraft().gameSettings.showDebugInfo
&& event.type == RenderGameOverlayEvent.ElementType.TEXT) {
event.right.add(Math.min(3, event.right.size()), javaVersion);
event.right.add(Math.min(4, event.right.size()), lwjglVersion);
}
}
}
@@ -3,7 +3,6 @@ package me.eigenraven.lwjgl3ify;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+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;
}