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

Commit 3eaa338e authored by Jason Sams's avatar Jason Sams
Browse files

Add named objects and implement support for ProgramFragmentStore and...

Add named objects and implement support for ProgramFragmentStore and ProgramFragment to be used by name in scripts.
parent da423d84
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@
#pragma version(1)
#pragma stateVertex(orthoWindow)
#pragma stateRaster(flat)
#pragma stateFragment(color)
#pragma stateStore(parent)
#pragma stateFragment(PgmFragBackground)
#pragma stateFragmentStore(MyBlend)


int main(void* con, int ft, int launchID) {
@@ -35,7 +35,7 @@ int main(void* con, int ft, int launchID) {
        }
    }

    contextBindProgramFragment(con, loadI32(con, 0, 7));
    //contextBindProgramFragment(con, loadI32(con, 0, 7));
    drawRect(con, 0, 256, 0, 512);
    contextBindProgramFragment(con, loadI32(con, 0, 6));

+3 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ public class FountainView extends RSSurfaceView {
        mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA, RenderScript.BlendDstFunc.ONE);
        mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
        mPFS = mRS.programFragmentStoreCreate();
        mPFS.setName("MyBlend");
        mRS.contextBindProgramFragmentStore(mPFS);

        mRS.samplerBegin();
@@ -92,6 +93,7 @@ public class FountainView extends RSSurfaceView {

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

        mRS.programFragmentBegin(null, null);
@@ -100,6 +102,7 @@ public class FountainView extends RSSurfaceView {
        mRS.contextBindProgramFragment(mPF2);
        mPF2.bindTexture(mTexture, 0);
        mPF2.bindSampler(mSampler, 0);
        mPF2.setName("PgmFragBackground");

        mParams[0] = 0;
        mParams[1] = partCount;
+26 −2
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ public class RenderScript {
    native private void nContextBindProgramFragmentStore(int pfs);
    native private void nContextBindProgramFragment(int pf);

    native private void nAssignName(int obj, byte[] name);

    native private void nElementBegin();
    native private void nElementAddPredefined(int predef);
    native private void nElementAdd(int kind, int type, int norm, int bits);
@@ -135,6 +137,7 @@ public class RenderScript {
    native private void nProgramFragmentStoreBlendFunc(int src, int dst);
    native private void nProgramFragmentStoreDither(boolean enable);
    native private int  nProgramFragmentStoreCreate();
    native private void nProgramFragmentStoreDestroy(int pgm);

    native private void nProgramFragmentBegin(int in, int out);
    native private void nProgramFragmentBindTexture(int vpf, int slot, int a);
@@ -143,6 +146,7 @@ public class RenderScript {
    native private void nProgramFragmentSetEnvMode(int slot, int env);
    native private void nProgramFragmentSetTexEnable(int slot, boolean enable);
    native private int  nProgramFragmentCreate();
    native private void nProgramFragmentDestroy(int pgm);


    private int     mDev;
@@ -166,6 +170,26 @@ public class RenderScript {
        }

        int mID;
        String mName;

        public void setName(String s) throws IllegalStateException, IllegalArgumentException
        {
            if(s.length() < 1) {
                throw new IllegalArgumentException("setName does not accept a zero length string.");
            }
            if(mName != null) {
                throw new IllegalArgumentException("setName object already has a name.");
            }

            try {
                byte[] bytes = s.getBytes("UTF-8");
                nAssignName(mID, bytes);
                mName = s;
            } catch (java.io.UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }

        protected void finalize() throws Throwable
        {
            if (mID != 0) {
@@ -661,7 +685,7 @@ public class RenderScript {
        }

        public void destroy() {
            nScriptDestroy(mID);
            nProgramFragmentStoreDestroy(mID);
            mID = 0;
        }
    }
@@ -712,7 +736,7 @@ public class RenderScript {
        }

        public void destroy() {
            nScriptDestroy(mID);
            nProgramFragmentDestroy(mID);
            mID = 0;
        }

+35 −0
Original line number Diff line number Diff line
@@ -60,6 +60,21 @@ static void _nInit(JNIEnv *_env, jclass _this)
}


// ---------------------------------------------------------------------------

static void
nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nAssignName, con(%p), obj(%p)", con, obj);

    jint len = _env->GetArrayLength(str);
    jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
    rsAssignName((void *)obj, (const char *)cptr);
    _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
}


// ---------------------------------------------------------------------------

static jint
@@ -662,9 +677,18 @@ nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nProgramFragmentStoreCreate, con(%p)", con);

    return (jint)rsProgramFragmentStoreCreate();
}

static void
nProgramFragmentStoreDestroy(JNIEnv *_env, jobject _this, jint pgm)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nProgramFragmentStoreDestroy, con(%p), pgm(%i)", con, pgm);
    rsProgramFragmentStoreDestroy((RsProgramFragmentStore)pgm);
}

// ---------------------------------------------------------------------------

static void
@@ -723,6 +747,14 @@ nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable)
    return (jint)rsProgramFragmentCreate();
}

static void
nProgramFragmentDestroy(JNIEnv *_env, jobject _this, jint pgm)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm);
    rsProgramFragmentDestroy((RsProgramFragment)pgm);
}


// ---------------------------------------------------------------------------

@@ -796,6 +828,7 @@ static JNINativeMethod methods[] = {
{"nDeviceDestroy",                 "(I)V",                                 (void*)nDeviceDestroy },
{"nContextCreate",                 "(ILandroid/view/Surface;I)I",          (void*)nContextCreate },
{"nContextDestroy",                "(I)V",                                 (void*)nContextDestroy },
{"nAssignName",                    "(I[B)V",                               (void*)nAssignName },

{"nElementBegin",                  "()V",                                  (void*)nElementBegin },
{"nElementAddPredefined",          "(I)V",                                 (void*)nElementAddPredefined },
@@ -858,6 +891,7 @@ static JNINativeMethod methods[] = {
{"nProgramFragmentStoreBlendFunc", "(II)V",                                (void*)nProgramFragmentStoreBlendFunc },
{"nProgramFragmentStoreDither",    "(Z)V",                                 (void*)nProgramFragmentStoreDither },
{"nProgramFragmentStoreCreate",    "()I",                                  (void*)nProgramFragmentStoreCreate },
{"nProgramFragmentStoreDestroy",   "(I)V",                                 (void*)nProgramFragmentStoreDestroy },

{"nProgramFragmentBegin",          "(II)V",                                (void*)nProgramFragmentBegin },
{"nProgramFragmentBindTexture",    "(III)V",                               (void*)nProgramFragmentBindTexture },
@@ -866,6 +900,7 @@ static JNINativeMethod methods[] = {
{"nProgramFragmentSetEnvMode",     "(II)V",                                (void*)nProgramFragmentSetEnvMode },
{"nProgramFragmentSetTexEnable",   "(IZ)V",                                (void*)nProgramFragmentSetTexEnable },
{"nProgramFragmentCreate",         "()I",                                  (void*)nProgramFragmentCreate },
{"nProgramFragmentDestroy",        "(I)V",                                 (void*)nProgramFragmentDestroy },

{"nContextBindRootScript",         "(I)V",                                 (void*)nContextBindRootScript },
{"nContextBindProgramFragmentStore","(I)V",                                (void*)nContextBindProgramFragmentStore },
+10 −0
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@ ContextBindProgramVertex {
	param RsProgramVertex pgm
	}

AssignName {
	param void *obj
	param const char *name
	}

ElementBegin {
}
@@ -332,6 +336,9 @@ ProgramFragmentStoreCreate {
	ret RsProgramFragmentStore
	}

ProgramFragmentStoreDestroy {
	param RsProgramFragmentStore pfs
	}


ProgramFragmentBegin {
@@ -370,6 +377,9 @@ ProgramFragmentCreate {
	ret RsProgramFragment
	}

ProgramFragmentDestroy {
	param RsProgramFragment pf
	}


ProgramVertexBegin {
Loading