diff options
author | Jason Sams <rjsams@android.com> | 2009-08-17 13:56:09 -0700 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2009-08-17 13:56:09 -0700 |
commit | 334ea0c98f051b5a6b85bc616c93304651854298 (patch) | |
tree | b3d87acd4f6285446fdc166d0ec9bb5330f42c21 /libs/rs/java | |
parent | 0ef135d5c79ff5b443b43f8743250044700a8bb5 (diff) | |
download | frameworks_base-334ea0c98f051b5a6b85bc616c93304651854298.zip frameworks_base-334ea0c98f051b5a6b85bc616c93304651854298.tar.gz frameworks_base-334ea0c98f051b5a6b85bc616c93304651854298.tar.bz2 |
Update fountain and add writable flag to script slots.
Diffstat (limited to 'libs/rs/java')
3 files changed, 65 insertions, 110 deletions
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c index 6e6afcd..e7804a5 100644 --- a/libs/rs/java/Fountain/res/raw/fountain.c +++ b/libs/rs/java/Fountain/res/raw/fountain.c @@ -1,86 +1,52 @@ // Fountain test script - #pragma version(1) #pragma stateVertex(default) -#pragma stateFragment(PgmFragParts) -#pragma stateFragmentStore(PFSBlend) - +#pragma stateFragment(default) +#pragma stateFragmentStore(default) int main(int launchID) { int ct; - int count = loadI32(0, OFFSETOF_SomeData_count); - int touch = loadI32(0, OFFSETOF_SomeData_touch); - int rate = 4; - int maxLife = (count / rate) - 1; + int count = Control_count - 1; + int rate = Control_rate; + float *dataF = loadArrayF(1, 0); + float height = getHeight(); - if (touch) { - int x = loadI32(0, OFFSETOF_SomeData_x); - int y = loadI32(0, OFFSETOF_SomeData_y); - int newPart = loadI32(2, 0); - for (ct=0; ct<rate; ct++) { - int idx = newPart * 5 + 1; - storeF(2, idx, randf(1.f) - 0.5f); - storeF(2, idx + 1, randf(1.f) - 0.5f); - storeI32(2, idx + 2, maxLife); - storeF(2, idx + 3, x); - storeF(2, idx + 4, y); + if (rate) { + debugI32("rate", rate); + int *dataI = loadArrayI32(1, 0); + float rMax = ((float)rate) * 0.005f; + int x = Control_x; + int y = Control_y; + int newPart = loadI32(1, count * 5); + int c = colorFloatRGBAtoUNorm8(Control_r, Control_g, Control_b, 0.99f); + + while (rate--) { + int idx = newPart * 5; + vec2Rand(dataF + idx, rMax); + dataF[idx + 2] = x; + dataF[idx + 3] = y; + dataI[idx + 4] = c; newPart++; if (newPart >= count) { newPart = 0; } } - storeI32(2, 0, newPart); + storeI32(1, count * 5, newPart); } - int drawCount = 0; - float height = getHeight(); for (ct=0; ct < count; ct++) { - int srcIdx = ct * 5 + 1; - - int life = loadI32(2, srcIdx + 2); - - if (life) { - float posx = loadF(2, srcIdx + 3); - float posy = loadF(2, srcIdx + 4); - float dx = loadF(2, srcIdx); - float dy = loadF(2, srcIdx + 1); - if (posy < height) { - int dstIdx = drawCount * 9; - int c = 0xcfcfcfcf; - - storeI32(1, dstIdx, c); - storeF(1, dstIdx + 1, posx); - storeF(1, dstIdx + 2, posy); - - storeI32(1, dstIdx + 3, c); - storeF(1, dstIdx + 4, posx + 1.f); - storeF(1, dstIdx + 5, posy + dy); - - storeI32(1, dstIdx + 6, c); - storeF(1, dstIdx + 7, posx - 1.f); - storeF(1, dstIdx + 8, posy + dy); - drawCount ++; - } else { - if (dy > 0) { - dy *= -0.5f; - } - } - - posx = posx + dx; - posy = posy + dy; - dy = dy + 0.05f; - life --; - - //storeI32(2, srcIdx, dx); - storeF(2, srcIdx + 1, dy); - storeI32(2, srcIdx + 2, life); - storeF(2, srcIdx + 3, posx); - storeF(2, srcIdx + 4, posy); + float dy = dataF[1] + 0.15f; + float posy = dataF[3] + dy; + if ((posy > height) && (dy > 0)) { + dy *= -0.3f; } + dataF[1] = dy; + dataF[2] += dataF[0]; + dataF[3] = posy; + dataF += 5; } - //drawTriangleArray(NAMED_PartBuffer, drawCount); uploadToBufferObject(NAMED_PartBuffer); - drawSimpleMeshRange(NAMED_PartMesh, 0, drawCount * 3); + drawSimpleMeshRange(NAMED_PartMesh, 0, count); return 1; } 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 da4eeb4..da9eda8 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java @@ -16,26 +16,22 @@ package com.android.fountain; -import java.io.Writer; - -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.renderscript.*; import android.util.Log; public class FountainRS { - public static final int PART_COUNT = 4000; + public static final int PART_COUNT = 20000; static class SomeData { public int x; public int y; - public int touch; public int rate; public int count; + public float r; + public float g; + public float b; } public FountainRS() { @@ -47,8 +43,18 @@ public class FountainRS { initRS(); } - public void newTouchPosition(int x, int y) { - mSD.touch = 1; + public void newTouchPosition(int x, int y, int rate) { + if (mSD.rate == 0) { + mSD.r = ((x & 0x1) != 0) ? 0.f : 1.f; + mSD.g = ((x & 0x2) != 0) ? 0.f : 1.f; + mSD.b = ((x & 0x4) != 0) ? 0.f : 1.f; + if ((mSD.r + mSD.g + mSD.b) < 0.9f) { + mSD.r = 0.8f; + mSD.g = 0.5f; + mSD.b = 1.f; + } + } + mSD.rate = rate; mSD.x = x; mSD.y = y; mIntAlloc.data(mSD); @@ -62,50 +68,29 @@ public class FountainRS { private RenderScript mRS; private Allocation mIntAlloc; private Allocation mPartAlloc; - private Allocation mVertAlloc; private Script mScript; - private ProgramStore mPFS; - private ProgramFragment mPF; private SimpleMesh mSM; - - private Bitmap mBackground; - - SomeData mSD = new SomeData(); + private SomeData mSD; private Type mSDType; private void initRS() { mSD = new SomeData(); mSDType = Type.createFromClass(mRS, SomeData.class, 1, "SomeData"); mIntAlloc = Allocation.createTyped(mRS, mSDType); - 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); - bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); - bs.setDepthMask(false); - bs.setDitherEnable(false); - mPFS = bs.create(); - mPFS.setName("PFSBlend"); - - ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); - mPF = bf.create(); - mPF.setName("PgmFragParts"); - mSD.count = PART_COUNT; mIntAlloc.data(mSD); Element.Builder eb = new Element.Builder(mRS); - eb.add(Element.DataType.UNSIGNED, Element.DataKind.RED, true, 8); - eb.add(Element.DataType.UNSIGNED, Element.DataKind.GREEN, true, 8); - eb.add(Element.DataType.UNSIGNED, Element.DataKind.BLUE, true, 8); - eb.add(Element.DataType.UNSIGNED, Element.DataKind.ALPHA, true, 8); - eb.add(Element.DataType.FLOAT, Element.DataKind.X, false, 32); - eb.add(Element.DataType.FLOAT, Element.DataKind.Y, false, 32); + eb.addFloat(Element.DataKind.USER); //dx + eb.addFloat(Element.DataKind.USER); //dy + eb.addFloatXY(); + eb.addUNorm8RGBA(); Element primElement = eb.create(); + SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS); - int vtxSlot = smb.addVertexType(primElement, PART_COUNT * 3); - smb.setPrimitive(Primitive.TRIANGLE); + int vtxSlot = smb.addVertexType(primElement, PART_COUNT); + smb.setPrimitive(Primitive.POINT); mSM = smb.create(); mSM.setName("PartMesh"); @@ -118,13 +103,12 @@ public class FountainRS { ScriptC.Builder sb = new ScriptC.Builder(mRS); sb.setScript(mRes, R.raw.fountain); sb.setRoot(true); - sb.setType(mSDType, 0); + sb.setType(mSDType, "Control", 0); mScript = sb.create(); mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); mScript.bindAllocation(mIntAlloc, 0); mScript.bindAllocation(mPartAlloc, 1); - mScript.bindAllocation(mVertAlloc, 2); mRS.contextBindRootScript(mScript); } 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 be8b24e..2768e2c 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java @@ -61,13 +61,18 @@ public class FountainView extends RSSurfaceView { @Override public boolean onTouchEvent(MotionEvent ev) { - boolean ret = true; int act = ev.getAction(); if (act == ev.ACTION_UP) { - ret = false; + mRender.newTouchPosition(0, 0, 0); + return false; } - mRender.newTouchPosition((int)ev.getX(), (int)ev.getY()); - return ret; + float rate = (ev.getPressure() * 50.f); + rate *= rate; + if(rate > 2000.f) { + rate = 2000.f; + } + mRender.newTouchPosition((int)ev.getX(), (int)ev.getY(), (int)rate); + return true; } } |