Reputation: 205
as an exercise I'm trying to render the Mandelbrot set using Haskell. I'm using gloss to display the result. So far I got the math correct, and displaying works. At the moment I generate a [[Word8]] which represents the iterations it took for each pixel to run to infinity and convert that to a ByteString, which I use to construct a gloss Picture, which I display. It works all fine and dandy and up to a resolution of a couple 100 pixels as width and height it goes reasonably fast, but then it takes way to long. So, to change that I am now trying to use accelerate to use the GPU to render, but I just don't have any idea what to do. It starts with what library to use. Plain accelerate? gloss-accelerate? gloss-raster-accelerate? I think, I have to use the last one. In the module Graphics.Gloss.Accelerate.Raster.Array a function makePicture exists, which I think I have to use, but I can't make sense of all the parameters and I haven't found a lot of documentation.
Could somebody explain the makePicture funktion to me, or at least point me to somewhere it is a bit more explained. A working example, which I can adjust to my case would be nice.
Upvotes: 1
Views: 209
Reputation: 1
You can have a look at the mandelbrot example from the github example directory from Accelerate. That one uses the accelerate and accelerate-gloss package. To give an idea of how you can program a Mandelbrot in Accelerate, there is this tutorial.
And more specific on the question of the makePicture
function.
It has 5 arguments
Render
the world that was given. When using the GPU, you should use run1
from the accelerate-llvm-ptx
package.Arrays world => (Acc world -> Acc (Array DIM2 Colour))
. Thus given a function with some parameters, where the parameters should be Accelerate Arrays
. Probably a tuple of scalars in your case, so you can indicate the range of the image you want to display. The resulting array is a matrix that needs to be of type Colour
(A tuple of 4 floats). My guess is that the dimension of the resulting array should correspond with the pixel width and pixel height you gave as arguments.world
(i.e. without Acc
in front of it). The parameters that are given to the function of the fourth argument.After that, it should produce a Gloss Picture
.
Upvotes: 0