Read and Write global variables
Reading and Writing global variables is a simple process. You can use the accessors method on the android framework layer or directly set them on the renderscript code layer. Remember any changes in the renderscript Code. Such changes will not be passed to the android framework layer.
For example, the structure is given in a file named rsfile. RS:
typedefstructPoint{
int x;
int y;
}Point_t;
Point_t point;
As shown in the following example, you can assign values to the rsfile. RS file directly. These values cannot be passed to the android framework layer:
Point. x = 1;
Point. y = 1;
You can assign a value to this struct In the android framework layer as follows. These values are passed to the renderscript runtime layer:
Scriptc_rsfile mscript;
...
Item I = new scriptfield_point.item ();
I. x = 1;
I. y = 1;
Mscript. set_point (I );
You can read the value of a variable in the renderscript Code as follows:
Rsdebug ("printing out a point ",
Point. X, point. y );
You can use the following code to read the variable value at the android framework layer. Keep in mind that this code will only return the value set at the android framework layer. If you only set the value at the renderscript runtime, you will get a null pointer exception:
Log. I ("tagname", "printing out a point:" + mscript. get_point (). x + "" + mscript. get_point (). y );
System. Out. println (point. get_x () + "" + point. get_y ());
Read/write global pointer
Assume that the memory has been allocated at the android framework layer and is bound to the renderscript runtime. The get and set methods are used to read and write the pointer memory from the android framework layer. In the renderscript runtime layer, you can use the pointer to read and write the memory as in the normal method, and the corresponding changes will be passed to the android framework layer, unlike the static allocated memory.
For example, the following pointer is given in the file named rsfile. RS:
Typedef struct point {
Int X;
Int y;
} Point_t;
Point_t * point;
Assuming that the memory has been allocated at the android framework layer, you can access the value in the struct as you do in normal methods. Any changes made to the struct using pointer variables will automatically apply to the android framework layer:
Point [Index]. x = 1;
Point [Index]. y = 1;
In the android framework layer, the Read and Write pointer values are also good:
Scriptfield_point P = new scriptfield_point (MRS, 1 );
Item I = new scriptfield_point.item ();
I. x = 100;
I. Y = 100;
P. Set (I, 0, true );
Mscript. bind_point (P );
Points. get_x (0); // read X and Y from index 0
Points. get_x (0 );
Once the memory is bound, you do not have to re-bind the memory to renderscript runtime every time you change the value in the memory.