Reputation: 3
Is there a possibility to set a field in the Android renderscript A out of another renderscript B? I know that you can call a kernel of another Script, using rsForEach()
, but how to set globals or bind allocations?
Example:
I have a (of course there will be multiple) slave script slave.rs
:
// just two example allocations
rs_allocation gImg1;
rs_allocation gImg2;
/** merge the two images element wise - just an example */
float2 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
float2 merged = 0;
merged.x = rsGetElementAt_float(gImg1, x, y);
merged.y = rsGetElementAt_float(gImg2, x, y);
return merged;
}
which i would like to call from my master.rs
script:
// my globals (which will be set from java)
rs_allocation gI0;
rs_allocation gI1;
rs_allocation gMerged;
rs_script mSlave;
/**
* This function is called from Java and should delegate some of its work
* to the kernel function of the slave - script
*/
void myFunction(){
// do some stuff
// now bind the allocations to the slave sript
rsBind(mSlave, "gImg1", gI0); // ??? does there exists something like that?
rsBind(mSlave, "gImg2", gI1); // ???
// and invoke the kernel
rsForEach(mSlave, 0 , gMerged );
}
Of course this is just a toy example, but I was hoping to realize some more complex renderscript constructs with avoiding too many context switches from Java to renderscript.
Some information about multiple Scripts are also provided in a comment to another question: https://stackoverflow.com/a/18926003/4118132
Also an overview on the renderscript functions are provided here: https://stuff.mit.edu/afs/sipb/project/android/docs/guide/topics/renderscript/reference.html
I'm aware that, starting in Android 4.4, the renderscript - engine can be used directly from the ndk.
Upvotes: 0
Views: 274
Reputation: 15775
No, there's no way to directly call functions of other scripts or bind allocations from one script to another. However, you can use a ScriptGroup
to create a chain of scripts to be run together with output of one feeding the input of another, or even a field of another.
Upvotes: 0