Rework qal_api.c and qal_api.h:

- Reformat to match "our" coding style
- Unroll all unreadable macros
- Remove the use of goto
This commit is contained in:
Yamagi Burmeister 2012-04-24 13:22:05 +00:00
parent 4ff4bf09e9
commit 79c137254a
2 changed files with 499 additions and 197 deletions

View file

@ -1,107 +1,118 @@
/*
This Source File was taken from the Q2Pro Port.
* Copyright (C) 2012 Yamagi Burmeister
* Copyright (C) 2010 skuller.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* =======================================================================
*
* Header file to the low level "qal" API implementation. This source file
* was taken from Q2Pro and modified by the YQ2 authors.
*
* =======================================================================
*/
Copyright (C) 2010 skuller.net
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define AL_NO_PROTOTYPES
#include <AL/al.h>
#define QAL_IMP \
QAL( LPALENABLE, alEnable ); \
QAL( LPALDISABLE, alDisable ); \
QAL( LPALISENABLED, alIsEnabled ); \
QAL( LPALGETSTRING, alGetString ); \
QAL( LPALGETBOOLEANV, alGetBooleanv ); \
QAL( LPALGETINTEGERV, alGetIntegerv ); \
QAL( LPALGETFLOATV, alGetFloatv ); \
QAL( LPALGETDOUBLEV, alGetDoublev ); \
QAL( LPALGETBOOLEAN, alGetBoolean ); \
QAL( LPALGETINTEGER, alGetInteger ); \
QAL( LPALGETFLOAT, alGetFloat ); \
QAL( LPALGETDOUBLE, alGetDouble ); \
QAL( LPALGETERROR, alGetError ); \
QAL( LPALISEXTENSIONPRESENT, alIsExtensionPresent ); \
QAL( LPALGETPROCADDRESS, alGetProcAddress ); \
QAL( LPALGETENUMVALUE, alGetEnumValue ); \
QAL( LPALLISTENERF, alListenerf ); \
QAL( LPALLISTENER3F, alListener3f ); \
QAL( LPALLISTENERFV, alListenerfv ); \
QAL( LPALLISTENERI, alListeneri ); \
QAL( LPALLISTENER3I, alListener3i ); \
QAL( LPALLISTENERIV, alListeneriv ); \
QAL( LPALGETLISTENERF, alGetListenerf ); \
QAL( LPALGETLISTENER3F, alGetListener3f ); \
QAL( LPALGETLISTENERFV, alGetListenerfv ); \
QAL( LPALGETLISTENERI, alGetListeneri ); \
QAL( LPALGETLISTENER3I, alGetListener3i ); \
QAL( LPALGETLISTENERIV, alGetListeneriv ); \
QAL( LPALGENSOURCES, alGenSources ); \
QAL( LPALDELETESOURCES, alDeleteSources ); \
QAL( LPALISSOURCE, alIsSource ); \
QAL( LPALSOURCEF, alSourcef ); \
QAL( LPALSOURCE3F, alSource3f ); \
QAL( LPALSOURCEFV, alSourcefv ); \
QAL( LPALSOURCEI, alSourcei ); \
QAL( LPALSOURCE3I, alSource3i ); \
QAL( LPALSOURCEIV, alSourceiv ); \
QAL( LPALGETSOURCEF, alGetSourcef ); \
QAL( LPALGETSOURCE3F, alGetSource3f ); \
QAL( LPALGETSOURCEFV, alGetSourcefv ); \
QAL( LPALGETSOURCEI, alGetSourcei ); \
QAL( LPALGETSOURCE3I, alGetSource3i ); \
QAL( LPALGETSOURCEIV, alGetSourceiv ); \
QAL( LPALSOURCEPLAYV, alSourcePlayv ); \
QAL( LPALSOURCESTOPV, alSourceStopv ); \
QAL( LPALSOURCEREWINDV, alSourceRewindv ); \
QAL( LPALSOURCEPAUSEV, alSourcePausev ); \
QAL( LPALSOURCEPLAY, alSourcePlay ); \
QAL( LPALSOURCESTOP, alSourceStop ); \
QAL( LPALSOURCEREWIND, alSourceRewind ); \
QAL( LPALSOURCEPAUSE, alSourcePause ); \
QAL( LPALSOURCEQUEUEBUFFERS, alSourceQueueBuffers ); \
QAL( LPALSOURCEUNQUEUEBUFFERS, alSourceUnqueueBuffers ); \
QAL( LPALGENBUFFERS, alGenBuffers ); \
QAL( LPALDELETEBUFFERS, alDeleteBuffers ); \
QAL( LPALISBUFFER, alIsBuffer ); \
QAL( LPALBUFFERDATA, alBufferData ); \
QAL( LPALBUFFERF, alBufferf ); \
QAL( LPALBUFFER3F, alBuffer3f ); \
QAL( LPALBUFFERFV, alBufferfv ); \
QAL( LPALBUFFERI, alBufferi ); \
QAL( LPALBUFFER3I, alBuffer3i ); \
QAL( LPALBUFFERIV, alBufferiv ); \
QAL( LPALGETBUFFERF, alGetBufferf ); \
QAL( LPALGETBUFFER3F, alGetBuffer3f ); \
QAL( LPALGETBUFFERFV, alGetBufferfv ); \
QAL( LPALGETBUFFERI, alGetBufferi ); \
QAL( LPALGETBUFFER3I, alGetBuffer3i ); \
QAL( LPALGETBUFFERIV, alGetBufferiv ); \
QAL( LPALDOPPLERFACTOR, alDopplerFactor ); \
QAL( LPALDOPPLERVELOCITY, alDopplerVelocity ); \
QAL( LPALSPEEDOFSOUND, alSpeedOfSound ); \
QAL( LPALDISTANCEMODEL, alDistanceModel );
#define QAL(type,func) extern type q##func;
QAL_IMP
#undef QAL
/* Function pointers used to tie
the qal API to the OpenAL API */
extern LPALENABLE qalEnable;
extern LPALDISABLE qalDisable;
extern LPALISENABLED qalIsEnabled;
extern LPALGETSTRING qalGetString;
extern LPALGETBOOLEANV qalGetBooleanv;
extern LPALGETINTEGERV qalGetIntegerv;
extern LPALGETFLOATV qalGetFloatv;
extern LPALGETDOUBLEV qalGetDoublev;
extern LPALGETBOOLEAN qalGetBoolean;
extern LPALGETINTEGER qalGetInteger;
extern LPALGETFLOAT qalGetFloat;
extern LPALGETDOUBLE qalGetDouble;
extern LPALGETERROR qalGetError;
extern LPALISEXTENSIONPRESENT qalIsExtensionPresent;
extern LPALGETPROCADDRESS qalGetProcAddress;
extern LPALGETENUMVALUE qalGetEnumValue;
extern LPALLISTENERF qalListenerf;
extern LPALLISTENER3F qalListener3f;
extern LPALLISTENERFV qalListenerfv;
extern LPALLISTENERI qalListeneri;
extern LPALLISTENER3I qalListener3i;
extern LPALLISTENERIV qalListeneriv;
extern LPALGETLISTENERF qalGetListenerf;
extern LPALGETLISTENER3F qalGetListener3f;
extern LPALGETLISTENERFV qalGetListenerfv;
extern LPALGETLISTENERI qalGetListeneri;
extern LPALGETLISTENER3I qalGetListener3i;
extern LPALGETLISTENERIV qalGetListeneriv;
extern LPALGENSOURCES qalGenSources;
extern LPALDELETESOURCES qalDeleteSources;
extern LPALISSOURCE qalIsSource;
extern LPALSOURCEF qalSourcef;
extern LPALSOURCE3F qalSource3f;
extern LPALSOURCEFV qalSourcefv;
extern LPALSOURCEI qalSourcei;
extern LPALSOURCE3I qalSource3i;
extern LPALSOURCEIV qalSourceiv;
extern LPALGETSOURCEF qalGetSourcef;
extern LPALGETSOURCE3F qalGetSource3f;
extern LPALGETSOURCEFV qalGetSourcefv;
extern LPALGETSOURCEI qalGetSourcei;
extern LPALGETSOURCE3I qalGetSource3i;
extern LPALGETSOURCEIV qalGetSourceiv;
extern LPALSOURCEPLAYV qalSourcePlayv;
extern LPALSOURCESTOPV qalSourceStopv;
extern LPALSOURCEREWINDV qalSourceRewindv;
extern LPALSOURCEPAUSEV qalSourcePausev;
extern LPALSOURCEPLAY qalSourcePlay;
extern LPALSOURCESTOP qalSourceStop;
extern LPALSOURCEREWIND qalSourceRewind;
extern LPALSOURCEPAUSE qalSourcePause;
extern LPALSOURCEQUEUEBUFFERS qalSourceQueueBuffers;
extern LPALSOURCEUNQUEUEBUFFERS qalSourceUnqueueBuffers;
extern LPALGENBUFFERS qalGenBuffers;
extern LPALDELETEBUFFERS qalDeleteBuffers;
extern LPALISBUFFER qalIsBuffer;
extern LPALBUFFERDATA qalBufferData;
extern LPALBUFFERF qalBufferf;
extern LPALBUFFER3F qalBuffer3f;
extern LPALBUFFERFV qalBufferfv;
extern LPALBUFFERI qalBufferi;
extern LPALBUFFER3I qalBuffer3i;
extern LPALBUFFERIV qalBufferiv;
extern LPALGETBUFFERF qalGetBufferf;
extern LPALGETBUFFER3F qalGetBuffer3f;
extern LPALGETBUFFERFV qalGetBufferfv;
extern LPALGETBUFFERI qalGetBufferi;
extern LPALGETBUFFER3I qalGetBuffer3i;
extern LPALGETBUFFERIV qalGetBufferiv;
extern LPALDOPPLERFACTOR qalDopplerFactor;
extern LPALDOPPLERVELOCITY qalDopplerVelocity;
extern LPALSPEEDOFSOUND qalSpeedOfSound;
extern LPALDISTANCEMODEL qalDistanceModel;
/*
* Loads the OpenAL shared lib, creates
* a context and device handle.
*/
qboolean QAL_Init( void );
/*
* Shuts OpenAL down, frees all context and
* device handles and unloads the shared lib.
*/
void QAL_Shutdown( void );

View file

@ -1,136 +1,427 @@
/*
This Source File was taken from the Q2Pro Port.
* Copyright (C) 2012 Yamagi Burmeister
* Copyright (C) 2010 skuller.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* =======================================================================
*
* Low level, platform depended "qal" API implementation. This files
* provides functions to load, initialize, shutdown und unload the
* OpenAL library and connects the "qal" funtion pointers to the
* OpenAL functions. This source file was taken from Q2Pro and
* modified by the YQ2 authors.
*
* =======================================================================
*/
Copyright (C) 2010 skuller.net
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <dlfcn.h>
#include <AL/alc.h>
#include "../../common/header/common.h"
#include "header/qal_api.h"
#include <AL/alc.h>
#include <dlfcn.h>
#define QALC_IMP \
QAL( LPALCCREATECONTEXT, alcCreateContext ); \
QAL( LPALCMAKECONTEXTCURRENT, alcMakeContextCurrent ); \
QAL( LPALCPROCESSCONTEXT, alcProcessContext ); \
QAL( LPALCSUSPENDCONTEXT, alcSuspendContext ); \
QAL( LPALCDESTROYCONTEXT, alcDestroyContext ); \
QAL( LPALCGETCURRENTCONTEXT, alcGetCurrentContext ); \
QAL( LPALCGETCONTEXTSDEVICE, alcGetContextsDevice ); \
QAL( LPALCOPENDEVICE, alcOpenDevice ); \
QAL( LPALCCLOSEDEVICE, alcCloseDevice ); \
QAL( LPALCGETERROR, alcGetError ); \
QAL( LPALCISEXTENSIONPRESENT, alcIsExtensionPresent ); \
QAL( LPALCGETPROCADDRESS, alcGetProcAddress ); \
QAL( LPALCGETENUMVALUE, alcGetEnumValue ); \
QAL( LPALCGETSTRING, alcGetString ); \
QAL( LPALCGETINTEGERV, alcGetIntegerv ); \
QAL( LPALCCAPTUREOPENDEVICE, alcCaptureOpenDevice ); \
QAL( LPALCCAPTURECLOSEDEVICE, alcCaptureCloseDevice ); \
QAL( LPALCCAPTURESTART, alcCaptureStart ); \
QAL( LPALCCAPTURESTOP, alcCaptureStop ); \
QAL( LPALCCAPTURESAMPLES, alcCaptureSamples );
static cvar_t *al_driver;
static cvar_t *al_device;
static void *handle;
static ALCdevice *device;
static ALCcontext *context;
static ALCdevice *device;
static cvar_t *al_device;
static cvar_t *al_driver;
static void *handle;
#define QAL(type,func) static type q##func;
QALC_IMP
#undef QAL
/* Function pointers for OpenAL management */
static LPALCCREATECONTEXT qalcCreateContext;
static LPALCMAKECONTEXTCURRENT qalcMakeContextCurrent;
static LPALCPROCESSCONTEXT qalcProcessContext;
static LPALCSUSPENDCONTEXT qalcSuspendContext;
static LPALCDESTROYCONTEXT qalcDestroyContext;
static LPALCGETCURRENTCONTEXT qalcGetCurrentContext;
static LPALCGETCONTEXTSDEVICE qalcGetContextsDevice;
static LPALCOPENDEVICE qalcOpenDevice;
static LPALCCLOSEDEVICE qalcCloseDevice;
static LPALCGETERROR qalcGetError;
static LPALCISEXTENSIONPRESENT qalcIsExtensionPresent;
static LPALCGETPROCADDRESS qalcGetProcAddress;
static LPALCGETENUMVALUE qalcGetEnumValue;
static LPALCGETSTRING qalcGetString;
static LPALCGETINTEGERV qalcGetIntegerv;
static LPALCCAPTUREOPENDEVICE qalcCaptureOpenDevice;
static LPALCCAPTURECLOSEDEVICE qalcCaptureCloseDevice;
static LPALCCAPTURESTART qalcCaptureStart;
static LPALCCAPTURESTOP qalcCaptureStop;
static LPALCCAPTURESAMPLES qalcCaptureSamples ;
#define QAL(type,func) type q##func;
QAL_IMP
#undef QAL
void QAL_Shutdown( void ) {
if( context ) {
/* Declaration of function pointers used
to connect OpenAL to our internal API */
LPALENABLE qalEnable;
LPALDISABLE qalDisable;
LPALISENABLED qalIsEnabled;
LPALGETSTRING qalGetString;
LPALGETBOOLEANV qalGetBooleanv;
LPALGETINTEGERV qalGetIntegerv;
LPALGETFLOATV qalGetFloatv;
LPALGETDOUBLEV qalGetDoublev;
LPALGETBOOLEAN qalGetBoolean;
LPALGETINTEGER qalGetInteger;
LPALGETFLOAT qalGetFloat;
LPALGETDOUBLE qalGetDouble;
LPALGETERROR qalGetError;
LPALISEXTENSIONPRESENT qalIsExtensionPresent;
LPALGETPROCADDRESS qalGetProcAddress;
LPALGETENUMVALUE qalGetEnumValue;
LPALLISTENERF qalListenerf;
LPALLISTENER3F qalListener3f;
LPALLISTENERFV qalListenerfv;
LPALLISTENERI qalListeneri;
LPALLISTENER3I qalListener3i;
LPALLISTENERIV qalListeneriv;
LPALGETLISTENERF qalGetListenerf;
LPALGETLISTENER3F qalGetListener3f;
LPALGETLISTENERFV qalGetListenerfv;
LPALGETLISTENERI qalGetListeneri;
LPALGETLISTENER3I qalGetListener3i;
LPALGETLISTENERIV qalGetListeneriv;
LPALGENSOURCES qalGenSources;
LPALDELETESOURCES qalDeleteSources;
LPALISSOURCE qalIsSource;
LPALSOURCEF qalSourcef;
LPALSOURCE3F qalSource3f;
LPALSOURCEFV qalSourcefv;
LPALSOURCEI qalSourcei;
LPALSOURCE3I qalSource3i;
LPALSOURCEIV qalSourceiv;
LPALGETSOURCEF qalGetSourcef;
LPALGETSOURCE3F qalGetSource3f;
LPALGETSOURCEFV qalGetSourcefv;
LPALGETSOURCEI qalGetSourcei;
LPALGETSOURCE3I qalGetSource3i;
LPALGETSOURCEIV qalGetSourceiv;
LPALSOURCEPLAYV qalSourcePlayv;
LPALSOURCESTOPV qalSourceStopv;
LPALSOURCEREWINDV qalSourceRewindv;
LPALSOURCEPAUSEV qalSourcePausev;
LPALSOURCEPLAY qalSourcePlay;
LPALSOURCESTOP qalSourceStop;
LPALSOURCEREWIND qalSourceRewind;
LPALSOURCEPAUSE qalSourcePause;
LPALSOURCEQUEUEBUFFERS qalSourceQueueBuffers;
LPALSOURCEUNQUEUEBUFFERS qalSourceUnqueueBuffers;
LPALGENBUFFERS qalGenBuffers;
LPALDELETEBUFFERS qalDeleteBuffers;
LPALISBUFFER qalIsBuffer;
LPALBUFFERDATA qalBufferData;
LPALBUFFERF qalBufferf;
LPALBUFFER3F qalBuffer3f;
LPALBUFFERFV qalBufferfv;
LPALBUFFERI qalBufferi;
LPALBUFFER3I qalBuffer3i;
LPALBUFFERIV qalBufferiv;
LPALGETBUFFERF qalGetBufferf;
LPALGETBUFFER3F qalGetBuffer3f;
LPALGETBUFFERFV qalGetBufferfv;
LPALGETBUFFERI qalGetBufferi;
LPALGETBUFFER3I qalGetBuffer3i;
LPALGETBUFFERIV qalGetBufferiv;
LPALDOPPLERFACTOR qalDopplerFactor;
LPALDOPPLERVELOCITY qalDopplerVelocity;
LPALSPEEDOFSOUND qalSpeedOfSound;
LPALDISTANCEMODEL qalDistanceModel;
/*
* Shuts OpenAL down, frees all context and
* device handles and unloads the shared lib.
*/
void
QAL_Shutdown()
{
if (context)
{
qalcMakeContextCurrent( NULL );
qalcDestroyContext( context );
context = NULL;
}
if( device ) {
if (device)
{
qalcCloseDevice( device );
device = NULL;
}
#define QAL(type,func) q##func = NULL;
QALC_IMP
QAL_IMP
#undef QAL
/* Disconnect function pointers used
for OpenAL management calls */
qalcCreateContext = NULL;
qalcMakeContextCurrent = NULL;
qalcProcessContext = NULL;
qalcSuspendContext = NULL;
qalcDestroyContext = NULL;
qalcGetCurrentContext = NULL;
qalcGetContextsDevice = NULL;
qalcOpenDevice = NULL;
qalcCloseDevice = NULL;
qalcGetError = NULL;
qalcIsExtensionPresent = NULL;
qalcGetProcAddress = NULL;
qalcGetEnumValue = NULL;
qalcGetString = NULL;
qalcGetIntegerv = NULL;
qalcCaptureOpenDevice = NULL;
qalcCaptureCloseDevice = NULL;
qalcCaptureStart = NULL;
qalcCaptureStop = NULL;
qalcCaptureSamples = NULL;
//Sys_FreeLibrary( handle );
/* Disconnect OpenAL
* function pointers */
qalEnable = NULL;
qalDisable = NULL;
qalIsEnabled = NULL;
qalGetString = NULL;
qalGetBooleanv = NULL;
qalGetIntegerv = NULL;
qalGetFloatv = NULL;
qalGetDoublev = NULL;
qalGetBoolean = NULL;
qalGetInteger = NULL;
qalGetFloat = NULL;
qalGetDouble = NULL;
qalGetError = NULL;
qalIsExtensionPresent = NULL;
qalGetProcAddress = NULL;
qalGetEnumValue = NULL;
qalListenerf = NULL;
qalListener3f = NULL;
qalListenerfv = NULL;
qalListeneri = NULL;
qalListener3i = NULL;
qalListeneriv = NULL;
qalGetListenerf = NULL;
qalGetListener3f = NULL;
qalGetListenerfv = NULL;
qalGetListeneri = NULL;
qalGetListener3i = NULL;
qalGetListeneriv = NULL;
qalGenSources = NULL;
qalDeleteSources = NULL;
qalIsSource = NULL;
qalSourcef = NULL;
qalSource3f = NULL;
qalSourcefv = NULL;
qalSourcei = NULL;
qalSource3i = NULL;
qalSourceiv = NULL;
qalGetSourcef = NULL;
qalGetSource3f = NULL;
qalGetSourcefv = NULL;
qalGetSourcei = NULL;
qalGetSource3i = NULL;
qalGetSourceiv = NULL;
qalSourcePlayv = NULL;
qalSourceStopv = NULL;
qalSourceRewindv = NULL;
qalSourcePausev = NULL;
qalSourcePlay = NULL;
qalSourceStop = NULL;
qalSourceRewind = NULL;
qalSourcePause = NULL;
qalSourceQueueBuffers = NULL;
qalSourceUnqueueBuffers = NULL;
qalGenBuffers = NULL;
qalDeleteBuffers = NULL;
qalIsBuffer = NULL;
qalBufferData = NULL;
qalBufferf = NULL;
qalBuffer3f = NULL;
qalBufferfv = NULL;
qalBufferi = NULL;
qalBuffer3i = NULL;
qalBufferiv = NULL;
qalGetBufferf = NULL;
qalGetBuffer3f = NULL;
qalGetBufferfv = NULL;
qalGetBufferi = NULL;
qalGetBuffer3i = NULL;
qalGetBufferiv = NULL;
qalDopplerFactor = NULL;
qalDopplerVelocity = NULL;
qalSpeedOfSound = NULL;
qalDistanceModel = NULL;
/* Unload the shared lib */
dlclose(handle);
handle = NULL;
al_driver->flags &= ~CVAR_ARCHIVE;
al_device->flags &= ~CVAR_ARCHIVE;
}
qboolean QAL_Init( void ) {
// DEFAULT_OPENAL_DRIVER is a define from the Makefile
/*
* Loads the OpenAL shared lib, creates
* a context and device handle.
*/
qboolean
QAL_Init()
{
/* DEFAULT_OPENAL_DRIVER is defined at compile time via the compiler */
al_driver = Cvar_Get( "al_driver", DEFAULT_OPENAL_DRIVER, CVAR_ARCHIVE );
al_device = Cvar_Get( "al_device", "", CVAR_ARCHIVE );
Com_Printf("LoadLibrary(%s)\n", al_driver->string);
/* Load the library */
handle = dlopen( al_driver->string, RTLD_LAZY );
//Sys_LoadLibrary( al_driver->string, NULL, &handle );
if( !handle ) {
if (!handle)
{
return false;
}
#define QAL(type,func) q##func = dlsym( handle, #func );
QALC_IMP
QAL_IMP
#undef QAL
/* Connect function pointers to management functions */
qalcCreateContext = dlsym(handle, "alcCreateContext");
qalcMakeContextCurrent = dlsym(handle, "alcMakeContextCurrent");
qalcProcessContext = dlsym(handle, "alcProcessContext");
qalcSuspendContext = dlsym(handle, "alcSuspendContext");
qalcDestroyContext = dlsym(handle, "alcDestroyContext");
qalcGetCurrentContext = dlsym(handle, "alcGetCurrentContext");
qalcGetContextsDevice = dlsym(handle, "alcGetContextsDevice");
qalcOpenDevice = dlsym(handle, "alcOpenDevice");
qalcCloseDevice = dlsym(handle, "alcCloseDevice");
qalcGetError = dlsym(handle, "alcGetError");
qalcIsExtensionPresent = dlsym(handle, "alcIsExtensionPresent");
qalcGetProcAddress = dlsym(handle, "alcGetProcAddress");
qalcGetEnumValue = dlsym(handle, "alcGetEnumValue");
qalcGetString = dlsym(handle, "alcGetString");
qalcGetIntegerv = dlsym(handle, "alcGetIntegerv");
qalcCaptureOpenDevice = dlsym(handle, "alcCaptureOpenDevice");
qalcCaptureCloseDevice = dlsym(handle, "alcCaptureCloseDevice");
qalcCaptureStart = dlsym(handle, "alcCaptureStart");
qalcCaptureStop = dlsym(handle, "alcCaptureStop");
qalcCaptureSamples = dlsym(handle, "alcCaptureSamples");
Com_Printf( "...opening OpenAL device: " );
device = qalcOpenDevice( al_device->string[0] ? al_device->string : NULL );
if( !device ) {
goto fail;
}
Com_Printf( "ok\n" );
/* Connect function pointers to
to OpenAL API functions */
qalEnable = dlsym(handle, "alEnable");
qalDisable = dlsym(handle, "alDisable");
qalIsEnabled = dlsym(handle, "alIsEnabled");
qalGetString = dlsym(handle, "alGetString");
qalGetBooleanv = dlsym(handle, "alGetBooleanv");
qalGetIntegerv = dlsym(handle, "alGetIntegerv");
qalGetFloatv = dlsym(handle, "alGetFloatv");
qalGetDoublev = dlsym(handle, "alGetDoublev");
qalGetBoolean = dlsym(handle, "alGetBoolean");
qalGetInteger = dlsym(handle, "alGetInteger");
qalGetFloat = dlsym(handle, "alGetFloat");
qalGetDouble = dlsym(handle, "alGetDouble");
qalGetError = dlsym(handle, "alGetError");
qalIsExtensionPresent = dlsym(handle, "alIsExtensionPresent");
qalGetProcAddress = dlsym(handle, "alGetProcAddress");
qalGetEnumValue = dlsym(handle, "alGetEnumValue");
qalListenerf = dlsym(handle, "alListenerf");
qalListener3f = dlsym(handle, "alListener3f");
qalListenerfv = dlsym(handle, "alListenerfv");
qalListeneri = dlsym(handle, "alListeneri");
qalListener3i = dlsym(handle, "alListener3i");
qalListeneriv = dlsym(handle, "alListeneriv");
qalGetListenerf = dlsym(handle, "alGetListenerf");
qalGetListener3f = dlsym(handle, "alGetListener3f");
qalGetListenerfv = dlsym(handle, "alGetListenerfv");
qalGetListeneri = dlsym(handle, "alGetListeneri");
qalGetListener3i = dlsym(handle, "alGetListener3i");
qalGetListeneriv = dlsym(handle, "alGetListeneriv");
qalGenSources = dlsym(handle, "alGenSources");
qalDeleteSources = dlsym(handle, "alDeleteSources");
qalIsSource = dlsym(handle, "alIsSource");
qalSourcef = dlsym(handle, "alSourcef");
qalSource3f = dlsym(handle, "alSource3f");
qalSourcefv = dlsym(handle, "alSourcefv");
qalSourcei = dlsym(handle, "alSourcei");
qalSource3i = dlsym(handle, "alSource3i");
qalSourceiv = dlsym(handle, "alSourceiv");
qalGetSourcef = dlsym(handle, "alGetSourcef");
qalGetSource3f = dlsym(handle, "alGetSource3f");
qalGetSourcefv = dlsym(handle, "alGetSourcefv");
qalGetSourcei = dlsym(handle, "alGetSourcei");
qalGetSource3i = dlsym(handle, "alGetSource3i");
qalGetSourceiv = dlsym(handle, "alGetSourceiv");
qalSourcePlayv = dlsym(handle, "alSourcePlayv");
qalSourceStopv = dlsym(handle, "alSourceStopv");
qalSourceRewindv = dlsym(handle, "alSourceRewindv");
qalSourcePausev = dlsym(handle, "alSourcePausev");
qalSourcePlay = dlsym(handle, "alSourcePlay");
qalSourceStop = dlsym(handle, "alSourceStop");
qalSourceRewind = dlsym(handle, "alSourceRewind");
qalSourcePause = dlsym(handle, "alSourcePause");
qalSourceQueueBuffers = dlsym(handle, "alSourceQueueBuffers");
qalSourceUnqueueBuffers = dlsym(handle, "alSourceUnqueueBuffers");
qalGenBuffers = dlsym(handle, "alGenBuffers");
qalDeleteBuffers = dlsym(handle, "alDeleteBuffers");
qalIsBuffer = dlsym(handle, "alIsBuffer");
qalBufferData = dlsym(handle, "alBufferData");
qalBufferf = dlsym(handle, "alBufferf");
qalBuffer3f = dlsym(handle, "alBuffer3f");
qalBufferfv = dlsym(handle, "alBufferfv");
qalBufferi = dlsym(handle, "alBufferi");
qalBuffer3i = dlsym(handle, "alBuffer3i");
qalBufferiv = dlsym(handle, "alBufferiv");
qalGetBufferf = dlsym(handle, "alGetBufferf");
qalGetBuffer3f = dlsym(handle, "alGetBuffer3f");
qalGetBufferfv = dlsym(handle, "alGetBufferfv");
qalGetBufferi = dlsym(handle, "alGetBufferi");
qalGetBuffer3i = dlsym(handle, "alGetBuffer3i");
qalGetBufferiv = dlsym(handle, "alGetBufferiv");
qalDopplerFactor = dlsym(handle, "alDopplerFactor");
qalDopplerVelocity = dlsym(handle, "alDopplerVelocity");
qalSpeedOfSound = dlsym(handle, "alSpeedOfSound");
qalDistanceModel = dlsym(handle, "alDistanceModel");
Com_Printf( "...creating OpenAL context: " );
context = qalcCreateContext( device, NULL );
if( !context ) {
goto fail;
}
Com_Printf( "ok\n" );
/* Open the OpenAL device */
Com_Printf("...opening OpenAL device:");
device = qalcOpenDevice(al_device->string[0] ? al_device->string : NULL);
Com_Printf( "...making context current: " );
if( !qalcMakeContextCurrent( context ) ) {
goto fail;
}
Com_Printf( "ok\n" );
if(!device)
{
Com_DPrintf("failed\n");
QAL_Shutdown();
return false;
}
al_driver->flags |= CVAR_ARCHIVE;
al_device->flags |= CVAR_ARCHIVE;
Com_Printf("ok\n");
/* Create the OpenAL context */
Com_Printf("...creating OpenAL context: ");
context = qalcCreateContext(device, NULL);
if(!context)
{
Com_DPrintf("failed\n");
QAL_Shutdown();
return false;
}
Com_Printf("ok\n");
/* Set the created context as current context */
Com_Printf("...making context current: ");
if (!qalcMakeContextCurrent(context))
{
Com_DPrintf("failed\n");
QAL_Shutdown();
return false;
}
Com_Printf("ok\n");
return true;
fail:
Com_DPrintf( "failed\n" );
QAL_Shutdown();
return false;
}