Stephen Hines | 05f25d2 | 2011-08-09 14:21:04 -0700 | [diff] [blame] | 1 | #include "rs_core.rsh" |
Alex Sakhartchouk | 5681ee6 | 2011-10-15 09:55:24 -0700 | [diff] [blame] | 2 | #include "rs_graphics.rsh" |
Stephen Hines | d4740c5 | 2011-08-08 15:04:52 -0700 | [diff] [blame] | 3 | /***************************************************************************** |
| 4 | * CAUTION |
| 5 | * |
| 6 | * The following structure layout provides a more efficient way to access |
| 7 | * internal members of the C++ class Allocation owned by librs. Unfortunately, |
| 8 | * since this class has virtual members, we can't simply use offsetof() or any |
| 9 | * other compiler trickery to dynamically get the appropriate values at |
| 10 | * build-time. This layout may need to be updated whenever |
| 11 | * frameworks/base/libs/rs/rsAllocation.h is modified. |
| 12 | * |
| 13 | * Having the layout information available in this file allows us to |
| 14 | * accelerate functionality like rsAllocationGetDimX(). Without this |
| 15 | * information, we would not be able to inline the bitcode, thus resulting in |
| 16 | * potential runtime performance penalties for tight loops operating on |
| 17 | * allocations. |
| 18 | * |
| 19 | *****************************************************************************/ |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 20 | typedef enum { |
| 21 | RS_ALLOCATION_MIPMAP_NONE = 0, |
| 22 | RS_ALLOCATION_MIPMAP_FULL = 1, |
| 23 | RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE = 2 |
| 24 | } rs_allocation_mipmap_control; |
| 25 | |
Stephen Hines | d4740c5 | 2011-08-08 15:04:52 -0700 | [diff] [blame] | 26 | typedef struct Allocation { |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 27 | char __pad[28]; |
Alex Sakhartchouk | 5681ee6 | 2011-10-15 09:55:24 -0700 | [diff] [blame] | 28 | struct { |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 29 | void * drv; |
Alex Sakhartchouk | 5681ee6 | 2011-10-15 09:55:24 -0700 | [diff] [blame] | 30 | struct { |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 31 | const void *type; |
| 32 | uint32_t usageFlags; |
| 33 | rs_allocation_mipmap_control mipmapControl; |
Stephen Hines | d4740c5 | 2011-08-08 15:04:52 -0700 | [diff] [blame] | 34 | uint32_t dimensionX; |
| 35 | uint32_t dimensionY; |
| 36 | uint32_t dimensionZ; |
| 37 | uint32_t elementSizeBytes; |
| 38 | bool hasMipmaps; |
| 39 | bool hasFaces; |
| 40 | bool hasReferences; |
Jason Sams | dcf7fec | 2011-12-09 16:13:43 -0800 | [diff] [blame] | 41 | void * usrPtr; |
Jason Sams | a0b6c06 | 2012-02-10 13:25:54 -0800 | [diff] [blame] | 42 | int32_t surfaceTextureID; |
Jason Sams | 8c504fb | 2012-02-15 12:07:16 -0800 | [diff] [blame] | 43 | void * wndSurface; |
Stephen Hines | d4740c5 | 2011-08-08 15:04:52 -0700 | [diff] [blame] | 44 | } state; |
| 45 | |
| 46 | struct DrvState { |
| 47 | void * mallocPtr; |
| 48 | } drvState; |
| 49 | } mHal; |
| 50 | } Allocation_t; |
| 51 | |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 52 | /***************************************************************************** |
| 53 | * CAUTION |
| 54 | * |
| 55 | * The following structure layout provides a more efficient way to access |
| 56 | * internal members of the C++ class ProgramStore owned by librs. Unfortunately, |
| 57 | * since this class has virtual members, we can't simply use offsetof() or any |
| 58 | * other compiler trickery to dynamically get the appropriate values at |
| 59 | * build-time. This layout may need to be updated whenever |
| 60 | * frameworks/base/libs/rs/rsProgramStore.h is modified. |
| 61 | * |
| 62 | * Having the layout information available in this file allows us to |
| 63 | * accelerate functionality like rsgProgramStoreGetDepthFunc(). Without this |
| 64 | * information, we would not be able to inline the bitcode, thus resulting in |
| 65 | * potential runtime performance penalties for tight loops operating on |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 66 | * program store. |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 67 | * |
| 68 | *****************************************************************************/ |
| 69 | typedef struct ProgramStore { |
| 70 | char __pad[36]; |
| 71 | struct { |
| 72 | struct { |
| 73 | bool ditherEnable; |
| 74 | bool colorRWriteEnable; |
| 75 | bool colorGWriteEnable; |
| 76 | bool colorBWriteEnable; |
| 77 | bool colorAWriteEnable; |
| 78 | rs_blend_src_func blendSrc; |
| 79 | rs_blend_dst_func blendDst; |
| 80 | bool depthWriteEnable; |
| 81 | rs_depth_func depthFunc; |
| 82 | } state; |
| 83 | } mHal; |
| 84 | } ProgramStore_t; |
| 85 | |
| 86 | /***************************************************************************** |
| 87 | * CAUTION |
| 88 | * |
| 89 | * The following structure layout provides a more efficient way to access |
| 90 | * internal members of the C++ class ProgramRaster owned by librs. Unfortunately, |
| 91 | * since this class has virtual members, we can't simply use offsetof() or any |
| 92 | * other compiler trickery to dynamically get the appropriate values at |
| 93 | * build-time. This layout may need to be updated whenever |
| 94 | * frameworks/base/libs/rs/rsProgramRaster.h is modified. |
| 95 | * |
| 96 | * Having the layout information available in this file allows us to |
| 97 | * accelerate functionality like rsgProgramRasterGetCullMode(). Without this |
| 98 | * information, we would not be able to inline the bitcode, thus resulting in |
| 99 | * potential runtime performance penalties for tight loops operating on |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 100 | * program raster. |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 101 | * |
| 102 | *****************************************************************************/ |
| 103 | typedef struct ProgramRaster { |
| 104 | char __pad[36]; |
| 105 | struct { |
| 106 | struct { |
| 107 | bool pointSprite; |
| 108 | rs_cull_mode cull; |
| 109 | } state; |
| 110 | } mHal; |
| 111 | } ProgramRaster_t; |
| 112 | |
| 113 | /***************************************************************************** |
| 114 | * CAUTION |
| 115 | * |
| 116 | * The following structure layout provides a more efficient way to access |
| 117 | * internal members of the C++ class Sampler owned by librs. Unfortunately, |
| 118 | * since this class has virtual members, we can't simply use offsetof() or any |
| 119 | * other compiler trickery to dynamically get the appropriate values at |
| 120 | * build-time. This layout may need to be updated whenever |
| 121 | * frameworks/base/libs/rs/rsSampler.h is modified. |
| 122 | * |
| 123 | * Having the layout information available in this file allows us to |
| 124 | * accelerate functionality like rsgProgramRasterGetMagFilter(). Without this |
| 125 | * information, we would not be able to inline the bitcode, thus resulting in |
| 126 | * potential runtime performance penalties for tight loops operating on |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 127 | * samplers. |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 128 | * |
| 129 | *****************************************************************************/ |
| 130 | typedef struct Sampler { |
| 131 | char __pad[32]; |
| 132 | struct { |
| 133 | struct { |
| 134 | rs_sampler_value magFilter; |
| 135 | rs_sampler_value minFilter; |
| 136 | rs_sampler_value wrapS; |
| 137 | rs_sampler_value wrapT; |
| 138 | rs_sampler_value wrapR; |
| 139 | float aniso; |
| 140 | } state; |
| 141 | } mHal; |
| 142 | } Sampler_t; |
| 143 | |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 144 | /***************************************************************************** |
| 145 | * CAUTION |
| 146 | * |
| 147 | * The following structure layout provides a more efficient way to access |
| 148 | * internal members of the C++ class Element owned by librs. Unfortunately, |
| 149 | * since this class has virtual members, we can't simply use offsetof() or any |
| 150 | * other compiler trickery to dynamically get the appropriate values at |
| 151 | * build-time. This layout may need to be updated whenever |
| 152 | * frameworks/base/libs/rs/rsElement.h is modified. |
| 153 | * |
| 154 | * Having the layout information available in this file allows us to |
| 155 | * accelerate functionality like rsElementGetSubElementCount(). Without this |
| 156 | * information, we would not be able to inline the bitcode, thus resulting in |
| 157 | * potential runtime performance penalties for tight loops operating on |
| 158 | * elements. |
| 159 | * |
| 160 | *****************************************************************************/ |
| 161 | typedef struct Element { |
| 162 | char __pad[28]; |
| 163 | struct { |
| 164 | void *drv; |
| 165 | struct { |
| 166 | rs_data_type dataType; |
| 167 | rs_data_kind dataKind; |
| 168 | uint32_t vectorSize; |
| 169 | uint32_t elementSizeBytes; |
| 170 | |
| 171 | // Subelements |
| 172 | const void **fields; |
| 173 | uint32_t *fieldArraySizes; |
| 174 | const char **fieldNames; |
| 175 | uint32_t *fieldNameLengths; |
| 176 | uint32_t *fieldOffsetBytes; |
| 177 | uint32_t fieldsCount; |
| 178 | } state; |
| 179 | } mHal; |
| 180 | } Element_t; |
| 181 | |
| 182 | /***************************************************************************** |
| 183 | * CAUTION |
| 184 | * |
| 185 | * The following structure layout provides a more efficient way to access |
| 186 | * internal members of the C++ class Type owned by librs. Unfortunately, |
| 187 | * since this class has virtual members, we can't simply use offsetof() or any |
| 188 | * other compiler trickery to dynamically get the appropriate values at |
| 189 | * build-time. This layout may need to be updated whenever |
| 190 | * frameworks/base/libs/rs/rsType.h is modified. |
| 191 | * |
| 192 | * Having the layout information available in this file allows us to |
| 193 | * accelerate functionality like rsAllocationGetElement(). Without this |
| 194 | * information, we would not be able to inline the bitcode, thus resulting in |
| 195 | * potential runtime performance penalties for tight loops operating on |
| 196 | * types. |
| 197 | * |
| 198 | *****************************************************************************/ |
| 199 | typedef struct Type { |
| 200 | char __pad[28]; |
| 201 | struct { |
| 202 | void *drv; |
| 203 | struct { |
| 204 | const void * element; |
| 205 | uint32_t dimX; |
| 206 | uint32_t dimY; |
| 207 | uint32_t dimZ; |
| 208 | bool dimLOD; |
| 209 | bool faces; |
| 210 | } state; |
| 211 | } mHal; |
| 212 | } Type_t; |
| 213 | |
| 214 | /***************************************************************************** |
| 215 | * CAUTION |
| 216 | * |
| 217 | * The following structure layout provides a more efficient way to access |
| 218 | * internal members of the C++ class Mesh owned by librs. Unfortunately, |
| 219 | * since this class has virtual members, we can't simply use offsetof() or any |
| 220 | * other compiler trickery to dynamically get the appropriate values at |
| 221 | * build-time. This layout may need to be updated whenever |
| 222 | * frameworks/base/libs/rs/rsMesh.h is modified. |
| 223 | * |
| 224 | * Having the layout information available in this file allows us to |
| 225 | * accelerate functionality like rsMeshGetVertexAllocationCount(). Without this |
| 226 | * information, we would not be able to inline the bitcode, thus resulting in |
| 227 | * potential runtime performance penalties for tight loops operating on |
| 228 | * meshes. |
| 229 | * |
| 230 | *****************************************************************************/ |
| 231 | typedef struct Mesh { |
| 232 | char __pad[28]; |
| 233 | struct { |
| 234 | void *drv; |
| 235 | struct { |
| 236 | void **vertexBuffers; |
| 237 | uint32_t vertexBuffersCount; |
| 238 | |
| 239 | // indexBuffers[i] could be NULL, in which case only primitives[i] is used |
| 240 | void **indexBuffers; |
| 241 | uint32_t indexBuffersCount; |
| 242 | rs_primitive *primitives; |
| 243 | uint32_t primitivesCount; |
| 244 | } state; |
| 245 | } mHal; |
| 246 | } Mesh_t; |
| 247 | |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 248 | |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 249 | /* Declaration of 4 basic functions in libRS */ |
| 250 | extern void __attribute__((overloadable)) |
| 251 | rsDebug(const char *, float, float); |
| 252 | extern void __attribute__((overloadable)) |
| 253 | rsDebug(const char *, float, float, float); |
| 254 | extern void __attribute__((overloadable)) |
| 255 | rsDebug(const char *, float, float, float, float); |
Shih-wei Liao | f9728b9 | 2011-01-17 18:04:33 -0800 | [diff] [blame] | 256 | extern float4 __attribute__((overloadable)) convert_float4(uchar4 c); |
| 257 | |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 258 | /* Implementation of Core Runtime */ |
| 259 | |
| 260 | extern void __attribute__((overloadable)) rsDebug(const char *s, float2 v) { |
| 261 | rsDebug(s, v.x, v.y); |
| 262 | } |
| 263 | |
| 264 | extern void __attribute__((overloadable)) rsDebug(const char *s, float3 v) { |
| 265 | rsDebug(s, v.x, v.y, v.z); |
| 266 | } |
| 267 | |
| 268 | extern void __attribute__((overloadable)) rsDebug(const char *s, float4 v) { |
| 269 | rsDebug(s, v.x, v.y, v.z, v.w); |
| 270 | } |
| 271 | |
Jason Sams | f7ab377 | 2012-02-29 15:59:43 -0800 | [diff] [blame^] | 272 | /* |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 273 | extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b) |
| 274 | { |
| 275 | uchar4 c; |
Jason Sams | 9d3f8a7 | 2011-10-13 17:20:04 -0700 | [diff] [blame] | 276 | c.x = (uchar)(r * 255.f + 0.5f); |
| 277 | c.y = (uchar)(g * 255.f + 0.5f); |
| 278 | c.z = (uchar)(b * 255.f + 0.5f); |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 279 | c.w = 255; |
| 280 | return c; |
| 281 | } |
| 282 | |
| 283 | extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b, float a) |
| 284 | { |
| 285 | uchar4 c; |
Jason Sams | 9d3f8a7 | 2011-10-13 17:20:04 -0700 | [diff] [blame] | 286 | c.x = (uchar)(r * 255.f + 0.5f); |
| 287 | c.y = (uchar)(g * 255.f + 0.5f); |
| 288 | c.z = (uchar)(b * 255.f + 0.5f); |
| 289 | c.w = (uchar)(a * 255.f + 0.5f); |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 290 | return c; |
| 291 | } |
| 292 | |
| 293 | extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3 color) |
| 294 | { |
| 295 | color *= 255.f; |
Jason Sams | 9d3f8a7 | 2011-10-13 17:20:04 -0700 | [diff] [blame] | 296 | color += 0.5f; |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 297 | uchar4 c = {color.x, color.y, color.z, 255}; |
| 298 | return c; |
| 299 | } |
| 300 | |
| 301 | extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float4 color) |
| 302 | { |
| 303 | color *= 255.f; |
Jason Sams | 9d3f8a7 | 2011-10-13 17:20:04 -0700 | [diff] [blame] | 304 | color += 0.5f; |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 305 | uchar4 c = {color.x, color.y, color.z, color.w}; |
| 306 | return c; |
| 307 | } |
Jason Sams | f7ab377 | 2012-02-29 15:59:43 -0800 | [diff] [blame^] | 308 | */ |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 309 | |
| 310 | extern float4 rsUnpackColor8888(uchar4 c) |
| 311 | { |
Jason Sams | 9d3f8a7 | 2011-10-13 17:20:04 -0700 | [diff] [blame] | 312 | float4 ret = (float4)0.003921569f; |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 313 | ret *= convert_float4(c); |
| 314 | return ret; |
| 315 | } |
| 316 | |
| 317 | ///////////////////////////////////////////////////// |
| 318 | // Matrix ops |
| 319 | ///////////////////////////////////////////////////// |
| 320 | |
| 321 | extern void __attribute__((overloadable)) |
| 322 | rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v) { |
| 323 | m->m[row * 4 + col] = v; |
| 324 | } |
| 325 | |
| 326 | extern float __attribute__((overloadable)) |
| 327 | rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col) { |
| 328 | return m->m[row * 4 + col]; |
| 329 | } |
| 330 | |
| 331 | extern void __attribute__((overloadable)) |
| 332 | rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v) { |
| 333 | m->m[row * 3 + col] = v; |
| 334 | } |
| 335 | |
| 336 | extern float __attribute__((overloadable)) |
| 337 | rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col) { |
| 338 | return m->m[row * 3 + col]; |
| 339 | } |
| 340 | |
| 341 | extern void __attribute__((overloadable)) |
| 342 | rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v) { |
| 343 | m->m[row * 2 + col] = v; |
| 344 | } |
| 345 | |
| 346 | extern float __attribute__((overloadable)) |
| 347 | rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col) { |
| 348 | return m->m[row * 2 + col]; |
| 349 | } |
| 350 | |
Jason Sams | 5bc951c | 2012-02-27 19:32:15 -0800 | [diff] [blame] | 351 | /* |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 352 | extern float4 __attribute__((overloadable)) |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 353 | rsMatrixMultiply(const rs_matrix4x4 *m, float4 in) { |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 354 | float4 ret; |
| 355 | ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + (m->m[8] * in.z) + (m->m[12] * in.w); |
| 356 | ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + (m->m[9] * in.z) + (m->m[13] * in.w); |
| 357 | ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + (m->m[10] * in.z) + (m->m[14] * in.w); |
| 358 | ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + (m->m[11] * in.z) + (m->m[15] * in.w); |
| 359 | return ret; |
| 360 | } |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 361 | extern float4 __attribute__((overloadable)) |
| 362 | rsMatrixMultiply(rs_matrix4x4 *m, float4 in) { |
| 363 | return rsMatrixMultiply((const rs_matrix4x4 *)m, in); |
| 364 | } |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 365 | |
| 366 | extern float4 __attribute__((overloadable)) |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 367 | rsMatrixMultiply(const rs_matrix4x4 *m, float3 in) { |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 368 | float4 ret; |
| 369 | ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + (m->m[8] * in.z) + m->m[12]; |
| 370 | ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + (m->m[9] * in.z) + m->m[13]; |
| 371 | ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + (m->m[10] * in.z) + m->m[14]; |
| 372 | ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + (m->m[11] * in.z) + m->m[15]; |
| 373 | return ret; |
| 374 | } |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 375 | extern float4 __attribute__((overloadable)) |
| 376 | rsMatrixMultiply(rs_matrix4x4 *m, float3 in) { |
| 377 | return rsMatrixMultiply((const rs_matrix4x4 *)m, in); |
| 378 | } |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 379 | |
| 380 | extern float4 __attribute__((overloadable)) |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 381 | rsMatrixMultiply(const rs_matrix4x4 *m, float2 in) { |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 382 | float4 ret; |
| 383 | ret.x = (m->m[0] * in.x) + (m->m[4] * in.y) + m->m[12]; |
| 384 | ret.y = (m->m[1] * in.x) + (m->m[5] * in.y) + m->m[13]; |
| 385 | ret.z = (m->m[2] * in.x) + (m->m[6] * in.y) + m->m[14]; |
| 386 | ret.w = (m->m[3] * in.x) + (m->m[7] * in.y) + m->m[15]; |
| 387 | return ret; |
| 388 | } |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 389 | extern float4 __attribute__((overloadable)) |
| 390 | rsMatrixMultiply(rs_matrix4x4 *m, float2 in) { |
| 391 | return rsMatrixMultiply((const rs_matrix4x4 *)m, in); |
| 392 | } |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 393 | |
| 394 | extern float3 __attribute__((overloadable)) |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 395 | rsMatrixMultiply(const rs_matrix3x3 *m, float3 in) { |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 396 | float3 ret; |
| 397 | ret.x = (m->m[0] * in.x) + (m->m[3] * in.y) + (m->m[6] * in.z); |
| 398 | ret.y = (m->m[1] * in.x) + (m->m[4] * in.y) + (m->m[7] * in.z); |
| 399 | ret.z = (m->m[2] * in.x) + (m->m[5] * in.y) + (m->m[8] * in.z); |
| 400 | return ret; |
| 401 | } |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 402 | extern float3 __attribute__((overloadable)) |
| 403 | rsMatrixMultiply(rs_matrix3x3 *m, float3 in) { |
| 404 | return rsMatrixMultiply((const rs_matrix3x3 *)m, in); |
| 405 | } |
| 406 | |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 407 | extern float3 __attribute__((overloadable)) |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 408 | rsMatrixMultiply(const rs_matrix3x3 *m, float2 in) { |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 409 | float3 ret; |
| 410 | ret.x = (m->m[0] * in.x) + (m->m[3] * in.y); |
| 411 | ret.y = (m->m[1] * in.x) + (m->m[4] * in.y); |
| 412 | ret.z = (m->m[2] * in.x) + (m->m[5] * in.y); |
| 413 | return ret; |
| 414 | } |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 415 | extern float3 __attribute__((overloadable)) |
| 416 | rsMatrixMultiply(rs_matrix3x3 *m, float2 in) { |
| 417 | return rsMatrixMultiply((const rs_matrix3x3 *)m, in); |
| 418 | } |
Jason Sams | 5bc951c | 2012-02-27 19:32:15 -0800 | [diff] [blame] | 419 | */ |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 420 | |
| 421 | extern float2 __attribute__((overloadable)) |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 422 | rsMatrixMultiply(const rs_matrix2x2 *m, float2 in) { |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 423 | float2 ret; |
| 424 | ret.x = (m->m[0] * in.x) + (m->m[2] * in.y); |
| 425 | ret.y = (m->m[1] * in.x) + (m->m[3] * in.y); |
| 426 | return ret; |
| 427 | } |
Jason Sams | f9931b8 | 2011-07-26 17:28:38 -0700 | [diff] [blame] | 428 | extern float2 __attribute__((overloadable)) |
| 429 | rsMatrixMultiply(rs_matrix2x2 *m, float2 in) { |
| 430 | return rsMatrixMultiply((const rs_matrix2x2 *)m, in); |
| 431 | } |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 432 | |
| 433 | ///////////////////////////////////////////////////// |
| 434 | // int ops |
| 435 | ///////////////////////////////////////////////////// |
| 436 | |
Stephen Hines | 85b860c | 2012-02-24 20:46:36 -0800 | [diff] [blame] | 437 | /*extern uint __attribute__((overloadable, always_inline)) rsClamp(uint amount, uint low, uint high) { |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 438 | return amount < low ? low : (amount > high ? high : amount); |
Stephen Hines | 85b860c | 2012-02-24 20:46:36 -0800 | [diff] [blame] | 439 | }*/ |
Shih-wei Liao | 50cdf8f | 2011-01-26 14:10:25 -0800 | [diff] [blame] | 440 | extern int __attribute__((overloadable, always_inline)) rsClamp(int amount, int low, int high) { |
| 441 | return amount < low ? low : (amount > high ? high : amount); |
| 442 | } |
| 443 | extern ushort __attribute__((overloadable, always_inline)) rsClamp(ushort amount, ushort low, ushort high) { |
| 444 | return amount < low ? low : (amount > high ? high : amount); |
| 445 | } |
| 446 | extern short __attribute__((overloadable, always_inline)) rsClamp(short amount, short low, short high) { |
| 447 | return amount < low ? low : (amount > high ? high : amount); |
| 448 | } |
| 449 | extern uchar __attribute__((overloadable, always_inline)) rsClamp(uchar amount, uchar low, uchar high) { |
| 450 | return amount < low ? low : (amount > high ? high : amount); |
| 451 | } |
| 452 | extern char __attribute__((overloadable, always_inline)) rsClamp(char amount, char low, char high) { |
| 453 | return amount < low ? low : (amount > high ? high : amount); |
| 454 | } |
Stephen Hines | d4740c5 | 2011-08-08 15:04:52 -0700 | [diff] [blame] | 455 | |
| 456 | // Opaque Allocation type operations |
| 457 | extern uint32_t __attribute__((overloadable)) |
| 458 | rsAllocationGetDimX(rs_allocation a) { |
| 459 | Allocation_t *alloc = (Allocation_t *)a.p; |
| 460 | return alloc->mHal.state.dimensionX; |
| 461 | } |
| 462 | |
| 463 | extern uint32_t __attribute__((overloadable)) |
| 464 | rsAllocationGetDimY(rs_allocation a) { |
| 465 | Allocation_t *alloc = (Allocation_t *)a.p; |
| 466 | return alloc->mHal.state.dimensionY; |
| 467 | } |
| 468 | |
| 469 | extern uint32_t __attribute__((overloadable)) |
| 470 | rsAllocationGetDimZ(rs_allocation a) { |
| 471 | Allocation_t *alloc = (Allocation_t *)a.p; |
| 472 | return alloc->mHal.state.dimensionZ; |
| 473 | } |
| 474 | |
| 475 | extern uint32_t __attribute__((overloadable)) |
| 476 | rsAllocationGetDimLOD(rs_allocation a) { |
| 477 | Allocation_t *alloc = (Allocation_t *)a.p; |
| 478 | return alloc->mHal.state.hasMipmaps; |
| 479 | } |
| 480 | |
| 481 | extern uint32_t __attribute__((overloadable)) |
| 482 | rsAllocationGetDimFaces(rs_allocation a) { |
| 483 | Allocation_t *alloc = (Allocation_t *)a.p; |
| 484 | return alloc->mHal.state.hasFaces; |
| 485 | } |
| 486 | |
| 487 | extern const void * __attribute__((overloadable)) |
| 488 | rsGetElementAt(rs_allocation a, uint32_t x) { |
| 489 | Allocation_t *alloc = (Allocation_t *)a.p; |
| 490 | const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.mallocPtr; |
| 491 | const uint32_t eSize = alloc->mHal.state.elementSizeBytes; |
| 492 | return &p[eSize * x]; |
| 493 | } |
| 494 | |
| 495 | extern const void * __attribute__((overloadable)) |
| 496 | rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y) { |
| 497 | Allocation_t *alloc = (Allocation_t *)a.p; |
| 498 | const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.mallocPtr; |
| 499 | const uint32_t eSize = alloc->mHal.state.elementSizeBytes; |
| 500 | const uint32_t dimX = alloc->mHal.state.dimensionX; |
| 501 | return &p[eSize * (x + y * dimX)]; |
| 502 | } |
| 503 | |
| 504 | extern const void * __attribute__((overloadable)) |
| 505 | rsGetElementAt(rs_allocation a, uint32_t x, uint32_t y, uint32_t z) { |
| 506 | Allocation_t *alloc = (Allocation_t *)a.p; |
| 507 | const uint8_t *p = (const uint8_t *)alloc->mHal.drvState.mallocPtr; |
| 508 | const uint32_t eSize = alloc->mHal.state.elementSizeBytes; |
| 509 | const uint32_t dimX = alloc->mHal.state.dimensionX; |
| 510 | const uint32_t dimY = alloc->mHal.state.dimensionY; |
| 511 | return &p[eSize * (x + y * dimX + z * dimX * dimY)]; |
| 512 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 513 | |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 514 | extern rs_element __attribute__((overloadable)) |
| 515 | rsAllocationGetElement(rs_allocation a) { |
| 516 | Allocation_t *alloc = (Allocation_t *)a.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 517 | if (alloc == NULL) { |
| 518 | rs_element nullElem = {0}; |
| 519 | return nullElem; |
| 520 | } |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 521 | Type_t *type = (Type_t *)alloc->mHal.state.type; |
| 522 | rs_element returnElem = {type->mHal.state.element}; |
| 523 | return returnElem; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Program Store |
| 528 | */ |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 529 | extern rs_depth_func __attribute__((overloadable)) |
| 530 | rsgProgramStoreGetDepthFunc(rs_program_store ps) { |
| 531 | ProgramStore_t *prog = (ProgramStore_t *)ps.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 532 | if (prog == NULL) { |
| 533 | return RS_DEPTH_FUNC_INVALID; |
| 534 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 535 | return prog->mHal.state.depthFunc; |
| 536 | } |
| 537 | |
| 538 | extern bool __attribute__((overloadable)) |
| 539 | rsgProgramStoreGetDepthMask(rs_program_store ps) { |
| 540 | ProgramStore_t *prog = (ProgramStore_t *)ps.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 541 | if (prog == NULL) { |
| 542 | return false; |
| 543 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 544 | return prog->mHal.state.depthWriteEnable; |
| 545 | } |
| 546 | |
| 547 | extern bool __attribute__((overloadable)) |
| 548 | rsgProgramStoreGetColorMaskR(rs_program_store ps) { |
| 549 | ProgramStore_t *prog = (ProgramStore_t *)ps.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 550 | if (prog == NULL) { |
| 551 | return false; |
| 552 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 553 | return prog->mHal.state.colorRWriteEnable; |
| 554 | } |
| 555 | |
| 556 | extern bool __attribute__((overloadable)) |
| 557 | rsgProgramStoreGetColorMaskG(rs_program_store ps) { |
| 558 | ProgramStore_t *prog = (ProgramStore_t *)ps.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 559 | if (prog == NULL) { |
| 560 | return false; |
| 561 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 562 | return prog->mHal.state.colorGWriteEnable; |
| 563 | } |
| 564 | |
| 565 | extern bool __attribute__((overloadable)) |
| 566 | rsgProgramStoreGetColorMaskB(rs_program_store ps) { |
| 567 | ProgramStore_t *prog = (ProgramStore_t *)ps.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 568 | if (prog == NULL) { |
| 569 | return false; |
| 570 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 571 | return prog->mHal.state.colorBWriteEnable; |
| 572 | } |
| 573 | |
| 574 | extern bool __attribute__((overloadable)) |
| 575 | rsgProgramStoreGetColorMaskA(rs_program_store ps) { |
| 576 | ProgramStore_t *prog = (ProgramStore_t *)ps.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 577 | if (prog == NULL) { |
| 578 | return false; |
| 579 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 580 | return prog->mHal.state.colorAWriteEnable; |
| 581 | } |
| 582 | |
| 583 | extern rs_blend_src_func __attribute__((overloadable)) |
| 584 | rsgProgramStoreGetBlendSrcFunc(rs_program_store ps) { |
| 585 | ProgramStore_t *prog = (ProgramStore_t *)ps.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 586 | if (prog == NULL) { |
| 587 | return RS_BLEND_SRC_INVALID; |
| 588 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 589 | return prog->mHal.state.blendSrc; |
| 590 | } |
| 591 | |
| 592 | extern rs_blend_dst_func __attribute__((overloadable)) |
| 593 | rsgProgramStoreGetBlendDstFunc(rs_program_store ps) { |
| 594 | ProgramStore_t *prog = (ProgramStore_t *)ps.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 595 | if (prog == NULL) { |
| 596 | return RS_BLEND_DST_INVALID; |
| 597 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 598 | return prog->mHal.state.blendDst; |
| 599 | } |
| 600 | |
| 601 | extern bool __attribute__((overloadable)) |
| 602 | rsgProgramStoreGetDitherEnabled(rs_program_store ps) { |
| 603 | ProgramStore_t *prog = (ProgramStore_t *)ps.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 604 | if (prog == NULL) { |
| 605 | return false; |
| 606 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 607 | return prog->mHal.state.ditherEnable; |
| 608 | } |
| 609 | |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 610 | /** |
| 611 | * Program Raster |
| 612 | */ |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 613 | extern bool __attribute__((overloadable)) |
| 614 | rsgProgramRasterGetPointSpriteEnabled(rs_program_raster pr) { |
| 615 | ProgramRaster_t *prog = (ProgramRaster_t *)pr.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 616 | if (prog == NULL) { |
| 617 | return false; |
| 618 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 619 | return prog->mHal.state.pointSprite; |
| 620 | } |
| 621 | |
| 622 | extern rs_cull_mode __attribute__((overloadable)) |
| 623 | rsgProgramRasterGetCullMode(rs_program_raster pr) { |
| 624 | ProgramRaster_t *prog = (ProgramRaster_t *)pr.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 625 | if (prog == NULL) { |
| 626 | return RS_CULL_INVALID; |
| 627 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 628 | return prog->mHal.state.cull; |
| 629 | } |
| 630 | |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 631 | /** |
| 632 | * Sampler |
| 633 | */ |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 634 | extern rs_sampler_value __attribute__((overloadable)) |
| 635 | rsgSamplerGetMinification(rs_sampler s) { |
| 636 | Sampler_t *prog = (Sampler_t *)s.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 637 | if (prog == NULL) { |
| 638 | return RS_SAMPLER_INVALID; |
| 639 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 640 | return prog->mHal.state.minFilter; |
| 641 | } |
| 642 | |
| 643 | extern rs_sampler_value __attribute__((overloadable)) |
| 644 | rsgSamplerGetMagnification(rs_sampler s) { |
| 645 | Sampler_t *prog = (Sampler_t *)s.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 646 | if (prog == NULL) { |
| 647 | return RS_SAMPLER_INVALID; |
| 648 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 649 | return prog->mHal.state.magFilter; |
| 650 | } |
| 651 | |
| 652 | extern rs_sampler_value __attribute__((overloadable)) |
| 653 | rsgSamplerGetWrapS(rs_sampler s) { |
| 654 | Sampler_t *prog = (Sampler_t *)s.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 655 | if (prog == NULL) { |
| 656 | return RS_SAMPLER_INVALID; |
| 657 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 658 | return prog->mHal.state.wrapS; |
| 659 | } |
| 660 | |
| 661 | extern rs_sampler_value __attribute__((overloadable)) |
| 662 | rsgSamplerGetWrapT(rs_sampler s) { |
| 663 | Sampler_t *prog = (Sampler_t *)s.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 664 | if (prog == NULL) { |
| 665 | return RS_SAMPLER_INVALID; |
| 666 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 667 | return prog->mHal.state.wrapT; |
| 668 | } |
| 669 | |
| 670 | extern float __attribute__((overloadable)) |
| 671 | rsgSamplerGetAnisotropy(rs_sampler s) { |
| 672 | Sampler_t *prog = (Sampler_t *)s.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 673 | if (prog == NULL) { |
| 674 | return 0.0f; |
| 675 | } |
Alex Sakhartchouk | aa08fd6 | 2011-11-17 16:01:24 -0800 | [diff] [blame] | 676 | return prog->mHal.state.aniso; |
| 677 | } |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 678 | |
| 679 | /** |
| 680 | * Mesh |
| 681 | */ |
| 682 | extern uint32_t __attribute__((overloadable)) |
| 683 | rsMeshGetVertexAllocationCount(rs_mesh m) { |
| 684 | Mesh_t *mesh = (Mesh_t *)m.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 685 | if (mesh == NULL) { |
| 686 | return 0; |
| 687 | } |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 688 | return mesh->mHal.state.vertexBuffersCount; |
| 689 | } |
| 690 | |
| 691 | extern uint32_t __attribute__((overloadable)) |
| 692 | rsMeshGetPrimitiveCount(rs_mesh m) { |
| 693 | Mesh_t *mesh = (Mesh_t *)m.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 694 | if (mesh == NULL) { |
| 695 | return 0; |
| 696 | } |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 697 | return mesh->mHal.state.primitivesCount; |
| 698 | } |
| 699 | |
| 700 | extern rs_allocation __attribute__((overloadable)) |
| 701 | rsMeshGetVertexAllocation(rs_mesh m, uint32_t index) { |
| 702 | Mesh_t *mesh = (Mesh_t *)m.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 703 | if (mesh == NULL || index >= mesh->mHal.state.vertexBuffersCount) { |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 704 | rs_allocation nullAlloc = {0}; |
| 705 | return nullAlloc; |
| 706 | } |
| 707 | rs_allocation returnAlloc = {mesh->mHal.state.vertexBuffers[index]}; |
| 708 | return returnAlloc; |
| 709 | } |
| 710 | |
| 711 | extern rs_allocation __attribute__((overloadable)) |
| 712 | rsMeshGetIndexAllocation(rs_mesh m, uint32_t index) { |
| 713 | Mesh_t *mesh = (Mesh_t *)m.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 714 | if (mesh == NULL || index >= mesh->mHal.state.primitivesCount) { |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 715 | rs_allocation nullAlloc = {0}; |
| 716 | return nullAlloc; |
| 717 | } |
| 718 | rs_allocation returnAlloc = {mesh->mHal.state.indexBuffers[index]}; |
| 719 | return returnAlloc; |
| 720 | } |
| 721 | |
| 722 | extern rs_primitive __attribute__((overloadable)) |
| 723 | rsMeshGetPrimitive(rs_mesh m, uint32_t index) { |
| 724 | Mesh_t *mesh = (Mesh_t *)m.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 725 | if (mesh == NULL || index >= mesh->mHal.state.primitivesCount) { |
| 726 | return RS_PRIMITIVE_INVALID; |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 727 | } |
| 728 | return mesh->mHal.state.primitives[index]; |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Element |
| 733 | */ |
| 734 | extern uint32_t __attribute__((overloadable)) |
| 735 | rsElementGetSubElementCount(rs_element e) { |
| 736 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 737 | if (element == NULL) { |
| 738 | return 0; |
| 739 | } |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 740 | return element->mHal.state.fieldsCount; |
| 741 | } |
| 742 | |
| 743 | extern rs_element __attribute__((overloadable)) |
| 744 | rsElementGetSubElement(rs_element e, uint32_t index) { |
| 745 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 746 | if (element == NULL || index >= element->mHal.state.fieldsCount) { |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 747 | rs_element nullElem = {0}; |
| 748 | return nullElem; |
| 749 | } |
| 750 | rs_element returnElem = {element->mHal.state.fields[index]}; |
| 751 | return returnElem; |
| 752 | } |
| 753 | |
| 754 | extern uint32_t __attribute__((overloadable)) |
| 755 | rsElementGetSubElementNameLength(rs_element e, uint32_t index) { |
| 756 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 757 | if (element == NULL || index >= element->mHal.state.fieldsCount) { |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | return element->mHal.state.fieldNameLengths[index]; |
| 761 | } |
| 762 | |
| 763 | extern uint32_t __attribute__((overloadable)) |
| 764 | rsElementGetSubElementName(rs_element e, uint32_t index, char *name, uint32_t nameLength) { |
| 765 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 766 | if (element == NULL || index >= element->mHal.state.fieldsCount || |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 767 | nameLength == 0 || name == 0) { |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | uint32_t numToCopy = element->mHal.state.fieldNameLengths[index]; |
| 772 | if (nameLength < numToCopy) { |
| 773 | numToCopy = nameLength; |
| 774 | } |
| 775 | // Place the null terminator manually, in case of partial string |
| 776 | numToCopy --; |
| 777 | name[numToCopy] = '\0'; |
| 778 | const char *nameSource = element->mHal.state.fieldNames[index]; |
| 779 | for (uint32_t i = 0; i < numToCopy; i ++) { |
| 780 | name[i] = nameSource[i]; |
| 781 | } |
| 782 | return numToCopy; |
| 783 | } |
| 784 | |
| 785 | extern uint32_t __attribute__((overloadable)) |
| 786 | rsElementGetSubElementArraySize(rs_element e, uint32_t index) { |
| 787 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 788 | if (element == NULL || index >= element->mHal.state.fieldsCount) { |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 789 | return 0; |
| 790 | } |
| 791 | return element->mHal.state.fieldArraySizes[index]; |
| 792 | } |
| 793 | |
| 794 | extern uint32_t __attribute__((overloadable)) |
| 795 | rsElementGetSubElementOffsetBytes(rs_element e, uint32_t index) { |
| 796 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 797 | if (element == NULL || index >= element->mHal.state.fieldsCount) { |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 798 | return 0; |
| 799 | } |
| 800 | return element->mHal.state.fieldOffsetBytes[index]; |
| 801 | } |
| 802 | |
| 803 | extern uint32_t __attribute__((overloadable)) |
| 804 | rsElementGetSizeBytes(rs_element e) { |
| 805 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 806 | if (element == NULL) { |
| 807 | return 0; |
| 808 | } |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 809 | return element->mHal.state.elementSizeBytes; |
| 810 | } |
| 811 | |
| 812 | extern rs_data_type __attribute__((overloadable)) |
| 813 | rsElementGetDataType(rs_element e) { |
| 814 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 815 | if (element == NULL) { |
| 816 | return RS_TYPE_INVALID; |
| 817 | } |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 818 | return element->mHal.state.dataType; |
| 819 | } |
| 820 | |
| 821 | extern rs_data_kind __attribute__((overloadable)) |
| 822 | rsElementGetDataKind(rs_element e) { |
| 823 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 824 | if (element == NULL) { |
| 825 | return RS_KIND_INVALID; |
| 826 | } |
Alex Sakhartchouk | 26301b4 | 2011-12-20 14:50:14 -0800 | [diff] [blame] | 827 | return element->mHal.state.dataKind; |
| 828 | } |
Alex Sakhartchouk | a6f221e | 2011-12-22 14:36:19 -0800 | [diff] [blame] | 829 | |
| 830 | extern uint32_t __attribute__((overloadable)) |
| 831 | rsElementGetVectorSize(rs_element e) { |
| 832 | Element_t *element = (Element_t *)e.p; |
Alex Sakhartchouk | d536473 | 2011-12-29 13:32:05 -0800 | [diff] [blame] | 833 | if (element == NULL) { |
| 834 | return 0; |
| 835 | } |
Alex Sakhartchouk | a6f221e | 2011-12-22 14:36:19 -0800 | [diff] [blame] | 836 | return element->mHal.state.vectorSize; |
| 837 | } |