예제 #1
0
        protected override void OnKeyDown(object sender, KeyboardKeyEventArgs e)
        {
            if (e.Key == Key.Space) // Space enqueues a FLExecutionContext for each texture
            {
                //Creating a Texture Map that maps the buffers of the Interpreter to the Textures
                //"result" is always the result buffer of the interpreter
                //but if we wanted, we can define a buffer in the FL Script and map this buffer to any texture by its name.
                //Thats for example a cheap way to do specular textures alongside the actual textures.
                Dictionary <string, Texture> texMap = new Dictionary <string, Texture>
                {
                    //In This example we could also use "in" as a key,
                    //but this can be wrong at times when the fl execution context starts with a different input texture
                    //than output texture
                    { "in", _tex }
                };
                Dictionary <string, Texture> texMap2 = new Dictionary <string, Texture>
                {
                    { "in", _tex2 }
                };

                //We change the color every enqueue, to be able to see the change
                string path = red ? "assets/filter/red.fl" : "assets/filter/blue.fl";
                red = !red;


                byte[] texBuf  = TextureLoader.TextureToByteArray(_tex);
                byte[] tex2Buf = TextureLoader.TextureToByteArray(_tex2);
                //Creating the Execution Context

                FlScriptExecutionContext fle = new FlScriptExecutionContext(path, texBuf, (int)_tex.Width,
                                                                            (int)_tex.Height, program => OnFinishCallback(program, texMap));
                FlScriptExecutionContext fle2 = new FlScriptExecutionContext(path, tex2Buf, (int)_tex2.Width,
                                                                             (int)_tex2.Height, program => OnFinishCallback(program, texMap2));

                //Enqueuing the Contexts
                flRunner.Enqueue(fle);
                flRunner.Enqueue(fle2);


                Logger.Log(DebugChannel.Log | DebugChannel.GameOpenFL,
                           "Enqueued 2 Items. Items In Queue: " + flRunner.ItemsInQueue, 1);
            }

            if (e.Key == Key.Enter && flRunner.ItemsInQueue != 0) //When we press enter we will process our queue.
            {
                flRunner.Process();
            }

            base.OnKeyDown(sender, e);
        }
예제 #2
0
        /// <summary>
        /// Runs a FL Script
        /// </summary>
        /// <param name="filename">Path to the FL Script</param>
        public void RunOnObjImage(string filename)
        {
            Dictionary <string, Texture> otherTex = new Dictionary <string, Texture>
            {
                { "result", Tex }, { "specularOut", SpecularTex }
            };
            MemoryBuffer b = TextureLoader.TextureToMemoryBuffer(CLAPI.MainThread, Tex, "BufferFromFLResult");

            byte[] buf = CLAPI.ReadBuffer <byte>(CLAPI.MainThread, b, (int)b.Size);
            FlScriptExecutionContext exec = new FlScriptExecutionContext(filename, buf, (int)Tex.Width,
                                                                         (int)Tex.Height, program => OnFinishCallback(program, otherTex));

            flRunner.Enqueue(exec);
            flRunner.Process();
        }
예제 #3
0
        private void Run()
        {
            FLConsole.Settings.SetVerbosity();
            BufferCreator creator = new BufferCreator();

            FLConsole.Settings.BufferCreatorTypes.ForEach(x =>
                                                          creator.AddBufferCreator((ASerializableBufferCreator)Activator.CreateInstance(x)));
            KernelDatabase db = new KernelDatabase(CLAPI.MainThread, FLConsole.Settings.KernelFolder,
                                                   DataVectorTypes.Uchar1);
            FLInstructionSet      iset = FLInstructionSet.CreateWithBuiltInTypes(db);
            FLProgramCheckBuilder programCheckBuilder = new FLProgramCheckBuilder(iset, creator);

            FLConsole.Settings.ProgramCheckTypes.ForEach(x =>
                                                         programCheckBuilder.AddProgramCheck((FLProgramCheck)Activator.CreateInstance(x)));


            FLScriptRunner runner =
                new FLScriptRunner(CLAPI.MainThread, db, creator, iset, programCheckBuilder,
                                   new WorkItemRunnerSettings(FLConsole.Settings.MultiThread,
                                                              FLConsole.Settings.WorkSizeMultiplier));

            string[] inputFiles  = SetInputFilesCommand.InputFiles;
            string[] outputFiles = SetOutputFilesCommand.OutputFiles;


            for (int i = 0; i < inputFiles.Length; i++)
            {
                string inp  = inputFiles[i];
                string outp = outputFiles.Length > i
                    ? outputFiles[i]
                    : $"./{Path.GetFileNameWithoutExtension(inp)}.out.png";

                Bitmap bmp = new Bitmap(FLConsole.Settings.Resolution.X,
                                        FLConsole.Settings.Resolution.Y);

                runner.Enqueue(new FlScriptExecutionContext(inp, bmp, result => OnFinishCallback(result, outp)));
            }

            runner.Process();
        }
예제 #4
0
 public static void Process()
 {
     runner.Process();
 }