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 
     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 /**
     68  * Bind a new ProgramFragment to the rendering context.
     69  *
     70  * @param pf
     71  */
     72 extern void __attribute__((overloadable))
     73     rsgBindProgramFragment(rs_program_fragment pf);
     74 
     75 /**
     76  * Bind a new ProgramStore to the rendering context.
     77  *
     78  * @param ps
     79  */
     80 extern void __attribute__((overloadable))
     81     rsgBindProgramStore(rs_program_store ps);
     82 
     83 /**
     84  * Bind a new ProgramVertex to the rendering context.
     85  *
     86  * @param pv
     87  */
     88 extern void __attribute__((overloadable))
     89     rsgBindProgramVertex(rs_program_vertex pv);
     90 
     91 /**
     92  * Bind a new ProgramRaster to the rendering context.
     93  *
     94  * @param pr
     95  */
     96 extern void __attribute__((overloadable))
     97     rsgBindProgramRaster(rs_program_raster pr);
     98 
     99 /**
    100  * Bind a new Sampler object to a ProgramFragment.  The sampler will
    101  * operate on the texture bound at the matching slot.
    102  *
    103  * @param slot
    104  */
    105 extern void __attribute__((overloadable))
    106     rsgBindSampler(rs_program_fragment, uint slot, rs_sampler);
    107 
    108 /**
    109  * Bind a new Allocation object to a ProgramFragment.  The
    110  * Allocation must be a valid texture for the Program.  The sampling
    111  * of the texture will be controled by the Sampler bound at the
    112  * matching slot.
    113  *
    114  * @param slot
    115  */
    116 extern void __attribute__((overloadable))
    117     rsgBindTexture(rs_program_fragment, uint slot, rs_allocation);
    118 
    119 /**
    120  * Load the projection matrix for a currently bound fixed function
    121  * vertex program. Calling this function with a custom vertex shader
    122  * would result in an error.
    123  * @param proj projection matrix
    124  */
    125 extern void __attribute__((overloadable))
    126     rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 *proj);
    127 /**
    128  * Load the model matrix for a currently bound fixed function
    129  * vertex program. Calling this function with a custom vertex shader
    130  * would result in an error.
    131  * @param model model matrix
    132  */
    133 extern void __attribute__((overloadable))
    134     rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *model);
    135 /**
    136  * Load the texture matrix for a currently bound fixed function
    137  * vertex program. Calling this function with a custom vertex shader
    138  * would result in an error.
    139  * @param tex texture matrix
    140  */
    141 extern void __attribute__((overloadable))
    142     rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *tex);
    143 /**
    144  * Get the projection matrix for a currently bound fixed function
    145  * vertex program. Calling this function with a custom vertex shader
    146  * would result in an error.
    147  * @param proj matrix to store the current projection matrix into
    148  */
    149 extern void __attribute__((overloadable))
    150     rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *proj);
    151 
    152 /**
    153  * Set the constant color for a fixed function emulation program.
    154  *
    155  * @param pf
    156  * @param r
    157  * @param g
    158  * @param b
    159  * @param a
    160  */
    161 extern void __attribute__((overloadable))
    162     rsgProgramFragmentConstantColor(rs_program_fragment pf, float r, float g, float b, float a);
    163 
    164 /**
    165  * Get the width of the current rendering surface.
    166  *
    167  * @return uint
    168  */
    169 extern uint __attribute__((overloadable))
    170     rsgGetWidth(void);
    171 
    172 /**
    173  * Get the height of the current rendering surface.
    174  *
    175  * @return uint
    176  */
    177 extern uint __attribute__((overloadable))
    178     rsgGetHeight(void);
    179 
    180 
    181 /**
    182  * Sync the contents of an allocation from its SCRIPT memory space to its HW
    183  * memory spaces.
    184  *
    185  * @param alloc
    186  */
    187 extern void __attribute__((overloadable))
    188     rsgAllocationSyncAll(rs_allocation alloc);
    189 
    190 /**
    191  * Sync the contents of an allocation from memory space
    192  * specified by source.
    193  *
    194  * @param alloc
    195  * @param source
    196  */
    197 extern void __attribute__((overloadable))
    198     rsgAllocationSyncAll(rs_allocation alloc,
    199                          rs_allocation_usage_type source);
    200 
    201 /**
    202  * Low performance utility function for drawing a simple rectangle.  Not
    203  * intended for drawing large quantities of geometry.
    204  *
    205  * @param x1
    206  * @param y1
    207  * @param x2
    208  * @param y2
    209  * @param z
    210  */
    211 extern void __attribute__((overloadable))
    212     rsgDrawRect(float x1, float y1, float x2, float y2, float z);
    213 
    214 /**
    215  * Low performance utility function for drawing a simple quad.  Not intended for
    216  * drawing large quantities of geometry.
    217  *
    218  * @param x1
    219  * @param y1
    220  * @param z1
    221  * @param x2
    222  * @param y2
    223  * @param z2
    224  * @param x3
    225  * @param y3
    226  * @param z3
    227  * @param x4
    228  * @param y4
    229  * @param z4
    230  */
    231 extern void __attribute__((overloadable))
    232     rsgDrawQuad(float x1, float y1, float z1,
    233                 float x2, float y2, float z2,
    234                 float x3, float y3, float z3,
    235                 float x4, float y4, float z4);
    236 
    237 
    238 /**
    239  * Low performance utility function for drawing a textured quad.  Not intended
    240  * for drawing large quantities of geometry.
    241  *
    242  * @param x1
    243  * @param y1
    244  * @param z1
    245  * @param u1
    246  * @param v1
    247  * @param x2
    248  * @param y2
    249  * @param z2
    250  * @param u2
    251  * @param v2
    252  * @param x3
    253  * @param y3
    254  * @param z3
    255  * @param u3
    256  * @param v3
    257  * @param x4
    258  * @param y4
    259  * @param z4
    260  * @param u4
    261  * @param v4
    262  */
    263 extern void __attribute__((overloadable))
    264     rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
    265                          float x2, float y2, float z2, float u2, float v2,
    266                          float x3, float y3, float z3, float u3, float v3,
    267                          float x4, float y4, float z4, float u4, float v4);
    268 
    269 
    270 /**
    271  * Low performance function for drawing rectangles in screenspace.  This
    272  * function uses the default passthough ProgramVertex.  Any bound ProgramVertex
    273  * is ignored.  This function has considerable overhead and should not be used
    274  * for drawing in shipping applications.
    275  *
    276  * @param x
    277  * @param y
    278  * @param z
    279  * @param w
    280  * @param h
    281  */
    282 extern void __attribute__((overloadable))
    283     rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h);
    284 
    285 /**
    286  * Draw a mesh using the current context state.  The whole mesh is
    287  * rendered.
    288  *
    289  * @param ism
    290  */
    291 extern void __attribute__((overloadable))
    292     rsgDrawMesh(rs_mesh ism);
    293 /**
    294  * Draw part of a mesh using the current context state.
    295  * @param ism mesh object to render
    296  * @param primitiveIndex for meshes that contain multiple primitive groups
    297  *        this parameter specifies the index of the group to draw.
    298  */
    299 extern void __attribute__((overloadable))
    300     rsgDrawMesh(rs_mesh ism, uint primitiveIndex);
    301 /**
    302  * Draw specified index range of part of a mesh using the current context state.
    303  * @param ism mesh object to render
    304  * @param primitiveIndex for meshes that contain multiple primitive groups
    305  *        this parameter specifies the index of the group to draw.
    306  * @param start starting index in the range
    307  * @param len number of indices to draw
    308  */
    309 extern void __attribute__((overloadable))
    310     rsgDrawMesh(rs_mesh ism, uint primitiveIndex, uint start, uint len);
    311 
    312 /**
    313  * Clears the rendering surface to the specified color.
    314  *
    315  * @param r
    316  * @param g
    317  * @param b
    318  * @param a
    319  */
    320 extern void __attribute__((overloadable))
    321     rsgClearColor(float r, float g, float b, float a);
    322 
    323 /**
    324  * Clears the depth suface to the specified value.
    325  */
    326 extern void __attribute__((overloadable))
    327     rsgClearDepth(float value);
    328 /**
    329  * Draws text given a string and location
    330  */
    331 extern void __attribute__((overloadable))
    332     rsgDrawText(const char *, int x, int y);
    333 /**
    334  * \overload
    335  */
    336 extern void __attribute__((overloadable))
    337     rsgDrawText(rs_allocation, int x, int y);
    338 /**
    339  * Binds the font object to be used for all subsequent font rendering calls
    340  * @param font object to bind
    341  */
    342 extern void __attribute__((overloadable))
    343     rsgBindFont(rs_font font);
    344 /**
    345  * Sets the font color for all subsequent rendering calls
    346  * @param r red component
    347  * @param g green component
    348  * @param b blue component
    349  * @param a alpha component
    350  */
    351 extern void __attribute__((overloadable))
    352     rsgFontColor(float r, float g, float b, float a);
    353 /**
    354  * Returns the bounding box of the text relative to (0, 0)
    355  * Any of left, right, top, bottom could be NULL
    356  */
    357 extern void __attribute__((overloadable))
    358     rsgMeasureText(const char *, int *left, int *right, int *top, int *bottom);
    359 /**
    360  * \overload
    361  */
    362 extern void __attribute__((overloadable))
    363     rsgMeasureText(rs_allocation, int *left, int *right, int *top, int *bottom);
    364 /**
    365  * Computes an axis aligned bounding box of a mesh object
    366  */
    367 extern void __attribute__((overloadable))
    368     rsgMeshComputeBoundingBox(rs_mesh mesh, float *minX, float *minY, float *minZ,
    369                                                 float *maxX, float *maxY, float *maxZ);
    370 /**
    371  * \overload
    372  */
    373 __inline__ static void __attribute__((overloadable, always_inline))
    374 rsgMeshComputeBoundingBox(rs_mesh mesh, float3 *bBoxMin, float3 *bBoxMax) {
    375     float x1, y1, z1, x2, y2, z2;
    376     rsgMeshComputeBoundingBox(mesh, &x1, &y1, &z1, &x2, &y2, &z2);
    377     bBoxMin->x = x1;
    378     bBoxMin->y = y1;
    379     bBoxMin->z = z1;
    380     bBoxMax->x = x2;
    381     bBoxMax->y = y2;
    382     bBoxMax->z = z2;
    383 }
    384 
    385 #endif
    386 
    387