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

Commit 334ea0c9 authored by Jason Sams's avatar Jason Sams
Browse files

Update fountain and add writable flag to script slots.

parent 0ef135d5
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -223,6 +223,52 @@ public class Element extends BaseObj {
            return this;
        }

        public Builder addFloat(Element.DataKind dk) {
            add(DataType.FLOAT, dk, false, 32, null);
            return this;
        }

        public Builder addFloat(Element.DataKind dk, String name) {
            add(DataType.FLOAT, dk, false, 32, name);
            return this;
        }

        public Builder addFloatXY() {
            add(DataType.FLOAT, DataKind.X, false, 32, null);
            add(DataType.FLOAT, DataKind.Y, false, 32, null);
            return this;
        }

        public Builder addFloatXYZ() {
            add(DataType.FLOAT, DataKind.X, false, 32, null);
            add(DataType.FLOAT, DataKind.Y, false, 32, null);
            add(DataType.FLOAT, DataKind.Z, false, 32, null);
            return this;
        }

        public Builder addFloatRGB() {
            add(DataType.FLOAT, DataKind.RED, false, 32, null);
            add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
            add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
            return this;
        }

        public Builder addFloatRGBA() {
            add(DataType.FLOAT, DataKind.RED, false, 32, null);
            add(DataType.FLOAT, DataKind.GREEN, false, 32, null);
            add(DataType.FLOAT, DataKind.BLUE, false, 32, null);
            add(DataType.FLOAT, DataKind.ALPHA, false, 32, null);
            return this;
        }

        public Builder addUNorm8RGBA() {
            add(DataType.UNSIGNED, DataKind.RED, true, 8, null);
            add(DataType.UNSIGNED, DataKind.GREEN, true, 8, null);
            add(DataType.UNSIGNED, DataKind.BLUE, true, 8, null);
            add(DataType.UNSIGNED, DataKind.ALPHA, true, 8, null);
            return this;
        }

        static synchronized Element internalCreate(RenderScript rs, Builder b) {
            rs.nElementBegin();
            for (int ct=0; ct < b.mEntryCount; ct++) {
+1 −1
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ public class RenderScript {
    native void nScriptSetClearDepth(int script, float depth);
    native void nScriptSetClearStencil(int script, int stencil);
    native void nScriptSetTimeZone(int script, byte[] timeZone);
    native void nScriptSetType(int type, String name, int slot);
    native void nScriptSetType(int type, boolean writable, String name, int slot);
    native void nScriptSetRoot(boolean isRoot);

    native void nScriptCBegin();
+8 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ public class Script extends BaseObj {

    boolean mIsRoot;
    Type[] mTypes;
    boolean[] mWritable;

    Script(int id, RenderScript rs) {
        super(rs);
@@ -67,11 +68,13 @@ public class Script extends BaseObj {
        boolean mIsRoot = false;
        Type[] mTypes;
        String[] mNames;
        boolean[] mWritable;

        Builder(RenderScript rs) {
            mRS = rs;
            mTypes = new Type[MAX_SLOT];
            mNames = new String[MAX_SLOT];
            mWritable = new boolean[MAX_SLOT];
        }

        public void setType(Type t, int slot) {
@@ -84,11 +87,15 @@ public class Script extends BaseObj {
            mNames[slot] = name;
        }

        public void setType(boolean writable, int slot) {
            mWritable[slot] = writable;
        }

        void transferCreate() {
            mRS.nScriptSetRoot(mIsRoot);
            for(int ct=0; ct < mTypes.length; ct++) {
                if(mTypes[ct] != null) {
                    mRS.nScriptSetType(mTypes[ct].mID, mNames[ct], ct);
                    mRS.nScriptSetType(mTypes[ct].mID, mWritable[ct], mNames[ct], ct);
                }
            }
        }
+4 −4
Original line number Diff line number Diff line
@@ -825,15 +825,15 @@ nScriptSetTimeZone(JNIEnv *_env, jobject _this, jint script, jbyteArray timeZone
}

static void
nScriptSetType(JNIEnv *_env, jobject _this, jint type, jstring _str, jint slot)
nScriptSetType(JNIEnv *_env, jobject _this, jint type, jboolean writable, jstring _str, jint slot)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nScriptCAddType, con(%p), type(%p), slot(%i)", con, (RsType)type, slot);
    LOG_API("nScriptCAddType, con(%p), type(%p), writable(%i), slot(%i)", con, (RsType)type, writable, slot);
    const char* n = NULL;
    if (_str) {
        n = _env->GetStringUTFChars(_str, NULL);
    }
    rsScriptSetType((RsType)type, slot, n);
    rsScriptSetType((RsType)type, slot, writable, n);
    if (n) {
        _env->ReleaseStringUTFChars(_str, n);
    }
@@ -1381,7 +1381,7 @@ static JNINativeMethod methods[] = {
{"nScriptSetClearDepth",           "(IF)V",                                (void*)nScriptSetClearDepth },
{"nScriptSetClearStencil",         "(II)V",                                (void*)nScriptSetClearStencil },
{"nScriptSetTimeZone",             "(I[B)V",                               (void*)nScriptSetTimeZone },
{"nScriptSetType",                 "(ILjava/lang/String;I)V",              (void*)nScriptSetType },
{"nScriptSetType",                 "(IZLjava/lang/String;I)V",             (void*)nScriptSetType },
{"nScriptSetRoot",                 "(Z)V",                                 (void*)nScriptSetRoot },

{"nScriptCBegin",                  "()V",                                  (void*)nScriptCBegin },
+31 −65
Original line number Diff line number Diff line
// Fountain test script

#pragma version(1)
#pragma stateVertex(default)
#pragma stateFragment(PgmFragParts)
#pragma stateFragmentStore(PFSBlend)

#pragma stateFragment(default)
#pragma stateFragmentStore(default)

int main(int launchID) {
    int ct;
    int count = loadI32(0, OFFSETOF_SomeData_count);
    int touch = loadI32(0, OFFSETOF_SomeData_touch);
    int rate = 4;
    int maxLife = (count / rate) - 1;
    int count = Control_count - 1;
    int rate = Control_rate;
    float *dataF = loadArrayF(1, 0);
    float height = getHeight();

    if (touch) {
        int x = loadI32(0, OFFSETOF_SomeData_x);
        int y = loadI32(0, OFFSETOF_SomeData_y);
        int newPart = loadI32(2, 0);
        for (ct=0; ct<rate; ct++) {
            int idx = newPart * 5 + 1;
            storeF(2, idx, randf(1.f) - 0.5f);
            storeF(2, idx + 1, randf(1.f) - 0.5f);
            storeI32(2, idx + 2, maxLife);
            storeF(2, idx + 3, x);
            storeF(2, idx + 4, y);
    if (rate) {
        debugI32("rate", rate);
        int *dataI = loadArrayI32(1, 0);
        float rMax = ((float)rate) * 0.005f;
        int x = Control_x;
        int y = Control_y;
        int newPart = loadI32(1, count * 5);
        int c = colorFloatRGBAtoUNorm8(Control_r, Control_g, Control_b, 0.99f);

        while (rate--) {
            int idx = newPart * 5;
            vec2Rand(dataF + idx, rMax);
            dataF[idx + 2] = x;
            dataF[idx + 3] = y;
            dataI[idx + 4] = c;
            newPart++;
            if (newPart >= count) {
                newPart = 0;
            }
        }
        storeI32(2, 0, newPart);
        storeI32(1, count * 5, newPart);
    }

    int drawCount = 0;
    float height = getHeight();
    for (ct=0; ct < count; ct++) {
        int srcIdx = ct * 5 + 1;

        int life = loadI32(2, srcIdx + 2);

        if (life) {
            float posx = loadF(2, srcIdx + 3);
            float posy = loadF(2, srcIdx + 4);
            float dx = loadF(2, srcIdx);
            float dy = loadF(2, srcIdx + 1);
            if (posy < height) {
                int dstIdx = drawCount * 9;
                int c = 0xcfcfcfcf;

                storeI32(1, dstIdx, c);
                storeF(1, dstIdx + 1, posx);
                storeF(1, dstIdx + 2, posy);

                storeI32(1, dstIdx + 3, c);
                storeF(1, dstIdx + 4, posx + 1.f);
                storeF(1, dstIdx + 5, posy + dy);

                storeI32(1, dstIdx + 6, c);
                storeF(1, dstIdx + 7, posx - 1.f);
                storeF(1, dstIdx + 8, posy + dy);
                drawCount ++;
            } else {
                if (dy > 0) {
                    dy *= -0.5f;
                }
            }

            posx = posx + dx;
            posy = posy + dy;
            dy = dy + 0.05f;
            life --;

            //storeI32(2, srcIdx, dx);
            storeF(2, srcIdx + 1, dy);
            storeI32(2, srcIdx + 2, life);
            storeF(2, srcIdx + 3, posx);
            storeF(2, srcIdx + 4, posy);
        float dy = dataF[1] + 0.15f;
        float posy = dataF[3] + dy;
        if ((posy > height) && (dy > 0)) {
            dy *= -0.3f;
        }
        dataF[1] = dy;
        dataF[2] += dataF[0];
        dataF[3] = posy;
        dataF += 5;
    }

    //drawTriangleArray(NAMED_PartBuffer, drawCount);
    uploadToBufferObject(NAMED_PartBuffer);
    drawSimpleMeshRange(NAMED_PartMesh, 0, drawCount * 3);
    drawSimpleMeshRange(NAMED_PartMesh, 0, count);
    return 1;
}
Loading