コード例 #1
0
ファイル: KeyTriggerComponent.cs プロジェクト: ByteChkR/Byt3
        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
ファイル: FLGeneratorComponent.cs プロジェクト: ByteChkR/Byt3
        /// <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();
        }