- 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.
This commit is contained in:
SND\AstrorEnales_cp 2011-11-09 19:37:21 +00:00
parent 867ce1f7d6
commit ebcf8d7f6e
8 changed files with 154 additions and 76 deletions

View File

@ -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
}
}

View File

@ -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
/// <summary>
/// Set the OpenGL viewport.
@ -208,6 +180,48 @@ namespace ANX.Framework.Windows.GL3
}
#endregion
#region Clear
/// <summary>
/// Clear the current screen by the specified clear color and options.
/// </summary>
/// <param name="options">Clear options defining which components
/// should be cleared.</param>
/// <param name="color">Clear color.</param>
/// <param name="depth">Depth value.</param>
/// <param name="stencil">Stencil value.</param>
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
/// <summary>
/// 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<T>(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>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
public void DrawUserPrimitives<T>(PrimitiveType primitiveType,
T[] vertexData, int vertexOffset, int primitiveCount,
VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
}
public void GetBackBufferData<T>(T[] data) where T : struct
{
throw new NotImplementedException();
}
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset,
int primitiveCount)
{
throw new NotImplementedException();
}
public void GetBackBufferData<T>(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<T>(Rectangle? rect, T[] data,
int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
public void DrawUserIndexedPrimitives<T>(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>(T[] data) where T : struct
{
throw new NotImplementedException();
}
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
}
}
public void GetBackBufferData<T>(T[] data, int startIndex,
int elementCount) where T : struct
{
throw new NotImplementedException();
}
}
}

View File

@ -60,7 +60,11 @@ namespace ANX.Framework
public struct Color : IPackedVector<uint>, IPackedVector, IEquatable<Color>
{
#region Private Members
private uint packedValue;
/// <summary>
/// Marcel NOTE: I made this internal and befriend the ANX.Framework
/// with the OGL Module so the datatype conversion can be made faster.
/// </summary>
internal uint packedValue;
#endregion // Private Members

View File

@ -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")]

View File

@ -1,4 +1,4 @@
namespace XnaToAnxConverter
namespace XNAToANXConverter
{
partial class ConverterForm
{

View File

@ -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
}
}

View File

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace XnaToAnxConverter
namespace XNAToANXConverter
{
static class Program
{

View File

@ -48,6 +48,7 @@
<DependentUpon>ConverterForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="ProjectData.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="ConverterForm.resx">
<DependentUpon>ConverterForm.cs</DependentUpon>