Let java put #defines into renderscript
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index efe6ff7..3343db5 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -104,6 +104,8 @@
mAccScript = NULL;
+ mInt32Defines.clear();
+ mFloatDefines.clear();
}
static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name)
@@ -123,6 +125,8 @@
rsc->appendNameDefines(&tmp);
appendDecls(&tmp);
+ rsc->appendVarDefines(&tmp);
+ appendVarDefines(&tmp);
tmp.append("#line 1\n");
const char* scriptSource[] = {tmp.string(), mProgram.mScriptText};
@@ -138,7 +142,6 @@
ACCsizei len;
accGetScriptInfoLog(mAccScript, sizeof(buf), &len, buf);
LOGE(buf);
-
}
mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
@@ -215,9 +218,31 @@
} else {
// Deal with an error.
}
-
}
+
+void ScriptCState::appendVarDefines(String8 *str)
+{
+ char buf[256];
+ LOGD("appendVarDefines mInt32Defines.size()=%d mFloatDefines.size()=%d\n",
+ mInt32Defines.size(), mFloatDefines.size());
+ for (size_t ct=0; ct < mInt32Defines.size(); ct++) {
+ str->append("#define ");
+ str->append(mInt32Defines.keyAt(ct));
+ str->append(" ");
+ sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct));
+ str->append(buf);
+ }
+ for (size_t ct=0; ct < mFloatDefines.size(); ct++) {
+ str->append("#define ");
+ str->append(mFloatDefines.keyAt(ct));
+ str->append(" ");
+ sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct));
+ str->append(buf);
+ }
+}
+
+
namespace android {
namespace renderscript {
@@ -270,6 +295,18 @@
return s;
}
+void rsi_ScriptCSetDefineF(Context *rsc, const char* name, float value)
+{
+ ScriptCState *ss = &rsc->mScriptC;
+ ss->mFloatDefines.add(String8(name), value);
+}
+
+void rsi_ScriptCSetDefineI32(Context *rsc, const char* name, int32_t value)
+{
+ ScriptCState *ss = &rsc->mScriptC;
+ ss->mInt32Defines.add(String8(name), value);
+}
+
}
}