From f06890de5944a2128932d3d272237c96555640eb Mon Sep 17 00:00:00 2001 From: Glatzemann Date: Fri, 11 Nov 2011 07:29:49 +0000 Subject: [PATCH] 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. --- ANX.Framework.Windows.DX10/Creator.cs | 51 ++-- .../EffectParameter_DX10.cs | 3 +- ANX.Framework.Windows.DX10/FormatConverter.cs | 29 +++ .../GraphicsDeviceWindowsDX10.cs | 16 +- .../Properties/AssemblyInfo.cs | 4 +- ANX.Framework.Windows.DX10/Texture2D_DX10.cs | 241 +++++++++++++++++- ANX.Framework.Windows.GL3/Creator.cs | 13 +- .../GraphicsDeviceWindowsGL3.cs | 15 +- ANX.Framework/ANX.Framework.csproj | 2 + .../GraphicTypeReaders/Texture2DReader.cs | 5 +- ANX.Framework/Graphics/GraphicsDevice.cs | 2 +- ANX.Framework/Graphics/Texture.cs | 31 ++- ANX.Framework/Graphics/Texture2D.cs | 28 +- ANX.Framework/GraphicsDeviceManager.cs | 46 +++- .../MotionSensing/MotionSensingDevice.cs | 2 +- .../MotionSensing/MotionSensingDeviceState.cs | 2 +- .../InputSystem/IMotionSensingDevice.cs | 2 +- .../RenderSystem/INativeGraphicsDevice.cs | 2 + .../NonXNA/RenderSystem/INativeTexture.cs | 60 +++++ .../NonXNA/RenderSystem/INativeTexture2D.cs | 60 +++++ .../RenderSystem/IRenderSystemCreator.cs | 3 +- ANX.Framework/Properties/AssemblyInfo.cs | 4 +- ANX.InputSystem.Windows.Kinect/Kinect.cs | 32 ++- .../Properties/AssemblyInfo.cs | 4 +- ANX.RenderSystem.Windows.DX11.1/Creator.cs | 6 + .../GraphicsDeviceWindowsDX11_1.cs | 13 + Samples/Kinect/Game1.cs | 16 +- 27 files changed, 613 insertions(+), 79 deletions(-) create mode 100644 ANX.Framework/NonXNA/RenderSystem/INativeTexture.cs create mode 100644 ANX.Framework/NonXNA/RenderSystem/INativeTexture2D.cs diff --git a/ANX.Framework.Windows.DX10/Creator.cs b/ANX.Framework.Windows.DX10/Creator.cs index 25641968..b045133d 100644 --- a/ANX.Framework.Windows.DX10/Creator.cs +++ b/ANX.Framework.Windows.DX10/Creator.cs @@ -8,6 +8,7 @@ using System.IO; using ANX.Framework.NonXNA; using System.Runtime.InteropServices; using SharpDX.DXGI; +using ANX.Framework.NonXNA.RenderSystem; #endregion // Using Statements @@ -103,14 +104,18 @@ namespace ANX.Framework.Windows.DX10 public Texture2D CreateTexture(GraphicsDevice graphics, string fileName) { - GraphicsDeviceWindowsDX10 graphicsDX10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10; - SharpDX.Direct3D10.Texture2D nativeTexture = SharpDX.Direct3D10.Texture2D.FromFile(graphicsDX10.NativeDevice, fileName); - Texture2D_DX10 texture = new Texture2D_DX10(graphics, nativeTexture.Description.Width, nativeTexture.Description.Height); - texture.NativeTexture = nativeTexture; + //TODO: implement + throw new NotImplementedException(); - return texture; + //GraphicsDeviceWindowsDX10 graphicsDX10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10; + //SharpDX.Direct3D10.Texture2D nativeTexture = SharpDX.Direct3D10.Texture2D.FromFile(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) { 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 // 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) { @@ -210,6 +215,7 @@ namespace ANX.Framework.Windows.DX10 return texture; } +*/ public INativeBlendState CreateBlendState() { @@ -231,34 +237,6 @@ namespace ANX.Framework.Windows.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) { if (type == PreDefinedShader.SpriteBatch) @@ -326,5 +304,10 @@ namespace ANX.Framework.Windows.DX10 return new System.Collections.ObjectModel.ReadOnlyCollection(adapterList); } + + public INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount) + { + return new Texture2D_DX10(graphics, width, height, surfaceFormat, mipCount); + } } } diff --git a/ANX.Framework.Windows.DX10/EffectParameter_DX10.cs b/ANX.Framework.Windows.DX10/EffectParameter_DX10.cs index 0d48cae7..1fa6b98b 100644 --- a/ANX.Framework.Windows.DX10/EffectParameter_DX10.cs +++ b/ANX.Framework.Windows.DX10/EffectParameter_DX10.cs @@ -6,6 +6,7 @@ using System.Text; using ANX.Framework.NonXNA; using SharpDX.Direct3D10; using ANX.Framework.Graphics; +using ANX.Framework.NonXNA.RenderSystem; #endregion // Using Statements @@ -83,7 +84,7 @@ namespace ANX.Framework.Windows.DX10 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; SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice; diff --git a/ANX.Framework.Windows.DX10/FormatConverter.cs b/ANX.Framework.Windows.DX10/FormatConverter.cs index 84b936d8..00747845 100644 --- a/ANX.Framework.Windows.DX10/FormatConverter.cs +++ b/ANX.Framework.Windows.DX10/FormatConverter.cs @@ -58,6 +58,35 @@ namespace ANX.Framework.Windows.DX10 { 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) { switch (surfaceFormat) diff --git a/ANX.Framework.Windows.DX10/GraphicsDeviceWindowsDX10.cs b/ANX.Framework.Windows.DX10/GraphicsDeviceWindowsDX10.cs index 181e09f1..289d434e 100644 --- a/ANX.Framework.Windows.DX10/GraphicsDeviceWindowsDX10.cs +++ b/ANX.Framework.Windows.DX10/GraphicsDeviceWindowsDX10.cs @@ -107,11 +107,14 @@ namespace ANX.Framework.Windows.DX10 private SharpDX.Direct3D10.Viewport currentViewport; private uint lastClearColor; private SharpDX.Color4 clearColor; + private bool vSyncEnabled; #endregion // Private Members public GraphicsDeviceWindowsDX10(PresentationParameters presentationParameters) { + this.vSyncEnabled = true; + // SwapChain description var desc = new SwapChainDescription() { @@ -202,7 +205,7 @@ namespace ANX.Framework.Windows.DX10 public void Present() { - swapChain.Present(0, PresentFlags.None); + swapChain.Present(this.vSyncEnabled ? 1 : 0, PresentFlags.None); } internal Device NativeDevice @@ -463,5 +466,16 @@ namespace ANX.Framework.Windows.DX10 } } + public bool VSync + { + get + { + return this.vSyncEnabled; + } + set + { + this.vSyncEnabled = value; + } + } } } diff --git a/ANX.Framework.Windows.DX10/Properties/AssemblyInfo.cs b/ANX.Framework.Windows.DX10/Properties/AssemblyInfo.cs index e62d79c4..0659f4ff 100644 --- a/ANX.Framework.Windows.DX10/Properties/AssemblyInfo.cs +++ b/ANX.Framework.Windows.DX10/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.7.1.0")] -[assembly: AssemblyFileVersion("0.7.1.0")] +[assembly: AssemblyVersion("0.7.3.0")] +[assembly: AssemblyFileVersion("0.7.3.0")] diff --git a/ANX.Framework.Windows.DX10/Texture2D_DX10.cs b/ANX.Framework.Windows.DX10/Texture2D_DX10.cs index ed8b4dc4..2d2efa33 100644 --- a/ANX.Framework.Windows.DX10/Texture2D_DX10.cs +++ b/ANX.Framework.Windows.DX10/Texture2D_DX10.cs @@ -5,6 +5,9 @@ using System.Linq; using System.Text; using ANX.Framework.Graphics; using SharpDX.Direct3D10; +using ANX.Framework.NonXNA.RenderSystem; +using System.IO; +using System.Runtime.InteropServices; #endregion // Using Statements @@ -57,11 +60,50 @@ using SharpDX.Direct3D10; 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) - : base(graphicsDevice, width, height) + #region Private Members + 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() @@ -71,14 +113,199 @@ namespace ANX.Framework.Windows.DX10 internal SharpDX.Direct3D10.Texture2D NativeTexture { - get; - set; + get + { + return this.nativeTexture; + } + set + { + if (this.nativeTexture != value) + { + if (this.nativeTexture != null) + { + this.nativeTexture.Dispose(); + } + + this.nativeTexture = value; + } + } } internal SharpDX.Direct3D10.ShaderResourceView NativeShaderResourceView { - get; - set; + get + { + return this.nativeShaderResourceView; + } + set + { + if (this.nativeShaderResourceView != value) + { + if (this.nativeShaderResourceView != null) + { + this.nativeShaderResourceView.Dispose(); + } + + this.nativeShaderResourceView = value; + } + } + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data) where T : struct + { + SetData(graphicsDevice, 0, data, 0, data.Length); + } + + public void SetData(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct + { + SetData(graphicsDevice, 0, data, startIndex, elementCount); + } + + public void SetData(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(colorDataArray, index, count); + + break; + } + + for (int idx = index; idx < index + actWidth; idx++) + { + ds.WriteByte(colorData[idx]); + } + //ds.WriteRange(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; + } } } } diff --git a/ANX.Framework.Windows.GL3/Creator.cs b/ANX.Framework.Windows.GL3/Creator.cs index 7d8bfb16..ee7e86ba 100644 --- a/ANX.Framework.Windows.GL3/Creator.cs +++ b/ANX.Framework.Windows.GL3/Creator.cs @@ -6,6 +6,7 @@ using System.Collections.ObjectModel; using OpenTK; using System.Collections.Generic; using System.Windows.Forms; +using ANX.Framework.NonXNA.RenderSystem; #region License @@ -120,12 +121,14 @@ namespace ANX.Framework.Windows.GL3 /// The number of mipmaps in the texture. /// The mipmaps as a single byte array. /// - public Texture2D CreateTexture(GraphicsDevice graphics, - SurfaceFormat surfaceFormat, int width, int height, int mipCount, - byte[] mipMaps) + public INativeTexture2D CreateTexture(GraphicsDevice graphics, + SurfaceFormat surfaceFormat, int width, int height, int mipCount) //, + //byte[] mipMaps) { - return new Texture2DGL3(graphics, surfaceFormat, width, - height, mipCount, mipMaps); + throw new NotImplementedException(); + + //return new Texture2DGL3(graphics, surfaceFormat, width, + // height, mipCount, mipMaps); } #endregion diff --git a/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs b/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs index 6f11f026..dbc529e6 100644 --- a/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs +++ b/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs @@ -304,5 +304,18 @@ namespace ANX.Framework.Windows.GL3 { throw new NotImplementedException(); } - } + + + public bool VSync + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + } } diff --git a/ANX.Framework/ANX.Framework.csproj b/ANX.Framework/ANX.Framework.csproj index d49c7254..95e8b424 100644 --- a/ANX.Framework/ANX.Framework.csproj +++ b/ANX.Framework/ANX.Framework.csproj @@ -310,6 +310,8 @@ + + diff --git a/ANX.Framework/Content/GraphicTypeReaders/Texture2DReader.cs b/ANX.Framework/Content/GraphicTypeReaders/Texture2DReader.cs index 7c633a31..0b58d5c9 100644 --- a/ANX.Framework/Content/GraphicTypeReaders/Texture2DReader.cs +++ b/ANX.Framework/Content/GraphicTypeReaders/Texture2DReader.cs @@ -82,7 +82,10 @@ namespace ANX.Framework.Content 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(colorData.ToArray()); + + return texture; } } } diff --git a/ANX.Framework/Graphics/GraphicsDevice.cs b/ANX.Framework/Graphics/GraphicsDevice.cs index d382b5d8..6894186b 100644 --- a/ANX.Framework/Graphics/GraphicsDevice.cs +++ b/ANX.Framework/Graphics/GraphicsDevice.cs @@ -326,7 +326,7 @@ namespace ANX.Framework.Graphics public void Dispose() { - throw new NotImplementedException(); + throw new NotImplementedException(); } protected virtual void Dispose(Boolean disposeManaged) diff --git a/ANX.Framework/Graphics/Texture.cs b/ANX.Framework/Graphics/Texture.cs index cb4c6e54..8dd9045e 100644 --- a/ANX.Framework/Graphics/Texture.cs +++ b/ANX.Framework/Graphics/Texture.cs @@ -1,5 +1,6 @@ #region Using Statements using System; +using ANX.Framework.NonXNA.RenderSystem; #endregion // Using Statements @@ -54,6 +55,10 @@ namespace ANX.Framework.Graphics { public abstract class Texture : GraphicsResource { + protected internal int levelCount; + protected internal SurfaceFormat format; + protected internal INativeTexture nativeTexture; + public Texture(GraphicsDevice graphicsDevice) : base(graphicsDevice) { @@ -64,7 +69,7 @@ namespace ANX.Framework.Graphics { get { - throw new NotImplementedException(); + return this.levelCount; } } @@ -72,7 +77,29 @@ namespace ANX.Framework.Graphics { 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; } } } diff --git a/ANX.Framework/Graphics/Texture2D.cs b/ANX.Framework/Graphics/Texture2D.cs index 0728b0ad..abdc0d74 100644 --- a/ANX.Framework/Graphics/Texture2D.cs +++ b/ANX.Framework/Graphics/Texture2D.cs @@ -1,6 +1,8 @@ #region Using Statements using System; using System.IO; +using ANX.Framework.NonXNA.RenderSystem; +using ANX.Framework.NonXNA; #endregion // Using Statements @@ -55,14 +57,22 @@ namespace ANX.Framework.Graphics { public class Texture2D : Texture, IGraphicsResource { + #region Private Members private int width; private int height; + #endregion // Private Members + public Texture2D(GraphicsDevice graphicsDevice, int width, int height) : base(graphicsDevice) { this.width = width; this.height = height; + + base.levelCount = 1; + base.format = SurfaceFormat.Color; + + CreateNativeTextureSurface(); } public Texture2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat format) @@ -71,7 +81,10 @@ namespace ANX.Framework.Graphics this.width = width; this.height = height; - throw new NotImplementedException(); + base.levelCount = 1; //TODO: mipmap paramter?!?!? + base.format = format; + + CreateNativeTextureSurface(); } public static Texture2D FromStream(GraphicsDevice graphicsDevice, Stream stream) @@ -116,22 +129,22 @@ namespace ANX.Framework.Graphics public void SetData(T[] data) where T : struct { - throw new NotImplementedException(); + this.nativeTexture.SetData(GraphicsDevice, data); } public void SetData(T[] data, int startIndex, int elementCount) where T : struct { - throw new NotImplementedException(); + this.nativeTexture.SetData(GraphicsDevice, data, startIndex, elementCount); } public override void Dispose() { - throw new NotImplementedException(); + base.Dispose(true); } protected override void Dispose(Boolean disposeManaged) { - throw new NotImplementedException(); + base.Dispose(disposeManaged); } public Rectangle Bounds @@ -157,5 +170,10 @@ namespace ANX.Framework.Graphics return this.height; } } + + private void CreateNativeTextureSurface() + { + base.nativeTexture = AddInSystemFactory.Instance.GetCurrentCreator().CreateTexture(GraphicsDevice, format, Width, Height, levelCount); + } } } diff --git a/ANX.Framework/GraphicsDeviceManager.cs b/ANX.Framework/GraphicsDeviceManager.cs index 37b5d715..e9f8feee 100644 --- a/ANX.Framework/GraphicsDeviceManager.cs +++ b/ANX.Framework/GraphicsDeviceManager.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using ANX.Framework.Graphics; +using System.IO; #endregion // Using Statements @@ -62,6 +63,9 @@ namespace ANX.Framework private Game game; private GraphicsDevice graphicsDevice; private DepthFormat depthStencilFormat = DepthFormat.Depth24; + private GraphicsProfile graphicsProfile; + + #endregion // Private Members public static readonly int DefaultBackBufferWidth = 800; public static readonly int DefaultBackBufferHeight = 600; //TODO: this is 480 in the original XNA @@ -73,8 +77,6 @@ namespace ANX.Framework public event EventHandler DeviceResetting; public event EventHandler PreparingDeviceSettings; - #endregion // Private Members - public GraphicsDeviceManager(Game game) { if (game == null) @@ -100,7 +102,7 @@ namespace ANX.Framework game.Window.ScreenDeviceNameChanged += new EventHandler(Window_ScreenDeviceNameChanged); game.Window.OrientationChanged += new EventHandler(Window_OrientationChanged); - //TODO: read graphics profile type from manifest resource stream + this.graphicsProfile = FetchGraphicsProfile(); } void Window_OrientationChanged(object sender, EventArgs e) @@ -273,8 +275,14 @@ namespace ANX.Framework public GraphicsProfile GraphicsProfile { - get { throw new NotImplementedException(); } - set { throw new NotImplementedException(); } + get + { + return this.graphicsProfile; + } + set + { + throw new NotImplementedException(); + } } public DepthFormat PreferredDepthStencilFormat @@ -312,8 +320,14 @@ namespace ANX.Framework public bool SynchronizeWithVerticalRetrace { - get { throw new NotImplementedException(); } - set { throw new NotImplementedException(); } + get + { + return graphicsDevice.NativeDevice.VSync; + } + set + { + graphicsDevice.NativeDevice.VSync = value; + } } public bool PreferMultiSampling @@ -327,5 +341,23 @@ namespace ANX.Framework get { 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; + } } } diff --git a/ANX.Framework/Input/MotionSensing/MotionSensingDevice.cs b/ANX.Framework/Input/MotionSensing/MotionSensingDevice.cs index f0c5188a..ef539ae8 100644 --- a/ANX.Framework/Input/MotionSensing/MotionSensingDevice.cs +++ b/ANX.Framework/Input/MotionSensing/MotionSensingDevice.cs @@ -65,7 +65,7 @@ namespace ANX.Framework.Input.MotionSensing motionSensingDevice = AddInSystemFactory.Instance.GetCurrentCreator().MotionSensingDevice; } - public GraphicsDevice GraphicsDevice + public static GraphicsDevice GraphicsDevice { get { diff --git a/ANX.Framework/Input/MotionSensing/MotionSensingDeviceState.cs b/ANX.Framework/Input/MotionSensing/MotionSensingDeviceState.cs index fe04d983..659c2792 100644 --- a/ANX.Framework/Input/MotionSensing/MotionSensingDeviceState.cs +++ b/ANX.Framework/Input/MotionSensing/MotionSensingDeviceState.cs @@ -83,7 +83,7 @@ namespace ANX.Framework.Input.MotionSensing 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 Spine { get { return this.pSpine; } } diff --git a/ANX.Framework/NonXNA/InputSystem/IMotionSensingDevice.cs b/ANX.Framework/NonXNA/InputSystem/IMotionSensingDevice.cs index 45165e85..4d80b7cc 100644 --- a/ANX.Framework/NonXNA/InputSystem/IMotionSensingDevice.cs +++ b/ANX.Framework/NonXNA/InputSystem/IMotionSensingDevice.cs @@ -56,7 +56,7 @@ using ANX.Framework.Graphics; #if XNAEXT namespace ANX.Framework.NonXNA { - public interface IMotionSensingDevice + public interface IMotionSensingDevice : IDisposable { GraphicsDevice GraphicsDevice { get; set; } diff --git a/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsDevice.cs b/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsDevice.cs index 011f5560..a333ff0a 100644 --- a/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsDevice.cs +++ b/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsDevice.cs @@ -83,5 +83,7 @@ namespace ANX.Framework.NonXNA void GetBackBufferData(T[] data, int startIndex, int elementCount) where T : struct; void ResizeBuffers(PresentationParameters presentationParameters); + + bool VSync { get; set; } } } diff --git a/ANX.Framework/NonXNA/RenderSystem/INativeTexture.cs b/ANX.Framework/NonXNA/RenderSystem/INativeTexture.cs new file mode 100644 index 00000000..9d1b8f89 --- /dev/null +++ b/ANX.Framework/NonXNA/RenderSystem/INativeTexture.cs @@ -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 + { + + } +} diff --git a/ANX.Framework/NonXNA/RenderSystem/INativeTexture2D.cs b/ANX.Framework/NonXNA/RenderSystem/INativeTexture2D.cs new file mode 100644 index 00000000..f548ab5f --- /dev/null +++ b/ANX.Framework/NonXNA/RenderSystem/INativeTexture2D.cs @@ -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 + { + + } +} diff --git a/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs b/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs index b964a352..0156de3d 100644 --- a/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs +++ b/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs @@ -4,6 +4,7 @@ using ANX.Framework.Graphics; using System.IO; using ANX.Framework.NonXNA; using System.Collections.ObjectModel; +using ANX.Framework.NonXNA.RenderSystem; #endregion // Using Statements @@ -62,7 +63,7 @@ namespace ANX.Framework 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); diff --git a/ANX.Framework/Properties/AssemblyInfo.cs b/ANX.Framework/Properties/AssemblyInfo.cs index b6ecdc3c..9ba88e05 100644 --- a/ANX.Framework/Properties/AssemblyInfo.cs +++ b/ANX.Framework/Properties/AssemblyInfo.cs @@ -32,8 +32,8 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.4.1.*")] -[assembly: AssemblyFileVersion("0.4.1.0")] +[assembly: AssemblyVersion("0.4.12.*")] +[assembly: AssemblyFileVersion("0.4.12.0")] [assembly:InternalsVisibleTo("ANX.Framework.Windows.DX10")] [assembly:InternalsVisibleTo("ANX.Framework.Windows.DX11.1")] diff --git a/ANX.InputSystem.Windows.Kinect/Kinect.cs b/ANX.InputSystem.Windows.Kinect/Kinect.cs index 1e8d9901..ee2a563e 100644 --- a/ANX.InputSystem.Windows.Kinect/Kinect.cs +++ b/ANX.InputSystem.Windows.Kinect/Kinect.cs @@ -78,6 +78,8 @@ namespace ANX.InputSystem.Windows.Kinect pNui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor); pNui.SkeletonEngine.TransformSmooth = true; + + this.cache = new Vector3[21]; //init for the first time for (int i = 0; i < 21; ++i) @@ -96,9 +98,28 @@ namespace ANX.InputSystem.Windows.Kinect 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(pNui_SkeletonFrameReady); pNui.DepthFrameReady += new EventHandler(pNui_DepthFrameReady); pNui.VideoFrameReady += new EventHandler(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) @@ -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. - this.rgb.SetData(e.ImageFrame.Image.Bits); + //TODO: special surface format: this.depth.SetData(e.ImageFrame.Image.Bits); } } @@ -178,5 +199,14 @@ namespace ANX.InputSystem.Windows.Kinect { get { return MotionSensingDeviceType.Kinect; } } + + public void Dispose() + { + if (pNui != null) + { + pNui.Uninitialize(); + pNui = null; + } + } } } diff --git a/ANX.InputSystem.Windows.Kinect/Properties/AssemblyInfo.cs b/ANX.InputSystem.Windows.Kinect/Properties/AssemblyInfo.cs index 4b7a4d20..19406fec 100644 --- a/ANX.InputSystem.Windows.Kinect/Properties/AssemblyInfo.cs +++ b/ANX.InputSystem.Windows.Kinect/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.0.0")] -[assembly: AssemblyFileVersion("0.5.0.0")] +[assembly: AssemblyVersion("0.5.2.0")] +[assembly: AssemblyFileVersion("0.5.2.0")] diff --git a/ANX.RenderSystem.Windows.DX11.1/Creator.cs b/ANX.RenderSystem.Windows.DX11.1/Creator.cs index 2fb47b3e..017d4dc8 100644 --- a/ANX.RenderSystem.Windows.DX11.1/Creator.cs +++ b/ANX.RenderSystem.Windows.DX11.1/Creator.cs @@ -223,5 +223,11 @@ namespace ANX.RenderSystem.Windows.DX11_1 { throw new NotImplementedException(); } + + + public Framework.NonXNA.RenderSystem.INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount) + { + throw new NotImplementedException(); + } } } diff --git a/ANX.RenderSystem.Windows.DX11.1/GraphicsDeviceWindowsDX11_1.cs b/ANX.RenderSystem.Windows.DX11.1/GraphicsDeviceWindowsDX11_1.cs index fd61c05d..90d7df28 100644 --- a/ANX.RenderSystem.Windows.DX11.1/GraphicsDeviceWindowsDX11_1.cs +++ b/ANX.RenderSystem.Windows.DX11.1/GraphicsDeviceWindowsDX11_1.cs @@ -636,5 +636,18 @@ namespace ANX.RenderSystem.Windows.DX11_1 { throw new NotImplementedException(); } + + + public bool VSync + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } } } diff --git a/Samples/Kinect/Game1.cs b/Samples/Kinect/Game1.cs index 769af5b5..3519e24e 100644 --- a/Samples/Kinect/Game1.cs +++ b/Samples/Kinect/Game1.cs @@ -5,6 +5,7 @@ using ANX.Framework; using ANX.Framework.Content; using ANX.Framework.Graphics; using ANX.Framework.Input; +using ANX.Framework.Input.MotionSensing; namespace Kinect { @@ -13,6 +14,8 @@ namespace Kinect GraphicsDeviceManager graphics; SpriteBatch spriteBatch; + MotionSensingDeviceState kinectState; + public Game1() : base("DirectX10", "Kinect") { @@ -22,7 +25,7 @@ namespace Kinect protected override void Initialize() { - // TODO: Fügen Sie Ihre Initialisierungslogik hier hinzu + MotionSensingDevice.GraphicsDevice = GraphicsDevice; base.Initialize(); } @@ -40,7 +43,7 @@ namespace Kinect //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) // this.Exit(); - // TODO: Fügen Sie Ihre Aktualisierungslogik hier hinzu + kinectState = MotionSensingDevice.GetState(); base.Update(gameTime); } @@ -49,7 +52,14 @@ namespace Kinect { 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); }