diff options
-rw-r--r-- | al/source.cpp | 49 | ||||
-rw-r--r-- | al/state.cpp | 48 | ||||
-rw-r--r-- | alc/alcontext.h | 11 |
3 files changed, 80 insertions, 28 deletions
diff --git a/al/source.cpp b/al/source.cpp index 6bdfa01a..2cb74589 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -850,6 +850,34 @@ ALenum EnumFromDirectMode(DirectMode mode) throw std::runtime_error{"Invalid DirectMode: "+std::to_string(int(mode))}; } +al::optional<DistanceModel> DistanceModelFromALenum(ALenum model) +{ + switch(model) + { + case AL_NONE: return al::make_optional(DistanceModel::Disable); + case AL_INVERSE_DISTANCE: return al::make_optional(DistanceModel::Inverse); + case AL_INVERSE_DISTANCE_CLAMPED: return al::make_optional(DistanceModel::InverseClamped); + case AL_LINEAR_DISTANCE: return al::make_optional(DistanceModel::Linear); + case AL_LINEAR_DISTANCE_CLAMPED: return al::make_optional(DistanceModel::LinearClamped); + case AL_EXPONENT_DISTANCE: return al::make_optional(DistanceModel::Exponent); + case AL_EXPONENT_DISTANCE_CLAMPED: return al::make_optional(DistanceModel::ExponentClamped); + } + return al::nullopt; +} +ALenum ALenumFromDistanceModel(DistanceModel model) +{ + switch(model) + { + case DistanceModel::Disable: return AL_NONE; + case DistanceModel::Inverse: return AL_INVERSE_DISTANCE; + case DistanceModel::InverseClamped: return AL_INVERSE_DISTANCE_CLAMPED; + case DistanceModel::Linear: return AL_LINEAR_DISTANCE; + case DistanceModel::LinearClamped: return AL_LINEAR_DISTANCE_CLAMPED; + case DistanceModel::Exponent: return AL_EXPONENT_DISTANCE; + case DistanceModel::ExponentClamped: return AL_EXPONENT_DISTANCE_CLAMPED; + } + throw std::runtime_error{"Unexpected distance model "+std::to_string(static_cast<int>(model))}; +} enum SourceProp : ALenum { srcPitch = AL_PITCH, @@ -1470,18 +1498,19 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a } Context->setError(AL_INVALID_VALUE, "Unsupported AL_DIRECT_CHANNELS_SOFT: 0x%04x\n", values[0]); + return false; case AL_DISTANCE_MODEL: CHECKSIZE(values, 1); - CHECKVAL(values[0] == AL_NONE || - values[0] == AL_INVERSE_DISTANCE || values[0] == AL_INVERSE_DISTANCE_CLAMPED || - values[0] == AL_LINEAR_DISTANCE || values[0] == AL_LINEAR_DISTANCE_CLAMPED || - values[0] == AL_EXPONENT_DISTANCE || values[0] == AL_EXPONENT_DISTANCE_CLAMPED); - - Source->mDistanceModel = static_cast<DistanceModel>(values[0]); - if(Context->mSourceDistanceModel) - return UpdateSourceProps(Source, Context); - return true; + if(auto model = DistanceModelFromALenum(values[0])) + { + Source->mDistanceModel = *model; + if(Context->mSourceDistanceModel) + return UpdateSourceProps(Source, Context); + return true; + } + Context->setError(AL_INVALID_VALUE, "Distance model out of range: 0x%04x", values[0]); + return false; case AL_SOURCE_RESAMPLER_SOFT: CHECKSIZE(values, 1); @@ -2022,7 +2051,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_DISTANCE_MODEL: CHECKSIZE(values, 1); - values[0] = static_cast<int>(Source->mDistanceModel); + values[0] = ALenumFromDistanceModel(Source->mDistanceModel); return true; case AL_SOURCE_RESAMPLER_SOFT: diff --git a/al/state.cpp b/al/state.cpp index f70d3689..c8eebbe0 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -94,6 +94,35 @@ const ALchar *GetResamplerName(const Resampler rtype) throw std::runtime_error{"Unexpected resampler index"}; } +al::optional<DistanceModel> DistanceModelFromALenum(ALenum model) +{ + switch(model) + { + case AL_NONE: return al::make_optional(DistanceModel::Disable); + case AL_INVERSE_DISTANCE: return al::make_optional(DistanceModel::Inverse); + case AL_INVERSE_DISTANCE_CLAMPED: return al::make_optional(DistanceModel::InverseClamped); + case AL_LINEAR_DISTANCE: return al::make_optional(DistanceModel::Linear); + case AL_LINEAR_DISTANCE_CLAMPED: return al::make_optional(DistanceModel::LinearClamped); + case AL_EXPONENT_DISTANCE: return al::make_optional(DistanceModel::Exponent); + case AL_EXPONENT_DISTANCE_CLAMPED: return al::make_optional(DistanceModel::ExponentClamped); + } + return al::nullopt; +} +ALenum ALenumFromDistanceModel(DistanceModel model) +{ + switch(model) + { + case DistanceModel::Disable: return AL_NONE; + case DistanceModel::Inverse: return AL_INVERSE_DISTANCE; + case DistanceModel::InverseClamped: return AL_INVERSE_DISTANCE_CLAMPED; + case DistanceModel::Linear: return AL_LINEAR_DISTANCE; + case DistanceModel::LinearClamped: return AL_LINEAR_DISTANCE_CLAMPED; + case DistanceModel::Exponent: return AL_EXPONENT_DISTANCE; + case DistanceModel::ExponentClamped: return AL_EXPONENT_DISTANCE_CLAMPED; + } + throw std::runtime_error{"Unexpected distance model "+std::to_string(static_cast<int>(model))}; +} + } // namespace /* WARNING: Non-standard export! Not part of any extension, or exposed in the @@ -254,7 +283,7 @@ START_API_FUNC break; case AL_DISTANCE_MODEL: - value = static_cast<ALdouble>(context->mDistanceModel); + value = static_cast<ALdouble>(ALenumFromDistanceModel(context->mDistanceModel)); break; case AL_SPEED_OF_SOUND: @@ -305,7 +334,7 @@ START_API_FUNC break; case AL_DISTANCE_MODEL: - value = static_cast<ALfloat>(context->mDistanceModel); + value = static_cast<ALfloat>(ALenumFromDistanceModel(context->mDistanceModel)); break; case AL_SPEED_OF_SOUND: @@ -356,7 +385,7 @@ START_API_FUNC break; case AL_DISTANCE_MODEL: - value = static_cast<ALint>(context->mDistanceModel); + value = ALenumFromDistanceModel(context->mDistanceModel); break; case AL_SPEED_OF_SOUND: @@ -407,7 +436,7 @@ START_API_FUNC break; case AL_DISTANCE_MODEL: - value = static_cast<ALint64SOFT>(context->mDistanceModel); + value = ALenumFromDistanceModel(context->mDistanceModel); break; case AL_SPEED_OF_SOUND: @@ -770,18 +799,15 @@ START_API_FUNC ContextRef context{GetContextRef()}; if UNLIKELY(!context) return; - if(!(value == AL_INVERSE_DISTANCE || value == AL_INVERSE_DISTANCE_CLAMPED || - value == AL_LINEAR_DISTANCE || value == AL_LINEAR_DISTANCE_CLAMPED || - value == AL_EXPONENT_DISTANCE || value == AL_EXPONENT_DISTANCE_CLAMPED || - value == AL_NONE)) - context->setError(AL_INVALID_VALUE, "Distance model 0x%04x out of range", value); - else + if(auto model = DistanceModelFromALenum(value)) { std::lock_guard<std::mutex> _{context->mPropLock}; - context->mDistanceModel = static_cast<DistanceModel>(value); + context->mDistanceModel = *model; if(!context->mSourceDistanceModel) DO_UPDATEPROPS(); } + else + context->setError(AL_INVALID_VALUE, "Distance model 0x%04x out of range", value); } END_API_FUNC diff --git a/alc/alcontext.h b/alc/alcontext.h index c13930b9..21102538 100644 --- a/alc/alcontext.h +++ b/alc/alcontext.h @@ -34,13 +34,10 @@ struct VoiceChange; enum class DistanceModel { - InverseClamped = AL_INVERSE_DISTANCE_CLAMPED, - LinearClamped = AL_LINEAR_DISTANCE_CLAMPED, - ExponentClamped = AL_EXPONENT_DISTANCE_CLAMPED, - Inverse = AL_INVERSE_DISTANCE, - Linear = AL_LINEAR_DISTANCE, - Exponent = AL_EXPONENT_DISTANCE, - Disable = AL_NONE, + Disable, + Inverse, InverseClamped, + Linear, LinearClamped, + Exponent, ExponentClamped, Default = InverseClamped }; |