summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--graphics/java/android/renderscript/Allocation.java19
-rw-r--r--graphics/java/android/renderscript/BaseObj.java1
-rw-r--r--graphics/java/android/renderscript/Element.java557
-rw-r--r--graphics/java/android/renderscript/ProgramVertex.java2
-rw-r--r--graphics/java/android/renderscript/RenderScript.java20
-rw-r--r--graphics/java/android/renderscript/SimpleMesh.java28
-rw-r--r--graphics/java/android/renderscript/Type.java8
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp84
-rw-r--r--libs/rs/Android.mk1
-rw-r--r--libs/rs/RenderScript.h60
-rw-r--r--libs/rs/java/Film/src/com/android/film/FilmRS.java14
-rw-r--r--libs/rs/java/Fountain/res/raw/fountain.c28
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java7
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java14
-rw-r--r--libs/rs/rs.spec21
-rw-r--r--libs/rs/rsAllocation.cpp12
-rw-r--r--libs/rs/rsComponent.cpp316
-rw-r--r--libs/rs/rsComponent.h68
-rw-r--r--libs/rs/rsContext.cpp17
-rw-r--r--libs/rs/rsContext.h1
-rw-r--r--libs/rs/rsElement.cpp241
-rw-r--r--libs/rs/rsElement.h30
-rw-r--r--libs/rs/rsFileA3D.cpp2
-rw-r--r--libs/rs/rsProgramFragment.cpp36
-rw-r--r--libs/rs/rsProgramVertex.cpp4
-rw-r--r--libs/rs/rsScriptC.cpp65
-rw-r--r--libs/rs/rsScriptC_Lib.cpp38
-rw-r--r--libs/rs/rsShaderCache.cpp5
-rw-r--r--libs/rs/rsSimpleMesh.cpp7
-rw-r--r--libs/rs/rsType.cpp98
-rw-r--r--libs/rs/rsVertexArray.cpp9
-rw-r--r--libs/rs/rsVertexArray.h4
32 files changed, 1018 insertions, 799 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index b6ac14a..880e459 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -171,9 +171,10 @@ public class Allocation extends BaseObj {
public Adapter1D createAdapter1D() {
mRS.validate();
int id = mRS.nAdapter1DCreate();
- if (id != 0) {
- mRS.nAdapter1DBindAllocation(id, mID);
+ if(id == 0) {
+ throw new IllegalStateException("allocation failed.");
}
+ mRS.nAdapter1DBindAllocation(id, mID);
return new Adapter1D(id, mRS);
}
@@ -213,9 +214,10 @@ public class Allocation extends BaseObj {
public Adapter2D createAdapter2D() {
mRS.validate();
int id = mRS.nAdapter2DCreate();
- if (id != 0) {
- mRS.nAdapter2DBindAllocation(id, mID);
+ if(id == 0) {
+ throw new IllegalStateException("allocation failed.");
}
+ mRS.nAdapter2DBindAllocation(id, mID);
return new Adapter2D(id, mRS);
}
@@ -258,6 +260,9 @@ public class Allocation extends BaseObj {
rs.validate();
int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(id, rs, null);
}
@@ -266,6 +271,9 @@ public class Allocation extends BaseObj {
rs.validate();
int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(id, rs, null);
}
@@ -282,6 +290,9 @@ public class Allocation extends BaseObj {
int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mID, genMips,
asset);
+ if(allocationId == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(allocationId, rs, null);
} catch (Exception e) {
// Ignore
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java
index e802ec5..002fc78 100644
--- a/graphics/java/android/renderscript/BaseObj.java
+++ b/graphics/java/android/renderscript/BaseObj.java
@@ -25,6 +25,7 @@ import android.util.Log;
class BaseObj {
BaseObj(RenderScript rs) {
+ rs.validate();
mRS = rs;
mID = 0;
mDestroyed = false;
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index ee9b098..66b1ccb 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -24,259 +24,220 @@ import java.lang.reflect.Field;
**/
public class Element extends BaseObj {
int mSize;
- Entry[] mEntries;
+ Element[] mElements;
+ String[] mElementNames;
- int getSizeBytes() {
- return mSize;
- }
- int getComponentCount() {
- return mEntries.length;
- }
- Element.DataType getComponentDataType(int num) {
- return mEntries[num].mType;
- }
- Element.DataKind getComponentDataKind(int num) {
- return mEntries[num].mKind;
- }
- boolean getComponentIsNormalized(int num) {
- return mEntries[num].mIsNormalized;
- }
- int getComponentBits(int num) {
- return mEntries[num].mBits;
- }
- String getComponentName(int num) {
- return mEntries[num].mName;
+ DataType mType;
+ DataKind mKind;
+ boolean mNormalized;
+ int mVectorSize;
+
+ int getSizeBytes() {return mSize;}
+
+ public enum DataType {
+ //FLOAT_16 (1, 2),
+ FLOAT_32 (2, 4),
+ //FLOAT_64 (3, 8),
+ SIGNED_8 (4, 1),
+ SIGNED_16 (5, 2),
+ SIGNED_32 (6, 4),
+ //SIGNED_64 (7, 8),
+ UNSIGNED_8 (8, 1),
+ UNSIGNED_16 (9, 2),
+ UNSIGNED_32 (10, 4),
+ //UNSIGNED_64 (11, 8),
+
+ UNSIGNED_5_6_5 (12, 2),
+ UNSIGNED_5_5_5_1 (13, 2),
+ UNSIGNED_4_4_4_4 (14, 2),
+
+ RS_ELEMENT (15, 4),
+ RS_TYPE (16, 4),
+ RS_ALLOCATION (17, 4),
+ RS_SAMPLER (18, 4),
+ RS_SCRIPT (19, 4),
+ RS_MESH (20, 4),
+ RS_PROGRAM_FRAGMENT (21, 4),
+ RS_PROGRAM_VERTEX (22, 4),
+ RS_PROGRAM_RASTER (23, 4),
+ RS_PROGRAM_STORE (24, 4);
+
+ int mID;
+ int mSize;
+ DataType(int id, int size) {
+ mID = id;
+ mSize = size;
+ }
}
- static class Entry {
- //Element mElement;
- Element.DataType mType;
- Element.DataKind mKind;
- boolean mIsNormalized;
- int mBits;
- String mName;
-
- //Entry(Element e, int bits) {
- //mElement = e;
- //int mBits = bits;
- //}
-
- Entry(DataType dt, DataKind dk, boolean isNorm, int bits, String name) {
- mType = dt;
- mKind = dk;
- mIsNormalized = isNorm;
- mBits = bits;
- mName = name;
+ public enum DataKind {
+ USER (0),
+ COLOR (1),
+ POSITION (2),
+ TEXTURE (3),
+ NORMAL (4),
+ INDEX (5),
+ POINT_SIZE(6),
+
+ PIXEL_L (7),
+ PIXEL_A (8),
+ PIXEL_LA (9),
+ PIXEL_RGB (10),
+ PIXEL_RGBA (11);
+
+ int mID;
+ DataKind(int id) {
+ mID = id;
}
}
public static Element USER_U8(RenderScript rs) {
if(rs.mElement_USER_U8 == null) {
- rs.mElement_USER_U8 = new Element(rs, 1);
- rs.mElement_USER_U8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 8, null);
- rs.mElement_USER_U8.init();
+ rs.mElement_USER_U8 = createUser(rs, DataType.UNSIGNED_8);
}
return rs.mElement_USER_U8;
}
public static Element USER_I8(RenderScript rs) {
if(rs.mElement_USER_I8 == null) {
- rs.mElement_USER_I8 = new Element(rs, 1);
- rs.mElement_USER_I8.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 8, null);
- rs.mElement_USER_I8.init();
+ rs.mElement_USER_I8 = createUser(rs, DataType.SIGNED_8);
}
return rs.mElement_USER_I8;
}
- public static Element USER_U16(RenderScript rs) {
- if(rs.mElement_USER_U16 == null) {
- rs.mElement_USER_U16 = new Element(rs, 1);
- rs.mElement_USER_U16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 16, null);
- rs.mElement_USER_U16.init();
- }
- return rs.mElement_USER_U16;
- }
-
- public static Element USER_I16(RenderScript rs) {
- if(rs.mElement_USER_I16 == null) {
- rs.mElement_USER_I16 = new Element(rs, 1);
- rs.mElement_USER_I16.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 16, null);
- rs.mElement_USER_I16.init();
- }
- return rs.mElement_USER_I16;
- }
-
public static Element USER_U32(RenderScript rs) {
if(rs.mElement_USER_U32 == null) {
- rs.mElement_USER_U32 = new Element(rs, 1);
- rs.mElement_USER_U32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 32, null);
- rs.mElement_USER_U32.init();
+ rs.mElement_USER_U32 = createUser(rs, DataType.UNSIGNED_32);
}
return rs.mElement_USER_U32;
}
public static Element USER_I32(RenderScript rs) {
if(rs.mElement_USER_I32 == null) {
- rs.mElement_USER_I32 = new Element(rs, 1);
- rs.mElement_USER_I32.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 32, null);
- rs.mElement_USER_I32.init();
+ rs.mElement_USER_I32 = createUser(rs, DataType.SIGNED_32);
}
return rs.mElement_USER_I32;
}
public static Element USER_F32(RenderScript rs) {
- if(rs.mElement_USER_FLOAT == null) {
- rs.mElement_USER_FLOAT = new Element(rs, 1);
- rs.mElement_USER_FLOAT.mEntries[0] = new Entry(DataType.FLOAT, DataKind.USER, false, 32, null);
- rs.mElement_USER_FLOAT.init();
+ if(rs.mElement_USER_F32 == null) {
+ rs.mElement_USER_F32 = createUser(rs, DataType.FLOAT_32);
}
- return rs.mElement_USER_FLOAT;
+ return rs.mElement_USER_F32;
}
public static Element A_8(RenderScript rs) {
if(rs.mElement_A_8 == null) {
- rs.mElement_A_8 = new Element(rs, 1);
- rs.mElement_A_8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
- rs.mElement_A_8.init();
+ rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A);
}
return rs.mElement_A_8;
}
public static Element RGB_565(RenderScript rs) {
if(rs.mElement_RGB_565 == null) {
- rs.mElement_RGB_565 = new Element(rs, 3);
- rs.mElement_RGB_565.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
- rs.mElement_RGB_565.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 6, "g");
- rs.mElement_RGB_565.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
- rs.mElement_RGB_565.init();
+ rs.mElement_RGB_565 = createPixel(rs, DataType.UNSIGNED_5_6_5, DataKind.PIXEL_RGB);
}
return rs.mElement_RGB_565;
}
public static Element RGB_888(RenderScript rs) {
if(rs.mElement_RGB_888 == null) {
- rs.mElement_RGB_888 = new Element(rs, 3);
- rs.mElement_RGB_888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
- rs.mElement_RGB_888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
- rs.mElement_RGB_888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
- rs.mElement_RGB_888.init();
+ rs.mElement_RGB_888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGB);
}
return rs.mElement_RGB_888;
}
public static Element RGBA_5551(RenderScript rs) {
if(rs.mElement_RGBA_5551 == null) {
- rs.mElement_RGBA_5551 = new Element(rs, 4);
- rs.mElement_RGBA_5551.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
- rs.mElement_RGBA_5551.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 5, "g");
- rs.mElement_RGBA_5551.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
- rs.mElement_RGBA_5551.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 1, "a");
- rs.mElement_RGBA_5551.init();
+ rs.mElement_RGBA_5551 = createPixel(rs, DataType.UNSIGNED_5_5_5_1, DataKind.PIXEL_RGBA);
}
return rs.mElement_RGBA_5551;
}
public static Element RGBA_4444(RenderScript rs) {
if(rs.mElement_RGBA_4444 == null) {
- rs.mElement_RGBA_4444 = new Element(rs, 4);
- rs.mElement_RGBA_4444.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 4, "r");
- rs.mElement_RGBA_4444.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 4, "g");
- rs.mElement_RGBA_4444.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 4, "b");
- rs.mElement_RGBA_4444.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 4, "a");
- rs.mElement_RGBA_4444.init();
+ rs.mElement_RGBA_4444 = createPixel(rs, DataType.UNSIGNED_4_4_4_4, DataKind.PIXEL_RGBA);
}
return rs.mElement_RGBA_4444;
}
public static Element RGBA_8888(RenderScript rs) {
if(rs.mElement_RGBA_8888 == null) {
- rs.mElement_RGBA_8888 = new Element(rs, 4);
- rs.mElement_RGBA_8888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
- rs.mElement_RGBA_8888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
- rs.mElement_RGBA_8888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
- rs.mElement_RGBA_8888.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
- rs.mElement_RGBA_8888.init();
+ rs.mElement_RGBA_8888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGBA);
}
return rs.mElement_RGBA_8888;
}
public static Element INDEX_16(RenderScript rs) {
if(rs.mElement_INDEX_16 == null) {
- rs.mElement_INDEX_16 = new Element(rs, 1);
- rs.mElement_INDEX_16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.INDEX, false, 16, "index");
- rs.mElement_INDEX_16.init();
+ rs.mElement_INDEX_16 = createIndex(rs);
}
return rs.mElement_INDEX_16;
}
- public static Element XY_F32(RenderScript rs) {
- if(rs.mElement_XY_F32 == null) {
- rs.mElement_XY_F32 = new Element(rs, 2);
- rs.mElement_XY_F32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.X, false, 32, "x");
- rs.mElement_XY_F32.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.Y, false, 32, "y");
- rs.mElement_XY_F32.init();
+ public static Element ATTRIB_POSITION_2(RenderScript rs) {
+ if(rs.mElement_POSITION_2 == null) {
+ rs.mElement_POSITION_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 2);
}
- return rs.mElement_XY_F32;
+ return rs.mElement_POSITION_2;
}
- public static Element XYZ_F32(RenderScript rs) {
- if(rs.mElement_XYZ_F32 == null) {
- rs.mElement_XYZ_F32 = new Element(rs, 3);
- rs.mElement_XYZ_F32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.X, false, 32, "x");
- rs.mElement_XYZ_F32.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.Y, false, 32, "y");
- rs.mElement_XYZ_F32.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.Z, false, 32, "z");
- rs.mElement_XYZ_F32.init();
+ public static Element ATTRIB_POSITION_3(RenderScript rs) {
+ if(rs.mElement_POSITION_3 == null) {
+ rs.mElement_POSITION_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 3);
}
- return rs.mElement_XYZ_F32;
+ return rs.mElement_POSITION_3;
}
- static void initPredefined(RenderScript rs) {
- rs.nInitElements(A_8(rs).mID, RGBA_4444(rs).mID, RGBA_8888(rs).mID, RGB_565(rs).mID);
+ public static Element ATTRIB_TEXTURE_2(RenderScript rs) {
+ if(rs.mElement_TEXTURE_2 == null) {
+ rs.mElement_TEXTURE_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.TEXTURE, 2);
+ }
+ return rs.mElement_TEXTURE_2;
}
- public enum DataType {
- FLOAT (0),
- UNSIGNED (1),
- SIGNED (2);
-
- int mID;
- DataType(int id) {
- mID = id;
+ public static Element ATTRIB_NORMAL_3(RenderScript rs) {
+ if(rs.mElement_NORMAL_3 == null) {
+ rs.mElement_NORMAL_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.NORMAL, 3);
}
+ return rs.mElement_NORMAL_3;
}
- public enum DataKind {
- USER (0),
- RED (1),
- GREEN (2),
- BLUE (3),
- ALPHA (4),
- LUMINANCE (5),
- INTENSITY (6),
- X (7),
- Y (8),
- Z (9),
- W (10),
- S (11),
- T (12),
- Q (13),
- R (14),
- NX (15),
- NY (16),
- NZ (17),
- INDEX (18),
- POINT_SIZE(19);
+ public static Element ATTRIB_COLOR_U8_4(RenderScript rs) {
+ if(rs.mElement_COLOR_U8_4 == null) {
+ rs.mElement_COLOR_U8_4 = createAttrib(rs, DataType.UNSIGNED_8, DataKind.COLOR, 4);
+ }
+ return rs.mElement_COLOR_U8_4;
+ }
- int mID;
- DataKind(int id) {
- mID = id;
+ public static Element ATTRIB_COLOR_F32_4(RenderScript rs) {
+ if(rs.mElement_COLOR_F32_4 == null) {
+ rs.mElement_COLOR_F32_4 = createAttrib(rs, DataType.FLOAT_32, DataKind.COLOR, 4);
}
+ return rs.mElement_COLOR_F32_4;
}
- Element(RenderScript rs, int count) {
+ Element(RenderScript rs, Element[] e, String[] n) {
super(rs);
mSize = 0;
- mEntries = new Entry[count];
+ mElements = e;
+ mElementNames = n;
+ int[] ids = new int[mElements.length];
+ for (int ct = 0; ct < mElements.length; ct++ ) {
+ mSize += mElements[ct].mSize;
+ ids[ct] = mElements[ct].mID;
+ }
+ mID = rs.nElementCreate2(ids, mElementNames);
+ }
+
+ Element(RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
+ super(rs);
+ mSize = dt.mSize * size;
+ mType = dt;
+ mKind = dk;
+ mNormalized = norm;
+ mVectorSize = size;
+ mID = rs.nElementCreate(dt.mID, dk.mID, norm, size);
}
public void destroy() throws IllegalStateException {
@@ -291,13 +252,13 @@ public class Element extends BaseObj {
for(Field f: fields) {
Class fc = f.getType();
if(fc == int.class) {
- b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 32, f.getName());
+ b.add(createUser(rs, DataType.SIGNED_32), f.getName());
} else if(fc == short.class) {
- b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 16, f.getName());
+ b.add(createUser(rs, DataType.SIGNED_16), f.getName());
} else if(fc == byte.class) {
- b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 8, f.getName());
+ b.add(createUser(rs, DataType.SIGNED_8), f.getName());
} else if(fc == float.class) {
- b.add(Element.DataType.FLOAT, Element.DataKind.USER, false, 32, f.getName());
+ b.add(createUser(rs, DataType.FLOAT_32), f.getName());
} else {
throw new IllegalArgumentException("Unkown field type");
}
@@ -305,193 +266,161 @@ public class Element extends BaseObj {
return b.create();
}
- static synchronized void internalCreate(RenderScript rs, Element e) {
- rs.nElementBegin();
- int bits = 0;
- for (int ct=0; ct < e.mEntries.length; ct++) {
- Entry en = e.mEntries[ct];
- //if(en.mElement != null) {
- //rs.nElementAdd(en.mElement.mID);
- //} else
- {
- rs.nElementAdd(en.mKind.mID, en.mType.mID, en.mIsNormalized, en.mBits, en.mName);
- bits += en.mBits;
- }
- }
- e.mID = rs.nElementCreate();
- e.mSize = (bits + 7) >> 3;
- }
- void init() {
- mRS.validate();
- internalCreate(mRS, this);
+ /////////////////////////////////////////
+ public static Element createUser(RenderScript rs, DataType dt) {
+ //android.util.Log.e("rs", "createUser " + dt.mID);
+ return new Element(rs, dt, DataKind.USER, false, 1);
}
-
- public static class Builder {
- RenderScript mRS;
- Entry[] mEntries;
- int mEntryCount;
-
- public Builder(RenderScript rs) {
- mRS = rs;
- mEntryCount = 0;
- mEntries = new Entry[8];
- }
-
- void addEntry(Entry e) {
- if(mEntries.length >= mEntryCount) {
- Entry[] en = new Entry[mEntryCount + 8];
- System.arraycopy(mEntries, 0, en, 0, mEntries.length);
- mEntries = en;
- }
- mEntries[mEntryCount] = e;
- mEntryCount++;
+ public static Element createVector(RenderScript rs, DataType dt, int size) {
+ //android.util.Log.e("rs", "createVector " + dt.mID + ", " + size);
+ if (size < 2 || size > 4) {
+ throw new IllegalArgumentException("Bad size");
}
+ return new Element(rs, dt, DataKind.USER, false, size);
+ }
- //public Builder add(Element e) throws IllegalArgumentException {
- //Entry en = new Entry(e, e.mSize * 8);
- //addEntry(en);
- //return this;
- //}
+ public static Element createIndex(RenderScript rs) {
+ android.util.Log.e("rs", "createIndex ");
+ return new Element(rs, DataType.UNSIGNED_16, DataKind.INDEX, false, 1);
+ }
- public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) {
- Entry en = new Entry(dt, dk, isNormalized, bits, name);
- addEntry(en);
- return this;
+ public static Element createAttrib(RenderScript rs, DataType dt, DataKind dk, int size) {
+ android.util.Log.e("rs", "createAttrib " + dt.mID + ", " + dk.mID + ", " + size);
+ if (!(dt == DataType.FLOAT_32 ||
+ dt == DataType.UNSIGNED_8 ||
+ dt == DataType.UNSIGNED_16 ||
+ dt == DataType.UNSIGNED_32 ||
+ dt == DataType.SIGNED_8 ||
+ dt == DataType.SIGNED_16 ||
+ dt == DataType.SIGNED_32)) {
+ throw new IllegalArgumentException("Unsupported DataType");
}
- public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) {
- add(dt, dk, isNormalized, bits, null);
- return this;
+ if (!(dk == DataKind.COLOR ||
+ dk == DataKind.POSITION ||
+ dk == DataKind.TEXTURE ||
+ dk == DataKind.NORMAL ||
+ dk == DataKind.POINT_SIZE)) {
+ throw new IllegalArgumentException("Unsupported DataKind");
}
- public Builder addFloat(Element.DataKind dk) {
- add(DataType.FLOAT, dk, false, 32, null);
- return this;
+ if (dk == DataKind.COLOR &&
+ ((dt != DataType.FLOAT_32 && dt != DataType.UNSIGNED_8) ||
+ size < 3 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloat(Element.DataKind dk, String name) {
- add(DataType.FLOAT, dk, false, 32, name);
- return this;
+ if (dk == DataKind.POSITION && (size < 1 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXY() {
- add(DataType.FLOAT, DataKind.X, false, 32, null);
- add(DataType.FLOAT, DataKind.Y, false, 32, null);
- return this;
+ if (dk == DataKind.TEXTURE &&
+ (dt != DataType.FLOAT_32 || size < 1 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXY(String prefix) {
- add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
- add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
- return this;
+ if (dk == DataKind.NORMAL &&
+ (dt != DataType.FLOAT_32 || size != 3)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXYZ() {
- add(DataType.FLOAT, DataKind.X, false, 32, null);
- add(DataType.FLOAT, DataKind.Y, false, 32, null);
- add(DataType.FLOAT, DataKind.Z, false, 32, null);
- return this;
+ if (dk == DataKind.POINT_SIZE &&
+ (dt != DataType.FLOAT_32 || size != 1)) {
+ throw new IllegalArgumentException("Bad combo");
}
- public Builder addFloatXYZ(String prefix) {
- add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
- add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
- add(DataType.FLOAT, DataKind.Z, false, 32, prefix + "z");
- return this;
+ boolean norm = false;
+ if (dk == DataKind.COLOR && dt == DataType.UNSIGNED_8) {
+ norm = true;
}
- public Builder addFloatST() {
- add(DataType.FLOAT, DataKind.S, false, 32, null);
- add(DataType.FLOAT, DataKind.T, false, 32, null);
- return this;
- }
+ return new Element(rs, dt, dk, norm, size);
+ }
- public Builder addFloatST(String prefix) {
- add(DataType.FLOAT, DataKind.S, false, 32, prefix + "s");
- add(DataType.FLOAT, DataKind.T, false, 32, prefix + "t");
- return this;
+ public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) {
+ android.util.Log.e("rs", "createPixel " + dt.mID + ", " + dk.mID);
+ if (!(dk == DataKind.PIXEL_L ||
+ dk == DataKind.PIXEL_A ||
+ dk == DataKind.PIXEL_LA ||
+ dk == DataKind.PIXEL_RGB ||
+ dk == DataKind.PIXEL_RGBA)) {
+ throw new IllegalArgumentException("Unsupported DataKind");
}
-
- public Builder addFloatNorm() {
- add(DataType.FLOAT, DataKind.NX, false, 32, null);
- add(DataType.FLOAT, DataKind.NY, false, 32, null);
- add(DataType.FLOAT, DataKind.NZ, false, 32, null);
- return this;
+ if (!(dt == DataType.UNSIGNED_8 ||
+ dt == DataType.UNSIGNED_5_6_5 ||
+ dt == DataType.UNSIGNED_4_4_4_4 ||
+ dt == DataType.UNSIGNED_5_5_5_1)) {
+ throw new IllegalArgumentException("Unsupported DataType");
}
-
- public Builder addFloatNorm(String prefix) {
- add(DataType.FLOAT, DataKind.NX, false, 32, prefix + "nx");
- add(DataType.FLOAT, DataKind.NY, false, 32, prefix + "ny");
- add(DataType.FLOAT, DataKind.NZ, false, 32, prefix + "nz");
- return this;
+ if (dt == DataType.UNSIGNED_5_6_5 && dk != DataKind.PIXEL_RGB) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
-
- public Builder addFloatPointSize() {
- add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, null);
- return this;
+ if (dt == DataType.UNSIGNED_5_5_5_1 && dk != DataKind.PIXEL_RGBA) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
-
- public Builder addFloatPointSize(String prefix) {
- add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, prefix + "pointSize");
- return this;
+ if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
- public Builder addFloatRGB() {
- add(DataType.FLOAT, DataKind.RED, false, 32, null);
- add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
- add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
- return this;
+ int size = 1;
+ if (dk == DataKind.PIXEL_LA) {
+ size = 2;
}
-
- public Builder addFloatRGB(String prefix) {
- add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
- add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
- add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
- return this;
+ if (dk == DataKind.PIXEL_RGB) {
+ size = 3;
}
-
- public Builder addFloatRGBA() {
- add(DataType.FLOAT, DataKind.RED, false, 32, null);
- add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
- add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
- add(DataType.FLOAT, DataKind.ALPHA, false, 32, null);
- return this;
+ if (dk == DataKind.PIXEL_RGBA) {
+ size = 4;
}
- public Builder addFloatRGBA(String prefix) {
- add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
- add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
- add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
- add(DataType.FLOAT, DataKind.ALPHA, false, 32, prefix + "a");
- return this;
- }
+ return new Element(rs, dt, dk, true, size);
+ }
- public Builder addUNorm8RGBA() {
- add(DataType.UNSIGNED, DataKind.RED, true, 8, null);
- add(DataType.UNSIGNED, DataKind.GREEN, true, 8, null);
- add(DataType.UNSIGNED, DataKind.BLUE, true, 8, null);
- add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, null);
- return this;
- }
+ public static class Builder {
+ RenderScript mRS;
+ Element[] mElements;
+ String[] mElementNames;
+ int mCount;
- public Builder addUNorm8RGBA(String prefix) {
- add(DataType.UNSIGNED, DataKind.RED, true, 8, prefix + "r");
- add(DataType.UNSIGNED, DataKind.GREEN, true, 8, prefix + "g");
- add(DataType.UNSIGNED, DataKind.BLUE, true, 8, prefix + "b");
- add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, prefix + "a");
- return this;
+ public Builder(RenderScript rs) {
+ mRS = rs;
+ mCount = 0;
+ mElements = new Element[8];
+ mElementNames = new String[8];
+ }
+
+ public void add(Element element, String name) {
+ if(mCount == mElements.length) {
+ Element[] e = new Element[mCount + 8];
+ String[] s = new String[mCount + 8];
+ System.arraycopy(mElements, 0, e, 0, mCount);
+ System.arraycopy(mElementNames, 0, s, 0, mCount);
+ mElements = e;
+ mElementNames = s;
+ }
+ mElements[mCount] = element;
+ mElementNames[mCount] = name;
+ mCount++;
}
public Element create() {
mRS.validate();
- Element e = new Element(mRS, mEntryCount);
- java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount);
- e.init();
- return e;
+ Element[] ein = new Element[mCount];
+ String[] sin = new String[mCount];
+ java.lang.System.arraycopy(mElements, 0, ein, 0, mCount);
+ java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
+ return new Element(mRS, ein, sin);
}
}
+ static void initPredefined(RenderScript rs) {
+ int a8 = rs.nElementCreate(DataType.UNSIGNED_8.mID,
+ DataKind.PIXEL_A.mID, true, 1);
+ int rgba4444 = rs.nElementCreate(DataType.UNSIGNED_4_4_4_4.mID,
+ DataKind.PIXEL_RGBA.mID, true, 4);
+ int rgba8888 = rs.nElementCreate(DataType.UNSIGNED_8.mID,
+ DataKind.PIXEL_RGBA.mID, true, 4);
+ int rgb565 = rs.nElementCreate(DataType.UNSIGNED_5_6_5.mID,
+ DataKind.PIXEL_RGB.mID, true, 3);
+ rs.nInitElements(a8, rgba4444, rgba8888, rgb565);
+ }
}
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index 101f030..84f6f2d 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -107,7 +107,7 @@ public class ProgramVertex extends Program {
mProjection = new Matrix();
mTexture = new Matrix();
- mAlloc = Allocation.createSized(rs, Element.USER_F32(rs), 48);
+ mAlloc = Allocation.createSized(rs, Element.createUser(rs, Element.DataType.FLOAT_32), 48);
mAlloc.subData1D(MODELVIEW_OFFSET, 16, mModel.mMat);
mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat);
mAlloc.subData1D(TEXTURE_OFFSET, 16, mTexture.mMat);
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 6574219..cc97a8f 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -89,9 +89,9 @@ public class RenderScript {
native void nObjDestroyOOB(int id);
native int nFileOpen(byte[] name);
- native void nElementBegin();
- native void nElementAdd(int kind, int type, boolean norm, int bits, String s);
- native int nElementCreate();
+
+ native int nElementCreate(int type, int kind, boolean norm, int vecSize);
+ native int nElementCreate2(int[] elements, String[] names);
native void nTypeBegin(int elementID);
native void nTypeAdd(int dim, int val);
@@ -198,14 +198,13 @@ public class RenderScript {
private Surface mSurface;
private MessageThread mMessageThread;
-
Element mElement_USER_U8;
Element mElement_USER_I8;
Element mElement_USER_U16;
Element mElement_USER_I16;
Element mElement_USER_U32;
Element mElement_USER_I32;
- Element mElement_USER_FLOAT;
+ Element mElement_USER_F32;
Element mElement_A_8;
Element mElement_RGB_565;
@@ -215,9 +214,12 @@ public class RenderScript {
Element mElement_RGBA_8888;
Element mElement_INDEX_16;
- Element mElement_XY_F32;
- Element mElement_XYZ_F32;
-
+ Element mElement_POSITION_2;
+ Element mElement_POSITION_3;
+ Element mElement_TEXTURE_2;
+ Element mElement_NORMAL_3;
+ Element mElement_COLOR_U8_4;
+ Element mElement_COLOR_F32_4;
///////////////////////////////////////////////////////////////////////////////////
//
@@ -303,9 +305,9 @@ public class RenderScript {
nDeviceSetConfig(mDev, 0, 1);
}
mContext = nContextCreate(mDev, 0, useDepth);
- Element.initPredefined(this);
mMessageThread = new MessageThread(this);
mMessageThread.start();
+ Element.initPredefined(this);
}
public void contextSetSurface(int w, int h, Surface sur) {
diff --git a/graphics/java/android/renderscript/SimpleMesh.java b/graphics/java/android/renderscript/SimpleMesh.java
index f45074e..8589a3e 100644
--- a/graphics/java/android/renderscript/SimpleMesh.java
+++ b/graphics/java/android/renderscript/SimpleMesh.java
@@ -313,28 +313,38 @@ public class SimpleMesh extends BaseObj {
public SimpleMesh create() {
Element.Builder b = new Element.Builder(mRS);
int floatCount = mVtxSize;
- if (mVtxSize == 2) {
- b.addFloatXY();
- } else {
- b.addFloatXYZ();
- }
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.POSITION,
+ mVtxSize), "position");
if ((mFlags & COLOR) != 0) {
floatCount += 4;
- b.addFloatRGBA();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.COLOR,
+ 4), "color");
}
if ((mFlags & TEXTURE_0) != 0) {
floatCount += 2;
- b.addFloatST();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.TEXTURE,
+ 2), "texture");
}
if ((mFlags & NORMAL) != 0) {
floatCount += 3;
- b.addFloatNorm();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.NORMAL,
+ 3), "normal");
}
mElement = b.create();
+ android.util.Log.e("rs", "sm create size=" + (mVtxCount / floatCount) + ", count=" + mVtxCount);
+
Builder smb = new Builder(mRS);
smb.addVertexType(mElement, mVtxCount / floatCount);
- smb.setIndexType(Element.INDEX_16(mRS), mIndexCount);
+ smb.setIndexType(Element.createIndex(mRS), mIndexCount);
smb.setPrimitive(Primitive.TRIANGLE);
SimpleMesh sm = smb.create();
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index ad4cf6b..8e59a31 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -122,16 +122,16 @@ public class Type extends BaseObj {
Field f = fields[ct];
Class fc = f.getType();
if(fc == int.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_32.mID;
arBits[ct] = 32;
} else if(fc == short.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_16.mID;
arBits[ct] = 16;
} else if(fc == byte.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_8.mID;
arBits[ct] = 8;
} else if(fc == float.class) {
- arTypes[ct] = Element.DataType.FLOAT.mID;
+ arTypes[ct] = Element.DataType.FLOAT_32.mID;
arBits[ct] = 32;
} else {
throw new IllegalArgumentException("Unkown field type");
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 6ae93a7..f4e752f 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -247,36 +247,39 @@ static void nContextDeinitToClient(JNIEnv *_env, jobject _this)
}
-static void
-nElementBegin(JNIEnv *_env, jobject _this)
+static jint
+nElementCreate(JNIEnv *_env, jobject _this, jint type, jint kind, jboolean norm, jint size)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nElementBegin, con(%p)", con);
- rsElementBegin(con);
+ LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
+ return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
}
-
-static void
-nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jboolean norm, jint bits, jstring name)
+static jint
+nElementCreate2(JNIEnv *_env, jobject _this, jintArray _ids, jobjectArray _names)
{
+ int fieldCount = _env->GetArrayLength(_ids);
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- const char* n = NULL;
- if (name) {
- n = _env->GetStringUTFChars(name, NULL);
+ LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
+
+ jint *ids = _env->GetIntArrayElements(_ids, NULL);
+ const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *));
+ size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t));
+
+ for (int ct=0; ct < fieldCount; ct++) {
+ jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
+ nameArray[ct] = _env->GetStringUTFChars(s, NULL);
+ sizeArray[ct] = _env->GetStringUTFLength(s);
}
- LOG_API("nElementAdd, con(%p), kind(%i), type(%i), norm(%i), bits(%i)", con, kind, type, norm, bits);
- rsElementAdd(con, (RsDataKind)kind, (RsDataType)type, norm != 0, (size_t)bits, n);
- if (n) {
- _env->ReleaseStringUTFChars(name, n);
+ jint id = (jint)rsElementCreate2(con, fieldCount, (RsElement *)ids, nameArray, sizeArray);
+ for (int ct=0; ct < fieldCount; ct++) {
+ jstring s = (jstring)_env->GetObjectArrayElement(_names, ct);
+ _env->ReleaseStringUTFChars(s, nameArray[ct]);
}
-}
-
-static jint
-nElementCreate(JNIEnv *_env, jobject _this)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nElementCreate, con(%p)", con);
- return (jint)rsElementCreate(con);
+ _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
+ free(nameArray);
+ free(sizeArray);
+ return (jint)id;
}
// -----------------------------------
@@ -395,26 +398,24 @@ nTypeSetupFields(JNIEnv *_env, jobject _this, jobject _type, jintArray _types, j
tfc[ct].bits = fBits[ct];
switch(fType[ct]) {
- case RS_TYPE_FLOAT:
+ case RS_TYPE_FLOAT_32:
tfc[ct].ptr = SF_LoadFloat;
tfc[ct].readPtr = SF_SaveFloat;
break;
- case RS_TYPE_UNSIGNED:
- case RS_TYPE_SIGNED:
- switch(tfc[ct].bits) {
- case 32:
- tfc[ct].ptr = SF_LoadInt;
- tfc[ct].readPtr = SF_SaveInt;
- break;
- case 16:
- tfc[ct].ptr = SF_LoadShort;
- tfc[ct].readPtr = SF_SaveShort;
- break;
- case 8:
- tfc[ct].ptr = SF_LoadByte;
- tfc[ct].readPtr = SF_SaveByte;
- break;
- }
+ case RS_TYPE_UNSIGNED_32:
+ case RS_TYPE_SIGNED_32:
+ tfc[ct].ptr = SF_LoadInt;
+ tfc[ct].readPtr = SF_SaveInt;
+ break;
+ case RS_TYPE_UNSIGNED_16:
+ case RS_TYPE_SIGNED_16:
+ tfc[ct].ptr = SF_LoadShort;
+ tfc[ct].readPtr = SF_SaveShort;
+ break;
+ case RS_TYPE_UNSIGNED_8:
+ case RS_TYPE_SIGNED_8:
+ tfc[ct].ptr = SF_LoadByte;
+ tfc[ct].readPtr = SF_SaveByte;
break;
}
tc->size += 4;
@@ -1367,9 +1368,8 @@ static JNINativeMethod methods[] = {
{"nFileOpen", "([B)I", (void*)nFileOpen },
-{"nElementBegin", "()V", (void*)nElementBegin },
-{"nElementAdd", "(IIZILjava/lang/String;)V", (void*)nElementAdd },
-{"nElementCreate", "()I", (void*)nElementCreate },
+{"nElementCreate", "(IIZI)I", (void*)nElementCreate },
+{"nElementCreate2", "([I[Ljava/lang/String;)I", (void*)nElementCreate2 },
{"nTypeBegin", "(I)V", (void*)nTypeBegin },
{"nTypeAdd", "(II)V", (void*)nTypeAdd },
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 111bdd4..3080ab0 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -76,6 +76,7 @@ ifneq ($(TARGET_SIMULATOR),true)
LOCAL_SRC_FILES:= \
rsAdapter.cpp \
rsAllocation.cpp \
+ rsComponent.cpp \
rsContext.cpp \
rsDevice.cpp \
rsElement.cpp \
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index d10eeda..bb2c06a 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -66,32 +66,50 @@ void rsContextDeinitToClient(RsContext);
#define RS_MAX_TEXTURE 2
enum RsDataType {
- RS_TYPE_FLOAT,
- RS_TYPE_UNSIGNED,
- RS_TYPE_SIGNED
+ RS_TYPE_NONE,
+ RS_TYPE_FLOAT_16,
+ RS_TYPE_FLOAT_32,
+ RS_TYPE_FLOAT_64,
+ RS_TYPE_SIGNED_8,
+ RS_TYPE_SIGNED_16,
+ RS_TYPE_SIGNED_32,
+ RS_TYPE_SIGNED_64,
+ RS_TYPE_UNSIGNED_8,
+ RS_TYPE_UNSIGNED_16,
+ RS_TYPE_UNSIGNED_32,
+ RS_TYPE_UNSIGNED_64,
+
+ RS_TYPE_UNSIGNED_5_6_5,
+ RS_TYPE_UNSIGNED_5_5_5_1,
+ RS_TYPE_UNSIGNED_4_4_4_4,
+
+ RS_TYPE_ELEMENT,
+ RS_TYPE_TYPE,
+ RS_TYPE_ALLOCATION,
+ RS_TYPE_SAMPLER,
+ RS_TYPE_SCRIPT,
+ RS_TYPE_MESH,
+ RS_TYPE_PROGRAM_FRAGMENT,
+ RS_TYPE_PROGRAM_VERTEX,
+ RS_TYPE_PROGRAM_RASTER,
+ RS_TYPE_PROGRAM_STORE
};
enum RsDataKind {
RS_KIND_USER,
- RS_KIND_RED,
- RS_KIND_GREEN,
- RS_KIND_BLUE,
- RS_KIND_ALPHA,
- RS_KIND_LUMINANCE,
- RS_KIND_INTENSITY,
- RS_KIND_X,
- RS_KIND_Y,
- RS_KIND_Z,
- RS_KIND_W,
- RS_KIND_S,
- RS_KIND_T,
- RS_KIND_Q,
- RS_KIND_R,
- RS_KIND_NX,
- RS_KIND_NY,
- RS_KIND_NZ,
+ RS_KIND_COLOR,
+ RS_KIND_POSITION,
+ RS_KIND_TEXTURE,
+ RS_KIND_NORMAL,
RS_KIND_INDEX,
- RS_KIND_POINT_SIZE
+ RS_KIND_POINT_SIZE,
+
+ RS_KIND_PIXEL_L,
+ RS_KIND_PIXEL_A,
+ RS_KIND_PIXEL_LA,
+ RS_KIND_PIXEL_RGB,
+ RS_KIND_PIXEL_RGBA,
+
};
enum RsSamplerParam {
diff --git a/libs/rs/java/Film/src/com/android/film/FilmRS.java b/libs/rs/java/Film/src/com/android/film/FilmRS.java
index dccc1d2..fcf487c 100644
--- a/libs/rs/java/Film/src/com/android/film/FilmRS.java
+++ b/libs/rs/java/Film/src/com/android/film/FilmRS.java
@@ -152,10 +152,13 @@ public class FilmRS {
mBufferIDs = new int[13];
mImages = new Allocation[13];
mAllocIDs = Allocation.createSized(mRS,
- Element.USER_F32(mRS), mBufferIDs.length);
+ Element.createUser(mRS, Element.DataType.FLOAT_32),
+ mBufferIDs.length);
- Element ie = Element.RGB_565(mRS);
+ Element ie = Element.createPixel(mRS, Element.DataType.UNSIGNED_5_6_5, Element.DataKind.PIXEL_RGB);
+ android.util.Log.e("rs", "load 1");
mImages[0] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p01, ie, true);
+ android.util.Log.e("rs", "load 2");
mImages[1] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p02, ie, true);
mImages[2] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p03, ie, true);
mImages[3] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p04, ie, true);
@@ -195,7 +198,8 @@ public class FilmRS {
{
mBufferState = new int[10];
mAllocState = Allocation.createSized(mRS,
- Element.USER_F32(mRS), mBufferState.length);
+ Element.createUser(mRS, Element.DataType.FLOAT_32),
+ mBufferState.length);
mBufferState[STATE_LAST_FOCUS] = -1;
mAllocState.data(mBufferState);
}
@@ -238,12 +242,12 @@ public class FilmRS {
mAllocOffsets = Allocation.createSized(mRS,
- Element.USER_I32(mRS), mFSM.mTriangleOffsets.length);
+ Element.createUser(mRS, Element.DataType.SIGNED_32), mFSM.mTriangleOffsets.length);
mAllocOffsets.data(mFSM.mTriangleOffsets);
mScriptStrip.bindAllocation(mAllocOffsets, 4);
mAllocOffsetsTex = Allocation.createSized(mRS,
- Element.USER_F32(mRS), mFSM.mTriangleOffsetsTex.length);
+ Element.createUser(mRS, Element.DataType.FLOAT_32), mFSM.mTriangleOffsetsTex.length);
mAllocOffsetsTex.data(mFSM.mTriangleOffsetsTex);
mScriptStrip.bindAllocation(mAllocOffsetsTex, 5);
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index f218f9b..73b819b 100644
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ b/libs/rs/java/Fountain/res/raw/fountain.c
@@ -14,19 +14,17 @@ int main(int launchID) {
float rMax = ((float)rate) * 0.005f;
int x = Control->x;
int y = Control->y;
- char r = Control->r * 255.f;
- char g = Control->g * 255.f;
- char b = Control->b * 255.f;
+ int color = ((int)(Control->r * 255.f)) |
+ ((int)(Control->g * 255.f)) << 8 |
+ ((int)(Control->b * 255.f)) << 16 |
+ (0xf0 << 24);
struct point_s * np = &p[newPart];
while (rate--) {
- vec2Rand((float *)np, rMax);
- np->x = x;
- np->y = y;
- np->r = r;
- np->g = g;
- np->b = b;
- np->a = 0xf0;
+ vec2Rand((float *)&np->delta.x, rMax);
+ np->position.x = x;
+ np->position.y = y;
+ np->color = color;
newPart++;
np++;
if (newPart >= count) {
@@ -37,14 +35,14 @@ int main(int launchID) {
}
for (ct=0; ct < count; ct++) {
- float dy = p->dy + 0.15f;
- float posy = p->y + dy;
+ float dy = p->delta.y + 0.15f;
+ float posy = p->position.y + dy;
if ((posy > height) && (dy > 0)) {
dy *= -0.3f;
}
- p->dy = dy;
- p->x += p->dx;
- p->y = posy;
+ p->delta.y = dy;
+ p->position.x += p->delta.x;
+ p->position.y = posy;
p++;
}
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
index f4f9b0c..71f95a7 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -79,10 +79,9 @@ public class FountainRS {
mIntAlloc.data(mSD);
Element.Builder eb = new Element.Builder(mRS);
- eb.addFloat(Element.DataKind.USER, "dx");
- eb.addFloat(Element.DataKind.USER, "dy");
- eb.addFloatXY("");
- eb.addUNorm8RGBA("");
+ eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 2), "delta");
+ eb.add(Element.createAttrib(mRS, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "position");
+ eb.add(Element.createAttrib(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.COLOR, 4), "color");
Element primElement = eb.create();
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
index 334fd9c..0ca00b3 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -62,7 +62,7 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
public float threshold;
}
-
+
static class Pixel {
public byte a;
public byte r;
@@ -78,7 +78,7 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
mParams.outWidth, mParams.outHeight);
mDisplayView.invalidate();
}
- };
+ };
@Override
public void run() {
@@ -131,7 +131,7 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
public void surfaceDestroyed(SurfaceHolder holder) {
}
-
+
private Script.Invokable createScript() {
mRS = new RenderScript(false, false);
mRS.mMessageCallback = new FilterCallback();
@@ -143,9 +143,11 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
final int pixelCount = mParams.inWidth * mParams.inHeight;
mPixelType = Type.createFromClass(mRS, Pixel.class, 1, "Pixel");
- mInPixelsAllocation = Allocation.createSized(mRS, Element.USER_I32(mRS),
+ mInPixelsAllocation = Allocation.createSized(mRS,
+ Element.createUser(mRS, Element.DataType.SIGNED_32),
pixelCount);
- mOutPixelsAllocation = Allocation.createSized(mRS, Element.USER_I32(mRS),
+ mOutPixelsAllocation = Allocation.createSized(mRS,
+ Element.createUser(mRS, Element.DataType.SIGNED_32),
pixelCount);
final int[] data = new int[pixelCount];
@@ -154,7 +156,7 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
mOutData = new int[pixelCount];
mOutPixelsAllocation.data(mOutData);
-
+
ScriptC.Builder sb = new ScriptC.Builder(mRS);
sb.setType(mParamsType, "Params", 0);
sb.setType(mPixelType, "InPixel", 1);
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index df415685..d12431f 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -60,18 +60,19 @@ ObjDestroy {
param void *obj
}
-ElementBegin {
-}
-
-ElementAdd {
- param RsDataKind dataKind
- param RsDataType dataType
- param bool isNormalized
- param size_t bits
- param const char * name
+ElementCreate {
+ param RsDataType mType
+ param RsDataKind mKind
+ param bool mNormalized
+ param uint32_t mVectorSize
+ ret RsElement
}
-ElementCreate {
+ElementCreate2 {
+ param size_t count
+ param const RsElement * elements
+ param const char ** names
+ param const size_t * nameLengths
ret RsElement
}
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 7f76390..19699dc 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -106,8 +106,8 @@ void Allocation::uploadToTexture(const Context *rsc)
return;
}
- GLenum type = mType->getElement()->getGLType();
- GLenum format = mType->getElement()->getGLFormat();
+ GLenum type = mType->getElement()->getComponent().getGLType();
+ GLenum format = mType->getElement()->getComponent().getGLFormat();
if (!type || !format) {
return;
@@ -422,10 +422,10 @@ static void elementConverter_8888_to_565(void *dst, const void *src, uint32_t co
static ElementConverter_t pickConverter(const Element *dst, const Element *src)
{
- GLenum srcGLType = src->getGLType();
- GLenum srcGLFmt = src->getGLFormat();
- GLenum dstGLType = dst->getGLType();
- GLenum dstGLFmt = dst->getGLFormat();
+ GLenum srcGLType = src->getComponent().getGLType();
+ GLenum srcGLFmt = src->getComponent().getGLFormat();
+ GLenum dstGLType = dst->getComponent().getGLType();
+ GLenum dstGLFmt = dst->getComponent().getGLFormat();
if (srcGLFmt == dstGLFmt && srcGLType == dstGLType) {
switch(dst->getSizeBytes()) {
diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp
new file mode 100644
index 0000000..0574343
--- /dev/null
+++ b/libs/rs/rsComponent.cpp
@@ -0,0 +1,316 @@
+/*
+ * 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.
+ */
+
+#include "rsComponent.h"
+
+#include <GLES/gl.h>
+
+using namespace android;
+using namespace android::renderscript;
+
+Component::Component()
+{
+ set(RS_TYPE_NONE, RS_KIND_USER, false, 1);
+}
+
+Component::~Component()
+{
+}
+
+void Component::set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize)
+{
+ mType = dt;
+ mKind = dk;
+ mNormalized = norm;
+ mVectorSize = vecSize;
+ rsAssert(vecSize <= 4);
+
+ mBits = 0;
+ mTypeBits = 0;
+ mIsFloat = false;
+ mIsSigned = false;
+ mIsPixel = false;
+
+ switch(mKind) {
+ case RS_KIND_PIXEL_L:
+ case RS_KIND_PIXEL_A:
+ mIsPixel = true;
+ rsAssert(mVectorSize == 1);
+ rsAssert(mNormalized == true);
+ break;
+ case RS_KIND_PIXEL_LA:
+ mIsPixel = true;
+ rsAssert(mVectorSize == 2);
+ rsAssert(mNormalized == true);
+ break;
+ case RS_KIND_PIXEL_RGB:
+ mIsPixel = true;
+ rsAssert(mVectorSize == 3);
+ rsAssert(mNormalized == true);
+ break;
+ case RS_KIND_PIXEL_RGBA:
+ mIsPixel = true;
+ rsAssert(mVectorSize == 4);
+ rsAssert(mNormalized == true);
+ break;
+ default:
+ break;
+ }
+
+ switch(mType) {
+ case RS_TYPE_NONE:
+ return;
+ case RS_TYPE_UNSIGNED_5_6_5:
+ mVectorSize = 3;
+ mBits = 16;
+ mNormalized = true;
+ rsAssert(mKind == RS_KIND_PIXEL_RGB);
+ return;
+ case RS_TYPE_UNSIGNED_5_5_5_1:
+ mVectorSize = 4;
+ mBits = 16;
+ mNormalized = true;
+ rsAssert(mKind == RS_KIND_PIXEL_RGBA);
+ return;
+ case RS_TYPE_UNSIGNED_4_4_4_4:
+ mVectorSize = 4;
+ mBits = 16;
+ mNormalized = true;
+ rsAssert(mKind == RS_KIND_PIXEL_RGBA);
+ return;
+ case RS_TYPE_ELEMENT:
+ case RS_TYPE_TYPE:
+ case RS_TYPE_ALLOCATION:
+ case RS_TYPE_SAMPLER:
+ case RS_TYPE_SCRIPT:
+ case RS_TYPE_MESH:
+ case RS_TYPE_PROGRAM_FRAGMENT:
+ case RS_TYPE_PROGRAM_VERTEX:
+ case RS_TYPE_PROGRAM_RASTER:
+ case RS_TYPE_PROGRAM_STORE:
+ rsAssert(mVectorSize == 1);
+ rsAssert(mNormalized == false);
+ rsAssert(mKind == RS_KIND_USER);
+ mBits = 32;
+ mTypeBits = 32;
+ return;
+
+ case RS_TYPE_FLOAT_16:
+ mTypeBits = 16;
+ mIsFloat = true;
+ break;
+ case RS_TYPE_FLOAT_32:
+ mTypeBits = 32;
+ mIsFloat = true;
+ break;
+ case RS_TYPE_FLOAT_64:
+ mTypeBits = 64;
+ mIsFloat = true;
+ break;
+ case RS_TYPE_SIGNED_8:
+ mTypeBits = 8;
+ mIsSigned = true;
+ break;
+ case RS_TYPE_SIGNED_16:
+ mTypeBits = 16;
+ mIsSigned = true;
+ break;
+ case RS_TYPE_SIGNED_32:
+ mTypeBits = 32;
+ mIsSigned = true;
+ break;
+ case RS_TYPE_SIGNED_64:
+ mTypeBits = 64;
+ mIsSigned = true;
+ break;
+ case RS_TYPE_UNSIGNED_8:
+ mTypeBits = 8;
+ break;
+ case RS_TYPE_UNSIGNED_16:
+ mTypeBits = 16;
+ break;
+ case RS_TYPE_UNSIGNED_32:
+ mTypeBits = 32;
+ break;
+ case RS_TYPE_UNSIGNED_64:
+ mTypeBits = 64;
+ break;
+ }
+
+ mBits = mTypeBits * mVectorSize;
+}
+
+
+
+
+uint32_t Component::getGLType() const
+{
+ switch (mType) {
+ case RS_TYPE_UNSIGNED_5_6_5: return GL_UNSIGNED_SHORT_5_6_5;
+ case RS_TYPE_UNSIGNED_5_5_5_1: return GL_UNSIGNED_SHORT_5_5_5_1;
+ case RS_TYPE_UNSIGNED_4_4_4_4: return GL_UNSIGNED_SHORT_4_4_4_4;
+
+ //case RS_TYPE_FLOAT_16: return GL_HALF_FLOAT;
+ case RS_TYPE_FLOAT_32: return GL_FLOAT;
+ case RS_TYPE_UNSIGNED_8: return GL_UNSIGNED_BYTE;
+ case RS_TYPE_UNSIGNED_16: return GL_UNSIGNED_SHORT;
+ case RS_TYPE_SIGNED_8: return GL_BYTE;
+ case RS_TYPE_SIGNED_16: return GL_SHORT;
+ default: break;
+ }
+
+ return 0;
+}
+
+uint32_t Component::getGLFormat() const
+{
+ switch (mKind) {
+ case RS_KIND_PIXEL_L: return GL_LUMINANCE;
+ case RS_KIND_PIXEL_A: return GL_ALPHA;
+ case RS_KIND_PIXEL_LA: return GL_LUMINANCE_ALPHA;
+ case RS_KIND_PIXEL_RGB: return GL_RGB;
+ case RS_KIND_PIXEL_RGBA: return GL_RGBA;
+ default: break;
+ }
+ return 0;
+}
+
+static const char * gCTypeStrings[] = {
+ 0,
+ 0,//"F16",
+ "float",
+ "double",
+ "char",
+ "short",
+ "int",
+ 0,//"S64",
+ "char",//U8",
+ "short",//U16",
+ "int",//U32",
+ 0,//"U64",
+ 0,//"UP_565",
+ 0,//"UP_5551",
+ 0,//"UP_4444",
+ 0,//"ELEMENT",
+ 0,//"TYPE",
+ 0,//"ALLOCATION",
+ 0,//"SAMPLER",
+ 0,//"SCRIPT",
+ 0,//"MESH",
+ 0,//"PROGRAM_FRAGMENT",
+ 0,//"PROGRAM_VERTEX",
+ 0,//"PROGRAM_RASTER",
+ 0,//"PROGRAM_STORE",
+};
+
+static const char * gCVecTypeStrings[] = {
+ 0,
+ 0,//"F16",
+ "vecF32",
+ "vecF64",
+ "vecI8",
+ "vecI16",
+ "vecI32",
+ 0,//"S64",
+ "vecU8",//U8",
+ "vecU16",//U16",
+ "vecU32",//U32",
+ 0,//"U64",
+ 0,//"UP_565",
+ 0,//"UP_5551",
+ 0,//"UP_4444",
+ 0,//"ELEMENT",
+ 0,//"TYPE",
+ 0,//"ALLOCATION",
+ 0,//"SAMPLER",
+ 0,//"SCRIPT",
+ 0,//"MESH",
+ 0,//"PROGRAM_FRAGMENT",
+ 0,//"PROGRAM_VERTEX",
+ 0,//"PROGRAM_RASTER",
+ 0,//"PROGRAM_STORE",
+};
+
+String8 Component::getCType() const
+{
+ char buf[64];
+ if (mVectorSize == 1) {
+ return String8(gCTypeStrings[mType]);
+ }
+
+ // Yuck, acc WAR
+ // Appears to have problems packing chars
+ if (mVectorSize == 4 && mType == RS_TYPE_UNSIGNED_8) {
+ return String8("int");
+ }
+
+
+ String8 s(gCVecTypeStrings[mType]);
+ sprintf(buf, "_%i_t", mVectorSize);
+ s.append(buf);
+ return s;
+}
+
+static const char * gTypeStrings[] = {
+ "NONE",
+ "F16",
+ "F32",
+ "F64",
+ "S8",
+ "S16",
+ "S32",
+ "S64",
+ "U8",
+ "U16",
+ "U32",
+ "U64",
+ "UP_565",
+ "UP_5551",
+ "UP_4444",
+ "ELEMENT",
+ "TYPE",
+ "ALLOCATION",
+ "SAMPLER",
+ "SCRIPT",
+ "MESH",
+ "PROGRAM_FRAGMENT",
+ "PROGRAM_VERTEX",
+ "PROGRAM_RASTER",
+ "PROGRAM_STORE",
+};
+
+static const char * gKindStrings[] = {
+ "USER",
+ "COLOR",
+ "POSITION",
+ "TEXTURE",
+ "NORMAL",
+ "INDEX",
+ "POINT_SIZE",
+ "PIXEL_L",
+ "PIXEL_A",
+ "PIXEL_LA",
+ "PIXEL_RGB",
+ "PIXEL_RGBA",
+};
+
+void Component::dumpLOGV(const char *prefix) const
+{
+ LOGV("%s Component: %s, %s, vectorSize=%i, bits=%i",
+ prefix, gTypeStrings[mType], gKindStrings[mKind], mVectorSize, mBits);
+}
+
+
diff --git a/libs/rs/rsComponent.h b/libs/rs/rsComponent.h
new file mode 100644
index 0000000..c122c8e
--- /dev/null
+++ b/libs/rs/rsComponent.h
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+#ifndef ANDROID_COMPONENT_H
+#define ANDROID_COMPONENT_H
+
+#include "rsUtils.h"
+
+// ---------------------------------------------------------------------------
+namespace android {
+namespace renderscript {
+
+
+// An element is a group of Components that occupies one cell in a structure.
+class Component
+{
+public:
+ Component();
+ ~Component();
+
+ void set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize=1);
+
+ uint32_t getGLType() const;
+ uint32_t getGLFormat() const;
+ String8 getCType() const;
+ void dumpLOGV(const char *prefix) const;
+
+
+ RsDataType getType() const {return mType;}
+ RsDataKind getKind() const {return mKind;}
+ bool getIsNormalized() const {return mNormalized;}
+ uint32_t getVectorSize() const {return mVectorSize;}
+ bool getIsFloat() const {return mIsFloat;}
+ bool getIsSigned() const {return mIsSigned;}
+ uint32_t getBits() const {return mBits;}
+
+protected:
+ RsDataType mType;
+ RsDataKind mKind;
+ bool mNormalized;
+ uint32_t mVectorSize;
+
+ // derived
+ uint32_t mBits;
+ uint32_t mTypeBits;
+ bool mIsFloat;
+ bool mIsSigned;
+ bool mIsPixel;
+};
+
+}
+}
+
+#endif
+
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 8f56efa..11f26b9 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -142,6 +142,13 @@ uint32_t Context::runScript(Script *s, uint32_t launchID)
return ret;
}
+void Context::checkError(const char *msg) const
+{
+ GLenum err = glGetError();
+ if (err != GL_NO_ERROR) {
+ LOGE("GL Error, 0x%x, from %s", err, msg);
+ }
+}
uint32_t Context::runRootScript()
{
@@ -169,11 +176,7 @@ uint32_t Context::runRootScript()
mStateFragmentStore.mLast.clear();
uint32_t ret = runScript(mRootScript.get(), 0);
- GLenum err = glGetError();
- if (err != GL_NO_ERROR) {
- LOGE("Pending GL Error, 0x%x", err);
- }
-
+ checkError("runRootScript");
return ret;
}
@@ -340,10 +343,6 @@ void * Context::threadProc(void *vrsc)
rsc->mObjDestroy.mNeedToEmpty = true;
rsc->objDestroyOOBRun();
- glClearColor(0,0,0,0);
- glClear(GL_COLOR_BUFFER_BIT);
- eglSwapBuffers(rsc->mEGL.mDisplay, rsc->mEGL.mSurface);
-
pthread_mutex_lock(&gInitMutex);
rsc->deinitEGL();
pthread_mutex_unlock(&gInitMutex);
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index dd0423e..aa7436d 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -168,6 +168,7 @@ public:
} props;
void dumpDebug() const;
+ void checkError(const char *) const;
mutable const ObjectBase * mObjHead;
diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp
index e796556..79ff35a 100644
--- a/libs/rs/rsElement.cpp
+++ b/libs/rs/rsElement.cpp
@@ -24,9 +24,6 @@ using namespace android::renderscript;
Element::Element(Context *rsc) : ObjectBase(rsc)
{
- mType = RS_TYPE_FLOAT;
- mIsNormalized = false;
- mKind = RS_KIND_USER;
mBits = 0;
mAllocFile = __FILE__;
mAllocLine = __LINE__;
@@ -80,161 +77,6 @@ size_t Element::getFieldOffsetBits(uint32_t componentNumber) const
return offset;
}
-uint32_t Element::getGLType() const
-{
- int bits[4];
-
- if (!mFieldCount) {
- switch (mType) {
- case RS_TYPE_FLOAT:
- if (mBits == 32) {
- return GL_FLOAT;
- }
- return 0;
- case RS_TYPE_SIGNED:
- switch (mBits) {
- case 8:
- return GL_BYTE;
- case 16:
- return GL_SHORT;
- //case 32:
- //return GL_INT;
- }
- return 0;
- case RS_TYPE_UNSIGNED:
- switch (mBits) {
- case 8:
- return GL_UNSIGNED_BYTE;
- case 16:
- return GL_UNSIGNED_SHORT;
- //case 32:
- //return GL_UNSIGNED_INT;
- }
- return 0;
- }
- }
-
- if (mFieldCount > 4) {
- return 0;
- }
-
- for (uint32_t ct=0; ct < mFieldCount; ct++) {
- bits[ct] = mFields[ct].e->mBits;
- if (mFields[ct].e->mFieldCount) {
- return 0;
- }
- if (mFields[ct].e->mType != RS_TYPE_UNSIGNED) {
- return 0;
- }
- if (!mFields[ct].e->mIsNormalized) {
- return 0;
- }
- }
-
- switch(mFieldCount) {
- case 1:
- if (bits[0] == 8) {
- return GL_UNSIGNED_BYTE;
- }
- return 0;
- case 2:
- if ((bits[0] == 8) &&
- (bits[1] == 8)) {
- return GL_UNSIGNED_BYTE;
- }
- return 0;
- case 3:
- if ((bits[0] == 8) &&
- (bits[1] == 8) &&
- (bits[2] == 8)) {
- return GL_UNSIGNED_BYTE;
- }
- if ((bits[0] == 5) &&
- (bits[1] == 6) &&
- (bits[2] == 5)) {
- return GL_UNSIGNED_SHORT_5_6_5;
- }
- return 0;
- case 4:
- if ((bits[0] == 8) &&
- (bits[1] == 8) &&
- (bits[2] == 8) &&
- (bits[3] == 8)) {
- return GL_UNSIGNED_BYTE;
- }
- if ((bits[0] == 4) &&
- (bits[1] == 4) &&
- (bits[2] == 4) &&
- (bits[3] == 4)) {
- return GL_UNSIGNED_SHORT_4_4_4_4;
- }
- if ((bits[0] == 5) &&
- (bits[1] == 5) &&
- (bits[2] == 5) &&
- (bits[3] == 1)) {
- return GL_UNSIGNED_SHORT_5_5_5_1;
- }
- }
- return 0;
-}
-
-uint32_t Element::getGLFormat() const
-{
- if (!mFieldCount) {
- if (mKind == RS_KIND_ALPHA) {
- return GL_ALPHA;
- }
- if (mKind == RS_KIND_LUMINANCE) {
- return GL_LUMINANCE;
- }
- }
-
- switch(mFieldCount) {
- case 2:
- if ((mFields[0].e->mKind == RS_KIND_LUMINANCE) &&
- (mFields[1].e->mKind == RS_KIND_ALPHA)) {
- return GL_LUMINANCE_ALPHA;
- }
- break;
- case 3:
- if ((mFields[0].e->mKind == RS_KIND_RED) &&
- (mFields[1].e->mKind == RS_KIND_GREEN) &&
- (mFields[2].e->mKind == RS_KIND_BLUE)) {
- return GL_RGB;
- }
- break;
- case 4:
- if ((mFields[0].e->mKind == RS_KIND_RED) &&
- (mFields[1].e->mKind == RS_KIND_GREEN) &&
- (mFields[2].e->mKind == RS_KIND_BLUE) &&
- (mFields[3].e->mKind == RS_KIND_ALPHA)) {
- return GL_RGBA;
- }
- break;
- }
- return 0;
-}
-
-const char * Element::getCType() const
-{
- switch(mType) {
- case RS_TYPE_FLOAT:
- return "float";
- case RS_TYPE_SIGNED:
- case RS_TYPE_UNSIGNED:
- switch(mBits) {
- case 32:
- return "int";
- case 16:
- return "short";
- case 8:
- return "char";
- }
- break;
- }
- return NULL;
-}
-
void Element::dumpLOGV(const char *prefix) const
{
ObjectBase::dumpLOGV(prefix);
@@ -246,19 +88,18 @@ void Element::dumpLOGV(const char *prefix) const
}
}
-Element * Element::create(Context *rsc, RsDataKind dk, RsDataType dt,
- bool isNorm, size_t bits)
+
+Element * Element::create(Context *rsc, RsDataType dt, RsDataKind dk,
+ bool isNorm, uint32_t vecSize)
{
Element *e = new Element(rsc);
- e->mKind = dk;
- e->mType = dt;
- e->mIsNormalized = isNorm;
- e->mBits = bits;
+ e->mComponent.set(dt, dk, isNorm, vecSize);
+ e->mBits = e->mComponent.getBits();
return e;
}
-Element * Element::create(Context *rsc, Element **ein, const char **nin,
- const size_t * lengths, size_t count)
+Element * Element::create(Context *rsc, size_t count, const Element **ein,
+ const char **nin, const size_t * lengths)
{
Element *e = new Element(rsc);
e->mFields = new ElementField_t [count];
@@ -267,11 +108,53 @@ Element * Element::create(Context *rsc, Element **ein, const char **nin,
for (size_t ct=0; ct < count; ct++) {
e->mFields[ct].e.set(ein[ct]);
e->mFields[ct].name.setTo(nin[ct], lengths[ct]);
+ LOGE("element %p %s", ein[ct], e->mFields[ct].name.string());
}
return e;
}
+String8 Element::getCStructBody(uint32_t indent) const
+{
+ String8 si;
+ for (uint32_t ct=0; ct < indent; ct++) {
+ si.append(" ");
+ }
+
+ String8 s(si);
+ s.append("{\n");
+ for (uint32_t ct = 0; ct < mFieldCount; ct++) {
+ s.append(si);
+ s.append(mFields[ct].e->getCType(indent+4));
+ s.append(" ");
+ s.append(mFields[ct].name);
+ s.append(";\n");
+ }
+ s.append(si);
+ s.append("}");
+ return s;
+}
+
+String8 Element::getCType(uint32_t indent) const
+{
+ String8 s;
+ for (uint32_t ct=0; ct < indent; ct++) {
+ s.append(" ");
+ }
+
+ if (!mFieldCount) {
+ // Basic component.
+ s.append(mComponent.getCType());
+ } else {
+ s.append("struct ");
+ s.append(getCStructBody(indent));
+ }
+
+ return s;
+}
+
+
+
ElementState::ElementState()
{
@@ -288,14 +171,31 @@ ElementState::~ElementState()
namespace android {
namespace renderscript {
-void rsi_ElementBegin(Context *rsc)
+RsElement rsi_ElementCreate(Context *rsc,
+ RsDataType dt,
+ RsDataKind dk,
+ bool norm,
+ uint32_t vecSize)
{
- ElementState * sec = &rsc->mStateElement;
+ //LOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize);
+ Element *e = Element::create(rsc, dt, dk, norm, vecSize);
+ e->incUserRef();
+ return e;
+}
- sec->mBuildList.clear();
- sec->mNames.clear();
+RsElement rsi_ElementCreate2(Context *rsc,
+ size_t count,
+ const RsElement * ein,
+ const char ** names,
+ const size_t * nameLengths)
+{
+ //LOGE("rsi_ElementCreate2 %i", count);
+ Element *e = Element::create(rsc, count, (const Element **)ein, names, nameLengths);
+ e->incUserRef();
+ return e;
}
+/*
void rsi_ElementAdd(Context *rsc, RsDataKind dk, RsDataType dt, bool isNormalized, size_t bits, const char *name)
{
ElementState * sec = &rsc->mStateElement;
@@ -345,6 +245,7 @@ RsElement rsi_ElementCreate(Context *rsc)
free(tmpLengths);
return se;
}
+*/
}
diff --git a/libs/rs/rsElement.h b/libs/rs/rsElement.h
index 43e2820..c46922c 100644
--- a/libs/rs/rsElement.h
+++ b/libs/rs/rsElement.h
@@ -17,7 +17,7 @@
#ifndef ANDROID_STRUCTURED_ELEMENT_H
#define ANDROID_STRUCTURED_ELEMENT_H
-//#include "rsComponent.h"
+#include "rsComponent.h"
#include "rsUtils.h"
#include "rsObjectBase.h"
@@ -53,20 +53,22 @@ public:
const Element * getField(uint32_t idx) const {return mFields[idx].e.get();}
const char * getFieldName(uint32_t idx) const {return mFields[idx].name.string();}
- RsDataType getType() const {return mType;}
- bool getIsNormalized() const {return mIsNormalized;}
- RsDataKind getKind() const {return mKind;}
+ const Component & getComponent() const {return mComponent;}
+ RsDataType getType() const {return mComponent.getType();}
+ //bool getIsNormalized() const {return mIsNormalized;}
+ RsDataKind getKind() const {return mComponent.getKind();}
uint32_t getBits() const {return mBits;}
//uint32_t getGLType() const;
- const char * getCType() const;
- void dumpLOGV(const char *prefix) const;
+ String8 getCType(uint32_t indent=0) const;
+ String8 getCStructBody(uint32_t indent=0) const;
+ void dumpLOGV(const char *prefix) const;
- static Element * create(Context *rsc, RsDataKind dk, RsDataType dt,
- bool isNorm, size_t bits);
- static Element * create(Context *rsc, Element **, const char **,
- const size_t * lengths, size_t count);
+ static Element * create(Context *rsc, RsDataType dt, RsDataKind dk,
+ bool isNorm, uint32_t vecSize);
+ static Element * create(Context *rsc, size_t count, const Element **,
+ const char **, const size_t * lengths);
protected:
// deallocate any components that are part of this element.
@@ -74,7 +76,7 @@ protected:
typedef struct {
String8 name;
- ObjectBaseRef<Element> e;
+ ObjectBaseRef<const Element> e;
} ElementField_t;
ElementField_t *mFields;
size_t mFieldCount;
@@ -82,12 +84,8 @@ protected:
Element(Context *);
-
- RsDataType mType;
- bool mIsNormalized;
- RsDataKind mKind;
+ Component mComponent;
uint32_t mBits;
- //String8 mName;
};
diff --git a/libs/rs/rsFileA3D.cpp b/libs/rs/rsFileA3D.cpp
index c566665..e3272c5 100644
--- a/libs/rs/rsFileA3D.cpp
+++ b/libs/rs/rsFileA3D.cpp
@@ -324,6 +324,7 @@ void FileA3D::processChunk_Verticies(Context *rsc, IO *io, A3DIndexEntry *ie)
void FileA3D::processChunk_Element(Context *rsc, IO *io, A3DIndexEntry *ie)
{
+ /*
rsi_ElementBegin(rsc);
uint32_t count = io->loadU32();
@@ -338,6 +339,7 @@ void FileA3D::processChunk_Element(Context *rsc, IO *io, A3DIndexEntry *ie)
}
LOGE("processChunk_Element create");
ie->mRsObj = rsi_ElementCreate(rsc);
+ */
}
void FileA3D::processChunk_ElementSource(Context *rsc, IO *io, A3DIndexEntry *ie)
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index 05672e5..f7394a6 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -213,9 +213,9 @@ void ProgramFragment::createShader()
if (mTextureEnableMask) {
if (mPointSpriteEnable) {
- mShader.append(" vec2 tex0 = gl_PointCoord;\n");
+ mShader.append(" vec2 t0 = gl_PointCoord;\n");
} else {
- mShader.append(" vec2 tex0 = varTex0.xy;\n");
+ mShader.append(" vec2 t0 = varTex0.xy;\n");
}
}
@@ -228,13 +228,39 @@ void ProgramFragment::createShader()
rsAssert(0);
break;
case RS_TEX_ENV_MODE_REPLACE:
- mShader.append(" col = texture2D(uni_Tex0, tex0);\n");
+ switch(mTextureFormats[texNum]) {
+ case 1:
+ mShader.append(" col.a = texture2D(uni_Tex0, t0).a;\n");
+ break;
+ case 2:
+ mShader.append(" col.rgba = texture2D(uni_Tex0, t0).rgba;\n");
+ break;
+ case 3:
+ mShader.append(" col.rgb = texture2D(uni_Tex0, t0).rgb;\n");
+ break;
+ case 4:
+ mShader.append(" col.rgba = texture2D(uni_Tex0, t0).rgba;\n");
+ break;
+ }
break;
case RS_TEX_ENV_MODE_MODULATE:
- mShader.append(" col *= texture2D(uni_Tex0, tex0);\n");
+ switch(mTextureFormats[texNum]) {
+ case 1:
+ mShader.append(" col.a *= texture2D(uni_Tex0, t0).a;\n");
+ break;
+ case 2:
+ mShader.append(" col.rgba *= texture2D(uni_Tex0, t0).rgba;\n");
+ break;
+ case 3:
+ mShader.append(" col.rgb *= texture2D(uni_Tex0, t0).rgb;\n");
+ break;
+ case 4:
+ mShader.append(" col.rgba *= texture2D(uni_Tex0, t0).rgba;\n");
+ break;
+ }
break;
case RS_TEX_ENV_MODE_DECAL:
- mShader.append(" col = texture2D(uni_Tex0, tex0);\n");
+ mShader.append(" col = texture2D(uni_Tex0, t0);\n");
break;
}
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index 153e2d6..fe628ca 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -246,9 +246,7 @@ ProgramVertexState::~ProgramVertexState()
void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h)
{
- rsi_ElementBegin(rsc);
- rsi_ElementAdd(rsc, RS_KIND_USER, RS_TYPE_FLOAT, false, 32, NULL);
- RsElement e = rsi_ElementCreate(rsc);
+ RsElement e = Element::create(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 1);
rsi_TypeBegin(rsc, e);
rsi_TypeAdd(rsc, RS_DIMENSION_X, 48);
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 3fa9813..9db3127 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -311,9 +311,15 @@ void ScriptCState::appendTypes(const Context *rsc, String8 *str)
char buf[256];
String8 tmp;
- str->append("struct vec2_s {float x; float y;};");
- str->append("struct vec3_s {float x; float y; float z;};");
- str->append("struct vec4_s {float x; float y; float z; float w;};");
+ str->append("struct vecF32_2_s {float x; float y;};\n");
+ str->append("struct vecF32_3_s {float x; float y; float z;};\n");
+ str->append("struct vecF32_4_s {float x; float y; float z; float w;};\n");
+ str->append("struct vecU8_4_s {char r; char g; char b; char a;};\n");
+ str->append("#define vecF32_2_t struct vecF32_2_s\n");
+ str->append("#define vecF32_3_t struct vecF32_3_s\n");
+ str->append("#define vecF32_4_t struct vecF32_4_s\n");
+ str->append("#define vecU8_4_t struct vecU8_4_s\n");
+ str->append("#define vecI8_4_t struct vecU8_4_s\n");
for (size_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
const Type *t = mConstantBufferTypes[ct].get();
@@ -324,8 +330,9 @@ void ScriptCState::appendTypes(const Context *rsc, String8 *str)
if (e->getName() && (e->getFieldCount() > 1)) {
String8 s("struct struct_");
s.append(e->getName());
- appendElementBody(&s, e);
+ s.append(e->getCStructBody());
s.append(";\n");
+
s.append("#define ");
s.append(e->getName());
s.append("_t struct struct_");
@@ -337,45 +344,25 @@ void ScriptCState::appendTypes(const Context *rsc, String8 *str)
str->append(s);
}
- if (t->getName()) {
- for (size_t ct2=0; ct2 < e->getFieldCount(); ct2++) {
- const Element *c = e->getField(ct2);
- tmp.setTo("#define OFFSETOF_");
- tmp.append(t->getName());
- tmp.append("_");
- tmp.append(e->getFieldName(ct2));
- sprintf(buf, " %i\n", ct2);
- tmp.append(buf);
- if (rsc->props.mLogScripts) {
- LOGV(tmp);
- }
- str->append(tmp);
- }
- }
-
if (mSlotNames[ct].length() > 0) {
String8 s;
- if (e->getFieldCount() > 1) {
- if (e->getName()) {
- // Use the named struct
- s.setTo(e->getName());
- s.append("_t *");
- } else {
- // create an struct named from the slot.
- s.setTo("struct ");
- s.append(mSlotNames[ct]);
- s.append("_s");
- appendElementBody(&s, e);
- s.append(";\n");
- s.append("struct ");
- s.append(mSlotNames[ct]);
- s.append("_s * ");
- }
+ if (e->getName()) {
+ // Use the named struct
+ s.setTo(e->getName());
} else {
- // Just make an array
- s.setTo(e->getField(0)->getCType());
- s.append("_t *");
+ // create an struct named from the slot.
+ s.setTo("struct ");
+ s.append(mSlotNames[ct]);
+ s.append("_s");
+ s.append(e->getCStructBody());
+ //appendElementBody(&s, e);
+ s.append(";\n");
+ s.append("struct ");
+ s.append(mSlotNames[ct]);
+ s.append("_s");
}
+
+ s.append(" * ");
s.append(mSlotNames[ct]);
s.append(";\n");
if (rsc->props.mLogScripts) {
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index e9f47d6..917f294 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -689,9 +689,9 @@ static void SC_drawLine(float x1, float y1, float z1,
VertexArray va;
va.setPosition(2, GL_FLOAT, 12, (uint32_t)&vtx);
if (rsc->checkVersion2_0()) {
- va.setupGL2(&rsc->mStateVertexArray, &rsc->mShaderCache);
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
} else {
- va.setupGL(&rsc->mStateVertexArray);
+ va.setupGL(rsc, &rsc->mStateVertexArray);
}
glDrawArrays(GL_LINES, 0, 2);
@@ -707,9 +707,9 @@ static void SC_drawPoint(float x, float y, float z)
VertexArray va;
va.setPosition(1, GL_FLOAT, 12, (uint32_t)&vtx);
if (rsc->checkVersion2_0()) {
- va.setupGL2(&rsc->mStateVertexArray, &rsc->mShaderCache);
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
} else {
- va.setupGL(&rsc->mStateVertexArray);
+ va.setupGL(rsc, &rsc->mStateVertexArray);
}
glDrawArrays(GL_POINTS, 0, 1);
@@ -742,9 +742,9 @@ static void SC_drawQuadTexCoords(float x1, float y1, float z1,
//va.setTexture(2, GL_FLOAT, 8, (uint32_t)&tex, 1);
//
if (rsc->checkVersion2_0()) {
- va.setupGL2(&rsc->mStateVertexArray, &rsc->mShaderCache);
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
} else {
- va.setupGL(&rsc->mStateVertexArray);
+ va.setupGL(rsc, &rsc->mStateVertexArray);
}
@@ -1223,33 +1223,33 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
// vec3
{ "vec3Norm", (void *)&SC_vec3Norm,
- "void", "(struct vec3_s *)" },
+ "void", "(struct vecF32_3_s *)" },
{ "vec3Length", (void *)&SC_vec3Length,
- "float", "(struct vec3_s *)" },
+ "float", "(struct vecF32_3_s *)" },
{ "vec3Add", (void *)&SC_vec3Add,
- "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
+ "void", "(struct vecF32_3_s *dest, struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
{ "vec3Sub", (void *)&SC_vec3Sub,
- "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
+ "void", "(struct vecF32_3_s *dest, struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
{ "vec3Cross", (void *)&SC_vec3Cross,
- "void", "(struct vec3_s *dest, struct vec3_s *lhs, struct vec3_s *rhs)" },
+ "void", "(struct vecF32_3_s *dest, struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
{ "vec3Dot", (void *)&SC_vec3Dot,
- "float", "(struct vec3_s *lhs, struct vec3_s *rhs)" },
+ "float", "(struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
{ "vec3Scale", (void *)&SC_vec3Scale,
- "void", "(struct vec3_s *lhs, float scale)" },
+ "void", "(struct vecF32_3_s *lhs, float scale)" },
// vec4
{ "vec4Norm", (void *)&SC_vec4Norm,
- "void", "(struct vec4_s *)" },
+ "void", "(struct vecF32_4_s *)" },
{ "vec4Length", (void *)&SC_vec4Length,
- "float", "(struct vec4_s *)" },
+ "float", "(struct vecF32_4_s *)" },
{ "vec4Add", (void *)&SC_vec4Add,
- "void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" },
+ "void", "(struct vecF32_4_s *dest, struct vecF32_4_s *lhs, struct vecF32_4_s *rhs)" },
{ "vec4Sub", (void *)&SC_vec4Sub,
- "void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" },
+ "void", "(struct vecF32_4_s *dest, struct vecF32_4_s *lhs, struct vecF32_4_s *rhs)" },
{ "vec4Dot", (void *)&SC_vec4Dot,
- "float", "(struct vec4_s *lhs, struct vec4_s *rhs)" },
+ "float", "(struct vecF32_4_s *lhs, struct vecF32_4_s *rhs)" },
{ "vec4Scale", (void *)&SC_vec4Scale,
- "void", "(struct vec4_s *lhs, float scale)" },
+ "void", "(struct vecF32_4_s *lhs, float scale)" },
// context
{ "bindProgramFragment", (void *)&SC_bindProgramFragment,
diff --git a/libs/rs/rsShaderCache.cpp b/libs/rs/rsShaderCache.cpp
index 8e2af34..311e3f5 100644
--- a/libs/rs/rsShaderCache.cpp
+++ b/libs/rs/rsShaderCache.cpp
@@ -93,7 +93,10 @@ bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag
glBindAttribLocation(pgm, VertexArray::POSITION, "attrib_Position");
glBindAttribLocation(pgm, VertexArray::COLOR, "attrib_Color");
-
+ //glBindAttribLocation(pgm, VertexArray::NORMAL, "attrib_Normal");
+ //glBindAttribLocation(pgm, VertexArray::POINT_SIZE, "attrib_PointSize");
+ //glBindAttribLocation(pgm, VertexArray::TEXTURE_0, "attrib_T0");
+ //glBindAttribLocation(pgm, VertexArray::TEXTURE_1, "attrib_T1");
//LOGE("e2 %x", glGetError());
glLinkProgram(pgm);
diff --git a/libs/rs/rsSimpleMesh.cpp b/libs/rs/rsSimpleMesh.cpp
index f7d14a5..5f5622d 100644
--- a/libs/rs/rsSimpleMesh.cpp
+++ b/libs/rs/rsSimpleMesh.cpp
@@ -62,9 +62,9 @@ void SimpleMesh::renderRange(Context *rsc, uint32_t start, uint32_t len) const
mVertexTypes[ct]->enableGLVertexBuffer(&va);
}
if (rsc->checkVersion2_0()) {
- va.setupGL2(0, &rsc->mShaderCache);
+ va.setupGL2(rsc, 0, &rsc->mShaderCache);
} else {
- va.setupGL(0);
+ va.setupGL(rsc, 0);
}
if (mIndexType.get()) {
@@ -74,6 +74,8 @@ void SimpleMesh::renderRange(Context *rsc, uint32_t start, uint32_t len) const
} else {
glDrawArrays(mGLPrimitive, start, len);
}
+
+ rsc->checkError("SimpleMesh::renderRange");
}
void SimpleMesh::uploadAll(Context *rsc)
@@ -89,6 +91,7 @@ void SimpleMesh::uploadAll(Context *rsc)
if (mPrimitiveBuffer.get()) {
mPrimitiveBuffer->deferedUploadToBufferObject(rsc);
}
+ rsc->checkError("SimpleMesh::uploadAll");
}
diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp
index 5eac0b5..e7bcb08 100644
--- a/libs/rs/rsType.cpp
+++ b/libs/rs/rsType.cpp
@@ -137,106 +137,44 @@ void Type::makeGLComponents()
memset(&mGL, 0, sizeof(mGL));
for (uint32_t ct=0; ct < getElement()->getFieldCount(); ct++) {
- const Element *c = getElement()->getField(ct);
+ const Component &c = getElement()->getField(ct)->getComponent();
- switch(c->getKind()) {
- case RS_KIND_X:
+ switch(c.getKind()) {
+ case RS_KIND_POSITION:
rsAssert(mGL.mVtx.size == 0);
- mGL.mVtx.size = 1;
+ mGL.mVtx.size = c.getVectorSize();
mGL.mVtx.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mVtx.type = c->getGLType();
+ mGL.mVtx.type = c.getGLType();
break;
- case RS_KIND_Y:
- rsAssert(mGL.mVtx.size == 1);
- rsAssert(mGL.mVtx.type == c->getGLType());
- mGL.mVtx.size = 2;
- break;
- case RS_KIND_Z:
- rsAssert(mGL.mVtx.size == 2);
- rsAssert(mGL.mVtx.type == c->getGLType());
- mGL.mVtx.size = 3;
- break;
- case RS_KIND_W:
- rsAssert(mGL.mVtx.size == 4);
- rsAssert(mGL.mVtx.type == c->getGLType());
- mGL.mVtx.size = 4;
- break;
- case RS_KIND_RED:
+ case RS_KIND_COLOR:
rsAssert(mGL.mColor.size == 0);
- mGL.mColor.size = 1;
+ mGL.mColor.size = c.getVectorSize();
mGL.mColor.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mColor.type = c->getGLType();
- break;
- case RS_KIND_GREEN:
- rsAssert(mGL.mColor.size == 1);
- rsAssert(mGL.mColor.type == c->getGLType());
- mGL.mColor.size = 2;
+ mGL.mColor.type = c.getGLType();
break;
- case RS_KIND_BLUE:
- rsAssert(mGL.mColor.size == 2);
- rsAssert(mGL.mColor.type == c->getGLType());
- mGL.mColor.size = 3;
- break;
- case RS_KIND_ALPHA:
- // Can be RGBA or A at this point
- if (mGL.mColor.size > 0) {
- rsAssert(mGL.mColor.size == 3);
- rsAssert(mGL.mColor.type == c->getGLType());
- mGL.mColor.size = 4;
- } else {
- mGL.mColor.size = 1;
- mGL.mColor.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mColor.type = c->getGLType();
- }
- break;
- case RS_KIND_NX:
+ case RS_KIND_NORMAL:
rsAssert(mGL.mNorm.size == 0);
- mGL.mNorm.size = 1;
+ mGL.mNorm.size = c.getVectorSize();
mGL.mNorm.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mNorm.type = c->getGLType();
- break;
- case RS_KIND_NY:
- rsAssert(mGL.mNorm.size == 1);
- rsAssert(mGL.mNorm.type == c->getGLType());
- mGL.mNorm.size = 2;
- break;
- case RS_KIND_NZ:
- rsAssert(mGL.mNorm.size == 2);
- rsAssert(mGL.mNorm.type == c->getGLType());
- mGL.mNorm.size = 3;
- break;
+ mGL.mNorm.type = c.getGLType();
+ break;
- case RS_KIND_S:
+ case RS_KIND_TEXTURE:
if (mGL.mTex[texNum].size) {
texNum++;
}
- mGL.mTex[texNum].size = 1;
+ mGL.mTex[texNum].size = c.getVectorSize();
mGL.mTex[texNum].offset = mElement->getFieldOffsetBytes(ct);
- mGL.mTex[texNum].type = c->getGLType();
- break;
- case RS_KIND_T:
- rsAssert(mGL.mTex[texNum].size == 1);
- rsAssert(mGL.mTex[texNum].type == c->getGLType());
- mGL.mTex[texNum].size = 2;
- break;
- case RS_KIND_R:
- rsAssert(mGL.mTex[texNum].size == 2);
- rsAssert(mGL.mTex[texNum].type == c->getGLType());
- mGL.mTex[texNum].size = 3;
- break;
- case RS_KIND_Q:
- rsAssert(mGL.mTex[texNum].size == 3);
- rsAssert(mGL.mTex[texNum].type == c->getGLType());
- mGL.mTex[texNum].size = 4;
- break;
+ mGL.mTex[texNum].type = c.getGLType();
+ break;
case RS_KIND_POINT_SIZE:
rsAssert(!mGL.mPointSize.size);
- mGL.mPointSize.size = 1;
+ mGL.mPointSize.size = c.getVectorSize();
mGL.mPointSize.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mPointSize.type = c->getGLType();
+ mGL.mPointSize.type = c.getGLType();
break;
default:
diff --git a/libs/rs/rsVertexArray.cpp b/libs/rs/rsVertexArray.cpp
index 34d42ed..2ba0ef9 100644
--- a/libs/rs/rsVertexArray.cpp
+++ b/libs/rs/rsVertexArray.cpp
@@ -96,15 +96,16 @@ void VertexArray::setTexture(uint32_t size, uint32_t type, uint32_t stride, uint
}
void VertexArray::logAttrib(uint32_t idx) const {
- LOGE("va %i: buf=%i size=%i type=0x%x stride=0x%x offset=0x%x", idx,
+ LOGE("va %i: buf=%i size=%i type=0x%x stride=0x%x norm=%i offset=0x%x", idx,
mAttribs[idx].buffer,
mAttribs[idx].size,
mAttribs[idx].type,
mAttribs[idx].stride,
+ mAttribs[idx].normalized,
mAttribs[idx].offset);
}
-void VertexArray::setupGL(class VertexArrayState *state) const
+void VertexArray::setupGL(const Context *rsc, class VertexArrayState *state) const
{
if (mAttribs[POSITION].size) {
//logAttrib(POSITION);
@@ -168,9 +169,10 @@ void VertexArray::setupGL(class VertexArrayState *state) const
} else {
glDisableClientState(GL_POINT_SIZE_ARRAY_OES);
}
+ rsc->checkError("VertexArray::setupGL");
}
-void VertexArray::setupGL2(class VertexArrayState *state, ShaderCache *sc) const
+void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, ShaderCache *sc) const
{
for (int ct=1; ct < _LAST; ct++) {
glDisableVertexAttribArray(ct);
@@ -194,6 +196,7 @@ void VertexArray::setupGL2(class VertexArrayState *state, ShaderCache *sc) const
rsAssert(ct);
}
}
+ rsc->checkError("VertexArray::setupGL2");
}
////////////////////////////////////////////
diff --git a/libs/rs/rsVertexArray.h b/libs/rs/rsVertexArray.h
index 235ffef..f97813f 100644
--- a/libs/rs/rsVertexArray.h
+++ b/libs/rs/rsVertexArray.h
@@ -64,8 +64,8 @@ public:
void setPointSize(uint32_t type, uint32_t stride, uint32_t offset);
void setTexture(uint32_t size, uint32_t type, uint32_t stride, uint32_t offset, uint32_t num);
- void setupGL(class VertexArrayState *) const;
- void setupGL2(class VertexArrayState *, ShaderCache *) const;
+ void setupGL(const Context *rsc, class VertexArrayState *) const;
+ void setupGL2(const Context *rsc, class VertexArrayState *, ShaderCache *) const;
void logAttrib(uint32_t idx) const;
protected: