Root/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #region File Description //----------------------------------------------------------------------------- // SpriteEffect.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #endregion namespace Microsoft.Xna.Framework.Graphics { /// <summary> /// The default effect used by SpriteBatch. /// </summary> internal class SpriteEffect : Effect { #region Effect Parameters EffectParameter matrixParam; #endregion #region Methods /// <summary> /// Creates a new SpriteEffect. /// </summary> public SpriteEffect(GraphicsDevice device) : base (device, Resources.SpriteEffect) { CacheEffectParameters(); } /// <summary> /// Creates a new SpriteEffect by cloning parameter settings from an existing instance. /// </summary> protected SpriteEffect(SpriteEffect cloneSource) : base (cloneSource) { CacheEffectParameters(); } /// <summary> /// Creates a clone of the current SpriteEffect instance. /// </summary> public override Effect Clone() { return new SpriteEffect( this ); } /// <summary> /// Looks up shortcut references to our effect parameters. /// </summary> void CacheEffectParameters() { matrixParam = Parameters[ "MatrixTransform" ]; } /// <summary> /// Lazily computes derived parameter values immediately before applying the effect. /// </summary> protected internal override void OnApply() { Viewport viewport = GraphicsDevice.Viewport; Matrix projection = Matrix.CreateOrthographicOffCenter(0, viewport.Width, viewport.Height, 0, 0, 1); Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0); matrixParam.SetValue(halfPixelOffset * projection); } #endregion } } |