Quake II RTX doxygen  1.0 dev
fixed.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 2013 Andrey Nazarov
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 
19 #include "shared/shared.h"
20 #include "common/cvar.h"
21 #include "common/common.h"
22 #include "fixed.h"
23 #include <AL/alc.h>
24 
25 static cvar_t *al_device;
26 
27 static ALCdevice *device;
28 static ALCcontext *context;
29 
30 void QAL_Shutdown(void)
31 {
32  if (context) {
33  alcMakeContextCurrent(NULL);
34  alcDestroyContext(context);
35  context = NULL;
36  }
37  if (device) {
38  alcCloseDevice(device);
39  device = NULL;
40  }
41 
42  if (al_device)
43  al_device->flags &= ~CVAR_SOUND;
44 }
45 
46 qboolean QAL_Init(void)
47 {
48  al_device = Cvar_Get("al_device", "", 0);
49 
50  device = alcOpenDevice(al_device->string[0] ? al_device->string : NULL);
51  if (!device) {
52  Com_SetLastError(va("alcOpenDevice(%s) failed", al_device->string));
53  goto fail;
54  }
55 
56  context = alcCreateContext(device, NULL);
57  if (!context) {
58  Com_SetLastError("alcCreateContext failed");
59  goto fail;
60  }
61 
62  if (!alcMakeContextCurrent(context)) {
63  Com_SetLastError("alcMakeContextCurrent failed");
64  goto fail;
65  }
66 
67  al_device->flags |= CVAR_SOUND;
68 
69  return qtrue;
70 
71 fail:
72  QAL_Shutdown();
73  return qfalse;
74 }
Cvar_Get
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
Definition: cvar.c:257
device
static ALCdevice * device
Definition: fixed.c:27
fixed.h
al_device
static cvar_t * al_device
Definition: fixed.c:25
va
char * va(const char *format,...)
Definition: shared.c:429
QAL_Shutdown
void QAL_Shutdown(void)
Definition: fixed.c:30
context
static ALCcontext * context
Definition: fixed.c:28
QAL_Init
qboolean QAL_Init(void)
Definition: fixed.c:46
Com_SetLastError
void Com_SetLastError(const char *msg)
Definition: common.c:382