Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Alex Sakhartchouk | c29a444 | 2011-02-22 10:30:32 -0800 | [diff] [blame] | 17 | package com.android.perftest; |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 18 | |
| 19 | import java.io.Writer; |
| 20 | |
| 21 | import android.content.res.Resources; |
| 22 | import android.graphics.Bitmap; |
| 23 | import android.graphics.BitmapFactory; |
| 24 | import android.renderscript.*; |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 25 | import android.renderscript.Allocation.MipmapControl; |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 26 | import android.renderscript.Program.TextureType; |
| 27 | import android.renderscript.ProgramStore.DepthFunc; |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 28 | import android.renderscript.ProgramStore.BlendSrcFunc; |
| 29 | import android.renderscript.ProgramStore.BlendDstFunc; |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 30 | import android.renderscript.Sampler.Value; |
| 31 | import android.util.Log; |
| 32 | |
| 33 | |
| 34 | public class RsBenchRS { |
| 35 | |
| 36 | int mWidth; |
| 37 | int mHeight; |
| 38 | |
| 39 | public RsBenchRS() { |
| 40 | } |
| 41 | |
| 42 | public void init(RenderScriptGL rs, Resources res, int width, int height) { |
| 43 | mRS = rs; |
| 44 | mRes = res; |
| 45 | mWidth = width; |
| 46 | mHeight = height; |
| 47 | mOptionsARGB.inScaled = false; |
| 48 | mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888; |
| 49 | mMode = 0; |
| 50 | mMaxModes = 0; |
| 51 | initRS(); |
| 52 | } |
| 53 | |
| 54 | private Resources mRes; |
| 55 | private RenderScriptGL mRS; |
| 56 | |
| 57 | private Sampler mLinearClamp; |
| 58 | private Sampler mLinearWrap; |
| 59 | private Sampler mMipLinearWrap; |
| 60 | private Sampler mNearestClamp; |
| 61 | private Sampler mMipLinearAniso8; |
| 62 | private Sampler mMipLinearAniso15; |
| 63 | |
| 64 | private ProgramStore mProgStoreBlendNoneDepth; |
| 65 | private ProgramStore mProgStoreBlendNone; |
| 66 | private ProgramStore mProgStoreBlendAlpha; |
| 67 | private ProgramStore mProgStoreBlendAdd; |
| 68 | |
| 69 | private ProgramFragment mProgFragmentTexture; |
| 70 | private ProgramFragment mProgFragmentColor; |
| 71 | |
| 72 | private ProgramVertex mProgVertex; |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 73 | private ProgramVertexFixedFunction.Constants mPVA; |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 74 | |
| 75 | // Custom shaders |
| 76 | private ProgramVertex mProgVertexCustom; |
| 77 | private ProgramFragment mProgFragmentCustom; |
| 78 | private ProgramFragment mProgFragmentMultitex; |
| 79 | private ProgramVertex mProgVertexPixelLight; |
| 80 | private ProgramVertex mProgVertexPixelLightMove; |
| 81 | private ProgramFragment mProgFragmentPixelLight; |
| 82 | private ScriptField_VertexShaderConstants_s mVSConst; |
| 83 | private ScriptField_FragentShaderConstants_s mFSConst; |
| 84 | private ScriptField_VertexShaderConstants3_s mVSConstPixel; |
| 85 | private ScriptField_FragentShaderConstants3_s mFSConstPixel; |
| 86 | |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 87 | private ProgramRaster mCullBack; |
| 88 | private ProgramRaster mCullFront; |
| 89 | private ProgramRaster mCullNone; |
| 90 | |
| 91 | private Allocation mTexTorus; |
| 92 | private Allocation mTexOpaque; |
| 93 | private Allocation mTexTransparent; |
| 94 | private Allocation mTexChecker; |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 95 | |
| 96 | private Mesh m10by10Mesh; |
| 97 | private Mesh m100by100Mesh; |
| 98 | private Mesh mWbyHMesh; |
| 99 | private Mesh mTorus; |
| 100 | |
| 101 | Font mFontSans; |
| 102 | Font mFontSerif; |
| 103 | Font mFontSerifBold; |
| 104 | Font mFontSerifItalic; |
| 105 | Font mFontSerifBoldItalic; |
| 106 | Font mFontMono; |
| 107 | private Allocation mTextAlloc; |
| 108 | |
| 109 | private ScriptC_rsbench mScript; |
| 110 | |
| 111 | private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options(); |
| 112 | |
| 113 | int mMode; |
| 114 | int mMaxModes; |
| 115 | |
| 116 | public void onActionDown(int x, int y) { |
| 117 | mMode ++; |
| 118 | mMode = mMode % mMaxModes; |
| 119 | mScript.set_gDisplayMode(mMode); |
| 120 | } |
| 121 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 122 | ProgramStore BLEND_ADD_DEPTH_NONE(RenderScript rs) { |
| 123 | ProgramStore.Builder builder = new ProgramStore.Builder(rs); |
| 124 | builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 125 | builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE); |
| 126 | builder.setDitherEnabled(false); |
| 127 | builder.setDepthMaskEnabled(false); |
| 128 | return builder.create(); |
| 129 | } |
| 130 | |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 131 | private Mesh getMbyNMesh(float width, float height, int wResolution, int hResolution) { |
| 132 | |
| 133 | Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS, |
| 134 | 2, Mesh.TriangleMeshBuilder.TEXTURE_0); |
| 135 | |
| 136 | for (int y = 0; y <= hResolution; y++) { |
| 137 | final float normalizedY = (float)y / hResolution; |
| 138 | final float yOffset = (normalizedY - 0.5f) * height; |
| 139 | for (int x = 0; x <= wResolution; x++) { |
| 140 | float normalizedX = (float)x / wResolution; |
| 141 | float xOffset = (normalizedX - 0.5f) * width; |
| 142 | tmb.setTexture((float)x % 2, (float)y % 2); |
| 143 | tmb.addVertex(xOffset, yOffset); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | for (int y = 0; y < hResolution; y++) { |
| 148 | final int curY = y * (wResolution + 1); |
| 149 | final int belowY = (y + 1) * (wResolution + 1); |
| 150 | for (int x = 0; x < wResolution; x++) { |
| 151 | int curV = curY + x; |
| 152 | int belowV = belowY + x; |
| 153 | tmb.addTriangle(curV, belowV, curV + 1); |
| 154 | tmb.addTriangle(belowV, belowV + 1, curV + 1); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return tmb.create(true); |
| 159 | } |
| 160 | |
| 161 | private void initProgramStore() { |
| 162 | // Use stock the stock program store object |
| 163 | mProgStoreBlendNoneDepth = ProgramStore.BLEND_NONE_DEPTH_TEST(mRS); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 164 | mProgStoreBlendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 165 | |
| 166 | // Create a custom program store |
| 167 | ProgramStore.Builder builder = new ProgramStore.Builder(mRS); |
| 168 | builder.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 169 | builder.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 170 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 171 | builder.setDitherEnabled(false); |
| 172 | builder.setDepthMaskEnabled(false); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 173 | mProgStoreBlendAlpha = builder.create(); |
| 174 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 175 | mProgStoreBlendAdd = BLEND_ADD_DEPTH_NONE(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 176 | |
| 177 | mScript.set_gProgStoreBlendNoneDepth(mProgStoreBlendNoneDepth); |
| 178 | mScript.set_gProgStoreBlendNone(mProgStoreBlendNone); |
| 179 | mScript.set_gProgStoreBlendAlpha(mProgStoreBlendAlpha); |
| 180 | mScript.set_gProgStoreBlendAdd(mProgStoreBlendAdd); |
| 181 | } |
| 182 | |
| 183 | private void initProgramFragment() { |
| 184 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 185 | ProgramFragmentFixedFunction.Builder texBuilder = new ProgramFragmentFixedFunction.Builder(mRS); |
| 186 | texBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, |
| 187 | ProgramFragmentFixedFunction.Builder.Format.RGBA, 0); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 188 | mProgFragmentTexture = texBuilder.create(); |
| 189 | mProgFragmentTexture.bindSampler(mLinearClamp, 0); |
| 190 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 191 | ProgramFragmentFixedFunction.Builder colBuilder = new ProgramFragmentFixedFunction.Builder(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 192 | colBuilder.setVaryingColor(false); |
| 193 | mProgFragmentColor = colBuilder.create(); |
| 194 | |
| 195 | mScript.set_gProgFragmentColor(mProgFragmentColor); |
| 196 | mScript.set_gProgFragmentTexture(mProgFragmentTexture); |
| 197 | } |
| 198 | |
| 199 | private void initProgramVertex() { |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 200 | ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 201 | mProgVertex = pvb.create(); |
| 202 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 203 | mPVA = new ProgramVertexFixedFunction.Constants(mRS); |
| 204 | ((ProgramVertexFixedFunction)mProgVertex).bindConstants(mPVA); |
| 205 | Matrix4f proj = new Matrix4f(); |
| 206 | proj.loadOrthoWindow(mWidth, mHeight); |
| 207 | mPVA.setProjection(proj); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 208 | |
| 209 | mScript.set_gProgVertex(mProgVertex); |
| 210 | } |
| 211 | |
| 212 | private void initCustomShaders() { |
| 213 | mVSConst = new ScriptField_VertexShaderConstants_s(mRS, 1); |
| 214 | mFSConst = new ScriptField_FragentShaderConstants_s(mRS, 1); |
| 215 | mScript.bind_gVSConstants(mVSConst); |
| 216 | mScript.bind_gFSConstants(mFSConst); |
| 217 | |
| 218 | mVSConstPixel = new ScriptField_VertexShaderConstants3_s(mRS, 1); |
| 219 | mFSConstPixel = new ScriptField_FragentShaderConstants3_s(mRS, 1); |
| 220 | mScript.bind_gVSConstPixel(mVSConstPixel); |
| 221 | mScript.bind_gFSConstPixel(mFSConstPixel); |
| 222 | |
| 223 | // Initialize the shader builder |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 224 | ProgramVertex.Builder pvbCustom = new ProgramVertex.Builder(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 225 | // Specify the resource that contains the shader string |
| 226 | pvbCustom.setShader(mRes, R.raw.shaderv); |
Alex Sakhartchouk | 0857196 | 2010-12-15 09:59:58 -0800 | [diff] [blame] | 227 | // Use a script field to specify the input layout |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 228 | pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); |
| 229 | // Define the constant input layout |
| 230 | pvbCustom.addConstant(mVSConst.getAllocation().getType()); |
| 231 | mProgVertexCustom = pvbCustom.create(); |
| 232 | // Bind the source of constant data |
| 233 | mProgVertexCustom.bindConstants(mVSConst.getAllocation(), 0); |
| 234 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 235 | ProgramFragment.Builder pfbCustom = new ProgramFragment.Builder(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 236 | // Specify the resource that contains the shader string |
| 237 | pfbCustom.setShader(mRes, R.raw.shaderf); |
Alex Sakhartchouk | 0857196 | 2010-12-15 09:59:58 -0800 | [diff] [blame] | 238 | // Tell the builder how many textures we have |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 239 | pfbCustom.addTexture(Program.TextureType.TEXTURE_2D); |
| 240 | // Define the constant input layout |
| 241 | pfbCustom.addConstant(mFSConst.getAllocation().getType()); |
| 242 | mProgFragmentCustom = pfbCustom.create(); |
| 243 | // Bind the source of constant data |
| 244 | mProgFragmentCustom.bindConstants(mFSConst.getAllocation(), 0); |
| 245 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 246 | pvbCustom = new ProgramVertex.Builder(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 247 | pvbCustom.setShader(mRes, R.raw.shader2v); |
| 248 | pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); |
| 249 | pvbCustom.addConstant(mVSConstPixel.getAllocation().getType()); |
| 250 | mProgVertexPixelLight = pvbCustom.create(); |
| 251 | mProgVertexPixelLight.bindConstants(mVSConstPixel.getAllocation(), 0); |
| 252 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 253 | pvbCustom = new ProgramVertex.Builder(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 254 | pvbCustom.setShader(mRes, R.raw.shader2movev); |
| 255 | pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS)); |
| 256 | pvbCustom.addConstant(mVSConstPixel.getAllocation().getType()); |
| 257 | mProgVertexPixelLightMove = pvbCustom.create(); |
| 258 | mProgVertexPixelLightMove.bindConstants(mVSConstPixel.getAllocation(), 0); |
| 259 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 260 | pfbCustom = new ProgramFragment.Builder(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 261 | pfbCustom.setShader(mRes, R.raw.shader2f); |
| 262 | pfbCustom.addTexture(Program.TextureType.TEXTURE_2D); |
| 263 | pfbCustom.addConstant(mFSConstPixel.getAllocation().getType()); |
| 264 | mProgFragmentPixelLight = pfbCustom.create(); |
| 265 | mProgFragmentPixelLight.bindConstants(mFSConstPixel.getAllocation(), 0); |
| 266 | |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 267 | pfbCustom = new ProgramFragment.Builder(mRS); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 268 | pfbCustom.setShader(mRes, R.raw.multitexf); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 269 | for (int texCount = 0; texCount < 3; texCount ++) { |
| 270 | pfbCustom.addTexture(Program.TextureType.TEXTURE_2D); |
| 271 | } |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 272 | mProgFragmentMultitex = pfbCustom.create(); |
| 273 | |
| 274 | mScript.set_gProgVertexCustom(mProgVertexCustom); |
| 275 | mScript.set_gProgFragmentCustom(mProgFragmentCustom); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 276 | mScript.set_gProgVertexPixelLight(mProgVertexPixelLight); |
| 277 | mScript.set_gProgVertexPixelLightMove(mProgVertexPixelLightMove); |
| 278 | mScript.set_gProgFragmentPixelLight(mProgFragmentPixelLight); |
| 279 | mScript.set_gProgFragmentMultitex(mProgFragmentMultitex); |
| 280 | } |
| 281 | |
| 282 | private Allocation loadTextureRGB(int id) { |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 283 | return Allocation.createFromBitmapResource(mRS, mRes, id, |
| 284 | Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE, |
| 285 | Allocation.USAGE_GRAPHICS_TEXTURE); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | private Allocation loadTextureARGB(int id) { |
| 289 | Bitmap b = BitmapFactory.decodeResource(mRes, id, mOptionsARGB); |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 290 | return Allocation.createFromBitmap(mRS, b, |
| 291 | Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE, |
| 292 | Allocation.USAGE_GRAPHICS_TEXTURE); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | private void loadImages() { |
| 296 | mTexTorus = loadTextureRGB(R.drawable.torusmap); |
| 297 | mTexOpaque = loadTextureRGB(R.drawable.data); |
| 298 | mTexTransparent = loadTextureARGB(R.drawable.leaf); |
| 299 | mTexChecker = loadTextureRGB(R.drawable.checker); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 300 | |
| 301 | mScript.set_gTexTorus(mTexTorus); |
| 302 | mScript.set_gTexOpaque(mTexOpaque); |
| 303 | mScript.set_gTexTransparent(mTexTransparent); |
| 304 | mScript.set_gTexChecker(mTexChecker); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | private void initFonts() { |
| 308 | // Sans font by family name |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 309 | mFontSans = Font.create(mRS, mRes, "sans-serif", Font.Style.NORMAL, 8); |
| 310 | mFontSerif = Font.create(mRS, mRes, "serif", Font.Style.NORMAL, 8); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 311 | // Create fonts by family and style |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 312 | mFontSerifBold = Font.create(mRS, mRes, "serif", Font.Style.BOLD, 8); |
| 313 | mFontSerifItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8); |
| 314 | mFontSerifBoldItalic = Font.create(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8); |
| 315 | mFontMono = Font.create(mRS, mRes, "mono", Font.Style.NORMAL, 8); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 316 | |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 317 | mTextAlloc = Allocation.createFromString(mRS, "String from allocation", Allocation.USAGE_SCRIPT); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 318 | |
| 319 | mScript.set_gFontSans(mFontSans); |
| 320 | mScript.set_gFontSerif(mFontSerif); |
| 321 | mScript.set_gFontSerifBold(mFontSerifBold); |
| 322 | mScript.set_gFontSerifItalic(mFontSerifItalic); |
| 323 | mScript.set_gFontSerifBoldItalic(mFontSerifBoldItalic); |
| 324 | mScript.set_gFontMono(mFontMono); |
| 325 | mScript.set_gTextAlloc(mTextAlloc); |
| 326 | } |
| 327 | |
| 328 | private void initMesh() { |
| 329 | m10by10Mesh = getMbyNMesh(mWidth, mHeight, 10, 10); |
| 330 | mScript.set_g10by10Mesh(m10by10Mesh); |
| 331 | m100by100Mesh = getMbyNMesh(mWidth, mHeight, 100, 100); |
| 332 | mScript.set_g100by100Mesh(m100by100Mesh); |
| 333 | mWbyHMesh= getMbyNMesh(mWidth, mHeight, mWidth/4, mHeight/4); |
| 334 | mScript.set_gWbyHMesh(mWbyHMesh); |
| 335 | |
| 336 | FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.torus); |
| 337 | FileA3D.IndexEntry entry = model.getIndexEntry(0); |
Alex Sakhartchouk | e27cdee | 2010-12-17 11:41:08 -0800 | [diff] [blame] | 338 | if (entry == null || entry.getEntryType() != FileA3D.EntryType.MESH) { |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 339 | Log.e("rs", "could not load model"); |
| 340 | } else { |
| 341 | mTorus = (Mesh)entry.getObject(); |
| 342 | mScript.set_gTorusMesh(mTorus); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | private void initSamplers() { |
| 347 | Sampler.Builder bs = new Sampler.Builder(mRS); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 348 | bs.setMinification(Sampler.Value.LINEAR); |
| 349 | bs.setMagnification(Sampler.Value.LINEAR); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 350 | bs.setWrapS(Sampler.Value.WRAP); |
| 351 | bs.setWrapT(Sampler.Value.WRAP); |
| 352 | mLinearWrap = bs.create(); |
| 353 | |
| 354 | mLinearClamp = Sampler.CLAMP_LINEAR(mRS); |
| 355 | mNearestClamp = Sampler.CLAMP_NEAREST(mRS); |
| 356 | mMipLinearWrap = Sampler.WRAP_LINEAR_MIP_LINEAR(mRS); |
| 357 | |
| 358 | bs = new Sampler.Builder(mRS); |
Alex Sakhartchouk | b4d7bb6 | 2010-12-21 14:42:26 -0800 | [diff] [blame] | 359 | bs.setMinification(Sampler.Value.LINEAR_MIP_LINEAR); |
| 360 | bs.setMagnification(Sampler.Value.LINEAR); |
Alex Sakhartchouk | 6b5222d | 2010-12-13 14:48:21 -0800 | [diff] [blame] | 361 | bs.setWrapS(Sampler.Value.WRAP); |
| 362 | bs.setWrapT(Sampler.Value.WRAP); |
| 363 | bs.setAnisotropy(8.0f); |
| 364 | mMipLinearAniso8 = bs.create(); |
| 365 | bs.setAnisotropy(15.0f); |
| 366 | mMipLinearAniso15 = bs.create(); |
| 367 | |
| 368 | mScript.set_gLinearClamp(mLinearClamp); |
| 369 | mScript.set_gLinearWrap(mLinearWrap); |
| 370 | mScript.set_gMipLinearWrap(mMipLinearWrap); |
| 371 | mScript.set_gMipLinearAniso8(mMipLinearAniso8); |
| 372 | mScript.set_gMipLinearAniso15(mMipLinearAniso15); |
| 373 | mScript.set_gNearestClamp(mNearestClamp); |
| 374 | } |
| 375 | |
| 376 | private void initProgramRaster() { |
| 377 | mCullBack = ProgramRaster.CULL_BACK(mRS); |
| 378 | mCullFront = ProgramRaster.CULL_FRONT(mRS); |
| 379 | mCullNone = ProgramRaster.CULL_NONE(mRS); |
| 380 | |
| 381 | mScript.set_gCullBack(mCullBack); |
| 382 | mScript.set_gCullFront(mCullFront); |
| 383 | mScript.set_gCullNone(mCullNone); |
| 384 | } |
| 385 | |
| 386 | private void initRS() { |
| 387 | |
| 388 | mScript = new ScriptC_rsbench(mRS, mRes, R.raw.rsbench); |
| 389 | |
| 390 | mMaxModes = mScript.get_gMaxModes(); |
| 391 | |
| 392 | initSamplers(); |
| 393 | initProgramStore(); |
| 394 | initProgramFragment(); |
| 395 | initProgramVertex(); |
| 396 | initFonts(); |
| 397 | loadImages(); |
| 398 | initMesh(); |
| 399 | initProgramRaster(); |
| 400 | initCustomShaders(); |
| 401 | |
| 402 | mRS.bindRootScript(mScript); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | |
| 407 | |