Implement basic allocation readback. Add Get height, width to ScriptC_Lib.
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index bf83aab..5ed9ed51 100644
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ b/libs/rs/java/Fountain/res/raw/fountain.c
@@ -7,8 +7,7 @@
int main(int launchID) {
- int count, touch, x, y, rate, maxLife, lifeShift;
- int life;
+ int count, touch, x, y, rate;
int ct, ct2;
int newPart;
int drawCount;
@@ -25,15 +24,7 @@
y = loadI32(0, 4);
rate = 4;
- maxLife = (count / rate) - 1;
- lifeShift = 0;
- {
- life = maxLife;
- while (life > 255) {
- life = life >> 1;
- lifeShift ++;
- }
- }
+ int maxLife = (count / rate) - 1;
if (touch) {
newPart = loadI32(2, 0);
@@ -57,19 +48,20 @@
}
drawCount = 0;
+ float height = getHeight();
for (ct=0; ct < count; ct++) {
srcIdx = ct * 5 + 1;
dx = loadF(2, srcIdx);
dy = loadF(2, srcIdx + 1);
- life = loadI32(2, srcIdx + 2);
+ int life = loadI32(2, srcIdx + 2);
posx = loadF(2, srcIdx + 3);
posy = loadF(2, srcIdx + 4);
if (life) {
- if (posy < 480.f) {
+ if (posy < height) {
dstIdx = drawCount * 9;
- c = 0xffafcf | ((life >> lifeShift) << 24);
+ c = 0xcfcfcfcf;
storeI32(1, dstIdx, c);
storeF(1, dstIdx + 1, posx);
@@ -91,7 +83,7 @@
posx = posx + dx;
posy = posy + dy;
- dy = dy + 0.1f;
+ dy = dy + 0.05f;
life --;
//storeI32(2, srcIdx, dx);
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 c2d1c65..ad4f949 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -39,6 +39,7 @@
public class FountainRS {
+ public static final int PART_COUNT = 4000;
public FountainRS() {
}
@@ -75,10 +76,8 @@
int mParams[] = new int[10];
private void initRS() {
- int partCount = 1024;
-
mIntAlloc = Allocation.createSized(mRS, Element.USER_I32, 10);
- mVertAlloc = Allocation.createSized(mRS, Element.USER_I32, partCount * 5 + 1);
+ mVertAlloc = Allocation.createSized(mRS, Element.USER_I32, PART_COUNT * 5 + 1);
ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, ProgramStore.BlendDstFunc.ONE);
@@ -93,10 +92,12 @@
mPF.setName("PgmFragParts");
mParams[0] = 0;
- mParams[1] = partCount;
+ mParams[1] = PART_COUNT;
mParams[2] = 0;
mParams[3] = 0;
mParams[4] = 0;
+ mParams[5] = 0;
+ mParams[6] = 0;
mIntAlloc.data(mParams);
Element.Builder eb = new Element.Builder(mRS);
@@ -109,7 +110,7 @@
Element primElement = eb.create();
SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
- int vtxSlot = smb.addVertexType(primElement, partCount * 3);
+ int vtxSlot = smb.addVertexType(primElement, PART_COUNT * 3);
smb.setPrimitive(Primitive.TRIANGLE);
mSM = smb.create();
mSM.setName("PartMesh");
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index b644833..7dbf412 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -155,6 +155,10 @@
param const void *data
}
+AllocationRead {
+ param RsAllocation va
+ param void * data
+ }
Adapter1DCreate {
ret RsAdapter1D
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 5ec73d7..ad9c739 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -120,6 +120,11 @@
memcpy(mPtr, data, mType->getSizeBytes());
}
+void Allocation::read(void *data)
+{
+ memcpy(data, mPtr, mType->getSizeBytes());
+}
+
void Allocation::subData(uint32_t xoff, uint32_t count, const void *data)
{
uint32_t eSize = mType->getElementSizeBytes();
@@ -523,6 +528,12 @@
rsc->allocationCheck(a);
}
+void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data)
+{
+ Allocation *a = static_cast<Allocation *>(va);
+ a->read(data);
+}
+
}
}
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index eb1da69..00af9ed 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -60,6 +60,8 @@
void subData(uint32_t xoff, uint32_t yoff, uint32_t zoff,
uint32_t w, uint32_t h, uint32_t d, const void *data);
+ void read(void *data);
+
void enableGLVertexBuffers() const;
void setupGLIndexBuffers() const;
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 799c443..54c555f 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -115,6 +115,9 @@
mFloatDefines.add(String8(name), value);
}
+ uint32_t getWidth() const {return mWidth;}
+ uint32_t getHeight() const {return mHeight;}
+
protected:
Device *mDev;
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index b46e1cf..4ee112d 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -547,32 +547,6 @@
rsi_TriangleMeshRenderRange(rsc, mesh, start, count);
}
-// Assumes (GL_FIXED) x,y,z (GL_UNSIGNED_BYTE)r,g,b,a
-static void SC_drawTriangleArray(int ialloc, uint32_t count)
-{
- GET_TLS();
- RsAllocation alloc = (RsAllocation)ialloc;
-
- const Allocation *a = (const Allocation *)alloc;
- const uint32_t *ptr = (const uint32_t *)a->getPtr();
-
- rsc->setupCheck();
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- glVertexPointer(2, GL_FIXED, 12, ptr + 1);
- //glTexCoordPointer(2, GL_FIXED, 24, ptr + 1);
- glColorPointer(4, GL_UNSIGNED_BYTE, 12, ptr);
-
- glDrawArrays(GL_TRIANGLES, 0, count * 3);
-}
-
static void SC_drawLine(float x1, float y1, float z1,
float x2, float y2, float z2)
{
@@ -601,13 +575,13 @@
float u4, float v4)
{
GET_TLS();
-
+
//LOGE("Quad");
//LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
//LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
//LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
//LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
-
+
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};
@@ -795,7 +769,17 @@
LOGE("%s %i", s, i);
}
+static uint32_t SC_getWidth()
+{
+ GET_TLS();
+ return rsc->getWidth();
+}
+static uint32_t SC_getHeight()
+{
+ GET_TLS();
+ return rsc->getHeight();
+}
//////////////////////////////////////////////////////////////////////////////
// Class implementation
@@ -981,8 +965,6 @@
"void", "(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" },
{ "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
"void", "(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4)" },
- { "drawTriangleArray", (void *)&SC_drawTriangleArray,
- "void", "(int ialloc, int count)" },
{ "drawTriangleMesh", (void *)&SC_drawTriangleMesh,
"void", "(int mesh)" },
{ "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange,
@@ -1018,6 +1000,12 @@
{ "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
"void", "(int)" },
+ { "getWidth", (void *)&SC_getWidth,
+ "int", "()" },
+ { "getHeight", (void *)&SC_getHeight,
+ "int", "()" },
+
+
{ "debugF", (void *)&SC_debugF,
"void", "(void *, float)" },