Example #1
0
        public override object ConvertFrom(ref ObjectContext objectContext, Scalar fromScalar)
        {
            var parameterKey = ParameterKeys.FindByName(fromScalar.Value);

            if (parameterKey == null)
            {
                throw new YamlException(fromScalar.Start, fromScalar.End, "Unable to find registered ParameterKey [{0}]".ToFormat(fromScalar.Value));
            }
            return(parameterKey);
        }
Example #2
0
        private ParameterKey GetComposedKey(ParameterKey key, int transformIndex)
        {
            var compositeKey = new ParameterCompositeKey(key, transformIndex);

            if (!compositeKeys.TryGetValue(compositeKey, out ParameterKey rawCompositeKey))
            {
                rawCompositeKey = ParameterKeys.FindByName($"{key.Name}.Transforms[{transformIndex}]");
                compositeKeys.Add(compositeKey, rawCompositeKey);
            }
            return(rawCompositeKey);
        }
Example #3
0
        private static ParameterKey FindOrCreateValueKey <T>(ref EffectValueDescription binding) where T : struct
        {
            var name = binding.KeyInfo.KeyName;
            var key  = ParameterKeys.FindByName(name) as ValueParameterKey <T> ?? ParameterKeys.NewValue <T>(name: name);

            // Update the default value with the one from the shader
            if (binding.DefaultValue is T defaultValue)
            {
                key.DefaultValueMetadataT.DefaultValue = defaultValue;
            }
            return(key);
        }
        public override object ConvertFrom(ref ObjectContext objectContext, Scalar fromScalar)
        {
            var parameterKey = ParameterKeys.FindByName(fromScalar.Value);

            if (parameterKey == null)
            {
                parameterKey = ParameterKeys.New <object>(null, fromScalar.Value);
                // Dont' throw an exception if keys was not found
                //throw new YamlException(fromScalar.Start, fromScalar.End, "Unable to find registered ParameterKey [{0}]".ToFormat(fromScalar.Value));
            }
            return(parameterKey);
        }
Example #5
0
        private ParameterKey GetComposedKey(ParameterKey key, int transformIndex)
        {
            var compositeKey = new ParameterCompositeKey(key, transformIndex);

            ParameterKey rawCompositeKey;
            if (!compositeKeys.TryGetValue(compositeKey, out rawCompositeKey))
            {
                rawCompositeKey = ParameterKeys.FindByName(string.Format("{0}.Transforms[{1}]", key.Name, transformIndex));
                compositeKeys.Add(compositeKey, rawCompositeKey);
            }
            return rawCompositeKey;
        }
Example #6
0
        /// <summary>
        /// Get the correct parameter key.
        /// </summary>
        /// <typeparam name="TValue">The type of the parameter.</typeparam>
        /// <param name="linkName">The name of the parameter key.</param>
        /// <returns>The parameter key.</returns>
        private static ParameterKey <TValue> GetTypedParameterKey <TValue>(string linkName)
        {
            var pk = ParameterKeys.FindByName(linkName);

            if (pk != null)
            {
                if (pk.PropertyType == typeof(TValue))
                {
                    return((ParameterKey <TValue>)pk);
                }
            }
            //TODO: log error
            return(null);
        }
Example #7
0
        // TODO this is not reusable outside this class (in other generators?)
        private KeyValuePair <ParameterKey, object> CreateKeyValue(ParameterKey key, object value)
        {
            // Find the real key instead of key loaded from yaml
            // as it can be later change at runtime
            var keyName = key.Name;

            key = ParameterKeys.FindByName(keyName);
            if (key == null)
            {
                throw new InvalidOperationException("ParameterKey [{0}] was not found from assemblies".ToFormat(keyName));
            }

            return(new KeyValuePair <ParameterKey, object>(key, key.ConvertValue(value)));
        }
Example #8
0
        public override UpdatableMember ResolveIndexer(string indexerName)
        {
            var key = ParameterKeys.FindByName(indexerName);

            if (key == null)
            {
                throw new InvalidOperationException($"Property Key path parse error: could not parse indexer value '{indexerName}'");
            }

            switch (key.Type)
            {
            case ParameterKeyType.Value:
                var accessorType = typeof(ValueParameterCollectionAccessor <>).MakeGenericType(key.PropertyType);
                return((UpdatableMember)Activator.CreateInstance(accessorType, key));

            case ParameterKeyType.Object:
                return(new ObjectParameterCollectionAccessor(key));

            default:
                throw new NotSupportedException($"{nameof(ParameterCollectionResolver)} can only handle Value and Object keys");
            }
        }
Example #9
0
        private static ParameterKey FindOrCreateValueKey <T>(EffectValueDescription binding) where T : struct
        {
            var name = binding.KeyInfo.KeyName;

            return(ParameterKeys.FindByName(name) ?? ParameterKeys.NewValue <T>(default(T), name));
        }
Example #10
0
 private static ParameterKey FindOrCreateResourceKey <T>(string name)
 {
     return(ParameterKeys.FindByName(name) ?? ParameterKeys.NewObject <T>(default(T), name));
 }
Example #11
0
        private static void UpdateValueBindingKey(ref EffectValueDescription binding)
        {
            switch (binding.Type.Class)
            {
            case EffectParameterClass.Scalar:
                switch (binding.Type.Type)
                {
                case EffectParameterType.Bool:
                    binding.KeyInfo.Key = FindOrCreateValueKey <bool>(binding);
                    break;

                case EffectParameterType.Int:
                    binding.KeyInfo.Key = FindOrCreateValueKey <int>(binding);
                    break;

                case EffectParameterType.UInt:
                    binding.KeyInfo.Key = FindOrCreateValueKey <uint>(binding);
                    break;

                case EffectParameterType.Float:
                    binding.KeyInfo.Key = FindOrCreateValueKey <float>(binding);
                    break;
                }
                break;

            case EffectParameterClass.Color:
            {
                var componentCount = binding.Type.RowCount != 1 ? binding.Type.RowCount : binding.Type.ColumnCount;
                switch (binding.Type.Type)
                {
                case EffectParameterType.Float:
                    binding.KeyInfo.Key = componentCount == 4
                                                        ? FindOrCreateValueKey <Color4>(binding)
                                                        : (componentCount == 3 ? FindOrCreateValueKey <Color3>(binding) : null);
                    break;
                }
            }
            break;

            case EffectParameterClass.Vector:
            {
                var componentCount = binding.Type.RowCount != 1 ? binding.Type.RowCount : binding.Type.ColumnCount;
                switch (binding.Type.Type)
                {
                case EffectParameterType.Bool:
                case EffectParameterType.Int:
                    binding.KeyInfo.Key = componentCount == 4 ? (ParameterKey)FindOrCreateValueKey <Int4>(binding) : (componentCount == 3 ? FindOrCreateValueKey <Int3>(binding) : null);
                    break;

                case EffectParameterType.UInt:
                    binding.KeyInfo.Key = componentCount == 4 ? FindOrCreateValueKey <UInt4>(binding) : null;
                    break;

                case EffectParameterType.Float:
                    binding.KeyInfo.Key = componentCount == 4
                                                        ? FindOrCreateValueKey <Vector4>(binding)
                                                        : (componentCount == 3 ? (ParameterKey)FindOrCreateValueKey <Vector3>(binding) : (componentCount == 2 ? FindOrCreateValueKey <Vector2>(binding) : null));
                    break;
                }
            }
            break;

            case EffectParameterClass.MatrixRows:
            case EffectParameterClass.MatrixColumns:
                binding.KeyInfo.Key = FindOrCreateValueKey <Matrix>(binding);
                break;

            case EffectParameterClass.Struct:
                binding.KeyInfo.Key = ParameterKeys.FindByName(binding.KeyInfo.KeyName);
                break;
            }

            if (binding.KeyInfo.Key == null)
            {
                throw new InvalidOperationException(string.Format("Unable to find/generate key [{0}] with unsupported type [{1}/{2}]", binding.KeyInfo.KeyName, binding.Type.Class, binding.Type.Type));
            }
        }
Example #12
0
        private static ParameterKey FindOrCreateValueKey <T>(EffectParameterValueData binding) where T : struct
        {
            var name = binding.Param.KeyName;

            return(ParameterKeys.FindByName(name) ?? ParameterKeys.NewValue <T>(default(T), name));
        }
Example #13
0
        private ParameterKey FindOrCreateValueKey <T>(EffectParameterValueData binding) where T : struct
        {
            var name = binding.Param.KeyName;

            return(ParameterKeys.FindByName(name) ?? (binding.Count > 1 ? (ParameterKey)ParameterKeys.New <T[]>(name) : ParameterKeys.New <T>(name)));
        }
Example #14
0
 private ParameterKey FindOrCreateResourceKey <T>(string name)
 {
     return(ParameterKeys.FindByName(name) ?? ParameterKeys.New <T>(name));
 }
Example #15
0
        private ParameterKey UpdateValueBindingKey(ref EffectParameterValueData binding)
        {
            switch (binding.Param.Class)
            {
            case EffectParameterClass.Scalar:
                switch (binding.Param.Type)
                {
                case EffectParameterType.Bool:
                    binding.Param.Key = FindOrCreateValueKey <bool>(binding);
                    break;

                case EffectParameterType.Int:
                    binding.Param.Key = FindOrCreateValueKey <int>(binding);
                    break;

                case EffectParameterType.UInt:
                    binding.Param.Key = FindOrCreateValueKey <uint>(binding);
                    break;

                case EffectParameterType.Float:
                    binding.Param.Key = FindOrCreateValueKey <float>(binding);
                    break;
                }
                break;

            case EffectParameterClass.Color:
            {
                var componentCount = binding.RowCount != 1 ? binding.RowCount : binding.ColumnCount;
                switch (binding.Param.Type)
                {
                case EffectParameterType.Float:
                    binding.Param.Key = componentCount == 4
                                                        ? FindOrCreateValueKey <Color4>(binding)
                                                        : (componentCount == 3 ? (ParameterKey)FindOrCreateValueKey <Color3>(binding) : null);
                    break;
                }
            }
            break;

            case EffectParameterClass.Vector:
            {
                var componentCount = binding.RowCount != 1 ? binding.RowCount : binding.ColumnCount;
                switch (binding.Param.Type)
                {
                case EffectParameterType.Bool:
                case EffectParameterType.Int:
                    binding.Param.Key = componentCount == 4 ? (ParameterKey)FindOrCreateValueKey <Int4>(binding) : (componentCount == 3 ? FindOrCreateValueKey <Int3>(binding) : null);
                    break;

                case EffectParameterType.UInt:
                    binding.Param.Key = componentCount == 4 ? FindOrCreateValueKey <UInt4>(binding) : null;
                    break;

                case EffectParameterType.Float:
                    binding.Param.Key = componentCount == 4
                                                        ? FindOrCreateValueKey <Vector4>(binding)
                                                        : (componentCount == 3 ? (ParameterKey)FindOrCreateValueKey <Vector3>(binding) : (componentCount == 2 ? FindOrCreateValueKey <Vector2>(binding) : null));
                    break;
                }
            }
            break;

            case EffectParameterClass.MatrixRows:
            case EffectParameterClass.MatrixColumns:
                binding.Param.Key = FindOrCreateValueKey <Matrix>(binding);
                break;

            case EffectParameterClass.Struct:
                binding.Param.Key = ParameterKeys.FindByName(binding.Param.KeyName);
                break;
            }

            if (binding.Param.Key == null)
            {
                throw new InvalidOperationException(string.Format("Unable to find/generate key [{0}] with unsupported type [{1}/{2}]", binding.Param.KeyName, binding.Param.Class, binding.Param.Type));
            }

            if (binding.Count > 1)
            {
                // Unspecified array length: guess from shader and set default parameter with array matching shader size
                binding.Param.Key = binding.Param.Key.CloneLength(binding.Count);
            }

            return(binding.Param.Key);
        }