2008-01-15 00:24:15 +00:00
|
|
|
|
#region --- OpenTK.OpenAL License ---
|
|
|
|
|
/* XRamExtension.cs
|
|
|
|
|
* C header: \OpenAL 1.1 SDK\include\xram.h
|
|
|
|
|
* Spec: ?
|
|
|
|
|
* Copyright (c) 2008 Christoph Brandtner and Stefanos Apostolopoulos
|
|
|
|
|
* See license.txt for license details (MIT)
|
|
|
|
|
* http://www.OpenTK.net */
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace OpenTK.OpenAL
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public class XRamExtension
|
|
|
|
|
{
|
|
|
|
|
#region instance state
|
|
|
|
|
|
|
|
|
|
private bool _valid = false;
|
|
|
|
|
|
|
|
|
|
/// <summary>Returns True if the X-Ram Extension has been found and could be initialized.</summary>
|
|
|
|
|
public bool IsInitialized
|
|
|
|
|
{
|
|
|
|
|
get { return _valid; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion instance state
|
|
|
|
|
|
|
|
|
|
#region X-RAM Function pointer definitions
|
|
|
|
|
|
2008-01-15 00:45:54 +00:00
|
|
|
|
[CLSCompliant(false)]
|
2008-01-18 13:32:51 +00:00
|
|
|
|
public unsafe delegate bool Delegate_SetBufferMode( int n,ref uint buffers,int value );
|
2008-01-15 00:24:15 +00:00
|
|
|
|
//typedef ALboolean (__cdecl *EAXSetBufferMode)(ALsizei n, ALuint *buffers, ALint value);
|
|
|
|
|
|
2008-01-15 00:45:54 +00:00
|
|
|
|
[CLSCompliant(false)]
|
2008-01-18 13:32:51 +00:00
|
|
|
|
public delegate int Delegate_GetBufferMode( uint buffer,out int value );
|
2008-01-15 00:24:15 +00:00
|
|
|
|
//typedef ALenum (__cdecl *EAXGetBufferMode)(ALuint buffer, ALint *value);
|
|
|
|
|
|
2008-01-20 19:00:03 +00:00
|
|
|
|
//[CLSCompliant(false)]
|
2008-01-17 20:55:56 +00:00
|
|
|
|
private Delegate_SetBufferMode Imported_SetBufferMode;
|
2008-01-20 19:00:03 +00:00
|
|
|
|
//[CLSCompliant(false)]
|
2008-01-17 20:55:56 +00:00
|
|
|
|
private Delegate_GetBufferMode Imported_GetBufferMode;
|
2008-01-15 00:24:15 +00:00
|
|
|
|
|
|
|
|
|
#endregion X-RAM Function pointer definitions
|
|
|
|
|
|
|
|
|
|
#region X-RAM Tokens
|
|
|
|
|
|
|
|
|
|
private int AL_EAX_RAM_SIZE, AL_EAX_RAM_FREE,
|
|
|
|
|
AL_STORAGE_AUTOMATIC, AL_STORAGE_HARDWARE, AL_STORAGE_ACCESSIBLE;
|
|
|
|
|
|
|
|
|
|
#endregion X-RAM Tokens
|
|
|
|
|
|
|
|
|
|
#region Constructor / Extension Loading
|
|
|
|
|
|
2008-01-18 13:32:51 +00:00
|
|
|
|
public XRamExtension( )
|
2008-01-15 00:24:15 +00:00
|
|
|
|
{ // Query if Extension supported and retrieve Tokens/Pointers if it is.
|
|
|
|
|
_valid = false;
|
2008-01-18 13:32:51 +00:00
|
|
|
|
if ( AL.IsExtensionPresent("EAX-RAM") == false )
|
2008-01-15 00:24:15 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
AL_EAX_RAM_SIZE = AL.GetEnumValue("AL_EAX_RAM_SIZE");
|
|
|
|
|
AL_EAX_RAM_FREE = AL.GetEnumValue("AL_EAX_RAM_FREE");
|
|
|
|
|
AL_STORAGE_AUTOMATIC = AL.GetEnumValue("AL_STORAGE_AUTOMATIC");
|
|
|
|
|
AL_STORAGE_HARDWARE = AL.GetEnumValue("AL_STORAGE_HARDWARE");
|
|
|
|
|
AL_STORAGE_ACCESSIBLE = AL.GetEnumValue("AL_STORAGE_ACCESSIBLE");
|
|
|
|
|
|
2008-01-18 13:32:51 +00:00
|
|
|
|
Console.WriteLine("RamSize: {0} RamFree: {1} StorageAuto: {2} StorageHW: {3} StorageAccess: {4}",AL_EAX_RAM_SIZE,AL_EAX_RAM_FREE,AL_STORAGE_AUTOMATIC,AL_STORAGE_HARDWARE,AL_STORAGE_ACCESSIBLE);
|
2008-01-15 00:24:15 +00:00
|
|
|
|
|
2008-01-18 13:32:51 +00:00
|
|
|
|
if ( AL_EAX_RAM_SIZE == 0 ||
|
2008-01-15 00:24:15 +00:00
|
|
|
|
AL_EAX_RAM_FREE == 0 ||
|
|
|
|
|
AL_STORAGE_AUTOMATIC == 0 ||
|
|
|
|
|
AL_STORAGE_HARDWARE == 0 ||
|
2008-01-18 13:32:51 +00:00
|
|
|
|
AL_STORAGE_ACCESSIBLE == 0 )
|
2008-01-15 00:24:15 +00:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Token values could not be retrieved.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-18 13:32:51 +00:00
|
|
|
|
Console.WriteLine("Free Ram: {0} / {1}",GetRamFree( ),GetRamSize( ));
|
2008-01-15 00:24:15 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2008-01-18 13:32:51 +00:00
|
|
|
|
Imported_GetBufferMode = (Delegate_GetBufferMode) Marshal.GetDelegateForFunctionPointer(AL.GetProcAddress("EAXGetBufferMode"),typeof(Delegate_GetBufferMode));
|
|
|
|
|
Imported_SetBufferMode = (Delegate_SetBufferMode) Marshal.GetDelegateForFunctionPointer(AL.GetProcAddress("EAXSetBufferMode"),typeof(Delegate_SetBufferMode));
|
|
|
|
|
} catch ( Exception e )
|
2008-01-15 00:24:15 +00:00
|
|
|
|
{
|
2008-01-18 13:32:51 +00:00
|
|
|
|
Console.WriteLine("Attempt to marshal AL.GetProcAddress failed. " + e.ToString( ));
|
2008-01-15 00:24:15 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_valid = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Constructor / Extension Loading
|
|
|
|
|
|
|
|
|
|
#region Public Methods
|
|
|
|
|
|
|
|
|
|
/// <summary>Query total amount of X-RAM.</summary>
|
2008-01-18 13:32:51 +00:00
|
|
|
|
public int GetRamSize( )
|
2008-01-15 00:24:15 +00:00
|
|
|
|
{
|
2008-01-18 13:32:51 +00:00
|
|
|
|
return AL.Get((Enums.ALGetInteger) AL_EAX_RAM_SIZE);
|
2008-01-15 00:24:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Query free X-RAM available.</summary>
|
2008-01-18 13:32:51 +00:00
|
|
|
|
public int GetRamFree( )
|
2008-01-15 00:24:15 +00:00
|
|
|
|
{
|
2008-01-18 13:32:51 +00:00
|
|
|
|
return AL.Get((Enums.ALGetInteger) AL_EAX_RAM_FREE);
|
2008-01-15 00:24:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum XRamStorage : byte
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Put an Open AL Buffer into X-RAM if memory is available, otherwise use host RAM. This is the default mode.
|
|
|
|
|
/// alGenBuffers(1, &uiBuffer);
|
|
|
|
|
/// eaxSetBufferMode(1, &uiBuffer, alGetEnumValue("AL_STORAGE_AUTOMATIC"));
|
2008-01-17 19:02:37 +00:00
|
|
|
|
/// alBufferData(...);</summary>
|
2008-01-15 00:24:15 +00:00
|
|
|
|
Automatic,
|
|
|
|
|
/// <summary>Force an Open AL Buffer into X-RAM (good for non-streaming buffers)
|
|
|
|
|
// alGenBuffers(1, &uiBuffer);
|
|
|
|
|
// eaxSetBufferMode(1, &uiBuffer, alGetEnumValue("AL_STORAGE_HARDWARE"));
|
2008-01-17 19:02:37 +00:00
|
|
|
|
// alBufferData(...);</summary>
|
2008-01-15 00:24:15 +00:00
|
|
|
|
Hardware = 1,
|
|
|
|
|
/// <summary>Force an Open AL Buffer into 'accessible' (currently host) RAM (good for streaming buffers)
|
|
|
|
|
/// alGenBuffers(1, &uiBuffer);
|
|
|
|
|
/// eaxSetBufferMode(1, &uiBuffer, alGetEnumValue("AL_STORAGE_ACCESSIBLE"));
|
2008-01-17 19:02:37 +00:00
|
|
|
|
/// alBufferData(...);</summary>
|
2008-01-15 00:24:15 +00:00
|
|
|
|
Acessible = 2,
|
|
|
|
|
}
|
2008-01-17 19:02:37 +00:00
|
|
|
|
|
2008-01-15 00:45:54 +00:00
|
|
|
|
[CLSCompliant(false)]
|
2008-01-18 13:32:51 +00:00
|
|
|
|
public void SetBufferMode( int n,ref uint buffer,XRamStorage mode )
|
2008-01-15 00:24:15 +00:00
|
|
|
|
{
|
2008-01-18 13:32:51 +00:00
|
|
|
|
switch ( mode )
|
2008-01-15 00:24:15 +00:00
|
|
|
|
{
|
2008-01-18 13:32:51 +00:00
|
|
|
|
case XRamStorage.Acessible:
|
|
|
|
|
Imported_SetBufferMode(1,ref buffer,AL_STORAGE_ACCESSIBLE);
|
|
|
|
|
break;
|
|
|
|
|
case XRamStorage.Hardware:
|
|
|
|
|
Imported_SetBufferMode(1,ref buffer,AL_STORAGE_HARDWARE);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Imported_SetBufferMode(1,ref buffer,AL_STORAGE_AUTOMATIC);
|
|
|
|
|
break;
|
2008-01-15 00:24:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-17 19:02:37 +00:00
|
|
|
|
[CLSCompliant(false)]
|
2008-01-18 13:32:51 +00:00
|
|
|
|
public XRamStorage GetBufferMode( ref uint buffer )
|
2008-01-16 23:57:54 +00:00
|
|
|
|
{
|
|
|
|
|
int t; // this is improper, find sample codes using it and figure out what 2nd param does.
|
2008-01-18 13:32:51 +00:00
|
|
|
|
return (XRamStorage) Imported_GetBufferMode(buffer,out t);
|
2008-01-16 23:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-15 00:24:15 +00:00
|
|
|
|
#endregion Public Methods
|
|
|
|
|
}
|
2008-01-18 13:32:51 +00:00
|
|
|
|
|
2008-01-15 00:24:15 +00:00
|
|
|
|
}
|