Пример #1
0
        public VeldridHost(string title)
        {
            WindowCreateInfo wci = new WindowCreateInfo
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 1280,
                WindowHeight = 720,
                WindowTitle  = title,
            };

            window          = VeldridStartup.CreateWindow(ref wci);
            window.Resized += () => windowResized = true;
            window.KeyDown += OnKeyDown;
        }
Пример #2
0
        private static void VeldridRunLoop(Sdl2Window window, GraphicsDevice graphicsDevice, Action action)
        {
            while (window.Exists)
            {
                window.PumpEvents();

                if (window.Exists)
                {
                    action();

                    graphicsDevice.SwapBuffers();
                    graphicsDevice.WaitForIdle();
                }
            }
        }
Пример #3
0
        private static unsafe GraphicsDevice CreateMetalGraphicsDevice(
            GraphicsDeviceOptions options,
            Sdl2Window window,
            bool colorSrgb)
        {
            SwapchainSource      source        = GetSwapchainSource(window);
            SwapchainDescription swapchainDesc = new SwapchainDescription(
                source,
                (uint)window.Width, (uint)window.Height,
                options.SwapchainDepthFormat,
                options.SyncToVerticalBlank,
                colorSrgb);

            return(GraphicsDevice.CreateMetal(options, swapchainDesc));
        }
Пример #4
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window);

            textRenderer = new TextRender.TextRenderer(_graphicsDevice);
            text         = new Text(textRenderer, "Hello world!")
            {
                Position = new Vector2(200, 100),
                FontSize = 24,
                Color    = RgbaFloat.White
            };
            text.Initialize();

            text2 = new Text(textRenderer, "Test")
            {
                Position  = new Vector2(400, 150),
                FontSize  = 36,
                FontStyle = FontStyle.Bold,
                FontName  = "Courier New",
                Color     = RgbaFloat.Yellow
            };
            text2.Initialize();

            CreateResources();

            while (window.Exists)
            {
                window.PumpEvents();

                if (window.Exists)
                {
                    Draw();
                    Thread.Sleep(1);
                }
            }

            DisposeResources();
        }
Пример #5
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };

            window = VeldridStartup.CreateWindow(ref windowCI);

            s          = new GShader(window);
            s.fillMode = PolygonFillMode.Solid;
            s.topo     = PrimitiveTopology.PointList;

            List <VertexPositionColour> verts = new List <VertexPositionColour>()
            {
                new VertexPositionColour(new Vector2(0.9f, 0.9f), new RgbaFloat(1, 1, 1, 1)),
                new VertexPositionColour(new Vector2(-0.9f, 0.9f), new RgbaFloat(1, 1, 1, 1)),
                new VertexPositionColour(new Vector2(-0.9f, -0.9f), new RgbaFloat(1, 1, 1, 1)),
                new VertexPositionColour(new Vector2(0.9f, -0.9f), new RgbaFloat(1, 1, 1, 1))
            };

            //INITIALISE VERTEX SET HERE


            s.verteces = verts;
            s.GenerateIndeces();
            s.CreateResources();

            Thread vertexThread = new Thread(new ThreadStart(WaitForVertex));

            vertexThread.Start();

            while (window.Exists)
            {
                window.PumpEvents();
                if (updateFromThread1)
                {
                    AddVertex(/*INSERT FUNCTION TO GENERATE ONE RANDOM VERTEX HERE*/);
                    updateFromThread1 = false;
                }
                s.Draw();
            }
            s.DisposeResources();
        }
Пример #6
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 1920,
                Y            = 100,
                WindowWidth  = 1920,
                WindowHeight = 1920,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, GraphicsBackend.OpenGL);

            CreateResources(window);

            var pty         = new LinuxPty();
            var readStream  = new ConsoleLoggingStream(pty.ReadStream, "READ");
            var writeStream = new ConsoleLoggingStream(pty.WriteStream, "WRIT");

            var charsWidth  = (int)(window.Width / (float)_fontAtlas.CellWidth);
            var charsHeight = (int)(window.Height / (float)_fontAtlas.CellHeight);

            pty.SetSize(charsWidth, charsHeight);

            _tokenizer = new OutputTokenizer(_textLayout);

            var inputProcessor = new InputKeyStreamer {
                OutStream = writeStream
            };

#pragma warning disable 4014
            PipePtyToScreen(readStream);
#pragma warning restore 4014

            while (window.Exists)
            {
                var input = window.PumpEvents();
                inputProcessor.ProcessToStream(input);

                if (window.Exists)
                {
                    Draw();
                }
            }

            DisposeResources();
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameWindow"/> class.
        /// </summary>
        /// <param name="title">The title.</param>
        public GameWindow(string title)
        {
            var windowCreateInfo = new WindowCreateInfo
            {
                X            = Sdl2Native.SDL_WINDOWPOS_CENTERED,
                Y            = Sdl2Native.SDL_WINDOWPOS_CENTERED,
                WindowWidth  = Configuration.ChunkWidth * Configuration.TileSize,
                WindowHeight = Configuration.ChunkHeight * Configuration.TileSize,
                WindowTitle  = title,
            };

            this.window           = VeldridStartup.CreateWindow(ref windowCreateInfo);
            this.window.Resizable = false;
            this.window.Resized  += () => { this.windowResized = true; };
            this.window.KeyDown  += this.OnKeyDown;
        }
Пример #8
0
        public static void CreateWindowAndGraphicsDevice(
            WindowProps windowProps,
            GraphicsDeviceOptions deviceOptions,
            GraphicsBackend preferredBackend,
            out Sdl2Window window,
            out GraphicsDevice gd)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(typeof(WindowStartup));
            using (Profiler sdlProfiler = new Profiler("SDL_Init"))
#endif
            Sdl2Native.SDL_Init(SDLInitFlags.Video);

            window = CreateWindow(ref windowProps, preferredBackend);
            gd     = CreateGraphicsDevice(window, deviceOptions, preferredBackend);
        }
Пример #9
0
        public static void Main(string[] args)
        {
            window = CreateWindow();

            Initialize();

            while (window.Exists)
            {
                inputSnapshot = window.PumpEvents();

                Update();
                Draw();
            }

            Dispose();
        }
Пример #10
0
        public static unsafe GraphicsDevice CreateVulkanGraphicsDevice(
            GraphicsDeviceOptions options,
            Sdl2Window window,
            bool colorSrgb)
        {
            SwapchainDescription scDesc = new SwapchainDescription(
                GetSwapchainSource(window),
                (uint)window.Width,
                (uint)window.Height,
                options.SwapchainDepthFormat,
                options.SyncToVerticalBlank,
                colorSrgb);
            GraphicsDevice gd = GraphicsDevice.CreateVulkan(options, scDesc);

            return(gd);
        }
Пример #11
0
        public IDrawspace GetDrawspace(IRect2D subRect)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = (int)subRect.Position.X,
                Y            = (int)subRect.Position.Y,
                WindowWidth  = (int)subRect.Size.X,
                WindowHeight = (int)subRect.Size.Y,
                WindowTitle  = "Veldrid Tutorial"
            };
            Sdl2Window _window = VeldridStartup.CreateWindow(ref windowCI);

            _windowList.Add(_window);
            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(_window);
            return(new VeldridDrawspace(_window));
        }
Пример #12
0
        public static void CreateWindowAndGraphicsDevice(
            WindowCreateInfo windowCI,
            GraphicsDeviceOptions deviceOptions,
            GraphicsBackend preferredBackend,
            out Sdl2Window window,
            out GraphicsDevice gd)
        {
            Sdl2Native.SDL_Init(SDLInitFlags.Video);
            if (preferredBackend == GraphicsBackend.OpenGL || preferredBackend == GraphicsBackend.OpenGLES)
            {
                SetSDLGLContextAttributes(deviceOptions, preferredBackend);
            }

            window = CreateWindow(ref windowCI);
            gd     = CreateGraphicsDevice(window, deviceOptions, preferredBackend);
        }
Пример #13
0
        public RenderView()
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "Veldrid Tutorial"
            };

            Window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDeviceOptions options = new GraphicsDeviceOptions
            {
                PreferStandardClipSpaceYDirection = true,
                PreferDepthRangeZeroToOne         = true
            };

            void CreateAndAddCursor(SDL_SystemCursor type)
            {
                var cursor = Sdl2Native.SDL_CreateSystemCursor(type);

                cursorMap.Add(type, cursor);
            }

            CreateAndAddCursor(SDL_SystemCursor.Arrow);
            CreateAndAddCursor(SDL_SystemCursor.Crosshair);
            CreateAndAddCursor(SDL_SystemCursor.Hand);
            CreateAndAddCursor(SDL_SystemCursor.IBeam);
            CreateAndAddCursor(SDL_SystemCursor.No);
            CreateAndAddCursor(SDL_SystemCursor.SizeAll);
            CreateAndAddCursor(SDL_SystemCursor.SizeNESW);
            CreateAndAddCursor(SDL_SystemCursor.SizeNS);
            CreateAndAddCursor(SDL_SystemCursor.SizeNWSE);
            CreateAndAddCursor(SDL_SystemCursor.SizeWE);
            CreateAndAddCursor(SDL_SystemCursor.Wait);
            CreateAndAddCursor(SDL_SystemCursor.WaitArrow);

            GraphicsDevice = dispose.Add(VeldridStartup.CreateGraphicsDevice(Window, options, GraphicsBackend.Direct3D11));

            Window.Resized += () =>
            {
                GraphicsDevice.MainSwapchain.Resize((uint)Window.Width, (uint)Window.Height);
            };
        }
Пример #14
0
        public static void Main(string[] args)
        {
            window          = CreateWindow();
            window.Resized += () => graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height);

            Initialize();

            while (window.Exists)
            {
                inputSnapshot = window.PumpEvents();

                Update();
                Draw();
            }

            Dispose();
        }
Пример #15
0
        /// <summary>
        /// Sets per-frame data based on the associated window.
        /// This is called by Update(float).
        /// </summary>
        private void SetPerFrameImGuiData(float deltaSeconds)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(GetType());
#endif
            ImGuiIOPtr io = ImGui.GetIO();
            io.DisplaySize = new Vector2(
                windowWidth / scaleFactor.X,
                windowHeight / scaleFactor.Y);
            io.DisplayFramebufferScale = scaleFactor;
            io.DeltaTime = deltaSeconds;             // DeltaTime is in seconds.

            ImGuiPlatformIOPtr plIo          = ImGui.GetPlatformIO();
            Sdl2Window         mainSdlWindow = mainWindow.SdlWindow;
            plIo.MainViewport.Pos  = new Vector2(mainSdlWindow.X, mainSdlWindow.Y);
            plIo.MainViewport.Size = new Vector2(mainSdlWindow.Width, mainSdlWindow.Height);
        }
Пример #16
0
        public VeldridStartupWindow(string title, ViewerOptions options)
        {
            _options = options;
            var wci = new WindowCreateInfo
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = 1280,
                WindowHeight       = 720,
                WindowTitle        = title,
                WindowInitialState = _options.WindowState
            };

            _window          = VeldridStartup.CreateWindow(ref wci);
            _window.Resized += () => { _windowResized = true; };
            _window.KeyDown += OnKeyDown;
        }
Пример #17
0
        public MachWindow()
        {
            window = VeldridStartup.CreateWindow(new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "MachSeven"
            });

            GraphicsDeviceOptions options = new GraphicsDeviceOptions
            {
                PreferStandardClipSpaceYDirection = true,
                PreferDepthRangeZeroToOne         = true
            };
        }
Пример #18
0
        protected override void CreateWindow_Internal()
        {
            TickFunction WindowTick = new TickFunction
            {
                TickFunc = (DeltaTime) => {
                    var Snapshot = Window.PumpEvents();
                    VeldridInputSource.LastInputSnapshot(Snapshot);
                },
                TickPriority = TickFunction.HighPriority,
                CanTick      = true,
            };

            IEngine.Instance.GameThreadTickManager.AddTick(WindowTick);

            Veldrid.StartupUtilities.WindowCreateInfo windowCI = new Veldrid.StartupUtilities.WindowCreateInfo
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = (int)ScreenSize.X,
                WindowHeight       = (int)ScreenSize.Y,
                WindowInitialState = Veldrid.WindowState.Normal,
                WindowTitle        = "Intro",
            };

            Window               = VeldridStartup.CreateWindow(ref windowCI);
            Window.KeyDown      += VeldridInputSource.OnWindowKeyEvent;
            Window.KeyUp        += VeldridInputSource.OnWindowKeyEvent;
            Window.MouseDown    += VeldridInputSource.OnWindowMouseEvent;
            Window.MouseUp      += VeldridInputSource.OnWindowMouseEvent;
            Window.Resized      += Window_Resized;
            Window.Closing      += Window_Closing;
            Window.Closed       += Window_Closed;
            Window.LimitPollRate = true;


            Veldrid.GraphicsDeviceOptions options = new Veldrid.GraphicsDeviceOptions()
            {
                PreferStandardClipSpaceYDirection = true,
                Debug = false,
            };

            GraphicsDevice = VeldridStartup.CreateVulkanGraphicsDevice(options, Window);


            ConstructVeldridResources();
        }
Пример #19
0
        static void Main(string[] args)
        {
            WindowCreateInfo windowCi = new WindowCreateInfo()
            {
                X                  = 100,
                Y                  = 100,
                WindowWidth        = 800,
                WindowHeight       = 600,
                WindowTitle        = "Pentagonal Hexecontahedron",
                WindowInitialState = WindowState.Normal
            };
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                true,
                PixelFormat.R16_UNorm,
                true,
                ResourceBindingModel.Improved,
                true,
                true);

            _window          = VeldridStartup.CreateWindow(ref windowCi);
            _window.Resized += () => { _isResized = true; };

            _window.KeyUp += keyArg =>
            {
                if (keyArg.Key == Key.Escape)
                {
                    _window.Close();
                }
            };
            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(_window, options, GraphicsBackend.Vulkan);

            CreateResources();

            while (_window.Exists)
            {
                InputSnapshot snapshot = _window.PumpEvents();
                if (snapshot.IsMouseDown(MouseButton.Left))
                {
                    _rotate += 0.01f;
                    ViewProjectionUpdate();
                }
                Draw();
            }

            DisposeResources();
        }
Пример #20
0
        public static void Run()
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = Width,
                WindowHeight = Height,
                WindowTitle  = "Veldrid Tutorial"
            };

            Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

            GraphicsDeviceOptions options = new GraphicsDeviceOptions
            {
                PreferStandardClipSpaceYDirection = true,
                PreferDepthRangeZeroToOne         = true,
                SwapchainDepthFormat = PixelFormat.R16_UNorm,
                Debug = false
            };

            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, options);

            //_graphicsDevice = VeldridStartup.CreateDefaultOpenGLGraphicsDevice(options, window, GraphicsBackend.OpenGL);

            //_graphicsDevice = VeldridStartup.CreateVulkanGraphicsDevice(options, window);

            //_graphicsDevice = VeldridStartup.CreateDefaultD3D11GraphicsDevice(options, window);

            window.Resized += () => _graphicsDevice.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);

            _texData  = new ImageSharpTexture("image.png");
            _vertices = GetCubeVertices();
            _indices  = GetCubeIndices();

            CreateResources();

            while (window.Exists)
            {
                window.PumpEvents();
                Draw();
            }

            DisposeResources();
        }
Пример #21
0
        public static void UpdateFrameInput(Sdl2Window window, InputSnapshot snapshot)
        {
            FrameSnapshot = snapshot;
            _newKeysThisFrame.Clear();
            _newMouseButtonsThisFrame.Clear();

            window.CursorVisible = !LockMouse;

            if (LockMouse)
            {
                window.SetMousePosition(window.Width / 2, window.Height / 2);
                MousePosition = new Vector2(window.Width / 2, window.Height / 2);
                MouseDelta    = snapshot.MousePosition - MousePosition;
            }
            else
            {
                var newPosition = snapshot.MousePosition;
                MouseDelta    = newPosition - MousePosition;
                MousePosition = newPosition;
            }
            for (int i = 0; i < snapshot.KeyEvents.Count; i++)
            {
                KeyEvent ke = snapshot.KeyEvents[i];
                if (ke.Down)
                {
                    KeyDown(ke.Key);
                }
                else
                {
                    KeyUp(ke.Key);
                }
            }
            for (int i = 0; i < snapshot.MouseEvents.Count; i++)
            {
                MouseEvent me = snapshot.MouseEvents[i];
                if (me.Down)
                {
                    MouseDown(me.MouseButton);
                }
                else
                {
                    MouseUp(me.MouseButton);
                }
            }
        }
Пример #22
0
        public Renderable(string title, Resolution windowSize, GraphicsDeviceOptions graphicsDeviceOptions, RenderOptions renderOptions)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo()
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = windowSize.Horizontal,
                WindowHeight = windowSize.Vertical,
                WindowTitle  = title
            };

            _contextWindow = VeldridStartup.CreateWindow(ref windowCI);

            if (renderOptions.UsePreferredGraphicsBackend)
            {
                _graphicsDevice = VeldridStartup.CreateGraphicsDevice(_contextWindow, graphicsDeviceOptions, renderOptions.PreferredGraphicsBackend);
            }
            else
            {
                _graphicsDevice = VeldridStartup.CreateGraphicsDevice(_contextWindow, graphicsDeviceOptions);
            }

            _renderOptions       = renderOptions;
            _contextWindow.Title = $"{title} / {_graphicsDevice.BackendType.ToString()}";
            _factory             = new DisposeCollectorResourceFactory(_graphicsDevice.ResourceFactory);
            _commandList         = _factory.CreateCommandList();

            _sceneRuntimeState = new SceneRuntimeDescriptor();

            _modelPNTTBDescriptorList = new List <ModelRuntimeDescriptor <VertexPositionNormalTextureTangentBitangent> >();
            _modelPNDescriptorList    = new List <ModelRuntimeDescriptor <VertexPositionNormal> >();
            _modelPTDescriptorList    = new List <ModelRuntimeDescriptor <VertexPositionTexture> >();
            _modelPCDescriptorList    = new List <ModelRuntimeDescriptor <VertexPositionColor> >();
            _modelPDescriptorList     = new List <ModelRuntimeDescriptor <VertexPosition> >();

            PNTTBRuntimeGeometry = new GeometryDescriptor <VertexPositionNormalTextureTangentBitangent>();
            PNRuntimeGeometry    = new GeometryDescriptor <VertexPositionNormal>();
            PTRuntimeGeometry    = new GeometryDescriptor <VertexPositionTexture>();
            PCRuntimeGeometry    = new GeometryDescriptor <VertexPositionColor>();
            PRuntimeGeometry     = new GeometryDescriptor <VertexPosition>();

            // Tick every millisecond
            _frameTimer = new FrameTimer(1.0);
            _running    = false;
        }
Пример #23
0
        public VeldridDrawspace(Sdl2Window window)
        {
            _window         = window;
            _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window);
            Factory         = _graphicsDevice.ResourceFactory;
            ShaderDescription vertexShaderDesc = new ShaderDescription(
                ShaderStages.Vertex,
                Encoding.UTF8.GetBytes(VertexCode),
                "main");
            ShaderDescription fragmentShaderDesc = new ShaderDescription(
                ShaderStages.Fragment,
                Encoding.UTF8.GetBytes(FragmentCode),
                "main");

            _shaders = Factory.CreateFromSpirv(vertexShaderDesc, fragmentShaderDesc);
            // imag3e layout
            // Create pipeline
            GraphicsPipelineDescription pipelineDescription = new GraphicsPipelineDescription();

            pipelineDescription.BlendState        = BlendStateDescription.SingleOverrideBlend;
            pipelineDescription.DepthStencilState = new DepthStencilStateDescription(
                depthTestEnabled: true,
                depthWriteEnabled: true,
                comparisonKind: ComparisonKind.LessEqual);
            pipelineDescription.RasterizerState = new RasterizerStateDescription(
                cullMode: FaceCullMode.Back,
                fillMode: PolygonFillMode.Solid,
                frontFace: FrontFace.Clockwise,
                depthClipEnabled: true,
                scissorTestEnabled: false);
            pipelineDescription.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
            pipelineDescription.ResourceLayouts   = System.Array.Empty <ResourceLayout>();
            VertexLayoutDescription vertexLayout = new VertexLayoutDescription(
                new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2),
                new VertexElementDescription("Color", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float4));

            pipelineDescription.ShaderSet = new ShaderSetDescription(
                vertexLayouts: new VertexLayoutDescription[] { vertexLayout },
                shaders: _shaders);
            pipelineDescription.Outputs = _graphicsDevice.SwapchainFramebuffer.OutputDescription;

            _pipeline = Factory.CreateGraphicsPipeline(pipelineDescription);

            _commandList = Factory.CreateCommandList();
        }
Пример #24
0
        private unsafe void SetupPlatformIo(Sdl2Window sdlWindow)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(GetType());
#endif
            ImGuiStylePtr style = ImGui.GetStyle();
            style.WindowRounding = 0.0f;
            style.Colors[(int)ImGuiCol.WindowBg].W = 1.0f;

            createWindow       = PlatformCreateWindow;
            destroyWindow      = PlatformDestroyWindow;
            showWindow         = PlatformShowWindow;
            getWindowPosition  = PlatformGetWindowPosition;
            setWindowPosition  = PlatformSetWindowPosition;
            getWindowSize      = PlatformGetWindowSize;
            setWindowSize      = PlatformSetWindowSize;
            setWindowTitle     = PlatformSetWindowTitle;
            getWindowFocus     = PlatformGetWindowFocus;
            setWindowFocus     = PlatformSetWindowFocus;
            getWindowMinimized = PlatformGetWindowMinimized;
            setWindowAlpha     = PlatformSetWindowAlpha;

            createVulkanSurface = PlatformCreateVkSurface;

            ImGuiPlatformIOPtr plIo = ImGui.GetPlatformIO();
            plIo.NativePtr->Platform_CreateWindow       = Marshal.GetFunctionPointerForDelegate(createWindow);
            plIo.NativePtr->Platform_DestroyWindow      = Marshal.GetFunctionPointerForDelegate(destroyWindow);
            plIo.NativePtr->Platform_ShowWindow         = Marshal.GetFunctionPointerForDelegate(showWindow);
            plIo.NativePtr->Platform_GetWindowPos       = Marshal.GetFunctionPointerForDelegate(getWindowPosition);
            plIo.NativePtr->Platform_SetWindowPos       = Marshal.GetFunctionPointerForDelegate(setWindowPosition);
            plIo.NativePtr->Platform_GetWindowSize      = Marshal.GetFunctionPointerForDelegate(getWindowSize);
            plIo.NativePtr->Platform_SetWindowSize      = Marshal.GetFunctionPointerForDelegate(setWindowSize);
            plIo.NativePtr->Platform_SetWindowTitle     = Marshal.GetFunctionPointerForDelegate(setWindowTitle);
            plIo.NativePtr->Platform_GetWindowMinimized = Marshal.GetFunctionPointerForDelegate(getWindowMinimized);
            plIo.NativePtr->Platform_GetWindowFocus     = Marshal.GetFunctionPointerForDelegate(getWindowFocus);
            plIo.NativePtr->Platform_SetWindowFocus     = Marshal.GetFunctionPointerForDelegate(setWindowFocus);
            plIo.NativePtr->Platform_SetWindowAlpha     = Marshal.GetFunctionPointerForDelegate(setWindowAlpha);
            plIo.NativePtr->Platform_CreateVkSurface    = Marshal.GetFunctionPointerForDelegate(createVulkanSurface);

            UpdateMonitors();

            ImGuiViewportPtr mainViewport = plIo.MainViewport;
            mainViewport.PlatformHandle   = sdlWindow.Handle;
            mainViewport.PlatformUserData = (IntPtr)mainWindow.GcHandle;
        }
Пример #25
0
        public VeldridStartupWindow(string title)
        {
            WindowCreateInfo wci = new WindowCreateInfo
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 640,
                WindowHeight = 360,
                WindowTitle  = title,
            };

            _window          = VeldridStartup.CreateWindow(ref wci);
            _window.Resized += () =>
            {
                _windowResized = true;
            };
            _window.KeyDown += OnKeyDown;
        }
Пример #26
0
        public DesktopWindow(string title, uint width, uint height)
        {
            const int centered = Sdl2Native.SDL_WINDOWPOS_CENTERED;

            Sdl2Native.SDL_Init(SDLInitFlags.Video | SDLInitFlags.GameController);
            _window = new Sdl2Window(title,
                                     centered, centered,
                                     (int)width, (int)height,
                                     SDL_WindowFlags.OpenGL,
                                     threadedProcessing: false
                                     );
            SwapchainSource = VeldridStartup.GetSwapchainSource(_window);

            _arrow  = Sdl2Native.SDL_CreateSystemCursor(SDL_SystemCursor.Arrow);
            _hand   = Sdl2Native.SDL_CreateSystemCursor(SDL_SystemCursor.Hand);
            _wait   = Sdl2Native.SDL_CreateSystemCursor(SDL_SystemCursor.Wait);
            _cursor = SystemCursor.Arrow;
        }
Пример #27
0
        private static void VeldridInit(out Sdl2Window window, out GraphicsDevice graphicsDevice)
        {
            WindowCreateInfo windowCI = new WindowCreateInfo
            {
                X            = 100,
                Y            = 100,
                WindowWidth  = 960,
                WindowHeight = 540,
                WindowTitle  = "OpenWheels Text Rendering"
            };

            window = VeldridStartup.CreateWindow(ref windowCI);

            // no debug, no depth buffer and enable v-sync
            var gdo = new GraphicsDeviceOptions(false, null, syncToVerticalBlank: true);

            graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, gdo, GraphicsBackend.OpenGL);
        }
Пример #28
0
        private static void VeldridRunLoop(Sdl2Window window, GraphicsDevice gd, VRContext vr, Action action)
        {
            while (window.Exists)
            {
                var input = window.PumpEvents();

                if (!window.Exists)
                {
                    continue;
                }

                action();
                vr.SubmitFrame();

                _MirrorTexMgr.Run(MirrorTextureEyeSource.BothEyes);
                gd.SwapBuffers();
            }
        }
Пример #29
0
        static void Main(string[] args)
        {
            Console.SetOut(Logic.console);
            Trace.Listeners.Add(new TextWriterTraceListener(Logic.console));

            model = Logic.MakeData(args[0]);

            window = Utilities.MakeWindow(720, 720);
            Logic.Init(window);
            window.Resized += Resize;

            FPS fpsCounter = new FPS();

            device = VeldridStartup.CreateGraphicsDevice(window, new GraphicsDeviceOptions(DebugMode, null, false, ResourceBindingModel.Improved));
            CreateResources();
            DateTime start = DateTime.Now;
            TimeSpan delta = TimeSpan.FromSeconds(0);

            Logic.Heading      = Logic.Heading;
            Logic.Position     = Logic.Position;
            window.WindowState = WindowState.Maximized;

            while (window.Exists)
            {
                if (loader != null && loader.IsCompleted)
                {
                    model             = loader.Result;
                    compute["data"]   = model.StructBuffer();
                    compute["values"] = model.ValueTexture();
                    compute.Update(factory);
                    loader = null;
                }
                delta = DateTime.Now - start;
                start = DateTime.Now;

                var input = window.PumpEvents();
                Logic.Update(delta, input);
                Logic.MakeGUI(fpsCounter.Frames);
                Draw();
                fpsCounter.Frame();
            }
            ImGui.DestroyContext();
            DisposeResources();
        }
Пример #30
0
        public static GraphicsDevice CreateGraphicsDevice(
            Sdl2Window window,
            GraphicsDeviceOptions options,
            GraphicsBackend preferredBackend)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(typeof(WindowStartup));
#endif
            switch (preferredBackend)
            {
            case GraphicsBackend.Direct3D11:
#if !EXCLUDE_D3D11_BACKEND
                return(CreateDefaultD3D11GraphicsDevice(options, window));
#else
                throw new VeldridException("D3D11 support has not been included in this configuration of Veldrid");
#endif
            case GraphicsBackend.Vulkan:
#if !EXCLUDE_VULKAN_BACKEND
                return(CreateVulkanGraphicsDevice(options, window));
#else
                throw new VeldridException("Vulkan support has not been included in this configuration of Veldrid");
#endif
            case GraphicsBackend.OpenGL:
#if !EXCLUDE_OPENGL_BACKEND
                return(CreateDefaultOpenGLGraphicsDevice(options, window, preferredBackend));
#else
                throw new VeldridException("OpenGL support has not been included in this configuration of Veldrid");
#endif
            case GraphicsBackend.Metal:
#if !EXCLUDE_METAL_BACKEND
                return(CreateMetalGraphicsDevice(options, window));
#else
                throw new VeldridException("Metal support has not been included in this configuration of Veldrid");
#endif
            case GraphicsBackend.OpenGLES:
#if !EXCLUDE_OPENGL_BACKEND
                return(CreateDefaultOpenGLGraphicsDevice(options, window, preferredBackend));
#else
                throw new VeldridException("OpenGL support has not been included in this configuration of Veldrid");
#endif
            default:
                throw new VeldridException("Invalid GraphicsBackend: " + preferredBackend);
            }
        }