public Bitmap Render(Rendering.ExecutionOptions options, Action <string> log) { try { var result = new Bitmap(options.Width, options.Height); int width = options.Width; int height = options.Height; log("Initializing and copying data to GPU memory"); int[,] iterations = new int[height, width]; var dev_iterations = gpu.CopyToDevice(iterations); var gridSize = new dim3(height, width); var blockSize = BlockSize; var minX = (float)options.MinX; var maxX = (float)options.MaxX; var minY = (float)options.MinY; var maxY = (float)options.MaxY; var stepX = (maxX - minX) / ((float)width); var stepY = (maxY - minY) / ((float)height); log("Launching Mandelbrot calculations"); gpu.Launch(gridSize, blockSize, "CalculateMandelbrot", minX, maxY, stepX, stepY, dev_iterations); log("Mandelbrot calculations done, fetching results from GPU memory"); gpu.CopyFromDevice(dev_iterations, iterations); log("Generating the final image"); Rendering.fastDrawBitmap(result, iterations); return(result); } finally { gpu.FreeAll(); } }
private void RegenerateImage() { this.txtMinX.Text = currentMinX.ToString("0.0######"); this.txtMaxX.Text = currentMaxX.ToString("0.0######"); this.txtMinY.Text = currentMinY.ToString("0.0######"); this.txtMaxY.Text = currentMaxY.ToString("0.0######"); this.btnGenerate.Enabled = false; this.imageBox.Enabled = false; this.btnReset.Enabled = false; AppendLogLine("Rendering..."); timer.Reset(); timer.Start(); var executionOptions = new Rendering .ExecutionOptions( (int)numDegreeParallel.Value, (int)(imageBox.Width * 1.5), (int)(imageBox.Height * 1.5), currentMinX, currentMaxX, currentMinY, currentMaxY); if (rdioGPU.Checked) { imageBox.Image = renderer.Render(executionOptions, AppendLogLine); } else if (rdioCpu.Checked) { imageBox.Image = Rendering.renderFinal(executionOptions, AppendLogLine); } timer.Stop(); AppendLogLine("Rendering took " + timer.Elapsed); this.btnGenerate.Enabled = true; this.imageBox.Enabled = true; this.btnReset.Enabled = true; }