Пример #1
0
        /// <summary>
        /// Create and initialize a new game.
        /// </summary>
        public EditorWindow()
        {
            disposer = new DisposeGroup();
            // Initialize window and imgui
            var projectInfo = Assembly.GetExecutingAssembly().GetName();

            view = disposer.Add(new RenderView(new RenderViewSettings()
            {
                X      = 100,
                Y      = 100,
                Width  = 1280,
                Height = 720,
                Title  = $"{projectInfo.Name} {DateTime.Now.Year}.{projectInfo.Version.Major}.{projectInfo.Version.Minor}.r{projectInfo.Version.Revision}",
            }));
            gd    = view.GraphicsDevice;
            cl    = gd.ResourceFactory.CreateCommandList();
            imGui = new ImGuiView(gd, view.Window, gd.MainSwapchain.Framebuffer.OutputDescription, view.Width, view.Height);
            ImGui.GetIO().ConfigWindowsMoveFromTitleBarOnly = true;
        }
Пример #2
0
        public TestCanvas(GraphicsDevice gd, ImGuiView view, Func <Vector2> computeSize) : base(gd, view, computeSize)
        {
            Buffer = dispose.Add(new BufferList <VertexPositionColor>(gd, 6));

            VertexPositionColor[] quadVertices =
            {
                new VertexPositionColor(new Vector2(-150f,  150f), RgbaFloat.Red),
                new VertexPositionColor(new Vector2(150f,   150f), RgbaFloat.Green),
                new VertexPositionColor(new Vector2(-150f, -150f), RgbaFloat.Blue),
                new VertexPositionColor(new Vector2(150f,  -150f), RgbaFloat.Yellow)
            };

            ushort[] quadIndices = { 0, 1, 2, 3 };

            VertexBuffer = Factory.CreateBuffer(new BufferDescription(4 * VertexPositionColor.SizeInBytes, BufferUsage.VertexBuffer | BufferUsage.Dynamic));
            IndexBuffer  = Factory.CreateBuffer(new BufferDescription(4 * sizeof(ushort), BufferUsage.IndexBuffer));
            dispose.Add(VertexBuffer);
            dispose.Add(IndexBuffer);

            ProjMatrix = Factory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer | BufferUsage.Dynamic));
            dispose.Add(ProjMatrix);

            GraphicsDevice.UpdateBuffer(VertexBuffer, 0, quadVertices);
            GraphicsDevice.UpdateBuffer(IndexBuffer, 0, quadIndices);

            VertexLayoutDescription vertexLayout = new VertexLayoutDescription(
                new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2),
                new VertexElementDescription("Color", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float4));

            Layout = Factory.CreateResourceLayout(new ResourceLayoutDescription(
                                                      new ResourceLayoutElementDescription("ProjectionMatrixBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex)));
            dispose.Add(Layout);

            ShaderDescription vertexShaderDesc = new ShaderDescription(
                ShaderStages.Vertex,
                Encoding.UTF8.GetBytes(VertexCode),
                "main");
            ShaderDescription fragmentShaderDesc = new ShaderDescription(
                ShaderStages.Fragment,
                Encoding.UTF8.GetBytes(FragmentCode),
                "main");

            Shaders = dispose.AddArray(Factory.CreateFromSpirv(vertexShaderDesc, fragmentShaderDesc));

            var pipelineDescription = new GraphicsPipelineDescription();

            pipelineDescription.BlendState        = BlendStateDescription.SingleOverrideBlend;
            pipelineDescription.DepthStencilState = new DepthStencilStateDescription(
                depthTestEnabled: true,
                depthWriteEnabled: true,
                comparisonKind: ComparisonKind.LessEqual);
            pipelineDescription.RasterizerState = new RasterizerStateDescription(
                cullMode: FaceCullMode.Front,
                fillMode: PolygonFillMode.Solid,
                frontFace: FrontFace.Clockwise,
                depthClipEnabled: true,
                scissorTestEnabled: false);
            pipelineDescription.PrimitiveTopology = PrimitiveTopology.TriangleList;
            pipelineDescription.ResourceLayouts   = new ResourceLayout[] { Layout };
            pipelineDescription.ShaderSet         = new ShaderSetDescription(
                vertexLayouts: new VertexLayoutDescription[] { vertexLayout },
                shaders: Shaders);
            pipelineDescription.Outputs = Canvas.FrameBuffer.OutputDescription;

            Pipeline = Factory.CreateGraphicsPipeline(pipelineDescription);

            MainResourceSet = Factory.CreateResourceSet(new ResourceSetDescription(Layout, ProjMatrix));
        }
Пример #3
0
        private void InitializeUi()
        {
            //Create ImGui Windows
            var mainmenu = new UIMainMenuBar(new IUIComponent[]
            {
                new UIMenu("File", new IUIComponent[]
                {
                    new UIMenuItem("Open Scene", "CTRL+O"),
                    new UIMenuItem("Open Project", "CTRL+SHIFT+O"),
                    new UIMenuItem("New Scene", "CTRL+N"),
                    new UIMenuItem("New Project", "CTRL+SHIFT+N"),

                    new UIMenuItem("Exit", "ALT+F4", () => view.Close())
                }),
                new UIMenu("Edit", new IUIComponent[]
                {
                    new UIMenuItem("Open Scene", "CTRL+O"),
                    new UIMenuItem("Open Project", "CTRL+SHIFT+O"),
                    new UIMenuItem("New Scene", "CTRL+N"),
                    new UIMenuItem("New Project", "CTRL+SHIFT+N"),

                    new UIMenuItem("Exit", "ALT+F4", () => view.Close())
                }),

                new UIMenu("Windows", new IUIComponent[]
                {
                    new UIMenuItem("Scene", action: () => uihost.Children.Add(new UIWindow("Scene", new IUIComponent[] {  })))
                })
            });

            var sceneWindow = new UIWindow("Scene", new IUIComponent[]
            {
            });
            var gameWindow = new UIWindow("Game", new IUIComponent[]
            {
                new UIMenuBar(new IUIComponent[] { new UIMenu("Status", new IUIComponent[] { new UIMenuItem($"FPS: {ImGui.GetIO().Framerate}") }), }),
            });
            var hierarchyWindow = new UIWindow("Hierarchy", new IUIComponent[]
            {
            });
            var inspectorWindow = new UIWindow("Inspector", new IUIComponent[]
            {
            });
            var projectWindow = new UIWindow("Project", new IUIComponent[]
            {
            });
            var consoleWindow = new UIWindow("Console", new IUIComponent[]
            {
            });

            var pattern = new MIDIPattern();

            projectConnect = new ProjectConnect();
            var pianoRollWindow = UIUtils.CreatePianoRollWindow(projectConnect, pattern, gd, imGui);

            // Initialize imgui UI
            uihost = disposer.Add(new UIHost(new IUIComponent[]
            {
                mainmenu,
                sceneWindow,
                gameWindow,
                hierarchyWindow,
                inspectorWindow,
                projectWindow,
                consoleWindow,
                //pianoRollWindow,
            }));


            frameTimer = new Stopwatch();
            frameTimer.Start();

            hotkeys = new HotkeyHandler <GlobalHotkey>();
        }