blob: 80267c773b470e1d0521e732b841a94357f82a9d [file] [log] [blame]
Alex Sakhartchouk9996b752011-08-09 11:36:19 -07001/*
2 * Copyright (C) 2011 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
17/** @file rs_graphics.rsh
18 * \brief Renderscript graphics API
19 *
20 * A set of graphics functions used by Renderscript.
21 *
22 */
Jason Sams1b937f52010-06-09 14:26:16 -070023#ifndef __RS_GRAPHICS_RSH__
24#define __RS_GRAPHICS_RSH__
25
Alex Sakhartchouk407f8ca2011-09-23 17:05:04 -070026// These are API 15 once it get official
27typedef enum {
28 RS_DEPTH_FUNC_ALWAYS,
29 RS_DEPTH_FUNC_LESS,
30 RS_DEPTH_FUNC_LEQUAL,
31 RS_DEPTH_FUNC_GREATER,
32 RS_DEPTH_FUNC_GEQUAL,
33 RS_DEPTH_FUNC_EQUAL,
34 RS_DEPTH_FUNC_NOTEQUAL
35} rs_depth_func;
36
37typedef enum {
38 RS_BLEND_SRC_ZERO, // 0
39 RS_BLEND_SRC_ONE, // 1
40 RS_BLEND_SRC_DST_COLOR, // 2
41 RS_BLEND_SRC_ONE_MINUS_DST_COLOR, // 3
42 RS_BLEND_SRC_SRC_ALPHA, // 4
43 RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA, // 5
44 RS_BLEND_SRC_DST_ALPHA, // 6
45 RS_BLEND_SRC_ONE_MINUS_DST_ALPHA, // 7
46 RS_BLEND_SRC_SRC_ALPHA_SATURATE // 8
47} rs_blend_src_func;
48
49typedef enum {
50 RS_BLEND_DST_ZERO, // 0
51 RS_BLEND_DST_ONE, // 1
52 RS_BLEND_DST_SRC_COLOR, // 2
53 RS_BLEND_DST_ONE_MINUS_SRC_COLOR, // 3
54 RS_BLEND_DST_SRC_ALPHA, // 4
55 RS_BLEND_DST_ONE_MINUS_SRC_ALPHA, // 5
56 RS_BLEND_DST_DST_ALPHA, // 6
57 RS_BLEND_DST_ONE_MINUS_DST_ALPHA // 7
58} rs_blend_dst_func;
59
60typedef enum {
61 RS_CULL_BACK,
62 RS_CULL_FRONT,
63 RS_CULL_NONE
64} rs_cull_mode;
65
66typedef enum {
67 RS_SAMPLER_NEAREST,
68 RS_SAMPLER_LINEAR,
69 RS_SAMPLER_LINEAR_MIP_LINEAR,
70 RS_SAMPLER_WRAP,
71 RS_SAMPLER_CLAMP,
72 RS_SAMPLER_LINEAR_MIP_NEAREST,
73} rs_sampler_value;
74
Alex Sakhartchouk43253872011-09-28 15:23:18 -070075#if (defined(RS_VERSION) && (RS_VERSION >= 14))
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070076/**
77 * Set the color target used for all subsequent rendering calls
78 * @param colorTarget
79 * @param slot
80 */
81extern void __attribute__((overloadable))
82 rsgBindColorTarget(rs_allocation colorTarget, uint slot);
83
84/**
85 * Clear the previously set color target
86 * @param slot
87 */
88extern void __attribute__((overloadable))
89 rsgClearColorTarget(uint slot);
90
91/**
92 * Set the depth target used for all subsequent rendering calls
93 * @param depthTarget
94 */
95extern void __attribute__((overloadable))
96 rsgBindDepthTarget(rs_allocation depthTarget);
97
98/**
99 * Clear the previously set depth target
100 */
101extern void __attribute__((overloadable))
102 rsgClearDepthTarget(void);
103
104/**
105 * Clear all color and depth targets and resume rendering into
106 * the framebuffer
107 */
108extern void __attribute__((overloadable))
109 rsgClearAllRenderTargets(void);
110
111/**
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700112 * Force Renderscript to finish all rendering commands
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -0700113 */
114extern uint __attribute__((overloadable))
115 rsgFinish(void);
Jason Samsf2bcce72010-03-26 15:33:42 -0700116
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700117#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
118
Jason Sams09aeb8a2011-01-28 15:49:07 -0800119/**
120 * Bind a new ProgramFragment to the rendering context.
121 *
122 * @param pf
123 */
124extern void __attribute__((overloadable))
125 rsgBindProgramFragment(rs_program_fragment pf);
126
127/**
128 * Bind a new ProgramStore to the rendering context.
129 *
130 * @param ps
131 */
132extern void __attribute__((overloadable))
133 rsgBindProgramStore(rs_program_store ps);
134
Alex Sakhartchouk407f8ca2011-09-23 17:05:04 -0700135
136/**
137 * @hide
138 * Get program store depth function
139 *
140 * @param ps
141 */
142extern rs_depth_func __attribute__((overloadable))
143 rsgProgramStoreGetDepthFunc(rs_program_store ps);
144
145/**
146 * @hide
147 * Get program store depth mask
148 *
149 * @param ps
150 */
151extern bool __attribute__((overloadable))
152 rsgProgramStoreGetDepthMask(rs_program_store ps);
153/**
154 * @hide
155 * Get program store red component color mask
156 *
157 * @param ps
158 */
159extern bool __attribute__((overloadable))
160 rsgProgramStoreGetColorMaskR(rs_program_store ps);
161
162/**
163 * @hide
164 * Get program store green component color mask
165 *
166 * @param ps
167 */
168extern bool __attribute__((overloadable))
169 rsgProgramStoreGetColorMaskG(rs_program_store ps);
170
171/**
172 * @hide
173 * Get program store blur component color mask
174 *
175 * @param ps
176 */
177extern bool __attribute__((overloadable))
178 rsgProgramStoreGetColorMaskB(rs_program_store ps);
179
180/**
181 * @hide
182 * Get program store alpha component color mask
183 *
184 * @param ps
185 */
186extern bool __attribute__((overloadable))
187 rsgProgramStoreGetColorMaskA(rs_program_store ps);
188
189/**
190 * @hide
191 * Get program store blend source function
192 *
193 * @param ps
194 */
195extern rs_blend_src_func __attribute__((overloadable))
196 rsgProgramStoreGetBlendSrcFunc(rs_program_store ps);
197
198/**
199 * @hide
200 * Get program store blend destination function
201 *
202 * @param ps
203 */
204extern rs_blend_dst_func __attribute__((overloadable))
205 rsgProgramStoreGetBlendDstFunc(rs_program_store ps);
206
207/**
208 * @hide
209 * Get program store dither state
210 *
211 * @param ps
212 */
213extern bool __attribute__((overloadable))
214 rsgProgramStoreGetDitherEnabled(rs_program_store ps);
215
216
Jason Sams09aeb8a2011-01-28 15:49:07 -0800217/**
218 * Bind a new ProgramVertex to the rendering context.
219 *
220 * @param pv
221 */
222extern void __attribute__((overloadable))
223 rsgBindProgramVertex(rs_program_vertex pv);
224
225/**
226 * Bind a new ProgramRaster to the rendering context.
227 *
228 * @param pr
229 */
230extern void __attribute__((overloadable))
231 rsgBindProgramRaster(rs_program_raster pr);
232
233/**
Alex Sakhartchouk407f8ca2011-09-23 17:05:04 -0700234 * @hide
235 * Get program raster point sprite state
236 *
237 * @param pr
238 */
239extern bool __attribute__((overloadable))
240 rsgProgramRasterGetPointSpriteEnabled(rs_program_raster pr);
241
242/**
243 * @hide
244 * Get program raster cull mode
245 *
246 * @param pr
247 */
248extern rs_cull_mode __attribute__((overloadable))
249 rsgProgramRasterGetCullMode(rs_program_raster pr);
250
251/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800252 * Bind a new Sampler object to a ProgramFragment. The sampler will
253 * operate on the texture bound at the matching slot.
254 *
255 * @param slot
256 */
Jason Sams73495472010-07-29 17:31:14 -0700257extern void __attribute__((overloadable))
258 rsgBindSampler(rs_program_fragment, uint slot, rs_sampler);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800259
260/**
Alex Sakhartchouk407f8ca2011-09-23 17:05:04 -0700261 * @hide
262 * Get sampler minification value
263 *
264 * @param pr
265 */
266extern rs_sampler_value __attribute__((overloadable))
267 rsgSamplerGetMinification(rs_sampler s);
268
269/**
270 * @hide
271 * Get sampler magnification value
272 *
273 * @param pr
274 */
275extern rs_sampler_value __attribute__((overloadable))
276 rsgSamplerGetMagnification(rs_sampler s);
277
278/**
279 * @hide
280 * Get sampler wrap S value
281 *
282 * @param pr
283 */
284extern rs_sampler_value __attribute__((overloadable))
285 rsgSamplerGetWrapS(rs_sampler s);
286
287/**
288 * @hide
289 * Get sampler wrap T value
290 *
291 * @param pr
292 */
293extern rs_sampler_value __attribute__((overloadable))
294 rsgSamplerGetWrapT(rs_sampler s);
295
296/**
297 * @hide
298 * Get sampler anisotropy
299 *
300 * @param pr
301 */
302extern float __attribute__((overloadable))
303 rsgSamplerGetAnisotropy(rs_sampler s);
304
305/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800306 * Bind a new Allocation object to a ProgramFragment. The
307 * Allocation must be a valid texture for the Program. The sampling
308 * of the texture will be controled by the Sampler bound at the
309 * matching slot.
310 *
311 * @param slot
312 */
Jason Sams73495472010-07-29 17:31:14 -0700313extern void __attribute__((overloadable))
314 rsgBindTexture(rs_program_fragment, uint slot, rs_allocation);
Jason Sams51f36ab2010-03-18 14:36:05 -0700315
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700316/**
317 * Load the projection matrix for a currently bound fixed function
318 * vertex program. Calling this function with a custom vertex shader
319 * would result in an error.
320 * @param proj projection matrix
321 */
Jason Sams73495472010-07-29 17:31:14 -0700322extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700323 rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 *proj);
324/**
325 * Load the model matrix for a currently bound fixed function
326 * vertex program. Calling this function with a custom vertex shader
327 * would result in an error.
328 * @param model model matrix
329 */
Jason Sams73495472010-07-29 17:31:14 -0700330extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700331 rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *model);
332/**
333 * Load the texture matrix for a currently bound fixed function
334 * vertex program. Calling this function with a custom vertex shader
335 * would result in an error.
336 * @param tex texture matrix
337 */
Jason Sams73495472010-07-29 17:31:14 -0700338extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700339 rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *tex);
340/**
341 * Get the projection matrix for a currently bound fixed function
342 * vertex program. Calling this function with a custom vertex shader
343 * would result in an error.
344 * @param proj matrix to store the current projection matrix into
345 */
Jason Sams6445e522010-08-04 17:50:20 -0700346extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700347 rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *proj);
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700348
Jason Sams09aeb8a2011-01-28 15:49:07 -0800349/**
350 * Set the constant color for a fixed function emulation program.
351 *
352 * @param pf
353 * @param r
354 * @param g
355 * @param b
356 * @param a
357 */
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700358extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800359 rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a);
Jason Sams6445e522010-08-04 17:50:20 -0700360
Jason Sams09aeb8a2011-01-28 15:49:07 -0800361/**
362 * Get the width of the current rendering surface.
363 *
364 * @return uint
365 */
Jason Sams73495472010-07-29 17:31:14 -0700366extern uint __attribute__((overloadable))
367 rsgGetWidth(void);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800368
369/**
370 * Get the height of the current rendering surface.
371 *
372 * @return uint
373 */
Jason Sams73495472010-07-29 17:31:14 -0700374extern uint __attribute__((overloadable))
375 rsgGetHeight(void);
Jason Sams51f36ab2010-03-18 14:36:05 -0700376
Jason Samsb7e83bd2010-12-15 01:41:00 -0800377
Jason Sams09aeb8a2011-01-28 15:49:07 -0800378/**
379 * Sync the contents of an allocation from its SCRIPT memory space to its HW
380 * memory spaces.
381 *
382 * @param alloc
383 */
384extern void __attribute__((overloadable))
385 rsgAllocationSyncAll(rs_allocation alloc);
386
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700387#if (defined(RS_VERSION) && (RS_VERSION >= 14))
388
Jason Sams09aeb8a2011-01-28 15:49:07 -0800389/**
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700390 * Sync the contents of an allocation from memory space
391 * specified by source.
392 *
393 * @param alloc
394 * @param source
395 */
396extern void __attribute__((overloadable))
397 rsgAllocationSyncAll(rs_allocation alloc,
398 rs_allocation_usage_type source);
399
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700400#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
401
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700402/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800403 * Low performance utility function for drawing a simple rectangle. Not
404 * intended for drawing large quantities of geometry.
405 *
406 * @param x1
407 * @param y1
408 * @param x2
409 * @param y2
410 * @param z
411 */
Jason Samsb7e83bd2010-12-15 01:41:00 -0800412extern void __attribute__((overloadable))
Jason Sams73495472010-07-29 17:31:14 -0700413 rsgDrawRect(float x1, float y1, float x2, float y2, float z);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800414
415/**
416 * Low performance utility function for drawing a simple quad. Not intended for
417 * drawing large quantities of geometry.
418 *
419 * @param x1
420 * @param y1
421 * @param z1
422 * @param x2
423 * @param y2
424 * @param z2
425 * @param x3
426 * @param y3
427 * @param z3
428 * @param x4
429 * @param y4
430 * @param z4
431 */
Jason Sams73495472010-07-29 17:31:14 -0700432extern void __attribute__((overloadable))
433 rsgDrawQuad(float x1, float y1, float z1,
434 float x2, float y2, float z2,
435 float x3, float y3, float z3,
436 float x4, float y4, float z4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800437
438
439/**
440 * Low performance utility function for drawing a textured quad. Not intended
441 * for drawing large quantities of geometry.
442 *
443 * @param x1
444 * @param y1
445 * @param z1
446 * @param u1
447 * @param v1
448 * @param x2
449 * @param y2
450 * @param z2
451 * @param u2
452 * @param v2
453 * @param x3
454 * @param y3
455 * @param z3
456 * @param u3
457 * @param v3
458 * @param x4
459 * @param y4
460 * @param z4
461 * @param u4
462 * @param v4
463 */
Jason Sams73495472010-07-29 17:31:14 -0700464extern void __attribute__((overloadable))
465 rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
466 float x2, float y2, float z2, float u2, float v2,
467 float x3, float y3, float z3, float u3, float v3,
468 float x4, float y4, float z4, float u4, float v4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800469
470
471/**
472 * Low performance function for drawing rectangles in screenspace. This
473 * function uses the default passthough ProgramVertex. Any bound ProgramVertex
474 * is ignored. This function has considerable overhead and should not be used
475 * for drawing in shipping applications.
476 *
477 * @param x
478 * @param y
479 * @param z
480 * @param w
481 * @param h
482 */
Jason Sams73495472010-07-29 17:31:14 -0700483extern void __attribute__((overloadable))
484 rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h);
Jason Sams51f36ab2010-03-18 14:36:05 -0700485
Jason Sams09aeb8a2011-01-28 15:49:07 -0800486/**
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700487 * Draw a mesh using the current context state. The whole mesh is
Jason Sams09aeb8a2011-01-28 15:49:07 -0800488 * rendered.
489 *
490 * @param ism
491 */
Jason Sams73495472010-07-29 17:31:14 -0700492extern void __attribute__((overloadable))
493 rsgDrawMesh(rs_mesh ism);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700494/**
495 * Draw part of a mesh using the current context state.
496 * @param ism mesh object to render
497 * @param primitiveIndex for meshes that contain multiple primitive groups
498 * this parameter specifies the index of the group to draw.
499 */
Jason Sams73495472010-07-29 17:31:14 -0700500extern void __attribute__((overloadable))
501 rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700502/**
503 * Draw specified index range of part of a mesh using the current context state.
504 * @param ism mesh object to render
505 * @param primitiveIndex for meshes that contain multiple primitive groups
506 * this parameter specifies the index of the group to draw.
507 * @param start starting index in the range
508 * @param len number of indices to draw
509 */
Jason Sams73495472010-07-29 17:31:14 -0700510extern void __attribute__((overloadable))
511 rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len);
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -0700512
Jason Sams09aeb8a2011-01-28 15:49:07 -0800513/**
514 * Clears the rendering surface to the specified color.
515 *
516 * @param r
517 * @param g
518 * @param b
519 * @param a
520 */
Jason Sams73495472010-07-29 17:31:14 -0700521extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800522 rsgClearColor(float r, float g, float b, float a);
523
524/**
525 * Clears the depth suface to the specified value.
Jason Sams09aeb8a2011-01-28 15:49:07 -0800526 */
Jason Sams73495472010-07-29 17:31:14 -0700527extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800528 rsgClearDepth(float value);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700529/**
530 * Draws text given a string and location
531 */
Jason Sams73495472010-07-29 17:31:14 -0700532extern void __attribute__((overloadable))
533 rsgDrawText(const char *, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700534/**
535 * \overload
536 */
Jason Sams73495472010-07-29 17:31:14 -0700537extern void __attribute__((overloadable))
538 rsgDrawText(rs_allocation, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700539/**
540 * Binds the font object to be used for all subsequent font rendering calls
541 * @param font object to bind
542 */
Jason Sams73495472010-07-29 17:31:14 -0700543extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700544 rsgBindFont(rs_font font);
545/**
546 * Sets the font color for all subsequent rendering calls
547 * @param r red component
548 * @param g green component
549 * @param b blue component
550 * @param a alpha component
551 */
Alex Sakhartchouk9fc9f032010-08-04 14:45:48 -0700552extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700553 rsgFontColor(float r, float g, float b, float a);
554/**
555 * Returns the bounding box of the text relative to (0, 0)
556 * Any of left, right, top, bottom could be NULL
557 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700558extern void __attribute__((overloadable))
559 rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700560/**
561 * \overload
562 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700563extern void __attribute__((overloadable))
564 rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700565/**
566 * Computes an axis aligned bounding box of a mesh object
567 */
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700568extern void __attribute__((overloadable))
569 rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,
570 float *maxX, float *maxY, float *maxZ);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700571/**
572 * \overload
573 */
Jason Sams399dc9e2010-10-15 17:57:07 -0700574__inline__ static void __attribute__((overloadable, always_inline))
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700575rsgMeshComputeBoundingBox(rs_mesh mesh, float3 *bBoxMin, float3 *bBoxMax) {
576 float x1, y1, z1, x2, y2, z2;
577 rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2);
578 bBoxMin->x = x1;
579 bBoxMin->y = y1;
580 bBoxMin->z = z1;
581 bBoxMax->x = x2;
582 bBoxMax->y = y2;
583 bBoxMax->z = z2;
584}
585
Jason Sams1b937f52010-06-09 14:26:16 -0700586#endif
Jason Sams51f36ab2010-03-18 14:36:05 -0700587