Beispiel #1
0
        public void TestCompiler()
        {
            var device = GraphicsDevice.New();

            // Compile a toolkit effect from a file
            var result = new EffectCompiler().CompileFromFile("TestEffect.fx");

            // Check that we don't have any errors
            Assert.False(result.HasErrors);

            var bytecode = result.EffectData;

            // Check that the name of this effect is the file name
            Assert.AreEqual(bytecode.Description.Name, "TestEffect");

            // We have 3 shaders compiled: VS, VS2, PS
            Assert.AreEqual(bytecode.Shaders.Count, 3);

            // Check that this is the profile 10.0
            Assert.AreEqual(bytecode.Shaders[0].Level, FeatureLevel.Level_10_0);

            // Create a EffectData pool from a single EffectData
            var effectGroup = EffectPool.New(device);

            //var effect = effectGroup.New<BasicEffect>();
            var effect = new Effect(device, bytecode, effectGroup);

            //Texture2D tex : register(t0);
            //Texture2D tex1 : register(t2);
            //Texture2D tex2 : register(t3);
            //Texture2D tex3 : register(t10);
            //SamplerState samp;
            var tex          = Texture2D.New(device, 256, 256, PixelFormat.R8.UNorm);
            var tex1         = Texture2D.New(device, 256, 256, PixelFormat.R8.UNorm);
            var tex2         = Texture2D.New(device, 256, 256, PixelFormat.R8.UNorm);
            var tex3         = Texture2D.New(device, 256, 256, PixelFormat.R8.UNorm);
            var samplerState = device.SamplerStates.PointWrap;

            effect.Parameters["tex"].SetResource(tex);
            effect.Parameters["tex1"].SetResource(tex1);
            effect.Parameters["tex2"].SetResource(tex2);
            effect.Parameters["tex3"].SetResource(tex3);
            effect.Parameters["worldViewProj"].SetValue(Matrix.Identity);
            effect.Parameters["samp"].SetResource(samplerState);

            //effect.Parameters["World"].SetValue(Vector3.Zero);
            //effect.Parameters["Tata"].SetResource(texture);

            effect.Techniques[0].Passes[0].Apply();

            Console.WriteLine(effect.Parameters.Count);

            effect.Dispose();
            device.Dispose();
        }