问题
I'm incrementing the value of a global in RS with the aim of passing it back to Java on kernel completion. rsDebug shows the value rising on each iteration, but mScript.get_var() returns the initial value of 1. What's the right way to get the last value of MAX?
RS:
int MAX = 1;
void root(const input* in, float* out){
MAX = MAX+1;
rsDebug("MAX",MAX);
*out = atan2(in->first, in->second);
}
Java:
float[] out = new float[100000];
mScript.forEach_root(mInAllocation, mOutAllocation);
mOutAllocation.copyTo(out);
Log.i("Max Count...", Integer.toString(mScript.get_MAX()));
回答1:
get_var only returns the last value set by Java, not the last value set by the RS code. at some point in the future this is going to be addressed, but it hasn't yet. for now, the way around is to stash the value in an RS Allocation and copy it back to Java.
yeah, it's not great. sorry, it's on my list of things to address (I almost did it, but it's far more complicated than I initially thought because of BaseObjs that can be set from RS).
来源:https://stackoverflow.com/questions/19528982/getting-the-value-from-a-renderscript-global-back-to-java