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

Commit 0ae234c9 authored by Jason Sams's avatar Jason Sams
Browse files

Add background bitmap to fountain test app for renderscript.

parent df98851d
Loading
Loading
Loading
Loading
+102 KiB
Loading image diff...
+28 −1
Original line number Diff line number Diff line
@@ -21,6 +21,10 @@ import java.util.ArrayList;
import java.util.concurrent.Semaphore;

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;
@@ -46,6 +50,10 @@ public class FountainView extends RSSurfaceView {
    private RenderScript.Script mScript;
    private RenderScript.ProgramFragmentStore mPFS;
    private RenderScript.ProgramFragment mPF;
    private RenderScript.ProgramFragment mPF2;
    private RenderScript.Allocation mTexture;

    private Bitmap mBackground;

    int mParams[] = new int[10];

@@ -58,6 +66,17 @@ public class FountainView extends RSSurfaceView {
        mPartAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 3 * 3);
        mVertAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 5 + 1);

        {
            Resources res = getResources();
            Drawable d = res.getDrawable(R.drawable.gadgets_clock_mp3);
            BitmapDrawable bd = (BitmapDrawable)d;
            Bitmap b = bd.getBitmap();
            mTexture = mRS.allocationCreateFromBitmap(b,
                                                      RenderScript.ElementPredefined.RGB_565,
                                                      true);
            mTexture.uploadToTexture(0);
        }

        mRS.programFragmentStoreBegin(null, null);
        mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA, RenderScript.BlendDstFunc.ONE);
        mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
@@ -66,7 +85,13 @@ public class FountainView extends RSSurfaceView {

        mRS.programFragmentBegin(null, null);
        mPF = mRS.programFragmentCreate();
        mRS.contextBindProgramFragment(mPF);
        //mRS.contextBindProgramFragment(mPF);

        mRS.programFragmentBegin(null, null);
        mRS.programFragmentSetTexEnable(0, true);
        mPF2 = mRS.programFragmentCreate();
        mRS.contextBindProgramFragment(mPF2);
        mPF2.bindTexture(mTexture, 0);

        mParams[0] = 0;
        mParams[1] = partCount;
@@ -74,6 +99,8 @@ public class FountainView extends RSSurfaceView {
        mParams[3] = 0;
        mParams[4] = 0;
        mParams[5] = mPartAlloc.mID;
        mParams[6] = mPF.mID;
        mParams[7] = mPF2.mID;
        mIntAlloc.data(mParams);

        int t2[] = new int[partCount * 4*3];
+4 −0
Original line number Diff line number Diff line
@@ -78,6 +78,10 @@ static const char* TEST_SCRIPT = ""
        "        }\n"
        "    }\n"
        "\n"
        "    contextBindProgramFragment(con, loadI32(con, 0, 7));\n"
        "    drawRect(con, 0, 256, 0, 512);\n"
        "    contextBindProgramFragment(con, loadI32(con, 0, 6));\n"
        "\n"
        "    if (touch) {\n"
        "        newPart = loadI32(con, 2, 0);\n"
        "        for (ct2=0; ct2<rate; ct2++) {\n"