diff options
author | Romain Guy <romainguy@android.com> | 2009-08-04 21:16:17 -0700 |
---|---|---|
committer | Romain Guy <romainguy@android.com> | 2009-08-05 18:39:37 -0700 |
commit | 31858c2b84d3aa273198731afb057aa70308eb7e (patch) | |
tree | c175b80d26c34c64e1260bd666335f7078330b18 /libs/rs/java/Fall/src/com | |
parent | 53c66b490a7bcae0efd3c8379ba01080d25ef69c (diff) | |
download | frameworks_base-31858c2b84d3aa273198731afb057aa70308eb7e.zip frameworks_base-31858c2b84d3aa273198731afb057aa70308eb7e.tar.gz frameworks_base-31858c2b84d3aa273198731afb057aa70308eb7e.tar.bz2 |
Draw untextured water mesh
Diffstat (limited to 'libs/rs/java/Fall/src/com')
-rw-r--r-- | libs/rs/java/Fall/src/com/android/fall/rs/FallRS.java | 43 |
1 files changed, 41 insertions, 2 deletions
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() { |