diff options
author | Alex Sakhartchouk <alexst@google.com> | 2012-02-03 15:50:18 -0800 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2012-02-03 15:52:04 -0800 |
commit | 6f31c36a3dbe5e61644ec39c4fcad0284d50e4f1 (patch) | |
tree | 9c1bd5eabb50d8f2948350848913ff9bc1ee96a6 /tests/RenderScriptTests/SceneGraph/src | |
parent | 912d82efebfdc2a6260e665a0f83362defd9affd (diff) | |
download | frameworks_base-6f31c36a3dbe5e61644ec39c4fcad0284d50e4f1.zip frameworks_base-6f31c36a3dbe5e61644ec39c4fcad0284d50e4f1.tar.gz frameworks_base-6f31c36a3dbe5e61644ec39c4fcad0284d50e4f1.tar.bz2 |
Fixes to simplify programmatic creation.
Change-Id: Ief2c794b0c50ce8016737628b9a7348574590039
Diffstat (limited to 'tests/RenderScriptTests/SceneGraph/src')
6 files changed, 72 insertions, 38 deletions
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java index 6e19825..42f2be5 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java @@ -39,7 +39,7 @@ public class Camera extends SceneGraphBase { public Camera() { mData = new ScriptField_Camera_s.Item(); mData.near = 0.1f; - mData.far = 100.0f; + mData.far = 1000.0f; mData.horizontalFOV = 60.0f; mData.aspect = 0; } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java index 79e932d..1c68e30 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java @@ -318,7 +318,7 @@ public class Scene extends SceneGraphBase { if (mLights.size() != 0) { Allocation lightData = Allocation.createSized(rs, Element.ALLOCATION(rs), - mCameras.size()); + mLights.size()); Allocation[] lightAllocs = new Allocation[mLights.size()]; for (int i = 0; i < mLights.size(); i ++) { lightAllocs[i] = mLights.get(i).getRSData().getAllocation(); diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java index a9dd8a1..01712b4 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java @@ -28,7 +28,10 @@ import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.android.scenegraph.Camera; +import com.android.scenegraph.MatrixTransform; import com.android.scenegraph.Scene; +import com.android.testapp.R; import android.content.res.Resources; import android.graphics.Bitmap; @@ -41,8 +44,6 @@ import android.renderscript.RenderScriptGL; import android.util.Log; import android.view.SurfaceHolder; -import com.android.testapp.R; - /** * @hide */ @@ -180,6 +181,20 @@ public class SceneManager extends SceneGraphBase { public void setActiveScene(Scene s) { mActiveScene = s; + + // Do some sanity checking + if (mActiveScene.getCameras().size() == 0) { + Matrix4f camPos = new Matrix4f(); + camPos.translate(0, 0, 10); + MatrixTransform cameraTransform = new MatrixTransform(); + cameraTransform.setName("_DefaultCameraTransform"); + cameraTransform.setMatrix(camPos); + mActiveScene.appendTransform(cameraTransform); + Camera cam = new Camera(); + cam.setName("_DefaultCamera"); + cam.setTransform(cameraTransform); + mActiveScene.appendCamera(cam); + } } static RenderScriptGL getRS() { diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java index 2299b72..3bad3b3 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java @@ -75,18 +75,18 @@ class FullscreenBlur { quad.appendSourceParams(new Float4Param("blurOffset3", advance * 3.5f));
}
- static RenderPass addPass(Scene scene, Allocation color, Allocation depth) {
+ static RenderPass addPass(Scene scene, Camera cam, Allocation color, Allocation depth) {
RenderPass pass = new RenderPass();
pass.setColorTarget(color);
pass.setDepthTarget(depth);
pass.setShouldClearColor(false);
pass.setShouldClearDepth(false);
- pass.setCamera(scene.getCameras().get(1));
+ pass.setCamera(cam);
scene.appendRenderPass(pass);
return pass;
}
- static void addBlurPasses(Scene scene, RenderScriptGL rs) {
+ static void addBlurPasses(Scene scene, RenderScriptGL rs, Camera cam) {
SceneManager sceneManager = SceneManager.getInstance();
ArrayList<RenderableBase> allDraw = scene.getRenderables();
int numDraw = allDraw.size();
@@ -101,7 +101,7 @@ class FullscreenBlur { RenderState vBlur = new RenderState(mPV_Blur, mPF_BlurV, blendNone, cullNone);
// Renders the scene off screen
- RenderPass blurSourcePass = addPass(scene,
+ RenderPass blurSourcePass = addPass(scene, cam,
sRenderTargetBlur0Color,
sRenderTargetBlur0Depth);
blurSourcePass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 1.0f));
@@ -113,42 +113,42 @@ class FullscreenBlur { }
// Pass for selecting bright colors
- RenderPass selectColorPass = addPass(scene,
+ RenderPass selectColorPass = addPass(scene, cam,
sRenderTargetBlur2Color,
sRenderTargetBlur2Depth);
Renderable quad = sceneManager.getRenderableQuad("ScreenAlignedQuadS", selectCol);
- quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur0Color)));
+ quad.appendSourceParams(new TextureParam("color", new Texture2D(sRenderTargetBlur0Color)));
selectColorPass.appendRenderable(quad);
// Horizontal blur
- RenderPass horizontalBlurPass = addPass(scene,
+ RenderPass horizontalBlurPass = addPass(scene, cam,
sRenderTargetBlur1Color,
sRenderTargetBlur1Depth);
quad = sceneManager.getRenderableQuad("ScreenAlignedQuadH", hBlur);
- quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur2Color)));
+ quad.appendSourceParams(new TextureParam("color", new Texture2D(sRenderTargetBlur2Color)));
addOffsets(quad, 1.0f / (float)sRenderTargetBlur0Color.getType().getX());
horizontalBlurPass.appendRenderable(quad);
// Vertical Blur
- RenderPass verticalBlurPass = addPass(scene,
+ RenderPass verticalBlurPass = addPass(scene, cam,
sRenderTargetBlur2Color,
sRenderTargetBlur2Depth);
quad = sceneManager.getRenderableQuad("ScreenAlignedQuadV", vBlur);
- quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur1Color)));
+ quad.appendSourceParams(new TextureParam("color", new Texture2D(sRenderTargetBlur1Color)));
addOffsets(quad, 1.0f / (float)sRenderTargetBlur0Color.getType().getY());
verticalBlurPass.appendRenderable(quad);
}
// Additively renders the blurred colors on top of the scene
- static void addCompositePass(Scene scene, RenderScriptGL rs) {
+ static void addCompositePass(Scene scene, RenderScriptGL rs, Camera cam) {
SceneManager sceneManager = SceneManager.getInstance();
RenderState drawTex = new RenderState(mPV_Blur, mPF_Texture,
SceneManager.BLEND_ADD_DEPTH_NONE(rs),
ProgramRaster.CULL_NONE(rs));
- RenderPass compositePass = addPass(scene, null, null);
- Renderable quad = sceneManager.getRenderableQuad("ScreenAlignedQuad", drawTex);
- quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur2Color)));
+ RenderPass compositePass = addPass(scene, cam, null, null);
+ Renderable quad = sceneManager.getRenderableQuad("ScreenAlignedQuadComposite", drawTex);
+ quad.appendSourceParams(new TextureParam("color", new Texture2D(sRenderTargetBlur2Color)));
compositePass.appendRenderable(quad);
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java index 2757398..08175f1 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java @@ -189,7 +189,7 @@ public class TestAppRS { int numDraw = allDraw.size(); if (mUseBlur) { - FullscreenBlur.addBlurPasses(mActiveScene, mRS); + FullscreenBlur.addBlurPasses(mActiveScene, mRS, mTouchHandler.getCamera()); } RenderPass mainPass = new RenderPass(); @@ -197,14 +197,14 @@ public class TestAppRS { mainPass.setShouldClearColor(true); mainPass.setClearDepth(1.0f); mainPass.setShouldClearDepth(true); - mainPass.setCamera(mActiveScene.getCameras().get(1)); + mainPass.setCamera(mTouchHandler.getCamera()); for (int i = 0; i < numDraw; i ++) { mainPass.appendRenderable((Renderable)allDraw.get(i)); } mActiveScene.appendRenderPass(mainPass); if (mUseBlur) { - FullscreenBlur.addCompositePass(mActiveScene, mRS); + FullscreenBlur.addCompositePass(mActiveScene, mRS, mTouchHandler.getCamera()); } } @@ -221,6 +221,7 @@ public class TestAppRS { public void prepareToRender(Scene s) { mSceneManager.setActiveScene(s); mActiveScene = s; + mTouchHandler.init(mActiveScene); addShadersToScene(); RenderState plastic = new RenderState(mGenericV, mPlasticF, null, null); RenderState diffuse = new RenderState(mGenericV, mDiffuseF, null, null); @@ -255,8 +256,6 @@ public class TestAppRS { plane.setVisible(!mUseBlur); } - mTouchHandler.init(mActiveScene); - long start = System.currentTimeMillis(); mActiveScene.initRS(mRS, mRes, mSceneManager); long end = System.currentTimeMillis(); diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java index 5dcc9f8..d8e48e8 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java @@ -28,25 +28,45 @@ public class TouchHandler { float mLastX; float mLastY; - RotateComponent mRotateX; float mRotateXValue; - RotateComponent mRotateY; float mRotateYValue; - TranslateComponent mDist; Float3 mDistValue; + Float3 mPosValue; + + CompoundTransform mCameraRig; + RotateComponent mRotateX; + RotateComponent mRotateY; + TranslateComponent mDist; + TranslateComponent mPosition; + Camera mCamera; public void init(Scene scene) { - CompoundTransform cameraRotate = (CompoundTransform)scene.getTransformByName("CameraAim"); - CompoundTransform cameraDist = (CompoundTransform)scene.getTransformByName("CameraDist"); - - if (cameraRotate != null && cameraDist != null) { - mRotateX = (RotateComponent)cameraRotate.mTransformComponents.get(2); - mRotateXValue = mRotateX.getAngle(); - mRotateY = (RotateComponent)cameraRotate.mTransformComponents.get(1); - mRotateYValue = mRotateY.getAngle(); - mDist = (TranslateComponent)cameraDist.mTransformComponents.get(0); - mDistValue = mDist.getValue(); - } + // Some initial values for camera position + mRotateXValue = -20; + mRotateYValue = 45; + mDistValue = new Float3(0, 0, 45); + mPosValue = new Float3(0, 4, 0); + + mRotateX = new RotateComponent("RotateX", new Float3(1, 0, 0), mRotateXValue); + mRotateY = new RotateComponent("RotateY", new Float3(0, 1, 0), mRotateYValue); + mDist = new TranslateComponent("Distance", mDistValue); + mPosition = new TranslateComponent("Distance", mPosValue); + + // Make a camera transform we can manipulate + mCameraRig = new CompoundTransform(); + mCameraRig.setName("CameraRig"); + mCameraRig.addComponent(mPosition); + mCameraRig.addComponent(mRotateY); + mCameraRig.addComponent(mRotateX); + mCameraRig.addComponent(mDist); + scene.appendTransform(mCameraRig); + mCamera = new Camera(); + mCamera.setTransform(mCameraRig); + scene.appendCamera(mCamera); + } + + public Camera getCamera() { + return mCamera; } public void onActionDown(float x, float y) { @@ -59,7 +79,7 @@ public class TouchHandler { return; } mDistValue.z *= 1.0f / scale; - mDistValue.z = Math.max(20.0f, Math.min(mDistValue.z, 100.0f)); + mDistValue.z = Math.max(10.0f, Math.min(mDistValue.z, 150.0f)); mDist.setValue(mDistValue); } |