Home | History | Annotate | Download | only in include
      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 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
     26 /**
     27  * Set the color target used for all subsequent rendering calls
     28  * @param colorTarget
     29  * @param slot
     30  */
     31 extern void __attribute__((overloadable))
     32     rsgBindColorTarget(rs_allocation colorTarget, uint slot);
     33 
     34 /**
     35  * Clear the previously set color target
     36  * @param slot
     37  */
     38 extern void __attribute__((overloadable))
     39     rsgClearColorTarget(uint slot);
     40 
     41 /**
     42  * Set the depth target used for all subsequent rendering calls
     43  * @param depthTarget
     44  */
     45 extern void __attribute__((overloadable))
     46     rsgBindDepthTarget(rs_allocation depthTarget);
     47 
     48 /**
     49  * Clear the previously set depth target
     50  */
     51 extern void __attribute__((overloadable))
     52     rsgClearDepthTarget(void);
     53 
     54 /**
     55  * Clear all color and depth targets and resume rendering into
     56  * the framebuffer
     57  */
     58 extern void __attribute__((overloadable))
     59     rsgClearAllRenderTargets(void);
     60 
     61 /**
     62  * Force Renderscript to finish all rendering commands
     63  */
     64 extern uint __attribute__((overloadable))
     65     rsgFinish(void);
     66 
     67 #endif //defined(RS_VERSION) && (RS_VERSION >= 14)
     68 
     69 /**
     70  * Bind a new ProgramFragment to the rendering context.
     71  *
     72  * @param pf
     73  */
     74 extern 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  */
     82 extern 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  */
     90 extern 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  */
     98 extern 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  */
    107 extern void __attribute__((overloadable))
    108     rsgBindSampler(rs_program_fragment, uint slot, rs_sampler);
    109 
    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  */
    118 extern void __attribute__((overloadable))
    119     rsgBindTexture(rs_program_fragment, uint slot, rs_allocation);
    120 
    121 /**
    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  */
    127 extern void __attribute__((overloadable))
    128     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  */
    135 extern void __attribute__((overloadable))
    136     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  */
    143 extern void __attribute__((overloadable))
    144     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  */
    151 extern void __attribute__((overloadable))
    152     rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *proj);
    153 
    154 /**
    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  */
    163 extern void __attribute__((overloadable))
    164     rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a);
    165 
    166 /**
    167  * Get the width of the current rendering surface.
    168  *
    169  * @return uint
    170  */
    171 extern uint __attribute__((overloadable))
    172     rsgGetWidth(void);
    173 
    174 /**
    175  * Get the height of the current rendering surface.
    176  *
    177  * @return uint
    178  */
    179 extern uint __attribute__((overloadable))
    180     rsgGetHeight(void);
    181 
    182 
    183 /**
    184  * Sync the contents of an allocation from its SCRIPT memory space to its HW
    185  * memory spaces.
    186  *
    187  * @param alloc
    188  */
    189 extern void __attribute__((overloadable))
    190     rsgAllocationSyncAll(rs_allocation alloc);
    191 
    192 #if (defined(RS_VERSION) && (RS_VERSION >= 14))
    193 
    194 /**
    195  * Sync the contents of an allocation from memory space
    196  * specified by source.
    197  *
    198  * @param alloc
    199  * @param source
    200  */
    201 extern void __attribute__((overloadable))
    202     rsgAllocationSyncAll(rs_allocation alloc,
    203                          rs_allocation_usage_type source);
    204 
    205 #endif //defined(RS_VERSION) && (RS_VERSION >= 14)
    206 
    207 /**
    208  * 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  */
    217 extern void __attribute__((overloadable))
    218     rsgDrawRect(float x1, float y1, float x2, float y2, float z);
    219 
    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  */
    237 extern 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);
    242 
    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  */
    269 extern 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);
    274 
    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  */
    288 extern void __attribute__((overloadable))
    289     rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h);
    290 
    291 /**
    292  * Draw a mesh using the current context state.  The whole mesh is
    293  * rendered.
    294  *
    295  * @param ism
    296  */
    297 extern void __attribute__((overloadable))
    298     rsgDrawMesh(rs_mesh ism);
    299 /**
    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  */
    305 extern void __attribute__((overloadable))
    306     rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
    307 /**
    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  */
    315 extern void __attribute__((overloadable))
    316     rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len);
    317 
    318 /**
    319  * Clears the rendering surface to the specified color.
    320  *
    321  * @param r
    322  * @param g
    323  * @param b
    324  * @param a
    325  */
    326 extern void __attribute__((overloadable))
    327     rsgClearColor(float r, float g, float b, float a);
    328 
    329 /**
    330  * Clears the depth suface to the specified value.
    331  */
    332 extern void __attribute__((overloadable))
    333     rsgClearDepth(float value);
    334 /**
    335  * Draws text given a string and location
    336  */
    337 extern void __attribute__((overloadable))
    338     rsgDrawText(const char *, int x, int y);
    339 /**
    340  * \overload
    341  */
    342 extern void __attribute__((overloadable))
    343     rsgDrawText(rs_allocation, int x, int y);
    344 /**
    345  * Binds the font object to be used for all subsequent font rendering calls
    346  * @param font object to bind
    347  */
    348 extern void __attribute__((overloadable))
    349     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  */
    357 extern void __attribute__((overloadable))
    358     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  */
    363 extern void __attribute__((overloadable))
    364     rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
    365 /**
    366  * \overload
    367  */
    368 extern void __attribute__((overloadable))
    369     rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom);
    370 /**
    371  * Computes an axis aligned bounding box of a mesh object
    372  */
    373 extern void __attribute__((overloadable))
    374     rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,
    375                                                 float *maxX, float *maxY, float *maxZ);
    376 /**
    377  * \overload
    378  */
    379 __inline__ static void __attribute__((overloadable, always_inline))
    380 rsgMeshComputeBoundingBox(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 
    391 #endif
    392 
    393