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

View File

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

View File

@ -10,8 +10,7 @@ namespace ANX.Framework.Graphics
public class AlphaTestEffect : Effect, IEffectMatrices, IEffectFog, IGraphicsResource public class AlphaTestEffect : Effect, IEffectMatrices, IEffectFog, IGraphicsResource
{ {
public AlphaTestEffect(GraphicsDevice device) public AlphaTestEffect(GraphicsDevice device)
: base(device, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode( : base(device, GetByteCode(), GetSourceLanguage())
NonXNA.PreDefinedShader.AlphaTestEffect))
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -22,6 +21,22 @@ namespace ANX.Framework.Graphics
throw new NotImplementedException(); 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() public override Effect Clone()
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -31,7 +31,7 @@ namespace ANX.Framework.Graphics
private Vector3 ambientLightColor; private Vector3 ambientLightColor;
public BasicEffect(GraphicsDevice graphics) public BasicEffect(GraphicsDevice graphics)
: base(graphics, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode(NonXNA.PreDefinedShader.BasicEffect)) : base(graphics, GetByteCode(), GetSourceLanguage())
{ {
world = base.Parameters["World"]; world = base.Parameters["World"];
view = base.Parameters["View"]; view = base.Parameters["View"];
@ -56,6 +56,22 @@ namespace ANX.Framework.Graphics
throw new NotImplementedException(); 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 public bool PreferPerPixelLighting
{ {
get get

View File

@ -83,8 +83,7 @@ namespace ANX.Framework.Graphics
#region Constructor #region Constructor
public DualTextureEffect(GraphicsDevice graphics) public DualTextureEffect(GraphicsDevice graphics)
: base(graphics, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode( : base(graphics, GetByteCode(), GetSourceLanguage())
NonXNA.PreDefinedShader.DualTextureEffect))
{ {
diffuseColor = Vector3.One; diffuseColor = Vector3.One;
Alpha = 1f; Alpha = 1f;
@ -114,6 +113,22 @@ namespace ANX.Framework.Graphics
} }
#endregion #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 #region Clone
public override Effect Clone() public override Effect Clone()
{ {

View File

@ -16,7 +16,7 @@ namespace ANX.Framework.Graphics
public class EnvironmentMapEffect : Effect, IEffectMatrices, IEffectLights, IEffectFog public class EnvironmentMapEffect : Effect, IEffectMatrices, IEffectLights, IEffectFog
{ {
public EnvironmentMapEffect(GraphicsDevice graphics) public EnvironmentMapEffect(GraphicsDevice graphics)
: base(graphics, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode(NonXNA.PreDefinedShader.EnvironmentMapEffect)) : base(graphics, GetByteCode(), GetSourceLanguage())
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -27,6 +27,22 @@ namespace ANX.Framework.Graphics
throw new NotImplementedException(); 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() public override Effect Clone()
{ {
return new EnvironmentMapEffect(this); return new EnvironmentMapEffect(this);

View File

@ -19,7 +19,7 @@ namespace ANX.Framework.Graphics
public class SkinnedEffect : Effect, IEffectMatrices, IEffectLights, IEffectFog public class SkinnedEffect : Effect, IEffectMatrices, IEffectLights, IEffectFog
{ {
public SkinnedEffect(GraphicsDevice graphics) public SkinnedEffect(GraphicsDevice graphics)
: base(graphics, AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().GetShaderByteCode(NonXNA.PreDefinedShader.SkinnedEffect)) : base(graphics, GetByteCode(), GetSourceLanguage())
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -30,6 +30,22 @@ namespace ANX.Framework.Graphics
throw new NotImplementedException(); 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() public override Effect Clone()
{ {
return new SkinnedEffect(this); return new SkinnedEffect(this);

View File

@ -82,9 +82,10 @@
<Compile Include="EffectParameter_DX10.cs" /> <Compile Include="EffectParameter_DX10.cs" />
<Compile Include="EffectTechnique_DX10.cs" /> <Compile Include="EffectTechnique_DX10.cs" />
<Compile Include="Effect_DX10.cs" /> <Compile Include="Effect_DX10.cs" />
<Compile Include="FormatConverter.cs" /> <Compile Include="Helpers\FormatConverter.cs" />
<Compile Include="GraphicsDeviceWindowsDX10.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="IndexBuffer_DX10.cs" />
<Compile Include="EffectPass_DX10.cs" /> <Compile Include="EffectPass_DX10.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -82,9 +82,10 @@
<Compile Include="EffectParameter_DX10.cs" /> <Compile Include="EffectParameter_DX10.cs" />
<Compile Include="EffectTechnique_DX10.cs" /> <Compile Include="EffectTechnique_DX10.cs" />
<Compile Include="Effect_DX10.cs" /> <Compile Include="Effect_DX10.cs" />
<Compile Include="FormatConverter.cs" /> <Compile Include="Helpers\FormatConverter.cs" />
<Compile Include="GraphicsDeviceWindowsDX10.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="IndexBuffer_DX10.cs" />
<Compile Include="EffectPass_DX10.cs" /> <Compile Include="EffectPass_DX10.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -83,9 +83,10 @@
<Compile Include="EffectParameter_DX10.cs" /> <Compile Include="EffectParameter_DX10.cs" />
<Compile Include="EffectTechnique_DX10.cs" /> <Compile Include="EffectTechnique_DX10.cs" />
<Compile Include="Effect_DX10.cs" /> <Compile Include="Effect_DX10.cs" />
<Compile Include="FormatConverter.cs" /> <Compile Include="Helpers\FormatConverter.cs" />
<Compile Include="GraphicsDeviceWindowsDX10.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="IndexBuffer_DX10.cs" />
<Compile Include="EffectPass_DX10.cs" /> <Compile Include="EffectPass_DX10.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -84,9 +84,10 @@
<Compile Include="EffectParameter_DX10.cs" /> <Compile Include="EffectParameter_DX10.cs" />
<Compile Include="EffectTechnique_DX10.cs" /> <Compile Include="EffectTechnique_DX10.cs" />
<Compile Include="Effect_DX10.cs" /> <Compile Include="Effect_DX10.cs" />
<Compile Include="FormatConverter.cs" /> <Compile Include="Helpers\FormatConverter.cs" />
<Compile Include="GraphicsDeviceWindowsDX10.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="IndexBuffer_DX10.cs" />
<Compile Include="EffectPass_DX10.cs" /> <Compile Include="EffectPass_DX10.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -1,14 +1,8 @@
#region Using Statements using ANX.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Direct3D10;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using ANX.Framework; using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -18,71 +12,31 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
public class BlendState_DX10 : INativeBlendState public class BlendState_DX10 : INativeBlendState
{ {
#region Private Members private const float ColorByteToFloatFactor = 1f / 255f;
private BlendStateDescription description;
private SharpDX.Direct3D10.BlendState nativeBlendState; #region Private
private bool nativeBlendStateDirty; private Dx10.BlendStateDescription description;
private Dx10.BlendState nativeBlendState;
private bool isDirty;
private SharpDX.Color4 blendFactor; private SharpDX.Color4 blendFactor;
private int multiSampleMask; private int multiSampleMask;
private bool bound; #endregion
#endregion // Private Members
public BlendState_DX10()
{
this.description = new BlendStateDescription();
for (int i = 0; i < description.IsBlendEnabled.Length; i++)
{
description.IsBlendEnabled[i] = (i < 4);
}
nativeBlendStateDirty = true;
}
public void Apply(GraphicsDevice graphics)
{
GraphicsDeviceWindowsDX10 gdx10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = gdx10.NativeDevice;
UpdateNativeBlendState(device);
this.bound = true;
device.OutputMerger.SetBlendState(nativeBlendState, this.blendFactor, this.multiSampleMask);
}
public void Release()
{
this.bound = false;
}
public void Dispose()
{
if (this.nativeBlendState != null)
{
this.nativeBlendState.Dispose();
this.nativeBlendState = null;
}
}
#region Public
public bool IsBound public bool IsBound
{ {
get get;
{ private set;
return this.bound;
}
} }
public Color BlendFactor public Color BlendFactor
{ {
set set
{ {
const float colorConvert = 1f / 255f; blendFactor.Red = value.R * ColorByteToFloatFactor;
blendFactor.Green = value.G * ColorByteToFloatFactor;
blendFactor.Red = value.R * colorConvert; blendFactor.Blue = value.B * ColorByteToFloatFactor;
blendFactor.Green = value.G * colorConvert; blendFactor.Alpha = value.A * ColorByteToFloatFactor;
blendFactor.Blue = value.B * colorConvert;
blendFactor.Alpha = value.A * colorConvert;
} }
} }
@ -90,7 +44,7 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
this.multiSampleMask = value; multiSampleMask = value;
} }
} }
@ -98,13 +52,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
BlendOperation alphaBlendOperation = FormatConverter.Translate(value); Dx10.BlendOperation alphaBlendOperation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.AlphaBlendOperation, ref alphaBlendOperation);
if (description.AlphaBlendOperation != alphaBlendOperation)
{
nativeBlendStateDirty = true;
description.AlphaBlendOperation = alphaBlendOperation;
}
} }
} }
@ -112,13 +61,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
BlendOperation blendOperation = FormatConverter.Translate(value); Dx10.BlendOperation blendOperation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BlendOperation, ref blendOperation);
if (description.BlendOperation != blendOperation)
{
nativeBlendStateDirty = true;
description.BlendOperation = blendOperation;
}
} }
} }
@ -126,13 +70,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
BlendOption destinationAlphaBlend = FormatConverter.Translate(value); Dx10.BlendOption destinationAlphaBlend = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.DestinationAlphaBlend, ref destinationAlphaBlend);
if (description.DestinationAlphaBlend != destinationAlphaBlend)
{
nativeBlendStateDirty = true;
description.DestinationAlphaBlend = destinationAlphaBlend;
}
} }
} }
@ -140,13 +79,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
BlendOption destinationBlend = FormatConverter.Translate(value); Dx10.BlendOption destinationBlend = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.DestinationBlend, ref destinationBlend);
if (description.DestinationBlend != destinationBlend)
{
nativeBlendStateDirty = true;
description.DestinationBlend = destinationBlend;
}
} }
} }
@ -154,13 +88,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value); Dx10.ColorWriteMaskFlags writeMask = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.RenderTargetWriteMask[0], ref writeMask);
if (description.RenderTargetWriteMask[0] != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
description.RenderTargetWriteMask[0] = renderTargetWriteMask;
}
} }
} }
@ -168,13 +97,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value); Dx10.ColorWriteMaskFlags writeMask = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.RenderTargetWriteMask[1], ref writeMask);
if (description.RenderTargetWriteMask[1] != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
description.RenderTargetWriteMask[1] = renderTargetWriteMask;
}
} }
} }
@ -182,13 +106,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value); Dx10.ColorWriteMaskFlags writeMask = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.RenderTargetWriteMask[2], ref writeMask);
if (description.RenderTargetWriteMask[2] != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
description.RenderTargetWriteMask[2] = renderTargetWriteMask;
}
} }
} }
@ -196,13 +115,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
ColorWriteMaskFlags renderTargetWriteMask = FormatConverter.Translate(value); Dx10.ColorWriteMaskFlags writeMask = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.RenderTargetWriteMask[3], ref writeMask);
if (description.RenderTargetWriteMask[3] != renderTargetWriteMask)
{
nativeBlendStateDirty = true;
description.RenderTargetWriteMask[3] = renderTargetWriteMask;
}
} }
} }
@ -210,13 +124,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
BlendOption sourceAlphaBlend = FormatConverter.Translate(value); Dx10.BlendOption sourceAlphaBlend = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.SourceAlphaBlend, ref sourceAlphaBlend);
if (description.SourceAlphaBlend != sourceAlphaBlend)
{
nativeBlendStateDirty = true;
description.SourceAlphaBlend = sourceAlphaBlend;
}
} }
} }
@ -224,30 +133,72 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
BlendOption sourceBlend = FormatConverter.Translate(value); Dx10.BlendOption sourceBlend = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.SourceBlend, ref sourceBlend);
}
}
#endregion
if (description.SourceBlend != sourceBlend) #region Constructor
public BlendState_DX10()
{ {
nativeBlendStateDirty = true; isDirty = true;
description.SourceBlend = sourceBlend; for (int i = 0; i < description.IsBlendEnabled.Length; i++)
} description.IsBlendEnabled[i] = (i < 4);
}
} }
#endregion
private void UpdateNativeBlendState(SharpDX.Direct3D10.Device device) #region Apply
public void Apply(GraphicsDevice graphics)
{ {
if (this.nativeBlendStateDirty == true || this.nativeBlendState == null) Dx10.Device device = (graphics.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
{
if (this.nativeBlendState != null)
{
this.nativeBlendState.Dispose();
this.nativeBlendState = null;
}
this.nativeBlendState = new SharpDX.Direct3D10.BlendState(device, ref this.description); UpdateNativeBlendState(device);
IsBound = true;
this.nativeBlendStateDirty = false; device.OutputMerger.SetBlendState(nativeBlendState, blendFactor, multiSampleMask);
}
#endregion
#region Release
public void Release()
{
IsBound = false;
}
#endregion
#region Dispose
public void Dispose()
{
if (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
#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.Graphics;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.RenderSystem; using ANX.Framework.NonXNA.RenderSystem;
using ANX.RenderSystem.Windows.DX10.Helpers;
using SharpDX.DXGI; using SharpDX.DXGI;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.

View File

@ -1,86 +1,36 @@
#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.Graphics;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using ANX.Framework; using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
using StencilOperation = ANX.Framework.Graphics.StencilOperation;
namespace ANX.RenderSystem.Windows.DX10 namespace ANX.RenderSystem.Windows.DX10
{ {
public class DepthStencilState_DX10 : INativeDepthStencilState public class DepthStencilState_DX10 : INativeDepthStencilState
{ {
#region Private Members #region Private
private DepthStencilStateDescription description; private Dx10.DepthStencilStateDescription description;
private SharpDX.Direct3D10.DepthStencilState nativeDepthStencilState; private Dx10.DepthStencilState nativeDepthStencilState;
private bool nativeDepthStencilStateDirty; private bool isDirty;
private bool bound;
private int referenceStencil; private int referenceStencil;
#endregion
#endregion // Private Members #region Public (TODO)
public DepthStencilState_DX10()
{
this.description = new DepthStencilStateDescription();
this.nativeDepthStencilStateDirty = true;
}
public void Apply(GraphicsDevice graphicsDevice)
{
GraphicsDeviceWindowsDX10 gdx10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
Device device = gdx10.NativeDevice;
UpdateNativeDepthStencilState(device);
this.bound = true;
device.OutputMerger.SetDepthStencilState(nativeDepthStencilState, this.referenceStencil);
}
public void Release()
{
this.bound = false;
}
public void Dispose()
{
if (this.nativeDepthStencilState != null)
{
this.nativeDepthStencilState.Dispose();
this.nativeDepthStencilState = null;
}
}
public bool IsBound public bool IsBound
{ {
get get;
{ private set;
return this.bound;
}
} }
public StencilOperation CounterClockwiseStencilDepthBufferFail public StencilOperation CounterClockwiseStencilDepthBufferFail
{ {
set set
{ {
SharpDX.Direct3D10.StencilOperation operation = FormatConverter.Translate(value); Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BackFace.DepthFailOperation, ref operation);
if (description.BackFace.DepthFailOperation != operation)
{
description.BackFace.DepthFailOperation = operation;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -88,13 +38,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.StencilOperation operation = FormatConverter.Translate(value); Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BackFace.FailOperation, ref operation);
if (description.BackFace.FailOperation != operation)
{
description.BackFace.FailOperation = operation;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -102,13 +47,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.Comparison comparison = FormatConverter.Translate(value); Dx10.Comparison comparison = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BackFace.Comparison, ref comparison);
if (description.BackFace.Comparison != comparison)
{
description.BackFace.Comparison = comparison;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -116,13 +56,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.StencilOperation operation = FormatConverter.Translate(value); Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.BackFace.PassOperation, ref operation);
if (description.BackFace.PassOperation != operation)
{
description.BackFace.PassOperation = operation;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -133,7 +68,7 @@ namespace ANX.RenderSystem.Windows.DX10
if (description.IsDepthEnabled != value) if (description.IsDepthEnabled != value)
{ {
description.IsDepthEnabled = value; description.IsDepthEnabled = value;
nativeDepthStencilStateDirty = true; isDirty = true;
} }
} }
} }
@ -142,13 +77,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.Comparison comparison = FormatConverter.Translate(value); Dx10.Comparison comparison = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.DepthComparison, ref comparison);
if (description.DepthComparison != comparison)
{
description.DepthComparison = comparison;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -156,13 +86,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
DepthWriteMask writeMask = value ? DepthWriteMask.All : DepthWriteMask.Zero; Dx10.DepthWriteMask writeMask = value ? Dx10.DepthWriteMask.All : Dx10.DepthWriteMask.Zero;
UpdateValueAndMarkDirtyIfNeeded(ref description.DepthWriteMask, ref writeMask);
if (description.DepthWriteMask != writeMask)
{
description.DepthWriteMask = writeMask;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -170,11 +95,7 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
if (this.referenceStencil != value) UpdateValueAndMarkDirtyIfNeeded(ref referenceStencil, ref value);
{
this.referenceStencil = value;
this.nativeDepthStencilStateDirty = true;
}
} }
} }
@ -182,13 +103,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.StencilOperation operation = FormatConverter.Translate(value); Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FrontFace.DepthFailOperation, ref operation);
if (description.FrontFace.DepthFailOperation != operation)
{
description.FrontFace.DepthFailOperation = operation;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -199,7 +115,7 @@ namespace ANX.RenderSystem.Windows.DX10
if (description.IsStencilEnabled != value) if (description.IsStencilEnabled != value)
{ {
description.IsStencilEnabled = value; description.IsStencilEnabled = value;
nativeDepthStencilStateDirty = true; isDirty = true;
} }
} }
} }
@ -208,13 +124,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.StencilOperation operation = FormatConverter.Translate(value); Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FrontFace.FailOperation, ref operation);
if (description.FrontFace.FailOperation != operation)
{
description.FrontFace.FailOperation = operation;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -222,13 +133,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.Comparison comparison = FormatConverter.Translate(value); Dx10.Comparison comparison = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FrontFace.Comparison, ref comparison);
if (description.FrontFace.Comparison != comparison)
{
description.FrontFace.Comparison = comparison;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -237,12 +143,7 @@ namespace ANX.RenderSystem.Windows.DX10
set set
{ {
byte stencilMask = (byte)value; //TODO: check range byte stencilMask = (byte)value; //TODO: check range
UpdateValueAndMarkDirtyIfNeeded(ref description.StencilReadMask, ref stencilMask);
if (description.StencilReadMask != stencilMask)
{
description.StencilReadMask = stencilMask;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -250,13 +151,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.StencilOperation operation = FormatConverter.Translate(value); Dx10.StencilOperation operation = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FrontFace.PassOperation, ref operation);
if (description.FrontFace.PassOperation != operation)
{
description.FrontFace.PassOperation = operation;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -265,12 +161,7 @@ namespace ANX.RenderSystem.Windows.DX10
set set
{ {
byte stencilWriteMask = (byte)value; //TODO: check range byte stencilWriteMask = (byte)value; //TODO: check range
UpdateValueAndMarkDirtyIfNeeded(ref description.StencilWriteMask, ref stencilWriteMask);
if (description.StencilWriteMask != stencilWriteMask)
{
description.StencilWriteMask = stencilWriteMask;
nativeDepthStencilStateDirty = true;
}
} }
} }
@ -278,24 +169,68 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
//TODO: check if we really need this. in xna this enables only counter clockwise stencil operations //TODO: check if we really need in xna this enables only counter clockwise stencil operations
} }
} }
#endregion
private void UpdateNativeDepthStencilState(Device device) #region Constructor
public DepthStencilState_DX10()
{ {
if (this.nativeDepthStencilStateDirty == true || this.nativeDepthStencilState == null) isDirty = true;
{
if (this.nativeDepthStencilState != null)
{
this.nativeDepthStencilState.Dispose();
this.nativeDepthStencilState = null;
} }
#endregion
this.nativeDepthStencilState = new SharpDX.Direct3D10.DepthStencilState(device, ref this.description); #region Apply
public void Apply(GraphicsDevice graphicsDevice)
{
Dx10.Device device = (graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
UpdateNativeDepthStencilState(device);
IsBound = true;
this.nativeDepthStencilStateDirty = false; device.OutputMerger.SetDepthStencilState(nativeDepthStencilState, referenceStencil);
}
#endregion
#region Release
public void Release()
{
IsBound = false;
}
#endregion
#region Dispose
public void Dispose()
{
if (nativeDepthStencilState != null)
{
nativeDepthStencilState.Dispose();
nativeDepthStencilState = null;
} }
} }
#endregion
#region UpdateNativeDepthStencilState
private void UpdateNativeDepthStencilState(Dx10.Device device)
{
if (isDirty == true || nativeDepthStencilState == null)
{
Dispose();
nativeDepthStencilState = new Dx10.DepthStencilState(device, ref description);
isDirty = false;
}
}
#endregion
#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,179 +1,169 @@
#region Using Statements
using System; 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; using ANX.Framework;
using ANX.Framework.Graphics;
#endregion // Using Statements using ANX.Framework.NonXNA;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/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 namespace ANX.RenderSystem.Windows.DX10
{ {
public class EffectParameter_DX10 : INativeEffectParameter public class EffectParameter_DX10 : INativeEffectParameter
{ {
private EffectVariable nativeEffectVariable; #region Public
public Dx10.EffectVariable NativeParameter
public EffectVariable NativeParameter
{ {
get get;
{ internal set;
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 public string Name
{ {
get get
{ {
return nativeEffectVariable.Description.Name; return NativeParameter.Description.Name;
} }
} }
#endregion
#region INativeEffectParameter Member #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() public bool GetValueBoolean()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -283,17 +273,6 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion
#region INativeEffectParameter Member
public void SetValue(string value)
{
throw new NotImplementedException();
}
#endregion #endregion
} }
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using ANX.RenderSystem.Windows.DX10.Helpers;
using SharpDX.D3DCompiler; using SharpDX.D3DCompiler;
using Dx10 = SharpDX.Direct3D10; using Dx10 = SharpDX.Direct3D10;
@ -92,34 +93,45 @@ namespace ANX.RenderSystem.Windows.DX10
} }
#endregion #endregion
#region GetCurrentTechnique
public EffectTechnique_DX10 GetCurrentTechnique() public EffectTechnique_DX10 GetCurrentTechnique()
{ {
return managedEffect.CurrentTechnique.NativeTechnique as EffectTechnique_DX10; return managedEffect.CurrentTechnique.NativeTechnique as EffectTechnique_DX10;
} }
#endregion
#region Apply
public void Apply(GraphicsDevice graphicsDevice) public void Apply(GraphicsDevice graphicsDevice)
{ {
((GraphicsDeviceWindowsDX10)graphicsDevice.NativeDevice).currentEffect = this; ((GraphicsDeviceWindowsDX10)graphicsDevice.NativeDevice).currentEffect = this;
} }
#endregion
#region CompileVertexShader (TODO)
public static byte[] CompileVertexShader(string effectCode, string directory = "") 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, ShaderBytecode vertexShaderByteCode = ShaderBytecode.Compile(effectCode, "VS", "vs_4_0", ShaderFlags.None,
EffectFlags.None, null, new IncludeHandler(directory), "unknown"); EffectFlags.None, null, new IncludeHandler(directory), "unknown");
byte[] bytecode = new byte[vertexShaderByteCode.BufferSize]; byte[] bytecode = new byte[vertexShaderByteCode.BufferSize];
vertexShaderByteCode.Data.Read(bytecode, 0, bytecode.Length); vertexShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
return bytecode; return bytecode;
} }
#endregion
#region CompilePixelShader (TODO)
public static byte[] CompilePixelShader(string effectCode, string directory = "") 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, ShaderBytecode pixelShaderByteCode = ShaderBytecode.Compile(effectCode, "PS", "ps_4_0", ShaderFlags.None,
EffectFlags.None, null, new IncludeHandler(directory), "unknown"); EffectFlags.None, null, new IncludeHandler(directory), "unknown");
byte[] bytecode = new byte[pixelShaderByteCode.BufferSize]; byte[] bytecode = new byte[pixelShaderByteCode.BufferSize];
pixelShaderByteCode.Data.Read(bytecode, 0, bytecode.Length); pixelShaderByteCode.Data.Read(bytecode, 0, bytecode.Length);
return bytecode; return bytecode;
} }
#endregion
#region CompileFXShader
public static byte[] CompileFXShader(string effectCode, string directory = "") public static byte[] CompileFXShader(string effectCode, string directory = "")
{ {
ShaderBytecode effectByteCode = ShaderBytecode.Compile(effectCode, "fx_4_0", ShaderFlags.None, EffectFlags.None, ShaderBytecode effectByteCode = ShaderBytecode.Compile(effectCode, "fx_4_0", ShaderFlags.None, EffectFlags.None,
@ -128,6 +140,7 @@ namespace ANX.RenderSystem.Windows.DX10
effectByteCode.Data.Read(bytecode, 0, bytecode.Length); effectByteCode.Data.Read(bytecode, 0, bytecode.Length);
return bytecode; return bytecode;
} }
#endregion
#region Dispose #region Dispose
public void 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 System;
using SharpDX.DXGI;
using SharpDX.D3DCompiler;
using SharpDX.Direct3D10;
using ANX.Framework; using ANX.Framework;
using ANX.Framework.NonXNA;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using System.Runtime.InteropServices; using ANX.Framework.NonXNA;
using ANX.RenderSystem.Windows.DX10.Helpers;
#endregion // Using Statements using SharpDX.D3DCompiler;
using SharpDX.DXGI;
using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/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 namespace ANX.RenderSystem.Windows.DX10
{ {
public class GraphicsDeviceWindowsDX10 : INativeGraphicsDevice public class GraphicsDeviceWindowsDX10 : INativeGraphicsDevice
@ -28,48 +19,24 @@ namespace ANX.RenderSystem.Windows.DX10
private const float ColorMultiplier = 1f / 255f; private const float ColorMultiplier = 1f / 255f;
#endregion #endregion
#region Interop #region Private
[DllImport("user32.dll")] private Dx10.Device device;
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 SwapChain swapChain;
private RenderTargetView renderView; private Dx10.RenderTargetView renderView;
private RenderTargetView[] renderTargetView = new RenderTargetView[1]; private Dx10.RenderTargetView[] renderTargetView = new Dx10.RenderTargetView[1];
private DepthStencilView depthStencilView; private Dx10.DepthStencilView depthStencilView;
private SharpDX.Direct3D10.Texture2D depthStencilBuffer; private Dx10.Texture2D depthStencilBuffer;
private SharpDX.Direct3D10.Texture2D backBuffer; private Dx10.Texture2D backBuffer;
internal Effect_DX10 currentEffect; internal Effect_DX10 currentEffect;
private VertexBuffer currentVertexBuffer; private VertexBuffer currentVertexBuffer;
private IndexBuffer currentIndexBuffer; private IndexBuffer currentIndexBuffer;
private SharpDX.Direct3D10.Viewport currentViewport; private Dx10.Viewport currentViewport;
private uint lastClearColor; private uint lastClearColor;
private SharpDX.Color4 clearColor; private SharpDX.Color4 clearColor;
private bool vSyncEnabled; #endregion
#endregion // Private Members #region Public
internal Dx10.Device NativeDevice
internal Device NativeDevice
{ {
get get
{ {
@ -77,15 +44,21 @@ namespace ANX.RenderSystem.Windows.DX10
} }
} }
public bool VSync { get; set; }
#endregion
#region Constructor
public GraphicsDeviceWindowsDX10(PresentationParameters presentationParameters) public GraphicsDeviceWindowsDX10(PresentationParameters presentationParameters)
{ {
this.vSyncEnabled = true; VSync = true;
// SwapChain description // SwapChain description
var desc = new SwapChainDescription() var desc = new SwapChainDescription()
{ {
BufferCount = 1, 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, IsWindowed = true,
OutputHandle = presentationParameters.DeviceWindowHandle, OutputHandle = presentationParameters.DeviceWindowHandle,
SampleDescription = new SampleDescription(1, 0), SampleDescription = new SampleDescription(1, 0),
@ -96,33 +69,35 @@ namespace ANX.RenderSystem.Windows.DX10
// Create Device and SwapChain // Create Device and SwapChain
#if DIRECTX_DEBUG_LAYER #if DIRECTX_DEBUG_LAYER
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb205068(v=vs.85).aspx // 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 #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 #endif
// Ignore all windows events // Ignore all windows events
Factory factory = swapChain.GetParent<Factory>(); Factory factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(presentationParameters.DeviceWindowHandle, WindowAssociationFlags.IgnoreAll); factory.MakeWindowAssociation(presentationParameters.DeviceWindowHandle, WindowAssociationFlags.IgnoreAll);
ResizeRenderWindow(presentationParameters); WindowHelper.ResizeRenderWindow(presentationParameters);
// New RenderTargetView from the backbuffer // New RenderTargetView from the backbuffer
backBuffer = SharpDX.Direct3D10.Texture2D.FromSwapChain<SharpDX.Direct3D10.Texture2D>(swapChain, 0); backBuffer = Dx10.Texture2D.FromSwapChain<Dx10.Texture2D>(swapChain, 0);
renderView = new RenderTargetView(device, backBuffer); 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 // create the depth stencil buffer
// //
Format depthFormat = FormatConverter.Translate(presentationParameters.DepthStencilFormat); Format depthFormat = FormatConverter.Translate(presentationParameters.DepthStencilFormat);
if (depthFormat != Format.Unknown) if (depthFormat != Format.Unknown)
{
CreateDepthStencilBuffer(depthFormat); CreateDepthStencilBuffer(depthFormat);
} }
} #endregion
#region CreateDepthStencilBuffer
private void CreateDepthStencilBuffer(Format depthFormat) private void CreateDepthStencilBuffer(Format depthFormat)
{ {
if (this.depthStencilBuffer != null && if (this.depthStencilBuffer != null &&
@ -152,12 +127,12 @@ namespace ANX.RenderSystem.Windows.DX10
return; return;
} }
DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription() var depthStencilViewDesc = new Dx10.DepthStencilViewDescription()
{ {
Format = depthFormat, Format = depthFormat,
}; };
Texture2DDescription depthStencilTextureDesc = new Texture2DDescription() var depthStencilTextureDesc = new Dx10.Texture2DDescription()
{ {
Width = this.backBuffer.Description.Width, Width = this.backBuffer.Description.Width,
Height = this.backBuffer.Description.Height, Height = this.backBuffer.Description.Height,
@ -165,17 +140,19 @@ namespace ANX.RenderSystem.Windows.DX10
ArraySize = 1, ArraySize = 1,
Format = depthFormat, Format = depthFormat,
SampleDescription = new SampleDescription(1, 0), SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default, Usage = Dx10.ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil, BindFlags = Dx10.BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None, CpuAccessFlags = Dx10.CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.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 #region Clear
public void Clear(ref Color color) public void Clear(ref Color color)
@ -243,122 +220,117 @@ namespace ANX.RenderSystem.Windows.DX10
if ((options | ClearOptions.Stencil | ClearOptions.DepthBuffer) == options) if ((options | ClearOptions.Stencil | ClearOptions.DepthBuffer) == options)
{ {
// Clear the stencil buffer // 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) 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 else
{ {
device.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Depth, depth, (byte)stencil); device.ClearDepthStencilView(this.depthStencilView, Dx10.DepthStencilClearFlags.Depth, depth, (byte)stencil);
} }
} }
} }
#endregion #endregion
#region Present #region Present
public void 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,
#region DrawPrimitives & DrawIndexedPrimitives int startIndex, int primitiveCount)
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; Dx10.EffectTechnique technique = SetupEffectForDraw();
SetupEffectForDraw(out pass, out technique, out passSignature); int vertexCount = FormatConverter.CalculateVertexCount(primitiveType, primitiveCount);
SetupInputLayout(passSignature);
// Prepare All the stages
device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType); device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
device.Rasterizer.SetViewports(currentViewport); device.Rasterizer.SetViewports(currentViewport);
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView); device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i) for (int i = 0; i < technique.Description.PassCount; ++i)
{ {
pass.Apply(); technique.GetPassByIndex(i).Apply();
device.DrawIndexed(CalculateVertexCount(primitiveType, primitiveCount), startIndex, baseVertex); device.DrawIndexed(vertexCount, startIndex, baseVertex);
} }
} }
#endregion
#region DrawPrimitives
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount) public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset, int primitiveCount)
{ {
SharpDX.Direct3D10.EffectPass pass; SharpDX.Direct3D10.EffectTechnique technique; ShaderBytecode passSignature; Dx10.EffectTechnique technique = SetupEffectForDraw();
SetupEffectForDraw(out pass, out technique, out passSignature);
SetupInputLayout(passSignature);
// Prepare All the stages
device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType); device.InputAssembler.PrimitiveTopology = FormatConverter.Translate(primitiveType);
device.Rasterizer.SetViewports(currentViewport); device.Rasterizer.SetViewports(currentViewport);
device.OutputMerger.SetTargets(this.depthStencilView, this.renderView); device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
for (int i = 0; i < technique.Description.PassCount; ++i) for (int i = 0; i < technique.Description.PassCount; ++i)
{ {
pass.Apply(); technique.GetPassByIndex(i).Apply();
device.Draw(primitiveCount, vertexOffset); device.Draw(primitiveCount, vertexOffset);
} }
} }
#endregion
#endregion // DrawPrimitives & DrawIndexedPrimitives
#region DrawInstancedPrimitives #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); device.DrawIndexedInstanced(numVertices, instanceCount, startIndex, baseVertex, 0);
} }
#endregion
#endregion // DrawInstancedPrimitives
#region DrawUserIndexedPrimitives<T> #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 vertexCount = vertexData.Length;
int indexCount = indexData.Length; int indexCount = indexData.Length;
VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(this.device, vertexDeclaration, vertexCount, BufferUsage.None); VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(this.device, vertexDeclaration, vertexCount, BufferUsage.None);
vb10.SetData<T>(null, vertexData); 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); device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
IndexBuffer_DX10 idx10 = new IndexBuffer_DX10(this.device, indexFormat, indexCount, BufferUsage.None); IndexBuffer_DX10 idx10 = new IndexBuffer_DX10(this.device, indexFormat, indexCount, BufferUsage.None);
if (indexData.GetType() == typeof(Int16[])) if (indexData.GetType() == typeof(Int16[]))
{
idx10.SetData<short>(null, (short[])indexData); idx10.SetData<short>(null, (short[])indexData);
}
else else
{
idx10.SetData<int>(null, (int[])indexData); idx10.SetData<int>(null, (int[])indexData);
}
DrawIndexedPrimitives(primitiveType, 0, vertexOffset, numVertices, indexOffset, primitiveCount); DrawIndexedPrimitives(primitiveType, 0, vertexOffset, numVertices, indexOffset, primitiveCount);
} }
#endregion
#endregion // DrawUserIndexedPrimitives<T>
#region DrawUserPrimitives<T> #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; int vertexCount = vertexData.Length;
VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(this.device, vertexDeclaration, vertexCount, BufferUsage.None); VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(this.device, vertexDeclaration, vertexCount, BufferUsage.None);
vb10.SetData<T>(null, vertexData); 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); device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
SharpDX.Direct3D10.EffectPass pass; SharpDX.Direct3D10.EffectTechnique technique; ShaderBytecode passSignature; //TODO: check for currentEffect null and throw exception
SetupEffectForDraw(out pass, out technique, out passSignature); // TODO: check for null's and throw exceptions
// TODO: get the correct pass index!
var layout = CreateInputLayout(device, passSignature, vertexDeclaration); var technique = currentEffect.GetCurrentTechnique().NativeTechnique;
var pass = technique.GetPassByIndex(0);
var layout = CreateInputLayout(device, pass.Description.Signature, vertexDeclaration);
device.InputAssembler.InputLayout = layout; device.InputAssembler.InputLayout = layout;
// Prepare All the stages // Prepare All the stages
@ -373,28 +345,25 @@ namespace ANX.RenderSystem.Windows.DX10
device.Draw(primitiveCount, vertexOffset); device.Draw(primitiveCount, vertexOffset);
} }
} }
#endregion
#endregion // DrawUserPrimitives<T> #region SetupEffectForDraw
private Dx10.EffectTechnique SetupEffectForDraw()
private void SetupEffectForDraw(out SharpDX.Direct3D10.EffectPass pass, out SharpDX.Direct3D10.EffectTechnique technique,
out ShaderBytecode passSignature)
{ {
// get the current effect //TODO: check for currentEffect null and throw exception
//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 null's and throw exceptions // TODO: check for null's and throw exceptions
// TODO: get the correct pass index! // TODO: get the correct pass index!
technique = effect.GetCurrentTechnique().NativeTechnique; var technique = currentEffect.GetCurrentTechnique().NativeTechnique;
pass = technique.GetPassByIndex(0); var pass = technique.GetPassByIndex(0);
passSignature = pass.Description.Signature; SetupInputLayout(pass.Description.Signature);
}
return technique;
}
#endregion
#region SetupInputLayout
private void SetupInputLayout(ShaderBytecode passSignature) private void SetupInputLayout(ShaderBytecode passSignature)
{ {
// get the VertexDeclaration from current VertexBuffer to create input layout for the input assembler
if (currentVertexBuffer == null) if (currentVertexBuffer == null)
throw new ArgumentNullException("passSignature"); throw new ArgumentNullException("passSignature");
@ -403,31 +372,9 @@ namespace ANX.RenderSystem.Windows.DX10
device.InputAssembler.InputLayout = layout; device.InputAssembler.InputLayout = layout;
} }
#endregion
private int CalculateVertexCount(PrimitiveType type, int primitiveCount) #region SetIndexBuffer
{
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() + "'");
}
}
public void SetIndexBuffer(IndexBuffer indexBuffer) public void SetIndexBuffer(IndexBuffer indexBuffer)
{ {
if (indexBuffer == null) if (indexBuffer == null)
@ -448,30 +395,30 @@ namespace ANX.RenderSystem.Windows.DX10
throw new Exception("couldn't fetch native DirectX10 IndexBuffer"); throw new Exception("couldn't fetch native DirectX10 IndexBuffer");
} }
} }
#endregion
#if XNAEXT #if XNAEXT
#region SetConstantBuffer
public void SetConstantBuffer(int slot, ANX.Framework.Graphics.ConstantBuffer constantBuffer) public void SetConstantBuffer(int slot, ANX.Framework.Graphics.ConstantBuffer constantBuffer)
{ {
if (constantBuffer == null) if (constantBuffer == null)
{
throw new ArgumentNullException("constantBuffer"); throw new ArgumentNullException("constantBuffer");
}
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion
#endif #endif
#region SetVertexBuffers
public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers) public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
{ {
if (vertexBuffers == null) if (vertexBuffers == null)
{
throw new ArgumentNullException("vertexBuffers"); throw new ArgumentNullException("vertexBuffers");
}
this.currentVertexBuffer = vertexBuffers[0].VertexBuffer; //TODO: hmmmmm, not nice :-) this.currentVertexBuffer = vertexBuffers[0].VertexBuffer; //TODO: hmmmmm, not nice :-)
SharpDX.Direct3D10.VertexBufferBinding[] nativeVertexBufferBindings = Dx10.VertexBufferBinding[] nativeVertexBufferBindings =
new SharpDX.Direct3D10.VertexBufferBinding[vertexBuffers.Length]; new Dx10.VertexBufferBinding[vertexBuffers.Length];
for (int i = 0; i < vertexBuffers.Length; i++) for (int i = 0; i < vertexBuffers.Length; i++)
{ {
ANX.Framework.Graphics.VertexBufferBinding anxVertexBufferBinding = vertexBuffers[i]; ANX.Framework.Graphics.VertexBufferBinding anxVertexBufferBinding = vertexBuffers[i];
@ -479,7 +426,7 @@ namespace ANX.RenderSystem.Windows.DX10
if (nativeVertexBuffer != null) if (nativeVertexBuffer != null)
{ {
nativeVertexBufferBindings[i] = new SharpDX.Direct3D10.VertexBufferBinding(nativeVertexBuffer.NativeBuffer, nativeVertexBufferBindings[i] = new Dx10.VertexBufferBinding(nativeVertexBuffer.NativeBuffer,
anxVertexBufferBinding.VertexBuffer.VertexDeclaration.VertexStride, anxVertexBufferBinding.VertexOffset); anxVertexBufferBinding.VertexBuffer.VertexDeclaration.VertexStride, anxVertexBufferBinding.VertexOffset);
} }
else else
@ -490,36 +437,45 @@ namespace ANX.RenderSystem.Windows.DX10
device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings); device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
} }
#endregion
#region SetViewport
public void SetViewport(Viewport viewport) 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); viewport.MinDepth, viewport.MaxDepth);
} }
#endregion
#region CreateInputLayout
/// <summary> /// <summary>
/// This method creates a InputLayout which is needed by DirectX 10 for rendering primitives. /// 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. /// The VertexDeclaration of ANX/XNA needs to be mapped to the DirectX 10 types.
/// </summary> /// </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(); VertexElement[] vertexElements = vertexDeclaration.GetVertexElements();
int elementCount = vertexElements.Length; int elementCount = vertexElements.Length;
InputElement[] inputElements = new InputElement[elementCount]; var inputElements = new Dx10.InputElement[elementCount];
for (int i = 0; i < elementCount; i++) for (int i = 0; i < elementCount; i++)
inputElements[i] = CreateInputElementFromVertexElement(vertexElements[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); string elementName = FormatConverter.Translate(ref vertexElement);
Format elementFormat = ConvertVertexElementFormat(vertexElement.VertexElementFormat); 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) private Format ConvertVertexElementFormat(VertexElementFormat format)
{ {
switch (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."); throw new Exception("Can't map '" + format + "' to DXGI.Format in Dx10 CreateInputElementFromVertexElement.");
} }
#endregion
#region SetRenderTargets #region SetRenderTargets
public void SetRenderTargets(params RenderTargetBinding[] renderTargets) 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); device.OutputMerger.SetTargets(this.depthStencilView, this.renderView);
} }
else 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++) for (int i = 0; i < renderTargetCount; i++)
@ -591,7 +548,7 @@ namespace ANX.RenderSystem.Windows.DX10
renderTargetView[i].Dispose(); 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 #endregion
#region GetBackBufferData #region GetBackBufferData (TODO)
public void GetBackBufferData<T>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct public void GetBackBufferData<T>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -652,53 +609,22 @@ namespace ANX.RenderSystem.Windows.DX10
swapChain.ResizeBuffers(swapChain.Description.BufferCount, presentationParameters.BackBufferWidth, swapChain.ResizeBuffers(swapChain.Description.BufferCount, presentationParameters.BackBufferWidth,
presentationParameters.BackBufferHeight, Format.R8G8B8A8_UNorm, swapChain.Description.Flags); presentationParameters.BackBufferHeight, Format.R8G8B8A8_UNorm, swapChain.Description.Flags);
backBuffer = SharpDX.Direct3D10.Texture2D.FromSwapChain<SharpDX.Direct3D10.Texture2D>(swapChain, 0); backBuffer = Dx10.Texture2D.FromSwapChain<Dx10.Texture2D>(swapChain, 0);
renderView = new RenderTargetView(device, backBuffer); 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); presentationParameters.BackBufferHeight);
// create the depth stencil buffer // create the depth stencil buffer
Format depthFormat = FormatConverter.Translate(presentationParameters.DepthStencilFormat); Format depthFormat = FormatConverter.Translate(presentationParameters.DepthStencilFormat);
if (depthFormat != Format.Unknown) if (depthFormat != Format.Unknown)
{
CreateDepthStencilBuffer(depthFormat); CreateDepthStencilBuffer(depthFormat);
} }
}
ResizeRenderWindow(presentationParameters); WindowHelper.ResizeRenderWindow(presentationParameters);
} }
#endregion #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 #region Dispose
public void 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Direct3D10;
using SharpDX.D3DCompiler;
using System.IO; using System.IO;
using ANX.Framework.NonXNA; using SharpDX.D3DCompiler;
using ANX.Framework.Graphics;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
namespace ANX.RenderSystem.Windows.DX10 namespace ANX.RenderSystem.Windows.DX10.Helpers
{ {
internal class IncludeHandler : Include internal class IncludeHandler : Include
{ {
private string directory; private string directory;
public IDisposable Shadow { get; set; }
public IncludeHandler(string directory) public IncludeHandler(string directory)
{ {
this.directory = 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); //Console.WriteLine("Including {0} file {1} from directory {2}", type.ToString(), fileName, directory);
return System.IO.File.OpenRead(System.IO.Path.Combine(directory, fileName)); return File.OpenRead(Path.Combine(directory, fileName));
}
public IDisposable Shadow
{
get;
set;
} }
public void Dispose() 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,88 +1,33 @@
#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.Graphics;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using ANX.RenderSystem.Windows.DX10.Helpers;
#endregion // Using Statements using Dx10 = SharpDX.Direct3D10;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/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 namespace ANX.RenderSystem.Windows.DX10
{ {
public class RasterizerState_DX10 : INativeRasterizerState 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;
#endregion // Private Members #region Private
private Dx10.RasterizerStateDescription description;
private Dx10.RasterizerState nativeRasterizerState;
private bool isDirty;
#endregion
public RasterizerState_DX10() #region Public
{ public bool IsBound { get; private set; }
this.description = new RasterizerStateDescription();
this.description.IsAntialiasedLineEnabled = false;
this.nativeRasterizerStateDirty = true;
}
public void Apply(ANX.Framework.Graphics.GraphicsDevice graphicsDevice)
{
GraphicsDeviceWindowsDX10 gdx10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
Device device = gdx10.NativeDevice;
UpdateNativeRasterizerState(device);
this.bound = true;
device.Rasterizer.State = this.nativeRasterizerState;
}
public void Release()
{
this.bound = false;
}
public void Dispose()
{
if (this.nativeRasterizerState != null)
{
this.nativeRasterizerState.Dispose();
this.nativeRasterizerState = null;
}
}
public bool IsBound
{
get
{
return this.bound;
}
}
public CullMode CullMode public CullMode CullMode
{ {
set set
{ {
SharpDX.Direct3D10.CullMode cullMode = FormatConverter.Translate(value); Dx10.CullMode cullMode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.CullMode, ref cullMode);
if (description.CullMode != cullMode)
{
nativeRasterizerStateDirty = true;
description.CullMode = cullMode;
}
} }
} }
@ -94,12 +39,7 @@ namespace ANX.RenderSystem.Windows.DX10
// DirectX 10 uses a INT value // DirectX 10 uses a INT value
int depthBiasValue = (int)(value * intMaxOver16); int depthBiasValue = (int)(value * intMaxOver16);
UpdateValueAndMarkDirtyIfNeeded(ref description.DepthBias, ref depthBiasValue);
if (description.DepthBias != depthBiasValue)
{
nativeRasterizerStateDirty = true;
description.DepthBias = depthBiasValue;
}
} }
} }
@ -107,13 +47,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.FillMode fillMode = FormatConverter.Translate(value); Dx10.FillMode fillMode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.FillMode, ref fillMode);
if (description.FillMode != fillMode)
{
nativeRasterizerStateDirty = true;
description.FillMode = fillMode;
}
} }
} }
@ -123,7 +58,7 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
if (description.IsMultisampleEnabled != value) if (description.IsMultisampleEnabled != value)
{ {
nativeRasterizerStateDirty = true; isDirty = true;
description.IsMultisampleEnabled = value; description.IsMultisampleEnabled = value;
} }
} }
@ -135,7 +70,7 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
if (description.IsScissorEnabled != value) if (description.IsScissorEnabled != value)
{ {
nativeRasterizerStateDirty = true; isDirty = true;
description.IsScissorEnabled = value; description.IsScissorEnabled = value;
} }
} }
@ -145,28 +80,70 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
if (description.SlopeScaledDepthBias != value) UpdateValueAndMarkDirtyIfNeeded(ref description.SlopeScaledDepthBias, ref value);
}
}
#endregion
#region Constructor
public RasterizerState_DX10()
{ {
nativeRasterizerStateDirty = true; description.IsAntialiasedLineEnabled = false;
description.SlopeScaledDepthBias = value; isDirty = true;
}
#endregion
#region Apply
public void Apply(GraphicsDevice graphicsDevice)
{
UpdateNativeRasterizerState(graphicsDevice);
IsBound = true;
}
#endregion
#region Release
public void Release()
{
IsBound = false;
}
#endregion
#region Dispose
public void Dispose()
{
if (nativeRasterizerState != null)
{
nativeRasterizerState.Dispose();
nativeRasterizerState = null;
} }
} }
#endregion
#region UpdateNativeRasterizerState
private void UpdateNativeRasterizerState(GraphicsDevice graphicsDevice)
{
Dx10.Device device = (graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
if (isDirty == true || nativeRasterizerState == null)
{
Dispose();
nativeRasterizerState = new Dx10.RasterizerState(device, ref description);
isDirty = false;
} }
private void UpdateNativeRasterizerState(Device device) device.Rasterizer.State = nativeRasterizerState;
{
if (this.nativeRasterizerStateDirty == true || this.nativeRasterizerState == null)
{
if (this.nativeRasterizerState != null)
{
this.nativeRasterizerState.Dispose();
this.nativeRasterizerState = null;
} }
#endregion
this.nativeRasterizerState = new SharpDX.Direct3D10.RasterizerState(device, ref this.description); #region UpdateValueAndMarkDirtyIfNeeded
private void UpdateValueAndMarkDirtyIfNeeded<T>(ref T currentValue, ref T value)
this.nativeRasterizerStateDirty = false; {
if (value.Equals(currentValue) == false)
{
isDirty = true;
currentValue = value;
} }
} }
#endregion
} }
} }

View File

@ -1,13 +1,8 @@
#region Using Statements
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.Graphics; using ANX.Framework.Graphics;
using ANX.Framework.NonXNA.RenderSystem; using ANX.Framework.NonXNA.RenderSystem;
using SharpDX.Direct3D10; using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -17,24 +12,20 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
public class RenderTarget2D_DX10 : Texture2D_DX10, INativeRenderTarget2D, INativeTexture2D public class RenderTarget2D_DX10 : Texture2D_DX10, INativeRenderTarget2D, INativeTexture2D
{ {
#region Private Members #region Constructor
public RenderTarget2D_DX10(GraphicsDevice graphics, int width, int height, bool mipMap, SurfaceFormat preferredFormat,
#endregion // Private Members DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
public RenderTarget2D_DX10(GraphicsDevice graphics, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
: base(graphics) : base(graphics)
{ {
if (mipMap) if (mipMap)
{
throw new NotImplementedException("creating RenderTargets with mip map not yet implemented"); throw new NotImplementedException("creating RenderTargets with mip map not yet implemented");
}
this.surfaceFormat = surfaceFormat; this.surfaceFormat = surfaceFormat;
GraphicsDeviceWindowsDX10 graphicsDX10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10; 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, Width = width,
Height = height, Height = height,
@ -42,19 +33,19 @@ namespace ANX.RenderSystem.Windows.DX10
ArraySize = 1, ArraySize = 1,
Format = FormatConverter.Translate(preferredFormat), Format = FormatConverter.Translate(preferredFormat),
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
Usage = SharpDX.Direct3D10.ResourceUsage.Default, Usage = Dx10.ResourceUsage.Default,
BindFlags = SharpDX.Direct3D10.BindFlags.ShaderResource | SharpDX.Direct3D10.BindFlags.RenderTarget, BindFlags = Dx10.BindFlags.ShaderResource | Dx10.BindFlags.RenderTarget,
CpuAccessFlags = SharpDX.Direct3D10.CpuAccessFlags.None, CpuAccessFlags = Dx10.CpuAccessFlags.None,
OptionFlags = SharpDX.Direct3D10.ResourceOptionFlags.None, OptionFlags = Dx10.ResourceOptionFlags.None,
}; };
this.nativeTexture = new SharpDX.Direct3D10.Texture2D(graphicsDX10.NativeDevice, description); nativeTexture = new Dx10.Texture2D(graphicsDX10.NativeDevice, description);
this.nativeShaderResourceView = new SharpDX.Direct3D10.ShaderResourceView(graphicsDX10.NativeDevice, this.nativeTexture); 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 // 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 // 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.Graphics;
using ANX.Framework.NonXNA; using ANX.Framework.NonXNA;
using SharpDX.Direct3D10; using ANX.RenderSystem.Windows.DX10.Helpers;
using Dx10 = SharpDX.Direct3D10;
#endregion // Using Statements
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -14,56 +11,21 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
public class SamplerState_DX10 : INativeSamplerState public class SamplerState_DX10 : INativeSamplerState
{ {
#region Private Members #region Private
private SamplerStateDescription description; private Dx10.SamplerStateDescription description;
private SharpDX.Direct3D10.SamplerState nativeSamplerState; private Dx10.SamplerState nativeSamplerState;
private bool nativeSamplerStateDirty; private bool isDirty;
private bool bound; #endregion
#endregion // Private Members #region Public
public bool IsBound { get; private set; }
public SamplerState_DX10()
{
this.description = new SamplerStateDescription();
this.nativeSamplerStateDirty = true;
}
public void Apply(GraphicsDevice graphicsDevice, int index)
{
GraphicsDeviceWindowsDX10 gdx10 = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10;
Device device = gdx10.NativeDevice;
UpdateNativeSamplerState(device);
this.bound = true;
device.PixelShader.SetSampler(index, this.nativeSamplerState);
}
public void Release()
{
this.bound = false;
}
public bool IsBound
{
get
{
return this.bound;
}
}
public ANX.Framework.Graphics.TextureAddressMode AddressU public ANX.Framework.Graphics.TextureAddressMode AddressU
{ {
set set
{ {
SharpDX.Direct3D10.TextureAddressMode mode = FormatConverter.Translate(value); Dx10.TextureAddressMode mode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.AddressU, ref mode);
if (description.AddressU != mode)
{
description.AddressU = mode;
nativeSamplerStateDirty = true;
}
} }
} }
@ -71,13 +33,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.TextureAddressMode mode = FormatConverter.Translate(value); Dx10.TextureAddressMode mode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.AddressV, ref mode);
if (description.AddressV != mode)
{
description.AddressV = mode;
nativeSamplerStateDirty = true;
}
} }
} }
@ -85,13 +42,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.TextureAddressMode mode = FormatConverter.Translate(value); Dx10.TextureAddressMode mode = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.AddressW, ref mode);
if (description.AddressW != mode)
{
description.AddressW = mode;
nativeSamplerStateDirty = true;
}
} }
} }
@ -99,13 +51,8 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
SharpDX.Direct3D10.Filter filter = FormatConverter.Translate(value); Dx10.Filter filter = FormatConverter.Translate(value);
UpdateValueAndMarkDirtyIfNeeded(ref description.Filter, ref filter);
if (description.Filter != filter)
{
description.Filter = filter;
nativeSamplerStateDirty = true;
}
} }
} }
@ -113,11 +60,7 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
if (description.MaximumAnisotropy != value) UpdateValueAndMarkDirtyIfNeeded(ref description.MaximumAnisotropy, ref value);
{
description.MaximumAnisotropy = value;
nativeSamplerStateDirty = true;
}
} }
} }
@ -128,7 +71,7 @@ namespace ANX.RenderSystem.Windows.DX10
if (description.MaximumLod != value) if (description.MaximumLod != value)
{ {
description.MaximumLod = value; description.MaximumLod = value;
nativeSamplerStateDirty = true; isDirty = true;
} }
} }
} }
@ -137,37 +80,68 @@ namespace ANX.RenderSystem.Windows.DX10
{ {
set set
{ {
if (description.MipLodBias != value) UpdateValueAndMarkDirtyIfNeeded(ref description.MipLodBias, ref value);
{
description.MipLodBias = value;
nativeSamplerStateDirty = true;
}
} }
} }
#endregion
#region Constructor
public SamplerState_DX10()
{
isDirty = true;
}
#endregion
#region Apply
public void Apply(GraphicsDevice graphicsDevice, int index)
{
Dx10.Device device = (graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
UpdateNativeSamplerState(device);
IsBound = true;
device.PixelShader.SetSampler(index, nativeSamplerState);
}
#endregion
#region Release
public void Release()
{
IsBound = false;
}
#endregion
#region Dispose
public void Dispose() public void Dispose()
{ {
if (this.nativeSamplerState != null) if (nativeSamplerState != null)
{ {
this.nativeSamplerState.Dispose(); nativeSamplerState.Dispose();
this.nativeSamplerState = null; nativeSamplerState = null;
} }
} }
#endregion
private void UpdateNativeSamplerState(Device device) #region UpdateNativeSamplerState
private void UpdateNativeSamplerState(Dx10.Device device)
{ {
if (this.nativeSamplerStateDirty == true || this.nativeSamplerState == null) if (isDirty == true || nativeSamplerState == null)
{ {
if (this.nativeSamplerState != null) Dispose();
{ nativeSamplerState = new Dx10.SamplerState(device, ref description);
this.nativeSamplerState.Dispose(); isDirty = false;
this.nativeSamplerState = null;
} }
}
#endregion
this.nativeSamplerState = new SharpDX.Direct3D10.SamplerState(device, ref this.description); #region UpdateValueAndMarkDirtyIfNeeded
private void UpdateValueAndMarkDirtyIfNeeded<T>(ref T currentValue, ref T value)
this.nativeSamplerStateDirty = false; {
if (value.Equals(currentValue) == false)
{
isDirty = true;
currentValue = value;
} }
} }
#endregion
} }
} }

View File

@ -1,16 +1,11 @@
#region Using Statements
using System; 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.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ANX.Framework; using ANX.Framework;
using ANX.Framework.Graphics;
#endregion // Using Statements 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 // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "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 public class Texture2D_DX10 : INativeTexture2D
{ {
#region Private Members #region Private
protected internal SharpDX.Direct3D10.Texture2D nativeTexture; protected internal Dx10.Texture2D nativeTexture;
protected internal SharpDX.Direct3D10.ShaderResourceView nativeShaderResourceView; protected internal Dx10.ShaderResourceView nativeShaderResourceView;
protected internal int formatSize; protected internal int formatSize;
protected internal SurfaceFormat surfaceFormat; protected internal SurfaceFormat surfaceFormat;
protected internal GraphicsDevice graphicsDevice; protected internal GraphicsDevice graphicsDevice;
#endregion
#endregion // Private Members #region Public
internal Dx10.Texture2D NativeTexture
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
{ {
get get
{ {
@ -85,16 +35,14 @@ namespace ANX.RenderSystem.Windows.DX10
if (this.nativeTexture != value) if (this.nativeTexture != value)
{ {
if (this.nativeTexture != null) if (this.nativeTexture != null)
{
this.nativeTexture.Dispose(); this.nativeTexture.Dispose();
}
this.nativeTexture = value; this.nativeTexture = value;
} }
} }
} }
internal SharpDX.Direct3D10.ShaderResourceView NativeShaderResourceView internal Dx10.ShaderResourceView NativeShaderResourceView
{ {
get 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 public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct
{ {
SetData<T>(graphicsDevice, 0, data, 0, data.Length); SetData<T>(graphicsDevice, 0, data, 0, data.Length);
@ -124,7 +145,8 @@ namespace ANX.RenderSystem.Windows.DX10
SetData<T>(graphicsDevice, 0, data, startIndex, elementCount); 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 offsetInBytes parameter
//TODO: handle startIndex parameter //TODO: handle startIndex parameter
@ -132,8 +154,8 @@ namespace ANX.RenderSystem.Windows.DX10
if (this.surfaceFormat == SurfaceFormat.Color) if (this.surfaceFormat == SurfaceFormat.Color)
{ {
int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubResourceIndex(0, 0, 1); int subresource = Dx10.Texture2D.CalculateSubResourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None); SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, Dx10.MapMode.WriteDiscard, Dx10.MapFlags.None);
int rowPitch = rectangle.Pitch; int rowPitch = rectangle.Pitch;
unsafe unsafe
@ -174,8 +196,8 @@ namespace ANX.RenderSystem.Windows.DX10
int h = (Height + 3) >> 2; int h = (Height + 3) >> 2;
formatSize = (surfaceFormat == SurfaceFormat.Dxt1) ? 8 : 16; formatSize = (surfaceFormat == SurfaceFormat.Dxt1) ? 8 : 16;
int subresource = SharpDX.Direct3D10.Texture2D.CalculateSubResourceIndex(0, 0, 1); int subresource = Dx10.Texture2D.CalculateSubResourceIndex(0, 0, 1);
SharpDX.DataRectangle rectangle = this.nativeTexture.Map(subresource, SharpDX.Direct3D10.MapMode.WriteDiscard, SharpDX.Direct3D10.MapFlags.None); 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); SharpDX.DataStream ds = new SharpDX.DataStream(rectangle.DataPointer, Width * Height * 4 * 2, true, true);
int pitch = rectangle.Pitch; int pitch = rectangle.Pitch;
int col = 0; 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 throw new NotImplementedException();
{
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;
}
} }
#endregion
#region Dispose
public void Dispose() public void Dispose()
{ {
if (this.nativeShaderResourceView != null) if (this.nativeShaderResourceView != null)
@ -270,6 +265,7 @@ namespace ANX.RenderSystem.Windows.DX10
this.nativeTexture = null; this.nativeTexture = null;
} }
} }
#endregion
#region SaveAsJpeg (TODO) #region SaveAsJpeg (TODO)
public void SaveAsJpeg(Stream stream, int width, int height) public void SaveAsJpeg(Stream stream, int width, int height)
@ -285,24 +281,7 @@ namespace ANX.RenderSystem.Windows.DX10
} }
#endregion #endregion
#region INativeTexture2D Member #region GetData (TODO)
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
public void GetData<T>(T[] data) where T : struct public void GetData<T>(T[] data) where T : struct
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -313,6 +292,10 @@ namespace ANX.RenderSystem.Windows.DX10
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void GetData<T>(int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
{
throw new NotImplementedException();
}
#endregion #endregion
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -158,31 +158,112 @@ namespace ANX.Framework.Windows.GL3
#region DualTextureEffectShader #region DualTextureEffectShader
internal static byte[] DualTextureEffectByteCode = new byte[] 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, 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, 084, 101, 120, 116, 117, 114, 101, 034, 123, 097, 116, 116, 114, 105, 098,
109, 032, 109, 097, 116, 052, 032, 087, 111, 114, 108, 100, 086, 105, 101, 117, 116, 101, 032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 097, 116,
119, 080, 114, 111, 106, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 101,
032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 097, 116, 116, 114, 105, 120, 059, 097, 116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099,
098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 101, 120, 059, 097, 050, 032, 116, 101, 120, 050, 059, 118, 097, 114, 121, 105, 110, 103, 032,
116, 116, 114, 105, 098, 117, 116, 101, 032, 118, 101, 099, 050, 032, 116, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101, 059, 118, 097,
101, 120, 050, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 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, 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, 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, 100, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032,
123, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, 087, 111, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100,
114, 108, 100, 086, 105, 101, 119, 080, 114, 111, 106, 042, 112, 111, 115, 050, 059, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 032, 041, 123,
059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 103, 108, 095, 080, 111, 115, 105, 116, 105, 111, 110, 061, 087, 111, 114,
100, 061, 116, 101, 120, 059, 100, 105, 102, 102, 117, 115, 101, 084, 101, 108, 100, 086, 105, 101, 119, 080, 114, 111, 106, 042, 112, 111, 115, 059,
120, 067, 111, 111, 114, 100, 050, 061, 116, 101, 120, 050, 059, 125, 125, 100, 105, 102, 102, 117, 115, 101, 061, 068, 105, 102, 102, 117, 115, 101,
125, 102, 114, 097, 103, 109, 101, 110, 116, 115, 104, 097, 100, 101, 114, 067, 111, 108, 111, 114, 042, 099, 111, 108, 059, 100, 105, 102, 102, 117,
115, 123, 115, 104, 097, 100, 101, 114, 032, 034, 080, 083, 068, 117, 097, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 061, 116, 101, 120, 059,
108, 084, 101, 120, 116, 117, 114, 101, 034, 123, 117, 110, 105, 102, 111, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 032, 042, 061, 032, 050, 059, 099, 111, 108, 111, 114, 032, 042, 061, 032,
108, 111, 114, 061, 099, 111, 108, 111, 114, 059, 125, 125, 125, 116, 101, 111, 118, 101, 114, 108, 097, 121, 042, 100, 105, 102, 102, 117, 115, 101,
099, 104, 110, 105, 113, 117, 101, 115, 123, 116, 101, 099, 104, 110, 105, 059, 099, 111, 108, 111, 114, 046, 114, 103, 098, 061, 108, 101, 114, 112,
113, 117, 101, 032, 034, 068, 117, 097, 108, 084, 101, 120, 116, 117, 114, 040, 099, 111, 108, 111, 114, 046, 114, 103, 098, 044, 070, 111, 103, 067,
101, 069, 102, 102, 101, 099, 116, 034, 123, 118, 101, 114, 116, 101, 120, 111, 108, 111, 114, 042, 099, 111, 108, 111, 114, 046, 097, 044, 115, 112,
032, 034, 083, 112, 114, 105, 116, 101, 086, 101, 114, 116, 101, 120, 083, 101, 099, 117, 108, 097, 114, 046, 119, 041, 059, 103, 108, 095, 070, 114,
104, 097, 100, 101, 114, 034, 102, 114, 097, 103, 109, 101, 110, 116, 032, 097, 103, 067, 111, 108, 111, 114, 061, 099, 111, 108, 111, 114, 059, 125,
034, 083, 112, 114, 105, 116, 101, 070, 114, 097, 103, 109, 101, 110, 116, 125, 115, 104, 097, 100, 101, 114, 032, 034, 080, 083, 068, 117, 097, 108,
083, 104, 097, 100, 101, 114, 034, 125, 125, 187, 064, 170, 146, 113, 222, 084, 101, 120, 116, 117, 114, 101, 078, 111, 070, 111, 103, 034, 123, 118,
195, 185, 241, 224, 197, 214, 045, 090, 110, 247, 026, 116, 240, 217, 022, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102,
092, 081, 220, 169, 002, 136, 173, 102, 023, 033, 241, 036, 012, 008, 239, 102, 117, 115, 101, 059, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101,
183, 058, 168, 109, 213, 077, 167, 248, 035, 223, 044, 042, 036, 164, 161, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111,
159, 223, 225, 129, 012, 168, 228, 127, 147, 224, 089, 079, 235 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 #endregion //DualTextureEffectShader

View File

@ -262,24 +262,19 @@ namespace ANX.RenderSystem.Windows.GL3
private void MapVertexDeclaration(EffectGL3 effect) private void MapVertexDeclaration(EffectGL3 effect)
{ {
EffectTechniqueGL3 currentTechnique = effect.CurrentTechnique; EffectTechniqueGL3 currentTechnique = effect.CurrentTechnique;
ShaderAttributeGL3[] attributes = currentTechnique.activeAttributes; ShaderAttributeGL3[] attributes = currentTechnique.activeAttributes;
VertexElement[] elements = vertexDeclaration.GetVertexElements(); VertexElement[] elements = vertexDeclaration.GetVertexElements();
if (elements.Length != attributes.Length) if (elements.Length != attributes.Length)
{ throw new InvalidOperationException("Mapping the VertexDeclaration onto the glsl attributes failed because " +
throw new InvalidOperationException("Mapping the VertexDeclaration " + "we have " + attributes.Length + " Shader Attributes and " + elements.Length + " elements in the vertex " +
"onto the glsl attributes failed because we have " + "declaration which doesn't fit!");
attributes.Length + " Shader Attributes and " +
elements.Length + " elements in the vertex declaration which " +
"doesn't fit!");
}
for (int index = 0; index < attributes.Length; index++) for (int index = 0; index < attributes.Length; index++)
{ {
int location = attributes[index].Location; int location = attributes[index].Location;
attributes[index].Bind(elements[location].VertexElementUsage, attributes[index].Bind(elements[location].VertexElementUsage, vertexDeclaration.VertexStride,
vertexDeclaration.VertexStride, elements[location].Offset); elements[location].Offset);
} }
} }
#endregion #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. // "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license // For details see: http://anxframework.codeplex.com/license
//TODO: dummy implementation / placeholder vertexglobal
{
uniform vec4 DiffuseColor;
uniform vec4 FogVector;
uniform mat4 WorldViewProj;
}
vertexshaders vertexshaders
{ {
shader "VSDualTexture" shader "VSDualTexture"
{ {
uniform mat4 WorldViewProj;
attribute vec4 pos; attribute vec4 pos;
attribute vec2 tex; attribute vec2 tex;
attribute vec2 tex2; attribute vec2 tex2;
varying vec4 diffuse;
varying vec4 specular;
varying vec2 diffuseTexCoord; varying vec2 diffuseTexCoord;
varying vec2 diffuseTexCoord2; varying vec2 diffuseTexCoord2;
void main( ) void main( )
{ {
gl_Position = WorldViewProj * pos; 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; diffuseTexCoord = tex;
diffuseTexCoord2 = tex2; diffuseTexCoord2 = tex2;
} }
} }
} }
fragmentglobal
{
uniform sampler2D Texture;
uniform sampler2D Texture2;
uniform vec3 FogColor;
}
fragmentshaders fragmentshaders
{ {
shader "PSDualTexture" shader "PSDualTexture"
{ {
uniform sampler2D Texture; varying vec4 diffuse;
uniform sampler2D Texture2; varying vec4 specular;
varying vec2 diffuseTexCoord; varying vec2 diffuseTexCoord;
varying vec2 diffuseTexCoord2; varying vec2 diffuseTexCoord2;
void main( ) void main( )
{ {
vec4 color = texture2D(Texture, diffuseTexCoord); vec4 color = texture2D(Texture, diffuseTexCoord);
vec4 overlay = texture2D(Texture2, diffuseTexCoord2); vec4 overlay = texture2D(Texture2, diffuseTexCoord2);
color.rgb *= 2; color.rgb *= 2;
color *= overlay * diffuse;
color.rgb = lerp(color.rgb, FogColor * color.a, specular.w);
gl_FragColor = color;
}
}
// TODO shader "PSDualTextureNoFog"
//color *= overlay * pin.Diffuse; {
//ApplyFog(color, pin.Specular.w); 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; gl_FragColor = color;
} }
} }
@ -54,7 +136,25 @@ techniques
{ {
technique "DualTextureEffect" technique "DualTextureEffect"
{ {
vertex "SpriteVertexShader" vertex "VSDualTexture"
fragment "SpriteFragmentShader" fragment "PSDualTexture"
}
technique "DualTextureEffectNoFog"
{
vertex "VSDualTextureNoFog"
fragment "PSDualTextureNoFog"
}
technique "DualTextureEffectVertexColor"
{
vertex "VSDualTextureVertexColor"
fragment "PSDualTexture"
}
technique "DualTextureEffectNoFogVertexColor"
{
vertex "VSDualTextureVertexColorNoFog"
fragment "PSDualTextureNoFog"
} }
} }