Ying Wang | b335bb0 | 2011-11-29 10:23:55 -0800 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 23 | #ifndef __RS_GRAPHICS_RSH__ |
| 24 | #define __RS_GRAPHICS_RSH__ |
| 25 | |
| 26 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 27 | /** |
| 28 | * Set the color target used for all subsequent rendering calls |
| 29 | * @param colorTarget |
| 30 | * @param slot |
| 31 | */ |
| 32 | extern void __attribute__((overloadable)) |
| 33 | rsgBindColorTarget(rs_allocation colorTarget, uint slot); |
| 34 | |
| 35 | /** |
| 36 | * Clear the previously set color target |
| 37 | * @param slot |
| 38 | */ |
| 39 | extern void __attribute__((overloadable)) |
| 40 | rsgClearColorTarget(uint slot); |
| 41 | |
| 42 | /** |
| 43 | * Set the depth target used for all subsequent rendering calls |
| 44 | * @param depthTarget |
| 45 | */ |
| 46 | extern void __attribute__((overloadable)) |
| 47 | rsgBindDepthTarget(rs_allocation depthTarget); |
| 48 | |
| 49 | /** |
| 50 | * Clear the previously set depth target |
| 51 | */ |
| 52 | extern void __attribute__((overloadable)) |
| 53 | rsgClearDepthTarget(void); |
| 54 | |
| 55 | /** |
| 56 | * Clear all color and depth targets and resume rendering into |
| 57 | * the framebuffer |
| 58 | */ |
| 59 | extern void __attribute__((overloadable)) |
| 60 | rsgClearAllRenderTargets(void); |
| 61 | |
| 62 | /** |
| 63 | * Force Renderscript to finish all rendering commands |
| 64 | */ |
| 65 | extern uint __attribute__((overloadable)) |
| 66 | rsgFinish(void); |
| 67 | |
| 68 | #endif //defined(RS_VERSION) && (RS_VERSION >= 14) |
| 69 | |
| 70 | /** |
| 71 | * Bind a new ProgramFragment to the rendering context. |
| 72 | * |
| 73 | * @param pf |
| 74 | */ |
| 75 | extern 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 | */ |
| 83 | extern 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 | */ |
| 91 | extern 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 | */ |
| 99 | extern 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 | */ |
| 108 | extern void __attribute__((overloadable)) |
| 109 | rsgBindSampler(rs_program_fragment, uint slot, rs_sampler); |
| 110 | |
| 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 | */ |
| 119 | extern void __attribute__((overloadable)) |
| 120 | rsgBindTexture(rs_program_fragment, uint slot, rs_allocation); |
| 121 | |
| 122 | /** |
| 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 | */ |
| 128 | extern void __attribute__((overloadable)) |
| 129 | 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 | */ |
| 136 | extern void __attribute__((overloadable)) |
| 137 | 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 | */ |
| 144 | extern void __attribute__((overloadable)) |
| 145 | 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 | */ |
| 152 | extern void __attribute__((overloadable)) |
| 153 | rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *proj); |
| 154 | |
| 155 | /** |
| 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 | */ |
| 164 | extern void __attribute__((overloadable)) |
| 165 | rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a); |
| 166 | |
| 167 | /** |
| 168 | * Get the width of the current rendering surface. |
| 169 | * |
| 170 | * @return uint |
| 171 | */ |
| 172 | extern uint __attribute__((overloadable)) |
| 173 | rsgGetWidth(void); |
| 174 | |
| 175 | /** |
| 176 | * Get the height of the current rendering surface. |
| 177 | * |
| 178 | * @return uint |
| 179 | */ |
| 180 | extern uint __attribute__((overloadable)) |
| 181 | rsgGetHeight(void); |
| 182 | |
| 183 | |
| 184 | /** |
| 185 | * Sync the contents of an allocation from its SCRIPT memory space to its HW |
| 186 | * memory spaces. |
| 187 | * |
| 188 | * @param alloc |
| 189 | */ |
| 190 | extern void __attribute__((overloadable)) |
| 191 | rsgAllocationSyncAll(rs_allocation alloc); |
| 192 | |
| 193 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 194 | |
| 195 | /** |
| 196 | * Sync the contents of an allocation from memory space |
| 197 | * specified by source. |
| 198 | * |
| 199 | * @param alloc |
| 200 | * @param source |
| 201 | */ |
| 202 | extern void __attribute__((overloadable)) |
| 203 | rsgAllocationSyncAll(rs_allocation alloc, |
| 204 | rs_allocation_usage_type source); |
| 205 | |
| 206 | #endif //defined(RS_VERSION) && (RS_VERSION >= 14) |
| 207 | |
| 208 | /** |
| 209 | * Low performance utility function for drawing a simple rectangle. Not |
| 210 | * intended for drawing large quantities of geometry. |
| 211 | * |
| 212 | * @param x1 |
| 213 | * @param y1 |
| 214 | * @param x2 |
| 215 | * @param y2 |
| 216 | * @param z |
| 217 | */ |
| 218 | extern void __attribute__((overloadable)) |
| 219 | rsgDrawRect(float x1, float y1, float x2, float y2, float z); |
| 220 | |
| 221 | /** |
| 222 | * Low performance utility function for drawing a simple quad. Not intended for |
| 223 | * drawing large quantities of geometry. |
| 224 | * |
| 225 | * @param x1 |
| 226 | * @param y1 |
| 227 | * @param z1 |
| 228 | * @param x2 |
| 229 | * @param y2 |
| 230 | * @param z2 |
| 231 | * @param x3 |
| 232 | * @param y3 |
| 233 | * @param z3 |
| 234 | * @param x4 |
| 235 | * @param y4 |
| 236 | * @param z4 |
| 237 | */ |
| 238 | extern void __attribute__((overloadable)) |
| 239 | rsgDrawQuad(float x1, float y1, float z1, |
| 240 | float x2, float y2, float z2, |
| 241 | float x3, float y3, float z3, |
| 242 | float x4, float y4, float z4); |
| 243 | |
| 244 | |
| 245 | /** |
| 246 | * Low performance utility function for drawing a textured quad. Not intended |
| 247 | * for drawing large quantities of geometry. |
| 248 | * |
| 249 | * @param x1 |
| 250 | * @param y1 |
| 251 | * @param z1 |
| 252 | * @param u1 |
| 253 | * @param v1 |
| 254 | * @param x2 |
| 255 | * @param y2 |
| 256 | * @param z2 |
| 257 | * @param u2 |
| 258 | * @param v2 |
| 259 | * @param x3 |
| 260 | * @param y3 |
| 261 | * @param z3 |
| 262 | * @param u3 |
| 263 | * @param v3 |
| 264 | * @param x4 |
| 265 | * @param y4 |
| 266 | * @param z4 |
| 267 | * @param u4 |
| 268 | * @param v4 |
| 269 | */ |
| 270 | extern void __attribute__((overloadable)) |
| 271 | rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1, |
| 272 | float x2, float y2, float z2, float u2, float v2, |
| 273 | float x3, float y3, float z3, float u3, float v3, |
| 274 | float x4, float y4, float z4, float u4, float v4); |
| 275 | |
| 276 | |
| 277 | /** |
| 278 | * Low performance function for drawing rectangles in screenspace. This |
| 279 | * function uses the default passthough ProgramVertex. Any bound ProgramVertex |
| 280 | * is ignored. This function has considerable overhead and should not be used |
| 281 | * for drawing in shipping applications. |
| 282 | * |
| 283 | * @param x |
| 284 | * @param y |
| 285 | * @param z |
| 286 | * @param w |
| 287 | * @param h |
| 288 | */ |
| 289 | extern void __attribute__((overloadable)) |
| 290 | rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h); |
| 291 | |
| 292 | /** |
| 293 | * Draw a mesh using the current context state. The whole mesh is |
| 294 | * rendered. |
| 295 | * |
| 296 | * @param ism |
| 297 | */ |
| 298 | extern void __attribute__((overloadable)) |
| 299 | rsgDrawMesh(rs_mesh ism); |
| 300 | /** |
| 301 | * Draw part of a mesh using the current context state. |
| 302 | * @param ism mesh object to render |
| 303 | * @param primitiveIndex for meshes that contain multiple primitive groups |
| 304 | * this parameter specifies the index of the group to draw. |
| 305 | */ |
| 306 | extern void __attribute__((overloadable)) |
| 307 | rsgDrawMesh(rs_mesh ism, uint primitiveIndex); |
| 308 | /** |
| 309 | * Draw specified index range of part of a mesh using the current context state. |
| 310 | * @param ism mesh object to render |
| 311 | * @param primitiveIndex for meshes that contain multiple primitive groups |
| 312 | * this parameter specifies the index of the group to draw. |
| 313 | * @param start starting index in the range |
| 314 | * @param len number of indices to draw |
| 315 | */ |
| 316 | extern void __attribute__((overloadable)) |
| 317 | rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len); |
| 318 | |
| 319 | /** |
| 320 | * Clears the rendering surface to the specified color. |
| 321 | * |
| 322 | * @param r |
| 323 | * @param g |
| 324 | * @param b |
| 325 | * @param a |
| 326 | */ |
| 327 | extern void __attribute__((overloadable)) |
| 328 | rsgClearColor(float r, float g, float b, float a); |
| 329 | |
| 330 | /** |
| 331 | * Clears the depth suface to the specified value. |
| 332 | */ |
| 333 | extern void __attribute__((overloadable)) |
| 334 | rsgClearDepth(float value); |
| 335 | /** |
| 336 | * Draws text given a string and location |
| 337 | */ |
| 338 | extern void __attribute__((overloadable)) |
| 339 | rsgDrawText(const char *, int x, int y); |
| 340 | /** |
| 341 | * \overload |
| 342 | */ |
| 343 | extern void __attribute__((overloadable)) |
| 344 | rsgDrawText(rs_allocation, int x, int y); |
| 345 | /** |
| 346 | * Binds the font object to be used for all subsequent font rendering calls |
| 347 | * @param font object to bind |
| 348 | */ |
| 349 | extern void __attribute__((overloadable)) |
| 350 | rsgBindFont(rs_font font); |
| 351 | /** |
| 352 | * Sets the font color for all subsequent rendering calls |
| 353 | * @param r red component |
| 354 | * @param g green component |
| 355 | * @param b blue component |
| 356 | * @param a alpha component |
| 357 | */ |
| 358 | extern void __attribute__((overloadable)) |
| 359 | rsgFontColor(float r, float g, float b, float a); |
| 360 | /** |
| 361 | * Returns the bounding box of the text relative to (0, 0) |
| 362 | * Any of left, right, top, bottom could be NULL |
| 363 | */ |
| 364 | extern void __attribute__((overloadable)) |
| 365 | rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom); |
| 366 | /** |
| 367 | * \overload |
| 368 | */ |
| 369 | extern void __attribute__((overloadable)) |
| 370 | rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom); |
| 371 | /** |
| 372 | * Computes an axis aligned bounding box of a mesh object |
| 373 | */ |
| 374 | extern void __attribute__((overloadable)) |
| 375 | rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ, |
| 376 | float *maxX, float *maxY, float *maxZ); |
| 377 | /** |
| 378 | * \overload |
| 379 | */ |
| 380 | __inline__ static void __attribute__((overloadable, always_inline)) |
| 381 | rsgMeshComputeBoundingBox(rs_mesh mesh, float3 *bBoxMin, float3 *bBoxMax) { |
| 382 | float x1, y1, z1, x2, y2, z2; |
| 383 | rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2); |
| 384 | bBoxMin->x = x1; |
| 385 | bBoxMin->y = y1; |
| 386 | bBoxMin->z = z1; |
| 387 | bBoxMax->x = x2; |
| 388 | bBoxMax->y = y2; |
| 389 | bBoxMax->z = z2; |
| 390 | } |
| 391 | |
| 392 | #endif |
| 393 | |