summaryrefslogtreecommitdiffstats
path: root/libs/rs/java
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs/java')
-rw-r--r--libs/rs/java/Fall/res/raw/fall.c11
-rw-r--r--libs/rs/java/Fall/src/com/android/fall/rs/FallRS.java43
-rw-r--r--libs/rs/java/Grass/res/drawable-hdpi/aa.pngbin2803 -> 0 bytes
-rw-r--r--libs/rs/java/Grass/res/drawable-hdpi/night.jpgbin65755 -> 76591 bytes
-rw-r--r--libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java29
5 files changed, 67 insertions, 16 deletions
diff --git a/libs/rs/java/Fall/res/raw/fall.c b/libs/rs/java/Fall/res/raw/fall.c
index e69de29..76847e0 100644
--- a/libs/rs/java/Fall/res/raw/fall.c
+++ b/libs/rs/java/Fall/res/raw/fall.c
@@ -0,0 +1,11 @@
+#pragma version(1)
+#pragma stateVertex(PVBackground)
+#pragma stateFragment(PFBackground)
+#pragma stateFragmentStore(PSBackground)
+
+int main(int index) {
+ color(1.0f, 0.0f, 0.0f, 1.0f);
+ drawTriangleMesh(NAMED_mesh);
+
+ return 1;
+}
diff --git a/libs/rs/java/Fall/src/com/android/fall/rs/FallRS.java b/libs/rs/java/Fall/src/com/android/fall/rs/FallRS.java
index 833bed0..155bb6f 100644
--- a/libs/rs/java/Fall/src/com/android/fall/rs/FallRS.java
+++ b/libs/rs/java/Fall/src/com/android/fall/rs/FallRS.java
@@ -24,7 +24,7 @@ import android.renderscript.ProgramStore;
import android.renderscript.ProgramVertex;
import android.renderscript.Allocation;
import android.renderscript.Sampler;
-import android.renderscript.ProgramVertex;
+import android.renderscript.Element;
import static android.renderscript.Sampler.Value.LINEAR;
import static android.renderscript.Sampler.Value.CLAMP;
import static android.renderscript.ProgramStore.DepthFunc.*;
@@ -38,7 +38,7 @@ import android.graphics.Bitmap;
import java.util.TimeZone;
class FallRS {
- private static final int MESH_RESOLUTION = 64;
+ private static final int MESH_RESOLUTION = 32;
private static final int RSID_STATE = 0;
private static final int RSID_STATE_FRAMECOUNT = 0;
@@ -67,6 +67,7 @@ class FallRS {
private int[] mTextureBufferIDs;
private Allocation mState;
+ private RenderScript.TriangleMesh mMesh;
public FallRS(int width, int height) {
mWidth = width;
@@ -94,6 +95,7 @@ class FallRS {
}
mState.destroy();
mTextureBufferIDs = null;
+ mMesh.destroy();
}
@Override
@@ -127,7 +129,44 @@ class FallRS {
}
private void createMesh() {
+ final RenderScript rs = mRS;
+ rs.triangleMeshBegin(Element.XYZ_F32, Element.INDEX_16);
+
+ int wResolution;
+ int hResolution;
+
+ final int width = mWidth;
+ final int height = mHeight;
+
+ if (width < height) {
+ wResolution = MESH_RESOLUTION;
+ hResolution = (int) (MESH_RESOLUTION * height / (float) width);
+ } else {
+ wResolution = (int) (MESH_RESOLUTION * width / (float) height);
+ hResolution = MESH_RESOLUTION;
+ }
+
+ final float quadWidth = width / (float) wResolution;
+ final float quadHeight = height / (float) hResolution;
+
+ for (int y = 0; y <= hResolution; y++) {
+ final float yOffset = y * quadHeight;
+ for (int x = 0; x <= wResolution; x++) {
+ rs.triangleMeshAddVertex_XYZ(x * quadWidth, yOffset, 0.0f);
+ }
+ }
+
+ for (int y = 0; y < hResolution; y++) {
+ for (int x = 0; x < wResolution; x++) {
+ final int index = y * (wResolution + 1) + x;
+ final int iWR1 = index + wResolution + 1;
+ rs.triangleMeshAddTriangle(index, index + 1, iWR1);
+ rs.triangleMeshAddTriangle(index + 1, iWR1, iWR1 + 1);
+ }
+ }
+ mMesh = rs.triangleMeshCreate();
+ mMesh.setName("mesh");
}
private void createScriptStructures() {
diff --git a/libs/rs/java/Grass/res/drawable-hdpi/aa.png b/libs/rs/java/Grass/res/drawable-hdpi/aa.png
deleted file mode 100644
index 34cd891..0000000
--- a/libs/rs/java/Grass/res/drawable-hdpi/aa.png
+++ /dev/null
Binary files differ
diff --git a/libs/rs/java/Grass/res/drawable-hdpi/night.jpg b/libs/rs/java/Grass/res/drawable-hdpi/night.jpg
index 9989abf..77cd7f4 100644
--- a/libs/rs/java/Grass/res/drawable-hdpi/night.jpg
+++ b/libs/rs/java/Grass/res/drawable-hdpi/night.jpg
Binary files differ
diff --git a/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java b/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java
index 8160a41..d6fa105 100644
--- a/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java
+++ b/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java
@@ -32,6 +32,8 @@ import static android.util.MathUtils.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.renderscript.ScriptC;
+import android.renderscript.Type;
+import android.renderscript.Dimension;
import static android.renderscript.Sampler.Value.*;
import java.util.TimeZone;
@@ -64,7 +66,6 @@ class GrassRS {
private Resources mResources;
private RenderScript mRS;
- private final BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options();
private final int mWidth;
private final int mHeight;
@@ -89,8 +90,6 @@ class GrassRS {
public GrassRS(int width, int height) {
mWidth = width;
mHeight = height;
- mBitmapOptions.inScaled = false;
- mBitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
}
public void init(RenderScript rs, Resources res) {
@@ -190,7 +189,7 @@ class GrassRS {
textures[1] = loadTexture(R.drawable.sunrise, "sunrise");
textures[2] = loadTexture(R.drawable.sky, "sky");
textures[3] = loadTexture(R.drawable.sunset, "sunset");
- textures[4] = loadTextureARGB(R.drawable.aa, "aa");
+ textures[4] = generateTextureAlpha(4, 1, new int[] { 0x00FFFF00 }, "aa");
final int[] bufferIds = mTextureBufferIDs;
final int count = textures.length;
@@ -204,18 +203,20 @@ class GrassRS {
mTexturesIDs.data(bufferIds);
}
- private Allocation loadTexture(int id, String name) {
- final Allocation allocation = Allocation.createFromBitmapResource(mRS, mResources,
- id, RGB_565, false);
+ private Allocation generateTextureAlpha(int width, int height, int[] data, String name) {
+ final Type.Builder builder = new Type.Builder(mRS, A_8);
+ builder.add(Dimension.X, width);
+ builder.add(Dimension.Y, height);
+
+ final Allocation allocation = Allocation.createTyped(mRS, builder.create());
+ allocation.data(data);
allocation.setName(name);
return allocation;
}
- private Allocation loadTextureARGB(int id, String name) {
- // Forces ARGB 32 bits, because pngcrush sometimes optimize our PNGs to
- // indexed pictures, which are not well supported
- final Bitmap b = BitmapFactory.decodeResource(mResources, id, mBitmapOptions);
- final Allocation allocation = Allocation.createFromBitmap(mRS, b, RGBA_8888, false);
+ private Allocation loadTexture(int id, String name) {
+ final Allocation allocation = Allocation.createFromBitmapResource(mRS, mResources,
+ id, RGB_565, false);
allocation.setName(name);
return allocation;
}
@@ -236,7 +237,7 @@ class GrassRS {
mPfBackground.setName("PFBackground");
mPfBackground.bindSampler(mSampler, 0);
- b.setTexEnvMode(MODULATE, 0);
+ b.setTexEnvMode(REPLACE, 0);
mPfGrass = b.create();
mPfGrass.setName("PFGrass");
mPfGrass.bindSampler(mSampler, 0);
@@ -253,7 +254,7 @@ class GrassRS {
mPfsBackground = b.create();
mPfsBackground.setName("PFSBackground");
- b.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
+ b.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
mPfsGrass = b.create();
mPfsGrass.setName("PFSGrass");
}