mirror of
https://github.com/love2d/megasource.git
synced 2026-08-19 20:20:11 +02:00
Update OpenAL-soft to 1.23.1-bc7cb17.
This commit is contained in:
@@ -1,39 +1,42 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "router.h"
|
||||
|
||||
|
||||
std::atomic<DriverIface*> CurrentCtxDriver{nullptr};
|
||||
|
||||
#define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \
|
||||
#define DECL_THUNK1(R,n,T1) \
|
||||
AL_API auto AL_APIENTRY n(T1 a) noexcept -> R \
|
||||
{ \
|
||||
DriverIface *iface = GetThreadDriver(); \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a); \
|
||||
}
|
||||
#define DECL_THUNK2(R,n,T1,T2) AL_API R AL_APIENTRY n(T1 a, T2 b) \
|
||||
#define DECL_THUNK2(R,n,T1,T2) \
|
||||
AL_API auto AL_APIENTRY n(T1 a, T2 b) noexcept -> R \
|
||||
{ \
|
||||
DriverIface *iface = GetThreadDriver(); \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a, b); \
|
||||
}
|
||||
#define DECL_THUNK3(R,n,T1,T2,T3) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c) \
|
||||
#define DECL_THUNK3(R,n,T1,T2,T3) \
|
||||
AL_API auto AL_APIENTRY n(T1 a, T2 b, T3 c) noexcept -> R \
|
||||
{ \
|
||||
DriverIface *iface = GetThreadDriver(); \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a, b, c); \
|
||||
}
|
||||
#define DECL_THUNK4(R,n,T1,T2,T3,T4) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) \
|
||||
#define DECL_THUNK4(R,n,T1,T2,T3,T4) \
|
||||
AL_API auto AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) noexcept -> R \
|
||||
{ \
|
||||
DriverIface *iface = GetThreadDriver(); \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a, b, c, d); \
|
||||
}
|
||||
#define DECL_THUNK5(R,n,T1,T2,T3,T4,T5) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d, T5 e) \
|
||||
#define DECL_THUNK5(R,n,T1,T2,T3,T4,T5) \
|
||||
AL_API auto AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d, T5 e) noexcept -> R \
|
||||
{ \
|
||||
DriverIface *iface = GetThreadDriver(); \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
@@ -44,7 +47,7 @@ std::atomic<DriverIface*> CurrentCtxDriver{nullptr};
|
||||
/* Ugly hack for some apps calling alGetError without a current context, and
|
||||
* expecting it to be AL_NO_ERROR.
|
||||
*/
|
||||
AL_API ALenum AL_APIENTRY alGetError(void)
|
||||
AL_API auto AL_APIENTRY alGetError() noexcept -> ALenum
|
||||
{
|
||||
DriverIface *iface = GetThreadDriver();
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire);
|
||||
@@ -130,3 +133,42 @@ DECL_THUNK3(void, alGetBufferi, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK5(void, alGetBuffer3i, ALuint, ALenum, ALint*, ALint*, ALint*)
|
||||
DECL_THUNK3(void, alGetBufferiv, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK5(void, alBufferData, ALuint, ALenum, const ALvoid*, ALsizei, ALsizei)
|
||||
|
||||
/* EFX 1.0. Required here to be exported from libOpenAL32.dll.a/OpenAL32.lib
|
||||
* with the router enabled.
|
||||
*/
|
||||
DECL_THUNK2(void, alGenFilters, ALsizei, ALuint*)
|
||||
DECL_THUNK2(void, alDeleteFilters, ALsizei, const ALuint*)
|
||||
DECL_THUNK1(ALboolean, alIsFilter, ALuint)
|
||||
DECL_THUNK3(void, alFilterf, ALuint, ALenum, ALfloat)
|
||||
DECL_THUNK3(void, alFilterfv, ALuint, ALenum, const ALfloat*)
|
||||
DECL_THUNK3(void, alFilteri, ALuint, ALenum, ALint)
|
||||
DECL_THUNK3(void, alFilteriv, ALuint, ALenum, const ALint*)
|
||||
DECL_THUNK3(void, alGetFilterf, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetFilterfv, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetFilteri, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK3(void, alGetFilteriv, ALuint, ALenum, ALint*)
|
||||
|
||||
DECL_THUNK2(void, alGenEffects, ALsizei, ALuint*)
|
||||
DECL_THUNK2(void, alDeleteEffects, ALsizei, const ALuint*)
|
||||
DECL_THUNK1(ALboolean, alIsEffect, ALuint)
|
||||
DECL_THUNK3(void, alEffectf, ALuint, ALenum, ALfloat)
|
||||
DECL_THUNK3(void, alEffectfv, ALuint, ALenum, const ALfloat*)
|
||||
DECL_THUNK3(void, alEffecti, ALuint, ALenum, ALint)
|
||||
DECL_THUNK3(void, alEffectiv, ALuint, ALenum, const ALint*)
|
||||
DECL_THUNK3(void, alGetEffectf, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetEffectfv, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetEffecti, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK3(void, alGetEffectiv, ALuint, ALenum, ALint*)
|
||||
|
||||
DECL_THUNK2(void, alGenAuxiliaryEffectSlots, ALsizei, ALuint*)
|
||||
DECL_THUNK2(void, alDeleteAuxiliaryEffectSlots, ALsizei, const ALuint*)
|
||||
DECL_THUNK1(ALboolean, alIsAuxiliaryEffectSlot, ALuint)
|
||||
DECL_THUNK3(void, alAuxiliaryEffectSlotf, ALuint, ALenum, ALfloat)
|
||||
DECL_THUNK3(void, alAuxiliaryEffectSlotfv, ALuint, ALenum, const ALfloat*)
|
||||
DECL_THUNK3(void, alAuxiliaryEffectSloti, ALuint, ALenum, ALint)
|
||||
DECL_THUNK3(void, alAuxiliaryEffectSlotiv, ALuint, ALenum, const ALint*)
|
||||
DECL_THUNK3(void, alGetAuxiliaryEffectSlotf, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetAuxiliaryEffectSlotfv, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetAuxiliaryEffectSloti, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK3(void, alGetAuxiliaryEffectSlotiv, ALuint, ALenum, ALint*)
|
||||
|
||||
+187
-101
@@ -6,9 +6,10 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
#include <tuple>
|
||||
|
||||
#include "AL/alc.h"
|
||||
#include "alstring.h"
|
||||
@@ -118,6 +119,41 @@ static const std::array<FuncExportEntry,128> alcFunctions{{
|
||||
DECL(alDopplerVelocity),
|
||||
DECL(alSpeedOfSound),
|
||||
DECL(alDistanceModel),
|
||||
|
||||
/* EFX 1.0 */
|
||||
DECL(alGenFilters),
|
||||
DECL(alDeleteFilters),
|
||||
DECL(alIsFilter),
|
||||
DECL(alFilterf),
|
||||
DECL(alFilterfv),
|
||||
DECL(alFilteri),
|
||||
DECL(alFilteriv),
|
||||
DECL(alGetFilterf),
|
||||
DECL(alGetFilterfv),
|
||||
DECL(alGetFilteri),
|
||||
DECL(alGetFilteriv),
|
||||
DECL(alGenEffects),
|
||||
DECL(alDeleteEffects),
|
||||
DECL(alIsEffect),
|
||||
DECL(alEffectf),
|
||||
DECL(alEffectfv),
|
||||
DECL(alEffecti),
|
||||
DECL(alEffectiv),
|
||||
DECL(alGetEffectf),
|
||||
DECL(alGetEffectfv),
|
||||
DECL(alGetEffecti),
|
||||
DECL(alGetEffectiv),
|
||||
DECL(alGenAuxiliaryEffectSlots),
|
||||
DECL(alDeleteAuxiliaryEffectSlots),
|
||||
DECL(alIsAuxiliaryEffectSlot),
|
||||
DECL(alAuxiliaryEffectSlotf),
|
||||
DECL(alAuxiliaryEffectSlotfv),
|
||||
DECL(alAuxiliaryEffectSloti),
|
||||
DECL(alAuxiliaryEffectSlotiv),
|
||||
DECL(alGetAuxiliaryEffectSlotf),
|
||||
DECL(alGetAuxiliaryEffectSlotfv),
|
||||
DECL(alGetAuxiliaryEffectSloti),
|
||||
DECL(alGetAuxiliaryEffectSlotiv),
|
||||
}};
|
||||
#undef DECL
|
||||
|
||||
@@ -309,7 +345,57 @@ static ALint GetDriverIndexForName(const EnumeratedList *list, const ALCchar *na
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
|
||||
static void InitCtxFuncs(DriverIface &iface)
|
||||
{
|
||||
ALCdevice *device{iface.alcGetContextsDevice(iface.alcGetCurrentContext())};
|
||||
|
||||
#define LOAD_PROC(x) do { \
|
||||
iface.x = reinterpret_cast<decltype(iface.x)>(iface.alGetProcAddress(#x));\
|
||||
if(!iface.x) \
|
||||
ERR("Failed to find entry point for %s in %ls\n", #x, \
|
||||
iface.Name.c_str()); \
|
||||
} while(0)
|
||||
if(iface.alcIsExtensionPresent(device, "ALC_EXT_EFX"))
|
||||
{
|
||||
LOAD_PROC(alGenFilters);
|
||||
LOAD_PROC(alDeleteFilters);
|
||||
LOAD_PROC(alIsFilter);
|
||||
LOAD_PROC(alFilterf);
|
||||
LOAD_PROC(alFilterfv);
|
||||
LOAD_PROC(alFilteri);
|
||||
LOAD_PROC(alFilteriv);
|
||||
LOAD_PROC(alGetFilterf);
|
||||
LOAD_PROC(alGetFilterfv);
|
||||
LOAD_PROC(alGetFilteri);
|
||||
LOAD_PROC(alGetFilteriv);
|
||||
LOAD_PROC(alGenEffects);
|
||||
LOAD_PROC(alDeleteEffects);
|
||||
LOAD_PROC(alIsEffect);
|
||||
LOAD_PROC(alEffectf);
|
||||
LOAD_PROC(alEffectfv);
|
||||
LOAD_PROC(alEffecti);
|
||||
LOAD_PROC(alEffectiv);
|
||||
LOAD_PROC(alGetEffectf);
|
||||
LOAD_PROC(alGetEffectfv);
|
||||
LOAD_PROC(alGetEffecti);
|
||||
LOAD_PROC(alGetEffectiv);
|
||||
LOAD_PROC(alGenAuxiliaryEffectSlots);
|
||||
LOAD_PROC(alDeleteAuxiliaryEffectSlots);
|
||||
LOAD_PROC(alIsAuxiliaryEffectSlot);
|
||||
LOAD_PROC(alAuxiliaryEffectSlotf);
|
||||
LOAD_PROC(alAuxiliaryEffectSlotfv);
|
||||
LOAD_PROC(alAuxiliaryEffectSloti);
|
||||
LOAD_PROC(alAuxiliaryEffectSlotiv);
|
||||
LOAD_PROC(alGetAuxiliaryEffectSlotf);
|
||||
LOAD_PROC(alGetAuxiliaryEffectSlotfv);
|
||||
LOAD_PROC(alGetAuxiliaryEffectSloti);
|
||||
LOAD_PROC(alGetAuxiliaryEffectSlotiv);
|
||||
}
|
||||
#undef LOAD_PROC
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename) noexcept
|
||||
{
|
||||
ALCdevice *device = nullptr;
|
||||
ALint idx = 0;
|
||||
@@ -326,14 +412,14 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
|
||||
if(devicename)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
std::lock_guard<std::recursive_mutex> enumlock{EnumerationLock};
|
||||
if(DevicesList.Names.empty())
|
||||
(void)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
|
||||
std::ignore = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&DevicesList, devicename);
|
||||
if(idx < 0)
|
||||
{
|
||||
if(AllDevicesList.Names.empty())
|
||||
(void)alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
|
||||
std::ignore = alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&AllDevicesList, devicename);
|
||||
}
|
||||
}
|
||||
@@ -345,17 +431,17 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
|
||||
return nullptr;
|
||||
}
|
||||
TRACE("Found driver %d for name \"%s\"\n", idx, devicename);
|
||||
device = DriverList[idx].alcOpenDevice(devicename);
|
||||
device = DriverList[idx]->alcOpenDevice(devicename);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
if(drv.ALCVer >= MAKE_ALC_VER(1, 1) ||
|
||||
drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
if(drv->ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv->alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
{
|
||||
TRACE("Using default device from driver %d\n", idx);
|
||||
device = drv.alcOpenDevice(nullptr);
|
||||
device = drv->alcOpenDevice(nullptr);
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
@@ -366,7 +452,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
|
||||
{
|
||||
if(DeviceIfaceMap.insert(device, idx) != ALC_NO_ERROR)
|
||||
{
|
||||
DriverList[idx].alcCloseDevice(device);
|
||||
DriverList[idx]->alcCloseDevice(device);
|
||||
device = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -374,7 +460,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
|
||||
return device;
|
||||
}
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
|
||||
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device) noexcept
|
||||
{
|
||||
ALint idx;
|
||||
|
||||
@@ -383,14 +469,14 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
if(!DriverList[idx].alcCloseDevice(device))
|
||||
if(!DriverList[idx]->alcCloseDevice(device))
|
||||
return ALC_FALSE;
|
||||
DeviceIfaceMap.removeByKey(device);
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrlist)
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrlist) noexcept
|
||||
{
|
||||
ALCcontext *context;
|
||||
ALint idx;
|
||||
@@ -400,12 +486,12 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return nullptr;
|
||||
}
|
||||
context = DriverList[idx].alcCreateContext(device, attrlist);
|
||||
context = DriverList[idx]->alcCreateContext(device, attrlist);
|
||||
if(context)
|
||||
{
|
||||
if(ContextIfaceMap.insert(context, idx) != ALC_NO_ERROR)
|
||||
{
|
||||
DriverList[idx].alcDestroyContext(context);
|
||||
DriverList[idx]->alcDestroyContext(context);
|
||||
context = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -413,11 +499,11 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
|
||||
return context;
|
||||
}
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context) noexcept
|
||||
{
|
||||
ALint idx = -1;
|
||||
|
||||
std::lock_guard<std::mutex> _{ContextSwitchLock};
|
||||
std::lock_guard<std::mutex> ctxlock{ContextSwitchLock};
|
||||
if(context)
|
||||
{
|
||||
idx = ContextIfaceMap.lookupByKey(context);
|
||||
@@ -426,8 +512,11 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
if(!DriverList[idx].alcMakeContextCurrent(context))
|
||||
if(!DriverList[idx]->alcMakeContextCurrent(context))
|
||||
return ALC_FALSE;
|
||||
|
||||
auto do_init = [idx]() { InitCtxFuncs(*DriverList[idx]); };
|
||||
std::call_once(DriverList[idx]->InitOnceCtx, do_init);
|
||||
}
|
||||
|
||||
/* Unset the context from the old driver if it's different from the new
|
||||
@@ -443,10 +532,10 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
else
|
||||
{
|
||||
DriverIface *oldiface = GetThreadDriver();
|
||||
if(oldiface && oldiface != &DriverList[idx])
|
||||
if(oldiface && oldiface != DriverList[idx].get())
|
||||
oldiface->alcSetThreadContext(nullptr);
|
||||
oldiface = CurrentCtxDriver.exchange(&DriverList[idx]);
|
||||
if(oldiface && oldiface != &DriverList[idx])
|
||||
oldiface = CurrentCtxDriver.exchange(DriverList[idx].get());
|
||||
if(oldiface && oldiface != DriverList[idx].get())
|
||||
oldiface->alcMakeContextCurrent(nullptr);
|
||||
}
|
||||
SetThreadDriver(nullptr);
|
||||
@@ -454,29 +543,29 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcProcessContext(ALCcontext *context)
|
||||
ALC_API void ALC_APIENTRY alcProcessContext(ALCcontext *context) noexcept
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
ALint idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcProcessContext(context);
|
||||
return DriverList[idx]->alcProcessContext(context);
|
||||
}
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context)
|
||||
ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context) noexcept
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
ALint idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcSuspendContext(context);
|
||||
return DriverList[idx]->alcSuspendContext(context);
|
||||
}
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context)
|
||||
ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context) noexcept
|
||||
{
|
||||
ALint idx;
|
||||
|
||||
@@ -486,42 +575,42 @@ ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context)
|
||||
return;
|
||||
}
|
||||
|
||||
DriverList[idx].alcDestroyContext(context);
|
||||
DriverList[idx]->alcDestroyContext(context);
|
||||
ContextIfaceMap.removeByKey(context);
|
||||
}
|
||||
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void)
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext() noexcept
|
||||
{
|
||||
DriverIface *iface = GetThreadDriver();
|
||||
if(!iface) iface = CurrentCtxDriver.load();
|
||||
return iface ? iface->alcGetCurrentContext() : nullptr;
|
||||
}
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *context)
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *context) noexcept
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
ALint idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcGetContextsDevice(context);
|
||||
return DriverList[idx]->alcGetContextsDevice(context);
|
||||
}
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
|
||||
ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device) noexcept
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0) return ALC_INVALID_DEVICE;
|
||||
return DriverList[idx].alcGetError(device);
|
||||
return DriverList[idx]->alcGetError(device);
|
||||
}
|
||||
return LastError.exchange(ALC_NO_ERROR);
|
||||
}
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extname)
|
||||
ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extname) noexcept
|
||||
{
|
||||
const char *ptr;
|
||||
size_t len;
|
||||
@@ -534,7 +623,7 @@ ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const A
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
return DriverList[idx].alcIsExtensionPresent(device, extname);
|
||||
return DriverList[idx]->alcIsExtensionPresent(device, extname);
|
||||
}
|
||||
|
||||
len = strlen(extname);
|
||||
@@ -553,7 +642,7 @@ ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const A
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcname)
|
||||
ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcname) noexcept
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
@@ -563,7 +652,7 @@ ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *f
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return nullptr;
|
||||
}
|
||||
return DriverList[idx].alcGetProcAddress(device, funcname);
|
||||
return DriverList[idx]->alcGetProcAddress(device, funcname);
|
||||
}
|
||||
|
||||
auto iter = std::find_if(alcFunctions.cbegin(), alcFunctions.cend(),
|
||||
@@ -573,7 +662,7 @@ ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *f
|
||||
return (iter != alcFunctions.cend()) ? iter->address : nullptr;
|
||||
}
|
||||
|
||||
ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname)
|
||||
ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname) noexcept
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
@@ -583,7 +672,7 @@ ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *e
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return 0;
|
||||
}
|
||||
return DriverList[idx].alcGetEnumValue(device, enumname);
|
||||
return DriverList[idx]->alcGetEnumValue(device, enumname);
|
||||
}
|
||||
|
||||
auto iter = std::find_if(alcEnumerations.cbegin(), alcEnumerations.cend(),
|
||||
@@ -593,7 +682,7 @@ ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *e
|
||||
return (iter != alcEnumerations.cend()) ? iter->value : 0;
|
||||
}
|
||||
|
||||
ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param)
|
||||
ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param) noexcept
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
@@ -603,7 +692,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return nullptr;
|
||||
}
|
||||
return DriverList[idx].alcGetString(device, param);
|
||||
return DriverList[idx]->alcGetString(device, param);
|
||||
}
|
||||
|
||||
switch(param)
|
||||
@@ -625,16 +714,16 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
|
||||
|
||||
case ALC_DEVICE_SPECIFIER:
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
std::lock_guard<std::recursive_mutex> enumlock{EnumerationLock};
|
||||
DevicesList.clear();
|
||||
ALint idx{0};
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
/* Only enumerate names from drivers that support it. */
|
||||
if(drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
if(drv->ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv->alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
AppendDeviceList(&DevicesList,
|
||||
drv.alcGetString(nullptr, ALC_DEVICE_SPECIFIER), idx);
|
||||
drv->alcGetString(nullptr, ALC_DEVICE_SPECIFIER), idx);
|
||||
++idx;
|
||||
}
|
||||
/* Ensure the list is double-null termianted. */
|
||||
@@ -646,7 +735,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
|
||||
|
||||
case ALC_ALL_DEVICES_SPECIFIER:
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
std::lock_guard<std::recursive_mutex> enumlock{EnumerationLock};
|
||||
AllDevicesList.clear();
|
||||
ALint idx{0};
|
||||
for(const auto &drv : DriverList)
|
||||
@@ -654,13 +743,13 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
|
||||
/* If the driver doesn't support ALC_ENUMERATE_ALL_EXT, substitute
|
||||
* standard enumeration.
|
||||
*/
|
||||
if(drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATE_ALL_EXT"))
|
||||
if(drv->alcIsExtensionPresent(nullptr, "ALC_ENUMERATE_ALL_EXT"))
|
||||
AppendDeviceList(&AllDevicesList,
|
||||
drv.alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER), idx);
|
||||
else if(drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
drv->alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER), idx);
|
||||
else if(drv->ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv->alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
AppendDeviceList(&AllDevicesList,
|
||||
drv.alcGetString(nullptr, ALC_DEVICE_SPECIFIER), idx);
|
||||
drv->alcGetString(nullptr, ALC_DEVICE_SPECIFIER), idx);
|
||||
++idx;
|
||||
}
|
||||
/* Ensure the list is double-null termianted. */
|
||||
@@ -672,15 +761,15 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
|
||||
|
||||
case ALC_CAPTURE_DEVICE_SPECIFIER:
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
std::lock_guard<std::recursive_mutex> enumlock{EnumerationLock};
|
||||
CaptureDevicesList.clear();
|
||||
ALint idx{0};
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
if(drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE"))
|
||||
if(drv->ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv->alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE"))
|
||||
AppendDeviceList(&CaptureDevicesList,
|
||||
drv.alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER), idx);
|
||||
drv->alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER), idx);
|
||||
++idx;
|
||||
}
|
||||
/* Ensure the list is double-null termianted. */
|
||||
@@ -692,39 +781,33 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
|
||||
|
||||
case ALC_DEFAULT_DEVICE_SPECIFIER:
|
||||
{
|
||||
auto iter = std::find_if(DriverList.cbegin(), DriverList.cend(),
|
||||
[](const DriverIface &drv) -> bool
|
||||
{
|
||||
return drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT");
|
||||
}
|
||||
);
|
||||
if(iter != DriverList.cend())
|
||||
return iter->alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
if(drv->ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv->alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT"))
|
||||
return drv->alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
|
||||
{
|
||||
auto iter = std::find_if(DriverList.cbegin(), DriverList.cend(),
|
||||
[](const DriverIface &drv) -> bool
|
||||
{ return drv.alcIsExtensionPresent(nullptr, "ALC_ENUMERATE_ALL_EXT") != ALC_FALSE; });
|
||||
if(iter != DriverList.cend())
|
||||
return iter->alcGetString(nullptr, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
if(drv->alcIsExtensionPresent(nullptr, "ALC_ENUMERATE_ALL_EXT") != ALC_FALSE)
|
||||
return drv->alcGetString(nullptr, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
|
||||
{
|
||||
auto iter = std::find_if(DriverList.cbegin(), DriverList.cend(),
|
||||
[](const DriverIface &drv) -> bool
|
||||
{
|
||||
return drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE");
|
||||
}
|
||||
);
|
||||
if(iter != DriverList.cend())
|
||||
return iter->alcGetString(nullptr, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
if(drv->ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv->alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE"))
|
||||
return drv->alcGetString(nullptr, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -735,7 +818,7 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum para
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values)
|
||||
ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values) noexcept
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
@@ -745,7 +828,7 @@ ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsi
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return;
|
||||
}
|
||||
return DriverList[idx].alcGetIntegerv(device, param, size, values);
|
||||
return DriverList[idx]->alcGetIntegerv(device, param, size, values);
|
||||
}
|
||||
|
||||
if(size <= 0 || values == nullptr)
|
||||
@@ -790,7 +873,7 @@ ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsi
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize)
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize) noexcept
|
||||
{
|
||||
ALCdevice *device = nullptr;
|
||||
ALint idx = 0;
|
||||
@@ -800,9 +883,9 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename,
|
||||
if(devicename)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
std::lock_guard<std::recursive_mutex> enumlock{EnumerationLock};
|
||||
if(CaptureDevicesList.Names.empty())
|
||||
(void)alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
std::ignore = alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&CaptureDevicesList, devicename);
|
||||
}
|
||||
|
||||
@@ -813,17 +896,17 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename,
|
||||
return nullptr;
|
||||
}
|
||||
TRACE("Found driver %d for name \"%s\"\n", idx, devicename);
|
||||
device = DriverList[idx].alcCaptureOpenDevice(devicename, frequency, format, buffersize);
|
||||
device = DriverList[idx]->alcCaptureOpenDevice(devicename, frequency, format, buffersize);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
if(drv.ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv.alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE"))
|
||||
if(drv->ALCVer >= MAKE_ALC_VER(1, 1)
|
||||
|| drv->alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE"))
|
||||
{
|
||||
TRACE("Using default capture device from driver %d\n", idx);
|
||||
device = drv.alcCaptureOpenDevice(nullptr, frequency, format, buffersize);
|
||||
device = drv->alcCaptureOpenDevice(nullptr, frequency, format, buffersize);
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
@@ -834,7 +917,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename,
|
||||
{
|
||||
if(DeviceIfaceMap.insert(device, idx) != ALC_NO_ERROR)
|
||||
{
|
||||
DriverList[idx].alcCaptureCloseDevice(device);
|
||||
DriverList[idx]->alcCaptureCloseDevice(device);
|
||||
device = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -842,7 +925,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename,
|
||||
return device;
|
||||
}
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device)
|
||||
ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device) noexcept
|
||||
{
|
||||
ALint idx;
|
||||
|
||||
@@ -851,47 +934,47 @@ ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device)
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
if(!DriverList[idx].alcCaptureCloseDevice(device))
|
||||
if(!DriverList[idx]->alcCaptureCloseDevice(device))
|
||||
return ALC_FALSE;
|
||||
DeviceIfaceMap.removeByKey(device);
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
|
||||
ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device) noexcept
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcCaptureStart(device);
|
||||
return DriverList[idx]->alcCaptureStart(device);
|
||||
}
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
|
||||
ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device) noexcept
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcCaptureStop(device);
|
||||
return DriverList[idx]->alcCaptureStop(device);
|
||||
}
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
|
||||
ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples) noexcept
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcCaptureSamples(device, buffer, samples);
|
||||
return DriverList[idx]->alcCaptureSamples(device, buffer, samples);
|
||||
}
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
|
||||
ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context) noexcept
|
||||
{
|
||||
ALCenum err = ALC_INVALID_CONTEXT;
|
||||
ALint idx;
|
||||
@@ -908,23 +991,26 @@ ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
|
||||
idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
{
|
||||
if(DriverList[idx].alcSetThreadContext(context))
|
||||
if(DriverList[idx]->alcSetThreadContext(context))
|
||||
{
|
||||
auto do_init = [idx]() { InitCtxFuncs(*DriverList[idx]); };
|
||||
std::call_once(DriverList[idx]->InitOnceCtx, do_init);
|
||||
|
||||
DriverIface *oldiface = GetThreadDriver();
|
||||
if(oldiface != &DriverList[idx])
|
||||
if(oldiface != DriverList[idx].get())
|
||||
{
|
||||
SetThreadDriver(&DriverList[idx]);
|
||||
SetThreadDriver(DriverList[idx].get());
|
||||
if(oldiface) oldiface->alcSetThreadContext(nullptr);
|
||||
}
|
||||
return ALC_TRUE;
|
||||
}
|
||||
err = DriverList[idx].alcGetError(nullptr);
|
||||
err = DriverList[idx]->alcGetError(nullptr);
|
||||
}
|
||||
LastError.store(err);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext() noexcept
|
||||
{
|
||||
DriverIface *iface = GetThreadDriver();
|
||||
if(iface) return iface->alcGetThreadContext();
|
||||
|
||||
@@ -17,19 +17,10 @@
|
||||
#include "version.h"
|
||||
|
||||
|
||||
std::vector<DriverIface> DriverList;
|
||||
|
||||
thread_local DriverIface *ThreadCtxDriver;
|
||||
|
||||
enum LogLevel LogLevel = LogLevel_Error;
|
||||
FILE *LogFile;
|
||||
|
||||
#ifdef __MINGW32__
|
||||
DriverIface *GetThreadDriver() noexcept { return ThreadCtxDriver; }
|
||||
void SetThreadDriver(DriverIface *driver) noexcept { ThreadCtxDriver = driver; }
|
||||
#endif
|
||||
|
||||
static void LoadDriverList(void);
|
||||
static void LoadDriverList();
|
||||
|
||||
|
||||
BOOL APIENTRY DllMain(HINSTANCE, DWORD reason, void*)
|
||||
@@ -84,13 +75,13 @@ static void AddModule(HMODULE module, const WCHAR *name)
|
||||
{
|
||||
for(auto &drv : DriverList)
|
||||
{
|
||||
if(drv.Module == module)
|
||||
if(drv->Module == module)
|
||||
{
|
||||
TRACE("Skipping already-loaded module %p\n", decltype(std::declval<void*>()){module});
|
||||
FreeLibrary(module);
|
||||
return;
|
||||
}
|
||||
if(drv.Name == name)
|
||||
if(drv->Name == name)
|
||||
{
|
||||
TRACE("Skipping similarly-named module %ls\n", name);
|
||||
FreeLibrary(module);
|
||||
@@ -98,8 +89,8 @@ static void AddModule(HMODULE module, const WCHAR *name)
|
||||
}
|
||||
}
|
||||
|
||||
DriverList.emplace_back(name, module);
|
||||
DriverIface &newdrv = DriverList.back();
|
||||
DriverList.emplace_back(std::make_unique<DriverIface>(name, module));
|
||||
DriverIface &newdrv = *DriverList.back();
|
||||
|
||||
/* Load required functions. */
|
||||
int err = 0;
|
||||
@@ -189,18 +180,6 @@ static void AddModule(HMODULE module, const WCHAR *name)
|
||||
LOAD_PROC(alGenBuffers);
|
||||
LOAD_PROC(alDeleteBuffers);
|
||||
LOAD_PROC(alIsBuffer);
|
||||
LOAD_PROC(alBufferf);
|
||||
LOAD_PROC(alBuffer3f);
|
||||
LOAD_PROC(alBufferfv);
|
||||
LOAD_PROC(alBufferi);
|
||||
LOAD_PROC(alBuffer3i);
|
||||
LOAD_PROC(alBufferiv);
|
||||
LOAD_PROC(alGetBufferf);
|
||||
LOAD_PROC(alGetBuffer3f);
|
||||
LOAD_PROC(alGetBufferfv);
|
||||
LOAD_PROC(alGetBufferi);
|
||||
LOAD_PROC(alGetBuffer3i);
|
||||
LOAD_PROC(alGetBufferiv);
|
||||
LOAD_PROC(alBufferData);
|
||||
LOAD_PROC(alDopplerFactor);
|
||||
LOAD_PROC(alDopplerVelocity);
|
||||
@@ -219,6 +198,28 @@ static void AddModule(HMODULE module, const WCHAR *name)
|
||||
newdrv.ALCVer = MAKE_ALC_VER(1, 0);
|
||||
}
|
||||
|
||||
#undef LOAD_PROC
|
||||
#define LOAD_PROC(x) do { \
|
||||
newdrv.x = reinterpret_cast<decltype(newdrv.x)>(reinterpret_cast<void*>( \
|
||||
GetProcAddress(module, #x))); \
|
||||
if(!newdrv.x) \
|
||||
{ \
|
||||
WARN("Failed to find optional entry point for %s in %ls\n", #x, name); \
|
||||
} \
|
||||
} while(0)
|
||||
LOAD_PROC(alBufferf);
|
||||
LOAD_PROC(alBuffer3f);
|
||||
LOAD_PROC(alBufferfv);
|
||||
LOAD_PROC(alBufferi);
|
||||
LOAD_PROC(alBuffer3i);
|
||||
LOAD_PROC(alBufferiv);
|
||||
LOAD_PROC(alGetBufferf);
|
||||
LOAD_PROC(alGetBuffer3f);
|
||||
LOAD_PROC(alGetBufferfv);
|
||||
LOAD_PROC(alGetBufferi);
|
||||
LOAD_PROC(alGetBuffer3i);
|
||||
LOAD_PROC(alGetBufferiv);
|
||||
|
||||
#undef LOAD_PROC
|
||||
#define LOAD_PROC(x) do { \
|
||||
newdrv.x = reinterpret_cast<decltype(newdrv.x)>( \
|
||||
@@ -312,19 +313,18 @@ static int GetLoadedModuleDirectory(const WCHAR *name, WCHAR *moddir, DWORD leng
|
||||
return 1;
|
||||
}
|
||||
|
||||
void LoadDriverList(void)
|
||||
void LoadDriverList()
|
||||
{
|
||||
WCHAR dll_path[MAX_PATH+1] = L"";
|
||||
WCHAR cwd_path[MAX_PATH+1] = L"";
|
||||
WCHAR proc_path[MAX_PATH+1] = L"";
|
||||
WCHAR sys_path[MAX_PATH+1] = L"";
|
||||
int len;
|
||||
|
||||
if(GetLoadedModuleDirectory(L"OpenAL32.dll", dll_path, MAX_PATH))
|
||||
TRACE("Got DLL path %ls\n", dll_path);
|
||||
|
||||
GetCurrentDirectoryW(MAX_PATH, cwd_path);
|
||||
len = lstrlenW(cwd_path);
|
||||
auto len = wcslen(cwd_path);
|
||||
if(len > 0 && (cwd_path[len-1] == '\\' || cwd_path[len-1] == '/'))
|
||||
cwd_path[len-1] = '\0';
|
||||
TRACE("Got current working directory %ls\n", cwd_path);
|
||||
@@ -333,7 +333,7 @@ void LoadDriverList(void)
|
||||
TRACE("Got proc path %ls\n", proc_path);
|
||||
|
||||
GetSystemDirectoryW(sys_path, MAX_PATH);
|
||||
len = lstrlenW(sys_path);
|
||||
len = wcslen(sys_path);
|
||||
if(len > 0 && (sys_path[len-1] == '\\' || sys_path[len-1] == '/'))
|
||||
sys_path[len-1] = '\0';
|
||||
TRACE("Got system path %ls\n", sys_path);
|
||||
@@ -361,7 +361,7 @@ void LoadDriverList(void)
|
||||
PtrIntMap::~PtrIntMap()
|
||||
{
|
||||
std::lock_guard<std::mutex> maplock{mLock};
|
||||
al_free(mKeys);
|
||||
free(mKeys);
|
||||
mKeys = nullptr;
|
||||
mValues = nullptr;
|
||||
mSize = 0;
|
||||
@@ -382,8 +382,7 @@ ALenum PtrIntMap::insert(void *key, int value)
|
||||
ALsizei newcap{mCapacity ? (mCapacity<<1) : 4};
|
||||
if(newcap > mCapacity)
|
||||
newkeys = static_cast<void**>(
|
||||
al_calloc(16, (sizeof(mKeys[0])+sizeof(mValues[0]))*newcap)
|
||||
);
|
||||
calloc(newcap, sizeof(mKeys[0])+sizeof(mValues[0])));
|
||||
if(!newkeys)
|
||||
return AL_OUT_OF_MEMORY;
|
||||
auto newvalues = reinterpret_cast<int*>(&newkeys[newcap]);
|
||||
@@ -393,7 +392,7 @@ ALenum PtrIntMap::insert(void *key, int value)
|
||||
std::copy_n(mKeys, mSize, newkeys);
|
||||
std::copy_n(mValues, mSize, newvalues);
|
||||
}
|
||||
al_free(mKeys);
|
||||
free(mKeys);
|
||||
mKeys = newkeys;
|
||||
mValues = newvalues;
|
||||
mCapacity = newcap;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -24,6 +25,7 @@ struct DriverIface {
|
||||
std::wstring Name;
|
||||
HMODULE Module{nullptr};
|
||||
int ALCVer{0};
|
||||
std::once_flag InitOnceCtx{};
|
||||
|
||||
LPALCCREATECONTEXT alcCreateContext{nullptr};
|
||||
LPALCMAKECONTEXTCURRENT alcMakeContextCurrent{nullptr};
|
||||
@@ -123,6 +125,41 @@ struct DriverIface {
|
||||
LPALSPEEDOFSOUND alSpeedOfSound{nullptr};
|
||||
LPALDISTANCEMODEL alDistanceModel{nullptr};
|
||||
|
||||
/* Functions to load after first context creation. */
|
||||
LPALGENFILTERS alGenFilters{nullptr};
|
||||
LPALDELETEFILTERS alDeleteFilters{nullptr};
|
||||
LPALISFILTER alIsFilter{nullptr};
|
||||
LPALFILTERF alFilterf{nullptr};
|
||||
LPALFILTERFV alFilterfv{nullptr};
|
||||
LPALFILTERI alFilteri{nullptr};
|
||||
LPALFILTERIV alFilteriv{nullptr};
|
||||
LPALGETFILTERF alGetFilterf{nullptr};
|
||||
LPALGETFILTERFV alGetFilterfv{nullptr};
|
||||
LPALGETFILTERI alGetFilteri{nullptr};
|
||||
LPALGETFILTERIV alGetFilteriv{nullptr};
|
||||
LPALGENEFFECTS alGenEffects{nullptr};
|
||||
LPALDELETEEFFECTS alDeleteEffects{nullptr};
|
||||
LPALISEFFECT alIsEffect{nullptr};
|
||||
LPALEFFECTF alEffectf{nullptr};
|
||||
LPALEFFECTFV alEffectfv{nullptr};
|
||||
LPALEFFECTI alEffecti{nullptr};
|
||||
LPALEFFECTIV alEffectiv{nullptr};
|
||||
LPALGETEFFECTF alGetEffectf{nullptr};
|
||||
LPALGETEFFECTFV alGetEffectfv{nullptr};
|
||||
LPALGETEFFECTI alGetEffecti{nullptr};
|
||||
LPALGETEFFECTIV alGetEffectiv{nullptr};
|
||||
LPALGENAUXILIARYEFFECTSLOTS alGenAuxiliaryEffectSlots{nullptr};
|
||||
LPALDELETEAUXILIARYEFFECTSLOTS alDeleteAuxiliaryEffectSlots{nullptr};
|
||||
LPALISAUXILIARYEFFECTSLOT alIsAuxiliaryEffectSlot{nullptr};
|
||||
LPALAUXILIARYEFFECTSLOTF alAuxiliaryEffectSlotf{nullptr};
|
||||
LPALAUXILIARYEFFECTSLOTFV alAuxiliaryEffectSlotfv{nullptr};
|
||||
LPALAUXILIARYEFFECTSLOTI alAuxiliaryEffectSloti{nullptr};
|
||||
LPALAUXILIARYEFFECTSLOTIV alAuxiliaryEffectSlotiv{nullptr};
|
||||
LPALGETAUXILIARYEFFECTSLOTF alGetAuxiliaryEffectSlotf{nullptr};
|
||||
LPALGETAUXILIARYEFFECTSLOTFV alGetAuxiliaryEffectSlotfv{nullptr};
|
||||
LPALGETAUXILIARYEFFECTSLOTI alGetAuxiliaryEffectSloti{nullptr};
|
||||
LPALGETAUXILIARYEFFECTSLOTIV alGetAuxiliaryEffectSlotiv{nullptr};
|
||||
|
||||
template<typename T>
|
||||
DriverIface(T&& name, HMODULE mod)
|
||||
: Name(std::forward<T>(name)), Module(mod)
|
||||
@@ -134,22 +171,15 @@ struct DriverIface {
|
||||
Module = nullptr;
|
||||
}
|
||||
};
|
||||
using DriverIfacePtr = std::unique_ptr<DriverIface>;
|
||||
|
||||
extern std::vector<DriverIface> DriverList;
|
||||
inline std::vector<DriverIfacePtr> DriverList;
|
||||
|
||||
extern thread_local DriverIface *ThreadCtxDriver;
|
||||
extern std::atomic<DriverIface*> CurrentCtxDriver;
|
||||
inline thread_local DriverIface *ThreadCtxDriver{};
|
||||
inline std::atomic<DriverIface*> CurrentCtxDriver{};
|
||||
|
||||
/* HACK: MinGW generates bad code when accessing an extern thread_local object.
|
||||
* Add a wrapper function for it that only accesses it where it's defined.
|
||||
*/
|
||||
#ifdef __MINGW32__
|
||||
DriverIface *GetThreadDriver() noexcept;
|
||||
void SetThreadDriver(DriverIface *driver) noexcept;
|
||||
#else
|
||||
inline DriverIface *GetThreadDriver() noexcept { return ThreadCtxDriver; }
|
||||
inline void SetThreadDriver(DriverIface *driver) noexcept { ThreadCtxDriver = driver; }
|
||||
#endif
|
||||
|
||||
|
||||
class PtrIntMap {
|
||||
|
||||
Reference in New Issue
Block a user