Merge change 24024 into eclair
* changes: Remove "predefined" elements from Java layer. Static elements continue to exist but are no longer treated as a special version of element.
This commit is contained in:
@@ -209,35 +209,24 @@ public class Allocation extends BaseObj {
|
|||||||
static public Allocation createSized(RenderScript rs, Element e, int count)
|
static public Allocation createSized(RenderScript rs, Element e, int count)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
int id;
|
int id = rs.nAllocationCreateSized(e.mID, count);
|
||||||
if(e.mIsPredefined) {
|
if(id == 0) {
|
||||||
id = rs.nAllocationCreatePredefSized(e.mPredefinedID, count);
|
throw new IllegalStateException("Bad element.");
|
||||||
} else {
|
|
||||||
id = rs.nAllocationCreateSized(e.mID, count);
|
|
||||||
if(id == 0) {
|
|
||||||
throw new IllegalStateException("Bad element.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new Allocation(id, rs, null);
|
return new Allocation(id, rs, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
|
static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if(!dstFmt.mIsPredefined) {
|
|
||||||
throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element.");
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = rs.nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b);
|
int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b);
|
||||||
return new Allocation(id, rs, null);
|
return new Allocation(id, rs, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
|
static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if(!dstFmt.mIsPredefined) {
|
|
||||||
throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element.");
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b);
|
int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b);
|
||||||
return new Allocation(id, rs, null);
|
return new Allocation(id, rs, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,10 +239,10 @@ public class Allocation extends BaseObj {
|
|||||||
is = res.openRawResource(id, value);
|
is = res.openRawResource(id, value);
|
||||||
|
|
||||||
int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
|
int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
|
||||||
int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mPredefinedID, genMips,
|
int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mID, genMips,
|
||||||
asset);
|
asset);
|
||||||
|
|
||||||
return new Allocation(allocationId, rs, null);
|
return new Allocation(allocationId, rs, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Ignore
|
// Ignore
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -23,62 +23,171 @@ import java.lang.reflect.Field;
|
|||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
public class Element extends BaseObj {
|
public class Element extends BaseObj {
|
||||||
final int mPredefinedID;
|
int mSize;
|
||||||
final boolean mIsPredefined;
|
Entry[] mEntries;
|
||||||
final int mSize;
|
|
||||||
|
|
||||||
public static final Element USER_U8 = new Element(0, 1);
|
static class Entry {
|
||||||
public static final Element USER_I8 = new Element(1, 1);
|
Element mElement;
|
||||||
public static final Element USER_U16 = new Element(2, 2);
|
Element.DataType mType;
|
||||||
public static final Element USER_I16 = new Element(3, 2);
|
Element.DataKind mKind;
|
||||||
public static final Element USER_U32 = new Element(4, 4);
|
boolean mIsNormalized;
|
||||||
public static final Element USER_I32 = new Element(5, 4);
|
int mBits;
|
||||||
public static final Element USER_FLOAT = new Element(6, 4);
|
String mName;
|
||||||
|
|
||||||
public static final Element A_8 = new Element(7, 1);
|
Entry(Element e, int bits) {
|
||||||
public static final Element RGB_565 = new Element(8, 2);
|
mElement = e;
|
||||||
public static final Element RGB_888 = new Element(11, 2);
|
int mBits = bits;
|
||||||
public static final Element RGBA_5551 = new Element(9, 2);
|
}
|
||||||
public static final Element RGBA_4444 = new Element(10, 2);
|
|
||||||
public static final Element RGBA_8888 = new Element(12, 4);
|
|
||||||
|
|
||||||
public static final Element INDEX_16 = new Element(13, 2);
|
Entry(DataType dt, DataKind dk, boolean isNorm, int bits, String name) {
|
||||||
public static final Element INDEX_32 = new Element(14, 2);
|
mType = dt;
|
||||||
public static final Element XY_F32 = new Element(15, 8);
|
mKind = dk;
|
||||||
public static final Element XYZ_F32 = new Element(16, 12);
|
mIsNormalized = isNorm;
|
||||||
public static final Element ST_XY_F32 = new Element(17, 16);
|
mBits = bits;
|
||||||
public static final Element ST_XYZ_F32 = new Element(18, 20);
|
mName = name;
|
||||||
public static final Element NORM_XYZ_F32 = new Element(19, 24);
|
}
|
||||||
public static final Element NORM_ST_XYZ_F32 = new Element(20, 32);
|
|
||||||
|
|
||||||
void initPredef(RenderScript rs) {
|
|
||||||
mID = rs.nElementGetPredefined(mPredefinedID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init(RenderScript rs) {
|
public static final Element USER_U8 = new Element();
|
||||||
USER_U8.initPredef(rs);
|
public static final Element USER_I8 = new Element();
|
||||||
USER_I8.initPredef(rs);
|
public static final Element USER_U16 = new Element();
|
||||||
USER_U16.initPredef(rs);
|
public static final Element USER_I16 = new Element();
|
||||||
USER_I16.initPredef(rs);
|
public static final Element USER_U32 = new Element();
|
||||||
USER_U32.initPredef(rs);
|
public static final Element USER_I32 = new Element();
|
||||||
USER_I32.initPredef(rs);
|
public static final Element USER_FLOAT = new Element();
|
||||||
USER_FLOAT.initPredef(rs);
|
|
||||||
|
|
||||||
A_8.initPredef(rs);
|
public static final Element A_8 = new Element();
|
||||||
RGB_565.initPredef(rs);
|
public static final Element RGB_565 = new Element();
|
||||||
RGB_888.initPredef(rs);
|
public static final Element RGB_888 = new Element();
|
||||||
RGBA_5551.initPredef(rs);
|
public static final Element RGBA_5551 = new Element();
|
||||||
RGBA_4444.initPredef(rs);
|
public static final Element RGBA_4444 = new Element();
|
||||||
RGBA_8888.initPredef(rs);
|
public static final Element RGBA_8888 = new Element();
|
||||||
|
|
||||||
INDEX_16.initPredef(rs);
|
public static final Element INDEX_16 = new Element();
|
||||||
INDEX_32.initPredef(rs);
|
public static final Element XY_F32 = new Element();
|
||||||
XY_F32.initPredef(rs);
|
public static final Element XYZ_F32 = new Element();
|
||||||
XYZ_F32.initPredef(rs);
|
public static final Element ST_XY_F32 = new Element();
|
||||||
ST_XY_F32.initPredef(rs);
|
public static final Element ST_XYZ_F32 = new Element();
|
||||||
ST_XYZ_F32.initPredef(rs);
|
public static final Element NORM_XYZ_F32 = new Element();
|
||||||
NORM_XYZ_F32.initPredef(rs);
|
public static final Element NORM_ST_XYZ_F32 = new Element();
|
||||||
NORM_ST_XYZ_F32.initPredef(rs);
|
|
||||||
|
static void initPredefined(RenderScript rs) {
|
||||||
|
USER_U8.mEntries = new Entry[1];
|
||||||
|
USER_U8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 8, null);
|
||||||
|
USER_U8.init(rs);
|
||||||
|
|
||||||
|
USER_I8.mEntries = new Entry[1];
|
||||||
|
USER_I8.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 8, null);
|
||||||
|
USER_I8.init(rs);
|
||||||
|
|
||||||
|
USER_U16.mEntries = new Entry[1];
|
||||||
|
USER_U16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 16, null);
|
||||||
|
USER_U16.init(rs);
|
||||||
|
|
||||||
|
USER_I16.mEntries = new Entry[1];
|
||||||
|
USER_I16.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 16, null);
|
||||||
|
USER_I16.init(rs);
|
||||||
|
|
||||||
|
USER_U32.mEntries = new Entry[1];
|
||||||
|
USER_U32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 32, null);
|
||||||
|
USER_U32.init(rs);
|
||||||
|
|
||||||
|
USER_I32.mEntries = new Entry[1];
|
||||||
|
USER_I32.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 32, null);
|
||||||
|
USER_I32.init(rs);
|
||||||
|
|
||||||
|
USER_FLOAT.mEntries = new Entry[1];
|
||||||
|
USER_FLOAT.mEntries[0] = new Entry(DataType.FLOAT, DataKind.USER, false, 32, null);
|
||||||
|
USER_FLOAT.init(rs);
|
||||||
|
|
||||||
|
A_8.mEntries = new Entry[1];
|
||||||
|
A_8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
|
||||||
|
A_8.init(rs);
|
||||||
|
|
||||||
|
RGB_565.mEntries = new Entry[3];
|
||||||
|
RGB_565.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
|
||||||
|
RGB_565.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 6, "g");
|
||||||
|
RGB_565.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
|
||||||
|
RGB_565.init(rs);
|
||||||
|
|
||||||
|
RGB_888.mEntries = new Entry[3];
|
||||||
|
RGB_888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
|
||||||
|
RGB_888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
|
||||||
|
RGB_888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
|
||||||
|
RGB_888.init(rs);
|
||||||
|
|
||||||
|
RGBA_5551.mEntries = new Entry[4];
|
||||||
|
RGBA_5551.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
|
||||||
|
RGBA_5551.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 5, "g");
|
||||||
|
RGBA_5551.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
|
||||||
|
RGBA_5551.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 1, "a");
|
||||||
|
RGBA_5551.init(rs);
|
||||||
|
|
||||||
|
RGBA_4444.mEntries = new Entry[4];
|
||||||
|
RGBA_4444.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 4, "r");
|
||||||
|
RGBA_4444.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 4, "g");
|
||||||
|
RGBA_4444.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 4, "b");
|
||||||
|
RGBA_4444.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 4, "a");
|
||||||
|
RGBA_4444.init(rs);
|
||||||
|
|
||||||
|
RGBA_8888.mEntries = new Entry[4];
|
||||||
|
RGBA_8888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
|
||||||
|
RGBA_8888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
|
||||||
|
RGBA_8888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
|
||||||
|
RGBA_8888.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
|
||||||
|
RGBA_8888.init(rs);
|
||||||
|
|
||||||
|
INDEX_16.mEntries = new Entry[1];
|
||||||
|
INDEX_16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.INDEX, false, 16, "index");
|
||||||
|
INDEX_16.init(rs);
|
||||||
|
|
||||||
|
XY_F32.mEntries = new Entry[2];
|
||||||
|
XY_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
|
||||||
|
XY_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
|
||||||
|
XY_F32.init(rs);
|
||||||
|
|
||||||
|
XYZ_F32.mEntries = new Entry[3];
|
||||||
|
XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
|
||||||
|
XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
|
||||||
|
XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
|
||||||
|
XYZ_F32.init(rs);
|
||||||
|
|
||||||
|
ST_XY_F32.mEntries = new Entry[4];
|
||||||
|
ST_XY_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s");
|
||||||
|
ST_XY_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t");
|
||||||
|
ST_XY_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
|
||||||
|
ST_XY_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
|
||||||
|
ST_XY_F32.init(rs);
|
||||||
|
|
||||||
|
ST_XYZ_F32.mEntries = new Entry[5];
|
||||||
|
ST_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s");
|
||||||
|
ST_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t");
|
||||||
|
ST_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
|
||||||
|
ST_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
|
||||||
|
ST_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
|
||||||
|
ST_XYZ_F32.init(rs);
|
||||||
|
|
||||||
|
NORM_XYZ_F32.mEntries = new Entry[6];
|
||||||
|
NORM_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.NX, false, 32, "nx");
|
||||||
|
NORM_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.NY, false, 32, "ny");
|
||||||
|
NORM_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.NZ, false, 32, "nz");
|
||||||
|
NORM_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
|
||||||
|
NORM_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
|
||||||
|
NORM_XYZ_F32.mEntries[5] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
|
||||||
|
NORM_XYZ_F32.init(rs);
|
||||||
|
|
||||||
|
NORM_ST_XYZ_F32.mEntries = new Entry[8];
|
||||||
|
NORM_ST_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.NX, false, 32, "nx");
|
||||||
|
NORM_ST_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.NY, false, 32, "ny");
|
||||||
|
NORM_ST_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.NZ, false, 32, "nz");
|
||||||
|
NORM_ST_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s");
|
||||||
|
NORM_ST_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t");
|
||||||
|
NORM_ST_XYZ_F32.mEntries[5] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
|
||||||
|
NORM_ST_XYZ_F32.mEntries[6] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
|
||||||
|
NORM_ST_XYZ_F32.mEntries[7] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
|
||||||
|
NORM_ST_XYZ_F32.init(rs);
|
||||||
|
|
||||||
|
rs.nInitElements(A_8.mID, RGBA_4444.mID, RGBA_8888.mID, RGB_565.mID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,27 +230,13 @@ public class Element extends BaseObj {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Element() {
|
||||||
Element(int predef, int size) {
|
|
||||||
super(null);
|
super(null);
|
||||||
mID = 0;
|
mID = 0;
|
||||||
mPredefinedID = predef;
|
mSize = 0;
|
||||||
mIsPredefined = true;
|
|
||||||
mSize = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
Element(int id, RenderScript rs, int size) {
|
|
||||||
super(rs);
|
|
||||||
mID = id;
|
|
||||||
mPredefinedID = 0;
|
|
||||||
mIsPredefined = false;
|
|
||||||
mSize = size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() throws IllegalStateException {
|
public void destroy() throws IllegalStateException {
|
||||||
if(mIsPredefined) {
|
|
||||||
throw new IllegalStateException("Attempting to destroy a predefined Element.");
|
|
||||||
}
|
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,27 +261,41 @@ public class Element extends BaseObj {
|
|||||||
return b.create();
|
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 {
|
||||||
|
int norm = 0;
|
||||||
|
if (en.mIsNormalized) {
|
||||||
|
norm = 1;
|
||||||
|
}
|
||||||
|
rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits, en.mName);
|
||||||
|
bits += en.mBits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.mID = rs.nElementCreate();
|
||||||
|
e.mSize = (bits + 7) >> 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init(RenderScript rs) {
|
||||||
|
mRS = rs;
|
||||||
|
internalCreate(mRS, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
RenderScript mRS;
|
RenderScript mRS;
|
||||||
Entry[] mEntries;
|
Entry[] mEntries;
|
||||||
int mEntryCount;
|
int mEntryCount;
|
||||||
int mSizeBits;
|
|
||||||
|
|
||||||
private class Entry {
|
|
||||||
Element mElement;
|
|
||||||
Element.DataType mType;
|
|
||||||
Element.DataKind mKind;
|
|
||||||
boolean mIsNormalized;
|
|
||||||
int mBits;
|
|
||||||
String mName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder(RenderScript rs) {
|
public Builder(RenderScript rs) {
|
||||||
mRS = rs;
|
mRS = rs;
|
||||||
mEntryCount = 0;
|
mEntryCount = 0;
|
||||||
mEntries = new Entry[8];
|
mEntries = new Entry[8];
|
||||||
mSizeBits = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addEntry(Entry e) {
|
void addEntry(Entry e) {
|
||||||
@@ -200,24 +309,13 @@ public class Element extends BaseObj {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Builder add(Element e) throws IllegalArgumentException {
|
public Builder add(Element e) throws IllegalArgumentException {
|
||||||
if(!e.mIsPredefined) {
|
Entry en = new Entry(e, e.mSize * 8);
|
||||||
throw new IllegalArgumentException("add requires a predefined Element.");
|
|
||||||
}
|
|
||||||
Entry en = new Entry();
|
|
||||||
en.mElement = e;
|
|
||||||
addEntry(en);
|
addEntry(en);
|
||||||
mSizeBits += e.mSize * 8;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) {
|
public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) {
|
||||||
Entry en = new Entry();
|
Entry en = new Entry(dt, dk, isNormalized, bits, name);
|
||||||
en.mType = dt;
|
|
||||||
en.mKind = dk;
|
|
||||||
en.mIsNormalized = isNormalized;
|
|
||||||
en.mBits = bits;
|
|
||||||
en.mName = name;
|
|
||||||
mSizeBits += bits;
|
|
||||||
addEntry(en);
|
addEntry(en);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -345,26 +443,12 @@ public class Element extends BaseObj {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
static synchronized Element internalCreate(RenderScript rs, Builder b) {
|
|
||||||
rs.nElementBegin();
|
|
||||||
for (int ct=0; ct < b.mEntryCount; ct++) {
|
|
||||||
Entry en = b.mEntries[ct];
|
|
||||||
if(en.mElement != null) {
|
|
||||||
rs.nElementAddPredefined(en.mElement.mPredefinedID);
|
|
||||||
} else {
|
|
||||||
int norm = 0;
|
|
||||||
if (en.mIsNormalized) {
|
|
||||||
norm = 1;
|
|
||||||
}
|
|
||||||
rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits, en.mName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int id = rs.nElementCreate();
|
|
||||||
return new Element(id, rs, (b.mSizeBits + 7) >> 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element create() {
|
public Element create() {
|
||||||
return internalCreate(mRS, this);
|
Element e = new Element();
|
||||||
|
e.mEntries = new Entry[mEntryCount];
|
||||||
|
java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount);
|
||||||
|
e.init(mRS);
|
||||||
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public class RenderScript {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
native void nInitElements(int a8, int rgba4444, int rgba8888, int rgb565);
|
||||||
|
|
||||||
native int nDeviceCreate();
|
native int nDeviceCreate();
|
||||||
native void nDeviceDestroy(int dev);
|
native void nDeviceDestroy(int dev);
|
||||||
native int nContextCreate(int dev, Surface sur, int ver, boolean useDepth);
|
native int nContextCreate(int dev, Surface sur, int ver, boolean useDepth);
|
||||||
@@ -78,10 +80,8 @@ public class RenderScript {
|
|||||||
native int nFileOpen(byte[] name);
|
native int nFileOpen(byte[] name);
|
||||||
|
|
||||||
native void nElementBegin();
|
native void nElementBegin();
|
||||||
native void nElementAddPredefined(int predef);
|
|
||||||
native void nElementAdd(int kind, int type, int norm, int bits, String s);
|
native void nElementAdd(int kind, int type, int norm, int bits, String s);
|
||||||
native int nElementCreate();
|
native int nElementCreate();
|
||||||
native int nElementGetPredefined(int predef);
|
|
||||||
|
|
||||||
native void nTypeBegin(int elementID);
|
native void nTypeBegin(int elementID);
|
||||||
native void nTypeAdd(int dim, int val);
|
native void nTypeAdd(int dim, int val);
|
||||||
@@ -90,7 +90,6 @@ public class RenderScript {
|
|||||||
native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
|
native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
|
||||||
|
|
||||||
native int nAllocationCreateTyped(int type);
|
native int nAllocationCreateTyped(int type);
|
||||||
native int nAllocationCreatePredefSized(int predef, int count);
|
|
||||||
native int nAllocationCreateSized(int elem, int count);
|
native int nAllocationCreateSized(int elem, int count);
|
||||||
native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
|
native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
|
||||||
native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
|
native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
|
||||||
@@ -203,7 +202,7 @@ public class RenderScript {
|
|||||||
|
|
||||||
// TODO: This should be protected by a lock
|
// TODO: This should be protected by a lock
|
||||||
if(!mElementsInitialized) {
|
if(!mElementsInitialized) {
|
||||||
Element.init(this);
|
Element.initPredefined(this);
|
||||||
mElementsInitialized = true;
|
mElementsInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,7 +226,6 @@ public class RenderScript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void triangleMeshBegin(Element vertex, Element index) {
|
public void triangleMeshBegin(Element vertex, Element index) {
|
||||||
Log.e("rs", "vtx " + vertex.toString() + " " + vertex.mID + " " + vertex.mPredefinedID);
|
|
||||||
nTriangleMeshBegin(vertex.mID, index.mID);
|
nTriangleMeshBegin(vertex.mID, index.mID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ static jfieldID gContextId = 0;
|
|||||||
static jfieldID gNativeBitmapID = 0;
|
static jfieldID gNativeBitmapID = 0;
|
||||||
static jfieldID gTypeNativeCache = 0;
|
static jfieldID gTypeNativeCache = 0;
|
||||||
|
|
||||||
|
static RsElement g_A_8 = NULL;
|
||||||
|
static RsElement g_RGBA_4444 = NULL;
|
||||||
|
static RsElement g_RGBA_8888 = NULL;
|
||||||
|
static RsElement g_RGB_565 = NULL;
|
||||||
|
|
||||||
static void _nInit(JNIEnv *_env, jclass _this)
|
static void _nInit(JNIEnv *_env, jclass _this)
|
||||||
{
|
{
|
||||||
gContextId = _env->GetFieldID(_this, "mContext", "I");
|
gContextId = _env->GetFieldID(_this, "mContext", "I");
|
||||||
@@ -69,6 +74,13 @@ static void _nInit(JNIEnv *_env, jclass _this)
|
|||||||
gTypeNativeCache = _env->GetFieldID(typeClass, "mNativeCache", "I");
|
gTypeNativeCache = _env->GetFieldID(typeClass, "mNativeCache", "I");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void nInitElements(JNIEnv *_env, jobject _this, jint a8, jint rgba4444, jint rgba8888, jint rgb565)
|
||||||
|
{
|
||||||
|
g_A_8 = reinterpret_cast<RsElement>(a8);
|
||||||
|
g_RGBA_4444 = reinterpret_cast<RsElement>(rgba4444);
|
||||||
|
g_RGBA_8888 = reinterpret_cast<RsElement>(rgba8888);
|
||||||
|
g_RGB_565 = reinterpret_cast<RsElement>(rgb565);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -167,13 +179,6 @@ nElementBegin(JNIEnv *_env, jobject _this)
|
|||||||
rsElementBegin(con);
|
rsElementBegin(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
nElementAddPredefined(JNIEnv *_env, jobject _this, jint predef)
|
|
||||||
{
|
|
||||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
|
||||||
LOG_API("nElementAddPredefined, con(%p), predef(%i)", con, predef);
|
|
||||||
rsElementAddPredefined(con, (RsElementPredefined)predef);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jint norm, jint bits, jstring name)
|
nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jint norm, jint bits, jstring name)
|
||||||
@@ -198,14 +203,6 @@ nElementCreate(JNIEnv *_env, jobject _this)
|
|||||||
return (jint)rsElementCreate(con);
|
return (jint)rsElementCreate(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jint
|
|
||||||
nElementGetPredefined(JNIEnv *_env, jobject _this, jint predef)
|
|
||||||
{
|
|
||||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
|
||||||
LOG_API("nElementGetPredefined, con(%p) predef(%i)", con, predef);
|
|
||||||
return (jint)rsElementGetPredefined(con, (RsElementPredefined)predef);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -327,14 +324,6 @@ nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e)
|
|||||||
return (jint) rsAllocationCreateTyped(con, (RsElement)e);
|
return (jint) rsAllocationCreateTyped(con, (RsElement)e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jint
|
|
||||||
nAllocationCreatePredefSized(JNIEnv *_env, jobject _this, jint predef, jint count)
|
|
||||||
{
|
|
||||||
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
|
|
||||||
LOG_API("nAllocationCreatePredefSized, con(%p), predef(%i), count(%i)", con, predef, count);
|
|
||||||
return (jint) rsAllocationCreatePredefSized(con, (RsElementPredefined)predef, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
static jint
|
static jint
|
||||||
nAllocationCreateSized(JNIEnv *_env, jobject _this, jint e, jint count)
|
nAllocationCreateSized(JNIEnv *_env, jobject _this, jint e, jint count)
|
||||||
{
|
{
|
||||||
@@ -359,24 +348,24 @@ nAllocationUploadToBufferObject(JNIEnv *_env, jobject _this, jint a)
|
|||||||
rsAllocationUploadToBufferObject(con, (RsAllocation)a);
|
rsAllocationUploadToBufferObject(con, (RsAllocation)a);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RsElementPredefined SkBitmapToPredefined(SkBitmap::Config cfg)
|
static RsElement SkBitmapToPredefined(SkBitmap::Config cfg)
|
||||||
{
|
{
|
||||||
switch (cfg) {
|
switch (cfg) {
|
||||||
case SkBitmap::kA8_Config:
|
case SkBitmap::kA8_Config:
|
||||||
return RS_ELEMENT_A_8;
|
return g_A_8;
|
||||||
case SkBitmap::kARGB_4444_Config:
|
case SkBitmap::kARGB_4444_Config:
|
||||||
return RS_ELEMENT_RGBA_4444;
|
return g_RGBA_4444;
|
||||||
case SkBitmap::kARGB_8888_Config:
|
case SkBitmap::kARGB_8888_Config:
|
||||||
return RS_ELEMENT_RGBA_8888;
|
return g_RGBA_8888;
|
||||||
case SkBitmap::kRGB_565_Config:
|
case SkBitmap::kRGB_565_Config:
|
||||||
return RS_ELEMENT_RGB_565;
|
return g_RGB_565;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// If we don't have a conversion mark it as a user type.
|
// If we don't have a conversion mark it as a user type.
|
||||||
LOGE("Unsupported bitmap type");
|
LOGE("Unsupported bitmap type");
|
||||||
return RS_ELEMENT_USER_U8;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -388,14 +377,13 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean g
|
|||||||
const SkBitmap& bitmap(*nativeBitmap);
|
const SkBitmap& bitmap(*nativeBitmap);
|
||||||
SkBitmap::Config config = bitmap.getConfig();
|
SkBitmap::Config config = bitmap.getConfig();
|
||||||
|
|
||||||
RsElementPredefined e = SkBitmapToPredefined(config);
|
RsElement e = SkBitmapToPredefined(config);
|
||||||
|
if (e) {
|
||||||
if (e != RS_ELEMENT_USER_U8) {
|
|
||||||
bitmap.lockPixels();
|
bitmap.lockPixels();
|
||||||
const int w = bitmap.width();
|
const int w = bitmap.width();
|
||||||
const int h = bitmap.height();
|
const int h = bitmap.height();
|
||||||
const void* ptr = bitmap.getPixels();
|
const void* ptr = bitmap.getPixels();
|
||||||
jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
|
jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
|
||||||
bitmap.unlockPixels();
|
bitmap.unlockPixels();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -414,14 +402,14 @@ nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jbool
|
|||||||
|
|
||||||
SkBitmap::Config config = bitmap.getConfig();
|
SkBitmap::Config config = bitmap.getConfig();
|
||||||
|
|
||||||
RsElementPredefined e = SkBitmapToPredefined(config);
|
RsElement e = SkBitmapToPredefined(config);
|
||||||
|
|
||||||
if (e != RS_ELEMENT_USER_U8) {
|
if (e) {
|
||||||
bitmap.lockPixels();
|
bitmap.lockPixels();
|
||||||
const int w = bitmap.width();
|
const int w = bitmap.width();
|
||||||
const int h = bitmap.height();
|
const int h = bitmap.height();
|
||||||
const void* ptr = bitmap.getPixels();
|
const void* ptr = bitmap.getPixels();
|
||||||
jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
|
jint id = (jint)rsAllocationCreateFromBitmap(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
|
||||||
bitmap.unlockPixels();
|
bitmap.unlockPixels();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -437,14 +425,14 @@ nAllocationCreateFromBitmapBoxed(JNIEnv *_env, jobject _this, jint dstFmt, jbool
|
|||||||
const SkBitmap& bitmap(*nativeBitmap);
|
const SkBitmap& bitmap(*nativeBitmap);
|
||||||
SkBitmap::Config config = bitmap.getConfig();
|
SkBitmap::Config config = bitmap.getConfig();
|
||||||
|
|
||||||
RsElementPredefined e = SkBitmapToPredefined(config);
|
RsElement e = SkBitmapToPredefined(config);
|
||||||
|
|
||||||
if (e != RS_ELEMENT_USER_U8) {
|
if (e) {
|
||||||
bitmap.lockPixels();
|
bitmap.lockPixels();
|
||||||
const int w = bitmap.width();
|
const int w = bitmap.width();
|
||||||
const int h = bitmap.height();
|
const int h = bitmap.height();
|
||||||
const void* ptr = bitmap.getPixels();
|
const void* ptr = bitmap.getPixels();
|
||||||
jint id = (jint)rsAllocationCreateFromBitmapBoxed(con, w, h, (RsElementPredefined)dstFmt, e, genMips, ptr);
|
jint id = (jint)rsAllocationCreateFromBitmapBoxed(con, w, h, (RsElement)dstFmt, e, genMips, ptr);
|
||||||
bitmap.unlockPixels();
|
bitmap.unlockPixels();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -1244,6 +1232,8 @@ static const char *classPathName = "android/renderscript/RenderScript";
|
|||||||
|
|
||||||
static JNINativeMethod methods[] = {
|
static JNINativeMethod methods[] = {
|
||||||
{"_nInit", "()V", (void*)_nInit },
|
{"_nInit", "()V", (void*)_nInit },
|
||||||
|
{"nInitElements", "(IIII)V", (void*)nInitElements },
|
||||||
|
|
||||||
{"nDeviceCreate", "()I", (void*)nDeviceCreate },
|
{"nDeviceCreate", "()I", (void*)nDeviceCreate },
|
||||||
{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
|
{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
|
||||||
{"nContextCreate", "(ILandroid/view/Surface;IZ)I", (void*)nContextCreate },
|
{"nContextCreate", "(ILandroid/view/Surface;IZ)I", (void*)nContextCreate },
|
||||||
@@ -1255,10 +1245,8 @@ static JNINativeMethod methods[] = {
|
|||||||
{"nFileOpen", "([B)I", (void*)nFileOpen },
|
{"nFileOpen", "([B)I", (void*)nFileOpen },
|
||||||
|
|
||||||
{"nElementBegin", "()V", (void*)nElementBegin },
|
{"nElementBegin", "()V", (void*)nElementBegin },
|
||||||
{"nElementAddPredefined", "(I)V", (void*)nElementAddPredefined },
|
|
||||||
{"nElementAdd", "(IIIILjava/lang/String;)V", (void*)nElementAdd },
|
{"nElementAdd", "(IIIILjava/lang/String;)V", (void*)nElementAdd },
|
||||||
{"nElementCreate", "()I", (void*)nElementCreate },
|
{"nElementCreate", "()I", (void*)nElementCreate },
|
||||||
{"nElementGetPredefined", "(I)I", (void*)nElementGetPredefined },
|
|
||||||
|
|
||||||
{"nTypeBegin", "(I)V", (void*)nTypeBegin },
|
{"nTypeBegin", "(I)V", (void*)nTypeBegin },
|
||||||
{"nTypeAdd", "(II)V", (void*)nTypeAdd },
|
{"nTypeAdd", "(II)V", (void*)nTypeAdd },
|
||||||
@@ -1267,7 +1255,6 @@ static JNINativeMethod methods[] = {
|
|||||||
{"nTypeSetupFields", "(Landroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields },
|
{"nTypeSetupFields", "(Landroid/renderscript/Type;[I[I[Ljava/lang/reflect/Field;)V", (void*)nTypeSetupFields },
|
||||||
|
|
||||||
{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped },
|
{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped },
|
||||||
{"nAllocationCreatePredefSized", "(II)I", (void*)nAllocationCreatePredefSized },
|
|
||||||
{"nAllocationCreateSized", "(II)I", (void*)nAllocationCreateSized },
|
{"nAllocationCreateSized", "(II)I", (void*)nAllocationCreateSized },
|
||||||
{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
|
{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
|
||||||
{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed },
|
{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed },
|
||||||
|
|||||||
@@ -47,6 +47,20 @@
|
|||||||
// The higher, the smaller the ripple
|
// The higher, the smaller the ripple
|
||||||
#define RIPPLE_HEIGHT 10.0f
|
#define RIPPLE_HEIGHT 10.0f
|
||||||
|
|
||||||
|
float g_SkyOffsetX;
|
||||||
|
float g_SkyOffsetY;
|
||||||
|
|
||||||
|
struct vert_s {
|
||||||
|
float nx;
|
||||||
|
float ny;
|
||||||
|
float nz;
|
||||||
|
float s;
|
||||||
|
float t;
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
};
|
||||||
|
|
||||||
int offset(int x, int y, int width) {
|
int offset(int x, int y, int width) {
|
||||||
return x + 1 + (y + 1) * (width + 2);
|
return x + 1 + (y + 1) * (width + 2);
|
||||||
}
|
}
|
||||||
@@ -150,8 +164,8 @@ void generateRipples() {
|
|||||||
int *map = loadArrayI32(RSID_REFRACTION_MAP, 0);
|
int *map = loadArrayI32(RSID_REFRACTION_MAP, 0);
|
||||||
float *vertices = loadTriangleMeshVerticesF(NAMED_WaterMesh);
|
float *vertices = loadTriangleMeshVerticesF(NAMED_WaterMesh);
|
||||||
|
|
||||||
float fw = (float) width;
|
float fw = 1.f / width;
|
||||||
float fh = (float) height;
|
float fh = 1.f / height;
|
||||||
float fy = (1.0f / 512.0f) * (1.0f / RIPPLE_HEIGHT);
|
float fy = (1.0f / 512.0f) * (1.0f / RIPPLE_HEIGHT);
|
||||||
|
|
||||||
int h = height - 1;
|
int h = height - 1;
|
||||||
@@ -175,8 +189,8 @@ void generateRipples() {
|
|||||||
if (v >= height) v = height - 1;
|
if (v >= height) v = height - 1;
|
||||||
|
|
||||||
int index = (offset + w) << 3;
|
int index = (offset + w) << 3;
|
||||||
vertices[index + 3] = u / fw;
|
vertices[index + 3] = u * fw;
|
||||||
vertices[index + 4] = v / fh;
|
vertices[index + 4] = v * fh;
|
||||||
|
|
||||||
// Update Z coordinate of the vertex
|
// Update Z coordinate of the vertex
|
||||||
vertices[index + 7] = dy * fy;
|
vertices[index + 7] = dy * fy;
|
||||||
@@ -196,76 +210,26 @@ void generateRipples() {
|
|||||||
int x = 0;
|
int x = 0;
|
||||||
int yOffset = y * width;
|
int yOffset = y * width;
|
||||||
for ( ; x < width; x += 1) {
|
for ( ; x < width; x += 1) {
|
||||||
int o = (yOffset + x) << 3;
|
int o = ((yOffset + x) << 3);
|
||||||
int o1 = o + 8;
|
int o1 = o + 8 + 5;
|
||||||
int ow = o + w8;
|
int ow = o + w8 + 5;
|
||||||
int ow1 = ow + 8;
|
int ow1 = ow + 8;
|
||||||
|
|
||||||
// V1
|
struct vec3_s n1, n2, n3;
|
||||||
float v1x = vertices[o + 5];
|
vec3Sub(&n1, (struct vec3_s *)(vertices + o1 + 5), (struct vec3_s *)(vertices + o + 5));
|
||||||
float v1y = vertices[o + 6];
|
vec3Sub(&n2, (struct vec3_s *)(vertices + ow + 5), (struct vec3_s *)(vertices + o + 5));
|
||||||
float v1z = vertices[o + 7];
|
vec3Cross(&n3, &n1, &n2);
|
||||||
|
vec3Norm(&n3);
|
||||||
// V2
|
|
||||||
float v2x = vertices[o1 + 5];
|
|
||||||
float v2y = vertices[o1 + 6];
|
|
||||||
float v2z = vertices[o1 + 7];
|
|
||||||
|
|
||||||
// V3
|
|
||||||
float v3x = vertices[ow + 5];
|
|
||||||
float v3y = vertices[ow + 6];
|
|
||||||
float v3z = vertices[ow + 7];
|
|
||||||
|
|
||||||
// N1
|
|
||||||
float n1x = v2x - v1x;
|
|
||||||
float n1y = v2y - v1y;
|
|
||||||
float n1z = v2z - v1z;
|
|
||||||
|
|
||||||
// N2
|
|
||||||
float n2x = v3x - v1x;
|
|
||||||
float n2y = v3y - v1y;
|
|
||||||
float n2z = v3z - v1z;
|
|
||||||
|
|
||||||
// N1 x N2
|
|
||||||
float n3x = n1y * n2z - n1z * n2y;
|
|
||||||
float n3y = n1z * n2x - n1x * n2z;
|
|
||||||
float n3z = n1x * n2y - n1y * n2x;
|
|
||||||
|
|
||||||
// Normalize
|
|
||||||
float len = 1.0f / magf3(n3x, n3y, n3z);
|
|
||||||
n3x *= len;
|
|
||||||
n3y *= len;
|
|
||||||
n3z *= len;
|
|
||||||
|
|
||||||
// V2
|
|
||||||
v2x = vertices[ow1 + 5];
|
|
||||||
v2y = vertices[ow1 + 6];
|
|
||||||
v2z = vertices[ow1 + 7];
|
|
||||||
|
|
||||||
// N1
|
|
||||||
n1x = v2x - v1x;
|
|
||||||
n1y = v2y - v1y;
|
|
||||||
n1z = v2z - v1z;
|
|
||||||
|
|
||||||
// N2
|
|
||||||
n2x = v3x - v1x;
|
|
||||||
n2y = v3y - v1y;
|
|
||||||
n2z = v3z - v1z;
|
|
||||||
|
|
||||||
// Average of previous normal and N1 x N2
|
// Average of previous normal and N1 x N2
|
||||||
n3x = n3x * 0.5f + (n1y * n2z - n1z * n2y) * 0.5f;
|
vec3Sub(&n1, (struct vec3_s *)(vertices + ow1 + 5), (struct vec3_s *)(vertices + o + 5));
|
||||||
n3y = n3y * 0.5f + (n1z * n2x - n1x * n2z) * 0.5f;
|
vec3Cross(&n2, &n1, &n2);
|
||||||
n3z = n3z * 0.5f + (n1x * n2y - n1y * n2x) * 0.5f;
|
vec3Add(&n3, &n3, &n2);
|
||||||
|
vec3Norm(&n3);
|
||||||
|
|
||||||
// Normalize
|
vertices[o + 0] = n3.x;
|
||||||
len = 1.0f / magf3(n3x, n3y, n3z);
|
vertices[o + 1] = n3.y;
|
||||||
n3x *= len;
|
vertices[o + 2] = -n3.z;
|
||||||
n3y *= len;
|
|
||||||
n3z *= len;
|
|
||||||
|
|
||||||
vertices[o + 0] = n3x;
|
|
||||||
vertices[o + 1] = n3y;
|
|
||||||
vertices[o + 2] = -n3z;
|
|
||||||
|
|
||||||
// reset Z
|
// reset Z
|
||||||
//vertices[(yOffset + x) << 3 + 7] = 0.0f;
|
//vertices[(yOffset + x) << 3 + 7] = 0.0f;
|
||||||
@@ -433,15 +397,15 @@ void drawSky() {
|
|||||||
bindProgramFragmentStore(NAMED_PFSLeaf);
|
bindProgramFragmentStore(NAMED_PFSLeaf);
|
||||||
bindTexture(NAMED_PFSky, 0, NAMED_TSky);
|
bindTexture(NAMED_PFSky, 0, NAMED_TSky);
|
||||||
|
|
||||||
float x = State->skyOffsetX + State->skySpeedX;
|
float x = g_SkyOffsetX + State->skySpeedX;
|
||||||
float y = State->skyOffsetY + State->skySpeedY;
|
float y = g_SkyOffsetY + State->skySpeedY;
|
||||||
|
|
||||||
if (x > 1.0f) x = 0.0f;
|
if (x > 1.0f) x = 0.0f;
|
||||||
if (x < -1.0f) x = 0.0f;
|
if (x < -1.0f) x = 0.0f;
|
||||||
if (y > 1.0f) y = 0.0f;
|
if (y > 1.0f) y = 0.0f;
|
||||||
|
|
||||||
storeF(RSID_STATE, OFFSETOF_WorldState_skyOffsetX, x);
|
g_SkyOffsetX = x;
|
||||||
storeF(RSID_STATE, OFFSETOF_WorldState_skyOffsetY, y);
|
g_SkyOffsetY = y;
|
||||||
|
|
||||||
float matrix[16];
|
float matrix[16];
|
||||||
matrixLoadTranslate(matrix, x, y, 0.0f);
|
matrixLoadTranslate(matrix, x, y, 0.0f);
|
||||||
@@ -509,7 +473,7 @@ int main(int index) {
|
|||||||
drawRiverbed();
|
drawRiverbed();
|
||||||
drawSky();
|
drawSky();
|
||||||
drawLighting();
|
drawLighting();
|
||||||
drawLeaves();
|
//drawLeaves();
|
||||||
//drawNormals();
|
//drawNormals();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class FallRS {
|
|||||||
private static final int MESH_RESOLUTION = 48;
|
private static final int MESH_RESOLUTION = 48;
|
||||||
|
|
||||||
private static final int RSID_STATE = 0;
|
private static final int RSID_STATE = 0;
|
||||||
|
|
||||||
private static final int TEXTURES_COUNT = 3;
|
private static final int TEXTURES_COUNT = 3;
|
||||||
private static final int LEAVES_TEXTURES_COUNT = 4;
|
private static final int LEAVES_TEXTURES_COUNT = 4;
|
||||||
private static final int RSID_TEXTURE_RIVERBED = 0;
|
private static final int RSID_TEXTURE_RIVERBED = 0;
|
||||||
@@ -52,7 +52,7 @@ class FallRS {
|
|||||||
private static final int RSID_TEXTURE_SKY = 2;
|
private static final int RSID_TEXTURE_SKY = 2;
|
||||||
|
|
||||||
private static final int RSID_RIPPLE_MAP = 1;
|
private static final int RSID_RIPPLE_MAP = 1;
|
||||||
|
|
||||||
private static final int RSID_REFRACTION_MAP = 2;
|
private static final int RSID_REFRACTION_MAP = 2;
|
||||||
|
|
||||||
private static final int RSID_LEAVES = 3;
|
private static final int RSID_LEAVES = 3;
|
||||||
@@ -70,7 +70,21 @@ class FallRS {
|
|||||||
private static final int LEAF_STRUCT_DELTAX = 9;
|
private static final int LEAF_STRUCT_DELTAX = 9;
|
||||||
private static final int LEAF_STRUCT_DELTAY = 10;
|
private static final int LEAF_STRUCT_DELTAY = 10;
|
||||||
|
|
||||||
private static final int RSID_DROP = 4;
|
class Leaf {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float scale;
|
||||||
|
float angle;
|
||||||
|
float spin;
|
||||||
|
float u1;
|
||||||
|
float u2;
|
||||||
|
float altitude;
|
||||||
|
float rippled;
|
||||||
|
float deltaX;
|
||||||
|
float deltaY;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int RSID_DROP = 4;
|
||||||
|
|
||||||
private Resources mResources;
|
private Resources mResources;
|
||||||
private RenderScript mRS;
|
private RenderScript mRS;
|
||||||
@@ -175,10 +189,10 @@ class FallRS {
|
|||||||
|
|
||||||
float quadWidth = 2.0f / (float) wResolution;
|
float quadWidth = 2.0f / (float) wResolution;
|
||||||
float quadHeight = glHeight / (float) hResolution;
|
float quadHeight = glHeight / (float) hResolution;
|
||||||
|
|
||||||
wResolution += 2;
|
wResolution += 2;
|
||||||
hResolution += 2;
|
hResolution += 2;
|
||||||
|
|
||||||
for (int y = 0; y <= hResolution; y++) {
|
for (int y = 0; y <= hResolution; y++) {
|
||||||
final boolean shift = (y & 0x1) == 0;
|
final boolean shift = (y & 0x1) == 0;
|
||||||
final float yOffset = y * quadHeight - glHeight / 2.0f - quadHeight;
|
final float yOffset = y * quadHeight - glHeight / 2.0f - quadHeight;
|
||||||
@@ -267,12 +281,10 @@ class FallRS {
|
|||||||
public int leavesCount;
|
public int leavesCount;
|
||||||
public float glWidth;
|
public float glWidth;
|
||||||
public float glHeight;
|
public float glHeight;
|
||||||
public float skyOffsetX;
|
|
||||||
public float skyOffsetY;
|
|
||||||
public float skySpeedX;
|
public float skySpeedX;
|
||||||
public float skySpeedY;
|
public float skySpeedY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class DropState {
|
static class DropState {
|
||||||
public int dropX;
|
public int dropX;
|
||||||
public int dropY;
|
public int dropY;
|
||||||
@@ -295,11 +307,11 @@ class FallRS {
|
|||||||
mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
|
mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
|
||||||
mState = Allocation.createTyped(mRS, mStateType);
|
mState = Allocation.createTyped(mRS, mStateType);
|
||||||
mState.data(worldState);
|
mState.data(worldState);
|
||||||
|
|
||||||
mDrop = new DropState();
|
mDrop = new DropState();
|
||||||
mDrop.dropX = -1;
|
mDrop.dropX = -1;
|
||||||
mDrop.dropY = -1;
|
mDrop.dropY = -1;
|
||||||
|
|
||||||
mDropType = Type.createFromClass(mRS, DropState.class, 1, "DropState");
|
mDropType = Type.createFromClass(mRS, DropState.class, 1, "DropState");
|
||||||
mDropState = Allocation.createTyped(mRS, mDropType);
|
mDropState = Allocation.createTyped(mRS, mDropType);
|
||||||
mDropState.data(mDrop);
|
mDropState.data(mDrop);
|
||||||
@@ -346,7 +358,7 @@ class FallRS {
|
|||||||
final Allocation allocation = Allocation.createFromBitmap(mRS, b, RGBA_8888, false);
|
final Allocation allocation = Allocation.createFromBitmap(mRS, b, RGBA_8888, false);
|
||||||
allocation.setName(name);
|
allocation.setName(name);
|
||||||
return allocation;
|
return allocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createProgramFragment() {
|
private void createProgramFragment() {
|
||||||
Sampler.Builder sampleBuilder = new Sampler.Builder(mRS);
|
Sampler.Builder sampleBuilder = new Sampler.Builder(mRS);
|
||||||
@@ -368,7 +380,7 @@ class FallRS {
|
|||||||
mPfLighting = builder.create();
|
mPfLighting = builder.create();
|
||||||
mPfLighting.setName("PFLighting");
|
mPfLighting.setName("PFLighting");
|
||||||
mPfLighting.bindSampler(sampler, 0);
|
mPfLighting.bindSampler(sampler, 0);
|
||||||
|
|
||||||
builder = new ProgramFragment.Builder(mRS, null, null);
|
builder = new ProgramFragment.Builder(mRS, null, null);
|
||||||
builder.setTexEnable(true, 0);
|
builder.setTexEnable(true, 0);
|
||||||
builder.setTexEnvMode(MODULATE, 0);
|
builder.setTexEnvMode(MODULATE, 0);
|
||||||
@@ -407,7 +419,7 @@ class FallRS {
|
|||||||
mPvLight = builder.create();
|
mPvLight = builder.create();
|
||||||
mPvLight.bindAllocation(pvOrthoAlloc);
|
mPvLight.bindAllocation(pvOrthoAlloc);
|
||||||
mPvLight.setName("PVLight");
|
mPvLight.setName("PVLight");
|
||||||
|
|
||||||
builder = new ProgramVertex.Builder(mRS, null, null);
|
builder = new ProgramVertex.Builder(mRS, null, null);
|
||||||
builder.setTextureMatrixEnable(true);
|
builder.setTextureMatrixEnable(true);
|
||||||
mPvSky = builder.create();
|
mPvSky = builder.create();
|
||||||
|
|||||||
@@ -39,10 +39,6 @@ ObjDestroy {
|
|||||||
ElementBegin {
|
ElementBegin {
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementAddPredefined {
|
|
||||||
param RsElementPredefined predef
|
|
||||||
}
|
|
||||||
|
|
||||||
ElementAdd {
|
ElementAdd {
|
||||||
param RsDataKind dataKind
|
param RsDataKind dataKind
|
||||||
param RsDataType dataType
|
param RsDataType dataType
|
||||||
@@ -99,8 +95,8 @@ AllocationCreateFromFile {
|
|||||||
AllocationCreateFromBitmap {
|
AllocationCreateFromBitmap {
|
||||||
param uint32_t width
|
param uint32_t width
|
||||||
param uint32_t height
|
param uint32_t height
|
||||||
param RsElementPredefined dstFmt
|
param RsElement dstFmt
|
||||||
param RsElementPredefined srcFmt
|
param RsElement srcFmt
|
||||||
param bool genMips
|
param bool genMips
|
||||||
param const void * data
|
param const void * data
|
||||||
ret RsAllocation
|
ret RsAllocation
|
||||||
@@ -109,8 +105,8 @@ AllocationCreateFromBitmap {
|
|||||||
AllocationCreateFromBitmapBoxed {
|
AllocationCreateFromBitmapBoxed {
|
||||||
param uint32_t width
|
param uint32_t width
|
||||||
param uint32_t height
|
param uint32_t height
|
||||||
param RsElementPredefined dstFmt
|
param RsElement dstFmt
|
||||||
param RsElementPredefined srcFmt
|
param RsElement srcFmt
|
||||||
param bool genMips
|
param bool genMips
|
||||||
param const void * data
|
param const void * data
|
||||||
ret RsAllocation
|
ret RsAllocation
|
||||||
|
|||||||
@@ -310,40 +310,54 @@ static void elementConverter_8888_to_565(void *dst, const void *src, uint32_t co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ElementConverter_t pickConverter(RsElementPredefined dstFmt, RsElementPredefined srcFmt)
|
static ElementConverter_t pickConverter(const Element *dst, const Element *src)
|
||||||
{
|
{
|
||||||
if ((dstFmt == RS_ELEMENT_RGB_565) &&
|
GLenum srcGLType = src->getGLType();
|
||||||
(srcFmt == RS_ELEMENT_RGB_565)) {
|
GLenum srcGLFmt = src->getGLFormat();
|
||||||
return elementConverter_cpy_16;
|
GLenum dstGLType = dst->getGLType();
|
||||||
|
GLenum dstGLFmt = dst->getGLFormat();
|
||||||
|
|
||||||
|
if (srcGLFmt == dstGLFmt && srcGLType == dstGLType) {
|
||||||
|
switch(dst->getSizeBytes()) {
|
||||||
|
case 4:
|
||||||
|
return elementConverter_cpy_32;
|
||||||
|
case 2:
|
||||||
|
return elementConverter_cpy_16;
|
||||||
|
case 1:
|
||||||
|
return elementConverter_cpy_8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dstFmt == RS_ELEMENT_RGB_565) &&
|
if (srcGLType == GL_UNSIGNED_BYTE &&
|
||||||
(srcFmt == RS_ELEMENT_RGB_888)) {
|
srcGLFmt == GL_RGB &&
|
||||||
|
dstGLType == GL_UNSIGNED_SHORT_5_6_5 &&
|
||||||
|
dstGLType == GL_RGB) {
|
||||||
|
|
||||||
return elementConverter_888_to_565;
|
return elementConverter_888_to_565;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dstFmt == RS_ELEMENT_RGB_565) &&
|
if (srcGLType == GL_UNSIGNED_BYTE &&
|
||||||
(srcFmt == RS_ELEMENT_RGBA_8888)) {
|
srcGLFmt == GL_RGBA &&
|
||||||
|
dstGLType == GL_UNSIGNED_SHORT_5_6_5 &&
|
||||||
|
dstGLType == GL_RGB) {
|
||||||
|
|
||||||
return elementConverter_8888_to_565;
|
return elementConverter_8888_to_565;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dstFmt == RS_ELEMENT_RGBA_8888) &&
|
LOGE("pickConverter, unsuported combo, src %p, dst %p", src, dst);
|
||||||
(srcFmt == RS_ELEMENT_RGBA_8888)) {
|
|
||||||
return elementConverter_cpy_32;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGE("pickConverter, unsuported combo, src %i, dst %i", srcFmt, dstFmt);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h, RsElementPredefined dstFmt, RsElementPredefined srcFmt, bool genMips, const void *data)
|
RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data)
|
||||||
{
|
{
|
||||||
|
const Element *src = static_cast<const Element *>(_src);
|
||||||
|
const Element *dst = static_cast<const Element *>(_dst);
|
||||||
rsAssert(!(w & (w-1)));
|
rsAssert(!(w & (w-1)));
|
||||||
rsAssert(!(h & (h-1)));
|
rsAssert(!(h & (h-1)));
|
||||||
|
|
||||||
//LOGE("rsi_AllocationCreateFromBitmap %i %i %i %i %i", w, h, dstFmt, srcFmt, genMips);
|
//LOGE("rsi_AllocationCreateFromBitmap %i %i %i %i %i", w, h, dstFmt, srcFmt, genMips);
|
||||||
rsi_TypeBegin(rsc, rsi_ElementGetPredefined(rsc, dstFmt));
|
rsi_TypeBegin(rsc, _dst);
|
||||||
rsi_TypeAdd(rsc, RS_DIMENSION_X, w);
|
rsi_TypeAdd(rsc, RS_DIMENSION_X, w);
|
||||||
rsi_TypeAdd(rsc, RS_DIMENSION_Y, h);
|
rsi_TypeAdd(rsc, RS_DIMENSION_Y, h);
|
||||||
if (genMips) {
|
if (genMips) {
|
||||||
@@ -359,7 +373,7 @@ RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h
|
|||||||
}
|
}
|
||||||
texAlloc->incUserRef();
|
texAlloc->incUserRef();
|
||||||
|
|
||||||
ElementConverter_t cvt = pickConverter(dstFmt, srcFmt);
|
ElementConverter_t cvt = pickConverter(dst, src);
|
||||||
cvt(texAlloc->getPtr(), data, w * h);
|
cvt(texAlloc->getPtr(), data, w * h);
|
||||||
|
|
||||||
if (genMips) {
|
if (genMips) {
|
||||||
@@ -375,21 +389,18 @@ RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h
|
|||||||
return texAlloc;
|
return texAlloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t fmtToBits(RsElementPredefined fmt)
|
RsAllocation rsi_AllocationCreateFromBitmapBoxed(Context *rsc, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data)
|
||||||
{
|
|
||||||
return 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
RsAllocation rsi_AllocationCreateFromBitmapBoxed(Context *rsc, uint32_t w, uint32_t h, RsElementPredefined dstFmt, RsElementPredefined srcFmt, bool genMips, const void *data)
|
|
||||||
{
|
{
|
||||||
|
const Element *srcE = static_cast<const Element *>(_src);
|
||||||
|
const Element *dstE = static_cast<const Element *>(_dst);
|
||||||
uint32_t w2 = rsHigherPow2(w);
|
uint32_t w2 = rsHigherPow2(w);
|
||||||
uint32_t h2 = rsHigherPow2(h);
|
uint32_t h2 = rsHigherPow2(h);
|
||||||
|
|
||||||
if ((w2 == w) && (h2 == h)) {
|
if ((w2 == w) && (h2 == h)) {
|
||||||
return rsi_AllocationCreateFromBitmap(rsc, w, h, dstFmt, srcFmt, genMips, data);
|
return rsi_AllocationCreateFromBitmap(rsc, w, h, _dst, _src, genMips, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t bpp = fmtToBits(srcFmt) >> 3;
|
uint32_t bpp = srcE->getSizeBytes();
|
||||||
size_t size = w2 * h2 * bpp;
|
size_t size = w2 * h2 * bpp;
|
||||||
uint8_t *tmp = static_cast<uint8_t *>(malloc(size));
|
uint8_t *tmp = static_cast<uint8_t *>(malloc(size));
|
||||||
memset(tmp, 0, size);
|
memset(tmp, 0, size);
|
||||||
@@ -401,7 +412,7 @@ RsAllocation rsi_AllocationCreateFromBitmapBoxed(Context *rsc, uint32_t w, uint3
|
|||||||
src += w * bpp;
|
src += w * bpp;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsAllocation ret = rsi_AllocationCreateFromBitmap(rsc, w2, h2, dstFmt, srcFmt, genMips, tmp);
|
RsAllocation ret = rsi_AllocationCreateFromBitmap(rsc, w2, h2, _dst, _src, genMips, tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|||||||
@@ -184,10 +184,10 @@ void Context::timerPrint()
|
|||||||
|
|
||||||
LOGV("RS: Frame (%lli), Script %2.1f (%lli), Clear & Swap %2.1f (%lli), Idle %2.1f (%lli), Internal %2.1f (%lli)",
|
LOGV("RS: Frame (%lli), Script %2.1f (%lli), Clear & Swap %2.1f (%lli), Idle %2.1f (%lli), Internal %2.1f (%lli)",
|
||||||
frame / 1000000,
|
frame / 1000000,
|
||||||
100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
|
|
||||||
100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000,
|
|
||||||
100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimers[RS_TIMER_SCRIPT] / 1000000,
|
100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimers[RS_TIMER_SCRIPT] / 1000000,
|
||||||
100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimers[RS_TIMER_CLEAR_SWAP] / 1000000);
|
100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimers[RS_TIMER_CLEAR_SWAP] / 1000000,
|
||||||
|
100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
|
||||||
|
100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::setupCheck()
|
void Context::setupCheck()
|
||||||
|
|||||||
@@ -286,6 +286,10 @@ void ScriptCState::appendTypes(String8 *str)
|
|||||||
char buf[256];
|
char buf[256];
|
||||||
String8 tmp;
|
String8 tmp;
|
||||||
|
|
||||||
|
str->append("struct vec2_s {float x; float y;};");
|
||||||
|
str->append("struct vec3_s {float x; float y; float z;};");
|
||||||
|
str->append("struct vec4_s {float x; float y; float z; float w;};");
|
||||||
|
|
||||||
for (size_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
|
for (size_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
|
||||||
const Type *t = mConstantBufferTypes[ct].get();
|
const Type *t = mConstantBufferTypes[ct].get();
|
||||||
if (!t) {
|
if (!t) {
|
||||||
|
|||||||
@@ -36,6 +36,23 @@ using namespace android::renderscript;
|
|||||||
Context * rsc = tls->mContext; \
|
Context * rsc = tls->mContext; \
|
||||||
ScriptC * sc = (ScriptC *) tls->mScript
|
ScriptC * sc = (ScriptC *) tls->mScript
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
} vec3_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
float w;
|
||||||
|
} vec4_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
} vec2_t;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// IO routines
|
// IO routines
|
||||||
@@ -161,6 +178,60 @@ static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
|
|||||||
memcpy(&f[offset], m, sizeof(rsc_Matrix));
|
memcpy(&f[offset], m, sizeof(rsc_Matrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Vec3 routines
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
static void SC_vec3Norm(vec3_t *v)
|
||||||
|
{
|
||||||
|
float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
|
||||||
|
len = 1 / len;
|
||||||
|
v->x *= len;
|
||||||
|
v->y *= len;
|
||||||
|
v->z *= len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float SC_vec3Length(const vec3_t *v)
|
||||||
|
{
|
||||||
|
return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SC_vec3Add(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
|
||||||
|
{
|
||||||
|
dest->x = lhs->x + rhs->x;
|
||||||
|
dest->y = lhs->y + rhs->y;
|
||||||
|
dest->z = lhs->z + rhs->z;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SC_vec3Sub(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
|
||||||
|
{
|
||||||
|
dest->x = lhs->x - rhs->x;
|
||||||
|
dest->y = lhs->y - rhs->y;
|
||||||
|
dest->z = lhs->z - rhs->z;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SC_vec3Cross(vec3_t *dest, const vec3_t *lhs, const vec3_t *rhs)
|
||||||
|
{
|
||||||
|
float x = lhs->y * rhs->z - lhs->z * rhs->y;
|
||||||
|
float y = lhs->z * rhs->x - lhs->x * rhs->z;
|
||||||
|
float z = lhs->x * rhs->y - lhs->y * rhs->x;
|
||||||
|
dest->x = x;
|
||||||
|
dest->y = y;
|
||||||
|
dest->z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float SC_vec3Dot(const vec3_t *lhs, const vec3_t *rhs)
|
||||||
|
{
|
||||||
|
return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SC_vec3Scale(vec3_t *lhs, float scale)
|
||||||
|
{
|
||||||
|
lhs->x *= scale;
|
||||||
|
lhs->y *= scale;
|
||||||
|
lhs->z *= scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// Math routines
|
// Math routines
|
||||||
@@ -175,15 +246,15 @@ static float SC_sinf_fast(float x)
|
|||||||
const float A = 1.0f / (2.0f * M_PI);
|
const float A = 1.0f / (2.0f * M_PI);
|
||||||
const float B = -16.0f;
|
const float B = -16.0f;
|
||||||
const float C = 8.0f;
|
const float C = 8.0f;
|
||||||
|
|
||||||
// scale angle for easy argument reduction
|
// scale angle for easy argument reduction
|
||||||
x *= A;
|
x *= A;
|
||||||
|
|
||||||
if (fabsf(x) >= 0.5f) {
|
if (fabsf(x) >= 0.5f) {
|
||||||
// argument reduction
|
// argument reduction
|
||||||
x = x - ceilf(x + 0.5f) + 1.0f;
|
x = x - ceilf(x + 0.5f) + 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float y = B * x * fabsf(x) + C * x;
|
const float y = B * x * fabsf(x) + C * x;
|
||||||
return 0.2215f * (y * fabsf(y) - y) + y;
|
return 0.2215f * (y * fabsf(y) - y) + y;
|
||||||
}
|
}
|
||||||
@@ -195,15 +266,15 @@ static float SC_cosf_fast(float x)
|
|||||||
const float A = 1.0f / (2.0f * M_PI);
|
const float A = 1.0f / (2.0f * M_PI);
|
||||||
const float B = -16.0f;
|
const float B = -16.0f;
|
||||||
const float C = 8.0f;
|
const float C = 8.0f;
|
||||||
|
|
||||||
// scale angle for easy argument reduction
|
// scale angle for easy argument reduction
|
||||||
x *= A;
|
x *= A;
|
||||||
|
|
||||||
if (fabsf(x) >= 0.5f) {
|
if (fabsf(x) >= 0.5f) {
|
||||||
// argument reduction
|
// argument reduction
|
||||||
x = x - ceilf(x + 0.5f) + 1.0f;
|
x = x - ceilf(x + 0.5f) + 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float y = B * x * fabsf(x) + C * x;
|
const float y = B * x * fabsf(x) + C * x;
|
||||||
return 0.2215f * (y * fabsf(y) - y) + y;
|
return 0.2215f * (y * fabsf(y) - y) + y;
|
||||||
}
|
}
|
||||||
@@ -1038,6 +1109,22 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
|
|||||||
{ "vec2Rand", (void *)&SC_vec2Rand,
|
{ "vec2Rand", (void *)&SC_vec2Rand,
|
||||||
"void", "(float *vec, float maxLen)" },
|
"void", "(float *vec, float maxLen)" },
|
||||||
|
|
||||||
|
// vec3
|
||||||
|
{ "vec3Norm", (void *)&SC_vec3Norm,
|
||||||
|
"void", "(struct vec3_s *)" },
|
||||||
|
{ "vec3Length", (void *)&SC_vec3Length,
|
||||||
|
"float", "(struct vec3_s *)" },
|
||||||
|
{ "vec3Add", (void *)&SC_vec3Add,
|
||||||
|
"void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
|
||||||
|
{ "vec3Sub", (void *)&SC_vec3Sub,
|
||||||
|
"void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
|
||||||
|
{ "vec3Cross", (void *)&SC_vec3Cross,
|
||||||
|
"void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
|
||||||
|
{ "vec3Dot", (void *)&SC_vec3Dot,
|
||||||
|
"float", "(struct vec3_s *lhs, struct vec3_s *rhs)" },
|
||||||
|
{ "vec3Scale", (void *)&SC_vec3Scale,
|
||||||
|
"void", "(struct vec3_s *lhs, float scale)" },
|
||||||
|
|
||||||
// context
|
// context
|
||||||
{ "bindProgramFragment", (void *)&SC_bindProgramFragment,
|
{ "bindProgramFragment", (void *)&SC_bindProgramFragment,
|
||||||
"void", "(int)" },
|
"void", "(int)" },
|
||||||
|
|||||||
Reference in New Issue
Block a user