using System;
using Chernobyl.Event;
using Chernobyl.Graphics.Drawing;
using Chernobyl.Graphics.Material.Shader.Parameters;
using Microsoft.Xna.Framework.Graphics;
namespace Chernobyl.Graphics.Xna.Effects
{
///
/// The base class for all XNA shader parameters.
///
/// The type of the value being set into the shader parameter.
public abstract class XnaShaderParameter : Drawable, IShaderParameter
{
///
/// Invoked right after the value of the shader parameter changes.
///
public event EventHandler> ValueChanged
{
add {ValueChangedMethod += value; }
remove { ValueChangedMethod -= value; }
}
///
/// The value of the shader parameter.
///
public abstract TValue Value { get; set; }
///
/// The name of the shader parameter within the shader.
///
public string Name { get; set; }
///
/// The that controls that implements the
/// shader parameter. Usually, this controller is an
/// that controls the shader parameter
/// from a graphics API like OpenGL or XNA. If this property is null,
/// then the effect has no controller. This class will always return null.
///
public IShaderParameter Controller
{
get { return null; }
}
///
/// Creates a new instance that is a shallow copy of this instance.
///
/// The new shallow copied instance.
public abstract IShaderParameter ShallowClone();
///
/// Creates a new instance that is a shallow copy of this instance.
///
/// The new shallow copied instance.
IShaderParameter IShallowCloneable.ShallowClone()
{
return ShallowClone();
}
///
/// Shallow copies the data from this instance into the instance provided.
///
/// The XNA parameter that is to take the copied
/// data.
public void ShallowCopyTo(XnaShaderParameter destination)
{
((Drawable)this).ShallowCopyTo(destination);
destination.XnaEffect = XnaEffect;
destination.EffectParameter = EffectParameter;
destination.Name = Name;
destination.Value = Value;
}
///
/// The method used to handle the event. This
/// method is needed because derived classes cannot read/write the
/// event.
///
protected EventHandler> ValueChangedMethod { get; set; }
///
/// The XNA effect that holds the shader parameter represented by this
/// shader parameter class.
///
protected XnaEffect XnaEffect { get; set; }
///
/// The XNA effect parameter.
///
protected EffectParameter EffectParameter { get; set; }
}
}