private List <SerializableExternalFLFunction> ParseScriptDefines(DefineStatement[] statements) { List <SerializableExternalFLFunction> ret = new List <SerializableExternalFLFunction>(); for (int i = 0; i < statements.Length; i++) { string name = statements[i].Name; string relPath = FLParser.GetScriptPath(statements[i].SourceLine); string p = relPath; if (!IOManager.FileExists(p)) { throw new FLInvalidDefineStatementException("Can not Find Script with path: " + p); } SerializableFLProgram ps = parser.Process(new FLParserInput(p, false)); ret.Add( new SerializableExternalFLFunction( name, ps, statements[i].Modifiers as FLExecutableElementModifiers ) ); } return(ret); }
protected FLProgram Process(FlScriptExecutionContext context) { FLBuffer input = new FLBuffer( Instance, context.Input, context.Width, context.Height, context.Depth, context.Filename ); FLProgram program; if (context.IsCompiled) { Stream s = IOManager.GetStream(context.Filename); program = FLSerializer.LoadProgram(s, InstructionSet).Initialize(Instance, InstructionSet); s.Close(); } else { program = Parser.Process(new FLParserInput(context.Filename)).Initialize(Instance, InstructionSet); } program.Run(input, true); return(program); }
private Texture GenerateGroundTexture() { Stopwatch sw = new Stopwatch(); sw.Start(); int texWidth = 1024; int texHeight = 1024; Texture tex = TextureLoader.ParameterToTexture(texWidth, texHeight, "GroundTextureCL"); FLBuffer buffer = new FLBuffer(TextureLoader.TextureToMemoryBuffer(CLAPI.MainThread, tex, "BufferForFLProgram"), 128, 128); FLProgram program = parser.Process(new FLParserInput("assets/filter/examples/grass.fl")).Initialize(iset); program.Run(CLAPI.MainThread, buffer, true); FLBuffer result = program.GetActiveBuffer(false); byte[] dat = CLAPI.ReadBuffer <byte>(CLAPI.MainThread, result.Buffer, (int)result.Buffer.Size); //Create a texture from the output. TextureLoader.Update(tex, dat, 1024, 1024); Logger.Log(DebugChannel.Log, "Time for Ground Texture(ms): " + sw.ElapsedMilliseconds, 10); sw.Stop(); return(tex); }
protected override void InitializeScene() { creator = BufferCreator.CreateWithBuiltInTypes(); iset = FLInstructionSet.CreateWithBuiltInTypes(CLAPI.MainThread, "assets/kernel/"); checkPipeline = FLProgramCheckBuilder.CreateDefaultCheckBuilder(iset, creator); parser = new FLParser(iset, creator); checkPipeline.Attach(parser, true); Add(DebugConsoleComponent.CreateConsole()); Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView( MathHelper.DegreesToRadians(75f), //Field of View Vertical 16f / 9f, //Aspect Ratio 0.1f, //Near Plane 1000f); //Far Plane BasicCamera bc = new BasicCamera(proj, Vector3.Zero); Add(bc); //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from. GameObject box = new GameObject(-Vector3.UnitZ * 4, "Box"); //Creating a new Empty GameObject LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component DefaultFilepaths.DefaultLitShader, //The OpenGL Shader used(Unlit and Lit shaders are provided) Prefabs.Cube, //The Mesh that is going to be used by the MeshRenderer tex, //Diffuse Texture to put on the mesh 1); //Render Mask (UI = 1 << 30) box.AddComponent(lmr); //Attaching the Renderer to the GameObject box.AddComponent(new RotateSelfComponent()); //Adding a component that rotates the Object on the Y-Axis Add(box); //Adding the Object to the Scene. FLBuffer buffer = new FLBuffer(TextureLoader.TextureToMemoryBuffer(CLAPI.MainThread, tex, "BufferForFLProgram"), 128, 128); FLProgram program = parser.Process(new FLParserInput("assets/filter/red.fl")).Initialize(iset); program.Run(CLAPI.MainThread, buffer, true); FLBuffer result = program.GetActiveBuffer(false); byte[] dat = CLAPI.ReadBuffer <byte>(CLAPI.MainThread, result.Buffer, (int)result.Buffer.Size); //Create a texture from the output. TextureLoader.Update(tex, dat, 128, 128); result.Dispose(); }
public void OpenFL_DefineScriptFile_Wrong_Test() { TestSetup.SetupTestingSession(); string file = "resources/filter/defines/test_wrong_script_invalid_file.fl"; Assert.Catch <Byt3Exception>(() => { FLParser parser = new FLParser(); Assembly asm = Assembly.GetAssembly(typeof(ASerializableBufferCreator)); parser.BufferCreator.AddBufferCreatorsInAssembly(asm); SerializableFLProgram pr = parser.Process(new FLParserInput(file)); }); }
public void OpenFL_Comments_Test() { TestSetup.SetupTestingSession(); string file = "resources/filter/comments/test.fl"; FLParser parser = new FLParser(); Assembly asm = Assembly.GetAssembly(typeof(ASerializableBufferCreator)); parser.BufferCreator.AddBufferCreatorsInAssembly(asm); SerializableFLProgram pr = parser.Process(new FLParserInput(file)); //FLFunction entryPoint = pr.EntryPoint; //Provoking an exception if main function is not found }
public void OpenFL_Defines_Test() { TestSetup.SetupTestingSession(); string file = "resources/filter/defines/test.fl"; FLParser parser = new FLParser(); Assembly asm = Assembly.GetAssembly(typeof(ASerializableBufferCreator)); parser.BufferCreator.AddBufferCreatorsInAssembly(asm); SerializableFLProgram result = parser.Process(new FLParserInput(file)); Assert.True(result.DefinedBuffers.Count == 5); Assert.True(result.DefinedBuffers.Count(x => x.Name == "in") == 1); Assert.True(result.DefinedBuffers.Count(x => x.Name == "textureD") == 1); Assert.True(result.DefinedBuffers.Count(x => x.Name == "textureC") == 1); Assert.True(result.DefinedBuffers.Count(x => x.Name == "textureB") == 1); Assert.True(result.DefinedBuffers.Count(x => x.Name == "textureA") == 1); }
public void OpenFL_DefineFile_Wrong_Test() { TestSetup.SetupTestingSession(); string file = "resources/filter/defines/test_wrong_define_invalid_file.fl"; Assert.Catch <Byt3Exception>(() => { BufferCreator bc = new BufferCreator(); FLInstructionSet iset = new FLInstructionSet(); FLProgramCheckBuilder checkBuilder = new FLProgramCheckBuilder(iset, bc); checkBuilder.AddProgramCheck(new FilePathValidator()); FLParser parser = new FLParser(iset, bc); checkBuilder.Attach(parser, true); Assembly asm = Assembly.GetAssembly(typeof(ASerializableBufferCreator)); parser.BufferCreator.AddBufferCreatorsInAssembly(asm); SerializableFLProgram pr = parser.Process(new FLParserInput(file)); }); }
public void OpenFL_WFCDefines_Wrong_Test() { TestSetup.SetupTestingSession(); string[] files = IOManager.GetFiles("resources/filter/defines/", "test_wrong_define_wfc_*.fl"); Assert.IsNotEmpty(files, "No Test FL Scripts found for " + nameof(OpenFL_WFCDefines_Wrong_Test)); foreach (string file in files) { Assert.Catch <AggregateException>(() => { FLParser parser = new FLParser(); Assembly asm = Assembly.GetAssembly(typeof(ASerializableBufferCreator)); parser.BufferCreator.AddBufferCreatorsInAssembly(asm); SerializableFLProgram pr = parser.Process(new FLParserInput(file)); }); } }
private void Build() { FLConsole.Settings.SetVerbosity(); string[] inputFiles = SetInputFilesCommand.InputFiles; string[] outputFiles = SetOutputFilesCommand.OutputFiles; BufferCreator creator = new BufferCreator(); FLConsole.Settings.BufferCreatorTypes.ForEach(x => creator.AddBufferCreator((ASerializableBufferCreator)Activator.CreateInstance(x))); FLInstructionSet iset = FLInstructionSet.CreateWithBuiltInTypes(CLAPI.MainThread, FLConsole.Settings.KernelFolder); FLProgramCheckBuilder programCheckBuilder = new FLProgramCheckBuilder(iset, creator); FLParser p = new FLParser(iset, creator, new WorkItemRunnerSettings(FLConsole.Settings.MultiThread, FLConsole.Settings.WorkSizeMultiplier)); programCheckBuilder.Attach(p, true); Logger.Log(LogType.Log, $"Building {inputFiles.Length} Files", 1); for (int i = 0; i < inputFiles.Length; i++) { string inp = inputFiles[i]; Logger.Log(LogType.Log, $"Building {inp}", 2); string outp = outputFiles.Length > i ? outputFiles[i] : $"./{Path.GetFileNameWithoutExtension(inp)}.flc"; SerializableFLProgram prog = p.Process(new FLParserInput(inp)); Stream dst = File.Create(outp); FLSerializer.SaveProgram(dst, prog, iset, ExtraStepCommand.extras); dst.Close(); Logger.Log(LogType.Log, $"Output: {outp}", 2); } Logger.Log(LogType.Log, $"Finished Building {inputFiles.Length} Files", 1); }