added DX11 stock shaders to build system

updated StockShaderCodeGenerator (sscg) to support DX11 shaders
updated the DX11 RenderSystem to be on par with the DX10 RenderSystem (it is currently not working completly because of some issues with shaders)
This commit is contained in:
Glatzemann 2011-12-14 11:49:04 +00:00
parent 5eaba32696
commit e1076f8984
37 changed files with 4311 additions and 555 deletions

View File

@ -117,6 +117,17 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ANX.RenderSystem.Windows.Me
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecordingSample", "RecordingSample\RecordingSample\RecordingSample.csproj", "{160150D5-38E6-482D-97F5-2624F322A854}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DX11", "DX11", "{6285F3EF-07DB-49C9-8CDE-A9092789FE4F}"
ProjectSection(SolutionItems) = preProject
shader\DX11\AlphaTest.fx = shader\DX11\AlphaTest.fx
shader\DX11\BasicEffect.fx = shader\DX11\BasicEffect.fx
shader\DX11\build.xml = shader\DX11\build.xml
shader\DX11\DualTexture.fx = shader\DX11\DualTexture.fx
shader\DX11\EnvironmentMap.fx = shader\DX11\EnvironmentMap.fx
shader\DX11\Skinned.fx = shader\DX11\Skinned.fx
shader\DX11\SpriteBatch.fx = shader\DX11\SpriteBatch.fx
EndProjectSection
EndProject
Global
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
@ -442,5 +453,6 @@ Global
{CCB4679D-11AF-4EC6-AAA4-36619FCE70FA} = {60824BDB-AC8A-42ED-9B79-111FB44669FF}
{E4FFD875-95FC-48F2-8B6D-8483D0B71666} = {60824BDB-AC8A-42ED-9B79-111FB44669FF}
{BD648BB8-EF28-453C-B4F5-EE3C93EB4DAF} = {60824BDB-AC8A-42ED-9B79-111FB44669FF}
{6285F3EF-07DB-49C9-8CDE-A9092789FE4F} = {60824BDB-AC8A-42ED-9B79-111FB44669FF}
EndGlobalSection
EndGlobal

View File

@ -1,9 +1,61 @@
using System;
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D10;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using ANX.Framework;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.Framework.Windows.DX10
{

View File

@ -65,18 +65,35 @@
<HintPath>..\..\lib\SharpDX\Bin\SharpDX.DXGI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="BlendState_DX11.cs" />
<Compile Include="Creator.cs" />
<Compile Include="DepthStencilState_DX11.cs" />
<Compile Include="EffectParameter_DX11.cs" />
<Compile Include="EffectPass_DX11.cs" />
<Compile Include="EffectTechnique_DX11.cs" />
<Compile Include="Effect_DX11.cs" />
<Compile Include="FormatConverter.cs" />
<Compile Include="GraphicsDeviceWindowsDX11.cs" />
<Compile Include="IndexBuffer_DX11.cs" />
<Compile Include="Metadata.Designer.cs">
<DependentUpon>Metadata.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="NativeMethods.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RasterizerState_DX11.cs" />
<Compile Include="RenderTarget2D_DX11.cs" />
<Compile Include="SamplerState_DX11.cs" />
<Compile Include="ShaderByteCode.cs" />
<Compile Include="Texture2D_DX11.cs" />
<Compile Include="VertexBuffer_DX11.cs" />
<Compile Include="WindowsGameHost.cs" />
<Compile Include="WindowsGameWindow.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Metadata.resx">

View File

@ -0,0 +1,327 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Direct3D11;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using ANX.Framework;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class BlendState_DX11 : INativeBlendState
{
#region Private Members
private BlendStateDescription blendStateDescription;
private SharpDX.Direct3D11.BlendState nativeBlendState;
private bool nativeBlendStateDirty;
private SharpDX.Color4 blendFactor;
private int multiSampleMask;
private bool bound;
#endregion // Private Members
public BlendState_DX11()
{
for (int i = 0; i < blendStateDescription.RenderTarget.Length; i++)
{
blendStateDescription.RenderTarget[i] = new RenderTargetBlendDescription();
blendStateDescription.IndependentBlendEnable = true;
}
nativeBlendStateDirty = true;
}
public void Apply(GraphicsDevice graphics)
{
GraphicsDeviceWindowsDX11 gdx11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11;
SharpDX.Direct3D11.DeviceContext context = gdx11.NativeDevice;
UpdateNativeBlendState(context.Device);
this.bound = true;
context.OutputMerger.SetBlendState(nativeBlendState, this.blendFactor, this.multiSampleMask);
}
public void Release()
{
this.bound = false;
}
public void Dispose()
{
if (this.nativeBlendState != null)
{
this.nativeBlendState.Dispose();
this.nativeBlendState = null;
}
}
public bool IsBound
{
get
{
return this.bound;
}
}
public Color BlendFactor
{
set
{
const float colorConvert = 1f / 255f;
blendFactor.Red = value.R * colorConvert;
blendFactor.Green = value.G * colorConvert;
blendFactor.Blue = value.B * colorConvert;
blendFactor.Alpha = value.A * colorConvert;
}
}
public int MultiSampleMask
{
set
{
this.multiSampleMask = value;
}
}
public BlendFunction AlphaBlendFunction
{
set
{
BlendOperation alphaBlendOperation = FormatConverter.Translate(value);
for (int i = 0; i < blendStateDescription.RenderTarget.Length; i++)
{
if (blendStateDescription.RenderTarget[i].AlphaBlendOperation != alphaBlendOperation)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[i].AlphaBlendOperation = alphaBlendOperation;
}
}
}
}
public BlendFunction ColorBlendFunction
{
set
{
BlendOperation blendOperation = FormatConverter.Translate(value);
for (int i = 0; i < blendStateDescription.RenderTarget.Length; i++)
{
if (blendStateDescription.RenderTarget[i].BlendOperation != blendOperation)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[i].BlendOperation = blendOperation;
}
}
}
}
public Blend AlphaDestinationBlend
{
set
{
BlendOption destinationAlphaBlend = FormatConverter.Translate(value);
for (int i = 0; i < blendStateDescription.RenderTarget.Length; i++)
{
if (blendStateDescription.RenderTarget[i].DestinationAlphaBlend != destinationAlphaBlend)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[i].DestinationAlphaBlend = destinationAlphaBlend;
}
}
}
}
public Blend ColorDestinationBlend
{
set
{
BlendOption destinationBlend = FormatConverter.Translate(value);
for (int i = 0; i < blendStateDescription.RenderTarget.Length; i++)
{
if (blendStateDescription.RenderTarget[i].DestinationBlend != destinationBlend)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[i].DestinationBlend = destinationBlend;
}
}
}
}
public ColorWriteChannels ColorWriteChannels
{
set
{
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value);
//TODO: range check
if (blendStateDescription.RenderTarget[0].RenderTargetWriteMask != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[0].RenderTargetWriteMask = renderTargetWriteMask;
}
}
}
public ColorWriteChannels ColorWriteChannels1
{
set
{
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value);
//TODO: range check
if (blendStateDescription.RenderTarget[1].RenderTargetWriteMask != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[1].RenderTargetWriteMask = renderTargetWriteMask;
}
}
}
public ColorWriteChannels ColorWriteChannels2
{
set
{
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value);
//TODO: range check
if (blendStateDescription.RenderTarget[2].RenderTargetWriteMask != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[2].RenderTargetWriteMask = renderTargetWriteMask;
}
}
}
public ColorWriteChannels ColorWriteChannels3
{
set
{
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value);
//TODO: range check
if (blendStateDescription.RenderTarget[3].RenderTargetWriteMask != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[3].RenderTargetWriteMask = renderTargetWriteMask;
}
}
}
public Blend AlphaSourceBlend
{
set
{
BlendOption sourceAlphaBlend = FormatConverter.Translate(value);
for (int i = 0; i < blendStateDescription.RenderTarget.Length; i++)
{
if (blendStateDescription.RenderTarget[i].SourceAlphaBlend != sourceAlphaBlend)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[i].SourceAlphaBlend = sourceAlphaBlend;
}
}
}
}
public Blend ColorSourceBlend
{
set
{
BlendOption sourceBlend = FormatConverter.Translate(value);
for (int i = 0; i < blendStateDescription.RenderTarget.Length; i++)
{
if (blendStateDescription.RenderTarget[i].SourceBlend != sourceBlend)
{
nativeBlendStateDirty = true;
blendStateDescription.RenderTarget[i].SourceBlend = sourceBlend;
}
}
}
}
private void UpdateNativeBlendState(SharpDX.Direct3D11.Device device)
{
if (this.nativeBlendStateDirty == true || this.nativeBlendState == null)
{
if (this.nativeBlendState != null)
{
this.nativeBlendState.Dispose();
this.nativeBlendState = null;
}
this.nativeBlendState = new SharpDX.Direct3D11.BlendState(device, ref this.blendStateDescription);
this.nativeBlendStateDirty = false;
}
}
}
}

View File

@ -7,6 +7,8 @@ using ANX.Framework.Graphics;
using System.IO;
using ANX.Framework.NonXNA;
using System.Runtime.InteropServices;
using SharpDX.DXGI;
using ANX.Framework.NonXNA.RenderSystem;
using ANX.Framework;
#endregion // Using Statements
@ -62,17 +64,16 @@ namespace ANX.RenderSystem.Windows.DX11
{
public class Creator : IRenderSystemCreator
{
public void RegisterCreator(AddInSystemFactory factory)
{
factory.AddCreator(this);
}
public string Name
{
get { return "DirectX11"; }
}
public int Priority
{
get { return 5; }
}
public bool IsSupported
{
get
@ -82,173 +83,122 @@ namespace ANX.RenderSystem.Windows.DX11
}
}
public int Priority
{
get { return int.MaxValue; }
}
public GameHost CreateGameHost(Game game)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
//return new WindowsGameHost(game);
return new WindowsGameHost(game);
}
public INativeGraphicsDevice CreateGraphicsDevice(PresentationParameters presentationParameters)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
//return new GraphicsDeviceWindowsDX11_1(presentationParameters);
return new GraphicsDeviceWindowsDX11(presentationParameters);
}
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
//return new IndexBuffer_DX 11(graphics, size, indexCount, usage);
return new IndexBuffer_DX11(graphics, size, indexCount, usage);
}
public INativeBuffer CreateVertexBuffer(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
return new VertexBuffer_DX11(graphics, vertexDeclaration, vertexCount, usage);
}
public INativeEffect CreateEffect(GraphicsDevice graphics, Effect effect, Stream vertexShaderByteCode, Stream pixelShaderByteCode)
public INativeEffect CreateEffect(GraphicsDevice graphics, ANX.Framework.Graphics.Effect managedEffect, Stream vertexShaderByteCode, Stream pixelShaderByteCode)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
//return new Effect_DX11(graphics, vertexShaderByteCode, pixelShaderByteCode);
Effect_DX11 effect = new Effect_DX11(graphics, managedEffect, vertexShaderByteCode, pixelShaderByteCode);
return effect;
}
public INativeEffect CreateEffect(GraphicsDevice graphics, Effect effect, System.IO.Stream byteCode)
public INativeEffect CreateEffect(GraphicsDevice graphics, ANX.Framework.Graphics.Effect managedEffect, System.IO.Stream byteCode)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
//return new Effect_DX11(graphics, byteCode);
Effect_DX11 effect = new Effect_DX11(graphics, managedEffect, byteCode);
return effect;
}
public Texture2D CreateTexture(GraphicsDevice graphics, string fileName)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
}
public Texture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount, byte[] colorData)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
//TODO: implement
throw new NotImplementedException();
/*
if (mipCount > 1)
{
throw new Exception("creating textures with mip map not yet implemented");
}
//GraphicsDeviceWindowsDX10 graphicsDX10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
//SharpDX.Direct3D10.Texture2D nativeTexture = SharpDX.Direct3D10.Texture2D.FromFile<SharpDX.Direct3D10.Texture2D>(graphicsDX10.NativeDevice, fileName);
//Texture2D_DX10 texture = new Texture2D_DX10(graphics, nativeTexture.Description.Width, nativeTexture.Description.Height, FormatConverter.Translate(nativeTexture.Description.Format), nativeTexture.Description.MipLevels);
//texture.NativeTexture = nativeTexture;
GraphicsDeviceWindowsDX10 graphicsDX10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice;
Texture2D_DX10 texture = new Texture2D_DX10(graphics, width, height);
SharpDX.Direct3D10.Texture2DDescription description = new SharpDX.Direct3D10.Texture2DDescription()
{
Width = width,
Height = height,
MipLevels = mipCount,
ArraySize = mipCount,
Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = SharpDX.Direct3D10.ResourceUsage.Dynamic,
BindFlags = SharpDX.Direct3D10.BindFlags.ShaderResource,
CpuAccessFlags = SharpDX.Direct3D10.CpuAccessFlags.Write,
};
texture.NativeTexture = new SharpDX.Direct3D10.Texture2D(graphicsDX10.NativeDevice, description);
// description of texture formats of DX10: http://msdn.microsoft.com/en-us/library/bb694531(v=VS.85).aspx
// more helpfull information on DX10 textures: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx
if (surfaceFormat == SurfaceFormat.Color)
{
int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubresourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = texture.NativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None);
int rowPitch = rectangle.Pitch;
unsafe
{
byte* pTexels = (byte*)rectangle.DataPointer;
int srcIndex = 0;
for (int row = 0; row < height; row++)
{
int rowStart = row * rowPitch;
for (int col = 0; col < width; col++)
{
int colStart = col * 4;
pTexels[rowStart + colStart + 0] = colorData[srcIndex++];
pTexels[rowStart + colStart + 1] = colorData[srcIndex++];
pTexels[rowStart + colStart + 2] = colorData[srcIndex++];
pTexels[rowStart + colStart + 3] = colorData[srcIndex++];
}
}
}
texture.NativeTexture.Unmap(subresource);
}
else
{
throw new Exception(string.Format("creating textures of format {0} not yet implemented...", surfaceFormat.ToString()));
}
return texture;
*/
//return texture;
}
public INativeBlendState CreateBlendState()
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
return new BlendState_DX11();
}
public INativeRasterizerState CreateRasterizerState()
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
return new RasterizerState_DX11();
}
public INativeDepthStencilState CreateDepthStencilState()
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
return new DepthStencilState_DX11();
}
public INativeSamplerState CreateSamplerState()
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
return new SamplerState_DX11();
}
public byte[] GetShaderByteCode(PreDefinedShader type)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
if (type == PreDefinedShader.SpriteBatch)
{
return ShaderByteCode.SpriteBatchByteCode;
}
else if (type == PreDefinedShader.AlphaTestEffect)
{
return ShaderByteCode.AlphaTestEffectByteCode;
}
else if (type == PreDefinedShader.BasicEffect)
{
return ShaderByteCode.BasicEffectByteCode;
}
else if (type == PreDefinedShader.DualTextureEffect)
{
return ShaderByteCode.DualTextureEffectByteCode;
}
else if (type == PreDefinedShader.EnvironmentMapEffect)
{
return ShaderByteCode.EnvironmentMapEffectByteCode;
}
else if (type == PreDefinedShader.SkinnedEffect)
{
return ShaderByteCode.SkinnedEffectByteCode;
}
throw new NotImplementedException("ByteCode for '" + type.ToString() + "' is not yet available");
}
public void RegisterCreator(AddInSystemFactory factory)
{
factory.AddCreator(this);
}
@ -256,21 +206,68 @@ namespace ANX.RenderSystem.Windows.DX11
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
SharpDX.DXGI.Factory factory = new Factory();
List<GraphicsAdapter> adapterList = new List<GraphicsAdapter>();
DisplayModeCollection displayModeCollection = new DisplayModeCollection();
for (int i = 0; i < factory.GetAdapterCount(); i++)
{
using (Adapter adapter = factory.GetAdapter(i))
{
GraphicsAdapter ga = new GraphicsAdapter();
//ga.CurrentDisplayMode = ;
//ga.Description = ;
ga.DeviceId = adapter.Description.DeviceId;
ga.DeviceName = adapter.Description.Description;
ga.IsDefaultAdapter = i == 0; //TODO: how to set default adapter?
//ga.IsWideScreen = ;
//ga.MonitorHandle = ;
ga.Revision = adapter.Description.Revision;
ga.SubSystemId = adapter.Description.SubsystemId;
//ga.SupportedDisplayModes = ;
ga.VendorId = adapter.Description.VendorId;
using (Output adapterOutput = adapter.GetOutput(0))
{
foreach (ModeDescription modeDescription in adapterOutput.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced))
{
DisplayMode displayMode = new DisplayMode()
{
Format = FormatConverter.Translate(modeDescription.Format),
Width = modeDescription.Width,
Height = modeDescription.Height,
AspectRatio = (float)modeDescription.Width / (float)modeDescription.Height,
TitleSafeArea = new Rectangle(0, 0, modeDescription.Width, modeDescription.Height), //TODO: calculate this for real
};
displayModeCollection[displayMode.Format] = new DisplayMode[] { displayMode };
}
}
ga.SupportedDisplayModes = displayModeCollection;
adapterList.Add(ga);
}
}
factory.Dispose();
return new System.Collections.ObjectModel.ReadOnlyCollection<GraphicsAdapter>(adapterList);
}
public Framework.NonXNA.RenderSystem.INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount)
{
throw new NotImplementedException();
}
public Framework.NonXNA.RenderSystem.INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
public INativeTexture2D CreateTexture(GraphicsDevice graphics, SurfaceFormat surfaceFormat, int width, int height, int mipCount)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
throw new NotImplementedException();
return new Texture2D_DX11(graphics, width, height, surfaceFormat, mipCount);
}
public INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
{
AddInSystemFactory.Instance.PreventRenderSystemChange();
return new RenderTarget2D_DX11(graphics, width, height, mipMap, preferredFormat, preferredDepthFormat, preferredMultiSampleCount, usage);
}
}
}

View File

@ -0,0 +1,342 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Direct3D11;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using ANX.Framework;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class DepthStencilState_DX11 : INativeDepthStencilState
{
#region Private Members
private DepthStencilStateDescription description;
private SharpDX.Direct3D11.DepthStencilState nativeDepthStencilState;
private bool nativeDepthStencilStateDirty;
private bool bound;
private int referenceStencil;
#endregion // Private Members
public DepthStencilState_DX11()
{
this.description = new DepthStencilStateDescription();
this.nativeDepthStencilStateDirty = true;
}
public void Apply(ANX.Framework.Graphics.GraphicsDevice graphicsDevice)
{
GraphicsDeviceWindowsDX11 gdx11 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
DeviceContext context = gdx11.NativeDevice;
UpdateNativeDepthStencilState(context.Device);
this.bound = true;
context.OutputMerger.SetDepthStencilState(nativeDepthStencilState, this.referenceStencil);
}
public void Release()
{
this.bound = false;
}
public void Dispose()
{
if (this.nativeDepthStencilState != null)
{
this.nativeDepthStencilState.Dispose();
this.nativeDepthStencilState = null;
}
}
public bool IsBound
{
get
{
return this.bound;
}
}
public ANX.Framework.Graphics.StencilOperation CounterClockwiseStencilDepthBufferFail
{
set
{
SharpDX.Direct3D11.StencilOperation operation = FormatConverter.Translate(value);
if (description.BackFace.DepthFailOperation != operation)
{
description.BackFace.DepthFailOperation = operation;
nativeDepthStencilStateDirty = true;
}
}
}
public ANX.Framework.Graphics.StencilOperation CounterClockwiseStencilFail
{
set
{
SharpDX.Direct3D11.StencilOperation operation = FormatConverter.Translate(value);
if (description.BackFace.FailOperation != operation)
{
description.BackFace.FailOperation = operation;
nativeDepthStencilStateDirty = true;
}
}
}
public ANX.Framework.Graphics.CompareFunction CounterClockwiseStencilFunction
{
set
{
SharpDX.Direct3D11.Comparison comparison = FormatConverter.Translate(value);
if (description.BackFace.Comparison != comparison)
{
description.BackFace.Comparison = comparison;
nativeDepthStencilStateDirty = true;
}
}
}
public ANX.Framework.Graphics.StencilOperation CounterClockwiseStencilPass
{
set
{
SharpDX.Direct3D11.StencilOperation operation = FormatConverter.Translate(value);
if (description.BackFace.PassOperation != operation)
{
description.BackFace.PassOperation = operation;
nativeDepthStencilStateDirty = true;
}
}
}
public bool DepthBufferEnable
{
set
{
if (description.IsDepthEnabled != value)
{
description.IsDepthEnabled = value;
nativeDepthStencilStateDirty = true;
}
}
}
public ANX.Framework.Graphics.CompareFunction DepthBufferFunction
{
set
{
SharpDX.Direct3D11.Comparison comparison = FormatConverter.Translate(value);
if (description.DepthComparison != comparison)
{
description.DepthComparison = comparison;
nativeDepthStencilStateDirty = true;
}
}
}
public bool DepthBufferWriteEnable
{
set
{
DepthWriteMask writeMask = value ? DepthWriteMask.All : DepthWriteMask.Zero;
if (description.DepthWriteMask != writeMask)
{
description.DepthWriteMask = writeMask;
nativeDepthStencilStateDirty = true;
}
}
}
public int ReferenceStencil
{
set
{
if (this.referenceStencil != value)
{
this.referenceStencil = value;
this.nativeDepthStencilStateDirty = true;
}
}
}
public ANX.Framework.Graphics.StencilOperation StencilDepthBufferFail
{
set
{
SharpDX.Direct3D11.StencilOperation operation = FormatConverter.Translate(value);
if (description.FrontFace.DepthFailOperation != operation)
{
description.FrontFace.DepthFailOperation = operation;
nativeDepthStencilStateDirty = true;
}
}
}
public bool StencilEnable
{
set
{
if (description.IsStencilEnabled != value)
{
description.IsStencilEnabled = value;
nativeDepthStencilStateDirty = true;
}
}
}
public ANX.Framework.Graphics.StencilOperation StencilFail
{
set
{
SharpDX.Direct3D11.StencilOperation operation = FormatConverter.Translate(value);
if (description.FrontFace.FailOperation != operation)
{
description.FrontFace.FailOperation = operation;
nativeDepthStencilStateDirty = true;
}
}
}
public ANX.Framework.Graphics.CompareFunction StencilFunction
{
set
{
SharpDX.Direct3D11.Comparison comparison = FormatConverter.Translate(value);
if (description.FrontFace.Comparison != comparison)
{
description.FrontFace.Comparison = comparison;
nativeDepthStencilStateDirty = true;
}
}
}
public int StencilMask
{
set
{
byte stencilMask = (byte)value; //TODO: check range
if (description.StencilReadMask != stencilMask)
{
description.StencilReadMask = stencilMask;
nativeDepthStencilStateDirty = true;
}
}
}
public ANX.Framework.Graphics.StencilOperation StencilPass
{
set
{
SharpDX.Direct3D11.StencilOperation operation = FormatConverter.Translate(value);
if (description.FrontFace.PassOperation != operation)
{
description.FrontFace.PassOperation = operation;
nativeDepthStencilStateDirty = true;
}
}
}
public int StencilWriteMask
{
set
{
byte stencilWriteMask = (byte)value; //TODO: check range
if (description.StencilWriteMask != stencilWriteMask)
{
description.StencilWriteMask = stencilWriteMask;
nativeDepthStencilStateDirty = true;
}
}
}
public bool TwoSidedStencilMode
{
set
{
//TODO: check if we really need this. in xna this enables only counter clockwise stencil operations
}
}
private void UpdateNativeDepthStencilState(Device device)
{
if (this.nativeDepthStencilStateDirty == true || this.nativeDepthStencilState == null)
{
if (this.nativeDepthStencilState != null)
{
this.nativeDepthStencilState.Dispose();
this.nativeDepthStencilState = null;
}
this.nativeDepthStencilState = new SharpDX.Direct3D11.DepthStencilState(device, ref this.description);
this.nativeDepthStencilStateDirty = false;
}
}
}
}

View File

@ -0,0 +1,202 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D11;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA.RenderSystem;
using ANX.Framework;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class EffectParameter_DX11 : INativeEffectParameter
{
private EffectVariable nativeEffectVariable;
public EffectVariable NativeParameter
{
get
{
return this.nativeEffectVariable;
}
internal set
{
this.nativeEffectVariable = value;
}
}
public void SetValue(bool value)
{
nativeEffectVariable.AsScalar().Set(value);
}
public void SetValue(bool[] value)
{
nativeEffectVariable.AsScalar().Set(value);
}
public void SetValue(int value)
{
nativeEffectVariable.AsScalar().Set(value);
}
public void SetValue(int[] value)
{
nativeEffectVariable.AsScalar().Set(value);
}
public void SetValue(Matrix value)
{
SharpDX.Matrix m = new SharpDX.Matrix(value.M11, value.M12, value.M13, value.M14, value.M21, value.M22, value.M23, value.M24, value.M31, value.M32, value.M33, value.M34, value.M41, value.M42, value.M43, value.M44);
nativeEffectVariable.AsMatrix().SetMatrix(m);
}
public void SetValue(Matrix[] value)
{
int count = value.Length;
SharpDX.Matrix[] m = new SharpDX.Matrix[count];
Matrix anxMatrix;
for (int i = 0; i < count; i++)
{
anxMatrix = value[i];
m[i] = new SharpDX.Matrix(anxMatrix.M11, anxMatrix.M12, anxMatrix.M13, anxMatrix.M14,
anxMatrix.M21, anxMatrix.M22, anxMatrix.M23, anxMatrix.M24,
anxMatrix.M31, anxMatrix.M32, anxMatrix.M33, anxMatrix.M34,
anxMatrix.M41, anxMatrix.M42, anxMatrix.M43, anxMatrix.M44);
}
nativeEffectVariable.AsMatrix().SetMatrix(m);
}
public void SetValue(Quaternion value)
{
SharpDX.Vector4 q = new SharpDX.Vector4(value.X, value.Y, value.Z, value.W);
nativeEffectVariable.AsVector().Set(q);
}
public void SetValue(Quaternion[] value)
{
int count = value.Length;
SharpDX.Vector4[] q = new SharpDX.Vector4[count];
for (int i = 0; i < count; i++)
{
q[i] = new SharpDX.Vector4(value[i].X, value[i].Y, value[i].Z, value[i].W);
}
nativeEffectVariable.AsVector().Set(q);
}
public void SetValue(float value)
{
nativeEffectVariable.AsScalar().Set(value);
}
public void SetValue(float[] value)
{
nativeEffectVariable.AsScalar().Set(value);
}
public void SetValue(Vector2 value)
{
SharpDX.Vector2 v = new SharpDX.Vector2(value.X, value.Y);
nativeEffectVariable.AsVector().Set(v);
}
public void SetValue(Vector2[] value)
{
throw new NotImplementedException();
}
public void SetValue(Vector3 value)
{
SharpDX.Vector3 v = new SharpDX.Vector3(value.X, value.Y, value.Z);
nativeEffectVariable.AsVector().Set(v);
}
public void SetValue(Vector3[] value)
{
throw new NotImplementedException();
}
public void SetValue(Vector4 value)
{
SharpDX.Vector4 v = new SharpDX.Vector4(value.X, value.Y, value.Z, value.W);
nativeEffectVariable.AsVector().Set(v);
}
public void SetValue(Vector4[] value)
{
int count = value.Length;
SharpDX.Vector4[] q = new SharpDX.Vector4[count];
for (int i = 0; i < count; i++)
{
q[i] = new SharpDX.Vector4(value[i].X, value[i].Y, value[i].Z, value[i].W);
}
nativeEffectVariable.AsVector().Set(q);
}
public void SetValue(Texture value)
{
Texture2D_DX11 tex = value.NativeTexture as Texture2D_DX11;
nativeEffectVariable.AsShaderResource().SetResource(tex.NativeShaderResourceView);
}
public string Name
{
get
{
return nativeEffectVariable.Description.Name;
}
}
}
}

View File

@ -0,0 +1,84 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D11;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class EffectPass_DX11 : INativeEffectPass
{
private EffectPass nativePass;
public EffectPass NativePass
{
get
{
return this.nativePass;
}
internal set
{
this.nativePass = value;
}
}
public string Name
{
get
{
return nativePass.Description.Name;
}
}
}
}

View File

@ -0,0 +1,112 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D11;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class EffectTechnique_DX11 : INativeEffectTechnique
{
private EffectTechnique nativeTechnique;
private ANX.Framework.Graphics.Effect parentEffect;
internal EffectTechnique_DX11(ANX.Framework.Graphics.Effect parentEffect)
{
if (parentEffect == null)
{
throw new ArgumentNullException("parentEffect");
}
this.parentEffect = parentEffect;
}
public EffectTechnique NativeTechnique
{
get
{
return this.nativeTechnique;
}
internal set
{
this.nativeTechnique = value;
}
}
public string Name
{
get
{
return nativeTechnique.Description.Name;
}
}
public IEnumerable<ANX.Framework.Graphics.EffectPass> Passes
{
get
{
for (int i = 0; i < nativeTechnique.Description.PassCount; i++)
{
EffectPass_DX11 passDx11 = new EffectPass_DX11();
passDx11.NativePass = nativeTechnique.GetPassByIndex(i);
ANX.Framework.Graphics.EffectPass pass = new ANX.Framework.Graphics.EffectPass(this.parentEffect);
yield return pass;
}
}
}
}
}

View File

@ -66,12 +66,18 @@ namespace ANX.RenderSystem.Windows.DX11
private ShaderBytecode vertexShaderByteCode;
private VertexShader vertexShader;
private PixelShader pixelShader;
private ANX.Framework.Graphics.Effect managedEffect;
private ShaderBytecode effectByteCode;
private SharpDX.Direct3D11.Effect nativeEffect;
public Effect_DX11(GraphicsDevice device, Stream vertexShaderByteCode, Stream pixelShaderByteCode)
public Effect_DX11(GraphicsDevice device, ANX.Framework.Graphics.Effect managedEffect, Stream vertexShaderByteCode, Stream pixelShaderByteCode)
{
if (this.managedEffect == null)
{
throw new ArgumentNullException("managedEffect");
}
this.managedEffect = managedEffect;
if (vertexShaderByteCode.CanSeek)
{
vertexShaderByteCode.Seek(0, SeekOrigin.Begin);
@ -87,14 +93,20 @@ namespace ANX.RenderSystem.Windows.DX11
this.pixelShader = new PixelShader((SharpDX.Direct3D11.Device)device.NativeDevice, this.pixelShaderByteCode);
}
public Effect_DX11(GraphicsDevice device, Stream effectByteCode)
public Effect_DX11(GraphicsDevice device, ANX.Framework.Graphics.Effect managedEffect, Stream effectByteCode)
{
if (managedEffect == null)
{
throw new ArgumentNullException("managedEffect");
}
this.managedEffect = managedEffect;
if (effectByteCode.CanSeek)
{
effectByteCode.Seek(0, SeekOrigin.Begin);
}
this.effectByteCode = ShaderBytecode.FromStream(effectByteCode);
this.nativeEffect = new SharpDX.Direct3D11.Effect(((GraphicsDeviceWindowsDX11)device.NativeDevice).NativeDevice, this.effectByteCode);
this.nativeEffect = new SharpDX.Direct3D11.Effect(((GraphicsDeviceWindowsDX11)device.NativeDevice).NativeDevice.Device, this.effectByteCode);
}
public void Apply(GraphicsDevice graphicsDevice)
@ -209,20 +221,17 @@ namespace ANX.RenderSystem.Windows.DX11
public IEnumerable<ANX.Framework.Graphics.EffectTechnique> Techniques
{
get
get
{
throw new NotImplementedException();
for (int i = 0; i < nativeEffect.Description.TechniqueCount; i++)
{
EffectTechnique_DX11 teqDx11 = new EffectTechnique_DX11(this.managedEffect);
teqDx11.NativeTechnique = nativeEffect.GetTechniqueByIndex(i);
//for (int i = 0; i < nativeEffect.Description.TechniqueCount; i++)
//{
// EffectTechnique_DX11 teqDx11 = new EffectTechnique_DX11();
// teqDx10.NativeTechnique = nativeEffect.GetTechniqueByIndex(i);
ANX.Framework.Graphics.EffectTechnique teq = new ANX.Framework.Graphics.EffectTechnique(this.managedEffect, teqDx11);
// ANX.Framework.Graphics.EffectTechnique teq = new ANX.Framework.Graphics.EffectTechnique();
// teq.NativeTechnique = teqDx11;
// yield return teq;
//}
yield return teq;
}
}
}
@ -230,18 +239,16 @@ namespace ANX.RenderSystem.Windows.DX11
{
get
{
throw new NotImplementedException();
for (int i = 0; i < nativeEffect.Description.GlobalVariableCount; i++)
{
EffectParameter_DX11 parDx11 = new EffectParameter_DX11();
parDx11.NativeParameter = nativeEffect.GetVariableByIndex(i);
//for (int i = 0; i < nativeEffect.Description.GlobalVariableCount; i++)
//{
// EffectParameter_DX10 parDx10 = new EffectParameter_DX10();
// parDx10.NativeParameter = nativeEffect.GetVariableByIndex(i);
ANX.Framework.Graphics.EffectParameter par = new ANX.Framework.Graphics.EffectParameter();
par.NativeParameter = parDx11;
// Graphics.EffectParameter par = new Graphics.EffectParameter();
// par.NativeParameter = parDx10;
// yield return par;
//}
yield return par;
}
}
}
}

View File

@ -0,0 +1,387 @@
#region Using Statements
using System;
using ANX.Framework.Graphics;
using SharpDX.Direct3D11;
using SharpDX.Direct3D;
using SharpDX.DXGI;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
internal class FormatConverter
{
public static int FormatSize(SurfaceFormat format)
{
switch (format)
{
case SurfaceFormat.Vector4:
return 16;
//case SurfaceFormat.Vector3:
// return 12;
case SurfaceFormat.Vector2:
return 8;
case SurfaceFormat.Single:
case SurfaceFormat.Color:
//case SurfaceFormat.RGBA1010102:
//case SurfaceFormat.RG32:
return 4;
//case SurfaceFormat.BGR565:
//case SurfaceFormat.BGRA5551:
// return 2;
case SurfaceFormat.Dxt1:
case SurfaceFormat.Dxt3:
case SurfaceFormat.Dxt5:
case SurfaceFormat.Alpha8:
return 1;
default:
throw new ArgumentException("Invalid format");
}
}
public static SharpDX.DXGI.Format Translate(SurfaceFormat surfaceFormat)
{
switch (surfaceFormat)
{
case SurfaceFormat.Color:
return SharpDX.DXGI.Format.R8G8B8A8_UNorm;
case SurfaceFormat.Dxt3:
return SharpDX.DXGI.Format.BC2_UNorm;
case SurfaceFormat.Dxt5:
return SharpDX.DXGI.Format.BC3_UNorm;
}
throw new Exception("can't translate SurfaceFormat: " + surfaceFormat.ToString());
}
public static Format Translate(ANX.Framework.Graphics.DepthFormat depthFormat)
{
switch (depthFormat)
{
case DepthFormat.Depth16:
return Format.D16_UNorm;
case DepthFormat.Depth24:
//TODO: no DirectX10 24Bit depth format???
case DepthFormat.Depth24Stencil8:
return Format.D24_UNorm_S8_UInt;
case DepthFormat.None:
return Format.Unknown;
}
throw new Exception("can't translate DepthFormat: " + depthFormat.ToString());
}
public static SurfaceFormat Translate(SharpDX.DXGI.Format format)
{
switch (format)
{
case SharpDX.DXGI.Format.R8G8B8A8_UNorm:
return SurfaceFormat.Color;
case SharpDX.DXGI.Format.BC2_UNorm:
return SurfaceFormat.Dxt3;
case SharpDX.DXGI.Format.BC3_UNorm:
return SurfaceFormat.Dxt5;
}
throw new Exception("can't translate Format: " + format.ToString());
}
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;
}
throw new NotImplementedException();
}
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;
}
return SharpDX.Direct3D11.TextureAddressMode.Clamp;
}
public static PrimitiveTopology Translate(PrimitiveType primitiveType)
{
switch (primitiveType)
{
case PrimitiveType.LineList:
return PrimitiveTopology.LineList;
case PrimitiveType.LineStrip:
return PrimitiveTopology.LineStrip;
case PrimitiveType.TriangleList:
return PrimitiveTopology.TriangleList;
case PrimitiveType.TriangleStrip:
return PrimitiveTopology.TriangleStrip;
default:
throw new InvalidOperationException("unknown PrimitiveType: " + primitiveType.ToString());
}
}
public static SharpDX.DXGI.Format Translate(IndexElementSize indexElementSize)
{
switch (indexElementSize)
{
case IndexElementSize.SixteenBits:
return Format.R16_UInt;
case IndexElementSize.ThirtyTwoBits:
return Format.R32_UInt;
default:
throw new InvalidOperationException("unknown IndexElementSize: " + indexElementSize.ToString());
}
}
public static string Translate(VertexElementUsage usage)
{
//TODO: map the other Usages
if (usage == VertexElementUsage.TextureCoordinate)
{
return "TEXCOORD";
}
else
{
return usage.ToString().ToUpperInvariant();
}
}
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;
}
throw new NotImplementedException();
}
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;
}
throw new NotImplementedException();
}
public static ColorWriteMaskFlags Translate(ColorWriteChannels colorWriteChannels)
{
ColorWriteMaskFlags mask = 0;
if ((colorWriteChannels & ColorWriteChannels.All) == ColorWriteChannels.All)
{
mask |= ColorWriteMaskFlags.All;
}
if ((colorWriteChannels & ColorWriteChannels.Alpha) == ColorWriteChannels.Alpha)
{
mask |= ColorWriteMaskFlags.Alpha;
}
if ((colorWriteChannels & ColorWriteChannels.Blue) == ColorWriteChannels.Blue)
{
mask |= ColorWriteMaskFlags.Blue;
}
if ((colorWriteChannels & ColorWriteChannels.Green) == ColorWriteChannels.Green)
{
mask |= ColorWriteMaskFlags.Green;
}
if ((colorWriteChannels & ColorWriteChannels.Red) == ColorWriteChannels.Red)
{
mask |= ColorWriteMaskFlags.Red;
}
return mask;
}
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;
}
throw new NotImplementedException("unknown StencilOperation");
}
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;
}
throw new NotImplementedException("unknown CompareFunction");
}
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;
}
}
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;
}
}
}
}

View File

@ -6,11 +6,10 @@ using System.Text;
using SharpDX;
using SharpDX.DXGI;
using SharpDX.Direct3D;
using ANX.Framework.NonXNA;
using ANX.Framework.Graphics;
using SharpDX.Direct3D11;
using ANX.Framework;
using SharpDX.D3DCompiler;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D11;
using ANX.Framework.Graphics;
#endregion // Using Statements
@ -63,27 +62,67 @@ using SharpDX.D3DCompiler;
using Device = SharpDX.Direct3D11.Device;
using Buffer = SharpDX.Direct3D11.Buffer;
using System.Runtime.InteropServices;
using ANX.Framework;
namespace ANX.RenderSystem.Windows.DX11
{
public class GraphicsDeviceWindowsDX11 : INativeGraphicsDevice
{
private Device device;
private SwapChain swapChain;
{
#region Constants
private const float ColorMultiplier = 1f / 255f;
#endregion
#region Interop
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int width, int height, uint uFlags);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
#endregion
#region Private Members
private DeviceContext deviceContext;
private SwapChain swapChain;
private RenderTargetView renderView;
private RenderTargetView renderTargetView;
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;
private bool vSyncEnabled;
#endregion // Private Members
public GraphicsDeviceWindowsDX11(PresentationParameters presentationParameters)
{
this.vSyncEnabled = true;
// SwapChain description
var desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription = new ModeDescription(presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, new Rational(60, 1), Format.R8G8B8A8_UNorm),
ModeDescription = new ModeDescription(presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, new Rational(60, 1), FormatConverter.Translate(presentationParameters.BackBufferFormat)),
IsWindowed = true,
OutputHandle = presentationParameters.DeviceWindowHandle,
SampleDescription = new SampleDescription(1, 0),
@ -92,40 +131,222 @@ namespace ANX.RenderSystem.Windows.DX11
};
// 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(SharpDX.Direct3D10.DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain);
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out dxDevice, out swapChain);
#else
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out dxDevice, out swapChain);
#endif
this.deviceContext = new DeviceContext(dxDevice);
// Ignore all windows events
Factory factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(presentationParameters.DeviceWindowHandle, WindowAssociationFlags.IgnoreAll);
ResizeRenderWindow(presentationParameters);
// New RenderTargetView from the backbuffer
backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0);
renderView = new RenderTargetView(device, backBuffer);
renderView = new RenderTargetView(deviceContext.Device, backBuffer);
currentViewport = new SharpDX.Direct3D11.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
//
// create the depth stencil buffer
//
Format depthFormat = FormatConverter.Translate(presentationParameters.DepthStencilFormat);
if (depthFormat != Format.Unknown)
{
CreateDepthStencilBuffer(depthFormat);
}
}
private void CreateDepthStencilBuffer(Format depthFormat)
{
if (this.depthStencilBuffer != null &&
this.depthStencilBuffer.Description.Format == depthFormat &&
this.depthStencilBuffer.Description.Width == this.backBuffer.Description.Width &&
this.depthStencilBuffer.Description.Height == this.backBuffer.Description.Height)
{
// a DepthStencilBuffer with the right format and the right size already exists -> nothing to do
return;
}
if (this.depthStencilView != null)
{
this.depthStencilView.Dispose();
this.depthStencilView = null;
}
if (this.depthStencilBuffer != null)
{
this.depthStencilBuffer.Dispose();
this.depthStencilBuffer = null;
}
if (depthFormat == Format.Unknown)
{
// no DepthStencilBuffer to create... Old one was disposed already...
return;
}
DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription()
{
Format = depthFormat,
};
Texture2DDescription depthStencilTextureDesc = new Texture2DDescription()
{
Width = this.backBuffer.Description.Width,
Height = this.backBuffer.Description.Height,
MipLevels = 1,
ArraySize = 1,
Format = depthFormat,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
};
this.depthStencilBuffer = new SharpDX.Direct3D11.Texture2D(deviceContext.Device, depthStencilTextureDesc);
this.depthStencilView = new DepthStencilView(deviceContext.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
}
#region Clear
public void Clear(ref Color color)
{
throw new NotImplementedException();
//device.ClearRenderTargetView(renderView, new SharpDX.Color4(color.A / 255f, color.R / 255f, color.G / 255f, color.B / 255f));
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;
}
this.deviceContext.ClearRenderTargetView(this.renderTargetView != null ? this.renderTargetView : this.renderView, this.clearColor);
}
public void Clear(ClearOptions options, ANX.Framework.Vector4 color, float depth, int stencil)
{
if ((options & ClearOptions.Target) == ClearOptions.Target)
{
// Clear a RenderTarget (or BackBuffer)
this.clearColor.Red = color.X;
this.clearColor.Green = color.Y;
this.clearColor.Blue = color.Z;
this.clearColor.Alpha = color.W;
this.lastClearColor = 0;
this.deviceContext.ClearRenderTargetView(this.renderTargetView != null ? this.renderTargetView : this.renderView, this.clearColor);
}
if (this.depthStencilView != null)
{
if ((options | ClearOptions.Stencil | ClearOptions.DepthBuffer) == options)
{
// Clear the stencil buffer
deviceContext.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);
}
else
{
deviceContext.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Depth, depth, (byte)stencil);
}
}
}
#endregion
#region Present
public void Present()
{
swapChain.Present(0, PresentFlags.None);
swapChain.Present(this.vSyncEnabled ? 1 : 0, PresentFlags.None);
}
internal Device NativeDevice
#endregion // Present
#region DrawPrimitives & DrawIndexedPrimitives
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount)
{
SharpDX.Direct3D11.EffectPass pass; SharpDX.Direct3D11.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
// Prepare All the stages
deviceContext.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
deviceContext.Rasterizer.SetViewports(currentViewport);
deviceContext.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply(deviceContext);
deviceContext.DrawIndexed(CalculateVertexCount(primitiveType, primitiveCount), startIndex, baseVertex);
}
}
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount)
{
SharpDX.Direct3D11.EffectPass pass; SharpDX.Direct3D11.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
// Prepare All the stages
deviceContext.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
deviceContext.Rasterizer.SetViewports(currentViewport);
deviceContext.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply(deviceContext);
deviceContext.Draw(primitiveCount, vertexOffset);
}
}
#endregion // DrawPrimitives & DrawIndexedPrimitives
#region DrawInstancedPrimitives
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount)
{
throw new NotImplementedException();
}
#endregion // DrawInstancedPrimitives
#region DrawUserIndexedPrimitives<T>
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, Array indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration, IndexElementSize indexFormat) where T : struct, IVertexType
{
throw new NotImplementedException();
}
#endregion // DrawUserIndexedPrimitives<T>
#region DrawUserPrimitives<T>
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
}
#endregion // DrawUserPrimitives<T>
internal DeviceContext NativeDevice
{
get
{
return this.device;
return this.deviceContext;
}
}
@ -147,11 +368,9 @@ namespace ANX.RenderSystem.Windows.DX11
// 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(device, passSignature, vertexDeclaration);
var layout = CreateInputLayout(deviceContext.Device, passSignature, vertexDeclaration);
throw new NotImplementedException();
//device.InputAssembler.InputLayout = layout;
deviceContext.InputAssembler.InputLayout = layout;
}
private int CalculateVertexCount(PrimitiveType type, int primitiveCount)
@ -178,49 +397,6 @@ namespace ANX.RenderSystem.Windows.DX11
}
}
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount)
{
SharpDX.Direct3D11.EffectPass pass; SharpDX.Direct3D11.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
throw new NotImplementedException();
// Prepare All the stages
//device.InputAssembler.PrimitiveTopology = Translate(primitiveType);
//device.Rasterizer.SetViewports(currentViewport);
//device.OutputMerger.SetTargets(this.renderView);
//for (int i = 0; i < technique.Description.PassCount; ++i)
//{
// pass.Apply();
// device.DrawIndexed(CalculateVertexCount(primitiveType, primitiveCount), startIndex, baseVertex);
//}
}
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount)
{
SharpDX.Direct3D11.EffectPass pass; SharpDX.Direct3D11.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
throw new NotImplementedException();
// Prepare All the stages
//device.InputAssembler.PrimitiveTopology = Translate(primitiveType);
//device.Rasterizer.SetViewports(currentViewport);
//device.OutputMerger.SetTargets(this.renderView);
//for (int i = 0; i < technique.Description.PassCount; ++i)
//{
// pass.Apply();
// device.Draw(primitiveCount, vertexOffset);
//}
}
public void SetIndexBuffer(IndexBuffer indexBuffer)
{
if (indexBuffer == null)
@ -230,23 +406,44 @@ namespace ANX.RenderSystem.Windows.DX11
this.currentIndexBuffer = indexBuffer;
throw new NotImplementedException();
IndexBuffer_DX11 nativeIndexBuffer = indexBuffer.NativeIndexBuffer as IndexBuffer_DX11;
//IndexBuffer_DX11 nativeIndexBuffer = indexBuffer.NativeIndexBuffer as IndexBuffer_DX11;
//if (nativeIndexBuffer != null)
//{
// device.InputAssembler.SetIndexBuffer(nativeIndexBuffer.NativeBuffer, Translate(indexBuffer.IndexElementSize), 0);
//}
//else
//{
// throw new Exception("couldn't fetch native DirectX11.1 IndexBuffer");
//}
if (nativeIndexBuffer != null)
{
deviceContext.InputAssembler.SetIndexBuffer(nativeIndexBuffer.NativeBuffer, FormatConverter.Translate(indexBuffer.IndexElementSize), 0);
}
else
{
throw new Exception("couldn't fetch native DirectX10 IndexBuffer");
}
}
public void SetVertexBuffers(ANX.Framework.Graphics.VertexBufferBinding[] vertexBuffers)
{
throw new NotImplementedException();
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];
for (int i = 0; i < vertexBuffers.Length; i++)
{
ANX.Framework.Graphics.VertexBufferBinding anxVertexBufferBinding = vertexBuffers[i];
VertexBuffer_DX11 nativeVertexBuffer = anxVertexBufferBinding.VertexBuffer.NativeVertexBuffer as VertexBuffer_DX11;
if (nativeVertexBuffer != null)
{
nativeVertexBufferBindings[i] = new SharpDX.Direct3D11.VertexBufferBinding(nativeVertexBuffer.NativeBuffer, anxVertexBufferBinding.VertexBuffer.VertexDeclaration.VertexStride, anxVertexBufferBinding.VertexOffset);
}
else
{
throw new Exception("couldn't fetch native DirectX10 VertexBuffer");
}
}
deviceContext.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
}
public void SetViewport(ANX.Framework.Graphics.Viewport viewport)
@ -254,126 +451,6 @@ namespace ANX.RenderSystem.Windows.DX11
this.currentViewport = new SharpDX.Direct3D11.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height, viewport.MinDepth, viewport.MaxDepth);
}
public void ApplyStateObject(ANX.Framework.Graphics.BlendState blendState)
{
throw new NotImplementedException();
//BlendStateDescription description = new BlendStateDescription();
//description.AlphaBlendOperation = Translate(blendState.AlphaBlendFunction);
//description.BlendOperation = Translate(blendState.ColorBlendFunction);
//description.DestinationAlphaBlend = Translate(blendState.AlphaDestinationBlend);
//description.DestinationBlend = Translate(blendState.ColorDestinationBlend);
//for (int i = 0; i < 4; i++)
//{
// description.IsBlendEnabled[i] = true;
//}
//description.RenderTargetWriteMask[0] = Translate(blendState.ColorWriteChannels);
//description.RenderTargetWriteMask[1] = Translate(blendState.ColorWriteChannels1);
//description.RenderTargetWriteMask[2] = Translate(blendState.ColorWriteChannels2);
//description.RenderTargetWriteMask[3] = Translate(blendState.ColorWriteChannels3);
//description.SourceAlphaBlend = Translate(blendState.AlphaSourceBlend);
//description.SourceBlend = Translate(blendState.ColorSourceBlend);
//SharpDX.Direct3D11.BlendState nativeBlendState = new SharpDX.Direct3D11.BlendState(device, description);
//Vector4 tempVector = blendState.BlendFactor.ToVector4();
//SharpDX.Color4 blendFactor = new Color4(tempVector.X, tempVector.Y, tempVector.Z, tempVector.W);
//device.OutputMerger.SetBlendState(nativeBlendState, blendFactor, blendState.MultiSampleMask);
}
public void ApplyStateObject(ANX.Framework.Graphics.RasterizerState rasterizerState)
{
RasterizerStateDescription description = new RasterizerStateDescription();
description.CullMode = Translate(rasterizerState.CullMode);
description.DepthBias = (int)rasterizerState.DepthBias; //TODO: this looks wrong!!!
description.IsScissorEnabled = rasterizerState.ScissorTestEnable;
description.SlopeScaledDepthBias = rasterizerState.SlopeScaleDepthBias;
description.IsMultisampleEnabled = rasterizerState.MultiSampleAntiAlias;
description.FillMode = Translate(rasterizerState.FillMode);
description.IsAntialiasedLineEnabled = false; //TODO: this should be ok
SharpDX.Direct3D11.RasterizerState nativeRasterizerState = new SharpDX.Direct3D11.RasterizerState(device, description);
//device.Rasterizer.State = nativeRasterizerState;
throw new NotImplementedException();
}
public void ApplyStateObject(ANX.Framework.Graphics.DepthStencilState depthStencilState)
{
DepthStencilStateDescription description = new DepthStencilStateDescription();
description.IsStencilEnabled = depthStencilState.StencilEnable;
description.IsDepthEnabled = depthStencilState.DepthBufferEnable;
description.DepthComparison = Translate(depthStencilState.DepthBufferFunction);
//TODO: more to implement
SharpDX.Direct3D11.DepthStencilState nativeDepthStencilState = new SharpDX.Direct3D11.DepthStencilState(device, description);
//device.OutputMerger.SetDepthStencilState(nativeDepthStencilState, depthStencilState.ReferenceStencil);
throw new NotImplementedException();
}
public void ApplyStateObject(int slot, ANX.Framework.Graphics.SamplerState samplerState)
{
SamplerStateDescription description = new SamplerStateDescription();
description.AddressU = Translate(samplerState.AddressU);
description.AddressV = Translate(samplerState.AddressV);
description.AddressW = Translate(samplerState.AddressW);
description.Filter = Translate(samplerState.Filter);
description.MaximumAnisotropy = samplerState.MaxAnisotropy;
description.MaximumLod = samplerState.MaxMipLevel; //TODO: is this correct?
description.MipLodBias = samplerState.MipMapLevelOfDetailBias;
SharpDX.Direct3D11.SamplerState nativeSamplerState = new SharpDX.Direct3D11.SamplerState(device, description);
//device.PixelShader.SetSampler(slot, nativeSamplerState);
throw new NotImplementedException();
}
private 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;
}
throw new NotImplementedException();
}
private 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;
}
return SharpDX.Direct3D11.TextureAddressMode.Clamp;
}
/// <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.
@ -395,7 +472,7 @@ namespace ANX.RenderSystem.Windows.DX11
private InputElement CreateInputElementFromVertexElement(VertexElement vertexElement)
{
string elementName = Translate(vertexElement.VertexElementUsage);
string elementName = FormatConverter.Translate(vertexElement.VertexElementUsage);
Format elementFormat;
switch (vertexElement.VertexElementFormat)
@ -419,182 +496,46 @@ namespace ANX.RenderSystem.Windows.DX11
return new InputElement(elementName, vertexElement.UsageIndex, elementFormat, vertexElement.Offset, 0);
}
private PrimitiveTopology Translate(PrimitiveType primitiveType)
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
{
switch (primitiveType)
if (renderTargets == null)
{
case PrimitiveType.LineList:
return PrimitiveTopology.LineList;
case PrimitiveType.LineStrip:
return PrimitiveTopology.LineStrip;
case PrimitiveType.TriangleList:
return PrimitiveTopology.TriangleList;
case PrimitiveType.TriangleStrip:
return PrimitiveTopology.TriangleStrip;
default:
throw new InvalidOperationException("unknown PrimitiveType: " + primitiveType.ToString());
}
}
// reset the RenderTarget to backbuffer
if (renderTargetView != null)
{
renderTargetView.Dispose();
renderTargetView = null;
}
private SharpDX.DXGI.Format Translate(IndexElementSize indexElementSize)
{
switch (indexElementSize)
{
case IndexElementSize.SixteenBits:
return Format.R16_UInt;
case IndexElementSize.ThirtyTwoBits:
return Format.R32_UInt;
default:
throw new InvalidOperationException("unknown IndexElementSize: " + indexElementSize.ToString());
}
}
private string Translate(VertexElementUsage usage)
{
//TODO: map the other Usages
if (usage == VertexElementUsage.TextureCoordinate)
{
return "TEXCOORD";
deviceContext.OutputMerger.SetRenderTargets(1, new RenderTargetView[] { this.renderView }, this.depthStencilView);
deviceContext.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
}
else
{
return usage.ToString().ToUpperInvariant();
if (renderTargets.Length == 1)
{
RenderTarget2D renderTarget = renderTargets[0].RenderTarget as RenderTarget2D;
RenderTarget2D_DX11 nativeRenderTarget = renderTarget.NativeRenderTarget as RenderTarget2D_DX11;
if (renderTarget != null)
{
if (renderTargetView != null)
{
renderTargetView.Dispose();
renderTargetView = null;
}
this.renderTargetView = new RenderTargetView(deviceContext.Device, ((Texture2D_DX11)nativeRenderTarget).NativeShaderResourceView.Resource);
DepthStencilView depthStencilView = null;
deviceContext.OutputMerger.SetRenderTargets(1, new RenderTargetView[] { this.renderTargetView }, depthStencilView);
}
}
else
{
throw new NotImplementedException("handling of multiple RenderTargets are not yet implemented");
}
}
}
private ColorWriteMaskFlags Translate(ColorWriteChannels colorWriteChannels)
{
switch (colorWriteChannels)
{
case ColorWriteChannels.All:
return ColorWriteMaskFlags.All;
case ColorWriteChannels.Alpha:
return ColorWriteMaskFlags.Alpha;
case ColorWriteChannels.Blue:
return ColorWriteMaskFlags.Blue;
case ColorWriteChannels.Green:
return ColorWriteMaskFlags.Green;
case ColorWriteChannels.Red:
return ColorWriteMaskFlags.Red;
}
return 0;
}
private 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;
}
return BlendOption.One;
}
private 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;
}
return BlendOperation.Add;
}
private 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;
}
}
private 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;
}
}
private Comparison Translate(CompareFunction compareFunction)
{
switch (compareFunction)
{
case CompareFunction.Always:
return Comparison.Always;
case CompareFunction.Equal:
return Comparison.Equal;
case CompareFunction.Greater:
return Comparison.Greater;
case CompareFunction.GreaterEqual:
return Comparison.GreaterEqual;
case CompareFunction.Less:
return Comparison.Less;
case CompareFunction.LessEqual:
return Comparison.LessEqual;
case CompareFunction.Never:
return Comparison.Never;
case CompareFunction.NotEqual:
return Comparison.NotEqual;
}
return Comparison.Always;
}
public void SetRenderTargets(params Framework.Graphics.RenderTargetBinding[] renderTargets)
{
throw new NotImplementedException();
}
public void GetBackBufferData<T>(Framework.Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
public void GetBackBufferData<T>(ANX.Framework.Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
@ -609,49 +550,91 @@ namespace ANX.RenderSystem.Windows.DX11
throw new NotImplementedException();
}
public void Clear(Framework.Graphics.ClearOptions options, Framework.Vector4 color, float depth, int stencil)
public void ResizeBuffers(PresentationParameters presentationParameters)
{
throw new NotImplementedException();
if (swapChain != null)
{
renderView.Dispose();
backBuffer.Dispose();
//TODO: handle format
swapChain.ResizeBuffers(swapChain.Description.BufferCount, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, Format.R8G8B8A8_UNorm, (int)swapChain.Description.Flags);
backBuffer = SharpDX.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 = FormatConverter.Translate(presentationParameters.DepthStencilFormat);
if (depthFormat != Format.Unknown)
{
CreateDepthStencilBuffer(depthFormat);
}
}
ResizeRenderWindow(presentationParameters);
}
public void DrawInstancedPrimitives(Framework.Graphics.PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount)
private void ResizeRenderWindow(PresentationParameters presentationParameters)
{
throw new NotImplementedException();
RECT windowRect;
RECT clientRect;
if (GetWindowRect(presentationParameters.DeviceWindowHandle, out windowRect) &&
GetClientRect(presentationParameters.DeviceWindowHandle, out clientRect))
{
int width = presentationParameters.BackBufferWidth + ((windowRect.Right - windowRect.Left) - clientRect.Right);
int height = presentationParameters.BackBufferHeight + ((windowRect.Bottom - windowRect.Top) - clientRect.Bottom);
SetWindowPos(presentationParameters.DeviceWindowHandle, IntPtr.Zero, windowRect.Left, windowRect.Top, width, height, 0);
}
}
public void DrawUserIndexedPrimitives<T>(Framework.Graphics.PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, Array indexData, int indexOffset, int primitiveCount, Framework.Graphics.VertexDeclaration vertexDeclaration, Framework.Graphics.IndexElementSize indexFormat) where T : struct, Framework.Graphics.IVertexType
{
throw new NotImplementedException();
}
public void DrawUserPrimitives<T>(Framework.Graphics.PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, Framework.Graphics.VertexDeclaration vertexDeclaration) where T : struct, Framework.Graphics.IVertexType
{
throw new NotImplementedException();
}
public void ResizeBuffers(Framework.Graphics.PresentationParameters presentationParameters)
{
throw new NotImplementedException();
}
public bool VSync
{
get
{
throw new NotImplementedException();
return this.vSyncEnabled;
}
set
{
throw new NotImplementedException();
this.vSyncEnabled = value;
}
}
public void Dispose()
{
//TODO: implement
if (renderTargetView != null)
{
renderTargetView.Dispose();
renderTargetView = null;
}
if (swapChain != null)
{
renderView.Dispose();
renderView = null;
backBuffer.Dispose();
backBuffer = null;
swapChain.Dispose();
swapChain = null;
}
if (this.depthStencilView != null)
{
this.depthStencilBuffer.Dispose();
this.depthStencilBuffer = null;
this.depthStencilView.Dispose();
this.depthStencilView = null;
}
//TODO: dispose everything else
}
}
}

View File

@ -0,0 +1,155 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D11;
using ANX.Framework.Graphics;
using System.Runtime.InteropServices;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class IndexBuffer_DX11 : INativeBuffer, IDisposable
{
private SharpDX.Direct3D11.Buffer buffer;
private IndexElementSize size;
public IndexBuffer_DX11(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage)
{
this.size = size;
//TODO: translate and use usage
GraphicsDeviceWindowsDX11 gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11;
SharpDX.Direct3D11.DeviceContext context = gd11 != null ? gd11.NativeDevice as SharpDX.Direct3D11.DeviceContext : null;
if (context != null)
{
BufferDescription description = new BufferDescription()
{
Usage = ResourceUsage.Dynamic,
SizeInBytes = (size == IndexElementSize.SixteenBits ? 2 : 4) * indexCount,
BindFlags = BindFlags.IndexBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None
};
this.buffer = new SharpDX.Direct3D11.Buffer(context.Device, description);
//this.buffer.Unmap();
}
}
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct
{
SetData<T>(graphicsDevice, data, 0, data.Length);
}
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
{
if (startIndex > 0 || elementCount < data.Length)
{
throw new NotImplementedException("currently starIndex and elementCount of SetData are not implemented");
}
GraphicsDeviceWindowsDX11 dx11GraphicsDevice = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
DeviceContext context = dx11GraphicsDevice.NativeDevice;
//TODO: check offsetInBytes parameter for bounds etc.
GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
IntPtr dataPointer = pinnedArray.AddrOfPinnedObject();
int dataLength = Marshal.SizeOf(typeof(T)) * data.Length;
unsafe
{
using (var vData = new SharpDX.DataStream(dataPointer, dataLength, true, false))
{
if (offsetInBytes > 0)
{
vData.Seek(offsetInBytes / (size == IndexElementSize.SixteenBits ? 2 : 4), System.IO.SeekOrigin.Begin);
}
SharpDX.DataStream stream;
SharpDX.DataBox box = context.MapSubresource(this.buffer, MapMode.WriteDiscard, MapFlags.None, out stream);
vData.CopyTo(stream);
context.UnmapSubresource(this.buffer, 0);
}
}
pinnedArray.Free();
}
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct
{
SetData<T>(graphicsDevice, 0, data, startIndex, elementCount);
}
public SharpDX.Direct3D11.Buffer NativeBuffer
{
get
{
return this.buffer;
}
}
public void Dispose()
{
if (this.buffer != null)
{
buffer.Dispose();
buffer = null;
}
}
}
}

View File

@ -0,0 +1,120 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Security;
using System.Drawing;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
internal sealed class NativeMethods
{
[SuppressUnmanagedCodeSecurity, DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
// Nested Types
[StructLayout(LayoutKind.Sequential)]
public struct Message
{
public IntPtr hWnd;
public NativeMethods.WindowMessage msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public Point p;
}
internal enum WindowMessage : uint
{
ActivateApplication = 0x1c,
Character = 0x102,
Close = 0x10,
Destroy = 2,
EnterMenuLoop = 0x211,
EnterSizeMove = 0x231,
ExitMenuLoop = 530,
ExitSizeMove = 0x232,
GetMinMax = 0x24,
KeyDown = 0x100,
KeyUp = 0x101,
LeftButtonDoubleClick = 0x203,
LeftButtonDown = 0x201,
LeftButtonUp = 0x202,
MiddleButtonDoubleClick = 0x209,
MiddleButtonDown = 0x207,
MiddleButtonUp = 520,
MouseFirst = 0x201,
MouseLast = 0x20d,
MouseMove = 0x200,
MouseWheel = 0x20a,
NonClientHitTest = 0x84,
Paint = 15,
PowerBroadcast = 0x218,
Quit = 0x12,
RightButtonDoubleClick = 0x206,
RightButtonDown = 0x204,
RightButtonUp = 0x205,
SetCursor = 0x20,
Size = 5,
SystemCharacter = 0x106,
SystemCommand = 0x112,
SystemKeyDown = 260,
SystemKeyUp = 0x105,
XButtonDoubleClick = 0x20d,
XButtonDown = 0x20b,
XButtonUp = 0x20c
}
}
}

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Buildnummer
// Revision
//
[assembly: AssemblyVersion("0.1.3.0")]
[assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: AssemblyVersion("0.7.0.0")]
[assembly: AssemblyFileVersion("0.7.0.0")]

View File

@ -0,0 +1,212 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Direct3D11;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class RasterizerState_DX11 : INativeRasterizerState
{
#region Private Members
private RasterizerStateDescription description;
private SharpDX.Direct3D11.RasterizerState nativeRasterizerState;
private bool nativeRasterizerStateDirty;
private bool bound;
private const int intMaxOver16 = int.MaxValue / 16;
#endregion // Private Members
public RasterizerState_DX11()
{
this.description = new RasterizerStateDescription();
this.description.IsAntialiasedLineEnabled = false;
this.nativeRasterizerStateDirty = true;
}
public void Apply(ANX.Framework.Graphics.GraphicsDevice graphicsDevice)
{
GraphicsDeviceWindowsDX11 gdx11 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
DeviceContext context = gdx11.NativeDevice;
UpdateNativeRasterizerState(context.Device);
this.bound = true;
context.Rasterizer.State = this.nativeRasterizerState;
}
public void Release()
{
this.bound = false;
}
public void Dispose()
{
if (this.nativeRasterizerState != null)
{
this.nativeRasterizerState.Dispose();
this.nativeRasterizerState = null;
}
}
public bool IsBound
{
get
{
return this.bound;
}
}
public ANX.Framework.Graphics.CullMode CullMode
{
set
{
SharpDX.Direct3D11.CullMode cullMode = FormatConverter.Translate(value);
if (description.CullMode != cullMode)
{
nativeRasterizerStateDirty = true;
description.CullMode = cullMode;
}
}
}
public float DepthBias
{
set
{
// XNA uses a float value in the range of 0f..16f as value
// DirectX 10 uses a INT value
int depthBiasValue = (int)(value * intMaxOver16);
if (description.DepthBias != depthBiasValue)
{
nativeRasterizerStateDirty = true;
description.DepthBias = depthBiasValue;
}
}
}
public ANX.Framework.Graphics.FillMode FillMode
{
set
{
SharpDX.Direct3D11.FillMode fillMode = FormatConverter.Translate(value);
if (description.FillMode != fillMode)
{
nativeRasterizerStateDirty = true;
description.FillMode = fillMode;
}
}
}
public bool MultiSampleAntiAlias
{
set
{
if (description.IsMultisampleEnabled != value)
{
nativeRasterizerStateDirty = true;
description.IsMultisampleEnabled = value;
}
}
}
public bool ScissorTestEnable
{
set
{
if (description.IsScissorEnabled != value)
{
nativeRasterizerStateDirty = true;
description.IsScissorEnabled = value;
}
}
}
public float SlopeScaleDepthBias
{
set
{
if (description.SlopeScaledDepthBias != value)
{
nativeRasterizerStateDirty = true;
description.SlopeScaledDepthBias = value;
}
}
}
private void UpdateNativeRasterizerState(Device device)
{
if (this.nativeRasterizerStateDirty == true || this.nativeRasterizerState == null)
{
if (this.nativeRasterizerState != null)
{
this.nativeRasterizerState.Dispose();
this.nativeRasterizerState = null;
}
this.nativeRasterizerState = new SharpDX.Direct3D11.RasterizerState(device, ref this.description);
this.nativeRasterizerStateDirty = false;
}
}
}
}

View File

@ -0,0 +1,103 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA.RenderSystem;
using SharpDX.Direct3D11;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class RenderTarget2D_DX11 : Texture2D_DX11, INativeRenderTarget2D, INativeTexture2D
{
#region Private Members
#endregion // Private Members
public RenderTarget2D_DX11(GraphicsDevice graphics, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
: base(graphics)
{
if (mipMap)
{
throw new NotImplementedException("creating RenderTargets with mip map not yet implemented");
}
this.surfaceFormat = surfaceFormat;
GraphicsDeviceWindowsDX11 graphicsDX11 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
SharpDX.Direct3D11.DeviceContext device = graphicsDX11.NativeDevice;
SharpDX.Direct3D11.Texture2DDescription description = new SharpDX.Direct3D11.Texture2DDescription()
{
Width = width,
Height = height,
MipLevels = 1,
ArraySize = 1,
Format = FormatConverter.Translate(preferredFormat),
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = SharpDX.Direct3D11.ResourceUsage.Default,
BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource | SharpDX.Direct3D11.BindFlags.RenderTarget,
CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None,
OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None,
};
this.nativeTexture = new SharpDX.Direct3D11.Texture2D(graphicsDX11.NativeDevice.Device, description);
this.nativeShaderResourceView = new SharpDX.Direct3D11.ShaderResourceView(graphicsDX11.NativeDevice.Device, this.nativeTexture);
// description of texture formats of DX10: http://msdn.microsoft.com/en-us/library/bb694531(v=VS.85).aspx
// more helpfull information on DX10 textures: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx
this.formatSize = FormatConverter.FormatSize(surfaceFormat);
}
}
}

View File

@ -0,0 +1,216 @@
#region Using Statements
using System;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D11;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class SamplerState_DX11 : INativeSamplerState
{
#region Private Members
private SamplerStateDescription description;
private SharpDX.Direct3D11.SamplerState nativeSamplerState;
private bool nativeSamplerStateDirty;
private bool bound;
#endregion // Private Members
public SamplerState_DX11()
{
this.description = new SamplerStateDescription();
this.nativeSamplerStateDirty = true;
}
public void Apply(GraphicsDevice graphicsDevice, int index)
{
GraphicsDeviceWindowsDX11 gdx11 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
DeviceContext context = gdx11.NativeDevice;
UpdateNativeSamplerState(context.Device);
this.bound = true;
context.PixelShader.SetSampler(index, this.nativeSamplerState);
}
public void Release()
{
this.bound = false;
}
public bool IsBound
{
get
{
return this.bound;
}
}
public ANX.Framework.Graphics.TextureAddressMode AddressU
{
set
{
SharpDX.Direct3D11.TextureAddressMode mode = FormatConverter.Translate(value);
if (description.AddressU != mode)
{
description.AddressU = mode;
nativeSamplerStateDirty = true;
}
}
}
public ANX.Framework.Graphics.TextureAddressMode AddressV
{
set
{
SharpDX.Direct3D11.TextureAddressMode mode = FormatConverter.Translate(value);
if (description.AddressV != mode)
{
description.AddressV = mode;
nativeSamplerStateDirty = true;
}
}
}
public ANX.Framework.Graphics.TextureAddressMode AddressW
{
set
{
SharpDX.Direct3D11.TextureAddressMode mode = FormatConverter.Translate(value);
if (description.AddressW != mode)
{
description.AddressW = mode;
nativeSamplerStateDirty = true;
}
}
}
public TextureFilter Filter
{
set
{
SharpDX.Direct3D11.Filter filter = FormatConverter.Translate(value);
if (description.Filter != filter)
{
description.Filter = filter;
nativeSamplerStateDirty = true;
}
}
}
public int MaxAnisotropy
{
set
{
if (description.MaximumAnisotropy != value)
{
description.MaximumAnisotropy = value;
nativeSamplerStateDirty = true;
}
}
}
public int MaxMipLevel
{
set
{
if (description.MaximumLod != value)
{
description.MaximumLod = value;
nativeSamplerStateDirty = true;
}
}
}
public float MipMapLevelOfDetailBias
{
set
{
if (description.MipLodBias != value)
{
description.MipLodBias = value;
nativeSamplerStateDirty = true;
}
}
}
public void Dispose()
{
if (this.nativeSamplerState != null)
{
this.nativeSamplerState.Dispose();
this.nativeSamplerState = null;
}
}
private void UpdateNativeSamplerState(Device device)
{
if (this.nativeSamplerStateDirty == true || this.nativeSamplerState == null)
{
if (this.nativeSamplerState != null)
{
this.nativeSamplerState.Dispose();
this.nativeSamplerState = null;
}
this.nativeSamplerState = new SharpDX.Direct3D11.SamplerState(device, ref this.description);
this.nativeSamplerStateDirty = false;
}
}
}
}

View File

@ -0,0 +1,217 @@
#region Using Statements
using System;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
internal static class ShaderByteCode
{
#region SpriteBatchShader
internal static byte[] SpriteBatchByteCode = new byte[]
{
068,
088, 066, 067, 025, 110, 120, 179, 245, 124, 038, 142, 158, 241, 235, 093, 024, 198, 181, 194, 001,
000, 000, 000, 128, 001, 000, 000, 001, 000, 000, 000, 036, 000, 000, 000, 070, 088, 049, 048, 084,
001, 000, 000, 001, 016, 255, 254, 001, 000, 000, 000, 001, 000, 000, 000, 002, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 168, 000, 000, 000, 000,
000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 036, 071, 108, 111, 098, 097, 108, 115, 000, 102, 108, 111, 097, 116, 052, 120, 052,
000, 013, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 064, 000, 000, 000, 064, 000, 000,
000, 064, 000, 000, 000, 011, 100, 000, 000, 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115,
102, 111, 114, 109, 000, 084, 101, 120, 116, 117, 114, 101, 050, 068, 000, 066, 000, 000, 000, 002,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 012,
000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 000, 083, 097, 109, 112, 108, 101, 114, 083, 116,
097, 116, 101, 000, 112, 000, 000, 000, 002, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 021, 000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 083,
097, 109, 112, 108, 101, 114, 000, 004, 000, 000, 000, 064, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 050, 000, 000, 000, 022, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 104,
000, 000, 000, 076, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 153,
000, 000, 000, 125, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 000,
000, 000, 000
};
#endregion //SpriteBatchShader
#region AlphaTestEffectShader
internal static byte[] AlphaTestEffectByteCode = new byte[]
{
068,
088, 066, 067, 025, 110, 120, 179, 245, 124, 038, 142, 158, 241, 235, 093, 024, 198, 181, 194, 001,
000, 000, 000, 128, 001, 000, 000, 001, 000, 000, 000, 036, 000, 000, 000, 070, 088, 049, 048, 084,
001, 000, 000, 001, 016, 255, 254, 001, 000, 000, 000, 001, 000, 000, 000, 002, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 168, 000, 000, 000, 000,
000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 036, 071, 108, 111, 098, 097, 108, 115, 000, 102, 108, 111, 097, 116, 052, 120, 052,
000, 013, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 064, 000, 000, 000, 064, 000, 000,
000, 064, 000, 000, 000, 011, 100, 000, 000, 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115,
102, 111, 114, 109, 000, 084, 101, 120, 116, 117, 114, 101, 050, 068, 000, 066, 000, 000, 000, 002,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 012,
000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 000, 083, 097, 109, 112, 108, 101, 114, 083, 116,
097, 116, 101, 000, 112, 000, 000, 000, 002, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 021, 000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 083,
097, 109, 112, 108, 101, 114, 000, 004, 000, 000, 000, 064, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 050, 000, 000, 000, 022, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 104,
000, 000, 000, 076, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 153,
000, 000, 000, 125, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 000,
000, 000, 000
};
#endregion //AlphaTestEffectShader
#region BasicEffectShader
internal static byte[] BasicEffectByteCode = new byte[]
{
068,
088, 066, 067, 025, 110, 120, 179, 245, 124, 038, 142, 158, 241, 235, 093, 024, 198, 181, 194, 001,
000, 000, 000, 128, 001, 000, 000, 001, 000, 000, 000, 036, 000, 000, 000, 070, 088, 049, 048, 084,
001, 000, 000, 001, 016, 255, 254, 001, 000, 000, 000, 001, 000, 000, 000, 002, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 168, 000, 000, 000, 000,
000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 036, 071, 108, 111, 098, 097, 108, 115, 000, 102, 108, 111, 097, 116, 052, 120, 052,
000, 013, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 064, 000, 000, 000, 064, 000, 000,
000, 064, 000, 000, 000, 011, 100, 000, 000, 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115,
102, 111, 114, 109, 000, 084, 101, 120, 116, 117, 114, 101, 050, 068, 000, 066, 000, 000, 000, 002,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 012,
000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 000, 083, 097, 109, 112, 108, 101, 114, 083, 116,
097, 116, 101, 000, 112, 000, 000, 000, 002, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 021, 000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 083,
097, 109, 112, 108, 101, 114, 000, 004, 000, 000, 000, 064, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 050, 000, 000, 000, 022, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 104,
000, 000, 000, 076, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 153,
000, 000, 000, 125, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 000,
000, 000, 000
};
#endregion //BasicEffectShader
#region DualTextureEffectShader
internal static byte[] DualTextureEffectByteCode = new byte[]
{
068,
088, 066, 067, 025, 110, 120, 179, 245, 124, 038, 142, 158, 241, 235, 093, 024, 198, 181, 194, 001,
000, 000, 000, 128, 001, 000, 000, 001, 000, 000, 000, 036, 000, 000, 000, 070, 088, 049, 048, 084,
001, 000, 000, 001, 016, 255, 254, 001, 000, 000, 000, 001, 000, 000, 000, 002, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 168, 000, 000, 000, 000,
000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 036, 071, 108, 111, 098, 097, 108, 115, 000, 102, 108, 111, 097, 116, 052, 120, 052,
000, 013, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 064, 000, 000, 000, 064, 000, 000,
000, 064, 000, 000, 000, 011, 100, 000, 000, 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115,
102, 111, 114, 109, 000, 084, 101, 120, 116, 117, 114, 101, 050, 068, 000, 066, 000, 000, 000, 002,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 012,
000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 000, 083, 097, 109, 112, 108, 101, 114, 083, 116,
097, 116, 101, 000, 112, 000, 000, 000, 002, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 021, 000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 083,
097, 109, 112, 108, 101, 114, 000, 004, 000, 000, 000, 064, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 050, 000, 000, 000, 022, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 104,
000, 000, 000, 076, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 153,
000, 000, 000, 125, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 000,
000, 000, 000
};
#endregion //DualTextureEffectShader
#region EnvironmentMapEffectShader
internal static byte[] EnvironmentMapEffectByteCode = new byte[]
{
068,
088, 066, 067, 025, 110, 120, 179, 245, 124, 038, 142, 158, 241, 235, 093, 024, 198, 181, 194, 001,
000, 000, 000, 128, 001, 000, 000, 001, 000, 000, 000, 036, 000, 000, 000, 070, 088, 049, 048, 084,
001, 000, 000, 001, 016, 255, 254, 001, 000, 000, 000, 001, 000, 000, 000, 002, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 168, 000, 000, 000, 000,
000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 036, 071, 108, 111, 098, 097, 108, 115, 000, 102, 108, 111, 097, 116, 052, 120, 052,
000, 013, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 064, 000, 000, 000, 064, 000, 000,
000, 064, 000, 000, 000, 011, 100, 000, 000, 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115,
102, 111, 114, 109, 000, 084, 101, 120, 116, 117, 114, 101, 050, 068, 000, 066, 000, 000, 000, 002,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 012,
000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 000, 083, 097, 109, 112, 108, 101, 114, 083, 116,
097, 116, 101, 000, 112, 000, 000, 000, 002, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 021, 000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 083,
097, 109, 112, 108, 101, 114, 000, 004, 000, 000, 000, 064, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 050, 000, 000, 000, 022, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 104,
000, 000, 000, 076, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 153,
000, 000, 000, 125, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 000,
000, 000, 000
};
#endregion //EnvironmentMapEffectShader
#region SkinnedEffectShader
internal static byte[] SkinnedEffectByteCode = new byte[]
{
068,
088, 066, 067, 025, 110, 120, 179, 245, 124, 038, 142, 158, 241, 235, 093, 024, 198, 181, 194, 001,
000, 000, 000, 128, 001, 000, 000, 001, 000, 000, 000, 036, 000, 000, 000, 070, 088, 049, 048, 084,
001, 000, 000, 001, 016, 255, 254, 001, 000, 000, 000, 001, 000, 000, 000, 002, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 168, 000, 000, 000, 000,
000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 036, 071, 108, 111, 098, 097, 108, 115, 000, 102, 108, 111, 097, 116, 052, 120, 052,
000, 013, 000, 000, 000, 001, 000, 000, 000, 000, 000, 000, 000, 064, 000, 000, 000, 064, 000, 000,
000, 064, 000, 000, 000, 011, 100, 000, 000, 077, 097, 116, 114, 105, 120, 084, 114, 097, 110, 115,
102, 111, 114, 109, 000, 084, 101, 120, 116, 117, 114, 101, 050, 068, 000, 066, 000, 000, 000, 002,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 012,
000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 000, 083, 097, 109, 112, 108, 101, 114, 083, 116,
097, 116, 101, 000, 112, 000, 000, 000, 002, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 021, 000, 000, 000, 084, 101, 120, 116, 117, 114, 101, 083,
097, 109, 112, 108, 101, 114, 000, 004, 000, 000, 000, 064, 000, 000, 000, 000, 000, 000, 000, 001,
000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 050, 000, 000, 000, 022, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 104,
000, 000, 000, 076, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 153,
000, 000, 000, 125, 000, 000, 000, 000, 000, 000, 000, 255, 255, 255, 255, 000, 000, 000, 000, 000,
000, 000, 000
};
#endregion //SkinnedEffectShader
}
}

View File

@ -0,0 +1,316 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Graphics;
using SharpDX.Direct3D11;
using ANX.Framework.NonXNA.RenderSystem;
using System.IO;
using System.Runtime.InteropServices;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class Texture2D_DX11 : INativeTexture2D
{
#region Private Members
protected internal SharpDX.Direct3D11.Texture2D nativeTexture;
protected internal SharpDX.Direct3D11.ShaderResourceView nativeShaderResourceView;
protected internal int formatSize;
protected internal SurfaceFormat surfaceFormat;
protected internal GraphicsDevice graphicsDevice;
#endregion // Private Members
internal Texture2D_DX11(GraphicsDevice graphicsDevice)
{
this.graphicsDevice = graphicsDevice;
}
public Texture2D_DX11(GraphicsDevice graphicsDevice, int width, int height, SurfaceFormat surfaceFormat, int mipCount)
{
if (mipCount > 1)
{
throw new Exception("creating textures with mip map not yet implemented");
}
this.graphicsDevice = graphicsDevice;
this.surfaceFormat = surfaceFormat;
GraphicsDeviceWindowsDX11 graphicsDX11 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
SharpDX.Direct3D11.DeviceContext context = graphicsDX11.NativeDevice;
SharpDX.Direct3D11.Texture2DDescription description = new SharpDX.Direct3D11.Texture2DDescription()
{
Width = width,
Height = height,
MipLevels = mipCount,
ArraySize = mipCount,
Format = FormatConverter.Translate(surfaceFormat),
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = SharpDX.Direct3D11.ResourceUsage.Dynamic,
BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource,
CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.Write,
OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None,
};
this.nativeTexture = new SharpDX.Direct3D11.Texture2D(context.Device, description);
this.nativeShaderResourceView = new SharpDX.Direct3D11.ShaderResourceView(context.Device, this.nativeTexture);
// description of texture formats of DX10: http://msdn.microsoft.com/en-us/library/bb694531(v=VS.85).aspx
// more helpfull information on DX10 textures: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205131(v=vs.85).aspx
this.formatSize = FormatConverter.FormatSize(surfaceFormat);
}
public override int GetHashCode()
{
return NativeTexture.NativePointer.ToInt32();
}
internal SharpDX.Direct3D11.Texture2D NativeTexture
{
get
{
return this.nativeTexture;
}
set
{
if (this.nativeTexture != value)
{
if (this.nativeTexture != null)
{
this.nativeTexture.Dispose();
}
this.nativeTexture = value;
}
}
}
internal SharpDX.Direct3D11.ShaderResourceView NativeShaderResourceView
{
get
{
return this.nativeShaderResourceView;
}
set
{
if (this.nativeShaderResourceView != value)
{
if (this.nativeShaderResourceView != null)
{
this.nativeShaderResourceView.Dispose();
}
this.nativeShaderResourceView = value;
}
}
}
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct
{
SetData<T>(graphicsDevice, 0, data, 0, data.Length);
}
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data, int startIndex, int elementCount) where T : struct
{
SetData<T>(graphicsDevice, 0, data, startIndex, elementCount);
}
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
{
//TODO: handle offsetInBytes parameter
//TODO: handle startIndex parameter
//TODO: handle elementCount parameter
GraphicsDeviceWindowsDX11 dx11GraphicsDevice = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
DeviceContext context = dx11GraphicsDevice.NativeDevice;
if (this.surfaceFormat == SurfaceFormat.Color)
{
int subresource = SharpDX.Direct3D11.Texture2D.CalculateSubResourceIndex(0, 0, 1);
SharpDX.DataBox rectangle = context.MapSubresource(this.nativeTexture, subresource, MapMode.WriteDiscard, MapFlags.None);
int rowPitch = rectangle.RowPitch;
unsafe
{
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
byte* colorData = (byte*)handle.AddrOfPinnedObject();
byte* pTexels = (byte*)rectangle.DataPointer;
int srcIndex = 0;
for (int row = 0; row < Height; row++)
{
int rowStart = row * rowPitch;
for (int col = 0; col < Width; col++)
{
int colStart = col * formatSize;
pTexels[rowStart + colStart + 0] = colorData[srcIndex++];
pTexels[rowStart + colStart + 1] = colorData[srcIndex++];
pTexels[rowStart + colStart + 2] = colorData[srcIndex++];
pTexels[rowStart + colStart + 3] = colorData[srcIndex++];
}
}
handle.Free();
}
context.UnmapSubresource(this.nativeTexture, subresource);
}
else if (surfaceFormat == SurfaceFormat.Dxt5 || surfaceFormat == SurfaceFormat.Dxt3 || surfaceFormat == SurfaceFormat.Dxt1)
{
unsafe
{
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
byte* colorData = (byte*)handle.AddrOfPinnedObject();
int w = (Width + 3) >> 2;
int h = (Height + 3) >> 2;
formatSize = (surfaceFormat == SurfaceFormat.Dxt1) ? 8 : 16;
int subresource = SharpDX.Direct3D11.Texture2D.CalculateSubResourceIndex(0, 0, 1);
SharpDX.DataBox rectangle = context.MapSubresource(this.nativeTexture, subresource, MapMode.WriteDiscard, MapFlags.None);
SharpDX.DataStream ds = new SharpDX.DataStream(rectangle.DataPointer, Width * Height * 4 * 2, true, true);
int pitch = rectangle.RowPitch;
int col = 0;
int index = 0; // startIndex
int count = data.Length; // elementCount
int actWidth = w * formatSize;
for (int i = 0; i < h; i++)
{
ds.Position = (i * pitch) + (col * formatSize);
if (count <= 0)
{
break;
}
else if (count < actWidth)
{
for (int idx = index; idx < index + count; idx++)
{
ds.WriteByte(colorData[idx]);
}
break;
}
for (int idx = index; idx < index + actWidth; idx++)
{
ds.WriteByte(colorData[idx]);
}
index += actWidth;
count -= actWidth;
}
handle.Free();
context.UnmapSubresource(this.nativeTexture, subresource);
}
}
else
{
throw new Exception(string.Format("creating textures of format {0} not yet implemented...", surfaceFormat.ToString()));
}
}
public int Width
{
get
{
if (this.nativeTexture != null)
{
return this.nativeTexture.Description.Width;
}
return 0;
}
}
public int Height
{
get
{
if (this.nativeTexture != null)
{
return this.nativeTexture.Description.Height;
}
return 0;
}
}
public GraphicsDevice GraphicsDevice
{
get
{
return this.graphicsDevice;
}
}
public void Dispose()
{
if (this.nativeShaderResourceView != null)
{
this.nativeShaderResourceView.Dispose();
this.nativeShaderResourceView = null;
}
if (this.nativeTexture != null)
{
this.nativeTexture.Dispose();
this.nativeTexture = null;
}
}
}
}

View File

@ -6,6 +6,7 @@ using System.Text;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D11;
using ANX.Framework.Graphics;
using System.Runtime.InteropServices;
#endregion // Using Statements
@ -68,11 +69,11 @@ namespace ANX.RenderSystem.Windows.DX11
this.vertexStride = vertexDeclaration.VertexStride;
//TODO: translate and use usage
GraphicsDeviceWindowsDX11 gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11;
SharpDX.Direct3D11.Device device = gd11 != null ? gd11.NativeDevice as SharpDX.Direct3D11.Device : null;
if (device != null)
GraphicsDeviceWindowsDX11 gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11;
SharpDX.Direct3D11.DeviceContext context = gd11 != null ? gd11.NativeDevice as SharpDX.Direct3D11.DeviceContext : null;
if (context != null)
{
BufferDescription description = new BufferDescription()
{
@ -83,7 +84,7 @@ namespace ANX.RenderSystem.Windows.DX11
OptionFlags = ResourceOptionFlags.None
};
this.buffer = new SharpDX.Direct3D11.Buffer(device, description);
this.buffer = new SharpDX.Direct3D11.Buffer(context.Device, description);
//this.buffer.Unmap();
}
}
@ -95,25 +96,33 @@ namespace ANX.RenderSystem.Windows.DX11
throw new NotImplementedException("currently starIndex and elementCount of SetData are not implemented");
}
GraphicsDeviceWindowsDX11 dx11GraphicsDevice = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
DeviceContext context = dx11GraphicsDevice.NativeDevice;
//TODO: check offsetInBytes parameter for bounds etc.
throw new NotImplementedException();
GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
IntPtr dataPointer = pinnedArray.AddrOfPinnedObject();
/*
using (var vData = new SharpDX.DataStream(data, true, false))
int dataLength = Marshal.SizeOf(typeof(T)) * data.Length;
unsafe
{
if (offsetInBytes > 0)
using (var vData = new SharpDX.DataStream(dataPointer, dataLength, true, false))
{
vData.Seek(offsetInBytes / vertexStride, System.IO.SeekOrigin.Begin);
}
if (offsetInBytes > 0)
{
vData.Seek(offsetInBytes / vertexStride, System.IO.SeekOrigin.Begin);
}
using (var d = buffer.Map(MapMode.WriteDiscard))
{
vData.CopyTo(d);
buffer.Unmap();
SharpDX.DataStream stream;
SharpDX.DataBox box = context.MapSubresource(this.buffer, MapMode.WriteDiscard, MapFlags.None, out stream);
vData.CopyTo(stream);
context.UnmapSubresource(this.buffer, 0);
}
}
*/
pinnedArray.Free();
}
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct

View File

@ -0,0 +1,137 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ANX.Framework.Windows.DX10;
using ANX.Framework.Input;
using ANX.Framework;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
public class WindowsGameHost : GameHost
{
private Game game;
private WindowsGameWindow gameWindow;
private bool exitRequested;
public WindowsGameHost(Game game)
: base(game)
{
this.game = game;
//this.LockThreadToProcessor();
this.gameWindow = new WindowsGameWindow();
Mouse.WindowHandle = this.gameWindow.Handle; //TODO: find a way to initialize all InputSystems with one Handle
Keyboard.WindowHandle = this.gameWindow.Handle;
//TouchPanel.WindowHandle = this.gameWindow.Handle;
//this.gameWindow.IsMouseVisible = game.IsMouseVisible;
this.gameWindow.Activated += new EventHandler<EventArgs>(this.GameWindowActivated);
this.gameWindow.Deactivated += new EventHandler<EventArgs>(this.GameWindowDeactivated);
//this.gameWindow.Suspend += new EventHandler<EventArgs>(this.GameWindowSuspend);
//this.gameWindow.Resume += new EventHandler<EventArgs>(this.GameWindowResume);
}
public override void Run()
{
Application.Idle += new EventHandler(this.ApplicationIdle);
Application.Run(this.gameWindow.Form);
Application.Idle -= this.ApplicationIdle;
}
public void RunOneFrame()
{
//this.gameWindow.Tick();
base.OnIdle();
}
public override GameWindow Window
{
get
{
return this.gameWindow;
}
}
public override void Exit()
{
this.exitRequested = true;
}
private void GameWindowActivated(object sender, EventArgs e)
{
base.OnActivated();
}
private void GameWindowDeactivated(object sender, EventArgs e)
{
base.OnDeactivated();
}
private void ApplicationIdle(object sender, EventArgs e)
{
NativeMethods.Message message;
while (!NativeMethods.PeekMessage(out message, IntPtr.Zero, 0, 0, 0))
{
if (this.exitRequested)
{
this.gameWindow.Close();
}
else
{
this.RunOneFrame();
}
}
}
}
}

View File

@ -0,0 +1,163 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpDX.Windows;
using ANX.Framework;
#endregion // Using Statements
#region License
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
#endregion // License
namespace ANX.RenderSystem.Windows.DX11
{
internal class WindowsGameWindow : GameWindow
{
#region Private Members
private RenderForm gameWindow;
#endregion // Private Members
internal WindowsGameWindow()
{
this.gameWindow = new RenderForm("ANX.Framework");
this.gameWindow.Width = 800;
this.gameWindow.Height = 480;
this.gameWindow.MaximizeBox = false;
this.gameWindow.FormBorderStyle = FormBorderStyle.Fixed3D;
}
public void Close()
{
if (gameWindow != null)
{
gameWindow.Close();
}
}
public Form Form
{
get
{
return gameWindow;
}
}
public override IntPtr Handle
{
get
{
return gameWindow.Handle;
}
}
public override bool IsMinimized
{
get
{
return gameWindow.WindowState == FormWindowState.Minimized;
}
}
public override void BeginScreenDeviceChange(bool willBeFullScreen)
{
throw new NotImplementedException();
}
public override void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)
{
throw new NotImplementedException();
}
protected override void SetTitle(string title)
{
this.gameWindow.Text = title;
}
public override bool AllowUserResizing
{
get
{
return gameWindow.FormBorderStyle == FormBorderStyle.Sizable;
}
set
{
if (value)
{
gameWindow.FormBorderStyle = FormBorderStyle.Sizable;
}
else
{
gameWindow.FormBorderStyle = FormBorderStyle.Fixed3D;
}
}
}
public override Rectangle ClientBounds
{
get
{
return new Rectangle(this.gameWindow.ClientRectangle.Left, this.gameWindow.ClientRectangle.Top, this.gameWindow.ClientRectangle.Width, this.gameWindow.ClientRectangle.Height);
}
}
public override string ScreenDeviceName
{
get { throw new NotImplementedException(); }
}
public override DisplayOrientation CurrentOrientation
{
get { throw new NotImplementedException(); }
}
}
}

View File

@ -11,7 +11,9 @@ namespace WindowsGame1
/// </summary>
static void Main(string[] args)
{
//AddInSystemFactory.Instance.PreferredRenderSystem = "OpenGL3";
//AddInSystemFactory.Instance.PreferredRenderSystem = "OpenGL3";
//AddInSystemFactory.Instance.PreferredRenderSystem = "DirectX11";
using (Game1 game = new Game1())
{
game.Run();

View File

@ -95,6 +95,10 @@
<Project>{EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}</Project>
<Name>ANX.Framework.Windows.GL3</Name>
</ProjectReference>
<ProjectReference Include="..\..\RenderSystems\ANX.RenderSystem.Windows.DX11\ANX.RenderSystem.Windows.DX11.csproj">
<Project>{B30DE9C2-0926-46B6-8351-9AF276C472D5}</Project>
<Name>ANX.RenderSystem.Windows.DX11</Name>
</ProjectReference>
<ProjectReference Include="..\..\SoundSystems\ANX.SoundSystem.Windows.XAudio\ANX.SoundSystem.Windows.XAudio.csproj">
<Project>{6A582788-C4D2-410C-96CD-177F75712D65}</Project>
<Name>ANX.SoundSystem.Windows.XAudio</Name>

View File

@ -6,6 +6,7 @@ using System.Text;
using ANX.Framework.Windows.DX10;
using ANX.Framework.Windows.GL3;
using System.IO;
using ANX.RenderSystem.Windows.DX11;
#endregion // Using Statements
@ -103,6 +104,9 @@ namespace StockShaderCodeGenerator
case "ANX.Framework.Windows.DX10":
byteCode = Effect_DX10.CompileFXShader(sourceCode);
break;
case "ANX.RenderSystem.Windows.DX11":
byteCode = Effect_DX11.CompileFXShader(sourceCode);
break;
case "ANX.Framework.Windows.GL3":
byteCode = EffectGL3.CompileShader(sourceCode);
break;

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.8.0.*")]
[assembly: AssemblyFileVersion("0.8.0.0")]
[assembly: AssemblyVersion("0.8.1.*")]
[assembly: AssemblyFileVersion("0.8.1.0")]

View File

@ -63,6 +63,10 @@
<Project>{EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}</Project>
<Name>ANX.Framework.Windows.GL3</Name>
</ProjectReference>
<ProjectReference Include="..\..\RenderSystems\ANX.RenderSystem.Windows.DX11\ANX.RenderSystem.Windows.DX11.csproj">
<Project>{B30DE9C2-0926-46B6-8351-9AF276C472D5}</Project>
<Name>ANX.RenderSystem.Windows.DX11</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -125,6 +125,7 @@
<arg value='/p:Platform="${build.platform}"'/>
<arg value="/p:OutputPath=../${build.dir}/${build.configuration}" />
<arg value='/p:DefineConstants="${project.anx.directives}"' />
<arg value="/p:AllowUnsafeBlocks=true" />
<arg value="/clp:ErrorsOnly" />
<arg value="${project.anx.path.rendersystem.dx11}/${project.anx.name.rendersystem.dx11}.csproj" />
</exec>
@ -323,6 +324,14 @@
<arg value="../shader/DX10/build.xml" />
</exec>
<echo message="===================================================" />
<echo message="Now generating code for DirectX 11 stock shaders" />
<echo message="===================================================" />
<exec program="sscg.exe" >
<arg value="../shader/DX11/build.xml" />
</exec>
<echo message="===================================================" />
<echo message="Now generating code for OpenGL 3 stock shaders" />
<echo message="===================================================" />

View File

@ -1,2 +1,3 @@
../Tools/bin/sscg.exe ../shader/DX10/build.xml
../Tools/bin/sscg.exe ../shader/DX11/build.xml
../Tools/bin/sscg.exe ../shader/GL3/build.xml

90
shader/DX11/AlphaTest.fx Normal file
View File

@ -0,0 +1,90 @@
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
//TODO: dummy implementation / placeholder
uniform extern float4x4 MatrixTransform;
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
{
float4 pos : POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
PixelShaderInput AlphaTestVertexShader( VertexShaderInput input )
{
PixelShaderInput output = (PixelShaderInput)0;
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
return output;
}
float4 AlphaTestPixelShader( PixelShaderInput input ) : SV_Target
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
}
technique11 AlphaTest
{
pass AlphaTestPass
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, AlphaTestVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, AlphaTestPixelShader() ) );
}
}

View File

@ -0,0 +1,89 @@
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
//TODO: dummy implementation / placeholder
uniform extern float4x4 MatrixTransform;
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
{
float4 pos : POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
PixelShaderInput AlphaTestVertexShader( VertexShaderInput input )
{
PixelShaderInput output = (PixelShaderInput)0;
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
return output;
}
float4 AlphaTestPixelShader( PixelShaderInput input ) : SV_Target
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
}
technique11 AlphaTest
{
pass AlphaTestPass
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, AlphaTestVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, AlphaTestPixelShader() ) );
}
}

View File

@ -0,0 +1,89 @@
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
//TODO: dummy implementation / placeholder
uniform extern float4x4 MatrixTransform;
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
{
float4 pos : POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
PixelShaderInput AlphaTestVertexShader( VertexShaderInput input )
{
PixelShaderInput output = (PixelShaderInput)0;
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
return output;
}
float4 AlphaTestPixelShader( PixelShaderInput input ) : SV_Target
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
}
technique11 AlphaTest
{
pass AlphaTestPass
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, AlphaTestVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, AlphaTestPixelShader() ) );
}
}

View File

@ -0,0 +1,89 @@
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
//TODO: dummy implementation / placeholder
uniform extern float4x4 MatrixTransform;
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
{
float4 pos : POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
PixelShaderInput AlphaTestVertexShader( VertexShaderInput input )
{
PixelShaderInput output = (PixelShaderInput)0;
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
return output;
}
float4 AlphaTestPixelShader( PixelShaderInput input ) : SV_Target
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
}
technique11 AlphaTest
{
pass AlphaTestPass
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, AlphaTestVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, AlphaTestPixelShader() ) );
}
}

89
shader/DX11/Skinned.fx Normal file
View File

@ -0,0 +1,89 @@
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
//TODO: dummy implementation / placeholder
uniform extern float4x4 MatrixTransform;
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
{
float4 pos : POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
PixelShaderInput AlphaTestVertexShader( VertexShaderInput input )
{
PixelShaderInput output = (PixelShaderInput)0;
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
return output;
}
float4 AlphaTestPixelShader( PixelShaderInput input ) : SV_Target
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
}
technique11 AlphaTest
{
pass AlphaTestPass
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, AlphaTestVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, AlphaTestPixelShader() ) );
}
}

View File

@ -0,0 +1,87 @@
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
uniform extern float4x4 MatrixTransform;
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
struct VertexShaderInput
{
float4 pos : POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float4 col : COLOR;
float2 tex : TEXCOORD0;
};
PixelShaderInput SpriteVertexShader( VertexShaderInput input )
{
PixelShaderInput output = (PixelShaderInput)0;
output.pos = mul(input.pos, MatrixTransform);
output.col = input.col;
output.tex = input.tex;
return output;
}
float4 SpritePixelShader( PixelShaderInput input ) : SV_Target
{
return Texture.Sample(TextureSampler, input.tex) * input.col;
}
technique11 SpriteTechnique
{
pass SpriteColorPass
{
SetGeometryShader( 0 );
SetVertexShader( CompileShader( vs_4_0, SpriteVertexShader() ) );
SetPixelShader( CompileShader( ps_4_0, SpritePixelShader() ) );
}
}

29
shader/DX11/build.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<Build License="../doc/license.txt"
Target="../RenderSystems/ANX.RenderSystem.Windows.DX11/ShaderByteCode.cs"
Namespace="ANX.RenderSystem.Windows.DX11">
<Shader Type="SpriteBatch"
Source="../Shader/DX11/SpriteBatch.fx"
RenderSystem="ANX.RenderSystem.Windows.DX11"
/>
<Shader Type="AlphaTestEffect"
Source="../Shader/DX11/AlphaTest.fx"
RenderSystem="ANX.RenderSystem.Windows.DX11"
/>
<Shader Type="BasicEffect"
Source="../Shader/DX11/BasicEffect.fx"
RenderSystem="ANX.RenderSystem.Windows.DX11"
/>
<Shader Type="DualTextureEffect"
Source="../Shader/DX11/DualTexture.fx"
RenderSystem="ANX.RenderSystem.Windows.DX11"
/>
<Shader Type="EnvironmentMapEffect"
Source="../Shader/DX11/EnvironmentMap.fx"
RenderSystem="ANX.RenderSystem.Windows.DX11"
/>
<Shader Type="SkinnedEffect"
Source="../Shader/DX11/Skinned.fx"
RenderSystem="ANX.RenderSystem.Windows.DX11"
/>
</Build>