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

Commit b2b96c25 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 2668

* changes:
  Add sampler support
parents 3d7fcb69 02fb2cb5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public class FountainView extends RSSurfaceView {
    private RenderScript.ProgramFragment mPF;
    private RenderScript.ProgramFragment mPF2;
    private RenderScript.Allocation mTexture;
    private RenderScript.Sampler mSampler;

    private Bitmap mBackground;

@@ -83,6 +84,12 @@ public class FountainView extends RSSurfaceView {
        mPFS = mRS.programFragmentStoreCreate();
        mRS.contextBindProgramFragmentStore(mPFS);

        mRS.samplerBegin();
        mRS.samplerSet(RenderScript.SamplerParam.FILTER_MAG, RenderScript.SamplerValue.LINEAR);
        mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN, RenderScript.SamplerValue.LINEAR);
        mSampler = mRS.samplerCreate();


        mRS.programFragmentBegin(null, null);
        mPF = mRS.programFragmentCreate();
        //mRS.contextBindProgramFragment(mPF);
@@ -92,6 +99,7 @@ public class FountainView extends RSSurfaceView {
        mPF2 = mRS.programFragmentCreate();
        mRS.contextBindProgramFragment(mPF2);
        mPF2.bindTexture(mTexture, 0);
        mPF2.bindSampler(mSampler, 0);

        mParams[0] = 0;
        mParams[1] = partCount;
+63 −6
Original line number Diff line number Diff line
@@ -49,9 +49,7 @@ public class RenderScript {
        sInitialized = false;
        try {
            System.loadLibrary("RS_jni");
            Log.e(LOG_TAG, "*** Renderscript INIT");
            _nInit();
            Log.e(LOG_TAG, "*** Renderscript INIT 3");
            sInitialized = true;
        } catch (UnsatisfiedLinkError e) {
            Log.d(LOG_TAG, "RenderScript JNI library not found!");
@@ -126,6 +124,10 @@ public class RenderScript {
    native private void nScriptCSetScript(byte[] script, int offset, int length);
    native private int  nScriptCCreate();

    native private void nSamplerDestroy(int sampler);
    native private void nSamplerBegin();
    native private void nSamplerSet(int param, int value);
    native private int  nSamplerCreate();

    native private void nProgramFragmentStoreBegin(int in, int out);
    native private void nProgramFragmentStoreDepthFunc(int func);
@@ -307,6 +309,34 @@ public class RenderScript {
        }
    }

    public enum SamplerParam {
        FILTER_MIN (0),
        FILTER_MAG (1),
        WRAP_MODE_S (2),
        WRAP_MODE_T (3),
        WRAP_MODE_R (4);

        int mID;
        SamplerParam(int id) {
            mID = id;
        }
    }

    public enum SamplerValue {
        NEAREST (0),
        LINEAR (1),
        LINEAR_MIP_LINEAR (2),
        WRAP (3),
        CLAMP (4);

        int mID;
        SamplerValue(int id) {
            mID = id;
        }
    }



    public class Element extends BaseObj {
        Element(int id) {
            mID = id;
@@ -727,9 +757,9 @@ public class RenderScript {
            nProgramFragmentBindTexture(mID, slot, va.mID);
        }

        //public void bindSampler(Sampler vs, int slot) {
            //nProgramFragmentBindSampler(mID, slot, vs.mID);
        //}
        public void bindSampler(Sampler vs, int slot) {
            nProgramFragmentBindSampler(mID, slot, vs.mID);
        }
    }

    public void programFragmentBegin(Element in, Element out) {
@@ -761,6 +791,33 @@ public class RenderScript {
        return new ProgramFragment(id);
    }

    //////////////////////////////////////////////////////////////////////////////////
    // Sampler

    public class Sampler extends BaseObj {
        Sampler(int id) {
            mID = id;
        }

        public void destroy() {
            nSamplerDestroy(mID);
            mID = 0;
        }
    }

    public void samplerBegin() {
        nSamplerBegin();
    }

    public void samplerSet(SamplerParam p, SamplerValue v) {
        nSamplerSet(p.mID, v.mID);
    }

    public Sampler samplerCreate() {
        int id = nSamplerCreate();
        return new Sampler(id);
    }


    ///////////////////////////////////////////////////////////////////////////////////
    // Root state
+39 −9
Original line number Diff line number Diff line
@@ -717,14 +717,6 @@ nContextBindRootScript(JNIEnv *_env, jobject _this, jint script)
    rsContextBindRootScript((RsScript)script);
}

static void
nContextBindSampler(JNIEnv *_env, jobject _this, jint sampler, jint slot)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nContextBindSampler, con(%p), sampler(%p), slot(%i)", con, (RsSampler)sampler, slot);
    rsContextBindSampler(slot, (RsSampler)sampler);
}

static void
nContextBindProgramFragmentStore(JNIEnv *_env, jobject _this, jint pfs)
{
@@ -741,6 +733,40 @@ nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf)
    rsContextBindProgramFragment((RsProgramFragment)pf);
}

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

static void
nSamplerDestroy(JNIEnv *_env, jobject _this, jint s)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nSamplerDestroy, con(%p), sampler(%p)", con, (RsSampler)s);
    rsSamplerDestroy((RsSampler)s);
}

static void
nSamplerBegin(JNIEnv *_env, jobject _this)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nSamplerBegin, con(%p)", con);
    rsSamplerBegin();
}

static void
nSamplerSet(JNIEnv *_env, jobject _this, jint p, jint v)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v);
    rsSamplerSet((RsSamplerParam)p, (RsSamplerValue)v);
}

static jint
nSamplerCreate(JNIEnv *_env, jobject _this)
{
    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
    LOG_API("nSamplerCreate, con(%p), script(%p)", con, (RsScript)script);
    return (jint)rsSamplerCreate();
}


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

@@ -825,10 +851,14 @@ static JNINativeMethod methods[] = {
{"nProgramFragmentCreate",         "()I",                                  (void*)nProgramFragmentCreate },

{"nContextBindRootScript",         "(I)V",                                 (void*)nContextBindRootScript },
//{"nContextBindSampler",          "(II)V",                                (void*)nContextBindSampler },
{"nContextBindProgramFragmentStore","(I)V",                                (void*)nContextBindProgramFragmentStore },
{"nContextBindProgramFragment",    "(I)V",                                 (void*)nContextBindProgramFragment },

{"nSamplerDestroy",                "(I)V",                                 (void*)nSamplerDestroy },
{"nSamplerBegin",                  "()V",                                  (void*)nSamplerBegin },
{"nSamplerSet",                    "(II)V",                                (void*)nSamplerSet },
{"nSamplerCreate",                 "()I",                                  (void*)nSamplerCreate },

};

static int registerFuncs(JNIEnv *_env)
+3 −5
Original line number Diff line number Diff line


ContextBindSampler {
	param uint32_t slot
	param RsSampler sampler
	}

ContextBindRootScript {
	param RsScript sampler
	}
@@ -212,6 +207,9 @@ SamplerCreate {
	ret RsSampler
	}

SamplerDestroy {
	param RsSampler s
	}

TriangleMeshBegin {
	param RsElement vertex
+4 −4
Original line number Diff line number Diff line
@@ -62,14 +62,14 @@ void ProgramFragment::setupGL()
            break;
        }

//        if (mSamplers[ct].get()) {
            //mSamplers[ct]->setupGL();
//        } else {
        if (mSamplers[ct].get()) {
            mSamplers[ct]->setupGL();
        } else {
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        //}
        }
    }
    glActiveTexture(GL_TEXTURE0);
}
Loading