Esempio n. 1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            await Init();

            GpuFence fence             = Device.DefaultQueue.CreateFence();
            UInt64   currentFenceValue = 0;

            while (true)
            {
                if (SwapChain == null)
                {
                    SwapChainDescriptor = new GpuSwapChainDescriptor(GpuTextureFormat.BGRA8UNorm, (uint)GpuView.Width, (uint)GpuView.Height);
                    SwapChain           = Device.ConfigureSwapChainForSwapChainPanel(SwapChainDescriptor, GpuView);
                    DepthTexture        = Device.CreateTexture(new GpuTextureDescriptor(new GpuExtend3DDict {
                        Width = SwapChainDescriptor.Width, Height = SwapChainDescriptor.Height, Depth = 1
                    }, GpuTextureFormat.Depth24PlusStencil8, GpuTextureUsageFlags.OutputAttachment));
                    CubeTexture = Device.CreateTexture(new GpuTextureDescriptor(new GpuExtend3DDict {
                        Width = SwapChainDescriptor.Width, Height = SwapChainDescriptor.Height, Depth = 1
                    }, GpuTextureFormat.BGRA8UNorm, GpuTextureUsageFlags.Sampled | GpuTextureUsageFlags.CopyDst));
                    UniformBindGroup = Device.CreateBindGroup(new GpuBindGroupDescriptor(UniformBindGroupLayout, new GpuBindGroupEntry[]
                    {
                        new GpuBindGroupEntry(0, new GpuBufferBinding(UniformBuffer, UniformBufferSize)),
                        new GpuBindGroupEntry(1, Sampler),
                        new GpuBindGroupEntry(2, CubeTexture.CreateView())
                    }));
                }
                DrawFrame();
                var fenceValueWaitFor = ++currentFenceValue;
                Device.DefaultQueue.Signal(fence, fenceValueWaitFor);
                await fence.OnCompletionAsync(fenceValueWaitFor);
            }
        }