mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
update openal-soft
sync point: master-ac5d40e40a0155351fe1be4aab30017b6a13a859
This commit is contained in:
parent
762a84550f
commit
3603188b7f
365 changed files with 76053 additions and 53126 deletions
132
Engine/lib/openal-soft/router/al.cpp
Normal file
132
Engine/lib/openal-soft/router/al.cpp
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#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) \
|
||||
{ \
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
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) \
|
||||
{ \
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
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) \
|
||||
{ \
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
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) \
|
||||
{ \
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
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) \
|
||||
{ \
|
||||
DriverIface *iface = ThreadCtxDriver; \
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
|
||||
return iface->n(a, b, c, d, e); \
|
||||
}
|
||||
|
||||
|
||||
/* 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)
|
||||
{
|
||||
DriverIface *iface = ThreadCtxDriver;
|
||||
if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire);
|
||||
return iface ? iface->alGetError() : AL_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
DECL_THUNK1(void, alDopplerFactor, ALfloat)
|
||||
DECL_THUNK1(void, alDopplerVelocity, ALfloat)
|
||||
DECL_THUNK1(void, alSpeedOfSound, ALfloat)
|
||||
DECL_THUNK1(void, alDistanceModel, ALenum)
|
||||
|
||||
DECL_THUNK1(void, alEnable, ALenum)
|
||||
DECL_THUNK1(void, alDisable, ALenum)
|
||||
DECL_THUNK1(ALboolean, alIsEnabled, ALenum)
|
||||
|
||||
DECL_THUNK1(const ALchar*, alGetString, ALenum)
|
||||
DECL_THUNK2(void, alGetBooleanv, ALenum, ALboolean*)
|
||||
DECL_THUNK2(void, alGetIntegerv, ALenum, ALint*)
|
||||
DECL_THUNK2(void, alGetFloatv, ALenum, ALfloat*)
|
||||
DECL_THUNK2(void, alGetDoublev, ALenum, ALdouble*)
|
||||
DECL_THUNK1(ALboolean, alGetBoolean, ALenum)
|
||||
DECL_THUNK1(ALint, alGetInteger, ALenum)
|
||||
DECL_THUNK1(ALfloat, alGetFloat, ALenum)
|
||||
DECL_THUNK1(ALdouble, alGetDouble, ALenum)
|
||||
|
||||
DECL_THUNK1(ALboolean, alIsExtensionPresent, const ALchar*)
|
||||
DECL_THUNK1(void*, alGetProcAddress, const ALchar*)
|
||||
DECL_THUNK1(ALenum, alGetEnumValue, const ALchar*)
|
||||
|
||||
DECL_THUNK2(void, alListenerf, ALenum, ALfloat)
|
||||
DECL_THUNK4(void, alListener3f, ALenum, ALfloat, ALfloat, ALfloat)
|
||||
DECL_THUNK2(void, alListenerfv, ALenum, const ALfloat*)
|
||||
DECL_THUNK2(void, alListeneri, ALenum, ALint)
|
||||
DECL_THUNK4(void, alListener3i, ALenum, ALint, ALint, ALint)
|
||||
DECL_THUNK2(void, alListeneriv, ALenum, const ALint*)
|
||||
DECL_THUNK2(void, alGetListenerf, ALenum, ALfloat*)
|
||||
DECL_THUNK4(void, alGetListener3f, ALenum, ALfloat*, ALfloat*, ALfloat*)
|
||||
DECL_THUNK2(void, alGetListenerfv, ALenum, ALfloat*)
|
||||
DECL_THUNK2(void, alGetListeneri, ALenum, ALint*)
|
||||
DECL_THUNK4(void, alGetListener3i, ALenum, ALint*, ALint*, ALint*)
|
||||
DECL_THUNK2(void, alGetListeneriv, ALenum, ALint*)
|
||||
|
||||
DECL_THUNK2(void, alGenSources, ALsizei, ALuint*)
|
||||
DECL_THUNK2(void, alDeleteSources, ALsizei, const ALuint*)
|
||||
DECL_THUNK1(ALboolean, alIsSource, ALuint)
|
||||
DECL_THUNK3(void, alSourcef, ALuint, ALenum, ALfloat)
|
||||
DECL_THUNK5(void, alSource3f, ALuint, ALenum, ALfloat, ALfloat, ALfloat)
|
||||
DECL_THUNK3(void, alSourcefv, ALuint, ALenum, const ALfloat*)
|
||||
DECL_THUNK3(void, alSourcei, ALuint, ALenum, ALint)
|
||||
DECL_THUNK5(void, alSource3i, ALuint, ALenum, ALint, ALint, ALint)
|
||||
DECL_THUNK3(void, alSourceiv, ALuint, ALenum, const ALint*)
|
||||
DECL_THUNK3(void, alGetSourcef, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK5(void, alGetSource3f, ALuint, ALenum, ALfloat*, ALfloat*, ALfloat*)
|
||||
DECL_THUNK3(void, alGetSourcefv, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK3(void, alGetSourcei, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK5(void, alGetSource3i, ALuint, ALenum, ALint*, ALint*, ALint*)
|
||||
DECL_THUNK3(void, alGetSourceiv, ALuint, ALenum, ALint*)
|
||||
DECL_THUNK2(void, alSourcePlayv, ALsizei, const ALuint*)
|
||||
DECL_THUNK2(void, alSourceStopv, ALsizei, const ALuint*)
|
||||
DECL_THUNK2(void, alSourceRewindv, ALsizei, const ALuint*)
|
||||
DECL_THUNK2(void, alSourcePausev, ALsizei, const ALuint*)
|
||||
DECL_THUNK1(void, alSourcePlay, ALuint)
|
||||
DECL_THUNK1(void, alSourceStop, ALuint)
|
||||
DECL_THUNK1(void, alSourceRewind, ALuint)
|
||||
DECL_THUNK1(void, alSourcePause, ALuint)
|
||||
DECL_THUNK3(void, alSourceQueueBuffers, ALuint, ALsizei, const ALuint*)
|
||||
DECL_THUNK3(void, alSourceUnqueueBuffers, ALuint, ALsizei, ALuint*)
|
||||
|
||||
DECL_THUNK2(void, alGenBuffers, ALsizei, ALuint*)
|
||||
DECL_THUNK2(void, alDeleteBuffers, ALsizei, const ALuint*)
|
||||
DECL_THUNK1(ALboolean, alIsBuffer, ALuint)
|
||||
DECL_THUNK3(void, alBufferf, ALuint, ALenum, ALfloat)
|
||||
DECL_THUNK5(void, alBuffer3f, ALuint, ALenum, ALfloat, ALfloat, ALfloat)
|
||||
DECL_THUNK3(void, alBufferfv, ALuint, ALenum, const ALfloat*)
|
||||
DECL_THUNK3(void, alBufferi, ALuint, ALenum, ALint)
|
||||
DECL_THUNK5(void, alBuffer3i, ALuint, ALenum, ALint, ALint, ALint)
|
||||
DECL_THUNK3(void, alBufferiv, ALuint, ALenum, const ALint*)
|
||||
DECL_THUNK3(void, alGetBufferf, ALuint, ALenum, ALfloat*)
|
||||
DECL_THUNK5(void, alGetBuffer3f, ALuint, ALenum, ALfloat*, ALfloat*, ALfloat*)
|
||||
DECL_THUNK3(void, alGetBufferfv, ALuint, ALenum, ALfloat*)
|
||||
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)
|
||||
932
Engine/lib/openal-soft/router/alc.cpp
Normal file
932
Engine/lib/openal-soft/router/alc.cpp
Normal file
|
|
@ -0,0 +1,932 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include "AL/alc.h"
|
||||
#include "alstring.h"
|
||||
#include "router.h"
|
||||
|
||||
|
||||
#define DECL(x) { #x, reinterpret_cast<void*>(x) }
|
||||
struct FuncExportEntry {
|
||||
const char *funcName;
|
||||
void *address;
|
||||
};
|
||||
static const std::array<FuncExportEntry,95> alcFunctions{{
|
||||
DECL(alcCreateContext),
|
||||
DECL(alcMakeContextCurrent),
|
||||
DECL(alcProcessContext),
|
||||
DECL(alcSuspendContext),
|
||||
DECL(alcDestroyContext),
|
||||
DECL(alcGetCurrentContext),
|
||||
DECL(alcGetContextsDevice),
|
||||
DECL(alcOpenDevice),
|
||||
DECL(alcCloseDevice),
|
||||
DECL(alcGetError),
|
||||
DECL(alcIsExtensionPresent),
|
||||
DECL(alcGetProcAddress),
|
||||
DECL(alcGetEnumValue),
|
||||
DECL(alcGetString),
|
||||
DECL(alcGetIntegerv),
|
||||
DECL(alcCaptureOpenDevice),
|
||||
DECL(alcCaptureCloseDevice),
|
||||
DECL(alcCaptureStart),
|
||||
DECL(alcCaptureStop),
|
||||
DECL(alcCaptureSamples),
|
||||
|
||||
DECL(alcSetThreadContext),
|
||||
DECL(alcGetThreadContext),
|
||||
|
||||
DECL(alEnable),
|
||||
DECL(alDisable),
|
||||
DECL(alIsEnabled),
|
||||
DECL(alGetString),
|
||||
DECL(alGetBooleanv),
|
||||
DECL(alGetIntegerv),
|
||||
DECL(alGetFloatv),
|
||||
DECL(alGetDoublev),
|
||||
DECL(alGetBoolean),
|
||||
DECL(alGetInteger),
|
||||
DECL(alGetFloat),
|
||||
DECL(alGetDouble),
|
||||
DECL(alGetError),
|
||||
DECL(alIsExtensionPresent),
|
||||
DECL(alGetProcAddress),
|
||||
DECL(alGetEnumValue),
|
||||
DECL(alListenerf),
|
||||
DECL(alListener3f),
|
||||
DECL(alListenerfv),
|
||||
DECL(alListeneri),
|
||||
DECL(alListener3i),
|
||||
DECL(alListeneriv),
|
||||
DECL(alGetListenerf),
|
||||
DECL(alGetListener3f),
|
||||
DECL(alGetListenerfv),
|
||||
DECL(alGetListeneri),
|
||||
DECL(alGetListener3i),
|
||||
DECL(alGetListeneriv),
|
||||
DECL(alGenSources),
|
||||
DECL(alDeleteSources),
|
||||
DECL(alIsSource),
|
||||
DECL(alSourcef),
|
||||
DECL(alSource3f),
|
||||
DECL(alSourcefv),
|
||||
DECL(alSourcei),
|
||||
DECL(alSource3i),
|
||||
DECL(alSourceiv),
|
||||
DECL(alGetSourcef),
|
||||
DECL(alGetSource3f),
|
||||
DECL(alGetSourcefv),
|
||||
DECL(alGetSourcei),
|
||||
DECL(alGetSource3i),
|
||||
DECL(alGetSourceiv),
|
||||
DECL(alSourcePlayv),
|
||||
DECL(alSourceStopv),
|
||||
DECL(alSourceRewindv),
|
||||
DECL(alSourcePausev),
|
||||
DECL(alSourcePlay),
|
||||
DECL(alSourceStop),
|
||||
DECL(alSourceRewind),
|
||||
DECL(alSourcePause),
|
||||
DECL(alSourceQueueBuffers),
|
||||
DECL(alSourceUnqueueBuffers),
|
||||
DECL(alGenBuffers),
|
||||
DECL(alDeleteBuffers),
|
||||
DECL(alIsBuffer),
|
||||
DECL(alBufferData),
|
||||
DECL(alBufferf),
|
||||
DECL(alBuffer3f),
|
||||
DECL(alBufferfv),
|
||||
DECL(alBufferi),
|
||||
DECL(alBuffer3i),
|
||||
DECL(alBufferiv),
|
||||
DECL(alGetBufferf),
|
||||
DECL(alGetBuffer3f),
|
||||
DECL(alGetBufferfv),
|
||||
DECL(alGetBufferi),
|
||||
DECL(alGetBuffer3i),
|
||||
DECL(alGetBufferiv),
|
||||
DECL(alDopplerFactor),
|
||||
DECL(alDopplerVelocity),
|
||||
DECL(alSpeedOfSound),
|
||||
DECL(alDistanceModel),
|
||||
}};
|
||||
#undef DECL
|
||||
|
||||
#define DECL(x) { #x, (x) }
|
||||
struct EnumExportEntry {
|
||||
const ALCchar *enumName;
|
||||
ALCenum value;
|
||||
};
|
||||
static const std::array<EnumExportEntry,92> alcEnumerations{{
|
||||
DECL(ALC_INVALID),
|
||||
DECL(ALC_FALSE),
|
||||
DECL(ALC_TRUE),
|
||||
|
||||
DECL(ALC_MAJOR_VERSION),
|
||||
DECL(ALC_MINOR_VERSION),
|
||||
DECL(ALC_ATTRIBUTES_SIZE),
|
||||
DECL(ALC_ALL_ATTRIBUTES),
|
||||
DECL(ALC_DEFAULT_DEVICE_SPECIFIER),
|
||||
DECL(ALC_DEVICE_SPECIFIER),
|
||||
DECL(ALC_ALL_DEVICES_SPECIFIER),
|
||||
DECL(ALC_DEFAULT_ALL_DEVICES_SPECIFIER),
|
||||
DECL(ALC_EXTENSIONS),
|
||||
DECL(ALC_FREQUENCY),
|
||||
DECL(ALC_REFRESH),
|
||||
DECL(ALC_SYNC),
|
||||
DECL(ALC_MONO_SOURCES),
|
||||
DECL(ALC_STEREO_SOURCES),
|
||||
DECL(ALC_CAPTURE_DEVICE_SPECIFIER),
|
||||
DECL(ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER),
|
||||
DECL(ALC_CAPTURE_SAMPLES),
|
||||
|
||||
DECL(ALC_NO_ERROR),
|
||||
DECL(ALC_INVALID_DEVICE),
|
||||
DECL(ALC_INVALID_CONTEXT),
|
||||
DECL(ALC_INVALID_ENUM),
|
||||
DECL(ALC_INVALID_VALUE),
|
||||
DECL(ALC_OUT_OF_MEMORY),
|
||||
|
||||
DECL(AL_INVALID),
|
||||
DECL(AL_NONE),
|
||||
DECL(AL_FALSE),
|
||||
DECL(AL_TRUE),
|
||||
|
||||
DECL(AL_SOURCE_RELATIVE),
|
||||
DECL(AL_CONE_INNER_ANGLE),
|
||||
DECL(AL_CONE_OUTER_ANGLE),
|
||||
DECL(AL_PITCH),
|
||||
DECL(AL_POSITION),
|
||||
DECL(AL_DIRECTION),
|
||||
DECL(AL_VELOCITY),
|
||||
DECL(AL_LOOPING),
|
||||
DECL(AL_BUFFER),
|
||||
DECL(AL_GAIN),
|
||||
DECL(AL_MIN_GAIN),
|
||||
DECL(AL_MAX_GAIN),
|
||||
DECL(AL_ORIENTATION),
|
||||
DECL(AL_REFERENCE_DISTANCE),
|
||||
DECL(AL_ROLLOFF_FACTOR),
|
||||
DECL(AL_CONE_OUTER_GAIN),
|
||||
DECL(AL_MAX_DISTANCE),
|
||||
DECL(AL_SEC_OFFSET),
|
||||
DECL(AL_SAMPLE_OFFSET),
|
||||
DECL(AL_BYTE_OFFSET),
|
||||
DECL(AL_SOURCE_TYPE),
|
||||
DECL(AL_STATIC),
|
||||
DECL(AL_STREAMING),
|
||||
DECL(AL_UNDETERMINED),
|
||||
|
||||
DECL(AL_SOURCE_STATE),
|
||||
DECL(AL_INITIAL),
|
||||
DECL(AL_PLAYING),
|
||||
DECL(AL_PAUSED),
|
||||
DECL(AL_STOPPED),
|
||||
|
||||
DECL(AL_BUFFERS_QUEUED),
|
||||
DECL(AL_BUFFERS_PROCESSED),
|
||||
|
||||
DECL(AL_FORMAT_MONO8),
|
||||
DECL(AL_FORMAT_MONO16),
|
||||
DECL(AL_FORMAT_STEREO8),
|
||||
DECL(AL_FORMAT_STEREO16),
|
||||
|
||||
DECL(AL_FREQUENCY),
|
||||
DECL(AL_BITS),
|
||||
DECL(AL_CHANNELS),
|
||||
DECL(AL_SIZE),
|
||||
|
||||
DECL(AL_UNUSED),
|
||||
DECL(AL_PENDING),
|
||||
DECL(AL_PROCESSED),
|
||||
|
||||
DECL(AL_NO_ERROR),
|
||||
DECL(AL_INVALID_NAME),
|
||||
DECL(AL_INVALID_ENUM),
|
||||
DECL(AL_INVALID_VALUE),
|
||||
DECL(AL_INVALID_OPERATION),
|
||||
DECL(AL_OUT_OF_MEMORY),
|
||||
|
||||
DECL(AL_VENDOR),
|
||||
DECL(AL_VERSION),
|
||||
DECL(AL_RENDERER),
|
||||
DECL(AL_EXTENSIONS),
|
||||
|
||||
DECL(AL_DOPPLER_FACTOR),
|
||||
DECL(AL_DOPPLER_VELOCITY),
|
||||
DECL(AL_DISTANCE_MODEL),
|
||||
DECL(AL_SPEED_OF_SOUND),
|
||||
|
||||
DECL(AL_INVERSE_DISTANCE),
|
||||
DECL(AL_INVERSE_DISTANCE_CLAMPED),
|
||||
DECL(AL_LINEAR_DISTANCE),
|
||||
DECL(AL_LINEAR_DISTANCE_CLAMPED),
|
||||
DECL(AL_EXPONENT_DISTANCE),
|
||||
DECL(AL_EXPONENT_DISTANCE_CLAMPED),
|
||||
}};
|
||||
#undef DECL
|
||||
|
||||
static const ALCchar alcNoError[] = "No Error";
|
||||
static const ALCchar alcErrInvalidDevice[] = "Invalid Device";
|
||||
static const ALCchar alcErrInvalidContext[] = "Invalid Context";
|
||||
static const ALCchar alcErrInvalidEnum[] = "Invalid Enum";
|
||||
static const ALCchar alcErrInvalidValue[] = "Invalid Value";
|
||||
static const ALCchar alcErrOutOfMemory[] = "Out of Memory";
|
||||
static const ALCchar alcExtensionList[] =
|
||||
"ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
|
||||
"ALC_EXT_thread_local_context";
|
||||
|
||||
static const ALCint alcMajorVersion = 1;
|
||||
static const ALCint alcMinorVersion = 1;
|
||||
|
||||
|
||||
static std::recursive_mutex EnumerationLock;
|
||||
static std::mutex ContextSwitchLock;
|
||||
|
||||
static std::atomic<ALCenum> LastError{ALC_NO_ERROR};
|
||||
static PtrIntMap DeviceIfaceMap;
|
||||
static PtrIntMap ContextIfaceMap;
|
||||
|
||||
|
||||
typedef struct EnumeratedList {
|
||||
std::vector<ALCchar> Names;
|
||||
std::vector<ALCint> Indicies;
|
||||
|
||||
void clear()
|
||||
{
|
||||
Names.clear();
|
||||
Indicies.clear();
|
||||
}
|
||||
} EnumeratedList;
|
||||
static EnumeratedList DevicesList;
|
||||
static EnumeratedList AllDevicesList;
|
||||
static EnumeratedList CaptureDevicesList;
|
||||
|
||||
static void AppendDeviceList(EnumeratedList *list, const ALCchar *names, ALint idx)
|
||||
{
|
||||
const ALCchar *name_end = names;
|
||||
if(!name_end) return;
|
||||
|
||||
ALCsizei count = 0;
|
||||
while(*name_end)
|
||||
{
|
||||
TRACE("Enumerated \"%s\", driver %d\n", name_end, idx);
|
||||
++count;
|
||||
name_end += strlen(name_end)+1;
|
||||
}
|
||||
if(names == name_end)
|
||||
return;
|
||||
|
||||
list->Names.reserve(list->Names.size() + (name_end - names) + 1);
|
||||
list->Names.insert(list->Names.cend(), names, name_end);
|
||||
|
||||
list->Indicies.reserve(list->Indicies.size() + count);
|
||||
list->Indicies.insert(list->Indicies.cend(), count, idx);
|
||||
}
|
||||
|
||||
static ALint GetDriverIndexForName(const EnumeratedList *list, const ALCchar *name)
|
||||
{
|
||||
const ALCchar *devnames = list->Names.data();
|
||||
const ALCint *index = list->Indicies.data();
|
||||
|
||||
while(devnames && *devnames)
|
||||
{
|
||||
if(strcmp(name, devnames) == 0)
|
||||
return *index;
|
||||
devnames += strlen(devnames)+1;
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
|
||||
{
|
||||
ALCdevice *device = nullptr;
|
||||
ALint idx = 0;
|
||||
|
||||
/* Prior to the enumeration extension, apps would hardcode these names as a
|
||||
* quality hint for the wrapper driver. Ignore them since there's no sane
|
||||
* way to map them.
|
||||
*/
|
||||
if(devicename && (devicename[0] == '\0' ||
|
||||
strcmp(devicename, "DirectSound3D") == 0 ||
|
||||
strcmp(devicename, "DirectSound") == 0 ||
|
||||
strcmp(devicename, "MMSYSTEM") == 0))
|
||||
devicename = nullptr;
|
||||
if(devicename)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
if(DevicesList.Names.empty())
|
||||
(void)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&DevicesList, devicename);
|
||||
if(idx < 0)
|
||||
{
|
||||
if(AllDevicesList.Names.empty())
|
||||
(void)alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&AllDevicesList, devicename);
|
||||
}
|
||||
}
|
||||
|
||||
if(idx < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_VALUE);
|
||||
TRACE("Failed to find driver for name \"%s\"\n", devicename);
|
||||
return nullptr;
|
||||
}
|
||||
TRACE("Found driver %d for name \"%s\"\n", idx, 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"))
|
||||
{
|
||||
TRACE("Using default device from driver %d\n", idx);
|
||||
device = drv.alcOpenDevice(nullptr);
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
|
||||
if(device)
|
||||
{
|
||||
if(DeviceIfaceMap.insert(device, idx) != ALC_NO_ERROR)
|
||||
{
|
||||
DriverList[idx].alcCloseDevice(device);
|
||||
device = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
|
||||
{
|
||||
ALint idx;
|
||||
|
||||
if(!device || (idx=DeviceIfaceMap.lookupByKey(device)) < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
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)
|
||||
{
|
||||
ALCcontext *context;
|
||||
ALint idx;
|
||||
|
||||
if(!device || (idx=DeviceIfaceMap.lookupByKey(device)) < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return nullptr;
|
||||
}
|
||||
context = DriverList[idx].alcCreateContext(device, attrlist);
|
||||
if(context)
|
||||
{
|
||||
if(ContextIfaceMap.insert(context, idx) != ALC_NO_ERROR)
|
||||
{
|
||||
DriverList[idx].alcDestroyContext(context);
|
||||
context = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
{
|
||||
ALint idx = -1;
|
||||
|
||||
std::lock_guard<std::mutex> _{ContextSwitchLock};
|
||||
if(context)
|
||||
{
|
||||
idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
if(!DriverList[idx].alcMakeContextCurrent(context))
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
/* Unset the context from the old driver if it's different from the new
|
||||
* current one.
|
||||
*/
|
||||
if(idx < 0)
|
||||
{
|
||||
DriverIface *oldiface = ThreadCtxDriver;
|
||||
if(oldiface) oldiface->alcSetThreadContext(nullptr);
|
||||
oldiface = CurrentCtxDriver.exchange(nullptr);
|
||||
if(oldiface) oldiface->alcMakeContextCurrent(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
DriverIface *oldiface = ThreadCtxDriver;
|
||||
if(oldiface && oldiface != &DriverList[idx])
|
||||
oldiface->alcSetThreadContext(nullptr);
|
||||
oldiface = CurrentCtxDriver.exchange(&DriverList[idx]);
|
||||
if(oldiface && oldiface != &DriverList[idx])
|
||||
oldiface->alcMakeContextCurrent(nullptr);
|
||||
}
|
||||
ThreadCtxDriver = nullptr;
|
||||
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcProcessContext(ALCcontext *context)
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
ALint idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcProcessContext(context);
|
||||
}
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context)
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
ALint idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcSuspendContext(context);
|
||||
}
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context)
|
||||
{
|
||||
ALint idx;
|
||||
|
||||
if(!context || (idx=ContextIfaceMap.lookupByKey(context)) < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
return;
|
||||
}
|
||||
|
||||
DriverList[idx].alcDestroyContext(context);
|
||||
ContextIfaceMap.removeByKey(context);
|
||||
}
|
||||
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void)
|
||||
{
|
||||
DriverIface *iface = ThreadCtxDriver;
|
||||
if(!iface) iface = CurrentCtxDriver.load();
|
||||
return iface ? iface->alcGetCurrentContext() : nullptr;
|
||||
}
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *context)
|
||||
{
|
||||
if(context)
|
||||
{
|
||||
ALint idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcGetContextsDevice(context);
|
||||
}
|
||||
LastError.store(ALC_INVALID_CONTEXT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0) return ALC_INVALID_DEVICE;
|
||||
return DriverList[idx].alcGetError(device);
|
||||
}
|
||||
return LastError.exchange(ALC_NO_ERROR);
|
||||
}
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extname)
|
||||
{
|
||||
const char *ptr;
|
||||
size_t len;
|
||||
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
return DriverList[idx].alcIsExtensionPresent(device, extname);
|
||||
}
|
||||
|
||||
len = strlen(extname);
|
||||
ptr = alcExtensionList;
|
||||
while(ptr && *ptr)
|
||||
{
|
||||
if(al::strncasecmp(ptr, extname, len) == 0 && (ptr[len] == '\0' || isspace(ptr[len])))
|
||||
return ALC_TRUE;
|
||||
if((ptr=strchr(ptr, ' ')) != nullptr)
|
||||
{
|
||||
do {
|
||||
++ptr;
|
||||
} while(isspace(*ptr));
|
||||
}
|
||||
}
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcname)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return nullptr;
|
||||
}
|
||||
return DriverList[idx].alcGetProcAddress(device, funcname);
|
||||
}
|
||||
|
||||
auto iter = std::find_if(alcFunctions.cbegin(), alcFunctions.cend(),
|
||||
[funcname](const FuncExportEntry &entry) -> bool
|
||||
{ return strcmp(funcname, entry.funcName) == 0; }
|
||||
);
|
||||
return (iter != alcFunctions.cend()) ? iter->address : nullptr;
|
||||
}
|
||||
|
||||
ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return 0;
|
||||
}
|
||||
return DriverList[idx].alcGetEnumValue(device, enumname);
|
||||
}
|
||||
|
||||
auto iter = std::find_if(alcEnumerations.cbegin(), alcEnumerations.cend(),
|
||||
[enumname](const EnumExportEntry &entry) -> bool
|
||||
{ return strcmp(enumname, entry.enumName) == 0; }
|
||||
);
|
||||
return (iter != alcEnumerations.cend()) ? iter->value : 0;
|
||||
}
|
||||
|
||||
ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return nullptr;
|
||||
}
|
||||
return DriverList[idx].alcGetString(device, param);
|
||||
}
|
||||
|
||||
switch(param)
|
||||
{
|
||||
case ALC_NO_ERROR:
|
||||
return alcNoError;
|
||||
case ALC_INVALID_ENUM:
|
||||
return alcErrInvalidEnum;
|
||||
case ALC_INVALID_VALUE:
|
||||
return alcErrInvalidValue;
|
||||
case ALC_INVALID_DEVICE:
|
||||
return alcErrInvalidDevice;
|
||||
case ALC_INVALID_CONTEXT:
|
||||
return alcErrInvalidContext;
|
||||
case ALC_OUT_OF_MEMORY:
|
||||
return alcErrOutOfMemory;
|
||||
case ALC_EXTENSIONS:
|
||||
return alcExtensionList;
|
||||
|
||||
case ALC_DEVICE_SPECIFIER:
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{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"))
|
||||
AppendDeviceList(&DevicesList,
|
||||
drv.alcGetString(nullptr, ALC_DEVICE_SPECIFIER), idx);
|
||||
++idx;
|
||||
}
|
||||
/* Ensure the list is double-null termianted. */
|
||||
if(DevicesList.Names.empty())
|
||||
DevicesList.Names.emplace_back('\0');
|
||||
DevicesList.Names.emplace_back('\0');
|
||||
return DevicesList.Names.data();
|
||||
}
|
||||
|
||||
case ALC_ALL_DEVICES_SPECIFIER:
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
AllDevicesList.clear();
|
||||
ALint idx{0};
|
||||
for(const auto &drv : DriverList)
|
||||
{
|
||||
/* If the driver doesn't support ALC_ENUMERATE_ALL_EXT, substitute
|
||||
* standard enumeration.
|
||||
*/
|
||||
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"))
|
||||
AppendDeviceList(&AllDevicesList,
|
||||
drv.alcGetString(nullptr, ALC_DEVICE_SPECIFIER), idx);
|
||||
++idx;
|
||||
}
|
||||
/* Ensure the list is double-null termianted. */
|
||||
if(AllDevicesList.Names.empty())
|
||||
AllDevicesList.Names.emplace_back('\0');
|
||||
AllDevicesList.Names.emplace_back('\0');
|
||||
return AllDevicesList.Names.data();
|
||||
}
|
||||
|
||||
case ALC_CAPTURE_DEVICE_SPECIFIER:
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{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"))
|
||||
AppendDeviceList(&CaptureDevicesList,
|
||||
drv.alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER), idx);
|
||||
++idx;
|
||||
}
|
||||
/* Ensure the list is double-null termianted. */
|
||||
if(CaptureDevicesList.Names.empty())
|
||||
CaptureDevicesList.Names.emplace_back('\0');
|
||||
CaptureDevicesList.Names.emplace_back('\0');
|
||||
return CaptureDevicesList.Names.data();
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
return "";
|
||||
}
|
||||
|
||||
default:
|
||||
LastError.store(ALC_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return;
|
||||
}
|
||||
return DriverList[idx].alcGetIntegerv(device, param, size, values);
|
||||
}
|
||||
|
||||
if(size <= 0 || values == nullptr)
|
||||
{
|
||||
LastError.store(ALC_INVALID_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(param)
|
||||
{
|
||||
case ALC_MAJOR_VERSION:
|
||||
if(size >= 1)
|
||||
{
|
||||
values[0] = alcMajorVersion;
|
||||
return;
|
||||
}
|
||||
/*fall-through*/
|
||||
case ALC_MINOR_VERSION:
|
||||
if(size >= 1)
|
||||
{
|
||||
values[0] = alcMinorVersion;
|
||||
return;
|
||||
}
|
||||
LastError.store(ALC_INVALID_VALUE);
|
||||
return;
|
||||
|
||||
case ALC_ATTRIBUTES_SIZE:
|
||||
case ALC_ALL_ATTRIBUTES:
|
||||
case ALC_FREQUENCY:
|
||||
case ALC_REFRESH:
|
||||
case ALC_SYNC:
|
||||
case ALC_MONO_SOURCES:
|
||||
case ALC_STEREO_SOURCES:
|
||||
case ALC_CAPTURE_SAMPLES:
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return;
|
||||
|
||||
default:
|
||||
LastError.store(ALC_INVALID_ENUM);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize)
|
||||
{
|
||||
ALCdevice *device = nullptr;
|
||||
ALint idx = 0;
|
||||
|
||||
if(devicename && devicename[0] == '\0')
|
||||
devicename = nullptr;
|
||||
if(devicename)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> _{EnumerationLock};
|
||||
if(CaptureDevicesList.Names.empty())
|
||||
(void)alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
idx = GetDriverIndexForName(&CaptureDevicesList, devicename);
|
||||
}
|
||||
|
||||
if(idx < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_VALUE);
|
||||
TRACE("Failed to find driver for name \"%s\"\n", devicename);
|
||||
return nullptr;
|
||||
}
|
||||
TRACE("Found driver %d for name \"%s\"\n", idx, devicename);
|
||||
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"))
|
||||
{
|
||||
TRACE("Using default capture device from driver %d\n", idx);
|
||||
device = drv.alcCaptureOpenDevice(nullptr, frequency, format, buffersize);
|
||||
break;
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
|
||||
if(device)
|
||||
{
|
||||
if(DeviceIfaceMap.insert(device, idx) != ALC_NO_ERROR)
|
||||
{
|
||||
DriverList[idx].alcCaptureCloseDevice(device);
|
||||
device = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device)
|
||||
{
|
||||
ALint idx;
|
||||
|
||||
if(!device || (idx=DeviceIfaceMap.lookupByKey(device)) < 0)
|
||||
{
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
if(!DriverList[idx].alcCaptureCloseDevice(device))
|
||||
return ALC_FALSE;
|
||||
DeviceIfaceMap.removeByKey(device);
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcCaptureStart(device);
|
||||
}
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcCaptureStop(device);
|
||||
}
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
|
||||
{
|
||||
if(device)
|
||||
{
|
||||
ALint idx = DeviceIfaceMap.lookupByKey(device);
|
||||
if(idx >= 0)
|
||||
return DriverList[idx].alcCaptureSamples(device, buffer, samples);
|
||||
}
|
||||
LastError.store(ALC_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
|
||||
ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
|
||||
{
|
||||
ALCenum err = ALC_INVALID_CONTEXT;
|
||||
ALint idx;
|
||||
|
||||
if(!context)
|
||||
{
|
||||
DriverIface *oldiface = ThreadCtxDriver;
|
||||
if(oldiface && !oldiface->alcSetThreadContext(nullptr))
|
||||
return ALC_FALSE;
|
||||
ThreadCtxDriver = nullptr;
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
idx = ContextIfaceMap.lookupByKey(context);
|
||||
if(idx >= 0)
|
||||
{
|
||||
if(DriverList[idx].alcSetThreadContext(context))
|
||||
{
|
||||
DriverIface *oldiface = ThreadCtxDriver;
|
||||
if(oldiface != &DriverList[idx])
|
||||
{
|
||||
ThreadCtxDriver = &DriverList[idx];
|
||||
if(oldiface) oldiface->alcSetThreadContext(nullptr);
|
||||
}
|
||||
return ALC_TRUE;
|
||||
}
|
||||
err = DriverList[idx].alcGetError(nullptr);
|
||||
}
|
||||
LastError.store(err);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
|
||||
{
|
||||
DriverIface *iface = ThreadCtxDriver;
|
||||
if(iface) return iface->alcGetThreadContext();
|
||||
return nullptr;
|
||||
}
|
||||
439
Engine/lib/openal-soft/router/router.cpp
Normal file
439
Engine/lib/openal-soft/router/router.cpp
Normal file
|
|
@ -0,0 +1,439 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include "router.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "AL/alc.h"
|
||||
#include "AL/al.h"
|
||||
|
||||
#include "almalloc.h"
|
||||
#include "strutils.h"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
|
||||
std::vector<DriverIface> DriverList;
|
||||
|
||||
thread_local DriverIface *ThreadCtxDriver;
|
||||
|
||||
enum LogLevel LogLevel = LogLevel_Error;
|
||||
FILE *LogFile;
|
||||
|
||||
static void LoadDriverList(void);
|
||||
|
||||
|
||||
BOOL APIENTRY DllMain(HINSTANCE, DWORD reason, void*)
|
||||
{
|
||||
switch(reason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
LogFile = stderr;
|
||||
if(auto logfname = al::getenv("ALROUTER_LOGFILE"))
|
||||
{
|
||||
FILE *f = fopen(logfname->c_str(), "w");
|
||||
if(f == nullptr)
|
||||
ERR("Could not open log file: %s\n", logfname->c_str());
|
||||
else
|
||||
LogFile = f;
|
||||
}
|
||||
if(auto loglev = al::getenv("ALROUTER_LOGLEVEL"))
|
||||
{
|
||||
char *end = nullptr;
|
||||
long l = strtol(loglev->c_str(), &end, 0);
|
||||
if(!end || *end != '\0')
|
||||
ERR("Invalid log level value: %s\n", loglev->c_str());
|
||||
else if(l < LogLevel_None || l > LogLevel_Trace)
|
||||
ERR("Log level out of range: %s\n", loglev->c_str());
|
||||
else
|
||||
LogLevel = static_cast<enum LogLevel>(l);
|
||||
}
|
||||
TRACE("Initializing router v0.1-%s %s\n", ALSOFT_GIT_COMMIT_HASH, ALSOFT_GIT_BRANCH);
|
||||
LoadDriverList();
|
||||
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
DriverList.clear();
|
||||
|
||||
if(LogFile && LogFile != stderr)
|
||||
fclose(LogFile);
|
||||
LogFile = nullptr;
|
||||
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void AddModule(HMODULE module, const WCHAR *name)
|
||||
{
|
||||
for(auto &drv : DriverList)
|
||||
{
|
||||
if(drv.Module == module)
|
||||
{
|
||||
TRACE("Skipping already-loaded module %p\n", decltype(std::declval<void*>()){module});
|
||||
FreeLibrary(module);
|
||||
return;
|
||||
}
|
||||
if(drv.Name == name)
|
||||
{
|
||||
TRACE("Skipping similarly-named module %ls\n", name);
|
||||
FreeLibrary(module);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DriverList.emplace_back(name, module);
|
||||
DriverIface &newdrv = DriverList.back();
|
||||
|
||||
/* Load required functions. */
|
||||
int err = 0;
|
||||
#define LOAD_PROC(x) do { \
|
||||
newdrv.x = reinterpret_cast<decltype(newdrv.x)>(reinterpret_cast<void*>( \
|
||||
GetProcAddress(module, #x))); \
|
||||
if(!newdrv.x) \
|
||||
{ \
|
||||
ERR("Failed to find entry point for %s in %ls\n", #x, name); \
|
||||
err = 1; \
|
||||
} \
|
||||
} while(0)
|
||||
LOAD_PROC(alcCreateContext);
|
||||
LOAD_PROC(alcMakeContextCurrent);
|
||||
LOAD_PROC(alcProcessContext);
|
||||
LOAD_PROC(alcSuspendContext);
|
||||
LOAD_PROC(alcDestroyContext);
|
||||
LOAD_PROC(alcGetCurrentContext);
|
||||
LOAD_PROC(alcGetContextsDevice);
|
||||
LOAD_PROC(alcOpenDevice);
|
||||
LOAD_PROC(alcCloseDevice);
|
||||
LOAD_PROC(alcGetError);
|
||||
LOAD_PROC(alcIsExtensionPresent);
|
||||
LOAD_PROC(alcGetProcAddress);
|
||||
LOAD_PROC(alcGetEnumValue);
|
||||
LOAD_PROC(alcGetString);
|
||||
LOAD_PROC(alcGetIntegerv);
|
||||
LOAD_PROC(alcCaptureOpenDevice);
|
||||
LOAD_PROC(alcCaptureCloseDevice);
|
||||
LOAD_PROC(alcCaptureStart);
|
||||
LOAD_PROC(alcCaptureStop);
|
||||
LOAD_PROC(alcCaptureSamples);
|
||||
|
||||
LOAD_PROC(alEnable);
|
||||
LOAD_PROC(alDisable);
|
||||
LOAD_PROC(alIsEnabled);
|
||||
LOAD_PROC(alGetString);
|
||||
LOAD_PROC(alGetBooleanv);
|
||||
LOAD_PROC(alGetIntegerv);
|
||||
LOAD_PROC(alGetFloatv);
|
||||
LOAD_PROC(alGetDoublev);
|
||||
LOAD_PROC(alGetBoolean);
|
||||
LOAD_PROC(alGetInteger);
|
||||
LOAD_PROC(alGetFloat);
|
||||
LOAD_PROC(alGetDouble);
|
||||
LOAD_PROC(alGetError);
|
||||
LOAD_PROC(alIsExtensionPresent);
|
||||
LOAD_PROC(alGetProcAddress);
|
||||
LOAD_PROC(alGetEnumValue);
|
||||
LOAD_PROC(alListenerf);
|
||||
LOAD_PROC(alListener3f);
|
||||
LOAD_PROC(alListenerfv);
|
||||
LOAD_PROC(alListeneri);
|
||||
LOAD_PROC(alListener3i);
|
||||
LOAD_PROC(alListeneriv);
|
||||
LOAD_PROC(alGetListenerf);
|
||||
LOAD_PROC(alGetListener3f);
|
||||
LOAD_PROC(alGetListenerfv);
|
||||
LOAD_PROC(alGetListeneri);
|
||||
LOAD_PROC(alGetListener3i);
|
||||
LOAD_PROC(alGetListeneriv);
|
||||
LOAD_PROC(alGenSources);
|
||||
LOAD_PROC(alDeleteSources);
|
||||
LOAD_PROC(alIsSource);
|
||||
LOAD_PROC(alSourcef);
|
||||
LOAD_PROC(alSource3f);
|
||||
LOAD_PROC(alSourcefv);
|
||||
LOAD_PROC(alSourcei);
|
||||
LOAD_PROC(alSource3i);
|
||||
LOAD_PROC(alSourceiv);
|
||||
LOAD_PROC(alGetSourcef);
|
||||
LOAD_PROC(alGetSource3f);
|
||||
LOAD_PROC(alGetSourcefv);
|
||||
LOAD_PROC(alGetSourcei);
|
||||
LOAD_PROC(alGetSource3i);
|
||||
LOAD_PROC(alGetSourceiv);
|
||||
LOAD_PROC(alSourcePlayv);
|
||||
LOAD_PROC(alSourceStopv);
|
||||
LOAD_PROC(alSourceRewindv);
|
||||
LOAD_PROC(alSourcePausev);
|
||||
LOAD_PROC(alSourcePlay);
|
||||
LOAD_PROC(alSourceStop);
|
||||
LOAD_PROC(alSourceRewind);
|
||||
LOAD_PROC(alSourcePause);
|
||||
LOAD_PROC(alSourceQueueBuffers);
|
||||
LOAD_PROC(alSourceUnqueueBuffers);
|
||||
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);
|
||||
LOAD_PROC(alSpeedOfSound);
|
||||
LOAD_PROC(alDistanceModel);
|
||||
if(!err)
|
||||
{
|
||||
ALCint alc_ver[2] = { 0, 0 };
|
||||
newdrv.alcGetIntegerv(nullptr, ALC_MAJOR_VERSION, 1, &alc_ver[0]);
|
||||
newdrv.alcGetIntegerv(nullptr, ALC_MINOR_VERSION, 1, &alc_ver[1]);
|
||||
if(newdrv.alcGetError(nullptr) == ALC_NO_ERROR)
|
||||
newdrv.ALCVer = MAKE_ALC_VER(alc_ver[0], alc_ver[1]);
|
||||
else
|
||||
newdrv.ALCVer = MAKE_ALC_VER(1, 0);
|
||||
|
||||
#undef LOAD_PROC
|
||||
#define LOAD_PROC(x) do { \
|
||||
newdrv.x = reinterpret_cast<decltype(newdrv.x)>( \
|
||||
newdrv.alcGetProcAddress(nullptr, #x)); \
|
||||
if(!newdrv.x) \
|
||||
{ \
|
||||
ERR("Failed to find entry point for %s in %ls\n", #x, name); \
|
||||
err = 1; \
|
||||
} \
|
||||
} while(0)
|
||||
if(newdrv.alcIsExtensionPresent(nullptr, "ALC_EXT_thread_local_context"))
|
||||
{
|
||||
LOAD_PROC(alcSetThreadContext);
|
||||
LOAD_PROC(alcGetThreadContext);
|
||||
}
|
||||
}
|
||||
|
||||
if(err)
|
||||
{
|
||||
DriverList.pop_back();
|
||||
return;
|
||||
}
|
||||
TRACE("Loaded module %p, %ls, ALC %d.%d\n", decltype(std::declval<void*>()){module}, name,
|
||||
newdrv.ALCVer>>8, newdrv.ALCVer&255);
|
||||
#undef LOAD_PROC
|
||||
}
|
||||
|
||||
static void SearchDrivers(WCHAR *path)
|
||||
{
|
||||
WIN32_FIND_DATAW fdata;
|
||||
|
||||
TRACE("Searching for drivers in %ls...\n", path);
|
||||
std::wstring srchPath = path;
|
||||
srchPath += L"\\*oal.dll";
|
||||
|
||||
HANDLE srchHdl = FindFirstFileW(srchPath.c_str(), &fdata);
|
||||
if(srchHdl != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
do {
|
||||
HMODULE mod;
|
||||
|
||||
srchPath = path;
|
||||
srchPath += L"\\";
|
||||
srchPath += fdata.cFileName;
|
||||
TRACE("Found %ls\n", srchPath.c_str());
|
||||
|
||||
mod = LoadLibraryW(srchPath.c_str());
|
||||
if(!mod)
|
||||
WARN("Could not load %ls\n", srchPath.c_str());
|
||||
else
|
||||
AddModule(mod, fdata.cFileName);
|
||||
} while(FindNextFileW(srchHdl, &fdata));
|
||||
FindClose(srchHdl);
|
||||
}
|
||||
}
|
||||
|
||||
static WCHAR *strrchrW(WCHAR *str, WCHAR ch)
|
||||
{
|
||||
WCHAR *res = nullptr;
|
||||
while(str && *str != '\0')
|
||||
{
|
||||
if(*str == ch)
|
||||
res = str;
|
||||
++str;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int GetLoadedModuleDirectory(const WCHAR *name, WCHAR *moddir, DWORD length)
|
||||
{
|
||||
HMODULE module = nullptr;
|
||||
WCHAR *sep0, *sep1;
|
||||
|
||||
if(name)
|
||||
{
|
||||
module = GetModuleHandleW(name);
|
||||
if(!module) return 0;
|
||||
}
|
||||
|
||||
if(GetModuleFileNameW(module, moddir, length) == 0)
|
||||
return 0;
|
||||
|
||||
sep0 = strrchrW(moddir, '/');
|
||||
if(sep0) sep1 = strrchrW(sep0+1, '\\');
|
||||
else sep1 = strrchrW(moddir, '\\');
|
||||
|
||||
if(sep1) *sep1 = '\0';
|
||||
else if(sep0) *sep0 = '\0';
|
||||
else *moddir = '\0';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void LoadDriverList(void)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
|
||||
if(GetLoadedModuleDirectory(nullptr, proc_path, MAX_PATH))
|
||||
TRACE("Got proc path %ls\n", proc_path);
|
||||
|
||||
GetSystemDirectoryW(sys_path, MAX_PATH);
|
||||
len = lstrlenW(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);
|
||||
|
||||
/* Don't search the DLL's path if it is the same as the current working
|
||||
* directory, app's path, or system path (don't want to do duplicate
|
||||
* searches, or increase the priority of the app or system path).
|
||||
*/
|
||||
if(dll_path[0] &&
|
||||
(!cwd_path[0] || wcscmp(dll_path, cwd_path) != 0) &&
|
||||
(!proc_path[0] || wcscmp(dll_path, proc_path) != 0) &&
|
||||
(!sys_path[0] || wcscmp(dll_path, sys_path) != 0))
|
||||
SearchDrivers(dll_path);
|
||||
if(cwd_path[0] &&
|
||||
(!proc_path[0] || wcscmp(cwd_path, proc_path) != 0) &&
|
||||
(!sys_path[0] || wcscmp(cwd_path, sys_path) != 0))
|
||||
SearchDrivers(cwd_path);
|
||||
if(proc_path[0] && (!sys_path[0] || wcscmp(proc_path, sys_path) != 0))
|
||||
SearchDrivers(proc_path);
|
||||
if(sys_path[0])
|
||||
SearchDrivers(sys_path);
|
||||
}
|
||||
|
||||
|
||||
PtrIntMap::~PtrIntMap()
|
||||
{
|
||||
std::lock_guard<std::mutex> maplock{mLock};
|
||||
al_free(mKeys);
|
||||
mKeys = nullptr;
|
||||
mValues = nullptr;
|
||||
mSize = 0;
|
||||
mCapacity = 0;
|
||||
}
|
||||
|
||||
ALenum PtrIntMap::insert(void *key, int value)
|
||||
{
|
||||
std::lock_guard<std::mutex> maplock{mLock};
|
||||
auto iter = std::lower_bound(mKeys, mKeys+mSize, key);
|
||||
auto pos = static_cast<ALsizei>(std::distance(mKeys, iter));
|
||||
|
||||
if(pos == mSize || mKeys[pos] != key)
|
||||
{
|
||||
if(mSize == mCapacity)
|
||||
{
|
||||
void **newkeys{nullptr};
|
||||
ALsizei newcap{mCapacity ? (mCapacity<<1) : 4};
|
||||
if(newcap > mCapacity)
|
||||
newkeys = static_cast<void**>(
|
||||
al_calloc(16, (sizeof(mKeys[0])+sizeof(mValues[0]))*newcap)
|
||||
);
|
||||
if(!newkeys)
|
||||
return AL_OUT_OF_MEMORY;
|
||||
auto newvalues = reinterpret_cast<int*>(&newkeys[newcap]);
|
||||
|
||||
if(mKeys)
|
||||
{
|
||||
std::copy_n(mKeys, mSize, newkeys);
|
||||
std::copy_n(mValues, mSize, newvalues);
|
||||
}
|
||||
al_free(mKeys);
|
||||
mKeys = newkeys;
|
||||
mValues = newvalues;
|
||||
mCapacity = newcap;
|
||||
}
|
||||
|
||||
if(pos < mSize)
|
||||
{
|
||||
std::copy_backward(mKeys+pos, mKeys+mSize, mKeys+mSize+1);
|
||||
std::copy_backward(mValues+pos, mValues+mSize, mValues+mSize+1);
|
||||
}
|
||||
mSize++;
|
||||
}
|
||||
mKeys[pos] = key;
|
||||
mValues[pos] = value;
|
||||
|
||||
return AL_NO_ERROR;
|
||||
}
|
||||
|
||||
int PtrIntMap::removeByKey(void *key)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
std::lock_guard<std::mutex> maplock{mLock};
|
||||
auto iter = std::lower_bound(mKeys, mKeys+mSize, key);
|
||||
auto pos = static_cast<ALsizei>(std::distance(mKeys, iter));
|
||||
if(pos < mSize && mKeys[pos] == key)
|
||||
{
|
||||
ret = mValues[pos];
|
||||
if(pos+1 < mSize)
|
||||
{
|
||||
std::copy(mKeys+pos+1, mKeys+mSize, mKeys+pos);
|
||||
std::copy(mValues+pos+1, mValues+mSize, mValues+pos);
|
||||
}
|
||||
mSize--;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int PtrIntMap::lookupByKey(void *key)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
std::lock_guard<std::mutex> maplock{mLock};
|
||||
auto iter = std::lower_bound(mKeys, mKeys+mSize, key);
|
||||
auto pos = static_cast<ALsizei>(std::distance(mKeys, iter));
|
||||
if(pos < mSize && mKeys[pos] == key)
|
||||
ret = mValues[pos];
|
||||
|
||||
return ret;
|
||||
}
|
||||
192
Engine/lib/openal-soft/router/router.h
Normal file
192
Engine/lib/openal-soft/router/router.h
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
#ifndef ROUTER_ROUTER_H
|
||||
#define ROUTER_ROUTER_H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <winnt.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
#include "AL/alc.h"
|
||||
#include "AL/al.h"
|
||||
#include "AL/alext.h"
|
||||
|
||||
|
||||
#define MAKE_ALC_VER(major, minor) (((major)<<8) | (minor))
|
||||
|
||||
struct DriverIface {
|
||||
std::wstring Name;
|
||||
HMODULE Module{nullptr};
|
||||
int ALCVer{0};
|
||||
|
||||
LPALCCREATECONTEXT alcCreateContext{nullptr};
|
||||
LPALCMAKECONTEXTCURRENT alcMakeContextCurrent{nullptr};
|
||||
LPALCPROCESSCONTEXT alcProcessContext{nullptr};
|
||||
LPALCSUSPENDCONTEXT alcSuspendContext{nullptr};
|
||||
LPALCDESTROYCONTEXT alcDestroyContext{nullptr};
|
||||
LPALCGETCURRENTCONTEXT alcGetCurrentContext{nullptr};
|
||||
LPALCGETCONTEXTSDEVICE alcGetContextsDevice{nullptr};
|
||||
LPALCOPENDEVICE alcOpenDevice{nullptr};
|
||||
LPALCCLOSEDEVICE alcCloseDevice{nullptr};
|
||||
LPALCGETERROR alcGetError{nullptr};
|
||||
LPALCISEXTENSIONPRESENT alcIsExtensionPresent{nullptr};
|
||||
LPALCGETPROCADDRESS alcGetProcAddress{nullptr};
|
||||
LPALCGETENUMVALUE alcGetEnumValue{nullptr};
|
||||
LPALCGETSTRING alcGetString{nullptr};
|
||||
LPALCGETINTEGERV alcGetIntegerv{nullptr};
|
||||
LPALCCAPTUREOPENDEVICE alcCaptureOpenDevice{nullptr};
|
||||
LPALCCAPTURECLOSEDEVICE alcCaptureCloseDevice{nullptr};
|
||||
LPALCCAPTURESTART alcCaptureStart{nullptr};
|
||||
LPALCCAPTURESTOP alcCaptureStop{nullptr};
|
||||
LPALCCAPTURESAMPLES alcCaptureSamples{nullptr};
|
||||
|
||||
PFNALCSETTHREADCONTEXTPROC alcSetThreadContext{nullptr};
|
||||
PFNALCGETTHREADCONTEXTPROC alcGetThreadContext{nullptr};
|
||||
|
||||
LPALENABLE alEnable{nullptr};
|
||||
LPALDISABLE alDisable{nullptr};
|
||||
LPALISENABLED alIsEnabled{nullptr};
|
||||
LPALGETSTRING alGetString{nullptr};
|
||||
LPALGETBOOLEANV alGetBooleanv{nullptr};
|
||||
LPALGETINTEGERV alGetIntegerv{nullptr};
|
||||
LPALGETFLOATV alGetFloatv{nullptr};
|
||||
LPALGETDOUBLEV alGetDoublev{nullptr};
|
||||
LPALGETBOOLEAN alGetBoolean{nullptr};
|
||||
LPALGETINTEGER alGetInteger{nullptr};
|
||||
LPALGETFLOAT alGetFloat{nullptr};
|
||||
LPALGETDOUBLE alGetDouble{nullptr};
|
||||
LPALGETERROR alGetError{nullptr};
|
||||
LPALISEXTENSIONPRESENT alIsExtensionPresent{nullptr};
|
||||
LPALGETPROCADDRESS alGetProcAddress{nullptr};
|
||||
LPALGETENUMVALUE alGetEnumValue{nullptr};
|
||||
LPALLISTENERF alListenerf{nullptr};
|
||||
LPALLISTENER3F alListener3f{nullptr};
|
||||
LPALLISTENERFV alListenerfv{nullptr};
|
||||
LPALLISTENERI alListeneri{nullptr};
|
||||
LPALLISTENER3I alListener3i{nullptr};
|
||||
LPALLISTENERIV alListeneriv{nullptr};
|
||||
LPALGETLISTENERF alGetListenerf{nullptr};
|
||||
LPALGETLISTENER3F alGetListener3f{nullptr};
|
||||
LPALGETLISTENERFV alGetListenerfv{nullptr};
|
||||
LPALGETLISTENERI alGetListeneri{nullptr};
|
||||
LPALGETLISTENER3I alGetListener3i{nullptr};
|
||||
LPALGETLISTENERIV alGetListeneriv{nullptr};
|
||||
LPALGENSOURCES alGenSources{nullptr};
|
||||
LPALDELETESOURCES alDeleteSources{nullptr};
|
||||
LPALISSOURCE alIsSource{nullptr};
|
||||
LPALSOURCEF alSourcef{nullptr};
|
||||
LPALSOURCE3F alSource3f{nullptr};
|
||||
LPALSOURCEFV alSourcefv{nullptr};
|
||||
LPALSOURCEI alSourcei{nullptr};
|
||||
LPALSOURCE3I alSource3i{nullptr};
|
||||
LPALSOURCEIV alSourceiv{nullptr};
|
||||
LPALGETSOURCEF alGetSourcef{nullptr};
|
||||
LPALGETSOURCE3F alGetSource3f{nullptr};
|
||||
LPALGETSOURCEFV alGetSourcefv{nullptr};
|
||||
LPALGETSOURCEI alGetSourcei{nullptr};
|
||||
LPALGETSOURCE3I alGetSource3i{nullptr};
|
||||
LPALGETSOURCEIV alGetSourceiv{nullptr};
|
||||
LPALSOURCEPLAYV alSourcePlayv{nullptr};
|
||||
LPALSOURCESTOPV alSourceStopv{nullptr};
|
||||
LPALSOURCEREWINDV alSourceRewindv{nullptr};
|
||||
LPALSOURCEPAUSEV alSourcePausev{nullptr};
|
||||
LPALSOURCEPLAY alSourcePlay{nullptr};
|
||||
LPALSOURCESTOP alSourceStop{nullptr};
|
||||
LPALSOURCEREWIND alSourceRewind{nullptr};
|
||||
LPALSOURCEPAUSE alSourcePause{nullptr};
|
||||
LPALSOURCEQUEUEBUFFERS alSourceQueueBuffers{nullptr};
|
||||
LPALSOURCEUNQUEUEBUFFERS alSourceUnqueueBuffers{nullptr};
|
||||
LPALGENBUFFERS alGenBuffers{nullptr};
|
||||
LPALDELETEBUFFERS alDeleteBuffers{nullptr};
|
||||
LPALISBUFFER alIsBuffer{nullptr};
|
||||
LPALBUFFERF alBufferf{nullptr};
|
||||
LPALBUFFER3F alBuffer3f{nullptr};
|
||||
LPALBUFFERFV alBufferfv{nullptr};
|
||||
LPALBUFFERI alBufferi{nullptr};
|
||||
LPALBUFFER3I alBuffer3i{nullptr};
|
||||
LPALBUFFERIV alBufferiv{nullptr};
|
||||
LPALGETBUFFERF alGetBufferf{nullptr};
|
||||
LPALGETBUFFER3F alGetBuffer3f{nullptr};
|
||||
LPALGETBUFFERFV alGetBufferfv{nullptr};
|
||||
LPALGETBUFFERI alGetBufferi{nullptr};
|
||||
LPALGETBUFFER3I alGetBuffer3i{nullptr};
|
||||
LPALGETBUFFERIV alGetBufferiv{nullptr};
|
||||
LPALBUFFERDATA alBufferData{nullptr};
|
||||
LPALDOPPLERFACTOR alDopplerFactor{nullptr};
|
||||
LPALDOPPLERVELOCITY alDopplerVelocity{nullptr};
|
||||
LPALSPEEDOFSOUND alSpeedOfSound{nullptr};
|
||||
LPALDISTANCEMODEL alDistanceModel{nullptr};
|
||||
|
||||
DriverIface(std::wstring name, HMODULE mod)
|
||||
: Name(std::move(name)), Module(mod)
|
||||
{ }
|
||||
~DriverIface()
|
||||
{
|
||||
if(Module)
|
||||
FreeLibrary(Module);
|
||||
Module = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
extern std::vector<DriverIface> DriverList;
|
||||
|
||||
extern thread_local DriverIface *ThreadCtxDriver;
|
||||
extern std::atomic<DriverIface*> CurrentCtxDriver;
|
||||
|
||||
|
||||
class PtrIntMap {
|
||||
void **mKeys{nullptr};
|
||||
/* Shares memory with keys. */
|
||||
int *mValues{nullptr};
|
||||
|
||||
ALsizei mSize{0};
|
||||
ALsizei mCapacity{0};
|
||||
std::mutex mLock;
|
||||
|
||||
public:
|
||||
PtrIntMap() = default;
|
||||
~PtrIntMap();
|
||||
|
||||
ALenum insert(void *key, int value);
|
||||
int removeByKey(void *key);
|
||||
int lookupByKey(void *key);
|
||||
};
|
||||
|
||||
|
||||
enum LogLevel {
|
||||
LogLevel_None = 0,
|
||||
LogLevel_Error = 1,
|
||||
LogLevel_Warn = 2,
|
||||
LogLevel_Trace = 3,
|
||||
};
|
||||
extern enum LogLevel LogLevel;
|
||||
extern FILE *LogFile;
|
||||
|
||||
#define TRACE(...) do { \
|
||||
if(LogLevel >= LogLevel_Trace) \
|
||||
{ \
|
||||
fprintf(LogFile, "AL Router (II): " __VA_ARGS__); \
|
||||
fflush(LogFile); \
|
||||
} \
|
||||
} while(0)
|
||||
#define WARN(...) do { \
|
||||
if(LogLevel >= LogLevel_Warn) \
|
||||
{ \
|
||||
fprintf(LogFile, "AL Router (WW): " __VA_ARGS__); \
|
||||
fflush(LogFile); \
|
||||
} \
|
||||
} while(0)
|
||||
#define ERR(...) do { \
|
||||
if(LogLevel >= LogLevel_Error) \
|
||||
{ \
|
||||
fprintf(LogFile, "AL Router (EE): " __VA_ARGS__); \
|
||||
fflush(LogFile); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#endif /* ROUTER_ROUTER_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue