From e69750905a1a50479c0d13313ee6e0dd95657028 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 8 Dec 2015 16:48:25 +0100 Subject: [PATCH] Fix gcc warning about function casts --- apps/openmw/mwsound/openal_output.cpp | 36 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 407a24ce1..c2e808dee 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -50,6 +50,20 @@ namespace const int sLoudnessFPS = 20; // loudness values per second of audio +// Helper to get an OpenAL extension function +template +void convertPointer(T& dest, R src) +{ + memcpy(&dest, &src, sizeof(src)); +} + +template +void getFunc(T& func, ALCdevice *device, const char *name) +{ + void* funcPtr = alcGetProcAddress(device, name); + convertPointer(func, funcPtr); +} + } namespace MWSound @@ -602,9 +616,8 @@ std::vector OpenAL_Output::enumerateHrtf() if(!alcIsExtensionPresent(mDevice, "ALC_SOFT_HRTF")) return ret; - LPALCGETSTRINGISOFT alcGetStringiSOFT = reinterpret_cast( - alcGetProcAddress(mDevice, "alcGetStringiSOFT") - ); + LPALCGETSTRINGISOFT alcGetStringiSOFT = 0; + getFunc(alcGetStringiSOFT, mDevice, "alcGetStringiSOFT"); ALCint num_hrtf; alcGetIntegerv(mDevice, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtf); @@ -626,12 +639,12 @@ void OpenAL_Output::enableHrtf(const std::string &hrtfname, bool auto_enable) return; } - LPALCGETSTRINGISOFT alcGetStringiSOFT = reinterpret_cast( - alcGetProcAddress(mDevice, "alcGetStringiSOFT") - ); - LPALCRESETDEVICESOFT alcResetDeviceSOFT = reinterpret_cast( - alcGetProcAddress(mDevice, "alcResetDeviceSOFT") - ); + + LPALCGETSTRINGISOFT alcGetStringiSOFT = 0; + getFunc(alcGetStringiSOFT, mDevice, "alcGetStringiSOFT"); + + LPALCRESETDEVICESOFT alcResetDeviceSOFT = 0; + getFunc(alcResetDeviceSOFT, mDevice, "alcResetDeviceSOFT"); std::vector attrs; attrs.push_back(ALC_HRTF_SOFT); @@ -681,9 +694,8 @@ void OpenAL_Output::disableHrtf() return; } - LPALCRESETDEVICESOFT alcResetDeviceSOFT = reinterpret_cast( - alcGetProcAddress(mDevice, "alcResetDeviceSOFT") - ); + LPALCRESETDEVICESOFT alcResetDeviceSOFT = 0; + getFunc(alcResetDeviceSOFT, mDevice, "alcResetDeviceSOFT"); std::vector attrs; attrs.push_back(ALC_HRTF_SOFT);