diff --git a/ANX.Framework.Windows.DX10/GraphicsDeviceWindowsDX10.cs b/ANX.Framework.Windows.DX10/GraphicsDeviceWindowsDX10.cs index bffad100..552a6b37 100644 --- a/ANX.Framework.Windows.DX10/GraphicsDeviceWindowsDX10.cs +++ b/ANX.Framework.Windows.DX10/GraphicsDeviceWindowsDX10.cs @@ -62,14 +62,38 @@ using ANX.Framework.Graphics; using Device = SharpDX.Direct3D10.Device; using Buffer = SharpDX.Direct3D10.Buffer; +using System.Runtime.InteropServices; namespace ANX.Framework.Windows.DX10 { public class GraphicsDeviceWindowsDX10 : INativeGraphicsDevice - { - #region Constants - private const float ColorMultiplier = 1f / 255f; - #endregion + { + #region Constants + private const float ColorMultiplier = 1f / 255f; + #endregion + + #region Interop + [DllImport("user32.dll")] + private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int width, int height, uint uFlags); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect); + + [StructLayout(LayoutKind.Sequential)] + public struct RECT + { + public int Left; // x position of upper-left corner + public int Top; // y position of upper-left corner + public int Right; // x position of lower-right corner + public int Bottom; // y position of lower-right corner + } + + #endregion private Device device; private SwapChain swapChain; @@ -370,5 +394,35 @@ namespace ANX.Framework.Windows.DX10 { throw new NotImplementedException(); } + + + public void ResizeBuffers(PresentationParameters presentationParameters) + { + if (swapChain != null) + { + renderView.Dispose(); + backBuffer.Dispose(); + + //TODO: handle format + + swapChain.ResizeBuffers(swapChain.Description.BufferCount, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, Format.R8G8B8A8_UNorm, (int)swapChain.Description.Flags); + + backBuffer = SharpDX.Direct3D10.Texture2D.FromSwapChain(swapChain, 0); + renderView = new RenderTargetView(device, backBuffer); + } + + // resize the render window + RECT windowRect; + RECT clientRect; + if (GetWindowRect(presentationParameters.DeviceWindowHandle, out windowRect) && + GetClientRect(presentationParameters.DeviceWindowHandle, out clientRect)) + { + int width = presentationParameters.BackBufferWidth + ((windowRect.Right - windowRect.Left) - clientRect.Right); + int height = presentationParameters.BackBufferHeight + ((windowRect.Bottom - windowRect.Top) - clientRect.Bottom); + + SetWindowPos(presentationParameters.DeviceWindowHandle, IntPtr.Zero, windowRect.Left, windowRect.Top, width, height, 0); + } } + + } } diff --git a/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs b/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs index e121bc29..d59748b9 100644 --- a/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs +++ b/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs @@ -293,10 +293,24 @@ namespace ANX.Framework.Windows.GL3 throw new NotImplementedException(); } +<<<<<<< .mine + public void DrawUserPrimitives(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType + { + throw new NotImplementedException(); + } + + + public void ResizeBuffers(PresentationParameters presentationParameters) + { + throw new NotImplementedException(); + } + } +======= public void GetBackBufferData(T[] data, int startIndex, int elementCount) where T : struct { throw new NotImplementedException(); } } +>>>>>>> .r12199 } diff --git a/ANX.Framework/Graphics/GraphicsDevice.cs b/ANX.Framework/Graphics/GraphicsDevice.cs index c2430729..d382b5d8 100644 --- a/ANX.Framework/Graphics/GraphicsDevice.cs +++ b/ANX.Framework/Graphics/GraphicsDevice.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using ANX.Framework.NonXNA; using ANX.Framework.Graphics; +using System.Runtime.InteropServices; #endregion // Using Statements @@ -298,7 +299,27 @@ namespace ANX.Framework.Graphics public void Reset(PresentationParameters presentationParameters, GraphicsAdapter adapter) { - throw new NotImplementedException(); + if (presentationParameters == null) + { + throw new ArgumentNullException("presentationParameters"); + } + + if (adapter == null) + { + throw new ArgumentNullException("adapter"); + } + + if (this.currentAdapter != adapter) + { + throw new InvalidOperationException("adapter switch not yet implemented"); + } + + raise_DeviceResetting(this, EventArgs.Empty); + + // reset presentation parameters + nativeDevice.ResizeBuffers(presentationParameters); //TODO: check if necessary + + raise_DeviceReset(this, EventArgs.Empty); } #endregion // Reset diff --git a/ANX.Framework/GraphicsDeviceManager.cs b/ANX.Framework/GraphicsDeviceManager.cs index 0c36ea96..fac51dc4 100644 --- a/ANX.Framework/GraphicsDeviceManager.cs +++ b/ANX.Framework/GraphicsDeviceManager.cs @@ -144,9 +144,21 @@ namespace ANX.Framework deviceInformation.PresentationParameters.BackBufferHeight = DefaultBackBufferHeight; this.graphicsDevice = new GraphicsDevice(deviceInformation.Adapter, deviceInformation.GraphicsProfile, deviceInformation.PresentationParameters); - OnDeviceCreated(this, EventArgs.Empty); - //TODO: hookup events + this.graphicsDevice.DeviceResetting += new EventHandler(graphicsDevice_DeviceResetting); + this.graphicsDevice.DeviceReset += new EventHandler(graphicsDevice_DeviceReset); + + OnDeviceCreated(this, EventArgs.Empty); + } + + void graphicsDevice_DeviceReset(object sender, EventArgs e) + { + OnDeviceReset(this, EventArgs.Empty); + } + + void graphicsDevice_DeviceResetting(object sender, EventArgs e) + { + OnDeviceResetting(this, EventArgs.Empty); } public void EndDraw() diff --git a/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsDevice.cs b/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsDevice.cs index 4875933d..011f5560 100644 --- a/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsDevice.cs +++ b/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsDevice.cs @@ -81,5 +81,7 @@ namespace ANX.Framework.NonXNA void GetBackBufferData(Nullable rect, T[] data, int startIndex, int elementCount) where T : struct; void GetBackBufferData(T[] data) where T : struct; void GetBackBufferData(T[] data, int startIndex, int elementCount) where T : struct; + + void ResizeBuffers(PresentationParameters presentationParameters); } } diff --git a/ANX.RenderSystem.Windows.DX11.1/GraphicsDeviceWindowsDX11_1.cs b/ANX.RenderSystem.Windows.DX11.1/GraphicsDeviceWindowsDX11_1.cs index e04636fa..fd61c05d 100644 --- a/ANX.RenderSystem.Windows.DX11.1/GraphicsDeviceWindowsDX11_1.cs +++ b/ANX.RenderSystem.Windows.DX11.1/GraphicsDeviceWindowsDX11_1.cs @@ -630,5 +630,11 @@ namespace ANX.RenderSystem.Windows.DX11_1 { throw new NotImplementedException(); } + + + public void ResizeBuffers(Framework.Graphics.PresentationParameters presentationParameters) + { + throw new NotImplementedException(); + } } } diff --git a/Samples/Kinect/Game1.cs b/Samples/Kinect/Game1.cs index 046d520f..769af5b5 100644 --- a/Samples/Kinect/Game1.cs +++ b/Samples/Kinect/Game1.cs @@ -17,7 +17,7 @@ namespace Kinect : base("DirectX10", "Kinect") { graphics = new GraphicsDeviceManager(this); - Content.RootDirectory = "Content"; + Content.RootDirectory = "SampleContent"; } protected override void Initialize() diff --git a/Samples/TextRendering/Game1.cs b/Samples/TextRendering/Game1.cs index e9db78f2..baf18de1 100644 --- a/Samples/TextRendering/Game1.cs +++ b/Samples/TextRendering/Game1.cs @@ -72,6 +72,10 @@ namespace TextRendering protected override void Initialize() { + GraphicsDevice.PresentationParameters.BackBufferWidth = 1280; + GraphicsDevice.PresentationParameters.BackBufferHeight = 720; + GraphicsDevice.Reset(); + base.Initialize(); }