I'm looking to return an array of struct from my renderscript kernel. My problem is that although I can create an array of the struct in java using the generated code and pass this to my root method by getting the allocation of the array generated from this, I cant get the array back into java. The Renderscript documentation says to use the copyTo method to copy out of the allocation which ensures that the renderscript has finished operating on it. However this method only supports float, int, byte, bitmap. Even after waiting several seconds before accessing the array to ensure that the renderscript has finished the data in the out allocation doesn't appear changed at all so I wonder if i am approaching this wrong.
Any help at all appreciated
Edit for clarification:
I Create a array of my struct in java with the following
ScriptField_NBody bodys = ScriptField_NBody.create1D(mRS, size, Allocation.USAGE_SCRIPT);
ScriptField_NBody outBodys = new ScriptField_NBody(mRS, 1);
I then call my renderscript function after populating bodys
nBodyScript.forEach_root(bodys.getAllocation(), outBodys.getAllocation())
My renderscript should simply copy bodys to outBodys
void root(const NBody_t *v_in, NBody_t *v_out, uint32_t x) {
*v_out = *v_in;
}
Back in java I now want to access outBodies, (from debug code I know that my renderscript function reads the data and copies it fine). However I cant use the standard copyTo on the outBodys.getllocation() function as this only can take floats, int, bytes and bitmaps, nor does outBodies object update from the allocation on its own. Note that NBody_t is a struct I defined in the renderscript file.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…