Example #1
0
        /// <summary>
        /// Add a new generic parameter.
        /// </summary>
        /// <typeparam name="TValue">The type of the generic.</typeparam>
        /// <param name="keyName">The name of the generic.</param>
        /// <param name="generics">The target ComputeColorParameters.</param>
        public void AddKey <TValue>(string keyName, ComputeColorParameters generics)
        {
            IComputeColorParameter computeColorParameter;
            var typeT = typeof(TValue);

            if (typeT == typeof(Texture))
            {
                computeColorParameter = new ComputeColorParameterTexture();
            }
            else if (typeT == typeof(float))
            {
                computeColorParameter = new ComputeColorParameterFloat();
            }
            else if (typeT == typeof(int))
            {
                computeColorParameter = new ComputeColorParameterInt();
            }
            else if (typeT == typeof(Vector2))
            {
                computeColorParameter = new ComputeColorParameterFloat2();
            }
            else if (typeT == typeof(Vector3))
            {
                computeColorParameter = new ComputeColorParameterFloat3();
            }
            else if (typeT == typeof(Vector4))
            {
                computeColorParameter = new ComputeColorParameterFloat4();
            }
            else if (typeT == typeof(SamplerState))
            {
                computeColorParameter = new ComputeColorParameterSampler();
            }
            else
            {
                throw new Exception("Unsupported generic format");
            }

            if (Generics.ContainsKey(keyName))
            {
                var gen = Generics[keyName];
                if (gen == null || gen.GetType() != computeColorParameter.GetType())
                {
                    generics[keyName] = computeColorParameter;
                }
                else
                {
                    generics[keyName] = gen;
                }
            }
            else
            {
                generics.Add(keyName, computeColorParameter);
            }
        }
Example #2
0
 protected ComputeShaderClassBase()
 {
     Generics         = new ComputeColorParameters();
     CompositionNodes = new Dictionary <string, T>();
     Members          = new Dictionary <ParameterKey, object>();
 }