1
#include "alutInternal.h"
5
Unintialized, /* ALUT has not been initialized yet or has been de-initialised */
6
ALUTDeviceAndContext, /* alutInit has been called successfully */
7
ExternalDeviceAndContext /* alutInitWithoutContext has been called */
8
} initialisationState = Unintialized;
11
* Note: alutContext contains something valid only when initialisationState
12
* contains ALUTDeviceAndContext.
14
static ALCcontext *alutContext;
16
ALboolean _alutSanityCheck(void)
20
if (initialisationState == Unintialized)
22
_alutSetError(ALUT_ERROR_INVALID_OPERATION);
26
context = alcGetCurrentContext();
29
_alutSetError(ALUT_ERROR_NO_CURRENT_CONTEXT);
33
if (alGetError() != AL_NO_ERROR)
35
_alutSetError(ALUT_ERROR_AL_ERROR_ON_ENTRY);
39
if (alcGetError(alcGetContextsDevice(context)) != ALC_NO_ERROR)
41
_alutSetError(ALUT_ERROR_ALC_ERROR_ON_ENTRY);
48
ALboolean alutInit(int *argcp, char **argv)
53
if (initialisationState != Unintialized)
55
_alutSetError(ALUT_ERROR_INVALID_OPERATION);
59
if ((argcp == NULL) != (argv == NULL))
61
_alutSetError(ALUT_ERROR_INVALID_VALUE);
65
device = alcOpenDevice(NULL);
68
_alutSetError(ALUT_ERROR_OPEN_DEVICE);
72
context = alcCreateContext(device, NULL);
75
alcCloseDevice(device);
76
_alutSetError(ALUT_ERROR_CREATE_CONTEXT);
80
if (!alcMakeContextCurrent(context))
82
alcDestroyContext(context);
83
alcCloseDevice(device);
84
_alutSetError(ALUT_ERROR_MAKE_CONTEXT_CURRENT);
88
initialisationState = ALUTDeviceAndContext;
89
alutContext = context;
93
ALboolean alutInitWithoutContext(int *argcp, char **argv)
95
if (initialisationState != Unintialized)
97
_alutSetError(ALUT_ERROR_INVALID_OPERATION);
101
if ((argcp == NULL) != (argv == NULL))
103
_alutSetError(ALUT_ERROR_INVALID_VALUE);
107
initialisationState = ExternalDeviceAndContext;
111
ALboolean alutExit(void)
115
if (initialisationState == Unintialized)
117
_alutSetError(ALUT_ERROR_INVALID_OPERATION);
121
if (initialisationState == ExternalDeviceAndContext)
123
initialisationState = Unintialized;
127
if (!_alutSanityCheck())
132
if (!alcMakeContextCurrent(NULL))
134
_alutSetError(ALUT_ERROR_MAKE_CONTEXT_CURRENT);
138
device = alcGetContextsDevice(alutContext);
139
alcDestroyContext(alutContext);
140
if (alcGetError(device) != ALC_NO_ERROR)
142
_alutSetError(ALUT_ERROR_DESTROY_CONTEXT);
146
if (!alcCloseDevice(device))
148
_alutSetError(ALUT_ERROR_CLOSE_DEVICE);
152
initialisationState = Unintialized;