summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-12-17 16:55:08 -0800
committerJason Sams <rjsams@android.com>2009-12-17 16:55:08 -0800
commit68afd01ec9fd37774d8291192952a25e5605b6fb (patch)
treeb75c5b23b57446285d9c14a5d789722b916ea1e8
parent8bb41dd61474e977aa61048ba8f733a984a3b22d (diff)
downloadframeworks_base-68afd01ec9fd37774d8291192952a25e5605b6fb.zip
frameworks_base-68afd01ec9fd37774d8291192952a25e5605b6fb.tar.gz
frameworks_base-68afd01ec9fd37774d8291192952a25e5605b6fb.tar.bz2
Move texture bindings to base program object. Change ProgramFragment creation to require a texture format in 1.0 mode.
-rw-r--r--graphics/java/android/renderscript/Program.java21
-rw-r--r--graphics/java/android/renderscript/ProgramFragment.java150
-rw-r--r--graphics/java/android/renderscript/RenderScript.java9
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp59
-rw-r--r--libs/rs/RenderScript.h1
-rw-r--r--libs/rs/java/Film/src/com/android/film/FilmRS.java8
-rw-r--r--libs/rs/rs.spec23
-rw-r--r--libs/rs/rsProgram.cpp35
-rw-r--r--libs/rs/rsProgram.h13
-rw-r--r--libs/rs/rsProgramFragment.cpp148
-rw-r--r--libs/rs/rsProgramFragment.h29
-rw-r--r--libs/rs/rsScriptC_Lib.cpp20
12 files changed, 190 insertions, 326 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 },
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 44ff901..d10eeda 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -158,6 +158,7 @@ enum RsBlendDstFunc {
};
enum RsTexEnvMode {
+ RS_TEX_ENV_MODE_NONE,
RS_TEX_ENV_MODE_REPLACE,
RS_TEX_ENV_MODE_MODULATE,
RS_TEX_ENV_MODE_DECAL
diff --git a/libs/rs/java/Film/src/com/android/film/FilmRS.java b/libs/rs/java/Film/src/com/android/film/FilmRS.java
index 3b93c18..dccc1d2 100644
--- a/libs/rs/java/Film/src/com/android/film/FilmRS.java
+++ b/libs/rs/java/Film/src/com/android/film/FilmRS.java
@@ -121,13 +121,13 @@ public class FilmRS {
bs.setWrapT(Sampler.Value.WRAP);
mSampler = bs.create();
- ProgramFragment.Builder b = new ProgramFragment.Builder(mRS, null, null);
-
+ ProgramFragment.Builder b = new ProgramFragment.Builder(mRS);
mPFBackground = b.create();
mPFBackground.setName("PFBackground");
- b.setTexEnable(true, 0);
- b.setTexEnvMode(ProgramFragment.EnvMode.REPLACE, 0);
+ b = new ProgramFragment.Builder(mRS);
+ b.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
+ ProgramFragment.Builder.Format.RGBA, 0);
mPFImages = b.create();
mPFImages.bindSampler(mSampler, 0);
mPFImages.setName("PFImages");
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 5de76b2..df415685 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -372,37 +372,22 @@ ProgramBindConstants {
param RsAllocation constants
}
-ProgramFragmentBegin {
- param RsElement in
- param RsElement out
- param bool pointSpriteEnable
- }
-
-ProgramFragmentSetShader {
- param const char * text
- param uint32_t length
- }
-ProgramFragmentBindTexture {
+ProgramBindTexture {
param RsProgramFragment pf
param uint32_t slot
param RsAllocation a
}
-ProgramFragmentBindSampler {
+ProgramBindSampler {
param RsProgramFragment pf
param uint32_t slot
param RsSampler s
}
-ProgramFragmentSetSlot {
- param uint32_t slot
- param bool enable
- param RsTexEnvMode env
- param RsType t
- }
-
ProgramFragmentCreate {
+ param const uint32_t * params
+ param uint32_t paramLength
ret RsProgramFragment
}
diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp
index e6d1e36..ede8c86 100644
--- a/libs/rs/rsProgram.cpp
+++ b/libs/rs/rsProgram.cpp
@@ -121,6 +121,30 @@ void Program::bindAllocation(Allocation *alloc)
mDirty = true;
}
+void Program::bindTexture(uint32_t slot, Allocation *a)
+{
+ if (slot >= MAX_TEXTURE) {
+ LOGE("Attempt to bind a texture to a slot > MAX_TEXTURE");
+ return;
+ }
+
+ //LOGE("bindtex %i %p", slot, a);
+ mTextures[slot].set(a);
+ mDirty = true;
+}
+
+void Program::bindSampler(uint32_t slot, Sampler *s)
+{
+ if (slot >= MAX_TEXTURE) {
+ LOGE("Attempt to bind a Sampler to a slot > MAX_TEXTURE");
+ return;
+ }
+
+ mSamplers[slot].set(s);
+ mDirty = true;
+}
+
+
void Program::createShader()
{
}
@@ -182,6 +206,17 @@ void rsi_ProgramBindConstants(Context *rsc, RsProgram vp, uint32_t slot, RsAlloc
p->bindAllocation(static_cast<Allocation *>(constants));
}
+void rsi_ProgramBindTexture(Context *rsc, RsProgram vpf, uint32_t slot, RsAllocation a)
+{
+ Program *p = static_cast<Program *>(vpf);
+ p->bindTexture(slot, static_cast<Allocation *>(a));
+}
+
+void rsi_ProgramBindSampler(Context *rsc, RsProgram vpf, uint32_t slot, RsSampler s)
+{
+ Program *p = static_cast<Program *>(vpf);
+ p->bindSampler(slot, static_cast<Sampler *>(s));
+}
}
}
diff --git a/libs/rs/rsProgram.h b/libs/rs/rsProgram.h
index 003498e..25a5434 100644
--- a/libs/rs/rsProgram.h
+++ b/libs/rs/rsProgram.h
@@ -32,6 +32,7 @@ class Program : public ObjectBase
public:
const static uint32_t MAX_ATTRIBS = 8;
const static uint32_t MAX_UNIFORMS = 16;
+ const static uint32_t MAX_TEXTURE = 2;
Program(Context *);
Program(Context *, const char * shaderText, uint32_t shaderLength,
@@ -41,6 +42,9 @@ public:
void bindAllocation(Allocation *);
virtual void createShader();
+ void bindTexture(uint32_t slot, Allocation *);
+ void bindSampler(uint32_t slot, Sampler *);
+
uint32_t getShaderID() const {return mShaderID;}
void setShader(const char *, uint32_t len);
@@ -72,6 +76,15 @@ protected:
String8 mAttribNames[MAX_ATTRIBS];
String8 mUniformNames[MAX_UNIFORMS];
+ // The difference between Textures and Constants is how they are accessed
+ // Texture lookups go though a sampler which in effect converts normalized
+ // coordinates into type specific. Multiple samples may also be taken
+ // and filtered.
+ //
+ // Constants are strictly accessed by programetic loads.
+ ObjectBaseRef<Allocation> mTextures[MAX_TEXTURE];
+ ObjectBaseRef<Sampler> mSamplers[MAX_TEXTURE];
+
bool loadShader(Context *, uint32_t type);
public:
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index c353301..05672e5 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -26,18 +26,28 @@ using namespace android;
using namespace android::renderscript;
-ProgramFragment::ProgramFragment(Context *rsc, Element *in, Element *out, bool pointSpriteEnable) :
+ProgramFragment::ProgramFragment(Context *rsc, const uint32_t * params,
+ uint32_t paramLength) :
Program(rsc)
{
mAllocFile = __FILE__;
mAllocLine = __LINE__;
- for (uint32_t ct=0; ct < MAX_TEXTURE; ct++) {
- mEnvModes[ct] = RS_TEX_ENV_MODE_REPLACE;
- mTextureDimensions[ct] = 2;
- }
+ rsAssert(paramLength = 5);
+
+ mEnvModes[0] = (RsTexEnvMode)params[0];
+ mTextureFormats[0] = params[1];
+ mEnvModes[1] = (RsTexEnvMode)params[2];
+ mTextureFormats[1] = params[3];
+ mPointSpriteEnable = params[4] != 0;
+
mTextureEnableMask = 0;
- mPointSpriteEnable = pointSpriteEnable;
- mEnvModes[1] = RS_TEX_ENV_MODE_DECAL;
+ if (mEnvModes[0]) {
+ mTextureEnableMask |= 1;
+ }
+ if (mEnvModes[1]) {
+ mTextureEnableMask |= 2;
+ }
+ init(rsc);
}
ProgramFragment::ProgramFragment(Context *rsc, const char * shaderText,
@@ -84,6 +94,9 @@ void ProgramFragment::setupGL(const Context *rsc, ProgramFragmentState *state)
glBindTexture(GL_TEXTURE_2D, mTextures[ct]->getTextureID());
switch(mEnvModes[ct]) {
+ case RS_TEX_ENV_MODE_NONE:
+ rsAssert(0);
+ break;
case RS_TEX_ENV_MODE_REPLACE:
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
break;
@@ -211,6 +224,9 @@ void ProgramFragment::createShader()
while (mask) {
if (mask & 1) {
switch(mEnvModes[texNum]) {
+ case RS_TEX_ENV_MODE_NONE:
+ rsAssert(0);
+ break;
case RS_TEX_ENV_MODE_REPLACE:
mShader.append(" col = texture2D(uni_Tex0, tex0);\n");
break;
@@ -235,69 +251,6 @@ void ProgramFragment::createShader()
}
}
-void ProgramFragment::bindTexture(uint32_t slot, Allocation *a)
-{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to bind a texture to a slot > MAX_TEXTURE");
- return;
- }
-
- //LOGE("bindtex %i %p", slot, a);
- mTextures[slot].set(a);
- mDirty = true;
-}
-
-void ProgramFragment::bindSampler(uint32_t slot, Sampler *s)
-{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to bind a Sampler to a slot > MAX_TEXTURE");
- return;
- }
-
- mSamplers[slot].set(s);
- mDirty = true;
-}
-
-void ProgramFragment::setType(uint32_t slot, const Element *e, uint32_t dim)
-{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to setType to a slot > MAX_TEXTURE");
- return;
- }
-
- if (dim >= 4) {
- LOGE("Attempt to setType to a dimension > 3");
- return;
- }
-
- mTextureFormats[slot].set(e);
- mTextureDimensions[slot] = dim;
-}
-
-void ProgramFragment::setEnvMode(uint32_t slot, RsTexEnvMode env)
-{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to setEnvMode to a slot > MAX_TEXTURE");
- return;
- }
-
- mEnvModes[slot] = env;
-}
-
-void ProgramFragment::setTexEnable(uint32_t slot, bool enable)
-{
- if (slot >= MAX_TEXTURE) {
- LOGE("Attempt to setEnvMode to a slot > MAX_TEXTURE");
- return;
- }
-
- uint32_t bit = 1 << slot;
- mTextureEnableMask &= ~bit;
- if (enable) {
- mTextureEnableMask |= bit;
- }
-}
-
void ProgramFragment::init(Context *rsc)
{
mUniformCount = 2;
@@ -320,7 +273,12 @@ ProgramFragmentState::~ProgramFragmentState()
void ProgramFragmentState::init(Context *rsc, int32_t w, int32_t h)
{
- ProgramFragment *pf = new ProgramFragment(rsc, NULL, NULL, false);
+ uint32_t tmp[5] = {
+ RS_TEX_ENV_MODE_NONE, 0,
+ RS_TEX_ENV_MODE_NONE, 0,
+ 0
+ };
+ ProgramFragment *pf = new ProgramFragment(rsc, tmp, 5);
mDefault.set(pf);
pf->init(rsc);
}
@@ -335,52 +293,12 @@ void ProgramFragmentState::deinit(Context *rsc)
namespace android {
namespace renderscript {
-void rsi_ProgramFragmentBegin(Context * rsc, RsElement in, RsElement out, bool pointSpriteEnable)
+RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc,
+ const uint32_t * params,
+ uint32_t paramLength)
{
- delete rsc->mStateFragment.mPF;
- rsc->mStateFragment.mPF = new ProgramFragment(rsc, (Element *)in, (Element *)out, pointSpriteEnable);
-}
-
-void rsi_ProgramFragmentBindTexture(Context *rsc, RsProgramFragment vpf, uint32_t slot, RsAllocation a)
-{
- ProgramFragment *pf = static_cast<ProgramFragment *>(vpf);
- pf->bindTexture(slot, static_cast<Allocation *>(a));
-}
-
-void rsi_ProgramFragmentBindSampler(Context *rsc, RsProgramFragment vpf, uint32_t slot, RsSampler s)
-{
- ProgramFragment *pf = static_cast<ProgramFragment *>(vpf);
- pf->bindSampler(slot, static_cast<Sampler *>(s));
-}
-
-void rsi_ProgramFragmentSetSlot(Context *rsc, uint32_t slot, bool enable, RsTexEnvMode env, RsType vt)
-{
- const Type *t = static_cast<const Type *>(vt);
- if (t) {
- uint32_t dim = 1;
- if (t->getDimY()) {
- dim ++;
- if (t->getDimZ()) {
- dim ++;
- }
- }
- rsc->mStateFragment.mPF->setType(slot, t->getElement(), dim);
- }
- rsc->mStateFragment.mPF->setEnvMode(slot, env);
- rsc->mStateFragment.mPF->setTexEnable(slot, enable);
-}
-
-void rsi_ProgramFragmentSetShader(Context *rsc, const char *txt, uint32_t len)
-{
- rsc->mStateFragment.mPF->setShader(txt, len);
-}
-
-RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc)
-{
- ProgramFragment *pf = rsc->mStateFragment.mPF;
+ ProgramFragment *pf = new ProgramFragment(rsc, params, paramLength);
pf->incUserRef();
- pf->init(rsc);
- rsc->mStateFragment.mPF = 0;
return pf;
}
diff --git a/libs/rs/rsProgramFragment.h b/libs/rs/rsProgramFragment.h
index 14b4ec3..9fa565d 100644
--- a/libs/rs/rsProgramFragment.h
+++ b/libs/rs/rsProgramFragment.h
@@ -28,11 +28,7 @@ class ProgramFragmentState;
class ProgramFragment : public Program
{
public:
- const static uint32_t MAX_TEXTURE = 2;
-
-
-
- ProgramFragment(Context *, Element *in, Element *out, bool pointSpriteEnable);
+ ProgramFragment(Context *, const uint32_t * params, uint32_t paramLength);
ProgramFragment(Context *rsc, const char * shaderText,
uint32_t shaderLength, const uint32_t * params,
uint32_t paramLength);
@@ -41,33 +37,14 @@ public:
virtual void setupGL(const Context *, ProgramFragmentState *);
virtual void setupGL2(const Context *, ProgramFragmentState *, ShaderCache *sc);
-
- void bindTexture(uint32_t slot, Allocation *);
- void bindSampler(uint32_t slot, Sampler *);
- void setType(uint32_t slot, const Element *, uint32_t dim);
-
- void setEnvMode(uint32_t slot, RsTexEnvMode);
- void setTexEnable(uint32_t slot, bool);
-
virtual void createShader();
virtual void loadShader(Context *rsc);
virtual void init(Context *rsc);
-
protected:
- // The difference between Textures and Constants is how they are accessed
- // Texture lookups go though a sampler which in effect converts normalized
- // coordinates into type specific. Multiple samples may also be taken
- // and filtered.
- //
- // Constants are strictly accessed by programetic loads.
- ObjectBaseRef<Allocation> mTextures[MAX_TEXTURE];
- ObjectBaseRef<Sampler> mSamplers[MAX_TEXTURE];
- ObjectBaseRef<const Element> mTextureFormats[MAX_TEXTURE];
- uint32_t mTextureDimensions[MAX_TEXTURE];
-
-
// Hacks to create a program for now
+ uint32_t mTextureFormats[MAX_TEXTURE];
+ uint32_t mTextureDimensions[MAX_TEXTURE];
RsTexEnvMode mEnvModes[MAX_TEXTURE];
uint32_t mTextureEnableMask;
bool mPointSpriteEnable;
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index ade136c..e9f47d6 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -619,20 +619,20 @@ static void SC_vec2Rand(float *vec, float maxLen)
static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
{
GET_TLS();
- rsi_ProgramFragmentBindTexture(rsc,
- static_cast<ProgramFragment *>(vpf),
- slot,
- static_cast<Allocation *>(va));
+ rsi_ProgramBindTexture(rsc,
+ static_cast<ProgramFragment *>(vpf),
+ slot,
+ static_cast<Allocation *>(va));
}
static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
{
GET_TLS();
- rsi_ProgramFragmentBindSampler(rsc,
- static_cast<ProgramFragment *>(vpf),
- slot,
- static_cast<Sampler *>(vs));
+ rsi_ProgramBindSampler(rsc,
+ static_cast<ProgramFragment *>(vpf),
+ slot,
+ static_cast<Sampler *>(vs));
}
@@ -846,9 +846,7 @@ static void SC_color(float r, float g, float b, float a)
rsc->mStateVertex.color[1] = g;
rsc->mStateVertex.color[2] = b;
rsc->mStateVertex.color[3] = a;
- if (rsc->checkVersion2_0()) {
- glVertexAttrib4f(1, r, g, b, a);
- } else {
+ if (!rsc->checkVersion2_0()) {
glColor4f(r, g, b, a);
}
}