1/* 2 * Copyright (C) 2011-2012 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#include "rs_mesh.rsh" 27#include "rs_program.rsh" 28 29#if (defined(RS_VERSION) && (RS_VERSION >= 14)) 30/** 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/** 66 * Force RenderScript to finish all rendering commands 67 */ 68extern uint __attribute__((overloadable)) 69 rsgFinish(void); 70 71#endif //defined(RS_VERSION) && (RS_VERSION >= 14) 72 73/** 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 */ 111extern void __attribute__((overloadable)) 112 rsgBindSampler(rs_program_fragment, uint slot, rs_sampler); 113 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 */ 122extern void __attribute__((overloadable)) 123 rsgBindTexture(rs_program_fragment, uint slot, rs_allocation); 124 125/** 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 */ 131extern void __attribute__((overloadable)) 132 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 */ 139extern void __attribute__((overloadable)) 140 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 */ 147extern void __attribute__((overloadable)) 148 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 */ 155extern void __attribute__((overloadable)) 156 rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *proj); 157 158/** 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 */ 167extern void __attribute__((overloadable)) 168 rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a); 169 170/** 171 * 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/** 193 * Get the width of the current rendering surface. 194 * 195 * @return uint 196 */ 197extern uint __attribute__((overloadable)) 198 rsgGetWidth(void); 199 200/** 201 * Get the height of the current rendering surface. 202 * 203 * @return uint 204 */ 205extern uint __attribute__((overloadable)) 206 rsgGetHeight(void); 207 208 209/** 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 218#if (defined(RS_VERSION) && (RS_VERSION >= 14)) 219 220/** 221 * 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 231#endif //defined(RS_VERSION) && (RS_VERSION >= 14) 232 233/** 234 * 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 */ 243extern void __attribute__((overloadable)) 244 rsgDrawRect(float x1, float y1, float x2, float y2, float z); 245 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 */ 263extern 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); 268 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 */ 295extern 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); 300 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 */ 314extern void __attribute__((overloadable)) 315 rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h); 316 317extern void __attribute__((overloadable)) 318 rsgDrawPath(rs_path p); 319 320/** 321 * Draw a mesh using the current context state. The whole mesh is 322 * rendered. 323 * 324 * @param ism 325 */ 326extern void __attribute__((overloadable)) 327 rsgDrawMesh(rs_mesh ism); 328/** 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 */ 334extern void __attribute__((overloadable)) 335 rsgDrawMesh(rs_mesh ism, uint primitiveIndex); 336/** 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 */ 344extern void __attribute__((overloadable)) 345 rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len); 346 347/** 348 * Clears the rendering surface to the specified color. 349 * 350 * @param r 351 * @param g 352 * @param b 353 * @param a 354 */ 355extern void __attribute__((overloadable)) 356 rsgClearColor(float r, float g, float b, float a); 357 358/** 359 * Clears the depth suface to the specified value. 360 */ 361extern void __attribute__((overloadable)) 362 rsgClearDepth(float value); 363/** 364 * Draws text given a string and location 365 */ 366extern void __attribute__((overloadable)) 367 rsgDrawText(const char *, int x, int y); 368/** 369 * \overload 370 */ 371extern void __attribute__((overloadable)) 372 rsgDrawText(rs_allocation, int x, int y); 373/** 374 * Binds the font object to be used for all subsequent font rendering calls 375 * @param font object to bind 376 */ 377extern void __attribute__((overloadable)) 378 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 */ 386extern void __attribute__((overloadable)) 387 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 */ 392extern void __attribute__((overloadable)) 393 rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom); 394/** 395 * \overload 396 */ 397extern void __attribute__((overloadable)) 398 rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom); 399/** 400 * Computes an axis aligned bounding box of a mesh object 401 */ 402extern void __attribute__((overloadable)) 403 rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ, 404 float *maxX, float *maxY, float *maxZ); 405/** 406 * \overload 407 */ 408__inline__ static void __attribute__((overloadable, always_inline)) 409rsgMeshComputeBoundingBox(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 420#endif 421 422