Esempio n. 1
0
        /// <summary>
        /// Creates a new instance of the <see cref="EffectBinding"/> class for a material instance.
        /// </summary>
        internal EffectBinding CreateMaterialInstance()
        {
            Debug.Assert(Hints == EffectParameterHint.Material, "EffectBinding for material expected.");

            // Note: The EffectBinding used in a Material can be a special binding, such as
            // BasicEffectBinding. The EffectBinding used in the MaterialInstance is not a
            // clone of the BasicEffectBinding, instead it is a normal EffectBinding.

            // A material instance may contain all parameters, except global and material settings.
            const EffectParameterHint hints = EffectParameterHint.Local
                                              | EffectParameterHint.PerInstance
                                              | EffectParameterHint.PerPass;

            var effectBinding = new EffectBinding
            {
                EffectEx          = EffectEx,
                MaterialBinding   = this,
                TechniqueBinding  = TechniqueBinding.Clone(),
                ParameterBindings = new EffectParameterBindingCollection(hints),
                OpaqueData        = OpaqueData,
            };

            // Copy all local, per-instance and per-pass bindings.
            foreach (var binding in EffectEx.ParameterBindings)
            {
                if ((binding.Description.Hint & hints) != 0)
                {
                    effectBinding.ParameterBindings.Add(binding.Clone());
                }
            }

            return(effectBinding);
        }
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="EffectParameterDescription"/> class.
        /// </summary>
        /// <param name="parameter">The effect parameter.</param>
        /// <param name="semantic">The semantic.</param>
        /// <param name="index">The index.</param>
        /// <param name="hint">
        /// A value indicating how the effect parameter should be treated during state sorting.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="parameter"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Invalid <paramref name="index"/>. Allowed values are -1, 0, and positive numbers.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="hint"/> is invalid.
        /// </exception>
        public EffectParameterDescription(EffectParameter parameter, string semantic, int index, EffectParameterHint hint)
        {
            if (parameter == null)
            throw new ArgumentNullException("parameter");
              if (index < -1)
            throw new ArgumentOutOfRangeException("index", "The index of the effect parameter must be -1, 0, or positive.");

              ValidateHint(hint);

              Semantic = semantic;
              Parameter = parameter;
              Index = index;
              Hint = hint;
        }
        private static void ValidateHint(EffectParameterHint hint)
        {
            switch (hint)
            {
            case EffectParameterHint.Global:
            case EffectParameterHint.Material:
            case EffectParameterHint.PerInstance:
            case EffectParameterHint.Local:
            case EffectParameterHint.PerPass:
                return;

            default:
                throw new ArgumentException("Invalid effect parameter hint. Allowed values are Global, Material, Local, PerInstance, and PerPass.", "hint");
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EffectParameterDescription"/> class.
        /// </summary>
        /// <param name="parameter">The effect parameter.</param>
        /// <param name="semantic">The semantic.</param>
        /// <param name="index">The index.</param>
        /// <param name="hint">
        /// A value indicating how the effect parameter should be treated during state sorting.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="parameter"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Invalid <paramref name="index"/>. Allowed values are -1, 0, and positive numbers.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="hint"/> is invalid.
        /// </exception>
        public EffectParameterDescription(EffectParameter parameter, string semantic, int index, EffectParameterHint hint)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }
            if (index < -1)
            {
                throw new ArgumentOutOfRangeException("index", "The index of the effect parameter must be -1, 0, or positive.");
            }

            ValidateHint(hint);

            Semantic  = semantic;
            Parameter = parameter;
            Index     = index;
            Hint      = hint;
        }
        private static void ValidateHint(EffectParameterHint hint)
        {
            switch (hint)
              {
            case EffectParameterHint.Global:
            case EffectParameterHint.Material:
            case EffectParameterHint.PerInstance:
            case EffectParameterHint.Local:
            case EffectParameterHint.PerPass:
              return;

            default:
              throw new ArgumentException("Invalid effect parameter hint. Allowed values are Global, Material, Local, PerInstance, and PerPass.", "hint");
              }
        }
Esempio n. 6
0
        public EffectBinding(IGraphicsService graphicsService, Effect effect, IDictionary <string, object> opaqueData, EffectParameterHint hints)
        {
            if (graphicsService == null)
            {
                throw new ArgumentNullException("graphicsService");
            }
            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }

            if (effect is AlphaTestEffect && !(effect is WrappedAlphaTestEffect) ||
                effect is BasicEffect && !(effect is WrappedBasicEffect) ||
                effect is DualTextureEffect && !(effect is WrappedDualTextureEffect) ||
                effect is EnvironmentMapEffect && !(effect is WrappedEnvironmentMapEffect) ||
                effect is SkinnedEffect && !(effect is WrappedSkinnedEffect))
            {
                throw new ArgumentException("The EffectBinding class cannot be used with XNA stock effects (e.g. BasicEffect). Use a derived effect binding instead (e.g. BasicEffectBinding).");
            }

            // Initialize additional information, if not already initialized.
            EffectEx = EffectEx.From(effect, graphicsService);

            if (KeepOpaqueData)
            {
                OpaqueData = opaqueData;
            }

            // Initialize effect bindings.
            ParameterBindings = new EffectParameterBindingCollection(hints);
            InitializeBindings(graphicsService, opaqueData);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EffectParameterBindingCollection"/> class.
 /// </summary>
 /// <param name="hints">
 /// A bitwise combination of <see cref="EffectParameterHint"/> values. The value defines which
 /// parameter bindings can be added to the collection.
 /// </param>
 internal EffectParameterBindingCollection(EffectParameterHint hints)
 {
     Hints = hints;
 }
Esempio n. 8
0
        public EffectBinding(IGraphicsService graphicsService, Effect effect, IDictionary<string, object> opaqueData, EffectParameterHint hints)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");
              if (effect == null)
            throw new ArgumentNullException("effect");

              if (effect is AlphaTestEffect && !(effect is WrappedAlphaTestEffect)
              || effect is BasicEffect && !(effect is WrappedBasicEffect)
              || effect is DualTextureEffect && !(effect is WrappedDualTextureEffect)
              || effect is EnvironmentMapEffect && !(effect is WrappedEnvironmentMapEffect)
              || effect is SkinnedEffect && !(effect is WrappedSkinnedEffect))
              {
            throw new ArgumentException("The EffectBinding class cannot be used with XNA stock effects (e.g. BasicEffect). Use a derived effect binding instead (e.g. BasicEffectBinding).");
              }

              // Initialize additional information, if not already initialized.
              EffectEx = EffectEx.From(effect, graphicsService);

              if (KeepOpaqueData)
            OpaqueData = opaqueData;

              // Initialize effect bindings.
              ParameterBindings = new EffectParameterBindingCollection(hints);
              InitializeBindings(graphicsService, opaqueData);
        }