schell / gelatin

A nice Haskell graphics API. There's always room for jello.
BSD 3-Clause "New" or "Revised" License
41 stars 4 forks source link

gelatin: Improve geometry generation API feel and performance #28

Open schell opened 6 years ago

schell commented 6 years ago

to uses snoc under the hood, which is O(n^2) - when building lots of geometry the CPU time is unacceptable, eg:

setGeometry $ vertices $ mapM to [ mkvert x y | x <- [0 .. dx], y <- [0 .. dy] ]

For big values of dx and dy It's much faster with something like:

let verts = [ mkvert x y
            | x <- [0 .. dy]
            , y <- [0 .. dx]
            ]
in setRawGeometry $ VUnboxed.singleton $ RawTriangles verts

Maybe this could be fixed by more use of addVertexList or something - but the whole point of the API is that it makes generating geometry easy and hopefully type safe, without necessarily having to dive into Vector.

Think up new wieldy ways of generating geometry that are also fast in CPU time.