blob: 1fcb7ed1653552b3fe793644cf8694da067e6def [file] [log] [blame]
Alex Sakhartchouk9996b752011-08-09 11:36:19 -07001/*
Alex Sakhartchoukf8e195e2012-03-22 10:50:55 -07002 * Copyright (C) 2011-2012 The Android Open Source Project
Alex Sakhartchouk9996b752011-08-09 11:36:19 -07003 *
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
Stephen Hinese227f9a2013-05-29 14:48:19 -070018 * \brief RenderScript graphics API
Alex Sakhartchouk9996b752011-08-09 11:36:19 -070019 *
Stephen Hinese227f9a2013-05-29 14:48:19 -070020 * A set of graphics functions used by RenderScript.
Alex Sakhartchouk9996b752011-08-09 11:36:19 -070021 *
22 */
Jason Sams1b937f52010-06-09 14:26:16 -070023#ifndef __RS_GRAPHICS_RSH__
24#define __RS_GRAPHICS_RSH__
Alex Sakhartchouk5909d262011-11-17 15:59:13 -080025
Jason Sams3ff0fe72014-05-19 15:06:59 -070026#ifdef __LP64__
27//#error "RenderScript graphics is deprecated and not supported in 64bit mode."
28#else
29
Alex Sakhartchoukf8e195e2012-03-22 10:50:55 -070030#include "rs_mesh.rsh"
31#include "rs_program.rsh"
32
Alex Sakhartchouk43253872011-09-28 15:23:18 -070033#if (defined(RS_VERSION) && (RS_VERSION >= 14))
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070034/**
35 * Set the color target used for all subsequent rendering calls
36 * @param colorTarget
37 * @param slot
38 */
39extern void __attribute__((overloadable))
40 rsgBindColorTarget(rs_allocation colorTarget, uint slot);
41
42/**
43 * Clear the previously set color target
44 * @param slot
45 */
46extern void __attribute__((overloadable))
47 rsgClearColorTarget(uint slot);
48
49/**
50 * Set the depth target used for all subsequent rendering calls
51 * @param depthTarget
52 */
53extern void __attribute__((overloadable))
54 rsgBindDepthTarget(rs_allocation depthTarget);
55
56/**
57 * Clear the previously set depth target
58 */
59extern void __attribute__((overloadable))
60 rsgClearDepthTarget(void);
61
62/**
63 * Clear all color and depth targets and resume rendering into
64 * the framebuffer
65 */
66extern void __attribute__((overloadable))
67 rsgClearAllRenderTargets(void);
68
69/**
Stephen Hinese227f9a2013-05-29 14:48:19 -070070 * Force RenderScript to finish all rendering commands
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070071 */
72extern uint __attribute__((overloadable))
73 rsgFinish(void);
Jason Samsf2bcce72010-03-26 15:33:42 -070074
Alex Sakhartchouk43253872011-09-28 15:23:18 -070075#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
76
Jason Sams09aeb8a2011-01-28 15:49:07 -080077/**
78 * Bind a new ProgramFragment to the rendering context.
79 *
80 * @param pf
81 */
82extern void __attribute__((overloadable))
83 rsgBindProgramFragment(rs_program_fragment pf);
84
85/**
86 * Bind a new ProgramStore to the rendering context.
87 *
88 * @param ps
89 */
90extern void __attribute__((overloadable))
91 rsgBindProgramStore(rs_program_store ps);
92
93/**
94 * Bind a new ProgramVertex to the rendering context.
95 *
96 * @param pv
97 */
98extern void __attribute__((overloadable))
99 rsgBindProgramVertex(rs_program_vertex pv);
100
101/**
102 * Bind a new ProgramRaster to the rendering context.
103 *
104 * @param pr
105 */
106extern void __attribute__((overloadable))
107 rsgBindProgramRaster(rs_program_raster pr);
108
109/**
110 * Bind a new Sampler object to a ProgramFragment. The sampler will
111 * operate on the texture bound at the matching slot.
112 *
113 * @param slot
114 */
Jason Sams73495472010-07-29 17:31:14 -0700115extern void __attribute__((overloadable))
116 rsgBindSampler(rs_program_fragment, uint slot, rs_sampler);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800117
118/**
119 * Bind a new Allocation object to a ProgramFragment. The
120 * Allocation must be a valid texture for the Program. The sampling
121 * of the texture will be controled by the Sampler bound at the
122 * matching slot.
123 *
124 * @param slot
125 */
Jason Sams73495472010-07-29 17:31:14 -0700126extern void __attribute__((overloadable))
127 rsgBindTexture(rs_program_fragment, uint slot, rs_allocation);
Jason Sams51f36ab2010-03-18 14:36:05 -0700128
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700129/**
130 * Load the projection matrix for a currently bound fixed function
131 * vertex program. Calling this function with a custom vertex shader
132 * would result in an error.
133 * @param proj projection matrix
134 */
Jason Sams73495472010-07-29 17:31:14 -0700135extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700136 rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 *proj);
137/**
138 * Load the model matrix for a currently bound fixed function
139 * vertex program. Calling this function with a custom vertex shader
140 * would result in an error.
141 * @param model model matrix
142 */
Jason Sams73495472010-07-29 17:31:14 -0700143extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700144 rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *model);
145/**
146 * Load the texture matrix for a currently bound fixed function
147 * vertex program. Calling this function with a custom vertex shader
148 * would result in an error.
149 * @param tex texture matrix
150 */
Jason Sams73495472010-07-29 17:31:14 -0700151extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700152 rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *tex);
153/**
154 * Get the projection matrix for a currently bound fixed function
155 * vertex program. Calling this function with a custom vertex shader
156 * would result in an error.
157 * @param proj matrix to store the current projection matrix into
158 */
Jason Sams6445e522010-08-04 17:50:20 -0700159extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700160 rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *proj);
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700161
Jason Sams09aeb8a2011-01-28 15:49:07 -0800162/**
163 * Set the constant color for a fixed function emulation program.
164 *
165 * @param pf
166 * @param r
167 * @param g
168 * @param b
169 * @param a
170 */
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700171extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800172 rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a);
Jason Sams6445e522010-08-04 17:50:20 -0700173
Jason Sams09aeb8a2011-01-28 15:49:07 -0800174/**
Alex Sakhartchouka720a142012-01-10 10:16:52 -0800175 * Bind a new Allocation object to a ProgramFragment. The
176 * Allocation must be a valid constant input for the Program.
177 *
178 * @param ps program object
179 * @param slot index of the constant buffer on the program
180 * @param c constants to bind
181 */
182extern void __attribute__((overloadable))
183 rsgBindConstant(rs_program_fragment ps, uint slot, rs_allocation c);
184
185/**
186 * Bind a new Allocation object to a ProgramVertex. The
187 * Allocation must be a valid constant input for the Program.
188 *
189 * @param pv program object
190 * @param slot index of the constant buffer on the program
191 * @param c constants to bind
192 */
193extern void __attribute__((overloadable))
194 rsgBindConstant(rs_program_vertex pv, uint slot, rs_allocation c);
195
196/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800197 * Get the width of the current rendering surface.
198 *
199 * @return uint
200 */
Jason Sams73495472010-07-29 17:31:14 -0700201extern uint __attribute__((overloadable))
202 rsgGetWidth(void);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800203
204/**
205 * Get the height of the current rendering surface.
206 *
207 * @return uint
208 */
Jason Sams73495472010-07-29 17:31:14 -0700209extern uint __attribute__((overloadable))
210 rsgGetHeight(void);
Jason Sams51f36ab2010-03-18 14:36:05 -0700211
Jason Samsb7e83bd2010-12-15 01:41:00 -0800212
Jason Sams09aeb8a2011-01-28 15:49:07 -0800213/**
214 * Sync the contents of an allocation from its SCRIPT memory space to its HW
215 * memory spaces.
216 *
217 * @param alloc
218 */
219extern void __attribute__((overloadable))
220 rsgAllocationSyncAll(rs_allocation alloc);
221
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700222#if (defined(RS_VERSION) && (RS_VERSION >= 14))
223
Jason Sams09aeb8a2011-01-28 15:49:07 -0800224/**
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700225 * Sync the contents of an allocation from memory space
226 * specified by source.
227 *
228 * @param alloc
229 * @param source
230 */
231extern void __attribute__((overloadable))
232 rsgAllocationSyncAll(rs_allocation alloc,
233 rs_allocation_usage_type source);
234
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700235#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
236
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700237/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800238 * Low performance utility function for drawing a simple rectangle. Not
239 * intended for drawing large quantities of geometry.
240 *
241 * @param x1
242 * @param y1
243 * @param x2
244 * @param y2
245 * @param z
246 */
Jason Samsb7e83bd2010-12-15 01:41:00 -0800247extern void __attribute__((overloadable))
Jason Sams73495472010-07-29 17:31:14 -0700248 rsgDrawRect(float x1, float y1, float x2, float y2, float z);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800249
250/**
251 * Low performance utility function for drawing a simple quad. Not intended for
252 * drawing large quantities of geometry.
253 *
254 * @param x1
255 * @param y1
256 * @param z1
257 * @param x2
258 * @param y2
259 * @param z2
260 * @param x3
261 * @param y3
262 * @param z3
263 * @param x4
264 * @param y4
265 * @param z4
266 */
Jason Sams73495472010-07-29 17:31:14 -0700267extern void __attribute__((overloadable))
268 rsgDrawQuad(float x1, float y1, float z1,
269 float x2, float y2, float z2,
270 float x3, float y3, float z3,
271 float x4, float y4, float z4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800272
273
274/**
275 * Low performance utility function for drawing a textured quad. Not intended
276 * for drawing large quantities of geometry.
277 *
278 * @param x1
279 * @param y1
280 * @param z1
281 * @param u1
282 * @param v1
283 * @param x2
284 * @param y2
285 * @param z2
286 * @param u2
287 * @param v2
288 * @param x3
289 * @param y3
290 * @param z3
291 * @param u3
292 * @param v3
293 * @param x4
294 * @param y4
295 * @param z4
296 * @param u4
297 * @param v4
298 */
Jason Sams73495472010-07-29 17:31:14 -0700299extern void __attribute__((overloadable))
300 rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
301 float x2, float y2, float z2, float u2, float v2,
302 float x3, float y3, float z3, float u3, float v3,
303 float x4, float y4, float z4, float u4, float v4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800304
305
306/**
307 * Low performance function for drawing rectangles in screenspace. This
308 * function uses the default passthough ProgramVertex. Any bound ProgramVertex
309 * is ignored. This function has considerable overhead and should not be used
310 * for drawing in shipping applications.
311 *
312 * @param x
313 * @param y
314 * @param z
315 * @param w
316 * @param h
317 */
Jason Sams73495472010-07-29 17:31:14 -0700318extern void __attribute__((overloadable))
319 rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h);
Jason Sams51f36ab2010-03-18 14:36:05 -0700320
Jason Sams9e0afb52011-10-31 13:23:43 -0700321extern void __attribute__((overloadable))
322 rsgDrawPath(rs_path p);
323
Jason Sams09aeb8a2011-01-28 15:49:07 -0800324/**
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700325 * Draw a mesh using the current context state. The whole mesh is
Jason Sams09aeb8a2011-01-28 15:49:07 -0800326 * rendered.
327 *
328 * @param ism
329 */
Jason Sams73495472010-07-29 17:31:14 -0700330extern void __attribute__((overloadable))
331 rsgDrawMesh(rs_mesh ism);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700332/**
333 * Draw part of a mesh using the current context state.
334 * @param ism mesh object to render
335 * @param primitiveIndex for meshes that contain multiple primitive groups
336 * this parameter specifies the index of the group to draw.
337 */
Jason Sams73495472010-07-29 17:31:14 -0700338extern void __attribute__((overloadable))
339 rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700340/**
341 * Draw specified index range of part of a mesh using the current context state.
342 * @param ism mesh object to render
343 * @param primitiveIndex for meshes that contain multiple primitive groups
344 * this parameter specifies the index of the group to draw.
345 * @param start starting index in the range
346 * @param len number of indices to draw
347 */
Jason Sams73495472010-07-29 17:31:14 -0700348extern void __attribute__((overloadable))
349 rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len);
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -0700350
Jason Sams09aeb8a2011-01-28 15:49:07 -0800351/**
352 * Clears the rendering surface to the specified color.
353 *
354 * @param r
355 * @param g
356 * @param b
357 * @param a
358 */
Jason Sams73495472010-07-29 17:31:14 -0700359extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800360 rsgClearColor(float r, float g, float b, float a);
361
362/**
363 * Clears the depth suface to the specified value.
Jason Sams09aeb8a2011-01-28 15:49:07 -0800364 */
Jason Sams73495472010-07-29 17:31:14 -0700365extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800366 rsgClearDepth(float value);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700367/**
368 * Draws text given a string and location
369 */
Jason Sams73495472010-07-29 17:31:14 -0700370extern void __attribute__((overloadable))
371 rsgDrawText(const char *, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700372/**
373 * \overload
374 */
Jason Sams73495472010-07-29 17:31:14 -0700375extern void __attribute__((overloadable))
376 rsgDrawText(rs_allocation, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700377/**
378 * Binds the font object to be used for all subsequent font rendering calls
379 * @param font object to bind
380 */
Jason Sams73495472010-07-29 17:31:14 -0700381extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700382 rsgBindFont(rs_font font);
383/**
384 * Sets the font color for all subsequent rendering calls
385 * @param r red component
386 * @param g green component
387 * @param b blue component
388 * @param a alpha component
389 */
Alex Sakhartchouk9fc9f032010-08-04 14:45:48 -0700390extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700391 rsgFontColor(float r, float g, float b, float a);
392/**
393 * Returns the bounding box of the text relative to (0, 0)
394 * Any of left, right, top, bottom could be NULL
395 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700396extern void __attribute__((overloadable))
397 rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700398/**
399 * \overload
400 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700401extern void __attribute__((overloadable))
402 rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700403/**
404 * Computes an axis aligned bounding box of a mesh object
405 */
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700406extern void __attribute__((overloadable))
407 rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,
408 float *maxX, float *maxY, float *maxZ);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700409/**
410 * \overload
411 */
Jason Sams399dc9e2010-10-15 17:57:07 -0700412__inline__ static void __attribute__((overloadable, always_inline))
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700413rsgMeshComputeBoundingBox(rs_mesh mesh, float3 *bBoxMin, float3 *bBoxMax) {
414 float x1, y1, z1, x2, y2, z2;
415 rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2);
416 bBoxMin->x = x1;
417 bBoxMin->y = y1;
418 bBoxMin->z = z1;
419 bBoxMax->x = x2;
420 bBoxMax->y = y2;
421 bBoxMax->z = z2;
422}
423
Jason Sams3ff0fe72014-05-19 15:06:59 -0700424#endif //__LP64__
Jason Sams1b937f52010-06-09 14:26:16 -0700425#endif
Jason Sams51f36ab2010-03-18 14:36:05 -0700426