first working version of Texture2D ANX content pipeline

This commit is contained in:
Glatzemann 2012-10-05 09:55:12 +00:00 committed by Konstantin Koch
parent 298aad1a1c
commit 193cd6d61c
2 changed files with 32 additions and 2 deletions

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
#endregion
@ -17,16 +18,18 @@ namespace ANX.Framework.Content.Pipeline.Graphics
public class PixelBitmapContent<T> : BitmapContent where T : struct, IEquatable<T>
{
private T[,] pixels;
private int pixelSize;
protected PixelBitmapContent()
{
this.pixelSize = Marshal.SizeOf(typeof(T));
}
public PixelBitmapContent(int width, int height)
: base(width, height)
{
pixels = new T[width, height];
this.pixelSize = Marshal.SizeOf(typeof(T));
}
public T GetPixel(int x, int y)
@ -38,14 +41,39 @@ namespace ANX.Framework.Content.Pipeline.Graphics
{
int rowSize = Marshal.SizeOf(typeof(T)) * base.Width;
byte[] array = new byte[rowSize * base.Height];
int destinationIndex = 0;
for (int i = 0; i < base.Height; i++)
{
T[] row = GetRow(i);
for (int x = 0; x < row.Length; x++)
{
Array.Copy(GetBytes<T>(row[x]), 0, array, destinationIndex, pixelSize);
destinationIndex += pixelSize;
}
}
return array;
}
private static byte[] GetBytes<T>(T value)
{
byte[] buffer = new byte[Marshal.SizeOf(typeof(T))];
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try
{
Marshal.StructureToPtr(value, handle.AddrOfPinnedObject(), false);
}
finally
{
handle.Free();
}
return buffer;
}
public T[] GetRow(int y)
{
T[] row = new T[Width];

View File

@ -67,7 +67,9 @@
<Reference Include="System.Net" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddInSelector.cs" />
<Compile Include="AddInSelector.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="AddInSelector.Designer.cs">
<DependentUpon>AddInSelector.cs</DependentUpon>
</Compile>