using Chernobyl.Collections.Generic.Event; using Chernobyl.Event; using Chernobyl.Graphics.Material.Shader.Parameters; using Chernobyl.Graphics.Texture; using Chernobyl.Graphics.Xna.Effects; using Microsoft.Xna.Framework.Graphics; namespace Chernobyl.Graphics.Xna.Controllers.Shaders { /// /// Handles XNA texture parameters. /// public class XnaTextureParameter : XnaShaderParameter { /// /// Constructor. /// /// The services class that holds the services that will be injected /// into this class. /// The initial value of the texture parameter. /// The name of the texture parameter. public XnaTextureParameter(IEventCollection services, ITexture value, string name) { _value = value; Name = name; ProcessNewValue(); } /// /// Constructor. /// /// The services class that holds the services that will be injected /// into this class. /// The that this parameter /// belongs to. /// The XNA that /// this parameter represents. /// The initial value of the texture parameter. /// The name of the texture parameter. public XnaTextureParameter(IEventCollection services, XnaEffect effect, EffectParameter effectParam, ITexture value, string name) { XnaEffect = effect; EffectParameter = effectParam; _value = value; Name = name; ProcessNewValue(); } /// /// Initializes a new instance of the /// class. This constructor is typically used for cloning (see /// ). /// XnaTextureParameter() { } /// /// Applies the texture parameter to the EffectParameter of the effect /// applied above this texture parameter. /// public override void PreDraw() { EffectParameter.SetValue(XnaTextureValue.XnaTexture); } /// /// The value of the texture. /// public override ITexture Value { get { return _value; } set { if(ValueChangedMethod != null) { ValueChangedEventArgs vce = new ValueChangedEventArgs(_value, value); _value = value; ValueChangedMethod(this, vce); } else _value = value; ProcessNewValue(); } } /// /// Creates a new instance that is a shallow copy of this instance. /// /// The new shallow copied instance. public override IShaderParameter ShallowClone() { XnaTextureParameter clone = new XnaTextureParameter(); ShallowCopyTo(clone); return clone; } /// /// Caches the XNA texture from the Chernobyl texture. This method was /// created because you should not call virtual properties/methods /// ( in this case) from the constructor. /// void ProcessNewValue() { if(_value != null) { Chernobyl.Graphics.Texture.Texture2D text = (Chernobyl.Graphics.Texture.Texture2D)_value; XnaTextureValue = (XnaTexture2D)text.Controller; } } /// /// The XNA texture that was pulled from the texture . /// XnaTexture2D XnaTextureValue { get; set; } /// /// The backing field to . /// ITexture _value; } }