Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [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 | |
Jason Sams | 94d8e90a | 2009-06-10 16:09:05 -0700 | [diff] [blame] | 17 | package android.renderscript; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 18 | |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 19 | import java.io.IOException; |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 20 | import java.io.InputStream; |
| 21 | |
| 22 | import android.content.res.Resources; |
| 23 | import android.os.Bundle; |
| 24 | import android.util.Config; |
| 25 | import android.util.Log; |
| 26 | import android.view.Surface; |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 27 | |
Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 28 | import android.graphics.Bitmap; |
| 29 | import android.graphics.BitmapFactory; |
Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 30 | import android.graphics.Color; |
| 31 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 32 | |
Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 33 | /** |
| 34 | * @hide |
| 35 | * |
| 36 | **/ |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 37 | public class RenderScript { |
Jason Sams | f29ca50 | 2009-06-23 12:22:47 -0700 | [diff] [blame] | 38 | static final String LOG_TAG = "libRS_jni"; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 39 | private static final boolean DEBUG = false; |
| 40 | private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; |
| 41 | |
| 42 | |
| 43 | |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 44 | /* |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 45 | * We use a class initializer to allow the native code to cache some |
| 46 | * field offsets. |
| 47 | */ |
| 48 | private static boolean sInitialized; |
| 49 | native private static void _nInit(); |
| 50 | |
Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 51 | private static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); |
| 52 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 53 | static { |
| 54 | sInitialized = false; |
| 55 | try { |
Jason Sams | e29d471 | 2009-07-23 15:19:03 -0700 | [diff] [blame] | 56 | System.loadLibrary("rs_jni"); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 57 | _nInit(); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 58 | sInitialized = true; |
| 59 | } catch (UnsatisfiedLinkError e) { |
| 60 | Log.d(LOG_TAG, "RenderScript JNI library not found!"); |
| 61 | } |
Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 62 | mBitmapOptions.inScaled = false; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 65 | native int nDeviceCreate(); |
| 66 | native void nDeviceDestroy(int dev); |
| 67 | native int nContextCreate(int dev, Surface sur, int ver); |
| 68 | native void nContextDestroy(int con); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 69 | |
| 70 | //void rsContextBindSampler (uint32_t slot, RsSampler sampler); |
| 71 | //void rsContextBindRootScript (RsScript sampler); |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 72 | native void nContextBindRootScript(int script); |
| 73 | native void nContextBindSampler(int sampler, int slot); |
| 74 | native void nContextBindProgramFragmentStore(int pfs); |
| 75 | native void nContextBindProgramFragment(int pf); |
| 76 | native void nContextBindProgramVertex(int pf); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 77 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 78 | native void nAssignName(int obj, byte[] name); |
| 79 | native int nFileOpen(byte[] name); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 80 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 81 | native void nElementBegin(); |
| 82 | native void nElementAddPredefined(int predef); |
| 83 | native void nElementAdd(int kind, int type, int norm, int bits); |
| 84 | native int nElementCreate(); |
| 85 | native int nElementGetPredefined(int predef); |
| 86 | native void nElementDestroy(int obj); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 87 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 88 | native void nTypeBegin(int elementID); |
| 89 | native void nTypeAdd(int dim, int val); |
| 90 | native int nTypeCreate(); |
| 91 | native void nTypeDestroy(int id); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 92 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 93 | native int nAllocationCreateTyped(int type); |
| 94 | native int nAllocationCreatePredefSized(int predef, int count); |
| 95 | native int nAllocationCreateSized(int elem, int count); |
| 96 | native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp); |
| 97 | native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp); |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 98 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 99 | native void nAllocationUploadToTexture(int alloc, int baseMioLevel); |
| 100 | native void nAllocationDestroy(int alloc); |
| 101 | native void nAllocationData(int id, int[] d); |
| 102 | native void nAllocationData(int id, float[] d); |
| 103 | native void nAllocationSubData1D(int id, int off, int count, int[] d); |
| 104 | native void nAllocationSubData1D(int id, int off, int count, float[] d); |
| 105 | native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d); |
| 106 | native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 107 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 108 | native void nTriangleMeshDestroy(int id); |
| 109 | native void nTriangleMeshBegin(int vertex, int index); |
| 110 | native void nTriangleMeshAddVertex_XY (float x, float y); |
| 111 | native void nTriangleMeshAddVertex_XYZ (float x, float y, float z); |
| 112 | native void nTriangleMeshAddVertex_XY_ST (float x, float y, float s, float t); |
| 113 | native void nTriangleMeshAddVertex_XYZ_ST (float x, float y, float z, float s, float t); |
| 114 | native void nTriangleMeshAddVertex_XYZ_ST_NORM (float x, float y, float z, float s, float t, float nx, float ny, float nz); |
| 115 | native void nTriangleMeshAddTriangle(int i1, int i2, int i3); |
| 116 | native int nTriangleMeshCreate(); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 117 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 118 | native void nAdapter1DDestroy(int id); |
| 119 | native void nAdapter1DBindAllocation(int ad, int alloc); |
| 120 | native void nAdapter1DSetConstraint(int ad, int dim, int value); |
| 121 | native void nAdapter1DData(int ad, int[] d); |
| 122 | native void nAdapter1DSubData(int ad, int off, int count, int[] d); |
| 123 | native void nAdapter1DData(int ad, float[] d); |
| 124 | native void nAdapter1DSubData(int ad, int off, int count, float[] d); |
| 125 | native int nAdapter1DCreate(); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 126 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 127 | native void nScriptDestroy(int script); |
| 128 | native void nScriptBindAllocation(int vtm, int alloc, int slot); |
| 129 | native void nScriptCBegin(); |
| 130 | native void nScriptCSetClearColor(float r, float g, float b, float a); |
| 131 | native void nScriptCSetClearDepth(float depth); |
| 132 | native void nScriptCSetClearStencil(int stencil); |
| 133 | native void nScriptCSetTimeZone(byte[] timeZone); |
| 134 | native void nScriptCAddType(int type); |
| 135 | native void nScriptCSetRoot(boolean isRoot); |
| 136 | native void nScriptCSetScript(byte[] script, int offset, int length); |
| 137 | native int nScriptCCreate(); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 138 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 139 | native void nSamplerDestroy(int sampler); |
| 140 | native void nSamplerBegin(); |
| 141 | native void nSamplerSet(int param, int value); |
| 142 | native int nSamplerCreate(); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 143 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 144 | native void nProgramFragmentStoreBegin(int in, int out); |
| 145 | native void nProgramFragmentStoreDepthFunc(int func); |
| 146 | native void nProgramFragmentStoreDepthMask(boolean enable); |
| 147 | native void nProgramFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a); |
| 148 | native void nProgramFragmentStoreBlendFunc(int src, int dst); |
| 149 | native void nProgramFragmentStoreDither(boolean enable); |
| 150 | native int nProgramFragmentStoreCreate(); |
| 151 | native void nProgramFragmentStoreDestroy(int pgm); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 152 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 153 | native void nProgramFragmentBegin(int in, int out); |
| 154 | native void nProgramFragmentBindTexture(int vpf, int slot, int a); |
| 155 | native void nProgramFragmentBindSampler(int vpf, int slot, int s); |
| 156 | native void nProgramFragmentSetType(int slot, int vt); |
| 157 | native void nProgramFragmentSetEnvMode(int slot, int env); |
| 158 | native void nProgramFragmentSetTexEnable(int slot, boolean enable); |
| 159 | native int nProgramFragmentCreate(); |
| 160 | native void nProgramFragmentDestroy(int pgm); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 161 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 162 | native void nProgramVertexDestroy(int pv); |
| 163 | native void nProgramVertexBindAllocation(int pv, int slot, int mID); |
| 164 | native void nProgramVertexBegin(int inID, int outID); |
| 165 | native void nProgramVertexSetType(int slot, int mID); |
| 166 | native void nProgramVertexSetTextureMatrixEnable(boolean enable); |
| 167 | native void nProgramVertexAddLight(int id); |
| 168 | native int nProgramVertexCreate(); |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 169 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 170 | native void nLightBegin(); |
| 171 | native void nLightSetIsMono(boolean isMono); |
| 172 | native void nLightSetIsLocal(boolean isLocal); |
| 173 | native int nLightCreate(); |
| 174 | native void nLightDestroy(int l); |
| 175 | native void nLightSetColor(int l, float r, float g, float b); |
| 176 | native void nLightSetPosition(int l, float x, float y, float z); |
Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 177 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 178 | |
| 179 | private int mDev; |
| 180 | private int mContext; |
| 181 | private Surface mSurface; |
| 182 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 183 | private static boolean mElementsInitialized = false; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 184 | |
| 185 | /////////////////////////////////////////////////////////////////////////////////// |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 186 | // |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 187 | |
| 188 | RenderScript(Surface sur) { |
| 189 | mSurface = sur; |
| 190 | mDev = nDeviceCreate(); |
| 191 | mContext = nContextCreate(mDev, mSurface, 0); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 192 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 193 | // TODO: This should be protected by a lock |
| 194 | if(!mElementsInitialized) { |
| 195 | Element.init(this); |
| 196 | mElementsInitialized = true; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 200 | ////////////////////////////////////////////////////////////////////////////////// |
| 201 | // Element |
| 202 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 203 | Element.Builder mElementBuilder = new Element.Builder(this); |
| 204 | public Element.Builder elementBuilderCreate() throws IllegalStateException { |
| 205 | mElementBuilder.begin(); |
| 206 | return mElementBuilder; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 209 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 210 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 211 | |
| 212 | public enum DepthFunc { |
| 213 | ALWAYS (0), |
| 214 | LESS (1), |
| 215 | LEQUAL (2), |
| 216 | GREATER (3), |
| 217 | GEQUAL (4), |
| 218 | EQUAL (5), |
| 219 | NOTEQUAL (6); |
| 220 | |
| 221 | int mID; |
| 222 | DepthFunc(int id) { |
| 223 | mID = id; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | public enum BlendSrcFunc { |
| 228 | ZERO (0), |
| 229 | ONE (1), |
| 230 | DST_COLOR (2), |
| 231 | ONE_MINUS_DST_COLOR (3), |
| 232 | SRC_ALPHA (4), |
| 233 | ONE_MINUS_SRC_ALPHA (5), |
| 234 | DST_ALPHA (6), |
| 235 | ONE_MINUS_DST_ALPA (7), |
| 236 | SRC_ALPHA_SATURATE (8); |
| 237 | |
| 238 | int mID; |
| 239 | BlendSrcFunc(int id) { |
| 240 | mID = id; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | public enum BlendDstFunc { |
| 245 | ZERO (0), |
| 246 | ONE (1), |
| 247 | SRC_COLOR (2), |
| 248 | ONE_MINUS_SRC_COLOR (3), |
| 249 | SRC_ALPHA (4), |
| 250 | ONE_MINUS_SRC_ALPHA (5), |
| 251 | DST_ALPHA (6), |
| 252 | ONE_MINUS_DST_ALPA (7); |
| 253 | |
| 254 | int mID; |
| 255 | BlendDstFunc(int id) { |
| 256 | mID = id; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | public enum EnvMode { |
| 261 | REPLACE (0), |
| 262 | MODULATE (1), |
| 263 | DECAL (2); |
| 264 | |
| 265 | int mID; |
| 266 | EnvMode(int id) { |
| 267 | mID = id; |
| 268 | } |
| 269 | } |
| 270 | |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 271 | public enum SamplerParam { |
| 272 | FILTER_MIN (0), |
| 273 | FILTER_MAG (1), |
| 274 | WRAP_MODE_S (2), |
| 275 | WRAP_MODE_T (3), |
| 276 | WRAP_MODE_R (4); |
| 277 | |
| 278 | int mID; |
| 279 | SamplerParam(int id) { |
| 280 | mID = id; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | public enum SamplerValue { |
| 285 | NEAREST (0), |
| 286 | LINEAR (1), |
| 287 | LINEAR_MIP_LINEAR (2), |
| 288 | WRAP (3), |
| 289 | CLAMP (4); |
| 290 | |
| 291 | int mID; |
| 292 | SamplerValue(int id) { |
| 293 | mID = id; |
| 294 | } |
| 295 | } |
| 296 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 297 | ////////////////////////////////////////////////////////////////////////////////// |
| 298 | // Type |
| 299 | |
| 300 | public enum Dimension { |
| 301 | X (0), |
| 302 | Y (1), |
| 303 | Z (2), |
| 304 | LOD (3), |
| 305 | FACE (4), |
| 306 | ARRAY_0 (100); |
| 307 | |
| 308 | int mID; |
| 309 | Dimension(int id) { |
| 310 | mID = id; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | public class Type extends BaseObj { |
| 315 | Type(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 316 | super(RenderScript.this); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 317 | mID = id; |
| 318 | } |
| 319 | |
| 320 | public void destroy() { |
| 321 | nTypeDestroy(mID); |
| 322 | mID = 0; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | public void typeBegin(Element e) { |
| 327 | nTypeBegin(e.mID); |
| 328 | } |
| 329 | |
| 330 | public void typeAdd(Dimension d, int value) { |
| 331 | nTypeAdd(d.mID, value); |
| 332 | } |
| 333 | |
| 334 | public Type typeCreate() { |
| 335 | int id = nTypeCreate(); |
| 336 | return new Type(id); |
| 337 | } |
| 338 | |
| 339 | |
| 340 | ////////////////////////////////////////////////////////////////////////////////// |
| 341 | // Allocation |
| 342 | |
| 343 | public class Allocation extends BaseObj { |
| 344 | Allocation(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 345 | super(RenderScript.this); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 346 | mID = id; |
| 347 | } |
| 348 | |
| 349 | public void uploadToTexture(int baseMipLevel) { |
| 350 | nAllocationUploadToTexture(mID, baseMipLevel); |
| 351 | } |
| 352 | |
| 353 | public void destroy() { |
| 354 | nAllocationDestroy(mID); |
| 355 | mID = 0; |
| 356 | } |
| 357 | |
| 358 | public void data(int[] d) { |
| 359 | nAllocationData(mID, d); |
| 360 | } |
| 361 | |
| 362 | public void data(float[] d) { |
| 363 | nAllocationData(mID, d); |
| 364 | } |
| 365 | |
| 366 | public void subData1D(int off, int count, int[] d) { |
| 367 | nAllocationSubData1D(mID, off, count, d); |
| 368 | } |
| 369 | |
| 370 | public void subData1D(int off, int count, float[] d) { |
| 371 | nAllocationSubData1D(mID, off, count, d); |
| 372 | } |
| 373 | |
| 374 | public void subData2D(int xoff, int yoff, int w, int h, int[] d) { |
| 375 | nAllocationSubData2D(mID, xoff, yoff, w, h, d); |
| 376 | } |
| 377 | |
| 378 | public void subData2D(int xoff, int yoff, int w, int h, float[] d) { |
| 379 | nAllocationSubData2D(mID, xoff, yoff, w, h, d); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | public Allocation allocationCreateTyped(Type type) { |
| 384 | int id = nAllocationCreateTyped(type.mID); |
| 385 | return new Allocation(id); |
| 386 | } |
| 387 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 388 | public Allocation allocationCreateSized(Element e, int count) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 389 | int id; |
| 390 | if(e.mIsPredefined) { |
| 391 | id = nAllocationCreatePredefSized(e.mPredefinedID, count); |
| 392 | } else { |
| 393 | id = nAllocationCreateSized(e.mID, count); |
| 394 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 395 | return new Allocation(id); |
| 396 | } |
| 397 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 398 | public Allocation allocationCreateFromBitmap(Bitmap b, Element dstFmt, boolean genMips) |
| 399 | throws IllegalArgumentException { |
| 400 | if(!dstFmt.mIsPredefined) { |
| 401 | throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); |
| 402 | } |
| 403 | |
| 404 | int id = nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 405 | return new Allocation(id); |
| 406 | } |
| 407 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 408 | public Allocation allocationCreateFromBitmapBoxed(Bitmap b, Element dstFmt, boolean genMips) |
| 409 | throws IllegalArgumentException { |
| 410 | if(!dstFmt.mIsPredefined) { |
| 411 | throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element."); |
| 412 | } |
| 413 | |
| 414 | int id = nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b); |
Jason Sams | fe08d99 | 2009-05-27 14:45:32 -0700 | [diff] [blame] | 415 | return new Allocation(id); |
| 416 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 417 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 418 | public Allocation allocationCreateFromBitmapResource(Resources res, int id, Element dstFmt, boolean genMips) |
| 419 | throws IllegalArgumentException { |
| 420 | |
Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 421 | Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 422 | return allocationCreateFromBitmap(b, dstFmt, genMips); |
Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 425 | public Allocation allocationCreateFromBitmapResourceBoxed(Resources res, int id, Element dstFmt, boolean genMips) |
| 426 | throws IllegalArgumentException { |
| 427 | |
Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 428 | Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 429 | return allocationCreateFromBitmapBoxed(b, dstFmt, genMips); |
Jason Sams | dba3ba5 | 2009-07-30 14:56:12 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 433 | ////////////////////////////////////////////////////////////////////////////////// |
| 434 | // Adapter1D |
| 435 | |
| 436 | public class Adapter1D extends BaseObj { |
| 437 | Adapter1D(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 438 | super(RenderScript.this); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 439 | mID = id; |
| 440 | } |
| 441 | |
| 442 | public void destroy() { |
| 443 | nAdapter1DDestroy(mID); |
| 444 | mID = 0; |
| 445 | } |
| 446 | |
| 447 | public void bindAllocation(Allocation a) { |
| 448 | nAdapter1DBindAllocation(mID, a.mID); |
| 449 | } |
| 450 | |
| 451 | public void setConstraint(Dimension dim, int value) { |
| 452 | nAdapter1DSetConstraint(mID, dim.mID, value); |
| 453 | } |
| 454 | |
| 455 | public void data(int[] d) { |
| 456 | nAdapter1DData(mID, d); |
| 457 | } |
| 458 | |
| 459 | public void subData(int off, int count, int[] d) { |
| 460 | nAdapter1DSubData(mID, off, count, d); |
| 461 | } |
| 462 | |
| 463 | public void data(float[] d) { |
| 464 | nAdapter1DData(mID, d); |
| 465 | } |
| 466 | |
| 467 | public void subData(int off, int count, float[] d) { |
| 468 | nAdapter1DSubData(mID, off, count, d); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | public Adapter1D adapter1DCreate() { |
| 473 | int id = nAdapter1DCreate(); |
| 474 | return new Adapter1D(id); |
| 475 | } |
| 476 | |
| 477 | |
| 478 | ////////////////////////////////////////////////////////////////////////////////// |
| 479 | // Triangle Mesh |
| 480 | |
| 481 | public class TriangleMesh extends BaseObj { |
| 482 | TriangleMesh(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 483 | super(RenderScript.this); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 484 | mID = id; |
| 485 | } |
| 486 | |
| 487 | public void destroy() { |
| 488 | nTriangleMeshDestroy(mID); |
| 489 | mID = 0; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | public void triangleMeshBegin(Element vertex, Element index) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 494 | Log.e("rs", "vtx " + vertex.toString() + " " + vertex.mID + " " + vertex.mPredefinedID); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 495 | nTriangleMeshBegin(vertex.mID, index.mID); |
| 496 | } |
| 497 | |
| 498 | public void triangleMeshAddVertex_XY(float x, float y) { |
| 499 | nTriangleMeshAddVertex_XY(x, y); |
| 500 | } |
| 501 | |
| 502 | public void triangleMeshAddVertex_XYZ(float x, float y, float z) { |
| 503 | nTriangleMeshAddVertex_XYZ(x, y, z); |
| 504 | } |
| 505 | |
| 506 | public void triangleMeshAddVertex_XY_ST(float x, float y, float s, float t) { |
| 507 | nTriangleMeshAddVertex_XY_ST(x, y, s, t); |
| 508 | } |
| 509 | |
| 510 | public void triangleMeshAddVertex_XYZ_ST(float x, float y, float z, float s, float t) { |
| 511 | nTriangleMeshAddVertex_XYZ_ST(x, y, z, s, t); |
| 512 | } |
| 513 | |
Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 514 | public void triangleMeshAddVertex_XYZ_ST_NORM(float x, float y, float z, float s, float t, float nx, float ny, float nz) { |
| 515 | nTriangleMeshAddVertex_XYZ_ST_NORM(x, y, z, s, t, nx, ny, nz); |
| 516 | } |
| 517 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 518 | public void triangleMeshAddTriangle(int i1, int i2, int i3) { |
| 519 | nTriangleMeshAddTriangle(i1, i2, i3); |
| 520 | } |
| 521 | |
| 522 | public TriangleMesh triangleMeshCreate() { |
| 523 | int id = nTriangleMeshCreate(); |
| 524 | return new TriangleMesh(id); |
| 525 | } |
| 526 | |
| 527 | ////////////////////////////////////////////////////////////////////////////////// |
| 528 | // Script |
| 529 | |
| 530 | public class Script extends BaseObj { |
| 531 | Script(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 532 | super(RenderScript.this); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 533 | mID = id; |
| 534 | } |
| 535 | |
| 536 | public void destroy() { |
| 537 | nScriptDestroy(mID); |
| 538 | mID = 0; |
| 539 | } |
| 540 | |
| 541 | public void bindAllocation(Allocation va, int slot) { |
| 542 | nScriptBindAllocation(mID, va.mID, slot); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | public void scriptCBegin() { |
| 547 | nScriptCBegin(); |
| 548 | } |
| 549 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 550 | public void scriptCSetTimeZone(String timeZone) { |
| 551 | try { |
| 552 | byte[] bytes = timeZone.getBytes("UTF-8"); |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 553 | nScriptCSetTimeZone(bytes); |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 554 | } catch (java.io.UnsupportedEncodingException e) { |
| 555 | throw new RuntimeException(e); |
| 556 | } |
| 557 | } |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 558 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 559 | public void scriptCSetClearColor(float r, float g, float b, float a) { |
| 560 | nScriptCSetClearColor(r, g, b, a); |
| 561 | } |
| 562 | |
| 563 | public void scriptCSetClearDepth(float d) { |
| 564 | nScriptCSetClearDepth(d); |
| 565 | } |
| 566 | |
| 567 | public void scriptCSetClearStencil(int stencil) { |
| 568 | nScriptCSetClearStencil(stencil); |
| 569 | } |
| 570 | |
| 571 | public void scriptCAddType(Type t) { |
| 572 | nScriptCAddType(t.mID); |
| 573 | } |
| 574 | |
| 575 | public void scriptCSetRoot(boolean r) { |
| 576 | nScriptCSetRoot(r); |
| 577 | } |
| 578 | |
| 579 | public void scriptCSetScript(String s) { |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 580 | try { |
Jack Palevich | 63975dd | 2009-05-28 15:34:15 -0700 | [diff] [blame] | 581 | byte[] bytes = s.getBytes("UTF-8"); |
| 582 | nScriptCSetScript(bytes, 0, bytes.length); |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 583 | } catch (java.io.UnsupportedEncodingException e) { |
| 584 | throw new RuntimeException(e); |
| 585 | } |
| 586 | } |
| 587 | |
Jack Palevich | 43702d8 | 2009-05-28 13:38:16 -0700 | [diff] [blame] | 588 | public void scriptCSetScript(Resources resources, int id) { |
| 589 | InputStream is = resources.openRawResource(id); |
| 590 | try { |
| 591 | try { |
| 592 | scriptCSetScript(is); |
| 593 | } finally { |
| 594 | is.close(); |
| 595 | } |
| 596 | } catch(IOException e) { |
| 597 | throw new Resources.NotFoundException(); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | public void scriptCSetScript(InputStream is) throws IOException { |
| 602 | byte[] buf = new byte[1024]; |
| 603 | int currentPos = 0; |
| 604 | while(true) { |
| 605 | int bytesLeft = buf.length - currentPos; |
| 606 | if (bytesLeft == 0) { |
| 607 | byte[] buf2 = new byte[buf.length * 2]; |
| 608 | System.arraycopy(buf, 0, buf2, 0, buf.length); |
| 609 | buf = buf2; |
| 610 | bytesLeft = buf.length - currentPos; |
| 611 | } |
| 612 | int bytesRead = is.read(buf, currentPos, bytesLeft); |
| 613 | if (bytesRead <= 0) { |
| 614 | break; |
| 615 | } |
| 616 | currentPos += bytesRead; |
| 617 | } |
| 618 | nScriptCSetScript(buf, 0, currentPos); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | public Script scriptCCreate() { |
| 622 | int id = nScriptCCreate(); |
| 623 | return new Script(id); |
| 624 | } |
| 625 | |
| 626 | ////////////////////////////////////////////////////////////////////////////////// |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 627 | // ProgramVertex |
| 628 | |
| 629 | public class ProgramVertex extends BaseObj { |
| 630 | ProgramVertex(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 631 | super(RenderScript.this); |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 632 | mID = id; |
| 633 | } |
| 634 | |
| 635 | public void destroy() { |
| 636 | nProgramVertexDestroy(mID); |
| 637 | mID = 0; |
| 638 | } |
| 639 | |
| 640 | public void bindAllocation(int slot, Allocation va) { |
| 641 | nProgramVertexBindAllocation(mID, slot, va.mID); |
| 642 | } |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | public void programVertexBegin(Element in, Element out) { |
| 646 | int inID = 0; |
| 647 | int outID = 0; |
| 648 | if (in != null) { |
| 649 | inID = in.mID; |
| 650 | } |
| 651 | if (out != null) { |
| 652 | outID = out.mID; |
| 653 | } |
| 654 | nProgramVertexBegin(inID, outID); |
| 655 | } |
| 656 | |
| 657 | public void programVertexSetType(int slot, Type t) { |
| 658 | nProgramVertexSetType(slot, t.mID); |
| 659 | } |
| 660 | |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 661 | public void programVertexSetTextureMatrixEnable(boolean enable) { |
| 662 | nProgramVertexSetTextureMatrixEnable(enable); |
| 663 | } |
| 664 | |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 665 | public void programVertexAddLight(Light l) { |
| 666 | nProgramVertexAddLight(l.mID); |
| 667 | } |
| 668 | |
Jason Sams | 1fe9b8c | 2009-06-11 14:46:10 -0700 | [diff] [blame] | 669 | public ProgramVertex programVertexCreate() { |
| 670 | int id = nProgramVertexCreate(); |
| 671 | return new ProgramVertex(id); |
| 672 | } |
| 673 | |
| 674 | |
| 675 | ////////////////////////////////////////////////////////////////////////////////// |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 676 | // ProgramFragmentStore |
| 677 | |
| 678 | public class ProgramFragmentStore extends BaseObj { |
| 679 | ProgramFragmentStore(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 680 | super(RenderScript.this); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 681 | mID = id; |
| 682 | } |
| 683 | |
| 684 | public void destroy() { |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 685 | nProgramFragmentStoreDestroy(mID); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 686 | mID = 0; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | public void programFragmentStoreBegin(Element in, Element out) { |
| 691 | int inID = 0; |
| 692 | int outID = 0; |
| 693 | if (in != null) { |
| 694 | inID = in.mID; |
| 695 | } |
| 696 | if (out != null) { |
| 697 | outID = out.mID; |
| 698 | } |
| 699 | nProgramFragmentStoreBegin(inID, outID); |
| 700 | } |
| 701 | |
| 702 | public void programFragmentStoreDepthFunc(DepthFunc func) { |
| 703 | nProgramFragmentStoreDepthFunc(func.mID); |
| 704 | } |
| 705 | |
| 706 | public void programFragmentStoreDepthMask(boolean enable) { |
| 707 | nProgramFragmentStoreDepthMask(enable); |
| 708 | } |
| 709 | |
| 710 | public void programFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a) { |
| 711 | nProgramFragmentStoreColorMask(r,g,b,a); |
| 712 | } |
| 713 | |
| 714 | public void programFragmentStoreBlendFunc(BlendSrcFunc src, BlendDstFunc dst) { |
| 715 | nProgramFragmentStoreBlendFunc(src.mID, dst.mID); |
| 716 | } |
| 717 | |
| 718 | public void programFragmentStoreDitherEnable(boolean enable) { |
| 719 | nProgramFragmentStoreDither(enable); |
| 720 | } |
| 721 | |
| 722 | public ProgramFragmentStore programFragmentStoreCreate() { |
| 723 | int id = nProgramFragmentStoreCreate(); |
| 724 | return new ProgramFragmentStore(id); |
| 725 | } |
| 726 | |
| 727 | ////////////////////////////////////////////////////////////////////////////////// |
| 728 | // ProgramFragment |
| 729 | |
| 730 | public class ProgramFragment extends BaseObj { |
| 731 | ProgramFragment(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 732 | super(RenderScript.this); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 733 | mID = id; |
| 734 | } |
| 735 | |
| 736 | public void destroy() { |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 737 | nProgramFragmentDestroy(mID); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 738 | mID = 0; |
| 739 | } |
| 740 | |
| 741 | public void bindTexture(Allocation va, int slot) { |
| 742 | nProgramFragmentBindTexture(mID, slot, va.mID); |
| 743 | } |
| 744 | |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 745 | public void bindSampler(Sampler vs, int slot) { |
| 746 | nProgramFragmentBindSampler(mID, slot, vs.mID); |
| 747 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | public void programFragmentBegin(Element in, Element out) { |
| 751 | int inID = 0; |
| 752 | int outID = 0; |
| 753 | if (in != null) { |
| 754 | inID = in.mID; |
| 755 | } |
| 756 | if (out != null) { |
| 757 | outID = out.mID; |
| 758 | } |
| 759 | nProgramFragmentBegin(inID, outID); |
| 760 | } |
| 761 | |
| 762 | public void programFragmentSetType(int slot, Type t) { |
| 763 | nProgramFragmentSetType(slot, t.mID); |
| 764 | } |
| 765 | |
| 766 | public void programFragmentSetType(int slot, EnvMode t) { |
| 767 | nProgramFragmentSetEnvMode(slot, t.mID); |
| 768 | } |
| 769 | |
| 770 | public void programFragmentSetTexEnable(int slot, boolean enable) { |
| 771 | nProgramFragmentSetTexEnable(slot, enable); |
| 772 | } |
| 773 | |
Jason Sams | e6c8e9b | 2009-07-17 17:29:09 -0700 | [diff] [blame] | 774 | public void programFragmentSetTexEnvMode(int slot, EnvMode env) { |
| 775 | nProgramFragmentSetEnvMode(slot, env.mID); |
| 776 | } |
| 777 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 778 | public ProgramFragment programFragmentCreate() { |
| 779 | int id = nProgramFragmentCreate(); |
| 780 | return new ProgramFragment(id); |
| 781 | } |
| 782 | |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 783 | ////////////////////////////////////////////////////////////////////////////////// |
| 784 | // Sampler |
| 785 | |
| 786 | public class Sampler extends BaseObj { |
| 787 | Sampler(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 788 | super(RenderScript.this); |
Jason Sams | 02fb2cb | 2009-05-28 15:37:57 -0700 | [diff] [blame] | 789 | mID = id; |
| 790 | } |
| 791 | |
| 792 | public void destroy() { |
| 793 | nSamplerDestroy(mID); |
| 794 | mID = 0; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | public void samplerBegin() { |
| 799 | nSamplerBegin(); |
| 800 | } |
| 801 | |
| 802 | public void samplerSet(SamplerParam p, SamplerValue v) { |
| 803 | nSamplerSet(p.mID, v.mID); |
| 804 | } |
| 805 | |
| 806 | public Sampler samplerCreate() { |
| 807 | int id = nSamplerCreate(); |
| 808 | return new Sampler(id); |
| 809 | } |
| 810 | |
Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 811 | ////////////////////////////////////////////////////////////////////////////////// |
| 812 | // Light |
| 813 | |
| 814 | public class Light extends BaseObj { |
| 815 | Light(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 816 | super(RenderScript.this); |
Jason Sams | bba134c | 2009-06-22 15:49:21 -0700 | [diff] [blame] | 817 | mID = id; |
| 818 | } |
| 819 | |
| 820 | public void destroy() { |
| 821 | nLightDestroy(mID); |
| 822 | mID = 0; |
| 823 | } |
| 824 | |
| 825 | public void setColor(float r, float g, float b) { |
| 826 | nLightSetColor(mID, r, g, b); |
| 827 | } |
| 828 | |
| 829 | public void setPosition(float x, float y, float z) { |
| 830 | nLightSetPosition(mID, x, y, z); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | public void lightBegin() { |
| 835 | nLightBegin(); |
| 836 | } |
| 837 | |
| 838 | public void lightSetIsMono(boolean isMono) { |
| 839 | nLightSetIsMono(isMono); |
| 840 | } |
| 841 | |
| 842 | public void lightSetIsLocal(boolean isLocal) { |
| 843 | nLightSetIsLocal(isLocal); |
| 844 | } |
| 845 | |
| 846 | public Light lightCreate() { |
| 847 | int id = nLightCreate(); |
| 848 | return new Light(id); |
| 849 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 850 | |
Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 851 | ////////////////////////////////////////////////////////////////////////////////// |
| 852 | // File |
| 853 | |
| 854 | public class File extends BaseObj { |
| 855 | File(int id) { |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 856 | super(RenderScript.this); |
Jason Sams | 64676f3 | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 857 | mID = id; |
| 858 | } |
| 859 | |
| 860 | public void destroy() { |
| 861 | //nLightDestroy(mID); |
| 862 | mID = 0; |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | public File fileOpen(String s) throws IllegalStateException, IllegalArgumentException |
| 867 | { |
| 868 | if(s.length() < 1) { |
| 869 | throw new IllegalArgumentException("fileOpen does not accept a zero length string."); |
| 870 | } |
| 871 | |
| 872 | try { |
| 873 | byte[] bytes = s.getBytes("UTF-8"); |
| 874 | int id = nFileOpen(bytes); |
| 875 | return new File(id); |
| 876 | } catch (java.io.UnsupportedEncodingException e) { |
| 877 | throw new RuntimeException(e); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 882 | /////////////////////////////////////////////////////////////////////////////////// |
| 883 | // Root state |
| 884 | |
| 885 | public void contextBindRootScript(Script s) { |
| 886 | nContextBindRootScript(s.mID); |
| 887 | } |
| 888 | |
| 889 | //public void contextBindSampler(Sampler s, int slot) { |
| 890 | //nContextBindSampler(s.mID); |
| 891 | //} |
| 892 | |
| 893 | public void contextBindProgramFragmentStore(ProgramFragmentStore pfs) { |
| 894 | nContextBindProgramFragmentStore(pfs.mID); |
| 895 | } |
| 896 | |
| 897 | public void contextBindProgramFragment(ProgramFragment pf) { |
| 898 | nContextBindProgramFragment(pf.mID); |
| 899 | } |
| 900 | |
Jason Sams | 0826a6f | 2009-06-15 19:04:56 -0700 | [diff] [blame] | 901 | public void contextBindProgramVertex(ProgramVertex pf) { |
| 902 | nContextBindProgramVertex(pf.mID); |
| 903 | } |
| 904 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 905 | /* |
| 906 | RsAdapter2D rsAdapter2DCreate (); |
| 907 | void rsAdapter2DBindAllocation (RsAdapter2D adapt, RsAllocation alloc); |
| 908 | void rsAdapter2DDestroy (RsAdapter2D adapter); |
| 909 | void rsAdapter2DSetConstraint (RsAdapter2D adapter, RsDimension dim, uint32_t value); |
| 910 | void rsAdapter2DData (RsAdapter2D adapter, const void * data); |
| 911 | void rsAdapter2DSubData (RsAdapter2D adapter, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void * data); |
| 912 | void rsSamplerBegin (); |
| 913 | void rsSamplerSet (RsSamplerParam p, RsSamplerValue value); |
| 914 | RsSampler rsSamplerCreate (); |
| 915 | void rsSamplerBind (RsSampler sampler, RsAllocation alloc); |
| 916 | */ |
| 917 | |
| 918 | } |
| 919 | |
Jason Sams | 36e612a | 2009-07-31 16:26:13 -0700 | [diff] [blame^] | 920 | |