Merging some Dx10 and Dx11 Effect and GraphicsDevice code into BaseDirectX
This commit is contained in:
parent
e2f1aa32bd
commit
1bb53ec785
@ -82,6 +82,10 @@
|
||||
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
|
||||
<Name>ANX.Framework</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\RenderSystems\ANX.BaseDirectX\ANX.BaseDirectX.csproj">
|
||||
<Project>{A4D3AD34-E49C-4142-8620-2AFF44ED6719}</Project>
|
||||
<Name>ANX.BaseDirectX</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\RenderSystems\ANX.Framework.Windows.DX10\ANX.RenderSystem.Windows.DX10.csproj">
|
||||
<Project>{5BE49183-2F6F-4527-AC90-D816911FCF90}</Project>
|
||||
<Name>ANX.RenderSystem.Windows.DX10</Name>
|
||||
|
@ -80,6 +80,10 @@
|
||||
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
|
||||
<Name>ANX.Framework</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\RenderSystems\ANX.BaseDirectX\ANX.BaseDirectX_Linux.csproj">
|
||||
<Project>{A4D3AD34-E49C-4142-8620-2AFF44ED6719}</Project>
|
||||
<Name>ANX.BaseDirectX</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\RenderSystems\ANX.Framework.Windows.DX10\ANX.RenderSystem.Windows.DX10_Linux.csproj">
|
||||
<Project>{5BE49183-2F6F-4527-AC90-D816911FCF90}</Project>
|
||||
<Name>ANX.RenderSystem.Windows.DX10</Name>
|
||||
|
@ -83,6 +83,10 @@
|
||||
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
|
||||
<Name>ANX.Framework</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\RenderSystems\ANX.BaseDirectX\ANX.BaseDirectX_PSVita.csproj">
|
||||
<Project>{A4D3AD34-E49C-4142-8620-2AFF44ED6719}</Project>
|
||||
<Name>ANX.BaseDirectX</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\RenderSystems\ANX.Framework.Windows.DX10\ANX.RenderSystem.Windows.DX10_PSVita.csproj">
|
||||
<Project>{5BE49183-2F6F-4527-AC90-D816911FCF90}</Project>
|
||||
<Name>ANX.RenderSystem.Windows.DX10</Name>
|
||||
|
@ -81,6 +81,10 @@
|
||||
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
|
||||
<Name>ANX.Framework</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\RenderSystems\ANX.BaseDirectX\ANX.BaseDirectX_WindowsMetro.csproj">
|
||||
<Project>{A4D3AD34-E49C-4142-8620-2AFF44ED6719}</Project>
|
||||
<Name>ANX.BaseDirectX</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
@ -19,7 +19,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG;XNAEXT</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -29,7 +29,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;XNAEXT</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -40,6 +40,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpDX.D3DCompiler">
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.D3DCompiler.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpDX.DXGI, Version=2.2.0.0, Culture=neutral, PublicKeyToken=6f19e8495e7498cf, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.DXGI.dll</HintPath>
|
||||
@ -47,12 +50,15 @@
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BaseEffect.cs" />
|
||||
<Compile Include="BaseFormatConverter.cs" />
|
||||
<Compile Include="BaseGraphicsDevice.cs" />
|
||||
<Compile Include="BaseStateObject.cs" />
|
||||
<Compile Include="BaseTexture2D.cs" />
|
||||
<Compile Include="BaseVertexBuffer.cs" />
|
||||
<Compile Include="BaseIndexBuffer.cs" />
|
||||
<Compile Include="BaseEffectTechnique.cs" />
|
||||
<Compile Include="IncludeHandler.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WindowHelper.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -18,7 +18,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;LINUX;</DefineConstants>
|
||||
<DefineConstants>XNAEXT;DEBUG;TRACE;LINUX;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -28,7 +28,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;LINUX;</DefineConstants>
|
||||
<DefineConstants>XNAEXT;TRACE;LINUX;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -39,6 +39,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpDX.D3DCompiler">
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.D3DCompiler.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpDX.DXGI, Version=2.2.0.0, Culture=neutral, PublicKeyToken=6f19e8495e7498cf, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.DXGI.dll</HintPath>
|
||||
@ -46,12 +49,15 @@
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BaseEffect.cs" />
|
||||
<Compile Include="BaseFormatConverter.cs" />
|
||||
<Compile Include="BaseGraphicsDevice.cs" />
|
||||
<Compile Include="BaseStateObject.cs" />
|
||||
<Compile Include="BaseTexture2D.cs" />
|
||||
<Compile Include="BaseVertexBuffer.cs" />
|
||||
<Compile Include="BaseIndexBuffer.cs" />
|
||||
<Compile Include="BaseEffectTechnique.cs" />
|
||||
<Compile Include="IncludeHandler.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WindowHelper.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -18,7 +18,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;PSVITA;</DefineConstants>
|
||||
<DefineConstants>XNAEXT;DEBUG;TRACE;PSVITA;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -28,7 +28,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;PSVITA;</DefineConstants>
|
||||
<DefineConstants>XNAEXT;TRACE;PSVITA;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -39,6 +39,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpDX.D3DCompiler">
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.D3DCompiler.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpDX.DXGI, Version=2.2.0.0, Culture=neutral, PublicKeyToken=6f19e8495e7498cf, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.DXGI.dll</HintPath>
|
||||
@ -47,12 +50,15 @@
|
||||
<Reference Include="System.Core" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BaseEffect.cs" />
|
||||
<Compile Include="BaseFormatConverter.cs" />
|
||||
<Compile Include="BaseGraphicsDevice.cs" />
|
||||
<Compile Include="BaseStateObject.cs" />
|
||||
<Compile Include="BaseTexture2D.cs" />
|
||||
<Compile Include="BaseVertexBuffer.cs" />
|
||||
<Compile Include="BaseIndexBuffer.cs" />
|
||||
<Compile Include="BaseEffectTechnique.cs" />
|
||||
<Compile Include="IncludeHandler.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WindowHelper.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -20,7 +20,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;WINDOWSMETRO;</DefineConstants>
|
||||
<DefineConstants>XNAEXT;DEBUG;TRACE;WINDOWSMETRO;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -30,7 +30,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;WINDOWSMETRO;</DefineConstants>
|
||||
<DefineConstants>XNAEXT;TRACE;WINDOWSMETRO;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -41,6 +41,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpDX.D3DCompiler">
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.D3DCompiler.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpDX.DXGI, Version=2.2.0.0, Culture=neutral, PublicKeyToken=6f19e8495e7498cf, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\SharpDX\Bin\Standard-net20\SharpDX.DXGI.dll</HintPath>
|
||||
@ -48,12 +51,15 @@
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BaseEffect.cs" />
|
||||
<Compile Include="BaseFormatConverter.cs" />
|
||||
<Compile Include="BaseGraphicsDevice.cs" />
|
||||
<Compile Include="BaseStateObject.cs" />
|
||||
<Compile Include="BaseTexture2D.cs" />
|
||||
<Compile Include="BaseVertexBuffer.cs" />
|
||||
<Compile Include="BaseIndexBuffer.cs" />
|
||||
<Compile Include="BaseEffectTechnique.cs" />
|
||||
<Compile Include="IncludeHandler.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WindowHelper.cs" />
|
||||
</ItemGroup>
|
||||
|
68
RenderSystems/ANX.BaseDirectX/BaseEffect.cs
Normal file
68
RenderSystems/ANX.BaseDirectX/BaseEffect.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using SharpDX.D3DCompiler;
|
||||
using System.IO;
|
||||
using ANX.Framework.Graphics;
|
||||
|
||||
// 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
|
||||
|
||||
namespace ANX.BaseDirectX
|
||||
{
|
||||
public abstract class BaseEffect
|
||||
{
|
||||
protected Effect managedEffect;
|
||||
|
||||
#region Constructor
|
||||
protected BaseEffect(Effect managedEffect)
|
||||
{
|
||||
if (managedEffect == null)
|
||||
throw new ArgumentNullException("managedEffect");
|
||||
this.managedEffect = managedEffect;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetByteCode
|
||||
protected ShaderBytecode GetByteCode(Stream stream)
|
||||
{
|
||||
if (stream.CanSeek)
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return ShaderBytecode.FromStream(stream);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompileVertexShader (TODO)
|
||||
public static byte[] CompileVertexShader(string effectCode, string directory = "")
|
||||
{
|
||||
// TODO: not all entry points are named VS!
|
||||
ShaderBytecode vertexShaderByteCode = ShaderBytecode.Compile(effectCode, "VS", "vs_4_0", ShaderFlags.None,
|
||||
EffectFlags.None, null, new IncludeHandler(directory), "unknown");
|
||||
byte[] bytecode = new byte[vertexShaderByteCode.BufferSize];
|
||||
vertexShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
|
||||
return bytecode;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompilePixelShader (TODO)
|
||||
public static byte[] CompilePixelShader(string effectCode, string directory = "")
|
||||
{
|
||||
// TODO: not all entry points are named PS!
|
||||
ShaderBytecode pixelShaderByteCode = ShaderBytecode.Compile(effectCode, "PS", "ps_4_0", ShaderFlags.None,
|
||||
EffectFlags.None, null, new IncludeHandler(directory), "unknown");
|
||||
byte[] bytecode = new byte[pixelShaderByteCode.BufferSize];
|
||||
pixelShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
|
||||
return bytecode;
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected static byte[] CompileShader(string profile, string effectCode, string directory = "")
|
||||
{
|
||||
ShaderBytecode effectByteCode = ShaderBytecode.Compile(effectCode, profile, ShaderFlags.None, EffectFlags.None,
|
||||
null, new IncludeHandler(directory), "unknown");
|
||||
byte[] bytecode = new byte[effectByteCode.BufferSize];
|
||||
effectByteCode.Data.Read(bytecode, 0, bytecode.Length);
|
||||
return bytecode;
|
||||
}
|
||||
}
|
||||
}
|
@ -154,5 +154,31 @@ namespace ANX.BaseDirectX
|
||||
throw new NotImplementedException("Couldn't calculate vertex count for PrimitiveType '" + type + "'.");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ConvertVertexElementFormat
|
||||
public static Format ConvertVertexElementFormat(VertexElementFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case VertexElementFormat.Vector2:
|
||||
return Format.R32G32_Float;
|
||||
case VertexElementFormat.Vector3:
|
||||
return Format.R32G32B32_Float;
|
||||
case VertexElementFormat.Vector4:
|
||||
return Format.R32G32B32A32_Float;
|
||||
case VertexElementFormat.Color:
|
||||
return Format.R8G8B8A8_UNorm;
|
||||
case VertexElementFormat.Single:
|
||||
return Format.R32_Float;
|
||||
// TODO: validate
|
||||
case VertexElementFormat.Short2:
|
||||
return Format.R16G16_SInt;
|
||||
case VertexElementFormat.Short4:
|
||||
return Format.R16G16B16A16_SInt;
|
||||
}
|
||||
|
||||
throw new Exception("Can't map '" + format + "' to DXGI.Format in Dx10 CreateInputElementFromVertexElement.");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
160
RenderSystems/ANX.BaseDirectX/BaseGraphicsDevice.cs
Normal file
160
RenderSystems/ANX.BaseDirectX/BaseGraphicsDevice.cs
Normal file
@ -0,0 +1,160 @@
|
||||
//#define DIRECTX_DEBUG_LAYER
|
||||
using System;
|
||||
using ANX.Framework;
|
||||
using ANX.Framework.Graphics;
|
||||
using SharpDX.DXGI;
|
||||
|
||||
// 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
|
||||
|
||||
namespace ANX.BaseDirectX
|
||||
{
|
||||
public abstract class BaseGraphicsDevice<S>
|
||||
{
|
||||
#region Constants
|
||||
protected const float ColorMultiplier = 1f / 255f;
|
||||
|
||||
protected const bool IsDebugMode =
|
||||
#if DIRECTX_DEBUG_LAYER
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
protected S nativeDevice;
|
||||
protected uint lastClearColor;
|
||||
protected SharpDX.Color4 clearColor;
|
||||
protected SharpDX.DXGI.SwapChain swapChain;
|
||||
protected VertexBuffer currentVertexBuffer;
|
||||
protected IndexBuffer currentIndexBuffer;
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
public bool VSync { get; set; }
|
||||
|
||||
public S NativeDevice
|
||||
{
|
||||
get
|
||||
{
|
||||
return nativeDevice;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
protected BaseGraphicsDevice(PresentationParameters presentationParameters)
|
||||
{
|
||||
VSync = true;
|
||||
|
||||
CreateDevice(presentationParameters);
|
||||
MakeWindowAssociationAndResize(presentationParameters);
|
||||
CreateRenderView();
|
||||
|
||||
// create the depth stencil buffer
|
||||
SharpDX.DXGI.Format depthFormat = BaseFormatConverter.Translate(presentationParameters.DepthStencilFormat);
|
||||
if (depthFormat != SharpDX.DXGI.Format.Unknown)
|
||||
CreateDepthStencilBuffer(depthFormat);
|
||||
}
|
||||
#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 UpdateClearColorIfNeeded
|
||||
protected void UpdateClearColorIfNeeded(ref Color color)
|
||||
{
|
||||
uint newClearColor = color.PackedValue;
|
||||
if (lastClearColor != newClearColor)
|
||||
{
|
||||
lastClearColor = newClearColor;
|
||||
clearColor.Red = color.R * ColorMultiplier;
|
||||
clearColor.Green = color.G * ColorMultiplier;
|
||||
clearColor.Blue = color.B * ColorMultiplier;
|
||||
clearColor.Alpha = color.A * ColorMultiplier;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetViewport
|
||||
public void SetViewport(Viewport viewport)
|
||||
{
|
||||
SetViewport(viewport.X, viewport.Y, viewport.Width, viewport.Height, viewport.MinDepth, viewport.MaxDepth);
|
||||
}
|
||||
|
||||
protected abstract void SetViewport(int x, int y, int width, int height, float minDepth, float maxDepth);
|
||||
#endregion
|
||||
|
||||
#region ResizeBuffers
|
||||
public void ResizeBuffers(PresentationParameters presentationParameters)
|
||||
{
|
||||
if (swapChain != null)
|
||||
{
|
||||
DisposeRenderView();
|
||||
|
||||
Format colorFormat = BaseFormatConverter.Translate(presentationParameters.BackBufferFormat);
|
||||
swapChain.ResizeBuffers(swapChain.Description.BufferCount, presentationParameters.BackBufferWidth,
|
||||
presentationParameters.BackBufferHeight, colorFormat, swapChain.Description.Flags);
|
||||
|
||||
CreateRenderView();
|
||||
|
||||
SetViewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, 0f, 1f);
|
||||
|
||||
// create the depth stencil buffer
|
||||
Format depthFormat = BaseFormatConverter.Translate(presentationParameters.DepthStencilFormat);
|
||||
if (depthFormat != Format.Unknown)
|
||||
CreateDepthStencilBuffer(depthFormat);
|
||||
}
|
||||
|
||||
WindowHelper.ResizeRenderWindow(presentationParameters);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetBackBufferData (TODO)
|
||||
public void GetBackBufferData<T>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void GetBackBufferData<T>(T[] data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#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
|
||||
|
||||
protected abstract void CreateDevice(PresentationParameters presentationParameters);
|
||||
protected abstract void CreateRenderView();
|
||||
protected abstract void CreateDepthStencilBuffer(SharpDX.DXGI.Format depthFormat);
|
||||
protected abstract void DisposeRenderView();
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ using SharpDX.D3DCompiler;
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
// For details see: http://anxframework.codeplex.com/license
|
||||
|
||||
namespace ANX.RenderSystem.Windows.DX11.Helpers
|
||||
namespace ANX.BaseDirectX
|
||||
{
|
||||
internal class IncludeHandler : Include
|
||||
public class IncludeHandler : Include
|
||||
{
|
||||
private string directory;
|
||||
|
@ -84,7 +84,6 @@
|
||||
<Compile Include="Effect_DX10.cs" />
|
||||
<Compile Include="Helpers\FormatConverter.cs" />
|
||||
<Compile Include="GraphicsDeviceWindowsDX10.cs" />
|
||||
<Compile Include="Helpers\IncludeHandler.cs" />
|
||||
<Compile Include="IndexBuffer_DX10.cs" />
|
||||
<Compile Include="EffectPass_DX10.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -84,7 +84,6 @@
|
||||
<Compile Include="Effect_DX10.cs" />
|
||||
<Compile Include="Helpers\FormatConverter.cs" />
|
||||
<Compile Include="GraphicsDeviceWindowsDX10.cs" />
|
||||
<Compile Include="Helpers\IncludeHandler.cs" />
|
||||
<Compile Include="IndexBuffer_DX10.cs" />
|
||||
<Compile Include="EffectPass_DX10.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -85,7 +85,6 @@
|
||||
<Compile Include="Effect_DX10.cs" />
|
||||
<Compile Include="Helpers\FormatConverter.cs" />
|
||||
<Compile Include="GraphicsDeviceWindowsDX10.cs" />
|
||||
<Compile Include="Helpers\IncludeHandler.cs" />
|
||||
<Compile Include="IndexBuffer_DX10.cs" />
|
||||
<Compile Include="EffectPass_DX10.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -86,7 +86,6 @@
|
||||
<Compile Include="Effect_DX10.cs" />
|
||||
<Compile Include="Helpers\FormatConverter.cs" />
|
||||
<Compile Include="GraphicsDeviceWindowsDX10.cs" />
|
||||
<Compile Include="Helpers\IncludeHandler.cs" />
|
||||
<Compile Include="IndexBuffer_DX10.cs" />
|
||||
<Compile Include="EffectPass_DX10.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ANX.BaseDirectX;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.RenderSystem.Windows.DX10.Helpers;
|
||||
using SharpDX.D3DCompiler;
|
||||
using Dx10 = SharpDX.Direct3D10;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
@ -13,20 +12,15 @@ using Dx10 = SharpDX.Direct3D10;
|
||||
|
||||
namespace ANX.RenderSystem.Windows.DX10
|
||||
{
|
||||
public class Effect_DX10 : INativeEffect
|
||||
public class Effect_DX10 : BaseEffect, INativeEffect
|
||||
{
|
||||
#region Private
|
||||
private Dx10.VertexShader vertexShader;
|
||||
private Dx10.PixelShader pixelShader;
|
||||
private Effect managedEffect;
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
internal Dx10.Effect NativeEffect
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal Dx10.Effect NativeEffect { get; private set; }
|
||||
|
||||
public IEnumerable<EffectTechnique> Techniques
|
||||
{
|
||||
@ -58,37 +52,20 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Effect_DX10(GraphicsDevice device, Effect setManagedEffect, Stream vertexShaderStream, Stream pixelShaderStream)
|
||||
{
|
||||
if (setManagedEffect == null)
|
||||
throw new ArgumentNullException("managedEffect");
|
||||
managedEffect = setManagedEffect;
|
||||
|
||||
if (vertexShaderStream.CanSeek)
|
||||
vertexShaderStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var vertexShaderByteCode = ShaderBytecode.FromStream(vertexShaderStream);
|
||||
vertexShader = new Dx10.VertexShader((SharpDX.Direct3D10.Device)device.NativeDevice, vertexShaderByteCode);
|
||||
|
||||
if (pixelShaderStream.CanSeek)
|
||||
pixelShaderStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var pixelShaderByteCode = ShaderBytecode.FromStream(pixelShaderStream);
|
||||
pixelShader = new Dx10.PixelShader((SharpDX.Direct3D10.Device)device.NativeDevice, pixelShaderByteCode);
|
||||
public Effect_DX10(GraphicsDevice graphicsDevice, Effect managedEffect, Stream vertexShaderStream,
|
||||
Stream pixelShaderStream)
|
||||
: base(managedEffect)
|
||||
{
|
||||
var device = ((GraphicsDeviceWindowsDX10)graphicsDevice.NativeDevice).NativeDevice;
|
||||
vertexShader = new Dx10.VertexShader(device, GetByteCode(vertexShaderStream));
|
||||
pixelShader = new Dx10.PixelShader(device, GetByteCode(pixelShaderStream));
|
||||
}
|
||||
|
||||
public Effect_DX10(GraphicsDevice device, Effect setManagedEffect, Stream effectStream)
|
||||
{
|
||||
if (setManagedEffect == null)
|
||||
throw new ArgumentNullException("managedEffect");
|
||||
managedEffect = setManagedEffect;
|
||||
|
||||
if (effectStream.CanSeek)
|
||||
effectStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var effectByteCode = ShaderBytecode.FromStream(effectStream);
|
||||
NativeEffect = new Dx10.Effect(((GraphicsDeviceWindowsDX10)device.NativeDevice).NativeDevice,
|
||||
effectByteCode, EffectFlags.None);
|
||||
public Effect_DX10(GraphicsDevice graphicsDevice, Effect managedEffect, Stream effectStream)
|
||||
: base(managedEffect)
|
||||
{
|
||||
var device = ((GraphicsDeviceWindowsDX10)graphicsDevice.NativeDevice).NativeDevice;
|
||||
NativeEffect = new Dx10.Effect(device, GetByteCode(effectStream));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -106,39 +83,11 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompileVertexShader (TODO)
|
||||
public static byte[] CompileVertexShader(string effectCode, string directory = "")
|
||||
{
|
||||
// TODO: not all entry points are named VS!
|
||||
ShaderBytecode vertexShaderByteCode = ShaderBytecode.Compile(effectCode, "VS", "vs_4_0", ShaderFlags.None,
|
||||
EffectFlags.None, null, new IncludeHandler(directory), "unknown");
|
||||
byte[] bytecode = new byte[vertexShaderByteCode.BufferSize];
|
||||
vertexShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
|
||||
return bytecode;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompilePixelShader (TODO)
|
||||
public static byte[] CompilePixelShader(string effectCode, string directory = "")
|
||||
{
|
||||
// TODO: not all entry points are named PS!
|
||||
ShaderBytecode pixelShaderByteCode = ShaderBytecode.Compile(effectCode, "PS", "ps_4_0", ShaderFlags.None,
|
||||
EffectFlags.None, null, new IncludeHandler(directory), "unknown");
|
||||
byte[] bytecode = new byte[pixelShaderByteCode.BufferSize];
|
||||
pixelShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
|
||||
return bytecode;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompileFXShader
|
||||
public static byte[] CompileFXShader(string effectCode, string directory = "")
|
||||
{
|
||||
ShaderBytecode effectByteCode = ShaderBytecode.Compile(effectCode, "fx_4_0", ShaderFlags.None, EffectFlags.None,
|
||||
null, new IncludeHandler(directory), "unknown");
|
||||
byte[] bytecode = new byte[effectByteCode.BufferSize];
|
||||
effectByteCode.Data.Read(bytecode, 0, bytecode.Length);
|
||||
return bytecode;
|
||||
}
|
||||
{
|
||||
return CompileShader("fx_4_0", effectCode, directory);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
|
@ -1,13 +1,11 @@
|
||||
//#define DIRECTX_DEBUG_LAYER
|
||||
using System;
|
||||
using ANX.BaseDirectX;
|
||||
using ANX.Framework;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.RenderSystem.Windows.DX10.Helpers;
|
||||
using SharpDX.D3DCompiler;
|
||||
using SharpDX.DXGI;
|
||||
using Dx10 = SharpDX.Direct3D10;
|
||||
using ANX.BaseDirectX;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -15,92 +13,57 @@ using ANX.BaseDirectX;
|
||||
|
||||
namespace ANX.RenderSystem.Windows.DX10
|
||||
{
|
||||
public class GraphicsDeviceWindowsDX10 : INativeGraphicsDevice
|
||||
public class GraphicsDeviceWindowsDX10 : BaseGraphicsDevice<Dx10.Device>, INativeGraphicsDevice
|
||||
{
|
||||
#region Constants
|
||||
private const float ColorMultiplier = 1f / 255f;
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
private Dx10.Device device;
|
||||
private SwapChain swapChain;
|
||||
private Dx10.RenderTargetView renderView;
|
||||
private Dx10.RenderTargetView[] renderTargetView = new Dx10.RenderTargetView[1];
|
||||
private Dx10.DepthStencilView depthStencilView;
|
||||
private Dx10.Texture2D depthStencilBuffer;
|
||||
private Dx10.Texture2D backBuffer;
|
||||
internal Effect_DX10 currentEffect;
|
||||
private VertexBuffer currentVertexBuffer;
|
||||
private IndexBuffer currentIndexBuffer;
|
||||
private Dx10.Viewport currentViewport;
|
||||
private uint lastClearColor;
|
||||
private SharpDX.Color4 clearColor;
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
internal Dx10.Device NativeDevice
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.device;
|
||||
}
|
||||
}
|
||||
|
||||
public bool VSync { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public GraphicsDeviceWindowsDX10(PresentationParameters presentationParameters)
|
||||
: base(presentationParameters)
|
||||
{
|
||||
VSync = true;
|
||||
|
||||
// SwapChain description
|
||||
var desc = new SwapChainDescription()
|
||||
{
|
||||
BufferCount = 1,
|
||||
ModeDescription = new ModeDescription(presentationParameters.BackBufferWidth,
|
||||
presentationParameters.BackBufferHeight, new Rational(60, 1),
|
||||
BaseFormatConverter.Translate(presentationParameters.BackBufferFormat)),
|
||||
IsWindowed = true,
|
||||
OutputHandle = presentationParameters.DeviceWindowHandle,
|
||||
SampleDescription = new SampleDescription(1, 0),
|
||||
SwapEffect = SwapEffect.Discard,
|
||||
Usage = Usage.RenderTargetOutput
|
||||
};
|
||||
|
||||
// Create Device and SwapChain
|
||||
#if DIRECTX_DEBUG_LAYER
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb205068(v=vs.85).aspx
|
||||
Dx10.Device.CreateWithSwapChain(Dx10.DriverType.Hardware, Dx10.DeviceCreationFlags.Debug, desc, out device,
|
||||
out swapChain);
|
||||
#else
|
||||
Dx10.Device.CreateWithSwapChain(Dx10.DriverType.Hardware, Dx10.DeviceCreationFlags.None, desc, out device,
|
||||
out swapChain);
|
||||
#endif
|
||||
|
||||
// Ignore all windows events
|
||||
Factory factory = swapChain.GetParent<Factory>();
|
||||
factory.MakeWindowAssociation(presentationParameters.DeviceWindowHandle, WindowAssociationFlags.IgnoreAll);
|
||||
|
||||
WindowHelper.ResizeRenderWindow(presentationParameters);
|
||||
|
||||
// New RenderTargetView from the backbuffer
|
||||
backBuffer = Dx10.Texture2D.FromSwapChain<Dx10.Texture2D>(swapChain, 0);
|
||||
renderView = new Dx10.RenderTargetView(device, backBuffer);
|
||||
|
||||
currentViewport = new Dx10.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
|
||||
|
||||
//
|
||||
// create the depth stencil buffer
|
||||
//
|
||||
Format depthFormat = BaseFormatConverter.Translate(presentationParameters.DepthStencilFormat);
|
||||
if (depthFormat != Format.Unknown)
|
||||
CreateDepthStencilBuffer(depthFormat);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateDevice
|
||||
protected override void CreateDevice(PresentationParameters presentationParameters)
|
||||
{
|
||||
var desc = new SwapChainDescription()
|
||||
{
|
||||
BufferCount = 1,
|
||||
ModeDescription = new ModeDescription(presentationParameters.BackBufferWidth,
|
||||
presentationParameters.BackBufferHeight, new Rational(60, 1),
|
||||
BaseFormatConverter.Translate(presentationParameters.BackBufferFormat)),
|
||||
IsWindowed = true,
|
||||
OutputHandle = presentationParameters.DeviceWindowHandle,
|
||||
SampleDescription = new SampleDescription(1, 0),
|
||||
SwapEffect = SwapEffect.Discard,
|
||||
Usage = Usage.RenderTargetOutput
|
||||
};
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb205068(v=vs.85).aspx
|
||||
var flags = IsDebugMode ? Dx10.DeviceCreationFlags.Debug : Dx10.DeviceCreationFlags.None;
|
||||
Dx10.Device.CreateWithSwapChain(Dx10.DriverType.Hardware, flags, desc, out nativeDevice, out swapChain);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateRenderView
|
||||
protected override void CreateRenderView()
|
||||
{
|
||||
backBuffer = Dx10.Texture2D.FromSwapChain<Dx10.Texture2D>(swapChain, 0);
|
||||
renderView = new Dx10.RenderTargetView(nativeDevice, backBuffer);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateDepthStencilBuffer
|
||||
private void CreateDepthStencilBuffer(Format depthFormat)
|
||||
protected override void CreateDepthStencilBuffer(Format depthFormat)
|
||||
{
|
||||
if (this.depthStencilBuffer != null &&
|
||||
this.depthStencilBuffer.Description.Format == depthFormat &&
|
||||
@ -147,9 +110,9 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
CpuAccessFlags = Dx10.CpuAccessFlags.None,
|
||||
OptionFlags = Dx10.ResourceOptionFlags.None
|
||||
};
|
||||
this.depthStencilBuffer = new Dx10.Texture2D(device, depthStencilTextureDesc);
|
||||
this.depthStencilBuffer = new Dx10.Texture2D(nativeDevice, depthStencilTextureDesc);
|
||||
|
||||
this.depthStencilView = new Dx10.DepthStencilView(device, this.depthStencilBuffer);
|
||||
this.depthStencilView = new Dx10.DepthStencilView(nativeDevice, this.depthStencilBuffer);
|
||||
|
||||
// this workaround is working but maybe not the best solution to issue #472
|
||||
Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil, Vector4.Zero, 1.0f, 0);
|
||||
@ -159,20 +122,10 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
#region Clear
|
||||
public void Clear(ref Color color)
|
||||
{
|
||||
uint newClearColor = color.PackedValue;
|
||||
if (lastClearColor != newClearColor)
|
||||
{
|
||||
lastClearColor = newClearColor;
|
||||
clearColor.Red = color.R * ColorMultiplier;
|
||||
clearColor.Green = color.G * ColorMultiplier;
|
||||
clearColor.Blue = color.B * ColorMultiplier;
|
||||
clearColor.Alpha = color.A * ColorMultiplier;
|
||||
}
|
||||
UpdateClearColorIfNeeded(ref color);
|
||||
|
||||
if (this.renderTargetView[0] == null)
|
||||
{
|
||||
this.device.ClearRenderTargetView(this.renderView, this.clearColor);
|
||||
}
|
||||
nativeDevice.ClearRenderTargetView(this.renderView, this.clearColor);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < this.renderTargetView.Length; i++)
|
||||
@ -182,7 +135,7 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
break;
|
||||
}
|
||||
|
||||
this.device.ClearRenderTargetView(this.renderTargetView[i], this.clearColor);
|
||||
nativeDevice.ClearRenderTargetView(this.renderTargetView[i], this.clearColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -201,18 +154,16 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
|
||||
if (this.renderTargetView[0] == null)
|
||||
{
|
||||
this.device.ClearRenderTargetView(this.renderView, this.clearColor);
|
||||
nativeDevice.ClearRenderTargetView(this.renderView, this.clearColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < this.renderTargetView.Length; i++)
|
||||
{
|
||||
if (this.renderTargetView[i] == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
this.device.ClearRenderTargetView(this.renderTargetView[i], this.clearColor);
|
||||
nativeDevice.ClearRenderTargetView(this.renderTargetView[i], this.clearColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -222,17 +173,18 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
if ((options | ClearOptions.Stencil | ClearOptions.DepthBuffer) == options)
|
||||
{
|
||||
// Clear the stencil buffer
|
||||
device.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Depth |
|
||||
nativeDevice.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Depth |
|
||||
Dx10.DepthStencilClearFlags.Stencil, depth, (byte)stencil);
|
||||
}
|
||||
else if ((options | ClearOptions.Stencil) == options)
|
||||
{
|
||||
device.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Stencil, depth,
|
||||
nativeDevice.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Stencil, depth,
|
||||
(byte)stencil);
|
||||
}
|
||||
else
|
||||
{
|
||||
device.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Depth, depth, (byte)stencil);
|
||||
nativeDevice.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Depth, depth,
|
||||
(byte)stencil);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -252,18 +204,18 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
Dx10.EffectTechnique technique = SetupEffectForDraw();
|
||||
int vertexCount = BaseFormatConverter.CalculateVertexCount(primitiveType, primitiveCount);
|
||||
|
||||
device.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
device.Rasterizer.SetViewports(currentViewport);
|
||||
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
nativeDevice.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
nativeDevice.Rasterizer.SetViewports(currentViewport);
|
||||
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
|
||||
for (int i = 0; i < technique.Description.PassCount; ++i)
|
||||
{
|
||||
technique.GetPassByIndex(i).Apply();
|
||||
device.DrawIndexed(vertexCount, startIndex, baseVertex);
|
||||
nativeDevice.DrawIndexed(vertexCount, startIndex, baseVertex);
|
||||
}
|
||||
|
||||
device.InputAssembler.InputLayout.Dispose();
|
||||
device.InputAssembler.InputLayout = null;
|
||||
nativeDevice.InputAssembler.InputLayout.Dispose();
|
||||
nativeDevice.InputAssembler.InputLayout = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -272,18 +224,18 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
{
|
||||
Dx10.EffectTechnique technique = SetupEffectForDraw();
|
||||
|
||||
device.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
device.Rasterizer.SetViewports(currentViewport);
|
||||
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
nativeDevice.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
nativeDevice.Rasterizer.SetViewports(currentViewport);
|
||||
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
|
||||
for (int i = 0; i < technique.Description.PassCount; ++i)
|
||||
{
|
||||
technique.GetPassByIndex(i).Apply();
|
||||
device.Draw(primitiveCount, vertexOffset);
|
||||
nativeDevice.Draw(primitiveCount, vertexOffset);
|
||||
}
|
||||
|
||||
device.InputAssembler.InputLayout.Dispose();
|
||||
device.InputAssembler.InputLayout = null;
|
||||
nativeDevice.InputAssembler.InputLayout.Dispose();
|
||||
nativeDevice.InputAssembler.InputLayout = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -291,7 +243,7 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices,
|
||||
int startIndex, int primitiveCount, int instanceCount)
|
||||
{
|
||||
device.DrawIndexedInstanced(numVertices, instanceCount, startIndex, baseVertex, 0);
|
||||
nativeDevice.DrawIndexedInstanced(numVertices, instanceCount, startIndex, baseVertex, 0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -302,15 +254,15 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
{
|
||||
int vertexCount = vertexData.Length;
|
||||
int indexCount = indexData.Length;
|
||||
VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(this.device, vertexDeclaration, vertexCount, BufferUsage.None);
|
||||
VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(nativeDevice, vertexDeclaration, vertexCount, BufferUsage.None);
|
||||
vb10.SetData<T>(null, vertexData);
|
||||
|
||||
Dx10.VertexBufferBinding nativeVertexBufferBindings = new Dx10.VertexBufferBinding(vb10.NativeBuffer,
|
||||
vertexDeclaration.VertexStride, 0);
|
||||
|
||||
device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
|
||||
IndexBuffer_DX10 idx10 = new IndexBuffer_DX10(this.device, indexFormat, indexCount, BufferUsage.None);
|
||||
IndexBuffer_DX10 idx10 = new IndexBuffer_DX10(nativeDevice, indexFormat, indexCount, BufferUsage.None);
|
||||
if (indexData.GetType() == typeof(Int16[]))
|
||||
idx10.SetData<short>(null, (short[])indexData);
|
||||
else
|
||||
@ -325,36 +277,36 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
VertexDeclaration vertexDeclaration) where T : struct, IVertexType
|
||||
{
|
||||
int vertexCount = vertexData.Length;
|
||||
VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(this.device, vertexDeclaration, vertexCount, BufferUsage.None);
|
||||
VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(nativeDevice, vertexDeclaration, vertexCount, BufferUsage.None);
|
||||
vb10.SetData<T>(null, vertexData);
|
||||
|
||||
Dx10.VertexBufferBinding nativeVertexBufferBindings = new Dx10.VertexBufferBinding(vb10.NativeBuffer,
|
||||
vertexDeclaration.VertexStride, 0);
|
||||
|
||||
device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
|
||||
//TODO: check for currentEffect null and throw exception
|
||||
// TODO: check for null's and throw exceptions
|
||||
// TODO: get the correct pass index!
|
||||
var technique = currentEffect.GetCurrentTechnique().NativeTechnique;
|
||||
var pass = technique.GetPassByIndex(0);
|
||||
var layout = CreateInputLayout(device, pass.Description.Signature, vertexDeclaration);
|
||||
var layout = CreateInputLayout(nativeDevice, pass.Description.Signature, vertexDeclaration);
|
||||
|
||||
device.InputAssembler.InputLayout = layout;
|
||||
nativeDevice.InputAssembler.InputLayout = layout;
|
||||
// Prepare All the stages
|
||||
device.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
device.Rasterizer.SetViewports(currentViewport);
|
||||
nativeDevice.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
nativeDevice.Rasterizer.SetViewports(currentViewport);
|
||||
|
||||
//device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
|
||||
for (int i = 0; i < technique.Description.PassCount; ++i)
|
||||
{
|
||||
pass.Apply();
|
||||
device.Draw(primitiveCount, vertexOffset);
|
||||
nativeDevice.Draw(primitiveCount, vertexOffset);
|
||||
}
|
||||
|
||||
device.InputAssembler.InputLayout.Dispose();
|
||||
device.InputAssembler.InputLayout = null;
|
||||
nativeDevice.InputAssembler.InputLayout.Dispose();
|
||||
nativeDevice.InputAssembler.InputLayout = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -379,9 +331,9 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
throw new ArgumentNullException("passSignature");
|
||||
|
||||
VertexDeclaration vertexDeclaration = currentVertexBuffer.VertexDeclaration;
|
||||
var layout = CreateInputLayout(device, passSignature, vertexDeclaration);
|
||||
var layout = CreateInputLayout(nativeDevice, passSignature, vertexDeclaration);
|
||||
|
||||
device.InputAssembler.InputLayout = layout;
|
||||
nativeDevice.InputAssembler.InputLayout = layout;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -389,9 +341,7 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
public void SetIndexBuffer(IndexBuffer indexBuffer)
|
||||
{
|
||||
if (indexBuffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("indexBuffer");
|
||||
}
|
||||
|
||||
this.currentIndexBuffer = indexBuffer;
|
||||
|
||||
@ -399,7 +349,7 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
|
||||
if (nativeIndexBuffer != null)
|
||||
{
|
||||
device.InputAssembler.SetIndexBuffer(nativeIndexBuffer.NativeBuffer,
|
||||
nativeDevice.InputAssembler.SetIndexBuffer(nativeIndexBuffer.NativeBuffer,
|
||||
BaseFormatConverter.Translate(indexBuffer.IndexElementSize), 0);
|
||||
}
|
||||
else
|
||||
@ -409,18 +359,6 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
}
|
||||
#endregion
|
||||
|
||||
#if XNAEXT
|
||||
#region SetConstantBuffer
|
||||
public void SetConstantBuffer(int slot, ANX.Framework.Graphics.ConstantBuffer constantBuffer)
|
||||
{
|
||||
if (constantBuffer == null)
|
||||
throw new ArgumentNullException("constantBuffer");
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
|
||||
#region SetVertexBuffers
|
||||
public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
|
||||
{
|
||||
@ -447,16 +385,15 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
}
|
||||
}
|
||||
|
||||
device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetViewport
|
||||
public void SetViewport(Viewport viewport)
|
||||
{
|
||||
this.currentViewport = new Dx10.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height,
|
||||
viewport.MinDepth, viewport.MaxDepth);
|
||||
}
|
||||
protected override void SetViewport(int x, int y, int width, int height, float minDepth, float maxDepth)
|
||||
{
|
||||
currentViewport = new Dx10.Viewport(x, y, width, height, minDepth, maxDepth);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateInputLayout
|
||||
@ -482,37 +419,11 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
private Dx10.InputElement CreateInputElementFromVertexElement(VertexElement vertexElement)
|
||||
{
|
||||
string elementName = BaseFormatConverter.Translate(ref vertexElement);
|
||||
Format elementFormat = ConvertVertexElementFormat(vertexElement.VertexElementFormat);
|
||||
Format elementFormat = BaseFormatConverter.ConvertVertexElementFormat(vertexElement.VertexElementFormat);
|
||||
return new Dx10.InputElement(elementName, vertexElement.UsageIndex, elementFormat, vertexElement.Offset, 0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ConvertVertexElementFormat
|
||||
private Format ConvertVertexElementFormat(VertexElementFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case VertexElementFormat.Vector2:
|
||||
return Format.R32G32_Float;
|
||||
case VertexElementFormat.Vector3:
|
||||
return Format.R32G32B32_Float;
|
||||
case VertexElementFormat.Vector4:
|
||||
return Format.R32G32B32A32_Float;
|
||||
case VertexElementFormat.Color:
|
||||
return Format.R8G8B8A8_UNorm;
|
||||
case VertexElementFormat.Single:
|
||||
return Format.R32_Float;
|
||||
// TODO: validate
|
||||
case VertexElementFormat.Short2:
|
||||
return Format.R16G16_SInt;
|
||||
case VertexElementFormat.Short4:
|
||||
return Format.R16G16B16A16_SInt;
|
||||
}
|
||||
|
||||
throw new Exception("Can't map '" + format + "' to DXGI.Format in Dx10 CreateInputElementFromVertexElement.");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetRenderTargets
|
||||
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
|
||||
{
|
||||
@ -528,8 +439,9 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
}
|
||||
}
|
||||
|
||||
device.OutputMerger.SetRenderTargets(1, new Dx10.RenderTargetView[] { this.renderView }, this.depthStencilView);
|
||||
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
nativeDevice.OutputMerger.SetRenderTargets(1, new Dx10.RenderTargetView[] { this.renderView },
|
||||
this.depthStencilView);
|
||||
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -556,16 +468,15 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
RenderTarget2D_DX10 nativeRenderTarget = renderTarget.NativeRenderTarget as RenderTarget2D_DX10;
|
||||
|
||||
if (renderTargetView[i] != null)
|
||||
{
|
||||
renderTargetView[i].Dispose();
|
||||
}
|
||||
|
||||
renderTargetView[i] = new Dx10.RenderTargetView(device, ((Texture2D_DX10)nativeRenderTarget).NativeShaderResourceView.Resource);
|
||||
renderTargetView[i] = new Dx10.RenderTargetView(nativeDevice,
|
||||
((Texture2D_DX10)nativeRenderTarget).NativeShaderResourceView.Resource);
|
||||
}
|
||||
}
|
||||
|
||||
device.OutputMerger.SetRenderTargets(renderTargetCount, renderTargetView, this.depthStencilView);
|
||||
device.OutputMerger.SetTargets(this.depthStencilView, this.renderTargetView);
|
||||
nativeDevice.OutputMerger.SetRenderTargets(renderTargetCount, renderTargetView, this.depthStencilView);
|
||||
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderTargetView);
|
||||
|
||||
//if (renderTargets.Length == 1)
|
||||
//{
|
||||
@ -591,50 +502,15 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetBackBufferData (TODO)
|
||||
public void GetBackBufferData<T>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#region DisposeRenderView
|
||||
protected override void DisposeRenderView()
|
||||
{
|
||||
renderView.Dispose();
|
||||
renderView = null;
|
||||
|
||||
public void GetBackBufferData<T>(T[] data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ResizeBuffers
|
||||
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, swapChain.Description.Flags);
|
||||
|
||||
backBuffer = Dx10.Texture2D.FromSwapChain<Dx10.Texture2D>(swapChain, 0);
|
||||
renderView = new Dx10.RenderTargetView(device, backBuffer);
|
||||
|
||||
currentViewport = new Dx10.Viewport(0, 0, presentationParameters.BackBufferWidth,
|
||||
presentationParameters.BackBufferHeight);
|
||||
|
||||
// create the depth stencil buffer
|
||||
Format depthFormat = BaseFormatConverter.Translate(presentationParameters.DepthStencilFormat);
|
||||
if (depthFormat != Format.Unknown)
|
||||
CreateDepthStencilBuffer(depthFormat);
|
||||
}
|
||||
|
||||
WindowHelper.ResizeRenderWindow(presentationParameters);
|
||||
}
|
||||
backBuffer.Dispose();
|
||||
backBuffer = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
@ -651,11 +527,7 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
|
||||
if (swapChain != null)
|
||||
{
|
||||
renderView.Dispose();
|
||||
renderView = null;
|
||||
|
||||
backBuffer.Dispose();
|
||||
backBuffer = null;
|
||||
DisposeRenderView();
|
||||
|
||||
swapChain.Dispose();
|
||||
swapChain = null;
|
||||
|
@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpDX.D3DCompiler;
|
||||
|
||||
// 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
|
||||
|
||||
namespace ANX.RenderSystem.Windows.DX10.Helpers
|
||||
{
|
||||
internal class IncludeHandler : Include
|
||||
{
|
||||
private string directory;
|
||||
|
||||
public IDisposable Shadow { get; set; }
|
||||
|
||||
public IncludeHandler(string directory)
|
||||
{
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
public void Close(Stream stream)
|
||||
{
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
public Stream Open(IncludeType type, string fileName, Stream parentStream)
|
||||
{
|
||||
//Console.WriteLine("Including {0} file {1} from directory {2}", type.ToString(), fileName, directory);
|
||||
|
||||
return File.OpenRead(Path.Combine(directory, fileName));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -97,7 +97,7 @@ namespace ANX.RenderSystem.Windows.DX10
|
||||
#region UpdateNativeSamplerState
|
||||
private void UpdateNativeSamplerState(Dx10.Device device)
|
||||
{
|
||||
if (isDirty == true || nativeState == null)
|
||||
if (isDirty || nativeState == null)
|
||||
{
|
||||
Dispose();
|
||||
nativeState = new Dx10.SamplerState(device, ref description);
|
||||
|
@ -102,7 +102,6 @@
|
||||
<Compile Include="Effect_DX11.cs" />
|
||||
<Compile Include="FormatConverter.cs" />
|
||||
<Compile Include="GraphicsDeviceWindowsDX11.cs" />
|
||||
<Compile Include="Helpers\IncludeHandler.cs" />
|
||||
<Compile Include="IndexBuffer_DX11.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RasterizerState_DX11.cs" />
|
||||
|
@ -101,7 +101,6 @@
|
||||
<Compile Include="Effect_DX11.cs" />
|
||||
<Compile Include="FormatConverter.cs" />
|
||||
<Compile Include="GraphicsDeviceWindowsDX11.cs" />
|
||||
<Compile Include="Helpers\IncludeHandler.cs" />
|
||||
<Compile Include="IndexBuffer_DX11.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RasterizerState_DX11.cs" />
|
||||
|
@ -102,7 +102,6 @@
|
||||
<Compile Include="Effect_DX11.cs" />
|
||||
<Compile Include="FormatConverter.cs" />
|
||||
<Compile Include="GraphicsDeviceWindowsDX11.cs" />
|
||||
<Compile Include="Helpers\IncludeHandler.cs" />
|
||||
<Compile Include="IndexBuffer_DX11.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RasterizerState_DX11.cs" />
|
||||
|
@ -99,7 +99,6 @@
|
||||
<Compile Include="Effect_DX11.cs" />
|
||||
<Compile Include="FormatConverter.cs" />
|
||||
<Compile Include="GraphicsDeviceWindowsDX11.cs" />
|
||||
<Compile Include="Helpers\IncludeHandler.cs" />
|
||||
<Compile Include="IndexBuffer_DX11.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RasterizerState_DX11.cs" />
|
||||
|
@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ANX.BaseDirectX;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.RenderSystem.Windows.DX11.Helpers;
|
||||
using SharpDX.D3DCompiler;
|
||||
using Dx11 = SharpDX.Direct3D11;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
@ -13,20 +11,15 @@ using Dx11 = SharpDX.Direct3D11;
|
||||
|
||||
namespace ANX.RenderSystem.Windows.DX11
|
||||
{
|
||||
public class Effect_DX11 : INativeEffect
|
||||
public class Effect_DX11 : BaseEffect, INativeEffect
|
||||
{
|
||||
#region Private
|
||||
private Dx11.VertexShader vertexShader;
|
||||
private Dx11.PixelShader pixelShader;
|
||||
private Effect managedEffect;
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
internal Dx11.Effect NativeEffect
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal Dx11.Effect NativeEffect { get; private set; }
|
||||
|
||||
public IEnumerable<EffectTechnique> Techniques
|
||||
{
|
||||
@ -58,43 +51,20 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Effect_DX11(GraphicsDevice device, Effect setManagedEffect, Stream vertexShaderStream, Stream pixelShaderStream)
|
||||
public Effect_DX11(GraphicsDevice graphicsDevice, Effect managedEffect, Stream vertexShaderStream,
|
||||
Stream pixelShaderStream)
|
||||
: base(managedEffect)
|
||||
{
|
||||
if (setManagedEffect == null)
|
||||
throw new ArgumentNullException("managedEffect");
|
||||
managedEffect = setManagedEffect;
|
||||
|
||||
if (vertexShaderStream.CanSeek)
|
||||
vertexShaderStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var vertexShaderByteCode = ShaderBytecode.FromStream(vertexShaderStream);
|
||||
vertexShader = new Dx11.VertexShader((Dx11.Device)device.NativeDevice, vertexShaderByteCode);
|
||||
|
||||
if (pixelShaderStream.CanSeek)
|
||||
pixelShaderStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var pixelShaderByteCode = ShaderBytecode.FromStream(pixelShaderStream);
|
||||
pixelShader = new Dx11.PixelShader((Dx11.Device)device.NativeDevice, pixelShaderByteCode);
|
||||
var device = ((GraphicsDeviceWindowsDX11)graphicsDevice.NativeDevice).NativeDevice.Device;
|
||||
vertexShader = new Dx11.VertexShader(device, GetByteCode(vertexShaderStream));
|
||||
pixelShader = new Dx11.PixelShader(device, GetByteCode(pixelShaderStream));
|
||||
}
|
||||
|
||||
public Effect_DX11(GraphicsDevice device, Effect setManagedEffect, Stream effectStream)
|
||||
public Effect_DX11(GraphicsDevice graphicsDevice, Effect managedEffect, Stream effectStream)
|
||||
: base(managedEffect)
|
||||
{
|
||||
if (setManagedEffect == null)
|
||||
throw new ArgumentNullException("managedEffect");
|
||||
managedEffect = setManagedEffect;
|
||||
|
||||
if (effectStream.CanSeek)
|
||||
effectStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var effectByteCode = ShaderBytecode.FromStream(effectStream);
|
||||
NativeEffect = new Dx11.Effect(((GraphicsDeviceWindowsDX11)device.NativeDevice).NativeDevice.Device, effectByteCode);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Apply
|
||||
public void Apply(GraphicsDevice graphicsDevice)
|
||||
{
|
||||
((GraphicsDeviceWindowsDX11)graphicsDevice.NativeDevice).currentEffect = this;
|
||||
var device = ((GraphicsDeviceWindowsDX11)graphicsDevice.NativeDevice).NativeDevice.Device;
|
||||
NativeEffect = new Dx11.Effect(device, GetByteCode(effectStream));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -105,32 +75,19 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static byte[] CompileVertexShader(string effectCode, string directory = "")
|
||||
#region Apply
|
||||
public void Apply(GraphicsDevice graphicsDevice)
|
||||
{
|
||||
ShaderBytecode vertexShaderByteCode = ShaderBytecode.Compile(effectCode, "VS", "vs_4_0", ShaderFlags.None,
|
||||
EffectFlags.None, null, new IncludeHandler(directory), "unknown");
|
||||
byte[] bytecode = new byte[vertexShaderByteCode.BufferSize];
|
||||
vertexShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
|
||||
return bytecode;
|
||||
}
|
||||
|
||||
public static byte[] CompilePixelShader(string effectCode, string directory = "")
|
||||
{
|
||||
ShaderBytecode pixelShaderByteCode = ShaderBytecode.Compile(effectCode, "PS", "ps_4_0", ShaderFlags.None,
|
||||
EffectFlags.None, null, new IncludeHandler(directory), "unknown");
|
||||
byte[] bytecode = new byte[pixelShaderByteCode.BufferSize];
|
||||
pixelShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
|
||||
return bytecode;
|
||||
((GraphicsDeviceWindowsDX11)graphicsDevice.NativeDevice).currentEffect = this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompileFXShader
|
||||
public static byte[] CompileFXShader(string effectCode, string directory = "")
|
||||
{
|
||||
ShaderBytecode effectByteCode = ShaderBytecode.Compile(effectCode, "fx_5_0", ShaderFlags.None, EffectFlags.None,
|
||||
null, new IncludeHandler(directory), "unknown");
|
||||
byte[] bytecode = new byte[effectByteCode.BufferSize];
|
||||
effectByteCode.Data.Read(bytecode, 0, bytecode.Length);
|
||||
return bytecode;
|
||||
return CompileShader("fx_5_0", effectCode, directory);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
public void Dispose()
|
||||
|
@ -1,11 +1,8 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using ANX.Framework.Graphics;
|
||||
using SharpDX.Direct3D11;
|
||||
using SharpDX.Direct3D;
|
||||
using SharpDX.DXGI;
|
||||
|
||||
#endregion // Using Statements
|
||||
using Dx11 = SharpDX.Direct3D11;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -13,203 +10,207 @@ using SharpDX.DXGI;
|
||||
|
||||
namespace ANX.RenderSystem.Windows.DX11
|
||||
{
|
||||
internal class FormatConverter
|
||||
{
|
||||
public static Filter Translate(TextureFilter filter)
|
||||
{
|
||||
switch (filter)
|
||||
{
|
||||
case TextureFilter.Anisotropic:
|
||||
return Filter.Anisotropic;
|
||||
case TextureFilter.Linear:
|
||||
return Filter.MinMagMipLinear;
|
||||
case TextureFilter.LinearMipPoint:
|
||||
return Filter.MinMagMipPoint;
|
||||
case TextureFilter.MinLinearMagPointMipLinear:
|
||||
return Filter.MinLinearMagPointMipLinear;
|
||||
case TextureFilter.MinLinearMagPointMipPoint:
|
||||
return Filter.MinLinearMagMipPoint;
|
||||
case TextureFilter.MinPointMagLinearMipLinear:
|
||||
return Filter.MinPointMagMipLinear;
|
||||
case TextureFilter.MinPointMagLinearMipPoint:
|
||||
return Filter.MinPointMagLinearMipPoint;
|
||||
case TextureFilter.Point:
|
||||
return Filter.MinMagMipPoint;
|
||||
case TextureFilter.PointMipLinear:
|
||||
return Filter.MinMagPointMipLinear;
|
||||
}
|
||||
internal class FormatConverter
|
||||
{
|
||||
#region Translate (TextureFilter)
|
||||
public static Dx11.Filter Translate(TextureFilter filter)
|
||||
{
|
||||
switch (filter)
|
||||
{
|
||||
case TextureFilter.Anisotropic:
|
||||
return Dx11.Filter.Anisotropic;
|
||||
case TextureFilter.Linear:
|
||||
return Dx11.Filter.MinMagMipLinear;
|
||||
case TextureFilter.LinearMipPoint:
|
||||
return Dx11.Filter.MinMagMipPoint;
|
||||
case TextureFilter.MinLinearMagPointMipLinear:
|
||||
return Dx11.Filter.MinLinearMagPointMipLinear;
|
||||
case TextureFilter.MinLinearMagPointMipPoint:
|
||||
return Dx11.Filter.MinLinearMagMipPoint;
|
||||
case TextureFilter.MinPointMagLinearMipLinear:
|
||||
return Dx11.Filter.MinPointMagMipLinear;
|
||||
case TextureFilter.MinPointMagLinearMipPoint:
|
||||
return Dx11.Filter.MinPointMagLinearMipPoint;
|
||||
case TextureFilter.Point:
|
||||
return Dx11.Filter.MinMagMipPoint;
|
||||
case TextureFilter.PointMipLinear:
|
||||
return Dx11.Filter.MinMagPointMipLinear;
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static SharpDX.Direct3D11.TextureAddressMode Translate(ANX.Framework.Graphics.TextureAddressMode addressMode)
|
||||
{
|
||||
switch (addressMode)
|
||||
{
|
||||
case ANX.Framework.Graphics.TextureAddressMode.Clamp:
|
||||
return SharpDX.Direct3D11.TextureAddressMode.Clamp;
|
||||
case ANX.Framework.Graphics.TextureAddressMode.Mirror:
|
||||
return SharpDX.Direct3D11.TextureAddressMode.Mirror;
|
||||
case ANX.Framework.Graphics.TextureAddressMode.Wrap:
|
||||
return SharpDX.Direct3D11.TextureAddressMode.Wrap;
|
||||
}
|
||||
#region Translate (TextureAddressMode)
|
||||
public static Dx11.TextureAddressMode Translate(TextureAddressMode addressMode)
|
||||
{
|
||||
switch (addressMode)
|
||||
{
|
||||
case TextureAddressMode.Clamp:
|
||||
return Dx11.TextureAddressMode.Clamp;
|
||||
case TextureAddressMode.Mirror:
|
||||
return Dx11.TextureAddressMode.Mirror;
|
||||
case TextureAddressMode.Wrap:
|
||||
return Dx11.TextureAddressMode.Wrap;
|
||||
}
|
||||
|
||||
return SharpDX.Direct3D11.TextureAddressMode.Clamp;
|
||||
}
|
||||
return Dx11.TextureAddressMode.Clamp;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static BlendOperation Translate(BlendFunction blendFunction)
|
||||
{
|
||||
switch (blendFunction)
|
||||
{
|
||||
case BlendFunction.Add:
|
||||
return BlendOperation.Add;
|
||||
case BlendFunction.Max:
|
||||
return BlendOperation.Maximum;
|
||||
case BlendFunction.Min:
|
||||
return BlendOperation.Minimum;
|
||||
case BlendFunction.ReverseSubtract:
|
||||
return BlendOperation.ReverseSubtract;
|
||||
case BlendFunction.Subtract:
|
||||
return BlendOperation.Subtract;
|
||||
}
|
||||
#region Translate (BlendFunction)
|
||||
public static Dx11.BlendOperation Translate(BlendFunction blendFunction)
|
||||
{
|
||||
switch (blendFunction)
|
||||
{
|
||||
case BlendFunction.Add:
|
||||
return Dx11.BlendOperation.Add;
|
||||
case BlendFunction.Max:
|
||||
return Dx11.BlendOperation.Maximum;
|
||||
case BlendFunction.Min:
|
||||
return Dx11.BlendOperation.Minimum;
|
||||
case BlendFunction.ReverseSubtract:
|
||||
return Dx11.BlendOperation.ReverseSubtract;
|
||||
case BlendFunction.Subtract:
|
||||
return Dx11.BlendOperation.Subtract;
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static BlendOption Translate(Blend blend)
|
||||
{
|
||||
switch (blend)
|
||||
{
|
||||
case Blend.BlendFactor:
|
||||
return BlendOption.BlendFactor;
|
||||
case Blend.DestinationAlpha:
|
||||
return BlendOption.DestinationAlpha;
|
||||
case Blend.DestinationColor:
|
||||
return BlendOption.DestinationColor;
|
||||
case Blend.InverseBlendFactor:
|
||||
return BlendOption.InverseBlendFactor;
|
||||
case Blend.InverseDestinationAlpha:
|
||||
return BlendOption.InverseDestinationAlpha;
|
||||
case Blend.InverseDestinationColor:
|
||||
return BlendOption.InverseDestinationColor;
|
||||
case Blend.InverseSourceAlpha:
|
||||
return BlendOption.InverseSourceAlpha;
|
||||
case Blend.InverseSourceColor:
|
||||
return BlendOption.InverseSourceColor;
|
||||
case Blend.One:
|
||||
return BlendOption.One;
|
||||
case Blend.SourceAlpha:
|
||||
return BlendOption.SourceAlpha;
|
||||
case Blend.SourceAlphaSaturation:
|
||||
return BlendOption.SourceAlphaSaturate;
|
||||
case Blend.SourceColor:
|
||||
return BlendOption.SourceColor;
|
||||
case Blend.Zero:
|
||||
return BlendOption.Zero;
|
||||
}
|
||||
#region Translate (Blend)
|
||||
public static Dx11.BlendOption Translate(Blend blend)
|
||||
{
|
||||
switch (blend)
|
||||
{
|
||||
case Blend.BlendFactor:
|
||||
return Dx11.BlendOption.BlendFactor;
|
||||
case Blend.DestinationAlpha:
|
||||
return Dx11.BlendOption.DestinationAlpha;
|
||||
case Blend.DestinationColor:
|
||||
return Dx11.BlendOption.DestinationColor;
|
||||
case Blend.InverseBlendFactor:
|
||||
return Dx11.BlendOption.InverseBlendFactor;
|
||||
case Blend.InverseDestinationAlpha:
|
||||
return Dx11.BlendOption.InverseDestinationAlpha;
|
||||
case Blend.InverseDestinationColor:
|
||||
return Dx11.BlendOption.InverseDestinationColor;
|
||||
case Blend.InverseSourceAlpha:
|
||||
return Dx11.BlendOption.InverseSourceAlpha;
|
||||
case Blend.InverseSourceColor:
|
||||
return Dx11.BlendOption.InverseSourceColor;
|
||||
case Blend.One:
|
||||
return Dx11.BlendOption.One;
|
||||
case Blend.SourceAlpha:
|
||||
return Dx11.BlendOption.SourceAlpha;
|
||||
case Blend.SourceAlphaSaturation:
|
||||
return Dx11.BlendOption.SourceAlphaSaturate;
|
||||
case Blend.SourceColor:
|
||||
return Dx11.BlendOption.SourceColor;
|
||||
case Blend.Zero:
|
||||
return Dx11.BlendOption.Zero;
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static ColorWriteMaskFlags Translate(ColorWriteChannels colorWriteChannels)
|
||||
{
|
||||
ColorWriteMaskFlags mask = 0;
|
||||
#region Translate (ColorWriteChannels)
|
||||
public static Dx11.ColorWriteMaskFlags Translate(ColorWriteChannels colorWriteChannels)
|
||||
{
|
||||
Dx11.ColorWriteMaskFlags mask = 0;
|
||||
|
||||
if ((colorWriteChannels & ColorWriteChannels.All) == ColorWriteChannels.All)
|
||||
mask |= ColorWriteMaskFlags.All;
|
||||
if ((colorWriteChannels & ColorWriteChannels.All) == ColorWriteChannels.All)
|
||||
mask |= Dx11.ColorWriteMaskFlags.All;
|
||||
|
||||
if ((colorWriteChannels & ColorWriteChannels.Alpha) == ColorWriteChannels.Alpha)
|
||||
mask |= ColorWriteMaskFlags.Alpha;
|
||||
if ((colorWriteChannels & ColorWriteChannels.Alpha) == ColorWriteChannels.Alpha)
|
||||
mask |= Dx11.ColorWriteMaskFlags.Alpha;
|
||||
|
||||
if ((colorWriteChannels & ColorWriteChannels.Blue) == ColorWriteChannels.Blue)
|
||||
mask |= ColorWriteMaskFlags.Blue;
|
||||
if ((colorWriteChannels & ColorWriteChannels.Blue) == ColorWriteChannels.Blue)
|
||||
mask |= Dx11.ColorWriteMaskFlags.Blue;
|
||||
|
||||
if ((colorWriteChannels & ColorWriteChannels.Green) == ColorWriteChannels.Green)
|
||||
mask |= ColorWriteMaskFlags.Green;
|
||||
if ((colorWriteChannels & ColorWriteChannels.Green) == ColorWriteChannels.Green)
|
||||
mask |= Dx11.ColorWriteMaskFlags.Green;
|
||||
|
||||
if ((colorWriteChannels & ColorWriteChannels.Red) == ColorWriteChannels.Red)
|
||||
mask |= ColorWriteMaskFlags.Red;
|
||||
if ((colorWriteChannels & ColorWriteChannels.Red) == ColorWriteChannels.Red)
|
||||
mask |= Dx11.ColorWriteMaskFlags.Red;
|
||||
|
||||
return mask;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static SharpDX.Direct3D11.StencilOperation Translate(ANX.Framework.Graphics.StencilOperation stencilOperation)
|
||||
{
|
||||
switch (stencilOperation)
|
||||
{
|
||||
case ANX.Framework.Graphics.StencilOperation.Decrement:
|
||||
return SharpDX.Direct3D11.StencilOperation.Decrement;
|
||||
case ANX.Framework.Graphics.StencilOperation.DecrementSaturation:
|
||||
return SharpDX.Direct3D11.StencilOperation.DecrementAndClamp;
|
||||
case ANX.Framework.Graphics.StencilOperation.Increment:
|
||||
return SharpDX.Direct3D11.StencilOperation.Increment;
|
||||
case ANX.Framework.Graphics.StencilOperation.IncrementSaturation:
|
||||
return SharpDX.Direct3D11.StencilOperation.IncrementAndClamp;
|
||||
case ANX.Framework.Graphics.StencilOperation.Invert:
|
||||
return SharpDX.Direct3D11.StencilOperation.Invert;
|
||||
case ANX.Framework.Graphics.StencilOperation.Keep:
|
||||
return SharpDX.Direct3D11.StencilOperation.Keep;
|
||||
case ANX.Framework.Graphics.StencilOperation.Replace:
|
||||
return SharpDX.Direct3D11.StencilOperation.Replace;
|
||||
case ANX.Framework.Graphics.StencilOperation.Zero:
|
||||
return SharpDX.Direct3D11.StencilOperation.Zero;
|
||||
}
|
||||
#region Translate (StencilOperation)
|
||||
public static Dx11.StencilOperation Translate(StencilOperation stencilOperation)
|
||||
{
|
||||
switch (stencilOperation)
|
||||
{
|
||||
case StencilOperation.Decrement:
|
||||
return Dx11.StencilOperation.Decrement;
|
||||
case StencilOperation.DecrementSaturation:
|
||||
return Dx11.StencilOperation.DecrementAndClamp;
|
||||
case StencilOperation.Increment:
|
||||
return Dx11.StencilOperation.Increment;
|
||||
case StencilOperation.IncrementSaturation:
|
||||
return Dx11.StencilOperation.IncrementAndClamp;
|
||||
case StencilOperation.Invert:
|
||||
return Dx11.StencilOperation.Invert;
|
||||
case StencilOperation.Keep:
|
||||
return Dx11.StencilOperation.Keep;
|
||||
case StencilOperation.Replace:
|
||||
return Dx11.StencilOperation.Replace;
|
||||
case StencilOperation.Zero:
|
||||
return Dx11.StencilOperation.Zero;
|
||||
}
|
||||
|
||||
throw new NotImplementedException("unknown StencilOperation");
|
||||
}
|
||||
throw new NotImplementedException("unknown StencilOperation");
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static Comparison Translate(ANX.Framework.Graphics.CompareFunction compareFunction)
|
||||
{
|
||||
switch (compareFunction)
|
||||
{
|
||||
case ANX.Framework.Graphics.CompareFunction.Always:
|
||||
return Comparison.Always;
|
||||
case ANX.Framework.Graphics.CompareFunction.Equal:
|
||||
return Comparison.Equal;
|
||||
case ANX.Framework.Graphics.CompareFunction.Greater:
|
||||
return Comparison.Greater;
|
||||
case ANX.Framework.Graphics.CompareFunction.GreaterEqual:
|
||||
return Comparison.GreaterEqual;
|
||||
case ANX.Framework.Graphics.CompareFunction.Less:
|
||||
return Comparison.Less;
|
||||
case ANX.Framework.Graphics.CompareFunction.LessEqual:
|
||||
return Comparison.LessEqual;
|
||||
case ANX.Framework.Graphics.CompareFunction.Never:
|
||||
return Comparison.Never;
|
||||
case ANX.Framework.Graphics.CompareFunction.NotEqual:
|
||||
return Comparison.NotEqual;
|
||||
}
|
||||
#region Translate (CompareFunction)
|
||||
public static Dx11.Comparison Translate(CompareFunction compareFunction)
|
||||
{
|
||||
switch (compareFunction)
|
||||
{
|
||||
case CompareFunction.Always:
|
||||
return Dx11.Comparison.Always;
|
||||
case CompareFunction.Equal:
|
||||
return Dx11.Comparison.Equal;
|
||||
case CompareFunction.Greater:
|
||||
return Dx11.Comparison.Greater;
|
||||
case CompareFunction.GreaterEqual:
|
||||
return Dx11.Comparison.GreaterEqual;
|
||||
case CompareFunction.Less:
|
||||
return Dx11.Comparison.Less;
|
||||
case CompareFunction.LessEqual:
|
||||
return Dx11.Comparison.LessEqual;
|
||||
case CompareFunction.Never:
|
||||
return Dx11.Comparison.Never;
|
||||
case CompareFunction.NotEqual:
|
||||
return Dx11.Comparison.NotEqual;
|
||||
}
|
||||
|
||||
throw new NotImplementedException("unknown CompareFunction");
|
||||
}
|
||||
throw new NotImplementedException("unknown CompareFunction");
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static SharpDX.Direct3D11.CullMode Translate(ANX.Framework.Graphics.CullMode cullMode)
|
||||
{
|
||||
if (cullMode == ANX.Framework.Graphics.CullMode.CullClockwiseFace)
|
||||
{
|
||||
return SharpDX.Direct3D11.CullMode.Front;
|
||||
}
|
||||
else if (cullMode == ANX.Framework.Graphics.CullMode.CullCounterClockwiseFace)
|
||||
{
|
||||
return SharpDX.Direct3D11.CullMode.Back;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SharpDX.Direct3D11.CullMode.None;
|
||||
}
|
||||
}
|
||||
#region Translate (CullMode)
|
||||
public static Dx11.CullMode Translate(CullMode cullMode)
|
||||
{
|
||||
if (cullMode == CullMode.CullClockwiseFace)
|
||||
return Dx11.CullMode.Front;
|
||||
else if (cullMode == CullMode.CullCounterClockwiseFace)
|
||||
return Dx11.CullMode.Back;
|
||||
else
|
||||
return Dx11.CullMode.None;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static SharpDX.Direct3D11.FillMode Translate(ANX.Framework.Graphics.FillMode fillMode)
|
||||
{
|
||||
if (fillMode == ANX.Framework.Graphics.FillMode.WireFrame)
|
||||
{
|
||||
return SharpDX.Direct3D11.FillMode.Wireframe;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SharpDX.Direct3D11.FillMode.Solid;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#region Translate (FillMode)
|
||||
public static Dx11.FillMode Translate(FillMode fillMode)
|
||||
{
|
||||
return fillMode == FillMode.WireFrame ? Dx11.FillMode.Wireframe : Dx11.FillMode.Solid;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
//#define DIRECTX_DEBUG_LAYER
|
||||
using System;
|
||||
using ANX.BaseDirectX;
|
||||
using ANX.Framework;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.RenderSystem.Windows.DX11.Helpers;
|
||||
using SharpDX.D3DCompiler;
|
||||
using SharpDX.Direct3D;
|
||||
using SharpDX.Direct3D11;
|
||||
using SharpDX.DXGI;
|
||||
using Device = SharpDX.Direct3D11.Device;
|
||||
using ANX.BaseDirectX;
|
||||
|
||||
// This file is part of the ANX.Framework created by the
|
||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
||||
@ -17,90 +15,61 @@ using ANX.BaseDirectX;
|
||||
|
||||
namespace ANX.RenderSystem.Windows.DX11
|
||||
{
|
||||
public class GraphicsDeviceWindowsDX11 : INativeGraphicsDevice
|
||||
public class GraphicsDeviceWindowsDX11 : BaseGraphicsDevice<DeviceContext>, INativeGraphicsDevice
|
||||
{
|
||||
#region Constants
|
||||
private const float ColorMultiplier = 1f / 255f;
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
private DeviceContext deviceContext;
|
||||
private SwapChain swapChain;
|
||||
private RenderTargetView renderView;
|
||||
private RenderTargetView[] renderTargetView = new RenderTargetView[1];
|
||||
private DepthStencilView depthStencilView;
|
||||
private SharpDX.Direct3D11.Texture2D depthStencilBuffer;
|
||||
private SharpDX.Direct3D11.Texture2D backBuffer;
|
||||
internal Effect_DX11 currentEffect;
|
||||
private VertexBuffer currentVertexBuffer;
|
||||
private IndexBuffer currentIndexBuffer;
|
||||
private SharpDX.Direct3D11.Viewport currentViewport;
|
||||
private uint lastClearColor;
|
||||
private SharpDX.Color4 clearColor;
|
||||
#endregion
|
||||
|
||||
internal DeviceContext NativeDevice
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.deviceContext;
|
||||
}
|
||||
}
|
||||
|
||||
public bool VSync { get; set; }
|
||||
|
||||
public GraphicsDeviceWindowsDX11(PresentationParameters presentationParameters)
|
||||
#region Constructor
|
||||
public GraphicsDeviceWindowsDX11(PresentationParameters presentationParameters)
|
||||
: base(presentationParameters)
|
||||
{
|
||||
VSync = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
// SwapChain description
|
||||
var desc = new SwapChainDescription()
|
||||
{
|
||||
BufferCount = 1,
|
||||
#region CreateDevice
|
||||
protected override void CreateDevice(PresentationParameters presentationParameters)
|
||||
{
|
||||
var desc = new SwapChainDescription()
|
||||
{
|
||||
BufferCount = 1,
|
||||
ModeDescription = new ModeDescription(presentationParameters.BackBufferWidth,
|
||||
presentationParameters.BackBufferHeight, new Rational(60, 1),
|
||||
BaseFormatConverter.Translate(presentationParameters.BackBufferFormat)),
|
||||
IsWindowed = true,
|
||||
OutputHandle = presentationParameters.DeviceWindowHandle,
|
||||
SampleDescription = new SampleDescription(1, 0),
|
||||
SwapEffect = SwapEffect.Discard,
|
||||
Usage = Usage.RenderTargetOutput
|
||||
};
|
||||
IsWindowed = true,
|
||||
OutputHandle = presentationParameters.DeviceWindowHandle,
|
||||
SampleDescription = new SampleDescription(1, 0),
|
||||
SwapEffect = SwapEffect.Discard,
|
||||
Usage = Usage.RenderTargetOutput
|
||||
};
|
||||
|
||||
// Create Device and SwapChain
|
||||
Device dxDevice;
|
||||
// Create Device and SwapChain
|
||||
Device dxDevice;
|
||||
|
||||
#if DIRECTX_DEBUG_LAYER
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb205068(v=vs.85).aspx
|
||||
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out dxDevice, out swapChain);
|
||||
#else
|
||||
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out dxDevice, out swapChain);
|
||||
#endif
|
||||
this.deviceContext = dxDevice.ImmediateContext;
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb205068(v=vs.85).aspx
|
||||
var flags = IsDebugMode ? DeviceCreationFlags.Debug : DeviceCreationFlags.None;
|
||||
Device.CreateWithSwapChain(DriverType.Hardware, flags, desc, out dxDevice, out swapChain);
|
||||
nativeDevice = dxDevice.ImmediateContext;
|
||||
}
|
||||
#endregion
|
||||
|
||||
// Ignore all windows events
|
||||
Factory factory = swapChain.GetParent<Factory>();
|
||||
factory.MakeWindowAssociation(presentationParameters.DeviceWindowHandle, WindowAssociationFlags.IgnoreAll);
|
||||
#region CreateRenderView
|
||||
protected override void CreateRenderView()
|
||||
{
|
||||
backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0);
|
||||
renderView = new RenderTargetView(nativeDevice.Device, backBuffer);
|
||||
}
|
||||
#endregion
|
||||
|
||||
WindowHelper.ResizeRenderWindow(presentationParameters);
|
||||
|
||||
// New RenderTargetView from the backbuffer
|
||||
backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0);
|
||||
renderView = new RenderTargetView(deviceContext.Device, backBuffer);
|
||||
|
||||
currentViewport = new SharpDX.Direct3D11.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
|
||||
|
||||
//
|
||||
// create the depth stencil buffer
|
||||
//
|
||||
Format depthFormat = BaseFormatConverter.Translate(presentationParameters.DepthStencilFormat);
|
||||
if (depthFormat != Format.Unknown)
|
||||
{
|
||||
CreateDepthStencilBuffer(depthFormat);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateDepthStencilBuffer(Format depthFormat)
|
||||
#region CreateDepthStencilBuffer
|
||||
protected override void CreateDepthStencilBuffer(Format depthFormat)
|
||||
{
|
||||
if (this.depthStencilBuffer != null &&
|
||||
this.depthStencilBuffer.Description.Format == depthFormat &&
|
||||
@ -147,30 +116,21 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
CpuAccessFlags = CpuAccessFlags.None,
|
||||
OptionFlags = ResourceOptionFlags.None
|
||||
};
|
||||
this.depthStencilBuffer = new SharpDX.Direct3D11.Texture2D(deviceContext.Device, depthStencilTextureDesc);
|
||||
this.depthStencilBuffer = new SharpDX.Direct3D11.Texture2D(nativeDevice.Device, depthStencilTextureDesc);
|
||||
|
||||
this.depthStencilView = new DepthStencilView(deviceContext.Device, this.depthStencilBuffer);
|
||||
this.depthStencilView = new DepthStencilView(nativeDevice.Device, this.depthStencilBuffer);
|
||||
|
||||
Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil, ANX.Framework.Vector4.Zero, 1.0f, 0); //TODO: this workaround is working but maybe not the best solution to issue #472
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Clear
|
||||
public void Clear(ref Color color)
|
||||
#region Clear
|
||||
public void Clear(ref Color color)
|
||||
{
|
||||
uint newClearColor = color.PackedValue;
|
||||
if (lastClearColor != newClearColor)
|
||||
{
|
||||
lastClearColor = newClearColor;
|
||||
clearColor.Red = color.R * ColorMultiplier;
|
||||
clearColor.Green = color.G * ColorMultiplier;
|
||||
clearColor.Blue = color.B * ColorMultiplier;
|
||||
clearColor.Alpha = color.A * ColorMultiplier;
|
||||
}
|
||||
UpdateClearColorIfNeeded(ref color);
|
||||
|
||||
if (this.renderTargetView[0] == null)
|
||||
{
|
||||
this.deviceContext.ClearRenderTargetView(this.renderView, this.clearColor);
|
||||
}
|
||||
nativeDevice.ClearRenderTargetView(this.renderView, this.clearColor);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < this.renderTargetView.Length; i++)
|
||||
@ -180,7 +140,7 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
break;
|
||||
}
|
||||
|
||||
this.deviceContext.ClearRenderTargetView(this.renderTargetView[i], this.clearColor);
|
||||
nativeDevice.ClearRenderTargetView(this.renderTargetView[i], this.clearColor);
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,19 +159,15 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
this.lastClearColor = 0;
|
||||
|
||||
if (this.renderTargetView[0] == null)
|
||||
{
|
||||
this.deviceContext.ClearRenderTargetView(this.renderView, this.clearColor);
|
||||
}
|
||||
nativeDevice.ClearRenderTargetView(this.renderView, this.clearColor);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < this.renderTargetView.Length; i++)
|
||||
{
|
||||
if (this.renderTargetView[i] == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
this.deviceContext.ClearRenderTargetView(this.renderTargetView[i], this.clearColor);
|
||||
nativeDevice.ClearRenderTargetView(this.renderTargetView[i], this.clearColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -221,15 +177,17 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
if ((options | ClearOptions.Stencil | ClearOptions.DepthBuffer) == options)
|
||||
{
|
||||
// Clear the stencil buffer
|
||||
deviceContext.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, depth, (byte)stencil);
|
||||
nativeDevice.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Depth |
|
||||
DepthStencilClearFlags.Stencil, depth, (byte)stencil);
|
||||
}
|
||||
else if ((options | ClearOptions.Stencil) == options)
|
||||
{
|
||||
deviceContext.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Stencil, depth, (byte)stencil);
|
||||
nativeDevice.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Stencil, depth,
|
||||
(byte)stencil);
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceContext.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Depth, depth, (byte)stencil);
|
||||
nativeDevice.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Depth, depth, (byte)stencil);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -243,7 +201,7 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DrawPrimitives & DrawIndexedPrimitives
|
||||
#region DrawIndexedPrimitives
|
||||
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex,
|
||||
int numVertices, int startIndex, int primitiveCount)
|
||||
{
|
||||
@ -255,21 +213,24 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
var layout = SetupInputLayout(passSignature);
|
||||
|
||||
// Prepare All the stages
|
||||
deviceContext.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
deviceContext.Rasterizer.SetViewports(currentViewport);
|
||||
nativeDevice.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
nativeDevice.Rasterizer.SetViewports(currentViewport);
|
||||
|
||||
deviceContext.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
|
||||
for (int i = 0; i < technique.Description.PassCount; ++i)
|
||||
{
|
||||
pass.Apply(deviceContext);
|
||||
deviceContext.DrawIndexed(BaseFormatConverter.CalculateVertexCount(primitiveType, primitiveCount), startIndex, baseVertex);
|
||||
pass.Apply(nativeDevice);
|
||||
nativeDevice.DrawIndexed(BaseFormatConverter.CalculateVertexCount(primitiveType, primitiveCount), startIndex,
|
||||
baseVertex);
|
||||
}
|
||||
|
||||
layout.Dispose();
|
||||
layout = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DrawPrimitives
|
||||
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount)
|
||||
{
|
||||
SharpDX.Direct3D11.EffectPass pass; SharpDX.Direct3D11.EffectTechnique technique; ShaderBytecode passSignature;
|
||||
@ -278,27 +239,26 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
var layout = SetupInputLayout(passSignature);
|
||||
|
||||
// Prepare All the stages
|
||||
deviceContext.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
deviceContext.Rasterizer.SetViewports(currentViewport);
|
||||
nativeDevice.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
nativeDevice.Rasterizer.SetViewports(currentViewport);
|
||||
|
||||
deviceContext.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
|
||||
for (int i = 0; i < technique.Description.PassCount; ++i)
|
||||
{
|
||||
pass.Apply(deviceContext);
|
||||
deviceContext.Draw(primitiveCount, vertexOffset);
|
||||
pass.Apply(nativeDevice);
|
||||
nativeDevice.Draw(primitiveCount, vertexOffset);
|
||||
}
|
||||
|
||||
layout.Dispose();
|
||||
layout = null;
|
||||
}
|
||||
|
||||
#endregion // DrawPrimitives & DrawIndexedPrimitives
|
||||
#endregion
|
||||
|
||||
#region DrawInstancedPrimitives
|
||||
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount)
|
||||
{
|
||||
deviceContext.DrawIndexedInstanced(numVertices, instanceCount, startIndex, baseVertex, 0);
|
||||
nativeDevice.DrawIndexedInstanced(numVertices, instanceCount, startIndex, baseVertex, 0);
|
||||
}
|
||||
|
||||
#endregion // DrawInstancedPrimitives
|
||||
@ -310,15 +270,15 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
{
|
||||
int vertexCount = vertexData.Length;
|
||||
int indexCount = indexData.Length;
|
||||
var vb11 = new VertexBuffer_DX11(this.deviceContext.Device, vertexDeclaration, vertexCount, BufferUsage.None);
|
||||
var vb11 = new VertexBuffer_DX11(nativeDevice.Device, vertexDeclaration, vertexCount, BufferUsage.None);
|
||||
vb11.SetData<T>(null, vertexData);
|
||||
|
||||
var nativeVertexBufferBindings = new SharpDX.Direct3D11.VertexBufferBinding(vb11.NativeBuffer,
|
||||
vertexDeclaration.VertexStride, 0);
|
||||
|
||||
deviceContext.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
|
||||
IndexBuffer_DX11 idx10 = new IndexBuffer_DX11(this.deviceContext.Device, indexFormat, indexCount, BufferUsage.None);
|
||||
IndexBuffer_DX11 idx10 = new IndexBuffer_DX11(nativeDevice.Device, indexFormat, indexCount, BufferUsage.None);
|
||||
if (indexData.GetType() == typeof(Int16[]))
|
||||
idx10.SetData<short>(null, (short[])indexData);
|
||||
else
|
||||
@ -333,29 +293,29 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
|
||||
{
|
||||
int vertexCount = vertexData.Length;
|
||||
VertexBuffer_DX11 vb11 = new VertexBuffer_DX11(this.deviceContext.Device, vertexDeclaration, vertexCount, BufferUsage.None);
|
||||
VertexBuffer_DX11 vb11 = new VertexBuffer_DX11(nativeDevice.Device, vertexDeclaration, vertexCount, BufferUsage.None);
|
||||
vb11.SetData<T>(null, vertexData);
|
||||
|
||||
SharpDX.Direct3D11.VertexBufferBinding nativeVertexBufferBindings = new SharpDX.Direct3D11.VertexBufferBinding(vb11.NativeBuffer, vertexDeclaration.VertexStride, 0);
|
||||
|
||||
deviceContext.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
|
||||
SharpDX.Direct3D11.EffectPass pass; SharpDX.Direct3D11.EffectTechnique technique; ShaderBytecode passSignature;
|
||||
SetupEffectForDraw(out pass, out technique, out passSignature);
|
||||
|
||||
var layout = CreateInputLayout(deviceContext.Device, passSignature, vertexDeclaration);
|
||||
var layout = CreateInputLayout(nativeDevice.Device, passSignature, vertexDeclaration);
|
||||
|
||||
deviceContext.InputAssembler.InputLayout = layout;
|
||||
nativeDevice.InputAssembler.InputLayout = layout;
|
||||
// Prepare All the stages
|
||||
deviceContext.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
deviceContext.Rasterizer.SetViewports(currentViewport);
|
||||
nativeDevice.InputAssembler.PrimitiveTopology = BaseFormatConverter.Translate(primitiveType);
|
||||
nativeDevice.Rasterizer.SetViewports(currentViewport);
|
||||
|
||||
//device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
|
||||
for (int i = 0; i < technique.Description.PassCount; ++i)
|
||||
{
|
||||
pass.Apply(deviceContext);
|
||||
deviceContext.Draw(primitiveCount, vertexOffset);
|
||||
pass.Apply(nativeDevice);
|
||||
nativeDevice.Draw(primitiveCount, vertexOffset);
|
||||
}
|
||||
|
||||
layout.Dispose();
|
||||
@ -364,7 +324,9 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
|
||||
#endregion // DrawUserPrimitives<T>
|
||||
|
||||
private void SetupEffectForDraw(out SharpDX.Direct3D11.EffectPass pass, out SharpDX.Direct3D11.EffectTechnique technique, out ShaderBytecode passSignature)
|
||||
#region SetupEffectForDraw
|
||||
private void SetupEffectForDraw(out SharpDX.Direct3D11.EffectPass pass, out SharpDX.Direct3D11.EffectTechnique technique,
|
||||
out ShaderBytecode passSignature)
|
||||
{
|
||||
// get the current effect
|
||||
//TODO: check for null and throw exception
|
||||
@ -377,66 +339,53 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
pass = technique.GetPassByIndex(0);
|
||||
passSignature = pass.Description.Signature;
|
||||
}
|
||||
#endregion
|
||||
|
||||
private InputLayout SetupInputLayout(ShaderBytecode passSignature)
|
||||
#region SetupInputLayout
|
||||
private InputLayout SetupInputLayout(ShaderBytecode passSignature)
|
||||
{
|
||||
// get the VertexDeclaration from current VertexBuffer to create input layout for the input assembler
|
||||
//TODO: check for null and throw exception
|
||||
VertexDeclaration vertexDeclaration = currentVertexBuffer.VertexDeclaration;
|
||||
var layout = CreateInputLayout(deviceContext.Device, passSignature, vertexDeclaration);
|
||||
var layout = CreateInputLayout(nativeDevice.Device, passSignature, vertexDeclaration);
|
||||
|
||||
deviceContext.InputAssembler.InputLayout = layout;
|
||||
nativeDevice.InputAssembler.InputLayout = layout;
|
||||
return layout;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void SetIndexBuffer(IndexBuffer indexBuffer)
|
||||
#region SetIndexBuffer
|
||||
public void SetIndexBuffer(IndexBuffer indexBuffer)
|
||||
{
|
||||
if (indexBuffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("indexBuffer");
|
||||
}
|
||||
|
||||
this.currentIndexBuffer = indexBuffer;
|
||||
|
||||
IndexBuffer_DX11 nativeIndexBuffer = indexBuffer.NativeIndexBuffer as IndexBuffer_DX11;
|
||||
|
||||
if (nativeIndexBuffer != null)
|
||||
{
|
||||
deviceContext.InputAssembler.SetIndexBuffer(nativeIndexBuffer.NativeBuffer,
|
||||
nativeDevice.InputAssembler.SetIndexBuffer(nativeIndexBuffer.NativeBuffer,
|
||||
BaseFormatConverter.Translate(indexBuffer.IndexElementSize), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("couldn't fetch native DirectX10 IndexBuffer");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#if XNAEXT
|
||||
public void SetConstantBuffer(int slot, ANX.Framework.Graphics.ConstantBuffer constantBuffer)
|
||||
{
|
||||
if (constantBuffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("constantBuffer");
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endif
|
||||
|
||||
public void SetVertexBuffers(ANX.Framework.Graphics.VertexBufferBinding[] vertexBuffers)
|
||||
#region SetVertexBuffers
|
||||
public void SetVertexBuffers(ANX.Framework.Graphics.VertexBufferBinding[] vertexBuffers)
|
||||
{
|
||||
if (vertexBuffers == null)
|
||||
{
|
||||
throw new ArgumentNullException("vertexBuffers");
|
||||
}
|
||||
|
||||
this.currentVertexBuffer = vertexBuffers[0].VertexBuffer; //TODO: hmmmmm, not nice :-)
|
||||
|
||||
SharpDX.Direct3D11.VertexBufferBinding[] nativeVertexBufferBindings = new SharpDX.Direct3D11.VertexBufferBinding[vertexBuffers.Length];
|
||||
var nativeVertexBufferBindings = new SharpDX.Direct3D11.VertexBufferBinding[vertexBuffers.Length];
|
||||
for (int i = 0; i < vertexBuffers.Length; i++)
|
||||
{
|
||||
ANX.Framework.Graphics.VertexBufferBinding anxVertexBufferBinding = vertexBuffers[i];
|
||||
VertexBuffer_DX11 nativeVertexBuffer = anxVertexBufferBinding.VertexBuffer.NativeVertexBuffer as VertexBuffer_DX11;
|
||||
var nativeVertexBuffer = anxVertexBufferBinding.VertexBuffer.NativeVertexBuffer as VertexBuffer_DX11;
|
||||
|
||||
if (nativeVertexBuffer != null)
|
||||
{
|
||||
@ -448,60 +397,43 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
}
|
||||
}
|
||||
|
||||
deviceContext.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
}
|
||||
nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void SetViewport(ANX.Framework.Graphics.Viewport viewport)
|
||||
{
|
||||
this.currentViewport = new SharpDX.Direct3D11.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height, viewport.MinDepth, viewport.MaxDepth);
|
||||
}
|
||||
#region SetViewport
|
||||
protected override void SetViewport(int x, int y, int width, int height, float minDepth, float maxDepth)
|
||||
{
|
||||
currentViewport = new SharpDX.Direct3D11.Viewport(x, y, width, height, minDepth, maxDepth);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// This method creates a InputLayout which is needed by DirectX 10 for rendering primitives. The VertexDeclaration of ANX/XNA needs to be mapped
|
||||
/// to the DirectX 10 types. This is what this method is for.
|
||||
/// </summary>
|
||||
private InputLayout CreateInputLayout(Device device, ShaderBytecode passSignature, VertexDeclaration vertexDeclaration)
|
||||
#region CreateInputLayout
|
||||
private InputLayout CreateInputLayout(Device device, ShaderBytecode passSignature, VertexDeclaration vertexDeclaration)
|
||||
{
|
||||
VertexElement[] vertexElements = vertexDeclaration.GetVertexElements();
|
||||
int elementCount = vertexElements.Length;
|
||||
InputElement[] inputElements = new InputElement[elementCount];
|
||||
|
||||
for (int i = 0; i < elementCount; i++)
|
||||
{
|
||||
inputElements[i] = CreateInputElementFromVertexElement(vertexElements[i]);
|
||||
}
|
||||
|
||||
// Layout from VertexShader input signature
|
||||
return new InputLayout(device, passSignature, inputElements);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private InputElement CreateInputElementFromVertexElement(VertexElement vertexElement)
|
||||
#region CreateInputElementFromVertexElement
|
||||
private InputElement CreateInputElementFromVertexElement(VertexElement vertexElement)
|
||||
{
|
||||
string elementName = BaseFormatConverter.Translate(ref vertexElement);
|
||||
Format elementFormat = BaseFormatConverter.ConvertVertexElementFormat(vertexElement.VertexElementFormat);
|
||||
return new InputElement(elementName, vertexElement.UsageIndex, elementFormat, vertexElement.Offset, 0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
Format elementFormat;
|
||||
switch (vertexElement.VertexElementFormat)
|
||||
{
|
||||
case VertexElementFormat.Vector2:
|
||||
elementFormat = Format.R32G32_Float;
|
||||
break;
|
||||
case VertexElementFormat.Vector3:
|
||||
elementFormat = Format.R32G32B32_Float;
|
||||
break;
|
||||
case VertexElementFormat.Vector4:
|
||||
elementFormat = Format.R32G32B32A32_Float;
|
||||
break;
|
||||
case VertexElementFormat.Color:
|
||||
elementFormat = Format.R8G8B8A8_UNorm;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("can't map '" + vertexElement.VertexElementFormat.ToString() + "' to DXGI.Format in DirectX10 RenderSystem CreateInputElementFromVertexElement");
|
||||
}
|
||||
|
||||
return new InputElement(elementName, vertexElement.UsageIndex, elementFormat, vertexElement.Offset, 0);
|
||||
}
|
||||
|
||||
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
|
||||
#region SetRenderTargets
|
||||
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
|
||||
{
|
||||
if (renderTargets == null)
|
||||
{
|
||||
@ -516,7 +448,7 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
}
|
||||
|
||||
//deviceContext.OutputMerger.SetRenderTargets(1, new RenderTargetView[] { this.renderView }, this.depthStencilView);
|
||||
deviceContext.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -547,60 +479,30 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
renderTargetView[i].Dispose();
|
||||
}
|
||||
|
||||
renderTargetView[i] = new RenderTargetView(deviceContext.Device, ((Texture2D_DX11)nativeRenderTarget).NativeShaderResourceView.Resource);
|
||||
renderTargetView[i] = new RenderTargetView(nativeDevice.Device,
|
||||
((Texture2D_DX11)nativeRenderTarget).NativeShaderResourceView.Resource);
|
||||
}
|
||||
}
|
||||
|
||||
//deviceContext.OutputMerger.SetRenderTargets(renderTargetCount, renderTargetView, this.depthStencilView);
|
||||
deviceContext.OutputMerger.SetTargets(this.depthStencilView, this.renderTargetView);
|
||||
nativeDevice.OutputMerger.SetTargets(this.depthStencilView, this.renderTargetView);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void GetBackBufferData<T>(ANX.Framework.Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#region DisposeRenderView
|
||||
protected override void DisposeRenderView()
|
||||
{
|
||||
renderView.Dispose();
|
||||
renderView = null;
|
||||
|
||||
public void GetBackBufferData<T>(T[] data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
backBuffer.Dispose();
|
||||
backBuffer = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
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, swapChain.Description.Flags);
|
||||
|
||||
backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0);
|
||||
renderView = new RenderTargetView(deviceContext.Device, backBuffer);
|
||||
|
||||
currentViewport = new SharpDX.Direct3D11.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
|
||||
|
||||
//
|
||||
// create the depth stencil buffer
|
||||
//
|
||||
Format depthFormat = BaseFormatConverter.Translate(presentationParameters.DepthStencilFormat);
|
||||
if (depthFormat != Format.Unknown)
|
||||
{
|
||||
CreateDepthStencilBuffer(depthFormat);
|
||||
}
|
||||
}
|
||||
|
||||
WindowHelper.ResizeRenderWindow(presentationParameters);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
#region Dispose
|
||||
public void Dispose()
|
||||
{
|
||||
for (int i = 0; i < renderTargetView.Length; i++)
|
||||
{
|
||||
@ -613,11 +515,7 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
|
||||
if (swapChain != null)
|
||||
{
|
||||
renderView.Dispose();
|
||||
renderView = null;
|
||||
|
||||
backBuffer.Dispose();
|
||||
backBuffer = null;
|
||||
DisposeRenderView();
|
||||
|
||||
swapChain.Dispose();
|
||||
swapChain = null;
|
||||
@ -634,5 +532,6 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
|
||||
//TODO: dispose everything else
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,10 @@
|
||||
<Project>{6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35}</Project>
|
||||
<Name>ANX.Framework</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\RenderSystems\ANX.BaseDirectX\ANX.BaseDirectX.csproj">
|
||||
<Project>{A4D3AD34-E49C-4142-8620-2AFF44ED6719}</Project>
|
||||
<Name>ANX.BaseDirectX</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\RenderSystems\ANX.Framework.Windows.DX10\ANX.RenderSystem.Windows.DX10.csproj">
|
||||
<Project>{5BE49183-2F6F-4527-AC90-D816911FCF90}</Project>
|
||||
<Name>ANX.RenderSystem.Windows.DX10</Name>
|
||||
|
Loading…
x
Reference in New Issue
Block a user