blob: 80491ee893a9473c9d5296667d8ff48d41f1da8a [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 Sakhartchouk5909d262011-11-17 15:59:13 -080025
Alex Sakhartchouk43253872011-09-28 15:23:18 -070026#if (defined(RS_VERSION) && (RS_VERSION >= 14))
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070027/**
28 * Set the color target used for all subsequent rendering calls
29 * @param colorTarget
30 * @param slot
31 */
32extern void __attribute__((overloadable))
33 rsgBindColorTarget(rs_allocation colorTarget, uint slot);
34
35/**
36 * Clear the previously set color target
37 * @param slot
38 */
39extern void __attribute__((overloadable))
40 rsgClearColorTarget(uint slot);
41
42/**
43 * Set the depth target used for all subsequent rendering calls
44 * @param depthTarget
45 */
46extern void __attribute__((overloadable))
47 rsgBindDepthTarget(rs_allocation depthTarget);
48
49/**
50 * Clear the previously set depth target
51 */
52extern void __attribute__((overloadable))
53 rsgClearDepthTarget(void);
54
55/**
56 * Clear all color and depth targets and resume rendering into
57 * the framebuffer
58 */
59extern void __attribute__((overloadable))
60 rsgClearAllRenderTargets(void);
61
62/**
Alex Sakhartchouk9996b752011-08-09 11:36:19 -070063 * Force Renderscript to finish all rendering commands
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070064 */
65extern uint __attribute__((overloadable))
66 rsgFinish(void);
Jason Samsf2bcce72010-03-26 15:33:42 -070067
Alex Sakhartchouk43253872011-09-28 15:23:18 -070068#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
69
Jason Sams09aeb8a2011-01-28 15:49:07 -080070/**
71 * Bind a new ProgramFragment to the rendering context.
72 *
73 * @param pf
74 */
75extern void __attribute__((overloadable))
76 rsgBindProgramFragment(rs_program_fragment pf);
77
78/**
79 * Bind a new ProgramStore to the rendering context.
80 *
81 * @param ps
82 */
83extern void __attribute__((overloadable))
84 rsgBindProgramStore(rs_program_store ps);
85
86/**
87 * Bind a new ProgramVertex to the rendering context.
88 *
89 * @param pv
90 */
91extern void __attribute__((overloadable))
92 rsgBindProgramVertex(rs_program_vertex pv);
93
94/**
95 * Bind a new ProgramRaster to the rendering context.
96 *
97 * @param pr
98 */
99extern void __attribute__((overloadable))
100 rsgBindProgramRaster(rs_program_raster pr);
101
102/**
103 * Bind a new Sampler object to a ProgramFragment. The sampler will
104 * operate on the texture bound at the matching slot.
105 *
106 * @param slot
107 */
Jason Sams73495472010-07-29 17:31:14 -0700108extern void __attribute__((overloadable))
109 rsgBindSampler(rs_program_fragment, uint slot, rs_sampler);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800110
111/**
112 * Bind a new Allocation object to a ProgramFragment. The
113 * Allocation must be a valid texture for the Program. The sampling
114 * of the texture will be controled by the Sampler bound at the
115 * matching slot.
116 *
117 * @param slot
118 */
Jason Sams73495472010-07-29 17:31:14 -0700119extern void __attribute__((overloadable))
120 rsgBindTexture(rs_program_fragment, uint slot, rs_allocation);
Jason Sams51f36ab2010-03-18 14:36:05 -0700121
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700122/**
123 * Load the projection matrix for a currently bound fixed function
124 * vertex program. Calling this function with a custom vertex shader
125 * would result in an error.
126 * @param proj projection matrix
127 */
Jason Sams73495472010-07-29 17:31:14 -0700128extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700129 rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 *proj);
130/**
131 * Load the model matrix for a currently bound fixed function
132 * vertex program. Calling this function with a custom vertex shader
133 * would result in an error.
134 * @param model model matrix
135 */
Jason Sams73495472010-07-29 17:31:14 -0700136extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700137 rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *model);
138/**
139 * Load the texture matrix for a currently bound fixed function
140 * vertex program. Calling this function with a custom vertex shader
141 * would result in an error.
142 * @param tex texture matrix
143 */
Jason Sams73495472010-07-29 17:31:14 -0700144extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700145 rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *tex);
146/**
147 * Get the projection matrix for a currently bound fixed function
148 * vertex program. Calling this function with a custom vertex shader
149 * would result in an error.
150 * @param proj matrix to store the current projection matrix into
151 */
Jason Sams6445e522010-08-04 17:50:20 -0700152extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700153 rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *proj);
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700154
Jason Sams09aeb8a2011-01-28 15:49:07 -0800155/**
156 * Set the constant color for a fixed function emulation program.
157 *
158 * @param pf
159 * @param r
160 * @param g
161 * @param b
162 * @param a
163 */
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700164extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800165 rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a);
Jason Sams6445e522010-08-04 17:50:20 -0700166
Jason Sams09aeb8a2011-01-28 15:49:07 -0800167/**
Alex Sakhartchouka720a142012-01-10 10:16:52 -0800168 * Bind a new Allocation object to a ProgramFragment. The
169 * Allocation must be a valid constant input for the Program.
170 *
171 * @param ps program object
172 * @param slot index of the constant buffer on the program
173 * @param c constants to bind
174 */
175extern void __attribute__((overloadable))
176 rsgBindConstant(rs_program_fragment ps, uint slot, rs_allocation c);
177
178/**
179 * Bind a new Allocation object to a ProgramVertex. The
180 * Allocation must be a valid constant input for the Program.
181 *
182 * @param pv program object
183 * @param slot index of the constant buffer on the program
184 * @param c constants to bind
185 */
186extern void __attribute__((overloadable))
187 rsgBindConstant(rs_program_vertex pv, uint slot, rs_allocation c);
188
189/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800190 * Get the width of the current rendering surface.
191 *
192 * @return uint
193 */
Jason Sams73495472010-07-29 17:31:14 -0700194extern uint __attribute__((overloadable))
195 rsgGetWidth(void);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800196
197/**
198 * Get the height of the current rendering surface.
199 *
200 * @return uint
201 */
Jason Sams73495472010-07-29 17:31:14 -0700202extern uint __attribute__((overloadable))
203 rsgGetHeight(void);
Jason Sams51f36ab2010-03-18 14:36:05 -0700204
Jason Samsb7e83bd2010-12-15 01:41:00 -0800205
Jason Sams09aeb8a2011-01-28 15:49:07 -0800206/**
207 * Sync the contents of an allocation from its SCRIPT memory space to its HW
208 * memory spaces.
209 *
210 * @param alloc
211 */
212extern void __attribute__((overloadable))
213 rsgAllocationSyncAll(rs_allocation alloc);
214
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700215#if (defined(RS_VERSION) && (RS_VERSION >= 14))
216
Jason Sams09aeb8a2011-01-28 15:49:07 -0800217/**
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700218 * Sync the contents of an allocation from memory space
219 * specified by source.
220 *
221 * @param alloc
222 * @param source
223 */
224extern void __attribute__((overloadable))
225 rsgAllocationSyncAll(rs_allocation alloc,
226 rs_allocation_usage_type source);
227
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700228#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
229
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700230/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800231 * Low performance utility function for drawing a simple rectangle. Not
232 * intended for drawing large quantities of geometry.
233 *
234 * @param x1
235 * @param y1
236 * @param x2
237 * @param y2
238 * @param z
239 */
Jason Samsb7e83bd2010-12-15 01:41:00 -0800240extern void __attribute__((overloadable))
Jason Sams73495472010-07-29 17:31:14 -0700241 rsgDrawRect(float x1, float y1, float x2, float y2, float z);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800242
243/**
244 * Low performance utility function for drawing a simple quad. Not intended for
245 * drawing large quantities of geometry.
246 *
247 * @param x1
248 * @param y1
249 * @param z1
250 * @param x2
251 * @param y2
252 * @param z2
253 * @param x3
254 * @param y3
255 * @param z3
256 * @param x4
257 * @param y4
258 * @param z4
259 */
Jason Sams73495472010-07-29 17:31:14 -0700260extern void __attribute__((overloadable))
261 rsgDrawQuad(float x1, float y1, float z1,
262 float x2, float y2, float z2,
263 float x3, float y3, float z3,
264 float x4, float y4, float z4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800265
266
267/**
268 * Low performance utility function for drawing a textured quad. Not intended
269 * for drawing large quantities of geometry.
270 *
271 * @param x1
272 * @param y1
273 * @param z1
274 * @param u1
275 * @param v1
276 * @param x2
277 * @param y2
278 * @param z2
279 * @param u2
280 * @param v2
281 * @param x3
282 * @param y3
283 * @param z3
284 * @param u3
285 * @param v3
286 * @param x4
287 * @param y4
288 * @param z4
289 * @param u4
290 * @param v4
291 */
Jason Sams73495472010-07-29 17:31:14 -0700292extern void __attribute__((overloadable))
293 rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
294 float x2, float y2, float z2, float u2, float v2,
295 float x3, float y3, float z3, float u3, float v3,
296 float x4, float y4, float z4, float u4, float v4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800297
298
299/**
300 * Low performance function for drawing rectangles in screenspace. This
301 * function uses the default passthough ProgramVertex. Any bound ProgramVertex
302 * is ignored. This function has considerable overhead and should not be used
303 * for drawing in shipping applications.
304 *
305 * @param x
306 * @param y
307 * @param z
308 * @param w
309 * @param h
310 */
Jason Sams73495472010-07-29 17:31:14 -0700311extern void __attribute__((overloadable))
312 rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h);
Jason Sams51f36ab2010-03-18 14:36:05 -0700313
Jason Sams9e0afb52011-10-31 13:23:43 -0700314extern void __attribute__((overloadable))
315 rsgDrawPath(rs_path p);
316
Jason Sams09aeb8a2011-01-28 15:49:07 -0800317/**
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700318 * Draw a mesh using the current context state. The whole mesh is
Jason Sams09aeb8a2011-01-28 15:49:07 -0800319 * rendered.
320 *
321 * @param ism
322 */
Jason Sams73495472010-07-29 17:31:14 -0700323extern void __attribute__((overloadable))
324 rsgDrawMesh(rs_mesh ism);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700325/**
326 * Draw part of a mesh using the current context state.
327 * @param ism mesh object to render
328 * @param primitiveIndex for meshes that contain multiple primitive groups
329 * this parameter specifies the index of the group to draw.
330 */
Jason Sams73495472010-07-29 17:31:14 -0700331extern void __attribute__((overloadable))
332 rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700333/**
334 * Draw specified index range of part of a mesh using the current context state.
335 * @param ism mesh object to render
336 * @param primitiveIndex for meshes that contain multiple primitive groups
337 * this parameter specifies the index of the group to draw.
338 * @param start starting index in the range
339 * @param len number of indices to draw
340 */
Jason Sams73495472010-07-29 17:31:14 -0700341extern void __attribute__((overloadable))
342 rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len);
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -0700343
Jason Sams09aeb8a2011-01-28 15:49:07 -0800344/**
345 * Clears the rendering surface to the specified color.
346 *
347 * @param r
348 * @param g
349 * @param b
350 * @param a
351 */
Jason Sams73495472010-07-29 17:31:14 -0700352extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800353 rsgClearColor(float r, float g, float b, float a);
354
355/**
356 * Clears the depth suface to the specified value.
Jason Sams09aeb8a2011-01-28 15:49:07 -0800357 */
Jason Sams73495472010-07-29 17:31:14 -0700358extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800359 rsgClearDepth(float value);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700360/**
361 * Draws text given a string and location
362 */
Jason Sams73495472010-07-29 17:31:14 -0700363extern void __attribute__((overloadable))
364 rsgDrawText(const char *, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700365/**
366 * \overload
367 */
Jason Sams73495472010-07-29 17:31:14 -0700368extern void __attribute__((overloadable))
369 rsgDrawText(rs_allocation, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700370/**
371 * Binds the font object to be used for all subsequent font rendering calls
372 * @param font object to bind
373 */
Jason Sams73495472010-07-29 17:31:14 -0700374extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700375 rsgBindFont(rs_font font);
376/**
377 * Sets the font color for all subsequent rendering calls
378 * @param r red component
379 * @param g green component
380 * @param b blue component
381 * @param a alpha component
382 */
Alex Sakhartchouk9fc9f032010-08-04 14:45:48 -0700383extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700384 rsgFontColor(float r, float g, float b, float a);
385/**
386 * Returns the bounding box of the text relative to (0, 0)
387 * Any of left, right, top, bottom could be NULL
388 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700389extern void __attribute__((overloadable))
390 rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700391/**
392 * \overload
393 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700394extern void __attribute__((overloadable))
395 rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700396/**
397 * Computes an axis aligned bounding box of a mesh object
398 */
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700399extern void __attribute__((overloadable))
400 rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,
401 float *maxX, float *maxY, float *maxZ);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700402/**
403 * \overload
404 */
Jason Sams399dc9e2010-10-15 17:57:07 -0700405__inline__ static void __attribute__((overloadable, always_inline))
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700406rsgMeshComputeBoundingBox(rs_mesh mesh, float3 *bBoxMin, float3 *bBoxMax) {
407 float x1, y1, z1, x2, y2, z2;
408 rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2);
409 bBoxMin->x = x1;
410 bBoxMin->y = y1;
411 bBoxMin->z = z1;
412 bBoxMax->x = x2;
413 bBoxMax->y = y2;
414 bBoxMax->z = z2;
415}
416
Jason Sams1b937f52010-06-09 14:26:16 -0700417#endif
Jason Sams51f36ab2010-03-18 14:36:05 -0700418