diff --git a/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs b/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs
index 41591ad0..6f11f026 100644
--- a/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs
+++ b/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs
@@ -57,248 +57,252 @@ namespace ANX.Framework.Windows.GL3
///
/// Native OpenGL implementation for a graphics device.
///
- public class GraphicsDeviceWindowsGL3 : INativeGraphicsDevice
- {
- #region Constants
- private const float ColorMultiplier = 1f / 255f;
- #endregion
+ public class GraphicsDeviceWindowsGL3 : INativeGraphicsDevice
+ {
+ #region Constants
+ private const float ColorMultiplier = 1f / 255f;
+ #endregion
- #region Private
- ///
- /// Native graphics context.
- ///
- private GraphicsContext nativeContext;
+ #region Private
+ ///
+ /// Native graphics context.
+ ///
+ private GraphicsContext nativeContext;
- ///
- /// The OpenTK window info helper class to provide window informations
- /// to the graphics device.
- ///
- private IWindowInfo nativeWindowInfo;
- #endregion
+ ///
+ /// The OpenTK window info helper class to provide window informations
+ /// to the graphics device.
+ ///
+ private IWindowInfo nativeWindowInfo;
+ #endregion
- #region Constructor
- ///
- /// Create a new OpenGL graphics context.
- ///
- /// Parameters for the window
- /// and graphics context.
- internal GraphicsDeviceWindowsGL3(
- PresentationParameters presentationParameters)
- {
- ResetDevice(presentationParameters);
- }
- #endregion
+ #region Constructor
+ ///
+ /// Create a new OpenGL graphics context.
+ ///
+ /// Parameters for the window
+ /// and graphics context.
+ internal GraphicsDeviceWindowsGL3(
+ PresentationParameters presentationParameters)
+ {
+ ResetDevice(presentationParameters);
+ }
+ #endregion
- #region ResetDevice
- ///
- /// Reset the graphics device with the given presentation paramters.
- /// If a device is currently set, then we dispose the old one.
- ///
- /// Parameters for the
- /// graphics device.
- private void ResetDevice(PresentationParameters presentationParameters)
- {
- #region Validation
- if (nativeContext != null)
- {
- nativeContext.Dispose();
- nativeContext = null;
- }
+ #region ResetDevice
+ ///
+ /// Reset the graphics device with the given presentation paramters.
+ /// If a device is currently set, then we dispose the old one.
+ ///
+ /// Parameters for the
+ /// graphics device.
+ private void ResetDevice(PresentationParameters presentationParameters)
+ {
+ #region Validation
+ if (nativeContext != null)
+ {
+ nativeContext.Dispose();
+ nativeContext = null;
+ }
- if (nativeWindowInfo != null)
- {
- nativeWindowInfo.Dispose();
- nativeWindowInfo = null;
- }
- #endregion
+ if (nativeWindowInfo != null)
+ {
+ nativeWindowInfo.Dispose();
+ nativeWindowInfo = null;
+ }
+ #endregion
- // OpenGL Depth Buffer Size: 0/16/24/32
- int depth = 0;
- int stencil = 0;
- switch (presentationParameters.DepthStencilFormat)
- {
- case DepthFormat.None:
- break;
+ // OpenGL Depth Buffer Size: 0/16/24/32
+ int depth = 0;
+ int stencil = 0;
+ switch (presentationParameters.DepthStencilFormat)
+ {
+ case DepthFormat.None:
+ break;
- case DepthFormat.Depth16:
- depth = 16;
- break;
+ case DepthFormat.Depth16:
+ depth = 16;
+ break;
- case DepthFormat.Depth24:
- depth = 24;
- break;
+ case DepthFormat.Depth24:
+ depth = 24;
+ break;
- case DepthFormat.Depth24Stencil8:
- depth = 24;
- stencil = 8;
- break;
- }
+ case DepthFormat.Depth24Stencil8:
+ depth = 24;
+ stencil = 8;
+ break;
+ }
- nativeWindowInfo = Utilities.CreateWindowsWindowInfo(
- presentationParameters.DeviceWindowHandle);
+ nativeWindowInfo = Utilities.CreateWindowsWindowInfo(
+ presentationParameters.DeviceWindowHandle);
- GraphicsMode graphicsMode = new GraphicsMode(
- DatatypesMapping.SurfaceToColorFormat(
- presentationParameters.BackBufferFormat),
- depth, stencil,
- // AntiAlias Samples: 2/4/8/16/32
- presentationParameters.MultiSampleCount);
+ GraphicsMode graphicsMode = new GraphicsMode(
+ DatatypesMapping.SurfaceToColorFormat(
+ presentationParameters.BackBufferFormat),
+ depth, stencil,
+ // AntiAlias Samples: 2/4/8/16/32
+ presentationParameters.MultiSampleCount);
- nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo);
- nativeContext.MakeCurrent(nativeWindowInfo);
- nativeContext.LoadAll();
- }
- #endregion
+ nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo);
+ nativeContext.MakeCurrent(nativeWindowInfo);
+ nativeContext.LoadAll();
+ }
+ #endregion
- #region SetViewport
- ///
- /// Set the OpenGL viewport.
- ///
- /// Viewport data to set natively.
- public void SetViewport(Viewport viewport)
- {
- GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);
- }
- #endregion
+ #region SetViewport
+ ///
+ /// Set the OpenGL viewport.
+ ///
+ /// Viewport data to set natively.
+ public void SetViewport(Viewport viewport)
+ {
+ GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);
+ }
+ #endregion
- #region Clear
- private uint lastClearColor;
- ///
- /// Clear the current screen by the specified clear color.
- ///
- /// Clear color.
- public void Clear(ref Color color)
- {
- uint newClearColor = color.PackedValue;
- if (lastClearColor != newClearColor)
- {
- lastClearColor = newClearColor;
- GL.ClearColor(color.R * ColorMultiplier, color.G * ColorMultiplier,
- color.B * ColorMultiplier, color.A * ColorMultiplier);
- }
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- }
+ #region Clear
+ private uint lastClearColor;
+ ///
+ /// Clear the current screen by the specified clear color.
+ ///
+ /// Clear color.
+ public void Clear(ref Color color)
+ {
+ uint newClearColor = color.PackedValue;
+ if (lastClearColor != newClearColor)
+ {
+ lastClearColor = newClearColor;
+ GL.ClearColor(color.R * ColorMultiplier, color.G * ColorMultiplier,
+ color.B * ColorMultiplier, color.A * ColorMultiplier);
+ }
+ GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
+ }
- ///
- /// Clear the current screen by the specified clear color and options.
- ///
- /// Clear options defining which components
- /// should be cleared.
- /// Clear color.
- /// Depth value.
- /// Stencil value.
- public void Clear(ClearOptions options, Vector4 color, float depth,
- int stencil)
- {
- Color anxColor;
- DatatypesMapping.Convert(ref color, out anxColor);
- uint newClearColor = anxColor.PackedValue;
- if (lastClearColor != newClearColor)
- {
- lastClearColor = newClearColor;
- GL.ClearColor(anxColor.R * ColorMultiplier, anxColor.G * ColorMultiplier,
- anxColor.B * ColorMultiplier, anxColor.A * ColorMultiplier);
- }
+ ///
+ /// Clear the current screen by the specified clear color and options.
+ ///
+ /// Clear options defining which components
+ /// should be cleared.
+ /// Clear color.
+ /// Depth value.
+ /// Stencil value.
+ public void Clear(ClearOptions options, Vector4 color, float depth,
+ int stencil)
+ {
+ Color anxColor;
+ DatatypesMapping.Convert(ref color, out anxColor);
+ uint newClearColor = anxColor.PackedValue;
+ if (lastClearColor != newClearColor)
+ {
+ lastClearColor = newClearColor;
+ GL.ClearColor(anxColor.R * ColorMultiplier, anxColor.G * ColorMultiplier,
+ anxColor.B * ColorMultiplier, anxColor.A * ColorMultiplier);
+ }
- ClearBufferMask mask = (ClearBufferMask)0;
- if ((options | ClearOptions.Target) == options)
- {
- mask |= ClearBufferMask.ColorBufferBit;
- }
- if ((options | ClearOptions.Stencil) == options)
- {
- mask |= ClearBufferMask.StencilBufferBit;
- }
- if ((options | ClearOptions.DepthBuffer) == options)
- {
- mask |= ClearBufferMask.DepthBufferBit;
- }
+ ClearBufferMask mask = (ClearBufferMask)0;
+ if ((options | ClearOptions.Target) == options)
+ {
+ mask |= ClearBufferMask.ColorBufferBit;
+ }
+ if ((options | ClearOptions.Stencil) == options)
+ {
+ mask |= ClearBufferMask.StencilBufferBit;
+ }
+ if ((options | ClearOptions.DepthBuffer) == options)
+ {
+ mask |= ClearBufferMask.DepthBufferBit;
+ }
- GL.ClearDepth(depth);
- GL.ClearStencil(stencil);
- GL.Clear(mask);
- }
- #endregion
+ GL.ClearDepth(depth);
+ GL.ClearStencil(stencil);
+ GL.Clear(mask);
+ }
+ #endregion
- #region Present
- ///
- /// Swap the graphics buffers.
- ///
- public void Present()
- {
- nativeContext.SwapBuffers();
- }
- #endregion
+ #region Present
+ ///
+ /// Swap the graphics buffers.
+ ///
+ public void Present()
+ {
+ if (WindowsGameWindow.Form != null &&
+ WindowsGameWindow.Form.IsDisposed == false)
+ {
+ nativeContext.SwapBuffers();
+ }
+ }
+ #endregion
- public void DrawIndexedPrimitives(PrimitiveType primitiveType,
- int baseVertex, int minVertexIndex, int numVertices, int startIndex,
- int primitiveCount)
- {
- throw new NotImplementedException();
- }
+ public void DrawIndexedPrimitives(PrimitiveType primitiveType,
+ int baseVertex, int minVertexIndex, int numVertices, int startIndex,
+ int primitiveCount)
+ {
+ throw new NotImplementedException();
+ }
- public void DrawInstancedPrimitives(PrimitiveType primitiveType,
- int baseVertex, int minVertexIndex, int numVertices, int startIndex,
- int primitiveCount, int instanceCount)
- {
- throw new NotImplementedException();
- }
+ public void DrawInstancedPrimitives(PrimitiveType primitiveType,
+ int baseVertex, int minVertexIndex, int numVertices, int startIndex,
+ int primitiveCount, int instanceCount)
+ {
+ throw new NotImplementedException();
+ }
- public void DrawUserIndexedPrimitives(PrimitiveType primitiveType,
- T[] vertexData, int vertexOffset, int numVertices, Array indexData,
- int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration,
- IndexElementSize indexFormat) where T : struct, IVertexType
- {
- throw new NotImplementedException();
- }
+ public void DrawUserIndexedPrimitives(PrimitiveType primitiveType,
+ T[] vertexData, int vertexOffset, int numVertices, Array indexData,
+ int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration,
+ IndexElementSize indexFormat) where T : struct, IVertexType
+ {
+ throw new NotImplementedException();
+ }
- public void DrawUserPrimitives(PrimitiveType primitiveType,
- T[] vertexData, int vertexOffset, int primitiveCount,
- VertexDeclaration vertexDeclaration) where T : struct, IVertexType
- {
- throw new NotImplementedException();
- }
+ public void DrawUserPrimitives(PrimitiveType primitiveType,
+ T[] vertexData, int vertexOffset, int primitiveCount,
+ VertexDeclaration vertexDeclaration) where T : struct, IVertexType
+ {
+ throw new NotImplementedException();
+ }
- public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset,
- int primitiveCount)
- {
- throw new NotImplementedException();
- }
+ public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset,
+ int primitiveCount)
+ {
+ throw new NotImplementedException();
+ }
- public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
- {
- throw new NotImplementedException();
- }
+ public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
+ {
+ throw new NotImplementedException();
+ }
- public void SetIndexBuffer(IndexBuffer indexBuffer)
- {
- throw new NotImplementedException();
- }
+ public void SetIndexBuffer(IndexBuffer indexBuffer)
+ {
+ throw new NotImplementedException();
+ }
- public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
- {
- throw new NotImplementedException();
- }
+ public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
+ {
+ throw new NotImplementedException();
+ }
- public void GetBackBufferData(Rectangle? rect, T[] data,
- int startIndex, int elementCount) where T : struct
- {
- throw new NotImplementedException();
- }
+ public void GetBackBufferData(Rectangle? rect, T[] data,
+ int startIndex, int elementCount) where T : struct
+ {
+ throw new NotImplementedException();
+ }
- public void GetBackBufferData(T[] data) where T : struct
- {
- throw new NotImplementedException();
- }
+ public void GetBackBufferData(T[] data) where T : struct
+ {
+ throw new NotImplementedException();
+ }
- public void GetBackBufferData(T[] data, int startIndex, int elementCount) where T : struct
- {
- throw new NotImplementedException();
- }
+ public void GetBackBufferData(T[] data, int startIndex, int elementCount) where T : struct
+ {
+ throw new NotImplementedException();
+ }
- public void ResizeBuffers(PresentationParameters presentationParameters)
- {
- throw new NotImplementedException();
- }
- }
+ public void ResizeBuffers(PresentationParameters presentationParameters)
+ {
+ throw new NotImplementedException();
+ }
+ }
}
diff --git a/ANX.Framework.Windows.GL3/WindowsGameHost.cs b/ANX.Framework.Windows.GL3/WindowsGameHost.cs
index a95e5fc0..df564c86 100644
--- a/ANX.Framework.Windows.GL3/WindowsGameHost.cs
+++ b/ANX.Framework.Windows.GL3/WindowsGameHost.cs
@@ -53,10 +53,13 @@ namespace ANX.Framework.Windows.GL3
{
public class WindowsGameHost : GameHost
{
+ #region Private
private Game game;
private WindowsGameWindow gameWindow;
private bool isQuitting;
+ #endregion
+ #region Public
public override GameWindow Window
{
get
@@ -64,16 +67,15 @@ namespace ANX.Framework.Windows.GL3
return this.gameWindow;
}
}
+ #endregion
+ #region Constructor
public WindowsGameHost(Game setGame)
: base(setGame)
{
isQuitting = false;
game = setGame;
gameWindow = new WindowsGameWindow();
- //Mouse.WindowHandle = gameWindow.Handle;
- //TouchPanel.WindowHandle = gameWindow.Handle;
- //gameWindow.IsMouseVisible = game.IsMouseVisible;
gameWindow.Activated += delegate
{
OnActivated();
@@ -82,13 +84,17 @@ namespace ANX.Framework.Windows.GL3
{
OnDeactivated();
};
- //gameWindow.Suspend += GameWindowSuspend;
- //gameWindow.Resume += GameWindowResume;
+ WindowsGameWindow.Form.FormClosing += delegate
+ {
+ isQuitting = true;
+ };
}
+ #endregion
+ #region Run
public override void Run()
{
- gameWindow.Form.Show();
+ WindowsGameWindow.Form.Show();
while (isQuitting == false)
{
Application.DoEvents();
@@ -96,10 +102,13 @@ namespace ANX.Framework.Windows.GL3
}
gameWindow.Close();
}
+ #endregion
+ #region Exit
public override void Exit()
{
isQuitting = true;
}
+ #endregion
}
}
diff --git a/ANX.Framework.Windows.GL3/WindowsGameWindow.cs b/ANX.Framework.Windows.GL3/WindowsGameWindow.cs
index 4b2255b1..17700622 100644
--- a/ANX.Framework.Windows.GL3/WindowsGameWindow.cs
+++ b/ANX.Framework.Windows.GL3/WindowsGameWindow.cs
@@ -52,94 +52,118 @@ using OpenTK.Platform.Windows;
namespace ANX.Framework.Windows.GL3
{
- internal class WindowsGameWindow : ANX.Framework.GameWindow
+ internal class WindowsGameWindow : ANX.Framework.GameWindow
+ {
+ #region Public
+ internal static Form Form
{
- #region Public
- public Form Form
+ get;
+ private set;
+ }
+
+ public override IntPtr Handle
+ {
+ get
{
- get;
- private set;
+ return Form.Handle;
}
+ }
- public override IntPtr Handle
+ public override bool IsMinimized
+ {
+ get
{
- get
- {
- return Form.Handle;
- }
+ return Form.WindowState == FormWindowState.Minimized;
}
+ }
- public override bool IsMinimized
+ #region AllowUserResizing
+ public override bool AllowUserResizing
+ {
+ get
{
- get
- {
- return Form.WindowState == FormWindowState.Minimized;
- }
+ return Form.FormBorderStyle == FormBorderStyle.Sizable;
}
- #endregion
-
- #region Constructor
- internal WindowsGameWindow()
+ set
{
- Form = new Form()
- {
- Text = "ANX Framework",
- };
+ Form.FormBorderStyle = value ?
+ FormBorderStyle.Sizable :
+ FormBorderStyle.Fixed3D;
}
- #endregion
+ }
+ #endregion
- #region Close
- public void Close()
+ #region ClientBounds
+ public override Rectangle ClientBounds
+ {
+ get
{
- if (Form != null)
- {
- Form.Close();
- Form.Dispose();
- Form = null;
- }
+ System.Drawing.Rectangle rect = Form.ClientRectangle;
+ return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
}
- #endregion
+ }
+ #endregion
- public override void BeginScreenDeviceChange(bool willBeFullScreen)
- {
- throw new NotImplementedException();
- }
+ #region CurrentOrientation
+ public override DisplayOrientation CurrentOrientation
+ {
+ get
+ {
+ return DisplayOrientation.Default;
+ }
+ }
+ #endregion
+ #endregion
- public override void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)
- {
- throw new NotImplementedException();
- }
+ #region Constructor
+ internal WindowsGameWindow()
+ {
+ Form = new Form()
+ {
+ Text = "ANX Framework",
+ MaximizeBox = false,
+ FormBorderStyle = FormBorderStyle.Fixed3D,
+ ClientSize = new System.Drawing.Size(800, 600),
+ };
+ }
+ #endregion
- protected override void SetTitle(string title)
- {
- throw new NotImplementedException();
- }
+ #region Close
+ public void Close()
+ {
+ if (Form != null)
+ {
+ Form.Close();
+ Form.Dispose();
+ Form = null;
+ }
+ }
+ #endregion
- public override bool AllowUserResizing
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
+ #region SetTitle
+ protected override void SetTitle(string title)
+ {
+ Form.Text = title;
+ }
+ #endregion
- public override Rectangle ClientBounds
- {
- get { throw new NotImplementedException(); }
- }
+ public override void BeginScreenDeviceChange(bool willBeFullScreen)
+ {
+ throw new NotImplementedException();
+ }
- public override string ScreenDeviceName
- {
- get { throw new NotImplementedException(); }
- }
+ public override void EndScreenDeviceChange(string screenDeviceName,
+ int clientWidth, int clientHeight)
+ {
+ throw new NotImplementedException();
+ }
- public override DisplayOrientation CurrentOrientation
- {
- get { throw new NotImplementedException(); }
- }
- }
+ public override string ScreenDeviceName
+ {
+ get
+ {
+ throw new NotImplementedException();
+ }
+ }
+ }
}
diff --git a/Tools/XNAToANXConverter/ProjectData.cs b/Tools/XNAToANXConverter/ProjectData.cs
new file mode 100644
index 00000000..4c0f62a9
--- /dev/null
+++ b/Tools/XNAToANXConverter/ProjectData.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.Xml;
+using System.Xml.Linq;
+using System.IO;
+
+namespace XNAToANXConverter
+{
+ public static class ProjectData
+ {
+ private const string XnaBaseName = "Microsoft.Xna.Framework";
+ private const string AnxBaseName = "ANX.Framework";
+
+ #region Convert
+ public static void Convert(string sourceFilepath, string destinationFilepath)
+ {
+ string sourceFolderPath =
+ sourceFilepath.Replace(Path.GetFileName(sourceFilepath), "");
+ string destinationFolderPath =
+ destinationFilepath.Replace(Path.GetFileName(destinationFilepath), "");
+
+ if (Directory.Exists(destinationFolderPath) == false)
+ {
+ Directory.CreateDirectory(destinationFolderPath);
+ }
+
+ XDocument doc = XDocument.Load(sourceFilepath);
+ XElement root = doc.Root;
+ foreach (XElement propertyGroup in root.Elements())
+ {
+ if (propertyGroup.Name.LocalName != "ItemGroup")
+ {
+ continue;
+ }
+
+ List elements = new List(propertyGroup.Elements());
+ foreach (XElement item in elements)
+ {
+ if (item.Name.LocalName == "Reference")
+ {
+ #region Process Reference
+ string assemblyPath = item.Attribute("Include").Value;
+ if (assemblyPath.Contains(XnaBaseName))
+ {
+ item.Remove();
+
+ string anxPath = assemblyPath.Replace(XnaBaseName, AnxBaseName);
+ if (anxPath.Contains(", Version"))
+ {
+ anxPath = anxPath.Substring(0, anxPath.IndexOf(',')) + ".dll";
+ }
+ propertyGroup.Add(new XElement("Reference",
+ new XAttribute("Include", anxPath)));
+ }
+ #endregion
+ }
+ else if (item.Name.LocalName == "Compile")
+ {
+ #region Process Compile
+ string codeFilepath = item.Attribute("Include").Value;
+ string absolutePath = Path.Combine(sourceFolderPath, codeFilepath);
+ string text = File.ReadAllText(absolutePath);
+
+ text = text.Replace(XnaBaseName, AnxBaseName);
+
+ string destCodeFolderPath = codeFilepath.Replace(
+ Path.GetFileName(codeFilepath), "");
+
+ destCodeFolderPath = Path.Combine(destinationFolderPath,
+ destCodeFolderPath);
+ if (Directory.Exists(destCodeFolderPath) == false)
+ {
+ Directory.CreateDirectory(destCodeFolderPath);
+ }
+
+ File.WriteAllText(Path.Combine(destinationFolderPath,
+ codeFilepath), text);
+ #endregion
+ }
+ else if (item.Name.LocalName == "BootstrapperPackage")
+ {
+ #region Process BootstrapperPackage
+ // Remove all bootstrapper tasks for XNA.
+ string includeName = item.Attribute("Include").Value;
+ if (includeName.Contains(XnaBaseName))
+ {
+ item.Remove();
+ }
+ #endregion
+ }
+ }
+ }
+
+ doc.Save(destinationFilepath);
+ }
+ #endregion
+ }
+}