Exemple #1
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 <see cref="GraphicsDevice.DefaultEffectPool"/>. This bytecode must contain only one effect.</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) : base(device)
        {
            if (effectData.Effects.Count != 1)
                throw new ArgumentException(string.Format("Expecting only one effect in the effect bytecode instead of [{0}]. Use GraphicsDevice.DefaultEffectPool.RegisterBytecode instead", Utilities.Join(",", effectData.Effects)), "bytecode");

            ConstantBuffers = new EffectConstantBufferCollection();
            Parameters = new EffectParameterCollection();
            Techniques = new EffectTechniqueCollection();
            ResourceLinker = ToDispose(new EffectResourceLinker());
            Pool = device.DefaultEffectPool;

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

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

            Initialize();
        }
Exemple #2
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();
 }