diff options
author | Chris Robinson <[email protected]> | 2023-05-14 00:55:54 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-05-14 01:27:14 -0700 |
commit | 6a007660fb7bac51f01ef0b9466bfcc6ade7389b (patch) | |
tree | 2b7764e1132f8466a731cd26934dfa7ea73154ed | |
parent | 54ce34ba9901b3d7ad231a49587f60918e45ac90 (diff) |
Implement direct functions for context state
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | al/direct_defs.h | 35 | ||||
-rw-r--r-- | al/error.cpp | 7 | ||||
-rw-r--r-- | al/state.cpp | 279 | ||||
-rw-r--r-- | alc/alc.cpp | 22 |
5 files changed, 180 insertions, 164 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fe46a688..eeef181f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -742,6 +742,7 @@ set(OPENAL_OBJS al/buffer.h al/debug.cpp al/debug.h + al/direct_defs.h al/effect.cpp al/effect.h al/effects/autowah.cpp diff --git a/al/direct_defs.h b/al/direct_defs.h new file mode 100644 index 00000000..555e9565 --- /dev/null +++ b/al/direct_defs.h @@ -0,0 +1,35 @@ +#ifndef AL_DIRECT_DEFS_H +#define AL_DIRECT_DEFS_H + +#define DECL_FUNC(R, Name) \ +R AL_API Name(void) START_API_FUNC \ +{ \ + return Name##Direct(GetContextRef().get()); \ +} END_API_FUNC + +#define DECL_FUNC1(R, Name, T1) \ +R AL_API Name(T1 a) START_API_FUNC \ +{ \ + return Name##Direct(GetContextRef().get(), a); \ +} END_API_FUNC + +#define DECL_FUNC2(R, Name, T1, T2) \ +R AL_API Name(T1 a, T2 b) START_API_FUNC \ +{ \ + return Name##Direct(GetContextRef().get(), a, b); \ +} END_API_FUNC + + +#define DECL_FUNCEXT(R, Name,Ext) \ +R AL_API Name##Ext(void) START_API_FUNC \ +{ \ + return Name##Direct##Ext(GetContextRef().get()); \ +} END_API_FUNC + +#define DECL_FUNCEXT2(R, Name,Ext, T1, T2) \ +R AL_API Name##Ext(T1 a, T2 b) START_API_FUNC \ +{ \ + return Name##Direct##Ext(GetContextRef().get(), a, b); \ +} END_API_FUNC + +#endif /* AL_DIRECT_DEFS_H */ diff --git a/al/error.cpp b/al/error.cpp index b0607d66..e33ee161 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -41,6 +41,7 @@ #include "almalloc.h" #include "core/except.h" #include "core/logging.h" +#include "direct_defs.h" #include "opthelpers.h" @@ -89,10 +90,9 @@ void ALCcontext::setError(ALenum errorCode, const char *msg, ...) debugMessage(DebugSource::API, DebugType::Error, 0, DebugSeverity::High, msglen, msg); } -AL_API ALenum AL_APIENTRY alGetError(void) -START_API_FUNC +AL_API DECL_FUNC(ALenum, alGetError) +FORCE_ALIGN ALenum AL_APIENTRY alGetErrorDirect(ALCcontext *context) noexcept { - ContextRef context{GetContextRef()}; if(!context) UNLIKELY { static constexpr ALenum deferror{AL_INVALID_OPERATION}; @@ -111,4 +111,3 @@ START_API_FUNC return context->mLastError.exchange(AL_NO_ERROR); } -END_API_FUNC diff --git a/al/state.cpp b/al/state.cpp index f749af50..e1b50af0 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -45,6 +45,7 @@ #include "core/except.h" #include "core/mixer/defs.h" #include "core/voice.h" +#include "direct_defs.h" #include "intrusive_ptr.h" #include "opthelpers.h" #include "strutils.h" @@ -303,11 +304,10 @@ START_API_FUNC END_API_FUNC -AL_API void AL_APIENTRY alEnable(ALenum capability) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alEnableDirect(ALCcontext *context, ALenum capability) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; switch(capability) { @@ -315,7 +315,7 @@ START_API_FUNC { std::lock_guard<std::mutex> _{context->mPropLock}; context->mSourceDistanceModel = true; - UpdateProps(context.get()); + UpdateProps(context); } break; @@ -331,13 +331,11 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "Invalid enable property 0x%04x", capability); } } -END_API_FUNC -AL_API void AL_APIENTRY alDisable(ALenum capability) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alDisableDirect(ALCcontext *context, ALenum capability) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; switch(capability) { @@ -345,7 +343,7 @@ START_API_FUNC { std::lock_guard<std::mutex> _{context->mPropLock}; context->mSourceDistanceModel = false; - UpdateProps(context.get()); + UpdateProps(context); } break; @@ -361,13 +359,11 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "Invalid disable property 0x%04x", capability); } } -END_API_FUNC -AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability) -START_API_FUNC +FORCE_ALIGN ALboolean AL_APIENTRY alIsEnabledDirect(ALCcontext *context, ALenum capability) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return AL_FALSE; + if(!context) UNLIKELY + return AL_FALSE; std::lock_guard<std::mutex> _{context->mPropLock}; ALboolean value{AL_FALSE}; @@ -391,127 +387,88 @@ START_API_FUNC return value; } -END_API_FUNC - -AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname) -START_API_FUNC -{ - ALboolean value{AL_FALSE}; - alGetBooleanv(pname, &value); - return value; -} -END_API_FUNC -AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname) -START_API_FUNC -{ - ALdouble value{0.0}; - alGetDoublev(pname, &value); - return value; +#define DECL_GETFUNC(R, Name, Ext) \ +AL_API R AL_APIENTRY Name##Ext(ALenum pname) \ +START_API_FUNC \ +{ \ + R value{}; \ + Name##vDirect##Ext(GetContextRef().get(), pname, &value); \ + return value; \ +} \ +END_API_FUNC \ +FORCE_ALIGN R AL_APIENTRY Name##Direct##Ext(ALCcontext *context, ALenum pname) noexcept \ +{ \ + R value{}; \ + Name##vDirect##Ext(context, pname, &value); \ + return value; \ } -END_API_FUNC -AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname) -START_API_FUNC -{ - ALfloat value{0.0f}; - alGetFloatv(pname, &value); - return value; -} -END_API_FUNC +DECL_GETFUNC(ALboolean, alGetBoolean,) +DECL_GETFUNC(ALdouble, alGetDouble,) +DECL_GETFUNC(ALfloat, alGetFloat,) +DECL_GETFUNC(ALint, alGetInteger,) -AL_API ALint AL_APIENTRY alGetInteger(ALenum pname) -START_API_FUNC -{ - ALint value{0}; - alGetIntegerv(pname, &value); - return value; -} -END_API_FUNC +DECL_GETFUNC(ALint64SOFT, alGetInteger64,SOFT) +DECL_GETFUNC(ALvoid*, alGetPointer,SOFT) -AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname) -START_API_FUNC -{ - ALint64SOFT value{0}; - alGetInteger64vSOFT(pname, &value); - return value; -} -END_API_FUNC +#undef DECL_GETFUNC -AL_API ALvoid* AL_APIENTRY alGetPointerSOFT(ALenum pname) -START_API_FUNC -{ - ALvoid *value{nullptr}; - alGetPointervSOFT(pname, &value); - return value; -} -END_API_FUNC -AL_API void AL_APIENTRY alGetBooleanv(ALenum pname, ALboolean *values) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alGetBooleanvDirect(ALCcontext *context, ALenum pname, ALboolean *values) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; if(!values) UNLIKELY return context->setError(AL_INVALID_VALUE, "NULL pointer"); - GetValue(context.get(), pname, values); + GetValue(context, pname, values); } -END_API_FUNC -AL_API void AL_APIENTRY alGetDoublev(ALenum pname, ALdouble *values) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alGetDoublevDirect(ALCcontext *context, ALenum pname, ALdouble *values) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; if(!values) UNLIKELY return context->setError(AL_INVALID_VALUE, "NULL pointer"); - GetValue(context.get(), pname, values); + GetValue(context, pname, values); } -END_API_FUNC -AL_API void AL_APIENTRY alGetFloatv(ALenum pname, ALfloat *values) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alGetFloatvDirect(ALCcontext *context, ALenum pname, ALfloat *values) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; if(!values) UNLIKELY return context->setError(AL_INVALID_VALUE, "NULL pointer"); - GetValue(context.get(), pname, values); + GetValue(context, pname, values); } -END_API_FUNC -AL_API void AL_APIENTRY alGetIntegerv(ALenum pname, ALint *values) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alGetIntegervDirect(ALCcontext *context, ALenum pname, ALint *values) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; if(!values) UNLIKELY return context->setError(AL_INVALID_VALUE, "NULL pointer"); - GetValue(context.get(), pname, values); + GetValue(context, pname, values); } -END_API_FUNC -AL_API void AL_APIENTRY alGetInteger64vSOFT(ALenum pname, ALint64SOFT *values) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alGetInteger64vDirectSOFT(ALCcontext *context, ALenum pname, ALint64SOFT *values) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; if(!values) UNLIKELY return context->setError(AL_INVALID_VALUE, "NULL pointer"); - GetValue(context.get(), pname, values); + GetValue(context, pname, values); } -END_API_FUNC -AL_API void AL_APIENTRY alGetPointervSOFT(ALenum pname, ALvoid **values) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alGetPointervDirectSOFT(ALCcontext *context, ALenum pname, ALvoid **values) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; if(!values) UNLIKELY return context->setError(AL_INVALID_VALUE, "NULL pointer"); @@ -538,13 +495,11 @@ START_API_FUNC context->setError(AL_INVALID_ENUM, "Invalid context pointer property 0x%04x", pname); } } -END_API_FUNC -AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname) -START_API_FUNC +FORCE_ALIGN const ALchar* AL_APIENTRY alGetStringDirect(ALCcontext *context, ALenum pname) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return nullptr; + if(!context) UNLIKELY + return nullptr; const ALchar *value{nullptr}; switch(pname) @@ -602,13 +557,11 @@ START_API_FUNC } return value; } -END_API_FUNC -AL_API void AL_APIENTRY alDopplerFactor(ALfloat value) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alDopplerFactorDirect(ALCcontext *context, ALfloat value) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; if(!(value >= 0.0f && std::isfinite(value))) context->setError(AL_INVALID_VALUE, "Doppler factor %f out of range", value); @@ -616,39 +569,14 @@ START_API_FUNC { std::lock_guard<std::mutex> _{context->mPropLock}; context->mDopplerFactor = value; - UpdateProps(context.get()); - } -} -END_API_FUNC - -AL_API void AL_APIENTRY alDopplerVelocity(ALfloat value) -START_API_FUNC -{ - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; - - if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY - context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, - DebugSeverity::Medium, -1, - "alDopplerVelocity is deprecated in AL 1.1, use alSpeedOfSound; " - "alDopplerVelocity(x) -> alSpeedOfSound(343.3f * x)"); - - if(!(value >= 0.0f && std::isfinite(value))) - context->setError(AL_INVALID_VALUE, "Doppler velocity %f out of range", value); - else - { - std::lock_guard<std::mutex> _{context->mPropLock}; - context->mDopplerVelocity = value; - UpdateProps(context.get()); + UpdateProps(context); } } -END_API_FUNC -AL_API void AL_APIENTRY alSpeedOfSound(ALfloat value) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alSpeedOfSoundDirect(ALCcontext *context, ALfloat value) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; if(!(value > 0.0f && std::isfinite(value))) context->setError(AL_INVALID_VALUE, "Speed of sound %f out of range", value); @@ -656,58 +584,50 @@ START_API_FUNC { std::lock_guard<std::mutex> _{context->mPropLock}; context->mSpeedOfSound = value; - UpdateProps(context.get()); + UpdateProps(context); } } -END_API_FUNC -AL_API void AL_APIENTRY alDistanceModel(ALenum value) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alDistanceModelDirect(ALCcontext *context, ALenum value) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; if(auto model = DistanceModelFromALenum(value)) { std::lock_guard<std::mutex> _{context->mPropLock}; context->mDistanceModel = *model; if(!context->mSourceDistanceModel) - UpdateProps(context.get()); + UpdateProps(context); } else context->setError(AL_INVALID_VALUE, "Distance model 0x%04x out of range", value); } -END_API_FUNC -AL_API void AL_APIENTRY alDeferUpdatesSOFT(void) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alDeferUpdatesDirectSOFT(ALCcontext *context) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; std::lock_guard<std::mutex> _{context->mPropLock}; context->deferUpdates(); } -END_API_FUNC -AL_API void AL_APIENTRY alProcessUpdatesSOFT(void) -START_API_FUNC +FORCE_ALIGN void AL_APIENTRY alProcessUpdatesDirectSOFT(ALCcontext *context) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return; + if(!context) UNLIKELY + return; std::lock_guard<std::mutex> _{context->mPropLock}; context->processUpdates(); } -END_API_FUNC -AL_API const ALchar* AL_APIENTRY alGetStringiSOFT(ALenum pname, ALsizei index) -START_API_FUNC +FORCE_ALIGN const ALchar* AL_APIENTRY alGetStringiDirectSOFT(ALCcontext *context, ALenum pname, ALsizei index) noexcept { - ContextRef context{GetContextRef()}; - if(!context) UNLIKELY return nullptr; + if(!context) UNLIKELY + return nullptr; const ALchar *value{nullptr}; switch(pname) @@ -724,6 +644,45 @@ START_API_FUNC } return value; } + +AL_API DECL_FUNC1(void, alEnable, ALenum) +AL_API DECL_FUNC1(void, alDisable, ALenum) +AL_API DECL_FUNC1(ALboolean, alIsEnabled, ALenum) +AL_API DECL_FUNC2(void, alGetBooleanv, ALenum, ALboolean*) +AL_API DECL_FUNC2(void, alGetDoublev, ALenum, ALdouble*) +AL_API DECL_FUNC2(void, alGetFloatv, ALenum, ALfloat*) +AL_API DECL_FUNC2(void, alGetIntegerv, ALenum, ALint*) +AL_API DECL_FUNCEXT2(void, alGetInteger64v,SOFT, ALenum, ALint64SOFT*) +AL_API DECL_FUNCEXT2(void, alGetPointerv,SOFT, ALenum, ALvoid**) +AL_API DECL_FUNC1(const ALchar*, alGetString, ALenum) +AL_API DECL_FUNC1(void, alDopplerFactor, ALfloat) +AL_API DECL_FUNC1(void, alSpeedOfSound, ALfloat) +AL_API DECL_FUNC1(void, alDistanceModel, ALenum) +AL_API DECL_FUNCEXT(void, alDeferUpdates,SOFT) +AL_API DECL_FUNCEXT(void, alProcessUpdates,SOFT) +AL_API DECL_FUNCEXT2(const ALchar*, alGetStringi,SOFT, ALenum,ALsizei) + +AL_API void AL_APIENTRY alDopplerVelocity(ALfloat value) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(!context) UNLIKELY return; + + if(context->mContextFlags.test(ContextFlags::DebugBit)) UNLIKELY + context->debugMessage(DebugSource::API, DebugType::DeprecatedBehavior, 0, + DebugSeverity::Medium, -1, + "alDopplerVelocity is deprecated in AL 1.1, use alSpeedOfSound; " + "alDopplerVelocity(x) -> alSpeedOfSound(343.3f * x)"); + + if(!(value >= 0.0f && std::isfinite(value))) + context->setError(AL_INVALID_VALUE, "Doppler velocity %f out of range", value); + else + { + std::lock_guard<std::mutex> _{context->mPropLock}; + context->mDopplerVelocity = value; + UpdateProps(context.get()); + } +} END_API_FUNC diff --git a/alc/alc.cpp b/alc/alc.cpp index 9fedee0b..c9a56d90 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -467,6 +467,28 @@ const struct { DECL(alPushDebugGroupEXT), DECL(alPopDebugGroupEXT), DECL(alGetDebugMessageLogEXT), + + /* Direct Context functions */ + DECL(alEnableDirect), + DECL(alDisableDirect), + DECL(alIsEnabledDirect), + DECL(alDopplerFactorDirect), + DECL(alSpeedOfSoundDirect), + DECL(alDistanceModelDirect), + DECL(alGetStringDirect), + DECL(alGetBooleanvDirect), + DECL(alGetIntegervDirect), + DECL(alGetFloatvDirect), + DECL(alGetDoublevDirect), + DECL(alGetBooleanDirect), + DECL(alGetIntegerDirect), + DECL(alGetFloatDirect), + DECL(alGetDoubleDirect), + + DECL(alDeferUpdatesDirectSOFT), + DECL(alProcessUpdatesDirectSOFT), + DECL(alGetStringiDirectSOFT), + #ifdef ALSOFT_EAX }, eaxFunctions[] = { DECL(EAXGet), |