diff options
| author | Jason Sams <rjsams@android.com> | 2009-05-28 15:37:57 -0700 |
|---|---|---|
| committer | Jason Sams <rjsams@android.com> | 2009-05-28 16:16:46 -0700 |
| commit | 02fb2cb531035779a25dbf9595e0628ea40585b0 (patch) | |
| tree | c8151779dd70e8242412a327add168a0e5444a4e /libs/rs | |
| parent | 206b83190708738552be7760acfeefa1143555b5 (diff) | |
| download | frameworks_base-02fb2cb531035779a25dbf9595e0628ea40585b0.zip frameworks_base-02fb2cb531035779a25dbf9595e0628ea40585b0.tar.gz frameworks_base-02fb2cb531035779a25dbf9595e0628ea40585b0.tar.bz2 | |
Add sampler support
Diffstat (limited to 'libs/rs')
| -rw-r--r-- | libs/rs/java/Fountain/src/com/android/fountain/FountainView.java | 8 | ||||
| -rw-r--r-- | libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java | 69 | ||||
| -rw-r--r-- | libs/rs/jni/RenderScript_jni.cpp | 48 | ||||
| -rw-r--r-- | libs/rs/rs.spec | 8 | ||||
| -rw-r--r-- | libs/rs/rsProgramFragment.cpp | 8 | ||||
| -rw-r--r-- | libs/rs/rsSampler.cpp | 24 |
6 files changed, 140 insertions, 25 deletions
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java index bc34080..3381525 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java @@ -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; diff --git a/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java b/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java index 739f9ae..cf16cec 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java @@ -38,7 +38,7 @@ public class RenderScript { - /* + /* * We use a class initializer to allow the native code to cache some * field offsets. */ @@ -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 diff --git a/libs/rs/jni/RenderScript_jni.cpp b/libs/rs/jni/RenderScript_jni.cpp index 50849af..4af58a6 100644 --- a/libs/rs/jni/RenderScript_jni.cpp +++ b/libs/rs/jni/RenderScript_jni.cpp @@ -718,14 +718,6 @@ nContextBindRootScript(JNIEnv *_env, jobject _this, jint 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) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); @@ -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) diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index 98c7008..090be32 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -1,10 +1,5 @@ -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 diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp index 1a6e2c7..3d316ea 100644 --- a/libs/rs/rsProgramFragment.cpp +++ b/libs/rs/rsProgramFragment.cpp @@ -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); } diff --git a/libs/rs/rsSampler.cpp b/libs/rs/rsSampler.cpp index 3c008c9..ca407db 100644 --- a/libs/rs/rsSampler.cpp +++ b/libs/rs/rsSampler.cpp @@ -53,7 +53,21 @@ Sampler::~Sampler() void Sampler::setupGL() { + GLenum translate[] = { + GL_NEAREST, //RS_SAMPLER_NEAREST, + GL_LINEAR, //RS_SAMPLER_LINEAR, + GL_LINEAR_MIP_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR, + GL_WRAP, //RS_SAMPLER_WRAP, + GL_CLAMP_TO_EDGS, //RS_SAMPLER_CLAMP + + } + + //LOGE("setup gl"); + switch(mMagFilter) { + case RS_SAMPLER_ + } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -76,7 +90,7 @@ void Sampler::unbindFromContext(SamplerState *ss) void SamplerState::setupGL() { - for (uint32_t ct=0; ct < 1/*RS_MAX_SAMPLER_SLOT*/; ct++) { + for (uint32_t ct=0; ct < RS_MAX_SAMPLER_SLOT; ct++) { Sampler *s = mSamplers[ct].get(); if (s) { s->setupGL(); @@ -140,4 +154,12 @@ RsSampler rsi_SamplerCreate(Context *rsc) return s; } +void rsi_SamplerDestroy(Context *rsc, RsSampler vs) +{ + Sampler * s = static_cast<Sampler *>(vs); + s->decRef(); + +} + + }} |
