Merge change 4426
* changes: Switch fountain to use ProgramVertex rather than hard coded camers in scripts. Remove camera code from scripts.
This commit is contained in:
@@ -18,12 +18,13 @@ package com.android.fountain;
|
||||
|
||||
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 @@ public class FountainRS {
|
||||
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 @@ public class FountainRS {
|
||||
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;
|
||||
|
||||
@@ -139,8 +139,8 @@ class Matrix {
|
||||
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) {
|
||||
|
||||
@@ -154,10 +154,7 @@ public class RenderScript {
|
||||
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 @@ public class RenderScript {
|
||||
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);
|
||||
|
||||
@@ -8,6 +8,7 @@ int main(void* con, int ft, int launchID)
|
||||
int x;
|
||||
|
||||
renderTriangleMesh(con, NAMED_MeshCard);
|
||||
renderTriangleMesh(con, NAMED_MeshTab);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,11 @@ import android.renderscript.RenderScript;
|
||||
|
||||
|
||||
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 @@ class RolloMesh {
|
||||
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 @@ class RolloMesh {
|
||||
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();
|
||||
|
||||
@@ -74,8 +74,8 @@ public class RolloRS {
|
||||
//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 @@ public class RolloRS {
|
||||
|
||||
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);
|
||||
|
||||
@@ -790,14 +790,6 @@ nProgramVertexSetType(JNIEnv *_env, jobject _this, jint slot, jint t)
|
||||
rsProgramVertexSetType(slot, (RsType)t);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -806,22 +798,6 @@ nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enabl
|
||||
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 @@ static JNINativeMethod methods[] = {
|
||||
{"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 },
|
||||
|
||||
@@ -286,10 +286,6 @@ ScriptCSetRoot {
|
||||
param bool isRoot
|
||||
}
|
||||
|
||||
ScriptCSetOrtho {
|
||||
param bool isOrtho
|
||||
}
|
||||
|
||||
ScriptCSetScript {
|
||||
param void * codePtr
|
||||
}
|
||||
@@ -403,19 +399,7 @@ ProgramVertexSetType {
|
||||
param RsType constants
|
||||
}
|
||||
|
||||
ProgramVertexSetCameraMode {
|
||||
param bool ortho
|
||||
}
|
||||
|
||||
ProgramVertexSetTextureMatrixEnable {
|
||||
param bool enable
|
||||
}
|
||||
|
||||
ProgramVertexSetModelMatrixEnable {
|
||||
param bool enable
|
||||
}
|
||||
|
||||
ProgramVertexSetProjectionMatrixEnable {
|
||||
param bool enable
|
||||
}
|
||||
|
||||
|
||||
@@ -81,24 +81,6 @@ bool Context::runRootScript()
|
||||
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);
|
||||
|
||||
|
||||
@@ -25,14 +25,21 @@ ProgramVertex::ProgramVertex(Element *in, Element *out) :
|
||||
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 @@ void ProgramVertex::setupGL()
|
||||
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 @@ void rsi_ProgramVertexSetType(Context *rsc, uint32_t slot, RsType constants)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -38,9 +38,6 @@ public:
|
||||
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 @@ protected:
|
||||
|
||||
// Hacks to create a program for now
|
||||
bool mTextureMatrixEnable;
|
||||
bool mProjectionEnable;
|
||||
bool mTransformEnable;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ public:
|
||||
|
||||
struct Enviroment_t {
|
||||
bool mIsRoot;
|
||||
bool mIsOrtho;
|
||||
float mClearColor[4];
|
||||
float mClearDepth;
|
||||
uint32_t mClearStencil;
|
||||
|
||||
@@ -428,7 +428,6 @@ void ScriptCState::clear()
|
||||
mEnviroment.mClearDepth = 1;
|
||||
mEnviroment.mClearStencil = 0;
|
||||
mEnviroment.mIsRoot = false;
|
||||
mEnviroment.mIsOrtho = true;
|
||||
|
||||
mAccScript = NULL;
|
||||
|
||||
@@ -556,12 +555,6 @@ void rsi_ScriptCSetRoot(Context * rsc, bool isRoot)
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user