summaryrefslogtreecommitdiffstats
path: root/tests/RenderScriptTests/SceneGraph/src
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2012-02-02 14:15:55 -0800
committerAlex Sakhartchouk <alexst@google.com>2012-02-02 15:28:44 -0800
commit5c15b765fecca6b0ba2760d04c86798ff980fd53 (patch)
tree0b882c93b6b0e38ad47c417e22a1cd9f5ece22ed /tests/RenderScriptTests/SceneGraph/src
parentebd661b50af7c47d85eddfe273386d36e0591a66 (diff)
downloadframeworks_base-5c15b765fecca6b0ba2760d04c86798ff980fd53.zip
frameworks_base-5c15b765fecca6b0ba2760d04c86798ff980fd53.tar.gz
frameworks_base-5c15b765fecca6b0ba2760d04c86798ff980fd53.tar.bz2
Adding float param time stamp. Cleanup, robustness.
Change-Id: I99148cf0566f0825739968bf1c7fbca021ef144e
Diffstat (limited to 'tests/RenderScriptTests/SceneGraph/src')
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java23
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java47
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java19
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java4
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh42
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh9
6 files changed, 98 insertions, 46 deletions
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java
index fdc3bbe..1502458 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Float4Param.java
@@ -45,57 +45,50 @@ public class Float4Param extends ShaderParam {
public Float4Param(String name, float x) {
super(name);
- set(x, 0, 0, 0, 1);
+ set(x, 0, 0, 0);
}
public Float4Param(String name, float x, float y) {
super(name);
- set(x, y, 0, 0, 2);
+ set(x, y, 0, 0);
}
public Float4Param(String name, float x, float y, float z) {
super(name);
- set(x, y, z, 0, 3);
+ set(x, y, z, 0);
}
public Float4Param(String name, float x, float y, float z, float w) {
super(name);
- set(x, y, z, w, 4);
+ set(x, y, z, w);
}
- void set(float x, float y, float z, float w, int vecSize) {
+ void set(float x, float y, float z, float w) {
mData.float_value.x = x;
mData.float_value.y = y;
mData.float_value.z = z;
mData.float_value.w = w;
- mData.float_vecSize = vecSize;
if (mField != null) {
mField.set_float_value(0, mData.float_value, true);
- mField.set_float_vecSize(0, mData.float_vecSize, true);
}
+ incTimestamp();
}
public void setValue(Float4 v) {
- set(v.x, v.y, v.z, v.w, mData.float_vecSize);
+ set(v.x, v.y, v.z, v.w);
}
public Float4 getValue() {
return mData.float_value;
}
- public void setVecSize(int vecSize) {
- mData.float_vecSize = vecSize;
- if (mField != null) {
- mField.set_float_vecSize(0, mData.float_vecSize, true);
- }
- }
-
public void setLight(LightBase l) {
mLight = l;
if (mField != null) {
mData.light = mLight.getRSData().getAllocation();
mField.set_light(0, mData.light, true);
}
+ incTimestamp();
}
boolean findLight(String property) {
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
index d98ed2c..481b2de 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.Iterator;
import com.android.scenegraph.Float4Param;
+import com.android.scenegraph.SceneManager;
import com.android.scenegraph.ShaderParam;
import com.android.scenegraph.TransformParam;
@@ -65,10 +66,18 @@ public class Renderable extends RenderableBase {
public void setRenderState(RenderState renderState) {
mRenderState = renderState;
+ if (mField != null) {
+ RenderScriptGL rs = SceneManager.getRS();
+ updateFieldItem(rs);
+ mField.set(mData, 0, true);
+ }
}
public void setMesh(Mesh mesh) {
mData.mesh = mesh;
+ if (mField != null) {
+ mField.set_mesh(0, mData.mesh, true);
+ }
}
public void setMesh(String mesh, String indexName) {
@@ -82,10 +91,19 @@ public class Renderable extends RenderableBase {
public void setTransform(Transform t) {
mTransform = t;
+ if (mField != null) {
+ RenderScriptGL rs = SceneManager.getRS();
+ updateFieldItem(rs);
+ mField.set(mData, 0, true);
+ }
}
public void appendSourceParams(ShaderParam p) {
mSourceParams.put(p.getParamName(), p);
+ // Possibly lift this restriction later
+ if (mField != null) {
+ throw new RuntimeException("Can't add source params to objects that are rendering");
+ }
}
public void resolveMeshData(Mesh mesh) {
@@ -125,7 +143,10 @@ public class Renderable extends RenderableBase {
}
ProgramFragment pf = mRenderState.mFragment.mProgram;
mData.pf_num_textures = pf != null ? Math.min(pf.getTextureCount(), paramIndex) : 0;
- mField.set(mData, 0, true);
+ if (mField != null) {
+ mField.set_pf_textures(0, mData.pf_textures, true);
+ mField.set_pf_num_textures(0, mData.pf_num_textures, true);
+ }
}
public void setVisible(boolean vis) {
@@ -139,7 +160,7 @@ public class Renderable extends RenderableBase {
if (mField != null) {
return mField;
}
- getRsFieldItem(rs, res);
+ updateFieldItem(rs);
mField = new ScriptField_Renderable_s(rs, 1);
mField.set(mData, 0, true);
@@ -147,9 +168,8 @@ public class Renderable extends RenderableBase {
return mField;
}
- void getRsFieldItem(RenderScriptGL rs, Resources res) {
- Allocation pvParams = null, pfParams = null;
- Allocation vertexConstants = null, fragmentConstants = null;
+ void updateVertexConstants(RenderScriptGL rs) {
+ Allocation pvParams = null, vertexConstants = null;
VertexShader pv = mRenderState.mVertex;
if (pv != null && pv.getObjectConstants() != null) {
vertexConstants = Allocation.createTyped(rs, pv.getObjectConstants());
@@ -157,6 +177,12 @@ public class Renderable extends RenderableBase {
pvParams = ShaderParam.fillInParams(vertexConst, mSourceParams,
mTransform).getAllocation();
}
+ mData.pv_const = vertexConstants;
+ mData.pv_constParams = pvParams;
+ }
+
+ void updateFragmentConstants(RenderScriptGL rs) {
+ Allocation pfParams = null, fragmentConstants = null;
FragmentShader pf = mRenderState.mFragment;
if (pf != null && pf.getObjectConstants() != null) {
fragmentConstants = Allocation.createTyped(rs, pf.getObjectConstants());
@@ -164,15 +190,18 @@ public class Renderable extends RenderableBase {
pfParams = ShaderParam.fillInParams(fragmentConst, mSourceParams,
mTransform).getAllocation();
}
-
- mData.pv_const = vertexConstants;
- mData.pv_constParams = pvParams;
mData.pf_const = fragmentConstants;
mData.pf_constParams = pfParams;
+ }
+
+ void updateFieldItem(RenderScriptGL rs) {
+ updateVertexConstants(rs);
+ updateFragmentConstants(rs);
+
if (mTransform != null) {
mData.transformMatrix = mTransform.getRSData().getAllocation();
}
- mData.name = SceneManager.getStringAsAllocation(rs, getName());
+ mData.name = getNameAlloc(rs);
mData.render_state = mRenderState.getRSData().getAllocation();
mData.bVolInitialized = 0;
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java
index b1071d3..8dea535 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java
@@ -50,6 +50,8 @@ public abstract class ShaderParam extends SceneGraphBase {
static final String modelView = "modelView";
static final String modelViewProj = "modelViewProj";
+ static final long sMaxTimeStamp = 0xffffffffL;
+
ScriptField_ShaderParamData_s.Item mData;
ScriptField_ShaderParamData_s mField;
@@ -80,14 +82,14 @@ public abstract class ShaderParam extends SceneGraphBase {
matchingParam = trParam;
}
}
- if (subElem.getDataType() == Element.DataType.FLOAT_32) {
- Float4Param fParam = (Float4Param)matchingParam;
- fParam.setVecSize(subElem.getVectorSize());
- }
ScriptField_ShaderParam_s.Item paramRS = new ScriptField_ShaderParam_s.Item();
paramRS.bufferOffset = offset;
paramRS.transformTimestamp = 0;
+ paramRS.dataTimestamp = 0;
paramRS.data = matchingParam.getRSData().getAllocation();
+ if (subElem.getDataType() == Element.DataType.FLOAT_32) {
+ paramRS.float_vecSize = subElem.getVectorSize();
+ }
paramList.add(paramRS);
}
@@ -121,6 +123,14 @@ public abstract class ShaderParam extends SceneGraphBase {
}
}
+ protected void incTimestamp() {
+ if (mField != null) {
+ mData.timestamp ++;
+ mData.timestamp %= sMaxTimeStamp;
+ mField.set_timestamp(0, mData.timestamp, true);
+ }
+ }
+
abstract void initLocalData();
public ScriptField_ShaderParamData_s getRSData() {
@@ -139,6 +149,7 @@ public abstract class ShaderParam extends SceneGraphBase {
}
}
initLocalData();
+ mData.timestamp = 1;
mField.set(mData, 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 d9fb0d0..d120d5d 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
@@ -41,6 +41,10 @@ public class TransformParam extends ShaderParam {
public void setTransform(Transform t) {
mTransform = t;
+ if (mField != null && mTransform != null) {
+ mData.transform = mTransform.getRSData().getAllocation();
+ }
+ incTimestamp();
}
int getTypeFromName() {
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh
index 2169de3..d1edb72 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh
@@ -19,22 +19,24 @@
#include "scenegraph_objects.rsh"
//#define DEBUG_PARAMS
-
static void debugParam(SgShaderParam *p, SgShaderParamData *pData,
uint8_t *constantBuffer, const SgCamera *currentCam) {
- rsDebug("____________ Param bufferOffset", p->bufferOffset);
- rsDebug("Param Type ", pData->type);
- if (rsIsObject(pData->paramName)) {
- printName(pData->paramName);
- }
+ rsDebug("____________ Param ____________", p);
+ printName(pData->paramName);
+ rsDebug("bufferOffset", p->bufferOffset);
+ rsDebug("type ", pData->type);
+ rsDebug("data timestamp ", pData->timestamp);
+ rsDebug("param timestamp", p->dataTimestamp);
uint8_t *dataPtr = constantBuffer + p->bufferOffset;
const SgTransform *pTransform = NULL;
if (rsIsObject(pData->transform)) {
pTransform = (const SgTransform *)rsGetElementAt(pData->transform, 0);
- rsDebug("Param transform", pTransform);
+ rsDebug("transform", pTransform);
printName(pTransform->name);
+ rsDebug("timestamp", pTransform->timestamp);
+ rsDebug("param timestamp", p->transformTimestamp);
}
const SgLight *pLight = NULL;
@@ -69,15 +71,25 @@ static void writeFloatData(float *ptr, const float4 *input, uint32_t vecSize) {
static bool processParam(SgShaderParam *p, SgShaderParamData *pData,
uint8_t *constantBuffer, const SgCamera *currentCam) {
+ bool isDataOnly = (pData->type > SHADER_PARAM_DATA_ONLY);
const SgTransform *pTransform = NULL;
if (rsIsObject(pData->transform)) {
pTransform = (const SgTransform *)rsGetElementAt(pData->transform, 0);
+ }
+
+ if (isDataOnly) {
// If we are a transform param and our transform is unchanged, nothing to do
- bool isTransformOnly = (pData->type > SHADER_PARAM_DATA_ONLY);
- if (p->transformTimestamp == pTransform->timestamp && isTransformOnly) {
- return false;
+ if (pTransform) {
+ if (p->transformTimestamp == pTransform->timestamp) {
+ return false;
+ }
+ p->transformTimestamp = pTransform->timestamp;
+ } else {
+ if (p->dataTimestamp == pData->timestamp) {
+ return false;
+ }
+ p->dataTimestamp = pData->timestamp;
}
- p->transformTimestamp = pTransform->timestamp;
}
const SgLight *pLight = NULL;
@@ -89,17 +101,17 @@ static bool processParam(SgShaderParam *p, SgShaderParamData *pData,
switch(pData->type) {
case SHADER_PARAM_FLOAT4_DATA:
- writeFloatData((float*)dataPtr, &pData->float_value, pData->float_vecSize);
+ writeFloatData((float*)dataPtr, &pData->float_value, p->float_vecSize);
break;
case SHADER_PARAM_FLOAT4_CAMERA_POS:
- writeFloatData((float*)dataPtr, &currentCam->position, pData->float_vecSize);
+ writeFloatData((float*)dataPtr, &currentCam->position, p->float_vecSize);
break;
case SHADER_PARAM_FLOAT4_CAMERA_DIR: break;
case SHADER_PARAM_FLOAT4_LIGHT_COLOR:
- writeFloatData((float*)dataPtr, &pLight->color, pData->float_vecSize);
+ writeFloatData((float*)dataPtr, &pLight->color, p->float_vecSize);
break;
case SHADER_PARAM_FLOAT4_LIGHT_POS:
- writeFloatData((float*)dataPtr, &pLight->position, pData->float_vecSize);
+ writeFloatData((float*)dataPtr, &pLight->position, p->float_vecSize);
break;
case SHADER_PARAM_FLOAT4_LIGHT_DIR: break;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh
index af39ecf..511d78b 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/scenegraph_objects.rsh
@@ -174,10 +174,8 @@ typedef struct Light_s {
// This represents the shader parameter data needed to set a float or transform data
typedef struct ShaderParamData_s {
int type;
-
float4 float_value;
- // Use one param type to handle all vector types for now
- int float_vecSize;
+ uint32_t timestamp;
rs_allocation paramName;
rs_allocation camera;
rs_allocation light;
@@ -190,10 +188,15 @@ typedef struct ShaderParamData_s {
typedef struct ShaderParam_s {
// Used to check whether transform params need to be updated
uint32_t transformTimestamp;
+ // Used to check whether data params need to be updated
+ // These are used when somebody set the matrix of float value directly in java
+ uint32_t dataTimestamp;
// Specifies where in the constant buffer data gets written to
int bufferOffset;
// An instance of SgShaderParamData that could be shared by multiple objects
rs_allocation data;
+ // How many components of the vector we need to write
+ int float_vecSize;
} SgShaderParam;
// This represents a texture object