1

私は Renderscript を初めて使用し、C 構造体を使用してデータを表現しようとしています。私が読んでいることから、コンパイラは反映されたクラス呼び出し ScriptField_structName を作成して、構造体の内部データにアクセスできるようにする必要があります。

これが私の.rsファイルです:

`

#pragma version(1) //first line
#pragma rs java_package_name(com.example.androidmathoptimizationtest) //java package
#pragma rs_fp_imprecise //relax math, will gain access to NEON optimization and others
//this is our first rs file on our own :)
#include "creditCard.rsh"


typedef struct WorldState {
 float time;
 int galaxyRadius;
 float angle;
 int audioData[1024];
} WorldState_t;


CreditCard_t *mainList[];
int right;
double red;

static float Compute(int n, float x[]){

    float sum = 0;

   for(int i =0; i<n; i++){
    sum += x[i];

   }



    return x[1];

}


void root( const float *v_in, float *v_out){


    float x[] ={1,2,3} ;
    rsGetAllocation(mainList);


    *v_out= Compute(sizeof(x)/sizeof(float),x);


}

`

これが私のJava宣言です:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    t1=new TextView(getApplicationContext());
    t1 =(TextView) findViewById(R.id.T1);
    createCreditCards();

    test3();
}


@SuppressLint("NewApi")
public void test3(){

    float[] a = new float[5];

    for(int i = 0; i<a.length; i++){
        a[i]=i;
    }
   mRS = RenderScript.create(this);


    Type t = new Type.Builder(mRS, Element.U8_4(mRS)).create();

    Allocation mInAllocation = Allocation.createSized(mRS, Element.I32(mRS), clist.size(), Allocation.USAGE_SCRIPT);
    Allocation mOutAllocation = Allocation.createSized(mRS, Element.I32(mRS), clist.size(), Allocation.USAGE_SCRIPT);


    ScriptC_test mScript = new ScriptC_test(mRS, getResources(), R.raw.test);

    float[] x = new float[a.length];
    mInAllocation.copyFrom(a);
    mInAllocation.copyTo(x);
     mScript.forEach_root(mInAllocation, mOutAllocation);
     float[] y =new float[a.length];
    mOutAllocation.copyTo(y);
    t1.setText(String.format("A array: %s\n\nmInAllocation: %s\n\nmOutAllocation: %s", ArrayToString(a), ArrayToString(x), ArrayToString(y)));
}
4

1 に答える 1