From ebcf8d7f6e3e5374d5f690205dfd2ad1f512e5f0 Mon Sep 17 00:00:00 2001 From: "SND\\AstrorEnales_cp" Date: Wed, 9 Nov 2011 19:37:21 +0000 Subject: [PATCH] - Finished first working version of the XNA to ANX converter - Implemented second Clear method for OGL - Improved the DatatypesMapping by making the packedValue of Color internal and visible to the ogl library. --- ANX.Framework.Windows.GL3/DatatypesMapping.cs | 39 ++++- .../GraphicsDeviceWindowsGL3.cs | 162 +++++++++++------- ANX.Framework/Color.cs | 6 +- ANX.Framework/Properties/AssemblyInfo.cs | 2 + .../ConverterForm.Designer.cs | 2 +- Tools/XNAToANXConverter/ConverterForm.cs | 14 +- Tools/XNAToANXConverter/Program.cs | 4 +- .../XNAToANXConverter.csproj | 1 + 8 files changed, 154 insertions(+), 76 deletions(-) diff --git a/ANX.Framework.Windows.GL3/DatatypesMapping.cs b/ANX.Framework.Windows.GL3/DatatypesMapping.cs index 1e83f7bd..f4d9c7ed 100644 --- a/ANX.Framework.Windows.GL3/DatatypesMapping.cs +++ b/ANX.Framework.Windows.GL3/DatatypesMapping.cs @@ -53,7 +53,9 @@ namespace ANX.Framework.Windows.GL3 { internal static class DatatypesMapping { + #region Constants public const float ColorMultiplier = 1f / 255f; + #endregion #region Convert ANX.Color -> OpenTK.Color4 public static void Convert(ref Color anxColor, out Color4 otkColor) @@ -68,14 +70,22 @@ namespace ANX.Framework.Windows.GL3 #region Convert OpenTK.Color4 -> ANX.Color public static void Convert(ref Color4 otkColor, out Color anxColor) { - anxColor = new Color(otkColor.R, otkColor.G, otkColor.B, otkColor.A); + byte r = (byte)(otkColor.R * 255); + byte g = (byte)(otkColor.G * 255); + byte b = (byte)(otkColor.B * 255); + byte a = (byte)(otkColor.A * 255); + anxColor.packedValue = (uint)(r + (g << 8) + (b << 16) + (a << 24)); + } + #endregion -// TODO: would be faster but can't access the private uint. Fix this later. - //byte r = (byte)(otkColor.R * 255); - //byte g = (byte)(otkColor.G * 255); - //byte b = (byte)(otkColor.B * 255); - //byte a = (byte)(otkColor.A * 255); - //anxColor.PackedValue = (uint)(r + (g << 8) + (b << 16) + (a << 24)); + #region Convert ANX.Vector4 -> ANX.Color + public static void Convert(ref Vector4 anxVector, out Color anxColor) + { + byte r = (byte)(anxVector.X * 255); + byte g = (byte)(anxVector.Y * 255); + byte b = (byte)(anxVector.Z * 255); + byte a = (byte)(anxVector.W * 255); + anxColor.packedValue = (uint)(r + (g << 8) + (b << 16) + (a << 24)); } #endregion @@ -148,5 +158,20 @@ namespace ANX.Framework.Windows.GL3 } } #endregion + + #region Tests + private class Tests + { + #region TestConvertVector4ToColor + public static void TestConvertVector4ToColor() + { + Vector4 vector = new Vector4(1f, 0.5f, 0.75f, 0f); + Color color; + DatatypesMapping.Convert(ref vector, out color); + Console.WriteLine(color.ToString()); + } + #endregion + } + #endregion } } diff --git a/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs b/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs index 4d6f343b..e121bc29 100644 --- a/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs +++ b/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs @@ -149,35 +149,7 @@ namespace ANX.Framework.Windows.GL3 nativeContext.LoadAll(); } #endregion - - public void DrawUserPrimitive() - { - throw new NotImplementedException(); - } - - public void DrawIndexedPrimitives(PrimitiveType primitiveType, - int baseVertex, int minVertexIndex, int numVertices, int startIndex, - 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 SetIndexBuffer(IndexBuffer indexBuffer) - { - throw new NotImplementedException(); - } - + #region SetViewport /// /// Set the OpenGL viewport. @@ -208,6 +180,48 @@ namespace ANX.Framework.Windows.GL3 } #endregion + #region Clear + /// + /// 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; + } + + GL.ClearDepth(depth); + GL.ClearStencil(stencil); + GL.Clear(mask); + } + #endregion + #region Present /// /// Swap the graphics buffers. @@ -218,47 +232,71 @@ namespace ANX.Framework.Windows.GL3 } #endregion + public void DrawIndexedPrimitives(PrimitiveType primitiveType, + int baseVertex, int minVertexIndex, int numVertices, int startIndex, + int primitiveCount) + { + throw new NotImplementedException(); + } - public void SetRenderTargets(params RenderTargetBinding[] renderTargets) - { - 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 GetBackBufferData(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct - { - 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 GetBackBufferData(T[] data) where T : struct - { - throw new NotImplementedException(); - } + public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, + int primitiveCount) + { + throw new NotImplementedException(); + } - public void GetBackBufferData(T[] data, int startIndex, int elementCount) where T : struct - { - throw new NotImplementedException(); - } + public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers) + { + throw new NotImplementedException(); + } + public void SetIndexBuffer(IndexBuffer indexBuffer) + { + throw new NotImplementedException(); + } - public void Clear(ClearOptions options, Vector4 color, float depth, int stencil) - { - throw new NotImplementedException(); - } + public void SetRenderTargets(params RenderTargetBinding[] renderTargets) + { + 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 GetBackBufferData(Rectangle? rect, T[] data, + int startIndex, int elementCount) where T : struct + { + 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 GetBackBufferData(T[] data) where T : struct + { + 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 GetBackBufferData(T[] data, int startIndex, + int elementCount) where T : struct + { + throw new NotImplementedException(); + } + } } diff --git a/ANX.Framework/Color.cs b/ANX.Framework/Color.cs index a392fd0b..b388a676 100644 --- a/ANX.Framework/Color.cs +++ b/ANX.Framework/Color.cs @@ -60,7 +60,11 @@ namespace ANX.Framework public struct Color : IPackedVector, IPackedVector, IEquatable { #region Private Members - private uint packedValue; + /// + /// Marcel NOTE: I made this internal and befriend the ANX.Framework + /// with the OGL Module so the datatype conversion can be made faster. + /// + internal uint packedValue; #endregion // Private Members diff --git a/ANX.Framework/Properties/AssemblyInfo.cs b/ANX.Framework/Properties/AssemblyInfo.cs index 9bf7af13..b0d5cb63 100644 --- a/ANX.Framework/Properties/AssemblyInfo.cs +++ b/ANX.Framework/Properties/AssemblyInfo.cs @@ -34,3 +34,5 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("0.4.1.*")] [assembly: AssemblyFileVersion("0.4.1.0")] + +[assembly:InternalsVisibleTo("ANX.Framework.Windows.GL3")] \ No newline at end of file diff --git a/Tools/XNAToANXConverter/ConverterForm.Designer.cs b/Tools/XNAToANXConverter/ConverterForm.Designer.cs index 22a4d3fd..9bc2c88b 100644 --- a/Tools/XNAToANXConverter/ConverterForm.Designer.cs +++ b/Tools/XNAToANXConverter/ConverterForm.Designer.cs @@ -1,4 +1,4 @@ -namespace XnaToAnxConverter +namespace XNAToANXConverter { partial class ConverterForm { diff --git a/Tools/XNAToANXConverter/ConverterForm.cs b/Tools/XNAToANXConverter/ConverterForm.cs index d9b9d9e2..7bfb3773 100644 --- a/Tools/XNAToANXConverter/ConverterForm.cs +++ b/Tools/XNAToANXConverter/ConverterForm.cs @@ -4,7 +4,7 @@ using System.Drawing.Drawing2D; using System.IO; using System.Windows.Forms; -namespace XnaToAnxConverter +namespace XNAToANXConverter { public partial class ConverterForm : Form { @@ -30,12 +30,15 @@ namespace XnaToAnxConverter } #endregion + #region checkBox1_CheckedChanged private void checkBox1_CheckedChanged(object sender, EventArgs e) { destPath.Enabled = checkBox1.Checked; browsePath2.Enabled = checkBox1.Checked; } + #endregion + #region browsePath1_Click private void browsePath1_Click(object sender, EventArgs e) { using (OpenFileDialog dialog = new OpenFileDialog()) @@ -50,7 +53,9 @@ namespace XnaToAnxConverter } } } + #endregion + #region browsePath2_Click private void browsePath2_Click(object sender, EventArgs e) { using (SaveFileDialog dialog = new SaveFileDialog()) @@ -59,13 +64,16 @@ namespace XnaToAnxConverter dialog.InitialDirectory = "C:\\"; dialog.Filter = "csproj file|*.csproj"; dialog.CheckFileExists = false; + dialog.CheckPathExists = false; if (dialog.ShowDialog() == DialogResult.OK) { destPath.Text = dialog.FileName; } } } + #endregion + #region convertButton_Click private void convertButton_Click(object sender, EventArgs e) { string source = sourcePath.Text; @@ -92,7 +100,9 @@ namespace XnaToAnxConverter return; } - // TODO: convert + ProjectData.Convert(source, dest); + MessageBox.Show("Finished conversion!", "Conversion"); } + #endregion } } diff --git a/Tools/XNAToANXConverter/Program.cs b/Tools/XNAToANXConverter/Program.cs index 13ddaad4..2513dbc6 100644 --- a/Tools/XNAToANXConverter/Program.cs +++ b/Tools/XNAToANXConverter/Program.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Windows.Forms; -namespace XnaToAnxConverter +namespace XNAToANXConverter { static class Program { diff --git a/Tools/XNAToANXConverter/XNAToANXConverter.csproj b/Tools/XNAToANXConverter/XNAToANXConverter.csproj index 40328d82..69f48f11 100644 --- a/Tools/XNAToANXConverter/XNAToANXConverter.csproj +++ b/Tools/XNAToANXConverter/XNAToANXConverter.csproj @@ -48,6 +48,7 @@ ConverterForm.cs + ConverterForm.cs