summaryrefslogtreecommitdiffstats
path: root/graphics/java/android/renderscript
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java/android/renderscript')
-rw-r--r--graphics/java/android/renderscript/Allocation.java54
-rw-r--r--graphics/java/android/renderscript/BaseObj.java5
-rw-r--r--graphics/java/android/renderscript/Byte2.java37
-rw-r--r--graphics/java/android/renderscript/Byte3.java38
-rw-r--r--graphics/java/android/renderscript/Byte4.java38
-rw-r--r--graphics/java/android/renderscript/Element.java330
-rw-r--r--graphics/java/android/renderscript/FieldPacker.java155
-rw-r--r--graphics/java/android/renderscript/FileA3D.java218
-rw-r--r--graphics/java/android/renderscript/Float2.java (renamed from graphics/java/android/renderscript/Vector2f.java)4
-rw-r--r--graphics/java/android/renderscript/Float3.java (renamed from graphics/java/android/renderscript/Vector3f.java)4
-rw-r--r--graphics/java/android/renderscript/Float4.java (renamed from graphics/java/android/renderscript/Vector4f.java)4
-rw-r--r--graphics/java/android/renderscript/Font.java59
-rw-r--r--graphics/java/android/renderscript/Int2.java37
-rw-r--r--graphics/java/android/renderscript/Int3.java38
-rw-r--r--graphics/java/android/renderscript/Int4.java38
-rw-r--r--graphics/java/android/renderscript/Long2.java37
-rw-r--r--graphics/java/android/renderscript/Long3.java38
-rw-r--r--graphics/java/android/renderscript/Long4.java38
-rw-r--r--graphics/java/android/renderscript/Mesh.java479
-rw-r--r--graphics/java/android/renderscript/Program.java6
-rw-r--r--graphics/java/android/renderscript/ProgramFragment.java6
-rw-r--r--graphics/java/android/renderscript/ProgramRaster.java70
-rw-r--r--graphics/java/android/renderscript/ProgramStore.java29
-rw-r--r--graphics/java/android/renderscript/ProgramVertex.java3
-rw-r--r--graphics/java/android/renderscript/RenderScript.java104
-rw-r--r--graphics/java/android/renderscript/RenderScriptGL.java4
-rw-r--r--graphics/java/android/renderscript/Sampler.java80
-rw-r--r--graphics/java/android/renderscript/Script.java114
-rw-r--r--graphics/java/android/renderscript/ScriptC.java100
-rw-r--r--graphics/java/android/renderscript/Short2.java37
-rw-r--r--graphics/java/android/renderscript/Short3.java38
-rw-r--r--graphics/java/android/renderscript/Short4.java38
-rw-r--r--graphics/java/android/renderscript/SimpleMesh.java364
-rw-r--r--graphics/java/android/renderscript/Type.java60
34 files changed, 1934 insertions, 770 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 17c0778..87735b5 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -40,6 +40,21 @@ public class Allocation extends BaseObj {
mType = t;
}
+ Allocation(int id, RenderScript rs) {
+ super(rs);
+ mID = id;
+ }
+
+ @Override
+ void updateFromNative() {
+ mRS.validate();
+ int typeID = mRS.nAllocationGetType(mID);
+ if(typeID != 0) {
+ mType = new Type(typeID, mRS);
+ mType.updateFromNative();
+ }
+ }
+
public Type getType() {
return mType;
}
@@ -76,10 +91,30 @@ public class Allocation extends BaseObj {
subData1D(0, mType.getElementCount(), d);
}
+ public void subData(int off, FieldPacker fp) {
+ int eSize = mType.mElement.getSizeBytes();
+ final byte[] data = fp.getData();
+
+ int count = data.length / eSize;
+ if ((eSize * count) != data.length) {
+ throw new IllegalArgumentException("Field packer length " + data.length +
+ " not divisible by element size " + eSize + ".");
+ }
+ data1DChecks(off, count, data.length, data.length);
+ mRS.nAllocationSubData1D(mID, off, count, data, data.length);
+ }
+
private void data1DChecks(int off, int count, int len, int dataSize) {
mRS.validate();
- if((off < 0) || (count < 1) || ((off + count) > mType.getElementCount())) {
- throw new IllegalArgumentException("Offset or Count out of bounds.");
+ if(off < 0) {
+ throw new IllegalArgumentException("Offset must be >= 0.");
+ }
+ if(count < 1) {
+ throw new IllegalArgumentException("Count must be >= 1.");
+ }
+ if((off + count) > mType.getElementCount()) {
+ throw new IllegalArgumentException("Overflow, Available count " + mType.getElementCount() +
+ ", got " + count + " at offset " + off + ".");
}
if((len) < dataSize) {
throw new IllegalArgumentException("Array too small for allocation type.");
@@ -366,6 +401,21 @@ public class Allocation extends BaseObj {
Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions);
return createFromBitmapBoxed(rs, b, dstFmt, genMips);
}
+
+ static public Allocation createFromString(RenderScript rs, String str)
+ throws IllegalArgumentException {
+ byte[] allocArray = null;
+ try {
+ allocArray = str.getBytes("UTF-8");
+ Allocation alloc = Allocation.createSized(rs, Element.U8(rs), allocArray.length);
+ alloc.data(allocArray);
+ return alloc;
+ }
+ catch (Exception e) {
+ Log.e("rs", "could not convert string to utf-8");
+ }
+ return null;
+ }
}
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java
index 002fc78..28675dc 100644
--- a/graphics/java/android/renderscript/BaseObj.java
+++ b/graphics/java/android/renderscript/BaseObj.java
@@ -81,5 +81,10 @@ class BaseObj {
mRS.nObjDestroy(mID);
}
+ // If an object came from an a3d file, java fields need to be
+ // created with objects from the native layer
+ void updateFromNative() {
+ }
+
}
diff --git a/graphics/java/android/renderscript/Byte2.java b/graphics/java/android/renderscript/Byte2.java
new file mode 100644
index 0000000..95cf88c
--- /dev/null
+++ b/graphics/java/android/renderscript/Byte2.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Byte2 {
+ public Byte2() {
+ }
+
+ public byte x;
+ public byte y;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Byte3.java b/graphics/java/android/renderscript/Byte3.java
new file mode 100644
index 0000000..a6c0ca9
--- /dev/null
+++ b/graphics/java/android/renderscript/Byte3.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Byte3 {
+ public Byte3() {
+ }
+
+ public byte x;
+ public byte y;
+ public byte z;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Byte4.java b/graphics/java/android/renderscript/Byte4.java
new file mode 100644
index 0000000..a5bfc61
--- /dev/null
+++ b/graphics/java/android/renderscript/Byte4.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Byte4 {
+ public Byte4() {
+ }
+
+ public byte x;
+ public byte y;
+ public byte z;
+ public byte w;
+}
+
+
+
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index 10ef05a..5d2a059 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -17,6 +17,7 @@
package android.renderscript;
import java.lang.reflect.Field;
+import android.util.Log;
/**
* @hide
@@ -47,20 +48,22 @@ public class Element extends BaseObj {
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);
+ BOOLEAN(12, 1),
+
+ UNSIGNED_5_6_5 (13, 2),
+ UNSIGNED_5_5_5_1 (14, 2),
+ UNSIGNED_4_4_4_4 (15, 2),
+
+ RS_ELEMENT (16, 4),
+ RS_TYPE (17, 4),
+ RS_ALLOCATION (18, 4),
+ RS_SAMPLER (19, 4),
+ RS_SCRIPT (20, 4),
+ RS_MESH (21, 4),
+ RS_PROGRAM_FRAGMENT (22, 4),
+ RS_PROGRAM_VERTEX (23, 4),
+ RS_PROGRAM_RASTER (24, 4),
+ RS_PROGRAM_STORE (25, 4);
int mID;
int mSize;
@@ -72,12 +75,6 @@ public class Element extends BaseObj {
public enum DataKind {
USER (0),
- COLOR (1),
- POSITION (2),
- TEXTURE (3),
- NORMAL (4),
- INDEX (5),
- POINT_SIZE(6),
PIXEL_L (7),
PIXEL_A (8),
@@ -91,41 +88,133 @@ public class Element extends BaseObj {
}
}
- public static Element USER_U8(RenderScript rs) {
- if(rs.mElement_USER_U8 == null) {
- rs.mElement_USER_U8 = createUser(rs, DataType.UNSIGNED_8);
+ public static Element BOOLEAN(RenderScript rs) {
+ if(rs.mElement_BOOLEAN == null) {
+ rs.mElement_BOOLEAN = createUser(rs, DataType.BOOLEAN);
+ }
+ return rs.mElement_BOOLEAN;
+ }
+
+ public static Element U8(RenderScript rs) {
+ if(rs.mElement_U8 == null) {
+ rs.mElement_U8 = createUser(rs, DataType.UNSIGNED_8);
+ }
+ return rs.mElement_U8;
+ }
+
+ public static Element I8(RenderScript rs) {
+ if(rs.mElement_I8 == null) {
+ rs.mElement_I8 = createUser(rs, DataType.SIGNED_8);
+ }
+ return rs.mElement_I8;
+ }
+
+ public static Element U16(RenderScript rs) {
+ if(rs.mElement_U16 == null) {
+ rs.mElement_U16 = createUser(rs, DataType.UNSIGNED_16);
+ }
+ return rs.mElement_U16;
+ }
+
+ public static Element I16(RenderScript rs) {
+ if(rs.mElement_I16 == null) {
+ rs.mElement_I16 = createUser(rs, DataType.SIGNED_16);
+ }
+ return rs.mElement_I16;
+ }
+
+ public static Element U32(RenderScript rs) {
+ if(rs.mElement_U32 == null) {
+ rs.mElement_U32 = createUser(rs, DataType.UNSIGNED_32);
+ }
+ return rs.mElement_U32;
+ }
+
+ public static Element I32(RenderScript rs) {
+ if(rs.mElement_I32 == null) {
+ rs.mElement_I32 = createUser(rs, DataType.SIGNED_32);
+ }
+ return rs.mElement_I32;
+ }
+
+ public static Element F32(RenderScript rs) {
+ if(rs.mElement_F32 == null) {
+ rs.mElement_F32 = createUser(rs, DataType.FLOAT_32);
+ }
+ return rs.mElement_F32;
+ }
+
+ public static Element ELEMENT(RenderScript rs) {
+ if(rs.mElement_ELEMENT == null) {
+ rs.mElement_ELEMENT = createUser(rs, DataType.RS_ELEMENT);
+ }
+ return rs.mElement_ELEMENT;
+ }
+
+ public static Element TYPE(RenderScript rs) {
+ if(rs.mElement_TYPE == null) {
+ rs.mElement_TYPE = createUser(rs, DataType.RS_TYPE);
+ }
+ return rs.mElement_TYPE;
+ }
+
+ public static Element ALLOCATION(RenderScript rs) {
+ if(rs.mElement_ALLOCATION == null) {
+ rs.mElement_ALLOCATION = createUser(rs, DataType.RS_ALLOCATION);
+ }
+ return rs.mElement_ALLOCATION;
+ }
+
+ public static Element SAMPLER(RenderScript rs) {
+ if(rs.mElement_SAMPLER == null) {
+ rs.mElement_SAMPLER = createUser(rs, DataType.RS_SAMPLER);
+ }
+ return rs.mElement_SAMPLER;
+ }
+
+ public static Element SCRIPT(RenderScript rs) {
+ if(rs.mElement_SCRIPT == null) {
+ rs.mElement_SCRIPT = createUser(rs, DataType.RS_SCRIPT);
+ }
+ return rs.mElement_SCRIPT;
+ }
+
+ public static Element MESH(RenderScript rs) {
+ if(rs.mElement_MESH == null) {
+ rs.mElement_MESH = createUser(rs, DataType.RS_MESH);
}
- return rs.mElement_USER_U8;
+ return rs.mElement_MESH;
}
- public static Element USER_I8(RenderScript rs) {
- if(rs.mElement_USER_I8 == null) {
- rs.mElement_USER_I8 = createUser(rs, DataType.SIGNED_8);
+ public static Element PROGRAM_FRAGMENT(RenderScript rs) {
+ if(rs.mElement_PROGRAM_FRAGMENT == null) {
+ rs.mElement_PROGRAM_FRAGMENT = createUser(rs, DataType.RS_PROGRAM_FRAGMENT);
}
- return rs.mElement_USER_I8;
+ return rs.mElement_PROGRAM_FRAGMENT;
}
- public static Element USER_U32(RenderScript rs) {
- if(rs.mElement_USER_U32 == null) {
- rs.mElement_USER_U32 = createUser(rs, DataType.UNSIGNED_32);
+ public static Element PROGRAM_VERTEX(RenderScript rs) {
+ if(rs.mElement_PROGRAM_VERTEX == null) {
+ rs.mElement_PROGRAM_VERTEX = createUser(rs, DataType.RS_PROGRAM_VERTEX);
}
- return rs.mElement_USER_U32;
+ return rs.mElement_PROGRAM_VERTEX;
}
- public static Element USER_I32(RenderScript rs) {
- if(rs.mElement_USER_I32 == null) {
- rs.mElement_USER_I32 = createUser(rs, DataType.SIGNED_32);
+ public static Element PROGRAM_RASTER(RenderScript rs) {
+ if(rs.mElement_PROGRAM_RASTER == null) {
+ rs.mElement_PROGRAM_RASTER = createUser(rs, DataType.RS_PROGRAM_RASTER);
}
- return rs.mElement_USER_I32;
+ return rs.mElement_PROGRAM_RASTER;
}
- public static Element USER_F32(RenderScript rs) {
- if(rs.mElement_USER_F32 == null) {
- rs.mElement_USER_F32 = createUser(rs, DataType.FLOAT_32);
+ public static Element PROGRAM_STORE(RenderScript rs) {
+ if(rs.mElement_PROGRAM_STORE == null) {
+ rs.mElement_PROGRAM_STORE = createUser(rs, DataType.RS_PROGRAM_STORE);
}
- return rs.mElement_USER_F32;
+ return rs.mElement_PROGRAM_STORE;
}
+
public static Element A_8(RenderScript rs) {
if(rs.mElement_A_8 == null) {
rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A);
@@ -168,54 +257,34 @@ public class Element extends BaseObj {
return rs.mElement_RGBA_8888;
}
- public static Element INDEX_16(RenderScript rs) {
- if(rs.mElement_INDEX_16 == null) {
- rs.mElement_INDEX_16 = createIndex(rs);
- }
- return rs.mElement_INDEX_16;
- }
-
- public static Element ATTRIB_POSITION_2(RenderScript rs) {
- if(rs.mElement_POSITION_2 == null) {
- rs.mElement_POSITION_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 2);
+ public static Element F32_2(RenderScript rs) {
+ if(rs.mElement_FLOAT_2 == null) {
+ rs.mElement_FLOAT_2 = createVector(rs, DataType.FLOAT_32, 2);
}
- return rs.mElement_POSITION_2;
+ return rs.mElement_FLOAT_2;
}
- public static Element ATTRIB_POSITION_3(RenderScript rs) {
- if(rs.mElement_POSITION_3 == null) {
- rs.mElement_POSITION_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 3);
+ public static Element F32_3(RenderScript rs) {
+ if(rs.mElement_FLOAT_3 == null) {
+ rs.mElement_FLOAT_3 = createVector(rs, DataType.FLOAT_32, 3);
}
- return rs.mElement_POSITION_3;
+ return rs.mElement_FLOAT_3;
}
- public static Element ATTRIB_TEXTURE_2(RenderScript rs) {
- if(rs.mElement_TEXTURE_2 == null) {
- rs.mElement_TEXTURE_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.TEXTURE, 2);
+ public static Element F32_4(RenderScript rs) {
+ if(rs.mElement_FLOAT_4 == null) {
+ rs.mElement_FLOAT_4 = createVector(rs, DataType.FLOAT_32, 4);
}
- return rs.mElement_TEXTURE_2;
+ return rs.mElement_FLOAT_4;
}
- 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);
+ public static Element U8_4(RenderScript rs) {
+ if(rs.mElement_UCHAR_4 == null) {
+ rs.mElement_UCHAR_4 = createVector(rs, DataType.UNSIGNED_8, 4);
}
- return rs.mElement_NORMAL_3;
+ return rs.mElement_UCHAR_4;
}
- public static Element ATTRIB_COLOR_U8_4(RenderScript rs) {
- if(rs.mElement_COLOR_U8_4 == null) {
- rs.mElement_COLOR_U8_4 = createAttrib(rs, DataType.UNSIGNED_8, DataKind.COLOR, 4);
- }
- return rs.mElement_COLOR_U8_4;
- }
-
- public static Element ATTRIB_COLOR_F32_4(RenderScript rs) {
- if(rs.mElement_COLOR_F32_4 == null) {
- rs.mElement_COLOR_F32_4 = createAttrib(rs, DataType.FLOAT_32, DataKind.COLOR, 4);
- }
- return rs.mElement_COLOR_F32_4;
- }
Element(RenderScript rs, Element[] e, String[] n) {
super(rs);
@@ -240,32 +309,48 @@ public class Element extends BaseObj {
mID = rs.nElementCreate(dt.mID, dk.mID, norm, size);
}
- public void destroy() throws IllegalStateException {
- super.destroy();
+ Element(RenderScript rs, int id) {
+ super(rs);
+ mID = id;
}
- public static Element createFromClass(RenderScript rs, Class c) {
- rs.validate();
- Field[] fields = c.getFields();
- Builder b = new Builder(rs);
-
- for(Field f: fields) {
- Class fc = f.getType();
- if(fc == int.class) {
- b.add(createUser(rs, DataType.SIGNED_32), f.getName());
- } else if(fc == short.class) {
- b.add(createUser(rs, DataType.SIGNED_16), f.getName());
- } else if(fc == byte.class) {
- b.add(createUser(rs, DataType.SIGNED_8), f.getName());
- } else if(fc == float.class) {
- b.add(createUser(rs, DataType.FLOAT_32), f.getName());
- } else {
- throw new IllegalArgumentException("Unkown field type");
+ @Override
+ void updateFromNative() {
+
+ // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
+ int[] dataBuffer = new int[5];
+ mRS.nElementGetNativeData(mID, dataBuffer);
+ for (DataType dt: DataType.values()) {
+ if(dt.mID == dataBuffer[0]){
+ mType = dt;
+ }
+ }
+ for (DataKind dk: DataKind.values()) {
+ if(dk.mID == dataBuffer[1]){
+ mKind = dk;
+ }
+ }
+
+ mNormalized = dataBuffer[2] == 1 ? true : false;
+ mVectorSize = dataBuffer[3];
+ int numSubElements = dataBuffer[4];
+ if(numSubElements > 0) {
+ mElements = new Element[numSubElements];
+ mElementNames = new String[numSubElements];
+
+ int[] subElementIds = new int[numSubElements];
+ mRS.nElementGetSubElements(mID, subElementIds, mElementNames);
+ for(int i = 0; i < numSubElements; i ++) {
+ mElements[i] = new Element(mRS, subElementIds[i]);
+ mElements[i].updateFromNative();
}
}
- return b.create();
+
}
+ public void destroy() throws IllegalStateException {
+ super.destroy();
+ }
/////////////////////////////////////////
public static Element createUser(RenderScript rs, DataType dt) {
@@ -279,59 +364,6 @@ public class Element extends BaseObj {
return new Element(rs, dt, DataKind.USER, false, size);
}
- public static Element createIndex(RenderScript rs) {
- return new Element(rs, DataType.UNSIGNED_16, DataKind.INDEX, false, 1);
- }
-
- 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");
- }
-
- 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");
- }
-
- if (dk == DataKind.COLOR &&
- ((dt != DataType.FLOAT_32 && dt != DataType.UNSIGNED_8) ||
- size < 3 || size > 4)) {
- throw new IllegalArgumentException("Bad combo");
- }
- if (dk == DataKind.POSITION && (size < 1 || size > 4)) {
- throw new IllegalArgumentException("Bad combo");
- }
- if (dk == DataKind.TEXTURE &&
- (dt != DataType.FLOAT_32 || size < 1 || size > 4)) {
- throw new IllegalArgumentException("Bad combo");
- }
- if (dk == DataKind.NORMAL &&
- (dt != DataType.FLOAT_32 || size != 3)) {
- throw new IllegalArgumentException("Bad combo");
- }
- if (dk == DataKind.POINT_SIZE &&
- (dt != DataType.FLOAT_32 || size != 1)) {
- throw new IllegalArgumentException("Bad combo");
- }
-
- boolean norm = false;
- if (dk == DataKind.COLOR && dt == DataType.UNSIGNED_8) {
- norm = true;
- }
-
- return new Element(rs, dt, dk, norm, size);
- }
-
public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) {
if (!(dk == DataKind.PIXEL_L ||
dk == DataKind.PIXEL_A ||
diff --git a/graphics/java/android/renderscript/FieldPacker.java b/graphics/java/android/renderscript/FieldPacker.java
index b26e47d..f03b51c 100644
--- a/graphics/java/android/renderscript/FieldPacker.java
+++ b/graphics/java/android/renderscript/FieldPacker.java
@@ -33,21 +33,28 @@ public class FieldPacker {
}
}
- void reset() {
+ public void reset() {
mPos = 0;
}
+ public void reset(int i) {
+ mPos = i;
+ }
+
+ public void skip(int i) {
+ mPos += i;
+ }
- void addI8(byte v) {
+ public void addI8(byte v) {
mData[mPos++] = v;
}
- void addI16(short v) {
+ public void addI16(short v) {
align(2);
mData[mPos++] = (byte)(v & 0xff);
mData[mPos++] = (byte)(v >> 8);
}
- void addI32(int v) {
+ public void addI32(int v) {
align(4);
mData[mPos++] = (byte)(v & 0xff);
mData[mPos++] = (byte)((v >> 8) & 0xff);
@@ -55,7 +62,7 @@ public class FieldPacker {
mData[mPos++] = (byte)((v >> 24) & 0xff);
}
- void addI64(long v) {
+ public void addI64(long v) {
align(8);
mData[mPos++] = (byte)(v & 0xff);
mData[mPos++] = (byte)((v >> 8) & 0xff);
@@ -67,14 +74,14 @@ public class FieldPacker {
mData[mPos++] = (byte)((v >> 56) & 0xff);
}
- void addU8(short v) {
+ public void addU8(short v) {
if ((v < 0) || (v > 0xff)) {
throw new IllegalArgumentException("Saving value out of range for type");
}
mData[mPos++] = (byte)v;
}
- void addU16(int v) {
+ public void addU16(int v) {
if ((v < 0) || (v > 0xffff)) {
throw new IllegalArgumentException("Saving value out of range for type");
}
@@ -83,7 +90,7 @@ public class FieldPacker {
mData[mPos++] = (byte)(v >> 8);
}
- void addU32(long v) {
+ public void addU32(long v) {
if ((v < 0) || (v > 0xffffffff)) {
throw new IllegalArgumentException("Saving value out of range for type");
}
@@ -94,7 +101,7 @@ public class FieldPacker {
mData[mPos++] = (byte)((v >> 24) & 0xff);
}
- void addU64(long v) {
+ public void addU64(long v) {
if (v < 0) {
throw new IllegalArgumentException("Saving value out of range for type");
}
@@ -109,15 +116,139 @@ public class FieldPacker {
mData[mPos++] = (byte)((v >> 56) & 0xff);
}
- void addF32(float v) {
+ public void addF32(float v) {
addI32(Float.floatToRawIntBits(v));
}
- void addF64(float v) {
+ public void addF64(float v) {
addI64(Double.doubleToRawLongBits(v));
}
- final byte[] getData() {
+ public void addObj(BaseObj obj) {
+ if (obj != null) {
+ addI32(obj.getID());
+ } else {
+ addI32(0);
+ }
+ }
+
+ public void addF32(Float2 v) {
+ addF32(v.x);
+ addF32(v.y);
+ }
+ public void addF32(Float3 v) {
+ addF32(v.x);
+ addF32(v.y);
+ addF32(v.z);
+ }
+ public void addF32(Float4 v) {
+ addF32(v.x);
+ addF32(v.y);
+ addF32(v.z);
+ addF32(v.w);
+ }
+
+ public void addI8(Byte2 v) {
+ addI8(v.x);
+ addI8(v.y);
+ }
+ public void addI8(Byte3 v) {
+ addI8(v.x);
+ addI8(v.y);
+ addI8(v.z);
+ }
+ public void addI8(Byte4 v) {
+ addI8(v.x);
+ addI8(v.y);
+ addI8(v.z);
+ addI8(v.w);
+ }
+
+ public void addU8(Short2 v) {
+ addU8(v.x);
+ addU8(v.y);
+ }
+ public void addU8(Short3 v) {
+ addU8(v.x);
+ addU8(v.y);
+ addU8(v.z);
+ }
+ public void addU8(Short4 v) {
+ addU8(v.x);
+ addU8(v.y);
+ addU8(v.z);
+ addU8(v.w);
+ }
+
+ public void addI16(Short2 v) {
+ addI16(v.x);
+ addI16(v.y);
+ }
+ public void addI16(Short3 v) {
+ addI16(v.x);
+ addI16(v.y);
+ addI16(v.z);
+ }
+ public void addI16(Short4 v) {
+ addI16(v.x);
+ addI16(v.y);
+ addI16(v.z);
+ addI16(v.w);
+ }
+
+ public void addU16(Int2 v) {
+ addU16(v.x);
+ addU16(v.y);
+ }
+ public void addU16(Int3 v) {
+ addU16(v.x);
+ addU16(v.y);
+ addU16(v.z);
+ }
+ public void addU16(Int4 v) {
+ addU16(v.x);
+ addU16(v.y);
+ addU16(v.z);
+ addU16(v.w);
+ }
+
+ public void addI32(Int2 v) {
+ addI32(v.x);
+ addI32(v.y);
+ }
+ public void addI32(Int3 v) {
+ addI32(v.x);
+ addI32(v.y);
+ addI32(v.z);
+ }
+ public void addI32(Int4 v) {
+ addI32(v.x);
+ addI32(v.y);
+ addI32(v.z);
+ addI32(v.w);
+ }
+
+ public void addU32(Int2 v) {
+ addU32(v.x);
+ addU32(v.y);
+ }
+ public void addU32(Int3 v) {
+ addU32(v.x);
+ addU32(v.y);
+ addU32(v.z);
+ }
+ public void addU32(Int4 v) {
+ addU32(v.x);
+ addU32(v.y);
+ addU32(v.z);
+ addU32(v.w);
+ }
+
+ public void addBoolean(boolean v) {
+ addI8((byte)(v ? 1 : 0));
+ }
+
+ public final byte[] getData() {
return mData;
}
diff --git a/graphics/java/android/renderscript/FileA3D.java b/graphics/java/android/renderscript/FileA3D.java
new file mode 100644
index 0000000..302a5f4
--- /dev/null
+++ b/graphics/java/android/renderscript/FileA3D.java
@@ -0,0 +1,218 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+
+import android.content.res.Resources;
+import android.content.res.AssetManager;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.util.Log;
+import android.util.TypedValue;
+
+/**
+ * @hide
+ *
+ **/
+public class FileA3D extends BaseObj {
+
+ public enum ClassID {
+
+ UNKNOWN,
+ MESH,
+ TYPE,
+ ELEMENT,
+ ALLOCATION,
+ PROGRAM_VERTEX,
+ PROGRAM_RASTER,
+ PROGRAM_FRAGMENT,
+ PROGRAM_STORE,
+ SAMPLER,
+ ANIMATION,
+ LIGHT,
+ ADAPTER_1D,
+ ADAPTER_2D,
+ SCRIPT_C;
+
+ public static ClassID toClassID(int intID) {
+ return ClassID.values()[intID];
+ }
+ }
+
+ // Read only class with index entries
+ public static class IndexEntry {
+ RenderScript mRS;
+ int mIndex;
+ int mID;
+ String mName;
+ ClassID mClassID;
+ BaseObj mLoadedObj;
+
+ public String getName() {
+ return mName;
+ }
+
+ public ClassID getClassID() {
+ return mClassID;
+ }
+
+ public BaseObj getObject() {
+ mRS.validate();
+ BaseObj obj = internalCreate(mRS, this);
+ return obj;
+ }
+
+ static synchronized BaseObj internalCreate(RenderScript rs, IndexEntry entry) {
+ if(entry.mLoadedObj != null) {
+ return entry.mLoadedObj;
+ }
+
+ if(entry.mClassID == ClassID.UNKNOWN) {
+ return null;
+ }
+
+ int objectID = rs.nFileA3DGetEntryByIndex(entry.mID, entry.mIndex);
+ if(objectID == 0) {
+ return null;
+ }
+
+ switch (entry.mClassID) {
+ case MESH:
+ entry.mLoadedObj = new Mesh(objectID, rs);
+ break;
+ case TYPE:
+ entry.mLoadedObj = new Type(objectID, rs);
+ break;
+ case ELEMENT:
+ entry.mLoadedObj = null;
+ break;
+ case ALLOCATION:
+ entry.mLoadedObj = null;
+ break;
+ case PROGRAM_VERTEX:
+ entry.mLoadedObj = new ProgramVertex(objectID, rs);
+ break;
+ case PROGRAM_RASTER:
+ break;
+ case PROGRAM_FRAGMENT:
+ break;
+ case PROGRAM_STORE:
+ break;
+ case SAMPLER:
+ break;
+ case ANIMATION:
+ break;
+ case LIGHT:
+ break;
+ case ADAPTER_1D:
+ break;
+ case ADAPTER_2D:
+ break;
+ case SCRIPT_C:
+ break;
+ }
+
+ entry.mLoadedObj.updateFromNative();
+
+ return entry.mLoadedObj;
+ }
+
+ IndexEntry(RenderScript rs, int index, int id, String name, ClassID classID) {
+ mRS = rs;
+ mIndex = index;
+ mID = id;
+ mName = name;
+ mClassID = classID;
+ mLoadedObj = null;
+ }
+ }
+
+ IndexEntry[] mFileEntries;
+
+ FileA3D(int id, RenderScript rs) {
+ super(rs);
+ mID = id;
+ }
+
+ private void initEntries() {
+ int numFileEntries = mRS.nFileA3DGetNumIndexEntries(mID);
+ if(numFileEntries <= 0) {
+ return;
+ }
+
+ mFileEntries = new IndexEntry[numFileEntries];
+ int[] ids = new int[numFileEntries];
+ String[] names = new String[numFileEntries];
+
+ mRS.nFileA3DGetIndexEntries(mID, numFileEntries, ids, names);
+
+ for(int i = 0; i < numFileEntries; i ++) {
+ mFileEntries[i] = new IndexEntry(mRS, i, mID, names[i], ClassID.toClassID(ids[i]));
+ }
+ }
+
+ public int getNumIndexEntries() {
+ if(mFileEntries == null) {
+ return 0;
+ }
+ return mFileEntries.length;
+ }
+
+ public IndexEntry getIndexEntry(int index) {
+ if(getNumIndexEntries() == 0 || index < 0 || index >= mFileEntries.length) {
+ return null;
+ }
+ return mFileEntries[index];
+ }
+
+ static public FileA3D createFromResource(RenderScript rs, Resources res, int id)
+ throws IllegalArgumentException {
+
+ rs.validate();
+ InputStream is = null;
+ try {
+ final TypedValue value = new TypedValue();
+ is = res.openRawResource(id, value);
+
+ int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
+
+ int fileId = rs.nFileA3DCreateFromAssetStream(asset);
+
+ if(fileId == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
+ FileA3D fa3d = new FileA3D(fileId, rs);
+ fa3d.initEntries();
+ return fa3d;
+
+ } catch (Exception e) {
+ // Ignore
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/graphics/java/android/renderscript/Vector2f.java b/graphics/java/android/renderscript/Float2.java
index 567d57f..8fea91f 100644
--- a/graphics/java/android/renderscript/Vector2f.java
+++ b/graphics/java/android/renderscript/Float2.java
@@ -24,8 +24,8 @@ import android.util.Log;
* @hide
*
**/
-public class Vector2f {
- public Vector2f() {
+public class Float2 {
+ public Float2() {
}
public float x;
diff --git a/graphics/java/android/renderscript/Vector3f.java b/graphics/java/android/renderscript/Float3.java
index f2842f3..9d9e406 100644
--- a/graphics/java/android/renderscript/Vector3f.java
+++ b/graphics/java/android/renderscript/Float3.java
@@ -24,8 +24,8 @@ import android.util.Log;
* @hide
*
**/
-public class Vector3f {
- public Vector3f() {
+public class Float3 {
+ public Float3() {
}
public float x;
diff --git a/graphics/java/android/renderscript/Vector4f.java b/graphics/java/android/renderscript/Float4.java
index fabd959..a703e80 100644
--- a/graphics/java/android/renderscript/Vector4f.java
+++ b/graphics/java/android/renderscript/Float4.java
@@ -24,8 +24,8 @@ import android.util.Log;
* @hide
*
**/
-public class Vector4f {
- public Vector4f() {
+public class Float4 {
+ public Float4() {
}
public float x;
diff --git a/graphics/java/android/renderscript/Font.java b/graphics/java/android/renderscript/Font.java
new file mode 100644
index 0000000..41f8827
--- /dev/null
+++ b/graphics/java/android/renderscript/Font.java
@@ -0,0 +1,59 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+
+import android.content.res.Resources;
+import android.content.res.AssetManager;
+import android.util.Log;
+import android.util.TypedValue;
+
+/**
+ * @hide
+ *
+ **/
+public class Font extends BaseObj {
+
+ Font(int id, RenderScript rs) {
+ super(rs);
+ mID = id;
+ }
+
+ static public Font create(RenderScript rs, Resources res, String fileName, int size)
+ throws IllegalArgumentException {
+
+ rs.validate();
+ try {
+ int dpi = res.getDisplayMetrics().densityDpi;
+ int fontId = rs.nFontCreateFromFile(fileName, size, dpi);
+
+ if(fontId == 0) {
+ throw new IllegalStateException("Load loading a font");
+ }
+ Font rsFont = new Font(fontId, rs);
+
+ return rsFont;
+
+ } catch (Exception e) {
+ // Ignore
+ }
+
+ return null;
+ }
+}
diff --git a/graphics/java/android/renderscript/Int2.java b/graphics/java/android/renderscript/Int2.java
new file mode 100644
index 0000000..56e2fe9
--- /dev/null
+++ b/graphics/java/android/renderscript/Int2.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Int2 {
+ public Int2() {
+ }
+
+ public int x;
+ public int y;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Int3.java b/graphics/java/android/renderscript/Int3.java
new file mode 100644
index 0000000..1b27509
--- /dev/null
+++ b/graphics/java/android/renderscript/Int3.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Int3 {
+ public Int3() {
+ }
+
+ public int x;
+ public int y;
+ public int z;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Int4.java b/graphics/java/android/renderscript/Int4.java
new file mode 100644
index 0000000..3d6f3f5
--- /dev/null
+++ b/graphics/java/android/renderscript/Int4.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Int4 {
+ public Int4() {
+ }
+
+ public int x;
+ public int y;
+ public int z;
+ public int w;
+}
+
+
+
diff --git a/graphics/java/android/renderscript/Long2.java b/graphics/java/android/renderscript/Long2.java
new file mode 100644
index 0000000..11ead2f
--- /dev/null
+++ b/graphics/java/android/renderscript/Long2.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Long2 {
+ public Long2() {
+ }
+
+ public long x;
+ public long y;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Long3.java b/graphics/java/android/renderscript/Long3.java
new file mode 100644
index 0000000..1604532
--- /dev/null
+++ b/graphics/java/android/renderscript/Long3.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Long3 {
+ public Long3() {
+ }
+
+ public long x;
+ public long y;
+ public long z;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Long4.java b/graphics/java/android/renderscript/Long4.java
new file mode 100644
index 0000000..2fd2747
--- /dev/null
+++ b/graphics/java/android/renderscript/Long4.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Long4 {
+ public Long4() {
+ }
+
+ public long x;
+ public long y;
+ public long z;
+ public long w;
+}
+
+
+
diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java
new file mode 100644
index 0000000..4bee97a
--- /dev/null
+++ b/graphics/java/android/renderscript/Mesh.java
@@ -0,0 +1,479 @@
+/*
+ * 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 java.util.Vector;
+
+import android.util.Config;
+import android.util.Log;
+
+/**
+ * @hide
+ *
+ **/
+public class Mesh extends BaseObj {
+
+ Allocation[] mVertexBuffers;
+ Allocation[] mIndexBuffers;
+ Primitive[] mPrimitives;
+
+ Mesh(int id, RenderScript rs) {
+ super(rs);
+ mID = id;
+ }
+
+ public int getVertexAllocationCount() {
+ if(mVertexBuffers == null) {
+ return 0;
+ }
+ return mVertexBuffers.length;
+ }
+ public Allocation getVertexAllocation(int slot) {
+ return mVertexBuffers[slot];
+ }
+
+ public int getPrimitiveCount() {
+ if(mIndexBuffers == null) {
+ return 0;
+ }
+ return mIndexBuffers.length;
+ }
+ public Allocation getIndexAllocation(int slot) {
+ return mIndexBuffers[slot];
+ }
+ public Primitive getPrimitive(int slot) {
+ return mPrimitives[slot];
+ }
+
+ @Override
+ void updateFromNative() {
+ int vtxCount = mRS.nMeshGetVertexBufferCount(mID);
+ int idxCount = mRS.nMeshGetIndexCount(mID);
+
+ int[] vtxIDs = new int[vtxCount];
+ int[] idxIDs = new int[idxCount];
+ int[] primitives = new int[idxCount];
+
+ mRS.nMeshGetVertices(mID, vtxIDs, vtxCount);
+ mRS.nMeshGetIndices(mID, idxIDs, primitives, vtxCount);
+
+ mVertexBuffers = new Allocation[vtxCount];
+ mIndexBuffers = new Allocation[idxCount];
+ mPrimitives = new Primitive[idxCount];
+
+ for(int i = 0; i < vtxCount; i ++) {
+ if(vtxIDs[i] != 0) {
+ mVertexBuffers[i] = new Allocation(vtxIDs[i], mRS);
+ mVertexBuffers[i].updateFromNative();
+ }
+ }
+
+ for(int i = 0; i < idxCount; i ++) {
+ if(idxIDs[i] != 0) {
+ mIndexBuffers[i] = new Allocation(idxIDs[i], mRS);
+ mIndexBuffers[i].updateFromNative();
+ }
+ mPrimitives[i] = Primitive.values()[primitives[i]];
+ }
+ }
+
+ public static class Builder {
+ RenderScript mRS;
+
+ class Entry {
+ Type t;
+ Element e;
+ int size;
+ Primitive prim;
+ }
+
+ int mVertexTypeCount;
+ Entry[] mVertexTypes;
+ Vector mIndexTypes;
+
+ public Builder(RenderScript rs) {
+ mRS = rs;
+ mVertexTypeCount = 0;
+ mVertexTypes = new Entry[16];
+ mIndexTypes = new Vector();
+ }
+
+ public int addVertexType(Type t) throws IllegalStateException {
+ if (mVertexTypeCount >= mVertexTypes.length) {
+ throw new IllegalStateException("Max vertex types exceeded.");
+ }
+
+ int addedIndex = mVertexTypeCount;
+ mVertexTypes[mVertexTypeCount] = new Entry();
+ mVertexTypes[mVertexTypeCount].t = t;
+ mVertexTypes[mVertexTypeCount].e = null;
+ mVertexTypeCount++;
+ return addedIndex;
+ }
+
+ public int addVertexType(Element e, int size) throws IllegalStateException {
+ if (mVertexTypeCount >= mVertexTypes.length) {
+ throw new IllegalStateException("Max vertex types exceeded.");
+ }
+
+ int addedIndex = mVertexTypeCount;
+ mVertexTypes[mVertexTypeCount] = new Entry();
+ mVertexTypes[mVertexTypeCount].t = null;
+ mVertexTypes[mVertexTypeCount].e = e;
+ mVertexTypes[mVertexTypeCount].size = size;
+ mVertexTypeCount++;
+ return addedIndex;
+ }
+
+ public int addIndexType(Type t, Primitive p) {
+ int addedIndex = mIndexTypes.size();
+ Entry indexType = new Entry();
+ indexType.t = t;
+ indexType.e = null;
+ indexType.size = 0;
+ indexType.prim = p;
+ mIndexTypes.addElement(indexType);
+ return addedIndex;
+ }
+
+ public int addIndexType(Primitive p) {
+ int addedIndex = mIndexTypes.size();
+ Entry indexType = new Entry();
+ indexType.t = null;
+ indexType.e = null;
+ indexType.size = 0;
+ indexType.prim = p;
+ mIndexTypes.addElement(indexType);
+ return addedIndex;
+ }
+
+ public int addIndexType(Element e, int size, Primitive p) {
+ int addedIndex = mIndexTypes.size();
+ Entry indexType = new Entry();
+ indexType.t = null;
+ indexType.e = e;
+ indexType.size = size;
+ indexType.prim = p;
+ mIndexTypes.addElement(indexType);
+ return addedIndex;
+ }
+
+ Type newType(Element e, int size) {
+ Type.Builder tb = new Type.Builder(mRS, e);
+ tb.add(Dimension.X, size);
+ return tb.create();
+ }
+
+ static synchronized Mesh internalCreate(RenderScript rs, Builder b) {
+
+ int id = rs.nMeshCreate(b.mVertexTypeCount, b.mIndexTypes.size());
+ Mesh newMesh = new Mesh(id, rs);
+ newMesh.mIndexBuffers = new Allocation[b.mIndexTypes.size()];
+ newMesh.mPrimitives = new Primitive[b.mIndexTypes.size()];
+ newMesh.mVertexBuffers = new Allocation[b.mVertexTypeCount];
+
+ for(int ct = 0; ct < b.mIndexTypes.size(); ct ++) {
+ Allocation alloc = null;
+ Entry entry = (Entry)b.mIndexTypes.elementAt(ct);
+ if (entry.t != null) {
+ alloc = Allocation.createTyped(rs, entry.t);
+ }
+ else if(entry.e != null) {
+ alloc = Allocation.createSized(rs, entry.e, entry.size);
+ }
+ int allocID = (alloc == null) ? 0 : alloc.getID();
+ rs.nMeshBindIndex(id, allocID, entry.prim.mID, ct);
+ newMesh.mIndexBuffers[ct] = alloc;
+ newMesh.mPrimitives[ct] = entry.prim;
+ }
+
+ for(int ct = 0; ct < b.mVertexTypeCount; ct ++) {
+ Allocation alloc = null;
+ Entry entry = b.mVertexTypes[ct];
+ if (entry.t != null) {
+ alloc = Allocation.createTyped(rs, entry.t);
+ } else if(entry.e != null) {
+ alloc = Allocation.createSized(rs, entry.e, entry.size);
+ }
+ rs.nMeshBindVertex(id, alloc.getID(), ct);
+ newMesh.mVertexBuffers[ct] = alloc;
+ }
+
+ return newMesh;
+ }
+
+ public Mesh create() {
+ mRS.validate();
+ Mesh sm = internalCreate(mRS, this);
+ return sm;
+ }
+ }
+
+ public static class AllocationBuilder {
+ RenderScript mRS;
+
+ class Entry {
+ Allocation a;
+ Primitive prim;
+ }
+
+ int mVertexTypeCount;
+ Entry[] mVertexTypes;
+
+ Vector mIndexTypes;
+
+ public AllocationBuilder(RenderScript rs) {
+ mRS = rs;
+ mVertexTypeCount = 0;
+ mVertexTypes = new Entry[16];
+ mIndexTypes = new Vector();
+ }
+
+ public int addVertexAllocation(Allocation a) throws IllegalStateException {
+ if (mVertexTypeCount >= mVertexTypes.length) {
+ throw new IllegalStateException("Max vertex types exceeded.");
+ }
+
+ int addedIndex = mVertexTypeCount;
+ mVertexTypes[mVertexTypeCount] = new Entry();
+ mVertexTypes[mVertexTypeCount].a = a;
+ mVertexTypeCount++;
+ return addedIndex;
+ }
+
+ public int addIndexAllocation(Allocation a, Primitive p) {
+ int addedIndex = mIndexTypes.size();
+ Entry indexType = new Entry();
+ indexType.a = a;
+ indexType.prim = p;
+ mIndexTypes.addElement(indexType);
+ return addedIndex;
+ }
+
+ public int addIndexType(Primitive p) {
+ int addedIndex = mIndexTypes.size();
+ Entry indexType = new Entry();
+ indexType.a = null;
+ indexType.prim = p;
+ mIndexTypes.addElement(indexType);
+ return addedIndex;
+ }
+
+ static synchronized Mesh internalCreate(RenderScript rs, AllocationBuilder b) {
+
+ int id = rs.nMeshCreate(b.mVertexTypeCount, b.mIndexTypes.size());
+ Mesh newMesh = new Mesh(id, rs);
+ newMesh.mIndexBuffers = new Allocation[b.mIndexTypes.size()];
+ newMesh.mPrimitives = new Primitive[b.mIndexTypes.size()];
+ newMesh.mVertexBuffers = new Allocation[b.mVertexTypeCount];
+
+ for(int ct = 0; ct < b.mIndexTypes.size(); ct ++) {
+ Entry entry = (Entry)b.mIndexTypes.elementAt(ct);
+ int allocID = (entry.a == null) ? 0 : entry.a.getID();
+ rs.nMeshBindIndex(id, allocID, entry.prim.mID, ct);
+ newMesh.mIndexBuffers[ct] = entry.a;
+ newMesh.mPrimitives[ct] = entry.prim;
+ }
+
+ for(int ct = 0; ct < b.mVertexTypeCount; ct ++) {
+ Entry entry = b.mVertexTypes[ct];
+ rs.nMeshBindVertex(id, entry.a.mID, ct);
+ newMesh.mVertexBuffers[ct] = entry.a;
+ }
+
+ return newMesh;
+ }
+
+ public Mesh create() {
+ mRS.validate();
+ Mesh sm = internalCreate(mRS, this);
+ return sm;
+ }
+ }
+
+
+ public static class TriangleMeshBuilder {
+ float mVtxData[];
+ int mVtxCount;
+ short mIndexData[];
+ int mIndexCount;
+ RenderScript mRS;
+ Element mElement;
+
+ float mNX = 0;
+ float mNY = 0;
+ float mNZ = -1;
+ float mS0 = 0;
+ float mT0 = 0;
+ float mR = 1;
+ float mG = 1;
+ float mB = 1;
+ float mA = 1;
+
+ int mVtxSize;
+ int mFlags;
+
+ public static final int COLOR = 0x0001;
+ public static final int NORMAL = 0x0002;
+ public static final int TEXTURE_0 = 0x0100;
+
+ public TriangleMeshBuilder(RenderScript rs, int vtxSize, int flags) {
+ mRS = rs;
+ mVtxCount = 0;
+ mIndexCount = 0;
+ mVtxData = new float[128];
+ mIndexData = new short[128];
+ mVtxSize = vtxSize;
+ mFlags = flags;
+
+ if (vtxSize < 2 || vtxSize > 3) {
+ throw new IllegalArgumentException("Vertex size out of range.");
+ }
+ }
+
+ private void makeSpace(int count) {
+ if ((mVtxCount + count) >= mVtxData.length) {
+ float t[] = new float[mVtxData.length * 2];
+ System.arraycopy(mVtxData, 0, t, 0, mVtxData.length);
+ mVtxData = t;
+ }
+ }
+
+ private void latch() {
+ if ((mFlags & COLOR) != 0) {
+ makeSpace(4);
+ mVtxData[mVtxCount++] = mR;
+ mVtxData[mVtxCount++] = mG;
+ mVtxData[mVtxCount++] = mB;
+ mVtxData[mVtxCount++] = mA;
+ }
+ if ((mFlags & TEXTURE_0) != 0) {
+ makeSpace(2);
+ mVtxData[mVtxCount++] = mS0;
+ mVtxData[mVtxCount++] = mT0;
+ }
+ if ((mFlags & NORMAL) != 0) {
+ makeSpace(3);
+ mVtxData[mVtxCount++] = mNX;
+ mVtxData[mVtxCount++] = mNY;
+ mVtxData[mVtxCount++] = mNZ;
+ }
+ }
+
+ public void addVertex(float x, float y) {
+ if (mVtxSize != 2) {
+ throw new IllegalStateException("add mistmatch with declared components.");
+ }
+ makeSpace(2);
+ mVtxData[mVtxCount++] = x;
+ mVtxData[mVtxCount++] = y;
+ latch();
+ }
+
+ public void addVertex(float x, float y, float z) {
+ if (mVtxSize != 3) {
+ throw new IllegalStateException("add mistmatch with declared components.");
+ }
+ makeSpace(3);
+ mVtxData[mVtxCount++] = x;
+ mVtxData[mVtxCount++] = y;
+ mVtxData[mVtxCount++] = z;
+ latch();
+ }
+
+ public void setTexture(float s, float t) {
+ if ((mFlags & TEXTURE_0) == 0) {
+ throw new IllegalStateException("add mistmatch with declared components.");
+ }
+ mS0 = s;
+ mT0 = t;
+ }
+
+ public void setNormal(float x, float y, float z) {
+ if ((mFlags & NORMAL) == 0) {
+ throw new IllegalStateException("add mistmatch with declared components.");
+ }
+ mNX = x;
+ mNY = y;
+ mNZ = z;
+ }
+
+ public void setColor(float r, float g, float b, float a) {
+ if ((mFlags & COLOR) == 0) {
+ throw new IllegalStateException("add mistmatch with declared components.");
+ }
+ mR = r;
+ mG = g;
+ mB = b;
+ mA = a;
+ }
+
+ public void addTriangle(int idx1, int idx2, int idx3) {
+ if((idx1 >= mVtxCount) || (idx1 < 0) ||
+ (idx2 >= mVtxCount) || (idx2 < 0) ||
+ (idx3 >= mVtxCount) || (idx3 < 0)) {
+ throw new IllegalStateException("Index provided greater than vertex count.");
+ }
+ if ((mIndexCount + 3) >= mIndexData.length) {
+ short t[] = new short[mIndexData.length * 2];
+ System.arraycopy(mIndexData, 0, t, 0, mIndexData.length);
+ mIndexData = t;
+ }
+ mIndexData[mIndexCount++] = (short)idx1;
+ mIndexData[mIndexCount++] = (short)idx2;
+ mIndexData[mIndexCount++] = (short)idx3;
+ }
+
+ public Mesh create(boolean uploadToBufferObject) {
+ Element.Builder b = new Element.Builder(mRS);
+ int floatCount = mVtxSize;
+ b.add(Element.createVector(mRS,
+ Element.DataType.FLOAT_32,
+ mVtxSize), "position");
+ if ((mFlags & COLOR) != 0) {
+ floatCount += 4;
+ b.add(Element.F32_4(mRS), "color");
+ }
+ if ((mFlags & TEXTURE_0) != 0) {
+ floatCount += 2;
+ b.add(Element.F32_2(mRS), "texture0");
+ }
+ if ((mFlags & NORMAL) != 0) {
+ floatCount += 3;
+ b.add(Element.F32_3(mRS), "normal");
+ }
+ mElement = b.create();
+
+ Builder smb = new Builder(mRS);
+ smb.addVertexType(mElement, mVtxCount / floatCount);
+ smb.addIndexType(Element.U16(mRS), mIndexCount, Primitive.TRIANGLE);
+
+ Mesh sm = smb.create();
+
+ sm.getVertexAllocation(0).data(mVtxData);
+ if(uploadToBufferObject) {
+ sm.getVertexAllocation(0).uploadToBufferObject();
+ }
+
+ sm.getIndexAllocation(0).data(mIndexData);
+ sm.getIndexAllocation(0).uploadToBufferObject();
+
+ return sm;
+ }
+ }
+}
+
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
index 1614ec5..b16dac1 100644
--- a/graphics/java/android/renderscript/Program.java
+++ b/graphics/java/android/renderscript/Program.java
@@ -91,8 +91,9 @@ public class Program extends BaseObj {
mTextureCount = 0;
}
- public void setShader(String s) {
+ public BaseProgramBuilder setShader(String s) {
mShader = s;
+ return this;
}
public void addInput(Element e) throws IllegalStateException {
@@ -120,12 +121,13 @@ public class Program extends BaseObj {
return mConstantCount++;
}
- public void setTextureCount(int count) throws IllegalArgumentException {
+ public BaseProgramBuilder 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;
+ return this;
}
protected void initProgram(Program p) {
diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java
index 5e04f0c..d06d768 100644
--- a/graphics/java/android/renderscript/ProgramFragment.java
+++ b/graphics/java/android/renderscript/ProgramFragment.java
@@ -106,16 +106,18 @@ public class ProgramFragment extends Program {
mPointSpriteEnable = false;
}
- public void setTexture(EnvMode env, Format fmt, int slot)
+ public Builder setTexture(EnvMode env, Format fmt, int slot)
throws IllegalArgumentException {
if((slot < 0) || (slot >= MAX_TEXTURE)) {
throw new IllegalArgumentException("MAX_TEXTURE exceeded.");
}
mSlots[slot] = new Slot(env, fmt);
+ return this;
}
- public void setPointSpriteTexCoordinateReplacement(boolean enable) {
+ public Builder setPointSpriteTexCoordinateReplacement(boolean enable) {
mPointSpriteEnable = enable;
+ return this;
}
public ProgramFragment create() {
diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java
index 56f9bf4..6fc9fff 100644
--- a/graphics/java/android/renderscript/ProgramRaster.java
+++ b/graphics/java/android/renderscript/ProgramRaster.java
@@ -26,23 +26,34 @@ import android.util.Log;
*
**/
public class ProgramRaster extends BaseObj {
+
+ public enum CullMode {
+ BACK (0),
+ FRONT (1),
+ NONE (2);
+
+ int mID;
+ CullMode(int id) {
+ mID = id;
+ }
+ }
+
boolean mPointSmooth;
boolean mLineSmooth;
boolean mPointSprite;
- float mPointSize;
float mLineWidth;
- Element mIn;
- Element mOut;
+ CullMode mCullMode;
ProgramRaster(int id, RenderScript rs) {
super(rs);
mID = id;
- mPointSize = 1.0f;
mLineWidth = 1.0f;
mPointSmooth = false;
mLineSmooth = false;
mPointSprite = false;
+
+ mCullMode = CullMode.BACK;
}
public void setLineWidth(float w) {
@@ -51,51 +62,43 @@ public class ProgramRaster extends BaseObj {
mRS.nProgramRasterSetLineWidth(mID, w);
}
- public void setPointSize(float s) {
+ public void setCullMode(CullMode m) {
mRS.validate();
- mPointSize = s;
- mRS.nProgramRasterSetPointSize(mID, s);
+ mCullMode = m;
+ mRS.nProgramRasterSetCullMode(mID, m.mID);
}
- void internalInit() {
- int inID = 0;
- int outID = 0;
- if (mIn != null) {
- inID = mIn.mID;
- }
- if (mOut != null) {
- outID = mOut.mID;
- }
- mID = mRS.nProgramRasterCreate(inID, outID, mPointSmooth, mLineSmooth, mPointSprite);
- }
-
-
public static class Builder {
RenderScript mRS;
- ProgramRaster mPR;
+ boolean mPointSprite;
+ boolean mPointSmooth;
+ boolean mLineSmooth;
- public Builder(RenderScript rs, Element in, Element out) {
+ public Builder(RenderScript rs) {
mRS = rs;
- mPR = new ProgramRaster(0, rs);
+ mPointSmooth = false;
+ mLineSmooth = false;
+ mPointSprite = false;
}
- public void setPointSpriteEnable(boolean enable) {
- mPR.mPointSprite = enable;
+ public Builder setPointSpriteEnable(boolean enable) {
+ mPointSprite = enable;
+ return this;
}
- public void setPointSmoothEnable(boolean enable) {
- mPR.mPointSmooth = enable;
+ public Builder setPointSmoothEnable(boolean enable) {
+ mPointSmooth = enable;
+ return this;
}
- public void setLineSmoothEnable(boolean enable) {
- mPR.mLineSmooth = enable;
+ public Builder setLineSmoothEnable(boolean enable) {
+ mLineSmooth = enable;
+ return this;
}
-
static synchronized ProgramRaster internalCreate(RenderScript rs, Builder b) {
- b.mPR.internalInit();
- ProgramRaster pr = b.mPR;
- b.mPR = new ProgramRaster(0, b.mRS);
+ int id = rs.nProgramRasterCreate(b.mPointSmooth, b.mLineSmooth, b.mPointSprite);
+ ProgramRaster pr = new ProgramRaster(id, rs);
return pr;
}
@@ -111,3 +114,4 @@ public class ProgramRaster extends BaseObj {
+
diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java
index 69be245..a92cbb6 100644
--- a/graphics/java/android/renderscript/ProgramStore.java
+++ b/graphics/java/android/renderscript/ProgramStore.java
@@ -114,28 +114,33 @@ public class ProgramStore extends BaseObj {
}
- public void setDepthFunc(DepthFunc func) {
+ public Builder setDepthFunc(DepthFunc func) {
mDepthFunc = func;
+ return this;
}
- public void setDepthMask(boolean enable) {
+ public Builder setDepthMask(boolean enable) {
mDepthMask = enable;
+ return this;
}
- public void setColorMask(boolean r, boolean g, boolean b, boolean a) {
+ public Builder setColorMask(boolean r, boolean g, boolean b, boolean a) {
mColorMaskR = r;
mColorMaskG = g;
mColorMaskB = b;
mColorMaskA = a;
+ return this;
}
- public void setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
+ public Builder setBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
mBlendSrc = src;
mBlendDst = dst;
+ return this;
}
- public void setDitherEnable(boolean enable) {
+ public Builder setDitherEnable(boolean enable) {
mDither = enable;
+ return this;
}
static synchronized ProgramStore internalCreate(RenderScript rs, Builder b) {
@@ -147,17 +152,17 @@ public class ProgramStore extends BaseObj {
if (b.mOut != null) {
outID = b.mOut.mID;
}
- rs.nProgramFragmentStoreBegin(inID, outID);
- rs.nProgramFragmentStoreDepthFunc(b.mDepthFunc.mID);
- rs.nProgramFragmentStoreDepthMask(b.mDepthMask);
- rs.nProgramFragmentStoreColorMask(b.mColorMaskR,
+ rs.nProgramStoreBegin(inID, outID);
+ rs.nProgramStoreDepthFunc(b.mDepthFunc.mID);
+ rs.nProgramStoreDepthMask(b.mDepthMask);
+ rs.nProgramStoreColorMask(b.mColorMaskR,
b.mColorMaskG,
b.mColorMaskB,
b.mColorMaskA);
- rs.nProgramFragmentStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID);
- rs.nProgramFragmentStoreDither(b.mDither);
+ rs.nProgramStoreBlendFunc(b.mBlendSrc.mID, b.mBlendDst.mID);
+ rs.nProgramStoreDither(b.mDither);
- int id = rs.nProgramFragmentStoreCreate();
+ int id = rs.nProgramStoreCreate();
return new ProgramStore(id, rs);
}
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index 1b155d7..ec377e2 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -47,8 +47,9 @@ public class ProgramVertex extends Program {
mRS = rs;
}
- public void setTextureMatrixEnable(boolean enable) {
+ public Builder setTextureMatrixEnable(boolean enable) {
mTextureMatrixEnable = enable;
+ return this;
}
public ProgramVertex create() {
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index a935243..1135a75 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -68,10 +68,11 @@ public class RenderScript {
native void nContextSetSurface(int w, int h, Surface sur);
native void nContextSetPriority(int p);
native void nContextDump(int bits);
+ native void nContextFinish();
native void nContextBindRootScript(int script);
native void nContextBindSampler(int sampler, int slot);
- native void nContextBindProgramFragmentStore(int pfs);
+ native void nContextBindProgramStore(int pfs);
native void nContextBindProgramFragment(int pf);
native void nContextBindProgramVertex(int pf);
native void nContextBindProgramRaster(int pr);
@@ -89,12 +90,15 @@ public class RenderScript {
native int nElementCreate(int type, int kind, boolean norm, int vecSize);
native int nElementCreate2(int[] elements, String[] names);
+ native void nElementGetNativeData(int id, int[] elementData);
+ native void nElementGetSubElements(int id, int[] IDs, String[] names);
native void nTypeBegin(int elementID);
native void nTypeAdd(int dim, int val);
native int nTypeCreate();
native void nTypeFinalDestroy(Type t);
native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
+ native void nTypeGetNativeData(int id, int[] typeData);
native int nAllocationCreateTyped(int type);
native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
@@ -116,6 +120,14 @@ public class RenderScript {
native void nAllocationRead(int id, float[] d);
native void nAllocationSubDataFromObject(int id, Type t, int offset, Object o);
native void nAllocationSubReadFromObject(int id, Type t, int offset, Object o);
+ native int nAllocationGetType(int id);
+
+ native int nFileA3DCreateFromAssetStream(int assetStream);
+ native int nFileA3DGetNumIndexEntries(int fileA3D);
+ native void nFileA3DGetIndexEntries(int fileA3D, int numEntries, int[] IDs, String[] names);
+ native int nFileA3DGetEntryByIndex(int fileA3D, int index);
+
+ native int nFontCreateFromFile(String fileName, int size, int dpi);
native void nAdapter1DBindAllocation(int ad, int alloc);
native void nAdapter1DSetConstraint(int ad, int dim, int value);
@@ -134,36 +146,32 @@ public class RenderScript {
native int nAdapter2DCreate();
native void nScriptBindAllocation(int script, int alloc, int slot);
- native void nScriptSetClearColor(int script, float r, float g, float b, float a);
- native void nScriptSetClearDepth(int script, float depth);
- native void nScriptSetClearStencil(int script, int stencil);
native void nScriptSetTimeZone(int script, byte[] timeZone);
- native void nScriptSetType(int type, boolean writable, String name, int slot);
- native void nScriptSetRoot(boolean isRoot);
- native void nScriptSetInvokable(String name, int slot);
native void nScriptInvoke(int id, int slot);
+ native void nScriptInvokeV(int id, int slot, byte[] params);
+ native void nScriptSetVarI(int id, int slot, int val);
+ native void nScriptSetVarF(int id, int slot, float val);
+ native void nScriptSetVarV(int id, int slot, byte[] val);
native void nScriptCBegin();
native void nScriptCSetScript(byte[] script, int offset, int length);
native int nScriptCCreate();
- native void nScriptCAddDefineI32(String name, int value);
- native void nScriptCAddDefineF(String name, float value);
native void nSamplerBegin();
native void nSamplerSet(int param, int value);
native int nSamplerCreate();
- native void nProgramFragmentStoreBegin(int in, int out);
- native void nProgramFragmentStoreDepthFunc(int func);
- native void nProgramFragmentStoreDepthMask(boolean enable);
- native void nProgramFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a);
- native void nProgramFragmentStoreBlendFunc(int src, int dst);
- native void nProgramFragmentStoreDither(boolean enable);
- native int nProgramFragmentStoreCreate();
+ native void nProgramStoreBegin(int in, int out);
+ native void nProgramStoreDepthFunc(int func);
+ native void nProgramStoreDepthMask(boolean enable);
+ native void nProgramStoreColorMask(boolean r, boolean g, boolean b, boolean a);
+ native void nProgramStoreBlendFunc(int src, int dst);
+ native void nProgramStoreDither(boolean enable);
+ native int nProgramStoreCreate();
- native int nProgramRasterCreate(int in, int out, boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
+ native int nProgramRasterCreate(boolean pointSmooth, boolean lineSmooth, boolean pointSprite);
native void nProgramRasterSetLineWidth(int pr, float v);
- native void nProgramRasterSetPointSize(int pr, float v);
+ native void nProgramRasterSetCullMode(int pr, int mode);
native void nProgramBindConstants(int pv, int slot, int mID);
native void nProgramBindTexture(int vpf, int slot, int a);
@@ -182,9 +190,13 @@ public class RenderScript {
native void nLightSetColor(int l, float r, float g, float b);
native void nLightSetPosition(int l, float x, float y, float z);
- native int nSimpleMeshCreate(int batchID, int idxID, int[] vtxID, int prim);
- native void nSimpleMeshBindVertex(int id, int alloc, int slot);
- native void nSimpleMeshBindIndex(int id, int alloc);
+ native int nMeshCreate(int vtxCount, int indexCount);
+ native void nMeshBindVertex(int id, int alloc, int slot);
+ native void nMeshBindIndex(int id, int alloc, int prim, int slot);
+ native int nMeshGetVertexBufferCount(int id);
+ native int nMeshGetIndexCount(int id);
+ native void nMeshGetVertices(int id, int[] vtxIds, int vtxIdCount);
+ native void nMeshGetIndices(int id, int[] idxIds, int[] primitives, int vtxIdCount);
native void nAnimationBegin(int attribCount, int keyframeCount);
native void nAnimationAdd(float time, float[] attribs);
@@ -195,13 +207,25 @@ public class RenderScript {
@SuppressWarnings({"FieldCanBeLocal"})
protected 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_F32;
+ Element mElement_U8;
+ Element mElement_I8;
+ Element mElement_U16;
+ Element mElement_I16;
+ Element mElement_U32;
+ Element mElement_I32;
+ Element mElement_F32;
+ Element mElement_BOOLEAN;
+
+ Element mElement_ELEMENT;
+ Element mElement_TYPE;
+ Element mElement_ALLOCATION;
+ Element mElement_SAMPLER;
+ Element mElement_SCRIPT;
+ Element mElement_MESH;
+ Element mElement_PROGRAM_FRAGMENT;
+ Element mElement_PROGRAM_VERTEX;
+ Element mElement_PROGRAM_RASTER;
+ Element mElement_PROGRAM_STORE;
Element mElement_A_8;
Element mElement_RGB_565;
@@ -210,13 +234,17 @@ public class RenderScript {
Element mElement_RGBA_4444;
Element mElement_RGBA_8888;
- Element mElement_INDEX_16;
- 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;
+ Element mElement_FLOAT_2;
+ Element mElement_FLOAT_3;
+ Element mElement_FLOAT_4;
+ Element mElement_UCHAR_4;
+
+ Sampler mSampler_CLAMP_NEAREST;
+ Sampler mSampler_CLAMP_LINEAR;
+ Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR;
+ Sampler mSampler_WRAP_NEAREST;
+ Sampler mSampler_WRAP_LINEAR;
+ Sampler mSampler_WRAP_LINEAR_MIP_LINEAR;
///////////////////////////////////////////////////////////////////////////////////
//
@@ -282,7 +310,6 @@ public class RenderScript {
mRS.mMessageCallback.mID = msg;
mRS.mMessageCallback.run();
}
- //Log.d(LOG_TAG, "MessageThread msg " + msg + " v1 " + rbuf[0] + " v2 " + rbuf[1] + " v3 " +rbuf[2]);
}
Log.d(LOG_TAG, "MessageThread exiting.");
}
@@ -307,6 +334,10 @@ public class RenderScript {
nContextDump(bits);
}
+ public void finish() {
+ nContextFinish();
+ }
+
public void destroy() {
validate();
nContextDeinitToClient();
@@ -335,3 +366,4 @@ public class RenderScript {
}
+
diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java
index d1df23d..e90b4fc 100644
--- a/graphics/java/android/renderscript/RenderScriptGL.java
+++ b/graphics/java/android/renderscript/RenderScriptGL.java
@@ -74,9 +74,9 @@ public class RenderScriptGL extends RenderScript {
nContextBindRootScript(safeID(s));
}
- public void contextBindProgramFragmentStore(ProgramStore p) {
+ public void contextBindProgramStore(ProgramStore p) {
validate();
- nContextBindProgramFragmentStore(safeID(p));
+ nContextBindProgramStore(safeID(p));
}
public void contextBindProgramFragment(ProgramFragment p) {
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 40ba722..da83d04 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -51,6 +51,86 @@ public class Sampler extends BaseObj {
mID = id;
}
+ Sampler mSampler_CLAMP_NEAREST;
+ Sampler mSampler_CLAMP_LINEAR;
+ Sampler mSampler_CLAMP_LINEAR_MIP;
+ Sampler mSampler_WRAP_NEAREST;
+ Sampler mSampler_WRAP_LINEAR;
+ Sampler mSampler_WRAP_LINEAR_MIP;
+
+ public static Sampler CLAMP_NEAREST(RenderScript rs) {
+ if(rs.mSampler_CLAMP_NEAREST == null) {
+ Builder b = new Builder(rs);
+ b.setMin(Value.NEAREST);
+ b.setMag(Value.NEAREST);
+ b.setWrapS(Value.CLAMP);
+ b.setWrapT(Value.CLAMP);
+ rs.mSampler_CLAMP_NEAREST = b.create();
+ }
+ return rs.mSampler_CLAMP_NEAREST;
+ }
+
+ public static Sampler CLAMP_LINEAR(RenderScript rs) {
+ if(rs.mSampler_CLAMP_LINEAR == null) {
+ Builder b = new Builder(rs);
+ b.setMin(Value.LINEAR);
+ b.setMag(Value.LINEAR);
+ b.setWrapS(Value.CLAMP);
+ b.setWrapT(Value.CLAMP);
+ rs.mSampler_CLAMP_LINEAR = b.create();
+ }
+ return rs.mSampler_CLAMP_LINEAR;
+ }
+
+ public static Sampler CLAMP_LINEAR_MIP_LINEAR(RenderScript rs) {
+ if(rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) {
+ Builder b = new Builder(rs);
+ b.setMin(Value.LINEAR_MIP_LINEAR);
+ b.setMag(Value.LINEAR_MIP_LINEAR);
+ b.setWrapS(Value.CLAMP);
+ b.setWrapT(Value.CLAMP);
+ rs.mSampler_CLAMP_LINEAR_MIP_LINEAR = b.create();
+ }
+ return rs.mSampler_CLAMP_LINEAR_MIP_LINEAR;
+ }
+
+ public static Sampler WRAP_NEAREST(RenderScript rs) {
+ if(rs.mSampler_WRAP_NEAREST == null) {
+ Builder b = new Builder(rs);
+ b.setMin(Value.NEAREST);
+ b.setMag(Value.NEAREST);
+ b.setWrapS(Value.WRAP);
+ b.setWrapT(Value.WRAP);
+ rs.mSampler_WRAP_NEAREST = b.create();
+ }
+ return rs.mSampler_WRAP_NEAREST;
+ }
+
+ public static Sampler WRAP_LINEAR(RenderScript rs) {
+ if(rs.mSampler_WRAP_LINEAR == null) {
+ Builder b = new Builder(rs);
+ b.setMin(Value.LINEAR);
+ b.setMag(Value.LINEAR);
+ b.setWrapS(Value.WRAP);
+ b.setWrapT(Value.WRAP);
+ rs.mSampler_WRAP_LINEAR = b.create();
+ }
+ return rs.mSampler_WRAP_LINEAR;
+ }
+
+ public static Sampler WRAP_LINEAR_MIP_LINEAR(RenderScript rs) {
+ if(rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) {
+ Builder b = new Builder(rs);
+ b.setMin(Value.LINEAR_MIP_LINEAR);
+ b.setMag(Value.LINEAR_MIP_LINEAR);
+ b.setWrapS(Value.WRAP);
+ b.setWrapT(Value.WRAP);
+ rs.mSampler_WRAP_LINEAR_MIP_LINEAR = b.create();
+ }
+ return rs.mSampler_WRAP_LINEAR_MIP_LINEAR;
+ }
+
+
public static class Builder {
RenderScript mRS;
Value mMin;
diff --git a/graphics/java/android/renderscript/Script.java b/graphics/java/android/renderscript/Script.java
index 57ccfa3..d9aec59 100644
--- a/graphics/java/android/renderscript/Script.java
+++ b/graphics/java/android/renderscript/Script.java
@@ -42,6 +42,19 @@ public class Script extends BaseObj {
}
}
+ protected void invoke(int slot) {
+ mRS.nScriptInvoke(mID, slot);
+ }
+
+ protected void invoke(int slot, FieldPacker v) {
+ if (v != null) {
+ mRS.nScriptInvokeV(mID, slot, v.getData());
+ } else {
+ mRS.nScriptInvoke(mID, slot);
+ }
+ }
+
+
Script(int id, RenderScript rs) {
super(rs);
mID = id;
@@ -49,22 +62,27 @@ public class Script extends BaseObj {
public void bindAllocation(Allocation va, int slot) {
mRS.validate();
- mRS.nScriptBindAllocation(mID, va.mID, slot);
+ if (va != null) {
+ mRS.nScriptBindAllocation(mID, va.mID, slot);
+ } else {
+ mRS.nScriptBindAllocation(mID, 0, slot);
+ }
}
- public void setClearColor(float r, float g, float b, float a) {
- mRS.validate();
- mRS.nScriptSetClearColor(mID, r, g, b, a);
+ public void setVar(int index, float v) {
+ mRS.nScriptSetVarF(mID, index, v);
}
- public void setClearDepth(float d) {
- mRS.validate();
- mRS.nScriptSetClearDepth(mID, d);
+ public void setVar(int index, int v) {
+ mRS.nScriptSetVarI(mID, index, v);
}
- public void setClearStencil(int stencil) {
- mRS.validate();
- mRS.nScriptSetClearStencil(mID, stencil);
+ public void setVar(int index, boolean v) {
+ mRS.nScriptSetVarI(mID, index, v ? 1 : 0);
+ }
+
+ public void setVar(int index, FieldPacker v) {
+ mRS.nScriptSetVarV(mID, index, v.getData());
}
public void setTimeZone(String timeZone) {
@@ -78,72 +96,54 @@ public class Script extends BaseObj {
public static class Builder {
RenderScript mRS;
- boolean mIsRoot = false;
- Type[] mTypes;
- String[] mNames;
- boolean[] mWritable;
- int mInvokableCount = 0;
- Invokable[] mInvokables;
Builder(RenderScript rs) {
mRS = rs;
- mTypes = new Type[MAX_SLOT];
- mNames = new String[MAX_SLOT];
- mWritable = new boolean[MAX_SLOT];
- mInvokables = new Invokable[MAX_SLOT];
}
+ }
+
+
+ public static class FieldBase {
+ protected Element mElement;
+ protected Type mType;
+ protected Allocation mAllocation;
- public void setType(Type t, int slot) {
- mTypes[slot] = t;
- mNames[slot] = null;
+ protected void init(RenderScript rs, int dimx) {
+ mAllocation = Allocation.createSized(rs, mElement, dimx);
+ mType = mAllocation.getType();
}
- public void setType(Type t, String name, int slot) {
- mTypes[slot] = t;
- mNames[slot] = name;
+ protected FieldBase() {
}
- public Invokable addInvokable(String func) {
- Invokable i = new Invokable();
- i.mName = func;
- i.mRS = mRS;
- i.mSlot = mInvokableCount;
- mInvokables[mInvokableCount++] = i;
- return i;
+ public Element getElement() {
+ return mElement;
}
- public void setType(boolean writable, int slot) {
- mWritable[slot] = writable;
+ public Type getType() {
+ return mType;
}
- void transferCreate() {
- mRS.nScriptSetRoot(mIsRoot);
- for(int ct=0; ct < mTypes.length; ct++) {
- if(mTypes[ct] != null) {
- mRS.nScriptSetType(mTypes[ct].mID, mWritable[ct], mNames[ct], ct);
- }
- }
- for(int ct=0; ct < mInvokableCount; ct++) {
- mRS.nScriptSetInvokable(mInvokables[ct].mName, ct);
- }
+ public Allocation getAllocation() {
+ return mAllocation;
}
- void transferObject(Script s) {
- s.mIsRoot = mIsRoot;
- s.mTypes = mTypes;
- s.mInvokables = new Invokable[mInvokableCount];
- for(int ct=0; ct < mInvokableCount; ct++) {
- s.mInvokables[ct] = mInvokables[ct];
- s.mInvokables[ct].mScript = s;
- }
- s.mInvokables = null;
+ //@Override
+ public void updateAllocation() {
}
- public void setRoot(boolean r) {
- mIsRoot = r;
+
+ //
+ /*
+ public class ScriptField_UserField
+ extends android.renderscript.Script.FieldBase {
+
+ protected
+
}
- }
+ */
+ }
}
diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java
index bb99e23..5959be4 100644
--- a/graphics/java/android/renderscript/ScriptC.java
+++ b/graphics/java/android/renderscript/ScriptC.java
@@ -37,11 +37,49 @@ public class ScriptC extends Script {
super(id, rs);
}
+ protected ScriptC(RenderScript rs, Resources resources, int resourceID, boolean isRoot) {
+ super(0, rs);
+ mID = internalCreate(rs, resources, resourceID);
+ }
+
+
+ private static synchronized int internalCreate(RenderScript rs, Resources resources, int resourceID) {
+ byte[] pgm;
+ int pgmLength;
+ InputStream is = resources.openRawResource(resourceID);
+ try {
+ try {
+ pgm = new byte[1024];
+ pgmLength = 0;
+ while(true) {
+ int bytesLeft = pgm.length - pgmLength;
+ if (bytesLeft == 0) {
+ byte[] buf2 = new byte[pgm.length * 2];
+ System.arraycopy(pgm, 0, buf2, 0, pgm.length);
+ pgm = buf2;
+ bytesLeft = pgm.length - pgmLength;
+ }
+ int bytesRead = is.read(pgm, pgmLength, bytesLeft);
+ if (bytesRead <= 0) {
+ break;
+ }
+ pgmLength += bytesRead;
+ }
+ } finally {
+ is.close();
+ }
+ } catch(IOException e) {
+ throw new Resources.NotFoundException();
+ }
+
+ rs.nScriptCBegin();
+ rs.nScriptCSetScript(pgm, 0, pgmLength);
+ return rs.nScriptCCreate();
+ }
+
public static class Builder extends Script.Builder {
byte[] mProgram;
int mProgramLength;
- HashMap<String,Integer> mIntDefines = new HashMap();
- HashMap<String,Float> mFloatDefines = new HashMap();
public Builder(RenderScript rs) {
super(rs);
@@ -92,66 +130,20 @@ public class ScriptC extends Script {
static synchronized ScriptC internalCreate(Builder b) {
b.mRS.nScriptCBegin();
- b.transferCreate();
-
- for (Entry<String,Integer> e: b.mIntDefines.entrySet()) {
- b.mRS.nScriptCAddDefineI32(e.getKey(), e.getValue().intValue());
- }
- for (Entry<String,Float> e: b.mFloatDefines.entrySet()) {
- b.mRS.nScriptCAddDefineF(e.getKey(), e.getValue().floatValue());
- }
+ android.util.Log.e("rs", "len = " + b.mProgramLength);
b.mRS.nScriptCSetScript(b.mProgram, 0, b.mProgramLength);
int id = b.mRS.nScriptCCreate();
ScriptC obj = new ScriptC(id, b.mRS);
- b.transferObject(obj);
-
return obj;
}
- public void addDefine(String name, int value) {
- mIntDefines.put(name, value);
- }
-
- public void addDefine(String name, float value) {
- mFloatDefines.put(name, value);
- }
-
- /**
- * Takes the all public static final fields for a class, and adds defines
- * for them, using the name of the field as the name of the define.
- */
- public void addDefines(Class cl) {
- addDefines(cl.getFields(), (Modifier.STATIC | Modifier.FINAL | Modifier.PUBLIC), null);
- }
-
- /**
- * Takes the all public fields for an object, and adds defines
- * for them, using the name of the field as the name of the define.
- */
- public void addDefines(Object o) {
- addDefines(o.getClass().getFields(), Modifier.PUBLIC, o);
- }
-
- void addDefines(Field[] fields, int mask, Object o) {
- for (Field f: fields) {
- try {
- if ((f.getModifiers() & mask) == mask) {
- Class t = f.getType();
- if (t == int.class) {
- mIntDefines.put(f.getName(), f.getInt(o));
- }
- else if (t == float.class) {
- mFloatDefines.put(f.getName(), f.getFloat(o));
- }
- }
- } catch (IllegalAccessException ex) {
- // TODO: Do we want this log?
- Log.d(TAG, "addDefines skipping field " + f.getName());
- }
- }
- }
+ public void addDefine(String name, int value) {}
+ public void addDefine(String name, float value) {}
+ public void addDefines(Class cl) {}
+ public void addDefines(Object o) {}
+ void addDefines(Field[] fields, int mask, Object o) {}
public ScriptC create() {
return internalCreate(this);
diff --git a/graphics/java/android/renderscript/Short2.java b/graphics/java/android/renderscript/Short2.java
new file mode 100644
index 0000000..426801f
--- /dev/null
+++ b/graphics/java/android/renderscript/Short2.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Short2 {
+ public Short2() {
+ }
+
+ public short x;
+ public short y;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Short3.java b/graphics/java/android/renderscript/Short3.java
new file mode 100644
index 0000000..7b9c305
--- /dev/null
+++ b/graphics/java/android/renderscript/Short3.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Short3 {
+ public Short3() {
+ }
+
+ public short x;
+ public short y;
+ public short z;
+}
+
+
+
+
diff --git a/graphics/java/android/renderscript/Short4.java b/graphics/java/android/renderscript/Short4.java
new file mode 100644
index 0000000..9a474e2
--- /dev/null
+++ b/graphics/java/android/renderscript/Short4.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 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 java.lang.Math;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Short4 {
+ public Short4() {
+ }
+
+ public short x;
+ public short y;
+ public short z;
+ public short w;
+}
+
+
+
diff --git a/graphics/java/android/renderscript/SimpleMesh.java b/graphics/java/android/renderscript/SimpleMesh.java
deleted file mode 100644
index 4a217a9..0000000
--- a/graphics/java/android/renderscript/SimpleMesh.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * 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 SimpleMesh extends BaseObj {
- Type[] mVertexTypes;
- Type mIndexType;
- //Type mBatcheType;
- Primitive mPrimitive;
-
- SimpleMesh(int id, RenderScript rs) {
- super(rs);
- mID = id;
- }
-
- public void bindVertexAllocation(Allocation a, int slot) {
- mRS.validate();
- mRS.nSimpleMeshBindVertex(mID, a.mID, slot);
- }
-
- public void bindIndexAllocation(Allocation a) {
- mRS.validate();
- mRS.nSimpleMeshBindIndex(mID, a.mID);
- }
-
- public Allocation createVertexAllocation(int slot) {
- mRS.validate();
- return Allocation.createTyped(mRS, mVertexTypes[slot]);
- }
-
- public Allocation createIndexAllocation() {
- mRS.validate();
- return Allocation.createTyped(mRS, mIndexType);
- }
-
- public Type getVertexType(int slot) {
- return mVertexTypes[slot];
- }
-
- public Type getIndexType() {
- return mIndexType;
- }
-
- public static class Builder {
- RenderScript mRS;
-
- class Entry {
- Type t;
- Element e;
- int size;
- }
-
- int mVertexTypeCount;
- Entry[] mVertexTypes;
- Entry mIndexType;
- //Entry mBatchType;
- Primitive mPrimitive;
-
-
- public Builder(RenderScript rs) {
- mRS = rs;
- mVertexTypeCount = 0;
- mVertexTypes = new Entry[16];
- mIndexType = new Entry();
- }
-
- public int addVertexType(Type t) throws IllegalStateException {
- if (mVertexTypeCount >= mVertexTypes.length) {
- throw new IllegalStateException("Max vertex types exceeded.");
- }
-
- int addedIndex = mVertexTypeCount;
- mVertexTypes[mVertexTypeCount] = new Entry();
- mVertexTypes[mVertexTypeCount].t = t;
- mVertexTypeCount++;
- return addedIndex;
- }
-
- public int addVertexType(Element e, int size) throws IllegalStateException {
- if (mVertexTypeCount >= mVertexTypes.length) {
- throw new IllegalStateException("Max vertex types exceeded.");
- }
-
- int addedIndex = mVertexTypeCount;
- mVertexTypes[mVertexTypeCount] = new Entry();
- mVertexTypes[mVertexTypeCount].e = e;
- mVertexTypes[mVertexTypeCount].size = size;
- mVertexTypeCount++;
- return addedIndex;
- }
-
- public void setIndexType(Type t) {
- mIndexType.t = t;
- mIndexType.e = null;
- mIndexType.size = 0;
- }
-
- public void setIndexType(Element e, int size) {
- mIndexType.t = null;
- mIndexType.e = e;
- mIndexType.size = size;
- }
-
- public void setPrimitive(Primitive p) {
- mPrimitive = p;
- }
-
-
- Type newType(Element e, int size) {
- Type.Builder tb = new Type.Builder(mRS, e);
- tb.add(Dimension.X, size);
- return tb.create();
- }
-
- static synchronized SimpleMesh internalCreate(RenderScript rs, Builder b) {
- Type[] toDestroy = new Type[18];
- int toDestroyCount = 0;
-
- int indexID = 0;
- if (b.mIndexType.t != null) {
- indexID = b.mIndexType.t.mID;
- } else if (b.mIndexType.size != 0) {
- b.mIndexType.t = b.newType(b.mIndexType.e, b.mIndexType.size);
- indexID = b.mIndexType.t.mID;
- toDestroy[toDestroyCount++] = b.mIndexType.t;
- }
-
- int[] IDs = new int[b.mVertexTypeCount];
- for(int ct=0; ct < b.mVertexTypeCount; ct++) {
- if (b.mVertexTypes[ct].t != null) {
- IDs[ct] = b.mVertexTypes[ct].t.mID;
- } else {
- b.mVertexTypes[ct].t = b.newType(b.mVertexTypes[ct].e, b.mVertexTypes[ct].size);
- IDs[ct] = b.mVertexTypes[ct].t.mID;
- toDestroy[toDestroyCount++] = b.mVertexTypes[ct].t;
- }
- }
-
- int id = rs.nSimpleMeshCreate(0, indexID, IDs, b.mPrimitive.mID);
- for(int ct=0; ct < toDestroyCount; ct++) {
- toDestroy[ct].destroy();
- }
-
- return new SimpleMesh(id, rs);
- }
-
- public SimpleMesh create() {
- mRS.validate();
- SimpleMesh sm = internalCreate(mRS, this);
- sm.mVertexTypes = new Type[mVertexTypeCount];
- for(int ct=0; ct < mVertexTypeCount; ct++) {
- sm.mVertexTypes[ct] = mVertexTypes[ct].t;
- }
- sm.mIndexType = mIndexType.t;
- sm.mPrimitive = mPrimitive;
- return sm;
- }
- }
-
- public static class TriangleMeshBuilder {
- float mVtxData[];
- int mVtxCount;
- short mIndexData[];
- int mIndexCount;
- RenderScript mRS;
- Element mElement;
-
- float mNX = 0;
- float mNY = 0;
- float mNZ = -1;
- float mS0 = 0;
- float mT0 = 0;
- float mR = 1;
- float mG = 1;
- float mB = 1;
- float mA = 1;
-
- int mVtxSize;
- int mFlags;
-
- public static final int COLOR = 0x0001;
- public static final int NORMAL = 0x0002;
- public static final int TEXTURE_0 = 0x0100;
-
- public TriangleMeshBuilder(RenderScript rs, int vtxSize, int flags) {
- mRS = rs;
- mVtxCount = 0;
- mIndexCount = 0;
- mVtxData = new float[128];
- mIndexData = new short[128];
- mVtxSize = vtxSize;
- mFlags = flags;
-
- if (vtxSize < 2 || vtxSize > 3) {
- throw new IllegalArgumentException("Vertex size out of range.");
- }
- }
-
- private void makeSpace(int count) {
- if ((mVtxCount + count) >= mVtxData.length) {
- float t[] = new float[mVtxData.length * 2];
- System.arraycopy(mVtxData, 0, t, 0, mVtxData.length);
- mVtxData = t;
- }
- }
-
- private void latch() {
- if ((mFlags & COLOR) != 0) {
- makeSpace(4);
- mVtxData[mVtxCount++] = mR;
- mVtxData[mVtxCount++] = mG;
- mVtxData[mVtxCount++] = mB;
- mVtxData[mVtxCount++] = mA;
- }
- if ((mFlags & TEXTURE_0) != 0) {
- makeSpace(2);
- mVtxData[mVtxCount++] = mS0;
- mVtxData[mVtxCount++] = mT0;
- }
- if ((mFlags & NORMAL) != 0) {
- makeSpace(3);
- mVtxData[mVtxCount++] = mNX;
- mVtxData[mVtxCount++] = mNY;
- mVtxData[mVtxCount++] = mNZ;
- }
- }
-
- public void addVertex(float x, float y) {
- if (mVtxSize != 2) {
- throw new IllegalStateException("add mistmatch with declared components.");
- }
- makeSpace(2);
- mVtxData[mVtxCount++] = x;
- mVtxData[mVtxCount++] = y;
- latch();
- }
-
- public void addVertex(float x, float y, float z) {
- if (mVtxSize != 3) {
- throw new IllegalStateException("add mistmatch with declared components.");
- }
- makeSpace(3);
- mVtxData[mVtxCount++] = x;
- mVtxData[mVtxCount++] = y;
- mVtxData[mVtxCount++] = z;
- latch();
- }
-
- public void setTexture(float s, float t) {
- if ((mFlags & TEXTURE_0) == 0) {
- throw new IllegalStateException("add mistmatch with declared components.");
- }
- mS0 = s;
- mT0 = t;
- }
-
- public void setNormal(float x, float y, float z) {
- if ((mFlags & NORMAL) == 0) {
- throw new IllegalStateException("add mistmatch with declared components.");
- }
- mNX = x;
- mNY = y;
- mNZ = z;
- }
-
- public void setColor(float r, float g, float b, float a) {
- if ((mFlags & COLOR) == 0) {
- throw new IllegalStateException("add mistmatch with declared components.");
- }
- mR = r;
- mG = g;
- mB = b;
- mA = a;
- }
-
- public void addTriangle(int idx1, int idx2, int idx3) {
- if((idx1 >= mVtxCount) || (idx1 < 0) ||
- (idx2 >= mVtxCount) || (idx2 < 0) ||
- (idx3 >= mVtxCount) || (idx3 < 0)) {
- throw new IllegalStateException("Index provided greater than vertex count.");
- }
- if ((mIndexCount + 3) >= mIndexData.length) {
- short t[] = new short[mIndexData.length * 2];
- System.arraycopy(mIndexData, 0, t, 0, mIndexData.length);
- mIndexData = t;
- }
- mIndexData[mIndexCount++] = (short)idx1;
- mIndexData[mIndexCount++] = (short)idx2;
- mIndexData[mIndexCount++] = (short)idx3;
- }
-
- public SimpleMesh create() {
- Element.Builder b = new Element.Builder(mRS);
- int floatCount = mVtxSize;
- b.add(Element.createAttrib(mRS,
- Element.DataType.FLOAT_32,
- Element.DataKind.POSITION,
- mVtxSize), "position");
- if ((mFlags & COLOR) != 0) {
- floatCount += 4;
- b.add(Element.createAttrib(mRS,
- Element.DataType.FLOAT_32,
- Element.DataKind.COLOR,
- 4), "color");
- }
- if ((mFlags & TEXTURE_0) != 0) {
- floatCount += 2;
- b.add(Element.createAttrib(mRS,
- Element.DataType.FLOAT_32,
- Element.DataKind.TEXTURE,
- 2), "texture");
- }
- if ((mFlags & NORMAL) != 0) {
- floatCount += 3;
- 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.createIndex(mRS), mIndexCount);
- smb.setPrimitive(Primitive.TRIANGLE);
- SimpleMesh sm = smb.create();
-
- Allocation vertexAlloc = sm.createVertexAllocation(0);
- Allocation indexAlloc = sm.createIndexAllocation();
- sm.bindVertexAllocation(vertexAlloc, 0);
- sm.bindIndexAllocation(indexAlloc);
-
- vertexAlloc.data(mVtxData);
- vertexAlloc.uploadToBufferObject();
-
- indexAlloc.data(mIndexData);
- indexAlloc.uploadToBufferObject();
-
- return sm;
- }
- }
-}
-
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index 62d3867..8e45f2b 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -16,7 +16,9 @@
package android.renderscript;
+
import java.lang.reflect.Field;
+import android.util.Log;
/**
* @hide
@@ -108,48 +110,30 @@ public class Type extends BaseObj {
super.finalize();
}
- public static Type createFromClass(RenderScript rs, Class c, int size) {
- Element e = Element.createFromClass(rs, c);
- Builder b = new Builder(rs, e);
- b.add(Dimension.X, size);
- Type t = b.create();
- e.destroy();
-
- // native fields
- {
- Field[] fields = c.getFields();
- int[] arTypes = new int[fields.length];
- int[] arBits = new int[fields.length];
-
- for(int ct=0; ct < fields.length; ct++) {
- Field f = fields[ct];
- Class fc = f.getType();
- if(fc == int.class) {
- arTypes[ct] = Element.DataType.SIGNED_32.mID;
- arBits[ct] = 32;
- } else if(fc == short.class) {
- arTypes[ct] = Element.DataType.SIGNED_16.mID;
- arBits[ct] = 16;
- } else if(fc == byte.class) {
- arTypes[ct] = Element.DataType.SIGNED_8.mID;
- arBits[ct] = 8;
- } else if(fc == float.class) {
- arTypes[ct] = Element.DataType.FLOAT_32.mID;
- arBits[ct] = 32;
- } else {
- throw new IllegalArgumentException("Unkown field type");
- }
- }
- rs.nTypeSetupFields(t, arTypes, arBits, fields);
+ @Override
+ void updateFromNative() {
+ // We have 6 integer to obtain mDimX; mDimY; mDimZ;
+ // mDimLOD; mDimFaces; mElement;
+ int[] dataBuffer = new int[6];
+ mRS.nTypeGetNativeData(mID, dataBuffer);
+
+ mDimX = dataBuffer[0];
+ mDimY = dataBuffer[1];
+ mDimZ = dataBuffer[2];
+ mDimLOD = dataBuffer[3] == 1 ? true : false;
+ mDimFaces = dataBuffer[4] == 1 ? true : false;
+
+ int elementID = dataBuffer[5];
+ if(elementID != 0) {
+ mElement = new Element(mRS, elementID);
+ mElement.updateFromNative();
}
- t.mJavaClass = c;
- return t;
+ calcElementCount();
}
public static Type createFromClass(RenderScript rs, Class c, int size, String scriptName) {
- Type t = createFromClass(rs, c, size);
- t.setName(scriptName);
- return t;
+ android.util.Log.e("RenderScript", "Calling depricated createFromClass");
+ return null;
}