Renderscript is deprecated. Removing from the sdk.
Change-Id: I4963ec4e9287003772d5818789d2de72b72f59c3
@@ -51,11 +51,6 @@ bin/dx platform-tools/dx
|
|||||||
bin/dexdump platform-tools/dexdump
|
bin/dexdump platform-tools/dexdump
|
||||||
framework/dx.jar platform-tools/lib/dx.jar
|
framework/dx.jar platform-tools/lib/dx.jar
|
||||||
|
|
||||||
# Framework include for Renderscript
|
|
||||||
frameworks/rs/scriptc platform-tools/renderscript/include
|
|
||||||
external/clang/lib/Headers platform-tools/renderscript/clang-include
|
|
||||||
external/clang/LICENSE.TXT platform-tools/renderscript/clang-include/LICENSE.TXT
|
|
||||||
|
|
||||||
# API database for tools such as lint
|
# API database for tools such as lint
|
||||||
development/sdk/api-versions.xml platform-tools/api/api-versions.xml
|
development/sdk/api-versions.xml platform-tools/api/api-versions.xml
|
||||||
|
|
||||||
@@ -200,12 +195,6 @@ development/samples/WiFiDirectDemo samples/${PLATFORM_NAME}/WiFiDire
|
|||||||
development/samples/Wiktionary samples/${PLATFORM_NAME}/Wiktionary
|
development/samples/Wiktionary samples/${PLATFORM_NAME}/Wiktionary
|
||||||
development/samples/WiktionarySimple samples/${PLATFORM_NAME}/WiktionarySimple
|
development/samples/WiktionarySimple samples/${PLATFORM_NAME}/WiktionarySimple
|
||||||
development/samples/XmlAdapters samples/${PLATFORM_NAME}/XmlAdapters
|
development/samples/XmlAdapters samples/${PLATFORM_NAME}/XmlAdapters
|
||||||
development/samples/RenderScript/Balls samples/${PLATFORM_NAME}/RenderScript/Balls
|
|
||||||
development/samples/RenderScript/Fountain samples/${PLATFORM_NAME}/RenderScript/Fountain
|
|
||||||
development/samples/RenderScript/FountainFbo samples/${PLATFORM_NAME}/RenderScript/FountainFbo
|
|
||||||
development/samples/RenderScript/HelloCompute samples/${PLATFORM_NAME}/RenderScript/HelloCompute
|
|
||||||
development/samples/RenderScript/HelloWorld samples/${PLATFORM_NAME}/RenderScript/HelloWorld
|
|
||||||
development/samples/RenderScript/MiscSamples samples/${PLATFORM_NAME}/RenderScript/MiscSamples
|
|
||||||
|
|
||||||
# NOTICE files are copied by build/core/Makefile from sdk.git
|
# NOTICE files are copied by build/core/Makefile from sdk.git
|
||||||
sdk/files/sdk_files_NOTICE.txt samples/${PLATFORM_NAME}/NOTICE.txt
|
sdk/files/sdk_files_NOTICE.txt samples/${PLATFORM_NAME}/NOTICE.txt
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
include $(call all-subdir-makefiles)
|
|
||||||
@@ -1,26 +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) $(call all-renderscript-files-under, src)
|
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := RsBalls
|
|
||||||
|
|
||||||
include $(BUILD_PACKAGE)
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.example.android.rs.balls">
|
|
||||||
<uses-sdk android:minSdkVersion="14" />
|
|
||||||
<application
|
|
||||||
android:label="RsBalls"
|
|
||||||
android:icon="@drawable/test_pattern">
|
|
||||||
<activity android:name="Balls"
|
|
||||||
android:screenOrientation="landscape">
|
|
||||||
<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 brute force physics simulation that renders many balls onto the screen and moves them according to user touch and gravity.</p>
|
|
||||||
|
Before Width: | Height: | Size: 413 B |
|
Before Width: | Height: | Size: 307 B |
@@ -1,118 +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.balls;
|
|
||||||
|
|
||||||
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 android.app.Activity;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.View;
|
|
||||||
import android.hardware.Sensor;
|
|
||||||
import android.hardware.SensorEvent;
|
|
||||||
import android.hardware.SensorEventListener;
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
|
|
||||||
public class Balls extends Activity implements SensorEventListener {
|
|
||||||
//EventListener mListener = new EventListener();
|
|
||||||
|
|
||||||
private static final String LOG_TAG = "libRS_jni";
|
|
||||||
private static final boolean DEBUG = false;
|
|
||||||
private static final boolean LOG_ENABLED = false;
|
|
||||||
|
|
||||||
private BallsView mView;
|
|
||||||
private SensorManager mSensorManager;
|
|
||||||
|
|
||||||
// get the current looper (from your Activity UI thread for instance
|
|
||||||
|
|
||||||
|
|
||||||
public void onSensorChanged(SensorEvent event) {
|
|
||||||
//android.util.Log.d("rs", "sensor: " + event.sensor + ", x: " + event.values[0] + ", y: " + event.values[1] + ", z: " + event.values[2]);
|
|
||||||
synchronized (this) {
|
|
||||||
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
|
|
||||||
if(mView != null) {
|
|
||||||
mView.setAccel(event.values[0], event.values[1], event.values[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
|
|
||||||
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
|
||||||
|
|
||||||
// Create our Preview view and set it as the content of our
|
|
||||||
// Activity
|
|
||||||
mView = new BallsView(this);
|
|
||||||
setContentView(mView);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
mSensorManager.registerListener(this,
|
|
||||||
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
|
|
||||||
SensorManager.SENSOR_DELAY_FASTEST);
|
|
||||||
|
|
||||||
// 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() {
|
|
||||||
super.onPause();
|
|
||||||
mView.pause();
|
|
||||||
onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
mSensorManager.unregisterListener(this);
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void log(String message) {
|
|
||||||
if (LOG_ENABLED) {
|
|
||||||
Log.v(LOG_TAG, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,143 +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.balls;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.renderscript.*;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class BallsRS {
|
|
||||||
public static final int PART_COUNT = 900;
|
|
||||||
|
|
||||||
public BallsRS() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private Resources mRes;
|
|
||||||
private RenderScriptGL mRS;
|
|
||||||
private ScriptC_balls mScript;
|
|
||||||
private ScriptC_ball_physics mPhysicsScript;
|
|
||||||
private ProgramFragment mPFLines;
|
|
||||||
private ProgramFragment mPFPoints;
|
|
||||||
private ProgramVertex mPV;
|
|
||||||
private ScriptField_Point mPoints;
|
|
||||||
private ScriptField_VpConsts mVpConsts;
|
|
||||||
|
|
||||||
void updateProjectionMatrices() {
|
|
||||||
mVpConsts = new ScriptField_VpConsts(mRS, 1,
|
|
||||||
Allocation.USAGE_SCRIPT |
|
|
||||||
Allocation.USAGE_GRAPHICS_CONSTANTS);
|
|
||||||
ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
|
|
||||||
Matrix4f mvp = new Matrix4f();
|
|
||||||
mvp.loadOrtho(0, mRS.getWidth(), mRS.getHeight(), 0, -1, 1);
|
|
||||||
i.MVP = mvp;
|
|
||||||
mVpConsts.set(i, 0, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createProgramVertex() {
|
|
||||||
updateProjectionMatrices();
|
|
||||||
|
|
||||||
ProgramVertex.Builder sb = new ProgramVertex.Builder(mRS);
|
|
||||||
String t = "varying vec4 varColor;\n" +
|
|
||||||
"void main() {\n" +
|
|
||||||
" vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n" +
|
|
||||||
" pos.xy = ATTRIB_position;\n" +
|
|
||||||
" gl_Position = UNI_MVP * pos;\n" +
|
|
||||||
" varColor = vec4(1.0, 1.0, 1.0, 1.0);\n" +
|
|
||||||
" gl_PointSize = ATTRIB_size;\n" +
|
|
||||||
"}\n";
|
|
||||||
sb.setShader(t);
|
|
||||||
sb.addConstant(mVpConsts.getType());
|
|
||||||
sb.addInput(mPoints.getElement());
|
|
||||||
ProgramVertex pvs = sb.create();
|
|
||||||
pvs.bindConstants(mVpConsts.getAllocation(), 0);
|
|
||||||
mRS.bindProgramVertex(pvs);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Allocation loadTexture(int id) {
|
|
||||||
final Allocation allocation =
|
|
||||||
Allocation.createFromBitmapResource(mRS, mRes,
|
|
||||||
id, Allocation.MipmapControl.MIPMAP_NONE,
|
|
||||||
Allocation.USAGE_GRAPHICS_TEXTURE);
|
|
||||||
return allocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) {
|
|
||||||
ProgramStore.Builder builder = new ProgramStore.Builder(rs);
|
|
||||||
builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
|
|
||||||
builder.setBlendFunc(ProgramStore.BlendSrcFunc.ONE, ProgramStore.BlendDstFunc.ONE);
|
|
||||||
builder.setDitherEnabled(false);
|
|
||||||
builder.setDepthMaskEnabled(false);
|
|
||||||
return builder.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(RenderScriptGL rs, Resources res, int width, int height) {
|
|
||||||
mRS = rs;
|
|
||||||
mRes = res;
|
|
||||||
|
|
||||||
ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(rs);
|
|
||||||
pfb.setPointSpriteTexCoordinateReplacement(true);
|
|
||||||
pfb.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
|
|
||||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
|
||||||
pfb.setVaryingColor(true);
|
|
||||||
mPFPoints = pfb.create();
|
|
||||||
|
|
||||||
pfb = new ProgramFragmentFixedFunction.Builder(rs);
|
|
||||||
pfb.setVaryingColor(true);
|
|
||||||
mPFLines = pfb.create();
|
|
||||||
|
|
||||||
android.util.Log.e("rs", "Load texture");
|
|
||||||
mPFPoints.bindTexture(loadTexture(R.drawable.flares), 0);
|
|
||||||
|
|
||||||
mPoints = new ScriptField_Point(mRS, PART_COUNT, Allocation.USAGE_SCRIPT);
|
|
||||||
|
|
||||||
Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS);
|
|
||||||
smb.addVertexAllocation(mPoints.getAllocation());
|
|
||||||
smb.addIndexSetType(Mesh.Primitive.POINT);
|
|
||||||
Mesh smP = smb.create();
|
|
||||||
|
|
||||||
mPhysicsScript = new ScriptC_ball_physics(mRS, mRes, R.raw.ball_physics);
|
|
||||||
|
|
||||||
mScript = new ScriptC_balls(mRS, mRes, R.raw.balls);
|
|
||||||
mScript.set_partMesh(smP);
|
|
||||||
mScript.set_physics_script(mPhysicsScript);
|
|
||||||
mScript.bind_point(mPoints);
|
|
||||||
mScript.bind_balls1(new ScriptField_Ball(mRS, PART_COUNT, Allocation.USAGE_SCRIPT));
|
|
||||||
mScript.bind_balls2(new ScriptField_Ball(mRS, PART_COUNT, Allocation.USAGE_SCRIPT));
|
|
||||||
|
|
||||||
mScript.set_gPFLines(mPFLines);
|
|
||||||
mScript.set_gPFPoints(mPFPoints);
|
|
||||||
createProgramVertex();
|
|
||||||
|
|
||||||
mRS.bindProgramStore(BLEND_ADD_DEPTH_NONE(mRS));
|
|
||||||
|
|
||||||
mPhysicsScript.set_gMinPos(new Float2(5, 5));
|
|
||||||
mPhysicsScript.set_gMaxPos(new Float2(width - 5, height - 5));
|
|
||||||
|
|
||||||
mScript.invoke_initParts(width, height);
|
|
||||||
|
|
||||||
mRS.bindRootScript(mScript);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void newTouchPosition(float x, float y, float pressure, int id) {
|
|
||||||
mPhysicsScript.invoke_touch(x, y, pressure, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAccel(float x, float y) {
|
|
||||||
mPhysicsScript.set_gGravityVector(new Float2(x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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.example.android.rs.balls;
|
|
||||||
|
|
||||||
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 BallsView extends RSSurfaceView {
|
|
||||||
|
|
||||||
public BallsView(Context context) {
|
|
||||||
super(context);
|
|
||||||
//setFocusable(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RenderScriptGL mRS;
|
|
||||||
private BallsRS 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();
|
|
||||||
mRS = createRenderScriptGL(sc);
|
|
||||||
mRS.setSurface(holder, w, h);
|
|
||||||
mRender = new BallsRS();
|
|
||||||
mRender.init(mRS, getResources(), w, h);
|
|
||||||
}
|
|
||||||
mRender.updateProjectionMatrices();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDetachedFromWindow() {
|
|
||||||
if(mRS != null) {
|
|
||||||
mRS = null;
|
|
||||||
destroyRenderScriptGL();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onTouchEvent(MotionEvent ev)
|
|
||||||
{
|
|
||||||
int act = ev.getActionMasked();
|
|
||||||
if (act == ev.ACTION_UP) {
|
|
||||||
mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0));
|
|
||||||
return false;
|
|
||||||
} else if (act == MotionEvent.ACTION_POINTER_UP) {
|
|
||||||
// only one pointer going up, we can get the index like this
|
|
||||||
int pointerIndex = ev.getActionIndex();
|
|
||||||
int pointerId = ev.getPointerId(pointerIndex);
|
|
||||||
mRender.newTouchPosition(0, 0, 0, pointerId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int count = ev.getHistorySize();
|
|
||||||
int pcount = ev.getPointerCount();
|
|
||||||
|
|
||||||
for (int p=0; p < pcount; p++) {
|
|
||||||
int id = ev.getPointerId(p);
|
|
||||||
mRender.newTouchPosition(ev.getX(p),
|
|
||||||
ev.getY(p),
|
|
||||||
ev.getPressure(p),
|
|
||||||
id);
|
|
||||||
|
|
||||||
for (int i=0; i < count; i++) {
|
|
||||||
mRender.newTouchPosition(ev.getHistoricalX(p, i),
|
|
||||||
ev.getHistoricalY(p, i),
|
|
||||||
ev.getHistoricalPressure(p, i),
|
|
||||||
id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAccel(float x, float y, float z) {
|
|
||||||
if (mRender == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mRender.setAccel(x, -y);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
#pragma version(1)
|
|
||||||
#pragma rs java_package_name(com.example.android.rs.balls)
|
|
||||||
|
|
||||||
#include "balls.rsh"
|
|
||||||
|
|
||||||
float2 gGravityVector = {0.f, 9.8f};
|
|
||||||
|
|
||||||
float2 gMinPos = {0.f, 0.f};
|
|
||||||
float2 gMaxPos = {1280.f, 700.f};
|
|
||||||
|
|
||||||
static float2 touchPos[10];
|
|
||||||
static float touchPressure[10];
|
|
||||||
|
|
||||||
void touch(float x, float y, float pressure, int id) {
|
|
||||||
if (id >= 10) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
touchPos[id].x = x;
|
|
||||||
touchPos[id].y = y;
|
|
||||||
touchPressure[id] = pressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
void root(const Ball_t *ballIn, Ball_t *ballOut, const BallControl_t *ctl, uint32_t x) {
|
|
||||||
float2 fv = {0, 0};
|
|
||||||
float2 pos = ballIn->position;
|
|
||||||
|
|
||||||
int arcID = -1;
|
|
||||||
float arcInvStr = 100000;
|
|
||||||
|
|
||||||
const Ball_t * bPtr = rsGetElementAt(ctl->ain, 0);
|
|
||||||
for (uint32_t xin = 0; xin < ctl->dimX; xin++) {
|
|
||||||
float2 vec = bPtr[xin].position - pos;
|
|
||||||
float2 vec2 = vec * vec;
|
|
||||||
float len2 = vec2.x + vec2.y;
|
|
||||||
|
|
||||||
if (len2 < 10000) {
|
|
||||||
//float minDist = ballIn->size + bPtr[xin].size;
|
|
||||||
float forceScale = ballIn->size * bPtr[xin].size;
|
|
||||||
forceScale *= forceScale;
|
|
||||||
|
|
||||||
if (len2 > 16 /* (minDist*minDist)*/) {
|
|
||||||
// Repulsion
|
|
||||||
float len = sqrt(len2);
|
|
||||||
fv -= (vec / (len * len * len)) * 20000.f * forceScale;
|
|
||||||
} else {
|
|
||||||
if (len2 < 1) {
|
|
||||||
if (xin == x) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ballOut->delta = 0.f;
|
|
||||||
ballOut->position = ballIn->position;
|
|
||||||
if (xin > x) {
|
|
||||||
ballOut->position.x += 1.f;
|
|
||||||
} else {
|
|
||||||
ballOut->position.x -= 1.f;
|
|
||||||
}
|
|
||||||
//ballOut->color.rgb = 1.f;
|
|
||||||
//ballOut->arcID = -1;
|
|
||||||
//ballOut->arcStr = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Collision
|
|
||||||
float2 axis = normalize(vec);
|
|
||||||
float e1 = dot(axis, ballIn->delta);
|
|
||||||
float e2 = dot(axis, bPtr[xin].delta);
|
|
||||||
float e = (e1 - e2) * 0.45f;
|
|
||||||
if (e1 > 0) {
|
|
||||||
fv -= axis * e;
|
|
||||||
} else {
|
|
||||||
fv += axis * e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fv /= ballIn->size * ballIn->size * ballIn->size;
|
|
||||||
fv -= gGravityVector * 4.f;
|
|
||||||
fv *= ctl->dt;
|
|
||||||
|
|
||||||
for (int i=0; i < 10; i++) {
|
|
||||||
if (touchPressure[i] > 0.1f) {
|
|
||||||
float2 vec = touchPos[i] - ballIn->position;
|
|
||||||
float2 vec2 = vec * vec;
|
|
||||||
float len2 = max(2.f, vec2.x + vec2.y);
|
|
||||||
fv -= (vec / len2) * touchPressure[i] * 300.f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ballOut->delta = (ballIn->delta * (1.f - 0.004f)) + fv;
|
|
||||||
ballOut->position = ballIn->position + (ballOut->delta * ctl->dt);
|
|
||||||
|
|
||||||
const float wallForce = 400.f;
|
|
||||||
if (ballOut->position.x > (gMaxPos.x - 20.f)) {
|
|
||||||
float d = gMaxPos.x - ballOut->position.x;
|
|
||||||
if (d < 0.f) {
|
|
||||||
if (ballOut->delta.x > 0) {
|
|
||||||
ballOut->delta.x *= -0.7f;
|
|
||||||
}
|
|
||||||
ballOut->position.x = gMaxPos.x;
|
|
||||||
} else {
|
|
||||||
ballOut->delta.x -= min(wallForce / (d * d), 10.f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ballOut->position.x < (gMinPos.x + 20.f)) {
|
|
||||||
float d = ballOut->position.x - gMinPos.x;
|
|
||||||
if (d < 0.f) {
|
|
||||||
if (ballOut->delta.x < 0) {
|
|
||||||
ballOut->delta.x *= -0.7f;
|
|
||||||
}
|
|
||||||
ballOut->position.x = gMinPos.x + 1.f;
|
|
||||||
} else {
|
|
||||||
ballOut->delta.x += min(wallForce / (d * d), 10.f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ballOut->position.y > (gMaxPos.y - 20.f)) {
|
|
||||||
float d = gMaxPos.y - ballOut->position.y;
|
|
||||||
if (d < 0.f) {
|
|
||||||
if (ballOut->delta.y > 0) {
|
|
||||||
ballOut->delta.y *= -0.7f;
|
|
||||||
}
|
|
||||||
ballOut->position.y = gMaxPos.y;
|
|
||||||
} else {
|
|
||||||
ballOut->delta.y -= min(wallForce / (d * d), 10.f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ballOut->position.y < (gMinPos.y + 20.f)) {
|
|
||||||
float d = ballOut->position.y - gMinPos.y;
|
|
||||||
if (d < 0.f) {
|
|
||||||
if (ballOut->delta.y < 0) {
|
|
||||||
ballOut->delta.y *= -0.7f;
|
|
||||||
}
|
|
||||||
ballOut->position.y = gMinPos.y + 1.f;
|
|
||||||
} else {
|
|
||||||
ballOut->delta.y += min(wallForce / (d * d * d), 10.f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ballOut->size = ballIn->size;
|
|
||||||
|
|
||||||
//rsDebug("physics pos out", ballOut->position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
#pragma version(1)
|
|
||||||
#pragma rs java_package_name(com.example.android.rs.balls)
|
|
||||||
#include "rs_graphics.rsh"
|
|
||||||
|
|
||||||
#include "balls.rsh"
|
|
||||||
|
|
||||||
#pragma stateVertex(parent)
|
|
||||||
#pragma stateStore(parent)
|
|
||||||
|
|
||||||
rs_program_fragment gPFPoints;
|
|
||||||
rs_program_fragment gPFLines;
|
|
||||||
rs_mesh partMesh;
|
|
||||||
|
|
||||||
typedef struct __attribute__((packed, aligned(4))) Point {
|
|
||||||
float2 position;
|
|
||||||
float size;
|
|
||||||
} Point_t;
|
|
||||||
Point_t *point;
|
|
||||||
|
|
||||||
typedef struct VpConsts {
|
|
||||||
rs_matrix4x4 MVP;
|
|
||||||
} VpConsts_t;
|
|
||||||
VpConsts_t *vpConstants;
|
|
||||||
|
|
||||||
rs_script physics_script;
|
|
||||||
|
|
||||||
Ball_t *balls1;
|
|
||||||
Ball_t *balls2;
|
|
||||||
|
|
||||||
static int frame = 0;
|
|
||||||
|
|
||||||
void initParts(int w, int h)
|
|
||||||
{
|
|
||||||
uint32_t dimX = rsAllocationGetDimX(rsGetAllocation(balls1));
|
|
||||||
|
|
||||||
for (uint32_t ct=0; ct < dimX; ct++) {
|
|
||||||
balls1[ct].position.x = rsRand(0.f, (float)w);
|
|
||||||
balls1[ct].position.y = rsRand(0.f, (float)h);
|
|
||||||
balls1[ct].delta.x = 0.f;
|
|
||||||
balls1[ct].delta.y = 0.f;
|
|
||||||
balls1[ct].size = 1.f;
|
|
||||||
|
|
||||||
float r = rsRand(100.f);
|
|
||||||
if (r > 90.f) {
|
|
||||||
balls1[ct].size += pow(10.f, rsRand(0.f, 2.f)) * 0.07f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int root() {
|
|
||||||
rsgClearColor(0.f, 0.f, 0.f, 1.f);
|
|
||||||
|
|
||||||
BallControl_t bc;
|
|
||||||
Ball_t *bout;
|
|
||||||
|
|
||||||
if (frame & 1) {
|
|
||||||
bc.ain = rsGetAllocation(balls2);
|
|
||||||
bc.aout = rsGetAllocation(balls1);
|
|
||||||
bout = balls1;
|
|
||||||
} else {
|
|
||||||
bc.ain = rsGetAllocation(balls1);
|
|
||||||
bc.aout = rsGetAllocation(balls2);
|
|
||||||
bout = balls2;
|
|
||||||
}
|
|
||||||
|
|
||||||
bc.dimX = rsAllocationGetDimX(bc.ain);
|
|
||||||
bc.dt = 1.f / 30.f;
|
|
||||||
|
|
||||||
rsForEach(physics_script, bc.ain, bc.aout, &bc, sizeof(bc));
|
|
||||||
|
|
||||||
for (uint32_t ct=0; ct < bc.dimX; ct++) {
|
|
||||||
point[ct].position = bout[ct].position;
|
|
||||||
point[ct].size = 6.f /*+ bout[ct].color.g * 6.f*/ * bout[ct].size;
|
|
||||||
}
|
|
||||||
|
|
||||||
frame++;
|
|
||||||
rsgBindProgramFragment(gPFPoints);
|
|
||||||
rsgDrawMesh(partMesh);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
|
|
||||||
typedef struct __attribute__((packed, aligned(4))) Ball {
|
|
||||||
float2 delta;
|
|
||||||
float2 position;
|
|
||||||
//float3 color;
|
|
||||||
float size;
|
|
||||||
//int arcID;
|
|
||||||
//float arcStr;
|
|
||||||
} Ball_t;
|
|
||||||
Ball_t *balls;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct BallControl {
|
|
||||||
uint32_t dimX;
|
|
||||||
rs_allocation ain;
|
|
||||||
rs_allocation aout;
|
|
||||||
float dt;
|
|
||||||
} BallControl_t;
|
|
||||||
@@ -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 := optional
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
|
||||||
|
|
||||||
# TODO: build fails with this set
|
|
||||||
# LOCAL_SDK_VERSION := current
|
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := RsFountain
|
|
||||||
|
|
||||||
include $(BUILD_PACKAGE)
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.example.android.rs.fountain">
|
|
||||||
<uses-sdk android:minSdkVersion="14" />
|
|
||||||
<application
|
|
||||||
android:label="RsFountain"
|
|
||||||
android:hardwareAccelerated="true"
|
|
||||||
android:icon="@drawable/test_pattern">
|
|
||||||
<activity android:name="Fountain">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
</application>
|
|
||||||
</manifest>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<p>An example that renders many dots on the screen that follow a user's touch. The dots fall
|
|
||||||
to the bottom of the screen when the user releases the finger.</p>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 307 B |
@@ -1,95 +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.fountain;
|
|
||||||
|
|
||||||
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 Fountain 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 = false;
|
|
||||||
|
|
||||||
private FountainView 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 FountainView(this);
|
|
||||||
setContentView(mView);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
Log.e("rs", "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() {
|
|
||||||
Log.e("rs", "onPause");
|
|
||||||
|
|
||||||
// Ideally a game should implement onResume() and onPause()
|
|
||||||
// to take appropriate action when the activity looses focus
|
|
||||||
super.onPause();
|
|
||||||
mView.pause();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Runtime.getRuntime().exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void log(String message) {
|
|
||||||
if (LOG_ENABLED) {
|
|
||||||
Log.v(LOG_TAG, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -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.example.android.rs.fountain;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.renderscript.*;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
|
||||||
public class FountainRS {
|
|
||||||
public static final int PART_COUNT = 50000;
|
|
||||||
|
|
||||||
public FountainRS() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private Resources mRes;
|
|
||||||
private RenderScriptGL mRS;
|
|
||||||
private ScriptC_fountain mScript;
|
|
||||||
public void init(RenderScriptGL rs, Resources res) {
|
|
||||||
mRS = rs;
|
|
||||||
mRes = res;
|
|
||||||
|
|
||||||
ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(rs);
|
|
||||||
pfb.setVaryingColor(true);
|
|
||||||
rs.bindProgramFragment(pfb.create());
|
|
||||||
|
|
||||||
ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);//
|
|
||||||
// Allocation.USAGE_GRAPHICS_VERTEX);
|
|
||||||
|
|
||||||
Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS);
|
|
||||||
smb.addVertexAllocation(points.getAllocation());
|
|
||||||
smb.addIndexSetType(Mesh.Primitive.POINT);
|
|
||||||
Mesh sm = smb.create();
|
|
||||||
|
|
||||||
mScript = new ScriptC_fountain(mRS, mRes, R.raw.fountain);
|
|
||||||
mScript.set_partMesh(sm);
|
|
||||||
mScript.bind_point(points);
|
|
||||||
mRS.bindRootScript(mScript);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean holdingColor[] = new boolean[10];
|
|
||||||
public void newTouchPosition(float x, float y, float pressure, int id) {
|
|
||||||
if (id >= holdingColor.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int rate = (int)(pressure * pressure * 500.f);
|
|
||||||
if (rate > 500) {
|
|
||||||
rate = 500;
|
|
||||||
}
|
|
||||||
if (rate > 0) {
|
|
||||||
mScript.invoke_addParticles(rate, x, y, id, !holdingColor[id]);
|
|
||||||
holdingColor[id] = true;
|
|
||||||
} else {
|
|
||||||
holdingColor[id] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +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.fountain;
|
|
||||||
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.concurrent.Semaphore;
|
|
||||||
|
|
||||||
import android.renderscript.RSTextureView;
|
|
||||||
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 FountainView extends RSTextureView {
|
|
||||||
|
|
||||||
public FountainView(Context context) {
|
|
||||||
super(context);
|
|
||||||
//setFocusable(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RenderScriptGL mRS;
|
|
||||||
private FountainRS mRender;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onAttachedToWindow() {
|
|
||||||
super.onAttachedToWindow();
|
|
||||||
android.util.Log.e("rs", "onAttachedToWindow");
|
|
||||||
if (mRS == null) {
|
|
||||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
|
||||||
mRS = createRenderScriptGL(sc);
|
|
||||||
mRender = new FountainRS();
|
|
||||||
mRender.init(mRS, getResources());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDetachedFromWindow() {
|
|
||||||
super.onDetachedFromWindow();
|
|
||||||
android.util.Log.e("rs", "onDetachedFromWindow");
|
|
||||||
if (mRS != null) {
|
|
||||||
mRS = null;
|
|
||||||
destroyRenderScriptGL();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onTouchEvent(MotionEvent ev)
|
|
||||||
{
|
|
||||||
int act = ev.getActionMasked();
|
|
||||||
if (act == ev.ACTION_UP) {
|
|
||||||
mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0));
|
|
||||||
return false;
|
|
||||||
} else if (act == MotionEvent.ACTION_POINTER_UP) {
|
|
||||||
// only one pointer going up, we can get the index like this
|
|
||||||
int pointerIndex = ev.getActionIndex();
|
|
||||||
int pointerId = ev.getPointerId(pointerIndex);
|
|
||||||
mRender.newTouchPosition(0, 0, 0, pointerId);
|
|
||||||
}
|
|
||||||
int count = ev.getHistorySize();
|
|
||||||
int pcount = ev.getPointerCount();
|
|
||||||
|
|
||||||
for (int p=0; p < pcount; p++) {
|
|
||||||
int id = ev.getPointerId(p);
|
|
||||||
mRender.newTouchPosition(ev.getX(p),
|
|
||||||
ev.getY(p),
|
|
||||||
ev.getPressure(p),
|
|
||||||
id);
|
|
||||||
|
|
||||||
for (int i=0; i < count; i++) {
|
|
||||||
mRender.newTouchPosition(ev.getHistoricalX(p, i),
|
|
||||||
ev.getHistoricalY(p, i),
|
|
||||||
ev.getHistoricalPressure(p, i),
|
|
||||||
id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
// Fountain test script
|
|
||||||
#pragma version(1)
|
|
||||||
#pragma rs_fp_relaxed
|
|
||||||
|
|
||||||
#pragma rs java_package_name(com.example.android.rs.fountain)
|
|
||||||
|
|
||||||
#pragma stateFragment(parent)
|
|
||||||
|
|
||||||
#include "rs_graphics.rsh"
|
|
||||||
|
|
||||||
static int newPart = 0;
|
|
||||||
rs_mesh partMesh;
|
|
||||||
|
|
||||||
typedef struct __attribute__((packed, aligned(4))) Point {
|
|
||||||
float2 delta;
|
|
||||||
float2 position;
|
|
||||||
uchar4 color;
|
|
||||||
} Point_t;
|
|
||||||
Point_t *point;
|
|
||||||
|
|
||||||
int root() {
|
|
||||||
float dt = min(rsGetDt(), 0.1f);
|
|
||||||
rsgClearColor(0.f, 0.f, 0.f, 1.f);
|
|
||||||
const float height = rsgGetHeight();
|
|
||||||
const int size = rsAllocationGetDimX(rsGetAllocation(point));
|
|
||||||
float dy2 = dt * (10.f);
|
|
||||||
Point_t * p = point;
|
|
||||||
for (int ct=0; ct < size; ct++) {
|
|
||||||
p->delta.y += dy2;
|
|
||||||
p->position += p->delta;
|
|
||||||
if ((p->position.y > height) && (p->delta.y > 0)) {
|
|
||||||
p->delta.y *= -0.3f;
|
|
||||||
}
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
rsgDrawMesh(partMesh);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float4 partColor[10];
|
|
||||||
void addParticles(int rate, float x, float y, int index, bool newColor)
|
|
||||||
{
|
|
||||||
if (newColor) {
|
|
||||||
partColor[index].x = rsRand(0.5f, 1.0f);
|
|
||||||
partColor[index].y = rsRand(1.0f);
|
|
||||||
partColor[index].z = rsRand(1.0f);
|
|
||||||
}
|
|
||||||
float rMax = ((float)rate) * 0.02f;
|
|
||||||
int size = rsAllocationGetDimX(rsGetAllocation(point));
|
|
||||||
uchar4 c = rsPackColorTo8888(partColor[index]);
|
|
||||||
|
|
||||||
Point_t * np = &point[newPart];
|
|
||||||
float2 p = {x, y};
|
|
||||||
while (rate--) {
|
|
||||||
float angle = rsRand(3.14f * 2.f);
|
|
||||||
float len = rsRand(rMax);
|
|
||||||
np->delta.x = len * sin(angle);
|
|
||||||
np->delta.y = len * cos(angle);
|
|
||||||
np->position = p;
|
|
||||||
np->color = c;
|
|
||||||
newPart++;
|
|
||||||
np++;
|
|
||||||
if (newPart >= size) {
|
|
||||||
newPart = 0;
|
|
||||||
np = &point[newPart];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -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 := optional
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
|
||||||
|
|
||||||
# TODO: build fails with this set
|
|
||||||
# LOCAL_SDK_VERSION := current
|
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := RsFountainFbo
|
|
||||||
|
|
||||||
include $(BUILD_PACKAGE)
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.example.android.rs.fountainfbo">
|
|
||||||
<uses-sdk android:minSdkVersion="14" />
|
|
||||||
<application
|
|
||||||
android:label="RsFountainFbo"
|
|
||||||
android:hardwareAccelerated="true"
|
|
||||||
android:icon="@drawable/test_pattern">
|
|
||||||
<activity android:name="FountainFbo">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
</application>
|
|
||||||
</manifest>
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<p>An example that renders many dots on the screen that follow a user's touch. The dots fall
|
|
||||||
to the bottom of the screen when no touch is detected. This example modifies
|
|
||||||
the <a href="../Fountain/index.html">Fountain</a> sample to include rendering to a
|
|
||||||
a framebuffer object as well as the default framebuffer.</p>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 307 B |
@@ -1,65 +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.fountainfbo;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class FountainFbo extends Activity {
|
|
||||||
private static final String LOG_TAG = "libRS_jni";
|
|
||||||
private static final boolean DEBUG = false;
|
|
||||||
private static final boolean LOG_ENABLED = false;
|
|
||||||
|
|
||||||
private FountainFboView 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 FountainFboView(this);
|
|
||||||
setContentView(mView);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
Log.e("rs", "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() {
|
|
||||||
Log.e("rs", "onPause");
|
|
||||||
|
|
||||||
/* Ideally a game should implement onResume() and onPause()
|
|
||||||
to take appropriate action when the activity loses focus */
|
|
||||||
super.onPause();
|
|
||||||
mView.pause();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void log(String message) {
|
|
||||||
if (LOG_ENABLED) {
|
|
||||||
Log.v(LOG_TAG, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,99 +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.fountainfbo;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.renderscript.Allocation;
|
|
||||||
import android.renderscript.Element;
|
|
||||||
import android.renderscript.Mesh;
|
|
||||||
import android.renderscript.ProgramFragment;
|
|
||||||
import android.renderscript.ProgramFragmentFixedFunction;
|
|
||||||
import android.renderscript.RenderScriptGL;
|
|
||||||
import android.renderscript.Type;
|
|
||||||
|
|
||||||
public class FountainFboRS {
|
|
||||||
public static final int PART_COUNT = 50000;
|
|
||||||
|
|
||||||
public FountainFboRS() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private Resources mRes;
|
|
||||||
private RenderScriptGL mRS;
|
|
||||||
private ScriptC_fountainfbo mScript;
|
|
||||||
private Allocation mColorBuffer;
|
|
||||||
private ProgramFragment mProgramFragment;
|
|
||||||
private ProgramFragment mTextureProgramFragment;
|
|
||||||
public void init(RenderScriptGL rs, Resources res) {
|
|
||||||
mRS = rs;
|
|
||||||
mRes = res;
|
|
||||||
|
|
||||||
ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);
|
|
||||||
|
|
||||||
Mesh.AllocationBuilder smb = new Mesh.AllocationBuilder(mRS);
|
|
||||||
smb.addVertexAllocation(points.getAllocation());
|
|
||||||
smb.addIndexSetType(Mesh.Primitive.POINT);
|
|
||||||
Mesh sm = smb.create();
|
|
||||||
|
|
||||||
mScript = new ScriptC_fountainfbo(mRS, mRes, R.raw.fountainfbo);
|
|
||||||
mScript.set_partMesh(sm);
|
|
||||||
mScript.bind_point(points);
|
|
||||||
|
|
||||||
ProgramFragmentFixedFunction.Builder pfb = new ProgramFragmentFixedFunction.Builder(rs);
|
|
||||||
pfb.setVaryingColor(true);
|
|
||||||
mProgramFragment = pfb.create();
|
|
||||||
mScript.set_gProgramFragment(mProgramFragment);
|
|
||||||
|
|
||||||
/* Second fragment shader to use a texture (framebuffer object) to draw with */
|
|
||||||
pfb.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
|
|
||||||
ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
|
|
||||||
|
|
||||||
/* Set the fragment shader in the Renderscript runtime */
|
|
||||||
mTextureProgramFragment = pfb.create();
|
|
||||||
mScript.set_gTextureProgramFragment(mTextureProgramFragment);
|
|
||||||
|
|
||||||
/* Create the allocation for the color buffer */
|
|
||||||
Type.Builder colorBuilder = new Type.Builder(mRS, Element.RGBA_8888(mRS));
|
|
||||||
colorBuilder.setX(256).setY(256);
|
|
||||||
mColorBuffer = Allocation.createTyped(mRS, colorBuilder.create(),
|
|
||||||
Allocation.USAGE_GRAPHICS_TEXTURE |
|
|
||||||
Allocation.USAGE_GRAPHICS_RENDER_TARGET);
|
|
||||||
|
|
||||||
/* Set the allocation in the Renderscript runtime */
|
|
||||||
mScript.set_gColorBuffer(mColorBuffer);
|
|
||||||
|
|
||||||
mRS.bindRootScript(mScript);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean holdingColor[] = new boolean[10];
|
|
||||||
public void newTouchPosition(float x, float y, float pressure, int id) {
|
|
||||||
if (id >= holdingColor.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int rate = (int)(pressure * pressure * 500.f);
|
|
||||||
if (rate > 500) {
|
|
||||||
rate = 500;
|
|
||||||
}
|
|
||||||
if (rate > 0) {
|
|
||||||
mScript.invoke_addParticles(rate, x, y, id, !holdingColor[id]);
|
|
||||||
holdingColor[id] = true;
|
|
||||||
} else {
|
|
||||||
holdingColor[id] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,91 +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.fountainfbo;
|
|
||||||
|
|
||||||
|
|
||||||
import android.renderscript.RSTextureView;
|
|
||||||
import android.renderscript.RenderScriptGL;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.view.MotionEvent;
|
|
||||||
|
|
||||||
public class FountainFboView extends RSTextureView {
|
|
||||||
|
|
||||||
public FountainFboView(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RenderScriptGL mRS;
|
|
||||||
private FountainFboRS mRender;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onAttachedToWindow() {
|
|
||||||
super.onAttachedToWindow();
|
|
||||||
android.util.Log.e("rs", "onAttachedToWindow");
|
|
||||||
if (mRS == null) {
|
|
||||||
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
|
|
||||||
mRS = createRenderScriptGL(sc);
|
|
||||||
mRender = new FountainFboRS();
|
|
||||||
mRender.init(mRS, getResources());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDetachedFromWindow() {
|
|
||||||
super.onDetachedFromWindow();
|
|
||||||
android.util.Log.e("rs", "onDetachedFromWindow");
|
|
||||||
if (mRS != null) {
|
|
||||||
mRS = null;
|
|
||||||
destroyRenderScriptGL();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onTouchEvent(MotionEvent ev)
|
|
||||||
{
|
|
||||||
int act = ev.getActionMasked();
|
|
||||||
if (act == ev.ACTION_UP) {
|
|
||||||
mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0));
|
|
||||||
return false;
|
|
||||||
} else if (act == MotionEvent.ACTION_POINTER_UP) {
|
|
||||||
// only one pointer going up, we can get the index like this
|
|
||||||
int pointerIndex = ev.getActionIndex();
|
|
||||||
int pointerId = ev.getPointerId(pointerIndex);
|
|
||||||
mRender.newTouchPosition(0, 0, 0, pointerId);
|
|
||||||
}
|
|
||||||
int count = ev.getHistorySize();
|
|
||||||
int pcount = ev.getPointerCount();
|
|
||||||
|
|
||||||
for (int p=0; p < pcount; p++) {
|
|
||||||
int id = ev.getPointerId(p);
|
|
||||||
mRender.newTouchPosition(ev.getX(p),
|
|
||||||
ev.getY(p),
|
|
||||||
ev.getPressure(p),
|
|
||||||
id);
|
|
||||||
|
|
||||||
for (int i=0; i < count; i++) {
|
|
||||||
mRender.newTouchPosition(ev.getHistoricalX(p, i),
|
|
||||||
ev.getHistoricalY(p, i),
|
|
||||||
ev.getHistoricalPressure(p, i),
|
|
||||||
id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
// Fountain test script
|
|
||||||
#pragma version(1)
|
|
||||||
|
|
||||||
#pragma rs java_package_name(com.example.android.rs.fountainfbo)
|
|
||||||
|
|
||||||
#pragma stateFragment(parent)
|
|
||||||
|
|
||||||
#include "rs_graphics.rsh"
|
|
||||||
|
|
||||||
static int newPart = 0;
|
|
||||||
rs_mesh partMesh;
|
|
||||||
rs_program_vertex gProgramVertex;
|
|
||||||
|
|
||||||
//allocation for color buffer
|
|
||||||
rs_allocation gColorBuffer;
|
|
||||||
//fragment shader for rendering without a texture (used for rendering to framebuffer object)
|
|
||||||
rs_program_fragment gProgramFragment;
|
|
||||||
//fragment shader for rendering with a texture (used for rendering to default framebuffer)
|
|
||||||
rs_program_fragment gTextureProgramFragment;
|
|
||||||
|
|
||||||
typedef struct __attribute__((packed, aligned(4))) Point {
|
|
||||||
float2 delta;
|
|
||||||
float2 position;
|
|
||||||
uchar4 color;
|
|
||||||
} Point_t;
|
|
||||||
Point_t *point;
|
|
||||||
|
|
||||||
int root() {
|
|
||||||
float dt = min(rsGetDt(), 0.1f);
|
|
||||||
rsgClearColor(0.f, 0.f, 0.f, 1.f);
|
|
||||||
const float height = rsgGetHeight();
|
|
||||||
const int size = rsAllocationGetDimX(rsGetAllocation(point));
|
|
||||||
float dy2 = dt * (10.f);
|
|
||||||
Point_t * p = point;
|
|
||||||
for (int ct=0; ct < size; ct++) {
|
|
||||||
p->delta.y += dy2;
|
|
||||||
p->position += p->delta;
|
|
||||||
if ((p->position.y > height) && (p->delta.y > 0)) {
|
|
||||||
p->delta.y *= -0.3f;
|
|
||||||
}
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
//Tell Renderscript runtime to render to the frame buffer object
|
|
||||||
rsgBindColorTarget(gColorBuffer, 0);
|
|
||||||
|
|
||||||
//Begin rendering on a white background
|
|
||||||
rsgClearColor(1.f, 1.f, 1.f, 1.f);
|
|
||||||
rsgDrawMesh(partMesh);
|
|
||||||
|
|
||||||
//When done, tell Renderscript runtime to stop rendering to framebuffer object
|
|
||||||
rsgClearAllRenderTargets();
|
|
||||||
|
|
||||||
//Bind a new fragment shader that declares the framebuffer object to be used as a texture
|
|
||||||
rsgBindProgramFragment(gTextureProgramFragment);
|
|
||||||
|
|
||||||
//Bind the framebuffer object to the fragment shader at slot 0 as a texture
|
|
||||||
rsgBindTexture(gTextureProgramFragment, 0, gColorBuffer);
|
|
||||||
|
|
||||||
//Draw a quad using the framebuffer object as the texture
|
|
||||||
float startX = 10, startY = 10;
|
|
||||||
float s = 256;
|
|
||||||
rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
|
|
||||||
startX, startY + s, 0, 0, 0,
|
|
||||||
startX + s, startY + s, 0, 1, 0,
|
|
||||||
startX + s, startY, 0, 1, 1);
|
|
||||||
|
|
||||||
//Rebind the original fragment shader to render as normal
|
|
||||||
rsgBindProgramFragment(gProgramFragment);
|
|
||||||
|
|
||||||
//Render the main scene
|
|
||||||
rsgDrawMesh(partMesh);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float4 partColor[10];
|
|
||||||
void addParticles(int rate, float x, float y, int index, bool newColor)
|
|
||||||
{
|
|
||||||
if (newColor) {
|
|
||||||
partColor[index].x = rsRand(0.5f, 1.0f);
|
|
||||||
partColor[index].y = rsRand(1.0f);
|
|
||||||
partColor[index].z = rsRand(1.0f);
|
|
||||||
}
|
|
||||||
float rMax = ((float)rate) * 0.02f;
|
|
||||||
int size = rsAllocationGetDimX(rsGetAllocation(point));
|
|
||||||
uchar4 c = rsPackColorTo8888(partColor[index]);
|
|
||||||
|
|
||||||
Point_t * np = &point[newPart];
|
|
||||||
float2 p = {x, y};
|
|
||||||
while (rate--) {
|
|
||||||
float angle = rsRand(3.14f * 2.f);
|
|
||||||
float len = rsRand(rMax);
|
|
||||||
np->delta.x = len * sin(angle);
|
|
||||||
np->delta.y = len * cos(angle);
|
|
||||||
np->position = p;
|
|
||||||
np->color = c;
|
|
||||||
newPart++;
|
|
||||||
np++;
|
|
||||||
if (newPart >= size) {
|
|
||||||
newPart = 0;
|
|
||||||
np = &point[newPart];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,27 +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 := optional
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
|
|
||||||
$(call all-renderscript-files-under, src)
|
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := RsHelloCompute
|
|
||||||
|
|
||||||
include $(BUILD_PACKAGE)
|
|
||||||
@@ -1,30 +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.hellocompute">
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
||||||
<uses-sdk android:minSdkVersion="14" />
|
|
||||||
<application android:label="RsHelloCompute">
|
|
||||||
<activity android:name="HelloCompute">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
</application>
|
|
||||||
</manifest>
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
<p>A Renderscript compute sample that filters a bitmap. No Renderscript graphics APIs are used
|
|
||||||
in this sample.</p>
|
|
||||||
|
Before Width: | Height: | Size: 75 KiB |
@@ -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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/displayin"
|
|
||||||
android:layout_width="320dip"
|
|
||||||
android:layout_height="266dip" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/displayout"
|
|
||||||
android:layout_width="320dip"
|
|
||||||
android:layout_height="266dip" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,74 +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.hellocompute;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.renderscript.RenderScript;
|
|
||||||
import android.renderscript.Allocation;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
public class HelloCompute extends Activity {
|
|
||||||
private Bitmap mBitmapIn;
|
|
||||||
private Bitmap mBitmapOut;
|
|
||||||
|
|
||||||
private RenderScript mRS;
|
|
||||||
private Allocation mInAllocation;
|
|
||||||
private Allocation mOutAllocation;
|
|
||||||
private ScriptC_mono mScript;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.main);
|
|
||||||
|
|
||||||
mBitmapIn = loadBitmap(R.drawable.data);
|
|
||||||
mBitmapOut = Bitmap.createBitmap(mBitmapIn.getWidth(), mBitmapIn.getHeight(),
|
|
||||||
mBitmapIn.getConfig());
|
|
||||||
|
|
||||||
ImageView in = (ImageView) findViewById(R.id.displayin);
|
|
||||||
in.setImageBitmap(mBitmapIn);
|
|
||||||
|
|
||||||
ImageView out = (ImageView) findViewById(R.id.displayout);
|
|
||||||
out.setImageBitmap(mBitmapOut);
|
|
||||||
|
|
||||||
createScript();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void createScript() {
|
|
||||||
mRS = RenderScript.create(this);
|
|
||||||
|
|
||||||
mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
|
|
||||||
Allocation.MipmapControl.MIPMAP_NONE,
|
|
||||||
Allocation.USAGE_SCRIPT);
|
|
||||||
mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType());
|
|
||||||
|
|
||||||
mScript = new ScriptC_mono(mRS, getResources(), R.raw.mono);
|
|
||||||
|
|
||||||
mScript.forEach_root(mInAllocation, mOutAllocation);
|
|
||||||
mOutAllocation.copyTo(mBitmapOut);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Bitmap loadBitmap(int resource) {
|
|
||||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
|
||||||
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
|
||||||
return BitmapFactory.decodeResource(getResources(), resource, options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma version(1)
|
|
||||||
#pragma rs java_package_name(com.example.android.rs.hellocompute)
|
|
||||||
|
|
||||||
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
|
|
||||||
|
|
||||||
void root(const uchar4 *v_in, uchar4 *v_out) {
|
|
||||||
float4 f4 = rsUnpackColor8888(*v_in);
|
|
||||||
|
|
||||||
float3 mono = dot(f4.rgb, gMonoMult);
|
|
||||||
*v_out = rsPackColorTo8888(mono);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -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 := optional
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := RsHelloWorld
|
|
||||||
|
|
||||||
LOCAL_SDK_VERSION := current
|
|
||||||
|
|
||||||
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,26 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (C) 2012 The Android Open Source Project
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
#
|
|
||||||
|
|
||||||
LOCAL_PATH := $(call my-dir)
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE_TAGS := optional
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := LevelsRS
|
|
||||||
|
|
||||||
include $(BUILD_PACKAGE)
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
-->
|
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.android.rs.levels">
|
|
||||||
<uses-sdk android:minSdkVersion="14" />
|
|
||||||
<application android:label="Levels RS"
|
|
||||||
android:hardwareAccelerated="true">
|
|
||||||
|
|
||||||
<activity android:name="LevelsRSActivity"
|
|
||||||
android:label="Levels RS">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity android:name="LevelsDalvikActivity"
|
|
||||||
android:label="Levels Dalvik">
|
|
||||||
<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: 597 KiB |
@@ -1,140 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2012 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:id="@+id/toplevel">
|
|
||||||
<SurfaceView
|
|
||||||
android:id="@+id/surface"
|
|
||||||
android:layout_width="1dip"
|
|
||||||
android:layout_height="1dip" />
|
|
||||||
<ScrollView
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/display"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<Button
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/benchmark"
|
|
||||||
android:onClick="benchmark"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/benchmarkText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:text="@string/saturation"/>
|
|
||||||
</LinearLayout>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/inSaturationText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/saturation"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/inSaturation"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/outWhiteText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:text="@string/out_white"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/outWhite"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/inWhiteText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/in_white"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/inWhite"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/outBlackText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/out_black"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/outBlack"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/inBlackText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/in_black"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/inBlack"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/inGammaText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/gamma"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/inGamma"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2012 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:id="@+id/toplevel">
|
|
||||||
<SurfaceView
|
|
||||||
android:id="@+id/surface"
|
|
||||||
android:layout_width="1dip"
|
|
||||||
android:layout_height="1dip" />
|
|
||||||
<ScrollView
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
<TextureView
|
|
||||||
android:id="@+id/display"
|
|
||||||
android:layout_width="800sp"
|
|
||||||
android:layout_height="423sp" />
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<Button
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/benchmark"
|
|
||||||
android:onClick="benchmark"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/benchmarkText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:text="@string/saturation"/>
|
|
||||||
</LinearLayout>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/inSaturationText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/saturation"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/inSaturation"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/outWhiteText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:text="@string/out_white"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/outWhite"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/inWhiteText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/in_white"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/inWhite"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/outBlackText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/out_black"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/outBlack"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/inBlackText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/in_black"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/inBlack"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/inGammaText"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="8pt"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginTop="15sp"
|
|
||||||
android:text="@string/gamma"/>
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/inGamma"
|
|
||||||
android:layout_marginLeft="10sp"
|
|
||||||
android:layout_marginRight="10sp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
-->
|
|
||||||
|
|
||||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
|
||||||
<!-- General -->
|
|
||||||
<skip />
|
|
||||||
<!--slider label -->
|
|
||||||
<string name="in_white">In White</string>
|
|
||||||
<string name="out_white">Out White</string>
|
|
||||||
<string name="in_black">In Black</string>
|
|
||||||
<string name="out_black">Out Black</string>
|
|
||||||
<string name="gamma">Gamma</string>
|
|
||||||
<string name="saturation">Saturation</string>
|
|
||||||
<string name="benchmark">Benchmark</string>
|
|
||||||
|
|
||||||
</resources>
|
|
||||||
@@ -1,239 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.rs.levels;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.renderscript.Matrix3f;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.SeekBar;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
public class LevelsDalvikActivity extends Activity
|
|
||||||
implements SeekBar.OnSeekBarChangeListener {
|
|
||||||
private final String TAG = "Img";
|
|
||||||
private Bitmap mBitmapIn;
|
|
||||||
private Bitmap mBitmapOut;
|
|
||||||
private float mInBlack = 0.0f;
|
|
||||||
private SeekBar mInBlackSeekBar;
|
|
||||||
private float mOutBlack = 0.0f;
|
|
||||||
private SeekBar mOutBlackSeekBar;
|
|
||||||
private float mInWhite = 255.0f;
|
|
||||||
private SeekBar mInWhiteSeekBar;
|
|
||||||
private float mOutWhite = 255.0f;
|
|
||||||
private SeekBar mOutWhiteSeekBar;
|
|
||||||
private float mGamma = 1.0f;
|
|
||||||
private SeekBar mGammaSeekBar;
|
|
||||||
private float mSaturation = 1.0f;
|
|
||||||
private SeekBar mSaturationSeekBar;
|
|
||||||
private TextView mBenchmarkResult;
|
|
||||||
private ImageView mDisplayView;
|
|
||||||
|
|
||||||
Matrix3f satMatrix = new Matrix3f();
|
|
||||||
float mInWMinInB;
|
|
||||||
float mOutWMinOutB;
|
|
||||||
float mOverInWMinInB;
|
|
||||||
|
|
||||||
int mInPixels[];
|
|
||||||
int mOutPixels[];
|
|
||||||
|
|
||||||
private void setLevels() {
|
|
||||||
mInWMinInB = mInWhite - mInBlack;
|
|
||||||
mOutWMinOutB = mOutWhite - mOutBlack;
|
|
||||||
mOverInWMinInB = 1.f / mInWMinInB;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSaturation() {
|
|
||||||
float rWeight = 0.299f;
|
|
||||||
float gWeight = 0.587f;
|
|
||||||
float bWeight = 0.114f;
|
|
||||||
float oneMinusS = 1.0f - mSaturation;
|
|
||||||
|
|
||||||
satMatrix.set(0, 0, oneMinusS * rWeight + mSaturation);
|
|
||||||
satMatrix.set(0, 1, oneMinusS * rWeight);
|
|
||||||
satMatrix.set(0, 2, oneMinusS * rWeight);
|
|
||||||
satMatrix.set(1, 0, oneMinusS * gWeight);
|
|
||||||
satMatrix.set(1, 1, oneMinusS * gWeight + mSaturation);
|
|
||||||
satMatrix.set(1, 2, oneMinusS * gWeight);
|
|
||||||
satMatrix.set(2, 0, oneMinusS * bWeight);
|
|
||||||
satMatrix.set(2, 1, oneMinusS * bWeight);
|
|
||||||
satMatrix.set(2, 2, oneMinusS * bWeight + mSaturation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
|
||||||
if (fromUser) {
|
|
||||||
if (seekBar == mInBlackSeekBar) {
|
|
||||||
mInBlack = (float)progress;
|
|
||||||
setLevels();
|
|
||||||
} else if (seekBar == mOutBlackSeekBar) {
|
|
||||||
mOutBlack = (float)progress;
|
|
||||||
setLevels();
|
|
||||||
} else if (seekBar == mInWhiteSeekBar) {
|
|
||||||
mInWhite = (float)progress + 127.0f;
|
|
||||||
setLevels();
|
|
||||||
} else if (seekBar == mOutWhiteSeekBar) {
|
|
||||||
mOutWhite = (float)progress + 127.0f;
|
|
||||||
setLevels();
|
|
||||||
} else if (seekBar == mGammaSeekBar) {
|
|
||||||
mGamma = (float)progress/100.0f;
|
|
||||||
mGamma = Math.max(mGamma, 0.1f);
|
|
||||||
mGamma = 1.0f / mGamma;
|
|
||||||
} else if (seekBar == mSaturationSeekBar) {
|
|
||||||
mSaturation = (float)progress / 50.0f;
|
|
||||||
setSaturation();
|
|
||||||
}
|
|
||||||
|
|
||||||
filter();
|
|
||||||
mDisplayView.invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.main);
|
|
||||||
|
|
||||||
mBitmapIn = loadBitmap(R.drawable.city);
|
|
||||||
mBitmapOut = loadBitmap(R.drawable.city);
|
|
||||||
|
|
||||||
mDisplayView = (ImageView) findViewById(R.id.display);
|
|
||||||
mDisplayView.setImageBitmap(mBitmapOut);
|
|
||||||
|
|
||||||
mInBlackSeekBar = (SeekBar)findViewById(R.id.inBlack);
|
|
||||||
mInBlackSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mInBlackSeekBar.setMax(128);
|
|
||||||
mInBlackSeekBar.setProgress(0);
|
|
||||||
mOutBlackSeekBar = (SeekBar)findViewById(R.id.outBlack);
|
|
||||||
mOutBlackSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mOutBlackSeekBar.setMax(128);
|
|
||||||
mOutBlackSeekBar.setProgress(0);
|
|
||||||
|
|
||||||
mInWhiteSeekBar = (SeekBar)findViewById(R.id.inWhite);
|
|
||||||
mInWhiteSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mInWhiteSeekBar.setMax(128);
|
|
||||||
mInWhiteSeekBar.setProgress(128);
|
|
||||||
mOutWhiteSeekBar = (SeekBar)findViewById(R.id.outWhite);
|
|
||||||
mOutWhiteSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mOutWhiteSeekBar.setMax(128);
|
|
||||||
mOutWhiteSeekBar.setProgress(128);
|
|
||||||
|
|
||||||
mGammaSeekBar = (SeekBar)findViewById(R.id.inGamma);
|
|
||||||
mGammaSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mGammaSeekBar.setMax(150);
|
|
||||||
mGammaSeekBar.setProgress(100);
|
|
||||||
|
|
||||||
mSaturationSeekBar = (SeekBar)findViewById(R.id.inSaturation);
|
|
||||||
mSaturationSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mSaturationSeekBar.setProgress(50);
|
|
||||||
|
|
||||||
mBenchmarkResult = (TextView) findViewById(R.id.benchmarkText);
|
|
||||||
mBenchmarkResult.setText("Result: not run");
|
|
||||||
|
|
||||||
mInPixels = new int[mBitmapIn.getHeight() * mBitmapIn.getWidth()];
|
|
||||||
mOutPixels = new int[mBitmapOut.getHeight() * mBitmapOut.getWidth()];
|
|
||||||
mBitmapIn.getPixels(mInPixels, 0, mBitmapIn.getWidth(), 0, 0,
|
|
||||||
mBitmapIn.getWidth(), mBitmapIn.getHeight());
|
|
||||||
|
|
||||||
setLevels();
|
|
||||||
setSaturation();
|
|
||||||
filter();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Bitmap loadBitmap(int resource) {
|
|
||||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
|
||||||
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
|
||||||
Bitmap b = BitmapFactory.decodeResource(getResources(), resource, options);
|
|
||||||
Bitmap b2 = Bitmap.createBitmap(b.getWidth(), b.getHeight(), b.getConfig());
|
|
||||||
Canvas c = new Canvas(b2);
|
|
||||||
c.drawBitmap(b, 0, 0, null);
|
|
||||||
b.recycle();
|
|
||||||
return b2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void filter() {
|
|
||||||
final float[] m = satMatrix.getArray();
|
|
||||||
|
|
||||||
for (int i=0; i < mInPixels.length; i++) {
|
|
||||||
float r = (float)(mInPixels[i] & 0xff);
|
|
||||||
float g = (float)((mInPixels[i] >> 8) & 0xff);
|
|
||||||
float b = (float)((mInPixels[i] >> 16) & 0xff);
|
|
||||||
|
|
||||||
float tr = r * m[0] + g * m[3] + b * m[6];
|
|
||||||
float tg = r * m[1] + g * m[4] + b * m[7];
|
|
||||||
float tb = r * m[2] + g * m[5] + b * m[8];
|
|
||||||
r = tr;
|
|
||||||
g = tg;
|
|
||||||
b = tb;
|
|
||||||
|
|
||||||
if (r < 0.f) r = 0.f;
|
|
||||||
if (r > 255.f) r = 255.f;
|
|
||||||
if (g < 0.f) g = 0.f;
|
|
||||||
if (g > 255.f) g = 255.f;
|
|
||||||
if (b < 0.f) b = 0.f;
|
|
||||||
if (b > 255.f) b = 255.f;
|
|
||||||
|
|
||||||
r = (r - mInBlack) * mOverInWMinInB;
|
|
||||||
g = (g - mInBlack) * mOverInWMinInB;
|
|
||||||
b = (b - mInBlack) * mOverInWMinInB;
|
|
||||||
|
|
||||||
if (mGamma != 1.0f) {
|
|
||||||
r = (float)java.lang.Math.pow(r, mGamma);
|
|
||||||
g = (float)java.lang.Math.pow(g, mGamma);
|
|
||||||
b = (float)java.lang.Math.pow(b, mGamma);
|
|
||||||
}
|
|
||||||
|
|
||||||
r = (r * mOutWMinOutB) + mOutBlack;
|
|
||||||
g = (g * mOutWMinOutB) + mOutBlack;
|
|
||||||
b = (b * mOutWMinOutB) + mOutBlack;
|
|
||||||
|
|
||||||
if (r < 0.f) r = 0.f;
|
|
||||||
if (r > 255.f) r = 255.f;
|
|
||||||
if (g < 0.f) g = 0.f;
|
|
||||||
if (g > 255.f) g = 255.f;
|
|
||||||
if (b < 0.f) b = 0.f;
|
|
||||||
if (b > 255.f) b = 255.f;
|
|
||||||
|
|
||||||
mOutPixels[i] = ((int)r) + (((int)g) << 8) + (((int)b) << 16)
|
|
||||||
+ (mInPixels[i] & 0xff000000);
|
|
||||||
}
|
|
||||||
|
|
||||||
mBitmapOut.setPixels(mOutPixels, 0, mBitmapOut.getWidth(), 0, 0,
|
|
||||||
mBitmapOut.getWidth(), mBitmapOut.getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void benchmark(View v) {
|
|
||||||
filter();
|
|
||||||
long t = java.lang.System.currentTimeMillis();
|
|
||||||
filter();
|
|
||||||
t = java.lang.System.currentTimeMillis() - t;
|
|
||||||
mDisplayView.invalidate();
|
|
||||||
mBenchmarkResult.setText("Result: " + t + " ms");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,232 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.rs.levels;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.graphics.SurfaceTexture;
|
|
||||||
import android.renderscript.Allocation;
|
|
||||||
import android.renderscript.Matrix3f;
|
|
||||||
import android.renderscript.RenderScript;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.TextureView;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.SeekBar;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
public class LevelsRSActivity extends Activity
|
|
||||||
implements SeekBar.OnSeekBarChangeListener,
|
|
||||||
TextureView.SurfaceTextureListener
|
|
||||||
{
|
|
||||||
private final String TAG = "Img";
|
|
||||||
private Bitmap mBitmapIn;
|
|
||||||
private float mInBlack = 0.0f;
|
|
||||||
private SeekBar mInBlackSeekBar;
|
|
||||||
private float mOutBlack = 0.0f;
|
|
||||||
private SeekBar mOutBlackSeekBar;
|
|
||||||
private float mInWhite = 255.0f;
|
|
||||||
private SeekBar mInWhiteSeekBar;
|
|
||||||
private float mOutWhite = 255.0f;
|
|
||||||
private SeekBar mOutWhiteSeekBar;
|
|
||||||
private float mGamma = 1.0f;
|
|
||||||
private SeekBar mGammaSeekBar;
|
|
||||||
private float mSaturation = 1.0f;
|
|
||||||
private SeekBar mSaturationSeekBar;
|
|
||||||
private TextView mBenchmarkResult;
|
|
||||||
private TextureView mDisplayView;
|
|
||||||
|
|
||||||
Matrix3f satMatrix = new Matrix3f();
|
|
||||||
float mInWMinInB;
|
|
||||||
float mOutWMinOutB;
|
|
||||||
float mOverInWMinInB;
|
|
||||||
|
|
||||||
private RenderScript mRS;
|
|
||||||
private Allocation mInPixelsAllocation;
|
|
||||||
private Allocation mOutPixelsAllocation;
|
|
||||||
private ScriptC_levels mScript;
|
|
||||||
|
|
||||||
private void setLevels() {
|
|
||||||
mInWMinInB = mInWhite - mInBlack;
|
|
||||||
mOutWMinOutB = mOutWhite - mOutBlack;
|
|
||||||
mOverInWMinInB = 1.f / mInWMinInB;
|
|
||||||
|
|
||||||
mScript.set_inBlack(mInBlack);
|
|
||||||
mScript.set_outBlack(mOutBlack);
|
|
||||||
mScript.set_inWMinInB(mInWMinInB);
|
|
||||||
mScript.set_outWMinOutB(mOutWMinOutB);
|
|
||||||
mScript.set_overInWMinInB(mOverInWMinInB);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSaturation() {
|
|
||||||
float rWeight = 0.299f;
|
|
||||||
float gWeight = 0.587f;
|
|
||||||
float bWeight = 0.114f;
|
|
||||||
float oneMinusS = 1.0f - mSaturation;
|
|
||||||
|
|
||||||
satMatrix.set(0, 0, oneMinusS * rWeight + mSaturation);
|
|
||||||
satMatrix.set(0, 1, oneMinusS * rWeight);
|
|
||||||
satMatrix.set(0, 2, oneMinusS * rWeight);
|
|
||||||
satMatrix.set(1, 0, oneMinusS * gWeight);
|
|
||||||
satMatrix.set(1, 1, oneMinusS * gWeight + mSaturation);
|
|
||||||
satMatrix.set(1, 2, oneMinusS * gWeight);
|
|
||||||
satMatrix.set(2, 0, oneMinusS * bWeight);
|
|
||||||
satMatrix.set(2, 1, oneMinusS * bWeight);
|
|
||||||
satMatrix.set(2, 2, oneMinusS * bWeight + mSaturation);
|
|
||||||
mScript.set_colorMat(satMatrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
|
||||||
if (fromUser) {
|
|
||||||
if (seekBar == mInBlackSeekBar) {
|
|
||||||
mInBlack = (float)progress;
|
|
||||||
setLevels();
|
|
||||||
} else if (seekBar == mOutBlackSeekBar) {
|
|
||||||
mOutBlack = (float)progress;
|
|
||||||
setLevels();
|
|
||||||
} else if (seekBar == mInWhiteSeekBar) {
|
|
||||||
mInWhite = (float)progress + 127.0f;
|
|
||||||
setLevels();
|
|
||||||
} else if (seekBar == mOutWhiteSeekBar) {
|
|
||||||
mOutWhite = (float)progress + 127.0f;
|
|
||||||
setLevels();
|
|
||||||
} else if (seekBar == mGammaSeekBar) {
|
|
||||||
mGamma = (float)progress/100.0f;
|
|
||||||
mGamma = Math.max(mGamma, 0.1f);
|
|
||||||
mGamma = 1.0f / mGamma;
|
|
||||||
mScript.set_gamma(mGamma);
|
|
||||||
} else if (seekBar == mSaturationSeekBar) {
|
|
||||||
mSaturation = (float)progress / 50.0f;
|
|
||||||
setSaturation();
|
|
||||||
}
|
|
||||||
|
|
||||||
filter();
|
|
||||||
mDisplayView.invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.rs);
|
|
||||||
|
|
||||||
mBitmapIn = loadBitmap(R.drawable.city);
|
|
||||||
mDisplayView = (TextureView) findViewById(R.id.display);
|
|
||||||
|
|
||||||
mInBlackSeekBar = (SeekBar)findViewById(R.id.inBlack);
|
|
||||||
mInBlackSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mInBlackSeekBar.setMax(128);
|
|
||||||
mInBlackSeekBar.setProgress(0);
|
|
||||||
mOutBlackSeekBar = (SeekBar)findViewById(R.id.outBlack);
|
|
||||||
mOutBlackSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mOutBlackSeekBar.setMax(128);
|
|
||||||
mOutBlackSeekBar.setProgress(0);
|
|
||||||
|
|
||||||
mInWhiteSeekBar = (SeekBar)findViewById(R.id.inWhite);
|
|
||||||
mInWhiteSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mInWhiteSeekBar.setMax(128);
|
|
||||||
mInWhiteSeekBar.setProgress(128);
|
|
||||||
mOutWhiteSeekBar = (SeekBar)findViewById(R.id.outWhite);
|
|
||||||
mOutWhiteSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mOutWhiteSeekBar.setMax(128);
|
|
||||||
mOutWhiteSeekBar.setProgress(128);
|
|
||||||
|
|
||||||
mGammaSeekBar = (SeekBar)findViewById(R.id.inGamma);
|
|
||||||
mGammaSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mGammaSeekBar.setMax(150);
|
|
||||||
mGammaSeekBar.setProgress(100);
|
|
||||||
|
|
||||||
mSaturationSeekBar = (SeekBar)findViewById(R.id.inSaturation);
|
|
||||||
mSaturationSeekBar.setOnSeekBarChangeListener(this);
|
|
||||||
mSaturationSeekBar.setProgress(50);
|
|
||||||
|
|
||||||
mBenchmarkResult = (TextView) findViewById(R.id.benchmarkText);
|
|
||||||
mBenchmarkResult.setText("Result: not run");
|
|
||||||
|
|
||||||
mRS = RenderScript.create(this);
|
|
||||||
mInPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapIn,
|
|
||||||
Allocation.MipmapControl.MIPMAP_NONE,
|
|
||||||
Allocation.USAGE_SCRIPT);
|
|
||||||
mOutPixelsAllocation = Allocation.createTyped(mRS, mInPixelsAllocation.getType(),
|
|
||||||
Allocation.USAGE_SCRIPT |
|
|
||||||
Allocation.USAGE_IO_OUTPUT);
|
|
||||||
mDisplayView.setSurfaceTextureListener(this);
|
|
||||||
|
|
||||||
mScript = new ScriptC_levels(mRS, getResources(), R.raw.levels);
|
|
||||||
mScript.set_gamma(mGamma);
|
|
||||||
|
|
||||||
setSaturation();
|
|
||||||
setLevels();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Bitmap loadBitmap(int resource) {
|
|
||||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
|
||||||
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
|
||||||
Bitmap b = BitmapFactory.decodeResource(getResources(), resource, options);
|
|
||||||
Bitmap b2 = Bitmap.createBitmap(b.getWidth(), b.getHeight(), b.getConfig());
|
|
||||||
Canvas c = new Canvas(b2);
|
|
||||||
c.drawBitmap(b, 0, 0, null);
|
|
||||||
b.recycle();
|
|
||||||
return b2;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void filter() {
|
|
||||||
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
|
|
||||||
mOutPixelsAllocation.ioSendOutput();
|
|
||||||
mRS.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void benchmark(View v) {
|
|
||||||
filter();
|
|
||||||
long t = java.lang.System.currentTimeMillis();
|
|
||||||
filter();
|
|
||||||
t = java.lang.System.currentTimeMillis() - t;
|
|
||||||
mDisplayView.invalidate();
|
|
||||||
mBenchmarkResult.setText("Result: " + t + " ms");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
|
|
||||||
mOutPixelsAllocation.setSurfaceTexture(surface);
|
|
||||||
filter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
|
|
||||||
mOutPixelsAllocation.setSurfaceTexture(surface);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
|
||||||
mOutPixelsAllocation.setSurfaceTexture(null);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma version(1)
|
|
||||||
#pragma rs java_package_name(com.android.rs.levels)
|
|
||||||
|
|
||||||
float inBlack;
|
|
||||||
float outBlack;
|
|
||||||
float inWMinInB;
|
|
||||||
float outWMinOutB;
|
|
||||||
float overInWMinInB;
|
|
||||||
float gamma;
|
|
||||||
rs_matrix3x3 colorMat;
|
|
||||||
|
|
||||||
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
|
|
||||||
float3 pixel = convert_float4(in[0]).rgb;
|
|
||||||
pixel = rsMatrixMultiply(&colorMat, pixel);
|
|
||||||
pixel = clamp(pixel, 0.f, 255.f);
|
|
||||||
pixel = (pixel - inBlack) * overInWMinInB;
|
|
||||||
if (gamma != 1.0f)
|
|
||||||
pixel = pow(pixel, (float3)gamma);
|
|
||||||
pixel = pixel * outWMinOutB + outBlack;
|
|
||||||
pixel = clamp(pixel, 0.f, 255.f);
|
|
||||||
out->xyz = convert_uchar3(pixel);
|
|
||||||
out->w = 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -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 := optional
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
|
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := RsMiscSamples
|
|
||||||
|
|
||||||
LOCAL_SDK_VERSION := current
|
|
||||||
|
|
||||||
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 +0,0 @@
|
|||||||
<p>A set of samples that demonstrate how to use various features of the Renderscript APIs.</p>
|
|
||||||
@@ -1,40 +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)
|
|
||||||
|
|
||||||
# Host executable
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
LOCAL_MODULE := a3dconvert
|
|
||||||
LOCAL_MODULE_TAGS := optional
|
|
||||||
LOCAL_CFLAGS += -DANDROID_RS_SERIALIZE
|
|
||||||
# Needed for colladaDom
|
|
||||||
LOCAL_CFLAGS += -DNO_BOOST -DDOM_INCLUDE_TINYXML -DNO_ZAE
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
|
||||||
a3dconvert.cpp \
|
|
||||||
ObjLoader.cpp \
|
|
||||||
ColladaConditioner.cpp \
|
|
||||||
ColladaGeometry.cpp \
|
|
||||||
ColladaLoader.cpp
|
|
||||||
|
|
||||||
LOCAL_C_INCLUDES += external/collada/include
|
|
||||||
LOCAL_C_INCLUDES += external/collada/include/1.4
|
|
||||||
LOCAL_C_INCLUDES += frameworks/rs
|
|
||||||
LOCAL_C_INCLUDES += $(intermediates)
|
|
||||||
|
|
||||||
LOCAL_LDLIBS := -ldl -lpthread
|
|
||||||
LOCAL_STATIC_LIBRARIES += libRS libutils libcutils
|
|
||||||
LOCAL_STATIC_LIBRARIES += colladadom libtinyxml libpcrecpp libpcre
|
|
||||||
include $(BUILD_HOST_EXECUTABLE)
|
|
||||||
@@ -1,251 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the MIT Open Source License, for details please see license.txt or the website
|
|
||||||
* http://www.opensource.org/licenses/mit-license.php
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ColladaConditioner.h"
|
|
||||||
unsigned int ColladaConditioner::getMaxOffset( domInputLocalOffset_Array &input_array ) {
|
|
||||||
|
|
||||||
unsigned int maxOffset = 0;
|
|
||||||
for ( unsigned int i = 0; i < input_array.getCount(); i++ ) {
|
|
||||||
if ( input_array[i]->getOffset() > maxOffset ) {
|
|
||||||
maxOffset = (unsigned int)input_array[i]->getOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return maxOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColladaConditioner::createTrianglesFromPolylist( domMesh *thisMesh, domPolylist *thisPolylist ) {
|
|
||||||
|
|
||||||
// Create a new <triangles> inside the mesh that has the same material as the <polylist>
|
|
||||||
domTriangles *thisTriangles = (domTriangles *)thisMesh->createAndPlace("triangles");
|
|
||||||
//thisTriangles->setCount( 0 );
|
|
||||||
unsigned int triangles = 0;
|
|
||||||
thisTriangles->setMaterial(thisPolylist->getMaterial());
|
|
||||||
domP* p_triangles = (domP*)thisTriangles->createAndPlace("p");
|
|
||||||
|
|
||||||
// Give the new <triangles> the same <_dae> and <parameters> as the old <polylist>
|
|
||||||
for(int i=0; i<(int)(thisPolylist->getInput_array().getCount()); i++) {
|
|
||||||
|
|
||||||
thisTriangles->placeElement( thisPolylist->getInput_array()[i]->clone() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the number of inputs and primitives for the polygons array
|
|
||||||
int numberOfInputs = (int)getMaxOffset(thisPolylist->getInput_array()) + 1;
|
|
||||||
int numberOfPrimitives = (int)(thisPolylist->getVcount()->getValue().getCount());
|
|
||||||
|
|
||||||
unsigned int offset = 0;
|
|
||||||
|
|
||||||
// Triangulate all the primitives, this generates all the triangles in a single <p> element
|
|
||||||
for(int j = 0; j < numberOfPrimitives; j++) {
|
|
||||||
|
|
||||||
int triangleCount = (int)thisPolylist->getVcount()->getValue()[j] -2;
|
|
||||||
// Write out the primitives as triangles, just fan using the first element as the base
|
|
||||||
int idx = numberOfInputs;
|
|
||||||
for(int k = 0; k < triangleCount; k++) {
|
|
||||||
// First vertex
|
|
||||||
for(int l = 0; l < numberOfInputs; l++) {
|
|
||||||
|
|
||||||
p_triangles->getValue().append(thisPolylist->getP()->getValue()[offset + l]);
|
|
||||||
}
|
|
||||||
// Second vertex
|
|
||||||
for(int l = 0; l < numberOfInputs; l++) {
|
|
||||||
|
|
||||||
p_triangles->getValue().append(thisPolylist->getP()->getValue()[offset + idx + l]);
|
|
||||||
}
|
|
||||||
// Third vertex
|
|
||||||
idx += numberOfInputs;
|
|
||||||
for(int l = 0; l < numberOfInputs; l++) {
|
|
||||||
|
|
||||||
p_triangles->getValue().append(thisPolylist->getP()->getValue()[offset + idx + l]);
|
|
||||||
}
|
|
||||||
triangles++;
|
|
||||||
}
|
|
||||||
offset += (unsigned int)thisPolylist->getVcount()->getValue()[j] * numberOfInputs;
|
|
||||||
}
|
|
||||||
thisTriangles->setCount( triangles );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColladaConditioner::createTrianglesFromPolygons( domMesh *thisMesh, domPolygons *thisPolygons ) {
|
|
||||||
|
|
||||||
// Create a new <triangles> inside the mesh that has the same material as the <polygons>
|
|
||||||
domTriangles *thisTriangles = (domTriangles *)thisMesh->createAndPlace("triangles");
|
|
||||||
thisTriangles->setCount( 0 );
|
|
||||||
thisTriangles->setMaterial(thisPolygons->getMaterial());
|
|
||||||
domP* p_triangles = (domP*)thisTriangles->createAndPlace("p");
|
|
||||||
|
|
||||||
// Give the new <triangles> the same <_dae> and <parameters> as the old <polygons>
|
|
||||||
for(int i=0; i<(int)(thisPolygons->getInput_array().getCount()); i++) {
|
|
||||||
|
|
||||||
thisTriangles->placeElement( thisPolygons->getInput_array()[i]->clone() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the number of inputs and primitives for the polygons array
|
|
||||||
int numberOfInputs = (int)getMaxOffset(thisPolygons->getInput_array()) +1;
|
|
||||||
int numberOfPrimitives = (int)(thisPolygons->getP_array().getCount());
|
|
||||||
|
|
||||||
// Triangulate all the primitives, this generates all the triangles in a single <p> element
|
|
||||||
for(int j = 0; j < numberOfPrimitives; j++) {
|
|
||||||
|
|
||||||
// Check the polygons for consistancy (some exported files have had the wrong number of indices)
|
|
||||||
domP * thisPrimitive = thisPolygons->getP_array()[j];
|
|
||||||
int elementCount = (int)(thisPrimitive->getValue().getCount());
|
|
||||||
// Skip the invalid primitive
|
|
||||||
if((elementCount % numberOfInputs) != 0) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
int triangleCount = (elementCount/numberOfInputs)-2;
|
|
||||||
// Write out the primitives as triangles, just fan using the first element as the base
|
|
||||||
int idx = numberOfInputs;
|
|
||||||
for(int k = 0; k < triangleCount; k++) {
|
|
||||||
// First vertex
|
|
||||||
for(int l = 0; l < numberOfInputs; l++) {
|
|
||||||
|
|
||||||
p_triangles->getValue().append(thisPrimitive->getValue()[l]);
|
|
||||||
}
|
|
||||||
// Second vertex
|
|
||||||
for(int l = 0; l < numberOfInputs; l++) {
|
|
||||||
|
|
||||||
p_triangles->getValue().append(thisPrimitive->getValue()[idx + l]);
|
|
||||||
}
|
|
||||||
// Third vertex
|
|
||||||
idx += numberOfInputs;
|
|
||||||
for(int l = 0; l < numberOfInputs; l++) {
|
|
||||||
|
|
||||||
p_triangles->getValue().append(thisPrimitive->getValue()[idx + l]);
|
|
||||||
}
|
|
||||||
thisTriangles->setCount(thisTriangles->getCount()+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ColladaConditioner::triangulate(DAE *dae) {
|
|
||||||
|
|
||||||
int error = 0;
|
|
||||||
|
|
||||||
// How many geometry elements are there?
|
|
||||||
int geometryElementCount = (int)(dae->getDatabase()->getElementCount(NULL, "geometry" ));
|
|
||||||
|
|
||||||
for(int currentGeometry = 0; currentGeometry < geometryElementCount; currentGeometry++) {
|
|
||||||
|
|
||||||
// Find the next geometry element
|
|
||||||
domGeometry *thisGeometry;
|
|
||||||
// error = _dae->getDatabase()->getElement((daeElement**)&thisGeometry,currentGeometry, NULL, "geometry");
|
|
||||||
daeElement * element = 0;
|
|
||||||
error = dae->getDatabase()->getElement(&element,currentGeometry, NULL, "geometry");
|
|
||||||
thisGeometry = (domGeometry *) element;
|
|
||||||
|
|
||||||
// Get the mesh out of the geometry
|
|
||||||
domMesh *thisMesh = thisGeometry->getMesh();
|
|
||||||
|
|
||||||
if (thisMesh == NULL){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop over all the polygon elements
|
|
||||||
for(int currentPolygons = 0; currentPolygons < (int)(thisMesh->getPolygons_array().getCount()); currentPolygons++) {
|
|
||||||
|
|
||||||
// Get the polygons out of the mesh
|
|
||||||
// Always get index 0 because every pass through this loop deletes the <polygons> element as it finishes with it
|
|
||||||
domPolygons *thisPolygons = thisMesh->getPolygons_array()[currentPolygons];
|
|
||||||
createTrianglesFromPolygons( thisMesh, thisPolygons );
|
|
||||||
}
|
|
||||||
while (thisMesh->getPolygons_array().getCount() > 0) {
|
|
||||||
|
|
||||||
domPolygons *thisPolygons = thisMesh->getPolygons_array().get(0);
|
|
||||||
// Remove the polygons from the mesh
|
|
||||||
thisMesh->removeChildElement(thisPolygons);
|
|
||||||
}
|
|
||||||
int polylistElementCount = (int)(thisMesh->getPolylist_array().getCount());
|
|
||||||
for(int currentPolylist = 0; currentPolylist < polylistElementCount; currentPolylist++) {
|
|
||||||
|
|
||||||
// Get the polylist out of the mesh
|
|
||||||
// Always get index 0 because every pass through this loop deletes the <polygons> element as it finishes with it
|
|
||||||
domPolylist *thisPolylist = thisMesh->getPolylist_array()[currentPolylist];
|
|
||||||
createTrianglesFromPolylist( thisMesh, thisPolylist );
|
|
||||||
}
|
|
||||||
while (thisMesh->getPolylist_array().getCount() > 0) {
|
|
||||||
|
|
||||||
domPolylist *thisPolylist = thisMesh->getPolylist_array().get(0);
|
|
||||||
// Remove the polylist from the mesh
|
|
||||||
thisMesh->removeChildElement(thisPolylist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (error == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ColladaConditioner::triangulate(const char *inputFile) {
|
|
||||||
|
|
||||||
DAE dae;
|
|
||||||
bool convertSuceeded = true;
|
|
||||||
domCOLLADA* root = dae.open(inputFile);
|
|
||||||
|
|
||||||
if (!root) {
|
|
||||||
printf("Failed to read file %s.\n", inputFile);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
convertSuceeded = triangulate(&dae);
|
|
||||||
|
|
||||||
dae.writeAll();
|
|
||||||
if(!convertSuceeded) {
|
|
||||||
printf("Encountered errors\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertSuceeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ColladaConditioner::stripGeometry(DAE *dae) {
|
|
||||||
bool convertSuceeded = true;
|
|
||||||
|
|
||||||
int error = 0;
|
|
||||||
|
|
||||||
// How many geometry elements are there?
|
|
||||||
int geometryElementCount = (int)(dae->getDatabase()->getElementCount(NULL, "geometry" ));
|
|
||||||
for(int currentGeometry = 0; currentGeometry < geometryElementCount; currentGeometry++) {
|
|
||||||
|
|
||||||
// Find the next geometry element
|
|
||||||
domGeometry *thisGeometry = 0;
|
|
||||||
daeElement * element = 0;
|
|
||||||
error = dae->getDatabase()->getElement(&element, currentGeometry, NULL, "geometry");
|
|
||||||
thisGeometry = (domGeometry *) element;
|
|
||||||
|
|
||||||
// Get the mesh out of the geometry
|
|
||||||
domMesh *thisMesh = thisGeometry->getMesh();
|
|
||||||
|
|
||||||
if (thisMesh == NULL){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
daeBool removed = daeElement::removeFromParent(thisMesh);
|
|
||||||
convertSuceeded = convertSuceeded && removed;
|
|
||||||
}
|
|
||||||
return convertSuceeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ColladaConditioner::stripGeometry(const char *inputFile) {
|
|
||||||
DAE dae;
|
|
||||||
bool convertSuceeded = true;
|
|
||||||
domCOLLADA* root = dae.open(inputFile);
|
|
||||||
|
|
||||||
if (!root) {
|
|
||||||
printf("Failed to read file %s.\n", inputFile);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
stripGeometry(&dae);
|
|
||||||
|
|
||||||
dae.writeAll();
|
|
||||||
if(!convertSuceeded) {
|
|
||||||
printf("Encountered errors\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertSuceeded;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the MIT Open Source License, for details please see license.txt or the website
|
|
||||||
* http://www.opensource.org/licenses/mit-license.php
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef COLLADA_CONDITIONER
|
|
||||||
#define COLLADA_CONDITIONER
|
|
||||||
|
|
||||||
#include <dae.h>
|
|
||||||
#include <dom/domConstants.h>
|
|
||||||
#include <dom/domCOLLADA.h>
|
|
||||||
|
|
||||||
class ColladaConditioner {
|
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned int getMaxOffset( domInputLocalOffset_Array &input_array );
|
|
||||||
void createTrianglesFromPolylist( domMesh *thisMesh, domPolylist *thisPolylist );
|
|
||||||
void createTrianglesFromPolygons( domMesh *thisMesh, domPolygons *thisPolygons );
|
|
||||||
|
|
||||||
public:
|
|
||||||
bool triangulate(DAE *dae);
|
|
||||||
bool triangulate(const char *inputFile);
|
|
||||||
bool stripGeometry(DAE *dae);
|
|
||||||
bool stripGeometry(const char *inputFile);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //COLLADA_CONDITIONER
|
|
||||||
@@ -1,319 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the MIT Open Source License, for details please see license.txt or the website
|
|
||||||
* http://www.opensource.org/licenses/mit-license.php
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ColladaGeometry.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
ColladaGeometry::ColladaGeometry() :
|
|
||||||
mPositionFloats(NULL), mPositionOffset(-1),
|
|
||||||
mNormalFloats(NULL), mNormalOffset(-1),
|
|
||||||
mTangentFloats(NULL), mTangentOffset(-1),
|
|
||||||
mBinormalFloats(NULL), mBinormalOffset(-1),
|
|
||||||
mTexture1Floats(NULL), mTexture1Offset(-1),
|
|
||||||
mMultiIndexOffset(-1),
|
|
||||||
mPositionsStride(3), mNormalsStride(3),
|
|
||||||
mTextureCoordsStride(2), mTangentssStride(3), mBinormalsStride(3) {
|
|
||||||
|
|
||||||
mConvertedMesh.appendChannel("position", mPositionsStride);
|
|
||||||
mConvertedMesh.appendChannel("normal", mNormalsStride);
|
|
||||||
mConvertedMesh.appendChannel("texture0", mTextureCoordsStride);
|
|
||||||
mConvertedMesh.appendChannel("binormal", mBinormalsStride);
|
|
||||||
mConvertedMesh.appendChannel("tangent", mTangentssStride);
|
|
||||||
|
|
||||||
mPositions = &mConvertedMesh.mChannels[0].mData;
|
|
||||||
mNormals = &mConvertedMesh.mChannels[1].mData;
|
|
||||||
mTextureCoords = &mConvertedMesh.mChannels[2].mData;
|
|
||||||
mBinormals = &mConvertedMesh.mChannels[3].mData;
|
|
||||||
mTangents = &mConvertedMesh.mChannels[4].mData;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ColladaGeometry::init(domGeometryRef geometry) {
|
|
||||||
|
|
||||||
bool convertSuceeded = true;
|
|
||||||
|
|
||||||
const char* geoName = geometry->getName();
|
|
||||||
if (geoName == NULL) {
|
|
||||||
geoName = geometry->getId();
|
|
||||||
}
|
|
||||||
mConvertedMesh.mName = geoName;
|
|
||||||
mMesh = geometry->getMesh();
|
|
||||||
|
|
||||||
// Iterate over all the index groups and build up a simple resolved tri list and vertex array
|
|
||||||
const domTriangles_Array &allTriLists = mMesh->getTriangles_array();
|
|
||||||
int numTriLists = allTriLists.getCount();
|
|
||||||
mConvertedMesh.mTriangleLists.reserve(numTriLists);
|
|
||||||
mConvertedMesh.mTriangleListNames.reserve(numTriLists);
|
|
||||||
for (int i = 0; i < numTriLists; i ++) {
|
|
||||||
addTriangles(allTriLists[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertSuceeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColladaGeometry::addTriangles(domTriangles * colladaTriangles) {
|
|
||||||
|
|
||||||
int numTriangles = colladaTriangles->getCount();
|
|
||||||
int triListIndex = mConvertedMesh.mTriangleLists.size();
|
|
||||||
mConvertedMesh.mTriangleLists.resize(triListIndex + 1);
|
|
||||||
std::string materialName = colladaTriangles->getMaterial();
|
|
||||||
if (materialName.size() == 0) {
|
|
||||||
char buffer[128];
|
|
||||||
sprintf(buffer, "index%d", triListIndex);
|
|
||||||
materialName = buffer;
|
|
||||||
}
|
|
||||||
mConvertedMesh.mTriangleListNames.push_back(materialName);
|
|
||||||
|
|
||||||
// It's a good idea to tell stl how much memory we intend to use
|
|
||||||
// to limit the number of reallocations
|
|
||||||
mPositions->reserve(numTriangles * 3);
|
|
||||||
mNormals->reserve(numTriangles * 3);
|
|
||||||
mTangents->reserve(numTriangles * 3);
|
|
||||||
mBinormals->reserve(numTriangles * 3);
|
|
||||||
mTextureCoords->reserve(numTriangles * 3);
|
|
||||||
|
|
||||||
// Stores the pointers to the image data and where in the tri list that data comes from
|
|
||||||
cacheOffsetsAndDataPointers(colladaTriangles);
|
|
||||||
|
|
||||||
// Collapse the multiindex that collada uses
|
|
||||||
const domListOfUInts &colladaIndexList = colladaTriangles->getP()->getValue();
|
|
||||||
std::vector<uint32_t> &a3dIndexList = mConvertedMesh.mTriangleLists[triListIndex];
|
|
||||||
a3dIndexList.resize(numTriangles * 3);
|
|
||||||
for (int i = 0; i < numTriangles * 3; i ++) {
|
|
||||||
|
|
||||||
a3dIndexList[i] = remapIndexAndStoreData(colladaIndexList, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColladaGeometry::cacheOffsetsAndDataPointers(domTriangles * colladaTriangles) {
|
|
||||||
// Define the names of known vertex channels
|
|
||||||
const char *positionSemantic = "POSITION";
|
|
||||||
const char *vertexSemantic = "VERTEX";
|
|
||||||
const char *normalSemantic = "NORMAL";
|
|
||||||
const char *tangentSemantic = "TANGENT";
|
|
||||||
const char *binormalSemantic = "BINORMAL";
|
|
||||||
const char *texture1Semantic = "TEXCOORD";
|
|
||||||
|
|
||||||
const domInputLocalOffset_Array &inputs = colladaTriangles->getInput_array();
|
|
||||||
mMultiIndexOffset = inputs.getCount();
|
|
||||||
|
|
||||||
// inputs with offsets
|
|
||||||
// There are two places collada can put links to our data
|
|
||||||
// 1 - in the VERTEX, which is its way of saying follow a link to the vertex structure
|
|
||||||
// then every geometry array you find there is the same size as the position array
|
|
||||||
// 2 - a direct link to the channel from the primitive list. This tells us that there are
|
|
||||||
// potentially more or less floats in those channels because there is some vertex re-use
|
|
||||||
// or divergence in that data channel. For example, highly segmented uv set would produce a
|
|
||||||
// larger array because for every physical vertex position thre might be 2 or more uv coords
|
|
||||||
for (uint32_t i = 0; i < inputs.getCount(); i ++) {
|
|
||||||
|
|
||||||
int currentOffset = inputs[i]->getOffset();
|
|
||||||
const char *currentSemantic = inputs[i]->getSemantic();
|
|
||||||
|
|
||||||
domSource * source = (domSource*) (domElement*) inputs[i]->getSource().getElement();
|
|
||||||
if (strcmp(vertexSemantic, currentSemantic) == 0) {
|
|
||||||
mPositionOffset = currentOffset;
|
|
||||||
}
|
|
||||||
else if (strcmp(normalSemantic, currentSemantic) == 0) {
|
|
||||||
mNormalOffset = currentOffset;
|
|
||||||
mNormalFloats = &source->getFloat_array()->getValue();
|
|
||||||
}
|
|
||||||
else if (strcmp(tangentSemantic, currentSemantic) == 0) {
|
|
||||||
mTangentOffset = currentOffset;
|
|
||||||
mTangentFloats = &source->getFloat_array()->getValue();
|
|
||||||
}
|
|
||||||
else if (strcmp(binormalSemantic, currentSemantic) == 0) {
|
|
||||||
mBinormalOffset = currentOffset;
|
|
||||||
mBinormalFloats = &source->getFloat_array()->getValue();
|
|
||||||
}
|
|
||||||
else if (strcmp(texture1Semantic, currentSemantic) == 0) {
|
|
||||||
mTexture1Offset = currentOffset;
|
|
||||||
mTexture1Floats = & source->getFloat_array()->getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// There are multiple ways of getting to data, so follow them all
|
|
||||||
domVertices * vertices = mMesh->getVertices();
|
|
||||||
const domInputLocal_Array &verticesInputs = vertices->getInput_array();
|
|
||||||
for (uint32_t i = 0; i < verticesInputs.getCount(); i ++) {
|
|
||||||
|
|
||||||
const char *currentSemantic = verticesInputs[i]->getSemantic();
|
|
||||||
|
|
||||||
domSource * source = (domSource*) (domElement*) verticesInputs[i]->getSource().getElement();
|
|
||||||
if (strcmp(positionSemantic, currentSemantic) == 0) {
|
|
||||||
mPositionFloats = & source->getFloat_array()->getValue();
|
|
||||||
// TODO: Querry this from the accessor in the future because
|
|
||||||
// I supopose it's possible to have 4 floats if we hide something in w
|
|
||||||
int numberOfFloatsPerPoint = 3;
|
|
||||||
// We want to cllapse duplicate vertices, otherwise we could just unroll the tri list
|
|
||||||
mVertexRemap.resize(source->getFloat_array()->getCount()/numberOfFloatsPerPoint);
|
|
||||||
}
|
|
||||||
else if (strcmp(normalSemantic, currentSemantic) == 0) {
|
|
||||||
mNormalFloats = & source->getFloat_array()->getValue();
|
|
||||||
mNormalOffset = mPositionOffset;
|
|
||||||
}
|
|
||||||
else if (strcmp(tangentSemantic, currentSemantic) == 0) {
|
|
||||||
mTangentFloats = & source->getFloat_array()->getValue();
|
|
||||||
mTangentOffset = mPositionOffset;
|
|
||||||
}
|
|
||||||
else if (strcmp(binormalSemantic, currentSemantic) == 0) {
|
|
||||||
mBinormalFloats = & source->getFloat_array()->getValue();
|
|
||||||
mBinormalOffset = mPositionOffset;
|
|
||||||
}
|
|
||||||
else if (strcmp(texture1Semantic, currentSemantic) == 0) {
|
|
||||||
mTexture1Floats = & source->getFloat_array()->getValue();
|
|
||||||
mTexture1Offset = mPositionOffset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int ColladaGeometry::remapIndexAndStoreData(const domListOfUInts &colladaIndexList, int indexToRemap) {
|
|
||||||
|
|
||||||
domUint positionIndex = colladaIndexList[indexToRemap*mMultiIndexOffset + mPositionOffset];
|
|
||||||
|
|
||||||
float posX = (*mPositionFloats)[positionIndex * mPositionsStride + 0];
|
|
||||||
float posY = (*mPositionFloats)[positionIndex * mPositionsStride + 1];
|
|
||||||
float posZ = (*mPositionFloats)[positionIndex * mPositionsStride + 2];
|
|
||||||
|
|
||||||
float normX = 0;
|
|
||||||
float normY = 0;
|
|
||||||
float normZ = 0;
|
|
||||||
|
|
||||||
if (mNormalOffset != -1) {
|
|
||||||
domUint normalIndex = colladaIndexList[indexToRemap*mMultiIndexOffset + mNormalOffset];
|
|
||||||
normX = (*mNormalFloats)[normalIndex * mNormalsStride + 0];
|
|
||||||
normY = (*mNormalFloats)[normalIndex * mNormalsStride + 1];
|
|
||||||
normZ = (*mNormalFloats)[normalIndex * mNormalsStride + 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
float tanX = 0;
|
|
||||||
float tanY = 0;
|
|
||||||
float tanZ = 0;
|
|
||||||
|
|
||||||
if (mTangentOffset != -1) {
|
|
||||||
domUint tangentIndex = colladaIndexList[indexToRemap*mMultiIndexOffset + mTangentOffset];
|
|
||||||
tanX = (*mTangentFloats)[tangentIndex * mTangentssStride + 0];
|
|
||||||
tanY = (*mTangentFloats)[tangentIndex * mTangentssStride + 1];
|
|
||||||
tanZ = (*mTangentFloats)[tangentIndex * mTangentssStride + 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
float binormX = 0;
|
|
||||||
float binormY = 0;
|
|
||||||
float binormZ = 0;
|
|
||||||
|
|
||||||
if (mBinormalOffset != -1) {
|
|
||||||
domUint binormalIndex = colladaIndexList[indexToRemap*mMultiIndexOffset + mNormalOffset];
|
|
||||||
binormX = (*mBinormalFloats)[binormalIndex * mBinormalsStride + 0];
|
|
||||||
binormY = (*mBinormalFloats)[binormalIndex * mBinormalsStride + 1];
|
|
||||||
binormZ = (*mBinormalFloats)[binormalIndex * mBinormalsStride + 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
float texCoordX = 0;
|
|
||||||
float texCoordY = 0;
|
|
||||||
|
|
||||||
if (mTexture1Offset != -1) {
|
|
||||||
domUint texCoordIndex = colladaIndexList[indexToRemap*mMultiIndexOffset + mTexture1Offset];
|
|
||||||
texCoordX = (*mTexture1Floats)[texCoordIndex * mTextureCoordsStride + 0];
|
|
||||||
texCoordY = (*mTexture1Floats)[texCoordIndex * mTextureCoordsStride + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<uint32_t> &ithRemapList = mVertexRemap[positionIndex];
|
|
||||||
// We may have some potential vertices we can reuse
|
|
||||||
// loop over all the potential candidates and see if any match our guy
|
|
||||||
for (uint32_t i = 0; i < ithRemapList.size(); i ++) {
|
|
||||||
|
|
||||||
int ithRemap = ithRemapList[i];
|
|
||||||
// compare existing vertex with the new one
|
|
||||||
if ((*mPositions)[ithRemap * mPositionsStride + 0] != posX ||
|
|
||||||
(*mPositions)[ithRemap * mPositionsStride + 1] != posY ||
|
|
||||||
(*mPositions)[ithRemap * mPositionsStride + 2] != posZ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now go over normals
|
|
||||||
if (mNormalOffset != -1) {
|
|
||||||
if ((*mNormals)[ithRemap * mNormalsStride + 0] != normX ||
|
|
||||||
(*mNormals)[ithRemap * mNormalsStride + 1] != normY ||
|
|
||||||
(*mNormals)[ithRemap * mNormalsStride + 2] != normZ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now go over tangents
|
|
||||||
if (mTangentOffset != -1) {
|
|
||||||
if ((*mTangents)[ithRemap * mTangentssStride + 0] != tanX ||
|
|
||||||
(*mTangents)[ithRemap * mTangentssStride + 1] != tanY ||
|
|
||||||
(*mTangents)[ithRemap * mTangentssStride + 2] != tanZ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now go over binormals
|
|
||||||
if (mBinormalOffset != -1) {
|
|
||||||
if ((*mBinormals)[ithRemap * mBinormalsStride + 0] != binormX ||
|
|
||||||
(*mBinormals)[ithRemap * mBinormalsStride + 1] != binormY ||
|
|
||||||
(*mBinormals)[ithRemap * mBinormalsStride + 2] != binormZ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// And texcoords
|
|
||||||
if (mTexture1Offset != -1) {
|
|
||||||
if ((*mTextureCoords)[ithRemap * mTextureCoordsStride + 0] != texCoordX ||
|
|
||||||
(*mTextureCoords)[ithRemap * mTextureCoordsStride + 1] != texCoordY) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we got here the new vertex is identical to the one that we already stored
|
|
||||||
return ithRemap;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We did not encounter this vertex yet, store it and return its index
|
|
||||||
mPositions->push_back(posX);
|
|
||||||
mPositions->push_back(posY);
|
|
||||||
mPositions->push_back(posZ);
|
|
||||||
|
|
||||||
if (mNormalOffset != -1) {
|
|
||||||
mNormals->push_back(normX);
|
|
||||||
mNormals->push_back(normY);
|
|
||||||
mNormals->push_back(normZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mTangentOffset != -1) {
|
|
||||||
mTangents->push_back(tanX);
|
|
||||||
mTangents->push_back(tanY);
|
|
||||||
mTangents->push_back(tanZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mBinormalOffset != -1) {
|
|
||||||
mBinormals->push_back(binormX);
|
|
||||||
mBinormals->push_back(binormY);
|
|
||||||
mBinormals->push_back(binormZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mTexture1Offset != -1) {
|
|
||||||
mTextureCoords->push_back(texCoordX);
|
|
||||||
mTextureCoords->push_back(texCoordY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to remember this mapping. Since we are storing floats, not vec3's, need to
|
|
||||||
// divide by position size to get the right index
|
|
||||||
int currentVertexIndex = (mPositions->size()/mPositionsStride) - 1;
|
|
||||||
ithRemapList.push_back(currentVertexIndex);
|
|
||||||
|
|
||||||
return currentVertexIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2006 Sony Computer Entertainment Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the MIT Open Source License, for details please see license.txt or the website
|
|
||||||
* http://www.opensource.org/licenses/mit-license.php
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _COLLADA_GEOMETRY_H_
|
|
||||||
#define _COLLADA_GEOMETRY_H_
|
|
||||||
|
|
||||||
#include <dae.h>
|
|
||||||
#include <dom/domCOLLADA.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "rsContext.h"
|
|
||||||
#include "rsMesh.h"
|
|
||||||
#include "SimpleMesh.h"
|
|
||||||
|
|
||||||
using namespace android;
|
|
||||||
using namespace android::renderscript;
|
|
||||||
|
|
||||||
|
|
||||||
class ColladaGeometry {
|
|
||||||
public:
|
|
||||||
ColladaGeometry();
|
|
||||||
bool init(domGeometryRef geometry);
|
|
||||||
|
|
||||||
SimpleMesh *getMesh() {
|
|
||||||
return &mConvertedMesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
//Store some collada stuff
|
|
||||||
domMesh *mMesh;
|
|
||||||
|
|
||||||
// Cache the pointers to the collada version of the data
|
|
||||||
// This contains raw vertex data that is not necessarily the same size for all
|
|
||||||
// Offset refers to the way collada packs each triangle's index to position / normal / etc.
|
|
||||||
domListOfFloats *mPositionFloats;
|
|
||||||
int mPositionOffset;
|
|
||||||
domListOfFloats *mNormalFloats;
|
|
||||||
int mNormalOffset;
|
|
||||||
domListOfFloats *mTangentFloats;
|
|
||||||
int mTangentOffset;
|
|
||||||
domListOfFloats *mBinormalFloats;
|
|
||||||
int mBinormalOffset;
|
|
||||||
domListOfFloats *mTexture1Floats;
|
|
||||||
int mTexture1Offset;
|
|
||||||
|
|
||||||
// In the list of triangles, collada uses multiple indecies per triangle to point to the correct
|
|
||||||
// index in all the different arrays. We need to know the total number of these guys so we can
|
|
||||||
// just to the next triangle to process
|
|
||||||
int mMultiIndexOffset;
|
|
||||||
|
|
||||||
// All these vectors would contain the same number of "points"
|
|
||||||
// index*stride would properly get to the uv, normal etc.
|
|
||||||
// collada, like maya and many others keep point array, normal array etc
|
|
||||||
// different size in the cases the same vertex produces divergent normals for different faces
|
|
||||||
std::vector<float> *mPositions;
|
|
||||||
unsigned int mPositionsStride;
|
|
||||||
std::vector<float> *mNormals;
|
|
||||||
unsigned int mNormalsStride;
|
|
||||||
std::vector<float> *mTextureCoords;
|
|
||||||
unsigned int mTextureCoordsStride;
|
|
||||||
std::vector<float> *mTangents;
|
|
||||||
unsigned int mTangentssStride;
|
|
||||||
std::vector<float> *mBinormals;
|
|
||||||
unsigned int mBinormalsStride;
|
|
||||||
|
|
||||||
SimpleMesh mConvertedMesh;
|
|
||||||
|
|
||||||
// This vector is used to remap a position index into a list of all divergent vertices
|
|
||||||
std::vector<std::vector<unsigned int> > mVertexRemap;
|
|
||||||
|
|
||||||
void addTriangles(domTriangles * colladaTriangles);
|
|
||||||
void cacheOffsetsAndDataPointers(domTriangles * colladaTriangles);
|
|
||||||
int remapIndexAndStoreData(const domListOfUInts &colladaIndexList, int indexToRemap);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //COLLADA_TO_A3D_GEOMETRY
|
|
||||||
@@ -1,125 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ColladaLoader.h"
|
|
||||||
#include "ColladaConditioner.h"
|
|
||||||
#include "ColladaGeometry.h"
|
|
||||||
|
|
||||||
#include <dae.h>
|
|
||||||
#include <dom/domCOLLADA.h>
|
|
||||||
|
|
||||||
ColladaLoader::ColladaLoader() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ColladaLoader::~ColladaLoader() {
|
|
||||||
if (mDae) {
|
|
||||||
delete mDae;
|
|
||||||
}
|
|
||||||
clearGeometry();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColladaLoader::clearGeometry() {
|
|
||||||
for (uint32_t i = 0; i < mGeometries.size(); i++) {
|
|
||||||
delete mGeometries[i];
|
|
||||||
}
|
|
||||||
mGeometries.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ColladaLoader::init(const char *colladaFile) {
|
|
||||||
if (mDae) {
|
|
||||||
delete mDae;
|
|
||||||
}
|
|
||||||
clearGeometry();
|
|
||||||
|
|
||||||
mDae = new DAE();
|
|
||||||
|
|
||||||
bool convertSuceeded = true;
|
|
||||||
|
|
||||||
domCOLLADA* root = mDae->open(colladaFile);
|
|
||||||
if (!root) {
|
|
||||||
fprintf(stderr, "Failed to read file %s.\n", colladaFile);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We only want to deal with triangulated meshes since rendering complex polygons is not feasible
|
|
||||||
ColladaConditioner conditioner;
|
|
||||||
conditioner.triangulate(mDae);
|
|
||||||
|
|
||||||
domLibrary_geometries *allGeometry = daeSafeCast<domLibrary_geometries>(root->getDescendant("library_geometries"));
|
|
||||||
|
|
||||||
if (allGeometry) {
|
|
||||||
convertSuceeded = convertAllGeometry(allGeometry) && convertSuceeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertSuceeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleMesh *ColladaLoader::getMesh(uint32_t meshIndex) {
|
|
||||||
return mGeometries[meshIndex]->getMesh();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ColladaLoader::convertAllGeometry(domLibrary_geometries *allGeometry) {
|
|
||||||
|
|
||||||
bool convertSuceeded = true;
|
|
||||||
domGeometry_Array &geo_array = allGeometry->getGeometry_array();
|
|
||||||
for (size_t i = 0; i < geo_array.getCount(); i++) {
|
|
||||||
domGeometry *geometry = geo_array[i];
|
|
||||||
const char *geometryName = geometry->getName();
|
|
||||||
if (geometryName == NULL) {
|
|
||||||
geometryName = geometry->getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
domMeshRef mesh = geometry->getMesh();
|
|
||||||
if (mesh != NULL) {
|
|
||||||
printf("Converting geometry: %s\n", geometryName);
|
|
||||||
convertSuceeded = convertGeometry(geometry) && convertSuceeded;
|
|
||||||
} else {
|
|
||||||
printf("Skipping geometry: %s, unsupported type\n", geometryName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertSuceeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ColladaLoader::convertGeometry(domGeometry *geometry) {
|
|
||||||
bool convertSuceeded = true;
|
|
||||||
|
|
||||||
domMeshRef mesh = geometry->getMesh();
|
|
||||||
|
|
||||||
ColladaGeometry *convertedGeo = new ColladaGeometry();
|
|
||||||
convertedGeo->init(geometry);
|
|
||||||
|
|
||||||
mGeometries.push_back(convertedGeo);
|
|
||||||
|
|
||||||
return convertSuceeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ColladaLoader::stripGeometryAndSave() {
|
|
||||||
|
|
||||||
ColladaConditioner conditioner;
|
|
||||||
bool convertSuceeded = conditioner.stripGeometry(mDae);
|
|
||||||
|
|
||||||
mDae->writeAll();
|
|
||||||
if(!convertSuceeded) {
|
|
||||||
printf("Encountered errors\n");
|
|
||||||
} else {
|
|
||||||
printf("Stripped geometry data from collada file\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertSuceeded;
|
|
||||||
}
|
|
||||||
@@ -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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _COLLADA_LOADER_H_
|
|
||||||
#define _COLLADA_LOADER_H_
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class DAE;
|
|
||||||
class domLibrary_geometries;
|
|
||||||
class domGeometry;
|
|
||||||
class ColladaGeometry;
|
|
||||||
class SimpleMesh;
|
|
||||||
|
|
||||||
#include "GeometryLoader.h"
|
|
||||||
|
|
||||||
class ColladaLoader : public GeometryLoader {
|
|
||||||
public:
|
|
||||||
ColladaLoader();
|
|
||||||
virtual ~ColladaLoader();
|
|
||||||
|
|
||||||
virtual bool init(const char *colladaFile);
|
|
||||||
virtual SimpleMesh *getMesh(uint32_t meshIndex);
|
|
||||||
virtual uint32_t getNumMeshes() const {
|
|
||||||
return mGeometries.size();
|
|
||||||
}
|
|
||||||
bool stripGeometryAndSave();
|
|
||||||
|
|
||||||
private:
|
|
||||||
DAE *mDae;
|
|
||||||
void clearGeometry();
|
|
||||||
std::vector<ColladaGeometry*> mGeometries;
|
|
||||||
|
|
||||||
bool convertAllGeometry(domLibrary_geometries *allGeometry);
|
|
||||||
bool convertGeometry(domGeometry *geometry);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,31 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _GEOMETRY_LOADER_H_
|
|
||||||
#define _GEOMETRY_LOADER_H_
|
|
||||||
|
|
||||||
#include "SimpleMesh.h"
|
|
||||||
|
|
||||||
class GeometryLoader {
|
|
||||||
public:
|
|
||||||
virtual ~GeometryLoader() {
|
|
||||||
}
|
|
||||||
virtual bool init(const char *file) = 0;
|
|
||||||
virtual uint32_t getNumMeshes() const = 0;
|
|
||||||
virtual SimpleMesh *getMesh(uint32_t meshIndex) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif _GEOMETRY_LOADER_H_
|
|
||||||
@@ -1,333 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ObjLoader.h"
|
|
||||||
#include <rsFileA3D.h>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
ObjLoader::ObjLoader() :
|
|
||||||
mPositionsStride(3), mNormalsStride(3), mTextureCoordsStride(2) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isWhitespace(char c) {
|
|
||||||
const char whiteSpace[] = { ' ', '\n', '\t', '\f', '\r' };
|
|
||||||
const uint32_t numWhiteSpaceChars = 5;
|
|
||||||
for (uint32_t i = 0; i < numWhiteSpaceChars; i ++) {
|
|
||||||
if (whiteSpace[i] == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void eatWhitespace(std::istream &is) {
|
|
||||||
while(is.good() && isWhitespace(is.peek())) {
|
|
||||||
is.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getToken(std::istream &is, std::string &token) {
|
|
||||||
eatWhitespace(is);
|
|
||||||
token.clear();
|
|
||||||
char c;
|
|
||||||
while(is.good() && !isWhitespace(is.peek())) {
|
|
||||||
c = is.get();
|
|
||||||
if (is.good()){
|
|
||||||
token += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return token.size() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void appendDataFromStream(std::vector<float> &dataVec, uint32_t numFloats, std::istream &is) {
|
|
||||||
std::string token;
|
|
||||||
for (uint32_t i = 0; i < numFloats; i ++){
|
|
||||||
bool valid = getToken(is, token);
|
|
||||||
if (valid) {
|
|
||||||
dataVec.push_back((float)atof(token.c_str()));
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Encountered error reading geometry data");
|
|
||||||
dataVec.push_back(0.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool checkNegativeIndex(int idx) {
|
|
||||||
if(idx < 0) {
|
|
||||||
fprintf(stderr, "Negative indices are not supported. Skipping face\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjLoader::parseRawFaces(){
|
|
||||||
// We need at least a triangle
|
|
||||||
if (mRawFaces.size() < 3) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char slash = '/';
|
|
||||||
mParsedFaces.resize(mRawFaces.size());
|
|
||||||
for (uint32_t i = 0; i < mRawFaces.size(); i ++) {
|
|
||||||
size_t firstSeparator = mRawFaces[i].find_first_of(slash);
|
|
||||||
size_t nextSeparator = mRawFaces[i].find_last_of(slash);
|
|
||||||
|
|
||||||
// Use the string as a temp buffer to parse the index
|
|
||||||
// Insert 0 instead of the slash to avoid substrings
|
|
||||||
if (firstSeparator != std::string::npos) {
|
|
||||||
mRawFaces[i][firstSeparator] = 0;
|
|
||||||
}
|
|
||||||
// Simple case, only one index
|
|
||||||
int32_t vIdx = atoi(mRawFaces[i].c_str());
|
|
||||||
// We do not support negative indices
|
|
||||||
if (!checkNegativeIndex(vIdx)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// obj indices things beginning 1
|
|
||||||
mParsedFaces[i].vertIdx = (uint32_t)vIdx - 1;
|
|
||||||
|
|
||||||
if (nextSeparator != std::string::npos && nextSeparator != firstSeparator) {
|
|
||||||
mRawFaces[i][nextSeparator] = 0;
|
|
||||||
uint32_t nIdx = atoi(mRawFaces[i].c_str() + nextSeparator + 1);
|
|
||||||
if (!checkNegativeIndex(nIdx)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// obj indexes things beginning 1
|
|
||||||
mParsedFaces[i].normIdx = (uint32_t)nIdx - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// second case is where we have vertex and texture indices
|
|
||||||
if (nextSeparator != std::string::npos &&
|
|
||||||
(nextSeparator > firstSeparator + 1 || nextSeparator == firstSeparator)) {
|
|
||||||
uint32_t tIdx = atoi(mRawFaces[i].c_str() + firstSeparator + 1);
|
|
||||||
if (!checkNegativeIndex(tIdx)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// obj indexes things beginning 1
|
|
||||||
mParsedFaces[i].texIdx = (uint32_t)tIdx - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure a face list exists before we go adding to it
|
|
||||||
if (mMeshes.back().mUnfilteredFaces.size() == 0) {
|
|
||||||
mMeshes.back().appendUnfilteredFaces(mLastMtl);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we have our parsed face, that we need to triangulate as necessary
|
|
||||||
// Treat more complex polygons as fans.
|
|
||||||
// This approach will only work only for convex polygons
|
|
||||||
// but concave polygons need to be addressed elsewhere anyway
|
|
||||||
for (uint32_t next = 1; next < mParsedFaces.size() - 1; next ++) {
|
|
||||||
// push it to our current mesh
|
|
||||||
mMeshes.back().mUnfilteredFaces.back().push_back(mParsedFaces[0]);
|
|
||||||
mMeshes.back().mUnfilteredFaces.back().push_back(mParsedFaces[next]);
|
|
||||||
mMeshes.back().mUnfilteredFaces.back().push_back(mParsedFaces[next + 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjLoader::checkNewMeshCreation(std::string &newGroup) {
|
|
||||||
// start a new mesh if we have some faces
|
|
||||||
// accumulated on the current mesh.
|
|
||||||
// It's possible to have multiple group statements
|
|
||||||
// but we only care to actually start a new mesh
|
|
||||||
// once we can have something we can draw on the previous one
|
|
||||||
if (mMeshes.back().mUnfilteredFaces.size()) {
|
|
||||||
mMeshes.push_back(ObjMesh());
|
|
||||||
}
|
|
||||||
|
|
||||||
mMeshes.back().mName = newGroup;
|
|
||||||
printf("Converting vertex group: %s\n", newGroup.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjLoader::handleObjLine(char *line) {
|
|
||||||
const char* vtxToken = "v";
|
|
||||||
const char* normToken = "vn";
|
|
||||||
const char* texToken = "vt";
|
|
||||||
const char* groupToken = "g";
|
|
||||||
const char* mtlToken = "usemtl";
|
|
||||||
const char* faceToken = "f";
|
|
||||||
|
|
||||||
std::istringstream lineStream(line, std::istringstream::in);
|
|
||||||
|
|
||||||
std::string token;
|
|
||||||
bool valid = getToken(lineStream, token);
|
|
||||||
if (!valid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (token == vtxToken) {
|
|
||||||
appendDataFromStream(mObjPositions, 3, lineStream);
|
|
||||||
} else if (token == normToken) {
|
|
||||||
appendDataFromStream(mObjNormals, 3, lineStream);
|
|
||||||
} else if (token == texToken) {
|
|
||||||
appendDataFromStream(mObjTextureCoords, 2, lineStream);
|
|
||||||
} else if (token == groupToken) {
|
|
||||||
valid = getToken(lineStream, token);
|
|
||||||
checkNewMeshCreation(token);
|
|
||||||
} else if (token == faceToken) {
|
|
||||||
mRawFaces.clear();
|
|
||||||
while(getToken(lineStream, token)) {
|
|
||||||
mRawFaces.push_back(token);
|
|
||||||
}
|
|
||||||
parseRawFaces();
|
|
||||||
}
|
|
||||||
// Ignore materials for now
|
|
||||||
else if (token == mtlToken) {
|
|
||||||
valid = getToken(lineStream, token);
|
|
||||||
mLastMtl = token;
|
|
||||||
|
|
||||||
mMeshes.back().appendUnfilteredFaces(token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ObjLoader::init(const char *fileName) {
|
|
||||||
|
|
||||||
std::ifstream ifs(fileName , std::ifstream::in);
|
|
||||||
if (!ifs.good()) {
|
|
||||||
fprintf(stderr, "Failed to read file %s.\n", fileName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mMeshes.clear();
|
|
||||||
|
|
||||||
const uint32_t maxBufferSize = 2048;
|
|
||||||
char *buffer = new char[maxBufferSize];
|
|
||||||
|
|
||||||
mMeshes.push_back(ObjMesh());
|
|
||||||
|
|
||||||
std::string token;
|
|
||||||
bool isDone = false;
|
|
||||||
while(!isDone) {
|
|
||||||
ifs.getline(buffer, maxBufferSize);
|
|
||||||
if (ifs.good() && ifs.gcount() > 0) {
|
|
||||||
handleObjLine(buffer);
|
|
||||||
} else {
|
|
||||||
isDone = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ifs.close();
|
|
||||||
delete buffer;
|
|
||||||
|
|
||||||
reIndexGeometry();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjLoader::reIndexGeometry() {
|
|
||||||
// We want to know where each vertex lands
|
|
||||||
mVertexRemap.resize(mObjPositions.size() / mPositionsStride);
|
|
||||||
|
|
||||||
for (uint32_t m = 0; m < mMeshes.size(); m ++) {
|
|
||||||
// clear the remap vector of old data
|
|
||||||
for (uint32_t r = 0; r < mVertexRemap.size(); r ++) {
|
|
||||||
mVertexRemap[r].clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < mMeshes[m].mUnfilteredFaces.size(); i ++) {
|
|
||||||
mMeshes[m].mTriangleLists[i].reserve(mMeshes[m].mUnfilteredFaces[i].size() * 2);
|
|
||||||
for (uint32_t fI = 0; fI < mMeshes[m].mUnfilteredFaces[i].size(); fI ++) {
|
|
||||||
uint32_t newIndex = reIndexGeometryPrim(mMeshes[m], mMeshes[m].mUnfilteredFaces[i][fI]);
|
|
||||||
mMeshes[m].mTriangleLists[i].push_back(newIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t ObjLoader::reIndexGeometryPrim(ObjMesh &mesh, PrimitiveVtx &prim) {
|
|
||||||
|
|
||||||
std::vector<float> &mPositions = mesh.mChannels[0].mData;
|
|
||||||
std::vector<float> &mNormals = mesh.mChannels[1].mData;
|
|
||||||
std::vector<float> &mTextureCoords = mesh.mChannels[2].mData;
|
|
||||||
|
|
||||||
float posX = mObjPositions[prim.vertIdx * mPositionsStride + 0];
|
|
||||||
float posY = mObjPositions[prim.vertIdx * mPositionsStride + 1];
|
|
||||||
float posZ = mObjPositions[prim.vertIdx * mPositionsStride + 2];
|
|
||||||
|
|
||||||
float normX = 0.0f;
|
|
||||||
float normY = 0.0f;
|
|
||||||
float normZ = 0.0f;
|
|
||||||
if (prim.normIdx != MAX_INDEX) {
|
|
||||||
normX = mObjNormals[prim.normIdx * mNormalsStride + 0];
|
|
||||||
normY = mObjNormals[prim.normIdx * mNormalsStride + 1];
|
|
||||||
normZ = mObjNormals[prim.normIdx * mNormalsStride + 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
float texCoordX = 0.0f;
|
|
||||||
float texCoordY = 0.0f;
|
|
||||||
if (prim.texIdx != MAX_INDEX) {
|
|
||||||
texCoordX = mObjTextureCoords[prim.texIdx * mTextureCoordsStride + 0];
|
|
||||||
texCoordY = mObjTextureCoords[prim.texIdx * mTextureCoordsStride + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<unsigned int> &ithRemapList = mVertexRemap[prim.vertIdx];
|
|
||||||
// We may have some potential vertices we can reuse
|
|
||||||
// loop over all the potential candidates and see if any match our guy
|
|
||||||
for (unsigned int i = 0; i < ithRemapList.size(); i ++) {
|
|
||||||
|
|
||||||
int ithRemap = ithRemapList[i];
|
|
||||||
// compare existing vertex with the new one
|
|
||||||
if (mPositions[ithRemap * mPositionsStride + 0] != posX ||
|
|
||||||
mPositions[ithRemap * mPositionsStride + 1] != posY ||
|
|
||||||
mPositions[ithRemap * mPositionsStride + 2] != posZ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now go over normals
|
|
||||||
if (prim.normIdx != MAX_INDEX) {
|
|
||||||
if (mNormals[ithRemap * mNormalsStride + 0] != normX ||
|
|
||||||
mNormals[ithRemap * mNormalsStride + 1] != normY ||
|
|
||||||
mNormals[ithRemap * mNormalsStride + 2] != normZ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// And texcoords
|
|
||||||
if (prim.texIdx != MAX_INDEX) {
|
|
||||||
if (mTextureCoords[ithRemap * mTextureCoordsStride + 0] != texCoordX ||
|
|
||||||
mTextureCoords[ithRemap * mTextureCoordsStride + 1] != texCoordY) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we got here the new vertex is identical to the one that we already stored
|
|
||||||
return ithRemap;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We did not encounter this vertex yet, store it and return its index
|
|
||||||
mPositions.push_back(posX);
|
|
||||||
mPositions.push_back(posY);
|
|
||||||
mPositions.push_back(posZ);
|
|
||||||
|
|
||||||
if (prim.normIdx != MAX_INDEX) {
|
|
||||||
mNormals.push_back(normX);
|
|
||||||
mNormals.push_back(normY);
|
|
||||||
mNormals.push_back(normZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prim.texIdx != MAX_INDEX) {
|
|
||||||
mTextureCoords.push_back(texCoordX);
|
|
||||||
mTextureCoords.push_back(texCoordY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to remember this mapping. Since we are storing floats, not vec3's, need to
|
|
||||||
// divide by position size to get the right index
|
|
||||||
int currentVertexIndex = (mPositions.size()/mPositionsStride) - 1;
|
|
||||||
ithRemapList.push_back(currentVertexIndex);
|
|
||||||
|
|
||||||
return currentVertexIndex;
|
|
||||||
}
|
|
||||||
@@ -1,107 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _OBJ_LOADER_H_
|
|
||||||
#define _OBJ_LOADER_H_
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include "GeometryLoader.h"
|
|
||||||
|
|
||||||
using namespace android;
|
|
||||||
using namespace android::renderscript;
|
|
||||||
|
|
||||||
#define MAX_INDEX 0xffffffff
|
|
||||||
|
|
||||||
class ObjLoader : public GeometryLoader {
|
|
||||||
public:
|
|
||||||
ObjLoader();
|
|
||||||
virtual ~ObjLoader() {
|
|
||||||
}
|
|
||||||
virtual bool init(const char *objFile);
|
|
||||||
|
|
||||||
virtual SimpleMesh *getMesh(uint32_t meshIndex) {
|
|
||||||
return &mMeshes[meshIndex];
|
|
||||||
}
|
|
||||||
virtual uint32_t getNumMeshes() const {
|
|
||||||
return mMeshes.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
// .obj has a global list of vertex data
|
|
||||||
std::vector<float> mObjPositions;
|
|
||||||
std::vector<float> mObjNormals;
|
|
||||||
std::vector<float> mObjTextureCoords;
|
|
||||||
|
|
||||||
struct PrimitiveVtx {
|
|
||||||
uint32_t vertIdx;
|
|
||||||
uint32_t normIdx;
|
|
||||||
uint32_t texIdx;
|
|
||||||
|
|
||||||
PrimitiveVtx() : vertIdx(MAX_INDEX),
|
|
||||||
normIdx(MAX_INDEX),
|
|
||||||
texIdx(MAX_INDEX){
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Scratch buffer for faces
|
|
||||||
std::vector<std::string> mRawFaces;
|
|
||||||
std::vector<PrimitiveVtx> mParsedFaces;
|
|
||||||
std::string mLastMtl;
|
|
||||||
|
|
||||||
// Groups are used to separate multiple meshes within the same .obj file
|
|
||||||
class ObjMesh : public SimpleMesh {
|
|
||||||
public:
|
|
||||||
|
|
||||||
std::vector<std::vector<PrimitiveVtx> > mUnfilteredFaces;
|
|
||||||
|
|
||||||
void appendUnfilteredFaces(std::string name) {
|
|
||||||
appendFaceList(name);
|
|
||||||
mUnfilteredFaces.push_back(std::vector<PrimitiveVtx>());
|
|
||||||
// Reserve some space for index data
|
|
||||||
static const uint32_t numReserveIndecies = 128;
|
|
||||||
mUnfilteredFaces.back().reserve(numReserveIndecies);
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjMesh() {
|
|
||||||
appendChannel("position", 3);
|
|
||||||
appendChannel("normal", 3);
|
|
||||||
appendChannel("texture0", 2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<ObjMesh> mMeshes;
|
|
||||||
void checkNewMeshCreation(std::string &newGroup);
|
|
||||||
|
|
||||||
void parseRawFaces();
|
|
||||||
void handleObjLine(char *line);
|
|
||||||
|
|
||||||
void reIndexGeometry();
|
|
||||||
uint32_t reIndexGeometryPrim(ObjMesh &mesh, PrimitiveVtx &prim);
|
|
||||||
|
|
||||||
unsigned int mPositionsStride;
|
|
||||||
unsigned int mNormalsStride;
|
|
||||||
unsigned int mTextureCoordsStride;
|
|
||||||
|
|
||||||
// This vector is used to remap a position index into a list
|
|
||||||
// of all divergent vertices
|
|
||||||
std::vector<std::vector<unsigned int> > mVertexRemap;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //_OBJ_LOADER_H_
|
|
||||||
@@ -1,161 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _SIMPLE_MESH_H_
|
|
||||||
#define _SIMPLE_MESH_H_
|
|
||||||
|
|
||||||
#include <rsContext.h>
|
|
||||||
#include <rsMesh.h>
|
|
||||||
#include <string>
|
|
||||||
using namespace android;
|
|
||||||
using namespace android::renderscript;
|
|
||||||
|
|
||||||
class SimpleMesh {
|
|
||||||
public:
|
|
||||||
struct Channel {
|
|
||||||
std::vector<float> mData;
|
|
||||||
std::string mName;
|
|
||||||
uint32_t mStride;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Vertex channels (position, normal)
|
|
||||||
// This assumes all the data array are the same size
|
|
||||||
std::vector<Channel> mChannels;
|
|
||||||
|
|
||||||
// Triangle list index data
|
|
||||||
std::vector<std::vector<uint32_t> > mTriangleLists;
|
|
||||||
// Names of all the triangle lists
|
|
||||||
std::vector<std::string> mTriangleListNames;
|
|
||||||
// Name of the entire object
|
|
||||||
std::string mName;
|
|
||||||
|
|
||||||
// Adds another index set to the mesh
|
|
||||||
void appendFaceList(std::string name) {
|
|
||||||
mTriangleListNames.push_back(name);
|
|
||||||
mTriangleLists.push_back(std::vector<uint32_t>());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds another data channel (position, normal, etc.)
|
|
||||||
void appendChannel(std::string name, uint32_t stride) {
|
|
||||||
mChannels.push_back(Channel());
|
|
||||||
static const uint32_t reserveVtx = 128;
|
|
||||||
mChannels.back().mData.reserve(reserveVtx*stride);
|
|
||||||
mChannels.back().mName = name;
|
|
||||||
mChannels.back().mStride = stride;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleMesh() {
|
|
||||||
// reserve some data in the vectors
|
|
||||||
// simply letting it grow by itself tends to waste a lot of time on
|
|
||||||
// rallocations / copies when dealing with geometry data
|
|
||||||
static const uint32_t reserveFaces = 8;
|
|
||||||
static const uint32_t reserveChannels = 8;
|
|
||||||
mTriangleLists.reserve(reserveFaces);
|
|
||||||
mTriangleListNames.reserve(reserveFaces);
|
|
||||||
mChannels.reserve(reserveChannels);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generates a renderscript mesh that could be used for a3d serialization
|
|
||||||
Mesh *getRsMesh(Context *rsc) {
|
|
||||||
if (mChannels.size() == 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate the element that describes our channel layout
|
|
||||||
Element::Builder vtxBuilder;
|
|
||||||
for (uint32_t c = 0; c < mChannels.size(); c ++) {
|
|
||||||
// Skip empty channels
|
|
||||||
if (mChannels[c].mData.size() == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ObjectBaseRef<const Element> subElem = Element::createRef(rsc,
|
|
||||||
RS_TYPE_FLOAT_32,
|
|
||||||
RS_KIND_USER,
|
|
||||||
false,
|
|
||||||
mChannels[c].mStride);
|
|
||||||
vtxBuilder.add(subElem.get(), mChannels[c].mName.c_str(), 1);
|
|
||||||
}
|
|
||||||
ObjectBaseRef<const Element> vertexDataElem = vtxBuilder.create(rsc);
|
|
||||||
|
|
||||||
uint32_t numVerts = mChannels[0].mData.size()/mChannels[0].mStride;
|
|
||||||
ObjectBaseRef<Type> vertexDataType = Type::getTypeRef(rsc, vertexDataElem.get(),
|
|
||||||
numVerts, 0, 0, false, false);
|
|
||||||
vertexDataType->compute();
|
|
||||||
|
|
||||||
Allocation *vertexAlloc = Allocation::createAllocation(rsc, vertexDataType.get(),
|
|
||||||
RS_ALLOCATION_USAGE_SCRIPT);
|
|
||||||
|
|
||||||
uint32_t vertexSize = vertexDataElem->getSizeBytes()/sizeof(float);
|
|
||||||
// Fill this allocation with some data
|
|
||||||
float *dataPtr = (float*)vertexAlloc->getPtr();
|
|
||||||
for (uint32_t i = 0; i < numVerts; i ++) {
|
|
||||||
// Find the pointer to the current vertex's data
|
|
||||||
uint32_t vertexPos = i*vertexSize;
|
|
||||||
float *vertexPtr = dataPtr + vertexPos;
|
|
||||||
|
|
||||||
uint32_t elemIndex = 0;
|
|
||||||
for (uint32_t c = 0; c < mChannels.size(); c ++) {
|
|
||||||
// Skip empty channels
|
|
||||||
if (mChannels[c].mData.size() == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// This will address vector element alignment issues
|
|
||||||
uint32_t elemlOffset = vertexDataElem->getFieldOffsetBytes(elemIndex)/sizeof(float);
|
|
||||||
elemIndex ++;
|
|
||||||
float *channelPtr = vertexPtr + elemlOffset;
|
|
||||||
for (uint32_t cStride = 0; cStride < mChannels[c].mStride; cStride ++) {
|
|
||||||
*(channelPtr++) = mChannels[c].mData[i * mChannels[c].mStride + cStride];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now lets write index data
|
|
||||||
ObjectBaseRef<const Element> indexElem = Element::createRef(rsc, RS_TYPE_UNSIGNED_16,
|
|
||||||
RS_KIND_USER, false, 1);
|
|
||||||
|
|
||||||
Mesh *mesh = new Mesh(rsc, 1, mTriangleLists.size());
|
|
||||||
mesh->setName(mName.c_str());
|
|
||||||
mesh->setVertexBuffer(vertexAlloc, 0);
|
|
||||||
|
|
||||||
// load all primitives
|
|
||||||
for (uint32_t pCount = 0; pCount < mTriangleLists.size(); pCount ++) {
|
|
||||||
|
|
||||||
uint32_t numIndicies = mTriangleLists[pCount].size();
|
|
||||||
ObjectBaseRef<Type> indexType = Type::getTypeRef(rsc, indexElem.get(),
|
|
||||||
numIndicies, 0, 0, false, false );
|
|
||||||
|
|
||||||
indexType->compute();
|
|
||||||
|
|
||||||
Allocation *indexAlloc = Allocation::createAllocation(rsc, indexType.get(),
|
|
||||||
RS_ALLOCATION_USAGE_SCRIPT);
|
|
||||||
uint16_t *indexPtr = (uint16_t*)indexAlloc->getPtr();
|
|
||||||
const std::vector<uint32_t> &indexList = mTriangleLists[pCount];
|
|
||||||
uint32_t numTries = numIndicies / 3;
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < numTries; i ++) {
|
|
||||||
indexPtr[i * 3 + 0] = (uint16_t)indexList[i * 3 + 0];
|
|
||||||
indexPtr[i * 3 + 1] = (uint16_t)indexList[i * 3 + 1];
|
|
||||||
indexPtr[i * 3 + 2] = (uint16_t)indexList[i * 3 + 2];
|
|
||||||
}
|
|
||||||
indexAlloc->setName(mTriangleListNames[pCount].c_str());
|
|
||||||
mesh->setPrimitive(indexAlloc, RS_PRIMITIVE_TRIANGLE, pCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mesh;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,133 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "ColladaLoader.h"
|
|
||||||
#include "ObjLoader.h"
|
|
||||||
#include <rsContext.h>
|
|
||||||
#include <rsFileA3D.h>
|
|
||||||
|
|
||||||
bool rsdAllocationInit(const Context *rsc, Allocation *alloc, bool forceZero) {
|
|
||||||
void * ptr = malloc(alloc->mHal.state.type->getSizeBytes());
|
|
||||||
if (!ptr) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
alloc->mHal.drvState.mallocPtr = ptr;
|
|
||||||
if (forceZero) {
|
|
||||||
memset(ptr, 0, alloc->mHal.state.type->getSizeBytes());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void rsdAllocationDestroy(const Context *rsc, Allocation *alloc) {
|
|
||||||
if (alloc->mHal.drvState.mallocPtr) {
|
|
||||||
free(alloc->mHal.drvState.mallocPtr);
|
|
||||||
alloc->mHal.drvState.mallocPtr = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static RsdHalFunctions FunctionTable;
|
|
||||||
bool rsdHalInit(Context *rsc, uint32_t version_major, uint32_t version_minor) {
|
|
||||||
memset(&FunctionTable, 0, sizeof(FunctionTable));
|
|
||||||
FunctionTable.allocation.init = rsdAllocationInit;
|
|
||||||
FunctionTable.allocation.destroy = rsdAllocationDestroy;
|
|
||||||
rsc->mHal.funcs = FunctionTable;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool convertToA3D(GeometryLoader *loader, const char *a3dFile) {
|
|
||||||
if (!loader->getNumMeshes()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Now write all this stuff out
|
|
||||||
Context *rsc = Context::createContextLite();
|
|
||||||
rsdHalInit(rsc, 0, 0);
|
|
||||||
FileA3D file(rsc);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < loader->getNumMeshes(); i ++) {
|
|
||||||
Mesh *exportedMesh = loader->getMesh(i)->getRsMesh(rsc);
|
|
||||||
file.appendToFile(exportedMesh);
|
|
||||||
delete exportedMesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.writeFile(a3dFile);
|
|
||||||
delete rsc;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main (int argc, char * const argv[]) {
|
|
||||||
const char *objExt = ".obj";
|
|
||||||
const char *daeExt = ".dae";
|
|
||||||
|
|
||||||
if(argc != 3 && argc != 4) {
|
|
||||||
printf("-----------------------------------------------------------------\n");
|
|
||||||
printf("Usage:\n");
|
|
||||||
printf("a3dconvert input_file a3d_output_file\n");
|
|
||||||
printf("Currently .obj and .dae (collada) input files are accepted\n");
|
|
||||||
printf("-----------------------------------------------------------------\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSuccessful = false;
|
|
||||||
|
|
||||||
std::string filename = argv[1];
|
|
||||||
size_t dotPos = filename.find_last_of('.');
|
|
||||||
if (dotPos == std::string::npos) {
|
|
||||||
printf("Invalid input. Currently .obj and .dae (collada) input files are accepted\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool stripColladaGeo = false;
|
|
||||||
GeometryLoader *loader = NULL;
|
|
||||||
std::string ext = filename.substr(dotPos);
|
|
||||||
if (ext == daeExt) {
|
|
||||||
loader = new ColladaLoader();
|
|
||||||
if (argc == 4) {
|
|
||||||
std::string option = argv[3];
|
|
||||||
if (option == "-d") {
|
|
||||||
stripColladaGeo = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (ext == objExt) {
|
|
||||||
loader = new ObjLoader();
|
|
||||||
} else {
|
|
||||||
printf("Invalid input. Currently .obj and .dae (collada) input files are accepted\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
isSuccessful = loader->init(argv[1]);
|
|
||||||
if (isSuccessful) {
|
|
||||||
isSuccessful = convertToA3D(loader, argv[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSuccessful && stripColladaGeo) {
|
|
||||||
ColladaLoader *colladaLoader = (ColladaLoader*)loader;
|
|
||||||
colladaLoader->stripGeometryAndSave();
|
|
||||||
}
|
|
||||||
|
|
||||||
delete loader;
|
|
||||||
|
|
||||||
if(isSuccessful) {
|
|
||||||
printf("---All done---\n");
|
|
||||||
} else {
|
|
||||||
printf("---Encountered errors, conversion failed---\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return isSuccessful ? 0 : 1;
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
Parts of this code come from colladaDom with the license below. The rest is AOSP.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The MIT License
|
|
||||||
|
|
||||||
Copyright 2006 Sony Computer Entertainment Inc.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||