blob: 06a27720df7f9a62cce5d4ffc5ed4726710a17ea [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__
Alex Sakhartchouk43253872011-09-28 15:23:18 -070025#if (defined(RS_VERSION) && (RS_VERSION >= 14))
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070026/**
27 * Set the color target used for all subsequent rendering calls
28 * @param colorTarget
29 * @param slot
30 */
31extern void __attribute__((overloadable))
32 rsgBindColorTarget(rs_allocation colorTarget, uint slot);
33
34/**
35 * Clear the previously set color target
36 * @param slot
37 */
38extern void __attribute__((overloadable))
39 rsgClearColorTarget(uint slot);
40
41/**
42 * Set the depth target used for all subsequent rendering calls
43 * @param depthTarget
44 */
45extern void __attribute__((overloadable))
46 rsgBindDepthTarget(rs_allocation depthTarget);
47
48/**
49 * Clear the previously set depth target
50 */
51extern void __attribute__((overloadable))
52 rsgClearDepthTarget(void);
53
54/**
55 * Clear all color and depth targets and resume rendering into
56 * the framebuffer
57 */
58extern void __attribute__((overloadable))
59 rsgClearAllRenderTargets(void);
60
61/**
Alex Sakhartchouk9996b752011-08-09 11:36:19 -070062 * Force Renderscript to finish all rendering commands
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070063 */
64extern uint __attribute__((overloadable))
65 rsgFinish(void);
Jason Samsf2bcce72010-03-26 15:33:42 -070066
Alex Sakhartchouk43253872011-09-28 15:23:18 -070067#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
68
Jason Sams09aeb8a2011-01-28 15:49:07 -080069/**
70 * Bind a new ProgramFragment to the rendering context.
71 *
72 * @param pf
73 */
74extern void __attribute__((overloadable))
75 rsgBindProgramFragment(rs_program_fragment pf);
76
77/**
78 * Bind a new ProgramStore to the rendering context.
79 *
80 * @param ps
81 */
82extern void __attribute__((overloadable))
83 rsgBindProgramStore(rs_program_store ps);
84
85/**
86 * Bind a new ProgramVertex to the rendering context.
87 *
88 * @param pv
89 */
90extern void __attribute__((overloadable))
91 rsgBindProgramVertex(rs_program_vertex pv);
92
93/**
94 * Bind a new ProgramRaster to the rendering context.
95 *
96 * @param pr
97 */
98extern void __attribute__((overloadable))
99 rsgBindProgramRaster(rs_program_raster pr);
100
101/**
102 * Bind a new Sampler object to a ProgramFragment. The sampler will
103 * operate on the texture bound at the matching slot.
104 *
105 * @param slot
106 */
Jason Sams73495472010-07-29 17:31:14 -0700107extern void __attribute__((overloadable))
108 rsgBindSampler(rs_program_fragment, uint slot, rs_sampler);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800109
110/**
111 * Bind a new Allocation object to a ProgramFragment. The
112 * Allocation must be a valid texture for the Program. The sampling
113 * of the texture will be controled by the Sampler bound at the
114 * matching slot.
115 *
116 * @param slot
117 */
Jason Sams73495472010-07-29 17:31:14 -0700118extern void __attribute__((overloadable))
119 rsgBindTexture(rs_program_fragment, uint slot, rs_allocation);
Jason Sams51f36ab2010-03-18 14:36:05 -0700120
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700121/**
122 * Load the projection matrix for a currently bound fixed function
123 * vertex program. Calling this function with a custom vertex shader
124 * would result in an error.
125 * @param proj projection matrix
126 */
Jason Sams73495472010-07-29 17:31:14 -0700127extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700128 rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 *proj);
129/**
130 * Load the model 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 model model matrix
134 */
Jason Sams73495472010-07-29 17:31:14 -0700135extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700136 rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *model);
137/**
138 * Load the texture 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 tex texture matrix
142 */
Jason Sams73495472010-07-29 17:31:14 -0700143extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700144 rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *tex);
145/**
146 * Get the projection 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 proj matrix to store the current projection matrix into
150 */
Jason Sams6445e522010-08-04 17:50:20 -0700151extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700152 rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *proj);
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700153
Jason Sams09aeb8a2011-01-28 15:49:07 -0800154/**
155 * Set the constant color for a fixed function emulation program.
156 *
157 * @param pf
158 * @param r
159 * @param g
160 * @param b
161 * @param a
162 */
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700163extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800164 rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a);
Jason Sams6445e522010-08-04 17:50:20 -0700165
Jason Sams09aeb8a2011-01-28 15:49:07 -0800166/**
167 * Get the width of the current rendering surface.
168 *
169 * @return uint
170 */
Jason Sams73495472010-07-29 17:31:14 -0700171extern uint __attribute__((overloadable))
172 rsgGetWidth(void);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800173
174/**
175 * Get the height of the current rendering surface.
176 *
177 * @return uint
178 */
Jason Sams73495472010-07-29 17:31:14 -0700179extern uint __attribute__((overloadable))
180 rsgGetHeight(void);
Jason Sams51f36ab2010-03-18 14:36:05 -0700181
Jason Samsb7e83bd2010-12-15 01:41:00 -0800182
Jason Sams09aeb8a2011-01-28 15:49:07 -0800183/**
184 * Sync the contents of an allocation from its SCRIPT memory space to its HW
185 * memory spaces.
186 *
187 * @param alloc
188 */
189extern void __attribute__((overloadable))
190 rsgAllocationSyncAll(rs_allocation alloc);
191
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700192#if (defined(RS_VERSION) && (RS_VERSION >= 14))
193
Jason Sams09aeb8a2011-01-28 15:49:07 -0800194/**
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700195 * Sync the contents of an allocation from memory space
196 * specified by source.
197 *
198 * @param alloc
199 * @param source
200 */
201extern void __attribute__((overloadable))
202 rsgAllocationSyncAll(rs_allocation alloc,
203 rs_allocation_usage_type source);
204
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700205#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
206
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700207/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800208 * Low performance utility function for drawing a simple rectangle. Not
209 * intended for drawing large quantities of geometry.
210 *
211 * @param x1
212 * @param y1
213 * @param x2
214 * @param y2
215 * @param z
216 */
Jason Samsb7e83bd2010-12-15 01:41:00 -0800217extern void __attribute__((overloadable))
Jason Sams73495472010-07-29 17:31:14 -0700218 rsgDrawRect(float x1, float y1, float x2, float y2, float z);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800219
220/**
221 * Low performance utility function for drawing a simple quad. Not intended for
222 * drawing large quantities of geometry.
223 *
224 * @param x1
225 * @param y1
226 * @param z1
227 * @param x2
228 * @param y2
229 * @param z2
230 * @param x3
231 * @param y3
232 * @param z3
233 * @param x4
234 * @param y4
235 * @param z4
236 */
Jason Sams73495472010-07-29 17:31:14 -0700237extern void __attribute__((overloadable))
238 rsgDrawQuad(float x1, float y1, float z1,
239 float x2, float y2, float z2,
240 float x3, float y3, float z3,
241 float x4, float y4, float z4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800242
243
244/**
245 * Low performance utility function for drawing a textured quad. Not intended
246 * for drawing large quantities of geometry.
247 *
248 * @param x1
249 * @param y1
250 * @param z1
251 * @param u1
252 * @param v1
253 * @param x2
254 * @param y2
255 * @param z2
256 * @param u2
257 * @param v2
258 * @param x3
259 * @param y3
260 * @param z3
261 * @param u3
262 * @param v3
263 * @param x4
264 * @param y4
265 * @param z4
266 * @param u4
267 * @param v4
268 */
Jason Sams73495472010-07-29 17:31:14 -0700269extern void __attribute__((overloadable))
270 rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
271 float x2, float y2, float z2, float u2, float v2,
272 float x3, float y3, float z3, float u3, float v3,
273 float x4, float y4, float z4, float u4, float v4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800274
275
276/**
277 * Low performance function for drawing rectangles in screenspace. This
278 * function uses the default passthough ProgramVertex. Any bound ProgramVertex
279 * is ignored. This function has considerable overhead and should not be used
280 * for drawing in shipping applications.
281 *
282 * @param x
283 * @param y
284 * @param z
285 * @param w
286 * @param h
287 */
Jason Sams73495472010-07-29 17:31:14 -0700288extern void __attribute__((overloadable))
289 rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h);
Jason Sams51f36ab2010-03-18 14:36:05 -0700290
Jason Sams9e0afb52011-10-31 13:23:43 -0700291extern void __attribute__((overloadable))
292 rsgDrawPath(rs_path p);
293
Jason Sams09aeb8a2011-01-28 15:49:07 -0800294/**
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700295 * Draw a mesh using the current context state. The whole mesh is
Jason Sams09aeb8a2011-01-28 15:49:07 -0800296 * rendered.
297 *
298 * @param ism
299 */
Jason Sams73495472010-07-29 17:31:14 -0700300extern void __attribute__((overloadable))
301 rsgDrawMesh(rs_mesh ism);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700302/**
303 * Draw part of a mesh using the current context state.
304 * @param ism mesh object to render
305 * @param primitiveIndex for meshes that contain multiple primitive groups
306 * this parameter specifies the index of the group to draw.
307 */
Jason Sams73495472010-07-29 17:31:14 -0700308extern void __attribute__((overloadable))
309 rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700310/**
311 * Draw specified index range of part of a mesh using the current context state.
312 * @param ism mesh object to render
313 * @param primitiveIndex for meshes that contain multiple primitive groups
314 * this parameter specifies the index of the group to draw.
315 * @param start starting index in the range
316 * @param len number of indices to draw
317 */
Jason Sams73495472010-07-29 17:31:14 -0700318extern void __attribute__((overloadable))
319 rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len);
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -0700320
Jason Sams09aeb8a2011-01-28 15:49:07 -0800321/**
322 * Clears the rendering surface to the specified color.
323 *
324 * @param r
325 * @param g
326 * @param b
327 * @param a
328 */
Jason Sams73495472010-07-29 17:31:14 -0700329extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800330 rsgClearColor(float r, float g, float b, float a);
331
332/**
333 * Clears the depth suface to the specified value.
Jason Sams09aeb8a2011-01-28 15:49:07 -0800334 */
Jason Sams73495472010-07-29 17:31:14 -0700335extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800336 rsgClearDepth(float value);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700337/**
338 * Draws text given a string and location
339 */
Jason Sams73495472010-07-29 17:31:14 -0700340extern void __attribute__((overloadable))
341 rsgDrawText(const char *, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700342/**
343 * \overload
344 */
Jason Sams73495472010-07-29 17:31:14 -0700345extern void __attribute__((overloadable))
346 rsgDrawText(rs_allocation, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700347/**
348 * Binds the font object to be used for all subsequent font rendering calls
349 * @param font object to bind
350 */
Jason Sams73495472010-07-29 17:31:14 -0700351extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700352 rsgBindFont(rs_font font);
353/**
354 * Sets the font color for all subsequent rendering calls
355 * @param r red component
356 * @param g green component
357 * @param b blue component
358 * @param a alpha component
359 */
Alex Sakhartchouk9fc9f032010-08-04 14:45:48 -0700360extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700361 rsgFontColor(float r, float g, float b, float a);
362/**
363 * Returns the bounding box of the text relative to (0, 0)
364 * Any of left, right, top, bottom could be NULL
365 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700366extern void __attribute__((overloadable))
367 rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700368/**
369 * \overload
370 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700371extern void __attribute__((overloadable))
372 rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700373/**
374 * Computes an axis aligned bounding box of a mesh object
375 */
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700376extern void __attribute__((overloadable))
377 rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,
378 float *maxX, float *maxY, float *maxZ);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700379/**
380 * \overload
381 */
Jason Sams399dc9e2010-10-15 17:57:07 -0700382__inline__ static void __attribute__((overloadable, always_inline))
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700383rsgMeshComputeBoundingBox(rs_mesh mesh, float3 *bBoxMin, float3 *bBoxMax) {
384 float x1, y1, z1, x2, y2, z2;
385 rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2);
386 bBoxMin->x = x1;
387 bBoxMin->y = y1;
388 bBoxMin->z = z1;
389 bBoxMax->x = x2;
390 bBoxMax->y = y2;
391 bBoxMax->z = z2;
392}
393
Jason Sams1b937f52010-06-09 14:26:16 -0700394#endif
Jason Sams51f36ab2010-03-18 14:36:05 -0700395