2011-11-16 14:27:53 +00:00
|
|
|
using ANX.Framework.Graphics;
|
|
|
|
using ANX.Framework.NonXNA;
|
2012-09-06 09:58:13 +00:00
|
|
|
using ANX.RenderSystem.Windows.DX10.Helpers;
|
|
|
|
using Dx10 = SharpDX.Direct3D10;
|
2011-11-16 14:27:53 +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-11-16 14:27:53 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
namespace ANX.RenderSystem.Windows.DX10
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
|
|
|
public class SamplerState_DX10 : INativeSamplerState
|
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
#region Private
|
|
|
|
private Dx10.SamplerStateDescription description;
|
|
|
|
private Dx10.SamplerState nativeSamplerState;
|
|
|
|
private bool isDirty;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Public
|
|
|
|
public bool IsBound { get; private set; }
|
|
|
|
|
|
|
|
public ANX.Framework.Graphics.TextureAddressMode AddressU
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Dx10.TextureAddressMode mode = FormatConverter.Translate(value);
|
|
|
|
UpdateValueAndMarkDirtyIfNeeded(ref description.AddressU, ref mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ANX.Framework.Graphics.TextureAddressMode AddressV
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Dx10.TextureAddressMode mode = FormatConverter.Translate(value);
|
|
|
|
UpdateValueAndMarkDirtyIfNeeded(ref description.AddressV, ref mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ANX.Framework.Graphics.TextureAddressMode AddressW
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Dx10.TextureAddressMode mode = FormatConverter.Translate(value);
|
|
|
|
UpdateValueAndMarkDirtyIfNeeded(ref description.AddressW, ref mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public TextureFilter Filter
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Dx10.Filter filter = FormatConverter.Translate(value);
|
|
|
|
UpdateValueAndMarkDirtyIfNeeded(ref description.Filter, ref filter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int MaxAnisotropy
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
UpdateValueAndMarkDirtyIfNeeded(ref description.MaximumAnisotropy, ref value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int MaxMipLevel
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (description.MaximumLod != value)
|
|
|
|
{
|
|
|
|
description.MaximumLod = value;
|
|
|
|
isDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public float MipMapLevelOfDetailBias
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
UpdateValueAndMarkDirtyIfNeeded(ref description.MipLodBias, ref value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
public SamplerState_DX10()
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
isDirty = true;
|
|
|
|
}
|
|
|
|
#endregion
|
2011-11-16 14:27:53 +00:00
|
|
|
|
2012-09-06 09:58:13 +00:00
|
|
|
#region Apply
|
|
|
|
public void Apply(GraphicsDevice graphicsDevice, int index)
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
Dx10.Device device = (graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
|
2011-11-16 14:27:53 +00:00
|
|
|
UpdateNativeSamplerState(device);
|
2012-09-06 09:58:13 +00:00
|
|
|
IsBound = true;
|
2011-11-16 14:27:53 +00:00
|
|
|
|
2012-09-06 09:58:13 +00:00
|
|
|
device.PixelShader.SetSampler(index, nativeSamplerState);
|
|
|
|
}
|
|
|
|
#endregion
|
2011-11-16 14:27:53 +00:00
|
|
|
|
2012-09-06 09:58:13 +00:00
|
|
|
#region Release
|
|
|
|
public void Release()
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
IsBound = false;
|
|
|
|
}
|
|
|
|
#endregion
|
2011-11-16 14:27:53 +00:00
|
|
|
|
2012-09-06 09:58:13 +00:00
|
|
|
#region Dispose
|
|
|
|
public void Dispose()
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
if (nativeSamplerState != null)
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
nativeSamplerState.Dispose();
|
|
|
|
nativeSamplerState = null;
|
2011-11-16 14:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-06 09:58:13 +00:00
|
|
|
#endregion
|
2011-11-16 14:27:53 +00:00
|
|
|
|
2012-09-06 09:58:13 +00:00
|
|
|
#region UpdateNativeSamplerState
|
|
|
|
private void UpdateNativeSamplerState(Dx10.Device device)
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
if (isDirty == true || nativeSamplerState == null)
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
Dispose();
|
|
|
|
nativeSamplerState = new Dx10.SamplerState(device, ref description);
|
|
|
|
isDirty = false;
|
2011-11-16 14:27:53 +00:00
|
|
|
}
|
2012-09-06 09:58:13 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region UpdateValueAndMarkDirtyIfNeeded
|
|
|
|
private void UpdateValueAndMarkDirtyIfNeeded<T>(ref T currentValue, ref T value)
|
|
|
|
{
|
|
|
|
if (value.Equals(currentValue) == false)
|
|
|
|
{
|
|
|
|
isDirty = true;
|
|
|
|
currentValue = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
2011-11-16 14:27:53 +00:00
|
|
|
}
|