- Wrote the DualTexture shader for GL3 but the rendering is not working yet

- Huge refactoring in the Dx10 RenderSystem + increasing much performance
This commit is contained in:
SND\AstrorEnales_cp 2012-09-06 09:58:13 +00:00
parent e1a2a05e88
commit dd173478d6
33 changed files with 1974 additions and 1929 deletions

View File

@ -45,7 +45,6 @@ namespace ANX.Framework
private ContentManager content;
private GameComponentCollection components;
private List<IGameComponent> drawableGameComponents;
#endregion
@ -93,9 +92,9 @@ namespace ANX.Framework
this.TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 60L); // default is 1/60s
//TODO: implement draw- and update-order handling of GameComponents
this.components = new GameComponentCollection();
this.components.ComponentAdded += components_ComponentAdded;
this.components.ComponentRemoved += components_ComponentRemoved;
this.Components = new GameComponentCollection();
this.Components.ComponentAdded += components_ComponentAdded;
this.Components.ComponentRemoved += components_ComponentRemoved;
this.drawableGameComponents = new List<IGameComponent>();
Logger.Info("finished initializing new Game class");
@ -105,8 +104,8 @@ namespace ANX.Framework
~Game()
{
this.components.ComponentAdded -= components_ComponentAdded;
this.components.ComponentRemoved -= components_ComponentRemoved;
this.Components.ComponentAdded -= components_ComponentAdded;
this.Components.ComponentRemoved -= components_ComponentRemoved;
Dispose(false);
}
@ -150,7 +149,7 @@ namespace ANX.Framework
protected virtual void Update(GameTime gameTime)
{
foreach (IUpdateable updateable in this.components)
foreach (IUpdateable updateable in this.Components)
{
if (updateable.Enabled)
{
@ -478,8 +477,8 @@ namespace ANX.Framework
if (disposing)
{
IDisposable disposable;
var array = new IGameComponent[components.Count];
components.CopyTo(array, 0);
var array = new IGameComponent[Components.Count];
Components.CopyTo(array, 0);
for (int i = 0; i < array.Length; i++)
{
disposable = (IDisposable)array[i];

View File

@ -30,9 +30,7 @@ namespace ANX.Framework
protected override void ClearItems()
{
for (int i = 0; i < base.Count; i++)
{
OnComponentRemoved(base[i]);
}
base.Clear();
}
@ -40,9 +38,7 @@ namespace ANX.Framework
protected override void InsertItem(int index, IGameComponent item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
base.Insert(index, item);
OnComponentAdded(item);
@ -64,17 +60,13 @@ namespace ANX.Framework
private void OnComponentAdded(IGameComponent component)
{
if (ComponentAdded != null)
{
ComponentAdded(this, new GameComponentCollectionEventArgs(component));
}
}
private void OnComponentRemoved(IGameComponent component)
{
if (ComponentRemoved != null)
{
ComponentRemoved(this, new GameComponentCollectionEventArgs(component));
}
}
}
}

View File

@ -9,9 +9,8 @@ namespace ANX.Framework.Graphics
{
public class AlphaTestEffect : Effect, IEffectMatrices, IEffectFog, IGraphicsResource
{
public AlphaTestEffect(GraphicsDevice device)
: base(device, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode(
NonXNA.PreDefinedShader.AlphaTestEffect))
public AlphaTestEffect(GraphicsDevice device)
: base(device, GetByteCode(), GetSourceLanguage())
{
throw new NotImplementedException();
}
@ -20,7 +19,23 @@ namespace ANX.Framework.Graphics
: base(cloneSource)
{
throw new NotImplementedException();
}
}
#region GetByteCode
private static byte[] GetByteCode()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetShaderByteCode(PreDefinedShader.AlphaTestEffect);
}
#endregion
#region GetSourceLanguage
private static EffectSourceLanguage GetSourceLanguage()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetStockShaderSourceLanguage;
}
#endregion
public override Effect Clone()
{

View File

@ -30,8 +30,8 @@ namespace ANX.Framework.Graphics
private DirectionalLight[] directionalLight;
private Vector3 ambientLightColor;
public BasicEffect(GraphicsDevice graphics)
: base(graphics, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode(NonXNA.PreDefinedShader.BasicEffect))
public BasicEffect(GraphicsDevice graphics)
: base(graphics, GetByteCode(), GetSourceLanguage())
{
world = base.Parameters["World"];
view = base.Parameters["View"];
@ -54,7 +54,23 @@ namespace ANX.Framework.Graphics
: base(cloneSource)
{
throw new NotImplementedException();
}
}
#region GetByteCode
private static byte[] GetByteCode()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetShaderByteCode(PreDefinedShader.BasicEffect);
}
#endregion
#region GetSourceLanguage
private static EffectSourceLanguage GetSourceLanguage()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetStockShaderSourceLanguage;
}
#endregion
public bool PreferPerPixelLighting
{

View File

@ -83,8 +83,7 @@ namespace ANX.Framework.Graphics
#region Constructor
public DualTextureEffect(GraphicsDevice graphics)
: base(graphics, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode(
NonXNA.PreDefinedShader.DualTextureEffect))
: base(graphics, GetByteCode(), GetSourceLanguage())
{
diffuseColor = Vector3.One;
Alpha = 1f;
@ -114,6 +113,22 @@ namespace ANX.Framework.Graphics
}
#endregion
#region GetByteCode
private static byte[] GetByteCode()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetShaderByteCode(PreDefinedShader.DualTextureEffect);
}
#endregion
#region GetSourceLanguage
private static EffectSourceLanguage GetSourceLanguage()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetStockShaderSourceLanguage;
}
#endregion
#region Clone
public override Effect Clone()
{

View File

@ -15,8 +15,8 @@ namespace ANX.Framework.Graphics
{
public class EnvironmentMapEffect : Effect, IEffectMatrices, IEffectLights, IEffectFog
{
public EnvironmentMapEffect(GraphicsDevice graphics)
: base(graphics, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode(NonXNA.PreDefinedShader.EnvironmentMapEffect))
public EnvironmentMapEffect(GraphicsDevice graphics)
: base(graphics, GetByteCode(), GetSourceLanguage())
{
throw new NotImplementedException();
}
@ -25,7 +25,23 @@ namespace ANX.Framework.Graphics
: base(cloneSource)
{
throw new NotImplementedException();
}
}
#region GetByteCode
private static byte[] GetByteCode()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetShaderByteCode(PreDefinedShader.EnvironmentMapEffect);
}
#endregion
#region GetSourceLanguage
private static EffectSourceLanguage GetSourceLanguage()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetStockShaderSourceLanguage;
}
#endregion
public override Effect Clone()
{

View File

@ -18,8 +18,8 @@ namespace ANX.Framework.Graphics
{
public class SkinnedEffect : Effect, IEffectMatrices, IEffectLights, IEffectFog
{
public SkinnedEffect(GraphicsDevice graphics)
: base(graphics, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode(NonXNA.PreDefinedShader.SkinnedEffect))
public SkinnedEffect(GraphicsDevice graphics)
: base(graphics, GetByteCode(), GetSourceLanguage())
{
throw new NotImplementedException();
}
@ -28,7 +28,23 @@ namespace ANX.Framework.Graphics
: base(cloneSource)
{
throw new NotImplementedException();
}
}
#region GetByteCode
private static byte[] GetByteCode()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetShaderByteCode(PreDefinedShader.SkinnedEffect);
}
#endregion
#region GetSourceLanguage
private static EffectSourceLanguage GetSourceLanguage()
{
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
return creator.GetStockShaderSourceLanguage;
}
#endregion
public override Effect Clone()
{

View File

@ -82,9 +82,10 @@
<Compile Include="EffectParameter_DX10.cs" />
<Compile Include="EffectTechnique_DX10.cs" />
<Compile Include="Effect_DX10.cs" />
<Compile Include="FormatConverter.cs" />
<Compile Include="Helpers\FormatConverter.cs" />
<Compile Include="GraphicsDeviceWindowsDX10.cs" />
<Compile Include="IncludeHandler.cs" />
<Compile Include="Helpers\IncludeHandler.cs" />
<Compile Include="Helpers\WindowHelper.cs" />
<Compile Include="IndexBuffer_DX10.cs" />
<Compile Include="EffectPass_DX10.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -82,9 +82,10 @@
<Compile Include="EffectParameter_DX10.cs" />
<Compile Include="EffectTechnique_DX10.cs" />
<Compile Include="Effect_DX10.cs" />
<Compile Include="FormatConverter.cs" />
<Compile Include="Helpers\FormatConverter.cs" />
<Compile Include="GraphicsDeviceWindowsDX10.cs" />
<Compile Include="IncludeHandler.cs" />
<Compile Include="Helpers\IncludeHandler.cs" />
<Compile Include="Helpers\WindowHelper.cs" />
<Compile Include="IndexBuffer_DX10.cs" />
<Compile Include="EffectPass_DX10.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -83,9 +83,10 @@
<Compile Include="EffectParameter_DX10.cs" />
<Compile Include="EffectTechnique_DX10.cs" />
<Compile Include="Effect_DX10.cs" />
<Compile Include="FormatConverter.cs" />
<Compile Include="Helpers\FormatConverter.cs" />
<Compile Include="GraphicsDeviceWindowsDX10.cs" />
<Compile Include="IncludeHandler.cs" />
<Compile Include="Helpers\IncludeHandler.cs" />
<Compile Include="Helpers\WindowHelper.cs" />
<Compile Include="IndexBuffer_DX10.cs" />
<Compile Include="EffectPass_DX10.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -84,9 +84,10 @@
<Compile Include="EffectParameter_DX10.cs" />
<Compile Include="EffectTechnique_DX10.cs" />
<Compile Include="Effect_DX10.cs" />
<Compile Include="FormatConverter.cs" />
<Compile Include="Helpers\FormatConverter.cs" />
<Compile Include="GraphicsDeviceWindowsDX10.cs" />
<Compile Include="IncludeHandler.cs" />
<Compile Include="Helpers\IncludeHandler.cs" />
<Compile Include="Helpers\WindowHelper.cs" />
<Compile Include="IndexBuffer_DX10.cs" />
<Compile Include="EffectPass_DX10.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -1,14 +1,8 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Direct3D10;
using ANX.Framework;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using ANX.Framework;
#endregion // Using Statements
using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -18,236 +12,193 @@ namespace ANX.RenderSystem.Windows.DX10
{
public class BlendState_DX10 : INativeBlendState
{
#region Private Members
private BlendStateDescription description;
private SharpDX.Direct3D10.BlendState nativeBlendState;
private bool nativeBlendStateDirty;
private const float ColorByteToFloatFactor = 1f / 255f;
#region Private
private Dx10.BlendStateDescription description;
private Dx10.BlendState nativeBlendState;
private bool isDirty;
private SharpDX.Color4 blendFactor;
private int multiSampleMask;
private bool bound;
#endregion
#endregion // Private Members
#region Public
public bool IsBound
{
get;
private set;
}
public BlendState_DX10()
{
this.description = new BlendStateDescription();
public Color BlendFactor
{
set
{
blendFactor.Red = value.R * ColorByteToFloatFactor;
blendFactor.Green = value.G * ColorByteToFloatFactor;
blendFactor.Blue = value.B * ColorByteToFloatFactor;
blendFactor.Alpha = value.A * ColorByteToFloatFactor;
}
}
public int MultiSampleMask
{
set
{
multiSampleMask = value;
}
}
public BlendFunction AlphaBlendFunction
{
set
{
Dx10.BlendOperation alphaBlendOperation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.AlphaBlendOperation, ref alphaBlendOperation);
}
}
public BlendFunction ColorBlendFunction
{
set
{
Dx10.BlendOperation blendOperation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BlendOperation, ref blendOperation);
}
}
public Blend AlphaDestinationBlend
{
set
{
Dx10.BlendOption destinationAlphaBlend = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.DestinationAlphaBlend, ref destinationAlphaBlend);
}
}
public Blend ColorDestinationBlend
{
set
{
Dx10.BlendOption destinationBlend = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.DestinationBlend, ref destinationBlend);
}
}
public ColorWriteChannels ColorWriteChannels
{
set
{
Dx10.ColorWriteMaskFlags writeMask = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.RenderTargetWriteMask[0], ref writeMask);
}
}
public ColorWriteChannels ColorWriteChannels1
{
set
{
Dx10.ColorWriteMaskFlags writeMask = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.RenderTargetWriteMask[1], ref writeMask);
}
}
public ColorWriteChannels ColorWriteChannels2
{
set
{
Dx10.ColorWriteMaskFlags writeMask = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.RenderTargetWriteMask[2], ref writeMask);
}
}
public ColorWriteChannels ColorWriteChannels3
{
set
{
Dx10.ColorWriteMaskFlags writeMask = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.RenderTargetWriteMask[3], ref writeMask);
}
}
public Blend AlphaSourceBlend
{
set
{
Dx10.BlendOption sourceAlphaBlend = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.SourceAlphaBlend, ref sourceAlphaBlend);
}
}
public Blend ColorSourceBlend
{
set
{
Dx10.BlendOption sourceBlend = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.SourceBlend, ref sourceBlend);
}
}
#endregion
#region Constructor
public BlendState_DX10()
{
isDirty = true;
for (int i = 0; i < description.IsBlendEnabled.Length; i++)
{
description.IsBlendEnabled[i] = (i < 4);
}
nativeBlendStateDirty = true;
}
#endregion
public void Apply(GraphicsDevice graphics)
#region Apply
public void Apply(GraphicsDevice graphics)
{
GraphicsDeviceWindowsDX10 gdx10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = gdx10.NativeDevice;
Dx10.Device device = (graphics.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
UpdateNativeBlendState(device);
this.bound = true;
IsBound = true;
device.OutputMerger.SetBlendState(nativeBlendState, this.blendFactor, this.multiSampleMask);
device.OutputMerger.SetBlendState(nativeBlendState, blendFactor, multiSampleMask);
}
#endregion
public void Release()
#region Release
public void Release()
{
this.bound = false;
}
IsBound = false;
}
#endregion
public void Dispose()
#region Dispose
public void Dispose()
{
if (this.nativeBlendState != null)
if (nativeBlendState != null)
{
this.nativeBlendState.Dispose();
this.nativeBlendState = null;
nativeBlendState.Dispose();
nativeBlendState = null;
}
}
#endregion
#region UpdateNativeBlendState
private void UpdateNativeBlendState(Dx10.Device device)
{
if (isDirty || nativeBlendState == null)
{
Dispose();
nativeBlendState = new Dx10.BlendState(device, ref description);
isDirty = false;
}
}
#endregion
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);
if (description.AlphaBlendOperation != alphaBlendOperation)
{
nativeBlendStateDirty = true;
description.AlphaBlendOperation = alphaBlendOperation;
}
}
}
public BlendFunction ColorBlendFunction
{
set
{
BlendOperation blendOperation = FormatConverter.Translate(value);
if (description.BlendOperation != blendOperation)
{
nativeBlendStateDirty = true;
description.BlendOperation = blendOperation;
}
}
}
public Blend AlphaDestinationBlend
{
set
{
BlendOption destinationAlphaBlend = FormatConverter.Translate(value);
if (description.DestinationAlphaBlend != destinationAlphaBlend)
{
nativeBlendStateDirty = true;
description.DestinationAlphaBlend = destinationAlphaBlend;
}
}
}
public Blend ColorDestinationBlend
{
set
{
BlendOption destinationBlend = FormatConverter.Translate(value);
if (description.DestinationBlend != destinationBlend)
{
nativeBlendStateDirty = true;
description.DestinationBlend = destinationBlend;
}
}
}
public ColorWriteChannels ColorWriteChannels
{
set
{
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value);
if (description.RenderTargetWriteMask[0] != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
description.RenderTargetWriteMask[0] = renderTargetWriteMask;
}
}
}
public ColorWriteChannels ColorWriteChannels1
{
set
{
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value);
if (description.RenderTargetWriteMask[1] != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
description.RenderTargetWriteMask[1] = renderTargetWriteMask;
}
}
}
public ColorWriteChannels ColorWriteChannels2
{
set
{
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value);
if (description.RenderTargetWriteMask[2] != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
description.RenderTargetWriteMask[2] = renderTargetWriteMask;
}
}
}
public ColorWriteChannels ColorWriteChannels3
{
set
{
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value);
if (description.RenderTargetWriteMask[3] != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
description.RenderTargetWriteMask[3] = renderTargetWriteMask;
}
}
}
public Blend AlphaSourceBlend
{
set
{
BlendOption sourceAlphaBlend = FormatConverter.Translate(value);
if (description.SourceAlphaBlend != sourceAlphaBlend)
{
nativeBlendStateDirty = true;
description.SourceAlphaBlend = sourceAlphaBlend;
}
}
}
public Blend ColorSourceBlend
{
set
{
BlendOption sourceBlend = FormatConverter.Translate(value);
if (description.SourceBlend != sourceBlend)
{
nativeBlendStateDirty = true;
description.SourceBlend = sourceBlend;
}
}
}
private void UpdateNativeBlendState(SharpDX.Direct3D10.Device device)
{
if (this.nativeBlendStateDirty == true || this.nativeBlendState == null)
{
if (this.nativeBlendState != null)
{
this.nativeBlendState.Dispose();
this.nativeBlendState = null;
}
this.nativeBlendState = new SharpDX.Direct3D10.BlendState(device, ref this.description);
this.nativeBlendStateDirty = false;
}
}
}
#region UpdateValueAndMarkDirtyIfNeeded
private void UpdateValueAndMarkDirtyIfNeeded<T>(ref T currentValue, ref T value)
{
if (value.Equals(currentValue) == false)
{
isDirty = true;
currentValue = value;
}
}
#endregion
}
}

View File

@ -6,8 +6,8 @@ using ANX.Framework;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.RenderSystem;
using ANX.RenderSystem.Windows.DX10.Helpers;
using SharpDX.DXGI;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.

View File

@ -1,301 +1,236 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Direct3D10;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using ANX.Framework;
#endregion // Using Statements
using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
using StencilOperation = ANX.Framework.Graphics.StencilOperation;
namespace ANX.RenderSystem.Windows.DX10
{
public class DepthStencilState_DX10 : INativeDepthStencilState
{
#region Private Members
private DepthStencilStateDescription description;
private SharpDX.Direct3D10.DepthStencilState nativeDepthStencilState;
private bool nativeDepthStencilStateDirty;
private bool bound;
#region Private
private Dx10.DepthStencilStateDescription description;
private Dx10.DepthStencilState nativeDepthStencilState;
private bool isDirty;
private int referenceStencil;
#endregion
#endregion // Private Members
#region Public (TODO)
public bool IsBound
{
get;
private set;
}
public DepthStencilState_DX10()
public StencilOperation CounterClockwiseStencilDepthBufferFail
{
set
{
Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BackFace.DepthFailOperation, ref operation);
}
}
public StencilOperation CounterClockwiseStencilFail
{
set
{
Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BackFace.FailOperation, ref operation);
}
}
public CompareFunction CounterClockwiseStencilFunction
{
set
{
Dx10.Comparison comparison = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BackFace.Comparison, ref comparison);
}
}
public StencilOperation CounterClockwiseStencilPass
{
set
{
Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BackFace.PassOperation, ref operation);
}
}
public bool DepthBufferEnable
{
set
{
if (description.IsDepthEnabled != value)
{
description.IsDepthEnabled = value;
isDirty = true;
}
}
}
public CompareFunction DepthBufferFunction
{
set
{
Dx10.Comparison comparison = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.DepthComparison, ref comparison);
}
}
public bool DepthBufferWriteEnable
{
set
{
Dx10.DepthWriteMask writeMask = value ? Dx10.DepthWriteMask.All : Dx10.DepthWriteMask.Zero;
UpdateValueAndMarkDirtyIfNeeded(ref description.DepthWriteMask, ref writeMask);
}
}
public int ReferenceStencil
{
set
{
UpdateValueAndMarkDirtyIfNeeded(ref referenceStencil, ref value);
}
}
public StencilOperation StencilDepthBufferFail
{
set
{
Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FrontFace.DepthFailOperation, ref operation);
}
}
public bool StencilEnable
{
set
{
if (description.IsStencilEnabled != value)
{
description.IsStencilEnabled = value;
isDirty = true;
}
}
}
public StencilOperation StencilFail
{
set
{
Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FrontFace.FailOperation, ref operation);
}
}
public CompareFunction StencilFunction
{
set
{
Dx10.Comparison comparison = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FrontFace.Comparison, ref comparison);
}
}
public int StencilMask
{
set
{
byte stencilMask = (byte)value; //TODO: check range
UpdateValueAndMarkDirtyIfNeeded(ref description.StencilReadMask, ref stencilMask);
}
}
public StencilOperation StencilPass
{
set
{
Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FrontFace.PassOperation, ref operation);
}
}
public int StencilWriteMask
{
set
{
byte stencilWriteMask = (byte)value; //TODO: check range
UpdateValueAndMarkDirtyIfNeeded(ref description.StencilWriteMask, ref stencilWriteMask);
}
}
public bool TwoSidedStencilMode
{
set
{
//TODO: check if we really need in xna this enables only counter clockwise stencil operations
}
}
#endregion
#region Constructor
public DepthStencilState_DX10()
{
this.description = new DepthStencilStateDescription();
this.nativeDepthStencilStateDirty = true;
isDirty = true;
}
#endregion
#region Apply
public void Apply(GraphicsDevice graphicsDevice)
{
GraphicsDeviceWindowsDX10 gdx10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
Device device = gdx10.NativeDevice;
Dx10.Device device = (graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
UpdateNativeDepthStencilState(device);
this.bound = true;
IsBound = true;
device.OutputMerger.SetDepthStencilState(nativeDepthStencilState, this.referenceStencil);
device.OutputMerger.SetDepthStencilState(nativeDepthStencilState, referenceStencil);
}
#endregion
#region Release
public void Release()
{
this.bound = false;
IsBound = false;
}
#endregion
#region Dispose
public void Dispose()
{
if (this.nativeDepthStencilState != null)
if (nativeDepthStencilState != null)
{
this.nativeDepthStencilState.Dispose();
this.nativeDepthStencilState = null;
nativeDepthStencilState.Dispose();
nativeDepthStencilState = null;
}
}
#endregion
public bool IsBound
#region UpdateNativeDepthStencilState
private void UpdateNativeDepthStencilState(Dx10.Device device)
{
get
if (isDirty == true || nativeDepthStencilState == null)
{
return this.bound;
Dispose();
nativeDepthStencilState = new Dx10.DepthStencilState(device, ref description);
isDirty = false;
}
}
#endregion
public StencilOperation CounterClockwiseStencilDepthBufferFail
{
set
{
SharpDX.Direct3D10.StencilOperation operation = FormatConverter.Translate(value);
if (description.BackFace.DepthFailOperation != operation)
{
description.BackFace.DepthFailOperation = operation;
nativeDepthStencilStateDirty = true;
}
}
}
public StencilOperation CounterClockwiseStencilFail
{
set
{
SharpDX.Direct3D10.StencilOperation operation = FormatConverter.Translate(value);
if (description.BackFace.FailOperation != operation)
{
description.BackFace.FailOperation = operation;
nativeDepthStencilStateDirty = true;
}
}
}
public CompareFunction CounterClockwiseStencilFunction
{
set
{
SharpDX.Direct3D10.Comparison comparison = FormatConverter.Translate(value);
if (description.BackFace.Comparison != comparison)
{
description.BackFace.Comparison = comparison;
nativeDepthStencilStateDirty = true;
}
}
}
public StencilOperation CounterClockwiseStencilPass
{
set
{
SharpDX.Direct3D10.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 CompareFunction DepthBufferFunction
{
set
{
SharpDX.Direct3D10.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 StencilOperation StencilDepthBufferFail
{
set
{
SharpDX.Direct3D10.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 StencilOperation StencilFail
{
set
{
SharpDX.Direct3D10.StencilOperation operation = FormatConverter.Translate(value);
if (description.FrontFace.FailOperation != operation)
{
description.FrontFace.FailOperation = operation;
nativeDepthStencilStateDirty = true;
}
}
}
public CompareFunction StencilFunction
{
set
{
SharpDX.Direct3D10.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 StencilOperation StencilPass
{
set
{
SharpDX.Direct3D10.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.Direct3D10.DepthStencilState(device, ref this.description);
this.nativeDepthStencilStateDirty = false;
}
}
#region UpdateValueAndMarkDirtyIfNeeded
private void UpdateValueAndMarkDirtyIfNeeded<T>(ref T currentValue, ref T value)
{
if (value.Equals(currentValue) == false)
{
isDirty = true;
currentValue = value;
}
}
#endregion
}
}

View File

@ -1,299 +1,278 @@
#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.RenderSystem;
using ANX.Framework;
#endregion // Using Statements
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
using Texture2D = ANX.Framework.Graphics.Texture2D;
using Texture3D = ANX.Framework.Graphics.Texture3D;
namespace ANX.RenderSystem.Windows.DX10
{
public class EffectParameter_DX10 : 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, bool transpose)
{
// TODO: handle transpose!
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, bool transpose)
{
// TODO: handle transpose!
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)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
Texture2D_DX10 tex = value.NativeTexture as Texture2D_DX10;
GraphicsDeviceWindowsDX10 graphicsDX10 = tex.GraphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice;
nativeEffectVariable.AsShaderResource().SetResource(tex.NativeShaderResourceView);
}
public string Name
{
get
{
return nativeEffectVariable.Description.Name;
}
}
#region INativeEffectParameter Member
public bool GetValueBoolean()
{
throw new NotImplementedException();
}
public bool[] GetValueBooleanArray(int count)
{
throw new NotImplementedException();
}
public int GetValueInt32()
{
throw new NotImplementedException();
}
public int[] GetValueInt32Array(int count)
{
throw new NotImplementedException();
}
public Matrix GetValueMatrix()
{
throw new NotImplementedException();
}
public Matrix[] GetValueMatrixArray(int count)
{
throw new NotImplementedException();
}
public Matrix GetValueMatrixTranspose()
{
throw new NotImplementedException();
}
public Matrix[] GetValueMatrixTransposeArray(int count)
{
throw new NotImplementedException();
}
public Quaternion GetValueQuaternion()
{
throw new NotImplementedException();
}
public Quaternion[] GetValueQuaternionArray(int count)
{
throw new NotImplementedException();
}
public float GetValueSingle()
{
throw new NotImplementedException();
}
public float[] GetValueSingleArray(int count)
{
throw new NotImplementedException();
}
public string GetValueString()
{
throw new NotImplementedException();
}
public Texture2D GetValueTexture2D()
{
throw new NotImplementedException();
}
public Texture3D GetValueTexture3D()
{
throw new NotImplementedException();
}
public TextureCube GetValueTextureCube()
{
throw new NotImplementedException();
}
public Vector2 GetValueVector2()
{
throw new NotImplementedException();
}
public Vector2[] GetValueVector2Array(int count)
{
throw new NotImplementedException();
}
public Vector3 GetValueVector3()
{
throw new NotImplementedException();
}
public Vector3[] GetValueVector3Array(int count)
{
throw new NotImplementedException();
}
public Vector4 GetValueVector4()
{
throw new NotImplementedException();
}
public Vector4[] GetValueVector4Array(int count)
{
throw new NotImplementedException();
}
#endregion
#region INativeEffectParameter Member
public void SetValue(string value)
{
throw new NotImplementedException();
}
#endregion
public class EffectParameter_DX10 : INativeEffectParameter
{
#region Public
public Dx10.EffectVariable NativeParameter
{
get;
internal set;
}
public string Name
{
get
{
return NativeParameter.Description.Name;
}
}
#endregion
#region SetValue (bool)
public void SetValue(bool value)
{
NativeParameter.AsScalar().Set(value);
}
#endregion
#region SetValue (bool[])
public void SetValue(bool[] value)
{
NativeParameter.AsScalar().Set(value);
}
#endregion
#region SetValue (int)
public void SetValue(int value)
{
NativeParameter.AsScalar().Set(value);
}
#endregion
#region SetValue (int[])
public void SetValue(int[] value)
{
NativeParameter.AsScalar().Set(value);
}
#endregion
#region SetValue (Matrix, transpose) (TODO)
public void SetValue(Matrix value, bool transpose)
{
// TODO: handle transpose!
NativeParameter.AsMatrix().SetMatrix(value);
}
#endregion
#region SetValue (Matrix[], transpose) (TODO)
public void SetValue(Matrix[] value, bool transpose)
{
// TODO: handle transpose!
NativeParameter.AsMatrix().SetMatrix(value);
}
#endregion
#region SetValue (Quaternion)
public void SetValue(Quaternion value)
{
NativeParameter.AsVector().Set(value);
}
#endregion
#region SetValue (Quaternion[])
public void SetValue(Quaternion[] value)
{
NativeParameter.AsVector().Set(value);
}
#endregion
#region SetValue (float)
public void SetValue(float value)
{
NativeParameter.AsScalar().Set(value);
}
#endregion
#region SetValue (float[])
public void SetValue(float[] value)
{
NativeParameter.AsScalar().Set(value);
}
#endregion
#region SetValue (Vector2)
public void SetValue(Vector2 value)
{
NativeParameter.AsVector().Set(value);
}
#endregion
#region SetValue (Vector2[])
public void SetValue(Vector2[] value)
{
NativeParameter.AsVector().Set(value);
}
#endregion
#region SetValue (Vector3)
public void SetValue(Vector3 value)
{
NativeParameter.AsVector().Set(value);
}
#endregion
#region SetValue (Vector3[])
public void SetValue(Vector3[] value)
{
NativeParameter.AsVector().Set(value);
}
#endregion
#region SetValue (Vector4)
public void SetValue(Vector4 value)
{
NativeParameter.AsVector().Set(value);
}
#endregion
#region SetValue (Vector4[])
public void SetValue(Vector4[] value)
{
NativeParameter.AsVector().Set(value);
}
#endregion
#region SetValue (Texture)
public void SetValue(Texture value)
{
if (value == null)
throw new ArgumentNullException("value");
var tex = value.NativeTexture as Texture2D_DX10;
var graphicsDX10 = tex.GraphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
Dx10.Device device = graphicsDX10.NativeDevice;
NativeParameter.AsShaderResource().SetResource(tex.NativeShaderResourceView);
}
#endregion
#region SetValue (string) (TODO)
public void SetValue(string value)
{
throw new NotImplementedException();
}
#endregion
#region Get (TODO)
public bool GetValueBoolean()
{
throw new NotImplementedException();
}
public bool[] GetValueBooleanArray(int count)
{
throw new NotImplementedException();
}
public int GetValueInt32()
{
throw new NotImplementedException();
}
public int[] GetValueInt32Array(int count)
{
throw new NotImplementedException();
}
public Matrix GetValueMatrix()
{
throw new NotImplementedException();
}
public Matrix[] GetValueMatrixArray(int count)
{
throw new NotImplementedException();
}
public Matrix GetValueMatrixTranspose()
{
throw new NotImplementedException();
}
public Matrix[] GetValueMatrixTransposeArray(int count)
{
throw new NotImplementedException();
}
public Quaternion GetValueQuaternion()
{
throw new NotImplementedException();
}
public Quaternion[] GetValueQuaternionArray(int count)
{
throw new NotImplementedException();
}
public float GetValueSingle()
{
throw new NotImplementedException();
}
public float[] GetValueSingleArray(int count)
{
throw new NotImplementedException();
}
public string GetValueString()
{
throw new NotImplementedException();
}
public Texture2D GetValueTexture2D()
{
throw new NotImplementedException();
}
public Texture3D GetValueTexture3D()
{
throw new NotImplementedException();
}
public TextureCube GetValueTextureCube()
{
throw new NotImplementedException();
}
public Vector2 GetValueVector2()
{
throw new NotImplementedException();
}
public Vector2[] GetValueVector2Array(int count)
{
throw new NotImplementedException();
}
public Vector3 GetValueVector3()
{
throw new NotImplementedException();
}
public Vector3[] GetValueVector3Array(int count)
{
throw new NotImplementedException();
}
public Vector4 GetValueVector4()
{
throw new NotImplementedException();
}
public Vector4[] GetValueVector4Array(int count)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using ANX.RenderSystem.Windows.DX10.Helpers;
using SharpDX.D3DCompiler;
using Dx10 = SharpDX.Direct3D10;
@ -92,35 +93,46 @@ namespace ANX.RenderSystem.Windows.DX10
}
#endregion
#region GetCurrentTechnique
public EffectTechnique_DX10 GetCurrentTechnique()
{
return managedEffect.CurrentTechnique.NativeTechnique as EffectTechnique_DX10;
}
#endregion
#region Apply
public void Apply(GraphicsDevice graphicsDevice)
{
((GraphicsDeviceWindowsDX10)graphicsDevice.NativeDevice).currentEffect = this;
}
#endregion
public static byte[] CompileVertexShader(string effectCode, string directory = "")
#region CompileVertexShader (TODO)
public static byte[] CompileVertexShader(string effectCode, string directory = "")
{
// TODO: not all entry points are named VS!
ShaderBytecode vertexShaderByteCode = ShaderBytecode.Compile(effectCode, "VS", "vs_4_0", ShaderFlags.None,
EffectFlags.None, null, new IncludeHandler(directory), "unknown");
byte[] bytecode = new byte[vertexShaderByteCode.BufferSize];
vertexShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
return bytecode;
}
}
#endregion
public static byte[] CompilePixelShader(string effectCode, string directory = "")
{
#region CompilePixelShader (TODO)
public static byte[] CompilePixelShader(string effectCode, string directory = "")
{
// TODO: not all entry points are named PS!
ShaderBytecode pixelShaderByteCode = ShaderBytecode.Compile(effectCode, "PS", "ps_4_0", ShaderFlags.None,
EffectFlags.None, null, new IncludeHandler(directory), "unknown");
byte[] bytecode = new byte[pixelShaderByteCode.BufferSize];
pixelShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
return bytecode;
}
}
#endregion
public static byte[] CompileFXShader(string effectCode, string directory = "")
#region CompileFXShader
public static byte[] CompileFXShader(string effectCode, string directory = "")
{
ShaderBytecode effectByteCode = ShaderBytecode.Compile(effectCode, "fx_4_0", ShaderFlags.None, EffectFlags.None,
null, new IncludeHandler(directory), "unknown");
@ -128,6 +140,7 @@ namespace ANX.RenderSystem.Windows.DX10
effectByteCode.Data.Read(bytecode, 0, bytecode.Length);
return bytecode;
}
#endregion
#region Dispose
public void Dispose()

View File

@ -1,345 +0,0 @@
#region Using Statements
using System;
using ANX.Framework.Graphics;
using SharpDX.Direct3D10;
using SharpDX.Direct3D;
using SharpDX.DXGI;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
using TextureAddressMode = ANX.Framework.Graphics.TextureAddressMode;
using StencilOperation = ANX.Framework.Graphics.StencilOperation;
using CullMode = ANX.Framework.Graphics.CullMode;
using FillMode = ANX.Framework.Graphics.FillMode;
namespace ANX.RenderSystem.Windows.DX10
{
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.Direct3D10.TextureAddressMode Translate(ANX.Framework.Graphics.TextureAddressMode addressMode)
{
switch (addressMode)
{
case TextureAddressMode.Clamp:
return SharpDX.Direct3D10.TextureAddressMode.Clamp;
case TextureAddressMode.Mirror:
return SharpDX.Direct3D10.TextureAddressMode.Mirror;
case TextureAddressMode.Wrap:
return SharpDX.Direct3D10.TextureAddressMode.Wrap;
}
return SharpDX.Direct3D10.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(ref VertexElement element)
{
//TODO: map the other Usages
if (element.VertexElementUsage == VertexElementUsage.TextureCoordinate)
return "TEXCOORD";
else
return element.VertexElementUsage.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.Direct3D10.StencilOperation Translate(ANX.Framework.Graphics.StencilOperation stencilOperation)
{
switch (stencilOperation)
{
case StencilOperation.Decrement:
return SharpDX.Direct3D10.StencilOperation.Decrement;
case StencilOperation.DecrementSaturation:
return SharpDX.Direct3D10.StencilOperation.DecrementAndClamp;
case StencilOperation.Increment:
return SharpDX.Direct3D10.StencilOperation.Increment;
case StencilOperation.IncrementSaturation:
return SharpDX.Direct3D10.StencilOperation.IncrementAndClamp;
case StencilOperation.Invert:
return SharpDX.Direct3D10.StencilOperation.Invert;
case StencilOperation.Keep:
return SharpDX.Direct3D10.StencilOperation.Keep;
case StencilOperation.Replace:
return SharpDX.Direct3D10.StencilOperation.Replace;
case StencilOperation.Zero:
return SharpDX.Direct3D10.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.Direct3D10.CullMode Translate(CullMode cullMode)
{
if (cullMode == CullMode.CullClockwiseFace)
{
return SharpDX.Direct3D10.CullMode.Front;
}
else if (cullMode == CullMode.CullCounterClockwiseFace)
{
return SharpDX.Direct3D10.CullMode.Back;
}
else
{
return SharpDX.Direct3D10.CullMode.None;
}
}
public static SharpDX.Direct3D10.FillMode Translate(FillMode fillMode)
{
if (fillMode == FillMode.WireFrame)
{
return SharpDX.Direct3D10.FillMode.Wireframe;
}
else
{
return SharpDX.Direct3D10.FillMode.Solid;
}
}
}
}

View File

@ -1,25 +1,16 @@
#region Using Statements
using System;
using SharpDX.DXGI;
using SharpDX.D3DCompiler;
using SharpDX.Direct3D10;
using ANX.Framework;
using ANX.Framework.NonXNA;
using ANX.Framework.Graphics;
using System.Runtime.InteropServices;
#endregion // Using Statements
using ANX.Framework.NonXNA;
using ANX.RenderSystem.Windows.DX10.Helpers;
using SharpDX.D3DCompiler;
using SharpDX.DXGI;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
using Device = SharpDX.Direct3D10.Device;
using Rectangle = ANX.Framework.Rectangle;
using Vector4 = ANX.Framework.Vector4;
using VertexBufferBinding = ANX.Framework.Graphics.VertexBufferBinding;
using Viewport = ANX.Framework.Graphics.Viewport;
namespace ANX.RenderSystem.Windows.DX10
{
public class GraphicsDeviceWindowsDX10 : INativeGraphicsDevice
@ -28,48 +19,24 @@ namespace ANX.RenderSystem.Windows.DX10
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 Device device;
private SwapChain swapChain;
private RenderTargetView renderView;
private RenderTargetView[] renderTargetView = new RenderTargetView[1];
private DepthStencilView depthStencilView;
private SharpDX.Direct3D10.Texture2D depthStencilBuffer;
private SharpDX.Direct3D10.Texture2D backBuffer;
#region Private
private Dx10.Device device;
private SwapChain swapChain;
private Dx10.RenderTargetView renderView;
private Dx10.RenderTargetView[] renderTargetView = new Dx10.RenderTargetView[1];
private Dx10.DepthStencilView depthStencilView;
private Dx10.Texture2D depthStencilBuffer;
private Dx10.Texture2D backBuffer;
internal Effect_DX10 currentEffect;
private VertexBuffer currentVertexBuffer;
private IndexBuffer currentIndexBuffer;
private SharpDX.Direct3D10.Viewport currentViewport;
private Dx10.Viewport currentViewport;
private uint lastClearColor;
private SharpDX.Color4 clearColor;
private bool vSyncEnabled;
#endregion
#endregion // Private Members
internal Device NativeDevice
#region Public
internal Dx10.Device NativeDevice
{
get
{
@ -77,15 +44,21 @@ namespace ANX.RenderSystem.Windows.DX10
}
}
public GraphicsDeviceWindowsDX10(PresentationParameters presentationParameters)
public bool VSync { get; set; }
#endregion
#region Constructor
public GraphicsDeviceWindowsDX10(PresentationParameters presentationParameters)
{
this.vSyncEnabled = true;
VSync = true;
// SwapChain description
var desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription = new ModeDescription(presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight, new Rational(60, 1), FormatConverter.Translate(presentationParameters.BackBufferFormat)),
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),
@ -96,34 +69,36 @@ namespace ANX.RenderSystem.Windows.DX10
// Create Device and SwapChain
#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);
Dx10.Device.CreateWithSwapChain(Dx10.DriverType.Hardware, Dx10.DeviceCreationFlags.Debug, desc, out device,
out swapChain);
#else
Device.CreateWithSwapChain(SharpDX.Direct3D10.DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);
Dx10.Device.CreateWithSwapChain(Dx10.DriverType.Hardware, Dx10.DeviceCreationFlags.None, desc, out device,
out swapChain);
#endif
// Ignore all windows events
Factory factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(presentationParameters.DeviceWindowHandle, WindowAssociationFlags.IgnoreAll);
ResizeRenderWindow(presentationParameters);
WindowHelper.ResizeRenderWindow(presentationParameters);
// New RenderTargetView from the backbuffer
backBuffer = SharpDX.Direct3D10.Texture2D.FromSwapChain<SharpDX.Direct3D10.Texture2D>(swapChain, 0);
renderView = new RenderTargetView(device, backBuffer);
backBuffer = Dx10.Texture2D.FromSwapChain<Dx10.Texture2D>(swapChain, 0);
renderView = new Dx10.RenderTargetView(device, backBuffer);
currentViewport = new SharpDX.Direct3D10.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
currentViewport = new Dx10.Viewport(0, 0, presentationParameters.BackBufferWidth, presentationParameters.BackBufferHeight);
//
// create the depth stencil buffer
//
Format depthFormat = FormatConverter.Translate(presentationParameters.DepthStencilFormat);
if (depthFormat != Format.Unknown)
{
CreateDepthStencilBuffer(depthFormat);
}
}
#endregion
private void CreateDepthStencilBuffer(Format depthFormat)
#region CreateDepthStencilBuffer
private void CreateDepthStencilBuffer(Format depthFormat)
{
if (this.depthStencilBuffer != null &&
this.depthStencilBuffer.Description.Format == depthFormat &&
@ -152,12 +127,12 @@ namespace ANX.RenderSystem.Windows.DX10
return;
}
DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription()
var depthStencilViewDesc = new Dx10.DepthStencilViewDescription()
{
Format = depthFormat,
};
Texture2DDescription depthStencilTextureDesc = new Texture2DDescription()
var depthStencilTextureDesc = new Dx10.Texture2DDescription()
{
Width = this.backBuffer.Description.Width,
Height = this.backBuffer.Description.Height,
@ -165,17 +140,19 @@ namespace ANX.RenderSystem.Windows.DX10
ArraySize = 1,
Format = depthFormat,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
Usage = Dx10.ResourceUsage.Default,
BindFlags = Dx10.BindFlags.DepthStencil,
CpuAccessFlags = Dx10.CpuAccessFlags.None,
OptionFlags = Dx10.ResourceOptionFlags.None
};
this.depthStencilBuffer = new SharpDX.Direct3D10.Texture2D(device, depthStencilTextureDesc);
this.depthStencilBuffer = new Dx10.Texture2D(device, depthStencilTextureDesc);
this.depthStencilView = new DepthStencilView(device, this.depthStencilBuffer);
this.depthStencilView = new Dx10.DepthStencilView(device, this.depthStencilBuffer);
Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil, Vector4.Zero, 1.0f, 0); // this workaround is working but maybe not the best solution to issue #472
// this workaround is working but maybe not the best solution to issue #472
Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil, Vector4.Zero, 1.0f, 0);
}
#endregion
#region Clear
public void Clear(ref Color color)
@ -243,122 +220,117 @@ namespace ANX.RenderSystem.Windows.DX10
if ((options | ClearOptions.Stencil | ClearOptions.DepthBuffer) == options)
{
// Clear the stencil buffer
device.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, depth, (byte)stencil);
device.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Depth |
Dx10.DepthStencilClearFlags.Stencil, depth, (byte)stencil);
}
else if ((options | ClearOptions.Stencil) == options)
{
device.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Stencil, depth, (byte)stencil);
device.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Stencil, depth,
(byte)stencil);
}
else
{
device.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Depth, depth, (byte)stencil);
device.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Depth, depth, (byte)stencil);
}
}
}
#endregion
#region Present
public void Present()
{
swapChain.Present(this.vSyncEnabled ? 1 : 0, PresentFlags.None);
swapChain.Present(VSync ? 1 : 0, PresentFlags.None);
}
#endregion
#endregion // Present
#region DrawIndexedPrimitives
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices,
int startIndex, int primitiveCount)
{
Dx10.EffectTechnique technique = SetupEffectForDraw();
int vertexCount = FormatConverter.CalculateVertexCount(primitiveType, primitiveCount);
#region DrawPrimitives & DrawIndexedPrimitives
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount)
{
SharpDX.Direct3D10.EffectPass pass; SharpDX.Direct3D10.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
// Prepare All the stages
device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
device.Rasterizer.SetViewports(currentViewport);
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply();
device.DrawIndexed(CalculateVertexCount(primitiveType, primitiveCount), startIndex, baseVertex);
{
technique.GetPassByIndex(i).Apply();
device.DrawIndexed(vertexCount, startIndex, baseVertex);
}
}
}
#endregion
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount)
{
SharpDX.Direct3D10.EffectPass pass; SharpDX.Direct3D10.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
#region DrawPrimitives
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount)
{
Dx10.EffectTechnique technique = SetupEffectForDraw();
SetupInputLayout(passSignature);
// Prepare All the stages
device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
device.Rasterizer.SetViewports(currentViewport);
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply();
{
technique.GetPassByIndex(i).Apply();
device.Draw(primitiveCount, vertexOffset);
}
}
#endregion // DrawPrimitives & DrawIndexedPrimitives
#endregion
#region DrawInstancedPrimitives
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount)
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices,
int startIndex, int primitiveCount, int instanceCount)
{
device.DrawIndexedInstanced(numVertices, instanceCount, startIndex, baseVertex, 0);
}
#endregion // DrawInstancedPrimitives
#endregion
#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
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
{
int vertexCount = vertexData.Length;
int indexCount = indexData.Length;
VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(this.device, vertexDeclaration, vertexCount, BufferUsage.None);
vb10.SetData<T>(null, vertexData);
SharpDX.Direct3D10.VertexBufferBinding nativeVertexBufferBindings = new SharpDX.Direct3D10.VertexBufferBinding(vb10.NativeBuffer, vertexDeclaration.VertexStride, 0);
Dx10.VertexBufferBinding nativeVertexBufferBindings = new Dx10.VertexBufferBinding(vb10.NativeBuffer,
vertexDeclaration.VertexStride, 0);
device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
IndexBuffer_DX10 idx10 = new IndexBuffer_DX10(this.device, indexFormat, indexCount, BufferUsage.None);
if (indexData.GetType() == typeof(Int16[]))
{
idx10.SetData<short>(null, (short[])indexData);
}
else
{
idx10.SetData<int>(null, (int[])indexData);
}
DrawIndexedPrimitives(primitiveType, 0, vertexOffset, numVertices, indexOffset, primitiveCount);
}
#endregion // DrawUserIndexedPrimitives<T>
#endregion
#region DrawUserPrimitives<T>
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount,
VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
int vertexCount = vertexData.Length;
VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(this.device, vertexDeclaration, vertexCount, BufferUsage.None);
vb10.SetData<T>(null, vertexData);
SharpDX.Direct3D10.VertexBufferBinding nativeVertexBufferBindings = new SharpDX.Direct3D10.VertexBufferBinding(vb10.NativeBuffer, vertexDeclaration.VertexStride, 0);
Dx10.VertexBufferBinding nativeVertexBufferBindings = new Dx10.VertexBufferBinding(vb10.NativeBuffer,
vertexDeclaration.VertexStride, 0);
device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
SharpDX.Direct3D10.EffectPass pass; SharpDX.Direct3D10.EffectTechnique technique; ShaderBytecode passSignature;
SetupEffectForDraw(out pass, out technique, out passSignature);
var layout = CreateInputLayout(device, passSignature, vertexDeclaration);
//TODO: check for currentEffect null and throw exception
// TODO: check for null's and throw exceptions
// TODO: get the correct pass index!
var technique = currentEffect.GetCurrentTechnique().NativeTechnique;
var pass = technique.GetPassByIndex(0);
var layout = CreateInputLayout(device, pass.Description.Signature, vertexDeclaration);
device.InputAssembler.InputLayout = layout;
// Prepare All the stages
@ -373,28 +345,25 @@ namespace ANX.RenderSystem.Windows.DX10
device.Draw(primitiveCount, vertexOffset);
}
}
#endregion
#endregion // DrawUserPrimitives<T>
private void SetupEffectForDraw(out SharpDX.Direct3D10.EffectPass pass, out SharpDX.Direct3D10.EffectTechnique technique,
out ShaderBytecode passSignature)
#region SetupEffectForDraw
private Dx10.EffectTechnique SetupEffectForDraw()
{
// get the current effect
//TODO: check for null and throw exception
Effect_DX10 effect = this.currentEffect;
// get the input semantic of the current effect / technique that is used
//TODO: check for currentEffect null and throw exception
// TODO: check for null's and throw exceptions
// TODO: get the correct pass index!
technique = effect.GetCurrentTechnique().NativeTechnique;
pass = technique.GetPassByIndex(0);
passSignature = pass.Description.Signature;
}
var technique = currentEffect.GetCurrentTechnique().NativeTechnique;
var pass = technique.GetPassByIndex(0);
SetupInputLayout(pass.Description.Signature);
private void SetupInputLayout(ShaderBytecode passSignature)
return technique;
}
#endregion
#region SetupInputLayout
private void SetupInputLayout(ShaderBytecode passSignature)
{
// get the VertexDeclaration from current VertexBuffer to create input layout for the input assembler
if (currentVertexBuffer == null)
throw new ArgumentNullException("passSignature");
@ -403,31 +372,9 @@ namespace ANX.RenderSystem.Windows.DX10
device.InputAssembler.InputLayout = layout;
}
private int CalculateVertexCount(PrimitiveType type, int primitiveCount)
{
if (type == PrimitiveType.TriangleList)
{
return primitiveCount * 3;
}
else if (type == PrimitiveType.LineList)
{
return primitiveCount * 2;
}
else if (type == PrimitiveType.LineStrip)
{
return primitiveCount + 1;
}
else if (type == PrimitiveType.TriangleStrip)
{
return primitiveCount + 2;
}
else
{
throw new NotImplementedException("couldn't calculate vertex count for PrimitiveType '" + type.ToString() + "'");
}
}
#endregion
#region SetIndexBuffer
public void SetIndexBuffer(IndexBuffer indexBuffer)
{
if (indexBuffer == null)
@ -448,30 +395,30 @@ namespace ANX.RenderSystem.Windows.DX10
throw new Exception("couldn't fetch native DirectX10 IndexBuffer");
}
}
#endregion
#if XNAEXT
#region SetConstantBuffer
public void SetConstantBuffer(int slot, ANX.Framework.Graphics.ConstantBuffer constantBuffer)
{
if (constantBuffer == null)
{
throw new ArgumentNullException("constantBuffer");
}
throw new NotImplementedException();
}
#endregion
#endif
public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
#region SetVertexBuffers
public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
{
if (vertexBuffers == null)
{
throw new ArgumentNullException("vertexBuffers");
}
this.currentVertexBuffer = vertexBuffers[0].VertexBuffer; //TODO: hmmmmm, not nice :-)
SharpDX.Direct3D10.VertexBufferBinding[] nativeVertexBufferBindings =
new SharpDX.Direct3D10.VertexBufferBinding[vertexBuffers.Length];
Dx10.VertexBufferBinding[] nativeVertexBufferBindings =
new Dx10.VertexBufferBinding[vertexBuffers.Length];
for (int i = 0; i < vertexBuffers.Length; i++)
{
ANX.Framework.Graphics.VertexBufferBinding anxVertexBufferBinding = vertexBuffers[i];
@ -479,7 +426,7 @@ namespace ANX.RenderSystem.Windows.DX10
if (nativeVertexBuffer != null)
{
nativeVertexBufferBindings[i] = new SharpDX.Direct3D10.VertexBufferBinding(nativeVertexBuffer.NativeBuffer,
nativeVertexBufferBindings[i] = new Dx10.VertexBufferBinding(nativeVertexBuffer.NativeBuffer,
anxVertexBufferBinding.VertexBuffer.VertexDeclaration.VertexStride, anxVertexBufferBinding.VertexOffset);
}
else
@ -489,37 +436,46 @@ namespace ANX.RenderSystem.Windows.DX10
}
device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
}
}
#endregion
public void SetViewport(Viewport viewport)
#region SetViewport
public void SetViewport(Viewport viewport)
{
this.currentViewport = new SharpDX.Direct3D10.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height,
this.currentViewport = new Dx10.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height,
viewport.MinDepth, viewport.MaxDepth);
}
#endregion
/// <summary>
#region CreateInputLayout
/// <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.
/// </summary>
private InputLayout CreateInputLayout(Device device, ShaderBytecode passSignature, VertexDeclaration vertexDeclaration)
private Dx10.InputLayout CreateInputLayout(Dx10.Device device, ShaderBytecode passSignature,
VertexDeclaration vertexDeclaration)
{
VertexElement[] vertexElements = vertexDeclaration.GetVertexElements();
int elementCount = vertexElements.Length;
InputElement[] inputElements = new InputElement[elementCount];
var inputElements = new Dx10.InputElement[elementCount];
for (int i = 0; i < elementCount; i++)
inputElements[i] = CreateInputElementFromVertexElement(vertexElements[i]);
return new InputLayout(device, passSignature, inputElements);
}
return new Dx10.InputLayout(device, passSignature, inputElements);
}
#endregion
private InputElement CreateInputElementFromVertexElement(VertexElement vertexElement)
#region CreateInputElementFromVertexElement
private Dx10.InputElement CreateInputElementFromVertexElement(VertexElement vertexElement)
{
string elementName = FormatConverter.Translate(ref vertexElement);
Format elementFormat = ConvertVertexElementFormat(vertexElement.VertexElementFormat);
return new InputElement(elementName, vertexElement.UsageIndex, elementFormat, vertexElement.Offset, 0);
}
return new Dx10.InputElement(elementName, vertexElement.UsageIndex, elementFormat, vertexElement.Offset, 0);
}
#endregion
#region ConvertVertexElementFormat
private Format ConvertVertexElementFormat(VertexElementFormat format)
{
switch (format)
@ -543,6 +499,7 @@ namespace ANX.RenderSystem.Windows.DX10
throw new Exception("Can't map '" + format + "' to DXGI.Format in Dx10 CreateInputElementFromVertexElement.");
}
#endregion
#region SetRenderTargets
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
@ -559,7 +516,7 @@ namespace ANX.RenderSystem.Windows.DX10
}
}
device.OutputMerger.SetRenderTargets(1, new RenderTargetView[] { this.renderView }, this.depthStencilView);
device.OutputMerger.SetRenderTargets(1, new Dx10.RenderTargetView[] { this.renderView }, this.depthStencilView);
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
}
else
@ -576,7 +533,7 @@ namespace ANX.RenderSystem.Windows.DX10
}
}
this.renderTargetView = new RenderTargetView[renderTargetCount];
this.renderTargetView = new Dx10.RenderTargetView[renderTargetCount];
}
for (int i = 0; i < renderTargetCount; i++)
@ -591,7 +548,7 @@ namespace ANX.RenderSystem.Windows.DX10
renderTargetView[i].Dispose();
}
renderTargetView[i] = new RenderTargetView(device, ((Texture2D_DX10)nativeRenderTarget).NativeShaderResourceView.Resource);
renderTargetView[i] = new Dx10.RenderTargetView(device, ((Texture2D_DX10)nativeRenderTarget).NativeShaderResourceView.Resource);
}
}
@ -622,7 +579,7 @@ namespace ANX.RenderSystem.Windows.DX10
}
#endregion
#region GetBackBufferData
#region GetBackBufferData (TODO)
public void GetBackBufferData<T>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
@ -652,53 +609,22 @@ namespace ANX.RenderSystem.Windows.DX10
swapChain.ResizeBuffers(swapChain.Description.BufferCount, presentationParameters.BackBufferWidth,
presentationParameters.BackBufferHeight, Format.R8G8B8A8_UNorm, swapChain.Description.Flags);
backBuffer = SharpDX.Direct3D10.Texture2D.FromSwapChain<SharpDX.Direct3D10.Texture2D>(swapChain, 0);
renderView = new RenderTargetView(device, backBuffer);
backBuffer = Dx10.Texture2D.FromSwapChain<Dx10.Texture2D>(swapChain, 0);
renderView = new Dx10.RenderTargetView(device, backBuffer);
currentViewport = new SharpDX.Direct3D10.Viewport(0, 0, presentationParameters.BackBufferWidth,
currentViewport = new Dx10.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);
WindowHelper.ResizeRenderWindow(presentationParameters);
}
#endregion
#region ResizeRenderWindow
private void ResizeRenderWindow(PresentationParameters presentationParameters)
{
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);
}
}
#endregion
public bool VSync
{
get
{
return this.vSyncEnabled;
}
set
{
this.vSyncEnabled = value;
}
}
#region Dispose
public void Dispose()
{

View File

@ -0,0 +1,360 @@
using System;
using ANX.Framework.Graphics;
using SharpDX.Direct3D;
using SharpDX.DXGI;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.RenderSystem.Windows.DX10.Helpers
{
internal class FormatConverter
{
#region FormatSize (SurfaceFormat)
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;
}
throw new ArgumentException("Invalid format '" + format + "'.");
}
#endregion
#region Translate (SurfaceFormat)
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());
}
#endregion
#region Translate (DepthFormat)
public static Format Translate(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());
}
#endregion
#region Translate (Format)
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());
}
#endregion
#region Translate (TextureFilter)
public static Dx10.Filter Translate(TextureFilter filter)
{
switch (filter)
{
case TextureFilter.Anisotropic:
return Dx10.Filter.Anisotropic;
case TextureFilter.Linear:
return Dx10.Filter.MinMagMipLinear;
case TextureFilter.LinearMipPoint:
return Dx10.Filter.MinMagMipPoint;
case TextureFilter.MinLinearMagPointMipLinear:
return Dx10.Filter.MinLinearMagPointMipLinear;
case TextureFilter.MinLinearMagPointMipPoint:
return Dx10.Filter.MinLinearMagMipPoint;
case TextureFilter.MinPointMagLinearMipLinear:
return Dx10.Filter.MinPointMagMipLinear;
case TextureFilter.MinPointMagLinearMipPoint:
return Dx10.Filter.MinPointMagLinearMipPoint;
case TextureFilter.Point:
return Dx10.Filter.MinMagMipPoint;
case TextureFilter.PointMipLinear:
return Dx10.Filter.MinMagPointMipLinear;
}
throw new NotImplementedException();
}
#endregion
#region Translate (TextureAddressMode)
public static Dx10.TextureAddressMode Translate(TextureAddressMode addressMode)
{
switch (addressMode)
{
case TextureAddressMode.Clamp:
return Dx10.TextureAddressMode.Clamp;
case TextureAddressMode.Mirror:
return Dx10.TextureAddressMode.Mirror;
case TextureAddressMode.Wrap:
return Dx10.TextureAddressMode.Wrap;
}
return Dx10.TextureAddressMode.Clamp;
}
#endregion
#region Translate (PrimitiveType)
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;
}
throw new InvalidOperationException("unknown PrimitiveType: " + primitiveType);
}
#endregion
#region Translate (IndexElementSize)
public static SharpDX.DXGI.Format Translate(IndexElementSize indexElementSize)
{
switch (indexElementSize)
{
case IndexElementSize.SixteenBits:
return Format.R16_UInt;
case IndexElementSize.ThirtyTwoBits:
return Format.R32_UInt;
}
throw new InvalidOperationException("unknown IndexElementSize: " + indexElementSize);
}
#endregion
#region Translate (VertexElement)
public static string Translate(ref VertexElement element)
{
//TODO: map the other Usages
if (element.VertexElementUsage == VertexElementUsage.TextureCoordinate)
return "TEXCOORD";
else
return element.VertexElementUsage.ToString().ToUpperInvariant();
}
#endregion
#region Translate (BlendFunction)
public static Dx10.BlendOperation Translate(BlendFunction blendFunction)
{
switch (blendFunction)
{
case BlendFunction.Add:
return Dx10.BlendOperation.Add;
case BlendFunction.Max:
return Dx10.BlendOperation.Maximum;
case BlendFunction.Min:
return Dx10.BlendOperation.Minimum;
case BlendFunction.ReverseSubtract:
return Dx10.BlendOperation.ReverseSubtract;
case BlendFunction.Subtract:
return Dx10.BlendOperation.Subtract;
}
throw new NotImplementedException();
}
#endregion
#region Translate (Blend)
public static Dx10.BlendOption Translate(Blend blend)
{
switch (blend)
{
case Blend.BlendFactor:
return Dx10.BlendOption.BlendFactor;
case Blend.DestinationAlpha:
return Dx10.BlendOption.DestinationAlpha;
case Blend.DestinationColor:
return Dx10.BlendOption.DestinationColor;
case Blend.InverseBlendFactor:
return Dx10.BlendOption.InverseBlendFactor;
case Blend.InverseDestinationAlpha:
return Dx10.BlendOption.InverseDestinationAlpha;
case Blend.InverseDestinationColor:
return Dx10.BlendOption.InverseDestinationColor;
case Blend.InverseSourceAlpha:
return Dx10.BlendOption.InverseSourceAlpha;
case Blend.InverseSourceColor:
return Dx10.BlendOption.InverseSourceColor;
case Blend.One:
return Dx10.BlendOption.One;
case Blend.SourceAlpha:
return Dx10.BlendOption.SourceAlpha;
case Blend.SourceAlphaSaturation:
return Dx10.BlendOption.SourceAlphaSaturate;
case Blend.SourceColor:
return Dx10.BlendOption.SourceColor;
case Blend.Zero:
return Dx10.BlendOption.Zero;
}
throw new NotImplementedException();
}
#endregion
#region Translate (ColorWriteChannels)
public static Dx10.ColorWriteMaskFlags Translate(ColorWriteChannels colorWriteChannels)
{
Dx10.ColorWriteMaskFlags mask = 0;
if ((colorWriteChannels & ColorWriteChannels.All) == ColorWriteChannels.All)
mask |= Dx10.ColorWriteMaskFlags.All;
if ((colorWriteChannels & ColorWriteChannels.Alpha) == ColorWriteChannels.Alpha)
mask |= Dx10.ColorWriteMaskFlags.Alpha;
if ((colorWriteChannels & ColorWriteChannels.Blue) == ColorWriteChannels.Blue)
mask |= Dx10.ColorWriteMaskFlags.Blue;
if ((colorWriteChannels & ColorWriteChannels.Green) == ColorWriteChannels.Green)
mask |= Dx10.ColorWriteMaskFlags.Green;
if ((colorWriteChannels & ColorWriteChannels.Red) == ColorWriteChannels.Red)
mask |= Dx10.ColorWriteMaskFlags.Red;
return mask;
}
#endregion
#region Translate (StencilOperation)
public static Dx10.StencilOperation Translate(StencilOperation stencilOperation)
{
switch (stencilOperation)
{
case StencilOperation.Decrement:
return Dx10.StencilOperation.Decrement;
case StencilOperation.DecrementSaturation:
return Dx10.StencilOperation.DecrementAndClamp;
case StencilOperation.Increment:
return Dx10.StencilOperation.Increment;
case StencilOperation.IncrementSaturation:
return Dx10.StencilOperation.IncrementAndClamp;
case StencilOperation.Invert:
return Dx10.StencilOperation.Invert;
case StencilOperation.Keep:
return Dx10.StencilOperation.Keep;
case StencilOperation.Replace:
return Dx10.StencilOperation.Replace;
case StencilOperation.Zero:
return Dx10.StencilOperation.Zero;
}
throw new NotImplementedException("unknown StencilOperation");
}
#endregion
#region Translate (CompareFunction)
public static Dx10.Comparison Translate(CompareFunction compareFunction)
{
switch (compareFunction)
{
case CompareFunction.Always:
return Dx10.Comparison.Always;
case CompareFunction.Equal:
return Dx10.Comparison.Equal;
case CompareFunction.Greater:
return Dx10.Comparison.Greater;
case CompareFunction.GreaterEqual:
return Dx10.Comparison.GreaterEqual;
case CompareFunction.Less:
return Dx10.Comparison.Less;
case CompareFunction.LessEqual:
return Dx10.Comparison.LessEqual;
case CompareFunction.Never:
return Dx10.Comparison.Never;
case CompareFunction.NotEqual:
return Dx10.Comparison.NotEqual;
}
throw new NotImplementedException("unknown CompareFunction");
}
#endregion
#region Translate (CullMode)
public static Dx10.CullMode Translate(CullMode cullMode)
{
if (cullMode == CullMode.CullClockwiseFace)
return Dx10.CullMode.Front;
else if (cullMode == CullMode.CullCounterClockwiseFace)
return Dx10.CullMode.Back;
else
return Dx10.CullMode.None;
}
#endregion
#region Translate (FillMode)
public static Dx10.FillMode Translate(FillMode fillMode)
{
return fillMode == FillMode.WireFrame ? Dx10.FillMode.Wireframe : Dx10.FillMode.Solid;
}
#endregion
#region CalculateVertexCount
public static int CalculateVertexCount(PrimitiveType type, int primitiveCount)
{
if (type == PrimitiveType.TriangleList)
return primitiveCount * 3;
else if (type == PrimitiveType.LineList)
return primitiveCount * 2;
else if (type == PrimitiveType.LineStrip)
return primitiveCount + 1;
else if (type == PrimitiveType.TriangleStrip)
return primitiveCount + 2;
throw new NotImplementedException("Couldn't calculate vertex count for PrimitiveType '" + type + "'.");
}
#endregion
}
}

View File

@ -1,26 +1,19 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Direct3D10;
using SharpDX.D3DCompiler;
using System.IO;
using ANX.Framework.NonXNA;
using ANX.Framework.Graphics;
#endregion // Using Statements
using SharpDX.D3DCompiler;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.RenderSystem.Windows.DX10
namespace ANX.RenderSystem.Windows.DX10.Helpers
{
internal class IncludeHandler : Include
{
private string directory;
public IDisposable Shadow { get; set; }
public IncludeHandler(string directory)
{
this.directory = directory;
@ -35,13 +28,7 @@ namespace ANX.RenderSystem.Windows.DX10
{
//Console.WriteLine("Including {0} file {1} from directory {2}", type.ToString(), fileName, directory);
return System.IO.File.OpenRead(System.IO.Path.Combine(directory, fileName));
}
public IDisposable Shadow
{
get;
set;
return File.OpenRead(Path.Combine(directory, fileName));
}
public void Dispose()

View File

@ -0,0 +1,47 @@
using System;
using System.Runtime.InteropServices;
using ANX.Framework.Graphics;
namespace ANX.RenderSystem.Windows.DX10.Helpers
{
internal static class WindowHelper
{
[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
}
[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)]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
#region ResizeRenderWindow
public static void ResizeRenderWindow(PresentationParameters presentationParameters)
{
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);
}
}
#endregion
}
}

View File

@ -1,172 +1,149 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Direct3D10;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
#endregion // Using Statements
using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
using CullMode = ANX.Framework.Graphics.CullMode;
using FillMode = ANX.Framework.Graphics.FillMode;
namespace ANX.RenderSystem.Windows.DX10
{
public class RasterizerState_DX10 : INativeRasterizerState
{
#region Private Members
private RasterizerStateDescription description;
private SharpDX.Direct3D10.RasterizerState nativeRasterizerState;
private bool nativeRasterizerStateDirty;
private bool bound;
{
private const int intMaxOver16 = int.MaxValue / 16;
private const int intMaxOver16 = int.MaxValue / 16;
#region Private
private Dx10.RasterizerStateDescription description;
private Dx10.RasterizerState nativeRasterizerState;
private bool isDirty;
#endregion
#endregion // Private Members
#region Public
public bool IsBound { get; private set; }
public RasterizerState_DX10()
public CullMode CullMode
{
set
{
Dx10.CullMode cullMode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.CullMode, ref 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);
UpdateValueAndMarkDirtyIfNeeded(ref description.DepthBias, ref depthBiasValue);
}
}
public FillMode FillMode
{
set
{
Dx10.FillMode fillMode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FillMode, ref fillMode);
}
}
public bool MultiSampleAntiAlias
{
set
{
if (description.IsMultisampleEnabled != value)
{
isDirty = true;
description.IsMultisampleEnabled = value;
}
}
}
public bool ScissorTestEnable
{
set
{
if (description.IsScissorEnabled != value)
{
isDirty = true;
description.IsScissorEnabled = value;
}
}
}
public float SlopeScaleDepthBias
{
set
{
UpdateValueAndMarkDirtyIfNeeded(ref description.SlopeScaledDepthBias, ref value);
}
}
#endregion
#region Constructor
public RasterizerState_DX10()
{
this.description = new RasterizerStateDescription();
description.IsAntialiasedLineEnabled = false;
isDirty = true;
}
#endregion
this.description.IsAntialiasedLineEnabled = false;
this.nativeRasterizerStateDirty = true;
}
public void Apply(ANX.Framework.Graphics.GraphicsDevice graphicsDevice)
#region Apply
public void Apply(GraphicsDevice graphicsDevice)
{
GraphicsDeviceWindowsDX10 gdx10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
Device device = gdx10.NativeDevice;
UpdateNativeRasterizerState(graphicsDevice);
IsBound = true;
}
#endregion
UpdateNativeRasterizerState(device);
this.bound = true;
device.Rasterizer.State = this.nativeRasterizerState;
}
public void Release()
#region Release
public void Release()
{
this.bound = false;
}
IsBound = false;
}
#endregion
public void Dispose()
#region Dispose
public void Dispose()
{
if (this.nativeRasterizerState != null)
if (nativeRasterizerState != null)
{
this.nativeRasterizerState.Dispose();
this.nativeRasterizerState = null;
nativeRasterizerState.Dispose();
nativeRasterizerState = null;
}
}
}
#endregion
public bool IsBound
{
get
#region UpdateNativeRasterizerState
private void UpdateNativeRasterizerState(GraphicsDevice graphicsDevice)
{
Dx10.Device device = (graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
if (isDirty == true || nativeRasterizerState == null)
{
return this.bound;
Dispose();
nativeRasterizerState = new Dx10.RasterizerState(device, ref description);
isDirty = false;
}
}
public CullMode CullMode
{
set
{
SharpDX.Direct3D10.CullMode cullMode = FormatConverter.Translate(value);
device.Rasterizer.State = nativeRasterizerState;
}
#endregion
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 FillMode FillMode
{
set
{
SharpDX.Direct3D10.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.Direct3D10.RasterizerState(device, ref this.description);
this.nativeRasterizerStateDirty = false;
}
}
}
#region UpdateValueAndMarkDirtyIfNeeded
private void UpdateValueAndMarkDirtyIfNeeded<T>(ref T currentValue, ref T value)
{
if (value.Equals(currentValue) == false)
{
isDirty = true;
currentValue = value;
}
}
#endregion
}
}

View File

@ -1,13 +1,8 @@
#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.Direct3D10;
#endregion // Using Statements
using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -16,25 +11,21 @@ using SharpDX.Direct3D10;
namespace ANX.RenderSystem.Windows.DX10
{
public class RenderTarget2D_DX10 : Texture2D_DX10, INativeRenderTarget2D, INativeTexture2D
{
#region Private Members
#endregion // Private Members
public RenderTarget2D_DX10(GraphicsDevice graphics, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
{
#region Constructor
public RenderTarget2D_DX10(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;
GraphicsDeviceWindowsDX10 graphicsDX10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice;
Dx10.Device device = graphicsDX10.NativeDevice;
SharpDX.Direct3D10.Texture2DDescription description = new SharpDX.Direct3D10.Texture2DDescription()
var description = new Dx10.Texture2DDescription()
{
Width = width,
Height = height,
@ -42,19 +33,19 @@ namespace ANX.RenderSystem.Windows.DX10
ArraySize = 1,
Format = FormatConverter.Translate(preferredFormat),
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = SharpDX.Direct3D10.ResourceUsage.Default,
BindFlags = SharpDX.Direct3D10.BindFlags.ShaderResource | SharpDX.Direct3D10.BindFlags.RenderTarget,
CpuAccessFlags = SharpDX.Direct3D10.CpuAccessFlags.None,
OptionFlags = SharpDX.Direct3D10.ResourceOptionFlags.None,
Usage = Dx10.ResourceUsage.Default,
BindFlags = Dx10.BindFlags.ShaderResource | Dx10.BindFlags.RenderTarget,
CpuAccessFlags = Dx10.CpuAccessFlags.None,
OptionFlags = Dx10.ResourceOptionFlags.None,
};
this.nativeTexture = new SharpDX.Direct3D10.Texture2D(graphicsDX10.NativeDevice, description);
this.nativeShaderResourceView = new SharpDX.Direct3D10.ShaderResourceView(graphicsDX10.NativeDevice, this.nativeTexture);
nativeTexture = new Dx10.Texture2D(graphicsDX10.NativeDevice, description);
nativeShaderResourceView = new Dx10.ShaderResourceView(graphicsDX10.NativeDevice, 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);
}
}
formatSize = FormatConverter.FormatSize(surfaceFormat);
}
#endregion
}
}

View File

@ -1,10 +1,7 @@
#region Using Statements
using System;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D10;
#endregion // Using Statements
using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -14,160 +11,137 @@ namespace ANX.RenderSystem.Windows.DX10
{
public class SamplerState_DX10 : INativeSamplerState
{
#region Private Members
private SamplerStateDescription description;
private SharpDX.Direct3D10.SamplerState nativeSamplerState;
private bool nativeSamplerStateDirty;
private bool bound;
#region Private
private Dx10.SamplerStateDescription description;
private Dx10.SamplerState nativeSamplerState;
private bool isDirty;
#endregion
#endregion // Private Members
#region Public
public bool IsBound { get; private set; }
public SamplerState_DX10()
public ANX.Framework.Graphics.TextureAddressMode AddressU
{
set
{
Dx10.TextureAddressMode mode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.AddressU, ref mode);
}
}
public ANX.Framework.Graphics.TextureAddressMode AddressV
{
set
{
Dx10.TextureAddressMode mode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.AddressV, ref mode);
}
}
public ANX.Framework.Graphics.TextureAddressMode AddressW
{
set
{
Dx10.TextureAddressMode mode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.AddressW, ref mode);
}
}
public TextureFilter Filter
{
set
{
Dx10.Filter filter = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.Filter, ref filter);
}
}
public int MaxAnisotropy
{
set
{
UpdateValueAndMarkDirtyIfNeeded(ref description.MaximumAnisotropy, ref value);
}
}
public int MaxMipLevel
{
set
{
if (description.MaximumLod != value)
{
description.MaximumLod = value;
isDirty = true;
}
}
}
public float MipMapLevelOfDetailBias
{
set
{
UpdateValueAndMarkDirtyIfNeeded(ref description.MipLodBias, ref value);
}
}
#endregion
#region Constructor
public SamplerState_DX10()
{
this.description = new SamplerStateDescription();
isDirty = true;
}
#endregion
this.nativeSamplerStateDirty = true;
}
public void Apply(GraphicsDevice graphicsDevice, int index)
#region Apply
public void Apply(GraphicsDevice graphicsDevice, int index)
{
GraphicsDeviceWindowsDX10 gdx10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
Device device = gdx10.NativeDevice;
Dx10.Device device = (graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
UpdateNativeSamplerState(device);
this.bound = true;
IsBound = true;
device.PixelShader.SetSampler(index, this.nativeSamplerState);
}
device.PixelShader.SetSampler(index, nativeSamplerState);
}
#endregion
public void Release()
#region Release
public void Release()
{
this.bound = false;
}
IsBound = false;
}
#endregion
public bool IsBound
#region Dispose
public void Dispose()
{
get
{
return this.bound;
}
}
public ANX.Framework.Graphics.TextureAddressMode AddressU
{
set
if (nativeSamplerState != null)
{
SharpDX.Direct3D10.TextureAddressMode mode = FormatConverter.Translate(value);
if (description.AddressU != mode)
{
description.AddressU = mode;
nativeSamplerStateDirty = true;
}
nativeSamplerState.Dispose();
nativeSamplerState = null;
}
}
#endregion
public ANX.Framework.Graphics.TextureAddressMode AddressV
#region UpdateNativeSamplerState
private void UpdateNativeSamplerState(Dx10.Device device)
{
set
if (isDirty == true || nativeSamplerState == null)
{
SharpDX.Direct3D10.TextureAddressMode mode = FormatConverter.Translate(value);
if (description.AddressV != mode)
{
description.AddressV = mode;
nativeSamplerStateDirty = true;
}
Dispose();
nativeSamplerState = new Dx10.SamplerState(device, ref description);
isDirty = false;
}
}
}
#endregion
public ANX.Framework.Graphics.TextureAddressMode AddressW
{
set
{
SharpDX.Direct3D10.TextureAddressMode mode = FormatConverter.Translate(value);
if (description.AddressW != mode)
{
description.AddressW = mode;
nativeSamplerStateDirty = true;
}
}
}
public TextureFilter Filter
{
set
{
SharpDX.Direct3D10.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.Direct3D10.SamplerState(device, ref this.description);
this.nativeSamplerStateDirty = false;
}
}
}
#region UpdateValueAndMarkDirtyIfNeeded
private void UpdateValueAndMarkDirtyIfNeeded<T>(ref T currentValue, ref T value)
{
if (value.Equals(currentValue) == false)
{
isDirty = true;
currentValue = value;
}
}
#endregion
}
}

View File

@ -1,16 +1,11 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Graphics;
using SharpDX.Direct3D10;
using ANX.Framework.NonXNA.RenderSystem;
using System.IO;
using System.Runtime.InteropServices;
using ANX.Framework;
#endregion // Using Statements
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA.RenderSystem;
using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -20,61 +15,16 @@ namespace ANX.RenderSystem.Windows.DX10
{
public class Texture2D_DX10 : INativeTexture2D
{
#region Private Members
protected internal SharpDX.Direct3D10.Texture2D nativeTexture;
protected internal SharpDX.Direct3D10.ShaderResourceView nativeShaderResourceView;
#region Private
protected internal Dx10.Texture2D nativeTexture;
protected internal Dx10.ShaderResourceView nativeShaderResourceView;
protected internal int formatSize;
protected internal SurfaceFormat surfaceFormat;
protected internal GraphicsDevice graphicsDevice;
#endregion
#endregion // Private Members
internal Texture2D_DX10(GraphicsDevice graphicsDevice)
{
this.graphicsDevice = graphicsDevice;
}
public Texture2D_DX10(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;
GraphicsDeviceWindowsDX10 graphicsDX10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = graphicsDX10.NativeDevice;
SharpDX.Direct3D10.Texture2DDescription description = new SharpDX.Direct3D10.Texture2DDescription()
{
Width = width,
Height = height,
MipLevels = mipCount,
ArraySize = mipCount,
Format = FormatConverter.Translate(surfaceFormat),
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = SharpDX.Direct3D10.ResourceUsage.Dynamic,
BindFlags = SharpDX.Direct3D10.BindFlags.ShaderResource,
CpuAccessFlags = SharpDX.Direct3D10.CpuAccessFlags.Write,
OptionFlags = SharpDX.Direct3D10.ResourceOptionFlags.None,
};
this.nativeTexture = new SharpDX.Direct3D10.Texture2D(graphicsDX10.NativeDevice, description);
this.nativeShaderResourceView = new SharpDX.Direct3D10.ShaderResourceView(graphicsDX10.NativeDevice, 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.Direct3D10.Texture2D NativeTexture
#region Public
internal Dx10.Texture2D NativeTexture
{
get
{
@ -85,16 +35,14 @@ namespace ANX.RenderSystem.Windows.DX10
if (this.nativeTexture != value)
{
if (this.nativeTexture != null)
{
this.nativeTexture.Dispose();
}
this.nativeTexture = value;
}
}
}
internal SharpDX.Direct3D10.ShaderResourceView NativeShaderResourceView
internal Dx10.ShaderResourceView NativeShaderResourceView
{
get
{
@ -114,6 +62,79 @@ namespace ANX.RenderSystem.Windows.DX10
}
}
public int Width
{
get
{
return (this.nativeTexture != null) ? this.nativeTexture.Description.Width : 0;
}
}
public int Height
{
get
{
return (this.nativeTexture != null) ? this.nativeTexture.Description.Height : 0;
}
}
public GraphicsDevice GraphicsDevice
{
get
{
return this.graphicsDevice;
}
}
#endregion
#region Constructor
internal Texture2D_DX10(GraphicsDevice graphicsDevice)
{
this.graphicsDevice = graphicsDevice;
}
public Texture2D_DX10(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;
GraphicsDeviceWindowsDX10 graphicsDX10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
Dx10.Device device = graphicsDX10.NativeDevice;
Dx10.Texture2DDescription description = new Dx10.Texture2DDescription()
{
Width = width,
Height = height,
MipLevels = mipCount,
ArraySize = mipCount,
Format = FormatConverter.Translate(surfaceFormat),
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = Dx10.ResourceUsage.Dynamic,
BindFlags = Dx10.BindFlags.ShaderResource,
CpuAccessFlags = Dx10.CpuAccessFlags.Write,
OptionFlags = Dx10.ResourceOptionFlags.None,
};
this.nativeTexture = new Dx10.Texture2D(graphicsDX10.NativeDevice, description);
this.nativeShaderResourceView = new Dx10.ShaderResourceView(graphicsDX10.NativeDevice, 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);
}
#endregion
#region GetHashCode
public override int GetHashCode()
{
return NativeTexture.NativePointer.ToInt32();
}
#endregion
#region SetData
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct
{
SetData<T>(graphicsDevice, 0, data, 0, data.Length);
@ -124,7 +145,8 @@ namespace ANX.RenderSystem.Windows.DX10
SetData<T>(graphicsDevice, 0, data, startIndex, elementCount);
}
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
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
@ -132,8 +154,8 @@ namespace ANX.RenderSystem.Windows.DX10
if (this.surfaceFormat == SurfaceFormat.Color)
{
int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubResourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None);
int subresource = Dx10.Texture2D.CalculateSubResourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, Dx10.MapMode.WriteDiscard, Dx10.MapFlags.None);
int rowPitch = rectangle.Pitch;
unsafe
@ -174,8 +196,8 @@ namespace ANX.RenderSystem.Windows.DX10
int h = (Height + 3) >> 2;
formatSize = (surfaceFormat == SurfaceFormat.Dxt1) ? 8 : 16;
int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubResourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None);
int subresource = Dx10.Texture2D.CalculateSubResourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, Dx10.MapMode.WriteDiscard, Dx10.MapFlags.None);
SharpDX.DataStream ds = new SharpDX.DataStream(rectangle.DataPointer, Width * Height * 4 * 2, true, true);
int pitch = rectangle.Pitch;
int col = 0;
@ -222,40 +244,13 @@ namespace ANX.RenderSystem.Windows.DX10
}
}
public int Width
public void SetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
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;
}
throw new NotImplementedException();
}
#endregion
#region Dispose
public void Dispose()
{
if (this.nativeShaderResourceView != null)
@ -270,6 +265,7 @@ namespace ANX.RenderSystem.Windows.DX10
this.nativeTexture = null;
}
}
#endregion
#region SaveAsJpeg (TODO)
public void SaveAsJpeg(Stream stream, int width, int height)
@ -285,24 +281,7 @@ namespace ANX.RenderSystem.Windows.DX10
}
#endregion
#region INativeTexture2D Member
public void GetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
public void SetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
#endregion
#region INativeBuffer Member
#region GetData (TODO)
public void GetData<T>(T[] data) where T : struct
{
throw new NotImplementedException();
@ -313,6 +292,10 @@ namespace ANX.RenderSystem.Windows.DX10
throw new NotImplementedException();
}
public void GetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -243,16 +243,12 @@ namespace ANX.RenderSystem.Windows.GL3
}
#endregion
#region Apply (TODO)
#region Apply
public void Apply(GraphicsDevice graphicsDevice)
{
if (GraphicsDeviceWindowsGL3.activeEffect != this)
{
GL.Enable(EnableCap.Blend);
GL.UseProgram(CurrentTechnique.programHandle);
GraphicsDeviceWindowsGL3.activeEffect = this;
ErrorHelper.Check("UseProgram");
}
GL.UseProgram(CurrentTechnique.programHandle);
GraphicsDeviceWindowsGL3.activeEffect = this;
ErrorHelper.Check("UseProgram");
}
#endregion

View File

@ -59,8 +59,7 @@ namespace ANX.RenderSystem.Windows.GL3
/// <summary>
/// Create a ne effect technique object.
/// </summary>
internal EffectTechniqueGL3(Effect setParentEffect, string setName,
int setProgramHandle)
internal EffectTechniqueGL3(Effect setParentEffect, string setName, int setProgramHandle)
{
parentEffect = setParentEffect;
Name = setName;

View File

@ -20,17 +20,8 @@ namespace ANX.RenderSystem.Windows.GL3
#endregion
#region Private
/// <summary>
/// Native graphics context.
/// </summary>
private GraphicsContext nativeContext;
/// <summary>
/// The OpenTK window info helper class to provide window informations
/// to the graphics device.
/// </summary>
private IWindowInfo nativeWindowInfo;
private GraphicsMode graphicsMode;
private int cachedVersionMinor = -1;
@ -51,9 +42,7 @@ namespace ANX.RenderSystem.Windows.GL3
{
get
{
if (Current == null || Current.nativeContext == null)
return false;
return Current.nativeContext.IsCurrent;
return (Current == null || Current.nativeContext == null) ? false : Current.nativeContext.IsCurrent;
}
}
#endregion
@ -251,19 +240,16 @@ namespace ANX.RenderSystem.Windows.GL3
#endregion
#region DrawIndexedPrimitives
public void DrawIndexedPrimitives(PrimitiveType primitiveType,
int baseVertex, int minVertexIndex, int numVertices, int startIndex,
int primitiveCount)
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices,
int startIndex, int primitiveCount)
{
// TODO: baseVertex, minVertexIndex, numVertices, startIndex, primitiveCount
DrawElementsType elementsType =
boundIndexBuffer.elementSize == IndexElementSize.SixteenBits ?
// TODO: baseVertex, minVertexIndex, numVertices, startIndex
DrawElementsType elementsType = boundIndexBuffer.elementSize == IndexElementSize.SixteenBits ?
DrawElementsType.UnsignedShort :
DrawElementsType.UnsignedInt;
int count;
BeginMode mode = DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType,
primitiveCount, out count);
BeginMode mode = DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType, primitiveCount, out count);
GL.DrawElements(mode, count, elementsType, 0);
ErrorHelper.Check("DrawElements");
@ -348,8 +334,7 @@ namespace ANX.RenderSystem.Windows.GL3
boundVertexBuffers = new VertexBufferGL3[vertexBuffers.Length];
for (int index = 0; index < vertexBuffers.Length; index++)
{
var nativeBuffer =
(VertexBufferGL3)vertexBuffers[index].VertexBuffer.NativeVertexBuffer;
var nativeBuffer = (VertexBufferGL3)vertexBuffers[index].VertexBuffer.NativeVertexBuffer;
boundVertexBuffers[index] = nativeBuffer;
nativeBuffer.Bind(activeEffect);
}
@ -359,12 +344,8 @@ namespace ANX.RenderSystem.Windows.GL3
#region SetIndexBuffer
public void SetIndexBuffer(IndexBuffer indexBuffer)
{
IndexBufferGL3 nativeBuffer =
(IndexBufferGL3)indexBuffer.NativeIndexBuffer;
boundIndexBuffer = nativeBuffer;
GL.BindBuffer(BufferTarget.ElementArrayBuffer,
nativeBuffer.BufferHandle);
boundIndexBuffer = (IndexBufferGL3)indexBuffer.NativeIndexBuffer;
GL.BindBuffer(BufferTarget.ElementArrayBuffer, boundIndexBuffer.BufferHandle);
ErrorHelper.Check("BindBuffer");
}
#endregion

View File

@ -1,8 +1,8 @@
using System;
using ANX.Framework;
using ANX.Framework.Graphics;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using ANX.Framework;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -194,8 +194,7 @@ namespace ANX.RenderSystem.Windows.GL3.Helpers
/// </summary>
/// <param name="type">XNA PrimitiveType.</param>
/// <returns>Translated BeginMode for OpenGL.</returns>
public static BeginMode PrimitiveTypeToBeginMode(PrimitiveType type,
int primitiveCount, out int count)
public static BeginMode PrimitiveTypeToBeginMode(PrimitiveType type, int primitiveCount, out int count)
{
switch (type)
{

View File

@ -158,31 +158,112 @@ namespace ANX.Framework.Windows.GL3
#region DualTextureEffectShader
internal static byte[] DualTextureEffectByteCode = new byte[]
{
155, 005, 118, 101, 114, 116, 101, 120, 115, 104, 097, 100, 101, 114, 115,
228, 019, 118, 101, 114, 116, 101, 120, 103, 108, 111, 098, 097, 108, 123,
117, 110, 105, 102, 111, 114, 109, 032, 118, 101, 099, 052, 032, 068, 105,
102, 102, 117, 115, 101, 067, 111, 108, 111, 114, 059, 117, 110, 105, 102,
111, 114, 109, 032, 118, 101, 099, 052, 032, 070, 111, 103, 086, 101, 099,
116, 111, 114, 059, 117, 110, 105, 102, 111, 114, 109, 032, 109, 097, 116,
052, 032, 087, 111, 114, 108, 100, 086, 105, 101, 119, 080, 114, 111, 106,
059, 125, 118, 101, 114, 116, 101, 120, 115, 104, 097, 100, 101, 114, 115,
123, 115, 104, 097, 100, 101, 114, 032, 034, 086, 083, 068, 117, 097, 108,
084, 101, 120, 116, 117, 114, 101, 034, 123, 117, 110, 105, 102, 111, 114,
109, 032, 109, 097, 116, 052, 032, 087, 111, 114, 108, 100, 086, 105, 101,
119, 080, 114, 111, 106, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101,
032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 097, 116, 116, 114, 105,
098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 101, 120, 059, 097,
116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116,
101, 120, 050, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099,
084, 101, 120, 116, 117, 114, 101, 034, 123, 097, 116, 116, 114, 105, 098,
117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 097, 116,
116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 101,
120, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099,
050, 032, 116, 101, 120, 050, 059, 118, 097, 114, 121, 105, 110, 103, 032,
118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, 059, 118, 097,
114, 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 115, 112, 101, 099,
117, 108, 097, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101,
099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111,
111, 114, 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099,
050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111,
114, 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050,
114, 100, 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032,
041, 123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, 087,
111, 114, 108, 100, 086, 105, 101, 119, 080, 114, 111, 106, 042, 112, 111,
115, 059, 100, 105, 102, 102, 117, 115, 101, 061, 068, 105, 102, 102, 117,
115, 101, 067, 111, 108, 111, 114, 059, 115, 112, 101, 099, 117, 108, 097,
114, 061, 118, 101, 099, 052, 040, 048, 044, 048, 044, 048, 044, 115, 097,
116, 117, 114, 097, 116, 101, 040, 100, 111, 116, 040, 112, 111, 115, 044,
070, 111, 103, 086, 101, 099, 116, 111, 114, 041, 041, 041, 059, 100, 105,
102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 061, 116,
101, 120, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111,
111, 114, 100, 050, 061, 116, 101, 120, 050, 059, 125, 125, 115, 104, 097,
100, 101, 114, 032, 034, 086, 083, 068, 117, 097, 108, 084, 101, 120, 116,
117, 114, 101, 078, 111, 070, 111, 103, 034, 123, 097, 116, 116, 114, 105,
098, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 097,
116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116,
101, 120, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101,
099, 050, 032, 116, 101, 120, 050, 059, 118, 097, 114, 121, 105, 110, 103,
032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, 059, 118,
097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032, 100, 105, 102,
102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 059, 118, 097,
114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032, 100, 105, 102, 102,
117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 050, 059, 118, 111,
105, 100, 032, 109, 097, 105, 110, 040, 032, 041, 123, 103, 108, 095, 080,
111, 115, 105, 116, 105, 111, 110, 061, 087, 111, 114, 108, 100, 086, 105,
101, 119, 080, 114, 111, 106, 042, 112, 111, 115, 059, 100, 105, 102, 102,
117, 115, 101, 061, 068, 105, 102, 102, 117, 115, 101, 067, 111, 108, 111,
114, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111,
114, 100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, 115, 101, 084,
101, 120, 067, 111, 111, 114, 100, 050, 061, 116, 101, 120, 050, 059, 125,
125, 115, 104, 097, 100, 101, 114, 032, 034, 086, 083, 068, 117, 097, 108,
084, 101, 120, 116, 117, 114, 101, 086, 101, 114, 116, 101, 120, 067, 111,
108, 111, 114, 034, 123, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032,
118, 101, 099, 052, 032, 112, 111, 115, 059, 097, 116, 116, 114, 105, 098,
117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 101, 120, 059, 097, 116,
116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 101,
120, 050, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101,
099, 052, 032, 099, 111, 108, 059, 118, 097, 114, 121, 105, 110, 103, 032,
118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, 059, 118, 097,
114, 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 115, 112, 101, 099,
117, 108, 097, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101,
099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111,
111, 114, 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099,
050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111,
114, 100, 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032,
041, 123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, 087,
111, 114, 108, 100, 086, 105, 101, 119, 080, 114, 111, 106, 042, 112, 111,
115, 059, 100, 105, 102, 102, 117, 115, 101, 061, 068, 105, 102, 102, 117,
115, 101, 067, 111, 108, 111, 114, 042, 099, 111, 108, 059, 115, 112, 101,
099, 117, 108, 097, 114, 061, 118, 101, 099, 052, 040, 048, 044, 048, 044,
048, 044, 115, 097, 116, 117, 114, 097, 116, 101, 040, 100, 111, 116, 040,
112, 111, 115, 044, 070, 111, 103, 086, 101, 099, 116, 111, 114, 041, 041,
041, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111,
114, 100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, 115, 101, 084,
101, 120, 067, 111, 111, 114, 100, 050, 061, 116, 101, 120, 050, 059, 125,
125, 115, 104, 097, 100, 101, 114, 032, 034, 086, 083, 068, 117, 097, 108,
084, 101, 120, 116, 117, 114, 101, 086, 101, 114, 116, 101, 120, 067, 111,
108, 111, 114, 078, 111, 070, 111, 103, 034, 123, 097, 116, 116, 114, 105,
098, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 097,
116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116,
101, 120, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101,
099, 050, 032, 116, 101, 120, 050, 059, 097, 116, 116, 114, 105, 098, 117,
116, 101, 032, 118, 101, 099, 052, 032, 099, 111, 108, 059, 118, 097, 114,
121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117,
115, 101, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050,
032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114,
100, 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032, 041,
123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, 087, 111,
114, 108, 100, 086, 105, 101, 119, 080, 114, 111, 106, 042, 112, 111, 115,
059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114,
100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101,
120, 067, 111, 111, 114, 100, 050, 061, 116, 101, 120, 050, 059, 125, 125,
125, 102, 114, 097, 103, 109, 101, 110, 116, 115, 104, 097, 100, 101, 114,
115, 123, 115, 104, 097, 100, 101, 114, 032, 034, 080, 083, 068, 117, 097,
108, 084, 101, 120, 116, 117, 114, 101, 034, 123, 117, 110, 105, 102, 111,
100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032,
100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100,
050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032, 041, 123,
103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, 087, 111, 114,
108, 100, 086, 105, 101, 119, 080, 114, 111, 106, 042, 112, 111, 115, 059,
100, 105, 102, 102, 117, 115, 101, 061, 068, 105, 102, 102, 117, 115, 101,
067, 111, 108, 111, 114, 042, 099, 111, 108, 059, 100, 105, 102, 102, 117,
115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 061, 116, 101, 120, 059,
100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100,
050, 061, 116, 101, 120, 050, 059, 125, 125, 125, 102, 114, 097, 103, 109,
101, 110, 116, 103, 108, 111, 098, 097, 108, 123, 117, 110, 105, 102, 111,
114, 109, 032, 115, 097, 109, 112, 108, 101, 114, 050, 068, 032, 084, 101,
120, 116, 117, 114, 101, 059, 117, 110, 105, 102, 111, 114, 109, 032, 115,
097, 109, 112, 108, 101, 114, 050, 068, 032, 084, 101, 120, 116, 117, 114,
101, 050, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050,
101, 050, 059, 117, 110, 105, 102, 111, 114, 109, 032, 118, 101, 099, 051,
032, 070, 111, 103, 067, 111, 108, 111, 114, 059, 125, 102, 114, 097, 103,
109, 101, 110, 116, 115, 104, 097, 100, 101, 114, 115, 123, 115, 104, 097,
100, 101, 114, 032, 034, 080, 083, 068, 117, 097, 108, 084, 101, 120, 116,
117, 114, 101, 034, 123, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101,
099, 052, 032, 100, 105, 102, 102, 117, 115, 101, 059, 118, 097, 114, 121,
105, 110, 103, 032, 118, 101, 099, 052, 032, 115, 112, 101, 099, 117, 108,
097, 114, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050,
032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114,
100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032,
100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100,
@ -194,19 +275,63 @@ namespace ANX.Framework.Windows.GL3
101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, 120, 116, 117, 114,
101, 050, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111,
111, 114, 100, 050, 041, 059, 099, 111, 108, 111, 114, 046, 114, 103, 098,
032, 042, 061, 032, 050, 059, 103, 108, 095, 070, 114, 097, 103, 067, 111,
108, 111, 114, 061, 099, 111, 108, 111, 114, 059, 125, 125, 125, 116, 101,
099, 104, 110, 105, 113, 117, 101, 115, 123, 116, 101, 099, 104, 110, 105,
113, 117, 101, 032, 034, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114,
101, 069, 102, 102, 101, 099, 116, 034, 123, 118, 101, 114, 116, 101, 120,
032, 034, 083, 112, 114, 105, 116, 101, 086, 101, 114, 116, 101, 120, 083,
104, 097, 100, 101, 114, 034, 102, 114, 097, 103, 109, 101, 110, 116, 032,
034, 083, 112, 114, 105, 116, 101, 070, 114, 097, 103, 109, 101, 110, 116,
083, 104, 097, 100, 101, 114, 034, 125, 125, 187, 064, 170, 146, 113, 222,
195, 185, 241, 224, 197, 214, 045, 090, 110, 247, 026, 116, 240, 217, 022,
092, 081, 220, 169, 002, 136, 173, 102, 023, 033, 241, 036, 012, 008, 239,
183, 058, 168, 109, 213, 077, 167, 248, 035, 223, 044, 042, 036, 164, 161,
159, 223, 225, 129, 012, 168, 228, 127, 147, 224, 089, 079, 235
032, 042, 061, 032, 050, 059, 099, 111, 108, 111, 114, 032, 042, 061, 032,
111, 118, 101, 114, 108, 097, 121, 042, 100, 105, 102, 102, 117, 115, 101,
059, 099, 111, 108, 111, 114, 046, 114, 103, 098, 061, 108, 101, 114, 112,
040, 099, 111, 108, 111, 114, 046, 114, 103, 098, 044, 070, 111, 103, 067,
111, 108, 111, 114, 042, 099, 111, 108, 111, 114, 046, 097, 044, 115, 112,
101, 099, 117, 108, 097, 114, 046, 119, 041, 059, 103, 108, 095, 070, 114,
097, 103, 067, 111, 108, 111, 114, 061, 099, 111, 108, 111, 114, 059, 125,
125, 115, 104, 097, 100, 101, 114, 032, 034, 080, 083, 068, 117, 097, 108,
084, 101, 120, 116, 117, 114, 101, 078, 111, 070, 111, 103, 034, 123, 118,
097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102,
102, 117, 115, 101, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101,
099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111,
111, 114, 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099,
050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111,
114, 100, 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032,
041, 123, 118, 101, 099, 052, 032, 099, 111, 108, 111, 114, 061, 116, 101,
120, 116, 117, 114, 101, 050, 068, 040, 084, 101, 120, 116, 117, 114, 101,
044, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114,
100, 041, 059, 118, 101, 099, 052, 032, 111, 118, 101, 114, 108, 097, 121,
061, 116, 101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, 120, 116,
117, 114, 101, 050, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120,
067, 111, 111, 114, 100, 050, 041, 059, 099, 111, 108, 111, 114, 046, 114,
103, 098, 032, 042, 061, 032, 050, 059, 099, 111, 108, 111, 114, 032, 042,
061, 032, 111, 118, 101, 114, 108, 097, 121, 042, 100, 105, 102, 102, 117,
115, 101, 059, 103, 108, 095, 070, 114, 097, 103, 067, 111, 108, 111, 114,
061, 099, 111, 108, 111, 114, 059, 125, 125, 125, 116, 101, 099, 104, 110,
105, 113, 117, 101, 115, 123, 116, 101, 099, 104, 110, 105, 113, 117, 101,
032, 034, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 069, 102,
102, 101, 099, 116, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 086,
083, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 034, 102, 114,
097, 103, 109, 101, 110, 116, 032, 034, 080, 083, 068, 117, 097, 108, 084,
101, 120, 116, 117, 114, 101, 034, 125, 116, 101, 099, 104, 110, 105, 113,
117, 101, 032, 034, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101,
069, 102, 102, 101, 099, 116, 078, 111, 070, 111, 103, 034, 123, 118, 101,
114, 116, 101, 120, 032, 034, 086, 083, 068, 117, 097, 108, 084, 101, 120,
116, 117, 114, 101, 078, 111, 070, 111, 103, 034, 102, 114, 097, 103, 109,
101, 110, 116, 032, 034, 080, 083, 068, 117, 097, 108, 084, 101, 120, 116,
117, 114, 101, 078, 111, 070, 111, 103, 034, 125, 116, 101, 099, 104, 110,
105, 113, 117, 101, 032, 034, 068, 117, 097, 108, 084, 101, 120, 116, 117,
114, 101, 069, 102, 102, 101, 099, 116, 086, 101, 114, 116, 101, 120, 067,
111, 108, 111, 114, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 086,
083, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 086, 101, 114,
116, 101, 120, 067, 111, 108, 111, 114, 034, 102, 114, 097, 103, 109, 101,
110, 116, 032, 034, 080, 083, 068, 117, 097, 108, 084, 101, 120, 116, 117,
114, 101, 034, 125, 116, 101, 099, 104, 110, 105, 113, 117, 101, 032, 034,
068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 069, 102, 102, 101,
099, 116, 078, 111, 070, 111, 103, 086, 101, 114, 116, 101, 120, 067, 111,
108, 111, 114, 034, 123, 118, 101, 114, 116, 101, 120, 032, 034, 086, 083,
068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 101, 086, 101, 114, 116,
101, 120, 067, 111, 108, 111, 114, 078, 111, 070, 111, 103, 034, 102, 114,
097, 103, 109, 101, 110, 116, 032, 034, 080, 083, 068, 117, 097, 108, 084,
101, 120, 116, 117, 114, 101, 078, 111, 070, 111, 103, 034, 125, 125, 175,
031, 128, 135, 091, 053, 148, 130, 202, 159, 176, 084, 033, 124, 189, 185,
203, 176, 133, 157, 191, 216, 029, 170, 061, 255, 076, 118, 188, 098, 065,
207, 215, 039, 153, 215, 233, 181, 035, 132, 019, 152, 136, 212, 164, 051,
001, 074, 135, 233, 177, 169, 110, 009, 048, 124, 035, 141, 123, 034, 179,
143, 110, 122
};
#endregion //DualTextureEffectShader

View File

@ -262,24 +262,19 @@ namespace ANX.RenderSystem.Windows.GL3
private void MapVertexDeclaration(EffectGL3 effect)
{
EffectTechniqueGL3 currentTechnique = effect.CurrentTechnique;
ShaderAttributeGL3[] attributes = currentTechnique.activeAttributes;
VertexElement[] elements = vertexDeclaration.GetVertexElements();
if (elements.Length != attributes.Length)
{
throw new InvalidOperationException("Mapping the VertexDeclaration " +
"onto the glsl attributes failed because we have " +
attributes.Length + " Shader Attributes and " +
elements.Length + " elements in the vertex declaration which " +
"doesn't fit!");
}
throw new InvalidOperationException("Mapping the VertexDeclaration onto the glsl attributes failed because " +
"we have " + attributes.Length + " Shader Attributes and " + elements.Length + " elements in the vertex " +
"declaration which doesn't fit!");
for (int index = 0; index < attributes.Length; index++)
{
int location = attributes[index].Location;
attributes[index].Bind(elements[location].VertexElementUsage,
vertexDeclaration.VertexStride, elements[location].Offset);
attributes[index].Bind(elements[location].VertexElementUsage, vertexDeclaration.VertexStride,
elements[location].Offset);
}
}
#endregion

View File

@ -18,4 +18,3 @@ namespace DualTextureSample
}
}
}

View File

@ -2,49 +2,131 @@
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
//TODO: dummy implementation / placeholder
vertexglobal
{
uniform vec4 DiffuseColor;
uniform vec4 FogVector;
uniform mat4 WorldViewProj;
}
vertexshaders
{
shader "VSDualTexture"
{
uniform mat4 WorldViewProj;
attribute vec4 pos;
attribute vec2 tex;
attribute vec2 tex2;
varying vec4 diffuse;
varying vec4 specular;
varying vec2 diffuseTexCoord;
varying vec2 diffuseTexCoord2;
void main( )
{
gl_Position = WorldViewProj * pos;
diffuse = DiffuseColor;
specular = vec4(0, 0, 0, saturate(dot(pos, FogVector)));
diffuseTexCoord = tex;
diffuseTexCoord2 = tex2;
}
}
shader "VSDualTextureNoFog"
{
attribute vec4 pos;
attribute vec2 tex;
attribute vec2 tex2;
varying vec4 diffuse;
varying vec2 diffuseTexCoord;
varying vec2 diffuseTexCoord2;
void main( )
{
gl_Position = WorldViewProj * pos;
diffuse = DiffuseColor;
diffuseTexCoord = tex;
diffuseTexCoord2 = tex2;
}
}
shader "VSDualTextureVertexColor"
{
attribute vec4 pos;
attribute vec2 tex;
attribute vec2 tex2;
attribute vec4 col;
varying vec4 diffuse;
varying vec4 specular;
varying vec2 diffuseTexCoord;
varying vec2 diffuseTexCoord2;
void main( )
{
gl_Position = WorldViewProj * pos;
diffuse = DiffuseColor * col;
specular = vec4(0, 0, 0, saturate(dot(pos, FogVector)));
diffuseTexCoord = tex;
diffuseTexCoord2 = tex2;
}
}
shader "VSDualTextureVertexColorNoFog"
{
attribute vec4 pos;
attribute vec2 tex;
attribute vec2 tex2;
attribute vec4 col;
varying vec4 diffuse;
varying vec2 diffuseTexCoord;
varying vec2 diffuseTexCoord2;
void main( )
{
gl_Position = WorldViewProj * pos;
diffuse = DiffuseColor * col;
diffuseTexCoord = tex;
diffuseTexCoord2 = tex2;
}
}
}
fragmentglobal
{
uniform sampler2D Texture;
uniform sampler2D Texture2;
uniform vec3 FogColor;
}
fragmentshaders
{
shader "PSDualTexture"
{
uniform sampler2D Texture;
uniform sampler2D Texture2;
varying vec4 diffuse;
varying vec4 specular;
varying vec2 diffuseTexCoord;
varying vec2 diffuseTexCoord2;
void main( )
{
vec4 color = texture2D(Texture, diffuseTexCoord);
vec4 overlay = texture2D(Texture2, diffuseTexCoord2);
color.rgb *= 2;
// TODO
//color *= overlay * pin.Diffuse;
//ApplyFog(color, pin.Specular.w);
color *= overlay * diffuse;
color.rgb = lerp(color.rgb, FogColor * color.a, specular.w);
gl_FragColor = color;
}
}
shader "PSDualTextureNoFog"
{
varying vec4 diffuse;
varying vec2 diffuseTexCoord;
varying vec2 diffuseTexCoord2;
void main( )
{
vec4 color = texture2D(Texture, diffuseTexCoord);
vec4 overlay = texture2D(Texture2, diffuseTexCoord2);
color.rgb *= 2;
color *= overlay * diffuse;
gl_FragColor = color;
}
}
@ -54,7 +136,25 @@ techniques
{
technique "DualTextureEffect"
{
vertex "SpriteVertexShader"
fragment "SpriteFragmentShader"
vertex "VSDualTexture"
fragment "PSDualTexture"
}
technique "DualTextureEffectNoFog"
{
vertex "VSDualTextureNoFog"
fragment "PSDualTextureNoFog"
}
technique "DualTextureEffectVertexColor"
{
vertex "VSDualTextureVertexColor"
fragment "PSDualTexture"
}
technique "DualTextureEffectNoFogVertexColor"
{
vertex "VSDualTextureVertexColorNoFog"
fragment "PSDualTextureNoFog"
}
}