diff options
Diffstat (limited to 'tests/RenderScriptTests/Balls')
-rw-r--r-- | tests/RenderScriptTests/Balls/Android.mk | 26 | ||||
-rw-r--r-- | tests/RenderScriptTests/Balls/AndroidManifest.xml | 16 | ||||
-rw-r--r-- | tests/RenderScriptTests/Balls/_index.html | 1 | ||||
-rw-r--r-- | tests/RenderScriptTests/Balls/res/drawable/flares.png | bin | 413 -> 0 bytes | |||
-rw-r--r-- | tests/RenderScriptTests/Balls/res/drawable/test_pattern.png | bin | 307 -> 0 bytes | |||
-rw-r--r-- | tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/Balls.java | 118 | ||||
-rw-r--r-- | tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsRS.java | 151 | ||||
-rw-r--r-- | tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsView.java | 116 | ||||
-rw-r--r-- | tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/ball_physics.rs | 155 | ||||
-rw-r--r-- | tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/balls.rs | 106 | ||||
-rw-r--r-- | tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/balls.rsh | 19 |
11 files changed, 0 insertions, 708 deletions
diff --git a/tests/RenderScriptTests/Balls/Android.mk b/tests/RenderScriptTests/Balls/Android.mk deleted file mode 100644 index 77281ce..0000000 --- a/tests/RenderScriptTests/Balls/Android.mk +++ /dev/null @@ -1,26 +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_MODULE_TAGS := tests - -LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src) - -LOCAL_PACKAGE_NAME := RsBalls - -include $(BUILD_PACKAGE) diff --git a/tests/RenderScriptTests/Balls/AndroidManifest.xml b/tests/RenderScriptTests/Balls/AndroidManifest.xml deleted file mode 100644 index 80e6b39..0000000 --- a/tests/RenderScriptTests/Balls/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.example.android.rs.balls"> - <uses-sdk android:minSdkVersion="14" /> - <application - android:label="RsBalls" - android:icon="@drawable/test_pattern"> - <activity android:name="Balls" - android:screenOrientation="landscape"> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - </application> -</manifest> diff --git a/tests/RenderScriptTests/Balls/_index.html b/tests/RenderScriptTests/Balls/_index.html deleted file mode 100644 index 8760485..0000000 --- a/tests/RenderScriptTests/Balls/_index.html +++ /dev/null @@ -1 +0,0 @@ -<p>A brute force physics simulation that renders many balls onto the screen and moves them according to user touch and gravity.</p>
\ No newline at end of file diff --git a/tests/RenderScriptTests/Balls/res/drawable/flares.png b/tests/RenderScriptTests/Balls/res/drawable/flares.png Binary files differdeleted file mode 100644 index 3a5c970..0000000 --- a/tests/RenderScriptTests/Balls/res/drawable/flares.png +++ /dev/null diff --git a/tests/RenderScriptTests/Balls/res/drawable/test_pattern.png b/tests/RenderScriptTests/Balls/res/drawable/test_pattern.png Binary files differdeleted file mode 100644 index e7d1455..0000000 --- a/tests/RenderScriptTests/Balls/res/drawable/test_pattern.png +++ /dev/null diff --git a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/Balls.java b/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/Balls.java deleted file mode 100644 index 2c6558e..0000000 --- a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/Balls.java +++ /dev/null @@ -1,118 +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.example.android.rs.balls; - -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.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 android.app.Activity; -import android.content.Context; -import android.os.Bundle; -import android.view.View; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; - -public class Balls extends Activity implements SensorEventListener { - //EventListener mListener = new EventListener(); - - private static final String LOG_TAG = "libRS_jni"; - private static final boolean DEBUG = false; - private static final boolean LOG_ENABLED = false; - - private BallsView mView; - private SensorManager mSensorManager; - - // get the current looper (from your Activity UI thread for instance - - - public void onSensorChanged(SensorEvent event) { - //android.util.Log.d("rs", "sensor: " + event.sensor + ", x: " + event.values[0] + ", y: " + event.values[1] + ", z: " + event.values[2]); - synchronized (this) { - if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { - if(mView != null) { - mView.setAccel(event.values[0], event.values[1], event.values[2]); - } - } - } - } - - public void onAccuracyChanged(Sensor sensor, int accuracy) { - } - - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - - mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); - - // Create our Preview view and set it as the content of our - // Activity - mView = new BallsView(this); - setContentView(mView); - } - - @Override - protected void onResume() { - mSensorManager.registerListener(this, - mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), - SensorManager.SENSOR_DELAY_FASTEST); - - // Ideally a game should implement onResume() and onPause() - // to take appropriate action when the activity looses focus - super.onResume(); - mView.resume(); - } - - @Override - protected void onPause() { - super.onPause(); - mView.pause(); - onStop(); - } - - @Override - protected void onStop() { - mSensorManager.unregisterListener(this); - super.onStop(); - } - - static void log(String message) { - if (LOG_ENABLED) { - Log.v(LOG_TAG, message); - } - } - - -} - diff --git a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsRS.java b/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsRS.java deleted file mode 100644 index d9d182c..0000000 --- a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsRS.java +++ /dev/null @@ -1,151 +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.example.android.rs.balls; - -import android.content.res.Resources; -import android.renderscript.*; -import android.util.Log; - - -public class BallsRS { - public static final int PART_COUNT = 4000; - - public BallsRS() { - } - - private Resources mRes; - private RenderScriptGL mRS; - private ScriptC_balls mScript; - private ScriptC_ball_physics mPhysicsScript; - private ProgramFragment mPFPoints; - private ScriptField_Point mPoints; - private ScriptField_VpConsts mVpConsts; - private ScriptField_BallGrid mGrid; - private ScriptField_Ball mBalls; - private Allocation mGridCache; - - void updateProjectionMatrices() { - mVpConsts = new ScriptField_VpConsts(mRS, 1, - Allocation.USAGE_SCRIPT | - Allocation.USAGE_GRAPHICS_CONSTANTS); - ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item(); - Matrix4f mvp = new Matrix4f(); - mvp.loadOrtho(0, mRS.getWidth(), mRS.getHeight(), 0, -1, 1); - i.MVP = mvp; - mVpConsts.set(i, 0, true); - } - - private void createProgramVertex() { - updateProjectionMatrices(); - - ProgramVertex.Builder sb = new ProgramVertex.Builder(mRS); - String t = "varying vec4 varColor;\n" + - "void main() {\n" + - " vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n" + - " pos.xy = ATTRIB_position;\n" + - " gl_Position = UNI_MVP * pos;\n" + - " varColor = ATTRIB_color;\n" + - " gl_PointSize = 12.0;\n" + - "}\n"; - sb.setShader(t); - sb.addConstant(mVpConsts.getType()); - sb.addInput(mPoints.getElement()); - ProgramVertex pvs = sb.create(); - pvs.bindConstants(mVpConsts.getAllocation(), 0); - mRS.bindProgramVertex(pvs); - } - - private Allocation loadTexture(int id) { - final Allocation allocation = - Allocation.createFromBitmapResource(mRS, mRes, - id, Allocation.MipmapControl.MIPMAP_NONE, - Allocation.USAGE_GRAPHICS_TEXTURE); - return allocation; - } - - ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) { - ProgramStore.Builder builder = new ProgramStore.Builder(rs); - builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); - builder.setBlendFunc(ProgramStore.BlendSrcFunc.ONE, ProgramStore.BlendDstFunc.ONE); - builder.setDitherEnabled(false); - builder.setDepthMaskEnabled(false); - return builder.create(); - } - - private void createPF(int width, int height) { - ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(mRS); - pfb.setPointSpriteTexCoordinateReplacement(true); - pfb.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE, - ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); - pfb.setVaryingColor(true); - mPFPoints = pfb.create(); - } - - public void init(RenderScriptGL rs, Resources res, int width, int height) { - mRS = rs; - mRes = res; - - createPF(width, height); - - mPFPoints.bindTexture(loadTexture(R.drawable.flares), 0); - - mPoints = new ScriptField_Point(mRS, PART_COUNT, Allocation.USAGE_SCRIPT); - - Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS); - smb.addVertexAllocation(mPoints.getAllocation()); - smb.addIndexSetType(Mesh.Primitive.POINT); - Mesh smP = smb.create(); - - mGrid = ScriptField_BallGrid.create2D(mRS, (width + 99) / 100, (height + 99) / 100); - mGridCache = Allocation.createSized(mRS, Element.F32_2(mRS), PART_COUNT); - mBalls = new ScriptField_Ball(mRS, PART_COUNT, Allocation.USAGE_SCRIPT); - - mPhysicsScript = new ScriptC_ball_physics(mRS); - mPhysicsScript.set_gGridCache(mGridCache); - mPhysicsScript.set_gBalls(mBalls.getAllocation()); - - mScript = new ScriptC_balls(mRS); - mScript.set_partMesh(smP); - mScript.set_physics_script(mPhysicsScript); - mScript.bind_point(mPoints); - mScript.bind_balls(mBalls); - mScript.set_gGrid(mGrid.getAllocation()); - mScript.bind_gGridCache(mGridCache); - - mScript.set_gPFPoints(mPFPoints); - createProgramVertex(); - - mRS.bindProgramStore(BLEND_ADD_DEPTH_NONE(mRS)); - - mPhysicsScript.set_gMinPos(new Float2(5, 5)); - mPhysicsScript.set_gMaxPos(new Float2(width - 5, height - 5)); - mPhysicsScript.set_gGrid(mGrid.getAllocation()); - - mScript.invoke_initParts(width, height); - - mRS.bindRootScript(mScript); - } - - public void newTouchPosition(float x, float y, float pressure, int id) { - mPhysicsScript.invoke_touch(x, y, pressure * mRS.getWidth() / 1280, id); - } - - public void setAccel(float x, float y) { - mPhysicsScript.set_gGravityVector(new Float2(x, y)); - } - -} diff --git a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsView.java b/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsView.java deleted file mode 100644 index 041782d..0000000 --- a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/BallsView.java +++ /dev/null @@ -1,116 +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.example.android.rs.balls; - -import java.io.Writer; -import java.util.ArrayList; -import java.util.concurrent.Semaphore; - -import android.renderscript.RSSurfaceView; -import android.renderscript.RenderScript; -import android.renderscript.RenderScriptGL; - -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; - -public class BallsView extends RSSurfaceView { - - public BallsView(Context context) { - super(context); - //setFocusable(true); - } - - private RenderScriptGL mRS; - private BallsRS mRender; - - public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { - super.surfaceChanged(holder, format, w, h); - if (mRS == null) { - RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); - mRS = createRenderScriptGL(sc); - mRS.setSurface(holder, w, h); - mRender = new BallsRS(); - mRender.init(mRS, getResources(), w, h); - } - mRender.updateProjectionMatrices(); - } - - @Override - protected void onDetachedFromWindow() { - if(mRS != null) { - mRS = null; - destroyRenderScriptGL(); - } - } - - - @Override - public boolean onTouchEvent(MotionEvent ev) - { - int act = ev.getActionMasked(); - if (act == ev.ACTION_UP) { - mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0)); - return false; - } else if (act == MotionEvent.ACTION_POINTER_UP) { - // only one pointer going up, we can get the index like this - int pointerIndex = ev.getActionIndex(); - int pointerId = ev.getPointerId(pointerIndex); - mRender.newTouchPosition(0, 0, 0, pointerId); - return false; - } - int count = ev.getHistorySize(); - int pcount = ev.getPointerCount(); - - for (int p=0; p < pcount; p++) { - int id = ev.getPointerId(p); - mRender.newTouchPosition(ev.getX(p), - ev.getY(p), - ev.getPressure(p), - id); - - for (int i=0; i < count; i++) { - mRender.newTouchPosition(ev.getHistoricalX(p, i), - ev.getHistoricalY(p, i), - ev.getHistoricalPressure(p, i), - id); - } - } - return true; - } - - void setAccel(float x, float y, float z) { - if ((mRender == null) || (mRS == null)) { - return; - } - mRender.setAccel(x, -y); - } - -} - - diff --git a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/ball_physics.rs b/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/ball_physics.rs deleted file mode 100644 index 5b5d2e0..0000000 --- a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/ball_physics.rs +++ /dev/null @@ -1,155 +0,0 @@ -#pragma version(1) -#pragma rs java_package_name(com.example.android.rs.balls) - -#include "balls.rsh" - -float2 gGravityVector = {0.f, 9.8f}; - -float2 gMinPos = {0.f, 0.f}; -float2 gMaxPos = {1280.f, 700.f}; - -static float2 touchPos[10]; -static float touchPressure[10]; -static const float gDT = 1.f / 30.f; - -rs_allocation gGrid; -rs_allocation gGridCache; -rs_allocation gBalls; - -float gScale = 1.f; - -void touch(float x, float y, float pressure, int id) { - if (id >= 10) { - return; - } - - touchPos[id].x = x; - touchPos[id].y = y; - touchPressure[id] = pressure; -} - -void root(Ball_t *ball, uint32_t x) { - float2 fv = 0; - float pressure = 0; - float2 pos = ball->position; - int2 gridPos[9]; - - gridPos[0] = convert_int2((ball->position / 100.f) /*- 0.4999f*/); - gridPos[1] = (int2){gridPos[0].x - 1, gridPos[0].y - 1}; - gridPos[2] = (int2){gridPos[0].x + 0, gridPos[0].y - 1}; - gridPos[3] = (int2){gridPos[0].x + 1, gridPos[0].y - 1}; - gridPos[4] = (int2){gridPos[0].x - 1, gridPos[0].y}; - gridPos[5] = (int2){gridPos[0].x + 1, gridPos[0].y}; - gridPos[6] = (int2){gridPos[0].x - 1, gridPos[0].y + 1}; - gridPos[7] = (int2){gridPos[0].x + 0, gridPos[0].y + 1}; - gridPos[8] = (int2){gridPos[0].x + 1, gridPos[0].y + 1}; - - for (int gct=0; gct < 9; gct++) { - if ((gridPos[gct].x >= rsAllocationGetDimX(gGrid)) || - (gridPos[gct].x < 0) || - (gridPos[gct].y >= rsAllocationGetDimY(gGrid)) || - (gridPos[gct].y < 0)) { - continue; - } - //rsDebug("grid ", gridPos[gct]); - const BallGrid_t *bg = (const BallGrid_t *)rsGetElementAt(gGrid, gridPos[gct].x, gridPos[gct].y); - - for (int cidx = 0; cidx < bg->count; cidx++) { - float2 bcptr = rsGetElementAt_float2(gGridCache, bg->cacheIdx + cidx); - float2 vec = bcptr - pos; - float2 vec2 = vec * vec; - float len2 = vec2.x + vec2.y; - - if ((len2 < 10000.f) && (len2 > 0.f)) { - float t = native_powr(len2, 1.5f) + 16.0f; - float2 pfv = (vec / t) * 16000.f; - pressure += length(pfv); - fv -= pfv; - } - } - } - - //fv /= ball->size * ball->size * ball->size; - fv -= gGravityVector * 4.f * gScale; - fv *= gDT; - - for (int i=0; i < 10; i++) { - if (touchPressure[i] > 0.1f) { - float2 vec = touchPos[i] - ball->position; - float2 vec2 = vec * vec; - float len2 = max(2.f, vec2.x + vec2.y); - float2 pfv = (vec / len2) * touchPressure[i] * 500.f * gScale; - pressure += length(pfv); - fv -= pfv; - } - } - - ball->delta = (ball->delta * (1.f - 0.008f)) + fv; - ball->position = ball->position + (ball->delta * gDT); - - const float wallForce = 400.f * gScale; - if (ball->position.x > (gMaxPos.x - 20.f)) { - float d = gMaxPos.x - ball->position.x; - if (d < 0.f) { - if (ball->delta.x > 0) { - ball->delta.x *= -0.7f; - } - ball->position.x = gMaxPos.x - 1.f; - } else { - ball->delta.x -= min(wallForce / (d * d), 10.f); - } - } - - if (ball->position.x < (gMinPos.x + 20.f)) { - float d = ball->position.x - gMinPos.x; - if (d < 0.f) { - if (ball->delta.x < 0) { - ball->delta.x *= -0.7f; - } - ball->position.x = gMinPos.x + 1.f; - } else { - ball->delta.x += min(wallForce / (d * d), 10.f); - } - } - - if (ball->position.y > (gMaxPos.y - 20.f)) { - float d = gMaxPos.y - ball->position.y; - if (d < 0.f) { - if (ball->delta.y > 0) { - ball->delta.y *= -0.7f; - } - ball->position.y = gMaxPos.y - 1.f; - } else { - ball->delta.y -= min(wallForce / (d * d), 10.f); - } - } - - if (ball->position.y < (gMinPos.y + 20.f)) { - float d = ball->position.y - gMinPos.y; - if (d < 0.f) { - if (ball->delta.y < 0) { - ball->delta.y *= -0.7f; - } - ball->position.y = gMinPos.y + 1.f; - } else { - ball->delta.y += min(wallForce / (d * d * d), 10.f); - } - } - - // low pressure ~500, high ~2500 - pressure = max(pressure - 400.f, 0.f); - ball->pressure = pressure; - - //rsDebug("p ", pressure); - - float4 color = 1.f; - color.r = pow(pressure, 0.25f) / 12.f; - color.b = 1.f - color.r; - color.g = sin(pressure / 1500.f * 3.14f); - color.rgb = max(color.rgb, (float3)0); - color.rgb = normalize(color.rgb); - ball->color = rsPackColorTo8888(color); - - //rsDebug("physics pos out", ball->position); -} - diff --git a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/balls.rs b/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/balls.rs deleted file mode 100644 index 9be9f38..0000000 --- a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/balls.rs +++ /dev/null @@ -1,106 +0,0 @@ -#pragma version(1) -#pragma rs java_package_name(com.example.android.rs.balls) -#include "rs_graphics.rsh" - -#include "balls.rsh" - -#pragma stateVertex(parent) -#pragma stateStore(parent) - -rs_program_fragment gPFPoints; -rs_mesh partMesh; - -rs_allocation gGrid; -BallGrid_t *unused1; -float2 *gGridCache; - -typedef struct __attribute__((packed, aligned(4))) Point { - float2 position; - uchar4 color; -} Point_t; -Point_t *point; - -typedef struct VpConsts { - rs_matrix4x4 MVP; -} VpConsts_t; -VpConsts_t *vpConstants; - -rs_script physics_script; - - -void initParts(int w, int h) -{ - uint32_t dimX = rsAllocationGetDimX(rsGetAllocation(balls)); - - for (uint32_t ct=0; ct < dimX; ct++) { - balls[ct].position.x = rsRand(0.f, (float)w); - balls[ct].position.y = rsRand(0.f, (float)h); - balls[ct].delta.x = 0.f; - balls[ct].delta.y = 0.f; - } -} - -int root() { - rsgClearColor(0.f, 0.f, 0.f, 1.f); - - int2 gridDims = (int2){ rsAllocationGetDimX(gGrid), - rsAllocationGetDimY(gGrid) }; - - rs_allocation ain = rsGetAllocation(balls); - int32_t dimX = rsAllocationGetDimX(ain); - - // Binning - // Clear the particle list - for (uint32_t ct=0; ct < dimX; ct++) { - balls[ct].next = -1; - } - - // Clear the grid - for (uint32_t y=0; y < gridDims.y; y++) { - for (uint32_t x=0; x < gridDims.x; x++) { - BallGrid_t *bg = (BallGrid_t *)rsGetElementAt(gGrid, x, y); - bg->count = 0; - bg->idx = -1; - } - } - - // Create the particle list per grid - for (uint32_t ct=0; ct < dimX; ct++) { - int2 p = convert_int2(balls[ct].position / 100.f); - p.x = rsClamp(p.x, 0, (int)(gridDims.x-1)); - p.y = rsClamp(p.y, 0, (int)(gridDims.y-1)); - BallGrid_t *bg = (BallGrid_t *)rsGetElementAt(gGrid, p.x, p.y); - bg->count ++; - balls[ct].next = bg->idx; - bg->idx = ct; - } - - // Create the sorted grid cache - uint32_t gridIdx = 0; - for (uint32_t y=0; y < gridDims.y; y++) { - for (uint32_t x=0; x < gridDims.x; x++) { - BallGrid_t *bg = (BallGrid_t *)rsGetElementAt(gGrid, x, y); - bg->cacheIdx = gridIdx; - - int idx = bg->idx; - while (idx >= 0) { - const Ball_t * bPtr = &balls[idx]; - gGridCache[gridIdx++] = bPtr->position; - idx = bPtr->next; - } - } - } - - - rsForEach(physics_script, ain, ain); - - for (uint32_t ct=0; ct < dimX; ct++) { - point[ct].position = balls[ct].position; - point[ct].color = balls[ct].color; - } - - rsgBindProgramFragment(gPFPoints); - rsgDrawMesh(partMesh); - return 1; -} - diff --git a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/balls.rsh b/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/balls.rsh deleted file mode 100644 index ebe23f8..0000000 --- a/tests/RenderScriptTests/Balls/src/com/example/android/rs/balls/balls.rsh +++ /dev/null @@ -1,19 +0,0 @@ - -typedef struct __attribute__((packed, aligned(4))) Ball { - float2 delta; - float2 position; - uchar4 color; - float pressure; - //float size; - int32_t next; - //int arcID; - //float arcStr; -} Ball_t; -Ball_t *balls; - - -typedef struct BallGrid { - int32_t idx; - int32_t count; - int32_t cacheIdx; -} BallGrid_t; |