Closed RaminHAL9001 closed 5 years ago
Sorry, I accidentally created this issue,
I have edited and re-opened this issue. Sorry about the confusion.
The function you seek is execStateT, runStateT or evalStateT. runDrawContext
is just a convenience function that allocate and freeze the image, if you don't need theses steps, just execute the monad transformer.
For context, the current implementation of runDrawContext:
runDrawContext width height background drawing = do
buff <- M.new (width * height * componentCount background)
let mutable = MutableImage width height buff
fillImageWith mutable background
img <- execStateT drawing mutable
unsafeFreezeImage img
I would like it if I could allocate my own
MutableImage
withnewMutableImage
and retain a copy of the mutable image between calls torunDrawContext
. This will allow me to allocate an IOVector within my Haskell program that I can pass to a low-level C language API just one time. This would also allow users of this library to manage their own memory, without being forced to allocate+freeze an image after every rendering step, taking pressure off of the allocator and garbage collector.So I propose a
runDrawContextOnIOVector
function which takes aMutableImage
which stores an IOVector internally, and basically works the same asrunDrawContext
but does not freeze the vector, rather it simply updates the IOVector in place.I may be able to write this code myself, if I have time, and submit a pull request. But I thought I would open an issue first to see if you would be interested in including such a feature. I am not sure if the types in the JuicyPixels library would allow for this feature as I described it, but I can investigate.