LoadOAL.linux.cpp
Engine/source/sfx/openal/linux/LoadOAL.linux.cpp
Public Variables
Public Functions
ALboolean
LoadOAL10Library(char * szOALFullPathName, LPOPENALFNTABLE lpOALFnTable)
ALvoid
Detailed Description
Public Variables
void * openal_library
Public Functions
LoadOAL10Library(char * szOALFullPathName, LPOPENALFNTABLE lpOALFnTable)
UnloadOAL10Library()
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24// TODO: Implement OpenAL loading code which is currently stubbed out. 25 26#if defined(__linux__) && !defined(TORQUE_OS_LINUX) 27#define TORQUE_OS_LINUX 28#endif 29 30#include <dlfcn.h> 31#include <err.h> 32#include <string.h> 33#include "sfx/openal/LoadOAL.h" 34#include "console/console.h" 35 36void* openal_library = NULL; 37 38ALboolean LoadOAL10Library(char *szOALFullPathName, LPOPENALFNTABLE lpOALFnTable) 39{ 40 if (!lpOALFnTable) 41 return AL_FALSE; 42 43 if (szOALFullPathName) 44 openal_library = dlopen(szOALFullPathName, RTLD_LAZY); 45 else 46 openal_library = dlopen("libopenal.so", RTLD_LAZY); 47 48 if (openal_library == NULL) { 49 Con::errorf("Failed to load OpenAL shared library. Sound will not be available"); 50 return AL_FALSE; 51 } 52 53 memset(lpOALFnTable, 0, sizeof(OPENALFNTABLE)); 54 55 lpOALFnTable->alEnable = (LPALENABLE)dlsym(openal_library,"alEnable"); 56 if (lpOALFnTable->alEnable == NULL) 57 { 58 warn("Failed to retrieve 'alEnable' function address\n"); 59 return AL_FALSE; 60 } 61 lpOALFnTable->alDisable = (LPALDISABLE)dlsym(openal_library,"alDisable"); 62 if (lpOALFnTable->alDisable == NULL) 63 { 64 warn("Failed to retrieve 'alDisable' function address\n"); 65 return AL_FALSE; 66 } 67 lpOALFnTable->alIsEnabled = (LPALISENABLED)dlsym(openal_library,"alIsEnabled"); 68 if (lpOALFnTable->alIsEnabled == NULL) 69 { 70 warn("Failed to retrieve 'alIsEnabled' function address\n"); 71 return AL_FALSE; 72 } 73 lpOALFnTable->alGetBoolean = (LPALGETBOOLEAN)dlsym(openal_library,"alGetBoolean"); 74 if (lpOALFnTable->alGetBoolean == NULL) 75 { 76 warn("Failed to retrieve 'alGetBoolean' function address\n"); 77 return AL_FALSE; 78 } 79 lpOALFnTable->alGetInteger = (LPALGETINTEGER)dlsym(openal_library,"alGetInteger"); 80 if (lpOALFnTable->alGetInteger == NULL) 81 { 82 warn("Failed to retrieve 'alGetInteger' function address\n"); 83 return AL_FALSE; 84 } 85 lpOALFnTable->alGetFloat = (LPALGETFLOAT)dlsym(openal_library,"alGetFloat"); 86 if (lpOALFnTable->alGetFloat == NULL) 87 { 88 warn("Failed to retrieve 'alGetFloat' function address\n"); 89 return AL_FALSE; 90 } 91 lpOALFnTable->alGetDouble = (LPALGETDOUBLE)dlsym(openal_library,"alGetDouble"); 92 if (lpOALFnTable->alGetDouble == NULL) 93 { 94 warn("Failed to retrieve 'alGetDouble' function address\n"); 95 return AL_FALSE; 96 } 97 lpOALFnTable->alGetBooleanv = (LPALGETBOOLEANV)dlsym(openal_library,"alGetBooleanv"); 98 if (lpOALFnTable->alGetBooleanv == NULL) 99 { 100 warn("Failed to retrieve 'alGetBooleanv' function address\n"); 101 return AL_FALSE; 102 } 103 lpOALFnTable->alGetIntegerv = (LPALGETINTEGERV)dlsym(openal_library,"alGetIntegerv"); 104 if (lpOALFnTable->alGetIntegerv == NULL) 105 { 106 warn("Failed to retrieve 'alGetIntegerv' function address\n"); 107 return AL_FALSE; 108 } 109 lpOALFnTable->alGetFloatv = (LPALGETFLOATV)dlsym(openal_library,"alGetFloatv"); 110 if (lpOALFnTable->alGetFloatv == NULL) 111 { 112 warn("Failed to retrieve 'alGetFloatv' function address\n"); 113 return AL_FALSE; 114 } 115 lpOALFnTable->alGetDoublev = (LPALGETDOUBLEV)dlsym(openal_library,"alGetDoublev"); 116 if (lpOALFnTable->alGetDoublev == NULL) 117 { 118 warn("Failed to retrieve 'alGetDoublev' function address\n"); 119 return AL_FALSE; 120 } 121 lpOALFnTable->alGetString = (LPALGETSTRING)dlsym(openal_library,"alGetString"); 122 if (lpOALFnTable->alGetString == NULL) 123 { 124 warn("Failed to retrieve 'alGetString' function address\n"); 125 return AL_FALSE; 126 } 127 lpOALFnTable->alGetError = (LPALGETERROR)dlsym(openal_library,"alGetError"); 128 if (lpOALFnTable->alGetError == NULL) 129 { 130 warn("Failed to retrieve 'alGetError' function address\n"); 131 return AL_FALSE; 132 } 133 lpOALFnTable->alIsExtensionPresent = (LPALISEXTENSIONPRESENT)dlsym(openal_library,"alIsExtensionPresent"); 134 if (lpOALFnTable->alIsExtensionPresent == NULL) 135 { 136 warn("Failed to retrieve 'alIsExtensionPresent' function address\n"); 137 return AL_FALSE; 138 } 139 lpOALFnTable->alGetProcAddress = (LPALGETPROCADDRESS)dlsym(openal_library,"alGetProcAddress"); 140 if (lpOALFnTable->alGetProcAddress == NULL) 141 { 142 warn("Failed to retrieve 'alGetProcAddress' function address\n"); 143 return AL_FALSE; 144 } 145 lpOALFnTable->alGetEnumValue = (LPALGETENUMVALUE)dlsym(openal_library,"alGetEnumValue"); 146 if (lpOALFnTable->alGetEnumValue == NULL) 147 { 148 warn("Failed to retrieve 'alGetEnumValue' function address\n"); 149 return AL_FALSE; 150 } 151 lpOALFnTable->alListeneri = (LPALLISTENERI)dlsym(openal_library,"alListeneri"); 152 if (lpOALFnTable->alListeneri == NULL) 153 { 154 warn("Failed to retrieve 'alListeneri' function address\n"); 155 return AL_FALSE; 156 } 157 lpOALFnTable->alListenerf = (LPALLISTENERF)dlsym(openal_library,"alListenerf"); 158 if (lpOALFnTable->alListenerf == NULL) 159 { 160 warn("Failed to retrieve 'alListenerf' function address\n"); 161 return AL_FALSE; 162 } 163 lpOALFnTable->alListener3f = (LPALLISTENER3F)dlsym(openal_library,"alListener3f"); 164 if (lpOALFnTable->alListener3f == NULL) 165 { 166 warn("Failed to retrieve 'alListener3f' function address\n"); 167 return AL_FALSE; 168 } 169 lpOALFnTable->alListenerfv = (LPALLISTENERFV)dlsym(openal_library,"alListenerfv"); 170 if (lpOALFnTable->alListenerfv == NULL) 171 { 172 warn("Failed to retrieve 'alListenerfv' function address\n"); 173 return AL_FALSE; 174 } 175 lpOALFnTable->alGetListeneri = (LPALGETLISTENERI)dlsym(openal_library,"alGetListeneri"); 176 if (lpOALFnTable->alGetListeneri == NULL) 177 { 178 warn("Failed to retrieve 'alGetListeneri' function address\n"); 179 return AL_FALSE; 180 } 181 lpOALFnTable->alGetListenerf =(LPALGETLISTENERF)dlsym(openal_library,"alGetListenerf"); 182 if (lpOALFnTable->alGetListenerf == NULL) 183 { 184 warn("Failed to retrieve 'alGetListenerf' function address\n"); 185 return AL_FALSE; 186 } 187 lpOALFnTable->alGetListener3f = (LPALGETLISTENER3F)dlsym(openal_library,"alGetListener3f"); 188 if (lpOALFnTable->alGetListener3f == NULL) 189 { 190 warn("Failed to retrieve 'alGetListener3f' function address\n"); 191 return AL_FALSE; 192 } 193 lpOALFnTable->alGetListenerfv = (LPALGETLISTENERFV)dlsym(openal_library,"alGetListenerfv"); 194 if (lpOALFnTable->alGetListenerfv == NULL) 195 { 196 warn("Failed to retrieve 'alGetListenerfv' function address\n"); 197 return AL_FALSE; 198 } 199 lpOALFnTable->alGenSources = (LPALGENSOURCES)dlsym(openal_library,"alGenSources"); 200 if (lpOALFnTable->alGenSources == NULL) 201 { 202 warn("Failed to retrieve 'alGenSources' function address\n"); 203 return AL_FALSE; 204 } 205 lpOALFnTable->alDeleteSources = (LPALDELETESOURCES)dlsym(openal_library,"alDeleteSources"); 206 if (lpOALFnTable->alDeleteSources == NULL) 207 { 208 warn("Failed to retrieve 'alDeleteSources' function address\n"); 209 return AL_FALSE; 210 } 211 lpOALFnTable->alIsSource = (LPALISSOURCE)dlsym(openal_library,"alIsSource"); 212 if (lpOALFnTable->alIsSource == NULL) 213 { 214 warn("Failed to retrieve 'alIsSource' function address\n"); 215 return AL_FALSE; 216 } 217 lpOALFnTable->alSourcei = (LPALSOURCEI)dlsym(openal_library,"alSourcei"); 218 if (lpOALFnTable->alSourcei == NULL) 219 { 220 warn("Failed to retrieve 'alSourcei' function address\n"); 221 return AL_FALSE; 222 } 223 lpOALFnTable->alSourcef = (LPALSOURCEF)dlsym(openal_library,"alSourcef"); 224 if (lpOALFnTable->alSourcef == NULL) 225 { 226 warn("Failed to retrieve 'alSourcef' function address\n"); 227 return AL_FALSE; 228 } 229 lpOALFnTable->alSource3f = (LPALSOURCE3F)dlsym(openal_library,"alSource3f"); 230 if (lpOALFnTable->alSource3f == NULL) 231 { 232 warn("Failed to retrieve 'alSource3f' function address\n"); 233 return AL_FALSE; 234 } 235 lpOALFnTable->alSourcefv = (LPALSOURCEFV)dlsym(openal_library,"alSourcefv"); 236 if (lpOALFnTable->alSourcefv == NULL) 237 { 238 warn("Failed to retrieve 'alSourcefv' function address\n"); 239 return AL_FALSE; 240 } 241 lpOALFnTable->alGetSourcei = (LPALGETSOURCEI)dlsym(openal_library,"alGetSourcei"); 242 if (lpOALFnTable->alGetSourcei == NULL) 243 { 244 warn("Failed to retrieve 'alGetSourcei' function address\n"); 245 return AL_FALSE; 246 } 247 lpOALFnTable->alGetSourcef = (LPALGETSOURCEF)dlsym(openal_library,"alGetSourcef"); 248 if (lpOALFnTable->alGetSourcef == NULL) 249 { 250 warn("Failed to retrieve 'alGetSourcef' function address\n"); 251 return AL_FALSE; 252 } 253 lpOALFnTable->alGetSourcefv = (LPALGETSOURCEFV)dlsym(openal_library,"alGetSourcefv"); 254 if (lpOALFnTable->alGetSourcefv == NULL) 255 { 256 warn("Failed to retrieve 'alGetSourcefv' function address\n"); 257 return AL_FALSE; 258 } 259 lpOALFnTable->alSourcePlayv = (LPALSOURCEPLAYV)dlsym(openal_library,"alSourcePlayv"); 260 if (lpOALFnTable->alSourcePlayv == NULL) 261 { 262 warn("Failed to retrieve 'alSourcePlayv' function address\n"); 263 return AL_FALSE; 264 } 265 lpOALFnTable->alSourceStopv = (LPALSOURCESTOPV)dlsym(openal_library,"alSourceStopv"); 266 if (lpOALFnTable->alSourceStopv == NULL) 267 { 268 warn("Failed to retrieve 'alSourceStopv' function address\n"); 269 return AL_FALSE; 270 } 271 lpOALFnTable->alSourcePlay = (LPALSOURCEPLAY)dlsym(openal_library,"alSourcePlay"); 272 if (lpOALFnTable->alSourcePlay == NULL) 273 { 274 warn("Failed to retrieve 'alSourcePlay' function address\n"); 275 return AL_FALSE; 276 } 277 lpOALFnTable->alSourcePause = (LPALSOURCEPAUSE)dlsym(openal_library,"alSourcePause"); 278 if (lpOALFnTable->alSourcePause == NULL) 279 { 280 warn("Failed to retrieve 'alSourcePause' function address\n"); 281 return AL_FALSE; 282 } 283 lpOALFnTable->alSourceStop = (LPALSOURCESTOP)dlsym(openal_library,"alSourceStop"); 284 if (lpOALFnTable->alSourceStop == NULL) 285 { 286 warn("Failed to retrieve 'alSourceStop' function address\n"); 287 return AL_FALSE; 288 } 289 lpOALFnTable->alSourceRewind = (LPALSOURCEREWIND)dlsym(openal_library,"alSourceRewind"); 290 if (lpOALFnTable->alSourceRewind == NULL) 291 { 292 warn("Failed to retrieve 'alSourceRewind' function address\n"); 293 return AL_FALSE; 294 } 295 lpOALFnTable->alGenBuffers = (LPALGENBUFFERS)dlsym(openal_library,"alGenBuffers"); 296 if (lpOALFnTable->alGenBuffers == NULL) 297 { 298 warn("Failed to retrieve 'alGenBuffers' function address\n"); 299 return AL_FALSE; 300 } 301 lpOALFnTable->alDeleteBuffers = (LPALDELETEBUFFERS)dlsym(openal_library,"alDeleteBuffers"); 302 if (lpOALFnTable->alDeleteBuffers == NULL) 303 { 304 warn("Failed to retrieve 'alDeleteBuffers' function address\n"); 305 return AL_FALSE; 306 } 307 lpOALFnTable->alIsBuffer = (LPALISBUFFER)dlsym(openal_library,"alIsBuffer"); 308 if (lpOALFnTable->alIsBuffer == NULL) 309 { 310 warn("Failed to retrieve 'alIsBuffer' function address\n"); 311 return AL_FALSE; 312 } 313 lpOALFnTable->alBufferData = (LPALBUFFERDATA)dlsym(openal_library,"alBufferData"); 314 if (lpOALFnTable->alBufferData == NULL) 315 { 316 warn("Failed to retrieve 'alBufferData' function address\n"); 317 return AL_FALSE; 318 } 319 lpOALFnTable->alGetBufferi = (LPALGETBUFFERI)dlsym(openal_library,"alGetBufferi"); 320 if (lpOALFnTable->alGetBufferi == NULL) 321 { 322 warn("Failed to retrieve 'alGetBufferi' function address\n"); 323 return AL_FALSE; 324 } 325 lpOALFnTable->alGetBufferf = (LPALGETBUFFERF)dlsym(openal_library,"alGetBufferf"); 326 if (lpOALFnTable->alGetBufferf == NULL) 327 { 328 warn("Failed to retrieve 'alGetBufferf' function address\n"); 329 return AL_FALSE; 330 } 331 lpOALFnTable->alSourceQueueBuffers = (LPALSOURCEQUEUEBUFFERS)dlsym(openal_library,"alSourceQueueBuffers"); 332 if (lpOALFnTable->alSourceQueueBuffers == NULL) 333 { 334 warn("Failed to retrieve 'alSourceQueueBuffers' function address\n"); 335 return AL_FALSE; 336 } 337 lpOALFnTable->alSourceUnqueueBuffers = (LPALSOURCEUNQUEUEBUFFERS)dlsym(openal_library,"alSourceUnqueueBuffers"); 338 if (lpOALFnTable->alSourceUnqueueBuffers == NULL) 339 { 340 warn("Failed to retrieve 'alSourceUnqueueBuffers' function address\n"); 341 return AL_FALSE; 342 } 343 lpOALFnTable->alDistanceModel = (LPALDISTANCEMODEL)dlsym(openal_library,"alDistanceModel"); 344 if (lpOALFnTable->alDistanceModel == NULL) 345 { 346 warn("Failed to retrieve 'alDistanceModel' function address\n"); 347 return AL_FALSE; 348 } 349 lpOALFnTable->alDopplerFactor = (LPALDOPPLERFACTOR)dlsym(openal_library,"alDopplerFactor"); 350 if (lpOALFnTable->alDopplerFactor == NULL) 351 { 352 warn("Failed to retrieve 'alDopplerFactor' function address\n"); 353 return AL_FALSE; 354 } 355 lpOALFnTable->alDopplerVelocity = (LPALDOPPLERVELOCITY)dlsym(openal_library,"alDopplerVelocity"); 356 if (lpOALFnTable->alDopplerVelocity == NULL) 357 { 358 warn("Failed to retrieve 'alDopplerVelocity' function address\n"); 359 return AL_FALSE; 360 } 361 lpOALFnTable->alcGetString = (LPALCGETSTRING)dlsym(openal_library,"alcGetString"); 362 if (lpOALFnTable->alcGetString == NULL) 363 { 364 warn("Failed to retrieve 'alcGetString' function address\n"); 365 return AL_FALSE; 366 } 367 lpOALFnTable->alcGetIntegerv = (LPALCGETINTEGERV)dlsym(openal_library,"alcGetIntegerv"); 368 if (lpOALFnTable->alcGetIntegerv == NULL) 369 { 370 warn("Failed to retrieve 'alcGetIntegerv' function address\n"); 371 return AL_FALSE; 372 } 373 lpOALFnTable->alcOpenDevice = (LPALCOPENDEVICE)dlsym(openal_library,"alcOpenDevice"); 374 if (lpOALFnTable->alcOpenDevice == NULL) 375 { 376 warn("Failed to retrieve 'alcOpenDevice' function address\n"); 377 return AL_FALSE; 378 } 379 lpOALFnTable->alcCloseDevice = (LPALCCLOSEDEVICE)dlsym(openal_library,"alcCloseDevice"); 380 if (lpOALFnTable->alcCloseDevice == NULL) 381 { 382 warn("Failed to retrieve 'alcCloseDevice' function address\n"); 383 return AL_FALSE; 384 } 385 lpOALFnTable->alcCreateContext = (LPALCCREATECONTEXT)dlsym(openal_library,"alcCreateContext"); 386 if (lpOALFnTable->alcCreateContext == NULL) 387 { 388 warn("Failed to retrieve 'alcCreateContext' function address\n"); 389 return AL_FALSE; 390 } 391 lpOALFnTable->alcMakeContextCurrent = (LPALCMAKECONTEXTCURRENT)dlsym(openal_library,"alcMakeContextCurrent"); 392 if (lpOALFnTable->alcMakeContextCurrent == NULL) 393 { 394 warn("Failed to retrieve 'alcMakeContextCurrent' function address\n"); 395 return AL_FALSE; 396 } 397 lpOALFnTable->alcProcessContext = (LPALCPROCESSCONTEXT)dlsym(openal_library,"alcProcessContext"); 398 if (lpOALFnTable->alcProcessContext == NULL) 399 { 400 warn("Failed to retrieve 'alcProcessContext' function address\n"); 401 return AL_FALSE; 402 } 403 lpOALFnTable->alcGetCurrentContext = (LPALCGETCURRENTCONTEXT)dlsym(openal_library,"alcGetCurrentContext"); 404 if (lpOALFnTable->alcGetCurrentContext == NULL) 405 { 406 warn("Failed to retrieve 'alcGetCurrentContext' function address\n"); 407 return AL_FALSE; 408 } 409 lpOALFnTable->alcGetContextsDevice = (LPALCGETCONTEXTSDEVICE)dlsym(openal_library,"alcGetContextsDevice"); 410 if (lpOALFnTable->alcGetContextsDevice == NULL) 411 { 412 warn("Failed to retrieve 'alcGetContextsDevice' function address\n"); 413 return AL_FALSE; 414 } 415 lpOALFnTable->alcSuspendContext = (LPALCSUSPENDCONTEXT)dlsym(openal_library,"alcSuspendContext"); 416 if (lpOALFnTable->alcSuspendContext == NULL) 417 { 418 warn("Failed to retrieve 'alcSuspendContext' function address\n"); 419 return AL_FALSE; 420 } 421 lpOALFnTable->alcDestroyContext = (LPALCDESTROYCONTEXT)dlsym(openal_library,"alcDestroyContext"); 422 if (lpOALFnTable->alcDestroyContext == NULL) 423 { 424 warn("Failed to retrieve 'alcDestroyContext' function address\n"); 425 return AL_FALSE; 426 } 427 lpOALFnTable->alcGetError = (LPALCGETERROR)dlsym(openal_library,"alcGetError"); 428 if (lpOALFnTable->alcGetError == NULL) 429 { 430 warn("Failed to retrieve 'alcGetError' function address\n"); 431 return AL_FALSE; 432 } 433 lpOALFnTable->alcIsExtensionPresent = (LPALCISEXTENSIONPRESENT)dlsym(openal_library,"alcIsExtensionPresent"); 434 if (lpOALFnTable->alcIsExtensionPresent == NULL) 435 { 436 warn("Failed to retrieve 'alcIsExtensionPresent' function address\n"); 437 return AL_FALSE; 438 } 439 lpOALFnTable->alcGetProcAddress = (LPALCGETPROCADDRESS)dlsym(openal_library,"alcGetProcAddress"); 440 if (lpOALFnTable->alcGetProcAddress == NULL) 441 { 442 warn("Failed to retrieve 'alcGetProcAddress' function address\n"); 443 return AL_FALSE; 444 } 445 lpOALFnTable->alcGetEnumValue = (LPALCGETENUMVALUE)dlsym(openal_library,"alcGetEnumValue"); 446 if (lpOALFnTable->alcGetEnumValue == NULL) 447 { 448 warn("Failed to retrieve 'alcGetEnumValue' function address\n"); 449 return AL_FALSE; 450 } 451 452 453 return AL_TRUE; 454} 455 456ALvoid UnloadOAL10Library() 457{ 458 if (openal_library != NULL) 459 dlclose(openal_library); 460} 461
