Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b37c0a5d authored by Jason Sams's avatar Jason Sams
Browse files

Switch fountain to use ProgramVertex rather than hard coded camers in scripts....

Switch fountain to use ProgramVertex rather than hard coded camers in scripts.  Remove camera code from scripts.
parent 0826a6f9
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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) {
+0 −15
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ int main(void* con, int ft, int launchID)
    int x;

    renderTriangleMesh(con, NAMED_MeshCard);
    renderTriangleMesh(con, NAMED_MeshTab);
    return 1;
}
+34 −9
Original line number Diff line number Diff line
@@ -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();
Loading