reading used GraphicsProfile out of game assembly

some work on Kinect InputSystem (Dispose, fetching of RGB image)
changed handling of native textures (providing data for Texture2D at the moment)
implemented SetData methods for Texture2D
basic Dispose handling of Texture and Texture2D implemented
RenderSystemDX10: moved FormatSize method to FormatConverter to avoid duplicated code
RenderSystemGL3 is BROKEN in this version. New texture handling needs to be adapted.
This commit is contained in:
Glatzemann 2011-11-11 07:29:49 +00:00
parent 619282f1c6
commit f06890de59
27 changed files with 613 additions and 79 deletions

View File

@ -8,6 +8,7 @@ using System.IO;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SharpDX.DXGI; using SharpDX.DXGI;
using ANX.Framework.NonXNA.RenderSystem;
#endregion // Using Statements #endregion // Using Statements
@ -103,14 +104,18 @@ namespace ANX.Framework.Windows.DX10
public Texture2D CreateTexture(GraphicsDevice graphics, string fileName) public Texture2D CreateTexture(GraphicsDevice graphics, string fileName)
{ {
GraphicsDeviceWindowsDX10 graphicsDX10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10; //TODO: implement
SharpDX.Direct3D10.Texture2D nativeTexture = SharpDX.Direct3D10.Texture2D.FromFile<SharpDX.Direct3D10.Texture2D>(graphicsDX10.NativeDevice, fileName); throw new NotImplementedException();
Texture2D_DX10 texture = new Texture2D_DX10(graphics, nativeTexture.Description.Width, nativeTexture.Description.Height);
texture.NativeTexture = nativeTexture;
return texture; //GraphicsDeviceWindowsDX10 graphicsDX10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
//SharpDX.Direct3D10.Texture2D nativeTexture = SharpDX.Direct3D10.Texture2D.FromFile<SharpDX.Direct3D10.Texture2D>(graphicsDX10.NativeDevice, fileName);
//Texture2D_DX10 texture = new Texture2D_DX10(graphics, nativeTexture.Description.Width, nativeTexture.Description.Height);
//texture.NativeTexture = nativeTexture;
//return texture;
} }
/*
public Texture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount, byte[] colorData) public Texture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount, byte[] colorData)
{ {
if (mipCount > 1) if (mipCount > 1)
@ -141,7 +146,7 @@ namespace ANX.Framework.Windows.DX10
// description of texture formats of DX10: http://msdn.microsoft.com/en-us/library/bb694531(v=VS.85).aspx // description of texture formats of DX10: http://msdn.microsoft.com/en-us/library/bb694531(v=VS.85).aspx
// more helpfull information on DX10 textures: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx // more helpfull information on DX10 textures: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx
int formatSize = FormatSize(surfaceFormat); int formatSize = FormatConverter.FormatSize(surfaceFormat);
if (surfaceFormat == SurfaceFormat.Color) if (surfaceFormat == SurfaceFormat.Color)
{ {
@ -210,6 +215,7 @@ namespace ANX.Framework.Windows.DX10
return texture; return texture;
} }
*/
public INativeBlendState CreateBlendState() public INativeBlendState CreateBlendState()
{ {
@ -231,34 +237,6 @@ namespace ANX.Framework.Windows.DX10
return new SamplerState_DX10(); return new SamplerState_DX10();
} }
private static int FormatSize(SurfaceFormat format)
{
switch (format)
{
case SurfaceFormat.Vector4:
return 16;
//case SurfaceFormat.Vector3:
// return 12;
case SurfaceFormat.Vector2:
return 8;
case SurfaceFormat.Single:
case SurfaceFormat.Color:
//case SurfaceFormat.RGBA1010102:
//case SurfaceFormat.RG32:
return 4;
//case SurfaceFormat.BGR565:
//case SurfaceFormat.BGRA5551:
// return 2;
case SurfaceFormat.Dxt1:
case SurfaceFormat.Dxt3:
case SurfaceFormat.Dxt5:
case SurfaceFormat.Alpha8:
return 1;
default:
throw new ArgumentException("Invalid format");
}
}
public byte[] GetShaderByteCode(PreDefinedShader type) public byte[] GetShaderByteCode(PreDefinedShader type)
{ {
if (type == PreDefinedShader.SpriteBatch) if (type == PreDefinedShader.SpriteBatch)
@ -326,5 +304,10 @@ namespace ANX.Framework.Windows.DX10
return new System.Collections.ObjectModel.ReadOnlyCollection<GraphicsAdapter>(adapterList); return new System.Collections.ObjectModel.ReadOnlyCollection<GraphicsAdapter>(adapterList);
} }
public INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount)
{
return new Texture2D_DX10(graphics, width, height, surfaceFormat, mipCount);
}
} }
} }

View File

@ -6,6 +6,7 @@ using System.Text;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using SharpDX.Direct3D10; using SharpDX.Direct3D10;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using ANX.Framework.NonXNA.RenderSystem;
#endregion // Using Statements #endregion // Using Statements
@ -83,7 +84,7 @@ namespace ANX.Framework.Windows.DX10
public void SetValue(Texture value) public void SetValue(Texture value)
{ {
Texture2D_DX10 tex = value as Texture2D_DX10; Texture2D_DX10 tex = value.NativeTexture as Texture2D_DX10;
GraphicsDeviceWindowsDX10 graphicsDX10 = tex.GraphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10; GraphicsDeviceWindowsDX10 graphicsDX10 = tex.GraphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice; SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice;

View File

@ -58,6 +58,35 @@ namespace ANX.Framework.Windows.DX10
{ {
internal class FormatConverter internal class FormatConverter
{ {
public static int FormatSize(SurfaceFormat format)
{
switch (format)
{
case SurfaceFormat.Vector4:
return 16;
//case SurfaceFormat.Vector3:
// return 12;
case SurfaceFormat.Vector2:
return 8;
case SurfaceFormat.Single:
case SurfaceFormat.Color:
//case SurfaceFormat.RGBA1010102:
//case SurfaceFormat.RG32:
return 4;
//case SurfaceFormat.BGR565:
//case SurfaceFormat.BGRA5551:
// return 2;
case SurfaceFormat.Dxt1:
case SurfaceFormat.Dxt3:
case SurfaceFormat.Dxt5:
case SurfaceFormat.Alpha8:
return 1;
default:
throw new ArgumentException("Invalid format");
}
}
public static SharpDX.DXGI.Format Translate(SurfaceFormat surfaceFormat) public static SharpDX.DXGI.Format Translate(SurfaceFormat surfaceFormat)
{ {
switch (surfaceFormat) switch (surfaceFormat)

View File

@ -107,11 +107,14 @@ namespace ANX.Framework.Windows.DX10
private SharpDX.Direct3D10.Viewport currentViewport; private SharpDX.Direct3D10.Viewport currentViewport;
private uint lastClearColor; private uint lastClearColor;
private SharpDX.Color4 clearColor; private SharpDX.Color4 clearColor;
private bool vSyncEnabled;
#endregion // Private Members #endregion // Private Members
public GraphicsDeviceWindowsDX10(PresentationParameters presentationParameters) public GraphicsDeviceWindowsDX10(PresentationParameters presentationParameters)
{ {
this.vSyncEnabled = true;
// SwapChain description // SwapChain description
var desc = new SwapChainDescription() var desc = new SwapChainDescription()
{ {
@ -202,7 +205,7 @@ namespace ANX.Framework.Windows.DX10
public void Present() public void Present()
{ {
swapChain.Present(0, PresentFlags.None); swapChain.Present(this.vSyncEnabled ? 1 : 0, PresentFlags.None);
} }
internal Device NativeDevice internal Device NativeDevice
@ -463,5 +466,16 @@ namespace ANX.Framework.Windows.DX10
} }
} }
public bool VSync
{
get
{
return this.vSyncEnabled;
}
set
{
this.vSyncEnabled = value;
}
}
} }
} }

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.7.1.0")] [assembly: AssemblyVersion("0.7.3.0")]
[assembly: AssemblyFileVersion("0.7.1.0")] [assembly: AssemblyFileVersion("0.7.3.0")]

View File

@ -5,6 +5,9 @@ using System.Linq;
using System.Text; using System.Text;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using SharpDX.Direct3D10; using SharpDX.Direct3D10;
using ANX.Framework.NonXNA.RenderSystem;
using System.IO;
using System.Runtime.InteropServices;
#endregion // Using Statements #endregion // Using Statements
@ -57,11 +60,50 @@ using SharpDX.Direct3D10;
namespace ANX.Framework.Windows.DX10 namespace ANX.Framework.Windows.DX10
{ {
public class Texture2D_DX10 : ANX.Framework.Graphics.Texture2D public class Texture2D_DX10 : INativeTexture2D
{ {
public Texture2D_DX10(GraphicsDevice graphicsDevice, int width, int height) #region Private Members
: base(graphicsDevice, width, height) private SharpDX.Direct3D10.Texture2D nativeTexture;
private SharpDX.Direct3D10.ShaderResourceView nativeShaderResourceView;
private int formatSize;
private SurfaceFormat surfaceFormat;
private GraphicsDevice graphicsDevice;
#endregion // Private Members
public Texture2D_DX10(GraphicsDevice graphicsDevice, int width, int height, SurfaceFormat surfaceFormat, int mipCount)
{ {
if (mipCount > 1)
{
throw new Exception("creating textures with mip map not yet implemented");
}
this.graphicsDevice = graphicsDevice;
this.surfaceFormat = surfaceFormat;
GraphicsDeviceWindowsDX10 graphicsDX10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice;
SharpDX.Direct3D10.Texture2DDescription description = new SharpDX.Direct3D10.Texture2DDescription()
{
Width = width,
Height = height,
MipLevels = mipCount,
ArraySize = mipCount,
Format = FormatConverter.Translate(surfaceFormat),
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = SharpDX.Direct3D10.ResourceUsage.Dynamic,
BindFlags = SharpDX.Direct3D10.BindFlags.ShaderResource,
CpuAccessFlags = SharpDX.Direct3D10.CpuAccessFlags.Write,
OptionFlags = SharpDX.Direct3D10.ResourceOptionFlags.None,
};
this.nativeTexture = new SharpDX.Direct3D10.Texture2D(graphicsDX10.NativeDevice, description);
this.nativeShaderResourceView = new SharpDX.Direct3D10.ShaderResourceView(graphicsDX10.NativeDevice, this.nativeTexture);
// description of texture formats of DX10: http://msdn.microsoft.com/en-us/library/bb694531(v=VS.85).aspx
// more helpfull information on DX10 textures: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx
this.formatSize = FormatConverter.FormatSize(surfaceFormat);
} }
public override int GetHashCode() public override int GetHashCode()
@ -71,14 +113,199 @@ namespace ANX.Framework.Windows.DX10
internal SharpDX.Direct3D10.Texture2D NativeTexture internal SharpDX.Direct3D10.Texture2D NativeTexture
{ {
get; get
set; {
return this.nativeTexture;
}
set
{
if (this.nativeTexture != value)
{
if (this.nativeTexture != null)
{
this.nativeTexture.Dispose();
}
this.nativeTexture = value;
}
}
} }
internal SharpDX.Direct3D10.ShaderResourceView NativeShaderResourceView internal SharpDX.Direct3D10.ShaderResourceView NativeShaderResourceView
{ {
get; get
set; {
return this.nativeShaderResourceView;
}
set
{
if (this.nativeShaderResourceView != value)
{
if (this.nativeShaderResourceView != null)
{
this.nativeShaderResourceView.Dispose();
}
this.nativeShaderResourceView = value;
}
}
}
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct
{
SetData<T>(graphicsDevice, 0, data, 0, data.Length);
}
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct
{
SetData<T>(graphicsDevice, 0, data, startIndex, elementCount);
}
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
{
//TODO: handle offsetInBytes parameter
//TODO: handle startIndex parameter
//TODO: handle elementCount parameter
if (this.surfaceFormat == SurfaceFormat.Color)
{
int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubresourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None);
int rowPitch = rectangle.Pitch;
unsafe
{
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
byte* colorData = (byte*)handle.AddrOfPinnedObject();
byte* pTexels = (byte*)rectangle.DataPointer;
int srcIndex = 0;
for (int row = 0; row < Height; row++)
{
int rowStart = row * rowPitch;
for (int col = 0; col < Width; col++)
{
int colStart = col * formatSize;
pTexels[rowStart + colStart + 0] = colorData[srcIndex++];
pTexels[rowStart + colStart + 1] = colorData[srcIndex++];
pTexels[rowStart + colStart + 2] = colorData[srcIndex++];
pTexels[rowStart + colStart + 3] = colorData[srcIndex++];
}
}
handle.Free();
}
this.nativeTexture.Unmap(subresource);
}
else if (surfaceFormat == SurfaceFormat.Dxt5 || surfaceFormat == SurfaceFormat.Dxt3 || surfaceFormat == SurfaceFormat.Dxt1)
{
unsafe
{
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
byte* colorData = (byte*)handle.AddrOfPinnedObject();
int w = (Width + 3) >> 2;
int h = (Height + 3) >> 2;
formatSize = (surfaceFormat == SurfaceFormat.Dxt1) ? 8 : 16;
int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubresourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None);
SharpDX.DataStream ds = new SharpDX.DataStream(rectangle.DataPointer, Width * Height * 4 * 2, true, true);
int pitch = rectangle.Pitch;
int col = 0;
int index = 0; // startIndex
int count = data.Length; // elementCount
int actWidth = w * formatSize;
for (int i = 0; i < h; i++)
{
ds.Position = (i * pitch) + (col * formatSize);
if (count <= 0)
{
break;
}
else if (count < actWidth)
{
for (int idx = index; idx < index + count; idx++)
{
ds.WriteByte(colorData[idx]);
}
//ds.WriteRange<byte>(colorDataArray, index, count);
break;
}
for (int idx = index; idx < index + actWidth; idx++)
{
ds.WriteByte(colorData[idx]);
}
//ds.WriteRange<byte>(colorDataArray, index, actWidth);
index += actWidth;
count -= actWidth;
}
handle.Free();
this.nativeTexture.Unmap(subresource);
}
}
else
{
throw new Exception(string.Format("creating textures of format {0} not yet implemented...", surfaceFormat.ToString()));
}
}
public int Width
{
get
{
if (this.nativeTexture != null)
{
return this.nativeTexture.Description.Width;
}
return 0;
}
}
public int Height
{
get
{
if (this.nativeTexture != null)
{
return this.nativeTexture.Description.Height;
}
return 0;
}
}
public GraphicsDevice GraphicsDevice
{
get
{
return this.graphicsDevice;
}
}
public void Dispose()
{
if (this.nativeShaderResourceView != null)
{
this.nativeShaderResourceView.Dispose();
this.nativeShaderResourceView = null;
}
if (this.nativeTexture != null)
{
this.nativeTexture.Dispose();
this.nativeTexture = null;
}
} }
} }
} }

View File

@ -6,6 +6,7 @@ using System.Collections.ObjectModel;
using OpenTK; using OpenTK;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using ANX.Framework.NonXNA.RenderSystem;
#region License #region License
@ -120,12 +121,14 @@ namespace ANX.Framework.Windows.GL3
/// <param name="mipCount">The number of mipmaps in the texture.</param> /// <param name="mipCount">The number of mipmaps in the texture.</param>
/// <param name="mipMaps">The mipmaps as a single byte array.</param> /// <param name="mipMaps">The mipmaps as a single byte array.</param>
/// <returns></returns> /// <returns></returns>
public Texture2D CreateTexture(GraphicsDevice graphics, public INativeTexture2D CreateTexture(GraphicsDevice graphics,
SurfaceFormat surfaceFormat, int width, int height, int mipCount, SurfaceFormat surfaceFormat, int width, int height, int mipCount) //,
byte[] mipMaps) //byte[] mipMaps)
{ {
return new Texture2DGL3(graphics, surfaceFormat, width, throw new NotImplementedException();
height, mipCount, mipMaps);
//return new Texture2DGL3(graphics, surfaceFormat, width,
// height, mipCount, mipMaps);
} }
#endregion #endregion

View File

@ -304,5 +304,18 @@ namespace ANX.Framework.Windows.GL3
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
public bool VSync
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
}
} }

View File

@ -310,6 +310,8 @@
<Compile Include="NonXNA\RenderSystem\INativeRasterizerState.cs" /> <Compile Include="NonXNA\RenderSystem\INativeRasterizerState.cs" />
<Compile Include="NonXNA\RenderSystem\INativeDepthStencilState.cs" /> <Compile Include="NonXNA\RenderSystem\INativeDepthStencilState.cs" />
<Compile Include="NonXNA\RenderSystem\INativeSamplerState.cs" /> <Compile Include="NonXNA\RenderSystem\INativeSamplerState.cs" />
<Compile Include="NonXNA\RenderSystem\INativeTexture.cs" />
<Compile Include="NonXNA\RenderSystem\INativeTexture2D.cs" />
<Compile Include="NonXNA\RenderSystem\PreDefinedShader.cs" /> <Compile Include="NonXNA\RenderSystem\PreDefinedShader.cs" />
<Compile Include="NonXNA\RenderSystem\INativeBlendState.cs" /> <Compile Include="NonXNA\RenderSystem\INativeBlendState.cs" />
<Compile Include="NonXNA\RenderSystem\INativeBuffer.cs" /> <Compile Include="NonXNA\RenderSystem\INativeBuffer.cs" />

View File

@ -82,7 +82,10 @@ namespace ANX.Framework.Content
colorData.AddRange(input.ReadBytes(size)); colorData.AddRange(input.ReadBytes(size));
} }
return rfc.CreateTexture(graphics, sFormat, width, height, mipCount, colorData.ToArray()); Texture2D texture = new Texture2D(graphics, width, height, mipCount > 0, sFormat);
texture.SetData<byte>(colorData.ToArray());
return texture;
} }
} }
} }

View File

@ -326,7 +326,7 @@ namespace ANX.Framework.Graphics
public void Dispose() public void Dispose()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
protected virtual void Dispose(Boolean disposeManaged) protected virtual void Dispose(Boolean disposeManaged)

View File

@ -1,5 +1,6 @@
#region Using Statements #region Using Statements
using System; using System;
using ANX.Framework.NonXNA.RenderSystem;
#endregion // Using Statements #endregion // Using Statements
@ -54,6 +55,10 @@ namespace ANX.Framework.Graphics
{ {
public abstract class Texture : GraphicsResource public abstract class Texture : GraphicsResource
{ {
protected internal int levelCount;
protected internal SurfaceFormat format;
protected internal INativeTexture nativeTexture;
public Texture(GraphicsDevice graphicsDevice) public Texture(GraphicsDevice graphicsDevice)
: base(graphicsDevice) : base(graphicsDevice)
{ {
@ -64,7 +69,7 @@ namespace ANX.Framework.Graphics
{ {
get get
{ {
throw new NotImplementedException(); return this.levelCount;
} }
} }
@ -72,7 +77,29 @@ namespace ANX.Framework.Graphics
{ {
get get
{ {
throw new NotImplementedException(); return this.format;
}
}
internal INativeTexture NativeTexture
{
get
{
return this.nativeTexture;
}
}
public override void Dispose()
{
Dispose(true);
}
protected override void Dispose(bool disposeManaged)
{
if (disposeManaged && nativeTexture != null)
{
nativeTexture.Dispose();
nativeTexture = null;
} }
} }
} }

View File

@ -1,6 +1,8 @@
#region Using Statements #region Using Statements
using System; using System;
using System.IO; using System.IO;
using ANX.Framework.NonXNA.RenderSystem;
using ANX.Framework.NonXNA;
#endregion // Using Statements #endregion // Using Statements
@ -55,14 +57,22 @@ namespace ANX.Framework.Graphics
{ {
public class Texture2D : Texture, IGraphicsResource public class Texture2D : Texture, IGraphicsResource
{ {
#region Private Members
private int width; private int width;
private int height; private int height;
#endregion // Private Members
public Texture2D(GraphicsDevice graphicsDevice, int width, int height) public Texture2D(GraphicsDevice graphicsDevice, int width, int height)
: base(graphicsDevice) : base(graphicsDevice)
{ {
this.width = width; this.width = width;
this.height = height; this.height = height;
base.levelCount = 1;
base.format = SurfaceFormat.Color;
CreateNativeTextureSurface();
} }
public Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat format) public Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat format)
@ -71,7 +81,10 @@ namespace ANX.Framework.Graphics
this.width = width; this.width = width;
this.height = height; this.height = height;
throw new NotImplementedException(); base.levelCount = 1; //TODO: mipmap paramter?!?!?
base.format = format;
CreateNativeTextureSurface();
} }
public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream) public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream)
@ -116,22 +129,22 @@ namespace ANX.Framework.Graphics
public void SetData<T>(T[] data) where T : struct public void SetData<T>(T[] data) where T : struct
{ {
throw new NotImplementedException(); this.nativeTexture.SetData<T>(GraphicsDevice, data);
} }
public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct
{ {
throw new NotImplementedException(); this.nativeTexture.SetData<T>(GraphicsDevice, data, startIndex, elementCount);
} }
public override void Dispose() public override void Dispose()
{ {
throw new NotImplementedException(); base.Dispose(true);
} }
protected override void Dispose(Boolean disposeManaged) protected override void Dispose(Boolean disposeManaged)
{ {
throw new NotImplementedException(); base.Dispose(disposeManaged);
} }
public Rectangle Bounds public Rectangle Bounds
@ -157,5 +170,10 @@ namespace ANX.Framework.Graphics
return this.height; return this.height;
} }
} }
private void CreateNativeTextureSurface()
{
base.nativeTexture = AddInSystemFactory.Instance.GetCurrentCreator<IRenderSystemCreator>().CreateTexture(GraphicsDevice, format, Width, Height, levelCount);
}
} }
} }

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using System.IO;
#endregion // Using Statements #endregion // Using Statements
@ -62,6 +63,9 @@ namespace ANX.Framework
private Game game; private Game game;
private GraphicsDevice graphicsDevice; private GraphicsDevice graphicsDevice;
private DepthFormat depthStencilFormat = DepthFormat.Depth24; private DepthFormat depthStencilFormat = DepthFormat.Depth24;
private GraphicsProfile graphicsProfile;
#endregion // Private Members
public static readonly int DefaultBackBufferWidth = 800; public static readonly int DefaultBackBufferWidth = 800;
public static readonly int DefaultBackBufferHeight = 600; //TODO: this is 480 in the original XNA public static readonly int DefaultBackBufferHeight = 600; //TODO: this is 480 in the original XNA
@ -73,8 +77,6 @@ namespace ANX.Framework
public event EventHandler<EventArgs> DeviceResetting; public event EventHandler<EventArgs> DeviceResetting;
public event EventHandler<PreparingDeviceSettingsEventArgs> PreparingDeviceSettings; public event EventHandler<PreparingDeviceSettingsEventArgs> PreparingDeviceSettings;
#endregion // Private Members
public GraphicsDeviceManager(Game game) public GraphicsDeviceManager(Game game)
{ {
if (game == null) if (game == null)
@ -100,7 +102,7 @@ namespace ANX.Framework
game.Window.ScreenDeviceNameChanged += new EventHandler<EventArgs>(Window_ScreenDeviceNameChanged); game.Window.ScreenDeviceNameChanged += new EventHandler<EventArgs>(Window_ScreenDeviceNameChanged);
game.Window.OrientationChanged += new EventHandler<EventArgs>(Window_OrientationChanged); game.Window.OrientationChanged += new EventHandler<EventArgs>(Window_OrientationChanged);
//TODO: read graphics profile type from manifest resource stream this.graphicsProfile = FetchGraphicsProfile();
} }
void Window_OrientationChanged(object sender, EventArgs e) void Window_OrientationChanged(object sender, EventArgs e)
@ -273,8 +275,14 @@ namespace ANX.Framework
public GraphicsProfile GraphicsProfile public GraphicsProfile GraphicsProfile
{ {
get { throw new NotImplementedException(); } get
set { throw new NotImplementedException(); } {
return this.graphicsProfile;
}
set
{
throw new NotImplementedException();
}
} }
public DepthFormat PreferredDepthStencilFormat public DepthFormat PreferredDepthStencilFormat
@ -312,8 +320,14 @@ namespace ANX.Framework
public bool SynchronizeWithVerticalRetrace public bool SynchronizeWithVerticalRetrace
{ {
get { throw new NotImplementedException(); } get
set { throw new NotImplementedException(); } {
return graphicsDevice.NativeDevice.VSync;
}
set
{
graphicsDevice.NativeDevice.VSync = value;
}
} }
public bool PreferMultiSampling public bool PreferMultiSampling
@ -327,5 +341,23 @@ namespace ANX.Framework
get { throw new NotImplementedException(); } get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); } set { throw new NotImplementedException(); }
} }
private GraphicsProfile FetchGraphicsProfile()
{
Stream manifestResourceStream = this.game.GetType().Assembly.GetManifestResourceStream("Microsoft.Xna.Framework.RuntimeProfile");
if (manifestResourceStream != null)
{
using (StreamReader reader = new StreamReader(manifestResourceStream))
{
if (reader.ReadToEnd().Contains("HiDef"))
{
return GraphicsProfile.HiDef;
}
}
}
return GraphicsProfile.Reach;
}
} }
} }

View File

@ -65,7 +65,7 @@ namespace ANX.Framework.Input.MotionSensing
motionSensingDevice = AddInSystemFactory.Instance.GetCurrentCreator<IInputSystemCreator>().MotionSensingDevice; motionSensingDevice = AddInSystemFactory.Instance.GetCurrentCreator<IInputSystemCreator>().MotionSensingDevice;
} }
public GraphicsDevice GraphicsDevice public static GraphicsDevice GraphicsDevice
{ {
get get
{ {

View File

@ -83,7 +83,7 @@ namespace ANX.Framework.Input.MotionSensing
public Texture2D RGB { get { return this.pRGB; } } public Texture2D RGB { get { return this.pRGB; } }
public Texture2D Derpth { get { return this.pDepth; } } public Texture2D Depth { get { return this.pDepth; } }
public Vector3 HipCenter { get { return this.pHipCenter; } } public Vector3 HipCenter { get { return this.pHipCenter; } }
public Vector3 Spine { get { return this.pSpine; } } public Vector3 Spine { get { return this.pSpine; } }

View File

@ -56,7 +56,7 @@ using ANX.Framework.Graphics;
#if XNAEXT #if XNAEXT
namespace ANX.Framework.NonXNA namespace ANX.Framework.NonXNA
{ {
public interface IMotionSensingDevice public interface IMotionSensingDevice : IDisposable
{ {
GraphicsDevice GraphicsDevice { get; set; } GraphicsDevice GraphicsDevice { get; set; }

View File

@ -83,5 +83,7 @@ namespace ANX.Framework.NonXNA
void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct; void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct;
void ResizeBuffers(PresentationParameters presentationParameters); void ResizeBuffers(PresentationParameters presentationParameters);
bool VSync { get; set; }
} }
} }

View File

@ -0,0 +1,60 @@
#region Using Statements
using System;
using ANX.Framework.Graphics;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.Framework.NonXNA.RenderSystem
{
public interface INativeTexture : INativeBuffer
{
}
}

View File

@ -0,0 +1,60 @@
#region Using Statements
using System;
using ANX.Framework.Graphics;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.Framework.NonXNA.RenderSystem
{
public interface INativeTexture2D : INativeTexture
{
}
}

View File

@ -4,6 +4,7 @@ using ANX.Framework.Graphics;
using System.IO; using System.IO;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using ANX.Framework.NonXNA.RenderSystem;
#endregion // Using Statements #endregion // Using Statements
@ -62,7 +63,7 @@ namespace ANX.Framework
INativeGraphicsDevice CreateGraphicsDevice(PresentationParameters presentationParameters); INativeGraphicsDevice CreateGraphicsDevice(PresentationParameters presentationParameters);
Texture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount, byte[] mipMaps); INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount);
INativeBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage); INativeBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage);

View File

@ -32,8 +32,8 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.1.*")] [assembly: AssemblyVersion("0.4.12.*")]
[assembly: AssemblyFileVersion("0.4.1.0")] [assembly: AssemblyFileVersion("0.4.12.0")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.DX10")] [assembly:InternalsVisibleTo("ANX.Framework.Windows.DX10")]
[assembly:InternalsVisibleTo("ANX.Framework.Windows.DX11.1")] [assembly:InternalsVisibleTo("ANX.Framework.Windows.DX11.1")]

View File

@ -78,6 +78,8 @@ namespace ANX.InputSystem.Windows.Kinect
pNui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor); pNui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor);
pNui.SkeletonEngine.TransformSmooth = true; pNui.SkeletonEngine.TransformSmooth = true;
this.cache = new Vector3[21]; this.cache = new Vector3[21];
//init for the first time //init for the first time
for (int i = 0; i < 21; ++i) for (int i = 0; i < 21; ++i)
@ -96,9 +98,28 @@ namespace ANX.InputSystem.Windows.Kinect
pNui.SkeletonEngine.SmoothParameters = parameters; pNui.SkeletonEngine.SmoothParameters = parameters;
try
{
pNui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
pNui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);
}
catch (InvalidOperationException)
{
// Display error message; omitted for space return;
}
//lastTime = DateTime.Now;
pNui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(pNui_SkeletonFrameReady); pNui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(pNui_SkeletonFrameReady);
pNui.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(pNui_DepthFrameReady); pNui.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(pNui_DepthFrameReady);
pNui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(pNui_VideoFrameReady); pNui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(pNui_VideoFrameReady);
// move down all the way
pNui.NuiCamera.ElevationAngle = -15;
System.Threading.Thread.Sleep(1500);
// move up all the way
pNui.NuiCamera.ElevationAngle = 20;
} }
void pNui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e) void pNui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
@ -125,7 +146,7 @@ namespace ANX.InputSystem.Windows.Kinect
} }
//TODO: this works only if the image is in RGBA32 Format. Other formats does need a conversion first. //TODO: this works only if the image is in RGBA32 Format. Other formats does need a conversion first.
this.rgb.SetData<byte>(e.ImageFrame.Image.Bits); //TODO: special surface format: this.depth.SetData<byte>(e.ImageFrame.Image.Bits);
} }
} }
@ -178,5 +199,14 @@ namespace ANX.InputSystem.Windows.Kinect
{ {
get { return MotionSensingDeviceType.Kinect; } get { return MotionSensingDeviceType.Kinect; }
} }
public void Dispose()
{
if (pNui != null)
{
pNui.Uninitialize();
pNui = null;
}
}
} }
} }

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.0.0")] [assembly: AssemblyVersion("0.5.2.0")]
[assembly: AssemblyFileVersion("0.5.0.0")] [assembly: AssemblyFileVersion("0.5.2.0")]

View File

@ -223,5 +223,11 @@ namespace ANX.RenderSystem.Windows.DX11_1
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Framework.NonXNA.RenderSystem.INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -636,5 +636,18 @@ namespace ANX.RenderSystem.Windows.DX11_1
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public bool VSync
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
} }
} }

View File

@ -5,6 +5,7 @@ using ANX.Framework;
using ANX.Framework.Content; using ANX.Framework.Content;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using ANX.Framework.Input; using ANX.Framework.Input;
using ANX.Framework.Input.MotionSensing;
namespace Kinect namespace Kinect
{ {
@ -13,6 +14,8 @@ namespace Kinect
GraphicsDeviceManager graphics; GraphicsDeviceManager graphics;
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
MotionSensingDeviceState kinectState;
public Game1() public Game1()
: base("DirectX10", "Kinect") : base("DirectX10", "Kinect")
{ {
@ -22,7 +25,7 @@ namespace Kinect
protected override void Initialize() protected override void Initialize()
{ {
// TODO: Fügen Sie Ihre Initialisierungslogik hier hinzu MotionSensingDevice.GraphicsDevice = GraphicsDevice;
base.Initialize(); base.Initialize();
} }
@ -40,7 +43,7 @@ namespace Kinect
//if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
// this.Exit(); // this.Exit();
// TODO: Fügen Sie Ihre Aktualisierungslogik hier hinzu kinectState = MotionSensingDevice.GetState();
base.Update(gameTime); base.Update(gameTime);
} }
@ -49,7 +52,14 @@ namespace Kinect
{ {
GraphicsDevice.Clear(Color.Black); GraphicsDevice.Clear(Color.Black);
// TODO: Fügen Sie Ihren Zeichnungscode hier hinzu if (kinectState.Depth != null)
{
spriteBatch.Begin();
spriteBatch.Draw(kinectState.RGB, Vector2.Zero, Color.White);
spriteBatch.End();
}
base.Draw(gameTime); base.Draw(gameTime);
} }