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;
17 _alutSanityCheck (void)
21 if (initialisationState == Unintialized)
23 _alutSetError (ALUT_ERROR_INVALID_OPERATION);
27 context = alcGetCurrentContext ();
30 _alutSetError (ALUT_ERROR_NO_CURRENT_CONTEXT);
34 if (alGetError () != AL_NO_ERROR)
36 _alutSetError (ALUT_ERROR_AL_ERROR_ON_ENTRY);
40 if (alcGetError (alcGetContextsDevice (context)) != ALC_NO_ERROR)
42 _alutSetError (ALUT_ERROR_ALC_ERROR_ON_ENTRY);
50 alutInit (int *argcp, char **argv)
55 if (initialisationState != Unintialized)
57 _alutSetError (ALUT_ERROR_INVALID_OPERATION);
61 if ((argcp == NULL) != (argv == NULL))
63 _alutSetError (ALUT_ERROR_INVALID_VALUE);
67 device = alcOpenDevice (NULL);
70 _alutSetError (ALUT_ERROR_OPEN_DEVICE);
74 context = alcCreateContext (device, NULL);
77 alcCloseDevice (device);
78 _alutSetError (ALUT_ERROR_CREATE_CONTEXT);
82 if (!alcMakeContextCurrent (context))
84 alcDestroyContext (context);
85 alcCloseDevice (device);
86 _alutSetError (ALUT_ERROR_MAKE_CONTEXT_CURRENT);
90 initialisationState = ALUTDeviceAndContext;
91 alutContext = context;
96 alutInitWithoutContext (int *argcp, char **argv)
98 if (initialisationState != Unintialized)
100 _alutSetError (ALUT_ERROR_INVALID_OPERATION);
104 if ((argcp == NULL) != (argv == NULL))
106 _alutSetError (ALUT_ERROR_INVALID_VALUE);
110 initialisationState = ExternalDeviceAndContext;
119 if (initialisationState == Unintialized)
121 _alutSetError (ALUT_ERROR_INVALID_OPERATION);
125 if (initialisationState == ExternalDeviceAndContext)
127 initialisationState = Unintialized;
131 if (!_alutSanityCheck ())
136 if (!alcMakeContextCurrent (NULL))
138 _alutSetError (ALUT_ERROR_MAKE_CONTEXT_CURRENT);
142 device = alcGetContextsDevice (alutContext);
143 alcDestroyContext (alutContext);
144 if (alcGetError (device) != ALC_NO_ERROR)
146 _alutSetError (ALUT_ERROR_DESTROY_CONTEXT);
150 if (!alcCloseDevice (device))
152 _alutSetError (ALUT_ERROR_CLOSE_DEVICE);
156 initialisationState = Unintialized;