summaryrefslogtreecommitdiffstats
path: root/tests/RenderScriptTests/SceneGraph/src
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2012-01-17 17:35:31 -0800
committerAlex Sakhartchouk <alexst@google.com>2012-01-17 17:35:31 -0800
commitce047cb47b761f00593f247a3901fe8155371d47 (patch)
treec726e286e0f4ce2fbf26f755ffb3ee909a811736 /tests/RenderScriptTests/SceneGraph/src
parent81aee81850a8213dfc10cc81e332063ae49d2bd1 (diff)
downloadframeworks_base-ce047cb47b761f00593f247a3901fe8155371d47.zip
frameworks_base-ce047cb47b761f00593f247a3901fe8155371d47.tar.gz
frameworks_base-ce047cb47b761f00593f247a3901fe8155371d47.tar.bz2
Fixing blur passes. Refactoring.
Change-Id: Ie511e7738e2cf259231f48250421b5e340d38565
Diffstat (limited to 'tests/RenderScriptTests/SceneGraph/src')
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FullscreenBlur.java196
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java12
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java6
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java8
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java5
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs86
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs1
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rs70
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs10
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh49
-rw-r--r--tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh94
11 files changed, 283 insertions, 254 deletions
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FullscreenBlur.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FullscreenBlur.java
index ffe0092..e0b4aae 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FullscreenBlur.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/FullscreenBlur.java
@@ -20,6 +20,9 @@ package com.android.scenegraph;
import java.util.ArrayList;
import com.android.scenegraph.Float4Param;
+import com.android.scenegraph.SceneManager;
+import com.android.scenegraph.Texture2D;
+import com.android.scenegraph.TextureParam;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -57,159 +60,115 @@ class FullscreenBlur {
Type.Builder b = new Type.Builder(rs, Element.RGBA_8888(rs));
b.setX(w/8).setY(h/8);
Type renderType = b.create();
- sRenderTargetBlur0Color = Allocation.createTyped(rs, renderType,
- Allocation.USAGE_GRAPHICS_TEXTURE |
- Allocation.USAGE_GRAPHICS_RENDER_TARGET);
- sRenderTargetBlur1Color = Allocation.createTyped(rs, renderType,
- Allocation.USAGE_GRAPHICS_TEXTURE |
- Allocation.USAGE_GRAPHICS_RENDER_TARGET);
- sRenderTargetBlur2Color = Allocation.createTyped(rs, renderType,
- Allocation.USAGE_GRAPHICS_TEXTURE |
- Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-
- b = new Type.Builder(rs,
- Element.createPixel(rs, Element.DataType.UNSIGNED_16,
- Element.DataKind.PIXEL_DEPTH));
+ int usage = Allocation.USAGE_GRAPHICS_TEXTURE | Allocation.USAGE_GRAPHICS_RENDER_TARGET;
+ sRenderTargetBlur0Color = Allocation.createTyped(rs, renderType, usage);
+ sRenderTargetBlur1Color = Allocation.createTyped(rs, renderType, usage);
+ sRenderTargetBlur2Color = Allocation.createTyped(rs, renderType, usage);
+
+ b = new Type.Builder(rs, Element.createPixel(rs, Element.DataType.UNSIGNED_16,
+ Element.DataKind.PIXEL_DEPTH));
b.setX(w/8).setY(h/8);
- sRenderTargetBlur0Depth = Allocation.createTyped(rs,
- b.create(),
- Allocation.USAGE_GRAPHICS_RENDER_TARGET);
-
- sRenderTargetBlur1Depth = Allocation.createTyped(rs,
- b.create(),
- Allocation.USAGE_GRAPHICS_RENDER_TARGET);
- sRenderTargetBlur2Depth = Allocation.createTyped(rs,
- b.create(),
- Allocation.USAGE_GRAPHICS_RENDER_TARGET);
+ renderType = b.create();
+ usage = Allocation.USAGE_GRAPHICS_RENDER_TARGET;
+ sRenderTargetBlur0Depth = Allocation.createTyped(rs, renderType, usage);
+ sRenderTargetBlur1Depth = Allocation.createTyped(rs, renderType, usage);
+ sRenderTargetBlur2Depth = Allocation.createTyped(rs, renderType, usage);
}
- static void addBlurPasses(Scene scene, RenderScriptGL rs, SceneManager sceneManager) {
- ArrayList<RenderableBase> allDraw = scene.getRenderables();
- int numDraw = allDraw.size();
+ static void addOffsets(Renderable quad, float advance) {
+ quad.appendSourceParams(new Float4Param("blurOffset0", - advance * 2.5f));
+ quad.appendSourceParams(new Float4Param("blurOffset1", - advance * 0.5f));
+ quad.appendSourceParams(new Float4Param("blurOffset2", advance * 1.5f));
+ quad.appendSourceParams(new Float4Param("blurOffset3", advance * 3.5f));
+ }
- RenderState drawTex = new RenderState(mPV_Blur, mPF_Texture,
- BLEND_ADD_DEPTH_NONE(rs),
- ProgramRaster.CULL_NONE(rs));
+ static RenderPass addPass(Scene scene, Allocation color, Allocation depth) {
+ RenderPass pass = new RenderPass();
+ pass.setColorTarget(color);
+ pass.setDepthTarget(depth);
+ pass.setShouldClearColor(false);
+ pass.setShouldClearDepth(false);
+ pass.setCamera(scene.getCameras().get(1));
+ scene.appendRenderPass(pass);
+ return pass;
+ }
- RenderState selectCol = new RenderState(mPV_Blur, mPF_SelectColor,
- ProgramStore.BLEND_NONE_DEPTH_NONE(rs),
- ProgramRaster.CULL_NONE(rs));
+ static void addBlurPasses(Scene scene, RenderScriptGL rs) {
+ SceneManager sceneManager = SceneManager.getInstance();
+ ArrayList<RenderableBase> allDraw = scene.getRenderables();
+ int numDraw = allDraw.size();
- RenderState hBlur = new RenderState(mPV_Blur, mPF_BlurH,
- ProgramStore.BLEND_NONE_DEPTH_NONE(rs),
- ProgramRaster.CULL_NONE(rs));
+ ProgramRaster cullNone = ProgramRaster.CULL_NONE(rs);
+ ProgramStore blendAdd = SceneManager.BLEND_ADD_DEPTH_NONE(rs);
+ ProgramStore blendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(rs);
- RenderState vBlur = new RenderState(mPV_Blur, mPF_BlurV,
- ProgramStore.BLEND_NONE_DEPTH_NONE(rs),
- ProgramRaster.CULL_NONE(rs));
+ RenderState drawTex = new RenderState(mPV_Blur, mPF_Texture, blendAdd, cullNone);
+ RenderState selectCol = new RenderState(mPV_Blur, mPF_SelectColor, blendNone, cullNone);
+ RenderState hBlur = new RenderState(mPV_Blur, mPF_BlurH, blendNone, cullNone);
+ RenderState vBlur = new RenderState(mPV_Blur, mPF_BlurV, blendNone, cullNone);
- RenderPass blurSourcePass = new RenderPass();
- blurSourcePass.setColorTarget(sRenderTargetBlur0Color);
- blurSourcePass.setDepthTarget(sRenderTargetBlur0Depth);
+ // Renders the scene off screen
+ RenderPass blurSourcePass = addPass(scene,
+ sRenderTargetBlur0Color,
+ sRenderTargetBlur0Depth);
blurSourcePass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 1.0f));
blurSourcePass.setShouldClearColor(true);
blurSourcePass.setClearDepth(1.0f);
blurSourcePass.setShouldClearDepth(true);
- blurSourcePass.setCamera(scene.getCameras().get(1));
for (int i = 0; i < numDraw; i ++) {
blurSourcePass.appendRenderable((Renderable)allDraw.get(i));
}
- scene.appendRenderPass(blurSourcePass);
-
- RenderPass selectColorPass = new RenderPass();
- selectColorPass.setColorTarget(sRenderTargetBlur2Color);
- selectColorPass.setDepthTarget(sRenderTargetBlur2Depth);
- selectColorPass.setShouldClearColor(false);
- selectColorPass.setShouldClearDepth(false);
- selectColorPass.setCamera(scene.getCameras().get(1));
- // Make blur shape
+
+ // Pass for selecting bright colors
+ RenderPass selectColorPass = addPass(scene,
+ sRenderTargetBlur2Color,
+ sRenderTargetBlur2Depth);
Renderable quad = sceneManager.getRenderableQuad("ScreenAlignedQuadS", selectCol);
- quad.updateTextures(rs, sRenderTargetBlur0Color, 0);
+ quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur0Color)));
selectColorPass.appendRenderable(quad);
- scene.appendRenderPass(selectColorPass);
-
- RenderPass horizontalBlurPass = new RenderPass();
- horizontalBlurPass.setColorTarget(sRenderTargetBlur1Color);
- horizontalBlurPass.setDepthTarget(sRenderTargetBlur1Depth);
- horizontalBlurPass.setShouldClearColor(false);
- horizontalBlurPass.setShouldClearDepth(false);
- horizontalBlurPass.setCamera(scene.getCameras().get(1));
- // Make blur shape
- quad = sceneManager.getRenderableQuad("ScreenAlignedQuadH", hBlur);
- quad.updateTextures(rs, sRenderTargetBlur2Color, 0);
-
- float xAdvance = 1.0f / (float)sRenderTargetBlur0Color.getType().getX();
- quad.appendSourceParams(new Float4Param("blurOffset0", - xAdvance * 2.5f));
- quad.appendSourceParams(new Float4Param("blurOffset1", - xAdvance * 0.5f));
- quad.appendSourceParams(new Float4Param("blurOffset2", xAdvance * 1.5f));
- quad.appendSourceParams(new Float4Param("blurOffset3", xAdvance * 3.5f));
+ // Horizontal blur
+ RenderPass horizontalBlurPass = addPass(scene,
+ sRenderTargetBlur1Color,
+ sRenderTargetBlur1Depth);
+ quad = sceneManager.getRenderableQuad("ScreenAlignedQuadH", hBlur);
+ quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur2Color)));
+ addOffsets(quad, 1.0f / (float)sRenderTargetBlur0Color.getType().getX());
horizontalBlurPass.appendRenderable(quad);
- scene.appendRenderPass(horizontalBlurPass);
-
- RenderPass verticalBlurPass = new RenderPass();
- verticalBlurPass.setColorTarget(sRenderTargetBlur2Color);
- verticalBlurPass.setDepthTarget(sRenderTargetBlur2Depth);
- verticalBlurPass.setShouldClearColor(false);
- verticalBlurPass.setShouldClearDepth(false);
- verticalBlurPass.setCamera(scene.getCameras().get(1));
- // Make blur shape
- quad = sceneManager.getRenderableQuad("ScreenAlignedQuadV", vBlur);
- quad.updateTextures(rs, sRenderTargetBlur1Color, 0);
- float yAdvance = 1.0f / (float)sRenderTargetBlur0Color.getType().getY();
- quad.appendSourceParams(new Float4Param("blurOffset0", - yAdvance * 2.5f));
- quad.appendSourceParams(new Float4Param("blurOffset1", - yAdvance * 0.5f));
- quad.appendSourceParams(new Float4Param("blurOffset2", yAdvance * 1.5f));
- quad.appendSourceParams(new Float4Param("blurOffset3", yAdvance * 3.5f));
+ // Vertical Blur
+ RenderPass verticalBlurPass = addPass(scene,
+ sRenderTargetBlur2Color,
+ sRenderTargetBlur2Depth);
+ quad = sceneManager.getRenderableQuad("ScreenAlignedQuadV", vBlur);
+ quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur1Color)));
+ addOffsets(quad, 1.0f / (float)sRenderTargetBlur0Color.getType().getY());
verticalBlurPass.appendRenderable(quad);
- scene.appendRenderPass(verticalBlurPass);
-
}
- static void addCompositePass(Scene scene, RenderScriptGL rs, SceneManager sceneManager) {
+ // Additively renders the blurred colors on top of the scene
+ static void addCompositePass(Scene scene, RenderScriptGL rs) {
+ SceneManager sceneManager = SceneManager.getInstance();
RenderState drawTex = new RenderState(mPV_Blur, mPF_Texture,
- BLEND_ADD_DEPTH_NONE(rs),
- ProgramRaster.CULL_NONE(rs));
-
- RenderPass compositePass = new RenderPass();
- compositePass.setClearColor(new Float4(1.0f, 1.0f, 1.0f, 0.0f));
- compositePass.setShouldClearColor(false);
- compositePass.setClearDepth(1.0f);
- compositePass.setShouldClearDepth(false);
- compositePass.setCamera(scene.getCameras().get(1));
+ SceneManager.BLEND_ADD_DEPTH_NONE(rs),
+ ProgramRaster.CULL_NONE(rs));
+
+ RenderPass compositePass = addPass(scene, null, null);
Renderable quad = sceneManager.getRenderableQuad("ScreenAlignedQuad", drawTex);
- quad.updateTextures(rs, sRenderTargetBlur2Color, 0);
+ quad.appendSourceParams(new TextureParam("tex0", new Texture2D(sRenderTargetBlur2Color)));
compositePass.appendRenderable(quad);
-
- scene.appendRenderPass(compositePass);
- }
-
- private static ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) {
- ProgramStore.Builder builder = new ProgramStore.Builder(rs);
- builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
- builder.setBlendFunc(ProgramStore.BlendSrcFunc.ONE, ProgramStore.BlendDstFunc.ONE);
- builder.setDitherEnabled(false);
- builder.setDepthMaskEnabled(false);
- return builder.create();
}
- static void initShaders(Resources res, RenderScript rs,
- ScriptField_VShaderParams_s vsConst,
- ScriptField_FShaderParams_s fsConst) {
+ static void initShaders(Resources res, RenderScript rs) {
ProgramVertex.Builder vb = new ProgramVertex.Builder(rs);
- vb.addConstant(vsConst.getAllocation().getType());
vb.addInput(ScriptField_VertexShaderInputs_s.createElement(rs));
vb.setShader(res, R.raw.blur_vertex);
mPV_Blur = vb.create();
- mPV_Blur.bindConstants(vsConst.getAllocation(), 0);
ProgramFragment.Builder fb = new ProgramFragment.Builder(rs);
- fb.addConstant(fsConst.getAllocation().getType());
fb.setShader(res, R.raw.texture);
fb.addTexture(TextureType.TEXTURE_2D);
mPF_Texture = fb.create();
- mPF_Texture.bindConstants(fsConst.getAllocation(), 0);
mPF_Texture.bindSampler(Sampler.WRAP_LINEAR_MIP_LINEAR(rs), 0);
mFsBlurHConst = new ScriptField_FBlurOffsets_s(rs, 1);
@@ -219,7 +178,6 @@ class FullscreenBlur {
fb.setShader(res, R.raw.blur_h);
fb.addTexture(TextureType.TEXTURE_2D);
mPF_BlurH = fb.create();
- mPF_BlurH.bindTexture(sRenderTargetBlur0Color, 0);
mPF_BlurH.bindSampler(Sampler.CLAMP_LINEAR(rs), 0);
mFsBlurVConst = new ScriptField_FBlurOffsets_s(rs, 1);
@@ -230,16 +188,12 @@ class FullscreenBlur {
fb.addTexture(TextureType.TEXTURE_2D);
mPF_BlurV = fb.create();
- mPF_BlurV.bindTexture(sRenderTargetBlur1Color, 0);
mPF_BlurV.bindSampler(Sampler.CLAMP_LINEAR(rs), 0);
fb = new ProgramFragment.Builder(rs);
- //fb.addConstant(mFsBlurVConst.getAllocation().getType());
fb.setShader(res, R.raw.select_color);
fb.addTexture(TextureType.TEXTURE_2D);
mPF_SelectColor = fb.create();
- //mPF_SelectColor.bindConstants(mFsBlurVConst.getAllocation(), 0);
- //mPF_SelectColor.bindTexture(sRenderTargetBlur1Color, 0);
mPF_SelectColor.bindSampler(Sampler.CLAMP_LINEAR(rs), 0);
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
index 5232a64..e99d710 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/SceneManager.java
@@ -50,6 +50,7 @@ public class SceneManager extends SceneGraphBase {
ScriptC_camera mCameraScript;
ScriptC_light mLightScript;
ScriptC_params mParamsScript;
+ ScriptC_cull mCullScript;
ScriptC_transform mTransformScript;
RenderScriptGL mRS;
@@ -112,6 +113,15 @@ public class SceneManager extends SceneGraphBase {
Allocation.USAGE_GRAPHICS_TEXTURE);
}
+ public static ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) {
+ ProgramStore.Builder builder = new ProgramStore.Builder(rs);
+ builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
+ builder.setBlendFunc(ProgramStore.BlendSrcFunc.ONE, ProgramStore.BlendDstFunc.ONE);
+ builder.setDitherEnabled(false);
+ builder.setDepthMaskEnabled(false);
+ return builder.create();
+ }
+
static Allocation getStringAsAllocation(RenderScript rs, String str) {
if (str == null) {
return null;
@@ -212,12 +222,14 @@ 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);
+ 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_gCullScript(mCullScript);
Allocation checker = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.checker,
MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java
index 3e88afb..8016595 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TestAppRS.java
@@ -215,7 +215,7 @@ public class TestAppRS {
fb.setShader(mRes, R.raw.plastic_lights);
mPF_Lights = fb.create();
- FullscreenBlur.initShaders(mRes, mRS, mVsConst, mFsConst);
+ FullscreenBlur.initShaders(mRes, mRS);
}
void initRenderPasses() {
@@ -223,7 +223,7 @@ public class TestAppRS {
int numDraw = allDraw.size();
if (mUseBlur) {
- FullscreenBlur.addBlurPasses(mActiveScene, mRS, mSceneManager);
+ FullscreenBlur.addBlurPasses(mActiveScene, mRS);
}
RenderPass mainPass = new RenderPass();
@@ -238,7 +238,7 @@ public class TestAppRS {
mActiveScene.appendRenderPass(mainPass);
if (mUseBlur) {
- FullscreenBlur.addCompositePass(mActiveScene, mRS, mSceneManager);
+ FullscreenBlur.addCompositePass(mActiveScene, mRS);
}
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
index 76ac629..d5e4eb1 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Texture2D.java
@@ -35,6 +35,10 @@ public class Texture2D extends SceneGraphBase {
public Texture2D() {
}
+ public Texture2D(Allocation tex) {
+ setTexture(tex);
+ }
+
public void setFileDir(String dir) {
mFileDir = dir;
}
@@ -47,6 +51,10 @@ public class Texture2D extends SceneGraphBase {
return mFileName;
}
+ public void setTexture(Allocation tex) {
+ mRsTexture = tex;
+ }
+
Allocation getRsData(RenderScriptGL rs, Resources res) {
if (mRsTexture != null) {
return mRsTexture;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java
index af22201..df7147a 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/TextureParam.java
@@ -40,6 +40,11 @@ public class TextureParam extends ShaderParam {
super(name);
}
+ public TextureParam(String name, Texture2D t) {
+ super(name);
+ setTexture(t);
+ }
+
public void setTexture(Texture2D t) {
mTexture = t;
}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs
new file mode 100644
index 0000000..95d2a6a
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/cull.rs
@@ -0,0 +1,86 @@
+// 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"
+
+static void getTransformedSphere(SgRenderable *obj) {
+ obj->worldBoundingSphere = obj->boundingSphere;
+ obj->worldBoundingSphere.w = 1.0f;
+ const SgTransform *objTransform = (const SgTransform *)rsGetElementAt(obj->transformMatrix, 0);
+ obj->worldBoundingSphere = rsMatrixMultiply(&objTransform->globalMat, obj->worldBoundingSphere);
+
+ const float4 unitVec = {0.57735f, 0.57735f, 0.57735f, 0.0f};
+ float4 scaledVec = rsMatrixMultiply(&objTransform->globalMat, unitVec);
+ scaledVec.w = 0.0f;
+ obj->worldBoundingSphere.w = obj->boundingSphere.w * length(scaledVec);
+}
+
+static bool frustumCulled(SgRenderable *obj, SgCamera *cam) {
+ if (!obj->bVolInitialized) {
+ float minX, minY, minZ, maxX, maxY, maxZ;
+ rsgMeshComputeBoundingBox(obj->mesh,
+ &minX, &minY, &minZ,
+ &maxX, &maxY, &maxZ);
+ //rsDebug("min", minX, minY, minZ);
+ //rsDebug("max", maxX, maxY, maxZ);
+ float4 sphere;
+ sphere.x = (maxX + minX) * 0.5f;
+ sphere.y = (maxY + minY) * 0.5f;
+ sphere.z = (maxZ + minZ) * 0.5f;
+ float3 radius;
+ radius.x = (maxX - sphere.x);
+ radius.y = (maxY - sphere.y);
+ radius.z = (maxZ - sphere.z);
+
+ sphere.w = length(radius);
+ obj->boundingSphere = sphere;
+ obj->bVolInitialized = 1;
+ //rsDebug("Sphere", sphere);
+ }
+
+ getTransformedSphere(obj);
+
+ return !rsIsSphereInFrustum(&obj->worldBoundingSphere,
+ &cam->frustumPlanes[0], &cam->frustumPlanes[1],
+ &cam->frustumPlanes[2], &cam->frustumPlanes[3],
+ &cam->frustumPlanes[4], &cam->frustumPlanes[5]);
+}
+
+
+void root(const rs_allocation *v_in, rs_allocation *v_out, const void *usrData) {
+
+ SgRenderable *drawable = (SgRenderable *)rsGetElementAt(*v_out, 0);
+ const SgCamera *camera = (const SgCamera*)usrData;
+
+ drawable->isVisible = 0;
+ // Not loaded yet
+ if (!rsIsObject(drawable->mesh) || drawable->cullType == CULL_ALWAYS) {
+ return;
+ }
+
+ // check to see if we are culling this object and if it's
+ // outside the frustum
+ if (drawable->cullType == CULL_FRUSTUM && frustumCulled(drawable, (SgCamera*)camera)) {
+#ifdef DEBUG_RENDERABLES
+ rsDebug("Culled", drawable);
+ printName(drawable->name);
+#endif // DEBUG_RENDERABLES
+ return;
+ }
+ drawable->isVisible = 1;
+}
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs
index 0976afa..7f7141d 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs
@@ -19,6 +19,7 @@
// The sole purpose of this script is to have various structs exposed
// so that java reflected classes are generated
#include "transform_def.rsh"
+#include "testApp.rsh"
SgTransform *exportPtr;
SgRenderState *sExport;
SgRenderable *drExport;
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rs
index 61dc482..7977698d 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rs
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/params.rs
@@ -31,13 +31,10 @@ static void writeFloatData(float *ptr, const float4 *input, uint32_t vecSize) {
*ptr = input->x;
break;
case 2:
- *ptr++ = input->x;
- *ptr = input->y;
+ *((float2*)ptr) = (*input).xy;
break;
case 3:
- *ptr++ = input->x;
- *ptr++ = input->y;
- *ptr = input->z;
+ *((float3*)ptr) = (*input).xyz;
break;
case 4:
*((float4*)ptr) = *input;
@@ -116,72 +113,15 @@ static void processParam(SgShaderParam *p, uint8_t *constantBuffer, const SgCame
}
}
-static void getTransformedSphere(SgRenderable *obj) {
- obj->worldBoundingSphere = obj->boundingSphere;
- obj->worldBoundingSphere.w = 1.0f;
- const SgTransform *objTransform = (const SgTransform *)rsGetElementAt(obj->transformMatrix, 0);
- obj->worldBoundingSphere = rsMatrixMultiply(&objTransform->globalMat, obj->worldBoundingSphere);
-
- const float4 unitVec = {0.57735f, 0.57735f, 0.57735f, 0.0f};
- float4 scaledVec = rsMatrixMultiply(&objTransform->globalMat, unitVec);
- scaledVec.w = 0.0f;
- obj->worldBoundingSphere.w = obj->boundingSphere.w * length(scaledVec);
-}
-
-static bool frustumCulled(SgRenderable *obj, SgCamera *cam) {
- if (!obj->bVolInitialized) {
- float minX, minY, minZ, maxX, maxY, maxZ;
- rsgMeshComputeBoundingBox(obj->mesh,
- &minX, &minY, &minZ,
- &maxX, &maxY, &maxZ);
- //rsDebug("min", minX, minY, minZ);
- //rsDebug("max", maxX, maxY, maxZ);
- float4 sphere;
- sphere.x = (maxX + minX) * 0.5f;
- sphere.y = (maxY + minY) * 0.5f;
- sphere.z = (maxZ + minZ) * 0.5f;
- float3 radius;
- radius.x = (maxX - sphere.x);
- radius.y = (maxY - sphere.y);
- radius.z = (maxZ - sphere.z);
-
- sphere.w = length(radius);
- obj->boundingSphere = sphere;
- obj->bVolInitialized = 1;
- //rsDebug("Sphere", sphere);
- }
-
- getTransformedSphere(obj);
-
- return !rsIsSphereInFrustum(&obj->worldBoundingSphere,
- &cam->frustumPlanes[0], &cam->frustumPlanes[1],
- &cam->frustumPlanes[2], &cam->frustumPlanes[3],
- &cam->frustumPlanes[4], &cam->frustumPlanes[5]);
-}
-
-
void root(const rs_allocation *v_in, rs_allocation *v_out, const void *usrData) {
SgRenderable *drawable = (SgRenderable *)rsGetElementAt(*v_out, 0);
- const SgCamera *camera = (const SgCamera*)usrData;
-
- drawable->isVisible = 0;
- // Not loaded yet
- if (!rsIsObject(drawable->mesh) || drawable->cullType == CULL_ALWAYS) {
+ // Visibility flag was set earlier in the cull stage
+ if (!drawable->isVisible) {
return;
}
- // check to see if we are culling this object and if it's
- // outside the frustum
- if (drawable->cullType == CULL_FRUSTUM && frustumCulled(drawable, (SgCamera*)camera)) {
-#ifdef DEBUG_RENDERABLES
- rsDebug("Culled", drawable);
- printName(drawable->name);
-#endif // DEBUG_RENDERABLES
- return;
- }
- drawable->isVisible = 1;
-
+ 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);
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs
index e9077f2..e272232 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/render.rs
@@ -23,6 +23,7 @@ rs_script gTransformScript;
rs_script gCameraScript;
rs_script gLightScript;
rs_script gParamsScript;
+rs_script gCullScript;
SgTransform *gRootNode;
rs_allocation gCameras;
@@ -56,8 +57,12 @@ static void draw(SgRenderable *obj) {
printName(obj->name);
#endif //DEBUG_RENDERABLES
- rsgBindConstant(renderState->pv, 0, obj->pv_const);
- rsgBindConstant(renderState->pf, 0, obj->pf_const);
+ if (rsIsObject(obj->pv_const)) {
+ rsgBindConstant(renderState->pv, 0, obj->pv_const);
+ }
+ if (rsIsObject(obj->pf_const)) {
+ rsgBindConstant(renderState->pf, 0, obj->pf_const);
+ }
if (rsIsObject(renderState->ps)) {
rsgBindProgramStore(renderState->ps);
@@ -134,6 +139,7 @@ static void drawAllObjects(rs_allocation allObj) {
}
// Run the params and cull script
+ rsForEach(gCullScript, nullAlloc, allObj, gActiveCamera, sizeof(gActiveCamera));
rsForEach(gParamsScript, nullAlloc, allObj, gActiveCamera, sizeof(gActiveCamera));
int numRenderables = rsAllocationGetDimX(allObj);
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh
new file mode 100644
index 0000000..e1ce287
--- /dev/null
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/testApp.rsh
@@ -0,0 +1,49 @@
+// 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)
+
+// Helpers
+typedef struct VShaderParams_s {
+ rs_matrix4x4 model;
+ rs_matrix4x4 viewProj;
+} VShaderParams;
+
+typedef struct FShaderParams_s {
+ float4 cameraPos;
+} FShaderParams;
+
+typedef struct FShaderLightParams_s {
+ float4 lightPos_0;
+ float4 lightColor_0;
+ float4 lightPos_1;
+ float4 lightColor_1;
+ float4 cameraPos;
+ float4 diffuse;
+} FShaderLightParams;
+
+typedef struct FBlurOffsets_s {
+ float blurOffset0;
+ float blurOffset1;
+ float blurOffset2;
+ float blurOffset3;
+} FBlurOffsets;
+
+typedef struct VertexShaderInputs_s {
+ float4 position;
+ float3 normal;
+ float2 texture0;
+} VertexShaderInputs;
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 2c81151..5c687cc 100644
--- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh
+++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/transform_def.rsh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 The Android Open Source Project
+// Copyright (C) 2011-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.
@@ -23,15 +23,28 @@
#define TRANSFORM_ROTATE 2
#define TRANSFORM_SCALE 3
-static void printName(rs_allocation name) {
- rsDebug("Object Name: ", 0);
- if (!rsIsObject(name)) {
- rsDebug("no name", 0);
- return;
- }
+#define CULL_FRUSTUM 0
+#define CULL_ALWAYS 2
- rsDebug((const char*)rsGetElementAt(name, 0), 0);
-}
+#define LIGHT_POINT 0
+#define LIGHT_DIRECTIONAL 1
+
+#define SHADER_PARAM_FLOAT4_DATA 0
+#define SHADER_PARAM_FLOAT4_CAMERA_POS 1
+#define SHADER_PARAM_FLOAT4_CAMERA_DIR 2
+#define SHADER_PARAM_FLOAT4_LIGHT_COLOR 3
+#define SHADER_PARAM_FLOAT4_LIGHT_POS 4
+#define SHADER_PARAM_FLOAT4_LIGHT_DIR 5
+
+#define SHADER_PARAM_TRANSFORM_DATA 100
+#define SHADER_PARAM_TRANSFORM_VIEW 101
+#define SHADER_PARAM_TRANSFORM_PROJ 102
+#define SHADER_PARAM_TRANSFORM_VIEW_PROJ 103
+#define SHADER_PARAM_TRANSFORM_MODEL 104
+#define SHADER_PARAM_TRANSFORM_MODEL_VIEW 105
+#define SHADER_PARAM_TRANSFORM_MODEL_VIEW_PROJ 106
+
+#define SHADER_PARAM_TEXTURE 200
typedef struct __attribute__((packed, aligned(4))) SgTransform {
rs_matrix4x4 globalMat;
@@ -55,9 +68,6 @@ typedef struct RenderState_s {
rs_program_raster pr;
} SgRenderState;
-#define CULL_FRUSTUM 0
-#define CULL_ALWAYS 2
-
typedef struct Renderable_s {
rs_allocation render_state;
// Buffer with vertex constant data
@@ -107,9 +117,6 @@ typedef struct __attribute__((packed, aligned(4))) Camera_s {
float4 frustumPlanes[6];
} SgCamera;
-#define LIGHT_POINT 0
-#define LIGHT_DIRECTIONAL 1
-
typedef struct __attribute__((packed, aligned(4))) Light_s {
float4 position;
float4 color;
@@ -119,23 +126,6 @@ typedef struct __attribute__((packed, aligned(4))) Light_s {
rs_allocation transformMatrix;
} SgLight;
-#define SHADER_PARAM_FLOAT4_DATA 0
-#define SHADER_PARAM_FLOAT4_CAMERA_POS 1
-#define SHADER_PARAM_FLOAT4_CAMERA_DIR 2
-#define SHADER_PARAM_FLOAT4_LIGHT_COLOR 3
-#define SHADER_PARAM_FLOAT4_LIGHT_POS 4
-#define SHADER_PARAM_FLOAT4_LIGHT_DIR 5
-
-#define SHADER_PARAM_TRANSFORM_DATA 100
-#define SHADER_PARAM_TRANSFORM_VIEW 101
-#define SHADER_PARAM_TRANSFORM_PROJ 102
-#define SHADER_PARAM_TRANSFORM_VIEW_PROJ 103
-#define SHADER_PARAM_TRANSFORM_MODEL 104
-#define SHADER_PARAM_TRANSFORM_MODEL_VIEW 105
-#define SHADER_PARAM_TRANSFORM_MODEL_VIEW_PROJ 106
-
-#define SHADER_PARAM_TEXTURE 200
-
// This represents a shader parameter that knows for to update itself
typedef struct ShaderParam_s {
uint32_t type;
@@ -151,37 +141,15 @@ typedef struct ShaderParam_s {
rs_allocation texture;
} SgShaderParam;
-// Helpers
-typedef struct VShaderParams_s {
- rs_matrix4x4 model;
- rs_matrix4x4 viewProj;
-} VShaderParams;
-
-typedef struct FShaderParams_s {
- float4 cameraPos;
-} FShaderParams;
-
-typedef struct FShaderLightParams_s {
- float4 lightPos_0;
- float4 lightColor_0;
- float4 lightPos_1;
- float4 lightColor_1;
- float4 cameraPos;
- float4 diffuse;
-} FShaderLightParams;
-
-typedef struct FBlurOffsets_s {
- float blurOffset0;
- float blurOffset1;
- float blurOffset2;
- float blurOffset3;
-} FBlurOffsets;
-
-typedef struct VertexShaderInputs_s {
- float4 position;
- float3 normal;
- float2 texture0;
-} VertexShaderInputs;
+static void printName(rs_allocation name) {
+ rsDebug("Object Name: ", 0);
+ if (!rsIsObject(name)) {
+ rsDebug("no name", 0);
+ return;
+ }
+
+ rsDebug((const char*)rsGetElementAt(name, 0), 0);
+}
static void printCameraInfo(const SgCamera *cam) {
rsDebug("***** Camera information. ptr:", cam);