| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 | //-----------------------------------------------------------------------------// Copyright (c) 2012 GarageGames, LLC//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions://// The above copyright notice and this permission notice shall be included in// all copies or substantial portions of the Software.//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS// IN THE SOFTWARE.//-----------------------------------------------------------------------------#if 0#include "platformX86UNIX/platformX86UNIX.h"#include "console/console.h"#include <dlfcn.h>#include <al/altypes.h>#include <al/alctypes.h>#define INITGUID#include <al/eaxtypes.h>// Define the OpenAL and Extension Stub functions#define AL_FUNCTION(fn_return, fn_name, fn_args, fn_value) fn_return stub_##fn_name fn_args{ fn_value }#include <al/al_func.h>#include <al/alc_func.h>#include <al/eax_func.h>#undef AL_FUNCTION// Declare the OpenAL and Extension Function pointers// And initialize them to the stub functions#define AL_FUNCTION(fn_return,fn_name,fn_args, fn_value) fn_return (*fn_name)fn_args = stub_##fn_name;#include <al/al_func.h>#include <al/alc_func.h>#include <al/eax_func.h>#undef AL_FUNCTION// Declarations for the "emulated" functions (al functions that don't // exist in the loki openal implementation)ALboolean emu_alGetBoolean(ALenum param);ALint emu_alGetInteger(ALenum param);ALfloat emu_alGetFloat(ALenum param);ALdouble emu_alGetDouble(ALenum param);void emu_alListeneri( ALenum param, ALint value );void emu_alGetListener3f(ALenum pname,ALfloat *v1,ALfloat *v2,ALfloat *v3);ALCdevice* emu_alcGetContextsDevice(ALCcontext *context);static void *dlHandle = NULL;static char* dlError = "no error";/*!   Get an "emulated" function address and bind it to the function pointer*/static bool bindEmulatedFunction(void *&fnAddress, const char *name){   fnAddress = NULL;   if (dStrcmp(name, "alGetBoolean")==0)      fnAddress = (void*)&emu_alGetBoolean;   else if (dStrcmp(name, "alGetInteger")==0)      fnAddress = (void*)&emu_alGetInteger;   else if (dStrcmp(name, "alGetFloat")==0)      fnAddress = (void*)&emu_alGetFloat;   else if (dStrcmp(name, "alGetDouble")==0)      fnAddress = (void*)&emu_alGetDouble;   else if (dStrcmp(name, "alListeneri")==0)      fnAddress = (void*)&emu_alListeneri;   else if (dStrcmp(name, "alGetListener3f")==0)      fnAddress = (void*)&emu_alGetListener3f;   else if (dStrcmp(name, "alcGetContextsDevice")==0)      fnAddress = (void*)&emu_alcGetContextsDevice;   return fnAddress != NULL;}/*!   Get a function address from the OpenAL DLL and bind it to the *     function pointer*/static bool bindFunction( void *&fnAddress, const char *name ){   fnAddress = dlsym(dlHandle, name);   if( !fnAddress )      if (bindEmulatedFunction(fnAddress, name))         Con::warnf(ConsoleLogEntry::General, " Missing OpenAL function '%s', using emulated function", name);      else         Con::errorf(ConsoleLogEntry::General, " Missing OpenAL function '%s'", name);   return (fnAddress != NULL);}/*!   Get a function address for an OpenAL extension function and bind it *     to it's function pointer*/static bool bindExtensionFunction( void *&fnAddress, const char *name ){   fnAddress = alGetProcAddress( (ALubyte*)name );   if( !fnAddress )      Con::errorf(ConsoleLogEntry::General, " Missing OpenAL Extension function '%s'", name);   return (fnAddress != NULL);}/*!   Bind the functions in the OpenAL DLL to the al interface functions  */static bool bindOpenALFunctions(){   bool result = true;   #define AL_FUNCTION(fn_return, fn_name, fn_args, fn_value) result &= bindFunction( *(void**)&fn_name, #fn_name);   #include <al/al_func.h>   #include <al/alc_func.h>   #undef AL_FUNCTION   return result;}/*!   Bind the stub functions to the al interface functions  */static void unbindOpenALFunctions(){   #define AL_FUNCTION(fn_return, fn_name, fn_args, fn_value) fn_name = stub_##fn_name;   #include <al/al_func.h>   #include <al/alc_func.h>   #include <al/eax_func.h>   #undef AL_FUNCTION}/*!   Bind the EAX Extension functions to the EAX interface functions  */static bool bindEAXFunctions(){   bool result = true;   #define AL_FUNCTION(fn_return, fn_name, fn_args, fn_value) result &= bindExtensionFunction( *(void**)&fn_name, #fn_name);   #include <al/eax_func.h>   #undef AL_FUNCTION   return result;}// Definitions for the emulated functionsALboolean emu_alGetBoolean(ALenum param){   ALboolean alboolean;   alGetBooleanv(param, &alboolean);   return alboolean;}ALint emu_alGetInteger(ALenum param){   ALint alint;   alGetIntegerv(param, &alint);   return alint;}ALfloat emu_alGetFloat(ALenum param){   ALfloat alfloat;   alGetFloatv(param, &alfloat);   return alfloat;}ALdouble emu_alGetDouble(ALenum param){   ALdouble aldouble;   alGetDoublev(param, &aldouble);   return aldouble;}void emu_alGetListener3f(ALenum pname,ALfloat *v0,ALfloat *v1,ALfloat *v2){   ALfloat ptArray[10];   ptArray[0] = *v0;   ptArray[1] = *v1;   ptArray[2] = *v2;   alGetListenerfv(pname, ptArray);   *v0 = ptArray[0];   *v1 = ptArray[1];   *v2 = ptArray[2];}void emu_alListeneri( ALenum param, ALint value ){   alListenerf(param, static_cast<ALfloat>(value));}ALCdevice* emu_alcGetContextsDevice(ALCcontext *context){   // this function isn't emulated   AssertFatal(false, "alcGetContextsDevice is not available");   return NULL;}namespace Audio{/*!   Shutdown and Unload the OpenAL DLL  */void OpenALDLLShutdown(){   if (dlHandle != NULL)   {      dlclose(dlHandle);      // FreeBSD didn't like that const dlerror() was returning.      if ((dlError = (char *)dlerror()) != NULL)         Con::errorf(ConsoleLogEntry::General, " Error unloading OpenAL Library: %s", dlError);   }   dlHandle = NULL;   unbindOpenALFunctions();   }   /*!   Dynamically Loads the OpenAL DLL if present and binds all the functions.*     If there is no DLL or an unexpected error occurs binding functions the*     stub functions are automatically bound.*/bool OpenALDLLInit(){   OpenALDLLShutdown();   const char* libName = "libopenal.so";   // these are relative to the current working directory   const char* searchPath[] = {      "lib",      "tplib", // superceeded by "lib", here for backass compatibility      "", // i.e.: current working directory      NULL // this must be last   };    char openalPath[4096];   for (int i = 0; searchPath[i] != NULL; ++i)   {         dSprintf(openalPath, sizeof(openalPath), "%s/%s/%s",         Platform::getWorkingDirectory(),          searchPath[i],         libName);               Con::printf("		Searching for OpenAl at location : %s", openalPath);      dlHandle = dlopen(openalPath, RTLD_NOW);      if (dlHandle != NULL)      {         // found it         Con::printf("   Loading OpenAL: %s", openalPath);         break;      }   }      if (dlHandle == NULL)   {      // couldn't find it in our searchPath, try the system path      dlHandle = dlopen(libName, RTLD_NOW);      if (dlHandle != NULL)         Con::printf("   Loading OpenAL from system (dlopen) path");   }   if (dlHandle != NULL)   {      // if the DLL loaded bind the OpenAL function pointers      if(bindOpenALFunctions())      {         // if EAX is available bind it's function pointers         if (alIsExtensionPresent((ALubyte*)"EAX" ))            bindEAXFunctions();         return(true);      }      // an error occured, shutdown      OpenALDLLShutdown();   }   else   {      Con::errorf(ConsoleLogEntry::General, " Error loading OpenAL Library: %s", dlerror());   }   return(false);}} // end namespace Audio#endif //0
 |