Merge "Remove the obsolete film example."
@@ -1,27 +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 := optional
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
|
||||
|
||||
LOCAL_PACKAGE_NAME := Film
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.film">
|
||||
<application android:label="Film">
|
||||
<activity android:name="Film"
|
||||
android:screenOrientation="portrait"
|
||||
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: 248 KiB |
|
Before Width: | Height: | Size: 136 KiB |
|
Before Width: | Height: | Size: 149 KiB |
|
Before Width: | Height: | Size: 274 KiB |
|
Before Width: | Height: | Size: 342 KiB |
|
Before Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 136 KiB |
|
Before Width: | Height: | Size: 314 KiB |
|
Before Width: | Height: | Size: 274 KiB |
|
Before Width: | Height: | Size: 358 KiB |
|
Before Width: | Height: | Size: 312 KiB |
|
Before Width: | Height: | Size: 360 KiB |
|
Before Width: | Height: | Size: 305 KiB |
@@ -1,110 +0,0 @@
|
||||
// Fountain test script
|
||||
|
||||
#pragma version(1)
|
||||
#pragma stateVertex(orthoWindow)
|
||||
#pragma stateRaster(flat)
|
||||
#pragma stateFragment(PgmFragBackground)
|
||||
#pragma stateStore(MyBlend)
|
||||
|
||||
|
||||
int main(void* con, int ft, int launchID) {
|
||||
int count, touch, x, y, rate, maxLife, lifeShift;
|
||||
int life;
|
||||
int ct, ct2;
|
||||
int newPart;
|
||||
int drawCount;
|
||||
int dx, dy, idx;
|
||||
int posx,posy;
|
||||
int c;
|
||||
int srcIdx;
|
||||
int dstIdx;
|
||||
|
||||
count = loadI32(con, 0, 1);
|
||||
touch = loadI32(con, 0, 2);
|
||||
x = loadI32(con, 0, 3);
|
||||
y = loadI32(con, 0, 4);
|
||||
|
||||
rate = 4;
|
||||
maxLife = (count / rate) - 1;
|
||||
lifeShift = 0;
|
||||
{
|
||||
life = maxLife;
|
||||
while (life > 255) {
|
||||
life = life >> 1;
|
||||
lifeShift ++;
|
||||
}
|
||||
}
|
||||
|
||||
drawRect(con, 0, 256, 0, 512);
|
||||
contextBindProgramFragment(con, NAMED_PgmFragParts);
|
||||
|
||||
if (touch) {
|
||||
newPart = loadI32(con, 2, 0);
|
||||
for (ct2=0; ct2<rate; ct2++) {
|
||||
dx = scriptRand(con, 0x10000) - 0x8000;
|
||||
dy = scriptRand(con, 0x10000) - 0x8000;
|
||||
|
||||
idx = newPart * 5 + 1;
|
||||
storeI32(con, 2, idx, dx);
|
||||
storeI32(con, 2, idx + 1, dy);
|
||||
storeI32(con, 2, idx + 2, maxLife);
|
||||
storeI32(con, 2, idx + 3, x << 16);
|
||||
storeI32(con, 2, idx + 4, y << 16);
|
||||
|
||||
newPart++;
|
||||
if (newPart >= count) {
|
||||
newPart = 0;
|
||||
}
|
||||
}
|
||||
storeI32(con, 2, 0, newPart);
|
||||
}
|
||||
|
||||
drawCount = 0;
|
||||
for (ct=0; ct < count; ct++) {
|
||||
srcIdx = ct * 5 + 1;
|
||||
|
||||
dx = loadI32(con, 2, srcIdx);
|
||||
dy = loadI32(con, 2, srcIdx + 1);
|
||||
life = loadI32(con, 2, srcIdx + 2);
|
||||
posx = loadI32(con, 2, srcIdx + 3);
|
||||
posy = loadI32(con, 2, srcIdx + 4);
|
||||
|
||||
if (life) {
|
||||
if (posy < (480 << 16)) {
|
||||
dstIdx = drawCount * 9;
|
||||
c = 0xffafcf | ((life >> lifeShift) << 24);
|
||||
|
||||
storeU32(con, 1, dstIdx, c);
|
||||
storeI32(con, 1, dstIdx + 1, posx);
|
||||
storeI32(con, 1, dstIdx + 2, posy);
|
||||
|
||||
storeU32(con, 1, dstIdx + 3, c);
|
||||
storeI32(con, 1, dstIdx + 4, posx + 0x10000);
|
||||
storeI32(con, 1, dstIdx + 5, posy + dy * 4);
|
||||
|
||||
storeU32(con, 1, dstIdx + 6, c);
|
||||
storeI32(con, 1, dstIdx + 7, posx - 0x10000);
|
||||
storeI32(con, 1, dstIdx + 8, posy + dy * 4);
|
||||
drawCount ++;
|
||||
} else {
|
||||
if (dy > 0) {
|
||||
dy = (-dy) >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
posx = posx + dx;
|
||||
posy = posy + dy;
|
||||
dy = dy + 0x400;
|
||||
life --;
|
||||
|
||||
//storeI32(con, 2, srcIdx, dx);
|
||||
storeI32(con, 2, srcIdx + 1, dy);
|
||||
storeI32(con, 2, srcIdx + 2, life);
|
||||
storeI32(con, 2, srcIdx + 3, posx);
|
||||
storeI32(con, 2, srcIdx + 4, posy);
|
||||
}
|
||||
}
|
||||
|
||||
drawTriangleArray(con, NAMED_PartBuffer, drawCount);
|
||||
return 1;
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
// Fountain test script
|
||||
|
||||
#pragma version(1)
|
||||
#pragma stateVertex(PVBackground)
|
||||
#pragma stateFragment(PFBackground)
|
||||
#pragma stateStore(PSBackground)
|
||||
|
||||
#define STATE_TRIANGLE_OFFSET_COUNT 0
|
||||
#define STATE_LAST_FOCUS 1
|
||||
|
||||
|
||||
// The script enviroment has 3 env allocations.
|
||||
// bank0: (r) The enviroment structure
|
||||
// bank1: (r) The position information
|
||||
// bank2: (rw) The temporary texture state
|
||||
|
||||
int lastFocus;
|
||||
|
||||
int main(int index)
|
||||
{
|
||||
float mat1[16];
|
||||
|
||||
float trans = Pos->translate;
|
||||
float rot = Pos->rotate;
|
||||
|
||||
matrixLoadScale(mat1, 2.f, 2.f, 2.f);
|
||||
matrixTranslate(mat1, 0.f, 0.f, trans);
|
||||
matrixRotate(mat1, 90.f, 0.f, 0.f, 1.f);
|
||||
matrixRotate(mat1, rot, 1.f, 0.f, 0.f);
|
||||
vpLoadModelMatrix(mat1);
|
||||
|
||||
// Draw the lighting effect in the strip and fill the Z buffer.
|
||||
drawSimpleMesh(NAMED_mesh);
|
||||
|
||||
// Start of images.
|
||||
bindProgramStore(NAMED_PSImages);
|
||||
bindProgramFragment(NAMED_PFImages);
|
||||
bindProgramVertex(NAMED_PVImages);
|
||||
|
||||
float focusPos = Pos->focus;
|
||||
int focusID = 0;
|
||||
int lastFocusID = loadI32(2, STATE_LAST_FOCUS);
|
||||
int imgCount = 13;
|
||||
|
||||
if (trans > (-.3f)) {
|
||||
focusID = -1.0f - focusPos;
|
||||
if (focusID >= imgCount) {
|
||||
focusID = -1;
|
||||
}
|
||||
} else {
|
||||
focusID = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
if (focusID != lastFocusID) {
|
||||
if (lastFocusID >= 0) {
|
||||
uploadToTexture(con, env->tex[lastFocusID], 1);
|
||||
}
|
||||
if (focusID >= 0) {
|
||||
uploadToTexture(con, env->tex[focusID], 0);
|
||||
}
|
||||
}
|
||||
*/
|
||||
lastFocus = focusID;
|
||||
|
||||
int triangleOffsetsCount = Pos->triangleOffsetCount;
|
||||
|
||||
int imgId = 0;
|
||||
for (imgId=1; imgId <= imgCount; imgId++) {
|
||||
float pos = focusPos + imgId + 0.4f;
|
||||
int offset = (int)floorf(pos * 2.f);
|
||||
pos = pos - 0.75f;
|
||||
|
||||
offset = offset + triangleOffsetsCount / 2;
|
||||
if (!((offset < 0) || (offset >= triangleOffsetsCount))) {
|
||||
int start = offset -2;
|
||||
int end = offset + 2;
|
||||
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
if (end >= triangleOffsetsCount) {
|
||||
end = triangleOffsetsCount-1;
|
||||
}
|
||||
|
||||
bindTexture(NAMED_PFImages, 0, loadI32(0, imgId - 1));
|
||||
matrixLoadTranslate(mat1, -pos - loadF(5, triangleOffsetsCount / 2), 0, 0);
|
||||
vpLoadTextureMatrix(mat1);
|
||||
drawSimpleMeshRange(NAMED_mesh, loadI32(4, start), (loadI32(4, end) - loadI32(4, start)));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,90 +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.film;
|
||||
|
||||
import android.renderscript.RSSurfaceView;
|
||||
import android.renderscript.RenderScript;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.provider.Settings.System;
|
||||
import android.util.Config;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.lang.Runtime;
|
||||
|
||||
public class Film extends Activity {
|
||||
//EventListener mListener = new EventListener();
|
||||
|
||||
private static final String LOG_TAG = "libRS_jni";
|
||||
private static final boolean DEBUG = false;
|
||||
private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
|
||||
|
||||
private FilmView mView;
|
||||
|
||||
// get the current looper (from your Activity UI thread for instance
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
// Create our Preview view and set it as the content of our
|
||||
// Activity
|
||||
mView = new FilmView(this);
|
||||
setContentView(mView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity looses focus
|
||||
super.onResume();
|
||||
mView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity looses focus
|
||||
super.onPause();
|
||||
mView.onPause();
|
||||
|
||||
Runtime.getRuntime().exit(0);
|
||||
}
|
||||
|
||||
|
||||
static void log(String message) {
|
||||
if (LOG_ENABLED) {
|
||||
Log.v(LOG_TAG, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,253 +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.film;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import android.renderscript.*;
|
||||
|
||||
public class FilmRS {
|
||||
class StripPosition {
|
||||
public float translate;
|
||||
public float rotate;
|
||||
public float focus;
|
||||
public int triangleOffsetCount;
|
||||
}
|
||||
StripPosition mPos = new StripPosition();
|
||||
|
||||
|
||||
private final int STATE_LAST_FOCUS = 1;
|
||||
|
||||
public FilmRS() {
|
||||
}
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res, int width, int height) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
initRS();
|
||||
}
|
||||
|
||||
public void setFilmStripPosition(int x, int y)
|
||||
{
|
||||
if (x < 50) {
|
||||
x = 50;
|
||||
}
|
||||
if (x > 270) {
|
||||
x = 270;
|
||||
}
|
||||
|
||||
float anim = ((float)x-50) / 270.f;
|
||||
mPos.translate = 2f * anim + 0.5f; // translation
|
||||
mPos.rotate = (anim * 40); // rotation
|
||||
mPos.focus = ((float)y) / 16.f - 10.f; // focusPos
|
||||
mPos.triangleOffsetCount = mFSM.mTriangleOffsetsCount;
|
||||
mAllocPos.data(mPos);
|
||||
}
|
||||
|
||||
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
private Script mScriptStrip;
|
||||
private Script mScriptImage;
|
||||
private Sampler mSampler;
|
||||
private ProgramStore mPSBackground;
|
||||
private ProgramStore mPSImages;
|
||||
private ProgramFragment mPFBackground;
|
||||
private ProgramFragment mPFImages;
|
||||
private ProgramVertex mPVBackground;
|
||||
private ProgramVertex mPVImages;
|
||||
private ProgramVertex.MatrixAllocation mPVA;
|
||||
private Type mStripPositionType;
|
||||
|
||||
private Allocation mImages[];
|
||||
private Allocation mAllocIDs;
|
||||
private Allocation mAllocPos;
|
||||
private Allocation mAllocState;
|
||||
private Allocation mAllocPV;
|
||||
private Allocation mAllocOffsetsTex;
|
||||
private Allocation mAllocOffsets;
|
||||
|
||||
private SimpleMesh mMesh;
|
||||
private Light mLight;
|
||||
|
||||
private FilmStripMesh mFSM;
|
||||
|
||||
private int[] mBufferIDs;
|
||||
private float[] mBufferPos = new float[3];
|
||||
private int[] mBufferState;
|
||||
|
||||
private void initPFS() {
|
||||
ProgramStore.Builder b = new ProgramStore.Builder(mRS, null, null);
|
||||
|
||||
b.setDepthFunc(ProgramStore.DepthFunc.LESS);
|
||||
b.setDitherEnable(true);
|
||||
b.setDepthMask(true);
|
||||
mPSBackground = b.create();
|
||||
mPSBackground.setName("PSBackground");
|
||||
|
||||
b.setDepthFunc(ProgramStore.DepthFunc.EQUAL);
|
||||
b.setDitherEnable(false);
|
||||
b.setDepthMask(false);
|
||||
b.setBlendFunc(ProgramStore.BlendSrcFunc.ONE,
|
||||
ProgramStore.BlendDstFunc.ONE);
|
||||
mPSImages = b.create();
|
||||
mPSImages.setName("PSImages");
|
||||
}
|
||||
|
||||
private void initPF() {
|
||||
Sampler.Builder bs = new Sampler.Builder(mRS);
|
||||
bs.setMin(Sampler.Value.LINEAR);//_MIP_LINEAR);
|
||||
bs.setMag(Sampler.Value.LINEAR);
|
||||
bs.setWrapS(Sampler.Value.CLAMP);
|
||||
bs.setWrapT(Sampler.Value.WRAP);
|
||||
mSampler = bs.create();
|
||||
|
||||
ProgramFragment.Builder b = new ProgramFragment.Builder(mRS);
|
||||
mPFBackground = b.create();
|
||||
mPFBackground.setName("PFBackground");
|
||||
|
||||
b = new ProgramFragment.Builder(mRS);
|
||||
b.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
|
||||
ProgramFragment.Builder.Format.RGBA, 0);
|
||||
mPFImages = b.create();
|
||||
mPFImages.bindSampler(mSampler, 0);
|
||||
mPFImages.setName("PFImages");
|
||||
}
|
||||
|
||||
private void initPV() {
|
||||
mLight = (new Light.Builder(mRS)).create();
|
||||
mLight.setPosition(0, -0.5f, -1.0f);
|
||||
|
||||
ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
|
||||
//pvb.addLight(mLight);
|
||||
mPVBackground = pvb.create();
|
||||
mPVBackground.setName("PVBackground");
|
||||
|
||||
pvb = new ProgramVertex.Builder(mRS, null, null);
|
||||
pvb.setTextureMatrixEnable(true);
|
||||
mPVImages = pvb.create();
|
||||
mPVImages.setName("PVImages");
|
||||
}
|
||||
|
||||
private void loadImages() {
|
||||
mBufferIDs = new int[13];
|
||||
mImages = new Allocation[13];
|
||||
mAllocIDs = Allocation.createSized(mRS,
|
||||
Element.createUser(mRS, Element.DataType.FLOAT_32),
|
||||
mBufferIDs.length);
|
||||
|
||||
Element ie = Element.createPixel(mRS, Element.DataType.UNSIGNED_5_6_5, Element.DataKind.PIXEL_RGB);
|
||||
mImages[0] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p01, ie, true);
|
||||
mImages[1] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p02, ie, true);
|
||||
mImages[2] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p03, ie, true);
|
||||
mImages[3] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p04, ie, true);
|
||||
mImages[4] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p05, ie, true);
|
||||
mImages[5] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p06, ie, true);
|
||||
mImages[6] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p07, ie, true);
|
||||
mImages[7] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p08, ie, true);
|
||||
mImages[8] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p09, ie, true);
|
||||
mImages[9] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p10, ie, true);
|
||||
mImages[10] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p11, ie, true);
|
||||
mImages[11] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p12, ie, true);
|
||||
mImages[12] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p13, ie, true);
|
||||
|
||||
int black[] = new int[1024];
|
||||
for(int ct=0; ct < mImages.length; ct++) {
|
||||
Allocation.Adapter2D a = mImages[ct].createAdapter2D();
|
||||
|
||||
int size = 512;
|
||||
int mip = 0;
|
||||
while(size >= 2) {
|
||||
a.subData(0, 0, 2, size, black);
|
||||
a.subData(size-2, 0, 2, size, black);
|
||||
a.subData(0, 0, size, 2, black);
|
||||
a.subData(0, size-2, size, 2, black);
|
||||
size >>= 1;
|
||||
mip++;
|
||||
a.setConstraint(Dimension.LOD, mip);
|
||||
}
|
||||
|
||||
mImages[ct].uploadToTexture(1);
|
||||
mBufferIDs[ct] = mImages[ct].getID();
|
||||
}
|
||||
mAllocIDs.data(mBufferIDs);
|
||||
}
|
||||
|
||||
private void initState()
|
||||
{
|
||||
mBufferState = new int[10];
|
||||
mAllocState = Allocation.createSized(mRS,
|
||||
Element.createUser(mRS, Element.DataType.FLOAT_32),
|
||||
mBufferState.length);
|
||||
mBufferState[STATE_LAST_FOCUS] = -1;
|
||||
mAllocState.data(mBufferState);
|
||||
}
|
||||
|
||||
private void initRS() {
|
||||
mFSM = new FilmStripMesh();
|
||||
mMesh = mFSM.init(mRS);
|
||||
mMesh.setName("mesh");
|
||||
|
||||
initPFS();
|
||||
initPF();
|
||||
initPV();
|
||||
|
||||
Log.e("rs", "Done loading named");
|
||||
|
||||
ScriptC.Builder sb = new ScriptC.Builder(mRS);
|
||||
sb.setScript(mRes, R.raw.filmstrip);
|
||||
mScriptStrip = sb.create();
|
||||
|
||||
mAllocPos = Allocation.createTyped(mRS, mStripPositionType);
|
||||
|
||||
loadImages();
|
||||
initState();
|
||||
|
||||
mPVA = new ProgramVertex.MatrixAllocation(mRS);
|
||||
mPVBackground.bindAllocation(mPVA);
|
||||
mPVImages.bindAllocation(mPVA);
|
||||
mPVA.setupProjectionNormalized(320, 480);
|
||||
|
||||
|
||||
mScriptStrip.bindAllocation(mAllocIDs, 0);
|
||||
mScriptStrip.bindAllocation(mAllocPos, 1);
|
||||
mScriptStrip.bindAllocation(mAllocState, 2);
|
||||
mScriptStrip.bindAllocation(mPVA.mAlloc, 3);
|
||||
|
||||
|
||||
mAllocOffsets = Allocation.createSized(mRS,
|
||||
Element.createUser(mRS, Element.DataType.SIGNED_32), mFSM.mTriangleOffsets.length);
|
||||
mAllocOffsets.data(mFSM.mTriangleOffsets);
|
||||
mScriptStrip.bindAllocation(mAllocOffsets, 4);
|
||||
|
||||
mAllocOffsetsTex = Allocation.createSized(mRS,
|
||||
Element.createUser(mRS, Element.DataType.FLOAT_32), mFSM.mTriangleOffsetsTex.length);
|
||||
mAllocOffsetsTex.data(mFSM.mTriangleOffsetsTex);
|
||||
mScriptStrip.bindAllocation(mAllocOffsetsTex, 5);
|
||||
|
||||
setFilmStripPosition(0, 0);
|
||||
mRS.contextBindRootScript(mScriptStrip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,259 +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.
|
||||
*/
|
||||
|
||||
|
||||
package com.android.film;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.lang.Math;
|
||||
import android.util.Log;
|
||||
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.SimpleMesh;
|
||||
|
||||
|
||||
class FilmStripMesh {
|
||||
|
||||
class Vertex {
|
||||
float nx;
|
||||
float ny;
|
||||
float nz;
|
||||
float s;
|
||||
float t;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
Vertex() {
|
||||
nx = 0;
|
||||
ny = 0;
|
||||
nz = 0;
|
||||
s = 0;
|
||||
t = 0;
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
void xyz(float _x, float _y, float _z) {
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
}
|
||||
|
||||
void nxyz(float _x, float _y, float _z) {
|
||||
nx = _x;
|
||||
ny = _y;
|
||||
nz = _z;
|
||||
}
|
||||
|
||||
void st(float _s, float _t) {
|
||||
s = _s;
|
||||
t = _t;
|
||||
}
|
||||
|
||||
void computeNorm(Vertex v1, Vertex v2) {
|
||||
float dx = v1.x - v2.x;
|
||||
float dy = v1.y - v2.y;
|
||||
float dz = v1.z - v2.z;
|
||||
float len = (float)java.lang.Math.sqrt(dx*dx + dy*dy + dz*dz);
|
||||
dx /= len;
|
||||
dy /= len;
|
||||
dz /= len;
|
||||
|
||||
nx = dx * dz;
|
||||
ny = dy * dz;
|
||||
nz = (float)java.lang.Math.sqrt(dx*dx + dy*dy);
|
||||
|
||||
len = (float)java.lang.Math.sqrt(nx*nx + ny*ny + nz*nz);
|
||||
nx /= len;
|
||||
ny /= len;
|
||||
nz /= len;
|
||||
}
|
||||
}
|
||||
|
||||
int[] mTriangleOffsets;
|
||||
float[] mTriangleOffsetsTex;
|
||||
int mTriangleOffsetsCount;
|
||||
|
||||
SimpleMesh init(RenderScript rs)
|
||||
{
|
||||
float vtx[] = new float[] {
|
||||
60.431003f, 124.482050f,
|
||||
60.862074f, 120.872604f,
|
||||
61.705303f, 117.336662f,
|
||||
62.949505f, 113.921127f,
|
||||
64.578177f, 110.671304f,
|
||||
66.569716f, 107.630302f,
|
||||
68.897703f, 104.838457f,
|
||||
71.531259f, 102.332803f,
|
||||
74.435452f, 100.146577f,
|
||||
77.571757f, 98.308777f,
|
||||
80.898574f, 96.843781f,
|
||||
84.371773f, 95.771023f,
|
||||
87.945283f, 95.104731f,
|
||||
98.958994f, 95.267098f,
|
||||
109.489523f, 98.497596f,
|
||||
118.699582f, 104.539366f,
|
||||
125.856872f, 112.912022f,
|
||||
130.392311f, 122.949849f,
|
||||
131.945283f, 133.854731f,
|
||||
130.392311f, 144.759613f,
|
||||
125.856872f, 154.797439f,
|
||||
118.699582f, 163.170096f,
|
||||
109.489523f, 169.211866f,
|
||||
98.958994f, 172.442364f,
|
||||
87.945283f, 172.604731f,
|
||||
72.507313f, 172.672927f,
|
||||
57.678920f, 168.377071f,
|
||||
44.668135f, 160.067134f,
|
||||
34.534908f, 148.420104f,
|
||||
28.104767f, 134.384831f,
|
||||
25.901557f, 119.104731f,
|
||||
28.104767f, 103.824631f,
|
||||
34.534908f, 89.789358f,
|
||||
44.668135f, 78.142327f,
|
||||
57.678920f, 69.832390f,
|
||||
72.507313f, 65.536534f,
|
||||
87.945283f, 65.604731f,
|
||||
106.918117f, 65.688542f,
|
||||
125.141795f, 60.409056f,
|
||||
141.131686f, 50.196376f,
|
||||
153.585137f, 35.882502f,
|
||||
161.487600f, 18.633545f,
|
||||
164.195283f, -0.145269f,
|
||||
161.487600f, -18.924084f,
|
||||
153.585137f, -36.173040f,
|
||||
141.131686f, -50.486914f,
|
||||
125.141795f, -60.699594f,
|
||||
106.918117f, -65.979081f,
|
||||
87.945283f, -65.895269f,
|
||||
80f, -65.895269f,
|
||||
60f, -65.895269f,
|
||||
40f, -65.895269f,
|
||||
20f, -65.895269f,
|
||||
0f, -65.895269f,
|
||||
-20f, -65.895269f,
|
||||
-40f, -65.895269f,
|
||||
-60f, -65.895269f,
|
||||
-80f, -65.895269f,
|
||||
-87.945283f, -65.895269f,
|
||||
-106.918117f, -65.979081f,
|
||||
-125.141795f, -60.699594f,
|
||||
-141.131686f, -50.486914f,
|
||||
-153.585137f, -36.173040f,
|
||||
-161.487600f, -18.924084f,
|
||||
-164.195283f, -0.145269f,
|
||||
-161.487600f, 18.633545f,
|
||||
-153.585137f, 35.882502f,
|
||||
-141.131686f, 50.196376f,
|
||||
-125.141795f, 60.409056f,
|
||||
-106.918117f, 65.688542f,
|
||||
-87.945283f, 65.604731f,
|
||||
-72.507313f, 65.536534f,
|
||||
-57.678920f, 69.832390f,
|
||||
-44.668135f, 78.142327f,
|
||||
-34.534908f, 89.789358f,
|
||||
-28.104767f, 103.824631f,
|
||||
-25.901557f, 119.104731f,
|
||||
-28.104767f, 134.384831f,
|
||||
-34.534908f, 148.420104f,
|
||||
-44.668135f, 160.067134f,
|
||||
-57.678920f, 168.377071f,
|
||||
-72.507313f, 172.672927f,
|
||||
-87.945283f, 172.604731f,
|
||||
-98.958994f, 172.442364f,
|
||||
-109.489523f, 169.211866f,
|
||||
-118.699582f, 163.170096f,
|
||||
-125.856872f, 154.797439f,
|
||||
-130.392311f, 144.759613f,
|
||||
-131.945283f, 133.854731f,
|
||||
-130.392311f, 122.949849f,
|
||||
-125.856872f, 112.912022f,
|
||||
-118.699582f, 104.539366f,
|
||||
-109.489523f, 98.497596f,
|
||||
-98.958994f, 95.267098f,
|
||||
-87.945283f, 95.104731f,
|
||||
-84.371773f, 95.771023f,
|
||||
-80.898574f, 96.843781f,
|
||||
-77.571757f, 98.308777f,
|
||||
-74.435452f, 100.146577f,
|
||||
-71.531259f, 102.332803f,
|
||||
-68.897703f, 104.838457f,
|
||||
-66.569716f, 107.630302f,
|
||||
-64.578177f, 110.671304f,
|
||||
-62.949505f, 113.921127f,
|
||||
-61.705303f, 117.336662f,
|
||||
-60.862074f, 120.872604f,
|
||||
-60.431003f, 124.482050f
|
||||
};
|
||||
|
||||
|
||||
mTriangleOffsets = new int[64];
|
||||
mTriangleOffsetsTex = new float[64];
|
||||
|
||||
mTriangleOffsets[0] = 0;
|
||||
mTriangleOffsetsCount = 1;
|
||||
|
||||
Vertex t = new Vertex();
|
||||
t.nxyz(1, 0, 0);
|
||||
int count = vtx.length / 2;
|
||||
|
||||
SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(
|
||||
rs, 3,
|
||||
SimpleMesh.TriangleMeshBuilder.NORMAL | SimpleMesh.TriangleMeshBuilder.TEXTURE_0);
|
||||
|
||||
float runningS = 0;
|
||||
for (int ct=0; ct < (count-1); ct++) {
|
||||
t.x = -vtx[ct*2] / 100.f;
|
||||
t.z = vtx[ct*2+1] / 100.f;
|
||||
t.s = runningS;
|
||||
t.nx = (vtx[ct*2+3] - vtx[ct*2 +1]);
|
||||
t.ny = (vtx[ct*2+2] - vtx[ct*2 ]);
|
||||
float len = (float)java.lang.Math.sqrt(t.nx * t.nx + t.ny * t.ny);
|
||||
runningS += len / 100;
|
||||
t.nx /= len;
|
||||
t.ny /= len;
|
||||
t.y = -0.5f;
|
||||
t.t = 0;
|
||||
tm.setNormal(t.nx, t.ny, t.nz);
|
||||
tm.setTexture(t.s, t.t);
|
||||
tm.addVertex(t.x, t.y, t.z);
|
||||
//android.util.Log.e("rs", "vtx x="+t.x+" y="+t.y+" z="+t.z+" s="+t.s+" t="+t.t);
|
||||
t.y = .5f;
|
||||
t.t = 1;
|
||||
tm.setTexture(t.s, t.t);
|
||||
tm.addVertex(t.x, t.y, t.z);
|
||||
//android.util.Log.e("rs", "vtx x="+t.x+" y="+t.y+" z="+t.z+" s="+t.s+" t="+t.t);
|
||||
|
||||
if((runningS*2) > mTriangleOffsetsCount) {
|
||||
mTriangleOffsets[mTriangleOffsetsCount] = ct*2 * 3;
|
||||
mTriangleOffsetsTex[mTriangleOffsetsCount] = t.s;
|
||||
mTriangleOffsetsCount ++;
|
||||
}
|
||||
}
|
||||
|
||||
count = (count * 2 - 2);
|
||||
for (int ct=0; ct < (count-2); ct+= 2) {
|
||||
tm.addTriangle(ct, ct+1, ct+2);
|
||||
tm.addTriangle(ct+1, ct+3, ct+2);
|
||||
}
|
||||
return tm.create();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,93 +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.film;
|
||||
|
||||
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 FilmView extends RSSurfaceView {
|
||||
|
||||
public FilmView(Context context) {
|
||||
super(context);
|
||||
//setFocusable(true);
|
||||
}
|
||||
|
||||
private RenderScriptGL mRS;
|
||||
private FilmRS mRender;
|
||||
|
||||
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
super.surfaceChanged(holder, format, w, h);
|
||||
if (mRS == null) {
|
||||
mRS = createRenderScript(true);
|
||||
mRS.contextSetSurface(w, h, holder.getSurface());
|
||||
mRender = new FilmRS();
|
||||
mRender.init(mRS, getResources(), w, h);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
if(mRS != null) {
|
||||
mRS = null;
|
||||
destroyRenderScript();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
// break point at here
|
||||
// this method doesn't work when 'extends View' include 'extends ScrollView'.
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev)
|
||||
{
|
||||
boolean ret = true;
|
||||
int act = ev.getAction();
|
||||
if (act == ev.ACTION_UP) {
|
||||
ret = false;
|
||||
}
|
||||
mRender.setFilmStripPosition((int)ev.getX(), (int)ev.getY() / 5);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||