public void RenderCl(OpenCLProxy clProxy) { if (clProxy.HardwareAccelerationEnabled) { clProxy.RunKernel(_computeKernel, RenderUtils.ScreenArea); } else { int totalSize = RenderUtils.ScreenArea; for (int i = 0; i < totalSize; i++) { _kernel.Run(clProxy.ReadIntBuffer("image", totalSize), 0, 0, 0, 0, 0, 0, 0, 0, 0); } _kernel.Finish(); } }
/// <summary> /// Load GPU kernels for planet rendering /// </summary> private void LoadKernels() { try { bool useSoftware = (_renderingType == RenderingType.OpenCLSoftware); _gpuClear = new GpuClear(); _clProxy = new OpenCLProxy(useSoftware); if (Directory.Exists("Kernels")) { KernelManager.GenerateKernels("Kernels"); } else { KernelManager.GenerateKernels("../../Kernels"); } _clProxy.CreateIntArgument("resX", RenderUtils.ScreenWidth); _clProxy.CreateIntArgument("resY", RenderUtils.ScreenHeight); _clProxy.CreateDoubleArgument("cameraLeft", 0); _clProxy.CreateDoubleArgument("cameraTop", 0); _clProxy.CreateDoubleArgument("cameraWidth", 0); _clProxy.CreateDoubleArgument("cameraHeight", 0); _clProxy.CreateDoubleArgument("sunNormalX", 0); _clProxy.CreateDoubleArgument("sunNormalY", 0); _clProxy.CreateDoubleArgument("rotation", 0); _clProxy.CreateIntBuffer("image", new int[RenderUtils.ScreenArea], ComputeMemoryFlags.UseHostPointer); _gpuClear.Load(_clProxy); foreach (IGpuRenderable renderable in _massiveBodies) { renderable.Load(_clProxy); } } catch (Exception) { _renderingType = RenderingType.GDIPlus; } }
public void RenderCl(OpenCLProxy clProxy, RectangleD cameraBounds, IPhysicsBody sun) { RectangleD bounds = ComputeBoundingBox(); // Not in range easy return if (!cameraBounds.IntersectsWith(bounds)) { return; } DVector2 sunNormal = DVector2.Zero; if (sun != null) { sunNormal = sun.Position - Position; sunNormal.Normalize(); } var normalizedPosition = new DVector2(cameraBounds.X - Position.X, cameraBounds.Y - Position.Y); if (clProxy.HardwareAccelerationEnabled) { clProxy.UpdateDoubleArgument("cameraLeft", normalizedPosition.X); clProxy.UpdateDoubleArgument("cameraTop", normalizedPosition.Y); clProxy.UpdateDoubleArgument("cameraWidth", cameraBounds.Width); clProxy.UpdateDoubleArgument("cameraHeight", cameraBounds.Height); clProxy.UpdateDoubleArgument("sunNormalX", sunNormal.X); clProxy.UpdateDoubleArgument("sunNormalY", sunNormal.Y); clProxy.UpdateDoubleArgument("rotation", Rotation); clProxy.RunKernel(_computeKernel, RenderUtils.ScreenArea); } else { int totalSize = RenderUtils.ScreenArea; for (int i = 0; i < totalSize; i++) { Kernel.Run(clProxy.ReadIntBuffer("image", totalSize), RenderUtils.ScreenWidth, RenderUtils.ScreenHeight, normalizedPosition.X, normalizedPosition.Y, cameraBounds.Width, cameraBounds.Height, sunNormal.X, sunNormal.Y, Rotation); } Kernel.Finish(); } }
public void Load(OpenCLProxy clProxy) { _kernel = new ClearKernel(); _computeKernel = clProxy.CreateKernel(_kernel); }
public void Load(OpenCLProxy clProxy) { if (Kernel != null) { _computeKernel = clProxy.CreateKernel(Kernel); } }