blob: af84461a86b42e5b6a7f93c1b810d58287e0598d [file] [log] [blame]
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -07001#
Jason Sams41371c72015-03-26 20:46:57 +00002# Copyright (C) 2015 The Android Open Source Project
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -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
17header:
Jason Sams41371c72015-03-26 20:46:57 +000018summary: TODO Add documentation
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070019description:
Jason Sams41371c72015-03-26 20:46:57 +000020 TODO Add documentation
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070021end:
22
23function: rsClamp
24# TODO Why always_inline?
25attrib: const, always_inline
26t: i8, i16, i32, u8, u16, u32
27ret: #1
28arg: #1 amount, "The value to clamp"
29arg: #1 low, "Lower bound"
30arg: #1 high, "Upper bound"
31summary: Restrain a value to a range
32description:
33 Clamp a value between low and high.
34
35 Deprecated. Use @clamp() instead.
36test: none
37end:
38
Jason Sams41371c72015-03-26 20:46:57 +000039function: rsExtractFrustumPlanes
40# TODO Why always_inline?
41attrib: always_inline
42ret: void
43arg: const rs_matrix4x4* viewProj, "matrix to extract planes from"
44arg: float4* left, "left plane"
45arg: float4* right, "right plane"
46arg: float4* top, "top plane"
47arg: float4* bottom, "bottom plane"
48arg: float4* near, "near plane"
49arg: float4* far, "far plane"
50summary:
51description:
52 Computes 6 frustum planes from the view projection matrix
53inline:
54 // x y z w = a b c d in the plane equation
55 left->x = viewProj->m[3] + viewProj->m[0];
56 left->y = viewProj->m[7] + viewProj->m[4];
57 left->z = viewProj->m[11] + viewProj->m[8];
58 left->w = viewProj->m[15] + viewProj->m[12];
59
60 right->x = viewProj->m[3] - viewProj->m[0];
61 right->y = viewProj->m[7] - viewProj->m[4];
62 right->z = viewProj->m[11] - viewProj->m[8];
63 right->w = viewProj->m[15] - viewProj->m[12];
64
65 top->x = viewProj->m[3] - viewProj->m[1];
66 top->y = viewProj->m[7] - viewProj->m[5];
67 top->z = viewProj->m[11] - viewProj->m[9];
68 top->w = viewProj->m[15] - viewProj->m[13];
69
70 bottom->x = viewProj->m[3] + viewProj->m[1];
71 bottom->y = viewProj->m[7] + viewProj->m[5];
72 bottom->z = viewProj->m[11] + viewProj->m[9];
73 bottom->w = viewProj->m[15] + viewProj->m[13];
74
75 near->x = viewProj->m[3] + viewProj->m[2];
76 near->y = viewProj->m[7] + viewProj->m[6];
77 near->z = viewProj->m[11] + viewProj->m[10];
78 near->w = viewProj->m[15] + viewProj->m[14];
79
80 far->x = viewProj->m[3] - viewProj->m[2];
81 far->y = viewProj->m[7] - viewProj->m[6];
82 far->z = viewProj->m[11] - viewProj->m[10];
83 far->w = viewProj->m[15] - viewProj->m[14];
84
85 float len = length(left->xyz);
86 *left /= len;
87 len = length(right->xyz);
88 *right /= len;
89 len = length(top->xyz);
90 *top /= len;
91 len = length(bottom->xyz);
92 *bottom /= len;
93 len = length(near->xyz);
94 *near /= len;
95 len = length(far->xyz);
96 *far /= len;
97test: none
98end:
99
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700100function: rsFrac
101attrib: const
102ret: float
103arg: float v
104summary:
105description:
106 Returns the fractional part of a float
107test: none
108end:
109
Jason Sams41371c72015-03-26 20:46:57 +0000110function: rsIsSphereInFrustum
111attrib: always_inline
112ret: bool
113arg: float4* sphere, "float4 representing the sphere"
114arg: float4* left, "left plane"
115arg: float4* right, "right plane"
116arg: float4* top, "top plane"
117arg: float4* bottom, "bottom plane"
118arg: float4* near, "near plane"
119arg: float4* far, "far plane"
120summary:
121description:
122 Checks if a sphere is withing the 6 frustum planes
123inline:
124 float distToCenter = dot(left->xyz, sphere->xyz) + left->w;
125 if (distToCenter < -sphere->w) {
126 return false;
127 }
128 distToCenter = dot(right->xyz, sphere->xyz) + right->w;
129 if (distToCenter < -sphere->w) {
130 return false;
131 }
132 distToCenter = dot(top->xyz, sphere->xyz) + top->w;
133 if (distToCenter < -sphere->w) {
134 return false;
135 }
136 distToCenter = dot(bottom->xyz, sphere->xyz) + bottom->w;
137 if (distToCenter < -sphere->w) {
138 return false;
139 }
140 distToCenter = dot(near->xyz, sphere->xyz) + near->w;
141 if (distToCenter < -sphere->w) {
142 return false;
143 }
144 distToCenter = dot(far->xyz, sphere->xyz) + far->w;
145 if (distToCenter < -sphere->w) {
146 return false;
147 }
148 return true;
149test: none
150end:
151
152function: rsPackColorTo8888
153attrib: const
154ret: uchar4
155arg: float r
156arg: float g
157arg: float b
158summary:
159description:
160 Pack floating point (0-1) RGB values into a uchar4.
161
162 For the float3 variant and the variant that only specifies r, g, b,
163 the alpha component is set to 255 (1.0).
164test: none
165end:
166
167function: rsPackColorTo8888
168attrib: const
169ret: uchar4
170arg: float r
171arg: float g
172arg: float b
173arg: float a
174test: none
175end:
176
177function: rsPackColorTo8888
178attrib: const
179ret: uchar4
180arg: float3 color
181test: none
182end:
183
184function: rsPackColorTo8888
185attrib: const
186ret: uchar4
187arg: float4 color
188test: none
189end:
190
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700191function: rsRand
192ret: int
193arg: int max_value
194summary:
195description:
196 Return a random value between 0 (or min_value) and max_malue.
197test: none
198end:
199
200function: rsRand
201ret: int
202arg: int min_value
203arg: int max_value
204test: none
205end:
206
207function: rsRand
208ret: float
209arg: float max_value
210test: none
211end:
212
213function: rsRand
214ret: float
215arg: float min_value
216arg: float max_value
217test: none
218end:
Jason Sams41371c72015-03-26 20:46:57 +0000219
220function: rsUnpackColor8888
221attrib: =const
222ret: float4
223arg: uchar4 c
224summary:
225description:
226 Unpack a uchar4 color to float4. The resulting float range will be (0-1).
227test: none
228end:
229
230function: rsYuvToRGBA_#2#1
231attrib: const
232w: 4
233t: u8, f32
234ret: #2#1
235arg: uchar y
236arg: uchar u
237arg: uchar v
238summary:
239description:
240 Convert from YUV to RGBA.
241test: none
242end: