コード例 #1
0
ファイル: GameView.cs プロジェクト: twenty0ne/UnityDecompiled
 private void LoadRenderDoc()
 {
     if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
     {
         RenderDoc.Load();
         ShaderUtil.RecreateGfxDevice();
     }
 }
コード例 #2
0
        public static void Init()
        {
            string CapturePath = Path.GetFullPath("./RenderDocCapture/");

            if (!Directory.Exists(CapturePath))
            {
                Directory.CreateDirectory(CapturePath);
            }

            if (RenderDoc.Load(out RDoc))
            {
                RDoc.SetCaptureSavePath(CapturePath);
            }
        }
コード例 #3
0
        private void Update(float deltaSeconds)
        {
            _fta.AddTime(deltaSeconds);
            _scene.Update(deltaSeconds);

            if (ImGui.BeginMainMenuBar())
            {
                if (ImGui.BeginMenu("Settings"))
                {
                    if (ImGui.BeginMenu("Graphics Backend"))
                    {
                        if (ImGui.MenuItem("Vulkan", string.Empty, _gd.BackendType == GraphicsBackend.Vulkan, GraphicsDevice.IsBackendSupported(GraphicsBackend.Vulkan)))
                        {
                            ChangeBackend(GraphicsBackend.Vulkan);
                        }
                        if (ImGui.MenuItem("OpenGL", string.Empty, _gd.BackendType == GraphicsBackend.OpenGL, GraphicsDevice.IsBackendSupported(GraphicsBackend.OpenGL)))
                        {
                            ChangeBackend(GraphicsBackend.OpenGL);
                        }
                        if (ImGui.MenuItem("OpenGL ES", string.Empty, _gd.BackendType == GraphicsBackend.OpenGLES, GraphicsDevice.IsBackendSupported(GraphicsBackend.OpenGLES)))
                        {
                            ChangeBackend(GraphicsBackend.OpenGLES);
                        }
                        if (ImGui.MenuItem("Direct3D 11", string.Empty, _gd.BackendType == GraphicsBackend.Direct3D11, GraphicsDevice.IsBackendSupported(GraphicsBackend.Direct3D11)))
                        {
                            ChangeBackend(GraphicsBackend.Direct3D11);
                        }
                        if (ImGui.MenuItem("Metal", string.Empty, _gd.BackendType == GraphicsBackend.Metal, GraphicsDevice.IsBackendSupported(GraphicsBackend.Metal)))
                        {
                            ChangeBackend(GraphicsBackend.Metal);
                        }
                        ImGui.EndMenu();
                    }
                    if (ImGui.BeginMenu("MSAA"))
                    {
                        if (ImGui.Combo("MSAA", ref _msaaOption, _msaaOptions, _msaaOptions.Length))
                        {
                            ChangeMsaa(_msaaOption);
                        }

                        ImGui.EndMenu();
                    }
                    bool threadedRendering = _scene.ThreadedRendering;
                    if (ImGui.MenuItem("Render with multiple threads", string.Empty, threadedRendering, true))
                    {
                        _scene.ThreadedRendering = !_scene.ThreadedRendering;
                    }
                    bool tinted = _fsq.UseTintedTexture;
                    if (ImGui.MenuItem("Tinted output", string.Empty, tinted, true))
                    {
                        _fsq.UseTintedTexture = !tinted;
                    }

                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Window"))
                {
                    bool isFullscreen = _window.WindowState == WindowState.BorderlessFullScreen;
                    if (ImGui.MenuItem("Fullscreen", "F11", isFullscreen, true))
                    {
                        ToggleFullscreenState();
                    }
                    if (ImGui.MenuItem("Always Recreate Sdl2Window", string.Empty, _recreateWindow, true))
                    {
                        _recreateWindow = !_recreateWindow;
                    }
                    if (ImGui.IsItemHovered())
                    {
                        ImGui.SetTooltip(
                            "Causes a new OS window to be created whenever the graphics backend is switched. This is much safer, and is the default.");
                    }
                    if (ImGui.MenuItem("sRGB Swapchain Format", string.Empty, _colorSrgb, true))
                    {
                        _colorSrgb = !_colorSrgb;
                        ChangeBackend(_gd.BackendType);
                    }
                    bool vsync = _gd.SyncToVerticalBlank;
                    if (ImGui.MenuItem("VSync", string.Empty, vsync, true))
                    {
                        _gd.SyncToVerticalBlank = !_gd.SyncToVerticalBlank;
                    }
                    bool resizable = _window.Resizable;
                    if (ImGui.MenuItem("Resizable Window", string.Empty, resizable))
                    {
                        _window.Resizable = !_window.Resizable;
                    }
                    bool bordered = _window.BorderVisible;
                    if (ImGui.MenuItem("Visible Window Border", string.Empty, bordered))
                    {
                        _window.BorderVisible = !_window.BorderVisible;
                    }

                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Materials"))
                {
                    if (ImGui.BeginMenu("Brick"))
                    {
                        DrawIndexedMaterialMenu(CommonMaterials.Brick);
                        ImGui.EndMenu();
                    }
                    if (ImGui.BeginMenu("Vase"))
                    {
                        DrawIndexedMaterialMenu(CommonMaterials.Vase);
                        ImGui.EndMenu();
                    }
                    if (ImGui.BeginMenu("Reflective"))
                    {
                        DrawIndexedMaterialMenu(CommonMaterials.Reflective);
                        ImGui.EndMenu();
                    }

                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Debug"))
                {
                    if (ImGui.MenuItem("Refresh Device Objects"))
                    {
                        RefreshDeviceObjects(1);
                    }
                    if (ImGui.MenuItem("Refresh Device Objects (10 times)"))
                    {
                        RefreshDeviceObjects(10);
                    }
                    if (ImGui.MenuItem("Refresh Device Objects (100 times)"))
                    {
                        RefreshDeviceObjects(100);
                    }
                    if (_controllerTracker != null)
                    {
                        if (ImGui.MenuItem("Controller State"))
                        {
                            _controllerDebugMenu = true;
                        }
                    }
                    else
                    {
                        if (ImGui.MenuItem("Connect to Controller"))
                        {
                            Sdl2ControllerTracker.CreateDefault(out _controllerTracker);
                            _scene.Camera.Controller = _controllerTracker;
                        }
                    }

                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("RenderDoc"))
                {
                    if (_renderDoc == null)
                    {
                        if (ImGui.MenuItem("Load"))
                        {
                            if (RenderDoc.Load(out _renderDoc))
                            {
                                ChangeBackend(_gd.BackendType);
                            }
                        }
                    }
                    else
                    {
                        if (ImGui.MenuItem("Trigger Capture"))
                        {
                            _renderDoc.TriggerCapture();
                        }
                        if (ImGui.BeginMenu("Options"))
                        {
                            bool allowVsync = _renderDoc.AllowVSync;
                            if (ImGui.Checkbox("Allow VSync", ref allowVsync))
                            {
                                _renderDoc.AllowVSync = allowVsync;
                            }
                            bool validation = _renderDoc.APIValidation;
                            if (ImGui.Checkbox("API Validation", ref validation))
                            {
                                _renderDoc.APIValidation = validation;
                            }
                            int delayForDebugger = (int)_renderDoc.DelayForDebugger;
                            if (ImGui.InputInt("Debugger Delay", ref delayForDebugger))
                            {
                                delayForDebugger            = Math.Clamp(delayForDebugger, 0, int.MaxValue);
                                _renderDoc.DelayForDebugger = (uint)delayForDebugger;
                            }
                            bool verifyBufferAccess = _renderDoc.VerifyBufferAccess;
                            if (ImGui.Checkbox("Verify Buffer Access", ref verifyBufferAccess))
                            {
                                _renderDoc.VerifyBufferAccess = verifyBufferAccess;
                            }
                            bool overlayEnabled = _renderDoc.OverlayEnabled;
                            if (ImGui.Checkbox("Overlay Visible", ref overlayEnabled))
                            {
                                _renderDoc.OverlayEnabled = overlayEnabled;
                            }
                            bool overlayFrameRate = _renderDoc.OverlayFrameRate;
                            if (ImGui.Checkbox("Overlay Frame Rate", ref overlayFrameRate))
                            {
                                _renderDoc.OverlayFrameRate = overlayFrameRate;
                            }
                            bool overlayFrameNumber = _renderDoc.OverlayFrameNumber;
                            if (ImGui.Checkbox("Overlay Frame Number", ref overlayFrameNumber))
                            {
                                _renderDoc.OverlayFrameNumber = overlayFrameNumber;
                            }
                            bool overlayCaptureList = _renderDoc.OverlayCaptureList;
                            if (ImGui.Checkbox("Overlay Capture List", ref overlayCaptureList))
                            {
                                _renderDoc.OverlayCaptureList = overlayCaptureList;
                            }
                            ImGui.EndMenu();
                        }
                        if (ImGui.MenuItem("Launch Replay UI"))
                        {
                            _renderDoc.LaunchReplayUI();
                        }
                    }
                    ImGui.EndMenu();
                }

                if (_controllerDebugMenu)
                {
                    if (ImGui.Begin("Controller State", ref _controllerDebugMenu, ImGuiWindowFlags.NoCollapse))
                    {
                        if (_controllerTracker != null)
                        {
                            ImGui.Columns(2);
                            ImGui.Text($"Name: {_controllerTracker.ControllerName}");
                            foreach (SDL_GameControllerAxis axis in (SDL_GameControllerAxis[])Enum.GetValues(typeof(SDL_GameControllerAxis)))
                            {
                                ImGui.Text($"{axis}: {_controllerTracker.GetAxis(axis)}");
                            }
                            ImGui.NextColumn();
                            foreach (SDL_GameControllerButton button in (SDL_GameControllerButton[])Enum.GetValues(typeof(SDL_GameControllerButton)))
                            {
                                ImGui.Text($"{button}: {_controllerTracker.IsPressed(button)}");
                            }
                        }
                        else
                        {
                            ImGui.Text("No controller detected.");
                        }
                    }
                    ImGui.End();
                }

                ImGui.Text(_fta.CurrentAverageFramesPerSecond.ToString("000.0 fps / ") + _fta.CurrentAverageFrameTimeMilliseconds.ToString("#00.00 ms"));

                ImGui.EndMainMenuBar();
            }

            if (InputTracker.GetKeyDown(Key.F11))
            {
                ToggleFullscreenState();
            }

            if (InputTracker.GetKeyDown(Key.Keypad6))
            {
                _window.X += 10;
            }
            if (InputTracker.GetKeyDown(Key.Keypad4))
            {
                _window.X -= 10;
            }
            if (InputTracker.GetKeyDown(Key.Keypad8))
            {
                _window.Y += 10;
            }
            if (InputTracker.GetKeyDown(Key.Keypad2))
            {
                _window.Y -= 10;
            }

            _window.Title = _gd.BackendType.ToString();
        }
コード例 #4
0
 public DrawTriangle()
     : base("BasicTest")
 {
     // Initialize RenderDoc before the graphics context.
     RenderDoc.Load(out this.renderDoc);
 }
コード例 #5
0
        unsafe public MapStudioNew()
        {
            CFG.AttemptLoadOrDefault();

            if (UseRenderdoc)
            {
                RenderDoc.Load(out RenderDocManager);
                RenderDocManager.OverlayEnabled = false;
            }

            WindowCreateInfo windowCI = new WindowCreateInfo
            {
                X                  = CFG.Current.GFX_Display_X,
                Y                  = CFG.Current.GFX_Display_Y,
                WindowWidth        = CFG.Current.GFX_Display_Width,
                WindowHeight       = CFG.Current.GFX_Display_Height,
                WindowInitialState = WindowState.Maximized,
                WindowTitle        = "Dark Souls Map Studio " + _version + " by Katalash",
            };
            GraphicsDeviceOptions gdOptions = new GraphicsDeviceOptions(false, PixelFormat.R32_Float, true, ResourceBindingModel.Improved, true, true, _colorSrgb);

#if DEBUG
            gdOptions.Debug = true;
#endif

            VeldridStartup.CreateWindowAndGraphicsDevice(
                windowCI,
                gdOptions,
                //VeldridStartup.GetPlatformDefaultBackend(),
                //GraphicsBackend.Metal,
                GraphicsBackend.Vulkan,

                //GraphicsBackend.Direct3D11,
                //GraphicsBackend.OpenGL,
                //GraphicsBackend.OpenGLES,
                out _window,
                out _gd);
            _window.Resized += () => _windowResized = true;
            _window.Moved   += (p) => _windowMoved = true;

            Sdl2Native.SDL_Init(SDLInitFlags.GameController);
            //Sdl2ControllerTracker.CreateDefault(out _controllerTracker);

            var factory = _gd.ResourceFactory;
            TextureSamplerResourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription(
                                                                            new ResourceLayoutElementDescription("SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                                                                            new ResourceLayoutElementDescription("SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment)));

            Scene.Renderer.Initialize(_gd);

            ImguiRenderer = new ImGuiRenderer(_gd, _gd.SwapchainFramebuffer.OutputDescription, CFG.Current.GFX_Display_Width,
                                              CFG.Current.GFX_Display_Height, ColorSpaceHandling.Legacy);
            MainWindowCommandList = factory.CreateCommandList();
            GuiCommandList        = factory.CreateCommandList();

            _assetLocator = new AssetLocator();
            MSBEditor     = new MsbEditor.MsbEditorScreen(_window, _gd, _assetLocator);
            ModelEditor   = new MsbEditor.ModelEditorScreen(_window, _gd, _assetLocator);
            ParamEditor   = new MsbEditor.ParamEditorScreen(_window, _gd);
            TextEditor    = new MsbEditor.TextEditorScreen(_window, _gd);

            MsbEditor.ParamBank.LoadParams(_assetLocator);
            MsbEditor.FMGBank.LoadFMGs(_assetLocator);
            MsbEditor.MtdBank.LoadMtds(_assetLocator);

            ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard;
            var fonts    = ImGui.GetIO().Fonts;
            var fileJp   = Path.Combine(AppContext.BaseDirectory, $@"Assets\Fonts\NotoSansCJKtc-Light.otf");
            var fontJp   = File.ReadAllBytes(fileJp);
            var fileEn   = Path.Combine(AppContext.BaseDirectory, $@"Assets\Fonts\RobotoMono-Light.ttf");
            var fontEn   = File.ReadAllBytes(fileEn);
            var fileIcon = Path.Combine(AppContext.BaseDirectory, $@"Assets\Fonts\forkawesome-webfont.ttf");
            var fontIcon = File.ReadAllBytes(fileIcon);
            //fonts.AddFontFromFileTTF($@"Assets\Fonts\NotoSansCJKtc-Medium.otf", 20.0f, null, fonts.GetGlyphRangesJapanese());
            fonts.Clear();
            fixed(byte *p = fontEn)
            {
                var ptr = ImGuiNative.ImFontConfig_ImFontConfig();
                var cfg = new ImFontConfigPtr(ptr);

                cfg.GlyphMinAdvanceX = 5.0f;
                cfg.OversampleH      = 5;
                cfg.OversampleV      = 5;
                var f = fonts.AddFontFromMemoryTTF((IntPtr)p, fontEn.Length, 14.0f, cfg, fonts.GetGlyphRangesDefault());
            }

            fixed(byte *p = fontJp)
            {
                var ptr = ImGuiNative.ImFontConfig_ImFontConfig();
                var cfg = new ImFontConfigPtr(ptr);

                cfg.MergeMode        = true;
                cfg.GlyphMinAdvanceX = 7.0f;
                cfg.OversampleH      = 5;
                cfg.OversampleV      = 5;
                var f = fonts.AddFontFromMemoryTTF((IntPtr)p, fontJp.Length, 16.0f, cfg, fonts.GetGlyphRangesJapanese());
            }

            fixed(byte *p = fontIcon)
            {
                ushort[] ranges = { ForkAwesome.IconMin, ForkAwesome.IconMax, 0 };
                var      ptr    = ImGuiNative.ImFontConfig_ImFontConfig();
                var      cfg    = new ImFontConfigPtr(ptr);

                cfg.MergeMode        = true;
                cfg.GlyphMinAdvanceX = 12.0f;
                cfg.OversampleH      = 5;
                cfg.OversampleV      = 5;
                ImFontGlyphRangesBuilder b = new ImFontGlyphRangesBuilder();

                fixed(ushort *r = ranges)
                {
                    var f = fonts.AddFontFromMemoryTTF((IntPtr)p, fontIcon.Length, 16.0f, cfg, (IntPtr)r);
                }
            }

            fonts.Build();
            ImguiRenderer.RecreateFontDeviceTexture();
            ImguiRenderer.OnSetupDone();

            var style = ImGui.GetStyle();
            style.TabBorderSize = 0;

            if (CFG.Current.LastProjectFile != null && CFG.Current.LastProjectFile != "")
            {
                if (File.Exists(CFG.Current.LastProjectFile))
                {
                    var project = MsbEditor.ProjectSettings.Deserialize(CFG.Current.LastProjectFile);
                    AttemptLoadProject(project, CFG.Current.LastProjectFile, false);
                }
            }
        }