Fixed a bug that would cause context creation to fail under OpenAL SI (0.0.6-0.0.8) on Linux.

This commit is contained in:
the_fiddler 2008-04-13 19:46:42 +00:00
parent d4590f183b
commit 6b72455421

View file

@ -25,12 +25,20 @@ namespace OpenTK.Audio
bool disposed; bool disposed;
bool is_processing; bool is_processing;
ContextHandle device_handle, context_handle; ContextHandle device_handle, context_handle;
bool context_exists;
string device_name; string device_name;
static object audio_context_lock = new object(); static object audio_context_lock = new object();
static List<string> available_devices = new List<string>(); static List<string> available_devices = new List<string>();
static Dictionary<ContextHandle, AudioContext> available_contexts = new Dictionary<ContextHandle, AudioContext>(); static Dictionary<ContextHandle, AudioContext> available_contexts = new Dictionary<ContextHandle, AudioContext>();
static bool openal_supported = true; static bool openal_supported = true;
bool context_exists; static Version version;
private enum Version
{
OpenAL10,
OpenAL11
}
#endregion #endregion
@ -182,9 +190,15 @@ namespace OpenTK.Audio
Debug.Indent(); Debug.Indent();
if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT")) if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT"))
{
version = Version.OpenAL11;
available_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.DeviceSpecifier)); available_devices.AddRange(Alc.GetString(IntPtr.Zero, AlcGetStringList.DeviceSpecifier));
}
else else
{
version = Version.OpenAL10;
Debug.Print("Device enumeration extension not available. Failed to enumerate devices."); Debug.Print("Device enumeration extension not available. Failed to enumerate devices.");
}
foreach (string s in available_devices) foreach (string s in available_devices)
Debug.WriteLine(s); Debug.WriteLine(s);
@ -233,7 +247,8 @@ namespace OpenTK.Audio
/// </remarks> /// </remarks>
void CreateContext(string device, int freq, int refresh, bool sync, int maxEfxSends) void CreateContext(string device, int freq, int refresh, bool sync, int maxEfxSends)
{ {
if (available_devices.Count == 0) throw new NotSupportedException("No audio hardware is available."); if (version == Version.OpenAL11 && available_devices.Count == 0) // Version.OpenAL10 does not support device enumeration.
throw new NotSupportedException("No audio hardware is available.");
if (context_exists) throw new NotSupportedException("Multiple AudioContexts are not supported."); if (context_exists) throw new NotSupportedException("Multiple AudioContexts are not supported.");
if (freq < 0) throw new ArgumentOutOfRangeException("freq", freq, "Should be greater than zero."); if (freq < 0) throw new ArgumentOutOfRangeException("freq", freq, "Should be greater than zero.");
if (refresh < 0) throw new ArgumentOutOfRangeException("refresh", refresh, "Should be greater than zero."); if (refresh < 0) throw new ArgumentOutOfRangeException("refresh", refresh, "Should be greater than zero.");