示例#1
0
        public void Run()
        {
            Veldrid.InputSnapshot snapshot = window.PumpEvents();
            if (!window.Exists)
            {
                return;
            }
            controller.Update(1f / 60f, snapshot);

            ImGuiNET.ImGui.Text("Hello World!");
            ImGuiNET.ImGui.SameLine();
            ImGuiNET.ImGui.Checkbox("show another window?", ref showAWindow);
            if (showAWindow)
            {
                ImGuiNET.ImGui.SetNextWindowSize(
                    new System.Numerics.Vector2(128, 128));
                ImGuiNET.ImGui.Begin("Another window", ref showAWindow);
                ImGuiNET.ImGui.Text("Lorem ipsum");
                if (ImGuiNET.ImGui.Button("I got it"))
                {
                    showAWindow = false;
                }
                ImGuiNET.ImGui.End();
            }

            cl.Begin();
            cl.SetFramebuffer(gd.MainSwapchain.Framebuffer);
            cl.ClearColorTarget(0, new Veldrid.RgbaFloat(160f / 255, 160f / 255, 192f / 255, 255f));
            controller.Render(gd, cl);
            cl.End();
            gd.SubmitCommands(cl);
            gd.SwapBuffers(gd.MainSwapchain);
        }
示例#2
0
        /// <summary>
        /// Submits the queued draw calls to the GPU
        /// </summary>
        internal void OnFrameEnd()
        {
            // End() must be called before commands can be submitted for execution.
            veldridCommandList.End();
            veldridGraphicsDevice.SubmitCommands(veldridCommandList);

            // Once commands have been submitted, the rendered image can be presented to the application window.
            veldridGraphicsDevice.SwapBuffers();

            nextBufferSlot = 0;
        }
        static void Main(string[] args)
        {
            //AppDomain.CurrentDomain.ProcessExit+= (s,e)=>{}

            var path = Path.GetTempFileName();

            System.IO.File.WriteAllText(path, testVGAOutputProgram);
            var assemblerInst   = new assembler.Assembler(path);
            var assembledResult = assemblerInst.ConvertToBinary();
            var binaryProgram   = assembledResult.Select(x => Convert.ToInt32(x, 16));

            //lets convert our final assembled program back to assembly instructions so we can view it.
            //dissasembly)
            var assembler2 = new assembler.Assembler(path);

            expandedCode = assembler2.ExpandMacros().ToArray();


            simulatorInstance = new simulator.eightChipsSimulator(16, (int)Math.Pow(2, 16));
            simulatorInstance.setUserCode(binaryProgram.ToArray());

            //TODO use cancellation token here.
            simulationThread = Task.Run(() =>
            {
                simulatorInstance.ProgramCounter = (int)assembler.Assembler.MemoryMap[assembler.Assembler.MemoryMapKeys.user_code].AbsoluteStart;
                simulatorInstance.runSimulation();
            });


            // Create window, GraphicsDevice, and all resources necessary for the demo.
            VeldridStartup.CreateWindowAndGraphicsDevice(
                new WindowCreateInfo(50, 50, 1280, 720, WindowState.Normal, "8 chips simulator 2"),
                new GraphicsDeviceOptions(true, null, true),
                out mainWindow,
                out gd);

            mainWindow.Resized += () =>
            {
                gd.MainSwapchain.Resize((uint)mainWindow.Width, (uint)mainWindow.Height);
                controller.WindowResized(mainWindow.Width, mainWindow.Height);
            };
            commandList = gd.ResourceFactory.CreateCommandList();
            controller  = new Veldrid.ImGuiRenderer(gd, gd.MainSwapchain.Framebuffer.OutputDescription, mainWindow.Width, mainWindow.Height);

            var data = simulatorInstance.mainMemory.Select(x => convertShortFormatToFullColor(Convert.ToInt32(x).ToBinary())).ToArray();

            //try creating an texture and binding it to an image which imgui will draw...
            //we'll need to modify this image every frame potentially...

            var texture = gd.ResourceFactory.CreateTexture(TextureDescription.Texture2D(width, height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled));

            CPUframeBufferTextureId = controller.GetOrCreateImGuiBinding(gd.ResourceFactory, texture);
            gd.UpdateTexture(texture, data, 0, 0, 0, width, height, 1, 0, 0);
            textureMap.Add(CPUframeBufferTextureId, texture);

            /*
             *          var state = new object();
             *          var timer = new System.Threading.Timer((o) =>
             *          {
             *              int[] newdata = simulatorInstance.mainMemory.Select(x => convertShortFormatToFullColor(x)).ToArray();
             *              var currenttexture = textureMap[CPUframeBufferTextureId];
             *              gd.UpdateTexture(currenttexture, newdata, 0, 0, 0, 256, 256, 1, 0, 0);
             *          }, state, 1000, 150);
             *
             */
            // Main application loop
            while (mainWindow.Exists)
            {
                InputSnapshot snapshot = mainWindow.PumpEvents();
                if (!mainWindow.Exists)
                {
                    break;
                }
                controller.Update(1f / 60f, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.

                SubmitUI();

                commandList.Begin();
                commandList.SetFramebuffer(gd.MainSwapchain.Framebuffer);
                commandList.ClearColorTarget(0, new RgbaFloat(.1f, .1f, .1f, .2f));
                controller.Render(gd, commandList);
                commandList.End();
                gd.SubmitCommands(commandList);
                gd.SwapBuffers(gd.MainSwapchain);
            }

            // Clean up Veldrid resources
            gd.WaitForIdle();
            controller.Dispose();
            commandList.Dispose();
            gd.Dispose();
        }