summaryrefslogtreecommitdiffstats
path: root/tests/RenderScriptTests/SceneGraph/src
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2012-01-30 12:03:06 -0800
committerAlex Sakhartchouk <alexst@google.com>2012-01-30 12:03:06 -0800
commite93db17a143ff560f92d94b68ce1e76f79db7902 (patch)
tree33dd6fc7bf4812ca99f9019bdfd20176f9eae02b /tests/RenderScriptTests/SceneGraph/src
parentd3474b79eeebe5c83e2ee27576e24a593098ddf0 (diff)
downloadframeworks_base-e93db17a143ff560f92d94b68ce1e76f79db7902.zip
frameworks_base-e93db17a143ff560f92d94b68ce1e76f79db7902.tar.gz
frameworks_base-e93db17a143ff560f92d94b68ce1e76f79db7902.tar.bz2
Making the SceneGraph more robust to make sure data is propagated to RS.
Caching RS name allocations. Change-Id: I5e7a17a9ac76f81548145ae78665da322ec51271
Diffstat (limited to 'tests/RenderScriptTests/SceneGraph/src')
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java39
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java49
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java4
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java19
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/LightBase.java45
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/MatrixTransform.java15
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderPass.java2
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java31
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java6
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java12
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneGraphBase.java15
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java16
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java3
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java8
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java2
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java8
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java38
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java6
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java10
19 files changed, 233 insertions, 95 deletions
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java
index 3689b3d..04a7e4c 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java
@@ -19,9 +19,11 @@ package com.android.scenegraph;
import java.lang.Math;
import java.util.ArrayList;
+import com.android.scenegraph.SceneManager;
+
+import android.renderscript.*;
import android.renderscript.Matrix4f;
import android.renderscript.RenderScriptGL;
-import android.renderscript.*;
import android.util.Log;
/**
@@ -44,34 +46,59 @@ public class Camera extends SceneGraphBase {
public void setTransform(Transform t) {
mTransform = t;
+ updateRSData();
}
public void setFOV(float fov) {
mFOV = fov;
+ updateRSData();
}
public void setNear(float n) {
mNear = n;
+ updateRSData();
}
public void setFar(float f) {
mFar = f;
+ updateRSData();
+ }
+
+ public void setName(String n) {
+ super.setName(n);
+ updateRSData();
}
- ScriptField_Camera_s getRSData(RenderScriptGL rs) {
+ ScriptField_Camera_s getRSData() {
if (mField != null) {
return mField;
}
+ RenderScriptGL rs = SceneManager.getRS();
+ if (rs == null) {
+ return null;
+ }
+
mField = new ScriptField_Camera_s(rs, 1);
+ updateRSData();
+ return mField;
+ }
+
+ void updateRSData() {
+ if (mField == null) {
+ return;
+ }
+ RenderScriptGL rs = SceneManager.getRS();
+ if (rs == null) {
+ return;
+ }
+
ScriptField_Camera_s.Item cam = new ScriptField_Camera_s.Item();
cam.horizontalFOV = mFOV;
cam.near = mNear;
cam.far = mFar;
- cam.transformMatrix = mTransform.getRSData(rs).getAllocation();
- cam.name = SceneManager.getStringAsAllocation(rs, getName());
+ cam.transformMatrix = mTransform.getRSData().getAllocation();
+ cam.name = getNameAlloc(rs);
mField.set(cam, 0, true);
-
- return mField;
}
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java
index 5eb1d8a..b136aaa 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java
@@ -31,10 +31,18 @@ public class CompoundTransform extends Transform {
public static abstract class Component {
String mName;
+ Allocation mNameAlloc;
int mRsId;
Float4 mValue;
CompoundTransform mParent;
+ Allocation getNameAlloc(RenderScriptGL rs) {
+ if (mNameAlloc == null) {
+ mNameAlloc = SceneManager.getStringAsAllocation(rs, getName());
+ }
+ return mNameAlloc;
+ }
+
public String getName() {
return mName;
}
@@ -53,7 +61,7 @@ public class CompoundTransform extends Transform {
mValue.x = val.x;
mValue.y = val.y;
mValue.z = val.z;
- mParent.updateRSData();
+ mParent.updateRSComponents(true);
}
}
@@ -73,11 +81,11 @@ public class CompoundTransform extends Transform {
mValue.x = val.x;
mValue.y = val.y;
mValue.z = val.z;
- mParent.updateRSData();
+ mParent.updateRSComponents(true);
}
public void setAngle(float val) {
mValue.w = val;
- mParent.updateRSData();
+ mParent.updateRSComponents(true);
}
}
@@ -94,7 +102,7 @@ public class CompoundTransform extends Transform {
mValue.x = val.x;
mValue.y = val.y;
mValue.z = val.z;
- mParent.updateRSData();
+ mParent.updateRSComponents(true);
}
}
@@ -113,6 +121,7 @@ public class CompoundTransform extends Transform {
}
c.mParent = this;
mTransformComponents.add(c);
+ updateRSComponents(true);
}
public void setComponent(int index, Component c) {
@@ -121,40 +130,32 @@ public class CompoundTransform extends Transform {
}
c.mParent = this;
mTransformComponents.set(index, c);
+ updateRSComponents(true);
}
- void initLocalData() {
- mTransformData = new ScriptField_SgTransform.Item();
- int numElements = mTransformComponents.size();
- for (int i = 0; i < numElements; i ++) {
- Component ith = mTransformComponents.get(i);
- mTransformData.transforms[i] = ith.mValue;
- mTransformData.transformTypes[i] = ith.mRsId;
- mTransformData.transformNames[i] = SceneManager.getStringAsAllocation(mRS, ith.mName);
- }
- // "null" terminate the array
- mTransformData.transformTypes[numElements] = RS_ID_NONE;
-
- mTransformData.isDirty = 1;
- mTransformData.children = null;
- mTransformData.name = SceneManager.getStringAsAllocation(mRS, getName());
- }
-
- void updateRSData() {
+ // TODO: Will need to optimize this function a bit, we copy more data than we need to
+ void updateRSComponents(boolean copy) {
if (mField == null) {
return;
}
+ RenderScriptGL rs = SceneManager.getRS();
int numElements = mTransformComponents.size();
for (int i = 0; i < numElements; i ++) {
Component ith = mTransformComponents.get(i);
mTransformData.transforms[i] = ith.mValue;
mTransformData.transformTypes[i] = ith.mRsId;
- mTransformData.transformNames[i] = SceneManager.getStringAsAllocation(mRS, ith.mName);
+ mTransformData.transformNames[i] = ith.getNameAlloc(rs);
}
// "null" terminate the array
mTransformData.transformTypes[numElements] = RS_ID_NONE;
mTransformData.isDirty = 1;
- mField.set(mTransformData, 0, true);
+ if (copy) {
+ mField.set(mTransformData, 0, true);
+ }
+ }
+
+ void initLocalData() {
+ updateRSComponents(false);
}
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java
index 57294da..fbda50f 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java
@@ -145,10 +145,10 @@ public class Float4Param extends ShaderParam {
mRsFieldItem.float_value = mValue;
mRsFieldItem.float_vecSize = mVecSize;
if (mCamera != null) {
- mRsFieldItem.camera = mCamera.getRSData(rs).getAllocation();
+ mRsFieldItem.camera = mCamera.getRSData().getAllocation();
}
if (mLight != null) {
- mRsFieldItem.light = mLight.getRSData(rs).getAllocation();
+ mRsFieldItem.light = mLight.getRSData().getAllocation();
}
}
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java
index 02372f3..0fb32ff 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java
@@ -91,26 +91,37 @@ public class FragmentShader extends Shader {
return mProgram;
}
- public void updateTextures(RenderScriptGL rs, Resources res) {
+ public void updateTextures() {
+ RenderScriptGL rs = SceneManager.getRS();
+ Resources res = SceneManager.getRes();
+ if (rs == null || res == null) {
+ return;
+ }
int shaderTextureStart = mTextureTypes.size();
for (int i = 0; i < mShaderTextureNames.size(); i ++) {
ShaderParam sp = mSourceParams.get(mShaderTextureNames.get(i));
if (sp != null && sp instanceof TextureParam) {
TextureParam p = (TextureParam)sp;
- mProgram.bindTexture(p.getTexture().getRsData(rs, res), shaderTextureStart + i);
+ mProgram.bindTexture(p.getTexture().getRsData(), shaderTextureStart + i);
}
}
}
- public ScriptField_FragmentShader_s getRSData(RenderScriptGL rs, Resources res) {
+ ScriptField_FragmentShader_s getRSData() {
if (mField != null) {
return mField;
}
+ RenderScriptGL rs = SceneManager.getRS();
+ Resources res = SceneManager.getRes();
+ if (rs == null || res == null) {
+ return null;
+ }
+
ScriptField_FragmentShader_s.Item item = new ScriptField_FragmentShader_s.Item();
item.program = mProgram;
- linkConstants(rs, res);
+ linkConstants(rs);
if (mPerShaderConstants != null) {
item.shaderConst = mConstantBuffer;
item.shaderConstParams = mConstantBufferParams;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/LightBase.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/LightBase.java
index 3dfc161..8f5e2e7 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/LightBase.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/LightBase.java
@@ -44,43 +44,62 @@ public abstract class LightBase extends SceneGraphBase {
public void setTransform(Transform t) {
mTransform = t;
+ updateRSData();
}
public void setColor(float r, float g, float b) {
mColor.x = r;
mColor.y = g;
mColor.z = b;
+ updateRSData();
}
public void setColor(Float3 c) {
- mColor.x = c.x;
- mColor.y = c.y;
- mColor.z = c.z;
+ setColor(c.x, c.y, c.z);
}
public void setIntensity(float i) {
mIntensity = i;
+ updateRSData();
}
- abstract void initLocalData();
+ public void setName(String n) {
+ super.setName(n);
+ updateRSData();
+ }
- protected void updateBaseData(RenderScriptGL rs) {
+ protected void updateRSData() {
if (mField == null) {
- mField = new ScriptField_Light_s(rs, 1);
- mFieldData = new ScriptField_Light_s.Item();
+ return;
}
-
- mFieldData.transformMatrix = mTransform.getRSData(rs).getAllocation();
- mFieldData.name = SceneManager.getStringAsAllocation(rs, getName());
+ RenderScriptGL rs = SceneManager.getRS();
+ mFieldData.transformMatrix = mTransform.getRSData().getAllocation();
+ mFieldData.name = getNameAlloc(rs);
mFieldData.color = mColor;
mFieldData.intensity = mIntensity;
- }
- ScriptField_Light_s getRSData(RenderScriptGL rs) {
- updateBaseData(rs);
initLocalData();
mField.set(mFieldData, 0, true);
+ }
+
+ abstract void initLocalData();
+
+ ScriptField_Light_s getRSData() {
+ if (mField != null) {
+ return mField;
+ }
+
+ RenderScriptGL rs = SceneManager.getRS();
+ if (rs == null) {
+ return null;
+ }
+ if (mField == null) {
+ mField = new ScriptField_Light_s(rs, 1);
+ mFieldData = new ScriptField_Light_s.Item();
+ }
+
+ updateRSData();
return mField;
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/MatrixTransform.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/MatrixTransform.java
index fb57f89..1e5f0fd 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/MatrixTransform.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/MatrixTransform.java
@@ -34,20 +34,23 @@ public class MatrixTransform extends Transform {
public void setMatrix(Matrix4f matrix) {
mLocalMatrix = matrix;
+ updateRSData();
+ }
+
+ public Matrix4f getMatrix() {
+ return new Matrix4f(mLocalMatrix.getArray());
}
void initLocalData() {
- mTransformData = new ScriptField_SgTransform.Item();
// "null" terminate the array
mTransformData.transformTypes[0] = RS_ID_NONE;
mTransformData.localMat = mLocalMatrix;
-
- mTransformData.isDirty = 1;
- mTransformData.children = null;
- mTransformData.name = SceneManager.getStringAsAllocation(mRS, getName());
}
- public void updateRSData() {
+ void updateRSData() {
+ if (mField == null) {
+ return;
+ }
mTransformData.localMat = mLocalMatrix;
mTransformData.isDirty = 1;
mField.set(mTransformData, 0, true);
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderPass.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderPass.java
index a9cb688..3cd70f5 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderPass.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderPass.java
@@ -91,7 +91,7 @@ public class RenderPass extends SceneGraphBase {
mRsField = new ScriptField_RenderPass_s.Item();
mRsField.color_target = mColorTarget;
mRsField.depth_target = mDepthTarget;
- mRsField.camera = mCamera != null ? mCamera.getRSData(rs).getAllocation() : null;
+ mRsField.camera = mCamera != null ? mCamera.getRSData().getAllocation() : null;
if (mObjectsToDraw.size() != 0) {
Allocation drawableData = Allocation.createSized(rs,
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java
index 8546e95..c08a722 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java
@@ -62,33 +62,50 @@ public class RenderState extends SceneGraphBase {
public void setProgramVertex(VertexShader pv) {
mVertex = pv;
+ updateRSData();
}
public void setProgramFragment(FragmentShader pf) {
mFragment = pf;
+ updateRSData();
}
public void setProgramStore(ProgramStore ps) {
mStore = ps;
+ updateRSData();
}
public void setProgramRaster(ProgramRaster pr) {
mRaster = pr;
+ updateRSData();
}
- public ScriptField_RenderState_s getRSData(RenderScriptGL rs, Resources res) {
- if (mField != null) {
- return mField;
+ void updateRSData() {
+ if (mField == null) {
+ return;
}
-
ScriptField_RenderState_s.Item item = new ScriptField_RenderState_s.Item();
- item.pv = mVertex.getRSData(rs, res).getAllocation();
- item.pf = mFragment.getRSData(rs, res).getAllocation();
+ item.pv = mVertex.getRSData().getAllocation();
+ item.pf = mFragment.getRSData().getAllocation();
item.ps = mStore;
item.pr = mRaster;
- mField = new ScriptField_RenderState_s(rs, 1);
mField.set(item, 0, true);
+ }
+
+ public ScriptField_RenderState_s getRSData() {
+ if (mField != null) {
+ return mField;
+ }
+
+ RenderScriptGL rs = SceneManager.getRS();
+ if (rs == null) {
+ return null;
+ }
+
+ mField = new ScriptField_RenderState_s(rs, 1);
+ updateRSData();
+
return mField;
}
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
index 8b2b8db..445c590 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
@@ -138,7 +138,7 @@ public class Renderable extends RenderableBase {
ShaderParam sp = allParamsIter.next();
if (sp instanceof TextureParam) {
TextureParam p = (TextureParam)sp;
- mRsFieldItem.pf_textures[paramIndex++] = p.getTexture().getRsData(rs, res);
+ mRsFieldItem.pf_textures[paramIndex++] = p.getTexture().getRsData();
}
}
ProgramFragment pf = mRenderState.mFragment.mProgram;
@@ -228,10 +228,10 @@ public class Renderable extends RenderableBase {
mRsFieldItem.pf_const = mFragmentConstants;
mRsFieldItem.pf_constParams = pfParams != null ? pfParams.getAllocation() : null;
if (mTransform != null) {
- mRsFieldItem.transformMatrix = mTransform.getRSData(rs).getAllocation();
+ mRsFieldItem.transformMatrix = mTransform.getRSData().getAllocation();
}
mRsFieldItem.name = SceneManager.getStringAsAllocation(rs, getName());
- mRsFieldItem.render_state = mRenderState.getRSData(rs, res).getAllocation();
+ mRsFieldItem.render_state = mRenderState.getRSData().getAllocation();
mRsFieldItem.bVolInitialized = 0;
mRsFieldItem.cullType = mCullType;
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java
index 715fb23..e325204 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java
@@ -58,7 +58,7 @@ public class Scene extends SceneGraphBase {
long start = System.currentTimeMillis();
for (int i = 0; i < objects[0].size(); i ++) {
FragmentShader sI = objects[0].get(i);
- sI.updateTextures(mRS, mRes);
+ sI.updateTextures();
}
long end = System.currentTimeMillis();
Log.v(TIMER_TAG, "Shader texture init time: " + (end - start));
@@ -266,7 +266,7 @@ public class Scene extends SceneGraphBase {
Allocation[] shaderAllocs = new Allocation[mVertexShaders.size()];
for (int i = 0; i < mVertexShaders.size(); i ++) {
VertexShader sI = mVertexShaders.get(i);
- shaderAllocs[i] = sI.getRSData(rs, res).getAllocation();
+ shaderAllocs[i] = sI.getRSData().getAllocation();
}
shaderData.copyFrom(shaderAllocs);
sceneManager.mRenderLoop.set_gVertexShaders(shaderData);
@@ -275,7 +275,7 @@ public class Scene extends SceneGraphBase {
shaderAllocs = new Allocation[mFragmentShaders.size()];
for (int i = 0; i < mFragmentShaders.size(); i ++) {
FragmentShader sI = mFragmentShaders.get(i);
- shaderAllocs[i] = sI.getRSData(rs, res).getAllocation();
+ shaderAllocs[i] = sI.getRSData().getAllocation();
}
shaderData.copyFrom(shaderAllocs);
sceneManager.mRenderLoop.set_gFragmentShaders(shaderData);
@@ -285,7 +285,7 @@ public class Scene extends SceneGraphBase {
mRS = rs;
mRes = res;
long start = System.currentTimeMillis();
- mTransformRSData = mRootTransforms.getRSData(rs);
+ mTransformRSData = mRootTransforms.getRSData();
long end = System.currentTimeMillis();
Log.v(TIMER_TAG, "Transform init time: " + (end - start));
@@ -312,7 +312,7 @@ public class Scene extends SceneGraphBase {
Allocation cameraData = Allocation.createSized(rs, Element.ALLOCATION(rs), mCameras.size());
Allocation[] cameraAllocs = new Allocation[mCameras.size()];
for (int i = 0; i < mCameras.size(); i ++) {
- cameraAllocs[i] = mCameras.get(i).getRSData(rs).getAllocation();
+ cameraAllocs[i] = mCameras.get(i).getRSData().getAllocation();
}
cameraData.copyFrom(cameraAllocs);
sceneManager.mRenderLoop.set_gCameras(cameraData);
@@ -323,7 +323,7 @@ public class Scene extends SceneGraphBase {
mCameras.size());
Allocation[] lightAllocs = new Allocation[mLights.size()];
for (int i = 0; i < mLights.size(); i ++) {
- lightAllocs[i] = mLights.get(i).getRSData(rs).getAllocation();
+ lightAllocs[i] = mLights.get(i).getRSData().getAllocation();
}
lightData.copyFrom(lightAllocs);
sceneManager.mRenderLoop.set_gLights(lightData);
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneGraphBase.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneGraphBase.java
index 36fb82b..412ffbf 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneGraphBase.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneGraphBase.java
@@ -19,15 +19,17 @@ package com.android.scenegraph;
import java.lang.Math;
import java.util.ArrayList;
+import com.android.scenegraph.SceneManager;
+
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.Matrix4f;
import android.renderscript.ProgramFragment;
import android.renderscript.ProgramStore;
import android.renderscript.ProgramVertex;
-import android.renderscript.RenderScript;
import android.renderscript.RSRuntimeException;
-
+import android.renderscript.RenderScript;
+import android.renderscript.RenderScriptGL;
import android.util.Log;
/**
@@ -35,13 +37,22 @@ import android.util.Log;
*/
public abstract class SceneGraphBase {
String mName;
+ Allocation mNameAlloc;
public void setName(String n) {
mName = n;
+ mNameAlloc = null;
}
public String getName() {
return mName;
}
+
+ Allocation getNameAlloc(RenderScriptGL rs) {
+ if (mNameAlloc == null) {
+ mNameAlloc = SceneManager.getStringAsAllocation(rs, getName());
+ }
+ return mNameAlloc;
+ }
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
index 45d1dfb..2411e92 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
@@ -41,6 +41,8 @@ import android.renderscript.RenderScriptGL;
import android.util.Log;
import android.view.SurfaceHolder;
+import com.android.testapp.R;
+
/**
* @hide
*/
@@ -163,6 +165,20 @@ public class SceneManager extends SceneGraphBase {
mActiveScene = s;
}
+ static RenderScriptGL getRS() {
+ if (sSceneManager == null) {
+ return null;
+ }
+ return sSceneManager.mRS;
+ }
+
+ static Resources getRes() {
+ if (sSceneManager == null) {
+ return null;
+ }
+ return sSceneManager.mRes;
+ }
+
public static SceneManager getInstance() {
if (sSceneManager == null) {
sSceneManager = new SceneManager();
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java
index 7541115..41bd651 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java
@@ -20,7 +20,6 @@ import java.lang.Math;
import java.util.ArrayList;
import java.util.HashMap;
-import android.content.res.Resources;
import android.renderscript.*;
import android.renderscript.ProgramFragment.Builder;
import android.util.Log;
@@ -63,7 +62,7 @@ public abstract class Shader extends SceneGraphBase {
return mPerObjConstants;
}
- void linkConstants(RenderScriptGL rs, Resources res) {
+ void linkConstants(RenderScriptGL rs) {
if (mPerShaderConstants == null) {
return;
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
index dd01554..2f04858 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
@@ -54,11 +54,17 @@ public class Texture2D extends TextureBase {
mRsTexture = tex;
}
- Allocation getRsData(RenderScriptGL rs, Resources res) {
+ Allocation getRsData() {
if (mRsTexture != null) {
return mRsTexture;
}
+ RenderScriptGL rs = SceneManager.getRS();
+ Resources res = SceneManager.getRes();
+ if (rs == null || res == null) {
+ return null;
+ }
+
String shortName = mFileName.substring(mFileName.lastIndexOf('/') + 1);
mRsTexture = SceneManager.loadTexture2D(mFileDir + shortName, rs, res);
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java
index d6b525b..425c6d6 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java
@@ -29,7 +29,7 @@ import android.util.Log;
*/
public abstract class TextureBase extends SceneGraphBase {
protected Allocation mRsTexture;
- abstract Allocation getRsData(RenderScriptGL rs, Resources res);
+ abstract Allocation getRsData();
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java
index e338be4..ba42494 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java
@@ -60,11 +60,17 @@ public class TextureCube extends TextureBase {
mRsTexture = tex;
}
- Allocation getRsData(RenderScriptGL rs, Resources res) {
+ Allocation getRsData() {
if (mRsTexture != null) {
return mRsTexture;
}
+ RenderScriptGL rs = SceneManager.getRS();
+ Resources res = SceneManager.getRes();
+ if (rs == null || res == null) {
+ return null;
+ }
+
String shortName = mFileName.substring(mFileName.lastIndexOf('/') + 1);
mRsTexture = SceneManager.loadCubemap(mFileDir + shortName, rs, res);
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java
index 8f0cbe5..359fad4 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java
@@ -33,7 +33,6 @@ public abstract class Transform extends SceneGraphBase {
static final int RS_ID_ROTATE = 2;
static final int RS_ID_SCALE = 3;
- RenderScriptGL mRS;
Transform mParent;
ArrayList<Transform> mChildren;
@@ -48,19 +47,16 @@ public abstract class Transform extends SceneGraphBase {
public void appendChild(Transform t) {
mChildren.add(t);
t.mParent = this;
+ updateRSChildData(true);
}
abstract void initLocalData();
- abstract void updateRSData();
- ScriptField_SgTransform getRSData(RenderScriptGL rs) {
- if (mField != null) {
- return mField;
+ void updateRSChildData(boolean copyData) {
+ if (mField == null) {
+ return;
}
-
- mRS = rs;
- initLocalData();
-
+ RenderScriptGL rs = SceneManager.getRS();
if (mChildren.size() != 0) {
Allocation childRSData = Allocation.createSized(rs, Element.ALLOCATION(rs),
mChildren.size());
@@ -69,14 +65,34 @@ public abstract class Transform extends SceneGraphBase {
Allocation[] childrenAllocs = new Allocation[mChildren.size()];
for (int i = 0; i < mChildren.size(); i ++) {
Transform child = mChildren.get(i);
- childrenAllocs[i] = child.getRSData(rs).getAllocation();
+ childrenAllocs[i] = child.getRSData().getAllocation();
}
childRSData.copyFrom(childrenAllocs);
}
+ if (copyData) {
+ mField.set(mTransformData, 0, true);
+ }
+ }
+ ScriptField_SgTransform getRSData() {
+ if (mField != null) {
+ return mField;
+ }
+
+ RenderScriptGL rs = SceneManager.getRS();
+ if (rs == null) {
+ return null;
+ }
mField = new ScriptField_SgTransform(rs, 1);
- mField.set(mTransformData, 0, true);
+ mTransformData = new ScriptField_SgTransform.Item();
+ mTransformData.name = getNameAlloc(rs);
+ mTransformData.isDirty = 1;
+
+ initLocalData();
+ updateRSChildData(false);
+
+ mField.set(mTransformData, 0, true);
return mField;
}
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
index f340841..e082013 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
@@ -70,13 +70,13 @@ public class TransformParam extends ShaderParam {
mRsFieldItem.type = getTypeFromName();
mRsFieldItem.bufferOffset = mOffset;
if (mTransform != null) {
- mRsFieldItem.transform = mTransform.getRSData(rs).getAllocation();
+ mRsFieldItem.transform = mTransform.getRSData().getAllocation();
}
if (mCamera != null) {
- mRsFieldItem.camera = mCamera.getRSData(rs).getAllocation();
+ mRsFieldItem.camera = mCamera.getRSData().getAllocation();
}
if (mLight != null) {
- mRsFieldItem.light = mLight.getRSData(rs).getAllocation();
+ mRsFieldItem.light = mLight.getRSData().getAllocation();
}
}
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java
index f118996..e3c5193 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java
@@ -75,15 +75,21 @@ public class VertexShader extends Shader {
return mProgram;
}
- public ScriptField_VertexShader_s getRSData(RenderScriptGL rs, Resources res) {
+ ScriptField_VertexShader_s getRSData() {
if (mField != null) {
return mField;
}
+ RenderScriptGL rs = SceneManager.getRS();
+ Resources res = SceneManager.getRes();
+ if (rs == null || res == null) {
+ return null;
+ }
+
ScriptField_VertexShader_s.Item item = new ScriptField_VertexShader_s.Item();
item.program = mProgram;
- linkConstants(rs, res);
+ linkConstants(rs);
if (mPerShaderConstants != null) {
item.shaderConst = mConstantBuffer;
item.shaderConstParams = mConstantBufferParams;