public Swapchain CreateSwapchain() { Swapchain swapchain; if (Widget.Backend == GraphicsBackend.OpenGL) { swapchain = Widget.GraphicsDevice.MainSwapchain; } else { // To embed Veldrid in an Eto control, these platform-specific // versions of CreateSwapchain use the technique outlined here: // // https://github.com/mellinoe/veldrid/issues/155 // var source = SwapchainSource.CreateNSView(Control.Handle); var renderSize = RenderSize; swapchain = Widget.GraphicsDevice.ResourceFactory.CreateSwapchain( new SwapchainDescription( source, (uint)renderSize.Width, (uint)renderSize.Height, Widget.GraphicsDeviceOptions.SwapchainDepthFormat, Widget.GraphicsDeviceOptions.SyncToVerticalBlank, Widget.GraphicsDeviceOptions.SwapchainSrgbFormat)); } return(swapchain); }
public override void ViewDidLoad() { base.ViewDidLoad(); // device init GraphicsDeviceOptions options = new GraphicsDeviceOptions(false, null, false, ResourceBindingModel.Improved); #if DEBUG options.Debug = true; #endif SwapchainSource ss = SwapchainSource.CreateNSView(this.View.Handle); SwapchainDescription scd = new SwapchainDescription( ss, width, height, PixelFormat.R32_Float, false); graphicsDevice = GraphicsDevice.CreateMetal(options); swapchain = graphicsDevice.ResourceFactory.CreateSwapchain(ref scd); factory = graphicsDevice.ResourceFactory; // resource init CreateSizeDependentResources(); VertexPosition[] quadVertices = { new VertexPosition(new Vector3(-1, 1, 0)), new VertexPosition(new Vector3(1, 1, 0)), new VertexPosition(new Vector3(-1, -1, 0)), new VertexPosition(new Vector3(1, -1, 0)) }; uint[] quadIndices = new uint[] { 0, 1, 2, 1, 3, 2 }; vertexBuffer = factory.CreateBuffer(new BufferDescription(4 * VertexPosition.SizeInBytes, BufferUsage.VertexBuffer)); indexBuffer = factory.CreateBuffer(new BufferDescription(6 * sizeof(uint), BufferUsage.IndexBuffer)); graphicsDevice.UpdateBuffer(vertexBuffer, 0, quadVertices); graphicsDevice.UpdateBuffer(indexBuffer, 0, quadIndices); commandList = factory.CreateCommandList(); viewLoaded = true; displayTimer = NSTimer.CreateRepeatingTimer(60.0 / 1000.0, Render); displayTimer.Fire(); }
public override void ViewDidMoveToWindow() { base.ViewDidMoveToWindow(); var swapchainSource = SwapchainSource.CreateNSView(Handle); var swapchainDescription = new SwapchainDescription(swapchainSource, (uint)Frame.Width, (uint)Frame.Height, null, true, true); if (_backend == GraphicsBackend.Metal) { GraphicsDevice = GraphicsDevice.CreateMetal(_deviceOptions); } MainSwapchain = GraphicsDevice.ResourceFactory.CreateSwapchain(swapchainDescription); DeviceReady?.Invoke(); _displayLink = new CVDisplayLink(); _displayLink.SetOutputCallback(HandleDisplayLinkOutputCallback); _displayLink.Start(); }