Switch fountain to use ProgramVertex rather than hard coded camers in scripts. Remove camera code from scripts.
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
index 0a0b05a..d167b5f 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -18,12 +18,13 @@
import java.io.Writer;
-import android.renderscript.RenderScript;
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.renderscript.RenderScript;
+import android.renderscript.ProgramVertexAlloc;
import android.util.Log;
public class FountainRS {
@@ -57,8 +58,10 @@
private RenderScript.ProgramFragmentStore mPFS;
private RenderScript.ProgramFragment mPF;
private RenderScript.ProgramFragment mPF2;
+ private RenderScript.ProgramVertex mPV;
private RenderScript.Allocation mTexture;
private RenderScript.Sampler mSampler;
+ private ProgramVertexAlloc mPVA;
private Bitmap mBackground;
@@ -107,6 +110,16 @@
mPF2.bindSampler(mSampler, 0);
mPF2.setName("PgmFragBackground");
+ mRS.programVertexBegin(null, null);
+ mPV = mRS.programVertexCreate();
+ mPVA = new ProgramVertexAlloc(mRS);
+ mPV.bindAllocation(0, mPVA.mAlloc);
+ mPVA.setupOrthoWindow(320, 480);
+ mRS.contextBindProgramVertex(mPV);
+
+
+
+
mParams[0] = 0;
mParams[1] = partCount;
mParams[2] = 0;
diff --git a/libs/rs/java/RenderScript/android/renderscript/Matrix.java b/libs/rs/java/RenderScript/android/renderscript/Matrix.java
index 03222aa..91e7b34 100644
--- a/libs/rs/java/RenderScript/android/renderscript/Matrix.java
+++ b/libs/rs/java/RenderScript/android/renderscript/Matrix.java
@@ -139,8 +139,8 @@
mMat[5] = 2 / (t - b);
mMat[10]= -2 / (f - n);
mMat[12]= -(r + l) / (r - l);
- mMat[12]= -(t + b) / (t - b);
- mMat[12]= -(f + n) / (f - n);
+ mMat[13]= -(t + b) / (t - b);
+ mMat[14]= -(f + n) / (f - n);
}
public void loadFrustum(float l, float r, float b, float t, float n, float f) {
diff --git a/libs/rs/java/RenderScript/android/renderscript/RenderScript.java b/libs/rs/java/RenderScript/android/renderscript/RenderScript.java
index afb4ae3..4d5c4a0 100644
--- a/libs/rs/java/RenderScript/android/renderscript/RenderScript.java
+++ b/libs/rs/java/RenderScript/android/renderscript/RenderScript.java
@@ -154,10 +154,7 @@
native private void nProgramVertexBindAllocation(int pv, int slot, int mID);
native private void nProgramVertexBegin(int inID, int outID);
native private void nProgramVertexSetType(int slot, int mID);
- native private void nProgramVertexSetCameraMode(boolean isOrtho);
native private void nProgramVertexSetTextureMatrixEnable(boolean enable);
- native private void nProgramVertexSetModelMatrixEnable(boolean enable);
- native private void nProgramVertexSetProjectionMatrixEnable(boolean enable);
native private int nProgramVertexCreate();
@@ -733,22 +730,10 @@
nProgramVertexSetType(slot, t.mID);
}
- public void programVertexSetCameraMode(boolean isOrtho) {
- nProgramVertexSetCameraMode(isOrtho);
- }
-
public void programVertexSetTextureMatrixEnable(boolean enable) {
nProgramVertexSetTextureMatrixEnable(enable);
}
- public void programVertexSetModelMatrixEnable(boolean enable) {
- nProgramVertexSetModelMatrixEnable(enable);
- }
-
- public void programVertexSetProjectionMatrixEnable(boolean enable) {
- nProgramVertexSetProjectionMatrixEnable(enable);
- }
-
public ProgramVertex programVertexCreate() {
int id = nProgramVertexCreate();
return new ProgramVertex(id);
diff --git a/libs/rs/java/Rollo/res/raw/rollo.c b/libs/rs/java/Rollo/res/raw/rollo.c
index b81c567..56ee425 100644
--- a/libs/rs/java/Rollo/res/raw/rollo.c
+++ b/libs/rs/java/Rollo/res/raw/rollo.c
@@ -8,6 +8,7 @@
int x;
renderTriangleMesh(con, NAMED_MeshCard);
+ renderTriangleMesh(con, NAMED_MeshTab);
return 1;
}
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java
index c44a817..d7252fb 100644
--- a/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java
+++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java
@@ -24,6 +24,11 @@
class RolloMesh {
+ static public final float mCardHeight = 1.2f;
+ static public final float mCardWidth = 1.8f;
+ static public final float mTabHeight = 0.2f;
+ static public final float mTabs = 3;
+ static public final float mTabGap = 0.1f;
static RenderScript.TriangleMesh createCard(RenderScript rs) {
RenderScript.Element vtx = rs.elementGetPredefined(
@@ -31,12 +36,15 @@
RenderScript.Element idx = rs.elementGetPredefined(
RenderScript.ElementPredefined.INDEX_16);
- rs.triangleMeshBegin(vtx, idx);
- rs.triangleMeshAddVertex_XYZ_ST(0, 0, 0, 0, 0);
- rs.triangleMeshAddVertex_XYZ_ST(0, 1, 0, 0, 1);
- rs.triangleMeshAddVertex_XYZ_ST(1, 1, 0, 1, 1);
- rs.triangleMeshAddVertex_XYZ_ST(1, 0, 0, 1, 0);
+ float w = mCardWidth / 2;
+ float h = mCardHeight;
+ float z = 0;
+ rs.triangleMeshBegin(vtx, idx);
+ rs.triangleMeshAddVertex_XYZ_ST(-w, 0, z, 0, 0);
+ rs.triangleMeshAddVertex_XYZ_ST(-w, h, z, 0, 1);
+ rs.triangleMeshAddVertex_XYZ_ST( w, h, z, 1, 1);
+ rs.triangleMeshAddVertex_XYZ_ST( w, 0, z, 1, 0);
rs.triangleMeshAddTriangle(0,1,2);
rs.triangleMeshAddTriangle(0,2,3);
return rs.triangleMeshCreate();
@@ -48,11 +56,28 @@
RenderScript.Element idx = rs.elementGetPredefined(
RenderScript.ElementPredefined.INDEX_16);
+
+ float tabSlope = 0.1f;
+ float num = 0;
+
+ float w = (mCardWidth - ((mTabs - 1) * mTabGap)) / mTabs;
+ float w1 = -(mCardWidth / 2) + ((w + mTabGap) * num);
+ float w2 = w1 + (w * tabSlope);
+ float w3 = w1 + w - (w * tabSlope);
+ float w4 = w1 + w;
+ float h1 = mCardHeight;
+ float h2 = h1 + mTabHeight;
+ float z = 0;
+
+ float stScale = w / mTabHeight / 2;
+ float stScale2 = stScale * (tabSlope / w);
+
+
rs.triangleMeshBegin(vtx, idx);
- rs.triangleMeshAddVertex_XYZ_ST(0.0f, 0, 0, -1.0f, 0);
- rs.triangleMeshAddVertex_XYZ_ST(0.2f, 1, 0, -0.8f, 1);
- rs.triangleMeshAddVertex_XYZ_ST(1.8f, 1, 0, 0.8f, 1);
- rs.triangleMeshAddVertex_XYZ_ST(2.0f, 0, 0, 1.0f, 0);
+ rs.triangleMeshAddVertex_XYZ_ST(w1, h1, z, -stScale, 0);
+ rs.triangleMeshAddVertex_XYZ_ST(w2, h2, z, -stScale2, 1);
+ rs.triangleMeshAddVertex_XYZ_ST(w3, h2, z, stScale2, 1);
+ rs.triangleMeshAddVertex_XYZ_ST(w4, h1, z, stScale, 0);
rs.triangleMeshAddTriangle(0,1,2);
rs.triangleMeshAddTriangle(0,2,3);
return rs.triangleMeshCreate();
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
index aa9f338..da0b146 100644
--- a/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
+++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
@@ -74,8 +74,8 @@
//private float[] mBufferPV;
private void initNamed() {
- //mMeshTab = RolloMesh.createTab(mRS);
- //mMeshTab.setName("MeshTab");
+ mMeshTab = RolloMesh.createTab(mRS);
+ mMeshTab.setName("MeshTab");
mMeshCard = RolloMesh.createCard(mRS);
mMeshCard.setName("MeshCard");
Log.e("rs", "Done loading strips");
@@ -117,10 +117,7 @@
mPVAlloc = new ProgramVertexAlloc(mRS);
mRS.programVertexBegin(null, null);
- mRS.programVertexSetCameraMode(true);
mRS.programVertexSetTextureMatrixEnable(true);
- mRS.programVertexSetModelMatrixEnable(true);
- mRS.programVertexSetProjectionMatrixEnable(true);
mPV = mRS.programVertexCreate();
mPV.setName("PV");
mPV.bindAllocation(0, mPVAlloc.mAlloc);
diff --git a/libs/rs/jni/RenderScript_jni.cpp b/libs/rs/jni/RenderScript_jni.cpp
index 7a3a7af..ab17a4a 100644
--- a/libs/rs/jni/RenderScript_jni.cpp
+++ b/libs/rs/jni/RenderScript_jni.cpp
@@ -791,14 +791,6 @@
}
static void
-nProgramVertexSetCameraMode(JNIEnv *_env, jobject _this, jboolean isOrtho)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexSetCameraMode, con(%p), isOrtho(%i)", con, isOrtho);
- rsProgramVertexSetCameraMode(isOrtho);
-}
-
-static void
nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
@@ -806,22 +798,6 @@
rsProgramVertexSetTextureMatrixEnable(enable);
}
-static void
-nProgramVertexSetModelMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexSetModelMatrixEnable, con(%p), enable(%i)", con, enable);
- rsProgramVertexSetModelMatrixEnable(enable);
-}
-
-static void
-nProgramVertexSetProjectionMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
-{
- RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nProgramVertexSetProjectionMatrixEnable, con(%p), enable(%i)", con, enable);
- rsProgramVertexSetProjectionMatrixEnable(enable);
-}
-
static jint
nProgramVertexCreate(JNIEnv *_env, jobject _this)
{
@@ -1000,10 +976,7 @@
{"nProgramVertexBindAllocation", "(III)V", (void*)nProgramVertexBindAllocation },
{"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin },
{"nProgramVertexSetType", "(II)V", (void*)nProgramVertexSetType },
-{"nProgramVertexSetCameraMode", "(Z)V", (void*)nProgramVertexSetCameraMode },
{"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable },
-{"nProgramVertexSetModelMatrixEnable", "(Z)V", (void*)nProgramVertexSetModelMatrixEnable },
-{"nProgramVertexSetProjectionMatrixEnable", "(Z)V", (void*)nProgramVertexSetProjectionMatrixEnable },
{"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate },
{"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript },
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 107096f..dd489b8 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -286,10 +286,6 @@
param bool isRoot
}
-ScriptCSetOrtho {
- param bool isOrtho
- }
-
ScriptCSetScript {
param void * codePtr
}
@@ -403,19 +399,7 @@
param RsType constants
}
-ProgramVertexSetCameraMode {
- param bool ortho
- }
-
ProgramVertexSetTextureMatrixEnable {
param bool enable
}
-ProgramVertexSetModelMatrixEnable {
- param bool enable
- }
-
-ProgramVertexSetProjectionMatrixEnable {
- param bool enable
- }
-
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 266c455..c466f46 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -81,24 +81,6 @@
glEnable(GL_LIGHT0);
glViewport(0, 0, mWidth, mHeight);
- if(mRootScript->mEnviroment.mIsOrtho) {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrthof(0, mWidth, mHeight, 0, 0, 1);
- glMatrixMode(GL_MODELVIEW);
- } else {
- float aspectH = ((float)mWidth) / mHeight;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustumf(-1, 1, -aspectH, aspectH, 1, 100);
- glRotatef(-90, 0,0,1);
- glTranslatef(0, 0, -3);
- glMatrixMode(GL_MODELVIEW);
- }
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
glDepthMask(GL_TRUE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index fc26ab5..c24f228 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -25,14 +25,21 @@
Program(in, out)
{
mTextureMatrixEnable = false;
- mProjectionEnable = false;
- mTransformEnable = false;
}
ProgramVertex::~ProgramVertex()
{
}
+static void logMatrix(const char *txt, const float *f)
+{
+ LOGE("Matrix %s, %p", txt, f);
+ LOGE("%6.2f, %6.2f, %6.2f, %6.2f", f[0], f[4], f[8], f[12]);
+ LOGE("%6.2f, %6.2f, %6.2f, %6.2f", f[1], f[5], f[9], f[13]);
+ LOGE("%6.2f, %6.2f, %6.2f, %6.2f", f[2], f[6], f[10], f[14]);
+ LOGE("%6.2f, %6.2f, %6.2f, %6.2f", f[3], f[7], f[11], f[15]);
+}
+
void ProgramVertex::setupGL()
{
const float *f = static_cast<const float *>(mConstants[0]->getPtr());
@@ -44,19 +51,13 @@
glLoadIdentity();
}
+ //logMatrix("prog", &f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]);
+ //logMatrix("model", &f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET]);
glMatrixMode(GL_PROJECTION);
- if (mProjectionEnable) {
- glLoadMatrixf(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]);
- } else {
- }
-
+ glLoadMatrixf(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]);
glMatrixMode(GL_MODELVIEW);
- if (mTransformEnable) {
- glLoadMatrixf(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET]);
- } else {
- glLoadIdentity();
- }
+ glLoadMatrixf(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET]);
}
void ProgramVertex::setConstantType(uint32_t slot, const Type *t)
@@ -110,26 +111,11 @@
rsc->mStateVertex.mPV->setConstantType(slot, static_cast<const Type *>(constants));
}
-void rsi_ProgramVertexSetCameraMode(Context *rsc, bool ortho)
-{
- rsc->mStateVertex.mPV->setProjectionEnabled(!ortho);
-}
-
void rsi_ProgramVertexSetTextureMatrixEnable(Context *rsc, bool enable)
{
rsc->mStateVertex.mPV->setTextureMatrixEnable(enable);
}
-void rsi_ProgramVertexSetModelMatrixEnable(Context *rsc, bool enable)
-{
- rsc->mStateVertex.mPV->setTransformEnable(enable);
-}
-
-void rsi_ProgramVertexSetProjectionMatrixEnable(Context *rsc, bool enable)
-{
- rsc->mStateVertex.mPV->setProjectionEnable(enable);
-}
-
}
diff --git a/libs/rs/rsProgramVertex.h b/libs/rs/rsProgramVertex.h
index 677be6e..0b3a3eb 100644
--- a/libs/rs/rsProgramVertex.h
+++ b/libs/rs/rsProgramVertex.h
@@ -38,9 +38,6 @@
void setConstantType(uint32_t slot, const Type *);
void bindAllocation(uint32_t slot, Allocation *);
void setTextureMatrixEnable(bool e) {mTextureMatrixEnable = e;}
- void setProjectionEnabled(bool e) {mProjectionEnable = e;}
- void setTransformEnable(bool e) {mTransformEnable = e;}
- void setProjectionEnable(bool e) {mProjectionEnable = e;}
protected:
bool mDirty;
@@ -50,8 +47,6 @@
// Hacks to create a program for now
bool mTextureMatrixEnable;
- bool mProjectionEnable;
- bool mTransformEnable;
};
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index d32f116..7dd2b61 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -39,7 +39,6 @@
struct Enviroment_t {
bool mIsRoot;
- bool mIsOrtho;
float mClearColor[4];
float mClearDepth;
uint32_t mClearStencil;
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index d29eb9f..2963831 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -428,7 +428,6 @@
mEnviroment.mClearDepth = 1;
mEnviroment.mClearStencil = 0;
mEnviroment.mIsRoot = false;
- mEnviroment.mIsOrtho = true;
mAccScript = NULL;
@@ -556,12 +555,6 @@
ss->mEnviroment.mIsRoot = isRoot;
}
-void rsi_ScriptCSetOrtho(Context * rsc, bool isOrtho)
-{
- ScriptCState *ss = &rsc->mScriptC;
- ss->mEnviroment.mIsOrtho = isOrtho;
-}
-
void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len)
{
ScriptCState *ss = &rsc->mScriptC;