Resizing of RenderWindow using PresentationParameters and GraphicsDevice.Reset implemented. See TextRendering as example. But: GraphicsDevice.Reset is very incomplete at the moment.

This commit is contained in:
Glatzemann 2011-11-09 19:39:21 +00:00
parent ebcf8d7f6e
commit 0a8bdbb9b0
8 changed files with 121 additions and 8 deletions

View File

@ -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<SharpDX.Direct3D10.Texture2D>(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);
}
}
}
}

View File

@ -293,10 +293,24 @@ namespace ANX.Framework.Windows.GL3
throw new NotImplementedException();
}
<<<<<<< .mine
public void DrawUserPrimitives<T>(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>(T[] data, int startIndex,
int elementCount) where T : struct
{
throw new NotImplementedException();
}
}
>>>>>>> .r12199
}

View File

@ -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

View File

@ -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<EventArgs>(graphicsDevice_DeviceResetting);
this.graphicsDevice.DeviceReset += new EventHandler<EventArgs>(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()

View File

@ -81,5 +81,7 @@ namespace ANX.Framework.NonXNA
void GetBackBufferData<T>(Nullable<Rectangle> rect, T[] data, int startIndex, int elementCount) where T : struct;
void GetBackBufferData<T>(T[] data) where T : struct;
void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct;
void ResizeBuffers(PresentationParameters presentationParameters);
}
}

View File

@ -630,5 +630,11 @@ namespace ANX.RenderSystem.Windows.DX11_1
{
throw new NotImplementedException();
}
public void ResizeBuffers(Framework.Graphics.PresentationParameters presentationParameters)
{
throw new NotImplementedException();
}
}
}

View File

@ -17,7 +17,7 @@ namespace Kinect
: base("DirectX10", "Kinect")
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
Content.RootDirectory = "SampleContent";
}
protected override void Initialize()

View File

@ -72,6 +72,10 @@ namespace TextRendering
protected override void Initialize()
{
GraphicsDevice.PresentationParameters.BackBufferWidth = 1280;
GraphicsDevice.PresentationParameters.BackBufferHeight = 720;
GraphicsDevice.Reset();
base.Initialize();
}