Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 1 | # |
Jason Sams | 41371c7 | 2015-03-26 20:46:57 +0000 | [diff] [blame] | 2 | # Copyright (C) 2015 The Android Open Source Project |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 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 | header: |
Jason Sams | 41371c7 | 2015-03-26 20:46:57 +0000 | [diff] [blame] | 18 | summary: TODO Add documentation |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 19 | description: |
Jason Sams | 41371c7 | 2015-03-26 20:46:57 +0000 | [diff] [blame] | 20 | TODO Add documentation |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 21 | end: |
| 22 | |
| 23 | function: rsClamp |
| 24 | # TODO Why always_inline? |
| 25 | attrib: const, always_inline |
| 26 | t: i8, i16, i32, u8, u16, u32 |
| 27 | ret: #1 |
| 28 | arg: #1 amount, "The value to clamp" |
| 29 | arg: #1 low, "Lower bound" |
| 30 | arg: #1 high, "Upper bound" |
| 31 | summary: Restrain a value to a range |
| 32 | description: |
| 33 | Clamp a value between low and high. |
| 34 | |
| 35 | Deprecated. Use @clamp() instead. |
| 36 | test: none |
| 37 | end: |
| 38 | |
Jason Sams | 41371c7 | 2015-03-26 20:46:57 +0000 | [diff] [blame] | 39 | function: rsExtractFrustumPlanes |
| 40 | # TODO Why always_inline? |
| 41 | attrib: always_inline |
| 42 | ret: void |
| 43 | arg: const rs_matrix4x4* viewProj, "matrix to extract planes from" |
| 44 | arg: float4* left, "left plane" |
| 45 | arg: float4* right, "right plane" |
| 46 | arg: float4* top, "top plane" |
| 47 | arg: float4* bottom, "bottom plane" |
| 48 | arg: float4* near, "near plane" |
| 49 | arg: float4* far, "far plane" |
| 50 | summary: |
| 51 | description: |
| 52 | Computes 6 frustum planes from the view projection matrix |
| 53 | inline: |
| 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; |
| 97 | test: none |
| 98 | end: |
| 99 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 100 | function: rsFrac |
| 101 | attrib: const |
| 102 | ret: float |
| 103 | arg: float v |
| 104 | summary: |
| 105 | description: |
| 106 | Returns the fractional part of a float |
| 107 | test: none |
| 108 | end: |
| 109 | |
Jason Sams | 41371c7 | 2015-03-26 20:46:57 +0000 | [diff] [blame] | 110 | function: rsIsSphereInFrustum |
| 111 | attrib: always_inline |
| 112 | ret: bool |
| 113 | arg: float4* sphere, "float4 representing the sphere" |
| 114 | arg: float4* left, "left plane" |
| 115 | arg: float4* right, "right plane" |
| 116 | arg: float4* top, "top plane" |
| 117 | arg: float4* bottom, "bottom plane" |
| 118 | arg: float4* near, "near plane" |
| 119 | arg: float4* far, "far plane" |
| 120 | summary: |
| 121 | description: |
| 122 | Checks if a sphere is withing the 6 frustum planes |
| 123 | inline: |
| 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; |
| 149 | test: none |
| 150 | end: |
| 151 | |
| 152 | function: rsPackColorTo8888 |
| 153 | attrib: const |
| 154 | ret: uchar4 |
| 155 | arg: float r |
| 156 | arg: float g |
| 157 | arg: float b |
| 158 | summary: |
| 159 | description: |
| 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). |
| 164 | test: none |
| 165 | end: |
| 166 | |
| 167 | function: rsPackColorTo8888 |
| 168 | attrib: const |
| 169 | ret: uchar4 |
| 170 | arg: float r |
| 171 | arg: float g |
| 172 | arg: float b |
| 173 | arg: float a |
| 174 | test: none |
| 175 | end: |
| 176 | |
| 177 | function: rsPackColorTo8888 |
| 178 | attrib: const |
| 179 | ret: uchar4 |
| 180 | arg: float3 color |
| 181 | test: none |
| 182 | end: |
| 183 | |
| 184 | function: rsPackColorTo8888 |
| 185 | attrib: const |
| 186 | ret: uchar4 |
| 187 | arg: float4 color |
| 188 | test: none |
| 189 | end: |
| 190 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 191 | function: rsRand |
| 192 | ret: int |
| 193 | arg: int max_value |
| 194 | summary: |
| 195 | description: |
| 196 | Return a random value between 0 (or min_value) and max_malue. |
| 197 | test: none |
| 198 | end: |
| 199 | |
| 200 | function: rsRand |
| 201 | ret: int |
| 202 | arg: int min_value |
| 203 | arg: int max_value |
| 204 | test: none |
| 205 | end: |
| 206 | |
| 207 | function: rsRand |
| 208 | ret: float |
| 209 | arg: float max_value |
| 210 | test: none |
| 211 | end: |
| 212 | |
| 213 | function: rsRand |
| 214 | ret: float |
| 215 | arg: float min_value |
| 216 | arg: float max_value |
| 217 | test: none |
| 218 | end: |
Jason Sams | 41371c7 | 2015-03-26 20:46:57 +0000 | [diff] [blame] | 219 | |
| 220 | function: rsUnpackColor8888 |
| 221 | attrib: =const |
| 222 | ret: float4 |
| 223 | arg: uchar4 c |
| 224 | summary: |
| 225 | description: |
| 226 | Unpack a uchar4 color to float4. The resulting float range will be (0-1). |
| 227 | test: none |
| 228 | end: |
| 229 | |
| 230 | function: rsYuvToRGBA_#2#1 |
| 231 | attrib: const |
| 232 | w: 4 |
| 233 | t: u8, f32 |
| 234 | ret: #2#1 |
| 235 | arg: uchar y |
| 236 | arg: uchar u |
| 237 | arg: uchar v |
| 238 | summary: |
| 239 | description: |
| 240 | Convert from YUV to RGBA. |
| 241 | test: none |
| 242 | end: |