Merge "Remove graphics-related RenderScript tests."
@ -1 +0,0 @@
|
||||
include $(call all-subdir-makefiles)
|
@ -1,28 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2008 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := FBOTest
|
||||
|
||||
LOCAL_SDK_VERSION := 17
|
||||
|
||||
include $(BUILD_PACKAGE)
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.fbotest">
|
||||
<application android:label="_FBOTest">
|
||||
<activity android:name="FBOTest"
|
||||
android:label="FBO Base Test"
|
||||
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>
|
||||
<activity android:name="FBOSync"
|
||||
android:label="FBO Sync Test"
|
||||
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>
|
Before Width: | Height: | Size: 286 KiB |
@ -1,72 +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.fbotest;
|
||||
|
||||
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.MenuInflater;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.net.Uri;
|
||||
|
||||
import java.lang.Runtime;
|
||||
|
||||
public class FBOSync extends Activity {
|
||||
|
||||
private FBOSyncView 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 FBOSyncView(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();
|
||||
}
|
||||
}
|
||||
|
@ -1,213 +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.fbotest;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.Element.DataType;
|
||||
import android.renderscript.Element.DataKind;
|
||||
import android.renderscript.ProgramStore.DepthFunc;
|
||||
import android.renderscript.Type.Builder;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class FBOSyncRS {
|
||||
|
||||
public FBOSyncRS() {
|
||||
}
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initRS();
|
||||
}
|
||||
|
||||
public void surfaceChanged() {
|
||||
mRS.getWidth();
|
||||
mRS.getHeight();
|
||||
}
|
||||
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
private Sampler mSampler;
|
||||
private ProgramStore mPSBackground;
|
||||
private ProgramFragment mPFBackground;
|
||||
private ProgramVertex mPVBackground;
|
||||
private ProgramVertexFixedFunction.Constants mPVA;
|
||||
|
||||
private Allocation mGridImage;
|
||||
private Allocation mOffscreen;
|
||||
private Allocation mOffscreenDepth;
|
||||
private Allocation mAllocPV;
|
||||
private Allocation mReadBackTest;
|
||||
|
||||
private Font mItalic;
|
||||
private Allocation mTextAlloc;
|
||||
|
||||
private ScriptField_MeshInfo mMeshes;
|
||||
private ScriptC_fbosync mScript;
|
||||
|
||||
|
||||
public void onActionDown(float x, float y) {
|
||||
mScript.invoke_onActionDown(x, y);
|
||||
}
|
||||
|
||||
public void onActionScale(float scale) {
|
||||
mScript.invoke_onActionScale(scale);
|
||||
}
|
||||
|
||||
public void onActionMove(float x, float y) {
|
||||
mScript.invoke_onActionMove(x, y);
|
||||
}
|
||||
|
||||
private void initPFS() {
|
||||
ProgramStore.Builder b = new ProgramStore.Builder(mRS);
|
||||
|
||||
b.setDepthFunc(ProgramStore.DepthFunc.LESS);
|
||||
b.setDitherEnabled(false);
|
||||
b.setDepthMaskEnabled(true);
|
||||
mPSBackground = b.create();
|
||||
|
||||
mScript.set_gPFSBackground(mPSBackground);
|
||||
}
|
||||
|
||||
private void initPF() {
|
||||
Sampler.Builder bs = new Sampler.Builder(mRS);
|
||||
bs.setMinification(Sampler.Value.LINEAR);
|
||||
bs.setMagnification(Sampler.Value.LINEAR);
|
||||
bs.setWrapS(Sampler.Value.CLAMP);
|
||||
bs.setWrapT(Sampler.Value.CLAMP);
|
||||
mSampler = bs.create();
|
||||
|
||||
ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
|
||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
||||
mPFBackground = b.create();
|
||||
mPFBackground.bindSampler(mSampler, 0);
|
||||
|
||||
mScript.set_gPFBackground(mPFBackground);
|
||||
}
|
||||
|
||||
private void initPV() {
|
||||
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
|
||||
mPVBackground = pvb.create();
|
||||
|
||||
mPVA = new ProgramVertexFixedFunction.Constants(mRS);
|
||||
((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
|
||||
|
||||
mScript.set_gPVBackground(mPVBackground);
|
||||
}
|
||||
|
||||
private void loadImage() {
|
||||
mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
mScript.set_gTGrid(mGridImage);
|
||||
}
|
||||
|
||||
private void initTextAllocation(String fileName) {
|
||||
String allocString = "Displaying file: " + fileName;
|
||||
mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
|
||||
mScript.set_gTextAlloc(mTextAlloc);
|
||||
}
|
||||
|
||||
private void initMeshes(FileA3D model) {
|
||||
int numEntries = model.getIndexEntryCount();
|
||||
int numMeshes = 0;
|
||||
for (int i = 0; i < numEntries; i ++) {
|
||||
FileA3D.IndexEntry entry = model.getIndexEntry(i);
|
||||
if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
|
||||
numMeshes ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numMeshes > 0) {
|
||||
mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);
|
||||
|
||||
for (int i = 0; i < numEntries; i ++) {
|
||||
FileA3D.IndexEntry entry = model.getIndexEntry(i);
|
||||
if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
|
||||
Mesh mesh = entry.getMesh();
|
||||
mMeshes.set_mMesh(i, mesh, false);
|
||||
mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
|
||||
}
|
||||
}
|
||||
mMeshes.copyAll();
|
||||
} else {
|
||||
throw new RSRuntimeException("No valid meshes in file");
|
||||
}
|
||||
|
||||
mScript.bind_gMeshes(mMeshes);
|
||||
mScript.invoke_updateMeshInfo();
|
||||
}
|
||||
|
||||
public void loadA3DFile(String path) {
|
||||
FileA3D model = FileA3D.createFromFile(mRS, path);
|
||||
initMeshes(model);
|
||||
initTextAllocation(path);
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
|
||||
mScript = new ScriptC_fbosync(mRS, mRes, R.raw.fbosync);
|
||||
|
||||
initPFS();
|
||||
initPF();
|
||||
initPV();
|
||||
|
||||
loadImage();
|
||||
|
||||
Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
|
||||
b.setX(512).setY(512);
|
||||
mOffscreen = Allocation.createTyped(mRS,
|
||||
b.create(),
|
||||
Allocation.USAGE_SCRIPT |
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE |
|
||||
Allocation.USAGE_GRAPHICS_RENDER_TARGET);
|
||||
mScript.set_gOffscreen(mOffscreen);
|
||||
|
||||
mReadBackTest = Allocation.createTyped(mRS,
|
||||
b.create(),
|
||||
Allocation.USAGE_SCRIPT |
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
mScript.set_gReadBackTest(mReadBackTest);
|
||||
|
||||
b = new Type.Builder(mRS,
|
||||
Element.createPixel(mRS, DataType.UNSIGNED_16,
|
||||
DataKind.PIXEL_DEPTH));
|
||||
b.setX(512).setY(512);
|
||||
mOffscreenDepth = Allocation.createTyped(mRS,
|
||||
b.create(),
|
||||
Allocation.USAGE_GRAPHICS_RENDER_TARGET);
|
||||
mScript.set_gOffscreenDepth(mOffscreenDepth);
|
||||
|
||||
FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
|
||||
initMeshes(model);
|
||||
|
||||
mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
|
||||
mScript.set_gItalic(mItalic);
|
||||
|
||||
initTextAllocation("R.raw.robot");
|
||||
|
||||
mRS.bindRootScript(mScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,144 +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.fbotest;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScriptGL;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.ScaleGestureDetector;
|
||||
import android.util.Log;
|
||||
|
||||
public class FBOSyncView extends RSSurfaceView {
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private FBOSyncRS mRender;
|
||||
|
||||
private ScaleGestureDetector mScaleDetector;
|
||||
|
||||
private static final int INVALID_POINTER_ID = -1;
|
||||
private int mActivePointerId = INVALID_POINTER_ID;
|
||||
|
||||
public FBOSyncView(Context context) {
|
||||
super(context);
|
||||
ensureRenderScript();
|
||||
mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
|
||||
}
|
||||
|
||||
private void ensureRenderScript() {
|
||||
if (mRS == null) {
|
||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
||||
sc.setDepth(16, 24);
|
||||
mRS = createRenderScriptGL(sc);
|
||||
mRender = new FBOSyncRS();
|
||||
mRender.init(mRS, getResources());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
ensureRenderScript();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
super.surfaceChanged(holder, format, w, h);
|
||||
mRender.surfaceChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
mRender = null;
|
||||
if (mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScriptGL();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadA3DFile(String path) {
|
||||
mRender.loadA3DFile(path);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,72 +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.fbotest;
|
||||
|
||||
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.MenuInflater;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.net.Uri;
|
||||
|
||||
import java.lang.Runtime;
|
||||
|
||||
public class FBOTest extends Activity {
|
||||
|
||||
private FBOTestView 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 FBOTestView(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();
|
||||
}
|
||||
}
|
||||
|
@ -1,205 +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.fbotest;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.Element.DataType;
|
||||
import android.renderscript.Element.DataKind;
|
||||
import android.renderscript.ProgramStore.DepthFunc;
|
||||
import android.renderscript.Type.Builder;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class FBOTestRS {
|
||||
|
||||
public FBOTestRS() {
|
||||
}
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initRS();
|
||||
}
|
||||
|
||||
public void surfaceChanged() {
|
||||
mRS.getWidth();
|
||||
mRS.getHeight();
|
||||
}
|
||||
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
private Sampler mSampler;
|
||||
private ProgramStore mPSBackground;
|
||||
private ProgramFragment mPFBackground;
|
||||
private ProgramVertex mPVBackground;
|
||||
private ProgramVertexFixedFunction.Constants mPVA;
|
||||
|
||||
private Allocation mGridImage;
|
||||
private Allocation mOffscreen;
|
||||
private Allocation mOffscreenDepth;
|
||||
private Allocation mAllocPV;
|
||||
|
||||
private Font mItalic;
|
||||
private Allocation mTextAlloc;
|
||||
|
||||
private ScriptField_MeshInfo mMeshes;
|
||||
private ScriptC_fbotest mScript;
|
||||
|
||||
|
||||
public void onActionDown(float x, float y) {
|
||||
mScript.invoke_onActionDown(x, y);
|
||||
}
|
||||
|
||||
public void onActionScale(float scale) {
|
||||
mScript.invoke_onActionScale(scale);
|
||||
}
|
||||
|
||||
public void onActionMove(float x, float y) {
|
||||
mScript.invoke_onActionMove(x, y);
|
||||
}
|
||||
|
||||
private void initPFS() {
|
||||
ProgramStore.Builder b = new ProgramStore.Builder(mRS);
|
||||
|
||||
b.setDepthFunc(ProgramStore.DepthFunc.LESS);
|
||||
b.setDitherEnabled(false);
|
||||
b.setDepthMaskEnabled(true);
|
||||
mPSBackground = b.create();
|
||||
|
||||
mScript.set_gPFSBackground(mPSBackground);
|
||||
}
|
||||
|
||||
private void initPF() {
|
||||
Sampler.Builder bs = new Sampler.Builder(mRS);
|
||||
bs.setMinification(Sampler.Value.LINEAR);
|
||||
bs.setMagnification(Sampler.Value.LINEAR);
|
||||
bs.setWrapS(Sampler.Value.CLAMP);
|
||||
bs.setWrapT(Sampler.Value.CLAMP);
|
||||
mSampler = bs.create();
|
||||
|
||||
ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
|
||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
||||
mPFBackground = b.create();
|
||||
mPFBackground.bindSampler(mSampler, 0);
|
||||
|
||||
mScript.set_gPFBackground(mPFBackground);
|
||||
}
|
||||
|
||||
private void initPV() {
|
||||
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
|
||||
mPVBackground = pvb.create();
|
||||
|
||||
mPVA = new ProgramVertexFixedFunction.Constants(mRS);
|
||||
((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
|
||||
|
||||
mScript.set_gPVBackground(mPVBackground);
|
||||
}
|
||||
|
||||
private void loadImage() {
|
||||
mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
mScript.set_gTGrid(mGridImage);
|
||||
}
|
||||
|
||||
private void initTextAllocation(String fileName) {
|
||||
String allocString = "Displaying file: " + fileName;
|
||||
mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
|
||||
mScript.set_gTextAlloc(mTextAlloc);
|
||||
}
|
||||
|
||||
private void initMeshes(FileA3D model) {
|
||||
int numEntries = model.getIndexEntryCount();
|
||||
int numMeshes = 0;
|
||||
for (int i = 0; i < numEntries; i ++) {
|
||||
FileA3D.IndexEntry entry = model.getIndexEntry(i);
|
||||
if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
|
||||
numMeshes ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numMeshes > 0) {
|
||||
mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);
|
||||
|
||||
for (int i = 0; i < numEntries; i ++) {
|
||||
FileA3D.IndexEntry entry = model.getIndexEntry(i);
|
||||
if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
|
||||
Mesh mesh = entry.getMesh();
|
||||
mMeshes.set_mMesh(i, mesh, false);
|
||||
mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
|
||||
}
|
||||
}
|
||||
mMeshes.copyAll();
|
||||
} else {
|
||||
throw new RSRuntimeException("No valid meshes in file");
|
||||
}
|
||||
|
||||
mScript.bind_gMeshes(mMeshes);
|
||||
mScript.invoke_updateMeshInfo();
|
||||
}
|
||||
|
||||
public void loadA3DFile(String path) {
|
||||
FileA3D model = FileA3D.createFromFile(mRS, path);
|
||||
initMeshes(model);
|
||||
initTextAllocation(path);
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
|
||||
mScript = new ScriptC_fbotest(mRS, mRes, R.raw.fbotest);
|
||||
|
||||
initPFS();
|
||||
initPF();
|
||||
initPV();
|
||||
|
||||
loadImage();
|
||||
|
||||
Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
|
||||
b.setX(512).setY(512);
|
||||
mOffscreen = Allocation.createTyped(mRS,
|
||||
b.create(),
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE |
|
||||
Allocation.USAGE_GRAPHICS_RENDER_TARGET);
|
||||
mScript.set_gOffscreen(mOffscreen);
|
||||
|
||||
b = new Type.Builder(mRS,
|
||||
Element.createPixel(mRS, DataType.UNSIGNED_16,
|
||||
DataKind.PIXEL_DEPTH));
|
||||
b.setX(512).setY(512);
|
||||
mOffscreenDepth = Allocation.createTyped(mRS,
|
||||
b.create(),
|
||||
Allocation.USAGE_GRAPHICS_RENDER_TARGET);
|
||||
mScript.set_gOffscreenDepth(mOffscreenDepth);
|
||||
|
||||
FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
|
||||
initMeshes(model);
|
||||
|
||||
mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
|
||||
mScript.set_gItalic(mItalic);
|
||||
|
||||
initTextAllocation("R.raw.robot");
|
||||
|
||||
mRS.bindRootScript(mScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,144 +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.fbotest;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScriptGL;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.ScaleGestureDetector;
|
||||
import android.util.Log;
|
||||
|
||||
public class FBOTestView extends RSSurfaceView {
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private FBOTestRS mRender;
|
||||
|
||||
private ScaleGestureDetector mScaleDetector;
|
||||
|
||||
private static final int INVALID_POINTER_ID = -1;
|
||||
private int mActivePointerId = INVALID_POINTER_ID;
|
||||
|
||||
public FBOTestView(Context context) {
|
||||
super(context);
|
||||
ensureRenderScript();
|
||||
mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
|
||||
}
|
||||
|
||||
private void ensureRenderScript() {
|
||||
if (mRS == null) {
|
||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
||||
sc.setDepth(16, 24);
|
||||
mRS = createRenderScriptGL(sc);
|
||||
mRender = new FBOTestRS();
|
||||
mRender.init(mRS, getResources());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
ensureRenderScript();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
super.surfaceChanged(holder, format, w, h);
|
||||
mRender.surfaceChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
mRender = null;
|
||||
if (mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScriptGL();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadA3DFile(String path) {
|
||||
mRender.loadA3DFile(path);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,230 +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.fbotest)
|
||||
|
||||
#include "rs_graphics.rsh"
|
||||
|
||||
rs_program_vertex gPVBackground;
|
||||
rs_program_fragment gPFBackground;
|
||||
|
||||
rs_allocation gTGrid;
|
||||
|
||||
rs_program_store gPFSBackground;
|
||||
|
||||
rs_font gItalic;
|
||||
rs_allocation gTextAlloc;
|
||||
|
||||
rs_allocation gOffscreen;
|
||||
rs_allocation gOffscreenDepth;
|
||||
rs_allocation gReadBackTest;
|
||||
|
||||
typedef struct MeshInfo {
|
||||
rs_mesh mMesh;
|
||||
int mNumIndexSets;
|
||||
float3 bBoxMin;
|
||||
float3 bBoxMax;
|
||||
} MeshInfo_t;
|
||||
|
||||
MeshInfo_t *gMeshes;
|
||||
|
||||
static float3 gLookAt;
|
||||
|
||||
static float gRotateX;
|
||||
static float gRotateY;
|
||||
static float gZoom;
|
||||
|
||||
static float gLastX;
|
||||
static float gLastY;
|
||||
|
||||
void onActionDown(float x, float y) {
|
||||
gLastX = x;
|
||||
gLastY = y;
|
||||
}
|
||||
|
||||
void onActionScale(float scale) {
|
||||
|
||||
gZoom *= 1.0f / scale;
|
||||
gZoom = max(0.1f, min(gZoom, 500.0f));
|
||||
}
|
||||
|
||||
void onActionMove(float x, float y) {
|
||||
float dx = gLastX - x;
|
||||
float dy = gLastY - y;
|
||||
|
||||
if (fabs(dy) <= 2.0f) {
|
||||
dy = 0.0f;
|
||||
}
|
||||
if (fabs(dx) <= 2.0f) {
|
||||
dx = 0.0f;
|
||||
}
|
||||
|
||||
gRotateY -= dx;
|
||||
if (gRotateY > 360) {
|
||||
gRotateY -= 360;
|
||||
}
|
||||
if (gRotateY < 0) {
|
||||
gRotateY += 360;
|
||||
}
|
||||
|
||||
gRotateX -= dy;
|
||||
gRotateX = min(gRotateX, 80.0f);
|
||||
gRotateX = max(gRotateX, -80.0f);
|
||||
|
||||
gLastX = x;
|
||||
gLastY = y;
|
||||
}
|
||||
|
||||
void init() {
|
||||
gRotateX = 0.0f;
|
||||
gRotateY = 0.0f;
|
||||
gZoom = 50.0f;
|
||||
gLookAt = 0.0f;
|
||||
}
|
||||
|
||||
void updateMeshInfo() {
|
||||
rs_allocation allMeshes = rsGetAllocation(gMeshes);
|
||||
int size = rsAllocationGetDimX(allMeshes);
|
||||
gLookAt = 0.0f;
|
||||
float minX, minY, minZ, maxX, maxY, maxZ;
|
||||
for (int i = 0; i < size; i++) {
|
||||
MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
|
||||
rsgMeshComputeBoundingBox(info->mMesh,
|
||||
&minX, &minY, &minZ,
|
||||
&maxX, &maxY, &maxZ);
|
||||
info->bBoxMin = (float3){minX, minY, minZ};
|
||||
info->bBoxMax = (float3){maxX, maxY, maxZ};
|
||||
gLookAt += (info->bBoxMin + info->bBoxMax)*0.5f;
|
||||
}
|
||||
gLookAt = gLookAt / (float)size;
|
||||
}
|
||||
|
||||
static void renderAllMeshes() {
|
||||
rs_allocation allMeshes = rsGetAllocation(gMeshes);
|
||||
int size = rsAllocationGetDimX(allMeshes);
|
||||
gLookAt = 0.0f;
|
||||
for (int i = 0; i < size; i++) {
|
||||
MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
|
||||
rsgDrawMesh(info->mMesh);
|
||||
}
|
||||
}
|
||||
|
||||
static void drawDescription() {
|
||||
uint height = rsgGetHeight();
|
||||
int left = 0, right = 0, top = 0, bottom = 0;
|
||||
|
||||
rsgBindFont(gItalic);
|
||||
|
||||
rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
|
||||
rsgDrawText(gTextAlloc, 2 -left, height - 2 + bottom);
|
||||
}
|
||||
|
||||
static void renderOffscreen(bool useDepth) {
|
||||
|
||||
rsgBindColorTarget(gOffscreen, 0);
|
||||
if (useDepth) {
|
||||
rsgBindDepthTarget(gOffscreenDepth);
|
||||
rsgClearDepth(1.0f);
|
||||
} else {
|
||||
rsgClearDepthTarget();
|
||||
}
|
||||
rsgClearColor(0.8f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
rsgBindProgramVertex(gPVBackground);
|
||||
rs_matrix4x4 proj;
|
||||
float aspect = (float)rsAllocationGetDimX(gOffscreen) / (float)rsAllocationGetDimY(gOffscreen);
|
||||
rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
|
||||
rsgProgramVertexLoadProjectionMatrix(&proj);
|
||||
|
||||
rsgBindProgramFragment(gPFBackground);
|
||||
rsgBindProgramStore(gPFSBackground);
|
||||
rsgBindTexture(gPFBackground, 0, gTGrid);
|
||||
|
||||
rs_matrix4x4 matrix;
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
// Position our models on the screen
|
||||
rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
|
||||
rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
|
||||
rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
renderAllMeshes();
|
||||
|
||||
// Render into the frambuffer
|
||||
rsgClearAllRenderTargets();
|
||||
}
|
||||
|
||||
static void drawOffscreenResult(int posX, int posY, rs_allocation texture) {
|
||||
// display the result
|
||||
rs_matrix4x4 proj, matrix;
|
||||
rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
|
||||
rsgProgramVertexLoadProjectionMatrix(&proj);
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
rsgBindTexture(gPFBackground, 0, texture);
|
||||
float startX = posX, startY = posY;
|
||||
float width = 256, height = 256;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
|
||||
startX, startY + height, 0, 0, 0,
|
||||
startX + width, startY + height, 0, 1, 0,
|
||||
startX + width, startY, 0, 1, 1);
|
||||
}
|
||||
|
||||
int root(void) {
|
||||
|
||||
rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgClearDepth(1.0f);
|
||||
|
||||
renderOffscreen(true);
|
||||
drawOffscreenResult(0, 0, gOffscreen);
|
||||
|
||||
|
||||
uint32_t w = rsAllocationGetDimX(gOffscreen);
|
||||
uint32_t h = rsAllocationGetDimY(gOffscreen);
|
||||
|
||||
rsgAllocationSyncAll(gOffscreen, RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET);
|
||||
|
||||
rsAllocationCopy2DRange(gReadBackTest, 0, 0, 0,
|
||||
RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, w, h,
|
||||
gOffscreen, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X);
|
||||
|
||||
rsgAllocationSyncAll(gReadBackTest);
|
||||
drawOffscreenResult(0, 300, gReadBackTest);
|
||||
|
||||
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, gTGrid);
|
||||
|
||||
rs_matrix4x4 matrix;
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
// Position our models on the screen
|
||||
rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
|
||||
rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
|
||||
rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
renderAllMeshes();
|
||||
|
||||
drawDescription();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,219 +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.fbotest)
|
||||
|
||||
#include "rs_graphics.rsh"
|
||||
|
||||
rs_program_vertex gPVBackground;
|
||||
rs_program_fragment gPFBackground;
|
||||
|
||||
rs_allocation gTGrid;
|
||||
|
||||
rs_program_store gPFSBackground;
|
||||
|
||||
rs_font gItalic;
|
||||
rs_allocation gTextAlloc;
|
||||
|
||||
rs_allocation gOffscreen;
|
||||
rs_allocation gOffscreenDepth;
|
||||
|
||||
typedef struct MeshInfo {
|
||||
rs_mesh mMesh;
|
||||
int mNumIndexSets;
|
||||
float3 bBoxMin;
|
||||
float3 bBoxMax;
|
||||
} MeshInfo_t;
|
||||
|
||||
MeshInfo_t *gMeshes;
|
||||
|
||||
static float3 gLookAt;
|
||||
|
||||
static float gRotateX;
|
||||
static float gRotateY;
|
||||
static float gZoom;
|
||||
|
||||
static float gLastX;
|
||||
static float gLastY;
|
||||
|
||||
void onActionDown(float x, float y) {
|
||||
gLastX = x;
|
||||
gLastY = y;
|
||||
}
|
||||
|
||||
void onActionScale(float scale) {
|
||||
|
||||
gZoom *= 1.0f / scale;
|
||||
gZoom = max(0.1f, min(gZoom, 500.0f));
|
||||
}
|
||||
|
||||
void onActionMove(float x, float y) {
|
||||
float dx = gLastX - x;
|
||||
float dy = gLastY - y;
|
||||
|
||||
if (fabs(dy) <= 2.0f) {
|
||||
dy = 0.0f;
|
||||
}
|
||||
if (fabs(dx) <= 2.0f) {
|
||||
dx = 0.0f;
|
||||
}
|
||||
|
||||
gRotateY -= dx;
|
||||
if (gRotateY > 360) {
|
||||
gRotateY -= 360;
|
||||
}
|
||||
if (gRotateY < 0) {
|
||||
gRotateY += 360;
|
||||
}
|
||||
|
||||
gRotateX -= dy;
|
||||
gRotateX = min(gRotateX, 80.0f);
|
||||
gRotateX = max(gRotateX, -80.0f);
|
||||
|
||||
gLastX = x;
|
||||
gLastY = y;
|
||||
}
|
||||
|
||||
void init() {
|
||||
gRotateX = 0.0f;
|
||||
gRotateY = 0.0f;
|
||||
gZoom = 50.0f;
|
||||
gLookAt = 0.0f;
|
||||
}
|
||||
|
||||
void updateMeshInfo() {
|
||||
rs_allocation allMeshes = rsGetAllocation(gMeshes);
|
||||
int size = rsAllocationGetDimX(allMeshes);
|
||||
gLookAt = 0.0f;
|
||||
float minX, minY, minZ, maxX, maxY, maxZ;
|
||||
for (int i = 0; i < size; i++) {
|
||||
MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
|
||||
rsgMeshComputeBoundingBox(info->mMesh,
|
||||
&minX, &minY, &minZ,
|
||||
&maxX, &maxY, &maxZ);
|
||||
info->bBoxMin = (float3){minX, minY, minZ};
|
||||
info->bBoxMax = (float3){maxX, maxY, maxZ};
|
||||
gLookAt += (info->bBoxMin + info->bBoxMax)*0.5f;
|
||||
}
|
||||
gLookAt = gLookAt / (float)size;
|
||||
}
|
||||
|
||||
static void renderAllMeshes() {
|
||||
rs_allocation allMeshes = rsGetAllocation(gMeshes);
|
||||
int size = rsAllocationGetDimX(allMeshes);
|
||||
gLookAt = 0.0f;
|
||||
for (int i = 0; i < size; i++) {
|
||||
MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
|
||||
rsgDrawMesh(info->mMesh);
|
||||
}
|
||||
}
|
||||
|
||||
static void drawDescription() {
|
||||
uint height = rsgGetHeight();
|
||||
int left = 0, right = 0, top = 0, bottom = 0;
|
||||
|
||||
rsgBindFont(gItalic);
|
||||
|
||||
rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
|
||||
rsgDrawText(gTextAlloc, 2 -left, height - 2 + bottom);
|
||||
}
|
||||
|
||||
static void renderOffscreen(bool useDepth) {
|
||||
|
||||
rsgBindColorTarget(gOffscreen, 0);
|
||||
if (useDepth) {
|
||||
rsgBindDepthTarget(gOffscreenDepth);
|
||||
rsgClearDepth(1.0f);
|
||||
} else {
|
||||
rsgClearDepthTarget();
|
||||
}
|
||||
rsgClearColor(0.8f, 0.8f, 0.8f, 1.0f);
|
||||
|
||||
rsgBindProgramVertex(gPVBackground);
|
||||
rs_matrix4x4 proj;
|
||||
float aspect = (float)rsAllocationGetDimX(gOffscreen) / (float)rsAllocationGetDimY(gOffscreen);
|
||||
rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
|
||||
rsgProgramVertexLoadProjectionMatrix(&proj);
|
||||
|
||||
rsgBindProgramFragment(gPFBackground);
|
||||
rsgBindProgramStore(gPFSBackground);
|
||||
rsgBindTexture(gPFBackground, 0, gTGrid);
|
||||
|
||||
rs_matrix4x4 matrix;
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
// Position our models on the screen
|
||||
rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
|
||||
rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
|
||||
rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
renderAllMeshes();
|
||||
|
||||
// Render into the frambuffer
|
||||
rsgClearAllRenderTargets();
|
||||
}
|
||||
|
||||
static void drawOffscreenResult(int posX, int posY) {
|
||||
// display the result
|
||||
rs_matrix4x4 proj, matrix;
|
||||
rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
|
||||
rsgProgramVertexLoadProjectionMatrix(&proj);
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
rsgBindTexture(gPFBackground, 0, gOffscreen);
|
||||
float startX = posX, startY = posY;
|
||||
float width = 256, height = 256;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
|
||||
startX, startY + height, 0, 0, 0,
|
||||
startX + width, startY + height, 0, 1, 0,
|
||||
startX + width, startY, 0, 1, 1);
|
||||
}
|
||||
|
||||
int root(void) {
|
||||
|
||||
rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgClearDepth(1.0f);
|
||||
|
||||
renderOffscreen(true);
|
||||
drawOffscreenResult(0, 0);
|
||||
|
||||
renderOffscreen(false);
|
||||
drawOffscreenResult(0, 256);
|
||||
|
||||
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, gTGrid);
|
||||
|
||||
rs_matrix4x4 matrix;
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
// Position our models on the screen
|
||||
rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
|
||||
rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
|
||||
rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
renderAllMeshes();
|
||||
|
||||
drawDescription();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,28 +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.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := RsHelloWorld
|
||||
|
||||
LOCAL_SDK_VERSION := 17
|
||||
|
||||
include $(BUILD_PACKAGE)
|
@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.android.rs.helloworld">
|
||||
<uses-sdk android:minSdkVersion="11" />
|
||||
<application android:label="RsHelloWorld"
|
||||
android:icon="@drawable/test_pattern">
|
||||
<activity android:name="HelloWorld"
|
||||
android:label="RsHelloWorld"
|
||||
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>
|
@ -1 +0,0 @@
|
||||
<p>A Renderscript graphics application that draws the text "Hello, World!" where the user touches.</p>
|
Before Width: | Height: | Size: 307 B |
@ -1,54 +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.example.android.rs.helloworld;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
// Renderscript activity
|
||||
public class HelloWorld extends Activity {
|
||||
|
||||
// Custom view to use with RenderScript
|
||||
private HelloWorldView mView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
// Create our view and set it as the content of our Activity
|
||||
mView = new HelloWorldView(this);
|
||||
setContentView(mView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// Ideally an app should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity loses focus
|
||||
super.onResume();
|
||||
mView.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
// Ideally an app should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity loses focus
|
||||
super.onPause();
|
||||
mView.pause();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,52 +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.example.android.rs.helloworld;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
|
||||
// This is the renderer for the HelloWorldView
|
||||
public class HelloWorldRS {
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
|
||||
private ScriptC_helloworld mScript;
|
||||
|
||||
public HelloWorldRS() {
|
||||
}
|
||||
|
||||
// This provides us with the renderscript context and resources that
|
||||
// allow us to create the script that does rendering
|
||||
public void init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initRS();
|
||||
}
|
||||
|
||||
public void onActionDown(int x, int y) {
|
||||
mScript.set_gTouchX(x);
|
||||
mScript.set_gTouchY(y);
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
mScript = new ScriptC_helloworld(mRS, mRes, R.raw.helloworld);
|
||||
mRS.bindRootScript(mScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,76 +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.example.android.rs.helloworld;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScriptGL;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class HelloWorldView extends RSSurfaceView {
|
||||
// Renderscipt context
|
||||
private RenderScriptGL mRS;
|
||||
// Script that does the rendering
|
||||
private HelloWorldRS mRender;
|
||||
|
||||
public HelloWorldView(Context context) {
|
||||
super(context);
|
||||
ensureRenderScript();
|
||||
}
|
||||
|
||||
private void ensureRenderScript() {
|
||||
if (mRS == null) {
|
||||
// Initialize renderscript with desired surface characteristics.
|
||||
// In this case, just use the defaults
|
||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
||||
mRS = createRenderScriptGL(sc);
|
||||
// Create an instance of the script that does the rendering
|
||||
mRender = new HelloWorldRS();
|
||||
mRender.init(mRS, getResources());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
ensureRenderScript();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
// Handle the system event and clean up
|
||||
mRender = null;
|
||||
if (mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScriptGL();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
// Pass touch events from the system to the rendering script
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
mRender.onActionDown((int)ev.getX(), (int)ev.getY());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,47 +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)
|
||||
|
||||
// Tell which java package name the reflected files should belong to
|
||||
#pragma rs java_package_name(com.example.android.rs.helloworld)
|
||||
|
||||
// Built-in header with graphics API's
|
||||
#include "rs_graphics.rsh"
|
||||
|
||||
// gTouchX and gTouchY are variables that will be reflected for use
|
||||
// by the java API. We can use them to notify the script of touch events.
|
||||
int gTouchX;
|
||||
int gTouchY;
|
||||
|
||||
// This is invoked automatically when the script is created
|
||||
void init() {
|
||||
gTouchX = 50.0f;
|
||||
gTouchY = 50.0f;
|
||||
}
|
||||
|
||||
int root(void) {
|
||||
|
||||
// Clear the background color
|
||||
rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
// Tell the runtime what the font color should be
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
// Introuduce ourselves to the world by drawing a greeting
|
||||
// at the position user touched on the screen
|
||||
rsgDrawText("Hello World!", gTouchX, gTouchY);
|
||||
|
||||
// Return value tells RS roughly how often to redraw
|
||||
// in this case 20 ms
|
||||
return 20;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2008 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := RsMiscSamples
|
||||
|
||||
LOCAL_SDK_VERSION := 17
|
||||
|
||||
include $(BUILD_PACKAGE)
|
@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.android.rs.miscsamples">
|
||||
<uses-sdk android:minSdkVersion="11" />
|
||||
<application android:label="RsMiscSamples"
|
||||
android:icon="@drawable/test_pattern">
|
||||
<activity android:name="RsList"
|
||||
android:label="RsList"
|
||||
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>
|
||||
|
||||
<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>
|
@ -1 +0,0 @@
|
||||
<p>A set of samples that demonstrate how to use various features of the Renderscript APIs.</p>
|
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 307 B |
Before Width: | Height: | Size: 46 KiB |
@ -1,13 +0,0 @@
|
||||
varying vec2 varTex0;
|
||||
|
||||
void main() {
|
||||
vec2 t0 = varTex0.xy;
|
||||
lowp vec4 col0 = texture2D(UNI_Tex0, t0).rgba;
|
||||
lowp vec4 col1 = texture2D(UNI_Tex1, t0*4.0).rgba;
|
||||
lowp vec4 col2 = texture2D(UNI_Tex2, t0).rgba;
|
||||
col0.xyz = col0.xyz*col1.xyz*1.5;
|
||||
col0.xyz = mix(col0.xyz, col2.xyz, col2.w);
|
||||
col0.w = 0.5;
|
||||
gl_FragColor = col0;
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
varying vec3 varWorldPos;
|
||||
varying vec3 varWorldNormal;
|
||||
varying vec2 varTex0;
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 V = normalize(-varWorldPos.xyz);
|
||||
vec3 worldNorm = normalize(varWorldNormal);
|
||||
|
||||
vec3 light0Vec = normalize(UNI_light0_Posision.xyz - varWorldPos);
|
||||
vec3 light0R = -reflect(light0Vec, worldNorm);
|
||||
float light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light0_Diffuse;
|
||||
float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
|
||||
float light0_Specular = pow(light0Spec, UNI_light0_CosinePower) * UNI_light0_Specular;
|
||||
|
||||
vec3 light1Vec = normalize(UNI_light1_Posision.xyz - varWorldPos);
|
||||
vec3 light1R = reflect(light1Vec, worldNorm);
|
||||
float light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light1_Diffuse;
|
||||
float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
|
||||
float light1_Specular = pow(light1Spec, UNI_light1_CosinePower) * UNI_light1_Specular;
|
||||
|
||||
vec2 t0 = varTex0.xy;
|
||||
lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
|
||||
col.xyz = col.xyz * (light0_Diffuse * UNI_light0_DiffuseColor.xyz + light1_Diffuse * UNI_light1_DiffuseColor.xyz);
|
||||
col.xyz += light0_Specular * UNI_light0_SpecularColor.xyz;
|
||||
col.xyz += light1_Specular * UNI_light1_SpecularColor.xyz;
|
||||
gl_FragColor = col;
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
varying vec3 varWorldPos;
|
||||
varying vec3 varWorldNormal;
|
||||
varying vec2 varTex0;
|
||||
|
||||
// This is where actual shader code begins
|
||||
void main() {
|
||||
vec4 objPos = ATTRIB_position;
|
||||
vec3 oldPos = objPos.xyz;
|
||||
objPos.xyz += 0.1*sin(objPos.xyz*2.0 + UNI_time);
|
||||
objPos.xyz += 0.05*sin(objPos.xyz*4.0 + UNI_time*0.5);
|
||||
objPos.xyz += 0.02*sin(objPos.xyz*7.0 + UNI_time*0.75);
|
||||
vec4 worldPos = UNI_model * objPos;
|
||||
gl_Position = UNI_proj * worldPos;
|
||||
|
||||
mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
|
||||
vec3 worldNorm = model3 * (ATTRIB_normal + oldPos - objPos.xyz);
|
||||
|
||||
varWorldPos = worldPos.xyz;
|
||||
varWorldNormal = worldNorm;
|
||||
varTex0 = ATTRIB_texture0;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
varying vec3 varWorldPos;
|
||||
varying vec3 varWorldNormal;
|
||||
varying vec2 varTex0;
|
||||
|
||||
// This is where actual shader code begins
|
||||
void main() {
|
||||
vec4 objPos = ATTRIB_position;
|
||||
vec4 worldPos = UNI_model * objPos;
|
||||
gl_Position = UNI_proj * worldPos;
|
||||
|
||||
mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
|
||||
vec3 worldNorm = model3 * ATTRIB_normal;
|
||||
|
||||
varWorldPos = worldPos.xyz;
|
||||
varWorldNormal = worldNorm;
|
||||
varTex0 = ATTRIB_texture0;
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
|
||||
varying lowp float light0_Diffuse;
|
||||
varying lowp float light0_Specular;
|
||||
varying lowp float light1_Diffuse;
|
||||
varying lowp float light1_Specular;
|
||||
varying vec2 varTex0;
|
||||
|
||||
void main() {
|
||||
vec2 t0 = varTex0.xy;
|
||||
lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
|
||||
col.xyz = col.xyz * (light0_Diffuse * UNI_light_DiffuseColor[0].xyz + light1_Diffuse * UNI_light_DiffuseColor[1].xyz);
|
||||
col.xyz += light0_Specular * UNI_light_SpecularColor[0].xyz;
|
||||
col.xyz += light1_Specular * UNI_light_SpecularColor[1].xyz;
|
||||
gl_FragColor = col;
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
varying float light0_Diffuse;
|
||||
varying float light0_Specular;
|
||||
varying float light1_Diffuse;
|
||||
varying float light1_Specular;
|
||||
varying vec2 varTex0;
|
||||
|
||||
// This is where actual shader code begins
|
||||
void main() {
|
||||
vec4 worldPos = UNI_model[0] * ATTRIB_position;
|
||||
worldPos = UNI_model[1] * worldPos;
|
||||
gl_Position = UNI_proj * worldPos;
|
||||
|
||||
mat4 model0 = UNI_model[0];
|
||||
mat3 model3 = mat3(model0[0].xyz, model0[1].xyz, model0[2].xyz);
|
||||
vec3 worldNorm = model3 * ATTRIB_normal;
|
||||
vec3 V = normalize(-worldPos.xyz);
|
||||
|
||||
vec3 light0Vec = normalize(UNI_light_Posision[0].xyz - worldPos.xyz);
|
||||
vec3 light0R = -reflect(light0Vec, worldNorm);
|
||||
light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light_Diffuse[0];
|
||||
float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
|
||||
light0_Specular = pow(light0Spec, UNI_light_CosinePower[0]) * UNI_light_Specular[0];
|
||||
|
||||
vec3 light1Vec = normalize(UNI_light_Posision[1].xyz - worldPos.xyz);
|
||||
vec3 light1R = reflect(light1Vec, worldNorm);
|
||||
light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light_Diffuse[1];
|
||||
float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
|
||||
light1_Specular = pow(light1Spec, UNI_light_CosinePower[1]) * UNI_light_Specular[1];
|
||||
|
||||
gl_PointSize = 1.0;
|
||||
varTex0 = ATTRIB_texture0;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
|
||||
varying vec3 worldNormal;
|
||||
|
||||
void main() {
|
||||
lowp vec4 col = textureCube(UNI_Tex0, worldNormal);
|
||||
gl_FragColor = col;
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
varying vec3 worldNormal;
|
||||
|
||||
// This is where actual shader code begins
|
||||
void main() {
|
||||
vec4 worldPos = UNI_model * ATTRIB_position;
|
||||
gl_Position = UNI_proj * worldPos;
|
||||
|
||||
mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
|
||||
worldNormal = model3 * ATTRIB_normal;
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
|
||||
varying lowp float light0_Diffuse;
|
||||
varying lowp float light0_Specular;
|
||||
varying lowp float light1_Diffuse;
|
||||
varying lowp float light1_Specular;
|
||||
varying vec2 varTex0;
|
||||
|
||||
void main() {
|
||||
vec2 t0 = varTex0.xy;
|
||||
lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
|
||||
col.xyz = col.xyz * (light0_Diffuse * UNI_light0_DiffuseColor.xyz + light1_Diffuse * UNI_light1_DiffuseColor.xyz);
|
||||
col.xyz += light0_Specular * UNI_light0_SpecularColor.xyz;
|
||||
col.xyz += light1_Specular * UNI_light1_SpecularColor.xyz;
|
||||
gl_FragColor = col;
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
varying float light0_Diffuse;
|
||||
varying float light0_Specular;
|
||||
varying float light1_Diffuse;
|
||||
varying float light1_Specular;
|
||||
varying vec2 varTex0;
|
||||
|
||||
// This is where actual shader code begins
|
||||
void main() {
|
||||
vec4 worldPos = UNI_model * ATTRIB_position;
|
||||
gl_Position = UNI_proj * worldPos;
|
||||
|
||||
mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
|
||||
vec3 worldNorm = model3 * ATTRIB_normal;
|
||||
vec3 V = normalize(-worldPos.xyz);
|
||||
|
||||
vec3 light0Vec = normalize(UNI_light0_Posision.xyz - worldPos.xyz);
|
||||
vec3 light0R = -reflect(light0Vec, worldNorm);
|
||||
light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light0_Diffuse;
|
||||
float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
|
||||
light0_Specular = pow(light0Spec, UNI_light0_CosinePower) * UNI_light0_Specular;
|
||||
|
||||
vec3 light1Vec = normalize(UNI_light1_Posision.xyz - worldPos.xyz);
|
||||
vec3 light1R = reflect(light1Vec, worldNorm);
|
||||
light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light1_Diffuse;
|
||||
float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
|
||||
light1_Specular = pow(light1Spec, UNI_light1_CosinePower) * UNI_light1_Specular;
|
||||
|
||||
gl_PointSize = 1.0;
|
||||
varTex0 = ATTRIB_texture0;
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.rs.miscsamples;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class RsList extends Activity {
|
||||
|
||||
private RsListView 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 RsListView(this);
|
||||
setContentView(mView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity loses focus
|
||||
super.onResume();
|
||||
mView.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity loses focus
|
||||
super.onPause();
|
||||
mView.pause();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.rs.miscsamples;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.Vector;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.ProgramStore.DepthFunc;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class RsListRS {
|
||||
|
||||
private final int STATE_LAST_FOCUS = 1;
|
||||
|
||||
private static final String[] DATA_LIST = {
|
||||
"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
|
||||
"Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
|
||||
"Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
|
||||
"Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
|
||||
"Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
|
||||
"Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
|
||||
"British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria",
|
||||
"Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
|
||||
"Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
|
||||
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
|
||||
"Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
|
||||
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
|
||||
"East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
|
||||
"Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
|
||||
"Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
|
||||
"French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
|
||||
"Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
|
||||
"Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
|
||||
"Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
|
||||
"Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
|
||||
"Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
|
||||
"Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
|
||||
"Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
|
||||
"Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
|
||||
"Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
|
||||
"Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
|
||||
"Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
|
||||
"Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
|
||||
"Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
|
||||
"Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
|
||||
"Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
|
||||
"Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
|
||||
"Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
|
||||
"Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
|
||||
"Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
|
||||
"The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
|
||||
"Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
|
||||
"Ukraine", "United Arab Emirates", "United Kingdom",
|
||||
"United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
|
||||
"Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
|
||||
"Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
|
||||
};
|
||||
|
||||
public RsListRS() {
|
||||
}
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initRS();
|
||||
}
|
||||
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
private Font mItalic;
|
||||
|
||||
ScriptField_ListAllocs_s mListAllocs;
|
||||
|
||||
private ScriptC_rslist mScript;
|
||||
|
||||
int mLastX;
|
||||
int mLastY;
|
||||
|
||||
public void onActionDown(int x, int y) {
|
||||
mScript.set_gDY(0.0f);
|
||||
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
}
|
||||
|
||||
public void onActionMove(int x, int y) {
|
||||
int dx = mLastX - x;
|
||||
int dy = mLastY - y;
|
||||
|
||||
if (Math.abs(dy) <= 2) {
|
||||
dy = 0;
|
||||
}
|
||||
|
||||
mScript.set_gDY(dy);
|
||||
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
|
||||
mScript = new ScriptC_rslist(mRS, mRes, R.raw.rslist);
|
||||
|
||||
mListAllocs = new ScriptField_ListAllocs_s(mRS, DATA_LIST.length);
|
||||
for (int i = 0; i < DATA_LIST.length; i ++) {
|
||||
ScriptField_ListAllocs_s.Item listElem = new ScriptField_ListAllocs_s.Item();
|
||||
listElem.text = Allocation.createFromString(mRS, DATA_LIST[i], Allocation.USAGE_SCRIPT);
|
||||
mListAllocs.set(listElem, i, false);
|
||||
}
|
||||
|
||||
mListAllocs.copyAll();
|
||||
|
||||
mScript.bind_gList(mListAllocs);
|
||||
|
||||
mItalic = Font.create(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
|
||||
mScript.set_gItalic(mItalic);
|
||||
|
||||
mRS.bindRootScript(mScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.rs.miscsamples;
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScriptGL;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class RsListView extends RSSurfaceView {
|
||||
|
||||
public RsListView(Context context) {
|
||||
super(context);
|
||||
ensureRenderScript();
|
||||
}
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private RsListRS mRender;
|
||||
|
||||
private void ensureRenderScript() {
|
||||
if (mRS == null) {
|
||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
||||
mRS = createRenderScriptGL(sc);
|
||||
mRender = new RsListRS();
|
||||
mRender.init(mRS, getResources());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
ensureRenderScript();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
mRender = null;
|
||||
if (mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScriptGL();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev)
|
||||
{
|
||||
boolean ret = false;
|
||||
int act = ev.getAction();
|
||||
if (act == MotionEvent.ACTION_DOWN) {
|
||||
mRender.onActionDown((int)ev.getX(), (int)ev.getY());
|
||||
ret = true;
|
||||
} else if (act == MotionEvent.ACTION_MOVE) {
|
||||
mRender.onActionMove((int)ev.getX(), (int)ev.getY());
|
||||
ret = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.rs.miscsamples;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
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.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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,422 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.rs.miscsamples;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.Font.Style;
|
||||
import android.renderscript.Program.TextureType;
|
||||
import android.renderscript.ProgramStore.DepthFunc;
|
||||
import android.renderscript.ProgramStore.BlendSrcFunc;
|
||||
import android.renderscript.ProgramStore.BlendDstFunc;
|
||||
import android.renderscript.Sampler.Value;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class RsRenderStatesRS {
|
||||
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
|
||||
public RsRenderStatesRS() {
|
||||
}
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mWidth = mRS.getWidth();
|
||||
mHeight = mRS.getHeight();
|
||||
mRes = res;
|
||||
mOptionsARGB.inScaled = false;
|
||||
mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
mMode = 0;
|
||||
mMaxModes = 0;
|
||||
initRS();
|
||||
}
|
||||
|
||||
public void surfaceChanged() {
|
||||
mWidth = mRS.getWidth();
|
||||
mHeight = mRS.getHeight();
|
||||
|
||||
Matrix4f proj = new Matrix4f();
|
||||
proj.loadOrthoWindow(mWidth, mHeight);
|
||||
mPVA.setProjection(proj);
|
||||
}
|
||||
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
|
||||
private Sampler mLinearClamp;
|
||||
private Sampler mLinearWrap;
|
||||
private Sampler mMipLinearWrap;
|
||||
private Sampler mNearestClamp;
|
||||
private Sampler mMipLinearAniso8;
|
||||
private Sampler mMipLinearAniso15;
|
||||
|
||||
private ProgramStore mProgStoreBlendNoneDepth;
|
||||
private ProgramStore mProgStoreBlendNone;
|
||||
private ProgramStore mProgStoreBlendAlpha;
|
||||
private ProgramStore mProgStoreBlendAdd;
|
||||
|
||||
private ProgramFragment mProgFragmentTexture;
|
||||
private ProgramFragment mProgFragmentColor;
|
||||
|
||||
private ProgramVertex mProgVertex;
|
||||
private ProgramVertexFixedFunction.Constants mPVA;
|
||||
|
||||
// Custom shaders
|
||||
private ProgramVertex mProgVertexCustom;
|
||||
private ProgramFragment mProgFragmentCustom;
|
||||
private ProgramFragment mProgFragmentMultitex;
|
||||
private ScriptField_VertexShaderConstants_s mVSConst;
|
||||
private ScriptField_VertexShaderConstants2_s mVSConst2;
|
||||
private ScriptField_FragentShaderConstants_s mFSConst;
|
||||
private ScriptField_FragentShaderConstants2_s mFSConst2;
|
||||
|
||||
private ProgramVertex mProgVertexCustom2;
|
||||
private ProgramFragment mProgFragmentCustom2;
|
||||
|
||||
private ProgramVertex mProgVertexCube;
|
||||
private ProgramFragment mProgFragmentCube;
|
||||
|
||||
private ProgramRaster mCullBack;
|
||||
private ProgramRaster mCullFront;
|
||||
private ProgramRaster mCullNone;
|
||||
|
||||
private Allocation mTexTorus;
|
||||
private Allocation mTexOpaque;
|
||||
private Allocation mTexTransparent;
|
||||
private Allocation mTexChecker;
|
||||
private Allocation mTexCube;
|
||||
|
||||
private Mesh mMbyNMesh;
|
||||
private Mesh mTorus;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) {
|
||||
ProgramStore.Builder builder = new ProgramStore.Builder(rs);
|
||||
builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
|
||||
builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
|
||||
builder.setDitherEnabled(false);
|
||||
builder.setDepthMaskEnabled(false);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private Mesh getMbyNMesh(float width, float height, int wResolution, int hResolution) {
|
||||
|
||||
Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS,
|
||||
2, Mesh.TriangleMeshBuilder.TEXTURE_0);
|
||||
|
||||
for (int y = 0; y <= hResolution; y++) {
|
||||
final float normalizedY = (float)y / hResolution;
|
||||
final float yOffset = (normalizedY - 0.5f) * height;
|
||||
for (int x = 0; x <= wResolution; x++) {
|
||||
float normalizedX = (float)x / wResolution;
|
||||
float xOffset = (normalizedX - 0.5f) * width;
|
||||
tmb.setTexture(normalizedX, normalizedY);
|
||||
tmb.addVertex(xOffset, yOffset);
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < hResolution; y++) {
|
||||
final int curY = y * (wResolution + 1);
|
||||
final int belowY = (y + 1) * (wResolution + 1);
|
||||
for (int x = 0; x < wResolution; x++) {
|
||||
int curV = curY + x;
|
||||
int belowV = belowY + x;
|
||||
tmb.addTriangle(curV, belowV, curV + 1);
|
||||
tmb.addTriangle(belowV, belowV + 1, curV + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return tmb.create(true);
|
||||
}
|
||||
|
||||
private void initProgramStore() {
|
||||
// Use stock the stock program store object
|
||||
mProgStoreBlendNoneDepth = ProgramStore.BLEND_NONE_DEPTH_TEST(mRS);
|
||||
mProgStoreBlendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(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.setDitherEnabled(false);
|
||||
builder.setDepthMaskEnabled(false);
|
||||
mProgStoreBlendAlpha = builder.create();
|
||||
|
||||
mProgStoreBlendAdd = BLEND_ADD_DEPTH_NONE(mRS);
|
||||
|
||||
mScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth);
|
||||
mScript.set_gProgStoreBlendNone(mProgStoreBlendNone);
|
||||
mScript.set_gProgStoreBlendAlpha(mProgStoreBlendAlpha);
|
||||
mScript.set_gProgStoreBlendAdd(mProgStoreBlendAdd);
|
||||
}
|
||||
|
||||
private void initProgramFragment() {
|
||||
|
||||
ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
|
||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
||||
mProgFragmentTexture = texBuilder.create();
|
||||
mProgFragmentTexture.bindSampler(mLinearClamp, 0);
|
||||
|
||||
ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
colBuilder.setVaryingColor(false);
|
||||
mProgFragmentColor = colBuilder.create();
|
||||
|
||||
mScript.set_gProgFragmentColor(mProgFragmentColor);
|
||||
mScript.set_gProgFragmentTexture(mProgFragmentTexture);
|
||||
}
|
||||
|
||||
private void initProgramVertex() {
|
||||
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
|
||||
mProgVertex = pvb.create();
|
||||
|
||||
mPVA = new ProgramVertexFixedFunction.Constants(mRS);
|
||||
((ProgramVertexFixedFunction)mProgVertex).bindConstants(mPVA);
|
||||
Matrix4f proj = new Matrix4f();
|
||||
proj.loadOrthoWindow(mWidth, mHeight);
|
||||
mPVA.setProjection(proj);
|
||||
|
||||
mScript.set_gProgVertex(mProgVertex);
|
||||
}
|
||||
|
||||
private void initCustomShaders() {
|
||||
mVSConst = new ScriptField_VertexShaderConstants_s(mRS, 1);
|
||||
mVSConst2 = new ScriptField_VertexShaderConstants2_s(mRS, 1);
|
||||
mFSConst = new ScriptField_FragentShaderConstants_s(mRS, 1);
|
||||
mFSConst2 = new ScriptField_FragentShaderConstants2_s(mRS, 1);
|
||||
|
||||
mScript.bind_gVSConstants(mVSConst);
|
||||
mScript.bind_gVSConstants2(mVSConst2);
|
||||
mScript.bind_gFSConstants(mFSConst);
|
||||
mScript.bind_gFSConstants2(mFSConst2);
|
||||
|
||||
// Initialize the shader builder
|
||||
ProgramVertex.Builder pvbCustom = new ProgramVertex.Builder(mRS);
|
||||
// Specify the resource that contains the shader string
|
||||
pvbCustom.setShader(mRes, R.raw.shaderv);
|
||||
// Use a script field to spcify the input layout
|
||||
pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
|
||||
// Define the constant input layout
|
||||
pvbCustom.addConstant(mVSConst.getAllocation().getType());
|
||||
mProgVertexCustom = pvbCustom.create();
|
||||
// Bind the source of constant data
|
||||
mProgVertexCustom.bindConstants(mVSConst.getAllocation(), 0);
|
||||
|
||||
ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
// Specify the resource that contains the shader string
|
||||
pfbCustom.setShader(mRes, R.raw.shaderf);
|
||||
//Tell the builder how many textures we have
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
|
||||
// Define the constant input layout
|
||||
pfbCustom.addConstant(mFSConst.getAllocation().getType());
|
||||
mProgFragmentCustom = pfbCustom.create();
|
||||
// Bind the source of constant data
|
||||
mProgFragmentCustom.bindConstants(mFSConst.getAllocation(), 0);
|
||||
|
||||
pvbCustom = new ProgramVertex.Builder(mRS);
|
||||
pvbCustom.setShader(mRes, R.raw.shaderarrayv);
|
||||
pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
|
||||
pvbCustom.addConstant(mVSConst2.getAllocation().getType());
|
||||
mProgVertexCustom2 = pvbCustom.create();
|
||||
mProgVertexCustom2.bindConstants(mVSConst2.getAllocation(), 0);
|
||||
|
||||
pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
pfbCustom.setShader(mRes, R.raw.shaderarrayf);
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
|
||||
pfbCustom.addConstant(mFSConst2.getAllocation().getType());
|
||||
mProgFragmentCustom2 = pfbCustom.create();
|
||||
mProgFragmentCustom2.bindConstants(mFSConst2.getAllocation(), 0);
|
||||
|
||||
// Cubemap test shaders
|
||||
pvbCustom = new ProgramVertex.Builder(mRS);
|
||||
pvbCustom.setShader(mRes, R.raw.shadercubev);
|
||||
pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
|
||||
pvbCustom.addConstant(mVSConst.getAllocation().getType());
|
||||
mProgVertexCube = pvbCustom.create();
|
||||
mProgVertexCube.bindConstants(mVSConst.getAllocation(), 0);
|
||||
|
||||
pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
pfbCustom.setShader(mRes, R.raw.shadercubef);
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_CUBE);
|
||||
mProgFragmentCube = pfbCustom.create();
|
||||
|
||||
pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
pfbCustom.setShader(mRes, R.raw.multitexf);
|
||||
for (int texCount = 0; texCount < 3; texCount ++) {
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
|
||||
}
|
||||
mProgFragmentMultitex = pfbCustom.create();
|
||||
|
||||
mScript.set_gProgVertexCustom(mProgVertexCustom);
|
||||
mScript.set_gProgFragmentCustom(mProgFragmentCustom);
|
||||
mScript.set_gProgVertexCustom2(mProgVertexCustom2);
|
||||
mScript.set_gProgFragmentCustom2(mProgFragmentCustom2);
|
||||
mScript.set_gProgVertexCube(mProgVertexCube);
|
||||
mScript.set_gProgFragmentCube(mProgFragmentCube);
|
||||
mScript.set_gProgFragmentMultitex(mProgFragmentMultitex);
|
||||
}
|
||||
|
||||
private Allocation loadTextureRGB(int id) {
|
||||
return Allocation.createFromBitmapResource(mRS, mRes, id,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
}
|
||||
|
||||
private Allocation loadTextureARGB(int id) {
|
||||
Bitmap b = BitmapFactory.decodeResource(mRes, id, mOptionsARGB);
|
||||
return Allocation.createFromBitmap(mRS, b,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
}
|
||||
|
||||
private void loadImages() {
|
||||
mTexTorus = loadTextureRGB(R.drawable.torusmap);
|
||||
mTexOpaque = loadTextureRGB(R.drawable.data);
|
||||
mTexTransparent = loadTextureARGB(R.drawable.leaf);
|
||||
mTexChecker = loadTextureRGB(R.drawable.checker);
|
||||
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.cubemap_test);
|
||||
mTexCube = Allocation.createCubemapFromBitmap(mRS, b);
|
||||
|
||||
mScript.set_gTexTorus(mTexTorus);
|
||||
mScript.set_gTexOpaque(mTexOpaque);
|
||||
mScript.set_gTexTransparent(mTexTransparent);
|
||||
mScript.set_gTexChecker(mTexChecker);
|
||||
mScript.set_gTexCube(mTexCube);
|
||||
}
|
||||
|
||||
private void initFonts() {
|
||||
// Sans font by family name
|
||||
mFontSans = Font.create(mRS, mRes, "sans-serif", Font.Style.NORMAL, 8);
|
||||
mFontSerif = Font.create(mRS, mRes, "serif", Font.Style.NORMAL, 8);
|
||||
// Create fonts by family and style
|
||||
mFontSerifBold = Font.create(mRS, mRes, "serif", Font.Style.BOLD, 8);
|
||||
mFontSerifItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
|
||||
mFontSerifBoldItalic = Font.create(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
|
||||
mFontMono = Font.create(mRS, mRes, "mono", Font.Style.NORMAL, 8);
|
||||
|
||||
mTextAlloc = Allocation.createFromString(mRS, "String from allocation", Allocation.USAGE_SCRIPT);
|
||||
|
||||
mScript.set_gFontSans(mFontSans);
|
||||
mScript.set_gFontSerif(mFontSerif);
|
||||
mScript.set_gFontSerifBold(mFontSerifBold);
|
||||
mScript.set_gFontSerifItalic(mFontSerifItalic);
|
||||
mScript.set_gFontSerifBoldItalic(mFontSerifBoldItalic);
|
||||
mScript.set_gFontMono(mFontMono);
|
||||
mScript.set_gTextAlloc(mTextAlloc);
|
||||
}
|
||||
|
||||
private void initMesh() {
|
||||
mMbyNMesh = getMbyNMesh(256, 256, 10, 10);
|
||||
mScript.set_gMbyNMesh(mMbyNMesh);
|
||||
|
||||
FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus);
|
||||
FileA3D.IndexEntry entry = model.getIndexEntry(0);
|
||||
if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) {
|
||||
Log.e("rs", "could not load model");
|
||||
} else {
|
||||
mTorus = (Mesh)entry.getObject();
|
||||
mScript.set_gTorusMesh(mTorus);
|
||||
}
|
||||
}
|
||||
|
||||
private void initSamplers() {
|
||||
Sampler.Builder bs = new Sampler.Builder(mRS);
|
||||
bs.setMinification(Sampler.Value.LINEAR);
|
||||
bs.setMagnification(Sampler.Value.LINEAR);
|
||||
bs.setWrapS(Sampler.Value.WRAP);
|
||||
bs.setWrapT(Sampler.Value.WRAP);
|
||||
mLinearWrap = bs.create();
|
||||
|
||||
mLinearClamp = Sampler.CLAMP_LINEAR(mRS);
|
||||
mNearestClamp = Sampler.CLAMP_NEAREST(mRS);
|
||||
mMipLinearWrap = Sampler.WRAP_LINEAR_MIP_LINEAR(mRS);
|
||||
|
||||
bs = new Sampler.Builder(mRS);
|
||||
bs.setMinification(Sampler.Value.LINEAR_MIP_LINEAR);
|
||||
bs.setMagnification(Sampler.Value.LINEAR);
|
||||
bs.setWrapS(Sampler.Value.WRAP);
|
||||
bs.setWrapT(Sampler.Value.WRAP);
|
||||
bs.setAnisotropy(8.0f);
|
||||
mMipLinearAniso8 = bs.create();
|
||||
bs.setAnisotropy(15.0f);
|
||||
mMipLinearAniso15 = bs.create();
|
||||
|
||||
mScript.set_gLinearClamp(mLinearClamp);
|
||||
mScript.set_gLinearWrap(mLinearWrap);
|
||||
mScript.set_gMipLinearWrap(mMipLinearWrap);
|
||||
mScript.set_gMipLinearAniso8(mMipLinearAniso8);
|
||||
mScript.set_gMipLinearAniso15(mMipLinearAniso15);
|
||||
mScript.set_gNearestClamp(mNearestClamp);
|
||||
}
|
||||
|
||||
private void initProgramRaster() {
|
||||
mCullBack = ProgramRaster.CULL_BACK(mRS);
|
||||
mCullFront = ProgramRaster.CULL_FRONT(mRS);
|
||||
mCullNone = ProgramRaster.CULL_NONE(mRS);
|
||||
|
||||
mScript.set_gCullBack(mCullBack);
|
||||
mScript.set_gCullFront(mCullFront);
|
||||
mScript.set_gCullNone(mCullNone);
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
|
||||
mScript = new ScriptC_rsrenderstates(mRS, mRes, R.raw.rsrenderstates);
|
||||
|
||||
mMaxModes = mScript.get_gMaxModes();
|
||||
|
||||
initSamplers();
|
||||
initProgramStore();
|
||||
initProgramFragment();
|
||||
initProgramVertex();
|
||||
initFonts();
|
||||
loadImages();
|
||||
initMesh();
|
||||
initProgramRaster();
|
||||
initCustomShaders();
|
||||
|
||||
mRS.bindRootScript(mScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.rs.miscsamples;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScriptGL;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
public class RsRenderStatesView extends RSSurfaceView {
|
||||
|
||||
public RsRenderStatesView(Context context) {
|
||||
super(context);
|
||||
ensureRenderScript();
|
||||
}
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private RsRenderStatesRS mRender;
|
||||
|
||||
private void ensureRenderScript() {
|
||||
if (mRS == null) {
|
||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
||||
sc.setDepth(16, 24);
|
||||
mRS = createRenderScriptGL(sc);
|
||||
mRender = new RsRenderStatesRS();
|
||||
mRender.init(mRS, getResources());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
ensureRenderScript();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
super.surfaceChanged(holder, format, w, h);
|
||||
mRender.surfaceChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
mRender = null;
|
||||
if (mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScriptGL();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
mRender.onActionDown((int)ev.getX(), (int)ev.getY());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,70 +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.example.android.rs.miscsamples)
|
||||
|
||||
#include "rs_graphics.rsh"
|
||||
|
||||
float gDY;
|
||||
|
||||
rs_font gItalic;
|
||||
|
||||
typedef struct ListAllocs_s {
|
||||
rs_allocation text;
|
||||
} ListAllocs;
|
||||
|
||||
ListAllocs *gList;
|
||||
|
||||
void init() {
|
||||
gDY = 0.0f;
|
||||
}
|
||||
|
||||
int textPos = 0;
|
||||
|
||||
int root(void) {
|
||||
|
||||
rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
textPos -= (int)gDY*2;
|
||||
gDY *= 0.95;
|
||||
|
||||
rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
|
||||
rsgBindFont(gItalic);
|
||||
|
||||
rs_allocation listAlloc;
|
||||
listAlloc = rsGetAllocation(gList);
|
||||
int allocSize = rsAllocationGetDimX(listAlloc);
|
||||
|
||||
int width = rsgGetWidth();
|
||||
int height = rsgGetHeight();
|
||||
|
||||
int itemHeight = 80;
|
||||
int currentYPos = itemHeight + textPos;
|
||||
|
||||
for (int i = 0; i < allocSize; i ++) {
|
||||
if (currentYPos - itemHeight > height) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentYPos > 0) {
|
||||
rsgDrawRect(0, currentYPos - 1, width, currentYPos, 0);
|
||||
rsgDrawText(gList[i].text, 30, currentYPos - 32);
|
||||
}
|
||||
currentYPos += itemHeight;
|
||||
}
|
||||
|
||||
return 10;
|
||||
}
|
@ -1,680 +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.example.android.rs.miscsamples)
|
||||
|
||||
#include "rs_graphics.rsh"
|
||||
#include "shader_def.rsh"
|
||||
|
||||
const int gMaxModes = 11;
|
||||
|
||||
rs_program_vertex gProgVertex;
|
||||
rs_program_fragment gProgFragmentColor;
|
||||
rs_program_fragment gProgFragmentTexture;
|
||||
|
||||
rs_program_store gProgStoreBlendNoneDepth;
|
||||
rs_program_store gProgStoreBlendNone;
|
||||
rs_program_store gProgStoreBlendAlpha;
|
||||
rs_program_store gProgStoreBlendAdd;
|
||||
|
||||
rs_allocation gTexOpaque;
|
||||
rs_allocation gTexTorus;
|
||||
rs_allocation gTexTransparent;
|
||||
rs_allocation gTexChecker;
|
||||
rs_allocation gTexCube;
|
||||
|
||||
rs_mesh gMbyNMesh;
|
||||
rs_mesh gTorusMesh;
|
||||
|
||||
rs_font gFontSans;
|
||||
rs_font gFontSerif;
|
||||
rs_font gFontSerifBold;
|
||||
rs_font gFontSerifItalic;
|
||||
rs_font gFontSerifBoldItalic;
|
||||
rs_font gFontMono;
|
||||
rs_allocation gTextAlloc;
|
||||
|
||||
int gDisplayMode;
|
||||
|
||||
rs_sampler gLinearClamp;
|
||||
rs_sampler gLinearWrap;
|
||||
rs_sampler gMipLinearWrap;
|
||||
rs_sampler gMipLinearAniso8;
|
||||
rs_sampler gMipLinearAniso15;
|
||||
rs_sampler gNearestClamp;
|
||||
|
||||
rs_program_raster gCullBack;
|
||||
rs_program_raster gCullFront;
|
||||
rs_program_raster gCullNone;
|
||||
|
||||
// Custom vertex shader compunents
|
||||
VertexShaderConstants *gVSConstants;
|
||||
VertexShaderConstants2 *gVSConstants2;
|
||||
FragentShaderConstants *gFSConstants;
|
||||
FragentShaderConstants2 *gFSConstants2;
|
||||
// Export these out to easily set the inputs to shader
|
||||
VertexShaderInputs *gVSInputs;
|
||||
// Custom shaders we use for lighting
|
||||
rs_program_vertex gProgVertexCustom;
|
||||
rs_program_fragment gProgFragmentCustom;
|
||||
rs_program_vertex gProgVertexCustom2;
|
||||
rs_program_fragment gProgFragmentCustom2;
|
||||
rs_program_vertex gProgVertexCube;
|
||||
rs_program_fragment gProgFragmentCube;
|
||||
rs_program_fragment gProgFragmentMultitex;
|
||||
|
||||
float gDt = 0;
|
||||
|
||||
void init() {
|
||||
}
|
||||
|
||||
static void displayFontSamples() {
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
int yPos = 100;
|
||||
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);
|
||||
yPos += 50;
|
||||
|
||||
// Now use text metrics to center the text
|
||||
uint width = rsgGetWidth();
|
||||
uint height = rsgGetHeight();
|
||||
int left = 0, right = 0, top = 0, bottom = 0;
|
||||
|
||||
rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f);
|
||||
rsgBindFont(gFontSerifBoldItalic);
|
||||
|
||||
rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
|
||||
int centeredPos = width / 2 - (right - left) / 2;
|
||||
rsgDrawText(gTextAlloc, centeredPos, yPos);
|
||||
yPos += 30;
|
||||
|
||||
const char* text = "Centered Text Sample";
|
||||
rsgMeasureText(text, &left, &right, &top, &bottom);
|
||||
centeredPos = width / 2 - (right - left) / 2;
|
||||
rsgDrawText(text, centeredPos, yPos);
|
||||
yPos += 30;
|
||||
|
||||
rsgBindFont(gFontSans);
|
||||
text = "More Centered Text Samples";
|
||||
rsgMeasureText(text, &left, &right, &top, &bottom);
|
||||
centeredPos = width / 2 - (right - left) / 2;
|
||||
rsgDrawText(text, centeredPos, yPos);
|
||||
yPos += 30;
|
||||
|
||||
// Now draw bottom and top right aligned text
|
||||
text = "Top-right aligned text";
|
||||
rsgMeasureText(text, &left, &right, &top, &bottom);
|
||||
rsgDrawText(text, width - right, top);
|
||||
|
||||
text = "Top-left";
|
||||
rsgMeasureText(text, &left, &right, &top, &bottom);
|
||||
rsgDrawText(text, -left, top);
|
||||
|
||||
text = "Bottom-right aligned text";
|
||||
rsgMeasureText(text, &left, &right, &top, &bottom);
|
||||
rsgDrawText(text, width - right, height + bottom);
|
||||
|
||||
}
|
||||
|
||||
static void bindProgramVertexOrtho() {
|
||||
// Default vertex sahder
|
||||
rsgBindProgramVertex(gProgVertex);
|
||||
// Setup the projectioni matrix
|
||||
rs_matrix4x4 proj;
|
||||
rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
|
||||
rsgProgramVertexLoadProjectionMatrix(&proj);
|
||||
}
|
||||
|
||||
static void displayShaderSamples() {
|
||||
bindProgramVertexOrtho();
|
||||
rs_matrix4x4 matrix;
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
// Fragment shader with texture
|
||||
rsgBindProgramStore(gProgStoreBlendNone);
|
||||
rsgBindProgramFragment(gProgFragmentTexture);
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
|
||||
rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
|
||||
|
||||
float startX = 0, startY = 0;
|
||||
float width = 256, height = 256;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
|
||||
startX, startY + height, 0, 0, 1,
|
||||
startX + width, startY + height, 0, 1, 1,
|
||||
startX + width, startY, 0, 1, 0);
|
||||
|
||||
startX = 200; startY = 0;
|
||||
width = 128; height = 128;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
|
||||
startX, startY + height, 0, 0, 1,
|
||||
startX + width, startY + height, 0, 1, 1,
|
||||
startX + width, startY, 0, 1, 0);
|
||||
|
||||
rsgBindProgramStore(gProgStoreBlendAlpha);
|
||||
rsgBindTexture(gProgFragmentTexture, 0, gTexTransparent);
|
||||
startX = 0; startY = 200;
|
||||
width = 128; height = 128;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
|
||||
startX, startY + height, 0, 0, 1,
|
||||
startX + width, startY + height, 0, 1, 1,
|
||||
startX + width, startY, 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);
|
||||
}
|
||||
|
||||
static void displayBlendingSamples() {
|
||||
int i;
|
||||
|
||||
bindProgramVertexOrtho();
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
static void displayMeshSamples() {
|
||||
|
||||
bindProgramVertexOrtho();
|
||||
rs_matrix4x4 matrix;
|
||||
rsMatrixLoadTranslate(&matrix, 128, 128, 0);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
// Fragment shader with texture
|
||||
rsgBindProgramStore(gProgStoreBlendNone);
|
||||
rsgBindProgramFragment(gProgFragmentTexture);
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
|
||||
rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
|
||||
|
||||
rsgDrawMesh(gMbyNMesh);
|
||||
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgBindFont(gFontMono);
|
||||
rsgDrawText("User gen 10 by 10 grid mesh", 10, 250);
|
||||
}
|
||||
|
||||
static void displayTextureSamplers() {
|
||||
|
||||
bindProgramVertexOrtho();
|
||||
rs_matrix4x4 matrix;
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
// Fragment shader with texture
|
||||
rsgBindProgramStore(gProgStoreBlendNone);
|
||||
rsgBindProgramFragment(gProgFragmentTexture);
|
||||
rsgBindTexture(gProgFragmentTexture, 0, gTexOpaque);
|
||||
|
||||
// Linear clamp
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
|
||||
float startX = 0, startY = 0;
|
||||
float width = 300, height = 300;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
|
||||
startX, startY + height, 0, 0, 1.1,
|
||||
startX + width, startY + height, 0, 1.1, 1.1,
|
||||
startX + width, startY, 0, 1.1, 0);
|
||||
|
||||
// Linear Wrap
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gLinearWrap);
|
||||
startX = 0; startY = 300;
|
||||
width = 300; height = 300;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
|
||||
startX, startY + height, 0, 0, 1.1,
|
||||
startX + width, startY + height, 0, 1.1, 1.1,
|
||||
startX + width, startY, 0, 1.1, 0);
|
||||
|
||||
// Nearest
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gNearestClamp);
|
||||
startX = 300; startY = 0;
|
||||
width = 300; height = 300;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
|
||||
startX, startY + height, 0, 0, 1.1,
|
||||
startX + width, startY + height, 0, 1.1, 1.1,
|
||||
startX + width, startY, 0, 1.1, 0);
|
||||
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gMipLinearWrap);
|
||||
startX = 300; startY = 300;
|
||||
width = 300; height = 300;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
|
||||
startX, startY + height, 0, 0, 1.5,
|
||||
startX + width, startY + height, 0, 1.5, 1.5,
|
||||
startX + width, startY, 0, 1.5, 0);
|
||||
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgBindFont(gFontMono);
|
||||
rsgDrawText("Filtering: linear clamp", 10, 290);
|
||||
rsgDrawText("Filtering: linear wrap", 10, 590);
|
||||
rsgDrawText("Filtering: nearest clamp", 310, 290);
|
||||
rsgDrawText("Filtering: miplinear wrap", 310, 590);
|
||||
}
|
||||
|
||||
static float gTorusRotation = 0;
|
||||
|
||||
static void displayCullingSamples() {
|
||||
rsgBindProgramVertex(gProgVertex);
|
||||
// Setup the projectioni matrix with 60 degree field of view
|
||||
rs_matrix4x4 proj;
|
||||
float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
|
||||
rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
|
||||
rsgProgramVertexLoadProjectionMatrix(&proj);
|
||||
|
||||
// Fragment shader with texture
|
||||
rsgBindProgramStore(gProgStoreBlendNoneDepth);
|
||||
rsgBindProgramFragment(gProgFragmentTexture);
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
|
||||
rsgBindTexture(gProgFragmentTexture, 0, gTexTorus);
|
||||
|
||||
// Aplly a rotation to our mesh
|
||||
gTorusRotation += 50.0f * gDt;
|
||||
if (gTorusRotation > 360.0f) {
|
||||
gTorusRotation -= 360.0f;
|
||||
}
|
||||
|
||||
rs_matrix4x4 matrix;
|
||||
// Position our model on the screen
|
||||
rsMatrixLoadTranslate(&matrix, -2.0f, 0.0f, -10.0f);
|
||||
rsMatrixRotate(&matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
// Use front face culling
|
||||
rsgBindProgramRaster(gCullFront);
|
||||
rsgDrawMesh(gTorusMesh);
|
||||
|
||||
rsMatrixLoadTranslate(&matrix, 2.0f, 0.0f, -10.0f);
|
||||
rsMatrixRotate(&matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
// Use back face culling
|
||||
rsgBindProgramRaster(gCullBack);
|
||||
rsgDrawMesh(gTorusMesh);
|
||||
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgBindFont(gFontMono);
|
||||
rsgDrawText("Displaying mesh front/back face culling", 10, rsgGetHeight() - 10);
|
||||
}
|
||||
|
||||
static float gLight0Rotation = 0;
|
||||
static float gLight1Rotation = 0;
|
||||
|
||||
static void setupCustomShaderLights() {
|
||||
float4 light0Pos = {-5.0f, 5.0f, -10.0f, 1.0f};
|
||||
float4 light1Pos = {2.0f, 5.0f, 15.0f, 1.0f};
|
||||
float4 light0DiffCol = {0.9f, 0.7f, 0.7f, 1.0f};
|
||||
float4 light0SpecCol = {0.9f, 0.6f, 0.6f, 1.0f};
|
||||
float4 light1DiffCol = {0.5f, 0.5f, 0.9f, 1.0f};
|
||||
float4 light1SpecCol = {0.5f, 0.5f, 0.9f, 1.0f};
|
||||
|
||||
gLight0Rotation += 50.0f * gDt;
|
||||
if (gLight0Rotation > 360.0f) {
|
||||
gLight0Rotation -= 360.0f;
|
||||
}
|
||||
gLight1Rotation -= 50.0f * gDt;
|
||||
if (gLight1Rotation > 360.0f) {
|
||||
gLight1Rotation -= 360.0f;
|
||||
}
|
||||
|
||||
rs_matrix4x4 l0Mat;
|
||||
rsMatrixLoadRotate(&l0Mat, gLight0Rotation, 1.0f, 0.0f, 0.0f);
|
||||
light0Pos = rsMatrixMultiply(&l0Mat, light0Pos);
|
||||
rs_matrix4x4 l1Mat;
|
||||
rsMatrixLoadRotate(&l1Mat, gLight1Rotation, 0.0f, 0.0f, 1.0f);
|
||||
light1Pos = rsMatrixMultiply(&l1Mat, light1Pos);
|
||||
|
||||
// Set light 0 properties
|
||||
gVSConstants->light0_Posision = light0Pos;
|
||||
gVSConstants->light0_Diffuse = 1.0f;
|
||||
gVSConstants->light0_Specular = 0.5f;
|
||||
gVSConstants->light0_CosinePower = 10.0f;
|
||||
// Set light 1 properties
|
||||
gVSConstants->light1_Posision = light1Pos;
|
||||
gVSConstants->light1_Diffuse = 1.0f;
|
||||
gVSConstants->light1_Specular = 0.7f;
|
||||
gVSConstants->light1_CosinePower = 25.0f;
|
||||
rsgAllocationSyncAll(rsGetAllocation(gVSConstants));
|
||||
|
||||
gVSConstants2->light_Posision[0] = light0Pos;
|
||||
gVSConstants2->light_Diffuse[0] = 1.0f;
|
||||
gVSConstants2->light_Specular[0] = 0.5f;
|
||||
gVSConstants2->light_CosinePower[0] = 10.0f;
|
||||
gVSConstants2->light_Posision[1] = light1Pos;
|
||||
gVSConstants2->light_Diffuse[1] = 1.0f;
|
||||
gVSConstants2->light_Specular[1] = 0.7f;
|
||||
gVSConstants2->light_CosinePower[1] = 25.0f;
|
||||
rsgAllocationSyncAll(rsGetAllocation(gVSConstants2));
|
||||
|
||||
// Update fragmetn shader constants
|
||||
// Set light 0 colors
|
||||
gFSConstants->light0_DiffuseColor = light0DiffCol;
|
||||
gFSConstants->light0_SpecularColor = light0SpecCol;
|
||||
// Set light 1 colors
|
||||
gFSConstants->light1_DiffuseColor = light1DiffCol;
|
||||
gFSConstants->light1_SpecularColor = light1SpecCol;
|
||||
rsgAllocationSyncAll(rsGetAllocation(gFSConstants));
|
||||
|
||||
gFSConstants2->light_DiffuseColor[0] = light0DiffCol;
|
||||
gFSConstants2->light_SpecularColor[0] = light0SpecCol;
|
||||
// Set light 1 colors
|
||||
gFSConstants2->light_DiffuseColor[1] = light1DiffCol;
|
||||
gFSConstants2->light_SpecularColor[1] = light1SpecCol;
|
||||
rsgAllocationSyncAll(rsGetAllocation(gFSConstants2));
|
||||
}
|
||||
|
||||
static void displayCustomShaderSamples() {
|
||||
|
||||
// Update vertex shader constants
|
||||
// Load model matrix
|
||||
// Aplly a rotation to our mesh
|
||||
gTorusRotation += 50.0f * gDt;
|
||||
if (gTorusRotation > 360.0f) {
|
||||
gTorusRotation -= 360.0f;
|
||||
}
|
||||
|
||||
// Position our model on the screen
|
||||
rsMatrixLoadTranslate(&gVSConstants->model, 0.0f, 0.0f, -10.0f);
|
||||
rsMatrixRotate(&gVSConstants->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
|
||||
rsMatrixRotate(&gVSConstants->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
|
||||
// Setup the projectioni matrix
|
||||
float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
|
||||
rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f);
|
||||
setupCustomShaderLights();
|
||||
|
||||
rsgBindProgramVertex(gProgVertexCustom);
|
||||
|
||||
// Fragment shader with texture
|
||||
rsgBindProgramStore(gProgStoreBlendNoneDepth);
|
||||
rsgBindProgramFragment(gProgFragmentCustom);
|
||||
rsgBindSampler(gProgFragmentCustom, 0, gLinearClamp);
|
||||
rsgBindTexture(gProgFragmentCustom, 0, gTexTorus);
|
||||
|
||||
// Use back face culling
|
||||
rsgBindProgramRaster(gCullBack);
|
||||
rsgDrawMesh(gTorusMesh);
|
||||
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgBindFont(gFontMono);
|
||||
rsgDrawText("Custom shader sample", 10, rsgGetHeight() - 10);
|
||||
}
|
||||
|
||||
static void displayCustomShaderSamples2() {
|
||||
|
||||
// Update vertex shader constants
|
||||
// Load model matrix
|
||||
// Aplly a rotation to our mesh
|
||||
gTorusRotation += 50.0f * gDt;
|
||||
if (gTorusRotation > 360.0f) {
|
||||
gTorusRotation -= 360.0f;
|
||||
}
|
||||
|
||||
// Position our model on the screen
|
||||
rsMatrixLoadTranslate(&gVSConstants2->model[1], 0.0f, 0.0f, -10.0f);
|
||||
rsMatrixLoadIdentity(&gVSConstants2->model[0]);
|
||||
rsMatrixRotate(&gVSConstants2->model[0], gTorusRotation, 1.0f, 0.0f, 0.0f);
|
||||
rsMatrixRotate(&gVSConstants2->model[0], gTorusRotation, 0.0f, 0.0f, 1.0f);
|
||||
// Setup the projectioni matrix
|
||||
float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
|
||||
rsMatrixLoadPerspective(&gVSConstants2->proj, 30.0f, aspect, 0.1f, 100.0f);
|
||||
setupCustomShaderLights();
|
||||
|
||||
rsgBindProgramVertex(gProgVertexCustom2);
|
||||
|
||||
// Fragment shader with texture
|
||||
rsgBindProgramStore(gProgStoreBlendNoneDepth);
|
||||
rsgBindProgramFragment(gProgFragmentCustom2);
|
||||
rsgBindSampler(gProgFragmentCustom2, 0, gLinearClamp);
|
||||
rsgBindTexture(gProgFragmentCustom2, 0, gTexTorus);
|
||||
|
||||
// Use back face culling
|
||||
rsgBindProgramRaster(gCullBack);
|
||||
rsgDrawMesh(gTorusMesh);
|
||||
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgBindFont(gFontMono);
|
||||
rsgDrawText("Custom shader sample with array uniforms", 10, rsgGetHeight() - 10);
|
||||
}
|
||||
|
||||
static void displayCubemapShaderSample() {
|
||||
// Update vertex shader constants
|
||||
// Load model matrix
|
||||
// Aplly a rotation to our mesh
|
||||
gTorusRotation += 50.0f * gDt;
|
||||
if (gTorusRotation > 360.0f) {
|
||||
gTorusRotation -= 360.0f;
|
||||
}
|
||||
|
||||
// Position our model on the screen
|
||||
// Position our model on the screen
|
||||
rsMatrixLoadTranslate(&gVSConstants->model, 0.0f, 0.0f, -10.0f);
|
||||
rsMatrixRotate(&gVSConstants->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
|
||||
rsMatrixRotate(&gVSConstants->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
|
||||
// Setup the projectioni matrix
|
||||
float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
|
||||
rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f);
|
||||
rsgAllocationSyncAll(rsGetAllocation(gFSConstants));
|
||||
|
||||
rsgBindProgramVertex(gProgVertexCube);
|
||||
|
||||
// Fragment shader with texture
|
||||
rsgBindProgramStore(gProgStoreBlendNoneDepth);
|
||||
rsgBindProgramFragment(gProgFragmentCube);
|
||||
rsgBindSampler(gProgFragmentCube, 0, gLinearClamp);
|
||||
rsgBindTexture(gProgFragmentCube, 0, gTexCube);
|
||||
|
||||
// Use back face culling
|
||||
rsgBindProgramRaster(gCullBack);
|
||||
rsgDrawMesh(gTorusMesh);
|
||||
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgBindFont(gFontMono);
|
||||
rsgDrawText("Cubemap shader sample", 10, rsgGetHeight() - 10);
|
||||
}
|
||||
|
||||
static void displayMultitextureSample() {
|
||||
bindProgramVertexOrtho();
|
||||
rs_matrix4x4 matrix;
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
// Fragment shader with texture
|
||||
rsgBindProgramStore(gProgStoreBlendNone);
|
||||
rsgBindProgramFragment(gProgFragmentMultitex);
|
||||
rsgBindSampler(gProgFragmentMultitex, 0, gLinearClamp);
|
||||
rsgBindSampler(gProgFragmentMultitex, 1, gLinearWrap);
|
||||
rsgBindSampler(gProgFragmentMultitex, 2, gLinearClamp);
|
||||
rsgBindTexture(gProgFragmentMultitex, 0, gTexChecker);
|
||||
rsgBindTexture(gProgFragmentMultitex, 1, gTexTorus);
|
||||
rsgBindTexture(gProgFragmentMultitex, 2, gTexTransparent);
|
||||
|
||||
float startX = 0, startY = 0;
|
||||
float width = 256, height = 256;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
|
||||
startX, startY + height, 0, 0, 1,
|
||||
startX + width, startY + height, 0, 1, 1,
|
||||
startX + width, startY, 0, 1, 0);
|
||||
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgBindFont(gFontMono);
|
||||
rsgDrawText("Custom shader with multitexturing", 10, 280);
|
||||
}
|
||||
|
||||
static float gAnisoTime = 0.0f;
|
||||
static uint anisoMode = 0;
|
||||
static void displayAnisoSample() {
|
||||
|
||||
gAnisoTime += gDt;
|
||||
|
||||
rsgBindProgramVertex(gProgVertex);
|
||||
float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
|
||||
rs_matrix4x4 proj;
|
||||
rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
|
||||
rsgProgramVertexLoadProjectionMatrix(&proj);
|
||||
|
||||
rs_matrix4x4 matrix;
|
||||
// Fragment shader with texture
|
||||
rsgBindProgramStore(gProgStoreBlendNone);
|
||||
rsgBindProgramFragment(gProgFragmentTexture);
|
||||
rsMatrixLoadTranslate(&matrix, 0.0f, 0.0f, -10.0f);
|
||||
rsMatrixRotate(&matrix, -80, 1.0f, 0.0f, 0.0f);
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
rsgBindProgramRaster(gCullNone);
|
||||
|
||||
rsgBindTexture(gProgFragmentTexture, 0, gTexChecker);
|
||||
|
||||
if (gAnisoTime >= 5.0f) {
|
||||
gAnisoTime = 0.0f;
|
||||
anisoMode ++;
|
||||
anisoMode = anisoMode % 3;
|
||||
}
|
||||
|
||||
if (anisoMode == 0) {
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gMipLinearAniso8);
|
||||
} else if (anisoMode == 1) {
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gMipLinearAniso15);
|
||||
} else {
|
||||
rsgBindSampler(gProgFragmentTexture, 0, gMipLinearWrap);
|
||||
}
|
||||
|
||||
float startX = -15;
|
||||
float startY = -15;
|
||||
float width = 30;
|
||||
float height = 30;
|
||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
|
||||
startX, startY + height, 0, 0, 10,
|
||||
startX + width, startY + height, 0, 10, 10,
|
||||
startX + width, startY, 0, 10, 0);
|
||||
|
||||
rsgBindProgramRaster(gCullBack);
|
||||
|
||||
rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgBindFont(gFontMono);
|
||||
if (anisoMode == 0) {
|
||||
rsgDrawText("Anisotropic filtering 8", 10, 40);
|
||||
} else if (anisoMode == 1) {
|
||||
rsgDrawText("Anisotropic filtering 15", 10, 40);
|
||||
} else {
|
||||
rsgDrawText("Miplinear filtering", 10, 40);
|
||||
}
|
||||
}
|
||||
|
||||
int root(void) {
|
||||
|
||||
gDt = rsGetDt();
|
||||
|
||||
rsgClearColor(0.2f, 0.2f, 0.2f, 0.0f);
|
||||
rsgClearDepth(1.0f);
|
||||
|
||||
switch (gDisplayMode) {
|
||||
case 0:
|
||||
displayFontSamples();
|
||||
break;
|
||||
case 1:
|
||||
displayShaderSamples();
|
||||
break;
|
||||
case 2:
|
||||
displayBlendingSamples();
|
||||
break;
|
||||
case 3:
|
||||
displayMeshSamples();
|
||||
break;
|
||||
case 4:
|
||||
displayTextureSamplers();
|
||||
break;
|
||||
case 5:
|
||||
displayCullingSamples();
|
||||
break;
|
||||
case 6:
|
||||
displayCustomShaderSamples();
|
||||
break;
|
||||
case 7:
|
||||
displayMultitextureSample();
|
||||
break;
|
||||
case 8:
|
||||
displayAnisoSample();
|
||||
break;
|
||||
case 9:
|
||||
displayCustomShaderSamples2();
|
||||
break;
|
||||
case 10:
|
||||
displayCubemapShaderSample();
|
||||
break;
|
||||
}
|
||||
|
||||
return 10;
|
||||
}
|
@ -1,83 +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.example.android.rs.miscsamples)
|
||||
|
||||
typedef struct VertexShaderConstants_s {
|
||||
rs_matrix4x4 model;
|
||||
rs_matrix4x4 proj;
|
||||
float4 light0_Posision;
|
||||
float light0_Diffuse;
|
||||
float light0_Specular;
|
||||
float light0_CosinePower;
|
||||
|
||||
float4 light1_Posision;
|
||||
float light1_Diffuse;
|
||||
float light1_Specular;
|
||||
float light1_CosinePower;
|
||||
} VertexShaderConstants;
|
||||
|
||||
typedef struct VertexShaderConstants2_s {
|
||||
rs_matrix4x4 model[2];
|
||||
rs_matrix4x4 proj;
|
||||
float4 light_Posision[2];
|
||||
float light_Diffuse[2];
|
||||
float light_Specular[2];
|
||||
float light_CosinePower[2];
|
||||
} VertexShaderConstants2;
|
||||
|
||||
typedef struct VertexShaderConstants3_s {
|
||||
rs_matrix4x4 model;
|
||||
rs_matrix4x4 proj;
|
||||
float time;
|
||||
} VertexShaderConstants3;
|
||||
|
||||
|
||||
typedef struct FragentShaderConstants_s {
|
||||
float4 light0_DiffuseColor;
|
||||
float4 light0_SpecularColor;
|
||||
|
||||
float4 light1_DiffuseColor;
|
||||
float4 light1_SpecularColor;
|
||||
} FragentShaderConstants;
|
||||
|
||||
typedef struct FragentShaderConstants2_s {
|
||||
float4 light_DiffuseColor[2];
|
||||
float4 light_SpecularColor[2];
|
||||
} FragentShaderConstants2;
|
||||
|
||||
typedef struct FragentShaderConstants3_s {
|
||||
float4 light0_DiffuseColor;
|
||||
float4 light0_SpecularColor;
|
||||
float4 light0_Posision;
|
||||
float light0_Diffuse;
|
||||
float light0_Specular;
|
||||
float light0_CosinePower;
|
||||
|
||||
float4 light1_DiffuseColor;
|
||||
float4 light1_SpecularColor;
|
||||
float4 light1_Posision;
|
||||
float light1_Diffuse;
|
||||
float light1_Specular;
|
||||
float light1_CosinePower;
|
||||
} FragentShaderConstants3;
|
||||
|
||||
typedef struct VertexShaderInputs_s {
|
||||
float4 position;
|
||||
float3 normal;
|
||||
float2 texture0;
|
||||
} VertexShaderInputs;
|
||||
|
@ -1,29 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2008 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
||||
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
|
||||
|
||||
LOCAL_SDK_VERSION := 17
|
||||
|
||||
LOCAL_PACKAGE_NAME := ModelViewer
|
||||
|
||||
include $(BUILD_PACKAGE)
|
@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.modelviewer">
|
||||
<application android:label="ModelViewer">
|
||||
<activity android:name="SimpleModel"
|
||||
android:label="SimpleModel"
|
||||
android:screenOrientation="nosensor">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="A3DSelector"
|
||||
android:label="A3DSelector"
|
||||
android:hardwareAccelerated="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="SceneGraph"
|
||||
android:label="SceneGraph"
|
||||
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>
|
Before Width: | Height: | Size: 286 KiB |
@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/load_model"
|
||||
android:title="@string/load_model" />
|
||||
<item android:id="@+id/display_options"
|
||||
android:title="@string/display_options" />
|
||||
<item android:id="@+id/sensor"
|
||||
android:title="@string/sensor" />
|
||||
</menu>
|
@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<skip />
|
||||
<string name="load_model">Load Model</string>
|
||||
<string name="display_options">Display Options</string>
|
||||
<string name="sensor">Toggle Sensor</string>
|
||||
</resources>
|
@ -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.modelviewer;
|
||||
|
||||
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 A3DSelector extends ListActivity {
|
||||
|
||||
File[] mCurrentSubList;
|
||||
File mCurrentFile;
|
||||
|
||||
class A3DFilter implements FileFilter {
|
||||
public boolean accept(File file) {
|
||||
if (file.isDirectory()) {
|
||||
return true;
|
||||
}
|
||||
return file.getName().endsWith(".a3d");
|
||||
}
|
||||
}
|
||||
|
||||
private void populateList(File file) {
|
||||
|
||||
mCurrentFile = file;
|
||||
setTitle(mCurrentFile.getAbsolutePath() + "/*.a3d");
|
||||
List<String> names = new ArrayList<String>();
|
||||
names.add("..");
|
||||
|
||||
mCurrentSubList = mCurrentFile.listFiles(new A3DFilter());
|
||||
|
||||
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<String>(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();
|
||||
}
|
||||
|
||||
}
|
@ -1,70 +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.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 SceneGraph extends Activity {
|
||||
|
||||
private SceneGraphView 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 SceneGraphView(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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,217 +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.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.Element.Builder;
|
||||
import android.renderscript.Font.Style;
|
||||
import android.renderscript.ProgramStore.DepthFunc;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class SceneGraphRS {
|
||||
|
||||
private final int STATE_LAST_FOCUS = 1;
|
||||
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
int mRotation;
|
||||
|
||||
public SceneGraphRS() {
|
||||
}
|
||||
|
||||
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 ProgramVertexFixedFunction.Constants mPVA;
|
||||
|
||||
private Allocation mGridImage;
|
||||
private Allocation mAllocPV;
|
||||
|
||||
private Mesh mMesh;
|
||||
|
||||
private Font mItalic;
|
||||
private Allocation mTextAlloc;
|
||||
|
||||
private ScriptC_scenegraph mScript;
|
||||
private ScriptC_transform mTransformScript;
|
||||
|
||||
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.setDitherEnabled(false);
|
||||
b.setDepthMaskEnabled(true);
|
||||
mPSBackground = b.create();
|
||||
|
||||
mScript.set_gPFSBackground(mPSBackground);
|
||||
}
|
||||
|
||||
private void initPF() {
|
||||
Sampler.Builder bs = new Sampler.Builder(mRS);
|
||||
bs.setMinification(Sampler.Value.LINEAR);
|
||||
bs.setMagnification(Sampler.Value.LINEAR);
|
||||
bs.setWrapS(Sampler.Value.CLAMP);
|
||||
bs.setWrapT(Sampler.Value.CLAMP);
|
||||
mSampler = bs.create();
|
||||
|
||||
ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
|
||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
||||
mPFBackground = b.create();
|
||||
mPFBackground.bindSampler(mSampler, 0);
|
||||
|
||||
mScript.set_gPFBackground(mPFBackground);
|
||||
}
|
||||
|
||||
private void initPV() {
|
||||
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
|
||||
mPVBackground = pvb.create();
|
||||
|
||||
mPVA = new ProgramVertexFixedFunction.Constants(mRS);
|
||||
((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
|
||||
|
||||
mScript.set_gPVBackground(mPVBackground);
|
||||
}
|
||||
|
||||
private void loadImage() {
|
||||
mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
mScript.set_gTGrid(mGridImage);
|
||||
}
|
||||
|
||||
private void initTextAllocation() {
|
||||
String allocString = "Displaying file: R.raw.robot";
|
||||
mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
|
||||
mScript.set_gTextAlloc(mTextAlloc);
|
||||
}
|
||||
|
||||
SgTransform mRootTransform;
|
||||
SgTransform mGroup1;
|
||||
|
||||
SgTransform mRobot1;
|
||||
SgTransform mRobot2;
|
||||
|
||||
void initTransformHierarchy() {
|
||||
mRootTransform = new SgTransform(mRS);
|
||||
|
||||
mGroup1 = new SgTransform(mRS);
|
||||
mRootTransform.addChild(mGroup1);
|
||||
|
||||
mRobot1 = new SgTransform(mRS);
|
||||
mRobot2 = new SgTransform(mRS);
|
||||
|
||||
mGroup1.addChild(mRobot1);
|
||||
mGroup1.addChild(mRobot2);
|
||||
|
||||
mGroup1.setTransform(0, new Float4(0.0f, 0.0f, -15.0f, 0.0f), TransformType.TRANSLATE);
|
||||
mGroup1.setTransform(1, new Float4(0.0f, 1.0f, 0.0f, 15.0f), TransformType.ROTATE);
|
||||
|
||||
mRobot1.setTransform(0, new Float4(-3.0f, -0.5f, 0.0f, 0.0f), TransformType.TRANSLATE);
|
||||
mRobot1.setTransform(1, new Float4(0.0f, 1.0f, 0.0f, 20.0f), TransformType.ROTATE);
|
||||
mRobot1.setTransform(2, new Float4(0.2f, 0.2f, 0.2f, 0.0f), TransformType.SCALE);
|
||||
|
||||
mRobot2.setTransform(0, new Float4(3.0f, 0.0f, 0.0f, 0.0f), TransformType.TRANSLATE);
|
||||
mRobot2.setTransform(1, new Float4(0.0f, 1.0f, 0.0f, -20.0f), TransformType.ROTATE);
|
||||
mRobot2.setTransform(2, new Float4(0.3f, 0.3f, 0.3f, 0.0f), TransformType.SCALE);
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
|
||||
mScript = new ScriptC_scenegraph(mRS, mRes, R.raw.scenegraph);
|
||||
mTransformScript = new ScriptC_transform(mRS, mRes, R.raw.transform);
|
||||
mTransformScript.set_transformScript(mTransformScript);
|
||||
|
||||
mScript.set_gTransformRS(mTransformScript);
|
||||
|
||||
initPFS();
|
||||
initPF();
|
||||
initPV();
|
||||
|
||||
loadImage();
|
||||
|
||||
FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
|
||||
FileA3D.IndexEntry entry = model.getIndexEntry(0);
|
||||
if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) {
|
||||
Log.e("rs", "could not load model");
|
||||
} else {
|
||||
mMesh = (Mesh)entry.getObject();
|
||||
mScript.set_gTestMesh(mMesh);
|
||||
}
|
||||
|
||||
mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
|
||||
mScript.set_gItalic(mItalic);
|
||||
|
||||
initTextAllocation();
|
||||
|
||||
initTransformHierarchy();
|
||||
|
||||
mScript.bind_gRootNode(mRootTransform.getField());
|
||||
|
||||
mScript.bind_gGroup(mGroup1.mParent.mChildField);
|
||||
mScript.bind_gRobot1(mRobot1.mParent.mChildField);
|
||||
mScript.set_gRobot1Index(mRobot1.mIndexInParentGroup);
|
||||
mScript.bind_gRobot2(mRobot2.mParent.mChildField);
|
||||
mScript.set_gRobot2Index(mRobot2.mIndexInParentGroup);
|
||||
|
||||
mRS.bindRootScript(mScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,96 +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 SceneGraphView extends RSSurfaceView {
|
||||
|
||||
public SceneGraphView(Context context) {
|
||||
super(context);
|
||||
//setFocusable(true);
|
||||
}
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private SceneGraphRS mRender;
|
||||
|
||||
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
super.surfaceChanged(holder, format, w, h);
|
||||
if (mRS == null) {
|
||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
||||
sc.setDepth(16, 24);
|
||||
mRS = createRenderScriptGL(sc);
|
||||
mRS.setSurface(holder, w, h);
|
||||
mRender = new SceneGraphRS();
|
||||
mRender.init(mRS, getResources(), w, h);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
if (mRS != 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)
|
||||
{
|
||||
boolean ret = true;
|
||||
int act = ev.getAction();
|
||||
if (act == ev.ACTION_UP) {
|
||||
ret = false;
|
||||
}
|
||||
|
||||
mRender.touchEvent((int)ev.getX(), (int)ev.getY());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,112 +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.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.Element.Builder;
|
||||
import android.renderscript.ProgramStore.DepthFunc;
|
||||
import android.util.Log;
|
||||
|
||||
enum TransformType {
|
||||
|
||||
NONE(0),
|
||||
TRANSLATE(1),
|
||||
ROTATE(2),
|
||||
SCALE(3);
|
||||
|
||||
int mID;
|
||||
TransformType(int id) {
|
||||
mID = id;
|
||||
}
|
||||
}
|
||||
|
||||
public class SgTransform {
|
||||
|
||||
|
||||
ScriptField_SgTransform mTransformField;
|
||||
ScriptField_SgTransform mChildField;
|
||||
public ScriptField_SgTransform.Item mTransformData;
|
||||
|
||||
RenderScript mRS;
|
||||
|
||||
Vector mChildren;
|
||||
SgTransform mParent;
|
||||
int mIndexInParentGroup;
|
||||
|
||||
public void setParent(SgTransform parent, int parentIndex) {
|
||||
mParent = parent;
|
||||
mIndexInParentGroup = parentIndex;
|
||||
}
|
||||
|
||||
public void addChild(SgTransform child) {
|
||||
mChildren.add(child);
|
||||
child.setParent(this, mChildren.size() - 1);
|
||||
}
|
||||
|
||||
public void setTransform(int index, Float4 value, TransformType type) {
|
||||
mTransformData.transforms[index] = value;
|
||||
mTransformData.transformTypes[index] = type.mID;
|
||||
}
|
||||
|
||||
void initData() {
|
||||
int numElements = mTransformData.transforms.length;
|
||||
mTransformData.transformTypes = new int[numElements];
|
||||
for (int i = 0; i < numElements; i ++) {
|
||||
mTransformData.transforms[i] = new Float4(0, 0, 0, 0);
|
||||
mTransformData.transformTypes[i] = TransformType.NONE.mID;
|
||||
}
|
||||
|
||||
mTransformData.isDirty = 1;
|
||||
mTransformData.children = null;
|
||||
}
|
||||
|
||||
public SgTransform(RenderScript rs) {
|
||||
mRS = rs;
|
||||
mTransformData = new ScriptField_SgTransform.Item();
|
||||
mChildren = new Vector();
|
||||
initData();
|
||||
}
|
||||
|
||||
public ScriptField_SgTransform.Item getData() {
|
||||
if (mChildren.size() != 0) {
|
||||
mChildField = new ScriptField_SgTransform(mRS, mChildren.size());
|
||||
mTransformData.children = mChildField.getAllocation();
|
||||
|
||||
for (int i = 0; i < mChildren.size(); i ++) {
|
||||
SgTransform child = (SgTransform)mChildren.get(i);
|
||||
mChildField.set(child.getData(), i, false);
|
||||
}
|
||||
mChildField.copyAll();
|
||||
}
|
||||
|
||||
return mTransformData;
|
||||
}
|
||||
|
||||
public ScriptField_SgTransform getField() {
|
||||
mTransformField = new ScriptField_SgTransform(mRS, 1);
|
||||
mTransformField.set(getData(), 0, true);
|
||||
return mTransformField;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.modelviewer;
|
||||
|
||||
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.MenuInflater;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.net.Uri;
|
||||
|
||||
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.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.display_options:
|
||||
return true;
|
||||
case R.id.sensor:
|
||||
mView.toggleSensor();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int FIND_A3D_MODEL = 10;
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == FIND_A3D_MODEL) {
|
||||
Uri selectedImageUri = data.getData();
|
||||
Log.e("Selected Path: ", selectedImageUri.getPath());
|
||||
mView.loadA3DFile(selectedImageUri.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadModel() {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_PICK);
|
||||
intent.setClassName("com.android.modelviewer",
|
||||
"com.android.modelviewer.A3DSelector");
|
||||
startActivityForResult(intent, FIND_A3D_MODEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,187 +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.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 {
|
||||
|
||||
public SimpleModelRS() {
|
||||
}
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initRS();
|
||||
}
|
||||
|
||||
public void surfaceChanged() {
|
||||
mRS.getWidth();
|
||||
mRS.getHeight();
|
||||
}
|
||||
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
private Sampler mSampler;
|
||||
private ProgramStore mPSBackground;
|
||||
private ProgramFragment mPFBackground;
|
||||
private ProgramVertex mPVBackground;
|
||||
private ProgramVertexFixedFunction.Constants mPVA;
|
||||
|
||||
private Allocation mGridImage;
|
||||
private Allocation mAllocPV;
|
||||
|
||||
private Font mItalic;
|
||||
private Allocation mTextAlloc;
|
||||
|
||||
private ScriptField_MeshInfo mMeshes;
|
||||
private ScriptC_simplemodel mScript;
|
||||
|
||||
|
||||
public void onActionDown(float x, float y) {
|
||||
mScript.invoke_onActionDown(x, y);
|
||||
}
|
||||
|
||||
public void onActionScale(float scale) {
|
||||
mScript.invoke_onActionScale(scale);
|
||||
}
|
||||
|
||||
public void onActionMove(float x, float y) {
|
||||
mScript.invoke_onActionMove(x, y);
|
||||
}
|
||||
|
||||
public void onPostureChanged(Matrix4f posture) {
|
||||
mScript.set_gPostureMatrix(posture);
|
||||
}
|
||||
|
||||
private void initPFS() {
|
||||
ProgramStore.Builder b = new ProgramStore.Builder(mRS);
|
||||
|
||||
b.setDepthFunc(ProgramStore.DepthFunc.LESS);
|
||||
b.setDitherEnabled(false);
|
||||
b.setDepthMaskEnabled(true);
|
||||
mPSBackground = b.create();
|
||||
|
||||
mScript.set_gPFSBackground(mPSBackground);
|
||||
}
|
||||
|
||||
private void initPF() {
|
||||
Sampler.Builder bs = new Sampler.Builder(mRS);
|
||||
bs.setMinification(Sampler.Value.LINEAR);
|
||||
bs.setMagnification(Sampler.Value.LINEAR);
|
||||
bs.setWrapS(Sampler.Value.CLAMP);
|
||||
bs.setWrapT(Sampler.Value.CLAMP);
|
||||
mSampler = bs.create();
|
||||
|
||||
ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
|
||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
||||
mPFBackground = b.create();
|
||||
mPFBackground.bindSampler(mSampler, 0);
|
||||
|
||||
mScript.set_gPFBackground(mPFBackground);
|
||||
}
|
||||
|
||||
private void initPV() {
|
||||
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
|
||||
mPVBackground = pvb.create();
|
||||
|
||||
mPVA = new ProgramVertexFixedFunction.Constants(mRS);
|
||||
((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
|
||||
|
||||
mScript.set_gPVBackground(mPVBackground);
|
||||
}
|
||||
|
||||
private void loadImage() {
|
||||
mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
mScript.set_gTGrid(mGridImage);
|
||||
}
|
||||
|
||||
private void initTextAllocation(String fileName) {
|
||||
String allocString = "Displaying file: " + fileName;
|
||||
mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
|
||||
mScript.set_gTextAlloc(mTextAlloc);
|
||||
}
|
||||
|
||||
private void initMeshes(FileA3D model) {
|
||||
int numEntries = model.getIndexEntryCount();
|
||||
int numMeshes = 0;
|
||||
for (int i = 0; i < numEntries; i ++) {
|
||||
FileA3D.IndexEntry entry = model.getIndexEntry(i);
|
||||
if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
|
||||
numMeshes ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numMeshes > 0) {
|
||||
mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);
|
||||
|
||||
for (int i = 0; i < numEntries; i ++) {
|
||||
FileA3D.IndexEntry entry = model.getIndexEntry(i);
|
||||
if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
|
||||
Mesh mesh = entry.getMesh();
|
||||
mMeshes.set_mMesh(i, mesh, false);
|
||||
mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
|
||||
}
|
||||
}
|
||||
mMeshes.copyAll();
|
||||
} else {
|
||||
throw new RSRuntimeException("No valid meshes in file");
|
||||
}
|
||||
|
||||
mScript.bind_gMeshes(mMeshes);
|
||||
mScript.invoke_updateMeshInfo();
|
||||
}
|
||||
|
||||
public void loadA3DFile(String path) {
|
||||
FileA3D model = FileA3D.createFromFile(mRS, path);
|
||||
initMeshes(model);
|
||||
initTextAllocation(path);
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
|
||||
mScript = new ScriptC_simplemodel(mRS, mRes, R.raw.simplemodel);
|
||||
|
||||
initPFS();
|
||||
initPF();
|
||||
initPV();
|
||||
|
||||
loadImage();
|
||||
|
||||
FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
|
||||
initMeshes(model);
|
||||
|
||||
mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
|
||||
mScript.set_gItalic(mItalic);
|
||||
|
||||
initTextAllocation("R.raw.robot");
|
||||
|
||||
mRS.bindRootScript(mScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,197 +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.modelviewer;
|
||||
|
||||
import android.renderscript.Matrix4f;
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScriptGL;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.ScaleGestureDetector;
|
||||
import android.util.Log;
|
||||
|
||||
public class SimpleModelView extends RSSurfaceView implements SensorEventListener {
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private SimpleModelRS mRender;
|
||||
|
||||
private ScaleGestureDetector mScaleDetector;
|
||||
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mRotationVectorSensor;
|
||||
private final float[] mRotationMatrix = new float[16];
|
||||
|
||||
private static final int INVALID_POINTER_ID = -1;
|
||||
private int mActivePointerId = INVALID_POINTER_ID;
|
||||
private boolean mUseSensor = false;
|
||||
private Matrix4f mIdentityMatrix = new Matrix4f();
|
||||
|
||||
public SimpleModelView(Context context) {
|
||||
super(context);
|
||||
ensureRenderScript();
|
||||
mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
|
||||
// Get an instance of the SensorManager
|
||||
mSensorManager = (SensorManager)getContext().getSystemService(Context.SENSOR_SERVICE);
|
||||
// find the rotation-vector sensor
|
||||
mRotationVectorSensor = mSensorManager.getDefaultSensor(
|
||||
Sensor.TYPE_ROTATION_VECTOR);
|
||||
mIdentityMatrix.loadIdentity();
|
||||
}
|
||||
|
||||
private void ensureRenderScript() {
|
||||
if (mRS == null) {
|
||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
||||
sc.setDepth(16, 24);
|
||||
mRS = createRenderScriptGL(sc);
|
||||
mRender = new SimpleModelRS();
|
||||
mRender.init(mRS, getResources());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
mSensorManager.registerListener(this, mRotationVectorSensor, 10000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
mSensorManager.unregisterListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
ensureRenderScript();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
super.surfaceChanged(holder, format, w, h);
|
||||
mRender.surfaceChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
mRender = null;
|
||||
if (mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScriptGL();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadA3DFile(String path) {
|
||||
mRender.loadA3DFile(path);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
// we received a sensor event. it is a good practice to check
|
||||
// that we received the proper event
|
||||
if (mUseSensor) {
|
||||
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
|
||||
// convert the rotation-vector to a 4x4 matrix. the matrix
|
||||
// is interpreted by Open GL as the inverse of the
|
||||
// rotation-vector, which is what we want.
|
||||
SensorManager.getRotationMatrixFromVector(
|
||||
mRotationMatrix , event.values);
|
||||
|
||||
if (mRender != null) {
|
||||
mRender.onPostureChanged(new Matrix4f(mRotationMatrix));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
}
|
||||
|
||||
public void toggleSensor() {
|
||||
mUseSensor = !mUseSensor;
|
||||
if (mUseSensor == false) {
|
||||
mRender.onPostureChanged(mIdentityMatrix);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +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"
|
||||
#include "transform_def.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;
|
||||
|
||||
rs_script gTransformRS;
|
||||
|
||||
SgTransform *gGroup;
|
||||
SgTransform *gRobot1;
|
||||
int gRobot1Index;
|
||||
SgTransform *gRobot2;
|
||||
int gRobot2Index;
|
||||
|
||||
SgTransform *gRootNode;
|
||||
|
||||
void init() {
|
||||
gRotate = 0.0f;
|
||||
}
|
||||
|
||||
int root(void) {
|
||||
|
||||
gGroup->transforms[1].w += 0.5f;
|
||||
gGroup->isDirty = 1;
|
||||
|
||||
SgTransform *robot1Ptr = gRobot1 + gRobot1Index;
|
||||
|
||||
robot1Ptr->transforms[1].w -= 1.5f;
|
||||
robot1Ptr->isDirty = 1;
|
||||
|
||||
SgTransform *robot2Ptr = gRobot2 + gRobot2Index;
|
||||
robot2Ptr->transforms[1].w += 2.5f;
|
||||
robot2Ptr->isDirty = 1;
|
||||
|
||||
rsForEach(gTransformRS, gRootNode->children, gRootNode->children);
|
||||
|
||||
rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgClearDepth(1.0f);
|
||||
|
||||
rsgBindProgramVertex(gPVBackground);
|
||||
rs_matrix4x4 proj;
|
||||
float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
|
||||
rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
|
||||
rsgProgramVertexLoadProjectionMatrix(&proj);
|
||||
|
||||
rsgBindProgramFragment(gPFBackground);
|
||||
rsgBindProgramStore(gPFSBackground);
|
||||
rsgBindTexture(gPFBackground, 0, gTGrid);
|
||||
|
||||
rsgProgramVertexLoadModelMatrix(&robot1Ptr->globalMat);
|
||||
rsgDrawMesh(gTestMesh);
|
||||
|
||||
rsgProgramVertexLoadModelMatrix(&robot2Ptr->globalMat);
|
||||
rsgDrawMesh(gTestMesh);
|
||||
|
||||
//color(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
rsgDrawText("Renderscript transform test", 30, 695);
|
||||
|
||||
rsgBindFont(gItalic);
|
||||
rsgDrawText(gTextAlloc, 30, 730);
|
||||
|
||||
return 10;
|
||||
}
|
@ -1,172 +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.modelviewer)
|
||||
|
||||
#include "rs_graphics.rsh"
|
||||
|
||||
rs_program_vertex gPVBackground;
|
||||
rs_program_fragment gPFBackground;
|
||||
|
||||
rs_allocation gTGrid;
|
||||
|
||||
rs_program_store gPFSBackground;
|
||||
|
||||
rs_font gItalic;
|
||||
rs_allocation gTextAlloc;
|
||||
|
||||
rs_matrix4x4 gPostureMatrix;
|
||||
|
||||
typedef struct MeshInfo {
|
||||
rs_mesh mMesh;
|
||||
int mNumIndexSets;
|
||||
float3 bBoxMin;
|
||||
float3 bBoxMax;
|
||||
} MeshInfo_t;
|
||||
|
||||
MeshInfo_t *gMeshes;
|
||||
|
||||
static float3 gLookAt;
|
||||
|
||||
static float gRotateX;
|
||||
static float gRotateY;
|
||||
static float gZoom;
|
||||
|
||||
static float gLastX;
|
||||
static float gLastY;
|
||||
|
||||
static float3 toFloat3(float x, float y, float z) {
|
||||
float3 f;
|
||||
f.x = x;
|
||||
f.y = y;
|
||||
f.z = z;
|
||||
return f;
|
||||
}
|
||||
|
||||
void onActionDown(float x, float y) {
|
||||
gLastX = x;
|
||||
gLastY = y;
|
||||
}
|
||||
|
||||
void onActionScale(float scale) {
|
||||
|
||||
gZoom *= 1.0f / scale;
|
||||
gZoom = max(0.1f, min(gZoom, 500.0f));
|
||||
}
|
||||
|
||||
void onActionMove(float x, float y) {
|
||||
float dx = gLastX - x;
|
||||
float dy = gLastY - y;
|
||||
|
||||
if (fabs(dy) <= 2.0f) {
|
||||
dy = 0.0f;
|
||||
}
|
||||
if (fabs(dx) <= 2.0f) {
|
||||
dx = 0.0f;
|
||||
}
|
||||
|
||||
gRotateY -= dx;
|
||||
if (gRotateY > 360) {
|
||||
gRotateY -= 360;
|
||||
}
|
||||
if (gRotateY < 0) {
|
||||
gRotateY += 360;
|
||||
}
|
||||
|
||||
gRotateX -= dy;
|
||||
gRotateX = min(gRotateX, 80.0f);
|
||||
gRotateX = max(gRotateX, -80.0f);
|
||||
|
||||
gLastX = x;
|
||||
gLastY = y;
|
||||
}
|
||||
|
||||
void init() {
|
||||
gRotateX = 0.0f;
|
||||
gRotateY = 0.0f;
|
||||
gZoom = 50.0f;
|
||||
gLookAt = 0.0f;
|
||||
rsMatrixLoadIdentity(&gPostureMatrix);
|
||||
}
|
||||
|
||||
void updateMeshInfo() {
|
||||
rs_allocation allMeshes = rsGetAllocation(gMeshes);
|
||||
int size = rsAllocationGetDimX(allMeshes);
|
||||
gLookAt = 0.0f;
|
||||
float minX, minY, minZ, maxX, maxY, maxZ;
|
||||
for (int i = 0; i < size; i++) {
|
||||
MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
|
||||
rsgMeshComputeBoundingBox(info->mMesh,
|
||||
&minX, &minY, &minZ,
|
||||
&maxX, &maxY, &maxZ);
|
||||
info->bBoxMin = toFloat3(minX, minY, minZ);
|
||||
info->bBoxMax = toFloat3(maxX, maxY, maxZ);
|
||||
gLookAt += (info->bBoxMin + info->bBoxMax)*0.5f;
|
||||
}
|
||||
gLookAt = gLookAt / (float)size;
|
||||
}
|
||||
|
||||
static void renderAllMeshes() {
|
||||
rs_allocation allMeshes = rsGetAllocation(gMeshes);
|
||||
int size = rsAllocationGetDimX(allMeshes);
|
||||
gLookAt = 0.0f;
|
||||
for (int i = 0; i < size; i++) {
|
||||
MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
|
||||
rsgDrawMesh(info->mMesh);
|
||||
}
|
||||
}
|
||||
|
||||
void drawDescription() {
|
||||
uint height = rsgGetHeight();
|
||||
int left = 0, right = 0, top = 0, bottom = 0;
|
||||
|
||||
rsgBindFont(gItalic);
|
||||
|
||||
rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
|
||||
rsgDrawText(gTextAlloc, 2 -left, height - 2 + bottom);
|
||||
}
|
||||
|
||||
int root(void) {
|
||||
|
||||
rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
rsgClearDepth(1.0f);
|
||||
|
||||
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, gTGrid);
|
||||
|
||||
rs_matrix4x4 matrix;
|
||||
rsMatrixLoadIdentity(&matrix);
|
||||
// Position our models on the screen
|
||||
rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
|
||||
rsMatrixMultiply(&matrix, &gPostureMatrix);
|
||||
rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
|
||||
rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
rsgProgramVertexLoadModelMatrix(&matrix);
|
||||
|
||||
renderAllMeshes();
|
||||
|
||||
drawDescription();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,96 +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 "transform_def.rsh"
|
||||
|
||||
rs_script transformScript;
|
||||
|
||||
typedef struct {
|
||||
int changed;
|
||||
rs_matrix4x4 *mat;
|
||||
} ParentData;
|
||||
|
||||
static void appendTransformation(int type, float4 data, rs_matrix4x4 *mat) {
|
||||
rs_matrix4x4 temp;
|
||||
|
||||
switch (type) {
|
||||
case TRANSFORM_TRANSLATE:
|
||||
rsMatrixLoadTranslate(&temp, data.x, data.y, data.z);
|
||||
break;
|
||||
case TRANSFORM_ROTATE:
|
||||
rsMatrixLoadRotate(&temp, data.w, data.x, data.y, data.z);
|
||||
break;
|
||||
case TRANSFORM_SCALE:
|
||||
rsMatrixLoadScale(&temp, data.x, data.y, data.z);
|
||||
break;
|
||||
}
|
||||
rsMatrixMultiply(mat, &temp);
|
||||
}
|
||||
|
||||
void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
|
||||
|
||||
SgTransform *data = (SgTransform *)v_out;
|
||||
const ParentData *parent = (const ParentData *)usrData;
|
||||
|
||||
//rsDebug("Transform data", (int)data);
|
||||
//rsDebug("Entering parent", (int)parent);
|
||||
|
||||
rs_matrix4x4 *localMat = &data->localMat;
|
||||
rs_matrix4x4 *globalMat = &data->globalMat;
|
||||
|
||||
ParentData toChild;
|
||||
toChild.changed = 0;
|
||||
toChild.mat = globalMat;
|
||||
|
||||
//rsDebug("Transform is dirty", data->isDirty);
|
||||
|
||||
// Refresh matrices if dirty
|
||||
if (data->isDirty) {
|
||||
data->isDirty = 0;
|
||||
toChild.changed = 1;
|
||||
|
||||
// Reset our local matrix
|
||||
rsMatrixLoadIdentity(localMat);
|
||||
|
||||
for (int i = 0; i < 16; i ++) {
|
||||
if (data->transformTypes[i] == TRANSFORM_NONE) {
|
||||
break;
|
||||
}
|
||||
//rsDebug("Transform adding transformation", transformTypes[i]);
|
||||
appendTransformation(data->transformTypes[i], data->transforms[i], localMat);
|
||||
}
|
||||
}
|
||||
|
||||
//rsDebug("Transform checking parent", (int)0);
|
||||
|
||||
if (parent) {
|
||||
if (parent->changed) {
|
||||
toChild.changed = 1;
|
||||
|
||||
rsMatrixLoad(globalMat, parent->mat);
|
||||
rsMatrixMultiply(globalMat, localMat);
|
||||
}
|
||||
} else {
|
||||
rsMatrixLoad(globalMat, localMat);
|
||||
}
|
||||
|
||||
//rsDebug("Transform calling self with child ", (int)data->children.p);
|
||||
if (data->children.p) {
|
||||
rsForEach(transformScript, data->children, data->children, (void*)&toChild, sizeof(toChild));
|
||||
}
|
||||
}
|
@ -1,35 +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)
|
||||
|
||||
#define TRANSFORM_NONE 0
|
||||
#define TRANSFORM_TRANSLATE 1
|
||||
#define TRANSFORM_ROTATE 2
|
||||
#define TRANSFORM_SCALE 3
|
||||
|
||||
typedef struct __attribute__((packed, aligned(4))) SgTransform {
|
||||
rs_matrix4x4 globalMat;
|
||||
rs_matrix4x4 localMat;
|
||||
|
||||
float4 transforms[16];
|
||||
int transformTypes[16];
|
||||
|
||||
int isDirty;
|
||||
|
||||
rs_allocation children;
|
||||
|
||||
} SgTransform;
|
@ -1,31 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2008 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := android.test.runner
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
||||
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
|
||||
|
||||
LOCAL_SDK_VERSION := 17
|
||||
|
||||
LOCAL_PACKAGE_NAME := PerfTest
|
||||
|
||||
include $(BUILD_PACKAGE)
|
@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.perftest">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-sdk android:minSdkVersion="11" />
|
||||
<application android:label="PerfTest"
|
||||
android:icon="@drawable/test_pattern">
|
||||
<uses-library android:name="android.test.runner" />
|
||||
<activity android:name="RsBench"
|
||||
android:label="RsBenchmark">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<instrumentation android:name=".RsPerfTestRunner"
|
||||
android:targetPackage="com.android.perftest"
|
||||
android:label="Test runner for RsBench tests"
|
||||
/>
|
||||
</manifest>
|
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 413 B |
Before Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 134 KiB |
Before Width: | Height: | Size: 307 B |
Before Width: | Height: | Size: 46 KiB |
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/benchmark_all"
|
||||
android:title="@string/benchmark_all" />
|
||||
<item android:id="@+id/benchmark_one"
|
||||
android:title="@string/benchmark_one" />
|
||||
<item android:id="@+id/debug_mode"
|
||||
android:title="@string/debug_mode" />
|
||||
</menu>
|
||||
|
@ -1,13 +0,0 @@
|
||||
varying vec2 varTex0;
|
||||
|
||||
void main() {
|
||||
vec2 t0 = varTex0.xy;
|
||||
lowp vec4 col0 = texture2D(UNI_Tex0, t0).rgba;
|
||||
lowp vec4 col1 = texture2D(UNI_Tex1, t0*4.0).rgba;
|
||||
lowp vec4 col2 = texture2D(UNI_Tex2, t0).rgba;
|
||||
col0.xyz = col0.xyz*col1.xyz*1.5;
|
||||
col0.xyz = mix(col0.xyz, col2.xyz, col2.w);
|
||||
col0.w = 0.5;
|
||||
gl_FragColor = col0;
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
varying vec3 varWorldPos;
|
||||
varying vec3 varWorldNormal;
|
||||
varying vec2 varTex0;
|
||||
|
||||
void main() {
|
||||
|
||||
vec3 V = normalize(-varWorldPos.xyz);
|
||||
vec3 worldNorm = normalize(varWorldNormal);
|
||||
|
||||
vec3 light0Vec = normalize(UNI_light0_Posision.xyz - varWorldPos);
|
||||
vec3 light0R = -reflect(light0Vec, worldNorm);
|
||||
float light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light0_Diffuse;
|
||||
float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
|
||||
float light0_Specular = pow(light0Spec, UNI_light0_CosinePower) * UNI_light0_Specular;
|
||||
|
||||
vec3 light1Vec = normalize(UNI_light1_Posision.xyz - varWorldPos);
|
||||
vec3 light1R = reflect(light1Vec, worldNorm);
|
||||
float light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light1_Diffuse;
|
||||
float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
|
||||
float light1_Specular = pow(light1Spec, UNI_light1_CosinePower) * UNI_light1_Specular;
|
||||
|
||||
vec2 t0 = varTex0.xy;
|
||||
lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
|
||||
col.xyz = col.xyz * (light0_Diffuse * UNI_light0_DiffuseColor.xyz + light1_Diffuse * UNI_light1_DiffuseColor.xyz);
|
||||
col.xyz += light0_Specular * UNI_light0_SpecularColor.xyz;
|
||||
col.xyz += light1_Specular * UNI_light1_SpecularColor.xyz;
|
||||
gl_FragColor = col;
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
varying vec3 varWorldPos;
|
||||
varying vec3 varWorldNormal;
|
||||
varying vec2 varTex0;
|
||||
|
||||
// This is where actual shader code begins
|
||||
void main() {
|
||||
vec4 objPos = ATTRIB_position;
|
||||
vec3 oldPos = objPos.xyz;
|
||||
objPos.xyz += 0.1*sin(objPos.xyz*2.0 + UNI_time);
|
||||
objPos.xyz += 0.05*sin(objPos.xyz*4.0 + UNI_time*0.5);
|
||||
objPos.xyz += 0.02*sin(objPos.xyz*7.0 + UNI_time*0.75);
|
||||
vec4 worldPos = UNI_model * objPos;
|
||||
gl_Position = UNI_proj * worldPos;
|
||||
|
||||
mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
|
||||
vec3 worldNorm = model3 * (ATTRIB_normal + oldPos - objPos.xyz);
|
||||
|
||||
varWorldPos = worldPos.xyz;
|
||||
varWorldNormal = worldNorm;
|
||||
varTex0 = ATTRIB_texture0;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
varying vec3 varWorldPos;
|
||||
varying vec3 varWorldNormal;
|
||||
varying vec2 varTex0;
|
||||
|
||||
// This is where actual shader code begins
|
||||
void main() {
|
||||
vec4 objPos = ATTRIB_position;
|
||||
vec4 worldPos = UNI_model * objPos;
|
||||
gl_Position = UNI_proj * worldPos;
|
||||
|
||||
mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
|
||||
vec3 worldNorm = model3 * ATTRIB_normal;
|
||||
|
||||
varWorldPos = worldPos.xyz;
|
||||
varWorldNormal = worldNorm;
|
||||
varTex0 = ATTRIB_texture0;
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
|
||||
varying lowp float light0_Diffuse;
|
||||
varying lowp float light0_Specular;
|
||||
varying lowp float light1_Diffuse;
|
||||
varying lowp float light1_Specular;
|
||||
varying vec2 varTex0;
|
||||
|
||||
void main() {
|
||||
vec2 t0 = varTex0.xy;
|
||||
lowp vec4 col = texture2D(UNI_Tex0, t0).rgba;
|
||||
col.xyz = col.xyz * (light0_Diffuse * UNI_light0_DiffuseColor.xyz + light1_Diffuse * UNI_light1_DiffuseColor.xyz);
|
||||
col.xyz += light0_Specular * UNI_light0_SpecularColor.xyz;
|
||||
col.xyz += light1_Specular * UNI_light1_SpecularColor.xyz;
|
||||
gl_FragColor = col;
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
varying float light0_Diffuse;
|
||||
varying float light0_Specular;
|
||||
varying float light1_Diffuse;
|
||||
varying float light1_Specular;
|
||||
varying vec2 varTex0;
|
||||
|
||||
// This is where actual shader code begins
|
||||
void main() {
|
||||
vec4 worldPos = UNI_model * ATTRIB_position;
|
||||
gl_Position = UNI_proj * worldPos;
|
||||
|
||||
mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
|
||||
vec3 worldNorm = model3 * ATTRIB_normal;
|
||||
vec3 V = normalize(-worldPos.xyz);
|
||||
|
||||
vec3 light0Vec = normalize(UNI_light0_Posision.xyz - worldPos.xyz);
|
||||
vec3 light0R = -reflect(light0Vec, worldNorm);
|
||||
light0_Diffuse = clamp(dot(worldNorm, light0Vec), 0.0, 1.0) * UNI_light0_Diffuse;
|
||||
float light0Spec = clamp(dot(light0R, V), 0.001, 1.0);
|
||||
light0_Specular = pow(light0Spec, UNI_light0_CosinePower) * UNI_light0_Specular;
|
||||
|
||||
vec3 light1Vec = normalize(UNI_light1_Posision.xyz - worldPos.xyz);
|
||||
vec3 light1R = reflect(light1Vec, worldNorm);
|
||||
light1_Diffuse = clamp(dot(worldNorm, light1Vec), 0.0, 1.0) * UNI_light1_Diffuse;
|
||||
float light1Spec = clamp(dot(light1R, V), 0.001, 1.0);
|
||||
light1_Specular = pow(light1Spec, UNI_light1_CosinePower) * UNI_light1_Specular;
|
||||
|
||||
gl_PointSize = 1.0;
|
||||
varTex0 = ATTRIB_texture0;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
varying vec2 varTex0;
|
||||
|
||||
void main() {
|
||||
lowp vec3 col0 = texture2D(UNI_Tex0, varTex0).rgb;
|
||||
gl_FragColor.xyz = col0;
|
||||
gl_FragColor.w = 0.5;
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
varying vec2 varTex0;
|
||||
|
||||
void main() {
|
||||
lowp vec3 col0 = texture2D(UNI_Tex0, varTex0).rgb;
|
||||
gl_FragColor.xyz = col0 * UNI_modulate.rgb;
|
||||
gl_FragColor.w = UNI_modulate.a;
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<skip />
|
||||
<string name="benchmark_all">Benchmark All</string>
|
||||
<string name="benchmark_one">Benchmark One</string>
|
||||
<string name="debug_mode">Debug Mode</string>
|
||||
</resources>
|
||||
|
@ -1,171 +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.perftest;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class FillTest implements RsBenchBaseTest{
|
||||
|
||||
private static final String TAG = "FillTest";
|
||||
private RenderScriptGL mRS;
|
||||
private Resources mRes;
|
||||
|
||||
// Custom shaders
|
||||
private ProgramFragment mProgFragmentMultitex;
|
||||
private ProgramFragment mProgFragmentSingletex;
|
||||
private ProgramFragment mProgFragmentSingletexModulate;
|
||||
private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
|
||||
int mBenchmarkDimX;
|
||||
int mBenchmarkDimY;
|
||||
|
||||
private ScriptC_fill_test mFillScript;
|
||||
ScriptField_TestScripts_s.Item[] mTests;
|
||||
ScriptField_FillTestFragData_s mFragData;
|
||||
|
||||
private final String[] mNames = {
|
||||
"Fill screen 10x singletexture",
|
||||
"Fill screen 10x 3tex multitexture",
|
||||
"Fill screen 10x blended singletexture",
|
||||
"Fill screen 10x blended 3tex multitexture",
|
||||
"Fill screen 3x modulate blended singletexture",
|
||||
"Fill screen 1x modulate blended singletexture",
|
||||
};
|
||||
|
||||
public FillTest() {
|
||||
mOptionsARGB.inScaled = false;
|
||||
mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
mBenchmarkDimX = 1280;
|
||||
mBenchmarkDimY = 720;
|
||||
}
|
||||
|
||||
void addTest(int index, int testId, int blend, int quadCount) {
|
||||
mTests[index] = new ScriptField_TestScripts_s.Item();
|
||||
mTests[index].testScript = mFillScript;
|
||||
mTests[index].testName = Allocation.createFromString(mRS,
|
||||
mNames[index],
|
||||
Allocation.USAGE_SCRIPT);
|
||||
mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
|
||||
mNames[index],
|
||||
Allocation.USAGE_SCRIPT);
|
||||
|
||||
ScriptField_FillTestData_s.Item dataItem = new ScriptField_FillTestData_s.Item();
|
||||
dataItem.testId = testId;
|
||||
dataItem.blend = blend;
|
||||
dataItem.quadCount = quadCount;
|
||||
ScriptField_FillTestData_s testData = new ScriptField_FillTestData_s(mRS, 1);
|
||||
testData.set(dataItem, 0, true);
|
||||
mTests[index].testData = testData.getAllocation();
|
||||
}
|
||||
|
||||
public boolean init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initCustomShaders();
|
||||
initFillScript();
|
||||
mTests = new ScriptField_TestScripts_s.Item[mNames.length];
|
||||
|
||||
int index = 0;
|
||||
|
||||
addTest(index++, 1 /*testId*/, 0 /*blend*/, 10 /*quadCount*/);
|
||||
addTest(index++, 0 /*testId*/, 0 /*blend*/, 10 /*quadCount*/);
|
||||
addTest(index++, 1 /*testId*/, 1 /*blend*/, 10 /*quadCount*/);
|
||||
addTest(index++, 0 /*testId*/, 1 /*blend*/, 10 /*quadCount*/);
|
||||
addTest(index++, 2 /*testId*/, 1 /*blend*/, 3 /*quadCount*/);
|
||||
addTest(index++, 2 /*testId*/, 1 /*blend*/, 1 /*quadCount*/);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ScriptField_TestScripts_s.Item[] getTests() {
|
||||
return mTests;
|
||||
}
|
||||
|
||||
public String[] getTestNames() {
|
||||
return mNames;
|
||||
}
|
||||
|
||||
private void initCustomShaders() {
|
||||
ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
pfbCustom.setShader(mRes, R.raw.multitexf);
|
||||
for (int texCount = 0; texCount < 3; texCount ++) {
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
|
||||
}
|
||||
mProgFragmentMultitex = pfbCustom.create();
|
||||
|
||||
pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
pfbCustom.setShader(mRes, R.raw.singletexf);
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
|
||||
mProgFragmentSingletex = pfbCustom.create();
|
||||
|
||||
pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
pfbCustom.setShader(mRes, R.raw.singletexfm);
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
|
||||
mFragData = new ScriptField_FillTestFragData_s(mRS, 1);
|
||||
pfbCustom.addConstant(mFragData.getType());
|
||||
mProgFragmentSingletexModulate = pfbCustom.create();
|
||||
mProgFragmentSingletexModulate.bindConstants(mFragData.getAllocation(), 0);
|
||||
}
|
||||
|
||||
private Allocation loadTextureARGB(int id) {
|
||||
Bitmap b = BitmapFactory.decodeResource(mRes, id, mOptionsARGB);
|
||||
return Allocation.createFromBitmap(mRS, b,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
}
|
||||
|
||||
private Allocation loadTextureRGB(int id) {
|
||||
return Allocation.createFromBitmapResource(mRS, mRes, id,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
}
|
||||
|
||||
void initFillScript() {
|
||||
mFillScript = new ScriptC_fill_test(mRS, mRes, R.raw.fill_test);
|
||||
|
||||
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
|
||||
ProgramVertexFixedFunction progVertex = pvb.create();
|
||||
ProgramVertexFixedFunction.Constants PVA = new ProgramVertexFixedFunction.Constants(mRS);
|
||||
((ProgramVertexFixedFunction)progVertex).bindConstants(PVA);
|
||||
Matrix4f proj = new Matrix4f();
|
||||
proj.loadOrthoWindow(mBenchmarkDimX, mBenchmarkDimY);
|
||||
PVA.setProjection(proj);
|
||||
mFillScript.set_gProgVertex(progVertex);
|
||||
|
||||
mFillScript.set_gProgFragmentTexture(mProgFragmentSingletex);
|
||||
mFillScript.set_gProgFragmentTextureModulate(mProgFragmentSingletexModulate);
|
||||
mFillScript.set_gProgFragmentMultitex(mProgFragmentMultitex);
|
||||
mFillScript.set_gProgStoreBlendNone(ProgramStore.BLEND_NONE_DEPTH_NONE(mRS));
|
||||
mFillScript.set_gProgStoreBlendAlpha(ProgramStore.BLEND_ALPHA_DEPTH_NONE(mRS));
|
||||
|
||||
mFillScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
|
||||
mFillScript.set_gLinearWrap(Sampler.WRAP_LINEAR(mRS));
|
||||
mFillScript.set_gTexTorus(loadTextureRGB(R.drawable.torusmap));
|
||||
mFillScript.set_gTexOpaque(loadTextureRGB(R.drawable.data));
|
||||
mFillScript.set_gTexTransparent(loadTextureARGB(R.drawable.leaf));
|
||||
mFillScript.set_gTexChecker(loadTextureRGB(R.drawable.checker));
|
||||
|
||||
mFillScript.bind_gFragData(mFragData);
|
||||
}
|
||||
}
|
@ -1,170 +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.perftest;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.Element.DataKind;
|
||||
import android.renderscript.Element.DataType;
|
||||
import android.renderscript.Allocation.MipmapControl;
|
||||
import android.renderscript.Program.TextureType;
|
||||
import android.renderscript.RenderScript.RSMessageHandler;
|
||||
import android.renderscript.Mesh.Primitive;
|
||||
import android.renderscript.Matrix4f;
|
||||
import android.renderscript.ProgramVertexFixedFunction;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class MeshTest implements RsBenchBaseTest{
|
||||
|
||||
private static final String TAG = "MeshTest";
|
||||
private RenderScriptGL mRS;
|
||||
private Resources mRes;
|
||||
|
||||
int mBenchmarkDimX;
|
||||
int mBenchmarkDimY;
|
||||
|
||||
private Mesh m10by10Mesh;
|
||||
private Mesh m100by100Mesh;
|
||||
private Mesh mWbyHMesh;
|
||||
|
||||
private ScriptC_mesh_test mGeoScript;
|
||||
|
||||
private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
|
||||
|
||||
ScriptField_TestScripts_s.Item[] mTests;
|
||||
|
||||
private final String[] mNames = {
|
||||
"Full screen mesh 10 by 10",
|
||||
"Full screen mesh 100 by 100",
|
||||
"Full screen mesh W / 4 by H / 4"
|
||||
};
|
||||
|
||||
public MeshTest() {
|
||||
mBenchmarkDimX = 1280;
|
||||
mBenchmarkDimY = 720;
|
||||
}
|
||||
|
||||
void addTest(int index, int meshNum) {
|
||||
mTests[index] = new ScriptField_TestScripts_s.Item();
|
||||
mTests[index].testScript = mGeoScript;
|
||||
mTests[index].testName = Allocation.createFromString(mRS,
|
||||
mNames[index],
|
||||
Allocation.USAGE_SCRIPT);
|
||||
mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
|
||||
mNames[index],
|
||||
Allocation.USAGE_SCRIPT);
|
||||
|
||||
ScriptField_MeshTestData_s.Item dataItem = new ScriptField_MeshTestData_s.Item();
|
||||
dataItem.meshNum = meshNum;
|
||||
ScriptField_MeshTestData_s testData = new ScriptField_MeshTestData_s(mRS, 1);
|
||||
testData.set(dataItem, 0, true);
|
||||
mTests[index].testData = testData.getAllocation();
|
||||
}
|
||||
|
||||
public boolean init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initGeoScript();
|
||||
mTests = new ScriptField_TestScripts_s.Item[mNames.length];
|
||||
|
||||
int index = 0;
|
||||
addTest(index++, 0 /*meshNum*/);
|
||||
addTest(index++, 1 /*meshNum*/);
|
||||
addTest(index++, 2 /*meshNum*/);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ScriptField_TestScripts_s.Item[] getTests() {
|
||||
return mTests;
|
||||
}
|
||||
|
||||
public String[] getTestNames() {
|
||||
return mNames;
|
||||
}
|
||||
|
||||
private Mesh getMbyNMesh(float width, float height, int wResolution, int hResolution) {
|
||||
|
||||
Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS,
|
||||
2, Mesh.TriangleMeshBuilder.TEXTURE_0);
|
||||
|
||||
for (int y = 0; y <= hResolution; y++) {
|
||||
final float normalizedY = (float)y / hResolution;
|
||||
final float yOffset = (normalizedY - 0.5f) * height;
|
||||
for (int x = 0; x <= wResolution; x++) {
|
||||
float normalizedX = (float)x / wResolution;
|
||||
float xOffset = (normalizedX - 0.5f) * width;
|
||||
tmb.setTexture((float)x % 2, (float)y % 2);
|
||||
tmb.addVertex(xOffset, yOffset);
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < hResolution; y++) {
|
||||
final int curY = y * (wResolution + 1);
|
||||
final int belowY = (y + 1) * (wResolution + 1);
|
||||
for (int x = 0; x < wResolution; x++) {
|
||||
int curV = curY + x;
|
||||
int belowV = belowY + x;
|
||||
tmb.addTriangle(curV, belowV, curV + 1);
|
||||
tmb.addTriangle(belowV, belowV + 1, curV + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return tmb.create(true);
|
||||
}
|
||||
|
||||
private Allocation loadTextureRGB(int id) {
|
||||
return Allocation.createFromBitmapResource(mRS, mRes, id,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
}
|
||||
|
||||
void initGeoScript() {
|
||||
mGeoScript = new ScriptC_mesh_test(mRS, mRes, R.raw.mesh_test);
|
||||
|
||||
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
|
||||
ProgramVertexFixedFunction progVertex = pvb.create();
|
||||
ProgramVertexFixedFunction.Constants PVA = new ProgramVertexFixedFunction.Constants(mRS);
|
||||
((ProgramVertexFixedFunction)progVertex).bindConstants(PVA);
|
||||
Matrix4f proj = new Matrix4f();
|
||||
proj.loadOrthoWindow(mBenchmarkDimX, mBenchmarkDimY);
|
||||
PVA.setProjection(proj);
|
||||
|
||||
mGeoScript.set_gProgVertex(progVertex);
|
||||
ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
|
||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
||||
mGeoScript.set_gProgFragmentTexture(texBuilder.create());
|
||||
mGeoScript.set_gProgStoreBlendNone(ProgramStore.BLEND_NONE_DEPTH_NONE(mRS));
|
||||
|
||||
mGeoScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
|
||||
mGeoScript.set_gTexOpaque(loadTextureRGB(R.drawable.data));
|
||||
|
||||
m10by10Mesh = getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, 10, 10);
|
||||
m100by100Mesh = getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, 100, 100);
|
||||
mWbyHMesh= getMbyNMesh(mBenchmarkDimX, mBenchmarkDimY, mBenchmarkDimX/4, mBenchmarkDimY/4);
|
||||
|
||||
mGeoScript.set_g10by10Mesh(m10by10Mesh);
|
||||
mGeoScript.set_g100by100Mesh(m100by100Mesh);
|
||||
mGeoScript.set_gWbyHMesh(mWbyHMesh);
|
||||
}
|
||||
}
|
@ -1,136 +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.perftest;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScript;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
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.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.lang.Runtime;
|
||||
|
||||
public class RsBench extends Activity {
|
||||
private final String TAG = "RsBench";
|
||||
public RsBenchView mView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
int iterations = 0;
|
||||
Intent intent = getIntent();
|
||||
Uri uri = intent.getData();
|
||||
if (uri != null) {
|
||||
// when lauched from instrumentation
|
||||
String scheme = uri.getScheme();
|
||||
if ("iterations".equals(scheme)) {
|
||||
iterations = Integer.parseInt(uri.getSchemeSpecificPart());
|
||||
}
|
||||
}
|
||||
// Create our Preview view and set it as the content of our
|
||||
// Activity
|
||||
mView = new RsBenchView(this);
|
||||
setContentView(mView);
|
||||
mView.setLoops(iterations);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity loses focus
|
||||
super.onResume();
|
||||
mView.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity loses 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.benchmark_all:
|
||||
mView.setBenchmarkMode(-1);
|
||||
mView.suspendRendering(false);
|
||||
return true;
|
||||
case R.id.benchmark_one:
|
||||
mView.suspendRendering(true);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Pick a Test");
|
||||
builder.setItems(mView.getTestNames(),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Starting to benchmark: " + mView.getTestNames()[item],
|
||||
Toast.LENGTH_SHORT).show();
|
||||
mView.setBenchmarkMode(item);
|
||||
mView.suspendRendering(false);
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
return true;
|
||||
case R.id.debug_mode:
|
||||
mView.suspendRendering(true);
|
||||
AlertDialog.Builder debugBuilder = new AlertDialog.Builder(this);
|
||||
debugBuilder.setTitle("Pick a Test");
|
||||
debugBuilder.setItems(mView.getTestNames(),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Switching to: " + mView.getTestNames()[item],
|
||||
Toast.LENGTH_SHORT).show();
|
||||
mView.setDebugMode(item);
|
||||
mView.suspendRendering(false);
|
||||
}
|
||||
});
|
||||
debugBuilder.show();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +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.perftest;
|
||||
import android.renderscript.*;
|
||||
import android.content.res.Resources;
|
||||
|
||||
interface RsBenchBaseTest {
|
||||
boolean init(RenderScriptGL rs, Resources res);
|
||||
|
||||
ScriptField_TestScripts_s.Item[] getTests();
|
||||
String[] getTestNames();
|
||||
}
|
@ -1,328 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010-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.perftest;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.Element.DataKind;
|
||||
import android.renderscript.Element.DataType;
|
||||
import android.renderscript.Allocation.MipmapControl;
|
||||
import android.renderscript.Program.TextureType;
|
||||
import android.renderscript.RenderScript.RSMessageHandler;
|
||||
import android.renderscript.Sampler.Value;
|
||||
import android.renderscript.Mesh.Primitive;
|
||||
import android.renderscript.Matrix4f;
|
||||
import android.renderscript.ProgramVertexFixedFunction;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class RsBenchRS {
|
||||
|
||||
private static final String TAG = "RsBenchRS";
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
int mLoops;
|
||||
int mCurrentLoop;
|
||||
|
||||
int mBenchmarkDimX;
|
||||
int mBenchmarkDimY;
|
||||
|
||||
public RsBenchRS() {
|
||||
}
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res, int width, int height, int loops) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mMode = 0;
|
||||
mLoops = loops;
|
||||
mCurrentLoop = 0;
|
||||
mBenchmarkDimX = 1280;
|
||||
mBenchmarkDimY = 720;
|
||||
initRS();
|
||||
}
|
||||
|
||||
private boolean stopTest = false;
|
||||
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
|
||||
private ProgramStore mProgStoreBlendNone;
|
||||
private ProgramStore mProgStoreBlendAlpha;
|
||||
|
||||
private ProgramFragment mProgFragmentTexture;
|
||||
private ProgramFragment mProgFragmentColor;
|
||||
|
||||
private ProgramVertex mProgVertex;
|
||||
private ProgramVertexFixedFunction.Constants mPVA;
|
||||
private ProgramVertexFixedFunction.Constants mPvProjectionAlloc;
|
||||
|
||||
private ScriptC_rsbench mScript;
|
||||
|
||||
ScriptField_TestScripts_s.Item[] mIndividualTests;
|
||||
|
||||
int mMode;
|
||||
|
||||
String[] mTestNames;
|
||||
float[] mLocalTestResults;
|
||||
|
||||
static Allocation createZeroTerminatedAlloc(RenderScript rs,
|
||||
String str,
|
||||
int usage) {
|
||||
byte[] allocArray = null;
|
||||
try {
|
||||
allocArray = str.getBytes("UTF-8");
|
||||
byte[] allocArrayZero = new byte[allocArray.length + 1];
|
||||
System.arraycopy(allocArray, 0, allocArrayZero, 0, allocArray.length);
|
||||
allocArrayZero[allocArrayZero.length - 1] = '\0';
|
||||
Allocation alloc = Allocation.createSized(rs, Element.U8(rs),
|
||||
allocArrayZero.length, usage);
|
||||
alloc.copyFrom(allocArrayZero);
|
||||
return alloc;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RSRuntimeException("Could not convert string to utf-8.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void appendTests(RsBenchBaseTest testSet) {
|
||||
ScriptField_TestScripts_s.Item[] newTests = testSet.getTests();
|
||||
if (mIndividualTests != null) {
|
||||
ScriptField_TestScripts_s.Item[] combined;
|
||||
combined = new ScriptField_TestScripts_s.Item[newTests.length + mIndividualTests.length];
|
||||
System.arraycopy(mIndividualTests, 0, combined, 0, mIndividualTests.length);
|
||||
System.arraycopy(newTests, 0, combined, mIndividualTests.length, newTests.length);
|
||||
mIndividualTests = combined;
|
||||
} else {
|
||||
mIndividualTests = newTests;
|
||||
}
|
||||
|
||||
String[] newNames = testSet.getTestNames();
|
||||
if (mTestNames != null) {
|
||||
String[] combinedNames;
|
||||
combinedNames = new String[newNames.length + mTestNames.length];
|
||||
System.arraycopy(mTestNames, 0, combinedNames, 0, mTestNames.length);
|
||||
System.arraycopy(newNames, 0, combinedNames, mTestNames.length, newNames.length);
|
||||
mTestNames = combinedNames;
|
||||
} else {
|
||||
mTestNames = newNames;
|
||||
}
|
||||
}
|
||||
|
||||
void createTestAllocation() {
|
||||
int numTests = mIndividualTests.length;
|
||||
mLocalTestResults = new float[numTests];
|
||||
ScriptField_TestScripts_s allTests;
|
||||
allTests = new ScriptField_TestScripts_s(mRS, numTests);
|
||||
for (int i = 0; i < numTests; i ++) {
|
||||
allTests.set(mIndividualTests[i], i, false);
|
||||
}
|
||||
allTests.copyAll();
|
||||
mScript.bind_gTestScripts(allTests);
|
||||
}
|
||||
|
||||
private void saveTestResults() {
|
||||
String state = Environment.getExternalStorageState();
|
||||
if (!Environment.MEDIA_MOUNTED.equals(state)) {
|
||||
Log.v(TAG, "sdcard is read only");
|
||||
return;
|
||||
}
|
||||
File sdCard = Environment.getExternalStorageDirectory();
|
||||
if (!sdCard.canWrite()) {
|
||||
Log.v(TAG, "ssdcard is read only");
|
||||
return;
|
||||
}
|
||||
|
||||
File resultFile = new File(sdCard, "rsbench_result" + mCurrentLoop + ".csv");
|
||||
resultFile.setWritable(true, false);
|
||||
|
||||
try {
|
||||
BufferedWriter results = new BufferedWriter(new FileWriter(resultFile));
|
||||
for (int i = 0; i < mLocalTestResults.length; i ++) {
|
||||
results.write(mTestNames[i] + ", " + mLocalTestResults[i] + ",\n");
|
||||
}
|
||||
results.close();
|
||||
Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
Log.v(TAG, "Unable to write result file " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a message handler to handle message sent from the script
|
||||
*/
|
||||
protected RSMessageHandler mRsMessage = new RSMessageHandler() {
|
||||
public void run() {
|
||||
if (mID == mScript.get_RS_MSG_RESULTS_READY()) {
|
||||
for (int i = 0; i < mLocalTestResults.length; i ++) {
|
||||
mLocalTestResults[i] = Float.intBitsToFloat(mData[i]);
|
||||
}
|
||||
saveTestResults();
|
||||
if (mLoops > 0) {
|
||||
mCurrentLoop ++;
|
||||
mCurrentLoop = mCurrentLoop % mLoops;
|
||||
}
|
||||
return;
|
||||
|
||||
} else if (mID == mScript.get_RS_MSG_TEST_DONE()) {
|
||||
synchronized(this) {
|
||||
stopTest = true;
|
||||
this.notifyAll();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
Log.v(TAG, "Perf test got unexpected message");
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Wait for message from the script
|
||||
*/
|
||||
public boolean testIsFinished() {
|
||||
synchronized(this) {
|
||||
while (true) {
|
||||
if (stopTest) {
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
this.wait(60*1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initProgramFragment() {
|
||||
|
||||
ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
|
||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
||||
mProgFragmentTexture = texBuilder.create();
|
||||
mProgFragmentTexture.bindSampler(Sampler.CLAMP_LINEAR(mRS), 0);
|
||||
|
||||
ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
colBuilder.setVaryingColor(false);
|
||||
mProgFragmentColor = colBuilder.create();
|
||||
|
||||
mScript.set_gProgFragmentTexture(mProgFragmentTexture);
|
||||
}
|
||||
|
||||
private void initProgramVertex() {
|
||||
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
|
||||
mProgVertex = pvb.create();
|
||||
|
||||
mPVA = new ProgramVertexFixedFunction.Constants(mRS);
|
||||
((ProgramVertexFixedFunction)mProgVertex).bindConstants(mPVA);
|
||||
Matrix4f proj = new Matrix4f();
|
||||
proj.loadOrthoWindow(mBenchmarkDimX, mBenchmarkDimY);
|
||||
mPVA.setProjection(proj);
|
||||
|
||||
mScript.set_gProgVertex(mProgVertex);
|
||||
}
|
||||
|
||||
private int strlen(byte[] array) {
|
||||
int count = 0;
|
||||
while(count < array.length && array[count] != 0) {
|
||||
count ++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setDebugMode(int num) {
|
||||
mScript.invoke_setDebugMode(num);
|
||||
}
|
||||
|
||||
public void setBenchmarkMode(int benchNum) {
|
||||
mScript.invoke_setBenchmarkMode(benchNum);
|
||||
}
|
||||
|
||||
public void pause(boolean pause) {
|
||||
mScript.set_gPauseRendering(pause);
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
|
||||
mScript = new ScriptC_rsbench(mRS, mRes, R.raw.rsbench);
|
||||
mRS.bindRootScript(mScript);
|
||||
|
||||
mRS.setMessageHandler(mRsMessage);
|
||||
|
||||
mScript.set_gMaxLoops(mLoops);
|
||||
|
||||
initProgramVertex();
|
||||
initProgramFragment();
|
||||
mScript.set_gFontSerif(Font.create(mRS, mRes, "serif", Font.Style.NORMAL, 8));
|
||||
|
||||
Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
|
||||
b.setX(mBenchmarkDimX).setY(mBenchmarkDimY);
|
||||
Allocation offscreen = Allocation.createTyped(mRS,
|
||||
b.create(),
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE |
|
||||
Allocation.USAGE_GRAPHICS_RENDER_TARGET);
|
||||
mScript.set_gRenderBufferColor(offscreen);
|
||||
|
||||
b = new Type.Builder(mRS,
|
||||
Element.createPixel(mRS, DataType.UNSIGNED_16,
|
||||
DataKind.PIXEL_DEPTH));
|
||||
b.setX(mBenchmarkDimX).setY(mBenchmarkDimY);
|
||||
offscreen = Allocation.createTyped(mRS,
|
||||
b.create(),
|
||||
Allocation.USAGE_GRAPHICS_RENDER_TARGET);
|
||||
mScript.set_gRenderBufferDepth(offscreen);
|
||||
mScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
|
||||
|
||||
RsBenchBaseTest test = new TextTest();
|
||||
if (test.init(mRS, mRes)) {
|
||||
appendTests(test);
|
||||
}
|
||||
test = new FillTest();
|
||||
if (test.init(mRS, mRes)) {
|
||||
appendTests(test);
|
||||
}
|
||||
test = new MeshTest();
|
||||
if (test.init(mRS, mRes)) {
|
||||
appendTests(test);
|
||||
}
|
||||
test = new TorusTest();
|
||||
if (test.init(mRS, mRes)) {
|
||||
appendTests(test);
|
||||
}
|
||||
test = new UiTest();
|
||||
if (test.init(mRS, mRes)) {
|
||||
appendTests(test);
|
||||
}
|
||||
createTestAllocation();
|
||||
|
||||
mScript.set_gLoadComplete(true);
|
||||
}
|
||||
}
|
@ -1,78 +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.perftest;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.TouchUtils;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* To run the test, please use command
|
||||
*
|
||||
* adb shell am instrument -w com.android.perftest/.RsPerfTestRunner
|
||||
*
|
||||
*/
|
||||
public class RsBenchTest extends ActivityInstrumentationTestCase2<RsBench> {
|
||||
private String TAG = "RsBenchTest";
|
||||
private int iterations = 0;
|
||||
private RsBench mAct;
|
||||
|
||||
public RsBenchTest() {
|
||||
super(RsBench.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
Instrumentation mInst = getInstrumentation();
|
||||
RsPerfTestRunner mRunner = (RsPerfTestRunner) getInstrumentation();
|
||||
iterations = mRunner.iterations;
|
||||
Log.v(TAG, "Run benchmark for " + iterations + " iterations.");
|
||||
|
||||
Uri data = Uri.fromParts("iterations", Integer.toString(iterations), null);
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.setClassName("com.android.perftest", "com.android.perftest.RsBench");
|
||||
intent.setData(data);
|
||||
mAct = (RsBench) mInst.startActivitySync(intent);
|
||||
mInst.waitForIdleSync();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
mAct.finish();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run tests and wait until the test has been run for iterations.
|
||||
*/
|
||||
@LargeTest
|
||||
public void testRsBench() {
|
||||
if (mAct.mView.testIsFinished()) {
|
||||
return;
|
||||
} else {
|
||||
fail("test didn't stop correctly");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,106 +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.perftest;
|
||||
|
||||
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.renderscript.RenderScript.RSMessageHandler;
|
||||
|
||||
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 RsBenchView extends RSSurfaceView {
|
||||
|
||||
public RsBenchView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private RsBenchRS mRender;
|
||||
private int mLoops = 0;
|
||||
|
||||
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 RsBenchRS();
|
||||
Log.v("RsBenchView", "mLoops = " + mLoops);
|
||||
mRender.init(mRS, getResources(), w, h, mLoops);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
if (mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScriptGL();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the total number of loops the benchmark tests will run
|
||||
* before the test results are collected.
|
||||
*/
|
||||
public void setLoops(int iterations) {
|
||||
if (iterations > 0) {
|
||||
mLoops = iterations;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for message from the script
|
||||
*/
|
||||
public boolean testIsFinished() {
|
||||
return mRender.testIsFinished();
|
||||
}
|
||||
|
||||
void setBenchmarkMode(int benchNum) {
|
||||
mRender.setBenchmarkMode(benchNum);
|
||||
}
|
||||
|
||||
void suspendRendering(boolean pause) {
|
||||
mRender.pause(pause);
|
||||
}
|
||||
|
||||
void setDebugMode(int num) {
|
||||
mRender.setDebugMode(num);
|
||||
}
|
||||
|
||||
String[] getTestNames() {
|
||||
return mRender.mTestNames;
|
||||
}
|
||||
}
|
@ -1,56 +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.perftest;
|
||||
|
||||
//import com.android.perftest.RsBenchTest;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.test.InstrumentationTestRunner;
|
||||
import android.test.InstrumentationTestSuite;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Run the RenderScript Performance Test
|
||||
* adb shell am instrument -w com.android.perftest/.RsPerfTestRunner
|
||||
*
|
||||
* with specified iterations:
|
||||
* adb shell am instrument -e iterations <n> -w com.android.perftest/.RsPerfTestRunner
|
||||
*
|
||||
*/
|
||||
public class RsPerfTestRunner extends InstrumentationTestRunner {
|
||||
public int iterations = 10;
|
||||
|
||||
@Override
|
||||
public TestSuite getAllTests() {
|
||||
TestSuite suite = new InstrumentationTestSuite(this);
|
||||
suite.addTestSuite(RsBenchTest.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
String strValue = (String)icicle.get("iterations");
|
||||
if (strValue != null) {
|
||||
int intValue = Integer.parseInt(strValue);
|
||||
if (iterations > 0) {
|
||||
iterations = intValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,93 +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.perftest;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class TextTest implements RsBenchBaseTest{
|
||||
|
||||
private static final String TAG = "TextTest";
|
||||
private RenderScriptGL mRS;
|
||||
private Resources mRes;
|
||||
|
||||
private ScriptC_text_test mTextScript;
|
||||
ScriptField_TestScripts_s.Item[] mTests;
|
||||
|
||||
private final String[] mNames = {
|
||||
"Fill screen with text 1 time",
|
||||
"Fill screen with text 3 times",
|
||||
"Fill screen with text 5 times"
|
||||
};
|
||||
|
||||
public TextTest() {
|
||||
}
|
||||
|
||||
void addTest(int index, int fillNum) {
|
||||
mTests[index] = new ScriptField_TestScripts_s.Item();
|
||||
mTests[index].testScript = mTextScript;
|
||||
mTests[index].testName = Allocation.createFromString(mRS,
|
||||
mNames[index],
|
||||
Allocation.USAGE_SCRIPT);
|
||||
mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
|
||||
mNames[index],
|
||||
Allocation.USAGE_SCRIPT);
|
||||
|
||||
ScriptField_TextTestData_s.Item dataItem = new ScriptField_TextTestData_s.Item();
|
||||
dataItem.fillNum = fillNum;
|
||||
ScriptField_TextTestData_s testData = new ScriptField_TextTestData_s(mRS, 1);
|
||||
testData.set(dataItem, 0, true);
|
||||
mTests[index].testData = testData.getAllocation();
|
||||
}
|
||||
|
||||
public boolean init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initTextScript();
|
||||
mTests = new ScriptField_TestScripts_s.Item[mNames.length];
|
||||
|
||||
int index = 0;
|
||||
addTest(index++, 1 /*fillNum*/);
|
||||
addTest(index++, 3 /*fillNum*/);
|
||||
addTest(index++, 5 /*fillNum*/);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ScriptField_TestScripts_s.Item[] getTests() {
|
||||
return mTests;
|
||||
}
|
||||
|
||||
public String[] getTestNames() {
|
||||
return mNames;
|
||||
}
|
||||
|
||||
void initTextScript() {
|
||||
DisplayMetrics metrics = mRes.getDisplayMetrics();
|
||||
|
||||
mTextScript = new ScriptC_text_test(mRS, mRes, R.raw.text_test);
|
||||
mTextScript.set_gFontSans(Font.create(mRS, mRes, "sans-serif",
|
||||
Font.Style.NORMAL, 8.0f / metrics.density));
|
||||
mTextScript.set_gFontSerif(Font.create(mRS, mRes, "serif",
|
||||
Font.Style.NORMAL, 8.0f / metrics.density));
|
||||
}
|
||||
}
|
@ -1,272 +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.perftest;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.renderscript.*;
|
||||
import android.renderscript.Element.DataKind;
|
||||
import android.renderscript.Element.DataType;
|
||||
import android.renderscript.Allocation.MipmapControl;
|
||||
import android.renderscript.Program.TextureType;
|
||||
import android.renderscript.RenderScript.RSMessageHandler;
|
||||
import android.renderscript.Mesh.Primitive;
|
||||
import android.renderscript.Matrix4f;
|
||||
import android.renderscript.ProgramVertexFixedFunction;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class TorusTest implements RsBenchBaseTest{
|
||||
|
||||
private static final String TAG = "TorusTest";
|
||||
private RenderScriptGL mRS;
|
||||
private Resources mRes;
|
||||
|
||||
private ProgramStore mProgStoreBlendNoneDepth;
|
||||
private ProgramStore mProgStoreBlendNone;
|
||||
private ProgramStore mProgStoreBlendAlpha;
|
||||
|
||||
private ProgramFragment mProgFragmentTexture;
|
||||
private ProgramFragment mProgFragmentColor;
|
||||
|
||||
private ProgramVertex mProgVertex;
|
||||
private ProgramVertexFixedFunction.Constants mPVA;
|
||||
private ProgramVertexFixedFunction.Constants mPvProjectionAlloc;
|
||||
|
||||
// Custom shaders
|
||||
private ProgramVertex mProgVertexCustom;
|
||||
private ProgramFragment mProgFragmentCustom;
|
||||
private ProgramFragment mProgFragmentMultitex;
|
||||
private ProgramVertex mProgVertexPixelLight;
|
||||
private ProgramVertex mProgVertexPixelLightMove;
|
||||
private ProgramFragment mProgFragmentPixelLight;
|
||||
private ScriptField_VertexShaderConstants_s mVSConst;
|
||||
private ScriptField_FragentShaderConstants_s mFSConst;
|
||||
private ScriptField_VertexShaderConstants3_s mVSConstPixel;
|
||||
private ScriptField_FragentShaderConstants3_s mFSConstPixel;
|
||||
|
||||
private Allocation mTexTorus;
|
||||
private Mesh mTorus;
|
||||
|
||||
private ScriptC_torus_test mTorusScript;
|
||||
|
||||
private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
|
||||
|
||||
ScriptField_TestScripts_s.Item[] mTests;
|
||||
|
||||
private final String[] mNames = {
|
||||
"Geo test 25.6k flat color",
|
||||
"Geo test 51.2k flat color",
|
||||
"Geo test 204.8k small tries flat color",
|
||||
"Geo test 25.6k single texture",
|
||||
"Geo test 51.2k single texture",
|
||||
"Geo test 204.8k small tries single texture",
|
||||
"Geo test 25.6k geo heavy vertex",
|
||||
"Geo test 51.2k geo heavy vertex",
|
||||
"Geo test 204.8k geo raster load heavy vertex",
|
||||
"Geo test 25.6k heavy fragment",
|
||||
"Geo test 51.2k heavy fragment",
|
||||
"Geo test 204.8k small tries heavy fragment",
|
||||
"Geo test 25.6k heavy fragment heavy vertex",
|
||||
"Geo test 51.2k heavy fragment heavy vertex",
|
||||
"Geo test 204.8k small tries heavy fragment heavy vertex"
|
||||
};
|
||||
|
||||
public TorusTest() {
|
||||
}
|
||||
|
||||
void addTest(int index, int testId, int user1, int user2) {
|
||||
mTests[index] = new ScriptField_TestScripts_s.Item();
|
||||
mTests[index].testScript = mTorusScript;
|
||||
mTests[index].testName = Allocation.createFromString(mRS,
|
||||
mNames[index],
|
||||
Allocation.USAGE_SCRIPT);
|
||||
mTests[index].debugName = RsBenchRS.createZeroTerminatedAlloc(mRS,
|
||||
mNames[index],
|
||||
Allocation.USAGE_SCRIPT);
|
||||
|
||||
ScriptField_TorusTestData_s.Item dataItem = new ScriptField_TorusTestData_s.Item();
|
||||
dataItem.testId = testId;
|
||||
dataItem.user1 = user1;
|
||||
dataItem.user2 = user2;
|
||||
ScriptField_TorusTestData_s testData = new ScriptField_TorusTestData_s(mRS, 1);
|
||||
testData.set(dataItem, 0, true);
|
||||
mTests[index].testData = testData.getAllocation();
|
||||
}
|
||||
|
||||
public boolean init(RenderScriptGL rs, Resources res) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initCustomShaders();
|
||||
loadImages();
|
||||
initMesh();
|
||||
initTorusScript();
|
||||
mTests = new ScriptField_TestScripts_s.Item[mNames.length];
|
||||
|
||||
int index = 0;
|
||||
addTest(index++, 0, 0 /*useTexture*/, 1 /*numMeshes*/);
|
||||
addTest(index++, 0, 0 /*useTexture*/, 2 /*numMeshes*/);
|
||||
addTest(index++, 0, 0 /*useTexture*/, 8 /*numMeshes*/);
|
||||
addTest(index++, 0, 1 /*useTexture*/, 1 /*numMeshes*/);
|
||||
addTest(index++, 0, 1 /*useTexture*/, 2 /*numMeshes*/);
|
||||
addTest(index++, 0, 1 /*useTexture*/, 8 /*numMeshes*/);
|
||||
|
||||
// Secont test
|
||||
addTest(index++, 1, 1 /*numMeshes*/, 0 /*unused*/);
|
||||
addTest(index++, 1, 2 /*numMeshes*/, 0 /*unused*/);
|
||||
addTest(index++, 1, 8 /*numMeshes*/, 0 /*unused*/);
|
||||
|
||||
// Third test
|
||||
addTest(index++, 2, 1 /*numMeshes*/, 0 /*heavyVertex*/);
|
||||
addTest(index++, 2, 2 /*numMeshes*/, 0 /*heavyVertex*/);
|
||||
addTest(index++, 2, 8 /*numMeshes*/, 0 /*heavyVertex*/);
|
||||
addTest(index++, 2, 1 /*numMeshes*/, 1 /*heavyVertex*/);
|
||||
addTest(index++, 2, 2 /*numMeshes*/, 1 /*heavyVertex*/);
|
||||
addTest(index++, 2, 8 /*numMeshes*/, 1 /*heavyVertex*/);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ScriptField_TestScripts_s.Item[] getTests() {
|
||||
return mTests;
|
||||
}
|
||||
|
||||
public String[] getTestNames() {
|
||||
return mNames;
|
||||
}
|
||||
|
||||
private void initCustomShaders() {
|
||||
mVSConst = new ScriptField_VertexShaderConstants_s(mRS, 1);
|
||||
mFSConst = new ScriptField_FragentShaderConstants_s(mRS, 1);
|
||||
|
||||
mVSConstPixel = new ScriptField_VertexShaderConstants3_s(mRS, 1);
|
||||
mFSConstPixel = new ScriptField_FragentShaderConstants3_s(mRS, 1);
|
||||
|
||||
// Initialize the shader builder
|
||||
ProgramVertex.Builder pvbCustom = new ProgramVertex.Builder(mRS);
|
||||
// Specify the resource that contains the shader string
|
||||
pvbCustom.setShader(mRes, R.raw.shaderv);
|
||||
// Use a script field to specify the input layout
|
||||
pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
|
||||
// Define the constant input layout
|
||||
pvbCustom.addConstant(mVSConst.getAllocation().getType());
|
||||
mProgVertexCustom = pvbCustom.create();
|
||||
// Bind the source of constant data
|
||||
mProgVertexCustom.bindConstants(mVSConst.getAllocation(), 0);
|
||||
|
||||
ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
// Specify the resource that contains the shader string
|
||||
pfbCustom.setShader(mRes, R.raw.shaderf);
|
||||
// Tell the builder how many textures we have
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
|
||||
// Define the constant input layout
|
||||
pfbCustom.addConstant(mFSConst.getAllocation().getType());
|
||||
mProgFragmentCustom = pfbCustom.create();
|
||||
// Bind the source of constant data
|
||||
mProgFragmentCustom.bindConstants(mFSConst.getAllocation(), 0);
|
||||
|
||||
pvbCustom = new ProgramVertex.Builder(mRS);
|
||||
pvbCustom.setShader(mRes, R.raw.shader2v);
|
||||
pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
|
||||
pvbCustom.addConstant(mVSConstPixel.getAllocation().getType());
|
||||
mProgVertexPixelLight = pvbCustom.create();
|
||||
mProgVertexPixelLight.bindConstants(mVSConstPixel.getAllocation(), 0);
|
||||
|
||||
pvbCustom = new ProgramVertex.Builder(mRS);
|
||||
pvbCustom.setShader(mRes, R.raw.shader2movev);
|
||||
pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
|
||||
pvbCustom.addConstant(mVSConstPixel.getAllocation().getType());
|
||||
mProgVertexPixelLightMove = pvbCustom.create();
|
||||
mProgVertexPixelLightMove.bindConstants(mVSConstPixel.getAllocation(), 0);
|
||||
|
||||
pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
pfbCustom.setShader(mRes, R.raw.shader2f);
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
|
||||
pfbCustom.addConstant(mFSConstPixel.getAllocation().getType());
|
||||
mProgFragmentPixelLight = pfbCustom.create();
|
||||
mProgFragmentPixelLight.bindConstants(mFSConstPixel.getAllocation(), 0);
|
||||
|
||||
pfbCustom = new ProgramFragment.Builder(mRS);
|
||||
pfbCustom.setShader(mRes, R.raw.multitexf);
|
||||
for (int texCount = 0; texCount < 3; texCount ++) {
|
||||
pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
|
||||
}
|
||||
mProgFragmentMultitex = pfbCustom.create();
|
||||
|
||||
ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
colBuilder.setVaryingColor(false);
|
||||
mProgFragmentColor = colBuilder.create();
|
||||
|
||||
ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
|
||||
texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
|
||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
||||
mProgFragmentTexture = texBuilder.create();
|
||||
|
||||
ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
|
||||
mProgVertex = pvb.create();
|
||||
ProgramVertexFixedFunction.Constants PVA = new ProgramVertexFixedFunction.Constants(mRS);
|
||||
((ProgramVertexFixedFunction)mProgVertex).bindConstants(PVA);
|
||||
Matrix4f proj = new Matrix4f();
|
||||
proj.loadOrthoWindow(1280, 720);
|
||||
PVA.setProjection(proj);
|
||||
}
|
||||
|
||||
private Allocation loadTextureRGB(int id) {
|
||||
return Allocation.createFromBitmapResource(mRS, mRes, id,
|
||||
Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
|
||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
||||
}
|
||||
|
||||
private void loadImages() {
|
||||
mTexTorus = loadTextureRGB(R.drawable.torusmap);
|
||||
}
|
||||
|
||||
private void initMesh() {
|
||||
FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus);
|
||||
FileA3D.IndexEntry entry = model.getIndexEntry(0);
|
||||
if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) {
|
||||
Log.e("rs", "could not load model");
|
||||
} else {
|
||||
mTorus = (Mesh)entry.getObject();
|
||||
}
|
||||
}
|
||||
|
||||
void initTorusScript() {
|
||||
mTorusScript = new ScriptC_torus_test(mRS, mRes, R.raw.torus_test);
|
||||
mTorusScript.set_gCullFront(ProgramRaster.CULL_FRONT(mRS));
|
||||
mTorusScript.set_gCullBack(ProgramRaster.CULL_BACK(mRS));
|
||||
mTorusScript.set_gLinearClamp(Sampler.CLAMP_LINEAR(mRS));
|
||||
mTorusScript.set_gTorusMesh(mTorus);
|
||||
mTorusScript.set_gTexTorus(mTexTorus);
|
||||
mTorusScript.set_gProgVertexCustom(mProgVertexCustom);
|
||||
mTorusScript.set_gProgFragmentCustom(mProgFragmentCustom);
|
||||
mTorusScript.set_gProgVertexPixelLight(mProgVertexPixelLight);
|
||||
mTorusScript.set_gProgVertexPixelLightMove(mProgVertexPixelLightMove);
|
||||
mTorusScript.set_gProgFragmentPixelLight(mProgFragmentPixelLight);
|
||||
mTorusScript.bind_gVSConstPixel(mVSConstPixel);
|
||||
mTorusScript.bind_gFSConstPixel(mFSConstPixel);
|
||||
mTorusScript.bind_gVSConstants(mVSConst);
|
||||
mTorusScript.bind_gFSConstants(mFSConst);
|
||||
mTorusScript.set_gProgVertex(mProgVertex);
|
||||
mTorusScript.set_gProgFragmentTexture(mProgFragmentTexture);
|
||||
mTorusScript.set_gProgFragmentColor(mProgFragmentColor);
|
||||
mTorusScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth);
|
||||
}
|
||||
}
|