first working version of Texture2D ANX content pipeline
This commit is contained in:
parent
298aad1a1c
commit
193cd6d61c
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -17,16 +18,18 @@ namespace ANX.Framework.Content.Pipeline.Graphics
|
|||||||
public class PixelBitmapContent<T> : BitmapContent where T : struct, IEquatable<T>
|
public class PixelBitmapContent<T> : BitmapContent where T : struct, IEquatable<T>
|
||||||
{
|
{
|
||||||
private T[,] pixels;
|
private T[,] pixels;
|
||||||
|
private int pixelSize;
|
||||||
|
|
||||||
protected PixelBitmapContent()
|
protected PixelBitmapContent()
|
||||||
{
|
{
|
||||||
|
this.pixelSize = Marshal.SizeOf(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PixelBitmapContent(int width, int height)
|
public PixelBitmapContent(int width, int height)
|
||||||
: base(width, height)
|
: base(width, height)
|
||||||
{
|
{
|
||||||
pixels = new T[width, height];
|
pixels = new T[width, height];
|
||||||
|
this.pixelSize = Marshal.SizeOf(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetPixel(int x, int y)
|
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;
|
int rowSize = Marshal.SizeOf(typeof(T)) * base.Width;
|
||||||
byte[] array = new byte[rowSize * base.Height];
|
byte[] array = new byte[rowSize * base.Height];
|
||||||
|
|
||||||
|
int destinationIndex = 0;
|
||||||
for (int i = 0; i < base.Height; i++)
|
for (int i = 0; i < base.Height; i++)
|
||||||
{
|
{
|
||||||
T[] row = GetRow(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;
|
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)
|
public T[] GetRow(int y)
|
||||||
{
|
{
|
||||||
T[] row = new T[Width];
|
T[] row = new T[Width];
|
||||||
|
@ -67,7 +67,9 @@
|
|||||||
<Reference Include="System.Net" />
|
<Reference Include="System.Net" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AddInSelector.cs" />
|
<Compile Include="AddInSelector.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="AddInSelector.Designer.cs">
|
<Compile Include="AddInSelector.Designer.cs">
|
||||||
<DependentUpon>AddInSelector.cs</DependentUpon>
|
<DependentUpon>AddInSelector.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user