diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/renderscript/Program.java | 21 | ||||
-rw-r--r-- | graphics/java/android/renderscript/ProgramFragment.java | 150 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 9 | ||||
-rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 59 |
4 files changed, 88 insertions, 151 deletions
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java index 88b87b0..9d70cb2 100644 --- a/graphics/java/android/renderscript/Program.java +++ b/graphics/java/android/renderscript/Program.java @@ -46,6 +46,27 @@ public class Program extends BaseObj { mRS.nProgramBindConstants(mID, slot, a.mID); } + public void bindTexture(Allocation va, int slot) + throws IllegalArgumentException { + mRS.validate(); + if((slot < 0) || (slot >= mTextureCount)) { + throw new IllegalArgumentException("Slot ID out of range."); + } + + mRS.nProgramBindTexture(mID, slot, va.mID); + } + + public void bindSampler(Sampler vs, int slot) + throws IllegalArgumentException { + mRS.validate(); + if((slot < 0) || (slot >= mTextureCount)) { + throw new IllegalArgumentException("Slot ID out of range."); + } + + mRS.nProgramBindSampler(mID, slot, vs.mID); + } + + public static class BaseProgramBuilder { RenderScript mRS; Element mInputs[]; diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java index f150043..5e04f0c 100644 --- a/graphics/java/android/renderscript/ProgramFragment.java +++ b/graphics/java/android/renderscript/ProgramFragment.java @@ -26,44 +26,10 @@ import android.util.Log; * **/ public class ProgramFragment extends Program { - public static final int MAX_SLOT = 2; - - public enum EnvMode { - REPLACE (0), - MODULATE (1), - DECAL (2); - - int mID; - EnvMode(int id) { - mID = id; - } - } - - ProgramFragment(int id, RenderScript rs) { super(id, rs); } - public void bindTexture(Allocation va, int slot) - throws IllegalArgumentException { - mRS.validate(); - if((slot < 0) || (slot >= MAX_SLOT)) { - throw new IllegalArgumentException("Slot ID out of range."); - } - - mRS.nProgramFragmentBindTexture(mID, slot, va.mID); - } - - public void bindSampler(Sampler vs, int slot) - throws IllegalArgumentException { - mRS.validate(); - if((slot < 0) || (slot >= MAX_SLOT)) { - throw new IllegalArgumentException("Slot ID out of range."); - } - - mRS.nProgramFragmentBindSampler(mID, slot, vs.mID); - } - public static class ShaderBuilder extends BaseProgramBuilder { public ShaderBuilder(RenderScript rs) { super(rs); @@ -97,101 +63,77 @@ public class ProgramFragment extends Program { } public static class Builder { + public static final int MAX_TEXTURE = 2; RenderScript mRS; - Element mIn; - Element mOut; boolean mPointSpriteEnable; - String mShader; - private class Slot { - Type mType; - EnvMode mEnv; - boolean mTexEnable; + public enum EnvMode { + REPLACE (1), + MODULATE (2), + DECAL (3); - Slot() { - mTexEnable = false; + int mID; + EnvMode(int id) { + mID = id; } } - Slot[] mSlots; - public Builder(RenderScript rs, Element in, Element out) { - mRS = rs; - mIn = in; - mOut = out; - mSlots = new Slot[MAX_SLOT]; - mPointSpriteEnable = false; - for(int ct=0; ct < MAX_SLOT; ct++) { - mSlots[ct] = new Slot(); - } - } - - public void setShader(String s) { - mShader = s; - } + public enum Format { + ALPHA (1), + LUMINANCE_ALPHA (2), + RGB (3), + RGBA (4); - public void setType(int slot, Type t) - throws IllegalArgumentException { - if((slot < 0) || (slot >= MAX_SLOT)) { - throw new IllegalArgumentException("Slot ID out of range."); + int mID; + Format(int id) { + mID = id; } - - mSlots[slot].mType = t; } - public void setTexEnable(boolean enable, int slot) - throws IllegalArgumentException { - if((slot < 0) || (slot >= MAX_SLOT)) { - throw new IllegalArgumentException("Slot ID out of range."); + private class Slot { + EnvMode env; + Format format; + Slot(EnvMode _env, Format _fmt) { + env = _env; + format = _fmt; } + } + Slot[] mSlots; - mSlots[slot].mTexEnable = enable; + public Builder(RenderScript rs) { + mRS = rs; + mSlots = new Slot[MAX_TEXTURE]; + mPointSpriteEnable = false; } - public void setTexEnvMode(EnvMode env, int slot) + public void setTexture(EnvMode env, Format fmt, int slot) throws IllegalArgumentException { - if((slot < 0) || (slot >= MAX_SLOT)) { - throw new IllegalArgumentException("Slot ID out of range."); + if((slot < 0) || (slot >= MAX_TEXTURE)) { + throw new IllegalArgumentException("MAX_TEXTURE exceeded."); } - - mSlots[slot].mEnv = env; + mSlots[slot] = new Slot(env, fmt); } public void setPointSpriteTexCoordinateReplacement(boolean enable) { mPointSpriteEnable = enable; } - static synchronized ProgramFragment internalCreate(RenderScript rs, Builder b) { - int inID = 0; - int outID = 0; - if (b.mIn != null) { - inID = b.mIn.mID; - } - if (b.mOut != null) { - outID = b.mOut.mID; - } - rs.nProgramFragmentBegin(inID, outID, b.mPointSpriteEnable); - for(int ct=0; ct < MAX_SLOT; ct++) { - if(b.mSlots[ct].mTexEnable) { - Slot s = b.mSlots[ct]; - int typeID = 0; - if(s.mType != null) { - typeID = s.mType.mID; - } - rs.nProgramFragmentSetSlot(ct, true, s.mEnv.mID, typeID); - } - } - - if (b.mShader != null) { - rs.nProgramFragmentSetShader(b.mShader); - } - - int id = rs.nProgramFragmentCreate(); - return new ProgramFragment(id, rs); - } - public ProgramFragment create() { mRS.validate(); - return internalCreate(mRS, this); + int[] tmp = new int[MAX_TEXTURE * 2 + 1]; + if (mSlots[0] != null) { + tmp[0] = mSlots[0].env.mID; + tmp[1] = mSlots[0].format.mID; + } + if (mSlots[1] != null) { + tmp[2] = mSlots[1].env.mID; + tmp[3] = mSlots[1].format.mID; + } + tmp[4] = mPointSpriteEnable ? 1 : 0; + int id = mRS.nProgramFragmentCreate(tmp); + ProgramFragment pf = new ProgramFragment(id, mRS); + pf.mTextureCount = MAX_TEXTURE; + return pf; } } } diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 0e4d5b0..6574219 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -168,13 +168,10 @@ public class RenderScript { native void nProgramRasterSetPointSize(int pr, float v); native void nProgramBindConstants(int pv, int slot, int mID); + native void nProgramBindTexture(int vpf, int slot, int a); + native void nProgramBindSampler(int vpf, int slot, int s); - native void nProgramFragmentBegin(int in, int out, boolean pointSpriteEnable); - native void nProgramFragmentBindTexture(int vpf, int slot, int a); - native void nProgramFragmentBindSampler(int vpf, int slot, int s); - native void nProgramFragmentSetSlot(int slot, boolean enable, int env, int vt); - native void nProgramFragmentSetShader(String txt); - native int nProgramFragmentCreate(); + native int nProgramFragmentCreate(int[] params); native int nProgramFragmentCreate2(String shader, int[] params); native int nProgramVertexCreate(boolean texMat); diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 8bacefc..6ae93a7 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -1063,56 +1063,36 @@ nProgramBindConstants(JNIEnv *_env, jobject _this, jint vpv, jint slot, jint a) rsProgramBindConstants(con, (RsProgram)vpv, slot, (RsAllocation)a); } -// --------------------------------------------------------------------------- - static void -nProgramFragmentSetShader(JNIEnv *_env, jobject _this, jstring name) +nProgramBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); - const char* n = _env->GetStringUTFChars(name, NULL); - LOG_API("nProgramFragmentSetShader, con(%p)", con); - rsProgramFragmentSetShader(con, n, _env->GetStringUTFLength(name)); - _env->ReleaseStringUTFChars(name, n); + LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a); + rsProgramBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a); } static void -nProgramFragmentBegin(JNIEnv *_env, jobject _this, jint in, jint out, jboolean pointSpriteEnable) +nProgramBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); - LOG_API("nProgramFragmentBegin, con(%p), in(%p), out(%p) PointSprite(%i)", con, (RsElement)in, (RsElement)out, pointSpriteEnable); - rsProgramFragmentBegin(con, (RsElement)in, (RsElement)out, pointSpriteEnable); + LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a); + rsProgramBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a); } -static void -nProgramFragmentBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) -{ - RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); - LOG_API("nProgramFragmentBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a); - rsProgramFragmentBindTexture(con, (RsProgramFragment)vpf, slot, (RsAllocation)a); -} +// --------------------------------------------------------------------------- -static void -nProgramFragmentBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) +static jint +nProgramFragmentCreate(JNIEnv *_env, jobject _this, jintArray params) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); - LOG_API("nProgramFragmentBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a); - rsProgramFragmentBindSampler(con, (RsProgramFragment)vpf, slot, (RsSampler)a); -} + jint *paramPtr = _env->GetIntArrayElements(params, NULL); + jint paramLen = _env->GetArrayLength(params); -static void -nProgramFragmentSetSlot(JNIEnv *_env, jobject _this, jint slot, jboolean enable, jint env, jint vt) -{ - RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); - LOG_API("nProgramFragmentSetType, con(%p), slot(%i), enable(%i), env(%i), vt(%p)", con, slot, enable, env, (RsType)vt); - rsProgramFragmentSetSlot(con, slot, enable, (RsTexEnvMode)env, (RsType)vt); -} + LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, shaderLen, paramLen); -static jint -nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable) -{ - RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); - LOG_API("nProgramFragmentCreate, con(%p)", con); - return (jint)rsProgramFragmentCreate(con); + jint ret = (jint)rsProgramFragmentCreate(con, (uint32_t *)paramPtr, paramLen); + _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); + return ret; } static jint @@ -1455,13 +1435,10 @@ static JNINativeMethod methods[] = { {"nProgramFragmentStoreCreate", "()I", (void*)nProgramFragmentStoreCreate }, {"nProgramBindConstants", "(III)V", (void*)nProgramBindConstants }, +{"nProgramBindTexture", "(III)V", (void*)nProgramBindTexture }, +{"nProgramBindSampler", "(III)V", (void*)nProgramBindSampler }, -{"nProgramFragmentBegin", "(IIZ)V", (void*)nProgramFragmentBegin }, -{"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture }, -{"nProgramFragmentBindSampler", "(III)V", (void*)nProgramFragmentBindSampler }, -{"nProgramFragmentSetSlot", "(IZII)V", (void*)nProgramFragmentSetSlot }, -{"nProgramFragmentSetShader", "(Ljava/lang/String;)V", (void*)nProgramFragmentSetShader }, -{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate }, +{"nProgramFragmentCreate", "([I)I", (void*)nProgramFragmentCreate }, {"nProgramFragmentCreate2", "(Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate2 }, {"nProgramRasterCreate", "(IIZZZ)I", (void*)nProgramRasterCreate }, |