summaryrefslogtreecommitdiffstats
path: root/tests/RenderScriptTests/SceneGraph
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2012-01-20 14:16:50 -0800
committerAlex Sakhartchouk <alexst@google.com>2012-01-20 14:16:50 -0800
commit4fd35d8f49dbed174828da60b70c37e7a77a0d13 (patch)
treef3b74ee9a06f2ecd5a2b81060de888c2a216afd1 /tests/RenderScriptTests/SceneGraph
parent7483a5e8fe23c1b806911297a6c4b5719b1b3a64 (diff)
downloadframeworks_base-4fd35d8f49dbed174828da60b70c37e7a77a0d13.zip
frameworks_base-4fd35d8f49dbed174828da60b70c37e7a77a0d13.tar.gz
frameworks_base-4fd35d8f49dbed174828da60b70c37e7a77a0d13.tar.bz2
Many optimizations of rendering path.
Adding ability to split up per shader and per object updates. Added cubemaps as scenegraph objects. Change-Id: I7877658c35ad1407444e1e092c7634b46d745691
Diffstat (limited to 'tests/RenderScriptTests/SceneGraph')
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java104
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java23
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java48
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java68
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java18
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java80
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java37
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java102
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java3
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java38
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java73
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java4
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java101
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs2
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs6
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs42
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs62
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh (renamed from tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rs)39
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs32
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh8
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh29
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs42
22 files changed, 790 insertions, 171 deletions
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java
new file mode 100644
index 0000000..fb81f73
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FragmentShader.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.scenegraph;
+
+import java.lang.Math;
+import java.util.ArrayList;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.renderscript.ProgramFragment.Builder;
+import android.util.Log;
+
+/**
+ * @hide
+ */
+public class FragmentShader extends Shader {
+ ProgramFragment mProgram;
+ ScriptField_FragmentShader_s mField;
+
+ public static class Builder {
+
+ FragmentShader mShader;
+ ProgramFragment.Builder mBuilder;
+
+ public Builder(RenderScriptGL rs) {
+ mShader = new FragmentShader();
+ mBuilder = new ProgramFragment.Builder(rs);
+ }
+
+ public Builder setShader(Resources resources, int resourceID) {
+ mBuilder.setShader(resources, resourceID);
+ return this;
+ }
+
+ public Builder setObjectConst(Type type) {
+ mShader.mPerObjConstants = type;
+ return this;
+ }
+
+ public Builder setShaderConst(Type type) {
+ mShader.mPerShaderConstants = type;
+ return this;
+ }
+
+ public Builder addTexture(Program.TextureType texType, String name) {
+ mBuilder.addTexture(texType);
+ mShader.mTextureNames.add(name);
+ return this;
+ }
+
+ FragmentShader create() {
+ if (mShader.mPerShaderConstants != null) {
+ mBuilder.addConstant(mShader.mPerShaderConstants);
+ }
+ if (mShader.mPerObjConstants != null) {
+ mBuilder.addConstant(mShader.mPerObjConstants);
+ }
+ mShader.mProgram = mBuilder.create();
+ return mShader;
+ }
+ }
+
+ FragmentShader() {
+ }
+
+ public ScriptField_FragmentShader_s getRSData(RenderScriptGL rs) {
+ if (mField != null) {
+ return mField;
+ }
+
+ ScriptField_FragmentShader_s.Item item = new ScriptField_FragmentShader_s.Item();
+ item.program = mProgram;
+
+ linkConstants(rs);
+ if (mPerShaderConstants != null) {
+ item.shaderConst = mConstantBuffer;
+ item.shaderConstParams = mConstantBufferParams;
+ mProgram.bindConstants(item.shaderConst, 0);
+ }
+
+ item.objectConstIndex = -1;
+ if (mPerObjConstants != null) {
+ item.objectConstIndex = mPerShaderConstants != null ? 1 : 0;
+ }
+
+ mField = new ScriptField_FragmentShader_s(rs, 1);
+ mField.set(item, 0, true);
+ return mField;
+ }
+}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java
index e8aec95..c8a0be0 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/RenderState.java
@@ -35,15 +35,15 @@ import android.util.Log;
* @hide
*/
public class RenderState extends SceneGraphBase {
- ProgramVertex mVertex;
- ProgramFragment mFragment;
+ VertexShader mVertex;
+ FragmentShader mFragment;
ProgramStore mStore;
ProgramRaster mRaster;
ScriptField_RenderState_s mField;
- public RenderState(ProgramVertex pv,
- ProgramFragment pf,
+ public RenderState(VertexShader pv,
+ FragmentShader pf,
ProgramStore ps,
ProgramRaster pr) {
mVertex = pv;
@@ -52,6 +52,13 @@ public class RenderState extends SceneGraphBase {
mRaster = pr;
}
+ public RenderState(ProgramVertex pv,
+ ProgramFragment pf,
+ ProgramStore ps,
+ ProgramRaster pr) {
+ // Just to fix the build for now
+ }
+
public RenderState(RenderState r) {
mVertex = r.mVertex;
mFragment = r.mFragment;
@@ -59,11 +66,11 @@ public class RenderState extends SceneGraphBase {
mRaster = r.mRaster;
}
- public void setProgramVertex(ProgramVertex pv) {
+ public void setProgramVertex(VertexShader pv) {
mVertex = pv;
}
- public void setProgramFragment(ProgramFragment pf) {
+ public void setProgramFragment(FragmentShader pf) {
mFragment = pf;
}
@@ -81,8 +88,8 @@ public class RenderState extends SceneGraphBase {
}
ScriptField_RenderState_s.Item item = new ScriptField_RenderState_s.Item();
- item.pv = mVertex;
- item.pf = mFragment;
+ item.pv = mVertex.getRSData(rs).getAllocation();
+ item.pf = mFragment.getRSData(rs).getAllocation();
item.ps = mStore;
item.pr = mRaster;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
index 3fa2a51..c73b32e 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Renderable.java
@@ -141,7 +141,7 @@ public class Renderable extends RenderableBase {
mRsFieldItem.pf_textures[paramIndex++] = p.getTexture().getRsData(rs, res);
}
}
- ProgramFragment pf = mRenderState.mFragment;
+ ProgramFragment pf = mRenderState.mFragment.mProgram;
mRsFieldItem.pf_num_textures = pf != null ? Math.min(pf.getTextureCount(), paramIndex) : 0;
mRsField.set(mRsFieldItem, 0, true);
}
@@ -157,47 +157,17 @@ public class Renderable extends RenderableBase {
mRsField.set(mRsFieldItem, 0, true);
}
- ShaderParam findParamByName(String name) {
- return mSourceParams.get(name);
- }
-
- void fillInParams(Element constantElem, ArrayList<ShaderParam> paramList) {
- int subElemCount = constantElem.getSubElementCount();
- for (int i = 0; i < subElemCount; i ++) {
- String inputName = constantElem.getSubElementName(i);
- int offset = constantElem.getSubElementOffsetBytes(i);
- ShaderParam matchingParam = findParamByName(inputName);
- Element subElem = constantElem.getSubElement(i);
- // Make one if it's not there
- if (matchingParam == null) {
- if (subElem.getDataType() == Element.DataType.FLOAT_32) {
- matchingParam = new Float4Param(inputName);
- } else if (subElem.getDataType() == Element.DataType.MATRIX_4X4) {
- TransformParam trParam = new TransformParam(inputName);
- trParam.setTransform(mTransform);
- matchingParam = trParam;
- }
- }
- matchingParam.setOffset(offset);
- if (subElem.getDataType() == Element.DataType.FLOAT_32) {
- Float4Param fParam = (Float4Param)matchingParam;
- fParam.setVecSize(subElem.getVectorSize());
- }
- paramList.add(matchingParam);
- }
- }
-
void linkConstants() {
// Assign all the fragment params
if (mFragmentConstants != null) {
Element fragmentConst = mFragmentConstants.getType().getElement();
- fillInParams(fragmentConst, mFragmentParamList);
+ ShaderParam.fillInParams(fragmentConst, mSourceParams, mTransform, mFragmentParamList);
}
// Assign all the vertex params
if (mVertexConstants != null) {
Element vertexConst = mVertexConstants.getType().getElement();
- fillInParams(vertexConst, mVertexParamList);
+ ShaderParam.fillInParams(vertexConst, mSourceParams, mTransform, mVertexParamList);
}
}
@@ -218,13 +188,13 @@ public class Renderable extends RenderableBase {
return;
}
- ProgramVertex pv = mRenderState.mVertex;
- if (pv != null && pv.getConstantCount() > 0) {
- mVertexConstants = Allocation.createTyped(rs, pv.getConstant(0));
+ VertexShader pv = mRenderState.mVertex;
+ if (pv != null && pv.getObjectConstants() != null) {
+ mVertexConstants = Allocation.createTyped(rs, pv.getObjectConstants());
}
- ProgramFragment pf = mRenderState.mFragment;
- if (pf != null && pf.getConstantCount() > 0) {
- mFragmentConstants = Allocation.createTyped(rs, pf.getConstant(0));
+ FragmentShader pf = mRenderState.mFragment;
+ if (pf != null && pf.getObjectConstants() != null) {
+ mFragmentConstants = Allocation.createTyped(rs, pf.getObjectConstants());
}
// Very important step that links available inputs and the constants vertex and
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java
index baf6dff..3d48547 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Scene.java
@@ -56,6 +56,8 @@ public class Scene extends SceneGraphBase {
ArrayList<RenderPass> mRenderPasses;
ArrayList<LightBase> mLights;
ArrayList<Camera> mCameras;
+ ArrayList<FragmentShader> mFragmentShaders;
+ ArrayList<VertexShader> mVertexShaders;
ArrayList<RenderableBase> mRenderables;
HashMap<String, RenderableBase> mRenderableMap;
ArrayList<Texture2D> mTextures;
@@ -74,6 +76,8 @@ public class Scene extends SceneGraphBase {
mRenderPasses = new ArrayList<RenderPass>();
mLights = new ArrayList<LightBase>();
mCameras = new ArrayList<Camera>();
+ mFragmentShaders = new ArrayList<FragmentShader>();
+ mVertexShaders = new ArrayList<VertexShader>();
mRenderables = new ArrayList<RenderableBase>();
mRenderableMap = new HashMap<String, RenderableBase>();
mRenderableMeshMap = new HashMap<String, ArrayList<Renderable> >();
@@ -112,6 +116,14 @@ public class Scene extends SceneGraphBase {
mCameras.add(c);
}
+ public void appendShader(FragmentShader f) {
+ mFragmentShaders.add(f);
+ }
+
+ public void appendShader(VertexShader v) {
+ mVertexShaders.add(v);
+ }
+
public ArrayList<Camera> getCameras() {
return mCameras;
}
@@ -211,21 +223,7 @@ public class Scene extends SceneGraphBase {
}
}
- public void initRS(RenderScriptGL rs, Resources res, SceneManager sceneManager) {
- mRS = rs;
- mRes = res;
- long start = System.currentTimeMillis();
- mTransformRSData = mRootTransforms.getRSData(rs);
- long end = System.currentTimeMillis();
- Log.v(TIMER_TAG, "Transform init time: " + (end - start));
-
- start = System.currentTimeMillis();
-
- sceneManager.mRenderLoop.bind_gRootNode(mTransformRSData);
- end = System.currentTimeMillis();
- Log.v(TIMER_TAG, "Script init time: " + (end - start));
-
- start = System.currentTimeMillis();
+ private void addDrawables(RenderScriptGL rs, Resources res, SceneManager sceneManager) {
Allocation drawableData = Allocation.createSized(rs,
Element.ALLOCATION(rs),
mRenderables.size());
@@ -240,10 +238,50 @@ public class Scene extends SceneGraphBase {
sceneManager.mRenderLoop.set_gRenderableObjects(drawableData);
initRenderPassRS(rs, sceneManager);
+ }
+ private void addShaders(RenderScriptGL rs, Resources res, SceneManager sceneManager) {
+ Allocation shaderData = Allocation.createSized(rs, Element.ALLOCATION(rs),
+ mVertexShaders.size());
+ Allocation[] shaderAllocs = new Allocation[mVertexShaders.size()];
+ for (int i = 0; i < mVertexShaders.size(); i ++) {
+ VertexShader sI = mVertexShaders.get(i);
+ shaderAllocs[i] = sI.getRSData(rs).getAllocation();
+ }
+ shaderData.copyFrom(shaderAllocs);
+ sceneManager.mRenderLoop.set_gVertexShaders(shaderData);
+
+ shaderData = Allocation.createSized(rs, Element.ALLOCATION(rs), mFragmentShaders.size());
+ shaderAllocs = new Allocation[mFragmentShaders.size()];
+ for (int i = 0; i < mFragmentShaders.size(); i ++) {
+ FragmentShader sI = mFragmentShaders.get(i);
+ shaderAllocs[i] = sI.getRSData(rs).getAllocation();
+ }
+ shaderData.copyFrom(shaderAllocs);
+ sceneManager.mRenderLoop.set_gFragmentShaders(shaderData);
+ }
+
+ public void initRS(RenderScriptGL rs, Resources res, SceneManager sceneManager) {
+ mRS = rs;
+ mRes = res;
+ long start = System.currentTimeMillis();
+ mTransformRSData = mRootTransforms.getRSData(rs);
+ long end = System.currentTimeMillis();
+ Log.v(TIMER_TAG, "Transform init time: " + (end - start));
+
+ start = System.currentTimeMillis();
+
+ sceneManager.mRenderLoop.bind_gRootNode(mTransformRSData);
+ end = System.currentTimeMillis();
+ Log.v(TIMER_TAG, "Script init time: " + (end - start));
+
+ start = System.currentTimeMillis();
+ addDrawables(rs, res, sceneManager);
end = System.currentTimeMillis();
Log.v(TIMER_TAG, "Renderable init time: " + (end - start));
+ addShaders(rs, res, sceneManager);
+
Allocation opaqueBuffer = Allocation.createSized(rs, Element.U32(rs), mRenderables.size());
Allocation transparentBuffer = Allocation.createSized(rs,
Element.U32(rs), mRenderables.size());
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
index e99d710..2a88b6b 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
@@ -47,10 +47,12 @@ import android.view.SurfaceHolder;
public class SceneManager extends SceneGraphBase {
ScriptC_render mRenderLoop;
- ScriptC_camera mCameraScript;
- ScriptC_light mLightScript;
- ScriptC_params mParamsScript;
- ScriptC_cull mCullScript;
+ ScriptC mCameraScript;
+ ScriptC mLightScript;
+ ScriptC mObjectParamsScript;
+ ScriptC mFragmentParamsScript;
+ ScriptC mVertexParamsScript;
+ ScriptC mCullScript;
ScriptC_transform mTransformScript;
RenderScriptGL mRS;
@@ -221,14 +223,18 @@ public class SceneManager extends SceneGraphBase {
mCameraScript = new ScriptC_camera(rs, res, R.raw.camera);
mLightScript = new ScriptC_light(rs, res, R.raw.light);
- mParamsScript = new ScriptC_params(rs, res, R.raw.params);
+ mObjectParamsScript = new ScriptC_object_params(rs, res, R.raw.object_params);
+ mFragmentParamsScript = new ScriptC_object_params(rs, res, R.raw.fragment_params);
+ mVertexParamsScript = new ScriptC_object_params(rs, res, R.raw.vertex_params);
mCullScript = new ScriptC_cull(rs, res, R.raw.cull);
mRenderLoop = new ScriptC_render(rs, res, R.raw.render);
mRenderLoop.set_gTransformScript(mTransformScript);
mRenderLoop.set_gCameraScript(mCameraScript);
mRenderLoop.set_gLightScript(mLightScript);
- mRenderLoop.set_gParamsScript(mParamsScript);
+ mRenderLoop.set_gObjectParamsScript(mObjectParamsScript);
+ mRenderLoop.set_gFragmentParamsScript(mFragmentParamsScript);
+ mRenderLoop.set_gVertexParamsScript(mVertexParamsScript);
mRenderLoop.set_gCullScript(mCullScript);
Allocation checker = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.checker,
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java
new file mode 100644
index 0000000..9713eb5
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Shader.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.scenegraph;
+
+import java.lang.Math;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.util.Log;
+
+/**
+ * @hide
+ */
+public abstract class Shader extends SceneGraphBase {
+ protected Type mPerObjConstants;
+ protected Type mPerShaderConstants;
+
+ protected HashMap<String, ShaderParam> mSourceParams;
+ protected ArrayList<ShaderParam> mParamList;
+ protected ArrayList<String> mTextureNames;
+
+ protected Allocation mConstantBuffer;
+ protected Allocation mConstantBufferParams;
+
+ public Shader() {
+ mSourceParams = new HashMap<String, ShaderParam>();
+ mParamList = new ArrayList<ShaderParam>();
+ mTextureNames = new ArrayList<String>();
+ }
+
+ public void appendSourceParams(ShaderParam p) {
+ mSourceParams.put(p.getParamName(), p);
+ }
+
+ public Type getObjectConstants() {
+ return mPerObjConstants;
+ }
+
+ public Type getShaderConstants() {
+ return mPerObjConstants;
+ }
+
+ void linkConstants(RenderScriptGL rs) {
+ if (mPerShaderConstants == null) {
+ return;
+ }
+
+ Element constElem = mPerShaderConstants.getElement();
+ ShaderParam.fillInParams(constElem, mSourceParams, null, mParamList);
+
+ mConstantBuffer = Allocation.createTyped(rs, mPerShaderConstants);
+
+ ScriptField_ShaderParam_s rsParams = null;
+ int paramCount = mParamList.size();
+ if (paramCount != 0) {
+ rsParams = new ScriptField_ShaderParam_s(rs, paramCount);
+ for (int i = 0; i < paramCount; i++) {
+ rsParams.set(mParamList.get(i).getRSData(rs), i, false);
+ }
+ rsParams.copyAll();
+ mConstantBufferParams = rsParams.getAllocation();
+ }
+ }
+}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java
index 627d3b7..742b14d 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/ShaderParam.java
@@ -18,13 +18,16 @@ package com.android.scenegraph;
import java.lang.Math;
import java.util.ArrayList;
+import java.util.HashMap;
-import android.renderscript.RenderScriptGL;
+import com.android.scenegraph.Transform;
+
+import android.renderscript.Element;
import android.renderscript.Matrix4f;
import android.renderscript.ProgramFragment;
import android.renderscript.ProgramStore;
import android.renderscript.ProgramVertex;
-import android.renderscript.Element;
+import android.renderscript.RenderScriptGL;
import android.util.Log;
/**
@@ -67,6 +70,36 @@ public abstract class ShaderParam extends SceneGraphBase {
String mParamName;
int mOffset;
+ static void fillInParams(Element constantElem,
+ HashMap<String, ShaderParam> sourceParams,
+ Transform transform,
+ ArrayList<ShaderParam> paramList) {
+ int subElemCount = constantElem.getSubElementCount();
+ for (int i = 0; i < subElemCount; i ++) {
+ String inputName = constantElem.getSubElementName(i);
+ int offset = constantElem.getSubElementOffsetBytes(i);
+
+ ShaderParam matchingParam = sourceParams.get(inputName);
+ Element subElem = constantElem.getSubElement(i);
+ // Make one if it's not there
+ if (matchingParam == null) {
+ if (subElem.getDataType() == Element.DataType.FLOAT_32) {
+ matchingParam = new Float4Param(inputName);
+ } else if (subElem.getDataType() == Element.DataType.MATRIX_4X4) {
+ TransformParam trParam = new TransformParam(inputName);
+ trParam.setTransform(transform);
+ matchingParam = trParam;
+ }
+ }
+ matchingParam.setOffset(offset);
+ if (subElem.getDataType() == Element.DataType.FLOAT_32) {
+ Float4Param fParam = (Float4Param)matchingParam;
+ fParam.setVecSize(subElem.getVectorSize());
+ }
+ paramList.add(matchingParam);
+ }
+ }
+
public ShaderParam(String name) {
mParamName = name;
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java
index 8016595..6444c43 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java
@@ -23,6 +23,8 @@ import java.util.Vector;
import com.android.scenegraph.SceneManager;
import com.android.scenegraph.SceneManager.SceneLoadedCallback;
+import com.android.scenegraph.VertexShader;
+import com.android.scenegraph.VertexShader.Builder;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -62,17 +64,19 @@ public class TestAppRS {
private Resources mRes;
private RenderScriptGL mRS;
- private ProgramFragment mPF_Paint;
- private ProgramFragment mPF_Lights;
- private ProgramFragment mPF_Aluminum;
- private ProgramFragment mPF_Plastic;
- private ProgramFragment mPF_Diffuse;
- private ProgramFragment mPF_Texture;
ScriptField_FShaderParams_s mFsConst;
ScriptField_FShaderLightParams_s mFsConst2;
- private ProgramVertex mPV_Paint;
ScriptField_VShaderParams_s mVsConst;
+ // Shaders
+ private FragmentShader mPaintF;
+ private FragmentShader mLightsF;
+ private FragmentShader mAluminumF;
+ private FragmentShader mPlasticF;
+ private FragmentShader mDiffuseF;
+ private FragmentShader mTextureF;
+ private VertexShader mPaintV;
+
private Allocation mDefaultCube;
private Allocation mAllocPV;
private Allocation mEnvCube;
@@ -150,12 +154,12 @@ public class TestAppRS {
protected void onPostExecute(Boolean result) {
if (tempEnv != null) {
mEnvCube = tempEnv;
- mPF_Paint.bindTexture(mEnvCube, 1);
+ mPaintF.mProgram.bindTexture(mEnvCube, 1);
}
if (tempDiff != null) {
mDiffCube = tempDiff;
- mPF_Aluminum.bindTexture(mDiffCube, 1);
+ mAluminumF.mProgram.bindTexture(mDiffCube, 1);
}
}
}
@@ -174,48 +178,47 @@ public class TestAppRS {
mTouchHandler.onActionMove(x, y);
}
- ProgramFragment createFromResource(int id, boolean addCubemap) {
- ProgramFragment.Builder fb = new ProgramFragment.Builder(mRS);
- fb.addConstant(mFsConst.getAllocation().getType());
+ FragmentShader createFromResource(int id, boolean addCubemap) {
+ FragmentShader.Builder fb = new FragmentShader.Builder(mRS);
+ fb.setShaderConst(mFsConst.getAllocation().getType());
fb.setShader(mRes, id);
- fb.addTexture(TextureType.TEXTURE_2D);
+ fb.addTexture(TextureType.TEXTURE_2D, "diffuse");
if (addCubemap) {
- fb.addTexture(TextureType.TEXTURE_CUBE);
+ fb.addTexture(TextureType.TEXTURE_CUBE, "reflection");
}
- ProgramFragment pf = fb.create();
- pf.bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS), 0);
+ FragmentShader pf = fb.create();
+ pf.mProgram.bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS), 0);
if (addCubemap) {
- pf.bindSampler(Sampler.CLAMP_LINEAR_MIP_LINEAR(mRS), 1);
+ pf.mProgram.bindSampler(Sampler.CLAMP_LINEAR_MIP_LINEAR(mRS), 1);
}
return pf;
}
- // All the custom shaders used to render the scene are initialized here
- // This includes stuff like plastic, car paint, etc.
private void initPaintShaders() {
- ProgramVertex.Builder vb = new ProgramVertex.Builder(mRS);
- mVsConst = new ScriptField_VShaderParams_s(mRS, 1);
- vb.addConstant(mVsConst.getAllocation().getType());
+ ScriptField_VObjectParams_s objConst = new ScriptField_VObjectParams_s(mRS, 1);
+ ScriptField_VSParams_s shaderConst = new ScriptField_VSParams_s(mRS, 1);
+
+ VertexShader.Builder vb = new VertexShader.Builder(mRS);
vb.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
vb.setShader(mRes, R.raw.shader2v);
- mPV_Paint = vb.create();
+ vb.setObjectConst(objConst.getAllocation().getType());
+ vb.setShaderConst(shaderConst.getAllocation().getType());
+ mPaintV = vb.create();
mFsConst = new ScriptField_FShaderParams_s(mRS, 1);
mFsConst2 = new ScriptField_FShaderLightParams_s(mRS, 1);
- mPF_Paint = createFromResource(R.raw.paintf, true);
- mPF_Aluminum = createFromResource(R.raw.metal, true);
+ mPaintF = createFromResource(R.raw.paintf, true);
+ mAluminumF = createFromResource(R.raw.metal, true);
- mPF_Plastic = createFromResource(R.raw.plastic, false);
- mPF_Diffuse = createFromResource(R.raw.diffuse, false);
- mPF_Texture = createFromResource(R.raw.texture, false);
+ mPlasticF = createFromResource(R.raw.plastic, false);
+ mDiffuseF = createFromResource(R.raw.diffuse, false);
+ mTextureF = createFromResource(R.raw.texture, false);
- ProgramFragment.Builder fb = new ProgramFragment.Builder(mRS);
- fb.addConstant(mFsConst2.getAllocation().getType());
+ FragmentShader.Builder fb = new FragmentShader.Builder(mRS);
+ fb.setObjectConst(mFsConst2.getAllocation().getType());
fb.setShader(mRes, R.raw.plastic_lights);
- mPF_Lights = fb.create();
-
- FullscreenBlur.initShaders(mRes, mRS);
+ mLightsF = fb.create();
}
void initRenderPasses() {
@@ -242,18 +245,27 @@ public class TestAppRS {
}
}
+ private void addShadersToScene() {
+ mActiveScene.appendShader(mPaintF);
+ mActiveScene.appendShader(mLightsF);
+ mActiveScene.appendShader(mAluminumF);
+ mActiveScene.appendShader(mPlasticF);
+ mActiveScene.appendShader(mDiffuseF);
+ mActiveScene.appendShader(mTextureF);
+ mActiveScene.appendShader(mPaintV);
+ }
+
public void prepareToRender(Scene s) {
mSceneManager.setActiveScene(s);
mActiveScene = s;
- RenderState plastic = new RenderState(mPV_Paint, mPF_Plastic, null, null);
- RenderState diffuse = new RenderState(mPV_Paint, mPF_Diffuse, null, null);
- RenderState paint = new RenderState(mPV_Paint, mPF_Paint, null, null);
- RenderState aluminum = new RenderState(mPV_Paint, mPF_Aluminum, null, null);
- RenderState lights = new RenderState(mPV_Paint, mPF_Lights, null, null);
- RenderState glassTransp = new RenderState(mPV_Paint,
- mPF_Paint,
- ProgramStore.BLEND_ALPHA_DEPTH_TEST(mRS),
- null);
+ addShadersToScene();
+ RenderState plastic = new RenderState(mPaintV, mPlasticF, null, null);
+ RenderState diffuse = new RenderState(mPaintV, mDiffuseF, null, null);
+ RenderState paint = new RenderState(mPaintV, mPaintF, null, null);
+ RenderState aluminum = new RenderState(mPaintV, mAluminumF, null, null);
+ RenderState lights = new RenderState(mPaintV, mLightsF, null, null);
+ RenderState glassTransp = new RenderState(mPaintV, mPaintF,
+ ProgramStore.BLEND_ALPHA_DEPTH_TEST(mRS), null);
initRenderPasses();
@@ -275,7 +287,7 @@ public class TestAppRS {
Renderable plane = (Renderable)mActiveScene.getRenderableByName("pPlaneShape1");
if (plane != null) {
- RenderState texState = new RenderState(mPV_Paint, mPF_Texture, null, null);
+ RenderState texState = new RenderState(mPaintV, mTextureF, null, null);
plane.setRenderState(texState);
plane.setVisible(mRS, !mUseBlur);
}
@@ -297,8 +309,8 @@ public class TestAppRS {
Bitmap b = BitmapFactory.decodeResource(mRes, R.drawable.defaultcube);
mDefaultCube = Allocation.createCubemapFromBitmap(mRS, b);
- mPF_Paint.bindTexture(mDefaultCube, 1);
- mPF_Aluminum.bindTexture(mDefaultCube, 1);
+ mPaintF.mProgram.bindTexture(mDefaultCube, 1);
+ mAluminumF.mProgram.bindTexture(mDefaultCube, 1);
// Reflection maps from SD card
new ImageLoaderTask().execute();
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
index d5e4eb1..dd01554 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
@@ -27,10 +27,9 @@ import android.util.Log;
/**
* @hide
*/
-public class Texture2D extends SceneGraphBase {
+public class Texture2D extends TextureBase {
String mFileName;
String mFileDir;
- Allocation mRsTexture;
public Texture2D() {
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java
new file mode 100644
index 0000000..d6b525b
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureBase.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.scenegraph;
+
+import java.lang.Math;
+
+import com.android.scenegraph.SceneManager;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.util.Log;
+
+/**
+ * @hide
+ */
+public abstract class TextureBase extends SceneGraphBase {
+ protected Allocation mRsTexture;
+ abstract Allocation getRsData(RenderScriptGL rs, Resources res);
+}
+
+
+
+
+
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java
new file mode 100644
index 0000000..fad52d0
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureCube.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.scenegraph;
+
+import java.lang.Math;
+
+import com.android.scenegraph.SceneManager;
+import com.android.scenegraph.TextureBase;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.util.Log;
+
+/**
+ * @hide
+ */
+public class TextureCube extends TextureBase {
+ String mFileName;
+ String mFileDir;
+
+ public TextureCube() {
+ }
+
+ public TextureCube(Allocation tex) {
+ setTexture(tex);
+ }
+
+ public void setFileDir(String dir) {
+ mFileDir = dir;
+ }
+
+ public void setFileName(String file) {
+ mFileName = file;
+ }
+
+ public String getFileName() {
+ return mFileName;
+ }
+
+ public void setTexture(Allocation tex) {
+ mRsTexture = tex;
+ }
+
+ Allocation getRsData(RenderScriptGL rs, Resources res) {
+ if (mRsTexture != null) {
+ return mRsTexture;
+ }
+
+ String shortName = mFileName.substring(mFileName.lastIndexOf('/') + 1);
+ mRsTexture = SceneManager.loadCubemap(mFileDir + shortName, rs, res);
+
+ return mRsTexture;
+ }
+}
+
+
+
+
+
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
index ff91b90..f340841 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TransformParam.java
@@ -69,7 +69,9 @@ public class TransformParam extends ShaderParam {
void initLocalData(RenderScriptGL rs) {
mRsFieldItem.type = getTypeFromName();
mRsFieldItem.bufferOffset = mOffset;
- mRsFieldItem.transform = mTransform.getRSData(rs).getAllocation();
+ if (mTransform != null) {
+ mRsFieldItem.transform = mTransform.getRSData(rs).getAllocation();
+ }
if (mCamera != null) {
mRsFieldItem.camera = mCamera.getRSData(rs).getAllocation();
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java
new file mode 100644
index 0000000..7bf806e
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/VertexShader.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.scenegraph;
+
+import java.lang.Math;
+import java.util.ArrayList;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.util.Log;
+
+/**
+ * @hide
+ */
+public class VertexShader extends Shader {
+ ProgramVertex mProgram;
+ ScriptField_VertexShader_s mField;
+
+ public static class Builder {
+ VertexShader mShader;
+ ProgramVertex.Builder mBuilder;
+
+ public Builder(RenderScriptGL rs) {
+ mShader = new VertexShader();
+ mBuilder = new ProgramVertex.Builder(rs);
+ }
+
+ public Builder setShader(Resources resources, int resourceID) {
+ mBuilder.setShader(resources, resourceID);
+ return this;
+ }
+
+ public Builder setObjectConst(Type type) {
+ mShader.mPerObjConstants = type;
+ return this;
+ }
+
+ public Builder setShaderConst(Type type) {
+ mShader.mPerShaderConstants = type;
+ return this;
+ }
+
+ public Builder addInput(Element e) {
+ mBuilder.addInput(e);
+ return this;
+ }
+
+ VertexShader create() {
+ if (mShader.mPerShaderConstants != null) {
+ mBuilder.addConstant(mShader.mPerShaderConstants);
+ }
+ if (mShader.mPerObjConstants != null) {
+ mBuilder.addConstant(mShader.mPerObjConstants);
+ }
+ mShader.mProgram = mBuilder.create();
+ return mShader;
+ }
+ }
+
+ VertexShader() {
+ }
+
+ public ScriptField_VertexShader_s getRSData(RenderScriptGL rs) {
+ if (mField != null) {
+ return mField;
+ }
+
+ ScriptField_VertexShader_s.Item item = new ScriptField_VertexShader_s.Item();
+ item.program = mProgram;
+
+ linkConstants(rs);
+ if (mPerShaderConstants != null) {
+ item.shaderConst = mConstantBuffer;
+ item.shaderConstParams = mConstantBufferParams;
+ mProgram.bindConstants(item.shaderConst, 0);
+ }
+
+ item.objectConstIndex = -1;
+ if (mPerObjConstants != null) {
+ item.objectConstIndex = mPerShaderConstants != null ? 1 : 0;
+ }
+
+ mField = new ScriptField_VertexShader_s(rs, 1);
+ mField.set(item, 0, true);
+ return mField;
+ }
+}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs
index 95d2a6a..bca6240 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs
@@ -62,7 +62,7 @@ static bool frustumCulled(SgRenderable *obj, SgCamera *cam) {
}
-void root(const rs_allocation *v_in, rs_allocation *v_out, const void *usrData) {
+void root(rs_allocation *v_out, const void *usrData) {
SgRenderable *drawable = (SgRenderable *)rsGetElementAt(*v_out, 0);
const SgCamera *camera = (const SgCamera*)usrData;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs
index 7f7141d..d2f70e6 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs
@@ -27,9 +27,13 @@ SgRenderPass *pExport;
SgCamera *exportPtrCam;
SgLight *exportPtrLight;
SgShaderParam *spExport;
+SgVertexShader *pvExport;
+SgFragmentShader *pfExport;
+
FBlurOffsets *blurExport;
VertexShaderInputs *iExport;
-
VShaderParams *vConst;
FShaderParams *fConst;
FShaderLightParams *fConts2;
+VSParams *vConst2;
+VObjectParams *vConst3;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs
new file mode 100644
index 0000000..d68b1a5
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/fragment_params.rs
@@ -0,0 +1,42 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma version(1)
+
+#pragma rs java_package_name(com.android.scenegraph)
+
+#include "transform_def.rsh"
+
+//#define DEBUG_PARAMS
+
+#include "params.rsh"
+
+void root(rs_allocation *v_out, const void *usrData) {
+
+ SgFragmentShader *shader = (SgFragmentShader *)rsGetElementAt(*v_out, 0);
+ const SgCamera *camera = (const SgCamera*)usrData;
+ if (rsIsObject(shader->shaderConst)) {
+ uint8_t *constantBuffer = (uint8_t*)rsGetElementAt(shader->shaderConst, 0);
+
+ int numParams = 0;
+ if (rsIsObject(shader->shaderConstParams)) {
+ numParams = rsAllocationGetDimX(shader->shaderConstParams);
+ }
+ for (int i = 0; i < numParams; i ++) {
+ SgShaderParam *current = (SgShaderParam*)rsGetElementAt(shader->shaderConstParams, i);
+ processParam(current, constantBuffer, camera);
+ }
+ rsgAllocationSyncAll(shader->shaderConst);
+ }
+}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs
new file mode 100644
index 0000000..a122bd9f
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/object_params.rs
@@ -0,0 +1,62 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma version(1)
+
+#pragma rs java_package_name(com.android.scenegraph)
+
+#include "transform_def.rsh"
+
+//#define DEBUG_PARAMS
+
+#include "params.rsh"
+
+void root(rs_allocation *v_out, const void *usrData) {
+
+ SgRenderable *drawable = (SgRenderable *)rsGetElementAt(*v_out, 0);
+ // Visibility flag was set earlier in the cull stage
+ if (!drawable->isVisible) {
+ return;
+ }
+
+ const SgCamera *camera = (const SgCamera*)usrData;
+ // Data we are updating
+ if (rsIsObject(drawable->pf_const)) {
+ uint8_t *constantBuffer = (uint8_t*)rsGetElementAt(drawable->pf_const, 0);
+
+ int numParams = 0;
+ if (rsIsObject(drawable->pf_constParams)) {
+ numParams = rsAllocationGetDimX(drawable->pf_constParams);
+ }
+ for (int i = 0; i < numParams; i ++) {
+ SgShaderParam *current = (SgShaderParam*)rsGetElementAt(drawable->pf_constParams, i);
+ processParam(current, constantBuffer, camera);
+ }
+ //rsgAllocationSyncAll(drawable->pf_const);
+ }
+
+ if (rsIsObject(drawable->pv_const)) {
+ uint8_t *constantBuffer = (uint8_t*)rsGetElementAt(drawable->pv_const, 0);
+
+ int numParams = 0;
+ if (rsIsObject(drawable->pv_constParams)) {
+ numParams = rsAllocationGetDimX(drawable->pv_constParams);
+ }
+ for (int i = 0; i < numParams; i ++) {
+ SgShaderParam *current = (SgShaderParam*)rsGetElementAt(drawable->pv_constParams, i);
+ processParam(current, constantBuffer, camera);
+ }
+ //rsgAllocationSyncAll(drawable->pv_const);
+ }
+}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh
index 7977698d..e7adb66 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rs
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rsh
@@ -112,42 +112,3 @@ static void processParam(SgShaderParam *p, uint8_t *constantBuffer, const SgCame
break;
}
}
-
-void root(const rs_allocation *v_in, rs_allocation *v_out, const void *usrData) {
-
- SgRenderable *drawable = (SgRenderable *)rsGetElementAt(*v_out, 0);
- // Visibility flag was set earlier in the cull stage
- if (!drawable->isVisible) {
- return;
- }
-
- const SgCamera *camera = (const SgCamera*)usrData;
- // Data we are updating
- if (rsIsObject(drawable->pf_const)) {
- uint8_t *constantBuffer = (uint8_t*)rsGetElementAt(drawable->pf_const, 0);
-
- int numParams = 0;
- if (rsIsObject(drawable->pf_constParams)) {
- numParams = rsAllocationGetDimX(drawable->pf_constParams);
- }
- for (int i = 0; i < numParams; i ++) {
- SgShaderParam *current = (SgShaderParam*)rsGetElementAt(drawable->pf_constParams, i);
- processParam(current, constantBuffer, camera);
- }
- //rsgAllocationSyncAll(drawable->pf_const);
- }
-
- if (rsIsObject(drawable->pv_const)) {
- uint8_t *constantBuffer = (uint8_t*)rsGetElementAt(drawable->pv_const, 0);
-
- int numParams = 0;
- if (rsIsObject(drawable->pv_constParams)) {
- numParams = rsAllocationGetDimX(drawable->pv_constParams);
- }
- for (int i = 0; i < numParams; i ++) {
- SgShaderParam *current = (SgShaderParam*)rsGetElementAt(drawable->pv_constParams, i);
- processParam(current, constantBuffer, camera);
- }
- //rsgAllocationSyncAll(drawable->pv_const);
- }
-}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs
index cae6d27..afe5fa6 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs
@@ -22,12 +22,16 @@
rs_script gTransformScript;
rs_script gCameraScript;
rs_script gLightScript;
-rs_script gParamsScript;
+rs_script gObjectParamsScript;
+rs_script gFragmentParamsScript;
+rs_script gVertexParamsScript;
rs_script gCullScript;
SgTransform *gRootNode;
rs_allocation gCameras;
rs_allocation gLights;
+rs_allocation gFragmentShaders;
+rs_allocation gVertexShaders;
rs_allocation gRenderableObjects;
rs_allocation gRenderPasses;
@@ -57,11 +61,14 @@ static void draw(SgRenderable *obj) {
printName(obj->name);
#endif //DEBUG_RENDERABLES
- if (rsIsObject(obj->pv_const)) {
- rsgBindConstant(renderState->pv, 0, obj->pv_const);
+ const SgVertexShader *pv = (const SgVertexShader *)rsGetElementAt(renderState->pv, 0);
+ const SgFragmentShader *pf = (const SgFragmentShader *)rsGetElementAt(renderState->pf, 0);
+
+ if (pv->objectConstIndex != -1) {
+ rsgBindConstant(pv->program, pv->objectConstIndex, obj->pv_const);
}
- if (rsIsObject(obj->pf_const)) {
- rsgBindConstant(renderState->pf, 0, obj->pf_const);
+ if (pf->objectConstIndex != -1) {
+ rsgBindConstant(pf->program, pf->objectConstIndex, obj->pf_const);
}
if (rsIsObject(renderState->ps)) {
@@ -77,14 +84,14 @@ static void draw(SgRenderable *obj) {
rsgBindProgramRaster(pr);
}
- rsgBindProgramFragment(renderState->pf);
- rsgBindProgramVertex(renderState->pv);
+ rsgBindProgramVertex(pv->program);
+ rsgBindProgramFragment(pf->program);
for (uint32_t i = 0; i < obj->pf_num_textures; i ++) {
if (rsIsObject(obj->pf_textures[i])) {
- rsgBindTexture(renderState->pf, i, obj->pf_textures[i]);
+ rsgBindTexture(pf->program, i, obj->pf_textures[i]);
} else {
- rsgBindTexture(renderState->pf, i, gTGrid);
+ rsgBindTexture(pf->program, i, gTGrid);
}
}
@@ -138,9 +145,14 @@ static void drawAllObjects(rs_allocation allObj) {
return;
}
+ rsForEach(gVertexParamsScript, nullAlloc, gVertexShaders,
+ gActiveCamera, sizeof(gActiveCamera));
+ rsForEach(gFragmentParamsScript, nullAlloc, gFragmentShaders,
+ gActiveCamera, sizeof(gActiveCamera));
+
// Run the params and cull script
rsForEach(gCullScript, nullAlloc, allObj, gActiveCamera, sizeof(gActiveCamera));
- rsForEach(gParamsScript, nullAlloc, allObj, gActiveCamera, sizeof(gActiveCamera));
+ rsForEach(gObjectParamsScript, nullAlloc, allObj, gActiveCamera, sizeof(gActiveCamera));
int numRenderables = rsAllocationGetDimX(allObj);
for (int i = 0; i < numRenderables; i ++) {
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh
index e1ce287..2b16652 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh
@@ -22,6 +22,14 @@ typedef struct VShaderParams_s {
rs_matrix4x4 viewProj;
} VShaderParams;
+typedef struct VSParams_s {
+ rs_matrix4x4 viewProj;
+} VSParams;
+
+typedef struct VObjectParams_s {
+ rs_matrix4x4 model;
+} VObjectParams;
+
typedef struct FShaderParams_s {
float4 cameraPos;
} FShaderParams;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh
index 5c687cc..e3df60e 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh
@@ -16,6 +16,9 @@
#pragma rs java_package_name(com.android.scenegraph)
+#ifndef _TRANSFORM_DEF_
+#define _TRANSFORM_DEF_
+
#include "rs_graphics.rsh"
#define TRANSFORM_NONE 0
@@ -61,9 +64,29 @@ typedef struct __attribute__((packed, aligned(4))) SgTransform {
rs_allocation name;
} SgTransform;
+typedef struct VertexShader_s {
+ rs_program_vertex program;
+ // Buffer with vertex constant data
+ rs_allocation shaderConst;
+ // ShaderParam's that populate data
+ rs_allocation shaderConstParams;
+ // location of the per object constants on the buffer
+ int objectConstIndex;
+} SgVertexShader;
+
+typedef struct FragmentShader_s {
+ rs_program_fragment program;
+ // Buffer with vertex constant data
+ rs_allocation shaderConst;
+ // ShaderParam's that populate data
+ rs_allocation shaderConstParams;
+ // location of the per object constants on the buffer
+ int objectConstIndex;
+} SgFragmentShader;
+
typedef struct RenderState_s {
- rs_program_vertex pv;
- rs_program_fragment pf;
+ rs_allocation pv; // VertexShader struct
+ rs_allocation pf; // FragmentShader struct
rs_program_store ps;
rs_program_raster pr;
} SgRenderState;
@@ -223,3 +246,5 @@ static void getCameraRay(const SgCamera *cam, int screenX, int screenY, float3 *
rsDebug("Vec Z", vec->z);
*pnt = cam->position.xyz;
}
+
+#endif // _TRANSFORM_DEF_
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs
new file mode 100644
index 0000000..f67379e
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/vertex_params.rs
@@ -0,0 +1,42 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma version(1)
+
+#pragma rs java_package_name(com.android.scenegraph)
+
+#include "transform_def.rsh"
+
+//#define DEBUG_PARAMS
+
+#include "params.rsh"
+
+void root(rs_allocation *v_out, const void *usrData) {
+
+ SgVertexShader *shader = (SgVertexShader *)rsGetElementAt(*v_out, 0);
+ const SgCamera *camera = (const SgCamera*)usrData;
+ if (rsIsObject(shader->shaderConst)) {
+ uint8_t *constantBuffer = (uint8_t*)rsGetElementAt(shader->shaderConst, 0);
+
+ int numParams = 0;
+ if (rsIsObject(shader->shaderConstParams)) {
+ numParams = rsAllocationGetDimX(shader->shaderConstParams);
+ }
+ for (int i = 0; i < numParams; i ++) {
+ SgShaderParam *current = (SgShaderParam*)rsGetElementAt(shader->shaderConstParams, i);
+ processParam(current, constantBuffer, camera);
+ }
+ rsgAllocationSyncAll(shader->shaderConst);
+ }
+}