- Some refactorings in the GL render system

- Started working on SoundSystem creator and SoundEffects
This commit is contained in:
SND\AstrorEnales_cp 2012-01-25 15:31:58 +00:00
parent bb32753f59
commit dd2353ec88
15 changed files with 957 additions and 353 deletions

View File

@ -453,7 +453,9 @@
<Compile Include="NonXNA\RenderSystem\IRenderSystemCreator.cs" />
<Compile Include="NonXNA\ResourceTracker\GraphicsResourceTracker.cs" />
<None Include="NonXNA\ResourceTracker\WeakReference.cs" />
<Compile Include="NonXNA\SoundSystem\ISoundEffect.cs" />
<Compile Include="NonXNA\SoundSystem\ISoundSystemCreator.cs" />
<Compile Include="NonXNA\SoundSystem\ISoundEffectInstance.cs" />
<Compile Include="Plane.cs" />
<Compile Include="PlaneIntersectionType.cs" />
<Compile Include="PlayerIndex.cs" />

View File

@ -54,38 +54,63 @@ using System.IO;
namespace ANX.Framework.Audio
{
public sealed class DynamicSoundEffectInstance : SoundEffectInstance
{
public DynamicSoundEffectInstance(int sampleRate, AudioChannels channels)
{
public sealed class DynamicSoundEffectInstance : SoundEffectInstance
{
public event EventHandler<EventArgs> BufferNeeded;
}
public override bool IsLooped { get { return false; } set { } }
public int PendingBufferCount { get { throw new NotImplementedException(); } }
public TimeSpan GetSampleDuration(int sizeInBytes)
{
throw new NotImplementedException();
}
public int GetSampleSizeInBytes(TimeSpan duration)
{
throw new NotImplementedException();
}
public override void Play()
{
public DynamicSoundEffectInstance(int sampleRate, AudioChannels channels)
{
throw new NotImplementedException();
}
}
public void SubmitBuffer(byte[] buffer)
{
public override bool IsLooped
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
}
public void SubmitBuffer(byte[] buffer, int offset, int count)
{
public int PendingBufferCount
{
get
{
throw new NotImplementedException();
}
}
}
protected override void Dispose(bool disposing)
{
}
public event EventHandler<EventArgs> BufferNeeded;
}
public TimeSpan GetSampleDuration(int sizeInBytes)
{
throw new NotImplementedException();
}
public int GetSampleSizeInBytes(TimeSpan duration)
{
throw new NotImplementedException();
}
public override void Play()
{
throw new NotImplementedException();
}
public void SubmitBuffer(byte[] buffer)
{
throw new NotImplementedException();
}
public void SubmitBuffer(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
protected override void Dispose(bool disposing)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,10 +1,6 @@
#region Using Statements
using System;
using System.IO;
using System;
using System.Runtime.InteropServices;
#endregion // Using Statements
#region License
//
@ -54,21 +50,23 @@ using System.Runtime.InteropServices;
namespace ANX.Framework.Audio
{
[SerializableAttribute]
public sealed class InstancePlayLimitException : ExternalException
{
public InstancePlayLimitException ()
{
[SerializableAttribute]
public sealed class InstancePlayLimitException : ExternalException
{
#region Constructor
public InstancePlayLimitException()
{
}
}
public InstancePlayLimitException(string message)
{
public InstancePlayLimitException(string message)
: base(message)
{
}
}
public InstancePlayLimitException (string message,Exception inner)
{
}
}
public InstancePlayLimitException(string message, Exception inner)
: base(message, inner)
{
}
#endregion
}
}

View File

@ -1,7 +1,4 @@
#region Using Statements
using System;
#endregion // Using Statements
using System;
#region License
@ -52,53 +49,83 @@ using System;
namespace ANX.Framework.Audio
{
public struct RendererDetail
{
public struct RendererDetail
{
#region Private
private string friendlyName;
private string rendererId;
#endregion
public string FriendlyName
{
get
{
throw new NotImplementedException();
}
}
#region Public
public string FriendlyName
{
get
{
return friendlyName;
}
}
public string RendererId
{
get
{
throw new NotImplementedException();
}
}
public string RendererId
{
get
{
return rendererId;
}
}
#endregion
#region Constructor
internal RendererDetail(string setFriendlyName, string setRendererId)
{
friendlyName = setFriendlyName;
rendererId = setRendererId;
}
#endregion
public override int GetHashCode()
{
throw new NotImplementedException();
}
#region GetHashCode
public override int GetHashCode()
{
int hash1 = String.IsNullOrEmpty(friendlyName) ?
0 :
friendlyName.GetHashCode();
public override string ToString()
{
throw new NotImplementedException();
}
int hash2 = String.IsNullOrEmpty(rendererId) ?
0 :
rendererId.GetHashCode();
public override bool Equals(object obj)
{
if (obj != null && obj.GetType() == this.GetType())
{
return this == (RendererDetail)obj;
}
return hash1 ^ hash2;
}
#endregion
return false;
}
#region ToString
public override string ToString()
{
return base.ToString();
}
#endregion
#region Equality
public override bool Equals(object obj)
{
if (obj != null && obj is RendererDetail)
{
return this == (RendererDetail)obj;
}
public static bool operator ==(RendererDetail lhs, RendererDetail rhs)
{
return lhs.FriendlyName.Equals(rhs.FriendlyName) && lhs.RendererId.Equals(rhs.RendererId);
}
return false;
}
public static bool operator !=(RendererDetail lhs, RendererDetail rhs)
{
return !lhs.FriendlyName.Equals(rhs.FriendlyName) || !lhs.RendererId.Equals(rhs.RendererId);
}
}
public static bool operator ==(RendererDetail lhs, RendererDetail rhs)
{
return lhs.friendlyName.Equals(rhs.friendlyName) &&
lhs.rendererId.Equals(rhs.rendererId);
}
public static bool operator !=(RendererDetail lhs, RendererDetail rhs)
{
return lhs.friendlyName.Equals(rhs.friendlyName) == false ||
lhs.rendererId.Equals(rhs.rendererId) == false;
}
#endregion
}
}

View File

@ -1,8 +1,7 @@
#region Using Statements
using System;
using System;
using System.IO;
#endregion // Using Statements
using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.SoundSystem;
#region License
@ -51,51 +50,180 @@ using System.IO;
#endregion // License
namespace ANX.Framework.Audio
{
public sealed class SoundEffect : IDisposable
{
public SoundEffect (byte[] buffer,int sampleRate,AudioChannels channels){}
public SoundEffect (byte[] buffer, int offset, int count, int sampleRate, AudioChannels channels, int loopStart, int loopLength){}
public static float DistanceScale { get; set; }
public static float DopplerScale { get; set; }
public TimeSpan Duration { get { throw new NotImplementedException(); } }
public bool IsDisposed { get { throw new NotImplementedException(); } }
public static float MasterVolume { get; set; }
public string Name { get; set; }
public static float SpeedOfSound { get; set; }
public SoundEffectInstance CreateInstance()
{
throw new NotImplementedException();
}
public static SoundEffect FromStream(Stream stream)
{
throw new NotImplementedException();
}
public static TimeSpan GetSampleDuration(int sizeInBytes, int sampleRate, AudioChannels channels)
{
throw new NotImplementedException();
}
public static int GetSampleSizeInBytes(TimeSpan duration, int sampleRate, AudioChannels channels)
{
throw new NotImplementedException();
}
public bool Play ()
{
throw new NotImplementedException();
}
public bool Play(float volume, float pitch, float pan)
{
throw new NotImplementedException();
}
~SoundEffect()
{
throw new NotImplementedException();
}
public void Dispose()
{
throw new NotImplementedException();
}
}
public sealed class SoundEffect : IDisposable
{
#region Static
#region DistanceScale (TODO)
public static float DistanceScale
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
#endregion
#region DopplerScale (TODO)
public static float DopplerScale
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
#endregion
#region MasterVolume (TODO)
public static float MasterVolume
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
#endregion
#region SpeedOfSound (TODO)
public static float SpeedOfSound
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
#endregion
#endregion
#region Private
private ISoundEffect nativeSoundEffect;
#endregion
#region Public
public TimeSpan Duration
{
get
{
return nativeSoundEffect.Duration;
}
}
public bool IsDisposed
{
get;
private set;
}
public string Name
{
get;
set;
}
#endregion
#region Constructor
private SoundEffect(Stream stream)
{
nativeSoundEffect =
AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>()
.CreateSoundEffect(stream);
}
public SoundEffect(byte[] buffer, int sampleRate, AudioChannels channels)
: this(buffer, 0, buffer.Length, sampleRate, channels, 0, 0)
{
}
public SoundEffect(byte[] buffer, int offset, int count, int sampleRate,
AudioChannels channels, int loopStart, int loopLength)
{
nativeSoundEffect =
AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>()
.CreateSoundEffect(buffer, offset, count, sampleRate, channels,
loopStart, loopLength);
}
~SoundEffect()
{
Dispose();
}
#endregion
#region CreateInstance
public SoundEffectInstance CreateInstance()
{
return new SoundEffectInstance(this);
}
#endregion
#region FromStream
public static SoundEffect FromStream(Stream stream)
{
return new SoundEffect(stream);
}
#endregion
#region GetSampleDuration
public static TimeSpan GetSampleDuration(int sizeInBytes, int sampleRate,
AudioChannels channels)
{
float sizeMulBlockAlign = sizeInBytes / ((int)channels * 2);
return TimeSpan.FromMilliseconds((double)(sizeMulBlockAlign * 1000f /
(float)sampleRate));
}
#endregion
#region GetSampleSizeInBytes
public static int GetSampleSizeInBytes(TimeSpan duration, int sampleRate,
AudioChannels channels)
{
int timeMulSamples = (int)(duration.TotalMilliseconds *
(double)((float)sampleRate / 1000f));
return (timeMulSamples + timeMulSamples % (int)channels) *
((int)channels * 2);
}
#endregion
#region Play (TODO)
public bool Play()
{
return Play(1f, 0f, 0f);
}
public bool Play(float volume, float pitch, float pan)
{
// TODO: fire and forget play
throw new NotImplementedException();
}
#endregion
#region Dispose
public void Dispose()
{
if (IsDisposed == false)
{
IsDisposed = true;
nativeSoundEffect.Dispose();
nativeSoundEffect = null;
}
}
#endregion
}
}

View File

@ -1,8 +1,7 @@
#region Using Statements
using System;
using System;
using System.IO;
#endregion // Using Statements
using ANX.Framework.NonXNA.SoundSystem;
using ANX.Framework.NonXNA;
#region License
@ -53,33 +52,130 @@ using System.IO;
namespace ANX.Framework.Audio
{
public class SoundEffectInstance : IDisposable
{
public bool IsDisposed { get { throw new NotImplementedException(); } }
public virtual bool IsLooped { get; set; }
public float Pan { get; set; }
public float Pitch { get; set; }
public SoundState State { get { throw new NotImplementedException(); } }
public float Volume { get; set; }
public void Apply3D ( AudioListener listener, AudioEmitter emitter){}
public void Apply3D ( AudioListener[] listeners, AudioEmitter emitter){}
public void Pause (){}
public virtual void Play (){}
public void Resume (){}
public void Stop (){}
public void Stop (bool immediate){}
public class SoundEffectInstance : IDisposable
{
#region Private
private SoundEffect parent;
~SoundEffectInstance()
{
throw new NotImplementedException();
}
public void Dispose()
{
throw new NotImplementedException();
}
protected virtual void Dispose (bool disposing)
{
throw new NotImplementedException();
}
}
private ISoundEffectInstance nativeInstance;
#endregion
#region Public (TODO)
public bool IsDisposed
{
get
{
throw new NotImplementedException();
}
}
public virtual bool IsLooped
{
get;
set;
}
public float Pan
{
get;
set;
}
public float Pitch
{
get;
set;
}
public SoundState State
{
get
{
throw new NotImplementedException();
}
}
public float Volume
{
get;
set;
}
#endregion
#region Constructor
protected SoundEffectInstance()
{
}
internal SoundEffectInstance(SoundEffect setParent)
{
parent = setParent;
nativeInstance =
AddInSystemFactory.Instance.GetDefaultCreator<ISoundSystemCreator>()
.CreateSoundEffectInstance(setParent);
}
~SoundEffectInstance()
{
Dispose();
}
#endregion
#region Apply3D (TODO)
public void Apply3D(AudioListener listener, AudioEmitter emitter)
{
throw new NotImplementedException();
}
public void Apply3D(AudioListener[] listeners, AudioEmitter emitter)
{
throw new NotImplementedException();
}
#endregion
#region Pause (TODO)
public void Pause()
{
throw new NotImplementedException();
}
#endregion
#region Play (TODO)
public virtual void Play()
{
throw new NotImplementedException();
}
#endregion
#region Resume (TODO)
public void Resume()
{
throw new NotImplementedException();
}
#endregion
#region Stop (TODO)
public void Stop()
{
throw new NotImplementedException();
}
public void Stop(bool immediate)
{
throw new NotImplementedException();
}
#endregion
#region Dispose (TODO)
public void Dispose()
{
throw new NotImplementedException();
}
protected virtual void Dispose(bool disposing)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -0,0 +1,56 @@
using System;
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.Framework.NonXNA.SoundSystem
{
public interface ISoundEffect : IDisposable
{
TimeSpan Duration { get; }
}
}

View File

@ -0,0 +1,55 @@
using System;
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.Framework.NonXNA.SoundSystem
{
public interface ISoundEffectInstance : IDisposable
{
}
}

View File

@ -1,11 +1,7 @@
#region Using Statements
using System;
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
#endregion // Using Statements
using ANX.Framework.Audio;
using ANX.Framework.NonXNA.SoundSystem;
#region License
@ -56,8 +52,13 @@ using System.Linq;
namespace ANX.Framework.NonXNA
{
public interface ISoundSystemCreator : ICreator
{
public interface ISoundSystemCreator : ICreator
{
ISoundEffect CreateSoundEffect(Stream stream);
}
ISoundEffect CreateSoundEffect(byte[] buffer, int offset, int count,
int sampleRate, AudioChannels channels, int loopStart, int loopLength);
ISoundEffectInstance CreateSoundEffectInstance(SoundEffect parent);
}
}

View File

@ -58,6 +58,8 @@
<Compile Include="EffectTechniqueGL3.cs" />
<Compile Include="ErrorHelper.cs" />
<Compile Include="GraphicsDeviceWindowsGL3.cs" />
<Compile Include="Helpers\LinuxInterop.cs" />
<Compile Include="Helpers\WindowsInterop.cs" />
<Compile Include="IndexBufferGL3.cs" />
<Compile Include="Metadata.Designer.cs">
<DependentUpon>Metadata.resx</DependentUpon>

View File

@ -1,8 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using ANX.Framework.Windows.GL3.Helpers;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform;
@ -65,64 +64,6 @@ namespace ANX.Framework.Windows.GL3
private const float ColorMultiplier = 1f / 255f;
#endregion
#region Interop
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int width, int height, uint uFlags);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
[DllImport("libX11")]
static extern IntPtr XCreateColormap(IntPtr display, IntPtr window, IntPtr visual, int alloc);
[DllImport("libX11", EntryPoint = "XGetVisualInfo")]
static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo template, out int nitems);
static IntPtr XGetVisualInfo(IntPtr display, int vinfo_mask, ref XVisualInfo template, out int nitems)
{
return XGetVisualInfoInternal(display, (IntPtr)vinfo_mask, ref template, out nitems);
}
[DllImport("libX11")]
extern static int XPending(IntPtr diplay);
[StructLayout(LayoutKind.Sequential)]
struct XVisualInfo
{
public IntPtr Visual;
public IntPtr VisualID;
public int Screen;
public int Depth;
public int Class;
public long RedMask;
public long GreenMask;
public long blueMask;
public int ColormapSize;
public int BitsPerRgb;
public override string ToString()
{
return String.Format("id ({0}), screen ({1}), depth ({2}), class ({3})",
VisualID, Screen, Depth, Class);
}
}
#endregion
#region Private
/// <summary>
/// Native graphics context.
@ -217,49 +158,16 @@ namespace ANX.Framework.Windows.GL3
break;
}
GraphicsMode graphicsMode = new GraphicsMode(DatatypesMapping.SurfaceToColorFormat(presentationParameters.BackBufferFormat),
depth,
stencil,
presentationParameters.MultiSampleCount // AntiAlias Samples: 2/4/8/16/32
);
GraphicsMode graphicsMode = new GraphicsMode(
DatatypesMapping.SurfaceToColorFormat(
presentationParameters.BackBufferFormat),
depth,
stencil,
// AntiAlias Samples: 2/4/8/16/32
presentationParameters.MultiSampleCount);
if (OpenTK.Configuration.RunningOnWindows)
{
nativeWindowInfo = Utilities.CreateWindowsWindowInfo(presentationParameters.DeviceWindowHandle);
}
else if (OpenTK.Configuration.RunningOnX11)
{
// Use reflection to retrieve the necessary values from Mono's Windows.Forms implementation.
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
if (xplatui == null) throw new PlatformNotSupportedException(
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
// get the required handles from the X11 API.
IntPtr display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
IntPtr rootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
int screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
// get the XVisualInfo for this GraphicsMode
XVisualInfo info = new XVisualInfo();
info.VisualID = graphicsMode.Index.Value;
int dummy;
IntPtr infoPtr = XGetVisualInfo(display, 1 /* VisualInfoMask.ID */, ref info, out dummy);
info = (XVisualInfo)Marshal.PtrToStructure(infoPtr, typeof(XVisualInfo));
// set the X11 colormap.
SetStaticFieldValue(xplatui, "CustomVisual", info.Visual);
SetStaticFieldValue(xplatui, "CustomColormap", XCreateColormap(display, rootWindow, info.Visual, 0));
nativeWindowInfo = Utilities.CreateX11WindowInfo(display, screen, presentationParameters.DeviceWindowHandle, rootWindow, infoPtr);
}
else if (OpenTK.Configuration.RunningOnMacOS)
{
nativeWindowInfo = Utilities.CreateMacOSCarbonWindowInfo(presentationParameters.DeviceWindowHandle, false, true);
}
else
{
throw new NotImplementedException();
}
CreateWindowInfo(presentationParameters.DeviceWindowHandle,
graphicsMode.Index.Value);
ResizeRenderWindow(presentationParameters);
@ -278,6 +186,30 @@ namespace ANX.Framework.Windows.GL3
}
#endregion
#region CreateWindowInfo
private void CreateWindowInfo(IntPtr windowHandle, IntPtr graphicsModeHandle)
{
if (OpenTK.Configuration.RunningOnWindows)
{
nativeWindowInfo = Utilities.CreateWindowsWindowInfo(windowHandle);
}
else if (OpenTK.Configuration.RunningOnX11)
{
nativeWindowInfo = LinuxInterop.CreateX11WindowInfo(windowHandle,
graphicsModeHandle);
}
else if (OpenTK.Configuration.RunningOnMacOS)
{
nativeWindowInfo = Utilities.CreateMacOSCarbonWindowInfo(windowHandle,
false, true);
}
else
{
throw new NotImplementedException();
}
}
#endregion
#region SetViewport
/// <summary>
/// Set the OpenGL viewport.
@ -484,38 +416,14 @@ namespace ANX.Framework.Windows.GL3
{
if (OpenTK.Configuration.RunningOnWindows)
{
RECT windowRect;
RECT clientRect;
if (GetWindowRect(presentationParameters.DeviceWindowHandle,
out windowRect) &&
GetClientRect(presentationParameters.DeviceWindowHandle,
out clientRect))
{
int width = presentationParameters.BackBufferWidth +
((windowRect.Right - windowRect.Left) - clientRect.Right);
int height = presentationParameters.BackBufferHeight +
((windowRect.Bottom - windowRect.Top) - clientRect.Bottom);
SetWindowPos(presentationParameters.DeviceWindowHandle, IntPtr.Zero,
windowRect.Left, windowRect.Top, width, height, 0);
}
WindowsInterop.ResizeWindow(presentationParameters.DeviceWindowHandle,
presentationParameters.BackBufferWidth,
presentationParameters.BackBufferHeight);
}
else
{
throw new NotImplementedException();
}
}
#endregion
#region GetStaticFieldValue
static object GetStaticFieldValue(Type type, string fieldName)
{
return type.GetField(fieldName,
BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
}
#endregion
#region SetStaticFieldValue
static void SetStaticFieldValue(Type type, string fieldName, object value)
{
type.GetField(fieldName,
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).SetValue(null, value);
}
#endregion

View File

@ -0,0 +1,149 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using OpenTK.Platform;
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.Framework.Windows.GL3.Helpers
{
internal static class LinuxInterop
{
#region XVisualInfo (Helper struct)
[StructLayout(LayoutKind.Sequential)]
private struct XVisualInfo
{
public IntPtr Visual;
public IntPtr VisualID;
public int Screen;
public int Depth;
public int Class;
public long RedMask;
public long GreenMask;
public long blueMask;
public int ColormapSize;
public int BitsPerRgb;
public override string ToString()
{
return String.Format("id ({0}), screen ({1}), depth ({2}), class ({3})",
VisualID, Screen, Depth, Class);
}
}
#endregion
#region Invokes
[DllImport("libX11")]
private static extern IntPtr XCreateColormap(IntPtr display, IntPtr window,
IntPtr visual, int alloc);
[DllImport("libX11", EntryPoint = "XGetVisualInfo")]
private static extern IntPtr XGetVisualInfoInternal(IntPtr display,
IntPtr vinfo_mask, ref XVisualInfo template, out int nitems);
[DllImport("libX11")]
private static extern int XPending(IntPtr diplay);
#endregion
#region GetStaticFieldValue
private static object GetStaticFieldValue(Type type, string fieldName)
{
return type.GetField(fieldName,
BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
}
#endregion
#region SetStaticFieldValue
private static void SetStaticFieldValue(Type type, string fieldName,
object value)
{
type.GetField(fieldName,
BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, value);
}
#endregion
#region CreateX11WindowInfo
public static IWindowInfo CreateX11WindowInfo(IntPtr windowHandle,
IntPtr graphicsModeHandle)
{
// Use reflection to retrieve the necessary values from Mono's
// Windows.Forms implementation.
Type xplatui = Type.GetType(
"System.Windows.Forms.XplatUIX11, System.Windows.Forms");
if (xplatui == null)
{
throw new PlatformNotSupportedException(
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform " +
"or Mono runtime version, aborting.");
}
// get the required handles from the X11 API.
IntPtr display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
IntPtr rootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
int screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
// get the XVisualInfo for this GraphicsMode
XVisualInfo info = new XVisualInfo()
{
VisualID = graphicsModeHandle,
};
int dummy;
IntPtr infoPtr = XGetVisualInfoInternal(display,
(IntPtr)1 /* VisualInfoMask.ID */, ref info, out dummy);
info = (XVisualInfo)Marshal.PtrToStructure(infoPtr, typeof(XVisualInfo));
// set the X11 colormap.
SetStaticFieldValue(xplatui, "CustomVisual", info.Visual);
SetStaticFieldValue(xplatui, "CustomColormap", XCreateColormap(display, rootWindow, info.Visual, 0));
return Utilities.CreateX11WindowInfo(display, screen, windowHandle,
rootWindow, infoPtr);
}
#endregion
}
}

View File

@ -0,0 +1,112 @@
using System;
using System.Runtime.InteropServices;
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.Framework.Windows.GL3.Helpers
{
internal static class WindowsInterop
{
#region RECT (Helper struct)
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
/// <summary>
/// X position of upper-left corner.
/// </summary>
public int Left;
/// <summary>
/// Y position of upper-left corner.
/// </summary>
public int Top;
/// <summary>
/// X position of lower-right corner.
/// </summary>
public int Right;
/// <summary>
/// Y position of lower-right corner.
/// </summary>
public int Bottom;
}
#endregion
#region Invokes
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int x, int y, int width, int height, uint uFlags);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
#endregion
#region ResizeWindow
public static void ResizeWindow(IntPtr windowHandle, int backBufferWidth,
int backBufferHeight)
{
RECT windowRect;
RECT clientRect;
if (GetWindowRect(windowHandle, out windowRect) &&
GetClientRect(windowHandle, out clientRect))
{
int width = backBufferWidth + ((windowRect.Right - windowRect.Left) -
clientRect.Right);
int height = backBufferHeight + ((windowRect.Bottom - windowRect.Top) -
clientRect.Bottom);
SetWindowPos(windowHandle, IntPtr.Zero, windowRect.Left, windowRect.Top,
width, height, 0);
}
}
#endregion
}
}

View File

@ -1,13 +1,8 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;
using System.Runtime.InteropServices;
using ANX.Framework.Audio;
using ANX.Framework.NonXNA;
#endregion // Using Statements
using ANX.Framework.NonXNA.SoundSystem;
#region License
@ -58,34 +53,65 @@ using ANX.Framework.NonXNA;
namespace ANX.SoundSystem.OpenAL
{
public class Creator : ISoundSystemCreator
{
public class Creator : ISoundSystemCreator
{
#region Public
public string Name
{
get
{
return "OpenAL";
}
}
public void RegisterCreator(AddInSystemFactory factory)
{
factory.AddCreator(this);
}
public int Priority
{
get
{
return 100;
}
}
public string Name
{
get { return "OpenAL"; }
}
public bool IsSupported
{
get
{
PlatformID platform = AddInSystemFactory.Instance.OperatingSystem.Platform;
return platform == PlatformID.Win32NT ||
platform == PlatformID.Unix ||
platform == PlatformID.MacOSX;
}
}
#endregion
public int Priority
{
get { return 100; }
}
#region RegisterCreator
public void RegisterCreator(AddInSystemFactory factory)
{
factory.AddCreator(this);
}
#endregion
public bool IsSupported
{
get
{
//TODO: this is just a very basic version of test for support
return AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.Win32NT ||
AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.Unix ||
AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.MacOSX;
}
}
#region CreateSoundEffectInstance (TODO)
public ISoundEffectInstance CreateSoundEffectInstance(SoundEffect parent)
{
AddInSystemFactory.Instance.PreventSoundSystemChange();
throw new NotImplementedException();
}
#endregion
}
#region CreateSoundEffect (TODO)
public ISoundEffect CreateSoundEffect(Stream stream)
{
AddInSystemFactory.Instance.PreventSoundSystemChange();
throw new NotImplementedException();
}
public ISoundEffect CreateSoundEffect(byte[] buffer, int offset, int count,
int sampleRate, AudioChannels channels, int loopStart, int loopLength)
{
AddInSystemFactory.Instance.PreventSoundSystemChange();
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -85,5 +85,24 @@ namespace ANX.SoundSystem.Windows.XAudio
}
}
}
#region ISoundSystemCreator Member
public Framework.NonXNA.SoundSystem.ISoundEffect CreateSoundEffect(Stream stream)
{
throw new NotImplementedException();
}
public Framework.NonXNA.SoundSystem.ISoundEffect CreateSoundEffect(byte[] buffer, int offset, int count, int sampleRate, Framework.Audio.AudioChannels channels, int loopStart, int loopLength)
{
throw new NotImplementedException();
}
public Framework.NonXNA.SoundSystem.ISoundEffectInstance CreateSoundEffectInstance(Framework.Audio.SoundEffect parent)
{
throw new NotImplementedException();
}
#endregion
}
}