我正在使用渲染脚本。我想将数组的元素传递给渲染脚本,并希望对渲染脚本中的每个元素执行平方并将数据返回到 android 框架工作。
我正在尝试通过以下代码来做到这一点。
1.java代码 2.RS代码
但是通过这些代码,这件事是不可能的。请你告诉我我用这些代码做了什么错误。
==================================================== ===========================
爪哇代码
public class SUM extends Activity {
private int[] input;
private int[] output;
private RenderScript mRS;
private Allocation mInAllocation;
private Allocation mOutAllocation;
private ScriptC_Sum mScript;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
input= new int[4];
input[0]=0;
input[1]=1;
input[2]=2;
input[3]=3;
output =new int[4];
createScript();
}
private void createScript() {
mRS = RenderScript.create(this);
mInAllocation = Allocation.createSized(mRS, Element.U32(mRS),4);
mOutAllocation = Allocation.createTyped(mRS,mInAllocation.getType());
mScript = new ScriptC_Sum(mRS, getResources(), R.raw.sum);
mScript.bind_v_in(mInAllocation);
mScript.bind_v_out(mOutAllocation);
mScript.invoke_square(mInAllocation,mOutAllocation);
}
}
==================================================== ========= RS 代码
#pragma version(1)
#pragma rs java_package_name(com.cdacb.mars.summation)
#include "rs_types.rsh"
#include "rs_graphics.rsh"
#include "rs_core.rsh"
int32_t *v_in ;
int32_t *v_out;
void square(){
}
void root(int32_t *v_in,int32_t *v_out )
{
square();
}