summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/Color.java3
-rw-r--r--graphics/java/android/graphics/Typeface.java3
-rw-r--r--graphics/java/android/graphics/drawable/GradientDrawable.java4
-rw-r--r--graphics/java/android/renderscript/Allocation.java27
-rw-r--r--graphics/java/android/renderscript/BaseObj.java1
-rw-r--r--graphics/java/android/renderscript/Element.java553
-rw-r--r--graphics/java/android/renderscript/Program.java144
-rw-r--r--graphics/java/android/renderscript/ProgramFragment.java167
-rw-r--r--graphics/java/android/renderscript/ProgramVertex.java69
-rw-r--r--graphics/java/android/renderscript/RenderScript.java57
-rw-r--r--graphics/java/android/renderscript/Sampler.java32
-rw-r--r--graphics/java/android/renderscript/SimpleMesh.java26
-rw-r--r--graphics/java/android/renderscript/Type.java11
13 files changed, 598 insertions, 499 deletions
diff --git a/graphics/java/android/graphics/Color.java b/graphics/java/android/graphics/Color.java
index 5cefaa3..a50693d 100644
--- a/graphics/java/android/graphics/Color.java
+++ b/graphics/java/android/graphics/Color.java
@@ -30,7 +30,8 @@ import java.util.Locale;
* (green << 8) | blue. Each component ranges between 0..255 with 0
* meaning no contribution for that component, and 255 meaning 100%
* contribution. Thus opaque-black would be 0xFF000000 (100% opaque but
- * no contributes from red, gree, blue, and opaque-white would be 0xFFFFFFFF
+ * no contributions from red, green, or blue), and opaque-white would be
+ * 0xFFFFFFFF
*/
public class Color {
public static final int BLACK = 0xFF000000;
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index f0d5a6a..9a404f4 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -143,6 +143,9 @@ public class Typeface {
// don't allow clients to call this directly
private Typeface(int ni) {
+ if (ni == 0) {
+ throw new IllegalStateException();
+ }
native_instance = ni;
}
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index 91a2bc1..63d1446 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -778,8 +778,8 @@ public class GradientDrawable extends Drawable {
com.android.internal.R.styleable.DrawableCorners_bottomLeftRadius, radius);
int bottomRightRadius = a.getDimensionPixelSize(
com.android.internal.R.styleable.DrawableCorners_bottomRightRadius, radius);
- if (topLeftRadius != radius && topRightRadius != radius &&
- bottomLeftRadius != radius && bottomRightRadius != radius) {
+ if (topLeftRadius != radius || topRightRadius != radius ||
+ bottomLeftRadius != radius || bottomRightRadius != radius) {
setCornerRadii(new float[] {
topLeftRadius, topLeftRadius,
topRightRadius, topRightRadius,
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index b6ac14a..e5cf38e 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -39,15 +39,17 @@ public class Allocation extends BaseObj {
mType = t;
}
+ public Type getType() {
+ return mType;
+ }
+
public void uploadToTexture(int baseMipLevel) {
mRS.validate();
- mRS.validateSurface();
mRS.nAllocationUploadToTexture(mID, baseMipLevel);
}
public void uploadToBufferObject() {
mRS.validate();
- mRS.validateSurface();
mRS.nAllocationUploadToBufferObject(mID);
}
@@ -171,9 +173,10 @@ public class Allocation extends BaseObj {
public Adapter1D createAdapter1D() {
mRS.validate();
int id = mRS.nAdapter1DCreate();
- if (id != 0) {
- mRS.nAdapter1DBindAllocation(id, mID);
+ if(id == 0) {
+ throw new IllegalStateException("allocation failed.");
}
+ mRS.nAdapter1DBindAllocation(id, mID);
return new Adapter1D(id, mRS);
}
@@ -213,9 +216,10 @@ public class Allocation extends BaseObj {
public Adapter2D createAdapter2D() {
mRS.validate();
int id = mRS.nAdapter2DCreate();
- if (id != 0) {
- mRS.nAdapter2DBindAllocation(id, mID);
+ if(id == 0) {
+ throw new IllegalStateException("allocation failed.");
}
+ mRS.nAdapter2DBindAllocation(id, mID);
return new Adapter2D(id, mRS);
}
@@ -258,14 +262,20 @@ public class Allocation extends BaseObj {
rs.validate();
int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(id, rs, null);
}
- static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
+ static Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
throws IllegalArgumentException {
rs.validate();
int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(id, rs, null);
}
@@ -282,6 +292,9 @@ public class Allocation extends BaseObj {
int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mID, genMips,
asset);
+ if(allocationId == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(allocationId, rs, null);
} catch (Exception e) {
// Ignore
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java
index e802ec5..002fc78 100644
--- a/graphics/java/android/renderscript/BaseObj.java
+++ b/graphics/java/android/renderscript/BaseObj.java
@@ -25,6 +25,7 @@ import android.util.Log;
class BaseObj {
BaseObj(RenderScript rs) {
+ rs.validate();
mRS = rs;
mID = 0;
mDestroyed = false;
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index ee9b098..10ef05a 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -24,259 +24,220 @@ 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;
+
+ int getSizeBytes() {return mSize;}
+
+ public enum DataType {
+ //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;
+ int mSize;
+ DataType(int id, int size) {
+ mID = id;
+ mSize = size;
+ }
}
- 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 enum DataKind {
+ USER (0),
+ 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) {
+ mID = id;
}
}
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();
+ 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 = new Element(rs, 1);
- rs.mElement_USER_I8.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 8, null);
- rs.mElement_USER_I8.init();
+ rs.mElement_USER_I8 = createUser(rs, DataType.SIGNED_8);
}
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();
+ 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 = new Element(rs, 1);
- rs.mElement_USER_I32.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 32, null);
- rs.mElement_USER_I32.init();
+ 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_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();
+ if(rs.mElement_USER_F32 == null) {
+ rs.mElement_USER_F32 = createUser(rs, DataType.FLOAT_32);
}
- return rs.mElement_USER_FLOAT;
+ return rs.mElement_USER_F32;
}
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();
+ 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 = 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();
+ 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 = 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();
+ 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 = 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();
+ 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 = 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();
+ 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 = 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();
+ 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 = new Element(rs, 1);
- rs.mElement_INDEX_16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.INDEX, false, 16, "index");
- rs.mElement_INDEX_16.init();
+ rs.mElement_INDEX_16 = createIndex(rs);
}
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();
+ 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_XY_F32;
+ return rs.mElement_POSITION_2;
}
- 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();
+ 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_XYZ_F32;
+ return rs.mElement_POSITION_3;
}
- static void initPredefined(RenderScript rs) {
- rs.nInitElements(A_8(rs).mID, RGBA_4444(rs).mID, RGBA_8888(rs).mID, RGB_565(rs).mID);
+ 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 enum DataType {
- FLOAT (0),
- UNSIGNED (1),
- SIGNED (2);
-
- int mID;
- DataType(int id) {
- mID = id;
+ 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 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);
+ 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;
+ }
- int mID;
- DataKind(int id) {
- mID = id;
+ 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, int count) {
+ 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,157 @@ 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;
- }
- }
- e.mID = rs.nElementCreate();
- e.mSize = (bits + 7) >> 3;
- }
- void init() {
- mRS.validate();
- internalCreate(mRS, this);
+ /////////////////////////////////////////
+ public static Element createUser(RenderScript rs, DataType dt) {
+ return new Element(rs, dt, DataKind.USER, false, 1);
}
-
- public static class Builder {
- RenderScript mRS;
- Entry[] mEntries;
- int mEntryCount;
-
- public Builder(RenderScript rs) {
- mRS = rs;
- mEntryCount = 0;
- mEntries = new Entry[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;
- }
- mEntries[mEntryCount] = e;
- mEntryCount++;
+ public static Element createVector(RenderScript rs, DataType dt, int size) {
+ if (size < 2 || size > 4) {
+ throw new IllegalArgumentException("Bad size");
}
+ return new Element(rs, dt, DataKind.USER, false, size);
+ }
- //public Builder add(Element e) throws IllegalArgumentException {
- //Entry en = new Entry(e, e.mSize * 8);
- //addEntry(en);
- //return this;
- //}
+ public static Element createIndex(RenderScript rs) {
+ return new Element(rs, DataType.UNSIGNED_16, DataKind.INDEX, false, 1);
+ }
- 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 static Element createAttrib(RenderScript rs, DataType dt, DataKind dk, int 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");
}
- public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) {
- add(dt, dk, isNormalized, bits, null);
- return this;
+ if (!(dk == DataKind.COLOR ||
+ dk == DataKind.POSITION ||
+ dk == DataKind.TEXTURE ||
+ dk == DataKind.NORMAL ||
+ dk == DataKind.POINT_SIZE ||
+ dk == DataKind.USER)) {
+ throw new IllegalArgumentException("Unsupported DataKind");
}
- public Builder addFloat(Element.DataKind dk) {
- add(DataType.FLOAT, dk, false, 32, null);
- return this;
+ if (dk == DataKind.COLOR &&
+ ((dt != DataType.FLOAT_32 && dt != DataType.UNSIGNED_8) ||
+ size < 3 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloat(Element.DataKind dk, String name) {
- add(DataType.FLOAT, dk, false, 32, name);
- return this;
+ if (dk == DataKind.POSITION && (size < 1 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXY() {
- add(DataType.FLOAT, DataKind.X, false, 32, null);
- add(DataType.FLOAT, DataKind.Y, false, 32, null);
- return this;
+ if (dk == DataKind.TEXTURE &&
+ (dt != DataType.FLOAT_32 || size < 1 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- 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;
+ if (dk == DataKind.NORMAL &&
+ (dt != DataType.FLOAT_32 || size != 3)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- 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;
+ if (dk == DataKind.POINT_SIZE &&
+ (dt != DataType.FLOAT_32 || size != 1)) {
+ throw new IllegalArgumentException("Bad combo");
}
- 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;
+ boolean norm = false;
+ if (dk == DataKind.COLOR && dt == DataType.UNSIGNED_8) {
+ norm = true;
}
- public Builder addFloatST() {
- add(DataType.FLOAT, DataKind.S, false, 32, null);
- add(DataType.FLOAT, DataKind.T, false, 32, null);
- return this;
- }
+ return new Element(rs, dt, dk, norm, size);
+ }
- 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 static Element createPixel(RenderScript rs, DataType dt, DataKind dk) {
+ 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");
}
-
- 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;
+ 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");
}
-
- 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;
+ if (dt == DataType.UNSIGNED_5_6_5 && dk != DataKind.PIXEL_RGB) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
-
- public Builder addFloatPointSize() {
- add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, null);
- return this;
+ if (dt == DataType.UNSIGNED_5_5_5_1 && dk != DataKind.PIXEL_RGBA) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
-
- public Builder addFloatPointSize(String prefix) {
- add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, prefix + "pointSize");
- return this;
+ if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
- 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;
+ int size = 1;
+ if (dk == DataKind.PIXEL_LA) {
+ size = 2;
}
-
- 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;
+ if (dk == DataKind.PIXEL_RGB) {
+ size = 3;
}
-
- 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;
+ if (dk == DataKind.PIXEL_RGBA) {
+ size = 4;
}
- 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;
- }
+ return new Element(rs, dt, dk, true, size);
+ }
- 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 static class Builder {
+ RenderScript mRS;
+ Element[] mElements;
+ String[] mElementNames;
+ int mCount;
- 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;
+ public Builder(RenderScript rs) {
+ mRS = rs;
+ mCount = 0;
+ mElements = new Element[8];
+ mElementNames = new String[8];
+ }
+
+ 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;
+ }
+ 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);
+ }
}
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
new file mode 100644
index 0000000..1614ec5
--- /dev/null
+++ b/graphics/java/android/renderscript/Program.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+
+import android.util.Config;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Program extends BaseObj {
+ public static final int MAX_INPUT = 8;
+ public static final int MAX_OUTPUT = 8;
+ public static final int MAX_CONSTANT = 8;
+ public static final int MAX_TEXTURE = 8;
+
+ Element mInputs[];
+ Element mOutputs[];
+ Type mConstants[];
+ int mTextureCount;
+ String mShader;
+
+ Program(int id, RenderScript rs) {
+ super(rs);
+ mID = id;
+ }
+
+ public void bindConstants(Allocation a, int slot) {
+ mRS.nProgramBindConstants(mID, slot, a.mID);
+ }
+
+ public void bindTexture(Allocation va, int slot)
+ throws IllegalArgumentException {
+ mRS.validate();
+ if((slot < 0) || (slot >= mTextureCount)) {
+ throw new IllegalArgumentException("Slot ID out of range.");
+ }
+
+ mRS.nProgramBindTexture(mID, slot, va.mID);
+ }
+
+ public void bindSampler(Sampler vs, int slot)
+ throws IllegalArgumentException {
+ mRS.validate();
+ if((slot < 0) || (slot >= mTextureCount)) {
+ throw new IllegalArgumentException("Slot ID out of range.");
+ }
+
+ mRS.nProgramBindSampler(mID, slot, vs.mID);
+ }
+
+
+ public static class BaseProgramBuilder {
+ RenderScript mRS;
+ Element mInputs[];
+ Element mOutputs[];
+ Type mConstants[];
+ Type mTextures[];
+ int mInputCount;
+ int mOutputCount;
+ int mConstantCount;
+ int mTextureCount;
+ String mShader;
+
+
+ protected BaseProgramBuilder(RenderScript rs) {
+ mRS = rs;
+ mInputs = new Element[MAX_INPUT];
+ mOutputs = new Element[MAX_OUTPUT];
+ mConstants = new Type[MAX_CONSTANT];
+ mInputCount = 0;
+ mOutputCount = 0;
+ mConstantCount = 0;
+ mTextureCount = 0;
+ }
+
+ public void setShader(String s) {
+ mShader = s;
+ }
+
+ public void addInput(Element e) throws IllegalStateException {
+ // Should check for consistant and non-conflicting names...
+ if(mInputCount >= MAX_INPUT) {
+ throw new IllegalArgumentException("Max input count exceeded.");
+ }
+ mInputs[mInputCount++] = e;
+ }
+
+ public void addOutput(Element e) throws IllegalStateException {
+ // Should check for consistant and non-conflicting names...
+ if(mOutputCount >= MAX_OUTPUT) {
+ throw new IllegalArgumentException("Max output count exceeded.");
+ }
+ mOutputs[mOutputCount++] = e;
+ }
+
+ public int addConstant(Type t) throws IllegalStateException {
+ // Should check for consistant and non-conflicting names...
+ if(mConstantCount >= MAX_CONSTANT) {
+ throw new IllegalArgumentException("Max input count exceeded.");
+ }
+ mConstants[mConstantCount] = t;
+ return mConstantCount++;
+ }
+
+ public void setTextureCount(int count) throws IllegalArgumentException {
+ // Should check for consistant and non-conflicting names...
+ if(count >= MAX_CONSTANT) {
+ throw new IllegalArgumentException("Max texture count exceeded.");
+ }
+ mTextureCount = count;
+ }
+
+ protected void initProgram(Program p) {
+ p.mInputs = new Element[mInputCount];
+ System.arraycopy(mInputs, 0, p.mInputs, 0, mInputCount);
+ p.mOutputs = new Element[mOutputCount];
+ System.arraycopy(mOutputs, 0, p.mOutputs, 0, mOutputCount);
+ p.mConstants = new Type[mConstantCount];
+ System.arraycopy(mConstants, 0, p.mConstants, 0, mConstantCount);
+ p.mTextureCount = mTextureCount;
+ }
+ }
+
+}
+
+
diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java
index 1a72578..5e04f0c 100644
--- a/graphics/java/android/renderscript/ProgramFragment.java
+++ b/graphics/java/android/renderscript/ProgramFragment.java
@@ -25,134 +25,115 @@ import android.util.Log;
* @hide
*
**/
-public class ProgramFragment extends BaseObj {
- public static final int MAX_SLOT = 2;
-
- public enum EnvMode {
- REPLACE (0),
- MODULATE (1),
- DECAL (2);
-
- int mID;
- EnvMode(int id) {
- mID = id;
- }
- }
-
-
+public class ProgramFragment extends Program {
ProgramFragment(int id, RenderScript rs) {
- super(rs);
- mID = id;
+ super(id, rs);
}
- public void bindTexture(Allocation va, int slot)
- throws IllegalArgumentException {
- mRS.validate();
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ public static class ShaderBuilder extends BaseProgramBuilder {
+ public ShaderBuilder(RenderScript rs) {
+ super(rs);
}
- mRS.nProgramFragmentBindTexture(mID, slot, va.mID);
- }
+ public ProgramFragment create() {
+ mRS.validate();
+ int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + 1) * 2];
+ int idx = 0;
- public void bindSampler(Sampler vs, int slot)
- throws IllegalArgumentException {
- mRS.validate();
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
- }
+ for (int i=0; i < mInputCount; i++) {
+ tmp[idx++] = 0;
+ tmp[idx++] = mInputs[i].mID;
+ }
+ for (int i=0; i < mOutputCount; i++) {
+ tmp[idx++] = 1;
+ tmp[idx++] = mOutputs[i].mID;
+ }
+ for (int i=0; i < mConstantCount; i++) {
+ tmp[idx++] = 2;
+ tmp[idx++] = mConstants[i].mID;
+ }
+ tmp[idx++] = 3;
+ tmp[idx++] = mTextureCount;
- mRS.nProgramFragmentBindSampler(mID, slot, vs.mID);
+ int id = mRS.nProgramFragmentCreate2(mShader, tmp);
+ ProgramFragment pf = new ProgramFragment(id, mRS);
+ initProgram(pf);
+ return pf;
+ }
}
-
public static class Builder {
+ public static final int MAX_TEXTURE = 2;
RenderScript mRS;
- Element mIn;
- Element mOut;
boolean mPointSpriteEnable;
- private class Slot {
- Type mType;
- EnvMode mEnv;
- boolean mTexEnable;
+ public enum EnvMode {
+ REPLACE (1),
+ MODULATE (2),
+ DECAL (3);
- Slot() {
- mTexEnable = false;
+ int mID;
+ EnvMode(int id) {
+ mID = id;
}
}
- Slot[] mSlots;
- public Builder(RenderScript rs, Element in, Element out) {
- mRS = rs;
- mIn = in;
- mOut = out;
- mSlots = new Slot[MAX_SLOT];
- mPointSpriteEnable = false;
- for(int ct=0; ct < MAX_SLOT; ct++) {
- mSlots[ct] = new Slot();
- }
- }
+ public enum Format {
+ ALPHA (1),
+ LUMINANCE_ALPHA (2),
+ RGB (3),
+ RGBA (4);
- public void setType(int slot, Type t)
- throws IllegalArgumentException {
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ int mID;
+ Format(int id) {
+ mID = id;
}
-
- mSlots[slot].mType = t;
}
- public void setTexEnable(boolean enable, int slot)
- throws IllegalArgumentException {
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ private class Slot {
+ EnvMode env;
+ Format format;
+ Slot(EnvMode _env, Format _fmt) {
+ env = _env;
+ format = _fmt;
}
+ }
+ Slot[] mSlots;
- mSlots[slot].mTexEnable = enable;
+ public Builder(RenderScript rs) {
+ mRS = rs;
+ mSlots = new Slot[MAX_TEXTURE];
+ mPointSpriteEnable = false;
}
- public void setTexEnvMode(EnvMode env, int slot)
+ public void setTexture(EnvMode env, Format fmt, int slot)
throws IllegalArgumentException {
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ if((slot < 0) || (slot >= MAX_TEXTURE)) {
+ throw new IllegalArgumentException("MAX_TEXTURE exceeded.");
}
-
- mSlots[slot].mEnv = env;
+ mSlots[slot] = new Slot(env, fmt);
}
public void setPointSpriteTexCoordinateReplacement(boolean enable) {
mPointSpriteEnable = enable;
}
- static synchronized ProgramFragment internalCreate(RenderScript rs, Builder b) {
- int inID = 0;
- int outID = 0;
- if (b.mIn != null) {
- inID = b.mIn.mID;
- }
- if (b.mOut != null) {
- outID = b.mOut.mID;
- }
- rs.nProgramFragmentBegin(inID, outID, b.mPointSpriteEnable);
- for(int ct=0; ct < MAX_SLOT; ct++) {
- if(b.mSlots[ct].mTexEnable) {
- Slot s = b.mSlots[ct];
- int typeID = 0;
- if(s.mType != null) {
- typeID = s.mType.mID;
- }
- rs.nProgramFragmentSetSlot(ct, true, s.mEnv.mID, typeID);
- }
- }
-
- int id = rs.nProgramFragmentCreate();
- return new ProgramFragment(id, rs);
- }
-
public ProgramFragment create() {
mRS.validate();
- return internalCreate(mRS, this);
+ int[] tmp = new int[MAX_TEXTURE * 2 + 1];
+ if (mSlots[0] != null) {
+ tmp[0] = mSlots[0].env.mID;
+ tmp[1] = mSlots[0].format.mID;
+ }
+ if (mSlots[1] != null) {
+ tmp[2] = mSlots[1].env.mID;
+ tmp[3] = mSlots[1].format.mID;
+ }
+ tmp[4] = mPointSpriteEnable ? 1 : 0;
+ int id = mRS.nProgramFragmentCreate(tmp);
+ ProgramFragment pf = new ProgramFragment(id, mRS);
+ pf.mTextureCount = MAX_TEXTURE;
+ return pf;
}
}
}
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index ba97d5b..84f6f2d 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -25,72 +25,67 @@ import android.util.Log;
* @hide
*
**/
-public class ProgramVertex extends BaseObj {
+public class ProgramVertex extends Program {
public static final int MAX_LIGHT = 8;
+
ProgramVertex(int id, RenderScript rs) {
- super(rs);
- mID = id;
+ super(id, rs);
}
public void bindAllocation(MatrixAllocation va) {
mRS.validate();
- mRS.nProgramVertexBindAllocation(mID, va.mAlloc.mID);
+ bindConstants(va.mAlloc, 0);
}
public static class Builder {
RenderScript mRS;
- Element mIn;
- Element mOut;
- Light[] mLights;
- int mLightCount;
boolean mTextureMatrixEnable;
-
public Builder(RenderScript rs, Element in, Element out) {
mRS = rs;
- mIn = in;
- mOut = out;
- mLights = new Light[MAX_LIGHT];
- mLightCount = 0;
}
public void setTextureMatrixEnable(boolean enable) {
mTextureMatrixEnable = enable;
}
- public void addLight(Light l) throws IllegalStateException {
- if(mLightCount >= MAX_LIGHT) {
- throw new IllegalArgumentException("Max light count exceeded.");
- }
- mLights[mLightCount] = l;
- mLightCount++;
+ public ProgramVertex create() {
+ int id = mRS.nProgramVertexCreate(mTextureMatrixEnable);
+ return new ProgramVertex(id, mRS);
}
+ }
+ public static class ShaderBuilder extends BaseProgramBuilder {
+ public ShaderBuilder(RenderScript rs) {
+ super(rs);
+ }
+ public ProgramVertex create() {
+ mRS.validate();
+ int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount +1) * 2];
+ int idx = 0;
- static synchronized ProgramVertex internalCreate(RenderScript rs, Builder b) {
- int inID = 0;
- int outID = 0;
- if (b.mIn != null) {
- inID = b.mIn.mID;
+ for (int i=0; i < mInputCount; i++) {
+ tmp[idx++] = 0;
+ tmp[idx++] = mInputs[i].mID;
}
- if (b.mOut != null) {
- outID = b.mOut.mID;
+ for (int i=0; i < mOutputCount; i++) {
+ tmp[idx++] = 1;
+ tmp[idx++] = mOutputs[i].mID;
}
- rs.nProgramVertexBegin(inID, outID);
- for(int ct=0; ct < b.mLightCount; ct++) {
- rs.nProgramVertexAddLight(b.mLights[ct].mID);
+ for (int i=0; i < mConstantCount; i++) {
+ tmp[idx++] = 2;
+ tmp[idx++] = mConstants[i].mID;
}
- rs.nProgramVertexSetTextureMatrixEnable(b.mTextureMatrixEnable);
- int id = rs.nProgramVertexCreate();
- return new ProgramVertex(id, rs);
- }
+ tmp[idx++] = 3;
+ tmp[idx++] = mTextureCount;
- public ProgramVertex create() {
- mRS.validate();
- return internalCreate(mRS, this);
+ int id = mRS.nProgramVertexCreate2(mShader, tmp);
+ ProgramVertex pv = new ProgramVertex(id, mRS);
+ initProgram(pv);
+ return pv;
}
}
@@ -112,7 +107,7 @@ public class ProgramVertex extends BaseObj {
mProjection = new Matrix();
mTexture = new Matrix();
- mAlloc = Allocation.createSized(rs, Element.USER_F32(rs), 48);
+ mAlloc = Allocation.createSized(rs, Element.createUser(rs, Element.DataType.FLOAT_32), 48);
mAlloc.subData1D(MODELVIEW_OFFSET, 16, mModel.mMat);
mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat);
mAlloc.subData1D(TEXTURE_OFFSET, 16, mTexture.mMat);
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 0d8b675..29361af 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -76,8 +76,6 @@ public class RenderScript {
native void nContextBindProgramFragment(int pf);
native void nContextBindProgramVertex(int pf);
native void nContextBindProgramRaster(int pr);
- native void nContextAddDefineI32(String name, int value);
- native void nContextAddDefineF(String name, float value);
native void nContextPause();
native void nContextResume();
native int nContextGetMessage(int[] data, boolean wait);
@@ -89,9 +87,9 @@ public class RenderScript {
native void nObjDestroyOOB(int id);
native int nFileOpen(byte[] name);
- native void nElementBegin();
- native void nElementAdd(int kind, int type, boolean norm, int bits, String s);
- native int nElementCreate();
+
+ native int nElementCreate(int type, int kind, boolean norm, int vecSize);
+ native int nElementCreate2(int[] elements, String[] names);
native void nTypeBegin(int elementID);
native void nTypeAdd(int dim, int val);
@@ -167,17 +165,15 @@ public class RenderScript {
native void nProgramRasterSetLineWidth(int pr, float v);
native void nProgramRasterSetPointSize(int pr, float v);
- native void nProgramFragmentBegin(int in, int out, boolean pointSpriteEnable);
- native void nProgramFragmentBindTexture(int vpf, int slot, int a);
- native void nProgramFragmentBindSampler(int vpf, int slot, int s);
- native void nProgramFragmentSetSlot(int slot, boolean enable, int env, int vt);
- native int nProgramFragmentCreate();
+ native void nProgramBindConstants(int pv, int slot, int mID);
+ native void nProgramBindTexture(int vpf, int slot, int a);
+ native void nProgramBindSampler(int vpf, int slot, int s);
+
+ native int nProgramFragmentCreate(int[] params);
+ native int nProgramFragmentCreate2(String shader, int[] params);
- native void nProgramVertexBindAllocation(int pv, int mID);
- native void nProgramVertexBegin(int inID, int outID);
- native void nProgramVertexSetTextureMatrixEnable(boolean enable);
- native void nProgramVertexAddLight(int id);
- native int nProgramVertexCreate();
+ native int nProgramVertexCreate(boolean texMat);
+ native int nProgramVertexCreate2(String shader, int[] params);
native void nLightBegin();
native void nLightSetIsMono(boolean isMono);
@@ -200,14 +196,13 @@ public class RenderScript {
private Surface mSurface;
private MessageThread mMessageThread;
-
Element mElement_USER_U8;
Element mElement_USER_I8;
Element mElement_USER_U16;
Element mElement_USER_I16;
Element mElement_USER_U32;
Element mElement_USER_I32;
- Element mElement_USER_FLOAT;
+ Element mElement_USER_F32;
Element mElement_A_8;
Element mElement_RGB_565;
@@ -217,9 +212,12 @@ public class RenderScript {
Element mElement_RGBA_8888;
Element mElement_INDEX_16;
- Element mElement_XY_F32;
- Element mElement_XYZ_F32;
-
+ Element mElement_POSITION_2;
+ Element mElement_POSITION_3;
+ Element mElement_TEXTURE_2;
+ Element mElement_NORMAL_3;
+ Element mElement_COLOR_U8_4;
+ Element mElement_COLOR_F32_4;
///////////////////////////////////////////////////////////////////////////////////
//
@@ -248,13 +246,8 @@ public class RenderScript {
}
}
- void validateSurface() {
- if (mSurface == null) {
- throw new IllegalStateException("Uploading data to GL with no surface.");
- }
- }
-
public void contextSetPriority(Priority p) {
+ validate();
nContextSetPriority(p.mID);
}
@@ -305,23 +298,26 @@ public class RenderScript {
nDeviceSetConfig(mDev, 0, 1);
}
mContext = nContextCreate(mDev, 0, useDepth);
- Element.initPredefined(this);
mMessageThread = new MessageThread(this);
mMessageThread.start();
+ Element.initPredefined(this);
}
public void contextSetSurface(int w, int h, Surface sur) {
mSurface = sur;
mWidth = w;
mHeight = h;
+ validate();
nContextSetSurface(w, h, mSurface);
}
public void contextDump(int bits) {
+ validate();
nContextDump(bits);
}
public void destroy() {
+ validate();
nContextDeinitToClient();
mMessageThread.mRun = false;
@@ -337,10 +333,12 @@ public class RenderScript {
}
void pause() {
+ validate();
nContextPause();
}
void resume() {
+ validate();
nContextResume();
}
@@ -381,22 +379,27 @@ public class RenderScript {
}
public void contextBindRootScript(Script s) {
+ validate();
nContextBindRootScript(safeID(s));
}
public void contextBindProgramFragmentStore(ProgramStore p) {
+ validate();
nContextBindProgramFragmentStore(safeID(p));
}
public void contextBindProgramFragment(ProgramFragment p) {
+ validate();
nContextBindProgramFragment(safeID(p));
}
public void contextBindProgramRaster(ProgramRaster p) {
+ validate();
nContextBindProgramRaster(safeID(p));
}
public void contextBindProgramVertex(ProgramVertex p) {
+ validate();
nContextBindProgramVertex(safeID(p));
}
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 625a576..40ba722 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -69,23 +69,45 @@ public class Sampler extends BaseObj {
}
public void setMin(Value v) {
- mMin = v;
+ if (v == Value.NEAREST ||
+ v == Value.LINEAR ||
+ v == Value.LINEAR_MIP_LINEAR) {
+ mMin = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setMag(Value v) {
- mMag = v;
+ if (v == Value.NEAREST || v == Value.LINEAR) {
+ mMag = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setWrapS(Value v) {
- mWrapS = v;
+ if (v == Value.WRAP || v == Value.CLAMP) {
+ mWrapS = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setWrapT(Value v) {
- mWrapT = v;
+ if (v == Value.WRAP || v == Value.CLAMP) {
+ mWrapT = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setWrapR(Value v) {
- mWrapR = v;
+ if (v == Value.WRAP || v == Value.CLAMP) {
+ mWrapR = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
static synchronized Sampler internalCreate(RenderScript rs, Builder b) {
diff --git a/graphics/java/android/renderscript/SimpleMesh.java b/graphics/java/android/renderscript/SimpleMesh.java
index f45074e..4a217a9 100644
--- a/graphics/java/android/renderscript/SimpleMesh.java
+++ b/graphics/java/android/renderscript/SimpleMesh.java
@@ -313,28 +313,36 @@ public class SimpleMesh extends BaseObj {
public SimpleMesh create() {
Element.Builder b = new Element.Builder(mRS);
int floatCount = mVtxSize;
- if (mVtxSize == 2) {
- b.addFloatXY();
- } else {
- b.addFloatXYZ();
- }
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.POSITION,
+ mVtxSize), "position");
if ((mFlags & COLOR) != 0) {
floatCount += 4;
- b.addFloatRGBA();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.COLOR,
+ 4), "color");
}
if ((mFlags & TEXTURE_0) != 0) {
floatCount += 2;
- b.addFloatST();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.TEXTURE,
+ 2), "texture");
}
if ((mFlags & NORMAL) != 0) {
floatCount += 3;
- b.addFloatNorm();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.NORMAL,
+ 3), "normal");
}
mElement = b.create();
Builder smb = new Builder(mRS);
smb.addVertexType(mElement, mVtxCount / floatCount);
- smb.setIndexType(Element.INDEX_16(mRS), mIndexCount);
+ smb.setIndexType(Element.createIndex(mRS), mIndexCount);
smb.setPrimitive(Primitive.TRIANGLE);
SimpleMesh sm = smb.create();
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index ad4cf6b..62d3867 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -34,6 +34,9 @@ public class Type extends BaseObj {
private int mNativeCache;
Class mJavaClass;
+ public Element getElement() {
+ return mElement;
+ }
public int getX() {
return mDimX;
@@ -122,16 +125,16 @@ public class Type extends BaseObj {
Field f = fields[ct];
Class fc = f.getType();
if(fc == int.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_32.mID;
arBits[ct] = 32;
} else if(fc == short.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_16.mID;
arBits[ct] = 16;
} else if(fc == byte.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_8.mID;
arBits[ct] = 8;
} else if(fc == float.class) {
- arTypes[ct] = Element.DataType.FLOAT.mID;
+ arTypes[ct] = Element.DataType.FLOAT_32.mID;
arBits[ct] = 32;
} else {
throw new IllegalArgumentException("Unkown field type");