Home | History | Annotate | Download | only in scriptc
      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_matrix.rsh
     18  *  \brief Matrix routines
     19  *
     20  *
     21  */
     22 
     23 #ifndef __RS_MATRIX_RSH__
     24 #define __RS_MATRIX_RSH__
     25 
     26 /**
     27  * Set one element of a matrix.
     28  *
     29  * @param m The matrix to be set
     30  * @param row
     31  * @param col
     32  * @param v
     33  *
     34  * @return void
     35  */
     36 _RS_RUNTIME void __attribute__((overloadable))
     37 rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v);
     38 /**
     39  * \overload
     40  */
     41 _RS_RUNTIME void __attribute__((overloadable))
     42 rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v);
     43 /**
     44  * \overload
     45  */
     46 _RS_RUNTIME void __attribute__((overloadable))
     47 rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v);
     48 
     49 /**
     50  * Get one element of a matrix.
     51  *
     52  * @param m The matrix to read from
     53  * @param row
     54  * @param col
     55  *
     56  * @return float
     57  */
     58 _RS_RUNTIME float __attribute__((overloadable))
     59 rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col);
     60 /**
     61  * \overload
     62  */
     63 _RS_RUNTIME float __attribute__((overloadable))
     64 rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col);
     65 /**
     66  * \overload
     67  */
     68 _RS_RUNTIME float __attribute__((overloadable))
     69 rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col);
     70 
     71 /**
     72  * Set the elements of a matrix to the identity matrix.
     73  *
     74  * @param m
     75  */
     76 extern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix4x4 *m);
     77 /**
     78  * \overload
     79  */
     80 extern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix3x3 *m);
     81 /**
     82  * \overload
     83  */
     84 extern void __attribute__((overloadable)) rsMatrixLoadIdentity(rs_matrix2x2 *m);
     85 
     86 /**
     87  * Set the elements of a matrix from an array of floats.
     88  *
     89  * @param m
     90  */
     91 extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const float *v);
     92 /**
     93  * \overload
     94  */
     95 extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix3x3 *m, const float *v);
     96 /**
     97  * \overload
     98  */
     99 extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix2x2 *m, const float *v);
    100 /**
    101  * \overload
    102  */
    103 extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix4x4 *v);
    104 /**
    105  * \overload
    106  */
    107 extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix3x3 *v);
    108 
    109 /**
    110  * Set the elements of a matrix from another matrix.
    111  *
    112  * @param m
    113  */
    114 extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix4x4 *m, const rs_matrix2x2 *v);
    115 /**
    116  * \overload
    117  */
    118 extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix3x3 *m, const rs_matrix3x3 *v);
    119 /**
    120  * \overload
    121  */
    122 extern void __attribute__((overloadable)) rsMatrixLoad(rs_matrix2x2 *m, const rs_matrix2x2 *v);
    123 
    124 /**
    125  * Load a rotation matrix.
    126  *
    127  * @param m
    128  * @param rot
    129  * @param x
    130  * @param y
    131  * @param z
    132  */
    133 extern void __attribute__((overloadable))
    134 rsMatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
    135 
    136 /**
    137  * Load a scale matrix.
    138  *
    139  * @param m
    140  * @param x
    141  * @param y
    142  * @param z
    143  */
    144 extern void __attribute__((overloadable))
    145 rsMatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z);
    146 
    147 /**
    148  * Load a translation matrix.
    149  *
    150  * @param m
    151  * @param x
    152  * @param y
    153  * @param z
    154  */
    155 extern void __attribute__((overloadable))
    156 rsMatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z);
    157 
    158 /**
    159  * Multiply two matrix (lhs, rhs) and place the result in m.
    160  *
    161  * @param m
    162  * @param lhs
    163  * @param rhs
    164  */
    165 extern void __attribute__((overloadable))
    166 rsMatrixLoadMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs);
    167 /**
    168  * \overload
    169  */
    170 extern void __attribute__((overloadable))
    171 rsMatrixLoadMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs);
    172 /**
    173  * \overload
    174  */
    175 extern void __attribute__((overloadable))
    176 rsMatrixLoadMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs);
    177 
    178 /**
    179  * Multiply the matrix m by rhs and place the result back into m.
    180  *
    181  * @param m (lhs)
    182  * @param rhs
    183  */
    184 extern void __attribute__((overloadable))
    185 rsMatrixMultiply(rs_matrix4x4 *m, const rs_matrix4x4 *rhs);
    186 /**
    187  * \overload
    188  */
    189 extern void __attribute__((overloadable))
    190 rsMatrixMultiply(rs_matrix3x3 *m, const rs_matrix3x3 *rhs);
    191 /**
    192  * \overload
    193  */
    194 extern void __attribute__((overloadable))
    195 rsMatrixMultiply(rs_matrix2x2 *m, const rs_matrix2x2 *rhs);
    196 
    197 /**
    198  * Multiple matrix m with a rotation matrix
    199  *
    200  * @param m
    201  * @param rot
    202  * @param x
    203  * @param y
    204  * @param z
    205  */
    206 extern void __attribute__((overloadable))
    207 rsMatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z);
    208 
    209 /**
    210  * Multiple matrix m with a scale matrix
    211  *
    212  * @param m
    213  * @param x
    214  * @param y
    215  * @param z
    216  */
    217 extern void __attribute__((overloadable))
    218 rsMatrixScale(rs_matrix4x4 *m, float x, float y, float z);
    219 
    220 /**
    221  * Multiple matrix m with a translation matrix
    222  *
    223  * @param m
    224  * @param x
    225  * @param y
    226  * @param z
    227  */
    228 extern void __attribute__((overloadable))
    229 rsMatrixTranslate(rs_matrix4x4 *m, float x, float y, float z);
    230 
    231 /**
    232  * Load an Ortho projection matrix constructed from the 6 planes
    233  *
    234  * @param m
    235  * @param left
    236  * @param right
    237  * @param bottom
    238  * @param top
    239  * @param near
    240  * @param far
    241  */
    242 extern void __attribute__((overloadable))
    243 rsMatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far);
    244 
    245 /**
    246  * Load an Frustum projection matrix constructed from the 6 planes
    247  *
    248  * @param m
    249  * @param left
    250  * @param right
    251  * @param bottom
    252  * @param top
    253  * @param near
    254  * @param far
    255  */
    256 extern void __attribute__((overloadable))
    257 rsMatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far);
    258 
    259 /**
    260  * Load an perspective projection matrix constructed from the 6 planes
    261  *
    262  * @param m
    263  * @param fovy Field of view, in degrees along the Y axis.
    264  * @param aspect Ratio of x / y.
    265  * @param near
    266  * @param far
    267  */
    268 extern void __attribute__((overloadable))
    269 rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
    270 
    271 #if !defined(RS_VERSION) || (RS_VERSION < 14)
    272 /**
    273  * Multiply a vector by a matrix and return the result vector.
    274  * API version 10-13
    275  */
    276 _RS_RUNTIME float4 __attribute__((overloadable))
    277 rsMatrixMultiply(rs_matrix4x4 *m, float4 in);
    278 
    279 /**
    280  * \overload
    281  */
    282 _RS_RUNTIME float4 __attribute__((overloadable))
    283 rsMatrixMultiply(rs_matrix4x4 *m, float3 in);
    284 
    285 /**
    286  * \overload
    287  */
    288 _RS_RUNTIME float4 __attribute__((overloadable))
    289 rsMatrixMultiply(rs_matrix4x4 *m, float2 in);
    290 
    291 /**
    292  * \overload
    293  */
    294 _RS_RUNTIME float3 __attribute__((overloadable))
    295 rsMatrixMultiply(rs_matrix3x3 *m, float3 in);
    296 
    297 /**
    298  * \overload
    299  */
    300 _RS_RUNTIME float3 __attribute__((overloadable))
    301 rsMatrixMultiply(rs_matrix3x3 *m, float2 in);
    302 
    303 /**
    304  * \overload
    305  */
    306 _RS_RUNTIME float2 __attribute__((overloadable))
    307 rsMatrixMultiply(rs_matrix2x2 *m, float2 in);
    308 #else
    309 /**
    310  * Multiply a vector by a matrix and return the result vector.
    311  * API version 14+
    312  */
    313 _RS_RUNTIME float4 __attribute__((overloadable))
    314 rsMatrixMultiply(const rs_matrix4x4 *m, float4 in);
    315 
    316 /**
    317  * \overload
    318  */
    319 _RS_RUNTIME float4 __attribute__((overloadable))
    320 rsMatrixMultiply(const rs_matrix4x4 *m, float3 in);
    321 
    322 /**
    323  * \overload
    324  */
    325 _RS_RUNTIME float4 __attribute__((overloadable))
    326 rsMatrixMultiply(const rs_matrix4x4 *m, float2 in);
    327 
    328 /**
    329  * \overload
    330  */
    331 _RS_RUNTIME float3 __attribute__((overloadable))
    332 rsMatrixMultiply(const rs_matrix3x3 *m, float3 in);
    333 
    334 /**
    335  * \overload
    336  */
    337 _RS_RUNTIME float3 __attribute__((overloadable))
    338 rsMatrixMultiply(const rs_matrix3x3 *m, float2 in);
    339 
    340 /**
    341  * \overload
    342  */
    343 _RS_RUNTIME float2 __attribute__((overloadable))
    344 rsMatrixMultiply(const rs_matrix2x2 *m, float2 in);
    345 #endif
    346 
    347 
    348 /**
    349  * Returns true if the matrix was successfully inversed
    350  *
    351  * @param m
    352  */
    353 extern bool __attribute__((overloadable)) rsMatrixInverse(rs_matrix4x4 *m);
    354 
    355 /**
    356  * Returns true if the matrix was successfully inversed and transposed.
    357  *
    358  * @param m
    359  */
    360 extern bool __attribute__((overloadable)) rsMatrixInverseTranspose(rs_matrix4x4 *m);
    361 
    362 /**
    363  * Transpose the matrix m.
    364  *
    365  * @param m
    366  */
    367 extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix4x4 *m);
    368 /**
    369  * \overload
    370  */
    371 extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix3x3 *m);
    372 /**
    373  * \overload
    374  */
    375 extern void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix2x2 *m);
    376 
    377 
    378 #endif
    379