killed homebrew AL interop; using Tao.OpenAL now instead

This commit is contained in:
Chris Forbes
2010-02-16 23:41:31 +13:00
parent a72d19e754
commit bb1e9e09f2
4 changed files with 40 additions and 29 deletions

View File

@@ -124,6 +124,7 @@ namespace OpenRa
Sound.Initialize(); Sound.Initialize();
PerfHistory.items["render"].hasNormalTick = false; PerfHistory.items["render"].hasNormalTick = false;
PerfHistory.items["batches"].hasNormalTick = false; PerfHistory.items["batches"].hasNormalTick = false;
PerfHistory.items["text"].hasNormalTick = false;
Game.controller = controller; Game.controller = controller;
ChangeMap(mapName); ChangeMap(mapName);
@@ -193,6 +194,7 @@ namespace OpenRa
PerfHistory.items["render"].Tick(); PerfHistory.items["render"].Tick();
PerfHistory.items["batches"].Tick(); PerfHistory.items["batches"].Tick();
PerfHistory.items["text"].Tick();
} }
public static void SyncLobbyInfo(string data) public static void SyncLobbyInfo(string data)

View File

@@ -146,18 +146,26 @@ namespace OpenRa.Graphics
public void DrawText(string text, int2 pos, Color c) public void DrawText(string text, int2 pos, Color c)
{ {
Bitmap b = RenderTextToBitmap(text, fDebug, c); using (new PerfSample("text"))
textSheet.Texture.SetData(b); {
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome"); var size = MeasureText(text);
rgbaRenderer.Flush(); Bitmap b = RenderTextToBitmap(text, fDebug, c);
textSheet.Texture.SetData(b);
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome");
rgbaRenderer.Flush();
}
} }
public void DrawText2(string text, int2 pos, Color c) public void DrawText2(string text, int2 pos, Color c)
{ {
Bitmap b = RenderTextToBitmap(text, fTitle, c); using (new PerfSample("text"))
textSheet.Texture.SetData(b); {
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome"); var size = MeasureText2(text);
rgbaRenderer.Flush(); Bitmap b = RenderTextToBitmap(text, fTitle, c);
textSheet.Texture.SetData(b);
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome");
rgbaRenderer.Flush();
}
} }
public int2 MeasureText(string text) public int2 MeasureText(string text)

View File

@@ -63,6 +63,7 @@
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Tao.OpenAl, Version=1.1.0.1, Culture=neutral, PublicKeyToken=a7579dda88828311, processorArchitecture=MSIL" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Chat.cs" /> <Compile Include="Chat.cs" />
@@ -105,7 +106,6 @@
<Compile Include="Shroud.cs" /> <Compile Include="Shroud.cs" />
<Compile Include="Smudge.cs" /> <Compile Include="Smudge.cs" />
<Compile Include="Sound.cs" /> <Compile Include="Sound.cs" />
<Compile Include="Support\OpenAlInterop.cs" />
<Compile Include="Support\PerfHistory.cs" /> <Compile Include="Support\PerfHistory.cs" />
<Compile Include="Sync.cs" /> <Compile Include="Sync.cs" />
<Compile Include="Traits\Attack\AttackOmni.cs" /> <Compile Include="Traits\Attack\AttackOmni.cs" />

View File

@@ -23,6 +23,7 @@ using System.Collections.Generic;
using OpenRa.FileFormats; using OpenRa.FileFormats;
using OpenRa.Support; using OpenRa.Support;
using OpenRa.Traits; using OpenRa.Traits;
using Tao.OpenAl;
namespace OpenRa namespace OpenRa
{ {
@@ -160,19 +161,19 @@ namespace OpenRa
public OpenAlSoundEngine() public OpenAlSoundEngine()
{ {
//var str = Alc.alcGetString(IntPtr.Zero, Alc.ALC_DEFAULT_DEVICE_SPECIFIER); //var str = Alc.alcGetString(IntPtr.Zero, Alc.ALC_DEFAULT_DEVICE_SPECIFIER);
var dev = OpenAlInterop.alcOpenDevice(IntPtr.Zero); var dev = Alc.alcOpenDevice(null);
if (dev == IntPtr.Zero) if (dev == IntPtr.Zero)
throw new InvalidOperationException("Can't create OpenAL device"); throw new InvalidOperationException("Can't create OpenAL device");
var ctx = OpenAlInterop.alcCreateContext(dev, IntPtr.Zero); var ctx = Alc.alcCreateContext(dev, IntPtr.Zero);
if (ctx == IntPtr.Zero) if (ctx == IntPtr.Zero)
throw new InvalidOperationException("Can't create OpenAL context"); throw new InvalidOperationException("Can't create OpenAL context");
OpenAlInterop.alcMakeContextCurrent(ctx); Alc.alcMakeContextCurrent(ctx);
for (var i = 0; i < POOL_SIZE; i++) for (var i = 0; i < POOL_SIZE; i++)
{ {
var source = 0; var source = 0;
OpenAlInterop.alGenSources(1, out source); Al.alGenSources(1, out source);
if (0 != OpenAlInterop.alGetError()) if (0 != Al.alGetError())
throw new InvalidOperationException("failed generating source {0}".F(i)); throw new InvalidOperationException("failed generating source {0}".F(i));
sourcePool.Add(source, false); sourcePool.Add(source, false);
} }
@@ -193,8 +194,8 @@ namespace OpenRa
foreach (int key in sourcePool.Keys) foreach (int key in sourcePool.Keys)
{ {
int state; int state;
OpenAlInterop.alGetSourcei(key, OpenAlInterop.AL_SOURCE_STATE, out state); Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
if (state != OpenAlInterop.AL_PLAYING) if (state != Al.AL_PLAYING)
freeSources.Add(key); freeSources.Add(key);
} }
@@ -223,7 +224,7 @@ namespace OpenRa
public float Volume public float Volume
{ {
get { return volume; } get { return volume; }
set { OpenAlInterop.alListenerf(OpenAlInterop.AL_GAIN, volume = value); } set { Al.alListenerf(Al.AL_GAIN, volume = value); }
} }
} }
@@ -234,15 +235,15 @@ namespace OpenRa
static int MakeALFormat(int channels, int bits) static int MakeALFormat(int channels, int bits)
{ {
if (channels == 1) if (channels == 1)
return bits == 16 ? OpenAlInterop.AL_FORMAT_MONO16 : OpenAlInterop.AL_FORMAT_MONO8; return bits == 16 ? Al.AL_FORMAT_MONO16 : Al.AL_FORMAT_MONO8;
else else
return bits == 16 ? OpenAlInterop.AL_FORMAT_STEREO16 : OpenAlInterop.AL_FORMAT_STEREO8; return bits == 16 ? Al.AL_FORMAT_STEREO16 : Al.AL_FORMAT_STEREO8;
} }
public OpenAlSoundSource(byte[] data, int channels, int sampleBits, int sampleRate) public OpenAlSoundSource(byte[] data, int channels, int sampleBits, int sampleRate)
{ {
OpenAlInterop.alGenBuffers(1, out buffer); Al.alGenBuffers(1, out buffer);
OpenAlInterop.alBufferData(buffer, MakeALFormat(channels, sampleBits), data, data.Length, sampleRate); Al.alBufferData(buffer, MakeALFormat(channels, sampleBits), data, data.Length, sampleRate);
} }
} }
@@ -255,13 +256,13 @@ namespace OpenRa
{ {
if (source == -1) return; if (source == -1) return;
this.source = source; this.source = source;
OpenAlInterop.alSourcef(source, OpenAlInterop.AL_PITCH, 1f); Al.alSourcef(source, Al.AL_PITCH, 1f);
OpenAlInterop.alSourcef(source, OpenAlInterop.AL_GAIN, 1f); Al.alSourcef(source, Al.AL_GAIN, 1f);
OpenAlInterop.alSource3f(source, OpenAlInterop.AL_POSITION, 0f, 0f, 0f); Al.alSource3f(source, Al.AL_POSITION, 0f, 0f, 0f);
OpenAlInterop.alSource3f(source, OpenAlInterop.AL_VELOCITY, 0f, 0f, 0f); Al.alSource3f(source, Al.AL_VELOCITY, 0f, 0f, 0f);
OpenAlInterop.alSourcei(source, OpenAlInterop.AL_BUFFER, buffer); Al.alSourcei(source, Al.AL_BUFFER, buffer);
OpenAlInterop.alSourcei(source, OpenAlInterop.AL_LOOPING, looping ? OpenAlInterop.AL_TRUE : OpenAlInterop.AL_FALSE); Al.alSourcei(source, Al.AL_LOOPING, looping ? Al.AL_TRUE : Al.AL_FALSE);
OpenAlInterop.alSourcePlay(source); Al.alSourcePlay(source);
} }
public float Volume public float Volume
@@ -270,7 +271,7 @@ namespace OpenRa
set set
{ {
if (source != -1) if (source != -1)
OpenAlInterop.alSourcef(source, OpenAlInterop.AL_GAIN, volume = value); Al.alSourcef(source, Al.AL_GAIN, volume = value);
} }
} }
} }