1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package com.android.fountain;
import android.content.res.Resources;
import android.renderscript.*;
import android.util.Log;
public class ScriptField_Point
extends android.renderscript.Script.FieldBase
{
static public class Item {
Item() {
delta = new Float2();
pos = new Float2();
color = new Short4();
}
public static final int sizeof = (5*4);
Float2 delta;
Float2 pos;
Short4 color;
}
private Item mItemArray[];
public ScriptField_Point(RenderScript rs, int count) {
// Allocate a pack/unpack buffer
mIOBuffer = new FieldPacker(Item.sizeof * count);
mItemArray = new Item[count];
Element.Builder eb = new Element.Builder(rs);
eb.add(Element.createVector(rs, Element.DataType.FLOAT_32, 2), "delta");
eb.add(Element.createAttrib(rs, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "pos");
eb.add(Element.createAttrib(rs, Element.DataType.UNSIGNED_8, Element.DataKind.COLOR, 4), "color");
mElement = eb.create();
init(rs, count);
}
private void copyToArray(Item i, int index) {
mIOBuffer.reset(index * Item.sizeof);
mIOBuffer.addF32(i.delta);
mIOBuffer.addF32(i.pos);
mIOBuffer.addU8(i.color);
}
public void set(Item i, int index, boolean copyNow) {
mItemArray[index] = i;
if (copyNow) {
copyToArray(i, index);
mAllocation.subData1D(index * Item.sizeof, Item.sizeof, mIOBuffer.getData());
}
}
public void copyAll() {
for (int ct=0; ct < mItemArray.length; ct++) {
copyToArray(mItemArray[ct], ct);
}
mAllocation.data(mIOBuffer.getData());
}
private FieldPacker mIOBuffer;
}
|