From 32e09b5891da0174f161d99e2d3ebe67d6efa39c Mon Sep 17 00:00:00 2001 From: Alex Sakhartchouk Date: Mon, 23 Aug 2010 10:24:10 -0700 Subject: Renderscript samples. Resolving name conflict in model viewer. Adding fov projection matrix function. Adding helper methods for blending. Change-Id: Ibd3f1510436811398787c285845d050158bd6de8 --- libs/rs/java/ModelViewer/AndroidManifest.xml | 3 +- .../src/com/android/modelviewer/ModelViewer.java | 71 --------- .../src/com/android/modelviewer/ModelViewerRS.java | 170 --------------------- .../com/android/modelviewer/ModelViewerView.java | 94 ------------ .../src/com/android/modelviewer/SceneGraphRS.java | 4 +- .../src/com/android/modelviewer/SimpleModel.java | 71 +++++++++ .../src/com/android/modelviewer/SimpleModelRS.java | 170 +++++++++++++++++++++ .../com/android/modelviewer/SimpleModelView.java | 94 ++++++++++++ .../src/com/android/modelviewer/modelviewer.rs | 72 --------- .../src/com/android/modelviewer/simplemodel.rs | 72 +++++++++ 10 files changed, 411 insertions(+), 410 deletions(-) delete mode 100644 libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewer.java delete mode 100644 libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java delete mode 100644 libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java create mode 100644 libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java create mode 100644 libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java create mode 100644 libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java delete mode 100644 libs/rs/java/ModelViewer/src/com/android/modelviewer/modelviewer.rs create mode 100644 libs/rs/java/ModelViewer/src/com/android/modelviewer/simplemodel.rs (limited to 'libs/rs/java/ModelViewer') diff --git a/libs/rs/java/ModelViewer/AndroidManifest.xml b/libs/rs/java/ModelViewer/AndroidManifest.xml index 39976d2..959fe53 100644 --- a/libs/rs/java/ModelViewer/AndroidManifest.xml +++ b/libs/rs/java/ModelViewer/AndroidManifest.xml @@ -2,7 +2,8 @@ - diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewer.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewer.java deleted file mode 100644 index 7491744..0000000 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewer.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.modelviewer; - -import android.renderscript.RSSurfaceView; -import android.renderscript.RenderScript; - -import android.app.Activity; -import android.content.res.Configuration; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.provider.Settings.System; -import android.util.Config; -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 java.lang.Runtime; - -public class ModelViewer extends Activity { - - private ModelViewerView 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 ModelViewerView(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.onResume(); - } - - @Override - protected void onPause() { - // Ideally a game should implement onResume() and onPause() - // to take appropriate action when the activity looses focus - super.onPause(); - mView.onPause(); - } - -} - diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java deleted file mode 100644 index 479aaf3..0000000 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.modelviewer; - -import java.io.Writer; - -import android.content.res.Resources; -import android.renderscript.*; -import android.renderscript.ProgramStore.DepthFunc; -import android.util.Log; - - -public class ModelViewerRS { - - private final int STATE_LAST_FOCUS = 1; - - int mWidth; - int mHeight; - int mRotation; - - public ModelViewerRS() { - } - - public void init(RenderScriptGL rs, Resources res, int width, int height) { - mRS = rs; - mRes = res; - mWidth = width; - mHeight = height; - mRotation = 0; - initRS(); - } - - private Resources mRes; - private RenderScriptGL mRS; - private Sampler mSampler; - private ProgramStore mPSBackground; - private ProgramFragment mPFBackground; - private ProgramVertex mPVBackground; - private ProgramVertex.MatrixAllocation mPVA; - - private Allocation mGridImage; - private Allocation mAllocPV; - - private Mesh mMesh; - - private Font mItalic; - private Allocation mTextAlloc; - - private ScriptC_Modelviewer mScript; - - int mLastX; - int mLastY; - - public void touchEvent(int x, int y) { - int dx = mLastX - x; - if(Math.abs(dx) > 50 || Math.abs(dx) < 3) { - dx = 0; - } - - mRotation -= dx; - if(mRotation > 360) { - mRotation -= 360; - } - if(mRotation < 0) { - mRotation += 360; - } - - mScript.set_gRotate(-(float)mRotation); - - mLastX = x; - mLastY = y; - } - - private void initPFS() { - ProgramStore.Builder b = new ProgramStore.Builder(mRS, null, null); - - b.setDepthFunc(ProgramStore.DepthFunc.LESS); - b.setDitherEnable(false); - b.setDepthMask(true); - mPSBackground = b.create(); - - mScript.set_gPFSBackground(mPSBackground); - } - - private void initPF() { - Sampler.Builder bs = new Sampler.Builder(mRS); - bs.setMin(Sampler.Value.LINEAR); - bs.setMag(Sampler.Value.LINEAR); - bs.setWrapS(Sampler.Value.CLAMP); - bs.setWrapT(Sampler.Value.WRAP); - mSampler = bs.create(); - - ProgramFragment.Builder b = new ProgramFragment.Builder(mRS); - b.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, - ProgramFragment.Builder.Format.RGBA, 0); - mPFBackground = b.create(); - mPFBackground.bindSampler(mSampler, 0); - - mScript.set_gPFBackground(mPFBackground); - } - - private void initPV() { - ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); - mPVBackground = pvb.create(); - - mPVA = new ProgramVertex.MatrixAllocation(mRS); - mPVBackground.bindAllocation(mPVA); - mPVA.setupProjectionNormalized(mWidth, mHeight); - - mScript.set_gPVBackground(mPVBackground); - } - - private void loadImage() { - mGridImage = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.robot, Element.RGB_565(mRS), true); - mGridImage.uploadToTexture(0); - - mScript.set_gTGrid(mGridImage); - } - - private void initTextAllocation() { - String allocString = "Displaying file: R.raw.robot"; - mTextAlloc = Allocation.createFromString(mRS, allocString); - mScript.set_gTextAlloc(mTextAlloc); - } - - private void initRS() { - - mScript = new ScriptC_Modelviewer(mRS, mRes, R.raw.modelviewer, true); - - initPFS(); - initPF(); - initPV(); - - loadImage(); - - FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot); - FileA3D.IndexEntry entry = model.getIndexEntry(0); - if(entry == null || entry.getClassID() != FileA3D.ClassID.MESH) { - Log.e("rs", "could not load model"); - } - else { - mMesh = (Mesh)entry.getObject(); - mScript.set_gTestMesh(mMesh); - } - - mItalic = Font.create(mRS, mRes, "DroidSerif-Italic.ttf", 8); - mScript.set_gItalic(mItalic); - - initTextAllocation(); - - mRS.contextBindRootScript(mScript); - } -} - - - diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java deleted file mode 100644 index 061cf8e..0000000 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.modelviewer; - -import java.io.Writer; -import java.util.ArrayList; -import java.util.concurrent.Semaphore; - -import android.renderscript.RSSurfaceView; -import android.renderscript.RenderScript; -import android.renderscript.RenderScriptGL; - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.os.Handler; -import android.os.Message; -import android.util.AttributeSet; -import android.util.Log; -import android.view.Surface; -import android.view.SurfaceHolder; -import android.view.SurfaceView; -import android.view.KeyEvent; -import android.view.MotionEvent; - -public class ModelViewerView extends RSSurfaceView { - - public ModelViewerView(Context context) { - super(context); - //setFocusable(true); - } - - private RenderScriptGL mRS; - private ModelViewerRS mRender; - - - public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { - super.surfaceChanged(holder, format, w, h); - if (mRS == null) { - mRS = createRenderScript(true); - mRS.contextSetSurface(w, h, holder.getSurface()); - mRender = new ModelViewerRS(); - mRender.init(mRS, getResources(), w, h); - } - } - - @Override - protected void onDetachedFromWindow() { - if(mRS != null) { - mRS = null; - destroyRenderScript(); - } - } - - @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) - { - boolean ret = true; - int act = ev.getAction(); - if (act == ev.ACTION_UP) { - ret = false; - } - - mRender.touchEvent((int)ev.getX(), (int)ev.getY()); - return ret; - } -} - - diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java index 3f4d930..9672a6a 100644 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java @@ -90,7 +90,7 @@ public class SceneGraphRS { } private void initPFS() { - ProgramStore.Builder b = new ProgramStore.Builder(mRS, null, null); + ProgramStore.Builder b = new ProgramStore.Builder(mRS); b.setDepthFunc(ProgramStore.DepthFunc.LESS); b.setDitherEnable(false); @@ -118,7 +118,7 @@ public class SceneGraphRS { } private void initPV() { - ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); + ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS); mPVBackground = pvb.create(); mPVA = new ProgramVertex.MatrixAllocation(mRS); diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java new file mode 100644 index 0000000..cb7c39c --- /dev/null +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.modelviewer; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; + +import android.app.Activity; +import android.content.res.Configuration; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.provider.Settings.System; +import android.util.Config; +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 java.lang.Runtime; + +public class SimpleModel extends Activity { + + private SimpleModelView 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 SimpleModelView(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.onResume(); + } + + @Override + protected void onPause() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity looses focus + super.onPause(); + mView.onPause(); + } + +} + diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java new file mode 100644 index 0000000..b8b0119 --- /dev/null +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.modelviewer; + +import java.io.Writer; + +import android.content.res.Resources; +import android.renderscript.*; +import android.renderscript.ProgramStore.DepthFunc; +import android.util.Log; + + +public class SimpleModelRS { + + private final int STATE_LAST_FOCUS = 1; + + int mWidth; + int mHeight; + int mRotation; + + public SimpleModelRS() { + } + + public void init(RenderScriptGL rs, Resources res, int width, int height) { + mRS = rs; + mRes = res; + mWidth = width; + mHeight = height; + mRotation = 0; + initRS(); + } + + private Resources mRes; + private RenderScriptGL mRS; + private Sampler mSampler; + private ProgramStore mPSBackground; + private ProgramFragment mPFBackground; + private ProgramVertex mPVBackground; + private ProgramVertex.MatrixAllocation mPVA; + + private Allocation mGridImage; + private Allocation mAllocPV; + + private Mesh mMesh; + + private Font mItalic; + private Allocation mTextAlloc; + + private ScriptC_Simplemodel mScript; + + int mLastX; + int mLastY; + + public void touchEvent(int x, int y) { + int dx = mLastX - x; + if(Math.abs(dx) > 50 || Math.abs(dx) < 3) { + dx = 0; + } + + mRotation -= dx; + if(mRotation > 360) { + mRotation -= 360; + } + if(mRotation < 0) { + mRotation += 360; + } + + mScript.set_gRotate(-(float)mRotation); + + mLastX = x; + mLastY = y; + } + + private void initPFS() { + ProgramStore.Builder b = new ProgramStore.Builder(mRS); + + b.setDepthFunc(ProgramStore.DepthFunc.LESS); + b.setDitherEnable(false); + b.setDepthMask(true); + mPSBackground = b.create(); + + mScript.set_gPFSBackground(mPSBackground); + } + + private void initPF() { + Sampler.Builder bs = new Sampler.Builder(mRS); + bs.setMin(Sampler.Value.LINEAR); + bs.setMag(Sampler.Value.LINEAR); + bs.setWrapS(Sampler.Value.CLAMP); + bs.setWrapT(Sampler.Value.WRAP); + mSampler = bs.create(); + + ProgramFragment.Builder b = new ProgramFragment.Builder(mRS); + b.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, + ProgramFragment.Builder.Format.RGBA, 0); + mPFBackground = b.create(); + mPFBackground.bindSampler(mSampler, 0); + + mScript.set_gPFBackground(mPFBackground); + } + + private void initPV() { + ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS); + mPVBackground = pvb.create(); + + mPVA = new ProgramVertex.MatrixAllocation(mRS); + mPVBackground.bindAllocation(mPVA); + mPVA.setupProjectionNormalized(mWidth, mHeight); + + mScript.set_gPVBackground(mPVBackground); + } + + private void loadImage() { + mGridImage = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.robot, Element.RGB_565(mRS), true); + mGridImage.uploadToTexture(0); + + mScript.set_gTGrid(mGridImage); + } + + private void initTextAllocation() { + String allocString = "Displaying file: R.raw.robot"; + mTextAlloc = Allocation.createFromString(mRS, allocString); + mScript.set_gTextAlloc(mTextAlloc); + } + + private void initRS() { + + mScript = new ScriptC_Simplemodel(mRS, mRes, R.raw.simplemodel, true); + + initPFS(); + initPF(); + initPV(); + + loadImage(); + + FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot); + FileA3D.IndexEntry entry = model.getIndexEntry(0); + if(entry == null || entry.getClassID() != FileA3D.ClassID.MESH) { + Log.e("rs", "could not load model"); + } + else { + mMesh = (Mesh)entry.getObject(); + mScript.set_gTestMesh(mMesh); + } + + mItalic = Font.create(mRS, mRes, "DroidSerif-Italic.ttf", 8); + mScript.set_gItalic(mItalic); + + initTextAllocation(); + + mRS.contextBindRootScript(mScript); + } +} + + + diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java new file mode 100644 index 0000000..2574fdd --- /dev/null +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.modelviewer; + +import java.io.Writer; +import java.util.ArrayList; +import java.util.concurrent.Semaphore; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; +import android.renderscript.RenderScriptGL; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.os.Message; +import android.util.AttributeSet; +import android.util.Log; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.KeyEvent; +import android.view.MotionEvent; + +public class SimpleModelView extends RSSurfaceView { + + public SimpleModelView(Context context) { + super(context); + //setFocusable(true); + } + + private RenderScriptGL mRS; + private SimpleModelRS mRender; + + + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + super.surfaceChanged(holder, format, w, h); + if (mRS == null) { + mRS = createRenderScript(true); + mRS.contextSetSurface(w, h, holder.getSurface()); + mRender = new SimpleModelRS(); + mRender.init(mRS, getResources(), w, h); + } + } + + @Override + protected void onDetachedFromWindow() { + if(mRS != null) { + mRS = null; + destroyRenderScript(); + } + } + + @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) + { + boolean ret = true; + int act = ev.getAction(); + if (act == ev.ACTION_UP) { + ret = false; + } + + mRender.touchEvent((int)ev.getX(), (int)ev.getY()); + return ret; + } +} + + diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/modelviewer.rs b/libs/rs/java/ModelViewer/src/com/android/modelviewer/modelviewer.rs deleted file mode 100644 index adb609c..0000000 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/modelviewer.rs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2009 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.modelviewer) - -#include "rs_graphics.rsh" - -rs_program_vertex gPVBackground; -rs_program_fragment gPFBackground; - -rs_allocation gTGrid; -rs_mesh gTestMesh; - -rs_program_store gPFSBackground; - -float gRotate; - -rs_font gItalic; -rs_allocation gTextAlloc; - -#pragma rs export_var(gPVBackground, gPFBackground, gTGrid, gTestMesh, gPFSBackground, gRotate, gItalic, gTextAlloc) - -float gDT; -int64_t gLastTime; - -void init() { - gRotate = 0.0f; -} - -int root(int launchID) { - - rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f); - rsgClearDepth(1.0f); - - rsgBindProgramVertex(gPVBackground); - - rsgBindProgramFragment(gPFBackground); - rsgBindProgramStore(gPFSBackground); - rsgBindTexture(gPFBackground, 0, gTGrid); - - rs_matrix4x4 matrix; - rsMatrixLoadIdentity(&matrix); - // Position our model on the screen - rsMatrixTranslate(&matrix, 0.0f, -0.3f, 1.2f); - rsMatrixScale(&matrix, 0.2f, 0.2f, 0.2f); - rsMatrixRotate(&matrix, -25.0f, 1.0f, 0.0f, 0.0f); - rsMatrixRotate(&matrix, gRotate, 0.0f, 1.0f, 0.0f); - rsgProgramVertexLoadModelMatrix(&matrix); - - rsgDrawMesh(gTestMesh); - - rsgFontColor(0.3f, 0.3f, 0.3f, 1.0f); - rsgDrawText("Renderscript model test", 30, 695); - - rsgBindFont(gItalic); - rsgDrawText(gTextAlloc, 30, 730); - - return 10; -} diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/simplemodel.rs b/libs/rs/java/ModelViewer/src/com/android/modelviewer/simplemodel.rs new file mode 100644 index 0000000..adb609c --- /dev/null +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/simplemodel.rs @@ -0,0 +1,72 @@ +// Copyright (C) 2009 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.modelviewer) + +#include "rs_graphics.rsh" + +rs_program_vertex gPVBackground; +rs_program_fragment gPFBackground; + +rs_allocation gTGrid; +rs_mesh gTestMesh; + +rs_program_store gPFSBackground; + +float gRotate; + +rs_font gItalic; +rs_allocation gTextAlloc; + +#pragma rs export_var(gPVBackground, gPFBackground, gTGrid, gTestMesh, gPFSBackground, gRotate, gItalic, gTextAlloc) + +float gDT; +int64_t gLastTime; + +void init() { + gRotate = 0.0f; +} + +int root(int launchID) { + + rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f); + rsgClearDepth(1.0f); + + rsgBindProgramVertex(gPVBackground); + + rsgBindProgramFragment(gPFBackground); + rsgBindProgramStore(gPFSBackground); + rsgBindTexture(gPFBackground, 0, gTGrid); + + rs_matrix4x4 matrix; + rsMatrixLoadIdentity(&matrix); + // Position our model on the screen + rsMatrixTranslate(&matrix, 0.0f, -0.3f, 1.2f); + rsMatrixScale(&matrix, 0.2f, 0.2f, 0.2f); + rsMatrixRotate(&matrix, -25.0f, 1.0f, 0.0f, 0.0f); + rsMatrixRotate(&matrix, gRotate, 0.0f, 1.0f, 0.0f); + rsgProgramVertexLoadModelMatrix(&matrix); + + rsgDrawMesh(gTestMesh); + + rsgFontColor(0.3f, 0.3f, 0.3f, 1.0f); + rsgDrawText("Renderscript model test", 30, 695); + + rsgBindFont(gItalic); + rsgDrawText(gTextAlloc, 30, 730); + + return 10; +} -- cgit v1.1