From d4cb9c587c23e3c24d928b0ac1a4de5679846f93 Mon Sep 17 00:00:00 2001 From: Alex Sakhartchouk Date: Thu, 26 Jan 2012 15:51:19 -0800 Subject: Separating scenegraph from the app that uses it. Change-Id: I326d3e9804ae2433e8963105442c4a0b8f8f9a6f --- .../SceneGraph/AndroidManifest.xml | 2 +- .../src/com/android/scenegraph/ColladaScene.java | 9 - .../src/com/android/scenegraph/FileSelector.java | 110 -------- .../src/com/android/scenegraph/FragmentShader.java | 6 +- .../src/com/android/scenegraph/FullscreenBlur.java | 190 -------------- .../src/com/android/scenegraph/Renderable.java | 2 +- .../src/com/android/scenegraph/SceneManager.java | 4 +- .../src/com/android/scenegraph/TestApp.java | 115 -------- .../android/scenegraph/TestAppLoadingScreen.java | 119 --------- .../src/com/android/scenegraph/TestAppRS.java | 291 --------------------- .../src/com/android/scenegraph/TestAppView.java | 152 ----------- .../src/com/android/scenegraph/TouchHandler.java | 122 --------- .../src/com/android/scenegraph/VertexShader.java | 6 +- .../src/com/android/scenegraph/camera.rs | 2 +- .../SceneGraph/src/com/android/scenegraph/cull.rs | 2 +- .../src/com/android/scenegraph/export.rs | 11 +- .../src/com/android/scenegraph/fragment_params.rs | 2 +- .../SceneGraph/src/com/android/scenegraph/light.rs | 2 +- .../src/com/android/scenegraph/object_params.rs | 2 +- .../src/com/android/scenegraph/params.rsh | 2 +- .../src/com/android/scenegraph/render.rs | 2 +- .../src/com/android/scenegraph/scenegraph.rs | 90 ------- .../com/android/scenegraph/scenegraph_objects.rsh | 250 ++++++++++++++++++ .../src/com/android/scenegraph/testApp.rsh | 57 ---- .../src/com/android/scenegraph/transform.rs | 2 +- .../src/com/android/scenegraph/transform_def.rsh | 250 ------------------ .../src/com/android/scenegraph/vertex_params.rs | 2 +- .../src/com/android/testapp/FileSelector.java | 110 ++++++++ .../src/com/android/testapp/FullscreenBlur.java | 187 +++++++++++++ .../src/com/android/testapp/TestApp.java | 115 ++++++++ .../com/android/testapp/TestAppLoadingScreen.java | 117 +++++++++ .../src/com/android/testapp/TestAppRS.java | 289 ++++++++++++++++++++ .../src/com/android/testapp/TestAppView.java | 152 +++++++++++ .../src/com/android/testapp/TouchHandler.java | 122 +++++++++ .../SceneGraph/src/com/android/testapp/test_app.rs | 99 +++++++ .../src/com/android/testapp/test_app.rsh | 57 ++++ 36 files changed, 1522 insertions(+), 1530 deletions(-) delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FileSelector.java delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FullscreenBlur.java delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestApp.java delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppLoadingScreen.java delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppView.java delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TouchHandler.java delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph.rs create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh delete mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FileSelector.java create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestApp.java create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppLoadingScreen.java create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppView.java create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rs create mode 100644 tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rsh (limited to 'tests/RenderScriptTests/SceneGraph') diff --git a/tests/RenderScriptTests/SceneGraph/AndroidManifest.xml b/tests/RenderScriptTests/SceneGraph/AndroidManifest.xml index 7017d5a7b46d..e8d1e8e2b080 100644 --- a/tests/RenderScriptTests/SceneGraph/AndroidManifest.xml +++ b/tests/RenderScriptTests/SceneGraph/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="com.android.testapp"> diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java index a3bf023bd653..301075e52441 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ColladaScene.java @@ -48,14 +48,8 @@ public class ColladaScene { private final int STATE_LAST_FOCUS = 1; boolean mLoadFromSD = false; - TestAppRS mRenderer; SceneLoadedCallback mCallback; - public ColladaScene(String name, TestAppRS renderer) { - modelName = name; - mRenderer = renderer; - } - public ColladaScene(String name, SceneLoadedCallback cb) { modelName = name; mCallback = cb; @@ -104,9 +98,6 @@ public class ColladaScene { protected void onPostExecute(Boolean result) { mActiveScene = sceneSource.getScene(); - if (mRenderer != null) { - mRenderer.prepareToRender(mActiveScene); - } if (mCallback != null) { mCallback.mLoadedScene = mActiveScene; mCallback.run(); diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FileSelector.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FileSelector.java deleted file mode 100644 index 691b433271da..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FileSelector.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2011 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.android.scenegraph; - -import java.io.File; -import java.io.FileFilter; -import java.util.ArrayList; -import java.util.List; - -import android.app.ListActivity; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.ListView; - -/** - * A list view where the last item the user clicked is placed in - * the "activated" state, causing its background to highlight. - */ -public class FileSelector extends ListActivity { - - File[] mCurrentSubList; - File mCurrentFile; - - class DAEFilter implements FileFilter { - public boolean accept(File file) { - if (file.isDirectory()) { - return true; - } - return file.getName().endsWith(".dae"); - } - } - - private void populateList(File file) { - - mCurrentFile = file; - setTitle(mCurrentFile.getAbsolutePath() + "/*.dae"); - List names = new ArrayList(); - names.add(".."); - - mCurrentSubList = mCurrentFile.listFiles(new DAEFilter()); - - if (mCurrentSubList != null) { - for (int i = 0; i < mCurrentSubList.length; i ++) { - String fileName = mCurrentSubList[i].getName(); - if (mCurrentSubList[i].isDirectory()) { - fileName = "/" + fileName; - } - names.add(fileName); - } - } - - // Use the built-in layout for showing a list item with a single - // line of text whose background is changes when activated. - setListAdapter(new ArrayAdapter(this, - android.R.layout.simple_list_item_activated_1, names)); - getListView().setTextFilterEnabled(true); - - // Tell the list view to show one checked/activated item at a time. - getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - populateList(new File("/sdcard/")); - } - - @Override - protected void onListItemClick(ListView l, View v, int position, long id) { - if (position == 0) { - File parent = mCurrentFile.getParentFile(); - if (parent == null) { - return; - } - populateList(parent); - return; - } - - // the first thing in list is parent directory - File selectedFile = mCurrentSubList[position - 1]; - if (selectedFile.isDirectory()) { - populateList(selectedFile); - return; - } - - Intent resultIntent = new Intent(); - resultIntent.setData(Uri.fromFile(selectedFile)); - setResult(RESULT_OK, resultIntent); - finish(); - } - -} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java index 0c6312f93ed2..52523b5f3c6f 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java @@ -68,7 +68,7 @@ public class FragmentShader extends Shader { return this; } - FragmentShader create() { + public FragmentShader create() { if (mShader.mPerShaderConstants != null) { mBuilder.addConstant(mShader.mPerShaderConstants); } @@ -90,6 +90,10 @@ public class FragmentShader extends Shader { FragmentShader() { } + public ProgramFragment getProgram() { + return mProgram; + } + public void updateTextures(RenderScriptGL rs, Resources res) { int shaderTextureStart = mTextureTypes.size(); for (int i = 0; i < mShaderTextureNames.size(); i ++) { diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FullscreenBlur.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FullscreenBlur.java deleted file mode 100644 index 17ee621d1e79..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FullscreenBlur.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) 2011 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.android.scenegraph; - -import java.util.ArrayList; - -import com.android.scenegraph.Float4Param; -import com.android.scenegraph.SceneManager; -import com.android.scenegraph.Texture2D; -import com.android.scenegraph.TextureParam; - -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.AsyncTask; -import android.renderscript.*; -import android.renderscript.Allocation.MipmapControl; -import android.renderscript.Element.Builder; -import android.renderscript.Font.Style; -import android.renderscript.Program.TextureType; -import android.renderscript.ProgramStore.DepthFunc; -import android.util.Log; - -class FullscreenBlur { - - static Allocation sRenderTargetBlur0Color; - static Allocation sRenderTargetBlur0Depth; - static Allocation sRenderTargetBlur1Color; - static Allocation sRenderTargetBlur1Depth; - static Allocation sRenderTargetBlur2Color; - static Allocation sRenderTargetBlur2Depth; - - static FragmentShader mPF_BlurH; - static FragmentShader mPF_BlurV; - static FragmentShader mPF_SelectColor; - static FragmentShader mPF_Texture; - static VertexShader mPV_Paint; - static VertexShader mPV_Blur; - - // This is only used when full screen blur is enabled - // Basically, it's the offscreen render targets - static void createRenderTargets(RenderScriptGL rs, int w, int h) { - Type.Builder b = new Type.Builder(rs, Element.RGBA_8888(rs)); - Type renderType = b.setX(w/8).setY(h/8).create(); - int usage = Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_GRAPHICS_RENDER_TARGET; - sRenderTargetBlur0Color = Allocation.createTyped(rs, renderType, usage); - sRenderTargetBlur1Color = Allocation.createTyped(rs, renderType, usage); - sRenderTargetBlur2Color = Allocation.createTyped(rs, renderType, usage); - - b = new Type.Builder(rs, Element.createPixel(rs, Element.DataType.UNSIGNED_16, - Element.DataKind.PIXEL_DEPTH)); - renderType = b.setX(w/8).setY(h/8).create(); - usage = Allocation.USAGE_GRAPHICS_RENDER_TARGET; - sRenderTargetBlur0Depth = Allocation.createTyped(rs, renderType, usage); - sRenderTargetBlur1Depth = Allocation.createTyped(rs, renderType, usage); - sRenderTargetBlur2Depth = Allocation.createTyped(rs, renderType, usage); - } - - static void addOffsets(Renderable quad, float advance) { - quad.appendSourceParams(new Float4Param("blurOffset0", - advance * 2.5f)); - quad.appendSourceParams(new Float4Param("blurOffset1", - advance * 0.5f)); - quad.appendSourceParams(new Float4Param("blurOffset2", advance * 1.5f)); - quad.appendSourceParams(new Float4Param("blurOffset3", advance * 3.5f)); - } - - static RenderPass addPass(Scene scene, 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)); - scene.appendRenderPass(pass); - return pass; - } - - static void addBlurPasses(Scene scene, RenderScriptGL rs) { - SceneManager sceneManager = SceneManager.getInstance(); - ArrayList allDraw = scene.getRenderables(); - int numDraw = allDraw.size(); - - ProgramRaster cullNone = ProgramRaster.CULL_NONE(rs); - ProgramStore blendAdd = SceneManager.BLEND_ADD_DEPTH_NONE(rs); - ProgramStore blendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(rs); - - RenderState drawTex = new RenderState(mPV_Blur, mPF_Texture, blendAdd, cullNone); - RenderState selectCol = new RenderState(mPV_Blur, mPF_SelectColor, blendNone, cullNone); - RenderState hBlur = new RenderState(mPV_Blur, mPF_BlurH, blendNone, cullNone); - RenderState vBlur = new RenderState(mPV_Blur, mPF_BlurV, blendNone, cullNone); - - // Renders the scene off screen - RenderPass blurSourcePass = addPass(scene, - sRenderTargetBlur0Color, - sRenderTargetBlur0Depth); - blurSourcePass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 1.0f)); - blurSourcePass.setShouldClearColor(true); - blurSourcePass.setClearDepth(1.0f); - blurSourcePass.setShouldClearDepth(true); - for (int i = 0; i < numDraw; i ++) { - blurSourcePass.appendRenderable((Renderable)allDraw.get(i)); - } - - // Pass for selecting bright colors - RenderPass selectColorPass = addPass(scene, - sRenderTargetBlur2Color, - sRenderTargetBlur2Depth); - Renderable quad = sceneManager.getRenderableQuad("ScreenAlignedQuadS", selectCol); - quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur0Color))); - selectColorPass.appendRenderable(quad); - - // Horizontal blur - RenderPass horizontalBlurPass = addPass(scene, - sRenderTargetBlur1Color, - sRenderTargetBlur1Depth); - quad = sceneManager.getRenderableQuad("ScreenAlignedQuadH", hBlur); - quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur2Color))); - addOffsets(quad, 1.0f / (float)sRenderTargetBlur0Color.getType().getX()); - horizontalBlurPass.appendRenderable(quad); - - // Vertical Blur - RenderPass verticalBlurPass = addPass(scene, - sRenderTargetBlur2Color, - sRenderTargetBlur2Depth); - quad = sceneManager.getRenderableQuad("ScreenAlignedQuadV", vBlur); - quad.appendSourceParams(new TextureParam("tex0", 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) { - 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))); - compositePass.appendRenderable(quad); - } - - static private FragmentShader getShader(Resources res, RenderScriptGL rs, - int resID, Type constants) { - FragmentShader.Builder fb = new FragmentShader.Builder(rs); - fb.setShader(res, resID); - fb.addTexture(TextureType.TEXTURE_2D, "color"); - if (constants != null) { - fb.setObjectConst(constants); - } - FragmentShader prog = fb.create(); - prog.mProgram.bindSampler(Sampler.CLAMP_LINEAR(rs), 0); - return prog; - } - - static void initShaders(Resources res, RenderScriptGL rs) { - ScriptField_FBlurOffsets_s blurConst = new ScriptField_FBlurOffsets_s(rs, 1); - VertexShader.Builder vb = new VertexShader.Builder(rs); - vb.addInput(ScriptField_VertexShaderInputs_s.createElement(rs)); - vb.setShader(res, R.raw.blur_vertex); - mPV_Blur = vb.create(); - - mPF_Texture = getShader(res, rs, R.raw.texture, null); - mPF_Texture.mProgram.bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(rs), 0); - mPF_BlurH = getShader(res, rs, R.raw.blur_h, blurConst.getAllocation().getType()); - mPF_BlurV = getShader(res, rs, R.raw.blur_v, blurConst.getAllocation().getType()); - mPF_SelectColor = getShader(res, rs, R.raw.select_color, null); - } - -} - - - - - diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java index cf4a8464b559..8b2b8db10f95 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java @@ -151,7 +151,7 @@ public class Renderable extends RenderableBase { mRsFieldItem.pf_textures[slot] = a; } - void setVisible(RenderScriptGL rs, boolean vis) { + public void setVisible(RenderScriptGL rs, boolean vis) { getRsField(rs, null); mRsFieldItem.cullType = vis ? 0 : 2; mRsField.set(mRsFieldItem, 0, true); diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java index 2a88b6b67dd0..8ddeda79ed94 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java @@ -149,8 +149,8 @@ public class SceneManager extends SceneGraphBase { } public static class SceneLoadedCallback implements Runnable { - Scene mLoadedScene; - String mName; + public Scene mLoadedScene; + public String mName; public void run() { } } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestApp.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestApp.java deleted file mode 100644 index ccdd2aa40ef6..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestApp.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2011 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.android.scenegraph; - -import android.renderscript.RSSurfaceView; -import android.renderscript.RenderScript; - -import android.app.Activity; -import android.content.res.Configuration; -import android.content.Intent; -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.view.MenuInflater; -import android.view.Window; -import android.net.Uri; - -import java.lang.Runtime; - -public class TestApp extends Activity { - - private TestAppView mView; - - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - - // Create our Preview view and set it as the content of our - // Activity - mView = new TestAppView(this); - setContentView(mView); - } - - @Override - protected void onResume() { - // 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() { - // Ideally a game should implement onResume() and onPause() - // to take appropriate action when the activity looses focus - super.onPause(); - mView.pause(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.loader_menu, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle item selection - switch (item.getItemId()) { - case R.id.load_model: - loadModel(); - return true; - case R.id.use_blur: - mView.mRender.toggleBlur(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - private static final int FIND_DAE_MODEL = 10; - public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (resultCode == RESULT_OK) { - if (requestCode == FIND_DAE_MODEL) { - Uri selectedImageUri = data.getData(); - Log.e("Selected Path: ", selectedImageUri.getPath()); - mView.mRender.loadModel(selectedImageUri.getPath()); - } - } - } - - public void loadModel() { - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_PICK); - intent.setClassName("com.android.scenegraph", - "com.android.scenegraph.FileSelector"); - startActivityForResult(intent, FIND_DAE_MODEL); - } - -} - diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppLoadingScreen.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppLoadingScreen.java deleted file mode 100644 index 60bdbb97f044..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppLoadingScreen.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2012 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.android.scenegraph; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Vector; - -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.AsyncTask; -import android.renderscript.*; -import android.renderscript.Allocation.MipmapControl; -import android.renderscript.Element.Builder; -import android.renderscript.Font.Style; -import android.renderscript.Program.TextureType; -import android.renderscript.ProgramStore.DepthFunc; -import android.util.Log; - -import com.android.scenegraph.SceneManager.SceneLoadedCallback; - -// This is where the scenegraph and the rendered objects are initialized and used -public class TestAppLoadingScreen { - - private static String TAG = "TestAppLoadingScreen"; - - int mWidth; - int mHeight; - - private Resources mRes; - private RenderScriptGL mRS; - private ScriptC_scenegraph mScript; - - public TestAppLoadingScreen(RenderScriptGL rs, Resources res) { - mRS = rs; - mRes = res; - // Shows the loading screen with some text - renderLoading(); - // Adds a little 3D bugdroid model to the laoding screen asynchronously. - new LoadingScreenLoaderTask().execute(); - } - - public void showLoadingScreen(boolean show) { - mScript.set_gInitialized(!show); - } - - // The loading screen has some elements that shouldn't be loaded on the UI thread - private class LoadingScreenLoaderTask extends AsyncTask { - Allocation robotTex; - Mesh robotMesh; - protected Boolean doInBackground(String... names) { - long start = System.currentTimeMillis(); - robotTex = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot, - MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE, - Allocation.USAGE_GRAPHICS_TEXTURE); - - FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot); - FileA3D.IndexEntry entry = model.getIndexEntry(0); - if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) { - robotMesh = entry.getMesh(); - } - - mScript.set_gPFSBackground(ProgramStore.BLEND_NONE_DEPTH_TEST(mRS)); - - ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS); - b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, - ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); - ProgramFragment pfDefault = b.create(); - pfDefault.bindSampler(Sampler.CLAMP_LINEAR(mRS), 0); - mScript.set_gPFBackground(pfDefault); - - ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS); - ProgramVertexFixedFunction pvDefault = pvb.create(); - ProgramVertexFixedFunction.Constants va = new ProgramVertexFixedFunction.Constants(mRS); - ((ProgramVertexFixedFunction)pvDefault).bindConstants(va); - mScript.set_gPVBackground(pvDefault); - - long end = System.currentTimeMillis(); - Log.v("TIMER", "Loading load time: " + (end - start)); - return new Boolean(true); - } - - protected void onPostExecute(Boolean result) { - mScript.set_gRobotTex(robotTex); - mScript.set_gRobotMesh(robotMesh); - } - } - - // Creates a simple script to show a loding screen until everything is initialized - // Could also be used to do some custom renderscript work before handing things over - // to the scenegraph - void renderLoading() { - mScript = new ScriptC_scenegraph(mRS, mRes, R.raw.scenegraph); - mRS.bindRootScript(mScript); - } - - - public void setRenderLoop(ScriptC renderLoop) { - mScript.set_gRenderLoop(renderLoop); - Allocation dummyAlloc = Allocation.createSized(mRS, Element.I32(mRS), 1); - mScript.set_gDummyAlloc(dummyAlloc); - } -} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java deleted file mode 100644 index 087b776221b9..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright (C) 2011-2012 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.android.scenegraph; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Vector; - -import com.android.scenegraph.SceneManager; -import com.android.scenegraph.SceneManager.SceneLoadedCallback; -import com.android.scenegraph.VertexShader; -import com.android.scenegraph.VertexShader.Builder; - -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.AsyncTask; -import android.renderscript.*; -import android.renderscript.Program.TextureType; -import android.util.Log; - -// This is where the scenegraph and the rendered objects are initialized and used -public class TestAppRS { - - private static String modelName = "orientation_test.dae"; - private static String TAG = "TestAppRS"; - private static String mFilePath = ""; - - int mWidth; - int mHeight; - - boolean mUseBlur; - - TestAppLoadingScreen mLoadingScreen; - - // Used to asynchronously load scene elements like meshes and transform hierarchies - SceneLoadedCallback mLoadedCallback = new SceneLoadedCallback() { - public void run() { - prepareToRender(mLoadedScene); - } - }; - - // Top level class that initializes all the elements needed to use the scene graph - SceneManager mSceneManager; - - // Used to move the camera around in the 3D world - TouchHandler mTouchHandler; - - private Resources mRes; - private RenderScriptGL mRS; - - ScriptField_FShaderParams_s mFsConst; - ScriptField_FShaderLightParams_s mFsConst2; - ScriptField_VShaderParams_s mVsConst; - - // Shaders - private FragmentShader mPaintF; - private FragmentShader mLightsF; - private FragmentShader mAluminumF; - private FragmentShader mPlasticF; - private FragmentShader mDiffuseF; - private FragmentShader mTextureF; - private VertexShader mPaintV; - - private Allocation mDefaultCube; - private TextureCube mEnvCube; - private TextureCube mDiffCube; - - Scene mActiveScene; - - public TestAppRS() { - mUseBlur = false; - } - - // This is a part of the test app, it's used to tests multiple render passes and is toggled - // on and off in the menu, off by default - void toggleBlur() { - mUseBlur = !mUseBlur; - - mActiveScene.clearRenderPasses(); - initRenderPasses(); - mActiveScene.initRenderPassRS(mRS, mSceneManager); - - // This is just a hardcoded object in the scene that gets turned on and off for the demo - // to make things look a bit better. This could be deleted in the cleanup - Renderable plane = (Renderable)mActiveScene.getRenderableByName("pPlaneShape1"); - if (plane != null) { - plane.setVisible(mRS, !mUseBlur); - } - } - - public void init(RenderScriptGL rs, Resources res, int width, int height) { - mRS = rs; - mRes = res; - mWidth = width; - mHeight = height; - - mTouchHandler = new TouchHandler(); - - mSceneManager = SceneManager.getInstance(); - // Initializes all the RS specific scenegraph elements - mSceneManager.initRS(mRS, mRes, mWidth, mHeight); - - mLoadingScreen = new TestAppLoadingScreen(mRS, mRes); - - // Initi renderscript stuff specific to the app. This will need to be abstracted out later. - initRS(); - - // Load a scene to render - mSceneManager.loadModel(mFilePath + modelName, mLoadedCallback); - } - - // When a new model file is selected from the UI, this function gets called to init everything - void loadModel(String path) { - //String shortName = path.substring(path.lastIndexOf('/') + 1); - //shortName = shortName.substring(0, shortName.lastIndexOf('.')); - mLoadingScreen.showLoadingScreen(true); - mActiveScene.destroyRS(mSceneManager); - mSceneManager.loadModel(path, mLoadedCallback); - } - - public void onActionDown(float x, float y) { - mTouchHandler.onActionDown(x, y); - - //mSceneManager.getRenderLoop().invoke_pick((int)x, (int)y); - } - - public void onActionScale(float scale) { - mTouchHandler.onActionScale(scale); - } - - public void onActionMove(float x, float y) { - mTouchHandler.onActionMove(x, y); - } - - FragmentShader createFromResource(int id, boolean addCubemap) { - FragmentShader.Builder fb = new FragmentShader.Builder(mRS); - fb.setShaderConst(mFsConst.getAllocation().getType()); - fb.setShader(mRes, id); - fb.addTexture(TextureType.TEXTURE_2D, "diffuse"); - if (addCubemap) { - fb.addShaderTexture(TextureType.TEXTURE_CUBE, "reflection"); - } - FragmentShader pf = fb.create(); - pf.mProgram.bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS), 0); - if (addCubemap) { - pf.mProgram.bindSampler(Sampler.CLAMP_LINEAR_MIP_LINEAR(mRS), 1); - } - return pf; - } - - private void initPaintShaders() { - ScriptField_VObjectParams_s objConst = new ScriptField_VObjectParams_s(mRS, 1); - ScriptField_VSParams_s shaderConst = new ScriptField_VSParams_s(mRS, 1); - - VertexShader.Builder vb = new VertexShader.Builder(mRS); - vb.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); - vb.setShader(mRes, R.raw.shader2v); - vb.setObjectConst(objConst.getAllocation().getType()); - vb.setShaderConst(shaderConst.getAllocation().getType()); - mPaintV = vb.create(); - - mFsConst = new ScriptField_FShaderParams_s(mRS, 1); - mFsConst2 = new ScriptField_FShaderLightParams_s(mRS, 1); - - mPaintF = createFromResource(R.raw.paintf, true); - mPaintF.appendSourceParams(new TextureParam("reflection", mEnvCube)); - mAluminumF = createFromResource(R.raw.metal, true); - mAluminumF.appendSourceParams(new TextureParam("reflection", mDiffCube)); - - mPlasticF = createFromResource(R.raw.plastic, false); - mDiffuseF = createFromResource(R.raw.diffuse, false); - mTextureF = createFromResource(R.raw.texture, false); - - FragmentShader.Builder fb = new FragmentShader.Builder(mRS); - fb.setObjectConst(mFsConst2.getAllocation().getType()); - fb.setShader(mRes, R.raw.plastic_lights); - mLightsF = fb.create(); - - FullscreenBlur.initShaders(mRes, mRS); - } - - void initRenderPasses() { - ArrayList allDraw = mActiveScene.getRenderables(); - int numDraw = allDraw.size(); - - if (mUseBlur) { - FullscreenBlur.addBlurPasses(mActiveScene, mRS); - } - - RenderPass mainPass = new RenderPass(); - mainPass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 1.0f)); - mainPass.setShouldClearColor(true); - mainPass.setClearDepth(1.0f); - mainPass.setShouldClearDepth(true); - mainPass.setCamera(mActiveScene.getCameras().get(1)); - for (int i = 0; i < numDraw; i ++) { - mainPass.appendRenderable((Renderable)allDraw.get(i)); - } - mActiveScene.appendRenderPass(mainPass); - - if (mUseBlur) { - FullscreenBlur.addCompositePass(mActiveScene, mRS); - } - } - - private void addShadersToScene() { - mActiveScene.appendShader(mPaintF); - mActiveScene.appendShader(mLightsF); - mActiveScene.appendShader(mAluminumF); - mActiveScene.appendShader(mPlasticF); - mActiveScene.appendShader(mDiffuseF); - mActiveScene.appendShader(mTextureF); - mActiveScene.appendShader(mPaintV); - } - - public void prepareToRender(Scene s) { - mSceneManager.setActiveScene(s); - mActiveScene = s; - addShadersToScene(); - RenderState plastic = new RenderState(mPaintV, mPlasticF, null, null); - RenderState diffuse = new RenderState(mPaintV, mDiffuseF, null, null); - RenderState paint = new RenderState(mPaintV, mPaintF, null, null); - RenderState aluminum = new RenderState(mPaintV, mAluminumF, null, null); - RenderState lights = new RenderState(mPaintV, mLightsF, null, null); - RenderState glassTransp = new RenderState(mPaintV, mPaintF, - ProgramStore.BLEND_ALPHA_DEPTH_TEST(mRS), null); - - initRenderPasses(); - - mActiveScene.assignRenderState(plastic); - - mActiveScene.assignRenderStateToMaterial(diffuse, "lambert2$"); - - mActiveScene.assignRenderStateToMaterial(paint, "^#Paint"); - mActiveScene.assignRenderStateToMaterial(paint, "^#Carbon"); - mActiveScene.assignRenderStateToMaterial(paint, "^#Glass"); - mActiveScene.assignRenderStateToMaterial(paint, "^#MainGlass"); - - mActiveScene.assignRenderStateToMaterial(aluminum, "^#Metal"); - mActiveScene.assignRenderStateToMaterial(aluminum, "^#Brake"); - - mActiveScene.assignRenderStateToMaterial(glassTransp, "^#GlassLight"); - - mActiveScene.assignRenderStateToMaterial(lights, "^#LightBlinn"); - - Renderable plane = (Renderable)mActiveScene.getRenderableByName("pPlaneShape1"); - if (plane != null) { - RenderState texState = new RenderState(mPaintV, mTextureF, null, null); - plane.setRenderState(texState); - plane.setVisible(mRS, !mUseBlur); - } - - mTouchHandler.init(mActiveScene); - - long start = System.currentTimeMillis(); - mActiveScene.initRS(mRS, mRes, mSceneManager); - long end = System.currentTimeMillis(); - Log.v("TIMER", "Scene init time: " + (end - start)); - - mLoadingScreen.showLoadingScreen(false); - } - - private void initRS() { - - FullscreenBlur.createRenderTargets(mRS, mWidth, mHeight); - // Reflection maps from SD card - mEnvCube = new TextureCube("sdcard/scenegraph/", "cube_env.png"); - mDiffCube = new TextureCube("sdcard/scenegraph/", "cube_spec.png"); - initPaintShaders(); - - ScriptC_render renderLoop = mSceneManager.getRenderLoop(); - - mLoadingScreen.setRenderLoop(renderLoop); - } -} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppView.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppView.java deleted file mode 100644 index cefa3e651860..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppView.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2011 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.android.scenegraph; - -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; -import android.view.ScaleGestureDetector; - -public class TestAppView extends RSSurfaceView { - - public TestAppView(Context context) { - super(context); - mScaleDetector = new ScaleGestureDetector(context, new ScaleListener()); - } - - private RenderScriptGL mRS; - TestAppRS mRender; - - private ScaleGestureDetector mScaleDetector; - private static final int INVALID_POINTER_ID = -1; - private int mActivePointerId = INVALID_POINTER_ID; - - 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(); - sc.setDepth(16, 24); - mRS = createRenderScriptGL(sc); - mRS.setSurface(holder, w, h); - mRender = new TestAppRS(); - mRender.init(mRS, getResources(), w, h); - } - } - - @Override - protected void onDetachedFromWindow() { - if (mRS != null) { - mRender = null; - mRS = null; - destroyRenderScriptGL(); - } - } - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) - { - // break point at here - // this method doesn't work when 'extends View' include 'extends ScrollView'. - return super.onKeyDown(keyCode, event); - } - - - @Override - public boolean onTouchEvent(MotionEvent ev) { - mScaleDetector.onTouchEvent(ev); - - boolean ret = false; - float x = ev.getX(); - float y = ev.getY(); - - final int action = ev.getAction(); - - switch (action & MotionEvent.ACTION_MASK) { - case MotionEvent.ACTION_DOWN: { - mRender.onActionDown(x, y); - mActivePointerId = ev.getPointerId(0); - ret = true; - break; - } - case MotionEvent.ACTION_MOVE: { - if (!mScaleDetector.isInProgress()) { - mRender.onActionMove(x, y); - } - mRender.onActionDown(x, y); - ret = true; - break; - } - - case MotionEvent.ACTION_UP: { - mActivePointerId = INVALID_POINTER_ID; - break; - } - - case MotionEvent.ACTION_CANCEL: { - mActivePointerId = INVALID_POINTER_ID; - break; - } - - case MotionEvent.ACTION_POINTER_UP: { - final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) - >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; - final int pointerId = ev.getPointerId(pointerIndex); - if (pointerId == mActivePointerId) { - // This was our active pointer going up. Choose a new - // active pointer and adjust accordingly. - final int newPointerIndex = pointerIndex == 0 ? 1 : 0; - x = ev.getX(newPointerIndex); - y = ev.getY(newPointerIndex); - mRender.onActionDown(x, y); - mActivePointerId = ev.getPointerId(newPointerIndex); - } - break; - } - } - - return ret; - } - - private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { - @Override - public boolean onScale(ScaleGestureDetector detector) { - mRender.onActionScale(detector.getScaleFactor()); - return true; - } - } -} - - diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TouchHandler.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TouchHandler.java deleted file mode 100644 index eacc3d0f493d..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TouchHandler.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2011 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.android.scenegraph; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.FileInputStream; -import java.io.BufferedInputStream; -import java.io.Writer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Vector; - -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.AsyncTask; -import android.renderscript.*; -import android.renderscript.Allocation.MipmapControl; -import android.renderscript.Element.Builder; -import android.renderscript.Font.Style; -import android.renderscript.Program.TextureType; -import android.renderscript.ProgramStore.DepthFunc; -import android.util.Log; - -import com.android.scenegraph.SceneManager.SceneLoadedCallback; - -public class TouchHandler { - - private static String TAG = "TouchHandler"; - - public TouchHandler() { - } - - public void init(Scene scene) { - mCameraRotate = (CompoundTransform)scene.getTransformByName("CameraAim"); - mCameraDist = (CompoundTransform)scene.getTransformByName("CameraDist"); - - if (mCameraRotate != null && mCameraDist != null) { - mRotateX = mCameraRotate.mTransformComponents.get(2); - mRotateY = mCameraRotate.mTransformComponents.get(1); - mDist = mCameraDist.mTransformComponents.get(0); - } - } - - - private Resources mRes; - private RenderScriptGL mRS; - - float mLastX; - float mLastY; - - CompoundTransform mCameraRotate; - CompoundTransform mCameraDist; - - CompoundTransform.Component mRotateX; - CompoundTransform.Component mRotateY; - CompoundTransform.Component mDist; - - public void onActionDown(float x, float y) { - mLastX = x; - mLastY = y; - } - - public void onActionScale(float scale) { - if (mCameraDist == null) { - return; - } - mDist.mValue.z *= 1.0f / scale; - mDist.mValue.z = Math.max(20.0f, Math.min(mDist.mValue.z, 100.0f)); - mCameraDist.updateRSData(); - } - - public void onActionMove(float x, float y) { - if (mCameraRotate == null) { - return; - } - - float dx = mLastX - x; - float dy = mLastY - y; - - if (Math.abs(dy) <= 2.0f) { - dy = 0.0f; - } - if (Math.abs(dx) <= 2.0f) { - dx = 0.0f; - } - - mRotateY.mValue.w += dx*0.25; - if (mRotateY.mValue.w > 360) { - mRotateY.mValue.w -= 360; - } - if (mRotateY.mValue.w < 0) { - mRotateY.mValue.w += 360; - } - - mRotateX.mValue.w += dy*0.25; - mRotateX.mValue.w = Math.max(mRotateX.mValue.w, -80.0f); - mRotateX.mValue.w = Math.min(mRotateX.mValue.w, 0.0f); - - mLastX = x; - mLastY = y; - - mCameraRotate.updateRSData(); - } -} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java index 4351f664f40a..2ceed327f86e 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java @@ -59,7 +59,7 @@ public class VertexShader extends Shader { return this; } - VertexShader create() { + public VertexShader create() { if (mShader.mPerShaderConstants != null) { mBuilder.addConstant(mShader.mPerShaderConstants); } @@ -74,6 +74,10 @@ public class VertexShader extends Shader { VertexShader() { } + public ProgramVertex getProgram() { + return mProgram; + } + public ScriptField_VertexShader_s getRSData(RenderScriptGL rs, Resources res) { if (mField != null) { return mField; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/camera.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/camera.rs index 980eb9fdd7d8..50554a0817aa 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/camera.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/camera.rs @@ -17,7 +17,7 @@ #pragma rs java_package_name(com.android.scenegraph) //#define DEBUG_CAMERA -#include "transform_def.rsh" +#include "scenegraph_objects.rsh" void root(const rs_allocation *v_in, rs_allocation *v_out, const float *usrData) { diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs index bca62403c7a5..024e026b69df 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs @@ -16,7 +16,7 @@ #pragma rs java_package_name(com.android.scenegraph) -#include "transform_def.rsh" +#include "scenegraph_objects.rsh" static void getTransformedSphere(SgRenderable *obj) { obj->worldBoundingSphere = obj->boundingSphere; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs index d2f70e670bf7..cd46c144ee19 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs @@ -18,8 +18,7 @@ // The sole purpose of this script is to have various structs exposed // so that java reflected classes are generated -#include "transform_def.rsh" -#include "testApp.rsh" +#include "scenegraph_objects.rsh" SgTransform *exportPtr; SgRenderState *sExport; SgRenderable *drExport; @@ -29,11 +28,3 @@ SgLight *exportPtrLight; SgShaderParam *spExport; SgVertexShader *pvExport; SgFragmentShader *pfExport; - -FBlurOffsets *blurExport; -VertexShaderInputs *iExport; -VShaderParams *vConst; -FShaderParams *fConst; -FShaderLightParams *fConts2; -VSParams *vConst2; -VObjectParams *vConst3; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs index 4cd412de96de..f5816ed2796b 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs @@ -16,7 +16,7 @@ #pragma rs java_package_name(com.android.scenegraph) -#include "transform_def.rsh" +#include "scenegraph_objects.rsh" //#define DEBUG_PARAMS diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/light.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/light.rs index ae489afc3812..e11979f27ff8 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/light.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/light.rs @@ -17,7 +17,7 @@ #pragma rs java_package_name(com.android.scenegraph) //#define DEBUG_LIGHT -#include "transform_def.rsh" +#include "scenegraph_objects.rsh" void root(const rs_allocation *v_in, rs_allocation *v_out) { diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs index 92ac6bbabf8d..0d524a663150 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs @@ -16,7 +16,7 @@ #pragma rs java_package_name(com.android.scenegraph) -#include "transform_def.rsh" +#include "scenegraph_objects.rsh" //#define DEBUG_PARAMS diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh index 01e6ae54c504..16a877d7a4b1 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh @@ -16,7 +16,7 @@ #pragma rs java_package_name(com.android.scenegraph) -#include "transform_def.rsh" +#include "scenegraph_objects.rsh" //#define DEBUG_PARAMS diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs index afe5fa64db7d..0d6c795aa671 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs @@ -17,7 +17,7 @@ #pragma rs java_package_name(com.android.scenegraph) #include "rs_graphics.rsh" -#include "transform_def.rsh" +#include "scenegraph_objects.rsh" rs_script gTransformScript; rs_script gCameraScript; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph.rs deleted file mode 100644 index 421105b29f58..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph.rs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2011 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. - -#pragma version(1) - -#pragma rs java_package_name(com.android.scenegraph) - -#include "rs_graphics.rsh" -#include "transform_def.rsh" - -rs_program_vertex gPVBackground; -rs_program_fragment gPFBackground; - -rs_allocation gRobotTex; -rs_mesh gRobotMesh; - -rs_program_store gPFSBackground; - -rs_allocation gDummyAlloc; -rs_script gRenderLoop; - -bool gInitialized = false; - -float gRotate; - -void init() { - gRotate = 0.0f; -} - -static int pos = 50; -static float gRotateY = 120.0f; -static float3 gLookAt = 0; -static float gZoom = 50.0f; -static void displayLoading() { - if (rsIsObject(gRobotTex) && rsIsObject(gRobotMesh)) { - rsgBindProgramVertex(gPVBackground); - rs_matrix4x4 proj; - float aspect = (float)rsgGetWidth() / (float)rsgGetHeight(); - rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f); - rsgProgramVertexLoadProjectionMatrix(&proj); - - rsgBindProgramFragment(gPFBackground); - rsgBindProgramStore(gPFSBackground); - rsgBindTexture(gPFBackground, 0, gRobotTex); - - rs_matrix4x4 matrix; - rsMatrixLoadIdentity(&matrix); - // Position our models on the screen - gRotateY += rsGetDt()*100; - rsMatrixTranslate(&matrix, 0, 0, -gZoom); - rsMatrixRotate(&matrix, 20.0f, 1.0f, 0.0f, 0.0f); - rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f); - rsMatrixScale(&matrix, 0.2f, 0.2f, 0.2f); - rsgProgramVertexLoadModelMatrix(&matrix); - rsgDrawMesh(gRobotMesh); - } - - uint width = rsgGetWidth(); - uint height = rsgGetHeight(); - int left = 0, right = 0, top = 0, bottom = 0; - const char* text = "Initializing..."; - rsgMeasureText(text, &left, &right, &top, &bottom); - int centeredPos = width / 2 - (right - left) / 2; - rsgDrawText(text, centeredPos, height / 2 + height / 10); -} - -int root(void) { - rs_allocation nullAlloc; - if (!gInitialized) { - rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f); - rsgClearDepth(1.0f); - displayLoading(); - return 30; - } - - rsForEach(gRenderLoop, gDummyAlloc, nullAlloc); - - return 10; -} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh new file mode 100644 index 000000000000..e3df60e0eaec --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh @@ -0,0 +1,250 @@ +// Copyright (C) 2011-2012 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. + +#pragma version(1) + +#pragma rs java_package_name(com.android.scenegraph) + +#ifndef _TRANSFORM_DEF_ +#define _TRANSFORM_DEF_ + +#include "rs_graphics.rsh" + +#define TRANSFORM_NONE 0 +#define TRANSFORM_TRANSLATE 1 +#define TRANSFORM_ROTATE 2 +#define TRANSFORM_SCALE 3 + +#define CULL_FRUSTUM 0 +#define CULL_ALWAYS 2 + +#define LIGHT_POINT 0 +#define LIGHT_DIRECTIONAL 1 + +#define SHADER_PARAM_FLOAT4_DATA 0 +#define SHADER_PARAM_FLOAT4_CAMERA_POS 1 +#define SHADER_PARAM_FLOAT4_CAMERA_DIR 2 +#define SHADER_PARAM_FLOAT4_LIGHT_COLOR 3 +#define SHADER_PARAM_FLOAT4_LIGHT_POS 4 +#define SHADER_PARAM_FLOAT4_LIGHT_DIR 5 + +#define SHADER_PARAM_TRANSFORM_DATA 100 +#define SHADER_PARAM_TRANSFORM_VIEW 101 +#define SHADER_PARAM_TRANSFORM_PROJ 102 +#define SHADER_PARAM_TRANSFORM_VIEW_PROJ 103 +#define SHADER_PARAM_TRANSFORM_MODEL 104 +#define SHADER_PARAM_TRANSFORM_MODEL_VIEW 105 +#define SHADER_PARAM_TRANSFORM_MODEL_VIEW_PROJ 106 + +#define SHADER_PARAM_TEXTURE 200 + +typedef struct __attribute__((packed, aligned(4))) SgTransform { + rs_matrix4x4 globalMat; + rs_matrix4x4 localMat; + + float4 transforms[16]; + int transformTypes[16]; + rs_allocation transformNames[16]; + + int isDirty; + + rs_allocation children; + + rs_allocation name; +} SgTransform; + +typedef struct VertexShader_s { + rs_program_vertex program; + // Buffer with vertex constant data + rs_allocation shaderConst; + // ShaderParam's that populate data + rs_allocation shaderConstParams; + // location of the per object constants on the buffer + int objectConstIndex; +} SgVertexShader; + +typedef struct FragmentShader_s { + rs_program_fragment program; + // Buffer with vertex constant data + rs_allocation shaderConst; + // ShaderParam's that populate data + rs_allocation shaderConstParams; + // location of the per object constants on the buffer + int objectConstIndex; +} SgFragmentShader; + +typedef struct RenderState_s { + rs_allocation pv; // VertexShader struct + rs_allocation pf; // FragmentShader struct + rs_program_store ps; + rs_program_raster pr; +} SgRenderState; + +typedef struct Renderable_s { + rs_allocation render_state; + // Buffer with vertex constant data + rs_allocation pv_const; + // ShaderParam's that populate data + rs_allocation pv_constParams; + // Buffer with fragment constant data + rs_allocation pf_const; + // ShaderParam's that populate data + rs_allocation pf_constParams; + rs_allocation pf_textures[8]; + int pf_num_textures; + rs_mesh mesh; + int meshIndex; + rs_allocation transformMatrix; + rs_allocation name; + float4 boundingSphere; + float4 worldBoundingSphere; + int bVolInitialized; + int cullType; // specifies whether to frustum cull + int isVisible; +} SgRenderable; + +typedef struct RenderPass_s { + rs_allocation color_target; + rs_allocation depth_target; + rs_allocation camera; + rs_allocation objects; + + float4 clear_color; + float clear_depth; + bool should_clear_color; + bool should_clear_depth; +} SgRenderPass; + +typedef struct __attribute__((packed, aligned(4))) Camera_s { + rs_matrix4x4 proj; + rs_matrix4x4 view; + rs_matrix4x4 viewProj; + float4 position; + float near; + float far; + float horizontalFOV; + float aspect; + rs_allocation name; + rs_allocation transformMatrix; + float4 frustumPlanes[6]; +} SgCamera; + +typedef struct __attribute__((packed, aligned(4))) Light_s { + float4 position; + float4 color; + float intensity; + int type; + rs_allocation name; + rs_allocation transformMatrix; +} SgLight; + +// This represents a shader parameter that knows for to update itself +typedef struct ShaderParam_s { + uint32_t type; + uint32_t bufferOffset; + + float4 float_value; + // Use one param type to handle all vector types for now + uint32_t float_vecSize; + + rs_allocation camera; + rs_allocation light; + rs_allocation transform; + rs_allocation texture; +} SgShaderParam; + +static void printName(rs_allocation name) { + rsDebug("Object Name: ", 0); + if (!rsIsObject(name)) { + rsDebug("no name", 0); + return; + } + + rsDebug((const char*)rsGetElementAt(name, 0), 0); +} + +static void printCameraInfo(const SgCamera *cam) { + rsDebug("***** Camera information. ptr:", cam); + printName(cam->name); + const SgTransform *camTransform = (const SgTransform *)rsGetElementAt(cam->transformMatrix, 0); + rsDebug("Transform name:", camTransform); + printName(camTransform->name); + + rsDebug("Aspect: ", cam->aspect); + rsDebug("Near: ", cam->near); + rsDebug("Far: ", cam->far); + rsDebug("Fov: ", cam->horizontalFOV); + rsDebug("Position: ", cam->position); + rsDebug("Proj: ", &cam->proj); + rsDebug("View: ", &cam->view); +} + +static void printLightInfo(const SgLight *light) { + rsDebug("***** Light information. ptr:", light); + printName(light->name); + const SgTransform *lTransform = (const SgTransform *)rsGetElementAt(light->transformMatrix, 0); + rsDebug("Transform name:", lTransform); + printName(lTransform->name); + + rsDebug("Position: ", light->position); + rsDebug("Color : ", light->color); + rsDebug("Intensity: ", light->intensity); + rsDebug("Type: ", light->type); +} + +static void getCameraRay(const SgCamera *cam, int screenX, int screenY, float3 *pnt, float3 *vec) { + rsDebug("=================================", screenX); + rsDebug("Point X", screenX); + rsDebug("Point Y", screenY); + + rs_matrix4x4 mvpInv; + rsMatrixLoad(&mvpInv, &cam->viewProj); + rsMatrixInverse(&mvpInv); + + float width = (float)rsgGetWidth(); + float height = (float)rsgGetHeight(); + + float4 pos = {(float)screenX, height - (float)screenY, 0.0f, 1.0f}; + + pos.x /= width; + pos.y /= height; + + rsDebug("Pre Norm X", pos.x); + rsDebug("Pre Norm Y", pos.y); + + pos.xy = pos.xy * 2.0f - 1.0f; + + rsDebug("Norm X", pos.x); + rsDebug("Norm Y", pos.y); + + pos = rsMatrixMultiply(&mvpInv, pos); + float oneOverW = 1.0f / pos.w; + pos.xyz *= oneOverW; + + rsDebug("World X", pos.x); + rsDebug("World Y", pos.y); + rsDebug("World Z", pos.z); + + rsDebug("Cam X", cam->position.x); + rsDebug("Cam Y", cam->position.y); + rsDebug("Cam Z", cam->position.z); + + *vec = normalize(pos.xyz - cam->position.xyz); + rsDebug("Vec X", vec->x); + rsDebug("Vec Y", vec->y); + rsDebug("Vec Z", vec->z); + *pnt = cam->position.xyz; +} + +#endif // _TRANSFORM_DEF_ diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh deleted file mode 100644 index 2b166528c823..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2012 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. - -#pragma version(1) - -#pragma rs java_package_name(com.android.scenegraph) - -// Helpers -typedef struct VShaderParams_s { - rs_matrix4x4 model; - rs_matrix4x4 viewProj; -} VShaderParams; - -typedef struct VSParams_s { - rs_matrix4x4 viewProj; -} VSParams; - -typedef struct VObjectParams_s { - rs_matrix4x4 model; -} VObjectParams; - -typedef struct FShaderParams_s { - float4 cameraPos; -} FShaderParams; - -typedef struct FShaderLightParams_s { - float4 lightPos_0; - float4 lightColor_0; - float4 lightPos_1; - float4 lightColor_1; - float4 cameraPos; - float4 diffuse; -} FShaderLightParams; - -typedef struct FBlurOffsets_s { - float blurOffset0; - float blurOffset1; - float blurOffset2; - float blurOffset3; -} FBlurOffsets; - -typedef struct VertexShaderInputs_s { - float4 position; - float3 normal; - float2 texture0; -} VertexShaderInputs; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform.rs index 6bc5317bf9e3..ce5e99913713 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform.rs @@ -18,7 +18,7 @@ //#define DEBUG_TRANSFORMS -#include "transform_def.rsh" +#include "scenegraph_objects.rsh" rs_script gTransformScript; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh deleted file mode 100644 index e3df60e0eaec..000000000000 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh +++ /dev/null @@ -1,250 +0,0 @@ -// Copyright (C) 2011-2012 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. - -#pragma version(1) - -#pragma rs java_package_name(com.android.scenegraph) - -#ifndef _TRANSFORM_DEF_ -#define _TRANSFORM_DEF_ - -#include "rs_graphics.rsh" - -#define TRANSFORM_NONE 0 -#define TRANSFORM_TRANSLATE 1 -#define TRANSFORM_ROTATE 2 -#define TRANSFORM_SCALE 3 - -#define CULL_FRUSTUM 0 -#define CULL_ALWAYS 2 - -#define LIGHT_POINT 0 -#define LIGHT_DIRECTIONAL 1 - -#define SHADER_PARAM_FLOAT4_DATA 0 -#define SHADER_PARAM_FLOAT4_CAMERA_POS 1 -#define SHADER_PARAM_FLOAT4_CAMERA_DIR 2 -#define SHADER_PARAM_FLOAT4_LIGHT_COLOR 3 -#define SHADER_PARAM_FLOAT4_LIGHT_POS 4 -#define SHADER_PARAM_FLOAT4_LIGHT_DIR 5 - -#define SHADER_PARAM_TRANSFORM_DATA 100 -#define SHADER_PARAM_TRANSFORM_VIEW 101 -#define SHADER_PARAM_TRANSFORM_PROJ 102 -#define SHADER_PARAM_TRANSFORM_VIEW_PROJ 103 -#define SHADER_PARAM_TRANSFORM_MODEL 104 -#define SHADER_PARAM_TRANSFORM_MODEL_VIEW 105 -#define SHADER_PARAM_TRANSFORM_MODEL_VIEW_PROJ 106 - -#define SHADER_PARAM_TEXTURE 200 - -typedef struct __attribute__((packed, aligned(4))) SgTransform { - rs_matrix4x4 globalMat; - rs_matrix4x4 localMat; - - float4 transforms[16]; - int transformTypes[16]; - rs_allocation transformNames[16]; - - int isDirty; - - rs_allocation children; - - rs_allocation name; -} SgTransform; - -typedef struct VertexShader_s { - rs_program_vertex program; - // Buffer with vertex constant data - rs_allocation shaderConst; - // ShaderParam's that populate data - rs_allocation shaderConstParams; - // location of the per object constants on the buffer - int objectConstIndex; -} SgVertexShader; - -typedef struct FragmentShader_s { - rs_program_fragment program; - // Buffer with vertex constant data - rs_allocation shaderConst; - // ShaderParam's that populate data - rs_allocation shaderConstParams; - // location of the per object constants on the buffer - int objectConstIndex; -} SgFragmentShader; - -typedef struct RenderState_s { - rs_allocation pv; // VertexShader struct - rs_allocation pf; // FragmentShader struct - rs_program_store ps; - rs_program_raster pr; -} SgRenderState; - -typedef struct Renderable_s { - rs_allocation render_state; - // Buffer with vertex constant data - rs_allocation pv_const; - // ShaderParam's that populate data - rs_allocation pv_constParams; - // Buffer with fragment constant data - rs_allocation pf_const; - // ShaderParam's that populate data - rs_allocation pf_constParams; - rs_allocation pf_textures[8]; - int pf_num_textures; - rs_mesh mesh; - int meshIndex; - rs_allocation transformMatrix; - rs_allocation name; - float4 boundingSphere; - float4 worldBoundingSphere; - int bVolInitialized; - int cullType; // specifies whether to frustum cull - int isVisible; -} SgRenderable; - -typedef struct RenderPass_s { - rs_allocation color_target; - rs_allocation depth_target; - rs_allocation camera; - rs_allocation objects; - - float4 clear_color; - float clear_depth; - bool should_clear_color; - bool should_clear_depth; -} SgRenderPass; - -typedef struct __attribute__((packed, aligned(4))) Camera_s { - rs_matrix4x4 proj; - rs_matrix4x4 view; - rs_matrix4x4 viewProj; - float4 position; - float near; - float far; - float horizontalFOV; - float aspect; - rs_allocation name; - rs_allocation transformMatrix; - float4 frustumPlanes[6]; -} SgCamera; - -typedef struct __attribute__((packed, aligned(4))) Light_s { - float4 position; - float4 color; - float intensity; - int type; - rs_allocation name; - rs_allocation transformMatrix; -} SgLight; - -// This represents a shader parameter that knows for to update itself -typedef struct ShaderParam_s { - uint32_t type; - uint32_t bufferOffset; - - float4 float_value; - // Use one param type to handle all vector types for now - uint32_t float_vecSize; - - rs_allocation camera; - rs_allocation light; - rs_allocation transform; - rs_allocation texture; -} SgShaderParam; - -static void printName(rs_allocation name) { - rsDebug("Object Name: ", 0); - if (!rsIsObject(name)) { - rsDebug("no name", 0); - return; - } - - rsDebug((const char*)rsGetElementAt(name, 0), 0); -} - -static void printCameraInfo(const SgCamera *cam) { - rsDebug("***** Camera information. ptr:", cam); - printName(cam->name); - const SgTransform *camTransform = (const SgTransform *)rsGetElementAt(cam->transformMatrix, 0); - rsDebug("Transform name:", camTransform); - printName(camTransform->name); - - rsDebug("Aspect: ", cam->aspect); - rsDebug("Near: ", cam->near); - rsDebug("Far: ", cam->far); - rsDebug("Fov: ", cam->horizontalFOV); - rsDebug("Position: ", cam->position); - rsDebug("Proj: ", &cam->proj); - rsDebug("View: ", &cam->view); -} - -static void printLightInfo(const SgLight *light) { - rsDebug("***** Light information. ptr:", light); - printName(light->name); - const SgTransform *lTransform = (const SgTransform *)rsGetElementAt(light->transformMatrix, 0); - rsDebug("Transform name:", lTransform); - printName(lTransform->name); - - rsDebug("Position: ", light->position); - rsDebug("Color : ", light->color); - rsDebug("Intensity: ", light->intensity); - rsDebug("Type: ", light->type); -} - -static void getCameraRay(const SgCamera *cam, int screenX, int screenY, float3 *pnt, float3 *vec) { - rsDebug("=================================", screenX); - rsDebug("Point X", screenX); - rsDebug("Point Y", screenY); - - rs_matrix4x4 mvpInv; - rsMatrixLoad(&mvpInv, &cam->viewProj); - rsMatrixInverse(&mvpInv); - - float width = (float)rsgGetWidth(); - float height = (float)rsgGetHeight(); - - float4 pos = {(float)screenX, height - (float)screenY, 0.0f, 1.0f}; - - pos.x /= width; - pos.y /= height; - - rsDebug("Pre Norm X", pos.x); - rsDebug("Pre Norm Y", pos.y); - - pos.xy = pos.xy * 2.0f - 1.0f; - - rsDebug("Norm X", pos.x); - rsDebug("Norm Y", pos.y); - - pos = rsMatrixMultiply(&mvpInv, pos); - float oneOverW = 1.0f / pos.w; - pos.xyz *= oneOverW; - - rsDebug("World X", pos.x); - rsDebug("World Y", pos.y); - rsDebug("World Z", pos.z); - - rsDebug("Cam X", cam->position.x); - rsDebug("Cam Y", cam->position.y); - rsDebug("Cam Z", cam->position.z); - - *vec = normalize(pos.xyz - cam->position.xyz); - rsDebug("Vec X", vec->x); - rsDebug("Vec Y", vec->y); - rsDebug("Vec Z", vec->z); - *pnt = cam->position.xyz; -} - -#endif // _TRANSFORM_DEF_ diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs index 0890b01b573b..88955a88ffdd 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs @@ -16,7 +16,7 @@ #pragma rs java_package_name(com.android.scenegraph) -#include "transform_def.rsh" +#include "scenegraph_objects.rsh" //#define DEBUG_PARAMS diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FileSelector.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FileSelector.java new file mode 100644 index 000000000000..420e1330d88a --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FileSelector.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2011 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.android.testapp; + +import java.io.File; +import java.io.FileFilter; +import java.util.ArrayList; +import java.util.List; + +import android.app.ListActivity; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.ListView; + +/** + * A list view where the last item the user clicked is placed in + * the "activated" state, causing its background to highlight. + */ +public class FileSelector extends ListActivity { + + File[] mCurrentSubList; + File mCurrentFile; + + class DAEFilter implements FileFilter { + public boolean accept(File file) { + if (file.isDirectory()) { + return true; + } + return file.getName().endsWith(".dae"); + } + } + + private void populateList(File file) { + + mCurrentFile = file; + setTitle(mCurrentFile.getAbsolutePath() + "/*.dae"); + List names = new ArrayList(); + names.add(".."); + + mCurrentSubList = mCurrentFile.listFiles(new DAEFilter()); + + if (mCurrentSubList != null) { + for (int i = 0; i < mCurrentSubList.length; i ++) { + String fileName = mCurrentSubList[i].getName(); + if (mCurrentSubList[i].isDirectory()) { + fileName = "/" + fileName; + } + names.add(fileName); + } + } + + // Use the built-in layout for showing a list item with a single + // line of text whose background is changes when activated. + setListAdapter(new ArrayAdapter(this, + android.R.layout.simple_list_item_activated_1, names)); + getListView().setTextFilterEnabled(true); + + // Tell the list view to show one checked/activated item at a time. + getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + populateList(new File("/sdcard/")); + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + if (position == 0) { + File parent = mCurrentFile.getParentFile(); + if (parent == null) { + return; + } + populateList(parent); + return; + } + + // the first thing in list is parent directory + File selectedFile = mCurrentSubList[position - 1]; + if (selectedFile.isDirectory()) { + populateList(selectedFile); + return; + } + + Intent resultIntent = new Intent(); + resultIntent.setData(Uri.fromFile(selectedFile)); + setResult(RESULT_OK, resultIntent); + finish(); + } + +} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java new file mode 100644 index 000000000000..2e764e932e21 --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/FullscreenBlur.java @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2011 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.android.testapp; + +import java.util.ArrayList; + +import com.android.scenegraph.*; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.renderscript.*; +import android.renderscript.Allocation.MipmapControl; +import android.renderscript.Element.Builder; +import android.renderscript.Font.Style; +import android.renderscript.Program.TextureType; +import android.renderscript.ProgramStore.DepthFunc; +import android.util.Log; + +class FullscreenBlur { + + static Allocation sRenderTargetBlur0Color; + static Allocation sRenderTargetBlur0Depth; + static Allocation sRenderTargetBlur1Color; + static Allocation sRenderTargetBlur1Depth; + static Allocation sRenderTargetBlur2Color; + static Allocation sRenderTargetBlur2Depth; + + static FragmentShader mPF_BlurH; + static FragmentShader mPF_BlurV; + static FragmentShader mPF_SelectColor; + static FragmentShader mPF_Texture; + static VertexShader mPV_Paint; + static VertexShader mPV_Blur; + + // This is only used when full screen blur is enabled + // Basically, it's the offscreen render targets + static void createRenderTargets(RenderScriptGL rs, int w, int h) { + Type.Builder b = new Type.Builder(rs, Element.RGBA_8888(rs)); + Type renderType = b.setX(w/8).setY(h/8).create(); + int usage = Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_GRAPHICS_RENDER_TARGET; + sRenderTargetBlur0Color = Allocation.createTyped(rs, renderType, usage); + sRenderTargetBlur1Color = Allocation.createTyped(rs, renderType, usage); + sRenderTargetBlur2Color = Allocation.createTyped(rs, renderType, usage); + + b = new Type.Builder(rs, Element.createPixel(rs, Element.DataType.UNSIGNED_16, + Element.DataKind.PIXEL_DEPTH)); + renderType = b.setX(w/8).setY(h/8).create(); + usage = Allocation.USAGE_GRAPHICS_RENDER_TARGET; + sRenderTargetBlur0Depth = Allocation.createTyped(rs, renderType, usage); + sRenderTargetBlur1Depth = Allocation.createTyped(rs, renderType, usage); + sRenderTargetBlur2Depth = Allocation.createTyped(rs, renderType, usage); + } + + static void addOffsets(Renderable quad, float advance) { + quad.appendSourceParams(new Float4Param("blurOffset0", - advance * 2.5f)); + quad.appendSourceParams(new Float4Param("blurOffset1", - advance * 0.5f)); + quad.appendSourceParams(new Float4Param("blurOffset2", advance * 1.5f)); + quad.appendSourceParams(new Float4Param("blurOffset3", advance * 3.5f)); + } + + static RenderPass addPass(Scene scene, 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)); + scene.appendRenderPass(pass); + return pass; + } + + static void addBlurPasses(Scene scene, RenderScriptGL rs) { + SceneManager sceneManager = SceneManager.getInstance(); + ArrayList allDraw = scene.getRenderables(); + int numDraw = allDraw.size(); + + ProgramRaster cullNone = ProgramRaster.CULL_NONE(rs); + ProgramStore blendAdd = SceneManager.BLEND_ADD_DEPTH_NONE(rs); + ProgramStore blendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(rs); + + RenderState drawTex = new RenderState(mPV_Blur, mPF_Texture, blendAdd, cullNone); + RenderState selectCol = new RenderState(mPV_Blur, mPF_SelectColor, blendNone, cullNone); + RenderState hBlur = new RenderState(mPV_Blur, mPF_BlurH, blendNone, cullNone); + RenderState vBlur = new RenderState(mPV_Blur, mPF_BlurV, blendNone, cullNone); + + // Renders the scene off screen + RenderPass blurSourcePass = addPass(scene, + sRenderTargetBlur0Color, + sRenderTargetBlur0Depth); + blurSourcePass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 1.0f)); + blurSourcePass.setShouldClearColor(true); + blurSourcePass.setClearDepth(1.0f); + blurSourcePass.setShouldClearDepth(true); + for (int i = 0; i < numDraw; i ++) { + blurSourcePass.appendRenderable((Renderable)allDraw.get(i)); + } + + // Pass for selecting bright colors + RenderPass selectColorPass = addPass(scene, + sRenderTargetBlur2Color, + sRenderTargetBlur2Depth); + Renderable quad = sceneManager.getRenderableQuad("ScreenAlignedQuadS", selectCol); + quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur0Color))); + selectColorPass.appendRenderable(quad); + + // Horizontal blur + RenderPass horizontalBlurPass = addPass(scene, + sRenderTargetBlur1Color, + sRenderTargetBlur1Depth); + quad = sceneManager.getRenderableQuad("ScreenAlignedQuadH", hBlur); + quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur2Color))); + addOffsets(quad, 1.0f / (float)sRenderTargetBlur0Color.getType().getX()); + horizontalBlurPass.appendRenderable(quad); + + // Vertical Blur + RenderPass verticalBlurPass = addPass(scene, + sRenderTargetBlur2Color, + sRenderTargetBlur2Depth); + quad = sceneManager.getRenderableQuad("ScreenAlignedQuadV", vBlur); + quad.appendSourceParams(new TextureParam("tex0", 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) { + 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))); + compositePass.appendRenderable(quad); + } + + static private FragmentShader getShader(Resources res, RenderScriptGL rs, + int resID, Type constants) { + FragmentShader.Builder fb = new FragmentShader.Builder(rs); + fb.setShader(res, resID); + fb.addTexture(TextureType.TEXTURE_2D, "color"); + if (constants != null) { + fb.setObjectConst(constants); + } + FragmentShader prog = fb.create(); + prog.getProgram().bindSampler(Sampler.CLAMP_LINEAR(rs), 0); + return prog; + } + + static void initShaders(Resources res, RenderScriptGL rs) { + ScriptField_FBlurOffsets_s blurConst = new ScriptField_FBlurOffsets_s(rs, 1); + VertexShader.Builder vb = new VertexShader.Builder(rs); + vb.addInput(ScriptField_VertexShaderInputs_s.createElement(rs)); + vb.setShader(res, R.raw.blur_vertex); + mPV_Blur = vb.create(); + + mPF_Texture = getShader(res, rs, R.raw.texture, null); + mPF_Texture.getProgram().bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(rs), 0); + mPF_BlurH = getShader(res, rs, R.raw.blur_h, blurConst.getAllocation().getType()); + mPF_BlurV = getShader(res, rs, R.raw.blur_v, blurConst.getAllocation().getType()); + mPF_SelectColor = getShader(res, rs, R.raw.select_color, null); + } + +} + + + + + diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestApp.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestApp.java new file mode 100644 index 000000000000..8b032f74978b --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestApp.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2011 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.android.testapp; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; + +import android.app.Activity; +import android.content.res.Configuration; +import android.content.Intent; +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.view.MenuInflater; +import android.view.Window; +import android.net.Uri; + +import java.lang.Runtime; + +public class TestApp extends Activity { + + private TestAppView mView; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + // Create our Preview view and set it as the content of our + // Activity + mView = new TestAppView(this); + setContentView(mView); + } + + @Override + protected void onResume() { + // 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() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity looses focus + super.onPause(); + mView.pause(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.loader_menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle item selection + switch (item.getItemId()) { + case R.id.load_model: + loadModel(); + return true; + case R.id.use_blur: + mView.mRender.toggleBlur(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private static final int FIND_DAE_MODEL = 10; + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (resultCode == RESULT_OK) { + if (requestCode == FIND_DAE_MODEL) { + Uri selectedImageUri = data.getData(); + Log.e("Selected Path: ", selectedImageUri.getPath()); + mView.mRender.loadModel(selectedImageUri.getPath()); + } + } + } + + public void loadModel() { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_PICK); + intent.setClassName("com.android.scenegraph", + "com.android.scenegraph.FileSelector"); + startActivityForResult(intent, FIND_DAE_MODEL); + } + +} + diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppLoadingScreen.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppLoadingScreen.java new file mode 100644 index 000000000000..b818833c42a4 --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppLoadingScreen.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2012 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.android.testapp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.renderscript.*; +import android.renderscript.Allocation.MipmapControl; +import android.renderscript.Element.Builder; +import android.renderscript.Font.Style; +import android.renderscript.Program.TextureType; +import android.renderscript.ProgramStore.DepthFunc; +import android.util.Log; + +// This is where the scenegraph and the rendered objects are initialized and used +public class TestAppLoadingScreen { + + private static String TAG = "TestAppLoadingScreen"; + + int mWidth; + int mHeight; + + private Resources mRes; + private RenderScriptGL mRS; + private ScriptC_test_app mScript; + + public TestAppLoadingScreen(RenderScriptGL rs, Resources res) { + mRS = rs; + mRes = res; + // Shows the loading screen with some text + renderLoading(); + // Adds a little 3D bugdroid model to the laoding screen asynchronously. + new LoadingScreenLoaderTask().execute(); + } + + public void showLoadingScreen(boolean show) { + mScript.set_gInitialized(!show); + } + + // The loading screen has some elements that shouldn't be loaded on the UI thread + private class LoadingScreenLoaderTask extends AsyncTask { + Allocation robotTex; + Mesh robotMesh; + protected Boolean doInBackground(String... names) { + long start = System.currentTimeMillis(); + robotTex = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot, + MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE, + Allocation.USAGE_GRAPHICS_TEXTURE); + + FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot); + FileA3D.IndexEntry entry = model.getIndexEntry(0); + if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) { + robotMesh = entry.getMesh(); + } + + mScript.set_gPFSBackground(ProgramStore.BLEND_NONE_DEPTH_TEST(mRS)); + + ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS); + b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, + ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); + ProgramFragment pfDefault = b.create(); + pfDefault.bindSampler(Sampler.CLAMP_LINEAR(mRS), 0); + mScript.set_gPFBackground(pfDefault); + + ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS); + ProgramVertexFixedFunction pvDefault = pvb.create(); + ProgramVertexFixedFunction.Constants va = new ProgramVertexFixedFunction.Constants(mRS); + ((ProgramVertexFixedFunction)pvDefault).bindConstants(va); + mScript.set_gPVBackground(pvDefault); + + long end = System.currentTimeMillis(); + Log.v("TIMER", "Loading load time: " + (end - start)); + return new Boolean(true); + } + + protected void onPostExecute(Boolean result) { + mScript.set_gRobotTex(robotTex); + mScript.set_gRobotMesh(robotMesh); + } + } + + // Creates a simple script to show a loding screen until everything is initialized + // Could also be used to do some custom renderscript work before handing things over + // to the scenegraph + void renderLoading() { + mScript = new ScriptC_test_app(mRS, mRes, R.raw.test_app); + mRS.bindRootScript(mScript); + } + + + public void setRenderLoop(ScriptC renderLoop) { + mScript.set_gRenderLoop(renderLoop); + Allocation dummyAlloc = Allocation.createSized(mRS, Element.I32(mRS), 1); + mScript.set_gDummyAlloc(dummyAlloc); + } +} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java new file mode 100644 index 000000000000..8840d120ca14 --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppRS.java @@ -0,0 +1,289 @@ +/* + * Copyright (C) 2011-2012 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.android.testapp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import com.android.scenegraph.*; +import com.android.scenegraph.SceneManager.SceneLoadedCallback; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.renderscript.*; +import android.renderscript.Program.TextureType; +import android.util.Log; + +// This is where the scenegraph and the rendered objects are initialized and used +public class TestAppRS { + + private static String modelName = "orientation_test.dae"; + private static String TAG = "TestAppRS"; + private static String mFilePath = ""; + + int mWidth; + int mHeight; + + boolean mUseBlur; + + TestAppLoadingScreen mLoadingScreen; + + // Used to asynchronously load scene elements like meshes and transform hierarchies + SceneLoadedCallback mLoadedCallback = new SceneLoadedCallback() { + public void run() { + prepareToRender(mLoadedScene); + } + }; + + // Top level class that initializes all the elements needed to use the scene graph + SceneManager mSceneManager; + + // Used to move the camera around in the 3D world + TouchHandler mTouchHandler; + + private Resources mRes; + private RenderScriptGL mRS; + + ScriptField_FShaderParams_s mFsConst; + ScriptField_FShaderLightParams_s mFsConst2; + ScriptField_VShaderParams_s mVsConst; + + // Shaders + private FragmentShader mPaintF; + private FragmentShader mLightsF; + private FragmentShader mAluminumF; + private FragmentShader mPlasticF; + private FragmentShader mDiffuseF; + private FragmentShader mTextureF; + private VertexShader mPaintV; + + private Allocation mDefaultCube; + private TextureCube mEnvCube; + private TextureCube mDiffCube; + + Scene mActiveScene; + + public TestAppRS() { + mUseBlur = false; + } + + // This is a part of the test app, it's used to tests multiple render passes and is toggled + // on and off in the menu, off by default + void toggleBlur() { + mUseBlur = !mUseBlur; + + mActiveScene.clearRenderPasses(); + initRenderPasses(); + mActiveScene.initRenderPassRS(mRS, mSceneManager); + + // This is just a hardcoded object in the scene that gets turned on and off for the demo + // to make things look a bit better. This could be deleted in the cleanup + Renderable plane = (Renderable)mActiveScene.getRenderableByName("pPlaneShape1"); + if (plane != null) { + plane.setVisible(mRS, !mUseBlur); + } + } + + public void init(RenderScriptGL rs, Resources res, int width, int height) { + mRS = rs; + mRes = res; + mWidth = width; + mHeight = height; + + mTouchHandler = new TouchHandler(); + + mSceneManager = SceneManager.getInstance(); + // Initializes all the RS specific scenegraph elements + mSceneManager.initRS(mRS, mRes, mWidth, mHeight); + + mLoadingScreen = new TestAppLoadingScreen(mRS, mRes); + + // Initi renderscript stuff specific to the app. This will need to be abstracted out later. + initRS(); + + // Load a scene to render + mSceneManager.loadModel(mFilePath + modelName, mLoadedCallback); + } + + // When a new model file is selected from the UI, this function gets called to init everything + void loadModel(String path) { + //String shortName = path.substring(path.lastIndexOf('/') + 1); + //shortName = shortName.substring(0, shortName.lastIndexOf('.')); + mLoadingScreen.showLoadingScreen(true); + mActiveScene.destroyRS(mSceneManager); + mSceneManager.loadModel(path, mLoadedCallback); + } + + public void onActionDown(float x, float y) { + mTouchHandler.onActionDown(x, y); + + //mSceneManager.getRenderLoop().invoke_pick((int)x, (int)y); + } + + public void onActionScale(float scale) { + mTouchHandler.onActionScale(scale); + } + + public void onActionMove(float x, float y) { + mTouchHandler.onActionMove(x, y); + } + + FragmentShader createFromResource(int id, boolean addCubemap) { + FragmentShader.Builder fb = new FragmentShader.Builder(mRS); + fb.setShaderConst(mFsConst.getAllocation().getType()); + fb.setShader(mRes, id); + fb.addTexture(TextureType.TEXTURE_2D, "diffuse"); + if (addCubemap) { + fb.addShaderTexture(TextureType.TEXTURE_CUBE, "reflection"); + } + FragmentShader pf = fb.create(); + pf.getProgram().bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS), 0); + if (addCubemap) { + pf.getProgram().bindSampler(Sampler.CLAMP_LINEAR_MIP_LINEAR(mRS), 1); + } + return pf; + } + + private void initPaintShaders() { + ScriptField_VObjectParams_s objConst = new ScriptField_VObjectParams_s(mRS, 1); + ScriptField_VSParams_s shaderConst = new ScriptField_VSParams_s(mRS, 1); + + VertexShader.Builder vb = new VertexShader.Builder(mRS); + vb.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); + vb.setShader(mRes, R.raw.shader2v); + vb.setObjectConst(objConst.getAllocation().getType()); + vb.setShaderConst(shaderConst.getAllocation().getType()); + mPaintV = vb.create(); + + mFsConst = new ScriptField_FShaderParams_s(mRS, 1); + mFsConst2 = new ScriptField_FShaderLightParams_s(mRS, 1); + + mPaintF = createFromResource(R.raw.paintf, true); + mPaintF.appendSourceParams(new TextureParam("reflection", mEnvCube)); + mAluminumF = createFromResource(R.raw.metal, true); + mAluminumF.appendSourceParams(new TextureParam("reflection", mDiffCube)); + + mPlasticF = createFromResource(R.raw.plastic, false); + mDiffuseF = createFromResource(R.raw.diffuse, false); + mTextureF = createFromResource(R.raw.texture, false); + + FragmentShader.Builder fb = new FragmentShader.Builder(mRS); + fb.setObjectConst(mFsConst2.getAllocation().getType()); + fb.setShader(mRes, R.raw.plastic_lights); + mLightsF = fb.create(); + + FullscreenBlur.initShaders(mRes, mRS); + } + + void initRenderPasses() { + ArrayList allDraw = mActiveScene.getRenderables(); + int numDraw = allDraw.size(); + + if (mUseBlur) { + FullscreenBlur.addBlurPasses(mActiveScene, mRS); + } + + RenderPass mainPass = new RenderPass(); + mainPass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 1.0f)); + mainPass.setShouldClearColor(true); + mainPass.setClearDepth(1.0f); + mainPass.setShouldClearDepth(true); + mainPass.setCamera(mActiveScene.getCameras().get(1)); + for (int i = 0; i < numDraw; i ++) { + mainPass.appendRenderable((Renderable)allDraw.get(i)); + } + mActiveScene.appendRenderPass(mainPass); + + if (mUseBlur) { + FullscreenBlur.addCompositePass(mActiveScene, mRS); + } + } + + private void addShadersToScene() { + mActiveScene.appendShader(mPaintF); + mActiveScene.appendShader(mLightsF); + mActiveScene.appendShader(mAluminumF); + mActiveScene.appendShader(mPlasticF); + mActiveScene.appendShader(mDiffuseF); + mActiveScene.appendShader(mTextureF); + mActiveScene.appendShader(mPaintV); + } + + public void prepareToRender(Scene s) { + mSceneManager.setActiveScene(s); + mActiveScene = s; + addShadersToScene(); + RenderState plastic = new RenderState(mPaintV, mPlasticF, null, null); + RenderState diffuse = new RenderState(mPaintV, mDiffuseF, null, null); + RenderState paint = new RenderState(mPaintV, mPaintF, null, null); + RenderState aluminum = new RenderState(mPaintV, mAluminumF, null, null); + RenderState lights = new RenderState(mPaintV, mLightsF, null, null); + RenderState glassTransp = new RenderState(mPaintV, mPaintF, + ProgramStore.BLEND_ALPHA_DEPTH_TEST(mRS), null); + + initRenderPasses(); + + mActiveScene.assignRenderState(plastic); + + mActiveScene.assignRenderStateToMaterial(diffuse, "lambert2$"); + + mActiveScene.assignRenderStateToMaterial(paint, "^#Paint"); + mActiveScene.assignRenderStateToMaterial(paint, "^#Carbon"); + mActiveScene.assignRenderStateToMaterial(paint, "^#Glass"); + mActiveScene.assignRenderStateToMaterial(paint, "^#MainGlass"); + + mActiveScene.assignRenderStateToMaterial(aluminum, "^#Metal"); + mActiveScene.assignRenderStateToMaterial(aluminum, "^#Brake"); + + mActiveScene.assignRenderStateToMaterial(glassTransp, "^#GlassLight"); + + mActiveScene.assignRenderStateToMaterial(lights, "^#LightBlinn"); + + Renderable plane = (Renderable)mActiveScene.getRenderableByName("pPlaneShape1"); + if (plane != null) { + RenderState texState = new RenderState(mPaintV, mTextureF, null, null); + plane.setRenderState(texState); + plane.setVisible(mRS, !mUseBlur); + } + + mTouchHandler.init(mActiveScene); + + long start = System.currentTimeMillis(); + mActiveScene.initRS(mRS, mRes, mSceneManager); + long end = System.currentTimeMillis(); + Log.v("TIMER", "Scene init time: " + (end - start)); + + mLoadingScreen.showLoadingScreen(false); + } + + private void initRS() { + + FullscreenBlur.createRenderTargets(mRS, mWidth, mHeight); + // Reflection maps from SD card + mEnvCube = new TextureCube("sdcard/scenegraph/", "cube_env.png"); + mDiffCube = new TextureCube("sdcard/scenegraph/", "cube_spec.png"); + initPaintShaders(); + + ScriptC_render renderLoop = mSceneManager.getRenderLoop(); + + mLoadingScreen.setRenderLoop(renderLoop); + } +} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppView.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppView.java new file mode 100644 index 000000000000..687f35b3ec7d --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TestAppView.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2011 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.android.testapp; + +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; +import android.view.ScaleGestureDetector; + +public class TestAppView extends RSSurfaceView { + + public TestAppView(Context context) { + super(context); + mScaleDetector = new ScaleGestureDetector(context, new ScaleListener()); + } + + private RenderScriptGL mRS; + TestAppRS mRender; + + private ScaleGestureDetector mScaleDetector; + private static final int INVALID_POINTER_ID = -1; + private int mActivePointerId = INVALID_POINTER_ID; + + 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(); + sc.setDepth(16, 24); + mRS = createRenderScriptGL(sc); + mRS.setSurface(holder, w, h); + mRender = new TestAppRS(); + mRender.init(mRS, getResources(), w, h); + } + } + + @Override + protected void onDetachedFromWindow() { + if (mRS != null) { + mRender = null; + mRS = null; + destroyRenderScriptGL(); + } + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) + { + // break point at here + // this method doesn't work when 'extends View' include 'extends ScrollView'. + return super.onKeyDown(keyCode, event); + } + + + @Override + public boolean onTouchEvent(MotionEvent ev) { + mScaleDetector.onTouchEvent(ev); + + boolean ret = false; + float x = ev.getX(); + float y = ev.getY(); + + final int action = ev.getAction(); + + switch (action & MotionEvent.ACTION_MASK) { + case MotionEvent.ACTION_DOWN: { + mRender.onActionDown(x, y); + mActivePointerId = ev.getPointerId(0); + ret = true; + break; + } + case MotionEvent.ACTION_MOVE: { + if (!mScaleDetector.isInProgress()) { + mRender.onActionMove(x, y); + } + mRender.onActionDown(x, y); + ret = true; + break; + } + + case MotionEvent.ACTION_UP: { + mActivePointerId = INVALID_POINTER_ID; + break; + } + + case MotionEvent.ACTION_CANCEL: { + mActivePointerId = INVALID_POINTER_ID; + break; + } + + case MotionEvent.ACTION_POINTER_UP: { + final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) + >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; + final int pointerId = ev.getPointerId(pointerIndex); + if (pointerId == mActivePointerId) { + // This was our active pointer going up. Choose a new + // active pointer and adjust accordingly. + final int newPointerIndex = pointerIndex == 0 ? 1 : 0; + x = ev.getX(newPointerIndex); + y = ev.getY(newPointerIndex); + mRender.onActionDown(x, y); + mActivePointerId = ev.getPointerId(newPointerIndex); + } + break; + } + } + + return ret; + } + + private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { + @Override + public boolean onScale(ScaleGestureDetector detector) { + mRender.onActionScale(detector.getScaleFactor()); + return true; + } + } +} + + diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java new file mode 100644 index 000000000000..4d303419079e --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/TouchHandler.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2011 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.android.testapp; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.FileInputStream; +import java.io.BufferedInputStream; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.renderscript.*; +import android.renderscript.Allocation.MipmapControl; +import android.renderscript.Element.Builder; +import android.renderscript.Font.Style; +import android.renderscript.Program.TextureType; +import android.renderscript.ProgramStore.DepthFunc; +import android.util.Log; + +import com.android.scenegraph.*; + +public class TouchHandler { + + private static String TAG = "TouchHandler"; + + public TouchHandler() { + } + + public void init(Scene scene) { + mCameraRotate = (CompoundTransform)scene.getTransformByName("CameraAim"); + mCameraDist = (CompoundTransform)scene.getTransformByName("CameraDist"); + + if (mCameraRotate != null && mCameraDist != null) { + mRotateX = mCameraRotate.mTransformComponents.get(2); + mRotateY = mCameraRotate.mTransformComponents.get(1); + mDist = mCameraDist.mTransformComponents.get(0); + } + } + + + private Resources mRes; + private RenderScriptGL mRS; + + float mLastX; + float mLastY; + + CompoundTransform mCameraRotate; + CompoundTransform mCameraDist; + + CompoundTransform.Component mRotateX; + CompoundTransform.Component mRotateY; + CompoundTransform.Component mDist; + + public void onActionDown(float x, float y) { + mLastX = x; + mLastY = y; + } + + public void onActionScale(float scale) { + if (mCameraDist == null) { + return; + } + mDist.mValue.z *= 1.0f / scale; + mDist.mValue.z = Math.max(20.0f, Math.min(mDist.mValue.z, 100.0f)); + mCameraDist.updateRSData(); + } + + public void onActionMove(float x, float y) { + if (mCameraRotate == null) { + return; + } + + float dx = mLastX - x; + float dy = mLastY - y; + + if (Math.abs(dy) <= 2.0f) { + dy = 0.0f; + } + if (Math.abs(dx) <= 2.0f) { + dx = 0.0f; + } + + mRotateY.mValue.w += dx*0.25; + if (mRotateY.mValue.w > 360) { + mRotateY.mValue.w -= 360; + } + if (mRotateY.mValue.w < 0) { + mRotateY.mValue.w += 360; + } + + mRotateX.mValue.w += dy*0.25; + mRotateX.mValue.w = Math.max(mRotateX.mValue.w, -80.0f); + mRotateX.mValue.w = Math.min(mRotateX.mValue.w, 0.0f); + + mLastX = x; + mLastY = y; + + mCameraRotate.updateRSData(); + } +} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rs new file mode 100644 index 000000000000..cb4e3d0a05a8 --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rs @@ -0,0 +1,99 @@ +// Copyright (C) 2011 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. + +#pragma version(1) + +#pragma rs java_package_name(com.android.testapp) + +#include "rs_graphics.rsh" +#include "test_app.rsh" + +// Making sure these get reflected +FBlurOffsets *blurExport; +VertexShaderInputs *iExport; +VShaderParams *vConst; +FShaderParams *fConst; +FShaderLightParams *fConts2; +VSParams *vConst2; +VObjectParams *vConst3; + +rs_program_vertex gPVBackground; +rs_program_fragment gPFBackground; + +rs_allocation gRobotTex; +rs_mesh gRobotMesh; + +rs_program_store gPFSBackground; + +rs_allocation gDummyAlloc; +rs_script gRenderLoop; + +bool gInitialized = false; + +float gRotate; + +void init() { + gRotate = 0.0f; +} + +static int pos = 50; +static float gRotateY = 120.0f; +static float3 gLookAt = 0; +static float gZoom = 50.0f; +static void displayLoading() { + if (rsIsObject(gRobotTex) && rsIsObject(gRobotMesh)) { + rsgBindProgramVertex(gPVBackground); + rs_matrix4x4 proj; + float aspect = (float)rsgGetWidth() / (float)rsgGetHeight(); + rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f); + rsgProgramVertexLoadProjectionMatrix(&proj); + + rsgBindProgramFragment(gPFBackground); + rsgBindProgramStore(gPFSBackground); + rsgBindTexture(gPFBackground, 0, gRobotTex); + + rs_matrix4x4 matrix; + rsMatrixLoadIdentity(&matrix); + // Position our models on the screen + gRotateY += rsGetDt()*100; + rsMatrixTranslate(&matrix, 0, 0, -gZoom); + rsMatrixRotate(&matrix, 20.0f, 1.0f, 0.0f, 0.0f); + rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f); + rsMatrixScale(&matrix, 0.2f, 0.2f, 0.2f); + rsgProgramVertexLoadModelMatrix(&matrix); + rsgDrawMesh(gRobotMesh); + } + + uint width = rsgGetWidth(); + uint height = rsgGetHeight(); + int left = 0, right = 0, top = 0, bottom = 0; + const char* text = "Initializing..."; + rsgMeasureText(text, &left, &right, &top, &bottom); + int centeredPos = width / 2 - (right - left) / 2; + rsgDrawText(text, centeredPos, height / 2 + height / 10); +} + +int root(void) { + rs_allocation nullAlloc; + if (!gInitialized) { + rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f); + rsgClearDepth(1.0f); + displayLoading(); + return 30; + } + + rsForEach(gRenderLoop, gDummyAlloc, nullAlloc); + + return 10; +} diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rsh new file mode 100644 index 000000000000..2885ac575045 --- /dev/null +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/testapp/test_app.rsh @@ -0,0 +1,57 @@ +// Copyright (C) 2012 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. + +#pragma version(1) + +#pragma rs java_package_name(com.android.testapp) + +// Helpers +typedef struct VShaderParams_s { + rs_matrix4x4 model; + rs_matrix4x4 viewProj; +} VShaderParams; + +typedef struct VSParams_s { + rs_matrix4x4 viewProj; +} VSParams; + +typedef struct VObjectParams_s { + rs_matrix4x4 model; +} VObjectParams; + +typedef struct FShaderParams_s { + float4 cameraPos; +} FShaderParams; + +typedef struct FShaderLightParams_s { + float4 lightPos_0; + float4 lightColor_0; + float4 lightPos_1; + float4 lightColor_1; + float4 cameraPos; + float4 diffuse; +} FShaderLightParams; + +typedef struct FBlurOffsets_s { + float blurOffset0; + float blurOffset1; + float blurOffset2; + float blurOffset3; +} FBlurOffsets; + +typedef struct VertexShaderInputs_s { + float4 position; + float3 normal; + float2 texture0; +} VertexShaderInputs; -- cgit v1.2.3-59-g8ed1b