2012-09-08 10:37:41 +00:00
|
|
|
|
//#define DIRECTX_DEBUG_LAYER
|
2012-09-15 13:43:31 +00:00
|
|
|
|
|
|
|
|
|
#region Using Statements
|
2012-09-08 10:37:41 +00:00
|
|
|
|
using System;
|
|
|
|
|
using ANX.Framework;
|
|
|
|
|
using ANX.Framework.Graphics;
|
|
|
|
|
using SharpDX.DXGI;
|
|
|
|
|
|
2012-09-15 13:43:31 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2012-09-08 10:37:41 +00:00
|
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
|
|
|
|
|
2012-09-15 13:43:31 +00:00
|
|
|
|
#if DX10
|
|
|
|
|
namespace ANX.RenderSystem.Windows.DX10
|
|
|
|
|
#endif
|
|
|
|
|
#if DX11
|
|
|
|
|
namespace ANX.RenderSystem.Windows.DX11
|
|
|
|
|
#endif
|
2012-09-08 10:37:41 +00:00
|
|
|
|
{
|
2012-09-15 13:43:31 +00:00
|
|
|
|
public partial class GraphicsDeviceDX
|
2012-09-08 10:37:41 +00:00
|
|
|
|
{
|
|
|
|
|
#region Private
|
|
|
|
|
protected SharpDX.DXGI.SwapChain swapChain;
|
2012-09-22 11:17:36 +00:00
|
|
|
|
protected VertexBufferBinding[] currentVertexBuffer;
|
|
|
|
|
protected int currentVertexBufferCount;
|
2012-09-08 10:37:41 +00:00
|
|
|
|
protected IndexBuffer currentIndexBuffer;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Public
|
|
|
|
|
public bool VSync { get; set; }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
2012-09-15 13:43:31 +00:00
|
|
|
|
public GraphicsDeviceDX(PresentationParameters presentationParameters)
|
2012-09-08 10:37:41 +00:00
|
|
|
|
{
|
|
|
|
|
VSync = true;
|
|
|
|
|
|
|
|
|
|
CreateDevice(presentationParameters);
|
|
|
|
|
MakeWindowAssociationAndResize(presentationParameters);
|
2015-09-30 21:31:15 +02:00
|
|
|
|
CreateRenderView(presentationParameters);
|
2012-09-08 10:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region MakeWindowAssociationAndResize
|
|
|
|
|
protected void MakeWindowAssociationAndResize(PresentationParameters presentationParameters)
|
|
|
|
|
{
|
|
|
|
|
// Ignore all windows events
|
|
|
|
|
var factory = swapChain.GetParent<SharpDX.DXGI.Factory>();
|
|
|
|
|
factory.MakeWindowAssociation(presentationParameters.DeviceWindowHandle,
|
|
|
|
|
SharpDX.DXGI.WindowAssociationFlags.IgnoreAll);
|
|
|
|
|
|
|
|
|
|
WindowHelper.ResizeRenderWindow(presentationParameters);
|
|
|
|
|
|
|
|
|
|
SetViewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, 0f, 1f);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region SetViewport
|
|
|
|
|
public void SetViewport(Viewport viewport)
|
|
|
|
|
{
|
|
|
|
|
SetViewport(viewport.X, viewport.Y, viewport.Width, viewport.Height, viewport.MinDepth, viewport.MaxDepth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ResizeBuffers
|
|
|
|
|
public void ResizeBuffers(PresentationParameters presentationParameters)
|
|
|
|
|
{
|
|
|
|
|
if (swapChain != null)
|
|
|
|
|
{
|
2015-09-30 21:31:15 +02:00
|
|
|
|
DisposeBackBuffer();
|
2012-09-08 10:37:41 +00:00
|
|
|
|
|
2012-09-15 13:43:31 +00:00
|
|
|
|
Format colorFormat = DxFormatConverter.Translate(presentationParameters.BackBufferFormat);
|
2012-09-08 10:37:41 +00:00
|
|
|
|
swapChain.ResizeBuffers(swapChain.Description.BufferCount, presentationParameters.BackBufferWidth,
|
|
|
|
|
presentationParameters.BackBufferHeight, colorFormat, swapChain.Description.Flags);
|
|
|
|
|
|
2015-09-30 21:31:15 +02:00
|
|
|
|
CreateRenderView(presentationParameters);
|
2012-09-08 10:37:41 +00:00
|
|
|
|
|
|
|
|
|
SetViewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, 0f, 1f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WindowHelper.ResizeRenderWindow(presentationParameters);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region GetBackBufferData (TODO)
|
|
|
|
|
public void GetBackBufferData<T>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
|
|
|
|
|
{
|
2015-09-30 21:31:15 +02:00
|
|
|
|
this.backBuffer.GetData(0, rect, data, startIndex, elementCount);
|
2012-09-08 10:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GetBackBufferData<T>(T[] data) where T : struct
|
|
|
|
|
{
|
2015-09-30 21:31:15 +02:00
|
|
|
|
this.backBuffer.GetData(data);
|
2012-09-08 10:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct
|
|
|
|
|
{
|
2015-09-30 21:31:15 +02:00
|
|
|
|
this.backBuffer.GetData(data, startIndex, elementCount);
|
2012-09-08 10:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#if XNAEXT
|
|
|
|
|
#region SetConstantBuffer (TODO)
|
|
|
|
|
public void SetConstantBuffer(int slot, ConstantBuffer constantBuffer)
|
|
|
|
|
{
|
|
|
|
|
if (constantBuffer == null)
|
|
|
|
|
throw new ArgumentNullException("constantBuffer");
|
|
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|