Permalink
Browse files

First pass at a new Windows DirectX platform.

  • Loading branch information...
1 parent 2af9a73 commit 4886ffd4401d639b211ab5d12bb47e11d2dfc596 @tomspilman tomspilman committed Dec 9, 2012
Showing with 695 additions and 253 deletions.
  1. +20 −0 MonoGame.Framework.Windows.sln
  2. +39 −27 MonoGame.Framework/Audio/SoundEffect.cs
  3. +62 −62 MonoGame.Framework/Audio/SoundEffectInstance.cs
  4. +1 −1 MonoGame.Framework/Content/ContentManager.cs
  5. +1 −1 MonoGame.Framework/Content/ContentReaders/SoundEffectReader.cs
  6. +1 −1 MonoGame.Framework/Game.cs
  7. +3 −1 MonoGame.Framework/GamePlatform.cs
  8. +0 −13 MonoGame.Framework/Graphics/Effect/AlphaTestEffect.cs
  9. +2 −15 MonoGame.Framework/Graphics/Effect/EffectPass.cs
  10. +0 −16 MonoGame.Framework/Graphics/Effect/SpriteEffect.cs
  11. +2 −2 MonoGame.Framework/Graphics/GraphicsAdapter.cs
  12. +31 −24 MonoGame.Framework/Graphics/GraphicsDevice.cs
  13. +4 −3 MonoGame.Framework/Graphics/GraphicsExtensions.cs
  14. +2 −0 MonoGame.Framework/Graphics/OcclusionQuery.cs
  15. +2 −0 MonoGame.Framework/Graphics/RenderTarget2D.cs
  16. +2 −0 MonoGame.Framework/Graphics/SamplerStateCollection.cs
  17. +2 −0 MonoGame.Framework/Graphics/Shader/ConstantBuffer.cs
  18. +1 −1 MonoGame.Framework/Graphics/Shader/ConstantBufferCollection.cs
  19. +10 −8 MonoGame.Framework/Graphics/Shader/Shader.cs
  20. +4 −2 MonoGame.Framework/Graphics/States/BlendState.cs
  21. +4 −2 MonoGame.Framework/Graphics/States/DepthStencilState.cs
  22. +4 −2 MonoGame.Framework/Graphics/States/RasterizerState.cs
  23. +2 −2 MonoGame.Framework/Graphics/States/SamplerState.cs
  24. +2 −3 MonoGame.Framework/Graphics/Texture.cs
  25. +4 −3 MonoGame.Framework/Graphics/Texture2D.cs
  26. +18 −3 MonoGame.Framework/Graphics/Texture3D.cs
  27. +3 −1 MonoGame.Framework/Graphics/TextureCollection.cs
  28. +16 −16 MonoGame.Framework/Graphics/TextureCube.cs
  29. +5 −3 MonoGame.Framework/Graphics/Vertices/IndexBuffer.cs
  30. +4 −3 MonoGame.Framework/Graphics/Vertices/VertexBuffer.cs
  31. +4 −2 MonoGame.Framework/Graphics/Vertices/VertexDeclaration.cs
  32. +11 −8 MonoGame.Framework/Input/Mouse.cs
  33. +22 −13 MonoGame.Framework/Media/MediaPlayer.cs
  34. +3 −3 MonoGame.Framework/Media/MediaQueue.cs
  35. +10 −10 MonoGame.Framework/Media/Song.cs
  36. +383 −0 MonoGame.Framework/MonoGame.Framework.Windows.csproj
  37. +4 −2 MonoGame.Framework/Windows/GamerServices/Guide.cs
  38. +7 −0 MonoGame.Framework/Windows8/SharpDXHelper.cs
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.Windows", "MonoGame.Framework\MonoGame.Framework.Windows.csproj", "{7DE47032-A904-4C29-BD22-2D235E8D91BA}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7DE47032-A904-4C29-BD22-2D235E8D91BA}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -46,7 +46,7 @@ 1. Definitions
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
-#if WINRT
+#if DIRECTX
using SharpDX;
using SharpDX.XAudio2;
using SharpDX.Multimedia;
@@ -57,7 +57,7 @@ namespace Microsoft.Xna.Framework.Audio
{
public sealed class SoundEffect : IDisposable
{
-#if WINRT
+#if DIRECTX
internal DataStream _dataStream;
internal AudioBuffer _buffer;
internal AudioBuffer _loopedBuffer;
@@ -69,17 +69,17 @@ public sealed class SoundEffect : IDisposable
private List<SoundEffectInstance> _availableInstances;
private List<SoundEffectInstance> _toBeRecycledInstances;
#else
- private Sound _sound;
+ private Sound _sound;
private SoundEffectInstance _instance;
#endif
private string _name;
-#if !WINRT
- private string _filename = "";
+#if !DIRECTX
+ private string _filename = "";
private byte[] _data;
#endif
-#if WINRT
+#if DIRECTX
internal SoundEffect()
{
}
@@ -107,11 +107,11 @@ internal SoundEffect(string name, byte[] data)
#endif
public SoundEffect(byte[] buffer, int sampleRate, AudioChannels channels)
- {
-#if WINRT
+ {
+#if DIRECTX
Initialize(new WaveFormat(sampleRate, (int)channels), buffer, 0, buffer.Length, 0, buffer.Length);
#else
- //buffer should contain 16-bit PCM wave data
+ //buffer should contain 16-bit PCM wave data
short bitsPerSample = 16;
_name = "";
@@ -146,15 +146,15 @@ public SoundEffect(byte[] buffer, int sampleRate, AudioChannels channels)
}
public SoundEffect(byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength)
- {
-#if WINRT
+ {
+#if DIRECTX
Initialize(new WaveFormat(sampleRate, (int)channels), buffer, offset, count, loopStart, loopLength);
#else
throw new NotImplementedException();
#endif
}
-#if WINRT
+#if DIRECTX
// Extended constructor which supports custom formats / compression.
internal SoundEffect(WaveFormat format, byte[] buffer, int offset, int count, int loopStart, int loopLength)
@@ -192,15 +192,15 @@ private void Initialize(WaveFormat format, byte[] buffer, int offset, int count,
};
}
#endif
-
+
public bool Play()
{
return Play(1.0f, 0.0f, 0.0f);
}
public bool Play(float volume, float pitch, float pan)
{
-#if WINRT
+#if DIRECTX
if (MasterVolume > 0.0f)
{
if (_playingInstances == null)
@@ -256,7 +256,7 @@ public bool Play(float volume, float pitch, float pan)
// has been reached. However, there is no limit on PC.
return true;
#else
- if ( MasterVolume > 0.0f )
+ if ( MasterVolume > 0.0f )
{
if(_instance == null)
_instance = CreateInstance();
@@ -273,14 +273,14 @@ public bool Play(float volume, float pitch, float pan)
public TimeSpan Duration
{
get
- {
-#if WINRT
+ {
+#if DIRECTX
var sampleCount = _buffer.PlayLength;
var avgBPS = _format.AverageBytesPerSecond;
return TimeSpan.FromSeconds((float)sampleCount / (float)avgBPS);
#else
- if ( _sound != null )
+ if ( _sound != null )
{
return new TimeSpan(0,0,(int)_sound.Duration);
}
@@ -305,8 +305,8 @@ public string Name
}
public SoundEffectInstance CreateInstance()
- {
-#if WINRT
+ {
+#if DIRECTX
SourceVoice voice = null;
if (Device != null)
voice = new SourceVoice(Device, _format, VoiceFlags.None, XAudio2.MaximumFrequencyRatio);
@@ -323,10 +323,10 @@ public SoundEffectInstance CreateInstance()
public void Dispose()
{
-#if WINRT
+#if DIRECTX
_dataStream.Dispose();
#else
- _sound.Dispose();
+ _sound.Dispose();
#endif
}
@@ -345,10 +345,10 @@ public static float MasterVolume
if ( _masterVolume != value )
_masterVolume = value;
-#if WINRT
+#if DIRECTX
MasterVoice.SetVolume(_masterVolume, 0);
#endif
- }
+ }
}
static float _distanceScale = 1f;
@@ -393,7 +393,7 @@ public static float MasterVolume
}
}
-#if WINRT
+#if DIRECTX
internal static XAudio2 Device { get; private set; }
internal static MasteringVoice MasterVoice { get; private set; }
@@ -436,19 +436,31 @@ internal static X3DAudio Device3D
static SoundEffect()
{
+ var flags = XAudio2Flags.None;
+#if DEBUG
+ flags |= XAudio2Flags.DebugEngine;
+#endif
// This cannot fail.
- Device = new XAudio2();
+ Device = new XAudio2(flags, ProcessorSpecifier.DefaultProcessor);
try
{
Device.StartEngine();
+ // Just use the default device.
+ const int deviceIndex = 0;
+
// Let windows autodetect number of channels and sample rate.
- MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate);
+ MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, deviceIndex);
MasterVoice.SetVolume(_masterVolume, 0);
// The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout.
+#if WINRT
Speakers = (Speakers)MasterVoice.ChannelMask;
+#else
+ var deviceDetails = Device.GetDeviceDetails(deviceIndex);
+ Speakers = deviceDetails.OutputFormat.ChannelMask;
+#endif
}
catch
{
Oops, something went wrong.

0 comments on commit 4886ffd

Please sign in to comment.