diff options
| author | Alex Sakhartchouk <alexst@google.com> | 2010-08-23 10:37:27 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-08-23 10:37:27 -0700 |
| commit | a1f1174b396cda7bdff469a2e974a737600c5eb0 (patch) | |
| tree | 0754c6be53683d8a842d4fb2818dc0639f4a4a21 /libs | |
| parent | c275c76ca33341a7bf1acfefcf6757d8079c781c (diff) | |
| parent | 32e09b5891da0174f161d99e2d3ebe67d6efa39c (diff) | |
| download | frameworks_base-a1f1174b396cda7bdff469a2e974a737600c5eb0.zip frameworks_base-a1f1174b396cda7bdff469a2e974a737600c5eb0.tar.gz frameworks_base-a1f1174b396cda7bdff469a2e974a737600c5eb0.tar.bz2 | |
Merge "Renderscript samples. Resolving name conflict in model viewer. Adding fov projection matrix function. Adding helper methods for blending."
Diffstat (limited to 'libs')
14 files changed, 601 insertions, 16 deletions
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 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.modelviewer"> <application android:label="ModelViewer"> - <activity android:name="ModelViewer" + <activity android:name="SimpleModel" + android:label="SimpleModel" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar"> <intent-filter> 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/ModelViewer.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java index 7491744..cb7c39c 100644 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewer.java +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java @@ -37,9 +37,9 @@ import android.widget.ListView; import java.lang.Runtime; -public class ModelViewer extends Activity { +public class SimpleModel extends Activity { - private ModelViewerView mView; + private SimpleModelView mView; @Override public void onCreate(Bundle icicle) { @@ -47,7 +47,7 @@ public class ModelViewer extends Activity { // Create our Preview view and set it as the content of our // Activity - mView = new ModelViewerView(this); + mView = new SimpleModelView(this); setContentView(mView); } diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java index 479aaf3..b8b0119 100644 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java @@ -24,7 +24,7 @@ import android.renderscript.ProgramStore.DepthFunc; import android.util.Log; -public class ModelViewerRS { +public class SimpleModelRS { private final int STATE_LAST_FOCUS = 1; @@ -32,7 +32,7 @@ public class ModelViewerRS { int mHeight; int mRotation; - public ModelViewerRS() { + public SimpleModelRS() { } public void init(RenderScriptGL rs, Resources res, int width, int height) { @@ -60,7 +60,7 @@ public class ModelViewerRS { private Font mItalic; private Allocation mTextAlloc; - private ScriptC_Modelviewer mScript; + private ScriptC_Simplemodel mScript; int mLastX; int mLastY; @@ -86,7 +86,7 @@ public class ModelViewerRS { } 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); @@ -114,7 +114,7 @@ public class ModelViewerRS { } 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); @@ -139,7 +139,7 @@ public class ModelViewerRS { private void initRS() { - mScript = new ScriptC_Modelviewer(mRS, mRes, R.raw.modelviewer, true); + mScript = new ScriptC_Simplemodel(mRS, mRes, R.raw.simplemodel, true); initPFS(); initPF(); diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java index 061cf8e..2574fdd 100644 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java @@ -39,15 +39,15 @@ import android.view.SurfaceView; import android.view.KeyEvent; import android.view.MotionEvent; -public class ModelViewerView extends RSSurfaceView { +public class SimpleModelView extends RSSurfaceView { - public ModelViewerView(Context context) { + public SimpleModelView(Context context) { super(context); //setFocusable(true); } private RenderScriptGL mRS; - private ModelViewerRS mRender; + private SimpleModelRS mRender; public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { @@ -55,7 +55,7 @@ public class ModelViewerView extends RSSurfaceView { if (mRS == null) { mRS = createRenderScript(true); mRS.contextSetSurface(w, h, holder.getSurface()); - mRender = new ModelViewerRS(); + mRender = new SimpleModelRS(); mRender.init(mRS, getResources(), w, h); } } diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/modelviewer.rs b/libs/rs/java/ModelViewer/src/com/android/modelviewer/simplemodel.rs index adb609c..adb609c 100644 --- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/modelviewer.rs +++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/simplemodel.rs diff --git a/libs/rs/java/Samples/AndroidManifest.xml b/libs/rs/java/Samples/AndroidManifest.xml index 17c6b16..be191f2 100644 --- a/libs/rs/java/Samples/AndroidManifest.xml +++ b/libs/rs/java/Samples/AndroidManifest.xml @@ -11,5 +11,14 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> + + <activity android:name="RsRenderStates" + android:label="RsStates" + android:theme="@android:style/Theme.Black.NoTitleBar"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> </application> </manifest> diff --git a/libs/rs/java/Samples/res/drawable/data.png b/libs/rs/java/Samples/res/drawable/data.png Binary files differnew file mode 100644 index 0000000..8e34714 --- /dev/null +++ b/libs/rs/java/Samples/res/drawable/data.png diff --git a/libs/rs/java/Samples/res/drawable/leaf.png b/libs/rs/java/Samples/res/drawable/leaf.png Binary files differnew file mode 100644 index 0000000..3cd3775 --- /dev/null +++ b/libs/rs/java/Samples/res/drawable/leaf.png diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java new file mode 100644 index 0000000..391007e --- /dev/null +++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.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.samples; + +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 RsRenderStates extends Activity { + + private RsRenderStatesView 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 RsRenderStatesView(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/Samples/src/com/android/samples/RsRenderStatesRS.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java new file mode 100644 index 0000000..5a6ff23 --- /dev/null +++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java @@ -0,0 +1,207 @@ +/* + * 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.samples; + +import java.io.Writer; + +import android.content.res.Resources; +import android.renderscript.*; +import android.renderscript.ProgramStore.DepthFunc; +import android.util.Log; +import android.graphics.BitmapFactory; +import android.graphics.Bitmap; + + +public class RsRenderStatesRS { + + int mWidth; + int mHeight; + + public RsRenderStatesRS() { + } + + public void init(RenderScriptGL rs, Resources res, int width, int height) { + mRS = rs; + mRes = res; + mWidth = width; + mHeight = height; + mOptionsARGB.inScaled = false; + mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888; + mMode = 0; + mMaxModes = 4; + initRS(); + } + + private Resources mRes; + private RenderScriptGL mRS; + + private Sampler mSampler; + + private ProgramStore mProgStoreBlendNone; + private ProgramStore mProgStoreBlendAlpha; + private ProgramStore mProgStoreBlendAdd; + + private ProgramFragment mProgFragmentTexture; + private ProgramFragment mProgFragmentColor; + private ProgramVertex mProgVertex; + private ProgramVertex.MatrixAllocation mPVA; + + private Allocation mTexOpaque; + private Allocation mTexTransparent; + + private Allocation mAllocPV; + + private Mesh mMbyNMesh; + + Font mFontSans; + Font mFontSerif; + Font mFontSerifBold; + Font mFontSerifItalic; + Font mFontSerifBoldItalic; + Font mFontMono; + + private Allocation mTextAlloc; + + private ScriptC_Rsrenderstates mScript; + + private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options(); + + int mMode; + int mMaxModes; + + public void onActionDown(int x, int y) { + mMode ++; + mMode = mMode % mMaxModes; + mScript.set_gDisplayMode(mMode); + } + + + private void initProgramStore() { + // Use stock the stock program store object + mProgStoreBlendNone = ProgramStore.BlendNone_DepthNoDepth(mRS); + + // Create a custom program store + ProgramStore.Builder builder = new ProgramStore.Builder(mRS); + builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); + builder.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, + ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); + builder.setDitherEnable(false); + builder.setDepthMask(false); + mProgStoreBlendAlpha = builder.create(); + + mProgStoreBlendAdd = ProgramStore.BlendAdd_DepthNoDepth(mRS); + + mScript.set_gProgStoreBlendNone(mProgStoreBlendNone); + mScript.set_gProgStoreBlendAlpha(mProgStoreBlendAlpha); + mScript.set_gProgStoreBlendAdd(mProgStoreBlendAdd); + } + + private void initProgramFragment() { + + 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.CLAMP); + mSampler = bs.create(); + + ProgramFragment.Builder texBuilder = new ProgramFragment.Builder(mRS); + texBuilder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, + ProgramFragment.Builder.Format.RGBA, 0); + mProgFragmentTexture = texBuilder.create(); + mProgFragmentTexture.bindSampler(mSampler, 0); + + ProgramFragment.Builder colBuilder = new ProgramFragment.Builder(mRS); + colBuilder.setVaryingColor(false); + mProgFragmentColor = colBuilder.create(); + + mScript.set_gProgFragmentColor(mProgFragmentColor); + mScript.set_gProgFragmentTexture(mProgFragmentTexture); + } + + private void initProgramVertex() { + ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS); + mProgVertex = pvb.create(); + + mPVA = new ProgramVertex.MatrixAllocation(mRS); + mProgVertex.bindAllocation(mPVA); + mPVA.setupOrthoWindow(mWidth, mHeight); + + mScript.set_gProgVertex(mProgVertex); + } + + private Allocation loadTextureRGB(int id) { + final Allocation allocation = Allocation.createFromBitmapResource(mRS, mRes, + id, Element.RGB_565(mRS), false); + allocation.uploadToTexture(0); + return allocation; + } + + private Allocation loadTextureARGB(int id) { + Bitmap b = BitmapFactory.decodeResource(mRes, id, mOptionsARGB); + final Allocation allocation = Allocation.createFromBitmap(mRS, b, Element.RGBA_8888(mRS), false); + allocation.uploadToTexture(0); + return allocation; + } + + private void loadImages() { + mTexOpaque = loadTextureRGB(R.drawable.data); + mTexTransparent = loadTextureARGB(R.drawable.leaf); + + mScript.set_gTexOpaque(mTexOpaque); + mScript.set_gTexTransparent(mTexTransparent); + } + + private void initFonts() { + // Sans font by family name + mFontSans = Font.createFromFamily(mRS, mRes, "sans-serif", Font.Style.NORMAL, 8); + // Create font by file name + mFontSerif = Font.create(mRS, mRes, "DroidSerif-Regular.ttf", 8); + // Create fonts by family and style + mFontSerifBold = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD, 8); + mFontSerifItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.ITALIC, 8); + mFontSerifBoldItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8); + mFontMono = Font.createFromFamily(mRS, mRes, "mono", Font.Style.NORMAL, 8); + + mScript.set_gFontSans(mFontSans); + mScript.set_gFontSerif(mFontSerif); + mScript.set_gFontSerifBold(mFontSerifBold); + mScript.set_gFontSerifItalic(mFontSerifItalic); + mScript.set_gFontSerifBoldItalic(mFontSerifBoldItalic); + mScript.set_gFontMono(mFontMono); + } + + private void initRS() { + + mScript = new ScriptC_Rsrenderstates(mRS, mRes, R.raw.rsrenderstates, true); + + initProgramStore(); + initProgramFragment(); + initProgramVertex(); + + initFonts(); + + loadImages(); + + + + mRS.contextBindRootScript(mScript); + } +} + + + diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java new file mode 100644 index 0000000..5548de3 --- /dev/null +++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.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.samples; + +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 RsRenderStatesView extends RSSurfaceView { + + public RsRenderStatesView(Context context) { + super(context); + //setFocusable(true); + } + + private RenderScriptGL mRS; + private RsRenderStatesRS 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 RsRenderStatesRS(); + 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 = false; + int act = ev.getAction(); + if (act == ev.ACTION_DOWN) { + mRender.onActionDown((int)ev.getX(), (int)ev.getY()); + ret = true; + } + + return ret; + } +} + + diff --git a/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs b/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs new file mode 100644 index 0000000..1526a50 --- /dev/null +++ b/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs @@ -0,0 +1,194 @@ +// 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.samples) + +#include "rs_graphics.rsh" + +rs_program_vertex gProgVertex; +rs_program_fragment gProgFragmentColor; +rs_program_fragment gProgFragmentTexture; + +rs_program_store gProgStoreBlendNone; +rs_program_store gProgStoreBlendAlpha; +rs_program_store gProgStoreBlendAdd; + +rs_allocation gTexOpaque; +rs_allocation gTexTransparent; + +rs_mesh gMbyNMesh; + +rs_font gFontSans; +rs_font gFontSerif; +rs_font gFontSerifBold; +rs_font gFontSerifItalic; +rs_font gFontSerifBoldItalic; +rs_font gFontMono; + +int gDisplayMode; + +#pragma rs export_var(gProgVertex, gProgFragmentColor, gProgFragmentTexture) +#pragma rs export_var(gProgStoreBlendNone, gProgStoreBlendAlpha, gProgStoreBlendAdd) +#pragma rs export_var(gTexOpaque, gTexTransparent) +#pragma rs export_var(gMbyNMesh) +#pragma rs export_var(gFontSans, gFontSerif, gFontSerifBold, gFontSerifItalic, gFontSerifBoldItalic, gFontMono) + +//What we are showing +#pragma rs export_var(gDisplayMode) + +void init() { +} + +void displayFontSamples() { + rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f); + int yPos = 30; + rsgBindFont(gFontSans); + rsgDrawText("Sans font sample", 30, yPos); + yPos += 30; + rsgFontColor(0.5f, 0.9f, 0.5f, 1.0f); + rsgBindFont(gFontSerif); + rsgDrawText("Serif font sample", 30, yPos); + yPos += 30; + rsgFontColor(0.7f, 0.7f, 0.7f, 1.0f); + rsgBindFont(gFontSerifBold); + rsgDrawText("Serif Bold font sample", 30, yPos); + yPos += 30; + rsgFontColor(0.5f, 0.5f, 0.9f, 1.0f); + rsgBindFont(gFontSerifItalic); + rsgDrawText("Serif Italic font sample", 30, yPos); + yPos += 30; + rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f); + rsgBindFont(gFontSerifBoldItalic); + rsgDrawText("Serif Bold Italic font sample", 30, yPos); + yPos += 30; + rsgBindFont(gFontMono); + rsgDrawText("Monospace font sample", 30, yPos); +} + +void displayShaderSamples() { + // Default vertex sahder + rsgBindProgramVertex(gProgVertex); + rs_matrix4x4 matrix; + rsMatrixLoadIdentity(&matrix); + rsgProgramVertexLoadModelMatrix(&matrix); + + // Fragment shader with texture + rsgBindProgramStore(gProgStoreBlendNone); + rsgBindProgramFragment(gProgFragmentTexture); + rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque); + + rsgDrawQuadTexCoords(0, 0, 0, 0, 0, + 0, 256, 0, 0, 1, + 256, 256, 0, 1, 1, + 256, 0, 0, 1, 0); + + rsgDrawQuadTexCoords(200, 0, 0, 0, 0, + 200, 128, 0, 0, 1, + 328, 128, 0, 1, 1, + 328, 0, 0, 1, 0); + + rsgBindProgramStore(gProgStoreBlendAlpha); + rsgBindTexture(gProgFragmentTexture, 0, gTexTransparent); + rsgDrawQuadTexCoords(0, 200, 0, 0, 0, + 0, 328, 0, 0, 1, + 128, 328, 0, 1, 1, + 128, 200, 0, 1, 0); + + // Fragment program with simple color + rsgBindProgramFragment(gProgFragmentColor); + rsgProgramFragmentConstantColor(gProgFragmentColor, 0.9, 0.3, 0.3, 1); + rsgDrawRect(200, 300, 350, 450, 0); + rsgProgramFragmentConstantColor(gProgFragmentColor, 0.3, 0.9, 0.3, 1); + rsgDrawRect(50, 400, 400, 600, 0); + + rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f); + rsgBindFont(gFontMono); + rsgDrawText("Texture shader", 10, 50); + rsgDrawText("Alpha-blended texture shader", 10, 280); + rsgDrawText("Flat color shader", 100, 450); +} + +void displayBlendingSamples() { + int i; + + rsgBindProgramVertex(gProgVertex); + rs_matrix4x4 matrix; + rsMatrixLoadIdentity(&matrix); + rsgProgramVertexLoadModelMatrix(&matrix); + + rsgBindProgramFragment(gProgFragmentColor); + + rsgBindProgramStore(gProgStoreBlendNone); + for(i = 0; i < 3; i ++) { + float iPlusOne = (float)(i + 1); + rsgProgramFragmentConstantColor(gProgFragmentColor, + 0.1f*iPlusOne, 0.2f*iPlusOne, 0.3f*iPlusOne, 1); + float yPos = 150 * (float)i; + rsgDrawRect(0, yPos, 200, yPos + 200, 0); + } + + rsgBindProgramStore(gProgStoreBlendAlpha); + for(i = 0; i < 3; i ++) { + float iPlusOne = (float)(i + 1); + rsgProgramFragmentConstantColor(gProgFragmentColor, + 0.2f*iPlusOne, 0.3f*iPlusOne, 0.1f*iPlusOne, 0.5); + float yPos = 150 * (float)i; + rsgDrawRect(150, yPos, 350, yPos + 200, 0); + } + + rsgBindProgramStore(gProgStoreBlendAdd); + for(i = 0; i < 3; i ++) { + float iPlusOne = (float)(i + 1); + rsgProgramFragmentConstantColor(gProgFragmentColor, + 0.3f*iPlusOne, 0.1f*iPlusOne, 0.2f*iPlusOne, 0.5); + float yPos = 150 * (float)i; + rsgDrawRect(300, yPos, 500, yPos + 200, 0); + } + + + rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f); + rsgBindFont(gFontMono); + rsgDrawText("No Blending", 10, 50); + rsgDrawText("Alpha Blending", 160, 150); + rsgDrawText("Additive Blending", 320, 250); + +} + +void displayMeshSamples() { +} + +int root(int launchID) { + + rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f); + rsgClearDepth(1.0f); + + switch(gDisplayMode) { + case 0: + displayFontSamples(); + break; + case 1: + displayShaderSamples(); + break; + case 2: + displayBlendingSamples(); + break; + case 3: + displayMeshSamples(); + break; + } + + return 10; +} diff --git a/libs/rs/scriptc/rs_core.rsh b/libs/rs/scriptc/rs_core.rsh index 0bfb3b9..99fc166 100644 --- a/libs/rs/scriptc/rs_core.rsh +++ b/libs/rs/scriptc/rs_core.rsh @@ -429,6 +429,15 @@ rsMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, floa m->m[15]= 0.f; } +static void __attribute__((overloadable)) +rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far) { + float top = near * tan((float) (fovy * M_PI / 360.0f)); + float bottom = -top; + float left = bottom * aspect; + float right = top * aspect; + rsMatrixLoadFrustum(m, left, right, bottom, top, near, far); +} + static float4 __attribute__((overloadable)) rsMatrixMultiply(rs_matrix4x4 *m, float4 in) { float4 ret; |
