androidallocationrenderscript

Renderscript how to init a buffer from a 2d float array for an allocation


I read the Android documentation about allocations and I also used them in few renderscripts. But there is something that still I couldn't understand.

If I create an allocation with createTyped() I create the structure but not the buffer, actually until now I used this method for input allocations and the buffer is then assigned when it does ioReceive(). To create an output allocation usually I use createFromBitmap() because this method also allocates the buffer. Otherwise to assign the buffer I can use setSurface().

But now I need an output allocation for a 2D float array, how can initialize and assign the buffer for such allocation?


Solution

  • You can create the allocation with createTyped() and then initialize it by calling copyFrom(myfloatarray) where myfloatarray is an array of float values in Java.