checkpoint pragma support. Includes more cleanup of script enviroment storage to keep the env settings in the base and only the per language state in ScriptC.
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index 8b473ab..5055c39 100644
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ b/libs/rs/java/Fountain/res/raw/fountain.c
@@ -1,5 +1,12 @@
// Fountain test script
+#pragma version(1)
+#pragma stateVertex(orthoWindow)
+#pragma stateRaster(flat)
+#pragma stateFragment(color)
+#pragma stateStore(parent)
+
+
int main(void* con, int ft, int launchID) {
int count, touch, x, y, rate, maxLife, lifeShift;
int life;
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 6a47de13..82d6499 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -57,21 +57,34 @@
eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mHeight);
}
+bool Context::runScript(Script *s)
+{
+ ObjectBaseRef<ProgramFragment> frag(mFragment);
+ ObjectBaseRef<ProgramVertex> vtx(mVertex);
+ ObjectBaseRef<ProgramFragmentStore> store(mFragmentStore);
+
+
+
+ return true;
+
+}
+
+
bool Context::runRootScript()
{
- rsAssert(mRootScript->mIsRoot);
+ rsAssert(mRootScript->mEnviroment.mIsRoot);
glColor4f(1,1,1,1);
glEnable(GL_LIGHT0);
- glViewport(0, 0, 320, 480);
- float aspectH = 480.f / 320.f;
+ glViewport(0, 0, mWidth, mHeight);
- if(mRootScript->mIsOrtho) {
+ if(mRootScript->mEnviroment.mIsOrtho) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrthof(0, 320, 480, 0, 0, 1);
+ glOrthof(0, mWidth, mHeight, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
} else {
+ float aspectH = ((float)mWidth) / mHeight;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustumf(-1, 1, -aspectH, aspectH, 1, 100);
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 64717e4..929c0f9 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -103,11 +103,16 @@
ObjectBaseRef<ProgramVertex> mVertex;
ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
+ ProgramFragment * mDefaultFragment;
+ ProgramVertex * mDefaultVertex;
+ ProgramFragmentStore * mDefaultFragmentStore;
+
private:
Context();
void initEGL();
+ bool runScript(Script *s);
bool runRootScript();
static void * threadProc(void *);
diff --git a/libs/rs/rsObjectBase.h b/libs/rs/rsObjectBase.h
index 7761e49..ca7acda 100644
--- a/libs/rs/rsObjectBase.h
+++ b/libs/rs/rsObjectBase.h
@@ -47,6 +47,16 @@
mRef = NULL;
}
+ ObjectBaseRef(const ObjectBaseRef &ref) {
+ mRef = ref.get();
+ mRef->incRef();
+ }
+
+ ObjectBaseRef(T *ref) {
+ mRef = ref;
+ ref->incRef();
+ }
+
~ObjectBaseRef() {
clear();
}
@@ -77,9 +87,6 @@
protected:
T * mRef;
-private:
- ObjectBaseRef(const ObjectBaseRef &) {};
-
};
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index efe52ad..25a21c1 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -40,10 +40,38 @@
float mClearDepth;
uint32_t mClearStencil;
- bool mUseStateVertex;
- bool mUseStateRaster;
- bool mUseStateFragment;
- bool mUseStateStore;
+ enum StateVertex {
+ VTX_ORTHO_WINDOW,
+ VTX_ORTHO_NORMALIZED,
+ VTX_PROJECTION,
+ VTX_PARENT
+ };
+ StateVertex mStateVertex;
+
+ enum StateRaster {
+ RASTER_FLAT,
+ RASTER_SMOOTH,
+ RASTER_PARENT
+ };
+ StateRaster mStateRaster;
+
+ enum StateFragment {
+ FRAGMENT_COLOR,
+ FRAGMENT_TEX_REPLACE,
+ FRAGMENT_TEX_MODULATE,
+ FRAGMENT_PARENT
+ };
+ StateFragment mStateFragment;
+
+ enum StateFragmentStore {
+ FRAGMENT_STORE_ALWAYS_REPLACE,
+ FRAGMENT_STORE_ALWAYS_BLEND,
+ FRAGMENT_STORE_DEPTH_LESS_REPLACE,
+ FRAGMENT_STORE_DEPTH_LESS_BLEND,
+ FRAGMENT_STORE_PARENT
+ };
+ StateFragmentStore mStateFragmentStore;
+
};
Enviroment_t mEnviroment;
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 91b743c..49d7872 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -434,6 +434,136 @@
accScriptSource(mAccScript, 1, scriptSource, scriptLength);
accCompileScript(mAccScript);
accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript);
+ rsAssert(mProgram.mScript);
+
+ if (mProgram.mScript) {
+ const static int pragmaMax = 16;
+ ACCsizei pragmaCount;
+ ACCchar * str[pragmaMax];
+ accGetPragmas(mAccScript, &pragmaCount, pragmaMax, &str[0]);
+
+ // Start with defaults
+ mEnviroment.mStateVertex =
+ Script::Enviroment_t::VTX_ORTHO_WINDOW;
+ mEnviroment.mStateRaster =
+ Script::Enviroment_t::RASTER_FLAT;
+ mEnviroment.mStateFragment =
+ Script::Enviroment_t::FRAGMENT_COLOR;
+ mEnviroment.mStateFragmentStore =
+ Script::Enviroment_t::FRAGMENT_STORE_ALWAYS_REPLACE;
+
+ for (int ct=0; ct < pragmaCount; ct+=2) {
+ LOGE("pragma %i %s %s", ct, str[ct], str[ct+1]);
+
+ if (!strcmp(str[ct], "version")) {
+ continue;
+
+ }
+
+
+ if (!strcmp(str[ct], "stateVertex")) {
+ if (!strcmp(str[ct+1], "orthoWindow")) {
+ mEnviroment.mStateVertex =
+ Script::Enviroment_t::VTX_ORTHO_WINDOW;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "orthoNormalized")) {
+ mEnviroment.mStateVertex =
+ Script::Enviroment_t::VTX_ORTHO_NORMALIZED;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "projection")) {
+ mEnviroment.mStateVertex =
+ Script::Enviroment_t::VTX_PROJECTION;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "parent")) {
+ mEnviroment.mStateVertex =
+ Script::Enviroment_t::VTX_PARENT;
+ continue;
+ }
+ LOGE("Unreconized value %s passed to stateVertex", str[ct+1]);
+ }
+
+ if (!strcmp(str[ct], "stateRaster")) {
+ if (!strcmp(str[ct+1], "flat")) {
+ mEnviroment.mStateRaster =
+ Script::Enviroment_t::RASTER_FLAT;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "smooth")) {
+ mEnviroment.mStateRaster =
+ Script::Enviroment_t::RASTER_SMOOTH;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "parent")) {
+ mEnviroment.mStateRaster =
+ Script::Enviroment_t::RASTER_PARENT;
+ continue;
+ }
+ LOGE("Unreconized value %s passed to stateRaster", str[ct+1]);
+ }
+
+ if (!strcmp(str[ct], "stateFragment")) {
+ if (!strcmp(str[ct+1], "color")) {
+ mEnviroment.mStateFragment =
+ Script::Enviroment_t::FRAGMENT_COLOR;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "texReplace")) {
+ mEnviroment.mStateFragment =
+ Script::Enviroment_t::FRAGMENT_TEX_REPLACE;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "texModulate")) {
+ mEnviroment.mStateFragment =
+ Script::Enviroment_t::FRAGMENT_TEX_MODULATE;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "parent")) {
+ mEnviroment.mStateFragment =
+ Script::Enviroment_t::FRAGMENT_PARENT;
+ continue;
+ }
+ LOGE("Unreconized value %s passed to stateFragment", str[ct+1]);
+ }
+
+ if (!strcmp(str[ct], "stateFragmentStore")) {
+ if (!strcmp(str[ct+1], "alwaysReplace")) {
+ mEnviroment.mStateFragmentStore =
+ Script::Enviroment_t::FRAGMENT_STORE_ALWAYS_REPLACE;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "alwaysBlend")) {
+ mEnviroment.mStateFragmentStore =
+ Script::Enviroment_t::FRAGMENT_STORE_ALWAYS_BLEND;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "depthLessReplace")) {
+ mEnviroment.mStateFragmentStore =
+ Script::Enviroment_t::FRAGMENT_STORE_DEPTH_LESS_REPLACE;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "depthLessBlend")) {
+ mEnviroment.mStateFragmentStore =
+ Script::Enviroment_t::FRAGMENT_STORE_DEPTH_LESS_BLEND;
+ continue;
+ }
+ if (!strcmp(str[ct+1], "parent")) {
+ mEnviroment.mStateFragmentStore =
+ Script::Enviroment_t::FRAGMENT_STORE_PARENT;
+ continue;
+ }
+ LOGE("Unreconized value %s passed to stateFragmentStore", str[ct+1]);
+ }
+
+ }
+
+
+ } else {
+ // Deal with an error.
+ }
+
}
namespace android {
@@ -511,6 +641,7 @@
s->mEnviroment = ss->mEnviroment;
s->mProgram = ss->mProgram;
ss->clear();
+
return s;
}
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index 892d21e..d178c86 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -69,7 +69,7 @@
ACCscript* mAccScript;
ScriptC::Program_t mProgram;
- ScriptC::Enviroment_t mEnviroment;
+ Script::Enviroment_t mEnviroment;
Vector<const Type *> mConstantBufferTypes;