blob: 32496db84562ff94ae1ddad62d625ce011e9570a [file] [log] [blame]
Jason Sams044e2ee2011-08-08 16:52:30 -07001/*
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -07002 * Copyright (C) 2015 The Android Open Source Project
Jason Sams044e2ee2011-08-08 16:52:30 -07003 *
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
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070017// Don't edit this file! It is auto-generated by frameworks/rs/api/gen_runtime.
18
19/*
20 * rs_matrix.rsh: Matrix functions
Jason Sams044e2ee2011-08-08 16:52:30 -070021 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070022 * These functions let you manipulate square matrices of rank 2x2, 3x3, and 4x4.
23 * They are particularly useful for graphical transformations and are
24 * compatible with OpenGL.
25 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070026 * We use a zero-based index for rows and columns. E.g. the last element of
27 * a rs_matrix4x4 is found at (3, 3).
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070028 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070029 * RenderScript uses column-major matrices and column-based vectors.
30 * Transforming a vector is done by postmultiplying the vector,
31 * e.g. (matrix * vector), as provided by rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070032 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070033 * To create a transformation matrix that performs two transformations at
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070034 * once, multiply the two source matrices, with the first transformation as the
35 * right argument. E.g. to create a transformation matrix that applies the
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070036 * transformation s1 followed by s2, call rsMatrixLoadMultiply(&combined, &s2, &s1).
37 * This derives from s2 * (s1 * v), which is (s2 * s1) * v.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070038 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070039 * We have two style of functions to create transformation matrices:
40 * rsMatrixLoadTransformation and rsMatrixTransformation. The
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070041 * former style simply stores the transformation matrix in the first argument.
42 * The latter modifies a pre-existing transformation matrix so that the new
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070043 * transformation happens first. E.g. if you call rsMatrixTranslate()
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070044 * on a matrix that already does a scaling, the resulting matrix when applied
45 * to a vector will first do the translation then the scaling.
Jason Sams044e2ee2011-08-08 16:52:30 -070046 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070047#ifndef RENDERSCRIPT_RS_MATRIX_RSH
48#define RENDERSCRIPT_RS_MATRIX_RSH
Jason Sams044e2ee2011-08-08 16:52:30 -070049
Jean-Luc Brouilletbe216382015-03-22 12:44:27 -070050#include "rs_vector_math.rsh"
51
52/*
53 * Computes 6 frustum planes from the view projection matrix
54 *
55 * Parameters:
56 * viewProj matrix to extract planes from
57 * left left plane
58 * right right plane
59 * top top plane
60 * bottom bottom plane
61 * near near plane
62 * far far plane
63 */
64static inline void __attribute__((always_inline, overloadable))
65 rsExtractFrustumPlanes(const rs_matrix4x4* viewProj, float4* left, float4* right, float4* top,
66 float4* bottom, float4* near, float4* far) {
67 // x y z w = a b c d in the plane equation
68 left->x = viewProj->m[3] + viewProj->m[0];
69 left->y = viewProj->m[7] + viewProj->m[4];
70 left->z = viewProj->m[11] + viewProj->m[8];
71 left->w = viewProj->m[15] + viewProj->m[12];
72
73 right->x = viewProj->m[3] - viewProj->m[0];
74 right->y = viewProj->m[7] - viewProj->m[4];
75 right->z = viewProj->m[11] - viewProj->m[8];
76 right->w = viewProj->m[15] - viewProj->m[12];
77
78 top->x = viewProj->m[3] - viewProj->m[1];
79 top->y = viewProj->m[7] - viewProj->m[5];
80 top->z = viewProj->m[11] - viewProj->m[9];
81 top->w = viewProj->m[15] - viewProj->m[13];
82
83 bottom->x = viewProj->m[3] + viewProj->m[1];
84 bottom->y = viewProj->m[7] + viewProj->m[5];
85 bottom->z = viewProj->m[11] + viewProj->m[9];
86 bottom->w = viewProj->m[15] + viewProj->m[13];
87
88 near->x = viewProj->m[3] + viewProj->m[2];
89 near->y = viewProj->m[7] + viewProj->m[6];
90 near->z = viewProj->m[11] + viewProj->m[10];
91 near->w = viewProj->m[15] + viewProj->m[14];
92
93 far->x = viewProj->m[3] - viewProj->m[2];
94 far->y = viewProj->m[7] - viewProj->m[6];
95 far->z = viewProj->m[11] - viewProj->m[10];
96 far->w = viewProj->m[15] - viewProj->m[14];
97
98 float len = length(left->xyz);
99 *left /= len;
100 len = length(right->xyz);
101 *right /= len;
102 len = length(top->xyz);
103 *top /= len;
104 len = length(bottom->xyz);
105 *bottom /= len;
106 len = length(near->xyz);
107 *near /= len;
108 len = length(far->xyz);
109 *far /= len;
110}
111
112/*
113 * Checks if a sphere is withing the 6 frustum planes
114 *
115 * Parameters:
116 * sphere float4 representing the sphere
117 * left left plane
118 * right right plane
119 * top top plane
120 * bottom bottom plane
121 * near near plane
122 * far far plane
123 */
124static inline bool __attribute__((always_inline, overloadable))
125 rsIsSphereInFrustum(float4* sphere, float4* left, float4* right, float4* top, float4* bottom,
126 float4* near, float4* far) {
127 float distToCenter = dot(left->xyz, sphere->xyz) + left->w;
128 if (distToCenter < -sphere->w) {
129 return false;
130 }
131 distToCenter = dot(right->xyz, sphere->xyz) + right->w;
132 if (distToCenter < -sphere->w) {
133 return false;
134 }
135 distToCenter = dot(top->xyz, sphere->xyz) + top->w;
136 if (distToCenter < -sphere->w) {
137 return false;
138 }
139 distToCenter = dot(bottom->xyz, sphere->xyz) + bottom->w;
140 if (distToCenter < -sphere->w) {
141 return false;
142 }
143 distToCenter = dot(near->xyz, sphere->xyz) + near->w;
144 if (distToCenter < -sphere->w) {
145 return false;
146 }
147 distToCenter = dot(far->xyz, sphere->xyz) + far->w;
148 if (distToCenter < -sphere->w) {
149 return false;
150 }
151 return true;
152}
153
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700154/*
155 * rsMatrixGet: Get one element
Jason Sams044e2ee2011-08-08 16:52:30 -0700156 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700157 * Returns one element of a matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700158 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700159 * Warning: The order of the column and row parameters may be unexpected.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700160 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700161 * Parameters:
162 * m The matrix to extract the element from.
163 * col The zero-based column of the element to be extracted.
164 * row The zero-based row of the element to extracted.
Jason Sams044e2ee2011-08-08 16:52:30 -0700165 */
Jean-Luc Brouillet129c1472015-03-02 15:37:07 -0800166extern float __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700167 rsMatrixGet(const rs_matrix4x4* m, uint32_t col, uint32_t row);
Jason Sams044e2ee2011-08-08 16:52:30 -0700168
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700169extern float __attribute__((overloadable))
170 rsMatrixGet(const rs_matrix3x3* m, uint32_t col, uint32_t row);
Jason Sams044e2ee2011-08-08 16:52:30 -0700171
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700172extern float __attribute__((overloadable))
173 rsMatrixGet(const rs_matrix2x2* m, uint32_t col, uint32_t row);
174
175/*
176 * rsMatrixInverse: Inverts a matrix in place
Jason Sams044e2ee2011-08-08 16:52:30 -0700177 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700178 * Returns true if the matrix was successfully inverted.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700179 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700180 * Parameters:
181 * m The matrix to invert.
Jason Sams044e2ee2011-08-08 16:52:30 -0700182 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700183extern bool __attribute__((overloadable))
184 rsMatrixInverse(rs_matrix4x4* m);
185
186/*
187 * rsMatrixInverseTranspose: Inverts and transpose a matrix in place
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700188 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700189 * The matrix is first inverted then transposed.
190 * Returns true if the matrix was successfully inverted.
191 *
192 * Parameters:
193 * m The matrix to modify.
194 */
195extern bool __attribute__((overloadable))
196 rsMatrixInverseTranspose(rs_matrix4x4* m);
197
198/*
199 * rsMatrixLoad: Load or copy a matrix
200 *
201 * Set the elements of a matrix from an array of floats or from another matrix.
202 *
203 * If loading from an array, the floats should be in row-major order, i.e. the element a
204 * row 0, column 0 should be first, followed by the element at
205 * row 0, column 1, etc.
206 *
207 * If loading from a matrix and the source is smaller than the destination, the rest of the
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700208 * destination is filled with elements of the identity matrix. E.g.
209 * loading a rs_matrix2x2 into a rs_matrix4x4 will give:
210 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700211 * m00 m01 0.0 0.0
212 * m10 m11 0.0 0.0
213 * 0.0 0.0 1.0 0.0
214 * 0.0 0.0 0.0 1.0
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700215 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700216 *
217 * Parameters:
218 * destination The matrix to set.
219 * array The array of values to set the matrix to. These arrays should be 4, 9, or 16 floats long, depending on the matrix size.
220 * source The source matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700221 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700222extern void __attribute__((overloadable))
223 rsMatrixLoad(rs_matrix4x4* destination, const float* array);
Jason Sams044e2ee2011-08-08 16:52:30 -0700224
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700225extern void __attribute__((overloadable))
226 rsMatrixLoad(rs_matrix3x3* destination, const float* array);
227
228extern void __attribute__((overloadable))
229 rsMatrixLoad(rs_matrix2x2* destination, const float* array);
230
231extern void __attribute__((overloadable))
232 rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix4x4* source);
233
234extern void __attribute__((overloadable))
235 rsMatrixLoad(rs_matrix3x3* destination, const rs_matrix3x3* source);
236
237extern void __attribute__((overloadable))
238 rsMatrixLoad(rs_matrix2x2* destination, const rs_matrix2x2* source);
239
240extern void __attribute__((overloadable))
241 rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix3x3* source);
242
243extern void __attribute__((overloadable))
244 rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix2x2* source);
245
246/*
247 * rsMatrixLoadFrustum: Load a frustum projection matrix
248 *
249 * Constructs a frustum projection matrix, transforming the box
250 * identified by the six clipping planes left, right, bottom, top,
251 * near, far.
252 *
253 * To apply this projection to a vector, multiply the vector by the
254 * created matrix using rsMatrixMultiply().
255 *
256 * Parameters:
257 * m The matrix to set.
258 */
259extern void __attribute__((overloadable))
260 rsMatrixLoadFrustum(rs_matrix4x4* m, float left, float right, float bottom, float top,
261 float near, float far);
262
263/*
264 * rsMatrixLoadIdentity: Load identity matrix
265 *
266 * Set the elements of a matrix to the identity matrix.
267 *
268 * Parameters:
269 * m The matrix to set.
270 */
271extern void __attribute__((overloadable))
272 rsMatrixLoadIdentity(rs_matrix4x4* m);
273
274extern void __attribute__((overloadable))
275 rsMatrixLoadIdentity(rs_matrix3x3* m);
276
277extern void __attribute__((overloadable))
278 rsMatrixLoadIdentity(rs_matrix2x2* m);
279
280/*
281 * rsMatrixLoadMultiply: Multiply two matrices
282 *
283 * Sets m to the matrix product of lhs * rhs.
284 *
285 * To combine two 4x4 transformaton matrices, multiply the second transformation matrix
286 * by the first transformation matrix. E.g. to create a transformation matrix that applies
287 * the transformation s1 followed by s2, call
288 * rsMatrixLoadMultiply(&combined, &s2, &s1).
289 *
290 * Warning: Prior to version 21, storing the result back into right matrix is not supported and
291 * will result in undefined behavior. Use rsMatrixMulitply instead. E.g. instead of doing
292 * rsMatrixLoadMultiply (&m2r, &m2r, &m2l), use rsMatrixMultiply (&m2r, &m2l).
293 * rsMatrixLoadMultiply (&m2l, &m2r, &m2l) works as expected.
294 *
295 * Parameters:
296 * m The matrix to set.
297 * lhs The left matrix of the product.
298 * rhs The right matrix of the product.
299 */
300extern void __attribute__((overloadable))
301 rsMatrixLoadMultiply(rs_matrix4x4* m, const rs_matrix4x4* lhs, const rs_matrix4x4* rhs);
302
303extern void __attribute__((overloadable))
304 rsMatrixLoadMultiply(rs_matrix3x3* m, const rs_matrix3x3* lhs, const rs_matrix3x3* rhs);
305
306extern void __attribute__((overloadable))
307 rsMatrixLoadMultiply(rs_matrix2x2* m, const rs_matrix2x2* lhs, const rs_matrix2x2* rhs);
308
309/*
310 * rsMatrixLoadOrtho: Load an orthographic projection matrix
311 *
312 * Constructs an orthographic projection matrix, transforming the box
313 * identified by the six clipping planes left, right, bottom, top,
314 * near, far into a unit cube with a corner at
315 * (-1, -1, -1) and the opposite at (1, 1, 1).
316 *
317 * To apply this projection to a vector, multiply the vector by the
318 * created matrix using rsMatrixMultiply().
319 *
320 * See https://en.wikipedia.org/wiki/Orthographic_projection .
321 *
322 * Parameters:
323 * m The matrix to set.
324 */
325extern void __attribute__((overloadable))
326 rsMatrixLoadOrtho(rs_matrix4x4* m, float left, float right, float bottom, float top, float near,
327 float far);
328
329/*
330 * rsMatrixLoadPerspective: Load a perspective projection matrix
331 *
332 * Constructs a perspective projection matrix, assuming a symmetrical field of view.
333 *
334 * To apply this projection to a vector, multiply the vector by the
335 * created matrix using rsMatrixMultiply().
336 *
337 * Parameters:
338 * m The matrix to set.
339 * fovy Field of view, in degrees along the Y axis.
340 * aspect Ratio of x / y.
341 * near The near clipping plane.
342 * far The far clipping plane.
343 */
344extern void __attribute__((overloadable))
345 rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
346
347/*
348 * rsMatrixLoadRotate: Load a rotation matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700349 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700350 * This function creates a rotation matrix. The axis of rotation is the
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700351 * (x, y, z) vector.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700352 *
353 * To rotate a vector, multiply the vector by the created matrix
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700354 * using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700355 *
356 * See http://en.wikipedia.org/wiki/Rotation_matrix .
357 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700358 * Parameters:
359 * m The matrix to set.
360 * rot How much rotation to do, in degrees.
361 * x The x component of the vector that is the axis of rotation.
362 * y The y component of the vector that is the axis of rotation.
363 * z The z component of the vector that is the axis of rotation.
Jason Sams044e2ee2011-08-08 16:52:30 -0700364 */
365extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700366 rsMatrixLoadRotate(rs_matrix4x4* m, float rot, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700367
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700368/*
369 * rsMatrixLoadScale: Load a scaling matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700370 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700371 * This function creates a scaling matrix, where each component of a
372 * vector is multiplied by a number. This number can be negative.
373 *
374 * To scale a vector, multiply the vector by the created matrix
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700375 * using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700376 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700377 * Parameters:
378 * m The matrix to set.
379 * x The multiple to scale the x components by.
380 * y The multiple to scale the y components by.
381 * z The multiple to scale the z components by.
Jason Sams044e2ee2011-08-08 16:52:30 -0700382 */
383extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700384 rsMatrixLoadScale(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700385
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700386/*
387 * rsMatrixLoadTranslate: Load a translation matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700388 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700389 * This function creates a translation matrix, where a
390 * number is added to each element of a vector.
391 *
392 * To translate a vector, multiply the vector by the created matrix
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700393 * using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700394 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700395 * Parameters:
396 * m The matrix to set.
397 * x The number to add to each x component.
398 * y The number to add to each y component.
399 * z The number to add to each z component.
Jason Sams044e2ee2011-08-08 16:52:30 -0700400 */
401extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700402 rsMatrixLoadTranslate(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700403
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700404/*
405 * rsMatrixMultiply: Multiply a matrix by a vector or another matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700406 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700407 * For the matrix by matrix variant, sets m to the matrix product m * rhs.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700408 *
409 * When combining two 4x4 transformation matrices using this function, the resulting
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700410 * matrix will correspond to performing the rhs transformation first followed by
411 * the original m transformation.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700412 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700413 * For the matrix by vector variant, returns the post-multiplication of the vector
414 * by the matrix, ie. m * in.
415 *
416 * When multiplying a float3 to a rs_matrix4x4, the vector is expanded with (1).
417 *
418 * When multiplying a float2 to a rs_matrix4x4, the vector is expanded with (0, 1).
419 *
420 * When multiplying a float2 to a rs_matrix3x3, the vector is expanded with (0).
421 *
422 * Starting with API 14, this function takes a const matrix as the first argument.
423 *
424 * Parameters:
425 * m The left matrix of the product and the matrix to be set.
426 * rhs The right matrix of the product.
Jason Sams044e2ee2011-08-08 16:52:30 -0700427 */
428extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700429 rsMatrixMultiply(rs_matrix4x4* m, const rs_matrix4x4* rhs);
Jason Sams044e2ee2011-08-08 16:52:30 -0700430
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700431extern void __attribute__((overloadable))
432 rsMatrixMultiply(rs_matrix3x3* m, const rs_matrix3x3* rhs);
433
434extern void __attribute__((overloadable))
435 rsMatrixMultiply(rs_matrix2x2* m, const rs_matrix2x2* rhs);
436
437#if !defined(RS_VERSION) || (RS_VERSION <= 13)
438extern float4 __attribute__((overloadable))
439 rsMatrixMultiply(rs_matrix4x4* m, float4 in);
440#endif
441
442#if !defined(RS_VERSION) || (RS_VERSION <= 13)
443extern float4 __attribute__((overloadable))
444 rsMatrixMultiply(rs_matrix4x4* m, float3 in);
445#endif
446
447#if !defined(RS_VERSION) || (RS_VERSION <= 13)
448extern float4 __attribute__((overloadable))
449 rsMatrixMultiply(rs_matrix4x4* m, float2 in);
450#endif
451
452#if !defined(RS_VERSION) || (RS_VERSION <= 13)
453extern float3 __attribute__((overloadable))
454 rsMatrixMultiply(rs_matrix3x3* m, float3 in);
455#endif
456
457#if !defined(RS_VERSION) || (RS_VERSION <= 13)
458extern float3 __attribute__((overloadable))
459 rsMatrixMultiply(rs_matrix3x3* m, float2 in);
460#endif
461
462#if !defined(RS_VERSION) || (RS_VERSION <= 13)
463extern float2 __attribute__((overloadable))
464 rsMatrixMultiply(rs_matrix2x2* m, float2 in);
465#endif
466
467#if (defined(RS_VERSION) && (RS_VERSION >= 14))
468extern float4 __attribute__((overloadable))
469 rsMatrixMultiply(const rs_matrix4x4* m, float4 in);
470#endif
471
472#if (defined(RS_VERSION) && (RS_VERSION >= 14))
473extern float4 __attribute__((overloadable))
474 rsMatrixMultiply(const rs_matrix4x4* m, float3 in);
475#endif
476
477#if (defined(RS_VERSION) && (RS_VERSION >= 14))
478extern float4 __attribute__((overloadable))
479 rsMatrixMultiply(const rs_matrix4x4* m, float2 in);
480#endif
481
482#if (defined(RS_VERSION) && (RS_VERSION >= 14))
483extern float3 __attribute__((overloadable))
484 rsMatrixMultiply(const rs_matrix3x3* m, float3 in);
485#endif
486
487#if (defined(RS_VERSION) && (RS_VERSION >= 14))
488extern float3 __attribute__((overloadable))
489 rsMatrixMultiply(const rs_matrix3x3* m, float2 in);
490#endif
491
492#if (defined(RS_VERSION) && (RS_VERSION >= 14))
493extern float2 __attribute__((overloadable))
494 rsMatrixMultiply(const rs_matrix2x2* m, float2 in);
495#endif
496
497/*
498 * rsMatrixRotate: Apply a rotation to a transformation matrix
499 *
500 * Multiply the matrix m with a rotation matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700501 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700502 * This function modifies a transformation matrix to first do a rotation.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700503 * The axis of rotation is the (x, y, z) vector.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700504 *
505 * To apply this combined transformation to a vector, multiply
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700506 * the vector by the created matrix using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700507 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700508 * Parameters:
509 * m The matrix to modify.
510 * rot How much rotation to do, in degrees.
511 * x The x component of the vector that is the axis of rotation.
512 * y The y component of the vector that is the axis of rotation.
513 * z The z component of the vector that is the axis of rotation.
Jason Sams044e2ee2011-08-08 16:52:30 -0700514 */
515extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700516 rsMatrixRotate(rs_matrix4x4* m, float rot, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700517
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700518/*
519 * rsMatrixScale: Apply a scaling to a transformation matrix
520 *
521 * Multiply the matrix m with a scaling matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700522 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700523 * This function modifies a transformation matrix to first do a scaling.
524 * When scaling, each component of a vector is multiplied by a number.
525 * This number can be negative.
526 *
527 * To apply this combined transformation to a vector, multiply
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700528 * the vector by the created matrix using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700529 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700530 * Parameters:
531 * m The matrix to modify.
532 * x The multiple to scale the x components by.
533 * y The multiple to scale the y components by.
534 * z The multiple to scale the z components by.
Jason Sams044e2ee2011-08-08 16:52:30 -0700535 */
536extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700537 rsMatrixScale(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700538
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700539/*
540 * rsMatrixSet: Set one element
541 *
542 * Set an element of a matrix.
543 *
544 * Warning: The order of the column and row parameters may be unexpected.
545 *
546 * Parameters:
547 * m The matrix that will be modified.
548 * col The zero-based column of the element to be set.
549 * row The zero-based row of the element to be set.
550 * v The value to set.
551 */
552extern void __attribute__((overloadable))
553 rsMatrixSet(rs_matrix4x4* m, uint32_t col, uint32_t row, float v);
554
555extern void __attribute__((overloadable))
556 rsMatrixSet(rs_matrix3x3* m, uint32_t col, uint32_t row, float v);
557
558extern void __attribute__((overloadable))
559 rsMatrixSet(rs_matrix2x2* m, uint32_t col, uint32_t row, float v);
560
561/*
562 * rsMatrixTranslate: Apply a translation to a transformation matrix
563 *
564 * Multiply the matrix m with a translation matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700565 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700566 * This function modifies a transformation matrix to first
567 * do a translation. When translating, a number is added
568 * to each component of a vector.
569 *
570 * To apply this combined transformation to a vector, multiply
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700571 * the vector by the created matrix using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700572 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700573 * Parameters:
574 * m The matrix to modify.
575 * x The number to add to each x component.
576 * y The number to add to each y component.
577 * z The number to add to each z component.
Jason Sams044e2ee2011-08-08 16:52:30 -0700578 */
579extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700580 rsMatrixTranslate(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700581
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700582/*
583 * rsMatrixTranspose: Transpose a matrix place
Jason Sams044e2ee2011-08-08 16:52:30 -0700584 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700585 * Transpose the matrix m in place.
Jason Sams044e2ee2011-08-08 16:52:30 -0700586 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700587 * Parameters:
588 * m The matrix to transpose.
Jason Sams044e2ee2011-08-08 16:52:30 -0700589 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700590extern void __attribute__((overloadable))
591 rsMatrixTranspose(rs_matrix4x4* m);
Jason Sams044e2ee2011-08-08 16:52:30 -0700592
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700593extern void __attribute__((overloadable))
594 rsMatrixTranspose(rs_matrix3x3* m);
Jason Sams044e2ee2011-08-08 16:52:30 -0700595
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700596extern void __attribute__((overloadable))
597 rsMatrixTranspose(rs_matrix2x2* m);
598
599#endif // RENDERSCRIPT_RS_MATRIX_RSH