2011-10-31 05:36:24 +00:00
|
|
|
using System;
|
2012-01-16 15:03:28 +00:00
|
|
|
using System.Runtime.InteropServices;
|
2012-08-09 09:45:04 +00:00
|
|
|
using ANX.Framework.NonXNA;
|
2012-09-04 08:31:17 +00:00
|
|
|
using ANX.Framework.NonXNA.Development;
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
namespace ANX.Framework.Graphics
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
[PercentageComplete(100)]
|
2012-08-09 09:45:04 +00:00
|
|
|
public class RasterizerState : GraphicsResource
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
#region Constants
|
|
|
|
public static readonly RasterizerState CullClockwise;
|
|
|
|
public static readonly RasterizerState CullCounterClockwise;
|
|
|
|
public static readonly RasterizerState CullNone;
|
|
|
|
#endregion
|
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
#region Private
|
|
|
|
private INativeRasterizerState nativeRasterizerState;
|
|
|
|
|
|
|
|
private CullMode cullMode;
|
|
|
|
private float depthBias;
|
|
|
|
private FillMode fillMode;
|
|
|
|
private bool multiSampleAntiAlias;
|
|
|
|
private bool scissorTestEnable;
|
|
|
|
private float slopeScaleDepthBias;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Public
|
|
|
|
internal INativeRasterizerState NativeRasterizerState
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.nativeRasterizerState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public CullMode CullMode
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.cullMode;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
ThrowIfBound();
|
2012-08-09 09:45:04 +00:00
|
|
|
this.cullMode = value;
|
|
|
|
this.nativeRasterizerState.CullMode = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public float DepthBias
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.depthBias;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
ThrowIfBound();
|
2012-08-09 09:45:04 +00:00
|
|
|
this.depthBias = value;
|
|
|
|
this.nativeRasterizerState.DepthBias = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public FillMode FillMode
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.fillMode;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
ThrowIfBound();
|
2012-08-09 09:45:04 +00:00
|
|
|
this.fillMode = value;
|
|
|
|
this.nativeRasterizerState.FillMode = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool MultiSampleAntiAlias
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.multiSampleAntiAlias;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
ThrowIfBound();
|
2012-08-09 09:45:04 +00:00
|
|
|
this.multiSampleAntiAlias = value;
|
|
|
|
this.nativeRasterizerState.MultiSampleAntiAlias = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool ScissorTestEnable
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.scissorTestEnable;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
ThrowIfBound();
|
2012-08-09 09:45:04 +00:00
|
|
|
this.scissorTestEnable = value;
|
|
|
|
this.nativeRasterizerState.ScissorTestEnable = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public float SlopeScaleDepthBias
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.slopeScaleDepthBias;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
ThrowIfBound();
|
2012-08-09 09:45:04 +00:00
|
|
|
this.slopeScaleDepthBias = value;
|
|
|
|
this.nativeRasterizerState.SlopeScaleDepthBias = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
public RasterizerState()
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
|
|
|
|
this.nativeRasterizerState = creator.CreateRasterizerState();
|
2012-08-09 09:45:04 +00:00
|
|
|
|
|
|
|
this.CullMode = CullMode.CullCounterClockwiseFace;
|
|
|
|
this.DepthBias = 0f;
|
|
|
|
this.FillMode = FillMode.Solid;
|
|
|
|
this.MultiSampleAntiAlias = true;
|
|
|
|
this.ScissorTestEnable = false;
|
|
|
|
this.SlopeScaleDepthBias = 0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
private RasterizerState(CullMode cullMode, string name)
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
var creator = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>();
|
|
|
|
this.nativeRasterizerState = creator.CreateRasterizerState();
|
2012-08-09 09:45:04 +00:00
|
|
|
|
|
|
|
this.CullMode = cullMode;
|
|
|
|
this.DepthBias = 0f;
|
|
|
|
this.FillMode = FillMode.Solid;
|
|
|
|
this.MultiSampleAntiAlias = true;
|
|
|
|
this.ScissorTestEnable = false;
|
|
|
|
this.SlopeScaleDepthBias = 0f;
|
|
|
|
Name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static RasterizerState()
|
|
|
|
{
|
2012-09-04 08:31:17 +00:00
|
|
|
CullClockwise = new RasterizerState(CullMode.CullClockwiseFace, "RasterizerState.CullClockwise");
|
|
|
|
CullCounterClockwise = new RasterizerState(CullMode.CullCounterClockwiseFace, "RasterizerState.CullCounterClockwise");
|
2012-08-09 09:45:04 +00:00
|
|
|
CullNone = new RasterizerState(CullMode.None, "RasterizerState.CullNone");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2012-09-04 08:31:17 +00:00
|
|
|
#region ThrowIfBound
|
|
|
|
private void ThrowIfBound()
|
2012-08-09 09:45:04 +00:00
|
|
|
{
|
|
|
|
if (this.nativeRasterizerState.IsBound)
|
2012-09-04 08:31:17 +00:00
|
|
|
throw new InvalidOperationException("You are not allowed to change RasterizerState properties " +
|
2012-08-09 09:45:04 +00:00
|
|
|
"while it is bound to the GraphicsDevice.");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Dispose
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
if (this.nativeRasterizerState != null)
|
|
|
|
{
|
|
|
|
this.nativeRasterizerState.Dispose();
|
|
|
|
this.nativeRasterizerState = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(
|
|
|
|
[MarshalAs(UnmanagedType.U1)] bool disposeManaged)
|
|
|
|
{
|
|
|
|
base.Dispose(disposeManaged);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|