blob: 25819537e26bd0a3646ec9311411d5a4da77f924 [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 Sams09aeb8a2011-01-28 15:49:07 -0800291/**
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700292 * Draw a mesh using the current context state. The whole mesh is
Jason Sams09aeb8a2011-01-28 15:49:07 -0800293 * rendered.
294 *
295 * @param ism
296 */
Jason Sams73495472010-07-29 17:31:14 -0700297extern void __attribute__((overloadable))
298 rsgDrawMesh(rs_mesh ism);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700299/**
300 * Draw part of a mesh using the current context state.
301 * @param ism mesh object to render
302 * @param primitiveIndex for meshes that contain multiple primitive groups
303 * this parameter specifies the index of the group to draw.
304 */
Jason Sams73495472010-07-29 17:31:14 -0700305extern void __attribute__((overloadable))
306 rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700307/**
308 * Draw specified index range of part of a mesh using the current context state.
309 * @param ism mesh object to render
310 * @param primitiveIndex for meshes that contain multiple primitive groups
311 * this parameter specifies the index of the group to draw.
312 * @param start starting index in the range
313 * @param len number of indices to draw
314 */
Jason Sams73495472010-07-29 17:31:14 -0700315extern void __attribute__((overloadable))
316 rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len);
Alex Sakhartchouk4e9a7a82010-07-01 16:14:06 -0700317
Jason Sams09aeb8a2011-01-28 15:49:07 -0800318/**
319 * Clears the rendering surface to the specified color.
320 *
321 * @param r
322 * @param g
323 * @param b
324 * @param a
325 */
Jason Sams73495472010-07-29 17:31:14 -0700326extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800327 rsgClearColor(float r, float g, float b, float a);
328
329/**
330 * Clears the depth suface to the specified value.
Jason Sams09aeb8a2011-01-28 15:49:07 -0800331 */
Jason Sams73495472010-07-29 17:31:14 -0700332extern void __attribute__((overloadable))
Jason Sams09aeb8a2011-01-28 15:49:07 -0800333 rsgClearDepth(float value);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700334/**
335 * Draws text given a string and location
336 */
Jason Sams73495472010-07-29 17:31:14 -0700337extern void __attribute__((overloadable))
338 rsgDrawText(const char *, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700339/**
340 * \overload
341 */
Jason Sams73495472010-07-29 17:31:14 -0700342extern void __attribute__((overloadable))
343 rsgDrawText(rs_allocation, int x, int y);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700344/**
345 * Binds the font object to be used for all subsequent font rendering calls
346 * @param font object to bind
347 */
Jason Sams73495472010-07-29 17:31:14 -0700348extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700349 rsgBindFont(rs_font font);
350/**
351 * Sets the font color for all subsequent rendering calls
352 * @param r red component
353 * @param g green component
354 * @param b blue component
355 * @param a alpha component
356 */
Alex Sakhartchouk9fc9f032010-08-04 14:45:48 -0700357extern void __attribute__((overloadable))
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700358 rsgFontColor(float r, float g, float b, float a);
359/**
360 * Returns the bounding box of the text relative to (0, 0)
361 * Any of left, right, top, bottom could be NULL
362 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700363extern void __attribute__((overloadable))
364 rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700365/**
366 * \overload
367 */
Alex Sakhartchouk09c67352010-10-05 11:33:27 -0700368extern void __attribute__((overloadable))
369 rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700370/**
371 * Computes an axis aligned bounding box of a mesh object
372 */
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700373extern void __attribute__((overloadable))
374 rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,
375 float *maxX, float *maxY, float *maxZ);
Alex Sakhartchouk9996b752011-08-09 11:36:19 -0700376/**
377 * \overload
378 */
Jason Sams399dc9e2010-10-15 17:57:07 -0700379__inline__ static void __attribute__((overloadable, always_inline))
Alex Sakhartchoukba4aa5c2010-08-13 14:32:23 -0700380rsgMeshComputeBoundingBox(rs_mesh mesh, float3 *bBoxMin, float3 *bBoxMax) {
381 float x1, y1, z1, x2, y2, z2;
382 rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2);
383 bBoxMin->x = x1;
384 bBoxMin->y = y1;
385 bBoxMin->z = z1;
386 bBoxMax->x = x2;
387 bBoxMax->y = y2;
388 bBoxMax->z = z2;
389}
390
Jason Sams1b937f52010-06-09 14:26:16 -0700391#endif
Jason Sams51f36ab2010-03-18 14:36:05 -0700392