blob: 782b27f1cde675222414eee0156f903e07e65ef6 [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
Alex Sakhartchoukf8e195e2012-03-22 10:50:55 -070026#include "rs_mesh.rsh"
27#include "rs_program.rsh"
28
Alex Sakhartchouk43253872011-09-28 15:23:18 -070029#if (defined(RS_VERSION) && (RS_VERSION >= 14))
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070030/**
31 * Set the color target used for all subsequent rendering calls
32 * @param colorTarget
33 * @param slot
34 */
35extern void __attribute__((overloadable))
36 rsgBindColorTarget(rs_allocation colorTarget, uint slot);
37
38/**
39 * Clear the previously set color target
40 * @param slot
41 */
42extern void __attribute__((overloadable))
43 rsgClearColorTarget(uint slot);
44
45/**
46 * Set the depth target used for all subsequent rendering calls
47 * @param depthTarget
48 */
49extern void __attribute__((overloadable))
50 rsgBindDepthTarget(rs_allocation depthTarget);
51
52/**
53 * Clear the previously set depth target
54 */
55extern void __attribute__((overloadable))
56 rsgClearDepthTarget(void);
57
58/**
59 * Clear all color and depth targets and resume rendering into
60 * the framebuffer
61 */
62extern void __attribute__((overloadable))
63 rsgClearAllRenderTargets(void);
64
65/**
Stephen Hinese227f9a2013-05-29 14:48:19 -070066 * Force RenderScript to finish all rendering commands
Alex Sakhartchouk7d9c5ff2011-04-01 14:19:01 -070067 */
68extern uint __attribute__((overloadable))
69 rsgFinish(void);
Jason Samsf2bcce72010-03-26 15:33:42 -070070
Alex Sakhartchouk43253872011-09-28 15:23:18 -070071#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
72
Jason Sams09aeb8a2011-01-28 15:49:07 -080073/**
74 * Bind a new ProgramFragment to the rendering context.
75 *
76 * @param pf
77 */
78extern void __attribute__((overloadable))
79 rsgBindProgramFragment(rs_program_fragment pf);
80
81/**
82 * Bind a new ProgramStore to the rendering context.
83 *
84 * @param ps
85 */
86extern void __attribute__((overloadable))
87 rsgBindProgramStore(rs_program_store ps);
88
89/**
90 * Bind a new ProgramVertex to the rendering context.
91 *
92 * @param pv
93 */
94extern void __attribute__((overloadable))
95 rsgBindProgramVertex(rs_program_vertex pv);
96
97/**
98 * Bind a new ProgramRaster to the rendering context.
99 *
100 * @param pr
101 */
102extern void __attribute__((overloadable))
103 rsgBindProgramRaster(rs_program_raster pr);
104
105/**
106 * Bind a new Sampler object to a ProgramFragment. The sampler will
107 * operate on the texture bound at the matching slot.
108 *
109 * @param slot
110 */
Jason Sams73495472010-07-29 17:31:14 -0700111extern void __attribute__((overloadable))
112 rsgBindSampler(rs_program_fragment, uint slot, rs_sampler);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800113
114/**
115 * Bind a new Allocation object to a ProgramFragment. The
116 * Allocation must be a valid texture for the Program. The sampling
117 * of the texture will be controled by the Sampler bound at the
118 * matching slot.
119 *
120 * @param slot
121 */
Jason Sams73495472010-07-29 17:31:14 -0700122extern void __attribute__((overloadable))
123 rsgBindTexture(rs_program_fragment, uint slot, rs_allocation);
Jason Sams51f36ab2010-03-18 14:36:05 -0700124
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700125/**
126 * Load the projection matrix for a currently bound fixed function
127 * vertex program. Calling this function with a custom vertex shader
128 * would result in an error.
129 * @param proj projection matrix
130 */
Jason Sams73495472010-07-29 17:31:14 -0700131extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700132 rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 *proj);
133/**
134 * Load the model matrix for a currently bound fixed function
135 * vertex program. Calling this function with a custom vertex shader
136 * would result in an error.
137 * @param model model matrix
138 */
Jason Sams73495472010-07-29 17:31:14 -0700139extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700140 rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *model);
141/**
142 * Load the texture matrix for a currently bound fixed function
143 * vertex program. Calling this function with a custom vertex shader
144 * would result in an error.
145 * @param tex texture matrix
146 */
Jason Sams73495472010-07-29 17:31:14 -0700147extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700148 rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *tex);
149/**
150 * Get the projection matrix for a currently bound fixed function
151 * vertex program. Calling this function with a custom vertex shader
152 * would result in an error.
153 * @param proj matrix to store the current projection matrix into
154 */
Jason Sams6445e522010-08-04 17:50:20 -0700155extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700156 rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *proj);
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700157
Jason Sams09aeb8a2011-01-28 15:49:07 -0800158/**
159 * Set the constant color for a fixed function emulation program.
160 *
161 * @param pf
162 * @param r
163 * @param g
164 * @param b
165 * @param a
166 */
Alex Sakhartchouk95333f92010-08-16 17:40:10 -0700167extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800168 rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a);
Jason Sams6445e522010-08-04 17:50:20 -0700169
Jason Sams09aeb8a2011-01-28 15:49:07 -0800170/**
Alex Sakhartchouka720a142012-01-10 10:16:52 -0800171 * Bind a new Allocation object to a ProgramFragment. The
172 * Allocation must be a valid constant input for the Program.
173 *
174 * @param ps program object
175 * @param slot index of the constant buffer on the program
176 * @param c constants to bind
177 */
178extern void __attribute__((overloadable))
179 rsgBindConstant(rs_program_fragment ps, uint slot, rs_allocation c);
180
181/**
182 * Bind a new Allocation object to a ProgramVertex. The
183 * Allocation must be a valid constant input for the Program.
184 *
185 * @param pv program object
186 * @param slot index of the constant buffer on the program
187 * @param c constants to bind
188 */
189extern void __attribute__((overloadable))
190 rsgBindConstant(rs_program_vertex pv, uint slot, rs_allocation c);
191
192/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800193 * Get the width of the current rendering surface.
194 *
195 * @return uint
196 */
Jason Sams73495472010-07-29 17:31:14 -0700197extern uint __attribute__((overloadable))
198 rsgGetWidth(void);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800199
200/**
201 * Get the height of the current rendering surface.
202 *
203 * @return uint
204 */
Jason Sams73495472010-07-29 17:31:14 -0700205extern uint __attribute__((overloadable))
206 rsgGetHeight(void);
Jason Sams51f36ab2010-03-18 14:36:05 -0700207
Jason Samsb7e83bd2010-12-15 01:41:00 -0800208
Jason Sams09aeb8a2011-01-28 15:49:07 -0800209/**
210 * Sync the contents of an allocation from its SCRIPT memory space to its HW
211 * memory spaces.
212 *
213 * @param alloc
214 */
215extern void __attribute__((overloadable))
216 rsgAllocationSyncAll(rs_allocation alloc);
217
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700218#if (defined(RS_VERSION) && (RS_VERSION >= 14))
219
Jason Sams09aeb8a2011-01-28 15:49:07 -0800220/**
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700221 * Sync the contents of an allocation from memory space
222 * specified by source.
223 *
224 * @param alloc
225 * @param source
226 */
227extern void __attribute__((overloadable))
228 rsgAllocationSyncAll(rs_allocation alloc,
229 rs_allocation_usage_type source);
230
Alex Sakhartchouk43253872011-09-28 15:23:18 -0700231#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
232
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700233/**
Jason Sams09aeb8a2011-01-28 15:49:07 -0800234 * Low performance utility function for drawing a simple rectangle. Not
235 * intended for drawing large quantities of geometry.
236 *
237 * @param x1
238 * @param y1
239 * @param x2
240 * @param y2
241 * @param z
242 */
Jason Samsb7e83bd2010-12-15 01:41:00 -0800243extern void __attribute__((overloadable))
Jason Sams73495472010-07-29 17:31:14 -0700244 rsgDrawRect(float x1, float y1, float x2, float y2, float z);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800245
246/**
247 * Low performance utility function for drawing a simple quad. Not intended for
248 * drawing large quantities of geometry.
249 *
250 * @param x1
251 * @param y1
252 * @param z1
253 * @param x2
254 * @param y2
255 * @param z2
256 * @param x3
257 * @param y3
258 * @param z3
259 * @param x4
260 * @param y4
261 * @param z4
262 */
Jason Sams73495472010-07-29 17:31:14 -0700263extern void __attribute__((overloadable))
264 rsgDrawQuad(float x1, float y1, float z1,
265 float x2, float y2, float z2,
266 float x3, float y3, float z3,
267 float x4, float y4, float z4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800268
269
270/**
271 * Low performance utility function for drawing a textured quad. Not intended
272 * for drawing large quantities of geometry.
273 *
274 * @param x1
275 * @param y1
276 * @param z1
277 * @param u1
278 * @param v1
279 * @param x2
280 * @param y2
281 * @param z2
282 * @param u2
283 * @param v2
284 * @param x3
285 * @param y3
286 * @param z3
287 * @param u3
288 * @param v3
289 * @param x4
290 * @param y4
291 * @param z4
292 * @param u4
293 * @param v4
294 */
Jason Sams73495472010-07-29 17:31:14 -0700295extern void __attribute__((overloadable))
296 rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
297 float x2, float y2, float z2, float u2, float v2,
298 float x3, float y3, float z3, float u3, float v3,
299 float x4, float y4, float z4, float u4, float v4);
Jason Sams09aeb8a2011-01-28 15:49:07 -0800300
301
302/**
303 * Low performance function for drawing rectangles in screenspace. This
304 * function uses the default passthough ProgramVertex. Any bound ProgramVertex
305 * is ignored. This function has considerable overhead and should not be used
306 * for drawing in shipping applications.
307 *
308 * @param x
309 * @param y
310 * @param z
311 * @param w
312 * @param h
313 */
Jason Sams73495472010-07-29 17:31:14 -0700314extern void __attribute__((overloadable))
315 rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h);
Jason Sams51f36ab2010-03-18 14:36:05 -0700316
Jason Sams9e0afb52011-10-31 13:23:43 -0700317extern void __attribute__((overloadable))
318 rsgDrawPath(rs_path p);
319
Jason Sams09aeb8a2011-01-28 15:49:07 -0800320/**
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700321 * Draw a mesh using the current context state. The whole mesh is
Jason Sams09aeb8a2011-01-28 15:49:07 -0800322 * rendered.
323 *
324 * @param ism
325 */
Jason Sams73495472010-07-29 17:31:14 -0700326extern void __attribute__((overloadable))
327 rsgDrawMesh(rs_mesh ism);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700328/**
329 * Draw part of a mesh using the current context state.
330 * @param ism mesh object to render
331 * @param primitiveIndex for meshes that contain multiple primitive groups
332 * this parameter specifies the index of the group to draw.
333 */
Jason Sams73495472010-07-29 17:31:14 -0700334extern void __attribute__((overloadable))
335 rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700336/**
337 * Draw specified index range of part of a mesh using the current context state.
338 * @param ism mesh object to render
339 * @param primitiveIndex for meshes that contain multiple primitive groups
340 * this parameter specifies the index of the group to draw.
341 * @param start starting index in the range
342 * @param len number of indices to draw
343 */
Jason Sams73495472010-07-29 17:31:14 -0700344extern void __attribute__((overloadable))
345 rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len);
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -0700346
Jason Sams09aeb8a2011-01-28 15:49:07 -0800347/**
348 * Clears the rendering surface to the specified color.
349 *
350 * @param r
351 * @param g
352 * @param b
353 * @param a
354 */
Jason Sams73495472010-07-29 17:31:14 -0700355extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800356 rsgClearColor(float r, float g, float b, float a);
357
358/**
359 * Clears the depth suface to the specified value.
Jason Sams09aeb8a2011-01-28 15:49:07 -0800360 */
Jason Sams73495472010-07-29 17:31:14 -0700361extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800362 rsgClearDepth(float value);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700363/**
364 * Draws text given a string and location
365 */
Jason Sams73495472010-07-29 17:31:14 -0700366extern void __attribute__((overloadable))
367 rsgDrawText(const char *, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700368/**
369 * \overload
370 */
Jason Sams73495472010-07-29 17:31:14 -0700371extern void __attribute__((overloadable))
372 rsgDrawText(rs_allocation, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700373/**
374 * Binds the font object to be used for all subsequent font rendering calls
375 * @param font object to bind
376 */
Jason Sams73495472010-07-29 17:31:14 -0700377extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700378 rsgBindFont(rs_font font);
379/**
380 * Sets the font color for all subsequent rendering calls
381 * @param r red component
382 * @param g green component
383 * @param b blue component
384 * @param a alpha component
385 */
Alex Sakhartchouk9fc9f032010-08-04 14:45:48 -0700386extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700387 rsgFontColor(float r, float g, float b, float a);
388/**
389 * Returns the bounding box of the text relative to (0, 0)
390 * Any of left, right, top, bottom could be NULL
391 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700392extern void __attribute__((overloadable))
393 rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700394/**
395 * \overload
396 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700397extern void __attribute__((overloadable))
398 rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700399/**
400 * Computes an axis aligned bounding box of a mesh object
401 */
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700402extern void __attribute__((overloadable))
403 rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,
404 float *maxX, float *maxY, float *maxZ);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700405/**
406 * \overload
407 */
Jason Sams399dc9e2010-10-15 17:57:07 -0700408__inline__ static void __attribute__((overloadable, always_inline))
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700409rsgMeshComputeBoundingBox(rs_mesh mesh, float3 *bBoxMin, float3 *bBoxMax) {
410 float x1, y1, z1, x2, y2, z2;
411 rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2);
412 bBoxMin->x = x1;
413 bBoxMin->y = y1;
414 bBoxMin->z = z1;
415 bBoxMax->x = x2;
416 bBoxMax->y = y2;
417 bBoxMax->z = z2;
418}
419
Jason Sams1b937f52010-06-09 14:26:16 -0700420#endif
Jason Sams51f36ab2010-03-18 14:36:05 -0700421