Esempio n. 1
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);
        }
Esempio n. 2
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));
        }
Esempio n. 3
0
 static LightSimpleAmbientKeys()
 {
     AmbientLight = ParameterKeys.NewValue(new Color3(1.0f, 1.0f, 1.0f));
 }
Esempio n. 4
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));
        }
 static ImageScalerShaderKeys()
 {
     // Default value of 1.0f
     Color = ParameterKeys.NewValue(Color4.White);
 }
Esempio n. 6
0
        public void TestDefaultValuesGettingUpdatedAfterRecompile()
        {
            Init();

            var shaderClassName = "DefaultValuesBeingUpdatedTest";
            var variableName    = "floatVar";

            // First register the key as it would've been done by the generator
            var initialKey = ParameterKeys.NewValue(1f, $"{shaderClassName}.{variableName}");

            ParameterKeys.Merge(initialKey, null, initialKey.Name);

            GenerateAndCheck("1", 1f);

            Compiler.ResetCache(new HashSet <string>()
            {
                shaderClassName
            });

            GenerateAndCheck("2", 2f);

            void GenerateAndCheck(string stringValue, float value)
            {
                var variables = new List <(string name, TypeBase type, string value, object clrValue)>();

                variables.Add((name: variableName, type: ScalarType.Float, value: stringValue, clrValue: value));

                var assignments = new StringBuilder();

                foreach (var v in variables)
                {
                    assignments.AppendLine($"{v.type} {v.name} = {v.value};");
                }

                var mixinSource = new ShaderMixinSource()
                {
                    Name = shaderClassName
                };

                mixinSource.Mixins.Add(CreateShaderClassCode(shaderClassName, assignments.ToString()));
                var byteCodeTask = Compiler.Compile(mixinSource, MixinParameters.EffectParameters, MixinParameters);

                Assert.False(byteCodeTask.Result.CompilationLog.HasErrors);

                var byteCode = byteCodeTask.Result.Bytecode;

                using (var graphicsDevice = GraphicsDevice.New())
                {
                    // The effect constructor updates the effect reflection
                    var effect = new Effect(graphicsDevice, byteCode);

                    var members = byteCode.Reflection.ConstantBuffers[0].Members;
                    foreach (var v in variables)
                    {
                        // Fetch the default value via the key - the previous test already checked whether the default value is present in the value description
                        var effectValueDescription = members.FirstOrDefault(k => k.KeyInfo.KeyName == $"{shaderClassName}.{v.name}");
                        var defaultValue           = effectValueDescription.KeyInfo.Key.DefaultValueMetadata.GetDefaultValue();
                        Assert.NotNull(defaultValue);
                        Assert.Equal(v.clrValue, defaultValue);
                    }
                }
            }
        }