blob: dc87b6a62acb2e643315c4d7431671725eadcd31 [file] [log] [blame]
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001/*
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 Sams94d8e90a2009-06-10 16:09:05 -070017package android.renderscript;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070018
Jack Palevich43702d82009-05-28 13:38:16 -070019import java.io.IOException;
Jason Sams36e612a2009-07-31 16:26:13 -070020import java.io.InputStream;
21
22import android.content.res.Resources;
Jason Samsb8c5a842009-07-31 20:40:47 -070023import android.graphics.Bitmap;
Jason Sams36e612a2009-07-31 16:26:13 -070024import android.util.Config;
25import android.util.Log;
26import android.view.Surface;
Jack Palevich43702d82009-05-28 13:38:16 -070027
Jack Palevich60aa3ea2009-05-26 13:45:08 -070028
Jason Samse29d4712009-07-23 15:19:03 -070029/**
30 * @hide
31 *
32 **/
Jack Palevich60aa3ea2009-05-26 13:45:08 -070033public class RenderScript {
Jason Samsf29ca502009-06-23 12:22:47 -070034 static final String LOG_TAG = "libRS_jni";
Jack Palevich60aa3ea2009-05-26 13:45:08 -070035 private static final boolean DEBUG = false;
36 private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
37
38
39
Jason Sams02fb2cb2009-05-28 15:37:57 -070040 /*
Jack Palevich60aa3ea2009-05-26 13:45:08 -070041 * We use a class initializer to allow the native code to cache some
42 * field offsets.
43 */
44 private static boolean sInitialized;
45 native private static void _nInit();
46
Jason Samsdba3ba52009-07-30 14:56:12 -070047
Jack Palevich60aa3ea2009-05-26 13:45:08 -070048 static {
49 sInitialized = false;
50 try {
Jason Samse29d4712009-07-23 15:19:03 -070051 System.loadLibrary("rs_jni");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070052 _nInit();
Jack Palevich60aa3ea2009-05-26 13:45:08 -070053 sInitialized = true;
54 } catch (UnsatisfiedLinkError e) {
55 Log.d(LOG_TAG, "RenderScript JNI library not found!");
56 }
57 }
58
Jason Sams36e612a2009-07-31 16:26:13 -070059 native int nDeviceCreate();
60 native void nDeviceDestroy(int dev);
61 native int nContextCreate(int dev, Surface sur, int ver);
62 native void nContextDestroy(int con);
Jack Palevich60aa3ea2009-05-26 13:45:08 -070063
64 //void rsContextBindSampler (uint32_t slot, RsSampler sampler);
65 //void rsContextBindRootScript (RsScript sampler);
Jason Sams36e612a2009-07-31 16:26:13 -070066 native void nContextBindRootScript(int script);
67 native void nContextBindSampler(int sampler, int slot);
68 native void nContextBindProgramFragmentStore(int pfs);
69 native void nContextBindProgramFragment(int pf);
70 native void nContextBindProgramVertex(int pf);
Jack Palevich60aa3ea2009-05-26 13:45:08 -070071
Jason Sams36e612a2009-07-31 16:26:13 -070072 native void nAssignName(int obj, byte[] name);
73 native int nFileOpen(byte[] name);
Jason Sams3eaa3382009-06-10 15:04:38 -070074
Jason Sams36e612a2009-07-31 16:26:13 -070075 native void nElementBegin();
76 native void nElementAddPredefined(int predef);
77 native void nElementAdd(int kind, int type, int norm, int bits);
78 native int nElementCreate();
79 native int nElementGetPredefined(int predef);
80 native void nElementDestroy(int obj);
Jack Palevich60aa3ea2009-05-26 13:45:08 -070081
Jason Sams36e612a2009-07-31 16:26:13 -070082 native void nTypeBegin(int elementID);
83 native void nTypeAdd(int dim, int val);
84 native int nTypeCreate();
85 native void nTypeDestroy(int id);
Jack Palevich60aa3ea2009-05-26 13:45:08 -070086
Jason Sams36e612a2009-07-31 16:26:13 -070087 native int nAllocationCreateTyped(int type);
88 native int nAllocationCreatePredefSized(int predef, int count);
89 native int nAllocationCreateSized(int elem, int count);
90 native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
91 native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
Jason Samsfe08d992009-05-27 14:45:32 -070092
Jason Sams36e612a2009-07-31 16:26:13 -070093 native void nAllocationUploadToTexture(int alloc, int baseMioLevel);
94 native void nAllocationDestroy(int alloc);
95 native void nAllocationData(int id, int[] d);
96 native void nAllocationData(int id, float[] d);
97 native void nAllocationSubData1D(int id, int off, int count, int[] d);
98 native void nAllocationSubData1D(int id, int off, int count, float[] d);
99 native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, int[] d);
100 native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700101
Jason Sams36e612a2009-07-31 16:26:13 -0700102 native void nTriangleMeshDestroy(int id);
103 native void nTriangleMeshBegin(int vertex, int index);
104 native void nTriangleMeshAddVertex_XY (float x, float y);
105 native void nTriangleMeshAddVertex_XYZ (float x, float y, float z);
106 native void nTriangleMeshAddVertex_XY_ST (float x, float y, float s, float t);
107 native void nTriangleMeshAddVertex_XYZ_ST (float x, float y, float z, float s, float t);
108 native void nTriangleMeshAddVertex_XYZ_ST_NORM (float x, float y, float z, float s, float t, float nx, float ny, float nz);
109 native void nTriangleMeshAddTriangle(int i1, int i2, int i3);
110 native int nTriangleMeshCreate();
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700111
Jason Sams36e612a2009-07-31 16:26:13 -0700112 native void nAdapter1DDestroy(int id);
113 native void nAdapter1DBindAllocation(int ad, int alloc);
114 native void nAdapter1DSetConstraint(int ad, int dim, int value);
115 native void nAdapter1DData(int ad, int[] d);
116 native void nAdapter1DSubData(int ad, int off, int count, int[] d);
117 native void nAdapter1DData(int ad, float[] d);
118 native void nAdapter1DSubData(int ad, int off, int count, float[] d);
119 native int nAdapter1DCreate();
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700120
Jason Sams36e612a2009-07-31 16:26:13 -0700121 native void nScriptDestroy(int script);
122 native void nScriptBindAllocation(int vtm, int alloc, int slot);
123 native void nScriptCBegin();
124 native void nScriptCSetClearColor(float r, float g, float b, float a);
125 native void nScriptCSetClearDepth(float depth);
126 native void nScriptCSetClearStencil(int stencil);
127 native void nScriptCSetTimeZone(byte[] timeZone);
128 native void nScriptCAddType(int type);
129 native void nScriptCSetRoot(boolean isRoot);
130 native void nScriptCSetScript(byte[] script, int offset, int length);
131 native int nScriptCCreate();
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700132
Jason Sams36e612a2009-07-31 16:26:13 -0700133 native void nSamplerDestroy(int sampler);
134 native void nSamplerBegin();
135 native void nSamplerSet(int param, int value);
136 native int nSamplerCreate();
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700137
Jason Sams36e612a2009-07-31 16:26:13 -0700138 native void nProgramFragmentStoreBegin(int in, int out);
139 native void nProgramFragmentStoreDepthFunc(int func);
140 native void nProgramFragmentStoreDepthMask(boolean enable);
141 native void nProgramFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a);
142 native void nProgramFragmentStoreBlendFunc(int src, int dst);
143 native void nProgramFragmentStoreDither(boolean enable);
144 native int nProgramFragmentStoreCreate();
145 native void nProgramFragmentStoreDestroy(int pgm);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700146
Jason Sams36e612a2009-07-31 16:26:13 -0700147 native void nProgramFragmentBegin(int in, int out);
148 native void nProgramFragmentBindTexture(int vpf, int slot, int a);
149 native void nProgramFragmentBindSampler(int vpf, int slot, int s);
150 native void nProgramFragmentSetType(int slot, int vt);
151 native void nProgramFragmentSetEnvMode(int slot, int env);
152 native void nProgramFragmentSetTexEnable(int slot, boolean enable);
153 native int nProgramFragmentCreate();
154 native void nProgramFragmentDestroy(int pgm);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700155
Jason Sams36e612a2009-07-31 16:26:13 -0700156 native void nProgramVertexDestroy(int pv);
157 native void nProgramVertexBindAllocation(int pv, int slot, int mID);
158 native void nProgramVertexBegin(int inID, int outID);
159 native void nProgramVertexSetType(int slot, int mID);
160 native void nProgramVertexSetTextureMatrixEnable(boolean enable);
161 native void nProgramVertexAddLight(int id);
162 native int nProgramVertexCreate();
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700163
Jason Sams36e612a2009-07-31 16:26:13 -0700164 native void nLightBegin();
165 native void nLightSetIsMono(boolean isMono);
166 native void nLightSetIsLocal(boolean isLocal);
167 native int nLightCreate();
168 native void nLightDestroy(int l);
169 native void nLightSetColor(int l, float r, float g, float b);
170 native void nLightSetPosition(int l, float x, float y, float z);
Jason Samsbba134c2009-06-22 15:49:21 -0700171
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700172
173 private int mDev;
174 private int mContext;
175 private Surface mSurface;
176
Jason Sams36e612a2009-07-31 16:26:13 -0700177 private static boolean mElementsInitialized = false;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700178
179 ///////////////////////////////////////////////////////////////////////////////////
Jack Palevich43702d82009-05-28 13:38:16 -0700180 //
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700181
182 RenderScript(Surface sur) {
183 mSurface = sur;
184 mDev = nDeviceCreate();
185 mContext = nContextCreate(mDev, mSurface, 0);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700186
Jason Sams36e612a2009-07-31 16:26:13 -0700187 // TODO: This should be protected by a lock
188 if(!mElementsInitialized) {
189 Element.init(this);
190 mElementsInitialized = true;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700191 }
192 }
193
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700194 //////////////////////////////////////////////////////////////////////////////////
195 // Element
196
Jason Sams36e612a2009-07-31 16:26:13 -0700197 Element.Builder mElementBuilder = new Element.Builder(this);
198 public Element.Builder elementBuilderCreate() throws IllegalStateException {
199 mElementBuilder.begin();
200 return mElementBuilder;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700201 }
202
Jason Samsb8c5a842009-07-31 20:40:47 -0700203 Type.Builder mTypeBuilder = new Type.Builder(this);
204 public Type.Builder typeBuilderCreate(Element e) throws IllegalStateException {
205 mTypeBuilder.begin(e);
206 return mTypeBuilder;
207 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700208
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700209
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700210
211 public enum DepthFunc {
212 ALWAYS (0),
213 LESS (1),
214 LEQUAL (2),
215 GREATER (3),
216 GEQUAL (4),
217 EQUAL (5),
218 NOTEQUAL (6);
219
220 int mID;
221 DepthFunc(int id) {
222 mID = id;
223 }
224 }
225
226 public enum BlendSrcFunc {
227 ZERO (0),
228 ONE (1),
229 DST_COLOR (2),
230 ONE_MINUS_DST_COLOR (3),
231 SRC_ALPHA (4),
232 ONE_MINUS_SRC_ALPHA (5),
233 DST_ALPHA (6),
234 ONE_MINUS_DST_ALPA (7),
235 SRC_ALPHA_SATURATE (8);
236
237 int mID;
238 BlendSrcFunc(int id) {
239 mID = id;
240 }
241 }
242
243 public enum BlendDstFunc {
244 ZERO (0),
245 ONE (1),
246 SRC_COLOR (2),
247 ONE_MINUS_SRC_COLOR (3),
248 SRC_ALPHA (4),
249 ONE_MINUS_SRC_ALPHA (5),
250 DST_ALPHA (6),
251 ONE_MINUS_DST_ALPA (7);
252
253 int mID;
254 BlendDstFunc(int id) {
255 mID = id;
256 }
257 }
258
259 public enum EnvMode {
260 REPLACE (0),
261 MODULATE (1),
262 DECAL (2);
263
264 int mID;
265 EnvMode(int id) {
266 mID = id;
267 }
268 }
269
Jason Sams02fb2cb2009-05-28 15:37:57 -0700270 public enum SamplerParam {
271 FILTER_MIN (0),
272 FILTER_MAG (1),
273 WRAP_MODE_S (2),
274 WRAP_MODE_T (3),
275 WRAP_MODE_R (4);
276
277 int mID;
278 SamplerParam(int id) {
279 mID = id;
280 }
281 }
282
283 public enum SamplerValue {
284 NEAREST (0),
285 LINEAR (1),
286 LINEAR_MIP_LINEAR (2),
287 WRAP (3),
288 CLAMP (4);
289
290 int mID;
291 SamplerValue(int id) {
292 mID = id;
293 }
294 }
295
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700296 //////////////////////////////////////////////////////////////////////////////////
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700297 // Triangle Mesh
298
299 public class TriangleMesh extends BaseObj {
300 TriangleMesh(int id) {
Jason Sams36e612a2009-07-31 16:26:13 -0700301 super(RenderScript.this);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700302 mID = id;
303 }
304
305 public void destroy() {
306 nTriangleMeshDestroy(mID);
307 mID = 0;
308 }
309 }
310
311 public void triangleMeshBegin(Element vertex, Element index) {
Jason Sams36e612a2009-07-31 16:26:13 -0700312 Log.e("rs", "vtx " + vertex.toString() + " " + vertex.mID + " " + vertex.mPredefinedID);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700313 nTriangleMeshBegin(vertex.mID, index.mID);
314 }
315
316 public void triangleMeshAddVertex_XY(float x, float y) {
317 nTriangleMeshAddVertex_XY(x, y);
318 }
319
320 public void triangleMeshAddVertex_XYZ(float x, float y, float z) {
321 nTriangleMeshAddVertex_XYZ(x, y, z);
322 }
323
324 public void triangleMeshAddVertex_XY_ST(float x, float y, float s, float t) {
325 nTriangleMeshAddVertex_XY_ST(x, y, s, t);
326 }
327
328 public void triangleMeshAddVertex_XYZ_ST(float x, float y, float z, float s, float t) {
329 nTriangleMeshAddVertex_XYZ_ST(x, y, z, s, t);
330 }
331
Jason Sams0826a6f2009-06-15 19:04:56 -0700332 public void triangleMeshAddVertex_XYZ_ST_NORM(float x, float y, float z, float s, float t, float nx, float ny, float nz) {
333 nTriangleMeshAddVertex_XYZ_ST_NORM(x, y, z, s, t, nx, ny, nz);
334 }
335
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700336 public void triangleMeshAddTriangle(int i1, int i2, int i3) {
337 nTriangleMeshAddTriangle(i1, i2, i3);
338 }
339
340 public TriangleMesh triangleMeshCreate() {
341 int id = nTriangleMeshCreate();
342 return new TriangleMesh(id);
343 }
344
345 //////////////////////////////////////////////////////////////////////////////////
346 // Script
347
348 public class Script extends BaseObj {
349 Script(int id) {
Jason Sams36e612a2009-07-31 16:26:13 -0700350 super(RenderScript.this);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700351 mID = id;
352 }
353
354 public void destroy() {
355 nScriptDestroy(mID);
356 mID = 0;
357 }
358
359 public void bindAllocation(Allocation va, int slot) {
360 nScriptBindAllocation(mID, va.mID, slot);
361 }
362 }
363
364 public void scriptCBegin() {
365 nScriptCBegin();
366 }
367
Romain Guy584a3752009-07-30 18:45:01 -0700368 public void scriptCSetTimeZone(String timeZone) {
369 try {
370 byte[] bytes = timeZone.getBytes("UTF-8");
Jason Sams36e612a2009-07-31 16:26:13 -0700371 nScriptCSetTimeZone(bytes);
Romain Guy584a3752009-07-30 18:45:01 -0700372 } catch (java.io.UnsupportedEncodingException e) {
373 throw new RuntimeException(e);
374 }
375 }
Jason Sams36e612a2009-07-31 16:26:13 -0700376
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700377 public void scriptCSetClearColor(float r, float g, float b, float a) {
378 nScriptCSetClearColor(r, g, b, a);
379 }
380
381 public void scriptCSetClearDepth(float d) {
382 nScriptCSetClearDepth(d);
383 }
384
385 public void scriptCSetClearStencil(int stencil) {
386 nScriptCSetClearStencil(stencil);
387 }
388
389 public void scriptCAddType(Type t) {
390 nScriptCAddType(t.mID);
391 }
392
393 public void scriptCSetRoot(boolean r) {
394 nScriptCSetRoot(r);
395 }
396
397 public void scriptCSetScript(String s) {
Jack Palevich43702d82009-05-28 13:38:16 -0700398 try {
Jack Palevich63975dd2009-05-28 15:34:15 -0700399 byte[] bytes = s.getBytes("UTF-8");
400 nScriptCSetScript(bytes, 0, bytes.length);
Jack Palevich43702d82009-05-28 13:38:16 -0700401 } catch (java.io.UnsupportedEncodingException e) {
402 throw new RuntimeException(e);
403 }
404 }
405
Jack Palevich43702d82009-05-28 13:38:16 -0700406 public void scriptCSetScript(Resources resources, int id) {
407 InputStream is = resources.openRawResource(id);
408 try {
409 try {
410 scriptCSetScript(is);
411 } finally {
412 is.close();
413 }
414 } catch(IOException e) {
415 throw new Resources.NotFoundException();
416 }
417 }
418
419 public void scriptCSetScript(InputStream is) throws IOException {
420 byte[] buf = new byte[1024];
421 int currentPos = 0;
422 while(true) {
423 int bytesLeft = buf.length - currentPos;
424 if (bytesLeft == 0) {
425 byte[] buf2 = new byte[buf.length * 2];
426 System.arraycopy(buf, 0, buf2, 0, buf.length);
427 buf = buf2;
428 bytesLeft = buf.length - currentPos;
429 }
430 int bytesRead = is.read(buf, currentPos, bytesLeft);
431 if (bytesRead <= 0) {
432 break;
433 }
434 currentPos += bytesRead;
435 }
436 nScriptCSetScript(buf, 0, currentPos);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700437 }
438
439 public Script scriptCCreate() {
440 int id = nScriptCCreate();
441 return new Script(id);
442 }
443
444 //////////////////////////////////////////////////////////////////////////////////
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700445 // ProgramVertex
446
447 public class ProgramVertex extends BaseObj {
448 ProgramVertex(int id) {
Jason Sams36e612a2009-07-31 16:26:13 -0700449 super(RenderScript.this);
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700450 mID = id;
451 }
452
453 public void destroy() {
454 nProgramVertexDestroy(mID);
455 mID = 0;
456 }
457
458 public void bindAllocation(int slot, Allocation va) {
459 nProgramVertexBindAllocation(mID, slot, va.mID);
460 }
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700461 }
462
463 public void programVertexBegin(Element in, Element out) {
464 int inID = 0;
465 int outID = 0;
466 if (in != null) {
467 inID = in.mID;
468 }
469 if (out != null) {
470 outID = out.mID;
471 }
472 nProgramVertexBegin(inID, outID);
473 }
474
475 public void programVertexSetType(int slot, Type t) {
476 nProgramVertexSetType(slot, t.mID);
477 }
478
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700479 public void programVertexSetTextureMatrixEnable(boolean enable) {
480 nProgramVertexSetTextureMatrixEnable(enable);
481 }
482
Jason Samsee411122009-07-21 12:20:54 -0700483 public void programVertexAddLight(Light l) {
484 nProgramVertexAddLight(l.mID);
485 }
486
Jason Sams1fe9b8c2009-06-11 14:46:10 -0700487 public ProgramVertex programVertexCreate() {
488 int id = nProgramVertexCreate();
489 return new ProgramVertex(id);
490 }
491
492
493 //////////////////////////////////////////////////////////////////////////////////
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700494 // ProgramFragmentStore
495
496 public class ProgramFragmentStore extends BaseObj {
497 ProgramFragmentStore(int id) {
Jason Sams36e612a2009-07-31 16:26:13 -0700498 super(RenderScript.this);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700499 mID = id;
500 }
501
502 public void destroy() {
Jason Sams3eaa3382009-06-10 15:04:38 -0700503 nProgramFragmentStoreDestroy(mID);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700504 mID = 0;
505 }
506 }
507
508 public void programFragmentStoreBegin(Element in, Element out) {
509 int inID = 0;
510 int outID = 0;
511 if (in != null) {
512 inID = in.mID;
513 }
514 if (out != null) {
515 outID = out.mID;
516 }
517 nProgramFragmentStoreBegin(inID, outID);
518 }
519
520 public void programFragmentStoreDepthFunc(DepthFunc func) {
521 nProgramFragmentStoreDepthFunc(func.mID);
522 }
523
524 public void programFragmentStoreDepthMask(boolean enable) {
525 nProgramFragmentStoreDepthMask(enable);
526 }
527
528 public void programFragmentStoreColorMask(boolean r, boolean g, boolean b, boolean a) {
529 nProgramFragmentStoreColorMask(r,g,b,a);
530 }
531
532 public void programFragmentStoreBlendFunc(BlendSrcFunc src, BlendDstFunc dst) {
533 nProgramFragmentStoreBlendFunc(src.mID, dst.mID);
534 }
535
536 public void programFragmentStoreDitherEnable(boolean enable) {
537 nProgramFragmentStoreDither(enable);
538 }
539
540 public ProgramFragmentStore programFragmentStoreCreate() {
541 int id = nProgramFragmentStoreCreate();
542 return new ProgramFragmentStore(id);
543 }
544
545 //////////////////////////////////////////////////////////////////////////////////
546 // ProgramFragment
547
548 public class ProgramFragment extends BaseObj {
549 ProgramFragment(int id) {
Jason Sams36e612a2009-07-31 16:26:13 -0700550 super(RenderScript.this);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700551 mID = id;
552 }
553
554 public void destroy() {
Jason Sams3eaa3382009-06-10 15:04:38 -0700555 nProgramFragmentDestroy(mID);
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700556 mID = 0;
557 }
558
559 public void bindTexture(Allocation va, int slot) {
560 nProgramFragmentBindTexture(mID, slot, va.mID);
561 }
562
Jason Sams02fb2cb2009-05-28 15:37:57 -0700563 public void bindSampler(Sampler vs, int slot) {
564 nProgramFragmentBindSampler(mID, slot, vs.mID);
565 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700566 }
567
568 public void programFragmentBegin(Element in, Element out) {
569 int inID = 0;
570 int outID = 0;
571 if (in != null) {
572 inID = in.mID;
573 }
574 if (out != null) {
575 outID = out.mID;
576 }
577 nProgramFragmentBegin(inID, outID);
578 }
579
580 public void programFragmentSetType(int slot, Type t) {
581 nProgramFragmentSetType(slot, t.mID);
582 }
583
584 public void programFragmentSetType(int slot, EnvMode t) {
585 nProgramFragmentSetEnvMode(slot, t.mID);
586 }
587
588 public void programFragmentSetTexEnable(int slot, boolean enable) {
589 nProgramFragmentSetTexEnable(slot, enable);
590 }
591
Jason Samse6c8e9b2009-07-17 17:29:09 -0700592 public void programFragmentSetTexEnvMode(int slot, EnvMode env) {
593 nProgramFragmentSetEnvMode(slot, env.mID);
594 }
595
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700596 public ProgramFragment programFragmentCreate() {
597 int id = nProgramFragmentCreate();
598 return new ProgramFragment(id);
599 }
600
Jason Sams02fb2cb2009-05-28 15:37:57 -0700601 //////////////////////////////////////////////////////////////////////////////////
602 // Sampler
603
604 public class Sampler extends BaseObj {
605 Sampler(int id) {
Jason Sams36e612a2009-07-31 16:26:13 -0700606 super(RenderScript.this);
Jason Sams02fb2cb2009-05-28 15:37:57 -0700607 mID = id;
608 }
609
610 public void destroy() {
611 nSamplerDestroy(mID);
612 mID = 0;
613 }
614 }
615
616 public void samplerBegin() {
617 nSamplerBegin();
618 }
619
620 public void samplerSet(SamplerParam p, SamplerValue v) {
621 nSamplerSet(p.mID, v.mID);
622 }
623
624 public Sampler samplerCreate() {
625 int id = nSamplerCreate();
626 return new Sampler(id);
627 }
628
Jason Samsbba134c2009-06-22 15:49:21 -0700629 //////////////////////////////////////////////////////////////////////////////////
630 // Light
631
632 public class Light extends BaseObj {
633 Light(int id) {
Jason Sams36e612a2009-07-31 16:26:13 -0700634 super(RenderScript.this);
Jason Samsbba134c2009-06-22 15:49:21 -0700635 mID = id;
636 }
637
638 public void destroy() {
639 nLightDestroy(mID);
640 mID = 0;
641 }
642
643 public void setColor(float r, float g, float b) {
644 nLightSetColor(mID, r, g, b);
645 }
646
647 public void setPosition(float x, float y, float z) {
648 nLightSetPosition(mID, x, y, z);
649 }
650 }
651
652 public void lightBegin() {
653 nLightBegin();
654 }
655
656 public void lightSetIsMono(boolean isMono) {
657 nLightSetIsMono(isMono);
658 }
659
660 public void lightSetIsLocal(boolean isLocal) {
661 nLightSetIsLocal(isLocal);
662 }
663
664 public Light lightCreate() {
665 int id = nLightCreate();
666 return new Light(id);
667 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700668
Jason Sams64676f32009-07-08 18:01:53 -0700669 //////////////////////////////////////////////////////////////////////////////////
670 // File
671
672 public class File extends BaseObj {
673 File(int id) {
Jason Sams36e612a2009-07-31 16:26:13 -0700674 super(RenderScript.this);
Jason Sams64676f32009-07-08 18:01:53 -0700675 mID = id;
676 }
677
678 public void destroy() {
679 //nLightDestroy(mID);
680 mID = 0;
681 }
682 }
683
684 public File fileOpen(String s) throws IllegalStateException, IllegalArgumentException
685 {
686 if(s.length() < 1) {
687 throw new IllegalArgumentException("fileOpen does not accept a zero length string.");
688 }
689
690 try {
691 byte[] bytes = s.getBytes("UTF-8");
692 int id = nFileOpen(bytes);
693 return new File(id);
694 } catch (java.io.UnsupportedEncodingException e) {
695 throw new RuntimeException(e);
696 }
697 }
698
699
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700700 ///////////////////////////////////////////////////////////////////////////////////
701 // Root state
702
703 public void contextBindRootScript(Script s) {
704 nContextBindRootScript(s.mID);
705 }
706
707 //public void contextBindSampler(Sampler s, int slot) {
708 //nContextBindSampler(s.mID);
709 //}
710
711 public void contextBindProgramFragmentStore(ProgramFragmentStore pfs) {
712 nContextBindProgramFragmentStore(pfs.mID);
713 }
714
715 public void contextBindProgramFragment(ProgramFragment pf) {
716 nContextBindProgramFragment(pf.mID);
717 }
718
Jason Sams0826a6f2009-06-15 19:04:56 -0700719 public void contextBindProgramVertex(ProgramVertex pf) {
720 nContextBindProgramVertex(pf.mID);
721 }
722
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700723/*
724 RsAdapter2D rsAdapter2DCreate ();
725 void rsAdapter2DBindAllocation (RsAdapter2D adapt, RsAllocation alloc);
726 void rsAdapter2DDestroy (RsAdapter2D adapter);
727 void rsAdapter2DSetConstraint (RsAdapter2D adapter, RsDimension dim, uint32_t value);
728 void rsAdapter2DData (RsAdapter2D adapter, const void * data);
729 void rsAdapter2DSubData (RsAdapter2D adapter, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void * data);
730 void rsSamplerBegin ();
731 void rsSamplerSet (RsSamplerParam p, RsSamplerValue value);
732 RsSampler rsSamplerCreate ();
733 void rsSamplerBind (RsSampler sampler, RsAllocation alloc);
734*/
735
736}
737
Jason Sams36e612a2009-07-31 16:26:13 -0700738