summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--graphics/java/android/renderscript/Allocation.java27
-rw-r--r--graphics/java/android/renderscript/BaseObj.java1
-rw-r--r--graphics/java/android/renderscript/Element.java553
-rw-r--r--graphics/java/android/renderscript/Program.java144
-rw-r--r--graphics/java/android/renderscript/ProgramFragment.java167
-rw-r--r--graphics/java/android/renderscript/ProgramVertex.java69
-rw-r--r--graphics/java/android/renderscript/RenderScript.java57
-rw-r--r--graphics/java/android/renderscript/Sampler.java32
-rw-r--r--graphics/java/android/renderscript/SimpleMesh.java26
-rw-r--r--graphics/java/android/renderscript/Type.java11
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp216
-rw-r--r--libs/rs/Android.mk7
-rw-r--r--libs/rs/RenderScript.h71
-rw-r--r--libs/rs/RenderScriptEnv.h1
-rw-r--r--libs/rs/java/Film/src/com/android/film/FilmRS.java22
-rw-r--r--libs/rs/java/Film/src/com/android/film/FilmView.java18
-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/Fountain/src/com/android/fountain/FountainView.java2
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java14
-rw-r--r--libs/rs/java/Rollo/Android.mk25
-rw-r--r--libs/rs/java/Rollo/AndroidManifest.xml16
-rw-r--r--libs/rs/java/Rollo/res/drawable/test_pattern.pngbin307 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/browser.pngbin5772 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/calendar.pngbin4551 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/g1155.pngbin5094 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/g2140.pngbin3982 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/maps.pngbin5374 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/market.pngbin4810 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path1920.pngbin3812 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path1927.pngbin4034 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path3099.pngbin4981 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path3950.pngbin4873 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path431.pngbin3995 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path4481.pngbin4113 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path5168.pngbin5328 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path676.pngbin4351 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path754.pngbin3205 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/path815.pngbin5536 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/photos.pngbin4902 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/polygon2408.pngbin3873 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/res/raw/rollo.c184
-rw-r--r--libs/rs/java/Rollo/res/raw/rollo2.c155
-rw-r--r--libs/rs/java/Rollo/res/raw/settings.pngbin3764 -> 0 bytes
-rw-r--r--libs/rs/java/Rollo/src/com/android/rollo/Rollo.java90
-rw-r--r--libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java315
-rw-r--r--libs/rs/java/Rollo/src/com/android/rollo/RolloView.java214
-rw-r--r--libs/rs/rs.spec81
-rw-r--r--libs/rs/rsAllocation.cpp135
-rw-r--r--libs/rs/rsAllocation.h19
-rw-r--r--libs/rs/rsComponent.cpp349
-rw-r--r--libs/rs/rsComponent.h71
-rw-r--r--libs/rs/rsContext.cpp130
-rw-r--r--libs/rs/rsContext.h30
-rw-r--r--libs/rs/rsElement.cpp265
-rw-r--r--libs/rs/rsElement.h45
-rw-r--r--libs/rs/rsFileA3D.cpp2
-rw-r--r--libs/rs/rsProgram.cpp227
-rw-r--r--libs/rs/rsProgram.h65
-rw-r--r--libs/rs/rsProgramFragment.cpp292
-rw-r--r--libs/rs/rsProgramFragment.h37
-rw-r--r--libs/rs/rsProgramFragmentStore.cpp42
-rw-r--r--libs/rs/rsProgramFragmentStore.h3
-rw-r--r--libs/rs/rsProgramRaster.cpp16
-rw-r--r--libs/rs/rsProgramRaster.h3
-rw-r--r--libs/rs/rsProgramVertex.cpp292
-rw-r--r--libs/rs/rsProgramVertex.h17
-rw-r--r--libs/rs/rsSampler.cpp10
-rw-r--r--libs/rs/rsSampler.h4
-rw-r--r--libs/rs/rsScriptC.cpp74
-rw-r--r--libs/rs/rsScriptC_Lib.cpp174
-rw-r--r--libs/rs/rsShaderCache.cpp167
-rw-r--r--libs/rs/rsShaderCache.h76
-rw-r--r--libs/rs/rsSimpleMesh.cpp51
-rw-r--r--libs/rs/rsSimpleMesh.h6
-rw-r--r--libs/rs/rsType.cpp228
-rw-r--r--libs/rs/rsType.h21
-rw-r--r--libs/rs/rsVertexArray.cpp216
-rw-r--r--libs/rs/rsVertexArray.h86
79 files changed, 3113 insertions, 2593 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index b6ac14aa4c29..e5cf38ec5efa 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -39,15 +39,17 @@ public class Allocation extends BaseObj {
mType = t;
}
+ public Type getType() {
+ return mType;
+ }
+
public void uploadToTexture(int baseMipLevel) {
mRS.validate();
- mRS.validateSurface();
mRS.nAllocationUploadToTexture(mID, baseMipLevel);
}
public void uploadToBufferObject() {
mRS.validate();
- mRS.validateSurface();
mRS.nAllocationUploadToBufferObject(mID);
}
@@ -171,9 +173,10 @@ public class Allocation extends BaseObj {
public Adapter1D createAdapter1D() {
mRS.validate();
int id = mRS.nAdapter1DCreate();
- if (id != 0) {
- mRS.nAdapter1DBindAllocation(id, mID);
+ if(id == 0) {
+ throw new IllegalStateException("allocation failed.");
}
+ mRS.nAdapter1DBindAllocation(id, mID);
return new Adapter1D(id, mRS);
}
@@ -213,9 +216,10 @@ public class Allocation extends BaseObj {
public Adapter2D createAdapter2D() {
mRS.validate();
int id = mRS.nAdapter2DCreate();
- if (id != 0) {
- mRS.nAdapter2DBindAllocation(id, mID);
+ if(id == 0) {
+ throw new IllegalStateException("allocation failed.");
}
+ mRS.nAdapter2DBindAllocation(id, mID);
return new Adapter2D(id, mRS);
}
@@ -258,14 +262,20 @@ public class Allocation extends BaseObj {
rs.validate();
int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(id, rs, null);
}
- static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
+ static Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
throws IllegalArgumentException {
rs.validate();
int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(id, rs, null);
}
@@ -282,6 +292,9 @@ public class Allocation extends BaseObj {
int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mID, genMips,
asset);
+ if(allocationId == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
return new Allocation(allocationId, rs, null);
} catch (Exception e) {
// Ignore
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java
index e802ec51a1ec..002fc788326a 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 ee9b098aa8be..10ef05a378b1 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -24,259 +24,220 @@ import java.lang.reflect.Field;
**/
public class Element extends BaseObj {
int mSize;
- Entry[] mEntries;
+ Element[] mElements;
+ String[] mElementNames;
- int getSizeBytes() {
- return mSize;
- }
- int getComponentCount() {
- return mEntries.length;
- }
- Element.DataType getComponentDataType(int num) {
- return mEntries[num].mType;
- }
- Element.DataKind getComponentDataKind(int num) {
- return mEntries[num].mKind;
- }
- boolean getComponentIsNormalized(int num) {
- return mEntries[num].mIsNormalized;
- }
- int getComponentBits(int num) {
- return mEntries[num].mBits;
- }
- String getComponentName(int num) {
- return mEntries[num].mName;
+ DataType mType;
+ DataKind mKind;
+ boolean mNormalized;
+ int mVectorSize;
+
+ int getSizeBytes() {return mSize;}
+
+ public enum DataType {
+ //FLOAT_16 (1, 2),
+ FLOAT_32 (2, 4),
+ //FLOAT_64 (3, 8),
+ SIGNED_8 (4, 1),
+ SIGNED_16 (5, 2),
+ SIGNED_32 (6, 4),
+ //SIGNED_64 (7, 8),
+ UNSIGNED_8 (8, 1),
+ UNSIGNED_16 (9, 2),
+ UNSIGNED_32 (10, 4),
+ //UNSIGNED_64 (11, 8),
+
+ UNSIGNED_5_6_5 (12, 2),
+ UNSIGNED_5_5_5_1 (13, 2),
+ UNSIGNED_4_4_4_4 (14, 2),
+
+ RS_ELEMENT (15, 4),
+ RS_TYPE (16, 4),
+ RS_ALLOCATION (17, 4),
+ RS_SAMPLER (18, 4),
+ RS_SCRIPT (19, 4),
+ RS_MESH (20, 4),
+ RS_PROGRAM_FRAGMENT (21, 4),
+ RS_PROGRAM_VERTEX (22, 4),
+ RS_PROGRAM_RASTER (23, 4),
+ RS_PROGRAM_STORE (24, 4);
+
+ int mID;
+ int mSize;
+ DataType(int id, int size) {
+ mID = id;
+ mSize = size;
+ }
}
- static class Entry {
- //Element mElement;
- Element.DataType mType;
- Element.DataKind mKind;
- boolean mIsNormalized;
- int mBits;
- String mName;
-
- //Entry(Element e, int bits) {
- //mElement = e;
- //int mBits = bits;
- //}
-
- Entry(DataType dt, DataKind dk, boolean isNorm, int bits, String name) {
- mType = dt;
- mKind = dk;
- mIsNormalized = isNorm;
- mBits = bits;
- mName = name;
+ public enum DataKind {
+ USER (0),
+ COLOR (1),
+ POSITION (2),
+ TEXTURE (3),
+ NORMAL (4),
+ INDEX (5),
+ POINT_SIZE(6),
+
+ PIXEL_L (7),
+ PIXEL_A (8),
+ PIXEL_LA (9),
+ PIXEL_RGB (10),
+ PIXEL_RGBA (11);
+
+ int mID;
+ DataKind(int id) {
+ mID = id;
}
}
public static Element USER_U8(RenderScript rs) {
if(rs.mElement_USER_U8 == null) {
- rs.mElement_USER_U8 = new Element(rs, 1);
- rs.mElement_USER_U8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 8, null);
- rs.mElement_USER_U8.init();
+ rs.mElement_USER_U8 = createUser(rs, DataType.UNSIGNED_8);
}
return rs.mElement_USER_U8;
}
public static Element USER_I8(RenderScript rs) {
if(rs.mElement_USER_I8 == null) {
- rs.mElement_USER_I8 = new Element(rs, 1);
- rs.mElement_USER_I8.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 8, null);
- rs.mElement_USER_I8.init();
+ rs.mElement_USER_I8 = createUser(rs, DataType.SIGNED_8);
}
return rs.mElement_USER_I8;
}
- public static Element USER_U16(RenderScript rs) {
- if(rs.mElement_USER_U16 == null) {
- rs.mElement_USER_U16 = new Element(rs, 1);
- rs.mElement_USER_U16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 16, null);
- rs.mElement_USER_U16.init();
- }
- return rs.mElement_USER_U16;
- }
-
- public static Element USER_I16(RenderScript rs) {
- if(rs.mElement_USER_I16 == null) {
- rs.mElement_USER_I16 = new Element(rs, 1);
- rs.mElement_USER_I16.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 16, null);
- rs.mElement_USER_I16.init();
- }
- return rs.mElement_USER_I16;
- }
-
public static Element USER_U32(RenderScript rs) {
if(rs.mElement_USER_U32 == null) {
- rs.mElement_USER_U32 = new Element(rs, 1);
- rs.mElement_USER_U32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 32, null);
- rs.mElement_USER_U32.init();
+ rs.mElement_USER_U32 = createUser(rs, DataType.UNSIGNED_32);
}
return rs.mElement_USER_U32;
}
public static Element USER_I32(RenderScript rs) {
if(rs.mElement_USER_I32 == null) {
- rs.mElement_USER_I32 = new Element(rs, 1);
- rs.mElement_USER_I32.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 32, null);
- rs.mElement_USER_I32.init();
+ rs.mElement_USER_I32 = createUser(rs, DataType.SIGNED_32);
}
return rs.mElement_USER_I32;
}
public static Element USER_F32(RenderScript rs) {
- if(rs.mElement_USER_FLOAT == null) {
- rs.mElement_USER_FLOAT = new Element(rs, 1);
- rs.mElement_USER_FLOAT.mEntries[0] = new Entry(DataType.FLOAT, DataKind.USER, false, 32, null);
- rs.mElement_USER_FLOAT.init();
+ if(rs.mElement_USER_F32 == null) {
+ rs.mElement_USER_F32 = createUser(rs, DataType.FLOAT_32);
}
- return rs.mElement_USER_FLOAT;
+ return rs.mElement_USER_F32;
}
public static Element A_8(RenderScript rs) {
if(rs.mElement_A_8 == null) {
- rs.mElement_A_8 = new Element(rs, 1);
- rs.mElement_A_8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
- rs.mElement_A_8.init();
+ rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A);
}
return rs.mElement_A_8;
}
public static Element RGB_565(RenderScript rs) {
if(rs.mElement_RGB_565 == null) {
- rs.mElement_RGB_565 = new Element(rs, 3);
- rs.mElement_RGB_565.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
- rs.mElement_RGB_565.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 6, "g");
- rs.mElement_RGB_565.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
- rs.mElement_RGB_565.init();
+ rs.mElement_RGB_565 = createPixel(rs, DataType.UNSIGNED_5_6_5, DataKind.PIXEL_RGB);
}
return rs.mElement_RGB_565;
}
public static Element RGB_888(RenderScript rs) {
if(rs.mElement_RGB_888 == null) {
- rs.mElement_RGB_888 = new Element(rs, 3);
- rs.mElement_RGB_888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
- rs.mElement_RGB_888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
- rs.mElement_RGB_888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
- rs.mElement_RGB_888.init();
+ rs.mElement_RGB_888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGB);
}
return rs.mElement_RGB_888;
}
public static Element RGBA_5551(RenderScript rs) {
if(rs.mElement_RGBA_5551 == null) {
- rs.mElement_RGBA_5551 = new Element(rs, 4);
- rs.mElement_RGBA_5551.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
- rs.mElement_RGBA_5551.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 5, "g");
- rs.mElement_RGBA_5551.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
- rs.mElement_RGBA_5551.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 1, "a");
- rs.mElement_RGBA_5551.init();
+ rs.mElement_RGBA_5551 = createPixel(rs, DataType.UNSIGNED_5_5_5_1, DataKind.PIXEL_RGBA);
}
return rs.mElement_RGBA_5551;
}
public static Element RGBA_4444(RenderScript rs) {
if(rs.mElement_RGBA_4444 == null) {
- rs.mElement_RGBA_4444 = new Element(rs, 4);
- rs.mElement_RGBA_4444.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 4, "r");
- rs.mElement_RGBA_4444.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 4, "g");
- rs.mElement_RGBA_4444.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 4, "b");
- rs.mElement_RGBA_4444.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 4, "a");
- rs.mElement_RGBA_4444.init();
+ rs.mElement_RGBA_4444 = createPixel(rs, DataType.UNSIGNED_4_4_4_4, DataKind.PIXEL_RGBA);
}
return rs.mElement_RGBA_4444;
}
public static Element RGBA_8888(RenderScript rs) {
if(rs.mElement_RGBA_8888 == null) {
- rs.mElement_RGBA_8888 = new Element(rs, 4);
- rs.mElement_RGBA_8888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
- rs.mElement_RGBA_8888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
- rs.mElement_RGBA_8888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
- rs.mElement_RGBA_8888.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
- rs.mElement_RGBA_8888.init();
+ rs.mElement_RGBA_8888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGBA);
}
return rs.mElement_RGBA_8888;
}
public static Element INDEX_16(RenderScript rs) {
if(rs.mElement_INDEX_16 == null) {
- rs.mElement_INDEX_16 = new Element(rs, 1);
- rs.mElement_INDEX_16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.INDEX, false, 16, "index");
- rs.mElement_INDEX_16.init();
+ rs.mElement_INDEX_16 = createIndex(rs);
}
return rs.mElement_INDEX_16;
}
- public static Element XY_F32(RenderScript rs) {
- if(rs.mElement_XY_F32 == null) {
- rs.mElement_XY_F32 = new Element(rs, 2);
- rs.mElement_XY_F32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.X, false, 32, "x");
- rs.mElement_XY_F32.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.Y, false, 32, "y");
- rs.mElement_XY_F32.init();
+ public static Element ATTRIB_POSITION_2(RenderScript rs) {
+ if(rs.mElement_POSITION_2 == null) {
+ rs.mElement_POSITION_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 2);
}
- return rs.mElement_XY_F32;
+ return rs.mElement_POSITION_2;
}
- public static Element XYZ_F32(RenderScript rs) {
- if(rs.mElement_XYZ_F32 == null) {
- rs.mElement_XYZ_F32 = new Element(rs, 3);
- rs.mElement_XYZ_F32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.X, false, 32, "x");
- rs.mElement_XYZ_F32.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.Y, false, 32, "y");
- rs.mElement_XYZ_F32.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.Z, false, 32, "z");
- rs.mElement_XYZ_F32.init();
+ public static Element ATTRIB_POSITION_3(RenderScript rs) {
+ if(rs.mElement_POSITION_3 == null) {
+ rs.mElement_POSITION_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.POSITION, 3);
}
- return rs.mElement_XYZ_F32;
+ return rs.mElement_POSITION_3;
}
- static void initPredefined(RenderScript rs) {
- rs.nInitElements(A_8(rs).mID, RGBA_4444(rs).mID, RGBA_8888(rs).mID, RGB_565(rs).mID);
+ public static Element ATTRIB_TEXTURE_2(RenderScript rs) {
+ if(rs.mElement_TEXTURE_2 == null) {
+ rs.mElement_TEXTURE_2 = createAttrib(rs, DataType.FLOAT_32, DataKind.TEXTURE, 2);
+ }
+ return rs.mElement_TEXTURE_2;
}
- public enum DataType {
- FLOAT (0),
- UNSIGNED (1),
- SIGNED (2);
-
- int mID;
- DataType(int id) {
- mID = id;
+ public static Element ATTRIB_NORMAL_3(RenderScript rs) {
+ if(rs.mElement_NORMAL_3 == null) {
+ rs.mElement_NORMAL_3 = createAttrib(rs, DataType.FLOAT_32, DataKind.NORMAL, 3);
}
+ return rs.mElement_NORMAL_3;
}
- public enum DataKind {
- USER (0),
- RED (1),
- GREEN (2),
- BLUE (3),
- ALPHA (4),
- LUMINANCE (5),
- INTENSITY (6),
- X (7),
- Y (8),
- Z (9),
- W (10),
- S (11),
- T (12),
- Q (13),
- R (14),
- NX (15),
- NY (16),
- NZ (17),
- INDEX (18),
- POINT_SIZE(19);
+ public static Element ATTRIB_COLOR_U8_4(RenderScript rs) {
+ if(rs.mElement_COLOR_U8_4 == null) {
+ rs.mElement_COLOR_U8_4 = createAttrib(rs, DataType.UNSIGNED_8, DataKind.COLOR, 4);
+ }
+ return rs.mElement_COLOR_U8_4;
+ }
- int mID;
- DataKind(int id) {
- mID = id;
+ public static Element ATTRIB_COLOR_F32_4(RenderScript rs) {
+ if(rs.mElement_COLOR_F32_4 == null) {
+ rs.mElement_COLOR_F32_4 = createAttrib(rs, DataType.FLOAT_32, DataKind.COLOR, 4);
}
+ return rs.mElement_COLOR_F32_4;
}
- Element(RenderScript rs, int count) {
+ Element(RenderScript rs, Element[] e, String[] n) {
super(rs);
mSize = 0;
- mEntries = new Entry[count];
+ mElements = e;
+ mElementNames = n;
+ int[] ids = new int[mElements.length];
+ for (int ct = 0; ct < mElements.length; ct++ ) {
+ mSize += mElements[ct].mSize;
+ ids[ct] = mElements[ct].mID;
+ }
+ mID = rs.nElementCreate2(ids, mElementNames);
+ }
+
+ Element(RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
+ super(rs);
+ mSize = dt.mSize * size;
+ mType = dt;
+ mKind = dk;
+ mNormalized = norm;
+ mVectorSize = size;
+ mID = rs.nElementCreate(dt.mID, dk.mID, norm, size);
}
public void destroy() throws IllegalStateException {
@@ -291,13 +252,13 @@ public class Element extends BaseObj {
for(Field f: fields) {
Class fc = f.getType();
if(fc == int.class) {
- b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 32, f.getName());
+ b.add(createUser(rs, DataType.SIGNED_32), f.getName());
} else if(fc == short.class) {
- b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 16, f.getName());
+ b.add(createUser(rs, DataType.SIGNED_16), f.getName());
} else if(fc == byte.class) {
- b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 8, f.getName());
+ b.add(createUser(rs, DataType.SIGNED_8), f.getName());
} else if(fc == float.class) {
- b.add(Element.DataType.FLOAT, Element.DataKind.USER, false, 32, f.getName());
+ b.add(createUser(rs, DataType.FLOAT_32), f.getName());
} else {
throw new IllegalArgumentException("Unkown field type");
}
@@ -305,193 +266,157 @@ public class Element extends BaseObj {
return b.create();
}
- static synchronized void internalCreate(RenderScript rs, Element e) {
- rs.nElementBegin();
- int bits = 0;
- for (int ct=0; ct < e.mEntries.length; ct++) {
- Entry en = e.mEntries[ct];
- //if(en.mElement != null) {
- //rs.nElementAdd(en.mElement.mID);
- //} else
- {
- rs.nElementAdd(en.mKind.mID, en.mType.mID, en.mIsNormalized, en.mBits, en.mName);
- bits += en.mBits;
- }
- }
- e.mID = rs.nElementCreate();
- e.mSize = (bits + 7) >> 3;
- }
- void init() {
- mRS.validate();
- internalCreate(mRS, this);
+ /////////////////////////////////////////
+ public static Element createUser(RenderScript rs, DataType dt) {
+ return new Element(rs, dt, DataKind.USER, false, 1);
}
-
- public static class Builder {
- RenderScript mRS;
- Entry[] mEntries;
- int mEntryCount;
-
- public Builder(RenderScript rs) {
- mRS = rs;
- mEntryCount = 0;
- mEntries = new Entry[8];
- }
-
- void addEntry(Entry e) {
- if(mEntries.length >= mEntryCount) {
- Entry[] en = new Entry[mEntryCount + 8];
- System.arraycopy(mEntries, 0, en, 0, mEntries.length);
- mEntries = en;
- }
- mEntries[mEntryCount] = e;
- mEntryCount++;
+ public static Element createVector(RenderScript rs, DataType dt, int size) {
+ if (size < 2 || size > 4) {
+ throw new IllegalArgumentException("Bad size");
}
+ return new Element(rs, dt, DataKind.USER, false, size);
+ }
- //public Builder add(Element e) throws IllegalArgumentException {
- //Entry en = new Entry(e, e.mSize * 8);
- //addEntry(en);
- //return this;
- //}
+ public static Element createIndex(RenderScript rs) {
+ return new Element(rs, DataType.UNSIGNED_16, DataKind.INDEX, false, 1);
+ }
- public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) {
- Entry en = new Entry(dt, dk, isNormalized, bits, name);
- addEntry(en);
- return this;
+ public static Element createAttrib(RenderScript rs, DataType dt, DataKind dk, int size) {
+ if (!(dt == DataType.FLOAT_32 ||
+ dt == DataType.UNSIGNED_8 ||
+ dt == DataType.UNSIGNED_16 ||
+ dt == DataType.UNSIGNED_32 ||
+ dt == DataType.SIGNED_8 ||
+ dt == DataType.SIGNED_16 ||
+ dt == DataType.SIGNED_32)) {
+ throw new IllegalArgumentException("Unsupported DataType");
}
- public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) {
- add(dt, dk, isNormalized, bits, null);
- return this;
+ if (!(dk == DataKind.COLOR ||
+ dk == DataKind.POSITION ||
+ dk == DataKind.TEXTURE ||
+ dk == DataKind.NORMAL ||
+ dk == DataKind.POINT_SIZE ||
+ dk == DataKind.USER)) {
+ throw new IllegalArgumentException("Unsupported DataKind");
}
- public Builder addFloat(Element.DataKind dk) {
- add(DataType.FLOAT, dk, false, 32, null);
- return this;
+ if (dk == DataKind.COLOR &&
+ ((dt != DataType.FLOAT_32 && dt != DataType.UNSIGNED_8) ||
+ size < 3 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloat(Element.DataKind dk, String name) {
- add(DataType.FLOAT, dk, false, 32, name);
- return this;
+ if (dk == DataKind.POSITION && (size < 1 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXY() {
- add(DataType.FLOAT, DataKind.X, false, 32, null);
- add(DataType.FLOAT, DataKind.Y, false, 32, null);
- return this;
+ if (dk == DataKind.TEXTURE &&
+ (dt != DataType.FLOAT_32 || size < 1 || size > 4)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXY(String prefix) {
- add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
- add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
- return this;
+ if (dk == DataKind.NORMAL &&
+ (dt != DataType.FLOAT_32 || size != 3)) {
+ throw new IllegalArgumentException("Bad combo");
}
-
- public Builder addFloatXYZ() {
- add(DataType.FLOAT, DataKind.X, false, 32, null);
- add(DataType.FLOAT, DataKind.Y, false, 32, null);
- add(DataType.FLOAT, DataKind.Z, false, 32, null);
- return this;
+ if (dk == DataKind.POINT_SIZE &&
+ (dt != DataType.FLOAT_32 || size != 1)) {
+ throw new IllegalArgumentException("Bad combo");
}
- public Builder addFloatXYZ(String prefix) {
- add(DataType.FLOAT, DataKind.X, false, 32, prefix + "x");
- add(DataType.FLOAT, DataKind.Y, false, 32, prefix + "y");
- add(DataType.FLOAT, DataKind.Z, false, 32, prefix + "z");
- return this;
+ boolean norm = false;
+ if (dk == DataKind.COLOR && dt == DataType.UNSIGNED_8) {
+ norm = true;
}
- public Builder addFloatST() {
- add(DataType.FLOAT, DataKind.S, false, 32, null);
- add(DataType.FLOAT, DataKind.T, false, 32, null);
- return this;
- }
+ return new Element(rs, dt, dk, norm, size);
+ }
- public Builder addFloatST(String prefix) {
- add(DataType.FLOAT, DataKind.S, false, 32, prefix + "s");
- add(DataType.FLOAT, DataKind.T, false, 32, prefix + "t");
- return this;
+ public static Element createPixel(RenderScript rs, DataType dt, DataKind dk) {
+ if (!(dk == DataKind.PIXEL_L ||
+ dk == DataKind.PIXEL_A ||
+ dk == DataKind.PIXEL_LA ||
+ dk == DataKind.PIXEL_RGB ||
+ dk == DataKind.PIXEL_RGBA)) {
+ throw new IllegalArgumentException("Unsupported DataKind");
}
-
- public Builder addFloatNorm() {
- add(DataType.FLOAT, DataKind.NX, false, 32, null);
- add(DataType.FLOAT, DataKind.NY, false, 32, null);
- add(DataType.FLOAT, DataKind.NZ, false, 32, null);
- return this;
+ if (!(dt == DataType.UNSIGNED_8 ||
+ dt == DataType.UNSIGNED_5_6_5 ||
+ dt == DataType.UNSIGNED_4_4_4_4 ||
+ dt == DataType.UNSIGNED_5_5_5_1)) {
+ throw new IllegalArgumentException("Unsupported DataType");
}
-
- public Builder addFloatNorm(String prefix) {
- add(DataType.FLOAT, DataKind.NX, false, 32, prefix + "nx");
- add(DataType.FLOAT, DataKind.NY, false, 32, prefix + "ny");
- add(DataType.FLOAT, DataKind.NZ, false, 32, prefix + "nz");
- return this;
+ if (dt == DataType.UNSIGNED_5_6_5 && dk != DataKind.PIXEL_RGB) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
-
- public Builder addFloatPointSize() {
- add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, null);
- return this;
+ if (dt == DataType.UNSIGNED_5_5_5_1 && dk != DataKind.PIXEL_RGBA) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
-
- public Builder addFloatPointSize(String prefix) {
- add(DataType.FLOAT, DataKind.POINT_SIZE, false, 32, prefix + "pointSize");
- return this;
+ if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
+ throw new IllegalArgumentException("Bad kind and type combo");
}
- public Builder addFloatRGB() {
- add(DataType.FLOAT, DataKind.RED, false, 32, null);
- add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
- add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
- return this;
+ int size = 1;
+ if (dk == DataKind.PIXEL_LA) {
+ size = 2;
}
-
- public Builder addFloatRGB(String prefix) {
- add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
- add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
- add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
- return this;
+ if (dk == DataKind.PIXEL_RGB) {
+ size = 3;
}
-
- public Builder addFloatRGBA() {
- add(DataType.FLOAT, DataKind.RED, false, 32, null);
- add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
- add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
- add(DataType.FLOAT, DataKind.ALPHA, false, 32, null);
- return this;
+ if (dk == DataKind.PIXEL_RGBA) {
+ size = 4;
}
- public Builder addFloatRGBA(String prefix) {
- add(DataType.FLOAT, DataKind.RED, false, 32, prefix + "r");
- add(DataType.FLOAT, DataKind.GREEN, false, 32, prefix + "g");
- add(DataType.FLOAT, DataKind.BLUE, false, 32, prefix + "b");
- add(DataType.FLOAT, DataKind.ALPHA, false, 32, prefix + "a");
- return this;
- }
+ return new Element(rs, dt, dk, true, size);
+ }
- public Builder addUNorm8RGBA() {
- add(DataType.UNSIGNED, DataKind.RED, true, 8, null);
- add(DataType.UNSIGNED, DataKind.GREEN, true, 8, null);
- add(DataType.UNSIGNED, DataKind.BLUE, true, 8, null);
- add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, null);
- return this;
- }
+ public static class Builder {
+ RenderScript mRS;
+ Element[] mElements;
+ String[] mElementNames;
+ int mCount;
- public Builder addUNorm8RGBA(String prefix) {
- add(DataType.UNSIGNED, DataKind.RED, true, 8, prefix + "r");
- add(DataType.UNSIGNED, DataKind.GREEN, true, 8, prefix + "g");
- add(DataType.UNSIGNED, DataKind.BLUE, true, 8, prefix + "b");
- add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, prefix + "a");
- return this;
+ public Builder(RenderScript rs) {
+ mRS = rs;
+ mCount = 0;
+ mElements = new Element[8];
+ mElementNames = new String[8];
+ }
+
+ public void add(Element element, String name) {
+ if(mCount == mElements.length) {
+ Element[] e = new Element[mCount + 8];
+ String[] s = new String[mCount + 8];
+ System.arraycopy(mElements, 0, e, 0, mCount);
+ System.arraycopy(mElementNames, 0, s, 0, mCount);
+ mElements = e;
+ mElementNames = s;
+ }
+ mElements[mCount] = element;
+ mElementNames[mCount] = name;
+ mCount++;
}
public Element create() {
mRS.validate();
- Element e = new Element(mRS, mEntryCount);
- java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount);
- e.init();
- return e;
+ Element[] ein = new Element[mCount];
+ String[] sin = new String[mCount];
+ java.lang.System.arraycopy(mElements, 0, ein, 0, mCount);
+ java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
+ return new Element(mRS, ein, sin);
}
}
+ static void initPredefined(RenderScript rs) {
+ int a8 = rs.nElementCreate(DataType.UNSIGNED_8.mID,
+ DataKind.PIXEL_A.mID, true, 1);
+ int rgba4444 = rs.nElementCreate(DataType.UNSIGNED_4_4_4_4.mID,
+ DataKind.PIXEL_RGBA.mID, true, 4);
+ int rgba8888 = rs.nElementCreate(DataType.UNSIGNED_8.mID,
+ DataKind.PIXEL_RGBA.mID, true, 4);
+ int rgb565 = rs.nElementCreate(DataType.UNSIGNED_5_6_5.mID,
+ DataKind.PIXEL_RGB.mID, true, 3);
+ rs.nInitElements(a8, rgba4444, rgba8888, rgb565);
+ }
}
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
new file mode 100644
index 000000000000..1614ec590cbd
--- /dev/null
+++ b/graphics/java/android/renderscript/Program.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+
+import android.util.Config;
+import android.util.Log;
+
+
+/**
+ * @hide
+ *
+ **/
+public class Program extends BaseObj {
+ public static final int MAX_INPUT = 8;
+ public static final int MAX_OUTPUT = 8;
+ public static final int MAX_CONSTANT = 8;
+ public static final int MAX_TEXTURE = 8;
+
+ Element mInputs[];
+ Element mOutputs[];
+ Type mConstants[];
+ int mTextureCount;
+ String mShader;
+
+ Program(int id, RenderScript rs) {
+ super(rs);
+ mID = id;
+ }
+
+ public void bindConstants(Allocation a, int slot) {
+ mRS.nProgramBindConstants(mID, slot, a.mID);
+ }
+
+ public void bindTexture(Allocation va, int slot)
+ throws IllegalArgumentException {
+ mRS.validate();
+ if((slot < 0) || (slot >= mTextureCount)) {
+ throw new IllegalArgumentException("Slot ID out of range.");
+ }
+
+ mRS.nProgramBindTexture(mID, slot, va.mID);
+ }
+
+ public void bindSampler(Sampler vs, int slot)
+ throws IllegalArgumentException {
+ mRS.validate();
+ if((slot < 0) || (slot >= mTextureCount)) {
+ throw new IllegalArgumentException("Slot ID out of range.");
+ }
+
+ mRS.nProgramBindSampler(mID, slot, vs.mID);
+ }
+
+
+ public static class BaseProgramBuilder {
+ RenderScript mRS;
+ Element mInputs[];
+ Element mOutputs[];
+ Type mConstants[];
+ Type mTextures[];
+ int mInputCount;
+ int mOutputCount;
+ int mConstantCount;
+ int mTextureCount;
+ String mShader;
+
+
+ protected BaseProgramBuilder(RenderScript rs) {
+ mRS = rs;
+ mInputs = new Element[MAX_INPUT];
+ mOutputs = new Element[MAX_OUTPUT];
+ mConstants = new Type[MAX_CONSTANT];
+ mInputCount = 0;
+ mOutputCount = 0;
+ mConstantCount = 0;
+ mTextureCount = 0;
+ }
+
+ public void setShader(String s) {
+ mShader = s;
+ }
+
+ public void addInput(Element e) throws IllegalStateException {
+ // Should check for consistant and non-conflicting names...
+ if(mInputCount >= MAX_INPUT) {
+ throw new IllegalArgumentException("Max input count exceeded.");
+ }
+ mInputs[mInputCount++] = e;
+ }
+
+ public void addOutput(Element e) throws IllegalStateException {
+ // Should check for consistant and non-conflicting names...
+ if(mOutputCount >= MAX_OUTPUT) {
+ throw new IllegalArgumentException("Max output count exceeded.");
+ }
+ mOutputs[mOutputCount++] = e;
+ }
+
+ public int addConstant(Type t) throws IllegalStateException {
+ // Should check for consistant and non-conflicting names...
+ if(mConstantCount >= MAX_CONSTANT) {
+ throw new IllegalArgumentException("Max input count exceeded.");
+ }
+ mConstants[mConstantCount] = t;
+ return mConstantCount++;
+ }
+
+ public void setTextureCount(int count) throws IllegalArgumentException {
+ // Should check for consistant and non-conflicting names...
+ if(count >= MAX_CONSTANT) {
+ throw new IllegalArgumentException("Max texture count exceeded.");
+ }
+ mTextureCount = count;
+ }
+
+ protected void initProgram(Program p) {
+ p.mInputs = new Element[mInputCount];
+ System.arraycopy(mInputs, 0, p.mInputs, 0, mInputCount);
+ p.mOutputs = new Element[mOutputCount];
+ System.arraycopy(mOutputs, 0, p.mOutputs, 0, mOutputCount);
+ p.mConstants = new Type[mConstantCount];
+ System.arraycopy(mConstants, 0, p.mConstants, 0, mConstantCount);
+ p.mTextureCount = mTextureCount;
+ }
+ }
+
+}
+
+
diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java
index 1a725785d907..5e04f0c57526 100644
--- a/graphics/java/android/renderscript/ProgramFragment.java
+++ b/graphics/java/android/renderscript/ProgramFragment.java
@@ -25,134 +25,115 @@ import android.util.Log;
* @hide
*
**/
-public class ProgramFragment extends BaseObj {
- public static final int MAX_SLOT = 2;
-
- public enum EnvMode {
- REPLACE (0),
- MODULATE (1),
- DECAL (2);
-
- int mID;
- EnvMode(int id) {
- mID = id;
- }
- }
-
-
+public class ProgramFragment extends Program {
ProgramFragment(int id, RenderScript rs) {
- super(rs);
- mID = id;
+ super(id, rs);
}
- public void bindTexture(Allocation va, int slot)
- throws IllegalArgumentException {
- mRS.validate();
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ public static class ShaderBuilder extends BaseProgramBuilder {
+ public ShaderBuilder(RenderScript rs) {
+ super(rs);
}
- mRS.nProgramFragmentBindTexture(mID, slot, va.mID);
- }
+ public ProgramFragment create() {
+ mRS.validate();
+ int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + 1) * 2];
+ int idx = 0;
- public void bindSampler(Sampler vs, int slot)
- throws IllegalArgumentException {
- mRS.validate();
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
- }
+ for (int i=0; i < mInputCount; i++) {
+ tmp[idx++] = 0;
+ tmp[idx++] = mInputs[i].mID;
+ }
+ for (int i=0; i < mOutputCount; i++) {
+ tmp[idx++] = 1;
+ tmp[idx++] = mOutputs[i].mID;
+ }
+ for (int i=0; i < mConstantCount; i++) {
+ tmp[idx++] = 2;
+ tmp[idx++] = mConstants[i].mID;
+ }
+ tmp[idx++] = 3;
+ tmp[idx++] = mTextureCount;
- mRS.nProgramFragmentBindSampler(mID, slot, vs.mID);
+ int id = mRS.nProgramFragmentCreate2(mShader, tmp);
+ ProgramFragment pf = new ProgramFragment(id, mRS);
+ initProgram(pf);
+ return pf;
+ }
}
-
public static class Builder {
+ public static final int MAX_TEXTURE = 2;
RenderScript mRS;
- Element mIn;
- Element mOut;
boolean mPointSpriteEnable;
- private class Slot {
- Type mType;
- EnvMode mEnv;
- boolean mTexEnable;
+ public enum EnvMode {
+ REPLACE (1),
+ MODULATE (2),
+ DECAL (3);
- Slot() {
- mTexEnable = false;
+ int mID;
+ EnvMode(int id) {
+ mID = id;
}
}
- Slot[] mSlots;
- public Builder(RenderScript rs, Element in, Element out) {
- mRS = rs;
- mIn = in;
- mOut = out;
- mSlots = new Slot[MAX_SLOT];
- mPointSpriteEnable = false;
- for(int ct=0; ct < MAX_SLOT; ct++) {
- mSlots[ct] = new Slot();
- }
- }
+ public enum Format {
+ ALPHA (1),
+ LUMINANCE_ALPHA (2),
+ RGB (3),
+ RGBA (4);
- public void setType(int slot, Type t)
- throws IllegalArgumentException {
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ int mID;
+ Format(int id) {
+ mID = id;
}
-
- mSlots[slot].mType = t;
}
- public void setTexEnable(boolean enable, int slot)
- throws IllegalArgumentException {
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ private class Slot {
+ EnvMode env;
+ Format format;
+ Slot(EnvMode _env, Format _fmt) {
+ env = _env;
+ format = _fmt;
}
+ }
+ Slot[] mSlots;
- mSlots[slot].mTexEnable = enable;
+ public Builder(RenderScript rs) {
+ mRS = rs;
+ mSlots = new Slot[MAX_TEXTURE];
+ mPointSpriteEnable = false;
}
- public void setTexEnvMode(EnvMode env, int slot)
+ public void setTexture(EnvMode env, Format fmt, int slot)
throws IllegalArgumentException {
- if((slot < 0) || (slot >= MAX_SLOT)) {
- throw new IllegalArgumentException("Slot ID out of range.");
+ if((slot < 0) || (slot >= MAX_TEXTURE)) {
+ throw new IllegalArgumentException("MAX_TEXTURE exceeded.");
}
-
- mSlots[slot].mEnv = env;
+ mSlots[slot] = new Slot(env, fmt);
}
public void setPointSpriteTexCoordinateReplacement(boolean enable) {
mPointSpriteEnable = enable;
}
- static synchronized ProgramFragment internalCreate(RenderScript rs, Builder b) {
- int inID = 0;
- int outID = 0;
- if (b.mIn != null) {
- inID = b.mIn.mID;
- }
- if (b.mOut != null) {
- outID = b.mOut.mID;
- }
- rs.nProgramFragmentBegin(inID, outID, b.mPointSpriteEnable);
- for(int ct=0; ct < MAX_SLOT; ct++) {
- if(b.mSlots[ct].mTexEnable) {
- Slot s = b.mSlots[ct];
- int typeID = 0;
- if(s.mType != null) {
- typeID = s.mType.mID;
- }
- rs.nProgramFragmentSetSlot(ct, true, s.mEnv.mID, typeID);
- }
- }
-
- int id = rs.nProgramFragmentCreate();
- return new ProgramFragment(id, rs);
- }
-
public ProgramFragment create() {
mRS.validate();
- return internalCreate(mRS, this);
+ int[] tmp = new int[MAX_TEXTURE * 2 + 1];
+ if (mSlots[0] != null) {
+ tmp[0] = mSlots[0].env.mID;
+ tmp[1] = mSlots[0].format.mID;
+ }
+ if (mSlots[1] != null) {
+ tmp[2] = mSlots[1].env.mID;
+ tmp[3] = mSlots[1].format.mID;
+ }
+ tmp[4] = mPointSpriteEnable ? 1 : 0;
+ int id = mRS.nProgramFragmentCreate(tmp);
+ ProgramFragment pf = new ProgramFragment(id, mRS);
+ pf.mTextureCount = MAX_TEXTURE;
+ return pf;
}
}
}
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index ba97d5be2240..84f6f2d03e17 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -25,72 +25,67 @@ import android.util.Log;
* @hide
*
**/
-public class ProgramVertex extends BaseObj {
+public class ProgramVertex extends Program {
public static final int MAX_LIGHT = 8;
+
ProgramVertex(int id, RenderScript rs) {
- super(rs);
- mID = id;
+ super(id, rs);
}
public void bindAllocation(MatrixAllocation va) {
mRS.validate();
- mRS.nProgramVertexBindAllocation(mID, va.mAlloc.mID);
+ bindConstants(va.mAlloc, 0);
}
public static class Builder {
RenderScript mRS;
- Element mIn;
- Element mOut;
- Light[] mLights;
- int mLightCount;
boolean mTextureMatrixEnable;
-
public Builder(RenderScript rs, Element in, Element out) {
mRS = rs;
- mIn = in;
- mOut = out;
- mLights = new Light[MAX_LIGHT];
- mLightCount = 0;
}
public void setTextureMatrixEnable(boolean enable) {
mTextureMatrixEnable = enable;
}
- public void addLight(Light l) throws IllegalStateException {
- if(mLightCount >= MAX_LIGHT) {
- throw new IllegalArgumentException("Max light count exceeded.");
- }
- mLights[mLightCount] = l;
- mLightCount++;
+ public ProgramVertex create() {
+ int id = mRS.nProgramVertexCreate(mTextureMatrixEnable);
+ return new ProgramVertex(id, mRS);
}
+ }
+ public static class ShaderBuilder extends BaseProgramBuilder {
+ public ShaderBuilder(RenderScript rs) {
+ super(rs);
+ }
+ public ProgramVertex create() {
+ mRS.validate();
+ int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount +1) * 2];
+ int idx = 0;
- static synchronized ProgramVertex internalCreate(RenderScript rs, Builder b) {
- int inID = 0;
- int outID = 0;
- if (b.mIn != null) {
- inID = b.mIn.mID;
+ for (int i=0; i < mInputCount; i++) {
+ tmp[idx++] = 0;
+ tmp[idx++] = mInputs[i].mID;
}
- if (b.mOut != null) {
- outID = b.mOut.mID;
+ for (int i=0; i < mOutputCount; i++) {
+ tmp[idx++] = 1;
+ tmp[idx++] = mOutputs[i].mID;
}
- rs.nProgramVertexBegin(inID, outID);
- for(int ct=0; ct < b.mLightCount; ct++) {
- rs.nProgramVertexAddLight(b.mLights[ct].mID);
+ for (int i=0; i < mConstantCount; i++) {
+ tmp[idx++] = 2;
+ tmp[idx++] = mConstants[i].mID;
}
- rs.nProgramVertexSetTextureMatrixEnable(b.mTextureMatrixEnable);
- int id = rs.nProgramVertexCreate();
- return new ProgramVertex(id, rs);
- }
+ tmp[idx++] = 3;
+ tmp[idx++] = mTextureCount;
- public ProgramVertex create() {
- mRS.validate();
- return internalCreate(mRS, this);
+ int id = mRS.nProgramVertexCreate2(mShader, tmp);
+ ProgramVertex pv = new ProgramVertex(id, mRS);
+ initProgram(pv);
+ return pv;
}
}
@@ -112,7 +107,7 @@ public class ProgramVertex extends BaseObj {
mProjection = new Matrix();
mTexture = new Matrix();
- mAlloc = Allocation.createSized(rs, Element.USER_F32(rs), 48);
+ mAlloc = Allocation.createSized(rs, Element.createUser(rs, Element.DataType.FLOAT_32), 48);
mAlloc.subData1D(MODELVIEW_OFFSET, 16, mModel.mMat);
mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat);
mAlloc.subData1D(TEXTURE_OFFSET, 16, mTexture.mMat);
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 0d8b6754d4ae..29361af583a7 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -76,8 +76,6 @@ public class RenderScript {
native void nContextBindProgramFragment(int pf);
native void nContextBindProgramVertex(int pf);
native void nContextBindProgramRaster(int pr);
- native void nContextAddDefineI32(String name, int value);
- native void nContextAddDefineF(String name, float value);
native void nContextPause();
native void nContextResume();
native int nContextGetMessage(int[] data, boolean wait);
@@ -89,9 +87,9 @@ public class RenderScript {
native void nObjDestroyOOB(int id);
native int nFileOpen(byte[] name);
- native void nElementBegin();
- native void nElementAdd(int kind, int type, boolean norm, int bits, String s);
- native int nElementCreate();
+
+ native int nElementCreate(int type, int kind, boolean norm, int vecSize);
+ native int nElementCreate2(int[] elements, String[] names);
native void nTypeBegin(int elementID);
native void nTypeAdd(int dim, int val);
@@ -167,17 +165,15 @@ public class RenderScript {
native void nProgramRasterSetLineWidth(int pr, float v);
native void nProgramRasterSetPointSize(int pr, float v);
- native void nProgramFragmentBegin(int in, int out, boolean pointSpriteEnable);
- native void nProgramFragmentBindTexture(int vpf, int slot, int a);
- native void nProgramFragmentBindSampler(int vpf, int slot, int s);
- native void nProgramFragmentSetSlot(int slot, boolean enable, int env, int vt);
- native int nProgramFragmentCreate();
+ native void nProgramBindConstants(int pv, int slot, int mID);
+ native void nProgramBindTexture(int vpf, int slot, int a);
+ native void nProgramBindSampler(int vpf, int slot, int s);
+
+ native int nProgramFragmentCreate(int[] params);
+ native int nProgramFragmentCreate2(String shader, int[] params);
- native void nProgramVertexBindAllocation(int pv, int mID);
- native void nProgramVertexBegin(int inID, int outID);
- native void nProgramVertexSetTextureMatrixEnable(boolean enable);
- native void nProgramVertexAddLight(int id);
- native int nProgramVertexCreate();
+ native int nProgramVertexCreate(boolean texMat);
+ native int nProgramVertexCreate2(String shader, int[] params);
native void nLightBegin();
native void nLightSetIsMono(boolean isMono);
@@ -200,14 +196,13 @@ public class RenderScript {
private Surface mSurface;
private MessageThread mMessageThread;
-
Element mElement_USER_U8;
Element mElement_USER_I8;
Element mElement_USER_U16;
Element mElement_USER_I16;
Element mElement_USER_U32;
Element mElement_USER_I32;
- Element mElement_USER_FLOAT;
+ Element mElement_USER_F32;
Element mElement_A_8;
Element mElement_RGB_565;
@@ -217,9 +212,12 @@ public class RenderScript {
Element mElement_RGBA_8888;
Element mElement_INDEX_16;
- Element mElement_XY_F32;
- Element mElement_XYZ_F32;
-
+ Element mElement_POSITION_2;
+ Element mElement_POSITION_3;
+ Element mElement_TEXTURE_2;
+ Element mElement_NORMAL_3;
+ Element mElement_COLOR_U8_4;
+ Element mElement_COLOR_F32_4;
///////////////////////////////////////////////////////////////////////////////////
//
@@ -248,13 +246,8 @@ public class RenderScript {
}
}
- void validateSurface() {
- if (mSurface == null) {
- throw new IllegalStateException("Uploading data to GL with no surface.");
- }
- }
-
public void contextSetPriority(Priority p) {
+ validate();
nContextSetPriority(p.mID);
}
@@ -305,23 +298,26 @@ public class RenderScript {
nDeviceSetConfig(mDev, 0, 1);
}
mContext = nContextCreate(mDev, 0, useDepth);
- Element.initPredefined(this);
mMessageThread = new MessageThread(this);
mMessageThread.start();
+ Element.initPredefined(this);
}
public void contextSetSurface(int w, int h, Surface sur) {
mSurface = sur;
mWidth = w;
mHeight = h;
+ validate();
nContextSetSurface(w, h, mSurface);
}
public void contextDump(int bits) {
+ validate();
nContextDump(bits);
}
public void destroy() {
+ validate();
nContextDeinitToClient();
mMessageThread.mRun = false;
@@ -337,10 +333,12 @@ public class RenderScript {
}
void pause() {
+ validate();
nContextPause();
}
void resume() {
+ validate();
nContextResume();
}
@@ -381,22 +379,27 @@ public class RenderScript {
}
public void contextBindRootScript(Script s) {
+ validate();
nContextBindRootScript(safeID(s));
}
public void contextBindProgramFragmentStore(ProgramStore p) {
+ validate();
nContextBindProgramFragmentStore(safeID(p));
}
public void contextBindProgramFragment(ProgramFragment p) {
+ validate();
nContextBindProgramFragment(safeID(p));
}
public void contextBindProgramRaster(ProgramRaster p) {
+ validate();
nContextBindProgramRaster(safeID(p));
}
public void contextBindProgramVertex(ProgramVertex p) {
+ validate();
nContextBindProgramVertex(safeID(p));
}
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 625a5760c85f..40ba7225f95e 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -69,23 +69,45 @@ public class Sampler extends BaseObj {
}
public void setMin(Value v) {
- mMin = v;
+ if (v == Value.NEAREST ||
+ v == Value.LINEAR ||
+ v == Value.LINEAR_MIP_LINEAR) {
+ mMin = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setMag(Value v) {
- mMag = v;
+ if (v == Value.NEAREST || v == Value.LINEAR) {
+ mMag = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setWrapS(Value v) {
- mWrapS = v;
+ if (v == Value.WRAP || v == Value.CLAMP) {
+ mWrapS = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setWrapT(Value v) {
- mWrapT = v;
+ if (v == Value.WRAP || v == Value.CLAMP) {
+ mWrapT = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
public void setWrapR(Value v) {
- mWrapR = v;
+ if (v == Value.WRAP || v == Value.CLAMP) {
+ mWrapR = v;
+ } else {
+ throw new IllegalArgumentException("Invalid value");
+ }
}
static synchronized Sampler internalCreate(RenderScript rs, Builder b) {
diff --git a/graphics/java/android/renderscript/SimpleMesh.java b/graphics/java/android/renderscript/SimpleMesh.java
index f45074e23b24..4a217a9e4d68 100644
--- a/graphics/java/android/renderscript/SimpleMesh.java
+++ b/graphics/java/android/renderscript/SimpleMesh.java
@@ -313,28 +313,36 @@ public class SimpleMesh extends BaseObj {
public SimpleMesh create() {
Element.Builder b = new Element.Builder(mRS);
int floatCount = mVtxSize;
- if (mVtxSize == 2) {
- b.addFloatXY();
- } else {
- b.addFloatXYZ();
- }
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.POSITION,
+ mVtxSize), "position");
if ((mFlags & COLOR) != 0) {
floatCount += 4;
- b.addFloatRGBA();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.COLOR,
+ 4), "color");
}
if ((mFlags & TEXTURE_0) != 0) {
floatCount += 2;
- b.addFloatST();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.TEXTURE,
+ 2), "texture");
}
if ((mFlags & NORMAL) != 0) {
floatCount += 3;
- b.addFloatNorm();
+ b.add(Element.createAttrib(mRS,
+ Element.DataType.FLOAT_32,
+ Element.DataKind.NORMAL,
+ 3), "normal");
}
mElement = b.create();
Builder smb = new Builder(mRS);
smb.addVertexType(mElement, mVtxCount / floatCount);
- smb.setIndexType(Element.INDEX_16(mRS), mIndexCount);
+ smb.setIndexType(Element.createIndex(mRS), mIndexCount);
smb.setPrimitive(Primitive.TRIANGLE);
SimpleMesh sm = smb.create();
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index ad4cf6be5381..62d3867ceec9 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -34,6 +34,9 @@ public class Type extends BaseObj {
private int mNativeCache;
Class mJavaClass;
+ public Element getElement() {
+ return mElement;
+ }
public int getX() {
return mDimX;
@@ -122,16 +125,16 @@ public class Type extends BaseObj {
Field f = fields[ct];
Class fc = f.getType();
if(fc == int.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_32.mID;
arBits[ct] = 32;
} else if(fc == short.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_16.mID;
arBits[ct] = 16;
} else if(fc == byte.class) {
- arTypes[ct] = Element.DataType.SIGNED.mID;
+ arTypes[ct] = Element.DataType.SIGNED_8.mID;
arBits[ct] = 8;
} else if(fc == float.class) {
- arTypes[ct] = Element.DataType.FLOAT.mID;
+ arTypes[ct] = Element.DataType.FLOAT_32.mID;
arBits[ct] = 32;
} else {
throw new IllegalArgumentException("Unkown field type");
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index af3bc7430a33..7ded133b0325 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;
@@ -1056,87 +1057,89 @@ nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this)
// ---------------------------------------------------------------------------
static void
-nProgramFragmentBegin(JNIEnv *_env, jobject _this, jint in, jint out, jboolean pointSpriteEnable)
+nProgramBindConstants(JNIEnv *_env, jobject _this, jint vpv, jint slot, jint a)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentBegin, con(%p), in(%p), out(%p) PointSprite(%i)", con, (RsElement)in, (RsElement)out, pointSpriteEnable);
- rsProgramFragmentBegin(con, (RsElement)in, (RsElement)out, pointSpriteEnable);
+ LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
+ rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a);
}
static void
-nProgramFragmentBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
+nProgramBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
- rsProgramFragmentBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
+ LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
+ rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
}
static void
-nProgramFragmentBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
+nProgramBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
- rsProgramFragmentBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
+ LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a);
+ rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a);
}
-static void
-nProgramFragmentSetSlot(JNIEnv *_env, jobject _this, jint slot, jboolean enable, jint env, jint vt)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentSetType, con(%p), slot(%i), enable(%i), env(%i), vt(%p)", con, slot, enable, env, (RsType)vt);
- rsProgramFragmentSetSlot(con, slot, enable, (RsTexEnvMode)env, (RsType)vt);
-}
+// ---------------------------------------------------------------------------
static jint
-nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable)
+nProgramFragmentCreate(JNIEnv *_env, jobject _this, jintArray params)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramFragmentCreate, con(%p)", con);
- return (jint)rsProgramFragmentCreate(con);
-}
+ jint *paramPtr = _env->GetIntArrayElements(params, NULL);
+ jint paramLen = _env->GetArrayLength(params);
-// ---------------------------------------------------------------------------
+ LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, shaderLen, paramLen);
-static void
-nProgramVertexBegin(JNIEnv *_env, jobject _this, jint in, jint out)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
- rsProgramVertexBegin(con, (RsElement)in, (RsElement)out);
+ jint ret = (jint)rsProgramFragmentCreate(con, (uint32_t *)paramPtr, paramLen);
+ _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
+ return ret;
}
-static void
-nProgramVertexBindAllocation(JNIEnv *_env, jobject _this, jint vpv, jint a)
+static jint
+nProgramFragmentCreate2(JNIEnv *_env, jobject _this, jstring shader, jintArray params)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexBindAllocation, con(%p), vpf(%p), a(%p)", con, (RsProgramVertex)vpv, (RsAllocation)a);
- rsProgramVertexBindAllocation(con, (RsProgramFragment)vpv, (RsAllocation)a);
-}
+ const char* shaderUTF = _env->GetStringUTFChars(shader, NULL);
+ jint shaderLen = _env->GetStringUTFLength(shader);
+ jint *paramPtr = _env->GetIntArrayElements(params, NULL);
+ jint paramLen = _env->GetArrayLength(params);
-static void
-nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexSetTextureMatrixEnable, con(%p), enable(%i)", con, enable);
- rsProgramVertexSetTextureMatrixEnable(con, enable);
+ LOG_API("nProgramFragmentCreate2, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen);
+
+ jint ret = (jint)rsProgramFragmentCreate2(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen);
+ _env->ReleaseStringUTFChars(shader, shaderUTF);
+ _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
+ return ret;
}
-static void
-nProgramVertexAddLight(JNIEnv *_env, jobject _this, jint light)
+
+// ---------------------------------------------------------------------------
+
+static jint
+nProgramVertexCreate(JNIEnv *_env, jobject _this, jboolean texMat)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexAddLight, con(%p), light(%p)", con, (RsLight)light);
- rsProgramVertexAddLight(con, (RsLight)light);
+ LOG_API("nProgramVertexCreate, con(%p), texMat(%i)", con, texMat);
+ return (jint)rsProgramVertexCreate(con, texMat);
}
static jint
-nProgramVertexCreate(JNIEnv *_env, jobject _this)
+nProgramVertexCreate2(JNIEnv *_env, jobject _this, jstring shader, jintArray params)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexCreate, con(%p)", con);
- return (jint)rsProgramVertexCreate(con);
-}
+ const char* shaderUTF = _env->GetStringUTFChars(shader, NULL);
+ jint shaderLen = _env->GetStringUTFLength(shader);
+ jint *paramPtr = _env->GetIntArrayElements(params, NULL);
+ jint paramLen = _env->GetArrayLength(params);
+
+ LOG_API("nProgramVertexCreate2, con(%p), shaderLen(%i), paramLen(%i)", con, shaderLen, paramLen);
+ jint ret = (jint)rsProgramVertexCreate2(con, shaderUTF, shaderLen, (uint32_t *)paramPtr, paramLen);
+ _env->ReleaseStringUTFChars(shader, shaderUTF);
+ _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT);
+ return ret;
+}
// ---------------------------------------------------------------------------
@@ -1209,26 +1212,6 @@ nContextBindProgramRaster(JNIEnv *_env, jobject _this, jint pf)
rsContextBindProgramRaster(con, (RsProgramRaster)pf);
}
-static void
-nContextAddDefineI32(JNIEnv *_env, jobject _this, jstring name, jint value)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- const char* n = _env->GetStringUTFChars(name, NULL);
- LOG_API("nScriptCAddDefineI32, con(%p) name(%s) value(%d)", con, n, value);
- rsContextSetDefineI32(con, n, value);
- _env->ReleaseStringUTFChars(name, n);
-}
-
-static void
-nContextAddDefineF(JNIEnv *_env, jobject _this, jstring name, jfloat value)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- const char* n = _env->GetStringUTFChars(name, NULL);
- LOG_API("nScriptCAddDefineF, con(%p) name(%s) value(%f)", con, n, value);
- rsContextSetDefineF(con, n, value);
- _env->ReleaseStringUTFChars(name, n);
-}
-
// ---------------------------------------------------------------------------
@@ -1365,9 +1348,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 },
@@ -1432,21 +1414,19 @@ static JNINativeMethod methods[] = {
{"nProgramFragmentStoreDither", "(Z)V", (void*)nProgramFragmentStoreDither },
{"nProgramFragmentStoreCreate", "()I", (void*)nProgramFragmentStoreCreate },
-{"nProgramFragmentBegin", "(IIZ)V", (void*)nProgramFragmentBegin },
-{"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture },
-{"nProgramFragmentBindSampler", "(III)V", (void*)nProgramFragmentBindSampler },
-{"nProgramFragmentSetSlot", "(IZII)V", (void*)nProgramFragmentSetSlot },
-{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate },
+{"nProgramBindConstants", "(III)V", (void*)nProgramBindConstants },
+{"nProgramBindTexture", "(III)V", (void*)nProgramBindTexture },
+{"nProgramBindSampler", "(III)V", (void*)nProgramBindSampler },
+
+{"nProgramFragmentCreate", "([I)I", (void*)nProgramFragmentCreate },
+{"nProgramFragmentCreate2", "(Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate2 },
{"nProgramRasterCreate", "(IIZZZ)I", (void*)nProgramRasterCreate },
{"nProgramRasterSetPointSize", "(IF)V", (void*)nProgramRasterSetPointSize },
{"nProgramRasterSetLineWidth", "(IF)V", (void*)nProgramRasterSetLineWidth },
-{"nProgramVertexBindAllocation", "(II)V", (void*)nProgramVertexBindAllocation },
-{"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin },
-{"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable },
-{"nProgramVertexAddLight", "(I)V", (void*)nProgramVertexAddLight },
-{"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate },
+{"nProgramVertexCreate", "(Z)I", (void*)nProgramVertexCreate },
+{"nProgramVertexCreate2", "(Ljava/lang/String;[I)I", (void*)nProgramVertexCreate2 },
{"nLightBegin", "()V", (void*)nLightBegin },
{"nLightSetIsMono", "(Z)V", (void*)nLightSetIsMono },
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index d36427763c22..88521f620325 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -96,11 +96,14 @@ LOCAL_SRC_FILES:= \
rsScript.cpp \
rsScriptC.cpp \
rsScriptC_Lib.cpp \
+ rsShaderCache.cpp \
rsSimpleMesh.cpp \
rsThreadIO.cpp \
- rsType.cpp
+ rsType.cpp \
+ rsVertexArray.cpp
-LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libui libacc
+
+LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libacc
LOCAL_LDLIBS := -lpthread -ldl
LOCAL_MODULE:= libRS
LOCAL_MODULE_TAGS := optional
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 3ca8b158c8b7..6662333d7420 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -36,11 +36,11 @@ typedef void * RsElement;
typedef void * RsFile;
typedef void * RsSampler;
typedef void * RsScript;
-typedef void * RsScriptBasicTemp;
typedef void * RsSimpleMesh;
typedef void * RsType;
typedef void * RsLight;
+typedef void * RsProgram;
typedef void * RsProgramVertex;
typedef void * RsProgramFragment;
typedef void * RsProgramFragmentStore;
@@ -64,34 +64,53 @@ void rsContextInitToClient(RsContext);
void rsContextDeinitToClient(RsContext);
#define RS_MAX_TEXTURE 2
+#define RS_MAX_ATTRIBS 16
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 {
@@ -158,11 +177,19 @@ enum RsBlendDstFunc {
};
enum RsTexEnvMode {
+ RS_TEX_ENV_MODE_NONE,
RS_TEX_ENV_MODE_REPLACE,
RS_TEX_ENV_MODE_MODULATE,
RS_TEX_ENV_MODE_DECAL
};
+enum RsProgramParam {
+ RS_PROGRAM_PARAM_INPUT,
+ RS_PROGRAM_PARAM_OUTPUT,
+ RS_PROGRAM_PARAM_CONSTANT,
+ RS_PROGRAM_PARAM_TEXTURE_COUNT,
+};
+
enum RsPrimitive {
RS_PRIMITIVE_POINT,
RS_PRIMITIVE_LINE,
diff --git a/libs/rs/RenderScriptEnv.h b/libs/rs/RenderScriptEnv.h
index ff0a7b15e3cb..99b8c0456f04 100644
--- a/libs/rs/RenderScriptEnv.h
+++ b/libs/rs/RenderScriptEnv.h
@@ -9,7 +9,6 @@ typedef void * RsDevice;
typedef void * RsElement;
typedef void * RsSampler;
typedef void * RsScript;
-typedef void * RsScriptBasicTemp;
typedef void * RsSimpleMesh;
typedef void * RsType;
typedef void * RsProgramFragment;
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 b5b6723be179..b80e619a5b7e 100644
--- a/libs/rs/java/Film/src/com/android/film/FilmRS.java
+++ b/libs/rs/java/Film/src/com/android/film/FilmRS.java
@@ -121,13 +121,13 @@ public class FilmRS {
bs.setWrapT(Sampler.Value.WRAP);
mSampler = bs.create();
- ProgramFragment.Builder b = new ProgramFragment.Builder(mRS, null, null);
-
+ ProgramFragment.Builder b = new ProgramFragment.Builder(mRS);
mPFBackground = b.create();
mPFBackground.setName("PFBackground");
- b.setTexEnable(true, 0);
- b.setTexEnvMode(ProgramFragment.EnvMode.REPLACE, 0);
+ b = new ProgramFragment.Builder(mRS);
+ b.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
+ ProgramFragment.Builder.Format.RGBA, 0);
mPFImages = b.create();
mPFImages.bindSampler(mSampler, 0);
mPFImages.setName("PFImages");
@@ -138,7 +138,7 @@ public class FilmRS {
mLight.setPosition(0, -0.5f, -1.0f);
ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
- pvb.addLight(mLight);
+ //pvb.addLight(mLight);
mPVBackground = pvb.create();
mPVBackground.setName("PVBackground");
@@ -152,9 +152,10 @@ 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);
mImages[0] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p01, ie, true);
mImages[1] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p02, ie, true);
mImages[2] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p03, ie, true);
@@ -195,7 +196,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 +240,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/Film/src/com/android/film/FilmView.java b/libs/rs/java/Film/src/com/android/film/FilmView.java
index 1c5b2bc1f8c3..4a201fd8dd7a 100644
--- a/libs/rs/java/Film/src/com/android/film/FilmView.java
+++ b/libs/rs/java/Film/src/com/android/film/FilmView.java
@@ -42,19 +42,29 @@ public class FilmView extends RSSurfaceView {
public FilmView(Context context) {
super(context);
-
//setFocusable(true);
}
private RenderScript mRS;
private FilmRS mRender;
+
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
+ if (mRS == null) {
+ mRS = createRenderScript(true);
+ mRS.contextSetSurface(w, h, holder.getSurface());
+ mRender = new FilmRS();
+ mRender.init(mRS, getResources(), w, h);
+ }
+ }
- mRS = createRenderScript(true);
- mRender = new FilmRS();
- mRender.init(mRS, getResources(), w, h);
+ @Override
+ protected void onDetachedFromWindow() {
+ if(mRS != null) {
+ mRS = null;
+ destroyRenderScript();
+ }
}
@Override
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index f218f9bfba57..73b819b3df86 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 f4f9b0cc76a5..71f95a7fc31c 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/Fountain/src/com/android/fountain/FountainView.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
index 1e7c5a2f047e..fcb93f432d43 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
@@ -51,7 +51,7 @@ public class FountainView extends RSSurfaceView {
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
if (mRS == null) {
- mRS = createRenderScript(false, true);
+ mRS = createRenderScript(false);
mRS.contextSetSurface(w, h, holder.getSurface());
mRender = new FountainRS();
mRender.init(mRS, getResources(), w, h);
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 334fd9c356fa..0ca00b3353fa 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/java/Rollo/Android.mk b/libs/rs/java/Rollo/Android.mk
deleted file mode 100644
index 5a4957c491d5..000000000000
--- a/libs/rs/java/Rollo/Android.mk
+++ /dev/null
@@ -1,25 +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.
-#
-
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
-
-LOCAL_PACKAGE_NAME := Rollo
-
-include $(BUILD_PACKAGE)
diff --git a/libs/rs/java/Rollo/AndroidManifest.xml b/libs/rs/java/Rollo/AndroidManifest.xml
deleted file mode 100644
index 12cb28f976d9..000000000000
--- a/libs/rs/java/Rollo/AndroidManifest.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.rollo">
- <application
- android:label="Rollo"
- android:icon="@drawable/test_pattern">
- <activity android:name="Rollo"
- android:theme="@android:style/Theme.Translucent"
- android:icon="@drawable/test_pattern">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-</manifest>
diff --git a/libs/rs/java/Rollo/res/drawable/test_pattern.png b/libs/rs/java/Rollo/res/drawable/test_pattern.png
deleted file mode 100644
index e7d145554c00..000000000000
--- a/libs/rs/java/Rollo/res/drawable/test_pattern.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/browser.png b/libs/rs/java/Rollo/res/raw/browser.png
deleted file mode 100644
index 513f0be49693..000000000000
--- a/libs/rs/java/Rollo/res/raw/browser.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/calendar.png b/libs/rs/java/Rollo/res/raw/calendar.png
deleted file mode 100644
index 030ae73d572c..000000000000
--- a/libs/rs/java/Rollo/res/raw/calendar.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/g1155.png b/libs/rs/java/Rollo/res/raw/g1155.png
deleted file mode 100644
index 68e1843a63e0..000000000000
--- a/libs/rs/java/Rollo/res/raw/g1155.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/g2140.png b/libs/rs/java/Rollo/res/raw/g2140.png
deleted file mode 100644
index 8c4e85333dec..000000000000
--- a/libs/rs/java/Rollo/res/raw/g2140.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/maps.png b/libs/rs/java/Rollo/res/raw/maps.png
deleted file mode 100644
index fd5fc39037c6..000000000000
--- a/libs/rs/java/Rollo/res/raw/maps.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/market.png b/libs/rs/java/Rollo/res/raw/market.png
deleted file mode 100644
index 83b6910fcdec..000000000000
--- a/libs/rs/java/Rollo/res/raw/market.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path1920.png b/libs/rs/java/Rollo/res/raw/path1920.png
deleted file mode 100644
index 3510665cb683..000000000000
--- a/libs/rs/java/Rollo/res/raw/path1920.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path1927.png b/libs/rs/java/Rollo/res/raw/path1927.png
deleted file mode 100644
index fccc84613104..000000000000
--- a/libs/rs/java/Rollo/res/raw/path1927.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path3099.png b/libs/rs/java/Rollo/res/raw/path3099.png
deleted file mode 100644
index 527ebf6f681f..000000000000
--- a/libs/rs/java/Rollo/res/raw/path3099.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path3950.png b/libs/rs/java/Rollo/res/raw/path3950.png
deleted file mode 100644
index 59a646ae6be2..000000000000
--- a/libs/rs/java/Rollo/res/raw/path3950.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path431.png b/libs/rs/java/Rollo/res/raw/path431.png
deleted file mode 100644
index 5d2ed75bb635..000000000000
--- a/libs/rs/java/Rollo/res/raw/path431.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path4481.png b/libs/rs/java/Rollo/res/raw/path4481.png
deleted file mode 100644
index 78be0fcb7969..000000000000
--- a/libs/rs/java/Rollo/res/raw/path4481.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path5168.png b/libs/rs/java/Rollo/res/raw/path5168.png
deleted file mode 100644
index a7c3a19eb999..000000000000
--- a/libs/rs/java/Rollo/res/raw/path5168.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path676.png b/libs/rs/java/Rollo/res/raw/path676.png
deleted file mode 100644
index 209969077307..000000000000
--- a/libs/rs/java/Rollo/res/raw/path676.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path754.png b/libs/rs/java/Rollo/res/raw/path754.png
deleted file mode 100644
index 88aed5b86e44..000000000000
--- a/libs/rs/java/Rollo/res/raw/path754.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/path815.png b/libs/rs/java/Rollo/res/raw/path815.png
deleted file mode 100644
index 407570f80adf..000000000000
--- a/libs/rs/java/Rollo/res/raw/path815.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/photos.png b/libs/rs/java/Rollo/res/raw/photos.png
deleted file mode 100644
index 1ed8f1e811ad..000000000000
--- a/libs/rs/java/Rollo/res/raw/photos.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/polygon2408.png b/libs/rs/java/Rollo/res/raw/polygon2408.png
deleted file mode 100644
index 4413954f7e19..000000000000
--- a/libs/rs/java/Rollo/res/raw/polygon2408.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/res/raw/rollo.c b/libs/rs/java/Rollo/res/raw/rollo.c
deleted file mode 100644
index b31be81aac14..000000000000
--- a/libs/rs/java/Rollo/res/raw/rollo.c
+++ /dev/null
@@ -1,184 +0,0 @@
-#pragma version(1)
-#pragma stateVertex(PV)
-#pragma stateFragment(PF)
-#pragma stateStore(PFS)
-
-// Scratch buffer layout
-#define SCRATCH_FADE 0
-#define SCRATCH_ZOOM 1
-#define SCRATCH_ROT 2
-
-//#define STATE_POS_X 0
-#define STATE_DONE 1
-//#define STATE_PRESSURE 2
-#define STATE_ZOOM 3
-//#define STATE_WARP 4
-#define STATE_ORIENTATION 5
-#define STATE_SELECTION 6
-#define STATE_FIRST_VISIBLE 7
-#define STATE_COUNT 8
-#define STATE_TOUCH 9
-
-
-float filter(float val, float target, float str)
-{
- float delta = (target - val);
- return val + delta * str;
-}
-
-int main(void* con, int ft, int launchID)
-{
- int rowCount;
- int row;
- int col;
- int imageID;
- int done = loadI32(0, STATE_DONE);
- int selectedID = loadI32(0, STATE_SELECTION);
-
- float f = loadF(2, 0);
-
- pfClearColor(0.0f, 0.0f, 0.0f, f);
- if (done) {
- if (f > 0.02f) {
- //f = f - 0.02f;
- //storeF(2, 0, f);
- }
- } else {
- if (f < 0.8f) {
- f = f + 0.02f;
- storeF(2, 0, f);
- }
- }
-
- float touchCut = 1.f;
- if (loadI32(0, STATE_TOUCH)) {
- touchCut = 4.f;
- }
-
-
- float targetZoom = ((float)loadI32(0, STATE_ZOOM)) / 1000.f;
- float zoom = filter(loadF(2, SCRATCH_ZOOM), targetZoom, 0.15 * touchCut);
- storeF(2, SCRATCH_ZOOM, zoom);
-
- float targetRot = loadI32(0, STATE_FIRST_VISIBLE) / 180.0f * 3.14f;
- targetRot = targetRot * 0.80f - .12f;
- float drawRot = filter(loadF(2, SCRATCH_ROT), targetRot, 0.1f * touchCut);
- storeF(2, SCRATCH_ROT, drawRot);
-
- float diam = 8.f;
- float scale = 1.0f / zoom;
-
- // Bug makes 1.0f alpha fail.
- color(1.0f, 1.0f, 1.0f, 0.99f);
-
- float rot = drawRot * scale;
- float rotStep = 16.0f / 180.0f * 3.14f * scale;
- rowCount = 4;
- int index = 0;
- int iconCount = loadI32(0, STATE_COUNT);
- while (iconCount) {
- float tmpSin = sinf(rot);
- float tmpCos = cosf(rot);
- //debugF("rot", rot);
-
- float tx1 = tmpSin * diam - (tmpCos * scale * 0.9f);
- float tx2 = tx1 + (tmpCos * scale * 1.8f);
- float tz1 = tmpCos * diam + (tmpSin * scale * 0.9f);
- float tz2 = tz1 - (tmpSin * scale * 1.8f);
-
- int y;
- for (y = rowCount -1; (y >= 0) && iconCount; y--) {
- float ty1 = ((y * 3.1f) - 5.f) * scale;
- float ty2 = ty1 + scale * 1.8f;
- bindTexture(NAMED_PF, 0, loadI32(1, index));
- drawQuad(tx1, ty1, tz1,
- tx2, ty1, tz2,
- tx2, ty2, tz2,
- tx1, ty2, tz1);
-
- iconCount--;
- index++;
- }
- rot = rot + rotStep;
- }
-
- if ((zoom < 1.1f) && (zoom > 0.9f)) {
- bindProgramVertex(NAMED_PVOrtho);
- bindProgramFragment(NAMED_PFText);
- bindProgramStore(NAMED_PFSText);
-
- rot = drawRot * scale;
- index = 0;
- iconCount = loadI32(0, STATE_COUNT);
- while (iconCount) {
- int y;
-
- float tx = 240.f + floorf(sinf(rot) * 430.f) - 64.f + 16.f;
-
- float alpha = 2.4f - (fabsf(tx - 240.f + 48.f) / 76.f);
- if (alpha > 0.99f) {
- alpha = 0.99f;
- }
- alpha = alpha * (1.f - (fabsf(zoom - 1.f) * 10.f));
-
- tx = tx + 0.25f;
-
- for (y = rowCount -1; (y >= 0) && iconCount; y--) {
-
- if (alpha > 0) {
- color(1.0f, 1.0f, 1.0f, alpha);
-
- float ty = 605.f - y * 150.f;
-
- ty = ty + 0.25f;
-
- bindTexture(NAMED_PFText, 0, loadI32(3, index));
- drawRect(tx, ty, tx + 128.f, ty + 32.f, 0.5f);
- }
- iconCount--;
- index++;
- }
- rot = rot + rotStep;
- }
-
-
- bindProgramVertex(NAMED_PV);
- bindProgramFragment(NAMED_PF);
- bindProgramStore(NAMED_PFS);
- }
-
- // Draw the selected icon
- color(1.0f, 1.0f, 1.0f, 0.9f);
- rot = drawRot * scale;
- index = 0;
- iconCount = loadI32(0, STATE_COUNT);
- while (iconCount) {
- int y;
- for (y = rowCount -1; (y >= 0) && iconCount; y--) {
- if (index == selectedID) {
-
- float tmpSin = sinf(rot) * scale;
- float tmpCos = cosf(rot) * scale;
- float tx1 = tmpSin * diam * 0.9f - tmpCos * 2.f;
- float tx2 = tx1 + (tmpCos * 4.f);
- float tz1 = tmpCos * diam * 0.9f + tmpSin * 2.f;
- float tz2 = tz1 - (tmpSin * 4.f);
-
- float ty1 = ((y * 3.1f) - 4.5f) * scale;
- float ty2 = ty1 + scale * 4.f;
- bindTexture(NAMED_PF, 0, loadI32(1, index));
- drawQuad(tx1, ty1, tz1,
- tx2, ty1, tz2,
- tx2, ty2, tz2,
- tx1, ty2, tz1);
- }
- iconCount--;
- index++;
- }
- rot = rot + rotStep;
- }
-
- return 1;
-}
-
-
diff --git a/libs/rs/java/Rollo/res/raw/rollo2.c b/libs/rs/java/Rollo/res/raw/rollo2.c
deleted file mode 100644
index 5b5cb2d382ba..000000000000
--- a/libs/rs/java/Rollo/res/raw/rollo2.c
+++ /dev/null
@@ -1,155 +0,0 @@
-#pragma version(1)
-#pragma stateVertex(PV)
-#pragma stateFragment(PF)
-#pragma stateStore(PFS)
-
-// Scratch buffer layout
-#define SCRATCH_FADE 0
-#define SCRATCH_ZOOM 1
-#define SCRATCH_ROT 2
-
-//#define STATE_POS_X 0
-#define STATE_DONE 1
-//#define STATE_PRESSURE 2
-#define STATE_ZOOM 3
-//#define STATE_WARP 4
-#define STATE_ORIENTATION 5
-#define STATE_SELECTION 6
-#define STATE_FIRST_VISIBLE 7
-#define STATE_COUNT 8
-#define STATE_TOUCH 9
-
-float filter(float val, float target, float str)
-{
- float delta = (target - val);
- return val + delta * str;
-}
-
-
-int main(void* con, int ft, int launchID)
-{
- int rowCount;
- int imageID;
- int done = loadI32(0, STATE_DONE);
- int selectedID = loadI32(0, STATE_SELECTION);
- int iconCount = loadI32(0, STATE_COUNT);
-
- float f = loadF(2, 0);
-
- float iconSize = 1.f;
- float iconSpacing = 0.2f;
- float z = 4.f;
-
- pfClearColor(0.0f, 0.0f, 0.0f, f);
- if (done) {
- } else {
- if (f < 0.8f) {
- f = f + 0.02f;
- storeF(2, 0, f);
- }
- }
-
- float touchCut = 1.f;
- if (loadI32(0, STATE_TOUCH)) {
- touchCut = 5.f;
- }
-
-
- float targetZoom = ((float)loadI32(0, STATE_ZOOM)) / 1000.f;
- float zoom = filter(loadF(2, SCRATCH_ZOOM), targetZoom, 0.15 * touchCut);
- storeF(2, SCRATCH_ZOOM, zoom);
-
- float targetPos = loadI32(0, STATE_FIRST_VISIBLE) / (-20.0f);
- float pos = filter(loadF(2, SCRATCH_ROT), targetPos, 0.1f * touchCut);
- storeF(2, SCRATCH_ROT, pos);
- pos = pos - 1.f;
-
- color(1.0f, 1.0f, 1.0f, 1.0f);
-
-
- // Draw flat icons first
- int index = ((int)pos) * 4;
- int row;
- int col;
- float xoffset = -0.3f;
- float gridSize = iconSize * 4.f + iconSpacing * 3.f;
- float yoffset = (pos - ((int)pos));
- for (row = 0; row < 4; row ++) {
- float ty1 = (gridSize / 2.f) - ((float)row - yoffset) * (iconSize + iconSpacing) - iconSize;
- float ty2 = ty1 + iconSize;
-
- for (col = 0; (col < 4) && (index < iconCount); col ++) {
- if (index >= 0) {
- bindTexture(NAMED_PF, 0, loadI32(1, index));
- float fcol = col;
- float tx1 = xoffset + (-gridSize / 2.f) + (fcol * (iconSize + iconSpacing));
- float tx2 = tx1 + iconSize;
-
- drawQuad(tx1, ty1, z,
- tx2, ty1, z,
- tx2, ty2, z,
- tx1, ty2, z);
- }
- index++;
- }
- }
-
- // bottom roller
- {
- float roll = (1.f - yoffset) * 0.5f * 3.14f;
- float tmpSin = sinf(roll);
- float tmpCos = cosf(roll);
-
- for (col = 0; (col < 4) && (index < iconCount) && (index >= 0); col ++) {
- float ty2 = (gridSize / 2.f) - ((float)row - yoffset) * (iconSize + iconSpacing);
- float ty1 = ty2 - tmpCos * iconSize;
-
- float tz1 = z + tmpSin * iconSize;
- float tz2 = z;
-
- float tx1 = xoffset + (-gridSize / 2.f) + ((float)col * (iconSize + iconSpacing));
- float tx2 = tx1 + iconSize;
-
- bindTexture(NAMED_PF, 0, loadI32(1, index));
- drawQuad(tx1, ty1, tz1,
- tx2, ty1, tz1,
- tx2, ty2, tz2,
- tx1, ty2, tz2);
- index++;
- }
- }
-
- // Top roller
- {
- index = (((int)pos) * 4) - 4;
- float roll = yoffset * 0.5f * 3.14f;
- float tmpSin = sinf(roll);
- float tmpCos = cosf(roll);
-
- for (col = 0; (col < 4) && (index < iconCount) && (index >= 0); col ++) {
- float ty1 = (gridSize / 2.f) - ((float)-1.f - yoffset) * (iconSize + iconSpacing) - iconSize;
- float ty2 = ty1 + tmpCos * iconSize;
-
- float tz1 = z;
- float tz2 = z + tmpSin * iconSize;
-
- float tx1 = xoffset + (-gridSize / 2.f) + ((float)col * (iconSize + iconSpacing));
- float tx2 = tx1 + iconSize;
-
- bindTexture(NAMED_PF, 0, loadI32(1, index));
- drawQuad(tx1, ty1, tz1,
- tx2, ty1, tz1,
- tx2, ty2, tz2,
- tx1, ty2, tz2);
- index++;
- }
- }
-
-
-
-
- return 1;
-}
-
-
-
diff --git a/libs/rs/java/Rollo/res/raw/settings.png b/libs/rs/java/Rollo/res/raw/settings.png
deleted file mode 100644
index dd2cd9570486..000000000000
--- a/libs/rs/java/Rollo/res/raw/settings.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/Rollo.java b/libs/rs/java/Rollo/src/com/android/rollo/Rollo.java
deleted file mode 100644
index 400d80180c26..000000000000
--- a/libs/rs/java/Rollo/src/com/android/rollo/Rollo.java
+++ /dev/null
@@ -1,90 +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 com.android.rollo;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
-import android.app.Activity;
-import android.content.res.Configuration;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Config;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-
-import java.lang.Runtime;
-
-public class Rollo extends Activity {
- //EventListener mListener = new EventListener();
-
- private static final String LOG_TAG = "libRS_jni";
- private static final boolean DEBUG = false;
- private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
-
- private RolloView mView;
-
- // get the current looper (from your Activity UI thread for instance
-
-
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- // Create our Preview view and set it as the content of our
- // Activity
- mView = new RolloView(this);
- setContentView(mView);
- }
-
- @Override
- protected void onResume() {
- // Ideally a game should implement onResume() and onPause()
- // to take appropriate action when the activity looses focus
- super.onResume();
- mView.onResume();
- }
-
- @Override
- protected void onPause() {
- // Ideally a game should implement onResume() and onPause()
- // to take appropriate action when the activity looses focus
- super.onPause();
- mView.onPause();
-
- Runtime.getRuntime().exit(0);
- }
-
-
- static void log(String message) {
- if (LOG_ENABLED) {
- Log.v(LOG_TAG, message);
- }
- }
-
-
-}
-
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
deleted file mode 100644
index ff89bc3e5ecb..000000000000
--- a/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
+++ /dev/null
@@ -1,315 +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 com.android.rollo;
-
-import java.io.Writer;
-
-import android.renderscript.RenderScript;
-import android.renderscript.ProgramVertex;
-import android.renderscript.Element;
-import android.renderscript.Allocation;
-import android.renderscript.Script;
-import android.renderscript.ScriptC;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.Sampler;
-
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.graphics.Typeface;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.util.Log;
-
-public class RolloRS {
- //public static final int STATE_SELECTED_ID = 0;
- public static final int STATE_DONE = 1;
- //public static final int STATE_PRESSURE = 2;
- public static final int STATE_ZOOM = 3;
- //public static final int STATE_WARP = 4;
- public static final int STATE_ORIENTATION = 5;
- public static final int STATE_SELECTION = 6;
- public static final int STATE_FIRST_VISIBLE = 7;
- public static final int STATE_COUNT = 8;
- public static final int STATE_TOUCH = 9;
-
-
- public RolloRS() {
- }
-
- public void init(RenderScript rs, Resources res, int width, int height) {
- mRS = rs;
- mRes = res;
- mWidth = width;
- mHeight = height;
- initNamed();
- initRS();
- }
-
- public void setPosition(float column) {
- mAllocStateBuf[STATE_FIRST_VISIBLE] = (int)(column * (-20));
- mAllocState.data(mAllocStateBuf);
- }
-
- public void setTouch(boolean touch) {
- mAllocStateBuf[STATE_TOUCH] = touch ? 1 : 0;
- mAllocState.data(mAllocStateBuf);
- }
-
- public void setZoom(float z) {
- //Log.e("rs", "zoom " + Float.toString(z));
-
- mAllocStateBuf[STATE_ZOOM] = (int)(z * 1000.f);
- mAllocState.data(mAllocStateBuf);
- }
-
- public void setSelected(int index) {
- //Log.e("rs", "setSelected " + Integer.toString(index));
-
- mAllocStateBuf[STATE_SELECTION] = index;
- mAllocStateBuf[STATE_DONE] = 1;
- mAllocState.data(mAllocStateBuf);
- }
-
- private int mWidth;
- private int mHeight;
-
- private Resources mRes;
- private RenderScript mRS;
- private Script mScript;
- private Sampler mSampler;
- private Sampler mSamplerText;
- private ProgramStore mPSBackground;
- private ProgramStore mPSText;
- private ProgramFragment mPFImages;
- private ProgramFragment mPFText;
- private ProgramVertex mPV;
- private ProgramVertex.MatrixAllocation mPVAlloc;
- private ProgramVertex mPVOrtho;
- private ProgramVertex.MatrixAllocation mPVOrthoAlloc;
- private Allocation[] mIcons;
- private Allocation[] mLabels;
-
- private int[] mAllocStateBuf;
- private Allocation mAllocState;
-
- private int[] mAllocIconIDBuf;
- private Allocation mAllocIconID;
-
- private int[] mAllocLabelIDBuf;
- private Allocation mAllocLabelID;
-
- private int[] mAllocScratchBuf;
- private Allocation mAllocScratch;
-
- private void initNamed() {
- Sampler.Builder sb = new Sampler.Builder(mRS);
- sb.setMin(Sampler.Value.LINEAR);//_MIP_LINEAR);
- sb.setMag(Sampler.Value.LINEAR);
- sb.setWrapS(Sampler.Value.CLAMP);
- sb.setWrapT(Sampler.Value.CLAMP);
- mSampler = sb.create();
-
- sb.setMin(Sampler.Value.NEAREST);
- sb.setMag(Sampler.Value.NEAREST);
- mSamplerText = sb.create();
-
-
- ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
- bf.setTexEnable(true, 0);
- bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
- mPFImages = bf.create();
- mPFImages.setName("PF");
- mPFImages.bindSampler(mSampler, 0);
-
- bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
- mPFText = bf.create();
- mPFText.setName("PFText");
- mPFText.bindSampler(mSamplerText, 0);
-
- ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
- bs.setDepthFunc(ProgramStore.DepthFunc.LESS);
- bs.setDitherEnable(false);
- bs.setDepthMask(true);
- bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
- ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
- mPSBackground = bs.create();
- mPSBackground.setName("PFS");
-
- bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
- bs.setDepthMask(false);
- bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
- ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
- mPSText = bs.create();
- mPSText.setName("PFSText");
-
- mPVAlloc = new ProgramVertex.MatrixAllocation(mRS);
- mPVAlloc.setupProjectionNormalized(mWidth, mHeight);
-
- ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
- mPV = pvb.create();
- mPV.setName("PV");
- mPV.bindAllocation(mPVAlloc);
-
- mPVOrthoAlloc = new ProgramVertex.MatrixAllocation(mRS);
- mPVOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
-
- pvb.setTextureMatrixEnable(true);
- mPVOrtho = pvb.create();
- mPVOrtho.setName("PVOrtho");
- mPVOrtho.bindAllocation(mPVOrthoAlloc);
-
- mRS.contextBindProgramVertex(mPV);
-
- mAllocScratchBuf = new int[32];
- mAllocScratch = Allocation.createSized(mRS,
- Element.USER_I32(mRS), mAllocScratchBuf.length);
- mAllocScratch.data(mAllocScratchBuf);
-
- Log.e("rs", "Done loading named");
-
-
-
- {
- mIcons = new Allocation[29];
- mAllocIconIDBuf = new int[mIcons.length];
- mAllocIconID = Allocation.createSized(mRS,
- Element.USER_I32(mRS), mAllocIconIDBuf.length);
-
- mLabels = new Allocation[29];
- mAllocLabelIDBuf = new int[mLabels.length];
- mAllocLabelID = Allocation.createSized(mRS,
- Element.USER_I32(mRS), mLabels.length);
-
- Element ie8888 = Element.RGBA_8888(mRS);
-
- mIcons[0] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.browser, ie8888, true);
- mIcons[1] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.market, ie8888, true);
- mIcons[2] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.photos, ie8888, true);
- mIcons[3] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.settings, ie8888, true);
- mIcons[4] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.calendar, ie8888, true);
- mIcons[5] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.g1155, ie8888, true);
- mIcons[6] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.g2140, ie8888, true);
- mIcons[7] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.maps, ie8888, true);
- mIcons[8] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path431, ie8888, true);
- mIcons[9] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path676, ie8888, true);
- mIcons[10] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path754, ie8888, true);
- mIcons[11] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path815, ie8888, true);
- mIcons[12] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path1920, ie8888, true);
- mIcons[13] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path1927, ie8888, true);
- mIcons[14] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path3099, ie8888, true);
- mIcons[15] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path3950, ie8888, true);
- mIcons[16] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path4481, ie8888, true);
- mIcons[17] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.path5168, ie8888, true);
- mIcons[18] = Allocation.createFromBitmapResource(mRS, mRes, R.raw.polygon2408, ie8888, true);
-
- mLabels[0] = makeTextBitmap("browser");
- mLabels[1] = makeTextBitmap("market");
- mLabels[2] = makeTextBitmap("photos");
- mLabels[3] = makeTextBitmap("settings");
- mLabels[4] = makeTextBitmap("calendar");
- mLabels[5] = makeTextBitmap("g1155");
- mLabels[6] = makeTextBitmap("g2140");
- mLabels[7] = makeTextBitmap("maps");
- mLabels[8] = makeTextBitmap("path431");
- mLabels[9] = makeTextBitmap("path676");
- mLabels[10] = makeTextBitmap("path754");
- mLabels[11] = makeTextBitmap("path815");
- mLabels[12] = makeTextBitmap("path1920");
- mLabels[13] = makeTextBitmap("path1927");
- mLabels[14] = makeTextBitmap("path3099");
- mLabels[15] = makeTextBitmap("path3950");
- mLabels[16] = makeTextBitmap("path4481");
- mLabels[17] = makeTextBitmap("path5168");
- mLabels[18] = makeTextBitmap("polygon2408");
-
- mIcons[19] = mIcons[0];
- mIcons[20] = mIcons[1];
- mIcons[21] = mIcons[2];
- mIcons[22] = mIcons[3];
- mIcons[23] = mIcons[4];
- mIcons[24] = mIcons[5];
- mIcons[25] = mIcons[6];
- mIcons[26] = mIcons[7];
- mIcons[27] = mIcons[8];
- mIcons[28] = mIcons[9];
-
- mLabels[19] = mLabels[0];
- mLabels[20] = mLabels[1];
- mLabels[21] = mLabels[2];
- mLabels[22] = mLabels[3];
- mLabels[23] = mLabels[4];
- mLabels[24] = mLabels[5];
- mLabels[25] = mLabels[6];
- mLabels[26] = mLabels[7];
- mLabels[27] = mLabels[8];
- mLabels[28] = mLabels[9];
-
- for(int ct=0; ct < mIcons.length; ct++) {
- mIcons[ct].uploadToTexture(0);
- mLabels[ct].uploadToTexture(0);
- mAllocIconIDBuf[ct] = mIcons[ct].getID();
- mAllocLabelIDBuf[ct] = mLabels[ct].getID();
- }
- mAllocIconID.data(mAllocIconIDBuf);
- mAllocLabelID.data(mAllocLabelIDBuf);
- }
-
- }
-
- Allocation makeTextBitmap(String t) {
- Bitmap b = Bitmap.createBitmap(128, 32, Bitmap.Config.ARGB_8888);
- Canvas c = new Canvas(b);
- Paint p = new Paint();
- p.setTypeface(Typeface.DEFAULT_BOLD);
- p.setTextSize(20);
- p.setColor(0xffffffff);
- c.drawText(t, 2, 26, p);
- return Allocation.createFromBitmap(mRS, b, Element.RGBA_8888(mRS), true);
- }
-
-
- private void initRS() {
- ScriptC.Builder sb = new ScriptC.Builder(mRS);
- sb.setScript(mRes, R.raw.rollo);
- //sb.setScript(mRes, R.raw.rollo2);
- sb.setRoot(true);
- mScript = sb.create();
- mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
-
- mAllocStateBuf = new int[] {0, 0, 0, 8, 0, 0, -1, 0, mAllocIconIDBuf.length, 0, 0};
- mAllocState = Allocation.createSized(mRS,
- Element.USER_I32(mRS), mAllocStateBuf.length);
- mScript.bindAllocation(mAllocState, 0);
- mScript.bindAllocation(mAllocIconID, 1);
- mScript.bindAllocation(mAllocScratch, 2);
- mScript.bindAllocation(mAllocLabelID, 3);
- setPosition(0);
- setZoom(1);
-
- //RenderScript.File f = mRS.fileOpen("/sdcard/test.a3d");
-
- mRS.contextBindRootScript(mScript);
- }
-}
-
-
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java
deleted file mode 100644
index 7524a0e380f4..000000000000
--- a/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java
+++ /dev/null
@@ -1,214 +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 com.android.rollo;
-
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-import java.lang.Float;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.graphics.PixelFormat;
-
-
-public class RolloView extends RSSurfaceView {
- public RolloView(Context context) {
- super(context);
- setFocusable(true);
- getHolder().setFormat(PixelFormat.TRANSLUCENT);
- }
-
- private RenderScript mRS;
- private RolloRS mRender;
-
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- super.surfaceChanged(holder, format, w, h);
-
- mRS = createRenderScript(false);
- mRender = new RolloRS();
- mRender.init(mRS, getResources(), w, h);
- }
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- // break point at here
- // this method doesn't work when 'extends View' include 'extends ScrollView'.
- return super.onKeyDown(keyCode, event);
- }
-
- boolean mControlMode = false;
- boolean mZoomMode = false;
- boolean mFlingMode = false;
- float mFlingX = 0;
- float mFlingY = 0;
- float mColumn = -1;
- float mOldColumn;
- float mZoom = 1;
-
- int mIconCount = 29;
- int mRows = 4;
- int mColumns = (mIconCount + mRows - 1) / mRows;
-
- float mMaxZoom = ((float)mColumns) / 3.f;
-
-
- void setColumn(boolean clamp)
- {
- //Log.e("rs", " col = " + Float.toString(mColumn));
- float c = mColumn;
- if(c > (mColumns -2)) {
- c = (mColumns -2);
- }
- if(c < 0) {
- c = 0;
- }
- mRender.setPosition(c);
- if(clamp) {
- mColumn = c;
- }
- }
-
- void computeSelection(float x, float y)
- {
- float col = mColumn + (x - 0.5f) * 4 + 1.25f;
- int iCol = (int)(col + 0.25f);
-
- float row = (y / 0.8f) * mRows;
- int iRow = (int)(row - 0.5f);
-
- mRender.setSelected(iCol * mRows + iRow);
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent ev)
- {
- boolean ret = true;
- int act = ev.getAction();
- if (act == ev.ACTION_UP) {
- ret = false;
- }
-
- float nx = ev.getX() / getWidth();
- float ny = ev.getY() / getHeight();
-
- //Log.e("rs", "width=" + Float.toString(getWidth()));
- //Log.e("rs", "height=" + Float.toString(getHeight()));
-
- mRender.setTouch(ret);
-
- if((ny > 0.85f) || mControlMode) {
- mFlingMode = false;
-
- // Projector control
- if((nx > 0.2f) && (nx < 0.8f) || mControlMode) {
- if(act != ev.ACTION_UP) {
- float zoom = mMaxZoom;
- if(mControlMode) {
- if(!mZoomMode) {
- zoom = 1.f;
- }
- float dx = nx - mFlingX;
-
- if((ny < 0.9) && mZoomMode) {
- zoom = mMaxZoom - ((0.9f - ny) * 10.f);
- if(zoom < 1) {
- zoom = 1;
- mZoomMode = false;
- }
- mOldColumn = mColumn;
- }
- mColumn += dx * 4;// * zoom;
- if(zoom > 1.01f) {
- mColumn += (mZoom - zoom) * (nx - 0.5f) * 4 * zoom;
- }
- } else {
- mOldColumn = mColumn;
- mColumn = ((float)mColumns) / 2;
- mControlMode = true;
- mZoomMode = true;
- }
- mZoom = zoom;
- mFlingX = nx;
- mRender.setZoom(zoom);
- if(mZoom < 1.01f) {
- computeSelection(nx, ny);
- }
- } else {
- mControlMode = false;
- mColumn = mOldColumn;
- mRender.setZoom(1.f);
- mRender.setSelected(-1);
- }
- } else {
- // Do something with corners here....
- }
- setColumn(true);
-
- } else {
- // icon control
- if(act != ev.ACTION_UP) {
- if(mFlingMode) {
- mColumn += (mFlingX - nx) * 4;
- setColumn(true);
- }
- mFlingMode = true;
- mFlingX = nx;
- mFlingY = ny;
- } else {
- mFlingMode = false;
- mColumn = (float)(java.lang.Math.floor(mColumn * 0.25f + 0.3f) * 4.f) + 1.f;
- setColumn(true);
- }
- }
-
-
- return ret;
- }
-
- @Override
- public boolean onTrackballEvent(MotionEvent ev)
- {
- float x = ev.getX();
- float y = ev.getY();
- //Float tx = new Float(x);
- //Float ty = new Float(y);
- //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString());
-
-
- return true;
- }
-
-}
-
-
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index a4e72d93f90b..ac115d34ffbd 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -20,16 +20,6 @@ ContextBindProgramRaster {
param RsProgramRaster pgm
}
-ContextSetDefineF {
- param const char* name
- param float value
- }
-
-ContextSetDefineI32 {
- param const char* name
- param int32_t value
- }
-
ContextPause {
}
@@ -60,18 +50,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
}
@@ -366,56 +357,50 @@ ProgramRasterSetPointSize{
}
-ProgramFragmentBegin {
- param RsElement in
- param RsElement out
- param bool pointSpriteEnable
+ProgramBindConstants {
+ param RsProgram vp
+ param uint32_t slot
+ param RsAllocation constants
}
-ProgramFragmentBindTexture {
+
+ProgramBindTexture {
param RsProgramFragment pf
param uint32_t slot
param RsAllocation a
}
-ProgramFragmentBindSampler {
+ProgramBindSampler {
param RsProgramFragment pf
param uint32_t slot
param RsSampler s
}
-ProgramFragmentSetSlot {
- param uint32_t slot
- param bool enable
- param RsTexEnvMode env
- param RsType t
- }
-
ProgramFragmentCreate {
+ param const uint32_t * params
+ param uint32_t paramLength
ret RsProgramFragment
}
-
-ProgramVertexBegin {
- param RsElement in
- param RsElement out
+ProgramFragmentCreate2 {
+ param const char * shaderText
+ param uint32_t shaderLength
+ param const uint32_t * params
+ param uint32_t paramLength
+ ret RsProgramFragment
}
ProgramVertexCreate {
+ param bool texMat
ret RsProgramVertex
}
-ProgramVertexBindAllocation {
- param RsProgramVertex vpgm
- param RsAllocation constants
- }
-
-ProgramVertexSetTextureMatrixEnable {
- param bool enable
- }
-
-ProgramVertexAddLight {
- param RsLight light
+ProgramVertexCreate2 {
+ param const char * shaderText
+ param uint32_t shaderLength
+ param const uint32_t * params
+ param uint32_t paramLength
+ ret RsProgramVertex
}
LightBegin {
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index ff8d29f2a8c4..eb6c5035d7fe 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -38,9 +38,9 @@ Allocation::Allocation(Context *rsc, const Type *type) : ObjectBase(rsc)
mIsTexture = false;
mTextureID = 0;
-
mIsVertexBuffer = false;
mBufferID = 0;
+ mUploadDefered = false;
mType.set(type);
rsAssert(type);
@@ -88,13 +88,26 @@ bool Allocation::fixAllocation()
return false;
}
-void Allocation::uploadToTexture(Context *rsc, uint32_t lodOffset)
+void Allocation::deferedUploadToTexture(const Context *rsc, uint32_t lodOffset)
{
- //rsAssert(!mTextureId);
rsAssert(lodOffset < mType->getLODCount());
+ mIsTexture = true;
+ mTextureLOD = lodOffset;
+ mUploadDefered = true;
+}
+
+void Allocation::uploadToTexture(const Context *rsc)
+{
+ //rsAssert(!mTextureId);
+
+ mIsTexture = true;
+ if (!rsc->checkDriver()) {
+ mUploadDefered = true;
+ 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;
@@ -109,15 +122,16 @@ void Allocation::uploadToTexture(Context *rsc, uint32_t lodOffset)
// Force a crash to 1: restart the app, 2: make sure we get a bugreport.
LOGE("Upload to texture failed to gen mTextureID");
rsc->dumpDebug();
- ((char *)0)[0] = 0;
+ mUploadDefered = true;
+ return;
}
}
glBindTexture(GL_TEXTURE_2D, mTextureID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
Adapter2D adapt(getContext(), this);
- for(uint32_t lod = 0; (lod + lodOffset) < mType->getLODCount(); lod++) {
- adapt.setLOD(lod+lodOffset);
+ for(uint32_t lod = 0; (lod + mTextureLOD) < mType->getLODCount(); lod++) {
+ adapt.setLOD(lod+mTextureLOD);
uint16_t * ptr = static_cast<uint16_t *>(adapt.getElement(0,0));
glTexImage2D(GL_TEXTURE_2D, lod, format,
@@ -126,19 +140,50 @@ void Allocation::uploadToTexture(Context *rsc, uint32_t lodOffset)
}
}
-void Allocation::uploadToBufferObject()
+void Allocation::deferedUploadToBufferObject(const Context *rsc)
+{
+ mIsVertexBuffer = true;
+ mUploadDefered = true;
+}
+
+void Allocation::uploadToBufferObject(const Context *rsc)
{
rsAssert(!mType->getDimY());
rsAssert(!mType->getDimZ());
+ mIsVertexBuffer = true;
+ if (!rsc->checkDriver()) {
+ mUploadDefered = true;
+ return;
+ }
+
if (!mBufferID) {
glGenBuffers(1, &mBufferID);
}
+ if (!mBufferID) {
+ LOGE("Upload to buffer object failed");
+ mUploadDefered = true;
+ return;
+ }
+
glBindBuffer(GL_ARRAY_BUFFER, mBufferID);
glBufferData(GL_ARRAY_BUFFER, mType->getSizeBytes(), getPtr(), GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
+void Allocation::uploadCheck(const Context *rsc)
+{
+ if (mUploadDefered) {
+ mUploadDefered = false;
+ if (mIsVertexBuffer) {
+ uploadToBufferObject(rsc);
+ }
+ if (mIsTexture) {
+ uploadToTexture(rsc);
+ }
+ }
+}
+
void Allocation::data(const void *data, uint32_t sizeBytes)
{
@@ -148,6 +193,8 @@ void Allocation::data(const void *data, uint32_t sizeBytes)
return;
}
memcpy(mPtr, data, size);
+ sendDirty();
+ mUploadDefered = true;
}
void Allocation::read(void *data)
@@ -168,6 +215,8 @@ void Allocation::subData(uint32_t xoff, uint32_t count, const void *data, uint32
return;
}
memcpy(ptr, data, size);
+ sendDirty();
+ mUploadDefered = true;
}
void Allocation::subData(uint32_t xoff, uint32_t yoff,
@@ -192,6 +241,8 @@ void Allocation::subData(uint32_t xoff, uint32_t yoff,
src += lineSize;
dst += destW * eSize;
}
+ sendDirty();
+ mUploadDefered = true;
}
void Allocation::subData(uint32_t xoff, uint32_t yoff, uint32_t zoff,
@@ -214,10 +265,30 @@ void Allocation::dumpLOGV(const char *prefix) const
LOGV("%s allocation mIsTexture=%i mTextureID=%i, mIsVertexBuffer=%i, mBufferID=%i",
prefix, mIsTexture, mTextureID, mIsVertexBuffer, mBufferID);
+}
+void Allocation::addProgramToDirty(const Program *p)
+{
+ mToDirtyList.add(p);
+}
+void Allocation::removeProgramToDirty(const Program *p)
+{
+ for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
+ if (mToDirtyList[ct] == p) {
+ mToDirtyList.removeAt(ct);
+ return;
+ }
+ }
+ rsAssert(0);
}
+void Allocation::sendDirty() const
+{
+ for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
+ mToDirtyList[ct]->forceDirty();
+ }
+}
/////////////////
//
@@ -247,13 +318,13 @@ RsAllocation rsi_AllocationCreateSized(Context *rsc, RsElement e, size_t count)
void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, uint32_t baseMipLevel)
{
Allocation *alloc = static_cast<Allocation *>(va);
- alloc->uploadToTexture(rsc, baseMipLevel);
+ alloc->deferedUploadToTexture(rsc, baseMipLevel);
}
void rsi_AllocationUploadToBufferObject(Context *rsc, RsAllocation va)
{
Allocation *alloc = static_cast<Allocation *>(va);
- alloc->uploadToBufferObject();
+ alloc->deferedUploadToBufferObject(rsc);
}
static void mip565(const Adapter2D &out, const Adapter2D &in)
@@ -294,6 +365,25 @@ static void mip8888(const Adapter2D &out, const Adapter2D &in)
}
}
+static void mip8(const Adapter2D &out, const Adapter2D &in)
+{
+ uint32_t w = out.getDimX();
+ uint32_t h = out.getDimY();
+
+ for (uint32_t y=0; y < h; y++) {
+ uint8_t *oPtr = static_cast<uint8_t *>(out.getElement(0, y));
+ const uint8_t *i1 = static_cast<uint8_t *>(in.getElement(0, y*2));
+ const uint8_t *i2 = static_cast<uint8_t *>(in.getElement(0, y*2+1));
+
+ for (uint32_t x=0; x < w; x++) {
+ *oPtr = (uint8_t)(((uint32_t)i1[0] + i1[1] + i2[0] + i2[1]) * 0.25f);
+ oPtr ++;
+ i1 += 2;
+ i2 += 2;
+ }
+ }
+}
+
static void mip(const Adapter2D &out, const Adapter2D &in)
{
switch(out.getBaseType()->getElement()->getSizeBits()) {
@@ -303,6 +393,9 @@ static void mip(const Adapter2D &out, const Adapter2D &in)
case 16:
mip565(out, in);
break;
+ case 8:
+ mip8(out, in);
+ break;
}
@@ -350,10 +443,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()) {
@@ -391,8 +484,9 @@ RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h
{
const Element *src = static_cast<const Element *>(_src);
const Element *dst = static_cast<const Element *>(_dst);
- rsAssert(!(w & (w-1)));
- rsAssert(!(h & (h-1)));
+
+ // Check for pow2 on pre es 2.0 versions.
+ rsAssert(rsc->checkVersion2_0() || (!(w & (w-1)) && !(h & (h-1))));
//LOGE("rsi_AllocationCreateFromBitmap %i %i %i %i %i", w, h, dstFmt, srcFmt, genMips);
rsi_TypeBegin(rsc, _dst);
@@ -452,31 +546,24 @@ RsAllocation rsi_AllocationCreateFromBitmapBoxed(Context *rsc, uint32_t w, uint3
RsAllocation ret = rsi_AllocationCreateFromBitmap(rsc, w2, h2, _dst, _src, genMips, tmp);
free(tmp);
return ret;
-
-
-
-
}
void rsi_AllocationData(Context *rsc, RsAllocation va, const void *data, uint32_t sizeBytes)
{
Allocation *a = static_cast<Allocation *>(va);
a->data(data, sizeBytes);
- rsc->allocationCheck(a);
}
void rsi_Allocation1DSubData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t count, const void *data, uint32_t sizeBytes)
{
Allocation *a = static_cast<Allocation *>(va);
a->subData(xoff, count, data, sizeBytes);
- rsc->allocationCheck(a);
}
void rsi_Allocation2DSubData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data, uint32_t sizeBytes)
{
Allocation *a = static_cast<Allocation *>(va);
a->subData(xoff, yoff, w, h, data, sizeBytes);
- rsc->allocationCheck(a);
}
void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data)
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index f54284ac5687..f0b21226d18b 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -23,7 +23,7 @@
namespace android {
namespace renderscript {
-
+class Program;
class Allocation : public ObjectBase
{
@@ -46,10 +46,12 @@ public:
void * getPtr() const {return mPtr;}
const Type * getType() const {return mType.get();}
- void uploadToTexture(Context *rsc, uint32_t lodOffset = 0);
+ void deferedUploadToTexture(const Context *rsc, uint32_t lodOffset);
+ void uploadToTexture(const Context *rsc);
uint32_t getTextureID() const {return mTextureID;}
- void uploadToBufferObject();
+ void deferedUploadToBufferObject(const Context *rsc);
+ void uploadToBufferObject(const Context *rsc);
uint32_t getBufferObjectID() const {return mBufferID;}
@@ -65,13 +67,21 @@ public:
void enableGLVertexBuffers() const;
void setupGLIndexBuffers() const;
+ void addProgramToDirty(const Program *);
+ void removeProgramToDirty(const Program *);
+
virtual void dumpLOGV(const char *prefix) const;
+ virtual void uploadCheck(const Context *rsc);
protected:
+ void sendDirty() const;
+
ObjectBaseRef<const Type> mType;
void * mPtr;
+ Vector<const Program *> mToDirtyList;
+
// Usage restrictions
bool mCpuWrite;
bool mCpuRead;
@@ -88,6 +98,7 @@ protected:
// Is this a legal structure to be used as a texture source.
// Initially this will require 1D or 2D and color data
bool mIsTexture;
+ uint32_t mTextureLOD;
uint32_t mTextureID;
// Is this a legal structure to be used as a vertex source.
@@ -95,6 +106,8 @@ protected:
// is allowed.
bool mIsVertexBuffer;
uint32_t mBufferID;
+
+ bool mUploadDefered;
};
}
diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp
index de074c8ce664..15a56f7fe48e 100644
--- a/libs/rs/rsComponent.cpp
+++ b/libs/rs/rsComponent.cpp
@@ -15,96 +15,323 @@
*/
#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(Context *rsc) : ObjectBase(rsc)
+Component::~Component()
{
- mAllocFile = __FILE__;
- mAllocLine = __LINE__;
- mType = FLOAT;
- mKind = USER;
- mIsNormalized = false;
- mBits = 0;
}
-Component::Component(Context *rsc,
- DataKind dk, DataType dt,
- bool isNormalized, uint32_t bits, const char * name) : ObjectBase(rsc)
+void Component::set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize)
{
- mAllocFile = __FILE__;
- mAllocLine = __LINE__;
mType = dt;
mKind = dk;
- mIsNormalized = isNormalized;
- mBits = bits;
- if (name) {
- mName = name;
+ 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;
}
-}
-const char * Component::getCType() const
-{
switch(mType) {
- case FLOAT:
- return "float";
- case SIGNED:
- case UNSIGNED:
- switch(mBits) {
- case 32:
- return "int";
- case 16:
- return "short";
- case 8:
- return "char";
- }
+ 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;
}
- return NULL;
+
+ mBits = mTypeBits * mVectorSize;
}
-Component::~Component()
+
+
+
+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::getGLType() const
+uint32_t Component::getGLFormat() const
{
- switch(mType) {
- case RS_TYPE_FLOAT:
- rsAssert(mBits == 32);
- return GL_FLOAT;
- case RS_TYPE_SIGNED:
- switch(mBits) {
- case 32:
- return 0;//GL_INT;
- case 16:
- return GL_SHORT;
- case 8:
- return GL_BYTE;
+ 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;
+}
+
+String8 Component::getGLSLType() const
+{
+ if (mType == RS_TYPE_SIGNED_32) {
+ switch(mVectorSize) {
+ case 1: return String8("int");
+ case 2: return String8("ivec2");
+ case 3: return String8("ivec3");
+ case 4: return String8("ivec4");
}
- break;
- case RS_TYPE_UNSIGNED:
- switch(mBits) {
- case 32:
- return 0;//GL_UNSIGNED_INT;
- case 16:
- return GL_UNSIGNED_SHORT;
- case 8:
- return GL_UNSIGNED_BYTE;
+ }
+ if (mType == RS_TYPE_FLOAT_32) {
+ switch(mVectorSize) {
+ case 1: return String8("float");
+ case 2: return String8("vec2");
+ case 3: return String8("vec3");
+ case 4: return String8("vec4");
}
- break;
}
- //rsAssert(!"Bad type");
- //LOGE("mType %i, mKind %i, mBits %i, mIsNormalized %i", mType, mKind, mBits, mIsNormalized);
- return 0;
+ return String8();
}
+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
{
- ObjectBase::dumpLOGV(prefix);
- LOGV("%s component: %i %i %i %i", prefix, mType, mKind, mIsNormalized, mBits);
+ 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
index 5366cc429e96..71de32435701 100644
--- a/libs/rs/rsComponent.h
+++ b/libs/rs/rsComponent.h
@@ -14,65 +14,56 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_STRUCTURED_COMPONENT_H
-#define ANDROID_RS_STRUCTURED_COMPONENT_H
+#ifndef ANDROID_COMPONENT_H
+#define ANDROID_COMPONENT_H
#include "rsUtils.h"
-#include "rsObjectBase.h"
// ---------------------------------------------------------------------------
namespace android {
namespace renderscript {
-class Component : public ObjectBase
+
+// An element is a group of Components that occupies one cell in a structure.
+class Component
{
public:
- enum DataType {
- FLOAT,
- UNSIGNED,
- SIGNED
- };
-
- enum DataKind {
- USER,
- RED, GREEN, BLUE, ALPHA, LUMINANCE, INTENSITY,
- X, Y, Z, W,
- S, T, Q, R,
- NX, NY, NZ,
- INDEX,
- POINT_SIZE
- };
-
+ Component();
+ ~Component();
- Component(Context *rsc, DataKind dk, DataType dt, bool isNorm, uint32_t bits, const char *);
- virtual ~Component();
-
- DataType getType() const {return mType;}
- bool getIsNormalized() const {return mIsNormalized;}
- DataKind getKind() const {return mKind;}
- uint32_t getBits() const {return mBits;}
+ void set(RsDataType dt, RsDataKind dk, bool norm, uint32_t vecSize=1);
uint32_t getGLType() const;
- const char * getCType() const;
-
- const char * getComponentName() const {return mName.string();}
- virtual void dumpLOGV(const char *prefix) const;
+ uint32_t getGLFormat() const;
+ String8 getCType() const;
+ String8 getGLSLType() 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;
- DataType mType;
- bool mIsNormalized;
- DataKind mKind;
+ // derived
uint32_t mBits;
- String8 mName;
-
-private:
- Component(Context *rsc);
+ uint32_t mTypeBits;
+ bool mIsFloat;
+ bool mIsSigned;
+ bool mIsPixel;
};
-
}
}
-#endif //ANDROID_RS_STRUCTURED_COMPONENT_H
+#endif
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 3652f0acdc5a..261b827169cb 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -27,6 +27,8 @@
#include <GLES/gl.h>
#include <GLES/glext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
#include <cutils/sched_policy.h>
@@ -50,11 +52,12 @@ static void checkEglError(const char* op, EGLBoolean returnVal = EGL_TRUE) {
}
}
-void Context::initEGL()
+void Context::initEGL(bool useGL2)
{
mEGL.mNumConfigs = -1;
EGLint configAttribs[128];
EGLint *configAttribsPtr = configAttribs;
+ EGLint context_attribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
memset(configAttribs, 0, sizeof(configAttribs));
@@ -62,6 +65,12 @@ void Context::initEGL()
configAttribsPtr[1] = EGL_WINDOW_BIT;
configAttribsPtr += 2;
+ if (useGL2) {
+ configAttribsPtr[0] = EGL_RENDERABLE_TYPE;
+ configAttribsPtr[1] = EGL_OPENGL_ES2_BIT;
+ configAttribsPtr += 2;
+ }
+
if (mUseDepth) {
configAttribsPtr[0] = EGL_DEPTH_SIZE;
configAttribsPtr[1] = 16;
@@ -91,7 +100,11 @@ void Context::initEGL()
//eglChooseConfig(mEGL.mDisplay, configAttribs, &mEGL.mConfig, 1, &mEGL.mNumConfigs);
- mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, NULL);
+ if (useGL2) {
+ mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, context_attribs2);
+ } else {
+ mEGL.mContext = eglCreateContext(mEGL.mDisplay, mEGL.mConfig, EGL_NO_CONTEXT, NULL);
+ }
checkEglError("eglCreateContext");
if (mEGL.mContext == EGL_NO_CONTEXT) {
LOGE("eglCreateContext returned EGL_NO_CONTEXT");
@@ -129,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()
{
@@ -156,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;
}
@@ -225,10 +241,20 @@ void Context::timerPrint()
void Context::setupCheck()
{
- mFragmentStore->setupGL(this, &mStateFragmentStore);
- mFragment->setupGL(this, &mStateFragment);
- mRaster->setupGL(this, &mStateRaster);
- mVertex->setupGL(this, &mStateVertex);
+ if (checkVersion2_0()) {
+ mShaderCache.lookup(this, mVertex.get(), mFragment.get());
+
+ mFragmentStore->setupGL2(this, &mStateFragmentStore);
+ mFragment->setupGL2(this, &mStateFragment, &mShaderCache);
+ mRaster->setupGL2(this, &mStateRaster);
+ mVertex->setupGL2(this, &mStateVertex, &mShaderCache);
+
+ } else {
+ mFragmentStore->setupGL(this, &mStateFragmentStore);
+ mFragment->setupGL(this, &mStateFragment);
+ mRaster->setupGL(this, &mStateRaster);
+ mVertex->setupGL(this, &mStateVertex);
+ }
}
static bool getProp(const char *str)
@@ -248,11 +274,8 @@ void * Context::threadProc(void *vrsc)
rsc->props.mLogTimes = getProp("debug.rs.profile");
rsc->props.mLogScripts = getProp("debug.rs.script");
- rsc->props.mLogObjects = getProp("debug.rs.objects");
-
- //pthread_mutex_lock(&gInitMutex);
- //rsc->initEGL();
- //pthread_mutex_unlock(&gInitMutex);
+ rsc->props.mLogObjects = getProp("debug.rs.object");
+ rsc->props.mLogShaders = getProp("debug.rs.shader");
ScriptTLSStruct *tlsStruct = new ScriptTLSStruct;
if (!tlsStruct) {
@@ -274,6 +297,7 @@ void * Context::threadProc(void *vrsc)
rsc->setFragment(NULL);
rsc->mStateFragmentStore.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
rsc->setFragmentStore(NULL);
+ rsc->mStateVertexArray.init(rsc);
rsc->mRunning = true;
bool mDraw = true;
@@ -319,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);
@@ -457,7 +477,7 @@ void Context::setSurface(uint32_t w, uint32_t h, Surface *sur)
if (!mEGL.mContext) {
first = true;
pthread_mutex_lock(&gInitMutex);
- initEGL();
+ initEGL(true);
pthread_mutex_unlock(&gInitMutex);
}
@@ -488,15 +508,35 @@ void Context::setSurface(uint32_t w, uint32_t h, Surface *sur)
//LOGV("EGL Version %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
LOGV("GL Version %s", mGL.mVersion);
- LOGV("GL Vendor %s", mGL.mVendor);
+ //LOGV("GL Vendor %s", mGL.mVendor);
LOGV("GL Renderer %s", mGL.mRenderer);
//LOGV("GL Extensions %s", mGL.mExtensions);
- if ((strlen((const char *)mGL.mVersion) < 12) || memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
+ const char *verptr = NULL;
+ if (strlen((const char *)mGL.mVersion) > 9) {
+ if (!memcmp(mGL.mVersion, "OpenGL ES-CM", 12)) {
+ verptr = (const char *)mGL.mVersion + 12;
+ }
+ if (!memcmp(mGL.mVersion, "OpenGL ES ", 10)) {
+ verptr = (const char *)mGL.mVersion + 9;
+ }
+ }
+
+ if (!verptr) {
LOGE("Error, OpenGL ES Lite not supported");
} else {
- sscanf((const char *)mGL.mVersion + 13, "%i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
+ sscanf(verptr, " %i.%i", &mGL.mMajorVersion, &mGL.mMinorVersion);
}
+
+ glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &mGL.mMaxVertexAttribs);
+ glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &mGL.mMaxVertexUniformVectors);
+ glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &mGL.mMaxVertexTextureUnits);
+
+ glGetIntegerv(GL_MAX_VARYING_VECTORS, &mGL.mMaxVaryingVectors);
+ glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mGL.mMaxTextureImageUnits);
+
+ glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &mGL.mMaxFragmentTextureImageUnits);
+ glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &mGL.mMaxFragmentUniformVectors);
}
}
@@ -544,13 +584,6 @@ void Context::setRaster(ProgramRaster *pr)
}
}
-void Context::allocationCheck(const Allocation *a)
-{
- mVertex->checkUpdatedAllocation(a);
- mFragment->checkUpdatedAllocation(a);
- mFragmentStore->checkUpdatedAllocation(a);
-}
-
void Context::setVertex(ProgramVertex *pv)
{
if (pv == NULL) {
@@ -558,7 +591,6 @@ void Context::setVertex(ProgramVertex *pv)
} else {
mVertex.set(pv);
}
- mVertex->forceDirty();
}
void Context::assignName(ObjectBase *obj, const char *name, uint32_t len)
@@ -600,26 +632,6 @@ void Context::appendNameDefines(String8 *str) const
}
}
-void Context::appendVarDefines(String8 *str) const
-{
- char buf[256];
- for (size_t ct=0; ct < mInt32Defines.size(); ct++) {
- str->append("#define ");
- str->append(mInt32Defines.keyAt(ct));
- str->append(" ");
- sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct));
- str->append(buf);
-
- }
- for (size_t ct=0; ct < mFloatDefines.size(); ct++) {
- str->append("#define ");
- str->append(mFloatDefines.keyAt(ct));
- str->append(" ");
- sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct));
- str->append(buf);
- }
-}
-
bool Context::objDestroyOOBInit()
{
int status = pthread_mutex_init(&mObjDestroy.mMutex, NULL);
@@ -751,6 +763,10 @@ void Context::dumpDebug() const
LOGE(" RS running %i, exit %i, useDepth %i, paused %i", mRunning, mExit, mUseDepth, mPaused);
LOGE(" RS pThreadID %li, nativeThreadID %i", mThreadId, mNativeThreadId);
+ LOGV("MAX Textures %i, %i %i", mGL.mMaxVertexTextureUnits, mGL.mMaxFragmentTextureImageUnits, mGL.mMaxTextureImageUnits);
+ LOGV("MAX Attribs %i", mGL.mMaxVertexAttribs);
+ LOGV("MAX Uniforms %i, %i", mGL.mMaxVertexUniformVectors, mGL.mMaxFragmentUniformVectors);
+ LOGV("MAX Varyings %i", mGL.mMaxVaryingVectors);
}
///////////////////////////////////////////////////////////////////////////////////////////
@@ -815,16 +831,6 @@ void rsi_ObjDestroy(Context *rsc, void *obj)
ob->decUserRef();
}
-void rsi_ContextSetDefineF(Context *rsc, const char* name, float value)
-{
- rsc->addInt32Define(name, value);
-}
-
-void rsi_ContextSetDefineI32(Context *rsc, const char* name, int32_t value)
-{
- rsc->addFloatDefine(name, value);
-}
-
void rsi_ContextPause(Context *rsc)
{
rsc->pause();
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 1770ee69912c..2edd16d6e634 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -37,6 +37,8 @@
#include "rsProgramFragmentStore.h"
#include "rsProgramRaster.h"
#include "rsProgramVertex.h"
+#include "rsShaderCache.h"
+#include "rsVertexArray.h"
#include "rsgApiStructs.h"
#include "rsLocklessFifo.h"
@@ -72,8 +74,10 @@ public:
ProgramRasterState mStateRaster;
ProgramVertexState mStateVertex;
LightState mStateLight;
+ VertexArrayState mStateVertexArray;
ScriptCState mScriptC;
+ ShaderCache mShaderCache;
void swapBuffers();
void setRootScript(Script *);
@@ -90,7 +94,7 @@ public:
const ProgramVertex * getVertex() {return mVertex.get();}
void setupCheck();
- void allocationCheck(const Allocation *);
+ bool checkDriver() const {return mEGL.mSurface != 0;}
void pause();
void resume();
@@ -101,7 +105,6 @@ public:
void removeName(ObjectBase *obj);
ObjectBase * lookupName(const char *name) const;
void appendNameDefines(String8 *str) const;
- void appendVarDefines(String8 *str) const;
uint32_t getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait);
bool sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace);
@@ -123,14 +126,6 @@ public:
return mStateRaster.mDefault.get();
}
- void addInt32Define(const char* name, int32_t value) {
- mInt32Defines.add(String8(name), value);
- }
-
- void addFloatDefine(const char* name, float value) {
- mFloatDefines.add(String8(name), value);
- }
-
uint32_t getWidth() const {return mEGL.mWidth;}
uint32_t getHeight() const {return mEGL.mHeight;}
@@ -160,9 +155,11 @@ public:
bool mLogTimes;
bool mLogScripts;
bool mLogObjects;
+ bool mLogShaders;
} props;
void dumpDebug() const;
+ void checkError(const char *) const;
mutable const ObjectBase * mObjHead;
@@ -190,6 +187,15 @@ protected:
uint32_t mMajorVersion;
uint32_t mMinorVersion;
+ int32_t mMaxVaryingVectors;
+ int32_t mMaxTextureImageUnits;
+
+ int32_t mMaxFragmentTextureImageUnits;
+ int32_t mMaxFragmentUniformVectors;
+
+ int32_t mMaxVertexAttribs;
+ int32_t mMaxVertexUniformVectors;
+ int32_t mMaxVertexTextureUnits;
} mGL;
uint32_t mWidth;
@@ -224,7 +230,7 @@ protected:
private:
Context();
- void initEGL();
+ void initEGL(bool useGL2);
void deinitEGL();
uint32_t runRootScript();
@@ -234,8 +240,6 @@ private:
Surface *mWndSurface;
Vector<ObjectBase *> mNames;
- KeyedVector<String8,int> mInt32Defines;
- KeyedVector<String8,float> mFloatDefines;
uint64_t mTimers[_RS_TIMER_TOTAL];
Timers mTimerActive;
diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp
index 67e4f1401066..207ad15e044a 100644
--- a/libs/rs/rsElement.cpp
+++ b/libs/rs/rsElement.cpp
@@ -24,19 +24,13 @@ using namespace android::renderscript;
Element::Element(Context *rsc) : ObjectBase(rsc)
{
+ mBits = 0;
mAllocFile = __FILE__;
mAllocLine = __LINE__;
- mComponents = NULL;
- mComponentCount = 0;
+ mFields = NULL;
+ mFieldCount = 0;
}
-Element::Element(Context *rsc, uint32_t count) : ObjectBase(rsc)
-{
- mAllocFile = __FILE__;
- mAllocLine = __LINE__;
- mComponents = new ObjectBaseRef<Component> [count];
- mComponentCount = count;
-}
Element::~Element()
{
@@ -45,153 +39,129 @@ Element::~Element()
void Element::clear()
{
- delete [] mComponents;
- mComponents = NULL;
- mComponentCount = 0;
+ delete [] mFields;
+ mFields = NULL;
+ mFieldCount = 0;
}
-void Element::setComponent(uint32_t idx, Component *c)
-{
- rsAssert(!mComponents[idx].get());
- rsAssert(idx < mComponentCount);
- mComponents[idx].set(c);
-
-// Fixme: This should probably not be here
- c->incUserRef();
-}
-
-
size_t Element::getSizeBits() const
{
+ if (!mFieldCount) {
+ return mBits;
+ }
+
size_t total = 0;
- for (size_t ct=0; ct < mComponentCount; ct++) {
- total += mComponents[ct]->getBits();
+ for (size_t ct=0; ct < mFieldCount; ct++) {
+ total += mFields[ct].e->mBits;
}
return total;
}
-size_t Element::getComponentOffsetBits(uint32_t componentNumber) const
+size_t Element::getFieldOffsetBits(uint32_t componentNumber) const
{
size_t offset = 0;
for (uint32_t ct = 0; ct < componentNumber; ct++) {
- offset += mComponents[ct]->getBits();
+ offset += mFields[ct].e->mBits;
}
return offset;
}
-uint32_t Element::getGLType() const
+void Element::dumpLOGV(const char *prefix) const
{
- int bits[4];
+ ObjectBase::dumpLOGV(prefix);
+ LOGV("%s Element: components %i, size %i", prefix, mFieldCount, mBits);
+ for (uint32_t ct = 0; ct < mFieldCount; ct++) {
+ char buf[1024];
+ sprintf(buf, "%s component %i: ", prefix, ct);
+ //mComponents[ct]->dumpLOGV(buf);
+ }
+}
+
+
+Element * Element::create(Context *rsc, RsDataType dt, RsDataKind dk,
+ bool isNorm, uint32_t vecSize)
+{
+ Element *e = new Element(rsc);
+ e->mComponent.set(dt, dk, isNorm, vecSize);
+ e->mBits = e->mComponent.getBits();
+ return e;
+}
+
+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];
+ e->mFieldCount = count;
- if (mComponentCount > 4) {
- return 0;
+ for (size_t ct=0; ct < count; ct++) {
+ e->mFields[ct].e.set(ein[ct]);
+ e->mFields[ct].name.setTo(nin[ct], lengths[ct]);
}
- for (uint32_t ct=0; ct < mComponentCount; ct++) {
- bits[ct] = mComponents[ct]->getBits();
- if (mComponents[ct]->getType() != Component::UNSIGNED) {
- return 0;
- }
- if (!mComponents[ct]->getIsNormalized()) {
- return 0;
- }
+ return e;
+}
+
+String8 Element::getCStructBody(uint32_t indent) const
+{
+ String8 si;
+ for (uint32_t ct=0; ct < indent; ct++) {
+ si.append(" ");
}
- switch(mComponentCount) {
- 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;
- }
+ 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");
}
- return 0;
+ s.append(si);
+ s.append("}");
+ return s;
}
-uint32_t Element::getGLFormat() const
+String8 Element::getCType(uint32_t indent) const
{
- switch(mComponentCount) {
- case 1:
- if (mComponents[0]->getKind() == Component::ALPHA) {
- return GL_ALPHA;
- }
- if (mComponents[0]->getKind() == Component::LUMINANCE) {
- return GL_LUMINANCE;
- }
- break;
- case 2:
- if ((mComponents[0]->getKind() == Component::LUMINANCE) &&
- (mComponents[1]->getKind() == Component::ALPHA)) {
- return GL_LUMINANCE_ALPHA;
- }
- break;
- case 3:
- if ((mComponents[0]->getKind() == Component::RED) &&
- (mComponents[1]->getKind() == Component::GREEN) &&
- (mComponents[2]->getKind() == Component::BLUE)) {
- return GL_RGB;
- }
- break;
- case 4:
- if ((mComponents[0]->getKind() == Component::RED) &&
- (mComponents[1]->getKind() == Component::GREEN) &&
- (mComponents[2]->getKind() == Component::BLUE) &&
- (mComponents[3]->getKind() == Component::ALPHA)) {
- return GL_RGBA;
- }
- break;
+ 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 0;
-}
+ return s;
+}
-void Element::dumpLOGV(const char *prefix) const
+String8 Element::getGLSLType(uint32_t indent) const
{
- ObjectBase::dumpLOGV(prefix);
- LOGV("%s Element: components %i, size %i", prefix, mComponentCount, getSizeBytes());
- for (uint32_t ct = 0; ct < mComponentCount; ct++) {
- char buf[1024];
- sprintf(buf, "%s component %i: ", prefix, ct);
- mComponents[ct]->dumpLOGV(buf);
+ String8 s;
+ for (uint32_t ct=0; ct < indent; ct++) {
+ s.append(" ");
}
+
+ if (!mFieldCount) {
+ // Basic component.
+ s.append(mComponent.getGLSLType());
+ } else {
+ rsAssert(0);
+ //s.append("struct ");
+ //s.append(getCStructBody(indent));
+ }
+
+ return s;
}
+
+
ElementState::ElementState()
{
}
@@ -200,46 +170,35 @@ ElementState::~ElementState()
{
}
+
/////////////////////////////////////////
//
namespace android {
namespace renderscript {
-void rsi_ElementBegin(Context *rsc)
-{
- rsc->mStateElement.mComponentBuildList.clear();
-}
-
-void rsi_ElementAdd(Context *rsc, RsDataKind dk, RsDataType dt, bool isNormalized, size_t bits, const char *name)
+RsElement rsi_ElementCreate(Context *rsc,
+ RsDataType dt,
+ RsDataKind dk,
+ bool norm,
+ uint32_t vecSize)
{
- ElementState * sec = &rsc->mStateElement;
-
- rsAssert(bits > 0);
-
- Component *c = new Component(rsc,
- static_cast<Component::DataKind>(dk),
- static_cast<Component::DataType>(dt),
- isNormalized,
- bits,
- name);
- sec->mComponentBuildList.add(c);
+ //LOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize);
+ Element *e = Element::create(rsc, dt, dk, norm, vecSize);
+ e->incUserRef();
+ return e;
}
-RsElement rsi_ElementCreate(Context *rsc)
+RsElement rsi_ElementCreate2(Context *rsc,
+ size_t count,
+ const RsElement * ein,
+ const char ** names,
+ const size_t * nameLengths)
{
- ElementState * sec = &rsc->mStateElement;
- Element *se = new Element(rsc, sec->mComponentBuildList.size());
-
- rsAssert(se->getComponentCount() > 0);
-
- for (size_t ct = 0; ct < se->getComponentCount(); ct++) {
- se->setComponent(ct, sec->mComponentBuildList[ct]);
- }
-
- rsc->mStateElement.mComponentBuildList.clear();
- se->incUserRef();
- return se;
+ //LOGE("rsi_ElementCreate2 %i", count);
+ Element *e = Element::create(rsc, count, (const Element **)ein, names, nameLengths);
+ e->incUserRef();
+ return e;
}
diff --git a/libs/rs/rsElement.h b/libs/rs/rsElement.h
index b41c552d17c0..777e8ee9a8e7 100644
--- a/libs/rs/rsElement.h
+++ b/libs/rs/rsElement.h
@@ -18,6 +18,8 @@
#define ANDROID_STRUCTURED_ELEMENT_H
#include "rsComponent.h"
+#include "rsUtils.h"
+#include "rsObjectBase.h"
// ---------------------------------------------------------------------------
namespace android {
@@ -28,41 +30,57 @@ namespace renderscript {
class Element : public ObjectBase
{
public:
- Element(Context *, uint32_t count);
~Element();
-
- void setComponent(uint32_t idx, Component *c);
-
uint32_t getGLType() const;
uint32_t getGLFormat() const;
-
size_t getSizeBits() const;
size_t getSizeBytes() const {
return (getSizeBits() + 7) >> 3;
}
- size_t getComponentOffsetBits(uint32_t componentNumber) const;
- size_t getComponentOffsetBytes(uint32_t componentNumber) const {
- return (getComponentOffsetBits(componentNumber) + 7) >> 3;
+ size_t getFieldOffsetBits(uint32_t componentNumber) const;
+ size_t getFieldOffsetBytes(uint32_t componentNumber) const {
+ return (getFieldOffsetBits(componentNumber) + 7) >> 3;
}
- uint32_t getComponentCount() const {return mComponentCount;}
- Component * getComponent(uint32_t idx) const {return mComponents[idx].get();}
+ uint32_t getFieldCount() const {return mFieldCount;}
+ const Element * getField(uint32_t idx) const {return mFields[idx].e.get();}
+ const char * getFieldName(uint32_t idx) const {return mFields[idx].name.string();}
+
+ const Component & getComponent() const {return mComponent;}
+ RsDataType getType() const {return mComponent.getType();}
+ RsDataKind getKind() const {return mComponent.getKind();}
+ uint32_t getBits() const {return mBits;}
+ String8 getCType(uint32_t indent=0) const;
+ String8 getCStructBody(uint32_t indent=0) const;
+ String8 getGLSLType(uint32_t indent=0) const;
void dumpLOGV(const char *prefix) const;
+ 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.
void clear();
- size_t mComponentCount;
- ObjectBaseRef<Component> * mComponents;
- //uint32_t *mOffsetTable;
+ typedef struct {
+ String8 name;
+ ObjectBaseRef<const Element> e;
+ } ElementField_t;
+ ElementField_t *mFields;
+ size_t mFieldCount;
+
Element(Context *);
+
+ Component mComponent;
+ uint32_t mBits;
};
@@ -71,7 +89,6 @@ public:
ElementState();
~ElementState();
- Vector<Component *> mComponentBuildList;
};
diff --git a/libs/rs/rsFileA3D.cpp b/libs/rs/rsFileA3D.cpp
index c566665ab35a..e3272c5d68e9 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/rsProgram.cpp b/libs/rs/rsProgram.cpp
index 5f2a6097192e..656a3c339529 100644
--- a/libs/rs/rsProgram.cpp
+++ b/libs/rs/rsProgram.cpp
@@ -17,34 +17,245 @@
#include "rsContext.h"
#include "rsProgram.h"
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
using namespace android;
using namespace android::renderscript;
-Program::Program(Context *rsc, Element *in, Element *out) : ObjectBase(rsc)
+Program::Program(Context *rsc) : ObjectBase(rsc)
{
mAllocFile = __FILE__;
mAllocLine = __LINE__;
+ mDirty = true;
+ mShaderID = 0;
+ mAttribCount = 0;
+ mUniformCount = 0;
+
+ mInputElements = NULL;
+ mOutputElements = NULL;
+ mConstantTypes = NULL;
+ mInputCount = 0;
+ mOutputCount = 0;
+ mConstantCount = 0;
+}
+
+Program::Program(Context *rsc, const char * shaderText, uint32_t shaderLength,
+ const uint32_t * params, uint32_t paramLength) :
+ ObjectBase(rsc)
+{
+ mAllocFile = __FILE__;
+ mAllocLine = __LINE__;
+ mDirty = true;
+ mShaderID = 0;
+ mAttribCount = 0;
+ mUniformCount = 0;
+ mTextureCount = 0;
- mElementIn.set(in);
- mElementOut.set(out);
+ mInputCount = 0;
+ mOutputCount = 0;
+ mConstantCount = 0;
+
+ for (uint32_t ct=0; ct < paramLength; ct+=2) {
+ if (params[ct] == RS_PROGRAM_PARAM_INPUT) {
+ mInputCount++;
+ }
+ if (params[ct] == RS_PROGRAM_PARAM_OUTPUT) {
+ mOutputCount++;
+ }
+ if (params[ct] == RS_PROGRAM_PARAM_CONSTANT) {
+ mConstantCount++;
+ }
+ if (params[ct] == RS_PROGRAM_PARAM_TEXTURE_COUNT) {
+ mTextureCount = params[ct+1];
+ }
+ }
+
+ mInputElements = new ObjectBaseRef<Element>[mInputCount];
+ mOutputElements = new ObjectBaseRef<Element>[mOutputCount];
+ mConstantTypes = new ObjectBaseRef<Type>[mConstantCount];
+
+ uint32_t input = 0;
+ uint32_t output = 0;
+ uint32_t constant = 0;
+ for (uint32_t ct=0; ct < paramLength; ct+=2) {
+ if (params[ct] == RS_PROGRAM_PARAM_INPUT) {
+ mInputElements[input++].set(reinterpret_cast<Element *>(params[ct+1]));
+ }
+ if (params[ct] == RS_PROGRAM_PARAM_OUTPUT) {
+ mOutputElements[output++].set(reinterpret_cast<Element *>(params[ct+1]));
+ }
+ if (params[ct] == RS_PROGRAM_PARAM_CONSTANT) {
+ mConstantTypes[constant++].set(reinterpret_cast<Type *>(params[ct+1]));
+ }
+ }
+ mUserShader.setTo(shaderText, shaderLength);
}
Program::~Program()
{
+ for (uint32_t ct=0; ct < MAX_UNIFORMS; ct++) {
+ bindAllocation(NULL, ct);
+ }
+
+ delete[] mInputElements;
+ delete[] mOutputElements;
+ delete[] mConstantTypes;
+ mInputCount = 0;
+ mOutputCount = 0;
+ mConstantCount = 0;
+}
+
+
+void Program::bindAllocation(Allocation *alloc, uint32_t slot)
+{
+ if (mConstants[slot].get() == alloc) {
+ return;
+ }
+ if (mConstants[slot].get()) {
+ mConstants[slot].get()->removeProgramToDirty(this);
+ }
+ mConstants[slot].set(alloc);
+ if (alloc) {
+ alloc->addProgramToDirty(this);
+ }
+ mDirty = true;
}
+void Program::bindTexture(uint32_t slot, Allocation *a)
+{
+ if (slot >= MAX_TEXTURE) {
+ LOGE("Attempt to bind a texture to a slot > MAX_TEXTURE");
+ return;
+ }
+
+ //LOGE("bindtex %i %p", slot, a);
+ mTextures[slot].set(a);
+ mDirty = true;
+}
-void Program::bindAllocation(Allocation *alloc)
+void Program::bindSampler(uint32_t slot, Sampler *s)
{
- mConstants.set(alloc);
+ if (slot >= MAX_TEXTURE) {
+ LOGE("Attempt to bind a Sampler to a slot > MAX_TEXTURE");
+ return;
+ }
+
+ mSamplers[slot].set(s);
mDirty = true;
}
-void Program::checkUpdatedAllocation(const Allocation *alloc)
+String8 Program::getGLSLInputString() const
+{
+ String8 s;
+ for (uint32_t ct=0; ct < mInputCount; ct++) {
+ const Element *e = mInputElements[ct].get();
+ for (uint32_t field=0; field < e->getFieldCount(); field++) {
+ const Element *f = e->getField(field);
+
+ // Cannot be complex
+ rsAssert(!f->getFieldCount());
+ switch(f->getComponent().getVectorSize()) {
+ case 1: s.append("attribute float ATTRIB_"); break;
+ case 2: s.append("attribute vec2 ATTRIB_"); break;
+ case 3: s.append("attribute vec3 ATTRIB_"); break;
+ case 4: s.append("attribute vec4 ATTRIB_"); break;
+ default:
+ rsAssert(0);
+ }
+
+ s.append(e->getFieldName(field));
+ s.append(";\n");
+ }
+ }
+ return s;
+}
+
+String8 Program::getGLSLOutputString() const
+{
+ return String8();
+}
+
+String8 Program::getGLSLConstantString() const
+{
+ return String8();
+}
+
+
+void Program::createShader()
+{
+}
+
+bool Program::loadShader(Context *rsc, uint32_t type)
{
- if (mConstants.get() == alloc) {
- mDirty = true;
+ mShaderID = glCreateShader(type);
+ rsAssert(mShaderID);
+
+ if (rsc->props.mLogShaders) {
+ LOGV("Loading shader type %x, ID %i", type, mShaderID);
+ LOGV(mShader.string());
}
+
+ if (mShaderID) {
+ const char * ss = mShader.string();
+ glShaderSource(mShaderID, 1, &ss, NULL);
+ glCompileShader(mShaderID);
+
+ GLint compiled = 0;
+ glGetShaderiv(mShaderID, GL_COMPILE_STATUS, &compiled);
+ if (!compiled) {
+ GLint infoLen = 0;
+ glGetShaderiv(mShaderID, GL_INFO_LOG_LENGTH, &infoLen);
+ if (infoLen) {
+ char* buf = (char*) malloc(infoLen);
+ if (buf) {
+ glGetShaderInfoLog(mShaderID, infoLen, NULL, buf);
+ LOGE("Could not compile shader \n%s\n", buf);
+ free(buf);
+ }
+ glDeleteShader(mShaderID);
+ mShaderID = 0;
+ return false;
+ }
+ }
+ }
+
+ if (rsc->props.mLogShaders) {
+ LOGV("--Shader load result %x ", glGetError());
+ }
+ return true;
+}
+
+void Program::setShader(const char *txt, uint32_t len)
+{
+ mUserShader.setTo(txt, len);
+}
+
+
+
+namespace android {
+namespace renderscript {
+
+
+void rsi_ProgramBindConstants(Context *rsc, RsProgram vp, uint32_t slot, RsAllocation constants)
+{
+ Program *p = static_cast<Program *>(vp);
+ p->bindAllocation(static_cast<Allocation *>(constants), slot);
+}
+
+void rsi_ProgramBindTexture(Context *rsc, RsProgram vpf, uint32_t slot, RsAllocation a)
+{
+ Program *p = static_cast<Program *>(vpf);
+ p->bindTexture(slot, static_cast<Allocation *>(a));
+}
+
+void rsi_ProgramBindSampler(Context *rsc, RsProgram vpf, uint32_t slot, RsSampler s)
+{
+ Program *p = static_cast<Program *>(vpf);
+ p->bindSampler(slot, static_cast<Sampler *>(s));
+}
+
+}
}
diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h
index 57c654f28c97..238ee7fc5ac7 100644
--- a/libs/rs/rsProgram.h
+++ b/libs/rs/rsProgram.h
@@ -25,29 +25,78 @@ namespace android {
namespace renderscript {
+class ShaderCache;
class Program : public ObjectBase
{
public:
- Program(Context *, Element *in, Element *out);
+ const static uint32_t MAX_ATTRIBS = 8;
+ const static uint32_t MAX_UNIFORMS = 16;
+ const static uint32_t MAX_TEXTURE = 2;
+
+ Program(Context *);
+ Program(Context *, const char * shaderText, uint32_t shaderLength,
+ const uint32_t * params, uint32_t paramLength);
virtual ~Program();
- void bindAllocation(Allocation *);
- void checkUpdatedAllocation(const Allocation *);
+ void bindAllocation(Allocation *, uint32_t slot);
+ virtual void createShader();
+
+ bool isUserProgram() const {return mUserShader.size() > 0;}
+
+ void bindTexture(uint32_t slot, Allocation *);
+ void bindSampler(uint32_t slot, Sampler *);
+
+ uint32_t getShaderID() const {return mShaderID;}
+ void setShader(const char *, uint32_t len);
+
+ uint32_t getAttribCount() const {return mAttribCount;}
+ uint32_t getUniformCount() const {return mUniformCount;}
+ const String8 & getAttribName(uint32_t i) const {return mAttribNames[i];}
+ const String8 & getUniformName(uint32_t i) const {return mUniformNames[i];}
+
+ String8 getGLSLInputString() const;
+ String8 getGLSLOutputString() const;
+ String8 getGLSLConstantString() const;
+
+ const Allocation * getTexture(uint32_t i) const {return mTextures[i].get();}
protected:
// Components not listed in "in" will be passed though
// unless overwritten by components in out.
- ObjectBaseRef<Element> mElementIn;
- ObjectBaseRef<Element> mElementOut;
+ ObjectBaseRef<Element> *mInputElements;
+ ObjectBaseRef<Element> *mOutputElements;
+ ObjectBaseRef<Type> *mConstantTypes;
+ uint32_t mInputCount;
+ uint32_t mOutputCount;
+ uint32_t mConstantCount;
- ObjectBaseRef<Allocation> mConstants;
+ ObjectBaseRef<Allocation> mConstants[MAX_UNIFORMS];
mutable bool mDirty;
-
+ String8 mShader;
+ String8 mUserShader;
+ uint32_t mShaderID;
+
+ uint32_t mTextureCount;
+ uint32_t mAttribCount;
+ uint32_t mUniformCount;
+ String8 mAttribNames[MAX_ATTRIBS];
+ String8 mUniformNames[MAX_UNIFORMS];
+
+ // The difference between Textures and Constants is how they are accessed
+ // Texture lookups go though a sampler which in effect converts normalized
+ // coordinates into type specific. Multiple samples may also be taken
+ // and filtered.
+ //
+ // Constants are strictly accessed by programetic loads.
+ ObjectBaseRef<Allocation> mTextures[MAX_TEXTURE];
+ ObjectBaseRef<Sampler> mSamplers[MAX_TEXTURE];
+
+ bool loadShader(Context *, uint32_t type);
public:
- void forceDirty() {mDirty = true;}
+ void forceDirty() const {mDirty = true;}
};
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index 5f2dfae6b2c9..15f3269a6add 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -19,25 +19,50 @@
#include <GLES/gl.h>
#include <GLES/glext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
using namespace android;
using namespace android::renderscript;
-ProgramFragment::ProgramFragment(Context *rsc, Element *in, Element *out, bool pointSpriteEnable) :
- Program(rsc, in, out)
+ProgramFragment::ProgramFragment(Context *rsc, const uint32_t * params,
+ uint32_t paramLength) :
+ Program(rsc)
{
mAllocFile = __FILE__;
mAllocLine = __LINE__;
- for (uint32_t ct=0; ct < MAX_TEXTURE; ct++) {
- mEnvModes[ct] = RS_TEX_ENV_MODE_REPLACE;
- mTextureDimensions[ct] = 2;
- }
+ rsAssert(paramLength = 5);
+
+ mEnvModes[0] = (RsTexEnvMode)params[0];
+ mTextureFormats[0] = params[1];
+ mEnvModes[1] = (RsTexEnvMode)params[2];
+ mTextureFormats[1] = params[3];
+ mPointSpriteEnable = params[4] != 0;
+
mTextureEnableMask = 0;
- mPointSpriteEnable = pointSpriteEnable;
- mEnvModes[1] = RS_TEX_ENV_MODE_DECAL;
+ if (mEnvModes[0]) {
+ mTextureEnableMask |= 1;
+ }
+ if (mEnvModes[1]) {
+ mTextureEnableMask |= 2;
+ }
+ init(rsc);
}
+ProgramFragment::ProgramFragment(Context *rsc, const char * shaderText,
+ uint32_t shaderLength, const uint32_t * params,
+ uint32_t paramLength) :
+ Program(rsc, shaderText, shaderLength, params, paramLength)
+{
+ mAllocFile = __FILE__;
+ mAllocLine = __LINE__;
+
+ init(rsc);
+ mTextureEnableMask = (1 << mTextureCount) -1;
+}
+
+
ProgramFragment::~ProgramFragment()
{
}
@@ -65,23 +90,13 @@ void ProgramFragment::setupGL(const Context *rsc, ProgramFragmentState *state)
}
glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, mPointSpriteEnable);
}
-
- rsAssert(mTextures[ct]->getTextureID() != 0);
- if (mTextures[ct]->getTextureID() == 0) {
- // This is a hack for eclair to try to fix the white squares bug.
- Allocation *a = (Allocation *)mTextures[ct].get();
- a->uploadToTexture((Context *)rsc, 0);
- if (mTextures[ct]->getTextureID() == 0) {
- // At this point we are screwed. Crash to restart the app.
- rsc->dumpDebug();
- LOGE("Multiple failures during texture upload. Driver appears wedged.");
- ((char *)0)[0] = 0;
- }
-
- }
+ mTextures[ct]->uploadCheck(rsc);
glBindTexture(GL_TEXTURE_2D, mTextures[ct]->getTextureID());
switch(mEnvModes[ct]) {
+ case RS_TEX_ENV_MODE_NONE:
+ rsAssert(0);
+ break;
case RS_TEX_ENV_MODE_REPLACE:
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
break;
@@ -94,7 +109,7 @@ void ProgramFragment::setupGL(const Context *rsc, ProgramFragmentState *state)
}
if (mSamplers[ct].get()) {
- mSamplers[ct]->setupGL();
+ mSamplers[ct]->setupGL(rsc);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -121,73 +136,158 @@ void ProgramFragment::setupGL(const Context *rsc, ProgramFragmentState *state)
}
glActiveTexture(GL_TEXTURE0);
mDirty = false;
+ rsc->checkError("ProgramFragment::setupGL");
}
-
-void ProgramFragment::bindTexture(uint32_t slot, Allocation *a)
+void ProgramFragment::setupGL2(const Context *rsc, ProgramFragmentState *state, ShaderCache *sc)
{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to bind a texture to a slot > MAX_TEXTURE");
- return;
+
+ //LOGE("sgl2 frag1 %x", glGetError());
+ if ((state->mLast.get() == this) && !mDirty) {
+ //return;
}
+ state->mLast.set(this);
- //LOGE("bindtex %i %p", slot, a);
- mTextures[slot].set(a);
- mDirty = true;
-}
+ rsc->checkError("ProgramFragment::setupGL2 start");
+ for (uint32_t ct=0; ct < MAX_TEXTURE; ct++) {
+ glActiveTexture(GL_TEXTURE0 + ct);
+ if (!(mTextureEnableMask & (1 << ct)) || !mTextures[ct].get()) {
+ continue;
+ }
-void ProgramFragment::bindSampler(uint32_t slot, Sampler *s)
-{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to bind a Sampler to a slot > MAX_TEXTURE");
- return;
+ mTextures[ct]->uploadCheck(rsc);
+ glBindTexture(GL_TEXTURE_2D, mTextures[ct]->getTextureID());
+ rsc->checkError("ProgramFragment::setupGL2 tex bind");
+ if (mSamplers[ct].get()) {
+ mSamplers[ct]->setupGL(rsc);
+ } else {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ rsc->checkError("ProgramFragment::setupGL2 tex env");
+ }
+
+ glUniform1i(sc->fragUniformSlot(ct), ct);
+ rsc->checkError("ProgramFragment::setupGL2 uniforms");
}
- mSamplers[slot].set(s);
- mDirty = true;
+ glActiveTexture(GL_TEXTURE0);
+ mDirty = false;
+ rsc->checkError("ProgramFragment::setupGL2");
+}
+
+void ProgramFragment::loadShader(Context *rsc) {
+ Program::loadShader(rsc, GL_FRAGMENT_SHADER);
}
-void ProgramFragment::setType(uint32_t slot, const Element *e, uint32_t dim)
+void ProgramFragment::createShader()
{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to setType to a slot > MAX_TEXTURE");
- return;
- }
+ mShader.setTo("precision mediump float;\n");
+ mShader.append("varying vec4 varColor;\n");
+ mShader.append("varying vec4 varTex0;\n");
+
+ if (mUserShader.length() > 1) {
+ for (uint32_t ct=0; ct < mTextureCount; ct++) {
+ char buf[256];
+ sprintf(buf, "uniform sampler2D uni_Tex%i;\n", ct);
+ mShader.append(buf);
+ }
- if (dim >= 4) {
- LOGE("Attempt to setType to a dimension > 3");
- return;
- }
+ mShader.append(mUserShader);
+ } else {
+ uint32_t mask = mTextureEnableMask;
+ uint32_t texNum = 0;
+ while (mask) {
+ if (mask & 1) {
+ char buf[64];
+ mShader.append("uniform sampler2D uni_Tex");
+ sprintf(buf, "%i", texNum);
+ mShader.append(buf);
+ mShader.append(";\n");
+ }
+ mask >>= 1;
+ texNum++;
+ }
- mTextureFormats[slot].set(e);
- mTextureDimensions[slot] = dim;
-}
-void ProgramFragment::setEnvMode(uint32_t slot, RsTexEnvMode env)
-{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to setEnvMode to a slot > MAX_TEXTURE");
- return;
- }
+ mShader.append("void main() {\n");
+ mShader.append(" vec4 col = varColor;\n");
- mEnvModes[slot] = env;
-}
+ if (mTextureEnableMask) {
+ if (mPointSpriteEnable) {
+ mShader.append(" vec2 t0 = gl_PointCoord;\n");
+ } else {
+ mShader.append(" vec2 t0 = varTex0.xy;\n");
+ }
+ }
-void ProgramFragment::setTexEnable(uint32_t slot, bool enable)
-{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to setEnvMode to a slot > MAX_TEXTURE");
- return;
- }
+ mask = mTextureEnableMask;
+ texNum = 0;
+ while (mask) {
+ if (mask & 1) {
+ switch(mEnvModes[texNum]) {
+ case RS_TEX_ENV_MODE_NONE:
+ rsAssert(0);
+ break;
+ case RS_TEX_ENV_MODE_REPLACE:
+ 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:
+ 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, t0);\n");
+ break;
+ }
- uint32_t bit = 1 << slot;
- mTextureEnableMask &= ~bit;
- if (enable) {
- mTextureEnableMask |= bit;
+ }
+ mask >>= 1;
+ texNum++;
+ }
+
+ //mShader.append(" col.a = 1.0;\n");
+ //mShader.append(" col.r = 0.5;\n");
+
+ mShader.append(" gl_FragColor = col;\n");
+ mShader.append("}\n");
}
}
+void ProgramFragment::init(Context *rsc)
+{
+ mUniformCount = 2;
+ mUniformNames[0].setTo("uni_Tex0");
+ mUniformNames[1].setTo("uni_Tex1");
+ createShader();
+}
ProgramFragmentState::ProgramFragmentState()
{
@@ -202,8 +302,14 @@ ProgramFragmentState::~ProgramFragmentState()
void ProgramFragmentState::init(Context *rsc, int32_t w, int32_t h)
{
- ProgramFragment *pf = new ProgramFragment(rsc, NULL, NULL, false);
+ uint32_t tmp[5] = {
+ RS_TEX_ENV_MODE_NONE, 0,
+ RS_TEX_ENV_MODE_NONE, 0,
+ 0
+ };
+ ProgramFragment *pf = new ProgramFragment(rsc, tmp, 5);
mDefault.set(pf);
+ pf->init(rsc);
}
void ProgramFragmentState::deinit(Context *rsc)
@@ -216,50 +322,24 @@ void ProgramFragmentState::deinit(Context *rsc)
namespace android {
namespace renderscript {
-void rsi_ProgramFragmentBegin(Context * rsc, RsElement in, RsElement out, bool pointSpriteEnable)
+RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc,
+ const uint32_t * params,
+ uint32_t paramLength)
{
- delete rsc->mStateFragment.mPF;
- rsc->mStateFragment.mPF = new ProgramFragment(rsc, (Element *)in, (Element *)out, pointSpriteEnable);
-}
-
-void rsi_ProgramFragmentBindTexture(Context *rsc, RsProgramFragment vpf, uint32_t slot, RsAllocation a)
-{
- ProgramFragment *pf = static_cast<ProgramFragment *>(vpf);
- pf->bindTexture(slot, static_cast<Allocation *>(a));
-}
-
-void rsi_ProgramFragmentBindSampler(Context *rsc, RsProgramFragment vpf, uint32_t slot, RsSampler s)
-{
- ProgramFragment *pf = static_cast<ProgramFragment *>(vpf);
- pf->bindSampler(slot, static_cast<Sampler *>(s));
-}
-
-void rsi_ProgramFragmentSetSlot(Context *rsc, uint32_t slot, bool enable, RsTexEnvMode env, RsType vt)
-{
- const Type *t = static_cast<const Type *>(vt);
- if (t) {
- uint32_t dim = 1;
- if (t->getDimY()) {
- dim ++;
- if (t->getDimZ()) {
- dim ++;
- }
- }
- rsc->mStateFragment.mPF->setType(slot, t->getElement(), dim);
- }
- rsc->mStateFragment.mPF->setEnvMode(slot, env);
- rsc->mStateFragment.mPF->setTexEnable(slot, enable);
+ ProgramFragment *pf = new ProgramFragment(rsc, params, paramLength);
+ pf->incUserRef();
+ return pf;
}
-RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc)
+RsProgramFragment rsi_ProgramFragmentCreate2(Context *rsc, const char * shaderText,
+ uint32_t shaderLength, const uint32_t * params,
+ uint32_t paramLength)
{
- ProgramFragment *pf = rsc->mStateFragment.mPF;
+ ProgramFragment *pf = new ProgramFragment(rsc, shaderText, shaderLength, params, paramLength);
pf->incUserRef();
- rsc->mStateFragment.mPF = 0;
return pf;
}
-
}
}
diff --git a/libs/rs/rsProgramFragment.h b/libs/rs/rsProgramFragment.h
index e26c6e8a35fd..9fa565d4cf8d 100644
--- a/libs/rs/rsProgramFragment.h
+++ b/libs/rs/rsProgramFragment.h
@@ -28,40 +28,23 @@ class ProgramFragmentState;
class ProgramFragment : public Program
{
public:
- const static uint32_t MAX_TEXTURE = 2;
-
-
-
- ProgramFragment(Context *, Element *in, Element *out, bool pointSpriteEnable);
+ ProgramFragment(Context *, const uint32_t * params, uint32_t paramLength);
+ ProgramFragment(Context *rsc, const char * shaderText,
+ uint32_t shaderLength, const uint32_t * params,
+ uint32_t paramLength);
virtual ~ProgramFragment();
virtual void setupGL(const Context *, ProgramFragmentState *);
+ virtual void setupGL2(const Context *, ProgramFragmentState *, ShaderCache *sc);
-
-
- void bindTexture(uint32_t slot, Allocation *);
- void bindSampler(uint32_t slot, Sampler *);
- void setType(uint32_t slot, const Element *, uint32_t dim);
-
- void setEnvMode(uint32_t slot, RsTexEnvMode);
- void setTexEnable(uint32_t slot, bool);
-
-
+ virtual void createShader();
+ virtual void loadShader(Context *rsc);
+ virtual void init(Context *rsc);
protected:
- // The difference between Textures and Constants is how they are accessed
- // Texture lookups go though a sampler which in effect converts normalized
- // coordinates into type specific. Multiple samples may also be taken
- // and filtered.
- //
- // Constants are strictly accessed by programetic loads.
- ObjectBaseRef<Allocation> mTextures[MAX_TEXTURE];
- ObjectBaseRef<Sampler> mSamplers[MAX_TEXTURE];
- ObjectBaseRef<const Element> mTextureFormats[MAX_TEXTURE];
- uint32_t mTextureDimensions[MAX_TEXTURE];
-
-
// Hacks to create a program for now
+ uint32_t mTextureFormats[MAX_TEXTURE];
+ uint32_t mTextureDimensions[MAX_TEXTURE];
RsTexEnvMode mEnvModes[MAX_TEXTURE];
uint32_t mTextureEnableMask;
bool mPointSpriteEnable;
diff --git a/libs/rs/rsProgramFragmentStore.cpp b/libs/rs/rsProgramFragmentStore.cpp
index de33d9c5ed04..8a2157f3c0b2 100644
--- a/libs/rs/rsProgramFragmentStore.cpp
+++ b/libs/rs/rsProgramFragmentStore.cpp
@@ -24,8 +24,8 @@ using namespace android;
using namespace android::renderscript;
-ProgramFragmentStore::ProgramFragmentStore(Context *rsc, Element *in, Element *out) :
- Program(rsc, in, out)
+ProgramFragmentStore::ProgramFragmentStore(Context *rsc) :
+ Program(rsc)
{
mAllocFile = __FILE__;
mAllocLine = __LINE__;
@@ -83,10 +83,44 @@ void ProgramFragmentStore::setupGL(const Context *rsc, ProgramFragmentStoreState
} else {
glDisable(GL_DITHER);
}
+}
+void ProgramFragmentStore::setupGL2(const Context *rsc, ProgramFragmentStoreState *state)
+{
+ if (state->mLast.get() == this) {
+ return;
+ }
+ state->mLast.set(this);
+
+ glColorMask(mColorRWriteEnable,
+ mColorGWriteEnable,
+ mColorBWriteEnable,
+ mColorAWriteEnable);
+ if (mBlendEnable) {
+ glEnable(GL_BLEND);
+ glBlendFunc(mBlendSrc, mBlendDst);
+ } else {
+ glDisable(GL_BLEND);
+ }
+ //LOGE("pfs %i, %i, %x", mDepthWriteEnable, mDepthTestEnable, mDepthFunc);
+
+ glDepthMask(mDepthWriteEnable);
+ if(mDepthTestEnable || mDepthWriteEnable) {
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(mDepthFunc);
+ } else {
+ glDisable(GL_DEPTH_TEST);
+ }
+
+ if (mDitherEnable) {
+ glEnable(GL_DITHER);
+ } else {
+ glDisable(GL_DITHER);
+ }
}
+
void ProgramFragmentStore::setDitherEnable(bool enable)
{
mDitherEnable = enable;
@@ -215,7 +249,7 @@ ProgramFragmentStoreState::~ProgramFragmentStoreState()
void ProgramFragmentStoreState::init(Context *rsc, int32_t w, int32_t h)
{
- ProgramFragmentStore *pfs = new ProgramFragmentStore(rsc, NULL, NULL);
+ ProgramFragmentStore *pfs = new ProgramFragmentStore(rsc);
mDefault.set(pfs);
}
@@ -232,7 +266,7 @@ namespace renderscript {
void rsi_ProgramFragmentStoreBegin(Context * rsc, RsElement in, RsElement out)
{
delete rsc->mStateFragmentStore.mPFS;
- rsc->mStateFragmentStore.mPFS = new ProgramFragmentStore(rsc, (Element *)in, (Element *)out);
+ rsc->mStateFragmentStore.mPFS = new ProgramFragmentStore(rsc);
}
diff --git a/libs/rs/rsProgramFragmentStore.h b/libs/rs/rsProgramFragmentStore.h
index a3443873c91f..3412c9918ac1 100644
--- a/libs/rs/rsProgramFragmentStore.h
+++ b/libs/rs/rsProgramFragmentStore.h
@@ -28,10 +28,11 @@ class ProgramFragmentStoreState;
class ProgramFragmentStore : public Program
{
public:
- ProgramFragmentStore(Context *, Element *in, Element *out);
+ ProgramFragmentStore(Context *);
virtual ~ProgramFragmentStore();
virtual void setupGL(const Context *, ProgramFragmentStoreState *);
+ virtual void setupGL2(const Context *, ProgramFragmentStoreState *);
void setDepthFunc(RsDepthFunc);
void setDepthMask(bool);
diff --git a/libs/rs/rsProgramRaster.cpp b/libs/rs/rsProgramRaster.cpp
index 51ae7cf61f16..13887d15e74e 100644
--- a/libs/rs/rsProgramRaster.cpp
+++ b/libs/rs/rsProgramRaster.cpp
@@ -25,12 +25,10 @@ using namespace android::renderscript;
ProgramRaster::ProgramRaster(Context *rsc,
- Element *in,
- Element *out,
bool pointSmooth,
bool lineSmooth,
bool pointSprite) :
- Program(rsc, in, out)
+ Program(rsc)
{
mAllocFile = __FILE__;
mAllocLine = __LINE__;
@@ -86,6 +84,14 @@ void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
}
}
+void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state)
+{
+ if (state->mLast.get() == this) {
+ return;
+ }
+ state->mLast.set(this);
+}
+
ProgramRasterState::ProgramRasterState()
@@ -98,7 +104,7 @@ ProgramRasterState::~ProgramRasterState()
void ProgramRasterState::init(Context *rsc, int32_t w, int32_t h)
{
- ProgramRaster *pr = new ProgramRaster(rsc, NULL, NULL, false, false, false);
+ ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
mDefault.set(pr);
}
@@ -118,8 +124,6 @@ RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement o
bool pointSprite)
{
ProgramRaster *pr = new ProgramRaster(rsc,
- static_cast<Element *>(in),
- static_cast<Element *>(out),
pointSmooth,
lineSmooth,
pointSprite);
diff --git a/libs/rs/rsProgramRaster.h b/libs/rs/rsProgramRaster.h
index a6d5ba8e5850..c3a9c9077866 100644
--- a/libs/rs/rsProgramRaster.h
+++ b/libs/rs/rsProgramRaster.h
@@ -29,14 +29,13 @@ class ProgramRaster : public Program
{
public:
ProgramRaster(Context *rsc,
- Element *in,
- Element *out,
bool pointSmooth,
bool lineSmooth,
bool pointSprite);
virtual ~ProgramRaster();
virtual void setupGL(const Context *, ProgramRasterState *);
+ virtual void setupGL2(const Context *, ProgramRasterState *);
void setLineWidth(float w);
void setPointSize(float s);
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index 68f589f45f82..28f13d4ef059 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -19,18 +19,34 @@
#include <GLES/gl.h>
#include <GLES/glext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
using namespace android;
using namespace android::renderscript;
-ProgramVertex::ProgramVertex(Context *rsc, Element *in, Element *out) :
- Program(rsc, in, out)
+ProgramVertex::ProgramVertex(Context *rsc, bool texMat) :
+ Program(rsc)
+{
+ mAllocFile = __FILE__;
+ mAllocLine = __LINE__;
+ mTextureMatrixEnable = texMat;
+ mLightCount = 0;
+ init(rsc);
+}
+
+ProgramVertex::ProgramVertex(Context *rsc, const char * shaderText,
+ uint32_t shaderLength, const uint32_t * params,
+ uint32_t paramLength) :
+ Program(rsc, shaderText, shaderLength, params, paramLength)
{
mAllocFile = __FILE__;
mAllocLine = __LINE__;
mTextureMatrixEnable = false;
mLightCount = 0;
+
+ init(rsc);
}
ProgramVertex::~ProgramVertex()
@@ -40,10 +56,10 @@ ProgramVertex::~ProgramVertex()
static void logMatrix(const char *txt, const float *f)
{
LOGV("Matrix %s, %p", txt, f);
- LOGV("%6.2f, %6.2f, %6.2f, %6.2f", f[0], f[4], f[8], f[12]);
- LOGV("%6.2f, %6.2f, %6.2f, %6.2f", f[1], f[5], f[9], f[13]);
- LOGV("%6.2f, %6.2f, %6.2f, %6.2f", f[2], f[6], f[10], f[14]);
- LOGV("%6.2f, %6.2f, %6.2f, %6.2f", f[3], f[7], f[11], f[15]);
+ LOGV("%6.4f, %6.4f, %6.4f, %6.4f", f[0], f[4], f[8], f[12]);
+ LOGV("%6.4f, %6.4f, %6.4f, %6.4f", f[1], f[5], f[9], f[13]);
+ LOGV("%6.4f, %6.4f, %6.4f, %6.4f", f[2], f[6], f[10], f[14]);
+ LOGV("%6.4f, %6.4f, %6.4f, %6.4f", f[3], f[7], f[11], f[15]);
}
void ProgramVertex::setupGL(const Context *rsc, ProgramVertexState *state)
@@ -53,7 +69,7 @@ void ProgramVertex::setupGL(const Context *rsc, ProgramVertexState *state)
}
state->mLast.set(this);
- const float *f = static_cast<const float *>(mConstants->getPtr());
+ const float *f = static_cast<const float *>(mConstants[0]->getPtr());
glMatrixMode(GL_TEXTURE);
if (mTextureMatrixEnable) {
@@ -92,6 +108,172 @@ void ProgramVertex::setupGL(const Context *rsc, ProgramVertexState *state)
mDirty = false;
}
+void ProgramVertex::loadShader(Context *rsc) {
+ Program::loadShader(rsc, GL_VERTEX_SHADER);
+}
+
+void ProgramVertex::createShader()
+{
+ mShader.setTo("");
+
+ mShader.append("varying vec4 varColor;\n");
+ mShader.append("varying vec4 varTex0;\n");
+
+ if (mUserShader.length() > 1) {
+ mShader.append("uniform mat4 ");
+ mShader.append(mUniformNames[0]);
+ mShader.append(";\n");
+
+ for (uint32_t ct=0; ct < mConstantCount; ct++) {
+ const Element *e = mConstantTypes[ct]->getElement();
+ for (uint32_t field=0; field < e->getFieldCount(); field++) {
+ const Element *f = e->getField(field);
+
+ // Cannot be complex
+ rsAssert(!f->getFieldCount());
+ switch(f->getComponent().getVectorSize()) {
+ case 1: mShader.append("uniform float UNI_"); break;
+ case 2: mShader.append("uniform vec2 UNI_"); break;
+ case 3: mShader.append("uniform vec3 UNI_"); break;
+ case 4: mShader.append("uniform vec4 UNI_"); break;
+ default:
+ rsAssert(0);
+ }
+
+ mShader.append(e->getFieldName(field));
+ mShader.append(";\n");
+ }
+ }
+
+
+ for (uint32_t ct=0; ct < mInputCount; ct++) {
+ const Element *e = mInputElements[ct].get();
+ for (uint32_t field=0; field < e->getFieldCount(); field++) {
+ const Element *f = e->getField(field);
+
+ // Cannot be complex
+ rsAssert(!f->getFieldCount());
+ switch(f->getComponent().getVectorSize()) {
+ case 1: mShader.append("attribute float ATTRIB_"); break;
+ case 2: mShader.append("attribute vec2 ATTRIB_"); break;
+ case 3: mShader.append("attribute vec3 ATTRIB_"); break;
+ case 4: mShader.append("attribute vec4 ATTRIB_"); break;
+ default:
+ rsAssert(0);
+ }
+
+ mShader.append(e->getFieldName(field));
+ mShader.append(";\n");
+ }
+ }
+ mShader.append(mUserShader);
+ } else {
+ mShader.append("attribute vec4 ATTRIB_LegacyPosition;\n");
+ mShader.append("attribute vec4 ATTRIB_LegacyColor;\n");
+ mShader.append("attribute vec3 ATTRIB_LegacyNormal;\n");
+ mShader.append("attribute float ATTRIB_LegacyPointSize;\n");
+ mShader.append("attribute vec4 ATTRIB_LegacyTexture;\n");
+
+ for (uint32_t ct=0; ct < mUniformCount; ct++) {
+ mShader.append("uniform mat4 ");
+ mShader.append(mUniformNames[ct]);
+ mShader.append(";\n");
+ }
+
+ mShader.append("void main() {\n");
+ mShader.append(" gl_Position = UNI_MVP * ATTRIB_LegacyPosition;\n");
+ mShader.append(" gl_PointSize = ATTRIB_LegacyPointSize;\n");
+
+ mShader.append(" varColor = ATTRIB_LegacyColor;\n");
+ if (mTextureMatrixEnable) {
+ mShader.append(" varTex0 = UNI_TexMatrix * ATTRIB_LegacyTexture;\n");
+ } else {
+ mShader.append(" varTex0 = ATTRIB_LegacyTexture;\n");
+ }
+ //mShader.append(" pos.x = pos.x / 480.0;\n");
+ //mShader.append(" pos.y = pos.y / 800.0;\n");
+ //mShader.append(" gl_Position = pos;\n");
+ mShader.append("}\n");
+ }
+}
+
+void ProgramVertex::setupGL2(const Context *rsc, ProgramVertexState *state, ShaderCache *sc)
+{
+ //LOGE("sgl2 vtx1 %x", glGetError());
+ if ((state->mLast.get() == this) && !mDirty) {
+ //return;
+ }
+
+ rsc->checkError("ProgramVertex::setupGL2 start");
+ glVertexAttrib4f(1, state->color[0], state->color[1], state->color[2], state->color[3]);
+
+ const float *f = static_cast<const float *>(mConstants[0]->getPtr());
+
+ Matrix mvp;
+ mvp.load(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]);
+ Matrix t;
+ t.load(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET]);
+ mvp.multiply(&t);
+
+ glUniformMatrix4fv(sc->vtxUniformSlot(0), 1, GL_FALSE, mvp.m);
+ if (mTextureMatrixEnable) {
+ glUniformMatrix4fv(sc->vtxUniformSlot(1), 1, GL_FALSE,
+ &f[RS_PROGRAM_VERTEX_TEXTURE_OFFSET]);
+ }
+
+ rsc->checkError("ProgramVertex::setupGL2 begin uniforms");
+ uint32_t uidx = 1;
+ for (uint32_t ct=0; ct < mConstantCount; ct++) {
+ Allocation *alloc = mConstants[ct+1].get();
+ if (!alloc) {
+ continue;
+ }
+
+ const uint8_t *data = static_cast<const uint8_t *>(alloc->getPtr());
+ const Element *e = mConstantTypes[ct]->getElement();
+ for (uint32_t field=0; field < e->getFieldCount(); field++) {
+ const Element *f = e->getField(field);
+ uint32_t offset = e->getFieldOffsetBytes(field);
+ int32_t slot = sc->vtxUniformSlot(uidx);
+
+ const float *fd = reinterpret_cast<const float *>(&data[offset]);
+
+ //LOGE("Uniform slot=%i, offset=%i, constant=%i, field=%i, uidx=%i", slot, offset, ct, field, uidx);
+ if (slot >= 0) {
+ switch(f->getComponent().getVectorSize()) {
+ case 1:
+ //LOGE("Uniform 1 = %f", fd[0]);
+ glUniform1fv(slot, 1, fd);
+ break;
+ case 2:
+ //LOGE("Uniform 2 = %f %f", fd[0], fd[1]);
+ glUniform2fv(slot, 1, fd);
+ break;
+ case 3:
+ //LOGE("Uniform 3 = %f %f %f", fd[0], fd[1], fd[2]);
+ glUniform3fv(slot, 1, fd);
+ break;
+ case 4:
+ //LOGE("Uniform 4 = %f %f %f %f", fd[0], fd[1], fd[2], fd[3]);
+ glUniform4fv(slot, 1, fd);
+ break;
+ default:
+ rsAssert(0);
+ }
+ }
+ uidx ++;
+ }
+ }
+
+ for (uint32_t ct=0; ct < mConstantCount; ct++) {
+ uint32_t glSlot = sc->vtxUniformSlot(ct + 1);
+
+ }
+
+ state->mLast.set(this);
+ rsc->checkError("ProgramVertex::setupGL2");
+}
+
void ProgramVertex::addLight(const Light *l)
{
if (mLightCount < MAX_LIGHTS) {
@@ -102,60 +284,103 @@ void ProgramVertex::addLight(const Light *l)
void ProgramVertex::setProjectionMatrix(const rsc_Matrix *m) const
{
- float *f = static_cast<float *>(mConstants->getPtr());
+ float *f = static_cast<float *>(mConstants[0]->getPtr());
memcpy(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], m, sizeof(rsc_Matrix));
mDirty = true;
}
void ProgramVertex::setModelviewMatrix(const rsc_Matrix *m) const
{
- float *f = static_cast<float *>(mConstants->getPtr());
+ float *f = static_cast<float *>(mConstants[0]->getPtr());
memcpy(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET], m, sizeof(rsc_Matrix));
mDirty = true;
}
void ProgramVertex::setTextureMatrix(const rsc_Matrix *m) const
{
- float *f = static_cast<float *>(mConstants->getPtr());
+ float *f = static_cast<float *>(mConstants[0]->getPtr());
memcpy(&f[RS_PROGRAM_VERTEX_TEXTURE_OFFSET], m, sizeof(rsc_Matrix));
mDirty = true;
}
void ProgramVertex::transformToScreen(const Context *rsc, float *v4out, const float *v3in) const
{
- float *f = static_cast<float *>(mConstants->getPtr());
+ float *f = static_cast<float *>(mConstants[0]->getPtr());
Matrix mvp;
mvp.loadMultiply((Matrix *)&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET],
(Matrix *)&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]);
mvp.vectorMultiply(v4out, v3in);
}
+void ProgramVertex::initAddUserElement(const Element *e, String8 *names, uint32_t *count, const char *prefix)
+{
+ rsAssert(e->getFieldCount());
+ for (uint32_t ct=0; ct < e->getFieldCount(); ct++) {
+ const Element *ce = e->getField(ct);
+ if (ce->getFieldCount()) {
+ initAddUserElement(ce, names, count, prefix);
+ } else {
+ String8 tmp(prefix);
+ tmp.append(e->getFieldName(ct));
+ names[*count].setTo(tmp.string());
+ (*count)++;
+ }
+ }
+}
+
+
+void ProgramVertex::init(Context *rsc)
+{
+ mAttribCount = 0;
+ if (mUserShader.size() > 0) {
+ for (uint32_t ct=0; ct < mInputCount; ct++) {
+ initAddUserElement(mInputElements[ct].get(), mAttribNames, &mAttribCount, "ATTRIB_");
+ }
+
+ mUniformCount = 1;
+ mUniformNames[0].setTo("UNI_MVP");
+ for (uint32_t ct=0; ct < mConstantCount; ct++) {
+ initAddUserElement(mConstantTypes[ct]->getElement(), mUniformNames, &mUniformCount, "UNI_");
+ }
+ } else {
+ mUniformCount = 2;
+ mUniformNames[0].setTo("UNI_MVP");
+ mUniformNames[1].setTo("UNI_TexMatrix");
+ }
+
+ createShader();
+}
+
+
+///////////////////////////////////////////////////////////////////////
+
ProgramVertexState::ProgramVertexState()
{
- mPV = NULL;
}
ProgramVertexState::~ProgramVertexState()
{
- delete mPV;
}
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);
mAllocType.set((Type *)rsi_TypeCreate(rsc));
- ProgramVertex *pv = new ProgramVertex(rsc, NULL, NULL);
+ ProgramVertex *pv = new ProgramVertex(rsc, false);
Allocation *alloc = (Allocation *)rsi_AllocationCreateTyped(rsc, mAllocType.get());
mDefaultAlloc.set(alloc);
mDefault.set(pv);
+ pv->init(rsc);
+ pv->bindAllocation(alloc, 0);
- pv->bindAllocation(alloc);
+ color[0] = 1.f;
+ color[1] = 1.f;
+ color[2] = 1.f;
+ color[3] = 1.f;
updateSize(rsc, w, h);
}
@@ -176,42 +401,27 @@ void ProgramVertexState::deinit(Context *rsc)
mDefault.clear();
mAllocType.clear();
mLast.clear();
- delete mPV;
- mPV = NULL;
}
namespace android {
namespace renderscript {
-void rsi_ProgramVertexBegin(Context *rsc, RsElement in, RsElement out)
-{
- delete rsc->mStateVertex.mPV;
- rsc->mStateVertex.mPV = new ProgramVertex(rsc, (Element *)in, (Element *)out);
-}
-RsProgramVertex rsi_ProgramVertexCreate(Context *rsc)
+RsProgramVertex rsi_ProgramVertexCreate(Context *rsc, bool texMat)
{
- ProgramVertex *pv = rsc->mStateVertex.mPV;
+ ProgramVertex *pv = new ProgramVertex(rsc, texMat);
pv->incUserRef();
- rsc->mStateVertex.mPV = 0;
return pv;
}
-void rsi_ProgramVertexBindAllocation(Context *rsc, RsProgramVertex vpgm, RsAllocation constants)
+RsProgramVertex rsi_ProgramVertexCreate2(Context *rsc, const char * shaderText,
+ uint32_t shaderLength, const uint32_t * params,
+ uint32_t paramLength)
{
- ProgramVertex *pv = static_cast<ProgramVertex *>(vpgm);
- pv->bindAllocation(static_cast<Allocation *>(constants));
-}
-
-void rsi_ProgramVertexSetTextureMatrixEnable(Context *rsc, bool enable)
-{
- rsc->mStateVertex.mPV->setTextureMatrixEnable(enable);
-}
-
-void rsi_ProgramVertexAddLight(Context *rsc, RsLight light)
-{
- rsc->mStateVertex.mPV->addLight(static_cast<const Light *>(light));
+ ProgramVertex *pv = new ProgramVertex(rsc, shaderText, shaderLength, params, paramLength);
+ pv->incUserRef();
+ return pv;
}
diff --git a/libs/rs/rsProgramVertex.h b/libs/rs/rsProgramVertex.h
index a97ba3825ff0..28554cc813d6 100644
--- a/libs/rs/rsProgramVertex.h
+++ b/libs/rs/rsProgramVertex.h
@@ -30,10 +30,13 @@ class ProgramVertex : public Program
public:
const static uint32_t MAX_LIGHTS = 8;
- ProgramVertex(Context *, Element *in, Element *out);
+ ProgramVertex(Context *,const char * shaderText, uint32_t shaderLength,
+ const uint32_t * params, uint32_t paramLength);
+ ProgramVertex(Context *, bool texMat);
virtual ~ProgramVertex();
virtual void setupGL(const Context *rsc, ProgramVertexState *state);
+ virtual void setupGL2(const Context *rsc, ProgramVertexState *state, ShaderCache *sc);
void setTextureMatrixEnable(bool e) {mTextureMatrixEnable = e;}
@@ -45,6 +48,10 @@ public:
void transformToScreen(const Context *, float *v4out, const float *v3in) const;
+ virtual void createShader();
+ virtual void loadShader(Context *);
+ virtual void init(Context *);
+
protected:
uint32_t mLightCount;
@@ -52,6 +59,9 @@ protected:
// Hacks to create a program for now
bool mTextureMatrixEnable;
+
+private:
+ void initAddUserElement(const Element *e, String8 *names, uint32_t *count, const char *prefix);
};
@@ -71,11 +81,8 @@ public:
ObjectBaseRef<Type> mAllocType;
- ProgramVertex *mPV;
-
- //ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE];
-
+ float color[4];
};
diff --git a/libs/rs/rsSampler.cpp b/libs/rs/rsSampler.cpp
index b7937507664d..7552d544659f 100644
--- a/libs/rs/rsSampler.cpp
+++ b/libs/rs/rsSampler.cpp
@@ -53,7 +53,7 @@ Sampler::~Sampler()
{
}
-void Sampler::setupGL()
+void Sampler::setupGL(const Context *rsc)
{
GLenum trans[] = {
GL_NEAREST, //RS_SAMPLER_NEAREST,
@@ -64,12 +64,12 @@ void Sampler::setupGL()
};
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, trans[mMinFilter]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, trans[mMagFilter]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, trans[mWrapS]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, trans[mWrapT]);
+ rsc->checkError("ProgramFragment::setupGL2 tex env");
}
void Sampler::bindToContext(SamplerState *ss, uint32_t slot)
@@ -84,18 +84,18 @@ void Sampler::unbindFromContext(SamplerState *ss)
mBoundSlot = -1;
ss->mSamplers[slot].clear();
}
-
+/*
void SamplerState::setupGL()
{
for (uint32_t ct=0; ct < RS_MAX_SAMPLER_SLOT; ct++) {
Sampler *s = mSamplers[ct].get();
if (s) {
- s->setupGL();
+ s->setupGL(rsc);
} else {
glBindTexture(GL_TEXTURE_2D, 0);
}
}
-}
+}*/
////////////////////////////////
diff --git a/libs/rs/rsSampler.h b/libs/rs/rsSampler.h
index ccf9b4dad5bd..9e20a2fcdcf6 100644
--- a/libs/rs/rsSampler.h
+++ b/libs/rs/rsSampler.h
@@ -41,7 +41,7 @@ public:
virtual ~Sampler();
void bind(Allocation *);
- void setupGL();
+ void setupGL(const Context *);
void bindToContext(SamplerState *, uint32_t slot);
void unbindFromContext(SamplerState *);
@@ -74,7 +74,7 @@ public:
ObjectBaseRef<Sampler> mSamplers[RS_MAX_SAMPLER_SLOT];
- void setupGL();
+ //void setupGL();
};
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index f11b862af61b..b7e0b86e81b1 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -137,7 +137,6 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
rsc->appendNameDefines(&tmp);
appendDecls(&tmp);
- rsc->appendVarDefines(&tmp);
appendVarDefines(rsc, &tmp);
appendTypes(rsc, &tmp);
tmp.append("#line 1\n");
@@ -270,12 +269,12 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
static void appendElementBody(String8 *s, const Element *e)
{
s->append(" {\n");
- for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) {
- const Component *c = e->getComponent(ct2);
+ for (size_t ct2=0; ct2 < e->getFieldCount(); ct2++) {
+ const Element *c = e->getField(ct2);
s->append(" ");
s->append(c->getCType());
s->append(" ");
- s->append(c->getComponentName());
+ s->append(e->getFieldName(ct2));
s->append(";\n");
}
s->append("}");
@@ -311,9 +310,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();
@@ -321,11 +326,12 @@ void ScriptCState::appendTypes(const Context *rsc, String8 *str)
continue;
}
const Element *e = t->getElement();
- if (e->getName() && (e->getComponentCount() > 1)) {
+ 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 +343,25 @@ void ScriptCState::appendTypes(const Context *rsc, String8 *str)
str->append(s);
}
- if (t->getName()) {
- for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) {
- const Component *c = e->getComponent(ct2);
- tmp.setTo("#define OFFSETOF_");
- tmp.append(t->getName());
- tmp.append("_");
- tmp.append(c->getComponentName());
- 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->getComponentCount() > 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->getComponent(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 de8df39944d4..61bb16f36621 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -26,6 +26,8 @@
#include <GLES/gl.h>
#include <GLES/glext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
#include <time.h>
@@ -102,8 +104,9 @@ static float* SC_loadSimpleMeshVerticesF(RsSimpleMesh mesh, uint32_t idx)
static void SC_updateSimpleMesh(RsSimpleMesh mesh)
{
+ GET_TLS();
SimpleMesh *sm = static_cast<SimpleMesh *>(mesh);
- sm->uploadAll();
+ sm->uploadAll(rsc);
}
static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
@@ -616,20 +619,20 @@ static void SC_vec2Rand(float *vec, float maxLen)
static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
{
GET_TLS();
- rsi_ProgramFragmentBindTexture(rsc,
- static_cast<ProgramFragment *>(vpf),
- slot,
- static_cast<Allocation *>(va));
+ rsi_ProgramBindTexture(rsc,
+ static_cast<ProgramFragment *>(vpf),
+ slot,
+ static_cast<Allocation *>(va));
}
static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
{
GET_TLS();
- rsi_ProgramFragmentBindSampler(rsc,
- static_cast<ProgramFragment *>(vpf),
- slot,
- static_cast<Sampler *>(vs));
+ rsi_ProgramBindSampler(rsc,
+ static_cast<ProgramFragment *>(vpf),
+ slot,
+ static_cast<Sampler *>(vs));
}
@@ -683,13 +686,13 @@ static void SC_drawLine(float x1, float y1, float z1,
rsc->setupCheck();
float vtx[] = { x1, y1, z1, x2, y2, z2 };
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, vtx);
-
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
+ VertexArray va;
+ va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
+ if (rsc->checkVersion2_0()) {
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
+ } else {
+ va.setupGL(rsc, &rsc->mStateVertexArray);
+ }
glDrawArrays(GL_LINES, 0, 2);
}
@@ -701,12 +704,13 @@ static void SC_drawPoint(float x, float y, float z)
float vtx[] = { x, y, z };
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, vtx);
-
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
+ VertexArray va;
+ va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
+ if (rsc->checkVersion2_0()) {
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
+ } else {
+ va.setupGL(rsc, &rsc->mStateVertexArray);
+ }
glDrawArrays(GL_POINTS, 0, 1);
}
@@ -721,6 +725,7 @@ static void SC_drawQuadTexCoords(float x1, float y1, float z1,
float u4, float v4)
{
GET_TLS();
+ rsc->setupCheck();
//LOGE("Quad");
//LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
@@ -731,26 +736,15 @@ static void SC_drawQuadTexCoords(float x1, float y1, float z1,
float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
- rsc->setupCheck();
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, vtx);
-
- glClientActiveTexture(GL_TEXTURE0);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(2, GL_FLOAT, 0, tex);
- glClientActiveTexture(GL_TEXTURE1);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(2, GL_FLOAT, 0, tex);
- glClientActiveTexture(GL_TEXTURE0);
-
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
+ VertexArray va;
+ va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
+ va.addLegacy(GL_FLOAT, 2, 8, RS_KIND_TEXTURE, false, (uint32_t)tex);
+ if (rsc->checkVersion2_0()) {
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
+ } else {
+ va.setupGL(rsc, &rsc->mStateVertexArray);
+ }
- //glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
@@ -769,29 +763,46 @@ static void SC_drawQuad(float x1, float y1, float z1,
static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h)
{
GET_TLS();
- rsc->setupCheck();
+ ObjectBaseRef<const ProgramVertex> tmp(rsc->getVertex());
+ rsc->setVertex(rsc->getDefaultProgramVertex());
+ //rsc->setupCheck();
+
+ //GLint crop[4] = {0, h, w, -h};
+
+ float sh = rsc->getHeight();
- GLint crop[4] = {0, h, w, -h};
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
- glDrawTexfOES(x, y, z, w, h);
+ SC_drawQuad(x, sh - y, z,
+ x+w, sh - y, z,
+ x+w, sh - (y+h), z,
+ x, sh - (y+h), z);
+ rsc->setVertex((ProgramVertex *)tmp.get());
}
static void SC_drawSpriteScreenspaceCropped(float x, float y, float z, float w, float h,
float cx0, float cy0, float cx1, float cy1)
{
GET_TLS();
- rsc->setupCheck();
+ ObjectBaseRef<const ProgramVertex> tmp(rsc->getVertex());
+ rsc->setVertex(rsc->getDefaultProgramVertex());
+
+ float tw = rsc->getFragment()->getTexture(0)->getType()->getDimY();
+ float th = rsc->getFragment()->getTexture(0)->getType()->getDimX();
+ float sh = rsc->getHeight();
+ float u0 = cx0 / tw;
+ float u1 = (cx1 + cx0) / tw;
+ float v0 = cy0 / th;
+ float v1 = (cy1 + cy0) / th;
- GLint crop[4] = {cx0, cy0, cx1, cy1};
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
- glDrawTexfOES(x, y, z, w, h);
+ SC_drawQuadTexCoords(x, sh - y, z, u0, v0,
+ x+w, sh - y, z, u1, v0,
+ x+w, sh - (y+h), z, u1, v1,
+ x, sh - (y+h), z, u0, v1);
+ rsc->setVertex((ProgramVertex *)tmp.get());
}
static void SC_drawSprite(float x, float y, float z, float w, float h)
{
GET_TLS();
- rsc->setupCheck();
-
float vin[3] = {x, y, z};
float vout[4];
@@ -813,9 +824,8 @@ static void SC_drawSprite(float x, float y, float z, float w, float h)
//LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]);
// U, V, W, H
- GLint crop[4] = {0, h, w, -h};
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
- glDrawTexiOES(vout[0], vout[1], 0/*vout[2]*/, w, h);
+ SC_drawSpriteScreenspace(vout[0], vout[1], z, h, w);
+ //rsc->setupCheck();
}
@@ -833,7 +843,7 @@ static void SC_drawSimpleMesh(RsSimpleMesh vsm)
GET_TLS();
SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
rsc->setupCheck();
- sm->render();
+ sm->render(rsc);
}
static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
@@ -841,7 +851,7 @@ static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t le
GET_TLS();
SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
rsc->setupCheck();
- sm->renderRange(start, len);
+ sm->renderRange(rsc, start, len);
}
@@ -851,7 +861,14 @@ static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t le
static void SC_color(float r, float g, float b, float a)
{
- glColor4f(r, g, b, a);
+ GET_TLS();
+ rsc->mStateVertex.color[0] = r;
+ rsc->mStateVertex.color[1] = g;
+ rsc->mStateVertex.color[2] = b;
+ rsc->mStateVertex.color[3] = a;
+ if (!rsc->checkVersion2_0()) {
+ glColor4f(r, g, b, a);
+ }
}
static void SC_ambient(float r, float g, float b, float a)
@@ -956,9 +973,14 @@ static int SC_hsbToAbgr(float h, float s, float b, float a)
static void SC_hsb(float h, float s, float b, float a)
{
+ GET_TLS();
float rgb[3];
SC_hsbToRgb(h, s, b, rgb);
- glColor4f(rgb[0], rgb[1], rgb[2], a);
+ if (rsc->checkVersion2_0()) {
+ glVertexAttrib4f(1, rgb[0], rgb[1], rgb[2], a);
+ } else {
+ glColor4f(rgb[0], rgb[1], rgb[2], a);
+ }
}
static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
@@ -973,6 +995,13 @@ static void SC_uploadToBufferObject(RsAllocation va)
rsi_AllocationUploadToBufferObject(rsc, va);
}
+static void SC_syncToGL(RsAllocation va)
+{
+ GET_TLS();
+ Allocation *a = static_cast<Allocation *>(va);
+
+}
+
static void SC_ClearColor(float r, float g, float b, float a)
{
//LOGE("c %f %f %f %f", r, g, b, a);
@@ -1221,33 +1250,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,
@@ -1323,6 +1352,9 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
{ "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
"void", "(int)" },
+ { "syncToGL", (void *)&SC_syncToGL,
+ "void", "(int)" },
+
{ "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
"int", "(float, float, float, float)" },
{ "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
diff --git a/libs/rs/rsShaderCache.cpp b/libs/rs/rsShaderCache.cpp
new file mode 100644
index 000000000000..3a1f37092500
--- /dev/null
+++ b/libs/rs/rsShaderCache.cpp
@@ -0,0 +1,167 @@
+/*
+ * 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 "rsContext.h"
+
+#include <GLES/gl.h>
+#include <GLES2/gl2.h>
+
+using namespace android;
+using namespace android::renderscript;
+
+
+ShaderCache::ShaderCache()
+{
+ mEntryCount = 0;
+ mEntryAllocationCount = 16;
+ mEntries = (entry_t *)calloc(mEntryAllocationCount, sizeof(entry_t));
+}
+
+ShaderCache::~ShaderCache()
+{
+ for (uint32_t ct=0; ct < mEntryCount; ct++) {
+ glDeleteProgram(mEntries[ct].program);
+ }
+
+ mEntryCount = 0;
+ mEntryAllocationCount = 0;
+ free(mEntries);
+}
+
+bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag)
+{
+ if (!vtx->getShaderID()) {
+ vtx->loadShader(rsc);
+ }
+ if (!frag->getShaderID()) {
+ frag->loadShader(rsc);
+ }
+ //LOGV("ShaderCache lookup vtx %i, frag %i", vtx->getShaderID(), frag->getShaderID());
+
+ for (uint32_t ct=0; ct < mEntryCount; ct++) {
+ if ((mEntries[ct].vtx == vtx->getShaderID()) &&
+ (mEntries[ct].frag == frag->getShaderID())) {
+
+ //LOGV("SC using program %i", mEntries[ct].program);
+ glUseProgram(mEntries[ct].program);
+ mCurrent = &mEntries[ct];
+ //LOGV("ShaderCache hit, using %i", ct);
+ rsc->checkError("ShaderCache::lookup (hit)");
+ return true;
+ }
+ }
+ // Not in cache, add it.
+
+ if (mEntryAllocationCount == mEntryCount) {
+ // Out of space, make some.
+ mEntryAllocationCount *= 2;
+ entry_t *e = (entry_t *)calloc(mEntryAllocationCount, sizeof(entry_t));
+ if (!e) {
+ LOGE("Out of memory for ShaderCache::lookup");
+ return false;
+ }
+ memcpy(e, mEntries, sizeof(entry_t) * mEntryCount);
+ free(mEntries);
+ mEntries = e;
+ }
+
+ //LOGV("ShaderCache miss, using %i", mEntryCount);
+ //LOGE("e0 %x", glGetError());
+
+ entry_t *e = &mEntries[mEntryCount];
+ mCurrent = e;
+ e->vtx = vtx->getShaderID();
+ e->frag = frag->getShaderID();
+ e->program = glCreateProgram();
+ e->mUserVertexProgram = vtx->isUserProgram();
+ if (mEntries[mEntryCount].program) {
+ GLuint pgm = e->program;
+ glAttachShader(pgm, vtx->getShaderID());
+ //LOGE("e1 %x", glGetError());
+ glAttachShader(pgm, frag->getShaderID());
+
+ if (!vtx->isUserProgram()) {
+ glBindAttribLocation(pgm, 0, "ATTRIB_LegacyPosition");
+ glBindAttribLocation(pgm, 1, "ATTRIB_LegacyColor");
+ glBindAttribLocation(pgm, 2, "ATTRIB_LegacyNormal");
+ glBindAttribLocation(pgm, 3, "ATTRIB_LegacyPointSize");
+ glBindAttribLocation(pgm, 4, "ATTRIB_LegacyTexture");
+ e->mVtxAttribSlots[RS_KIND_POSITION] = 0;
+ e->mVtxAttribSlots[RS_KIND_COLOR] = 1;
+ e->mVtxAttribSlots[RS_KIND_NORMAL] = 2;
+ e->mVtxAttribSlots[RS_KIND_POINT_SIZE] = 3;
+ e->mVtxAttribSlots[RS_KIND_TEXTURE] = 4;
+ }
+
+ //LOGE("e2 %x", glGetError());
+ glLinkProgram(pgm);
+ //LOGE("e3 %x", glGetError());
+ GLint linkStatus = GL_FALSE;
+ glGetProgramiv(pgm, GL_LINK_STATUS, &linkStatus);
+ if (linkStatus != GL_TRUE) {
+ GLint bufLength = 0;
+ glGetProgramiv(pgm, GL_INFO_LOG_LENGTH, &bufLength);
+ if (bufLength) {
+ char* buf = (char*) malloc(bufLength);
+ if (buf) {
+ glGetProgramInfoLog(pgm, bufLength, NULL, buf);
+ LOGE("Could not link program:\n%s\n", buf);
+ free(buf);
+ }
+ }
+ glDeleteProgram(pgm);
+ }
+ if (vtx->isUserProgram()) {
+ for (uint32_t ct=0; ct < vtx->getAttribCount(); ct++) {
+ e->mVtxAttribSlots[ct] = glGetAttribLocation(pgm, vtx->getAttribName(ct));
+ if (rsc->props.mLogShaders) {
+ LOGV("vtx A %i, %s = %d\n", ct, vtx->getAttribName(ct).string(), e->mVtxAttribSlots[ct]);
+ }
+ }
+ }
+ for (uint32_t ct=0; ct < vtx->getUniformCount(); ct++) {
+ e->mVtxUniformSlots[ct] = glGetUniformLocation(pgm, vtx->getUniformName(ct));
+ if (rsc->props.mLogShaders) {
+ LOGV("vtx U, %s = %d\n", vtx->getUniformName(ct).string(), e->mVtxUniformSlots[ct]);
+ }
+ }
+ for (uint32_t ct=0; ct < frag->getUniformCount(); ct++) {
+ e->mFragUniformSlots[ct] = glGetUniformLocation(pgm, frag->getUniformName(ct));
+ if (rsc->props.mLogShaders) {
+ LOGV("frag U, %s = %d\n", frag->getUniformName(ct).string(), e->mFragUniformSlots[ct]);
+ }
+ }
+ }
+
+ //LOGV("SC made program %i", e->program);
+ glUseProgram(e->program);
+ mEntryCount++;
+ rsc->checkError("ShaderCache::lookup (miss)");
+ return true;
+}
+
+void ShaderCache::cleanupVertex(uint32_t id)
+{
+}
+
+void ShaderCache::cleanupFragment(uint32_t id)
+{
+}
+
+void ShaderCache::cleanupAll()
+{
+}
+
diff --git a/libs/rs/rsShaderCache.h b/libs/rs/rsShaderCache.h
new file mode 100644
index 000000000000..7aa81834d747
--- /dev/null
+++ b/libs/rs/rsShaderCache.h
@@ -0,0 +1,76 @@
+/*
+ * 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_SHADER_CACHE_H
+#define ANDROID_SHADER_CACHE_H
+
+
+#include "rsObjectBase.h"
+#include "rsVertexArray.h"
+
+// ---------------------------------------------------------------------------
+namespace android {
+namespace renderscript {
+
+
+// An element is a group of Components that occupies one cell in a structure.
+class ShaderCache
+{
+public:
+ ShaderCache();
+ virtual ~ShaderCache();
+
+ bool lookup(Context *rsc, ProgramVertex *, ProgramFragment *);
+
+ void cleanupVertex(uint32_t id);
+ void cleanupFragment(uint32_t id);
+
+ void cleanupAll();
+
+ int32_t vtxAttribSlot(uint32_t a) const {return mCurrent->mVtxAttribSlots[a];}
+ int32_t vtxUniformSlot(uint32_t a) const {return mCurrent->mVtxUniformSlots[a];}
+ int32_t fragAttribSlot(uint32_t a) const {return mCurrent->mFragAttribSlots[a];}
+ int32_t fragUniformSlot(uint32_t a) const {return mCurrent->mFragUniformSlots[a];}
+ bool isUserVertexProgram() const {return mCurrent->mUserVertexProgram;}
+
+protected:
+ typedef struct {
+ uint32_t vtx;
+ uint32_t frag;
+ uint32_t program;
+ int32_t mVtxAttribSlots[Program::MAX_ATTRIBS];
+ int32_t mVtxUniformSlots[Program::MAX_UNIFORMS];
+ int32_t mFragAttribSlots[Program::MAX_ATTRIBS];
+ int32_t mFragUniformSlots[Program::MAX_UNIFORMS];
+ bool mUserVertexProgram;
+ } entry_t;
+ entry_t *mEntries;
+ entry_t *mCurrent;
+
+ uint32_t mEntryCount;
+ uint32_t mEntryAllocationCount;
+
+};
+
+
+
+}
+}
+#endif //ANDROID_SHADER_CACHE_H
+
+
+
+
diff --git a/libs/rs/rsSimpleMesh.cpp b/libs/rs/rsSimpleMesh.cpp
index b082fd7db26b..53ce5cdbd444 100644
--- a/libs/rs/rsSimpleMesh.cpp
+++ b/libs/rs/rsSimpleMesh.cpp
@@ -34,62 +34,71 @@ SimpleMesh::~SimpleMesh()
delete[] mVertexBuffers;
}
-void SimpleMesh::render() const
+void SimpleMesh::render(Context *rsc) const
{
if (mPrimitiveType.get()) {
- renderRange(0, mPrimitiveType->getDimX());
+ renderRange(rsc, 0, mPrimitiveType->getDimX());
return;
}
if (mIndexType.get()) {
- renderRange(0, mIndexType->getDimX());
+ renderRange(rsc, 0, mIndexType->getDimX());
return;
}
- renderRange(0, mVertexTypes[0]->getDimX());
+ renderRange(rsc, 0, mVertexTypes[0]->getDimX());
}
-void SimpleMesh::renderRange(uint32_t start, uint32_t len) const
+void SimpleMesh::renderRange(Context *rsc, uint32_t start, uint32_t len) const
{
if (len < 1) {
return;
}
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- for (uint32_t ct=0; ct < RS_MAX_TEXTURE; ct++) {
- glClientActiveTexture(GL_TEXTURE0 + ct);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- }
- glClientActiveTexture(GL_TEXTURE0);
-
- for (uint32_t ct=0; ct < mVertexTypeCount; ct++) {
- glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffers[ct]->getBufferObjectID());
- mVertexTypes[ct]->enableGLVertexBuffer();
+ rsc->checkError("SimpleMesh::renderRange 1");
+ VertexArray va;
+ if (rsc->checkVersion2_0()) {
+ for (uint32_t ct=0; ct < mVertexTypeCount; ct++) {
+ mVertexBuffers[ct]->uploadCheck(rsc);
+ va.setActiveBuffer(mVertexBuffers[ct]->getBufferObjectID());
+ mVertexTypes[ct]->enableGLVertexBuffer2(&va);
+ }
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
+ } else {
+ for (uint32_t ct=0; ct < mVertexTypeCount; ct++) {
+ mVertexBuffers[ct]->uploadCheck(rsc);
+ va.setActiveBuffer(mVertexBuffers[ct]->getBufferObjectID());
+ mVertexTypes[ct]->enableGLVertexBuffer(&va);
+ }
+ va.setupGL(rsc, 0);
}
+ rsc->checkError("SimpleMesh::renderRange 2");
if (mIndexType.get()) {
+ mIndexBuffer->uploadCheck(rsc);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer->getBufferObjectID());
glDrawElements(mGLPrimitive, len, GL_UNSIGNED_SHORT, (uint16_t *)(start * 2));
} else {
glDrawArrays(mGLPrimitive, start, len);
}
+
+ rsc->checkError("SimpleMesh::renderRange");
}
-void SimpleMesh::uploadAll()
+void SimpleMesh::uploadAll(Context *rsc)
{
for (uint32_t ct=0; ct < mVertexTypeCount; ct++) {
if (mVertexBuffers[ct].get()) {
- mVertexBuffers[ct]->uploadToBufferObject();
+ mVertexBuffers[ct]->deferedUploadToBufferObject(rsc);
}
}
if (mIndexBuffer.get()) {
- mIndexBuffer->uploadToBufferObject();
+ mIndexBuffer->deferedUploadToBufferObject(rsc);
}
if (mPrimitiveBuffer.get()) {
- mPrimitiveBuffer->uploadToBufferObject();
+ mPrimitiveBuffer->deferedUploadToBufferObject(rsc);
}
+ rsc->checkError("SimpleMesh::uploadAll");
}
diff --git a/libs/rs/rsSimpleMesh.h b/libs/rs/rsSimpleMesh.h
index 1e5c908a0c50..6defbdaadea2 100644
--- a/libs/rs/rsSimpleMesh.h
+++ b/libs/rs/rsSimpleMesh.h
@@ -45,9 +45,9 @@ public:
uint32_t mGLPrimitive;
- void render() const;
- void renderRange(uint32_t start, uint32_t len) const;
- void uploadAll();
+ void render(Context *) const;
+ void renderRange(Context *, uint32_t start, uint32_t len) const;
+ void uploadAll(Context *);
protected:
diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp
index ddaa2f0e1426..22a267a7873c 100644
--- a/libs/rs/rsType.cpp
+++ b/libs/rs/rsType.cpp
@@ -26,7 +26,6 @@ Type::Type(Context *rsc) : ObjectBase(rsc)
mAllocLine = __LINE__;
mLODs = 0;
mLODCount = 0;
- memset(&mGL, 0, sizeof(mGL));
clear();
}
@@ -93,9 +92,9 @@ void Type::compute()
mLODs[lod].mZ = tz;
mLODs[lod].mOffset = offset;
offset += tx * rsMax(ty, 1u) * rsMax(tz, 1u) * mElement->getSizeBytes();
- tx = (tx + 1) >> 1;
- ty = (ty + 1) >> 1;
- tz = (tz + 1) >> 1;
+ if (tx > 1) tx >>= 1;
+ if (ty > 1) ty >>= 1;
+ if (tz > 1) tz >>= 1;
}
// At this point the offset is the size of a mipmap chain;
@@ -133,110 +132,64 @@ uint32_t Type::getLODOffset(uint32_t lod, uint32_t x, uint32_t y, uint32_t z) co
void Type::makeGLComponents()
{
- uint32_t texNum = 0;
- memset(&mGL, 0, sizeof(mGL));
-
- for (uint32_t ct=0; ct < getElement()->getComponentCount(); ct++) {
- const Component *c = getElement()->getComponent(ct);
+ uint32_t userNum = 0;
+
+ for (uint32_t ct=0; ct < getElement()->getFieldCount(); ct++) {
+ const Component &c = getElement()->getField(ct)->getComponent();
+
+ switch(c.getKind()) {
+ case RS_KIND_USER:
+ mGL.mUser[userNum].size = c.getVectorSize();
+ mGL.mUser[userNum].offset = mElement->getFieldOffsetBytes(ct);
+ mGL.mUser[userNum].type = c.getGLType();
+ mGL.mUser[userNum].normalized = c.getType() != RS_TYPE_FLOAT_32;//c.getIsNormalized();
+ mGL.mUser[userNum].name.setTo(getElement()->getFieldName(ct));
+ userNum ++;
+ break;
- switch(c->getKind()) {
- case Component::X:
+ case RS_KIND_POSITION:
rsAssert(mGL.mVtx.size == 0);
- mGL.mVtx.size = 1;
- mGL.mVtx.offset = mElement->getComponentOffsetBytes(ct);
- mGL.mVtx.type = c->getGLType();
- break;
- case Component::Y:
- rsAssert(mGL.mVtx.size == 1);
- rsAssert(mGL.mVtx.type == c->getGLType());
- mGL.mVtx.size = 2;
- break;
- case Component::Z:
- rsAssert(mGL.mVtx.size == 2);
- rsAssert(mGL.mVtx.type == c->getGLType());
- mGL.mVtx.size = 3;
+ mGL.mVtx.size = c.getVectorSize();
+ mGL.mVtx.offset = mElement->getFieldOffsetBytes(ct);
+ mGL.mVtx.type = c.getGLType();
+ mGL.mVtx.normalized = false;
+ mGL.mVtx.name.setTo("Position");
break;
- case Component::W:
- rsAssert(mGL.mVtx.size == 4);
- rsAssert(mGL.mVtx.type == c->getGLType());
- mGL.mVtx.size = 4;
- break;
- case Component::RED:
+ case RS_KIND_COLOR:
rsAssert(mGL.mColor.size == 0);
- mGL.mColor.size = 1;
- mGL.mColor.offset = mElement->getComponentOffsetBytes(ct);
- mGL.mColor.type = c->getGLType();
- break;
- case Component::GREEN:
- rsAssert(mGL.mColor.size == 1);
- rsAssert(mGL.mColor.type == c->getGLType());
- mGL.mColor.size = 2;
- break;
- case Component::BLUE:
- rsAssert(mGL.mColor.size == 2);
- rsAssert(mGL.mColor.type == c->getGLType());
- mGL.mColor.size = 3;
+ mGL.mColor.size = c.getVectorSize();
+ mGL.mColor.offset = mElement->getFieldOffsetBytes(ct);
+ mGL.mColor.type = c.getGLType();
+ mGL.mColor.normalized = c.getType() != RS_TYPE_FLOAT_32;
+ mGL.mColor.name.setTo("Color");
break;
- case Component::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->getComponentOffsetBytes(ct);
- mGL.mColor.type = c->getGLType();
- }
- break;
- case Component::NX:
+ case RS_KIND_NORMAL:
rsAssert(mGL.mNorm.size == 0);
- mGL.mNorm.size = 1;
- mGL.mNorm.offset = mElement->getComponentOffsetBytes(ct);
- mGL.mNorm.type = c->getGLType();
- break;
- case Component::NY:
- rsAssert(mGL.mNorm.size == 1);
- rsAssert(mGL.mNorm.type == c->getGLType());
- mGL.mNorm.size = 2;
- break;
- case Component::NZ:
- rsAssert(mGL.mNorm.size == 2);
- rsAssert(mGL.mNorm.type == c->getGLType());
- mGL.mNorm.size = 3;
- break;
+ mGL.mNorm.size = c.getVectorSize();
+ mGL.mNorm.offset = mElement->getFieldOffsetBytes(ct);
+ mGL.mNorm.type = c.getGLType();
+ mGL.mNorm.normalized = false;
+ mGL.mNorm.name.setTo("Normal");
+ break;
- case Component::S:
- if (mGL.mTex[texNum].size) {
- texNum++;
- }
- mGL.mTex[texNum].size = 1;
- mGL.mTex[texNum].offset = mElement->getComponentOffsetBytes(ct);
- mGL.mTex[texNum].type = c->getGLType();
- break;
- case Component::T:
- rsAssert(mGL.mTex[texNum].size == 1);
- rsAssert(mGL.mTex[texNum].type == c->getGLType());
- mGL.mTex[texNum].size = 2;
- break;
- case Component::R:
- rsAssert(mGL.mTex[texNum].size == 2);
- rsAssert(mGL.mTex[texNum].type == c->getGLType());
- mGL.mTex[texNum].size = 3;
- break;
- case Component::Q:
- rsAssert(mGL.mTex[texNum].size == 3);
- rsAssert(mGL.mTex[texNum].type == c->getGLType());
- mGL.mTex[texNum].size = 4;
- break;
+ case RS_KIND_TEXTURE:
+ rsAssert(mGL.mTex.size == 0);
+ mGL.mTex.size = c.getVectorSize();
+ mGL.mTex.offset = mElement->getFieldOffsetBytes(ct);
+ mGL.mTex.type = c.getGLType();
+ mGL.mTex.normalized = false;
+ mGL.mTex.name.setTo("Texture");
+ break;
- case Component::POINT_SIZE:
+ case RS_KIND_POINT_SIZE:
rsAssert(!mGL.mPointSize.size);
- mGL.mPointSize.size = 1;
- mGL.mPointSize.offset = mElement->getComponentOffsetBytes(ct);
- mGL.mPointSize.type = c->getGLType();
+ mGL.mPointSize.size = c.getVectorSize();
+ mGL.mPointSize.offset = mElement->getFieldOffsetBytes(ct);
+ mGL.mPointSize.type = c.getGLType();
+ mGL.mPointSize.normalized = false;
+ mGL.mPointSize.name.setTo("PointSize");
break;
default:
@@ -245,62 +198,75 @@ void Type::makeGLComponents()
}
}
-void Type::enableGLVertexBuffer() const
+void Type::enableGLVertexBuffer(VertexArray *va) const
{
// Note: We are only going to enable buffers and never disable them
- // here. The reasonis more than one Allocation may be used as a vertex
+ // here. The reason is more than one Allocation may be used as a vertex
// source. So we cannot disable arrays that may have been in use by
// another allocation.
uint32_t stride = mElement->getSizeBytes();
if (mGL.mVtx.size) {
- //LOGE("va vtx %i %x, %i, %p", mGL.mVtx.size, mGL.mVtx.type, stride, (void *)mGL.mVtx.offset);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(mGL.mVtx.size,
- mGL.mVtx.type,
- stride,
- (void *)mGL.mVtx.offset);
+ va->addLegacy(mGL.mVtx.type,
+ mGL.mVtx.size,
+ stride,
+ RS_KIND_POSITION,
+ false,
+ mGL.mVtx.offset);
}
if (mGL.mNorm.size) {
- //LOGE("va norm %i %x, %i, %p", mGL.mNorm.size, mGL.mNorm.type, stride, (void *)mGL.mNorm.offset);
- glEnableClientState(GL_NORMAL_ARRAY);
- rsAssert(mGL.mNorm.size == 3);
- glNormalPointer(mGL.mNorm.type,
- stride,
- (void *)mGL.mNorm.offset);
+ va->addLegacy(mGL.mNorm.type,
+ 3,
+ stride,
+ RS_KIND_NORMAL,
+ false,
+ mGL.mNorm.offset);
}
if (mGL.mColor.size) {
- glEnableClientState(GL_COLOR_ARRAY);
- glColorPointer(mGL.mColor.size,
- mGL.mColor.type,
- stride,
- (void *)mGL.mColor.offset);
+ va->addLegacy(mGL.mColor.type,
+ mGL.mColor.size,
+ stride,
+ RS_KIND_COLOR,
+ true,
+ mGL.mColor.offset);
}
- for (uint32_t ct=0; ct < RS_MAX_TEXTURE; ct++) {
- if (mGL.mTex[ct].size) {
- //LOGE("va tex%i %i %x, %i, %p", ct, mGL.mTex[ct].size, mGL.mTex[ct].type, stride, (void *)mGL.mTex[ct].offset);
- glClientActiveTexture(GL_TEXTURE0 + ct);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(mGL.mTex[ct].size,
- mGL.mTex[ct].type,
- stride,
- (void *)mGL.mTex[ct].offset);
- }
+ if (mGL.mTex.size) {
+ va->addLegacy(mGL.mTex.type,
+ mGL.mTex.size,
+ stride,
+ RS_KIND_TEXTURE,
+ false,
+ mGL.mTex.offset);
}
- glClientActiveTexture(GL_TEXTURE0);
if (mGL.mPointSize.size) {
- glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
- glPointSizePointerOES(mGL.mPointSize.type,
- stride,
- (void *)mGL.mPointSize.offset);
+ va->addLegacy(mGL.mPointSize.type,
+ 1,
+ stride,
+ RS_KIND_POINT_SIZE,
+ false,
+ mGL.mPointSize.offset);
}
}
+void Type::enableGLVertexBuffer2(VertexArray *va) const
+{
+ // Do legacy buffers
+ enableGLVertexBuffer(va);
+
+ uint32_t stride = mElement->getSizeBytes();
+ for (uint32_t ct=0; ct < RS_MAX_ATTRIBS; ct++) {
+ if (mGL.mUser[ct].size) {
+ va->addUser(mGL.mUser[ct], stride);
+ }
+ }
+}
+
+
void Type::dumpLOGV(const char *prefix) const
{
diff --git a/libs/rs/rsType.h b/libs/rs/rsType.h
index 2c43405122ba..4fa49335b5e3 100644
--- a/libs/rs/rsType.h
+++ b/libs/rs/rsType.h
@@ -18,6 +18,7 @@
#define ANDROID_STRUCTURED_TYPE_H
#include "rsElement.h"
+#include "rsVertexArray.h"
// ---------------------------------------------------------------------------
namespace android {
@@ -67,7 +68,8 @@ public:
void clear();
void compute();
- void enableGLVertexBuffer() const;
+ void enableGLVertexBuffer(class VertexArray *) const;
+ void enableGLVertexBuffer2(class VertexArray *) const;
void dumpLOGV(const char *prefix) const;
@@ -108,18 +110,13 @@ protected:
LOD *mLODs;
uint32_t mLODCount;
- struct VertexComponent_t {
- uint32_t offset;
- uint32_t type;
- uint32_t size;
- uint32_t stride;
- };
struct GLState_t {
- VertexComponent_t mVtx;
- VertexComponent_t mNorm;
- VertexComponent_t mColor;
- VertexComponent_t mTex[RS_MAX_TEXTURE];
- VertexComponent_t mPointSize;
+ VertexArray::Attrib mUser[RS_MAX_ATTRIBS];
+ VertexArray::Attrib mVtx;
+ VertexArray::Attrib mNorm;
+ VertexArray::Attrib mColor;
+ VertexArray::Attrib mTex;
+ VertexArray::Attrib mPointSize;
};
GLState_t mGL;
void makeGLComponents();
diff --git a/libs/rs/rsVertexArray.cpp b/libs/rs/rsVertexArray.cpp
new file mode 100644
index 000000000000..d0c04148be37
--- /dev/null
+++ b/libs/rs/rsVertexArray.cpp
@@ -0,0 +1,216 @@
+/*
+ * 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 "rsContext.h"
+
+#include <GLES/gl.h>
+#include <GLES2/gl2.h>
+
+using namespace android;
+using namespace android::renderscript;
+
+
+VertexArray::VertexArray()
+{
+ clearAll();
+}
+
+VertexArray::~VertexArray()
+{
+}
+
+
+void VertexArray::clearAll()
+{
+ for (uint32_t ct=0; ct < RS_MAX_ATTRIBS; ct++) {
+ mAttribs[ct].clear();
+ }
+ mActiveBuffer = 0;
+ mCount = 0;
+}
+
+VertexArray::Attrib::Attrib()
+{
+ clear();
+}
+
+void VertexArray::Attrib::set(const Attrib &a)
+{
+ buffer = a.buffer;
+ offset = a.offset;
+ type = a.type;
+ size = a.size;
+ stride = a.stride;
+ normalized = a.normalized;
+ kind = RS_KIND_USER;
+ name.setTo(a.name);
+}
+
+void VertexArray::Attrib::clear()
+{
+ buffer = 0;
+ offset = 0;
+ type = 0;
+ size = 0;
+ stride = 0;
+ normalized = false;
+ name.setTo("");
+}
+
+void VertexArray::clear(uint32_t n)
+{
+ mAttribs[n].clear();
+}
+
+void VertexArray::addUser(const Attrib &a, uint32_t stride)
+{
+ assert(mCount < RS_MAX_ATTRIBS);
+ mAttribs[mCount].set(a);
+ mAttribs[mCount].buffer = mActiveBuffer;
+ mAttribs[mCount].stride = stride;
+ mAttribs[mCount].kind = RS_KIND_USER;
+ mCount ++;
+}
+
+void VertexArray::addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDataKind kind, bool normalized, uint32_t offset)
+{
+ assert(mCount < RS_MAX_ATTRIBS);
+ mAttribs[mCount].clear();
+ mAttribs[mCount].type = type;
+ mAttribs[mCount].size = size;
+ mAttribs[mCount].offset = offset;
+ mAttribs[mCount].normalized = normalized;
+ mAttribs[mCount].buffer = mActiveBuffer;
+ mAttribs[mCount].stride = stride;
+ mAttribs[mCount].kind = kind;
+ mCount ++;
+}
+
+void VertexArray::logAttrib(uint32_t idx, uint32_t slot) const {
+ LOGE("va %i: slot=%i name=%s buf=%i size=%i type=0x%x kind=%i stride=0x%x norm=%i offset=0x%x", idx, slot,
+ mAttribs[idx].name.string(),
+ mAttribs[idx].buffer,
+ mAttribs[idx].size,
+ mAttribs[idx].type,
+ mAttribs[idx].kind,
+ mAttribs[idx].stride,
+ mAttribs[idx].normalized,
+ mAttribs[idx].offset);
+}
+
+void VertexArray::setupGL(const Context *rsc, class VertexArrayState *state) const
+{
+ glClientActiveTexture(GL_TEXTURE0);
+ glDisableClientState(GL_NORMAL_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisableClientState(GL_POINT_SIZE_ARRAY_OES);
+
+ for (uint32_t ct=0; ct < mCount; ct++) {
+ switch(mAttribs[ct].kind) {
+ case RS_KIND_POSITION:
+ //logAttrib(POSITION);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
+ glVertexPointer(mAttribs[ct].size,
+ mAttribs[ct].type,
+ mAttribs[ct].stride,
+ (void *)mAttribs[ct].offset);
+ break;
+
+ case RS_KIND_NORMAL:
+ //logAttrib(NORMAL);
+ glEnableClientState(GL_NORMAL_ARRAY);
+ rsAssert(mAttribs[ct].size == 3);
+ glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
+ glNormalPointer(mAttribs[ct].type,
+ mAttribs[ct].stride,
+ (void *)mAttribs[ct].offset);
+ break;
+
+ case RS_KIND_COLOR:
+ //logAttrib(COLOR);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
+ glColorPointer(mAttribs[ct].size,
+ mAttribs[ct].type,
+ mAttribs[ct].stride,
+ (void *)mAttribs[ct].offset);
+ break;
+
+ case RS_KIND_TEXTURE:
+ //logAttrib(TEXTURE);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
+ glTexCoordPointer(mAttribs[ct].size,
+ mAttribs[ct].type,
+ mAttribs[ct].stride,
+ (void *)mAttribs[ct].offset);
+ break;
+
+ case RS_KIND_POINT_SIZE:
+ //logAttrib(POINT_SIZE);
+ glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
+ glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
+ glPointSizePointerOES(mAttribs[ct].type,
+ mAttribs[ct].stride,
+ (void *)mAttribs[ct].offset);
+ break;
+
+ default:
+ rsAssert(0);
+ }
+ }
+
+ rsc->checkError("VertexArray::setupGL");
+}
+
+void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, ShaderCache *sc) const
+{
+ rsc->checkError("VertexArray::setupGL2 start");
+ for (uint32_t ct=1; ct <= state->mLastEnableCount; ct++) {
+ glDisableVertexAttribArray(ct);
+ }
+
+ rsc->checkError("VertexArray::setupGL2 disabled");
+ for (uint32_t ct=0; ct < mCount; ct++) {
+ uint32_t slot = 0;
+ if (sc->isUserVertexProgram()) {
+ slot = sc->vtxAttribSlot(ct);
+ } else {
+ slot = sc->vtxAttribSlot(mAttribs[ct].kind);
+ }
+
+ //logAttrib(ct, slot);
+ glEnableVertexAttribArray(slot);
+ glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
+
+ glVertexAttribPointer(slot,
+ mAttribs[ct].size,
+ mAttribs[ct].type,
+ mAttribs[ct].normalized,
+ mAttribs[ct].stride,
+ (void *)mAttribs[ct].offset);
+ }
+ state->mLastEnableCount = mCount;
+ rsc->checkError("VertexArray::setupGL2 done");
+}
+////////////////////////////////////////////
+
+void VertexArrayState::init(Context *) {
+ mLastEnableCount = 0;
+}
+
diff --git a/libs/rs/rsVertexArray.h b/libs/rs/rsVertexArray.h
new file mode 100644
index 000000000000..3904cb69c231
--- /dev/null
+++ b/libs/rs/rsVertexArray.h
@@ -0,0 +1,86 @@
+/*
+ * 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_VERTEX_ARRAY_H
+#define ANDROID_VERTEX_ARRAY_H
+
+
+#include "rsObjectBase.h"
+
+// ---------------------------------------------------------------------------
+namespace android {
+namespace renderscript {
+
+class ShaderCache;
+
+// An element is a group of Components that occupies one cell in a structure.
+class VertexArray
+{
+public:
+ VertexArray();
+ virtual ~VertexArray();
+
+
+ class Attrib {
+ public:
+ uint32_t buffer;
+ uint32_t offset;
+ uint32_t type;
+ uint32_t size;
+ uint32_t stride;
+ bool normalized;
+ String8 name;
+ RsDataKind kind;
+
+ Attrib();
+ void set(const Attrib &);
+ void clear();
+ };
+
+
+ void clearAll();
+ void setActiveBuffer(uint32_t id) {mActiveBuffer = id;}
+ void addUser(const Attrib &, uint32_t stride);
+ void addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDataKind kind, bool normalized, uint32_t offset);
+
+ void setupGL(const Context *rsc, class VertexArrayState *) const;
+ void setupGL2(const Context *rsc, class VertexArrayState *, ShaderCache *) const;
+ void logAttrib(uint32_t idx, uint32_t slot) const;
+
+protected:
+ void clear(uint32_t index);
+ uint32_t mActiveBuffer;
+ uint32_t mCount;
+
+ Attrib mAttribs[RS_MAX_ATTRIBS];
+};
+
+
+class VertexArrayState {
+public:
+ void init(Context *);
+
+ uint32_t mLastEnableCount;
+ //VertexArray::Attrib mAttribs[VertexArray::_LAST];
+};
+
+
+}
+}
+#endif //ANDROID_LIGHT_H
+
+
+