Merge change 4533
* changes: Implement default programs and implement defaults and parents for imports.
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
// Fountain test script
|
||||
|
||||
#pragma version(1)
|
||||
#pragma stateVertex(orthoWindow)
|
||||
#pragma stateRaster(flat)
|
||||
#pragma stateVertex(default)
|
||||
#pragma stateFragment(PgmFragBackground)
|
||||
#pragma stateFragmentStore(MyBlend)
|
||||
#pragma stateFragmentStore(parent)
|
||||
|
||||
|
||||
int main(void* con, int ft, int launchID) {
|
||||
|
||||
@@ -58,10 +58,8 @@ public class FountainRS {
|
||||
private RenderScript.ProgramFragmentStore mPFS;
|
||||
private RenderScript.ProgramFragment mPF;
|
||||
private RenderScript.ProgramFragment mPF2;
|
||||
private RenderScript.ProgramVertex mPV;
|
||||
private RenderScript.Allocation mTexture;
|
||||
private RenderScript.Sampler mSampler;
|
||||
private ProgramVertexAlloc mPVA;
|
||||
|
||||
private Bitmap mBackground;
|
||||
|
||||
@@ -110,15 +108,6 @@ public class FountainRS {
|
||||
mPF2.bindSampler(mSampler, 0);
|
||||
mPF2.setName("PgmFragBackground");
|
||||
|
||||
mRS.programVertexBegin(null, null);
|
||||
mPV = mRS.programVertexCreate();
|
||||
mPVA = new ProgramVertexAlloc(mRS);
|
||||
mPV.bindAllocation(0, mPVA.mAlloc);
|
||||
mPVA.setupOrthoWindow(320, 480);
|
||||
mRS.contextBindProgramVertex(mPV);
|
||||
|
||||
|
||||
|
||||
|
||||
mParams[0] = 0;
|
||||
mParams[1] = partCount;
|
||||
|
||||
@@ -119,6 +119,14 @@ void * Context::threadProc(void *vrsc)
|
||||
rsc->mServerReturns.init(128);
|
||||
|
||||
rsc->initEGL();
|
||||
|
||||
rsc->mStateVertex.init(rsc, rsc->mWidth, rsc->mHeight);
|
||||
rsc->setVertex(NULL);
|
||||
rsc->mStateFragment.init(rsc, rsc->mWidth, rsc->mHeight);
|
||||
rsc->setFragment(NULL);
|
||||
rsc->mStateFragmentStore.init(rsc, rsc->mWidth, rsc->mHeight);
|
||||
rsc->setFragmentStore(NULL);
|
||||
|
||||
rsc->mRunning = true;
|
||||
bool mDraw = true;
|
||||
while (!rsc->mExit) {
|
||||
@@ -212,20 +220,32 @@ void Context::setRootScript(Script *s)
|
||||
|
||||
void Context::setFragmentStore(ProgramFragmentStore *pfs)
|
||||
{
|
||||
mFragmentStore.set(pfs);
|
||||
pfs->setupGL();
|
||||
if (pfs == NULL) {
|
||||
mFragmentStore.set(mStateFragmentStore.mDefault);
|
||||
} else {
|
||||
mFragmentStore.set(pfs);
|
||||
}
|
||||
mFragmentStore->setupGL();
|
||||
}
|
||||
|
||||
void Context::setFragment(ProgramFragment *pf)
|
||||
{
|
||||
mFragment.set(pf);
|
||||
pf->setupGL();
|
||||
if (pf == NULL) {
|
||||
mFragment.set(mStateFragment.mDefault);
|
||||
} else {
|
||||
mFragment.set(pf);
|
||||
}
|
||||
mFragment->setupGL();
|
||||
}
|
||||
|
||||
void Context::setVertex(ProgramVertex *pv)
|
||||
{
|
||||
mVertex.set(pv);
|
||||
pv->setupGL();
|
||||
if (pv == NULL) {
|
||||
mVertex.set(mStateVertex.mDefault);
|
||||
} else {
|
||||
mVertex.set(pv);
|
||||
}
|
||||
mVertex->setupGL();
|
||||
}
|
||||
|
||||
void Context::assignName(ObjectBase *obj, const char *name, uint32_t len)
|
||||
|
||||
@@ -81,6 +81,17 @@ public:
|
||||
ObjectBase * lookupName(const char *name) const;
|
||||
void appendNameDefines(String8 *str) const;
|
||||
|
||||
|
||||
ProgramFragment * getDefaultProgramFragment() const {
|
||||
return mStateFragment.mDefault.get();
|
||||
}
|
||||
ProgramVertex * getDefaultProgramVertex() const {
|
||||
return mStateVertex.mDefault.get();
|
||||
}
|
||||
ProgramFragmentStore * getDefaultProgramFragmentStore() const {
|
||||
return mStateFragmentStore.mDefault.get();
|
||||
}
|
||||
|
||||
protected:
|
||||
Device *mDev;
|
||||
|
||||
@@ -107,10 +118,6 @@ protected:
|
||||
ObjectBaseRef<ProgramVertex> mVertex;
|
||||
ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
|
||||
|
||||
ProgramFragment * mDefaultFragment;
|
||||
ProgramVertex * mDefaultVertex;
|
||||
ProgramFragmentStore * mDefaultFragmentStore;
|
||||
|
||||
private:
|
||||
Context();
|
||||
|
||||
|
||||
@@ -136,4 +136,26 @@ void Matrix::loadMultiply(const Matrix *lhs, const Matrix *rhs)
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix::loadOrtho(float l, float r, float b, float t, float n, float f) {
|
||||
loadIdentity();
|
||||
m[0] = 2 / (r - l);
|
||||
m[5] = 2 / (t - b);
|
||||
m[10]= -2 / (f - n);
|
||||
m[12]= -(r + l) / (r - l);
|
||||
m[13]= -(t + b) / (t - b);
|
||||
m[14]= -(f + n) / (f - n);
|
||||
}
|
||||
|
||||
void Matrix::loadFrustum(float l, float r, float b, float t, float n, float f) {
|
||||
loadIdentity();
|
||||
m[0] = 2 * n / (r - l);
|
||||
m[5] = 2 * n / (t - b);
|
||||
m[8] = (r + l) / (r - l);
|
||||
m[9] = (t + b) / (t - b);
|
||||
m[10]= -(f + n) / (f - n);
|
||||
m[11]= -1;
|
||||
m[14]= -2*f*n / (f - n);
|
||||
m[15]= 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ struct Matrix
|
||||
void loadTranslate(float x, float y, float z);
|
||||
void loadMultiply(const Matrix *lhs, const Matrix *rhs);
|
||||
|
||||
void loadOrtho(float l, float r, float b, float t, float n, float f);
|
||||
void loadFrustum(float l, float r, float b, float t, float n, float f);
|
||||
|
||||
void multiply(const Matrix *rhs) {
|
||||
Matrix tmp;
|
||||
tmp.loadMultiply(this, rhs);
|
||||
|
||||
@@ -148,6 +148,11 @@ ProgramFragmentState::~ProgramFragmentState()
|
||||
|
||||
}
|
||||
|
||||
void ProgramFragmentState::init(Context *rsc, int32_t w, int32_t h)
|
||||
{
|
||||
ProgramFragment *pf = new ProgramFragment(NULL, NULL);
|
||||
mDefault.set(pf);
|
||||
}
|
||||
|
||||
|
||||
namespace android {
|
||||
|
||||
@@ -82,9 +82,10 @@ public:
|
||||
~ProgramFragmentState();
|
||||
|
||||
ProgramFragment *mPF;
|
||||
void init(Context *rsc, int32_t w, int32_t h);
|
||||
|
||||
ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE];
|
||||
|
||||
ObjectBaseRef<ProgramFragment> mDefault;
|
||||
Vector<ProgramFragment *> mPrograms;
|
||||
};
|
||||
|
||||
|
||||
@@ -201,6 +201,12 @@ ProgramFragmentStoreState::~ProgramFragmentStoreState()
|
||||
|
||||
}
|
||||
|
||||
void ProgramFragmentStoreState::init(Context *rsc, int32_t w, int32_t h)
|
||||
{
|
||||
ProgramFragmentStore *pfs = new ProgramFragmentStore(NULL, NULL);
|
||||
mDefault.set(pfs);
|
||||
}
|
||||
|
||||
|
||||
namespace android {
|
||||
namespace renderscript {
|
||||
|
||||
@@ -74,7 +74,9 @@ class ProgramFragmentStoreState
|
||||
public:
|
||||
ProgramFragmentStoreState();
|
||||
~ProgramFragmentStoreState();
|
||||
void init(Context *rsc, int32_t w, int32_t h);
|
||||
|
||||
ObjectBaseRef<ProgramFragmentStore> mDefault;
|
||||
ProgramFragmentStore *mPFS;
|
||||
};
|
||||
|
||||
|
||||
@@ -81,6 +81,23 @@ ProgramVertexState::~ProgramVertexState()
|
||||
delete mPV;
|
||||
}
|
||||
|
||||
void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h)
|
||||
{
|
||||
ProgramVertex *pv = new ProgramVertex(NULL, NULL);
|
||||
Allocation *alloc = (Allocation *)
|
||||
rsi_AllocationCreatePredefSized(rsc, RS_ELEMENT_USER_FLOAT, 48);
|
||||
mDefaultAlloc.set(alloc);
|
||||
mDefault.set(pv);
|
||||
|
||||
pv->bindAllocation(0, alloc);
|
||||
|
||||
Matrix m;
|
||||
m.loadOrtho(0,w, h,0, -1,1);
|
||||
alloc->subData(RS_PROGRAM_VERTEX_PROJECTION_OFFSET, 16, &m.m[0]);
|
||||
|
||||
m.loadIdentity();
|
||||
alloc->subData(RS_PROGRAM_VERTEX_MODELVIEW_OFFSET, 16, &m.m[0]);
|
||||
}
|
||||
|
||||
|
||||
namespace android {
|
||||
|
||||
@@ -57,6 +57,11 @@ public:
|
||||
ProgramVertexState();
|
||||
~ProgramVertexState();
|
||||
|
||||
void init(Context *rsc, int32_t w, int32_t h);
|
||||
|
||||
ObjectBaseRef<ProgramVertex> mDefault;
|
||||
ObjectBaseRef<Allocation> mDefaultAlloc;
|
||||
|
||||
ProgramVertex *mPV;
|
||||
|
||||
//ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE];
|
||||
|
||||
@@ -398,6 +398,9 @@ bool ScriptC::run(Context *rsc, uint32_t launchID)
|
||||
if (mEnviroment.mFragment.get()) {
|
||||
rsc->setFragment(mEnviroment.mFragment.get());
|
||||
}
|
||||
if (mEnviroment.mVertex.get()) {
|
||||
rsc->setVertex(mEnviroment.mVertex.get());
|
||||
}
|
||||
|
||||
return mProgram.mScript(&e, &scriptCPtrTable, launchID) != 0;
|
||||
}
|
||||
@@ -448,6 +451,9 @@ void ScriptCState::runCompiler(Context *rsc)
|
||||
accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript);
|
||||
rsAssert(mProgram.mScript);
|
||||
|
||||
mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
|
||||
mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
|
||||
mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore());
|
||||
|
||||
if (mProgram.mScript) {
|
||||
const static int pragmaMax = 16;
|
||||
@@ -465,6 +471,18 @@ void ScriptCState::runCompiler(Context *rsc)
|
||||
|
||||
|
||||
if (!strcmp(str[ct], "stateVertex")) {
|
||||
if (!strcmp(str[ct+1], "default")) {
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(str[ct+1], "parent")) {
|
||||
mEnviroment.mVertex.clear();
|
||||
continue;
|
||||
}
|
||||
ProgramVertex * pv = (ProgramVertex *)rsc->lookupName(str[ct+1]);
|
||||
if (pv != NULL) {
|
||||
mEnviroment.mVertex.set(pv);
|
||||
continue;
|
||||
}
|
||||
LOGE("Unreconized value %s passed to stateVertex", str[ct+1]);
|
||||
}
|
||||
|
||||
@@ -473,8 +491,14 @@ void ScriptCState::runCompiler(Context *rsc)
|
||||
}
|
||||
|
||||
if (!strcmp(str[ct], "stateFragment")) {
|
||||
ProgramFragment * pf =
|
||||
(ProgramFragment *)rsc->lookupName(str[ct+1]);
|
||||
if (!strcmp(str[ct+1], "default")) {
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(str[ct+1], "parent")) {
|
||||
mEnviroment.mFragment.clear();
|
||||
continue;
|
||||
}
|
||||
ProgramFragment * pf = (ProgramFragment *)rsc->lookupName(str[ct+1]);
|
||||
if (pf != NULL) {
|
||||
mEnviroment.mFragment.set(pf);
|
||||
continue;
|
||||
@@ -483,18 +507,19 @@ void ScriptCState::runCompiler(Context *rsc)
|
||||
}
|
||||
|
||||
if (!strcmp(str[ct], "stateFragmentStore")) {
|
||||
if (!strcmp(str[ct+1], "default")) {
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(str[ct+1], "parent")) {
|
||||
mEnviroment.mFragmentStore.clear();
|
||||
continue;
|
||||
}
|
||||
ProgramFragmentStore * pfs =
|
||||
(ProgramFragmentStore *)rsc->lookupName(str[ct+1]);
|
||||
if (pfs != NULL) {
|
||||
mEnviroment.mFragmentStore.set(pfs);
|
||||
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]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user