Quake II RTX doxygen  1.0 dev
dynamic.c File Reference
#include "shared/shared.h"
#include "system/system.h"
#include "common/cvar.h"
#include "common/common.h"
#include "common/files.h"
#include "dynamic.h"
#include <AL/alc.h>

Go to the source code of this file.

Macros

#define QALC_IMP
 
#define QAL(type, func)   static type q##func
 
#define QAL(type, func)   type q##func
 
#define QAL(type, func)   q##func = NULL
 
#define QAL(type, func)   if ((q##func = Sys_GetProcAddress(handle, #func)) == NULL) goto fail;
 

Functions

QAL_IMP void QAL_Shutdown (void)
 
qboolean QAL_Init (void)
 

Variables

static cvar_t * al_driver
 
static cvar_t * al_device
 
static voidhandle
 
static ALCdevice * device
 
static ALCcontext * context
 

Macro Definition Documentation

◆ QAL [1/4]

#define QAL (   type,
  func 
)    static type q##func

Definition at line 60 of file dynamic.c.

◆ QAL [2/4]

#define QAL (   type,
  func 
)    type q##func

Definition at line 60 of file dynamic.c.

◆ QAL [3/4]

#define QAL (   type,
  func 
)    q##func = NULL

Definition at line 60 of file dynamic.c.

◆ QAL [4/4]

#define QAL (   type,
  func 
)    if ((q##func = Sys_GetProcAddress(handle, #func)) == NULL) goto fail;

Definition at line 60 of file dynamic.c.

◆ QALC_IMP

#define QALC_IMP
Value:
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);

Definition at line 27 of file dynamic.c.

Function Documentation

◆ QAL_Init()

qboolean QAL_Init ( void  )

Definition at line 92 of file dynamic.c.

93 {
94  al_driver = Cvar_Get("al_driver", LIBAL, 0);
95  al_device = Cvar_Get("al_device", "", 0);
96 
97  // don't allow absolute or relative paths
99 
100  Sys_LoadLibrary(al_driver->string, NULL, &handle);
101  if (!handle) {
102  return qfalse;
103  }
104 
105 #define QAL(type, func) if ((q##func = Sys_GetProcAddress(handle, #func)) == NULL) goto fail;
106  QALC_IMP
107  QAL_IMP
108 #undef QAL
109 
110  device = qalcOpenDevice(al_device->string[0] ? al_device->string : NULL);
111  if (!device) {
112  Com_SetLastError(va("alcOpenDevice(%s) failed", al_device->string));
113  goto fail;
114  }
115 
116  context = qalcCreateContext(device, NULL);
117  if (!context) {
118  Com_SetLastError("alcCreateContext failed");
119  goto fail;
120  }
121 
122  if (!qalcMakeContextCurrent(context)) {
123  Com_SetLastError("alcMakeContextCurrent failed");
124  goto fail;
125  }
126 
127  al_driver->flags |= CVAR_SOUND;
128  al_device->flags |= CVAR_SOUND;
129 
130  return qtrue;
131 
132 fail:
133  QAL_Shutdown();
134  return qfalse;
135 }

Referenced by AL_Init().

◆ QAL_Shutdown()

QAL_IMP void QAL_Shutdown ( void  )

Definition at line 64 of file dynamic.c.

65 {
66  if (context) {
67  qalcMakeContextCurrent(NULL);
68  qalcDestroyContext(context);
69  context = NULL;
70  }
71  if (device) {
72  qalcCloseDevice(device);
73  device = NULL;
74  }
75 
76 #define QAL(type, func) q##func = NULL
77  QALC_IMP
78  QAL_IMP
79 #undef QAL
80 
81  if (handle) {
83  handle = NULL;
84  }
85 
86  if (al_driver)
87  al_driver->flags &= ~CVAR_SOUND;
88  if (al_device)
89  al_device->flags &= ~CVAR_SOUND;
90 }

Referenced by AL_Init(), AL_Shutdown(), and QAL_Init().

Variable Documentation

◆ al_device

cvar_t* al_device
static

Definition at line 50 of file dynamic.c.

Referenced by QAL_Init(), and QAL_Shutdown().

◆ al_driver

cvar_t* al_driver
static

Definition at line 49 of file dynamic.c.

Referenced by QAL_Init(), and QAL_Shutdown().

◆ context

ALCcontext* context
static

Definition at line 54 of file dynamic.c.

Referenced by QAL_Init(), QAL_Shutdown(), stbi_write(), and Sys_ExceptionFilter().

◆ device

ALCdevice* device
static

Definition at line 53 of file dynamic.c.

Referenced by create_device_memory_allocator(), QAL_Init(), and QAL_Shutdown().

◆ handle

handle
static void * handle
Definition: dynamic.c:52
al_device
static cvar_t * al_device
Definition: dynamic.c:50
QAL_IMP
#define QAL_IMP
Definition: dynamic.h:27
QAL_Shutdown
QAL_IMP void QAL_Shutdown(void)
Definition: dynamic.c:64
Cvar_Get
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
Definition: cvar.c:257
QAL
#define QAL(type, func)
Definition: dynamic.c:60
device
static ALCdevice * device
Definition: dynamic.c:53
QALC_IMP
#define QALC_IMP
Definition: dynamic.c:27
al_driver
static cvar_t * al_driver
Definition: dynamic.c:49
va
char * va(const char *format,...)
Definition: shared.c:429
Sys_LoadLibrary
void * Sys_LoadLibrary(const char *path, const char *sym, void **handle)
Definition: system.c:794
FS_SanitizeFilenameVariable
void FS_SanitizeFilenameVariable(cvar_t *var)
Definition: files.c:294
context
static ALCcontext * context
Definition: dynamic.c:54
Com_SetLastError
void Com_SetLastError(const char *msg)
Definition: common.c:382
Sys_FreeLibrary
void Sys_FreeLibrary(void *handle)
Definition: system.c:787