Element restructuring. Add support for new basic Element types including the RS objects and vectors(2-4). In theory this paves the way for maintaining type info for RS objects, passing elements for GLSL uiforms/attribs/varyings, and supporting nested structures.
This will break some apps, checkings for other projects will follow to unbreak them.
This commit is contained in:
@@ -24,248 +24,66 @@ import java.lang.reflect.Field;
|
||||
**/
|
||||
public class Element extends BaseObj {
|
||||
int mSize;
|
||||
Entry[] mEntries;
|
||||
Element[] mElements;
|
||||
String[] mElementNames;
|
||||
|
||||
int getSizeBytes() {
|
||||
return mSize;
|
||||
}
|
||||
int getComponentCount() {
|
||||
return mEntries.length;
|
||||
}
|
||||
Element.DataType getComponentDataType(int num) {
|
||||
return mEntries[num].mType;
|
||||
}
|
||||
Element.DataKind getComponentDataKind(int num) {
|
||||
return mEntries[num].mKind;
|
||||
}
|
||||
boolean getComponentIsNormalized(int num) {
|
||||
return mEntries[num].mIsNormalized;
|
||||
}
|
||||
int getComponentBits(int num) {
|
||||
return mEntries[num].mBits;
|
||||
}
|
||||
String getComponentName(int num) {
|
||||
return mEntries[num].mName;
|
||||
}
|
||||
DataType mType;
|
||||
DataKind mKind;
|
||||
boolean mNormalized;
|
||||
int mVectorSize;
|
||||
|
||||
static class Entry {
|
||||
//Element mElement;
|
||||
Element.DataType mType;
|
||||
Element.DataKind mKind;
|
||||
boolean mIsNormalized;
|
||||
int mBits;
|
||||
String mName;
|
||||
|
||||
//Entry(Element e, int bits) {
|
||||
//mElement = e;
|
||||
//int mBits = bits;
|
||||
//}
|
||||
|
||||
Entry(DataType dt, DataKind dk, boolean isNorm, int bits, String name) {
|
||||
mType = dt;
|
||||
mKind = dk;
|
||||
mIsNormalized = isNorm;
|
||||
mBits = bits;
|
||||
mName = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static Element USER_U8(RenderScript rs) {
|
||||
if(rs.mElement_USER_U8 == null) {
|
||||
rs.mElement_USER_U8 = new Element(rs, 1);
|
||||
rs.mElement_USER_U8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 8, null);
|
||||
rs.mElement_USER_U8.init();
|
||||
}
|
||||
return rs.mElement_USER_U8;
|
||||
}
|
||||
|
||||
public static Element USER_I8(RenderScript rs) {
|
||||
if(rs.mElement_USER_I8 == null) {
|
||||
rs.mElement_USER_I8 = new Element(rs, 1);
|
||||
rs.mElement_USER_I8.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 8, null);
|
||||
rs.mElement_USER_I8.init();
|
||||
}
|
||||
return rs.mElement_USER_I8;
|
||||
}
|
||||
|
||||
public static Element USER_U16(RenderScript rs) {
|
||||
if(rs.mElement_USER_U16 == null) {
|
||||
rs.mElement_USER_U16 = new Element(rs, 1);
|
||||
rs.mElement_USER_U16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 16, null);
|
||||
rs.mElement_USER_U16.init();
|
||||
}
|
||||
return rs.mElement_USER_U16;
|
||||
}
|
||||
|
||||
public static Element USER_I16(RenderScript rs) {
|
||||
if(rs.mElement_USER_I16 == null) {
|
||||
rs.mElement_USER_I16 = new Element(rs, 1);
|
||||
rs.mElement_USER_I16.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 16, null);
|
||||
rs.mElement_USER_I16.init();
|
||||
}
|
||||
return rs.mElement_USER_I16;
|
||||
}
|
||||
|
||||
public static Element USER_U32(RenderScript rs) {
|
||||
if(rs.mElement_USER_U32 == null) {
|
||||
rs.mElement_USER_U32 = new Element(rs, 1);
|
||||
rs.mElement_USER_U32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 32, null);
|
||||
rs.mElement_USER_U32.init();
|
||||
}
|
||||
return rs.mElement_USER_U32;
|
||||
}
|
||||
|
||||
public static Element USER_I32(RenderScript rs) {
|
||||
if(rs.mElement_USER_I32 == null) {
|
||||
rs.mElement_USER_I32 = new Element(rs, 1);
|
||||
rs.mElement_USER_I32.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 32, null);
|
||||
rs.mElement_USER_I32.init();
|
||||
}
|
||||
return rs.mElement_USER_I32;
|
||||
}
|
||||
|
||||
public static Element USER_F32(RenderScript rs) {
|
||||
if(rs.mElement_USER_FLOAT == null) {
|
||||
rs.mElement_USER_FLOAT = new Element(rs, 1);
|
||||
rs.mElement_USER_FLOAT.mEntries[0] = new Entry(DataType.FLOAT, DataKind.USER, false, 32, null);
|
||||
rs.mElement_USER_FLOAT.init();
|
||||
}
|
||||
return rs.mElement_USER_FLOAT;
|
||||
}
|
||||
|
||||
public static Element A_8(RenderScript rs) {
|
||||
if(rs.mElement_A_8 == null) {
|
||||
rs.mElement_A_8 = new Element(rs, 1);
|
||||
rs.mElement_A_8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
|
||||
rs.mElement_A_8.init();
|
||||
}
|
||||
return rs.mElement_A_8;
|
||||
}
|
||||
|
||||
public static Element RGB_565(RenderScript rs) {
|
||||
if(rs.mElement_RGB_565 == null) {
|
||||
rs.mElement_RGB_565 = new Element(rs, 3);
|
||||
rs.mElement_RGB_565.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
|
||||
rs.mElement_RGB_565.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 6, "g");
|
||||
rs.mElement_RGB_565.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
|
||||
rs.mElement_RGB_565.init();
|
||||
}
|
||||
return rs.mElement_RGB_565;
|
||||
}
|
||||
|
||||
public static Element RGB_888(RenderScript rs) {
|
||||
if(rs.mElement_RGB_888 == null) {
|
||||
rs.mElement_RGB_888 = new Element(rs, 3);
|
||||
rs.mElement_RGB_888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
|
||||
rs.mElement_RGB_888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
|
||||
rs.mElement_RGB_888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
|
||||
rs.mElement_RGB_888.init();
|
||||
}
|
||||
return rs.mElement_RGB_888;
|
||||
}
|
||||
|
||||
public static Element RGBA_5551(RenderScript rs) {
|
||||
if(rs.mElement_RGBA_5551 == null) {
|
||||
rs.mElement_RGBA_5551 = new Element(rs, 4);
|
||||
rs.mElement_RGBA_5551.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
|
||||
rs.mElement_RGBA_5551.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 5, "g");
|
||||
rs.mElement_RGBA_5551.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
|
||||
rs.mElement_RGBA_5551.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 1, "a");
|
||||
rs.mElement_RGBA_5551.init();
|
||||
}
|
||||
return rs.mElement_RGBA_5551;
|
||||
}
|
||||
|
||||
public static Element RGBA_4444(RenderScript rs) {
|
||||
if(rs.mElement_RGBA_4444 == null) {
|
||||
rs.mElement_RGBA_4444 = new Element(rs, 4);
|
||||
rs.mElement_RGBA_4444.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 4, "r");
|
||||
rs.mElement_RGBA_4444.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 4, "g");
|
||||
rs.mElement_RGBA_4444.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 4, "b");
|
||||
rs.mElement_RGBA_4444.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 4, "a");
|
||||
rs.mElement_RGBA_4444.init();
|
||||
}
|
||||
return rs.mElement_RGBA_4444;
|
||||
}
|
||||
|
||||
public static Element RGBA_8888(RenderScript rs) {
|
||||
if(rs.mElement_RGBA_8888 == null) {
|
||||
rs.mElement_RGBA_8888 = new Element(rs, 4);
|
||||
rs.mElement_RGBA_8888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
|
||||
rs.mElement_RGBA_8888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
|
||||
rs.mElement_RGBA_8888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
|
||||
rs.mElement_RGBA_8888.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
|
||||
rs.mElement_RGBA_8888.init();
|
||||
}
|
||||
return rs.mElement_RGBA_8888;
|
||||
}
|
||||
|
||||
public static Element INDEX_16(RenderScript rs) {
|
||||
if(rs.mElement_INDEX_16 == null) {
|
||||
rs.mElement_INDEX_16 = new Element(rs, 1);
|
||||
rs.mElement_INDEX_16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.INDEX, false, 16, "index");
|
||||
rs.mElement_INDEX_16.init();
|
||||
}
|
||||
return rs.mElement_INDEX_16;
|
||||
}
|
||||
|
||||
public static Element XY_F32(RenderScript rs) {
|
||||
if(rs.mElement_XY_F32 == null) {
|
||||
rs.mElement_XY_F32 = new Element(rs, 2);
|
||||
rs.mElement_XY_F32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.X, false, 32, "x");
|
||||
rs.mElement_XY_F32.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.Y, false, 32, "y");
|
||||
rs.mElement_XY_F32.init();
|
||||
}
|
||||
return rs.mElement_XY_F32;
|
||||
}
|
||||
|
||||
public static Element XYZ_F32(RenderScript rs) {
|
||||
if(rs.mElement_XYZ_F32 == null) {
|
||||
rs.mElement_XYZ_F32 = new Element(rs, 3);
|
||||
rs.mElement_XYZ_F32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.X, false, 32, "x");
|
||||
rs.mElement_XYZ_F32.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.Y, false, 32, "y");
|
||||
rs.mElement_XYZ_F32.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.Z, false, 32, "z");
|
||||
rs.mElement_XYZ_F32.init();
|
||||
}
|
||||
return rs.mElement_XYZ_F32;
|
||||
}
|
||||
|
||||
static void initPredefined(RenderScript rs) {
|
||||
rs.nInitElements(A_8(rs).mID, RGBA_4444(rs).mID, RGBA_8888(rs).mID, RGB_565(rs).mID);
|
||||
}
|
||||
int getSizeBytes() {return mSize;}
|
||||
|
||||
public enum DataType {
|
||||
FLOAT (0),
|
||||
UNSIGNED (1),
|
||||
SIGNED (2);
|
||||
//FLOAT_16 (1, 2),
|
||||
FLOAT_32 (2, 4),
|
||||
//FLOAT_64 (3, 8),
|
||||
SIGNED_8 (4, 1),
|
||||
SIGNED_16 (5, 2),
|
||||
SIGNED_32 (6, 4),
|
||||
//SIGNED_64 (7, 8),
|
||||
UNSIGNED_8 (8, 1),
|
||||
UNSIGNED_16 (9, 2),
|
||||
UNSIGNED_32 (10, 4),
|
||||
//UNSIGNED_64 (11, 8),
|
||||
|
||||
UNSIGNED_5_6_5 (12, 2),
|
||||
UNSIGNED_5_5_5_1 (13, 2),
|
||||
UNSIGNED_4_4_4_4 (14, 2),
|
||||
|
||||
RS_ELEMENT (15, 4),
|
||||
RS_TYPE (16, 4),
|
||||
RS_ALLOCATION (17, 4),
|
||||
RS_SAMPLER (18, 4),
|
||||
RS_SCRIPT (19, 4),
|
||||
RS_MESH (20, 4),
|
||||
RS_PROGRAM_FRAGMENT (21, 4),
|
||||
RS_PROGRAM_VERTEX (22, 4),
|
||||
RS_PROGRAM_RASTER (23, 4),
|
||||
RS_PROGRAM_STORE (24, 4);
|
||||
|
||||
int mID;
|
||||
DataType(int id) {
|
||||
int mSize;
|
||||
DataType(int id, int size) {
|
||||
mID = id;
|
||||
mSize = size;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DataKind {
|
||||
USER (0),
|
||||
RED (1),
|
||||
GREEN (2),
|
||||
BLUE (3),
|
||||
ALPHA (4),
|
||||
LUMINANCE (5),
|
||||
INTENSITY (6),
|
||||
X (7),
|
||||
Y (8),
|
||||
Z (9),
|
||||
W (10),
|
||||
S (11),
|
||||
T (12),
|
||||
Q (13),
|
||||
R (14),
|
||||
NX (15),
|
||||
NY (16),
|
||||
NZ (17),
|
||||
INDEX (18),
|
||||
POINT_SIZE(19);
|
||||
COLOR (1),
|
||||
POSITION (2),
|
||||
TEXTURE (3),
|
||||
NORMAL (4),
|
||||
INDEX (5),
|
||||
POINT_SIZE(6),
|
||||
|
||||
PIXEL_L (7),
|
||||
PIXEL_A (8),
|
||||
PIXEL_LA (9),
|
||||
PIXEL_RGB (10),
|
||||
PIXEL_RGBA (11);
|
||||
|
||||
int mID;
|
||||
DataKind(int id) {
|
||||
@@ -273,10 +91,153 @@ public class Element extends BaseObj {
|
||||
}
|
||||
}
|
||||
|
||||
Element(RenderScript rs, int count) {
|
||||
public static Element USER_U8(RenderScript rs) {
|
||||
if(rs.mElement_USER_U8 == null) {
|
||||
rs.mElement_USER_U8 = createUser(rs, DataType.UNSIGNED_8);
|
||||
}
|
||||
return rs.mElement_USER_U8;
|
||||
}
|
||||
|
||||
public static Element USER_I8(RenderScript rs) {
|
||||
if(rs.mElement_USER_I8 == null) {
|
||||
rs.mElement_USER_I8 = createUser(rs, DataType.SIGNED_8);
|
||||
}
|
||||
return rs.mElement_USER_I8;
|
||||
}
|
||||
|
||||
public static Element USER_U32(RenderScript rs) {
|
||||
if(rs.mElement_USER_U32 == null) {
|
||||
rs.mElement_USER_U32 = createUser(rs, DataType.UNSIGNED_32);
|
||||
}
|
||||
return rs.mElement_USER_U32;
|
||||
}
|
||||
|
||||
public static Element USER_I32(RenderScript rs) {
|
||||
if(rs.mElement_USER_I32 == null) {
|
||||
rs.mElement_USER_I32 = createUser(rs, DataType.SIGNED_32);
|
||||
}
|
||||
return rs.mElement_USER_I32;
|
||||
}
|
||||
|
||||
public static Element USER_F32(RenderScript rs) {
|
||||
if(rs.mElement_USER_F32 == null) {
|
||||
rs.mElement_USER_F32 = createUser(rs, DataType.FLOAT_32);
|
||||
}
|
||||
return rs.mElement_USER_F32;
|
||||
}
|
||||
|
||||
public static Element A_8(RenderScript rs) {
|
||||
if(rs.mElement_A_8 == null) {
|
||||
rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A);
|
||||
}
|
||||
return rs.mElement_A_8;
|
||||
}
|
||||
|
||||
public static Element RGB_565(RenderScript rs) {
|
||||
if(rs.mElement_RGB_565 == null) {
|
||||
rs.mElement_RGB_565 = createPixel(rs, DataType.UNSIGNED_5_6_5, DataKind.PIXEL_RGB);
|
||||
}
|
||||
return rs.mElement_RGB_565;
|
||||
}
|
||||
|
||||
public static Element RGB_888(RenderScript rs) {
|
||||
if(rs.mElement_RGB_888 == null) {
|
||||
rs.mElement_RGB_888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGB);
|
||||
}
|
||||
return rs.mElement_RGB_888;
|
||||
}
|
||||
|
||||
public static Element RGBA_5551(RenderScript rs) {
|
||||
if(rs.mElement_RGBA_5551 == null) {
|
||||
rs.mElement_RGBA_5551 = createPixel(rs, DataType.UNSIGNED_5_5_5_1, DataKind.PIXEL_RGBA);
|
||||
}
|
||||
return rs.mElement_RGBA_5551;
|
||||
}
|
||||
|
||||
public static Element RGBA_4444(RenderScript rs) {
|
||||
if(rs.mElement_RGBA_4444 == null) {
|
||||
rs.mElement_RGBA_4444 = createPixel(rs, DataType.UNSIGNED_4_4_4_4, DataKind.PIXEL_RGBA);
|
||||
}
|
||||
return rs.mElement_RGBA_4444;
|
||||
}
|
||||
|
||||
public static Element RGBA_8888(RenderScript rs) {
|
||||
if(rs.mElement_RGBA_8888 == null) {
|
||||
rs.mElement_RGBA_8888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGBA);
|
||||
}
|
||||
return rs.mElement_RGBA_8888;
|
||||
}
|
||||
|
||||
public static Element INDEX_16(RenderScript rs) {
|
||||
if(rs.mElement_INDEX_16 == null) {
|
||||
rs.mElement_INDEX_16 = createIndex(rs);
|
||||
}
|
||||
return rs.mElement_INDEX_16;
|
||||
}
|
||||
|
||||
public static Element ATTRIB_POSITION_2(RenderScript rs) {
|
||||
if(rs.mElement_POSITION_2 == null) {
|
||||
rs.mElement_POSITION_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 2);
|
||||
}
|
||||
return rs.mElement_POSITION_2;
|
||||
}
|
||||
|
||||
public static Element ATTRIB_POSITION_3(RenderScript rs) {
|
||||
if(rs.mElement_POSITION_3 == null) {
|
||||
rs.mElement_POSITION_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 3);
|
||||
}
|
||||
return rs.mElement_POSITION_3;
|
||||
}
|
||||
|
||||
public static Element ATTRIB_TEXTURE_2(RenderScript rs) {
|
||||
if(rs.mElement_TEXTURE_2 == null) {
|
||||
rs.mElement_TEXTURE_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.TEXTURE, 2);
|
||||
}
|
||||
return rs.mElement_TEXTURE_2;
|
||||
}
|
||||
|
||||
public static Element ATTRIB_NORMAL_3(RenderScript rs) {
|
||||
if(rs.mElement_NORMAL_3 == null) {
|
||||
rs.mElement_NORMAL_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.NORMAL, 3);
|
||||
}
|
||||
return rs.mElement_NORMAL_3;
|
||||
}
|
||||
|
||||
public static Element ATTRIB_COLOR_U8_4(RenderScript rs) {
|
||||
if(rs.mElement_COLOR_U8_4 == null) {
|
||||
rs.mElement_COLOR_U8_4 = createAttrib(rs, DataType.UNSIGNED_8, DataKind.COLOR, 4);
|
||||
}
|
||||
return rs.mElement_COLOR_U8_4;
|
||||
}
|
||||
|
||||
public static Element ATTRIB_COLOR_F32_4(RenderScript rs) {
|
||||
if(rs.mElement_COLOR_F32_4 == null) {
|
||||
rs.mElement_COLOR_F32_4 = createAttrib(rs, DataType.FLOAT_32, DataKind.COLOR, 4);
|
||||
}
|
||||
return rs.mElement_COLOR_F32_4;
|
||||
}
|
||||
|
||||
Element(RenderScript rs, Element[] e, String[] n) {
|
||||
super(rs);
|
||||
mSize = 0;
|
||||
mEntries = new Entry[count];
|
||||
mElements = e;
|
||||
mElementNames = n;
|
||||
int[] ids = new int[mElements.length];
|
||||
for (int ct = 0; ct < mElements.length; ct++ ) {
|
||||
mSize += mElements[ct].mSize;
|
||||
ids[ct] = mElements[ct].mID;
|
||||
}
|
||||
mID = rs.nElementCreate2(ids, mElementNames);
|
||||
}
|
||||
|
||||
Element(RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
|
||||
super(rs);
|
||||
mSize = dt.mSize * size;
|
||||
mType = dt;
|
||||
mKind = dk;
|
||||
mNormalized = norm;
|
||||
mVectorSize = size;
|
||||
mID = rs.nElementCreate(dt.mID, dk.mID, norm, size);
|
||||
}
|
||||
|
||||
public void destroy() throws IllegalStateException {
|
||||
@@ -291,13 +252,13 @@ public class Element extends BaseObj {
|
||||
for(Field f: fields) {
|
||||
Class fc = f.getType();
|
||||
if(fc == int.class) {
|
||||
b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 32, f.getName());
|
||||
b.add(createUser(rs, DataType.SIGNED_32), f.getName());
|
||||
} else if(fc == short.class) {
|
||||
b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 16, f.getName());
|
||||
b.add(createUser(rs, DataType.SIGNED_16), f.getName());
|
||||
} else if(fc == byte.class) {
|
||||
b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 8, f.getName());
|
||||
b.add(createUser(rs, DataType.SIGNED_8), f.getName());
|
||||
} else if(fc == float.class) {
|
||||
b.add(Element.DataType.FLOAT, Element.DataKind.USER, false, 32, f.getName());
|
||||
b.add(createUser(rs, DataType.FLOAT_32), f.getName());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unkown field type");
|
||||
}
|
||||
@@ -305,193 +266,161 @@ public class Element extends BaseObj {
|
||||
return b.create();
|
||||
}
|
||||
|
||||
static synchronized void internalCreate(RenderScript rs, Element e) {
|
||||
rs.nElementBegin();
|
||||
int bits = 0;
|
||||
for (int ct=0; ct < e.mEntries.length; ct++) {
|
||||
Entry en = e.mEntries[ct];
|
||||
//if(en.mElement != null) {
|
||||
//rs.nElementAdd(en.mElement.mID);
|
||||
//} else
|
||||
{
|
||||
rs.nElementAdd(en.mKind.mID, en.mType.mID, en.mIsNormalized, en.mBits, en.mName);
|
||||
bits += en.mBits;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
public static Element createUser(RenderScript rs, DataType dt) {
|
||||
//android.util.Log.e("rs", "createUser " + dt.mID);
|
||||
return new Element(rs, dt, DataKind.USER, false, 1);
|
||||
}
|
||||
|
||||
public static Element createVector(RenderScript rs, DataType dt, int size) {
|
||||
//android.util.Log.e("rs", "createVector " + dt.mID + ", " + size);
|
||||
if (size < 2 || size > 4) {
|
||||
throw new IllegalArgumentException("Bad size");
|
||||
}
|
||||
e.mID = rs.nElementCreate();
|
||||
e.mSize = (bits + 7) >> 3;
|
||||
return new Element(rs, dt, DataKind.USER, false, size);
|
||||
}
|
||||
|
||||
void init() {
|
||||
mRS.validate();
|
||||
internalCreate(mRS, this);
|
||||
public static Element createIndex(RenderScript rs) {
|
||||
android.util.Log.e("rs", "createIndex ");
|
||||
return new Element(rs, DataType.UNSIGNED_16, DataKind.INDEX, false, 1);
|
||||
}
|
||||
|
||||
public static Element createAttrib(RenderScript rs, DataType dt, DataKind dk, int size) {
|
||||
android.util.Log.e("rs", "createAttrib " + dt.mID + ", " + dk.mID + ", " + size);
|
||||
if (!(dt == DataType.FLOAT_32 ||
|
||||
dt == DataType.UNSIGNED_8 ||
|
||||
dt == DataType.UNSIGNED_16 ||
|
||||
dt == DataType.UNSIGNED_32 ||
|
||||
dt == DataType.SIGNED_8 ||
|
||||
dt == DataType.SIGNED_16 ||
|
||||
dt == DataType.SIGNED_32)) {
|
||||
throw new IllegalArgumentException("Unsupported DataType");
|
||||
}
|
||||
|
||||
if (!(dk == DataKind.COLOR ||
|
||||
dk == DataKind.POSITION ||
|
||||
dk == DataKind.TEXTURE ||
|
||||
dk == DataKind.NORMAL ||
|
||||
dk == DataKind.POINT_SIZE)) {
|
||||
throw new IllegalArgumentException("Unsupported DataKind");
|
||||
}
|
||||
|
||||
if (dk == DataKind.COLOR &&
|
||||
((dt != DataType.FLOAT_32 && dt != DataType.UNSIGNED_8) ||
|
||||
size < 3 || size > 4)) {
|
||||
throw new IllegalArgumentException("Bad combo");
|
||||
}
|
||||
if (dk == DataKind.POSITION && (size < 1 || size > 4)) {
|
||||
throw new IllegalArgumentException("Bad combo");
|
||||
}
|
||||
if (dk == DataKind.TEXTURE &&
|
||||
(dt != DataType.FLOAT_32 || size < 1 || size > 4)) {
|
||||
throw new IllegalArgumentException("Bad combo");
|
||||
}
|
||||
if (dk == DataKind.NORMAL &&
|
||||
(dt != DataType.FLOAT_32 || size != 3)) {
|
||||
throw new IllegalArgumentException("Bad combo");
|
||||
}
|
||||
if (dk == DataKind.POINT_SIZE &&
|
||||
(dt != DataType.FLOAT_32 || size != 1)) {
|
||||
throw new IllegalArgumentException("Bad combo");
|
||||
}
|
||||
|
||||
boolean norm = false;
|
||||
if (dk == DataKind.COLOR && dt == DataType.UNSIGNED_8) {
|
||||
norm = true;
|
||||
}
|
||||
|
||||
return new Element(rs, dt, dk, norm, size);
|
||||
}
|
||||
|
||||
public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) {
|
||||
android.util.Log.e("rs", "createPixel " + dt.mID + ", " + dk.mID);
|
||||
if (!(dk == DataKind.PIXEL_L ||
|
||||
dk == DataKind.PIXEL_A ||
|
||||
dk == DataKind.PIXEL_LA ||
|
||||
dk == DataKind.PIXEL_RGB ||
|
||||
dk == DataKind.PIXEL_RGBA)) {
|
||||
throw new IllegalArgumentException("Unsupported DataKind");
|
||||
}
|
||||
if (!(dt == DataType.UNSIGNED_8 ||
|
||||
dt == DataType.UNSIGNED_5_6_5 ||
|
||||
dt == DataType.UNSIGNED_4_4_4_4 ||
|
||||
dt == DataType.UNSIGNED_5_5_5_1)) {
|
||||
throw new IllegalArgumentException("Unsupported DataType");
|
||||
}
|
||||
if (dt == DataType.UNSIGNED_5_6_5 && dk != DataKind.PIXEL_RGB) {
|
||||
throw new IllegalArgumentException("Bad kind and type combo");
|
||||
}
|
||||
if (dt == DataType.UNSIGNED_5_5_5_1 && dk != DataKind.PIXEL_RGBA) {
|
||||
throw new IllegalArgumentException("Bad kind and type combo");
|
||||
}
|
||||
if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
|
||||
throw new IllegalArgumentException("Bad kind and type combo");
|
||||
}
|
||||
|
||||
int size = 1;
|
||||
if (dk == DataKind.PIXEL_LA) {
|
||||
size = 2;
|
||||
}
|
||||
if (dk == DataKind.PIXEL_RGB) {
|
||||
size = 3;
|
||||
}
|
||||
if (dk == DataKind.PIXEL_RGBA) {
|
||||
size = 4;
|
||||
}
|
||||
|
||||
return new Element(rs, dt, dk, true, size);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
RenderScript mRS;
|
||||
Entry[] mEntries;
|
||||
int mEntryCount;
|
||||
Element[] mElements;
|
||||
String[] mElementNames;
|
||||
int mCount;
|
||||
|
||||
public Builder(RenderScript rs) {
|
||||
mRS = rs;
|
||||
mEntryCount = 0;
|
||||
mEntries = new Entry[8];
|
||||
mCount = 0;
|
||||
mElements = new Element[8];
|
||||
mElementNames = new String[8];
|
||||
}
|
||||
|
||||
void addEntry(Entry e) {
|
||||
if(mEntries.length >= mEntryCount) {
|
||||
Entry[] en = new Entry[mEntryCount + 8];
|
||||
System.arraycopy(mEntries, 0, en, 0, mEntries.length);
|
||||
mEntries = en;
|
||||
public void add(Element element, String name) {
|
||||
if(mCount == mElements.length) {
|
||||
Element[] e = new Element[mCount + 8];
|
||||
String[] s = new String[mCount + 8];
|
||||
System.arraycopy(mElements, 0, e, 0, mCount);
|
||||
System.arraycopy(mElementNames, 0, s, 0, mCount);
|
||||
mElements = e;
|
||||
mElementNames = s;
|
||||
}
|
||||
mEntries[mEntryCount] = e;
|
||||
mEntryCount++;
|
||||
}
|
||||
|
||||
//public Builder add(Element e) throws IllegalArgumentException {
|
||||
//Entry en = new Entry(e, e.mSize * 8);
|
||||
//addEntry(en);
|
||||
//return this;
|
||||
//}
|
||||
|
||||
public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) {
|
||||
Entry en = new Entry(dt, dk, isNormalized, bits, name);
|
||||
addEntry(en);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) {
|
||||
add(dt, dk, isNormalized, bits, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloat(Element.DataKind dk) {
|
||||
add(DataType.FLOAT, dk, false, 32, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloat(Element.DataKind dk, String name) {
|
||||
add(DataType.FLOAT, dk, false, 32, name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatXY() {
|
||||
add(DataType.FLOAT, DataKind.X, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.Y, false, 32, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatXY(String prefix) {
|
||||
add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
|
||||
add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatXYZ() {
|
||||
add(DataType.FLOAT, DataKind.X, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.Y, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.Z, false, 32, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatXYZ(String prefix) {
|
||||
add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
|
||||
add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
|
||||
add(DataType.FLOAT, DataKind.Z, false, 32, prefix + "z");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatST() {
|
||||
add(DataType.FLOAT, DataKind.S, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.T, false, 32, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatST(String prefix) {
|
||||
add(DataType.FLOAT, DataKind.S, false, 32, prefix + "s");
|
||||
add(DataType.FLOAT, DataKind.T, false, 32, prefix + "t");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatNorm() {
|
||||
add(DataType.FLOAT, DataKind.NX, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.NY, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.NZ, false, 32, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatNorm(String prefix) {
|
||||
add(DataType.FLOAT, DataKind.NX, false, 32, prefix + "nx");
|
||||
add(DataType.FLOAT, DataKind.NY, false, 32, prefix + "ny");
|
||||
add(DataType.FLOAT, DataKind.NZ, false, 32, prefix + "nz");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatPointSize() {
|
||||
add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatPointSize(String prefix) {
|
||||
add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, prefix + "pointSize");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatRGB() {
|
||||
add(DataType.FLOAT, DataKind.RED, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatRGB(String prefix) {
|
||||
add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
|
||||
add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
|
||||
add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatRGBA() {
|
||||
add(DataType.FLOAT, DataKind.RED, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
|
||||
add(DataType.FLOAT, DataKind.ALPHA, false, 32, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addFloatRGBA(String prefix) {
|
||||
add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
|
||||
add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
|
||||
add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
|
||||
add(DataType.FLOAT, DataKind.ALPHA, false, 32, prefix + "a");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addUNorm8RGBA() {
|
||||
add(DataType.UNSIGNED, DataKind.RED, true, 8, null);
|
||||
add(DataType.UNSIGNED, DataKind.GREEN, true, 8, null);
|
||||
add(DataType.UNSIGNED, DataKind.BLUE, true, 8, null);
|
||||
add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addUNorm8RGBA(String prefix) {
|
||||
add(DataType.UNSIGNED, DataKind.RED, true, 8, prefix + "r");
|
||||
add(DataType.UNSIGNED, DataKind.GREEN, true, 8, prefix + "g");
|
||||
add(DataType.UNSIGNED, DataKind.BLUE, true, 8, prefix + "b");
|
||||
add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, prefix + "a");
|
||||
return this;
|
||||
mElements[mCount] = element;
|
||||
mElementNames[mCount] = name;
|
||||
mCount++;
|
||||
}
|
||||
|
||||
public Element create() {
|
||||
mRS.validate();
|
||||
Element e = new Element(mRS, mEntryCount);
|
||||
java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount);
|
||||
e.init();
|
||||
return e;
|
||||
Element[] ein = new Element[mCount];
|
||||
String[] sin = new String[mCount];
|
||||
java.lang.System.arraycopy(mElements, 0, ein, 0, mCount);
|
||||
java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
|
||||
return new Element(mRS, ein, sin);
|
||||
}
|
||||
}
|
||||
|
||||
static void initPredefined(RenderScript rs) {
|
||||
int a8 = rs.nElementCreate(DataType.UNSIGNED_8.mID,
|
||||
DataKind.PIXEL_A.mID, true, 1);
|
||||
int rgba4444 = rs.nElementCreate(DataType.UNSIGNED_4_4_4_4.mID,
|
||||
DataKind.PIXEL_RGBA.mID, true, 4);
|
||||
int rgba8888 = rs.nElementCreate(DataType.UNSIGNED_8.mID,
|
||||
DataKind.PIXEL_RGBA.mID, true, 4);
|
||||
int rgb565 = rs.nElementCreate(DataType.UNSIGNED_5_6_5.mID,
|
||||
DataKind.PIXEL_RGB.mID, true, 3);
|
||||
rs.nInitElements(a8, rgba4444, rgba8888, rgb565);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user