Beispiel #1
0
        /// <summary>
        /// Generates a <see cref="ShaderMixinSource" /> for the specified names and parameters.
        /// </summary>
        /// <param name="pdxfxEffectName">The name.</param>
        /// <param name="properties">The properties.</param>
        /// <returns>The result of the mixin.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// pdxfxEffectName
        /// or
        /// properties
        /// </exception>
        /// <exception cref="System.ArgumentException">pdxfxEffectName</exception>
        public static ShaderMixinSource Generate(string pdxfxEffectName, ParameterCollection properties)
        {
            if (pdxfxEffectName == null)
            {
                throw new ArgumentNullException("pdxfxEffectName");
            }

            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            // Get the effect name and child effect name "RootEffectName.ChildEffectName"
            var effectName      = GetEffectName(pdxfxEffectName);
            var rootEffectName  = effectName.Key;
            var childEffectName = effectName.Value;

            IShaderMixinBuilder builder;
            Dictionary <string, IShaderMixinBuilder> builders;

            lock (RegisteredBuilders)
            {
                if (!TryGet(rootEffectName, out builder))
                {
                    throw new ArgumentException(string.Format("Pdxfx effect [{0}] not found", rootEffectName), "pdxfxEffectName");
                }

                builders = new Dictionary <string, IShaderMixinBuilder>(RegisteredBuilders);
            }

            // TODO cache mixin context and avoid to recreate one (check if if thread concurrency could occur here)
            var mixinTree = new ShaderMixinSource()
            {
                Name = pdxfxEffectName
            };
            var context = new ShaderMixinContext(mixinTree, properties, builders)
            {
                ChildEffectName = childEffectName
            };

            try
            {
                builder.Generate(mixinTree, context);
            }
            catch (ShaderMixinDiscardException discard)
            {
                // We don't rethrow as this exception is on purpose to early exit/escape from a shader mixin
            }
            return(mixinTree);
        }
Beispiel #2
0
        /// <summary>
        /// Generates a <see cref="ShaderMixinSourceTree" /> for the specified names and parameters.
        /// </summary>
        /// <param name="pdxfxEffectName">The name.</param>
        /// <param name="properties">The properties.</param>
        /// <returns>The result of the mixin.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// pdxfxEffectName
        /// or
        /// properties
        /// </exception>
        /// <exception cref="System.ArgumentException">pdxfxEffectName</exception>
        public static ShaderMixinSourceTree Generate(string pdxfxEffectName, ParameterCollection properties)
        {
            if (pdxfxEffectName == null)
            {
                throw new ArgumentNullException("pdxfxEffectName");
            }

            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            IShaderMixinBuilder builder;
            Dictionary <string, IShaderMixinBuilder> builders;

            lock (RegisteredBuilders)
            {
                if (!TryGet(pdxfxEffectName, out builder))
                {
                    throw new ArgumentException(string.Format("Pdxfx effect [{0}] not found", pdxfxEffectName), "pdxfxEffectName");
                }

                builders = new Dictionary <string, IShaderMixinBuilder>(RegisteredBuilders);
            }

            // TODO cache mixin context and avoid to recreate one (check if if thread concurrency could occur here)
            var context   = new ShaderMixinContext(properties, builders);
            var mixinTree = new ShaderMixinSourceTree()
            {
                Name = pdxfxEffectName
            };

            context.BeginChild(mixinTree);
            builder.Generate(mixinTree, context);
            context.EndChild();

            return(mixinTree);
        }
Beispiel #3
0
        /// <summary>
        /// Generates a <see cref="ShaderMixinSourceTree"/> for the specified names and parameters.
        /// </summary>
        /// <param name="pdxfxEffectName">The name.</param>
        /// <param name="properties">The properties.</param>
        /// <param name="mainUsedParameters">The parameters when prcessing the mixin.</param>
        /// <returns>The result of the mixin.</returns>
        public static ShaderMixinSourceTree Generate(string pdxfxEffectName, ParameterCollection properties, out ShaderMixinParameters mainUsedParameters, out List <ShaderMixinParameters> usedParameters)
        {
            if (pdxfxEffectName == null)
            {
                throw new ArgumentNullException("pdxfxEffectName");
            }

            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            IShaderMixinBuilder builder;
            Dictionary <string, IShaderMixinBuilder> builders;

            lock (RegisteredBuilders)
            {
                if (!TryGet(pdxfxEffectName, out builder))
                {
                    throw new ArgumentException(string.Format("Pdxfx effect [{0}] not found", pdxfxEffectName), "pdxfxEffectName");
                }

                builders = new Dictionary <string, IShaderMixinBuilder>(RegisteredBuilders);
            }

            var context   = new ShaderMixinContext(properties, builders, pdxfxEffectName);
            var mixinTree = new ShaderMixinSourceTree()
            {
                Name = pdxfxEffectName
            };

            builder.Generate(mixinTree, context);

            mainUsedParameters = context.GetMainUsedParameters();
            usedParameters     = context.GetUsedParameters();
            return(mixinTree);
        }