Esempio n. 1
0
        public void Render(double sleepTime, Core core)
        {
            try
            {
                startFrameTime = sw.Elapsed.TotalSeconds;
                Clear(new Color(_clearColor.X, _clearColor.Y, _clearColor.Z, _clearColor.W));
                debugTime = sw.Elapsed.TotalMilliseconds;
                ImGui.NewFrame();

                // ImGuiRender.InputUpdate();
                ImGuiRender.BeginBackGroundWindow();
                core.Tick();
                debugTime = sw.Elapsed.TotalMilliseconds;
                SpritesRender.Render();
                SpritesDebug.Tick = sw.Elapsed.TotalMilliseconds - debugTime;
                debugTime         = sw.Elapsed.TotalMilliseconds;
                ImGuiRender.Render();
                ImGuiDebug.Tick = sw.Elapsed.TotalMilliseconds - debugTime;
                debugTime       = sw.Elapsed.TotalMilliseconds;
                _swapChain.Present(VSync ? 1 : 0, PresentFlags.None);
                SwapchainDebug.Tick = (float)(sw.Elapsed.TotalMilliseconds - debugTime);
                endFrameTime        = sw.Elapsed.TotalSeconds;
                ImGui.GetIO().DeltaTime = (float)Time.DeltaTime;
            }
            catch (Exception e)
            {
                Core.Logger.Error($"DX11.Render -> {e}");
            }
        }
Esempio n. 2
0
        public DX11(RenderForm form, CoreSettings coreSettings)
        {
            _form = form;
            sw    = Stopwatch.StartNew();
            LoadedTexturesByName = new Dictionary <string, ShaderResourceView>();
            LoadedTexturesByPtrs = new Dictionary <IntPtr, ShaderResourceView>();

            var swapChainDesc = new SwapChainDescription
            {
                Usage             = Usage.RenderTargetOutput,
                OutputHandle      = form.Handle,
                BufferCount       = 1,
                IsWindowed        = true,
                Flags             = SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SwapEffect.Discard,
                SampleDescription = new SampleDescription(1, 0),
                ModeDescription   = new ModeDescription
                {
                    Format           = Format.R8G8B8A8_UNorm,
                    Width            = form.Width,
                    Height           = form.Height,
                    Scaling          = DisplayModeScaling.Unspecified,
                    RefreshRate      = new Rational(60, 1),
                    ScanlineOrdering = DisplayModeScanlineOrder.Unspecified
                }
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None,
                                       new[] { FeatureLevel.Level_11_0, FeatureLevel.Level_10_0 }, swapChainDesc, out var device,
                                       out var swapChain);

            D11Device     = device;
            DeviceContext = device.ImmediateContext;
            _swapChain    = swapChain;

            factory = swapChain.GetParent <Factory>();
            factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
            BackBuffer       = Resource.FromSwapChain <Texture2D>(swapChain, 0);
            RenderTargetView = new RenderTargetView(device, BackBuffer);

            using (new PerformanceTimer("Init ImGuiRender"))
            {
                ImGuiRender = new ImGuiRender(this, form, coreSettings);
            }

            using (new PerformanceTimer("Init SpriteRender"))
            {
                SpritesRender = new SpritesRender(this, form, coreSettings);
            }

            InitStates();

            form.UserResized += (sender, args) =>
            {
                RenderTargetView?.Dispose();
                BackBuffer.Dispose();

                swapChain.ResizeBuffers(1, form.Width, form.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);
                BackBuffer       = Resource.FromSwapChain <Texture2D>(swapChain, 0);
                RenderTargetView = new RenderTargetView(device, BackBuffer);
                ImGuiRender.Resize(form.Bounds);
                ImGuiRender.UpdateConstantBuffer();
                SpritesRender.ResizeConstBuffer(BackBuffer.Description);
                var descp = BackBuffer.Description;
                Viewport.Height = form.Height;
                Viewport.Width  = form.Width;
                DeviceContext.Rasterizer.SetViewport(Viewport);
                DeviceContext.OutputMerger.SetRenderTargets(RenderTargetView);
            };

            ImGuiDebug     = new DebugInformation("ImGui");
            SpritesDebug   = new DebugInformation("Sprites");
            SwapchainDebug = new DebugInformation("Swapchain");

            // Core.DebugInformations.Add(ImGuiDebug);
            // Core.DebugInformations.Add(ImGuiInputDebug);
            // Core.DebugInformations.Add(SpritesDebug);
            // Core.DebugInformations.Add(SwapchainDebug);
        }