Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasicEffect" /> class from a specified <see cref="EffectPool"/>.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="pool">The pool.</param>
        public BasicEffect(GraphicsDevice device, EffectPool pool)
            : base(device, effectBytecode, pool)
        {
            DirectionalLight0.Enabled = true;

            SpecularColor = Vector3.One;
            SpecularPower = 16;
        }
Пример #2
0
        /// <summary>
        /// Creates a new EnvironmentMapEffect with default parameter settings from a specified <see cref="EffectPool"/>.
        /// </summary>
        public EnvironmentMapEffect(GraphicsDevice device, EffectPool pool)
            : base(device, effectBytecode, pool)
        {
            CacheEffectParameters(null);

            DirectionalLight0.Enabled = true;

            EnvironmentMapAmount   = 1;
            EnvironmentMapSpecular = Vector3.Zero;
            FresnelFactor          = 1;
        }
Пример #3
0
        /// <summary>
        /// Creates a new SkinnedEffect with default parameter settings from a specified <see cref="EffectPool"/>.
        /// </summary>
        public SkinnedEffect(GraphicsDevice device, EffectPool pool)
            : base(device, effectBytecode, pool)
        {
            DirectionalLight0.Enabled = true;

            SpecularColor = Vector3.One;
            SpecularPower = 16;

            var identityBones = new Matrix[MaxBones];

            for (int i = 0; i < MaxBones; i++)
            {
                identityBones[i] = Matrix.Identity;
            }

            SetBoneTransforms(identityBones);
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Effect" /> class with the specified bytecode effect. See remarks.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="effectData">The bytecode to add to the Effect Pool. This bytecode must contain only one effect.</param>
        /// <param name="effectPool">The effect pool used to register the bytecode. Default is <see cref="GraphicsDevice.DefaultEffectPool"/>.</param>
        /// <exception cref="ArgumentException">If the bytecode doesn't contain a single effect.</exception>
        /// <remarks>The effect bytecode must contain only a single effect and will be registered into the <see cref="GraphicsDevice.DefaultEffectPool"/>.</remarks>
        public Effect(GraphicsDevice device, EffectData effectData, EffectPool effectPool = null)
            : base(device)
        {
            ConstantBuffers = new EffectConstantBufferCollection();
            Parameters      = new EffectParameterCollection();
            Techniques      = new EffectTechniqueCollection();

            Pool = effectPool ?? device.DefaultEffectPool;

            // Sets the effect name
            Name = effectData.Description.Name;

            // Register the bytecode to the pool
            var effect = Pool.RegisterBytecode(effectData);

            // Initialize from effect
            InitializeFrom(effect);

            // If everything was fine, then we can register it into the pool
            Pool.AddEffect(this);
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Effect" /> class with the specified bytecode effect. See remarks.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="effectData">The bytecode to add to the Effect Pool. This bytecode must contain only one effect.</param>
 /// <param name="effectPool">The effect pool used to register the bytecode. Default is <see cref="GraphicsDevice.DefaultEffectPool"/>.</param>
 /// <exception cref="ArgumentException">If the bytecode doesn't contain a single effect.</exception>
 /// <remarks>The effect bytecode must contain only a single effect and will be registered into the <see cref="GraphicsDevice.DefaultEffectPool"/>.</remarks>
 public Effect(GraphicsDevice device, EffectData effectData, EffectPool effectPool = null)
     : base(device)
 {
     CreateInstanceFrom(device, effectData, effectPool);
 }
Пример #6
0
 private static Buffer DefaultConstantBufferAllocator(GraphicsDevice device, EffectPool pool, EffectConstantBuffer constantBuffer)
 {
     return Buffer.Constant.New(device, constantBuffer.Size);
 }
Пример #7
0
 /// <summary>
 /// Creates a new named effect pool from a specified list of <see cref="EffectData" />.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="name">The name of this effect pool.</param>
 /// <param name="datas">The datas.</param>
 /// <returns>An instance of <see cref="EffectPool" />.</returns>
 public static EffectPool New(GraphicsDevice device, string name, params EffectData[] datas)
 {
     var group = new EffectPool(device);
     group.RegisterBytecode(datas);
     return group;
 }
Пример #8
0
        /// <summary>
        /// Creates a new EnvironmentMapEffect with default parameter settings from a specified <see cref="EffectPool"/>.
        /// </summary>
        public EnvironmentMapEffect(GraphicsDevice device, EffectPool pool)
            : base(device, effectBytecode, pool)
        {
            CacheEffectParameters(null);

            DirectionalLight0.Enabled = true;

            EnvironmentMapAmount = 1;
            EnvironmentMapSpecular = Vector3.Zero;
            FresnelFactor = 1;
        }
Пример #9
0
        /// <summary>
        /// Creates a new SkinnedEffect with default parameter settings from a specified <see cref="EffectPool"/>.
        /// </summary>
        public SkinnedEffect(GraphicsDevice device, EffectPool pool)
            : base(device, pool, SkinnedEffectName)
        {
            CacheEffectParameters(null);

            DirectionalLight0.Enabled = true;

            SpecularColor = Vector3.One;
            SpecularPower = 16;
            
            Matrix[] identityBones = new Matrix[MaxBones];
            
            for (int i = 0; i < MaxBones; i++)
            {
                identityBones[i] = Matrix.Identity;
            }
            
            SetBoneTransforms(identityBones);
        }
Пример #10
0
        private void AddEffectPool(EffectPool effectPool)
        {
            foreach (var registeredEffect in effectPool.RegisteredEffects)
            {
                AddEffect(registeredEffect);
            }

            effectPool.EffectAdded += effectPool_EffectAdded;
            effectPool.EffectRemoved += effectPool_EffectRemoved;
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasicEffect" /> class from a specified <see cref="EffectPool"/>.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="pool">The pool.</param>
        public BasicEffect(GraphicsDevice device, EffectPool pool)
            : base(device, effectBytecode, pool)
        {
            DirectionalLight0.Enabled = true;

            SpecularColor = Vector3.One;
            SpecularPower = 16;
        }
Пример #12
0
 /// <summary>
 /// Creates a new DualTextureEffect with default parameter settings from a specified <see cref="EffectPool"/>.
 /// </summary>
 public DualTextureEffect(GraphicsDevice device, EffectPool pool)
     : base(device, effectBytecode, pool)
 {
 }
Пример #13
0
 /// <summary>
 /// Creates a new AlphaTestEffect with default parameter settings from a specified <see cref="EffectPool"/>.
 /// </summary>
 public AlphaTestEffect(GraphicsDevice device, EffectPool pool)
     : base(device, effectBytecode, pool)
 {
 }
Пример #14
0
 /// <summary>
 /// Creates a new DualTextureEffect with default parameter settings from a specified <see cref="EffectPool"/>.
 /// </summary>
 public DualTextureEffect(GraphicsDevice device, EffectPool pool)
     : base(device, effectBytecode, pool)
 {
 }
Пример #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Effect" /> class with the specified bytecode effect. See remarks.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="effectData">The bytecode to add to the Effect Pool. This bytecode must contain only one effect.</param>
        /// <param name="effectPool">The effect pool used to register the bytecode. Default is <see cref="GraphicsDevice.DefaultEffectPool"/>.</param>
        /// <exception cref="ArgumentException">If the bytecode doesn't contain a single effect.</exception>
        /// <remarks>The effect bytecode must contain only a single effect and will be registered into the <see cref="GraphicsDevice.DefaultEffectPool"/>.</remarks>
        public Effect(GraphicsDevice device, EffectData effectData, EffectPool effectPool = null) : base(device)
        {
            if (effectData.Effects.Count != 1)
                throw new ArgumentException(string.Format("Expecting only one effect in the effect bytecode instead of [{0}].", Utilities.Join(",", effectData.Effects)), "effectData");

            ConstantBuffers = new EffectConstantBufferCollection();
            Parameters = new EffectParameterCollection();
            Techniques = new EffectTechniqueCollection();

            Pool = effectPool ?? device.DefaultEffectPool;

            // Sets the effect name
            Name = effectData.Effects[0].Name;

            // Register the bytecode to the pool
            Pool.RegisterBytecode(effectData);

            // Initialize from effect
            InitializeFrom(Pool.Find(Name));
            // If everything was fine, then we can register it into the pool
            Pool.AddEffect(this);
        }
Пример #16
0
        /// <summary>
        /// Creates a new SkinnedEffect with default parameter settings from a specified <see cref="EffectPool"/>.
        /// </summary>
        public SkinnedEffect(GraphicsDevice device, EffectPool pool)
            : base(device, effectBytecode, pool)
        {
            DirectionalLight0.Enabled = true;

            SpecularColor = Vector3.One;
            SpecularPower = 16;
            
            var identityBones = new Matrix[MaxBones];
            
            for (int i = 0; i < MaxBones; i++)
            {
                identityBones[i] = Matrix.Identity;
            }
            
            SetBoneTransforms(identityBones);
        }
Пример #17
0
 private static Buffer DefaultConstantBufferAllocator(GraphicsDevice device, EffectPool pool, EffectConstantBuffer constantBuffer)
 {
     return(Buffer.Constant.New(device, constantBuffer.Size));
 }
Пример #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Effect" /> class with the specified effect loaded from an effect pool.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="pool">The effect pool.</param>
 /// <param name="effectName">Name of the effect.</param>
 public Effect(GraphicsDevice device, EffectPool pool, string effectName) : base(device, effectName)
 {
     ConstantBuffers = new EffectConstantBufferCollection();
     Parameters = new EffectParameterCollection();
     Techniques = new EffectTechniqueCollection();
     ResourceLinker = ToDispose(new EffectResourceLinker());
     Pool = pool;
     Initialize();
 }
Пример #19
0
        internal void CreateInstanceFrom(GraphicsDevice device, EffectData effectData, EffectPool effectPool)
        {
            GraphicsDevice = device;
            ConstantBuffers = new EffectConstantBufferCollection();
            Parameters = new EffectParameterCollection();
            Techniques = new EffectTechniqueCollection();

            Pool = effectPool ?? device.DefaultEffectPool;

            // Sets the effect name
            Name = effectData.Description.Name;

            // Register the bytecode to the pool
            var effect = Pool.RegisterBytecode(effectData);

            // Initialize from effect
            InitializeFrom(effect, null);

            // If everything was fine, then we can register it into the pool
            Pool.AddEffect(this);
        }
Пример #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Effect" /> class with the specified bytecode effect. See remarks.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="effectData">The bytecode to add to the Effect Pool. This bytecode must contain only one effect.</param>
        /// <param name="effectPool">The effect pool used to register the bytecode. Default is <see cref="GraphicsDevice.DefaultEffectPool"/>.</param>
        /// <exception cref="ArgumentException">If the bytecode doesn't contain a single effect.</exception>
        /// <remarks>The effect bytecode must contain only a single effect and will be registered into the <see cref="GraphicsDevice.DefaultEffectPool"/>.</remarks>
        public Effect(GraphicsDevice device, EffectData effectData, EffectPool effectPool = null)
            : base(device)
        {
            CreateInstanceFrom(device, effectData, effectPool);

        }
Пример #21
0
        private void RemoveEffectPool(EffectPool effectPool)
        {
            effectPool.EffectAdded -= effectPool_EffectAdded;
            effectPool.EffectRemoved -= effectPool_EffectRemoved;

            foreach (var registeredEffect in effectPool.RegisteredEffects)
            {
                RemoveEffect(registeredEffect);
            }
        }
Пример #22
0
 /// <summary>
 /// Creates a new AlphaTestEffect with default parameter settings from a specified <see cref="EffectPool"/>.
 /// </summary>
 public AlphaTestEffect(GraphicsDevice device, EffectPool pool)
     : base(device, effectBytecode, pool)
 {
 }